Selaa lähdekoodia

Factorisation log Server

stany.ferer 3 kuukautta sitten
vanhempi
commit
e3ca9ac67a

+ 39 - 0
core/class/serverLog.class.php

@@ -0,0 +1,39 @@
+<?php 
+
+class serverLog {
+
+    public static function printLog(string $_log){
+        if (stripos($_log, 'error') !== false) {
+            echo '<div class="error">' . $_log . '</div>';
+        } elseif (stripos($_log, 'warn') !== false) {
+            echo '<div class="warning">' . $_log . '</div>';
+        } elseif (stripos($_log, 'notice') !== false) {
+            echo '<div class="notice">' . $_log . '</div>';
+        } else {
+            echo '<div>' . $_log . '</div>';
+        }
+    }
+
+    public static function filtreLog(string $_log){
+        if(self::ifFolderWww($_log)){
+            self::printLog($_log);
+        } elseif(self::ifFolderDomain($_log)){
+            self::printLog($_log);
+        } elseif(self::ifGeneral($_log)){
+            self::printLog($_log);
+        } 
+    }
+
+    private static function ifFolderWww(string $_log){
+        return (stripos($_log, DOCUMENT_ROOT) !== false) ? TRUE : FALSE;
+    }
+
+    private static function ifFolderDomain(string $_log){
+        return (stripos($_log, DOMAIN_CMS) !== false) ? TRUE : FALSE;
+    }
+
+    private static function ifGeneral(string $_log){
+        return (stripos($_log, "/var/www/") == FALSE AND stripos($_log, "https://") == FALSE) ? TRUE : FALSE;
+    }
+
+}

+ 0 - 1
core/class/user.class.php

@@ -187,7 +187,6 @@ class user {
         if (isset($connect["id"])) {
             if ($connect["status"] == "success") {
                 $_SESSION["user"] = array(
-                    "apiSession" => $connect["session_id"],
                     "id" => $connect["id"],
                     "prenom" => $connect["prenom"],
                     "nom" => $connect["nom"],

+ 14 - 1
core/views/pages/cms.parametres-server-logs.php

@@ -1,8 +1,21 @@
+
+<form method="get" action="/server-logs.php" target="iframeLogs">
+    <label for="search">Filtrer par mot-clé :</label>
+    <div class="input-group mb-3">
+        <input type="text" class="form-control" name="search" value="">
+        <div class="input-group-append">
+            <button class="btn btn-outline-primary" style="border-top-left-radius: 0; border-bottom-left-radius: 0;" type="submit">Filtrer les logs par un mot clé</button>
+        </div>
+    </div>
+</form>
+
+<hr>
+
 <table class="table table-bordered">
 <tbody>
     <tr>
         <td scope="row">
-            <iframe width="100%" style="height:100vh;" src="/server-logs.php"></iframe>
+            <iframe width="100%" style="height:100vh;" src="/server-logs.php" name="iframeLogs"></iframe>
         </td>
     </tr>
     </tbody>

+ 3 - 27
public-cms/server-logs.php

@@ -23,18 +23,6 @@ if ($search) {
 
 $lines = array_reverse($lines);
 
-function printLog(string $_log){
-    if (stripos($_log, 'error') !== false) {
-        echo '<div class="error">' . $_log . '</div>';
-    } elseif (stripos($_log, 'warn') !== false) {
-        echo '<div class="warning">' . $_log . '</div>';
-    } elseif (stripos($_log, 'notice') !== false) {
-        echo '<div class="notice">' . $_log . '</div>';
-    } else {
-        echo '<div>' . $_log . '</div>';
-    }
-}
-
 ?>
 
 <!DOCTYPE html>
@@ -49,6 +37,8 @@ function printLog(string $_log){
         .notice { color: blue; }
         pre { background: #fff; padding: 10px; border: 1px solid #ccc; overflow-x: auto; }
     </style>
+    <link rel="stylesheet" href="<?php cache::printFileWithTime("libs/bootstrap/assets/dist/css/bootstrap.min.css") ?>">
+    <script src="<?php cache::printFileWithTime("libs/bootstrap/js/bootstrap.min.js") ?>"></script>
     <script>
         setInterval(() => {
             location.reload();
@@ -56,24 +46,10 @@ function printLog(string $_log){
     </script>
 </head>
 <body>
-    <form method="get">
-        <label for="search">Filtrer par mot-clé :</label>
-        <input type="text" name="search" value="<?= htmlspecialchars($search) ?>">
-        <button type="submit">Filtrer</button>
-    </form>
-    <hr>
-    <pre>
 <?php
     foreach (array_slice($lines, 0, 100) as $line) {
-        if(stripos($line, DOCUMENT_ROOT) !== false){
-            printLog($line);
-        } elseif(stripos($line, DOMAIN_CMS) !== false){
-            printLog($line);
-        } elseif(stripos($line, "/var/www/") == false AND stripos($line, "https://") == false){
-            printLog($line);
-        } 
+        serverLog::filtreLog($line);
     }
 ?>
-    </pre>
 </body>
 </html>