Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Toperlock committed Mar 25, 2024
1 parent 91cd0c9 commit 1922474
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 61 deletions.
92 changes: 47 additions & 45 deletions parsers/clash2base64.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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'),
Expand All @@ -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')
Expand Down
6 changes: 3 additions & 3 deletions parsers/ss.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions parsers/ssr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,17 +28,17 @@ 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:
key_value = p.split('=')
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
2 changes: 1 addition & 1 deletion parsers/trojan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(',')
Expand Down
11 changes: 3 additions & 8 deletions tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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|-)?(?<![AR])US\d*|USA|America|United States'),
'🇰🇷': re.compile(r'韩国|韓國|首尔|韩|韓|春川|KOR|KR|Kr|(?<!North\s)Korea'),
'🇰🇷': re.compile(r'韩国|韓國|首尔|首爾|韩|韓|春川|KOR|KR|Kr|(?<!North\s)Korea'),
'🇰🇵': re.compile(r'朝鲜|KP|North Korea'),
'🇷🇺': re.compile(r'俄罗斯|俄羅斯|毛子|俄国|RU|RUS|Russia'),
'🇮🇳': re.compile(r'印度|孟买|\bIN|IND|India|INDIA|Mumbai'),
Expand All @@ -32,7 +32,7 @@ def saveFile(path,content):
'🇻🇦': re.compile(r'梵蒂冈|梵蒂岡|(\s|-)?VA\d*|Vatican City'),
'🇧🇪': re.compile(r'比利时|比利時|(\s|-)?BE\d*|Belgium'),
'🇦🇺': re.compile(r'澳大利亚|澳洲|墨尔本|悉尼|(\s|-)?AU\d*|Australia|Sydney'),
'🇨🇦': re.compile(r'加拿大|蒙特利尔|温哥华|多伦多|滑铁卢|楓葉|枫叶|CA|CAN|Waterloo|Canada|CANADA'),
'🇨🇦': re.compile(r'加拿大|蒙特利尔|温哥华|多伦多|多倫多|滑铁卢|楓葉|枫叶|CA|CAN|Waterloo|Canada|CANADA'),
'🇲🇾': re.compile(r'马来西亚|马来|馬來|MY|Malaysia|MALAYSIA'),
'🇲🇻': re.compile(r'马尔代夫|馬爾代夫|(\s|-)?MV\d*|Maldives'),
'🇹🇷': re.compile(r'土耳其|伊斯坦布尔|(\s|-)?TR\d|TR_|TUR|Turkey'),
Expand Down Expand Up @@ -166,11 +166,6 @@ def rename(input_str):
return country_code + ' ' + input_str
return input_str

def urlDecode(str):
str = str.strip()
str += (len(str)%4)*'='
return base64.urlsafe_b64decode(str)

def b64Decode(str):
str = str.strip()
str += (len(str)%4)*'='
Expand Down

0 comments on commit 1922474

Please sign in to comment.