From 179462b0c524f3ca4be80780fc199099ad8ca971 Mon Sep 17 00:00:00 2001 From: hermes Date: Fri, 27 Nov 2026 11:22:09 +0000 Subject: [PATCH] =?UTF-8?q?configs:=20=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82?= =?UTF-8?q?=D1=8B=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20WG-=D0=BF=D0=B8?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D1=80?= =?UTF-8?q?=D0=B5=D0=BB=D0=B5=D1=8F=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20vps?= =?UTF-8?q?02=20(2026-11-27)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WALKTHROUGH.md | 2 +- .../wg-relay-2026-11-27/patch1-relay-vps01.py | 45 +++++++++++++++++++ .../wg-relay-2026-11-27/patch2-relay-vps03.py | 34 ++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 configs/wg-relay-2026-11-27/patch1-relay-vps01.py create mode 100644 configs/wg-relay-2026-11-27/patch2-relay-vps03.py diff --git a/WALKTHROUGH.md b/WALKTHROUGH.md index f6d3019..dceb325 100644 --- a/WALKTHROUGH.md +++ b/WALKTHROUGH.md @@ -275,4 +275,4 @@ curl -s --socks5 127.0.0.1:1080 https://ifconfig.me # 5.129.217.146 - Спека: `openspec/specs/tunnel-proxy` (change `add-wg-relay-via-vps02`). - Бэкапы конфигов: `/etc/wireguard/wg0.conf.bak-2026-11-27` (bigbox, vps01), `wg0.conf.bak2-2026-11-27` (bigbox, vps03), `wg0.conf.bak3-2026-11-27` (vps03). -- Скрипты правки: `/opt/hermes/.hermes/cache/scratch/wg_relay_patch*.py` (временные). +- Скрипты правки: `configs/wg-relay-2026-11-27/patch1-relay-vps01.py`, `patch2-relay-vps03.py`. diff --git a/configs/wg-relay-2026-11-27/patch1-relay-vps01.py b/configs/wg-relay-2026-11-27/patch1-relay-vps01.py new file mode 100644 index 0000000..f4dd8d0 --- /dev/null +++ b/configs/wg-relay-2026-11-27/patch1-relay-vps01.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +"""Перевод пиринга WG на релей через vps02 (add-wg-relay-via-vps02).""" +import re, shutil, sys, os, time + +CONF = "/etc/wireguard/wg0.conf" +MODE = sys.argv[1] # vps01 | bigbox + +KEY_VPS02 = "JbC++sMcNaw1L7qL4ZvjfHYIjgw7h77aXXuz1sCHQlQ=" +KEY_VPS01 = "ZAvz4xCEPmlbor7/sg7+gCC5X5ju4IBK0KEmqD7xmBc=" +KEY_BIGBOX = "SXCR8BgJcomhe2pygfhNmXiRgoJynuwoQxMsqFDL/W8=" + +PLAN = { + "vps01": {KEY_VPS02: "10.8.0.2/32, 10.8.0.4/32", KEY_BIGBOX: None}, + "bigbox": {KEY_VPS02: "10.8.0.1/32, 10.8.0.4/32, 10.8.0.5/32", KEY_VPS01: None}, +}[MODE] + +bak = CONF + ".bak-2026-11-27" +if not os.path.exists(bak): + shutil.copy2(CONF, bak) + print(f"бэкап: {bak}") + +text = open(CONF).read() +# разбить на блоки: [Interface] и каждый [Peer] с окружающими строками +parts = re.split(r"(?m)^(?=\[Peer\])", text) +out = [] +for part in parts: + key = None + m = re.search(r"(?m)^PublicKey\s*=\s*(\S+)\s*$", part) + if m: + key = m.group(1) + if key in PLAN and PLAN[key] is not None: + if re.search(r"(?m)^AllowedIPs\s*=", part): + part = re.sub(r"(?m)^AllowedIPs\s*=.*$", "AllowedIPs = " + PLAN[key], part, count=1) + else: + part = part.rstrip("\n") + "\nAllowedIPs = " + PLAN[key] + "\n" + print(f"обновлён пир {key[:8]}… → AllowedIPs = {PLAN[key]}") + elif key in PLAN: + part = "".join(f"#DISABLED-20261127 {ln}" if ln.strip() else ln + for ln in part.splitlines(keepends=True)) + print(f"пир {key[:8]}… закомментирован") + out.append(part) + +new = "".join(out) +open(CONF, "w").write(new) +print("конфиг записан") diff --git a/configs/wg-relay-2026-11-27/patch2-relay-vps03.py b/configs/wg-relay-2026-11-27/patch2-relay-vps03.py new file mode 100644 index 0000000..4682d88 --- /dev/null +++ b/configs/wg-relay-2026-11-27/patch2-relay-vps03.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +"""Шаг 2 релея: 10.8.0.3 тоже через vps02 (UDP bigbox↔vps03 не доходит).""" +import re, shutil, sys, os + +CONF = "/etc/wireguard/wg0.conf" +MODE = sys.argv[1] + +KEY_VPS02 = "JbC++sMcNaw1L7qL4ZvjfHYIjgw7h77aXXuz1sCHQlQ=" +KEY_BIGBOX = "SXCR8BgJcomhe2pygfhNmXiRgoJynuwoQxMsqFDL/W8=" + +bak = CONF + ".bak2-2026-11-27" +if not os.path.exists(bak): + shutil.copy2(CONF, bak) + print("бэкап:", bak) + +text = open(CONF).read() +parts = re.split(r"(?m)^(?=\[Peer\])", text) +out = [] +for part in parts: + m = re.search(r"(?m)^PublicKey\s*=\s*(\S+)\s*$", part) + key = m.group(1) if m else None + if MODE == "bigbox" and key == KEY_VPS02: + part = re.sub(r"(?m)^AllowedIPs\s*=.*$", + "AllowedIPs = 10.8.0.1/32, 10.8.0.3/32, 10.8.0.4/32, 10.8.0.5/32", + part, count=1) + print("bigbox: пир vps02 → +10.8.0.3/32") + elif MODE == "vps03" and key == KEY_BIGBOX: + part = "".join(f"#DISABLED-20261127 {ln}" if ln.strip() else ln + for ln in part.splitlines(keepends=True)) + print("vps03: пир bigbox закомментирован") + out.append(part) + +open(CONF, "w").write("".join(out)) +print("конфиг записан")