|
|
|
@ -46,11 +46,11 @@ class Server:
|
|
|
|
|
self.__daemon = daemon |
|
|
|
|
self.__transm = Transmitter(self) |
|
|
|
|
self.__asyncServer = AsyncServer(self.__transm) |
|
|
|
|
self.__logLevel = 3 |
|
|
|
|
self.__logTarget = "STDOUT" |
|
|
|
|
self.__logLevel = None |
|
|
|
|
self.__logTarget = None |
|
|
|
|
# Set logging level |
|
|
|
|
self.setLogLevel(self.__logLevel) |
|
|
|
|
self.setLogTarget(self.__logTarget) |
|
|
|
|
self.setLogLevel(3) |
|
|
|
|
self.setLogTarget("STDOUT") |
|
|
|
|
|
|
|
|
|
def __sigTERMhandler(self, signum, frame): |
|
|
|
|
logSys.debug("Caught signal %d. Exiting" % signum) |
|
|
|
@ -66,6 +66,7 @@ class Server:
|
|
|
|
|
# First set the mask to only allow access to owner |
|
|
|
|
os.umask(0077) |
|
|
|
|
if self.__daemon: |
|
|
|
|
logSys.info("Starting in daemon mode") |
|
|
|
|
ret = self.__createDaemon() |
|
|
|
|
if ret: |
|
|
|
|
logSys.info("Daemon started") |
|
|
|
@ -264,7 +265,7 @@ class Server:
|
|
|
|
|
length = len(jailList) |
|
|
|
|
if not length == 0: |
|
|
|
|
jailList = jailList[:length-2] |
|
|
|
|
ret = [("Number of jail", self.__jails.size()), |
|
|
|
|
ret = [("Number of jail", self.__jails.size()), |
|
|
|
|
("Jail list", jailList)] |
|
|
|
|
return ret |
|
|
|
|
finally: |
|
|
|
@ -331,7 +332,7 @@ class Server:
|
|
|
|
|
# Syslog daemons already add date to the message. |
|
|
|
|
formatter = logging.Formatter("%(name)-16s: %(levelname)-6s %(message)s") |
|
|
|
|
facility = logging.handlers.SysLogHandler.LOG_DAEMON |
|
|
|
|
hdlr = logging.handlers.SysLogHandler("/dev/log", |
|
|
|
|
hdlr = logging.handlers.SysLogHandler("/dev/log", |
|
|
|
|
facility = facility) |
|
|
|
|
elif target == "STDOUT": |
|
|
|
|
hdlr = logging.StreamHandler(sys.stdout) |
|
|
|
@ -346,7 +347,6 @@ class Server:
|
|
|
|
|
logSys.error("Unable to log to " + target) |
|
|
|
|
logSys.info("Logging to previous target " + self.__logTarget) |
|
|
|
|
return False |
|
|
|
|
self.__logTarget = target |
|
|
|
|
# Removes previous handlers |
|
|
|
|
for handler in logging.getLogger("fail2ban").handlers: |
|
|
|
|
# Closes the handler. |
|
|
|
@ -355,6 +355,12 @@ class Server:
|
|
|
|
|
# tell the handler to use this format |
|
|
|
|
hdlr.setFormatter(formatter) |
|
|
|
|
logging.getLogger("fail2ban").addHandler(hdlr) |
|
|
|
|
# Does not display this message at startup. |
|
|
|
|
if not self.__logTarget == None: |
|
|
|
|
logSys.info("Changed logging target to %s for Fail2ban v%s" % |
|
|
|
|
(target, version.version)) |
|
|
|
|
# Sets the logging target. |
|
|
|
|
self.__logTarget = target |
|
|
|
|
return True |
|
|
|
|
finally: |
|
|
|
|
self.__loggingLock.release() |
|
|
|
|