diff --git a/fail2ban.py b/fail2ban.py index bd4048bc..f192f5b5 100755 --- a/fail2ban.py +++ b/fail2ban.py @@ -56,7 +56,6 @@ def dispUsage(): print "and bans the corresponding IP addresses using firewall rules." print print " -b start in background" - print " -d start in debug mode" print " -c read configuration file FILE" print " -p create PID lock in FILE" print " -h display this help message" @@ -186,6 +185,7 @@ def main(): stdout.setFormatter(formatter) conf["kill"] = False + conf["debug"] = False conf["verbose"] = 0 conf["conffile"] = "/etc/fail2ban.conf" @@ -216,7 +216,6 @@ def main(): ["str", "logtargets", "/var/log/fail2ban.log"], ["str", "syslog-target", "/dev/log"], ["int", "syslog-facility", 1], - ["bool", "debug", False], ["str", "pidlock", "/var/run/fail2ban.pid"], ["int", "maxfailures", 5], ["int", "bantime", 600], @@ -294,8 +293,8 @@ def main(): port = int(syslogtargets[3]) syslogtarget = (syslogtargets[1], port) hdlr = logging.handlers.SysLogHandler(syslogtarget, facility) - tformatter = logging.Formatter("fail2ban[%(process)d]: " + - formatterstring); + tformatter = logging.Formatter("%(asctime)s %(name)s " + + formatterstring, "%b %e %T"); else: # Target should be a file try: @@ -315,14 +314,14 @@ def main(): logSys.setLevel(logging.INFO) elif conf["verbose"] > 1: logSys.setLevel(logging.DEBUG) - - # Set debug log level - if conf["debug"]: - logSys.setLevel(logging.DEBUG) - formatterstring = ('%(levelname)s: [%(filename)s (%(lineno)d)] ' + + if conf["verbose"] > 2: + formatterstring = ('%(levelname)s: [%(filename)s (%(lineno)d)] ' + '%(message)s') - formatter = logging.Formatter("%(asctime)s " + formatterstring) - stdout.setFormatter(formatter) + formatter = logging.Formatter("%(asctime)s " + formatterstring) + stdout.setFormatter(formatter) + + # Debug mode. Should only be used by developers + if conf["debug"]: logSys.warn("DEBUG MODE: FIREWALL COMMANDS ARE _NOT_ EXECUTED BUT " + "ONLY DISPLAYED IN THE LOG MESSAGES") @@ -358,6 +357,8 @@ def main(): ["int", "port", "25"], ["str", "from", "root"], ["str", "to", "root"], + ["str", "user", ''], + ["str", "password", ''], ["bool", "localtime", False], ["str", "subject", "[Fail2Ban] Banned "], ["str", "message", "Fail2Ban notification"]) @@ -370,6 +371,8 @@ def main(): logSys.debug("Mail enabled") mail = Mail(mailConf["host"], mailConf["port"]) mail.setFromAddr(mailConf["from"]) + mail.setUser(mailConf["user"]) + mail.setPassword(mailConf["password"]) mail.setToAddr(mailConf["to"]) mail.setLocalTimeFlag(mailConf["localtime"]) logSys.debug("to: " + mailConf["to"] + " from: " + mailConf["from"])