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 959f109f9e
commit 5884877f18
11 changed files with 205 additions and 13 deletions
+63
View File
@@ -88,6 +88,10 @@ switch ($route) {
handleConfig($auth, $appConfig);
break;
case 'update':
handleUpdate($auth, $appConfig);
break;
case 'theme':
handleTheme($auth, $appConfig);
break;
@@ -1518,6 +1522,65 @@ function handleLogs(AdminAuth $auth, array $config): void
require __DIR__ . '/../admin/templates/layout.php';
}
function handleUpdate(AdminAuth $auth, array $config): void
{
$user = $auth->getCurrentUser();
$csrf = $auth->getCsrfToken();
$message = '';
$messageType = '';
$updateOutput = '';
// Load CMS version
$versionFile = $config['codepress_root'] . '/version.php';
$cmsVersion = '1.7.1';
if (file_exists($versionFile)) {
$verData = require $versionFile;
$cmsVersion = is_array($verData) ? ($verData['version'] ?? '1.7.1') : '1.7.1';
}
// Get git branch
$gitBranch = 'main';
if (function_exists('exec')) {
@exec('git rev-parse --abbrev-ref HEAD 2>&1', $branchOutput);
if (!empty($branchOutput[0]) && strpos($branchOutput[0], 'fatal') === false) {
$gitBranch = trim($branchOutput[0]);
}
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!$auth->verifyCsrf($_POST['csrf_token'] ?? '')) {
$message = 'Ongeldige CSRF token.';
$messageType = 'danger';
} else {
$root = $config['codepress_root'];
$cmd = 'cd ' . escapeshellarg($root) . ' && git pull origin ' . escapeshellarg($gitBranch) . ' 2>&1';
$outputLines = [];
$returnCode = -1;
if (function_exists('exec')) {
@exec($cmd, $outputLines, $returnCode);
$updateOutput = implode("\n", $outputLines);
} else {
$updateOutput = 'exec() is uitgeschakeld op de PHP server.';
$returnCode = 1;
}
if ($returnCode === 0) {
adminLog($config, 'info', $user['username'] . ' voerde een succesvolle systeemupdate uit');
$message = 'Systeem succesvol bijgewerkt naar de nieuwste versie!';
$messageType = 'success';
} else {
adminLog($config, 'warning', $user['username'] . ' probeerde een systeemupdate uit te voeren: ' . $updateOutput);
$message = 'Fout bij het bijwerken van het systeem. Bekijk de resultaten hieronder.';
$messageType = 'danger';
}
}
}
$route = 'update';
require __DIR__ . '/../admin/templates/layout.php';
}
// --- Frontmatter helpers ---
function parseFrontmatterField(string $content, string $key, string $default = ''): string
+1 -1
View File
@@ -111,7 +111,7 @@ if (!str_starts_with($path, '/-media/') && !str_starts_with($path, '/-assets/'))
$requestLogFile = dirname(__DIR__) . '/admin/storage/logs/requests.log';
$logger = new RequestLogger($requestLogFile);
$logger->log(
$_GET['page'] ?? $config['default_page'] ?? 'index',
$_GET['page'] ?? $cms->getEffectiveDefaultPage(),
RequestLogger::getClientIp(),
$_SERVER['HTTP_USER_AGENT'] ?? '',
$_SERVER['HTTP_REFERER'] ?? '',