fix: URL-encode share link params for v2rayNG SNI parsing
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+12
-2
@@ -21,6 +21,13 @@ def load_env() -> dict[str, str]:
|
||||
return env
|
||||
|
||||
|
||||
def _qs(value: str) -> str:
|
||||
"""URL-encode query / userinfo values for share links."""
|
||||
# quote() leaves unreserved chars like '.' unencoded; some clients (v2rayNG)
|
||||
# misparsed sni=www.microsoft.com — force dots encoded for compatibility.
|
||||
return quote(value, safe="").replace(".", "%2E")
|
||||
|
||||
|
||||
def build_links(node: dict, env: dict | None = None) -> dict[str, str]:
|
||||
env = env or load_env()
|
||||
vps_ip = env["VPS_IP"]
|
||||
@@ -34,8 +41,11 @@ def build_links(node: dict, env: dict | None = None) -> dict[str, str]:
|
||||
vless = (
|
||||
f"vless://{node['uuid']}@{vps_ip}:443"
|
||||
f"?encryption=none&flow=xtls-rprx-vision&security=reality"
|
||||
f"&sni={reality_sni}&fp=chrome&pbk={public_key}&sid={short_id}"
|
||||
f"&sni={_qs(reality_sni)}&fp=chrome&pbk={_qs(public_key)}&sid={_qs(short_id)}"
|
||||
f"&spx=%2F&type=tcp#{name}"
|
||||
)
|
||||
hy2 = f"hy2://{node['hy2_password']}@{domain}:{port}?sni={domain}#{name}-Hy2"
|
||||
hy2 = (
|
||||
f"hy2://{_qs(node['hy2_password'])}@{domain}:{port}"
|
||||
f"?sni={_qs(domain)}#{name}-Hy2"
|
||||
)
|
||||
return {"vless": vless, "hy2": hy2}
|
||||
|
||||
@@ -17,6 +17,16 @@ done
|
||||
|
||||
mkdir -p "$OUT_DIR"
|
||||
|
||||
urlencode() {
|
||||
python3 -c "import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1], safe='').replace('.', '%2E'))" "$1"
|
||||
}
|
||||
|
||||
REALITY_SNI_ENC="$(urlencode "$REALITY_SERVER_NAME")"
|
||||
REALITY_PBK_ENC="$(urlencode "$REALITY_PUBLIC_KEY")"
|
||||
REALITY_SID_ENC="$(urlencode "$REALITY_SHORT_ID")"
|
||||
HY2_PASSWORD_ENC="$(urlencode "$HY2_PASSWORD")"
|
||||
DOMAIN_SNI_ENC="$(urlencode "$DOMAIN")"
|
||||
|
||||
sed -e "s|\${VPS_IP}|${VPS_IP}|g" \
|
||||
-e "s|\${DOMAIN}|${DOMAIN}|g" \
|
||||
-e "s|\${UUID}|${UUID}|g" \
|
||||
@@ -28,10 +38,10 @@ sed -e "s|\${VPS_IP}|${VPS_IP}|g" \
|
||||
|
||||
cat > "$OUT_DIR/share-links.txt" <<EOF
|
||||
========== VLESS + Reality (主力) ==========
|
||||
vless://${UUID}@${VPS_IP}:443?encryption=none&flow=xtls-rprx-vision&security=reality&sni=${REALITY_SERVER_NAME}&fp=chrome&pbk=${REALITY_PUBLIC_KEY}&sid=${REALITY_SHORT_ID}&spx=%2F&type=tcp#Reality-Main
|
||||
vless://${UUID}@${VPS_IP}:443?encryption=none&flow=xtls-rprx-vision&security=reality&sni=${REALITY_SNI_ENC}&fp=chrome&pbk=${REALITY_PBK_ENC}&sid=${REALITY_SID_ENC}&spx=%2F&type=tcp#Reality-Main
|
||||
|
||||
========== Hysteria2 (备用) ==========
|
||||
hy2://${HY2_PASSWORD}@${DOMAIN}:8443?sni=${DOMAIN}#Hysteria2-Backup
|
||||
hy2://${HY2_PASSWORD_ENC}@${DOMAIN}:8443?sni=${DOMAIN_SNI_ENC}#Hysteria2-Backup
|
||||
EOF
|
||||
|
||||
echo "已生成:"
|
||||
|
||||
Reference in New Issue
Block a user