mirror of https://github.com/fail2ban/fail2ban
Added in command option to unban and IP, just like using 'banip'. Command looks like: fail2ban-client set <jail name> unbanip <ip>
parent
8e64c281dd
commit
6288ec2757
|
@ -120,6 +120,19 @@ class Actions(JailThread):
|
|||
def getBanTime(self):
|
||||
return self.__banManager.getBanTime()
|
||||
|
||||
##
|
||||
# Remove a banned IP now, rather than waiting for it to expire, even if set to never expire.
|
||||
#
|
||||
# @return the IP string or 'None' if not unbanned.
|
||||
def removeBannedIP(self, ip):
|
||||
# Find the ticket with the IP.
|
||||
ticket = self.__banManager.getTicketByIP(ip)
|
||||
if ticket != False:
|
||||
# Unban the IP.
|
||||
self.__unBan(ticket)
|
||||
return ip
|
||||
return 'None'
|
||||
|
||||
##
|
||||
# Main loop.
|
||||
#
|
||||
|
|
|
@ -208,7 +208,7 @@ class BanManager:
|
|||
return unBanList
|
||||
finally:
|
||||
self.__lock.release()
|
||||
|
||||
|
||||
##
|
||||
# Flush the ban list.
|
||||
#
|
||||
|
@ -223,3 +223,27 @@ class BanManager:
|
|||
return uBList
|
||||
finally:
|
||||
self.__lock.release()
|
||||
|
||||
##
|
||||
# Gets the ticket for the specified IP.
|
||||
#
|
||||
# @return the ticket for the IP or False.
|
||||
def getTicketByIP(self, ip):
|
||||
try:
|
||||
ipticket = False
|
||||
self.__lock.acquire()
|
||||
|
||||
# Find the ticket the IP goes with.
|
||||
for ticket in self.__banList:
|
||||
if ticket.getIP() == ip:
|
||||
ipticket = ticket
|
||||
break
|
||||
|
||||
unBanList = [ipticket]
|
||||
# Remove the ticket from the ban list.
|
||||
self.__banList = [ticket for ticket in self.__banList
|
||||
if ticket not in unBanList]
|
||||
|
||||
return ipticket
|
||||
finally:
|
||||
self.__lock.release()
|
||||
|
|
|
@ -241,6 +241,9 @@ class Server:
|
|||
def setBanIP(self, name, value):
|
||||
return self.__jails.getFilter(name).addBannedIP(value)
|
||||
|
||||
def setUnbanIP(self, name, value):
|
||||
return self.__jails.getAction(name).removeBannedIP(value)
|
||||
|
||||
def getBanTime(self, name):
|
||||
return self.__jails.getAction(name).getBanTime()
|
||||
|
||||
|
|
|
@ -175,6 +175,9 @@ class Transmitter:
|
|||
elif command[1] == "banip":
|
||||
value = command[2]
|
||||
return self.__server.setBanIP(name,value)
|
||||
elif command[1] == "unbanip":
|
||||
value = command[2]
|
||||
return self.__server.setUnbanIP(name,value)
|
||||
elif command[1] == "addaction":
|
||||
value = command[2]
|
||||
self.__server.addAction(name, value)
|
||||
|
|
Loading…
Reference in New Issue