- Add verbose option

git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@15 a942ae1a-1317-0410-a47c-b1dcaea8d605
0.6
Cyril Jaquier 2004-10-10 23:46:58 +00:00
parent 4602bb1bfc
commit e561e39583
3 changed files with 18 additions and 9 deletions

View File

@ -30,22 +30,25 @@ class Firewall:
banList = dict()
def __init__(self, banTime):
def __init__(self, banTime, verbose = False):
self.banTime = banTime
self.verbose = verbose
def addBanIP(self, ip):
if not self.inBanList(ip):
self.banList[ip] = time.time()
self.executeCmd(self.banIP(ip))
else:
print ip, "already in ban list"
if self.verbose:
print ip, "already in ban list"
def delBanIP(self, ip):
if self.inBanList(ip):
del self.banList[ip]
self.executeCmd(self.unBanIP(ip))
else:
print ip, "not in ban list"
if self.verbose:
print ip, "not in ban list"
def inBanList(self, ip):
return self.banList.has_key(ip)
@ -61,7 +64,8 @@ class Firewall:
btime = element[1]
if btime < time.time()-self.banTime:
self.delBanIP(ip)
print '`->', time.time()
if self.verbose:
print '`->', time.time()
def flushBanList(self):
iterBanList = self.banList.iteritems()
@ -71,7 +75,8 @@ class Firewall:
self.delBanIP(ip)
def executeCmd(self, cmd):
print cmd
if self.verbose:
print cmd
return #os.system(cmd)
def viewBanList(self):

View File

@ -28,11 +28,12 @@ import os, sys
class LogReader:
def __init__(self, logPath, findTime = 3600):
def __init__(self, logPath, findTime = 3600, verbose = False):
self.logPath = logPath
self.findTime = findTime
self.ignoreIpList = []
self.lastModTime = 0
self.verbose = verbose
def addIgnoreIP(self, ip):
self.ignoreIpList.append(ip)
@ -58,7 +59,8 @@ class LogReader:
if self.lastModTime == logStats.st_mtime:
return False
else:
print self.logPath, 'has been modified'
if self.verbose:
print self.logPath, 'has been modified'
self.lastModTime = logStats.st_mtime
return True

View File

@ -41,9 +41,11 @@ class Metalog(LogReader):
if unixTime < time.time()-self.findTime:
continue
if self.inIgnoreIPList(ip):
print 'Ignore', ip
if self.verbose:
print 'Ignore', ip
continue
print 'Found', ip, 'at', unixTime
if self.verbose:
print 'Found', ip, 'at', unixTime
if ipList.has_key(ip):
ipList[ip] = (ipList[ip][0]+1, unixTime)
else: