ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 7m28s
ci / test (pull_request) Successful in 12m52s
ci / build (pull_request) Successful in 11m21s
ci / image (pull_request) Successful in 4m38s
A custom domain now needs a single record: a CNAME to <label>.<status page host>, where the label is derived from the page's domain token. The wildcard record of the status page host routes it, and since the target belongs to one page alone it also proves who set it up; a CNAME to the shared host would not, as any organization could then claim a domain pointing at the platform. The TXT record stays for domains whose CNAME cannot be seen, behind a proxy or without a subdomain. - The domain watch looks for the records of a new domain every minute for a quarter of an hour, then every ten minutes for two days, and verifies it on its own; "Check now" still works. - Verified domains are checked daily. When the record is gone the owners are told, and a week later the domain is switched off, so a record left behind cannot be taken over. Domains verified before keep working without checks. - The editor shows the CNAME record first, the TXT way for proxies and apex domains, how the domain was verified and when a missing record will switch it off. The API returns cname_record and domain_missing_since. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
372 lines
15 KiB
Templ
372 lines
15 KiB
Templ
package web
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
|
)
|
|
|
|
// PageRow is a status page in the list.
|
|
type PageRow struct {
|
|
ID string
|
|
Title string
|
|
Slug string
|
|
Published bool
|
|
URL string
|
|
Domain string
|
|
Suspended bool
|
|
}
|
|
|
|
// PagesView is the data of the status page list.
|
|
type PagesView struct {
|
|
Pages []PageRow
|
|
CanWrite bool
|
|
}
|
|
|
|
templ StatusPagesPage(p Page, me Me, v PagesView) {
|
|
@consoleShell(p, me) {
|
|
@settingsHeading("pages.title", "pages.intro")
|
|
if len(v.Pages) > 0 {
|
|
<ul class="mb-12 divide-y divide-rule border-y border-rule text-sm">
|
|
for _, pg := range v.Pages {
|
|
<li class="flex flex-wrap items-center gap-x-4 gap-y-1 py-2.5">
|
|
if pg.Suspended {
|
|
@statusDot(StatusDown)
|
|
} else if pg.Published {
|
|
@statusDot(StatusUp)
|
|
} else {
|
|
@statusDot(StatusPaused)
|
|
}
|
|
<a href={ templ.SafeURL("/statuspages/" + pg.ID) } class="hover:underline">{ pg.Title }</a>
|
|
<span class="font-mono text-xs text-muted">{ pg.Slug }</span>
|
|
if pg.Domain != "" {
|
|
<span class="font-mono text-xs text-muted">{ pg.Domain }</span>
|
|
}
|
|
if pg.Suspended {
|
|
<span class="ml-auto text-xs text-down">{ i18n.T(ctx, "pages.suspended") }</span>
|
|
} else if pg.Published && pg.URL == "" {
|
|
<span class="ml-auto text-xs text-muted">{ i18n.T(ctx, "pages.own_servers_short") }</span>
|
|
} else if pg.Published {
|
|
<a href={ templ.SafeURL(pg.URL) } class="ml-auto text-muted hover:text-ink" target="_blank" rel="noopener">{ i18n.T(ctx, "pages.open") } ↗</a>
|
|
} else {
|
|
<span class="ml-auto text-xs text-muted">{ i18n.T(ctx, "pages.draft") }</span>
|
|
}
|
|
</li>
|
|
}
|
|
</ul>
|
|
}
|
|
if v.CanWrite {
|
|
<section class="max-w-md">
|
|
@sectionHeading("pages.create")
|
|
<form data-api="/org/statuspages" data-next-from="id" data-next="/statuspages/">
|
|
@formError()
|
|
@valueField(i18n.T(ctx, "pages.page_title"), "title", "", "Acme status", true)
|
|
@valueField(i18n.T(ctx, "pages.slug"), "slug", "", "acme", true)
|
|
@submit(i18n.T(ctx, "pages.create"))
|
|
</form>
|
|
</section>
|
|
}
|
|
}
|
|
}
|
|
|
|
// PageGroupRow is one nested group of a status page in tree order.
|
|
type PageGroupRow struct {
|
|
ID string
|
|
Name string
|
|
ParentID string
|
|
Position int
|
|
Depth int
|
|
Label string
|
|
}
|
|
|
|
// PageMonitorOption is a monitor in the page editor.
|
|
type PageMonitorOption struct {
|
|
ID string
|
|
Name string
|
|
MonitorGroupPath string
|
|
Included bool
|
|
GroupID string
|
|
Label string
|
|
}
|
|
|
|
// PageEditor is the data of the status page editor.
|
|
type PageEditor struct {
|
|
// OwnServers is set when the organization's own status page servers
|
|
// serve its pages instead of the platform's.
|
|
OwnServers bool
|
|
ID string
|
|
Title string
|
|
Slug string
|
|
Description string
|
|
Published bool
|
|
ShowDetails bool
|
|
Accent string
|
|
LogoURL string
|
|
CSS string
|
|
URL string
|
|
Domain string
|
|
DomainVerified bool
|
|
// CNAMEValue is the target unique to the page that its domain points
|
|
// at; empty when the platform's status page host is not known.
|
|
CNAMEValue string
|
|
// VerifiedBy is "cname" or "txt", empty for domains verified before
|
|
// either was recorded.
|
|
VerifiedBy string
|
|
// MissingSince and SwitchOffAt are set while the record of a verified
|
|
// domain cannot be found.
|
|
MissingSince string
|
|
SwitchOffAt string
|
|
// DomainChangesPerDay is how often the domain may be changed a day.
|
|
DomainChangesPerDay int
|
|
RecordName string
|
|
RecordValue string
|
|
Suspended bool
|
|
SuspendedReason string
|
|
Groups []PageGroupRow
|
|
HasOrgGroups bool
|
|
Monitors []PageMonitorOption
|
|
}
|
|
|
|
templ StatusPageEditor(p Page, me Me, e PageEditor) {
|
|
@consoleShell(p, me) {
|
|
<p class="mb-4 text-sm"><a href="/statuspages" class="text-muted hover:text-ink">← { i18n.T(ctx, "pages.title") }</a></p>
|
|
if e.Suspended {
|
|
<p class="mb-6 border-l-2 border-down pl-3 text-sm" role="alert">
|
|
{ i18n.T(ctx, "pages.suspended_notice") }
|
|
if e.SuspendedReason != "" {
|
|
{ " " + i18n.T(ctx, "console.suspended_reason", "Reason", e.SuspendedReason) }
|
|
}
|
|
</p>
|
|
}
|
|
<div class="mb-8 flex flex-wrap items-baseline justify-between gap-4">
|
|
<h1 class="text-lg font-semibold">{ e.Title }</h1>
|
|
<span class="flex gap-5 text-sm">
|
|
if e.Published && e.URL != "" {
|
|
<a href={ templ.SafeURL(e.URL) } target="_blank" rel="noopener" class="text-muted hover:text-ink">{ i18n.T(ctx, "pages.open") } ↗</a>
|
|
}
|
|
<a href={ templ.SafeURL("/api/v1/org/statuspages/" + e.ID + "/export") } class="text-muted hover:text-ink">{ i18n.T(ctx, "pages.export") }</a>
|
|
</span>
|
|
</div>
|
|
if e.OwnServers {
|
|
<p class="mb-6 border-l-2 border-ink pl-3 text-sm">{ i18n.T(ctx, "pages.own_servers") }</p>
|
|
}
|
|
<div class="grid gap-12 md:grid-cols-2">
|
|
<section>
|
|
@sectionHeading("pages.settings")
|
|
<form data-api={ "/org/statuspages/" + e.ID } data-method="put" data-next={ "/statuspages/" + e.ID }>
|
|
@formError()
|
|
@valueField(i18n.T(ctx, "pages.page_title"), "title", e.Title, "", true)
|
|
@valueField(i18n.T(ctx, "pages.slug"), "slug", e.Slug, "", true)
|
|
<div class="mb-4">
|
|
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "pages.description") }</span>
|
|
@MarkdownEditor("description", e.Description, 5, 10000, MarkdownInline)
|
|
</div>
|
|
@checkbox(i18n.T(ctx, "pages.published"), "published", e.Published)
|
|
@checkbox(i18n.T(ctx, "pages.show_details"), "show_component_details", e.ShowDetails)
|
|
<p class="-mt-2 mb-4 text-xs text-muted">{ i18n.T(ctx, "pages.show_details_hint") }</p>
|
|
<h3 class="mt-6 mb-3 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "pages.theme") }</h3>
|
|
@valueField(i18n.T(ctx, "pages.accent"), "theme.accent", e.Accent, "#1f6feb", false)
|
|
@valueField(i18n.T(ctx, "pages.logo"), "theme.logo_url", e.LogoURL, "https://example.com/logo.svg", false)
|
|
<label class="mb-4 block">
|
|
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "pages.css") }</span>
|
|
<textarea name="theme.css" rows="4" class="w-full border border-rule bg-transparent px-2.5 py-1.5 font-mono text-xs outline-none focus:border-ink">{ e.CSS }</textarea>
|
|
</label>
|
|
@submit(i18n.T(ctx, "common.save"))
|
|
</form>
|
|
<button
|
|
type="button"
|
|
data-delete={ "/org/statuspages/" + e.ID }
|
|
data-confirm={ i18n.T(ctx, "pages.delete_confirm") }
|
|
data-next="/statuspages"
|
|
class="mt-6 text-sm text-down hover:underline"
|
|
>{ i18n.T(ctx, "pages.delete") }</button>
|
|
</section>
|
|
<div>
|
|
<section class="mb-12">
|
|
<div class="mb-3 flex flex-wrap items-baseline justify-between gap-2">
|
|
@sectionHeading("pages.groups")
|
|
if e.HasOrgGroups {
|
|
<button
|
|
type="button"
|
|
data-post={ "/org/statuspages/" + e.ID + "/groups/import" }
|
|
data-confirm={ i18n.T(ctx, "pages.groups_import_confirm") }
|
|
data-ok={ i18n.T(ctx, "pages.groups_imported") }
|
|
data-reload
|
|
class="border border-rule px-2.5 py-1 text-xs hover:border-ink"
|
|
>{ i18n.T(ctx, "pages.groups_import") }</button>
|
|
}
|
|
</div>
|
|
<p class="mb-4 text-xs text-muted">{ i18n.T(ctx, "pages.groups_intro") }</p>
|
|
if len(e.Groups) > 0 {
|
|
<ul class="mb-4 divide-y divide-rule border-y border-rule text-sm">
|
|
for _, g := range e.Groups {
|
|
<li class="py-2" style={ indent(g.Depth) }>
|
|
<details>
|
|
<summary class="flex cursor-pointer items-center justify-between gap-2 select-none hover:text-ink">
|
|
<span>{ g.Name }</span>
|
|
<span class="text-xs text-muted">{ i18n.T(ctx, "common.edit") }</span>
|
|
</summary>
|
|
<form data-api={ "/org/statuspages/" + e.ID + "/groups/" + g.ID } data-method="put" data-next={ "/statuspages/" + e.ID } class="mt-3 max-w-sm">
|
|
@formError()
|
|
@valueField(i18n.T(ctx, "sso.field.name"), "name", g.Name, "", true)
|
|
<label class="mb-3 block">
|
|
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "groups.parent") }</span>
|
|
<select name="parent_id" data-nullable class={ inputClass }>
|
|
<option value="">{ i18n.T(ctx, "groups.none") }</option>
|
|
for _, opt := range e.Groups {
|
|
if opt.ID != g.ID {
|
|
<option value={ opt.ID } selected?={ opt.ID == g.ParentID }>{ opt.Label }</option>
|
|
}
|
|
}
|
|
</select>
|
|
</label>
|
|
<label class="mb-3 block">
|
|
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "pages.group_position") }</span>
|
|
<input type="number" name="position" data-number value={ strconv.Itoa(g.Position) } class={ inputClass }/>
|
|
</label>
|
|
<div class="flex items-center gap-4">
|
|
@submit(i18n.T(ctx, "common.save"))
|
|
<button
|
|
type="button"
|
|
data-delete={ "/org/statuspages/" + e.ID + "/groups/" + g.ID }
|
|
data-confirm={ i18n.T(ctx, "groups.delete_confirm") }
|
|
data-next={ "/statuspages/" + e.ID }
|
|
class="text-sm text-down hover:underline"
|
|
>{ i18n.T(ctx, "common.delete") }</button>
|
|
</div>
|
|
</form>
|
|
</details>
|
|
</li>
|
|
}
|
|
</ul>
|
|
}
|
|
<form data-api={ "/org/statuspages/" + e.ID + "/groups" } data-next={ "/statuspages/" + e.ID } class="border border-rule p-3">
|
|
@formError()
|
|
<div class="grid gap-3 sm:grid-cols-[1fr_1fr_5rem]">
|
|
<label class="block">
|
|
<span class="mb-1 block text-xs text-muted">{ i18n.T(ctx, "groups.create") }</span>
|
|
<input name="name" required maxlength="100" placeholder={ i18n.T(ctx, "sso.field.name") } class={ inputClass }/>
|
|
</label>
|
|
<label class="block">
|
|
<span class="mb-1 block text-xs text-muted">{ i18n.T(ctx, "groups.parent") }</span>
|
|
<select name="parent_id" data-nullable class={ inputClass }>
|
|
<option value="">{ i18n.T(ctx, "groups.none") }</option>
|
|
for _, opt := range e.Groups {
|
|
<option value={ opt.ID }>{ opt.Label }</option>
|
|
}
|
|
</select>
|
|
</label>
|
|
<label class="block">
|
|
<span class="mb-1 block text-xs text-muted">{ i18n.T(ctx, "pages.group_position") }</span>
|
|
<input type="number" name="position" data-number value={ strconv.Itoa(len(e.Groups)) } class={ inputClass }/>
|
|
</label>
|
|
</div>
|
|
<div class="mt-3">
|
|
@submit(i18n.T(ctx, "groups.create"))
|
|
</div>
|
|
</form>
|
|
</section>
|
|
<section class="mb-12">
|
|
@sectionHeading("pages.components")
|
|
<form data-api={ "/org/statuspages/" + e.ID + "/monitors" } data-method="put" data-rows="monitors" data-next={ "/statuspages/" + e.ID }>
|
|
@formError()
|
|
if len(e.Monitors) == 0 {
|
|
<p class="mb-4 text-sm text-muted">{ i18n.T(ctx, "console.monitors.empty") }</p>
|
|
}
|
|
<ul class="mb-4 divide-y divide-rule border-y border-rule text-sm">
|
|
for _, m := range e.Monitors {
|
|
<li data-row class="grid grid-cols-[auto_1fr] items-center gap-x-3 gap-y-1.5 py-2">
|
|
<input type="checkbox" data-field="include" checked?={ m.Included } class="accent-ink" aria-label={ m.Name }/>
|
|
<span class="flex flex-wrap items-baseline gap-x-2">
|
|
<span>{ m.Name }</span>
|
|
if m.MonitorGroupPath != "" {
|
|
<span class="font-mono text-xs text-muted">{ m.MonitorGroupPath }</span>
|
|
}
|
|
</span>
|
|
<input type="hidden" data-field="monitor_id" value={ m.ID }/>
|
|
<span></span>
|
|
<span class="flex gap-2">
|
|
<select data-field="group_id" data-nullable aria-label={ i18n.T(ctx, "pages.group") } class="w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink">
|
|
<option value="">{ i18n.T(ctx, "pages.no_group") }</option>
|
|
for _, opt := range e.Groups {
|
|
<option value={ opt.ID } selected?={ opt.ID == m.GroupID }>{ opt.Label }</option>
|
|
}
|
|
</select>
|
|
<input data-field="label" value={ m.Label } placeholder={ i18n.T(ctx, "pages.label") } class="w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink"/>
|
|
</span>
|
|
</li>
|
|
}
|
|
</ul>
|
|
@submit(i18n.T(ctx, "common.save"))
|
|
</form>
|
|
</section>
|
|
<section>
|
|
@sectionHeading("pages.domain")
|
|
<p class="mb-4 text-sm text-muted">{ i18n.T(ctx, "pages.domain_intro") }</p>
|
|
<form data-api={ "/org/statuspages/" + e.ID + "/domain" } data-method="put" data-next={ "/statuspages/" + e.ID }>
|
|
@formError()
|
|
@valueField(i18n.T(ctx, "pages.domain_name"), "domain", e.Domain, "status.example.com", false)
|
|
@submit(i18n.T(ctx, "common.save"))
|
|
</form>
|
|
if e.Domain != "" {
|
|
<div class="mt-6 space-y-4 border border-rule p-4 text-sm">
|
|
if e.DomainVerified {
|
|
<p>
|
|
<span class="text-up">●</span>
|
|
switch e.VerifiedBy {
|
|
case "cname":
|
|
{ i18n.T(ctx, "pages.domain_verified_by_cname") }
|
|
case "txt":
|
|
{ i18n.T(ctx, "pages.domain_verified_by_txt") }
|
|
default:
|
|
{ i18n.T(ctx, "pages.domain_step_verified") }
|
|
}
|
|
</p>
|
|
if e.MissingSince != "" {
|
|
<p class="border-l-2 border-down pl-3" role="alert">{ i18n.T(ctx, "pages.domain_missing", "Since", e.MissingSince, "Date", e.SwitchOffAt) }</p>
|
|
} else if e.VerifiedBy != "" {
|
|
<p class="text-xs text-muted">{ i18n.T(ctx, "pages.domain_keep") }</p>
|
|
}
|
|
} else if e.CNAMEValue != "" && !e.OwnServers {
|
|
<p>{ i18n.T(ctx, "pages.domain_cname_step") }</p>
|
|
@dnsRecordList("CNAME", e.Domain, e.CNAMEValue+".")
|
|
@verifyButton(e.ID, "pages.verify_now")
|
|
<details>
|
|
<summary class="cursor-pointer text-xs text-muted hover:text-ink">{ i18n.T(ctx, "pages.domain_alt_summary") }</summary>
|
|
<p class="mb-3 mt-3 text-xs">{ i18n.T(ctx, "pages.domain_alt", "Target", e.CNAMEValue) }</p>
|
|
@dnsRecordList("TXT", e.RecordName, e.RecordValue)
|
|
@verifyButton(e.ID, "pages.verify")
|
|
</details>
|
|
} else {
|
|
<p>{ i18n.T(ctx, "pages.domain_step_verify") }</p>
|
|
@dnsRecordList("TXT", e.RecordName, e.RecordValue)
|
|
@verifyButton(e.ID, "pages.verify")
|
|
if e.OwnServers {
|
|
<p>{ i18n.T(ctx, "pages.domain_step_cname_own") }</p>
|
|
} else {
|
|
<p>{ i18n.T(ctx, "pages.domain_step_cname_unknown") }</p>
|
|
}
|
|
<p class="text-xs text-muted">{ i18n.T(ctx, "pages.domain_apex") }</p>
|
|
}
|
|
<p class="text-xs text-muted">{ i18n.T(ctx, "pages.domain_step_tls", "Count", e.DomainChangesPerDay) }</p>
|
|
</div>
|
|
}
|
|
</section>
|
|
</div>
|
|
</div>
|
|
}
|
|
}
|
|
|
|
templ dnsRecordList(kind, name, value string) {
|
|
<dl class="grid grid-cols-[max-content_1fr] gap-x-4 gap-y-1 font-mono text-xs">
|
|
<dt class="text-muted">{ kind }</dt>
|
|
<dd class="break-all">{ name }</dd>
|
|
<dt class="text-muted">{ i18n.T(ctx, "pages.value") }</dt>
|
|
<dd class="break-all">{ value }</dd>
|
|
</dl>
|
|
}
|
|
|
|
templ verifyButton(pageID, label string) {
|
|
<button type="button" data-post={ "/org/statuspages/" + pageID + "/domain/verify" } data-ok={ i18n.T(ctx, "pages.domain_verified") } data-reload class="mt-3 border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, label) }</button>
|
|
}
|