From 6067579464f32e81f4810692cf465219ae6b2537 Mon Sep 17 00:00:00 2001 From: sebres Date: Thu, 27 Sep 2018 12:51:57 +0200 Subject: [PATCH] Fixed action parameter `timeout`: it is a time (integer), so avoid to convert it to string (for replacement); fix substituteRecursiveTags using auto-convert to string. Closes gh-2241. --- fail2ban/helpers.py | 2 +- fail2ban/server/action.py | 2 +- fail2ban/tests/servertestcase.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fail2ban/helpers.py b/fail2ban/helpers.py index 49a5ca47..c6da8f30 100644 --- a/fail2ban/helpers.py +++ b/fail2ban/helpers.py @@ -429,7 +429,7 @@ def substituteRecursiveTags(inptags, conditional='', m = tre_search(value, m.end()) continue # if calling map - be sure we've string: - if noRecRepl: repl = uni_string(repl) + if not isinstance(repl, basestring): repl = uni_string(repl) value = value.replace('<%s>' % rtag, repl) #logSys.log(5, 'value now: %s' % value) # increment reference count: diff --git a/fail2ban/server/action.py b/fail2ban/server/action.py index 10d1acd9..ef953eff 100644 --- a/fail2ban/server/action.py +++ b/fail2ban/server/action.py @@ -331,7 +331,7 @@ class CommandAction(ActionBase): if not name.startswith('_') and not self.__init and not callable(value): # special case for some parameters: if name in ('timeout', 'bantime'): - value = str(MyTime.str2seconds(value)) + value = MyTime.str2seconds(value) # parameters changed - clear properties and substitution cache: self.__properties = None self.__substCache.clear() diff --git a/fail2ban/tests/servertestcase.py b/fail2ban/tests/servertestcase.py index 425ab757..610a1a5d 100644 --- a/fail2ban/tests/servertestcase.py +++ b/fail2ban/tests/servertestcase.py @@ -661,11 +661,11 @@ class Transmitter(TransmitterBase): self.assertEqual( self.transm.proceed( ["set", self.jailName, "action", action, "timeout", "10"]), - (0, "10")) + (0, 10)) self.assertEqual( self.transm.proceed( ["get", self.jailName, "action", action, "timeout"]), - (0, "10")) + (0, 10)) self.assertEqual( self.transm.proceed(["set", self.jailName, "delaction", action]), (0, None))