Files
BFR/tools/gen_profiles.py
M1rsem 89d0adb27c Release VeilBox v1.11.0: switchable TrustTunnel/olcrtc profiles.
Rename display name to VeilBox, add box.profile + sbfr p switcher, and ship scrubbed sing-box profile templates for quick TT/olcrtc flips.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-12 20:34:21 +03:00

106 lines
3.2 KiB
Python

import json
import copy
from pathlib import Path
live = json.loads(Path(r"E:\bfr_mod\phone_configs\live\config-hy2-wg.json").read_text(encoding="utf-8"))
def scrub(cfg):
c = copy.deepcopy(cfg)
# Do not ship WireGuard private keys in the module repo
c.pop("endpoints", None)
for o in c.get("outbounds", []):
if "password" in o:
o["password"] = "YOUR_HYSTERIA2_PASSWORD"
if "uuid" in o:
o["uuid"] = "YOUR_UUID"
rules = []
seen = set()
for r in c.get("route", {}).get("rules", []):
key = json.dumps(r, sort_keys=True)
if key in seen:
continue
seen.add(key)
if r.get("outbound") == "wg-home":
continue
rules.append(r)
c.setdefault("route", {})["rules"] = rules
tags = {o.get("tag") for o in c.get("outbounds", [])}
if "sidecar-proxy" not in tags:
c["outbounds"].append(
{
"type": "socks",
"tag": "sidecar-proxy",
"server": "127.0.0.1",
"server_port": 10800,
"version": "5",
}
)
if "olcrtc-proxy" not in tags:
c["outbounds"].append(
{
"type": "socks",
"tag": "olcrtc-proxy",
"server": "127.0.0.1",
"server_port": 10801,
"version": "5",
}
)
c["dns"] = {
"servers": [
{"type": "local", "tag": "dns-direct"},
{
"type": "https",
"tag": "dns-remote",
"detour": "PLACEHOLDER",
"server": "1.1.1.1",
"path": "/dns-query",
},
],
"final": "dns-remote",
"strategy": "ipv4_only",
"independent_cache": True,
}
c["route"]["default_domain_resolver"] = "dns-direct"
c["route"]["auto_detect_interface"] = False
return c
def apply_profile(cfg, final_tag):
c = scrub(cfg)
c["route"]["final"] = final_tag
for s in c["dns"]["servers"]:
if s.get("tag") == "dns-remote":
s["detour"] = final_tag
rules = c["route"]["rules"]
has_tt = any(
r.get("ip_cidr") in ("13.140.17.163/32", ["13.140.17.163/32"]) for r in rules
)
if not has_tt:
rules.insert(0, {"ip_cidr": ["13.140.17.163/32"], "outbound": "direct"})
has_ya = any("yandex.ru" in (r.get("domain_suffix") or []) for r in rules)
if not has_ya:
rules.insert(
0,
{
"domain_suffix": ["yandex.ru", "yandex.net", "yandex.com", "ya.ru"],
"outbound": "direct",
},
)
c.setdefault("log", {})["level"] = "info"
c["log"]["timestamp"] = True
return c
out = Path(r"E:\bfr_mod\box\sing-box")
tt = apply_profile(live, "sidecar-proxy")
olc = apply_profile(live, "olcrtc-proxy")
(out / "config.trusttunnel.json").write_text(
json.dumps(tt, indent=2, ensure_ascii=False) + "\n", encoding="utf-8"
)
(out / "config.olcrtc.json").write_text(
json.dumps(olc, indent=2, ensure_ascii=False) + "\n", encoding="utf-8"
)
print("tt final", tt["route"]["final"])
print("olc final", olc["route"]["final"])