Файл: RootPanel 1.7.0 FreeCode/RootPanel 1.7.0 FreeCode/_rootinc/isp.inc.php
Строк: 539
<?
require_once($full_home_path."/_rootinc/todaynic/xmlbase.inc.php");
class ISPManager
{
public $controller = true;
public $protocol = null;
public $host = null;
public $folder = "manager";
public $user=null;
public $password = null;
public $errors=array();
public $fp=null;
/*
* initialization
*/
public function startup(&$controller) {
$this->controller =& $controller;
}
/*
* initialization
*/
public function init($protocol,$host,$user,$password,$folder='') {
$this->protocol=$protocol;
$this->host=$host;
$this->user=$user;
$this->password=$password;
if ($folder) {$this->folder=$folder;}
}
/*
* connect to the xml api
* Output: true on success, false on fail
*/
public function connect($api_path) {
$this->fp = curl_init();
curl_setopt($this->fp, CURLOPT_URL, $this->protocol."://".$this->host."/".$this->folder."/".$api_path);
curl_setopt($this->fp, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($this->fp, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->fp, CURLOPT_FAILONERROR, 0);
curl_setopt($this->fp, CURLOPT_RETURNTRANSFER,1);
curl_setopt($this->fp, CURLOPT_TIMEOUT, 120);
$result = curl_exec($this->fp);
curl_close($this->fp);
return $result;
}
/*
* create a ISPManager account
* Output: true on success, false on fail
*/
public function createAccount($acctDomain,$acctUser,$acctPass,$acctPackg,$acctIp,$acctEmail) {
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=user.edit&sok=yes&name=$acctUser&passwd=$acctPass&confirm=$acctPass&domain=$acctDomain&ip=$acctIp&owner=".$this->user."&preset=$acctPackg&email=$acctEmail&");
if($xmlstr=='') {
$this->errors[]='createAccount: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[ok][0])) {
if ($xmlArray[ok][0][value] == "restart") {
$this->restartApache();
}
return true;
} else if (isset($xmlArray[error][0])) {
$this->errors[] = "createAccount: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->errors[] = "createAccount: unknown error";
return false;
}
}
}
/*
* create a ISPManager reseller account
* Output: true on success, false on fail
*/
public function createResellerAccount($acctUser,$acctPass,$acctPackg,$acctIp,$acctEmail) {
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=reseller.edit&sok=yes&name=$acctUser&passwd=$acctPass&confirm=$acctPass&ip=$acctIp&preset=$acctPackg&email=$acctEmail");
if($xmlstr=='') {
$this->errors[]='createResellerAccount: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[ok][0])) {
if ($xmlArray[ok][0][value] == "restart") {
$this->restartApache();
}
return true;
} else if (isset($xmlArray[error][0])) {
$this->errors[] = "createResellerAccount: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->errors[] = "createResellerAccount: unknown error";
return false;
}
}
}
/*
* suspend a ISPManager account
* Output: true on success, false on fail
*/
public function suspend($acctUser) {
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=user.disable&elid=$acctUser&");
if($xmlstr=='') {
$this->errors[]='suspend: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[ok][0])) {
if ($xmlArray[ok][0][value] == "restart") {
$this->restartApache();
}
return true;
} else if (isset($xmlArray[error][0])) {
$this->errors[] = "suspend: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->errors[] = "suspend: unknown error";
return false;
}
}
}
/*
* suspend a ISPManager reseller account
* Output: true on success, false on fail
*/
public function suspendReseller($acctUser) {
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=reseller.disable&elid=$acctUser&");
if($xmlstr=='') {
$this->errors[]='suspendReseller: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[ok][0])) {
if ($xmlArray[ok][0][value] == "restart") {
$this->restartApache();
}
return true;
} else if (isset($xmlArray[error][0])) {
$this->errors[] = "suspendReseller: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->errors[] = "suspendReseller: unknown error";
return false;
}
}
}
/*
* unsuspend a ISPManager account
* Output: true on success, false on fail
*/
public function unsuspend($acctUser) {
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=user.enable&elid=$acctUser&");
if($xmlstr=='') {
$this->errors[]='unsuspend: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[ok][0])) {
if ($xmlArray[ok][0][value] == "restart") {
$this->restartApache();
}
return true;
} else if (isset($xmlArray[error][0])) {
$this->errors[] = "unsuspend: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->errors[] = "unsuspend: unknown error";
return false;
}
}
}
/*
* unsuspend a ISPManager reseller account
* Output: true on success, false on fail
*/
public function unsuspendReseller($acctUser) {
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=reseller.enable&elid=$acctUser&");
if($xmlstr=='') {
$this->errors[]='unsuspendReseller: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[ok][0])) {
if ($xmlArray[ok][0][value] == "restart") {
$this->restartApache();
}
return true;
} else if (isset($xmlArray[error][0])) {
$this->errors[] = "unsuspendReseller: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->errors[] = "unsuspendReseller: unknown error";
return false;
}
}
}
/*
* terminate a ISPManager account
* Output: true on success, false on fail
*/
public function terminate($acctUser) {
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=user.delete&elid=$acctUser&");
if($xmlstr=='') {
$this->errors[]='terminate: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[ok][0])) {
if ($xmlArray[ok][0][value] == "restart") {
$this->restartApache();
}
return true;
} else if (isset($xmlArray[error][0])) {
$this->errors[] = "terminate: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->errors[] = "terminate: unknown error";
return false;
}
}
}
/*
* terminate a ISPManager reseller account
* Output: true on success, false on fail
*/
public function terminateReseller($acctUser) {
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=reseller.delete&elid=$acctUser&");
if($xmlstr=='') {
$this->errors[]='terminateReseller: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[ok][0])) {
if ($xmlArray[ok][0][value] == "restart") {
$this->restartApache();
}
return true;
} else if (isset($xmlArray[error][0])) {
$this->errors[] = "terminateReseller: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->errors[] = "terminateReseller: unknown error";
return false;
}
}
}
/*
* restart Apache
* Output: true on success, false on fail
*/
public function restartApache()
{
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=restart&");
}
public function unzip($file,$dir)
{
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=file.extract&elid=$file&plid=$dir&");
if($xmlstr=='') {
$this->errors[]='unzip: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[ok][0])) {
return true;
} else if (isset($xmlArray[error][0])) {
$this->errors[] = "unzip: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->errors[] = "unzip: unknown error";
return false;
}
}
}
public function dbCreate($dbname,$dbuser,$dbpassword) {
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&name=$dbname&dbtype=MySQL&dbencoding=default&dbusername=$dbuser&dbpassword=$dbpassword&dbconfirm=$dbpassword&dbuserhost=on&func=db.edit&elid=&sok=yes&");
if($xmlstr=='') {
$this->errors[]='dbCreate: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[ok][0])) {
return true;
} else if (isset($xmlArray[error][0])) {
$this->errors[] = "dbCreate: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->errors[] = "dbCreate: unknown error";
return false;
}
}
}
public function getPackages() {
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=preset&");
if($xmlstr=='') {
$this->errors[]='getPackages: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[name][0][value])) {
while (list($i,$v) = each($xmlArray[name])) {
while (list($ii,$vv) = each($v)) {
$resArray[] = $vv;
}
}
return $resArray;
} else if (isset($xmlArray[error][0])) {
$this->errors[] = "getPackages: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->errors[] = "getPackages: unknown error";
return false;
}
}
}
public function getPackage($package) {
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=preset.edit&elid=$package&");
if($xmlstr=='') {
$this->errors[]='getPackage: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[name][0][value])) {
if (isset($xmlArray[shell][0])) { $resArray[shell] = "on"; } else { $resArray[shell] = "off"; }
if (isset($xmlArray[ssl][0])) { $resArray[ssl] = "on"; } else { $resArray[ssl] = "off"; }
if (isset($xmlArray[cgi][0])) { $resArray[cgi] = "on"; } else { $resArray[cgi] = "off"; }
if (isset($xmlArray[ssi][0])) { $resArray[ssi] = "on"; } else { $resArray[ssi] = "off"; }
if (isset($xmlArray[php][0])) { $resArray[php] = "on"; } else { $resArray[php] = "off"; }
if (isset($xmlArray[phpmod][0])) { $resArray[phpmod] = "on"; } else { $resArray[phpmod] = "off"; }
if (isset($xmlArray[phpcgi][0])) { $resArray[phpcgi] = "on"; } else { $resArray[phpcgi] = "off"; }
if (isset($xmlArray[phpfcgi][0])) { $resArray[phpfcgi] = "on"; } else { $resArray[phpfcgi] = "off"; }
if (isset($xmlArray[safemode][0])) { $resArray[safemode] = "on"; } else { $resArray[safemode] = "off"; }
$resArray[disklimit] = $xmlArray[disklimit][0][value];
$resArray[ftplimit] = $xmlArray[ftplimit][0][value];
$resArray[maillimit] = $xmlArray[maillimit][0][value];
$resArray[domainlimit] = $xmlArray[domainlimit][0][value];
$resArray[webdomainlimit] = $xmlArray[webdomainlimit][0][value];
$resArray[maildomainlimit] = $xmlArray[maildomainlimit][0][value];
$resArray[baselimit] = $xmlArray[baselimit][0][value];
$resArray[baseuserlimit] = $xmlArray[baseuserlimit][0][value];
$resArray[bandwidthlimit] = $xmlArray[bandwidthlimit][0][value];
if (isset($xmlArray[cpulimit][0])) { $resArray[cpulimit] = $xmlArray[cpulimit][0][value]; }
if (isset($xmlArray[memlimit][0])) { $resArray[memlimit] = $xmlArray[memlimit][0][value]; }
if (isset($xmlArray[proclimit][0])) { $resArray[proclimit] = $xmlArray[proclimit][0][value]; }
# only for reseller packages
if (isset($xmlArray[userlimit][0])) { $resArray[userlimit] = $xmlArray[userlimit][0][value]; }
return $resArray;
} else if (isset($xmlArray[error][0])) {
$this->errors[] = "getPackage: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->errors[] = "getPackage: unknown error";
return false;
}
}
}
public function getUser($user) {
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=user.edit&elid=$user&");
if($xmlstr=='') {
$this->errors[]='getUser: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[name][0][value])) {
while (list($i,$v) = each($xmlArray)) {
$resArray[$i] = $v[0][value];
}
return $resArray;
} else if (isset($xmlArray[error][0])) {
$this->errors[] = "getUser: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->errors[] = "getUser: unknown error";
return false;
}
}
}
public function getReseller($user) {
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=reseller.edit&elid=$user&");
if($xmlstr=='') {
$this->errors[]='getReseller: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[name][0][value])) {
while (list($i,$v) = each($xmlArray)) {
$resArray[$i] = $v[0][value];
}
return $resArray;
} else if (isset($xmlArray[error][0])) {
$this->errors[] = "getReseller: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->errors[] = "getReseller: unknown error";
return false;
}
}
}
public function changePackage($acctUser,$newPackage) {
$user = $this->getUser($acctUser);
$package = $this->getPackage($newPackage);
if (is_array($user) and is_array($package)) {
$user[preset] = $newPackage;
reset($package);
while (list($i,$v) = each($package)) {
$user[$i] = $v;
}
reset($user);
while (list($i,$v) = each($user)) {
$params = $params."$i=$v&";
}
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=user.edit&sok=yes&$params");
if($xmlstr=='') {
$this->errors[]='changePackage: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[ok][0])) {
if ($xmlArray[ok][0][value] == "restart") {
$this->restartApache();
}
return true;
} else if (isset($xmlArray[error][0])) {
$this->errors[] = "changePackage: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->errors[] = "changePackage: unknown error";
return false;
}
}
}
}
public function changeResellerPackage($acctUser,$newPackage) {
$user = $this->getReseller($acctUser);
$package = $this->getPackage($newPackage);
if (is_array($user) and is_array($package)) {
$user[preset] = $newPackage;
reset($package);
while (list($i,$v) = each($package)) {
$user[$i] = $v;
}
reset($user);
while (list($i,$v) = each($user)) {
$params = $params."$i=$v&";
}
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=reseller.edit&sok=yes&$params");
if($xmlstr=='') {
$this->errors[]='changeResellerPackage: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[ok][0])) {
if ($xmlArray[ok][0][value] == "restart") {
$this->restartApache();
}
return true;
} else if (isset($xmlArray[error][0])) {
$this->errors[] = "changeResellerPackage: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->errors[] = "changeResellerPackage: unknown error";
return false;
}
}
}
}
public function getWWWDomain($domain) {
//connect using proper xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=wwwdomain.edit&elid=$domain&");
if($xmlstr=='') {
$this->errors[]='getWWWDomain: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[domain][0][value])) {
while (list($i,$v) = each($xmlArray)) {
$resArray[$i] = $v[0][value];
}
return $resArray;
} else if (isset($xmlArray[error][0])) {
$this->errors[] = "getWWWDomain: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->errors[] = "getWWWDomain: unknown error";
return false;
}
}
}
public function addAlias($maindomain, $domain) {
$wwwDomain = $this->getWWWDomain($maindomain);
if (is_array($wwwDomain)) {
$wwwDomain['alias'] = $wwwDomain['alias']."%20".$domain."%20www.".$domain;
while (list($i,$v) = each($wwwDomain)) {
$params = $params."$i=$v&";
}
//connect using proper xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=wwwdomain.edit&sok=yes&$params");
if($xmlstr=='') {
$this->errors[]='addAlias: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[ok][0])) {
if ($xmlArray[ok][0][value] == "restart") {
$this->restartApache();
}
return true;
} else if (isset($xmlArray[error][0])) {
$this->errors[] = "addAlias: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->errors[] = "addAlias: unknown error";
return false;
}
}
}
}
/*
* add Domain
* Output: true on success, false on fail
*/
public function addDomain($domain,$ip,$ns,$mx,$owner,$webdomain,$maildomain) {
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=domain.edit&sok=yes&name=$domain&owner=$owner&ip=$ip&ns=$ns&mx=$mx&webdomain=$webdomain&maildomain=$maildomain");
if($xmlstr=='') {
$this->errors[]='addDomain: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[ok][0])) {
if ($xmlArray[ok][0][value] == "restart") {
$this->restartApache();
}
return true;
} else if (isset($xmlArray[error][0])) {
$this->errors[] = "addDomain: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->errors[] = "addDomain: unknown error";
return false;
}
}
}
public function getError($errorArray) {
$error = "Code: ".$errorArray[attributes][code].". ";
if ($errorArray[attributes][obj]) { $error = $error."Object: ".$errorArray[attributes][obj].". "; }
if ($errorArray[attributes][val]) { $error = $error."Val: ".$errorArray[attributes][val].". "; }
if ($errorArray[value]) { $error = $error."Error: ".$errorArray[value]."."; }
return $error;
}
}
?>