- 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-b1dcaea8d605
0.5
Cyril Jaquier 2005-07-15 19:27:38 +00:00
parent 74dfb8440e
commit bb430ec25c
2 changed files with 33 additions and 19 deletions

View File

@ -17,18 +17,18 @@ background = false
# #
debug = 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 # Option: pidlock
# Notes.: path of the PID lock file (must be able to write to file). # Notes.: path of the PID lock file (must be able to write to file).
# Values: FILE Default: /var/run/fail2ban.pid # Values: FILE Default: /var/run/fail2ban.pid
# #
pidlock = /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 # Option: maxretry
# Notes.: number of retrys before IP gets banned. # Notes.: number of retrys before IP gets banned.
# Values: NUM Default: 3 # Values: NUM Default: 3

View File

@ -56,7 +56,6 @@ def dispUsage():
print " -h display this help message" print " -h display this help message"
print " -i <IP(s)> IP(s) to ignore" print " -i <IP(s)> IP(s) to ignore"
print " -k kill a currently running Fail2Ban instance" 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 " -r <VALUE> allow a max of VALUE password failure"
print " -t <TIME> ban IP for TIME seconds" print " -t <TIME> ban IP for TIME seconds"
print " -v verbose. Use twice for greater effect" print " -v verbose. Use twice for greater effect"
@ -119,8 +118,6 @@ def getCmdLineOptions(optList):
conf["background"] = True conf["background"] = True
if opt[0] == "-d": if opt[0] == "-d":
conf["debug"] = True conf["debug"] = True
if opt[0] == "-l":
conf["logfile"] = opt[1]
if opt[0] == "-t": if opt[0] == "-t":
try: try:
conf["bantime"] = int(opt[1]) conf["bantime"] = int(opt[1])
@ -153,7 +150,7 @@ def main():
# Reads the command line options. # Reads the command line options.
try: try:
cmdOpts = 'hvVbdkc:l:t:i:r:p:' cmdOpts = 'hvVbdkc:t:i:r:p:'
cmdLongOpts = ['help','version'] cmdLongOpts = ['help','version']
optList, args = getopt.getopt(sys.argv[1:], cmdOpts, cmdLongOpts) optList, args = getopt.getopt(sys.argv[1:], cmdOpts, cmdLongOpts)
except getopt.GetoptError: except getopt.GetoptError:
@ -171,8 +168,8 @@ def main():
# Options # Options
optionValues = (["bool", "background", False], optionValues = (["bool", "background", False],
["str", "logtargets", "STDOUT /var/log/fail2ban.log"],
["bool", "debug", False], ["bool", "debug", False],
["str", "logfile", "/var/log/fail2ban.log"],
["str", "pidlock", "/var/run/fail2ban.pid"], ["str", "pidlock", "/var/run/fail2ban.pid"],
["int", "maxretry", 3], ["int", "maxretry", 3],
["int", "bantime", 600], ["int", "bantime", 600],
@ -188,6 +185,31 @@ def main():
getCmdLineOptions(optList) getCmdLineOptions(optList)
# Process some options # 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 # Verbose level
if conf["verbose"]: if conf["verbose"]:
logSys.warn("Verbose level is "+`conf["verbose"]`) logSys.warn("Verbose level is "+`conf["verbose"]`)
@ -210,14 +232,6 @@ def main():
if not retCode: if not retCode:
logSys.error("Unable to start daemon") logSys.error("Unable to start daemon")
sys.exit(-1) 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 # Ignores IP list
ignoreIPList = conf["ignoreip"].split(' ') ignoreIPList = conf["ignoreip"].split(' ')