From 1af81c0de486a819d5a21a950ff0b5fa034ba063 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Wed, 15 Aug 2012 22:31:25 +0200 Subject: [PATCH] Implementation of an Issue #149 --- lib/core/option.py | 7 ++++++- lib/core/optiondict.py | 1 + lib/parse/cmdline.py | 4 ++++ sqlmap.conf | 4 ++++ thirdparty/ansistrm/ansistrm.py | 3 ++- 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/core/option.py b/lib/core/option.py index 763b716a2..5733c29ad 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -77,6 +77,7 @@ from lib.core.exception import sqlmapSyntaxException from lib.core.exception import sqlmapUnsupportedDBMSException from lib.core.exception import sqlmapUserQuitException from lib.core.log import FORMATTER +from lib.core.log import LOGGER_HANDLER from lib.core.optiondict import optDict from lib.core.purge import purge from lib.core.settings import CODECS_LIST_PAGE @@ -1995,7 +1996,11 @@ def init(inputOptions=AttribDict(), overrideOptions=False): based upon command line and configuration file options. """ - coloramainit() + if not inputOptions.disableColoring: + coloramainit() + else: + if hasattr(LOGGER_HANDLER, "disable_coloring"): + LOGGER_HANDLER.disable_coloring = True __setConfAttributes() __setKnowledgeBaseAttributes() __mergeOptions(inputOptions, overrideOptions) diff --git a/lib/core/optiondict.py b/lib/core/optiondict.py index 743c97c1e..8f01c867c 100644 --- a/lib/core/optiondict.py +++ b/lib/core/optiondict.py @@ -192,6 +192,7 @@ optDict = { "checkPayload": "boolean", "cleanup": "boolean", "dependencies": "boolean", + "disableColoring": "boolean", "googlePage": "integer", "mobile": "boolean", "pageRank": "boolean", diff --git a/lib/parse/cmdline.py b/lib/parse/cmdline.py index 51b3c11a7..7e15c3c04 100644 --- a/lib/parse/cmdline.py +++ b/lib/parse/cmdline.py @@ -619,6 +619,10 @@ def cmdLineParser(): action="store_true", help="Check for missing sqlmap dependencies") + miscellaneous.add_option("--disable-coloring", dest="disableColoring", + action="store_true", + help="Disable console output coloring") + miscellaneous.add_option("--gpage", dest="googlePage", type="int", help="Use Google dork results from specified page number") diff --git a/sqlmap.conf b/sqlmap.conf index 135e3dd9f..0abfe363f 100644 --- a/sqlmap.conf +++ b/sqlmap.conf @@ -660,6 +660,10 @@ cleanup = False # Valid: True or False dependencies = False +# Disable console output coloring. +# Valid: True or False +disableColoring = False + # Use Google dork results from specified page number. # Valid: integer # Default: 1 diff --git a/thirdparty/ansistrm/ansistrm.py b/thirdparty/ansistrm/ansistrm.py index 8c275e23a..899accc2e 100644 --- a/thirdparty/ansistrm/ansistrm.py +++ b/thirdparty/ansistrm/ansistrm.py @@ -39,11 +39,12 @@ class ColorizingStreamHandler(logging.StreamHandler): } csi = '\x1b[' reset = '\x1b[0m' + disable_coloring = False @property def is_tty(self): isatty = getattr(self.stream, 'isatty', None) - return isatty and isatty() + return isatty and isatty() and not self.disable_coloring def emit(self, record): try: