From fad0f1958291431b7ebf2ef95eb1cf1915ca7ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=BA=D9=84=D8=A7=D9=85=D8=B1=D8=B6=D8=A7=20=D8=A8=D9=87?= =?UTF-8?q?=D8=B4=D8=AA=DB=8C=D8=A7=D9=86?= Date: Mon, 22 Nov 2021 15:55:27 +0330 Subject: [PATCH 01/18] Start Virtualizor Gate --- .gitignore | 1 + composer.json | 19 + enduser.php | 694 ------------------ src/PostData/BasePostData.php | 117 +++ src/PostData/BasePostDataInterface.php | 30 + src/PostData/CreateVS.php | 175 +++++ src/PostData/Space.php | 12 + src/Responses/Admin/ListVs.php | 224 ++++++ src/Responses/Admin/OsTemplate.php | 73 ++ src/Responses/Admin/Server.php | 195 +++++ src/Responses/Admin/VS.php | 396 +++++++++++ src/Responses/BaseResponse.php | 25 + src/VirtualizorAdmin.php | 947 +++++++++++++++++++++++++ src/VirtualizorClient.php | 723 +++++++++++++++++++ 14 files changed, 2937 insertions(+), 694 deletions(-) create mode 100644 .gitignore create mode 100644 composer.json delete mode 100644 enduser.php create mode 100644 src/PostData/BasePostData.php create mode 100644 src/PostData/BasePostDataInterface.php create mode 100644 src/PostData/CreateVS.php create mode 100644 src/PostData/Space.php create mode 100644 src/Responses/Admin/ListVs.php create mode 100644 src/Responses/Admin/OsTemplate.php create mode 100644 src/Responses/Admin/Server.php create mode 100644 src/Responses/Admin/VS.php create mode 100644 src/Responses/BaseResponse.php create mode 100644 src/VirtualizorAdmin.php create mode 100644 src/VirtualizorClient.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57872d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/vendor/ diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..354dd41 --- /dev/null +++ b/composer.json @@ -0,0 +1,19 @@ +{ + "name": "yiiman/virtualizor", + "description": "Tiny SDK for virtualizor", + "type": "library", + "license": "Apache", + "autoload": { + "psr-4": { + "YiiMan\\VirtualizorSdk\\": "src/" + } + }, + "authors": [ + { + "name": "غلامرضا بهشتیان", + "email": "amintado@gmail.com" + } + ], + "minimum-stability": "stable", + "require": {} +} diff --git a/enduser.php b/enduser.php deleted file mode 100644 index d7e97e3..0000000 --- a/enduser.php +++ /dev/null @@ -1,694 +0,0 @@ -key = $key; - $this->pass = $pass; - $this->ip = $ip; - $this->port = $port; - if(!($port == 4083 || $port == 443)){ - $this->protocol = 'http'; - } - } - - /** - * Dumps a variable - * - * @author Pulkit Gupta - * @param array $re The Array or any other variable. - * @return NULL - */ - function r($re){ - echo '
';
-		print_r($re);
-		echo '
'; - } - - /** - * Unserializes a string - * - * @author Pulkit Gupta - * @param string $str The serialized string - * @return array The unserialized array on success OR false on failure - */ - function _unserialize($str){ - - $var = @unserialize($str); - - if(empty($var)){ - - $str = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'._strlen('$2').':\"$2\";'", $str); - - $var = @unserialize($str); - - } - - //If it is still empty false - if(empty($var)){ - - return false; - - }else{ - - return $var; - - } - - } - - /** - * Makes an API request to the server to do a particular task - * - * @author Pulkit Gupta - * @param string $path The action you want to do - * @param array $post An array of DATA that should be posted - * @param array $cookies An array FOR SENDING COOKIES - * @return array The unserialized array on success OR false on failure - */ - function call($path, $post = array(), $cookies = array()){ - - $url = ($this->protocol).'://'.$this->ip.':'.$this->port.'/'.$path; - $url .= (strstr($url, '?') ? '' : '?'); - $url .= '&api=serialize&apikey='.rawurlencode($this->key).'&apipass='.rawurlencode($this->pass); - - // Set the curl parameters. - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - - // Time OUT - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); - - // Turn off the server and peer verification (TrustManager Concept). - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); - - // UserAgent - curl_setopt($ch, CURLOPT_USERAGENT, 'Virtualizor'); - - // Cookies - if(!empty($cookies)){ - curl_setopt($ch, CURLOPT_COOKIESESSION, true); - curl_setopt($ch, CURLOPT_COOKIE, http_build_query($cookies, '', '; ')); - } - - if(!empty($post)){ - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); - } - - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - - // Get response from the server. - $resp = curl_exec($ch); - curl_close($ch); - - // The following line is a method to test - //if(preg_match('/sync/is', $url)) echo $resp; - - if(empty($resp)){ - return false; - } - - $r = $this->_unserialize($resp); - - if(empty($r)){ - return false; - } - - return $r; - - } - - /** - * List the Virtual Servers in your account - * - * @author Pulkit Gupta - * @return array The array containing a list of Virtual Servers one has in their account - */ - function listvs(){ - - $resp = $this->call('index.php?act=listvs'); - - return $resp['vs']; - - } - - - /** - * START a Virtual Server - * - * @author Pulkit Gupta - * @param int $vid The VMs ID - * @return bool TRUE on success or FALSE on failure - */ - function start($vid){ - - // Make the Request - $res = $this->call('index.php?svs='.$vid.'&act=start&do=1'); - - // Did it finish ? - if(!empty($res['done'])){ - return true; - }else{ - return false; - } - - } - - - /** - * STOP a Virtual Server - * - * @author Pulkit Gupta - * @param int $vid The VMs ID - * @return bool TRUE on success or FALSE on failure - */ - function stop($vid){ - - // Make the Request - $res = $this->call('index.php?svs='.$vid.'&act=stop&do=1'); - - // Did it finish ? - if(!empty($res['done'])){ - return true; - }else{ - return false; - } - - } - - - /** - * RESTART a Virtual Server - * - * @author Pulkit Gupta - * @param int $vid The VMs ID - * @return bool TRUE on success or FALSE on failure - */ - function restart($vid){ - - // Make the Request - $res = $this->call('index.php?svs='.$vid.'&act=restart&do=1'); - - // Did it finish ? - if(!empty($res['done'])){ - return true; - }else{ - return false; - } - - } - - - /** - * POWER OFF a Virtual Server - * - * @author Pulkit Gupta - * @param int $vid The VMs ID - * @return bool TRUE on success or FALSE on failure - */ - function poweroff($vid){ - - // Make the Request - $res = $this->call('index.php?svs='.$vid.'&act=poweroff&do=1'); - - // Did it finish ? - if(!empty($res['done'])){ - return true; - }else{ - return false; - } - - } - - - /** - * STOP a Virtual Server - * - * @author Pulkit Gupta - * @param int $vid The VMs ID - * @return int 1 if the VM is ON, 0 if its OFF - */ - function status($vid){ - - // Make the Request - $res = $this->call('index.php?svs='.$vid.'&act=start'); - - return $res['status']; - - } - - /** - * GET or SET the hostname of a VM. To get the current hostname dont pass the $newhostname parameter - * - * @author Pulkit Gupta - * @param int $vid The VMs ID - * @param string $newhostname The new HOSTNAME of the virtual server. - * @return string The CURRENT hostname is returned if $newhostname is NULL. - * FALSE is returned if there was an error while setting the new hostname - * 'onboot' is returned if the new hostname will be set when the VPS is STOPPED and STARTED - * 'done' is returned if the new hostname has been set right now - Mainly OpenVZ - */ - function hostname($vid, $newhostname = NULL){ - - // Are we to change ? - if(!empty($newhostname)){ - - $post = array('newhost' => $newhostname, - 'changehost' => 'Change Hostname'); - - $resp = $this->call('index.php?svs='.$vid.'&act=hostname', $post); - - // Was there an error - if(!empty($resp['error'])){ - - $this->error = $resp['error']; - return false; - - // Will it be done when the VPS is STOPPED and STARTED ? - }elseif(!empty($resp['onboot'])){ - - return 'onboot'; - - // It was done successfully - }elseif(!empty($resp['done'])){ - - return 'done'; - - } - - // Just return the CURRENT HOSTNAME - }else{ - $resp = $this->call('index.php?svs='.$vid.'&act=hostname'); - return $resp['current']; - } - - } - - - /** - * GET the CPU details of a VM. Incase of Xen / KVM, only information is available as usage cannot be sensed. - * - * @author Pulkit Gupta - * @param int $vid The VMs ID - * @return array An array containing the details is returned. Usage details is available only in case of OpenVZ. - */ - function cpu($vid){ - - $resp = $this->call('index.php?svs='.$vid.'&act=cpu'); - - return $resp['cpu']; - - } - - /** - * GET the RAM details of a VM. Incase of Xen / KVM, only information is available as usage cannot be sensed. - * - * @author Pulkit Gupta - * @param int $vid The VMs ID - * @return array An array containing the details is returned. Usage details is available only in case of OpenVZ. - */ - function ram($vid){ - - $resp = $this->call('index.php?svs='.$vid.'&act=ram'); - - return $resp['ram']; - - } - - - /** - * GET the Disk details of a VM. Incase of Xen / KVM, only information is available as usage cannot be sensed. - * - * @author Pulkit Gupta - * @param int $vid The VMs ID - * @return array An array containing the details is returned. Usage details is available only in case of OpenVZ. - */ - function disk($vid){ - - $resp = $this->call('index.php?svs='.$vid.'&act=disk'); - - $ret['disk'] = $resp['disk']; - $ret['inodes'] = $resp['inodes']; - - return $ret; - - } - - /** - * GET the Bandwidth Usage of a VM. - * - * @author Pulkit Gupta - * @param int $vid The VMs ID - * @param int $month The month in the format YYYYMM e.g. 201205 is for the Month of May, 2012 - * @return array Returns an array of Bandwidth Information for the Month GIVEN. - * By Default the CURRENT MONTH details are returned - */ - function bandwidth($vid, $month = 0){ - - $resp = $this->call('index.php?svs='.$vid.'&act=bandwidth'.(!empty($month) ? '&show='.$month : '')); - - return $resp['bandwidth']; - - } - - - /** - * List the Processes in a VPS - Only OpenVZ - * - * @author Pulkit Gupta - * @param int $vid The VMs ID - * @return array An array containing all the processes is returned - */ - function processes($vid){ - - $resp = $this->call('index.php?svs='.$vid.'&act=processes'); - - return $resp['processes']; - - } - - - /** - * List the Services in a VPS - Only OpenVZ - * - * @author Pulkit Gupta - * @param int $vid The VMs ID - * @return array An array containing all the services is returned - */ - function services($vid){ - - $resp = $this->call('index.php?svs='.$vid.'&act=services'); - - $ret['services'] = $resp['services']; - $ret['autostart'] = $resp['autostart']; - $ret['running'] = $resp['running']; - - return $ret; - - } - - - /** - * Changes the root password of a VPS - * - * @author Pulkit Gupta - * @param int $vid The VMs ID - * @param string $pass The new password to set - * @return string FALSE is returned if there was an error while setting the new password - * 'onboot' is returned if the new password will be set when the VPS is STOPPED and STARTED - * 'done' is returned if the new password has been set right now - Mainly OpenVZ - */ - function changepassword($vid, $pass) { - - $post = array('newpass' => $pass, - 'conf' => $pass, - 'changepass' => 'Change Password' - ); - - $resp = $this->call('index.php?svs='.$vid.'&act=changepassword', $post); - - // Was there an error - if(!empty($resp['error'])){ - - $this->error = $resp['error']; - return false; - - // Will it be done when the VPS is STOPPED and STARTED ? - }elseif(!empty($resp['onboot'])){ - - return 'onboot'; - - // It was done successfully - }elseif(!empty($resp['done'])){ - - return 'done'; - - } - - } - - /** - * Get the VNC Details like PORT, IP, VNC Password. Only available in case of Xen and KVM VPS if VNC is enabled. - * - * @author Pulkit Gupta - * @param int $vid The VMs ID - * @return array An array containing all the VNC Details - */ - function vnc($vid){ - - $resp = $this->call('index.php?svs='.$vid.'&act=vnc'); - - return $resp['info']; - - } - - /** - * Change the VNC Password. Only available in case of Xen and KVM VPS if VNC is enabled. - * - * @author Pulkit Gupta - * @param int $vid The VMs ID - * @param string $pass The new password to set - * @return string FALSE is returned if there was an error while setting the new password - * 'onboot' is returned if the new password will be set when the VPS is STOPPED and STARTED - */ - function vncpass($vid, $pass) { - - $post = array('newpass' => $pass, - 'conf' => $pass, - 'vncpass' => 'Change Password' - ); - - $resp = $this->call('index.php?svs='.$vid.'&act=vncpass', $post); - - // Was there an error - if(!empty($resp['error'])){ - - $this->error = $resp['error']; - return false; - - // Will it be done when the VPS is STOPPED and STARTED ? - }elseif(!empty($resp['onboot']) || !empty($resp['done'])){ - - return 'onboot'; - - } - - } - - /** - * Re-installs a VPS if the $newosid is specified. If the $newosid is not passed, - * then this function will return an array of available templates. - * - * @author Pulkit Gupta - * @param int $vid The VMs ID - * @param int $newosid The Operating System ID (you got from the list) that will be installed on the VPS. - * @param string $newpass The new root password to set - * @return string FALSE is returned if there was an error while setting the new password - * string 'onboot' is returned if the new password will be set when the VPS is STOPPED and STARTED - * string 'done' is returned if the new password has been set right now - Mainly OpenVZ - * array An array of the list of avvailable OS Templates is returned if $newosid is NULL - */ - function ostemplate($vid, $newosid = NULL, $newpass = NULL){ - - // Get the list of OS Templates - $resp = $this->call('index.php?svs='.$vid.'&act=ostemplate'); - - // Get a list of Virtual Servers - $listvs = $this->listvs(); - - // Is there such a VPS ? - if(!empty($listvs[$vid])){ - - $resp = $resp['oslist'][$listvs[$vid]['virt']]; - - // No such VPS. Return an EMPTY ARRAY - }else{ - - return array(); - - } - - if(!empty($newosid)){ - - // The POST Vars - $post = array('newos' => $newosid, - 'newpass' => $newpass, - 'conf' => $newpass, - 'reinsos' => 'Reinstall'); - - $resp = $this->call('index.php?svs='.$vid.'&act=ostemplate', $post); - - // Was there an error - if(!empty($resp['error'])){ - - $this->error = $resp['error']; - return false; - - // Will it be done when the VPS is STOPPED and STARTED ? - }elseif(!empty($resp['onboot'])){ - - return 'onboot'; - - // It was done successfully - }elseif(!empty($resp['done'])){ - - return 'done'; - - } - - // Just return the OS List - }else{ - return $resp; - } - - } - - - /** - * Install a Control Panel - * - * @author Pulkit Gupta - * @param int $vid The VMs ID - * @param string $panel The Name of the Panel you want to install. Options - cpanel, plesk, webuzo, kloxo, webmin - * @return string FALSE is returned if there was an error while installing the control panel - * 'onboot' is returned if the control panel will be installed when the VPS is STOPPED and STARTED - * 'done' is returned if the control panel has been installed right now - Mainly OpenVZ - */ - function controlpanel($vid, $panel){ - - $post['ins'][$panel] = 1; - - $resp = $this->call('index.php?svs='.$vid.'&act=controlpanel', $post); - - // Was there an error - if(!empty($resp['error'])){ - - $this->error = $resp['error']; - return false; - - // Will it be done when the VPS is STOPPED and STARTED ? - }elseif(!empty($resp['onboot'])){ - - return 'onboot'; - - // It was done successfully - }elseif(!empty($resp['done'])){ - - return 'done'; - - } - - } - -} - -////////////// -// Examples -////////////// - -//$v = new Virtualizor_Enduser_API('127.0.0.1', '16_BIT_API_KEY', '32_BIT_API_PASS'); - -// Get the list of the VPS -//$v->r($v->listvs()); - -// Start a VPS -//echo $v->start(3); - -// Stop a VPS -//echo $v->stop(3); - -// Restart a VPS -//echo $v->restart(3); - -// Poweroff a VPS -//echo $v->poweroff(3); - -// Get the Status of a VPS -//echo $v->status(3); - -// Get the Hostname -//echo $v->hostname(4); - -// Change the Hostname -//$v->r($v->hostname(4, 'NEWHOSTNAME')); - -// CPU Details -//$v->r($v->cpu(4)); - -// Ram Details -//$v->r($v->ram(4)); - -// Disk Details -//$v->r($v->disk(4)); - -// Bandwidth Details for the Current Month -//$v->r($v->bandwidth(4)); - -// Bandwidth Details for the Month of May in 2012 -//$v->r($v->bandwidth(4, 201205)); - -// List the processes - OpenVZ only -//$v->r($v->processes(4)); - -// List the services - OpenVZ only -//$v->r($v->services(4)); - -// Change the Root Password of a Virtual Server ? -//$v->r($v->changepassword(4, 'test')); - -// Give the VNC Details - VNC must be enabled - Xen / KVM -//$v->r($v->vnc(4)); - -// Change the VNC Password - VNC must be enabled - Xen / KVM -//$v->r($v->vncpass(4, 'NEWpass')); - -// List available OS Templates -//$v->r($v->ostemplate(2)); - -// Reinstall the OS -//$v->r($v->ostemplate(4, 1, 'test')); - -// Install a Control Panel -//$v->r($v->controlpanel(4, 'cpanel')); - -?> \ No newline at end of file diff --git a/src/PostData/BasePostData.php b/src/PostData/BasePostData.php new file mode 100644 index 0000000..83b2a3f --- /dev/null +++ b/src/PostData/BasePostData.php @@ -0,0 +1,117 @@ +getProperties(\ReflectionProperty::IS_PUBLIC); + foreach ($props as $prop) { + if (!isset($this->{$prop->name})) { + continue; + } + $out[$prop->name] = $this->{$prop->name}; + } + + return $out; + } + + private function addError($prop, $error) + { + $this->errors[$prop] = $error; + } + + private function checkRequires() + { + $hasError = false; + $requires = $this->requiredFields(); + if (!empty($requires)) { + foreach ($requires as $f) { + if (!isset($this->{$f})) { + $this->addError($f, $f.' is required'); + $hasError = true; + } + } + } + + if ($hasError) { + return false; + } + return true; + } + + private function checkTypes() + { + $hasError = false; + $reflect = new \ReflectionClass($this); + $props = $reflect->getProperties(\ReflectionProperty::IS_PUBLIC); + foreach ($props as $prop) { + if (!isset($this->{$prop->name})) { + continue; + } + $type = $this->rules()[$prop->name]; + + if (is_callable($type)) { + if ($this->{$prop->name} instanceof $type) { + $this->addError($prop->name, $prop.'should instant of class'); + $hasError = true; + } + } else { + $isOk = true; + switch ($type) { + case 'integer': + $isOk = (is_int($this->{$prop->name}) | is_integer($this->{$prop->name})) ? true : false; + break; + case 'string': + $isOk = (is_string($this->{$prop->name})) ? true : false; + break; + case 'array': + $isOk = (is_array($this->{$prop->name})) ? true : false; + break; + case 'bool': + case 'boolean': + $isOk = (is_bool($this->{$prop->name})) ? true : false; + break; + } + + if (!$isOk) { + $this->addError($prop->name, $prop->name.' type should be '.$type); + $hasError = true; + } + } + } + + + if ($hasError) { + return true; + } else { + return false; + } + } + + public function validate(): bool + { + if ($this->checkRequires() * $this->checkTypes()) { + return true; + } else { + return false; + } + } +} \ No newline at end of file diff --git a/src/PostData/BasePostDataInterface.php b/src/PostData/BasePostDataInterface.php new file mode 100644 index 0000000..e95f27c --- /dev/null +++ b/src/PostData/BasePostDataInterface.php @@ -0,0 +1,30 @@ +'int'|'string'|'float'|'array'|'object'|'class'|'boolean' + * ] + * @return array + */ + public function rules():array; + + +} \ No newline at end of file diff --git a/src/PostData/CreateVS.php b/src/PostData/CreateVS.php new file mode 100644 index 0000000..4deef17 --- /dev/null +++ b/src/PostData/CreateVS.php @@ -0,0 +1,175 @@ + 'integer', + 'virt' => 'string', + 'uid' => 'integer', + 'user_email' => 'string', + 'user_pass' => 'string', + 'fname' => 'string', + 'lname' => 'string', + 'plid' => 'integer', + 'osid' => 'integer', + 'hostname' => 'string', + 'rootpass' => 'string', + 'ips' => 'array', + 'num_ips6' => 'integer', + 'num_ips6_subnet' => 'integer', + 'stid' => 'integer', + 'space' => 'integer', + 'ram' => 'integer', + 'swapram' => 'integer', + 'bandwidth' => 'integer', + 'network_speed' => 'integer', + 'cpu' => 'integer', + 'cores' => 'integer', + 'cpu_percent' => 'integer', + 'vnc' => 'integer', + 'vncpass' => 'string', + 'kvm_cache' => 'string', + 'io_mode' => 'string', + 'vnc_keymap' => 'string', + 'nic_type' => 'string', + 'osreinstall_limi' => 'integer', + ]; + } + +} \ No newline at end of file diff --git a/src/PostData/Space.php b/src/PostData/Space.php new file mode 100644 index 0000000..abe8029 --- /dev/null +++ b/src/PostData/Space.php @@ -0,0 +1,12 @@ +title = $data->title; + $this->network_status = $data->network_status; + $this->owners = $data->owners; + $this->plans = $data->plans; + $this->backup_plans = $data->backup_plans; + $this->timenow = $data->timenow; + $this->time_taken = $data->time_taken; + + + if (!empty($data->vs)) { + foreach ($data->vs as $v) { + $v=(object)$v; + $this->vs[] = new VS( + $v->vpsid, + $v->vps_name, + $v->uuid, + $v->serid, + $v->time, + $v->edittime, + $v->virt, + $v->uid, + $v->plid, + $v->hostname, + $v->osid, + $v->os_name, + $v->iso, + $v->sec_iso, + $v->boot, + $v->space, + $v->inodes, + $v->ram, + $v->burst, + $v->swap, + $v->cpu, + $v->cores, + $v->cpupin, + $v->cpu_percent, + $v->bandwidth, + $v->network_speed, + $v->upload_speed, + $v->io, + $v->ubc, + $v->acpi, + $v->apic, + $v->pae, + $v->shadow, + $v->vnc, + $v->vncport, + $v->vnc_passwd, + $v->hvm, + $v->suspended, + $v->suspend_reason, + $v->nw_suspended, + $v->rescue, + $v->band_suspend, + $v->tuntap, + $v->ppp, + $v->ploop, + $v->dns_nameserver, + $v->osreinstall_limit, + $v->preferences, + $v->nic_type, + $v->vif_type, + $v->virtio, + $v->pv_on_hvm, + $v->disks, + $v->kvm_cache, + $v->io_mode, + $v->cpu_mode, + $v->total_iops_sec, + $v->read_bytes_sec, + $v->write_bytes_sec, + $v->kvm_vga, + $v->acceleration, + $v->vnc_keymap, + $v->routing, + $v->mg, + $v->used_bandwidth, + $v->cached_disk, + $v->webuzo, + $v->disable_ebtables, + $v->install_xentools, + $v->admin_managed, + $v->rdp, + $v->topology_sockets, + $v->topology_cores, + $v->topology_threads, + $v->mac, + $v->notes, + $v->disable_nw_config, + $v->locked, + $v->openvz_features, + $v->speed_cap, + $v->numa, + $v->bpid, + $v->bserid, + $v->timezone, + $v->ha, + $v->data, + $v->server_name, + $v->email, + $v->pid, + $v->type, + $v->os_distro, + $v->stid, + $v->ips + ); + } + } + + if (!empty($data->ostemplates)) { + foreach ($data->ostemplates as $o) { + $o=(object)$o; + $this->osTemplates[] = new OsTemplate( + $o->osid, + $o->type, + $o->name, + $o->filename, + $o->size, + $o->pygrub, + $o->drive, + $o->hvm, + $o->perf_ops, + $o->active, + $o->url, + $o->distro, + $o->Nvirt + ); + } + } + + if (!empty($data->servers)) { + foreach ($data->servers as $server) { + $server=(object)$server; + $this->servers[] = new Server( + $server->serid, + $server->sgid, + $server->server_name, + $server->virt, + $server->ip, + $server->internal_ip, + $server->vnc_ip, + $server->settings, + $server->unique_txt, + $server->lv, + $server->hvm, + $server->licnumvs, + $server->total_ram, + $server->overcommit, + $server->ram, + $server->total_space, + $server->space, + $server->os, + $server->os_arch, + $server->uname, + $server->version, + $server->patch, + $server->lic_expires, + $server->checked, + $server->locked, + $server->vcores, + $server->ips, + $server->ipv6, + $server->ipv6_subnet, + $server->ips_int, + $server->bandwidth, + $server->update_resource, + $server->location, + $server->status, + $server->last_reverse_sync, + $server->ha_master, + $server->numvps, + $server->alloc_ram, + $server->alloc_space, + $server->alloc_cpu, + $server->alloc_cpu_percent, + $server->alloc_bandwidth, + $server->virts + ); + } + } + } +} \ No newline at end of file diff --git a/src/Responses/Admin/OsTemplate.php b/src/Responses/Admin/OsTemplate.php new file mode 100644 index 0000000..ef37f33 --- /dev/null +++ b/src/Responses/Admin/OsTemplate.php @@ -0,0 +1,73 @@ +osid = $osid; + $this->type = $type; + $this->name = $name; + $this->filename = $filename; + $this->size = $size; + $this->pygrub = $pygrub; + $this->drive = $drive; + $this->hvm = $hvm; + $this->perf_ops = $perf_ops; + $this->active = $active; + $this->url = $url; + $this->distro = $distro; + $this->Nvirt = $Nvirt; + } +} \ No newline at end of file diff --git a/src/Responses/Admin/Server.php b/src/Responses/Admin/Server.php new file mode 100644 index 0000000..bbb6493 --- /dev/null +++ b/src/Responses/Admin/Server.php @@ -0,0 +1,195 @@ +serid = $serid; + $this->sgid = $sgid; + $this->server_name = $server_name; + $this->virt = $virt; + $this->ip = $ip; + $this->internal_ip = $internal_ip; + $this->vnc_ip = $vnc_ip; + $this->settings = $settings; + $this->unique_txt = $unique_txt; + $this->lv = $lv; + $this->hvm = $hvm; + $this->licnumvs = $licnumvs; + $this->total_ram = $total_ram; + $this->overcommit = $overcommit; + $this->ram = $ram; + $this->total_space = $total_space; + $this->space = $space; + $this->os = $os; + $this->os_arch = $os_arch; + $this->uname = $uname; + $this->version = $version; + $this->patch = $patch; + $this->lic_expires = $lic_expires; + $this->checked = $checked; + $this->locked = $locked; + $this->vcores = $vcores; + $this->ips = $ips; + $this->ipv6 = $ipv6; + $this->ipv6_subnet = $ipv6_subnet; + $this->ips_int = $ips_int; + $this->bandwidth = $bandwidth; + $this->update_resource = $update_resource; + $this->location = $location; + $this->status = $status; + $this->last_reverse_sync = $last_reverse_sync; + $this->ha_master = $ha_master; + $this->numvps = $numvps; + $this->alloc_ram = $alloc_ram; + $this->alloc_space = $alloc_space; + $this->alloc_cpu = $alloc_cpu; + $this->alloc_cpu_percent = $alloc_cpu_percent; + $this->alloc_bandwidth = $alloc_bandwidth; + $this->virts = $virts; + } +} \ No newline at end of file diff --git a/src/Responses/Admin/VS.php b/src/Responses/Admin/VS.php new file mode 100644 index 0000000..4aebf32 --- /dev/null +++ b/src/Responses/Admin/VS.php @@ -0,0 +1,396 @@ +vpsid = (int) $vpsid; + $this->vps_name = $vps_name; + $this->uuid = $uuid; + $this->serid = $serid; + $this->time = $time; + $this->edittime = $edittime; + $this->virt = $virt; + $this->uid = (int) $uid; + $this->plid = (int) $plid; + $this->hostname = $hostname; + $this->osid = (int) $osid; + $this->os_name = $os_name; + $this->iso = $iso; + $this->sec_iso = $sec_iso; + $this->boot = $boot; + $this->space = (float) $space; + $this->inodes = $inodes; + $this->ram = (int) $ram; + $this->burst = $burst; + $this->swap = $swap; + $this->cpu = (float) $cpu; + $this->cores = (int) $cores; + $this->cpupin = (int) $cpupin; + $this->cpu_percent = (float) $cpu_percent; + $this->bandwidth = (float) $bandwidth; + $this->network_speed = (int) $network_speed; + $this->upload_speed = (int) $upload_speed; + $this->io = $io; + $this->ubc = !empty($ubc) ? unserialize($ubc) : $ubc; + $this->acpi = (int) $acpi; + $this->apic = (int) $apic; + $this->pae = (int) $pae; + $this->shadow = (int) $shadow; + $this->vnc = (int) $vnc; + $this->vncport = (int) $vncport; + $this->vnc_passwd = $vnc_passwd; + $this->hvm = (int) $hvm; + $this->suspended = (bool) $suspended; + $this->suspend_reason = $suspend_reason; + $this->nw_suspended = $nw_suspended; + $this->rescue = $rescue; + $this->band_suspend = $band_suspend; + $this->tuntap = $tuntap; + $this->ppp = $ppp; + $this->ploop = $ploop; + $this->dns_nameserver = !empty($dns_nameserver) ? unserialize($dns_nameserver) : $dns_nameserver; + $this->osreinstall_limit = $osreinstall_limit; + $this->preferences = $preferences; + $this->nic_type = $nic_type; + $this->vif_type = $vif_type; + $this->virtio = $virtio; + $this->pv_on_hvm = $pv_on_hvm; + $this->disks = $disks; + $this->kvm_cache = $kvm_cache; + $this->io_mode = $io_mode; + $this->cpu_mode = $cpu_mode; + $this->total_iops_sec = $total_iops_sec; + $this->read_bytes_sec = $read_bytes_sec; + $this->write_bytes_sec = $write_bytes_sec; + $this->kvm_vga = $kvm_vga; + $this->acceleration = $acceleration; + $this->vnc_keymap = $vnc_keymap; + $this->routing = $routing; + $this->mg = $mg; + $this->used_bandwidth = $used_bandwidth; + $this->cached_disk = !empty($cached_disk) ? unserialize($cached_disk) : $cached_disk; + $this->webuzo = $webuzo; + $this->disable_ebtables = $disable_ebtables; + $this->install_xentools = $install_xentools; + $this->admin_managed = $admin_managed; + $this->rdp = $rdp; + $this->topology_sockets = $topology_sockets; + $this->topology_cores = $topology_cores; + $this->topology_threads = $topology_threads; + $this->mac = $mac; + $this->notes = $notes; + $this->disable_nw_config = $disable_nw_config; + $this->locked = $locked; + $this->openvz_features = $openvz_features; + $this->speed_cap = $speed_cap; + $this->numa = $numa; + $this->bpid = $bpid; + $this->bserid = $bserid; + $this->timezone = $timezone; + $this->ha = $ha; + $this->data = !empty($data) ? json_decode($data) : $data; + $this->server_name = $server_name; + $this->email = $email; + $this->pid = $pid; + $this->type = $type; + $this->os_distro = $os_distro; + + $this->stid = $stid; + $this->ips = $ips; + } + +} \ No newline at end of file diff --git a/src/Responses/BaseResponse.php b/src/Responses/BaseResponse.php new file mode 100644 index 0000000..5762deb --- /dev/null +++ b/src/Responses/BaseResponse.php @@ -0,0 +1,25 @@ +key = $key; + $this->pass = $pass; + $this->ip = $ip; + $this->port = $port; + if($port != 4085){ + $this->protocol = 'http'; + } + } + + /** + * Dumps a variable + * + * @author Pulkit Gupta + * @param array $re The Array or any other variable. + * @return NULL + */ + function r($re){ + echo '
';
+        print_r($re);
+        echo '
'; + } + + /** + * Unserializes a string + * + * @author Pulkit Gupta + * @param string $str The serialized string + * @return array The unserialized array on success OR false on failure + */ + function _unserialize($str){ + + $var = @unserialize($str); + if(empty($var)){ + $str = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'._strlen('$2').':\"$2\";'", $str); + + $var = @unserialize($str); + } + + //If it is still empty false + if(empty($var)){ + + return false; + + }else{ + + return $var; + + } + + } + + /** + * Make an API Key + * + * @author Pulkit Gupta + * @param string $key An 8 bit random string + * @param string $pass The API Password of your NODE + * @return string The new APIKEY which will be used to query + */ + function make_apikey($key, $pass){ + return $key.md5($pass.$key); + } + + /** + * Generates a random string for the given length + * + * @author Pulkit Gupta + * @param int $length The length of the random string to be generated + * @return string The generated random string + */ + function generateRandStr($length){ + $randstr = ""; + for($i = 0; $i < $length; $i++){ + $randnum = mt_rand(0,61); + if($randnum < 10){ + $randstr .= chr($randnum+48); + }elseif($randnum < 36){ + $randstr .= chr($randnum+55); + }else{ + $randstr .= chr($randnum+61); + } + } + return strtolower($randstr); + } + + /** + * Makes an API request to the server to do a particular task + * + * @author Pulkit Gupta + * @param string $path The action you want to do + * @param array $post An array of DATA that should be posted + * @param array $cookies An array FOR SENDING COOKIES + * @return array The unserialized array on success OR false on failure + */ + function call($path, $data = array(), $post = array(), $cookies = array()){ + + $key = $this->generateRandStr(8); + $apikey = $this->make_apikey($key, $this->pass); + + $url = ($this->protocol).'://'.$this->ip.':'. $this->port .'/'. $path; + $url .= (strstr($url, '?') ? '' : '?'); + $url .= '&api=serialize&apikey='.rawurlencode($apikey); + + // Pass some data if there + if(!empty($data)){ + $url .= '&apidata='.rawurlencode(base64_encode(serialize($data))); + } + // Set the curl parameters. + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + + // Time OUT + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); + + // Turn off the server and peer verification (TrustManager Concept). + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); + + // UserAgent + curl_setopt($ch, CURLOPT_USERAGENT, 'Softaculous'); + + // Cookies + if(!empty($cookies)){ + curl_setopt($ch, CURLOPT_COOKIESESSION, true); + curl_setopt($ch, CURLOPT_COOKIE, http_build_query($cookies, '', '; ')); + } + + if(!empty($post)){ + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); + } + + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + + // Get response from the server. + $resp = curl_exec($ch); + curl_close($ch); + + // The following line is a method to test + //if(preg_match('/sync/is', $url)) echo $resp; + + if(empty($resp)){ + return false; + } + + $r = @unserialize($resp); + + if(empty($r)){ + return false; + } + + return $r; + + } + + /** + * Create a VPS + * + * @author Pulkit Gupta + * @param string $path The action you want to do + * @param array $post An array of DATA that should be posted + * @param array $cookies An array FOR SENDING COOKIES + * @return array The unserialized array on success OR false on failure + */ + function addippool($post){ + $post['addippool'] = 1; + $path = 'index.php?act=addippool'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + function addips($post){ + $path = 'index.php?act=addips'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + function addiso($post){ + $path = 'index.php?act=addiso'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + function addplan($post){ + + $path ='index.php?act=addplan'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + function addserver($post){ + $path ='index.php?act=addserver'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + function addtemplate($post){ + $path ='index.php?act=addtemplate'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + function adduser($post = 0){ + $path ='index.php?act=adduser'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + /** + * @param $fields + * @return bool + */ + private function checkFields(&$fields){ + if(!$fields->validate()){ + return false; + }else{ + return true; + } + } + + /** + * Create a VPS + * + * @author Pulkit Gupta + * @param CreateVS $fields An array of DATA that should be posted + * @param array $cookies An array FOR SENDING COOKIES + * @return array The unserialized array on success OR false on failure + */ + function addvs(CreateVS $fields,array $cookies){ + $path = 'index.php?act=addvs'; + if ($this->checkFields($fields)) { + $servedData=$fields->serve(); + $ret = $this->call($path, '',$servedData , $cookies); + return array( + 'title' => $ret['title'], + 'error' => @empty($ret['error']) ? array() : $ret['error'], + 'vs_info' => $ret['newvs'], + 'globals' => $ret['globals'] + ); + }else{ + return false; + } + } + + function addiprange($post){ + $path ='index.php?act=addiprange'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + function addsg($post){ + $path ='index.php?act=addsg'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + function addbackupserver($post){ + $path ='index.php?act=addbackupserver'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + function addstorage($post){ + $path ='index.php?act=addstorage'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + function adddnsplan($post){ + $path ='index.php?act=adddnsplan'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + function add_admin_acl($post){ + $path ='index.php?act=add_admin_acl'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + function addmg($post){ + $path ='index.php?act=addmg'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + function add_distro($post){ + $path ='index.php?act=add_distro'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + function addpdns($post){ + $path ='index.php?act=addpdns'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + + + function adminindex(){ + $path = 'index.php?act=adminindex'; + $res = $this->call($path); + return $res; + } + + function apidoings(){ + + } + + function backup($post){ + $path ='index.php?act=backup'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + function bandwidth(){ + $path ='index.php?act=backup'; + $ret = $this->call($path); + return $ret; + } + + /** + * Cleaning the POST variables + * + * @author Pulkit Gupta + * @param array $post An array of DATA that should be posted + * @param array $cookies An array FOR SENDING COOKIES + * @return array The unserialized array on success OR false on failure + */ + function clean_post(&$post, $edit = 0){ + $post['serid'] = !isset($post['serid']) ? 0 : (int)$post['serid']; + $post['uid'] = !isset($post['uid']) ? 0 : (int)$post['uid']; + $post['plid'] = !isset($post['plid']) ? 0 : (int)$post['plid']; + $post['osid'] = !isset($post['osid']) ? 0 : (int)$post['osid']; + $post['iso'] = !isset($post['iso']) ? 0 : (int)$post['iso']; + $post['space'] = !isset($post['space']) ? 10 : (int)$post['space']; + $post['ram'] = !isset($post['ram']) ? 512 : (int)$post['ram']; + $post['swapram'] = !isset($post['swapram']) ? 1024 : (int)$post['swapram']; + $post['bandwidth'] = !isset($post['bandwidth']) ? 0 : (int)$post['bandwidth']; + $post['network_speed'] = !isset($post['network_speed']) ? 0 : (int)$post['network_speed']; + $post['cpu'] = !isset($post['cpu']) ? 1000 : (int)$post['cpu']; + $post['cores'] = !isset($post['cores']) ? 4 : (int)$post['cores']; + $post['cpu_percent'] = !isset($post['cpu_percent']) ? 100 : (int)$post['cpu_percent']; + $post['vnc'] = !isset($post['vnc']) ? 1 : (int)$post['vnc']; + $post['vncpass'] = !isset($post['vncpass']) ? 'test' : $post['vncpass']; + $post['sec_iso'] = !isset($post['sec_iso']) ? 0 : $post['sec_iso']; + $post['kvm_cache'] = !isset($post['kvm_cache']) ? 0 : $post['kvm_cache']; + $post['io_mode'] = !isset($post['io_mode']) ? 0 : $post['io_mode']; + $post['vnc_keymap'] = !isset($post['vnc_keymap']) ? 'en-us' : $post['vnc_keymap']; + $post['nic_type'] = !isset($post['nic_type']) ? 'default' : $post['nic_type']; + $post['osreinstall_limit'] = !isset($post['osreinstall_limit']) ? 0 : (int)$post['osreinstall_limit']; + $post['mgs'] = !isset($post['mgs']) ? 0 : $post['mgs']; + $post['tuntap'] = !isset($post['tuntap']) ? 0 : $post['tuntap']; + $post['virtio'] = !isset($post['virtio']) ? 0 : $post['virtio']; + if(isset($post['hvm'])){ + $post['hvm'] = $post['hvm']; + } + $post['noemail'] = !isset($post['noemail']) ? 0 : $post['noemail']; + $post['boot'] = !isset($post['boot']) ? 'dca' : $post['boot']; + $post['band_suspend'] = !isset($post['band_suspend']) ? 0 : $post['band_suspend']; + $post['vif_type'] = !isset($post['vif_type']) ? 'netfront' : $post['vif_type']; + if($edit == 0){ + $post['addvps'] = !isset($post['addvps']) ? 1 : (int)$post['addvps']; + }else{ + $post['editvps'] = !isset($post['editvps']) ? 1 : $post['editvps']; + $post['acpi'] = !isset($post['acpi']) ? 1 : $post['acpi']; + $post['apic'] = !isset($post['apic']) ? 1 : $post['apic']; + $post['pae'] = !isset($post['pae']) ? 1 : $post['pae']; + $post['dns'] = !isset($post['dns']) ? array('4.2.2.1','4.2.2.2') : $post['dns']; + $post['editvps'] = !isset($post['editvps']) ? 1 : (int)$post['editvps']; + } + + return $post; + } + + function cluster(){ + + } + + function config($post){ + $path ='index.php?act=config'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + /** + * Get CPU usage details + * + * @author Pulkit Gupta + * @param + * @return array The unserialised array is returned on success or + * empty array is returned on failure + */ + function cpu($serverid = 0){ + $path = 'index.php?act=manageserver&changeserid='.$serverid; + $ret = $this->call($path); + return $ret['usage']['cpu']; + } + + function createssl($post){ + $path ='index.php?act=createssl'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + function createtemplate($post){ + $path ='index.php?act=createtemplate'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + function databackup(){ + + } + + function defaultvsconf($post){ + $path ='index.php?act=defaultvsconf'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + /** + * Delete a VPS + * + * @author Pulkit Gupta + * @param array $post An array of DATA that should be posted + * @return boolean 1 on success OR 0 on failure + */ + function delete_vs($vid){ + $path = 'index.php?act=vs&delete='.(int)$vid; + $res = $this->call($path); + return $res['done']; + } + + /** + * Get Disk usage details + * + * @author Pulkit Gupta + * @param + * @return array The unserialised array is returned on success or + * empty array is returned on failure + */ + function disk($serverid = 0){ + $path = 'index.php?act=manageserver&changeserid='.$serverid; + $ret = $this->call($path); + return $ret['usage']['disk']; + } + + function downloadiso(){ + + } + + function editemailtemp(){ + + } + + function editippool($post){ + $path = 'index.php?act=editippool'; + $res = $this->call($path, array(), $post); + return $res; + } + + function editips($post){ + $path = 'index.php?act=editips'; + $res = $this->call($path, array(), $post); + return $res; + } + + function editplan($post){ + $path = 'index.php?act=editplan'; + $res = $this->call($path, array(), $post); + return $res; + } + + function editserver($post){ + $path = 'index.php?act=editserver'; + $res = $this->call($path, array(), $post); + return $res; + } + + function edittemplate($post){ + $path = 'index.php?act=edittemplate'; + $res = $this->call($path, array(), $post); + return $res; + } + + function edituser($post){ + $path = 'index.php?act=edituser'; + $res = $this->call($path, array(), $post); + return $res; + } + + /** + * Create a VPS + * + * @author Pulkit Gupta + * @param array $post An array of DATA that should be posted + * @return array The unserialized array on success OR false on failure + */ + function editvs($post, $cookies = array()){ + $path = 'index.php?act=editvs&vpsid='.$post['vpsid']; + $post = $this->clean_post($post, 1); + $ret = $this->call($path, '', $post, $cookies); + return array( + 'title' => $ret['title'], + 'error' => @empty($ret['error']) ? array() : $ret['error'], + 'vs_info' => $ret['vps'] + ); + } + + function emailconfig($post){ + $path = 'index.php?act=emailconfig'; + $res = $this->call($path, array(), $post); + return $res; + } + + function emailtemp($post){ + $path = 'index.php?act=emailtemp'; + $res = $this->call($path, array(), $post); + return $res; + } + + function filemanager($post){ + $path = 'index.php?act=filemanager'; + $res = $this->call($path,'', $post); + return $res; + } + + function firewall($post){ + $path = 'index.php?act=firewall'; + $res = $this->call($path, array(), $post); + return $res; + } + + function giveos(){ + + } + + function health(){ + + } + + function hostname($post){ + $path = 'index.php?act=hostname'; + $res = $this->call($path,'',$post); + return $res; + } + + function import($post){ + $path = 'index.php?act=import'; + $res = $this->call($path, array(), $post); + return $res; + } + + function ippool($page = 1, $reslen = 50){ + $path = 'index.php?act=ippool&page='.$page.'&reslen='.$reslen; + $res = $this->call($path); + return $res; + } + + /** + * Get list of IPs + * + * @author Pulkit Gupta + * @param + * @return array The unserialised array on success. + */ + function ips($page = 1, $reslen = 50){ + $path = 'index.php?act=ips&page='.$page.'&reslen='.$reslen; + $ret = $this->call($path); + return $ret; + } + + function iso($page = 1, $reslen = 50){ + $path = 'index.php?act=iso&page='.$page.'&reslen='.$reslen; + $ret = $this->call($path); + return $ret; + } + + function kernelconf($post = 0){ + $path = 'index.php?act=kernelconf'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + function license(){ + $path = 'index.php?act=license'; + $ret = $this->call($path); + return $ret; + } + + /** + * List VPS + * + * @author Pulkit Gupta + * @param int page number, if not specified then only 50 records are returned. + * @return ListVs|false The ListVs class OR false on failure + * + */ + function listvs($page = 1, $reslen = 50){ + $path = 'index.php?act=vs&page='.$page.'&reslen='.$reslen; + $response= $this->call($path); + if (!empty($response)) { + + return new ListVs($response); + }else{ + return false; + } + } + + function login(){ + + } + + function loginlogs($page = 1, $reslen = 50){ + $path = 'index.php?act=loginlogs&page='.$page.'&reslen='.$reslen; + $ret = $this->call($path); + return $ret; + } + + function logs($page = 1, $reslen = 50){ + $path = 'index.php?act=logs&page='.$page.'&reslen='.$reslen; + $ret = $this->call($path); + return $ret; + } + + function maintenance($post){ + $path = 'index.php?act=maintenance'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + function makeslave(){ + + } + + function os($post){ + $path = 'index.php?act=os'; + $ret = $this->call($path, array(), $post); + return $ret; + } + + function ostemplates($page = 1, $reslen = 50){ + $path = 'index.php?act=ostemplates&page='.$page.'&reslen='.$reslen; + $ret = $this->call($path); + return $ret; + } + + function performance(){ + $path = 'index.php?act=performance'; + $ret = $this->call($path); + return $ret; + } + + function phpmyadmin(){ + + } + + function plans($page = 1, $reslen = 50){ + $path = 'index.php?act=plans&page='.$page.'&reslen='.$reslen; + $ret = $this->call($path); + return $ret; + } + + /** + * POWER OFF a Virtual Server + * + * @author Pulkit Gupta + * @param int $vid The VMs ID + * @return bool TRUE on success or FALSE on failure + */ + function poweroff($vid){ + // Make the Request + $res = $this->call('index.php?act=vs&action=poweroff&serid=0&vpsid='.(int)$vid); + return $res; + } + + function processes(){ + $path = 'index.php?act=processes'; + $ret = $this->call($path); + return $ret; + } + + /** + * Get RAM details + * + * @author Pulkit Gupta + * @param + * @return array The unserialised array is returned on success or + * empty array is returned on failure + */ + function ram($serverid = 0){ + $path = 'index.php?act=manageserver&changeserid='.$serverid; + $ret = $this->call($path); + return $ret['usage']['ram']; + } + + /** + * Rebuild a VPS + * + * @author Pulkit Gupta + * @param array $post An array of DATA that should be posted + * @return array The unserialized array on success OR false on failure + */ + function rebuild($post){ + $path = 'index.php?act=rebuild'; + return $this->call($path, '', $post); + } + + /** + * RESTART a Virtual Server + * + * @author Pulkit Gupta + * @param int $vid The VMs ID + * @return bool TRUE on success or FALSE on failure + */ + function restart($vid){ + // Make the Request + $res = $this->call('index.php?act=vs&action=restart&serid=0&vpsid='.(int)$vid); + return $res; + } + + function restartservices($post){ + $path = 'index.php?act=restartservices'; + $res = $this->call($path, array(), $post); + return $res; + } + + /** + * Current server information + * + * @author Pulkit Gupta + * @param + * @return array The unserialized array on success OR false on failure + */ + function serverinfo(){ + $path = 'index.php?act=serverinfo'; + return $this->call($path); + } + + /** + * List Servers + * + * @author Pulkit Gupta + * @param + * @return array The unserialized array on success OR false on failure + */ + function servers(){ + $path = 'index.php?act=servers'; + return $this->call($path); + } + + function services($post = 0){ + $path = 'index.php?act=services'; + $res = $this->call($path, '', $post); + return $res; + } + + function ssh(){ + /* $path = 'index.php?act=ssh'; + $res = $this->call($path); + return $res;*/ + } + + function ssl($post = 0){ + /* $path = 'index.php?act=ssl'; + $res = $this->call($path, '', $post); + return $res;*/ + } + + function sslcert(){ + /* $path = 'index.php?act=sslcert'; + $res = $this->call($path); + return $res;*/ + } + + /** + * START a Virtual Server + * + * @author Pulkit Gupta + * @param int $vid The VMs ID + * @return bool TRUE on success or FALSE on failure + */ + function start($vid){ + + $res = $this->call('index.php?act=vs&action=start&serid=0&vpsid='.(int)$vid); + return $res; + } + + /** + * STOP a Virtual Server + * + * @author Pulkit Gupta + * @param int $vid The VMs ID + * @return bool TRUE on success or FALSE on failure + */ + function stop($vid){ + // Make the Request + $res = $this->call('index.php?act=vs&action=stop&serid=0&vpsid='.(int)$vid); + return $res; + } + + /** + * Gives status of a Virtual Server + * + * @author Pulkit Gupta + * @param Array $vids array of IDs of VMs + * @return Array Contains the status info of the VMs + */ + function status($vids){ + + // Make the Request + $res = $this->call('index.php?act=vs&vs_status='.implode(',', $vids)); + return $res['status']; + + } + + /** + * Suspends a VM of a Virtual Server + * + * @author Pulkit Gupta + * @param int $vid The VMs ID + * @return int 1 if the VM is ON, 0 if its OFF + */ + function suspend($vid){ + $path = 'index.php?act=vs&suspend='.(int)$vid; + $res = $this->call($path); + return $res; + } + + /** + * Unsuspends a VM of a Virtual Server + * + * @author Pulkit Gupta + * @param int $vid The VMs ID + * @return int 1 if the VM is ON, 0 if its OFF + */ + function unsuspend($vid){ + $path = 'index.php?act=vs&unsuspend='.(int)$vid; + $res = $this->call($path); + return $res; + } + + function tools(){ + + } + + function ubc($post){ + $path = 'index.php?act=ubc'; + $res = $this->call($path, array(), $post); + return $res; + } + + function updates(){ + $path = 'index.php?act=updates'; + $res = $this->call($path); + return $res; + } + + function userlogs($page = 1, $reslen = 50){ + $path = 'index.php?act=userlogs&page='.$page.'&reslen='.$reslen; + $res = $this->call($path); + return $res; + } + + function users($page = 1, $reslen = 50){ + $path = 'index.php?act=users&page='.$page.'&reslen='.$reslen; + $res = $this->call($path); + return $res; + } + + function vnc($post){ + $path = 'index.php?act=vnc'; + $res = $this->call($path, array(), $post); + return $res; + } + + function vpsbackupsettings($post){ + $path = 'index.php?act=vpsbackupsettings'; + $res = $this->call($path, array(), $post); + return $res; + } + + function vpsbackups($post){ + $path = 'index.php?act=vpsbackups'; + $res = $this->call($path, '', $post); + return $res; + } + + function vs($page = 1, $reslen = 50){ + $path = 'index.php?act=vs&page='.$page.'&reslen='.$reslen; + $res = $this->call($path); + return $res; + } + + function vsbandwidth(){ + $path = 'index.php?act=vsbandwidth'; + $res = $this->call($path); + return $res; + } + + function vscpu(){ + $path = 'index.php?act=vscpu'; + $res = $this->call($path); + return $res; + } + + function vsram(){ + $path = 'index.php?act=vsram'; + $res = $this->call($path); + return $res; + + } +} \ No newline at end of file diff --git a/src/VirtualizorClient.php b/src/VirtualizorClient.php new file mode 100644 index 0000000..42a407e --- /dev/null +++ b/src/VirtualizorClient.php @@ -0,0 +1,723 @@ +key = $key; + $this->pass = $pass; + $this->ip = $ip; + $this->port = $port; + if (!($port == 4083 || $port == 443)) { + $this->protocol = 'http'; + } + } + + /** + * Dumps a variable + * + * @param array $re The Array or any other variable. + * @return NULL + * @author Pulkit Gupta + */ + public function r($re) + { + echo '
';
+        print_r($re);
+        echo '
'; + } + + /** + * Unserializes a string + * + * @param string $str The serialized string + * @return array The unserialized array on success OR false on failure + * @author Pulkit Gupta + */ + public function _unserialize($str) + { + + $var = @unserialize($str); + + if (empty($var)) { + + $str = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'._strlen('$2').':\"$2\";'", $str); + + $var = @unserialize($str); + + } + + //If it is still empty false + if (empty($var)) { + + return false; + + } else { + + return $var; + + } + + } + + /** + * Makes an API request to the server to do a particular task + * + * @param string $path The action you want to do + * @param array $post An array of DATA that should be posted + * @param array $cookies An array FOR SENDING COOKIES + * @return array The unserialized array on success OR false on failure + * @author Pulkit Gupta + */ + public function call($path, $post = [], $cookies = []) + { + + $url = ($this->protocol).'://'.$this->ip.':'.$this->port.'/'.$path; + $url .= (strstr($url, '?') ? '' : '?'); + $url .= '&api=json&apikey='.rawurlencode($this->key).'&apipass='.rawurlencode($this->pass); + + // Set the curl parameters. + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + + // Time OUT + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); + + // Turn off the server and peer verification (TrustManager Concept). + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + + // UserAgent + curl_setopt($ch, CURLOPT_USERAGENT, 'Virtualizor'); + + // Cookies + if (!empty($cookies)) { + curl_setopt($ch, CURLOPT_COOKIESESSION, true); + curl_setopt($ch, CURLOPT_COOKIE, http_build_query($cookies, '', '; ')); + } + + if (!empty($post)) { + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); + } + + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + + // Get response from the server. + $resp = curl_exec($ch); + curl_close($ch); + + // The following line is a method to test + //if(preg_match('/sync/is', $url)) echo $resp; + + if (empty($resp)) { + return false; + } + + $r = $this->_unserialize($resp); + + if (empty($r)) { + return false; + } + + return $r; + + } + + /** + * List the Virtual Servers in your account + * + * @return array The array containing a list of Virtual Servers one has in their account + * @author Pulkit Gupta + */ + public function listvs() + { + + $resp = $this->call('index.php?act=listvs'); + + return $resp['vs']; + + } + + + /** + * START a Virtual Server + * + * @param int $vid The VMs ID + * @return bool TRUE on success or FALSE on failure + * @author Pulkit Gupta + */ + public function start($vid) + { + + // Make the Request + $res = $this->call('index.php?svs='.$vid.'&act=start&do=1'); + + // Did it finish ? + if (!empty($res['done'])) { + return true; + } else { + return false; + } + + } + + + /** + * STOP a Virtual Server + * + * @param int $vid The VMs ID + * @return bool TRUE on success or FALSE on failure + * @author Pulkit Gupta + */ + public function stop($vid) + { + + // Make the Request + $res = $this->call('index.php?svs='.$vid.'&act=stop&do=1'); + + // Did it finish ? + if (!empty($res['done'])) { + return true; + } else { + return false; + } + + } + + + /** + * RESTART a Virtual Server + * + * @param int $vid The VMs ID + * @return bool TRUE on success or FALSE on failure + * @author Pulkit Gupta + */ + public function restart($vid) + { + + // Make the Request + $res = $this->call('index.php?svs='.$vid.'&act=restart&do=1'); + + // Did it finish ? + if (!empty($res['done'])) { + return true; + } else { + return false; + } + + } + + + /** + * POWER OFF a Virtual Server + * + * @param int $vid The VMs ID + * @return bool TRUE on success or FALSE on failure + * @author Pulkit Gupta + */ + public function poweroff($vid) + { + + // Make the Request + $res = $this->call('index.php?svs='.$vid.'&act=poweroff&do=1'); + + // Did it finish ? + if (!empty($res['done'])) { + return true; + } else { + return false; + } + + } + + + /** + * STOP a Virtual Server + * + * @param int $vid The VMs ID + * @return int 1 if the VM is ON, 0 if its OFF + * @author Pulkit Gupta + */ + public function status($vid) + { + + // Make the Request + $res = $this->call('index.php?svs='.$vid.'&act=start'); + + return $res['status']; + + } + + /** + * GET or SET the hostname of a VM. To get the current hostname dont pass the $newhostname parameter + * + * @param int $vid The VMs ID + * @param string $newhostname The new HOSTNAME of the virtual server. + * @return string The CURRENT hostname is returned if $newhostname is NULL. + * FALSE is returned if there was an error while setting the new hostname + * 'onboot' is returned if the new hostname will be set when the VPS is STOPPED and STARTED + * 'done' is returned if the new hostname has been set right now - Mainly OpenVZ + * @author Pulkit Gupta + */ + public function hostname($vid, $newhostname = null) + { + + // Are we to change ? + if (!empty($newhostname)) { + + $post = [ + 'newhost' => $newhostname, + 'changehost' => 'Change Hostname' + ]; + + $resp = $this->call('index.php?svs='.$vid.'&act=hostname', $post); + + // Was there an error + if (!empty($resp['error'])) { + + $this->error = $resp['error']; + return false; + + // Will it be done when the VPS is STOPPED and STARTED ? + } elseif (!empty($resp['onboot'])) { + + return 'onboot'; + + // It was done successfully + } elseif (!empty($resp['done'])) { + + return 'done'; + + } + + // Just return the CURRENT HOSTNAME + } else { + $resp = $this->call('index.php?svs='.$vid.'&act=hostname'); + return $resp['current']; + } + + } + + + /** + * GET the CPU details of a VM. Incase of Xen / KVM, only information is available as usage cannot be sensed. + * + * @param int $vid The VMs ID + * @return array An array containing the details is returned. Usage details is available only in case of OpenVZ. + * @author Pulkit Gupta + */ + public function cpu($vid) + { + + $resp = $this->call('index.php?svs='.$vid.'&act=cpu'); + + return $resp['cpu']; + + } + + /** + * GET the RAM details of a VM. Incase of Xen / KVM, only information is available as usage cannot be sensed. + * + * @param int $vid The VMs ID + * @return array An array containing the details is returned. Usage details is available only in case of OpenVZ. + * @author Pulkit Gupta + */ + public function ram($vid) + { + + $resp = $this->call('index.php?svs='.$vid.'&act=ram'); + + return $resp['ram']; + + } + + + /** + * GET the Disk details of a VM. Incase of Xen / KVM, only information is available as usage cannot be sensed. + * + * @param int $vid The VMs ID + * @return array An array containing the details is returned. Usage details is available only in case of OpenVZ. + * @author Pulkit Gupta + */ + public function disk($vid) + { + + $resp = $this->call('index.php?svs='.$vid.'&act=disk'); + + $ret['disk'] = $resp['disk']; + $ret['inodes'] = $resp['inodes']; + + return $ret; + + } + + /** + * GET the Bandwidth Usage of a VM. + * + * @param int $vid The VMs ID + * @param int $month The month in the format YYYYMM e.g. 201205 is for the Month of May, 2012 + * @return array Returns an array of Bandwidth Information for the Month GIVEN. + * By Default the CURRENT MONTH details are returned + * @author Pulkit Gupta + */ + public function bandwidth($vid, $month = 0) + { + + $resp = $this->call('index.php?svs='.$vid.'&act=bandwidth'.(!empty($month) ? '&show='.$month : '')); + + return $resp['bandwidth']; + + } + + + /** + * List the Processes in a VPS - Only OpenVZ + * + * @param int $vid The VMs ID + * @return array An array containing all the processes is returned + * @author Pulkit Gupta + */ + public function processes($vid) + { + + $resp = $this->call('index.php?svs='.$vid.'&act=processes'); + + return $resp['processes']; + + } + + + /** + * List the Services in a VPS - Only OpenVZ + * + * @param int $vid The VMs ID + * @return array An array containing all the services is returned + * @author Pulkit Gupta + */ + public function services($vid) + { + + $resp = $this->call('index.php?svs='.$vid.'&act=services'); + + $ret['services'] = $resp['services']; + $ret['autostart'] = $resp['autostart']; + $ret['running'] = $resp['running']; + + return $ret; + + } + + + /** + * Changes the root password of a VPS + * + * @param int $vid The VMs ID + * @param string $pass The new password to set + * @return string FALSE is returned if there was an error while setting the new password + * 'onboot' is returned if the new password will be set when the VPS is STOPPED and STARTED + * 'done' is returned if the new password has been set right now - Mainly OpenVZ + * @author Pulkit Gupta + */ + public function changepassword($vid, $pass) + { + + $post = [ + 'newpass' => $pass, + 'conf' => $pass, + 'changepass' => 'Change Password' + ]; + + $resp = $this->call('index.php?svs='.$vid.'&act=changepassword', $post); + + // Was there an error + if (!empty($resp['error'])) { + + $this->error = $resp['error']; + return false; + + // Will it be done when the VPS is STOPPED and STARTED ? + } elseif (!empty($resp['onboot'])) { + + return 'onboot'; + + // It was done successfully + } elseif (!empty($resp['done'])) { + + return 'done'; + + } + + } + + /** + * Get the VNC Details like PORT, IP, VNC Password. Only available in case of Xen and KVM VPS if VNC is enabled. + * + * @param int $vid The VMs ID + * @return array An array containing all the VNC Details + * @author Pulkit Gupta + */ + public function vnc($vid) + { + + $resp = $this->call('index.php?svs='.$vid.'&act=vnc'); + + return $resp['info']; + + } + + /** + * Change the VNC Password. Only available in case of Xen and KVM VPS if VNC is enabled. + * + * @param int $vid The VMs ID + * @param string $pass The new password to set + * @return string FALSE is returned if there was an error while setting the new password + * 'onboot' is returned if the new password will be set when the VPS is STOPPED and STARTED + * @author Pulkit Gupta + */ + public function vncpass($vid, $pass) + { + + $post = [ + 'newpass' => $pass, + 'conf' => $pass, + 'vncpass' => 'Change Password' + ]; + + $resp = $this->call('index.php?svs='.$vid.'&act=vncpass', $post); + + // Was there an error + if (!empty($resp['error'])) { + + $this->error = $resp['error']; + return false; + + // Will it be done when the VPS is STOPPED and STARTED ? + } elseif (!empty($resp['onboot']) || !empty($resp['done'])) { + + return 'onboot'; + + } + + } + + /** + * Re-installs a VPS if the $newosid is specified. If the $newosid is not passed, + * then this function will return an array of available templates. + * + * @param int $vid The VMs ID + * @param int $newosid The Operating System ID (you got from the list) that will be installed on the VPS. + * @param string $newpass The new root password to set + * @return string FALSE is returned if there was an error while setting the new password + * string 'onboot' is returned if the new password will be set when the VPS is STOPPED and STARTED + * string 'done' is returned if the new password has been set right now - Mainly OpenVZ + * array An array of the list of avvailable OS Templates is returned if $newosid is NULL + * @author Pulkit Gupta + */ + public function ostemplate($vid, $newosid = null, $newpass = null) + { + + // Get the list of OS Templates + $resp = $this->call('index.php?svs='.$vid.'&act=ostemplate'); + + // Get a list of Virtual Servers + $listvs = $this->listvs(); + + // Is there such a VPS ? + if (!empty($listvs[$vid])) { + + $resp = $resp['oslist'][$listvs[$vid]['virt']]; + + // No such VPS. Return an EMPTY ARRAY + } else { + + return []; + + } + + if (!empty($newosid)) { + + // The POST Vars + $post = [ + 'newos' => $newosid, + 'newpass' => $newpass, + 'conf' => $newpass, + 'reinsos' => 'Reinstall' + ]; + + $resp = $this->call('index.php?svs='.$vid.'&act=ostemplate', $post); + + // Was there an error + if (!empty($resp['error'])) { + + $this->error = $resp['error']; + return false; + + // Will it be done when the VPS is STOPPED and STARTED ? + } elseif (!empty($resp['onboot'])) { + + return 'onboot'; + + // It was done successfully + } elseif (!empty($resp['done'])) { + + return 'done'; + + } + + // Just return the OS List + } else { + return $resp; + } + + } + + + /** + * Install a Control Panel + * + * @param int $vid The VMs ID + * @param string $panel The Name of the Panel you want to install. Options - cpanel, plesk, webuzo, kloxo, webmin + * @return string FALSE is returned if there was an error while installing the control panel + * 'onboot' is returned if the control panel will be installed when the VPS is STOPPED and STARTED + * 'done' is returned if the control panel has been installed right now - Mainly OpenVZ + * @author Pulkit Gupta + */ + public function controlpanel($vid, $panel) + { + + $post['ins'][$panel] = 1; + + $resp = $this->call('index.php?svs='.$vid.'&act=controlpanel', $post); + + // Was there an error + if (!empty($resp['error'])) { + + $this->error = $resp['error']; + return false; + + // Will it be done when the VPS is STOPPED and STARTED ? + } elseif (!empty($resp['onboot'])) { + + return 'onboot'; + + // It was done successfully + } elseif (!empty($resp['done'])) { + + return 'done'; + + } + + } + +} + +////////////// +// Examples +////////////// + +//$v = new Virtualizor_Enduser_API('127.0.0.1', '16_BIT_API_KEY', '32_BIT_API_PASS'); + +// Get the list of the VPS +//$v->r($v->listvs()); + +// Start a VPS +//echo $v->start(3); + +// Stop a VPS +//echo $v->stop(3); + +// Restart a VPS +//echo $v->restart(3); + +// Poweroff a VPS +//echo $v->poweroff(3); + +// Get the Status of a VPS +//echo $v->status(3); + +// Get the Hostname +//echo $v->hostname(4); + +// Change the Hostname +//$v->r($v->hostname(4, 'NEWHOSTNAME')); + +// CPU Details +//$v->r($v->cpu(4)); + +// Ram Details +//$v->r($v->ram(4)); + +// Disk Details +//$v->r($v->disk(4)); + +// Bandwidth Details for the Current Month +//$v->r($v->bandwidth(4)); + +// Bandwidth Details for the Month of May in 2012 +//$v->r($v->bandwidth(4, 201205)); + +// List the processes - OpenVZ only +//$v->r($v->processes(4)); + +// List the services - OpenVZ only +//$v->r($v->services(4)); + +// Change the Root Password of a Virtual Server ? +//$v->r($v->changepassword(4, 'test')); + +// Give the VNC Details - VNC must be enabled - Xen / KVM +//$v->r($v->vnc(4)); + +// Change the VNC Password - VNC must be enabled - Xen / KVM +//$v->r($v->vncpass(4, 'NEWpass')); + +// List available OS Templates +//$v->r($v->ostemplate(2)); + +// Reinstall the OS +//$v->r($v->ostemplate(4, 1, 'test')); + +// Install a Control Panel +//$v->r($v->controlpanel(4, 'cpanel')); + +?> \ No newline at end of file From fb8098cc977e8648bbe857ca036cebc49205ea78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=BA=D9=84=D8=A7=D9=85=D8=B1=D8=B6=D8=A7=20=D8=A8=D9=87?= =?UTF-8?q?=D8=B4=D8=AA=DB=8C=D8=A7=D9=86?= Date: Wed, 24 Nov 2021 14:17:56 +0330 Subject: [PATCH 02/18] start Project --- composer.json | 40 +- index.php | 33 ++ src/PostData/BasePostData.php | 117 ---- src/PostData/BasePostDataInterface.php | 30 - src/PostData/CreateVS.php | 163 +++--- src/Responses/Admin/AddVs.php | 16 + src/Responses/Admin/BaseResponse.php | 59 ++ src/Responses/Admin/GlobalResponse.php | 17 + src/Responses/Admin/Ip.php | 39 ++ src/Responses/Admin/IpFull.php | 42 ++ src/Responses/Admin/Ippool.php | 20 + src/Responses/Admin/Ipsresponse.php | 18 + src/Responses/Admin/ListVs.php | 211 +------ src/Responses/Admin/LowResponseBase.php | 20 + src/Responses/Admin/Os.php | 40 ++ src/Responses/Admin/Os2.php | 22 + src/Responses/Admin/OsTemplate.php | 61 +- src/Responses/Admin/Plan.php | 162 ++++++ src/Responses/Admin/Resource.php | 66 +++ src/Responses/Admin/Server.php | 268 +++------ src/Responses/Admin/ServerGroup.php | 24 + src/Responses/Admin/Server_list.php | 18 + src/Responses/Admin/Storage.php | 44 ++ src/Responses/Admin/User.php | 22 + src/Responses/Admin/VS.php | 380 +++--------- src/Responses/BaseResponse.php | 25 - src/VirtualizorAdmin.php | 737 ++++++++++++++---------- 27 files changed, 1404 insertions(+), 1290 deletions(-) create mode 100644 index.php delete mode 100644 src/PostData/BasePostData.php delete mode 100644 src/PostData/BasePostDataInterface.php create mode 100644 src/Responses/Admin/AddVs.php create mode 100644 src/Responses/Admin/BaseResponse.php create mode 100644 src/Responses/Admin/GlobalResponse.php create mode 100644 src/Responses/Admin/Ip.php create mode 100644 src/Responses/Admin/IpFull.php create mode 100644 src/Responses/Admin/Ippool.php create mode 100644 src/Responses/Admin/Ipsresponse.php create mode 100644 src/Responses/Admin/LowResponseBase.php create mode 100644 src/Responses/Admin/Os.php create mode 100644 src/Responses/Admin/Os2.php create mode 100644 src/Responses/Admin/Plan.php create mode 100644 src/Responses/Admin/Resource.php create mode 100644 src/Responses/Admin/ServerGroup.php create mode 100644 src/Responses/Admin/Server_list.php create mode 100644 src/Responses/Admin/Storage.php create mode 100644 src/Responses/Admin/User.php delete mode 100644 src/Responses/BaseResponse.php diff --git a/composer.json b/composer.json index 354dd41..bccb501 100644 --- a/composer.json +++ b/composer.json @@ -1,19 +1,27 @@ { - "name": "yiiman/virtualizor", - "description": "Tiny SDK for virtualizor", - "type": "library", - "license": "Apache", - "autoload": { - "psr-4": { - "YiiMan\\VirtualizorSdk\\": "src/" - } + "name": "yiiman/virtualizor", + "description": "Tiny SDK for virtualizor", + "type": "library", + "license": "Apache", + "autoload": { + "psr-4": { + "YiiMan\\VirtualizorSdk\\": "src/" + } + }, + "authors": [ + { + "name": "YiiMan", + "email": "info@yiiman.ir", + "homepage": "https://yiiman.ir" }, - "authors": [ - { - "name": "غلامرضا بهشتیان", - "email": "amintado@gmail.com" - } - ], - "minimum-stability": "stable", - "require": {} + { + "name": "AriaNet", + "homepage": "https://ariaservice.net", + "email": "develop@ariaservice.net" + } + ], + "minimum-stability": "stable", + "require": { + "yiiman/apistorm": "dev-main" + } } diff --git a/index.php b/index.php new file mode 100644 index 0000000..d78a7e7 --- /dev/null +++ b/index.php @@ -0,0 +1,33 @@ +'; +$sv = new CreateVS(); +$sv->cores = 1; + +$sv->rootpass0='yiiman'; +$sv->virt=$sv::VIRTUALIZOR_TYPE_kvm; +$sv->user_email0='info@yiiman.ir'; +$sv->user_pass='YiiMan@@@22'; +$sv->hostname0='yiiman'; +$sv->osid0=870; +$sv->plid0=1; + + +//$res=$visualizor->listvs(); +$res=$visualizor->ips(); +$sv->ips[]=$res->ips[0]->gateway; +$servers=$visualizor->servers(); +$sv->node_select0=$servers->servers[0]->serid; +$created=$visualizor->addvs($sv, []); + +echo 'finish'; diff --git a/src/PostData/BasePostData.php b/src/PostData/BasePostData.php deleted file mode 100644 index 83b2a3f..0000000 --- a/src/PostData/BasePostData.php +++ /dev/null @@ -1,117 +0,0 @@ -getProperties(\ReflectionProperty::IS_PUBLIC); - foreach ($props as $prop) { - if (!isset($this->{$prop->name})) { - continue; - } - $out[$prop->name] = $this->{$prop->name}; - } - - return $out; - } - - private function addError($prop, $error) - { - $this->errors[$prop] = $error; - } - - private function checkRequires() - { - $hasError = false; - $requires = $this->requiredFields(); - if (!empty($requires)) { - foreach ($requires as $f) { - if (!isset($this->{$f})) { - $this->addError($f, $f.' is required'); - $hasError = true; - } - } - } - - if ($hasError) { - return false; - } - return true; - } - - private function checkTypes() - { - $hasError = false; - $reflect = new \ReflectionClass($this); - $props = $reflect->getProperties(\ReflectionProperty::IS_PUBLIC); - foreach ($props as $prop) { - if (!isset($this->{$prop->name})) { - continue; - } - $type = $this->rules()[$prop->name]; - - if (is_callable($type)) { - if ($this->{$prop->name} instanceof $type) { - $this->addError($prop->name, $prop.'should instant of class'); - $hasError = true; - } - } else { - $isOk = true; - switch ($type) { - case 'integer': - $isOk = (is_int($this->{$prop->name}) | is_integer($this->{$prop->name})) ? true : false; - break; - case 'string': - $isOk = (is_string($this->{$prop->name})) ? true : false; - break; - case 'array': - $isOk = (is_array($this->{$prop->name})) ? true : false; - break; - case 'bool': - case 'boolean': - $isOk = (is_bool($this->{$prop->name})) ? true : false; - break; - } - - if (!$isOk) { - $this->addError($prop->name, $prop->name.' type should be '.$type); - $hasError = true; - } - } - } - - - if ($hasError) { - return true; - } else { - return false; - } - } - - public function validate(): bool - { - if ($this->checkRequires() * $this->checkTypes()) { - return true; - } else { - return false; - } - } -} \ No newline at end of file diff --git a/src/PostData/BasePostDataInterface.php b/src/PostData/BasePostDataInterface.php deleted file mode 100644 index e95f27c..0000000 --- a/src/PostData/BasePostDataInterface.php +++ /dev/null @@ -1,30 +0,0 @@ -'int'|'string'|'float'|'array'|'object'|'class'|'boolean' - * ] - * @return array - */ - public function rules():array; - - -} \ No newline at end of file diff --git a/src/PostData/CreateVS.php b/src/PostData/CreateVS.php index 4deef17..a7422df 100644 --- a/src/PostData/CreateVS.php +++ b/src/PostData/CreateVS.php @@ -5,40 +5,43 @@ namespace YiiMan\VirtualizorSdk\PostData; +use YiiMan\ApiStorm\Post\BasePostData; + /** * Class CreateVS * @package YiiMan\VirtualizorSdk\PostData - * @property $serid - * @property integer $slave_server The slave server ID on which vps is to be created - * @property string $virt The Virtualization Technology has to be specified here, refer below table for valid values - * @property integer $uid Selects a unique ID of the user to which the vps will be assigned - * @property string $user_email Add User Email - * @property string $user_pass Add a password - * @property string $fname Add user first name - * @property string $lname Add user last name - * @property integer $plid The plan ID for the VPS - * @property integer $osid The ID of the Operating System - * @property string $hostname The hostname the VPS - * @property string $rootpass The root password for the VPS - * @property array $ips The IP Address(s) for the VPS - * @property integer $num_ips6 The Number of Ipv6 Address given to the vps - * @property integer $num_ips6_subnet The Number of IPV6 Subnet to be assigned to the vps - * @property integer $stid Storage ID on which the VPS is to be created. (Not needed if using Primary storage) - * @property array $space The disk space for the VPS. In case of Multiple Disk you can specify the array as given in the example. Otherwise just value for single disk VPS is enough - * @property integer $ram The ram value in MBs for the VPS - * @property integer $swapram The amount of SWAP for the VPS (Only for KVM, Xen, Proxmox KVM and XCP) - * @property integer $bandwidth The network bandwidth for the VPS: 0 (Zero) for unlimited - * @property integer $network_speed The network_speed for the VPS in KB/s - * @property integer $cpu The CPU weight for the VPS - * @property integer $cores The number of cores allotted to the VPS - * @property integer $cpu_percent The CPU Percent time for the VPS (Only for OpenVZ and Proxmox) - * @property bool $vnc Flag to enable vnc(0 or 1) (Only for KVM and Xen) - * @property string $vncpass The vnc password (Only for KVM and Xen) - * @property string $kvm_cache The type disk-cache mechanism can be writeback, writethrough, directsync or default (Only for KVM and Proxmox KVM) - * @property string $io_mode Sets the I/O policy for the VPS can be native/threads (Only for KVM) - * @property string $vnc_keymap Allows to select keymap can be 'en-us', 'de-ch', 'ar', 'da', 'et', 'fo', 'fr-be', 'fr-ch', 'hu', 'it', 'lt', 'mk', 'nl', 'no', 'pt', 'ru', 'sv', 'tr', 'de', 'en-gb', 'es', 'fi', 'fr', 'fr-ca', 'hr', 'is', 'ja', 'lv', 'nl-be', 'pl', 'pt-br', 'sl', 'th' - * @property string $nic_type The NIC type (default or e1000) (Only for KVM and Xen) - * @property integer $osreinstall_limi If you want to limit the number of OS re-installs per month.Eg. 0 - is unlimited + * @property integer $node_select0 server id that you want creta new vps on that + * @property string $user_email0 Add User Email + * @property integer $plid0 The plan ID for the VPS + * @property integer $osid0 The ID of the Operating System + * @property string $hostname0 The hostname the VPS + * @property string $rootpass0 The root password for the VPS + * @property $serid + * @property integer $slave_server The slave server ID on which vps is to be created + * @property string $virt The Virtualization Technology has to be specified here, refer below table for valid values + * @property integer $uid Selects a unique ID of the user to which the vps will be assigned + * @property string $user_pass Add a password + * @property string $fname Add user first name + * @property string $lname Add user last name + * @property array $ips The IP Address(s) for the VPS + * @property integer $num_ips6 The Number of Ipv6 Address given to the vps + * @property integer $num_ips6_subnet The Number of IPV6 Subnet to be assigned to the vps + * @property integer $stid Storage ID on which the VPS is to be created. (Not needed if using Primary storage) + * @property array $space The disk space for the VPS. In case of Multiple Disk you can specify the array as given in the example. Otherwise just value for single disk VPS is enough + * @property integer $ram The ram value in MBs for the VPS + * @property integer $swapram The amount of SWAP for the VPS (Only for KVM, Xen, Proxmox KVM and XCP) + * @property integer $bandwidth The network bandwidth for the VPS: 0 (Zero) for unlimited + * @property integer $network_speed The network_speed for the VPS in KB/s + * @property integer $cpu The CPU weight for the VPS + * @property integer $cores The number of cores allotted to the VPS + * @property integer $cpu_percent The CPU Percent time for the VPS (Only for OpenVZ and Proxmox) + * @property bool $vnc Flag to enable vnc(0 or 1) (Only for KVM and Xen) + * @property string $vncpass The vnc password (Only for KVM and Xen) + * @property string $kvm_cache The type disk-cache mechanism can be writeback, writethrough, directsync or default (Only for KVM and Proxmox KVM) + * @property string $io_mode Sets the I/O policy for the VPS can be native/threads (Only for KVM) + * @property string $vnc_keymap Allows to select keymap can be 'en-us', 'de-ch', 'ar', 'da', 'et', 'fo', 'fr-be', 'fr-ch', 'hu', 'it', 'lt', 'mk', 'nl', 'no', 'pt', 'ru', 'sv', 'tr', 'de', 'en-gb', 'es', 'fi', 'fr', 'fr-ca', 'hr', 'is', 'ja', 'lv', 'nl-be', 'pl', 'pt-br', 'sl', 'th' + * @property string $nic_type The NIC type (default or e1000) (Only for KVM and Xen) + * @property integer $osreinstall_limit If you want to limit the number of OS re-installs per month.Eg. 0 - is unlimited */ class CreateVS extends BasePostData { @@ -88,15 +91,15 @@ class CreateVS extends BasePostData public int $slave_server; public string $virt; public int $uid = 0; - public string $user_email; + public string $user_email0; public string $user_pass; public string $fname; public string $lname; - public int $plid = 0; - public int $osid = 0; - public string $hostname; - public string $rootpass; - public array $ips; + public int $plid0; + public int $osid0; + public string $hostname0; + public string $rootpass0; + public array $ips = []; public int $num_ips6; public int $num_ips6_subnet; public int $stid; @@ -110,66 +113,52 @@ class CreateVS extends BasePostData public int $cpu_percent = 100; public int $vnc = 1; public string $vncpass = 'test'; - public int $kvm_cache = 0; - public int $io_mode = 0; + public string $kvm_cache = 'writeback'; + public string $io_mode = 'native'; public string $vnc_keymap = 'en-us'; public string $nic_type = 'default'; public int $osreinstall_limit = 0; + public $node_select0; + public $addvps = 1; - public function requiredFields(): array - { - return - [ - 'virt', - 'user_email', - 'user_pass', - 'hostname', - 'rootpass', - 'osid', - 'ips', - 'space', - 'ram', - 'bandwidth', - 'cores' - ]; - } - public function rules(): array { return [ - 'slave_server' => 'integer', - 'virt' => 'string', - 'uid' => 'integer', - 'user_email' => 'string', - 'user_pass' => 'string', - 'fname' => 'string', - 'lname' => 'string', - 'plid' => 'integer', - 'osid' => 'integer', - 'hostname' => 'string', - 'rootpass' => 'string', - 'ips' => 'array', - 'num_ips6' => 'integer', - 'num_ips6_subnet' => 'integer', - 'stid' => 'integer', - 'space' => 'integer', - 'ram' => 'integer', - 'swapram' => 'integer', - 'bandwidth' => 'integer', - 'network_speed' => 'integer', - 'cpu' => 'integer', - 'cores' => 'integer', - 'cpu_percent' => 'integer', - 'vnc' => 'integer', - 'vncpass' => 'string', - 'kvm_cache' => 'string', - 'io_mode' => 'string', - 'vnc_keymap' => 'string', - 'nic_type' => 'string', - 'osreinstall_limi' => 'integer', + 'slave_server' => 'integer', + 'virt' => 'string', + 'uid' => 'integer', + 'user_email' => 'string', + 'user_pass' => 'string', + 'fname' => 'string', + 'lname' => 'string', + 'plid' => 'integer', + 'osid' => 'integer', + 'hostname' => 'string', + 'rootpass' => 'string', + 'ips' => 'array', + 'num_ips6' => 'integer', + 'num_ips6_subnet' => 'integer', + 'stid' => 'integer', + 'space' => 'integer', + 'ram' => 'integer', + 'swapram' => 'integer', + 'bandwidth' => 'integer', + 'network_speed' => 'integer', + 'cpu' => 'integer', + 'cores' => 'integer', + 'cpu_percent' => 'integer', + 'vnc' => 'integer', + 'vncpass' => 'string', + 'kvm_cache' => 'string', + 'io_mode' => 'string', + 'vnc_keymap' => 'string', + 'nic_type' => 'string', + 'osreinstall_limit' => 'integer', + 'node_select' => 'integer' ]; } + } \ No newline at end of file diff --git a/src/Responses/Admin/AddVs.php b/src/Responses/Admin/AddVs.php new file mode 100644 index 0000000..14c5e48 --- /dev/null +++ b/src/Responses/Admin/AddVs.php @@ -0,0 +1,16 @@ +title = $data->title; - $this->network_status = $data->network_status; - $this->owners = $data->owners; - $this->plans = $data->plans; - $this->backup_plans = $data->backup_plans; - $this->timenow = $data->timenow; - $this->time_taken = $data->time_taken; - - - if (!empty($data->vs)) { - foreach ($data->vs as $v) { - $v=(object)$v; - $this->vs[] = new VS( - $v->vpsid, - $v->vps_name, - $v->uuid, - $v->serid, - $v->time, - $v->edittime, - $v->virt, - $v->uid, - $v->plid, - $v->hostname, - $v->osid, - $v->os_name, - $v->iso, - $v->sec_iso, - $v->boot, - $v->space, - $v->inodes, - $v->ram, - $v->burst, - $v->swap, - $v->cpu, - $v->cores, - $v->cpupin, - $v->cpu_percent, - $v->bandwidth, - $v->network_speed, - $v->upload_speed, - $v->io, - $v->ubc, - $v->acpi, - $v->apic, - $v->pae, - $v->shadow, - $v->vnc, - $v->vncport, - $v->vnc_passwd, - $v->hvm, - $v->suspended, - $v->suspend_reason, - $v->nw_suspended, - $v->rescue, - $v->band_suspend, - $v->tuntap, - $v->ppp, - $v->ploop, - $v->dns_nameserver, - $v->osreinstall_limit, - $v->preferences, - $v->nic_type, - $v->vif_type, - $v->virtio, - $v->pv_on_hvm, - $v->disks, - $v->kvm_cache, - $v->io_mode, - $v->cpu_mode, - $v->total_iops_sec, - $v->read_bytes_sec, - $v->write_bytes_sec, - $v->kvm_vga, - $v->acceleration, - $v->vnc_keymap, - $v->routing, - $v->mg, - $v->used_bandwidth, - $v->cached_disk, - $v->webuzo, - $v->disable_ebtables, - $v->install_xentools, - $v->admin_managed, - $v->rdp, - $v->topology_sockets, - $v->topology_cores, - $v->topology_threads, - $v->mac, - $v->notes, - $v->disable_nw_config, - $v->locked, - $v->openvz_features, - $v->speed_cap, - $v->numa, - $v->bpid, - $v->bserid, - $v->timezone, - $v->ha, - $v->data, - $v->server_name, - $v->email, - $v->pid, - $v->type, - $v->os_distro, - $v->stid, - $v->ips - ); - } - } - - if (!empty($data->ostemplates)) { - foreach ($data->ostemplates as $o) { - $o=(object)$o; - $this->osTemplates[] = new OsTemplate( - $o->osid, - $o->type, - $o->name, - $o->filename, - $o->size, - $o->pygrub, - $o->drive, - $o->hvm, - $o->perf_ops, - $o->active, - $o->url, - $o->distro, - $o->Nvirt - ); - } - } - - if (!empty($data->servers)) { - foreach ($data->servers as $server) { - $server=(object)$server; - $this->servers[] = new Server( - $server->serid, - $server->sgid, - $server->server_name, - $server->virt, - $server->ip, - $server->internal_ip, - $server->vnc_ip, - $server->settings, - $server->unique_txt, - $server->lv, - $server->hvm, - $server->licnumvs, - $server->total_ram, - $server->overcommit, - $server->ram, - $server->total_space, - $server->space, - $server->os, - $server->os_arch, - $server->uname, - $server->version, - $server->patch, - $server->lic_expires, - $server->checked, - $server->locked, - $server->vcores, - $server->ips, - $server->ipv6, - $server->ipv6_subnet, - $server->ips_int, - $server->bandwidth, - $server->update_resource, - $server->location, - $server->status, - $server->last_reverse_sync, - $server->ha_master, - $server->numvps, - $server->alloc_ram, - $server->alloc_space, - $server->alloc_cpu, - $server->alloc_cpu_percent, - $server->alloc_bandwidth, - $server->virts - ); - } - } - } } \ No newline at end of file diff --git a/src/Responses/Admin/LowResponseBase.php b/src/Responses/Admin/LowResponseBase.php new file mode 100644 index 0000000..a77b4e8 --- /dev/null +++ b/src/Responses/Admin/LowResponseBase.php @@ -0,0 +1,20 @@ +osid = $osid; - $this->type = $type; - $this->name = $name; - $this->filename = $filename; - $this->size = $size; - $this->pygrub = $pygrub; - $this->drive = $drive; - $this->hvm = $hvm; - $this->perf_ops = $perf_ops; - $this->active = $active; - $this->url = $url; - $this->distro = $distro; - $this->Nvirt = $Nvirt; - } + $osid = 'int', + $type = 'string', + $name = 'string', + $filename = 'string', + $size = 'int', + $pygrub = 'int', + $drive = 'string', + $hvm = 'int', + $perf_ops = 'int', + $active = 'bool', + $url = 'string', + $distro = 'string', + $Nvirt = 'string'; } \ No newline at end of file diff --git a/src/Responses/Admin/Plan.php b/src/Responses/Admin/Plan.php new file mode 100644 index 0000000..5b1dada --- /dev/null +++ b/src/Responses/Admin/Plan.php @@ -0,0 +1,162 @@ +serid = $serid; - $this->sgid = $sgid; - $this->server_name = $server_name; - $this->virt = $virt; - $this->ip = $ip; - $this->internal_ip = $internal_ip; - $this->vnc_ip = $vnc_ip; - $this->settings = $settings; - $this->unique_txt = $unique_txt; - $this->lv = $lv; - $this->hvm = $hvm; - $this->licnumvs = $licnumvs; - $this->total_ram = $total_ram; - $this->overcommit = $overcommit; - $this->ram = $ram; - $this->total_space = $total_space; - $this->space = $space; - $this->os = $os; - $this->os_arch = $os_arch; - $this->uname = $uname; - $this->version = $version; - $this->patch = $patch; - $this->lic_expires = $lic_expires; - $this->checked = $checked; - $this->locked = $locked; - $this->vcores = $vcores; - $this->ips = $ips; - $this->ipv6 = $ipv6; - $this->ipv6_subnet = $ipv6_subnet; - $this->ips_int = $ips_int; - $this->bandwidth = $bandwidth; - $this->update_resource = $update_resource; - $this->location = $location; - $this->status = $status; - $this->last_reverse_sync = $last_reverse_sync; - $this->ha_master = $ha_master; - $this->numvps = $numvps; - $this->alloc_ram = $alloc_ram; - $this->alloc_space = $alloc_space; - $this->alloc_cpu = $alloc_cpu; - $this->alloc_cpu_percent = $alloc_cpu_percent; - $this->alloc_bandwidth = $alloc_bandwidth; - $this->virts = $virts; - } } \ No newline at end of file diff --git a/src/Responses/Admin/ServerGroup.php b/src/Responses/Admin/ServerGroup.php new file mode 100644 index 0000000..2468b85 --- /dev/null +++ b/src/Responses/Admin/ServerGroup.php @@ -0,0 +1,24 @@ +vpsid = (int) $vpsid; - $this->vps_name = $vps_name; - $this->uuid = $uuid; - $this->serid = $serid; - $this->time = $time; - $this->edittime = $edittime; - $this->virt = $virt; - $this->uid = (int) $uid; - $this->plid = (int) $plid; - $this->hostname = $hostname; - $this->osid = (int) $osid; - $this->os_name = $os_name; - $this->iso = $iso; - $this->sec_iso = $sec_iso; - $this->boot = $boot; - $this->space = (float) $space; - $this->inodes = $inodes; - $this->ram = (int) $ram; - $this->burst = $burst; - $this->swap = $swap; - $this->cpu = (float) $cpu; - $this->cores = (int) $cores; - $this->cpupin = (int) $cpupin; - $this->cpu_percent = (float) $cpu_percent; - $this->bandwidth = (float) $bandwidth; - $this->network_speed = (int) $network_speed; - $this->upload_speed = (int) $upload_speed; - $this->io = $io; - $this->ubc = !empty($ubc) ? unserialize($ubc) : $ubc; - $this->acpi = (int) $acpi; - $this->apic = (int) $apic; - $this->pae = (int) $pae; - $this->shadow = (int) $shadow; - $this->vnc = (int) $vnc; - $this->vncport = (int) $vncport; - $this->vnc_passwd = $vnc_passwd; - $this->hvm = (int) $hvm; - $this->suspended = (bool) $suspended; - $this->suspend_reason = $suspend_reason; - $this->nw_suspended = $nw_suspended; - $this->rescue = $rescue; - $this->band_suspend = $band_suspend; - $this->tuntap = $tuntap; - $this->ppp = $ppp; - $this->ploop = $ploop; - $this->dns_nameserver = !empty($dns_nameserver) ? unserialize($dns_nameserver) : $dns_nameserver; - $this->osreinstall_limit = $osreinstall_limit; - $this->preferences = $preferences; - $this->nic_type = $nic_type; - $this->vif_type = $vif_type; - $this->virtio = $virtio; - $this->pv_on_hvm = $pv_on_hvm; - $this->disks = $disks; - $this->kvm_cache = $kvm_cache; - $this->io_mode = $io_mode; - $this->cpu_mode = $cpu_mode; - $this->total_iops_sec = $total_iops_sec; - $this->read_bytes_sec = $read_bytes_sec; - $this->write_bytes_sec = $write_bytes_sec; - $this->kvm_vga = $kvm_vga; - $this->acceleration = $acceleration; - $this->vnc_keymap = $vnc_keymap; - $this->routing = $routing; - $this->mg = $mg; - $this->used_bandwidth = $used_bandwidth; - $this->cached_disk = !empty($cached_disk) ? unserialize($cached_disk) : $cached_disk; - $this->webuzo = $webuzo; - $this->disable_ebtables = $disable_ebtables; - $this->install_xentools = $install_xentools; - $this->admin_managed = $admin_managed; - $this->rdp = $rdp; - $this->topology_sockets = $topology_sockets; - $this->topology_cores = $topology_cores; - $this->topology_threads = $topology_threads; - $this->mac = $mac; - $this->notes = $notes; - $this->disable_nw_config = $disable_nw_config; - $this->locked = $locked; - $this->openvz_features = $openvz_features; - $this->speed_cap = $speed_cap; - $this->numa = $numa; - $this->bpid = $bpid; - $this->bserid = $bserid; - $this->timezone = $timezone; - $this->ha = $ha; - $this->data = !empty($data) ? json_decode($data) : $data; - $this->server_name = $server_name; - $this->email = $email; - $this->pid = $pid; - $this->type = $type; - $this->os_distro = $os_distro; - - $this->stid = $stid; - $this->ips = $ips; - } } \ No newline at end of file diff --git a/src/Responses/BaseResponse.php b/src/Responses/BaseResponse.php deleted file mode 100644 index 5762deb..0000000 --- a/src/Responses/BaseResponse.php +++ /dev/null @@ -1,25 +0,0 @@ -key = $key; $this->pass = $pass; $this->ip = $ip; $this->port = $port; - if($port != 4085){ + if ($port != 4085) { $this->protocol = 'http'; } } /** * Dumps a variable - * * @author Pulkit Gupta - * @param array $re The Array or any other variable. + * @param array $re The Array or any other variable. * @return NULL */ - function r($re){ + function r($re) + { echo '
';
         print_r($re);
         echo '
'; @@ -54,26 +61,26 @@ function r($re){ /** * Unserializes a string - * * @author Pulkit Gupta - * @param string $str The serialized string + * @param string $str The serialized string * @return array The unserialized array on success OR false on failure */ - function _unserialize($str){ + function _unserialize($str) + { $var = @unserialize($str); - if(empty($var)){ + if (empty($var)) { $str = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'._strlen('$2').':\"$2\";'", $str); $var = @unserialize($str); } //If it is still empty false - if(empty($var)){ + if (empty($var)) { return false; - }else{ + } else { return $var; @@ -83,33 +90,33 @@ function _unserialize($str){ /** * Make an API Key - * * @author Pulkit Gupta - * @param string $key An 8 bit random string - * @param string $pass The API Password of your NODE + * @param string $pass The API Password of your NODE + * @param string $key An 8 bit random string * @return string The new APIKEY which will be used to query */ - function make_apikey($key, $pass){ + function make_apikey($key, $pass) + { return $key.md5($pass.$key); } /** * Generates a random string for the given length - * * @author Pulkit Gupta - * @param int $length The length of the random string to be generated + * @param int $length The length of the random string to be generated * @return string The generated random string */ - function generateRandStr($length){ + function generateRandStr($length) + { $randstr = ""; - for($i = 0; $i < $length; $i++){ - $randnum = mt_rand(0,61); - if($randnum < 10){ - $randstr .= chr($randnum+48); - }elseif($randnum < 36){ - $randstr .= chr($randnum+55); - }else{ - $randstr .= chr($randnum+61); + for ($i = 0; $i < $length; $i++) { + $randnum = mt_rand(0, 61); + if ($randnum < 10) { + $randstr .= chr($randnum + 48); + } elseif ($randnum < 36) { + $randstr .= chr($randnum + 55); + } else { + $randstr .= chr($randnum + 61); } } return strtolower($randstr); @@ -117,24 +124,24 @@ function generateRandStr($length){ /** * Makes an API request to the server to do a particular task - * * @author Pulkit Gupta - * @param string $path The action you want to do - * @param array $post An array of DATA that should be posted - * @param array $cookies An array FOR SENDING COOKIES + * @param array $post An array of DATA that should be posted + * @param array $cookies An array FOR SENDING COOKIES + * @param string $path The action you want to do * @return array The unserialized array on success OR false on failure */ - function call($path, $data = array(), $post = array(), $cookies = array()){ + function call($path, $data = [], $post = [], $cookies = []) + { $key = $this->generateRandStr(8); $apikey = $this->make_apikey($key, $this->pass); - $url = ($this->protocol).'://'.$this->ip.':'. $this->port .'/'. $path; + $url = ($this->protocol).'://'.$this->ip.':'.$this->port.'/'.$path; $url .= (strstr($url, '?') ? '' : '?'); $url .= '&api=serialize&apikey='.rawurlencode($apikey); // Pass some data if there - if(!empty($data)){ + if (!empty($data)) { $url .= '&apidata='.rawurlencode(base64_encode(serialize($data))); } // Set the curl parameters. @@ -145,19 +152,19 @@ function call($path, $data = array(), $post = array(), $cookies = array()){ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); // Turn off the server and peer verification (TrustManager Concept). - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // UserAgent curl_setopt($ch, CURLOPT_USERAGENT, 'Softaculous'); // Cookies - if(!empty($cookies)){ + if (!empty($cookies)) { curl_setopt($ch, CURLOPT_COOKIESESSION, true); curl_setopt($ch, CURLOPT_COOKIE, http_build_query($cookies, '', '; ')); } - if(!empty($post)){ + if (!empty($post)) { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); } @@ -165,19 +172,21 @@ function call($path, $data = array(), $post = array(), $cookies = array()){ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Get response from the server. + $resp = curl_exec($ch); curl_close($ch); + // The following line is a method to test //if(preg_match('/sync/is', $url)) echo $resp; - if(empty($resp)){ + if (empty($resp)) { return false; } $r = @unserialize($resp); - if(empty($r)){ + if (empty($r)) { return false; } @@ -187,405 +196,482 @@ function call($path, $data = array(), $post = array(), $cookies = array()){ /** * Create a VPS - * * @author Pulkit Gupta - * @param string $path The action you want to do - * @param array $post An array of DATA that should be posted - * @param array $cookies An array FOR SENDING COOKIES + * @param array $post An array of DATA that should be posted + * @param array $cookies An array FOR SENDING COOKIES + * @param string $path The action you want to do * @return array The unserialized array on success OR false on failure */ - function addippool($post){ + function addippool($post) + { $post['addippool'] = 1; $path = 'index.php?act=addippool'; - $ret = $this->call($path, array(), $post); + $ret = $this->call($path, [], $post); return $ret; } - function addips($post){ + function addips($post) + { $path = 'index.php?act=addips'; - $ret = $this->call($path, array(), $post); + $ret = $this->call($path, [], $post); return $ret; } - function addiso($post){ + function addiso($post) + { $path = 'index.php?act=addiso'; - $ret = $this->call($path, array(), $post); + $ret = $this->call($path, [], $post); return $ret; } - function addplan($post){ + function addplan($post) + { - $path ='index.php?act=addplan'; - $ret = $this->call($path, array(), $post); + $path = 'index.php?act=addplan'; + $ret = $this->call($path, [], $post); return $ret; } - function addserver($post){ - $path ='index.php?act=addserver'; - $ret = $this->call($path, array(), $post); + function addserver($post) + { + $path = 'index.php?act=addserver'; + $ret = $this->call($path, [], $post); return $ret; } - function addtemplate($post){ - $path ='index.php?act=addtemplate'; - $ret = $this->call($path, array(), $post); + function addtemplate($post) + { + $path = 'index.php?act=addtemplate'; + $ret = $this->call($path, [], $post); return $ret; } - function adduser($post = 0){ - $path ='index.php?act=adduser'; - $ret = $this->call($path, array(), $post); + function adduser($post = 0) + { + $path = 'index.php?act=adduser'; + $ret = $this->call($path, [], $post); return $ret; } /** - * @param $fields - * @return bool + * @param string $path + * @param $data + * @param BasePostData $servedData + * @param array $cookies + * @return Res */ - private function checkFields(&$fields){ - if(!$fields->validate()){ - return false; - }else{ - return true; + private function callStorm(string $path, $data = '', $servedData = null, $cookies = []) + { + + $key = $this->generateRandStr(8); + $apikey = $this->make_apikey($key, $this->pass); + + + $path .= '&api=serialize&apikey='.rawurlencode($apikey); + + // Pass some data if there + if (!empty($data)) { + $path .= '&apidata='.rawurlencode(base64_encode(serialize($data))); + } + $connection = new Connection(); + $connection->baseURL = $this->ip; + $connection->port = $this->port; + $connection->protocol = $this->protocol; + $connection->responseType = $connection::CONTENT_TYPE_SERIALIZED; + if (is_object($servedData)) { + $arrayData = $servedData->serve(); + } else { + $arrayData = []; } + + return $connection->call($path, [], $arrayData, $cookies); } /** * Create a VPS - * * @author Pulkit Gupta - * @param CreateVS $fields An array of DATA that should be posted - * @param array $cookies An array FOR SENDING COOKIES - * @return array The unserialized array on success OR false on failure + * @param array $cookies An array FOR SENDING COOKIES + * @param CreateVS $fields An array of DATA that should be posted + * @return VS|Res|bool */ - function addvs(CreateVS $fields,array $cookies){ + function addvs(CreateVS $fields, array $cookies = []) + { $path = 'index.php?act=addvs'; - if ($this->checkFields($fields)) { - $servedData=$fields->serve(); - $ret = $this->call($path, '',$servedData , $cookies); - return array( - 'title' => $ret['title'], - 'error' => @empty($ret['error']) ? array() : $ret['error'], - 'vs_info' => $ret['newvs'], - 'globals' => $ret['globals'] - ); - }else{ + if ($fields->validate()) { + + $ret = $this->callStorm($path, 'addvs', $fields, $cookies); + if ($ret->isSuccess()) { + $data = $ret->getData(); + if (!empty($data['error'])) { + $ret->setError(500, $data['error']); + return $ret; + } else { + return new AddVs($ret); + } + } else { + return $ret; + } +// return [ +// 'title' => $ret->getData()['title'], +// 'error' => @empty($ret->getData()['error']) ? [] : $ret->getData()['error'], +// 'vs_info' => !empty($ret->getData()['newvs']) ? new VS($ret->getData()['newvs']) : $ret->getData()['newvs'], +// 'globals' => new GlobalResponse($ret['globals']) +// ]; + } else { return false; } } - function addiprange($post){ - $path ='index.php?act=addiprange'; - $ret = $this->call($path, array(), $post); + function addiprange($post) + { + $path = 'index.php?act=addiprange'; + $ret = $this->call($path, [], $post); return $ret; } - function addsg($post){ - $path ='index.php?act=addsg'; - $ret = $this->call($path, array(), $post); + function addsg($post) + { + $path = 'index.php?act=addsg'; + $ret = $this->call($path, [], $post); return $ret; } - function addbackupserver($post){ - $path ='index.php?act=addbackupserver'; - $ret = $this->call($path, array(), $post); + function addbackupserver($post) + { + $path = 'index.php?act=addbackupserver'; + $ret = $this->call($path, [], $post); return $ret; } - function addstorage($post){ - $path ='index.php?act=addstorage'; - $ret = $this->call($path, array(), $post); + function addstorage($post) + { + $path = 'index.php?act=addstorage'; + $ret = $this->call($path, [], $post); return $ret; } - function adddnsplan($post){ - $path ='index.php?act=adddnsplan'; - $ret = $this->call($path, array(), $post); + function adddnsplan($post) + { + $path = 'index.php?act=adddnsplan'; + $ret = $this->call($path, [], $post); return $ret; } - function add_admin_acl($post){ - $path ='index.php?act=add_admin_acl'; - $ret = $this->call($path, array(), $post); + function add_admin_acl($post) + { + $path = 'index.php?act=add_admin_acl'; + $ret = $this->call($path, [], $post); return $ret; } - function addmg($post){ - $path ='index.php?act=addmg'; - $ret = $this->call($path, array(), $post); + function addmg($post) + { + $path = 'index.php?act=addmg'; + $ret = $this->call($path, [], $post); return $ret; } - function add_distro($post){ - $path ='index.php?act=add_distro'; - $ret = $this->call($path, array(), $post); + function add_distro($post) + { + $path = 'index.php?act=add_distro'; + $ret = $this->call($path, [], $post); return $ret; } - function addpdns($post){ - $path ='index.php?act=addpdns'; - $ret = $this->call($path, array(), $post); + function addpdns($post) + { + $path = 'index.php?act=addpdns'; + $ret = $this->call($path, [], $post); return $ret; } - - function adminindex(){ + function adminindex() + { $path = 'index.php?act=adminindex'; $res = $this->call($path); return $res; } - function apidoings(){ + function apidoings() + { } - function backup($post){ - $path ='index.php?act=backup'; - $ret = $this->call($path, array(), $post); + function backup($post) + { + $path = 'index.php?act=backup'; + $ret = $this->call($path, [], $post); return $ret; } - function bandwidth(){ - $path ='index.php?act=backup'; + function bandwidth() + { + $path = 'index.php?act=backup'; $ret = $this->call($path); return $ret; } /** * Cleaning the POST variables - * * @author Pulkit Gupta - * @param array $post An array of DATA that should be posted - * @param array $cookies An array FOR SENDING COOKIES + * @param array $cookies An array FOR SENDING COOKIES + * @param array $post An array of DATA that should be posted * @return array The unserialized array on success OR false on failure */ - function clean_post(&$post, $edit = 0){ - $post['serid'] = !isset($post['serid']) ? 0 : (int)$post['serid']; - $post['uid'] = !isset($post['uid']) ? 0 : (int)$post['uid']; - $post['plid'] = !isset($post['plid']) ? 0 : (int)$post['plid']; - $post['osid'] = !isset($post['osid']) ? 0 : (int)$post['osid']; - $post['iso'] = !isset($post['iso']) ? 0 : (int)$post['iso']; - $post['space'] = !isset($post['space']) ? 10 : (int)$post['space']; - $post['ram'] = !isset($post['ram']) ? 512 : (int)$post['ram']; - $post['swapram'] = !isset($post['swapram']) ? 1024 : (int)$post['swapram']; - $post['bandwidth'] = !isset($post['bandwidth']) ? 0 : (int)$post['bandwidth']; - $post['network_speed'] = !isset($post['network_speed']) ? 0 : (int)$post['network_speed']; - $post['cpu'] = !isset($post['cpu']) ? 1000 : (int)$post['cpu']; - $post['cores'] = !isset($post['cores']) ? 4 : (int)$post['cores']; - $post['cpu_percent'] = !isset($post['cpu_percent']) ? 100 : (int)$post['cpu_percent']; - $post['vnc'] = !isset($post['vnc']) ? 1 : (int)$post['vnc']; + function clean_post(&$post, $edit = 0) + { + $post['serid'] = !isset($post['serid']) ? 0 : (int) $post['serid']; + $post['uid'] = !isset($post['uid']) ? 0 : (int) $post['uid']; + $post['plid'] = !isset($post['plid']) ? 0 : (int) $post['plid']; + $post['osid'] = !isset($post['osid']) ? 0 : (int) $post['osid']; + $post['iso'] = !isset($post['iso']) ? 0 : (int) $post['iso']; + $post['space'] = !isset($post['space']) ? 10 : (int) $post['space']; + $post['ram'] = !isset($post['ram']) ? 512 : (int) $post['ram']; + $post['swapram'] = !isset($post['swapram']) ? 1024 : (int) $post['swapram']; + $post['bandwidth'] = !isset($post['bandwidth']) ? 0 : (int) $post['bandwidth']; + $post['network_speed'] = !isset($post['network_speed']) ? 0 : (int) $post['network_speed']; + $post['cpu'] = !isset($post['cpu']) ? 1000 : (int) $post['cpu']; + $post['cores'] = !isset($post['cores']) ? 4 : (int) $post['cores']; + $post['cpu_percent'] = !isset($post['cpu_percent']) ? 100 : (int) $post['cpu_percent']; + $post['vnc'] = !isset($post['vnc']) ? 1 : (int) $post['vnc']; $post['vncpass'] = !isset($post['vncpass']) ? 'test' : $post['vncpass']; $post['sec_iso'] = !isset($post['sec_iso']) ? 0 : $post['sec_iso']; $post['kvm_cache'] = !isset($post['kvm_cache']) ? 0 : $post['kvm_cache']; $post['io_mode'] = !isset($post['io_mode']) ? 0 : $post['io_mode']; $post['vnc_keymap'] = !isset($post['vnc_keymap']) ? 'en-us' : $post['vnc_keymap']; - $post['nic_type'] = !isset($post['nic_type']) ? 'default' : $post['nic_type']; - $post['osreinstall_limit'] = !isset($post['osreinstall_limit']) ? 0 : (int)$post['osreinstall_limit']; + $post['nic_type'] = !isset($post['nic_type']) ? 'default' : $post['nic_type']; + $post['osreinstall_limit'] = !isset($post['osreinstall_limit']) ? 0 : (int) $post['osreinstall_limit']; $post['mgs'] = !isset($post['mgs']) ? 0 : $post['mgs']; $post['tuntap'] = !isset($post['tuntap']) ? 0 : $post['tuntap']; $post['virtio'] = !isset($post['virtio']) ? 0 : $post['virtio']; - if(isset($post['hvm'])){ + if (isset($post['hvm'])) { $post['hvm'] = $post['hvm']; } $post['noemail'] = !isset($post['noemail']) ? 0 : $post['noemail']; $post['boot'] = !isset($post['boot']) ? 'dca' : $post['boot']; $post['band_suspend'] = !isset($post['band_suspend']) ? 0 : $post['band_suspend']; $post['vif_type'] = !isset($post['vif_type']) ? 'netfront' : $post['vif_type']; - if($edit == 0){ - $post['addvps'] = !isset($post['addvps']) ? 1 : (int)$post['addvps']; - }else{ + if ($edit == 0) { + $post['addvps'] = !isset($post['addvps']) ? 1 : (int) $post['addvps']; + } else { $post['editvps'] = !isset($post['editvps']) ? 1 : $post['editvps']; $post['acpi'] = !isset($post['acpi']) ? 1 : $post['acpi']; $post['apic'] = !isset($post['apic']) ? 1 : $post['apic']; $post['pae'] = !isset($post['pae']) ? 1 : $post['pae']; - $post['dns'] = !isset($post['dns']) ? array('4.2.2.1','4.2.2.2') : $post['dns']; - $post['editvps'] = !isset($post['editvps']) ? 1 : (int)$post['editvps']; + $post['dns'] = !isset($post['dns']) ? [ + '4.2.2.1', + '4.2.2.2' + ] : $post['dns']; + $post['editvps'] = !isset($post['editvps']) ? 1 : (int) $post['editvps']; } return $post; } - function cluster(){ + function cluster() + { } - function config($post){ - $path ='index.php?act=config'; - $ret = $this->call($path, array(), $post); + function config($post) + { + $path = 'index.php?act=config'; + $ret = $this->call($path, [], $post); return $ret; } /** * Get CPU usage details - * * @author Pulkit Gupta * @param * @return array The unserialised array is returned on success or - * empty array is returned on failure + * empty array is returned on failure */ - function cpu($serverid = 0){ + function cpu($serverid = 0) + { $path = 'index.php?act=manageserver&changeserid='.$serverid; $ret = $this->call($path); return $ret['usage']['cpu']; } - function createssl($post){ - $path ='index.php?act=createssl'; - $ret = $this->call($path, array(), $post); + function createssl($post) + { + $path = 'index.php?act=createssl'; + $ret = $this->call($path, [], $post); return $ret; } - function createtemplate($post){ - $path ='index.php?act=createtemplate'; - $ret = $this->call($path, array(), $post); + function createtemplate($post) + { + $path = 'index.php?act=createtemplate'; + $ret = $this->call($path, [], $post); return $ret; } - function databackup(){ + function databackup() + { } - function defaultvsconf($post){ - $path ='index.php?act=defaultvsconf'; - $ret = $this->call($path, array(), $post); + function defaultvsconf($post) + { + $path = 'index.php?act=defaultvsconf'; + $ret = $this->call($path, [], $post); return $ret; } /** * Delete a VPS - * * @author Pulkit Gupta - * @param array $post An array of DATA that should be posted + * @param int $vid An array of DATA that should be posted * @return boolean 1 on success OR 0 on failure */ - function delete_vs($vid){ - $path = 'index.php?act=vs&delete='.(int)$vid; + function delete_vs(int $vid) + { + $path = 'index.php?act=vs&delete='.(int) $vid; $res = $this->call($path); return $res['done']; } /** * Get Disk usage details - * * @author Pulkit Gupta - * @param + * @param int $serverid * @return array The unserialised array is returned on success or - * empty array is returned on failure + * empty array is returned on failure */ - function disk($serverid = 0){ + function disk($serverid = 0) + { $path = 'index.php?act=manageserver&changeserid='.$serverid; $ret = $this->call($path); return $ret['usage']['disk']; } - function downloadiso(){ + function downloadiso() + { } - function editemailtemp(){ + function editemailtemp() + { } - function editippool($post){ + function editippool($post) + { $path = 'index.php?act=editippool'; - $res = $this->call($path, array(), $post); + $res = $this->call($path, [], $post); return $res; } - function editips($post){ + function editips($post) + { $path = 'index.php?act=editips'; - $res = $this->call($path, array(), $post); + $res = $this->call($path, [], $post); return $res; } - function editplan($post){ + function editplan($post) + { $path = 'index.php?act=editplan'; - $res = $this->call($path, array(), $post); + $res = $this->call($path, [], $post); return $res; } - function editserver($post){ + function editserver($post) + { $path = 'index.php?act=editserver'; - $res = $this->call($path, array(), $post); + $res = $this->call($path, [], $post); return $res; } - function edittemplate($post){ + function edittemplate($post) + { $path = 'index.php?act=edittemplate'; - $res = $this->call($path, array(), $post); + $res = $this->call($path, [], $post); return $res; } - function edituser($post){ + function edituser($post) + { $path = 'index.php?act=edituser'; - $res = $this->call($path, array(), $post); + $res = $this->call($path, [], $post); return $res; } /** * Create a VPS - * * @author Pulkit Gupta - * @param array $post An array of DATA that should be posted + * @param array $post An array of DATA that should be posted * @return array The unserialized array on success OR false on failure */ - function editvs($post, $cookies = array()){ + function editvs($post, $cookies = []) + { $path = 'index.php?act=editvs&vpsid='.$post['vpsid']; $post = $this->clean_post($post, 1); $ret = $this->call($path, '', $post, $cookies); - return array( - 'title' => $ret['title'], - 'error' => @empty($ret['error']) ? array() : $ret['error'], + return [ + 'title' => $ret['title'], + 'error' => @empty($ret['error']) ? [] : $ret['error'], 'vs_info' => $ret['vps'] - ); + ]; } - function emailconfig($post){ + function emailconfig($post) + { $path = 'index.php?act=emailconfig'; - $res = $this->call($path, array(), $post); + $res = $this->call($path, [], $post); return $res; } - function emailtemp($post){ + function emailtemp($post) + { $path = 'index.php?act=emailtemp'; - $res = $this->call($path, array(), $post); + $res = $this->call($path, [], $post); return $res; } - function filemanager($post){ + function filemanager($post) + { $path = 'index.php?act=filemanager'; - $res = $this->call($path,'', $post); + $res = $this->call($path, '', $post); return $res; } - function firewall($post){ + function firewall($post) + { $path = 'index.php?act=firewall'; - $res = $this->call($path, array(), $post); + $res = $this->call($path, [], $post); return $res; } - function giveos(){ + function giveos() + { } - function health(){ + function health() + { } - function hostname($post){ + function hostname($post) + { $path = 'index.php?act=hostname'; - $res = $this->call($path,'',$post); + $res = $this->call($path, '', $post); return $res; } - function import($post){ + function import($post) + { $path = 'index.php?act=import'; - $res = $this->call($path, array(), $post); + $res = $this->call($path, [], $post); return $res; } - function ippool($page = 1, $reslen = 50){ + function ippool($page = 1, $reslen = 50) + { $path = 'index.php?act=ippool&page='.$page.'&reslen='.$reslen; $res = $this->call($path); return $res; @@ -593,30 +679,38 @@ function ippool($page = 1, $reslen = 50){ /** * Get list of IPs - * * @author Pulkit Gupta * @param - * @return array The unserialised array on success. + * @return Res|Ipsresponse The unserialised array on success. */ - function ips($page = 1, $reslen = 50){ + function ips($page = 1, $reslen = 50) + { $path = 'index.php?act=ips&page='.$page.'&reslen='.$reslen; - $ret = $this->call($path); - return $ret; + $ret = $this->callStorm($path); + if ($ret->isSuccess()) { + return new Ipsresponse($ret); + } else { + return $ret; + } + } - function iso($page = 1, $reslen = 50){ + function iso($page = 1, $reslen = 50) + { $path = 'index.php?act=iso&page='.$page.'&reslen='.$reslen; $ret = $this->call($path); return $ret; } - function kernelconf($post = 0){ + function kernelconf($post = 0) + { $path = 'index.php?act=kernelconf'; - $ret = $this->call($path, array(), $post); + $ret = $this->call($path, [], $post); return $ret; } - function license(){ + function license() + { $path = 'index.php?act=license'; $ret = $this->call($path); return $ret; @@ -624,72 +718,80 @@ function license(){ /** * List VPS - * * @author Pulkit Gupta - * @param int page number, if not specified then only 50 records are returned. - * @return ListVs|false The ListVs class OR false on failure - * + * @param int page number, if not specified then only 50 records are returned. + * @return ListVs|Res The ListVs class OR false on failure */ - function listvs($page = 1, $reslen = 50){ + function listvs($page = 1, $reslen = 50) + { $path = 'index.php?act=vs&page='.$page.'&reslen='.$reslen; - $response= $this->call($path); - if (!empty($response)) { - + $response = $this->callStorm($path); + if ($response->isSuccess()) { return new ListVs($response); - }else{ - return false; + } else { + return $response; } } - function login(){ + function login() + { } - function loginlogs($page = 1, $reslen = 50){ + function loginlogs($page = 1, $reslen = 50) + { $path = 'index.php?act=loginlogs&page='.$page.'&reslen='.$reslen; $ret = $this->call($path); return $ret; } - function logs($page = 1, $reslen = 50){ + function logs($page = 1, $reslen = 50) + { $path = 'index.php?act=logs&page='.$page.'&reslen='.$reslen; $ret = $this->call($path); return $ret; } - function maintenance($post){ + function maintenance($post) + { $path = 'index.php?act=maintenance'; - $ret = $this->call($path, array(), $post); + $ret = $this->call($path, [], $post); return $ret; } - function makeslave(){ + function makeslave() + { } - function os($post){ + function os($post) + { $path = 'index.php?act=os'; - $ret = $this->call($path, array(), $post); + $ret = $this->call($path, [], $post); return $ret; } - function ostemplates($page = 1, $reslen = 50){ + function ostemplates($page = 1, $reslen = 50) + { $path = 'index.php?act=ostemplates&page='.$page.'&reslen='.$reslen; $ret = $this->call($path); return $ret; } - function performance(){ + function performance() + { $path = 'index.php?act=performance'; $ret = $this->call($path); return $ret; } - function phpmyadmin(){ + function phpmyadmin() + { } - function plans($page = 1, $reslen = 50){ + function plans($page = 1, $reslen = 50) + { $path = 'index.php?act=plans&page='.$page.'&reslen='.$reslen; $ret = $this->call($path); return $ret; @@ -697,18 +799,19 @@ function plans($page = 1, $reslen = 50){ /** * POWER OFF a Virtual Server - * * @author Pulkit Gupta - * @param int $vid The VMs ID + * @param int $vid The VMs ID * @return bool TRUE on success or FALSE on failure */ - function poweroff($vid){ + function poweroff($vid) + { // Make the Request - $res = $this->call('index.php?act=vs&action=poweroff&serid=0&vpsid='.(int)$vid); + $res = $this->call('index.php?act=vs&action=poweroff&serid=0&vpsid='.(int) $vid); return $res; } - function processes(){ + function processes() + { $path = 'index.php?act=processes'; $ret = $this->call($path); return $ret; @@ -716,13 +819,13 @@ function processes(){ /** * Get RAM details - * * @author Pulkit Gupta * @param * @return array The unserialised array is returned on success or - * empty array is returned on failure + * empty array is returned on failure */ - function ram($serverid = 0){ + function ram($serverid = 0) + { $path = 'index.php?act=manageserver&changeserid='.$serverid; $ret = $this->call($path); return $ret['usage']['ram']; @@ -730,78 +833,88 @@ function ram($serverid = 0){ /** * Rebuild a VPS - * * @author Pulkit Gupta - * @param array $post An array of DATA that should be posted + * @param array $post An array of DATA that should be posted * @return array The unserialized array on success OR false on failure */ - function rebuild($post){ + function rebuild($post) + { $path = 'index.php?act=rebuild'; return $this->call($path, '', $post); } /** * RESTART a Virtual Server - * * @author Pulkit Gupta - * @param int $vid The VMs ID + * @param int $vid The VMs ID * @return bool TRUE on success or FALSE on failure */ - function restart($vid){ + function restart($vid) + { // Make the Request - $res = $this->call('index.php?act=vs&action=restart&serid=0&vpsid='.(int)$vid); + $res = $this->call('index.php?act=vs&action=restart&serid=0&vpsid='.(int) $vid); return $res; } - function restartservices($post){ + function restartservices($post) + { $path = 'index.php?act=restartservices'; - $res = $this->call($path, array(), $post); + $res = $this->call($path, [], $post); return $res; } /** * Current server information - * * @author Pulkit Gupta * @param * @return array The unserialized array on success OR false on failure */ - function serverinfo(){ + function serverinfo() + { $path = 'index.php?act=serverinfo'; return $this->call($path); } /** * List Servers - * * @author Pulkit Gupta * @param - * @return array The unserialized array on success OR false on failure + * @return Res|Server_list The unserialized array on success OR false on failure */ - function servers(){ + function servers() + { $path = 'index.php?act=servers'; - return $this->call($path); + $ret = $this->callStorm($path); + if ($ret->isSuccess()) { + return new Server_list($ret); + } else { + return $ret; + } } - function services($post = 0){ + function services($post = 0) + { $path = 'index.php?act=services'; $res = $this->call($path, '', $post); return $res; } - function ssh(){ + function ssh() + { /* $path = 'index.php?act=ssh'; $res = $this->call($path); return $res;*/ } - function ssl($post = 0){ + function ssl($post = 0) + { /* $path = 'index.php?act=ssl'; $res = $this->call($path, '', $post); return $res;*/ } - function sslcert(){ + function sslcert() + { /* $path = 'index.php?act=sslcert'; $res = $this->call($path); return $res;*/ @@ -809,38 +922,38 @@ function sslcert(){ /** * START a Virtual Server - * * @author Pulkit Gupta - * @param int $vid The VMs ID + * @param int $vid The VMs ID * @return bool TRUE on success or FALSE on failure */ - function start($vid){ + function start($vid) + { - $res = $this->call('index.php?act=vs&action=start&serid=0&vpsid='.(int)$vid); + $res = $this->call('index.php?act=vs&action=start&serid=0&vpsid='.(int) $vid); return $res; } /** * STOP a Virtual Server - * * @author Pulkit Gupta - * @param int $vid The VMs ID + * @param int $vid The VMs ID * @return bool TRUE on success or FALSE on failure */ - function stop($vid){ + function stop($vid) + { // Make the Request - $res = $this->call('index.php?act=vs&action=stop&serid=0&vpsid='.(int)$vid); + $res = $this->call('index.php?act=vs&action=stop&serid=0&vpsid='.(int) $vid); return $res; } /** * Gives status of a Virtual Server - * * @author Pulkit Gupta - * @param Array $vids array of IDs of VMs + * @param Array $vids array of IDs of VMs * @return Array Contains the status info of the VMs */ - function status($vids){ + function status($vids) + { // Make the Request $res = $this->call('index.php?act=vs&vs_status='.implode(',', $vids)); @@ -850,95 +963,107 @@ function status($vids){ /** * Suspends a VM of a Virtual Server - * * @author Pulkit Gupta - * @param int $vid The VMs ID + * @param int $vid The VMs ID * @return int 1 if the VM is ON, 0 if its OFF */ - function suspend($vid){ - $path = 'index.php?act=vs&suspend='.(int)$vid; + function suspend($vid) + { + $path = 'index.php?act=vs&suspend='.(int) $vid; $res = $this->call($path); return $res; } /** * Unsuspends a VM of a Virtual Server - * * @author Pulkit Gupta - * @param int $vid The VMs ID + * @param int $vid The VMs ID * @return int 1 if the VM is ON, 0 if its OFF */ - function unsuspend($vid){ - $path = 'index.php?act=vs&unsuspend='.(int)$vid; + function unsuspend($vid) + { + $path = 'index.php?act=vs&unsuspend='.(int) $vid; $res = $this->call($path); return $res; } - function tools(){ + function tools() + { } - function ubc($post){ + function ubc($post) + { $path = 'index.php?act=ubc'; - $res = $this->call($path, array(), $post); + $res = $this->call($path, [], $post); return $res; } - function updates(){ + function updates() + { $path = 'index.php?act=updates'; $res = $this->call($path); return $res; } - function userlogs($page = 1, $reslen = 50){ + function userlogs($page = 1, $reslen = 50) + { $path = 'index.php?act=userlogs&page='.$page.'&reslen='.$reslen; $res = $this->call($path); return $res; } - function users($page = 1, $reslen = 50){ + function users($page = 1, $reslen = 50) + { $path = 'index.php?act=users&page='.$page.'&reslen='.$reslen; $res = $this->call($path); return $res; } - function vnc($post){ + function vnc($post) + { $path = 'index.php?act=vnc'; - $res = $this->call($path, array(), $post); + $res = $this->call($path, [], $post); return $res; } - function vpsbackupsettings($post){ + function vpsbackupsettings($post) + { $path = 'index.php?act=vpsbackupsettings'; - $res = $this->call($path, array(), $post); + $res = $this->call($path, [], $post); return $res; } - function vpsbackups($post){ + function vpsbackups($post) + { $path = 'index.php?act=vpsbackups'; $res = $this->call($path, '', $post); return $res; } - function vs($page = 1, $reslen = 50){ + function vs($page = 1, $reslen = 50) + { $path = 'index.php?act=vs&page='.$page.'&reslen='.$reslen; $res = $this->call($path); return $res; } - function vsbandwidth(){ + function vsbandwidth() + { $path = 'index.php?act=vsbandwidth'; $res = $this->call($path); return $res; } - function vscpu(){ + function vscpu() + { $path = 'index.php?act=vscpu'; $res = $this->call($path); return $res; } - function vsram(){ + function vsram() + { $path = 'index.php?act=vsram'; $res = $this->call($path); return $res; From f4595a39a6309e997624ca61d61a539cd4dbe5ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=BA=D9=84=D8=A7=D9=85=D8=B1=D8=B6=D8=A7=20=D8=A8=D9=87?= =?UTF-8?q?=D8=B4=D8=AA=DB=8C=D8=A7=D9=86?= Date: Sat, 27 Nov 2021 15:15:32 +0330 Subject: [PATCH 03/18] improve project --- index.php | 94 +++++++++++++++++++---- src/PostData/CreateVS.php | 98 ++++++++++++------------ src/PostData/EditUser.php | 109 +++++++++++++++++++++++++++ src/Responses/Admin/DoneResponse.php | 16 ++++ src/Responses/Admin/FullUser.php | 106 ++++++++++++++++++++++++++ src/Responses/Admin/Plan.php | 52 ++++++------- src/Responses/Admin/Plans.php | 16 ++++ src/Responses/Admin/Preference.php | 18 +++++ src/Responses/Admin/UserEdit.php | 21 ++++++ src/VirtualizorAdmin.php | 87 +++++++++++++++++---- 10 files changed, 512 insertions(+), 105 deletions(-) create mode 100644 src/PostData/EditUser.php create mode 100644 src/Responses/Admin/DoneResponse.php create mode 100644 src/Responses/Admin/FullUser.php create mode 100644 src/Responses/Admin/Plans.php create mode 100644 src/Responses/Admin/Preference.php create mode 100644 src/Responses/Admin/UserEdit.php diff --git a/index.php b/index.php index d78a7e7..57ed536 100644 --- a/index.php +++ b/index.php @@ -4,30 +4,94 @@ */ use YiiMan\VirtualizorSdk\PostData\CreateVS; -use YiiMan\VirtualizorSdk\Responses\Admin\VS; +use YiiMan\VirtualizorSdk\PostData\EditUser; use YiiMan\VirtualizorSdk\VirtualizorAdmin; include 'vendor/autoload.php'; $visualizor = new VirtualizorAdmin(); echo '
';
-$sv = new CreateVS();
-$sv->cores = 1;
 
-$sv->rootpass0='yiiman';
-$sv->virt=$sv::VIRTUALIZOR_TYPE_kvm;
-$sv->user_email0='info@yiiman.ir';
-$sv->user_pass='YiiMan@@@22';
-$sv->hostname0='yiiman';
-$sv->osid0=870;
-$sv->plid0=1;
+
+
+
+
+//create
+//$servers = $visualizor->servers();
+//$sv = new CreateVS();
+//$sv->cores0 = 1;
+//
+//$sv->rootpass0 = 'yiiman';
+//$sv->virt0 = $sv::VIRTUALIZOR_TYPE_kvm;
+//$sv->user_email0 = 'amintado@gmail.com';
+//$sv->user_pass0 = 'YiiMan@@@22';
+//$sv->hostname0 = 'yiiman';
+//$sv->osid0 = 870;
+//
+//$sv->bandwidth0 = 500;
+//$sv->space0 = 15;
+//$sv->ram0 = 512;
 
 
 //$res=$visualizor->listvs();
-$res=$visualizor->ips();
-$sv->ips[]=$res->ips[0]->gateway;
-$servers=$visualizor->servers();
-$sv->node_select0=$servers->servers[0]->serid;
-$created=$visualizor->addvs($sv, []);
+//$ips = $visualizor->ips();
+//$sv->ips0[] = $ips->ips[0]->gateway;
+
+//$plans = $visualizor->plans();
+//$sv->plid0 = (int)$plans->plans[0]->plid;
+//
+//$sv->node_select0 = $servers->servers[0]->serid;
+//$created = $visualizor->addvs($sv, []);
+
+
+//server list
+//$vsList=$visualizor->vs();
+
+
+//suspend
+//$suspend=$visualizor->userSuspend(2);
+
+//unsuspend
+//$unsuspend=$visualizor->userUnsuspend(2);
+
+//edit
+$editPost=new EditUser();
+$editPost->fname="amin".uniqid();
+$edit=$visualizor->edituser($editPost,2);
+
+//terminate
+
+
+//stop
+
+
+//restart
+
+
+//reinstall
+
+
+//start
+
+
+
+//checkStatus
+
+
+
+//checkUsage
+
+
+//hasSpace
+
+
+
+//reset_password
+
+
+//get_service_details
+
+
+
 
 echo 'finish';
diff --git a/src/PostData/CreateVS.php b/src/PostData/CreateVS.php
index a7422df..07a258b 100644
--- a/src/PostData/CreateVS.php
+++ b/src/PostData/CreateVS.php
@@ -10,38 +10,38 @@
 /**
  * Class CreateVS
  * @package YiiMan\VirtualizorSdk\PostData
- * @property  integer $node_select0      server id that you want creta new vps on that
- * @property  string  $user_email0       Add User Email
- * @property  integer $plid0             The plan ID for the VPS
- * @property  integer $osid0             The ID of the Operating System
- * @property  string  $hostname0         The hostname the VPS
- * @property  string  $rootpass0         The root password for the VPS
+ * @property  integer $node_select0       server id that you want creta new vps on that
+ * @property  string  $user_email0        Add User Email
+ * @property  integer $cores0             The number of cores allotted to the VPS
+ * @property  integer $plid0              The plan ID for the VPS
+ * @property  integer $osid0              The ID of the Operating System
+ * @property  string  $hostname0          The hostname the VPS
+ * @property  string  $rootpass0          The root password for the VPS
+ * @property  string  $virt0              The Virtualization Technology has to be specified here, refer below table for valid values
+ * @property  string  $user_pass0         Add a password
+ * @property  array   $ips0               The IP Address(s) for the VPS
+ * @property  array   $space0             The disk space for the VPS. In case of Multiple Disk you can specify the array as given in the example. Otherwise just value for single disk VPS is enough
+ * @property  integer $ram0               The ram value in MBs for the VPS
+ * @property  integer $bandwidth0         The network bandwidth for the VPS: 0 (Zero) for unlimited
  * @property          $serid
- * @property  integer $slave_server      The slave server ID on which vps is to be created
- * @property  string  $virt              The Virtualization Technology has to be specified here, refer below table for valid values
- * @property  integer $uid               Selects a unique ID of the user to which the vps will be assigned
- * @property  string  $user_pass         Add a password
- * @property  string  $fname             Add user first name
- * @property  string  $lname             Add user last name
- * @property  array   $ips               The IP Address(s) for the VPS
- * @property  integer $num_ips6          The Number of Ipv6 Address given to the vps
- * @property  integer $num_ips6_subnet   The Number of IPV6 Subnet to be assigned to the vps
- * @property  integer $stid              Storage ID on which the VPS is to be created. (Not needed if using Primary storage)
- * @property  array   $space             The disk space for the VPS. In case of Multiple Disk you can specify the array as given in the example. Otherwise just value for single disk VPS is enough
- * @property  integer $ram               The ram value in MBs for the VPS
- * @property  integer $swapram           The amount of SWAP for the VPS (Only for KVM, Xen, Proxmox KVM and XCP)
- * @property  integer $bandwidth         The network bandwidth for the VPS: 0 (Zero) for unlimited
- * @property  integer $network_speed     The network_speed for the VPS in KB/s
- * @property  integer $cpu               The CPU weight for the VPS
- * @property  integer $cores             The number of cores allotted to the VPS
- * @property  integer $cpu_percent       The CPU Percent time for the VPS (Only for OpenVZ and Proxmox)
- * @property  bool    $vnc               Flag to enable vnc(0 or 1) (Only for KVM and Xen)
- * @property  string  $vncpass           The vnc password (Only for KVM and Xen)
- * @property  string  $kvm_cache         The type disk-cache mechanism can be writeback, writethrough, directsync or default (Only for KVM and Proxmox KVM)
- * @property  string  $io_mode           Sets the I/O policy for the VPS can be native/threads (Only for KVM)
- * @property  string  $vnc_keymap        Allows to select keymap can be 'en-us', 'de-ch', 'ar', 'da', 'et', 'fo', 'fr-be', 'fr-ch', 'hu', 'it', 'lt', 'mk', 'nl', 'no', 'pt', 'ru', 'sv', 'tr', 'de', 'en-gb', 'es', 'fi', 'fr', 'fr-ca', 'hr', 'is', 'ja', 'lv', 'nl-be', 'pl', 'pt-br', 'sl', 'th'
- * @property  string  $nic_type          The NIC type (default or e1000) (Only for KVM and Xen)
- * @property  integer $osreinstall_limit If you want to limit the number of OS re-installs per month.Eg. 0 - is unlimited
+ * @property  integer $slave_server       The slave server ID on which vps is to be created
+ * @property  integer $uid                Selects a unique ID of the user to which the vps will be assigned
+ * @property  string  $fname              Add user first name
+ * @property  string  $lname              Add user last name
+ * @property  integer $num_ips6           The Number of Ipv6 Address given to the vps
+ * @property  integer $num_ips6_subnet    The Number of IPV6 Subnet to be assigned to the vps
+ * @property  integer $stid               Storage ID on which the VPS is to be created. (Not needed if using Primary storage)
+ * @property  integer $swapram            The amount of SWAP for the VPS (Only for KVM, Xen, Proxmox KVM and XCP)
+ * @property  integer $network_speed      The network_speed for the VPS in KB/s
+ * @property  integer $cpu                The CPU weight for the VPS
+ * @property  integer $cpu_percent        The CPU Percent time for the VPS (Only for OpenVZ and Proxmox)
+ * @property  bool    $vnc                Flag to enable vnc(0 or 1) (Only for KVM and Xen)
+ * @property  string  $vncpass            The vnc password (Only for KVM and Xen)
+ * @property  string  $kvm_cache          The type disk-cache mechanism can be writeback, writethrough, directsync or default (Only for KVM and Proxmox KVM)
+ * @property  string  $io_mode            Sets the I/O policy for the VPS can be native/threads (Only for KVM)
+ * @property  string  $vnc_keymap         Allows to select keymap can be 'en-us', 'de-ch', 'ar', 'da', 'et', 'fo', 'fr-be', 'fr-ch', 'hu', 'it', 'lt', 'mk', 'nl', 'no', 'pt', 'ru', 'sv', 'tr', 'de', 'en-gb', 'es', 'fi', 'fr', 'fr-ca', 'hr', 'is', 'ja', 'lv', 'nl-be', 'pl', 'pt-br', 'sl', 'th'
+ * @property  string  $nic_type           The NIC type (default or e1000) (Only for KVM and Xen)
+ * @property  integer $osreinstall_limit  If you want to limit the number of OS re-installs per month.Eg. 0 - is unlimited
  */
 class CreateVS extends BasePostData
 {
@@ -89,34 +89,34 @@ class CreateVS extends BasePostData
 
     public int $serid = 0;
     public int $slave_server;
-    public string $virt;
-    public int $uid = 0;
+    public string $virt0;
+    public int $uid;
     public string $user_email0;
-    public string $user_pass;
+    public string $user_pass0;
     public string $fname;
     public string $lname;
     public int $plid0;
     public int $osid0;
     public string $hostname0;
     public string $rootpass0;
-    public array $ips = [];
+    public array $ips0 = [];
     public int $num_ips6;
     public int $num_ips6_subnet;
     public int $stid;
-    public int $space = 10;
-    public int $ram = 512;
-    public int $swapram = 1024;
-    public int $bandwidth = 0;
-    public int $network_speed = 0;
-    public int $cpu = 1000;
-    public int $cores = 4;
-    public int $cpu_percent = 100;
-    public int $vnc = 1;
-    public string $vncpass = 'test';
-    public string $kvm_cache = 'writeback';
-    public string $io_mode = 'native';
-    public string $vnc_keymap = 'en-us';
-    public string $nic_type = 'default';
+    public int $space0;//GIG
+    public int $ram0;
+    public int $swapram;
+    public int $bandwidth0;
+    public int $network_speed;
+    public int $cpu;
+    public int $cores0;
+    public int $cpu_percent;
+    public int $vnc;
+    public string $vncpass;
+    public string $kvm_cache;
+    public string $io_mode;
+    public string $vnc_keymap;
+    public string $nic_type;
     public int $osreinstall_limit = 0;
     public $node_select0;
     public $addvps = 1;
diff --git a/src/PostData/EditUser.php b/src/PostData/EditUser.php
new file mode 100644
index 0000000..df9a53d
--- /dev/null
+++ b/src/PostData/EditUser.php
@@ -0,0 +1,109 @@
+ 'int',
+                'priority'        => 'int',
+                'newpass'         => 'string',
+                'newemail'        => 'string',
+                'fname'           => 'string',
+                'lname'           => 'string',
+                'dnsplan_id'      => 'int',
+                'acl_id'          => 'int',
+                'num_vs'          => 'int',
+                'num_users'       => 'int',
+                'space'           => 'int',
+                'ram'             => 'int',
+                'burst'           => 'int',
+                'bandwidth'       => 'int',
+                'cpu'             => 'int',
+                'cores'           => 'int',
+                'cpu_percent'     => 'int',
+                'num_cores'       => 'int',
+                'num_ipv4'        => 'int',
+                'num_ipv6_subnet' => 'int',
+                'num_ipv6'        => 'int',
+                'network_speed'   => 'int',
+                'upload_speed'    => 'int',
+                'band_suspend'    => 'boolean',
+                'service_period'  => 'int',
+                'allowed_virts'   => 'array',
+                'sgs'             => 'array',
+                'mgs'             => 'array',
+            ];
+    }
+}
\ No newline at end of file
diff --git a/src/Responses/Admin/DoneResponse.php b/src/Responses/Admin/DoneResponse.php
new file mode 100644
index 0000000..561caac
--- /dev/null
+++ b/src/Responses/Admin/DoneResponse.php
@@ -0,0 +1,16 @@
+serve();
         } else {
-            $arrayData = [];
+            if (empty($servedData)) {
+                $arrayData = [];
+            } else {
+                $arrayData = $servedData;
+            }
         }
 
         return $connection->call($path, [], $arrayData, $cookies);
@@ -593,10 +601,17 @@ function edittemplate($post)
         return $res;
     }
 
-    function edituser($post)
+    /**
+     * @param  UserEdit  $post
+     * @return Res
+     */
+    function edituser(EditUser $post, $uid)
     {
-        $path = 'index.php?act=edituser';
-        $res = $this->call($path, [], $post);
+        $path = 'index.php?act=edituser&uid='.$uid;
+        $res = $this->callStorm($path, [], $post);
+        if ($res->isSuccess()) {
+            return new UserEdit($res);
+        }
         return $res;
     }
 
@@ -790,10 +805,20 @@ function phpmyadmin()
 
     }
 
+    /**
+     * @param  int  $page
+     * @param  int  $reslen
+     * @return Res|Plans
+     */
     function plans($page = 1, $reslen = 50)
     {
         $path = 'index.php?act=plans&page='.$page.'&reslen='.$reslen;
-        $ret = $this->call($path);
+        $ret = $this->callStorm($path);
+        if ($ret->isSuccess()) {
+            return new Plans($ret);
+        } else {
+            return $ret;
+        }
         return $ret;
     }
 
@@ -965,13 +990,17 @@ function status($vids)
      * Suspends a VM of a Virtual Server
      * @author       Pulkit Gupta
      * @param  int  $vid  The VMs ID
