Explorar el Código

Isolation logs et accès logs blacklist

stany.ferer hace 3 meses
padre
commit
f8b660edc6

+ 12 - 1
conf.inc.php

@@ -112,4 +112,15 @@ define("TIME_TOAST_ALERT", 5000); // En millisecondes
 
 // Liens directs ProWeb
 define("PROWEB_DOSSIERS", "https://www.cse-invent.com/gestion/prestations/dossiers?pagesize=20&__d_id=%7BDefault%7D&d_date_dossier%5Boptions%5D=depuis_le&d_date_dossier%5Bfrom%5D=##DD-MM-YYYY##&etats_d=%7BDefault%7D&d_annul=Tous&d_rglt=Tous&f_mod_cat_libel_p=%7BDefault%7D&p_etat=3&f_o_name_bis=%7BDefault%7D&o_name_bis=%7BDefault%7D&mod_cat_libel_p=%7BDefault%7D&search=avance");
-define("PROWEB_SALARIES", "https://www.cse-invent.com/gestion/beneficiaire/od?pagesize=20&f_o_name_bis=%7BDefault%7D&soc_situation=Tous&soc_status=%7BDefault%7D&o_name_bis=%7BDefault%7D&search=avance");
+define("PROWEB_SALARIES", "https://www.cse-invent.com/gestion/beneficiaire/od?pagesize=20&f_o_name_bis=%7BDefault%7D&soc_situation=Tous&soc_status=%7BDefault%7D&o_name_bis=%7BDefault%7D&search=avance");
+
+define("SCRIPT_IMPORT", "https://www.cse-invent.com/gestion/test/util_import_auto_optim.php");
+define("SCRIPT_RAPPORT_IMPORT", "https://www.cse-invent.com/gestion/test/util_form_import_auto.php?type=historique");
+
+define("ALERT_AUTHENTICATOR", FALSE);
+define("WHITE_IP", [
+        "::1", // LocalHost
+        "127.0.0.1", // LocalHost
+    ]);
+
+define("SERVER_LOGS_BLACKLIST", DOCUMENT_ROOT . "blacklist/");

+ 3 - 0
core/class/icon.class.php

@@ -91,6 +91,9 @@ class icon
             case 'parametres-maj':
                 return "bi bi-git";
                 break;
+            case 'parametres-logs':
+                return "bi bi-list-columns-reverse";
+                break;
             default:
                 return $_type;
                 break;

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

@@ -42,4 +42,124 @@ class serverLog {
         return preg_replace("/('email'\s*=>\s*)'[^']*'/", "$1'##EMAIL##'", $input);
     }
 
+    public static function consoleApache(){
+        if (!is_readable(SERVER_LOGS_APACHE)) {
+            echo "Le fichier n'est pas accessible en lecture.";
+            exit();
+        }
+
+        $lines = file(SERVER_LOGS_APACHE);
+        $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; }
+                .error { color: salmon; }
+                .warning { color: orange; }
+                .notice { color: white; }
+                .grey { color: grey; }
+                pre { background: #fff; padding: 10px; border: 1px solid #ccc; overflow-x: auto; }
+            </style>
+            <link rel="stylesheet" href="' . cache::printFileWithTime("libs/bootstrap/assets/dist/css/bootstrap.min.css") . '">
+            <script src="' . cache::printFileWithTime("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(){ echo SERVER_LOGS_BLACKLIST . "/ip_attempts.log";
+        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; }
+                .error { color: salmon; }
+                .warning { color: orange; }
+                .notice { color: white; }
+                .grey { color: grey; }
+                pre { background: #fff; padding: 10px; border: 1px solid #ccc; overflow-x: auto; }
+            </style>
+            <link rel="stylesheet" href="' . cache::printFileWithTime("libs/bootstrap/assets/dist/css/bootstrap.min.css") . '">
+            <script src="' . cache::printFileWithTime("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; }
+                .error { color: salmon; }
+                .warning { color: orange; }
+                .notice { color: white; }
+                .grey { color: grey; }
+                pre { background: #fff; padding: 10px; border: 1px solid #ccc; overflow-x: auto; }
+            </style>
+            <link rel="stylesheet" href="' . cache::printFileWithTime("libs/bootstrap/assets/dist/css/bootstrap.min.css") . '">
+            <script src="' . cache::printFileWithTime("libs/bootstrap/js/bootstrap.min.js") . '"></script>
+        </head>
+        <body>';
+        foreach (array_slice($lines, 0, $limit) as $line) {
+            serverLog::filtreLog($line);
+        }
+        echo '</body>
+        </html>';
+    }
+
 }

