mirror of https://github.com/fail2ban/fail2ban
- Removed logfile option and added logtargets
git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_5@145 a942ae1a-1317-0410-a47c-b1dcaea8d6050.5
parent
74dfb8440e
commit
bb430ec25c
|
@ -17,18 +17,18 @@ background = false
|
|||
#
|
||||
debug = false
|
||||
|
||||
# Option: logtargets
|
||||
# Notes.: log targets. Space separated list of logging targets.
|
||||
# Values: STDOUT STDERR SYSLOG file Default: STDOUT /var/log/fail2ban.log
|
||||
#
|
||||
logtargets = STDOUT /var/log/fail2ban.log
|
||||
|
||||
# Option: pidlock
|
||||
# Notes.: path of the PID lock file (must be able to write to file).
|
||||
# Values: FILE Default: /var/run/fail2ban.pid
|
||||
#
|
||||
pidlock = /var/run/fail2ban.pid
|
||||
|
||||
# Option: logfile
|
||||
# Notes.: logfile for logging fail2ban messages.
|
||||
# Values: FILE Default: /var/log/fail2ban.log
|
||||
#
|
||||
logfile = /var/log/fail2ban.log
|
||||
|
||||
# Option: maxretry
|
||||
# Notes.: number of retrys before IP gets banned.
|
||||
# Values: NUM Default: 3
|
||||
|
|
40
fail2ban.py
40
fail2ban.py
|
@ -56,7 +56,6 @@ def dispUsage():
|
|||
print " -h display this help message"
|
||||
print " -i <IP(s)> IP(s) to ignore"
|
||||
print " -k kill a currently running Fail2Ban instance"
|
||||
print " -l <FILE> log messages in FILE"
|
||||
print " -r <VALUE> allow a max of VALUE password failure"
|
||||
print " -t <TIME> ban IP for TIME seconds"
|
||||
print " -v verbose. Use twice for greater effect"
|
||||
|
@ -119,8 +118,6 @@ def getCmdLineOptions(optList):
|
|||
conf["background"] = True
|
||||
if opt[0] == "-d":
|
||||
conf["debug"] = True
|
||||
if opt[0] == "-l":
|
||||
conf["logfile"] = opt[1]
|
||||
if opt[0] == "-t":
|
||||
try:
|
||||
conf["bantime"] = int(opt[1])
|
||||
|
@ -153,7 +150,7 @@ def main():
|
|||
|
||||
# Reads the command line options.
|
||||
try:
|
||||
cmdOpts = 'hvVbdkc:l:t:i:r:p:'
|
||||
cmdOpts = 'hvVbdkc:t:i:r:p:'
|
||||
cmdLongOpts = ['help','version']
|
||||
optList, args = getopt.getopt(sys.argv[1:], cmdOpts, cmdLongOpts)
|
||||
except getopt.GetoptError:
|
||||
|
@ -171,8 +168,8 @@ def main():
|
|||
|
||||
# Options
|
||||
optionValues = (["bool", "background", False],
|
||||
["str", "logtargets", "STDOUT /var/log/fail2ban.log"],
|
||||
["bool", "debug", False],
|
||||
["str", "logfile", "/var/log/fail2ban.log"],
|
||||
["str", "pidlock", "/var/run/fail2ban.pid"],
|
||||
["int", "maxretry", 3],
|
||||
["int", "bantime", 600],
|
||||
|
@ -188,6 +185,31 @@ def main():
|
|||
getCmdLineOptions(optList)
|
||||
|
||||
# Process some options
|
||||
# Log targets
|
||||
# Bug fix for #1234699
|
||||
os.umask(0077)
|
||||
# Remove all the targets before setting our own
|
||||
logSys.remove_all_targets()
|
||||
for target in conf["logtargets"].split():
|
||||
if target == "STDOUT":
|
||||
logSys.add_target(log4py.TARGET_SYS_STDOUT)
|
||||
elif target == "STDERR":
|
||||
logSys.add_target(log4py.TARGET_SYS_STDERR)
|
||||
elif target == "SYSLOG":
|
||||
logSys.add_target(log4py.TARGET_SYSLOG)
|
||||
else:
|
||||
# Target should be a file
|
||||
try:
|
||||
open(target, "a")
|
||||
logSys.add_target(target)
|
||||
except IOError:
|
||||
logSys.error("Unable to log to " + target)
|
||||
|
||||
# Check if at least one target exists
|
||||
if len(logSys.get_targets()) == 0:
|
||||
logSys.add_target(log4py.TARGET_SYS_STDOUT)
|
||||
logSys.error("No valid logging target found. Logging to STDOUT")
|
||||
|
||||
# Verbose level
|
||||
if conf["verbose"]:
|
||||
logSys.warn("Verbose level is "+`conf["verbose"]`)
|
||||
|
@ -210,14 +232,6 @@ def main():
|
|||
if not retCode:
|
||||
logSys.error("Unable to start daemon")
|
||||
sys.exit(-1)
|
||||
# Bug fix for #1234699
|
||||
os.umask(0077)
|
||||
try:
|
||||
open(conf["logfile"], "a")
|
||||
logSys.set_target(conf["logfile"])
|
||||
except IOError:
|
||||
logSys.error("Unable to log to " + conf["logfile"])
|
||||
logSys.warn("Using default output for logging")
|
||||
|
||||
# Ignores IP list
|
||||
ignoreIPList = conf["ignoreip"].split(' ')
|
||||
|
|
Loading…
Reference in New Issue