当前位置: 首页>>代码示例>>Python>>正文


Python BanManager.unBanList方法代码示例

本文整理汇总了Python中banmanager.BanManager.unBanList方法的典型用法代码示例。如果您正苦于以下问题:Python BanManager.unBanList方法的具体用法?Python BanManager.unBanList怎么用?Python BanManager.unBanList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在banmanager.BanManager的用法示例。


在下文中一共展示了BanManager.unBanList方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Actions

# 需要导入模块: from banmanager import BanManager [as 别名]
# 或者: from banmanager.BanManager import unBanList [as 别名]

#.........这里部分代码省略.........
	def getBanTime(self):
		return self.__banManager.getBanTime()
	
	
	
	
	
	
	
	
	def run(self):
		self.setActive(True)
		for action in self.__actions:
			action.execActionStart()
		while self._isActive():
			if not self.getIdle():
				
				ret = self.__checkBan()
				if not ret:
					self.__checkUnBan()
					time.sleep(self.getSleepTime())
			else:
				time.sleep(self.getSleepTime())
		self.__flushBan()
		for action in self.__actions:
			action.execActionStop()
		logSys.debug(self.jail.getName() + ": action terminated")
		return True
	
	
	
	
	
	
	
	def __checkBan(self):
		ticket = self.jail.getFailTicket()
		if ticket != False:
			aInfo = dict()
			bTicket = BanManager.createBanTicket(ticket)
			aInfo["ip"] = bTicket.getIP()
			aInfo["failures"] = bTicket.getAttempt()
			aInfo["time"] = bTicket.getTime()
			if self.__banManager.addBanTicket(bTicket):
				logSys.warn("[%s] Ban %s" % (self.jail.getName(), aInfo["ip"]))
				for action in self.__actions:
					action.execActionBan(aInfo)
				return True
			else:
				logSys.warn("[%s] %s already banned" % (self.jail.getName(), 
														aInfo["ip"]))
		return False
	
	
	
	
	
	
	def __checkUnBan(self):
		for ticket in self.__banManager.unBanList(MyTime.time()):
			self.__unBan(ticket)
	
	
	
	
	
	
	def __flushBan(self):
		logSys.debug("Flush ban list")
		for ticket in self.__banManager.flushBanList():
			self.__unBan(ticket)
	
	
	
	
	
	
	
	def __unBan(self, ticket):
		aInfo = dict()
		aInfo["ip"] = ticket.getIP()
		aInfo["failures"] = ticket.getAttempt()
		aInfo["time"] = ticket.getTime()
		logSys.warn("[%s] Unban %s" % (self.jail.getName(), aInfo["ip"]))
		for action in self.__actions:
			action.execActionUnban(aInfo)
			
	
	
	
	
	
	
	
	
	def status(self):
		ret = [("Currently banned", self.__banManager.size()), 
			   ("Total banned", self.__banManager.getBanTotal()),
			   ("IP list", self.__banManager.getBanList())]
		return ret
开发者ID:,项目名称:,代码行数:104,代码来源:

示例2: Actions

# 需要导入模块: from banmanager import BanManager [as 别名]
# 或者: from banmanager.BanManager import unBanList [as 别名]

#.........这里部分代码省略.........
	##
	# Main loop.
	#
	# This function is the main loop of the thread. It checks the Jail
	# queue and executes commands when an IP address is banned.
	# @return True when the thread exits nicely
	
	def run(self):
		self.setActive(True)
		for action in self.__actions:
			action.execActionStart()
		while self._isActive():
			if not self.getIdle():
				#logSys.debug(self.jail.getName() + ": action")
				ret = self.__checkBan()
				if not ret:
					self.__checkUnBan()
					time.sleep(self.getSleepTime())
			else:
				time.sleep(self.getSleepTime())
		self.__flushBan()
		for action in self.__actions:
			action.execActionStop()
		logSys.debug(self.jail.getName() + ": action terminated")
		return True

	##
	# Check for IP address to ban.
	#
	# Look in the Jail queue for FailTicket. If a ticket is available,
	# it executes the "ban" command and add a ticket to the BanManager.
	# @return True if an IP address get banned
	
	def __checkBan(self):
		ticket = self.jail.getFailTicket()
		if ticket != False:
			aInfo = dict()
			bTicket = BanManager.createBanTicket(ticket)
			aInfo["ip"] = bTicket.getIP()
			aInfo["failures"] = bTicket.getAttempt()
			aInfo["time"] = bTicket.getTime()
			aInfo["matches"] = "".join(bTicket.getMatches())
			if self.__banManager.addBanTicket(bTicket):
				logSys.warn("[%s] Ban %s" % (self.jail.getName(), aInfo["ip"]))
				for action in self.__actions:
					action.execActionBan(aInfo)
				return True
			else:
				logSys.warn("[%s] %s already banned" % (self.jail.getName(), 
														aInfo["ip"]))
		return False
	
	##
	# Check for IP address to unban.
	#
	# Unban IP address which are outdated.
	
	def __checkUnBan(self):
		for ticket in self.__banManager.unBanList(MyTime.time()):
			self.__unBan(ticket)
	
	##
	# Flush the ban list.
	#
	# Unban all IP address which are still in the banning list.
	
	def __flushBan(self):
		logSys.debug("Flush ban list")
		for ticket in self.__banManager.flushBanList():
			self.__unBan(ticket)
	
	##
	# Unbans host corresponding to the ticket.
	#
	# Executes the actions in order to unban the host given in the
	# ticket.
	
	def __unBan(self, ticket):
		aInfo = dict()
		aInfo["ip"] = ticket.getIP()
		aInfo["failures"] = ticket.getAttempt()
		aInfo["time"] = ticket.getTime()
		aInfo["matches"] = "".join(ticket.getMatches())
		logSys.warn("[%s] Unban %s" % (self.jail.getName(), aInfo["ip"]))
		for action in self.__actions:
			action.execActionUnban(aInfo)
			
	
	##
	# Get the status of the filter.
	#
	# Get some informations about the filter state such as the total
	# number of failures.
	# @return a list with tuple
	
	def status(self):
		ret = [("Currently banned", self.__banManager.size()), 
			   ("Total banned", self.__banManager.getBanTotal()),
			   ("IP list", self.__banManager.getBanList())]
		return ret
开发者ID:JohnyByk,项目名称:fail2ban,代码行数:104,代码来源:actions.py


注:本文中的banmanager.BanManager.unBanList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。