@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | use function time; |
37 | 37 | use function version_compare; |
38 | 38 | |
39 | - /** |
|
40 | - * Cross-Site Scripting protection. |
|
41 | - */ |
|
39 | + /** |
|
40 | + * Cross-Site Scripting protection. |
|
41 | + */ |
|
42 | 42 | class Xss |
43 | 43 | { |
44 | 44 | /** |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | unset($original); |
286 | 286 | |
287 | 287 | // Remove evil attributes such as style, onclick and xmlns |
288 | - $str = $this->removeEvilAttributes($str, $isImage); |
|
288 | + $str = $this->removeEvilAttributes($str, $isImage); |
|
289 | 289 | |
290 | 290 | /* |
291 | 291 | * Sanitize naughty HTML elements |
@@ -449,62 +449,62 @@ discard block |
||
449 | 449 | * @param boolean $is_image TRUE if this is an image |
450 | 450 | * @return string The string with the evil attributes removed |
451 | 451 | */ |
452 | - protected function removeEvilAttributes($str, $is_image) |
|
453 | - { |
|
454 | - // All javascript event handlers (e.g. onload, onclick, onmouseover), style, and xmlns |
|
455 | - $evilAttributes = array('on\w*', 'style', 'xmlns', 'formaction', 'form', 'xlink:href'); |
|
452 | + protected function removeEvilAttributes($str, $is_image) |
|
453 | + { |
|
454 | + // All javascript event handlers (e.g. onload, onclick, onmouseover), style, and xmlns |
|
455 | + $evilAttributes = array('on\w*', 'style', 'xmlns', 'formaction', 'form', 'xlink:href'); |
|
456 | 456 | |
457 | - if ($is_image) { |
|
458 | - /* |
|
457 | + if ($is_image) { |
|
458 | + /* |
|
459 | 459 | * Adobe Photoshop puts XML metadata into JFIF images, |
460 | 460 | * including namespacing, so we have to allow this for images. |
461 | 461 | */ |
462 | - unset($evilAttributes[array_search('xmlns', $evilAttributes)]); |
|
463 | - } |
|
462 | + unset($evilAttributes[array_search('xmlns', $evilAttributes)]); |
|
463 | + } |
|
464 | 464 | |
465 | - do { |
|
466 | - $count = 0; |
|
467 | - $attribs = array(); |
|
465 | + do { |
|
466 | + $count = 0; |
|
467 | + $attribs = array(); |
|
468 | 468 | |
469 | - // find occurrences of illegal attribute strings with quotes (042 and 047 are octal quotes) |
|
470 | - preg_match_all( |
|
469 | + // find occurrences of illegal attribute strings with quotes (042 and 047 are octal quotes) |
|
470 | + preg_match_all( |
|
471 | 471 | '/(?<!\w)(' . implode('|', $evilAttributes) . ')\s*=\s*(\042|\047)([^\\2]*?)(\\2)/is', |
472 | 472 | $str, |
473 | 473 | $matches, |
474 | 474 | PREG_SET_ORDER |
475 | 475 | ); |
476 | 476 | |
477 | - foreach ($matches as $attr) { |
|
478 | - $attribs[] = preg_quote($attr[0], '/'); |
|
479 | - } |
|
477 | + foreach ($matches as $attr) { |
|
478 | + $attribs[] = preg_quote($attr[0], '/'); |
|
479 | + } |
|
480 | 480 | |
481 | - // find occurrences of illegal attribute strings without quotes |
|
482 | - preg_match_all( |
|
481 | + // find occurrences of illegal attribute strings without quotes |
|
482 | + preg_match_all( |
|
483 | 483 | '/(?<!\w)(' . implode('|', $evilAttributes) . ')\s*=\s*([^\s>]*)/is', |
484 | 484 | $str, |
485 | 485 | $matches, |
486 | 486 | PREG_SET_ORDER |
487 | 487 | ); |
488 | 488 | |
489 | - foreach ($matches as $attr) { |
|
490 | - $attribs[] = preg_quote($attr[0], '/'); |
|
491 | - } |
|
489 | + foreach ($matches as $attr) { |
|
490 | + $attribs[] = preg_quote($attr[0], '/'); |
|
491 | + } |
|
492 | 492 | |
493 | - // replace illegal attribute strings that are inside an html tag |
|
494 | - if (count($attribs) > 0) { |
|
495 | - $str = preg_replace( |
|
493 | + // replace illegal attribute strings that are inside an html tag |
|
494 | + if (count($attribs) > 0) { |
|
495 | + $str = preg_replace( |
|
496 | 496 | '/(<?)(\/?[^><]+?)([^A-Za-z<>\-])(.*?)(' . implode('|', $attribs) . ')(.*?)([\s><]?)([><]*)/i', |
497 | 497 | '$1$2 $4$6$7$8', |
498 | 498 | $str, |
499 | 499 | -1, |
500 | 500 | $count |
501 | 501 | ); |
502 | - } |
|
502 | + } |
|
503 | 503 | |
504 | - } while ($count); |
|
504 | + } while ($count); |
|
505 | 505 | |
506 | - return $str; |
|
507 | - } |
|
506 | + return $str; |
|
507 | + } |
|
508 | 508 | |
509 | 509 | /** |
510 | 510 | * Random Hash for protecting URLs |
@@ -895,16 +895,16 @@ discard block |
||
895 | 895 | * @return bool |
896 | 896 | */ |
897 | 897 | protected function isPHP($version): bool |
898 | - { |
|
898 | + { |
|
899 | 899 | static $_isPHP; |
900 | 900 | |
901 | - $version = (string) $version; |
|
901 | + $version = (string) $version; |
|
902 | 902 | |
903 | - if (! isset($_isPHP[$version])) { |
|
904 | - $_isPHP[$version] = version_compare(PHP_VERSION, $version, '>='); |
|
905 | - } |
|
903 | + if (! isset($_isPHP[$version])) { |
|
904 | + $_isPHP[$version] = version_compare(PHP_VERSION, $version, '>='); |
|
905 | + } |
|
906 | 906 | |
907 | - return $_isPHP[$version]; |
|
908 | - } |
|
907 | + return $_isPHP[$version]; |
|
908 | + } |
|
909 | 909 | } |
910 | 910 |
@@ -90,13 +90,13 @@ discard block |
||
90 | 90 | |
91 | 91 | $this->deniedRegexList = [ |
92 | 92 | 'javascript\s*:', |
93 | - '\bon\w+=\S+(?=.*>)', // Inline JavaScript. |
|
93 | + '\bon\w+=\S+(?=.*>)', // Inline JavaScript. |
|
94 | 94 | '(document|(document\.)?window)\.(location|on\w*)', |
95 | 95 | 'expression\s*(\(|&\#40;)', // CSS and IE |
96 | - 'vbscript\s*:', // IE, surprise! |
|
97 | - 'wscript\s*:', // IE |
|
98 | - 'jscript\s*:', // IE |
|
99 | - 'vbs\s*:', // IE |
|
96 | + 'vbscript\s*:', // IE, surprise! |
|
97 | + 'wscript\s*:', // IE |
|
98 | + 'jscript\s*:', // IE |
|
99 | + 'vbs\s*:', // IE |
|
100 | 100 | 'Redirect\s+30\d:', |
101 | 101 | "([\"'])?data\s*:[^\\1]*?base64[^\\1]*?,[^\\1]*?\\1?", |
102 | 102 | ]; |
@@ -223,9 +223,9 @@ discard block |
||
223 | 223 | */ |
224 | 224 | $words = [ |
225 | 225 | 'javascript', 'expression', 'vbscript', 'jscript', 'wscript', |
226 | - 'vbs', 'script', 'base64', 'applet', 'alert', |
|
227 | - 'document', 'write', 'cookie', 'window', 'confirm', |
|
228 | - 'prompt', 'eval', |
|
226 | + 'vbs', 'script', 'base64', 'applet', 'alert', |
|
227 | + 'document', 'write', 'cookie', 'window', 'confirm', |
|
228 | + 'prompt', 'eval', |
|
229 | 229 | ]; |
230 | 230 | |
231 | 231 | foreach ($words as $word) { |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | ); |
281 | 281 | } |
282 | 282 | |
283 | - } while($original !== $str); |
|
283 | + } while ($original !== $str); |
|
284 | 284 | |
285 | 285 | unset($original); |
286 | 286 | |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | $originExif = @exif_read_data($imageAbsPath); |
394 | 394 | $filteredExif = []; |
395 | 395 | |
396 | - if (! empty($originExif)) { |
|
396 | + if (!empty($originExif)) { |
|
397 | 397 | $filteredExif = $this->clean($originExif, true); |
398 | 398 | } |
399 | 399 | |
@@ -620,21 +620,21 @@ discard block |
||
620 | 620 | "'", '"', '&', '$', '#', |
621 | 621 | '{', '}', '[', ']', '=', |
622 | 622 | ';', '?', '%20', '%22', |
623 | - '%3c', // < |
|
624 | - '%253c', // < |
|
625 | - '%3e', // > |
|
626 | - '%0e', // > |
|
627 | - '%28', // ( |
|
628 | - '%29', // ) |
|
629 | - '%2528', // ( |
|
630 | - '%26', // & |
|
631 | - '%24', // $ |
|
632 | - '%3f', // ? |
|
633 | - '%3b', // ; |
|
623 | + '%3c', // < |
|
624 | + '%253c', // < |
|
625 | + '%3e', // > |
|
626 | + '%0e', // > |
|
627 | + '%28', // ( |
|
628 | + '%29', // ) |
|
629 | + '%2528', // ( |
|
630 | + '%26', // & |
|
631 | + '%24', // $ |
|
632 | + '%3f', // ? |
|
633 | + '%3b', // ; |
|
634 | 634 | '%3d' // = |
635 | 635 | ]; |
636 | 636 | |
637 | - if (! $relativePath) { |
|
637 | + if (!$relativePath) { |
|
638 | 638 | $bad[] = './'; |
639 | 639 | $bad[] = '/'; |
640 | 640 | } |
@@ -676,19 +676,19 @@ discard block |
||
676 | 676 | protected function sanitizeNaughtyHtml(array $matches): string |
677 | 677 | { |
678 | 678 | static $naughtyTags = [ |
679 | - 'alert', 'prompt', 'confirm', 'applet', 'audio', |
|
680 | - 'basefont', 'base', 'behavior', 'bgsound', 'blink', |
|
681 | - 'body', 'embed', 'expression', 'form', 'frameset', |
|
682 | - 'frame', 'head', 'html', 'ilayer', 'iframe', |
|
683 | - 'input', 'button', 'select', 'isindex', 'layer', |
|
684 | - 'link', 'meta', 'keygen', 'object', 'plaintext', |
|
685 | - 'style', 'script', 'textarea', 'title', 'math', |
|
686 | - 'video', 'svg', 'xml', 'xss', |
|
679 | + 'alert', 'prompt', 'confirm', 'applet', 'audio', |
|
680 | + 'basefont', 'base', 'behavior', 'bgsound', 'blink', |
|
681 | + 'body', 'embed', 'expression', 'form', 'frameset', |
|
682 | + 'frame', 'head', 'html', 'ilayer', 'iframe', |
|
683 | + 'input', 'button', 'select', 'isindex', 'layer', |
|
684 | + 'link', 'meta', 'keygen', 'object', 'plaintext', |
|
685 | + 'style', 'script', 'textarea', 'title', 'math', |
|
686 | + 'video', 'svg', 'xml', 'xss', |
|
687 | 687 | ]; |
688 | 688 | |
689 | 689 | static $evilAttributes = [ |
690 | - 'on\w+', 'style', 'xmlns', 'seekSegmentTime', |
|
691 | - 'form', 'xlink:href', 'FSCommand', 'formaction', |
|
690 | + 'on\w+', 'style', 'xmlns', 'seekSegmentTime', |
|
691 | + 'form', 'xlink:href', 'FSCommand', 'formaction', |
|
692 | 692 | ]; |
693 | 693 | |
694 | 694 | // First, escape unclosed tags |
@@ -721,7 +721,7 @@ discard block |
||
721 | 721 | // of numerous XSS issues we've had. |
722 | 722 | $matches['attributes'] = preg_replace('#^[^a-z]+#i', '', $matches['attributes']); |
723 | 723 | |
724 | - if (! preg_match($attributesPattern, $matches['attributes'], $attribute, PREG_OFFSET_CAPTURE)) { |
|
724 | + if (!preg_match($attributesPattern, $matches['attributes'], $attribute, PREG_OFFSET_CAPTURE)) { |
|
725 | 725 | // No (valid) attribute found? Discard everything else inside the tag |
726 | 726 | break; |
727 | 727 | } |
@@ -745,7 +745,7 @@ discard block |
||
745 | 745 | |
746 | 746 | $attributes = empty($attributes) |
747 | 747 | ? '' |
748 | - : ' '.implode(' ', $attributes); |
|
748 | + : ' ' . implode(' ', $attributes); |
|
749 | 749 | return '<' . $matches['slash'] . $matches['tagName'] . $attributes . '>'; |
750 | 750 | } |
751 | 751 | |
@@ -900,7 +900,7 @@ discard block |
||
900 | 900 | |
901 | 901 | $version = (string) $version; |
902 | 902 | |
903 | - if (! isset($_isPHP[$version])) { |
|
903 | + if (!isset($_isPHP[$version])) { |
|
904 | 904 | $_isPHP[$version] = version_compare(PHP_VERSION, $version, '>='); |
905 | 905 | } |
906 | 906 |
@@ -19,9 +19,9 @@ |
||
19 | 19 | use function time; |
20 | 20 | use function uniqid; |
21 | 21 | |
22 | - /** |
|
23 | - * Cross Site Request Forgery protection. |
|
24 | - */ |
|
22 | + /** |
|
23 | + * Cross Site Request Forgery protection. |
|
24 | + */ |
|
25 | 25 | class Csrf |
26 | 26 | { |
27 | 27 | /** |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @var string |
31 | 31 | */ |
32 | - protected $hash = ''; |
|
32 | + protected $hash = ''; |
|
33 | 33 | |
34 | 34 | /** |
35 | 35 | * Token name. |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | // Let's start checking process. |
80 | 80 | |
81 | 81 | // Do the tokens exist in both the _POST and _SESSION? |
82 | - if (! isset($_POST[$this->name], $_SESSION[$this->name])) { |
|
82 | + if (!isset($_POST[$this->name], $_SESSION[$this->name])) { |
|
83 | 83 | return false; |
84 | 84 | } |
85 | 85 |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | { |
53 | 53 | $this->channel = $channel; |
54 | 54 | |
55 | - if (! empty($this->channel)) { |
|
55 | + if (!empty($this->channel)) { |
|
56 | 56 | $this->tableFilterLogs = $this->channel . ':shieldon_filter_logs'; |
57 | 57 | $this->tableRuleList = $this->channel . ':shieldon_rule_list'; |
58 | 58 | $this->tableSessions = $this->channel . ':shieldon_sessions'; |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | */ |
70 | 70 | protected function doInitialize(bool $dbCheck = true): void |
71 | 71 | { |
72 | - if (! $this->isInitialized) { |
|
73 | - if (! empty($this->channel)) { |
|
72 | + if (!$this->isInitialized) { |
|
73 | + if (!empty($this->channel)) { |
|
74 | 74 | $this->setChannel($this->channel); |
75 | 75 | } |
76 | 76 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | |
94 | 94 | $keys = $this->redis->keys($this->getNamespace($type) . ':*'); |
95 | 95 | |
96 | - foreach($keys as $key) { |
|
96 | + foreach ($keys as $key) { |
|
97 | 97 | $content = $this->redis->get($key); |
98 | 98 | $content = json_decode($content, true); |
99 | 99 | |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | { |
121 | 121 | $results = []; |
122 | 122 | |
123 | - if (! $this->checkExist($ip, $type)) { |
|
123 | + if (!$this->checkExist($ip, $type)) { |
|
124 | 124 | return $results; |
125 | 125 | } |
126 | 126 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $content = $this->redis->get($this->getKeyName($ip, $type)); |
140 | 140 | $resultData = json_decode($content, true); |
141 | 141 | |
142 | - if (! empty($resultData['log_data'])) { |
|
142 | + if (!empty($resultData['log_data'])) { |
|
143 | 143 | $results = $resultData['log_data']; |
144 | 144 | } |
145 | 145 | } |
@@ -220,8 +220,8 @@ discard block |
||
220 | 220 | foreach (['rule', 'filter_log', 'session'] as $type) { |
221 | 221 | $keys = $this->redis->keys($this->getNamespace($type) . ':*'); |
222 | 222 | |
223 | - if (! empty($keys)) { |
|
224 | - foreach($keys as $key) { |
|
223 | + if (!empty($keys)) { |
|
224 | + foreach ($keys as $key) { |
|
225 | 225 | $this->redis->del($key); |
226 | 226 | } |
227 | 227 | } |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | private function getKeyName(string $ip, string $type = 'filter_log'): string |
241 | 241 | { |
242 | 242 | switch ($type) { |
243 | - case 'filter_log' : return $this->tableFilterLogs . ':' . $ip; |
|
243 | + case 'filter_log' : return $this->tableFilterLogs . ':' . $ip; |
|
244 | 244 | case 'session': return $this->tableSessions . ':' . $ip; |
245 | 245 | case 'rule' : return $this->tableRuleList . ':' . $ip; |
246 | 246 | } |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | */ |
77 | 77 | protected function doInitialize(bool $dbCheck = true): void |
78 | 78 | { |
79 | - if (! $this->isInitialized) { |
|
80 | - if (! empty($this->channel)) { |
|
79 | + if (!$this->isInitialized) { |
|
80 | + if (!empty($this->channel)) { |
|
81 | 81 | $this->setChannel($this->channel); |
82 | 82 | } |
83 | 83 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | $it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS); |
108 | 108 | $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); |
109 | 109 | |
110 | - foreach($files as $file) { |
|
110 | + foreach ($files as $file) { |
|
111 | 111 | if ($file->isFile()) { |
112 | 112 | |
113 | 113 | $content = json_decode(file_get_contents($file->getPath() . '/' . $file->getFilename()), true); |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | { |
140 | 140 | $results = []; |
141 | 141 | |
142 | - if (! file_exists($this->getFilename($ip, $type))) { |
|
142 | + if (!file_exists($this->getFilename($ip, $type))) { |
|
143 | 143 | return $results; |
144 | 144 | } |
145 | 145 | |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | $fileContent = file_get_contents($this->getFilename($ip, $type)); |
160 | 160 | $resultData = json_decode($fileContent, true); |
161 | 161 | |
162 | - if (! empty($resultData['log_data'])) { |
|
162 | + if (!empty($resultData['log_data'])) { |
|
163 | 163 | $results = $resultData['log_data']; |
164 | 164 | } |
165 | 165 | break; |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | $it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS); |
244 | 244 | $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); |
245 | 245 | |
246 | - foreach($files as $file) { |
|
246 | + foreach ($files as $file) { |
|
247 | 247 | if ($file->isDir()) { |
248 | 248 | // @codeCoverageIgnoreStart |
249 | 249 | rmdir($file->getRealPath()); |
@@ -268,9 +268,9 @@ discard block |
||
268 | 268 | |
269 | 269 | // Check if are Shieldon directories removed or not. |
270 | 270 | $result = ( |
271 | - ! is_dir($this->getDirectory('filter_log')) && |
|
272 | - ! is_dir($this->getDirectory('rule')) && |
|
273 | - ! is_dir($this->getDirectory('session')) |
|
271 | + !is_dir($this->getDirectory('filter_log')) && |
|
272 | + !is_dir($this->getDirectory('rule')) && |
|
273 | + !is_dir($this->getDirectory('session')) |
|
274 | 274 | ); |
275 | 275 | |
276 | 276 | $this->createDirectory(); |
@@ -289,18 +289,18 @@ discard block |
||
289 | 289 | |
290 | 290 | $checkingFile = $this->directory . '/' . $this->channel . '_' . $this->checkPoint; |
291 | 291 | |
292 | - if (! file_exists($checkingFile)) { |
|
292 | + if (!file_exists($checkingFile)) { |
|
293 | 293 | $originalUmask = umask(0); |
294 | 294 | |
295 | - if (! is_dir($this->getDirectory('filter_log'))) { |
|
295 | + if (!is_dir($this->getDirectory('filter_log'))) { |
|
296 | 296 | $resultA = @mkdir($this->getDirectory('filter_log'), 0777, true); |
297 | 297 | } |
298 | 298 | |
299 | - if (! is_dir($this->getDirectory('rule'))) { |
|
299 | + if (!is_dir($this->getDirectory('rule'))) { |
|
300 | 300 | $resultB = @mkdir($this->getDirectory('rule'), 0777, true); |
301 | 301 | } |
302 | 302 | |
303 | - if (! is_dir($this->getDirectory('session'))) { |
|
303 | + if (!is_dir($this->getDirectory('session'))) { |
|
304 | 304 | $resultC = @mkdir($this->getDirectory('session'), 0777, true); |
305 | 305 | } |
306 | 306 | |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | */ |
325 | 325 | protected function checkDirectory(): bool |
326 | 326 | { |
327 | - if (! is_dir($this->directory) || ! is_writable($this->directory)) { |
|
327 | + if (!is_dir($this->directory) || !is_writable($this->directory)) { |
|
328 | 328 | throw new RuntimeException('The directory defined by File Driver must be writable. (' . $this->directory . ')'); |
329 | 329 | } |
330 | 330 | |
@@ -358,8 +358,8 @@ discard block |
||
358 | 358 | |
359 | 359 | switch ($type) { |
360 | 360 | case 'filter_log' : return $this->directory . '/' . $this->tableFilterLogs . '/' . $ip . '.' . $this->extension; |
361 | - case 'session' : return $this->directory . '/' . $this->tableSessions . '/' . $ip . '.' . $this->extension; |
|
362 | - case 'rule' : return $this->directory . '/' . $this->tableRuleList . '/' . $ip . '.' . $this->extension; |
|
361 | + case 'session' : return $this->directory . '/' . $this->tableSessions . '/' . $ip . '.' . $this->extension; |
|
362 | + case 'rule' : return $this->directory . '/' . $this->tableRuleList . '/' . $ip . '.' . $this->extension; |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | return ''; |
@@ -61,7 +61,7 @@ |
||
61 | 61 | { |
62 | 62 | $this->channel = $channel; |
63 | 63 | |
64 | - if (! empty($this->channel)) { |
|
64 | + if (!empty($this->channel)) { |
|
65 | 65 | $this->tableFilterLogs = $this->channel . '_shieldon_filter_logs'; |
66 | 66 | $this->tableRuleList = $this->channel . '_shieldon_rule_list'; |
67 | 67 | $this->tableSessions = $this->channel . '_shieldon_sessions'; |
@@ -146,7 +146,7 @@ |
||
146 | 146 | return $results; |
147 | 147 | } |
148 | 148 | |
149 | - /** |
|
149 | + /** |
|
150 | 150 | * {@inheritDoc} |
151 | 151 | */ |
152 | 152 | protected function doFetchAll(string $type = 'filter_log'): array |
@@ -60,12 +60,12 @@ discard block |
||
60 | 60 | */ |
61 | 61 | protected function doInitialize(bool $dbCheck = true): void |
62 | 62 | { |
63 | - if (! $this->isInitialized) { |
|
64 | - if (! empty($this->channel)) { |
|
63 | + if (!$this->isInitialized) { |
|
64 | + if (!empty($this->channel)) { |
|
65 | 65 | $this->setChannel($this->channel); |
66 | 66 | } |
67 | 67 | |
68 | - if ($dbCheck && ! $this->checkTableExists()) { |
|
68 | + if ($dbCheck && !$this->checkTableExists()) { |
|
69 | 69 | $this->installSql(); |
70 | 70 | } |
71 | 71 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | $resultData = $query->fetch($this->db::FETCH_ASSOC); |
94 | 94 | |
95 | 95 | // No data found. |
96 | - if (is_bool($resultData) && ! $resultData) { |
|
96 | + if (is_bool($resultData) && !$resultData) { |
|
97 | 97 | $resultData = []; |
98 | 98 | } |
99 | 99 | |
@@ -113,11 +113,11 @@ discard block |
||
113 | 113 | $resultData = $query->fetch($this->db::FETCH_ASSOC); |
114 | 114 | |
115 | 115 | // No data found. |
116 | - if (is_bool($resultData) && ! $resultData) { |
|
116 | + if (is_bool($resultData) && !$resultData) { |
|
117 | 117 | $resultData = []; |
118 | 118 | } |
119 | 119 | |
120 | - if (! empty($resultData['log_data'])) { |
|
120 | + if (!empty($resultData['log_data'])) { |
|
121 | 121 | $results = json_decode($resultData['log_data'], true); |
122 | 122 | } |
123 | 123 | break; |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | $resultData = $query->fetch($this->db::FETCH_ASSOC); |
134 | 134 | |
135 | 135 | // No data found. |
136 | - if (is_bool($resultData) && ! $resultData) { |
|
136 | + if (is_bool($resultData) && !$resultData) { |
|
137 | 137 | $resultData = []; |
138 | 138 | } |
139 | 139 | |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | $query->execute(); |
229 | 229 | $result = $query->fetch(); |
230 | 230 | |
231 | - if (! empty($result[$field])) { |
|
231 | + if (!empty($result[$field])) { |
|
232 | 232 | return true; |
233 | 233 | } |
234 | 234 | |
@@ -277,9 +277,9 @@ discard block |
||
277 | 277 | protected function doDelete(string $ip, string $type = 'filter_log'): bool |
278 | 278 | { |
279 | 279 | switch ($type) { |
280 | - case 'rule' : return $this->remove($this->tableRuleList, ['log_ip' => $ip]); |
|
280 | + case 'rule' : return $this->remove($this->tableRuleList, ['log_ip' => $ip]); |
|
281 | 281 | case 'filter_log': return $this->remove($this->tableFilterLogs, ['log_ip' => $ip]); |
282 | - case 'session' : return $this->remove($this->tableSessions, ['id' => $ip]); |
|
282 | + case 'session' : return $this->remove($this->tableSessions, ['id' => $ip]); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | return false; |
@@ -305,14 +305,14 @@ discard block |
||
305 | 305 | private function update(string $table, array $data, array $where) |
306 | 306 | { |
307 | 307 | $placeholder = []; |
308 | - foreach($data as $k => $v) { |
|
308 | + foreach ($data as $k => $v) { |
|
309 | 309 | $placeholder[] = "$k = :$k"; |
310 | 310 | } |
311 | 311 | |
312 | 312 | $dataPlaceholder = implode(', ', $placeholder); |
313 | 313 | |
314 | 314 | $placeholder = []; |
315 | - foreach($where as $k => $v) { |
|
315 | + foreach ($where as $k => $v) { |
|
316 | 316 | $placeholder[] = "$k = :$k"; |
317 | 317 | } |
318 | 318 | |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | |
325 | 325 | $bind = array_merge($data, $where); |
326 | 326 | |
327 | - foreach($bind as $k => $v) { |
|
327 | + foreach ($bind as $k => $v) { |
|
328 | 328 | |
329 | 329 | // @codeCoverageIgnoreStart |
330 | 330 | |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | |
353 | 353 | // @codeCoverageIgnoreStart |
354 | 354 | |
355 | - } catch(Exception $e) { |
|
355 | + } catch (Exception $e) { |
|
356 | 356 | throw $e->getMessage(); |
357 | 357 | return false; |
358 | 358 | } |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | { |
373 | 373 | $placeholderField = []; |
374 | 374 | $placeholderValue = []; |
375 | - foreach($data as $k => $v) { |
|
375 | + foreach ($data as $k => $v) { |
|
376 | 376 | $placeholderField[] = "`$k`"; |
377 | 377 | $placeholderValue[] = ":$k"; |
378 | 378 | } |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | $sql = 'INSERT INTO ' . $table . ' (' . $dataPlaceholderField . ') VALUES (' . $dataPlaceholderValue . ')'; |
385 | 385 | $query = $this->db->prepare($sql); |
386 | 386 | |
387 | - foreach($data as $k => $v) { |
|
387 | + foreach ($data as $k => $v) { |
|
388 | 388 | |
389 | 389 | // @codeCoverageIgnoreStart |
390 | 390 | |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | |
413 | 413 | // @codeCoverageIgnoreStart |
414 | 414 | |
415 | - } catch(Exception $e) { |
|
415 | + } catch (Exception $e) { |
|
416 | 416 | return false; |
417 | 417 | } |
418 | 418 | |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | { |
432 | 432 | |
433 | 433 | $placeholder = []; |
434 | - foreach($where as $k => $v) { |
|
434 | + foreach ($where as $k => $v) { |
|
435 | 435 | $placeholder[] = "`$k` = :$k"; |
436 | 436 | } |
437 | 437 | |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | $sql = 'DELETE FROM ' . $table . ' WHERE ' . $dataPlaceholder; |
443 | 443 | $query = $this->db->prepare($sql); |
444 | 444 | |
445 | - foreach($where as $k => $v) { |
|
445 | + foreach ($where as $k => $v) { |
|
446 | 446 | |
447 | 447 | // @codeCoverageIgnoreStart |
448 | 448 | |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | |
466 | 466 | // @codeCoverageIgnoreStart |
467 | 467 | |
468 | - } catch(Exception $e) { |
|
468 | + } catch (Exception $e) { |
|
469 | 469 | return false; |
470 | 470 | } |
471 | 471 |
@@ -27,11 +27,11 @@ |
||
27 | 27 | parent::__construct($pdo, $debug); |
28 | 28 | } |
29 | 29 | |
30 | - /** |
|
31 | - * Create SQL tables that Shieldon needs. |
|
32 | - * |
|
33 | - * @return bool |
|
34 | - */ |
|
30 | + /** |
|
31 | + * Create SQL tables that Shieldon needs. |
|
32 | + * |
|
33 | + * @return bool |
|
34 | + */ |
|
35 | 35 | protected function installSql(): bool |
36 | 36 | { |
37 | 37 | try { |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function setIp(string $ip = '', $queryRdns = false): void |
47 | 47 | { |
48 | - if (! empty($ip)) { |
|
48 | + if (!empty($ip)) { |
|
49 | 49 | $_SERVER['REMOTE_ADDR'] = $ip; |
50 | 50 | } |
51 | 51 | |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | |
56 | 56 | // Check if your IP is from localhost, perhaps your are in development environment? |
57 | 57 | if ( |
58 | - (substr($this->ip, 0 , 8) === '192.168.') || |
|
59 | - (substr($this->ip, 0 , 6) === '127.0.') |
|
58 | + (substr($this->ip, 0, 8) === '192.168.') || |
|
59 | + (substr($this->ip, 0, 6) === '127.0.') |
|
60 | 60 | ) { |
61 | 61 | $this->setRdns('localhost'); |
62 | 62 | } else { |
@@ -89,12 +89,12 @@ discard block |
||
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
92 | - if (! is_array($this->properties['colors'])) { |
|
92 | + if (!is_array($this->properties['colors'])) { |
|
93 | 93 | $this->properties['colors'] = $defaults['colors']; |
94 | 94 | } |
95 | 95 | |
96 | 96 | foreach ($defaults['colors'] as $k => $v) { |
97 | - if (! is_array($this->properties['colors'][$k])) { |
|
97 | + if (!is_array($this->properties['colors'][$k])) { |
|
98 | 98 | $this->properties['colors'][$k] = $defaults['colors'][$k]; |
99 | 99 | } |
100 | 100 | } |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | public function form(): string |
132 | 132 | { |
133 | 133 | // @codeCoverageIgnoreStart |
134 | - if (! extension_loaded('gd')) { |
|
134 | + if (!extension_loaded('gd')) { |
|
135 | 135 | return ''; |
136 | 136 | } |
137 | 137 | // @codeCoverageIgnoreEnd |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $html = ''; |
140 | 140 | $base64image = $this->createCaptcha(); |
141 | 141 | |
142 | - if (! empty($base64image)) { |
|
142 | + if (!empty($base64image)) { |
|
143 | 143 | $html = '<div style="padding: 0px; overflow: hidden; margin: 10px 0;">'; |
144 | 144 | $html .= '<div style=" |
145 | 145 | border: 1px #dddddd solid; |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | imagefilledrectangle($im, 0, 0, $this->properties['img_width'], $this->properties['img_height'], $colors['background']); |
209 | 209 | |
210 | 210 | // Create the spiral pattern. |
211 | - $theta = 1; |
|
211 | + $theta = 1; |
|
212 | 212 | $thetac = 7; |
213 | 213 | $radius = 16; |
214 | 214 | $circles = 20; |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | $y = 0; |
238 | 238 | |
239 | 239 | for ($i = 0; $i < $length; $i++) { |
240 | - $y = mt_rand(0 , $this->properties['img_height'] / 2); |
|
240 | + $y = mt_rand(0, $this->properties['img_height'] / 2); |
|
241 | 241 | imagestring($im, 5, $x, $y, $this->word[$i], $colors['text']); |
242 | 242 | $x += ($this->properties['font_spacing'] * 2); |
243 | 243 | } |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | imagerectangle($im, 0, 0, $this->properties['img_width'] - 1, $this->properties['img_height'] - 1, $colors['border']); |
247 | 247 | |
248 | 248 | // Generate image in base64 string. |
249 | - ob_start (); |
|
249 | + ob_start(); |
|
250 | 250 | |
251 | 251 | if (function_exists('imagejpeg')) { |
252 | 252 | $this->imageType = 'jpeg'; |