From 700f2d68db625fc527c08fdb198585a039bbe859 Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Sun, 7 Aug 2022 21:25:31 +0800 Subject: [PATCH] update: add dns and api path options --- Basis/Api.py | 2 +- Basis/Constant.py | 4 +--- main.py | 11 +++++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Basis/Api.py b/Basis/Api.py index 8cb5b36..3a37bda 100644 --- a/Basis/Api.py +++ b/Basis/Api.py @@ -115,6 +115,6 @@ def getVersion() -> Response: def startServer() -> None: - logging.warning('API server at http://:%i/' % ApiPort) + logging.warning('API server at http://:%i%s' % (ApiPort, ApiPath)) logging.warning('API ' + ('without token' if ApiToken == '' else 'token -> %s' % ApiToken)) pywsgi.WSGIServer(('0.0.0.0', ApiPort), webApi).serve_forever() # powered by gevent diff --git a/Basis/Constant.py b/Basis/Constant.py index 4175aa0..72c3b55 100644 --- a/Basis/Constant.py +++ b/Basis/Constant.py @@ -8,12 +8,10 @@ ApiPath = '/' ApiPort = 7839 ApiToken = '' -# LogLevel = 'DEBUG' -# LogLevel = 'WARNING' LogLevel = 'INFO' LogFile = 'runtime.log' -DnsServer = [] +DnsServer = None WorkDir = '/tmp/ProxyC' TestHost = 'proxyc.net' TestSite = 'www.bing.com' diff --git a/main.py b/main.py index 2729378..4d5384e 100755 --- a/main.py +++ b/main.py @@ -12,11 +12,12 @@ from Basis import Constant def mainArgParse(rawArgs: list) -> argparse.Namespace: mainParser = argparse.ArgumentParser(description = 'Start running API server') - mainParser.add_argument('--log', type = str, default = 'debug', help = 'output log level') - mainParser.add_argument('--port', type = int, default = 7839, help = 'port for running') - mainParser.add_argument('--token', type = str, default = '', help = 'token for api server') + mainParser.add_argument('--log', type = str, default = Constant.LogLevel, help = 'output log level') + mainParser.add_argument('--dns', type = str, nargs = '+', help = 'specify dns server') + mainParser.add_argument('--port', type = int, default = Constant.ApiPort, help = 'port for running') + mainParser.add_argument('--path', type = str, default = Constant.ApiPath, help = 'root path for api server') + mainParser.add_argument('--token', type = str, default = Constant.ApiToken, help = 'token for api server') mainParser.add_argument('-v', '--version', help = 'show version', action = 'store_true') - # TODO: api path / dns server return mainParser.parse_args(rawArgs) @@ -51,7 +52,9 @@ else: print('ProxyC version -> %s' % Constant.Version) sys.exit(0) Constant.LogLevel = mainArgs.log # overwrite global options + Constant.DnsServer = mainArgs.dns Constant.ApiPort = mainArgs.port + Constant.ApiPath = mainArgs.path Constant.ApiToken = mainArgs.token