feat: Network/IP-Verwaltung + Mailguard-Design-Übernahme

Backend:
* Migration 0009_networks: network_interfaces (ethernet|vlan|bond|
  bridge|wireguard, role wan|lan|dmz|mgmt|cluster, parent + vlan_id
  für VLANs) + ip_addresses (interface_id FK, address+prefix, is_vip
  + vip_priority für Cluster-Failover-VIPs).
* Repos services/networkifs + services/ipaddresses + Models +
  Handler /api/v1/network-interfaces (CRUD + /:id/ip-addresses)
  und /api/v1/ip-addresses (CRUD).
* /api/v1/system/interfaces refactored auf Go-natives net.Interfaces()
  statt `ip -j addr show` shell-out — die systemd-Sandbox blockt
  AF_NETLINK auch für Go's runtime, deswegen edgeguard-api.service
  RestrictAddressFamilies um AF_NETLINK ergänzt. Output-Shape
  bleibt identisch (ifindex, ifname, flags[], mtu, link_type,
  address, addr_info[]) — Frontend muss nicht angepasst werden.

Frontend:
* Networks-Page (/networks): "System-discovered Interfaces"
  read-only Tags-Card oben, deklarierte Interfaces unten als
  Tabelle mit Modal-CRUD; Type-Switch zeigt parent+vlan_id-Felder
  bei type=vlan; Role-Tags farbig (wan blau, lan grün, dmz orange,
  mgmt purple, cluster magenta).
* IPAddresses-Page (/ip-addresses): Tabelle pro Interface, VIP-
  Toggle blendet vip_priority-Eingabe ein. Goldenes VIP-Tag in der
  Liste.
* Sidebar erweitert um Networks + IP-Adressen + section-grouping.

Design 1:1 von mail-gateway/management-ui/ übernommen:
* enterprise.css verbatim (Inter-Font via Google CDN statt local
  woff2), Sidebar 240px dunkler Gradient #0B1426→#101D33→#0D1829,
  branding-accent #1677ff für Active-State, abgerundete Cards mit
  shadow-Token, Header weiß mit subtilem backdrop-filter.
* AntD-Theme-Tokens: colorPrimary #0EA5E9, fontSize 13, fontFamily
  'Inter', controlHeight 34, borderRadius 6.
* Layout-Komponenten neu strukturiert: AppLayout/Sidebar/Header
  matchen mailguard-Klassen-Naming (.app-layout, .main-content,
  .sidebar-section, .sidebar-menu-item.active, .header-left, …).
* Sidebar mit 4 Sektionen (Übersicht / Routing / Netzwerk / System)
  + Logo-Header + Versions-Footer.

Live-deployed auf 89.163.205.6: Networks-Endpoint listet eth0
(89.163.205.6/24, MAC bc:24:11:64:29:e8) + lo, frontend zeigt sie
als System-Tags in der Networks-Page.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Debian
2026-05-09 16:08:44 +02:00
parent f0589e5628
commit ca03e69637
21 changed files with 4115 additions and 87 deletions

View File

@@ -0,0 +1,129 @@
// Package ipaddresses implements CRUD against the `ip_addresses`
// table — addresses bound to operator-declared network interfaces,
// with is_vip + vip_priority for cluster-failover semantics.
package ipaddresses
import (
"context"
"errors"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
"git.netcell-it.de/projekte/edgeguard-native/internal/models"
)
var ErrNotFound = errors.New("ip address not found")
type Repo struct {
Pool *pgxpool.Pool
}
func New(pool *pgxpool.Pool) *Repo { return &Repo{Pool: pool} }
const baseSelect = `
SELECT id, interface_id, address, prefix, is_vip, vip_priority,
description, active, created_at, updated_at
FROM ip_addresses
`
func (r *Repo) List(ctx context.Context) ([]models.IPAddress, error) {
rows, err := r.Pool.Query(ctx, baseSelect+" ORDER BY interface_id ASC, address ASC")
if err != nil {
return nil, err
}
defer rows.Close()
out := make([]models.IPAddress, 0, 8)
for rows.Next() {
a, err := scan(rows)
if err != nil {
return nil, err
}
out = append(out, *a)
}
return out, rows.Err()
}
func (r *Repo) ListForInterface(ctx context.Context, ifaceID int64) ([]models.IPAddress, error) {
rows, err := r.Pool.Query(ctx, baseSelect+
" WHERE interface_id = $1 ORDER BY address ASC", ifaceID)
if err != nil {
return nil, err
}
defer rows.Close()
out := make([]models.IPAddress, 0, 4)
for rows.Next() {
a, err := scan(rows)
if err != nil {
return nil, err
}
out = append(out, *a)
}
return out, rows.Err()
}
func (r *Repo) Get(ctx context.Context, id int64) (*models.IPAddress, error) {
row := r.Pool.QueryRow(ctx, baseSelect+" WHERE id = $1", id)
a, err := scan(row)
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return nil, ErrNotFound
}
return nil, err
}
return a, nil
}
func (r *Repo) Create(ctx context.Context, a models.IPAddress) (*models.IPAddress, error) {
row := r.Pool.QueryRow(ctx, `
INSERT INTO ip_addresses (interface_id, address, prefix, is_vip, vip_priority, description, active)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING id, interface_id, address, prefix, is_vip, vip_priority,
description, active, created_at, updated_at`,
a.InterfaceID, a.Address, a.Prefix, a.IsVIP, a.VIPPriority, a.Description, a.Active)
return scan(row)
}
func (r *Repo) Update(ctx context.Context, id int64, a models.IPAddress) (*models.IPAddress, error) {
row := r.Pool.QueryRow(ctx, `
UPDATE ip_addresses SET
interface_id = $1, address = $2, prefix = $3,
is_vip = $4, vip_priority = $5, description = $6, active = $7,
updated_at = NOW()
WHERE id = $8
RETURNING id, interface_id, address, prefix, is_vip, vip_priority,
description, active, created_at, updated_at`,
a.InterfaceID, a.Address, a.Prefix, a.IsVIP, a.VIPPriority, a.Description, a.Active, id)
out, err := scan(row)
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return nil, ErrNotFound
}
return nil, err
}
return out, nil
}
func (r *Repo) Delete(ctx context.Context, id int64) error {
tag, err := r.Pool.Exec(ctx, `DELETE FROM ip_addresses WHERE id = $1`, id)
if err != nil {
return err
}
if tag.RowsAffected() == 0 {
return ErrNotFound
}
return nil
}
func scan(row interface{ Scan(...any) error }) (*models.IPAddress, error) {
var a models.IPAddress
if err := row.Scan(
&a.ID, &a.InterfaceID, &a.Address, &a.Prefix,
&a.IsVIP, &a.VIPPriority,
&a.Description, &a.Active,
&a.CreatedAt, &a.UpdatedAt,
); err != nil {
return nil, err
}
return &a, nil
}

