package app import ( "net/http" "strings" ) // --------------------------------------------------------------------- // domains table // --------------------------------------------------------------------- // GET /api/v1/domains/table -> { "lines": [ ... ] } func handleDomainsTable(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodGet { http.Error(w, "method not allowed", http.StatusMethodNotAllowed) return } lines := []string{} for _, setName := range []string{"agvpn4", "agvpn_dyn4"} { stdout, _, code, _ := runCommand("nft", "list", "set", "inet", "agvpn", setName) if code == 0 { for _, l := range strings.Split(stdout, "\n") { l = strings.TrimRight(l, "\r") if l != "" { lines = append(lines, l) } } continue } // Backward-compatible fallback for legacy hosts that still have ipset. stdout, _, code, _ = runCommand("ipset", "list", setName) if code != 0 { continue } for _, l := range strings.Split(stdout, "\n") { l = strings.TrimRight(l, "\r") if l != "" { lines = append(lines, l) } } } writeJSON(w, http.StatusOK, map[string]any{"lines": lines}) }