From aa2112b3603ed7f87e66f33049c0b927c983ec9e Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Thu, 17 Sep 2015 16:18:58 +0200 Subject: [PATCH] Update for #1414 --- lib/utils/api.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/utils/api.py b/lib/utils/api.py index 09aac2c5a..d8a38bf1e 100644 --- a/lib/utils/api.py +++ b/lib/utils/api.py @@ -661,7 +661,7 @@ def server(host="0.0.0.0", port=RESTAPI_SERVER_PORT): def _client(url, options=None): - logger.debug("Calling " + url) + logger.debug("Calling %s" % url) try: data = None if options is not None: @@ -671,7 +671,7 @@ def _client(url, options=None): text = response.read() except: if options: - logger.error("Failed to load and parse " + url) + logger.error("Failed to load and parse %s" % url) raise return text @@ -707,10 +707,10 @@ def client(host=RESTAPI_SERVER_HOST, port=RESTAPI_SERVER_PORT): if not taskid: logger.error("No task ID in use") continue - raw = _client(addr + "/scan/" + taskid + "/" + command) + raw = _client("%s/scan/%s/%s" % (addr, taskid, command)) res = dejsonize(raw) if not res["success"]: - logger.error("Failed to execute command " + command) + logger.error("Failed to execute command %s" % command) dataToStdout("%s\n" % raw) elif command.startswith("new"): @@ -730,7 +730,7 @@ def client(host=RESTAPI_SERVER_HOST, port=RESTAPI_SERVER_PORT): if cmdLineOptions[key] is None: del cmdLineOptions[key] - raw = _client(addr + "/task/new") + raw = _client("%s/task/new" % addr) res = dejsonize(raw) if not res["success"]: logger.error("Failed to create new task") @@ -738,7 +738,7 @@ def client(host=RESTAPI_SERVER_HOST, port=RESTAPI_SERVER_PORT): taskid = res["taskid"] logger.info("New task ID is '%s'" % taskid) - raw = _client(addr + "/scan/" + taskid + "/start", cmdLineOptions) + raw = _client("%s/scan/%s/start" % (addr, taskid), cmdLineOptions) res = dejsonize(raw) if not res["success"]: logger.error("Failed to start scan") @@ -758,10 +758,12 @@ def client(host=RESTAPI_SERVER_HOST, port=RESTAPI_SERVER_PORT): logger.info("Switching to task ID '%s' " % taskid) elif command in ("list", "flush"): - raw = _client(addr + "/admin/0/" + command) + raw = _client("%s/admin/%s/%s" % (addr, taskid or 0, command)) res = dejsonize(raw) if not res["success"]: - logger.error("Failed to execute command " + command) + logger.error("Failed to execute command %s" % command) + elif command == "flush": + taskid = None dataToStdout("%s\n" % raw) elif command in ("exit", "bye", "quit", 'q'):