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 "$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'] +