2
0

serverLog.class.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. class serverLog {
  3. public static function printLog(string $_log){
  4. if (stripos($_log, 'error') !== false) {
  5. echo '<div class="error">' . $_log . '</div>';
  6. } elseif (stripos($_log, 'fatal') !== false) {
  7. echo '<div class="error">' . $_log . '</div>';
  8. } elseif (stripos($_log, 'warn') !== false OR stripos($_log, 'alert') !== false) {
  9. echo '<div class="warning">' . $_log . '</div>';
  10. } elseif (stripos($_log, 'notice') !== false) {
  11. echo '<div class="notice">' . $_log . '</div>';
  12. } else {
  13. echo '<div class="grey">' . $_log . '</div>';
  14. }
  15. }
  16. public static function filtreLog(string $_log){
  17. $log = self::hidePassword($_log);
  18. $log = self::hideEmail($log);
  19. self::printLog($log);
  20. }
  21. private static function ifFolderWww(string $_log){
  22. return (stripos($_log, DOCUMENT_ROOT) !== false) ? TRUE : FALSE;
  23. }
  24. private static function ifFolderDomain(string $_log){
  25. return (stripos($_log, DOMAIN_CMS) !== false) ? TRUE : FALSE;
  26. }
  27. private static function ifGeneral(string $_log){
  28. return (stripos($_log, "/var/www/") == FALSE AND stripos($_log, "https://") == FALSE) ? TRUE : FALSE;
  29. }
  30. private static function hidePassword($input) {
  31. return preg_replace("/('password'\s*=>\s*)'[^']*'/", "$1'##PASSWORD##'", $input);
  32. }
  33. private static function hideEmail($input) {
  34. return preg_replace("/('email'\s*=>\s*)'[^']*'/", "$1'##EMAIL##'", $input);
  35. }
  36. public static function consoleApache(){
  37. if (!is_readable(SERVER_LOGS_APACHE)) {
  38. echo "Le fichier n'est pas accessible en lecture.";
  39. exit();
  40. }
  41. $lines = file(SERVER_LOGS_APACHE);
  42. $search = strtolower($_GET['search'] ?? '');
  43. $limit = strtolower($_GET['limit'] ?? 50); // A défaut les 50 derniers logs
  44. if ($search) {
  45. $lines = array_filter($lines, fn($line) => stripos($line, $search) !== false);
  46. }
  47. $lines = array_reverse($lines);
  48. echo '<!DOCTYPE html>
  49. <html lang="fr">
  50. <head>
  51. <meta charset="UTF-8">
  52. <style>
  53. body { font-family: monospace; background: black !important; padding: 20px; }
  54. div { font-size: 0.8em; }
  55. .error { color: salmon; }
  56. .warning { color: orange; }
  57. .notice { color: white; }
  58. .grey { color: grey; }
  59. pre { background: #fff; padding: 10px; border: 1px solid #ccc; overflow-x: auto; }
  60. </style>
  61. <link rel="stylesheet" href="' . cache::printFileWithTime("libs/bootstrap/assets/dist/css/bootstrap.min.css") . '">
  62. <script src="' . cache::printFileWithTime("libs/bootstrap/js/bootstrap.min.js") . '"></script>
  63. </head>
  64. <body>';
  65. foreach (array_slice($lines, 0, $limit) as $line) {
  66. serverLog::filtreLog($line);
  67. }
  68. echo '</body>
  69. </html>';
  70. }
  71. public static function consoleAttempts(){ echo SERVER_LOGS_BLACKLIST . "/ip_attempts.log";
  72. if (!is_readable(SERVER_LOGS_BLACKLIST . "/ip_attempts.log")) {
  73. echo "Le fichier n'est pas accessible en lecture.";
  74. exit();
  75. }
  76. $lines = file(SERVER_LOGS_BLACKLIST . "/ip_attempts.log");
  77. $search = strtolower($_GET['search'] ?? '');
  78. $limit = strtolower($_GET['limit'] ?? 50); // A défaut les 50 derniers logs
  79. if ($search) {
  80. $lines = array_filter($lines, fn($line) => stripos($line, $search) !== false);
  81. }
  82. $lines = array_reverse($lines);
  83. echo '<!DOCTYPE html>
  84. <html lang="fr">
  85. <head>
  86. <meta charset="UTF-8">
  87. <style>
  88. body { font-family: monospace; background: black !important; padding: 20px; }
  89. div { font-size: 0.8em; }
  90. .error { color: salmon; }
  91. .warning { color: orange; }
  92. .notice { color: white; }
  93. .grey { color: grey; }
  94. pre { background: #fff; padding: 10px; border: 1px solid #ccc; overflow-x: auto; }
  95. </style>
  96. <link rel="stylesheet" href="' . cache::printFileWithTime("libs/bootstrap/assets/dist/css/bootstrap.min.css") . '">
  97. <script src="' . cache::printFileWithTime("libs/bootstrap/js/bootstrap.min.js") . '"></script>
  98. </head>
  99. <body>';
  100. foreach (array_slice($lines, 0, $limit) as $line) {
  101. serverLog::filtreLog($line);
  102. }
  103. echo '</body>
  104. </html>';
  105. }
  106. public static function consoleIpBlacklist(){
  107. if (!is_readable(SERVER_LOGS_BLACKLIST . "/ip.txt")) {
  108. echo "Le fichier n'est pas accessible en lecture.";
  109. exit();
  110. }
  111. $lines = file(SERVER_LOGS_BLACKLIST . "/ip.txt");
  112. $search = strtolower($_GET['search'] ?? '');
  113. $limit = strtolower($_GET['limit'] ?? 50); // A défaut les 50 derniers logs
  114. if ($search) {
  115. $lines = array_filter($lines, fn($line) => stripos($line, $search) !== false);
  116. }
  117. $lines = array_reverse($lines);
  118. echo '<!DOCTYPE html>
  119. <html lang="fr">
  120. <head>
  121. <meta charset="UTF-8">
  122. <style>
  123. body { font-family: monospace; background: black !important; padding: 20px; }
  124. div { font-size: 0.8em; }
  125. .error { color: salmon; }
  126. .warning { color: orange; }
  127. .notice { color: white; }
  128. .grey { color: grey; }
  129. pre { background: #fff; padding: 10px; border: 1px solid #ccc; overflow-x: auto; }
  130. </style>
  131. <link rel="stylesheet" href="' . cache::printFileWithTime("libs/bootstrap/assets/dist/css/bootstrap.min.css") . '">
  132. <script src="' . cache::printFileWithTime("libs/bootstrap/js/bootstrap.min.js") . '"></script>
  133. </head>
  134. <body>';
  135. foreach (array_slice($lines, 0, $limit) as $line) {
  136. serverLog::filtreLog($line);
  137. }
  138. echo '</body>
  139. </html>';
  140. }
  141. }