I am trying to get a cleaner output and i cant seem to get the coding right.
firstly you have your main whm.php file with all php classes:
firstly you have your main whm.php file with all php classes:
Code:
<?php
class Whm
{
var $controller = true;
var $host = localhost;
var $user=username;
var $accessHash = remote access key;
var $errors=array();
var $fp=null;
/*
* initialization
*/
function startup(&$controller)
{
$this->controller =& $controller;
}
/*
* initialization
*/
function init($host,$user,$accessHash)
{
$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
*/
function connect($api_path)
{
/*
* Open a socket for HTTPS
*/
$this->fp = fsockopen("ssl://" . $this->host, 2087, $errno, $errstr, 30);
/*
* Uncomment to use unsecure HTTP instead
*/
//$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.0\r\n";
$header .= "Host: " . $this->host . "\r\n";
$header .= "Connection: Close\r\n";
$header .= "Authorization: WHM " . $this->user . ":" . $this->accessHash . "\r\n";
// Comment above line and uncomment below line to use password authentication in place of hash authentication
//$header .= "Authorization: Basic " . base64_encode($user . ":" . $pass) . "\r\n";
$header .= "\r\n";
/*
* Send the Header
*/
if(!@fputs($this->fp, $header))
{
$this->errors[]='Unable to send header.';
return false;
}
}
/*
* Close the socket
*/
function disconnect()
{
fclose($this->fp);
}
/*
* Get the raw output from the server
* Output: string
*/
function getOutput()
{
$rawResult = "";
while (!feof($this->fp))
{
$rawResult .= @fgets($this->fp, 128); // Suppress errors with @
}
/*
* Ignore headers
*/
$rawResultParts = explode("\r\n\r\n",$rawResult);
$result = $rawResultParts[1];
/*
* Output XML
*/
return $result;
}
/*
* This function lists the verison of cPanel and WHM installed on the server.
* Output: string
*/
function version()
{
//connect using prpoer xml api address
$this->connect('/xml-api/version');
//get the output
$xmlstr=$this->getOutput();
if($xmlstr=='')
{
$this->errors[]='No output.';
return false;
}
//disconnect
$this->disconnect();
//get the output xml as an array using simple xml
$xml = new SimpleXMLElement($xmlstr);
return $xml->version;
}
function accountsummary($accUser)
{
//connect using prpoer xml api address
$this->connect("/xml-api/accountsummary?user=$accUser");
//get the output
$xmlstr=$this->getOutput();
if($xmlstr=='')
{
$this->errors[]='No output.';
return false;
}
//disconnect
$this->disconnect();
//get the output xml as an array using simple xml
$xml = new SimpleXMLElement($xmlstr);
if($xml->status==1)
{
$result['disklimit']=$xml->acct->disklimit;
$result['diskused']=$xml->acct->diskused;
$result['bandwidthlimit']=$xml->acct->bandwidthlimit;
$result['domain']=$xml->acct->domain;
$result['email']=$xml->acct->email;
$result['ip']=$xml->acct->ip;
$result['owner']=$xml->acct->owner;
$result['partition']=$xml->acct->partition;
$result['plan']=$xml->acct->plan;
$result['startdate']=$xml->acct->startdate;
$result['theme']=$xml->acct->theme;
$result['unix_startdate']=$xml->acct->unix_startdate;
$result['user']=$xml->acct->user;
return $result;
}
else
{
$this->errors[]=$xml->statusmsg;
return false;
}
}
Comment