- Removed Python 2.4. Minimum required version is now Python 2.3.

git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_8@635 a942ae1a-1317-0410-a47c-b1dcaea8d605
_tent/ipv6_via_aInfo
Cyril Jaquier 2007-12-16 21:38:04 +00:00
parent e68cc2b176
commit ce6b8c959e
16 changed files with 61 additions and 34 deletions

View File

@ -2,7 +2,7 @@
<?eclipse-pydev version="1.0"?> <?eclipse-pydev version="1.0"?>
<pydev_project> <pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.4</pydev_property> <pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.3</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH"> <pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/fail2ban-0.8/client</path> <path>/fail2ban-0.8/client</path>
<path>/fail2ban-0.8/server</path> <path>/fail2ban-0.8/server</path>

View File

@ -25,6 +25,8 @@ ver. 0.8.2 (2007/??/??) - stable
- Moved socket to /var/run/fail2ban. - Moved socket to /var/run/fail2ban.
- Rewrote the communication server. - Rewrote the communication server.
- Refactoring. Reduced number of files. - Refactoring. Reduced number of files.
- Removed Python 2.4. Minimum required version is now Python
2.3.
ver. 0.8.1 (2007/08/14) - stable ver. 0.8.1 (2007/08/14) - stable
---------- ----------

8
README
View File

@ -4,7 +4,7 @@
|_| \__,_|_|_/___|_.__/\__,_|_||_| |_| \__,_|_|_/___|_.__/\__,_|_||_|
============================================================= =============================================================
Fail2Ban (version 0.8.1) 2007/08/14 Fail2Ban (version 0.8.2) 2007/??/??
============================================================= =============================================================
Fail2Ban scans log files like /var/log/pwdfail and bans IP Fail2Ban scans log files like /var/log/pwdfail and bans IP
@ -21,15 +21,15 @@ Installation:
------------- -------------
Required: Required:
>=python-2.4 (http://www.python.org) >=python-2.3 (http://www.python.org)
Optional: Optional:
>=gamin-0.0.21 (http://www.gnome.org/~veillard/gamin) >=gamin-0.0.21 (http://www.gnome.org/~veillard/gamin)
To install, just do: To install, just do:
> tar xvfj fail2ban-0.8.1.tar.bz2 > tar xvfj fail2ban-0.8.2.tar.bz2
> cd fail2ban-0.8.1 > cd fail2ban-0.8.2
> python setup.py install > python setup.py install
This will install Fail2Ban into /usr/share/fail2ban. The This will install Fail2Ban into /usr/share/fail2ban. The

View File

@ -55,7 +55,7 @@ files_after = 1.conf
""" """
@staticmethod #@staticmethod
def getIncludedFiles(filename, sectionName='INCLUDES', def getIncludedFiles(filename, sectionName='INCLUDES',
defaults={}, seen=[]): defaults={}, seen=[]):
""" """
@ -83,6 +83,7 @@ files_after = 1.conf
filenames = newFiles[0][1] + [filename] + newFiles[1][1] filenames = newFiles[0][1] + [filename] + newFiles[1][1]
#print "Includes list for " + filename + " is " + `filenames` #print "Includes list for " + filename + " is " + `filenames`
return filenames return filenames
getIncludedFiles = staticmethod(getIncludedFiles)
def read(self, filenames): def read(self, filenames):

View File

@ -41,14 +41,16 @@ class ConfigReader(SafeConfigParserWithIncludes):
ConfigReader.BASE_DIRECTORY} ) ConfigReader.BASE_DIRECTORY} )
self.__opts = None self.__opts = None
@staticmethod #@staticmethod
def setBaseDir(folderName): def setBaseDir(folderName):
path = folderName.rstrip('/') path = folderName.rstrip('/')
ConfigReader.BASE_DIRECTORY = path + '/' ConfigReader.BASE_DIRECTORY = path + '/'
setBaseDir = staticmethod(setBaseDir)
@staticmethod #@staticmethod
def getBaseDir(): def getBaseDir():
return ConfigReader.BASE_DIRECTORY return ConfigReader.BASE_DIRECTORY
getBaseDir = staticmethod(getBaseDir)
def read(self, filename): def read(self, filename):
basename = ConfigReader.BASE_DIRECTORY + filename basename = ConfigReader.BASE_DIRECTORY + filename

View File