-     * @return       int 1 if the VM is ON, 0 if its OFF
+     * @return       Res 1 if the VM is ON, 0 if its OFF
      */
     function suspend($vid)
     {
         $path = 'index.php?act=vs&suspend='.(int) $vid;
-        $res = $this->call($path);
-        return $res;
+        $res = $this->callStorm($path);
+        if ($res->isSuccess()) {
+            $test = $res;
+        } else {
+            return $res;
+        }
     }
 
     /**
@@ -1013,6 +1042,34 @@ function userlogs($page = 1, $reslen = 50)
         return $res;
     }
 
+    function userSuspend($uid)
+    {
+        $path = 'index.php?act=users&page=1&reslen=3';
+        $res = $this->callStorm($path, "", ['suspend' => $uid]);
+        if ($res->isSuccess()) {
+            return new DoneResponse($res);
+        }
+        return $res;
+    }
+
+    function userUnsuspend($uid)
+    {
+        $path = 'index.php?act=users&page=1&reslen=3';
+        $res = $this->callStorm($path, "", ['unsuspend' => $uid]);
+        $data = $res->getData();
+        if (!is_object($data)) {
+            $data = str_replace('Success !a:', 'a:', $data);
+            $data = unserialize($data);
+            $res->setData($data);
+        }
+
+        if ($res->isSuccess()) {
+            return new DoneResponse($res);
+        }
+        return $res;
+    }
+
+
     function users($page = 1, $reslen = 50)
     {
         $path = 'index.php?act=users&page='.$page.'&reslen='.$reslen;

From 686c87d7c568285c376117f8481ed91a1681f2b8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D8=BA=D9=84=D8=A7=D9=85=D8=B1=D8=B6=D8=A7=20=D8=A8=D9=87?=
 =?UTF-8?q?=D8=B4=D8=AA=DB=8C=D8=A7=D9=86?= 
Date: Sun, 28 Nov 2021 14:21:56 +0330
Subject: [PATCH 04/18] improve project

---
 index.php                                     | 112 +++++++-------
 src/PostData/CreateVS.php                     |  29 ++--
 src/PostData/EditUser.php                     |   8 +-
 src/PostData/ManageVPS.php                    | 141 ++++++++++++++++++
 src/PostData/Rebuild.php                      |  43 ++++++
 src/Responses/Admin/RebuildResponse.php       |  22 +++
 src/Responses/Admin/Status.php                |  44 ++++++
 src/Responses/Admin/StatusResponse.php        |  31 ++++
 src/Responses/Admin/UsersList.php             |  18 +++
 src/Responses/Admin/VPSStats/PieData.php      |  30 ++++
 src/Responses/Admin/VPSStats/Response.php     |  24 +++
 src/Responses/Admin/VPSStats/VpsData.php      |  56 +++++++
 .../Admin/VPSStats/pieClasses/IO.php          |  32 ++++
 .../VPSStats/pieClasses/ServerBandwidth.php   |  36 +++++
 .../Admin/VPSStats/pieClasses/ServerCpu.php   |  28 ++++
 .../Admin/VPSStats/pieClasses/ServerRam.php   |  18 +++
 src/VirtualizorAdmin.php                      |  91 ++++++++---
 17 files changed, 666 insertions(+), 97 deletions(-)
 create mode 100644 src/PostData/ManageVPS.php
 create mode 100644 src/PostData/Rebuild.php
 create mode 100644 src/Responses/Admin/RebuildResponse.php
 create mode 100644 src/Responses/Admin/Status.php
 create mode 100644 src/Responses/Admin/StatusResponse.php
 create mode 100644 src/Responses/Admin/UsersList.php
 create mode 100644 src/Responses/Admin/VPSStats/PieData.php
 create mode 100644 src/Responses/Admin/VPSStats/Response.php
 create mode 100644 src/Responses/Admin/VPSStats/VpsData.php
 create mode 100644 src/Responses/Admin/VPSStats/pieClasses/IO.php
 create mode 100644 src/Responses/Admin/VPSStats/pieClasses/ServerBandwidth.php
 create mode 100644 src/Responses/Admin/VPSStats/pieClasses/ServerCpu.php
 create mode 100644 src/Responses/Admin/VPSStats/pieClasses/ServerRam.php

diff --git a/index.php b/index.php
index 57ed536..7e668aa 100644
--- a/index.php
+++ b/index.php
@@ -5,93 +5,89 @@
 
 use YiiMan\VirtualizorSdk\PostData\CreateVS;
 use YiiMan\VirtualizorSdk\PostData\EditUser;
+use YiiMan\VirtualizorSdk\PostData\ManageVPS;
+use YiiMan\VirtualizorSdk\PostData\Rebuild;
 use YiiMan\VirtualizorSdk\VirtualizorAdmin;
 
 include 'vendor/autoload.php';
 
 $visualizor = new VirtualizorAdmin();
 echo '
';
-
-
-
-
-
+$u = $visualizor->users()->users[0];
+$userID = $u->uid;
+$userEmail = $u->email;
 //create
-//$servers = $visualizor->servers();
-//$sv = new CreateVS();
-//$sv->cores0 = 1;
-//
-//$sv->rootpass0 = 'yiiman';
-//$sv->virt0 = $sv::VIRTUALIZOR_TYPE_kvm;
-//$sv->user_email0 = 'amintado@gmail.com';
-//$sv->user_pass0 = 'YiiMan@@@22';
-//$sv->hostname0 = 'yiiman';
-//$sv->osid0 = 870;
-//
-//$sv->bandwidth0 = 500;
-//$sv->space0 = 15;
-//$sv->ram0 = 512;
-
-
-//$res=$visualizor->listvs();
-//$ips = $visualizor->ips();
-//$sv->ips0[] = $ips->ips[0]->gateway;
-
-//$plans = $visualizor->plans();
-//$sv->plid0 = (int)$plans->plans[0]->plid;
-//
-//$sv->node_select0 = $servers->servers[0]->serid;
-//$created = $visualizor->addvs($sv, []);
-
-
-//server list
-//$vsList=$visualizor->vs();
-
-
-//suspend
-//$suspend=$visualizor->userSuspend(2);
-
-//unsuspend
-//$unsuspend=$visualizor->userUnsuspend(2);
-
+$servers = $visualizor->servers();//classified
+
+$sv = new CreateVS();
+$sv->virt0 = $sv::VIRTUALIZOR_TYPE_kvm;
+$sv->user_email0 = $userEmail;
+$sv->rootpass0 = 'YiiMan@@@22';
+$sv->hostname0 = 'yiiman';
+$sv->osid0 = 870;
+$plans = $visualizor->plans();//classified
+$sv->plid0 = (int) $plans->plans[0]->plid;
+$sv->node_select0 = $servers->servers[0]->serid;
+$created = $visualizor->addvs($sv, []);//classified
+
+$vpsList = $visualizor->vps_list();//classified
+$vpsID = $vpsList->vs[0]->vpsid;
 //edit
-$editPost=new EditUser();
-$editPost->fname="amin".uniqid();
-$edit=$visualizor->edituser($editPost,2);
-
-//terminate
-
-
-//stop
+$editPost = new EditUser();
+$editPost->fname = "YiiMan".uniqid();
+$editPost->newemail0 = 'test@gmail.com';
 
+$edit = $visualizor->edituser($editPost, $userID);//classified
 
-//restart
+if (!empty($servers)) {
+    //suspend
+    $suspend = $visualizor->userSuspend($userID);//classified
 
+    //unsuspend
+    $unsuspend = $visualizor->userUnsuspend($userID);//classified
 
-//reinstall
+    //stop
+    $stopped = $visualizor->stop($vpsID);
 
+    //start
+    $start = $visualizor->start($vpsID);
 
-//start
+    //restart
 
+    $sid = $servers->servers[0]->serid;
+    $restart = $visualizor->restart($vpsID);
 
 
-//checkStatus
+    //reinstall|rebuild
+    $sid = $servers->servers[0]->serid;
 
+    $rebuild = new Rebuild();
+    $rebuild->osid = 870;
+    $rebuild = $visualizor->rebuild($rebuild, $vpsID);//classified
 
 
-//checkUsage
+    //checkStatus
+    $checkStatus = $visualizor->status([$vpsID]);//classified
 
+    //checkUsage
+    $checkUsage = $visualizor->stat($vpsID);
 
-//hasSpace
+    //hasSpace
 
 
+    //reset_password
+    $manage = new ManageVPS();
+    $manage->rootpass = 'amidikukuhkuh';
+    $resetPassword = $visualizor->managevps($manage, $vpsID);
 
-//reset_password
+    //get_service_details
 
 
-//get_service_details
+    //terminate
+    $deleted = $visualizor->delete_vs($vpsID);
 
 
+}
 
 
 echo 'finish';
diff --git a/src/PostData/CreateVS.php b/src/PostData/CreateVS.php
index 07a258b..34d081a 100644
--- a/src/PostData/CreateVS.php
+++ b/src/PostData/CreateVS.php
@@ -12,17 +12,17 @@
  * @package YiiMan\VirtualizorSdk\PostData
  * @property  integer $node_select0       server id that you want creta new vps on that
  * @property  string  $user_email0        Add User Email
- * @property  integer $cores0             The number of cores allotted to the VPS
+ * @property  integer $cores              The number of cores allotted to the VPS
  * @property  integer $plid0              The plan ID for the VPS
  * @property  integer $osid0              The ID of the Operating System
  * @property  string  $hostname0          The hostname the VPS
  * @property  string  $rootpass0          The root password for the VPS
  * @property  string  $virt0              The Virtualization Technology has to be specified here, refer below table for valid values
- * @property  string  $user_pass0         Add a password
- * @property  array   $ips0               The IP Address(s) for the VPS
- * @property  array   $space0             The disk space for the VPS. In case of Multiple Disk you can specify the array as given in the example. Otherwise just value for single disk VPS is enough
- * @property  integer $ram0               The ram value in MBs for the VPS
- * @property  integer $bandwidth0         The network bandwidth for the VPS: 0 (Zero) for unlimited
+ * @property  string  $user_pass          Add a password
+ * @property  array   $ips                The IP Address(s) for the VPS
+ * @property  array   $space              The disk space for the VPS. In case of Multiple Disk you can specify the array as given in the example. Otherwise just value for single disk VPS is enough
+ * @property  integer $ram                The ram value in MBs for the VPS
+ * @property  integer $bandwidth          The network bandwidth for the VPS: 0 (Zero) for unlimited
  * @property          $serid
  * @property  integer $slave_server       The slave server ID on which vps is to be created
  * @property  integer $uid                Selects a unique ID of the user to which the vps will be assigned
@@ -92,24 +92,24 @@ class CreateVS extends BasePostData
     public string $virt0;
     public int $uid;
     public string $user_email0;
-    public string $user_pass0;
+    public string $user_pass;
     public string $fname;
     public string $lname;
     public int $plid0;
     public int $osid0;
     public string $hostname0;
     public string $rootpass0;
-    public array $ips0 = [];
+    public array $ips;
     public int $num_ips6;
     public int $num_ips6_subnet;
     public int $stid;
-    public int $space0;//GIG
-    public int $ram0;
+    public int $space;//GIG
+    public int $ram;
     public int $swapram;
-    public int $bandwidth0;
+    public int $bandwidth;
     public int $network_speed;
     public int $cpu;
-    public int $cores0;
+    public int $cores;
     public int $cpu_percent;
     public int $vnc;
     public string $vncpass;
@@ -117,7 +117,7 @@ class CreateVS extends BasePostData
     public string $io_mode;
     public string $vnc_keymap;
     public string $nic_type;
-    public int $osreinstall_limit = 0;
+    public int $osreinstall_limit;
     public $node_select0;
     public $addvps = 1;
 
@@ -156,7 +156,8 @@ public function rules(): array
                 'vnc_keymap'        => 'string',
                 'nic_type'          => 'string',
                 'osreinstall_limit' => 'integer',
-                'node_select'       => 'integer'
+                'node_select'       => 'integer',
+                'addvps'            => 'integer'
             ];
     }
 
diff --git a/src/PostData/EditUser.php b/src/PostData/EditUser.php
index df9a53d..d3d5470 100644
--- a/src/PostData/EditUser.php
+++ b/src/PostData/EditUser.php
@@ -8,9 +8,9 @@
 /**
  * Class EditUser
  * @package YiiMan\VirtualizorSdk\PostData
- * @property integer $priority        This specifies if the user is a user(0) or admin(1) or cloud (2)
+ * @property integer $priority0        This specifies if the user is a user(0) or admin(1) or cloud (2)
  * @property string  $newpass         The password of the user
- * @property string  $newemail        The email of the user
+ * @property string  $newemail0        The email of the user
  * @property string  $fname           The first name of the user
  * @property string  $lname           The last name of the user
  * @property integer $dnsplan_id      The dnsplan ID for the user
@@ -41,9 +41,9 @@ class EditUser extends \YiiMan\ApiStorm\Post\BasePostData
     public $edituser=1;
     public
 
-        $priority,
+        $priority0=0,
         $newpass="",
-        $newemail,
+        $newemail0,
         $fname,
         $lname,
         $dnsplan_id,
diff --git a/src/PostData/ManageVPS.php b/src/PostData/ManageVPS.php
new file mode 100644
index 0000000..9856fc1
--- /dev/null
+++ b/src/PostData/ManageVPS.php
@@ -0,0 +1,141 @@
+ 'int',
+                'rootpass'          => 'string',
+                'ips'               => 'array',
+                'hostname'          => 'string',
+                'ram'               => 'int',
+                'bandwidth'         => 'int',
+                'cores'             => 'int',
+                'cpupin'            => 'int',
+                'uid'               => 'int',
+                'network_speed'     => 'int',
+                'upload_speed'      => 'int',
+                'hvm'               => 'int',
+                'io'                => 'int',
+                'burst'             => 'int',
+                'cpu_percent'       => 'int',
+                'acpi'              => 'int',
+                'apic'              => 'int',
+                'pae'               => 'int',
+                'vnc'               => 'int',
+                'shadow'            => 'int',
+                'iso'               => 'string',
+                'boot'              => 'string',
+                'band_suspend'      => 'int',
+                'tuntap'            => 'int',
+                'pv_on_hvm'         => 'int',
+                'ppp'               => 'int',
+                'mac_status'        => 'int',
+                'osreinstall_limit' => 'int',
+                'mgs'               => 'string',
+                'webuzo'            => 'string',
+                'cpu_mode'          => 'string',
+                'admin_managed'     => 'int',
+                'rdp'               => 'int',
+                'mac'               => 'string',
+                'notes'             => 'string',
+                'disable_nw_config' => 'int',
+                'topology_sockets'  => 'int',
+                'topology_cores'    => 'int',
+                'topology_threads'  => 'int',
+            ];
+    }
+}
\ No newline at end of file
diff --git a/src/PostData/Rebuild.php b/src/PostData/Rebuild.php
new file mode 100644
index 0000000..290af20
--- /dev/null
+++ b/src/PostData/Rebuild.php
@@ -0,0 +1,43 @@
+ 'int',
+                'osid'                  => 'int',
+                'newpass'               => 'string',
+                'conf'                  => 'string',
+                'format_primary'        => 'bool',
+                'eu_send_rebuild_email' => 'bool',
+            ];
+    }
+}
\ No newline at end of file
diff --git a/src/Responses/Admin/RebuildResponse.php b/src/Responses/Admin/RebuildResponse.php
new file mode 100644
index 0000000..cf369f6
--- /dev/null
+++ b/src/Responses/Admin/RebuildResponse.php
@@ -0,0 +1,22 @@
+vpsid0 = $vpsID;
+        $path = 'index.php?act=managevps&vpsid='.$vpsID;
+        $res=$this->callStorm($path,'',$post);
+        if ($res->isSuccess()) {
+            $ress=$res;
+        }else{
+            return $res;
+        }
+    }
+
     /**
      * Create a VPS
      * @author       Pulkit Gupta
@@ -737,7 +755,7 @@ function license()
      * @param  int page number, if not specified then only 50 records are returned.
      * @return       ListVs|Res The ListVs class OR false on failure
      */
