2026-09-23 09:52:01 +03:00
|
|
|
package dashboard
|
|
|
|
|
|
2026-09-23 11:58:53 +03:00
|
|
|
import (
|
|
|
|
|
"net/http"
|
2026-10-03 18:36:03 +03:00
|
|
|
"net/netip"
|
2026-10-01 19:31:11 +03:00
|
|
|
"net/url"
|
2026-10-03 18:36:03 +03:00
|
|
|
"strconv"
|
2026-09-23 11:58:53 +03:00
|
|
|
"strings"
|
|
|
|
|
)
|
2026-09-23 09:52:01 +03:00
|
|
|
|
|
|
|
|
type registryPageData struct {
|
|
|
|
|
PageData
|
2026-10-01 19:31:11 +03:00
|
|
|
Items []registryItem
|
|
|
|
|
Query string
|
|
|
|
|
StatusFilter string
|
2026-10-03 18:36:03 +03:00
|
|
|
Run int64 // drill-down from the analytics page
|
|
|
|
|
Subnet string
|
2026-10-01 19:31:11 +03:00
|
|
|
Page, PerPage int
|
|
|
|
|
Total int
|
|
|
|
|
Pager pagerData
|
|
|
|
|
PerPageOptions []int
|
2026-09-23 09:52:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type registryDetailData struct {
|
|
|
|
|
PageData
|
|
|
|
|
History registryHistoryResponse
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handleRegistryPage lists every address ever submitted to the check
|
|
|
|
|
// queue, with a summary of its accumulated check history — the durable
|
|
|
|
|
// record that survives an address being deleted from /ips and later
|
2026-09-23 11:58:53 +03:00
|
|
|
// re-added. See internal/db/migrations/0007_ip_registry.sql. Optional
|
|
|
|
|
// ?q=&status= query params narrow the list by address substring and by
|
2026-10-01 19:31:11 +03:00
|
|
|
// LastResult, and ?page=&per_page= select a page — all applied server-side
|
|
|
|
|
// (control-api's ListRegistryPage), so only the visible rows are transferred.
|
2026-09-23 09:52:01 +03:00
|
|
|
func (s *Server) handleRegistryPage(w http.ResponseWriter, r *http.Request) {
|
2026-09-23 11:58:53 +03:00
|
|
|
q := strings.TrimSpace(r.URL.Query().Get("q"))
|
|
|
|
|
status := r.URL.Query().Get("status")
|
2026-10-01 19:31:11 +03:00
|
|
|
if !containsStr(ipResults, status) {
|
|
|
|
|
status = ""
|
|
|
|
|
}
|
|
|
|
|
perPage := parsePerPage(r.URL.Query().Get("per_page"))
|
|
|
|
|
page := parsePage(r.URL.Query().Get("page"))
|
2026-10-03 18:36:03 +03:00
|
|
|
run, _ := strconv.ParseInt(r.URL.Query().Get("run"), 10, 64)
|
|
|
|
|
if run < 0 {
|
|
|
|
|
run = 0
|
|
|
|
|
}
|
|
|
|
|
subnet := strings.TrimSpace(r.URL.Query().Get("subnet"))
|
|
|
|
|
if _, err := netip.ParsePrefix(subnet); err != nil {
|
|
|
|
|
subnet = ""
|
|
|
|
|
}
|
|
|
|
|
query := registryQuery{Q: q, LastResult: status, Run: run, Subnet: subnet, Limit: perPage, Offset: (page - 1) * perPage}
|
2026-10-01 19:31:11 +03:00
|
|
|
|
|
|
|
|
res, err := s.CA.ListRegistryPage(r.Context(), query)
|
|
|
|
|
if err == nil {
|
|
|
|
|
if clamped := clampPage(page, res.Total, perPage); clamped != page {
|
|
|
|
|
page = clamped
|
|
|
|
|
query.Offset = (page - 1) * perPage
|
|
|
|
|
res, err = s.CA.ListRegistryPage(r.Context(), query)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
params := url.Values{}
|
|
|
|
|
if q != "" {
|
|
|
|
|
params.Set("q", q)
|
|
|
|
|
}
|
|
|
|
|
if status != "" {
|
|
|
|
|
params.Set("status", status)
|
|
|
|
|
}
|
2026-10-03 18:36:03 +03:00
|
|
|
if run > 0 {
|
|
|
|
|
params.Set("run", strconv.FormatInt(run, 10))
|
|
|
|
|
}
|
|
|
|
|
if subnet != "" {
|
|
|
|
|
params.Set("subnet", subnet)
|
|
|
|
|
}
|
2026-09-23 11:58:53 +03:00
|
|
|
data := registryPageData{
|
2026-10-03 18:36:03 +03:00
|
|
|
Run: run,
|
|
|
|
|
Subnet: subnet,
|
2026-10-01 19:31:11 +03:00
|
|
|
Items: res.Items,
|
|
|
|
|
Query: q,
|
|
|
|
|
StatusFilter: status,
|
|
|
|
|
Page: page,
|
|
|
|
|
PerPage: perPage,
|
|
|
|
|
Total: res.Total,
|
|
|
|
|
Pager: newPager("/registry", "registry-table-wrap", params, page, perPage, res.Total),
|
|
|
|
|
PerPageOptions: perPageOptions,
|
2026-09-23 11:58:53 +03:00
|
|
|
}
|
2026-09-23 09:52:01 +03:00
|
|
|
data.ActiveNav = "registry"
|
|
|
|
|
data.Banner = bannerFor(err)
|
2026-10-01 11:35:24 +03:00
|
|
|
s.renderPage(w, r, "registry_page", data)
|
2026-09-23 09:52:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handleRegistryDetail shows one address's full retained check history
|
|
|
|
|
// across every cycle it has ever run, not just the current attempt — see
|
|
|
|
|
// ip_detail_content in ip_detail.html for the attempt-scoped equivalent.
|
|
|
|
|
func (s *Server) handleRegistryDetail(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
ip := r.PathValue("ip")
|
|
|
|
|
history, err := s.CA.GetRegistryHistory(r.Context(), ip)
|
|
|
|
|
data := registryDetailData{History: history}
|
|
|
|
|
data.ActiveNav = "registry"
|
|
|
|
|
data.Banner = bannerFor(err)
|
2026-10-01 11:35:24 +03:00
|
|
|
s.renderPage(w, r, "registry_detail_page", data)
|
2026-09-23 09:52:01 +03:00
|
|
|
}
|