@ -40,13 +40,15 @@ class Configurator:
self.__fail2ban = Fail2banReader() self.__fail2ban = Fail2banReader()
self.__jails = JailsReader() self.__jails = JailsReader()
@staticmethod #@staticmethod
def setBaseDir(folderName): def setBaseDir(folderName):
ConfigReader.setBaseDir(folderName) ConfigReader.setBaseDir(folderName)
setBaseDir = staticmethod(setBaseDir)
@staticmethod #@staticmethod
def getBaseDir(): def getBaseDir():
return ConfigReader.getBaseDir() return ConfigReader.getBaseDir()
getBaseDir = staticmethod(getBaseDir)
def readEarly(self): def readEarly(self):
self.__fail2ban.read() self.__fail2ban.read()

View File

@ -47,7 +47,7 @@ class CSocket:
self.__csock.close() self.__csock.close()
return ret return ret
@staticmethod #@staticmethod
def receive(sock): def receive(sock):
msg = '' msg = ''
while msg.rfind(CSocket.END_STRING) == -1: while msg.rfind(CSocket.END_STRING) == -1:
@ -56,3 +56,4 @@ class CSocket:
raise RuntimeError, "socket connection broken" raise RuntimeError, "socket connection broken"
msg = msg + chunk msg = msg + chunk
return loads(msg) return loads(msg)
receive = staticmethod(receive)

View File

@ -129,7 +129,7 @@ class JailReader(ConfigReader):
stream.insert(0, ["add", self.__name, backend]) stream.insert(0, ["add", self.__name, backend])
return stream return stream
@staticmethod #@staticmethod
def splitAction(action): def splitAction(action):
m = JailReader.actionCRE.match(action) m = JailReader.actionCRE.match(action)
d = dict() d = dict()
@ -165,3 +165,4 @@ class JailReader(ConfigReader):
except IndexError: except IndexError:
logSys.error("Invalid argument %s in '%s'" % (p, m.group(2))) logSys.error("Invalid argument %s in '%s'" % (p, m.group(2)))
return [m.group(1), d] return [m.group(1), d]
splitAction = staticmethod(splitAction)

View File

@ -357,11 +357,12 @@ class Fail2banClient:
self.__stream = self.__configurator.getConfigStream() self.__stream = self.__configurator.getConfigStream()
return ret return ret
@staticmethod #@staticmethod
def dumpConfig(cmd): def dumpConfig(cmd):
for c in cmd: for c in cmd:
print c print c
return True return True
dumpConfig = staticmethod(dumpConfig)
class ServerExecutionException(Exception): class ServerExecutionException(Exception):

View File

@ -35,7 +35,7 @@ from client.configparserinc import SafeConfigParserWithIncludes
from ConfigParser import NoOptionError, NoSectionError, MissingSectionHeaderError from ConfigParser import NoOptionError, NoSectionError, MissingSectionHeaderError
from common.version import version from common.version import version
from server.filter import Filter from server.filter import Filter
from server.regex import RegexException from server.failregex import RegexException
# Gets the instance of the logger. # Gets the instance of the logger.
logSys = logging.getLogger("fail2ban.regex") logSys = logging.getLogger("fail2ban.regex")
@ -82,7 +82,7 @@ class Fail2banRegex:
logging.getLogger("fail2ban").addHandler(self.__hdlr) logging.getLogger("fail2ban").addHandler(self.__hdlr)
logging.getLogger("fail2ban").setLevel(logging.ERROR) logging.getLogger("fail2ban").setLevel(logging.ERROR)
@staticmethod #@staticmethod
def dispVersion(): def dispVersion():
print "Fail2Ban v" + version print "Fail2Ban v" + version
print print
@ -92,8 +92,9 @@ class Fail2banRegex:
print print
print "Written by Cyril Jaquier <lostcontrol@users.sourceforge.net>." print "Written by Cyril Jaquier <lostcontrol@users.sourceforge.net>."
print "Many contributions by Yaroslav O. Halchenko <debian@onerussian.com>." print "Many contributions by Yaroslav O. Halchenko <debian@onerussian.com>."
dispVersion = staticmethod(dispVersion)
@staticmethod #@staticmethod
def dispUsage(): def dispUsage():
print "Usage: "+sys.argv[0]+" [OPTIONS] <LOG> <REGEX> [IGNOREREGEX]" print "Usage: "+sys.argv[0]+" [OPTIONS] <LOG> <REGEX> [IGNOREREGEX]"
print print
@ -119,6 +120,7 @@ class Fail2banRegex:
print " filename path to a filter file (filter.d/sshd.conf)" print " filename path to a filter file (filter.d/sshd.conf)"
print print
print "Report bugs to <lostcontrol@users.sourceforge.net>" print "Report bugs to <lostcontrol@users.sourceforge.net>"
dispUsage = staticmethod(dispUsage)
def getCmdLineOptions(self, optList): def getCmdLineOptions(self, optList):
""" Gets the command line options """ Gets the command line options
@ -131,9 +133,10 @@ class Fail2banRegex:
self.dispVersion() self.dispVersion()
sys.exit(0) sys.exit(0)
@staticmethod #@staticmethod
def logIsFile(value): def logIsFile(value):
return os.path.isfile(value) return os.path.isfile(value)
logIsFile = staticmethod(logIsFile)
def readIgnoreRegex(self, value): def readIgnoreRegex(self, value):
if os.path.isfile(value): if os.path.isfile(value):

