Файл: _rootinc/isp.inc.php
Строк: 799
<?
class ISPManager
{
public $protocol = null;
public $host = null;
public $folder = "manager";
public $user = null;
public $password = null;
public $error = null;
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;}
}
public function connect($query) {
$query = @preg_replace("/&$/ui","",$query);
$fp = curl_init();
curl_setopt($fp, CURLOPT_URL, $this->protocol."://".$this->host."/".$this->folder."/".$query);
curl_setopt($fp, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($fp, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($fp, CURLOPT_FAILONERROR, 0);
curl_setopt($fp, CURLOPT_RETURNTRANSFER,1);
curl_setopt($fp, CURLOPT_TIMEOUT, 120);
$result = curl_exec($fp);
if (@curl_errno($fp)) {
$this->error = "cURL Error ".@curl_errno($fp).": ".@curl_error($fp);
return false;
}
curl_close($fp);
return $result;
}
public function createAccount($acctDomain,$acctUser,$acctPass,$acctPackg,$acctIp,$acctEmail,$owner) {
if (!$owner) { $owner = $this->user; }
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$acctDomain)) {
$idna = new idna_convert();
$acctDomain = $idna->encode($acctDomain);
}
$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=".$owner."&preset=".urlencode($acctPackg)."&email=$acctEmail&");
if($xmlstr=='') {
$this->error='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->error = "createAccount: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "createAccount: unknown error";
return false;
}
}
}
public function createResellerAccount($acctUser,$acctPass,$acctPackg,$acctIp,$acctEmail,$ip) {
$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=".urlencode($acctPackg)."&email=$acctEmail&ip=$ip");
if($xmlstr=='') {
$this->error='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->error = "createResellerAccount: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "createResellerAccount: unknown error";
return false;
}
}
}
public function suspend($acctUser) {
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=user.disable&elid=$acctUser&");
if($xmlstr=='') {
$this->error='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->error = "suspend: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "suspend: unknown error";
return false;
}
}
}
public function suspendReseller($acctUser) {
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=reseller.disable&elid=$acctUser&");
if($xmlstr=='') {
$this->error='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->error = "suspendReseller: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "suspendReseller: unknown error";
return false;
}
}
}
public function unsuspend($acctUser) {
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=user.enable&elid=$acctUser&");
if($xmlstr=='') {
$this->error='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->error = "unsuspend: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "unsuspend: unknown error";
return false;
}
}
}
public function unsuspendReseller($acctUser) {
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=reseller.enable&elid=$acctUser&");
if($xmlstr=='') {
$this->error='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->error = "unsuspendReseller: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "unsuspendReseller: unknown error";
return false;
}
}
}
public function terminate($acctUser) {
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=user.delete&elid=$acctUser&");
if($xmlstr=='') {
$this->error='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->error = "terminate: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "terminate: unknown error";
return false;
}
}
}
public function terminateReseller($acctUser) {
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=reseller.delete&elid=$acctUser&");
if($xmlstr=='') {
$this->error='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->error = "terminateReseller: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "terminateReseller: unknown error";
return false;
}
}
}
public function restartApache()
{
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=restart&");
sleep(5);
}
public function unzip($file,$dir)
{
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=file.extract&elid=$file&plid=$dir&");
if($xmlstr=='') {
$this->error='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->error = "unzip: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "unzip: unknown error";
return false;
}
}
}
public function dbCreate($dbname,$dbuser,$dbpassword) {
$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->error='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->error = "dbCreate: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "dbCreate: unknown error";
return false;
}
}
}
public function getPackages() {
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=preset&");
if($xmlstr=='') {
$this->error='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->error = "getPackages: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "getPackages: unknown error";
return false;
}
}
}
public function getPackage($package) {
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=preset.edit&elid=".urlencode($package)."&");
if($xmlstr=='') {
$this->error='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->error = "getPackage: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "getPackage: unknown error";
return false;
}
}
}
public function getUser($user) {
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=user.edit&elid=$user&");
if($xmlstr=='') {
$this->error='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->error = "getUser: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "getUser: unknown error";
return false;
}
}
}
public function getReseller($user) {
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=reseller.edit&elid=$user&");
if($xmlstr=='') {
$this->error='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->error = "getReseller: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "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] = urlencode($newPackage);
reset($package);
while (list($i,$v) = each($package)) {
$user[$i] = $v;
}
reset($user);
while (list($i,$v) = each($user)) {
$params = $params."$i=$v&";
}
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=user.edit&sok=yes&$params");
if($xmlstr=='') {
$this->error='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->error = "changePackage: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "changePackage: unknown error";
return false;
}
}
}
}
public function changePassword($acctUser,$newPassword) {
$user = $this->getUser($acctUser);
if (is_array($user)) {
$user[passwd] = $newPassword;
$user[confirm] = $newPassword;
reset($user);
while (list($i,$v) = each($user)) {
$params = $params."$i=$v&";
}
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=user.edit&sok=yes&$params");
if($xmlstr=='') {
$this->error='changePassword: 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->error = "changePassword: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "changePassword: unknown error";
return false;
}
}
}
}
public function changeResellerPassword($acctUser,$newPassword) {
$user = $this->getReseller($acctUser);
if (is_array($user)) {
$user[passwd] = $newPassword;
$user[confirm] = $newPassword;
reset($user);
while (list($i,$v) = each($user)) {
$params = $params."$i=$v&";
}
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=reseller.edit&sok=yes&$params");
if($xmlstr=='') {
$this->error='changeResellerPassword: 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->error = "changeResellerPassword: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "changeResellerPassword: 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] = urlencode($newPackage);
reset($package);
while (list($i,$v) = each($package)) {
$user[$i] = $v;
}
reset($user);
while (list($i,$v) = each($user)) {
$params = $params."$i=$v&";
}
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=reseller.edit&sok=yes&$params");
if($xmlstr=='') {
$this->error='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->error = "changeResellerPackage: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "changeResellerPackage: unknown error";
return false;
}
}
}
}
public function getWWWDomain($domain) {
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) {
$idna = new idna_convert();
$domain = $idna->encode($domain);
}
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=wwwdomain.edit&elid=$domain&");
if($xmlstr=='') {
$this->error='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->error = "getWWWDomain: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "getWWWDomain: unknown error";
return false;
}
}
}
public function addAlias($maindomain, $domain) {
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) {
$idna = new idna_convert();
$domain = $idna->encode($domain);
}
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$maindomain)) {
$idna = new idna_convert();
$maindomain = $idna->encode($maindomain);
}
$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&";
}
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=wwwdomain.edit&sok=yes&$params");
if($xmlstr=='') {
$this->error='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->error = "addAlias: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "addAlias: unknown error";
return false;
}
}
}
}
public function addDomain($domain,$ip,$ns,$mx,$owner,$webdomain,$maildomain) {
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) {
$idna = new idna_convert();
$domain = $idna->encode($domain);
}
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$webdomain)) {
$idna = new idna_convert();
$webdomain = $idna->encode($webdomain);
}
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$maildomain)) {
$idna = new idna_convert();
$maildomain = $idna->encode($maildomain);
}
$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->error='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->error = "addDomain: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "addDomain: unknown error";
return false;
}
}
}
public function deleteDomain($domain) {
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) {
$idna = new idna_convert();
$domain = $idna->encode($domain);
}
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=domain.delete&sok=ok&elid=$domain");
if($xmlstr=='') {
$this->error='deleteDomain: 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->error = "deleteDomain: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "deleteDomain: unknown error";
return false;
}
}
}
public function getDNS($domain) {
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) {
$idna = new idna_convert();
$domain = $idna->encode($domain);
}
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=domain.sublist&elid=$domain");
if($xmlstr=='') {
$this->error='deleteDomain: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if ($xmlArray[plid][0][value]) {
$result = array();
for ($i=0; $i<count($xmlArray[name]); $i++) {
$res = $this->getDNSOne($domain,$xmlArray[key][$i][value]);
if ($res) {
$result[$i][key] = $xmlArray[key][$i][value];
$result[$i][name] = $res[name];
$result[$i][type] = strtoupper($res[sdtype]);
$result[$i][addr] = $res[addr];
$result[$i][prio] = $res[prio];
}
}
if (count($result) > 0) {
return $result;
} else {
return false;
}
} else if (isset($xmlArray[error][0])) {
$this->error = "getDNS: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "getDNS: unknown error";
return false;
}
}
}
public function getDNSOne($domain,$key) {
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) {
$idna = new idna_convert();
$domain = $idna->encode($domain);
}
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=domain.sublist.edit&plid=$domain&elid=".urlencode($key));
if($xmlstr=='') {
$this->error='getDNSOne: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if ($xmlArray[sdtype][0][value]) {
$result[name] = $xmlArray[name][0][value];
$result[sdtype] = $xmlArray[sdtype][0][value];
$result[addr] = $xmlArray[addr][0][value];
$result[prio] = $xmlArray[prio][0][value];
return $result;
} else if (isset($xmlArray[error][0])) {
$this->error = "getDNSOne: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "getDNSOne: unknown error";
return false;
}
}
}
public function updateDNS($domain,$dns) {
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) {
$idna = new idna_convert();
$domain = $idna->encode($domain);
}
for ($i=0; $i<count($dns); $i++) {
$res = $this->updateDNSOne($domain,$dns[$i][key],trim($dns[$i][name]),trim($dns[$i][type]),trim($dns[$i][prio]),trim($dns[$i][addr]));
if (!$res) {
return false;
}
}
return true;
}
public function updateDNSOne($domain,$key,$name,$type,$prio,$addr) {
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) {
$idna = new idna_convert();
$domain = $idna->encode($domain);
}
if ($prio) {$prio = "&prio=$prio";}
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=domain.sublist.edit&sok=yes&plid=$domain&elid=".urlencode($key)."&name=$name&sdtype=$type&addr=".urlencode($addr).$prio);
if($xmlstr=='') {
$this->error='updateDNSOne: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[ok][0])) {
return true;
} else if (isset($xmlArray[error][0])) {
$this->error = "updateDNSOne: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "updateDNSOne: unknown error";
return false;
}
}
}
public function createDNS($domain,$name,$type,$addr,$prio) {
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) {
$idna = new idna_convert();
$domain = $idna->encode($domain);
}
if ($prio) {$prio = "&prio=$prio";}
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=domain.sublist.edit&sok=yes&plid=$domain&name=$name&sdtype=$type&addr=".urlencode($addr).$prio);
if($xmlstr=='') {
$this->error='createDNS: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[ok][0])) {
return true;
} else if (isset($xmlArray[error][0])) {
$this->error = "createDNS: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "createDNS: unknown error";
return false;
}
}
}
public function deleteDNS($domain,$key) {
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) {
$idna = new idna_convert();
$domain = $idna->encode($domain);
}
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=domain.sublist.delete&plid=$domain&elid=".urlencode($key));
if($xmlstr=='') {
$this->error='deleteDNS: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[ok][0])) {
return true;
} else if (isset($xmlArray[error][0])) {
$this->error = "deleteDNS: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "deleteDNS: unknown error";
return false;
}
}
}
public function assignIP($user,$ip) {
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=iplist.edit&sok=yes&elid=$ip&stat=assigned&owner=$user");
if($xmlstr=='') {
$this->error='assignIP: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[ok][0])) {
return true;
} else if (isset($xmlArray[error][0])) {
$this->error = "assignIP: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "assignIP: unknown error";
return false;
}
}
}
public function addMutualIp($user, $ip) {
//connect using prpoer xml api address
$xmlstr = $this->connect("ispmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=iplist.users.enable&elid=$user&plid=$ip");
if($xmlstr=='') {
$this->error='addMutualIp: No output.';
return false;
} else {
$xmlArray = toarray($xmlstr,"doc",1);
if (isset($xmlArray[ok][0])) {
return true;
} else if (isset($xmlArray[error][0])) {
$this->error = "addMutualIp: ".$this->getError($xmlArray[error][0]);
return false;
} else {
$this->error = "addMutualIp: 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;
}
}
?>