## 变更 - 将 `OneDrive.exe` 设为全局 `DIRECT`,优先于供应商 Microsoft 规则 - 为 Clash Verge 全局脚本补充国内可达的阿里 DNS / 腾讯 DNS DoH fallback - 同步更新路由器规则投影与跨平台生成说明 ## 验证 - `python -m unittest discover -s tests -v`:7 项通过 - mihomo DNS API 成功解析 OneDrive 目标 - 实际日志确认 `OneDrive.exe -> skydrive.wns.windows.com:443` 命中 `ProcessName(OneDrive.exe)` 并使用 `DIRECT` Reviewed-on: http://192.168.50.2:3000/ageorge156/vpn-rules/pulls/7
This commit was merged in pull request #7.
This commit is contained in:
@@ -4,14 +4,39 @@
|
||||
用法:
|
||||
python3 scripts/gen_clash_verge_script.py [--out 目标路径]
|
||||
|
||||
默认输出到 Clash Verge 数据目录 profiles/Script.js(全局直连规则的唯一正确机制,
|
||||
见 clash-verge-config 记忆)。生成后需在 Clash Verge 界面点「重启内核」生效。
|
||||
默认按 Windows/macOS 平台输出到 Clash Verge 数据目录 profiles/Script.js(全局直连
|
||||
规则的唯一正确机制)。生成后需在 Clash Verge 界面点「重启内核」生效。
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
DEFAULT_OUT = Path.home() / "Library/Application Support/io.github.clash-verge-rev.clash-verge-rev/profiles/Script.js"
|
||||
APP_ID = "io.github.clash-verge-rev.clash-verge-rev"
|
||||
|
||||
|
||||
def default_output_path(
|
||||
platform_name: str = sys.platform,
|
||||
*,
|
||||
home: Path | None = None,
|
||||
appdata: Path | None = None,
|
||||
) -> Path:
|
||||
"""返回当前平台的 Clash Verge 全局 Script.js 路径。"""
|
||||
home = home or Path.home()
|
||||
if platform_name == "win32":
|
||||
if appdata is None:
|
||||
roaming = os.environ.get("APPDATA")
|
||||
if not roaming:
|
||||
raise SystemExit("[error] Windows 环境缺少 APPDATA,无法定位 Clash Verge 数据目录")
|
||||
appdata = Path(roaming)
|
||||
return appdata / APP_ID / "profiles" / "Script.js"
|
||||
if platform_name == "darwin":
|
||||
return home / "Library/Application Support" / APP_ID / "profiles" / "Script.js"
|
||||
return home / ".local/share" / APP_ID / "profiles" / "Script.js"
|
||||
|
||||
|
||||
DEFAULT_OUT = default_output_path()
|
||||
|
||||
|
||||
def load_payload(path: Path) -> list[str]:
|
||||
@@ -22,7 +47,7 @@ def load_payload(path: Path) -> list[str]:
|
||||
if line.startswith("- "):
|
||||
payload.append(line[2:].strip())
|
||||
if not payload:
|
||||
raise SystemExit(f"❌ direct.yaml 里没有 payload 条目: {path}")
|
||||
raise SystemExit(f"[error] direct.yaml 里没有 payload 条目: {path}")
|
||||
return payload
|
||||
|
||||
|
||||
@@ -37,19 +62,37 @@ def render_script(payload: list[str]) -> str:
|
||||
rules = [f" {to_rule(e)!r}," for e in payload]
|
||||
lines = "\n".join(rules)
|
||||
return f"""// 由 vpn-rules/direct.yaml 生成 — 勿手改,改真源后重跑 gen_clash_verge_script.py。
|
||||
// 全局直连规则:FRP 控制面、B站、国内 LLM、内网段、国区 iCloud、UGREEN 一律 DIRECT。
|
||||
// 全局直连规则:OneDrive、FRP 控制面、B站、国内 LLM、内网段、国区 iCloud、UGREEN 一律 DIRECT。
|
||||
const prependRules = [
|
||||
{lines}
|
||||
];
|
||||
|
||||
// 国内可达的 DoH 同时作为 fallback,确保 OneDrive 等境外域名在 DIRECT 出站前可解析。
|
||||
const directDnsFallbacks = [
|
||||
'https://dns.alidns.com/dns-query',
|
||||
'https://doh.pub/dns-query',
|
||||
];
|
||||
|
||||
function main(config, profileName) {{
|
||||
const existingRules = Array.isArray(config.rules) ? config.rules : [];
|
||||
const existingRuleSet = new Set(existingRules);
|
||||
const dns = config.dns && typeof config.dns === 'object' && !Array.isArray(config.dns)
|
||||
? config.dns
|
||||
: {{}};
|
||||
const existingFallbacks = Array.isArray(dns.fallback)
|
||||
? dns.fallback
|
||||
: (typeof dns.fallback === 'string' ? [dns.fallback] : []);
|
||||
const existingFallbackSet = new Set(existingFallbacks);
|
||||
|
||||
config.rules = [
|
||||
...prependRules.filter((rule) => !existingRuleSet.has(rule)),
|
||||
...existingRules,
|
||||
];
|
||||
dns.fallback = [
|
||||
...directDnsFallbacks.filter((server) => !existingFallbackSet.has(server)),
|
||||
...existingFallbacks,
|
||||
];
|
||||
config.dns = dns;
|
||||
|
||||
return config;
|
||||
}}
|
||||
@@ -66,7 +109,7 @@ def main() -> None:
|
||||
out = Path(args.out)
|
||||
out.parent.mkdir(parents=True, exist_ok=True)
|
||||
out.write_text(script, encoding="utf-8")
|
||||
print(f"✅ 已生成 {out}({len(payload)} 条规则)")
|
||||
print(f"[ok] 已生成 {out}({len(payload)} 条规则)")
|
||||
print(" 请在 Clash Verge 界面点「重启内核」生效。")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user