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
|
||||
* performance fix: minimizes connection overhead, close socket only at
|
||||
communication end (gh-1099)
|
||||
* unbanip always deletes ip from database (independent of bantime, also if
|
||||
currently not banned or persistent)
|
||||
|
||||
- New Features:
|
||||
* New filters:
|
||||
|
|
|
@ -194,13 +194,14 @@ class Actions(JailThread, Mapping):
|
|||
ValueError
|
||||
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.
|
||||
ticket = self.__banManager.getTicketByIP(ip)
|
||||
if ticket is not None:
|
||||
# Unban the IP.
|
||||
self.__unBan(ticket)
|
||||
if self._jail.database is not None:
|
||||
self._jail.database.delBan(self._jail, ticket)
|
||||
else:
|
||||
raise ValueError("IP %s is not banned" % ip)
|
||||
|
||||
|
|
|
@ -418,19 +418,20 @@ class Fail2BanDb(object):
|
|||
"failures": ticket.getAttempt()}))
|
||||
|
||||
@commitandrollback
|
||||
def delBan(self, cur, jail, ticket):
|
||||
def delBan(self, cur, jail, ip):
|
||||
"""Delete a ban from the database.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
jail : Jail
|
||||
Jail in which the ban has occurred.
|
||||
ticket : BanTicket
|
||||
Ticket of the ban to be removed.
|
||||
ip : str
|
||||
IP to be removed.
|
||||
"""
|
||||
queryArgs = (jail.name, ip);
|
||||
cur.execute(
|
||||
"DELETE FROM bans WHERE jail = ? AND ip = ? AND timeofban = ?",
|
||||
(jail.name, ticket.getIP(), int(round(ticket.getTime()))))
|
||||
"DELETE FROM bans WHERE jail = ? AND ip = ?",
|
||||
queryArgs);
|
||||
|
||||
@commitandrollback
|
||||
def _getBans(self, cur, jail=None, bantime=None, ip=None):
|
||||
|
|
|
@ -212,7 +212,7 @@ class DatabaseTest(LogCaptureTestCase):
|
|||
def testDelBan(self):
|
||||
self.testAddBan()
|
||||
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)
|
||||
|
||||
def testGetBansWithTime(self):
|
||||
|
|
Loading…
Reference in New Issue