+ 2 - 1
core/views/_cms.menu.php

@@ -89,9 +89,10 @@
                 core::elementMenu("parametres-comptes", "/parametres-comptes.html", "Admin : Comptes Bancaires");
                 core::elementMenu("parametres-clients", "/parametres-clients.html", "Admin : Clients");
                 core::elementMenu("parametres-tags", "/parametres-tags.html", "Admin : Tags");
-                core::elementMenu("parametres-historique", "/parametres-historique.html", "Admin : Historique");
                 core::elementMenu("parametres", "/parametres.html", "Admin : Paramètres");
                 core::elementMenu("parametres-maj", "/parametres-maj.html", "Admin : Mise à jour");
+                core::elementMenu("parametres-historique", "/parametres-historique.html", "Admin : Historique");
+                core::elementMenu("parametres-logs", "/parametres-logs.html", "Admin : Logs système");
             echo '</ul>';
             ?>
         </ul>

+ 89 - 0
core/views/pages/cms.parametres-logs.php

@@ -0,0 +1,89 @@
+<?php
+maj::bashFetch();
+$checkMaintenance = debug::isFile("maintenance");
+$checkDebug = debug::isFile("debug");
+?>
+
+<header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light ">
+    <h2 class="bd-title" id="content">
+        <span>Administration : Logs Système</span>
+    </h2>
+</header>
+<?php
+echo core::filAriane(array(
+    "current" => "Logs Système",
+    "arbo" => array(
+        "Administration" => NULL,
+        "Logs Système" => "/parametres-logs.html"
+    )
+));
+?>
+
+<ul class="nav nav-tabs" id="tab-logs" role="tablist" style="margin-bottom:20px;">
+    <li><a class="nav-link active" href="#parametres-server-logs-apache">Apache</a></li>
+    <li><a class="nav-link" href="#parametres-server-logs-balcklist-attempts">Historique des Tentatives</a></li>
+    <li><a class="nav-link" href="#parametres-server-logs-balcklist-ip">IP Blacklistées</a></li>
+</ul>
+
+<div class="tab-content">
+    <div id="parametres-server-logs-apache" class="tab-pane fade in active show">
+        <?php get::page("parametres-server-logs", ["console" => "apache"]) ?>
+    </div>
+    <div id="parametres-server-logs-balcklist-attempts" class="tab-pane fade">
+        <?php get::page("parametres-server-logs", ["console" => "attempts"]) ?>
+    </div>
+    <div id="parametres-server-logs-balcklist-ip" class="tab-pane fade">
+        <?php get::page("parametres-server-logs", ["console" => "ip-blacklist"]) ?>
+    </div>
+</div>
+
+
+<script>
+$(document).ready(function(){
+
+    var fragment = window.location.hash;
+    var tmpOnglet = fragment ? fragment.substring(1) : '';
+    var onglet = "#" + tmpOnglet;
+
+    if (tmpOnglet !== "" && $(onglet).length) {
+        $('#tab-logs a[href="' + onglet + '"]').tab('show');
+    }
+
+    $("#tab-logs a").click(function(){
+        $(this).tab('show');
+    });
+    $('#tab-logs a').on('shown.bs.tab', function(event){
+        var x = $(event.target).text();
+        var y = $(event.relatedTarget).text();
+    });
+});s
+</script>
+
+<style>
+    h4 {
+        margin-top: 15px;
+    }
+
+    .element-parametres {
+        margin-top: 5px;
+    }
+
+    .modal-body {
+        position: relative;
+        overflow-y: auto;
+        max-height: 400px;
+        padding: 15px;
+    }
+
+    .modal-dialog{
+        width: 1005px !important;
+    }
+
+    .modal {
+        --bs-modal-width: none;
+    }
+
+    .autoModal.modal .modal-body {
+        max-height: 100%;
+    }
+</style>

+ 1 - 1
core/views/pages/cms.parametres-maj-console.php

@@ -71,7 +71,7 @@
         $("#consoleContenaire").show();
         $("#startMaj").hide();
         $("#progressMaj").show();
-        $.get('/console.maj.php', function(data) {
+        $.get('/console.logs.php?i=maj', function(data) {
             $("#consoleMaj").append( data );
         });
     });

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

