From bdb5d999068c8ef9a33bf3f8fbae0da512d056c9 Mon Sep 17 00:00:00 2001 From: sebres Date: Tue, 19 Aug 2025 11:37:01 +0200 Subject: [PATCH] Log `Repeal Ban` instead of `Unban` on stop action, jail or fail2ban, because the tickets are "unbanned" temporary (till restart); closes gh-4057 --- fail2ban/server/actions.py | 8 ++++---- fail2ban/tests/fail2banclienttestcase.py | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/fail2ban/server/actions.py b/fail2ban/server/actions.py index 26e80107..581c5724 100644 --- a/fail2ban/server/actions.py +++ b/fail2ban/server/actions.py @@ -640,12 +640,12 @@ class Actions(JailThread, Mapping): If actions specified, don't flush list - just execute unban for given actions (reload, obsolete resp. removed actions). """ - log = True + log = "Unban" if not stop else "Repeal Ban" if actions is None: logSys.debug(" Flush ban list") lst = self.banManager.flushBanList() else: - log = False # don't log "[jail] Unban ..." if removing actions only. + log = None # don't log "[jail] Unban ..." if removing actions only. lst = iter(self.banManager) cnt = 0 # first we'll execute flush for actions supporting this operation: @@ -686,7 +686,7 @@ class Actions(JailThread, Mapping): cnt, self.banManager.size(), self._jail.name) return cnt - def __unBan(self, ticket, actions=None, log=True): + def __unBan(self, ticket, actions=None, log="Unban"): """Unbans host corresponding to the ticket. Executes the actions in order to unban the host given in the @@ -704,7 +704,7 @@ class Actions(JailThread, Mapping): ip = ticket.getID() aInfo = self._getActionInfo(ticket) if log: - logSys.notice("[%s] Unban %s", self._jail.name, ip) + logSys.notice("[%s] %s %s", self._jail.name, log, ip) for name, action in unbactions.items(): try: logSys.debug("[%s] action %r: unban %s", self._jail.name, name, ip) diff --git a/fail2ban/tests/fail2banclienttestcase.py b/fail2ban/tests/fail2banclienttestcase.py index b3509739..c15e4978 100644 --- a/fail2ban/tests/fail2banclienttestcase.py +++ b/fail2ban/tests/fail2banclienttestcase.py @@ -1125,9 +1125,9 @@ class Fail2banServerTest(Fail2banClientServerBase): "3 ticket(s) in 'test-jail2", all=True, wait=MID_WAITTIME) # stop/start and unban/restore ban: self.assertLogged( - "[test-jail2] Unban 192.0.2.4", - "[test-jail2] Unban 192.0.2.8", - "[test-jail2] Unban 192.0.2.9", + "[test-jail2] Repeal Ban 192.0.2.4", + "[test-jail2] Repeal Ban 192.0.2.8", + "[test-jail2] Repeal Ban 192.0.2.9", "Jail 'test-jail2' stopped", "Jail 'test-jail2' started", "[test-jail2] Restore Ban 192.0.2.4",