- Improved usage message

- Exit with correct return code

git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@286 a942ae1a-1317-0410-a47c-b1dcaea8d605
0.x
Cyril Jaquier 2006-08-22 21:16:23 +00:00
parent 5c4a4f8726
commit bdc4c89051
1 changed files with 38 additions and 10 deletions

View File

@ -61,15 +61,35 @@ 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
print " -c <DIR> configuration directory"
print " -d dump configuration"
print " -v increase verbosity"
print " -q decrease verbosity"
print " -x force execution of the server"
print " -h display this help message"
print " <COMMAND>"
print
print " start start the server and the jails"
print " reload reload the configuration"
print " stop stop all jails and terminate the server"
print " status get the current status"
print
print " set loglevel <LEVEL> set loglevel to <LEVEL>"
print " get loglevel get loglevel"
print " set logtarget <TARGET> set log target to <TARGET>"
print " get logtarget get log target"
print
print " add <JAIL> create <JAIL>"
print " set <JAIL> <CMD> set the <CMD> value for <JAIL>"
print " get <JAIL> <CMD> get the <CMD> value for <JAIL>"
print " start <JAIL> start <JAIL>"
print " stop <JAIL> stop <JAIL>. The jail is removed"
print " status <JAIL> get the current status of <JAIL>"
print
print " [OPTIONS]"
print
print " -c <DIR> configuration directory"
print " -d dump configuration. For debugging"
print " -v increase verbosity"
print " -q decrease verbosity"
print " -x force execution of the server"
print " -h display this help message"
print
print "Report bugs to <lostcontrol@users.sourceforge.net>"
sys.exit(0)
def getCmdLineOptions(self, optList):
""" Gets the command line options
@ -85,6 +105,7 @@ class Fail2banClient:
self.conf["force"] = True
elif opt[0] in ["-h", "--help"]:
self.dispUsage()
sys.exit(0)
def ping(self):
return self.processCmd([["ping"]], False)
@ -123,6 +144,7 @@ class Fail2banClient:
if len(sys.argv) < 2:
self.dispUsage()
return False
if len(cmd) == 1 and cmd[0] == "start":
if self.ping():
@ -146,9 +168,10 @@ class Fail2banClient:
self.readConfig()
self.processCmd(['stop', 'all'], False)
# Configure the server
self.processCmd(self.stream, False)
return self.processCmd(self.stream, False)
else:
logSys.error("Could not find server")
return False
else:
return self.processCmd([cmd])
@ -212,7 +235,7 @@ class Fail2banClient:
stdout.setFormatter(formatter)
logSys.addHandler(stdout)
self.processCommand(args)
return self.processCommand(args)
def readConfig(self):
# Read the configuration
@ -235,4 +258,9 @@ class ServerExecutionException(Exception):
if __name__ == "__main__":
client = Fail2banClient()
client.start(sys.argv)
# Exit with correct return value
if client.start(sys.argv):
sys.exit(0)
else:
sys.exit(-1)