From 99a4c20e97d6d6b1e6b3898b189ec4c2b7bba27a Mon Sep 17 00:00:00 2001 From: Edwin Noorlander Date: Tue, 28 Jul 2026 14:59:18 +0200 Subject: [PATCH] Add request log to dashboard, update guides with logging docs --- admin/templates/pages/dashboard.php | 31 ++++++++++++++++++++++++++++- guide/en.codepress.md | 25 +++++++++++++++++++++++ guide/nl.codepress.md | 27 ++++++++++++++++++++++++- public/admin.php | 19 ++++++++++++++++++ 4 files changed, 100 insertions(+), 2 deletions(-) diff --git a/admin/templates/pages/dashboard.php b/admin/templates/pages/dashboard.php index 47fa884..2602d30 100644 --- a/admin/templates/pages/dashboard.php +++ b/admin/templates/pages/dashboard.php @@ -66,7 +66,10 @@
-
Recente activiteit
+
+ Recente activiteit + Bekijk alle → +

Geen activiteit geregistreerd.

@@ -85,6 +88,32 @@
+
+
+
+ Recente requests + Bekijk alle → +
+
+ +

Geen requests geregistreerd.

+ +
    + +
  • + + + + + bot? + +
  • + +
+ +
+
+
Snelle acties
diff --git a/guide/en.codepress.md b/guide/en.codepress.md index 0f4f1bf..0a95db2 100644 --- a/guide/en.codepress.md +++ b/guide/en.codepress.md @@ -9,6 +9,7 @@ - [Configuration](#configuration) - [Content Structure](#content-structure) - [Admin Console](#admin-console) +- [Logging & Request Log](#logging--request-log) - [Templates](#templates) - [URL Structure](#url-structure) - [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/` - **User management** - Add, remove users, change passwords - **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 - CSRF protection, brute-force lockout (5 attempts, 15 min) - 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) | | `users` | User management | | `guide` | Guide / documentation | +| `logs` | Log viewer (activity + requests) | ### Editor Features @@ -324,6 +328,27 @@ The content editor (`content-edit`, `content-new`) includes: - **Upload and "Create" buttons** are disabled until input is provided - **"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 ### Template Variables diff --git a/guide/nl.codepress.md b/guide/nl.codepress.md index d37dbbe..323b806 100644 --- a/guide/nl.codepress.md +++ b/guide/nl.codepress.md @@ -9,6 +9,7 @@ - [Configuratie](#configuratie) - [Content Structuur](#content-structuur) - [Admin Console](#admin-console) +- [Logging & Request Log](#logging--request-log) - [Templates](#templates) - [URL Structuur](#url-structuur) - [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/` - **Gebruikersbeheer** - Gebruikers toevoegen, verwijderen, wachtwoorden wijzigen - **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 - CSRF-bescherming, brute-force lockout (5 pogingen, 15 min) - 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) | | `users` | Gebruikersbeheer | | `guide` | Handleiding (deze documentatie) | +| `logs` | Log viewer (activiteiten + requests) | ### Editor Functionaliteit @@ -323,7 +327,28 @@ De content editor (`content-edit`, `content-new`) bevat: - **Layout selector** - Kies uit beschikbare layouts - **Plugin per-page zichtbaarheid** - Selecteer welke plugins op deze pagina tonen - **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 diff --git a/public/admin.php b/public/admin.php index 04b754b..739b688 100644 --- a/public/admin.php +++ b/public/admin.php @@ -218,6 +218,25 @@ function handleDashboard(AdminAuth $auth, array $config): void $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'; }