@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | protected static function printTempMessage() |
83 | 83 | { |
84 | 84 | if (self::isDefaultOuput()) { |
85 | - Console::reLog(Console::text(' ? ', 'green') . Console::text('waiting for api response', 'white') . Console::text(' ... ', 'green')); |
|
85 | + Console::reLog(Console::text(' ? ', 'green').Console::text('waiting for api response', 'white').Console::text(' ... ', 'green')); |
|
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
@@ -140,11 +140,11 @@ discard block |
||
140 | 140 | self::printLogo(); |
141 | 141 | |
142 | 142 | Console::log(); |
143 | - Console::log(Console::text(' Kristuff/AbuseIPDB Client version: ', 'darkgray') . Console::text(AbuseIPDBClient::VERSION, 'lightgray')); |
|
144 | - Console::log(Console::text(' Kristuff/AbuseIPDB Core version: ', 'darkgray') . Console::text(ApiHandler::VERSION, 'lightgray')); |
|
143 | + Console::log(Console::text(' Kristuff/AbuseIPDB Client version: ', 'darkgray').Console::text(AbuseIPDBClient::VERSION, 'lightgray')); |
|
144 | + Console::log(Console::text(' Kristuff/AbuseIPDB Core version: ', 'darkgray').Console::text(ApiHandler::VERSION, 'lightgray')); |
|
145 | 145 | Console::log(Console::text(' --------------------------------------------------', 'darkgray')); |
146 | 146 | Console::log(Console::text(' Released under the MIT licence', 'darkgray')); |
147 | - Console::log(Console::text(' Made with ', 'darkgray') . Console::text('♥', 'red') . Console::text(' in France', 'darkgray')); |
|
147 | + Console::log(Console::text(' Made with ', 'darkgray').Console::text('♥', 'red').Console::text(' in France', 'darkgray')); |
|
148 | 148 | Console::log( |
149 | 149 | Console::text(' © 2020-2021 Kristuff (', 'darkgray'). |
150 | 150 | Console::text('https://github.com/kristuff', 'darkgray', 'underlined'). |
@@ -166,8 +166,8 @@ discard block |
||
166 | 166 | { |
167 | 167 | if (self::isDefaultOuput()) { |
168 | 168 | Console::log(); |
169 | - Console::log( Console::text(' Kristuff\AbuseIPDB ', 'darkgray') . Console::text(' ' . AbuseIPDBClient::VERSION . ' ', 'white', 'blue')); |
|
170 | - Console::log(Console::text(' Made with ', 'darkgray') . Console::text('♥', 'red') . Console::text(' in France', 'darkgray')); |
|
169 | + Console::log(Console::text(' Kristuff\AbuseIPDB ', 'darkgray').Console::text(' '.AbuseIPDBClient::VERSION.' ', 'white', 'blue')); |
|
170 | + Console::log(Console::text(' Made with ', 'darkgray').Console::text('♥', 'red').Console::text(' in France', 'darkgray')); |
|
171 | 171 | Console::log(' © 2020-2021 Kristuff', 'darkgray'); |
172 | 172 | Console::log(); |
173 | 173 | } |
@@ -184,19 +184,19 @@ discard block |
||
184 | 184 | protected static function printFooter(string $requestTime = '') |
185 | 185 | { |
186 | 186 | if (self::isDefaultOuput()) { |
187 | - if (!empty($requestTime)){ |
|
187 | + if (!empty($requestTime)) { |
|
188 | 188 | $date_utc = new \DateTime("now", new \DateTimeZone("UTC")); |
189 | 189 | Console::log( |
190 | - Console::text(' Request time: ', 'darkgray') . Console::text($requestTime . 's', 'lightgray'). |
|
191 | - Console::text(' | UTC time: ', 'darkgray') . Console::text($date_utc->format('Y-m-d H:i:s'), 'lightgray') |
|
190 | + Console::text(' Request time: ', 'darkgray').Console::text($requestTime.'s', 'lightgray'). |
|
191 | + Console::text(' | UTC time: ', 'darkgray').Console::text($date_utc->format('Y-m-d H:i:s'), 'lightgray') |
|
192 | 192 | ); |
193 | 193 | } |
194 | 194 | Console::log(Console::text(' ------------------------------------------------------------------------------------------------------', 'darkgray')); |
195 | 195 | Console::log( |
196 | - Console::text(' Kristuff\AbuseIPDB ', 'darkgray') . |
|
197 | - Console::text(AbuseIPDBClient::VERSION, 'lightgray') . |
|
198 | - Console::text(' | Made with ', 'darkgray') . |
|
199 | - Console::text('♥', 'red') . |
|
196 | + Console::text(' Kristuff\AbuseIPDB ', 'darkgray'). |
|
197 | + Console::text(AbuseIPDBClient::VERSION, 'lightgray'). |
|
198 | + Console::text(' | Made with ', 'darkgray'). |
|
199 | + Console::text('♥', 'red'). |
|
200 | 200 | Console::text(' in France | © 2020-2021 Kristuff (https://github.com/kristuff)', 'darkgray') |
201 | 201 | ); |
202 | 202 | Console::log(); |
@@ -215,9 +215,9 @@ discard block |
||
215 | 215 | { |
216 | 216 | |
217 | 217 | // do not print null/blank values |
218 | - if (isset($value)){ |
|
219 | - $line = Console::text($text, 'white') . Console::text($value, $foregroundColor, $backgroundColor); |
|
220 | - if ($print && self::isDefaultOuput()){ |
|
218 | + if (isset($value)) { |
|
219 | + $line = Console::text($text, 'white').Console::text($value, $foregroundColor, $backgroundColor); |
|
220 | + if ($print && self::isDefaultOuput()) { |
|
221 | 221 | Console::log($line); |
222 | 222 | } |
223 | 223 | return $line; |
@@ -241,16 +241,16 @@ discard block |
||
241 | 241 | $scoreforegroundColor = 'white'; |
242 | 242 | $scoreBackgroundColor = 'green'; |
243 | 243 | |
244 | - if (intval($score) > 0 ){ |
|
244 | + if (intval($score) > 0) { |
|
245 | 245 | $scoreforegroundColor = 'black'; |
246 | 246 | $scoreBackgroundColor = 'yellow'; |
247 | 247 | } |
248 | - if (intval($score) > 50 ){ |
|
248 | + if (intval($score) > 50) { |
|
249 | 249 | $scoreforegroundColor = 'white'; |
250 | 250 | $scoreBackgroundColor = 'red'; |
251 | 251 | } |
252 | 252 | |
253 | - $badge = str_pad($score, 3, ' ',STR_PAD_LEFT); |
|
253 | + $badge = str_pad($score, 3, ' ', STR_PAD_LEFT); |
|
254 | 254 | return Console::text($padding.$badge.$padding, $scoreforegroundColor, $scoreBackgroundColor); |
255 | 255 | } |
256 | 256 | |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | * |
265 | 265 | * @return bool |
266 | 266 | */ |
267 | - protected static function hasErrors(object $response, bool $checkForEmpty = true ) |
|
267 | + protected static function hasErrors(object $response, bool $checkForEmpty = true) |
|
268 | 268 | { |
269 | 269 | return $checkForEmpty ? self::parseErrors($response) || self::checkForEmpty($response) : self::parseErrors($response); |
270 | 270 | } |
@@ -282,8 +282,8 @@ discard block |
||
282 | 282 | */ |
283 | 283 | private static function parseErrors(object $response) |
284 | 284 | { |
285 | - if (isset($response) && isset($response->errors)){ |
|
286 | - switch (self::$outputFormat){ |
|
285 | + if (isset($response) && isset($response->errors)) { |
|
286 | + switch (self::$outputFormat) { |
|
287 | 287 | case self::OUTPUT_DEFAULT: |
288 | 288 | self::printFormattedErrors($response); |
289 | 289 | break; |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | protected static function checkForEmpty(object $response) |
314 | 314 | { |
315 | 315 | // check for empty response ? |
316 | - if ( empty($response) || empty($response->data) ){ |
|
316 | + if (empty($response) || empty($response->data)) { |
|
317 | 317 | self::error('An unexpected error occurred.'); |
318 | 318 | return true; |
319 | 319 | } |
@@ -331,24 +331,24 @@ discard block |
||
331 | 331 | protected static function printFormattedErrors(object $response) |
332 | 332 | { |
333 | 333 | // top error badge |
334 | - Console::log(' ' . Console::text(' ERROR ','white', 'red')); |
|
334 | + Console::log(' '.Console::text(' ERROR ', 'white', 'red')); |
|
335 | 335 | |
336 | 336 | $num = 0; |
337 | 337 | // errors is an array, could have more than one error.. |
338 | - foreach ($response->errors as $err){ |
|
338 | + foreach ($response->errors as $err) { |
|
339 | 339 | $num++; |
340 | 340 | |
341 | - Console::log(Console::text(' ✗', 'red') . self::printResult(' Number: ', $num, 'lightyellow','', false)); |
|
342 | - self::printResult(' Status: ', $err->status ?? null, 'lightyellow',''); |
|
341 | + Console::log(Console::text(' ✗', 'red').self::printResult(' Number: ', $num, 'lightyellow', '', false)); |
|
342 | + self::printResult(' Status: ', $err->status ?? null, 'lightyellow', ''); |
|
343 | 343 | |
344 | - if (!empty($err->source) && !empty($err->source->parameter)){ |
|
344 | + if (!empty($err->source) && !empty($err->source->parameter)) { |
|
345 | 345 | self::printResult(' Parameter: ', $err->source->parameter, 'lightyellow'); |
346 | 346 | } |
347 | 347 | self::printResult(' Title: ', $err->title ?? null, 'lightyellow'); |
348 | 348 | self::printResult(' Detail: ', $err->detail ?? null, 'lightyellow'); |
349 | 349 | |
350 | 350 | // separate errors |
351 | - if (count($response->errors) > 1){ |
|
351 | + if (count($response->errors) > 1) { |
|
352 | 352 | Console::log(' ---'); |
353 | 353 | } |
354 | 354 | |
@@ -367,12 +367,12 @@ discard block |
||
367 | 367 | */ |
368 | 368 | protected static function printPlainTextErrors(object $response) |
369 | 369 | { |
370 | - foreach ($response->errors as $err){ |
|
370 | + foreach ($response->errors as $err) { |
|
371 | 371 | $text = 'Error: '; |
372 | - $text .= !empty($err->title) ? ' title: ' . $err->title : ''; |
|
373 | - $text .= !empty($err->status) ? ' status: ' . $err->status : ''; |
|
374 | - $text .= !empty($err->source) && !empty($err->source->parameter) ? ' parameter: ' . $err->source->parameter : ''; |
|
375 | - $text .= !empty($err->detail) ? ' detail: ' . $err->detail : ''; |
|
372 | + $text .= !empty($err->title) ? ' title: '.$err->title : ''; |
|
373 | + $text .= !empty($err->status) ? ' status: '.$err->status : ''; |
|
374 | + $text .= !empty($err->source) && !empty($err->source->parameter) ? ' parameter: '.$err->source->parameter : ''; |
|
375 | + $text .= !empty($err->detail) ? ' detail: '.$err->detail : ''; |
|
376 | 376 | $text .= PHP_EOL; |
377 | 377 | echo $text; |
378 | 378 | } |
@@ -391,11 +391,11 @@ discard block |
||
391 | 391 | { |
392 | 392 | if (self::isDefaultOuput()) { |
393 | 393 | // ✗ |
394 | - Console::log(' ' . Console::text(' ERROR ','white', 'red')); |
|
394 | + Console::log(' '.Console::text(' ERROR ', 'white', 'red')); |
|
395 | 395 | Console::log( |
396 | - Console::text(' ✗', 'red') . |
|
397 | - Console::text(' Detail: ', 'white') . |
|
398 | - Console::text($error, 'lightyellow') . |
|
396 | + Console::text(' ✗', 'red'). |
|
397 | + Console::text(' Detail: ', 'white'). |
|
398 | + Console::text($error, 'lightyellow'). |
|
399 | 399 | Console::text('', 'white') |
400 | 400 | ); |
401 | 401 | Console::log(); |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | */ |
416 | 416 | protected static function validate(bool $condition, string $message, bool $print = true) |
417 | 417 | { |
418 | - if ( !$condition ){ |
|
418 | + if (!$condition) { |
|
419 | 419 | if ($print && self::isDefaultOuput()) { |
420 | 420 | Console::log(); |
421 | 421 | self::error($message); |
@@ -439,10 +439,10 @@ discard block |
||
439 | 439 | */ |
440 | 440 | protected static function getNumericParameter(array $arguments, string $shortArg, string $longArg, int $defaultValue) |
441 | 441 | { |
442 | - if (self::inArguments($arguments,$shortArg, $longArg)){ |
|
443 | - $val = self::getArgumentValue($arguments,$shortArg, $longArg); |
|
442 | + if (self::inArguments($arguments, $shortArg, $longArg)) { |
|
443 | + $val = self::getArgumentValue($arguments, $shortArg, $longArg); |
|
444 | 444 | |
445 | - if (!is_numeric($val)){ |
|
445 | + if (!is_numeric($val)) { |
|
446 | 446 | self::error("Invalid parameter: $longArg must be a numeric value."); |
447 | 447 | self::printFooter(); |
448 | 448 | Program::exit(1); |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | { |
49 | 49 | // required at least one valid argument |
50 | 50 | self::$keyPath = $keyPath; |
51 | - self::validate( !empty($arguments), 'No valid arguments given. Run abuseipdb --help to get help.'); |
|
51 | + self::validate(!empty($arguments), 'No valid arguments given. Run abuseipdb --help to get help.'); |
|
52 | 52 | if (!self::parseCommand($arguments, $keyPath)) { |
53 | 53 | self::error('Invalid arguments. Run abuseipdb --help to get help.'); |
54 | 54 | self::printFooter(); |
@@ -69,9 +69,9 @@ discard block |
||
69 | 69 | { |
70 | 70 | self::printTitle(Console::text(' ► Register API key ', 'darkgray')); |
71 | 71 | |
72 | - $key = self::getArgumentValue($arguments,'S', 'save-key'); |
|
72 | + $key = self::getArgumentValue($arguments, 'S', 'save-key'); |
|
73 | 73 | |
74 | - if (empty($key)){ |
|
74 | + if (empty($key)) { |
|
75 | 75 | self::error('Null or invalid key argument.'); |
76 | 76 | self::printFooter(); |
77 | 77 | Program::exit(1); |
@@ -79,12 +79,12 @@ discard block |
||
79 | 79 | |
80 | 80 | $data = json_encode(['api_key' => $key]); |
81 | 81 | |
82 | - if (file_put_contents(self::$keyPath, $data, LOCK_EX) === false){ |
|
82 | + if (file_put_contents(self::$keyPath, $data, LOCK_EX) === false) { |
|
83 | 83 | self::error('An error occured during writing config file. Make sure to give the appropriate permissions do the config directory.'); |
84 | 84 | self::printFooter(); |
85 | 85 | Program::exit(1); |
86 | 86 | } |
87 | - Console::log(Console::text(' ✓ ', 'green') . Console::text('Your config key file has been successfully created.', 'white')); |
|
87 | + Console::log(Console::text(' ✓ ', 'green').Console::text('Your config key file has been successfully created.', 'white')); |
|
88 | 88 | Console::log(); |
89 | 89 | self::printFooter(); |
90 | 90 | Program::exit(); |
@@ -102,45 +102,45 @@ discard block |
||
102 | 102 | { |
103 | 103 | self::printBanner(); |
104 | 104 | |
105 | - Console::log(' ' . Console::text('SYNOPSIS:', 'white', 'underline')); |
|
106 | - Console::log(' ' . Console::text(' abuseipdb -C ') . |
|
107 | - Console::text('IP', 'yellow') . |
|
108 | - Console::text(' [-d ') . |
|
109 | - Console::text('DAYS', 'yellow') . |
|
110 | - Console::text('] [-v] [-l ') . |
|
111 | - Console::text('LIMIT', 'yellow') . |
|
105 | + Console::log(' '.Console::text('SYNOPSIS:', 'white', 'underline')); |
|
106 | + Console::log(' '.Console::text(' abuseipdb -C '). |
|
107 | + Console::text('IP', 'yellow'). |
|
108 | + Console::text(' [-d '). |
|
109 | + Console::text('DAYS', 'yellow'). |
|
110 | + Console::text('] [-v] [-l '). |
|
111 | + Console::text('LIMIT', 'yellow'). |
|
112 | 112 | Console::text(']')); |
113 | 113 | |
114 | - Console::log(' ' . Console::text(' abuseipdb -K ') . |
|
115 | - Console::text('NETWORK', 'yellow') . |
|
116 | - Console::text(' [-d ') . |
|
117 | - Console::text('DAYS', 'yellow') . |
|
114 | + Console::log(' '.Console::text(' abuseipdb -K '). |
|
115 | + Console::text('NETWORK', 'yellow'). |
|
116 | + Console::text(' [-d '). |
|
117 | + Console::text('DAYS', 'yellow'). |
|
118 | 118 | Console::text(']')); |
119 | 119 | |
120 | - Console::log(' ' . Console::text(' abuseipdb -R ' . |
|
121 | - Console::text('IP', 'yellow') . ' -c ' . |
|
122 | - Console::text('CATEGORIES', 'yellow') . ' -m ' . |
|
120 | + Console::log(' '.Console::text(' abuseipdb -R '. |
|
121 | + Console::text('IP', 'yellow').' -c '. |
|
122 | + Console::text('CATEGORIES', 'yellow').' -m '. |
|
123 | 123 | Console::text('MESSAGE', 'yellow'))); |
124 | 124 | |
125 | - Console::log(' ' . Console::text(' abuseipdb -V ' . |
|
125 | + Console::log(' '.Console::text(' abuseipdb -V '. |
|
126 | 126 | Console::text('FILE', 'yellow'))); |
127 | 127 | |
128 | - Console::log(' ' . Console::text(' abuseipdb -E ' . |
|
128 | + Console::log(' '.Console::text(' abuseipdb -E '. |
|
129 | 129 | Console::text('IP', 'yellow'))); |
130 | 130 | |
131 | - Console::log(' ' . Console::text(' abuseipdb -B ') . |
|
132 | - Console::text('[-l ') . |
|
133 | - Console::text('LIMIT', 'yellow') . |
|
134 | - Console::text('] [-s ') . |
|
135 | - Console::text('SCORE', 'yellow') . |
|
136 | - Console::text('] [-p ') . |
|
137 | - Console::text('', 'yellow') . |
|
131 | + Console::log(' '.Console::text(' abuseipdb -B '). |
|
132 | + Console::text('[-l '). |
|
133 | + Console::text('LIMIT', 'yellow'). |
|
134 | + Console::text('] [-s '). |
|
135 | + Console::text('SCORE', 'yellow'). |
|
136 | + Console::text('] [-p '). |
|
137 | + Console::text('', 'yellow'). |
|
138 | 138 | Console::text(']')); |
139 | 139 | |
140 | - Console::log(' ' . Console::text(' abuseipdb -L | -G | -h | --version')); |
|
140 | + Console::log(' '.Console::text(' abuseipdb -L | -G | -h | --version')); |
|
141 | 141 | |
142 | 142 | Console::log(); |
143 | - Console::log(' ' . Console::text('OPTIONS:', 'white', 'underline')); |
|
143 | + Console::log(' '.Console::text('OPTIONS:', 'white', 'underline')); |
|
144 | 144 | Console::log(); |
145 | 145 | Console::log(Console::text(' -h, --help', 'white')); |
146 | 146 | Console::log(' Prints the current help. If given, all next arguments are ignored.', 'lightgray'); |
@@ -151,39 +151,39 @@ discard block |
||
151 | 151 | Console::log(Console::text(' -L, --list', 'white')); |
152 | 152 | Console::log(' Prints the list report categories. If given, all next arguments are ignored.', 'lightgray'); |
153 | 153 | Console::log(); |
154 | - Console::log(Console::text(' -C, --check ', 'white') . Console::text('ip', 'yellow', 'underline')); |
|
154 | + Console::log(Console::text(' -C, --check ', 'white').Console::text('ip', 'yellow', 'underline')); |
|
155 | 155 | Console::log(' Performs a check request for the given IP address. A valid IPv4 or IPv6 address is required.', 'lightgray'); |
156 | 156 | Console::log(); |
157 | - Console::log(Console::text(' -K, --check-block ', 'white') . Console::text('network', 'yellow', 'underline')); |
|
157 | + Console::log(Console::text(' -K, --check-block ', 'white').Console::text('network', 'yellow', 'underline')); |
|
158 | 158 | Console::log(' Performs a check-block request for the given network. A valid subnet (v4 or v6) denoted with ', 'lightgray'); |
159 | 159 | Console::log(' CIDR notation is required.', 'lightgray'); |
160 | 160 | Console::log(); |
161 | - Console::log(Console::text(' -d, --days ', 'white') . Console::text('days', 'yellow', 'underline')); |
|
161 | + Console::log(Console::text(' -d, --days ', 'white').Console::text('days', 'yellow', 'underline')); |
|
162 | 162 | Console::log(' For a check or check-block request, defines the maxAgeDays. Min is 1, max is 365, default is 30.', 'lightgray'); |
163 | 163 | Console::log(); |
164 | - Console::log(Console::text(' -R, --report ', 'white') . Console::text('ip', 'yellow', 'underline')); |
|
164 | + Console::log(Console::text(' -R, --report ', 'white').Console::text('ip', 'yellow', 'underline')); |
|
165 | 165 | Console::log(' Performs a report request for the given IP address. A valid IPv4 or IPv6 address is required.', 'lightgray'); |
166 | 166 | Console::log(); |
167 | - Console::log(Console::text(' -V, --bulk-report ', 'white') . Console::text('path', 'yellow', 'underline')); |
|
167 | + Console::log(Console::text(' -V, --bulk-report ', 'white').Console::text('path', 'yellow', 'underline')); |
|
168 | 168 | Console::log(' Performs a bulk-report request sending a csv file. A valid file name or full path is required.', 'lightgray'); |
169 | 169 | Console::log(); |
170 | 170 | Console::log(Console::text(' -E, --clear ', 'white')); |
171 | 171 | Console::log(' Remove own reports for the given IP address. A valid IPv4 or IPv6 address is required.', 'lightgray'); |
172 | 172 | Console::log(); |
173 | - Console::log(Console::text(' -c, --categories ', 'white') . Console::text('categories', 'yellow', 'underline')); |
|
173 | + Console::log(Console::text(' -c, --categories ', 'white').Console::text('categories', 'yellow', 'underline')); |
|
174 | 174 | Console::log(' For a report request, defines the report category(ies). Categories must be separate by a comma.', 'lightgray'); |
175 | 175 | Console::log(' Some categories cannot be used alone. A category can be represented by its shortname or by its', 'lightgray'); |
176 | - Console::log(Console::text(' id. Use ','lightgray') . Console::text('abuseipdb -L', 'white') . Console::text(' to print the categories list.','lightgray')); |
|
176 | + Console::log(Console::text(' id. Use ', 'lightgray').Console::text('abuseipdb -L', 'white').Console::text(' to print the categories list.', 'lightgray')); |
|
177 | 177 | Console::log(); |
178 | - Console::log(Console::text(' -m, --message ', 'white') . Console::text('message', 'yellow', 'underline')); |
|
178 | + Console::log(Console::text(' -m, --message ', 'white').Console::text('message', 'yellow', 'underline')); |
|
179 | 179 | Console::log(' For a report request, defines the message to send with report. Message is required for all', 'lightgray'); |
180 | 180 | Console::log(' report requests.', 'lightgray'); |
181 | 181 | Console::log(); |
182 | 182 | Console::log(Console::text(' -B, --blacklist ', 'white')); |
183 | 183 | Console::log(' Performs a blacklist request. Default limit is 1000. This limit can ne changed with the', 'lightgray'); |
184 | - Console::log(' ' . Console::text('--limit', 'white') . Console::text(' parameter. ', 'lightgray')); |
|
184 | + Console::log(' '.Console::text('--limit', 'white').Console::text(' parameter. ', 'lightgray')); |
|
185 | 185 | Console::log(); |
186 | - Console::log(Console::text(' -l, --limit ', 'white') . Console::text('limit', 'yellow', 'underline')); |
|
186 | + Console::log(Console::text(' -l, --limit ', 'white').Console::text('limit', 'yellow', 'underline')); |
|
187 | 187 | Console::log(' For a blacklist request, defines the limit.', 'lightgray'); |
188 | 188 | Console::log(' For a check request with verbose flag, sets the max number of last reports displayed. Default is 10', 'lightgray'); |
189 | 189 | Console::log(' For a check-block request, sets the max number of IPs displayed. Default is 0 (no limit).', 'lightgray'); |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | Console::log(Console::text(' -v, --verbose ', 'white')); |
199 | 199 | Console::log(' For a check request, display additional fields like the x last reports. This increases ', 'lightgray'); |
200 | 200 | Console::log(Console::text(' request time and response size. Max number of last reports displayed can be changed with the ', 'lightgray')); |
201 | - Console::log(' ' . Console::text('--limit', 'white') . Console::text(' parameter. ', 'lightgray')); |
|
201 | + Console::log(' '.Console::text('--limit', 'white').Console::text(' parameter. ', 'lightgray')); |
|
202 | 202 | Console::log(); |
203 | 203 | Console::log(Console::text(' --version', 'white')); |
204 | 204 | Console::log(' Prints the current version. If given, all next arguments are ignored.', 'lightgray'); |
@@ -219,11 +219,11 @@ discard block |
||
219 | 219 | |
220 | 220 | self::printTitle(Console::text(' ► Current configuration ', 'darkgray')); |
221 | 221 | |
222 | - Console::log(Console::text(' api_key:[', 'white') . Console::text($conf['apiKey'], 'green') . Console::text(']', 'white')); |
|
222 | + Console::log(Console::text(' api_key:[', 'white').Console::text($conf['apiKey'], 'green').Console::text(']', 'white')); |
|
223 | 223 | Console::log(Console::text(' self_ips:', 'white')); |
224 | 224 | |
225 | 225 | foreach ($conf['selfIps'] as $ip) { |
226 | - Console::log(Console::text(' [', 'white') . Console::text($ip, 'green') . Console::text(']', 'white')); |
|
226 | + Console::log(Console::text(' [', 'white').Console::text($ip, 'green').Console::text(']', 'white')); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | Console::log(); |
@@ -244,10 +244,10 @@ discard block |
||
244 | 244 | |
245 | 245 | $categories = ApiHandler::getCategories(); |
246 | 246 | $rowHeaders = [ |
247 | - Console::text('ShortName', 'darkgray') => 15, |
|
248 | - Console::text('Id', 'darkgray') => 2, |
|
249 | - Console::text('Full name', 'darkgray') => 18, |
|
250 | - Console::text('Can be alone?', 'darkgray') => 15 |
|
247 | + Console::text('ShortName', 'darkgray') => 15, |
|
248 | + Console::text('Id', 'darkgray') => 2, |
|
249 | + Console::text('Full name', 'darkgray') => 18, |
|
250 | + Console::text('Can be alone?', 'darkgray') => 15 |
|
251 | 251 | ]; |
252 | 252 | Console::$verticalSeparator = ' '; |
253 | 253 | Console::$verticalInnerSeparator = ' '; |
@@ -257,17 +257,16 @@ discard block |
||
257 | 257 | |
258 | 258 | foreach ($categories as $cat) { |
259 | 259 | $id = Console::text($cat[1], 'white'); |
260 | - $standalone = $cat[3] ? Console::text('✓', 'green') . Console::text(' true ', 'lightgray') : |
|
261 | - Console::text('✗', 'red') . Console::text(' false', 'darkgray'); |
|
262 | - $shortName = Console::text($cat[0], 'white'); |
|
263 | - $fullName = Console::text($cat[2], 'lightgray'); |
|
260 | + $standalone = $cat[3] ? Console::text('✓', 'green').Console::text(' true ', 'lightgray') : Console::text('✗', 'red').Console::text(' false', 'darkgray'); |
|
261 | + $shortName = Console::text($cat[0], 'white'); |
|
262 | + $fullName = Console::text($cat[2], 'lightgray'); |
|
264 | 263 | |
265 | 264 | Console::log( |
266 | 265 | Console::TableRowStart(). |
267 | - Console::TableRowCell( $shortName , 15). |
|
268 | - Console::TableRowCell( $id , 2, Console::ALIGN_CENTER). |
|
269 | - Console::TableRowCell( $fullName , 18). |
|
270 | - Console::TableRowCell( $standalone , 15, Console::ALIGN_CENTER) |
|
266 | + Console::TableRowCell($shortName, 15). |
|
267 | + Console::TableRowCell($id, 2, Console::ALIGN_CENTER). |
|
268 | + Console::TableRowCell($fullName, 18). |
|
269 | + Console::TableRowCell($standalone, 15, Console::ALIGN_CENTER) |
|
271 | 270 | ); |
272 | 271 | } |
273 | 272 | //Console::log(Console::tableRowSeparator($rowHeaders), 'darkgray'); |
@@ -286,11 +285,11 @@ discard block |
||
286 | 285 | */ |
287 | 286 | protected static function reportIP(array $arguments) |
288 | 287 | { |
289 | - $ip = self::getArgumentValue($arguments,'R', 'report'); |
|
290 | - $cats = self::getArgumentValue($arguments,'c', 'categories'); |
|
291 | - $message = self::getArgumentValue($arguments,'m', 'message'); |
|
288 | + $ip = self::getArgumentValue($arguments, 'R', 'report'); |
|
289 | + $cats = self::getArgumentValue($arguments, 'c', 'categories'); |
|
290 | + $message = self::getArgumentValue($arguments, 'm', 'message'); |
|
292 | 291 | |
293 | - self::printTitle(Console::text(' ► Report IP: ', 'darkgray') . Console::text(escapeshellcmd($ip), 'white')); |
|
292 | + self::printTitle(Console::text(' ► Report IP: ', 'darkgray').Console::text(escapeshellcmd($ip), 'white')); |
|
294 | 293 | self::printTempMessage(); |
295 | 294 | |
296 | 295 | // Peforms request |
@@ -301,7 +300,7 @@ discard block |
||
301 | 300 | self::clearTempMessage(); |
302 | 301 | |
303 | 302 | // check for errors / empty response |
304 | - if (self::hasErrors($report)){ |
|
303 | + if (self::hasErrors($report)) { |
|
305 | 304 | self::printFooter(); |
306 | 305 | Program::exit(1); |
307 | 306 | } |
@@ -310,23 +309,23 @@ discard block |
||
310 | 309 | $score = empty($report->data->abuseConfidenceScore) ? 0 : $report->data->abuseConfidenceScore; |
311 | 310 | $scoreColor = self::getScoreColor($score); |
312 | 311 | |
313 | - switch (self::$outputFormat){ |
|
312 | + switch (self::$outputFormat) { |
|
314 | 313 | case self::OUTPUT_JSON: |
315 | 314 | echo json_encode($report, JSON_PRETTY_PRINT); |
316 | 315 | break; |
317 | 316 | |
318 | 317 | case self::OUTPUT_DEFAULT: |
319 | 318 | Console::log( |
320 | - Console::text(' ✓', 'green') . Console::text(' IP: [', 'white') . |
|
321 | - Console::text($ip, $scoreColor) . Console::text('] successfully reported', 'white') |
|
319 | + Console::text(' ✓', 'green').Console::text(' IP: [', 'white'). |
|
320 | + Console::text($ip, $scoreColor).Console::text('] successfully reported', 'white') |
|
322 | 321 | ); |
323 | - Console::log(Console::text(' Confidence score: ', 'white') . self::getScoreBadge($score)); |
|
322 | + Console::log(Console::text(' Confidence score: ', 'white').self::getScoreBadge($score)); |
|
324 | 323 | Console::log(); |
325 | 324 | self::printFooter($time); |
326 | 325 | break; |
327 | 326 | |
328 | 327 | case self::OUTPUT_PLAINTEXT: |
329 | - echo $score . PHP_EOL; |
|
328 | + echo $score.PHP_EOL; |
|
330 | 329 | break; |
331 | 330 | |
332 | 331 | } |
@@ -343,26 +342,26 @@ discard block |
||
343 | 342 | */ |
344 | 343 | protected static function bulkReport(array $arguments) |
345 | 344 | { |
346 | - $fileName = self::getArgumentValue($arguments,'V', 'bulk-report'); |
|
345 | + $fileName = self::getArgumentValue($arguments, 'V', 'bulk-report'); |
|
347 | 346 | |
348 | - self::printTitle(Console::text(' ► Bulk report for file: ', 'darkgray') . Console::text(escapeshellcmd($fileName), 'white')); |
|
347 | + self::printTitle(Console::text(' ► Bulk report for file: ', 'darkgray').Console::text(escapeshellcmd($fileName), 'white')); |
|
349 | 348 | self::printTempMessage(); |
350 | 349 | |
351 | 350 | // Peforms request |
352 | 351 | $timeStart = microtime(true); |
353 | 352 | $response = self::$api->bulkReport($fileName)->getObject(); |
354 | 353 | $timeEnd = microtime(true); |
355 | - $time = $timeEnd - $timeStart; // request time |
|
354 | + $time = $timeEnd - $timeStart; // request time |
|
356 | 355 | self::clearTempMessage(); |
357 | 356 | |
358 | 357 | // check for errors / empty response |
359 | - if (self::hasErrors($response)){ |
|
358 | + if (self::hasErrors($response)) { |
|
360 | 359 | self::printFooter(); |
361 | 360 | Program::exit(1); |
362 | 361 | } |
363 | 362 | |
364 | 363 | // ✓ Done |
365 | - switch (self::$outputFormat){ |
|
364 | + switch (self::$outputFormat) { |
|
366 | 365 | case self::OUTPUT_JSON: |
367 | 366 | echo json_encode($response, JSON_PRETTY_PRINT); |
368 | 367 | break; |
@@ -377,7 +376,7 @@ discard block |
||
377 | 376 | |
378 | 377 | case self::OUTPUT_PLAINTEXT: |
379 | 378 | $nbSavedReports = isset($response->data->savedReports) ? $response->data->savedReports : 0; |
380 | - echo $nbSavedReports . PHP_EOL; |
|
379 | + echo $nbSavedReports.PHP_EOL; |
|
381 | 380 | break; |
382 | 381 | |
383 | 382 | } |
@@ -394,8 +393,8 @@ discard block |
||
394 | 393 | */ |
395 | 394 | protected static function clearIP(array $arguments) |
396 | 395 | { |
397 | - $ip = self::getArgumentValue($arguments,'E', 'clear'); |
|
398 | - self::printTitle(Console::text(' ► Clear reports for IP: ', 'darkgray') . Console::text(escapeshellcmd($ip), 'white')); |
|
396 | + $ip = self::getArgumentValue($arguments, 'E', 'clear'); |
|
397 | + self::printTitle(Console::text(' ► Clear reports for IP: ', 'darkgray').Console::text(escapeshellcmd($ip), 'white')); |
|
399 | 398 | |
400 | 399 | // Peforms request |
401 | 400 | self::printTempMessage(); |
@@ -406,22 +405,22 @@ discard block |
||
406 | 405 | self::clearTempMessage(); |
407 | 406 | |
408 | 407 | // check for errors / empty response |
409 | - if (self::hasErrors($response)){ |
|
408 | + if (self::hasErrors($response)) { |
|
410 | 409 | self::printFooter($time); |
411 | 410 | Program::exit(1); |
412 | 411 | } |
413 | 412 | |
414 | 413 | // ✓ Done: print deleted report number |
415 | - switch (self::$outputFormat){ |
|
414 | + switch (self::$outputFormat) { |
|
416 | 415 | case self::OUTPUT_JSON: |
417 | 416 | echo json_encode($response, JSON_PRETTY_PRINT); |
418 | 417 | break; |
419 | 418 | |
420 | 419 | case self::OUTPUT_DEFAULT: |
421 | 420 | Console::log( |
422 | - Console::text(' ✓', 'green') . |
|
423 | - Console::text(' Successfull clear request for IP: [', 'white') . |
|
424 | - Console::text($ip, 'lightyellow') . |
|
421 | + Console::text(' ✓', 'green'). |
|
422 | + Console::text(' Successfull clear request for IP: [', 'white'). |
|
423 | + Console::text($ip, 'lightyellow'). |
|
425 | 424 | Console::text(']', 'white') |
426 | 425 | ); |
427 | 426 | self::printResult(' Deleted reports: ', $response->data->numReportsDeleted ?? 0, 'lightyellow'); |
@@ -430,7 +429,7 @@ discard block |
||
430 | 429 | break; |
431 | 430 | |
432 | 431 | case self::OUTPUT_PLAINTEXT: |
433 | - echo ($response->data->numReportsDeleted ?? 0) . PHP_EOL; |
|
432 | + echo ($response->data->numReportsDeleted ?? 0).PHP_EOL; |
|
434 | 433 | break; |
435 | 434 | |
436 | 435 | } |
@@ -450,8 +449,8 @@ discard block |
||
450 | 449 | self::printTitle(Console::text(' ► Get Blacklist ', 'darkgray')); |
451 | 450 | |
452 | 451 | $plainText = self::$outputFormat === self::OUTPUT_PLAINTEXT; |
453 | - $limit = self::getNumericParameter($arguments,'l', 'limit', 1000); |
|
454 | - $scoreMin = self::getNumericParameter($arguments,'s', 'score', 100); |
|
452 | + $limit = self::getNumericParameter($arguments, 'l', 'limit', 1000); |
|
453 | + $scoreMin = self::getNumericParameter($arguments, 's', 'score', 100); |
|
455 | 454 | |
456 | 455 | self::printTempMessage(); |
457 | 456 | |
@@ -465,13 +464,13 @@ discard block |
||
465 | 464 | |
466 | 465 | // response could be json on error, while plaintext flag is set |
467 | 466 | $decodedResponse = $response->getObject(); |
468 | - if (self::hasErrors($decodedResponse, false)){ |
|
467 | + if (self::hasErrors($decodedResponse, false)) { |
|
469 | 468 | self::printFooter($time); |
470 | 469 | Program::exit(1); |
471 | 470 | } |
472 | 471 | |
473 | 472 | // ✓ Done: print deleted report number |
474 | - switch (self::$outputFormat){ |
|
473 | + switch (self::$outputFormat) { |
|
475 | 474 | case self::OUTPUT_JSON: |
476 | 475 | echo json_encode($response, JSON_PRETTY_PRINT); |
477 | 476 | break; |
@@ -480,7 +479,7 @@ discard block |
||
480 | 479 | // print list |
481 | 480 | self::printResult(' List generated at: ', self::getDate($decodedResponse->meta->generatedAt), 'lightyellow', ''); |
482 | 481 | Console::log(); |
483 | - foreach ($decodedResponse->data as $report){ |
|
482 | + foreach ($decodedResponse->data as $report) { |
|
484 | 483 | $score = empty($report->abuseConfidenceScore) ? 0 : $report->abuseConfidenceScore; |
485 | 484 | $defaultColor = self::getScoreColor($score); |
486 | 485 | |
@@ -515,12 +514,12 @@ discard block |
||
515 | 514 | */ |
516 | 515 | protected static function checkBlock(array $arguments) |
517 | 516 | { |
518 | - $network = self::getArgumentValue($arguments,'K', 'check-block'); |
|
517 | + $network = self::getArgumentValue($arguments, 'K', 'check-block'); |
|
519 | 518 | |
520 | - self::printTitle(Console::text(' ► Check network: ', 'darkgray') . Console::text(escapeshellcmd($network), 'white') . Console::text('', 'darkgray')); |
|
519 | + self::printTitle(Console::text(' ► Check network: ', 'darkgray').Console::text(escapeshellcmd($network), 'white').Console::text('', 'darkgray')); |
|
521 | 520 | |
522 | 521 | $maxAge = self::getNumericParameter($arguments, 'd', 'days', 30); |
523 | - $limit = self::getNumericParameter($arguments,'l', 'limit', 0); // 0 mean no limit |
|
522 | + $limit = self::getNumericParameter($arguments, 'l', 'limit', 0); // 0 mean no limit |
|
524 | 523 | |
525 | 524 | self::printTempMessage(); |
526 | 525 | |
@@ -531,19 +530,19 @@ discard block |
||
531 | 530 | self::clearTempMessage(); |
532 | 531 | |
533 | 532 | // check for errors / empty response |
534 | - if (self::hasErrors($check)){ |
|
533 | + if (self::hasErrors($check)) { |
|
535 | 534 | self::printFooter($time); |
536 | 535 | Program::exit(1); |
537 | 536 | } |
538 | 537 | |
539 | - switch (self::$outputFormat){ |
|
538 | + switch (self::$outputFormat) { |
|
540 | 539 | case self::OUTPUT_JSON: |
541 | 540 | echo json_encode($check, JSON_PRETTY_PRINT); |
542 | 541 | break; |
543 | 542 | |
544 | 543 | case self::OUTPUT_DEFAULT: |
545 | 544 | self::printCheckBlockDetail($check); |
546 | - self::printCheckBlockReportedIP($check,$maxAge,$limit); |
|
545 | + self::printCheckBlockReportedIP($check, $maxAge, $limit); |
|
547 | 546 | Console::log(); |
548 | 547 | self::printFooter($time); |
549 | 548 | break; |
@@ -552,8 +551,8 @@ discard block |
||
552 | 551 | $nbReports = isset($check->data->reportedAddress) ? count($check->data->reportedAddress) : 0; |
553 | 552 | if ($nbReports > 0) { |
554 | 553 | $numberDiplayedReports = 0; |
555 | - foreach ($check->data->reportedAddress as $report){ |
|
556 | - echo ($report->ipAddress) . ' ' . $report->abuseConfidenceScore . PHP_EOL; |
|
554 | + foreach ($check->data->reportedAddress as $report) { |
|
555 | + echo ($report->ipAddress).' '.$report->abuseConfidenceScore.PHP_EOL; |
|
557 | 556 | |
558 | 557 | // counter |
559 | 558 | $numberDiplayedReports++; |
@@ -577,14 +576,14 @@ discard block |
||
577 | 576 | */ |
578 | 577 | protected static function checkIP(array $arguments) |
579 | 578 | { |
580 | - $ip = self::getArgumentValue($arguments,'C', 'check'); |
|
579 | + $ip = self::getArgumentValue($arguments, 'C', 'check'); |
|
581 | 580 | |
582 | - self::printTitle(Console::text(' ► Check IP: ', 'darkgray') . Console::text(escapeshellcmd($ip), 'white') . Console::text('', 'darkgray')); |
|
581 | + self::printTitle(Console::text(' ► Check IP: ', 'darkgray').Console::text(escapeshellcmd($ip), 'white').Console::text('', 'darkgray')); |
|
583 | 582 | |
584 | - $verbose = self::inArguments($arguments,'v', 'verbose'); |
|
583 | + $verbose = self::inArguments($arguments, 'v', 'verbose'); |
|
585 | 584 | $maxAge = self::getNumericParameter($arguments, 'd', 'days', 30); |
586 | - $maxReportsNumber = self::getNumericParameter($arguments,'l', 'limit', 10); |
|
587 | - $ip = self::getArgumentValue($arguments,'C', 'check'); |
|
585 | + $maxReportsNumber = self::getNumericParameter($arguments, 'l', 'limit', 10); |
|
586 | + $ip = self::getArgumentValue($arguments, 'C', 'check'); |
|
588 | 587 | |
589 | 588 | self::printTempMessage(); |
590 | 589 | $timeStart = microtime(true); |
@@ -594,15 +593,15 @@ discard block |
||
594 | 593 | self::clearTempMessage(); |
595 | 594 | |
596 | 595 | // check for errors / empty response |
597 | - if (self::hasErrors($check)){ |
|
596 | + if (self::hasErrors($check)) { |
|
598 | 597 | self::printFooter($time); |
599 | 598 | Program::exit(1); |
600 | 599 | } |
601 | 600 | |
602 | 601 | // score and data color (depending of abuseConfidenceScore) |
603 | - $score = empty($check->data->abuseConfidenceScore) ? 0 : $check->data->abuseConfidenceScore; |
|
602 | + $score = empty($check->data->abuseConfidenceScore) ? 0 : $check->data->abuseConfidenceScore; |
|
604 | 603 | |
605 | - switch (self::$outputFormat){ |
|
604 | + switch (self::$outputFormat) { |
|
606 | 605 | case self::OUTPUT_JSON: |
607 | 606 | echo json_encode($check, JSON_PRETTY_PRINT); |
608 | 607 | break; |
@@ -612,7 +611,7 @@ discard block |
||
612 | 611 | self::printCheckScore($check); |
613 | 612 | self::printCheckDetail($check, $defaultColor); |
614 | 613 | self::printCheckReports($check, $maxAge, $defaultColor); |
615 | - if ($verbose){ |
|
614 | + if ($verbose) { |
|
616 | 615 | self::printCheckLastReports($check, $maxReportsNumber); |
617 | 616 | } |
618 | 617 | Console::log(); |
@@ -620,7 +619,7 @@ discard block |
||
620 | 619 | break; |
621 | 620 | |
622 | 621 | case self::OUTPUT_PLAINTEXT: |
623 | - echo ($check->data->abuseConfidenceScore ?? 0) . PHP_EOL; |
|
622 | + echo ($check->data->abuseConfidenceScore ?? 0).PHP_EOL; |
|
624 | 623 | break; |
625 | 624 | |
626 | 625 | } |