Browse Source

fix: python reference parameter in dict

master
Dnomd343 3 years ago
parent
commit
f868654f03
  1. 14
      Checker.py
  2. 28
      ProxyBuilder/Shadowsocks.py
  3. 122
      ProxyBuilder/ShadowsocksR.py
  4. 9
      ProxyBuilder/builder.py

14
Checker.py

@ -48,13 +48,15 @@ def proxyTest(
启动失败:
return {
'success': False
'success': False,
'info': proxyInfo
}
测试完成:
return {
'success': True,
'result': checkResult
'check': checkResult,
'info': proxyInfo
}
"""
@ -74,7 +76,8 @@ def proxyTest(
return None
elif not status: # 节点信息有误
return {
'success': False
'success': False,
'info': rawInfo['info']
}
time.sleep(startDelay) # 延迟等待客户端启动
@ -85,7 +88,8 @@ def proxyTest(
elif not status: # 客户端异常退出
Builder.destroy(client)
return {
'success': False
'success': False,
'info': rawInfo['info']
}
if 'check' not in rawInfo: # 缺少检测项目
@ -106,5 +110,5 @@ def proxyTest(
return {
'success': True,
'check': checkResult,
'proxy': rawInfo['info']
'info': rawInfo['info']
}

28
ProxyBuilder/Shadowsocks.py

@ -218,7 +218,8 @@ def __pluginWithUdp(plugin: str, pluginParam: str) -> bool: # 插件是否使用
return False
return True # 默认假定占用UDP
def __ssPython(proxyInfo: dict, socksPort: int, isLegacy: bool = False) -> tuple[dict, str]: # ss-python配置生成
def __ssPython(proxyInfo: dict, socksPort: int,
isUdp: bool, isLegacy: bool = False) -> tuple[dict, str]: # ss-python配置生成
config = __baseConfig(proxyInfo, socksPort)
mbedtlsMethods = [
'aes-128-cfb128',
@ -233,20 +234,21 @@ def __ssPython(proxyInfo: dict, socksPort: int, isLegacy: bool = False) -> tuple
config['method'] = 'mbedtls:' + config['method']
if config['method'] in ['idea-cfb', 'seed-cfb']: # 仅openssl旧版本支持
config['extra_opts'] = '--libopenssl=libcrypto.so.1.0.0'
if not proxyInfo['udp']:
if not isUdp:
config['no_udp'] = True # 关闭UDP代理
config['shadowsocks'] = 'ss-python-legacy-local' if isLegacy else 'ss-python-local'
return config, 'ss-bootstrap-local'
def __ssLibev(proxyInfo: dict, socksPort: int, isLegacy: bool = False) -> tuple[dict, str]: # ss-libev配置生成
def __ssLibev(proxyInfo: dict, socksPort: int,
isUdp: bool, isLegacy: bool = False) -> tuple[dict, str]: # ss-libev配置生成
config = __baseConfig(proxyInfo, socksPort)
if proxyInfo['udp']:
if isUdp:
config['mode'] = 'tcp_and_udp'
return config, 'ss-libev-legacy-local' if isLegacy else 'ss-libev-local'
def __ssRust(proxyInfo: dict, socksPort: int) -> tuple[dict, str]: # ss-rust配置生成
def __ssRust(proxyInfo: dict, socksPort: int, isUdp: bool) -> tuple[dict, str]: # ss-rust配置生成
config = __baseConfig(proxyInfo, socksPort)
if proxyInfo['udp']:
if isUdp:
config['mode'] = 'tcp_and_udp'
return config, 'ss-rust-local'
@ -287,21 +289,21 @@ def load(proxyInfo: dict, socksPort: int, configFile: str) -> tuple[list or None
if not __ssFormatCheck(proxyInfo): # 参数有误
return None, None, None
if proxyInfo['plugin'] is None: # 无插件时启用UDP
proxyInfo['udp'] = True
isUdp = True
else:
proxyInfo['udp'] = not __pluginWithUdp( # 获取插件UDP冲突状态
isUdp = not __pluginWithUdp( # 获取插件UDP冲突状态
proxyInfo['plugin']['type'], proxyInfo['plugin']['param']
)
if proxyInfo['method'] in ssMethodList['ss-libev']: # 按序匹配客户端
config, ssFile = __ssLibev(proxyInfo, socksPort)
config, ssFile = __ssLibev(proxyInfo, socksPort, isUdp)
elif proxyInfo['method'] in ssMethodList['ss-libev-legacy']:
config, ssFile = __ssLibev(proxyInfo, socksPort, isLegacy = True)
config, ssFile = __ssLibev(proxyInfo, socksPort, isUdp, isLegacy = True)
elif proxyInfo['method'] in ssMethodList['ss-python']:
config, ssFile = __ssPython(proxyInfo, socksPort)
config, ssFile = __ssPython(proxyInfo, socksPort, isUdp)
elif proxyInfo['method'] in ssMethodList['ss-python-legacy']:
config, ssFile = __ssPython(proxyInfo, socksPort, isLegacy = True)
config, ssFile = __ssPython(proxyInfo, socksPort, isUdp, isLegacy = True)
elif proxyInfo['method'] in ssMethodList['ss-rust']:
config, ssFile = __ssRust(proxyInfo, socksPort)
config, ssFile = __ssRust(proxyInfo, socksPort, isUdp)
else:
return None, None, None # 无匹配加密方式
return [ssFile, '-c', configFile], json.dumps(config), {}

122
ProxyBuilder/ShadowsocksR.py

@ -54,73 +54,73 @@
import json
ssrMethodList = [ # ShadowsocksR加密方式
"aes-128-cfb",
"aes-192-cfb",
"aes-256-cfb",
"aes-128-cfb1",
"aes-192-cfb1",
"aes-256-cfb1",
"aes-128-cfb8",
"aes-192-cfb8",
"aes-256-cfb8",
"aes-128-ctr",
"aes-192-ctr",
"aes-256-ctr",
"aes-128-gcm",
"aes-192-gcm",
"aes-256-gcm",
"aes-128-ofb",
"aes-192-ofb",
"aes-256-ofb",
"camellia-128-cfb",
"camellia-192-cfb",
"camellia-256-cfb",
"none",
"table",
"rc4",
"rc4-md5",
"rc4-md5-6",
"bf-cfb",
"cast5-cfb",
"des-cfb",
"idea-cfb",
"seed-cfb",
"rc2-cfb",
"salsa20",
"xsalsa20",
"chacha20",
"xchacha20",
"chacha20-ietf",
'aes-128-cfb',
'aes-192-cfb',
'aes-256-cfb',
'aes-128-cfb1',
'aes-192-cfb1',
'aes-256-cfb1',
'aes-128-cfb8',
'aes-192-cfb8',
'aes-256-cfb8',
'aes-128-ctr',
'aes-192-ctr',
'aes-256-ctr',
'aes-128-gcm',
'aes-192-gcm',
'aes-256-gcm',
'aes-128-ofb',
'aes-192-ofb',
'aes-256-ofb',
'camellia-128-cfb',
'camellia-192-cfb',
'camellia-256-cfb',
'none',
'table',
'rc4',
'rc4-md5',
'rc4-md5-6',
'bf-cfb',
'cast5-cfb',
'des-cfb',
'idea-cfb',
'seed-cfb',
'rc2-cfb',
'salsa20',
'xsalsa20',
'chacha20',
'xchacha20',
'chacha20-ietf',
]
ssrProtocolList = [ # ShadowsocksR协议列表
"origin",
"verify_sha1",
"verify_simple",
"verify_deflate",
"auth_simple",
"auth_sha1",
"auth_sha1_v2",
"auth_sha1_v4",
"auth_aes128",
"auth_aes128_md5",
"auth_aes128_sha1",
"auth_chain_a",
"auth_chain_b",
"auth_chain_c",
"auth_chain_d",
"auth_chain_e",
"auth_chain_f",
'origin',
'verify_sha1',
'verify_simple',
'verify_deflate',
'auth_simple',
'auth_sha1',
'auth_sha1_v2',
'auth_sha1_v4',
'auth_aes128',
'auth_aes128_md5',
'auth_aes128_sha1',
'auth_chain_a',
'auth_chain_b',
'auth_chain_c',
'auth_chain_d',
'auth_chain_e',
'auth_chain_f',
]
ssrObfsList = [ # ShadowsocksR混淆方式
"plain",
"http_post",
"http_simple",
"tls_simple",
"tls1.2_ticket_auth",
"tls1.2_ticket_fastauth",
"random_head",
'plain',
'http_post',
'http_simple',
'tls_simple',
'tls1.2_ticket_auth',
'tls1.2_ticket_fastauth',
'random_head',
]
def __ssrFormatCheck(proxyInfo: dict) -> bool: # ShadowsocksR参数检查

9
ProxyBuilder/builder.py

@ -96,12 +96,9 @@ def build(proxyInfo: dict, configDir: str,
socksPort = __getAvailablePort(portRangeStart, portRangeEnd) # 获取Socks5测试端口
if 'type' not in proxyInfo: # 未指定节点类型
return False, 'Proxy type not specified'
proxyType = proxyInfo['type'] # 节点类型
proxyInfo.pop('type')
if proxyType == 'ss': # Shadowsocks节点
if proxyInfo['type'] == 'ss': # Shadowsocks节点
clientObj = Shadowsocks
elif proxyType == 'ssr': # ShadowsocksR节点
elif proxyInfo['type'] == 'ssr': # ShadowsocksR节点
clientObj = ShadowsocksR
else: # 未知类型
return False, 'Unknown proxy type'
@ -109,7 +106,7 @@ def build(proxyInfo: dict, configDir: str,
configFile = configDir + '/' + taskFlag + '.json' # 配置文件路径
startCommand, fileContent, envVar = clientObj.load(proxyInfo, socksPort, configFile) # 载入配置
if startCommand is None: # 格式出错
return False, 'Format error with ' + str(proxyType)
return False, 'Format error with ' + str(proxyInfo['type'])
try:
with open(configFile, 'w') as fileObject: # 保存配置文件
fileObject.write(fileContent)

Loading…
Cancel
Save