mirror of https://github.com/fail2ban/fail2ban
96 lines
3.0 KiB
Plaintext
Executable File
96 lines
3.0 KiB
Plaintext
Executable File
#! /bin/sh /usr/share/dpatch/dpatch-run
|
|
## 00_verbosity.dpatch by <debian@onerussian.com>
|
|
##
|
|
## All lines beginning with `## DP:' are a description of the patch.
|
|
## DP: Verbosity can be set either from command line or from config file.
|
|
## DP: Logically the maximal verbosity from two of them should be chosen since
|
|
## DP: verbosity from cmdline can't simple increase config file verbosity
|
|
## DP: because config line might not be even read yet
|
|
|
|
@DPATCH@
|
|
|
|
diff -x '*~' -Naur fail2ban-0.6.1.pre/fail2ban.py fail2ban-0.6.1.post/fail2ban.py
|
|
--- fail2ban-0.6.1.pre/fail2ban.py 2006-03-19 00:20:44.000000000 -0500
|
|
+++ fail2ban-0.6.1.post/fail2ban.py 2006-07-03 23:39:20.000000000 -0400
|
|
@@ -161,9 +161,11 @@
|
|
"""
|
|
# enabledsections can be defined just from the command line
|
|
conf["enabledsections"] = []
|
|
+ # by default we are silent
|
|
+ cmdLineVerbose = 0
|
|
for opt in optList:
|
|
if opt[0] == "-v":
|
|
- conf["verbose"] = conf["verbose"] + 1
|
|
+ cmdLineVerbose += 1
|
|
if opt[0] == "-b":
|
|
conf["background"] = True
|
|
if opt[0] == "-d":
|
|
@@ -192,6 +194,30 @@
|
|
conf["enabledsections"] = map(lambda x: x.upper(),
|
|
re.split("[:, \t\n]", opt[1]))
|
|
|
|
+ # Let's choose the maximal verbosity from cmdLine and config
|
|
+ # files: it would better describe the intent of the user
|
|
+ conf["verbose"] = max(cmdLineVerbose, conf["verbose"])
|
|
+
|
|
+
|
|
+presetVerbosityLevel = 0
|
|
+def setVerbosityLevel(level):
|
|
+ """ Sets verbosity level if previousely set one is different
|
|
+ """
|
|
+ global presetVerbosityLevel
|
|
+ # Verbose level
|
|
+ if level != presetVerbosityLevel and level:
|
|
+ logSys.warn("Verbose level is %d"%level)
|
|
+ if level == 1:
|
|
+ logSys.setLevel(logging.INFO)
|
|
+ elif level > 1:
|
|
+ logSys.setLevel(logging.DEBUG)
|
|
+ if conf["verbose"] > 2:
|
|
+ formatterstring = ('%(levelname)s: [%(filename)s (%(lineno)d)] ' +
|
|
+ '%(message)s')
|
|
+ formatter = logging.Formatter("%(asctime)s " + formatterstring)
|
|
+ stdout.setFormatter(formatter)
|
|
+ presetVerbosityLevel = level
|
|
+
|
|
def main():
|
|
""" Fail2Ban main function
|
|
"""
|
|
@@ -220,12 +246,16 @@
|
|
|
|
# Pre-parsing of command line options for the -c option
|
|
for opt in optList:
|
|
+ if opt[0] == "-v":
|
|
+ conf["verbose"] = conf["verbose"] + 1
|
|
if opt[0] == "-c":
|
|
conf["conffile"] = opt[1]
|
|
if opt[0] in ["-h", "--help"]:
|
|
dispUsage()
|
|
if opt[0] in ["-V", "--version"]:
|
|
dispVersion()
|
|
+
|
|
+ setVerbosityLevel(conf['verbose'])
|
|
|
|
# Reads the config file and create a LogReader instance for
|
|
# each log file to check.
|
|
@@ -337,18 +367,7 @@
|
|
hdlr.setFormatter(tformatter)
|
|
logSys.addHandler(hdlr)
|
|
|
|
- # Verbose level
|
|
- if conf["verbose"]:
|
|
- logSys.warn("Verbose level is "+`conf["verbose"]`)
|
|
- if conf["verbose"] == 1:
|
|
- logSys.setLevel(logging.INFO)
|
|
- elif conf["verbose"] > 1:
|
|
- logSys.setLevel(logging.DEBUG)
|
|
- if conf["verbose"] > 2:
|
|
- formatterstring = ('%(levelname)s: [%(filename)s (%(lineno)d)] ' +
|
|
- '%(message)s')
|
|
- formatter = logging.Formatter("%(asctime)s " + formatterstring)
|
|
- stdout.setFormatter(formatter)
|
|
+ setVerbosityLevel(conf['verbose'])
|
|
|
|
# Debug mode. Should only be used by developers
|
|
if conf["debug"]:
|