| @@ -193,10 +193,10 @@ discard block | ||
| 193 | 193 | * | 
| 194 | 194 | * @access public | 
| 195 | 195 | * @static | 
| 196 | - * @param string $filePath The file's full path | |
| 197 | - * @param bool $throwError Throw error on true or silent process. Default is true | |
| 196 | + * @param string $filePath The file's full path | |
| 197 | + * @param bool $throwError Throw error on true or silent process. Default is true | |
| 198 | 198 | * | 
| 199 | - * @return object|null | |
| 199 | + * @return object|null | |
| 200 | 200 | * @throws \Exception | 
| 201 | 201 | * @throws \LogicException | 
| 202 | 202 | */ | 
| @@ -204,10 +204,10 @@ discard block | ||
| 204 | 204 |      { | 
| 205 | 205 | // check file exists | 
| 206 | 206 |          if (!file_exists($filePath) || !is_file($filePath)){ | 
| 207 | -           if ($throwError) { | |
| 207 | +            if ($throwError) { | |
| 208 | 208 |                  throw new \Exception('Config file not found'); | 
| 209 | - } | |
| 210 | - return null; | |
| 209 | + } | |
| 210 | + return null; | |
| 211 | 211 | } | 
| 212 | 212 | |
| 213 | 213 | // get and parse content | 
| @@ -277,38 +277,38 @@ discard block | ||
| 277 | 277 |      { | 
| 278 | 278 |          Console::log(' ' . Console::text('SYNOPSIS:', 'white', 'underline'));  | 
| 279 | 279 |          Console::log(' ' . Console::text('    abuseipdb -C ') .  | 
| 280 | -                           Console::text('ip', 'yellow') .  | |
| 281 | -                           Console::text(' [-d ') .  | |
| 282 | -                           Console::text('days', 'yellow') .  | |
| 283 | -                           Console::text('] [-v] [-l ') .  | |
| 284 | -                           Console::text('limit', 'yellow') .  | |
| 285 | -                           Console::text(']'));  | |
| 280 | +                            Console::text('ip', 'yellow') .  | |
| 281 | +                            Console::text(' [-d ') .  | |
| 282 | +                            Console::text('days', 'yellow') .  | |
| 283 | +                            Console::text('] [-v] [-l ') .  | |
| 284 | +                            Console::text('limit', 'yellow') .  | |
| 285 | +                            Console::text(']'));  | |
| 286 | 286 | |
| 287 | 287 |          Console::log(' ' . Console::text('    abuseipdb -K ') .  | 
| 288 | -                           Console::text('network', 'yellow') .  | |
| 289 | -                           Console::text(' [-d ') .  | |
| 290 | -                           Console::text('days', 'yellow') .  | |
| 291 | -                           Console::text(']'));  | |
| 288 | +                            Console::text('network', 'yellow') .  | |
| 289 | +                            Console::text(' [-d ') .  | |
| 290 | +                            Console::text('days', 'yellow') .  | |
| 291 | +                            Console::text(']'));  | |
| 292 | 292 | |
| 293 | 293 |          Console::log(' ' . Console::text('    abuseipdb -R ' . | 
| 294 | -                           Console::text('ip', 'yellow') . ' -c ' . | |
| 295 | -                           Console::text('categories', 'yellow') . ' -m ' . | |
| 296 | -                           Console::text('message', 'yellow')));  | |
| 294 | +                            Console::text('ip', 'yellow') . ' -c ' . | |
| 295 | +                            Console::text('categories', 'yellow') . ' -m ' . | |
| 296 | +                            Console::text('message', 'yellow')));  | |
| 297 | 297 | |
| 298 | 298 |          Console::log(' ' . Console::text('    abuseipdb -V ' . | 
| 299 | -                           Console::text('path', 'yellow'))); | |
| 299 | +                            Console::text('path', 'yellow'))); | |
| 300 | 300 | |
| 301 | 301 |          Console::log(' ' . Console::text('    abuseipdb -E ' . | 
| 302 | -                           Console::text('ip', 'yellow'))); | |
| 302 | +                            Console::text('ip', 'yellow'))); | |
| 303 | 303 | |
| 304 | 304 |          Console::log(' ' . Console::text('    abuseipdb -B ') .  | 
| 305 | -                           Console::text('[-l ') .  | |
| 306 | -                           Console::text('limit', 'yellow') .  | |
| 307 | -                           Console::text('] [-s ') .  | |
| 308 | -                           Console::text('score', 'yellow') .  | |
| 309 | -                           Console::text('] [-p ') .  | |
| 310 | -                           Console::text('', 'yellow') .  | |
| 311 | -                           Console::text(']'));  | |
| 305 | +                            Console::text('[-l ') .  | |
| 306 | +                            Console::text('limit', 'yellow') .  | |
| 307 | +                            Console::text('] [-s ') .  | |
| 308 | +                            Console::text('score', 'yellow') .  | |
| 309 | +                            Console::text('] [-p ') .  | |
| 310 | +                            Console::text('', 'yellow') .  | |
| 311 | +                            Console::text(']'));  | |
| 312 | 312 | |
| 313 | 313 |          Console::log(' ' . Console::text('    abuseipdb -L ')); | 
| 314 | 314 |          Console::log(' ' . Console::text('    abuseipdb -G ')); | 
| @@ -864,7 +864,7 @@ discard block | ||
| 864 | 864 | |
| 865 | 865 |                      $line  = Console::text('    →', $defaultColor); | 
| 866 | 866 |                      $line .= self::printResult(' reported at: ', self::getDate($lastReport->reportedAt), $defaultColor, '', false); | 
| 867 | -              //    $line .= self::printResult(' by user: ', $lastReport->reporterId, $defaultColor, '', false); | |
| 867 | +                //    $line .= self::printResult(' by user: ', $lastReport->reporterId, $defaultColor, '', false); | |
| 868 | 868 |                      if (isset($lastReport->reporterCountryCode) && isset($lastReport->reporterCountryName)){ | 
| 869 | 869 |                          $line .= Console::text(' from: ', 'white'); | 
| 870 | 870 |                          $line .= self::printResult('', $lastReport->reporterCountryCode, $defaultColor, '', false); | 
| @@ -38,7 +38,7 @@ discard block | ||
| 38 | 38 | /** | 
| 39 | 39 | * @var string | 
| 40 | 40 | */ | 
| 41 | - const LONG_ARGUMENTS = ['config', 'list', 'blacklist', 'check:', 'check-block:', 'days:', 'report:', 'categories:', 'message:', 'limit:', 'plaintext', 'clear:','bulk-report:', 'help', 'verbose', 'score:','version']; | |
| 41 | + const LONG_ARGUMENTS = ['config', 'list', 'blacklist', 'check:', 'check-block:', 'days:', 'report:', 'categories:', 'message:', 'limit:', 'plaintext', 'clear:', 'bulk-report:', 'help', 'verbose', 'score:', 'version']; | |
| 42 | 42 | |
| 43 | 43 | /** | 
| 44 | 44 | * @var string $version | 
| @@ -53,7 +53,7 @@ discard block | ||
| 53 | 53 | /** | 
| 54 | 54 | * @var string $keyPath | 
| 55 | 55 | */ | 
| 56 | - private static $keyPath = __DIR__ .'/../config/key.json'; | |
| 56 | + private static $keyPath = __DIR__.'/../config/key.json'; | |
| 57 | 57 | |
| 58 | 58 | /** | 
| 59 | 59 | * The entry point of our app | 
| @@ -68,13 +68,13 @@ discard block | ||
| 68 | 68 | public static function start(array $arguments, string $keyPath) | 
| 69 | 69 |      { | 
| 70 | 70 | // prints help, (no need install) ? | 
| 71 | -        if (self::inArguments($arguments, 'h', 'help')){ | |
| 71 | +        if (self::inArguments($arguments, 'h', 'help')) { | |
| 72 | 72 | self::printBanner(); | 
| 73 | 73 | self::printHelp(); | 
| 74 | 74 | self::safeExit(); | 
| 75 | 75 | } | 
| 76 | 76 | // prints version? (note: no short arg) | 
| 77 | -        if (self::inArguments($arguments, 'version', 'version')){ | |
| 77 | +        if (self::inArguments($arguments, 'version', 'version')) { | |
| 78 | 78 | self::printVersion(); | 
| 79 | 79 | self::safeExit(); | 
| 80 | 80 | } | 
| @@ -82,7 +82,7 @@ discard block | ||
| 82 | 82 | // get key path from current script location (supposed in a bin folder) | 
| 83 | 83 | // and check for install then create a new instance of \ApiHandler | 
| 84 | 84 | self::$keyPath = $keyPath; // dirname(get_included_files()[0]) . '/../config/key.json'; | 
| 85 | - self::validate( self::checkForInstall(), 'Key file missing.'); | |
| 85 | + self::validate(self::checkForInstall(), 'Key file missing.'); | |
| 86 | 86 |          try { | 
| 87 | 87 | self::$api = self::fromConfigFile(self::$keyPath); | 
| 88 | 88 |          } catch (\Exception $e) { | 
| @@ -92,53 +92,53 @@ discard block | ||
| 92 | 92 | } | 
| 93 | 93 | |
| 94 | 94 | // required at least one valid argument | 
| 95 | - self::validate( !empty($arguments), 'No valid arguments given. Run abuseipdb --help to get help.'); | |
| 95 | + self::validate(!empty($arguments), 'No valid arguments given. Run abuseipdb --help to get help.'); | |
| 96 | 96 | |
| 97 | 97 | |
| 98 | 98 | // prints config ? | 
| 99 | -        if (self::inArguments($arguments, 'G', 'config')){ | |
| 99 | +        if (self::inArguments($arguments, 'G', 'config')) { | |
| 100 | 100 | self::printConfig(); | 
| 101 | 101 | self::safeExit(); | 
| 102 | 102 | } | 
| 103 | 103 | |
| 104 | 104 | // prints catgeories ? | 
| 105 | -        if (self::inArguments($arguments, 'L', 'list')){ | |
| 105 | +        if (self::inArguments($arguments, 'L', 'list')) { | |
| 106 | 106 | self::printCategories(); | 
| 107 | 107 | self::safeExit(); | 
| 108 | 108 | } | 
| 109 | 109 | |
| 110 | 110 | // check request ? | 
| 111 | -        if (self::inArguments($arguments, 'C', 'check')){ | |
| 111 | +        if (self::inArguments($arguments, 'C', 'check')) { | |
| 112 | 112 | self::checkIP($arguments); | 
| 113 | 113 | self::safeExit(); | 
| 114 | 114 | } | 
| 115 | 115 | |
| 116 | 116 | // check-block request ? | 
| 117 | -        if (self::inArguments($arguments, 'K', 'check-block')){ | |
| 117 | +        if (self::inArguments($arguments, 'K', 'check-block')) { | |
| 118 | 118 | self::checkBlock($arguments); | 
| 119 | 119 | self::safeExit(); | 
| 120 | 120 | } | 
| 121 | 121 | |
| 122 | 122 | // report request ? | 
| 123 | -        if (self::inArguments($arguments, 'R', 'report')){ | |
| 123 | +        if (self::inArguments($arguments, 'R', 'report')) { | |
| 124 | 124 | self::reportIP($arguments); | 
| 125 | 125 | self::safeExit(); | 
| 126 | 126 | } | 
| 127 | 127 | |
| 128 | 128 | // report request ? | 
| 129 | -        if (self::inArguments($arguments, 'V', 'bulk-report')){ | |
| 129 | +        if (self::inArguments($arguments, 'V', 'bulk-report')) { | |
| 130 | 130 | self::bulkReport($arguments); | 
| 131 | 131 | self::safeExit(); | 
| 132 | 132 | } | 
| 133 | 133 | |
| 134 | 134 | // report request ? | 
| 135 | -        if (self::inArguments($arguments, 'B', 'blacklist')){ | |
| 135 | +        if (self::inArguments($arguments, 'B', 'blacklist')) { | |
| 136 | 136 | self::getBlacklist($arguments); | 
| 137 | 137 | self::safeExit(); | 
| 138 | 138 | } | 
| 139 | 139 | |
| 140 | 140 | // report request ? | 
| 141 | -        if (self::inArguments($arguments, 'E', 'clear')){ | |
| 141 | +        if (self::inArguments($arguments, 'E', 'clear')) { | |
| 142 | 142 | self::clearIP($arguments); | 
| 143 | 143 | self::safeExit(); | 
| 144 | 144 | } | 
| @@ -164,21 +164,21 @@ discard block | ||
| 164 | 164 | public static function fromConfigFile(string $configPath) | 
| 165 | 165 |      { | 
| 166 | 166 | // check file exists | 
| 167 | -        if (!file_exists($configPath) || !is_file($configPath)){ | |
| 168 | -            throw new \InvalidArgumentException('The file [' . $configPath . '] does not exist.'); | |
| 167 | +        if (!file_exists($configPath) || !is_file($configPath)) { | |
| 168 | +            throw new \InvalidArgumentException('The file ['.$configPath.'] does not exist.'); | |
| 169 | 169 | } | 
| 170 | 170 | |
| 171 | 171 | // check file is readable | 
| 172 | -        if (!is_readable($configPath)){ | |
| 173 | -            throw new InvalidPermissionException('The file [' . $configPath . '] is not readable.'); | |
| 172 | +        if (!is_readable($configPath)) { | |
| 173 | +            throw new InvalidPermissionException('The file ['.$configPath.'] is not readable.'); | |
| 174 | 174 | } | 
| 175 | 175 | |
| 176 | 176 | $keyConfig = self::loadJsonFile($configPath); | 
| 177 | 177 | $selfIps = []; | 
| 178 | 178 | |
| 179 | 179 | // Look for other optional config files in the same directory | 
| 180 | - $selfIpsConfigPath = pathinfo($configPath, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR . 'self_ips.json'; | |
| 181 | -        if (file_exists($selfIpsConfigPath)){ | |
| 180 | + $selfIpsConfigPath = pathinfo($configPath, PATHINFO_DIRNAME).DIRECTORY_SEPARATOR.'self_ips.json'; | |
| 181 | +        if (file_exists($selfIpsConfigPath)) { | |
| 182 | 182 | $selfIps = self::loadJsonFile($selfIpsConfigPath)->self_ips; | 
| 183 | 183 | } | 
| 184 | 184 | |
| @@ -202,7 +202,7 @@ discard block | ||
| 202 | 202 | protected static function loadJsonFile(string $filePath, bool $throwError = true) | 
| 203 | 203 |      { | 
| 204 | 204 | // check file exists | 
| 205 | -        if (!file_exists($filePath) || !is_file($filePath)){ | |
| 205 | +        if (!file_exists($filePath) || !is_file($filePath)) { | |
| 206 | 206 |             if ($throwError) { | 
| 207 | 207 |                  throw new \Exception('Config file not found'); | 
| 208 | 208 | } | 
| @@ -238,23 +238,23 @@ discard block | ||
| 238 | 238 | // not installed | 
| 239 | 239 | self::printBanner(); | 
| 240 | 240 |          Console::log(' Your config key file was not found. Do you want to create it? ', 'white'); | 
| 241 | -        $create =  Console::ask(' Press Y/y to create a config key file: ', 'white'); | |
| 241 | +        $create = Console::ask(' Press Y/y to create a config key file: ', 'white'); | |
| 242 | 242 | |
| 243 | 243 |          if ($create == 'Y' || $create == 'y') { | 
| 244 | -            $key =     Console::ask(' - Please enter your api key: ', 'white'); | |
| 245 | -            $create =  Console::ask(' A config file will be created in config/ directory. Press Y/y to continue: ', 'white'); | |
| 244 | +            $key = Console::ask(' - Please enter your api key: ', 'white'); | |
| 245 | +            $create = Console::ask(' A config file will be created in config/ directory. Press Y/y to continue: ', 'white'); | |
| 246 | 246 | |
| 247 | 247 |              if ($create == 'Y' || $create == 'y') { | 
| 248 | 248 | $data = json_encode(['api_key' => $key]); | 
| 249 | 249 | |
| 250 | -                if (file_put_contents(self::$keyPath, $data, LOCK_EX) === false){ | |
| 250 | +                if (file_put_contents(self::$keyPath, $data, LOCK_EX) === false) { | |
| 251 | 251 |                      self::error('An error occured during writing config file. Make sure to give the appropriate permissions do the config directory.'); | 
| 252 | 252 | return false; | 
| 253 | 253 | } | 
| 254 | 254 | |
| 255 | 255 | // successfull. print message and exit to prevent errors with no arguments | 
| 256 | 256 | Console::log(); | 
| 257 | -                Console::log(Console::text('  ✓ ', 'green') . Console::text('Your config file has been successfully created.', 'white')); | |
| 257 | +                Console::log(Console::text('  ✓ ', 'green').Console::text('Your config file has been successfully created.', 'white')); | |
| 258 | 258 |                  Console::log('    You can now use abuseipdb.', 'white'); | 
| 259 | 259 | Console::log(); | 
| 260 | 260 | self::safeExit(); | 
| @@ -274,47 +274,47 @@ discard block | ||
| 274 | 274 | */ | 
| 275 | 275 | protected static function printHelp() | 
| 276 | 276 |      { | 
| 277 | -        Console::log(' ' . Console::text('SYNOPSIS:', 'white', 'underline'));  | |
| 278 | -        Console::log(' ' . Console::text('    abuseipdb -C ') .  | |
| 279 | -                           Console::text('ip', 'yellow') .  | |
| 280 | -                           Console::text(' [-d ') .  | |
| 281 | -                           Console::text('days', 'yellow') .  | |
| 282 | -                           Console::text('] [-v] [-l ') .  | |
| 283 | -                           Console::text('limit', 'yellow') .  | |
| 277 | +        Console::log(' '.Console::text('SYNOPSIS:', 'white', 'underline'));  | |
| 278 | +        Console::log(' '.Console::text('    abuseipdb -C ').  | |
| 279 | +                           Console::text('ip', 'yellow').  | |
| 280 | +                           Console::text(' [-d ').  | |
| 281 | +                           Console::text('days', 'yellow').  | |
| 282 | +                           Console::text('] [-v] [-l ').  | |
| 283 | +                           Console::text('limit', 'yellow').  | |
| 284 | 284 |                             Console::text(']'));  | 
| 285 | 285 | |
| 286 | -        Console::log(' ' . Console::text('    abuseipdb -K ') .  | |
| 287 | -                           Console::text('network', 'yellow') .  | |
| 288 | -                           Console::text(' [-d ') .  | |
| 289 | -                           Console::text('days', 'yellow') .  | |
| 286 | +        Console::log(' '.Console::text('    abuseipdb -K ').  | |
| 287 | +                           Console::text('network', 'yellow').  | |
| 288 | +                           Console::text(' [-d ').  | |
| 289 | +                           Console::text('days', 'yellow').  | |
| 290 | 290 |                             Console::text(']'));  | 
| 291 | 291 | |
| 292 | -        Console::log(' ' . Console::text('    abuseipdb -R ' . | |
| 293 | -                           Console::text('ip', 'yellow') . ' -c ' . | |
| 294 | -                           Console::text('categories', 'yellow') . ' -m ' . | |
| 292 | +        Console::log(' '.Console::text('    abuseipdb -R '. | |
| 293 | +                           Console::text('ip', 'yellow').' -c '. | |
| 294 | +                           Console::text('categories', 'yellow').' -m '. | |
| 295 | 295 |                             Console::text('message', 'yellow')));  | 
| 296 | 296 | |
| 297 | -        Console::log(' ' . Console::text('    abuseipdb -V ' . | |
| 297 | +        Console::log(' '.Console::text('    abuseipdb -V '. | |
| 298 | 298 |                             Console::text('path', 'yellow'))); | 
| 299 | 299 | |
| 300 | -        Console::log(' ' . Console::text('    abuseipdb -E ' . | |
| 300 | +        Console::log(' '.Console::text('    abuseipdb -E '. | |
| 301 | 301 |                             Console::text('ip', 'yellow'))); | 
| 302 | 302 | |
| 303 | -        Console::log(' ' . Console::text('    abuseipdb -B ') .  | |
| 304 | -                           Console::text('[-l ') .  | |
| 305 | -                           Console::text('limit', 'yellow') .  | |
| 306 | -                           Console::text('] [-s ') .  | |
| 307 | -                           Console::text('score', 'yellow') .  | |
| 308 | -                           Console::text('] [-p ') .  | |
| 309 | -                           Console::text('', 'yellow') .  | |
| 303 | +        Console::log(' '.Console::text('    abuseipdb -B ').  | |
| 304 | +                           Console::text('[-l ').  | |
| 305 | +                           Console::text('limit', 'yellow').  | |
| 306 | +                           Console::text('] [-s ').  | |
| 307 | +                           Console::text('score', 'yellow').  | |
| 308 | +                           Console::text('] [-p ').  | |
| 309 | +                           Console::text('', 'yellow').  | |
| 310 | 310 |                             Console::text(']'));  | 
| 311 | 311 | |
| 312 | -        Console::log(' ' . Console::text('    abuseipdb -L ')); | |
| 313 | -        Console::log(' ' . Console::text('    abuseipdb -G ')); | |
| 314 | -        Console::log(' ' . Console::text('    abuseipdb -h ')); | |
| 312 | +        Console::log(' '.Console::text('    abuseipdb -L ')); | |
| 313 | +        Console::log(' '.Console::text('    abuseipdb -G ')); | |
| 314 | +        Console::log(' '.Console::text('    abuseipdb -h ')); | |
| 315 | 315 | |
| 316 | 316 | Console::log(); | 
| 317 | -        Console::log(' ' . Console::text('OPTIONS:', 'white', 'underline'));  | |
| 317 | +        Console::log(' '.Console::text('OPTIONS:', 'white', 'underline'));  | |
| 318 | 318 | Console::log(); | 
| 319 | 319 |          Console::log(Console::text('   -h, --help', 'white'));  | 
| 320 | 320 |          Console::log('       Prints the current help. If given, all next arguments are ignored.', 'lightgray'); | 
| @@ -325,39 +325,39 @@ discard block | ||
| 325 | 325 |          Console::log(Console::text('   -L, --list', 'white'));  | 
| 326 | 326 |          Console::log('       Prints the list report categories. If given, all next arguments are ignored.', 'lightgray'); | 
| 327 | 327 | Console::log(); | 
| 328 | -        Console::log(Console::text('   -C, --check ', 'white') . Console::text('ip', 'yellow', 'underline'));  | |
| 328 | +        Console::log(Console::text('   -C, --check ', 'white').Console::text('ip', 'yellow', 'underline'));  | |
| 329 | 329 |          Console::log('       Performs a check request for the given IP address. A valid IPv4 or IPv6 address is required.', 'lightgray'); | 
| 330 | 330 | Console::log(); | 
| 331 | -        Console::log(Console::text('   -K, --check-block ', 'white') . Console::text('network', 'yellow', 'underline'));  | |
| 331 | +        Console::log(Console::text('   -K, --check-block ', 'white').Console::text('network', 'yellow', 'underline'));  | |
| 332 | 332 |          Console::log('       Performs a check-block request for the given network. A valid subnet (v4 or v6) denoted with ', 'lightgray'); | 
| 333 | 333 |          Console::log('       CIDR notation is required.', 'lightgray'); | 
| 334 | 334 | Console::log(); | 
| 335 | -        Console::log(Console::text('   -d, --days ', 'white') . Console::text('days', 'yellow', 'underline'));  | |
| 335 | +        Console::log(Console::text('   -d, --days ', 'white').Console::text('days', 'yellow', 'underline'));  | |
| 336 | 336 |          Console::log('       For a check or check-block request, defines the maxAgeDays. Min is 1, max is 365, default is 30.', 'lightgray'); | 
| 337 | 337 | Console::log(); | 
| 338 | -        Console::log(Console::text('   -R, --report ', 'white') . Console::text('ip', 'yellow', 'underline'));  | |
| 338 | +        Console::log(Console::text('   -R, --report ', 'white').Console::text('ip', 'yellow', 'underline'));  | |
| 339 | 339 |          Console::log('       Performs a report request for the given IP address. A valid IPv4 or IPv6 address is required.', 'lightgray'); | 
| 340 | 340 | Console::log(); | 
| 341 | -        Console::log(Console::text('   -V, --bulk-report ', 'white') . Console::text('path', 'yellow', 'underline'));  | |
| 341 | +        Console::log(Console::text('   -V, --bulk-report ', 'white').Console::text('path', 'yellow', 'underline'));  | |
| 342 | 342 |          Console::log('       Performs a bulk-report request sending a csv file. A valid file name or full path is required.', 'lightgray'); | 
| 343 | 343 | Console::log(); | 
| 344 | 344 |          Console::log(Console::text('   -E, --clear ', 'white'));  | 
| 345 | 345 |          Console::log('       Remove own reports for the given IP address. A valid IPv4 or IPv6 address is required.', 'lightgray'); | 
| 346 | 346 | Console::log(); | 
| 347 | -        Console::log(Console::text('   -c, --categories ', 'white') . Console::text('categories', 'yellow', 'underline'));  | |
| 347 | +        Console::log(Console::text('   -c, --categories ', 'white').Console::text('categories', 'yellow', 'underline'));  | |
| 348 | 348 |          Console::log('       For a report request, defines the report category(ies). Categories must be separate by a comma.', 'lightgray'); | 
| 349 | 349 |          Console::log('       Some categories cannot be used alone. A category can be represented by its shortname or by its', 'lightgray'); | 
| 350 | -        Console::log(Console::text('       id. Use ','lightgray')  . Console::text('abuseipdb -L', 'white') . Console::text(' to print the categories list.','lightgray')); | |
| 350 | +        Console::log(Console::text('       id. Use ', 'lightgray').Console::text('abuseipdb -L', 'white').Console::text(' to print the categories list.', 'lightgray')); | |
| 351 | 351 | Console::log(); | 
| 352 | -        Console::log(Console::text('   -m, --message ', 'white') . Console::text('message', 'yellow', 'underline'));  | |
| 352 | +        Console::log(Console::text('   -m, --message ', 'white').Console::text('message', 'yellow', 'underline'));  | |
| 353 | 353 |          Console::log('       For a report request, defines the message to send with report. Message is required for all', 'lightgray'); | 
| 354 | 354 |          Console::log('       report requests.', 'lightgray'); | 
| 355 | 355 | Console::log(); | 
| 356 | 356 |          Console::log(Console::text('   -B, --blacklist ', 'white'));  | 
| 357 | 357 |          Console::log('       Performs a blacklist request. Default limit is 1000. This limit can ne changed with the', 'lightgray'); | 
| 358 | -        Console::log('       ' . Console::text('--limit', 'white') . Console::text(' parameter. ', 'lightgray')); | |
| 358 | +        Console::log('       '.Console::text('--limit', 'white').Console::text(' parameter. ', 'lightgray')); | |
| 359 | 359 | Console::log(); | 
| 360 | -        Console::log(Console::text('   -l, --limit ', 'white') . Console::text('limit', 'yellow', 'underline'));  | |
| 360 | +        Console::log(Console::text('   -l, --limit ', 'white').Console::text('limit', 'yellow', 'underline'));  | |
| 361 | 361 |          Console::log('       For a blacklist request, defines the limit.', 'lightgray'); | 
| 362 | 362 |          Console::log('       For a check request with verbose flag, sets the max number of last reports displayed. Default is 10', 'lightgray'); | 
| 363 | 363 |          Console::log('       For a check-block request, sets the max number of IPs displayed. Default is 0 (no limit).', 'lightgray'); | 
| @@ -372,7 +372,7 @@ discard block | ||
| 372 | 372 |          Console::log(Console::text('   -v, --verbose ', 'white'));  | 
| 373 | 373 |          Console::log('       For a check request, display additional fields like the x last reports. This increases ', 'lightgray'); | 
| 374 | 374 |          Console::log(Console::text('       request time and response size. Max number of last reports displayed can be changed with the ', 'lightgray')); | 
| 375 | -        Console::log('       ' . Console::text('--limit', 'white') . Console::text(' parameter. ', 'lightgray')); | |
| 375 | +        Console::log('       '.Console::text('--limit', 'white').Console::text(' parameter. ', 'lightgray')); | |
| 376 | 376 | Console::log(); | 
| 377 | 377 |          Console::log(Console::text('   --version', 'white'));  | 
| 378 | 378 |          Console::log('       Prints the current version. If given, all next arguments are ignored.', 'lightgray'); | 
| @@ -393,11 +393,11 @@ discard block | ||
| 393 | 393 | |
| 394 | 394 |          self::printTitle(Console::text('  ► Current configuration ', 'darkgray')); | 
| 395 | 395 | |
| 396 | -        Console::log(Console::text('  api_key:[', 'white') . Console::text($conf['apiKey'], 'green') . Console::text(']', 'white')); | |
| 396 | +        Console::log(Console::text('  api_key:[', 'white').Console::text($conf['apiKey'], 'green').Console::text(']', 'white')); | |
| 397 | 397 |          Console::log(Console::text('  self_ips:', 'white')); | 
| 398 | 398 | |
| 399 | 399 |          foreach ($conf['selfIps'] as $ip) { | 
| 400 | -            Console::log(Console::text('    [', 'white') . Console::text($ip, 'green') . Console::text(']', 'white'));    | |
| 400 | +            Console::log(Console::text('    [', 'white').Console::text($ip, 'green').Console::text(']', 'white'));    | |
| 401 | 401 | } | 
| 402 | 402 | |
| 403 | 403 | Console::log(); | 
| @@ -418,10 +418,10 @@ discard block | ||
| 418 | 418 | |
| 419 | 419 | $categories = self::$api->getCategories(); | 
| 420 | 420 | $rowHeaders = [ | 
| 421 | -            Console::text('ShortName',      'darkgray') => 15,  | |
| 422 | -            Console::text('Id',             'darkgray') => 2,  | |
| 423 | -            Console::text('Full name',      'darkgray') => 18, | |
| 424 | -            Console::text('Can be alone?',  'darkgray') => 15 | |
| 421 | +            Console::text('ShortName', 'darkgray') => 15,  | |
| 422 | +            Console::text('Id', 'darkgray') => 2,  | |
| 423 | +            Console::text('Full name', 'darkgray') => 18, | |
| 424 | +            Console::text('Can be alone?', 'darkgray') => 15 | |
| 425 | 425 | ]; | 
| 426 | 426 | Console::$verticalSeparator = ' '; | 
| 427 | 427 | Console::$verticalInnerSeparator = ' '; | 
| @@ -431,17 +431,16 @@ discard block | ||
| 431 | 431 | |
| 432 | 432 |          foreach ($categories as $cat) { | 
| 433 | 433 | $id = Console::text($cat[1], 'white'); | 
| 434 | -            $standalone = $cat[3] ? Console::text('✓', 'green') . Console::text(' true ', 'lightgray') :  | |
| 435 | -                                    Console::text('✗', 'red')   . Console::text(' false', 'darkgray'); | |
| 436 | - $shortName = Console::text($cat[0], 'white'); | |
| 437 | - $fullName = Console::text($cat[2], 'lightgray'); | |
| 434 | +            $standalone = $cat[3] ? Console::text('✓', 'green').Console::text(' true ', 'lightgray') : Console::text('✗', 'red').Console::text(' false', 'darkgray'); | |
| 435 | + $shortName = Console::text($cat[0], 'white'); | |
| 436 | + $fullName = Console::text($cat[2], 'lightgray'); | |
| 438 | 437 | |
| 439 | 438 | Console::log( | 
| 440 | 439 | Console::TableRowStart(). | 
| 441 | - Console::TableRowCell( $shortName , 15). | |
| 442 | - Console::TableRowCell( $id , 2, Console::ALIGN_CENTER). | |
| 443 | - Console::TableRowCell( $fullName , 18). | |
| 444 | - Console::TableRowCell( $standalone , 15, Console::ALIGN_CENTER) | |
| 440 | + Console::TableRowCell($shortName, 15). | |
| 441 | + Console::TableRowCell($id, 2, Console::ALIGN_CENTER). | |
| 442 | + Console::TableRowCell($fullName, 18). | |
| 443 | + Console::TableRowCell($standalone, 15, Console::ALIGN_CENTER) | |
| 445 | 444 | ); | 
| 446 | 445 | } | 
| 447 | 446 | //Console::log(Console::tableRowSeparator($rowHeaders), 'darkgray'); | 
| @@ -460,11 +459,11 @@ discard block | ||
| 460 | 459 | */ | 
| 461 | 460 | protected static function reportIP(array $arguments) | 
| 462 | 461 |      { | 
| 463 | - $ip = self::getArgumentValue($arguments,'R', 'report'); | |
| 464 | - $cats = self::getArgumentValue($arguments,'c', 'categories'); | |
| 465 | - $message = self::getArgumentValue($arguments,'m', 'message'); | |
| 462 | + $ip = self::getArgumentValue($arguments, 'R', 'report'); | |
| 463 | + $cats = self::getArgumentValue($arguments, 'c', 'categories'); | |
| 464 | + $message = self::getArgumentValue($arguments, 'm', 'message'); | |
| 466 | 465 | |
| 467 | -        self::printTitle(Console::text('  ► Report IP: ', 'darkgray') . Console::text(escapeshellcmd($ip), 'white')); | |
| 466 | +        self::printTitle(Console::text('  ► Report IP: ', 'darkgray').Console::text(escapeshellcmd($ip), 'white')); | |
| 468 | 467 | self::printTempMessage(); | 
| 469 | 468 | |
| 470 | 469 | // Peforms request | 
| @@ -475,7 +474,7 @@ discard block | ||
| 475 | 474 | self::clearTempMessage(); | 
| 476 | 475 | |
| 477 | 476 | // check for errors / empty response | 
| 478 | -        if (self::printErrors($report)){ | |
| 477 | +        if (self::printErrors($report)) { | |
| 479 | 478 | self::printFooter(); | 
| 480 | 479 | self::safeExit(1); | 
| 481 | 480 | } | 
| @@ -484,12 +483,12 @@ discard block | ||
| 484 | 483 | $score = empty($report->data->abuseConfidenceScore) ? 0 : $report->data->abuseConfidenceScore; | 
| 485 | 484 | $scoreColor = self::getScoreColor($score); | 
| 486 | 485 | Console::log( | 
| 487 | -            Console::text('   ✓', 'green') .  | |
| 488 | -            Console::text(' IP: [', 'white') . | |
| 489 | - Console::text($ip, $scoreColor) . | |
| 486 | +            Console::text('   ✓', 'green').  | |
| 487 | +            Console::text(' IP: [', 'white'). | |
| 488 | + Console::text($ip, $scoreColor). | |
| 490 | 489 |              Console::text('] successfully reported', 'white') | 
| 491 | 490 | ); | 
| 492 | -        Console::log(Console::text('     Confidence score: ', 'white') . self::getScoreBadge($score)); | |
| 491 | +        Console::log(Console::text('     Confidence score: ', 'white').self::getScoreBadge($score)); | |
| 493 | 492 | |
| 494 | 493 | Console::log(); | 
| 495 | 494 | self::printFooter($time); | 
| @@ -506,28 +505,28 @@ discard block | ||
| 506 | 505 | */ | 
| 507 | 506 | protected static function bulkReport(array $arguments) | 
| 508 | 507 |      { | 
| 509 | - $fileName = self::getArgumentValue($arguments,'V', 'bulk-report'); | |
| 508 | + $fileName = self::getArgumentValue($arguments, 'V', 'bulk-report'); | |
| 510 | 509 | |
| 511 | -        self::printTitle(Console::text('  ► Bulk report for file: ', 'darkgray') . Console::text(escapeshellcmd($fileName), 'white')); | |
| 510 | +        self::printTitle(Console::text('  ► Bulk report for file: ', 'darkgray').Console::text(escapeshellcmd($fileName), 'white')); | |
| 512 | 511 | self::printTempMessage(); | 
| 513 | 512 | |
| 514 | 513 | // Peforms request | 
| 515 | 514 | $timeStart = microtime(true); | 
| 516 | 515 | $response = self::$api->bulkReport($fileName)->getObject(); | 
| 517 | 516 | $timeEnd = microtime(true); | 
| 518 | - $time = $timeEnd - $timeStart; // request time | |
| 517 | + $time = $timeEnd - $timeStart; // request time | |
| 519 | 518 | self::clearTempMessage(); | 
| 520 | 519 | |
| 521 | 520 | // check for errors / empty response | 
| 522 | -        if (self::printErrors($response)){ | |
| 521 | +        if (self::printErrors($response)) { | |
| 523 | 522 | self::printFooter(); | 
| 524 | 523 | self::safeExit(1); | 
| 525 | 524 | } | 
| 526 | 525 | |
| 527 | 526 | // ✓ Done | 
| 528 | 527 | Console::log( | 
| 529 | -            Console::text('   Bulk report for file: [', 'white') . | |
| 530 | - Console::text($fileName, 'lightyellow') . | |
| 528 | +            Console::text('   Bulk report for file: [', 'white'). | |
| 529 | + Console::text($fileName, 'lightyellow'). | |
| 531 | 530 |              Console::text('] done!', 'white') | 
| 532 | 531 | ); | 
| 533 | 532 | |
| @@ -538,14 +537,14 @@ discard block | ||
| 538 | 537 | $savedIcon = $nbSavedReports > 0 ? '✓' : '✗'; | 
| 539 | 538 | $errorIcon = $nbErrorReports > 0 ? '✗' : '✓'; | 
| 540 | 539 | |
| 541 | -        Console::log(Console::text('   ' . $savedIcon, $savedColor) . self::printResult(' Saved reports:    ', $nbSavedReports, $savedColor, '', false)); | |
| 542 | -        Console::log(Console::text('   ' . $errorIcon, $errorColor) . self::printResult(' Invalid reports:  ', $nbErrorReports, $errorColor, '', false)); | |
| 540 | +        Console::log(Console::text('   '.$savedIcon, $savedColor).self::printResult(' Saved reports:    ', $nbSavedReports, $savedColor, '', false)); | |
| 541 | +        Console::log(Console::text('   '.$errorIcon, $errorColor).self::printResult(' Invalid reports:  ', $nbErrorReports, $errorColor, '', false)); | |
| 543 | 542 | |
| 544 | -        if ($nbErrorReports > 0){ | |
| 543 | +        if ($nbErrorReports > 0) { | |
| 545 | 544 | $numberDiplayedReports = 0; | 
| 546 | 545 | $defaultColor = 'lightyellow'; // reset color for last reports | 
| 547 | 546 | |
| 548 | -            foreach ($response->data->invalidReports as $report){ | |
| 547 | +            foreach ($response->data->invalidReports as $report) { | |
| 549 | 548 | $input = $report->input ? escapeshellcmd($report->input) : ''; // in case on blank line, IP is null | 
| 550 | 549 |                  $line  = Console::text('      →', 'red'); | 
| 551 | 550 |                  $line .= self::printResult(' Input:         ', $input, $defaultColor, '', false); | 
| @@ -572,29 +571,29 @@ discard block | ||
| 572 | 571 | */ | 
| 573 | 572 | protected static function clearIP(array $arguments) | 
| 574 | 573 |      { | 
| 575 | - $ip = self::getArgumentValue($arguments,'E', 'clear'); | |
| 574 | + $ip = self::getArgumentValue($arguments, 'E', 'clear'); | |
| 576 | 575 | |
| 577 | -        self::printTitle(Console::text('  ► Clear reports for IP: ', 'darkgray') . Console::text(escapeshellcmd($ip), 'white')); | |
| 576 | +        self::printTitle(Console::text('  ► Clear reports for IP: ', 'darkgray').Console::text(escapeshellcmd($ip), 'white')); | |
| 578 | 577 | |
| 579 | 578 | // Peforms request | 
| 580 | 579 | self::printTempMessage(); | 
| 581 | 580 | $timeStart = microtime(true); // request startime | 
| 582 | 581 | $response = self::$api->clearAddress($ip)->getObject(); | 
| 583 | - $timeEnd = microtime(true); // request end time | |
| 582 | + $timeEnd = microtime(true); // request end time | |
| 584 | 583 | $time = $timeEnd - $timeStart; // request time | 
| 585 | 584 | self::clearTempMessage(); | 
| 586 | 585 | |
| 587 | 586 | // check for errors / empty response | 
| 588 | -        if (self::printErrors($response)){ | |
| 587 | +        if (self::printErrors($response)) { | |
| 589 | 588 | self::printFooter($time); | 
| 590 | 589 | self::safeExit(1); | 
| 591 | 590 | } | 
| 592 | 591 | |
| 593 | 592 | // ✓ Done: print deleted report number | 
| 594 | 593 | Console::log( | 
| 595 | -            Console::text('   ✓', 'green') .  | |
| 596 | -            Console::text(' Successfull clear request for IP: [', 'white') . | |
| 597 | - Console::text($ip, 'lightyellow') . | |
| 594 | +            Console::text('   ✓', 'green').  | |
| 595 | +            Console::text(' Successfull clear request for IP: [', 'white'). | |
| 596 | + Console::text($ip, 'lightyellow'). | |
| 598 | 597 |              Console::text(']', 'white') | 
| 599 | 598 | ); | 
| 600 | 599 | |
| @@ -614,42 +613,42 @@ discard block | ||
| 614 | 613 | */ | 
| 615 | 614 | protected static function getBlacklist(array $arguments) | 
| 616 | 615 |      { | 
| 617 | - $plainText = self::inArguments($arguments,'p','plaintext'); | |
| 616 | + $plainText = self::inArguments($arguments, 'p', 'plaintext'); | |
| 618 | 617 | |
| 619 | -        if (!$plainText){ | |
| 618 | +        if (!$plainText) { | |
| 620 | 619 |              self::printTitle(Console::text('  ► Get Blacklist ', 'darkgray')); | 
| 621 | 620 | } | 
| 622 | 621 | |
| 623 | - $limit = self::getNumericParameter($arguments,'l', 'limit', 1000); | |
| 624 | - $scoreMin = self::getNumericParameter($arguments,'s', 'score', 100); | |
| 622 | + $limit = self::getNumericParameter($arguments, 'l', 'limit', 1000); | |
| 623 | + $scoreMin = self::getNumericParameter($arguments, 's', 'score', 100); | |
| 625 | 624 | |
| 626 | -        if (!$plainText){ | |
| 625 | +        if (!$plainText) { | |
| 627 | 626 | self::printTempMessage(); | 
| 628 | 627 | } | 
| 629 | 628 | |
| 630 | 629 | // do request | 
| 631 | - $timeStart = microtime(true); // request startime | |
| 632 | - $response = self::$api->blacklist($limit, $plainText, $scoreMin); // perform request | |
| 633 | - $timeEnd = microtime(true); // request end time | |
| 634 | - $time = $timeEnd - $timeStart; // request time | |
| 630 | + $timeStart = microtime(true); // request startime | |
| 631 | + $response = self::$api->blacklist($limit, $plainText, $scoreMin); // perform request | |
| 632 | + $timeEnd = microtime(true); // request end time | |
| 633 | + $time = $timeEnd - $timeStart; // request time | |
| 635 | 634 | |
| 636 | -        if (!$plainText){ | |
| 635 | +        if (!$plainText) { | |
| 637 | 636 | self::clearTempMessage(); | 
| 638 | 637 | } | 
| 639 | 638 | |
| 640 | 639 | // response could be json on error, while plaintext flag is set | 
| 641 | 640 | $decodedResponse = $response->getObject(); | 
| 642 | 641 | |
| 643 | -        if ($plainText && $response->hasError()){ | |
| 642 | +        if ($plainText && $response->hasError()) { | |
| 644 | 643 | self::safeExit(1); | 
| 645 | 644 | } | 
| 646 | 645 | |
| 647 | -        if (!$plainText && self::printErrors($decodedResponse)){ | |
| 646 | +        if (!$plainText && self::printErrors($decodedResponse)) { | |
| 648 | 647 | self::printFooter($time); | 
| 649 | 648 | self::safeExit(1); | 
| 650 | 649 | } | 
| 651 | 650 | |
| 652 | -        if ($plainText){ | |
| 651 | +        if ($plainText) { | |
| 653 | 652 | // echo response "as is" | 
| 654 | 653 | Console::log($response->getPlaintext()); | 
| 655 | 654 | |
| @@ -658,7 +657,7 @@ discard block | ||
| 658 | 657 |              self::printResult('  List generated at: ', self::getDate($decodedResponse->meta->generatedAt), 'lightyellow', ''); | 
| 659 | 658 | Console::log(); | 
| 660 | 659 | |
| 661 | -            foreach ($decodedResponse->data as $report){ | |
| 660 | +            foreach ($decodedResponse->data as $report) { | |
| 662 | 661 | $score = empty($report->abuseConfidenceScore) ? 0 : $report->abuseConfidenceScore; | 
| 663 | 662 | $defaultColor = self::getScoreColor($score); | 
| 664 | 663 | |
| @@ -687,12 +686,12 @@ discard block | ||
| 687 | 686 | */ | 
| 688 | 687 | protected static function checkBlock($arguments) | 
| 689 | 688 |      { | 
| 690 | - $network = self::getArgumentValue($arguments,'K', 'check-block'); | |
| 689 | + $network = self::getArgumentValue($arguments, 'K', 'check-block'); | |
| 691 | 690 | |
| 692 | -        self::printTitle(Console::text('  ► Check network: ', 'darkgray') . Console::text(escapeshellcmd($network), 'white') . Console::text('', 'darkgray')); | |
| 691 | +        self::printTitle(Console::text('  ► Check network: ', 'darkgray').Console::text(escapeshellcmd($network), 'white').Console::text('', 'darkgray')); | |
| 693 | 692 | |
| 694 | 693 | $maxAge = self::getNumericParameter($arguments, 'd', 'days', 30); | 
| 695 | - $limit = self::getNumericParameter($arguments,'l', 'limit', 0); // 0 mean no limit | |
| 694 | + $limit = self::getNumericParameter($arguments, 'l', 'limit', 0); // 0 mean no limit | |
| 696 | 695 | |
| 697 | 696 | self::printTempMessage(); | 
| 698 | 697 | |
| @@ -703,7 +702,7 @@ discard block | ||
| 703 | 702 | self::clearTempMessage(); | 
| 704 | 703 | |
| 705 | 704 | // check for errors / empty response | 
| 706 | -        if (self::printErrors($check)){ | |
| 705 | +        if (self::printErrors($check)) { | |
| 707 | 706 | self::printFooter($time); | 
| 708 | 707 | self::safeExit(1); | 
| 709 | 708 | } | 
| @@ -718,18 +717,18 @@ discard block | ||
| 718 | 717 | // print reported addresses | 
| 719 | 718 | $nbReports = isset($check->data->reportedAddress) ? count($check->data->reportedAddress) : 0; | 
| 720 | 719 | |
| 721 | -        if ($nbReports > 0){ | |
| 720 | +        if ($nbReports > 0) { | |
| 722 | 721 |              self::printResult(Console::pad('   Reported addresses:', 23), $nbReports, 'lightyellow'); | 
| 723 | 722 | $numberDiplayedReports = 0; | 
| 724 | 723 | $defaultColor = 'lightyellow'; // reset color for last reports | 
| 725 | 724 | |
| 726 | -            foreach ($check->data->reportedAddress as $report){ | |
| 725 | +            foreach ($check->data->reportedAddress as $report) { | |
| 727 | 726 | $score = empty($report->abuseConfidenceScore) ? 0 : $report->abuseConfidenceScore; | 
| 728 | 727 | $defaultColor = self::getScoreColor($score); // color based on score | 
| 729 | 728 | |
| 730 | 729 |                  $line  = Console::text('   →', $defaultColor); | 
| 731 | 730 |                  $line .= self::printResult(' IP: ', $report->ipAddress, $defaultColor, '', false); | 
| 732 | -                $line .= self::printResult(' Country: ', $report->countryCode , $defaultColor, '', false); | |
| 731 | +                $line .= self::printResult(' Country: ', $report->countryCode, $defaultColor, '', false); | |
| 733 | 732 |                  $line .= Console::text(' | Confidence score: ', 'white'); | 
| 734 | 733 | $line .= self::getScoreBadge($score); | 
| 735 | 734 |                  $line .= self::printResult(' Total reports: ', $report->numReports, $defaultColor, '', false); | 
| @@ -744,7 +743,7 @@ discard block | ||
| 744 | 743 | $line .= Console::text($numberDiplayedReports, 'lightyellow'); | 
| 745 | 744 |                      $line .= Console::text('/', 'white'); | 
| 746 | 745 | $line .= Console::text($nbReports, 'lightyellow'); | 
| 747 | - $line .= Console::text($numberDiplayedReports > 1 ? ' IPs displayed)': ' IP displayed)', 'white'); | |
| 746 | + $line .= Console::text($numberDiplayedReports > 1 ? ' IPs displayed)' : ' IP displayed)', 'white'); | |
| 748 | 747 | Console::log($line); | 
| 749 | 748 | break; | 
| 750 | 749 | } | 
| @@ -752,8 +751,8 @@ discard block | ||
| 752 | 751 | |
| 753 | 752 |          } else { | 
| 754 | 753 | // no reports | 
| 755 | - $day = $maxAge > 1 ? 'in last '. $maxAge . ' days': ' today'; | |
| 756 | -            Console::log( Console::text('    ✓', 'green') . Console::text(' No IP reported ' . $day)); | |
| 754 | + $day = $maxAge > 1 ? 'in last '.$maxAge.' days' : ' today'; | |
| 755 | +            Console::log(Console::text('    ✓', 'green').Console::text(' No IP reported '.$day)); | |
| 757 | 756 | } | 
| 758 | 757 | |
| 759 | 758 | // footer | 
| @@ -772,13 +771,13 @@ discard block | ||
| 772 | 771 | */ | 
| 773 | 772 | protected static function checkIP($arguments) | 
| 774 | 773 |      { | 
| 775 | - $ip = self::getArgumentValue($arguments,'C', 'check'); | |
| 774 | + $ip = self::getArgumentValue($arguments, 'C', 'check'); | |
| 776 | 775 | |
| 777 | -        self::printTitle(Console::text('  ► Check IP: ', 'darkgray') . Console::text(escapeshellcmd($ip), 'white') . Console::text('', 'darkgray')); | |
| 776 | +        self::printTitle(Console::text('  ► Check IP: ', 'darkgray').Console::text(escapeshellcmd($ip), 'white').Console::text('', 'darkgray')); | |
| 778 | 777 | |
| 779 | - $verbose = self::inArguments($arguments,'v', 'verbose'); | |
| 778 | + $verbose = self::inArguments($arguments, 'v', 'verbose'); | |
| 780 | 779 | $maxAge = self::getNumericParameter($arguments, 'd', 'days', 30); | 
| 781 | - $maxReportsNumber = self::getNumericParameter($arguments,'l', 'limit', 10); | |
| 780 | + $maxReportsNumber = self::getNumericParameter($arguments, 'l', 'limit', 10); | |
| 782 | 781 | |
| 783 | 782 | self::printTempMessage(); | 
| 784 | 783 | |
| @@ -789,7 +788,7 @@ discard block | ||
| 789 | 788 | self::clearTempMessage(); | 
| 790 | 789 | |
| 791 | 790 | // check for errors / empty response | 
| 792 | -        if (self::printErrors($check)){ | |
| 791 | +        if (self::printErrors($check)) { | |
| 793 | 792 | self::printFooter($time); | 
| 794 | 793 | self::safeExit(1); | 
| 795 | 794 | } | 
| @@ -803,26 +802,26 @@ discard block | ||
| 803 | 802 | |
| 804 | 803 |  //      self::printResult('   isPublic', $check->data->isPublic, $defaultColor); | 
| 805 | 804 |  //      self::printResult('   ipVersion', $check->data->ipVersion, $defaultColor); | 
| 806 | -        $line = self::printResult(Console::pad('   Whitelisted:', 23), $check->data->isWhitelisted ? 'true': 'false', $defaultColor, '', false); | |
| 805 | +        $line = self::printResult(Console::pad('   Whitelisted:', 23), $check->data->isWhitelisted ? 'true' : 'false', $defaultColor, '', false); | |
| 807 | 806 |          $line .= $check->data->isWhitelisted ? Console::text(' ★', 'green') : '';  | 
| 808 | 807 | Console::log($line); | 
| 809 | 808 | |
| 810 | 809 |          self::printResult(Console::pad('   Country code:', 23), $check->data->countryCode, $defaultColor); | 
| 811 | 810 | |
| 812 | -        if (!empty($check->data->countryName)){ | |
| 811 | +        if (!empty($check->data->countryName)) { | |
| 813 | 812 |              self::printResult(Console::pad('   Country name:', 23), $check->data->countryName, $defaultColor); | 
| 814 | 813 | } | 
| 815 | 814 | |
| 816 | 815 |          self::printResult(Console::pad('   ISP:', 23), $check->data->isp, $defaultColor); | 
| 817 | 816 | |
| 818 | -        if ($check->data->usageType){ | |
| 817 | +        if ($check->data->usageType) { | |
| 819 | 818 |              $line = self::printResult(Console::pad('   Usage type:', 23), $check->data->usageType, $defaultColor, '', false); | 
| 820 | 819 |              $line .= $check->data->usageType === 'Reserved' ? Console::text(' ◆', 'green') : ''; | 
| 821 | 820 | Console::log($line); | 
| 822 | 821 | } | 
| 823 | 822 | |
| 824 | 823 |          $hostames = implode(', ', array_filter($check->data->hostnames)) ?? null; | 
| 825 | -        if (!empty($hostames)){ | |
| 824 | +        if (!empty($hostames)) { | |
| 826 | 825 |              self::printResult(Console::pad('   Hostname(s):', 23), $hostames, $defaultColor); | 
| 827 | 826 | } | 
| 828 | 827 | |
| @@ -830,34 +829,34 @@ discard block | ||
| 830 | 829 | |
| 831 | 830 | $nbReport = $check->data->totalReports && is_numeric($check->data->totalReports) ? intval($check->data->totalReports) : 0; | 
| 832 | 831 | |
| 833 | -        if ($nbReport > 0 ){ | |
| 832 | +        if ($nbReport > 0) { | |
| 834 | 833 |              $line  = self::printResult(Console::pad('   Total reports:', 23), $nbReport, $defaultColor, '', false); | 
| 835 | 834 |              $line .= self::printResult(' from ', $check->data->numDistinctUsers, $defaultColor, '', false); | 
| 836 | - $line .= Console::text($nbReport > 0 ? ' distinct users': ' user', 'white'); | |
| 835 | + $line .= Console::text($nbReport > 0 ? ' distinct users' : ' user', 'white'); | |
| 837 | 836 | Console::log($line); | 
| 838 | 837 | |
| 839 | 838 |          } else { | 
| 840 | 839 | // no reports | 
| 841 | - $day = $maxAge > 1 ? 'in last '. $maxAge . ' days': ' today'; | |
| 842 | -            Console::log( Console::text('   ✓', 'green') . Console::text(' Not reported ' . $day)); | |
| 840 | + $day = $maxAge > 1 ? 'in last '.$maxAge.' days' : ' today'; | |
| 841 | +            Console::log(Console::text('   ✓', 'green').Console::text(' Not reported '.$day)); | |
| 843 | 842 | } | 
| 844 | 843 | |
| 845 | -        if (!empty($check->data->lastReportedAt)){ | |
| 844 | +        if (!empty($check->data->lastReportedAt)) { | |
| 846 | 845 |              self::printResult(Console::pad('   Last reported at:', 23), self::getDate($check->data->lastReportedAt), $defaultColor); | 
| 847 | 846 | } | 
| 848 | 847 | |
| 849 | 848 | // print last reports | 
| 850 | -        if ($verbose){ | |
| 849 | +        if ($verbose) { | |
| 851 | 850 | $nbLastReports = isset($check->data->reports) ? count($check->data->reports) : 0; | 
| 852 | 851 | |
| 853 | -            if ($nbLastReports > 0){ | |
| 852 | +            if ($nbLastReports > 0) { | |
| 854 | 853 |                  Console::log('   Last reports:', 'white'); | 
| 855 | 854 | $numberDiplayedReports = 0; | 
| 856 | 855 | $defaultColor = 'lightyellow'; // reset color for last reports | 
| 857 | 856 | |
| 858 | -                foreach ($check->data->reports as $lastReport){ | |
| 857 | +                foreach ($check->data->reports as $lastReport) { | |
| 859 | 858 | $categories = []; | 
| 860 | -                    foreach (array_filter($lastReport->categories) as $catId){ | |
| 859 | +                    foreach (array_filter($lastReport->categories) as $catId) { | |
| 861 | 860 | $cat = self::$api->getCategoryNamebyId($catId)[0]; | 
| 862 | 861 |                          if ($cat !== false) { | 
| 863 | 862 | $categories[] = $cat; | 
| @@ -867,15 +866,15 @@ discard block | ||
| 867 | 866 |                      $line  = Console::text('    →', $defaultColor); | 
| 868 | 867 |                      $line .= self::printResult(' reported at: ', self::getDate($lastReport->reportedAt), $defaultColor, '', false); | 
| 869 | 868 |                //    $line .= self::printResult(' by user: ', $lastReport->reporterId, $defaultColor, '', false); | 
| 870 | -                    if (isset($lastReport->reporterCountryCode) && isset($lastReport->reporterCountryName)){ | |
| 869 | +                    if (isset($lastReport->reporterCountryCode) && isset($lastReport->reporterCountryName)) { | |
| 871 | 870 |                          $line .= Console::text(' from: ', 'white'); | 
| 872 | 871 |                          $line .= self::printResult('', $lastReport->reporterCountryCode, $defaultColor, '', false); | 
| 873 | 872 |                          $line .= Console::text(' - ', 'white'); | 
| 874 | 873 |                          $line .= self::printResult('', $lastReport->reporterCountryName, $defaultColor, '', false); | 
| 875 | 874 | } | 
| 876 | -                    $line .= Console::text(' with categor' .  (count($categories) > 1 ? "ies: " : "y: "), 'white'); | |
| 875 | +                    $line .= Console::text(' with categor'.(count($categories) > 1 ? "ies: " : "y: "), 'white'); | |
| 877 | 876 |                      foreach ($categories as $key => $cat) { | 
| 878 | - $line .= Console::text($key==0 ? '' : ',' , 'white') . Console::text($cat, $defaultColor); | |
| 877 | + $line .= Console::text($key == 0 ? '' : ',', 'white').Console::text($cat, $defaultColor); | |
| 879 | 878 | } | 
| 880 | 879 | Console::log($line); | 
| 881 | 880 | |
| @@ -886,7 +885,7 @@ discard block | ||
| 886 | 885 | $line .= Console::text($numberDiplayedReports, $defaultColor); | 
| 887 | 886 |                          $line .= Console::text('/', 'white'); | 
| 888 | 887 | $line .= Console::text($nbLastReports, $defaultColor); | 
| 889 | - $line .= Console::text($numberDiplayedReports > 1 ? ' reports displayed)': ' report displayed)', 'white'); | |
| 888 | + $line .= Console::text($numberDiplayedReports > 1 ? ' reports displayed)' : ' report displayed)', 'white'); | |
| 890 | 889 | Console::log($line); | 
| 891 | 890 | break; | 
| 892 | 891 | } | 
| @@ -91,7 +91,7 @@ | ||
| 91 | 91 | */ | 
| 92 | 92 | protected static function inArguments(array $arguments, string $shortArg, string $longArg) | 
| 93 | 93 |      { | 
| 94 | - return array_key_exists($shortArg, $arguments) || array_key_exists($longArg, $arguments); | |
| 94 | + return array_key_exists($shortArg, $arguments) || array_key_exists($longArg, $arguments); | |
| 95 | 95 | } | 
| 96 | 96 | |
| 97 | 97 | /** | 
| @@ -61,7 +61,7 @@ discard block | ||
| 61 | 61 | */ | 
| 62 | 62 | protected static function printTempMessage() | 
| 63 | 63 |      { | 
| 64 | -        Console::reLog(Console::text('   ? ', 'green') . Console::text('waiting for api response', 'white') . Console::text(' ... ', 'green')); | |
| 64 | +        Console::reLog(Console::text('   ? ', 'green').Console::text('waiting for api response', 'white').Console::text(' ... ', 'green')); | |
| 65 | 65 | } | 
| 66 | 66 | |
| 67 | 67 | /** | 
| @@ -113,14 +113,14 @@ discard block | ||
| 113 | 113 |      { | 
| 114 | 114 | self::printLogo(); | 
| 115 | 115 | Console::log(); | 
| 116 | -        Console::log(Console::text('  Kristuff/AbuseIPDB Client version: ', 'darkgray') . Console::text(AbuseIPDBClient::VERSION, 'lightgray')); | |
| 117 | -        Console::log(Console::text('  Kristuff/AbuseIPDB Core version:   ', 'darkgray') . Console::text(ApiHandler::VERSION, 'lightgray'));  | |
| 116 | +        Console::log(Console::text('  Kristuff/AbuseIPDB Client version: ', 'darkgray').Console::text(AbuseIPDBClient::VERSION, 'lightgray')); | |
| 117 | +        Console::log(Console::text('  Kristuff/AbuseIPDB Core version:   ', 'darkgray').Console::text(ApiHandler::VERSION, 'lightgray'));  | |
| 118 | 118 |          Console::log(Console::text('  --------------------------------------------------', 'darkgray'));     | 
| 119 | 119 |          //Console::log(Console::text('  __________________________________________________', 'darkgray'));     | 
| 120 | 120 | //Console::log(); | 
| 121 | 121 |          //Console::log(Console::text('  --------------------------------------------------', 'darkgray'));     | 
| 122 | 122 |          Console::log(Console::text('  Released under the MIT licence', 'darkgray')); | 
| 123 | -        Console::log(Console::text('  Made with ', 'darkgray') . Console::text('♥', 'red') . Console::text(' in France', 'darkgray')); | |
| 123 | +        Console::log(Console::text('  Made with ', 'darkgray').Console::text('♥', 'red').Console::text(' in France', 'darkgray')); | |
| 124 | 124 | Console::log( | 
| 125 | 125 |              Console::text('  © 2020-2021 Kristuff (', 'darkgray'). | 
| 126 | 126 |              Console::text('https://github.com/kristuff', 'darkgray', 'underlined'). | 
| @@ -141,8 +141,8 @@ discard block | ||
| 141 | 141 | protected static function printBanner() | 
| 142 | 142 |      { | 
| 143 | 143 | Console::log(); | 
| 144 | -        Console::log( Console::text(' Kristuff\AbuseIPDB ', 'darkgray') . Console::text(' ' . AbuseIPDBClient::VERSION . ' ', 'white', 'blue'));  | |
| 145 | -        Console::log(Console::text(' Made with ', 'darkgray') . Console::text('♥', 'red') . Console::text(' in France', 'darkgray'));  | |
| 144 | +        Console::log(Console::text(' Kristuff\AbuseIPDB ', 'darkgray').Console::text(' '.AbuseIPDBClient::VERSION.' ', 'white', 'blue'));  | |
| 145 | +        Console::log(Console::text(' Made with ', 'darkgray').Console::text('♥', 'red').Console::text(' in France', 'darkgray'));  | |
| 146 | 146 |          Console::log(' © 2020-2021 Kristuff', 'darkgray');  | 
| 147 | 147 | Console::log(); | 
| 148 | 148 | } | 
| @@ -157,19 +157,19 @@ discard block | ||
| 157 | 157 | */ | 
| 158 | 158 | protected static function printFooter(string $requestTime = '') | 
| 159 | 159 |      { | 
| 160 | -        if (!empty($requestTime)){ | |
| 160 | +        if (!empty($requestTime)) { | |
| 161 | 161 |              $date_utc = new \DateTime("now", new \DateTimeZone("UTC")); | 
| 162 | 162 | Console::log( | 
| 163 | -                Console::text('  Request time: ', 'darkgray') . Console::text($requestTime . 's', 'lightgray').  | |
| 164 | -                Console::text(' | UTC time: ', 'darkgray') . Console::text($date_utc->format('Y-m-d H:i:s'), 'lightgray') | |
| 163 | +                Console::text('  Request time: ', 'darkgray').Console::text($requestTime.'s', 'lightgray').  | |
| 164 | +                Console::text(' | UTC time: ', 'darkgray').Console::text($date_utc->format('Y-m-d H:i:s'), 'lightgray') | |
| 165 | 165 | ); | 
| 166 | 166 | } | 
| 167 | 167 |          Console::log(Console::text('  ------------------------------------------------------------------------------------------------------', 'darkgray'));  | 
| 168 | 168 | Console::log( | 
| 169 | -            Console::text('  Kristuff\AbuseIPDB ', 'darkgray') .  | |
| 170 | - Console::text(AbuseIPDBClient::VERSION, 'lightgray') . | |
| 171 | -            Console::text(' | Made with ', 'darkgray') .  | |
| 172 | -            Console::text('♥', 'red') . | |
| 169 | +            Console::text('  Kristuff\AbuseIPDB ', 'darkgray').  | |
| 170 | + Console::text(AbuseIPDBClient::VERSION, 'lightgray'). | |
| 171 | +            Console::text(' | Made with ', 'darkgray').  | |
| 172 | +            Console::text('♥', 'red'). | |
| 173 | 173 |              Console::text(' in France | © 2020-2021 Kristuff (https://github.com/kristuff)', 'darkgray') | 
| 174 | 174 | ); | 
| 175 | 175 | Console::log(); | 
| @@ -186,9 +186,9 @@ discard block | ||
| 186 | 186 | protected static function printResult($text, $value, string $foregroundColor = 'lightred', string $backgroundColor = '', bool $print = true) | 
| 187 | 187 |      { | 
| 188 | 188 | // do not print null/blank values | 
| 189 | -        if (isset($value)){ | |
| 190 | - $line = Console::text($text, 'white') . Console::text($value, $foregroundColor, $backgroundColor); | |
| 191 | -            if ($print){ | |
| 189 | +        if (isset($value)) { | |
| 190 | + $line = Console::text($text, 'white').Console::text($value, $foregroundColor, $backgroundColor); | |
| 191 | +            if ($print) { | |
| 192 | 192 | Console::log($line); | 
| 193 | 193 | } | 
| 194 | 194 | return $line; | 
| @@ -212,16 +212,16 @@ discard block | ||
| 212 | 212 | $scoreforegroundColor = 'white'; | 
| 213 | 213 | $scoreBackgroundColor = 'green'; | 
| 214 | 214 | |
| 215 | -        if (intval($score) > 0 ){ | |
| 215 | +        if (intval($score) > 0) { | |
| 216 | 216 | $scoreforegroundColor = 'black'; | 
| 217 | 217 | $scoreBackgroundColor = 'yellow'; | 
| 218 | 218 | } | 
| 219 | -        if (intval($score) > 50 ){ | |
| 219 | +        if (intval($score) > 50) { | |
| 220 | 220 | $scoreforegroundColor = 'white'; | 
| 221 | 221 | $scoreBackgroundColor = 'red'; | 
| 222 | 222 | } | 
| 223 | 223 | |
| 224 | - $badge = str_pad($score, 3, ' ',STR_PAD_LEFT); | |
| 224 | + $badge = str_pad($score, 3, ' ', STR_PAD_LEFT); | |
| 225 | 225 | return Console::text($padding.$badge.$padding, $scoreforegroundColor, $scoreBackgroundColor); | 
| 226 | 226 | } | 
| 227 | 227 | |
| @@ -237,27 +237,27 @@ discard block | ||
| 237 | 237 | */ | 
| 238 | 238 | protected static function printErrors($response, bool $checkForEmpty = true) | 
| 239 | 239 |      { | 
| 240 | -        if (isset($response) && isset($response->errors)){ | |
| 240 | +        if (isset($response) && isset($response->errors)) { | |
| 241 | 241 | |
| 242 | 242 | // top error badge | 
| 243 | -            Console::log('  ' .   Console::text(' ERROR ','white', 'red')); | |
| 243 | +            Console::log('  '.Console::text(' ERROR ', 'white', 'red')); | |
| 244 | 244 | |
| 245 | 245 | $num = 0; | 
| 246 | 246 | // errors is an array, could have more than one error.. | 
| 247 | -            foreach ($response->errors as $err){ | |
| 247 | +            foreach ($response->errors as $err) { | |
| 248 | 248 | $num++; | 
| 249 | 249 | |
| 250 | -                Console::log(Console::text('   ✗', 'red') .  self::printResult(' Number:    ', $num, 'lightyellow','', false)); | |
| 251 | -                self::printResult('     Status:    ', $err->status ?? null, 'lightyellow','');     | |
| 250 | +                Console::log(Console::text('   ✗', 'red').self::printResult(' Number:    ', $num, 'lightyellow', '', false)); | |
| 251 | +                self::printResult('     Status:    ', $err->status ?? null, 'lightyellow', '');     | |
| 252 | 252 | |
| 253 | -                if (!empty($err->source) && !empty($err->source->parameter)){ | |
| 253 | +                if (!empty($err->source) && !empty($err->source->parameter)) { | |
| 254 | 254 |                      self::printResult('     Parameter: ', $err->source->parameter, 'lightyellow');     | 
| 255 | 255 | } | 
| 256 | 256 |                  self::printResult('     Title:     ', $err->title ?? null, 'lightyellow');     | 
| 257 | 257 |                  self::printResult('     Detail:    ', $err->detail ?? null, 'lightyellow');     | 
| 258 | 258 | |
| 259 | 259 | // separate errors | 
| 260 | -                if (count($response->errors) > 1){ | |
| 260 | +                if (count($response->errors) > 1) { | |
| 261 | 261 |                      Console::log('   ---'); | 
| 262 | 262 | } | 
| 263 | 263 | |
| @@ -267,7 +267,7 @@ discard block | ||
| 267 | 267 | } | 
| 268 | 268 | |
| 269 | 269 | // check for empty response ? | 
| 270 | -        if ( $checkForEmpty && ( empty($response) || empty($response->data)) ){ | |
| 270 | +        if ($checkForEmpty && (empty($response) || empty($response->data))) { | |
| 271 | 271 |              self::error('An unexpected error occurred.'); | 
| 272 | 272 | return true; | 
| 273 | 273 | } | 
| @@ -287,11 +287,11 @@ discard block | ||
| 287 | 287 | protected static function error($error) | 
| 288 | 288 |      { | 
| 289 | 289 | // ✗ | 
| 290 | -        Console::log('  ' .   Console::text(' ERROR ','white', 'red')); | |
| 290 | +        Console::log('  '.Console::text(' ERROR ', 'white', 'red')); | |
| 291 | 291 | Console::log( | 
| 292 | -            Console::text('   ✗', 'red') .  | |
| 293 | -            Console::text(' Detail:    ', 'white') .  | |
| 294 | - Console::text($error, 'lightyellow') . | |
| 292 | +            Console::text('   ✗', 'red').  | |
| 293 | +            Console::text(' Detail:    ', 'white').  | |
| 294 | + Console::text($error, 'lightyellow'). | |
| 295 | 295 |              Console::text('', 'white') | 
| 296 | 296 | ); | 
| 297 | 297 | Console::log(); | 
| @@ -310,7 +310,7 @@ discard block | ||
| 310 | 310 | */ | 
| 311 | 311 | protected static function validate(bool $condition, string $message, bool $print = true) | 
| 312 | 312 |      { | 
| 313 | -        if ( !$condition ){ | |
| 313 | +        if (!$condition) { | |
| 314 | 314 |              if ($print) { | 
| 315 | 315 | Console::log(); | 
| 316 | 316 | self::error($message); | 
| @@ -334,10 +334,10 @@ discard block | ||
| 334 | 334 | */ | 
| 335 | 335 | protected static function getNumericParameter(array $arguments, string $shortArg, string $longArg, int $defaultValue) | 
| 336 | 336 |      { | 
| 337 | -         if (self::inArguments($arguments,$shortArg, $longArg)){ | |
| 338 | - $val = self::getArgumentValue($arguments,$shortArg, $longArg); | |
| 337 | +         if (self::inArguments($arguments, $shortArg, $longArg)) { | |
| 338 | + $val = self::getArgumentValue($arguments, $shortArg, $longArg); | |
| 339 | 339 | |
| 340 | -            if (!is_numeric($val)){ | |
| 340 | +            if (!is_numeric($val)) { | |
| 341 | 341 |                  self::error("Invalid parameter: $longArg must be a numeric value."); | 
| 342 | 342 | self::printFooter(); | 
| 343 | 343 | exit(1); |