From de4c629ee5e6b6066fd1d16a5792a25610994a01 Mon Sep 17 00:00:00 2001 From: leosw Date: Sat, 27 Dec 2025 19:06:34 +0100 Subject: [PATCH] Fix stats --- index.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/index.php b/index.php index 291e440..0a9ce09 100644 --- a/index.php +++ b/index.php @@ -160,27 +160,30 @@ if ($action === 'admin_generate_stats') { // Emplacement du rapport généré $report = __DIR__ . "/stats.html"; - $files = glob('/var/log/nginx/materiel.org-access.log*.gz'); + // Récupérer tous les logs gzip + $gz_files = glob('/var/log/nginx/materiel.org-access.log*.gz'); - $parts = []; + // Construire la commande + $cmd = "/bin/bash -c '("; - if (!empty($files)) { - $parts[] = 'zcat ' . implode(' ', array_map('escapeshellarg', $files)); + // 1. Logs compressés + if (!empty($gz_files)) { + $cmd .= "zcat " . implode(' ', array_map('escapeshellarg', $gz_files)) . " ; "; } + // 2. Log d’hier if (file_exists('/var/log/nginx/materiel.org-access.log.1')) { - $parts[] = 'cat /var/log/nginx/materiel.org-access.log.1'; + $cmd .= "cat /var/log/nginx/materiel.org-access.log.1 ; "; } - $parts[] = 'cat /var/log/nginx/materiel.org-access.log'; + // 3. Log du jour + $cmd .= "cat /var/log/nginx/materiel.org-access.log"; - // Commande GoAccess - $cmd = '/bin/bash -c \'(' . implode(' && ', $parts) . ')' - . ' | goaccess --log-format=COMBINED --no-progress -o ' - . escapeshellarg($report) - . ' -\' 2>&1'; + $cmd .= ") | goaccess --log-format=COMBINED --no-progress -o " + . escapeshellarg($report) + . " -' 2>&1"; - // Exécuter la commande + // Exécuter $output = shell_exec($cmd); // Vérifier si le fichier a été généré