package web import "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n" // Region is a row in a region list. type Region struct { ID string Key string Name string // Platform regions are shared by all organizations. Platform bool // Manageable regions can be deleted on the current page. Manageable bool Instances int64 } // Agent is a checker or status page server. type Agent struct { ID string Kind string Name string Region string Prefix string LastSeen string // AllowPrivate is set for an organization's checkers: whether they // may check private addresses. AllowPrivate *bool // Release is what the agent last reported; Outdated marks agents // behind the platform's release. Release string Outdated bool } // InstallView fills the install instructions shown with a new agent's // token. type InstallView struct { // ScriptURL is the platform's install script. ScriptURL string // APIURL goes into UPTIME_API_URL. APIURL string // Image is the image name without -checker or -statuspage. Image string // Channel is the image tag following the platform: latest, beta or edge. Channel string // Compose holds the Compose file per agent kind. Compose map[string]string // Release is the platform's release. Release string } // RegionsView is the data of the org regions page and the admin panel. type RegionsView struct { Regions []Region Agents []Agent // APIBase is the prefix of the endpoints the forms post to, either // /org or /admin. APIBase string // Next is the page to reload after a change. Next string // OwnRegions are the regions agents can be created in. OwnRegions []Region Install InstallView } templ regionsBody(v RegionsView) {
@sectionHeading("regions.list")
for _, r := range v.Regions { }
{ i18n.T(ctx, "sso.field.name") } { i18n.T(ctx, "regions.key") } { i18n.T(ctx, "regions.owner") } { i18n.T(ctx, "regions.instances") }
{ r.Name } { r.Key } if r.Platform { { i18n.T(ctx, "regions.platform") } } else { { i18n.T(ctx, "regions.own") } } 0), templ.KV("text-unknown", r.Instances == 0) }>● { i18n.T(ctx, "regions.live", "Count", int(r.Instances)) } if r.Manageable { }
@sectionHeading("regions.create")
@formError() @valueField(i18n.T(ctx, "regions.key"), "key", "", "office-berlin", true) @valueField(i18n.T(ctx, "sso.field.name"), "name", "", "Office Berlin", false) @submit(i18n.T(ctx, "regions.create"))
@sectionHeading("agents.create")
@formError() @valueField(i18n.T(ctx, "sso.field.name"), "name", "", "checker-1", true) if v.APIBase == "/org" { @checkbox(i18n.T(ctx, "agents.allow_private"), "allow_private", true)

{ i18n.T(ctx, "agents.allow_private_hint") }

} @submit(i18n.T(ctx, "agents.create"))
if len(v.Agents) > 0 {
@sectionHeading("agents.list") if v.Install.Release != "" {

{ i18n.T(ctx, "agents.platform_release", "Release", v.Install.Release) }

}
} } templ RegionsPage(p Page, me Me, v RegionsView) { @consoleShell(p, me) { @settingsHeading("regions.title", "regions.intro") @regionsBody(v) } } templ AdminPage(p Page, me Me, v RegionsView, storage StorageView, checkTypes []CheckTypeOption, platformPrivate bool, limits LimitsView, idps IDPAdminView) { @consoleShell(p, me) { @settingsHeading("admin.title", "admin.intro") @adminLinks() @idpSection(idps) @limitsSection(limits) @regionsBody(v) @checkerNetworkSection(platformPrivate) @checkTypesSection(checkTypes, "/admin/check-types", "/admin", "admin.check_types_intro") @storageSection(storage) } } // CheckTypeOption is a check type in the admin panel. type CheckTypeOption struct { Type string Enabled bool } templ checkerNetworkSection(allow bool) {
@sectionHeading("admin.checker_network")
@formError() @checkbox(i18n.T(ctx, "admin.platform_private"), "allow_private", allow)

{ i18n.T(ctx, "admin.platform_private_hint") }

} // checkTypesSection lets the platform or an organization choose the // check types it offers. templ checkTypesSection(types []CheckTypeOption, api, next, introID string) {
@sectionHeading("admin.check_types")

