mirror of https://github.com/fail2ban/fail2ban
- Improved beautifier
git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@360 a942ae1a-1317-0410-a47c-b1dcaea8d6050.x
parent
a618313206
commit
94d167e620
|
@ -24,8 +24,8 @@ __date__ = "$Date: 2006-08-22 23:59:51 +0200 (Tue, 22 Aug 2006) $"
|
||||||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
from server.server import ServerUnknownJail
|
from server.jails import UnknownJailException
|
||||||
from server.server import ServerDuplicateJail
|
from server.jails import DuplicateJailException
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
|
@ -52,48 +52,76 @@ class Beautifier:
|
||||||
logSys.debug("Beautify " + `response` + " with " + `self.inputCmd`)
|
logSys.debug("Beautify " + `response` + " with " + `self.inputCmd`)
|
||||||
inC = self.inputCmd
|
inC = self.inputCmd
|
||||||
msg = response
|
msg = response
|
||||||
if inC[0:1] == ['status']:
|
try:
|
||||||
if len(inC) > 1:
|
if inC[0] == "start":
|
||||||
msg = "Status for the jail: " + inC[1] + "\n"
|
msg = "Jail started"
|
||||||
msg = msg + "|- " + response[0][0] + "\n"
|
elif inC[0] == "stop":
|
||||||
msg = msg + "| |- " + response[0][1][0][0] + ":\t\t" + `response[0][1][0][1]` + "\n"
|
if len(inC) == 1:
|
||||||
msg = msg + "| `- " + response[0][1][1][0] + ":\t\t" + `response[0][1][1][1]` + "\n"
|
if response == None:
|
||||||
msg = msg + "`- " + response[1][0] + "\n"
|
msg = "Shutdown successful"
|
||||||
msg = msg + " |- " + response[1][1][0][0] + ":\t\t" + `response[1][1][0][1]` + "\n"
|
else:
|
||||||
msg = msg + " `- " + response[1][1][1][0] + ":\t\t" + `response[1][1][1][1]`
|
if response == None:
|
||||||
else:
|
msg = "Jail stopped"
|
||||||
msg = "Status\n"
|
elif inC[0] == "add":
|
||||||
msg = msg + "|- " + response[0][0] + ":\t" + `response[0][1]` + "\n"
|
msg = "Added jail " + response
|
||||||
msg = msg + "`- " + response[1][0] + ":\t\t" + response[1][1]
|
elif inC[0:1] == ['status']:
|
||||||
elif inC[1:2] == ['loglevel']:
|
if len(inC) > 1:
|
||||||
msg = "Current logging level is "
|
msg = "Status for the jail: " + inC[1] + "\n"
|
||||||
if response == 1:
|
msg = msg + "|- " + response[0][0] + "\n"
|
||||||
msg = msg + "ERROR"
|
msg = msg + "| |- " + response[0][1][0][0] + ":\t\t" + `response[0][1][0][1]` + "\n"
|
||||||
elif response == 2:
|
msg = msg + "| `- " + response[0][1][1][0] + ":\t\t" + `response[0][1][1][1]` + "\n"
|
||||||
msg = msg + "WARN"
|
msg = msg + "`- " + response[1][0] + "\n"
|
||||||
elif response == 3:
|
msg = msg + " |- " + response[1][1][0][0] + ":\t\t" + `response[1][1][0][1]` + "\n"
|
||||||
msg = msg + "INFO"
|
msg = msg + " `- " + response[1][1][1][0] + ":\t\t" + `response[1][1][1][1]`
|
||||||
elif response == 4:
|
else:
|
||||||
msg = msg + "DEBUG"
|
msg = "Status\n"
|
||||||
else:
|
msg = msg + "|- " + response[0][0] + ":\t" + `response[0][1]` + "\n"
|
||||||
msg = msg + `response`
|
msg = msg + "`- " + response[1][0] + ":\t\t" + response[1][1]
|
||||||
elif inC == ["stop"]:
|
elif inC[1] == "logtarget":
|
||||||
if response == None:
|
msg = "Current logging target is:\n"
|
||||||
msg = "Shutdown successful"
|
msg = msg + "`- " + response
|
||||||
elif inC[2] in ("logpath", "addlogpath", "dellogpath"):
|
elif inC[1:2] == ['loglevel']:
|
||||||
msg = "Current monitored log file(s):\n"
|
msg = "Current logging level is "
|
||||||
for path in response[:-1]:
|
if response == 1:
|
||||||
msg = msg + "|- " + path + "\n"
|
msg = msg + "ERROR"
|
||||||
msg = msg + "`- " + response[len(response)-1]
|
elif response == 2:
|
||||||
|
msg = msg + "WARN"
|
||||||
|
elif response == 3:
|
||||||
|
msg = msg + "INFO"
|
||||||
|
elif response == 4:
|
||||||
|
msg = msg + "DEBUG"
|
||||||
|
else:
|
||||||
|
msg = msg + `response`
|
||||||
|
elif inC[2] in ("logpath", "addlogpath", "dellogpath"):
|
||||||
|
if len(response) == 0:
|
||||||
|
msg = "No file is currently monitored"
|
||||||
|
else:
|
||||||
|
msg = "Current monitored log file(s):\n"
|
||||||
|
for path in response[:-1]:
|
||||||
|
msg = msg + "|- " + path + "\n"
|
||||||
|
msg = msg + "`- " + response[len(response)-1]
|
||||||
|
elif inC[2] in ("ignoreip", "addignoreip", "delignoreip"):
|
||||||
|
if len(response) == 0:
|
||||||
|
msg = "No IP address/network is ignored"
|
||||||
|
else:
|
||||||
|
msg = "These IP addresses/networks are ignored:\n"
|
||||||
|
for ip in response[:-1]:
|
||||||
|
msg = msg + "|- " + ip + "\n"
|
||||||
|
msg = msg + "`- " + response[len(response)-1]
|
||||||
|
except Exception:
|
||||||
|
logSys.warn("Beautifier error. Please report the error")
|
||||||
|
logSys.error("Beautify " + `response` + " with " + `self.inputCmd` +
|
||||||
|
" failed")
|
||||||
|
msg = msg + `response`
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
def beautifyError(self, response):
|
def beautifyError(self, response):
|
||||||
logSys.debug("Beautify (error) " + `response` + " with " + `self.inputCmd`)
|
logSys.debug("Beautify (error) " + `response` + " with " + `self.inputCmd`)
|
||||||
msg = response
|
msg = response
|
||||||
if isinstance(response, ServerUnknownJail):
|
if isinstance(response, UnknownJailException):
|
||||||
msg = "Sorry but the jail '" + response[0] + "' does not exist"
|
msg = "Sorry but the jail '" + response[0] + "' does not exist"
|
||||||
elif isinstance(response, IndexError):
|
elif isinstance(response, IndexError):
|
||||||
msg = "Sorry but the command is invalid"
|
msg = "Sorry but the command is invalid"
|
||||||
elif isinstance(response, ServerDuplicateJail):
|
elif isinstance(response, DuplicateJailException):
|
||||||
msg = "The jail '" + response[0] + "' already exists"
|
msg = "The jail '" + response[0] + "' already exists"
|
||||||
return msg
|
return msg
|
||||||
|
|
Loading…
Reference in New Issue