mirror of https://github.com/fail2ban/fail2ban
review of command line: more long-named options can be supplied via command line
parent
3f48907064
commit
7a28861fc7
|
@ -35,7 +35,8 @@ logSys = getLogger("fail2ban")
|
||||||
def output(s): # pragma: no cover
|
def output(s): # pragma: no cover
|
||||||
print(s)
|
print(s)
|
||||||
|
|
||||||
CONFIG_PARAMS = ("socket", "pidfile", "logtarget", "loglevel", "syslogsocket",)
|
# Config parameters required to start fail2ban which can be also set via command line (overwrite fail2ban.conf),
|
||||||
|
CONFIG_PARAMS = ("socket", "pidfile", "logtarget", "loglevel", "syslogsocket")
|
||||||
# Used to signal - we are in test cases (ex: prevents change logging params, log capturing, etc)
|
# Used to signal - we are in test cases (ex: prevents change logging params, log capturing, etc)
|
||||||
PRODUCTION = True
|
PRODUCTION = True
|
||||||
|
|
||||||
|
@ -94,9 +95,9 @@ class Fail2banCmdLine():
|
||||||
output("and bans the corresponding IP addresses using firewall rules.")
|
output("and bans the corresponding IP addresses using firewall rules.")
|
||||||
output("")
|
output("")
|
||||||
output("Options:")
|
output("Options:")
|
||||||
output(" -c <DIR> configuration directory")
|
output(" -c, --conf <DIR> configuration directory")
|
||||||
output(" -s <FILE> socket path")
|
output(" -s, --socket <FILE> socket path")
|
||||||
output(" -p <FILE> pidfile path")
|
output(" -p, --pidfile <FILE> pidfile path")
|
||||||
output(" --pname <NAME> name of the process (main thread) to identify instance (default fail2ban-server)")
|
output(" --pname <NAME> name of the process (main thread) to identify instance (default fail2ban-server)")
|
||||||
output(" --loglevel <LEVEL> logging level")
|
output(" --loglevel <LEVEL> logging level")
|
||||||
output(" --logtarget <TARGET> logging target, use file-name or stdout, stderr, syslog or sysout.")
|
output(" --logtarget <TARGET> logging target, use file-name or stdout, stderr, syslog or sysout.")
|
||||||
|
@ -130,17 +131,15 @@ class Fail2banCmdLine():
|
||||||
"""
|
"""
|
||||||
for opt in optList:
|
for opt in optList:
|
||||||
o = opt[0]
|
o = opt[0]
|
||||||
if o == "-c":
|
if o in ("-c", "--conf"):
|
||||||
self._conf["conf"] = opt[1]
|
self._conf["conf"] = opt[1]
|
||||||
elif o == "-s":
|
elif o in ("-s", "--socket"):
|
||||||
self._conf["socket"] = opt[1]
|
self._conf["socket"] = opt[1]
|
||||||
elif o == "-p":
|
elif o in ("-p", "--pidfile"):
|
||||||
self._conf["pidfile"] = opt[1]
|
self._conf["pidfile"] = opt[1]
|
||||||
elif o.startswith("--log") or o.startswith("--sys"):
|
elif o in ("-d", "--dp", "--dump-pretty"):
|
||||||
self._conf[ o[2:] ] = opt[1]
|
|
||||||
elif o in ["-d", "--dp", "--dump-pretty"]:
|
|
||||||
self._conf["dump"] = True if o == "-d" else 2
|
self._conf["dump"] = True if o == "-d" else 2
|
||||||
elif o == "-t" or o == "--test":
|
elif o in ("-t", "--test"):
|
||||||
self.cleanConfOnly = True
|
self.cleanConfOnly = True
|
||||||
self._conf["test"] = True
|
self._conf["test"] = True
|
||||||
elif o == "-v":
|
elif o == "-v":
|
||||||
|
@ -164,12 +163,14 @@ class Fail2banCmdLine():
|
||||||
from ..server.mytime import MyTime
|
from ..server.mytime import MyTime
|
||||||
output(MyTime.str2seconds(opt[1]))
|
output(MyTime.str2seconds(opt[1]))
|
||||||
return True
|
return True
|
||||||
elif o in ["-h", "--help"]:
|
elif o in ("-h", "--help"):
|
||||||
self.dispUsage()
|
self.dispUsage()
|
||||||
return True
|
return True
|
||||||
elif o in ["-V", "--version"]:
|
elif o in ("-V", "--version"):
|
||||||
self.dispVersion(o == "-V")
|
self.dispVersion(o == "-V")
|
||||||
return True
|
return True
|
||||||
|
elif o.startswith("--"): # other long named params (see also resetConf)
|
||||||
|
self._conf[ o[2:] ] = opt[1]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def initCmdLine(self, argv):
|
def initCmdLine(self, argv):
|
||||||
|
@ -186,7 +187,8 @@ class Fail2banCmdLine():
|
||||||
try:
|
try:
|
||||||
cmdOpts = 'hc:s:p:xfbdtviqV'
|
cmdOpts = 'hc:s:p:xfbdtviqV'
|
||||||
cmdLongOpts = ['loglevel=', 'logtarget=', 'syslogsocket=', 'test', 'async',
|
cmdLongOpts = ['loglevel=', 'logtarget=', 'syslogsocket=', 'test', 'async',
|
||||||
'pname=', 'timeout=', 'str2sec=', 'help', 'version', 'dp', '--dump-pretty']
|
'conf=', 'pidfile=', 'pname=', 'socket=',
|
||||||
|
'timeout=', 'str2sec=', 'help', 'version', 'dp', '--dump-pretty']
|
||||||
optList, self._args = getopt.getopt(self._argv[1:], cmdOpts, cmdLongOpts)
|
optList, self._args = getopt.getopt(self._argv[1:], cmdOpts, cmdLongOpts)
|
||||||
except getopt.GetoptError:
|
except getopt.GetoptError:
|
||||||
self.dispUsage()
|
self.dispUsage()
|
||||||
|
@ -228,7 +230,8 @@ class Fail2banCmdLine():
|
||||||
if not conf:
|
if not conf:
|
||||||
self.configurator.readEarly()
|
self.configurator.readEarly()
|
||||||
conf = self.configurator.getEarlyOptions()
|
conf = self.configurator.getEarlyOptions()
|
||||||
self._conf[o] = conf[o]
|
if o in conf:
|
||||||
|
self._conf[o] = conf[o]
|
||||||
|
|
||||||
logSys.info("Using socket file %s", self._conf["socket"])
|
logSys.info("Using socket file %s", self._conf["socket"])
|
||||||
|
|
||||||
|
|
|
@ -10,13 +10,13 @@ Fail2Ban v0.10.5 reads log file that contains password failure report
|
||||||
and bans the corresponding IP addresses using firewall rules.
|
and bans the corresponding IP addresses using firewall rules.
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
.TP
|
.TP
|
||||||
\fB\-c\fR <DIR>
|
\fB\-c\fR, \fB\-\-conf\fR <DIR>
|
||||||
configuration directory
|
configuration directory
|
||||||
.TP
|
.TP
|
||||||
\fB\-s\fR <FILE>
|
\fB\-s\fR, \fB\-\-socket\fR <FILE>
|
||||||
socket path
|
socket path
|
||||||
.TP
|
.TP
|
||||||
\fB\-p\fR <FILE>
|
\fB\-p\fR, \fB\-\-pidfile\fR <FILE>
|
||||||
pidfile path
|
pidfile path
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-pname\fR <NAME>
|
\fB\-\-pname\fR <NAME>
|
||||||
|
|
|
@ -10,13 +10,13 @@ Fail2Ban v0.10.5 reads log file that contains password failure report
|
||||||
and bans the corresponding IP addresses using firewall rules.
|
and bans the corresponding IP addresses using firewall rules.
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
.TP
|
.TP
|
||||||
\fB\-c\fR <DIR>
|
\fB\-c\fR, \fB\-\-conf\fR <DIR>
|
||||||
configuration directory
|
configuration directory
|
||||||
.TP
|
.TP
|
||||||
\fB\-s\fR <FILE>
|
\fB\-s\fR, \fB\-\-socket\fR <FILE>
|
||||||
socket path
|
socket path
|
||||||
.TP
|
.TP
|
||||||
\fB\-p\fR <FILE>
|
\fB\-p\fR, \fB\-\-pidfile\fR <FILE>
|
||||||
pidfile path
|
pidfile path
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-pname\fR <NAME>
|
\fB\-\-pname\fR <NAME>
|
||||||
|
|
Loading…
Reference in New Issue