|
@ -73,68 +73,85 @@ ssrObfsList = [ # ShadowsocksR混淆方式 |
|
|
'random_head', |
|
|
'random_head', |
|
|
] |
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
def __ssrProtocol(protocol) -> str: |
|
|
|
|
|
protocol = baseFunc.toStrTidy(protocol).replace('-', '_') |
|
|
|
|
|
if protocol == '': |
|
|
|
|
|
return 'origin' |
|
|
|
|
|
return protocol |
|
|
|
|
|
|
|
|
|
|
|
def __ssrObfs(obfs) -> str: |
|
|
|
|
|
obfs = baseFunc.toStrTidy(obfs).replace('-', '_') |
|
|
|
|
|
if obfs == '': |
|
|
|
|
|
return 'plain' |
|
|
|
|
|
return obfs |
|
|
|
|
|
|
|
|
ssrFilterRules = { |
|
|
ssrFilterRules = { |
|
|
'rootObject': { |
|
|
'rootObject': { |
|
|
'remark': { |
|
|
'remark': { |
|
|
'optional': False, |
|
|
'optional': False, |
|
|
'default': '', |
|
|
'default': '', |
|
|
'type': str |
|
|
'type': str, |
|
|
|
|
|
'format': baseFunc.toStr |
|
|
}, |
|
|
}, |
|
|
'group': { |
|
|
'group': { |
|
|
'optional': False, |
|
|
'optional': False, |
|
|
'default': '', |
|
|
'default': '', |
|
|
'type': str |
|
|
'type': str, |
|
|
|
|
|
'format': baseFunc.toStr |
|
|
}, |
|
|
}, |
|
|
'server': { |
|
|
'server': { |
|
|
'optional': True, |
|
|
'optional': True, |
|
|
'type': str, |
|
|
'type': str, |
|
|
'format': lambda s: s.lower().strip(), |
|
|
'format': baseFunc.toStrTidy, |
|
|
'filter': baseFunc.isHost, |
|
|
'filter': baseFunc.isHost, |
|
|
'errMsg': 'Illegal server address' |
|
|
'errMsg': 'Illegal server address' |
|
|
}, |
|
|
}, |
|
|
'port': { |
|
|
'port': { |
|
|
'optional': True, |
|
|
'optional': True, |
|
|
'type': int, |
|
|
'type': int, |
|
|
'format': lambda i: int(i), |
|
|
'format': baseFunc.toInt, |
|
|
'filter': baseFunc.isPort, |
|
|
'filter': baseFunc.isPort, |
|
|
'errMsg': 'Illegal port number' |
|
|
'errMsg': 'Illegal port number' |
|
|
}, |
|
|
}, |
|
|
'method': { |
|
|
'method': { |
|
|
'optional': True, |
|
|
'optional': True, |
|
|
'type': str, |
|
|
'type': str, |
|
|
'format': lambda s: s.replace('_', '-').lower().strip(), |
|
|
'format': lambda s: baseFunc.toStrTidy(s).replace('_', '-'), |
|
|
'filter': lambda method: method in ssrMethodList, |
|
|
'filter': lambda method: method in ssrMethodList, |
|
|
'errMsg': 'Unknown ShadowsocksR method' |
|
|
'errMsg': 'Unknown ShadowsocksR method' |
|
|
}, |
|
|
}, |
|
|
'passwd': { |
|
|
'passwd': { |
|
|
'optional': True, |
|
|
'optional': True, |
|
|
'type': str |
|
|
'type': str, |
|
|
|
|
|
'format': baseFunc.toStr |
|
|
}, |
|
|
}, |
|
|
'protocol': { |
|
|
'protocol': { |
|
|
'optional': False, |
|
|
'optional': False, |
|
|
'default': 'origin', |
|
|
'default': 'origin', |
|
|
'type': str, |
|
|
'type': str, |
|
|
'format': lambda s: s.replace('-', '_').lower().strip(), |
|
|
'format': __ssrProtocol, |
|
|
'filter': lambda method: method in ssrProtocolList, |
|
|
'filter': lambda protocol: protocol in ssrProtocolList, |
|
|
'errMsg': 'Unknown ShadowsocksR protocol' |
|
|
'errMsg': 'Unknown ShadowsocksR protocol' |
|
|
}, |
|
|
}, |
|
|
'protocolParam': { |
|
|
'protocolParam': { |
|
|
'optional': False, |
|
|
'optional': False, |
|
|
'default': '', |
|
|
'default': '', |
|
|
'type': str |
|
|
'type': str, |
|
|
|
|
|
'format': baseFunc.toStr |
|
|
}, |
|
|
}, |
|
|
'obfs': { |
|
|
'obfs': { |
|
|
'optional': False, |
|
|
'optional': False, |
|
|
'default': 'plain', |
|
|
'default': 'plain', |
|
|
'type': str, |
|
|
'type': str, |
|
|
'format': lambda s: s.replace('-', '_').lower().strip(), |
|
|
'format': __ssrObfs, |
|
|
'filter': lambda method: method in ssrObfsList, |
|
|
'filter': lambda obfs: obfs in ssrObfsList, |
|
|
'errMsg': 'Unknown ShadowsocksR obfs' |
|
|
'errMsg': 'Unknown ShadowsocksR obfs' |
|
|
}, |
|
|
}, |
|
|
'obfsParam': { |
|
|
'obfsParam': { |
|
|
'optional': False, |
|
|
'optional': False, |
|
|
'default': '', |
|
|
'default': '', |
|
|
'type': str |
|
|
'type': str, |
|
|
|
|
|
'format': baseFunc.toStr |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -153,11 +170,18 @@ def ssrFilter(rawInfo: dict, isExtra: bool) -> tuple[bool, str or dict]: |
|
|
} |
|
|
} |
|
|
""" |
|
|
""" |
|
|
try: |
|
|
try: |
|
|
if not isExtra: |
|
|
if not isExtra: # 去除非必要参数 |
|
|
ssrFilterRules['rootObject'].pop('remark') |
|
|
ssrFilterRules['rootObject'].pop('remark') |
|
|
ssrFilterRules['rootObject'].pop('group') |
|
|
ssrFilterRules['rootObject'].pop('group') |
|
|
return baseFunc.rulesFilter(rawInfo, ssrFilterRules, { |
|
|
status, result = baseFunc.ruleFilter(rawInfo, ssrFilterRules, { |
|
|
'type': 'ssr' |
|
|
'type': 'ssr' |
|
|
}) |
|
|
}) |
|
|
|
|
|
if not status: # 节点格式错误 |
|
|
|
|
|
return False, result |
|
|
|
|
|
if result['protocol'] == 'origin': # origin无参数 |
|
|
|
|
|
result['protocolParam'] = '' |
|
|
|
|
|
if result['obfs'] == 'plain': # plain无参数 |
|
|
|
|
|
result['obfsParam'] = '' |
|
|
|
|
|
return True, result |
|
|
except: |
|
|
except: |
|
|
return False, 'Unknown error' |
|
|
return False, 'Unknown error' |
|
|