From 08394be35ec1c63803652c5a1bb4ab881c293660 Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Mon, 9 Dec 2024 15:44:00 +0200 Subject: [PATCH] Ratelimit whitelist add/remove --- app/classes/ratelimitrer.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/app/classes/ratelimitrer.php b/app/classes/ratelimitrer.php index 3e3d9f2..628bfd0 100644 --- a/app/classes/ratelimitrer.php +++ b/app/classes/ratelimitrer.php @@ -67,6 +67,30 @@ class RateLimiter { return ($ip & $mask) == $subnet; } + public function addToWhitelist($ip, $isNetwork = false) { + if ($isNetwork) { + if (!in_array($ip, $this->whitelistedNetworks)) { + $this->whitelistedNetworks[] = $ip; + } + } else { + if (!in_array($ip, $this->whitelistedIps)) { + $this->whitelistedIps[] = $ip; + } + } + } + + public function removeFromWhitelist($ip) { + $indexIp = array_search($ip, $this->whitelistedIps); + if ($indexIp !== false) { + unset($this->whitelistedIps[$indexIp]); + } + + $indexNetwork = array_search($ip, $this->whitelistedNetworks); + if ($indexNetwork !== false) { + unset($this->whitelistedNetworks[$indexNetwork]); + } + } + public function attempt($username, $ipAddress) { // Clean old attempts $this->clearOldAttempts();