Permalink
Browse files

fixed options initiation

  • Loading branch information...
1 parent b0635bd commit 7adaffa71b52551cc05bc04eb40c212b16e041cf @inquisb inquisb committed Dec 20, 2012
Showing with 28 additions and 18 deletions.
  1. +1 −1 lib/core/option.py
  2. +2 −0 lib/core/optiondict.py
  3. +21 −16 lib/utils/api.py
  4. +4 −1 sqlmapapi.py
View
@@ -1784,7 +1784,7 @@ def _mergeOptions(inputOptions, overrideOptions):
kb.explicitSettings.add(key)
for key, value in defaults.items():
- if conf[key] is None:
+ if hasattr(conf, key) and conf[key] is None:
conf[key] = value
def _setTrafficOutputFP():
View
@@ -183,6 +183,7 @@
"hexConvert": "boolean",
"oDir": "string",
"parseErrors": "boolean",
+ "saveCmdline": "boolean",
"updateAll": "boolean",
"tor": "boolean",
"torPort": "integer",
@@ -202,6 +203,7 @@
"hpp": "boolean",
"mobile": "boolean",
"pageRank": "boolean",
+ "purgeOutput": "boolean",
"smart": "boolean",
"testFilter": "string",
"wizard": "boolean",
View
@@ -7,7 +7,6 @@
import json
import logging
-import optparse
import os
import shutil
import sys
@@ -27,20 +26,21 @@
from extra.bottle.bottle import static_file
from extra.bottle.bottle import template
from lib.controller.controller import start
+from lib.core.common import unArrayizeValue
from lib.core.convert import hexencode
from lib.core.convert import stdoutencode
from lib.core.data import paths
from lib.core.datatype import AttribDict
-from lib.core.data import cmdLineOptions
from lib.core.data import kb
from lib.core.data import logger
+from lib.core.defaults import _defaults
from lib.core.log import FORMATTER
from lib.core.log import LOGGER_HANDLER
from lib.core.log import LOGGER_OUTPUT
from lib.core.exception import SqlmapMissingDependence
+from lib.core.optiondict import optDict
from lib.core.option import init
from lib.core.settings import UNICODE_ENCODING
-from lib.parse.cmdline import cmdLineParser
RESTAPI_SERVER_HOST = "127.0.0.1"
RESTAPI_SERVER_PORT = 8775
@@ -60,6 +60,21 @@ def is_admin(taskid):
else:
return True
+def init_options():
+ dataype = {"boolean": False, "string": "", "integer": 0, "float": 0.0}
+ options = AttribDict()
+
+ for _ in optDict:
+ for name, type_ in optDict[_].items():
+ type_ = unArrayizeValue(type_)
+ options[name] = _defaults.get(name, dataype[type_])
+
+ # Enforce batch mode and disable coloring
+ options.batch = True
+ options.disableColoring = True
+
+ return options
+
@hook("after_request")
def security_headers():
"""
@@ -106,10 +121,8 @@ def task_new():
"""
global tasks
- optset()
-
taskid = hexencode(os.urandom(16))
- tasks[taskid] = AttribDict(cmdLineOptions)
+ tasks[taskid] = init_options()
return jsonize({"taskid": taskid})
@@ -247,7 +260,7 @@ def scan_start(taskid):
for key, value in request.json.items():
tasks[taskid][key] = value
- print "TASKS:", tasks
+ print "DEBUG TASKS:", tasks
# Overwrite output directory (oDir) value to a temporary directory
tasks[taskid].oDir = tempfile.mkdtemp(prefix="sqlmap-")
@@ -328,23 +341,15 @@ def download(taskid, target, filename):
else:
abort(500)
-def optset():
- # Store original command line options for possible later restoration
- cmdLineOptions.update(cmdLineParser().__dict__)
-
def server(host="0.0.0.0", port=RESTAPI_SERVER_PORT):
"""
REST-JSON API server
"""
global adminid
global tasks
- # Enforce batch mode and disable coloring
- cmdLineOptions.batch = True
- cmdLineOptions.disableColoring = True
-
adminid = hexencode(os.urandom(16))
- tasks[adminid] = AttribDict(cmdLineOptions)
+ tasks[adminid] = init_options()
logger.info("running REST-JSON API server at '%s:%d'.." % (host, port))
logger.info("the admin task ID is: %s" % adminid)
View
@@ -25,16 +25,19 @@
# Set default logging level to debug
logger.setLevel(logging.DEBUG)
+ # Initialize path variable
paths.SQLMAP_ROOT_PATH = modulePath()
setPaths()
+ # Parse command line options
apiparser = optparse.OptionParser()
- apiparser.add_option("--server", help="Act as a REST-JSON API server", default=RESTAPI_SERVER_PORT, action="store_true")
+ apiparser.add_option("-s", "--server", help="Act as a REST-JSON API server", default=RESTAPI_SERVER_PORT, action="store_true")
apiparser.add_option("-c", "--client", help="Act as a REST-JSON API client", default=RESTAPI_SERVER_PORT, action="store_true")
apiparser.add_option("-H", "--host", help="Host of the REST-JSON API server", default=RESTAPI_SERVER_HOST, action="store")
apiparser.add_option("-p", "--port", help="Port of the the REST-JSON API server", default=RESTAPI_SERVER_PORT, type="int", action="store")
(args, _) = apiparser.parse_args()
+ # Start the client or the server
if args.server is True:
server(args.host, args.port)
elif args.client is True:

0 comments on commit 7adaffa

Please sign in to comment.