whitelist-fix
All checks were successful
release-tag / release-image (push) Successful in 1m49s

This commit is contained in:
2025-11-10 00:24:54 +01:00
parent eaf47e7a9f
commit 068f13b73f

29
main.go
View File

@@ -980,33 +980,40 @@ func (s *server) handleWhitelist(w http.ResponseWriter, r *http.Request) {
return return
} }
var body struct { var body struct {
Entry string `json:"ip"` // rückwärtskompatibel: Feld heißt weiter "ip" IP string `json:"ip"`
// optional: "entry" wäre semantisch besser; hier bleiben wir kompatibel } // GUI bleibt kompatibel
}
if err := json.NewDecoder(r.Body).Decode(&body); err != nil { if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
http.Error(w, "bad request", http.StatusBadRequest) http.Error(w, "bad request", http.StatusBadRequest)
return return
} }
sRaw := strings.TrimSpace(body.Entry) raw := strings.TrimSpace(body.IP)
// 1) Einzel-IP? // Fall 1: Einzel-IP
if addr, err := netip.ParseAddr(sRaw); err == nil { if addr, err := netip.ParseAddr(raw); err == nil {
if err := s.st.AddWhitelist(addr.Unmap()); err != nil { addr = addr.Unmap()
if err := s.st.AddWhitelist(addr); err != nil {
http.Error(w, "store error", http.StatusInternalServerError) http.Error(w, "store error", http.StatusInternalServerError)
return return
} }
writeJSON(w, map[string]any{"status": "whitelisted_ip", "ip": addr.Unmap().String()}) writeJSON(w, map[string]any{
"status": "whitelisted_ip",
"ip": addr.String(),
})
return return
} }
// 2) Prefix? // Fall 2: Prefix (wir erlauben auch "8.8.8.8" → wird zu /32 normalisiert)
if norm, ok := normalizeLineToPrefix(sRaw); ok { if norm, ok := normalizeLineToPrefix(raw); ok {
if pfx, err := netip.ParsePrefix(norm); err == nil { if pfx, err := netip.ParsePrefix(norm); err == nil {
// wenn du Prefix-Whitelist hast:
if err := s.st.AddWhitelistPrefix(pfx); err != nil { if err := s.st.AddWhitelistPrefix(pfx); err != nil {
http.Error(w, "store error", http.StatusInternalServerError) http.Error(w, "store error", http.StatusInternalServerError)
return return
} }
writeJSON(w, map[string]any{"status": "whitelisted_prefix", "prefix": pfx.String()}) writeJSON(w, map[string]any{
"status": "whitelisted_prefix",
"prefix": pfx.String(),
})
return return
} }
} }