stany.ferer 3 mesi fa
parent
commit
ac1ca4b5f1
2 ha cambiato i file con 39 aggiunte e 1 eliminazioni
  1. 3 0
      .gitignore
  2. 36 1
      core/class/serverLog.class.php

+ 3 - 0
.gitignore

@@ -8,3 +8,6 @@ core/views/pages/cms.test.php
 .active-debug-email
 .active-debug-sql
 env.inc.php
+
+.codegpt
+blacklist/ip_attempts.log

+ 36 - 1
core/class/serverLog.class.php

@@ -3,7 +3,9 @@
 class serverLog {
 
     public static function printLog(string $_log){
-        if (stripos($_log, 'error') !== false) {
+        if (serverLog::startsWithIpDate($_log)) {
+            self::printLogAttempts($_log);
+        } elseif (stripos($_log, 'error') !== false) {
             echo '<div class="error">' . $_log . '</div>';
         } elseif (stripos($_log, 'fatal') !== false) {
             echo '<div class="error">' . $_log . '</div>';
@@ -22,6 +24,39 @@ class serverLog {
         self::printLog($log);
     }
 
+    private static function startsWithIpDate(string $str): bool {
+        return preg_match(
+            '/^\d{1,3}(\.\d{1,3}){3},\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},/',
+            $str
+        ) === 1;
+    }
+
+    public static function printLogAttempts(string $_log){
+        if (self::startsWithIpDate($_log)) {
+            $parts = explode(',', $_log, 4);
+            if (count($parts) === 4) {
+                echo '<div class="notice">'
+                    . '<span style="color:#4FC3F7;">' . htmlspecialchars($parts[0]) . '</span>, '
+                    . '<span style="color:#81C784;">' . htmlspecialchars($parts[1]) . '</span>, '
+                    . '<span style="color:#FFD54F;">' . htmlspecialchars($parts[2]) . '</span>, '
+                    . '<span style="color:#FF8A65;">' . htmlspecialchars($parts[3]) . '</span>'
+                    . '</div>';
+                return;
+            }
+        }
+        elseif (stripos($_log, 'error') !== false) {
+            echo '<div class="error">' . $_log . '</div>';
+        } elseif (stripos($_log, 'fatal') !== false) {
+            echo '<div class="error">' . $_log . '</div>';
+        } elseif (stripos($_log, 'warn') !== false OR stripos($_log, 'alert') !== false) {
+            echo '<div class="warning">' . $_log . '</div>';
+        } elseif (stripos($_log, 'notice') !== false) {
+            echo '<div class="notice">' . $_log . '</div>';
+        } else {
+            echo '<div class="grey">' . $_log . '</div>';
+        }
+    }
+
     private static function ifFolderWww(string $_log){
         return (stripos($_log, DOCUMENT_ROOT) !== false) ? TRUE : FALSE;
     }