From 22b93045629f207a5352be8abfc099024f0eab0d Mon Sep 17 00:00:00 2001 From: sebres Date: Wed, 12 Jun 2019 11:23:52 +0200 Subject: [PATCH 1/2] 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) --- config/action.d/badips.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/config/action.d/badips.py b/config/action.d/badips.py index e5de7555..a5fa1809 100644 --- a/config/action.d/badips.py +++ b/config/action.d/badips.py @@ -31,7 +31,7 @@ else: # pragma: 3.x no cover from urllib2 import Request, urlopen, HTTPError from urllib import urlencode -from fail2ban.server.actions import ActionBase +from fail2ban.server.actions import Actions, ActionBase, BanTicket from fail2ban.helpers import splitwords, str2LogLevel @@ -286,13 +286,8 @@ class BadIPsAction(ActionBase): # pragma: no cover - may be unavailable def _banIPs(self, ips): for ip in ips: try: - self._jail.actions[self.banaction].ban({ - 'ip': ip, - 'failures': 0, - 'matches': "", - 'ipmatches': "", - 'ipjailmatches': "", - }) + ai = Actions.ActionInfo(BanTicket(ip), self._jail) + self._jail.actions[self.banaction].ban(ai) except Exception as e: self._logSys.error( "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): for ip in ips: try: - self._jail.actions[self.banaction].unban({ - 'ip': ip, - 'failures': 0, - 'matches': "", - 'ipmatches': "", - 'ipjailmatches': "", - }) + ai = Actions.ActionInfo(BanTicket(ip), self._jail) + self._jail.actions[self.banaction].unban(ai) except Exception as e: self._logSys.error( "Error unbanning IP %s for jail '%s' with action '%s': %s", From 4c81338944962933523daa1b0a0bbb9a06d1f6cd Mon Sep 17 00:00:00 2001 From: sebres Date: Wed, 12 Jun 2019 11:28:19 +0200 Subject: [PATCH 2/2] update ChangeLog (gh-2390) --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index 668842cf..1ae33fff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -46,6 +46,7 @@ ver. 0.10.5-dev-1 (20??/??/??) - development edition * fixed read of included config-files (`.local` overwrites options of `.conf` for config-files included with before/after) * `action.d/abuseipdb.conf`: switched to use AbuseIPDB API v2 (gh-2302) +* `action.d/badips.py`: fixed start of banaction on demand (which may be IP-family related), gh-2390 * `action.d/helpers-common.conf`: rewritten grep arguments, now options `-wF` used to match only whole words and fixed string (not as pattern), gh-2298 * `filter.d/sshd.conf`: