diff --git a/Basis/Constant.py b/Basis/Constant.py index 72c3b55..9ffbc7f 100644 --- a/Basis/Constant.py +++ b/Basis/Constant.py @@ -1,6 +1,9 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +import os +import yaml + # Global Options Version = 'dev' @@ -17,6 +20,26 @@ TestHost = 'proxyc.net' TestSite = 'www.bing.com' PathEnv = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin' +# Load Env Options +yamlFile = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../env.yaml') +yamlContent = open(yamlFile, 'r', encoding = 'utf-8').read() +envOptions = yaml.load(yamlContent, Loader = yaml.FullLoader) +if 'version' in envOptions: + Version = envOptions['version'] +if 'loglevel' in envOptions: + LogLevel = envOptions['loglevel'] +if 'dir' in envOptions: + WorkDir = envOptions['dir'] +if 'dns' in envOptions: + DnsServer = envOptions['dns'] +if 'api' in envOptions: + if 'port' in envOptions['api']: + ApiPort = envOptions['api']['port'] + if 'path' in envOptions['api']: + ApiPath = envOptions['api']['path'] + if 'token' in envOptions['api']: + ApiToken = envOptions['api']['token'] + # Shadowsocks Info mbedtlsMethods = [ 'aes-128-cfb128', diff --git a/Dockerfile b/Dockerfile index 699f252..e3aa413 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,7 +31,7 @@ FROM ${PYTHON_IMG} AS wheels WORKDIR /wheels/ RUN apk add linux-headers COPY --from=build-base /apk/ /apk/ -RUN /apk/build-base && pip wheel colorlog flask IPy psutil pysocks requests salsa20 +RUN /apk/build-base && pip wheel colorlog flask IPy psutil pysocks pyyaml requests salsa20 COPY --from=gevent /wheels/*.whl /wheels/ COPY --from=numpy /wheels/*.whl /wheels/ diff --git a/env.yaml b/env.yaml new file mode 100644 index 0000000..7432cd0 --- /dev/null +++ b/env.yaml @@ -0,0 +1,10 @@ +version: 'v0.1' +loglevel: 'INFO' +dir: '/tmp/ProxyC' +dns: + - 223.5.5.5 + - 119.29.29.29 +api: + port: 17839 + path: '/v1' + token: 'dnomd343' diff --git a/main.py b/main.py index 4d5384e..80fc9fd 100755 --- a/main.py +++ b/main.py @@ -13,7 +13,7 @@ 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 = Constant.LogLevel, help = 'output log level') - mainParser.add_argument('--dns', type = str, nargs = '+', help = 'specify dns server') + mainParser.add_argument('--dns', type = str, default = Constant.DnsServer, 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')