diff --git a/go.mod b/go.mod index e9df13b..dfa1bcf 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/pquerna/otp v1.5.0 github.com/pressly/goose/v3 v3.30.1 github.com/redis/go-redis/v9 v9.23.0 + github.com/yuin/goldmark v1.7.13 go.uber.org/zap v1.28.0 golang.org/x/crypto v0.59.0 golang.org/x/net v0.63.0 diff --git a/go.sum b/go.sum index 4c4b8e9..ab7f07d 100644 --- a/go.sum +++ b/go.sum @@ -146,6 +146,8 @@ github.com/ugorji/go/codec v1.3.1 h1:waO7eEiFDwidsBN6agj1vJQ4AG7lh2yqXyOXqhgQuyY github.com/ugorji/go/codec v1.3.1/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4= github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU= github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E= +github.com/yuin/goldmark v1.7.13 h1:GPddIs617DnBLFFVJFgpo1aBfe/4xcvMc3SB5t/D0pA= +github.com/yuin/goldmark v1.7.13/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg= github.com/zeebo/assert v1.1.0 h1:hU1L1vLTHsnO8x8c9KAR5GmM5QscxHg5RNU5z5qbUWY= github.com/zeebo/assert v1.1.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0= github.com/zeebo/blake3 v0.2.4 h1:KYQPkhpRtcqh0ssGYcKLG1JYvddkEA8QwCM/yBqhaZI= diff --git a/internal/agentapi/pages.go b/internal/agentapi/pages.go index b74ec44..e71cb3e 100644 --- a/internal/agentapi/pages.go +++ b/internal/agentapi/pages.go @@ -63,6 +63,28 @@ type PageSnapshot struct { Sections []Section `json:"sections"` Incidents []PageIncident `json:"incidents"` GeneratedAt time.Time `json:"generated_at"` + // Legal holds the legal notice and privacy policy shown on the page. + // They travel with the snapshot so they stay available during an API + // outage, which some jurisdictions require. + Legal []LegalDoc `json:"legal,omitempty"` +} + +// LegalDoc is a legal notice ("imprint") or privacy policy ("privacy"): +// a link to a page elsewhere or Markdown to render. +type LegalDoc struct { + Kind string `json:"kind"` + URL string `json:"url,omitempty"` + Markdown string `json:"markdown,omitempty"` +} + +// LegalDocByKind returns the document of kind, if any. +func (s PageSnapshot) LegalDocByKind(kind string) (LegalDoc, bool) { + for _, d := range s.Legal { + if d.Kind == kind { + return d, true + } + } + return LegalDoc{}, false } // ErrNotFound means no published page matches. diff --git a/internal/api/audit.go b/internal/api/audit.go index 887f0fb..c59fe9d 100644 --- a/internal/api/audit.go +++ b/internal/api/audit.go @@ -76,6 +76,8 @@ var auditActions = map[string]string{ "POST /api/v1/org/tokens": "token.create", "DELETE /api/v1/org/tokens/:id": "token.delete", + "PUT /api/v1/admin/legal/:kind": "platform.legal_update", + "PUT /api/v1/org/legal/:kind": "org.legal_update", "POST /api/v1/admin/regions": "platform.region_create", "DELETE /api/v1/admin/regions/:id": "platform.region_delete", "POST /api/v1/admin/agents": "platform.agent_create", @@ -131,7 +133,7 @@ func (w *captureWriter) Write(b []byte) (int, error) { // Response fields worth keeping; anything else may be a secret, such as a // freshly created token. -var auditFields = []string{"name", "key", "slug", "email", "type", "target", "domain"} +var auditFields = []string{"name", "key", "slug", "email", "type", "target", "domain", "kind"} // audit records state-changing requests after they ran. func (s *Server) audit() gin.HandlerFunc { @@ -170,6 +172,10 @@ func (s *Server) audit() gin.HandlerFunc { } } } + if status < 400 && strings.HasPrefix(action, "auth.") { + // The address only identifies attempts on unknown accounts. + delete(details, "email") + } for _, param := range []string{"id", "user"} { if id, err := uuid.Parse(c.Param(param)); err == nil { e.TargetID = &id diff --git a/internal/api/legal.go b/internal/api/legal.go new file mode 100644 index 0000000..c3d64b3 --- /dev/null +++ b/internal/api/legal.go @@ -0,0 +1,210 @@ +package api + +import ( + "context" + "net/http" + "net/url" + "slices" + "strings" + + "github.com/a-h/templ" + "github.com/gin-gonic/gin" + "github.com/google/uuid" + + "git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi" + "git.zb-server.de/ZB-Server/uptimesebi/internal/store" + "git.zb-server.de/ZB-Server/uptimesebi/internal/tenant" + "git.zb-server.de/ZB-Server/uptimesebi/internal/web" +) + +// mergeLegal picks one document per kind, the organization's over the +// platform's. rows come organization first. +func mergeLegal(rows []store.LegalDocument) []agentapi.LegalDoc { + out := []agentapi.LegalDoc{} + seen := map[string]bool{} + for _, r := range rows { + if seen[r.Kind] || (r.Url == "" && r.Markdown == "") { + continue + } + seen[r.Kind] = true + out = append(out, agentapi.LegalDoc{Kind: r.Kind, URL: r.Url, Markdown: r.Markdown}) + } + return out +} + +// platformLegalDocs returns the platform's documents, which every console +// page links in its footer. +func (s *Server) platformLegalDocs(ctx context.Context) []agentapi.LegalDoc { + docs, err := s.legal.get(ctx, s.rdb, func(ctx context.Context) ([]agentapi.LegalDoc, error) { + var rows []store.LegalDocument + err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error { + var err error + rows, err = q.LegalDocuments(ctx, nil) + return err + }) + return mergeLegal(rows), err + }) + if err != nil { + s.log.WarnContext(ctx, "loading legal documents failed", "error", err) + } + return docs +} + +func validLegalKind(kind string) bool { return slices.Contains(web.LegalKinds, kind) } + +type legalRequest struct { + URL string `json:"url" binding:"max=2000"` + Markdown string `json:"markdown" binding:"max=100000"` +} + +// validLegalURL accepts absolute http and https URLs only, so a stored link +// cannot run script when clicked. +func validLegalURL(raw string) bool { + u, err := url.Parse(raw) + return err == nil && (u.Scheme == "https" || u.Scheme == "http") && u.Host != "" +} + +// saveLegal stores or, with both fields empty, removes a document of org, +// nil for the platform. +func (s *Server) saveLegal(c *gin.Context, scope tenant.Scope, org *uuid.UUID) bool { + kind := c.Param("kind") + if !validLegalKind(kind) { + fail(c, http.StatusNotFound, "not_found") + return false + } + var req legalRequest + if !bind(c, &req) { + return false + } + req.URL, req.Markdown = strings.TrimSpace(req.URL), strings.TrimSpace(req.Markdown) + if req.URL != "" && !validLegalURL(req.URL) { + fail(c, http.StatusUnprocessableEntity, "invalid_legal_url") + return false + } + auditDetail(c, "kind", kind) + ctx := c.Request.Context() + err := s.db.Tx(ctx, scope, func(q *store.Queries) error { + if req.URL == "" && req.Markdown == "" { + return q.DeleteLegalDocument(ctx, store.DeleteLegalDocumentParams{OrgID: org, Kind: kind}) + } + return q.UpsertLegalDocument(ctx, store.UpsertLegalDocumentParams{OrgID: org, Kind: kind, Url: req.URL, Markdown: req.Markdown}) + }) + if err != nil { + internalError(c, err) + return false + } + c.Status(http.StatusNoContent) + return true +} + +func (s *Server) adminSaveLegal(c *gin.Context) { + if s.saveLegal(c, tenant.System(), nil) { + if err := s.legal.bump(c.Request.Context(), s.rdb); err != nil { + s.log.ErrorContext(c.Request.Context(), "announcing legal document change failed", "error", err) + } + } +} + +func (s *Server) orgSaveLegal(c *gin.Context) { + p := current(c) + s.saveLegal(c, p.scope(), &p.Org.ID) +} + +type legalView struct { + Kind string `json:"kind"` + URL string `json:"url"` + Markdown string `json:"markdown"` +} + +// ownLegal returns the documents stored for org (nil: the platform), +// without fallbacks. +func (s *Server) ownLegal(ctx context.Context, scope tenant.Scope, org *uuid.UUID) ([]legalView, error) { + var rows []store.LegalDocument + err := s.db.Tx(ctx, scope, func(q *store.Queries) error { + var err error + rows, err = q.LegalDocuments(ctx, org) + return err + }) + out := make([]legalView, 0, len(web.LegalKinds)) + for _, kind := range web.LegalKinds { + v := legalView{Kind: kind} + for _, r := range rows { + if r.Kind == kind && (r.OrgID == nil) == (org == nil) { + v.URL, v.Markdown = r.Url, r.Markdown + } + } + out = append(out, v) + } + return out, err +} + +func (s *Server) adminListLegal(c *gin.Context) { + docs, err := s.ownLegal(c.Request.Context(), tenant.System(), nil) + if err != nil { + internalError(c, err) + return + } + c.JSON(http.StatusOK, gin.H{"documents": docs}) +} + +func (s *Server) orgListLegal(c *gin.Context) { + p := current(c) + docs, err := s.ownLegal(c.Request.Context(), p.scope(), &p.Org.ID) + if err != nil { + internalError(c, err) + return + } + c.JSON(http.StatusOK, gin.H{"documents": docs}) +} + +// legalPage serves a platform document to anyone: Markdown rendered here, +// links redirected. +func (s *Server) legalPage(c *gin.Context) { + kind := c.Param("kind") + for _, d := range s.platformLegalDocs(c.Request.Context()) { + if d.Kind != kind { + continue + } + if d.URL != "" { + c.Redirect(http.StatusFound, d.URL) + return + } + html, err := web.RenderMarkdown(d.Markdown) + if err != nil { + internalError(c, err) + return + } + web.Render(c, http.StatusOK, web.LegalPage(s.pageFor(c, web.LegalTitleID(kind)), html)) + return + } + c.Status(http.StatusNotFound) +} + +func toLegalForms(docs []legalView) []web.LegalForm { + out := make([]web.LegalForm, len(docs)) + for i, d := range docs { + out[i] = web.LegalForm{Kind: d.Kind, URL: d.URL, Markdown: d.Markdown} + } + return out +} + +func (s *Server) orgLegalView(c *gin.Context, p *principal, page web.Page, me web.Me) (templ.Component, error) { + docs, err := s.ownLegal(c.Request.Context(), p.scope(), &p.Org.ID) + if err != nil { + return nil, err + } + return web.LegalSettingsPage(page, me, "legal.org_title", "legal.org_intro", "/org/legal/", "/settings/legal", toLegalForms(docs)), nil +} + +func (s *Server) adminLegalPage(c *gin.Context) { + me, ok := s.adminMe(c) + if !ok { + return + } + docs, err := s.ownLegal(c.Request.Context(), tenant.System(), nil) + if err != nil { + internalError(c, err) + return + } + web.Render(c, http.StatusOK, web.LegalSettingsPage(s.pageFor(c, "legal.platform_title"), me, "legal.platform_title", "legal.platform_intro", "/admin/legal/", "/admin/legal", toLegalForms(docs))) +} diff --git a/internal/api/legal_test.go b/internal/api/legal_test.go new file mode 100644 index 0000000..1a37075 --- /dev/null +++ b/internal/api/legal_test.go @@ -0,0 +1,128 @@ +package api_test + +import ( + "context" + "net/http" + "strings" + "testing" + + "git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi" + "git.zb-server.de/ZB-Server/uptimesebi/internal/store" + "git.zb-server.de/ZB-Server/uptimesebi/internal/tenant" +) + +func TestLegalDocuments(t *testing.T) { + e := newEnv(t) + admin := e.browser(t) + admin.signup("a@"+uniq("lg")+".test", uniq("lg-")) + err := tenant.New(e.dbPool).Tx(context.Background(), tenant.Global(), func(q *store.Queries) error { + return q.MakeAdmin(context.Background(), admin.userIDSelf()) + }) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { + for _, kind := range []string{"imprint", "privacy"} { + admin.do("PUT", "/api/v1/admin/legal/"+kind, map[string]any{}) + } + }) + + imprint := "# Impressum\n\nBetreiber GmbH " + st, body := admin.do("PUT", "/api/v1/admin/legal/imprint", map[string]any{"markdown": imprint}) + expect(t, "admin sets imprint", st, body, http.StatusNoContent, "") + st, body = admin.do("PUT", "/api/v1/admin/legal/privacy", map[string]any{"url": "javascript:alert(1)"}) + expect(t, "javascript link", st, body, http.StatusUnprocessableEntity, "invalid_legal_url") + st, body = admin.do("PUT", "/api/v1/admin/legal/privacy", map[string]any{"url": "https://operator.example/privacy"}) + expect(t, "admin sets privacy link", st, body, http.StatusNoContent, "") + st, body = admin.do("PUT", "/api/v1/admin/legal/terms", map[string]any{"markdown": "x"}) + expect(t, "unknown kind", st, body, http.StatusNotFound, "not_found") + + // The console footer links them, also before signing in. + _, _, login := e.browser(t).page("/login") + if !strings.Contains(login, `href="/legal/imprint"`) || !strings.Contains(login, `href="https://operator.example/privacy"`) { + t.Error("login page footer lacks the legal links") + } + st, _, html := e.browser(t).page("/legal/imprint") + if st != http.StatusOK || !strings.Contains(html, "

Impressum

") || strings.Contains(html, " [x](javascript:alert(1))"}, + {Kind: "privacy", URL: "https://acme.example/privacy"}, + } + src.pages["|acme"] = agentapi.PageSnapshot{Title: "Acme status", Status: agentapi.PageOperational, Legal: legal} + src.pages["status.acme.test|"] = agentapi.PageSnapshot{Title: "Acme on own domain", Status: agentapi.PageOperational, Legal: legal} + h := newHarness(t, src, t.TempDir(), &now) + + _, page := h.get("status.example.test", "/acme") + if !strings.Contains(page, `href="/acme/imprint"`) || !strings.Contains(page, `href="https://acme.example/privacy"`) { + t.Error("status page does not link its legal documents") + } + if _, page := h.get("status.acme.test", "/"); !strings.Contains(page, `href="/imprint"`) { + t.Error("custom domain page does not link /imprint") + } + + // The API goes away; the documents stay reachable from the cache. + src.mu.Lock() + src.err = errors.New("connection refused") + src.mu.Unlock() + now = now.Add(time.Hour) + + for _, tc := range []struct{ host, path string }{{"status.example.test", "/acme/imprint"}, {"status.acme.test", "/imprint"}} { + code, body := h.get(tc.host, tc.path) + if code != http.StatusOK || !strings.Contains(body, "

Impressum

") || !strings.Contains(body, "Acme GmbH") { + t.Errorf("GET %s%s = %d, lacks the rendered imprint", tc.host, tc.path, code) + } + if strings.Contains(body, " - - { children... } + +
+ { children... } +
+ @legalFooter(p.Legal) } diff --git a/internal/web/layout_templ.go b/internal/web/layout_templ.go index 112f0f7..59b46b0 100644 --- a/internal/web/layout_templ.go +++ b/internal/web/layout_templ.go @@ -20,6 +20,8 @@ type Page struct { // typically after a redirect back from an SSO flow. ErrorID string NoticeID string + // Legal links the platform's legal notice and privacy policy. + Legal []LegalLink } func Layout(p Page) templ.Component { @@ -47,7 +49,7 @@ func Layout(p Page) templ.Component { var templ_7745c5c3_Var2 string templ_7745c5c3_Var2, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.Lang(ctx)).Resolve(ctx) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 18, Col: 28} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 20, Col: 28} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var2) if templ_7745c5c3_Err != nil { @@ -65,7 +67,7 @@ func Layout(p Page) templ.Component { var templ_7745c5c3_Var3 string templ_7745c5c3_Var3, templ_7745c5c3_Err = templruntime.NewAttributeExpression(p.CSRF).Resolve(ctx) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 23, Col: 44} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 25, Col: 44} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var3) if templ_7745c5c3_Err != nil { @@ -83,26 +85,26 @@ func Layout(p Page) templ.Component { var templ_7745c5c3_Var4 string templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, p.TitleID)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 25, Col: 34} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 27, Col: 34} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, " · uptimesebi") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "\">
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -110,7 +112,15 @@ func Layout(p Page) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = legalFooter(p.Legal).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -135,76 +145,76 @@ func languageSwitch(langs []string) templ.Component { } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } for _, l := range langs { if l == i18n.Lang(ctx) { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var7 string templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(l) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 40, Col: 50} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 45, Col: 50} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } else { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -242,7 +252,7 @@ func authShell(p Page) templ.Component { }() } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "

