Cleanup expired IP entries

main
Yasen Pramatarov 2025-01-03 18:08:59 +02:00
parent f4c008c65f
commit a076c28a30
1 changed files with 19 additions and 0 deletions

View File

@ -310,6 +310,25 @@ class RateLimiter {
return $stmt->fetchAll(PDO::FETCH_ASSOC); return $stmt->fetchAll(PDO::FETCH_ASSOC);
} }
public function cleanupExpiredEntries() {
try {
// Remove expired blacklist entries
$stmt = $this->db->prepare("DELETE FROM {$this->blacklistTable}
WHERE expiry_time IS NOT NULL AND expiry_time < NOW()");
$stmt->execute();
// Clean old login attempts
$stmt = $this->db->prepare("DELETE FROM {$this->tableName}
WHERE attempted_at < DATE_SUB(NOW(), INTERVAL ? MINUTE)");
$stmt->execute([$this->decayMinutes]);
return true;
} catch (Exception $e) {
$this->log->insertLog(0, "Failed to cleanup expired entries: " . $e->getMessage(), 'system');
return false;
}
}
public function attempt($username, $ipAddress) { public function attempt($username, $ipAddress) {
// Skip rate limiting for whitelisted IPs // Skip rate limiting for whitelisted IPs
if ($this->isIpWhitelisted($ipAddress)) { if ($this->isIpWhitelisted($ipAddress)) {