Skip to content

Commit f5ffd9f

Browse files
committedJan 22, 2016
add --servername option to support various of bottle server adapter
1 parent c6c5a93 commit f5ffd9f

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed
 

‎lib/utils/api.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ def download(taskid, target, filename):
637637
return jsonize({"success": False, "message": "File does not exist"})
638638

639639

640-
def server(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT):
640+
def server(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT, server_name='wsgiref'):
641641
"""
642642
REST-JSON API server
643643
"""
@@ -655,7 +655,14 @@ def server(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT):
655655

656656
# Run RESTful API
657657
try:
658-
run(host=host, port=port, quiet=True, debug=False)
658+
if server_name == 'gevent':
659+
from gevent import monkey
660+
monkey.patch_all()
661+
elif server_name == 'eventlet':
662+
import eventlet
663+
eventlet.monkey_patch()
664+
logger.debug('use {0} adapter run bottle'.format(server_name))
665+
run(host=host, port=port, quiet=True, debug=False, server=server_name)
659666
except socket.error, ex:
660667
if "already in use" in getSafeExString(ex):
661668
logger.error("Address already in use ('%s:%s')" % (host, port))

‎sqlmapapi.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ def main():
3737
apiparser.add_option("-c", "--client", help="Act as a REST-JSON API client", default=RESTAPI_DEFAULT_PORT, action="store_true")
3838
apiparser.add_option("-H", "--host", help="Host of the REST-JSON API server", default=RESTAPI_DEFAULT_ADDRESS, action="store")
3939
apiparser.add_option("-p", "--port", help="Port of the the REST-JSON API server", default=RESTAPI_DEFAULT_PORT, type="int", action="store")
40+
apiparser.add_option("", "--servername", help="bottle Server adapter to use default is wsgiref, see bottle document ", default='wsgiref', action="store")
4041
(args, _) = apiparser.parse_args()
4142

4243
# Start the client or the server
4344
if args.server is True:
44-
server(args.host, args.port)
45+
server(args.host, args.port, server_name=args.servername)
4546
elif args.client is True:
4647
client(args.host, args.port)
4748
else:

0 commit comments

Comments
 (0)
Please sign in to comment.