diff --git a/cmd/api/main.go b/cmd/api/main.go index f178a84..f7cc2ed 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -93,6 +93,7 @@ func run(log *slog.Logger, level *slog.LevelVar, args []string) error { go srv.RunNotifier(ctx) go srv.RunHousekeeping(ctx) go srv.RunRegionWatch(ctx) + go srv.RunDomainWatch(ctx) go srv.RunHeartbeats(ctx) return platform.Serve(ctx, log, platform.NewHTTPServer(cfg.Listen, r), health, 5*time.Second, cfg.ShutdownTimeout) diff --git a/internal/api/certificates_test.go b/internal/api/certificates_test.go index 6d03d35..afa9ff5 100644 --- a/internal/api/certificates_test.go +++ b/internal/api/certificates_test.go @@ -49,7 +49,7 @@ func TestCertificateOrdersAreLimited(t *testing.T) { // The editor explains the records, with the platform's servers as the // CNAME target. _, _, html := owner.page("/statuspages/" + id1) - for _, want := range []string{"Prove the domain is yours", "status.platform.test.", "ALIAS or ANAME", "at most 10 times a day"} { + for _, want := range []string{"Create this CNAME record", ".status.platform.test.", "Prove the domain with this TXT record", "ALIAS or ANAME", "at most 10 times a day"} { if !strings.Contains(html, want) { t.Errorf("the editor lacks %q", want) } diff --git a/internal/api/console.go b/internal/api/console.go index 8a2b70e..aefd208 100644 --- a/internal/api/console.go +++ b/internal/api/console.go @@ -1142,7 +1142,7 @@ func (s *Server) statusPageEditor(c *gin.Context, p *principal, page web.Page, m if err != nil { return nil, err } - v := viewStatusPage(row) + v := s.viewStatusPage(row) e := web.PageEditor{ ID: row.ID.String(), Title: row.Title, Slug: row.Slug, Description: row.Description, Published: row.Published, ShowDetails: row.ShowComponentDetails, @@ -1155,8 +1155,13 @@ func (s *Server) statusPageEditor(c *gin.Context, p *principal, page web.Page, m e.RecordName, e.RecordValue = v.DomainRecord.Name, v.DomainRecord.Value } e.DomainChangesPerDay = domainChangesPerDay - if !own { - e.CNAMETarget = s.cnameTarget() + if v.CNAMERecord != nil { + e.CNAMEValue = v.CNAMERecord.Value + } + e.VerifiedBy = deref(row.DomainVerifyMethod) + if f := row.DomainFailingSince; f != nil { + e.MissingSince = f.Local().Format("2006-01-02 15:04") + e.SwitchOffAt = f.Add(domainGrace).Local().Format("2006-01-02 15:04") } newPageGroupTree(pageGroups).walk(func(g store.StatusPageGroup, depth int) { var parentID string diff --git a/internal/api/domains.go b/internal/api/domains.go new file mode 100644 index 0000000..47f213d --- /dev/null +++ b/internal/api/domains.go @@ -0,0 +1,176 @@ +package api + +import ( + "context" + "crypto/sha256" + "encoding/base32" + "net" + "slices" + "strings" + "time" + + "github.com/google/uuid" + + "git.zb-server.de/ZB-Server/uptimesebi/internal/notify" + "git.zb-server.de/ZB-Server/uptimesebi/internal/store" + "git.zb-server.de/ZB-Server/uptimesebi/internal/tenant" +) + +// A custom domain proves it belongs to its page in one of two ways: +// +// - a CNAME to