Passed
Push — master ( 6140da...2e21e7 )
by Kris
01:45
created
lib/ApiDefintion.php 2 patches
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -41,82 +41,82 @@  discard block
 block discarded – undo
41 41
     protected $aipdbApiCategories = [
42 42
         
43 43
         // Altering DNS records resulting in improper redirection.        
44
-        ['dns-c'           , '1', 'DNS Compromise', true],    
44
+        [ 'dns-c', '1', 'DNS Compromise', true ],    
45 45
         
46 46
         // Falsifying domain server cache (cache poisoning).
47
-        ['dns-p'           , '2', 'DNS Poisoning', true],     
47
+        [ 'dns-p', '2', 'DNS Poisoning', true ],     
48 48
         
49 49
         // Fraudulent orders.
50
-        ['fraud-orders'    , '3', 'Fraud Orders', true],      
50
+        [ 'fraud-orders', '3', 'Fraud Orders', true ],      
51 51
 
52 52
         // Participating in distributed denial-of-service (usually part of botnet).        
53
-        ['ddos'            , '4', 'DDoS Attack', true],       
53
+        [ 'ddos', '4', 'DDoS Attack', true ],       
54 54
         
55 55
         // 
56
-        ['ftp-bf'          , '5', 'FTP Brute-Force', true],   
56
+        [ 'ftp-bf', '5', 'FTP Brute-Force', true ],   
57 57
         
58 58
         // Oversized IP packet.
59
-        ['pingdeath'       , '6', 'Ping of Death', true],     
59
+        [ 'pingdeath', '6', 'Ping of Death', true ],     
60 60
 
61 61
         // Phishing websites and/or email.
62
-        ['phishing'        , '7', 'Phishing', true],          
62
+        [ 'phishing', '7', 'Phishing', true ],          
63 63
         
64 64
         //
65
-        ['fraudvoip'       , '8', 'Fraud VoIP', true],        
65
+        [ 'fraudvoip', '8', 'Fraud VoIP', true ],        
66 66
 
67 67
         // Open proxy, open relay, or Tor exit node.
68
-        ['openproxy'       , '9', 'Open Proxy', true],        
68
+        [ 'openproxy', '9', 'Open Proxy', true ],        
69 69
 
70 70
          // Comment/forum spam, HTTP referer spam, or other CMS spam.
71
-         ['webspam'         , '10', 'Web Spam', true],        
71
+         [ 'webspam', '10', 'Web Spam', true ],        
72 72
 
73 73
         // Spam email content, infected attachments, and phishing emails. Note: Limit comments to only relevent
74 74
         // information (instead of log dumps) and be sure to remove PII if you want to remain anonymous.
75
-        ['emailspam'       , '11', 'Email Spam', true],                                                   
75
+        [ 'emailspam', '11', 'Email Spam', true ],                                                   
76 76
              
77 77
         // CMS blog comment spam.
78
-        ['blogspam'        , '12', 'Blog Spam', true],      
78
+        [ 'blogspam', '12', 'Blog Spam', true ],      
79 79
         
80 80
         // Conjunctive category.
81
-        ['vpnip'           , '13', 'VPN IP', false], // to check alone ??           
81
+        [ 'vpnip', '13', 'VPN IP', false ], // to check alone ??           
82 82
 
83 83
         // Scanning for open ports and vulnerable services.
84
-        ['scan'            , '14', 'Port Scan', true],        
84
+        [ 'scan', '14', 'Port Scan', true ],        
85 85
        
86 86
         // 
87
-        ['hack'            , '15', 'Hacking', true],           
87
+        [ 'hack', '15', 'Hacking', true ],           
88 88
 
89 89
         // Attempts at SQL injection.
90
-        ['sql'             , '16', 'SQL Injection', true],     
90
+        [ 'sql', '16', 'SQL Injection', true ],     
91 91
         
92 92
         // Email sender spoofing.
93
-        ['spoof'           , '17', 'Spoofing', true],         
93
+        [ 'spoof', '17', 'Spoofing', true ],         
94 94
 
95 95
         // Credential brute-force attacks on webpage logins and services like SSH, FTP, SIP, SMTP, RDP, etc. 
96 96
         // This category is seperate from DDoS attacks.
97
-        ['brute'           , '18', 'Brute-Force', true],     
97
+        [ 'brute', '18', 'Brute-Force', true ],     
98 98
 
99 99
         // Webpage scraping (for email addresses, content, etc) and crawlers that do not honor robots.txt.                                  
100 100
         // Excessive requests and user agent spoofing can also be reported here.                        
101
-        ['badbot'          , '19', 'Bad Web Bot', true],      
101
+        [ 'badbot', '19', 'Bad Web Bot', true ],      
102 102
                                                          
103 103
         // Host is likely infected with malware and being used for other attacks or to host malicious content. 
104 104
         // The host owner may not be aware of the compromise. This category is often used in combination 
105 105
         // with other attack categories.
106
-        ['explhost'        , '20', 'Exploited Host', true],
106
+        [ 'explhost', '20', 'Exploited Host', true ],
107 107
         
108 108
         // Attempts to probe for or exploit installed web applications such as a CMS 
109 109
         // like WordPress/Drupal, e-commerce solutions, forum software, phpMyAdmin and 
110 110
         // various other software plugins/solutions.                                                         
111
-        ['webattack'       , '21', 'Web App Attack', true ],   
111
+        [ 'webattack', '21', 'Web App Attack', true ],   
112 112
         
113 113
         // Secure Shell (SSH) abuse. Use this category in combination 
114 114
         // with more specific categories.
115
-        ['ssh'             , '22', 'SSH', false],              
115
+        [ 'ssh', '22', 'SSH', false ],              
116 116
 
117 117
         // Abuse was targeted at an "Internet of Things" type device. Include 
118 118
         // information about what type of device was targeted in the comments.         
119
-        ['oit'             , '23', 'IoT Targeted', true],     
119
+        [ 'oit', '23', 'IoT Targeted', true ],     
120 120
       ];
