hi
We have the below code working before cpanel upgrade. This code use to fetch us the data through cpanel. Please let us know the changes which needs to be made on our side to fix this code as per new cpanel.
<?php
class HTTP
{
function HTTP($host, $username, $password, $port = 2082, $ssl = '', $theme = 'sg')
{
$this->ssl = $ssl ? 'ssl://' : '';
$this->username = $username;
$this->password = $password;
$this->theme = $theme;
$this->auth = base64_encode($username . ':' . $password);
$this->port = $port;
$this->host = $host;
$this->path = '/frontend/' . $theme . '/';
}
function getData($url, $data = '')
{
$url = $this->path . $url;
if(is_array($data))
{
$url = $url . '?';
foreach($data as $key=>$value)
{
$url .= urlencode($key) . '=' . urlencode($value) . '&';
}
$url = substr($url, 0, -1);
}
$response = '';
$fp = fsockopen($this->ssl . $this->host, $this->port);
if(!$fp)
{
return false;
}
$out = 'GET ' . $url . ' HTTP/1.0' . "\r\n";
$out .= 'Authorization: Basic ' . $this->auth . "\r\n";
$out .= 'Connection: Close' . "\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp))
{
$response .= @fgets($fp);
}
fclose($fp);
return $response;
}
}
/**
* Functions to manipulate cPanel
*/
class cPanel
{
/**
* Creates an object to manipulate cPanel
* @param string $host cPanel host without leading http://
* @param string $username cPanel username
* @param string $password cPanel password
* @param int $port cPanel port, default to 2082. Change to 2083 if using SSL
* @param bool $ssl False for http (default), true for SSL (requires OpenSSL)
* @param string $theme cPanel theme, (forward compatibility- 'sg' theme currently required)
* @return cPanel
*/
function cPanel($host, $username, $password, $port = 2082, $ssl = false, $theme = 'sg')
{
$this->HTTP = new HTTP($host, $username, $password, $port, $ssl, $theme);
}
/**
* Change cPanel's password
*
* Returns true on success or false on failure.
* The cPanel object is no longer usable after changing the password.
* @param string $password new password
* @return bool
*/
function setPassword($password)
{
$data['oldpass'] = $this->HTTP->password;
$data['newpass'] = $password;
$response = $this->HTTP->getData('passwd/changepass.html', $data);
if(strpos($response, 'has been') && !strpos($response, 'could not'))
{
return true;
}
return false;
}
/**
* Retrieve contact email address.
*
* Returns the contact email address listed in cPanel.
* @return string
*/
function getContactEmail()
{
$email = array();
preg_match('/email" value="(.*)"/', $this->HTTP->getData('contact/index.html'), $email);
return $email[1];
}
/**
* Modify contact email address
*
* Returns true on success or false on failure.
* @param string new contact email address
* @return string
*/
function setContactEmail($email)
{
$data['email'] = $email;
$response = $this->HTTP->getData('contact/saveemail.html', $data);
if(strpos($response, 'has been'))
{
return true;
}
return false;
}
/**
* List all domains in the cPanel account
*
* Returns a numerically-indexed array on success or false on failure.
* @return array
*/
function listDomains()
{
$domainList = array();
preg_match_all('/<option value="([^"]*)/', $this->HTTP->getData('mail/addpop2.html'), $domainList);
if(count($domainList[1]) > 0)
{
return $domainList[1];
}
return false;
}
/**
* List all POP3 email accounts
*
* Returns a numerically-indexed array on success or false on failure.
* @return array
*/
function listMailAccounts()
{
$accountList = array();
preg_match_all('/\?acct=([^"]*)/', $this->HTTP->getData('mail/pops.html'), $accountList);
if(count($accountList[1]) > 0)
{
return $accountList[1];
}
return false;
}
/**



LinkBack URL
About LinkBacks
Reply With Quote




