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()
This commit is contained in:
2026-07-28 17:26:34 +02:00
parent e2d9ddd516
commit 62dd7ddb9c
10 changed files with 205 additions and 10 deletions
+27 -2
View File
@@ -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' => []];
}
+8
View File
@@ -86,6 +86,11 @@ $layoutSidebarColor = $layoutThemeConfig['header_color'] ?? '#0a369d';
<i class="bi bi-journal-text"></i> Logs
</a>
</li>
<li class="nav-item">
<a class="nav-link <?= ($route ?? '') === 'update' ? 'active' : '' ?>" href="/admin/update">
<i class="bi bi-cloud-arrow-down"></i> Update
</a>
</li>
<li class="nav-item mt-3">
<a class="nav-link" href="/" target="_blank">
<i class="bi bi-box-arrow-up-right"></i> Website bekijken
@@ -168,6 +173,9 @@ $layoutSidebarColor = $layoutThemeConfig['header_color'] ?? '#0a369d';
case 'logs':
require __DIR__ . '/pages/logs.php';
break;
case 'update':
require __DIR__ . '/pages/update.php';
break;
}
?>
</main>
+56
View File
@@ -0,0 +1,56 @@
<h2 class="mb-4"><i class="bi bi-cloud-arrow-down"></i> Systeem Update</h2>
<?php if (!empty($updateOutput)): ?>
<div class="card shadow-sm mb-4">
<div class="card-header bg-dark text-white">
<i class="bi bi-terminal"></i> Update Resultaten
</div>
<div class="card-body bg-dark text-light p-3">
<pre class="m-0 text-light" style="font-family: monospace; font-size: 0.9rem;"><?= htmlspecialchars($updateOutput) ?></pre>
</div>
</div>
<?php endif; ?>
<div class="card shadow-sm mb-4">
<div class="card-header">
<i class="bi bi-info-circle"></i> Systeeminformatie
</div>
<div class="card-body">
<div class="row">
<div class="col-md-6 mb-3">
<strong>Huidige CMS Versie:</strong>
<span class="badge bg-primary ms-2"><?= htmlspecialchars($cmsVersion ?? '1.7.1') ?></span>
</div>
<div class="col-md-6 mb-3">
<strong>Configuratiestatus:</strong>
<span class="badge bg-success ms-2"><i class="bi bi-check-circle"></i> Lokaal afgeschermd (Git-safe)</span>
</div>
</div>
<p class="text-muted small mb-0">
Lokale configuratiebestanden (zoals <code>config.json</code> en <code>admin.json</code>) zijn uitgesloten van Git.
Hierdoor blijven je instellingen, wachtwoorden en content veilig behouden tijdens het bijwerken.
</p>
</div>
</div>
<div class="card shadow-sm mb-4">
<div class="card-header">
<i class="bi bi-arrow-repeat"></i> CodePress CMS Bijwerken
</div>
<div class="card-body">
<p>Haal automatisch de nieuwste CMS updates op via het Git repository.</p>
<?php if (!empty($gitBranch)): ?>
<div class="mb-3">
<small class="text-muted">Git branch: <code><?= htmlspecialchars($gitBranch) ?></code></small>
</div>
<?php endif; ?>
<form method="POST" action="/admin/update">
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrf) ?>">
<button type="submit" class="btn btn-primary btn-lg" onclick="return confirm('Weet je zeker dat je het systeem wilt bijwerken naar de nieuwste versie?')">
<i class="bi bi-cloud-download"></i> Systeem nu bijwerken
</button>
</form>
</div>
</div>