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
78 lines
2.1 KiB
Go
78 lines
2.1 KiB
Go
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)
|
|
}
|