Browse Source

feat: constant utils

dev
dnomd343 2 years ago
parent
commit
ad349fe1c1
  1. 26
      Utils/Constant/Default.py
  2. 27
      Utils/Constant/LoadEnv.py
  3. 17
      Utils/Constant/Others.py
  4. 24
      Utils/Constant/Plugin.py
  5. 100
      Utils/Constant/Shadowsocks.py
  6. 14
      Utils/Constant/__init__.py
  7. 6
      env.yml

26
Utils/Constant/Default.py

@ -0,0 +1,26 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
Version = 'dev'
LogLevel = 'INFO'
LogFile = 'runtime.log'
ApiPath = '/'
ApiPort = 7839
ApiToken = ''
DnsServer = None
CheckThread = 64
WorkDir = '/tmp/ProxyC'
TestHost = 'proxyc.net'
TestSite = 'www.bing.com'
PathEnv = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin'
from Utils.Constant.LoadEnv import loadEnvOptions
for envKey, envValue in loadEnvOptions('../../env.yml').items():
if type(envValue) == int:
exec('%s = %s' % (envKey, envValue))
if type(envValue) == str:
exec('%s = \'%s\'' % (envKey, envValue))

27
Utils/Constant/LoadEnv.py

@ -0,0 +1,27 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import yaml
def loadEnvOptions(envFile: str) -> dict:
try:
yamlFile = os.path.join(os.path.dirname(os.path.realpath(__file__)), envFile)
yamlContent = open(yamlFile, 'r', encoding = 'utf-8').read() # read raw yaml content
envOptions = yaml.load(yamlContent, Loader = yaml.FullLoader) # decode yaml configure
except: # something error in env configure
return {}
options = {
'Version': envOptions['version'] if 'version' in envOptions else None,
'LogLevel': envOptions['loglevel'] if 'loglevel' in envOptions else None,
'WorkDir': envOptions['dir'] if 'dir' in envOptions else None,
'DnsServer': envOptions['dns'] if 'dns' in envOptions else None,
}
if 'api' in envOptions:
options.update({
'ApiPort': envOptions['api']['port'] if 'port' in envOptions['api'] else None,
'ApiPath': envOptions['api']['path'] if 'path' in envOptions['api'] else None,
'ApiToken': envOptions['api']['token'] if 'token' in envOptions['api'] else None,
})
return {k: v for k, v in options.items() if v is not None} # remove empty value

17
Utils/Constant/Others.py

@ -0,0 +1,17 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# V2ray / Xray
vmessMethods = ['aes-128-gcm', 'chacha20-poly1305', 'auto', 'none', 'zero']
quicMethods = ['none', 'aes-128-gcm', 'chacha20-poly1305']
udpObfuscations = ['none', 'srtp', 'utp', 'wechat-video', 'dtls', 'wireguard']
xtlsFlows = ['xtls-origin', 'xtls-direct', 'xtls-splice']
xtlsFlows = {x: x.replace('-', '-rprx-') for x in xtlsFlows}
# Trojan-Go
trojanGoMethods = ['aes-128-gcm', 'aes-256-gcm', 'chacha20-ietf-poly1305']
# Hysteria
hysteriaProtocols = ['udp', 'wechat-video', 'faketcp']

24
Utils/Constant/Plugin.py

@ -0,0 +1,24 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
Plugins = {
'simple-obfs': ['obfs-local', 'obfs-server'],
'simple-tls': ['simple-tls'],
'v2ray': ['v2ray-plugin'],
'xray': ['xray-plugin'],
'kcptun': ['kcptun-client', 'kcptun-server'],
'gost': ['gost-plugin'],
'cloak': ['ck-client', 'ck-server'],
'go-quiet': ['gq-client', 'gq-server'],
'mos-tls-tunnel': ['mtt-client', 'mtt-server'],
'rabbit': ['rabbit-plugin', 'rabbit'],
'qtun': ['qtun-client', 'qtun-server'],
'gun': ['gun-plugin'],
}
pluginClients = [p[0] for _, p in Plugins.items()] # plugin client list -> obfs-local / simple-tls / ...
Plugins = {caption: { # format plugins info
'client': plugin[0],
'server': plugin[1 if len(plugin) > 1 else 0]
} for caption, plugin in Plugins.items()}

100
Basis/Constant.py → Utils/Constant/Shadowsocks.py

