@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | * |
| 389 | 389 | * @return void |
| 390 | 390 | */ |
| 391 | - public function __construct(array $properties = [], string $sessionId = '') |
|
| 391 | + public function __construct(array $properties = [], string $sessionId = '') |
|
| 392 | 392 | { |
| 393 | 393 | // Set to container. |
| 394 | 394 | Container::set('shieldon', $this); |
@@ -400,7 +400,7 @@ discard block |
||
| 400 | 400 | // At least load a captcha instance. Foundation is the base one. |
| 401 | 401 | $this->setCaptcha(new \Shieldon\Captcha\Foundation()); |
| 402 | 402 | |
| 403 | - if (! empty($properties)) { |
|
| 403 | + if (!empty($properties)) { |
|
| 404 | 404 | $this->setProperties($properties); |
| 405 | 405 | } |
| 406 | 406 | |
@@ -449,7 +449,7 @@ discard block |
||
| 449 | 449 | |
| 450 | 450 | $logData['first_time_flag'] = $ipDetail['first_time_flag']; |
| 451 | 451 | |
| 452 | - if (! empty($ipDetail['ip'])) { |
|
| 452 | + if (!empty($ipDetail['ip'])) { |
|
| 453 | 453 | $logData['ip'] = $this->ip; |
| 454 | 454 | $logData['session'] = $this->sessionId; |
| 455 | 455 | $logData['hostname'] = $this->ipResolvedHostname; |
@@ -509,7 +509,7 @@ discard block |
||
| 509 | 509 | if ($this->enableCookieCheck) { |
| 510 | 510 | |
| 511 | 511 | // Get values from data table. We will count it and save it back to data table. |
| 512 | - $logData['flag_js_cookie'] = $ipDetail['flag_js_cookie'] ?? 0; |
|
| 512 | + $logData['flag_js_cookie'] = $ipDetail['flag_js_cookie'] ?? 0; |
|
| 513 | 513 | $logData['pageviews_cookie'] = $ipDetail['pageviews_cookie'] ?? 0; |
| 514 | 514 | |
| 515 | 515 | $c = $this->properties['cookie_name']; |
@@ -517,7 +517,7 @@ discard block |
||
| 517 | 517 | $jsCookie = $_COOKIE[$c] ?? 0; |
| 518 | 518 | |
| 519 | 519 | // Checking if a cookie is created by JavaScript. |
| 520 | - if (! empty($jsCookie)) { |
|
| 520 | + if (!empty($jsCookie)) { |
|
| 521 | 521 | |
| 522 | 522 | if ($jsCookie == '1') { |
| 523 | 523 | $logData['pageviews_cookie']++; |
@@ -559,9 +559,9 @@ discard block |
||
| 559 | 559 | |
| 560 | 560 | foreach (array_keys($this->properties['time_unit_quota']) as $timeUnit) { |
| 561 | 561 | switch ($timeUnit) { |
| 562 | - case 's': $timeSecond = 1; break; |
|
| 563 | - case 'm': $timeSecond = 60; break; |
|
| 564 | - case 'h': $timeSecond = 3600; break; |
|
| 562 | + case 's': $timeSecond = 1; break; |
|
| 563 | + case 'm': $timeSecond = 60; break; |
|
| 564 | + case 'h': $timeSecond = 3600; break; |
|
| 565 | 565 | case 'd': $timeSecond = 86400; break; |
| 566 | 566 | } |
| 567 | 567 | if (($now - $ipDetail["first_time_{$timeUnit}"]) >= ($timeSecond + 1)) { |
@@ -601,11 +601,11 @@ discard block |
||
| 601 | 601 | |
| 602 | 602 | // Is fagged as unusual beavior? Count the first time. |
| 603 | 603 | if ($isFlaggedAsUnusualBehavior) { |
| 604 | - $logData['first_time_flag'] = (! empty($logData['first_time_flag'])) ? $logData['first_time_flag'] : $now; |
|
| 604 | + $logData['first_time_flag'] = (!empty($logData['first_time_flag'])) ? $logData['first_time_flag'] : $now; |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | // Reset the flagged factor check. |
| 608 | - if (! empty($ipDetail['first_time_flag'])) { |
|
| 608 | + if (!empty($ipDetail['first_time_flag'])) { |
|
| 609 | 609 | if ($now - $ipDetail['first_time_flag'] >= $this->properties['time_reset_limit']) { |
| 610 | 610 | $logData['flag_multi_session'] = 0; |
| 611 | 611 | $logData['flag_empty_referer'] = 0; |
@@ -736,7 +736,7 @@ discard block |
||
| 736 | 736 | $currentSessionOrder = 0; |
| 737 | 737 | |
| 738 | 738 | //die('<pre>' . var_dump($onlineSessions) . '</pre>'); |
| 739 | - if (! empty($onlineSessions)) { |
|
| 739 | + if (!empty($onlineSessions)) { |
|
| 740 | 740 | foreach ($onlineSessions as $k => $v) { |
| 741 | 741 | $sessionPools[] = $v['id']; |
| 742 | 742 | $lasttime = (int) $v['time']; |
@@ -764,7 +764,7 @@ discard block |
||
| 764 | 764 | $this->currentSessionOrder = $currentSessionOrder; |
| 765 | 765 | $this->currentWaitNumber = $currentSessionOrder - $limit; |
| 766 | 766 | |
| 767 | - if (! in_array($this->sessionId, $sessionPools)) { |
|
| 767 | + if (!in_array($this->sessionId, $sessionPools)) { |
|
| 768 | 768 | $this->sessionCount++; |
| 769 | 769 | |
| 770 | 770 | // New session, record this data. |
@@ -807,7 +807,7 @@ discard block |
||
| 807 | 807 | if (session_status() === PHP_SESSION_NONE) { |
| 808 | 808 | session_start(); |
| 809 | 809 | } |
| 810 | - if (! $this->sessionId) { |
|
| 810 | + if (!$this->sessionId) { |
|
| 811 | 811 | $this->sessionId = session_id(); |
| 812 | 812 | } |
| 813 | 813 | } |
@@ -908,7 +908,7 @@ discard block |
||
| 908 | 908 | */ |
| 909 | 909 | public function setChannel(string $channel): self |
| 910 | 910 | { |
| 911 | - if (! $this->driver instanceof DriverProvider) { |
|
| 911 | + if (!$this->driver instanceof DriverProvider) { |
|
| 912 | 912 | throw new LogicException('setChannel method requires setDriver set first.'); |
| 913 | 913 | } else { |
| 914 | 914 | $this->driver->setChannel($channel); |
@@ -945,12 +945,12 @@ discard block |
||
| 945 | 945 | public function captchaResponse(): bool |
| 946 | 946 | { |
| 947 | 947 | foreach ($this->captcha as $captcha) { |
| 948 | - if (! $captcha->response()) { |
|
| 948 | + if (!$captcha->response()) { |
|
| 949 | 949 | return false; |
| 950 | 950 | } |
| 951 | 951 | } |
| 952 | 952 | |
| 953 | - if (! empty($this->isLimitSession)) { |
|
| 953 | + if (!empty($this->isLimitSession)) { |
|
| 954 | 954 | $this->result = $this->sessionHandler(self::RESPONSE_ALLOW); |
| 955 | 955 | } |
| 956 | 956 | |
@@ -973,7 +973,7 @@ discard block |
||
| 973 | 973 | |
| 974 | 974 | |
| 975 | 975 | $class = substr($class, strrpos($class, '\\') + 1); |
| 976 | - $this->component[$class] =& $instance; |
|
| 976 | + $this->component[$class] = & $instance; |
|
| 977 | 977 | |
| 978 | 978 | } |
| 979 | 979 | |
@@ -1175,7 +1175,7 @@ discard block |
||
| 1175 | 1175 | |
| 1176 | 1176 | if (file_exists($viewPath)) { |
| 1177 | 1177 | |
| 1178 | - if (! defined('SHIELDON_VIEW')) { |
|
| 1178 | + if (!defined('SHIELDON_VIEW')) { |
|
| 1179 | 1179 | define('SHIELDON_VIEW', true); |
| 1180 | 1180 | } |
| 1181 | 1181 | |
@@ -1251,7 +1251,7 @@ discard block |
||
| 1251 | 1251 | public function run(): int |
| 1252 | 1252 | { |
| 1253 | 1253 | // Ignore the excluded urls. |
| 1254 | - if (! empty($this->excludedUrls)) { |
|
| 1254 | + if (!empty($this->excludedUrls)) { |
|
| 1255 | 1255 | foreach ($this->excludedUrls as $url) { |
| 1256 | 1256 | if (0 === strpos($this->currentUrl, $url)) { |
| 1257 | 1257 | return $this->result = self::RESPONSE_ALLOW; |
@@ -1342,7 +1342,7 @@ discard block |
||
| 1342 | 1342 | |
| 1343 | 1343 | $ipRule = $this->driver->get($this->ip, 'rule'); |
| 1344 | 1344 | |
| 1345 | - if (! empty($ipRule)) { |
|
| 1345 | + if (!empty($ipRule)) { |
|
| 1346 | 1346 | |
| 1347 | 1347 | $ruleType = (int) $ipRule['type']; |
| 1348 | 1348 | |
@@ -1563,7 +1563,7 @@ discard block |
||
| 1563 | 1563 | |
| 1564 | 1564 | $result = $this->getComponent('Ip')->check(); |
| 1565 | 1565 | |
| 1566 | - if (! empty($result)) { |
|
| 1566 | + if (!empty($result)) { |
|
| 1567 | 1567 | |
| 1568 | 1568 | switch ($result['status']) { |
| 1569 | 1569 | |
@@ -1701,7 +1701,7 @@ discard block |
||
| 1701 | 1701 | */ |
| 1702 | 1702 | public function getSessionId(): string |
| 1703 | 1703 | { |
| 1704 | - if (! empty($this->sessionId)) { |
|
| 1704 | + if (!empty($this->sessionId)) { |
|
| 1705 | 1705 | return $this->sessionId; |
| 1706 | 1706 | } |
| 1707 | 1707 | |
@@ -577,10 +577,18 @@ |
||
| 577 | 577 | // He or she will get banned. |
| 578 | 578 | if ($logData["pageviews_{$timeUnit}"] > $this->properties['time_unit_quota'][$timeUnit]) { |
| 579 | 579 | |
| 580 | - if ($timeUnit === 's') $this->action(self::ACTION_TEMPORARILY_DENY, self::REASON_REACHED_LIMIT_SECOND); |
|
| 581 | - if ($timeUnit === 'm') $this->action(self::ACTION_TEMPORARILY_DENY, self::REASON_REACHED_LIMIT_MINUTE); |
|
| 582 | - if ($timeUnit === 'h') $this->action(self::ACTION_TEMPORARILY_DENY, self::REASON_REACHED_LIMIT_HOUR); |
|
| 583 | - if ($timeUnit === 'd') $this->action(self::ACTION_TEMPORARILY_DENY, self::REASON_REACHED_LIMIT_DAY); |
|
| 580 | + if ($timeUnit === 's') { |
|
| 581 | + $this->action(self::ACTION_TEMPORARILY_DENY, self::REASON_REACHED_LIMIT_SECOND); |
|
| 582 | + } |
|
| 583 | + if ($timeUnit === 'm') { |
|
| 584 | + $this->action(self::ACTION_TEMPORARILY_DENY, self::REASON_REACHED_LIMIT_MINUTE); |
|
| 585 | + } |
|
| 586 | + if ($timeUnit === 'h') { |
|
| 587 | + $this->action(self::ACTION_TEMPORARILY_DENY, self::REASON_REACHED_LIMIT_HOUR); |
|
| 588 | + } |
|
| 589 | + if ($timeUnit === 'd') { |
|
| 590 | + $this->action(self::ACTION_TEMPORARILY_DENY, self::REASON_REACHED_LIMIT_DAY); |
|
| 591 | + } |
|
| 584 | 592 | |
| 585 | 593 | return self::RESPONSE_TEMPORARILY_DENY; |
| 586 | 594 | } |
@@ -33,8 +33,8 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | public function send(string $message): bool |
| 35 | 35 | { |
| 36 | - if (! empty($message)) { |
|
| 37 | - echo "\n" . $this->provider() . "\n";; |
|
| 36 | + if (!empty($message)) { |
|
| 37 | + echo "\n" . $this->provider() . "\n"; ; |
|
| 38 | 38 | echo "\n--- BEGIN - Mock of sending message ---\n\n"; |
| 39 | 39 | echo $message; |
| 40 | 40 | echo "\n--- END - Mock of sending message ---\n"; |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | // If we don't get the string from the localization file, use placeholder instead. |
| 75 | 75 | $resultString = $placeholder; |
| 76 | 76 | |
| 77 | - if (! empty($i18n[$filename][$langcode])) { |
|
| 77 | + if (!empty($i18n[$filename][$langcode])) { |
|
| 78 | 78 | $resultString = $i18n[$filename][$langcode]; |
| 79 | 79 | } |
| 80 | 80 | |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | $masked = implode('.', $tmp); |
| 128 | 128 | |
| 129 | 129 | } else { |
| 130 | - $masked = str_repeat('*', strlen($str) - 6) . substr(str, -6); |
|
| 130 | + $masked = str_repeat('*', strlen($str) - 6) . substr(str, -6); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | return $masked; |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | $cpuLoads = @sys_getloadavg(); |
| 155 | 155 | $cpuCores = trim(@shell_exec("grep -P '^processor' /proc/cpuinfo|wc -l")); |
| 156 | 156 | |
| 157 | - if (! empty($cpuCores) && ! empty($cpuLoads)) { |
|
| 157 | + if (!empty($cpuCores) && !empty($cpuLoads)) { |
|
| 158 | 158 | $return = round($cpuLoads[1] / ($cpuCores + 1) * 100, 0) . '%'; |
| 159 | 159 | } |
| 160 | 160 | return $return; |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | |
| 180 | 180 | $freeResult = explode("\n", trim(@shell_exec('free'))); |
| 181 | 181 | |
| 182 | - if (! empty($freeResult)) { |
|
| 182 | + if (!empty($freeResult)) { |
|
| 183 | 183 | $parsed = preg_split("/[\s]+/", $freeResult[1]); |
| 184 | 184 | $return = round($parsed[2] / $parsed[1] * 100, 0) . '%'; |
| 185 | 185 | } |
@@ -119,7 +119,7 @@ |
||
| 119 | 119 | $keepCache = false; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - if (! $keepCache) { |
|
| 122 | + if (!$keepCache) { |
|
| 123 | 123 | $data = []; |
| 124 | 124 | } |
| 125 | 125 | // @codeCoverageIgnoreEnd |
@@ -94,14 +94,14 @@ discard block |
||
| 94 | 94 | */ |
| 95 | 95 | public function add(array $record): void |
| 96 | 96 | { |
| 97 | - if (! empty($record['session_id'])) { |
|
| 97 | + if (!empty($record['session_id'])) { |
|
| 98 | 98 | $record['session_id'] = substr($record['session_id'], 0, 4); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - $data[0] = $record['ip'] ?? 'null'; |
|
| 102 | - $data[1] = $record['session_id'] ?? 'null'; |
|
| 101 | + $data[0] = $record['ip'] ?? 'null'; |
|
| 102 | + $data[1] = $record['session_id'] ?? 'null'; |
|
| 103 | 103 | $data[2] = $record['action_code'] ?? 'null'; |
| 104 | - $data[3] = $record['timesamp'] ?? 'null'; |
|
| 104 | + $data[3] = $record['timesamp'] ?? 'null'; |
|
| 105 | 105 | |
| 106 | 106 | file_put_contents($this->filePath, implode(',', $data) . "\n", FILE_APPEND | LOCK_EX); |
| 107 | 107 | } |
@@ -131,14 +131,14 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | $logFile = fopen($this->filePath, 'r'); |
| 133 | 133 | |
| 134 | - while (! feof($logFile)) { |
|
| 134 | + while (!feof($logFile)) { |
|
| 135 | 135 | $line = fgets($logFile); |
| 136 | 136 | |
| 137 | - if (! empty($line)) { |
|
| 137 | + if (!empty($line)) { |
|
| 138 | 138 | $data = explode(',', trim($line)); |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - if (! empty($data[0])) { |
|
| 141 | + if (!empty($data[0])) { |
|
| 142 | 142 | $results[] = [ |
| 143 | 143 | 'ip' => $data[0], |
| 144 | 144 | 'session_id' => $data[1], |
@@ -173,14 +173,14 @@ discard block |
||
| 173 | 173 | |
| 174 | 174 | $logFile = fopen($thisDayLogFile, 'r'); |
| 175 | 175 | |
| 176 | - while (! feof($logFile)) { |
|
| 176 | + while (!feof($logFile)) { |
|
| 177 | 177 | $line = fgets($logFile); |
| 178 | 178 | |
| 179 | - if (! empty($line)) { |
|
| 179 | + if (!empty($line)) { |
|
| 180 | 180 | $data = explode(',', trim($line)); |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - if (! empty($data[0])) { |
|
| 183 | + if (!empty($data[0])) { |
|
| 184 | 184 | $results[] = [ |
| 185 | 185 | 'ip' => $data[0], |
| 186 | 186 | 'session_id' => $data[1], |
@@ -207,14 +207,14 @@ discard block |
||
| 207 | 207 | { |
| 208 | 208 | $result = true; |
| 209 | 209 | |
| 210 | - if (! is_dir($this->directory)) { |
|
| 210 | + if (!is_dir($this->directory)) { |
|
| 211 | 211 | $originalUmask = umask(0); |
| 212 | 212 | $result = @mkdir($this->directory, 0777, true); |
| 213 | 213 | umask($originalUmask); |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | // @codeCoverageIgnoreStart |
| 217 | - if (! is_writable($this->directory)) { |
|
| 217 | + if (!is_writable($this->directory)) { |
|
| 218 | 218 | throw new RuntimeException('The directory usded by ActionLogger must be writable. (' . $this->directory . ')'); |
| 219 | 219 | } |
| 220 | 220 | // @codeCoverageIgnoreEnd |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | $it = new RecursiveDirectoryIterator($this->directory, RecursiveDirectoryIterator::SKIP_DOTS); |
| 246 | 246 | $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); |
| 247 | 247 | |
| 248 | - foreach($files as $file) { |
|
| 248 | + foreach ($files as $file) { |
|
| 249 | 249 | if ($file->isDir()) { |
| 250 | 250 | // @codeCoverageIgnoreStart |
| 251 | 251 | rmdir($file->getRealPath()); |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | $it = new RecursiveDirectoryIterator($this->directory, RecursiveDirectoryIterator::SKIP_DOTS); |
| 276 | 276 | $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); |
| 277 | 277 | |
| 278 | - foreach($files as $file) { |
|
| 278 | + foreach ($files as $file) { |
|
| 279 | 279 | if ($file->isFile()) { |
| 280 | 280 | $key = $file->getBasename('.log'); |
| 281 | 281 | $size = $file->getSize(); |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | public function __construct(string $directory = '') |
| 89 | 89 | { |
| 90 | - if (! isset($this->logger)) { |
|
| 90 | + if (!isset($this->logger)) { |
|
| 91 | 91 | $this->logger = new Logger($directory); |
| 92 | 92 | } |
| 93 | 93 | |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | default: |
| 207 | 207 | |
| 208 | 208 | // We also accept querying N days data from logs. For example: `past_365_days`. |
| 209 | - if (preg_match('/past_([0-9]+)_days/', $this->type, $matches) ) { |
|
| 209 | + if (preg_match('/past_([0-9]+)_days/', $this->type, $matches)) { |
|
| 210 | 210 | |
| 211 | 211 | $dayCount = $matches[1]; |
| 212 | 212 | $startDate = date('Ymd', strtotime('-' . $dayCount . ' days')); |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | // Fetch data from log files. |
| 232 | 232 | $logs = $this->logger->get($startDate, $endDate); |
| 233 | 233 | |
| 234 | - foreach($logs as $log) { |
|
| 234 | + foreach ($logs as $log) { |
|
| 235 | 235 | |
| 236 | 236 | $logTimesamp = (int) $log['timesamp']; |
| 237 | 237 | $logIp = $log['ip']; |
@@ -252,12 +252,12 @@ discard block |
||
| 252 | 252 | |
| 253 | 253 | // Initialize all the counters. |
| 254 | 254 | foreach ($this->fields as $field) { |
| 255 | - if (! isset($this->periodDetail[$t][$k][$field])) { |
|
| 255 | + if (!isset($this->periodDetail[$t][$k][$field])) { |
|
| 256 | 256 | $this->periodDetail[$t][$k][$field] = 0; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | if ($logTimesamp >= $detailTimesampBegin && $logTimesamp < $detailTimesampEnd) { |
| 260 | - if (! isset($this->ipDetail[$t][$logIp][$field])) { |
|
| 260 | + if (!isset($this->ipDetail[$t][$logIp][$field])) { |
|
| 261 | 261 | $this->ipDetail[$t][$logIp][$field] = 0; |
| 262 | 262 | } |
| 263 | 263 | } |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | */ |
| 298 | 298 | public function getPeriodData() |
| 299 | 299 | { |
| 300 | - if (! empty($this->periodDetail[$this->type])) { |
|
| 300 | + if (!empty($this->periodDetail[$this->type])) { |
|
| 301 | 301 | return $this->periodDetail[$this->type]; |
| 302 | 302 | } |
| 303 | 303 | return []; |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | */ |
| 311 | 311 | public function getIpData() |
| 312 | 312 | { |
| 313 | - if (! empty($this->ipDetail[$this->type])) { |
|
| 313 | + if (!empty($this->ipDetail[$this->type])) { |
|
| 314 | 314 | return $this->ipDetail[$this->type]; |
| 315 | 315 | } |
| 316 | 316 | return []; |
@@ -329,25 +329,25 @@ discard block |
||
| 329 | 329 | return []; |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - $results['captcha_chart_string'] = ''; // string |
|
| 333 | - $results['pageview_chart_string'] = ''; // string |
|
| 334 | - $results['captcha_success_count'] = 0; // integer |
|
| 335 | - $results['captcha_failure_count'] = 0; // integer |
|
| 336 | - $results['captcha_count'] = 0; // integer |
|
| 337 | - $results['pageview_count'] = 0; // integer |
|
| 338 | - $results['captcha_percentageage'] = 0; // integer |
|
| 332 | + $results['captcha_chart_string'] = ''; // string |
|
| 333 | + $results['pageview_chart_string'] = ''; // string |
|
| 334 | + $results['captcha_success_count'] = 0; // integer |
|
| 335 | + $results['captcha_failure_count'] = 0; // integer |
|
| 336 | + $results['captcha_count'] = 0; // integer |
|
| 337 | + $results['pageview_count'] = 0; // integer |
|
| 338 | + $results['captcha_percentageage'] = 0; // integer |
|
| 339 | 339 | $results['captcha_failure_percentage'] = 0; // integer |
| 340 | 340 | $results['captcha_success_percentage'] = 0; // integer |
| 341 | 341 | |
| 342 | - $results['action_ban_count'] = 0; // integer |
|
| 343 | - $results['action_temp_ban_count'] = 0; // integer |
|
| 344 | - $results['action_unban_count'] = 0; // integer |
|
| 345 | - $results['blacklist_count'] = 0; // integer |
|
| 346 | - $results['session_limit_count'] = 0; // integer |
|
| 342 | + $results['action_ban_count'] = 0; // integer |
|
| 343 | + $results['action_temp_ban_count'] = 0; // integer |
|
| 344 | + $results['action_unban_count'] = 0; // integer |
|
| 345 | + $results['blacklist_count'] = 0; // integer |
|
| 346 | + $results['session_limit_count'] = 0; // integer |
|
| 347 | 347 | |
| 348 | 348 | $ipdData = $this->getIpData(); |
| 349 | 349 | |
| 350 | - if (! empty($ipdData)) { |
|
| 350 | + if (!empty($ipdData)) { |
|
| 351 | 351 | |
| 352 | 352 | foreach ($ipdData as $ipKey => $ipInfo) { |
| 353 | 353 | |
@@ -384,24 +384,24 @@ discard block |
||
| 384 | 384 | { |
| 385 | 385 | $periodData = $this->getPeriodData(); |
| 386 | 386 | |
| 387 | - $results['captcha_chart_string'] = ''; // string |
|
| 388 | - $results['pageview_chart_string'] = ''; // string |
|
| 389 | - $results['label_chart_string'] = ''; // string |
|
| 390 | - $results['captcha_success_count'] = 0; // integer |
|
| 391 | - $results['captcha_failure_count'] = 0; // integer |
|
| 392 | - $results['captcha_count'] = 0; // integer |
|
| 393 | - $results['pageview_count'] = 0; // integer |
|
| 394 | - $results['captcha_percentageage'] = 0; // integer |
|
| 387 | + $results['captcha_chart_string'] = ''; // string |
|
| 388 | + $results['pageview_chart_string'] = ''; // string |
|
| 389 | + $results['label_chart_string'] = ''; // string |
|
| 390 | + $results['captcha_success_count'] = 0; // integer |
|
| 391 | + $results['captcha_failure_count'] = 0; // integer |
|
| 392 | + $results['captcha_count'] = 0; // integer |
|
| 393 | + $results['pageview_count'] = 0; // integer |
|
| 394 | + $results['captcha_percentageage'] = 0; // integer |
|
| 395 | 395 | $results['captcha_failure_percentage'] = 0; // integer |
| 396 | 396 | $results['captcha_success_percentage'] = 0; // integer |
| 397 | 397 | |
| 398 | - $results['action_ban_count'] = 0; // integer |
|
| 399 | - $results['action_temp_ban_count'] = 0; // integer |
|
| 400 | - $results['action_unban_count'] = 0; // integer |
|
| 401 | - $results['blacklist_count'] = 0; // integer |
|
| 402 | - $results['session_limit_count'] = 0; // integer |
|
| 398 | + $results['action_ban_count'] = 0; // integer |
|
| 399 | + $results['action_temp_ban_count'] = 0; // integer |
|
| 400 | + $results['action_unban_count'] = 0; // integer |
|
| 401 | + $results['blacklist_count'] = 0; // integer |
|
| 402 | + $results['session_limit_count'] = 0; // integer |
|
| 403 | 403 | |
| 404 | - if (! empty($periodData)) { |
|
| 404 | + if (!empty($periodData)) { |
|
| 405 | 405 | |
| 406 | 406 | $chartCaptcha = []; |
| 407 | 407 | $chartPageview = []; |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | $results['captcha_chart_string'] = implode(',', $chartCaptcha); |
| 432 | - $results['pageview_chart_string']= implode(',', $chartPageview); |
|
| 432 | + $results['pageview_chart_string'] = implode(',', $chartPageview); |
|
| 433 | 433 | $results['captcha_success_chart_string'] = implode(',', $chartCaptchaSuccess); |
| 434 | 434 | $results['captcha_failure_chart_string'] = implode(',', $chartCaptchaFailure); |
| 435 | 435 | $results['label_chart_string'] = "'" . implode("','", $labels) . "'"; |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | $ip = $log['ip']; |
| 460 | 460 | $sessionId = $log['session_id']; |
| 461 | 461 | |
| 462 | - $this->ipDetail[$t][$ip]['session_id'][$sessionId ] = 1; |
|
| 462 | + $this->ipDetail[$t][$ip]['session_id'][$sessionId] = 1; |
|
| 463 | 463 | |
| 464 | 464 | if ($logActionCode === self::LOG_TEMPORARILY_BAN) { |
| 465 | 465 | $this->periodDetail[$t][$k]['action_temp_ban_count']++; |
@@ -10,11 +10,11 @@ |
||
| 10 | 10 | |
| 11 | 11 | namespace Shieldon\Security; |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * WWW-Authenticate |
|
| 15 | - * |
|
| 16 | - * @since 3.0.0 |
|
| 17 | - */ |
|
| 13 | + /** |
|
| 14 | + * WWW-Authenticate |
|
| 15 | + * |
|
| 16 | + * @since 3.0.0 |
|
| 17 | + */ |
|
| 18 | 18 | class httpAuthentication |
| 19 | 19 | { |
| 20 | 20 | /** |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function set(array $protectedUrlList = []): void |
| 76 | 76 | { |
| 77 | - if (! empty($protectedUrlList)) { |
|
| 77 | + if (!empty($protectedUrlList)) { |
|
| 78 | 78 | $this->protectedUrlList = $protectedUrlList; |
| 79 | 79 | } |
| 80 | 80 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | if (0 === strpos($this->currentUrl, $urlInfo['url'])) { |
| 96 | 96 | |
| 97 | 97 | // Prompt a window to ask for username and password. |
| 98 | - if (! isset($_SERVER['PHP_AUTH_USER']) || ! isset($_SERVER['PHP_AUTH_PW'])) { |
|
| 98 | + if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) { |
|
| 99 | 99 | header('WWW-Authenticate: Basic realm="' . $this->realm . '"'); |
| 100 | 100 | header('HTTP/1.0 401 Unauthorized'); |
| 101 | 101 | die('Permission required.'); |
@@ -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 | |