3232from lib .core .data import paths
3333from lib .core .common import unhandledExceptionMessage
3434from lib .core .exception import exceptionsTuple
35+ from lib .core .exception import SqlmapMissingDependence
3536from lib .core .exception import SqlmapSilentQuitException
3637from lib .core .exception import SqlmapUserQuitException
3738from lib .core .log import FORMATTER
3839from lib .core .log import LOGGER_HANDLER
3940from lib .core .option import init
4041from lib .core .profiling import profile
4142from lib .core .settings import LEGAL_DISCLAIMER
43+ from lib .core .settings import RESTAPI_SERVER_PORT
4244from lib .core .settings import XMLRPC_SERVER_PORT
4345from lib .core .testing import smokeTest
4446from lib .core .testing import liveTest
4547from lib .parse .cmdline import cmdLineParser
4648from lib .utils .xmlrpc import XMLRPCServer
4749
50+ try :
51+ from lib .utils .restapi import restAPIrun
52+ except SqlmapMissingDependence , e :
53+ e = getUnicode (e )
54+ logger .critical (e )
55+ sys .exit (1 )
56+
4857def modulePath ():
4958 """
5059 This will get us the program's directory, even if we are frozen
@@ -53,6 +62,18 @@ def modulePath():
5362
5463 return os .path .dirname (getUnicode (sys .executable if weAreFrozen () else __file__ , sys .getfilesystemencoding ()))
5564
65+ def restApiServe ():
66+ logger .setLevel (logging .INFO )
67+ cmdLineOptions .batch = True
68+ cmdLineOptions .disableColoring = True
69+ restAPIrun (port = cmdLineOptions .restApiPort or RESTAPI_SERVER_PORT )
70+ def emit (self , record ):
71+ message = stdoutencode (FORMATTER .format (record ))
72+ sys .stdout .write ("%s\n " % message .strip ('\r ' ))
73+ LOGGER_HANDLER .emit = types .MethodType (emit , LOGGER_HANDLER , type (LOGGER_HANDLER ))
74+ sys .stdout = StringIO .StringIO ()
75+ sys .stderr = StringIO .StringIO ()
76+
5677def xmlRpcServe ():
5778 logger .setLevel (logging .INFO )
5879 cmdLineOptions .batch = True
@@ -82,7 +103,9 @@ def main():
82103 # Store original command line options for possible later restoration
83104 cmdLineOptions .update (cmdLineParser ().__dict__ )
84105
85- if cmdLineOptions .xmlRpc :
106+ if cmdLineOptions .restApi :
107+ restApiServe ()
108+ elif cmdLineOptions .xmlRpc :
86109 xmlRpcServe ()
87110 else :
88111 init (cmdLineOptions )
@@ -106,6 +129,7 @@ def main():
106129 except exceptionsTuple , e :
107130 e = getUnicode (e )
108131 logger .critical (e )
132+ sys .exit (1 )
109133
110134 except KeyboardInterrupt :
111135 print
0 commit comments