ENH: Added use_dns option

pull/27/head
Lee Clemens 2012-01-09 20:01:34 -05:00
parent ae1e857e53
commit 9538553bc5
3 changed files with 55 additions and 15 deletions

View File

@ -64,6 +64,8 @@ class Filter(JailThread):
self.__failRegex = list()
## The regular expression list with expressions to ignore.
self.__ignoreRegex = list()
## Use DNS setting
self.__useDns = "warn"
## The amount of time to look back.
self.__findTime = 6000
## The ignore IP list.
@ -139,6 +141,21 @@ class Filter(JailThread):
ignoreRegex.append(regex.getRegex())
return ignoreRegex
##
# Set the Use DNS mode
# @param value the use_dns mode
def setUseDns(self, value):
self.__useDns = value
logSys.info("Set use_dns = %s" % value)
##
# Get the use_dns mode
# @return the use_dns mode
def getUseDns(self):
return self.__useDns
##
# Set the time needed to find a failure.
#
@ -325,7 +342,7 @@ class Filter(JailThread):
else:
try:
host = failRegex.getHost()
ipMatch = DNSUtils.textToIp(host)
ipMatch = DNSUtils.textToIp(host, self.__useDns)
if ipMatch:
for ip in ipMatch:
failList.append([ip, date])
@ -564,22 +581,33 @@ class DNSUtils:
isValidIP = staticmethod(isValidIP)
#@staticmethod
def textToIp(text):
def textToIp(text, useDns):
""" Return the IP of DNS found in a given text.
"""
ipList = list()
# Search for plain IP
plainIP = DNSUtils.searchIP(text)
if not plainIP == None:
plainIPStr = plainIP.group(0)
if DNSUtils.isValidIP(plainIPStr):
ipList.append(plainIPStr)
if not ipList:
# Try to get IP from possible DNS
ip = DNSUtils.dnsToIp(text)
for e in ip:
ipList.append(e)
return ipList
logSys.debug("Checking rDNS: %s" % text)
logSys.debug("DNS use_dns == %s" % useDns)
if useDns == "no":
logSys.debug("use_dns == no")
return None
else:
logSys.debug("use_dns != no")
ipList = list()
# Search for plain IP
plainIP = DNSUtils.searchIP(text)
if not plainIP is None:
plainIPStr = plainIP.group(0)
if DNSUtils.isValidIP(plainIPStr):
ipList.append(plainIPStr)
if not ipList:
# Try to get IP from possible DNS
ip = DNSUtils.dnsToIp(text)
for e in ip:
ipList.append(e)
logSys.debug("At bottom of textToIp, ipList == %s" % ipList)
if useDns == "warn":
logSys.warning("IP Banned after DNS Reverse Lookup: %s = %s",
text, ipList)
return ipList
textToIp = staticmethod(textToIp)
#@staticmethod

View File

@ -204,6 +204,12 @@ class Server:
def getIgnoreRegex(self, name):
return self.__jails.getFilter(name).getIgnoreRegex()
def setUseDns(self, name, value):
self.__jails.getFilter(name).setUseDns(value)
def getUseDns(self, name):
return self.__jails.getFilter(name).getUseDns()
def setMaxRetry(self, name, value):
self.__jails.getFilter(name).setMaxRetry(value)

View File

@ -154,6 +154,10 @@ class Transmitter:
value = int(command[2])
self.__server.delIgnoreRegex(name, value)
return self.__server.getIgnoreRegex(name)
elif command[1] == "use_dns":
value = command[2]
self.__server.setUseDns(name, value)
return self.__server.getUseDns(name)
elif command[1] == "findtime":
value = command[2]
self.__server.setFindTime(name, int(value))
@ -231,6 +235,8 @@ class Transmitter:
return self.__server.getFailRegex(name)
elif command[1] == "ignoreregex":
return self.__server.getIgnoreRegex(name)
elif command[1] == "use_dns":
return self.__server.getUseDns(name)
elif command[1] == "findtime":
return self.__server.getFindTime(name)
elif command[1] == "maxretry":