mirror of https://github.com/fail2ban/fail2ban
few confusing merge info helper
parent
46a8899f20
commit
92ba5ae09c
|
@ -243,7 +243,7 @@ class Actions(JailThread, Mapping):
|
||||||
logSys.debug(self._jail.name + ": action terminated")
|
logSys.debug(self._jail.name + ": action terminated")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def __getBansMerged(self, mi, idx):
|
def __getBansMerged(self, mi, overalljails=False):
|
||||||
"""Gets bans merged once, a helper for lambda(s), prevents stop of executing action by any exception inside.
|
"""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)
|
This function never returns None for ainfo lambdas - always a ticket (merged or single one)
|
||||||
|
@ -253,29 +253,28 @@ class Actions(JailThread, Mapping):
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
mi : dict
|
mi : dict
|
||||||
initial for lambda should contains {ip, ticket}
|
merge info, initial for lambda should contains {ip, ticket}
|
||||||
idx : str
|
overalljails : bool
|
||||||
key to get a merged bans :
|
switch to get a merged bans :
|
||||||
'all' - bans merged for all jails
|
False - (default) bans merged for current jail only
|
||||||
'jail' - bans merged for current jail only
|
True - bans merged for all jails of current ip address
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
BanTicket
|
BanTicket
|
||||||
merged or self ticket only
|
merged or self ticket only
|
||||||
"""
|
"""
|
||||||
|
idx = 'all' if overalljails else 'jail'
|
||||||
if idx in mi:
|
if idx in mi:
|
||||||
return mi[idx] if mi[idx] is not None else mi['ticket']
|
return mi[idx] if mi[idx] is not None else mi['ticket']
|
||||||
try:
|
try:
|
||||||
jail=self._jail
|
jail=self._jail
|
||||||
ip=mi['ip']
|
ip=mi['ip']
|
||||||
mi[idx] = None
|
mi[idx] = None
|
||||||
if idx == 'all':
|
if overalljails:
|
||||||
mi[idx] = jail.database.getBansMerged(ip=ip)
|
mi[idx] = jail.database.getBansMerged(ip=ip)
|
||||||
elif idx == 'jail':
|
else:
|
||||||
mi[idx] = jail.database.getBansMerged(ip=ip, jail=jail)
|
mi[idx] = jail.database.getBansMerged(ip=ip, jail=jail)
|
||||||
else: # pragma: no cover
|
|
||||||
raise ValueError("Unknown value %r for idx" % (idx,))
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logSys.error(
|
logSys.error(
|
||||||
"Failed to get %s bans merged, jail '%s': %s",
|
"Failed to get %s bans merged, jail '%s': %s",
|
||||||
|
@ -304,11 +303,12 @@ class Actions(JailThread, Mapping):
|
||||||
aInfo["time"] = bTicket.getTime()
|
aInfo["time"] = bTicket.getTime()
|
||||||
aInfo["matches"] = "\n".join(bTicket.getMatches())
|
aInfo["matches"] = "\n".join(bTicket.getMatches())
|
||||||
if self._jail.database is not None:
|
if self._jail.database is not None:
|
||||||
mi4ip = lambda idx, self=self, mi={'ip':ip, 'ticket':bTicket}: self.__getBansMerged(mi, idx)
|
mi4ip = lambda overalljails=False, self=self, \
|
||||||
aInfo["ipmatches"] = lambda: "\n".join(mi4ip('all').getMatches())
|
mi={'ip':ip, 'ticket':bTicket}: self.__getBansMerged(mi, overalljails)
|
||||||
aInfo["ipjailmatches"] = lambda: "\n".join(mi4ip('jail').getMatches())
|
aInfo["ipmatches"] = lambda: "\n".join(mi4ip(True).getMatches())
|
||||||
aInfo["ipfailures"] = lambda: mi4ip('all').getAttempt()
|
aInfo["ipjailmatches"] = lambda: "\n".join(mi4ip().getMatches())
|
||||||
aInfo["ipjailfailures"] = lambda: mi4ip('jail').getAttempt()
|
aInfo["ipfailures"] = lambda: mi4ip(True).getAttempt()
|
||||||
|
aInfo["ipjailfailures"] = lambda: mi4ip().getAttempt()
|
||||||
if self.__banManager.addBanTicket(bTicket):
|
if self.__banManager.addBanTicket(bTicket):
|
||||||
logSys.notice("[%s] Ban %s" % (self._jail.name, aInfo["ip"]))
|
logSys.notice("[%s] Ban %s" % (self._jail.name, aInfo["ip"]))
|
||||||
for name, action in self._actions.iteritems():
|
for name, action in self._actions.iteritems():
|
||||||
|
|
Loading…
Reference in New Issue