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