@@ -3,24 +3,24 @@ discard block |
||
| 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 |
||
| 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)) { |
@@ -30,8 +30,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -15,12 +15,12 @@ |
||
| 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 | ?> |