Terminal: drop files / paperclip; net core: fallback exit, re-test on network change, hide/unhide connections
- term.macOS: dropping files over an open terminal or the paperclip types their shell-escaped paths (bracketed paste when the program asks for it). - Traffic now goes through a fallback group "exit": the pick while it answers, "auto" when it doesn't. A pinned connection that dies no longer cuts the Mac off. - Faster checks (exit 30 s, auto 60 s, 3 failures trigger a re-test) and a re-test of every group 4 s after any network change (Wi-Fi switch, sleep, AmneziaVPN). - hide/unhide instead of deleting keys: Amnezia connections and VLESS nodes leave the list and "auto"; kept on disk, returned from "Убранные". - Core logs are owner-only (they can contain the subscription URL). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+44
-14
@@ -6,6 +6,8 @@ keys/*.vpnkey one vpn:// key per Amnezia connection (AmneziaWG 2/3); BroV
|
||||
src/saga.conf WireGuard client config -> only 192.168.8.0/24
|
||||
src/planet9.conf WireGuard client config -> only 192.168.68.0/24
|
||||
src/vless.sub 3x-ui subscription URL (all VLESS nodes)
|
||||
hidden.json connections removed in BroV: {"amnezia": [...], "vless": [...]} (proxy
|
||||
names). Hidden ones stay on disk and can be returned from the panel.
|
||||
|
||||
Secrets stay in this private folder; nothing here goes to git.
|
||||
"""
|
||||
@@ -28,10 +30,26 @@ CLIENTS = { # name: (conf file, routed subnets, what "off" means)
|
||||
# home WireGuard when away. Optional: only if src/home.conf exists.
|
||||
"home": ("home.conf", ["192.168.10.0/24"], "DIRECT"),
|
||||
}
|
||||
TEST_URL = "https://www.gstatic.com/generate_204"
|
||||
AI_DOMAINS = ["anthropic.com", "claude.ai", "claude.com", "openai.com", "chatgpt.com",
|
||||
"oaistatic.com", "oaiusercontent.com", "github.com", "githubusercontent.com"]
|
||||
|
||||
|
||||
def hidden():
|
||||
try:
|
||||
with open(os.path.join(CORE, "hidden.json")) as f:
|
||||
h = json.load(f)
|
||||
return {"amnezia": [str(x) for x in h.get("amnezia", [])], "vless": [str(x) for x in h.get("vless", [])]}
|
||||
except (OSError, ValueError, AttributeError):
|
||||
return {"amnezia": [], "vless": []}
|
||||
|
||||
|
||||
def rx(name):
|
||||
"""Literal regex for a node name (backslash only before ASCII punctuation: valid in Go
|
||||
regexp and regexp2 alike)."""
|
||||
return "".join("\\" + c if c in "\\.^$|?*+()[]{}" else c for c in name)
|
||||
|
||||
|
||||
def mid(v, default):
|
||||
"""'100-120' -> 110 (mihomo takes single ints for timers)."""
|
||||
if v is None or v == "":
|
||||
@@ -141,7 +159,9 @@ def main():
|
||||
|
||||
# Amnezia connections live in their own provider file so BroV can add keys live.
|
||||
keyfiles = sorted(f for f in os.listdir(KEYS) if f.endswith(".vpnkey"))
|
||||
awg = [amnezia(os.path.join(KEYS, f), "AWG " + f[:-len(".vpnkey")]) for f in keyfiles]
|
||||
hid = hidden()
|
||||
awg = [amnezia(os.path.join(KEYS, f), "AWG " + f[:-len(".vpnkey")]) for f in keyfiles
|
||||
if "AWG " + f[:-len(".vpnkey")] not in hid["amnezia"]]
|
||||
prov = os.path.join(KEYS, "amnezia.yaml")
|
||||
with open(os.open(prov, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600), "w") as f:
|
||||
f.write(y({"proxies": awg}) + "\n")
|
||||
@@ -156,9 +176,18 @@ def main():
|
||||
for name, (_, nets, _) in clients.items():
|
||||
# Through a switch group: BroV turns client networks on/off without a reload.
|
||||
rules += [f"IP-CIDR,{n},{name}-sw,no-resolve" for n in nets]
|
||||
rules += [f"DOMAIN-SUFFIX,{d},ai-out" for d in AI_DOMAINS]
|
||||
rules += [f"DOMAIN-SUFFIX,{d},exit" for d in AI_DOMAINS]
|
||||
rules += ["DOMAIN-SUFFIX,ru,DIRECT", "DOMAIN-SUFFIX,su,DIRECT", "DOMAIN-SUFFIX,xn--p1ai,DIRECT",
|
||||
"MATCH,ai-out"]
|
||||
"MATCH,exit"]
|
||||
vless = {
|
||||
# Fetch the list directly: the nodes themselves are dialled directly anyway.
|
||||
"type": "http", "url": sub, "interval": 43200, "path": "./providers/vless.yaml", "proxy": "DIRECT",
|
||||
"health-check": {"enable": True, "url": TEST_URL, "interval": 300}}
|
||||
if hid["vless"]:
|
||||
# Hidden nodes stay in the subscription, the core just skips them.
|
||||
vless["exclude-filter"] = "^(?:" + "|".join(rx(n) for n in hid["vless"]) + ")$"
|
||||
awg_prov = {"type": "file", "path": "./keys/amnezia.yaml",
|
||||
"health-check": {"enable": True, "url": TEST_URL, "interval": 300}}
|
||||
|
||||
cfg = {
|
||||
"mixed-port": 7890, "allow-lan": False, "mode": "rule", "log-level": "error", "ipv6": False,
|
||||
@@ -171,28 +200,29 @@ def main():
|
||||
"fake-ip-filter": ["*.lan", "*.local", "+.duckdns.org"],
|
||||
"default-nameserver": ["77.88.8.8", "1.1.1.1"],
|
||||
"proxy-server-nameserver": ["77.88.8.8", "1.1.1.1"],
|
||||
"nameserver": ["https://1.1.1.1/dns-query#ai-out", "https://8.8.8.8/dns-query#ai-out"],
|
||||
"nameserver": ["https://1.1.1.1/dns-query#exit", "https://8.8.8.8/dns-query#exit"],
|
||||
"direct-nameserver": ["77.88.8.8", "77.88.8.1"]},
|
||||
"proxies": proxies,
|
||||
"proxy-providers": {
|
||||
"amnezia-keys": {"type": "file", "path": "./keys/amnezia.yaml",
|
||||
"health-check": {"enable": True, "url": "https://www.gstatic.com/generate_204",
|
||||
"interval": 300}},
|
||||
"vless-cluster": {
|
||||
# Fetch the list directly: the nodes themselves are dialled directly anyway.
|
||||
"type": "http", "url": sub, "interval": 43200, "path": "./providers/vless.yaml", "proxy": "DIRECT",
|
||||
"health-check": {"enable": True, "url": "https://www.gstatic.com/generate_204", "interval": 300}}},
|
||||
"proxy-providers": {"amnezia-keys": awg_prov, "vless-cluster": vless},
|
||||
"proxy-groups": [
|
||||
# What traffic actually uses: the exit picked in BroV while it answers, "auto"
|
||||
# when it doesn't (a pinned connection that dies no longer takes the Mac offline).
|
||||
# Back to the pick as soon as it answers again. Checked every 30 s and right after
|
||||
# 3 failed connections.
|
||||
{"name": "exit", "type": "fallback", "proxies": ["ai-out", "auto"],
|
||||
"url": TEST_URL, "interval": 30, "timeout": 4000, "max-failed-times": 3, "lazy": False},
|
||||
# What BroV's globe panel switches: "auto", the Amnezia group, or one VLESS node.
|
||||
{"name": "ai-out", "type": "select", "proxies": ["auto", "amnezia"], "use": ["vless-cluster"]},
|
||||
# Fastest alive exit among every Amnezia connection and every VLESS node;
|
||||
# switches only when another one is 100+ ms faster.
|
||||
{"name": "auto", "type": "url-test", "use": ["amnezia-keys", "vless-cluster"],
|
||||
"url": "https://www.gstatic.com/generate_204", "interval": 120, "tolerance": 100, "lazy": False},
|
||||
"url": TEST_URL, "interval": 60, "timeout": 4000, "max-failed-times": 3,
|
||||
"tolerance": 100, "lazy": False},
|
||||
# Amnezia: "amnezia-auto" (fastest connection) or one fixed connection.
|
||||
{"name": "amnezia", "type": "select", "proxies": ["amnezia-auto"], "use": ["amnezia-keys"]},
|
||||
{"name": "amnezia-auto", "type": "url-test", "use": ["amnezia-keys"],
|
||||
"url": "https://www.gstatic.com/generate_204", "interval": 120, "tolerance": 100, "lazy": False},
|
||||
"url": TEST_URL, "interval": 60, "timeout": 4000, "max-failed-times": 3,
|
||||
"tolerance": 100, "lazy": False},
|
||||
] + [
|
||||
# Client networks: off (REJECT) until switched on in BroV.
|
||||
# Client networks: first option = "off" (REJECT, or DIRECT for home).
|
||||
|
||||
Reference in New Issue
Block a user