Explorar o código

Fefact ajax logs

stany.ferer hai 3 meses
pai
achega
ab18d9299c

+ 3 - 91
core/class/serverLog.class.php

@@ -91,13 +91,13 @@ class serverLog {
         return preg_replace("/('email'\s*=>\s*)'[^']*'/", "$1'##EMAIL##'", $input);
     }
 
-    public static function consoleApache(){
-        if (!is_readable(SERVER_LOGS_APACHE)) {
+    public static function consoleLog(string $_logFile){
+        if (!is_readable($_logFile)) {
             echo "Le fichier n'est pas accessible en lecture.";
             exit();
         }
 
-        $lines = file(SERVER_LOGS_APACHE);
+        $lines = file($_logFile);
         $search = strtolower($_GET['search'] ?? '');
         $limit = strtolower($_GET['limit'] ?? 50); // A défaut les 50 derniers logs
 
@@ -107,96 +107,8 @@ class serverLog {
 
         $lines = array_reverse($lines);
 
-        echo '<!DOCTYPE html>
-        <html lang="fr">
-        <head>
-            <meta charset="UTF-8">
-            <style>
-                body { font-family: monospace; background: black !important; padding: 20px; }
-                div { font-size: 0.8em; }
-                pre { background: #fff; padding: 10px; border: 1px solid #ccc; overflow-x: auto; }
-            </style>
-            <link rel="stylesheet" href="' . cache::getFileWithTime("libs/bootstrap/assets/dist/css/bootstrap.min.css") . '">
-            <script src="' . cache::getFileWithTime("libs/bootstrap/js/bootstrap.min.js") . '"></script>
-        </head>
-        <body>';
         foreach (array_slice($lines, 0, $limit) as $line) {
             serverLog::filtreLog($line);
         }
-        echo '</body>
-        </html>';
     }
-
-    public static function consoleAttempts(){ 
-        if (!is_readable(SERVER_LOGS_BLACKLIST . "ip_attempts.log")) {
-            echo "Le fichier n'est pas accessible en lecture.";
-            exit();
-        }
-
-        $lines = file(SERVER_LOGS_BLACKLIST . "ip_attempts.log");
-        $search = strtolower($_GET['search'] ?? '');
-        $limit = strtolower($_GET['limit'] ?? 50); // A défaut les 50 derniers logs
-
-        if ($search) {
-            $lines = array_filter($lines, fn($line) => stripos($line, $search) !== false);
-        }
-
-        $lines = array_reverse($lines);
-
-        echo '<!DOCTYPE html>
-        <html lang="fr">
-        <head>
-            <meta charset="UTF-8">
-            <style>
-                body { font-family: monospace; background: black !important; padding: 20px; }
-                div { font-size: 0.8em; }
-                pre { background: #fff; padding: 10px; border: 1px solid #ccc; overflow-x: auto; }
-            </style>
-            <link rel="stylesheet" href="' . cache::getFileWithTime("libs/bootstrap/assets/dist/css/bootstrap.min.css") . '">
-            <script src="' . cache::getFileWithTime("libs/bootstrap/js/bootstrap.min.js") . '"></script>
-        </head>
-        <body>';
-        foreach (array_slice($lines, 0, $limit) as $line) {
-            serverLog::filtreLog($line);
-        }
-        echo '</body>
-        </html>';
-    }
-
-    public static function consoleIpBlacklist(){
-        if (!is_readable(SERVER_LOGS_BLACKLIST . "ip.txt")) {
-            echo "Le fichier n'est pas accessible en lecture.";
-            exit();
-        }
-
-        $lines = file(SERVER_LOGS_BLACKLIST . "ip.txt");
-        $search = strtolower($_GET['search'] ?? '');
-        $limit = strtolower($_GET['limit'] ?? 50); // A défaut les 50 derniers logs
-
-        if ($search) {
-            $lines = array_filter($lines, fn($line) => stripos($line, $search) !== false);
-        }
-
-        $lines = array_reverse($lines);
-
-        echo '<!DOCTYPE html>
-        <html lang="fr">
-        <head>
-            <meta charset="UTF-8">
-            <style>
-                body { font-family: monospace; background: black !important; padding: 20px; }
-                div { font-size: 0.8em; }
-                pre { background: #fff; padding: 10px; border: 1px solid #ccc; overflow-x: auto; }
-            </style>
-            <link rel="stylesheet" href="' . cache::getFileWithTime("libs/bootstrap/assets/dist/css/bootstrap.min.css") . '">
-            <script src="' . cache::getFileWithTime("libs/bootstrap/js/bootstrap.min.js") . '"></script>
-        </head>
-        <body>';
-        foreach (array_slice($lines, 0, $limit) as $line) {
-            serverLog::filtreLog($line);
-        }
-        echo '</body>
-        </html>';
-    }
-
 }

+ 20 - 4
core/views/pages/cms.parametres-server-logs.php

@@ -1,4 +1,4 @@
-<form method="get" action="/console.logs.php" target="iframeLogs">
+<form id="logsForm" method="get" action="/console.logs.php">
     <input type="hidden" name="l" value="<?= $console ?>">
     <div class="input-group mb-3">
         <select class="form-control" name="limit">
@@ -23,9 +23,25 @@
 <table class="table table-bordered">
 <tbody>
     <tr>
-        <td scope="row">
-            <iframe width="100%" style="height:100vh;" src="/console.logs.php?l=<?= $console ?>" name="iframeLogs"></iframe>
+        <td scope="row" style="background:#222;">
+            <div id="logsResult" style="width:100%;height:100vh;overflow:auto;background:#222;color:#eee;padding:10px;"></div>
         </td>
     </tr>
     </tbody>
-</table>
+</table>
+
+<script>
+$(function() {
+    function loadLogs() {
+        $.get($("#logsForm").attr("action"), $("#logsForm").serialize(), function(data) {
+            $("#logsResult").html(data);
+        });
+    }
+    $("#logsForm").on("submit", function(e) {
+        e.preventDefault();
+        loadLogs();
+    });
+    // Chargement initial
+    loadLogs();
+});
+</script>

+ 3 - 3
public-cms/console.logs.php

@@ -13,13 +13,13 @@ switch (core::getGet("l")) {
         maj::start();
         break;
     case 'apache':
-        serverLog::consoleApache();
+        serverLog::consoleLog(SERVER_LOGS_APACHE);
         break;
     case 'attempts':
-        serverLog::consoleAttempts();
+        serverLog::consoleLog(SERVER_LOGS_BLACKLIST . "ip_attempts.log");
         break;
     case 'ip-blacklist':
-        serverLog::consoleIpBlacklist();
+        serverLog::consoleLog(SERVER_LOGS_BLACKLIST . "ip.txt");
         break;
     default:
         echo "...";