diff --git a/server/actions.py b/server/actions.py index f936de18..79783395 100644 --- a/server/actions.py +++ b/server/actions.py @@ -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. # diff --git a/server/banmanager.py b/server/banmanager.py index 214916b7..e9c81214 100644 --- a/server/banmanager.py +++ b/server/banmanager.py @@ -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() diff --git a/server/server.py b/server/server.py index b734f82a..d9532be2 100644 --- a/server/server.py +++ b/server/server.py @@ -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() diff --git a/server/transmitter.py b/server/transmitter.py index a618a1a1..23b609a1 100644 --- a/server/transmitter.py +++ b/server/transmitter.py @@ -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)