From f5ffd9fa02d024e9994cd683c8bd8fc66f6c3495 Mon Sep 17 00:00:00 2001 From: dozysun Date: Fri, 22 Jan 2016 11:33:12 +0800 Subject: [PATCH 1/2] add --servername option to support various of bottle server adapter --- lib/utils/api.py | 11 +++++++++-- sqlmapapi.py | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/utils/api.py b/lib/utils/api.py index 0be752d2d..1d186a60d 100644 --- a/lib/utils/api.py +++ b/lib/utils/api.py @@ -637,7 +637,7 @@ def download(taskid, target, filename): return jsonize({"success": False, "message": "File does not exist"}) -def server(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT): +def server(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT, server_name='wsgiref'): """ REST-JSON API server """ @@ -655,7 +655,14 @@ def server(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT): # Run RESTful API try: - run(host=host, port=port, quiet=True, debug=False) + if server_name == 'gevent': + from gevent import monkey + monkey.patch_all() + elif server_name == 'eventlet': + import eventlet + eventlet.monkey_patch() + logger.debug('use {0} adapter run bottle'.format(server_name)) + run(host=host, port=port, quiet=True, debug=False, server=server_name) except socket.error, ex: if "already in use" in getSafeExString(ex): logger.error("Address already in use ('%s:%s')" % (host, port)) diff --git a/sqlmapapi.py b/sqlmapapi.py index a4baa6ef3..a1effcc17 100755 --- a/sqlmapapi.py +++ b/sqlmapapi.py @@ -37,11 +37,12 @@ def main(): 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") + apiparser.add_option("", "--servername", help="bottle Server adapter to use default is wsgiref, see bottle document ", default='wsgiref', action="store") (args, _) = apiparser.parse_args() # Start the client or the server if args.server is True: - server(args.host, args.port) + server(args.host, args.port, server_name=args.servername) elif args.client is True: client(args.host, args.port) else: From 997362f61bee9ff528ba0f99cf764edd9ccc9e3b Mon Sep 17 00:00:00 2001 From: dozysun Date: Wed, 27 Jan 2016 10:35:18 +0800 Subject: [PATCH 2/2] change option name to adapter --- lib/utils/api.py | 10 +++++----- sqlmapapi.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/utils/api.py b/lib/utils/api.py index 1d186a60d..9992979e0 100644 --- a/lib/utils/api.py +++ b/lib/utils/api.py @@ -637,7 +637,7 @@ def download(taskid, target, filename): return jsonize({"success": False, "message": "File does not exist"}) -def server(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT, server_name='wsgiref'): +def server(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT, adapter='wsgiref'): """ REST-JSON API server """ @@ -655,14 +655,14 @@ def server(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT, server_name= # Run RESTful API try: - if server_name == 'gevent': + if adapter == 'gevent': from gevent import monkey monkey.patch_all() - elif server_name == 'eventlet': + elif adapter == 'eventlet': import eventlet eventlet.monkey_patch() - logger.debug('use {0} adapter run bottle'.format(server_name)) - run(host=host, port=port, quiet=True, debug=False, server=server_name) + logger.debug('use {0} adapter run bottle'.format(adapter)) + run(host=host, port=port, quiet=True, debug=False, server=adapter) except socket.error, ex: if "already in use" in getSafeExString(ex): logger.error("Address already in use ('%s:%s')" % (host, port)) diff --git a/sqlmapapi.py b/sqlmapapi.py index a1effcc17..0c3562aa7 100755 --- a/sqlmapapi.py +++ b/sqlmapapi.py @@ -37,12 +37,12 @@ def main(): 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") - apiparser.add_option("", "--servername", help="bottle Server adapter to use default is wsgiref, see bottle document ", default='wsgiref', action="store") + apiparser.add_option("", "--adapter", help="bottle Server adapter to use default is wsgiref, see bottle document ", default='wsgiref', action="store") (args, _) = apiparser.parse_args() # Start the client or the server if args.server is True: - server(args.host, args.port, server_name=args.servername) + server(args.host, args.port, adapter=args.adapter) elif args.client is True: client(args.host, args.port) else: