Completed
Branch master (598b3a)
by Joe
02:13
created
src/Cpanel.php 4 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -18,6 +18,9 @@  discard block
 block discarded – undo
18 18
         $this->setopt(CURLOPT_USERAGENT, 'cPanel Licensing Agent (php) 3.5' );
19 19
     }
20 20
 
21
+	/**
22
+	 * @param integer $option
23
+	 */
21 24
 	public function setopt($option, $value) {
22 25
 		$this->opts[$option] = $value;
23 26
 	}
@@ -36,6 +39,9 @@  discard block
 block discarded – undo
36 39
         }
37 40
     }
38 41
 
42
+    /**
43
+     * @param string $function
44
+     */
39 45
     private function get ($function, $args = array()) {
40 46
         if (!$function) {
41 47
             error_log("cPanelLicensing::get requires that a function is defined");
Please login to merge, or discard this patch.
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -3,24 +3,24 @@  discard block
 block discarded – undo
3 3
 namespace Detain\Cpanel;
4 4
 
5 5
 class Cpanel {
6
-	public $format;
7
-	public $curl;
8
-	public $opts;
6
+    public $format;
7
+    public $curl;
8
+    public $opts;
9 9
 
10 10
     public function __construct ($user, $pass) {
11 11
         if (!function_exists('curl_init')) {
12 12
             die("cPanelLicensing requires that curl+ssl support is compiled into the PHP interpreter");
13 13
         }
14
-		$this->opts = [];
14
+        $this->opts = [];
15 15
         $this->format = "simplexml";
16 16
         $this->setCredentials($user, $pass);
17 17
         $this->setopt(CURLOPT_RETURNTRANSFER,1);
18 18
         $this->setopt(CURLOPT_USERAGENT, 'cPanel Licensing Agent (php) 3.5' );
19 19
     }
20 20
 
21
-	public function setopt($option, $value) {
22
-		$this->opts[$option] = $value;
23
-	}
21
+    public function setopt($option, $value) {
22
+        $this->opts[$option] = $value;
23
+    }
24 24
 
25 25
     public function setCredentials ($user, $pass) {
26 26
         $this->setopt(CURLOPT_USERPWD, $user . ":" . $pass);
@@ -46,42 +46,42 @@  discard block
 block discarded – undo
46 46
         }
47 47
         $query = "https://manage2.cpanel.net/" . $function . "?" . http_build_query($args);
48 48
         $this->setopt(CURLOPT_URL, $query);
49
-		$this->curl = curl_init();
50
-		foreach ($this->opts as $option => $value) {
51
-			curl_setopt($this->curl, $option, $value);
52
-		}
49
+        $this->curl = curl_init();
50
+        foreach ($this->opts as $option => $value) {
51
+            curl_setopt($this->curl, $option, $value);
52
+        }
53 53
         $result = curl_exec($this->curl);
54
-		curl_close($this->curl);
54
+        curl_close($this->curl);
55 55
         if ($result == false) {
56 56
             error_log("cPanelLicensing::get failed: \"" . curl_error($this->curl) . "\"");
57 57
             return;
58 58
         }
59 59
         if ($this->format == "simplexml") {
60
-			function_requirements('xml2array');
61
-			$result = xml2array($result, 1, 'attribute');
62
-			$result = $result[str_replace('.cgi', '', $function)];
63
-			$result = $this->format_result($result);			
64
-			return $result;
60
+            function_requirements('xml2array');
61
+            $result = xml2array($result, 1, 'attribute');
62
+            $result = $result[str_replace('.cgi', '', $function)];
63
+            $result = $this->format_result($result);			
64
+            return $result;
65 65
         }
66 66
         else {
67 67
             return $result;
68 68
         }
69 69
     }
70 70
 
71
-	private function format_result($result) {
72
-		if (is_array($result)) {
73
-			foreach ($result as $key => $value) {
74
-				if (is_array($value)) {
75
-					if (isset($value['attr']) && is_array($value['attr'])) {
76
-						$result[$key] = $value['attr'];
77
-					} else {
78
-						$result[$key] = $this->format_result($value);
79
-					}
80
-				}
81
-			}
82
-		}
83
-		return $result;
84
-	}
71
+    private function format_result($result) {
72
+        if (is_array($result)) {
73
+            foreach ($result as $key => $value) {
74
+                if (is_array($value)) {
75
+                    if (isset($value['attr']) && is_array($value['attr'])) {
76
+                        $result[$key] = $value['attr'];
77
+                    } else {
78
+                        $result[$key] = $this->format_result($value);
79
+                    }
80
+                }
81
+            }
82
+        }
83
+        return $result;
84
+    }
85 85
 
86 86
     private function validateID ($id) {
87 87
         if (preg_match("/^(L|P|G)?\d*$/", $id)) {
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -7,26 +7,26 @@  discard block
 block discarded – undo
7 7
 	public $curl;
8 8
 	public $opts;
9 9
 
10
-    public function __construct ($user, $pass) {
10
+    public function __construct($user, $pass) {
11 11
         if (!function_exists('curl_init')) {
12 12
             die("cPanelLicensing requires that curl+ssl support is compiled into the PHP interpreter");
13 13
         }
14 14
 		$this->opts = [];
15 15
         $this->format = "simplexml";
16 16
         $this->setCredentials($user, $pass);
17
-        $this->setopt(CURLOPT_RETURNTRANSFER,1);
18
-        $this->setopt(CURLOPT_USERAGENT, 'cPanel Licensing Agent (php) 3.5' );
17
+        $this->setopt(CURLOPT_RETURNTRANSFER, 1);
18
+        $this->setopt(CURLOPT_USERAGENT, 'cPanel Licensing Agent (php) 3.5');
19 19
     }
20 20
 
21 21
 	public function setopt($option, $value) {
22 22
 		$this->opts[$option] = $value;
23 23
 	}
24 24
 
25
-    public function setCredentials ($user, $pass) {
25
+    public function setCredentials($user, $pass) {
26 26
         $this->setopt(CURLOPT_USERPWD, $user . ":" . $pass);
27 27
     }
28 28
 
29
-    public function set_format ($format) {
29
+    public function set_format($format) {
30 30
         if ($format != "xml" && $format != "json" && $format != "yaml" && $format != "simplexml") {
31 31
             error_log("set_format requires that the format is xml, json, yaml or simplexml");
32 32
             return;
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
         }
37 37
     }
38 38
 
39
-    private function get ($function, $args = array()) {
39
+    private function get($function, $args = array()) {
40 40
         if (!$function) {
41 41
             error_log("cPanelLicensing::get requires that a function is defined");
42 42
             return;
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 		return $result;
84 84
 	}
85 85
 
86
-    private function validateID ($id) {
86
+    private function validateID($id) {
87 87
         if (preg_match("/^(L|P|G)?\d*$/", $id)) {
88 88
             return 1;
89 89
         }
@@ -92,11 +92,11 @@  discard block
 block discarded – undo
92 92
         }
93 93
     }
94 94
 
95
-    private function validateIP ($ip) {
95
+    private function validateIP($ip) {
96 96
         return preg_match("/^\d*\.\d*\.\d*\.\d*$/", $ip);
97 97
     }
98 98
 
99
-    public function reactivateLicense ($args) {
99
+    public function reactivateLicense($args) {
100 100
         if (!array_key_exists('liscid', $args)) {
101 101
             error_log("cpanelLicensing::reactivateLicense requires that the argument array contains element liscid");
102 102
             return;
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
         return $this->get("XMLlicenseReActivate.cgi", $args);
109 109
     }
110 110
 
111
-    public function expireLicense ($args) {
111
+    public function expireLicense($args) {
112 112
         if (!array_key_exists("liscid", $args)) {
113 113
             error_log("cPanelLicensing::expireLicense requires that liscid elements exists in the array passed to it");
114 114
             return;
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
         return $this->get("XMLlicenseExpire.cgi", $args);
121 121
     }
122 122
 
123
-    public function extendOnetimeUpdates ($args) {
123
+    public function extendOnetimeUpdates($args) {
124 124
         if (!array_key_exists("ip", $args)) {
125 125
             error_log("cpanelLicensing::extendOnetimeUpdates requires that the element ip exists in the array is passed to it");
126 126
             return;
@@ -129,10 +129,10 @@  discard block
 block discarded – undo
129 129
             error_log("cpanelLicensing::extendOnetimeUpdates was passed an invalid ip");
130 130
             return;
131 131
         }
132
-        return $this->get( "XMLonetimeext.cgi", $args );
132
+        return $this->get("XMLonetimeext.cgi", $args);
133 133
     }
134 134
 
135
-    public function changeip ($args) {
135
+    public function changeip($args) {
136 136
         if (!array_key_exists("oldip", $args) || !array_key_exists("newip", $args)) {
137 137
             error_log("cpanelLicensing::changeip requires that oldip and newip elements exist in the array passed to it");
138 138
             return;
@@ -144,8 +144,8 @@  discard block
 block discarded – undo
144 144
         return $this->get("XMLtransfer.cgi", $args);
145 145
     }
146 146
 
147
-    public function requestTransfer ($args) {
148
-        if (!array_key_exists("ip", $args) || !array_key_exists("groupid", $args ) || !array_key_exists("packagegroup", $args)) {
147
+    public function requestTransfer($args) {
148
+        if (!array_key_exists("ip", $args) || !array_key_exists("groupid", $args) || !array_key_exists("packagegroup", $args)) {
149 149
             error_log("cpanelLicensing::requestTransfer requires that ip, groupid and packageid elements exist in the array passed to it");
150 150
             return;
151 151
         }
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
             error_log("The groupid passed to cpanelLicensing::requestTransfer is invalid");
154 154
             return;
155 155
         }
156
-        if (!$this->validateID( $args["packageid"])) {
156
+        if (!$this->validateID($args["packageid"])) {
157 157
             error_log("The package id passed to cpanelLicensing::requestTransfer is invalid");
158 158
             return;
159 159
         }
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
         return $this->get("XMLtransferRequest.cgi", $args);
165 165
     }
166 166
 
167
-    public function activateLicense ($args) {
167
+    public function activateLicense($args) {
168 168
         if (!array_key_exists("ip", $args) || !array_key_exists("groupid", $args) || !array_key_exists("packageid", $args)) {
169 169
             error_log("cpanelLicensing::activateLicense requires that ip, groupid and packageid elements exist in the array passed to it");
170 170
             return;
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
         return $this->get("XMLlicenseAdd.cgi", $args);
186 186
     }
187 187
 
188
-    public function addPickupPass ($args) {
188
+    public function addPickupPass($args) {
189 189
         if (!array_key_exists("pickup", $args)) {
190 190
             error_log("cPanelLicensing::addPickupPass requires a pickup param");
191 191
             return;
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
         return $this->get("XMLaddPickupPass.cgi", $args);
194 194
     }
195 195
 
196
-    public function registerAuth ($args) {
196
+    public function registerAuth($args) {
197 197
         if (!array_key_exists("user", $args)) {
198 198
             error_log("cPanelLicensing::registerAuth requires a user param");
199 199
             return;
@@ -213,11 +213,11 @@  discard block
 block discarded – undo
213 213
         return $response;
214 214
     }
215 215
 
216
-    public function fetchGroups () {
216
+    public function fetchGroups() {
217 217
         return $this->get("XMLgroupInfo.cgi");
218 218
     }
219 219
 
220
-    public function fetchLicenseRiskData ($args) {
220
+    public function fetchLicenseRiskData($args) {
221 221
         if (!array_key_exists("ip", $args)) {
222 222
             error_log("cpanelLicensing::fetchLicenseRiskData requires that ip exists as an element in the array is passed to it");
223 223
             return;
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
         return $this->get("XMLsecverify.cgi", $args);
230 230
     }
231 231
 
232
-    public function fetchLicenseRaw ($args) {
232
+    public function fetchLicenseRaw($args) {
233 233
         $args = array_merge(array("all" => 1), $args);
234 234
         if (!array_key_exists("ip", $args)) {
235 235
             error_log("cpanelLicesning::fetchLicenseRaw requires that ip exists as an element in the array is passed to it");
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
         return $this->get("XMLRawlookup.cgi", $args);
243 243
     }
244 244
 
245
-    public function fetchLicenseId ($args) {
245
+    public function fetchLicenseId($args) {
246 246
         $args = array_merge(array("all" => 1), $args);
247 247
         if (!array_key_exists('ip', $args)) {
248 248
             error_log("cpanelLicensing::getLicenseId requires that an IP is passed to it");
@@ -255,20 +255,20 @@  discard block
 block discarded – undo
255 255
         return $this->get("XMLlookup.cgi", $args);
256 256
     }
257 257
 
258
-    public function fetchPackages () {
258
+    public function fetchPackages() {
259 259
         return $this->get("XMLpackageInfo.cgi");
260 260
     }
261 261
 
262
-    public function fetchLicenses () {
262
+    public function fetchLicenses() {
263 263
         return $this->get("XMLlicenseInfo.cgi");
264 264
     }
265 265
 
266
-    public function fetchExpiredLicenses () {
266
+    public function fetchExpiredLicenses() {
267 267
         return $this->get("XMLlicenseInfo.cgi", array("expired" => '1'));
268 268
     }
269 269
 
270
-    public function findKey ($search, $xml_obj) {
271
-        $xml_obj = (array) $xml_obj;
270
+    public function findKey($search, $xml_obj) {
271
+        $xml_obj = (array)$xml_obj;
272 272
         if (array_key_exists("packages", $xml_obj)) {
273 273
             $type = "packages";
274 274
         }
@@ -279,9 +279,9 @@  discard block
 block discarded – undo
279 279
             error_log("cPanelLicensing::findKey with an object that is not groups or packages");
280 280
             return;
281 281
         }
282
-        foreach ((array) $xml_obj[$type] as $element) {
283
-            foreach ((array) $element as $key => $value) {
284
-                if ((string) $value == $search) {
282
+        foreach ((array)$xml_obj[$type] as $element) {
283
+            foreach ((array)$element as $key => $value) {
284
+                if ((string)$value == $search) {
285 285
                     return (string)$key;
286 286
                 }
287 287
             }
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -30,8 +30,7 @@  discard block
 block discarded – undo
30 30
         if ($format != "xml" && $format != "json" && $format != "yaml" && $format != "simplexml") {
31 31
             error_log("set_format requires that the format is xml, json, yaml or simplexml");
32 32
             return;
33
-        }
34
-        else {
33
+        } else {
35 34
             $this->format = $format;
36 35
         }
37 36
     }
@@ -62,8 +61,7 @@  discard block
 block discarded – undo
62 61
 			$result = $result[str_replace('.cgi', '', $function)];
63 62
 			$result = $this->format_result($result);			
64 63
 			return $result;
65
-        }
66
-        else {
64
+        } else {
67 65
             return $result;
68 66
         }
69 67
     }
@@ -86,8 +84,7 @@  discard block
 block discarded – undo
86 84
     private function validateID ($id) {
87 85
         if (preg_match("/^(L|P|G)?\d*$/", $id)) {
88 86
             return 1;
89
-        }
90
-        else {
87
+        } else {
91 88
             return 0;
92 89
         }
93 90
     }
@@ -271,11 +268,9 @@  discard block
 block discarded – undo
271 268
         $xml_obj = (array) $xml_obj;
272 269
         if (array_key_exists("packages", $xml_obj)) {
273 270
             $type = "packages";
274
-        }
275
-        else if (array_key_exists("groups", $xml_obj)) {
271
+        } else if (array_key_exists("groups", $xml_obj)) {
276 272
             $type = "groups";
277
-        }
278
-        else {
273
+        } else {
279 274
             error_log("cPanelLicensing::findKey with an object that is not groups or packages");
280 275
             return;
281 276
         }
Please login to merge, or discard this patch.
scripts/list_licenses.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@
 block discarded – undo
3 3
 function_requirements('xml2array');
4 4
 include("../cpl.inc.php");
5 5
 
6
-$cpl = new \Detain\Cpanel\Cpanel($_SERVER['argv'][1],$_SERVER['argv'][2]);
6
+$cpl = new \Detain\Cpanel\Cpanel($_SERVER['argv'][1], $_SERVER['argv'][2]);
7 7
 
8 8
 $licenses = $cpl->fetchLicenses();
9 9
 print_r($licenses);
Please login to merge, or discard this patch.
scripts/expire_license.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,10 +4,10 @@
 block discarded – undo
4 4
 
5 5
 $ip = "__IP__";
6 6
 
7
-$lisc = (array)$cpl->fetchLicenseId( array( "ip" => $ip ) );
7
+$lisc = (array)$cpl->fetchLicenseId(array("ip" => $ip));
8 8
 $liscid = $lisc["@attributes"]["licenseid"];
9 9
 
10
-if ( $liscid > 0 ) {
10
+if ($liscid > 0) {
11 11
     $expire = (array)$cpl->expireLicense(array(
12 12
         liscid => $liscid,
13 13
         reason => "Automagic Expiration",
Please login to merge, or discard this patch.
scripts/list_expired_licenses.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,11 +2,11 @@
 block discarded – undo
2 2
 
3 3
 include("../cpl.inc.php");
4 4
 
5
-$cpl = new \Detain\Cpanel\Cpanel($_SERVER['argv'][1],$_SERVER['argv'][2]);
5
+$cpl = new \Detain\Cpanel\Cpanel($_SERVER['argv'][1], $_SERVER['argv'][2]);
6 6
 
7 7
 $licenses = $cpl->fetchExpiredLicenses();
8 8
 
9
-foreach ( $licenses->licenses as $lisc ) {
9
+foreach ($licenses->licenses as $lisc) {
10 10
     $lisc = (array)$lisc;
11 11
     print "\nLicense IP: " . $lisc['@attributes']['ip'] . "\n";
12 12
     print "        ID: " . $lisc['@attributes']['name'] . "\n";
Please login to merge, or discard this patch.
scripts/fetch_risk_data.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -15,12 +15,12 @@
 block discarded – undo
15 15
 );
16 16
 
17 17
 if ($status["@attributes"]["status"] == 1) {
18
-   print "Risk Scores for $ip:\n";
19
-   print "aggregate : " . $status["@attributes"]["riskscore.aggregate.score"] . "\n";
20
-   print "directorder : " . $status["@attributes"]["riskscore.directorder.score"] . "\n";
21
-   print "main : " . $status["@attributes"]["riskscore.main.score"] . "\n";
18
+    print "Risk Scores for $ip:\n";
19
+    print "aggregate : " . $status["@attributes"]["riskscore.aggregate.score"] . "\n";
20
+    print "directorder : " . $status["@attributes"]["riskscore.directorder.score"] . "\n";
21
+    print "main : " . $status["@attributes"]["riskscore.main.score"] . "\n";
22 22
 } else {
23
-   print "Failed to fetch risk data\n";
23
+    print "Failed to fetch risk data\n";
24 24
 }
25 25
 
26 26
 ?>
Please login to merge, or discard this patch.
scripts/request_transfer.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -4,10 +4,10 @@
 block discarded – undo
4 4
 
5 5
 $ip = "__IP_TO_TRANSFER__";
6 6
 
7
-$group = $cpl->findKey("__GROUP_NAME__", $cpl->fetchGroups() );
8
-$package = $cpl->findKey("__PACKAGE_NAME__", $cpl->fetchPackages() );
7
+$group = $cpl->findKey("__GROUP_NAME__", $cpl->fetchGroups());
8
+$package = $cpl->findKey("__PACKAGE_NAME__", $cpl->fetchPackages());
9 9
 
10
-$result = (array)$cpl->requestTransfer( array(
10
+$result = (array)$cpl->requestTransfer(array(
11 11
     "ip" => $ip,
12 12
     "groupid" => $group,
13 13
     "packageid" => $package
Please login to merge, or discard this patch.
scripts/reactivate_license.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -4,12 +4,12 @@
 block discarded – undo
4 4
 
5 5
 $ip = "__IP__";
6 6
 
7
-$lisc = (array)$cpl->fetchLicenseID( array("ip" => $ip) );
7
+$lisc = (array)$cpl->fetchLicenseID(array("ip" => $ip));
8 8
 
9 9
 $id = $lisc['@attributes']['licenseid'];
10 10
 
11
-if ( $id > 0 ) {
12
-    $result = (array)$cpl->reactivateLicense( array( 'liscid' => $id, reactivateok => 1 ) );
11
+if ($id > 0) {
12
+    $result = (array)$cpl->reactivateLicense(array('liscid' => $id, reactivateok => 1));
13 13
 } else {
14 14
     print "no expired license exists for $ip\n";
15 15
 }
Please login to merge, or discard this patch.
scripts/add_new_license.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -2,12 +2,12 @@  discard block
 block discarded – undo
2 2
 
3 3
 include("../cpl.inc.php");
4 4
 
5
-$cpl = new \Detain\Cpanel\Cpanel( $_SERVER['argv'][1], $_SERVER['argv'][2] );
5
+$cpl = new \Detain\Cpanel\Cpanel($_SERVER['argv'][1], $_SERVER['argv'][2]);
6 6
 
7 7
 $ip = "__IP__";
8 8
 
9
-$groupid = $cpl->findKey("__GROUPNAME__", $cpl->fetchGroups() );
10
-$packageid = $cpl->findKey("__PACKAGENAME__", $cpl->fetchPackages() );
9
+$groupid = $cpl->findKey("__GROUPNAME__", $cpl->fetchGroups());
10
+$packageid = $cpl->findKey("__PACKAGENAME__", $cpl->fetchPackages());
11 11
 
12 12
 $lisc = (array)$cpl->activateLicense(array(
13 13
         "ip" => $ip,
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 );
22 22
 
23 23
 if ($lisc['@attributes']['status'] > 0) {
24
-    print "license added with id: ". $lisc['@attributes']['licenseid'] . "\n";
24
+    print "license added with id: " . $lisc['@attributes']['licenseid'] . "\n";
25 25
 } else {
26 26
     print "License add failed: " . $lisc['@attributes']['reason'] . "\n";
27 27
 }
Please login to merge, or discard this patch.
scripts/lookup_license_id_by_ip.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@
 block discarded – undo
2 2
 include("../cpl.inc.php");
3 3
 $cpl = new \Detain\Cpanel\Cpanel($_SERVER['argv'][1], $_SERVER['argv'][2]);
4 4
 $ip = "__IP__";
5
-$lisc = (array) $cpl->fetchLicenseId(array("ip" => $ip));
5
+$lisc = (array)$cpl->fetchLicenseId(array("ip" => $ip));
6 6
 print_r($lisc);
7 7
 $id = $lisc['licenseid'];
8 8
 $id = is_array($id) ? $id[0] : $id;
Please login to merge, or discard this patch.