mirror of https://github.com/fail2ban/fail2ban
tweak performance a bit (filter.py: inIgnoreIPList: changed default of parameter `log_ignore=True`, mostly used against filter-calls)
parent
a208b11796
commit
e01981cc72
|
@ -418,7 +418,7 @@ class Filter(JailThread):
|
|||
def addBannedIP(self, ip):
|
||||
if not isinstance(ip, IPAddr):
|
||||
ip = IPAddr(ip)
|
||||
if self.inIgnoreIPList(ip):
|
||||
if self.inIgnoreIPList(ip, log_ignore=False):
|
||||
logSys.warning('Requested to manually ban an ignored IP %s. User knows best. Proceeding to ban it.', ip)
|
||||
|
||||
unixTime = MyTime.time()
|
||||
|
@ -490,7 +490,7 @@ class Filter(JailThread):
|
|||
# @param ip IP address object
|
||||
# @return True if IP address is in ignore list
|
||||
|
||||
def inIgnoreIPList(self, ip, log_ignore=False):
|
||||
def inIgnoreIPList(self, ip, log_ignore=True):
|
||||
if not isinstance(ip, IPAddr):
|
||||
ip = IPAddr(ip)
|
||||
|
||||
|
@ -549,7 +549,7 @@ class Filter(JailThread):
|
|||
fail = element[3]
|
||||
logSys.debug("Processing line with time:%s and ip:%s",
|
||||
unixTime, ip)
|
||||
if self.inIgnoreIPList(ip, log_ignore=True):
|
||||
if self.inIgnoreIPList(ip):
|
||||
continue
|
||||
logSys.info(
|
||||
"[%s] Found %s - %s", self.jailName, ip, datetime.datetime.fromtimestamp(unixTime).strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
|
|
@ -336,20 +336,20 @@ class IgnoreIP(LogCaptureTestCase):
|
|||
ipList = ("127.0.0.1",)
|
||||
# test ignoreSelf is false:
|
||||
for ip in ipList:
|
||||
self.assertFalse(self.filter.inIgnoreIPList(ip, log_ignore=True))
|
||||
self.assertFalse(self.filter.inIgnoreIPList(ip))
|
||||
self.assertNotLogged("[%s] Ignore %s by %s" % (self.jail.name, ip, "ignoreself rule"))
|
||||
# test ignoreSelf with true:
|
||||
self.filter.ignoreSelf = True
|
||||
self.pruneLog()
|
||||
for ip in ipList:
|
||||
self.assertTrue(self.filter.inIgnoreIPList(ip, log_ignore=True))
|
||||
self.assertTrue(self.filter.inIgnoreIPList(ip))
|
||||
self.assertLogged("[%s] Ignore %s by %s" % (self.jail.name, ip, "ignoreself rule"))
|
||||
|
||||
def testIgnoreIPOK(self):
|
||||
ipList = "127.0.0.1", "192.168.0.1", "255.255.255.255", "99.99.99.99"
|
||||
for ip in ipList:
|
||||
self.filter.addIgnoreIP(ip)
|
||||
self.assertTrue(self.filter.inIgnoreIPList(ip, log_ignore=True))
|
||||
self.assertTrue(self.filter.inIgnoreIPList(ip))
|
||||
self.assertLogged("[%s] Ignore %s by %s" % (self.jail.name, ip, "ip"))
|
||||
|
||||
def testIgnoreIPNOK(self):
|
||||
|
|
Loading…
Reference in New Issue