Файл: billing/_rootinc/whm.inc.php
Строк: 466
<?
require_once($full_home_path."/_rootinc/todaynic/xmlbase.inc.php");
/**
* Cpanel/WHM XML API class
* Auther: Arash Hemmat
* License: GNU GPL
* Date: September 25 2007
*/
class Whm
{
public $controller = true;
public $protocol = null;
public $host = null;
public $user=null;
public $accessHash = null;
public $errors=array();
public $fp=null;
/*
* initialization
*/
public function startup(&$controller)
{
$this->controller =& $controller;
}
/*
* initialization
*/
public function init($protocol,$host,$user,$accessHash)
{
$this->protocol=$protocol;
$this->host=$host;
$this->user=$user;
// $accessHash = str_replace(array("r", "n"),"",$accessHash);
$this->accessHash=$accessHash;
}
/*
* connect to the xml api
* Output: true on success, false on fail
*/
public function connect($api_path)
{
if ($this->protocol == 'http') {
/*
* Uncomment to use unsecure HTTP instead
*/
$this->fp = fsockopen($this->host, 2086, $errno, $errstr, 30);
} else if ($this->protocol == 'https') {
/*
* Open a socket for HTTPS
*/
$this->fp = fsockopen("ssl://" . $this->host, 2087, $errno, $errstr, 30);
}
/*
* Die on error initializing socket
*/
if ($errno == 0 && $this->fp == false)
{
$this->errors[]="Socket Error: Could not initialize socket.";
return false;
}
elseif ($this->fp == false)
{
$this->errors[]="Socket Error #" . $errno . ": " . $errstr;
return false;
}
/*
* Assemble the header to send
*/
$header = "";
$header .= "GET " . $api_path . " HTTP/1.0rn";
$header .= "Host: " . $this->host . "rn";
$header .= "Connection: Closern";
// $header .= "Authorization: WHM " . $this->user . ":" . $this->accessHash . "rn";
// Comment above line and uncomment below line to use password authentication in place of hash authentication
$header .= "Authorization: Basic " . base64_encode($this->user . ":" . $this->accessHash) . "rn";
$header .= "rn";
/*
* Send the Header
*/
if(!@fputs($this->fp, $header))
{
$this->errors[]='connect: Unable to send header.';
return false;
}
}
/*
* Close the socket
*/
public function disconnect()
{
fclose($this->fp);
}
/*
* Get the raw output from the server
* Output: string
*/
public function getOutput()
{
$rawResult = "";
while (!@feof($this->fp))
{
$rawResult .= @fgets($this->fp, 128); // Suppress errors with @
}
/*
* Ignore headers
*/
$rawResultParts = explode("rnrn",$rawResult);
$result = $rawResultParts[1];
/*
* Output XML
*/
return $result;
}
/*
* create a cpanel account
* Output: array on success, false on fail
*/
public function createAccount($acctDomain,$acctUser,$acctPass,$acctPackg,$acctTheme,$acctEmail,$userIP,$acctReseller='0')
{
if ($userIP) {$ipAddon="&ip=y&customip=$userIP";} else {$ipAddon="&ip=n";}
//connect using prpoer xml api address
$this->connect("/xml-api/createacct?username=$acctUser&password=$acctPass&plan=$acctPackg&domain=$acctDomain$ipAddon&useregns=0&reseller=$acctReseller&contactemail=$acctEmail");
//get the output
$xmlstr=$this->getOutput();
if ($xmlstr=='') {
$this->errors[]='createAccount: No output';
$this->disconnect();
return false;
}
else if (preg_match("/password/ui",$xmlstr) and !preg_match('/<createacct>/ui',$xmlstr)) {
$this->errors[]='createAccount: Authentication error';
$this->disconnect();
return false;
} else {
$this->disconnect();
$xmlArray = toarray($xmlstr,"createacct",1);
if($xmlArray[status][0][value] == 1) {
$result['status']=$xmlArray[status][0][value];
$result['statusmsg']=$xmlArray[statusmsg][0][value];
$result['ip']=$xmlArray[ip][0][value];
$result['nameserver']=$xmlArray[nameserver][0][value];
$result['nameserver2']=$xmlArray[nameserver2][0][value];
$result['nameserver3']=$xmlArray[nameserver3][0][value];
$result['nameserver4']=$xmlArray[nameserver4][0][value];
$result['package']=$xmlArray[package][0][value];
$result['rawout']=$xmlArray[rawout][0][value];
return $result;
}
else
{
$this->errors[]="createAccount: ".$xmlArray[statusmsg][0][value];
return false;
}
}
}
/*
* suspend a cpanel account
* Output: string (statusmsg) on success, false on fail
*/
public function suspend($acctUser,$reason)
{
//connect using prpoer xml api address
$this->connect("/xml-api/suspendacct?user=$acctUser&reason=$reason");
//get the output
$xmlstr=$this->getOutput();
if ($xmlstr=='') {
$this->errors[]='suspend: No output';
$this->disconnect();
return false;
}
else if (preg_match("/password/ui",$xmlstr) and !preg_match('/<suspendacct>/ui',$xmlstr)) {
$this->errors[]='suspend: Authentication error';
$this->disconnect();
return false;
} else {
$this->disconnect();
$xmlArray = toarray($xmlstr,"suspendacct",1);
if($xmlArray[status][0][value] == 1)
{
return $xmlArray[statusmsg][0][value];
}
else
{
$this->errors[]="suspend: ".$xmlArray[statusmsg][0][value];
return false;
}
}
}
/*
* suspend a cpanel reseller account
* Output: string (statusmsg) on success, false on fail
*/
public function suspendReseller($acctUser,$reason)
{
//connect using prpoer xml api address
$this->connect("/xml-api/suspendreseller?user=$acctUser&reason=$reason");
//get the output
$xmlstr=$this->getOutput();
if ($xmlstr=='') {
$this->errors[]='suspendReseller: No output';
$this->disconnect();
return false;
}
else if (preg_match("/password/ui",$xmlstr) and !preg_match('/<suspendreseller>/ui',$xmlstr)) {
$this->errors[]='suspendReseller: Authentication error';
$this->disconnect();
return false;
} else {
$this->disconnect();
$xmlArray = toarray($xmlstr,"suspendreseller",1);
if($xmlArray[status][0][value] == 1)
{
return $xmlArray[statusmsg][0][value];
}
else
{
$this->errors[]="suspendReseller: ".$xmlArray[statusmsg][0][value];
return false;
}
}
}
/*
* unsuspend a suspended cpanel account
* Output: string (statusmsg) on success, false on fail
*/
public function unsuspend($acctUser)
{
//connect using prpoer xml api address
$this->connect("/xml-api/unsuspendacct?user=$acctUser");
//get the output
$xmlstr=$this->getOutput();
if ($xmlstr=='') {
$this->errors[]='unsuspend: No output';
$this->disconnect();
return false;
}
else if (preg_match("/password/ui",$xmlstr) and !preg_match('/<unsuspendacct>/ui',$xmlstr)) {
$this->errors[]='unsuspend: Authentication error';
$this->disconnect();
return false;
} else {
$this->disconnect();
$xmlArray = toarray($xmlstr,"unsuspendacct",1);
if($xmlArray[status][0][value] == 1)
{
return $xmlArray[statusmsg][0][value];
}
else
{
$this->errors[]="unsuspend: ".$xmlArray[statusmsg][0][value];
return false;
}
}
}
/*
* unsuspend a suspended cpanel reseller account
* Output: string (statusmsg) on success, false on fail
*/
public function unsuspendReseller($acctUser)
{
//connect using prpoer xml api address
$this->connect("/xml-api/unsuspendreseller?user=$acctUser");
//get the output
$xmlstr=$this->getOutput();
if ($xmlstr=='') {
$this->errors[]='unsuspendReseller: No output';
$this->disconnect();
return false;
}
else if (preg_match("/password/ui",$xmlstr) and !preg_match('/<unsuspendreseller>/ui',$xmlstr)) {
$this->errors[]='unsuspendReseller: Authentication error';
$this->disconnect();
return false;
} else {
$this->disconnect();
$xmlArray = toarray($xmlstr,"unsuspendreseller",1);
if($xmlArray[status][0][value] == 1)
{
return $xmlArray[statusmsg][0][value];
}
else
{
$this->errors[]="unsuspendReseller: ".$xmlArray[statusmsg][0][value];
return false;
}
}
}
/*
* terminate a cpanel account
* Output: string (statusmsg) on success, false on fail
*/
public function terminate($acctUser,$keepDns=0)
{
//connect using prpoer xml api address
$this->connect("/xml-api/removeacct?user=$acctUser&keepdns=$keepDns");
//get the output
$xmlstr=$this->getOutput();
if ($xmlstr=='') {
$this->errors[]='terminate: No output';
$this->disconnect();
return false;
}
else if (preg_match("/password/ui",$xmlstr) and !preg_match('/<removeacct>/ui',$xmlstr)) {
$this->errors[]='terminate: Authentication error';
$this->disconnect();
return false;
} else {
$this->disconnect();
$xmlArray = toarray($xmlstr,"removeacct",1);
if($xmlArray[status][0][value] == 1)
{
return $xmlArray[statusmsg][0][value];
}
else
{
$this->errors[]="terminate: ".$xmlArray[statusmsg][0][value];
return false;
}
}
}
/*
* terminate a cpanel reseller account
* Output: string (statusmsg) on success, false on fail
*/
public function terminateReseller($acctUser)
{
//connect using prpoer xml api address
$this->connect("/xml-api/terminatereseller?reseller=$acctUser&terminatereseller=1&verify=I%20understand%20this%20will%20irrevocably%20remove%20all%20the%20accounts%20owned%20by%20the%20reseller%20$acctUser");
//get the output
$xmlstr=$this->getOutput();
if ($xmlstr=='') {
$this->errors[]='terminateReseller: No output';
$this->disconnect();
return false;
}
else if (preg_match("/password/ui",$xmlstr) and !preg_match('/<terminatereseller>/ui',$xmlstr)) {
$this->errors[]='terminateReseller: Authentication error';
$this->disconnect();
return false;
} else {
$this->disconnect();
if (preg_match("/<accts>/ui",$xmlstr)) {
return true;
} else {
$this->errors[]="terminateReseller: ".$xmlArray[statusmsg][0][value];
return false;
}
# $xmlArray = toarray($xmlstr,"terminatereseller",1);
#
# if($xmlArray[status][0][value] == 1)
# {
# return $xmlArray[statusmsg][0][value];
#
# }
# else
# {
# $this->errors[]="terminateReseller: ".$xmlArray[statusmsg][0][value];
# return false;
# }
}
}
/*
* Upgrade/Downgrade and Account (Change Package)
* Output: array on success, false on fail
*/
public function changepackage($accUser,$pkg)
{
//connect using prpoer xml api address
$this->connect("/xml-api/changepackage?user=$accUser&pkg=$pkg");
//get the output
$xmlstr=$this->getOutput();
if ($xmlstr=='') {
$this->errors[]='No output';
$this->disconnect();
return false;
}
else if (preg_match("/password/ui",$xmlstr) and !preg_match('/<changepackage>/ui',$xmlstr)) {
$this->errors[]='Authentication error';
$this->disconnect();
return false;
}
else {
$this->disconnect();
$xmlArray = toarray($xmlstr,"changepackage",1);
if($xmlArray[status][0][value] == 1)
{
$result['statusmsg']=$xmlArray[statusmsg][0][value];
$result['rawout']=$xmlArray[rawout][0][value];
return $result;
}
else
{
$this->errors[]=$xmlArray[statusmsg][0][value];
return false;
}
}
}
public function changelanguage($accUser,$lng)
{
//connect using prpoer xml api address
$this->connect("/scripts2/domassmodify?acct-$accUser=1&lang=$lng");
//get the output
$xmlstr=$this->getOutput();
if($xmlstr=='')
{
$this->errors[]='No output';
return false;
}
//disconnect
$this->disconnect();
return true;
}
/*
* list packages
* Output: array on success, false on fail
*/
public function listPkgs()
{
//connect using prpoer xml api address
$this->connect('/xml-api/listpkgs');
//get the output
$xmlstr=$this->getOutput();
if($xmlstr == '') {
$this->errors[]='No output';
$this->disconnect();
return false;
}
else if (preg_match("/password/ui",$xmlstr) and !preg_match('/<listpkgs>/ui',$xmlstr)) {
$this->errors[]='Authentication error';
$this->disconnect();
return false;
} else {
$this->disconnect();
$xmlArray = toarray($xmlstr,"listpkgs",1);
if ($xmlArray[name]) {
while (list($i,$v) = each($xmlArray[name])) {
$resultArray[] = $v[value];
}
return $resultArray;
} else {
$this->errors[]=$xmlArray[statusmsg][0][value];
return false;
}
}
}
public function parkDomain($mainDomain,$domain)
{
//connect using prpoer xml api address
$this->connect("/scripts/park?domain=$mainDomain&ndomain=$domain");
//get the output
$xmlstr=$this->getOutput();
if($xmlstr=='')
{
$this->errors[]='No output';
return false;
}
//disconnect
$this->disconnect();
if (preg_match("/was successfully parked/iu",$xmlstr)) {
return true;
} else {
return false;
}
}
}
?>