From 5884877f18c06275314e34f451d9697e1a4ead00 Mon Sep 17 00:00:00 2001 From: Edwin Noorlander Date: Tue, 28 Jul 2026 17:26:34 +0200 Subject: [PATCH] Add system update feature, git-ignore local configs, and fix homepage request logging - Exclude config.json and admin.json in .gitignore so live settings/passwords are never overwritten by git - Auto-generate config.json and admin.json with defaults if missing - Add config.json.example and admin.json.example reference templates - Add System Update page (/admin/update) in Admin Console to pull updates via Git with 1 click - Log effective page name in index.php instead of literal 'auto' - Add extra HAProxy/PFSense proxy headers to RequestLogger::getClientIp() --- .gitignore | 4 ++ .../config/{admin.json => admin.json.example} | 3 - admin/src/AdminAuth.php | 29 ++++++++- admin/templates/layout.php | 8 +++ admin/templates/pages/update.php | 56 +++++++++++++++++ cms/core/class/RequestLogger.php | 2 + cms/core/config.php | 36 +++++++++++ config.json => config.json.example | 11 ++-- guide/nl.codepress.md | 4 +- public/admin.php | 63 +++++++++++++++++++ public/index.php | 2 +- 11 files changed, 205 insertions(+), 13 deletions(-) rename admin/config/{admin.json => admin.json.example} (86%) create mode 100644 admin/templates/pages/update.php rename config.json => config.json.example (80%) diff --git a/.gitignore b/.gitignore index d44a862..550d94e 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,10 @@ Thumbs.db *.tmp *.temp +# Local configuration & credentials +config.json +admin/config/admin.json + # No content content/ !content/.gitkeep diff --git a/admin/config/admin.json b/admin/config/admin.json.example similarity index 86% rename from admin/config/admin.json rename to admin/config/admin.json.example index 69410b9..0526dfc 100644 --- a/admin/config/admin.json +++ b/admin/config/admin.json.example @@ -11,8 +11,5 @@ "session_timeout": 1800, "max_login_attempts": 5, "lockout_duration": 900 - }, - "config": { - "default_page": "auto" } } diff --git a/admin/src/AdminAuth.php b/admin/src/AdminAuth.php index b20b914..48e5e91 100644 --- a/admin/src/AdminAuth.php +++ b/admin/src/AdminAuth.php @@ -20,10 +20,35 @@ class AdminAuth private function loadAdminConfig(): array { $path = $this->config['admin_config']; + $examplePath = dirname($path) . '/admin.json.example'; + if (!file_exists($path)) { - return ['users' => [], 'security' => []]; + if (file_exists($examplePath)) { + @copy($examplePath, $path); + } else { + $defaultAdminConfig = [ + 'users' => [ + [ + 'username' => 'admin', + 'password_hash' => password_hash('admin', PASSWORD_BCRYPT), + 'role' => 'admin', + 'created' => date('Y-m-d'), + ] + ], + 'security' => [ + 'session_timeout' => 1800, + 'max_login_attempts' => 5, + 'lockout_duration' => 900, + ] + ]; + $dir = dirname($path); + if (!is_dir($dir)) { + @mkdir($dir, 0755, true); + } + @file_put_contents($path, json_encode($defaultAdminConfig, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); + } } - $data = json_decode(file_get_contents($path), true); + $data = file_exists($path) ? json_decode(file_get_contents($path), true) : null; return is_array($data) ? $data : ['users' => [], 'security' => []]; } diff --git a/admin/templates/layout.php b/admin/templates/layout.php index c092622..1653113 100644 --- a/admin/templates/layout.php +++ b/admin/templates/layout.php @@ -86,6 +86,11 @@ $layoutSidebarColor = $layoutThemeConfig['header_color'] ?? '#0a369d'; Logs +