mirror of https://github.com/fail2ban/fail2ban
ENH: refactored previous commit to make it more Pythonic (With prev commit closes gh-86, gh-81)
parent
6288ec2757
commit
f14c7ae401
|
@ -127,7 +127,7 @@ class Actions(JailThread):
|
||||||
def removeBannedIP(self, ip):
|
def removeBannedIP(self, 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 != False:
|
if ticket is not None:
|
||||||
# Unban the IP.
|
# Unban the IP.
|
||||||
self.__unBan(ticket)
|
self.__unBan(ticket)
|
||||||
return ip
|
return ip
|
||||||
|
|
|
@ -230,20 +230,14 @@ class BanManager:
|
||||||
# @return the ticket for the IP or False.
|
# @return the ticket for the IP or False.
|
||||||
def getTicketByIP(self, ip):
|
def getTicketByIP(self, ip):
|
||||||
try:
|
try:
|
||||||
ipticket = False
|
|
||||||
self.__lock.acquire()
|
self.__lock.acquire()
|
||||||
|
|
||||||
# Find the ticket the IP goes with.
|
# Find the ticket the IP goes with and return it
|
||||||
for ticket in self.__banList:
|
for i, ticket in enumerate(self.__banList):
|
||||||
if ticket.getIP() == ip:
|
if ticket.getIP() == ip:
|
||||||
ipticket = ticket
|
# Return the ticket after removing (popping)
|
||||||
break
|
# if from the ban list.
|
||||||
|
return self.__banList.pop(i)
|
||||||
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:
|
finally:
|
||||||
self.__lock.release()
|
self.__lock.release()
|
||||||
|
return None # if none found
|
||||||
|
|
Loading…
Reference in New Issue