mirror of https://github.com/fail2ban/fail2ban
- Add verbose option
git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@15 a942ae1a-1317-0410-a47c-b1dcaea8d6050.6
parent
4602bb1bfc
commit
e561e39583
|
@ -30,14 +30,16 @@ class Firewall:
|
||||||
|
|
||||||
banList = dict()
|
banList = dict()
|
||||||
|
|
||||||
def __init__(self, banTime):
|
def __init__(self, banTime, verbose = False):
|
||||||
self.banTime = banTime
|
self.banTime = banTime
|
||||||
|
self.verbose = verbose
|
||||||
|
|
||||||
def addBanIP(self, ip):
|
def addBanIP(self, ip):
|
||||||
if not self.inBanList(ip):
|
if not self.inBanList(ip):
|
||||||
self.banList[ip] = time.time()
|
self.banList[ip] = time.time()
|
||||||
self.executeCmd(self.banIP(ip))
|
self.executeCmd(self.banIP(ip))
|
||||||
else:
|
else:
|
||||||
|
if self.verbose:
|
||||||
print ip, "already in ban list"
|
print ip, "already in ban list"
|
||||||
|
|
||||||
def delBanIP(self, ip):
|
def delBanIP(self, ip):
|
||||||
|
@ -45,6 +47,7 @@ class Firewall:
|
||||||
del self.banList[ip]
|
del self.banList[ip]
|
||||||
self.executeCmd(self.unBanIP(ip))
|
self.executeCmd(self.unBanIP(ip))
|
||||||
else:
|
else:
|
||||||
|
if self.verbose:
|
||||||
print ip, "not in ban list"
|
print ip, "not in ban list"
|
||||||
|
|
||||||
def inBanList(self, ip):
|
def inBanList(self, ip):
|
||||||
|
@ -61,6 +64,7 @@ class Firewall:
|
||||||
btime = element[1]
|
btime = element[1]
|
||||||
if btime < time.time()-self.banTime:
|
if btime < time.time()-self.banTime:
|
||||||
self.delBanIP(ip)
|
self.delBanIP(ip)
|
||||||
|
if self.verbose:
|
||||||
print '`->', time.time()
|
print '`->', time.time()
|
||||||
|
|
||||||
def flushBanList(self):
|
def flushBanList(self):
|
||||||
|
@ -71,6 +75,7 @@ class Firewall:
|
||||||
self.delBanIP(ip)
|
self.delBanIP(ip)
|
||||||
|
|
||||||
def executeCmd(self, cmd):
|
def executeCmd(self, cmd):
|
||||||
|
if self.verbose:
|
||||||
print cmd
|
print cmd
|
||||||
return #os.system(cmd)
|
return #os.system(cmd)
|
||||||
|
|
||||||
|
|
|
@ -28,11 +28,12 @@ import os, sys
|
||||||
|
|
||||||
class LogReader:
|
class LogReader:
|
||||||
|
|
||||||
def __init__(self, logPath, findTime = 3600):
|
def __init__(self, logPath, findTime = 3600, verbose = False):
|
||||||
self.logPath = logPath
|
self.logPath = logPath
|
||||||
self.findTime = findTime
|
self.findTime = findTime
|
||||||
self.ignoreIpList = []
|
self.ignoreIpList = []
|
||||||
self.lastModTime = 0
|
self.lastModTime = 0
|
||||||
|
self.verbose = verbose
|
||||||
|
|
||||||
def addIgnoreIP(self, ip):
|
def addIgnoreIP(self, ip):
|
||||||
self.ignoreIpList.append(ip)
|
self.ignoreIpList.append(ip)
|
||||||
|
@ -58,6 +59,7 @@ class LogReader:
|
||||||
if self.lastModTime == logStats.st_mtime:
|
if self.lastModTime == logStats.st_mtime:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
if self.verbose:
|
||||||
print self.logPath, 'has been modified'
|
print self.logPath, 'has been modified'
|
||||||
self.lastModTime = logStats.st_mtime
|
self.lastModTime = logStats.st_mtime
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -41,8 +41,10 @@ class Metalog(LogReader):
|
||||||
if unixTime < time.time()-self.findTime:
|
if unixTime < time.time()-self.findTime:
|
||||||
continue
|
continue
|
||||||
if self.inIgnoreIPList(ip):
|
if self.inIgnoreIPList(ip):
|
||||||
|
if self.verbose:
|
||||||
print 'Ignore', ip
|
print 'Ignore', ip
|
||||||
continue
|
continue
|
||||||
|
if self.verbose:
|
||||||
print 'Found', ip, 'at', unixTime
|
print 'Found', ip, 'at', unixTime
|
||||||
if ipList.has_key(ip):
|
if ipList.has_key(ip):
|
||||||
ipList[ip] = (ipList[ip][0]+1, unixTime)
|
ipList[ip] = (ipList[ip][0]+1, unixTime)
|
||||||
|
|
Loading…
Reference in New Issue