This commit is contained in:
leosw
2025-12-26 12:09:09 +01:00
parent 0faf933118
commit ea208f5845

View File

@@ -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 "<p>Accès refusé.</p>";
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 "<h3>Erreur lors de la génération du rapport</h3>";
echo "<pre>$output</pre>";
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']
</tbody>
</table>
<h2>Statistiques</h2>
<p> <a href="index.php?action=admin_generate_stats">🔄 Générer le rapport GoAccess</a> </p>
<?php
}