2013-02-14 15:32:17 +04:00
#!/usr/bin/env python
2012-12-20 18:59:11 +04:00
"""
2016-01-06 02:06:12 +03:00
Copyright ( c ) 2006 - 2016 sqlmap developers ( http : / / sqlmap . org / )
2012-12-20 18:59:11 +04:00
See the file ' doc/COPYING ' for copying permission
"""
import logging
2012-12-20 19:29:23 +04:00
import optparse
2012-12-20 18:59:11 +04:00
2015-11-08 02:10:28 +03:00
from lib . utils import versioncheck # this has to be the first non-standard import
2013-02-06 13:30:54 +04:00
from sqlmap import modulePath
2012-12-20 18:59:11 +04:00
from lib . core . common import setPaths
from lib . core . data import paths
from lib . core . data import logger
2016-01-27 12:03:30 +03:00
from lib . core . settings import RESTAPI_DEFAULT_ADAPTER
2015-12-13 01:48:30 +03:00
from lib . core . settings import RESTAPI_DEFAULT_ADDRESS
from lib . core . settings import RESTAPI_DEFAULT_PORT
2012-12-20 18:59:11 +04:00
from lib . utils . api import client
from lib . utils . api import server
2016-01-07 23:46:20 +03:00
def main ( ) :
2012-12-20 18:59:11 +04:00
"""
REST - JSON API main function
"""
2016-01-07 23:46:20 +03:00
2012-12-20 18:59:11 +04:00
# Set default logging level to debug
logger . setLevel ( logging . DEBUG )
2012-12-20 20:53:43 +04:00
# Initialize path variable
2012-12-20 18:59:11 +04:00
paths . SQLMAP_ROOT_PATH = modulePath ( )
setPaths ( )
2012-12-20 20:53:43 +04:00
# Parse command line options
2012-12-20 19:29:23 +04:00
apiparser = optparse . OptionParser ( )
2015-12-13 01:48:30 +03:00
apiparser . add_option ( " -s " , " --server " , help = " Act as a REST-JSON API server " , default = RESTAPI_DEFAULT_PORT , action = " store_true " )
apiparser . add_option ( " -c " , " --client " , help = " Act as a REST-JSON API client " , default = RESTAPI_DEFAULT_PORT , action = " store_true " )
apiparser . add_option ( " -H " , " --host " , help = " Host of the REST-JSON API server " , default = RESTAPI_DEFAULT_ADDRESS , action = " store " )
apiparser . add_option ( " -p " , " --port " , help = " Port of the the REST-JSON API server " , default = RESTAPI_DEFAULT_PORT , type = " int " , action = " store " )
2016-01-27 12:03:30 +03:00
apiparser . add_option ( " --adapter " , help = " Server (bottle) adapter to use (default %s ) " % RESTAPI_DEFAULT_ADAPTER , default = RESTAPI_DEFAULT_ADAPTER , action = " store " )
2012-12-20 19:29:23 +04:00
( args , _ ) = apiparser . parse_args ( )
2012-12-20 18:59:11 +04:00
2012-12-20 20:53:43 +04:00
# Start the client or the server
2012-12-20 18:59:11 +04:00
if args . server is True :
2016-01-27 05:35:18 +03:00
server ( args . host , args . port , adapter = args . adapter )
2012-12-20 18:59:11 +04:00
elif args . client is True :
client ( args . host , args . port )
2013-07-10 18:57:44 +04:00
else :
apiparser . print_help ( )
2016-01-07 23:46:20 +03:00
if __name__ == " __main__ " :
main ( )