- Fixed maxretry/findtime rate. Many thanks to Christos Psonis. Tracker #2019714.

git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_8@731 a942ae1a-1317-0410-a47c-b1dcaea8d605
_tent/ipv6_via_aInfo
Cyril Jaquier 2009-02-09 22:08:21 +00:00
parent 55fd21ec4b
commit 0cf733e878
4 changed files with 28 additions and 4 deletions

View File

@ -38,7 +38,9 @@ ver. 0.8.4 (2008/??/??) - stable
- Use timetuple instead of utctimetuple for ISO 8601. Maybe
not a 100% correct fix but seems to work. Tracker #2500276.
- Made the named-refused regex a bit less restrictive in
order to match logs with "view". Thanks to Stephen Gildea.
order to match logs with "view". Thanks to Stephen Gildea.
- Fixed maxretry/findtime rate. Many thanks to Christos
Psonis. Tracker #2019714.
ver. 0.8.3 (2008/07/17) - stable
----------

View File

@ -34,6 +34,7 @@ class FailData:
def __init__(self):
self.__retry = 0
self.__lastTime = 0
self.__lastReset = 0
def setRetry(self, value):
self.__retry = value
@ -50,4 +51,9 @@ class FailData:
def getLastTime(self):
return self.__lastTime
def getLastReset(self):
return self.__lastReset
def setLastReset(self, value):
self.__lastReset = value

View File

@ -90,11 +90,15 @@ class FailManager:
unixTime = ticket.getTime()
if self.__failList.has_key(ip):
fData = self.__failList[ip]
if fData.getLastReset() < unixTime - self.__maxTime:
fData.setLastReset(unixTime)
fData.setRetry(0)
fData.inc()
fData.setLastTime(unixTime)
else:
fData = FailData()
fData.inc()
fData.setLastReset(unixTime)
fData.setLastTime(unixTime)
self.__failList[ip] = fData
self.__failTotal += 1

View File

@ -39,7 +39,12 @@ class AddFailure(unittest.TestCase):
['193.168.0.128', 1167605999.0],
['87.142.124.10', 1167605999.0],
['87.142.124.10', 1167605999.0],
['87.142.124.10', 1167605999.0]]
['87.142.124.10', 1167605999.0],
['100.100.10.10', 1000000000.0],
['100.100.10.10', 1000000500.0],
['100.100.10.10', 1000001000.0],
['100.100.10.10', 1000001500.0],
['100.100.10.10', 1000002000.0]]
self.__failManager = FailManager()
for i in self.__items:
@ -49,7 +54,7 @@ class AddFailure(unittest.TestCase):
"""Call after every test case."""
def testAdd(self):
self.assertEqual(self.__failManager.size(), 2)
self.assertEqual(self.__failManager.size(), 3)
def _testDel(self):
self.__failManager.delFailure('193.168.0.128')
@ -76,3 +81,10 @@ class AddFailure(unittest.TestCase):
def testbanNOK(self):
self.__failManager.setMaxRetry(10)
self.assertRaises(FailManagerEmpty, self.__failManager.toBan)
def testWindow(self):
ticket = self.__failManager.toBan()
self.assertNotEqual(ticket.getIP(), "100.100.10.10")
ticket = self.__failManager.toBan()
self.assertNotEqual(ticket.getIP(), "100.100.10.10")
self.assertRaises(FailManagerEmpty, self.__failManager.toBan)