| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?php
- class serverLog {
- public static function printLog(string $_log){
- if (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>';
- }
- }
- public static function filtreLog(string $_log){
- $log = self::hidePassword($_log);
- $log = self::hideEmail($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;
- }
- private static function hidePassword($input) {
- return preg_replace("/('password'\s*=>\s*)'[^']*'/", "$1'##PASSWORD##'", $input);
- }
- private static function hideEmail($input) {
- 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>';
- }
- }
|