From 799f5977c5cbfb89ab5df42fad74e8f6ebc8039a Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Thu, 28 Feb 2008 23:01:30 +0000 Subject: [PATCH] - Fixed "Feb 29" bug. Thanks to James Andrewartha who pointed this out. Thanks to Yaroslav Halchenko for the fix. git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_8@652 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- ChangeLog | 2 ++ server/datetemplate.py | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 9b0ae1e4..bb80ace2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -31,6 +31,8 @@ ver. 0.8.2 (2008/??/??) - stable - Print monitored files in status. - Create a PID file in /var/run/fail2ban/. Thanks to Julien Perez. +- Fixed "Feb 29" bug. Thanks to James Andrewartha who pointed + this out. Thanks to Yaroslav Halchenko for the fix. ver. 0.8.1 (2007/08/14) - stable ---------- diff --git a/server/datetemplate.py b/server/datetemplate.py index 443ad1ba..59dc4745 100644 --- a/server/datetemplate.py +++ b/server/datetemplate.py @@ -129,7 +129,14 @@ class DateStrptime(DateTemplate): except ValueError: # Try to convert date string to 'C' locale conv = self.convertLocale(dateMatch.group()) - date = list(time.strptime(conv, self.getPattern())) + try: + date = list(time.strptime(conv, self.getPattern())) + except ValueError: + # Try to add the current year to the pattern. Should fix + # the "Feb 29" issue. + conv += " %s" % MyTime.gmtime()[0] + pattern = "%s %%Y" % self.getPattern() + date = list(time.strptime(conv, pattern)) if date[0] < 2000: # There is probably no year field in the logs date[0] = MyTime.gmtime()[0]