From ea208f5845f86520816b77d9b2160da3890bc286 Mon Sep 17 00:00:00 2001 From: leosw Date: Fri, 26 Dec 2025 12:09:09 +0100 Subject: [PATCH] Stats --- index.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/index.php b/index.php index ace6a52..299fefe 100644 --- a/index.php +++ b/index.php @@ -148,6 +148,39 @@ if ($action === 'delete_item' && is_logged()) { redirect('edit'); } +/* ---------- GENERATION STATISTIQUES ---------- */ +if ($action === 'admin_generate_stats') { + + // Sécurité : seul toi (ID=1) + if (!isset($_SESSION['owner_id']) || $_SESSION['owner_id'] != 1) { + echo "

Accès refusé.

"; + exit; + } + + // Emplacement du rapport généré + $report = __DIR__ . "/stats.html"; + + // Commande GoAccess + $cmd = "goaccess /var/log/nginx/access.log " + . "--log-format=COMBINED " + . "-o " . escapeshellarg($report) . " 2>&1"; + + // Exécuter la commande + $output = shell_exec($cmd); + + // Vérifier si le fichier a été généré + if (!file_exists($report)) { + echo "

Erreur lors de la génération du rapport

"; + echo "
$output
"; + exit; + } + + // Redirection vers le rapport + header("Location: stats.html"); + exit; +} + + /* ---------- SUPPRESSION PHOTO MATERIEL ---------- */ if ($action === 'delete_photo' && is_logged()) { @@ -437,6 +470,9 @@ if ($action === 'admin' && isset($_SESSION['owner_id']) && $_SESSION['owner_id'] +

Statistiques

+

🔄 Générer le rapport GoAccess

+