fix : vérification écriture settings + script setup.sh #63

Merged
cedricAbonnel merged 7 commits from feat/wizard-multi-step into main 2026-05-14 22:50:37 +00:00
3 changed files with 61 additions and 18 deletions
Showing only changes of commit 981c9f6cb3 - Show all commits
+10
View File
@@ -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') {
+28 -10
View File
@@ -57,23 +57,26 @@ class SearchLogParser
&& (time() - filemtime($this->cacheFile)) < $this->cacheTtl;
}
/** @return list<array{path:string,gz:bool}> */
/** @return list<array{path:string,type:string}> 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;
+23 -8
View File
@@ -507,14 +507,6 @@ function adminStatusBadge(array $a, int $now): string
value="<?= postsPerPage() ?>"
min="1" max="100">
</div>
<div class="mb-3">
<label for="apache-access-log" class="form-label small fw-semibold">Log d'accès Apache</label>
<input type="text" id="apache-access-log" name="apache_access_log"
class="form-control form-control-sm font-monospace"
value="<?= htmlspecialchars(apacheAccessLog()) ?>"
maxlength="200" placeholder="ex : lan.acegrp.monsite-access.log">
<div class="form-text">Nom du fichier dans <code>/var/log/apache2/</code>, utilisé par l'onglet Recherches.</div>
</div>
<div class="mb-3">
<label for="site-license-label" class="form-label small fw-semibold">Licence (libellé)</label>
<input type="text" id="site-license-label" name="site_license_label"
@@ -1070,6 +1062,29 @@ foreach (COLOR_PALETTE_16 as $_i => $_rgb):
<!-- ─────────────────────────── RECHERCHES ─────────────────────────── -->
<?php if ($tab === 'searches' && isAdmin()): ?>
<?php if (isset($_GET['saved'])): ?>
<div class="alert alert-success py-2 mb-3">Configuration enregistrée.</div>
<?php elseif (($_GET['error'] ?? '') === 'write'): ?>
<div class="alert alert-danger py-2 mb-3">Impossible d'enregistrer : le fichier n'est pas accessible en écriture.</div>
<?php endif; ?>
<div class="card mb-4" style="max-width:540px">
<div class="card-header bg-transparent py-2 small fw-semibold">Configuration des logs</div>
<div class="card-body py-3">
<form method="post" action="/?action=admin_save_searches_config">
<div class="mb-3">
<label for="apache-access-log" class="form-label small fw-semibold">Log d'accès Apache</label>
<input type="text" id="apache-access-log" name="apache_access_log"
class="form-control form-control-sm font-monospace"
value="<?= htmlspecialchars(apacheAccessLog()) ?>"
maxlength="200" placeholder="ex : lan.acegrp.monsite-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>
<button type="submit" class="btn btn-primary btn-sm">Enregistrer</button>
</form>
</div>
</div>
<div class="d-flex align-items-center justify-content-between mb-3 flex-wrap gap-2">
<h5 class="mb-0">Termes recherchés
<span class="badge bg-secondary ms-1"><?= count($adminData['search_terms'] ?? []) ?></span>