Browse Source

update: change pluginArg to pluginParam

master
Dnomd343 2 years ago
parent
commit
a1ab369cce
  1. 8
      ProxyBuilder/Shadowsocks.py
  2. 3
      ProxyBuilder/builder.py
  3. 38
      demo.py
  4. 4
      test/Shadowsocks.py

8
ProxyBuilder/Shadowsocks.py

@ -149,10 +149,10 @@ def __baseJSON(proxyInfo, socksPort): # 生成JSON基本结构
} }
if proxyInfo['plugin'] != '': if proxyInfo['plugin'] != '':
jsonContent['plugin'] = proxyInfo['plugin'] jsonContent['plugin'] = proxyInfo['plugin']
jsonContent['plugin_opts'] = proxyInfo['pluginArg'] jsonContent['plugin_opts'] = proxyInfo['pluginParam']
return jsonContent return jsonContent
def __pluginUdpCheck(plugin, pluginArg): # 插件是否使用UDP通讯 def __pluginUdpCheck(plugin, pluginParam): # 插件是否使用UDP通讯
if plugin == '': # 无插件 if plugin == '': # 无插件
return False return False
noUdpPlugin = [ # 不使用UDP通讯的插件 noUdpPlugin = [ # 不使用UDP通讯的插件
@ -173,7 +173,7 @@ def __pluginUdpCheck(plugin, pluginArg): # 插件是否使用UDP通讯
if plugin in onlyUdpPlugin: if plugin in onlyUdpPlugin:
return True return True
if plugin == 'v2ray-plugin' or plugin == 'xray-plugin' or plugin == 'gost-plugin': if plugin == 'v2ray-plugin' or plugin == 'xray-plugin' or plugin == 'gost-plugin':
if not 'mode=quic' in pluginArg.split(';'): if not 'mode=quic' in pluginParam.split(';'):
return False return False
return True # 默认假定占用UDP return True # 默认假定占用UDP
@ -216,7 +216,7 @@ def __ssRust(proxyInfo, socksPort): # ss-rust配置文件生成
return jsonContent, 'ss-rust-local' return jsonContent, 'ss-rust-local'
def load(proxyInfo, socksPort, configFile): # Shadowsocks配置载入 def load(proxyInfo, socksPort, configFile): # Shadowsocks配置载入
proxyInfo['udp'] = not __pluginUdpCheck(proxyInfo['plugin'], proxyInfo['pluginArg']) proxyInfo['udp'] = not __pluginUdpCheck(proxyInfo['plugin'], proxyInfo['pluginParam'])
if proxyInfo['method'] in ssMethodList['ss-libev']: if proxyInfo['method'] in ssMethodList['ss-libev']:
jsonContent, ssFile = __ssLibev(proxyInfo, socksPort) jsonContent, ssFile = __ssLibev(proxyInfo, socksPort)
elif proxyInfo['method'] in ssMethodList['ss-libev-legacy']: elif proxyInfo['method'] in ssMethodList['ss-libev-legacy']:

3
ProxyBuilder/builder.py

@ -77,8 +77,10 @@ def build(proxyInfo, configDir): # 构建代理节点连接
elif proxyType == 'ssr': # ShadowsocksR节点 elif proxyType == 'ssr': # ShadowsocksR节点
startCommand, fileContent = ShadowsocksR.load(proxyInfo, socksPort, configFile) startCommand, fileContent = ShadowsocksR.load(proxyInfo, socksPort, configFile)
else: # 未知类型 else: # 未知类型
print("Unknown proxy type")
return None return None
if startCommand == None: # 格式出错 if startCommand == None: # 格式出错
print("Format error with " + proxyType)
return None return None
try: try:
with open(configFile, 'w') as fileObject: with open(configFile, 'w') as fileObject:
@ -97,6 +99,7 @@ def build(proxyInfo, configDir): # 构建代理节点连接
stderr = subprocess.DEVNULL, stderr = subprocess.DEVNULL,
preexec_fn = exitWithMe) # 子进程跟随退出 preexec_fn = exitWithMe) # 子进程跟随退出
except: except:
print("WARNING: Subprocess may become a Orphan Process")
process = subprocess.Popen(startCommand, process = subprocess.Popen(startCommand,
stdout = subprocess.DEVNULL, stdout = subprocess.DEVNULL,
stderr = subprocess.DEVNULL) # prctl失败 回退正常启动 stderr = subprocess.DEVNULL) # prctl失败 回退正常启动

38
demo.py

@ -8,28 +8,28 @@ import requests
import ProxyBuilder as Builder import ProxyBuilder as Builder
import ProxyChecker as Checker import ProxyChecker as Checker
# testInfo = {
# 'type': 'ss',
# 'server': '127.0.0.1',
# 'port': 12345,
# 'password': 'dnomd343',
# 'method': 'aes-256-ctr',
# 'plugin': '',
# 'pluginArg': '',
# }
testInfo = { testInfo = {
'type': 'ssr', 'type': 'ss',
"server": "127.0.0.1", 'server': '127.0.0.1',
"port": 23456, 'port': 12345,
"password": "dnomd343", 'password': 'dnomd343',
"method": "table", 'method': 'aes-256-ctr',
"protocol": "auth_aes128_md5", 'plugin': '',
"protocolParam": "", 'pluginParam': '',
"obfs": "tls1.2_ticket_auth",
"obfsParam": ""
} }
# testInfo = {
# 'type': 'ssr',
# "server": "127.0.0.1",
# "port": 23456,
# "password": "dnomd343",
# "method": "table",
# "protocol": "auth_aes128_md5",
# "protocolParam": "",
# "obfs": "tls1.2_ticket_auth",
# "obfsParam": ""
# }
print("start") print("start")
print(testInfo) print(testInfo)
task = Builder.build(testInfo, '/tmp/ProxyC') task = Builder.build(testInfo, '/tmp/ProxyC')

4
test/Shadowsocks.py

@ -63,7 +63,7 @@ def test(port, password):
'password': password, 'password': password,
'method': method, 'method': method,
'plugin': '', 'plugin': '',
'pluginArg': '', 'pluginParam': '',
} }
testInfo = 'Shadowsocks method ' + method testInfo = 'Shadowsocks method ' + method
if method == 'plain' or method == 'none': if method == 'plain' or method == 'none':
@ -115,7 +115,7 @@ def test(port, password):
'password': password, 'password': password,
'method': 'aes-256-ctr', 'method': 'aes-256-ctr',
'plugin': 'obfs-local', 'plugin': 'obfs-local',
'pluginArg': 'obfs=http;obfs-host=www.bing.com', 'pluginParam': 'obfs=http;obfs-host=www.bing.com',
}, },
'serverCommand': [ 'serverCommand': [
'ss-bootstrap-server', 'ss-bootstrap-server',

Loading…
Cancel
Save