{ i18n.T(ctx, introID) }

@formError()
for _, t := range types { }
} // ModerationView lists public status pages for platform admins. type ModerationView struct { Search string Pages []ModeratedPage Pager Pager // Next is the page to return to after an action. Next string } // ModeratedPage is a status page with the organization and account // behind it. type ModeratedPage struct { ID, Title, Slug, URL, Created string Published bool Suspended string Org ModeratedTarget Owner *ModeratedTarget } // ModeratedTarget is an organization or account that can be suspended or // deleted. Suspended holds the reason, or "-" without one, when suspended. type ModeratedTarget struct { ID, Name, Detail, Suspended string // Admin marks platform admins, who are out of reach here. Admin bool } func (v ModerationView) next() string { return v.Next } templ moderationSection(v ModerationView) {
@sectionHeading("moderation.title")

{ i18n.T(ctx, "moderation.intro") }

if len(v.Pages) == 0 {

{ i18n.T(ctx, "moderation.none") }

} else {
for _, pg := range v.Pages { }
{ i18n.T(ctx, "moderation.page") } { i18n.T(ctx, "moderation.org") } { i18n.T(ctx, "moderation.owner") } { i18n.T(ctx, "moderation.created") }
{ pg.Title } { pg.Slug } @moderationState(pg.Suspended, !pg.Published) { pg.Org.Name } { pg.Org.Detail } @moderationState(pg.Org.Suspended, false) if pg.Owner != nil { { pg.Owner.Name } @moderationState(pg.Owner.Suspended, false) } else { – } { pg.Created }
{ i18n.T(ctx, "moderation.actions") }
@moderationActions("page", "/admin/status-pages/"+pg.ID, pg.Suspended, pg.Title, v.next()) @moderationActions("org", "/admin/orgs/"+pg.Org.ID, pg.Org.Suspended, pg.Org.Name, v.next()) if pg.Owner != nil && pg.Owner.Admin {

{ i18n.T(ctx, "moderation.owner_is_admin") }

} else if pg.Owner != nil { @moderationActions("owner", "/admin/users/"+pg.Owner.ID, pg.Owner.Suspended, pg.Owner.Name, v.next()) }
} @pager(v.Pager, "newer", "older")
} templ moderationState(suspended string, draft bool) { if suspended != "" { { i18n.T(ctx, "moderation.suspended") } if suspended != "-" { { "· " + suspended } } } else if draft { { i18n.T(ctx, "pages.draft") } } } // moderationActions suspends, reinstates or deletes one target; kind is // "page", "org" or "owner". templ moderationActions(kind, api, suspended, name, next string) {

{ i18n.T(ctx, "moderation.target_"+kind) }

@formError() if suspended != "" { } else { }
} templ adminLinks() {

{ i18n.T(ctx, "moderation.title") } { i18n.T(ctx, "orgs.title") } { i18n.T(ctx, "audit.platform_title") } { i18n.T(ctx, "legal.platform_title") }

} templ AdminStatusPagesPage(p Page, me Me, v ModerationView) { @consoleShell(p, me) {

← { i18n.T(ctx, "admin.title") }

@moderationSection(v) } } templ AdminOrgsPage(p Page, me Me, v OrgsView) { @consoleShell(p, me) {

← { i18n.T(ctx, "admin.title") }

@orgsSection(v) } } // agentInstall shows how to run the agent just created; the script fills // in the token, the kind chosen and whether it updates itself. templ agentInstall(in InstallView) {

{ i18n.T(ctx, "agents.install_heading") }

{ i18n.T(ctx, "agents.install_auto_hint") }

{ i18n.T(ctx, "agents.install_oneliner") }


		

{ i18n.T(ctx, "agents.install_statuspage_hint") }

{ i18n.T(ctx, "agents.install_compose") } for _, kind := range []string{"checker", "statuspage"} {

compose.yaml

{ in.Compose[kind] }

.env


					

{ i18n.T(ctx, "agents.install_compose_hint") }

}
}