mirror of https://github.com/fail2ban/fail2ban
- 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-b1dcaea8d6050.x
parent
9f5f6812f5
commit
f3df224ec4
|
@ -28,16 +28,39 @@ import re, time
|
||||||
|
|
||||||
from datetemplate import DateTemplate
|
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):
|
class DateStrptime(DateTemplate):
|
||||||
|
|
||||||
|
TABLE = dict()
|
||||||
|
TABLE["Oct"] = ["Okt"]
|
||||||
|
TABLE["Dec"] = ["Dez"]
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
DateTemplate.__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):
|
def getDate(self, line):
|
||||||
date = None
|
date = None
|
||||||
dateMatch = self.matchDate(line)
|
dateMatch = self.matchDate(line)
|
||||||
if dateMatch:
|
if dateMatch:
|
||||||
|
try:
|
||||||
|
# Try first with 'C' locale
|
||||||
date = list(time.strptime(dateMatch.group(), self.getPattern()))
|
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:
|
if date[0] < 2000:
|
||||||
# There is probably no year field in the logs
|
# There is probably no year field in the logs
|
||||||
date[0] = time.gmtime()[0]
|
date[0] = time.gmtime()[0]
|
||||||
|
|
Loading…
Reference in New Issue