mirror of https://github.com/fail2ban/fail2ban
flush jail in database: bulk remove of all IPs in the database (e. g. reload --unban).
parent
1e39c2600c
commit
2c69c0e7e5
|
@ -450,7 +450,7 @@ class Actions(JailThread, Mapping):
|
||||||
"""
|
"""
|
||||||
log = True
|
log = True
|
||||||
if actions is None:
|
if actions is None:
|
||||||
logSys.debug("Flush ban list")
|
logSys.debug(" Flush ban list")
|
||||||
lst = self.__banManager.flushBanList()
|
lst = self.__banManager.flushBanList()
|
||||||
else:
|
else:
|
||||||
log = False # don't log "[jail] Unban ..." if removing actions only.
|
log = False # don't log "[jail] Unban ..." if removing actions only.
|
||||||
|
@ -465,16 +465,16 @@ class Actions(JailThread, Mapping):
|
||||||
else:
|
else:
|
||||||
unbactions[name] = action
|
unbactions[name] = action
|
||||||
actions = unbactions
|
actions = unbactions
|
||||||
|
# flush the database also:
|
||||||
|
if db and self._jail.database is not None:
|
||||||
|
logSys.debug(" Flush jail in database")
|
||||||
|
self._jail.database.delBan(self._jail)
|
||||||
# unban each ticket with non-flasheable actions:
|
# unban each ticket with non-flasheable actions:
|
||||||
for ticket in lst:
|
for ticket in lst:
|
||||||
# delete ip from database also:
|
|
||||||
if db and self._jail.database is not None:
|
|
||||||
ip = str(ticket.getIP())
|
|
||||||
self._jail.database.delBan(self._jail, ip)
|
|
||||||
# unban ip:
|
# unban ip:
|
||||||
self.__unBan(ticket, actions=actions, log=log)
|
self.__unBan(ticket, actions=actions, log=log)
|
||||||
cnt += 1
|
cnt += 1
|
||||||
logSys.debug("Unbanned %s, %s ticket(s) in %r",
|
logSys.debug(" Unbanned %s, %s ticket(s) in %r",
|
||||||
cnt, self.__banManager.size(), self._jail.name)
|
cnt, self.__banManager.size(), self._jail.name)
|
||||||
return cnt
|
return cnt
|
||||||
|
|
||||||
|
|
|
@ -533,20 +533,26 @@ class Fail2BanDb(object):
|
||||||
ticket.getData()))
|
ticket.getData()))
|
||||||
|
|
||||||
@commitandrollback
|
@commitandrollback
|
||||||
def delBan(self, cur, jail, ip):
|
def delBan(self, cur, jail, *args):
|
||||||
"""Delete a ban from the database.
|
"""Delete a single or multiple tickets from the database.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
jail : Jail
|
jail : Jail
|
||||||
Jail in which the ban has occurred.
|
Jail in which the ticket(s) should be removed.
|
||||||
ip : str
|
args : list of IP
|
||||||
IP to be removed.
|
IPs to be removed, if not given all tickets of jail will be removed.
|
||||||
"""
|
"""
|
||||||
queryArgs = (jail.name, str(ip));
|
query = "DELETE FROM bans WHERE jail = ?"
|
||||||
cur.execute(
|
queryArgs = [jail.name];
|
||||||
"DELETE FROM bans WHERE jail = ? AND ip = ?",
|
if not len(args):
|
||||||
queryArgs);
|
cur.execute(query, queryArgs);
|
||||||
|
return
|
||||||
|
query += " AND ip = ?"
|
||||||
|
queryArgs.append('');
|
||||||
|
for ip in args:
|
||||||
|
queryArgs[1] = str(ip);
|
||||||
|
cur.execute(query, queryArgs);
|
||||||
|
|
||||||
@commitandrollback
|
@commitandrollback
|
||||||
def _getBans(self, cur, jail=None, bantime=None, ip=None):
|
def _getBans(self, cur, jail=None, bantime=None, ip=None):
|
||||||
|
|
Loading…
Reference in New Issue