View File

@ -231,7 +231,7 @@ class Action:
# @param aInfo the properties # @param aInfo the properties
# @return a string # @return a string
@staticmethod #@staticmethod
def replaceTag(query, aInfo): def replaceTag(query, aInfo):
""" Replace tags in query """ Replace tags in query
""" """
@ -241,6 +241,7 @@ class Action:
# New line # New line
string = string.replace("<br>", '\n') string = string.replace("<br>", '\n')
return string return string
replaceTag = staticmethod(replaceTag)
## ##
# Executes a command with preliminary checks and substitutions. # Executes a command with preliminary checks and substitutions.
@ -297,7 +298,7 @@ class Action:
# @param realCmd the command to execute # @param realCmd the command to execute
# @return True if the command succeeded # @return True if the command succeeded
@staticmethod #@staticmethod
def executeCmd(realCmd): def executeCmd(realCmd):
logSys.debug(realCmd) logSys.debug(realCmd)
try: try:
@ -312,3 +313,5 @@ class Action:
except OSError, e: except OSError, e:
logSys.error("%s failed with %s" % (realCmd, e)) logSys.error("%s failed with %s" % (realCmd, e))
return False return False
executeCmd = staticmethod(executeCmd)

View File

@ -125,7 +125,7 @@ class BanManager:
# @param ticket the FailTicket # @param ticket the FailTicket
# @return a BanTicket # @return a BanTicket
@staticmethod #@staticmethod
def createBanTicket(ticket): def createBanTicket(ticket):
ip = ticket.getIP() ip = ticket.getIP()
#lastTime = ticket.getTime() #lastTime = ticket.getTime()
@ -133,6 +133,7 @@ class BanManager:
banTicket = BanTicket(ip, lastTime) banTicket = BanTicket(ip, lastTime)
banTicket.setAttempt(ticket.getAttempt()) banTicket.setAttempt(ticket.getAttempt())
return banTicket return banTicket
createBanTicket = staticmethod(createBanTicket)
## ##
# Add a ban ticket. # Add a ban ticket.

View File

@ -164,8 +164,7 @@ class DateDetector:
try: try:
self.__lock.acquire() self.__lock.acquire()
logSys.debug("Sorting the template list") logSys.debug("Sorting the template list")
self.__templates.sort(cmp = lambda x, y: self.__templates.sort(lambda x, y: cmp(x.getHits(), y.getHits()))
cmp(x.getHits(), y.getHits()), self.__templates.reverse()
reverse = True)
finally: finally:
self.__lock.release() self.__lock.release()

View File

@ -114,13 +114,14 @@ class DateStrptime(DateTemplate):
def __init__(self): def __init__(self):
DateTemplate.__init__(self) DateTemplate.__init__(self)
@staticmethod #@staticmethod
def convertLocale(date): def convertLocale(date):
for t in DateStrptime.TABLE: for t in DateStrptime.TABLE:
for m in DateStrptime.TABLE[t]: for m in DateStrptime.TABLE[t]:
if date.find(m) >= 0: if date.find(m) >= 0:
return date.replace(m, t) return date.replace(m, t)
return date return date
convertLocale = staticmethod(convertLocale)
def getDate(self, line): def getDate(self, line):
date = None date = None

View File

