server-logs.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. function printLog(string $_log){
  18. if (stripos($_log, 'error') !== false) {
  19. echo '<div class="error">' . $_log . '</div>';
  20. } elseif (stripos($_log, 'warn') !== false) {
  21. echo '<div class="warning">' . $_log . '</div>';
  22. } elseif (stripos($_log, 'notice') !== false) {
  23. echo '<div class="notice">' . $_log . '</div>';
  24. }
  25. }
  26. ?>
  27. <!DOCTYPE html>
  28. <html lang="fr">
  29. <head>
  30. <meta charset="UTF-8">
  31. <title>Visualiseur de logs</title>
  32. <style>
  33. body { font-family: monospace; background: #f4f4f4; padding: 20px; }
  34. .error { color: red; }
  35. .warning { color: orange; }
  36. .notice { color: blue; }
  37. pre { background: #fff; padding: 10px; border: 1px solid #ccc; overflow-x: auto; }
  38. </style>
  39. <script>
  40. setInterval(() => {
  41. location.reload();
  42. }, 5000);
  43. </script>
  44. </head>
  45. <body>
  46. <form method="get">
  47. <label for="search">Filtrer par mot-clé :</label>
  48. <input type="text" name="search" value="<?= htmlspecialchars($search) ?>">
  49. <button type="submit">Filtrer</button>
  50. </form>
  51. <hr>
  52. <pre>
  53. <?php foreach (array_slice($lines, -50) as $line) {
  54. if(stripos($line, DOCUMENT_ROOT) !== false){
  55. printLog($line);
  56. } elseif(stripos($line, DOMAIN_CMS) !== false){
  57. printLog($line);
  58. } elseif(stripos($line, "/var/www/") === false AND stripos($line, "https://") === false){
  59. printLog($line);
  60. }
  61. } ?>
  62. </pre>
  63. </body>
  64. </html>