def toBan(self): try: self.__lock.acquire() for ip in self.__failList: data = self.__failList[ip] if data.getRetry() >= self.__maxRetry: self.__delFailure(ip) # Create a FailTicket from BanData failTicket = FailTicket(ip, data.getLastTime(), data.getMatches()) failTicket.setAttempt(data.getRetry()) return failTicket raise FailManagerEmpty finally: self.__lock.release()
def addBannedIP(self, ip): unixTime = MyTime.time() for i in xrange(self.failManager.getMaxRetry()): self.failManager.addFailure(FailTicket(ip, unixTime)) # Perform the banning of the IP now. try: # pragma: no branch - exception is the only way out while True: ticket = self.failManager.toBan() self.jail.putFailTicket(ticket) except FailManagerEmpty: self.failManager.cleanup(MyTime.time()) return ip
def processLineAndAdd(self, line): for element in self.processLine(line): ip = element[0] unixTime = element[1] logSys.debug("Processing line with time:%s and ip:%s" % (unixTime, ip)) if unixTime < MyTime.time() - self.getFindTime(): logSys.debug("Ignore line since time %s < %s - %s" % (unixTime, MyTime.time(), self.getFindTime())) break if self.inIgnoreIPList(ip): logSys.debug("Ignore %s" % ip) continue logSys.debug("Found %s" % ip) self.failManager.addFailure(FailTicket(ip, unixTime, [line]))
def processLineAndAdd(self, line): try: # Decode line to UTF-8 l = line.decode('utf-8') except UnicodeDecodeError: l = line for element in self.findFailure(l): ip = element[0] unixTime = element[1] if unixTime < MyTime.time() - self.getFindTime(): break if self.inIgnoreIPList(ip): logSys.debug("Ignore %s" % ip) continue logSys.debug("Found %s" % ip) self.failManager.addFailure(FailTicket(ip, unixTime))
def addBannedIP(self, ip): if self.inIgnoreIPList(ip): logSys.warning('Requested to manually ban an ignored IP %s. User knows best. Proceeding to ban it.' % ip) unixTime = MyTime.time() for i in xrange(self.failManager.getMaxRetry()): self.failManager.addFailure(FailTicket(ip, unixTime)) # Perform the banning of the IP now. try: # pragma: no branch - exception is the only way out while True: ticket = self.failManager.toBan() self.jail.putFailTicket(ticket) except FailManagerEmpty: self.failManager.cleanup(MyTime.time()) return ip
def processLineAndAdd(self, line): """Processes the line for failures and populates failManager """ for element in self.processLine(line)[1]: failregex = element[0] ip = element[1] unixTime = element[2] logSys.debug("Processing line with time:%s and ip:%s" % (unixTime, ip)) if unixTime < MyTime.time() - self.getFindTime(): logSys.debug("Ignore line since time %s < %s - %s" % (unixTime, MyTime.time(), self.getFindTime())) break if self.inIgnoreIPList(ip): logSys.debug("Ignore %s" % ip) continue logSys.debug("Found %s" % ip) ## print "D: Adding a ticket for %s" % ((ip, unixTime, [line]),) self.failManager.addFailure(FailTicket(ip, unixTime, [line]))
def addBannedIP(self, ip): unixTime = time.time() for i in xrange(self.failManager.getMaxRetry()): self.failManager.addFailure(FailTicket(ip, unixTime)) return ip
def addBannedIP(self, ip): unixTime = time.time() self.failManager.addFailure(FailTicket(ip, unixTime)) return ip