feat: WireGuard (server + client + peers + QR) + shared UI components
WireGuard --------- * Migration 0013: wireguard_interfaces (server|client mode, key envelope- encrypted) + wireguard_peers (per-server roster). Drop old empty 0005-Schema (Option-A peer_type, kein Iface-FK), neuer Aufbau mit zwei Tabellen + FK. * internal/services/secrets: Box mit AES-256-GCM, Master-Key in /var/lib/edgeguard/.master_key (lazy-create, 0600). Sealed/Open für PrivateKey + PSK. * internal/services/wireguard: KeyGen (Curve25519 mit clamping), PublicFromPrivate (für Import), InterfacesRepo, PeersRepo, Importer (parst /etc/wireguard/*.conf, server vs. client heuristisch nach ListenPort + Peer-Anzahl). * internal/wireguard: Renderer schreibt /etc/edgeguard/wireguard/<iface>.conf (0600), restartet wg-quick@<iface> via sudo (sudoers im postinst erweitert). Idempotent — re-render nur wenn content geändert. * internal/handlers/wireguard.go: REST CRUD für interfaces+peers, /generate-keypair, /peers/:id/config (text/plain wg-quick conf), /peers/:id/qr (PNG via go-qrcode). Auto-reload nach Mutation. * edgeguard-ctl wg-import [--path /etc/wireguard]: liest existierende conf-Files in die DB. Idempotent (überspringt vorhandene Iface-Namen). Shared UI components (proxy-lb-waf design pattern) -------------------------------------------------- * PageHeader: icon + title + subtitle + extras row, einheitlich oben auf jeder Page. * ActionButtons: Edit + Delete combo mit Popconfirm + Tooltip. * StatusDot: AntD Badge pattern statt "Yes/No" — schneller scanbar in dichten Tabellen. * DataTable: pageSizeOptions [20,50,100,200] + extraActions-Alias + optional renderMobileCard für Card-Liste auf < md Breakpoint. * enterprise.css: .page-header* + .datatable-toolbar Klassen. Frontend WireGuard ------------------ * /vpn/wireguard mit zwei Tabs (Server / Client) im neuen Pattern. * Server-Tab: Modal mit Generate-Keypair-Toggle, Peer-Roster im Drawer per Server. Pro Peer: QR-Code-Modal + .conf-Download. * Client-Tab: Upstream-Card im Modal, full-tunnel-Default (0.0.0.0/0,::/0), Keepalive 25. * i18n DE/EN für wg.* Block + common.* Erweiterung. Misc ---- * Sidebar: WireGuard unter Security-Sektion. * Nav-i18n: "Firewall (v2)" → "Firewall". * Version 1.0.8 → 1.0.11. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
62
cmd/edgeguard-ctl/wg_import.go
Normal file
62
cmd/edgeguard-ctl/wg_import.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"git.netcell-it.de/projekte/edgeguard-native/internal/database"
|
||||
"git.netcell-it.de/projekte/edgeguard-native/internal/services/secrets"
|
||||
"git.netcell-it.de/projekte/edgeguard-native/internal/services/wireguard"
|
||||
)
|
||||
|
||||
// cmdWGImport reads /etc/wireguard/*.conf (or a custom dir via
|
||||
// --path) and translates each [Interface]+[Peer] block into rows in
|
||||
// wireguard_interfaces / wireguard_peers. Idempotent: ifaces with a
|
||||
// name that already exists in the DB are skipped (no overwrite).
|
||||
//
|
||||
// Use after a fresh EdgeGuard install on a box that already had a
|
||||
// hand-rolled WireGuard setup — keeps existing tunnels live across
|
||||
// the migration. After import, run `edgeguard-ctl render-config` to
|
||||
// re-emit the conf files under /etc/edgeguard/wireguard/ and start
|
||||
// the wg-quick@ units. The original /etc/wireguard files are left
|
||||
// in place for fallback.
|
||||
func cmdWGImport(args []string) int {
|
||||
fs := flag.NewFlagSet("wg-import", flag.ExitOnError)
|
||||
path := fs.String("path", "/etc/wireguard", "directory holding *.conf files")
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return 2
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
pool, err := database.Open(ctx, database.ConnStringFromEnv())
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "wg-import: open db:", err)
|
||||
return 1
|
||||
}
|
||||
defer pool.Close()
|
||||
|
||||
box := secrets.New("")
|
||||
im := wireguard.NewImporter(
|
||||
wireguard.NewInterfacesRepo(pool),
|
||||
wireguard.NewPeersRepo(pool),
|
||||
box,
|
||||
)
|
||||
res, err := im.ImportDir(ctx, *path)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "wg-import:", err)
|
||||
return 1
|
||||
}
|
||||
fmt.Printf("wg-import: %d ifaces added, %d peers added\n", res.IfacesAdded, res.PeersAdded)
|
||||
for _, s := range res.Skipped {
|
||||
fmt.Printf(" skipped: %s\n", s)
|
||||
}
|
||||
if res.IfacesAdded > 0 {
|
||||
fmt.Println("\nNext: edgeguard-ctl render-config (re-emits configs + starts wg-quick@<iface>)")
|
||||
}
|
||||
return 0
|
||||
}
|
||||
Reference in New Issue
Block a user