Completed
Branch — master (188864)
by Joe
04:05
created
src/Cloudlinux.php 4 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -107,6 +107,9 @@  discard block
 block discarded – undo
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,7 +246,7 @@  discard block
 block discarded – undo
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)
249
+	 * @param integer $type optional parameter to specify the type of license to remove (1,2, or 16)
247 250
 	 * @return integer 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) {
Please login to merge, or discard this patch.
Indentation   +278 added lines, -278 removed lines patch added patch discarded remove patch
@@ -30,301 +30,301 @@
 block discarded – undo
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->xml_client->remove_license($this->authToken(), $ip);
254
-			else
255
-				return $this->response = $this->xml_client->remove_license($this->authToken(), $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->xml_client->remove_license($this->authToken(), $ip);
254
+            else
255
+                return $this->response = $this->xml_client->remove_license($this->authToken(), $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(),
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
254 254
 			else
255 255
 				return $this->response = $this->xml_client->remove_license($this->authToken(), $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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 	}
Please login to merge, or discard this patch.
Braces   +33 added lines, -26 removed lines patch added patch discarded remove patch
@@ -57,8 +57,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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->xml_client->remove_license($this->authToken(), $ip);
254
-			else
255
-				return $this->response = $this->xml_client->remove_license($this->authToken(), $ip, $type);
257
+			if ($type === false) {
258
+							return $this->response = $this->xml_client->remove_license($this->authToken(), $ip);
259
+			} else {
260
+							return $this->response = $this->xml_client->remove_license($this->authToken(), $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
 block discarded – undo
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:
Please login to merge, or discard this patch.