@@ -37,17 +37,17 @@ discard block |
||
37 | 37 | /** |
38 | 38 | * @var string |
39 | 39 | */ |
40 | - const OUTPUT_JSON = 'json'; |
|
40 | + const OUTPUT_JSON = 'json'; |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * @var string |
44 | 44 | */ |
45 | - const OUTPUT_DEFAULT = 'default'; |
|
45 | + const OUTPUT_DEFAULT = 'default'; |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * @var string |
49 | 49 | */ |
50 | - const OUTPUT_PLAINTEXT = 'plaintext'; |
|
50 | + const OUTPUT_PLAINTEXT = 'plaintext'; |
|
51 | 51 | |
52 | 52 | /** |
53 | 53 | * @var string $outputFormat |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | protected static function printTempMessage(): void |
93 | 93 | { |
94 | 94 | if (self::isDefaultOuput()) { |
95 | - Console::reLog(Console::text(' ? ', 'green') . Console::text('waiting for api response', 'white') . Console::text(' ... ', 'green')); |
|
95 | + Console::reLog(Console::text(' ? ', 'green').Console::text('waiting for api response', 'white').Console::text(' ... ', 'green')); |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
@@ -146,11 +146,11 @@ discard block |
||
146 | 146 | self::printLogo(); |
147 | 147 | |
148 | 148 | Console::log(); |
149 | - Console::log(Console::text(' Kristuff/AbuseIPDB Client version: ', 'darkgray') . Console::text(AbuseIPDBClient::VERSION, 'lightgray')); |
|
150 | - Console::log(Console::text(' Kristuff/AbuseIPDB Core version: ', 'darkgray') . Console::text(ApiHandler::VERSION, 'lightgray')); |
|
149 | + Console::log(Console::text(' Kristuff/AbuseIPDB Client version: ', 'darkgray').Console::text(AbuseIPDBClient::VERSION, 'lightgray')); |
|
150 | + Console::log(Console::text(' Kristuff/AbuseIPDB Core version: ', 'darkgray').Console::text(ApiHandler::VERSION, 'lightgray')); |
|
151 | 151 | Console::log(Console::text(' --------------------------------------------------', 'darkgray')); |
152 | 152 | Console::log(Console::text(' Released under the MIT licence', 'darkgray')); |
153 | - Console::log(Console::text(' Made with ', 'darkgray') . Console::text('♥', 'red') . Console::text(' in France', 'darkgray')); |
|
153 | + Console::log(Console::text(' Made with ', 'darkgray').Console::text('♥', 'red').Console::text(' in France', 'darkgray')); |
|
154 | 154 | Console::log( |
155 | 155 | Console::text(' © 2020-2021 Kristuff (', 'darkgray'). |
156 | 156 | Console::text('https://github.com/kristuff', 'darkgray', 'underlined'). |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | { |
173 | 173 | if (self::isDefaultOuput()) { |
174 | 174 | Console::log(); |
175 | - Console::log( Console::text(' Kristuff/AbuseIPDB-client ', 'darkgray') . Console::text(' ' . AbuseIPDBClient::VERSION . ' ', 'white', 'blue')); |
|
176 | - Console::log(Console::text(' Made with ', 'darkgray') . Console::text('♥', 'red') . Console::text(' in France', 'darkgray')); |
|
175 | + Console::log(Console::text(' Kristuff/AbuseIPDB-client ', 'darkgray').Console::text(' '.AbuseIPDBClient::VERSION.' ', 'white', 'blue')); |
|
176 | + Console::log(Console::text(' Made with ', 'darkgray').Console::text('♥', 'red').Console::text(' in France', 'darkgray')); |
|
177 | 177 | Console::log(Console::text(' © 2020-2021 Kristuff (', 'darkgray'). |
178 | 178 | Console::text('https://github.com/kristuff', 'darkgray', 'underlined'). |
179 | 179 | Console::text(')', 'darkgray') |
@@ -193,19 +193,19 @@ discard block |
||
193 | 193 | protected static function printFooter($requestTime = ''): void |
194 | 194 | { |
195 | 195 | if (self::isDefaultOuput()) { |
196 | - if (!empty($requestTime)){ |
|
196 | + if (!empty($requestTime)) { |
|
197 | 197 | $date_utc = new \DateTime("now", new \DateTimeZone("UTC")); |
198 | 198 | Console::log( |
199 | - Console::text(' Request time: ', 'darkgray') . Console::text($requestTime . 's', 'lightgray'). |
|
200 | - Console::text(' | UTC time: ', 'darkgray') . Console::text($date_utc->format('Y-m-d H:i:s'), 'lightgray') |
|
199 | + Console::text(' Request time: ', 'darkgray').Console::text($requestTime.'s', 'lightgray'). |
|
200 | + Console::text(' | UTC time: ', 'darkgray').Console::text($date_utc->format('Y-m-d H:i:s'), 'lightgray') |
|
201 | 201 | ); |
202 | 202 | } |
203 | 203 | Console::log(Console::text(' ------------------------------------------------------------------------------------------------------', 'darkgray')); |
204 | 204 | Console::log( |
205 | - Console::text(' Kristuff\AbuseIPDB ', 'darkgray') . |
|
206 | - Console::text(AbuseIPDBClient::VERSION, 'lightgray') . |
|
207 | - Console::text(' | Made with ', 'darkgray') . |
|
208 | - Console::text('♥', 'red') . |
|
205 | + Console::text(' Kristuff\AbuseIPDB ', 'darkgray'). |
|
206 | + Console::text(AbuseIPDBClient::VERSION, 'lightgray'). |
|
207 | + Console::text(' | Made with ', 'darkgray'). |
|
208 | + Console::text('♥', 'red'). |
|
209 | 209 | Console::text(' in France | © 2020-2021 Kristuff (https://github.com/kristuff)', 'darkgray') |
210 | 210 | ); |
211 | 211 | Console::log(); |
@@ -223,9 +223,9 @@ discard block |
||
223 | 223 | protected static function printResult($text, $value, string $foregroundColor = 'lightred', string $backgroundColor = '', bool $print = true): string |
224 | 224 | { |
225 | 225 | // do not print null/blank values |
226 | - if (isset($value)){ |
|
227 | - $line = Console::text($text, 'white') . Console::text($value, $foregroundColor, $backgroundColor); |
|
228 | - if ($print && self::isDefaultOuput()){ |
|
226 | + if (isset($value)) { |
|
227 | + $line = Console::text($text, 'white').Console::text($value, $foregroundColor, $backgroundColor); |
|
228 | + if ($print && self::isDefaultOuput()) { |
|
229 | 229 | Console::log($line); |
230 | 230 | } |
231 | 231 | return $line; |
@@ -249,16 +249,16 @@ discard block |
||
249 | 249 | $scoreforegroundColor = 'white'; |
250 | 250 | $scoreBackgroundColor = 'green'; |
251 | 251 | |
252 | - if (intval($score) > 0 ){ |
|
252 | + if (intval($score) > 0) { |
|
253 | 253 | $scoreforegroundColor = 'black'; |
254 | 254 | $scoreBackgroundColor = 'yellow'; |
255 | 255 | } |
256 | - if (intval($score) > 50 ){ |
|
256 | + if (intval($score) > 50) { |
|
257 | 257 | $scoreforegroundColor = 'white'; |
258 | 258 | $scoreBackgroundColor = 'red'; |
259 | 259 | } |
260 | 260 | |
261 | - $badge = str_pad(strval($score), 3, ' ',STR_PAD_LEFT); |
|
261 | + $badge = str_pad(strval($score), 3, ' ', STR_PAD_LEFT); |
|
262 | 262 | return Console::text($padding.$badge.$padding, $scoreforegroundColor, $scoreBackgroundColor); |
263 | 263 | } |
264 | 264 | } |
265 | 265 | \ No newline at end of file |
@@ -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 occurred when writing config file. Make sure to give the appropriate permissions to 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,61 +102,61 @@ 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') . |
|
112 | - Console::text('] [-o ') . |
|
113 | - Console::text('FORMAT', '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 | + Console::text('] [-o '). |
|
113 | + Console::text('FORMAT', 'yellow'). |
|
114 | 114 | Console::text(']')); |
115 | 115 | |
116 | - Console::log(' ' . Console::text(' abuseipdb -K ') . |
|
117 | - Console::text('NETWORK', 'yellow') . |
|
118 | - Console::text(' [-d ') . |
|
119 | - Console::text('DAYS', 'yellow') . |
|
120 | - Console::text('] [-o ') . |
|
121 | - Console::text('FORMAT', 'yellow') . |
|
116 | + Console::log(' '.Console::text(' abuseipdb -K '). |
|
117 | + Console::text('NETWORK', 'yellow'). |
|
118 | + Console::text(' [-d '). |
|
119 | + Console::text('DAYS', 'yellow'). |
|
120 | + Console::text('] [-o '). |
|
121 | + Console::text('FORMAT', 'yellow'). |
|
122 | 122 | Console::text(']')); |
123 | 123 | |
124 | - Console::log(' ' . Console::text(' abuseipdb -R ') . |
|
125 | - Console::text('IP', 'yellow') . ' -c ' . |
|
126 | - Console::text('CATEGORIES', 'yellow') . ' -m ' . |
|
127 | - Console::text('MESSAGE', 'yellow') . |
|
128 | - Console::text(' [-o ') . |
|
129 | - Console::text('FORMAT', 'yellow') . |
|
124 | + Console::log(' '.Console::text(' abuseipdb -R '). |
|
125 | + Console::text('IP', 'yellow').' -c '. |
|
126 | + Console::text('CATEGORIES', 'yellow').' -m '. |
|
127 | + Console::text('MESSAGE', 'yellow'). |
|
128 | + Console::text(' [-o '). |
|
129 | + Console::text('FORMAT', 'yellow'). |
|
130 | 130 | Console::text(']')); |
131 | 131 | |
132 | - Console::log(' ' . Console::text(' abuseipdb -V ') . |
|
133 | - Console::text('FILE', 'yellow') . |
|
134 | - Console::text(' [-o ') . |
|
135 | - Console::text('FORMAT', 'yellow') . |
|
132 | + Console::log(' '.Console::text(' abuseipdb -V '). |
|
133 | + Console::text('FILE', 'yellow'). |
|
134 | + Console::text(' [-o '). |
|
135 | + Console::text('FORMAT', 'yellow'). |
|
136 | 136 | Console::text(']')); |
137 | 137 | |
138 | - Console::log(' ' . Console::text(' abuseipdb -E ') . |
|
138 | + Console::log(' '.Console::text(' abuseipdb -E '). |
|
139 | 139 | Console::text('IP', 'yellow'). |
140 | - Console::text(' [-o ') . |
|
141 | - Console::text('FORMAT', 'yellow') . |
|
140 | + Console::text(' [-o '). |
|
141 | + Console::text('FORMAT', 'yellow'). |
|
142 | 142 | Console::text(']')); |
143 | 143 | |
144 | - Console::log(' ' . Console::text(' abuseipdb -B ') . |
|
145 | - Console::text('[-l ') . |
|
146 | - Console::text('LIMIT', 'yellow') . |
|
147 | - Console::text('] [-s ') . |
|
148 | - Console::text('SCORE', 'yellow') . |
|
149 | - Console::text('] [-o ') . |
|
150 | - Console::text('FORMAT', 'yellow') . |
|
144 | + Console::log(' '.Console::text(' abuseipdb -B '). |
|
145 | + Console::text('[-l '). |
|
146 | + Console::text('LIMIT', 'yellow'). |
|
147 | + Console::text('] [-s '). |
|
148 | + Console::text('SCORE', 'yellow'). |
|
149 | + Console::text('] [-o '). |
|
150 | + Console::text('FORMAT', 'yellow'). |
|
151 | 151 | Console::text(']')); |
152 | 152 | |
153 | - Console::log(' ' . Console::text(' abuseipdb -S ' . |
|
153 | + Console::log(' '.Console::text(' abuseipdb -S '. |
|
154 | 154 | Console::text('KEY', 'yellow'))); |
155 | 155 | |
156 | - Console::log(' ' . Console::text(' abuseipdb -L | -G | -h | --version')); |
|
156 | + Console::log(' '.Console::text(' abuseipdb -L | -G | -h | --version')); |
|
157 | 157 | |
158 | 158 | Console::log(); |
159 | - Console::log(' ' . Console::text('OPTIONS:', 'white', 'underline')); |
|
159 | + Console::log(' '.Console::text('OPTIONS:', 'white', 'underline')); |
|
160 | 160 | Console::log(); |
161 | 161 | Console::log(Console::text(' -h, --help', 'white')); |
162 | 162 | Console::log(' Prints the current help. If given, all next arguments are ignored.', 'lightgray'); |
@@ -167,46 +167,46 @@ discard block |
||
167 | 167 | Console::log(Console::text(' -L, --list', 'white')); |
168 | 168 | Console::log(' Prints the list report categories. If given, all next arguments are ignored.', 'lightgray'); |
169 | 169 | Console::log(); |
170 | - Console::log(Console::text(' -C, --check ', 'white') . Console::text('IP', 'yellow', 'underline')); |
|
170 | + Console::log(Console::text(' -C, --check ', 'white').Console::text('IP', 'yellow', 'underline')); |
|
171 | 171 | Console::log(' Performs a check request for the given IP address. A valid IPv4 or IPv6 address is required.', 'lightgray'); |
172 | 172 | Console::log(); |
173 | - Console::log(Console::text(' -K, --check-block ', 'white') . Console::text('NETWORK', 'yellow', 'underline')); |
|
173 | + Console::log(Console::text(' -K, --check-block ', 'white').Console::text('NETWORK', 'yellow', 'underline')); |
|
174 | 174 | Console::log(' Performs a check-block request for the given network. A valid subnet (v4 or v6) denoted with ', 'lightgray'); |
175 | 175 | Console::log(' CIDR notation is required.', 'lightgray'); |
176 | 176 | Console::log(); |
177 | - Console::log(Console::text(' -d, --days ', 'white') . Console::text('DAYS', 'yellow', 'underline')); |
|
177 | + Console::log(Console::text(' -d, --days ', 'white').Console::text('DAYS', 'yellow', 'underline')); |
|
178 | 178 | Console::log(' For a check or check-block request, defines the maxAgeDays. Min is 1, max is 365, default is 30.', 'lightgray'); |
179 | 179 | Console::log(); |
180 | - Console::log(Console::text(' -R, --report ', 'white') . Console::text('IP', 'yellow', 'underline')); |
|
180 | + Console::log(Console::text(' -R, --report ', 'white').Console::text('IP', 'yellow', 'underline')); |
|
181 | 181 | Console::log(' Performs a report request for the given IP address. A valid IPv4 or IPv6 address is required.', 'lightgray'); |
182 | 182 | Console::log(); |
183 | - Console::log(Console::text(' -V, --bulk-report ', 'white') . Console::text('FILE', 'yellow', 'underline')); |
|
183 | + Console::log(Console::text(' -V, --bulk-report ', 'white').Console::text('FILE', 'yellow', 'underline')); |
|
184 | 184 | Console::log(' Performs a bulk-report request sending a csv file. A valid file name or full path is required.', 'lightgray'); |
185 | 185 | Console::log(); |
186 | 186 | Console::log(Console::text(' -E, --clear ', 'white')); |
187 | 187 | Console::log(' Remove own reports for the given IP address. A valid IPv4 or IPv6 address is required.', 'lightgray'); |
188 | 188 | Console::log(); |
189 | - Console::log(Console::text(' -c, --categories ', 'white') . Console::text('CATEGORIES', 'yellow', 'underline')); |
|
189 | + Console::log(Console::text(' -c, --categories ', 'white').Console::text('CATEGORIES', 'yellow', 'underline')); |
|
190 | 190 | Console::log(' For a report request, defines the report category(ies). Categories must be separate by a comma.', 'lightgray'); |
191 | 191 | Console::log(' Some categories cannot be used alone. A category can be represented by its shortname or by its', 'lightgray'); |
192 | - Console::log(Console::text(' id. Use ','lightgray') . Console::text('abuseipdb -L', 'white') . Console::text(' to print the categories list.','lightgray')); |
|
192 | + Console::log(Console::text(' id. Use ', 'lightgray').Console::text('abuseipdb -L', 'white').Console::text(' to print the categories list.', 'lightgray')); |
|
193 | 193 | Console::log(); |
194 | - Console::log(Console::text(' -m, --message ', 'white') . Console::text('MESSAGE', 'yellow', 'underline')); |
|
194 | + Console::log(Console::text(' -m, --message ', 'white').Console::text('MESSAGE', 'yellow', 'underline')); |
|
195 | 195 | Console::log(' For a report request, defines the message to send with report. Message is required for all', 'lightgray'); |
196 | 196 | Console::log(' report requests.', 'lightgray'); |
197 | 197 | Console::log(); |
198 | 198 | Console::log(Console::text(' -B, --blacklist ', 'white')); |
199 | 199 | Console::log(' Performs a blacklist request. Default limit is 1000. This limit can ne changed with the', 'lightgray'); |
200 | - Console::log(' ' . Console::text('--limit', 'white') . Console::text(' parameter. ', 'lightgray')); |
|
200 | + Console::log(' '.Console::text('--limit', 'white').Console::text(' parameter. ', 'lightgray')); |
|
201 | 201 | Console::log(); |
202 | - Console::log(Console::text(' -l, --limit ', 'white') . Console::text('LIMIT', 'yellow', 'underline')); |
|
202 | + Console::log(Console::text(' -l, --limit ', 'white').Console::text('LIMIT', 'yellow', 'underline')); |
|
203 | 203 | Console::log(' For a blacklist request, defines the limit.', 'lightgray'); |
204 | 204 | Console::log(' For a check request with verbose flag, sets the max number of last reports displayed. Default is 10', 'lightgray'); |
205 | 205 | Console::log(' For a check-block request, sets the max number of IPs displayed. Default is 0 (no limit).', 'lightgray'); |
206 | 206 | Console::log(); |
207 | - Console::log(Console::text(' -o, --output ', 'white') . Console::text('FORMAT', 'yellow', 'underline')); |
|
207 | + Console::log(Console::text(' -o, --output ', 'white').Console::text('FORMAT', 'yellow', 'underline')); |
|
208 | 208 | Console::log(' Defines the output format for API requests. Default is a colorized report, possible formats are', 'lightgray'); |
209 | - Console::log(' '. Console::text('json', 'yellow', 'underline') . ' or ' . Console::text('plaintext', 'yellow', 'underline') . '. Plaintext option prints partial response (blacklist: IPs list, '); |
|
209 | + Console::log(' '.Console::text('json', 'yellow', 'underline').' or '.Console::text('plaintext', 'yellow', 'underline').'. Plaintext option prints partial response (blacklist: IPs list, '); |
|
210 | 210 | Console::log(' check or report: confidence score only, check-block: reported IPs list with confidence score, ', 'lightgray'); |
211 | 211 | Console::log(' bulk-report: number of saved reports, clear: number of deleted reports).', 'lightgray'); |
212 | 212 | Console::log(); |
@@ -217,12 +217,12 @@ discard block |
||
217 | 217 | Console::log(Console::text(' -v, --verbose ', 'white')); |
218 | 218 | Console::log(' For a check request, display additional fields like the x last reports. This increases ', 'lightgray'); |
219 | 219 | Console::log(Console::text(' request time and response size. Max number of last reports displayed can be changed with the ', 'lightgray')); |
220 | - Console::log(' ' . Console::text('--limit', 'white') . Console::text(' parameter. ', 'lightgray')); |
|
220 | + Console::log(' '.Console::text('--limit', 'white').Console::text(' parameter. ', 'lightgray')); |
|
221 | 221 | Console::log(); |
222 | 222 | Console::log(Console::text(' --version', 'white')); |
223 | 223 | Console::log(' Prints the current version. If given, all next arguments are ignored.', 'lightgray'); |
224 | 224 | Console::log(); |
225 | - Console::log(Console::text(' -S, --save-key ', 'white') . Console::text('KEY', 'yellow', 'underline')); |
|
225 | + Console::log(Console::text(' -S, --save-key ', 'white').Console::text('KEY', 'yellow', 'underline')); |
|
226 | 226 | Console::log(' Save the given API key in the configuration file. Requires writing permissions on the config directory. ', 'lightgray'); |
227 | 227 | Console::log(); |
228 | 228 | } |
@@ -241,11 +241,11 @@ discard block |
||
241 | 241 | |
242 | 242 | self::printTitle(Console::text(' ► Current configuration ', 'darkgray')); |
243 | 243 | |
244 | - Console::log(Console::text(' api_key:[', 'white') . Console::text($conf['apiKey'], 'green') . Console::text(']', 'white')); |
|
244 | + Console::log(Console::text(' api_key:[', 'white').Console::text($conf['apiKey'], 'green').Console::text(']', 'white')); |
|
245 | 245 | Console::log(Console::text(' self_ips:', 'white')); |
246 | 246 | |
247 | 247 | foreach ($conf['selfIps'] as $ip) { |
248 | - Console::log(Console::text(' [', 'white') . Console::text($ip, 'green') . Console::text(']', 'white')); |
|
248 | + Console::log(Console::text(' [', 'white').Console::text($ip, 'green').Console::text(']', 'white')); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | Console::log(); |
@@ -266,10 +266,10 @@ discard block |
||
266 | 266 | |
267 | 267 | $categories = ApiHandler::getCategories(); |
268 | 268 | $rowHeaders = [ |
269 | - Console::text('ShortName', 'darkgray') => 15, |
|
270 | - Console::text('Id', 'darkgray') => 2, |
|
271 | - Console::text('Full name', 'darkgray') => 18, |
|
272 | - Console::text('Can be alone?', 'darkgray') => 15 |
|
269 | + Console::text('ShortName', 'darkgray') => 15, |
|
270 | + Console::text('Id', 'darkgray') => 2, |
|
271 | + Console::text('Full name', 'darkgray') => 18, |
|
272 | + Console::text('Can be alone?', 'darkgray') => 15 |
|
273 | 273 | ]; |
274 | 274 | Console::$verticalSeparator = ' '; |
275 | 275 | Console::$verticalInnerSeparator = ' '; |
@@ -279,17 +279,16 @@ discard block |
||
279 | 279 | |
280 | 280 | foreach ($categories as $cat) { |
281 | 281 | $id = Console::text($cat[1], 'white'); |
282 | - $standalone = $cat[3] ? Console::text('✓', 'green') . Console::text(' true ', 'lightgray') : |
|
283 | - Console::text('✗', 'red') . Console::text(' false', 'darkgray'); |
|
284 | - $shortName = Console::text($cat[0], 'white'); |
|
285 | - $fullName = Console::text($cat[2], 'lightgray'); |
|
282 | + $standalone = $cat[3] ? Console::text('✓', 'green').Console::text(' true ', 'lightgray') : Console::text('✗', 'red').Console::text(' false', 'darkgray'); |
|
283 | + $shortName = Console::text($cat[0], 'white'); |
|
284 | + $fullName = Console::text($cat[2], 'lightgray'); |
|
286 | 285 | |
287 | 286 | Console::log( |
288 | 287 | Console::TableRowStart(). |
289 | - Console::TableRowCell( $shortName , 15). |
|
290 | - Console::TableRowCell( $id , 2, Console::ALIGN_CENTER). |
|
291 | - Console::TableRowCell( $fullName , 18). |
|
292 | - Console::TableRowCell( $standalone , 15, Console::ALIGN_CENTER) |
|
288 | + Console::TableRowCell($shortName, 15). |
|
289 | + Console::TableRowCell($id, 2, Console::ALIGN_CENTER). |
|
290 | + Console::TableRowCell($fullName, 18). |
|
291 | + Console::TableRowCell($standalone, 15, Console::ALIGN_CENTER) |
|
293 | 292 | ); |
294 | 293 | } |
295 | 294 | //Console::log(Console::tableRowSeparator($rowHeaders), 'darkgray'); |
@@ -308,11 +307,11 @@ discard block |
||
308 | 307 | */ |
309 | 308 | protected static function reportIP(array $arguments): void |
310 | 309 | { |
311 | - $ip = self::getArgumentValue($arguments,'R', 'report'); |
|
312 | - $cats = self::getArgumentValue($arguments,'c', 'categories'); |
|
313 | - $message = self::getArgumentValue($arguments,'m', 'message'); |
|
310 | + $ip = self::getArgumentValue($arguments, 'R', 'report'); |
|
311 | + $cats = self::getArgumentValue($arguments, 'c', 'categories'); |
|
312 | + $message = self::getArgumentValue($arguments, 'm', 'message'); |
|
314 | 313 | |
315 | - self::printTitle(Console::text(' ► Report IP: ', 'darkgray') . Console::text(escapeshellcmd($ip), 'white')); |
|
314 | + self::printTitle(Console::text(' ► Report IP: ', 'darkgray').Console::text(escapeshellcmd($ip), 'white')); |
|
316 | 315 | self::printTempMessage(); |
317 | 316 | |
318 | 317 | // Peforms request |
@@ -323,7 +322,7 @@ discard block |
||
323 | 322 | self::clearTempMessage(); |
324 | 323 | |
325 | 324 | // check for errors / empty response |
326 | - if (self::hasErrors($report)){ |
|
325 | + if (self::hasErrors($report)) { |
|
327 | 326 | self::printFooter(); |
328 | 327 | Program::exit(1); |
329 | 328 | } |
@@ -332,14 +331,14 @@ discard block |
||
332 | 331 | $score = empty($report->data->abuseConfidenceScore) ? 0 : $report->data->abuseConfidenceScore; |
333 | 332 | $scoreColor = self::getScoreColor($score); |
334 | 333 | |
335 | - switch (self::$outputFormat){ |
|
334 | + switch (self::$outputFormat) { |
|
336 | 335 | case self::OUTPUT_JSON: |
337 | 336 | echo json_encode($report, JSON_PRETTY_PRINT); |
338 | 337 | break; |
339 | 338 | |
340 | 339 | case self::OUTPUT_DEFAULT: |
341 | 340 | Console::log( |
342 | - Console::text(' ✓', 'green').Console::text(' IP: [', 'white') . |
|
341 | + Console::text(' ✓', 'green').Console::text(' IP: [', 'white'). |
|
343 | 342 | Console::text($ip, $scoreColor).Console::text('] successfully reported', 'white') |
344 | 343 | ); |
345 | 344 | Console::log(Console::text(' Confidence score: ', 'white').self::getScoreBadge($score)); |
@@ -365,26 +364,26 @@ discard block |
||
365 | 364 | */ |
366 | 365 | protected static function bulkReport(array $arguments): void |
367 | 366 | { |
368 | - $fileName = self::getArgumentValue($arguments,'V', 'bulk-report'); |
|
367 | + $fileName = self::getArgumentValue($arguments, 'V', 'bulk-report'); |
|
369 | 368 | |
370 | - self::printTitle(Console::text(' ► Bulk report for file: ', 'darkgray') . Console::text(escapeshellcmd($fileName), 'white')); |
|
369 | + self::printTitle(Console::text(' ► Bulk report for file: ', 'darkgray').Console::text(escapeshellcmd($fileName), 'white')); |
|
371 | 370 | self::printTempMessage(); |
372 | 371 | |
373 | 372 | // Peforms request |
374 | 373 | $timeStart = microtime(true); |
375 | 374 | $response = self::$api->bulkReport($fileName)->getObject(); |
376 | 375 | $timeEnd = microtime(true); |
377 | - $time = $timeEnd - $timeStart; // request time |
|
376 | + $time = $timeEnd - $timeStart; // request time |
|
378 | 377 | self::clearTempMessage(); |
379 | 378 | |
380 | 379 | // check for errors / empty response |
381 | - if (self::hasErrors($response)){ |
|
380 | + if (self::hasErrors($response)) { |
|
382 | 381 | self::printFooter(); |
383 | 382 | Program::exit(1); |
384 | 383 | } |
385 | 384 | |
386 | 385 | // ✓ Done |
387 | - switch (self::$outputFormat){ |
|
386 | + switch (self::$outputFormat) { |
|
388 | 387 | case self::OUTPUT_JSON: |
389 | 388 | echo json_encode($response, JSON_PRETTY_PRINT); |
390 | 389 | break; |
@@ -399,7 +398,7 @@ discard block |
||
399 | 398 | |
400 | 399 | case self::OUTPUT_PLAINTEXT: |
401 | 400 | $nbSavedReports = isset($response->data->savedReports) ? $response->data->savedReports : 0; |
402 | - echo $nbSavedReports . PHP_EOL; |
|
401 | + echo $nbSavedReports.PHP_EOL; |
|
403 | 402 | break; |
404 | 403 | |
405 | 404 | } |
@@ -416,8 +415,8 @@ discard block |
||
416 | 415 | */ |
417 | 416 | protected static function clearIP(array $arguments): void |
418 | 417 | { |
419 | - $ip = self::getArgumentValue($arguments,'E', 'clear'); |
|
420 | - self::printTitle(Console::text(' ► Clear reports for IP: ', 'darkgray') . Console::text(escapeshellcmd($ip), 'white')); |
|
418 | + $ip = self::getArgumentValue($arguments, 'E', 'clear'); |
|
419 | + self::printTitle(Console::text(' ► Clear reports for IP: ', 'darkgray').Console::text(escapeshellcmd($ip), 'white')); |
|
421 | 420 | |
422 | 421 | // Peforms request |
423 | 422 | self::printTempMessage(); |
@@ -428,22 +427,22 @@ discard block |
||
428 | 427 | self::clearTempMessage(); |
429 | 428 | |
430 | 429 | // check for errors / empty response |
431 | - if (self::hasErrors($response)){ |
|
430 | + if (self::hasErrors($response)) { |
|
432 | 431 | self::printFooter($time); |
433 | 432 | Program::exit(1); |
434 | 433 | } |
435 | 434 | |
436 | 435 | // ✓ Done: print deleted report number |
437 | - switch (self::$outputFormat){ |
|
436 | + switch (self::$outputFormat) { |
|
438 | 437 | case self::OUTPUT_JSON: |
439 | 438 | echo json_encode($response, JSON_PRETTY_PRINT); |
440 | 439 | break; |
441 | 440 | |
442 | 441 | case self::OUTPUT_DEFAULT: |
443 | 442 | Console::log( |
444 | - Console::text(' ✓', 'green') . |
|
445 | - Console::text(' Successfull clear request for IP: [', 'white') . |
|
446 | - Console::text($ip, 'lightyellow') . |
|
443 | + Console::text(' ✓', 'green'). |
|
444 | + Console::text(' Successfull clear request for IP: [', 'white'). |
|
445 | + Console::text($ip, 'lightyellow'). |
|
447 | 446 | Console::text(']', 'white') |
448 | 447 | ); |
449 | 448 | self::printResult(' Deleted reports: ', $response->data->numReportsDeleted ?? 0, 'lightyellow'); |
@@ -452,7 +451,7 @@ discard block |
||
452 | 451 | break; |
453 | 452 | |
454 | 453 | case self::OUTPUT_PLAINTEXT: |
455 | - echo ($response->data->numReportsDeleted ?? 0) . PHP_EOL; |
|
454 | + echo ($response->data->numReportsDeleted ?? 0).PHP_EOL; |
|
456 | 455 | break; |
457 | 456 | |
458 | 457 | } |
@@ -472,8 +471,8 @@ discard block |
||
472 | 471 | self::printTitle(Console::text(' ► Get Blacklist ', 'darkgray')); |
473 | 472 | |
474 | 473 | $plainText = (self::$outputFormat === self::OUTPUT_PLAINTEXT); |
475 | - $limit = self::getNumericParameter($arguments,'l', 'limit', 1000); |
|
476 | - $scoreMin = self::getNumericParameter($arguments,'s', 'score', 100); |
|
474 | + $limit = self::getNumericParameter($arguments, 'l', 'limit', 1000); |
|
475 | + $scoreMin = self::getNumericParameter($arguments, 's', 'score', 100); |
|
477 | 476 | |
478 | 477 | self::printTempMessage(); |
479 | 478 | |
@@ -487,13 +486,13 @@ discard block |
||
487 | 486 | |
488 | 487 | // response could be json on error, while plaintext flag is set |
489 | 488 | $decodedResponse = $response->getObject(); |
490 | - if (self::hasErrors($decodedResponse, false)){ |
|
489 | + if (self::hasErrors($decodedResponse, false)) { |
|
491 | 490 | self::printFooter($time); |
492 | 491 | Program::exit(1); |
493 | 492 | } |
494 | 493 | |
495 | 494 | // ✓ Done: print deleted report number |
496 | - switch (self::$outputFormat){ |
|
495 | + switch (self::$outputFormat) { |
|
497 | 496 | case self::OUTPUT_JSON: |
498 | 497 | echo json_encode($decodedResponse, JSON_PRETTY_PRINT); |
499 | 498 | break; |
@@ -502,7 +501,7 @@ discard block |
||
502 | 501 | // print list |
503 | 502 | self::printResult(' List generated at: ', self::getDate($decodedResponse->meta->generatedAt), 'lightyellow', ''); |
504 | 503 | Console::log(); |
505 | - foreach ($decodedResponse->data as $report){ |
|
504 | + foreach ($decodedResponse->data as $report) { |
|
506 | 505 | $score = empty($report->abuseConfidenceScore) ? 0 : $report->abuseConfidenceScore; |
507 | 506 | $defaultColor = self::getScoreColor($score); |
508 | 507 | |
@@ -537,12 +536,12 @@ discard block |
||
537 | 536 | */ |
538 | 537 | protected static function checkBlock(array $arguments): void |
539 | 538 | { |
540 | - $network = self::getArgumentValue($arguments,'K', 'check-block'); |
|
539 | + $network = self::getArgumentValue($arguments, 'K', 'check-block'); |
|
541 | 540 | |
542 | - self::printTitle(Console::text(' ► Check network: ', 'darkgray') . Console::text(escapeshellcmd($network), 'white') . Console::text('', 'darkgray')); |
|
541 | + self::printTitle(Console::text(' ► Check network: ', 'darkgray').Console::text(escapeshellcmd($network), 'white').Console::text('', 'darkgray')); |
|
543 | 542 | |
544 | 543 | $maxAge = self::getNumericParameter($arguments, 'd', 'days', 30); |
545 | - $limit = self::getNumericParameter($arguments,'l', 'limit', 0); // 0 mean no limit |
|
544 | + $limit = self::getNumericParameter($arguments, 'l', 'limit', 0); // 0 mean no limit |
|
546 | 545 | |
547 | 546 | self::printTempMessage(); |
548 | 547 | |
@@ -553,19 +552,19 @@ discard block |
||
553 | 552 | self::clearTempMessage(); |
554 | 553 | |
555 | 554 | // check for errors / empty response |
556 | - if (self::hasErrors($check)){ |
|
555 | + if (self::hasErrors($check)) { |
|
557 | 556 | self::printFooter($time); |
558 | 557 | Program::exit(1); |
559 | 558 | } |
560 | 559 | |
561 | - switch (self::$outputFormat){ |
|
560 | + switch (self::$outputFormat) { |
|
562 | 561 | case self::OUTPUT_JSON: |
563 | 562 | echo json_encode($check, JSON_PRETTY_PRINT); |
564 | 563 | break; |
565 | 564 | |
566 | 565 | case self::OUTPUT_DEFAULT: |
567 | 566 | self::printCheckBlockDetail($check); |
568 | - self::printCheckBlockReportedIP($check,$maxAge,$limit); |
|
567 | + self::printCheckBlockReportedIP($check, $maxAge, $limit); |
|
569 | 568 | Console::log(); |
570 | 569 | self::printFooter($time); |
571 | 570 | break; |
@@ -574,8 +573,8 @@ discard block |
||
574 | 573 | $nbReports = isset($check->data->reportedAddress) ? count($check->data->reportedAddress) : 0; |
575 | 574 | if ($nbReports > 0) { |
576 | 575 | $numberDiplayedReports = 0; |
577 | - foreach ($check->data->reportedAddress as $report){ |
|
578 | - echo ($report->ipAddress) . ' ' . $report->abuseConfidenceScore . PHP_EOL; |
|
576 | + foreach ($check->data->reportedAddress as $report) { |
|
577 | + echo ($report->ipAddress).' '.$report->abuseConfidenceScore.PHP_EOL; |
|
579 | 578 | |
580 | 579 | // counter |
581 | 580 | $numberDiplayedReports++; |
@@ -599,14 +598,14 @@ discard block |
||
599 | 598 | */ |
600 | 599 | protected static function checkIP(array $arguments): void |
601 | 600 | { |
602 | - $ip = self::getArgumentValue($arguments,'C', 'check'); |
|
601 | + $ip = self::getArgumentValue($arguments, 'C', 'check'); |
|
603 | 602 | |
604 | - self::printTitle(Console::text(' ► Check IP: ', 'darkgray') . Console::text(escapeshellcmd($ip), 'white') . Console::text('', 'darkgray')); |
|
603 | + self::printTitle(Console::text(' ► Check IP: ', 'darkgray').Console::text(escapeshellcmd($ip), 'white').Console::text('', 'darkgray')); |
|
605 | 604 | |
606 | - $verbose = self::inArguments($arguments,'v', 'verbose'); |
|
605 | + $verbose = self::inArguments($arguments, 'v', 'verbose'); |
|
607 | 606 | $maxAge = self::getNumericParameter($arguments, 'd', 'days', 30); |
608 | - $maxReportsNumber = self::getNumericParameter($arguments,'l', 'limit', 10); |
|
609 | - $ip = self::getArgumentValue($arguments,'C', 'check'); |
|
607 | + $maxReportsNumber = self::getNumericParameter($arguments, 'l', 'limit', 10); |
|
608 | + $ip = self::getArgumentValue($arguments, 'C', 'check'); |
|
610 | 609 | |
611 | 610 | self::printTempMessage(); |
612 | 611 | $timeStart = microtime(true); |
@@ -616,7 +615,7 @@ discard block |
||
616 | 615 | self::clearTempMessage(); |
617 | 616 | |
618 | 617 | // check for errors / empty response |
619 | - if (self::hasErrors($check)){ |
|
618 | + if (self::hasErrors($check)) { |
|
620 | 619 | self::printFooter($time); |
621 | 620 | Program::exit(1); |
622 | 621 | } |
@@ -624,7 +623,7 @@ discard block |
||
624 | 623 | // score and data color (depending of abuseConfidenceScore) |
625 | 624 | $score = empty($check->data->abuseConfidenceScore) ? 0 : $check->data->abuseConfidenceScore; |
626 | 625 | |
627 | - switch (self::$outputFormat){ |
|
626 | + switch (self::$outputFormat) { |
|
628 | 627 | case self::OUTPUT_JSON: |
629 | 628 | echo json_encode($check, JSON_PRETTY_PRINT); |
630 | 629 | break; |
@@ -634,7 +633,7 @@ discard block |
||
634 | 633 | self::printCheckScore($check); |
635 | 634 | self::printCheckDetail($check, $defaultColor); |
636 | 635 | self::printCheckReports($check, $maxAge, $defaultColor); |
637 | - if ($verbose){ |
|
636 | + if ($verbose) { |
|
638 | 637 | self::printCheckLastReports($check, $maxReportsNumber); |
639 | 638 | } |
640 | 639 | Console::log(); |
@@ -642,7 +641,7 @@ discard block |
||
642 | 641 | break; |
643 | 642 | |
644 | 643 | case self::OUTPUT_PLAINTEXT: |
645 | - echo ($check->data->abuseConfidenceScore ?? 0) . PHP_EOL; |
|
644 | + echo ($check->data->abuseConfidenceScore ?? 0).PHP_EOL; |
|
646 | 645 | break; |
647 | 646 | |
648 | 647 | } |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | */ |
57 | 57 | private static function parseErrors(?object $response = null): bool |
58 | 58 | { |
59 | - if (isset($response) && isset($response->errors)){ |
|
60 | - switch (self::$outputFormat){ |
|
59 | + if (isset($response) && isset($response->errors)) { |
|
60 | + switch (self::$outputFormat) { |
|
61 | 61 | case self::OUTPUT_DEFAULT: |
62 | 62 | self::printFormattedErrors($response); |
63 | 63 | break; |
@@ -86,24 +86,24 @@ discard block |
||
86 | 86 | protected static function printFormattedErrors(object $response): void |
87 | 87 | { |
88 | 88 | // top error badge |
89 | - Console::log(' ' . Console::text(' ERROR ','white', 'red')); |
|
89 | + Console::log(' '.Console::text(' ERROR ', 'white', 'red')); |
|
90 | 90 | |
91 | 91 | $num = 0; |
92 | 92 | // errors is an array, could have more than one error.. |
93 | - foreach ($response->errors as $err){ |
|
93 | + foreach ($response->errors as $err) { |
|
94 | 94 | $num++; |
95 | 95 | |
96 | - Console::log(Console::text(' ✗', 'red') . self::printResult(' Number: ', $num, 'lightyellow','', false)); |
|
97 | - self::printResult(' Status: ', $err->status ?? null, 'lightyellow',''); |
|
96 | + Console::log(Console::text(' ✗', 'red').self::printResult(' Number: ', $num, 'lightyellow', '', false)); |
|
97 | + self::printResult(' Status: ', $err->status ?? null, 'lightyellow', ''); |
|
98 | 98 | |
99 | - if (!empty($err->source) && !empty($err->source->parameter)){ |
|
99 | + if (!empty($err->source) && !empty($err->source->parameter)) { |
|
100 | 100 | self::printResult(' Parameter: ', $err->source->parameter, 'lightyellow'); |
101 | 101 | } |
102 | 102 | self::printResult(' Title: ', $err->title ?? null, 'lightyellow'); |
103 | 103 | self::printResult(' Detail: ', $err->detail ?? null, 'lightyellow'); |
104 | 104 | |
105 | 105 | // separate errors |
106 | - if (count($response->errors) > 1){ |
|
106 | + if (count($response->errors) > 1) { |
|
107 | 107 | Console::log(' ---'); |
108 | 108 | } |
109 | 109 | } |
@@ -123,11 +123,11 @@ discard block |
||
123 | 123 | { |
124 | 124 | if (self::isDefaultOuput()) { |
125 | 125 | // ✗ |
126 | - Console::log(' ' . Console::text(' ERROR ','white', 'red')); |
|
126 | + Console::log(' '.Console::text(' ERROR ', 'white', 'red')); |
|
127 | 127 | Console::log( |
128 | - Console::text(' ✗', 'red') . |
|
129 | - Console::text(' Detail: ', 'white') . |
|
130 | - Console::text($error, 'lightyellow') . |
|
128 | + Console::text(' ✗', 'red'). |
|
129 | + Console::text(' Detail: ', 'white'). |
|
130 | + Console::text($error, 'lightyellow'). |
|
131 | 131 | Console::text('', 'white') |
132 | 132 | ); |
133 | 133 | Console::log(); |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | */ |
148 | 148 | protected static function validate(bool $condition, string $message, bool $print = true): void |
149 | 149 | { |
150 | - if ( !$condition ){ |
|
150 | + if (!$condition) { |
|
151 | 151 | if ($print && self::isDefaultOuput()) { |
152 | 152 | Console::log(); |
153 | 153 | self::error($message); |
@@ -171,10 +171,10 @@ discard block |
||
171 | 171 | */ |
172 | 172 | protected static function getNumericParameter(array $arguments, string $shortArg, string $longArg, int $defaultValue): int |
173 | 173 | { |
174 | - if (self::inArguments($arguments,$shortArg, $longArg)){ |
|
175 | - $val = self::getArgumentValue($arguments,$shortArg, $longArg); |
|
174 | + if (self::inArguments($arguments, $shortArg, $longArg)) { |
|
175 | + $val = self::getArgumentValue($arguments, $shortArg, $longArg); |
|
176 | 176 | |
177 | - if (!is_numeric($val)){ |
|
177 | + if (!is_numeric($val)) { |
|
178 | 178 | self::error("Invalid parameter: $longArg must be a numeric value."); |
179 | 179 | self::printFooter(); |
180 | 180 | Program::exit(1); |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | */ |
196 | 196 | protected static function printPlainTextErrors(object $response): void |
197 | 197 | { |
198 | - foreach ($response->errors as $err){ |
|
198 | + foreach ($response->errors as $err) { |
|
199 | 199 | $text = 'Error: '; |
200 | 200 | $text .= self::getErrorDetail($err, 'title'); |
201 | 201 | $text .= self::getErrorDetail($err, 'statuts'); |
@@ -219,11 +219,11 @@ discard block |
||
219 | 219 | */ |
220 | 220 | private static function getErrorDetail(object $error, string $field, ?string $parent = null): string |
221 | 221 | { |
222 | - if (!empty($parent)){ |
|
223 | - return !empty($error->$parent) && !empty($error->$parent->$field) ? ' ' . $field . ': ' . $error->$parent->$field : ''; |
|
222 | + if (!empty($parent)) { |
|
223 | + return !empty($error->$parent) && !empty($error->$parent->$field) ? ' '.$field.': '.$error->$parent->$field : ''; |
|
224 | 224 | } |
225 | 225 | |
226 | - return !empty($error->$field) ? ' ' . $field . ': ' . $error->$field : ''; |
|
226 | + return !empty($error->$field) ? ' '.$field.': '.$error->$field : ''; |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | protected static function checkForEmpty(object $response): bool |
239 | 239 | { |
240 | 240 | // check for empty response ? |
241 | - if ( empty($response) || empty($response->data) ){ |
|
241 | + if (empty($response) || empty($response->data)) { |
|
242 | 242 | self::error('An unexpected error occurred.'); |
243 | 243 | return true; |
244 | 244 | } |