From 66f62efcbb904572935e0197487a228f2356ba15 Mon Sep 17 00:00:00 2001
From: Piero Toffanin <pt@masseranolabs.com>
Date: Wed, 24 Nov 2021 12:49:07 -0500
Subject: [PATCH] Tweak ban logic, update config description

---
 app/flood.py | 5 +++--
 app/main.py  | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/app/flood.py b/app/flood.py
index 4c458c7..d050aa9 100644
--- a/app/flood.py
+++ b/app/flood.py
@@ -9,6 +9,7 @@ threshold = -1
 
 def forgive_banned():
     global banned
+    global threshold
 
     clear_list = []
 
@@ -16,7 +17,7 @@ def forgive_banned():
         if banned[ip] <= 0:
             clear_list.append(ip)
         else:
-            banned[ip] -= 1
+            banned[ip] = min(threshold, banned[ip]) - 1
 
     for ip in clear_list:
         del banned[ip]
@@ -29,7 +30,7 @@ def setup(violations_threshold=100):
     threshold = violations_threshold
 
     scheduler = BackgroundScheduler()
-    scheduler.add_job(func=forgive_banned, trigger="interval", minutes=5)
+    scheduler.add_job(func=forgive_banned, trigger="interval", minutes=60)
     scheduler.start()
 
     # Shut down the scheduler when exiting the app
diff --git a/app/main.py b/app/main.py
index e8b6878..4905865 100644
--- a/app/main.py
+++ b/app/main.py
@@ -40,7 +40,7 @@ def main():
         default=DEFARGS['REQ_FLOOD_THRESHOLD'],
         type=int,
         metavar="<number>",
-        help="Set the maximum number of request limit offences per 4 weeks that a client can exceed before being banned. (%(default)s)",
+        help="Set the maximum number of request limit offences that a client can exceed before being banned. (%(default)s)",
     )
     parser.add_argument(
         "--batch-limit",
-- 
GitLab