hrefs still * point at system.php?tab=… so navigation degrades gracefully. * * Response: text/html fragment (no // wrapper). * On any auth failure or bad request: 403 / 400 with a plain-text body. */ require_once __DIR__ . "/../../config/bootstrap.php"; require_once __DIR__ . '/../../src/AdminAuth.php'; if (!AdminAuth::isAuthenticated()) { http_response_code(403); header('Content-Type: text/plain; charset=utf-8'); echo 'Non autorisé'; exit; } // ── Validate inputs ──────────────────────────────────────────────────────── const LOG_FILES_FRAG = [ 'nginx_access' => ['label' => 'nginx — accès', 'path' => '/var/log/nginx/posterg_access.log'], 'nginx_error' => ['label' => 'nginx — erreurs', 'path' => '/var/log/nginx/posterg_error.log'], 'php_error' => ['label' => 'PHP-FPM — erreurs', 'path' => '/var/log/php8.4-fpm.log'], ]; const ALLOWED_LINES_FRAG = [50, 100, 200, 500]; $tab = $_GET['tab'] ?? 'nginx_access'; if ($tab !== 'nginx_config' && !array_key_exists($tab, LOG_FILES_FRAG)) { $tab = 'nginx_access'; } $n = isset($_GET['n']) ? (int)$_GET['n'] : 100; if (!in_array($n, ALLOWED_LINES_FRAG, true)) { $n = 100; } header('Content-Type: text/html; charset=utf-8'); header('X-Robots-Tag: noindex'); // ── Helpers (duplicated from system.php — small enough to inline) ────────── function frag_readLogTail(string $logPath, int $lines, ?string &$errorMsg): ?array { $errorMsg = null; if (!function_exists('exec')) { $errorMsg = "exec() est désactivé sur ce serveur."; return null; } if (!file_exists($logPath)) { $errorMsg = "Fichier introuvable : " . htmlspecialchars($logPath); return null; } if (!is_readable($logPath)) { $errorMsg = "Fichier non lisible (permissions insuffisantes) : " . htmlspecialchars($logPath); return null; } $output = []; $rc = 0; exec('tail -n ' . intval($lines) . ' ' . escapeshellarg($logPath) . ' 2>/dev/null', $output, $rc); if ($rc !== 0) { $errorMsg = "Erreur lors de la lecture du fichier journal."; return null; } return array_reverse($output); } function frag_logLineClass(string $line): string { if (preg_match('/\[(crit|emerg|alert)\]/', $line)) return 'log-crit'; if (preg_match('/\[error\]/', $line)) return 'log-error'; if (preg_match('/\[warn\]/', $line)) return 'log-warn'; if (preg_match('/\[notice\]/', $line)) return 'log-notice'; if (preg_match('/" [45]\d\d /', $line)) return 'log-error'; if (preg_match('/" 3\d\d /', $line)) return 'log-notice'; return ''; } function frag_nginxLineClass(string $line): string { $trimmed = ltrim($line); if ($trimmed === '' || str_starts_with($trimmed, '#')) return 'nginx-comment'; if (preg_match('/^\s*(location|server|upstream|events|http|geo|map|types)\b/', $line)) return 'nginx-block'; return 'nginx-directive'; } // ── Render ───────────────────────────────────────────────────────────────── if ($tab === 'nginx_config') { $livePath = '/etc/nginx/sites-available/posterg'; $localPath = APP_ROOT . '/nginx/posterg.conf'; $lines = null; $source = null; $meta = null; $error = null; foreach ([[$livePath, 'live'], [$localPath, 'local']] as [$path, $src]) { if (file_exists($path) && is_readable($path)) { $raw = file($path, FILE_IGNORE_NEW_LINES); if ($raw !== false) { $lines = $raw; $source = $src; $sz = filesize($path); $meta = [ 'path' => $path, 'size' => $sz > 1048576 ? number_format($sz / 1048576, 2) . ' MB' : number_format($sz / 1024, 1) . ' KB', 'mtime' => date('d/m/Y H:i:s', filemtime($path)), ]; break; } } } if ($lines === null) { $error = file_exists($livePath) ? "Fichier non lisible (permissions insuffisantes) : " . htmlspecialchars($livePath) : "Config live introuvable (" . htmlspecialchars($livePath) . ") et config locale introuvable (" . htmlspecialchars($localPath) . ")."; } if ($meta): ?>
● Config déployée ⚠ Référence locale (config live inaccessible)
Configuration nginx non disponible
En développement, /etc/nginx/sites-available/posterg n'existe pas. La config de référence se trouve dans nginx/posterg.conf.
Le fichier de configuration est vide.
$line): ?>
$sz > 1048576 ? number_format($sz / 1048576, 2) . ' MB' : number_format($sz / 1024, 1) . ' KB', 'mtime' => date('d/m/Y H:i:s', filemtime($logPath)), ]; } ?>
0): ?> ligne(s)
Journaux non disponibles
En environnement de développement, les logs nginx ne sont pas disponibles. Cette page est pleinement fonctionnelle sur le serveur de production.
Le fichier journal est vide.
$line): ?>