Files
uptimesebi/internal/web/statuspages.templ
T
Sebastian UnterschützandClaude Opus 5.5 c0239e15bb
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Canceled after 6m3s
ci / test (pull_request) Canceled after 6m2s
ci / build (pull_request) Canceled after 0s
ci / image (pull_request) Canceled after 0s
feat(api): organizations with own status page servers serve their pages alone
The platform's status page servers handed out every published page,
including those of organizations running their own servers. Once one of
an organization's own status page servers has connected, the agent API
now answers the platform's servers 404 for its pages, so they drop them
from their cache, and only the organization's servers serve them. A
created but never connected token changes nothing, so moving over does
not take the pages offline.

The console no longer links such pages to the platform's address,
which would not serve them; the editor says who does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
2026-11-24 22:45:37 +01:00

320 lines
13 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
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")
<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 border border-rule p-4 text-sm">
if e.DomainVerified {
<p><span class="text-up">●</span> { i18n.T(ctx, "pages.domain_verified") }</p>
<p class="mt-2 text-xs text-muted">{ i18n.T(ctx, "pages.domain_cname") }</p>
} else {
<p class="mb-3">{ i18n.T(ctx, "pages.domain_instructions") }</p>
<dl class="mb-4 grid grid-cols-[max-content_1fr] gap-x-4 gap-y-1 font-mono text-xs">
<dt class="text-muted">TXT</dt>
<dd class="break-all">{ e.RecordName }</dd>
<dt class="text-muted">{ i18n.T(ctx, "pages.value") }</dt>
<dd class="break-all">{ e.RecordValue }</dd>
</dl>
<button type="button" data-post={ "/org/statuspages/" + e.ID + "/domain/verify" } data-ok={ i18n.T(ctx, "pages.domain_verified") } data-reload class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "pages.verify") }</button>
}
</div>
}
</section>
</div>
</div>
}
}