Файл: _rootinc/plesk10.inc.php
Строк: 563
<?
class Plesk10
{
public $protocol = null;
public $host = null;
public $user = null;
public $password = null;
public $error = null;
public function init($protocol,$host,$user,$password) {
$this->protocol = $protocol;
$this->host = $host;
$this->user = $user;
$this->password = $password;
}
public function send($xml) {
$fp = curl_init();
curl_setopt($fp, CURLOPT_URL, $this->protocol."://".$this->host.":8443/enterprise/control/agent.php");
curl_setopt($fp, CURLOPT_RETURNTRANSFER, true);
curl_setopt($fp, CURLOPT_POST, true);
curl_setopt($fp, CURLOPT_POSTFIELDS, $xml);
curl_setopt($fp, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($fp, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($fp, CURLOPT_FAILONERROR, false);
curl_setopt($fp, CURLOPT_TIMEOUT, 120);
curl_setopt($fp, CURLOPT_HTTPHEADER, array(
"HTTP_AUTH_LOGIN: $this->user",
"HTTP_AUTH_PASSWD: $this->password",
"Content-Type: text/xml"
));
$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 createCustomer($login, $password, $org, $name, $phone, $fax, $email, $address, $city, $state, $pcode, $country, $locale) {
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.6.3.0">
<customer>
<add>
<gen_info>
<cname>$org</cname>
<pname>$name</pname>
<login>$login</login>
<passwd>$password</passwd>
<phone>$phone</phone>
<fax>$fax</fax>
<email>$email</email>
<address>$address</address>
<city>$city</city>
<state>$state</state>
<pcode>$code</pcode>
<country>$country</country>
<locale>$locale</locale>
</gen_info>
</add>
</customer>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'createCustomer: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0][customer][0][add][0][result][0][status] == "ok") {
return $xmlArray[packet][0][customer][0][add][0][result][0][id];
} else if ($xmlArray[packet][0][customer][0][add][0][result][0][status] == "error") {
$this->error = "createCustomer: Code ".$xmlArray[packet][0][customer][0][add][0][result][0][errcode].", ".$xmlArray[packet][0][customer][0][add][0][result][0][errtext];
return false;
} else if ($xmlArray[packet][0][system][0][status] == "error") {
$this->error = "createCustomer: Code ".$xmlArray[packet][0][system][0][errcode].", ".$xmlArray[packet][0][system][0][errtext];
return false;
} else {
$this->error = "createCustomer: unknown error";
return false;
}
}
}
public function createSubscription($customerid, $domain, $ip, $login, $password, $package) {
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) {
$idna = new idna_convert();
$domain = $idna->encode($domain);
}
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.6.3.0">
<webspace>
<add>
<gen_setup>
<name>$domain</name>
<owner-id>$customerid</owner-id>
<htype>vrt_hst</htype>
<ip_address>$ip</ip_address>
<status>0</status>
</gen_setup>
<hosting>
<vrt_hst>
<property>
<name>ftp_login</name>
<value>$login</value>
</property>
<property>
<name>ftp_password</name>
<value>$password</value>
</property>
<ip_address>$ip</ip_address>
</vrt_hst>
</hosting>
<plan-name>$package</plan-name>
</add>
</webspace>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'createSubscription: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0][webspace][0][add][0][result][0][status] == "ok") {
return $xmlArray[packet][0][webspace][0][add][0][result][0][id];
} else if ($xmlArray[packet][0][webspace][0][add][0][result][0][status] == "error") {
$this->error = "createSubscription: Code ".$xmlArray[packet][0][webspace][0][add][0][result][0][errcode].", ".$xmlArray[packet][0][webspace][0][add][0][result][0][errtext];
return false;
} else if ($xmlArray[packet][0][system][0][status] == "error") {
$this->error = "createSubscription: Code ".$xmlArray[packet][0][system][0][errcode].", ".$xmlArray[packet][0][system][0][errtext];
return false;
} else {
$this->error = "createSubscription: unknown error";
return false;
}
}
}
public function createAlias($subscriptionid, $domain) {
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) {
$idna = new idna_convert();
$domain = $idna->encode($domain);
}
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.6.3.0">
<site-alias>
<create>
<name>$domain</name>
<site-id>$customerid</site-id>
</create>
</site-alias>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'createAlias: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0]["site-alias"][0][create][0][result][0][status] == "ok") {
return true;
} else if ($xmlArray[packet][0]["site-alias"][0][create][0][result][0][status] == "error") {
$this->error = "createAlias: Code ".$xmlArray[packet][0]["site-alias"][0][create][0][result][0][errcode].", ".$xmlArray[packet][0]["site-alias"][0][create][0][result][0][errtext];
return false;
} else if ($xmlArray[packet][0][system][0][status] == "error") {
$this->error = "createAlias: Code ".$xmlArray[packet][0][system][0][errcode].", ".$xmlArray[packet][0][system][0][errtext];
return false;
} else {
$this->error = "createAlias: unknown error";
return false;
}
}
}
public function deleteCustomer($customerid) {
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.6.3.0">
<customer>
<del>
<filter>
<id>$customerid</id>
</filter>
</del>
</customer>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'deleteCustomer: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0][customer][0][del][0][result][0][status] == "ok") {
return true;
} else if ($xmlArray[packet][0][customer][0][del][0][result][0][status] == "error") {
$this->error = "deleteCustomer: Code ".$xmlArray[packet][0][customer][0][del][0][result][0][errcode].", ".$xmlArray[packet][0][customer][0][del][0][result][0][errtext];
return false;
} else {
$this->error = "deleteCustomer: unknown error";
return false;
}
}
}
public function suspendCustomer($customerid) {
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.6.3.0">
<customer>
<set>
<filter>
<id>$customerid</id>
</filter>
<values>
<gen_info>
<status>16</status>
</gen_info>
</values>
</set>
</customer>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'suspendCustomer: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0][customer][0][set][0][result][0][status] == "ok") {
return true;
} else if ($xmlArray[packet][0][customer][0][set][0][result][0][status] == "error") {
$this->error = "suspendCustomer: Code ".$xmlArray[packet][0][customer][0][set][0][result][0][errcode].", ".$xmlArray[packet][0][customer][0][set][0][result][0][errtext];
return false;
} else if ($xmlArray[packet][0][system][0][status] == "error") {
$this->error = "suspendCustomer: Code ".$xmlArray[packet][0][system][0][errcode].", ".$xmlArray[packet][0][system][0][errtext];
return false;
} else {
$this->error = "suspendCustomer: unknown error";
return false;
}
}
}
public function unsuspendCustomer($customerid) {
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.6.3.0">
<customer>
<set>
<filter>
<id>$customerid</id>
</filter>
<values>
<gen_info>
<status>0</status>
</gen_info>
</values>
</set>
</customer>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'unsuspendCustomer: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0][customer][0][set][0][result][0][status] == "ok") {
return true;
} else if ($xmlArray[packet][0][customer][0][set][0][result][0][status] == "error") {
$this->error = "unsuspendCustomer: Code ".$xmlArray[packet][0][customer][0][set][0][result][0][errcode].", ".$xmlArray[packet][0][customer][0][set][0][result][0][errtext];
return false;
} else if ($xmlArray[packet][0][system][0][status] == "error") {
$this->error = "unsuspendCustomer: Code ".$xmlArray[packet][0][system][0][errcode].", ".$xmlArray[packet][0][system][0][errtext];
return false;
} else {
$this->error = "unsuspendCustomer: unknown error";
return false;
}
}
}
public function getServicePlans() {
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.6.3.0">
<service-plan>
<get>
<filter/>
</get>
</service-plan>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'getServicePlans: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0]["service-plan"][0][get][0][result][0][status] == "ok") {
while (list($id,$arr) = @each($xmlArray[packet][0]["service-plan"][0][get][0][result])) {
$resArray[] = $arr[name];
}
return $resArray;
} else if ($xmlArray[packet][0]["service-plan"][0][get][0][result][0][status] == "error") {
$this->error = "getServicePlans: Code ".$xmlArray[packet][0]["service-plan"][0][get][0][result][0][errcode].", ".$xmlArray[packet][0]["service-plan"][0][get][0][result][0][errtext];
return false;
} else if ($xmlArray[packet][0][system][0][status] == "error") {
$this->error = "getServicePlans: Code ".$xmlArray[packet][0][system][0][errcode].", ".$xmlArray[packet][0][system][0][errtext];
return false;
} else {
$this->error = "getServicePlans: unknown error";
return false;
}
}
}
public function switchSubscription($subscriptionid, $packageNew) {
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.6.3.0">
<webspace>
<switch-subscription>
<filter>
<id>$subscriptionid</id>
</filter>
<plan-name>$packageNew</plan-name>
</switch-subscription>
</webspace>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'switchSubscription: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0][webspace][0]["switch-subscription"][0][result][0][status] == "ok") {
return true;
} else if ($xmlArray[packet][0][webspace][0]["switch-subscription"][0][result][0][status] == "error") {
$this->error = "switchSubscription: Code ".$xmlArray[packet][0][webspace][0]["switch-subscription"][0][result][0][errcode].", ".$xmlArray[packet][0][webspace][0]["switch-subscription"][0][result][0][errtext];
return false;
} else if ($xmlArray[packet][0][system][0][status] == "error") {
$this->error = "switchSubscription: Code ".$xmlArray[packet][0][system][0][errcode].", ".$xmlArray[packet][0][system][0][errtext];
return false;
} else {
$this->error = "switchSubscription: unknown error";
return false;
}
}
}
public function changeCustomerPassword($customerid, $newPassword) {
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.6.3.0">
<customer>
<set>
<filter>
<id>$customerid</id>
</filter>
<values>
<gen_info>
<passwd>$newPassword</passwd>
</gen_info>
</values>
</set>
</customer>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'changeCustomerPassword: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0][customer][0][set][0][result][0][status] == "ok") {
return true;
} else if ($xmlArray[packet][0][customer][0][set][0][result][0][status] == "error") {
$this->error = "changeCustomerPassword: Code ".$xmlArray[packet][0][customer][0][set][0][result][0][errcode].", ".$xmlArray[packet][0][customer][0][set][0][result][0][errtext];
return false;
} else if ($xmlArray[packet][0][system][0][status] == "error") {
$this->error = "changeCustomerPassword: Code ".$xmlArray[packet][0][system][0][errcode].", ".$xmlArray[packet][0][system][0][errtext];
return false;
} else {
$this->error = "changeCustomerPassword: unknown error";
return false;
}
}
}
public function createReseller($login, $password, $org, $name, $phone, $fax, $email, $address, $city, $state, $pcode, $country, $locale, $package) {
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.6.3.0">
<reseller>
<add>
<gen-info>
<cname>$org</cname>
<pname>$name</pname>
<login>$login</login>
<passwd>$password</passwd>
<status>0</status>
<phone>$phone</phone>
<fax>$fax</fax>
<email>$email</email>
<address>$address</address>
<city>$city</city>
<state>$state</state>
<pcode>$code</pcode>
<country>$country</country>
<locale>$locale</locale>
</gen-info>
<plan-name>$package</plan-name>
</add>
</reseller>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'createReseller: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0][reseller][0][add][0][result][0][status] == "ok") {
return $xmlArray[packet][0][reseller][0][add][0][result][0][id];
} else if ($xmlArray[packet][0][reseller][0][add][0][result][0][status] == "error") {
$this->error = "createReseller: Code ".$xmlArray[packet][0][reseller][0][add][0][result][0][errcode].", ".$xmlArray[packet][0][reseller][0][add][0][result][0][errtext];
return false;
} else if ($xmlArray[packet][0][system][0][status] == "error") {
$this->error = "createReseller: Code ".$xmlArray[packet][0][system][0][errcode].", ".$xmlArray[packet][0][system][0][errtext];
return false;
} else {
$this->error = "createReseller: unknown error";
return false;
}
}
}
public function deleteReseller($resellerid) {
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.6.3.0">
<reseller>
<del>
<filter>
<id>$resellerid</id>
</filter>
</del>
</reseller>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'deleteReseller: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0][reseller][0][del][0][result][0][status] == "ok") {
return true;
} else if ($xmlArray[packet][0][reseller][0][del][0][result][0][status] == "error") {
$this->error = "deleteReseller: Code ".$xmlArray[packet][0][reseller][0][del][0][result][0][errcode].", ".$xmlArray[packet][0][reseller][0][del][0][result][0][errtext];
return false;
} else {
$this->error = "deleteReseller: unknown error";
return false;
}
}
}
public function suspendReseller($resellerid) {
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.6.3.0">
<reseller>
<set>
<filter>
<id>$resellerid</id>
</filter>
<values>
<gen-info>
<status>16</status>
</gen-info>
</values>
</set>
</reseller>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'suspendReseller: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0][reseller][0][set][0][result][0][status] == "ok") {
return true;
} else if ($xmlArray[packet][0][reseller][0][set][0][result][0][status] == "error") {
$this->error = "suspendReseller: Code ".$xmlArray[packet][0][reseller][0][set][0][result][0][errcode].", ".$xmlArray[packet][0][reseller][0][set][0][result][0][errtext];
return false;
} else if ($xmlArray[packet][0][system][0][status] == "error") {
$this->error = "suspendReseller: Code ".$xmlArray[packet][0][system][0][errcode].", ".$xmlArray[packet][0][system][0][errtext];
return false;
} else {
$this->error = "suspendReseller: unknown error";
return false;
}
}
}
public function unsuspendReseller($resellerid) {
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.6.3.0">
<reseller>
<set>
<filter>
<id>$resellerid</id>
</filter>
<values>
<gen-info>
<status>0</status>
</gen-info>
</values>
</set>
</reseller>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'unsuspendReseller: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0][reseller][0][set][0][result][0][status] == "ok") {
return true;
} else if ($xmlArray[packet][0][reseller][0][set][0][result][0][status] == "error") {
$this->error = "unsuspendReseller: Code ".$xmlArray[packet][0][reseller][0][set][0][result][0][errcode].", ".$xmlArray[packet][0][reseller][0][set][0][result][0][errtext];
return false;
} else if ($xmlArray[packet][0][system][0][status] == "error") {
$this->error = "unsuspendReseller: Code ".$xmlArray[packet][0][system][0][errcode].", ".$xmlArray[packet][0][system][0][errtext];
return false;
} else {
$this->error = "unsuspendReseller: unknown error";
return false;
}
}
}
public function getResellerPlans() {
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.6.3.0">
<reseller-plan>
<get>
<filter>
<all/>
</filter>
</get>
</reseller-plan>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'getResellerPlans: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0]["reseller-plan"][0][get][0][result][0][status] == "ok") {
while (list($id,$arr) = @each($xmlArray[packet][0]["reseller-plan"][0][get][0][result])) {
$resArray[] = $arr[name];
}
return $resArray;
} else if ($xmlArray[packet][0]["reseller-plan"][0][get][0][result][0][status] == "error") {
$this->error = "getResellerPlans: Code ".$xmlArray[packet][0]["reseller-plan"][0][get][0][result][0][errcode].", ".$xmlArray[packet][0]["reseller-plan"][0][get][0][result][0][errtext];
return false;
} else if ($xmlArray[packet][0][system][0][status] == "error") {
$this->error = "getResellerPlans: Code ".$xmlArray[packet][0][system][0][errcode].", ".$xmlArray[packet][0][system][0][errtext];
return false;
} else {
$this->error = "getResellerPlans: unknown error";
return false;
}
}
}
public function getResellerPlanGuid($package) {
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.6.3.0">
<reseller-plan>
<get>
<filter>
<name>$package</name>
</filter>
</get>
</reseller-plan>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'getResellerPlanGuid: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0]["reseller-plan"][0][get][0][result][0][status] == "ok") {
return $xmlArray[packet][0]["reseller-plan"][0][get][0][result][0][guid];
} else if ($xmlArray[packet][0]["reseller-plan"][0][get][0][result][0][status] == "error") {
$this->error = "getResellerPlanGuid: Code ".$xmlArray[packet][0]["reseller-plan"][0][get][0][result][0][errcode].", ".$xmlArray[packet][0]["reseller-plan"][0][get][0][result][0][errtext];
return false;
} else if ($xmlArray[packet][0][system][0][status] == "error") {
$this->error = "getResellerPlanGuid: Code ".$xmlArray[packet][0][system][0][errcode].", ".$xmlArray[packet][0][system][0][errtext];
return false;
} else {
$this->error = "getResellerPlanGuid: unknown error";
return false;
}
}
}
public function switchResellerPlan($resellerid, $packageNew) {
$packageNewGuid = $this->getResellerPlanGuid($packageNew);
if (!$packageNewGuid) { return false; }
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.6.3.0">
<reseller>
<switch-subscription>
<filter>
<id>$resellerid</id>
</filter>
<plan-guid>$packageNewGuid</plan-guid>
</switch-subscription>
</reseller>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'switchResellerPlan: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0][reseller][0]["switch-subscription"][0][result][0][status] == "ok") {
return true;
} else if ($xmlArray[packet][0][reseller][0]["switch-subscription"][0][result][0][status] == "error") {
$this->error = "switchResellerPlan: Code ".$xmlArray[packet][0][reseller][0]["switch-subscription"][0][result][0][errcode].", ".$xmlArray[packet][0][reseller][0]["switch-subscription"][0][result][0][errtext];
return false;
} else if ($xmlArray[packet][0][system][0][status] == "error") {
$this->error = "switchResellerPlan: Code ".$xmlArray[packet][0][system][0][errcode].", ".$xmlArray[packet][0][system][0][errtext];
return false;
} else {
$this->error = "switchResellerPlan: unknown error";
return false;
}
}
}
public function changeResellerPassword($resellerid, $newPassword) {
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.6.3.0">
<reseller>
<set>
<filter>
<id>$resellerid</id>
</filter>
<values>
<gen-info>
<passwd>$newPassword</passwd>
</gen-info>
</values>
</set>
</reseller>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'changeResellerPassword: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0][reseller][0][set][0][result][0][status] == "ok") {
return true;
} else if ($xmlArray[packet][0][reseller][0][set][0][result][0][status] == "error") {
$this->error = "changeResellerPassword: Code ".$xmlArray[packet][0][reseller][0][set][0][result][0][errcode].", ".$xmlArray[packet][0][reseller][0][set][0][result][0][errtext];
return false;
} else if ($xmlArray[packet][0][system][0][status] == "error") {
$this->error = "changeResellerPassword: Code ".$xmlArray[packet][0][system][0][errcode].", ".$xmlArray[packet][0][system][0][errtext];
return false;
} else {
$this->error = "changeResellerPassword: unknown error";
return false;
}
}
}
}
?>