Some more refactoring

This commit is contained in:
Miroslav Stampar 2012-07-11 20:13:23 +02:00
parent d7926b8aac
commit c6464b44be
3 changed files with 26 additions and 17 deletions

View File

@ -78,8 +78,10 @@ from lib.core.exception import sqlmapMissingDependence
from lib.core.exception import sqlmapSilentQuitException
from lib.core.exception import sqlmapSyntaxException
from lib.core.log import FORMATTER
from lib.core.log import LEVEL_ATTRS
from lib.core.log import LEVEL_COLORS
from lib.core.log import LEVEL_ON_COLORS
from lib.core.optiondict import optDict
from lib.core.settings import COLOR_MAP
from lib.core.settings import CUSTOM_INJECTION_MARK_CHAR
from lib.core.settings import DEFAULT_COOKIE_DELIMITER
from lib.core.settings import DEFAULT_GET_POST_DELIMITER
@ -696,14 +698,12 @@ def singleTimeLogMessage(message, level=logging.INFO, flag=None):
logger.log(level, message)
def setColor(message, bold=False):
retVal = message
level = extractRegexResult(r"\A\s*\[(?P<result>[A-Z ]+)\]", message)
if level:
attrs = ('bold',) if (level == "CRITICAL" or bold) else None
on_color = 'on_red' if level == "CRITICAL" else None
color = COLOR_MAP.get(level)
retVal = colored(message, color=color, on_color=on_color, attrs=attrs)
retVal = colored(message, color=LEVEL_COLORS.get(level), on_color=LEVEL_ON_COLORS.get(level), attrs=LEVEL_ATTRS.get(level))
else:
retVal = message
return retVal

View File

@ -18,6 +18,26 @@ logging.addLevelName(CUSTOM_LOGGING.TRAFFIC_IN, "TRAFFIC IN")
LOGGER = logging.getLogger("sqlmapLog")
LEVEL_COLORS = {
"CRITICAL": "white",
"ERROR": "red",
"WARNING": "yellow",
"INFO": "green",
"DEBUG": "blue",
"PAYLOAD": "magenta",
"TRAFFIC OUT": "cyan",
"TRAFFIC IN": "grey"
}
LEVEL_ON_COLORS = {
"CRITICAL": "on_red",
}
LEVEL_ATTRS = {
"CRITICAL": ('bold',),
}
try:
import ctypes
LOGGER_HANDLER = ColorizingStreamHandler(sys.stdout)

View File

@ -268,17 +268,6 @@ BASIC_HELP_ITEMS = (
"wizard"
)
COLOR_MAP = {
"CRITICAL": "white",
"ERROR": "red",
"WARNING": "yellow",
"INFO": "green",
"DEBUG": "blue",
"PAYLOAD": "magenta",
"TRAFFIC OUT": "cyan",
"TRAFFIC IN": "grey"
}
# string representation for NULL value
NULL = "NULL"