diff --git a/fail2ban.py b/fail2ban.py index 2d65070e..2dd83f92 100755 --- a/fail2ban.py +++ b/fail2ban.py @@ -112,17 +112,16 @@ def restoreFwRules(): """ Flush the ban list """ logSys.warn("Restoring firewall rules...") - for element in logFwList: - try: + try: + for element in logFwList: + # Execute end command of each section element[2].flushBanList(conf["debug"]) - except ExternalError: - # nothing bad really - we can survive :-) - pass - # Execute end command of each section - for element in logFwList: - element[2].restore(conf["debug"]) - # Execute global end command - executeCmd(conf["cmdend"], conf["debug"]) + element[2].restore(conf["debug"]) + # Execute global end command + executeCmd(conf["cmdend"], conf["debug"]) + except ExternalError: + # nothing bad really - we can survive :-) + pass def killApp(): """ Flush the ban list, remove the PID lock file and exit @@ -393,7 +392,8 @@ def main(): lObj = LogReader(l["logfile"], l["timeregex"], l["timepattern"], l["failregex"], l["maxfailures"], l["findtime"]) # Creates a firewall object - fObj = Firewall(l["fwban"], l["fwunban"], l["fwcheck"], l["bantime"]) + fObj = Firewall(l["fwstart"], l["fwend"], + l["fwban"], l["fwunban"], l["fwcheck"], l["bantime"]) # Links them into a list. I'm not really happy # with this :/ logFwList.append([t, lObj, fObj, dict()]) diff --git a/firewall/firewall.py b/firewall/firewall.py index 04aac6e1..84f070d7 100644 --- a/firewall/firewall.py +++ b/firewall/firewall.py @@ -37,27 +37,16 @@ class Firewall: the IP. """ - def __init__(self, banRule, unBanRule, checkRule, banTime): + def __init__(self, startRule, endRule, + banRule, unBanRule, checkRule, banTime): self.banRule = banRule self.unBanRule = unBanRule self.checkRule = checkRule - self.startRule = "" - self.endRule = "" + self.startRule = startRule + self.endRule = endRule self.banTime = banTime self.banList = dict() - def setStartRule(self, cmd): - self.startRule = cmd - - def getStartRule(self): - return self.startRule - - def setEndRule(self, cmd): - self.endRule = cmd - - def getEndRule(self): - return self.endRule - def initialize(self, debug): logSys.debug("Initialize firewall rules") executeCmd(self.startRule, debug)