@@ -1,5 +1,5 @@
-
-<form method="get" action="/console.logs.apache.php" target="iframeLogs">
+<form method="get" action="/console.logs.php" target="iframeLogs">
+    <input type="hidden" name="l" value="<?= $console ?>">
     <div class="input-group mb-3">
         <select class="form-control" name="limit">
             <option value="50">Limiter aux 50 derniers logs</option>
@@ -24,7 +24,7 @@
 <tbody>
     <tr>
         <td scope="row">
-            <iframe width="100%" style="height:100vh;" src="/console.logs.apache.php" name="iframeLogs"></iframe>
+            <iframe width="100%" style="height:100vh;" src="/console.logs.php?l=<?= $console ?>" name="iframeLogs"></iframe>
         </td>
     </tr>
     </tbody>

+ 0 - 4
core/views/pages/cms.parametres.php

@@ -23,7 +23,6 @@ echo core::filAriane(array(
     <li><a class="nav-link active" href="#parametres-general">Général</a></li>
     <li><a class="nav-link" href="#parametres-restore">Backup & restauration</a></li>
     <li><a class="nav-link" href="#parametres-debug">Debug & développement</a></li>
-    <li><a class="nav-link" href="#parametres-server-logs">Logs Apache serveur</a></li>
 </ul>
 
 <div class="tab-content">
@@ -36,9 +35,6 @@ echo core::filAriane(array(
     <div id="parametres-debug" class="tab-pane fade">
         <?php get::page("parametres-debug") ?>
     </div>
-    <div id="parametres-server-logs" class="tab-pane fade">
-        <?php get::page("parametres-server-logs") ?>
-    </div>
 </div>
 
 

+ 1 - 1
env.inc.template.php

@@ -15,7 +15,7 @@
     define("DOMAIN_MEDIA", "");
     define("DOMAIN_API", "https://" . DOMAIN_CMS . "/api/");
 
-    define("SERVER_LOGS", "/Applications/MAMP/logs/apache_error.log");
+    define("SERVER_LOGS_APACHE", "/Applications/MAMP/logs/apache_error.log");
     define("DOCUMENT_ROOT", "/Users/stanyferer/Sites/cms.cse-invent.com/html/");
     define("DOCUMENT_DATAS", "/Users/stanyferer/Sites/cms.cse-invent.com/data/");
     define("MAJ", "dev");

+ 0 - 52
public-cms/console.logs.apache.php

@@ -1,52 +0,0 @@
-<?php
-
-session_start();
-
-require_once "../env.inc.php";
-require_once "../access.inc.php";
-require_once "../conf.inc.php";
-
-require_once DIR_PHP_LAYOUTS . "header.php";
-require_once DIR_PHP_LAYOUTS . "cms.session.php";
-
-if (!is_readable(SERVER_LOGS)) {
-    echo "Le fichier n'est pas accessible en lecture.";
-    exit();
-}
-
-$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);
-}
-
-$lines = array_reverse($lines);
-
-?>
-
-<!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; }
-        .error { color: salmon; }
-        .warning { color: orange; }
-        .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") ?>">
-    <script src="<?php cache::printFileWithTime("libs/bootstrap/js/bootstrap.min.js") ?>"></script>
-</head>
-<body>
-<?php
-    foreach (array_slice($lines, 0, $limit) as $line) {
-        serverLog::filtreLog($line);
-    }
-?>
-</body>
-</html>

+ 27 - 0
public-cms/console.logs.php

@@ -0,0 +1,27 @@
+<?php
+
+session_start();
+
+require_once "../env.inc.php";
+require_once "../access.inc.php";
+require_once "../conf.inc.php";
+require_once DIR_PHP_LAYOUTS . "header.php";
+require_once DIR_PHP_LAYOUTS . "cms.session.php";
+
+switch (core::getGet("l")) {
+    case 'maj':
+        maj::start();
+        break;
+    case 'apache':
+        serverLog::consoleApache();
+        break;
+    case 'attempts':
+        serverLog::consoleAttempts();
+        break;
+    case 'ip-blacklist':
+        serverLog::consoleIpBlacklist();
+        break;
+    default:
+        echo "...";
+        break;
+}

+ 0 - 11
public-cms/console.maj.php

@@ -1,11 +0,0 @@
-<?php
-
-session_start();
-
-require_once "../env.inc.php";
-require_once "../access.inc.php";
-require_once "../conf.inc.php";
-require_once DIR_PHP_LAYOUTS . "header.php";
-require_once DIR_PHP_LAYOUTS . "cms.session.php";
-
-maj::start();