121 121
 
122 122
     /**
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
      */
130 130
     public function getCategoryIdbyName(string $categoryName)
131 131
     {
132
-        foreach ($this->aipdbApiCategories as $cat){
133
-            if ($cat[0] === $categoryName) {
132
+        foreach ($this->aipdbApiCategories as $cat) {
133
+            if ($cat[ 0 ] === $categoryName) {
134 134
                 return $cat;
135 135
             }
136 136
          }
@@ -149,8 +149,8 @@  discard block
 block discarded – undo
149 149
      */
150 150
     public function getCategoryNameById(string $categoryId)
151 151
     {
152
-        foreach ($this->aipdbApiCategories as $cat){
153
-           if ($cat[1] === $categoryId) {
152
+        foreach ($this->aipdbApiCategories as $cat) {
153
+           if ($cat[ 1 ] === $categoryId) {
154 154
                return $cat;
155 155
            }
156 156
         }
@@ -171,8 +171,8 @@  discard block
 block discarded – undo
171 171
     protected function getCategoryIndex(string $value, int $index)
172 172
     {
173 173
         $i = 0;
174
-        foreach ($this->aipdbApiCategories as $cat){
175
-            if ($cat[$index] === $value) {
174
+        foreach ($this->aipdbApiCategories as $cat) {
175
+            if ($cat[ $index ] === $value) {
176 176
                 return $i;
177 177
             }
178 178
             $i++;
Please login to merge, or discard this patch.
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
         // Open proxy, open relay, or Tor exit node.
71 71
         ['openproxy'       , '9', 'Open Proxy', true],        
72 72
 
73
-         // Comment/forum spam, HTTP referer spam, or other CMS spam.
74
-         ['webspam'         , '10', 'Web Spam', true],        
73
+            // Comment/forum spam, HTTP referer spam, or other CMS spam.
74
+            ['webspam'         , '10', 'Web Spam', true],        
75 75
 
76 76
         // Spam email content, infected attachments, and phishing emails. Note: Limit comments to only relevent
77 77
         // information (instead of log dumps) and be sure to remove PII if you want to remain anonymous.
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
         // Abuse was targeted at an "Internet of Things" type device. Include 
121 121
         // information about what type of device was targeted in the comments.         
122 122
         ['oit'             , '23', 'IoT Targeted', true],     
123
-      ];
123
+        ];
124 124
 
125 125
     /**
126 126
      * Get the category id corresponding to given name
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
             if ($cat[0] === $categoryName) {
137 137
                 return $cat;
138 138
             }
139
-         }
139
+            }
140 140
 
141 141
         // not found
142 142
         return false;
@@ -153,9 +153,9 @@  discard block
 block discarded – undo
153 153
     public function getCategoryNameById(string $categoryId)
154 154
     {
155 155
         foreach ($this->aipdbApiCategories as $cat){
156
-           if ($cat[1] === $categoryId) {
157
-               return $cat;
158
-           }
156
+            if ($cat[1] === $categoryId) {
157
+                return $cat;
158
+            }
159 159
         }
160 160
 
161 161
         // not found
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
                 return $i;
180 180
             }
181 181
             $i++;
182
-         }
182
+            }
183 183
 
184 184
         // not found
185 185
         return false;
Please login to merge, or discard this patch.
lib/ApiHandler.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
      */
157 157
     public function report(string $ip = '', string $categories = '', string $message = '', bool $returnArray = false)
158 158
     {
159
-         // ip must be set
159
+            // ip must be set
160 160
         if (empty($ip)){
161 161
             throw new \InvalidArgumentException('Ip was empty');
162 162
         }
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
         }
168 168
 
169 169
         // message must be set
170
-          if (empty($message)){
170
+            if (empty($message)){
171 171
             throw new \InvalidArgumentException('report message was empty');
172 172
         }
173 173
 
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 
281 281
         // option
282 282
         if ($verbose){
283
-           $data['verbose'] = true;
283
+            $data['verbose'] = true;
284 284
         }
285 285
 
286 286
         // check AbuseIPDB request
@@ -367,14 +367,14 @@  discard block
 block discarded – undo
367 367
             'Key: ' . $this->aipdbApiKey,
368 368
         ]);
369 369
   
370
-      // execute curl call
371
-      $result = curl_exec($ch);
370
+        // execute curl call
371
+        $result = curl_exec($ch);
372 372
   
373
-      // close connection
374
-      curl_close($ch);
373
+        // close connection
374
+        curl_close($ch);
375 375
   
376
-      // return response as JSON data
377
-      return $result;
376
+        // return response as JSON data
377
+        return $result;
378 378
     }
379 379
 
380 380
     /** 
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
      * @access public
386 386
      * @param string      $message           The original message 
387 387
      *  
388
-	 * @return string
388
+     * @return string
389 389
      */
390 390
     protected function cleanMessage(string $message)
391 391
     {
@@ -410,10 +410,10 @@  discard block
 block discarded – undo
410 410
      *
411 411
      * @access public
412 412
      * @static
413
-	 * @param string    $filePath       The file's full path
414
-	 * @param bool      $trowError      Throw error on true or silent process. Default is true
413
+     * @param string    $filePath       The file's full path
414
+     * @param bool      $trowError      Throw error on true or silent process. Default is true
415 415
      *  
416
-	 * @return object|null 
416
+     * @return object|null 
417 417
      * @throws \Exception
418 418
      * @throws \LogicException
419 419
      */
@@ -421,10 +421,10 @@  discard block
 block discarded – undo
421 421
     {
422 422
         // check file exists
423 423
         if (!file_exists($filePath) || !is_file($filePath)){
424
-           if ($throwError) {
424
+            if ($throwError) {
425 425
                 throw new \Exception('Config file not found');
426
-           }
427
-           return null;  
426
+            }
427
+            return null;  
428 428
         }
429 429
 
430 430
         // get and parse content
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
      * @access protected
51 51
      * @var array $selfIps  
52 52
      */
53
-    protected $selfIps = []; 
53
+    protected $selfIps = [ ]; 
54 54
 
55 55
     /**
56 56
      * Constructor
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
      * @param array   $myIps      The Ips/domain name you dont want to display in report messages
62 62
      * 
63 63
      */
64
-    public function __construct(string $apiKey, string $userId, array $myIps = [])
64
+    public function __construct(string $apiKey, string $userId, array $myIps = [ ])
65 65
     {
66 66
         $this->aipdbApiKey = $apiKey;
67 67
         $this->aipdbUserId = $userId;
@@ -100,21 +100,21 @@  discard block
 block discarded – undo
100 100
     {
101 101
 
102 102
         // check file exists
103
-        if (!file_exists($configPath) || !is_file($configPath)){
103
+        if (!file_exists($configPath) || !is_file($configPath)) {
104 104
             throw new \InvalidArgumentException('The file [' . $configPath . '] does not exist.');
105 105
         }
106 106
 
107 107
         // check file is readable
108
-        if (!is_readable($configPath)){
108
+        if (!is_readable($configPath)) {
109 109
             throw new InvalidPermissionException('The file [' . $configPath . '] is not readable.');
110 110
         }
111 111
 
112 112
         $keyConfig = self::loadJsonFile($configPath);
113
-        $selfIps = [];
113
+        $selfIps = [ ];
114 114
         
115 115
         // Look for other optional config files in the same directory 
116 116
         $selfIpsConfigPath = pathinfo($configPath, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR . 'self_ips.json';
117
-        if (file_exists($selfIpsConfigPath)){
117
+        if (file_exists($selfIpsConfigPath)) {
118 118
             $selfIps = self::loadJsonFile($selfIpsConfigPath)->self_ips;
119 119
         }
120 120
 
@@ -157,17 +157,17 @@  discard block
 block discarded – undo
157 157
     public function report(string $ip = '', string $categories = '', string $message = '', bool $returnArray = false)
158 158
     {
159 159
          // ip must be set
160
-        if (empty($ip)){
160
+        if (empty($ip)) {
161 161
             throw new \InvalidArgumentException('Ip was empty');
162 162
         }
163 163
 
164 164
         // categories must be set
165
-        if (empty($categories)){
165
+        if (empty($categories)) {
166 166
             throw new \InvalidArgumentException('categories list was empty');
167 167
         }
168 168
 
169 169
         // message must be set
170
-          if (empty($message)){
170
+          if (empty($message)) {
171 171
             throw new \InvalidArgumentException('report message was empty');
172 172
         }
173 173
 
@@ -234,12 +234,12 @@  discard block
 block discarded – undo
234 234
     public function checkBlock(string $network = null, int $maxAge = 30, bool $returnArray = false)
235 235
     {
236 236
         // max age must be less or equal to 365
237
-        if ($maxAge > 365 || $maxAge < 1){
237
+        if ($maxAge > 365 || $maxAge < 1) {
238 238
             throw new \InvalidArgumentException('maxAge must be at least 1 and less than 365 (' . $maxAge . ' was given)');
239 239
         }
240 240
 
241 241
         // ip must be set
242
-        if (empty($network)){
242
+        if (empty($network)) {
243 243
             throw new \InvalidArgumentException('network argument must be set (null given)');
244 244
         }
245 245
 
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
             'maxAgeInDays'  => $maxAge,  
250 250
         ];
251 251
 
252
-        $response = $this->apiRequest('check-block', $data, 'GET', $returnArray) ;
252
+        $response = $this->apiRequest('check-block', $data, 'GET', $returnArray);
253 253
 
254 254
         return json_decode($response, $returnArray);
255 255
     }
@@ -269,12 +269,12 @@  discard block
 block discarded – undo
269 269
     public function check(string $ip = null, int $maxAge = 30, bool $verbose = false, bool $returnArray = false)
270 270
     {
271 271
         // max age must be less or equal to 365
272
-        if ($maxAge > 365 || $maxAge < 1){
272
+        if ($maxAge > 365 || $maxAge < 1) {
273 273
             throw new \InvalidArgumentException('maxAge must be at least 1 and less than 365 (' . $maxAge . ' was given)');
274 274
         }
275 275
 
276 276
         // ip must be set
277
-        if (empty($ip)){
277
+        if (empty($ip)) {
278 278
             throw new \InvalidArgumentException('ip argument must be set (null given)');
279 279
         }
280 280
 
@@ -285,12 +285,12 @@  discard block
 block discarded – undo
285 285
         ];
286 286
 
287 287
         // option
288
-        if ($verbose){
289
-           $data['verbose'] = true;
288
+        if ($verbose) {
289
+           $data[ 'verbose' ] = true;
290 290
         }
291 291
 
292 292
         // check AbuseIPDB request
293
-        $response = $this->apiRequest('check', $data, 'GET', $returnArray) ;
293
+        $response = $this->apiRequest('check', $data, 'GET', $returnArray);
294 294
 
295 295
         return json_decode($response, $returnArray);
296 296
     }
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
     public function getBlacklist(int $limit = 10000, bool $plainText = false, bool $returnArray = false)
311 311
     {
312 312
 
313
-        if ($limit < 1){
313
+        if ($limit < 1) {
314 314
             throw new \InvalidArgumentException('limit must be at least 1 (' . $limit . ' was given)');
315 315
         }
316 316
 
@@ -322,13 +322,13 @@  discard block
 block discarded – undo
322 322
 
323 323
         // plaintext paremeter has no value and must be added only when true 
324 324
         // (set plaintext=false won't work)
325
-        if ($plainText){
326
-            $data['plaintext'] = $plainText;
325
+        if ($plainText) {
326
+            $data[ 'plaintext' ] = $plainText;
327 327
         }
328 328
 
329 329
         $response = $this->apiRequest('blacklist', $data, 'GET');
330 330
 
331
-        if ($plainText){
331
+        if ($plainText) {
332 332
             return $response;
333 333
         } 
334 334
        
@@ -359,21 +359,21 @@  discard block
 block discarded – undo
359 359
         foreach ($cats as $cat) {
360 360
 
361 361
             // get index on our array of categories
362
-            $catIndex    = is_numeric($cat) ? $this->getCategoryIndex($cat, 1) : $this->getCategoryIndex($cat, 0);
362
+            $catIndex = is_numeric($cat) ? $this->getCategoryIndex($cat, 1) : $this->getCategoryIndex($cat, 0);
363 363
 
364 364
             // check if found
365
-            if ($catIndex === false ){
366
-                throw new \InvalidArgumentException('Invalid report category was given : ['. $cat .  ']');
365
+            if ($catIndex === false) {
366
+                throw new \InvalidArgumentException('Invalid report category was given : [' . $cat . ']');
367 367
             }
368 368
 
369 369
             // get Id
370
-            $catId = $this->aipdbApiCategories[$catIndex][1];
370
+            $catId = $this->aipdbApiCategories[ $catIndex ][ 1 ];
371 371
 
372 372
             // need another ?
373
-            if ($needAnother !== false){
373
+            if ($needAnother !== false) {
374 374
 
375 375
                 // is a standalone cat ?
376
-                if ($this->aipdbApiCategories[$catIndex][3] === false) {
376
+                if ($this->aipdbApiCategories[ $catIndex ][ 3 ] === false) {
377 377
                     $needAnother = true;
378 378
 
379 379
                 } else {
@@ -384,10 +384,10 @@  discard block
 block discarded – undo
384 384
             }
385 385
 
386 386
             // set or add to cats list 
387
-            $catsString = ($catsString === '') ? $catId : $catsString .','.$catId;
387
+            $catsString = ($catsString === '') ? $catId : $catsString . ',' . $catId;
388 388
         }
389 389
 
390
-        if ($needAnother !== false){
390
+        if ($needAnother !== false) {
391 391
             throw new \InvalidArgumentException('Invalid report category paremeter given: some categories can\'t be used alone');
392 392
         }
393 393
 
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
         $message = str_replace('\\', '', $message);
460 460
 
461 461
         // Remove self ips
462
-        foreach ($this->selfIps as $ip){
462
+        foreach ($this->selfIps as $ip) {
463 463
             $message = str_replace($ip, '*', $message);
464 464
         }
465 465
 
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
     protected static function loadJsonFile(string $filePath, bool $throwError = true)
487 487
     {
488 488
         // check file exists
489
-        if (!file_exists($filePath) || !is_file($filePath)){
489
+        if (!file_exists($filePath) || !is_file($filePath)) {
490 490
            if ($throwError) {
491 491
                 throw new \Exception('Config file not found');
492 492
            }
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
         $json    = json_decode(utf8_encode($content));
499 499
 
500 500
         // check for errors
501
-        if ($json == null && json_last_error() != JSON_ERROR_NONE){
501
+        if ($json == null && json_last_error() != JSON_ERROR_NONE) {
502 502
             if ($throwError) {
503 503
                 throw new \LogicException(sprintf("Failed to parse config file Error: '%s'", json_last_error_msg()));
504 504
             }
Please login to merge, or discard this patch.