mirror of https://github.com/fail2ban/fail2ban
- Improved usage message
- Exit with correct return code git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@286 a942ae1a-1317-0410-a47c-b1dcaea8d6050.x
parent
5c4a4f8726
commit
bdc4c89051
|
@ -61,15 +61,35 @@ class Fail2banClient:
|
||||||
print "Fail2Ban v" + version + " reads log file that contains password failure report"
|
print "Fail2Ban v" + version + " reads log file that contains password failure report"
|
||||||
print "and bans the corresponding IP addresses using firewall rules."
|
print "and bans the corresponding IP addresses using firewall rules."
|
||||||
print
|
print
|
||||||
print " -c <DIR> configuration directory"
|
print " <COMMAND>"
|
||||||
print " -d dump configuration"
|
print
|
||||||
print " -v increase verbosity"
|
print " start start the server and the jails"
|
||||||
print " -q decrease verbosity"
|
print " reload reload the configuration"
|
||||||
print " -x force execution of the server"
|
print " stop stop all jails and terminate the server"
|
||||||
print " -h display this help message"
|
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
|
||||||
print "Report bugs to <lostcontrol@users.sourceforge.net>"
|
print "Report bugs to <lostcontrol@users.sourceforge.net>"
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
def getCmdLineOptions(self, optList):
|
def getCmdLineOptions(self, optList):
|
||||||
""" Gets the command line options
|
""" Gets the command line options
|
||||||
|
@ -85,6 +105,7 @@ class Fail2banClient:
|
||||||
self.conf["force"] = True
|
self.conf["force"] = True
|
||||||
elif opt[0] in ["-h", "--help"]:
|
elif opt[0] in ["-h", "--help"]:
|
||||||
self.dispUsage()
|
self.dispUsage()
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
def ping(self):
|
def ping(self):
|
||||||
return self.processCmd([["ping"]], False)
|
return self.processCmd([["ping"]], False)
|
||||||
|
@ -123,6 +144,7 @@ class Fail2banClient:
|
||||||
|
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
self.dispUsage()
|
self.dispUsage()
|
||||||
|
return False
|
||||||
|
|
||||||
if len(cmd) == 1 and cmd[0] == "start":
|
if len(cmd) == 1 and cmd[0] == "start":
|
||||||
if self.ping():
|
if self.ping():
|
||||||
|
@ -146,9 +168,10 @@ class Fail2banClient:
|
||||||
self.readConfig()
|
self.readConfig()
|
||||||
self.processCmd(['stop', 'all'], False)
|
self.processCmd(['stop', 'all'], False)
|
||||||
# Configure the server
|
# Configure the server
|
||||||
self.processCmd(self.stream, False)
|
return self.processCmd(self.stream, False)
|
||||||
else:
|
else:
|
||||||
logSys.error("Could not find server")
|
logSys.error("Could not find server")
|
||||||
|
return False
|
||||||
else:
|
else:
|
||||||
return self.processCmd([cmd])
|
return self.processCmd([cmd])
|
||||||
|
|
||||||
|
@ -212,7 +235,7 @@ class Fail2banClient:
|
||||||
stdout.setFormatter(formatter)
|
stdout.setFormatter(formatter)
|
||||||
logSys.addHandler(stdout)
|
logSys.addHandler(stdout)
|
||||||
|
|
||||||
self.processCommand(args)
|
return self.processCommand(args)
|
||||||
|
|
||||||
def readConfig(self):
|
def readConfig(self):
|
||||||
# Read the configuration
|
# Read the configuration
|
||||||
|
@ -235,4 +258,9 @@ class ServerExecutionException(Exception):
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
client = Fail2banClient()
|
client = Fail2banClient()
|
||||||
client.start(sys.argv)
|
# Exit with correct return value
|
||||||
|
if client.start(sys.argv):
|
||||||
|
sys.exit(0)
|
||||||
|
else:
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue