Voeg IP-uitsluitingen toe aan configuratie: IP's niet meetellen in statistieken en overslaan bij beveiliging
This commit is contained in:
@@ -127,6 +127,19 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card shadow-sm mb-4">
|
||||
<div class="card-header">
|
||||
<i class="bi bi-eye-slash"></i> IP Uitsluitingen
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="mb-3">
|
||||
<label for="excluded_ips" class="form-label fw-bold">IP-adressen uitsluiten van statistieken en beveiliging</label>
|
||||
<textarea class="form-control font-monospace" id="excluded_ips" name="excluded_ips" rows="4" placeholder="Één IP per regel (bijv. 127.0.0.1)"><?= htmlspecialchars(implode("\n", $configData['analytics']['excluded_ips'] ?? [])) ?></textarea>
|
||||
<div class="form-text">Verzoeken van deze IP-adressen worden niet opgenomen in de statistieken en overgeslagen bij beveiligingscontroles (bot-detectie, rate limiting).</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary btn-lg">
|
||||
<i class="bi bi-check-lg"></i> Configuratie opslaan
|
||||
</button>
|
||||
|
||||
+3
-1
@@ -53,7 +53,8 @@ if (!file_exists($configJsonPath)) {
|
||||
'geoip_mmdb_path' => '',
|
||||
'geoip_api_url' => '',
|
||||
'geoip_api_key' => '',
|
||||
'retention_days' => 400
|
||||
'retention_days' => 400,
|
||||
'excluded_ips' => []
|
||||
]
|
||||
];
|
||||
@file_put_contents($configJsonPath, json_encode($defaultConfig, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||||
@@ -87,6 +88,7 @@ if (file_exists($configJsonPath)) {
|
||||
'geoip_api_url' => '',
|
||||
'geoip_api_key' => '',
|
||||
'retention_days' => 400,
|
||||
'excluded_ips' => [],
|
||||
],
|
||||
];
|
||||
foreach ($sectionDefaults as $section => $defaults) {
|
||||
|
||||
@@ -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