platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
45
selective-vpn-api/app/domains_handlers_table.go
Normal file
45
selective-vpn-api/app/domains_handlers_table.go
Normal file
@@ -0,0 +1,45 @@
|
||||
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})
|
||||
}
|
||||
Reference in New Issue
Block a user