Spaces:
Running
Running
rogerxavier
commited on
Commit
•
3f92a54
1
Parent(s):
9834a2c
Upload 7 files
Browse files- server/__pycache__/decoder.cpython-38.pyc +0 -0
- server/__pycache__/resource.cpython-38.pyc +0 -0
- server/__pycache__/utils.cpython-38.pyc +0 -0
- server/decoder.py +105 -0
- server/resource.py +18 -0
- server/utils.py +25 -0
- server/uu.json +6 -0
server/__pycache__/decoder.cpython-38.pyc
ADDED
Binary file (3.44 kB). View file
|
|
server/__pycache__/resource.cpython-38.pyc
ADDED
Binary file (887 Bytes). View file
|
|
server/__pycache__/utils.cpython-38.pyc
ADDED
Binary file (376 Bytes). View file
|
|
server/decoder.py
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
import re
|
4 |
+
import json
|
5 |
+
from base64 import b64decode
|
6 |
+
from typing import Dict, Iterator, List, Union
|
7 |
+
from .resource import Resource
|
8 |
+
from dataclasses import dataclass
|
9 |
+
from urllib import parse
|
10 |
+
|
11 |
+
|
12 |
+
class BaseDecoder:
|
13 |
+
def __init__(self, encode_str: str, nameinfo: str = ""):
|
14 |
+
self.encode_str = encode_str
|
15 |
+
self.decode_str: str
|
16 |
+
self.nameinfo = nameinfo
|
17 |
+
|
18 |
+
@staticmethod
|
19 |
+
def _bytesto_str(iobytes: bytes) -> str:
|
20 |
+
return iobytes.decode('utf-8')
|
21 |
+
|
22 |
+
|
23 |
+
def decode(self) -> None:
|
24 |
+
self.decode_str = self._bytesto_str(b64decode(self.encode_str))
|
25 |
+
|
26 |
+
|
27 |
+
@dataclass
|
28 |
+
class EncodedCfg:
|
29 |
+
encoded_config_str: str
|
30 |
+
nameinfo: str = ""
|
31 |
+
|
32 |
+
|
33 |
+
class ListDecoder(BaseDecoder):
|
34 |
+
def iter_encode_config(self) -> Iterator[EncodedCfg]:
|
35 |
+
for config_str in self.decode_str.splitlines():
|
36 |
+
_config_str = re.sub(r"(vmess|ss)://", "", config_str)
|
37 |
+
nameinfo = ""
|
38 |
+
if "#" in _config_str:
|
39 |
+
_config_str, nameinfo = _config_str.split("#", 1)
|
40 |
+
nameinfo = parse.unquote(nameinfo)
|
41 |
+
|
42 |
+
_encoded_config_str = _config_str + (
|
43 |
+
(4 - len(_config_str) % 4) * "="
|
44 |
+
)
|
45 |
+
|
46 |
+
if "trojan" in config_str and "0.0.0.0" not in config_str and '美国' not in nameinfo and '443' not in config_str:
|
47 |
+
if "allowInsecure" in config_str:
|
48 |
+
# yield _encoded_config_str.replace('allowInsecure=0', 'allowInsecure=1').replace('type=tcp==', '')+"#"+"随机节点"
|
49 |
+
yield _encoded_config_str.replace('allowInsecure=0', 'allowInsecure=1').replace('type=tcp==', '')+"#"+nameinfo
|
50 |
+
else:
|
51 |
+
# yield _encoded_config_str.replace('type=tcp==', '')+"&allowInsecure=1"+"#"+"随机节点"
|
52 |
+
yield _encoded_config_str.replace('type=tcp==', '')+"&allowInsecure=1"+"#"+nameinfo
|
53 |
+
|
54 |
+
if ("vmess" in config_str) :
|
55 |
+
vmess_decoded_data = b64decode(_config_str).decode('utf-8')
|
56 |
+
vmess_info_json = json.loads(vmess_decoded_data)
|
57 |
+
vmess_info_str = json.dumps(vmess_info_json,ensure_ascii=False)#不转译中文
|
58 |
+
if ('倍率提示'not in vmess_info_str)and('导航' not in vmess_info_str) and('443' not in vmess_info_str):
|
59 |
+
yield config_str.replace('allowInsecure=0', 'allowInsecure=1')
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
+
class ConfigDecoder(BaseDecoder):
|
64 |
+
def get_json(self) -> Dict:
|
65 |
+
if re.match(r"^{.*}$", self.decode_str):
|
66 |
+
return json.loads(self.decode_str)
|
67 |
+
return self._parse_ss()
|
68 |
+
|
69 |
+
def _parse_ss(self):
|
70 |
+
crypt, pw_at_addr, port = self.decode_str.split(":")
|
71 |
+
pw, addr = pw_at_addr.split("@")
|
72 |
+
return {
|
73 |
+
"ps": self.nameinfo,
|
74 |
+
"add": addr,
|
75 |
+
"port": int(port),
|
76 |
+
"method": crypt,
|
77 |
+
"password": pw,
|
78 |
+
"ss": True,
|
79 |
+
"level": 0,
|
80 |
+
}
|
81 |
+
|
82 |
+
|
83 |
+
def _get_resource_from_url(url: str) -> str:
|
84 |
+
resource = Resource(url)
|
85 |
+
return resource.get_encoded_data()
|
86 |
+
|
87 |
+
|
88 |
+
def _get_listencoded_cfg_from_encoded_str(encoded_str: str) -> List[EncodedCfg]:
|
89 |
+
decoder = ListDecoder(encoded_str)
|
90 |
+
decoder.decode()
|
91 |
+
return [item for item in decoder.iter_encode_config()]
|
92 |
+
|
93 |
+
|
94 |
+
|
95 |
+
|
96 |
+
|
97 |
+
def decode_url_to_configs(url: str)->list:
|
98 |
+
encoded_str = _get_resource_from_url(url)
|
99 |
+
##https://github.com/CareyWang/sub-web 成功用这个订阅解析解决了订阅被cf格挡问题,且可用于sspanel
|
100 |
+
lst_encoded_cfg = _get_listencoded_cfg_from_encoded_str(encoded_str)#lst_encoded_cfg解析为节点后的列表,包含所有节点链接
|
101 |
+
return lst_encoded_cfg
|
102 |
+
|
103 |
+
|
104 |
+
|
105 |
+
|
server/resource.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
import requests
|
4 |
+
from .utils import headers
|
5 |
+
|
6 |
+
|
7 |
+
class Resource:
|
8 |
+
def __init__(self, url: str):
|
9 |
+
self.url = url
|
10 |
+
self.cutted_str: str
|
11 |
+
self._get_resource()
|
12 |
+
|
13 |
+
def _get_resource(self) -> None:
|
14 |
+
request = requests.get(self.url,headers=headers)
|
15 |
+
self.cutted_str = request.text
|
16 |
+
|
17 |
+
def get_encoded_data(self) -> str:
|
18 |
+
return self.cutted_str + ((4 - len(self.cutted_str) % 4) * "=")
|
server/utils.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import os
|
3 |
+
import hashlib
|
4 |
+
import secrets
|
5 |
+
# 获取当前文件所在的目录
|
6 |
+
current_dir = os.path.dirname(os.path.realpath(__file__))
|
7 |
+
# 读取配置文件
|
8 |
+
with open(os.path.join(current_dir, 'uu.json'), 'r') as f:
|
9 |
+
config = json.load(f)
|
10 |
+
|
11 |
+
headers = {
|
12 |
+
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
13 |
+
'accept-language': 'zh-CN,zh;q=0.9',
|
14 |
+
'cache-control': 'max-age=0',
|
15 |
+
'priority': 'u=0, i',
|
16 |
+
'sec-ch-ua': '"Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"',
|
17 |
+
'sec-ch-ua-mobile': '?0',
|
18 |
+
'sec-ch-ua-platform': '"macOS"',
|
19 |
+
'sec-fetch-dest': 'document',
|
20 |
+
'sec-fetch-mode': 'navigate',
|
21 |
+
'sec-fetch-site': 'none',
|
22 |
+
'sec-fetch-user': '?1',
|
23 |
+
'upgrade-insecure-requests': '1',
|
24 |
+
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36'
|
25 |
+
}
|
server/uu.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"baseUrl":"https://rogerxavier-v2b-proxy.hf.space",
|
3 |
+
"purchaseLinkBase":"https://afdian.com/order/create?product_type=1",
|
4 |
+
"planID": "ef3c43c6daa411ee965e5254001e7c00",
|
5 |
+
"skuID": "ef440afcdaa411ee9e165254001e7c00"
|
6 |
+
}
|