Voeg IP-uitsluitingen toe aan configuratie: IP's niet meetellen in statistieken en overslaan bij beveiliging
This commit is contained in:
@@ -754,6 +754,19 @@ function handleConfig(AdminAuth $auth, array $config): void
|
||||
$configData['features']['search_enabled'] = !empty($_POST['feature_search']);
|
||||
$configData['features']['breadcrumbs_enabled'] = !empty($_POST['feature_breadcrumbs']);
|
||||
|
||||
$parseLines = function($text) {
|
||||
$lines = explode("\n", str_replace("\r", "", $text));
|
||||
$clean = [];
|
||||
foreach ($lines as $line) {
|
||||
$item = trim($line);
|
||||
if ($item !== '') {
|
||||
$clean[] = $item;
|
||||
}
|
||||
}
|
||||
return array_values(array_unique($clean));
|
||||
};
|
||||
$configData['analytics']['excluded_ips'] = $parseLines($_POST['excluded_ips'] ?? '');
|
||||
|
||||
file_put_contents($configJson, json_encode($configData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||||
adminLog($config, 'info', $user['username'] . ' wijzigde site configuratie');
|
||||
$message = 'Configuratie opgeslagen.';
|
||||
|
||||
+5
-2
@@ -112,7 +112,10 @@ $secSettings = $config['security'] ?? [
|
||||
];
|
||||
|
||||
$userAgent = $_SERVER['HTTP_USER_AGENT'] ?? '';
|
||||
$isAllowedIp = in_array($clientIp, $secSettings['allowed_ips'] ?? [], true);
|
||||
$analyticsSettings = $config['analytics'] ?? [];
|
||||
$excludedIps = $analyticsSettings['excluded_ips'] ?? [];
|
||||
$isAllowedIp = in_array($clientIp, $secSettings['allowed_ips'] ?? [], true)
|
||||
|| in_array($clientIp, $excludedIps, true);
|
||||
$requestStatus = 'ok';
|
||||
|
||||
if (!$isAllowedIp) {
|
||||
@@ -182,7 +185,7 @@ if (!str_starts_with($path, '/-media/') && !str_starts_with($path, '/-assets/'))
|
||||
);
|
||||
|
||||
// Record aggregated statistics
|
||||
if (!empty($analyticsSettings['enabled'])) {
|
||||
if (!empty($analyticsSettings['enabled']) && !in_array($clientIp, $excludedIps, true)) {
|
||||
$analytics = new Analytics($analyticsSettings);
|
||||
$analytics->record($currentPage, $storedIp, $userAgent, $referrer, $geoCountry, $requestStatus);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user