Fix stats

This commit is contained in:
leosw
2025-12-27 19:06:34 +01:00
parent 989e817926
commit de4c629ee5

View File

@@ -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 dhier
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é