code review, manually ban uses by addFailure the count "maxRetry" directly;

log ticket time (found in line)
pull/716/head
sebres 2014-05-14 12:17:28 +02:00
parent d22ab320e2
commit 99c9cbf470
1 changed files with 11 additions and 9 deletions

View File

@ -21,7 +21,7 @@ __author__ = "Cyril Jaquier and Fail2Ban Contributors"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier, 2011-2013 Yaroslav Halchenko" __copyright__ = "Copyright (c) 2004 Cyril Jaquier, 2011-2013 Yaroslav Halchenko"
__license__ = "GPL" __license__ = "GPL"
import logging, re, os, fcntl, sys, locale, codecs import logging, re, os, fcntl, sys, locale, codecs, datetime
from .failmanager import FailManagerEmpty, FailManager from .failmanager import FailManagerEmpty, FailManager
from .ticket import FailTicket from .ticket import FailTicket
@ -309,8 +309,7 @@ class Filter(JailThread):
logSys.warning('Requested to manually ban an ignored IP %s. User knows best. Proceeding to ban it.' % ip) logSys.warning('Requested to manually ban an ignored IP %s. User knows best. Proceeding to ban it.' % ip)
unixTime = MyTime.time() unixTime = MyTime.time()
for i in xrange(self.failManager.getMaxRetry()): self.failManager.addFailure(FailTicket(ip, unixTime), self.failManager.getMaxRetry())
self.failManager.addFailure(FailTicket(ip, unixTime))
# Perform the banning of the IP now. # Perform the banning of the IP now.
try: # pragma: no branch - exception is the only way out try: # pragma: no branch - exception is the only way out
@ -433,12 +432,15 @@ class Filter(JailThread):
break break
retryCount = min(retryCount, self.failManager.getMaxRetry()) retryCount = min(retryCount, self.failManager.getMaxRetry())
except Exception as e: except Exception as e:
#logSys.error('%s', e, exc_info=logSys.getEffectiveLevel()<=logging.DEBUG) logSys.error('%s', e, exc_info=logSys.getEffectiveLevel()<=logging.DEBUG)
logSys.error('%s', e, exc_info=True) #logSys.error('%s', e, exc_info=True)
if banCount == 1 and retryCount == 1: try:
logSys.info("[%s] Found %s" % (self.jail.name, ip)) logSys.info(
else: ("[%s] Found %s - %s" % (self.jail.name, ip, datetime.datetime.fromtimestamp(unixTime).strftime("%Y-%m-%d %H:%M:%S")))
logSys.info("[%s] Found %s, %s # -> %s" % (self.jail.name, ip, banCount, retryCount)) + ((", %s # -> %s" % (banCount, retryCount)) if banCount != 1 or retryCount != 1 else '')
)
except Exception as e:
logSys.error('%s', e, exc_info=True)
self.failManager.addFailure(FailTicket(ip, unixTime, lines), retryCount) self.failManager.addFailure(FailTicket(ip, unixTime, lines), retryCount)
## ##