Browse Source

update: add dns and api path options

master^2
dnomd343 2 years ago
parent
commit
700f2d68db
  1. 2
      Basis/Api.py
  2. 4
      Basis/Constant.py
  3. 11
      main.py

2
Basis/Api.py

@ -115,6 +115,6 @@ def getVersion() -> Response:
def startServer() -> None: 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)) logging.warning('API ' + ('without token' if ApiToken == '' else 'token -> %s' % ApiToken))
pywsgi.WSGIServer(('0.0.0.0', ApiPort), webApi).serve_forever() # powered by gevent pywsgi.WSGIServer(('0.0.0.0', ApiPort), webApi).serve_forever() # powered by gevent

4
Basis/Constant.py

@ -8,12 +8,10 @@ ApiPath = '/'
ApiPort = 7839 ApiPort = 7839
ApiToken = '' ApiToken = ''
# LogLevel = 'DEBUG'
# LogLevel = 'WARNING'
LogLevel = 'INFO' LogLevel = 'INFO'
LogFile = 'runtime.log' LogFile = 'runtime.log'
DnsServer = [] DnsServer = None
WorkDir = '/tmp/ProxyC' WorkDir = '/tmp/ProxyC'
TestHost = 'proxyc.net' TestHost = 'proxyc.net'
TestSite = 'www.bing.com' TestSite = 'www.bing.com'

11
main.py

@ -12,11 +12,12 @@ from Basis import Constant
def mainArgParse(rawArgs: list) -> argparse.Namespace: def mainArgParse(rawArgs: list) -> argparse.Namespace:
mainParser = argparse.ArgumentParser(description = 'Start running API server') mainParser = argparse.ArgumentParser(description = 'Start running API server')
mainParser.add_argument('--log', type = str, default = 'debug', help = 'output log level') mainParser.add_argument('--log', type = str, default = Constant.LogLevel, help = 'output log level')
mainParser.add_argument('--port', type = int, default = 7839, help = 'port for running') mainParser.add_argument('--dns', type = str, nargs = '+', help = 'specify dns server')
mainParser.add_argument('--token', type = str, default = '', help = 'token for api 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') mainParser.add_argument('-v', '--version', help = 'show version', action = 'store_true')
# TODO: api path / dns server
return mainParser.parse_args(rawArgs) return mainParser.parse_args(rawArgs)
@ -51,7 +52,9 @@ else:
print('ProxyC version -> %s' % Constant.Version) print('ProxyC version -> %s' % Constant.Version)
sys.exit(0) sys.exit(0)
Constant.LogLevel = mainArgs.log # overwrite global options Constant.LogLevel = mainArgs.log # overwrite global options
Constant.DnsServer = mainArgs.dns
Constant.ApiPort = mainArgs.port Constant.ApiPort = mainArgs.port
Constant.ApiPath = mainArgs.path
Constant.ApiToken = mainArgs.token Constant.ApiToken = mainArgs.token

Loading…
Cancel
Save