fixes a small blemish by output in beautifier;

command "unban" returns a count of tickets that were flushed
pull/1725/head
sebres 2017-03-17 10:03:34 +01:00
parent da808fe67b
commit 93ec9e01d4
3 changed files with 18 additions and 5 deletions

View File

@ -89,6 +89,8 @@ class Beautifier:
val = " ".join(map(str, res1[1])) if isinstance(res1[1], list) else res1[1] val = " ".join(map(str, res1[1])) if isinstance(res1[1], list) else res1[1]
msg.append("%s %s:\t%s" % (prefix1, res1[0], val)) msg.append("%s %s:\t%s" % (prefix1, res1[0], val))
msg = "\n".join(msg) msg = "\n".join(msg)
elif len(inC) < 2:
pass # to few cmd args for below
elif inC[1] == "syslogsocket": elif inC[1] == "syslogsocket":
msg = "Current syslog socket is:\n" msg = "Current syslog socket is:\n"
msg += "`- " + response msg += "`- " + response
@ -110,6 +112,8 @@ class Beautifier:
else: else:
msg = "Current database purge age is:\n" msg = "Current database purge age is:\n"
msg += "`- %iseconds" % response msg += "`- %iseconds" % response
elif len(inC) < 3:
pass # to few cmd args for below
elif inC[2] in ("logpath", "addlogpath", "dellogpath"): elif inC[2] in ("logpath", "addlogpath", "dellogpath"):
if len(response) == 0: if len(response) == 0:
msg = "No file is currently monitored" msg = "No file is currently monitored"
@ -178,7 +182,8 @@ class Beautifier:
msg += ", ".join(response) msg += ", ".join(response)
except Exception: except Exception:
logSys.warning("Beautifier error. Please report the error") logSys.warning("Beautifier error. Please report the error")
logSys.error("Beautify %r with %r failed", response, self.__inputCmd) logSys.error("Beautify %r with %r failed", response, self.__inputCmd,
exc_info=logSys.getEffectiveLevel()<=logging.DEBUG)
msg = repr(msg) + repr(response) msg = repr(msg) + repr(response)
return msg return msg

View File

@ -108,11 +108,11 @@ class Transmitter:
value = command[1:] value = command[1:]
# if all ips: # if all ips:
if len(value) == 1 and value[0] == "--all": if len(value) == 1 and value[0] == "--all":
self.__server.setUnbanIP() return self.__server.setUnbanIP()
return cnt = 0
for value in value: for value in value:
self.__server.setUnbanIP(None, value) cnt += self.__server.setUnbanIP(None, value)
return None return cnt
elif command[0] == "echo": elif command[0] == "echo":
return command[1:] return command[1:]
elif command[0] == "sleep": elif command[0] == "sleep":

View File

@ -1075,6 +1075,14 @@ class Fail2banServerTest(Fail2banClientServerBase):
"[test-jail1] Ban 192.0.2.4", all=True "[test-jail1] Ban 192.0.2.4", all=True
) )
# unban all (just to test command, already empty - nothing to unban):
self.pruneLog("[test-phase 7b]")
self.execSuccess(startparams,
"--async", "unban", "--all")
self.assertLogged(
"Flush ban list",
"Unbanned 0, 0 ticket(s) in 'test-jail1'", all=True)
# backend-switch (restart instead of reload): # backend-switch (restart instead of reload):
self.pruneLog("[test-phase 8a]") self.pruneLog("[test-phase 8a]")
_write_jail_cfg(enabled=[1], backend="xxx-unknown-backend-zzz") _write_jail_cfg(enabled=[1], backend="xxx-unknown-backend-zzz")