diff --git a/fail2ban/client/beautifier.py b/fail2ban/client/beautifier.py index 308cb035..7b27e92f 100644 --- a/fail2ban/client/beautifier.py +++ b/fail2ban/client/beautifier.py @@ -89,45 +89,45 @@ class Beautifier: msg = "\n".join(msg) elif inC[1] == "syslogsocket": msg = "Current syslog socket is:\n" - msg = msg + "`- " + response + msg += "`- " + response elif inC[1] == "logtarget": msg = "Current logging target is:\n" - msg = msg + "`- " + response + msg += "`- " + response elif inC[1:2] == ['loglevel']: msg = "Current logging level is " if response == 1: - msg = msg + "ERROR" + msg += "ERROR" elif response == 2: - msg = msg + "WARN" + msg += "WARN" elif response == 3: - msg = msg + "INFO" + msg += "INFO" elif response == 4: - msg = msg + "DEBUG" + msg += "DEBUG" else: - msg = msg + repr(response) + msg += repr(response) elif inC[1] == "dbfile": if response is None: msg = "Database currently disabled" else: msg = "Current database file is:\n" - msg = msg + "`- " + response + msg += "`- " + response elif inC[1] == "dbpurgeage": if response is None: msg = "Database currently disabled" else: msg = "Current database purge age is:\n" - msg = msg + "`- %iseconds" % response + msg += "`- %iseconds" % response elif inC[2] in ("logpath", "addlogpath", "dellogpath"): if len(response) == 0: msg = "No file is currently monitored" else: msg = "Current monitored log file(s):\n" for path in response[:-1]: - msg = msg + "|- " + path + "\n" - msg = msg + "`- " + response[len(response)-1] + msg += "|- " + path + "\n" + msg += "`- " + response[-1] elif inC[2] == "logencoding": msg = "Current log encoding is set to:\n" - msg = msg + response + msg += response elif inC[2] in ("journalmatch", "addjournalmatch", "deljournalmatch"): if len(response) == 0: msg = "No journal match filter set" @@ -137,19 +137,19 @@ class Beautifier: elif inC[2] == "datepattern": msg = "Current date pattern set to: " if response is None: - msg = msg + "Not set/required" + msg += "Not set/required" elif response[0] is None: - msg = msg + "%s" % response[1] + msg += "%s" % response[1] else: - msg = msg + "%s (%s)" % response + msg += "%s (%s)" % response elif inC[2] in ("ignoreip", "addignoreip", "delignoreip"): if len(response) == 0: msg = "No IP address/network is ignored" else: msg = "These IP addresses/networks are ignored:\n" for ip in response[:-1]: - msg = msg + "|- " + ip + "\n" - msg = msg + "`- " + response[len(response)-1] + msg += "|- " + ip + "\n" + msg += "`- " + response[-1] elif inC[2] in ("failregex", "addfailregex", "delfailregex", "ignoreregex", "addignoreregex", "delignoreregex"): if len(response) == 0: @@ -157,10 +157,10 @@ class Beautifier: else: msg = "The following regular expression are defined:\n" c = 0 - for ip in response[:-1]: - msg = msg + "|- [" + str(c) + "]: " + ip + "\n" + for l in response[:-1]: + msg += "|- [" + str(c) + "]: " + l + "\n" c += 1 - msg = msg + "`- [" + str(c) + "]: " + response[len(response)-1] + msg += "`- [" + str(c) + "]: " + response[-1] elif inC[2] == "actions": if len(response) == 0: msg = "No actions for jail %s" % inC[1] @@ -187,7 +187,7 @@ class Beautifier: logSys.warning("Beautifier error. Please report the error") logSys.error("Beautify " + repr(response) + " with " + repr(self.__inputCmd) + " failed") - msg = msg + repr(response) + msg += repr(response) return msg def beautifyError(self, response): diff --git a/fail2ban/tests/clientbeautifiertestcase.py b/fail2ban/tests/clientbeautifiertestcase.py index 6fc63e6f..0390a8ff 100644 --- a/fail2ban/tests/clientbeautifiertestcase.py +++ b/fail2ban/tests/clientbeautifiertestcase.py @@ -201,8 +201,10 @@ class BeautifierTest(unittest.TestCase): IPAddr("::ffff:10.0.2.1") ] output = "These IP addresses/networks are ignored:\n" - output += "|- 127.0.0.0/8\n|- ::1\n" - output += "|- 2001:db8::/32\n`- 10.0.2.1" + output += "|- 127.0.0.0/8\n" + output += "|- ::1\n" + output += "|- 2001:db8::/32\n" + output += "`- 10.0.2.1" self.assertEqual(self.b.beautify(response), output) def testFailRegex(self): diff --git a/fail2ban/tests/filtertestcase.py b/fail2ban/tests/filtertestcase.py index 2d82ab6f..e8bd2e37 100644 --- a/fail2ban/tests/filtertestcase.py +++ b/fail2ban/tests/filtertestcase.py @@ -1457,6 +1457,11 @@ class DNSUtilsNetworkTests(unittest.TestCase): self.assertEqual(str(IPAddr('2606:2800:220:1:248:1893:25c8:0/120')), '2606:2800:220:1:248:1893:25c8:0/120') self.assertEqual(IPAddr('2606:2800:220:1:248:1893:25c8:0/120').ntoa, '2606:2800:220:1:248:1893:25c8:0/120') + def testIPAddr_CIDR_Repr(self): + self.assertEqual(["127.0.0.0/8", "::/32", "2001:db8::/32"], + [IPAddr("127.0.0.0", 8), IPAddr("::1", 32), IPAddr("2001:db8::", 32)] + ) + def testIPAddr_CompareDNS(self): ips = IPAddr('example.com') self.assertTrue(IPAddr("93.184.216.34").isInNet(ips))