Browse Source

- First attempt at solving bug #1457620

- Always use the 'C' locale and try to convert date representation like month names to this locale

git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@372 a942ae1a-1317-0410-a47c-b1dcaea8d605
0.x
Cyril Jaquier 18 years ago
parent
commit
f3df224ec4
  1. 25
      server/datestrptime.py

25
server/datestrptime.py

@ -28,16 +28,39 @@ import re, time
from datetemplate import DateTemplate
##
# Use strptime() to parse a date. Our current locale is the 'C'
# one because we do not set the locale explicitly. This is POSIX
# standard.
class DateStrptime(DateTemplate):
TABLE = dict()
TABLE["Oct"] = ["Okt"]
TABLE["Dec"] = ["Dez"]
def __init__(self):
DateTemplate.__init__(self)
@staticmethod
def convertLocale(date):
for t in DateStrptime.TABLE:
for m in DateStrptime.TABLE[t]:
if date.find(m) >= 0:
return date.replace(m, t)
return date
def getDate(self, line):
date = None
dateMatch = self.matchDate(line)
if dateMatch:
date = list(time.strptime(dateMatch.group(), self.getPattern()))
try:
# Try first with 'C' locale
date = list(time.strptime(dateMatch.group(), self.getPattern()))
except ValueError:
# Try to convert date string to 'C' locale
conv = self.convertLocale(dateMatch.group())
date = list(time.strptime(conv, self.getPattern()))
if date[0] < 2000:
# There is probably no year field in the logs
date[0] = time.gmtime()[0]

Loading…
Cancel
Save