Fix newest homepage detection, file creation dates, real IP, and request log visitor type

- Fix detectNewestPage() to search subdirectories recursively and handle language prefixes
- Fix getFileInfo() to preserve frontmatter created date or ctime instead of overwriting with mtime
- Automatically store created date in frontmatter when creating/editing files
- Add RequestLogger::getClientIp() with proxy and Cloudflare header support
- Replace domain column in request log with visitor/bot type badges (Human, AI, Search, Scraper)
- Update 'Activiteitenlog' to 'Activiteiten log' in UI and guide
This commit is contained in:
2026-07-28 16:56:51 +02:00
parent b8d4a4e6d5
commit f81be9e047
9 changed files with 256 additions and 44 deletions
+8 -1
View File
@@ -304,7 +304,14 @@ class AdminAuth
mkdir($dir, 0755, true);
}
$timestamp = date('Y-m-d H:i:s');
$ip = $_SERVER['REMOTE_ADDR'] ?? 'cli';
if (class_exists('RequestLogger')) {
$ip = RequestLogger::getClientIp();
} else {
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'] ?? $_SERVER['HTTP_X_REAL_IP'] ?? $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'] ?? 'cli';
if (($commaPos = strpos($ip, ',')) !== false) {
$ip = trim(substr($ip, 0, $commaPos));
}
}
file_put_contents($logFile, "[{$timestamp}] [{$level}] [{$ip}] {$message}\n", FILE_APPEND);
}
}
+10 -6
View File
@@ -100,12 +100,16 @@
<?php else: ?>
<ul class="list-unstyled mb-0">
<?php foreach ($recentRequests as $log): ?>
<li class="mb-2 pb-2 border-bottom small">
<span class="text-muted"><?= htmlspecialchars($log['time']) ?></span>
<code class="text-muted"><?= htmlspecialchars($log['ip']) ?></code>
<span class="text-truncate d-inline-block" style="max-width: 200px; vertical-align: bottom;"><?= htmlspecialchars($log['page']) ?></span>
<?php if ($log['ua']): ?>
<span class="badge bg-secondary" title="<?= htmlspecialchars($log['ua']) ?>">bot?</span>
<li class="mb-2 pb-2 border-bottom small d-flex justify-content-between align-items-center">
<div>
<span class="text-muted me-1"><?= htmlspecialchars($log['time']) ?></span>
<code class="text-muted me-1"><?= htmlspecialchars($log['ip']) ?></code>
<span class="fw-bold"><?= htmlspecialchars($log['page']) ?></span>
</div>
<?php if (!empty($log['visitor_info'])): ?>
<span class="badge bg-<?= $log['visitor_info']['badge'] ?>" title="<?= htmlspecialchars($log['ua']) ?>">
<i class="bi <?= $log['visitor_info']['icon'] ?>"></i> <?= $log['visitor_info']['label'] ?>
</span>
<?php endif; ?>
</li>
<?php endforeach; ?>
+8 -4
View File
@@ -2,7 +2,7 @@
<ul class="nav nav-tabs mb-3" id="logTabs" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link <?= $activeTab === 'admin' ? 'active' : '' ?>" id="admin-log-tab" data-bs-toggle="tab" data-bs-target="#admin-log" type="button" role="tab">Activiteitenlog</button>
<button class="nav-link <?= $activeTab === 'admin' ? 'active' : '' ?>" id="admin-log-tab" data-bs-toggle="tab" data-bs-target="#admin-log" type="button" role="tab">Activiteiten log</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link <?= $activeTab === 'requests' ? 'active' : '' ?>" id="request-log-tab" data-bs-toggle="tab" data-bs-target="#request-log" type="button" role="tab">Requests log</button>
@@ -16,7 +16,7 @@
<small class="text-muted"><?= count($adminLogs) ?> regels</small>
<div>
<a href="/admin/logs?tab=admin&download=1" class="btn btn-sm btn-outline-secondary"><i class="bi bi-download"></i> Download</a>
<a href="/admin/logs?tab=admin&clear=1" class="btn btn-sm btn-outline-danger" onclick="return confirm('Activiteitenlog wissen?')"><i class="bi bi-trash"></i> Wissen</a>
<a href="/admin/logs?tab=admin&clear=1" class="btn btn-sm btn-outline-danger" onclick="return confirm('Activiteiten log wissen?')"><i class="bi bi-trash"></i> Wissen</a>
</div>
</div>
<div class="card shadow-sm">
@@ -69,7 +69,7 @@
<th>Tijd</th>
<th>IP</th>
<th>Pagina</th>
<th>Domein</th>
<th>Type / Gebruiker</th>
<th>Taal</th>
<th>User agent</th>
<th>Referrer</th>
@@ -81,7 +81,11 @@
<td class="text-nowrap small text-muted"><?= htmlspecialchars($log['time']) ?></td>
<td><code class="small"><?= htmlspecialchars($log['ip']) ?></code></td>
<td><?= htmlspecialchars($log['page']) ?></td>
<td><?= htmlspecialchars($log['host']) ?></td>
<td>
<span class="badge bg-<?= $log['visitor_info']['badge'] ?>">
<i class="bi <?= $log['visitor_info']['icon'] ?>"></i> <?= $log['visitor_info']['label'] ?>
</span>
</td>
<td><?= htmlspecialchars($log['lang']) ?></td>
<td class="small text-muted" title="<?= htmlspecialchars($log['ua']) ?>"><?= htmlspecialchars(substr($log['ua'], 0, 60)) ?><?= strlen($log['ua']) > 60 ? '…' : '' ?></td>
<td class="small text-muted" title="<?= htmlspecialchars($log['referrer']) ?>"><?= htmlspecialchars(substr($log['referrer'], 0, 40)) ?><?= strlen($log['referrer']) > 40 ? '…' : '' ?></td>