From 1922474d108cf68f522c069a02bbe9e8c5c949c3 Mon Sep 17 00:00:00 2001 From: "@Toperlock" <861705708@qq.com> Date: Mon, 25 Mar 2024 19:12:32 +0800 Subject: [PATCH] update --- parsers/clash2base64.py | 92 +++++++++++++++++++++-------------------- parsers/ss.py | 6 +-- parsers/ssr.py | 8 ++-- parsers/trojan.py | 2 +- tool.py | 11 ++--- 5 files changed, 58 insertions(+), 61 deletions(-) diff --git a/parsers/clash2base64.py b/parsers/clash2base64.py index 6841f84e6..88b8320bb 100644 --- a/parsers/clash2base64.py +++ b/parsers/clash2base64.py @@ -4,49 +4,52 @@ def clash2v2ray(share_link): link = '' if share_link['type'] == 'vmess': - vmess_info = { - "v": "2", - "ps": share_link['name'].encode('utf-8', 'surrogatepass').decode('utf-8'), - "add": share_link['server'], - "port": share_link['port'], - "id": share_link['uuid'], - "aid": share_link['alterId'], - "net": share_link.get('network', 'tcp'), - "scy": share_link.get('cipher', 'auto'), - "type": "none", - "host": share_link.get('ws-opts', {}).get('headers', {}).get('Host', '') or share_link.get('ws-headers', {}).get('Host', ''), - "path": share_link.get('ws-path', '') or share_link.get('ws-opts', {}).get('path', ''), - "tls": '' - } - if share_link.get('skip-cert-verify') == False: - vmess_info['verify_cert'] = False - if share_link.get('tls') and share_link['tls'] != False: - vmess_info['tls'] = 'tls' - vmess_info["sni"] = share_link.get('servername', '') - if vmess_info['net'] == 'grpc': - vmess_info["type"] = share_link.get('grpc-opts', {}).get('grpc-mode') - if share_link.get('grpc-opts', {}).get('grpc-service-name') != '/': - vmess_info["path"] = share_link.get('grpc-opts', {}).get('grpc-service-name') - else: - vmess_info["path"] = '' - elif vmess_info['net'] == 'h2': - vmess_info['host'] = share_link.get('h2-opts', {}).get('host', []) - vmess_info["path"] = share_link.get('h2-opts', {}).get('path', '') - elif vmess_info['net'] == 'http': - vmess_info["headers"] = share_link.get('http-opts', {}).get('headers', {}) - vmess_info["host"] = share_link.get('http-opts', {}).get('headers', {}).get('Host', []) - vmess_info["path"] = share_link.get('http-opts', {}).get('path', []) - if share_link.get('smux',{}).get('enabled', '') == True: - vmess_info["protocol"] = share_link['smux']['protocol'] - vmess_info["max_connections"] = share_link['smux'].get('max-connections','') - vmess_info["min_streams"] = share_link['smux'].get('min-streams','') - vmess_info["max_streams"] = share_link['smux'].get('max-streams','') - vmess_info["padding"] = share_link['smux'].get('padding','') + try: + vmess_info = { + "v": "2", + "ps": share_link['name'].encode('utf-8', 'surrogatepass').decode('utf-8'), + "add": share_link['server'], + "port": share_link['port'], + "id": share_link['uuid'], + "aid": share_link['alterId'], + "net": share_link.get('network', 'tcp'), + "scy": share_link.get('cipher', 'auto'), + "type": "none", + "host": share_link.get('ws-opts', {}).get('headers', {}).get('Host', '') or share_link.get('ws-headers', {}).get('Host', ''), + "path": share_link.get('ws-path', '') or share_link.get('ws-opts', {}).get('path', ''), + "tls": '' + } + if share_link.get('skip-cert-verify') == False: + vmess_info['verify_cert'] = False + if share_link.get('tls') and share_link['tls'] != False: + vmess_info['tls'] = 'tls' + vmess_info["sni"] = share_link.get('servername', '') + if vmess_info['net'] == 'grpc': + vmess_info["type"] = share_link.get('grpc-opts', {}).get('grpc-mode') + if share_link.get('grpc-opts', {}).get('grpc-service-name') != '/': + vmess_info["path"] = share_link.get('grpc-opts', {}).get('grpc-service-name') + else: + vmess_info["path"] = '' + elif vmess_info['net'] == 'h2': + vmess_info['host'] = share_link.get('h2-opts', {}).get('host', []) + vmess_info["path"] = share_link.get('h2-opts', {}).get('path', '') + elif vmess_info['net'] == 'http': + vmess_info["headers"] = share_link.get('http-opts', {}).get('headers', {}) + vmess_info["host"] = share_link.get('http-opts', {}).get('headers', {}).get('Host', []) + vmess_info["path"] = share_link.get('http-opts', {}).get('path', []) + if share_link.get('smux',{}).get('enabled', '') == True: + vmess_info["protocol"] = share_link['smux']['protocol'] + vmess_info["max_connections"] = share_link['smux'].get('max-connections','') + vmess_info["min_streams"] = share_link['smux'].get('min-streams','') + vmess_info["max_streams"] = share_link['smux'].get('max-streams','') + vmess_info["padding"] = share_link['smux'].get('padding','') - vmess_json = json.dumps(vmess_info).encode('utf-8') - vmess_base64 = base64.b64encode(vmess_json).decode('utf-8') - link = f"vmess://{vmess_base64}" - return link + vmess_json = json.dumps(vmess_info).encode('utf-8') + vmess_base64 = base64.b64encode(vmess_json).decode('utf-8') + link = f"vmess://{vmess_base64}" + return link + except: + pass # TODO elif share_link['type'] == 'ss': ss_info = { @@ -133,9 +136,8 @@ def clash2v2ray(share_link): "password": share_link['password'], "server": share_link['server'], "port": share_link['port'], - "allowInsecure": share_link.get('allowInsecure', '1'), "sni": share_link.get('sni', ''), - "skip_cert_verify": '1' if share_link.get('skip-cert-verify') else "", + "skip_cert_verify": share_link.get('skip-cert-verify', False), "type": share_link.get('network', 'tcp'), "fp": share_link.get('client-fingerprint', ''), "alpn": quote(','.join(share_link.get('alpn', '')), 'utf-8'), @@ -150,7 +152,7 @@ def clash2v2ray(share_link): trojan_info["serviceName"] = server_parts[-2] else: trojan_info["serviceName"] = '' - link = "trojan://{password}@{server}:{port}?allowInsecure={allowInsecure}&sni={sni}&skip_cert_verify={skip_cert_verify}&type={type}&serviceName={serviceName}&fp={fp}&alpn={alpn}".format(**trojan_info) + link = "trojan://{password}@{server}:{port}?sni={sni}&skip_cert_verify={skip_cert_verify}&type={type}&serviceName={serviceName}&fp={fp}&alpn={alpn}".format(**trojan_info) elif trojan_info['type'] == 'ws': if share_link.get('ws-opts'): trojan_info["path"] = quote(share_link['ws-opts'].get('path', ''), 'utf-8') diff --git a/parsers/ss.py b/parsers/ss.py index b6975221d..a51371ae4 100644 --- a/parsers/ss.py +++ b/parsers/ss.py @@ -84,7 +84,7 @@ def parse(data): node['multiplex']['padding'] = True try: #fuck param = param.split('?')[0] - matcher = tool.urlDecode(param) #保留'/'测试能不能解码 + matcher = tool.b64Decode(param) #保留'/'测试能不能解码 except: param = param.split('/')[0].split('?')[0] #不能解码说明'/'不是base64内容 if param.find('@') > -1: @@ -96,7 +96,7 @@ def parse(data): else: return None try: - matcher = re.match(r'(.*?):(.*)', tool.urlDecode(param).decode('utf-8')) + matcher = re.match(r'(.*?):(.*)', tool.b64Decode(param).decode('utf-8')) if matcher: node['method'] = matcher.group(1) node['password'] = matcher.group(2) @@ -110,7 +110,7 @@ def parse(data): else: return None else: - matcher = re.match(r'(.*?):(.*)@(.*):(.*)', tool.urlDecode(param).decode('utf-8')) + matcher = re.match(r'(.*?):(.*)@(.*):(.*)', tool.b64Decode(param).decode('utf-8')) if matcher: node['method'] = matcher.group(1) node['password'] = matcher.group(2) diff --git a/parsers/ssr.py b/parsers/ssr.py index bd990b383..f7f46df6b 100644 --- a/parsers/ssr.py +++ b/parsers/ssr.py @@ -4,7 +4,7 @@ def parse(data): if not info or info.isspace(): return None try: - proxy_str = tool.urlDecode(info).decode('utf-8') + proxy_str = tool.b64Decode(info).decode('utf-8') except: proxy_str = info i = 0 @@ -28,10 +28,10 @@ def parse(data): } password_params = parts[5].split('/?') if i == 0: - node['password'] = tool.urlDecode(password_params[0]).decode('utf-8') + node['password'] = tool.b64Decode(password_params[0]).decode('utf-8') params = password_params[1].split('&') else: #fuck - node['password'] = tool.urlDecode(password_params[0].split('remarks')[0]).decode('utf-8') + node['password'] = tool.b64Decode(password_params[0].split('remarks')[0]).decode('utf-8') params = password_params[-1].split(password_params[0].split('remarks')[0])[-1].split('&') pdict = {'obfsparam':'obfs_param','protoparam':'protocol_param','remarks':'tag'} for p in params: @@ -39,6 +39,6 @@ def parse(data): keyname = key_value[0] if keyname in pdict.keys(): keyname = pdict[keyname] - node[keyname] = tool.urlDecode(key_value[1]).decode('utf-8') + node[keyname] = tool.b64Decode(key_value[1]).decode('utf-8') node['tag'] = node['tag'] if node.get('tag') else tool.genName()+'_shadowsocksr' return node diff --git a/parsers/trojan.py b/parsers/trojan.py index 2039823da..ffa2ee0ac 100644 --- a/parsers/trojan.py +++ b/parsers/trojan.py @@ -24,7 +24,7 @@ def parse(data): 'insecure': False } } - if netquery.get('allowInsecure') == '1': + if netquery.get('skip_cert_verify') == True: node['tls']['insecure'] = True if netquery.get('alpn'): node['tls']['alpn'] = netquery.get('alpn').strip('{}').split(',') diff --git a/tool.py b/tool.py index 87fde3d3f..0d4c48713 100644 --- a/tool.py +++ b/tool.py @@ -16,9 +16,9 @@ def saveFile(path,content): '🇹🇼': re.compile(r'台湾|台灣|臺灣|台北|台中|新北|彰化|台|CHT|HINET|TW|Taiwan|TAIWAN'), '🇲🇴': re.compile(r'澳门|澳門|(\s|-)?MO\d*|CTM|MAC|Macao|Macau'), '🇸🇬': re.compile(r'新加坡|狮城|獅城|沪新|京新|泉新|穗新|深新|杭新|广新|廣新|滬新|SG|Singapore|SINGAPORE'), - '🇯🇵': re.compile(r'日本|东京|大阪|埼玉|京日|苏日|沪日|广日|上日|穗日|川日|中日|泉日|杭日|深日|JP|Japan|JAPAN'), + '🇯🇵': re.compile(r'日本|东京|東京|大阪|埼玉|京日|苏日|沪日|广日|上日|穗日|川日|中日|泉日|杭日|深日|JP|Japan|JAPAN'), '🇺🇸': re.compile(r'美国|美國|京美|硅谷|凤凰城|洛杉矶|西雅图|圣何塞|芝加哥|哥伦布|纽约|广美|(\s|-)?(?