feat : SearchLogParser accepte un pattern glob pour les logs d'accès
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 <noreply@anthropic.com>
This commit is contained in:
+13
-8
@@ -11,7 +11,7 @@ class SearchLogParser
|
|||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
string $logDir = '/var/log/apache2',
|
string $logDir = '/var/log/apache2',
|
||||||
string $vhostBase = 'lan.acegrp.varlog-access.log',
|
string $vhostBase = '*-access.log',
|
||||||
string $cacheFile = '',
|
string $cacheFile = '',
|
||||||
int $cacheTtl = 600
|
int $cacheTtl = 600
|
||||||
) {
|
) {
|
||||||
@@ -47,8 +47,7 @@ class SearchLogParser
|
|||||||
|
|
||||||
public function isReadable(): bool
|
public function isReadable(): bool
|
||||||
{
|
{
|
||||||
$f = $this->logDir . '/' . $this->vhostBase;
|
return count($this->logFiles()) > 0;
|
||||||
return file_exists($f) && is_readable($f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function cacheValid(): bool
|
private function cacheValid(): bool
|
||||||
@@ -60,14 +59,19 @@ class SearchLogParser
|
|||||||
/** @return list<array{path:string,type:string}> type: plain|gz|tgz */
|
/** @return list<array{path:string,type:string}> type: plain|gz|tgz */
|
||||||
private function logFiles(): array
|
private function logFiles(): array
|
||||||
{
|
{
|
||||||
$base = $this->logDir . '/' . $this->vhostBase;
|
$pattern = $this->logDir . '/' . $this->vhostBase;
|
||||||
$files = [];
|
$files = [];
|
||||||
|
|
||||||
if (file_exists($base) && is_readable($base)) {
|
// Fichiers correspondant au pattern de base (courants + rotations incluses si glob)
|
||||||
$files[] = ['path' => $base, 'type' => 'plain'];
|
$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;
|
||||||
}
|
}
|
||||||
|
$candidates = array_merge([$base], glob($base . '.*') ?: []);
|
||||||
foreach (glob($base . '.*') ?: [] as $path) {
|
foreach ($candidates as $path) {
|
||||||
if (!is_readable($path)) {
|
if (!is_readable($path)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -79,6 +83,7 @@ class SearchLogParser
|
|||||||
$files[] = ['path' => $path, 'type' => 'plain'];
|
$files[] = ['path' => $path, 'type' => 'plain'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $files;
|
return $files;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ function apacheAccessLog(): string
|
|||||||
if ($fromSettings !== '') {
|
if ($fromSettings !== '') {
|
||||||
return $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
|
function saveSiteSettings(array $data): bool
|
||||||
|
|||||||
+3
-3
@@ -1073,12 +1073,12 @@ foreach (COLOR_PALETTE_16 as $_i => $_rgb):
|
|||||||
<div class="card-body py-3">
|
<div class="card-body py-3">
|
||||||
<form method="post" action="/?action=admin_save_searches_config">
|
<form method="post" action="/?action=admin_save_searches_config">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="apache-access-log" class="form-label small fw-semibold">Log d'accès Apache</label>
|
<label for="apache-access-log" class="form-label small fw-semibold">Pattern des logs d'accès</label>
|
||||||
<input type="text" id="apache-access-log" name="apache_access_log"
|
<input type="text" id="apache-access-log" name="apache_access_log"
|
||||||
class="form-control form-control-sm font-monospace"
|
class="form-control form-control-sm font-monospace"
|
||||||
value="<?= htmlspecialchars(apacheAccessLog()) ?>"
|
value="<?= htmlspecialchars(apacheAccessLog()) ?>"
|
||||||
maxlength="200" placeholder="ex : lan.acegrp.monsite-access.log">
|
maxlength="200" placeholder="ex : *-access.log">
|
||||||
<div class="form-text">Nom du fichier dans <code>/var/log/apache2/</code>. Supporte <code>.gz</code> et <code>.tar.gz</code>.</div>
|
<div class="form-text">Pattern glob dans <code>/var/log/apache2/</code>. Les rotations (<code>.gz</code>, <code>.tar.gz</code>) sont automatiquement incluses.</div>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-primary btn-sm">Enregistrer</button>
|
<button type="submit" class="btn btn-primary btn-sm">Enregistrer</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user