feat(statuspages): error page linking a home page set by admins
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 6m52s
ci / test (pull_request) Successful in 15m30s
ci / build (pull_request) Successful in 16m56s
ci / image (pull_request) Successful in 6m1s

The bare status page domain and pages that do not exist answered with a
plain "404 page not found". They now show an error page with a button to
the platform's home page, which platform admins set under Admin. The
status page servers receive it with the page index and keep it across
restarts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-26 20:37:59 +01:00
1 parent af992409ef
commit 1f90fe8470
17 files changed
+902 -395

No files matched your search

+5
View File
@@ -318,6 +318,11 @@ var endpoints = []endpoint{
{method: "PUT", path: "/api/v1/admin/checker-network", tag: "Platform", summary: "Let platform checkers check private addresses or not",
description: "Unset, they may on self-hosted installations and may not in the cloud edition. Applies from each checker's next poll.",
perm: "platform admin", req: checkerNetwork{}, status: http.StatusNoContent},
{method: "GET", path: "/api/v1/admin/statuspage-home", tag: "Platform", summary: "The home page linked from the status page servers' error page", perm: "platform admin",
resp: statusPageHome{}},
{method: "PUT", path: "/api/v1/admin/statuspage-home", tag: "Platform", summary: "Set the home page linked from the status page servers' error page",
description: "Visitors of the bare status page domain and of pages that do not exist see an error page with a link to this URL. Empty links none.",
perm: "platform admin", req: statusPageHome{}, status: http.StatusNoContent},
{method: "GET", path: "/api/v1/admin/identity-providers", tag: "Platform", summary: "Identity providers for signing up and in",
description: "With the callback URL to register at each provider. Secrets are never returned.", perm: "platform admin",
resp: obj{"providers": []idpView{}, "callback_url": ""}},
+1
View File
@@ -111,6 +111,7 @@ var auditActions = map[string]string{
"PUT /api/v1/org/legal/:kind": "org.legal_update",
"PUT /api/v1/admin/check-types": "platform.check_types_update",
"PUT /api/v1/admin/checker-network": "platform.checker_network_update",
"PUT /api/v1/admin/statuspage-home": "platform.statuspage_home_update",
"PUT /api/v1/admin/limits": "platform.limits_update",
"POST /api/v1/admin/identity-providers": "platform.idp_create",
"PUT /api/v1/admin/identity-providers/:id": "platform.idp_update",
+1 -1
View File
@@ -625,7 +625,7 @@ func (s *Server) adminPage(c *gin.Context) {
for _, t := range check.Types {
types = append(types, web.CheckTypeOption{Type: string(t), Enabled: !off[string(t)]})
}
web.Render(c, http.StatusOK, web.AdminPage(s.pageFor(c, "admin.title"), me, v, storageView(c, stats), types, s.platformPrivate(ctx), webLimits(s.platformLimits(ctx)), s.idpAdminView(ctx)))
web.Render(c, http.StatusOK, web.AdminPage(s.pageFor(c, "admin.title"), me, v, storageView(c, stats), types, s.platformPrivate(ctx), s.statusPageHome(ctx), webLimits(s.platformLimits(ctx)), s.idpAdminView(ctx)))
}
func (s *Server) adminStatusPagesPage(c *gin.Context) {
+5
View File
@@ -56,6 +56,8 @@ type Server struct {
limits *versioned[Limits]
// support caches how the platform runs support tickets.
support *versioned[supportSettings]
// pageHome caches the home page the status page servers link.
pageHome *versioned[string]
// draining, once closed, ends the long polls of checkers.
draining <-chan struct{}
// handler serves the requests agents send over their streams.
@@ -99,6 +101,7 @@ func New(cfg config.API, d Deps) *Server {
checkerNet: newVersioned[bool]("checker-network"),
limits: newVersioned[Limits]("limits"),
support: newVersioned[supportSettings]("support"),
pageHome: newVersioned[string]("statuspage-home"),
}
}
@@ -224,6 +227,8 @@ func (s *Server) Mount(r gin.IRouter) {
admin.PUT("/users/:id/suspension", s.adminSuspendUser)
admin.DELETE("/users/:id", s.adminDeleteUser)
admin.PUT("/checker-network", s.adminSetCheckerNetwork)
admin.GET("/statuspage-home", s.adminGetStatusPageHome)
admin.PUT("/statuspage-home", s.adminSetStatusPageHome)
admin.GET("/legal", s.adminListLegal)
admin.PUT("/legal/:kind", s.adminSaveLegal)
admin.GET("/regions", s.adminListRegions)
+77
View File
@@ -0,0 +1,77 @@
package api
import (
"context"
"encoding/json"
"errors"
"net/http"
"strings"
"github.com/gin-gonic/gin"
"github.com/jackc/pgx/v5"
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
"git.zb-server.de/ZB-Server/uptimesebi/internal/tenant"
)
// The status page servers answer visitors of pages that do not exist, and
// of their bare domain, with a page linking the platform's home page.
const settingStatusPageHome = "statuspage_home"
type statusPageHome struct {
// URL is the home page linked from the status page servers' error
// page; empty links none.
URL string `json:"url" binding:"max=2000"`
}
func (s *Server) statusPageHome(ctx context.Context) string {
v, err := s.pageHome.get(ctx, s.rdb, func(ctx context.Context) (string, error) {
var v statusPageHome
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
raw, err := q.GetPlatformSetting(ctx, settingStatusPageHome)
if errors.Is(err, pgx.ErrNoRows) {
return nil
}
if err != nil {
return err
}
return json.Unmarshal(raw, &v)
})
return v.URL, err
})
if err != nil {
s.log.WarnContext(ctx, "loading the status page home failed", "error", err)
return ""
}
return v
}
func (s *Server) adminGetStatusPageHome(c *gin.Context) {
c.JSON(http.StatusOK, statusPageHome{URL: s.statusPageHome(c.Request.Context())})
}
func (s *Server) adminSetStatusPageHome(c *gin.Context) {
var req statusPageHome
if !bind(c, &req) {
return
}
req.URL = strings.TrimSpace(req.URL)
if req.URL != "" && !validLegalURL(req.URL) {
fail(c, http.StatusUnprocessableEntity, "invalid_legal_url")
return
}
ctx := c.Request.Context()
raw, _ := json.Marshal(req)
auditDetail(c, "url", req.URL)
if err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
return q.SetPlatformSetting(ctx, store.SetPlatformSettingParams{Key: settingStatusPageHome, Value: raw})
}); err != nil {
internalError(c, err)
return
}
if err := s.pageHome.bump(ctx, s.rdb); err != nil {
s.log.ErrorContext(ctx, "announcing the status page home failed", "error", err)
}
c.Status(http.StatusNoContent)
}
+46
View File
@@ -0,0 +1,46 @@
package api_test
import (
"context"
"net/http"
"strings"
"testing"
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
"git.zb-server.de/ZB-Server/uptimesebi/internal/tenant"
)
func TestStatusPageHome(t *testing.T) {
e := newEnv(t)
admin := e.browser(t)
admin.signup("a@"+uniq("home")+".test", uniq("home-"))
if err := tenant.New(e.dbPool).Tx(context.Background(), tenant.Global(), func(q *store.Queries) error {
return q.MakeAdmin(context.Background(), admin.userIDSelf())
}); err != nil {
t.Fatal(err)
}
t.Cleanup(func() { admin.do("PUT", "/api/v1/admin/statuspage-home", map[string]any{"url": ""}) })
pages := e.statuspageClient(t, nil)
st, body := admin.do("PUT", "/api/v1/admin/statuspage-home", map[string]any{"url": "javascript:alert(1)"})
expect(t, "script link", st, body, http.StatusUnprocessableEntity, "invalid_legal_url")
if st, body := admin.do("PUT", "/api/v1/admin/statuspage-home", map[string]any{"url": " https://example.test/ "}); st != http.StatusNoContent {
t.Fatalf("set home = %d %v", st, body)
}
if _, body := admin.do("GET", "/api/v1/admin/statuspage-home", nil); body["url"] != "https://example.test/" {
t.Errorf("home = %v", body)
}
index, err := pages.Pages(context.Background())
if err != nil || index.HomeURL != "https://example.test/" {
t.Errorf("page index home = %q %v", index.HomeURL, err)
}
if _, _, html := admin.page("/admin"); !strings.Contains(html, `value="https://example.test/"`) {
t.Error("the admin page does not show the home page")
}
owner := e.browser(t)
owner.signup("o@"+uniq("home")+".test", uniq("home-"))
if st, _ := owner.do("PUT", "/api/v1/admin/statuspage-home", map[string]any{"url": "https://evil.test/"}); st != http.StatusForbidden {
t.Errorf("non-admin sets the home page = %d, want 403", st)
}
}
+1 -1
View File
@@ -461,7 +461,7 @@ func (s *Server) agentPageIndex(c *gin.Context) {
for i, r := range rows {
out[i] = agentapi.PageRef{Slug: r.Slug, Host: r.Host}
}
c.JSON(http.StatusOK, gin.H{"pages": out})
c.JSON(http.StatusOK, agentapi.PageIndex{Pages: out, HomeURL: s.statusPageHome(ctx)})
}
type statusPageRequest struct {
+2 -1
View File
@@ -205,7 +205,8 @@ func TestStatusPages(t *testing.T) {
own := e.statuspageClient(t, &org)
lists := func(c *agentapi.Client) bool {
t.Helper()
refs, err := c.Pages(context.Background())
index, err := c.Pages(context.Background())
refs := index.Pages
if err != nil {
t.Fatal(err)
}