From db5ca2f74f82d4ecccad693b4e6a76d438f082e7 Mon Sep 17 00:00:00 2001 From: Tobias Leuschner Date: Sat, 9 May 2026 12:57:26 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20Entfernen=20des=20wg=5Froute=20Helper-S?= =?UTF-8?q?kripts=20und=20Versionsnummer=20auf=201.0.32=20erh=C3=B6ht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 76 ----------------------------------------------------- version.txt | 2 +- 2 files changed, 1 insertion(+), 77 deletions(-) diff --git a/app.py b/app.py index af19a28..59c3933 100644 --- a/app.py +++ b/app.py @@ -327,40 +327,11 @@ def wg_update_state(): error=None, has_config=has_conf) -# Helper-Script das wg-quick via PostUp/PreDown aufruft -_WG_ROUTE_SCRIPT = BASE_DIR / 'wg_route.py' -_WG_ROUTE_PY = '''\ -#!/usr/bin/env python3 -"""PiCopy: lokale IPs bei aktivem WireGuard-VPN erreichbar halten.""" -import sys, subprocess, ipaddress - -def local_nets(): - r = subprocess.run(["ip", "-4", "addr", "show"], capture_output=True, text=True) - seen, res, iface = set(), [], "" - for ln in r.stdout.splitlines(): - if not ln[:1].isspace(): - iface = ln.split(":")[1].strip().split("@")[0] if ":" in ln else "" - elif iface and iface != "lo" and ln.strip().startswith("inet "): - try: - net = str(ipaddress.IPv4Interface(ln.split()[1]).network) - if net not in seen: seen.add(net); res.append(net) - except Exception: pass - return res - -up = len(sys.argv) < 2 or sys.argv[1] != "down" -for i, net in enumerate(local_nets()): - cmd = "add" if up else "del" - subprocess.run(["ip","rule",cmd,"from",net,"table","main","priority",str(100+i*2)], capture_output=True) - subprocess.run(["ip","rule",cmd,"to", net,"table","main","priority",str(101+i*2)], capture_output=True) -''' - - def wg_connect(): if not WG_CONF.exists(): with wg_lock: wg_state['error'] = 'Keine Konfiguration vorhanden' return False - _wg_inject_routing(WG_CONF.read_text(encoding='utf-8')) # PostUp/PreDown sicherstellen r = subprocess.run(['wg-quick', 'up', WG_IFACE], capture_output=True, text=True, timeout=30) if r.returncode == 0: @@ -425,56 +396,9 @@ def wg_uninstall(): _wg_apt('remove', ['wireguard', 'wireguard-tools']) -def _wg_inject_routing(content: str) -> str: - """Schreibt den Helper-Script und injiziert PostUp/PreDown in die Config, - falls 0.0.0.0/0 enthalten ist (Full-Tunnel). Gibt den ggf. geänderten - Config-Text zurück und schreibt ihn direkt in WG_CONF.""" - if '0.0.0.0/0' not in content: - return content - try: - _WG_ROUTE_SCRIPT.write_text(_WG_ROUTE_PY, encoding='utf-8') - _WG_ROUTE_SCRIPT.chmod(0o755) - except Exception as e: - log.warning(f'wg_route.py konnte nicht geschrieben werden: {e}') - return content - - post = f'PostUp = python3 {_WG_ROUTE_SCRIPT} up' - pred = f'PreDown = python3 {_WG_ROUTE_SCRIPT} down' - tag = str(_WG_ROUTE_SCRIPT) - - # Bereits vorhanden → nichts tun - if tag in content: - return content - - lines, new_lines, in_iface, done = content.splitlines(), [], False, False - for line in lines: - s = line.strip().lower() - # Alte PostUp/PreDown von uns entfernen (falls Pfad geändert) - if (s.startswith('postup') or s.startswith('predown')) and 'wg_route' in line: - continue - if line.strip() == '[Interface]': - in_iface = True - elif in_iface and line.strip().startswith('[') and not done: - new_lines += [post, pred, ''] - in_iface = False - done = True - new_lines.append(line) - if in_iface and not done: - new_lines += [post, pred] - - new_content = '\n'.join(new_lines) - try: - WG_CONF.write_text(new_content, encoding='utf-8') - WG_CONF.chmod(0o600) - except Exception as e: - log.warning(f'WG_CONF konnte nicht aktualisiert werden: {e}') - return new_content - - def wg_save_config(content: str): try: WG_CONF.parent.mkdir(parents=True, exist_ok=True) - content = _wg_inject_routing(content) WG_CONF.write_text(content, encoding='utf-8') WG_CONF.chmod(0o600) return True, '' diff --git a/version.txt b/version.txt index a8c6b78..08a69b5 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.0.31 \ No newline at end of file +1.0.32 \ No newline at end of file