mirror of https://github.com/fail2ban/fail2ban
amend to activate performance-fix (respect findtime before search of match) + code coverage
parent
57458a462e
commit
51fd9a1027
|
@ -425,8 +425,8 @@ class Filter(JailThread):
|
||||||
if isinstance(x, bytes):
|
if isinstance(x, bytes):
|
||||||
return x.decode(enc, errors)
|
return x.decode(enc, errors)
|
||||||
return x
|
return x
|
||||||
except (UnicodeDecodeError, UnicodeEncodeError):
|
except (UnicodeDecodeError, UnicodeEncodeError): # pragma: no cover - unsure if reachable
|
||||||
if errors != 'strict': # pragma: no cover - unsure if reachable
|
if errors != 'strict':
|
||||||
raise
|
raise
|
||||||
return uni_decode(x, enc, 'replace')
|
return uni_decode(x, enc, 'replace')
|
||||||
else:
|
else:
|
||||||
|
@ -436,8 +436,8 @@ class Filter(JailThread):
|
||||||
if isinstance(x, unicode):
|
if isinstance(x, unicode):
|
||||||
return x.encode(enc, errors)
|
return x.encode(enc, errors)
|
||||||
return x
|
return x
|
||||||
except (UnicodeDecodeError, UnicodeEncodeError):
|
except (UnicodeDecodeError, UnicodeEncodeError): # pragma: no cover - unsure if reachable
|
||||||
if errors != 'strict': # pragma: no cover - unsure if reachable
|
if errors != 'strict':
|
||||||
raise
|
raise
|
||||||
return uni_decode(x, enc, 'replace')
|
return uni_decode(x, enc, 'replace')
|
||||||
|
|
||||||
|
@ -446,7 +446,6 @@ class Filter(JailThread):
|
||||||
"""Split the time portion from log msg and return findFailures on them
|
"""Split the time portion from log msg and return findFailures on them
|
||||||
"""
|
"""
|
||||||
if date:
|
if date:
|
||||||
# be sure each element of tuple line has the same type:
|
|
||||||
tupleLine = line
|
tupleLine = line
|
||||||
else:
|
else:
|
||||||
l = line.rstrip('\r\n')
|
l = line.rstrip('\r\n')
|
||||||
|
@ -467,7 +466,7 @@ class Filter(JailThread):
|
||||||
def processLineAndAdd(self, line, date=None):
|
def processLineAndAdd(self, line, date=None):
|
||||||
"""Processes the line for failures and populates failManager
|
"""Processes the line for failures and populates failManager
|
||||||
"""
|
"""
|
||||||
for element in self.processLine(line, date)[1]:
|
for element in self.processLine(line, date, checkFindTime=True)[1]:
|
||||||
ip = element[1]
|
ip = element[1]
|
||||||
unixTime = element[2]
|
unixTime = element[2]
|
||||||
lines = element[3]
|
lines = element[3]
|
||||||
|
@ -832,24 +831,21 @@ class FileContainer:
|
||||||
def decode_line(filename, enc, line):
|
def decode_line(filename, enc, line):
|
||||||
try:
|
try:
|
||||||
return line.decode(enc, 'strict')
|
return line.decode(enc, 'strict')
|
||||||
except UnicodeDecodeError as e:
|
except (UnicodeDecodeError, UnicodeEncodeError) as e:
|
||||||
|
global _decode_line_warn
|
||||||
|
lev = logging.DEBUG
|
||||||
|
if _decode_line_warn.get(filename, 0) <= MyTime.time():
|
||||||
|
lev = logging.WARNING
|
||||||
|
_decode_line_warn[filename] = MyTime.time() + 24*60*60
|
||||||
|
logSys.log(lev,
|
||||||
|
"Error decoding line from '%s' with '%s'."
|
||||||
|
" Consider setting logencoding=utf-8 (or another appropriate"
|
||||||
|
" encoding) for this jail. Continuing"
|
||||||
|
" to process line ignoring invalid characters: %r",
|
||||||
|
filename, enc, line)
|
||||||
# decode with replacing error chars:
|
# decode with replacing error chars:
|
||||||
rline = line.decode(enc, 'replace')
|
line = line.decode(enc, 'replace')
|
||||||
except UnicodeEncodeError as e:
|
return line
|
||||||
# encode with replacing error chars:
|
|
||||||
rline = line.decode(enc, 'replace')
|
|
||||||
global _decode_line_warn
|
|
||||||
lev = logging.DEBUG
|
|
||||||
if _decode_line_warn.get(filename, 0) <= MyTime.time():
|
|
||||||
lev = logging.WARNING
|
|
||||||
_decode_line_warn[filename] = MyTime.time() + 24*60*60
|
|
||||||
logSys.log(lev,
|
|
||||||
"Error decoding line from '%s' with '%s'."
|
|
||||||
" Consider setting logencoding=utf-8 (or another appropriate"
|
|
||||||
" encoding) for this jail. Continuing"
|
|
||||||
" to process line ignoring invalid characters: %r",
|
|
||||||
filename, enc, line)
|
|
||||||
return rline
|
|
||||||
|
|
||||||
def readline(self):
|
def readline(self):
|
||||||
if self.__handler is None:
|
if self.__handler is None:
|
||||||
|
|
Loading…
Reference in New Issue