-    function listvs($page = 1, $reslen = 50)
+    function vps_list($page = 1, $reslen = 50)
     {
         $path = 'index.php?act=vs&page='.$page.'&reslen='.$reslen;
         $response = $this->callStorm($path);
@@ -856,16 +874,43 @@ function ram($serverid = 0)
         return $ret['usage']['ram'];
     }
 
+    /**
+     * @param $vpsId
+     * @return Res|Response
+     */
+    function stat($vpsId)
+    {
+        $path = 'index.php?act=vps_stats';
+        $post =
+            [
+                'show'  => 1,
+                'vpsid' => $vpsId
+            ];
+        $ret = $this->callStorm($path, '',$post);
+        if ($ret->isSuccess()) {
+            return new Response($ret);
+        } else {
+            return $ret;
+        }
+    }
+
     /**
      * Rebuild a VPS
      * @author       Pulkit Gupta
-     * @param  array  $post  An array of DATA that should be posted
-     * @return       array The unserialized array on success OR false on failure
+     * @param  Rebuild  $post  An array of DATA that should be posted
+     * @param  integer  $vpsid
+     * @return Res|RebuildResponse The unserialized array on success OR false on failure
      */
-    function rebuild($post)
+    function rebuild(Rebuild $post, int $vpsid)
     {
         $path = 'index.php?act=rebuild';
-        return $this->call($path, '', $post);
+        $post->vpsid = $vpsid;
+        $ret = $this->callStorm($path, '', $post);
+        if ($ret->isSuccess()) {
+            return new RebuildResponse($ret);
+        } else {
+            return $ret;
+        }
     }
 
     /**
@@ -972,18 +1017,19 @@ function stop($vid)
     }
 
     /**
-     * Gives status of a Virtual Server
-     * @author       Pulkit Gupta
-     * @param  Array  $vids  array of IDs of VMs
-     * @return       Array Contains the status info of the VMs
+     * @param  array  $vids
+     * @return Res|StatusResponse
      */
     function status($vids)
     {
 
         // Make the Request
-        $res = $this->call('index.php?act=vs&vs_status='.implode(',', $vids));
-        return $res['status'];
-
+        $res = $this->callStorm('index.php?act=vs&vs_status='.implode(',', $vids));
+        if ($res->isSuccess()) {
+            return new StatusResponse($res);
+        } else {
+            return $res;
+        }
     }
 
     /**
@@ -1069,12 +1115,21 @@ function userUnsuspend($uid)
         return $res;
     }
 
-
+    /**
+     * @param  int  $page
+     * @param  int  $reslen
+     * @return Res|UsersList
+     */
     function users($page = 1, $reslen = 50)
     {
         $path = 'index.php?act=users&page='.$page.'&reslen='.$reslen;
-        $res = $this->call($path);
-        return $res;
+        $res = $this->callStorm($path);
+        if ($res->isSuccess()) {
+            return new UsersList($res);
+        } else {
+            return $res;
+        }
+
     }
 
     function vnc($post)
