From 3bb83b3ffdccb44d27653ad840a1443a7bf2ae49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drix?= Date: Fri, 15 May 2026 00:35:19 +0200 Subject: [PATCH] =?UTF-8?q?feat=20:=20SearchLogParser=20accepte=20un=20pat?= =?UTF-8?q?tern=20glob=20pour=20les=20logs=20d'acc=C3=A8s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Balaye tous les fichiers correspondant au pattern (ex: *-access.log) et leurs rotations .gz/.tar.gz. Valeur par défaut : *-access.log. Label renommé en "Pattern des logs d'accès". Co-Authored-By: Claude Sonnet 4.6 --- src/SearchLogParser.php | 39 ++++++++++++++++++++++----------------- src/SiteSettings.php | 2 +- templates/admin.php | 6 +++--- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/SearchLogParser.php b/src/SearchLogParser.php index b9af3a9..63b092e 100644 --- a/src/SearchLogParser.php +++ b/src/SearchLogParser.php @@ -11,7 +11,7 @@ class SearchLogParser public function __construct( string $logDir = '/var/log/apache2', - string $vhostBase = 'lan.acegrp.varlog-access.log', + string $vhostBase = '*-access.log', string $cacheFile = '', int $cacheTtl = 600 ) { @@ -47,8 +47,7 @@ class SearchLogParser public function isReadable(): bool { - $f = $this->logDir . '/' . $this->vhostBase; - return file_exists($f) && is_readable($f); + return count($this->logFiles()) > 0; } private function cacheValid(): bool @@ -60,23 +59,29 @@ class SearchLogParser /** @return list type: plain|gz|tgz */ private function logFiles(): array { - $base = $this->logDir . '/' . $this->vhostBase; - $files = []; + $pattern = $this->logDir . '/' . $this->vhostBase; + $files = []; - if (file_exists($base) && is_readable($base)) { - $files[] = ['path' => $base, 'type' => 'plain']; - } - - foreach (glob($base . '.*') ?: [] as $path) { - if (!is_readable($path)) { + // Fichiers correspondant au pattern de base (courants + rotations incluses si glob) + $bases = glob($pattern) ?: []; + // Ajouter aussi les rotations (.N, .N.gz, .N.tar.gz) pour chaque base trouvée + foreach ($bases as $base) { + // Exclure les rotations déjà capturées par le pattern glob + if (str_ends_with($base, '.gz') || preg_match('/\.\d+$/', $base)) { 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']; + $candidates = array_merge([$base], glob($base . '.*') ?: []); + foreach ($candidates 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']; + } } } diff --git a/src/SiteSettings.php b/src/SiteSettings.php index 1d9d08f..856d0ae 100644 --- a/src/SiteSettings.php +++ b/src/SiteSettings.php @@ -65,7 +65,7 @@ function apacheAccessLog(): string if ($fromSettings !== '') { return $fromSettings; } - return (string)($_ENV['APACHE_ACCESS_LOG'] ?? getenv('APACHE_ACCESS_LOG') ?: 'lan.acegrp.varlog-access.log'); + return (string)($_ENV['APACHE_ACCESS_LOG'] ?? getenv('APACHE_ACCESS_LOG') ?: '*-access.log'); } function saveSiteSettings(array $data): bool diff --git a/templates/admin.php b/templates/admin.php index 32579dd..dc4dd46 100644 --- a/templates/admin.php +++ b/templates/admin.php @@ -1073,12 +1073,12 @@ foreach (COLOR_PALETTE_16 as $_i => $_rgb):
- + -
Nom du fichier dans /var/log/apache2/. Supporte .gz et .tar.gz.
+ maxlength="200" placeholder="ex : *-access.log"> +
Pattern glob dans /var/log/apache2/. Les rotations (.gz, .tar.gz) sont automatiquement incluses.