Log `Repeal Ban` instead of `Unban` on stop action, jail or fail2ban, because the tickets are "unbanned" temporary (till restart);

closes gh-4057
pull/2537/merge
sebres 2025-08-19 11:37:01 +02:00
parent 4e22c20559
commit bdb5d99906
2 changed files with 7 additions and 7 deletions

View File

@ -640,12 +640,12 @@ class Actions(JailThread, Mapping):
If actions specified, don't flush list - just execute unban for If actions specified, don't flush list - just execute unban for
given actions (reload, obsolete resp. removed actions). given actions (reload, obsolete resp. removed actions).
""" """
log = True log = "Unban" if not stop else "Repeal Ban"
if actions is None: if actions is None:
logSys.debug(" Flush ban list") logSys.debug(" Flush ban list")
lst = self.banManager.flushBanList() lst = self.banManager.flushBanList()
else: 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) lst = iter(self.banManager)
cnt = 0 cnt = 0
# first we'll execute flush for actions supporting this operation: # 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) cnt, self.banManager.size(), self._jail.name)
return cnt return cnt
def __unBan(self, ticket, actions=None, log=True): def __unBan(self, ticket, actions=None, log="Unban"):
"""Unbans host corresponding to the ticket. """Unbans host corresponding to the ticket.
Executes the actions in order to unban the host given in the Executes the actions in order to unban the host given in the
@ -704,7 +704,7 @@ class Actions(JailThread, Mapping):
ip = ticket.getID() ip = ticket.getID()
aInfo = self._getActionInfo(ticket) aInfo = self._getActionInfo(ticket)
if log: 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(): for name, action in unbactions.items():
try: try:
logSys.debug("[%s] action %r: unban %s", self._jail.name, name, ip) logSys.debug("[%s] action %r: unban %s", self._jail.name, name, ip)

View File

@ -1125,9 +1125,9 @@ class Fail2banServerTest(Fail2banClientServerBase):
"3 ticket(s) in 'test-jail2", all=True, wait=MID_WAITTIME) "3 ticket(s) in 'test-jail2", all=True, wait=MID_WAITTIME)
# stop/start and unban/restore ban: # stop/start and unban/restore ban:
self.assertLogged( self.assertLogged(
"[test-jail2] Unban 192.0.2.4", "[test-jail2] Repeal Ban 192.0.2.4",
"[test-jail2] Unban 192.0.2.8", "[test-jail2] Repeal Ban 192.0.2.8",
"[test-jail2] Unban 192.0.2.9", "[test-jail2] Repeal Ban 192.0.2.9",
"Jail 'test-jail2' stopped", "Jail 'test-jail2' stopped",
"Jail 'test-jail2' started", "Jail 'test-jail2' started",
"[test-jail2] Restore Ban 192.0.2.4", "[test-jail2] Restore Ban 192.0.2.4",