Conditionally log Ignore IP, and pass in reason (ignoreip, ignorecommand)

pull/930/head
Lee Clemens 2015-01-27 21:06:06 -05:00
parent 64feb0fd16
commit 076b103f97
2 changed files with 12 additions and 5 deletions

View File

@ -338,6 +338,10 @@ class Filter(JailThread):
logSys.debug("Remove " + ip + " from ignore list") logSys.debug("Remove " + ip + " from ignore list")
self.__ignoreIpList.remove(ip) self.__ignoreIpList.remove(ip)
def logIgnoreIp(self, ip, log_ignore, ignore_source="unknown source"):
if log_ignore:
logSys.info("[%s] Ignore %s due to %s" % (self.jail.name, ip, ignore_source))
def getIgnoreIP(self): def getIgnoreIP(self):
return self.__ignoreIpList return self.__ignoreIpList
@ -349,7 +353,7 @@ class Filter(JailThread):
# @param ip IP address # @param ip IP address
# @return True if IP address is in ignore list # @return True if IP address is in ignore list
def inIgnoreIPList(self, ip): def inIgnoreIPList(self, ip, log_ignore=False):
for i in self.__ignoreIpList: for i in self.__ignoreIpList:
# An empty string is always false # An empty string is always false
if i == "": if i == "":
@ -369,16 +373,20 @@ class Filter(JailThread):
# Check if IP in DNS # Check if IP in DNS
ips = DNSUtils.dnsToIp(i) ips = DNSUtils.dnsToIp(i)
if ip in ips: if ip in ips:
self.logIgnoreIp(ip, log_ignore, ignore_source="ignoreip by dns")
return True return True
else: else:
continue continue
if a == b: if a == b:
self.logIgnoreIp(ip, log_ignore, ignore_source="ignoreip by addr")
return True return True
if self.__ignoreCommand: if self.__ignoreCommand:
command = CommandAction.replaceTag(self.__ignoreCommand, { 'ip': ip } ) command = CommandAction.replaceTag(self.__ignoreCommand, { 'ip': ip } )
logSys.debug('ignore command: ' + command) logSys.debug('ignore command: ' + command)
return CommandAction.executeCmd(command) ret_ignore = CommandAction.executeCmd(command)
self.logIgnoreIp(ip, log_ignore and ret_ignore, ignore_source="ignorecommand")
return ret_ignore
return False return False
@ -418,8 +426,7 @@ class Filter(JailThread):
logSys.debug("Ignore line since time %s < %s - %s" logSys.debug("Ignore line since time %s < %s - %s"
% (unixTime, MyTime.time(), self.getFindTime())) % (unixTime, MyTime.time(), self.getFindTime()))
break break
if self.inIgnoreIPList(ip): if self.inIgnoreIPList(ip, log_ignore=True):
logSys.info("[%s] Ignore %s" % (self.jail.name, ip))
continue continue
logSys.info("[%s] Found %s" % (self.jail.name, ip)) logSys.info("[%s] Found %s" % (self.jail.name, ip))
## print "D: Adding a ticket for %s" % ((ip, unixTime, [line]),) ## print "D: Adding a ticket for %s" % ((ip, unixTime, [line]),)

View File

@ -213,7 +213,7 @@ class Jail:
if self.database is not None: if self.database is not None:
for ticket in self.database.getBansMerged( for ticket in self.database.getBansMerged(
jail=self, bantime=self.actions.getBanTime()): jail=self, bantime=self.actions.getBanTime()):
if not self.filter.inIgnoreIPList(ticket.getIP()): if not self.filter.inIgnoreIPList(ticket.getIP(), log_ignore=True):
self.__queue.put(ticket) self.__queue.put(ticket)
logSys.info("Jail '%s' started" % self.name) logSys.info("Jail '%s' started" % self.name)