mirror of https://github.com/fail2ban/fail2ban
unbanip always deletes ip from database (independent of bantime, also if currently not banned or persistent);
merged from #716 where it works; closes gh-972, closes gh-768pull/716/head^2
parent
00d8779f87
commit
95c2a2976f
|
@ -28,6 +28,8 @@ ver. 0.9.3 (2015/XX/XXX) - wanna-be-released
|
||||||
locale on systems with customized LC_ALL
|
locale on systems with customized LC_ALL
|
||||||
* performance fix: minimizes connection overhead, close socket only at
|
* performance fix: minimizes connection overhead, close socket only at
|
||||||
communication end (gh-1099)
|
communication end (gh-1099)
|
||||||
|
* unbanip always deletes ip from database (independent of bantime, also if
|
||||||
|
currently not banned or persistent)
|
||||||
|
|
||||||
- New Features:
|
- New Features:
|
||||||
* New filters:
|
* New filters:
|
||||||
|
|
|
@ -194,13 +194,14 @@ class Actions(JailThread, Mapping):
|
||||||
ValueError
|
ValueError
|
||||||
If `ip` is not banned
|
If `ip` is not banned
|
||||||
"""
|
"""
|
||||||
|
# Always delete ip from database (also if currently not banned)
|
||||||
|
if self._jail.database is not None:
|
||||||
|
self._jail.database.delBan(self._jail, ip)
|
||||||
# Find the ticket with the IP.
|
# Find the ticket with the IP.
|
||||||
ticket = self.__banManager.getTicketByIP(ip)
|
ticket = self.__banManager.getTicketByIP(ip)
|
||||||
if ticket is not None:
|
if ticket is not None:
|
||||||
# Unban the IP.
|
# Unban the IP.
|
||||||
self.__unBan(ticket)
|
self.__unBan(ticket)
|
||||||
if self._jail.database is not None:
|
|
||||||
self._jail.database.delBan(self._jail, ticket)
|
|
||||||
else:
|
else:
|
||||||
raise ValueError("IP %s is not banned" % ip)
|
raise ValueError("IP %s is not banned" % ip)
|
||||||
|
|
||||||
|
|
|
@ -418,19 +418,20 @@ class Fail2BanDb(object):
|
||||||
"failures": ticket.getAttempt()}))
|
"failures": ticket.getAttempt()}))
|
||||||
|
|
||||||
@commitandrollback
|
@commitandrollback
|
||||||
def delBan(self, cur, jail, ticket):
|
def delBan(self, cur, jail, ip):
|
||||||
"""Delete a ban from the database.
|
"""Delete a ban from the database.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
jail : Jail
|
jail : Jail
|
||||||
Jail in which the ban has occurred.
|
Jail in which the ban has occurred.
|
||||||
ticket : BanTicket
|
ip : str
|
||||||
Ticket of the ban to be removed.
|
IP to be removed.
|
||||||
"""
|
"""
|
||||||
|
queryArgs = (jail.name, ip);
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"DELETE FROM bans WHERE jail = ? AND ip = ? AND timeofban = ?",
|
"DELETE FROM bans WHERE jail = ? AND ip = ?",
|
||||||
(jail.name, ticket.getIP(), int(round(ticket.getTime()))))
|
queryArgs);
|
||||||
|
|
||||||
@commitandrollback
|
@commitandrollback
|
||||||
def _getBans(self, cur, jail=None, bantime=None, ip=None):
|
def _getBans(self, cur, jail=None, bantime=None, ip=None):
|
||||||
|
|
|
@ -212,7 +212,7 @@ class DatabaseTest(LogCaptureTestCase):
|
||||||
def testDelBan(self):
|
def testDelBan(self):
|
||||||
self.testAddBan()
|
self.testAddBan()
|
||||||
ticket = self.db.getBans(jail=self.jail)[0]
|
ticket = self.db.getBans(jail=self.jail)[0]
|
||||||
self.db.delBan(self.jail, ticket)
|
self.db.delBan(self.jail, ticket.getIP())
|
||||||
self.assertEqual(len(self.db.getBans(jail=self.jail)), 0)
|
self.assertEqual(len(self.db.getBans(jail=self.jail)), 0)
|
||||||
|
|
||||||
def testGetBansWithTime(self):
|
def testGetBansWithTime(self):
|
||||||
|
|
Loading…
Reference in New Issue