mirror of https://github.com/fail2ban/fail2ban
- Catch IOError when file can not be read
- Do not convert line to latin-1 but to utf8 git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@374 a942ae1a-1317-0410-a47c-b1dcaea8d6050.x
parent
f12d0fab61
commit
3ca397922d
|
@ -276,8 +276,14 @@ class Filter(JailThread):
|
||||||
try:
|
try:
|
||||||
self.crtFilename = filename
|
self.crtFilename = filename
|
||||||
self.crtHandler = open(filename)
|
self.crtHandler = open(filename)
|
||||||
|
logSys.debug("Opened " + filename)
|
||||||
|
return True
|
||||||
except OSError:
|
except OSError:
|
||||||
logSys.error("Unable to open " + filename)
|
logSys.error("Unable to open " + filename)
|
||||||
|
except IOError:
|
||||||
|
logSys.error("Unable to read " + filename +
|
||||||
|
". Please check permissions")
|
||||||
|
return False
|
||||||
|
|
||||||
##
|
##
|
||||||
# Close the log file.
|
# Close the log file.
|
||||||
|
@ -321,18 +327,21 @@ class Filter(JailThread):
|
||||||
|
|
||||||
def getFailures(self, filename):
|
def getFailures(self, filename):
|
||||||
ipList = dict()
|
ipList = dict()
|
||||||
logSys.debug(filename)
|
ret = self.openLogFile(filename)
|
||||||
self.openLogFile(filename)
|
if not ret:
|
||||||
|
logSys.error("Unable to get failures in " + filename)
|
||||||
|
return False
|
||||||
self.__setFilePos()
|
self.__setFilePos()
|
||||||
lastLine = None
|
lastLine = None
|
||||||
for line in self.crtHandler:
|
for line in self.crtHandler:
|
||||||
try:
|
try:
|
||||||
# Try to convert UTF-8 string to Latin-1
|
# Try to convert UTF-8 string to Latin-1
|
||||||
line = line.decode('utf-8').encode('latin-1')
|
#line = line.decode('utf-8').encode('latin-1')
|
||||||
|
line = line.decode('utf-8')
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
pass
|
pass
|
||||||
except UnicodeEncodeError:
|
#except UnicodeEncodeError:
|
||||||
logSys.warn("Mmhh... Are you sure you watch the correct file?")
|
# logSys.warn("Mmhh... Are you sure you watch the correct file?")
|
||||||
if not self.dateDetector.matchTime(line):
|
if not self.dateDetector.matchTime(line):
|
||||||
# There is no valid time in this line
|
# There is no valid time in this line
|
||||||
continue
|
continue
|
||||||
|
@ -351,6 +360,7 @@ class Filter(JailThread):
|
||||||
if lastLine:
|
if lastLine:
|
||||||
self.lastDate[filename] = self.dateDetector.getTime(lastLine)
|
self.lastDate[filename] = self.dateDetector.getTime(lastLine)
|
||||||
self.__closeLogFile()
|
self.__closeLogFile()
|
||||||
|
return True
|
||||||
|
|
||||||
##
|
##
|
||||||
# Finds the failure in a line.
|
# Finds the failure in a line.
|
||||||
|
|
Loading…
Reference in New Issue