Файл: _rootinc/solusvm.inc.php
Строк: 192
<?
class SolusVM
{
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($postfields) {
$postfields["id"] = $this->user;
$postfields["key"] = $this->password;
if ($this->protocol == "http") {$port = "5353";}
else if ($this->protocol == "https") {$port = "5656";}
$fp = curl_init();
curl_setopt($fp, CURLOPT_URL, $this->protocol."://".$this->host.":".$port."/api/admin/command.php");
curl_setopt($fp, CURLOPT_POST, 1);
curl_setopt($fp, CURLOPT_TIMEOUT, 20);
curl_setopt($fp, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($fp, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($fp, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($fp, CURLOPT_HTTPHEADER, array("Expect:"));
curl_setopt($fp, CURLOPT_HEADER, 0);
curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($fp, CURLOPT_POSTFIELDS, $postfields);
$result = curl_exec($fp);
if (@curl_errno($fp)) {
$this->error = "cURL Error ".@curl_errno($fp).": ".@curl_error($fp);
return false;
}
curl_close($fp);
preg_match_all('/<(.*?)>([^<]+)</\1>/i', $result, $match);
$result = array();
foreach ($match[1] as $x => $y)
{
$result[$y] = $match[2][$x];
}
return $result;
}
public function createClient($username,$password,$email,$firstname,$lastname,$company) {
$postfields["action"] = "client-create";
$postfields["username"] = $username;
$postfields["password"] = $password;
$postfields["email"] = $email;
$postfields["firstname"] = $firstname;
$postfields["lastname"] = $lastname;
$postfields["company"] = $company;
$result = $this->send($postfields);
if ($result["status"] == "success") {
return $result["username"];
} else if ($result["status"] == "error") {
$this->error = "createClient: ".$result["statusmsg"];
return false;
} else {
$this->error = "createClient: no output";
return false;
}
}
public function createServer($type,$node,$hostname,$password,$username,$plan,$template,$ips,$nodegroup) {
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$hostname)) {
$idna = new idna_convert();
$hostname = $idna->encode($hostname);
}
$postfields["action"] = "vserver-create";
$postfields["type"] = $type;
$postfields["node"] = $node;
if ($nodegroup) { $postfields["nodegroup"] = $nodegroup; }
$postfields["hostname"] = $hostname;
$postfields["password"] = $password;
$postfields["username"] = $username;
$postfields["plan"] = $plan;
$postfields["template"] = $template;
$postfields["ips"] = $ips;
$result = $this->send($postfields);
if ($result["status"] == "success") {
return $result;
} else if ($result["status"] == "error") {
$this->error = "createServer: ".$result["statusmsg"];
return false;
} else {
$this->error = "createServer: no output";
return false;
}
}
public function suspendServer($vserverid) {
$postfields["action"] = "vserver-suspend";
$postfields["vserverid"] = $vserverid;
$result = $this->send($postfields);
if ($result["status"] == "success") {
return true;
} else if ($result["status"] == "error") {
$this->error = "suspendServer: ".$result["statusmsg"];
return false;
} else {
$this->error = "suspendServer: no output";
return false;
}
}
public function unSuspendServer($vserverid) {
$postfields["action"] = "vserver-unsuspend";
$postfields["vserverid"] = $vserverid;
$result = $this->send($postfields);
if ($result["status"] == "success") {
return true;
} else if ($result["status"] == "error") {
$this->error = "unSuspendServer: ".$result["statusmsg"];
return false;
} else {
$this->error = "unSuspendServer: no output";
return false;
}
}
public function terminateServer($vserverid) {
$postfields["action"] = "vserver-terminate";
$postfields["vserverid"] = $vserverid;
$postfields["deleteclient"] = false;
$result = $this->send($postfields);
if ($result["status"] == "success") {
return true;
} else if ($result["status"] == "error") {
$this->error = "terminateServer: ".$result["statusmsg"];
return false;
} else {
$this->error = "terminateServer: no output";
return false;
}
}
public function changePlan($vserverid,$plan) {
$postfields["action"] = "vserver-change";
$postfields["vserverid"] = $vserverid;
$postfields["plan"] = $plan;
$result = $this->send($postfields);
if ($result["status"] == "success") {
return true;
} else if ($result["status"] == "error") {
$this->error = "changePlan: ".$result["statusmsg"];
return false;
} else {
$this->error = "changePlan: no output";
return false;
}
}
public function restartServer($vserverid) {
$postfields["action"] = "vserver-reboot";
$postfields["vserverid"] = $vserverid;
$result = $this->send($postfields);
if ($result["status"] == "success") {
return true;
} else if ($result["status"] == "error") {
$this->error = "restartServer: ".$result["statusmsg"];
return false;
} else {
$this->error = "restartServer: no output";
return false;
}
}
public function reinstallServer($vserverid,$template) {
$postfields["action"] = "vserver-rebuild";
$postfields["vserverid"] = $vserverid;
$postfields["template"] = $template;
$result = $this->send($postfields);
if ($result["status"] == "success") {
return true;
} else if ($result["status"] == "error") {
$this->error = "reinstallServer: ".$result["statusmsg"];
return false;
} else {
$this->error = "reinstallServer: no output";
return false;
}
}
public function changeClientPassword($username,$password) {
$postfields["action"] = "client-updatepassword";
$postfields["username"] = $username;
$postfields["password"] = $password;
$result = $this->send($postfields);
if ($result["status"] == "success") {
return true;
} else if ($result["status"] == "error") {
$this->error = "changeClientPassword: ".$result["statusmsg"];
return false;
} else {
$this->error = "changeClientPassword: no output";
return false;
}
}
public function changeServerPassword($vserverid,$rootpassword) {
$postfields["action"] = "vserver-rootpassword";
$postfields["vserverid"] = $vserverid;
$postfields["rootpassword"] = $rootpassword;
$result = $this->send($postfields);
if ($result["status"] == "success") {
return true;
} else if ($result["status"] == "error") {
$this->error = "changeServerPassword: ".$result["statusmsg"];
return false;
} else {
$this->error = "changeServerPassword: no output";
return false;
}
}
public function addExtraIP($vserverid) {
$postfields["action"] = "vserver-addip";
$postfields["vserverid"] = $vserverid;
$result = $this->send($postfields);
if ($result["status"] == "success") {
return $result["ipaddress"];
} else if ($result["status"] == "error") {
$this->error = "addExtraIP: ".$result["statusmsg"];
return false;
} else {
$this->error = "addExtraIP: no output";
return false;
}
}
}
?>