feat: umfangreiches UI+API-Polish (v1.1.36–1.1.42)

Backend:
- Audit-Log: Search-Endpoint mit ILIKE-Filter (actor/action/subject/date)
- NTP: /ntp/status via chronyc tracking (Stratum, Offset, Quelle)
- System: /service-restart mit Allowlist (haproxy/squid/unbound/chrony/scheduler)
- Domain-Response-Headers + Rate-Limit (Migration 0024)
- Join-Tokens (Migration 0025), Cluster-mTLS, Aggregator-Fan-Out
- apt-Service für Update-Banner (apt-get update + Versionsprüfung)
- Backup-Retry mit exponential backoff (retry_apt 3×)
- publish.sh fail-fast + cleanup-old.sh (max 10 Versionen)

Frontend:
- Audit-Log-Page (/audit) mit Filter + Pagination
- ErrorBoundary an React-Root + Vite build-target festgenagelt (iOS 15+)
- Storage-Schema-Stamp: auto-wipe bei Versions-Mismatch (blank-page-Fix)
- EmptyState-Komponente überall ausgerollt
- SSL: Aggregate-Karte (total/expiring/expired/errors)
- Backups: Aggregate-Karte (letzter Backup/Größe/Fehlschläge 24h) + Backup-Now
- NTP: Sync-Status-Karte (chronyc tracking live)
- Domains: Backend-UP/DOWN-Chip aus HAProxy-Stats
- Backends: HAProxy-Status-Spalte (UP/DEGRADED/DOWN)
- Settings: Service-Neustart-Karte (haproxy/squid/unbound/chrony/scheduler)
- Settings: Upgrade-Status-Card, Wartungsmodus, Auto-Update, Retention
- Dashboard: Recent-Alerts, Cluster-Health, License-Chip, Onboarding-Hint
- System-Regeln im Firewall als eigener Tab

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Debian
2026-05-19 16:18:41 +02:00
parent 3178e25e78
commit 35b7308ce2
82 changed files with 8408 additions and 392 deletions

View File

@@ -98,6 +98,98 @@ LIMIT $1`, limit)
return out, rows.Err()
}
// SearchFilter beschreibt einen filter-gestützten Audit-Log-Abruf.
// Alle Felder optional — leere Werte werden vom Query ignoriert. Such-
// Strings sind case-insensitive ILIKE-Substring-Matches. Limit wird auf
// 500 gedeckelt (UI-Schutz vor versehentlichem Full-Scan), Offset für
// einfaches Paging.
type SearchFilter struct {
Actor string
Action string
Subject string
Since *time.Time
Until *time.Time
Limit int
Offset int
}
// Search liefert audit_log-Einträge nach Filter, newest first. Filter-
// Felder werden via dynamisch zusammengesetzter WHERE-Klausel angewendet
// — Parametrisiert (kein String-Concat von User-Input).
func (r *Repo) Search(ctx context.Context, f SearchFilter) ([]Entry, error) {
if r == nil || r.Pool == nil {
return []Entry{}, nil
}
limit := f.Limit
if limit <= 0 || limit > 500 {
limit = 100
}
offset := f.Offset
if offset < 0 {
offset = 0
}
args := []any{}
where := ""
add := func(cond string, val any) {
args = append(args, val)
if where == "" {
where = " WHERE " + cond + "$" + itoa(len(args))
} else {
where += " AND " + cond + "$" + itoa(len(args))
}
}
if f.Actor != "" {
add("actor ILIKE ", "%"+f.Actor+"%")
}
if f.Action != "" {
add("action ILIKE ", "%"+f.Action+"%")
}
if f.Subject != "" {
add("subject ILIKE ", "%"+f.Subject+"%")
}
if f.Since != nil {
add("created_at >= ", *f.Since)
}
if f.Until != nil {
add("created_at <= ", *f.Until)
}
args = append(args, limit, offset)
q := "SELECT id, actor, action, subject, detail, node_id, created_at FROM audit_log" +
where +
" ORDER BY created_at DESC, id DESC LIMIT $" + itoa(len(args)-1) +
" OFFSET $" + itoa(len(args))
rows, err := r.Pool.Query(ctx, q, args...)
if err != nil {
return nil, err
}
defer rows.Close()
out := make([]Entry, 0, limit)
for rows.Next() {
var e Entry
if err := rows.Scan(&e.ID, &e.Actor, &e.Action, &e.Subject, &e.Detail, &e.NodeID, &e.CreatedAt); err != nil {
return nil, err
}
out = append(out, e)
}
return out, rows.Err()
}
func itoa(n int) string {
// kleiner local-Helper damit wir nicht strconv für Single-Digit-
// Parameter-Indizes importieren müssen.
if n < 10 {
return string(rune('0' + n))
}
// >9 Parameter ist hier in der Praxis nicht möglich (Filter <= 5 +
// LIMIT/OFFSET = 7), aber Fallback für Robustness.
s := ""
for n > 0 {
s = string(rune('0'+n%10)) + s
n /= 10
}
return s
}
// Log writes one audit_log row. detail is JSON-encodable (typically a
// map[string]any) — empty map means "no payload". If pool is nil
// (e.g. dev env without DB), Log silently no-ops so handlers don't
@@ -153,3 +245,24 @@ RETURNING id, created_at`,
r.broadcast(e)
return nil
}
// Cleanup löscht alle audit_log-Rows die älter als keepDays sind.
// Schutz vor unbounded growth bei langlebigen Boxen (audit_log kann
// sonst nach 1-2 Jahren mehrere GB Disk + entsprechende Query-Latenz
// haben). Liefert die Anzahl gelöschter Rows.
//
// keepDays <= 0 → no-op (Cleanup deaktiviert, alles bleibt erhalten).
// keepDays sollte deutlich über Audit-Anforderungen liegen — 90 Tage
// ist ein vernünftiger Default für Self-Service-Boxen.
func (r *Repo) Cleanup(ctx context.Context, keepDays int) (int64, error) {
if r == nil || r.Pool == nil || keepDays <= 0 {
return 0, nil
}
tag, err := r.Pool.Exec(ctx, `
DELETE FROM audit_log
WHERE created_at < NOW() - ($1::text || ' days')::interval`, keepDays)
if err != nil {
return 0, err
}
return tag.RowsAffected(), nil
}