'image/jpeg', 'jpeg' => 'image/jpeg', 'png' => 'image/png', 'gif' => 'image/gif', 'webp' => 'image/webp', 'svg' => 'image/svg+xml', 'pdf' => 'application/pdf', 'zip' => 'application/zip', 'mp4' => 'video/mp4', 'webm' => 'video/webm', 'ogg' => 'video/ogg', 'mp3' => 'audio/mpeg', 'wav' => 'audio/wav', 'css' => 'text/css', 'js' => 'application/javascript', ]; if (strpos($path, '/-media/') === 0) { $relative = ltrim(substr($path, 7), '/'); $root = realpath(__DIR__ . '/..'); $filePath = $root . '/content/' . $relative; if (strpos($filePath, $root . '/content') === 0) { $ext = strtolower(pathinfo($filePath, PATHINFO_EXTENSION)); if (in_array($ext, $allowedExt) && file_exists($filePath) && !is_dir($filePath)) { if (isset($mimeTypes[$ext])) { header('Content-Type: ' . $mimeTypes[$ext]); } readfile($filePath); exit; } } http_response_code(404); echo '
Access denied.
'; exit; } // Load RequestLogger for IP & request logging require_once __DIR__ . '/../cms/core/class/RequestLogger.php'; // Execute security checks & rate limiting $clientIp = RequestLogger::getClientIp(); $secSettings = $config['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, ]; $userAgent = $_SERVER['HTTP_USER_AGENT'] ?? ''; $isAllowedIp = in_array($clientIp, $secSettings['allowed_ips'] ?? [], true); $requestStatus = 'ok'; if (!$isAllowedIp) { // 1. IP Blocklist if (in_array($clientIp, $secSettings['blocked_ips'] ?? [], true)) { $requestStatus = 'blocked:ip'; } // 2. BotGuard User-Agent check if ($requestStatus === 'ok') { $botBlockReason = BotGuard::shouldBlock($userAgent, $secSettings); if ($botBlockReason !== null) { $requestStatus = $botBlockReason; } } // 3. Rate Limiting per IP if ($requestStatus === 'ok' && !empty($secSettings['rate_limit_enabled'])) { $cacheDir = dirname(__DIR__) . '/admin/storage/cache'; $rateLimiter = new RateLimiter( (int)($secSettings['rate_limit_max'] ?? 60), (int)($secSettings['rate_limit_window'] ?? 60), new FileCache($cacheDir) ); if (!$rateLimiter->isAllowed($clientIp)) { $requestStatus = 'blocked:ratelimit'; } } } // Instantiate CMS instance $cms = new CodePressCMS($config); // Log page view (not for media/assets) if (!str_starts_with($path, '/-media/') && !str_starts_with($path, '/-assets/')) { if (session_status() === PHP_SESSION_NONE) { @session_start(); } $loggedInUser = $_SESSION['admin_user'] ?? 'Gast'; $requestLogFile = dirname(__DIR__) . '/admin/storage/logs/requests.log'; $logger = new RequestLogger($requestLogFile); $logger->log( $_GET['page'] ?? $cms->getEffectiveDefaultPage(), $clientIp, $userAgent, $_SERVER['HTTP_REFERER'] ?? '', $loggedInUser, $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '', $requestStatus ); } // Block request if status is not ok if ($requestStatus !== 'ok') { if ($requestStatus === 'blocked:ratelimit') { http_response_code(429); header('Retry-After: ' . (int)($secSettings['rate_limit_window'] ?? 60)); echo 'Probeer het over een minuut opnieuw.
'; } else { http_response_code(403); echo 'Toegang geweigerd.
'; } exit; } $cms->render();