From 213c4315c3a7aa86c2577853b99f74a513f9b02a Mon Sep 17 00:00:00 2001 From: sebres Date: Thu, 15 May 2014 19:41:00 +0200 Subject: [PATCH 1/3] fix a TypeError bugs like "Failed to execute ban jail 'pam-generic' action 'iptables-allports'" getAttempt returns not a list (numeric), so by call of both lambda we have a TypeError except; simplifying code; --- fail2ban/server/actions.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/fail2ban/server/actions.py b/fail2ban/server/actions.py index d5799ca1..dd68ac13 100644 --- a/fail2ban/server/actions.py +++ b/fail2ban/server/actions.py @@ -255,23 +255,20 @@ class Actions(JailThread, Mapping): if ticket != False: aInfo = CallingMap() bTicket = BanManager.createBanTicket(ticket) - aInfo["ip"] = bTicket.getIP() + ip = bTicket.getIP() + aInfo["ip"] = ip aInfo["failures"] = bTicket.getAttempt() aInfo["time"] = bTicket.getTime() aInfo["matches"] = "\n".join(bTicket.getMatches()) if self._jail.database is not None: - aInfo["ipmatches"] = lambda: "\n".join( - self._jail.database.getBansMerged( - ip=bTicket.getIP()).getMatches()) - aInfo["ipjailmatches"] = lambda: "\n".join( - self._jail.database.getBansMerged( - ip=bTicket.getIP(), jail=self._jail).getMatches()) - aInfo["ipfailures"] = lambda: "\n".join( - self._jail.database.getBansMerged( - ip=bTicket.getIP()).getAttempt()) - aInfo["ipjailfailures"] = lambda: "\n".join( - self._jail.database.getBansMerged( - ip=bTicket.getIP(), jail=self._jail).getAttempt()) + aInfo["ipmatches"] = lambda jail=self._jail: "\n".join( + jail.database.getBansMerged(ip=ip).getMatches()) + aInfo["ipjailmatches"] = lambda jail=self._jail: "\n".join( + jail.database.getBansMerged(ip=ip, jail=jail).getMatches()) + aInfo["ipfailures"] = lambda jail=self._jail: \ + jail.database.getBansMerged(ip=ip).getAttempt() + aInfo["ipjailfailures"] = lambda jail=self._jail: \ + jail.database.getBansMerged(ip=ip, jail=jail).getAttempt() if self.__banManager.addBanTicket(bTicket): logSys.notice("[%s] Ban %s" % (self._jail.name, aInfo["ip"])) for name, action in self._actions.iteritems(): From fc4b69a2822b83527e26a9f139ee9403e7ae23bb Mon Sep 17 00:00:00 2001 From: Steven Hiscocks Date: Thu, 15 May 2014 22:15:12 +0100 Subject: [PATCH 2/3] DOC: Update ChangeLog fix for ip{,jail}failures action tags --- ChangeLog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index 515c79d2..d4ea774a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -27,6 +27,8 @@ ver. 0.9.1 (2014/xx/xx) - better, faster, stronger * Database now returns persistent bans on restart (bantime < 0) * Recursive action tags now fully processed. Fixes issue with bsd-ipfw action + * Fixed TypeError with "ipfailures" and "ipjailfailures" action tags. + Thanks Serg G. Brester - New features: - Added monit filter thanks Jason H Martin. From 0ca97431a0dbebd16d5a8caa9521c7e6362f489d Mon Sep 17 00:00:00 2001 From: Steven Hiscocks Date: Thu, 15 May 2014 22:48:03 +0100 Subject: [PATCH 3/3] ENH: Clearer warning with lines which failed to decode correctly --- fail2ban/server/filter.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fail2ban/server/filter.py b/fail2ban/server/filter.py index fb5aeb3d..73233905 100644 --- a/fail2ban/server/filter.py +++ b/fail2ban/server/filter.py @@ -790,8 +790,10 @@ class FileContainer: try: line = line.decode(self.getEncoding(), 'strict') except UnicodeDecodeError: - logSys.warning("Error decoding line from '%s' with '%s': %s" % - (self.getFileName(), self.getEncoding(), `line`)) + logSys.warning( + "Error decoding line from '%s' with '%s'. Continuing " + " to process line ignoring invalid characters: %r" % + (self.getFileName(), self.getEncoding(), line)) if sys.version_info >= (3,): # In python3, must be decoded line = line.decode(self.getEncoding(), 'ignore') return line