View File

@@ -0,0 +1,110 @@
// Package networkifs implements CRUD against the
// `network_interfaces` table — operator-declared interfaces
// (ethernet, vlan, bond, bridge, wireguard).
package networkifs
import (
"context"
"errors"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
"git.netcell-it.de/projekte/edgeguard-native/internal/models"
)
var ErrNotFound = errors.New("network interface not found")
type Repo struct {
Pool *pgxpool.Pool
}
func New(pool *pgxpool.Pool) *Repo { return &Repo{Pool: pool} }
const baseSelect = `
SELECT id, name, type, parent, vlan_id, role, mtu, active, description,
created_at, updated_at
FROM network_interfaces
`
func (r *Repo) List(ctx context.Context) ([]models.NetworkInterface, error) {
rows, err := r.Pool.Query(ctx, baseSelect+" ORDER BY name ASC")
if err != nil {
return nil, err
}
defer rows.Close()
out := make([]models.NetworkInterface, 0, 8)
for rows.Next() {
i, err := scan(rows)
if err != nil {
return nil, err
}
out = append(out, *i)
}
return out, rows.Err()
}
func (r *Repo) Get(ctx context.Context, id int64) (*models.NetworkInterface, error) {
row := r.Pool.QueryRow(ctx, baseSelect+" WHERE id = $1", id)
i, err := scan(row)
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return nil, ErrNotFound
}
return nil, err
}
return i, nil
}
func (r *Repo) Create(ctx context.Context, i models.NetworkInterface) (*models.NetworkInterface, error) {
row := r.Pool.QueryRow(ctx, `
INSERT INTO network_interfaces (name, type, parent, vlan_id, role, mtu, active, description)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING id, name, type, parent, vlan_id, role, mtu, active, description,
created_at, updated_at`,
i.Name, i.Type, i.Parent, i.VLANID, i.Role, i.MTU, i.Active, i.Description)
return scan(row)
}
func (r *Repo) Update(ctx context.Context, id int64, i models.NetworkInterface) (*models.NetworkInterface, error) {
row := r.Pool.QueryRow(ctx, `
UPDATE network_interfaces SET
name = $1, type = $2, parent = $3, vlan_id = $4,
role = $5, mtu = $6, active = $7, description = $8,
updated_at = NOW()
WHERE id = $9
RETURNING id, name, type, parent, vlan_id, role, mtu, active, description,
created_at, updated_at`,
i.Name, i.Type, i.Parent, i.VLANID, i.Role, i.MTU, i.Active, i.Description, id)
out, err := scan(row)
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return nil, ErrNotFound
}
return nil, err
}
return out, nil
}
func (r *Repo) Delete(ctx context.Context, id int64) error {
tag, err := r.Pool.Exec(ctx, `DELETE FROM network_interfaces WHERE id = $1`, id)
if err != nil {
return err
}
if tag.RowsAffected() == 0 {
return ErrNotFound
}
return nil
}
func scan(row interface{ Scan(...any) error }) (*models.NetworkInterface, error) {
var i models.NetworkInterface
if err := row.Scan(
&i.ID, &i.Name, &i.Type, &i.Parent, &i.VLANID,
&i.Role, &i.MTU, &i.Active, &i.Description,
&i.CreatedAt, &i.UpdatedAt,
); err != nil {
return nil, err
}
return &i, nil
}