Файл: _rootinc/plesk.inc.php
Строк: 416
<?
class Plesk
{
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}",
"HTTP_PRETTY_PRINT: TRUE",
"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 createUser($login, $password, $package, $org, $name, $phone, $fax, $email, $address, $city, $state, $code, $country, $lang) {
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.4.1.2">
<client>
<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>$lang</locale>
</gen_info>
<template-name>$package</template-name>
</add>
</client>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'createUser: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0][client][0][add][0][result][0][status] == "ok") {
return $xmlArray[packet][0][client][0][add][0][result][0][id];
} else if ($xmlArray[packet][0][client][0][add][0][result][0][status] == "error") {
$this->error = "createUser: Code ".$xmlArray[packet][0][client][0][add][0][result][0][errcode].", ".$xmlArray[packet][0][client][0][add][0][result][0][errtext];
return false;
} else if ($xmlArray[packet][0][system][0][status] == "error") {
$this->error = "createUser: Code ".$xmlArray[packet][0][system][0][errcode].", ".$xmlArray[packet][0][system][0][errtext];
return false;
} else {
$this->error = "createUser: unknown error";
return false;
}
}
}
public function createDomain($userid, $domain, $ip, $login, $password) {
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.4.1.2">
<domain>
<add>
<gen_setup>
<name>$domain</name>
<client_id>$userid</client_id>
<ip_address>$ip</ip_address>
</gen_setup>
<prefs>
<www>true</www>
</prefs>
<hosting>
<vrt_hst>
<ftp_login>$login</ftp_login>
<ftp_password>$password</ftp_password>
<ip_address>$ip</ip_address>
</vrt_hst>
</hosting>
<user>
<enabled>true</enabled>
<password>$password</password>
</user>
</add>
</domain>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'createDomain: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0][domain][0][add][0][result][0][status] == "ok") {
return $xmlArray[packet][0][domain][0][add][0][result][0][id];
} else if ($xmlArray[packet][0][domain][0][add][0][result][0][status] == "error") {
$this->error = "createDomain: Code ".$xmlArray[packet][0][domain][0][add][0][result][0][errcode].", ".$xmlArray[packet][0][domain][0][add][0][result][0][errtext];
return false;
} else {
$this->error = "createDomain: unknown error";
return false;
}
}
}
public function createAlias($domainid, $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.4.1.2">
<domain_alias>
<create>
<name>$domain</name>
<domain_id>$domainid</domain_id>
</create>
</domain_alias>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'createAlias: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0][domain_alias][0][create][0][result][0][status] == "ok") {
return true;
} else if ($xmlArray[packet][0][domain_alias][0][create][0][result][0][status] == "error") {
$this->error = "createAlias: Code ".$xmlArray[packet][0][domain_alias][0][create][0][result][0][errcode].", ".$xmlArray[packet][0][domain_alias][0][create][0][result][0][errtext];
return false;
} else {
$this->error = "createAlias: unknown error";
return false;
}
}
}
public function deleteUser($userid) {
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.4.1.2">
<client>
<del>
<filter>
<id>$userid</id>
</filter>
</del>
</client>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'deleteUser: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0][client][0][del][0][result][0][status] == "ok") {
return true;
} else if ($xmlArray[packet][0][client][0][del][0][result][0][status] == "error") {
$this->error = "deleteUser: Code ".$xmlArray[packet][0][client][0][del][0][result][0][errcode].", ".$xmlArray[packet][0][client][0][del][0][result][0][errtext];
return false;
} else {
$this->error = "deleteUser: unknown error";
return false;
}
}
}
public function suspendUser($id) {
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.5.2.1">
<client>
<set>
<filter>
<id>$id</id>
</filter>
<values>
<gen_info>
<status>16</status>
</gen_info>
</values>
</set>
</client>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'suspendUser: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0][client][0][set][0][result][0][status] == "ok") {
return true;
} else if ($xmlArray[packet][0][client][0][set][0][result][0][status] == "error") {
$this->error = "suspendUser: Code ".$xmlArray[packet][0][client][0][set][0][result][0][errcode].", ".$xmlArray[packet][0][client][0][set][0][result][0][errtext];
return false;
} else {
$this->error = "suspendUser: unknown error";
return false;
}
}
}
public function unsuspendUser($id) {
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.5.2.1">
<client>
<set>
<filter>
<id>$id</id>
</filter>
<values>
<gen_info>
<status>0</status>
</gen_info>
</values>
</set>
</client>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'unsuspendUser: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0][client][0][set][0][result][0][status] == "ok") {
return true;
} else if ($xmlArray[packet][0][client][0][set][0][result][0][status] == "error") {
$this->error = "unsuspendUser: Code ".$xmlArray[packet][0][client][0][set][0][result][0][errcode].", ".$xmlArray[packet][0][client][0][set][0][result][0][errtext];
return false;
} else {
$this->error = "unsuspendUser: unknown error";
return false;
}
}
}
public function getClientTemplates($package = '') {
if ($package) {
$filter="<name>$package</name>";
$limits="<limits></limits>";
$permissions="<permissions></permissions>";
}
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.4.1.2">
<client-template>
<get>
<filter>
$filter
</filter>
$limits
$permissions
</get>
</client-template>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'getClientTemplates: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0]["client-template"][0][get][0][result][0][status] == "ok") {
if ($xmlArray[packet][0]["client-template"][0][get][0][result][0][limits]) {
while (list($key,$value) = @each($xmlArray[packet][0]["client-template"][0][get][0][result][0][limits][0])) {
$resArray[limits]["$key"] = $value;
}
while (list($key,$value) = @each($xmlArray[packet][0]["client-template"][0][get][0][result][0][permissions][0])) {
$resArray[permissions]["$key"] = $value;
}
return $resArray;
} else {
while (list($id,$arr) = @each($xmlArray[packet][0]["client-template"][0][get][0][result])) {
$resArray[] = $arr[name];
}
return $resArray;
}
} else if ($xmlArray[packet][0]["client-template"][0][get][0][result][0][status] == "error") {
$this->error = "getClientTemplates: Code ".$xmlArray[packet][0]["client-template"][0][get][0][result][0][errcode].", ".$xmlArray[packet][0]["client-template"][0][get][0][result][0][errtext];
return false;
} else {
$this->error = "getClientTemplates: unknown error";
return false;
}
}
}
public function changePackage($userid, $packageNew) {
$package = $this->getClientTemplates($packageNew);
while (list($key,$value) = @each($package[limits])) {
$limits .= "<$key>$value</$key>n";
}
while (list($key,$value) = @each($package[permissions])) {
$permissions .= "<$key>$value</$key>n";
}
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.4.1.2">
<client>
<set>
<filter>
<id>$userid</id>
</filter>
<values>
<limits>
$limits
</limits>
<permissions>
$permissions
</permissions>
<template-name>$packageNew</template-name>
</values>
</set>
</client>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'changePackage: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0][client][0][set][0][result][0][status] == "ok") {
return true;
} else if ($xmlArray[packet][0][client][0][set][0][result][0][status] == "error") {
$this->error = "changePackage: Code ".$xmlArray[packet][0][client][0][set][0][result][0][errcode].", ".$xmlArray[packet][0][client][0][set][0][result][0][errtext];
return false;
} else {
$this->error = "changePackage: unknown error";
return false;
}
}
}
public function changeUserPassword($id, $newPassword) {
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.4.1.2">
<client>
<set>
<filter>
<id>$id</id>
</filter>
<values>
<gen_info>
<passwd>$newPassword</passwd>
</gen_info>
</values>
</set>
</client>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'changeUserPassword: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0][client][0][set][0][result][0][status] == "ok") {
return true;
} else if ($xmlArray[packet][0][client][0][set][0][result][0][status] == "error") {
$this->error = "changeUserPassword: Code ".$xmlArray[packet][0][client][0][set][0][result][0][errcode].", ".$xmlArray[packet][0][client][0][set][0][result][0][errtext];
return false;
} else {
$this->error = "changeUserPassword: unknown error";
return false;
}
}
}
public function changeDomainPassword($id, $newPassword) {
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="1.4.1.2">
<domain>
<set>
<filter>
<id>$id</id>
</filter>
<values>
<hosting>
<vrt_hst>
<ftp_password>$newPassword</ftp_password>
</vrt_hst>
</hosting>
<user>
<password>$newPassword</password>
</user>
</values>
</set>
</domain>
</packet>
EOF;
$xmlstr = $this->send($xml);
if ($xmlstr == '') {
$this->error = 'changeDomainPassword: No output.';
return false;
} else {
$xmlArray = xml2array($xmlstr);
if ($xmlArray[packet][0][domain][0][set][0][result][0][status] == "ok") {
return true;
} else if ($xmlArray[packet][0][domain][0][set][0][result][0][status] == "error") {
$this->error = "changeDomainPassword: Code ".$xmlArray[packet][0][domain][0][set][0][result][0][errcode].", ".$xmlArray[packet][0][domain][0][set][0][result][0][errtext];
return false;
} else {
$this->error = "changeDomainPassword: unknown error";
return false;
}
}
}
public function changePassword($userid,$domainid,$newPassword) {
if ($this->changeUserPassword($userid, $newPassword) and $this->changeDomainPassword($domainid, $newPassword)) {
return true;
} else {
return false;
}
}
}
?>