- 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,14 +30,16 @@ 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:
if self.verbose:
print ip, "already in ban list"
def delBanIP(self, ip):
@ -45,6 +47,7 @@ class Firewall:
del self.banList[ip]
self.executeCmd(self.unBanIP(ip))
else:
if self.verbose:
print ip, "not in ban list"
def inBanList(self, ip):
@ -61,6 +64,7 @@ class Firewall:
btime = element[1]
if btime < time.time()-self.banTime:
self.delBanIP(ip)
if self.verbose:
print '`->', time.time()
def flushBanList(self):
@ -71,6 +75,7 @@ class Firewall:
self.delBanIP(ip)
def executeCmd(self, cmd):
if self.verbose:
print cmd
return #os.system(cmd)

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,6 +59,7 @@ class LogReader:
if self.lastModTime == logStats.st_mtime:
return False
else:
if self.verbose:
print self.logPath, 'has been modified'
self.lastModTime = logStats.st_mtime
return True

View File

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