Browse Source

Fix bugs and factoring

stany.ferer 3 months ago
parent
commit
4e614d549e

+ 2 - 2
core/class/access.class.php

@@ -28,7 +28,7 @@ class access
         return in_array($_string, WHITE_ACCESS);
     }
 
-    public static function getAccessList(int $_idType = NULL)
+    public static function getAccessList(?int $_idType = NULL)
     {
         ($_idType == NULL) ? $idType = session::getType() : $idType = $_idType;
         $return["access"] = $return["noAccess"] = $return["exception"] = array();
@@ -178,7 +178,7 @@ class access
         return in_array($_exception, $accessList["exception"]) ? TRUE : FALSE;
     }
 
-    public static function ifAccesss(string $_accessAsk, int $_idType = NULL)
+    public static function ifAccesss(string $_accessAsk, ?int $_idType = NULL)
     {
         if (session::isConnect() == FALSE and self::checkAccessOffLine($_accessAsk)) {
             return TRUE;

+ 1 - 1
core/class/debug.class.php

@@ -156,7 +156,7 @@ class debug
         return $return;
     }
 
-    public static function print_r(array $_array, int $_exit = NULL)
+    public static function print_r(array $_array, ?int $_exit = NULL)
     {
         echo "<div>".debug::getTraces() . "</div>";
         echo "<pre>";

+ 5 - 3
core/class/get.class.php

@@ -4,9 +4,11 @@ class get
 {
     public static function environnement()
     {
-        if ($_SERVER['HTTP_HOST'] == DOMAIN_CMS) {
+        if(!isset($_SERVER['HTTP_HOST'])){
             return "cms.";
-        } elseif ($_SERVER['HTTP_HOST'] == DOMAIN_EVENTS or $_SERVER['HTTP_HOST'] == DOMAIN_CONTROL) {
+        } elseif ($_SERVER['HTTP_HOST'] == DOMAIN_CMS) {
+            return "cms.";
+        } elseif ($_SERVER['HTTP_HOST'] == DOMAIN_EVENTS OR $_SERVER['HTTP_HOST'] == DOMAIN_CONTROL) {
             return "events.";
         }
     }
@@ -19,7 +21,7 @@ class get
         return (core::ifGet("p") == FALSE AND in_array(self::getDefautPage(), $_menu)) ? TRUE : FALSE;
     }
 
-    public static function page(string $_page = NULL)
+    public static function page(?string $_page = NULL)
     {
         if (isset($_page)) {
             $page = $_page;

+ 5 - 9
core/class/serverLog.class.php

@@ -5,23 +5,19 @@ class serverLog {
     public static function printLog(string $_log){
         if (stripos($_log, 'error') !== false) {
             echo '<div class="error">' . $_log . '</div>';
-        } elseif (stripos($_log, 'warn') !== false) {
+        } 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>' . $_log . '</div>';
+            echo '<div class="grey">' . $_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);
-        } 
+        self::printLog($_log);
     }
 
     private static function ifFolderWww(string $_log){

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

@@ -1,6 +1,15 @@
 
 <form method="get" action="/server-logs.php" target="iframeLogs">
-    <label for="search">Filtrer par mot-clé :</label>
+    <div class="input-group mb-3">
+        <select class="form-control" name="limit">
+            <option value="50">Limiter aux 50 derniers logs</option>
+            <option value="100">Limiter aux 100 derniers logs</option>
+            <option value="200">Limiter aux 200 derniers logs</option>
+            <option value="300">Limiter aux 300 derniers logs</option>
+            <option value="400">Limiter aux 400 derniers logs</option>
+            <option value="500">Limiter aux 500 derniers logs</option>
+        </select>
+    </div>
     <div class="input-group mb-3">
         <input type="text" class="form-control" name="search" value="" placeholder="Mot clé à filtrer">
         <div class="input-group-append">

+ 7 - 4
public-cms/server-logs.php

@@ -16,6 +16,7 @@ if (!is_readable(SERVER_LOGS)) {
 
 $lines = file(SERVER_LOGS);
 $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);
@@ -31,10 +32,12 @@ $lines = array_reverse($lines);
     <meta charset="UTF-8">
     <title>Visualiseur de logs</title>
     <style>
-        body { font-family: monospace; background: #f4f4f4; padding: 20px; }
-        .error { color: red; }
+        body { font-family: monospace; background: black !important; padding: 20px; }
+        div { font-size: 0.8em; }
+        .error { color: salmon; }
         .warning { color: orange; }
-        .notice { color: blue; }
+        .notice { color: white; }
+        .grey { color: grey; }
         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") ?>">
@@ -42,7 +45,7 @@ $lines = array_reverse($lines);
 </head>
 <body>
 <?php
-    foreach (array_slice($lines, 0, 100) as $line) {
+    foreach (array_slice($lines, 0, $limit) as $line) {
         serverLog::filtreLog($line);
     }
 ?>