|
|
|
@ -21,7 +21,8 @@ __author__ = "Cyril Jaquier and Fail2Ban Contributors"
|
|
|
|
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier, 2011-2013 Yaroslav Halchenko"
|
|
|
|
|
__license__ = "GPL"
|
|
|
|
|
|
|
|
|
|
#import sys, os, getopt
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
from failmanager import FailManagerEmpty
|
|
|
|
|
from failmanager import FailManager
|
|
|
|
|
from ticket import FailTicket
|
|
|
|
@ -42,7 +43,6 @@ logSys = logging.getLogger("fail2ban.filter")
|
|
|
|
|
# that matches a given regular expression. This class is instantiated by
|
|
|
|
|
# a Jail object.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Filter(JailThread):
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
@ -67,13 +67,12 @@ class Filter(JailThread):
|
|
|
|
|
self.__findTime = 6000
|
|
|
|
|
## The ignore IP list.
|
|
|
|
|
self.__ignoreIpList = []
|
|
|
|
|
## External command
|
|
|
|
|
self.__ignoreCommand = False
|
|
|
|
|
|
|
|
|
|
self.dateDetector = DateDetector()
|
|
|
|
|
self.dateDetector.addDefaultTemplate()
|
|
|
|
|
logSys.debug("Created %s" % self)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
|
return "%s(%r)" % (self.__class__.__name__, self.jail)
|
|
|
|
|
|
|
|
|
@ -92,6 +91,7 @@ class Filter(JailThread):
|
|
|
|
|
logSys.error(e)
|
|
|
|
|
raise e
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def delFailRegex(self, index):
|
|
|
|
|
try:
|
|
|
|
|
del self.__failRegex[index]
|
|
|
|
@ -212,21 +212,6 @@ class Filter(JailThread):
|
|
|
|
|
def run(self): # pragma: no cover
|
|
|
|
|
raise Exception("run() is abstract")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Set external command, for ignoredips
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
def setIgnoreCommand(self, command):
|
|
|
|
|
self.__ignoreCommand = command
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Get external command, for ignoredips
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
def getIgnoreCommand(self):
|
|
|
|
|
return self.__ignoreCommand
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Ban an IP - http://blogs.buanzo.com.ar/2009/04/fail2ban-patch-ban-ip-address-manually.html
|
|
|
|
|
# Arturo 'Buanzo' Busleiman <buanzo@buanzo.com.ar>
|
|
|
|
@ -264,9 +249,6 @@ class Filter(JailThread):
|
|
|
|
|
self.__ignoreIpList.remove(ip)
|
|
|
|
|
|
|
|
|
|
def getIgnoreIP(self):
|
|
|
|
|
if self.__ignoreCommand is not False:
|
|
|
|
|
return self.__ignoreIpList + os.popen(self.__ignoreCommand).read().split(" ")
|
|
|
|
|
else:
|
|
|
|
|
return self.__ignoreIpList
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
@ -282,12 +264,6 @@ class Filter(JailThread):
|
|
|
|
|
# An empty string is always false
|
|
|
|
|
if i == "":
|
|
|
|
|
continue
|
|
|
|
|
# External command with ips to ignore
|
|
|
|
|
if self.__ignoreCommand is not False:
|
|
|
|
|
ignored_ips = os.popen(self.__ignoreCommand).read().split(" ")
|
|
|
|
|
if ip in ignored_ips:
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
s = i.split('/', 1)
|
|
|
|
|
# IP address without CIDR mask
|
|
|
|
|
if len(s) == 1:
|
|
|
|
|