def runThreads(configpath): config = getConfig(configpath) #TODO make iptables_lock optional iptables_lock = threading.Lock() cleaner = None if config["bantime"] != 0: cleaner = BanCleaner(config["bantime"], config["backend"], iptables_lock, config["interface"]) banner = BanFetcher(config["bindstrings"], config["interface"], config["backend"], iptables_lock) def handleSignal(signum, frame): if signum == 15 or signum == 16: banner.stopIt() if config["bantime"]: cleaner.stopIt() logging.warning("Closing on SIGTERM") signal.signal(signal.SIGTERM, handleSignal) try: if config["bantime"] != 0: cleaner.start() logging.warning("Started running cleaner") banner.start() logging.warning("Started running banner") except Exception as e: print "Exception %s" % e logging.error("Swabber exiting on exception %s!", str(e)) if config["bantime"]: cleaner.stopIt() banner.stopIt()
def testClean(self): ban_len = 1 bantime = datetime.timedelta(minutes=(ban_len*2)) ban = BanEntry(BAN_IP, datetime.datetime.now() - bantime) session.add(ban) session.commit() ban.ban(INTERFACE) cleaner = BanCleaner(db_conn, ban_len) cleaner.cleanBans() status, output = commands.getstatusoutput("/sbin/iptables -L -n") self.assertNotIn(BAN_IP, output, msg="Ban was not reset by cleaner")