From 3eb5e3b87662793282ca66f5fceeaad82eaf71b9 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Sun, 7 Aug 2011 02:41:08 +0000 Subject: [PATCH 01/27] BF: Allow for trailing spaces in sasl logs git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_8@783 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- config/filter.d/sasl.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/filter.d/sasl.conf b/config/filter.d/sasl.conf index e316605f..4be847ee 100644 --- a/config/filter.d/sasl.conf +++ b/config/filter.d/sasl.conf @@ -14,7 +14,7 @@ # (?:::f{4,6}:)?(?P[\w\-.^_]+) # Values: TEXT # -failregex = (?i): warning: [-._\w]+\[\]: SASL (?:LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(: [ A-Za-z0-9+/]*={0,2})?$ +failregex = (?i): warning: [-._\w]+\[\]: SASL (?:LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(: [ A-Za-z0-9+/]*={0,2})?\s*$ # Option: ignoreregex # Notes.: regex to ignore. If this regex matches, the line is ignored. From 3a58d0e6e40898c5b4ec14cafa625229b4c2081d Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Sat, 24 Sep 2011 02:28:45 +0000 Subject: [PATCH 02/27] BF: Lock server's executeCmd to prevent racing among iptables calls (Closes: #554162) Many kudos go to Michael Saavedra for the solution and the patch. git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_8@784 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- server/action.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/server/action.py b/server/action.py index f55d9a6d..8dafbf27 100644 --- a/server/action.py +++ b/server/action.py @@ -25,11 +25,15 @@ __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" import logging, os +import threading #from subprocess import call # Gets the instance of the logger. logSys = logging.getLogger("fail2ban.actions.action") +# Create a lock for running system commands +_cmd_lock = threading.Lock() + ## # Execute commands. # @@ -301,17 +305,21 @@ class Action: #@staticmethod def executeCmd(realCmd): logSys.debug(realCmd) - try: - # The following line gives deadlock with multiple jails - #retcode = call(realCmd, shell=True) - retcode = os.system(realCmd) - if retcode == 0: - logSys.debug("%s returned successfully" % realCmd) - return True - else: - logSys.error("%s returned %x" % (realCmd, retcode)) - except OSError, e: - logSys.error("%s failed with %s" % (realCmd, e)) + _cmd_lock.acquire() + try: # Try wrapped within another try needed for python version < 2.5 + try: + # The following line gives deadlock with multiple jails + #retcode = call(realCmd, shell=True) + retcode = os.system(realCmd) + if retcode == 0: + logSys.debug("%s returned successfully" % realCmd) + return True + else: + logSys.error("%s returned %x" % (realCmd, retcode)) + except OSError, e: + logSys.error("%s failed with %s" % (realCmd, e)) + finally: + _cmd_lock.release() return False executeCmd = staticmethod(executeCmd) From 3152afbdc2bbcf680fc400de22221f8ba1f76f35 Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Sun, 25 Sep 2011 12:58:13 +0100 Subject: [PATCH 03/27] Recognise time-stamped kernel messages e.g. Sep 25 12:51:04 myhost kernel: [773580.832329] sshd[25557]: Invalid user pgsql from 91.203.223.206 This fixes the sshd filter on Fedora 15, and probably other filters on other newish distros too. --- config/filter.d/common.conf | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/config/filter.d/common.conf b/config/filter.d/common.conf index b580c78d..18bf41c5 100644 --- a/config/filter.d/common.conf +++ b/config/filter.d/common.conf @@ -32,10 +32,16 @@ __daemon_re = [\[\(]?%(_daemon)s(?:\(\S+\))?[\]\)]?:? # EXAMPLES: sshd[31607], pop(pam_unix)[4920] __daemon_combs_re = (?:%(__pid_re)s?:\s+%(__daemon_re)s|%(__daemon_re)s%(__pid_re)s?:) +# Some messages have a kernel prefix with a timestamp +# EXAMPLES: kernel: [769570.846956] +__kernel_prefix = kernel: \[\d+\.\d+\] + +__hostname = \S+ + # # Common line prefixes (beginnings) which could be used in filters # # [hostname] [vserver tag] daemon_id spaces # this can be optional (for instance if we match named native log files) -__prefix_line = \s*(?:\S+ )?(?:@vserver_\S+ )?%(__daemon_combs_re)s?\s* +__prefix_line = \s*(?:%(__hostname)s )?(?:%(__kernel_prefix)s )?(?:@vserver_\S+ )?%(__daemon_combs_re)s?\s* From c3215933d77a5d70964b554c8ed1964bb358cb55 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Sun, 2 Oct 2011 21:50:55 -0400 Subject: [PATCH 04/27] Thank Yehuda for all his work on bringing sanity to wiki --- README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README b/README index fb6f3d2b..beb55c59 100644 --- a/README +++ b/README @@ -71,8 +71,8 @@ Munger, Christoph Haas, Justin Shore, Joël Bertrand, René Berber, mEDI, Axel Thimm, Eric Gerbier, Christian Rauch, Michael C. Haller, Jonathan Underwood, Hanno 'Rince' Wagner, Daniel B. Cid, David Nutter, Raphaël Marichez, Guillaume Delvit, Vaclav Misek, Adrien Clerc, Michael Hanselmann, Vincent Deffontaines, -Bill Heaton, Russell Odom, Christos Psonis, Arturo 'Buanzo' Busleiman and many -others. +Bill Heaton, Russell Odom, Christos Psonis, Arturo 'Buanzo' Busleiman, Yehuda +Katz, and many others. License: -------- From 90167a1befb5a5cd68acf0de0329c6628d676a43 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Mon, 3 Oct 2011 15:21:35 -0400 Subject: [PATCH 05/27] DOC: moved THANKS into a THANKS file for better visibility, concise README --- MANIFEST | 1 + README | 10 +--------- THANKS | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 THANKS diff --git a/MANIFEST b/MANIFEST index d3791b34..4c60f8e4 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1,6 +1,7 @@ README ChangeLog TODO +THANKS COPYING fail2ban-client fail2ban-server diff --git a/README b/README index beb55c59..e2431bfd 100644 --- a/README +++ b/README @@ -64,15 +64,7 @@ Cyril Jaquier: Thanks: ------- -Kévin Drapel, Marvin Rouge, Sireyessire, Robert Edeker, Tom Pike, Iain Lea, -Andrey G. Grozin, Yaroslav Halchenko, Jonathan Kamens, Stephen Gildea, Markus -Hoffmann, Mark Edgington, Patrick Börjesson, kojiro, zugeschmiert, Tyler, Nick -Munger, Christoph Haas, Justin Shore, Joël Bertrand, René Berber, mEDI, Axel -Thimm, Eric Gerbier, Christian Rauch, Michael C. Haller, Jonathan Underwood, -Hanno 'Rince' Wagner, Daniel B. Cid, David Nutter, Raphaël Marichez, Guillaume -Delvit, Vaclav Misek, Adrien Clerc, Michael Hanselmann, Vincent Deffontaines, -Bill Heaton, Russell Odom, Christos Psonis, Arturo 'Buanzo' Busleiman, Yehuda -Katz, and many others. +See THANKS file. License: -------- diff --git a/THANKS b/THANKS new file mode 100644 index 00000000..ff20d07d --- /dev/null +++ b/THANKS @@ -0,0 +1,47 @@ +Fail2Ban is an open source project with many contributions from its +users community. Below is an alphabetically sorted partial list of the +contributors to the project. If you have been left off, please let us +know (preferably send a pull request on github with the "fix") and you +will be added + +Adrien Clerc +Andrey G. Grozin +Arturo 'Buanzo' Busleiman +Axel Thimm +Bill Heaton +Christian Rauch +Christoph Haas +Christos Psonis +Daniel B. Cid +David Nutter +Eric Gerbier +Guillaume Delvit +Hanno 'Rince' Wagner +Iain Lea +Jonathan Kamens +Jonathan Underwood +Joël Bertrand +Justin Shore +Kévin Drapel +kojiro +Mark Edgington +Markus Hoffmann +Marvin Rouge +mEDI +Michael C. Haller +Michael Hanselmann +NickMunger +Patrick Börjesson +Raphaël Marichez +René Berber +Robert Edeker +Russell Odom +Sireyessire +Stephen Gildea +Tom Pike +Tyler +Vaclav Misek +Vincent Deffontaines +Yaroslav Halchenko +Yehuda Katz +zugeschmiert From 877de0d45fb88995e61e12fdd3b38c4c1b54077d Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Mon, 3 Oct 2011 15:22:36 -0400 Subject: [PATCH 06/27] adjusted the version in README to match the most recent "release" 0.8.5 --- README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README b/README index e2431bfd..cb4c1cd4 100644 --- a/README +++ b/README @@ -26,8 +26,8 @@ Optional: To install, just do: -> tar xvfj fail2ban-0.8.4.tar.bz2 -> cd fail2ban-0.8.4 +> tar xvfj fail2ban-0.8.5.tar.bz2 +> cd fail2ban-0.8.5 > python setup.py install This will install Fail2Ban into /usr/share/fail2ban. The executable scripts are From ec4fda8a1f04b598acddde23349ba21d0f097074 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Mon, 3 Oct 2011 22:31:56 +0200 Subject: [PATCH 07/27] Removed Subversion keyword --- TODO | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TODO b/TODO index 4737c79a..2b17c916 100644 --- a/TODO +++ b/TODO @@ -4,7 +4,7 @@ |_| \__,_|_|_/___|_.__/\__,_|_||_| ================================================================================ -ToDo $Revision$ +ToDo ================================================================================ Legend: From 08fced9646c7edfa61c21280152f7c6bd76df5b6 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Tue, 4 Oct 2011 10:55:16 -0400 Subject: [PATCH 08/27] ENH: added a .pylintrc to help with consistent appearance and catch obvious problems --- .pylintrc | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .pylintrc diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 00000000..ba38f23d --- /dev/null +++ b/.pylintrc @@ -0,0 +1,37 @@ +# Custom pylint configuration for the Fail2Ban project +# +# Set your PYLINTRC environment variable to point to this file +# e.g. +# export PYLINTRC=$PWD/.pylintrc + +[FORMAT] +indent-string='\t' + +[BASIC] +# Fail2Ban uses non-conventional to Python world camel-casing +# These regexps were originally borrowed from 0.4.x series of +# PyMVPA which had similar conventions. + +# Regular expression which should only match correct module names +module-rgx=(([a-z][a-z0-9_]*)|([A-Z][a-zA-Z0-9_]+))$ + +attr-rgx=[a-z_][a-zA-Z0-9_]{2,30} + +# Regular expression which should only match correct class names +class-rgx=[A-Z_]+[a-zA-Z0-9]+$ + +# Regular expression which should only match correct function names +function-rgx=[a-z_]+[a-z_][a-zA-Z0-9]*$ + +# Regular expression which should only match correct method names +method-rgx=([a-z_]|__)[a-zA-Z0-9]*(__)?$ + +# Regular expression which should only match correct argument names +argument-rgx=[a-z][a-zA-Z0-9]*_*[a-zA-Z0-9]*_*[a-zA-Z0-9]*_?$ + +# Regular expression which should only match correct variable names +variable-rgx=([a-z_]+[a-zA-Z0-9]*_*[a-zA-Z0-9]*_*[a-zA-Z0-9]*_?||(__.*__))$||[A-Z] + +# Regular expression which should only match correct module level names +# Default: (([A-Z_][A-Z1-9_]*)|(__.*__))$ +const-rgx=([a-z_]+[a-zA-Z0-9]*_*[a-zA-Z0-9]*_*[a-zA-Z0-9]*_?|__.*__)$||[A-Z] From 5a2d518bf264889771f3989ff3c096ba091ab854 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 7 Oct 2011 15:14:13 -0400 Subject: [PATCH 09/27] BF: set TZ to CEST while unittesting so dates matching would work now unittesting should work on any box (not only in CEST timezone ;) ) uff -- so much time was wasted to come to this minimal (and now obvious) solution -- it is just scary ;) --- fail2ban-testcases | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/fail2ban-testcases b/fail2ban-testcases index 9573d62b..28945ae3 100755 --- a/fail2ban-testcases +++ b/fail2ban-testcases @@ -26,7 +26,7 @@ __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" -import unittest, logging, sys +import unittest, logging, sys, time, os from common.version import version from testcases import banmanagertestcase @@ -40,6 +40,11 @@ from server.mytime import MyTime # Set the time to a fixed, known value # Sun Aug 14 12:00:00 CEST 2005 + +# yoh: we need to adjust TZ to match the one used by Cyril so all the timestamps match +old_TZ = os.environ.get('TZ', None) +os.environ['TZ'] = 'Europe/Zurich' +time.tzset() MyTime.setTime(1124013600) # Gets the instance of the logger. @@ -73,3 +78,10 @@ tests.addTest(unittest.makeSuite(datedetectortestcase.DateDetectorTest)) # Tests runner testRunner = unittest.TextTestRunner() testRunner.run(tests) + +# Just for the sake of it reset the TZ +# yoh is planing to move all this into setup/teardown methods within tests +os.environ.pop('TZ') +if old_TZ: + os.environ['TZ'] = old_TZ +time.tzset() From b6d50c1dea9bf2d6c37fdc595d7f9f0fd0e2cbc3 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 7 Oct 2011 15:14:34 -0400 Subject: [PATCH 10/27] ENH: Added localtime() to MyTime --- server/mytime.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/mytime.py b/server/mytime.py index b6762c4f..6bb38f85 100644 --- a/server/mytime.py +++ b/server/mytime.py @@ -76,4 +76,10 @@ class MyTime: else: return time.gmtime(MyTime.myTime) gmtime = staticmethod(gmtime) - \ No newline at end of file + + def localtime(x=None): + if MyTime.myTime == None or x is not None: + return time.localtime(x) + else: + return time.localtime(MyTime.myTime) + localtime = staticmethod(localtime) From 6641b1ce8b31c8bc1c0f717b1ba507d4f248c7d8 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 7 Oct 2011 15:14:54 -0400 Subject: [PATCH 11/27] ENH: few debug messages and use MyTime.localtime instead of straight time.time --- server/datetemplate.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/server/datetemplate.py b/server/datetemplate.py index 711c6c99..8af46018 100644 --- a/server/datetemplate.py +++ b/server/datetemplate.py @@ -30,6 +30,10 @@ import re, time from mytime import MyTime import iso8601 +import logging +logSys = logging.getLogger("fail2ban.datetemplate") + + class DateTemplate: def __init__(self): @@ -76,7 +80,7 @@ class DateEpoch(DateTemplate): dateMatch = self.matchDate(line) if dateMatch: # extract part of format which represents seconds since epoch - date = list(time.localtime(float(dateMatch.group()))) + date = list(MyTime.localtime(float(dateMatch.group()))) return date @@ -116,6 +120,8 @@ class DateStrptime(DateTemplate): for t in DateStrptime.TABLE: for m in DateStrptime.TABLE[t]: if date.find(m) >= 0: + logSys.debug(u"Replacing %r with %r in %r" % + (m, t, date)) return date.replace(m, t) return date convertLocale = staticmethod(convertLocale) @@ -145,6 +151,9 @@ class DateStrptime(DateTemplate): # If the date is greater than the current time, we suppose # that the log is not from this year but from the year before if time.mktime(date) > MyTime.time(): + logSys.debug( + u"Correcting deduced year from %d to %d since %f > %f" % + (date[0], date[0]-1, time.mktime(date), MyTime.time())) date[0] -= 1 elif date[1] == 1 and date[2] == 1: # If it is Jan 1st, it is either really Jan 1st or there @@ -169,7 +178,7 @@ class DateTai64n(DateTemplate): value = dateMatch.group() seconds_since_epoch = value[2:17] # convert seconds from HEX into local time stamp - date = list(time.localtime(int(seconds_since_epoch, 16))) + date = list(MyTime.localtime(int(seconds_since_epoch, 16))) return date From 94aa94e966a671e6fad90128b013b79f3dd84a4b Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 7 Oct 2011 15:15:18 -0400 Subject: [PATCH 12/27] ENH: more human-accessible printout of the dates if any comparison fails --- testcases/filtertestcase.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/testcases/filtertestcase.py b/testcases/filtertestcase.py index f738f34a..abc5dced 100644 --- a/testcases/filtertestcase.py +++ b/testcases/filtertestcase.py @@ -25,6 +25,8 @@ __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" import unittest +import time + from server.filterpoll import FilterPoll from server.filter import FileFilter from server.failmanager import FailManager @@ -94,23 +96,34 @@ class GetFailures(unittest.TestCase): def tearDown(self): """Call after every test case.""" - + + def _assertEqualEntries(self, found, output): + """Little helper to unify comparisons with the target entries + + and report helpful failure reports instead of millions of seconds ;) + """ + self.assertEqual(found[:2], output[:2]) + found_time, output_time = \ + time.localtime(found[2]),\ + time.localtime(output[2]) + self.assertEqual(found_time, output_time) + def testGetFailures01(self): output = ('193.168.0.128', 3, 1124013599.0) - + self.__filter.addLogPath(GetFailures.FILENAME_01) self.__filter.addFailRegex("(?:(?:Authentication failure|Failed [-/\w+]+) for(?: [iI](?:llegal|nvalid) user)?|[Ii](?:llegal|nvalid) user|ROOT LOGIN REFUSED) .*(?: from|FROM) ") self.__filter.getFailures(GetFailures.FILENAME_01) - + ticket = self.__filter.failManager.toBan() attempts = ticket.getAttempt() date = ticket.getTime() ip = ticket.getIP() found = (ip, attempts, date) - - self.assertEqual(found, output) + + self._assertEqualEntries(found, output) def testGetFailures02(self): output = ('141.3.81.106', 4, 1124013539.0) @@ -127,7 +140,7 @@ class GetFailures(unittest.TestCase): ip = ticket.getIP() found = (ip, attempts, date) - self.assertEqual(found, output) + self._assertEqualEntries(found, output) def testGetFailures03(self): output = ('203.162.223.135', 6, 1124013544.0) @@ -144,7 +157,7 @@ class GetFailures(unittest.TestCase): ip = ticket.getIP() found = (ip, attempts, date) - self.assertEqual(found, output) + self._assertEqualEntries(found, output) def testGetFailures04(self): output = [('212.41.96.186', 4, 1124013600.0), @@ -182,7 +195,7 @@ class GetFailures(unittest.TestCase): ip = ticket.getIP() found = (ip, attempts, date) - self.assertEqual(found, output) + self._assertEqualEntries(found, output) def testGetFailuresIgnoreRegex(self): output = ('141.3.81.106', 8, 1124013541.0) From 1674b7b4f2af1c715565932b49b4be8561af70c5 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Thu, 6 Oct 2011 17:18:28 -0400 Subject: [PATCH 13/27] ENH: rudimentary __str__ for the ticket --- server/ticket.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/ticket.py b/server/ticket.py index 3c0312b0..c89dc9f0 100644 --- a/server/ticket.py +++ b/server/ticket.py @@ -35,6 +35,10 @@ class Ticket: self.__ip = ip self.__time = time self.__attempt = 0 + + def __str__(self): + return "%s: ip=%s time=%s #attempts=%d" % \ + (self.__class__, self.__ip, self.__time, self.__attempt) def setIP(self, value): self.__ip = value From 19c9ac4fb56407ce4d90a82daf1ff95d5b27d49d Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Thu, 6 Oct 2011 17:18:17 -0400 Subject: [PATCH 14/27] ENH: failmanager -- additional debug message about # of known failures --- server/failmanager.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/failmanager.py b/server/failmanager.py index 95cd47c0..840455df 100644 --- a/server/failmanager.py +++ b/server/failmanager.py @@ -101,6 +101,8 @@ class FailManager: fData.setLastReset(unixTime) fData.setLastTime(unixTime) self.__failList[ip] = fData + logSys.debug("Currently have failures from %d IPs: %s" + % (len(self.__failList), self.__failList.keys())) self.__failTotal += 1 finally: self.__lock.release() From ed6daa70bfd01a843b39cc0a858163663ec040bc Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 7 Oct 2011 15:47:50 -0400 Subject: [PATCH 15/27] ENH: modelines for emacs and vim to assure consistent indentation scheme (tabs) --- client/__init__.py | 3 +++ client/actionreader.py | 5 ++++- client/beautifier.py | 3 +++ client/configparserinc.py | 3 +++ client/configreader.py | 3 +++ client/configurator.py | 5 ++++- client/csocket.py | 3 +++ client/fail2banreader.py | 5 ++++- client/filterreader.py | 5 ++++- client/jailreader.py | 3 +++ client/jailsreader.py | 5 ++++- common/__init__.py | 3 +++ common/helpers.py | 21 ++++++++++++--------- common/protocol.py | 3 +++ common/version.py | 3 +++ fail2ban-client | 3 +++ fail2ban-server | 3 +++ fail2ban-testcases | 5 ++++- server/__init__.py | 3 +++ server/action.py | 3 +++ server/actions.py | 3 +++ server/asyncserver.py | 3 +++ server/banmanager.py | 3 +++ server/datedetector.py | 3 +++ server/datetemplate.py | 4 +++- server/faildata.py | 3 +++ server/failmanager.py | 3 +++ server/failregex.py | 3 +++ server/filter.py | 3 +++ server/filtergamin.py | 3 +++ server/filterpoll.py | 3 +++ server/iso8601.py | 3 +++ server/jail.py | 3 +++ server/jails.py | 3 +++ server/jailthread.py | 3 +++ server/mytime.py | 3 +++ server/server.py | 3 +++ server/ticket.py | 3 +++ server/transmitter.py | 5 ++++- setup.py | 2 ++ testcases/__init__.py | 5 ++++- testcases/actiontestcase.py | 5 ++++- testcases/banmanagertestcase.py | 5 ++++- testcases/clientreadertestcase.py | 5 ++++- testcases/datedetectortestcase.py | 5 ++++- testcases/failmanagertestcase.py | 3 +++ testcases/filtertestcase.py | 3 +++ testcases/servertestcase.py | 5 ++++- 48 files changed, 165 insertions(+), 23 deletions(-) diff --git a/client/__init__.py b/client/__init__.py index dc25edd6..65ba9868 100644 --- a/client/__init__.py +++ b/client/__init__.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/client/actionreader.py b/client/actionreader.py index 51acaf07..29672bca 100644 --- a/client/actionreader.py +++ b/client/actionreader.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify @@ -87,4 +90,4 @@ class ActionReader(ConfigReader): stream.append(head + ["setcinfo", self.__file, p, self.__cInfo[p]]) return stream - \ No newline at end of file + diff --git a/client/beautifier.py b/client/beautifier.py index ab98b294..104a239e 100644 --- a/client/beautifier.py +++ b/client/beautifier.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/client/configparserinc.py b/client/configparserinc.py index 081ec399..da4e574b 100644 --- a/client/configparserinc.py +++ b/client/configparserinc.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/client/configreader.py b/client/configreader.py index f8e9ade8..18ae9b9a 100644 --- a/client/configreader.py +++ b/client/configreader.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/client/configurator.py b/client/configurator.py index 8c3a69dd..526f218b 100644 --- a/client/configurator.py +++ b/client/configurator.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify @@ -75,4 +78,4 @@ class Configurator: for opt in self.__streams["jails"]: cmds.append(opt) return cmds - \ No newline at end of file + diff --git a/client/csocket.py b/client/csocket.py index 13bae5f8..4bfb0510 100644 --- a/client/csocket.py +++ b/client/csocket.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/client/fail2banreader.py b/client/fail2banreader.py index 99bc522e..f4f2728f 100644 --- a/client/fail2banreader.py +++ b/client/fail2banreader.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify @@ -55,4 +58,4 @@ class Fail2banReader(ConfigReader): elif opt == "logtarget": stream.append(["set", "logtarget", self.__opts[opt]]) return stream - \ No newline at end of file + diff --git a/client/filterreader.py b/client/filterreader.py index 4e546da2..b20c6f83 100644 --- a/client/filterreader.py +++ b/client/filterreader.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify @@ -71,4 +74,4 @@ class FilterReader(ConfigReader): if regex != '': stream.append(["set", self.__name, "addignoreregex", regex]) return stream - \ No newline at end of file + diff --git a/client/jailreader.py b/client/jailreader.py index a65f5eae..52d5f82c 100644 --- a/client/jailreader.py +++ b/client/jailreader.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/client/jailsreader.py b/client/jailsreader.py index 620e7b45..9e68dffe 100644 --- a/client/jailsreader.py +++ b/client/jailsreader.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify @@ -84,4 +87,4 @@ class JailsReader(ConfigReader): stream.append(["start", jail.getName()]) return stream - \ No newline at end of file + diff --git a/common/__init__.py b/common/__init__.py index dc25edd6..65ba9868 100644 --- a/common/__init__.py +++ b/common/__init__.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/common/helpers.py b/common/helpers.py index a8671592..5afc3723 100644 --- a/common/helpers.py +++ b/common/helpers.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify @@ -27,12 +30,12 @@ __license__ = "GPL" def formatExceptionInfo(): - """ Author: Arturo 'Buanzo' Busleiman """ - import sys - cla, exc = sys.exc_info()[:2] - excName = cla.__name__ - try: - excArgs = exc.__dict__["args"] - except KeyError: - excArgs = str(exc) - return (excName, excArgs) + """ Author: Arturo 'Buanzo' Busleiman """ + import sys + cla, exc = sys.exc_info()[:2] + excName = cla.__name__ + try: + excArgs = exc.__dict__["args"] + except KeyError: + excArgs = str(exc) + return (excName, excArgs) diff --git a/common/protocol.py b/common/protocol.py index 675ef5ec..7f0ec9e1 100644 --- a/common/protocol.py +++ b/common/protocol.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/common/version.py b/common/version.py index fc90ffc6..ed2f72db 100644 --- a/common/version.py +++ b/common/version.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/fail2ban-client b/fail2ban-client index d212fe7f..31dd48ca 100755 --- a/fail2ban-client +++ b/fail2ban-client @@ -1,4 +1,7 @@ #!/usr/bin/python +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/fail2ban-server b/fail2ban-server index 696f3e95..f66bbaf8 100755 --- a/fail2ban-server +++ b/fail2ban-server @@ -1,4 +1,7 @@ #!/usr/bin/python +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/fail2ban-testcases b/fail2ban-testcases index 28945ae3..5abf506c 100755 --- a/fail2ban-testcases +++ b/fail2ban-testcases @@ -1,4 +1,7 @@ #!/usr/bin/python +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify @@ -83,5 +86,5 @@ testRunner.run(tests) # yoh is planing to move all this into setup/teardown methods within tests os.environ.pop('TZ') if old_TZ: - os.environ['TZ'] = old_TZ + os.environ['TZ'] = old_TZ time.tzset() diff --git a/server/__init__.py b/server/__init__.py index dc25edd6..65ba9868 100644 --- a/server/__init__.py +++ b/server/__init__.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/server/action.py b/server/action.py index 8dafbf27..e8f6bd12 100644 --- a/server/action.py +++ b/server/action.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/server/actions.py b/server/actions.py index 06f15ec6..96684485 100644 --- a/server/actions.py +++ b/server/actions.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/server/asyncserver.py b/server/asyncserver.py index 35cebf1f..97f20055 100644 --- a/server/asyncserver.py +++ b/server/asyncserver.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/server/banmanager.py b/server/banmanager.py index 13c2a307..b84c3691 100644 --- a/server/banmanager.py +++ b/server/banmanager.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/server/datedetector.py b/server/datedetector.py index 6ee6870d..f0cecede 100644 --- a/server/datedetector.py +++ b/server/datedetector.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/server/datetemplate.py b/server/datetemplate.py index 8af46018..c4a644b7 100644 --- a/server/datetemplate.py +++ b/server/datetemplate.py @@ -1,4 +1,6 @@ -# -*- coding: utf-8 -*- +# emacs: -*- mode: python; coding: utf-8; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/server/faildata.py b/server/faildata.py index d68cd7c1..3cc75c24 100644 --- a/server/faildata.py +++ b/server/faildata.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/server/failmanager.py b/server/failmanager.py index 840455df..c9dbdac1 100644 --- a/server/failmanager.py +++ b/server/failmanager.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/server/failregex.py b/server/failregex.py index 0a5a0de4..5bc1c401 100644 --- a/server/failregex.py +++ b/server/failregex.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/server/filter.py b/server/filter.py index 6f1e4c7d..b8f75aa0 100644 --- a/server/filter.py +++ b/server/filter.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/server/filtergamin.py b/server/filtergamin.py index d2b06fee..0489a2ef 100644 --- a/server/filtergamin.py +++ b/server/filtergamin.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/server/filterpoll.py b/server/filterpoll.py index 621816ed..618e4bac 100644 --- a/server/filterpoll.py +++ b/server/filterpoll.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/server/iso8601.py b/server/iso8601.py index 71dccfea..a42989ea 100644 --- a/server/iso8601.py +++ b/server/iso8601.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- +# vi: set ft=python sts=4 ts=4 sw=4 et: + # Copyright (c) 2007 Michael Twomey # # Permission is hereby granted, free of charge, to any person obtaining a diff --git a/server/jail.py b/server/jail.py index 7b4a2719..eefe69e5 100644 --- a/server/jail.py +++ b/server/jail.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/server/jails.py b/server/jails.py index 8dbde9c8..1ff94e06 100644 --- a/server/jails.py +++ b/server/jails.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/server/jailthread.py b/server/jailthread.py index 44667ff0..ac102ba3 100644 --- a/server/jailthread.py +++ b/server/jailthread.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/server/mytime.py b/server/mytime.py index 6bb38f85..b64a2b75 100644 --- a/server/mytime.py +++ b/server/mytime.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/server/server.py b/server/server.py index a1d7646a..b1d8e34e 100644 --- a/server/server.py +++ b/server/server.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/server/ticket.py b/server/ticket.py index c89dc9f0..1443fdb8 100644 --- a/server/ticket.py +++ b/server/ticket.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/server/transmitter.py b/server/transmitter.py index cb9d668d..27e966a6 100644 --- a/server/transmitter.py +++ b/server/transmitter.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify @@ -261,4 +264,4 @@ class Transmitter: name = command[0] return self.__server.statusJail(name) raise Exception("Invalid command (no status)") - \ No newline at end of file + diff --git a/setup.py b/setup.py index 1e43771f..aff89545 100755 --- a/setup.py +++ b/setup.py @@ -1,4 +1,6 @@ #!/usr/bin/python +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : # This file is part of Fail2Ban. # diff --git a/testcases/__init__.py b/testcases/__init__.py index 76dba873..65ba9868 100644 --- a/testcases/__init__.py +++ b/testcases/__init__.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify @@ -22,4 +25,4 @@ __author__ = "Cyril Jaquier" __version__ = "$Revision$" __date__ = "$Date$" __copyright__ = "Copyright (c) 2004 Cyril Jaquier" -__license__ = "GPL" \ No newline at end of file +__license__ = "GPL" diff --git a/testcases/actiontestcase.py b/testcases/actiontestcase.py index bc6f39ad..a537ab0c 100644 --- a/testcases/actiontestcase.py +++ b/testcases/actiontestcase.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify @@ -44,4 +47,4 @@ class ExecuteAction(unittest.TestCase): self.__action.setActionCheck("[ -e /tmp/fail2ban.test ]") self.assertTrue(self.__action.execActionBan(None)) - \ No newline at end of file + diff --git a/testcases/banmanagertestcase.py b/testcases/banmanagertestcase.py index 644cf6cb..4ff76f41 100644 --- a/testcases/banmanagertestcase.py +++ b/testcases/banmanagertestcase.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify @@ -53,4 +56,4 @@ class AddFailure(unittest.TestCase): def _testInListNOK(self): ticket = BanTicket('111.111.1.111', 1167605999.0) self.assertFalse(self.__banManager.inBanList(ticket)) - \ No newline at end of file + diff --git a/testcases/clientreadertestcase.py b/testcases/clientreadertestcase.py index 39ab80bf..74993914 100644 --- a/testcases/clientreadertestcase.py +++ b/testcases/clientreadertestcase.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify @@ -40,4 +43,4 @@ class JailReaderTest(unittest.TestCase): expected = ['mail-whois', {'name': 'SSH'}] result = JailReader.splitAction(action) self.assertEquals(expected, result) - \ No newline at end of file + diff --git a/testcases/datedetectortestcase.py b/testcases/datedetectortestcase.py index 43c7528d..70447b25 100644 --- a/testcases/datedetectortestcase.py +++ b/testcases/datedetectortestcase.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify @@ -64,4 +67,4 @@ class DateDetectorTest(unittest.TestCase): # # self.assertEqual(self.__datedetector.getTime(log), date) # self.assertEqual(self.__datedetector.getUnixTime(log), dateUnix) - \ No newline at end of file + diff --git a/testcases/failmanagertestcase.py b/testcases/failmanagertestcase.py index 95f25b44..3c1bce22 100644 --- a/testcases/failmanagertestcase.py +++ b/testcases/failmanagertestcase.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/testcases/filtertestcase.py b/testcases/filtertestcase.py index abc5dced..273dc8aa 100644 --- a/testcases/filtertestcase.py +++ b/testcases/filtertestcase.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify diff --git a/testcases/servertestcase.py b/testcases/servertestcase.py index 90ca92e4..ab32eb92 100644 --- a/testcases/servertestcase.py +++ b/testcases/servertestcase.py @@ -1,3 +1,6 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- +# vi: set ft=python sts=4 ts=4 sw=4 noet : + # This file is part of Fail2Ban. # # Fail2Ban is free software; you can redistribute it and/or modify @@ -124,4 +127,4 @@ class Transmitter(unittest.TestCase): jail = self.__server.jails[name] self.assertEqual(jail.getFilter().failManager.size(), 0) self.assertEqual(jail.getAction().banManager.size(), 2) - \ No newline at end of file + From b52d420575485eaf608977f63547c580d123137b Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 5 Oct 2011 10:43:59 -0400 Subject: [PATCH 16/27] ENH: added 'matches' to the Ticket(s) and deprecated "custom" constructors for derived *Tickets --- server/ticket.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/server/ticket.py b/server/ticket.py index 1443fdb8..7721cfbb 100644 --- a/server/ticket.py +++ b/server/ticket.py @@ -34,15 +34,24 @@ logSys = logging.getLogger("fail2ban") class Ticket: - def __init__(self, ip, time): + def __init__(self, ip, time, matches=None): + """Ticket constructor + + @param ip the IP address + @param time the ban time + @param matches (log) lines caused the ticket + """ + self.__ip = ip self.__time = time self.__attempt = 0 + self.__matches = matches or [] def __str__(self): return "%s: ip=%s time=%s #attempts=%d" % \ (self.__class__, self.__ip, self.__time, self.__attempt) + def setIP(self, value): self.__ip = value @@ -61,11 +70,12 @@ class Ticket: def getAttempt(self): return self.__attempt + def getMatches(self): + return self.__matches + class FailTicket(Ticket): - - def __init__(self, ip, time): - Ticket.__init__(self, ip, time) + pass ## @@ -74,14 +84,4 @@ class FailTicket(Ticket): # This class extends the Ticket class. It is mainly used by the BanManager. class BanTicket(Ticket): - - ## - # Constructor. - # - # Call the Ticket (parent) constructor and initialize default - # values. - # @param ip the IP address - # @param time the ban time - - def __init__(self, ip, time): - Ticket.__init__(self, ip, time) + pass From de8786dd1d81a9d42cef56f0c7a23d5f140c8e7e Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 5 Oct 2011 10:44:35 -0400 Subject: [PATCH 17/27] ENH: introduced usa of Ticket.__matches throughout --- server/actions.py | 2 ++ server/banmanager.py | 2 +- server/faildata.py | 18 +++++++++++++----- server/failmanager.py | 7 ++++--- server/filter.py | 2 +- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/server/actions.py b/server/actions.py index 96684485..3f3a9211 100644 --- a/server/actions.py +++ b/server/actions.py @@ -161,6 +161,7 @@ class Actions(JailThread): aInfo["ip"] = bTicket.getIP() aInfo["failures"] = bTicket.getAttempt() aInfo["time"] = bTicket.getTime() + aInfo["matches"] = bTicket.getMatches() if self.__banManager.addBanTicket(bTicket): logSys.warn("[%s] Ban %s" % (self.jail.getName(), aInfo["ip"])) for action in self.__actions: @@ -201,6 +202,7 @@ class Actions(JailThread): aInfo["ip"] = ticket.getIP() aInfo["failures"] = ticket.getAttempt() aInfo["time"] = ticket.getTime() + aInfo["matches"] = ticket.getMatches() logSys.warn("[%s] Unban %s" % (self.jail.getName(), aInfo["ip"])) for action in self.__actions: action.execActionUnban(aInfo) diff --git a/server/banmanager.py b/server/banmanager.py index b84c3691..328ad032 100644 --- a/server/banmanager.py +++ b/server/banmanager.py @@ -133,7 +133,7 @@ class BanManager: ip = ticket.getIP() #lastTime = ticket.getTime() lastTime = MyTime.time() - banTicket = BanTicket(ip, lastTime) + banTicket = BanTicket(ip, lastTime, ticket.getMatches()) banTicket.setAttempt(ticket.getAttempt()) return banTicket createBanTicket = staticmethod(createBanTicket) diff --git a/server/faildata.py b/server/faildata.py index 3cc75c24..2b7959a7 100644 --- a/server/faildata.py +++ b/server/faildata.py @@ -38,16 +38,24 @@ class FailData: self.__retry = 0 self.__lastTime = 0 self.__lastReset = 0 - + self.__matches = [] + def setRetry(self, value): self.__retry = value - + # keep only the last matches or reset entirely + self.__matches = self.__matches[-min(len(self.__matches, value)):] \ + if value else [] + def getRetry(self): return self.__retry - - def inc(self): + + def getMatches(self): + return self.__matches + + def inc(self, matches=None): self.__retry += 1 - + self.__matches += matches or [] + def setLastTime(self, value): if value > self.__lastTime: self.__lastTime = value diff --git a/server/failmanager.py b/server/failmanager.py index c9dbdac1..73e5f242 100644 --- a/server/failmanager.py +++ b/server/failmanager.py @@ -91,16 +91,17 @@ class FailManager: self.__lock.acquire() ip = ticket.getIP() unixTime = ticket.getTime() + matches = ticket.getMatches() 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.inc(matches) fData.setLastTime(unixTime) else: fData = FailData() - fData.inc() + fData.inc(matches) fData.setLastReset(unixTime) fData.setLastTime(unixTime) self.__failList[ip] = fData @@ -139,7 +140,7 @@ class FailManager: if data.getRetry() >= self.__maxRetry: self.__delFailure(ip) # Create a FailTicket from BanData - failTicket = FailTicket(ip, data.getLastTime()) + failTicket = FailTicket(ip, data.getLastTime(), data.getMatches()) failTicket.setAttempt(data.getRetry()) return failTicket raise FailManagerEmpty diff --git a/server/filter.py b/server/filter.py index b8f75aa0..38151d90 100644 --- a/server/filter.py +++ b/server/filter.py @@ -281,7 +281,7 @@ class Filter(JailThread): logSys.debug("Ignore %s" % ip) continue logSys.debug("Found %s" % ip) - self.failManager.addFailure(FailTicket(ip, unixTime)) + self.failManager.addFailure(FailTicket(ip, unixTime, [line])) ## # Returns true if the line should be ignored. From 344effb4374b70c20cb07027569966718e30a75f Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 7 Oct 2011 15:25:11 -0400 Subject: [PATCH 18/27] ENH: minor unittest to see if tickets carry correct 'matches' --- testcases/filtertestcase.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/testcases/filtertestcase.py b/testcases/filtertestcase.py index 273dc8aa..f18cb278 100644 --- a/testcases/filtertestcase.py +++ b/testcases/filtertestcase.py @@ -110,9 +110,13 @@ class GetFailures(unittest.TestCase): time.localtime(found[2]),\ time.localtime(output[2]) self.assertEqual(found_time, output_time) + if len(found) > 3: # match matches + self.assertEqual(found[3], output[3]) + def testGetFailures01(self): - output = ('193.168.0.128', 3, 1124013599.0) + output = ('193.168.0.128', 3, 1124013599.0, + ['Aug 14 11:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128\n']*3) self.__filter.addLogPath(GetFailures.FILENAME_01) self.__filter.addFailRegex("(?:(?:Authentication failure|Failed [-/\w+]+) for(?: [iI](?:llegal|nvalid) user)?|[Ii](?:llegal|nvalid) user|ROOT LOGIN REFUSED) .*(?: from|FROM) ") @@ -124,12 +128,15 @@ class GetFailures(unittest.TestCase): attempts = ticket.getAttempt() date = ticket.getTime() ip = ticket.getIP() - found = (ip, attempts, date) + matches = ticket.getMatches() + found = (ip, attempts, date, matches) self._assertEqualEntries(found, output) def testGetFailures02(self): - output = ('141.3.81.106', 4, 1124013539.0) + output = ('141.3.81.106', 4, 1124013539.0, + ['Aug 14 11:%d:59 i60p295 sshd[12365]: Failed publickey for roehl from ::ffff:141.3.81.106 port 51332 ssh2\n' + % m for m in 53, 54, 57, 58]) self.__filter.addLogPath(GetFailures.FILENAME_02) self.__filter.addFailRegex("Failed .* from ") @@ -141,7 +148,8 @@ class GetFailures(unittest.TestCase): attempts = ticket.getAttempt() date = ticket.getTime() ip = ticket.getIP() - found = (ip, attempts, date) + matches = ticket.getMatches() + found = (ip, attempts, date, matches) self._assertEqualEntries(found, output) From 22b700766c29daf215de5dd9192f5e7a1820b66b Mon Sep 17 00:00:00 2001 From: Tom Hendrikx Date: Mon, 7 Nov 2011 20:06:20 +0100 Subject: [PATCH 19/27] format output of matches data. --- server/actions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/actions.py b/server/actions.py index 3f3a9211..e438ab7a 100644 --- a/server/actions.py +++ b/server/actions.py @@ -161,7 +161,7 @@ class Actions(JailThread): aInfo["ip"] = bTicket.getIP() aInfo["failures"] = bTicket.getAttempt() aInfo["time"] = bTicket.getTime() - aInfo["matches"] = bTicket.getMatches() + aInfo["matches"] = "".join(bTicket.getMatches()) if self.__banManager.addBanTicket(bTicket): logSys.warn("[%s] Ban %s" % (self.jail.getName(), aInfo["ip"])) for action in self.__actions: @@ -202,7 +202,7 @@ class Actions(JailThread): aInfo["ip"] = ticket.getIP() aInfo["failures"] = ticket.getAttempt() aInfo["time"] = ticket.getTime() - aInfo["matches"] = ticket.getMatches() + aInfo["matches"] = "".join(ticket.getMatches()) logSys.warn("[%s] Unban %s" % (self.jail.getName(), aInfo["ip"])) for action in self.__actions: action.execActionUnban(aInfo) From 5f235427aaf990e64377a734754d4ebcb9a08e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz?= Date: Thu, 10 Nov 2011 18:51:29 +0100 Subject: [PATCH 20/27] Update server/datetemplate.py --- server/datetemplate.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/server/datetemplate.py b/server/datetemplate.py index c4a644b7..c25f9ae4 100644 --- a/server/datetemplate.py +++ b/server/datetemplate.py @@ -93,19 +93,18 @@ class DateEpoch(DateTemplate): class DateStrptime(DateTemplate): - TABLE = dict() - TABLE["Jan"] = [] - TABLE["Feb"] = [u"Fév"] - TABLE["Mar"] = [u"Mär"] - TABLE["Apr"] = ["Avr"] - TABLE["May"] = ["Mai"] - TABLE["Jun"] = [] - TABLE["Jul"] = [] - TABLE["Aug"] = ["Aou"] - TABLE["Sep"] = [] - TABLE["Oct"] = ["Okt"] - TABLE["Nov"] = [] - TABLE["Dec"] = [u"Déc", "Dez"] + TABLE["Jan"] = ["Sty"] + TABLE["Feb"] = [u"Fév", "Lut"] + TABLE["Mar"] = [u"Mär", "Mar"] + TABLE["Apr"] = ["Avr", "Kwi"] + TABLE["May"] = ["Mai", "Maj"] + TABLE["Jun"] = ["Lip"] + TABLE["Jul"] = ["Sie"] + TABLE["Aug"] = ["Aou", "Wrz"] + TABLE["Sep"] = ["Sie"] + TABLE["Oct"] = [u"Paź"] + TABLE["Nov"] = ["Lis"] + TABLE["Dec"] = [u"Déc", "Dez", "Gru"] def __init__(self): DateTemplate.__init__(self) From 9d45e35642f6b51e648fbc79e97e9db5c9437198 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 16 Nov 2011 07:45:46 -0500 Subject: [PATCH 21/27] BF: return declaration of TABLE back (thanks to michaelberg79) --- server/datetemplate.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/datetemplate.py b/server/datetemplate.py index c25f9ae4..a561abbe 100644 --- a/server/datetemplate.py +++ b/server/datetemplate.py @@ -92,7 +92,8 @@ class DateEpoch(DateTemplate): # standard. class DateStrptime(DateTemplate): - + + TABLE = dict() TABLE["Jan"] = ["Sty"] TABLE["Feb"] = [u"Fév", "Lut"] TABLE["Mar"] = [u"Mär", "Mar"] From ed0bf3ad968fcc71fa05976160afdf542acea477 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Thu, 9 Jul 2009 00:37:43 -0400 Subject: [PATCH 22/27] Removed duplicate entry for DataCha0s/2\.0 in badbots (closes: #519557) --- config/filter.d/apache-badbots.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/filter.d/apache-badbots.conf b/config/filter.d/apache-badbots.conf index 37798a01..1d70bb0e 100644 --- a/config/filter.d/apache-badbots.conf +++ b/config/filter.d/apache-badbots.conf @@ -11,7 +11,7 @@ [Definition] badbotscustom = EmailCollector|WebEMailExtrac|TrackBack/1\.02|sogou music spider -badbots = atSpider/1\.0|autoemailspider|China Local Browse 2\.6|ContentSmartz|DataCha0s/2\.0|DataCha0s/2\.0|DBrowse 1\.4b|DBrowse 1\.4d|Demo Bot DOT 16b|Demo Bot Z 16b|DSurf15a 01|DSurf15a 71|DSurf15a 81|DSurf15a VA|EBrowse 1\.4b|Educate Search VxB|EmailSiphon|EmailWolf 1\.00|ESurf15a 15|ExtractorPro|Franklin Locator 1\.8|FSurf15a 01|Full Web Bot 0416B|Full Web Bot 0516B|Full Web Bot 2816B|Industry Program 1\.0\.x|ISC Systems iRc Search 2\.1|IUPUI Research Bot v 1\.9a|LARBIN-EXPERIMENTAL \(efp@gmx\.net\)|LetsCrawl\.com/1\.0 +http\://letscrawl\.com/|Lincoln State Web Browser|LWP\:\:Simple/5\.803|Mac Finder 1\.0\.xx|MFC Foundation Class Library 4\.0|Microsoft URL Control - 6\.00\.8xxx|Missauga Locate 1\.0\.0|Missigua Locator 1\.9|Missouri College Browse|Mizzu Labs 2\.2|Mo College 1\.9|Mozilla/2\.0 \(compatible; NEWT ActiveX; Win32\)|Mozilla/3\.0 \(compatible; Indy Library\)|Mozilla/4\.0 \(compatible; Advanced Email Extractor v2\.xx\)|Mozilla/4\.0 \(compatible; Iplexx Spider/1\.0 http\://www\.iplexx\.at\)|Mozilla/4\.0 \(compatible; MSIE 5\.0; Windows NT; DigExt; DTS Agent|Mozilla/4\.0 efp@gmx\.net|Mozilla/5\.0 \(Version\: xxxx Type\:xx\)|MVAClient|NASA Search 1\.0|Nsauditor/1\.x|PBrowse 1\.4b|PEval 1\.4b|Poirot|Port Huron Labs|Production Bot 0116B|Production Bot 2016B|Production Bot DOT 3016B|Program Shareware 1\.0\.2|PSurf15a 11|PSurf15a 51|PSurf15a VA|psycheclone|RSurf15a 41|RSurf15a 51|RSurf15a 81|searchbot admin@google\.com|sogou spider|sohu agent|SSurf15a 11 |TSurf15a 11|Under the Rainbow 2\.2|User-Agent\: Mozilla/4\.0 \(compatible; MSIE 6\.0; Windows NT 5\.1\)|WebVulnCrawl\.blogspot\.com/1\.0 libwww-perl/5\.803|Wells Search II|WEP Search 00 +badbots = atSpider/1\.0|autoemailspider|China Local Browse 2\.6|ContentSmartz|DataCha0s/2\.0|DBrowse 1\.4b|DBrowse 1\.4d|Demo Bot DOT 16b|Demo Bot Z 16b|DSurf15a 01|DSurf15a 71|DSurf15a 81|DSurf15a VA|EBrowse 1\.4b|Educate Search VxB|EmailSiphon|EmailWolf 1\.00|ESurf15a 15|ExtractorPro|Franklin Locator 1\.8|FSurf15a 01|Full Web Bot 0416B|Full Web Bot 0516B|Full Web Bot 2816B|Industry Program 1\.0\.x|ISC Systems iRc Search 2\.1|IUPUI Research Bot v 1\.9a|LARBIN-EXPERIMENTAL \(efp@gmx\.net\)|LetsCrawl\.com/1\.0 +http\://letscrawl\.com/|Lincoln State Web Browser|LWP\:\:Simple/5\.803|Mac Finder 1\.0\.xx|MFC Foundation Class Library 4\.0|Microsoft URL Control - 6\.00\.8xxx|Missauga Locate 1\.0\.0|Missigua Locator 1\.9|Missouri College Browse|Mizzu Labs 2\.2|Mo College 1\.9|Mozilla/2\.0 \(compatible; NEWT ActiveX; Win32\)|Mozilla/3\.0 \(compatible; Indy Library\)|Mozilla/4\.0 \(compatible; Advanced Email Extractor v2\.xx\)|Mozilla/4\.0 \(compatible; Iplexx Spider/1\.0 http\://www\.iplexx\.at\)|Mozilla/4\.0 \(compatible; MSIE 5\.0; Windows NT; DigExt; DTS Agent|Mozilla/4\.0 efp@gmx\.net|Mozilla/5\.0 \(Version\: xxxx Type\:xx\)|MVAClient|NASA Search 1\.0|Nsauditor/1\.x|PBrowse 1\.4b|PEval 1\.4b|Poirot|Port Huron Labs|Production Bot 0116B|Production Bot 2016B|Production Bot DOT 3016B|Program Shareware 1\.0\.2|PSurf15a 11|PSurf15a 51|PSurf15a VA|psycheclone|RSurf15a 41|RSurf15a 51|RSurf15a 81|searchbot admin@google\.com|sogou spider|sohu agent|SSurf15a 11 |TSurf15a 11|Under the Rainbow 2\.2|User-Agent\: Mozilla/4\.0 \(compatible; MSIE 6\.0; Windows NT 5\.1\)|WebVulnCrawl\.blogspot\.com/1\.0 libwww-perl/5\.803|Wells Search II|WEP Search 00 # Option: failregex # Notes.: Regexp to catch known spambots and software alike. Please verify From dad91f7969871e737c616f47ba09b60cc3036764 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 18 Nov 2011 10:07:13 -0500 Subject: [PATCH 23/27] ENH: sshd.conf -- allow user names to have spaces and trailing spaces in the line absorbed from patches carried by Debian distribution of f2b --- config/filter.d/sshd.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/filter.d/sshd.conf b/config/filter.d/sshd.conf index 2c53ee7d..c65abe63 100644 --- a/config/filter.d/sshd.conf +++ b/config/filter.d/sshd.conf @@ -28,11 +28,11 @@ failregex = ^%(__prefix_line)s(?:error: PAM: )?Authentication failure for .* fro ^%(__prefix_line)sFailed (?:password|publickey) for .* from (?: port \d*)?(?: ssh\d*)?$ ^%(__prefix_line)sROOT LOGIN REFUSED.* FROM \s*$ ^%(__prefix_line)s[iI](?:llegal|nvalid) user .* from \s*$ - ^%(__prefix_line)sUser \S+ from not allowed because not listed in AllowUsers$ + ^%(__prefix_line)sUser .+ from not allowed because not listed in AllowUsers$ ^%(__prefix_line)sauthentication failure; logname=\S* uid=\S* euid=\S* tty=\S* ruser=\S* rhost=(?:\s+user=.*)?\s*$ ^%(__prefix_line)srefused connect from \S+ \(\)\s*$ ^%(__prefix_line)sAddress .* POSSIBLE BREAK-IN ATTEMPT!*\s*$ - ^%(__prefix_line)sUser \S+ from not allowed because none of user's groups are listed in AllowGroups$ + ^%(__prefix_line)sUser .+ from not allowed because none of user's groups are listed in AllowGroups\s*$ # Option: ignoreregex # Notes.: regex to ignore. If this regex matches, the line is ignored. From a9be451079d96671745a8f8f4eb078fcabc5fe17 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 18 Nov 2011 10:14:39 -0500 Subject: [PATCH 24/27] ENH: removed expansion for few Date and Revision SVN keywords For consistency of appearance... eventually we might just remove them altogether --- client/configparserinc.py | 4 ++-- config/filter.d/dovecot.conf | 2 +- config/filter.d/pam-generic.conf | 2 +- config/filter.d/pure-ftpd.conf | 2 +- server/asyncserver.py | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/client/configparserinc.py b/client/configparserinc.py index da4e574b..12ac97a8 100644 --- a/client/configparserinc.py +++ b/client/configparserinc.py @@ -22,8 +22,8 @@ # $Revision$ __author__ = 'Yaroslav Halhenko' -__revision__ = '$Revision: $' -__date__ = '$Date: $' +__revision__ = '$Revision$' +__date__ = '$Date$' __copyright__ = 'Copyright (c) 2007 Yaroslav Halchenko' __license__ = 'GPL' diff --git a/config/filter.d/dovecot.conf b/config/filter.d/dovecot.conf index 88888ddd..153b9bb0 100644 --- a/config/filter.d/dovecot.conf +++ b/config/filter.d/dovecot.conf @@ -2,7 +2,7 @@ # # Author: Martin Waschbuesch # -# $Revision: $ +# $Revision$ # [Definition] diff --git a/config/filter.d/pam-generic.conf b/config/filter.d/pam-generic.conf index 7e48a08d..702f8ab0 100644 --- a/config/filter.d/pam-generic.conf +++ b/config/filter.d/pam-generic.conf @@ -2,7 +2,7 @@ # # Author: Yaroslav Halchenko # -# $Revision: $ +# $Revision$ # [Definition] diff --git a/config/filter.d/pure-ftpd.conf b/config/filter.d/pure-ftpd.conf index 345780dc..8066ae00 100644 --- a/config/filter.d/pure-ftpd.conf +++ b/config/filter.d/pure-ftpd.conf @@ -3,7 +3,7 @@ # Author: Cyril Jaquier # Modified: Yaroslav Halchenko for pure-ftpd # -# $Revision: 3$ +# $Revision$ # [Definition] diff --git a/server/asyncserver.py b/server/asyncserver.py index 97f20055..3558a2dd 100644 --- a/server/asyncserver.py +++ b/server/asyncserver.py @@ -19,11 +19,11 @@ # Author: Cyril Jaquier # -# $Revision: 567 $ +# $Revision$ __author__ = "Cyril Jaquier" -__version__ = "$Revision: 567 $" -__date__ = "$Date: 2007-03-26 23:17:31 +0200 (Mon, 26 Mar 2007) $" +__version__ = "$Revision$" +__date__ = "$Date$" __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" From 441cd891bc2446ffca2981e4c2cdaa10bf779072 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 4 Feb 2009 15:38:37 -0500 Subject: [PATCH 25/27] NF: adding unittests for previous commit --- fail2ban-testcases | 1 + testcases/filtertestcase.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/fail2ban-testcases b/fail2ban-testcases index 5abf506c..c05a64bd 100755 --- a/fail2ban-testcases +++ b/fail2ban-testcases @@ -65,6 +65,7 @@ tests = unittest.TestSuite() tests.addTest(unittest.makeSuite(filtertestcase.IgnoreIP)) tests.addTest(unittest.makeSuite(filtertestcase.LogFile)) tests.addTest(unittest.makeSuite(filtertestcase.GetFailures)) +tests.addTest(unittest.makeSuite(filtertestcase.DNSUtilsTests)) # Server #tests.addTest(unittest.makeSuite(servertestcase.StartStop)) #tests.addTest(unittest.makeSuite(servertestcase.Transmitter)) diff --git a/testcases/filtertestcase.py b/testcases/filtertestcase.py index f18cb278..c004c7d2 100644 --- a/testcases/filtertestcase.py +++ b/testcases/filtertestcase.py @@ -31,7 +31,7 @@ import unittest import time from server.filterpoll import FilterPoll -from server.filter import FileFilter +from server.filter import FileFilter, DNSUtils from server.failmanager import FailManager from server.failmanager import FailManagerEmpty @@ -219,3 +219,15 @@ class GetFailures(unittest.TestCase): self.__filter.getFailures(GetFailures.FILENAME_02) self.assertRaises(FailManagerEmpty, self.__filter.failManager.toBan) + +class DNSUtilsTests(unittest.TestCase): + + def testTextToIp(self): + bogus = [ + 'doh1.2.3.4.buga.xxxxx.yyy', + '1.2.3.4.buga.xxxxx.yyy', + ] + """Really bogus addresses which should have no matches""" + for s in bogus: + res = DNSUtils.textToIp(s) + self.assertEqual(res, []) From a33135c24d5ca3e7fc4e9e2116fd4e6308c69a38 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 18 Nov 2011 10:39:39 -0500 Subject: [PATCH 26/27] ENH: set/getFile for ticket.py -- found in source distribution of 0.8.4 it was present in source distribution but seems to lack from VCS --- server/ticket.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/ticket.py b/server/ticket.py index 7721cfbb..81bffa9d 100644 --- a/server/ticket.py +++ b/server/ticket.py @@ -45,6 +45,7 @@ class Ticket: self.__ip = ip self.__time = time self.__attempt = 0 + self.__file = None self.__matches = matches or [] def __str__(self): @@ -58,6 +59,12 @@ class Ticket: def getIP(self): return self.__ip + def setFile(self, value): + self.__file = value + + def getFile(self): + return self.__file + def setTime(self, value): self.__time = value From 927a01a0763813d962f6ac90d4962c734d2954b1 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 18 Nov 2011 10:40:51 -0500 Subject: [PATCH 27/27] ENH: server.py -- addLogPath with tail=True it was present in source distribution of 0.8.4 but seems to lack from VCS --- server/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/server.py b/server/server.py index b1d8e34e..a5b0bf09 100644 --- a/server/server.py +++ b/server/server.py @@ -163,7 +163,7 @@ class Server: return self.__jails.getFilter(name).getIgnoreIP() def addLogPath(self, name, fileName): - self.__jails.getFilter(name).addLogPath(fileName) + self.__jails.getFilter(name).addLogPath(fileName, True) def delLogPath(self, name, fileName): self.__jails.getFilter(name).delLogPath(fileName)