Files
CodePress/cms/core/config.php
T
E.Noorlander d9ea2eee47 v2.6.5 (Lyra): Dynamische pad-resolutie, WordPress-stijl docblocks, security-fix wachtwoord, git-historie schoon
- Bug: dashboard toonde 0 content (AdminPluginAPI::getContentDir() gaf relatief pad terug zonder normalisatie)
- Dynamische pad-resolutie: PluginAPIInterface uitgebreid met getProjectRoot/getContentDir/getPluginsDir/getVersionInfo; CMSAPI en AdminPluginAPI implementeren deze universeel
- public/index.php media-serving gebruikt $config['content_dir'] i.p.v. hardcoded /content
- Navigation en Logs plugins halen paden via de API i.p.v. hardcoded dirname(__DIR__)
- WordPress-stijl docblocks toegevoegd voor alle classes, methods, properties en functies (~450 docblocks, @since 2.6.5)
- Security: hardcoded plaintext-wachtwoord 'admin' verwijderd uit AdminAuth.php; bij eerste installatie wordt een cryptografisch veilig wachtwoord gegenereerd (random_bytes, 16 tekens) en eenmalig op het inlogscherm getoond
- Security: git-geschiedenis schoongemaakt (admin.json, admin.json.example, admin-console/config/admin.json verwijderd uit alle commits; filter-branch over alle branches + tags, gc --prune --aggressive)
- README.md, README.en.md, AGENTS.md bijgewerkt
- Test-scripts bijgewerkt naar clean-URL structuur + actuele ARIA-waarden
- Versie verhoogd naar 2.6.5
- Tests: pentest 29/29, WCAG 25/25, functioneel 16/16, enhanced 25/25
2026-08-27 09:05:51 +00:00

214 lines
7.3 KiB
PHP

<?php
/**
* Configuratie-loader voor CodePress CMS.
*
* Laadt config.json (of maakt deze aan op basis van config.json.example of
* een ingebouwde standaardconfiguratie), voegt ontbrekende secties
* (security, analytics, logging) samen met defaults, converteert relatieve
* content_dir-paden naar absoluut, laadt de actieve theme-configuratie en
* returnt de uiteindelijke configuratie-array. Bij falen volgt een
* minimale fallback-configuratie.
*
* @since 2.6.5
* @package CodePress
*/
// Simple configuration loader
$configJsonPath = __DIR__ . '/../../config.json';
$configExamplePath = __DIR__ . '/../../config.json.example';
/**
* config.json automatisch aanmaken als deze nog niet bestaat.
*
* Kopieert config.json.example indien aanwezig; anders wordt een ingebouwde
* standaardconfiguratie weggeschreven.
*
* @since 2.6.5
*/
// Auto-create config.json if it does not exist
if (!file_exists($configJsonPath)) {
if (file_exists($configExamplePath)) {
@copy($configExamplePath, $configJsonPath);
} else {
$defaultConfig = [
'site_title' => 'CodePress',
'content_dir' => 'content',
'active_theme' => 'default',
'default_page' => 'auto',
'language' => [
'default' => 'nl',
'available' => ['nl', 'en']
],
'seo' => [
'description' => 'CodePress CMS - Lightweight file-based content management system',
'keywords' => 'cms, php, content management, file-based'
],
'author' => [
'name' => 'E. Noorlander',
'website' => 'noorlander.info',
'git' => ''
],
'show_version' => true,
'enabled_plugins' => ['HTMLBlock', 'Navigation'],
'features' => [
'auto_link_pages' => true,
'search_enabled' => true,
'breadcrumbs_enabled' => true
],
'security' => [
'block_ai_bots' => true,
'block_scrapers' => true,
'block_search_engines' => false,
'block_empty_user_agent' => true,
'rate_limit_enabled' => true,
'rate_limit_max' => 60,
'rate_limit_window' => 60,
'custom_blocked_agents' => [],
'blocked_ips' => [],
'allowed_ips' => []
],
'analytics' => [
'enabled' => true,
'anonymize_ip' => false,
'geoip_provider' => 'local',
'geoip_mmdb_path' => '',
'geoip_api_url' => '',
'geoip_api_key' => '',
'retention_days' => 400,
'excluded_ips' => [
'192.168.0.0/16',
'10.0.0.0/8',
'172.16.0.0/12',
'127.0.0.1',
'::1'
]
],
'logging' => [
'enabled' => true,
'driver' => 'sqlite',
'syslog_host' => '',
'syslog_port' => 514,
'syslog_facility' => 'local0',
'syslog_ident' => 'codepress',
'events' => [
'admin' => true,
'requests' => true,
'errors' => true,
'security' => true,
'content' => true,
'system' => true
]
]
];
@file_put_contents($configJsonPath, json_encode($defaultConfig, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
}
}
/**
* config.json inladen en ontbrekende secties aanvullen met defaults.
*
* Voegt default-waarden samen voor security, analytics en logging,
* garandeert de excluded_ips-standaardlijst en converteert relatieve
* content_dir-paden naar absoluut.
*
* @since 2.6.5
*/
if (file_exists($configJsonPath)) {
$jsonContent = file_get_contents($configJsonPath);
$config = json_decode($jsonContent, true);
if (json_last_error() === JSON_ERROR_NONE && is_array($config)) {
// Merge defaults for sections that may be missing in existing installs
$sectionDefaults = [
'security' => [
'block_ai_bots' => true,
'block_scrapers' => true,
'block_search_engines' => false,
'block_empty_user_agent' => true,
'rate_limit_enabled' => true,
'rate_limit_max' => 60,
'rate_limit_window' => 60,
'custom_blocked_agents' => [],
'blocked_ips' => [],
'allowed_ips' => [],
],
'analytics' => [
'enabled' => true,
'anonymize_ip' => false,
'geoip_provider' => 'local',
'geoip_mmdb_path' => '',
'geoip_api_url' => '',
'geoip_api_key' => '',
'retention_days' => 400,
'excluded_ips' => [
'192.168.0.0/16',
'10.0.0.0/8',
'172.16.0.0/12',
'127.0.0.1',
'::1'
],
],
'logging' => [
'enabled' => true,
'driver' => 'sqlite',
'syslog_host' => '',
'syslog_port' => 514,
'syslog_facility' => 'local0',
'syslog_ident' => 'codepress',
'events' => [
'admin' => true,
'requests' => true,
'errors' => true,
'security' => true,
'content' => true,
'system' => true
],
],
];
foreach ($sectionDefaults as $section => $defaults) {
$config[$section] = array_merge($defaults, is_array($config[$section] ?? null) ? $config[$section] : []);
}
// Ensure the private/loopback IP defaults are present when the list is empty
if (empty($config['analytics']['excluded_ips'])) {
$config['analytics']['excluded_ips'] = $sectionDefaults['analytics']['excluded_ips'];
}
// Convert relative paths to absolute
$projectRoot = __DIR__ . '/../../';
if (isset($config['content_dir']) && strpos($config['content_dir'], '/') !== 0) {
$config['content_dir'] = $projectRoot . $config['content_dir'];
}
/**
* Actieve theme-configuratie laden vanuit theme.json.
*
* @since 2.6.5
*/
// Load active theme
$activeTheme = $config['active_theme'] ?? 'default';
$themeDir = __DIR__ . '/../../themes/' . $activeTheme;
$config['theme_dir'] = $themeDir;
$themeFile = $themeDir . '/theme.json';
if (file_exists($themeFile)) {
$themeConfig = json_decode(file_get_contents($themeFile), true);
$config['theme'] = $themeConfig;
} else {
$config['theme'] = [];
}
return $config;
}
}
/**
* Minimale fallback-configuratie wanneer config.json niet geladen kon worden.
*
* @since 2.6.5
*/
// Fallback to minimal config
return [
'site_title' => 'CodePress',
'content_dir' => __DIR__ . '/../../content',
'default_page' => 'auto'
];