本文整理汇总了Python中banmanager.BanManager类的典型用法代码示例。如果您正苦于以下问题:Python BanManager类的具体用法?Python BanManager怎么用?Python BanManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BanManager类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, jail):
JailThread.__init__(self)
self.jail = jail
self.__actions = list()
self.__banManager = BanManager()
示例2: __init__
def __init__(self, jail):
JailThread.__init__(self)
## The jail which contains this action.
self.jail = jail
self.__actions = list()
## The ban manager.
self.__banManager = BanManager()
示例3: __checkBan
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
示例4: Actions
class Actions(JailThread):
def __init__(self, jail):
JailThread.__init__(self)
self.jail = jail
self.__actions = list()
self.__banManager = BanManager()
def addAction(self, name):
action = Action(name)
self.__actions.append(action)
def delAction(self, name):
for action in self.__actions:
if action.getName() == name:
self.__actions.remove(action)
break
def getAction(self, name):
for action in self.__actions:
if action.getName() == name:
return action
raise KeyError
def getLastAction(self):
action = self.__actions.pop()
self.__actions.append(action)
return action
def setBanTime(self, value):
self.__banManager.setBanTime(value)
logSys.info("Set banTime = %s" % value)
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()
#.........这里部分代码省略.........
示例5: Actions
class Actions(JailThread):
##
# Constructor.
#
# Initialize the filter object with default values.
# @param jail the jail object
def __init__(self, jail):
JailThread.__init__(self)
## The jail which contains this action.
self.jail = jail
self.__actions = list()
## The ban manager.
self.__banManager = BanManager()
##
# Adds an action.
#
# @param name The action name
def addAction(self, name):
action = Action(name)
self.__actions.append(action)
##
# Removes an action.
#
# @param name The action name
def delAction(self, name):
for action in self.__actions:
if action.getName() == name:
self.__actions.remove(action)
break
##
# Returns an action.
#
# Raises a KeyError exception if the action does not exist.
#
# @param name the action name
# @return the action
def getAction(self, name):
for action in self.__actions:
if action.getName() == name:
return action
raise KeyError
##
# Returns the last defined action.
#
# @return The last defined action.
def getLastAction(self):
action = self.__actions.pop()
self.__actions.append(action)
return action
##
# Set the ban time.
#
# @param value the time
def setBanTime(self, value):
self.__banManager.setBanTime(value)
logSys.info("Set banTime = %s" % value)
##
# Get the ban time.
#
# @return the time
def getBanTime(self):
return self.__banManager.getBanTime()
##
# 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()
#.........这里部分代码省略.........