From 17da4943df0716b394e2b40a973357fa0b423183 Mon Sep 17 00:00:00 2001 From: sebres Date: Wed, 26 Sep 2018 21:00:51 +0200 Subject: [PATCH 1/2] use short log-names for special pure numeric log-level (e.g. "Level 25" could be truncated by short formats) --- fail2ban/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fail2ban/__init__.py b/fail2ban/__init__.py index 317f53e7..fa6dcf77 100644 --- a/fail2ban/__init__.py +++ b/fail2ban/__init__.py @@ -79,3 +79,10 @@ logging.handlers.SysLogHandler.priority_map['NOTICE'] = 'notice' from time import strptime # strptime thread safety hack-around - http://bugs.python.org/issue7980 strptime("2012", "%Y") + +# short names for pure numeric log-level ("Level 25" could be truncated by short formats): +def _init(): + for i in xrange(50): + if logging.getLevelName(i).startswith('Level'): + logging.addLevelName(i, '#%02d-Lev.' % i) +_init() From 6067579464f32e81f4810692cf465219ae6b2537 Mon Sep 17 00:00:00 2001 From: sebres Date: Thu, 27 Sep 2018 12:51:57 +0200 Subject: [PATCH 2/2] 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))