action.d/badips.py: fix start of banaction on demand (which may be IP-family related), supplied action info with ticket instead of simulating it with dict;

(closes gh-2390)
pull/2448/head
sebres 2019-06-12 11:23:52 +02:00
parent 2725acb64b
commit 22b9304562
1 changed files with 5 additions and 15 deletions

View File

@ -31,7 +31,7 @@ else: # pragma: 3.x no cover
from urllib2 import Request, urlopen, HTTPError from urllib2 import Request, urlopen, HTTPError
from urllib import urlencode from urllib import urlencode
from fail2ban.server.actions import ActionBase from fail2ban.server.actions import Actions, ActionBase, BanTicket
from fail2ban.helpers import splitwords, str2LogLevel from fail2ban.helpers import splitwords, str2LogLevel
@ -286,13 +286,8 @@ class BadIPsAction(ActionBase): # pragma: no cover - may be unavailable
def _banIPs(self, ips): def _banIPs(self, ips):
for ip in ips: for ip in ips:
try: try:
self._jail.actions[self.banaction].ban({ ai = Actions.ActionInfo(BanTicket(ip), self._jail)
'ip': ip, self._jail.actions[self.banaction].ban(ai)
'failures': 0,
'matches': "",
'ipmatches': "",
'ipjailmatches': "",
})
except Exception as e: except Exception as e:
self._logSys.error( self._logSys.error(
"Error banning IP %s for jail '%s' with action '%s': %s", "Error banning IP %s for jail '%s' with action '%s': %s",
@ -307,13 +302,8 @@ class BadIPsAction(ActionBase): # pragma: no cover - may be unavailable
def _unbanIPs(self, ips): def _unbanIPs(self, ips):
for ip in ips: for ip in ips:
try: try:
self._jail.actions[self.banaction].unban({ ai = Actions.ActionInfo(BanTicket(ip), self._jail)
'ip': ip, self._jail.actions[self.banaction].unban(ai)
'failures': 0,
'matches': "",
'ipmatches': "",
'ipjailmatches': "",
})
except Exception as e: except Exception as e:
self._logSys.error( self._logSys.error(
"Error unbanning IP %s for jail '%s' with action '%s': %s", "Error unbanning IP %s for jail '%s' with action '%s': %s",