uptimesebi

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "

uptimesebi

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -250,20 +260,20 @@ func authShell(p Page) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var13 string templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, p.TitleID)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 55, Col: 66} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 60, Col: 66} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -275,7 +285,7 @@ func authShell(p Page) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -306,69 +316,69 @@ func field(label, name, typ, autocomplete string, required bool) templ.Component } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -393,20 +403,20 @@ func submit(label string) templ.Component { } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -432,39 +442,39 @@ func flash(p Page) templ.Component { ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) if p.ErrorID != "" { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var22 string templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, p.ErrorID)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 83, Col: 88} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 88, Col: 88} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } if p.NoticeID != "" { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var23 string templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, p.NoticeID)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 86, Col: 77} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 91, Col: 77} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -490,7 +500,7 @@ func formError() templ.Component { } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/internal/web/legal.go b/internal/web/legal.go new file mode 100644 index 0000000..af09305 --- /dev/null +++ b/internal/web/legal.go @@ -0,0 +1,61 @@ +package web + +import ( + "bytes" + + "github.com/yuin/goldmark" + "github.com/yuin/goldmark/extension" + + "git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi" +) + +// LegalKinds are the legal documents, in footer order. +var LegalKinds = []string{"imprint", "privacy"} + +// LegalTitleID names the catalog message of a document kind. +func LegalTitleID(kind string) string { return "legal." + kind } + +// LegalLink points to a legal document, ours or elsewhere. +type LegalLink struct { + Kind string + Href string + External bool +} + +// markdown renders untrusted input: goldmark drops raw HTML and links with +// dangerous schemes such as javascript: unless told otherwise. +var markdown = goldmark.New(goldmark.WithExtensions(extension.Table, extension.Linkify, extension.Strikethrough)) + +// RenderMarkdown converts src to HTML that is safe to embed. +func RenderMarkdown(src string) (string, error) { + var buf bytes.Buffer + if err := markdown.Convert([]byte(src), &buf); err != nil { + return "", err + } + return buf.String(), nil +} + +// LegalLinks turns documents into links: external URLs as they are, +// Markdown documents to base+kind. +func LegalLinks(docs []agentapi.LegalDoc, base string) []LegalLink { + var out []LegalLink + for _, kind := range LegalKinds { + for _, d := range docs { + if d.Kind != kind { + continue + } + switch { + case d.URL != "": + out = append(out, LegalLink{Kind: kind, Href: d.URL, External: true}) + case d.Markdown != "" && base != "": + out = append(out, LegalLink{Kind: kind, Href: base + kind}) + } + } + } + return out +} + +// PageLegalLinks returns the legal links of a status page. +func PageLegalLinks(s agentapi.PageSnapshot, base string) []LegalLink { + return LegalLinks(s.Legal, base) +} diff --git a/internal/web/legal.templ b/internal/web/legal.templ new file mode 100644 index 0000000..e865cd9 --- /dev/null +++ b/internal/web/legal.templ @@ -0,0 +1,92 @@ +package web + +import ( + "git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi" + "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n" +) + +templ legalLink(l LegalLink) { + if l.External { + { i18n.T(ctx, LegalTitleID(l.Kind)) } + } else { + { i18n.T(ctx, LegalTitleID(l.Kind)) } + } +} + +templ legalFooter(links []LegalLink) { + if len(links) > 0 { + + } +} + +templ legalBody(html string) { + +} + +// LegalPage shows a platform legal document. +templ LegalPage(p Page, html string) { + @Layout(p) { +
+