@ -1,62 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import yaml
# Global Options
Version = 'dev'
ApiPath = '/'
ApiPort = 7839
ApiToken = ''
CheckThread = 64
LogLevel = 'INFO'
LogFile = 'runtime.log'
DnsServer = None
WorkDir = '/tmp/ProxyC'
TestHost = 'proxyc.net'
TestSite = 'www.bing.com'
PathEnv = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin'
# Load Env Options
envOptions = {}
try:
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)
except: # something error in env.yaml
pass
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']
# WorkDir Create
try:
os.makedirs(WorkDir) # just like `mkdir -p ...`
except:
pass # folder exist or target is another thing
# Shadowsocks Info
mbedtlsMethods = [
mbedtlsMethods = [ # mbedtls methods in shadowsocks-python
'aes-128-cfb128',
'aes-192-cfb128',
'aes-256-cfb128',
@ -126,32 +71,9 @@ ssMethods = { # methods support of different Shadowsocks project
}
ssAllMethods = set()
[ssAllMethods.update(ssMethods[x]) for x in ssMethods]
[ssAllMethods.update(x) for _, x in ssMethods.items()]
ssAllMethods = sorted(list(ssAllMethods)) # methods of Shadowsocks
# Plugin Info
Plugins = {
'simple-obfs': ['obfs-local', 'obfs-server'],
'simple-tls': ['simple-tls'],
'v2ray': ['v2ray-plugin'],
'xray': ['xray-plugin'],
'kcptun': ['kcptun-client', 'kcptun-server'],
'gost': ['gost-plugin'],
'cloak': ['ck-client', 'ck-server'],
'go-quiet': ['gq-client', 'gq-server'],
'mos-tls-tunnel': ['mtt-client', 'mtt-server'],
'rabbit': ['rabbit-plugin', 'rabbit'],
'qtun': ['qtun-client', 'qtun-server'],
'gun': ['gun-plugin'],
}
Plugins = {x: [Plugins[x][0], Plugins[x][1 if len(Plugins[x]) == 2 else 0]] for x in Plugins}
Plugins = {x: {'client': Plugins[x][0], 'server': Plugins[x][1]} for x in Plugins} # format plugins info
pluginClients = [Plugins[x]['client'] for x in Plugins] # plugin client list -> obfs-local / simple-tls / ...
# ShadowsocksR Info
ssrMethods = [ # methods of ShadowsocksR
'aes-128-ctr', 'aes-192-ctr', 'aes-256-ctr',
'aes-128-gcm', 'aes-192-gcm', 'aes-256-gcm',
@ -178,21 +100,3 @@ ssrObfuscations = [ # obfuscations of ShadowsocksR (obfs)
'plain', 'http_post', 'http_simple', 'random_head',
'tls_simple', 'tls1.2_ticket_auth', 'tls1.2_ticket_fastauth',
]
# V2ray / Xray Info
vmessMethods = ['aes-128-gcm', 'chacha20-poly1305', 'auto', 'none', 'zero']
quicMethods = ['none', 'aes-128-gcm', 'chacha20-poly1305']
udpObfuscations = ['none', 'srtp', 'utp', 'wechat-video', 'dtls', 'wireguard']
xtlsFlows = ['xtls-origin', 'xtls-direct', 'xtls-splice']
xtlsFlows = {x: x.replace('-', '-rprx-') for x in xtlsFlows}
# Trojan-Go Info
trojanGoMethods = ['aes-128-gcm', 'aes-256-gcm', 'chacha20-ietf-poly1305']
# Hysteria Info
hysteriaProtocols = ['udp', 'wechat-video', 'faketcp']

14
Utils/Constant/__init__.py

@ -0,0 +1,14 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
from Utils.Constant.Plugin import *
from Utils.Constant.Others import *
from Utils.Constant.Default import *
from Utils.Constant.Shadowsocks import *
# Create WorkDir
try:
os.makedirs(WorkDir) # just like `mkdir -p ...`
except:
pass # folder exist or target is another thing

6
env.yaml → env.yml

@ -1,8 +1,8 @@
version: 'v0.1'
version: '0.1'
loglevel: 'INFO'
dir: '/tmp/ProxyC'
dir: '/tmp/ProxyC-test'
dns: null
api:
port: 7839
path: '/'
# path: '/'
token: ''
Loading…
Cancel
Save