Add request log to dashboard, update guides with logging docs

This commit is contained in:
2026-07-28 14:59:18 +02:00
parent 35f502ad93
commit 9fc26266cd
4 changed files with 100 additions and 2 deletions
+30 -1
View File
@@ -66,7 +66,10 @@
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<div class="card shadow-sm"> <div class="card shadow-sm">
<div class="card-header"><i class="bi bi-activity"></i> Recente activiteit</div> <div class="card-header d-flex justify-content-between align-items-center">
<span><i class="bi bi-activity"></i> Recente activiteit</span>
<a href="/admin/logs?tab=admin" class="btn btn-sm btn-outline-secondary">Bekijk alle →</a>
</div>
<div class="card-body" style="max-height: 300px; overflow-y: auto;"> <div class="card-body" style="max-height: 300px; overflow-y: auto;">
<?php if (empty($recentLogs)): ?> <?php if (empty($recentLogs)): ?>
<p class="text-muted mb-0">Geen activiteit geregistreerd.</p> <p class="text-muted mb-0">Geen activiteit geregistreerd.</p>
@@ -85,6 +88,32 @@
</div> </div>
</div> </div>
</div> </div>
<div class="col-md-6">
<div class="card shadow-sm">
<div class="card-header d-flex justify-content-between align-items-center">
<span><i class="bi bi-globe"></i> Recente requests</span>
<a href="/admin/logs?tab=requests" class="btn btn-sm btn-outline-secondary">Bekijk alle →</a>
</div>
<div class="card-body" style="max-height: 300px; overflow-y: auto;">
<?php if (empty($recentRequests)): ?>
<p class="text-muted mb-0">Geen requests geregistreerd.</p>
<?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>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
</div>
</div>
<div class="col-md-6"> <div class="col-md-6">
<div class="card shadow-sm"> <div class="card shadow-sm">
<div class="card-header"><i class="bi bi-lightning"></i> Snelle acties</div> <div class="card-header"><i class="bi bi-lightning"></i> Snelle acties</div>
+25
View File
@@ -9,6 +9,7 @@
- [Configuration](#configuration) - [Configuration](#configuration)
- [Content Structure](#content-structure) - [Content Structure](#content-structure)
- [Admin Console](#admin-console) - [Admin Console](#admin-console)
- [Logging & Request Log](#logging--request-log)
- [Templates](#templates) - [Templates](#templates)
- [URL Structure](#url-structure) - [URL Structure](#url-structure)
- [SEO Optimization](#seo-optimization) - [SEO Optimization](#seo-optimization)
@@ -86,6 +87,8 @@ CodePress CMS is a lightweight, file-based content management system built with
- **Media management** - Upload and delete media files in `content/-assets/` - **Media management** - Upload and delete media files in `content/-assets/`
- **User management** - Add, remove users, change passwords - **User management** - Add, remove users, change passwords
- **Guide** - Built-in documentation with API reference - **Guide** - Built-in documentation with API reference
- **Logging** - Activity log and request log with IP, page, domain; view and download via `/admin/logs`
- **Bot & AI blocking** - Automatic 403 for known bots and AI crawlers
- Session-based authentication with bcrypt hashing - Session-based authentication with bcrypt hashing
- CSRF protection, brute-force lockout (5 attempts, 15 min) - CSRF protection, brute-force lockout (5 attempts, 15 min)
- Default login: `admin` / `admin` (change immediately after installation) - Default login: `admin` / `admin` (change immediately after installation)
@@ -310,6 +313,7 @@ Media files (images, PDFs, video, audio) can be placed in any `content/` subdire
| `media-list` | JSON list of all media (for editor modal) | | `media-list` | JSON list of all media (for editor modal) |
| `users` | User management | | `users` | User management |
| `guide` | Guide / documentation | | `guide` | Guide / documentation |
| `logs` | Log viewer (activity + requests) |
### Editor Features ### Editor Features
@@ -324,6 +328,27 @@ The content editor (`content-edit`, `content-new`) includes:
- **Upload and "Create" buttons** are disabled until input is provided - **Upload and "Create" buttons** are disabled until input is provided
- **"Cancel" button** (instead of "Back") for unsaved changes - **"Cancel" button** (instead of "Back") for unsaved changes
### Logging & Request Log
The admin console maintains two logs:
- **Activity log** (`admin/storage/logs/admin.log`) — admin actions like creating, editing, deleting pages, enabling/disabling plugins, changing configuration.
- **Request log** (`admin/storage/logs/requests.log`) — every page view on the website, including IP, page, domain, language, user agent, and referrer.
Both logs can be viewed and downloaded via **`/admin/logs`** or the sidebar "Logs" link. The dashboard shows the last 20 entries of each log. Click "View all →" for the full list, where you can also download or clear.
### Bot & AI Blocking
Incoming requests are checked against known bot and AI crawler patterns via the User-Agent header. Detected bots receive a **403 Forbidden** response.
Blocked categories:
| Category | Examples |
|---|---|
| AI Crawlers | GPTBot, ChatGPT-User, Claude-Web, ClaudeBot, Google-Extended, CCBot, PerplexityBot |
| Search Engines | Googlebot, Bingbot, BingPreview, DuckDuckBot, YandexBot, Baiduspider |
| Scrapers | HTTrack, Scrapy, PhantomJS |
## Templates ## Templates
### Template Variables ### Template Variables
+26 -1
View File
@@ -9,6 +9,7 @@
- [Configuratie](#configuratie) - [Configuratie](#configuratie)
- [Content Structuur](#content-structuur) - [Content Structuur](#content-structuur)
- [Admin Console](#admin-console) - [Admin Console](#admin-console)
- [Logging & Request Log](#logging--request-log)
- [Templates](#templates) - [Templates](#templates)
- [URL Structuur](#url-structuur) - [URL Structuur](#url-structuur)
- [SEO Optimalisatie](#seo-optimalisatie) - [SEO Optimalisatie](#seo-optimalisatie)
@@ -86,6 +87,8 @@ CodePress CMS is een lichtgewicht, file-based content management systeem gebouwd
- **Media beheer** - Uploaden en verwijderen van mediabestanden in `content/-assets/` - **Media beheer** - Uploaden en verwijderen van mediabestanden in `content/-assets/`
- **Gebruikersbeheer** - Gebruikers toevoegen, verwijderen, wachtwoorden wijzigen - **Gebruikersbeheer** - Gebruikers toevoegen, verwijderen, wachtwoorden wijzigen
- **Handleiding** - Ingebouwde documentatie met API referentie - **Handleiding** - Ingebouwde documentatie met API referentie
- **Logging** - Activiteitenlog en requests log met IP, pagina, domein; te bekijken en downloaden via `/admin/logs`
- **Bot & AI blokkering** - Automatische 403 voor bekende bots en AI-crawlers
- Session-based authenticatie met bcrypt hashing - Session-based authenticatie met bcrypt hashing
- CSRF-bescherming, brute-force lockout (5 pogingen, 15 min) - CSRF-bescherming, brute-force lockout (5 pogingen, 15 min)
- Standaard login: `admin` / `admin` (wijzig direct na installatie) - Standaard login: `admin` / `admin` (wijzig direct na installatie)
@@ -311,6 +314,7 @@ Media bestanden (afbeeldingen, PDFs, video, audio) kunnen in elke `content/` sub
| `media-list` | JSON lijst van alle media (voor editor modal) | | `media-list` | JSON lijst van alle media (voor editor modal) |
| `users` | Gebruikersbeheer | | `users` | Gebruikersbeheer |
| `guide` | Handleiding (deze documentatie) | | `guide` | Handleiding (deze documentatie) |
| `logs` | Log viewer (activiteiten + requests) |
### Editor Functionaliteit ### Editor Functionaliteit
@@ -323,7 +327,28 @@ De content editor (`content-edit`, `content-new`) bevat:
- **Layout selector** - Kies uit beschikbare layouts - **Layout selector** - Kies uit beschikbare layouts
- **Plugin per-page zichtbaarheid** - Selecteer welke plugins op deze pagina tonen - **Plugin per-page zichtbaarheid** - Selecteer welke plugins op deze pagina tonen
- **Upload en "Aanmaken" knoppen** zijn disabled totdat er input is - **Upload en "Aanmaken" knoppen** zijn disabled totdat er input is
- **"Annuleren"** knop (i.p.v. "Terug") bij ongewijzigde wijzigingen - **"Annuleren" knop** (i.p.v. "Terug") bij ongewijzigde wijzigingen
### Logging & Request Log
De admin console houdt twee logs bij:
- **Activiteitenlog** (`admin/storage/logs/admin.log`) — admin acties zoals pagina's aanmaken, bewerken, verwijderen, plugin in/uitschakelen, configuratie wijzigen.
- **Requests log** (`admin/storage/logs/requests.log`) — elke pageview op de website, met IP, pagina, domein, taal, user-agent en referrer.
Beide logs zijn te bekijken en te downloaden via **`/admin/logs`** of via de sidebar link "Logs". Het dashboard toont de laatste 20 entries van elk log. Klik "Bekijk alle →" voor de volledige lijst, waar je ook kunt downloaden of wissen.
### Bot & AI Blokkering
Bij binnenkomende requests detecteert het systeem bekende bots en AI-crawlers op basis van de User-Agent header. Gedetecteerde bots krijgen een **403 Forbidden** en worden niet aan de CMS doorgegeven.
Geblokkeerde categorieën:
| Categorie | Voorbeelden |
|---|---|
| AI Crawlers | GPTBot, ChatGPT-User, Claude-Web, ClaudeBot, Google-Extended, CCBot, PerplexityBot |
| Search Engines | Googlebot, Bingbot, BingPreview, DuckDuckBot, YandexBot, Baiduspider |
| Scrapers | HTTrack, Scrapy, PhantomJS |
## Templates ## Templates
+19
View File
@@ -218,6 +218,25 @@ function handleDashboard(AdminAuth $auth, array $config): void
$recentLogs = array_reverse($recentLogs); $recentLogs = array_reverse($recentLogs);
} }
// Load recent request log
$requestLogFile = $config['request_log'];
$recentRequests = [];
if (file_exists($requestLogFile)) {
$lines = file($requestLogFile);
$lines = array_slice($lines, -20);
foreach ($lines as $line) {
if (preg_match('/^\[([^\]]+)\] \[([^\]]+)\] \[([^\]]+)\] \[([^\]]*)\] \[([^\]]+)\] \[([^\]]*)\] \[([^\]]*)\]$/', trim($line), $m)) {
$recentRequests[] = [
'time' => $m[1],
'ip' => $m[2],
'page' => $m[5],
'ua' => $m[6],
];
}
}
$recentRequests = array_reverse($recentRequests);
}
require __DIR__ . '/../admin/templates/layout.php'; require __DIR__ . '/../admin/templates/layout.php';
} }