@@ -107,6 +107,9 @@ discard block |
||
| 107 | 107 | return $ret; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | + /** |
|
| 111 | + * @param string $level |
|
| 112 | + */ |
|
| 110 | 113 | public function log($level, $text, $line = '', $file = '') { |
| 111 | 114 | if (function_exists('myadmin_log')) |
| 112 | 115 | myadmin_log('cloudlinux', $level, $text, $line, $file); |
@@ -243,8 +246,8 @@ discard block |
||
| 243 | 246 | * or |
| 244 | 247 | * Remove IP licenses with specified type for customer. Also unÂregisters from CLN server associated with IP. |
| 245 | 248 | * @param string $ip ip address to remove |
| 246 | - * @param bool|false|int $type optional parameter to specify the type of license to remove (1,2, or 16) |
|
| 247 | - * @return integer 0 on success, -1 on error, Error will be returned also if account have no licenses for provided IP. |
|
| 249 | + * @param integer $type optional parameter to specify the type of license to remove (1,2, or 16) |
|
| 250 | + * @return boolean 0 on success, -1 on error, Error will be returned also if account have no licenses for provided IP. |
|
| 248 | 251 | */ |
| 249 | 252 | public function remove_license($ip, $type = false) { |
| 250 | 253 | $this->log('info', "Calling CLoudLinux->xml_client->remove_license({$this->authToken()}, {$ip}, {$type})", __LINE__, __FILE__); |
@@ -30,301 +30,301 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class Cloudlinux |
| 32 | 32 | { |
| 33 | - private $login = ''; |
|
| 34 | - private $key = ''; |
|
| 35 | - private $authToken; |
|
| 36 | - public $prefix = 'registration.'; |
|
| 37 | - public $encoding = 'utf-8'; // utf-8 / UTF-8 |
|
| 38 | - public $api_type = 'rest'; |
|
| 39 | - public $sslverify = false; |
|
| 40 | - public $xml_options = []; |
|
| 41 | - public $xml_url = 'https://cln.cloudlinux.com/clweb/xmlrpc'; |
|
| 42 | - public $rest_url = 'https://cln.cloudlinux.com/api/'; |
|
| 43 | - public $rest_options = []; |
|
| 44 | - /** |
|
| 45 | - * @var \XML_RPC2_Client |
|
| 46 | - */ |
|
| 47 | - public $xml_client; |
|
| 48 | - public $response; |
|
| 33 | + private $login = ''; |
|
| 34 | + private $key = ''; |
|
| 35 | + private $authToken; |
|
| 36 | + public $prefix = 'registration.'; |
|
| 37 | + public $encoding = 'utf-8'; // utf-8 / UTF-8 |
|
| 38 | + public $api_type = 'rest'; |
|
| 39 | + public $sslverify = false; |
|
| 40 | + public $xml_options = []; |
|
| 41 | + public $xml_url = 'https://cln.cloudlinux.com/clweb/xmlrpc'; |
|
| 42 | + public $rest_url = 'https://cln.cloudlinux.com/api/'; |
|
| 43 | + public $rest_options = []; |
|
| 44 | + /** |
|
| 45 | + * @var \XML_RPC2_Client |
|
| 46 | + */ |
|
| 47 | + public $xml_client; |
|
| 48 | + public $response; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Cloudlinux::__construct() |
|
| 52 | - * |
|
| 53 | - * @param string $login API Login Name |
|
| 54 | - * @param string $key API Key |
|
| 55 | - * @param string $type API type to use, can be 'rest' or 'xml' |
|
| 56 | - */ |
|
| 57 | - public function __construct($login, $key, $type = 'rest') { |
|
| 58 | - $this->login = $login; |
|
| 59 | - $this->key = $key; |
|
| 60 | - if (!isset($GLOBALS['HTTP_RAW_POST_DATA'])) |
|
| 61 | - $GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents('php://input'); |
|
| 62 | - //if ($api_type == 'xml') { |
|
| 63 | - include_once('XML/RPC2/Client.php'); |
|
| 64 | - $this->xml_options['prefix'] = $this->prefix; |
|
| 65 | - $this->xml_options['encoding'] = $this->encoding; |
|
| 66 | - $this->xml_options['sslverify'] = $this->sslverify; |
|
| 67 | - $this->xml_client = \XML_RPC2_Client::create($this->xml_url, $this->xml_options); |
|
| 68 | - //} elseif ($this->api_type == 'rest') { |
|
| 69 | - //$this->rest_options[CURLOPT_SSL_VERIFYHOST] = $this->sslverify; |
|
| 70 | - //} |
|
| 71 | - } |
|
| 50 | + /** |
|
| 51 | + * Cloudlinux::__construct() |
|
| 52 | + * |
|
| 53 | + * @param string $login API Login Name |
|
| 54 | + * @param string $key API Key |
|
| 55 | + * @param string $type API type to use, can be 'rest' or 'xml' |
|
| 56 | + */ |
|
| 57 | + public function __construct($login, $key, $type = 'rest') { |
|
| 58 | + $this->login = $login; |
|
| 59 | + $this->key = $key; |
|
| 60 | + if (!isset($GLOBALS['HTTP_RAW_POST_DATA'])) |
|
| 61 | + $GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents('php://input'); |
|
| 62 | + //if ($api_type == 'xml') { |
|
| 63 | + include_once('XML/RPC2/Client.php'); |
|
| 64 | + $this->xml_options['prefix'] = $this->prefix; |
|
| 65 | + $this->xml_options['encoding'] = $this->encoding; |
|
| 66 | + $this->xml_options['sslverify'] = $this->sslverify; |
|
| 67 | + $this->xml_client = \XML_RPC2_Client::create($this->xml_url, $this->xml_options); |
|
| 68 | + //} elseif ($this->api_type == 'rest') { |
|
| 69 | + //$this->rest_options[CURLOPT_SSL_VERIFYHOST] = $this->sslverify; |
|
| 70 | + //} |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * getcurlpage() |
|
| 75 | - * gets a webpage via curl and returns the response. |
|
| 76 | - * also it sets a mozilla type agent. |
|
| 77 | - * @param string $url the url of the page you want |
|
| 78 | - * @param string $postfields postfields in the format of "v1=10&v2=20&v3=30" |
|
| 79 | - * @param string $options |
|
| 80 | - * @return string the webpage |
|
| 81 | - */ |
|
| 82 | - public function getcurlpage($url, $postfields = '', $options = '') { |
|
| 83 | - //myadmin_log('myadmin', 'info', "Get Url Page $url", __LINE__, __FILE__); |
|
| 84 | - $agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2790.0 Safari/537.36'; |
|
| 85 | - $ch = curl_init($url); |
|
| 86 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
| 87 | - curl_setopt($ch, CURLOPT_USERAGENT, $agent); |
|
| 88 | - if (is_array($postfields) || $postfields != '') { |
|
| 89 | - if (is_array($postfields)) { |
|
| 90 | - $postdata = []; |
|
| 91 | - foreach ($postfields as $field => $value) { |
|
| 92 | - $postdata[] = $field . '=' . urlencode($value); |
|
| 93 | - } |
|
| 94 | - curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $postdata)); |
|
| 95 | - } else { |
|
| 96 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - if (is_array($options) && sizeof($options) > 0) { |
|
| 100 | - foreach ($options as $key => $value) { |
|
| 101 | - curl_setopt($ch, $key, $value); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - $tmp = curl_exec($ch); |
|
| 105 | - curl_close($ch); |
|
| 106 | - $ret = $tmp; |
|
| 107 | - return $ret; |
|
| 108 | - } |
|
| 73 | + /** |
|
| 74 | + * getcurlpage() |
|
| 75 | + * gets a webpage via curl and returns the response. |
|
| 76 | + * also it sets a mozilla type agent. |
|
| 77 | + * @param string $url the url of the page you want |
|
| 78 | + * @param string $postfields postfields in the format of "v1=10&v2=20&v3=30" |
|
| 79 | + * @param string $options |
|
| 80 | + * @return string the webpage |
|
| 81 | + */ |
|
| 82 | + public function getcurlpage($url, $postfields = '', $options = '') { |
|
| 83 | + //myadmin_log('myadmin', 'info', "Get Url Page $url", __LINE__, __FILE__); |
|
| 84 | + $agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2790.0 Safari/537.36'; |
|
| 85 | + $ch = curl_init($url); |
|
| 86 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
| 87 | + curl_setopt($ch, CURLOPT_USERAGENT, $agent); |
|
| 88 | + if (is_array($postfields) || $postfields != '') { |
|
| 89 | + if (is_array($postfields)) { |
|
| 90 | + $postdata = []; |
|
| 91 | + foreach ($postfields as $field => $value) { |
|
| 92 | + $postdata[] = $field . '=' . urlencode($value); |
|
| 93 | + } |
|
| 94 | + curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $postdata)); |
|
| 95 | + } else { |
|
| 96 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + if (is_array($options) && sizeof($options) > 0) { |
|
| 100 | + foreach ($options as $key => $value) { |
|
| 101 | + curl_setopt($ch, $key, $value); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + $tmp = curl_exec($ch); |
|
| 105 | + curl_close($ch); |
|
| 106 | + $ret = $tmp; |
|
| 107 | + return $ret; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - public function log($level, $text, $line = '', $file = '') { |
|
| 111 | - if (function_exists('myadmin_log')) |
|
| 112 | - myadmin_log('cloudlinux', $level, $text, $line, $file); |
|
| 113 | - else |
|
| 114 | - error_log($text); |
|
| 115 | - } |
|
| 110 | + public function log($level, $text, $line = '', $file = '') { |
|
| 111 | + if (function_exists('myadmin_log')) |
|
| 112 | + myadmin_log('cloudlinux', $level, $text, $line, $file); |
|
| 113 | + else |
|
| 114 | + error_log($text); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Return system information about several Cloudlinux services |
|
| 119 | - * |
|
| 120 | - * @return array array of system information |
|
| 121 | - */ |
|
| 122 | - public function status() { |
|
| 123 | - $this->response = $this->getcurlpage($this->rest_url.'status.json', '', $this->rest_options); |
|
| 124 | - return json_decode($this->response, true); |
|
| 125 | - } |
|
| 117 | + /** |
|
| 118 | + * Return system information about several Cloudlinux services |
|
| 119 | + * |
|
| 120 | + * @return array array of system information |
|
| 121 | + */ |
|
| 122 | + public function status() { |
|
| 123 | + $this->response = $this->getcurlpage($this->rest_url.'status.json', '', $this->rest_options); |
|
| 124 | + return json_decode($this->response, true); |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - /** |
|
| 128 | - * Will return information about what kind of license types are available for registration and what types are already used by current account. |
|
| 129 | - * @param string $ip ip address to check |
|
| 130 | - * @return array returns an array with available(int[]) Â list of types that can be used to register new IP license, and owned(int[]) Â list of types that already registered(owned) by this account |
|
| 131 | - */ |
|
| 132 | - public function availability($ip) { |
|
| 133 | - $this->response = $this->getcurlpage($this->rest_url.'ipl/availability.json?ip='.$ip.'&token='.$this->authToken(), '', $this->rest_options); |
|
| 134 | - return json_decode($this->response, true); |
|
| 135 | - } |
|
| 127 | + /** |
|
| 128 | + * Will return information about what kind of license types are available for registration and what types are already used by current account. |
|
| 129 | + * @param string $ip ip address to check |
|
| 130 | + * @return array returns an array with available(int[]) Â list of types that can be used to register new IP license, and owned(int[]) Â list of types that already registered(owned) by this account |
|
| 131 | + */ |
|
| 132 | + public function availability($ip) { |
|
| 133 | + $this->response = $this->getcurlpage($this->rest_url.'ipl/availability.json?ip='.$ip.'&token='.$this->authToken(), '', $this->rest_options); |
|
| 134 | + return json_decode($this->response, true); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * Check if IP license is registered by any customer. |
|
| 139 | - * |
|
| 140 | - * @param string $ip ip address to check |
|
| 141 | - * @return array Will return list of registered license types or empty list if provided IP is not registered yet. |
|
| 142 | - */ |
|
| 143 | - public function check($ip) { |
|
| 144 | - $this->response = $this->getcurlpage($this->rest_url.'ipl/check.json?ip='.$ip.'&token='.$this->authToken(), '', $this->rest_options); |
|
| 145 | - $response = json_decode($this->response, true); |
|
| 146 | - if ($response['success'] == 1) |
|
| 147 | - return $response['data']; |
|
| 148 | - else |
|
| 149 | - return false; |
|
| 150 | - } |
|
| 137 | + /** |
|
| 138 | + * Check if IP license is registered by any customer. |
|
| 139 | + * |
|
| 140 | + * @param string $ip ip address to check |
|
| 141 | + * @return array Will return list of registered license types or empty list if provided IP is not registered yet. |
|
| 142 | + */ |
|
| 143 | + public function check($ip) { |
|
| 144 | + $this->response = $this->getcurlpage($this->rest_url.'ipl/check.json?ip='.$ip.'&token='.$this->authToken(), '', $this->rest_options); |
|
| 145 | + $response = json_decode($this->response, true); |
|
| 146 | + if ($response['success'] == 1) |
|
| 147 | + return $response['data']; |
|
| 148 | + else |
|
| 149 | + return false; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * Will register IP based license for authorized user. |
|
| 154 | - * |
|
| 155 | - * @param string $ip ip address to registger |
|
| 156 | - * @param int $type IP license type (1,2 or 16) |
|
| 157 | - * @return array On success response returns information about created or already registered license. ip(string) type(int) Â license type (1,2,16) registered(boolean) Â true if server was registered in CLN with this license (CLN licenses only). created(string) Â license creation time |
|
| 158 | - */ |
|
| 159 | - public function register($ip, $type) { |
|
| 160 | - $this->response = $this->getcurlpage($this->rest_url.'ipl/register.json?ip='.$ip.'&type='.$type.'&token='.$this->authToken(), '', $this->rest_options); |
|
| 161 | - return json_decode($this->response, true); |
|
| 162 | - } |
|
| 152 | + /** |
|
| 153 | + * Will register IP based license for authorized user. |
|
| 154 | + * |
|
| 155 | + * @param string $ip ip address to registger |
|
| 156 | + * @param int $type IP license type (1,2 or 16) |
|
| 157 | + * @return array On success response returns information about created or already registered license. ip(string) type(int) Â license type (1,2,16) registered(boolean) Â true if server was registered in CLN with this license (CLN licenses only). created(string) Â license creation time |
|
| 158 | + */ |
|
| 159 | + public function register($ip, $type) { |
|
| 160 | + $this->response = $this->getcurlpage($this->rest_url.'ipl/register.json?ip='.$ip.'&type='.$type.'&token='.$this->authToken(), '', $this->rest_options); |
|
| 161 | + return json_decode($this->response, true); |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - /** |
|
| 165 | - * Will remove IP based license from authorized user licenses. |
|
| 166 | - * |
|
| 167 | - * @param string $ip ip address to remove licenses on |
|
| 168 | - * @param int $type optional license type. If empty, will remove licenses with all types |
|
| 169 | - * @return bool |
|
| 170 | - */ |
|
| 171 | - public function rest_remove($ip, $type = 0) { |
|
| 172 | - if ($type != 0) |
|
| 173 | - $this->response = $this->getcurlpage($this->rest_url.'ipl/remove.json?ip='.$ip.'&type='.$type.'&token='.$this->authToken(), '', $this->rest_options); |
|
| 174 | - else |
|
| 175 | - $this->response = $this->getcurlpage($this->rest_url.'ipl/remove.json?ip='.$ip.'&token='.$this->authToken(), '', $this->rest_options); |
|
| 176 | - return json_decode($this->response, true); |
|
| 177 | - } |
|
| 164 | + /** |
|
| 165 | + * Will remove IP based license from authorized user licenses. |
|
| 166 | + * |
|
| 167 | + * @param string $ip ip address to remove licenses on |
|
| 168 | + * @param int $type optional license type. If empty, will remove licenses with all types |
|
| 169 | + * @return bool |
|
| 170 | + */ |
|
| 171 | + public function rest_remove($ip, $type = 0) { |
|
| 172 | + if ($type != 0) |
|
| 173 | + $this->response = $this->getcurlpage($this->rest_url.'ipl/remove.json?ip='.$ip.'&type='.$type.'&token='.$this->authToken(), '', $this->rest_options); |
|
| 174 | + else |
|
| 175 | + $this->response = $this->getcurlpage($this->rest_url.'ipl/remove.json?ip='.$ip.'&token='.$this->authToken(), '', $this->rest_options); |
|
| 176 | + return json_decode($this->response, true); |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - /** |
|
| 180 | - * Will remove IP based license from authorized user licenses. |
|
| 181 | - * |
|
| 182 | - * @param string $ip ip address to remove licenses on |
|
| 183 | - * @param int $type optional license type. If empty or 0, will remove licenses with all types |
|
| 184 | - * @return bool |
|
| 185 | - */ |
|
| 186 | - public function remove($ip, $type = 0) { |
|
| 187 | - if ($this->api_type == 'xml') |
|
| 188 | - return $this->remove_license($ip, $type); |
|
| 189 | - else |
|
| 190 | - return $this->rest_remove($ip, $type); |
|
| 191 | - } |
|
| 179 | + /** |
|
| 180 | + * Will remove IP based license from authorized user licenses. |
|
| 181 | + * |
|
| 182 | + * @param string $ip ip address to remove licenses on |
|
| 183 | + * @param int $type optional license type. If empty or 0, will remove licenses with all types |
|
| 184 | + * @return bool |
|
| 185 | + */ |
|
| 186 | + public function remove($ip, $type = 0) { |
|
| 187 | + if ($this->api_type == 'xml') |
|
| 188 | + return $this->remove_license($ip, $type); |
|
| 189 | + else |
|
| 190 | + return $this->rest_remove($ip, $type); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - /** |
|
| 194 | - * Return all IP licenses owned by authorized user. |
|
| 195 | - * |
|
| 196 | - * @return array an array of licenses each one containing these fields: ip(string) ype(int) Â license type (1,2,16) registered(boolean) Â true if server was registered in CLN with this license (CLN licenses only). created(string) Â license creation time |
|
| 197 | - */ |
|
| 198 | - public function rest_list() { |
|
| 199 | - $this->response = $this->getcurlpage($this->rest_url.'ipl/list.json?token='.$this->authToken(), '', $this->rest_options); |
|
| 200 | - return json_decode($this->response, true); |
|
| 201 | - } |
|
| 193 | + /** |
|
| 194 | + * Return all IP licenses owned by authorized user. |
|
| 195 | + * |
|
| 196 | + * @return array an array of licenses each one containing these fields: ip(string) ype(int) Â license type (1,2,16) registered(boolean) Â true if server was registered in CLN with this license (CLN licenses only). created(string) Â license creation time |
|
| 197 | + */ |
|
| 198 | + public function rest_list() { |
|
| 199 | + $this->response = $this->getcurlpage($this->rest_url.'ipl/list.json?token='.$this->authToken(), '', $this->rest_options); |
|
| 200 | + return json_decode($this->response, true); |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - /** |
|
| 204 | - * automatic authToken generator |
|
| 205 | - * |
|
| 206 | - * @return string the authToken |
|
| 207 | - */ |
|
| 208 | - public function authToken() { |
|
| 209 | - $time = time(); |
|
| 210 | - try { |
|
| 211 | - return $this->login . '|' . $time . '|' . sha1($this->key . $time); |
|
| 212 | - } catch (Exception $e) { |
|
| 213 | - $this->log('error', 'Caught exception code: ' . $e->getCode()); |
|
| 214 | - $this->log('error', 'Caught exception message: ' . $e->getMessage()); |
|
| 215 | - return false; |
|
| 216 | - } |
|
| 217 | - } |
|
| 203 | + /** |
|
| 204 | + * automatic authToken generator |
|
| 205 | + * |
|
| 206 | + * @return string the authToken |
|
| 207 | + */ |
|
| 208 | + public function authToken() { |
|
| 209 | + $time = time(); |
|
| 210 | + try { |
|
| 211 | + return $this->login . '|' . $time . '|' . sha1($this->key . $time); |
|
| 212 | + } catch (Exception $e) { |
|
| 213 | + $this->log('error', 'Caught exception code: ' . $e->getCode()); |
|
| 214 | + $this->log('error', 'Caught exception message: ' . $e->getMessage()); |
|
| 215 | + return false; |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - /** |
|
| 220 | - * Register new IP license. |
|
| 221 | - * |
|
| 222 | - * @param string $ip IP Address |
|
| 223 | - * @param integer $type license type (1,2 or 16) |
|
| 224 | - * @throws XmlRpcException for critical errors |
|
| 225 | - * @return integer 0 on success, -1 on error |
|
| 226 | - */ |
|
| 227 | - public function license($ip, $type) { |
|
| 228 | - $type = (int)$type; |
|
| 229 | - try { |
|
| 230 | - $this->log('error', 'Calling License(' . $this->authToken() . ',' . $ip . ',' . $type . ')'); |
|
| 231 | - $this->response = $this->xml_client->license($this->authToken(), $ip, $type); |
|
| 232 | - $this->log('error', 'Response: ' . var_export($this->response, true)); |
|
| 233 | - return $this->response; |
|
| 234 | - } catch (Exception $e) { |
|
| 235 | - $this->log('error', 'Caught exception code: ' . $e->getCode()); |
|
| 236 | - $this->log('error', 'Caught exception message: ' . $e->getMessage()); |
|
| 237 | - return false; |
|
| 238 | - } |
|
| 239 | - } |
|
| 219 | + /** |
|
| 220 | + * Register new IP license. |
|
| 221 | + * |
|
| 222 | + * @param string $ip IP Address |
|
| 223 | + * @param integer $type license type (1,2 or 16) |
|
| 224 | + * @throws XmlRpcException for critical errors |
|
| 225 | + * @return integer 0 on success, -1 on error |
|
| 226 | + */ |
|
| 227 | + public function license($ip, $type) { |
|
| 228 | + $type = (int)$type; |
|
| 229 | + try { |
|
| 230 | + $this->log('error', 'Calling License(' . $this->authToken() . ',' . $ip . ',' . $type . ')'); |
|
| 231 | + $this->response = $this->xml_client->license($this->authToken(), $ip, $type); |
|
| 232 | + $this->log('error', 'Response: ' . var_export($this->response, true)); |
|
| 233 | + return $this->response; |
|
| 234 | + } catch (Exception $e) { |
|
| 235 | + $this->log('error', 'Caught exception code: ' . $e->getCode()); |
|
| 236 | + $this->log('error', 'Caught exception message: ' . $e->getMessage()); |
|
| 237 | + return false; |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | - /** |
|
| 242 | - * Remove IP licenses with specified type for customer. Also unÂregisters from CLN server associated with IP. |
|
| 243 | - * or |
|
| 244 | - * Remove IP licenses with specified type for customer. Also unÂregisters from CLN server associated with IP. |
|
| 245 | - * @param string $ip ip address to remove |
|
| 246 | - * @param bool|false|int $type optional parameter to specify the type of license to remove (1,2, or 16) |
|
| 247 | - * @return integer 0 on success, -1 on error, Error will be returned also if account have no licenses for provided IP. |
|
| 248 | - */ |
|
| 249 | - public function remove_license($ip, $type = false) { |
|
| 250 | - $this->log('info', "Calling CLoudLinux->xml_client->remove_license({$this->authToken()}, {$ip}, {$type})", __LINE__, __FILE__); |
|
| 251 | - try { |
|
| 252 | - if ($type === false) |
|
| 253 | - return $this->response = $this->remove($ip); |
|
| 254 | - else |
|
| 255 | - return $this->response = $this->remove($ip, $type); |
|
| 256 | - } catch (Exception $e) { |
|
| 257 | - $this->log('error', 'Caught exception code: ' . $e->getCode()); |
|
| 258 | - $this->log('error', 'Caught exception message: ' . $e->getMessage()); |
|
| 259 | - return false; |
|
| 260 | - } |
|
| 261 | - } |
|
| 241 | + /** |
|
| 242 | + * Remove IP licenses with specified type for customer. Also unÂregisters from CLN server associated with IP. |
|
| 243 | + * or |
|
| 244 | + * Remove IP licenses with specified type for customer. Also unÂregisters from CLN server associated with IP. |
|
| 245 | + * @param string $ip ip address to remove |
|
| 246 | + * @param bool|false|int $type optional parameter to specify the type of license to remove (1,2, or 16) |
|
| 247 | + * @return integer 0 on success, -1 on error, Error will be returned also if account have no licenses for provided IP. |
|
| 248 | + */ |
|
| 249 | + public function remove_license($ip, $type = false) { |
|
| 250 | + $this->log('info', "Calling CLoudLinux->xml_client->remove_license({$this->authToken()}, {$ip}, {$type})", __LINE__, __FILE__); |
|
| 251 | + try { |
|
| 252 | + if ($type === false) |
|
| 253 | + return $this->response = $this->remove($ip); |
|
| 254 | + else |
|
| 255 | + return $this->response = $this->remove($ip, $type); |
|
| 256 | + } catch (Exception $e) { |
|
| 257 | + $this->log('error', 'Caught exception code: ' . $e->getCode()); |
|
| 258 | + $this->log('error', 'Caught exception message: ' . $e->getMessage()); |
|
| 259 | + return false; |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - /** |
|
| 264 | - * Check if IP license was registered by any customer. Arguments: |
|
| 265 | - * |
|
| 266 | - * @param string $ip ip address to remove |
|
| 267 | - * @param bool $checkAll True will search for any type of license. False  only for types 1 or 2 |
|
| 268 | - * @throws XmlRpcException for critical errors |
|
| 269 | - * @return array (list<int>): List of registered license types or empty list if no license found |
|
| 270 | - */ |
|
| 271 | - public function is_licensed($ip, $checkAll = true) { |
|
| 272 | - if ($this->api_type == 'xml') |
|
| 273 | - return $this->xml_is_licensed($ip, $checkAll); |
|
| 274 | - else |
|
| 275 | - return $this->check($ip, $checkAll); |
|
| 276 | - } |
|
| 277 | - /** |
|
| 278 | - * Check if IP license was registered by any customer. Arguments: |
|
| 279 | - * |
|
| 280 | - * @param string $ip ip address to remove |
|
| 281 | - * @param bool $checkAll True will search for any type of license. False  only for types 1 or 2 |
|
| 282 | - * @throws XmlRpcException for critical errors |
|
| 283 | - * @return array (list<int>): List of registered license types or empty list if no license found |
|
| 284 | - */ |
|
| 285 | - public function xml_is_licensed($ip, $checkAll = true) { |
|
| 286 | - try { |
|
| 287 | - return $this->response = $this->xml_client->is_licensed($this->authToken(), $ip, $checkAll); |
|
| 288 | - } catch (Exception $e) { |
|
| 289 | - $this->log('error', 'Caught exception code: ' . $e->getCode()); |
|
| 290 | - $this->log('error', 'Caught exception message: ' . $e->getMessage()); |
|
| 291 | - return false; |
|
| 292 | - } |
|
| 293 | - } |
|
| 263 | + /** |
|
| 264 | + * Check if IP license was registered by any customer. Arguments: |
|
| 265 | + * |
|
| 266 | + * @param string $ip ip address to remove |
|
| 267 | + * @param bool $checkAll True will search for any type of license. False  only for types 1 or 2 |
|
| 268 | + * @throws XmlRpcException for critical errors |
|
| 269 | + * @return array (list<int>): List of registered license types or empty list if no license found |
|
| 270 | + */ |
|
| 271 | + public function is_licensed($ip, $checkAll = true) { |
|
| 272 | + if ($this->api_type == 'xml') |
|
| 273 | + return $this->xml_is_licensed($ip, $checkAll); |
|
| 274 | + else |
|
| 275 | + return $this->check($ip, $checkAll); |
|
| 276 | + } |
|
| 277 | + /** |
|
| 278 | + * Check if IP license was registered by any customer. Arguments: |
|
| 279 | + * |
|
| 280 | + * @param string $ip ip address to remove |
|
| 281 | + * @param bool $checkAll True will search for any type of license. False  only for types 1 or 2 |
|
| 282 | + * @throws XmlRpcException for critical errors |
|
| 283 | + * @return array (list<int>): List of registered license types or empty list if no license found |
|
| 284 | + */ |
|
| 285 | + public function xml_is_licensed($ip, $checkAll = true) { |
|
| 286 | + try { |
|
| 287 | + return $this->response = $this->xml_client->is_licensed($this->authToken(), $ip, $checkAll); |
|
| 288 | + } catch (Exception $e) { |
|
| 289 | + $this->log('error', 'Caught exception code: ' . $e->getCode()); |
|
| 290 | + $this->log('error', 'Caught exception message: ' . $e->getMessage()); |
|
| 291 | + return false; |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | 294 | |
| 295 | - /** |
|
| 296 | - * @return bool|mixed |
|
| 297 | - */ |
|
| 298 | - public function license_list() { |
|
| 299 | - try { |
|
| 300 | - return json_decode($this->getcurlpage($this->rest_url.'ipl/list.json?token=' . $this->authToken())); |
|
| 301 | - } catch (Exception $e) { |
|
| 302 | - $this->log('error', 'Caught exception code: ' . $e->getCode()); |
|
| 303 | - $this->log('error', 'Caught exception message: ' . $e->getMessage()); |
|
| 304 | - return false; |
|
| 305 | - } |
|
| 306 | - } |
|
| 295 | + /** |
|
| 296 | + * @return bool|mixed |
|
| 297 | + */ |
|
| 298 | + public function license_list() { |
|
| 299 | + try { |
|
| 300 | + return json_decode($this->getcurlpage($this->rest_url.'ipl/list.json?token=' . $this->authToken())); |
|
| 301 | + } catch (Exception $e) { |
|
| 302 | + $this->log('error', 'Caught exception code: ' . $e->getCode()); |
|
| 303 | + $this->log('error', 'Caught exception message: ' . $e->getMessage()); |
|
| 304 | + return false; |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | - /** |
|
| 309 | - * Return list of all IP licenses owned by authorized user |
|
| 310 | - * |
|
| 311 | - * @throws XmlRpcException for critical errors |
|
| 312 | - * @return array (list<structure>): List of structures or empty list. Each structure contains keys: |
|
| 313 | - * IP(string) |
|
| 314 | - * TYPE(int) Â license type |
|
| 315 | - * REGISTERED(boolean) Â True if server was registered in CLN with this license |
|
| 316 | - */ |
|
| 317 | - public function reconcile() { |
|
| 318 | - try { |
|
| 319 | - return $this->response = $this->xml_client->reconcile($this->authToken()); |
|
| 320 | - } catch (Exception $e) { |
|
| 321 | - $this->log('error', 'Caught exception code: ' . $e->getCode()); |
|
| 322 | - $this->log('error', 'Caught exception message: ' . $e->getMessage()); |
|
| 323 | - return false; |
|
| 324 | - } |
|
| 325 | - } |
|
| 308 | + /** |
|
| 309 | + * Return list of all IP licenses owned by authorized user |
|
| 310 | + * |
|
| 311 | + * @throws XmlRpcException for critical errors |
|
| 312 | + * @return array (list<structure>): List of structures or empty list. Each structure contains keys: |
|
| 313 | + * IP(string) |
|
| 314 | + * TYPE(int) Â license type |
|
| 315 | + * REGISTERED(boolean) Â True if server was registered in CLN with this license |
|
| 316 | + */ |
|
| 317 | + public function reconcile() { |
|
| 318 | + try { |
|
| 319 | + return $this->response = $this->xml_client->reconcile($this->authToken()); |
|
| 320 | + } catch (Exception $e) { |
|
| 321 | + $this->log('error', 'Caught exception code: ' . $e->getCode()); |
|
| 322 | + $this->log('error', 'Caught exception message: ' . $e->getMessage()); |
|
| 323 | + return false; |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | 326 | |
| 327 | - /* |
|
| 327 | + /* |
|
| 328 | 328 | public function getKeyInfo($Key) { |
| 329 | 329 | $this->response = $this->xml->__call('partner10.getKeyInfo', array( |
| 330 | 330 | $this->AuthInfo(), |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | if (is_array($postfields)) { |
| 90 | 90 | $postdata = []; |
| 91 | 91 | foreach ($postfields as $field => $value) { |
| 92 | - $postdata[] = $field . '=' . urlencode($value); |
|
| 92 | + $postdata[] = $field.'='.urlencode($value); |
|
| 93 | 93 | } |
| 94 | 94 | curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $postdata)); |
| 95 | 95 | } else { |
@@ -208,10 +208,10 @@ discard block |
||
| 208 | 208 | public function authToken() { |
| 209 | 209 | $time = time(); |
| 210 | 210 | try { |
| 211 | - return $this->login . '|' . $time . '|' . sha1($this->key . $time); |
|
| 211 | + return $this->login.'|'.$time.'|'.sha1($this->key.$time); |
|
| 212 | 212 | } catch (Exception $e) { |
| 213 | - $this->log('error', 'Caught exception code: ' . $e->getCode()); |
|
| 214 | - $this->log('error', 'Caught exception message: ' . $e->getMessage()); |
|
| 213 | + $this->log('error', 'Caught exception code: '.$e->getCode()); |
|
| 214 | + $this->log('error', 'Caught exception message: '.$e->getMessage()); |
|
| 215 | 215 | return false; |
| 216 | 216 | } |
| 217 | 217 | } |
@@ -225,15 +225,15 @@ discard block |
||
| 225 | 225 | * @return integer 0 on success, -1 on error |
| 226 | 226 | */ |
| 227 | 227 | public function license($ip, $type) { |
| 228 | - $type = (int)$type; |
|
| 228 | + $type = (int) $type; |
|
| 229 | 229 | try { |
| 230 | - $this->log('error', 'Calling License(' . $this->authToken() . ',' . $ip . ',' . $type . ')'); |
|
| 230 | + $this->log('error', 'Calling License('.$this->authToken().','.$ip.','.$type.')'); |
|
| 231 | 231 | $this->response = $this->xml_client->license($this->authToken(), $ip, $type); |
| 232 | - $this->log('error', 'Response: ' . var_export($this->response, true)); |
|
| 232 | + $this->log('error', 'Response: '.var_export($this->response, true)); |
|
| 233 | 233 | return $this->response; |
| 234 | 234 | } catch (Exception $e) { |
| 235 | - $this->log('error', 'Caught exception code: ' . $e->getCode()); |
|
| 236 | - $this->log('error', 'Caught exception message: ' . $e->getMessage()); |
|
| 235 | + $this->log('error', 'Caught exception code: '.$e->getCode()); |
|
| 236 | + $this->log('error', 'Caught exception message: '.$e->getMessage()); |
|
| 237 | 237 | return false; |
| 238 | 238 | } |
| 239 | 239 | } |
@@ -254,8 +254,8 @@ discard block |
||
| 254 | 254 | else |
| 255 | 255 | return $this->response = $this->remove($ip, $type); |
| 256 | 256 | } catch (Exception $e) { |
| 257 | - $this->log('error', 'Caught exception code: ' . $e->getCode()); |
|
| 258 | - $this->log('error', 'Caught exception message: ' . $e->getMessage()); |
|
| 257 | + $this->log('error', 'Caught exception code: '.$e->getCode()); |
|
| 258 | + $this->log('error', 'Caught exception message: '.$e->getMessage()); |
|
| 259 | 259 | return false; |
| 260 | 260 | } |
| 261 | 261 | } |
@@ -286,8 +286,8 @@ discard block |
||
| 286 | 286 | try { |
| 287 | 287 | return $this->response = $this->xml_client->is_licensed($this->authToken(), $ip, $checkAll); |
| 288 | 288 | } catch (Exception $e) { |
| 289 | - $this->log('error', 'Caught exception code: ' . $e->getCode()); |
|
| 290 | - $this->log('error', 'Caught exception message: ' . $e->getMessage()); |
|
| 289 | + $this->log('error', 'Caught exception code: '.$e->getCode()); |
|
| 290 | + $this->log('error', 'Caught exception message: '.$e->getMessage()); |
|
| 291 | 291 | return false; |
| 292 | 292 | } |
| 293 | 293 | } |
@@ -297,10 +297,10 @@ discard block |
||
| 297 | 297 | */ |
| 298 | 298 | public function license_list() { |
| 299 | 299 | try { |
| 300 | - return json_decode($this->getcurlpage($this->rest_url.'ipl/list.json?token=' . $this->authToken())); |
|
| 300 | + return json_decode($this->getcurlpage($this->rest_url.'ipl/list.json?token='.$this->authToken())); |
|
| 301 | 301 | } catch (Exception $e) { |
| 302 | - $this->log('error', 'Caught exception code: ' . $e->getCode()); |
|
| 303 | - $this->log('error', 'Caught exception message: ' . $e->getMessage()); |
|
| 302 | + $this->log('error', 'Caught exception code: '.$e->getCode()); |
|
| 303 | + $this->log('error', 'Caught exception message: '.$e->getMessage()); |
|
| 304 | 304 | return false; |
| 305 | 305 | } |
| 306 | 306 | } |
@@ -318,8 +318,8 @@ discard block |
||
| 318 | 318 | try { |
| 319 | 319 | return $this->response = $this->xml_client->reconcile($this->authToken()); |
| 320 | 320 | } catch (Exception $e) { |
| 321 | - $this->log('error', 'Caught exception code: ' . $e->getCode()); |
|
| 322 | - $this->log('error', 'Caught exception message: ' . $e->getMessage()); |
|
| 321 | + $this->log('error', 'Caught exception code: '.$e->getCode()); |
|
| 322 | + $this->log('error', 'Caught exception message: '.$e->getMessage()); |
|
| 323 | 323 | return false; |
| 324 | 324 | } |
| 325 | 325 | } |
@@ -57,8 +57,9 @@ discard block |
||
| 57 | 57 | public function __construct($login, $key, $type = 'rest') { |
| 58 | 58 | $this->login = $login; |
| 59 | 59 | $this->key = $key; |
| 60 | - if (!isset($GLOBALS['HTTP_RAW_POST_DATA'])) |
|
| 61 | - $GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents('php://input'); |
|
| 60 | + if (!isset($GLOBALS['HTTP_RAW_POST_DATA'])) { |
|
| 61 | + $GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents('php://input'); |
|
| 62 | + } |
|
| 62 | 63 | //if ($api_type == 'xml') { |
| 63 | 64 | include_once('XML/RPC2/Client.php'); |
| 64 | 65 | $this->xml_options['prefix'] = $this->prefix; |
@@ -108,10 +109,11 @@ discard block |
||
| 108 | 109 | } |
| 109 | 110 | |
| 110 | 111 | public function log($level, $text, $line = '', $file = '') { |
| 111 | - if (function_exists('myadmin_log')) |
|
| 112 | - myadmin_log('cloudlinux', $level, $text, $line, $file); |
|
| 113 | - else |
|
| 114 | - error_log($text); |
|
| 112 | + if (function_exists('myadmin_log')) { |
|
| 113 | + myadmin_log('cloudlinux', $level, $text, $line, $file); |
|
| 114 | + } else { |
|
| 115 | + error_log($text); |
|
| 116 | + } |
|
| 115 | 117 | } |
| 116 | 118 | |
| 117 | 119 | /** |
@@ -143,10 +145,11 @@ discard block |
||
| 143 | 145 | public function check($ip) { |
| 144 | 146 | $this->response = $this->getcurlpage($this->rest_url.'ipl/check.json?ip='.$ip.'&token='.$this->authToken(), '', $this->rest_options); |
| 145 | 147 | $response = json_decode($this->response, true); |
| 146 | - if ($response['success'] == 1) |
|
| 147 | - return $response['data']; |
|
| 148 | - else |
|
| 149 | - return false; |
|
| 148 | + if ($response['success'] == 1) { |
|
| 149 | + return $response['data']; |
|
| 150 | + } else { |
|
| 151 | + return false; |
|
| 152 | + } |
|
| 150 | 153 | } |
| 151 | 154 | |
| 152 | 155 | /** |
@@ -169,10 +172,11 @@ discard block |
||
| 169 | 172 | * @return bool |
| 170 | 173 | */ |
| 171 | 174 | public function rest_remove($ip, $type = 0) { |
| 172 | - if ($type != 0) |
|
| 173 | - $this->response = $this->getcurlpage($this->rest_url.'ipl/remove.json?ip='.$ip.'&type='.$type.'&token='.$this->authToken(), '', $this->rest_options); |
|
| 174 | - else |
|
| 175 | - $this->response = $this->getcurlpage($this->rest_url.'ipl/remove.json?ip='.$ip.'&token='.$this->authToken(), '', $this->rest_options); |
|
| 175 | + if ($type != 0) { |
|
| 176 | + $this->response = $this->getcurlpage($this->rest_url.'ipl/remove.json?ip='.$ip.'&type='.$type.'&token='.$this->authToken(), '', $this->rest_options); |
|
| 177 | + } else { |
|
| 178 | + $this->response = $this->getcurlpage($this->rest_url.'ipl/remove.json?ip='.$ip.'&token='.$this->authToken(), '', $this->rest_options); |
|
| 179 | + } |
|
| 176 | 180 | return json_decode($this->response, true); |
| 177 | 181 | } |
| 178 | 182 | |
@@ -184,10 +188,11 @@ discard block |
||
| 184 | 188 | * @return bool |
| 185 | 189 | */ |
| 186 | 190 | public function remove($ip, $type = 0) { |
| 187 | - if ($this->api_type == 'xml') |
|
| 188 | - return $this->remove_license($ip, $type); |
|
| 189 | - else |
|
| 190 | - return $this->rest_remove($ip, $type); |
|
| 191 | + if ($this->api_type == 'xml') { |
|
| 192 | + return $this->remove_license($ip, $type); |
|
| 193 | + } else { |
|
| 194 | + return $this->rest_remove($ip, $type); |
|
| 195 | + } |
|
| 191 | 196 | } |
| 192 | 197 | |
| 193 | 198 | /** |
@@ -249,10 +254,11 @@ discard block |
||
| 249 | 254 | public function remove_license($ip, $type = false) { |
| 250 | 255 | $this->log('info', "Calling CLoudLinux->xml_client->remove_license({$this->authToken()}, {$ip}, {$type})", __LINE__, __FILE__); |
| 251 | 256 | try { |
| 252 | - if ($type === false) |
|
| 253 | - return $this->response = $this->remove($ip); |
|
| 254 | - else |
|
| 255 | - return $this->response = $this->remove($ip, $type); |
|
| 257 | + if ($type === false) { |
|
| 258 | + return $this->response = $this->remove($ip); |
|
| 259 | + } else { |
|
| 260 | + return $this->response = $this->remove($ip, $type); |
|
| 261 | + } |
|
| 256 | 262 | } catch (Exception $e) { |
| 257 | 263 | $this->log('error', 'Caught exception code: ' . $e->getCode()); |
| 258 | 264 | $this->log('error', 'Caught exception message: ' . $e->getMessage()); |
@@ -269,10 +275,11 @@ discard block |
||
| 269 | 275 | * @return array (list<int>): List of registered license types or empty list if no license found |
| 270 | 276 | */ |
| 271 | 277 | public function is_licensed($ip, $checkAll = true) { |
| 272 | - if ($this->api_type == 'xml') |
|
| 273 | - return $this->xml_is_licensed($ip, $checkAll); |
|
| 274 | - else |
|
| 275 | - return $this->check($ip, $checkAll); |
|
| 278 | + if ($this->api_type == 'xml') { |
|
| 279 | + return $this->xml_is_licensed($ip, $checkAll); |
|
| 280 | + } else { |
|
| 281 | + return $this->check($ip, $checkAll); |
|
| 282 | + } |
|
| 276 | 283 | } |
| 277 | 284 | /** |
| 278 | 285 | * Check if IP license was registered by any customer. Arguments: |
@@ -1,2 +1,2 @@ |
||
| 1 | 1 | <?php |
| 2 | -require_once(__DIR__ . '/../vendor/autoload.php'); |
|
| 2 | +require_once(__DIR__.'/../vendor/autoload.php'); |
|
@@ -9,213 +9,213 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class CloudlinuxTest extends \PHPUnit_Framework_TestCase |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * @var Cloudlinux |
|
| 14 | - */ |
|
| 15 | - protected $object; |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * Sets up the fixture, for example, opens a network connection. |
|
| 19 | - * This method is called before a test is executed. |
|
| 20 | - */ |
|
| 21 | - protected function setUp() |
|
| 22 | - { |
|
| 23 | - if (file_exists(__DIR__.'/.env')) { |
|
| 24 | - $dotenv = new Dotenv\Dotenv(__DIR__); |
|
| 25 | - $dotenv->load(); |
|
| 26 | - } |
|
| 27 | - $this->object = new Cloudlinux(getenv('CLOUDLINUX_LOGIN'), getenv('CLOUDLINUX_KEY')); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Tears down the fixture, for example, closes a network connection. |
|
| 32 | - * This method is called after a test is executed. |
|
| 33 | - */ |
|
| 34 | - protected function tearDown() |
|
| 35 | - { |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - public function testTestEnvironment() { |
|
| 39 | - $CLOUDLINUX_LOGIN = getenv('CLOUDLINUX_LOGIN'); |
|
| 40 | - $this->assertNotEmpty($CLOUDLINUX_LOGIN, 'No environment variables! Copy .env.example -> .env and fill out your account details.'); |
|
| 41 | - $this->assertInstanceOf('\Detain\Cloudlinux\Cloudlinux', $this->object); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @covers Detain\Cloudlinux\Cloudlinux::getcurlpage |
|
| 46 | - */ |
|
| 47 | - public function testGetcurlpage() |
|
| 48 | - { |
|
| 49 | - $this->assertRegExp('/<html/i', $this->object->getcurlpage('https://cln.cloudlinux.com')); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @covers Detain\Cloudlinux\Cloudlinux::status |
|
| 54 | - */ |
|
| 55 | - public function testStatus() |
|
| 56 | - { |
|
| 57 | - //Array( [success] => 1 [data] => Array([db_rhn_online] => 1 [db_clweb_connected] => 1 [db_clweb_online] => 1 [ip_server_reg] => 1 [xmlrpc] => 1 [rhn_overloaded] => [db_rhn_connected] => 1 ) ) |
|
| 58 | - // Remove the following lines when you implement this test. |
|
| 59 | - $status = $this->object->status(); |
|
| 60 | - $this->assertTrue(is_array($status)); |
|
| 61 | - $this->assertArrayHasKey('success', $status, 'Missing success status in response'); |
|
| 62 | - $this->assertArrayHasKey('data', $status, 'Missing data in response'); |
|
| 63 | - $this->assertEquals($status['data']['ip_server_reg'], 1, 'IP Server is not up'); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @covers Detain\Cloudlinux\Cloudlinux::availability |
|
| 68 | - * @todo Implement testAvailability(). |
|
| 69 | - */ |
|
| 70 | - public function testAvailability() |
|
| 71 | - { |
|
| 72 | - // Remove the following lines when you implement this test. |
|
| 73 | - $this->markTestIncomplete( |
|
| 74 | - 'This test has not been implemented yet.' |
|
| 75 | - ); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @covers Detain\Cloudlinux\Cloudlinux::check |
|
| 80 | - * @todo Implement testCheck(). |
|
| 81 | - */ |
|
| 82 | - public function testCheck() |
|
| 83 | - { |
|
| 84 | - // Remove the following lines when you implement this test. |
|
| 85 | - $this->markTestIncomplete( |
|
| 86 | - 'This test has not been implemented yet.' |
|
| 87 | - ); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @covers Detain\Cloudlinux\Cloudlinux::register |
|
| 92 | - * @todo Implement testRegister(). |
|
| 93 | - */ |
|
| 94 | - public function testRegister() |
|
| 95 | - { |
|
| 96 | - // Remove the following lines when you implement this test. |
|
| 97 | - $this->markTestIncomplete( |
|
| 98 | - 'This test has not been implemented yet.' |
|
| 99 | - ); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @covers Detain\Cloudlinux\Cloudlinux::rest_remove |
|
| 104 | - * @todo Implement testRest_remove(). |
|
| 105 | - */ |
|
| 106 | - public function testRest_remove() |
|
| 107 | - { |
|
| 108 | - // Remove the following lines when you implement this test. |
|
| 109 | - $this->markTestIncomplete( |
|
| 110 | - 'This test has not been implemented yet.' |
|
| 111 | - ); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @covers Detain\Cloudlinux\Cloudlinux::remove |
|
| 116 | - * @todo Implement testRemove(). |
|
| 117 | - */ |
|
| 118 | - public function testRemove() |
|
| 119 | - { |
|
| 120 | - // Remove the following lines when you implement this test. |
|
| 121 | - $this->markTestIncomplete( |
|
| 122 | - 'This test has not been implemented yet.' |
|
| 123 | - ); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @covers Detain\Cloudlinux\Cloudlinux::rest_list |
|
| 128 | - * @todo Implement testRest_list(). |
|
| 129 | - */ |
|
| 130 | - public function testRest_list() |
|
| 131 | - { |
|
| 132 | - // Remove the following lines when you implement this test. |
|
| 133 | - $this->markTestIncomplete( |
|
| 134 | - 'This test has not been implemented yet.' |
|
| 135 | - ); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @covers Detain\Cloudlinux\Cloudlinux::authToken |
|
| 140 | - * @todo Implement testAuthToken(). |
|
| 141 | - */ |
|
| 142 | - public function testAuthToken() |
|
| 143 | - { |
|
| 144 | - // Remove the following lines when you implement this test. |
|
| 145 | - $this->markTestIncomplete( |
|
| 146 | - 'This test has not been implemented yet.' |
|
| 147 | - ); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @covers Detain\Cloudlinux\Cloudlinux::license |
|
| 152 | - * @todo Implement testLicense(). |
|
| 153 | - */ |
|
| 154 | - public function testLicense() |
|
| 155 | - { |
|
| 156 | - // Remove the following lines when you implement this test. |
|
| 157 | - $this->markTestIncomplete( |
|
| 158 | - 'This test has not been implemented yet.' |
|
| 159 | - ); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @covers Detain\Cloudlinux\Cloudlinux::remove_license |
|
| 164 | - * @todo Implement testRemove_license(). |
|
| 165 | - */ |
|
| 166 | - public function testRemove_license() |
|
| 167 | - { |
|
| 168 | - // Remove the following lines when you implement this test. |
|
| 169 | - $this->markTestIncomplete( |
|
| 170 | - 'This test has not been implemented yet.' |
|
| 171 | - ); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * @covers Detain\Cloudlinux\Cloudlinux::is_licensed |
|
| 176 | - * @todo Implement testIs_licensed(). |
|
| 177 | - */ |
|
| 178 | - public function testIs_licensed() |
|
| 179 | - { |
|
| 180 | - // Remove the following lines when you implement this test. |
|
| 181 | - $this->markTestIncomplete( |
|
| 182 | - 'This test has not been implemented yet.' |
|
| 183 | - ); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @covers Detain\Cloudlinux\Cloudlinux::xml_is_licensed |
|
| 188 | - * @todo Implement testXml_is_licensed(). |
|
| 189 | - */ |
|
| 190 | - public function testXml_is_licensed() |
|
| 191 | - { |
|
| 192 | - // Remove the following lines when you implement this test. |
|
| 193 | - $this->markTestIncomplete( |
|
| 194 | - 'This test has not been implemented yet.' |
|
| 195 | - ); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * @covers Detain\Cloudlinux\Cloudlinux::license_list |
|
| 200 | - * @todo Implement testLicense_list(). |
|
| 201 | - */ |
|
| 202 | - public function testLicense_list() |
|
| 203 | - { |
|
| 204 | - // Remove the following lines when you implement this test. |
|
| 205 | - $this->markTestIncomplete( |
|
| 206 | - 'This test has not been implemented yet.' |
|
| 207 | - ); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * @covers Detain\Cloudlinux\Cloudlinux::reconcile |
|
| 212 | - * @todo Implement testReconcile(). |
|
| 213 | - */ |
|
| 214 | - public function testReconcile() |
|
| 215 | - { |
|
| 216 | - // Remove the following lines when you implement this test. |
|
| 217 | - $this->markTestIncomplete( |
|
| 218 | - 'This test has not been implemented yet.' |
|
| 219 | - ); |
|
| 220 | - } |
|
| 12 | + /** |
|
| 13 | + * @var Cloudlinux |
|
| 14 | + */ |
|
| 15 | + protected $object; |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * Sets up the fixture, for example, opens a network connection. |
|
| 19 | + * This method is called before a test is executed. |
|
| 20 | + */ |
|
| 21 | + protected function setUp() |
|
| 22 | + { |
|
| 23 | + if (file_exists(__DIR__.'/.env')) { |
|
| 24 | + $dotenv = new Dotenv\Dotenv(__DIR__); |
|
| 25 | + $dotenv->load(); |
|
| 26 | + } |
|
| 27 | + $this->object = new Cloudlinux(getenv('CLOUDLINUX_LOGIN'), getenv('CLOUDLINUX_KEY')); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Tears down the fixture, for example, closes a network connection. |
|
| 32 | + * This method is called after a test is executed. |
|
| 33 | + */ |
|
| 34 | + protected function tearDown() |
|
| 35 | + { |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + public function testTestEnvironment() { |
|
| 39 | + $CLOUDLINUX_LOGIN = getenv('CLOUDLINUX_LOGIN'); |
|
| 40 | + $this->assertNotEmpty($CLOUDLINUX_LOGIN, 'No environment variables! Copy .env.example -> .env and fill out your account details.'); |
|
| 41 | + $this->assertInstanceOf('\Detain\Cloudlinux\Cloudlinux', $this->object); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @covers Detain\Cloudlinux\Cloudlinux::getcurlpage |
|
| 46 | + */ |
|
| 47 | + public function testGetcurlpage() |
|
| 48 | + { |
|
| 49 | + $this->assertRegExp('/<html/i', $this->object->getcurlpage('https://cln.cloudlinux.com')); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @covers Detain\Cloudlinux\Cloudlinux::status |
|
| 54 | + */ |
|
| 55 | + public function testStatus() |
|
| 56 | + { |
|
| 57 | + //Array( [success] => 1 [data] => Array([db_rhn_online] => 1 [db_clweb_connected] => 1 [db_clweb_online] => 1 [ip_server_reg] => 1 [xmlrpc] => 1 [rhn_overloaded] => [db_rhn_connected] => 1 ) ) |
|
| 58 | + // Remove the following lines when you implement this test. |
|
| 59 | + $status = $this->object->status(); |
|
| 60 | + $this->assertTrue(is_array($status)); |
|
| 61 | + $this->assertArrayHasKey('success', $status, 'Missing success status in response'); |
|
| 62 | + $this->assertArrayHasKey('data', $status, 'Missing data in response'); |
|
| 63 | + $this->assertEquals($status['data']['ip_server_reg'], 1, 'IP Server is not up'); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @covers Detain\Cloudlinux\Cloudlinux::availability |
|
| 68 | + * @todo Implement testAvailability(). |
|
| 69 | + */ |
|
| 70 | + public function testAvailability() |
|
| 71 | + { |
|
| 72 | + // Remove the following lines when you implement this test. |
|
| 73 | + $this->markTestIncomplete( |
|
| 74 | + 'This test has not been implemented yet.' |
|
| 75 | + ); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @covers Detain\Cloudlinux\Cloudlinux::check |
|
| 80 | + * @todo Implement testCheck(). |
|
| 81 | + */ |
|
| 82 | + public function testCheck() |
|
| 83 | + { |
|
| 84 | + // Remove the following lines when you implement this test. |
|
| 85 | + $this->markTestIncomplete( |
|
| 86 | + 'This test has not been implemented yet.' |
|
| 87 | + ); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @covers Detain\Cloudlinux\Cloudlinux::register |
|
| 92 | + * @todo Implement testRegister(). |
|
| 93 | + */ |
|
| 94 | + public function testRegister() |
|
| 95 | + { |
|
| 96 | + // Remove the following lines when you implement this test. |
|
| 97 | + $this->markTestIncomplete( |
|
| 98 | + 'This test has not been implemented yet.' |
|
| 99 | + ); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @covers Detain\Cloudlinux\Cloudlinux::rest_remove |
|
| 104 | + * @todo Implement testRest_remove(). |
|
| 105 | + */ |
|
| 106 | + public function testRest_remove() |
|
| 107 | + { |
|
| 108 | + // Remove the following lines when you implement this test. |
|
| 109 | + $this->markTestIncomplete( |
|
| 110 | + 'This test has not been implemented yet.' |
|
| 111 | + ); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @covers Detain\Cloudlinux\Cloudlinux::remove |
|
| 116 | + * @todo Implement testRemove(). |
|
| 117 | + */ |
|
| 118 | + public function testRemove() |
|
| 119 | + { |
|
| 120 | + // Remove the following lines when you implement this test. |
|
| 121 | + $this->markTestIncomplete( |
|
| 122 | + 'This test has not been implemented yet.' |
|
| 123 | + ); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @covers Detain\Cloudlinux\Cloudlinux::rest_list |
|
| 128 | + * @todo Implement testRest_list(). |
|
| 129 | + */ |
|
| 130 | + public function testRest_list() |
|
| 131 | + { |
|
| 132 | + // Remove the following lines when you implement this test. |
|
| 133 | + $this->markTestIncomplete( |
|
| 134 | + 'This test has not been implemented yet.' |
|
| 135 | + ); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @covers Detain\Cloudlinux\Cloudlinux::authToken |
|
| 140 | + * @todo Implement testAuthToken(). |
|
| 141 | + */ |
|
| 142 | + public function testAuthToken() |
|
| 143 | + { |
|
| 144 | + // Remove the following lines when you implement this test. |
|
| 145 | + $this->markTestIncomplete( |
|
| 146 | + 'This test has not been implemented yet.' |
|
| 147 | + ); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @covers Detain\Cloudlinux\Cloudlinux::license |
|
| 152 | + * @todo Implement testLicense(). |
|
| 153 | + */ |
|
| 154 | + public function testLicense() |
|
| 155 | + { |
|
| 156 | + // Remove the following lines when you implement this test. |
|
| 157 | + $this->markTestIncomplete( |
|
| 158 | + 'This test has not been implemented yet.' |
|
| 159 | + ); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @covers Detain\Cloudlinux\Cloudlinux::remove_license |
|
| 164 | + * @todo Implement testRemove_license(). |
|
| 165 | + */ |
|
| 166 | + public function testRemove_license() |
|
| 167 | + { |
|
| 168 | + // Remove the following lines when you implement this test. |
|
| 169 | + $this->markTestIncomplete( |
|
| 170 | + 'This test has not been implemented yet.' |
|
| 171 | + ); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * @covers Detain\Cloudlinux\Cloudlinux::is_licensed |
|
| 176 | + * @todo Implement testIs_licensed(). |
|
| 177 | + */ |
|
| 178 | + public function testIs_licensed() |
|
| 179 | + { |
|
| 180 | + // Remove the following lines when you implement this test. |
|
| 181 | + $this->markTestIncomplete( |
|
| 182 | + 'This test has not been implemented yet.' |
|
| 183 | + ); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @covers Detain\Cloudlinux\Cloudlinux::xml_is_licensed |
|
| 188 | + * @todo Implement testXml_is_licensed(). |
|
| 189 | + */ |
|
| 190 | + public function testXml_is_licensed() |
|
| 191 | + { |
|
| 192 | + // Remove the following lines when you implement this test. |
|
| 193 | + $this->markTestIncomplete( |
|
| 194 | + 'This test has not been implemented yet.' |
|
| 195 | + ); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * @covers Detain\Cloudlinux\Cloudlinux::license_list |
|
| 200 | + * @todo Implement testLicense_list(). |
|
| 201 | + */ |
|
| 202 | + public function testLicense_list() |
|
| 203 | + { |
|
| 204 | + // Remove the following lines when you implement this test. |
|
| 205 | + $this->markTestIncomplete( |
|
| 206 | + 'This test has not been implemented yet.' |
|
| 207 | + ); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * @covers Detain\Cloudlinux\Cloudlinux::reconcile |
|
| 212 | + * @todo Implement testReconcile(). |
|
| 213 | + */ |
|
| 214 | + public function testReconcile() |
|
| 215 | + { |
|
| 216 | + // Remove the following lines when you implement this test. |
|
| 217 | + $this->markTestIncomplete( |
|
| 218 | + 'This test has not been implemented yet.' |
|
| 219 | + ); |
|
| 220 | + } |
|
| 221 | 221 | } |