77
88import json
99import logging
10- import optparse
1110import os
1211import shutil
1312import sys
2726from extra .bottle .bottle import static_file
2827from extra .bottle .bottle import template
2928from lib .controller .controller import start
29+ from lib .core .common import unArrayizeValue
3030from lib .core .convert import hexencode
3131from lib .core .convert import stdoutencode
3232from lib .core .data import paths
3333from lib .core .datatype import AttribDict
34- from lib .core .data import cmdLineOptions
3534from lib .core .data import kb
3635from lib .core .data import logger
36+ from lib .core .defaults import _defaults
3737from lib .core .log import FORMATTER
3838from lib .core .log import LOGGER_HANDLER
3939from lib .core .log import LOGGER_OUTPUT
4040from lib .core .exception import SqlmapMissingDependence
41+ from lib .core .optiondict import optDict
4142from lib .core .option import init
4243from lib .core .settings import UNICODE_ENCODING
43- from lib .parse .cmdline import cmdLineParser
4444
4545RESTAPI_SERVER_HOST = "127.0.0.1"
4646RESTAPI_SERVER_PORT = 8775
@@ -60,6 +60,21 @@ def is_admin(taskid):
6060 else :
6161 return True
6262
63+ def init_options ():
64+ dataype = {"boolean" : False , "string" : "" , "integer" : 0 , "float" : 0.0 }
65+ options = AttribDict ()
66+
67+ for _ in optDict :
68+ for name , type_ in optDict [_ ].items ():
69+ type_ = unArrayizeValue (type_ )
70+ options [name ] = _defaults .get (name , dataype [type_ ])
71+
72+ # Enforce batch mode and disable coloring
73+ options .batch = True
74+ options .disableColoring = True
75+
76+ return options
77+
6378@hook ("after_request" )
6479def security_headers ():
6580 """
@@ -106,10 +121,8 @@ def task_new():
106121 """
107122 global tasks
108123
109- optset ()
110-
111124 taskid = hexencode (os .urandom (16 ))
112- tasks [taskid ] = AttribDict ( cmdLineOptions )
125+ tasks [taskid ] = init_options ( )
113126
114127 return jsonize ({"taskid" : taskid })
115128
@@ -247,7 +260,7 @@ def scan_start(taskid):
247260 for key , value in request .json .items ():
248261 tasks [taskid ][key ] = value
249262
250- print "TASKS:" , tasks
263+ print "DEBUG TASKS:" , tasks
251264
252265 # Overwrite output directory (oDir) value to a temporary directory
253266 tasks [taskid ].oDir = tempfile .mkdtemp (prefix = "sqlmap-" )
@@ -328,23 +341,15 @@ def download(taskid, target, filename):
328341 else :
329342 abort (500 )
330343
331- def optset ():
332- # Store original command line options for possible later restoration
333- cmdLineOptions .update (cmdLineParser ().__dict__ )
334-
335344def server (host = "0.0.0.0" , port = RESTAPI_SERVER_PORT ):
336345 """
337346 REST-JSON API server
338347 """
339348 global adminid
340349 global tasks
341350
342- # Enforce batch mode and disable coloring
343- cmdLineOptions .batch = True
344- cmdLineOptions .disableColoring = True
345-
346351 adminid = hexencode (os .urandom (16 ))
347- tasks [adminid ] = AttribDict ( cmdLineOptions )
352+ tasks [adminid ] = init_options ( )
348353
349354 logger .info ("running REST-JSON API server at '%s:%d'.." % (host , port ))
350355 logger .info ("the admin task ID is: %s" % adminid )
0 commit comments