server-logs.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. session_start();
  3. require_once "../env.inc.php";
  4. require_once "../access.inc.php";
  5. require_once "../conf.inc.php";
  6. require_once DIR_PHP_LAYOUTS . "header.php";
  7. require_once DIR_PHP_LAYOUTS . "cms.session.php";
  8. if (!is_readable(SERVER_LOGS)) {
  9. echo "Le fichier n'est pas accessible en lecture.";
  10. exit();
  11. }
  12. $lines = file(SERVER_LOGS);
  13. $search = strtolower($_GET['search'] ?? '');
  14. if ($search) {
  15. $lines = array_filter($lines, fn($line) => stripos($line, $search) !== false);
  16. }
  17. ?>
  18. <!DOCTYPE html>
  19. <html lang="fr">
  20. <head>
  21. <meta charset="UTF-8">
  22. <title>Visualiseur de logs</title>
  23. <style>
  24. body { font-family: monospace; background: #f4f4f4; padding: 20px; }
  25. .error { color: red; }
  26. .warning { color: orange; }
  27. .notice { color: blue; }
  28. pre { background: #fff; padding: 10px; border: 1px solid #ccc; overflow-x: auto; }
  29. </style>
  30. <script>
  31. setInterval(() => {
  32. location.reload();
  33. }, 5000);
  34. </script>
  35. </head>
  36. <body>
  37. <form method="get">
  38. <label for="search">Filtrer par mot-clé :</label>
  39. <input type="text" name="search" value="<?= htmlspecialchars($search) ?>">
  40. <button type="submit">Filtrer</button>
  41. </form>
  42. <hr>
  43. <pre>
  44. <?php foreach (array_slice($lines, -50) as $line) {
  45. if(stripos($line, DOCUMENT_ROOT) !== false OR stripos($line, "/var/www/") === false){
  46. if (stripos($line, 'error') !== false) {
  47. echo '<div class="error">' . $line . '</div>';
  48. } elseif (stripos($line, 'warn') !== false) {
  49. echo '<div class="warning">' . $line . '</div>';
  50. } elseif (stripos($line, 'notice') !== false) {
  51. echo '<div class="notice">' . $line . '</div>';
  52. }
  53. }
  54. } ?>
  55. </pre>
  56. </body>
  57. </html>