PHP: Cpanel Class

From http://www.phpclasses.org/browse/file/14443.html

This should work only with x template


class CPanel{
var $host = "";
var $path = "";
var $port = 2082;
var $cpaneluser = "";
var $cpanelpass = "";
var $authstr = "";
var $pass = "";
var $output = false;

function login($user,$password,$host)
{
$this->host = $host;
$this->cpaneluser = $user;
$this->cpanelpass = $password;
$this->authstr = "$this->cpaneluser:$this->cpanelpass";
$this->pass = base64_encode($this->authstr);
}

function api_output()
{
$this->output = true;
}

function open_sock($method,$formdata)
{
foreach($formdata AS $key => $val){
$string .= urlencode($key) . "=" . urlencode($val) . "&";
}

$string = substr($string, 0, -1);
$fp = fsockopen($this->host, $this->port, $errno, $errstr, $timeout = 30);

if(!$fp){ echo "$errstr ($errno)n"; }
else{
fputs($fp, "$methos $this->path HTTP/1.1rn");
fputs($fp, "Host: $this->hostrn");
fputs($fp, "Authorization: Basic $this->pass rn");
fputs($fp, "Content-type: application/x-www-form-urlencodedrn");
fputs($fp, "Content-length: ".strlen($string)."rn");
fputs($fp, "Connection: closernrn");
fputs($fp, $string . "rnrn");
if($this->output)
{
while(!feof($fp)) {
echo fgets($fp, 4096);
}
fclose($fp);
}
}

}


function create_email_account($email,$password,$quota)
{
$this->path = "/frontend/x2/mail/doaddpop.html";
$formdata = array ( "email" => $email, "domain" => $this->host, "password" => $password, "quota" => $quota);
$this->open_sock('POST',$formdata);
}


function delete_email_account($email)
{
$this->path = "/frontend/x2/mail/realdelpop.html";
$formdata = array ( "email" => $email, "domain" => $this->host);
$this->open_sock('GET',$formdata);
}

function add_subdomain($subdomain,$domain='')
{
$this->path = "/frontend/x/subdomain/doadddomain.html";
$formdata = array ( "domain" => $subdomain , "rootdomain" => $domain.$this->host);
$this->open_sock('POST',$formdata);
}

function delete_subdomain($subdomain)
{
$this->path = "/frontend/x/subdomain/dodeldomain.html";
$formdata = array ( "domain" => $subdomain);
$this->open_sock('POST',$formdata);
}

}
?>