From 26a762ac942519bdacaac7a7ddd15d20b07fed17 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Thu, 4 Jan 2007 23:34:35 +0000 Subject: [PATCH] - Added signal handling in fail2ban-client - Added a wonderful visual effect when waiting on the server - Improved error message. Thanks to Yaroslav Halchenko git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@515 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- CHANGELOG | 7 ++++++- fail2ban-client | 40 ++++++++++++++++++++++++++++++++++++---- fail2ban-server | 2 +- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 71983906..65285a81 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,9 +4,14 @@ |_| \__,_|_|_/___|_.__/\__,_|_||_| ============================================================= -Fail2Ban (version 0.7.6) 2007/01/04 +Fail2Ban (version 0.7.7) 2007/??/?? ============================================================= +ver. 0.7.7 (2007/??/??) +---------- +- Added signal handling in fail2ban-client +- Added a wonderful visual effect when waiting on the server + ver. 0.7.6 (2007/01/04) - beta ---------- - Added a "sleep 1" in redhat-initd. Thanks to Jim Wight diff --git a/fail2ban-client b/fail2ban-client index 14aeabd0..52103d19 100755 --- a/fail2ban-client +++ b/fail2ban-client @@ -25,7 +25,7 @@ __date__ = "$Date$" __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" -import sys, string, os, pickle, re, logging +import sys, string, os, pickle, re, logging, signal import getopt, time, readline, shlex, socket # Inserts our own modules path first in the list @@ -87,7 +87,7 @@ class Fail2banClient: print " -i interactive mode" print " -v increase verbosity" print " -q decrease verbosity" - print " -x force execution of the server" + print " -x force execution of the server (remove socket file)" print " -h, --help display this help message" print " -V, --version print the version" print @@ -103,7 +103,13 @@ class Fail2banClient: print "Fail2Ban v" + version + " reads log file that contains password failure report" print "and bans the corresponding IP addresses using firewall rules." print - + + def __sigTERMhandler(self, signum, frame): + # Print a new line because we probably come from wait + print + logSys.warn("Caught signal %d. Exiting" % signum) + sys.exit(-1) + def __getCmdLineOptions(self, optList): """ Gets the command line options """ @@ -180,7 +186,11 @@ class Fail2banClient: self.__processCmd(self.__stream, False) return True except ServerExecutionException: - logSys.error("Could not start server. Try -x option") + logSys.error("Could not start server. Maybe an old " + + "socket file is still present. Try to " + + "remove " + self.__conf["socket"] + ". If " + + "you used fail2ban-client to start the " + + "server, adding the -x option will do it") return False elif len(cmd) == 1 and cmd[0] == "reload": if self.__ping(): @@ -229,18 +239,40 @@ class Fail2banClient: def __waitOnServer(self): # Wait for the server to start cnt = 0 + if self.__conf["verbose"] > 1: + pos = 0 + delta = 1 + mask = "[ ]" while not self.__ping(): + # Wonderful visual :) + if self.__conf["verbose"] > 1: + pos += delta + sys.stdout.write("\rINFO " + mask[:pos] + '#' + mask[pos+1:] + + " Waiting on the server...") + sys.stdout.flush() + if pos > len(mask)-3: + delta = -1 + elif pos < 2: + delta = 1 # The server has 30 secondes to start. if cnt >= 300: + if self.__conf["verbose"] > 1: + sys.stdout.write('\n') raise ServerExecutionException("Failed to start server") time.sleep(0.1) cnt += 1 + if self.__conf["verbose"] > 1: + sys.stdout.write('\n') def start(self, argv): # Command line options self.__argv = argv + # Install signal handlers + signal.signal(signal.SIGTERM, self.__sigTERMhandler) + signal.signal(signal.SIGINT, self.__sigTERMhandler) + # Reads the command line options. try: cmdOpts = 'hc:s:xdviqV' diff --git a/fail2ban-server b/fail2ban-server index bdb7455f..e706d04e 100755 --- a/fail2ban-server +++ b/fail2ban-server @@ -78,7 +78,7 @@ class Fail2banServer: print " -b start in background" print " -f start in foreground" print " -s socket path" - print " -x force execution of the server" + print " -x force execution of the server (remove socket file)" print " -h, --help display this help message" print " -V, --version print the version" print