@ -498,7 +498,7 @@ class DNSUtils:
DNS_CRE = re.compile("(?:(?:\w|-)+\.){2,}\w+") DNS_CRE = re.compile("(?:(?:\w|-)+\.){2,}\w+")
IP_CRE = re.compile("(?:\d{1,3}\.){3}\d{1,3}") IP_CRE = re.compile("(?:\d{1,3}\.){3}\d{1,3}")
@staticmethod #@staticmethod
def dnsToIp(dns): def dnsToIp(dns):
""" Convert a DNS into an IP address using the Python socket module. """ Convert a DNS into an IP address using the Python socket module.
Thanks to Kevin Drapel. Thanks to Kevin Drapel.
@ -509,8 +509,9 @@ class DNSUtils:
logSys.warn("Unable to find a corresponding IP address for %s" logSys.warn("Unable to find a corresponding IP address for %s"
% dns) % dns)
return list() return list()
dnsToIp = staticmethod(dnsToIp)
@staticmethod #@staticmethod
def searchIP(text): def searchIP(text):
""" Search if an IP address if directly available and return """ Search if an IP address if directly available and return
it. it.
@ -520,8 +521,9 @@ class DNSUtils:
return match return match
else: else:
return None return None
searchIP = staticmethod(searchIP)
@staticmethod #@staticmethod
def isValidIP(string): def isValidIP(string):
""" Return true if str is a valid IP """ Return true if str is a valid IP
""" """
@ -531,8 +533,9 @@ class DNSUtils:
return True return True
except socket.error: except socket.error:
return False return False
isValidIP = staticmethod(isValidIP)
@staticmethod #@staticmethod
def textToIp(text): def textToIp(text):
""" Return the IP of DNS found in a given text. """ Return the IP of DNS found in a given text.
""" """
@ -549,8 +552,9 @@ class DNSUtils:
for e in ip: for e in ip:
ipList.append(e) ipList.append(e)
return ipList return ipList
textToIp = staticmethod(textToIp)
@staticmethod #@staticmethod
def cidr(i, n): def cidr(i, n):
""" Convert an IP address string with a CIDR mask into a 32-bit """ Convert an IP address string with a CIDR mask into a 32-bit
integer. integer.
@ -558,15 +562,18 @@ class DNSUtils:
# 32-bit IPv4 address mask # 32-bit IPv4 address mask
MASK = 0xFFFFFFFFL MASK = 0xFFFFFFFFL
return ~(MASK >> n) & MASK & DNSUtils.addr2bin(i) return ~(MASK >> n) & MASK & DNSUtils.addr2bin(i)
cidr = staticmethod(cidr)
@staticmethod #@staticmethod
def addr2bin(string): def addr2bin(string):
""" Convert a string IPv4 address into an unsigned integer. """ Convert a string IPv4 address into an unsigned integer.
""" """
return struct.unpack("!L", socket.inet_aton(string))[0] return struct.unpack("!L", socket.inet_aton(string))[0]
addr2bin = staticmethod(addr2bin)
@staticmethod #@staticmethod
def bin2addr(addr): def bin2addr(addr):
""" Convert a numeric IPv4 address into string n.n.n.n form. """ Convert a numeric IPv4 address into string n.n.n.n form.
""" """
return socket.inet_ntoa(struct.pack("!L", addr)) return socket.inet_ntoa(struct.pack("!L", addr))
bin2addr = staticmethod(bin2addr)

View File

@ -46,31 +46,34 @@ class MyTime:
# #
# @param t the time to set or None # @param t the time to set or None
@staticmethod #@staticmethod
def setTime(t): def setTime(t):
MyTime.myTime = t MyTime.myTime = t
setTime = staticmethod(setTime)
## ##
# Equivalent to time.time() # Equivalent to time.time()
# #
# @return time.time() if setTime was called with None # @return time.time() if setTime was called with None
@staticmethod #@staticmethod
def time(): def time():
if MyTime.myTime == None: if MyTime.myTime == None:
return time.time() return time.time()
else: else:
return MyTime.myTime return MyTime.myTime
time = staticmethod(time)
## ##
# Equivalent to time.gmtime() # Equivalent to time.gmtime()
# #
# @return time.gmtime() if setTime was called with None # @return time.gmtime() if setTime was called with None
@staticmethod #@staticmethod
def gmtime(): def gmtime():
if MyTime.myTime == None: if MyTime.myTime == None:
return time.gmtime() return time.gmtime()
else: else:
return time.gmtime(MyTime.myTime) return time.gmtime(MyTime.myTime)
gmtime = staticmethod(gmtime)