Enhances add to whitelist

main
Yasen Pramatarov 2024-12-21 17:14:31 +02:00
parent 8d0518c7ff
commit 9b8f92f2eb
1 changed files with 30 additions and 9 deletions

View File

@ -89,16 +89,37 @@ class RateLimiter {
} }
// Add to whitelist // Add to whitelist
public function addToWhitelist($ip, $isNetwork = false, $description = '', $createdBy = 'system') { public function addToWhitelist($ip, $isNetwork = false, $description = '', $createdBy = 'system', $userId = null) {
$stmt = $this->db->prepare("INSERT INTO {$this->whitelistTable} try {
(ip_address, is_network, description, created_by) $stmt = $this->db->prepare("INSERT INTO {$this->whitelistTable}
VALUES (?, ?, ?, ?) (ip_address, is_network, description, created_by)
ON DUPLICATE KEY UPDATE VALUES (?, ?, ?, ?)
is_network = VALUES(is_network), ON DUPLICATE KEY UPDATE
description = VALUES(description), is_network = VALUES(is_network),
created_by = VALUES(created_by)"); description = VALUES(description),
created_by = VALUES(created_by)");
return $stmt->execute([$ip, $isNetwork, $description, $createdBy]); $result = $stmt->execute([$ip, $isNetwork, $description, $createdBy]);
if ($result) {
$logMessage = sprintf(
'IP Whitelist: Added %s "%s" by %s. Description: %s',
$isNetwork ? 'network' : 'IP',
$ip,
$createdBy,
$description
);
$this->log->insertLog($userId ?? 0, $logMessage, 'system');
}
return $result;
} catch (Exception $e) {
if ($userId) {
$this->log->insertLog($userId, "IP Whitelist: Failed to add {$ip}: " . $e->getMessage(), 'system');
}
return false;
}
} }
// Remove from whitelist // Remove from whitelist