uptimesebi

+ @legalBody(html) +
+ } +} + +// PublicLegalPage shows a legal document of a status page. +templ PublicLegalPage(s agentapi.PageSnapshot, a PublicAssets, kind, html, back string) { + + + + + + { i18n.T(ctx, LegalTitleID(kind)) } · { s.Title } + + + +
+

{ "← " + s.Title }

+ @legalBody(html) +
+ + +} + +// LegalForm is the stored state of one legal document. +type LegalForm struct { + Kind string + URL string + Markdown string +} + +// LegalSettingsPage edits legal documents. apiBase plus the kind is the +// endpoint each form saves to. +templ LegalSettingsPage(p Page, me Me, titleID, introID, apiBase, next string, docs []LegalForm) { + @consoleShell(p, me) { + @settingsHeading(titleID, introID) + for _, d := range docs { +
+ @sectionHeading(LegalTitleID(d.Kind)) +
+ @formError() + + +

{ i18n.T(ctx, "legal.hint") }

+ @submit(i18n.T(ctx, "common.save")) +
+
+ } + } +} diff --git a/internal/web/legal_templ.go b/internal/web/legal_templ.go new file mode 100644 index 0000000..1f79440 --- /dev/null +++ b/internal/web/legal_templ.go @@ -0,0 +1,508 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.3.1118 + +package web + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import templruntime "github.com/a-h/templ/runtime" + +import ( + "git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi" + "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n" +) + +func legalLink(l LegalLink) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + if l.External { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var3 string + templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, LegalTitleID(l.Kind))) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/legal.templ`, Line: 10, Col: 109} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var5 string + templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, LegalTitleID(l.Kind))) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/legal.templ`, Line: 12, Col: 94} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + return nil + }) +} + +func legalFooter(links []LegalLink) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + if len(links) > 0 { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + return nil + }) +} + +func legalBody(html string) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.Raw(html).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +// LegalPage shows a platform legal document. +func LegalPage(p Page, html string) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Var9 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "

uptimesebi

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = legalBody(html).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) + templ_7745c5c3_Err = Layout(p).Render(templ.WithChildren(ctx, templ_7745c5c3_Var9), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +// PublicLegalPage shows a legal document of a status page. +func PublicLegalPage(s agentapi.PageSnapshot, a PublicAssets, kind, html, back string) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var12 string + templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, LegalTitleID(kind))) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/legal.templ`, Line: 49, Col: 43} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, " · ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var13 string + templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(s.Title) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/legal.templ`, Line: 49, Col: 58} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var16 string + templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs("← " + s.Title) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/legal.templ`, Line: 54, Col: 113} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = legalBody(html).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +// LegalForm is the stored state of one legal document. +type LegalForm struct { + Kind string + URL string + Markdown string +} + +// LegalSettingsPage edits legal documents. apiBase plus the kind is the +// endpoint each form saves to. +func LegalSettingsPage(p Page, me Me, titleID, introID, apiBase, next string, docs []LegalForm) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Var18 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Err = settingsHeading(titleID, introID).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, d := range docs { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = sectionHeading(LegalTitleID(d.Kind)).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = formError().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var25 string + templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "legal.hint")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/legal.templ`, Line: 86, Col: 67} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = submit(i18n.T(ctx, "common.save")).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + return nil + }) + templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var18), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +var _ = templruntime.GeneratedTemplate diff --git a/internal/web/public.go b/internal/web/public.go index 16f6566..a6789ed 100644 --- a/internal/web/public.go +++ b/internal/web/public.go @@ -15,6 +15,10 @@ type PublicAssets struct { // StaleSince, if set, tells visitors that live updates are unavailable // and the page shows the state of that moment. StaleSince time.Time + // LegalBase prefixes links to legal documents served as Markdown, e.g. + // "/acme/" or "/" on a custom domain. Empty leaves them out, as in a + // single-file export, which can only link elsewhere. + LegalBase string } // StylesheetText returns the built stylesheet for inlining. diff --git a/internal/web/public.templ b/internal/web/public.templ index 0a2b33d..a4a5066 100644 --- a/internal/web/public.templ +++ b/internal/web/public.templ @@ -104,7 +104,12 @@ templ PublicStatusPage(s agentapi.PageSnapshot, a PublicAssets) { diff --git a/internal/web/public_templ.go b/internal/web/public_templ.go index 350b8c9..4ca5964 100644 --- a/internal/web/public_templ.go +++ b/internal/web/public_templ.go @@ -525,7 +525,17 @@ func PublicStatusPage(s agentapi.PageSnapshot, a PublicAssets) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, " uptimesebi") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, l := range PageLegalLinks(s, a.LegalBase) { + templ_7745c5c3_Err = legalLink(l).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 53, "uptimesebi") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/internal/web/regions.templ b/internal/web/regions.templ index c9cac96..9fc1d9b 100644 --- a/internal/web/regions.templ +++ b/internal/web/regions.templ @@ -146,7 +146,10 @@ templ RegionsPage(p Page, me Me, v RegionsView) { templ AdminPage(p Page, me Me, v RegionsView, storage StorageView) { @consoleShell(p, me) { @settingsHeading("admin.title", "admin.intro") -

{ i18n.T(ctx, "audit.platform_title") }

+

+ { i18n.T(ctx, "audit.platform_title") } + { i18n.T(ctx, "legal.platform_title") } +

@regionsBody(v) @storageSection(storage) } diff --git a/internal/web/regions_templ.go b/internal/web/regions_templ.go index ef3abed..3e2f813 100644 --- a/internal/web/regions_templ.go +++ b/internal/web/regions_templ.go @@ -729,20 +729,33 @@ func AdminPage(p Page, me Me, v RegionsView, storage StorageView) templ.Componen if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 55, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 55, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var39 string templ_7745c5c3_Var39, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "audit.platform_title")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 149, Col: 129} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 150, Col: 100} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var39)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 56, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 56, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var40 string + templ_7745c5c3_Var40, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "legal.platform_title")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 151, Col: 100} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var40)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 57, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err }