- Added a killApp() function

- Dict iteration improved


git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@77 a942ae1a-1317-0410-a47c-b1dcaea8d605
0.6
Cyril Jaquier 2005-03-06 17:44:48 +00:00
parent bc4524c165
commit 1a876366a7
1 changed files with 15 additions and 17 deletions

View File

@ -152,15 +152,22 @@ def createDaemon():
os.open("/dev/null", os.O_RDWR) # standard output (1) os.open("/dev/null", os.O_RDWR) # standard output (1)
os.open("/dev/null", os.O_RDWR) # standard error (2) os.open("/dev/null", os.O_RDWR) # standard error (2)
return(0) return True
def sigTERMhandler(signum, frame): def sigTERMhandler(signum, frame):
""" Handles the TERM signal when in daemon mode in order to """ Handles the TERM signal when in daemon mode in order to
exit properly. exit properly.
""" """
logSys.debug("Signal handler called with sig "+`signum`) logSys.debug("Signal handler called with sig "+`signum`)
logSys.info("Restoring iptables...") killApp()
def killApp():
""" Flush the ban list, remove the PID lock file and exit
nicely.
"""
logSys.warn("Restoring firewall rules...")
fireWall.flushBanList(conf["debug"]) fireWall.flushBanList(conf["debug"])
removePID(conf["pidlock"])
logSys.info("Exiting...") logSys.info("Exiting...")
sys.exit(0) sys.exit(0)
@ -467,7 +474,7 @@ if __name__ == "__main__":
for element in logList: for element in logList:
element.addIgnoreIP(ip) element.addIgnoreIP(ip)
logSys.warn("Fail2Ban v"+version+" is running") logSys.info("Fail2Ban v"+version+" is running")
# Main loop # Main loop
while True: while True:
try: try:
@ -495,9 +502,7 @@ if __name__ == "__main__":
failList = dict() failList = dict()
for element in modList: for element in modList:
e = element.getFailures() e = element.getFailures()
iter = e.iterkeys() for key in e.iterkeys():
for i in range(len(e)):
key = iter.next()
if failList.has_key(key): if failList.has_key(key):
if failList[key][0] < e[key][0]: if failList[key][0] < e[key][0]:
failList[key] = (e[key][0], e[key][1], failList[key] = (e[key][0], e[key][1],
@ -509,19 +514,12 @@ if __name__ == "__main__":
# We iterate the failure list and ban IP that make # We iterate the failure list and ban IP that make
# *retryAllowed* login failures. # *retryAllowed* login failures.
iterFailList = failList.iteritems() for element in failList.iteritems():
for i in range(len(failList)):
element = iterFailList.next()
if element[1][0] >= conf["maxretry"]: if element[1][0] >= conf["maxretry"]:
logSys.warn(`element[1][2]`+": "+element[0]+" has "+ logSys.info(`element[1][2]`+": "+element[0]+" has "+
`element[1][0]`+" login failure(s). Banned.") `element[1][0]`+" login failure(s). Banned.")
fireWall.addBanIP(element[0], conf["debug"]) fireWall.addBanIP(element[0], conf["debug"])
except KeyboardInterrupt: except KeyboardInterrupt:
# When the user press <ctrl>+<c> we flush the ban list # When the user press <ctrl>+<c> we exit nicely.
# and exit nicely. killApp()
logSys.info("Restoring firewall rules...")
fireWall.flushBanList(conf["debug"])
removePID(conf["pidlock"])
logSys.warn("Exiting...")
sys.exit(0)