From 9539012e1365bd216c8428fbe09047792947bce0 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Sun, 10 Dec 2006 16:37:22 +0000 Subject: [PATCH 01/24] - Added a "sleep 1". Thanks to Jim Wight git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@482 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- files/redhat-initd | 1 + 1 file changed, 1 insertion(+) diff --git a/files/redhat-initd b/files/redhat-initd index 5909efeb..12867615 100755 --- a/files/redhat-initd +++ b/files/redhat-initd @@ -48,6 +48,7 @@ stop() { if [ -n "$pid" ]; then $FAIL2BAN stop > /dev/null fi + sleep 1 getpid if [ -z "$pid" ]; then rm -f /var/lock/subsys/fail2ban From a9b3f190efd8736d65bfac9498c7a47531fc164b Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Sun, 10 Dec 2006 16:46:54 +0000 Subject: [PATCH 02/24] - Prepared for next release git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@483 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- CHANGELOG | 6 +++++- README | 2 +- common/version.py | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 90b4d506..3530ac3a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,9 +4,13 @@ |_| \__,_|_|_/___|_.__/\__,_|_||_| ============================================================= -Fail2Ban (version 0.7.5) 2006/12/07 +Fail2Ban (version 0.7.6) 200?/??/?? ============================================================= +ver. 0.7.6 (200?/??/??) - ??? +---------- +- Added a "sleep 1" in redhat-initd. Thanks to Jim Wight + ver. 0.7.5 (2006/12/07) - beta ---------- - Do not ban a host that is currently banned. Thanks to diff --git a/README b/README index f0f26801..0dedd93a 100644 --- a/README +++ b/README @@ -4,7 +4,7 @@ |_| \__,_|_|_/___|_.__/\__,_|_||_| ============================================================= -Fail2Ban (version 0.7.5) 2006/12/07 +Fail2Ban (version 0.7.6) 200?/??/?? ============================================================= Fail2Ban scans log files like /var/log/pwdfail and bans IP diff --git a/common/version.py b/common/version.py index ee3b9df7..9e74d0e5 100644 --- a/common/version.py +++ b/common/version.py @@ -24,4 +24,4 @@ __date__ = "$Date$" __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" -version = "0.7.5" +version = "0.7.5-SVN" From 8ca367d609c3e6cf7804d15fb3d76d9c1a3ef021 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Wed, 13 Dec 2006 23:02:46 +0000 Subject: [PATCH 03/24] - Use /dev/log for SYSLOG output. Thanks to Joerg Sommrey git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@488 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- CHANGELOG | 1 + config/fail2ban.conf | 5 +++-- server/server.py | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 3530ac3a..fc591814 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,6 +10,7 @@ Fail2Ban (version 0.7.6) 200?/??/?? ver. 0.7.6 (200?/??/??) - ??? ---------- - Added a "sleep 1" in redhat-initd. Thanks to Jim Wight +- Use /dev/log for SYSLOG output. Thanks to Joerg Sommrey ver. 0.7.5 (2006/12/07) - beta ---------- diff --git a/config/fail2ban.conf b/config/fail2ban.conf index 90439d0c..518c2ff4 100644 --- a/config/fail2ban.conf +++ b/config/fail2ban.conf @@ -18,8 +18,9 @@ loglevel = 3 # Option: logtarget -# Notes.: Set the log target. This could be a file, SYSLOG, STDERR. -# Values: STDERR SYSLOG file Default: /var/log/fail2ban.log +# Notes.: Set the log target. This could be a file, SYSLOG, STDERR or STDOUT. +# Only one log target can be specified. +# Values: STDOUT STDERR SYSLOG file Default: /var/log/fail2ban.log # logtarget = /var/log/fail2ban.log diff --git a/server/server.py b/server/server.py index b93032b0..13d57669 100644 --- a/server/server.py +++ b/server/server.py @@ -306,7 +306,9 @@ class Server: # Remove previous handler logging.getLogger("fail2ban").handlers = [] if target == "SYSLOG": - hdlr = logging.handlers.SysLogHandler() + facility = logging.handlers.SysLogHandler.LOG_DAEMON + hdlr = logging.handlers.SysLogHandler("/dev/log", + facility = facility) elif target == "STDOUT": hdlr = logging.StreamHandler(sys.stdout) elif target == "STDERR": From 6f7df2cc3c3f9a70c48189369268dd28ab285ec9 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Thu, 14 Dec 2006 21:20:03 +0000 Subject: [PATCH 04/24] - Use numeric output for iptables in "actioncheck" git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@489 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- CHANGELOG | 1 + config/action.d/iptables.conf | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index fc591814..fad0e412 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,7 @@ ver. 0.7.6 (200?/??/??) - ??? ---------- - Added a "sleep 1" in redhat-initd. Thanks to Jim Wight - Use /dev/log for SYSLOG output. Thanks to Joerg Sommrey +- Use numeric output for iptables in "actioncheck" ver. 0.7.5 (2006/12/07) - beta ---------- diff --git a/config/action.d/iptables.conf b/config/action.d/iptables.conf index 27809e13..d9be0202 100644 --- a/config/action.d/iptables.conf +++ b/config/action.d/iptables.conf @@ -27,7 +27,7 @@ actionstop = iptables -D INPUT -p --dport -j fail2ban- # Notes.: command executed once before each fwban command # Values: CMD # -actioncheck = iptables -L INPUT | grep -q fail2ban- +actioncheck = iptables -n -L INPUT | grep -q fail2ban- # Option: fwban # Notes.: command executed when banning an IP. Take care that the From b8a522cf3f2fe4a2b73043703116101b53ab54d2 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Fri, 15 Dec 2006 23:02:12 +0000 Subject: [PATCH 05/24] - Added protocol output for Mediawiki git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@490 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- common/protocol.py | 51 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/common/protocol.py b/common/protocol.py index 01c0c984..e53d121b 100644 --- a/common/protocol.py +++ b/common/protocol.py @@ -30,19 +30,23 @@ import textwrap # Describes the protocol used to communicate with the server. protocol = [ +['', "Basic", ""], ["start", "starts the server and the jails"], ["reload", "reloads the configuration"], ["stop", "stops all jails and terminate the server"], ["status", "gets the current status of the server"], ["ping", "tests if the server is alive"], -['', ''], +['', "Logging", ""], ["set loglevel ", "sets logging level to . 0 is minimal, 4 is debug"], ["get loglevel", "gets the logging level"], ["set logtarget ", "sets logging target to . Can be STDOUT, STDERR, SYSLOG or a file"], ["get logtarget", "gets logging target"], -['', ''], +['', "Jail control", ""], ["add ", "creates using "], -['', ''], +["start ", "starts the jail "], +["stop ", "stops the jail . The jail is removed"], +["status ", "gets the current status of "], +['', "Jail configuration", ""], ["set idle on|off", "sets the idle state of "], ["set addignoreip ", "adds to the ignore list of "], ["set delignoreip ", "removes from the ignore list of "], @@ -64,7 +68,7 @@ protocol = [ ["set actioncheck ", "sets the check command of the action for "], ["set actionban ", "sets the ban command of the action for "], ["set actionunban ", "sets the unban command of the action for "], -['', ''], +['', "Jail information", ""], ["get logpath", "gets the list of the monitored files for "], ["get ignoreip", "gets the list of ignored IP addresses for "], ["get timeregex", "gets the regular expression used for the time detection for "], @@ -80,10 +84,6 @@ protocol = [ ["get actioncheck ", "gets the check command for the action for "], ["get actionban ", "gets the ban command for the action for "], ["get actionunban ", "gets the unban command for the action for "], -['', ''], -["start ", "starts the jail "], -["stop ", "stops the jail . The jail is removed"], -["status ", "gets the current status of "] ] ## @@ -94,14 +94,41 @@ def printFormatted(): INDENT=4 MARGIN=41 WIDTH=34 + firstHeading = False for m in protocol: - if m[0] == '': + if m[0] == '' and firstHeading: print + firstHeading = True first = True for n in textwrap.wrap(m[1], WIDTH): if first: - n = ' ' * INDENT + m[0] + ' ' * (MARGIN - len(m[0])) + n + line = ' ' * INDENT + m[0] + ' ' * (MARGIN - len(m[0])) + n first = False else: - n = ' ' * (INDENT + MARGIN) + n - print n + line = ' ' * (INDENT + MARGIN) + n + print line + +## +# Prints the protocol in a "mediawiki" format. + +def printWiki(): + firstHeading = False + for m in protocol: + if m[0] == '': + if firstHeading: + print "|}" + __printWikiHeader(m[1], m[2]) + firstHeading = True + else: + print "|-" + print "| " + m[0] + " || || " + m[1] + print "|}" + +def __printWikiHeader(section, desc): + print + print "=== " + section + " ===" + print + print desc + print + print "{|" + print "| '''Command''' || || '''Description'''" From b02394fd23176f94d95ca9e7fdd175546fbbe004 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Sun, 17 Dec 2006 22:32:40 +0000 Subject: [PATCH 06/24] - Fixed restart. Wait for the server to shutdown git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@491 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- files/gentoo-initd | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/files/gentoo-initd b/files/gentoo-initd index 60ce443d..64a2105c 100755 --- a/files/gentoo-initd +++ b/files/gentoo-initd @@ -17,7 +17,7 @@ # # Author: Sireyessire, Cyril Jaquier # -# $Revision: 1.2 $ +# $Revision$ opts="start stop restart reload showlog" @@ -41,6 +41,32 @@ stop() { eend $? "Failed to stop fail2ban" } +restart() { + if ! service_stopped "${SVCNAME}" ; then + svc_stop || return "$?" + einfon "Waiting for server to shutdown ." + cnt=0 + while [ 1 ]; do + # Ping fail2ban-server + ${FAIL2BAN} ping &> /dev/null + if [ ! "$?" == "0" ]; then + break + fi + cnt=`expr $cnt + 1` + if [ $cnt -gt 60 ] ; then + # We have waited 1 minute. Failed + echo + eend 1 "Failed" + break + fi + sleep 1 + echo -n "." + done + echo + fi + svc_start +} + reload() { ebegin "Reloading fail2ban" ${FAIL2BAN} reload > /dev/null From 5dd2c5162ef42bad3b1403b1c0a24d8b734a717e Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Mon, 18 Dec 2006 22:30:30 +0000 Subject: [PATCH 07/24] - Reset logging handlers only if new handler succeeds git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@493 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- server/server.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/server/server.py b/server/server.py index 13d57669..c71708d7 100644 --- a/server/server.py +++ b/server/server.py @@ -300,14 +300,18 @@ class Server: finally: self.__loggingLock.release() + ## + # Sets the logging target. + # + # target can be a file, SYSLOG, STDOUT or STDERR. + # @param target the logging target + def setLogTarget(self, target): try: self.__loggingLock.acquire() - # Remove previous handler - logging.getLogger("fail2ban").handlers = [] if target == "SYSLOG": facility = logging.handlers.SysLogHandler.LOG_DAEMON - hdlr = logging.handlers.SysLogHandler("/dev/log", + hdlr = logging.handlers.SysLogHandler("/dev/log", facility = facility) elif target == "STDOUT": hdlr = logging.StreamHandler(sys.stdout) @@ -320,8 +324,11 @@ class Server: hdlr = logging.FileHandler(target) except IOError: logSys.error("Unable to log to " + target) + logSys.info("Logging to previous target " + self.__logTarget) return False self.__logTarget = target + # Remove previous handler + logging.getLogger("fail2ban").handlers = [] # set a format which is simpler for console use formatter = logging.Formatter("%(asctime)s %(name)-16s: %(levelname)-6s %(message)s") # tell the handler to use this format From 0c40adda4bd6e980071258f3a468131d495fc3d1 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Mon, 18 Dec 2006 22:33:01 +0000 Subject: [PATCH 08/24] - Fixed some comments git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@494 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- config/action.d/dummy.conf | 12 ++++++------ config/action.d/hostsdeny.conf | 12 ++++++------ config/action.d/ipfw.conf | 16 ++++++++-------- config/action.d/iptables.conf | 12 ++++++------ config/action.d/mail-whois.conf | 12 ++++++------ config/action.d/mail.conf | 12 ++++++------ config/action.d/shorewall.conf | 12 ++++++------ config/fail2ban.conf | 5 +++-- config/jail.conf | 19 +++++++++++++++---- 9 files changed, 62 insertions(+), 50 deletions(-) diff --git a/config/action.d/dummy.conf b/config/action.d/dummy.conf index 5737c372..cc729fdd 100644 --- a/config/action.d/dummy.conf +++ b/config/action.d/dummy.conf @@ -7,26 +7,26 @@ [Definition] -# Option: fwstart +# Option: actionstart # Notes.: command executed once at the start of Fail2Ban. # Values: CMD # actionstart = touch /tmp/fail2ban.dummy echo "" >> /tmp/fail2ban.dummy -# Option: fwend +# Option: actionend # Notes.: command executed once at the end of Fail2Ban # Values: CMD # actionstop = rm -f /tmp/fail2ban.dummy -# Option: fwcheck -# Notes.: command executed once before each fwban command +# Option: actioncheck +# Notes.: command executed once before each actionban command # Values: CMD # actioncheck = -# Option: fwban +# Option: actionban # Notes.: command executed when banning an IP. Take care that the # command is executed with Fail2Ban user rights. # Tags: IP address @@ -36,7 +36,7 @@ actioncheck = # actionban = echo "+" >> /tmp/fail2ban.dummy -# Option: fwunban +# Option: actionunban # Notes.: command executed when unbanning an IP. Take care that the # command is executed with Fail2Ban user rights. # Tags: IP address diff --git a/config/action.d/hostsdeny.conf b/config/action.d/hostsdeny.conf index 7f63ff9b..784fddc5 100644 --- a/config/action.d/hostsdeny.conf +++ b/config/action.d/hostsdeny.conf @@ -7,25 +7,25 @@ [Definition] -# Option: fwstart +# Option: actionstart # Notes.: command executed once at the start of Fail2Ban. # Values: CMD # actionstart = touch -# Option: fwend +# Option: actionend # Notes.: command executed once at the end of Fail2Ban # Values: CMD # actionstop = rm -f -# Option: fwcheck -# Notes.: command executed once before each fwban command +# Option: actioncheck +# Notes.: command executed once before each actionban command # Values: CMD # actioncheck = -# Option: fwban +# Option: actionban # Notes.: command executed when banning an IP. Take care that the # command is executed with Fail2Ban user rights. # Tags: IP address @@ -36,7 +36,7 @@ actioncheck = actionban = IP= && echo "ALL: $IP" >> -# Option: fwunban +# Option: actionunban # Notes.: command executed when unbanning an IP. Take care that the # command is executed with Fail2Ban user rights. # Tags: IP address diff --git a/config/action.d/ipfw.conf b/config/action.d/ipfw.conf index 1828eef9..5ae00cae 100644 --- a/config/action.d/ipfw.conf +++ b/config/action.d/ipfw.conf @@ -8,28 +8,28 @@ [Definition] -# Option: fwstart +# Option: actionstart # Notes.: command executed once at the start of Fail2Ban. # Values: CMD # actionstart = -# Option: fwend +# Option: actionend # Notes.: command executed once at the end of Fail2Ban # Values: CMD # actionstop = -# Option: fwcheck -# Notes.: command executed once before each fwban command +# Option: actioncheck +# Notes.: command executed once before each actionban command # Values: CMD # actioncheck = -# Option: fwban +# Option: actionban # Notes.: command executed when banning an IP. Take care that the # command is executed with Fail2Ban user rights. # Tags: IP address @@ -37,10 +37,10 @@ actioncheck = #