server-logs.php 2.1 KB

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