diff --git a/public/index.php b/public/index.php index 386f6c8..092b3b9 100644 --- a/public/index.php +++ b/public/index.php @@ -2810,6 +2810,16 @@ switch ($action) { header('Location: /admin/site?' . ($ok ? 'saved=1' : 'error=write')); exit; + case 'admin_save_searches_config': + requireAuth(); + if (!isAdmin() || $_SERVER['REQUEST_METHOD'] !== 'POST') { + http_response_code(403); + exit; + } + $ok = saveSiteSettings(['apache_access_log' => $_POST['apache_access_log'] ?? '']); + header('Location: /admin/searches?' . ($ok ? 'saved=1' : 'error=write')); + exit; + case 'admin_create_role': requireAuth(); if (!isAdmin() || $_SERVER['REQUEST_METHOD'] !== 'POST') { diff --git a/src/SearchLogParser.php b/src/SearchLogParser.php index cb7c3b5..b9af3a9 100644 --- a/src/SearchLogParser.php +++ b/src/SearchLogParser.php @@ -57,23 +57,26 @@ class SearchLogParser && (time() - filemtime($this->cacheFile)) < $this->cacheTtl; } - /** @return list */ + /** @return list type: plain|gz|tgz */ private function logFiles(): array { $base = $this->logDir . '/' . $this->vhostBase; $files = []; if (file_exists($base) && is_readable($base)) { - $files[] = ['path' => $base, 'gz' => false]; + $files[] = ['path' => $base, 'type' => 'plain']; } - for ($i = 1; $i <= 14; $i++) { - $plain = $base . '.' . $i; - $gz = $plain . '.gz'; - if (file_exists($plain) && is_readable($plain)) { - $files[] = ['path' => $plain, 'gz' => false]; - } elseif (file_exists($gz) && is_readable($gz)) { - $files[] = ['path' => $gz, 'gz' => true]; + foreach (glob($base . '.*') ?: [] as $path) { + if (!is_readable($path)) { + continue; + } + if (str_ends_with($path, '.tar.gz')) { + $files[] = ['path' => $path, 'type' => 'tgz']; + } elseif (str_ends_with($path, '.gz')) { + $files[] = ['path' => $path, 'type' => 'gz']; + } else { + $files[] = ['path' => $path, 'type' => 'plain']; } } @@ -82,7 +85,22 @@ class SearchLogParser private function parseFile(array $file, array &$counts): void { - if ($file['gz']) { + if ($file['type'] === 'tgz') { + try { + $phar = new PharData($file['path']); + foreach ($phar as $entry) { + $content = @file_get_contents('phar://' . $file['path'] . '/' . $entry->getFilename()); + if ($content === false) { + continue; + } + foreach (explode("\n", $content) as $line) { + $this->parseLine($line, $counts); + } + } + } catch (\Exception $e) { + // archive illisible, on ignore + } + } elseif ($file['type'] === 'gz') { $h = @gzopen($file['path'], 'rb'); if (!$h) { return; diff --git a/templates/admin.php b/templates/admin.php index 88ce490..32579dd 100644 --- a/templates/admin.php +++ b/templates/admin.php @@ -507,14 +507,6 @@ function adminStatusBadge(array $a, int $now): string value="" min="1" max="100"> -
- - -
Nom du fichier dans /var/log/apache2/, utilisé par l'onglet Recherches.
-
$_rgb): + +
Configuration enregistrée.
+ +
Impossible d'enregistrer : le fichier n'est pas accessible en écriture.
+ + +
+
Configuration des logs
+
+
+
+ + +
Nom du fichier dans /var/log/apache2/. Supporte .gz et .tar.gz.
+
+ +
+
+
+
Termes recherchés