From: <los...@us...> - 2009-02-09 22:55:29
|
Revision: 731 http://fail2ban.svn.sourceforge.net/fail2ban/?rev=731&view=rev Author: lostcontrol Date: 2009-02-09 22:08:21 +0000 (Mon, 09 Feb 2009) Log Message: ----------- - Fixed maxretry/findtime rate. Many thanks to Christos Psonis. Tracker #2019714. Modified Paths: -------------- branches/FAIL2BAN-0_8/ChangeLog branches/FAIL2BAN-0_8/server/faildata.py branches/FAIL2BAN-0_8/server/failmanager.py branches/FAIL2BAN-0_8/testcases/failmanagertestcase.py Modified: branches/FAIL2BAN-0_8/ChangeLog =================================================================== --- branches/FAIL2BAN-0_8/ChangeLog 2009-02-09 20:27:35 UTC (rev 730) +++ branches/FAIL2BAN-0_8/ChangeLog 2009-02-09 22:08:21 UTC (rev 731) @@ -38,7 +38,9 @@ - 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 ---------- Modified: branches/FAIL2BAN-0_8/server/faildata.py =================================================================== --- branches/FAIL2BAN-0_8/server/faildata.py 2009-02-09 20:27:35 UTC (rev 730) +++ branches/FAIL2BAN-0_8/server/faildata.py 2009-02-09 22:08:21 UTC (rev 731) @@ -34,6 +34,7 @@ def __init__(self): self.__retry = 0 self.__lastTime = 0 + self.__lastReset = 0 def setRetry(self, value): self.__retry = value @@ -50,4 +51,9 @@ def getLastTime(self): return self.__lastTime - \ No newline at end of file + + def getLastReset(self): + return self.__lastReset + + def setLastReset(self, value): + self.__lastReset = value Modified: branches/FAIL2BAN-0_8/server/failmanager.py =================================================================== --- branches/FAIL2BAN-0_8/server/failmanager.py 2009-02-09 20:27:35 UTC (rev 730) +++ branches/FAIL2BAN-0_8/server/failmanager.py 2009-02-09 22:08:21 UTC (rev 731) @@ -90,11 +90,15 @@ 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 Modified: branches/FAIL2BAN-0_8/testcases/failmanagertestcase.py =================================================================== --- branches/FAIL2BAN-0_8/testcases/failmanagertestcase.py 2009-02-09 20:27:35 UTC (rev 730) +++ branches/FAIL2BAN-0_8/testcases/failmanagertestcase.py 2009-02-09 22:08:21 UTC (rev 731) @@ -39,7 +39,12 @@ ['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 @@ """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 @@ 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) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |