|
|
|
@ -243,6 +243,45 @@ class Actions(JailThread, Mapping):
|
|
|
|
|
logSys.debug(self._jail.name + ": action terminated")
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def __getBansMerged(self, mi, overalljails=False):
|
|
|
|
|
"""Gets bans merged once, a helper for lambda(s), prevents stop of executing action by any exception inside.
|
|
|
|
|
|
|
|
|
|
This function never returns None for ainfo lambdas - always a ticket (merged or single one)
|
|
|
|
|
and prevents any errors through merging (to guarantee ban actions will be executed).
|
|
|
|
|
[TODO] move merging to observer - here we could wait for merge and read already merged info from a database
|
|
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
|
----------
|
|
|
|
|
mi : dict
|
|
|
|
|
merge info, initial for lambda should contains {ip, ticket}
|
|
|
|
|
overalljails : bool
|
|
|
|
|
switch to get a merged bans :
|
|
|
|
|
False - (default) bans merged for current jail only
|
|
|
|
|
True - bans merged for all jails of current ip address
|
|
|
|
|
|
|
|
|
|
Returns
|
|
|
|
|
-------
|
|
|
|
|
BanTicket
|
|
|
|
|
merged or self ticket only
|
|
|
|
|
"""
|
|
|
|
|
idx = 'all' if overalljails else 'jail'
|
|
|
|
|
if idx in mi:
|
|
|
|
|
return mi[idx] if mi[idx] is not None else mi['ticket']
|
|
|
|
|
try:
|
|
|
|
|
jail=self._jail
|
|
|
|
|
ip=mi['ip']
|
|
|
|
|
mi[idx] = None
|
|
|
|
|
if overalljails:
|
|
|
|
|
mi[idx] = jail.database.getBansMerged(ip=ip)
|
|
|
|
|
else:
|
|
|
|
|
mi[idx] = jail.database.getBansMerged(ip=ip, jail=jail)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logSys.error(
|
|
|
|
|
"Failed to get %s bans merged, jail '%s': %s",
|
|
|
|
|
idx, jail.name, e,
|
|
|
|
|
exc_info=logSys.getEffectiveLevel()<=logging.DEBUG)
|
|
|
|
|
return mi[idx] if mi[idx] is not None else mi['ticket']
|
|
|
|
|
|
|
|
|
|
def __checkBan(self):
|
|
|
|
|
"""Check for IP address to ban.
|
|
|
|
|
|
|
|
|
@ -264,14 +303,12 @@ class Actions(JailThread, Mapping):
|
|
|
|
|
aInfo["time"] = bTicket.getTime()
|
|
|
|
|
aInfo["matches"] = "\n".join(bTicket.getMatches())
|
|
|
|
|
if self._jail.database is not None:
|
|
|
|
|
aInfo["ipmatches"] = lambda jail=self._jail: "\n".join(
|
|
|
|
|
jail.database.getBansMerged(ip=ip).getMatches())
|
|
|
|
|
aInfo["ipjailmatches"] = lambda jail=self._jail: "\n".join(
|
|
|
|
|
jail.database.getBansMerged(ip=ip, jail=jail).getMatches())
|
|
|
|
|
aInfo["ipfailures"] = lambda jail=self._jail: \
|
|
|
|
|
jail.database.getBansMerged(ip=ip).getAttempt()
|
|
|
|
|
aInfo["ipjailfailures"] = lambda jail=self._jail: \
|
|
|
|
|
jail.database.getBansMerged(ip=ip, jail=jail).getAttempt()
|
|
|
|
|
mi4ip = lambda overalljails=False, self=self, \
|
|
|
|
|
mi={'ip':ip, 'ticket':bTicket}: self.__getBansMerged(mi, overalljails)
|
|
|
|
|
aInfo["ipmatches"] = lambda: "\n".join(mi4ip(True).getMatches())
|
|
|
|
|
aInfo["ipjailmatches"] = lambda: "\n".join(mi4ip().getMatches())
|
|
|
|
|
aInfo["ipfailures"] = lambda: mi4ip(True).getAttempt()
|
|
|
|
|
aInfo["ipjailfailures"] = lambda: mi4ip().getAttempt()
|
|
|
|
|
if self.__banManager.addBanTicket(bTicket):
|
|
|
|
|
logSys.notice("[%s] Ban %s" % (self._jail.name, aInfo["ip"]))
|
|
|
|
|
for name, action in self._actions.iteritems():
|
|
|
|
|