You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

60 lines
2.0 KiB

#!/usr/bin/python
# -*- coding:utf-8 -*-
import copy
def __originConfig(proxyInfo: dict) -> list:
return [
'client',
'--server', proxyInfo['server'] + ':' + str(proxyInfo['port']),
'--password', proxyInfo['passwd']
]
def __wsConfig(proxyInfo: dict) -> list:
return [
'wsclient',
'--wsserver', 'ws://' + proxyInfo['ws']['host'] + ':' + str(proxyInfo['port']) + proxyInfo['ws']['path'],
'--address', proxyInfo['server'] + ':' + str(proxyInfo['port']),
'--password', proxyInfo['passwd']
]
def __wssConfig(proxyInfo: dict) -> list:
wssConfig = [
'wssclient',
'--wssserver', 'wss://' + proxyInfo['ws']['host'] + ':' + str(proxyInfo['port']) + proxyInfo['ws']['path'],
'--address', proxyInfo['server'] + ':' + str(proxyInfo['port']),
'--password', proxyInfo['passwd']
]
if not proxyInfo['ws']['secure']['verify']:
wssConfig += ['--insecure']
return wssConfig
def load(proxyInfo: dict, socksPort: int, configFile: str) -> tuple[list, str or None, dict]:
"""
Brook配置载入
proxyInfo: 节点信息
socksPort: 本地通讯端口
configFile: 配置文件路径
return startCommand, fileContent, envVar
"""
proxyInfo = copy.deepcopy(proxyInfo)
if proxyInfo['server'].find(':') >= 0:
proxyInfo['server'] = '[' + proxyInfo['server'] + ']' # IPv6
if proxyInfo['ws'] is not None and proxyInfo['ws']['host'].find(':') >= 0:
proxyInfo['ws']['host'] = '[' + proxyInfo['ws']['host'] + ']' # IPv6
command = [
'brook',
'--debug', '--listen', 'skip success', # debug on
]
if proxyInfo['ws'] is None:
command += __originConfig(proxyInfo) # original mode
elif proxyInfo['ws']['secure'] is None:
command += __wsConfig(proxyInfo) # ws mode
else:
command += __wssConfig(proxyInfo) # wss mode
command += [
'--socks5', '127.0.0.1:' + str(socksPort)
]
return command, None, {}