@@ -1098,12 +1153,6 @@ function vpsbackups($post)
         return $res;
     }
 
-    function vs($page = 1, $reslen = 50)
-    {
-        $path = 'index.php?act=vs&page='.$page.'&reslen='.$reslen;
-        $res = $this->call($path);
-        return $res;
-    }
 
     function vsbandwidth()
     {

From 7b1bfd30a66b7720b46cc2f5b60361ae3082e13d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D8=BA=D9=84=D8=A7=D9=85=D8=B1=D8=B6=D8=A7=20=D8=A8=D9=87?=
 =?UTF-8?q?=D8=B4=D8=AA=DB=8C=D8=A7=D9=86?= 
Date: Sun, 28 Nov 2021 14:58:07 +0330
Subject: [PATCH 05/18] improve project

---
 index.php                | 173 +++++++++++++++++++++++++++------------
 src/VirtualizorAdmin.php |  17 ++--
 2 files changed, 128 insertions(+), 62 deletions(-)

diff --git a/index.php b/index.php
index 7e668aa..76e006b 100644
--- a/index.php
+++ b/index.php
@@ -9,85 +9,150 @@
 use YiiMan\VirtualizorSdk\PostData\Rebuild;
 use YiiMan\VirtualizorSdk\VirtualizorAdmin;
 
+
 include 'vendor/autoload.php';
 
-$visualizor = new VirtualizorAdmin();
-echo '
';
-$u = $visualizor->users()->users[0];
-$userID = $u->uid;
-$userEmail = $u->email;
-//create
-$servers = $visualizor->servers();//classified
 
-$sv = new CreateVS();
-$sv->virt0 = $sv::VIRTUALIZOR_TYPE_kvm;
-$sv->user_email0 = $userEmail;
-$sv->rootpass0 = 'YiiMan@@@22';
-$sv->hostname0 = 'yiiman';
-$sv->osid0 = 870;
-$plans = $visualizor->plans();//classified
-$sv->plid0 = (int) $plans->plans[0]->plid;
-$sv->node_select0 = $servers->servers[0]->serid;
-$created = $visualizor->addvs($sv, []);//classified
 
-$vpsList = $visualizor->vps_list();//classified
-$vpsID = $vpsList->vs[0]->vpsid;
-//edit
-$editPost = new EditUser();
-$editPost->fname = "YiiMan".uniqid();
-$editPost->newemail0 = 'test@gmail.com';
+// < Parameters >
+{
+    $serverIP='127.0.0.1';
+    $serverPort=4085;
+    $serverProtocol='https';
+
+    $serverKey='Get from side menu >Configuration>server info';
+    $serverKeyPass='Get from side menu >Configuration>server info';
+    $visualizor = new VirtualizorAdmin();
+    $visualizor->Virtualizor_Admin_API($serverIP,$serverKey,$serverKeyPass,$serverPort,$serverProtocol);
+    const NEW_LINE = "\n\n\n\n\n";
+}
+// 
+
+
+echo 'Started API test';
+$u = $visualizor->users();
+if ($u->isSuccess()) {
+    $u = $u->users[0];
+    $userID = $u->uid;
+    $userEmail = $u->email;
+
+    //create
+    $servers = $visualizor->servers();//classified
+    if ($servers->isSuccess()) {
+        $plans = $visualizor->plans();//classified
+        if ($plans->isSuccess()) {
+            $sv = new CreateVS();
+            $sv->virt0 = $sv::VIRTUALIZOR_TYPE_kvm;
+            $sv->user_email0 = $userEmail;
+            $sv->rootpass0 = 'YiiMan@@@22';
+            $sv->hostname0 = 'yiiman';
+            $sv->osid0 = 870;
+
+            $sv->plid0 = (int) $plans->plans[0]->plid;
+            $sv->node_select0 = $servers->servers[0]->serid;
+
+
+            // < Create New VPS after validate data >
+            {
+                if ($sv->validate()) {
+                    $created = $visualizor->addvs($sv, []);//classified
+                    echo 'Create new VPS was '.($created->isSuccess() ? 'Success' : 'not success because:'.$created->getError()->status_title).NEW_LINE;
+                }
+            }
+            // 
+
+
+        }
+
+        $vpsList = $visualizor->vps_list();//classified
+        if ($vpsList->isSuccess()) {
+            $vpsID = $vpsList->vs[0]->vpsid;
+            // < Edit User >
+            {
+                $editPost = new EditUser();
+                $editPost->fname = "YiiMan".uniqid();
+                $editPost->newemail0 = 'test@gmail.com';
+                if ($editPost->validate()) {
+                    $edit = $visualizor->edituser($editPost, $userID);//classified
+                    echo 'Edit user was '.($edit->isSuccess() ? 'Success' : 'not success because:'.$edit->getError()->status_title).NEW_LINE;
+
+                } else {
+                    echo 'Edit User: your data has some errors <'.implode(',', $editPost->errors()).'>'.NEW_LINE;
+                }
+            }
+            // 
+
+            if (!empty($servers)) {
+                //suspend
+                $suspend = $visualizor->userSuspend($userID);//classified
+                echo 'user Suspend was '.($suspend->isSuccess() ? 'Success' : 'not success because:'.$suspend->getError()->status_title).NEW_LINE;
+
+
+                //unsuspend
+                $unsuspend = $visualizor->userUnsuspend($userID);//classified
+                echo 'user UnSuspend was '.($unsuspend->isSuccess() ? 'Success' : 'not success because:'.$unsuspend->getError()->status_title).NEW_LINE;
 
-$edit = $visualizor->edituser($editPost, $userID);//classified
+                //stop
+                $stopped = $visualizor->stop($vpsID);
 
-if (!empty($servers)) {
-    //suspend
-    $suspend = $visualizor->userSuspend($userID);//classified
+                //start
+                $start = $visualizor->start($vpsID);
 
-    //unsuspend
-    $unsuspend = $visualizor->userUnsuspend($userID);//classified
+                //restart
 
-    //stop
-    $stopped = $visualizor->stop($vpsID);
+                $sid = $servers->servers[0]->serid;
+                $restart = $visualizor->restart($vpsID);
 
-    //start
-    $start = $visualizor->start($vpsID);
 
-    //restart
+                //reinstall|rebuild
+                $sid = $servers->servers[0]->serid;
 
-    $sid = $servers->servers[0]->serid;
-    $restart = $visualizor->restart($vpsID);
+                $rebuild = new Rebuild();
+                $rebuild->osid = 870;
+                $rebuild = $visualizor->rebuild($rebuild, $vpsID);//classified
+                echo 'VPS rebuild was '.($rebuild->isSuccess() ? 'Success' : 'not success because:'.$rebuild->getError()->status_title).NEW_LINE;
 
 
-    //reinstall|rebuild
-    $sid = $servers->servers[0]->serid;
+                //checkStatus
+                $checkStatus = $visualizor->status([$vpsID]);//classified
+                if (!$checkStatus->isSuccess()) {
+                    echo 'VPS stats has error:<'.$checkStatus->getError()->status_title.'>('.$checkStatus->getError()->status_description.')'.NEW_LINE;
+                } else {
+                    echo "VPS Stat: ".NEW_LINE;
+                    var_export($checkStatus);
+                }
 
-    $rebuild = new Rebuild();
-    $rebuild->osid = 870;
-    $rebuild = $visualizor->rebuild($rebuild, $vpsID);//classified
 
+                //checkUsage
+                $checkUsage = $visualizor->stat($vpsID);
+                if (!$checkUsage->isSuccess()) {
+                    echo 'VPS Usage has error:<'.$checkUsage->getError()->status_title.'>('.$checkUsage->getError()->status_description.')'.NEW_LINE;
+                } else {
+                    echo "VPS Usage: ".NEW_LINE;
+                    var_export($checkUsage);
+                }
 
-    //checkStatus
-    $checkStatus = $visualizor->status([$vpsID]);//classified
 
-    //checkUsage
-    $checkUsage = $visualizor->stat($vpsID);
+                //hasSpace
 
-    //hasSpace
 
+                //reset_password
+                $manage = new ManageVPS();
+                $manage->rootpass = 'amidikukuhkuh';
+                $resetPassword = $visualizor->managevps($manage, $vpsID);
 
-    //reset_password
-    $manage = new ManageVPS();
-    $manage->rootpass = 'amidikukuhkuh';
-    $resetPassword = $visualizor->managevps($manage, $vpsID);
+                //get_service_details
 
-    //get_service_details
 
+                //terminate
+                $deleted = $visualizor->delete_vs($vpsID);
 
-    //terminate
-    $deleted = $visualizor->delete_vs($vpsID);
 
+            }
+        }
 
+    }
 }
 
 
-echo 'finish';
+echo NEW_LINE.'finish'.NEW_LINE;
diff --git a/src/VirtualizorAdmin.php b/src/VirtualizorAdmin.php
index c63b2fb..bd6fe95 100644
--- a/src/VirtualizorAdmin.php
+++ b/src/VirtualizorAdmin.php
@@ -28,9 +28,9 @@
 
 class VirtualizorAdmin
 {
-    private $key = 'chykaaxaqiextynduamu6terpjwdruks';
-    private $pass = 't1hjdemtcigtfsewjebirnfknuhemeqy';
-    private $ip = '103.215.221.197';
+    private $key = '';
+    private $pass = '';
+    private $ip = '';
     private $port = 4085;
     private $protocol = 'https';
 
@@ -45,12 +45,13 @@ class VirtualizorAdmin
      * @param  string  $ip    IP of the NODE
      * @return       NULL
      */
-    function Virtualizor_Admin_API($ip, $key, $pass, $port = 4085)
+    function Virtualizor_Admin_API($ip, $key, $pass, $port = 4085, $prot = 'https')
     {
         $this->key = $key;
         $this->pass = $pass;
         $this->ip = $ip;
         $this->port = $port;
+        $this->protocol = $prot;
         if ($port != 4085) {
             $this->protocol = 'http';
         }
@@ -625,10 +626,10 @@ public function managevps(ManageVPS $post, int $vpsID)
     {
         $post->vpsid0 = $vpsID;
         $path = 'index.php?act=managevps&vpsid='.$vpsID;
-        $res=$this->callStorm($path,'',$post);
+        $res = $this->callStorm($path, '', $post);
         if ($res->isSuccess()) {
-            $ress=$res;
-        }else{
+            $ress = $res;
+        } else {
             return $res;
         }
     }
@@ -886,7 +887,7 @@ function stat($vpsId)
                 'show'  => 1,
                 'vpsid' => $vpsId
             ];
-        $ret = $this->callStorm($path, '',$post);
+        $ret = $this->callStorm($path, '', $post);
         if ($ret->isSuccess()) {
             return new Response($ret);
         } else {

From c425166a6688c329daae6e63659b7b368167f2f8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D8=BA=D9=84=D8=A7=D9=85=D8=B1=D8=B6=D8=A7=20=D8=A8=D9=87?=
 =?UTF-8?q?=D8=B4=D8=AA=DB=8C=D8=A7=D9=86?= 
Date: Mon, 29 Nov 2021 11:03:00 +0330
Subject: [PATCH 06/18] improve project

---
 composer.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/composer.json b/composer.json
index bccb501..854ad70 100644
--- a/composer.json
+++ b/composer.json
@@ -2,7 +2,7 @@
   "name": "yiiman/virtualizor",
   "description": "Tiny SDK for virtualizor",
   "type": "library",
-  "license": "Apache",
+  "license": "Apache-2.0",
   "autoload": {
     "psr-4": {
       "YiiMan\\VirtualizorSdk\\": "src/"

From dbfd0ac72545a190fab6b8b727c59ed004fd2169 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D8=BA=D9=84=D8=A7=D9=85=D8=B1=D8=B6=D8=A7=20=D8=A8=D9=87?=
 =?UTF-8?q?=D8=B4=D8=AA=DB=8C=D8=A7=D9=86?= 
Date: Wed, 1 Dec 2021 11:09:16 +0330
Subject: [PATCH 07/18] improve project

---
 .env-example  |  5 +++++
 .gitignore    |  2 ++
 README.md     | 21 +++++++++++++++++-
 composer.json |  3 ++-
 index.php     | 59 ++++++++++++++++++++++++++++-----------------------
 5 files changed, 62 insertions(+), 28 deletions(-)
 create mode 100644 .env-example

diff --git a/.env-example b/.env-example
new file mode 100644
index 0000000..d7e1bbb
--- /dev/null
+++ b/.env-example
@@ -0,0 +1,5 @@
+SERVER_IP=
+SERVER_PROTOCOL= #http | https
+SERVER_PORT=
+SERVER_KEY= #Get from side menu >Configuration>server info
+SERVER_PASS= #Get from side menu >Configuration>server info
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 57872d0..607642e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,3 @@
 /vendor/
+.env
+composer.lock
\ No newline at end of file
diff --git a/README.md b/README.md
index 49a83b3..29943f5 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,20 @@
-# Client_SDK
\ No newline at end of file
+# Admin virtualizor SDK
+Classified virtualizor admin sdk based on [APIStorm](https://github.com/yiiman-dev/apistorm) package
+
+# what is different?
+
+In this package, We have classified all the methods so that all the feedback is understandable for popular IDEs.
+
+## Usage
+for samples please clone package and install composer vendors
+
+then create `.env` file from `.env-example` file and fill your server data
+
+now execute ``index.php`` sample file in command line:
+
+
+`php index.php`
+
+# Composer install
+
+`composer require yiiman/virtualizor`
diff --git a/composer.json b/composer.json
index 854ad70..25a39be 100644
--- a/composer.json
+++ b/composer.json
@@ -22,6 +22,7 @@
   ],
   "minimum-stability": "stable",
   "require": {
-    "yiiman/apistorm": "dev-main"
+    "yiiman/apistorm": "dev-main",
+    "vlucas/phpdotenv": "5.4.x-dev"
   }
 }
diff --git a/index.php b/index.php
index 76e006b..f8bcfea 100644
--- a/index.php
+++ b/index.php
@@ -12,34 +12,41 @@
 
 include 'vendor/autoload.php';
 
+// < Load .env data >
+{
+    $dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
+    $dotenv->load();
+}
+// 
 
 
-// < Parameters >
+// < Initialize SDK >
 {
-    $serverIP='127.0.0.1';
-    $serverPort=4085;
-    $serverProtocol='https';
-
-    $serverKey='Get from side menu >Configuration>server info';
-    $serverKeyPass='Get from side menu >Configuration>server info';
-    $visualizor = new VirtualizorAdmin();
-    $visualizor->Virtualizor_Admin_API($serverIP,$serverKey,$serverKeyPass,$serverPort,$serverProtocol);
+    $virtualizor = new VirtualizorAdmin();
+    $virtualizor->Virtualizor_Admin_API
+    (
+        $_ENV['SERVER_IP'],
+        $_ENV['SERVER_KEY'],
+        $_ENV['SERVER_PASS'],
+        $_ENV['SERVER_PORT'],
+        $_ENV['SERVER_PROTOCOL']
+    );
     const NEW_LINE = "\n\n\n\n\n";
 }
-// 
+// 
 
 
 echo 'Started API test';
-$u = $visualizor->users();
+$u = $virtualizor->users();
 if ($u->isSuccess()) {
     $u = $u->users[0];
     $userID = $u->uid;
     $userEmail = $u->email;
 
     //create
-    $servers = $visualizor->servers();//classified
+    $servers = $virtualizor->servers();//classified
     if ($servers->isSuccess()) {
-        $plans = $visualizor->plans();//classified
+        $plans = $virtualizor->plans();//classified
         if ($plans->isSuccess()) {
             $sv = new CreateVS();
             $sv->virt0 = $sv::VIRTUALIZOR_TYPE_kvm;
@@ -55,7 +62,7 @@
             // < Create New VPS after validate data >
             {
                 if ($sv->validate()) {
-                    $created = $visualizor->addvs($sv, []);//classified
+                    $created = $virtualizor->addvs($sv, []);//classified
                     echo 'Create new VPS was '.($created->isSuccess() ? 'Success' : 'not success because:'.$created->getError()->status_title).NEW_LINE;
                 }
             }
@@ -64,7 +71,7 @@
 
         }
 
-        $vpsList = $visualizor->vps_list();//classified
+        $vpsList = $virtualizor->vps_list();//classified
         if ($vpsList->isSuccess()) {
             $vpsID = $vpsList->vs[0]->vpsid;
             // < Edit User >
@@ -73,7 +80,7 @@
                 $editPost->fname = "YiiMan".uniqid();
                 $editPost->newemail0 = 'test@gmail.com';
                 if ($editPost->validate()) {
-                    $edit = $visualizor->edituser($editPost, $userID);//classified
+                    $edit = $virtualizor->edituser($editPost, $userID);//classified
                     echo 'Edit user was '.($edit->isSuccess() ? 'Success' : 'not success because:'.$edit->getError()->status_title).NEW_LINE;
 
                 } else {
@@ -84,24 +91,24 @@
 
             if (!empty($servers)) {
                 //suspend
-                $suspend = $visualizor->userSuspend($userID);//classified
+                $suspend = $virtualizor->userSuspend($userID);//classified
                 echo 'user Suspend was '.($suspend->isSuccess() ? 'Success' : 'not success because:'.$suspend->getError()->status_title).NEW_LINE;
 
 
                 //unsuspend
-                $unsuspend = $visualizor->userUnsuspend($userID);//classified
+                $unsuspend = $virtualizor->userUnsuspend($userID);//classified
                 echo 'user UnSuspend was '.($unsuspend->isSuccess() ? 'Success' : 'not success because:'.$unsuspend->getError()->status_title).NEW_LINE;
 
                 //stop
-                $stopped = $visualizor->stop($vpsID);
+                $stopped = $virtualizor->stop($vpsID);
 
                 //start
-                $start = $visualizor->start($vpsID);
+                $start = $virtualizor->start($vpsID);
 
                 //restart
 
                 $sid = $servers->servers[0]->serid;
-                $restart = $visualizor->restart($vpsID);
+                $restart = $virtualizor->restart($vpsID);
 
 
                 //reinstall|rebuild
@@ -109,12 +116,12 @@
 
                 $rebuild = new Rebuild();
                 $rebuild->osid = 870;
-                $rebuild = $visualizor->rebuild($rebuild, $vpsID);//classified
+                $rebuild = $virtualizor->rebuild($rebuild, $vpsID);//classified
                 echo 'VPS rebuild was '.($rebuild->isSuccess() ? 'Success' : 'not success because:'.$rebuild->getError()->status_title).NEW_LINE;
 
 
                 //checkStatus
-                $checkStatus = $visualizor->status([$vpsID]);//classified
+                $checkStatus = $virtualizor->status([$vpsID]);//classified
                 if (!$checkStatus->isSuccess()) {
                     echo 'VPS stats has error:<'.$checkStatus->getError()->status_title.'>('.$checkStatus->getError()->status_description.')'.NEW_LINE;
                 } else {
@@ -124,7 +131,7 @@
 
 
                 //checkUsage
-                $checkUsage = $visualizor->stat($vpsID);
+                $checkUsage = $virtualizor->stat($vpsID);
                 if (!$checkUsage->isSuccess()) {
                     echo 'VPS Usage has error:<'.$checkUsage->getError()->status_title.'>('.$checkUsage->getError()->status_description.')'.NEW_LINE;
                 } else {
@@ -139,13 +146,13 @@
                 //reset_password
                 $manage = new ManageVPS();
                 $manage->rootpass = 'amidikukuhkuh';
-                $resetPassword = $visualizor->managevps($manage, $vpsID);
+                $resetPassword = $virtualizor->managevps($manage, $vpsID);
 
                 //get_service_details
 
 
                 //terminate
-                $deleted = $visualizor->delete_vs($vpsID);
+                $deleted = $virtualizor->delete_vs($vpsID);
 
 
             }

From 927e3e08314a9704dab8234ed8c498f2d32d9185 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D8=BA=D9=84=D8=A7=D9=85=D8=B1=D8=B6=D8=A7=20=D8=A8=D9=87?=
 =?UTF-8?q?=D8=B4=D8=AA=DB=8C=D8=A7=D9=86?= 
Date: Wed, 1 Dec 2021 13:59:59 +0330
Subject: [PATCH 08/18] added os templates

---
 index.php                               |  3 ++-
 src/Responses/Admin/OsName.php          | 22 ++++++++++++++++++++++
 src/Responses/Admin/OsTemplates.php     | 19 +++++++++++++++++++
 src/Responses/Admin/VirtualizorType.php | 25 +++++++++++++++++++++++++
 src/VirtualizorAdmin.php                | 14 ++++++++++++--
 5 files changed, 80 insertions(+), 3 deletions(-)
 create mode 100644 src/Responses/Admin/OsName.php
 create mode 100644 src/Responses/Admin/OsTemplates.php
 create mode 100644 src/Responses/Admin/VirtualizorType.php

diff --git a/index.php b/index.php
index f8bcfea..14628f4 100644
--- a/index.php
+++ b/index.php
@@ -31,7 +31,7 @@
         $_ENV['SERVER_PORT'],
         $_ENV['SERVER_PROTOCOL']
     );
-    const NEW_LINE = "\n\n\n\n\n";
+    define('NEW_LINE',"\n\n\n\n\n") ;
 }
 // 
 
@@ -48,6 +48,7 @@
     if ($servers->isSuccess()) {
         $plans = $virtualizor->plans();//classified
         if ($plans->isSuccess()) {
+            $osTemplates=$virtualizor->ostemplates()->oslist[0];
             $sv = new CreateVS();
             $sv->virt0 = $sv::VIRTUALIZOR_TYPE_kvm;
             $sv->user_email0 = $userEmail;
diff --git a/src/Responses/Admin/OsName.php b/src/Responses/Admin/OsName.php
new file mode 100644
index 0000000..2f06f01
--- /dev/null
+++ b/src/Responses/Admin/OsName.php
@@ -0,0 +1,22 @@
+ $osData) {
+            $out[$osID] = new Os($osData);
+        }
+        return $out;
+    }
+}
\ No newline at end of file
diff --git a/src/Responses/Admin/OsTemplates.php b/src/Responses/Admin/OsTemplates.php
new file mode 100644
index 0000000..cc40cc9
--- /dev/null
+++ b/src/Responses/Admin/OsTemplates.php
@@ -0,0 +1,19 @@
+ $osData) {
+            $out[$osName] = new OsName($osData);
+        }
+        return $out;
+    }
+}
\ No newline at end of file
diff --git a/src/VirtualizorAdmin.php b/src/VirtualizorAdmin.php
index bd6fe95..1af8300 100644
--- a/src/VirtualizorAdmin.php
+++ b/src/VirtualizorAdmin.php
@@ -17,6 +17,7 @@
 use YiiMan\VirtualizorSdk\Responses\Admin\DoneResponse;
 use YiiMan\VirtualizorSdk\Responses\Admin\Ipsresponse;
 use YiiMan\VirtualizorSdk\Responses\Admin\ListVs;
+use YiiMan\VirtualizorSdk\Responses\Admin\OsTemplates;
 use YiiMan\VirtualizorSdk\Responses\Admin\Plans;
 use YiiMan\VirtualizorSdk\Responses\Admin\RebuildResponse;
 use YiiMan\VirtualizorSdk\Responses\Admin\Server_list;
@@ -805,11 +806,20 @@ function os($post)
         return $ret;
     }
 
+    /**
+     * @param  int  $page
+     * @param  int  $reslen
+     * @return OsTemplates|Res
+     */
     function ostemplates($page = 1, $reslen = 50)
     {
         $path = 'index.php?act=ostemplates&page='.$page.'&reslen='.$reslen;
-        $ret = $this->call($path);
-        return $ret;
+        $ret = $this->callStorm($path);
+        if($ret->isSuccess()){
+            return new OsTemplates($ret);
+        }else{
+            return $ret;
+        }
     }
 
     function performance()

From 72e725b3392d209a3f4e0e363ebf223fc1ab299d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D8=BA=D9=84=D8=A7=D9=85=D8=B1=D8=B6=D8=A7=20=D8=A8=D9=87?=
 =?UTF-8?q?=D8=B4=D8=AA=DB=8C=D8=A7=D9=86?= 
Date: Sat, 18 Dec 2021 11:19:37 +0330
Subject: [PATCH 09/18] classify managevps method

---
 src/Responses/Admin/Disk.php      | 40 +++++++++++++++++++++++++++++++
 src/Responses/Admin/ManageVps.php | 15 ++++++++++++
 src/Responses/Admin/VS.php        |  2 +-
 src/VirtualizorAdmin.php          |  7 +++++-
 4 files changed, 62 insertions(+), 2 deletions(-)
 create mode 100644 src/Responses/Admin/Disk.php
 create mode 100644 src/Responses/Admin/ManageVps.php

diff --git a/src/Responses/Admin/Disk.php b/src/Responses/Admin/Disk.php
new file mode 100644
index 0000000..b7fe1e9
--- /dev/null
+++ b/src/Responses/Admin/Disk.php
@@ -0,0 +1,40 @@
+vpsid0 = $vpsID;
         $path = 'index.php?act=managevps&vpsid='.$vpsID;
         $res = $this->callStorm($path, '', $post);
         if ($res->isSuccess()) {
-            $ress = $res;
+            return new \YiiMan\VirtualizorSdk\Responses\Admin\ManageVps($res);
         } else {
             return $res;
         }

From acd4b4701971d072d00ee0c21f0a7b519afe5bf9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D8=BA=D9=84=D8=A7=D9=85=D8=B1=D8=B6=D8=A7=20=D8=A8=D9=87?=
 =?UTF-8?q?=D8=B4=D8=AA=DB=8C=D8=A7=D9=86?= 
Date: Sat, 18 Dec 2021 11:33:43 +0330
Subject: [PATCH 10/18] classify managevps method

---
 src/Responses/Admin/ManageVps.php | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/Responses/Admin/ManageVps.php b/src/Responses/Admin/ManageVps.php
index 39104a4..a028ac1 100644
--- a/src/Responses/Admin/ManageVps.php
+++ b/src/Responses/Admin/ManageVps.php
@@ -6,10 +6,11 @@
 namespace YiiMan\VirtualizorSdk\Responses\Admin;
 
 /**
+ *
+ *
  * @property VS $vs_info
  */
 class ManageVps extends DoneResponse
 {
     public $vs_info='class:YiiMan\VirtualizorSdk\Responses\Admin\VS';
-
 }
\ No newline at end of file

From 581fe49ac75b67c9fe9323b2dcf5013b299b4ccb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D8=BA=D9=84=D8=A7=D9=85=D8=B1=D8=B6=D8=A7=20=D8=A8=D9=87?=
 =?UTF-8?q?=D8=B4=D8=AA=DB=8C=D8=A7=D9=86?= 
Date: Sat, 18 Dec 2021 14:07:38 +0330
Subject: [PATCH 11/18] improve done messages response

---
 src/Responses/Admin/DoneResponse.php | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/Responses/Admin/DoneResponse.php b/src/Responses/Admin/DoneResponse.php
index 561caac..a215c63 100644
--- a/src/Responses/Admin/DoneResponse.php
+++ b/src/Responses/Admin/DoneResponse.php
@@ -8,9 +8,13 @@
 /**
  * Class DoneResponse
  * @package YiiMan\VirtualizorSdk\Responses\Admin
- * @property bool $done
+ * @property bool   $done
+ * @property string $done_msg
+ * @property string $error_msg
  */
 class DoneResponse extends LowResponseBase
 {
     public $done = 'bool';
+    public $done_msg = 'string';
+    public $error_msg = 'string';
 }
\ No newline at end of file

From dc2b5200681e7b5d6584c2e37f6b52224e87a712 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D8=BA=D9=84=D8=A7=D9=85=D8=B1=D8=B6=D8=A7=20=D8=A8=D9=87?=
 =?UTF-8?q?=D8=B4=D8=AA=DB=8C=D8=A7=D9=86?= 
Date: Sat, 18 Dec 2021 14:19:56 +0330
Subject: [PATCH 12/18] classify start,stop,restart methods

---
 src/VirtualizorAdmin.php | 36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/src/VirtualizorAdmin.php b/src/VirtualizorAdmin.php
index fe78c7f..55f72d7 100644
--- a/src/VirtualizorAdmin.php
+++ b/src/VirtualizorAdmin.php
@@ -820,9 +820,9 @@ function ostemplates($page = 1, $reslen = 50)
     {
         $path = 'index.php?act=ostemplates&page='.$page.'&reslen='.$reslen;
         $ret = $this->callStorm($path);
-        if($ret->isSuccess()){
+        if ($ret->isSuccess()) {
             return new OsTemplates($ret);
-        }else{
+        } else {
             return $ret;
         }
     }
@@ -933,13 +933,17 @@ function rebuild(Rebuild $post, int $vpsid)
      * RESTART a Virtual Server
      * @author       Pulkit Gupta
      * @param  int  $vid  The VMs ID
-     * @return       bool TRUE on success or FALSE on failure
+     * @return Res|DoneResponse
      */
     function restart($vid)
     {
         // Make the Request
-        $res = $this->call('index.php?act=vs&action=restart&serid=0&vpsid='.(int) $vid);
-        return $res;
+        $res = $this->callStorm('index.php?act=vs&action=restart&serid=0&vpsid='.(int) $vid);
+        if ($res->isSuccess()) {
+            return new DoneResponse($res);
+        } else {
+            return $res;
+        }
     }
 
     function restartservices($post)
@@ -1010,26 +1014,36 @@ function sslcert()
      * START a Virtual Server
      * @author       Pulkit Gupta
      * @param  int  $vid  The VMs ID
-     * @return       bool TRUE on success or FALSE on failure
+     * @return Res|DoneResponse
      */
     function start($vid)
     {
 
-        $res = $this->call('index.php?act=vs&action=start&serid=0&vpsid='.(int) $vid);
-        return $res;
+        $res = $this->callStorm('index.php?act=vs&action=start&serid=0&vpsid='.(int) $vid);
+        if ($res->isSuccess()) {
+            return new DoneResponse($res);
+        } else {
+            return $res;
+        }
+
     }
 
     /**
      * STOP a Virtual Server
      * @author       Pulkit Gupta
      * @param  int  $vid  The VMs ID
-     * @return       bool TRUE on success or FALSE on failure
+     * @return Res|DoneResponse
      */
     function stop($vid)
     {
         // Make the Request
-        $res = $this->call('index.php?act=vs&action=stop&serid=0&vpsid='.(int) $vid);
-        return $res;
+        $res = $this->callStorm('index.php?act=vs&action=stop&serid=0&vpsid='.(int) $vid);
+        if ($res->isSuccess()) {
+            return new DoneResponse($res);
+        } else {
+            return $res;
+        }
+
     }
 
     /**

From 777445464af239f639fe7f0858f1c1ae972a60f4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D8=BA=D9=84=D8=A7=D9=85=D8=B1=D8=B6=D8=A7=20=D8=A8=D9=87?=
 =?UTF-8?q?=D8=B4=D8=AA=DB=8C=D8=A7=D9=86?= 
Date: Sun, 19 Dec 2021 10:36:08 +0330
Subject: [PATCH 13/18] classify delete_vs method

---
 src/VirtualizorAdmin.php | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/VirtualizorAdmin.php b/src/VirtualizorAdmin.php
index 55f72d7..67b8a54 100644
--- a/src/VirtualizorAdmin.php
+++ b/src/VirtualizorAdmin.php
@@ -541,13 +541,17 @@ function defaultvsconf($post)
      * Delete a VPS
      * @author       Pulkit Gupta
      * @param  int  $vid  An array of DATA that should be posted
-     * @return       boolean 1 on success OR 0 on failure
+     * @return Res|DoneResponse
      */
     function delete_vs(int $vid)
     {
         $path = 'index.php?act=vs&delete='.(int) $vid;
-        $res = $this->call($path);
-        return $res['done'];
+        $res = $this->callStorm($path);
+        if ($res->isSuccess()) {
+            return new DoneResponse($res);
+        } else {
+            return $res;
+        }
     }
 
     /**

From 5f877604861d2b2471f6f9eca34d11dabf8548a0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D8=BA=D9=84=D8=A7=D9=85=D8=B1=D8=B6=D8=A7=20=D8=A8=D9=87?=
 =?UTF-8?q?=D8=B4=D8=AA=DB=8C=D8=A7=D9=86?= 
Date: Sun, 19 Dec 2021 10:50:23 +0330
Subject: [PATCH 14/18] classify suspend,unsuspend method

---
 src/VirtualizorAdmin.php | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/VirtualizorAdmin.php b/src/VirtualizorAdmin.php
index 67b8a54..2087dae 100644
--- a/src/VirtualizorAdmin.php
+++ b/src/VirtualizorAdmin.php
@@ -1070,14 +1070,14 @@ function status($vids)
      * Suspends a VM of a Virtual Server
      * @author       Pulkit Gupta
      * @param  int  $vid  The VMs ID
-     * @return       Res 1 if the VM is ON, 0 if its OFF
+     * @return Res|DoneResponse
      */
     function suspend($vid)
     {
         $path = 'index.php?act=vs&suspend='.(int) $vid;
         $res = $this->callStorm($path);
         if ($res->isSuccess()) {
-            $test = $res;
+            return new DoneResponse($res);
         } else {
             return $res;
         }
@@ -1087,13 +1087,17 @@ function suspend($vid)
      * Unsuspends a VM of a Virtual Server
      * @author       Pulkit Gupta
      * @param  int  $vid  The VMs ID
-     * @return       int 1 if the VM is ON, 0 if its OFF
+     * @return Res|DoneResponse
      */
     function unsuspend($vid)
     {
         $path = 'index.php?act=vs&unsuspend='.(int) $vid;
-        $res = $this->call($path);
-        return $res;
+        $res = $this->callStorm($path);
+        if ($res->isSuccess()) {
+            return new DoneResponse($res);
+        } else {
+            return $res;
+        }
     }
 
     function tools()

From e03a7094742e15d51abaff6f6fc0887111f4536a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D8=BA=D9=84=D8=A7=D9=85=D8=B1=D8=B6=D8=A7=20=D8=A8=D9=87?=
 =?UTF-8?q?=D8=B4=D8=AA=DB=8C=D8=A7=D9=86?= 
Date: Sun, 19 Dec 2021 11:26:21 +0330
Subject: [PATCH 15/18] Update README.md

---
 README.md                | 99 +++++++++++++++++++++++++++++++++++++++-
 src/VirtualizorAdmin.php |  1 -
 2 files changed, 98 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index 29943f5..dd76311 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,5 @@
 # Admin virtualizor SDK
+
 Classified virtualizor admin sdk based on [APIStorm](https://github.com/yiiman-dev/apistorm) package
 
 # what is different?
@@ -6,15 +7,111 @@ Classified virtualizor admin sdk based on [APIStorm](https://github.com/yiiman-d
 In this package, We have classified all the methods so that all the feedback is understandable for popular IDEs.
 
 ## Usage
+
 for samples please clone package and install composer vendors
 
 then create `.env` file from `.env-example` file and fill your server data
 
 now execute ``index.php`` sample file in command line:
 
-
 `php index.php`
 
 # Composer install
 
 `composer require yiiman/virtualizor`
+
+## Methods list
+
+| method                                                | classified  |
+| ----------------------------------------------------- | ----------- |
+| addippool                                             |   ✓   |
+| addips                                                |   ✗   |
+| addiso                                                |   ✗   |
+| addplan                                               |   ✗   |
+| addserver                                             |   ✗   |
+| addtemplate                                           |   ✗   |
+| adduser                                               |   ✗   |
+| addvs                                                 |   ✓   |
+| addiprange                                            |   ✗   |
+| addsg                                                 |   ✗   |
+| addbackupserver                                       |   ✗   |
+| addstorage                                            |   ✗   |
+| adddnsplan                                            |   ✗   |
+| add_admin_acl                                         |   ✗   |
+| addmg                                                 |   ✗   |
+| add_distro                                            |   ✗   |
+| addpdns                                               |   ✗   |
+| adminindex                                            |   ✗   |
+| apidoings                                             |   ✗   |
+| backup                                                |   ✗   |
+| bandwidth                                             |   ✗   |
+| cluster                                               |   ✗   |
+| config                                                |   ✗   |
+| cpu                                                   |   ✗   |
+| createssl                                             |   ✗   |
+| createtemplate                                        |   ✗   |
+| databackup                                            |   ✗   |
+| defaultvsconf                                         |   ✗   |
+| delete_vs                                             |   ✓   |
+| disk                                                  |   ✗   |
+| downloadiso                                           |   ✗   |
+| editemailtemp                                         |   ✗   |
+| editippool                                            |   ✗   |
+| editips                                               |   ✗   |
+| editplan                                              |   ✗   |
+| editserver                                            |   ✗   |
+| edittemplate                                          |   ✗   |
+| edituser                                              |   ✓   |
+| managevps                                             |   ✓   |
+| editvs                                                |   ✗   |
+| emailconfig                                           |   ✗   |
+| emailtemp                                             |   ✗   |
+| filemanager                                           |   ✗   |
+| firewall                                              |   ✗   |
+| giveos                                                |   ✗   |
+| health                                                |   ✗   |
+| hostname                                              |   ✗   |
+| import                                                |   ✗   |
+| ippool                                                |   ✗   |
+| ips                                                   |   ✓   |
+| iso                                                   |   ✗   |
+| kernelconf                                            |   ✗   |
+| license                                               |   ✗   |
+| vps_list                                              |   ✓   |
+| login                                                 |   ✗   |
+| loginlogs                                             |   ✗   |
+| logs                                                  |   ✗   |
+| maintenance                                           |   ✗   |
+| makeslave                                             |   ✗   |
+| os                                                    |   ✗   |
+| ostemplates                                           |   ✓   |
+| performance                                           |   ✗   |
+| phpmyadmin                                            |   ✗   |
+| plans                                                 |   ✓   |
+| poweroff                                              |   ✗   |
+| processes                                             |   ✗   |
+| ram                                                   |   ✗   |
+| stat                                                  |   ✓   |
+| rebuild                                               |   ✓   |
+| restart                                               |   ✓   |
+| restartservices                                       |   ✗   |
+| serverinfo                                            |   ✗   |
+| servers                                               |   ✓   |
+| services                                              |   ✗   |
+| start                                                 |   ✓   |
+| stop                                                  |   ✓   |
+| status                                                |   ✓   |
+| suspend                                               |   ✓   |
+| unsuspend                                             |   ✓   |
+| ubc                                                   |   ✗   |
+| updates                                               |   ✗   |
+| userlogs                                              |   ✗   |
+| userSuspend                                           |   ✓   |
+| userUnsuspend                                         |   ✓   |
+| users                                                 |   ✓   |
+| vnc                                                   |   ✗   |
+| vpsbackupsettings                                     |   ✗   |
+| vpsbackups                                            |   ✗   |
+| vsbandwidth                                           |   ✗   |
+| vscpu                                                 |   ✗   |
+| vsram                                                 |   ✗   |
diff --git a/src/VirtualizorAdmin.php b/src/VirtualizorAdmin.php
index 2087dae..34235d8 100644
--- a/src/VirtualizorAdmin.php
+++ b/src/VirtualizorAdmin.php
@@ -857,7 +857,6 @@ function plans($page = 1, $reslen = 50)
         } else {
             return $ret;
         }
-        return $ret;
     }
 
     /**

From ee34a2051209235303b7357500b349695b436280 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D8=BA=D9=84=D8=A7=D9=85=D8=B1=D8=B6=D8=A7=20=D8=A8=D9=87?=
 =?UTF-8?q?=D8=B4=D8=AA=DB=8C=D8=A7=D9=86?= 
Date: Sun, 19 Dec 2021 22:03:09 +0330
Subject: [PATCH 16/18] debug managevps method

---
 src/PostData/ManageVPS.php | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/PostData/ManageVPS.php b/src/PostData/ManageVPS.php
index 9856fc1..a5a9d07 100644
--- a/src/PostData/ManageVPS.php
+++ b/src/PostData/ManageVPS.php
@@ -89,6 +89,7 @@ class ManageVPS extends \YiiMan\ApiStorm\Post\BasePostData
     public $topology_sockets;
     public $topology_cores;
     public $topology_threads;
+    public $editvps=1;
 
     /**
      * @inheritDoc

From b67057eaab4573d17012a7801ca211a12bb9aeb8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D8=BA=D9=84=D8=A7=D9=85=D8=B1=D8=B6=D8=A7=20=D8=A8=D9=87?=
 =?UTF-8?q?=D8=B4=D8=AA=DB=8C=D8=A7=D9=86?= 
Date: Mon, 20 Dec 2021 21:25:45 +0330
Subject: [PATCH 17/18] debug managevps method

---
 src/VirtualizorAdmin.php | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/VirtualizorAdmin.php b/src/VirtualizorAdmin.php
index 34235d8..4e0157e 100644
--- a/src/VirtualizorAdmin.php
+++ b/src/VirtualizorAdmin.php
@@ -627,6 +627,10 @@ function edituser(EditUser $post, $uid)
         return $res;
     }
 
+
+
+
+
     /**
      * @param  ManageVPS  $post
      * @param  int        $vpsID

From 716f34bb33587cfa4da998a4d343b1836a83cdec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D8=BA=D9=84=D8=A7=D9=85=D8=B1=D8=B6=D8=A7=20=D8=A8=D9=87?=
 =?UTF-8?q?=D8=B4=D8=AA=DB=8C=D8=A7=D9=86?= 
Date: Wed, 22 Dec 2021 14:34:58 +0330
Subject: [PATCH 18/18] debug rebuild function

---
 src/PostData/Rebuild.php | 4 +++-
 src/VirtualizorAdmin.php | 4 ----
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/PostData/Rebuild.php b/src/PostData/Rebuild.php
index 290af20..7d2624f 100644
--- a/src/PostData/Rebuild.php
+++ b/src/PostData/Rebuild.php
@@ -23,7 +23,8 @@ class Rebuild extends \YiiMan\ApiStorm\Post\BasePostData
         $newpass0,
         $conf0,
         $format_primary,
-        $eu_send_rebuild_email;
+        $eu_send_rebuild_email,
+        $reos = 1;
 
     /**
      * @inheritDoc
@@ -38,6 +39,7 @@ public function rules(): array
                 'conf'                  => 'string',
                 'format_primary'        => 'bool',
                 'eu_send_rebuild_email' => 'bool',
+                'reos'                  => 'int',
             ];
     }
 }
\ No newline at end of file
diff --git a/src/VirtualizorAdmin.php b/src/VirtualizorAdmin.php
index 4e0157e..34235d8 100644
--- a/src/VirtualizorAdmin.php
+++ b/src/VirtualizorAdmin.php
@@ -627,10 +627,6 @@ function edituser(EditUser $post, $uid)
         return $res;
     }
 
-
-
-
-
     /**
      * @param  ManageVPS  $post
      * @param  int        $vpsID