Skip to content

Commit dc7f2a7

Browse files
committed
Minor refactoring
1 parent 273679f commit dc7f2a7

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

lib/core/settings.py

+6
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,12 @@
593593
# Number of rows to generate inside the full union test for limited output (mustn't be too large to prevent payload length problems)
594594
LIMITED_ROWS_TEST_NUMBER = 15
595595

596+
# Default REST-JSON API server listen address
597+
RESTAPI_DEFAULT_ADDRESS = "127.0.0.1"
598+
599+
# Default REST-JSON API server listen port
600+
RESTAPI_DEFAULT_PORT = 8775
601+
596602
# Format used for representing invalid unicode characters
597603
INVALID_UNICODE_CHAR_FORMAT = r"\x%02x"
598604

lib/utils/api.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
from lib.core.log import LOGGER_HANDLER
3737
from lib.core.optiondict import optDict
3838
from lib.core.settings import IS_WIN
39+
from lib.core.settings import RESTAPI_DEFAULT_ADDRESS
40+
from lib.core.settings import RESTAPI_DEFAULT_PORT
3941
from lib.core.subprocessng import Popen
4042
from lib.parse.cmdline import cmdLineParser
4143
from thirdparty.bottle.bottle import error as return_error
@@ -46,9 +48,6 @@
4648
from thirdparty.bottle.bottle import response
4749
from thirdparty.bottle.bottle import run
4850

49-
RESTAPI_SERVER_HOST = "127.0.0.1"
50-
RESTAPI_SERVER_PORT = 8775
51-
5251

5352
# global settings
5453
class DataStore(object):
@@ -638,7 +637,7 @@ def download(taskid, target, filename):
638637
return jsonize({"success": False, "message": "File does not exist"})
639638

640639

641-
def server(host="0.0.0.0", port=RESTAPI_SERVER_PORT):
640+
def server(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT):
642641
"""
643642
REST-JSON API server
644643
"""
@@ -680,7 +679,7 @@ def _client(url, options=None):
680679
return text
681680

682681

683-
def client(host=RESTAPI_SERVER_HOST, port=RESTAPI_SERVER_PORT):
682+
def client(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT):
684683
"""
685684
REST-JSON API client
686685
"""

sqlmapapi.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
from lib.core.common import setPaths
1515
from lib.core.data import paths
1616
from lib.core.data import logger
17+
from lib.core.settings import RESTAPI_DEFAULT_ADDRESS
18+
from lib.core.settings import RESTAPI_DEFAULT_PORT
1719
from lib.utils.api import client
1820
from lib.utils.api import server
1921

20-
RESTAPI_SERVER_HOST = "127.0.0.1"
21-
RESTAPI_SERVER_PORT = 8775
22-
2322
if __name__ == "__main__":
2423
"""
2524
REST-JSON API main function
@@ -33,10 +32,10 @@
3332

3433
# Parse command line options
3534
apiparser = optparse.OptionParser()
36-
apiparser.add_option("-s", "--server", help="Act as a REST-JSON API server", default=RESTAPI_SERVER_PORT, action="store_true")
37-
apiparser.add_option("-c", "--client", help="Act as a REST-JSON API client", default=RESTAPI_SERVER_PORT, action="store_true")
38-
apiparser.add_option("-H", "--host", help="Host of the REST-JSON API server", default=RESTAPI_SERVER_HOST, action="store")
39-
apiparser.add_option("-p", "--port", help="Port of the the REST-JSON API server", default=RESTAPI_SERVER_PORT, type="int", action="store")
35+
apiparser.add_option("-s", "--server", help="Act as a REST-JSON API server", default=RESTAPI_DEFAULT_PORT, action="store_true")
36+
apiparser.add_option("-c", "--client", help="Act as a REST-JSON API client", default=RESTAPI_DEFAULT_PORT, action="store_true")
37+
apiparser.add_option("-H", "--host", help="Host of the REST-JSON API server", default=RESTAPI_DEFAULT_ADDRESS, action="store")
38+
apiparser.add_option("-p", "--port", help="Port of the the REST-JSON API server", default=RESTAPI_DEFAULT_PORT, type="int", action="store")
4039
(args, _) = apiparser.parse_args()
4140

4241
# Start the client or the server

0 commit comments

Comments
 (0)