chore(ui): add module file and main stub
- chore(ui): add module file and main stub - feat(ui): add layout, pages and partials - feat(ui): add stylesheet and scripts - feat(ui): add page renderer and static file handler - test(ui): cover rendering, escaping and static serving
This commit is contained in:
1 parent
7089a6f408
commit
5ac8f98f10
26 files changed
+3921
No files matched your search
@@ -0,0 +1,209 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
// Copyright (C) 2026 Bryan Joshua Pedini
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"crypto/sha256"
|
||||||
|
"embed"
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"html/template"
|
||||||
|
"io/fs"
|
||||||
|
"net/http"
|
||||||
|
"path"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed templates/html
|
||||||
|
var uiTemplateFiles embed.FS
|
||||||
|
|
||||||
|
//go:embed static
|
||||||
|
var uiStaticFiles embed.FS
|
||||||
|
|
||||||
|
const defaultBootstrapCommand = "docker exec -i <container> /app user add <username> admin"
|
||||||
|
|
||||||
|
var uiContentTypes = map[string]string{
|
||||||
|
".css": "text/css; charset=utf-8",
|
||||||
|
".js": "text/javascript; charset=utf-8",
|
||||||
|
".mjs": "text/javascript; charset=utf-8",
|
||||||
|
".svg": "image/svg+xml",
|
||||||
|
".json": "application/json",
|
||||||
|
".txt": "text/plain; charset=utf-8",
|
||||||
|
".ico": "image/x-icon",
|
||||||
|
".png": "image/png",
|
||||||
|
".woff2": "font/woff2",
|
||||||
|
}
|
||||||
|
|
||||||
|
type pageData struct {
|
||||||
|
AppName string
|
||||||
|
Static string
|
||||||
|
Page string
|
||||||
|
Script string
|
||||||
|
Username string
|
||||||
|
Role string
|
||||||
|
Zone string
|
||||||
|
TargetUser string
|
||||||
|
Next string
|
||||||
|
Error string
|
||||||
|
NoActiveAdmin bool
|
||||||
|
BootstrapCommand string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d pageData) IsAdmin() bool {
|
||||||
|
return d.Role == "admin"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d pageData) Section() string {
|
||||||
|
switch d.Page {
|
||||||
|
case "zones", "zone", "import":
|
||||||
|
return "zones"
|
||||||
|
case "users", "user":
|
||||||
|
return "users"
|
||||||
|
}
|
||||||
|
return d.Page
|
||||||
|
}
|
||||||
|
|
||||||
|
type pageRenderer struct {
|
||||||
|
templates map[string]*template.Template
|
||||||
|
static fs.FS
|
||||||
|
hash string
|
||||||
|
prefix string
|
||||||
|
}
|
||||||
|
|
||||||
|
func staticHash(fsys fs.FS) (string, error) {
|
||||||
|
sum := sha256.New()
|
||||||
|
err := fs.WalkDir(fsys, ".", func(name string, entry fs.DirEntry, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if entry.IsDir() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
data, err := fs.ReadFile(fsys, name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Fprintf(sum, "%s\x00%d\x00", name, len(data))
|
||||||
|
sum.Write(data)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return hex.EncodeToString(sum.Sum(nil))[:16], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func newPageRenderer() (*pageRenderer, error) {
|
||||||
|
templates, err := fs.Sub(uiTemplateFiles, "templates/html")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
static, err := fs.Sub(uiStaticFiles, "static")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return newPageRendererFS(templates, static)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newPageRendererFS(templates, static fs.FS) (*pageRenderer, error) {
|
||||||
|
hash, err := staticHash(static)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("hash static files: %w", err)
|
||||||
|
}
|
||||||
|
pages, err := fs.Glob(templates, "pages/*.html")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(pages) == 0 {
|
||||||
|
return nil, fmt.Errorf("no page templates found")
|
||||||
|
}
|
||||||
|
renderer := &pageRenderer{
|
||||||
|
templates: make(map[string]*template.Template, len(pages)),
|
||||||
|
static: static,
|
||||||
|
hash: hash,
|
||||||
|
prefix: "/static/" + hash + "/",
|
||||||
|
}
|
||||||
|
for _, file := range pages {
|
||||||
|
name := strings.TrimSuffix(path.Base(file), ".html")
|
||||||
|
tmpl, err := template.New(name).ParseFS(templates, "layout.html", "partials/*.html", file)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("parse page %s: %w", name, err)
|
||||||
|
}
|
||||||
|
renderer.templates[name] = tmpl
|
||||||
|
}
|
||||||
|
return renderer, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *pageRenderer) staticPrefix() string {
|
||||||
|
return p.prefix
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *pageRenderer) hasScript(page string) bool {
|
||||||
|
info, err := fs.Stat(p.static, "js/"+page+".js")
|
||||||
|
return err == nil && !info.IsDir()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *pageRenderer) render(w http.ResponseWriter, status int, page string, data pageData) {
|
||||||
|
tmpl, ok := p.templates[page]
|
||||||
|
if !ok {
|
||||||
|
http.Error(w, "internal server error", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data.Static = p.prefix
|
||||||
|
data.Page = page
|
||||||
|
if p.hasScript(page) {
|
||||||
|
data.Script = page
|
||||||
|
}
|
||||||
|
if data.NoActiveAdmin && data.BootstrapCommand == "" {
|
||||||
|
data.BootstrapCommand = defaultBootstrapCommand
|
||||||
|
}
|
||||||
|
var buf bytes.Buffer
|
||||||
|
if err := tmpl.ExecuteTemplate(&buf, "layout", data); err != nil {
|
||||||
|
http.Error(w, "internal server error", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
|
w.Header().Set("Cache-Control", "no-store")
|
||||||
|
w.Header().Set("Content-Length", strconv.Itoa(buf.Len()))
|
||||||
|
w.WriteHeader(status)
|
||||||
|
w.Write(buf.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *pageRenderer) staticHandler() http.Handler {
|
||||||
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method != http.MethodGet && r.Method != http.MethodHead {
|
||||||
|
w.Header().Set("Allow", "GET, HEAD")
|
||||||
|
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !strings.HasPrefix(r.URL.Path, p.prefix) {
|
||||||
|
http.NotFound(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
name := strings.TrimPrefix(r.URL.Path, p.prefix)
|
||||||
|
if name == "" || strings.ContainsAny(name, "\\\x00") || !fs.ValidPath(name) {
|
||||||
|
http.NotFound(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data, err := fs.ReadFile(p.static, name)
|
||||||
|
if err != nil {
|
||||||
|
http.NotFound(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
contentType, ok := uiContentTypes[strings.ToLower(path.Ext(name))]
|
||||||
|
if !ok {
|
||||||
|
contentType = "application/octet-stream"
|
||||||
|
}
|
||||||
|
w.Header().Set("Content-Type", contentType)
|
||||||
|
w.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
|
||||||
|
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||||
|
w.Header().Set("Content-Length", strconv.Itoa(len(data)))
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
if r.Method == http.MethodGet {
|
||||||
|
w.Write(data)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,655 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
// Copyright (C) 2026 Bryan Joshua Pedini
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"io/fs"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"testing/fstest"
|
||||||
|
)
|
||||||
|
|
||||||
|
type failingFS struct{}
|
||||||
|
|
||||||
|
func (failingFS) Open(string) (fs.File, error) {
|
||||||
|
return nil, errors.New("open failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testStaticFS() fstest.MapFS {
|
||||||
|
return fstest.MapFS{
|
||||||
|
"css/app.css": {Data: []byte("body{}")},
|
||||||
|
"js/app.js": {Data: []byte("export {};")},
|
||||||
|
"js/page.js": {Data: []byte("export {};")},
|
||||||
|
"icon.svg": {Data: []byte("<svg></svg>")},
|
||||||
|
"data.bin": {Data: []byte{1, 2, 3}},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mustRenderer(t *testing.T) *pageRenderer {
|
||||||
|
t.Helper()
|
||||||
|
renderer, err := newPageRenderer()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("newPageRenderer: %v", err)
|
||||||
|
}
|
||||||
|
return renderer
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStaticHashStable(t *testing.T) {
|
||||||
|
first, err := staticHash(testStaticFS())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
second, err := staticHash(testStaticFS())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if first != second {
|
||||||
|
t.Fatalf("hash is not stable: %s != %s", first, second)
|
||||||
|
}
|
||||||
|
if len(first) != 16 {
|
||||||
|
t.Fatalf("hash length = %d, want 16", len(first))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStaticHashDetectsChanges(t *testing.T) {
|
||||||
|
base, _ := staticHash(testStaticFS())
|
||||||
|
changed := testStaticFS()
|
||||||
|
changed["css/app.css"] = &fstest.MapFile{Data: []byte("body{color:red}")}
|
||||||
|
renamed := testStaticFS()
|
||||||
|
renamed["css/other.css"] = renamed["css/app.css"]
|
||||||
|
delete(renamed, "css/app.css")
|
||||||
|
added := testStaticFS()
|
||||||
|
added["js/extra.js"] = &fstest.MapFile{Data: []byte("")}
|
||||||
|
for name, fsys := range map[string]fstest.MapFS{"content": changed, "name": renamed, "added": added} {
|
||||||
|
got, err := staticHash(fsys)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got == base {
|
||||||
|
t.Errorf("hash did not change after %s change", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStaticHashBoundaryBetweenFiles(t *testing.T) {
|
||||||
|
left := fstest.MapFS{"a": {Data: []byte("bc")}, "d": {Data: []byte("e")}}
|
||||||
|
right := fstest.MapFS{"a": {Data: []byte("b")}, "cd": {Data: []byte("e")}}
|
||||||
|
one, _ := staticHash(left)
|
||||||
|
two, _ := staticHash(right)
|
||||||
|
if one == two {
|
||||||
|
t.Fatal("different file layouts produced the same hash")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStaticHashError(t *testing.T) {
|
||||||
|
if _, err := staticHash(failingFS{}); err == nil {
|
||||||
|
t.Fatal("expected an error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNewPageRendererErrors(t *testing.T) {
|
||||||
|
good := fstest.MapFS{
|
||||||
|
"layout.html": {Data: []byte(`{{define "layout"}}{{template "content" .}}{{end}}`)},
|
||||||
|
"partials/p.html": {Data: []byte(`{{define "p"}}x{{end}}`)},
|
||||||
|
"pages/home.html": {Data: []byte(`{{define "content"}}ok{{end}}`)},
|
||||||
|
"pages/broken.html": {Data: []byte(`{{define "content"}}{{end`)},
|
||||||
|
"pages/missing.html": {Data: []byte(`{{define "other"}}x{{end}}`)},
|
||||||
|
}
|
||||||
|
if _, err := newPageRendererFS(failingFS{}, testStaticFS()); err == nil {
|
||||||
|
t.Error("expected an error for an unreadable template tree")
|
||||||
|
}
|
||||||
|
if _, err := newPageRendererFS(good, failingFS{}); err == nil {
|
||||||
|
t.Error("expected an error for an unreadable static tree")
|
||||||
|
}
|
||||||
|
empty := fstest.MapFS{"layout.html": {Data: []byte("x")}}
|
||||||
|
if _, err := newPageRendererFS(empty, testStaticFS()); err == nil {
|
||||||
|
t.Error("expected an error without pages")
|
||||||
|
}
|
||||||
|
if _, err := newPageRendererFS(good, testStaticFS()); err == nil {
|
||||||
|
t.Error("expected an error for a template that does not parse")
|
||||||
|
}
|
||||||
|
delete(good, "pages/broken.html")
|
||||||
|
if _, err := newPageRendererFS(good, testStaticFS()); err != nil {
|
||||||
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStaticHandler(t *testing.T) {
|
||||||
|
renderer, err := newPageRendererFS(minimalTemplates(), testStaticFS())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
handler := renderer.staticHandler()
|
||||||
|
prefix := renderer.staticPrefix()
|
||||||
|
if !strings.HasPrefix(prefix, "/static/") || !strings.HasSuffix(prefix, "/") {
|
||||||
|
t.Fatalf("unexpected prefix %q", prefix)
|
||||||
|
}
|
||||||
|
cases := map[string]string{
|
||||||
|
"css/app.css": "text/css; charset=utf-8",
|
||||||
|
"js/app.js": "text/javascript; charset=utf-8",
|
||||||
|
"icon.svg": "image/svg+xml",
|
||||||
|
"data.bin": "application/octet-stream",
|
||||||
|
}
|
||||||
|
for name, contentType := range cases {
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
handler.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, prefix+name, nil))
|
||||||
|
if rec.Code != http.StatusOK {
|
||||||
|
t.Errorf("%s: status %d", name, rec.Code)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if got := rec.Header().Get("Content-Type"); got != contentType {
|
||||||
|
t.Errorf("%s: content type %q, want %q", name, got, contentType)
|
||||||
|
}
|
||||||
|
if got := rec.Header().Get("Cache-Control"); got != "public, max-age=31536000, immutable" {
|
||||||
|
t.Errorf("%s: cache control %q", name, got)
|
||||||
|
}
|
||||||
|
if got := rec.Header().Get("X-Content-Type-Options"); got != "nosniff" {
|
||||||
|
t.Errorf("%s: nosniff %q", name, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
handler.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, prefix+"css/app.css", nil))
|
||||||
|
if rec.Body.String() != "body{}" {
|
||||||
|
t.Errorf("body = %q", rec.Body.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStaticHandlerHead(t *testing.T) {
|
||||||
|
renderer, _ := newPageRendererFS(minimalTemplates(), testStaticFS())
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
renderer.staticHandler().ServeHTTP(rec, httptest.NewRequest(http.MethodHead, renderer.staticPrefix()+"css/app.css", nil))
|
||||||
|
if rec.Code != http.StatusOK || rec.Body.Len() != 0 {
|
||||||
|
t.Fatalf("HEAD: status %d, body %d bytes", rec.Code, rec.Body.Len())
|
||||||
|
}
|
||||||
|
if rec.Header().Get("Content-Length") != "6" {
|
||||||
|
t.Errorf("content length %q", rec.Header().Get("Content-Length"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStaticHandlerMethod(t *testing.T) {
|
||||||
|
renderer, _ := newPageRendererFS(minimalTemplates(), testStaticFS())
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
renderer.staticHandler().ServeHTTP(rec, httptest.NewRequest(http.MethodPost, renderer.staticPrefix()+"css/app.css", nil))
|
||||||
|
if rec.Code != http.StatusMethodNotAllowed || rec.Header().Get("Allow") != "GET, HEAD" {
|
||||||
|
t.Fatalf("POST: status %d, allow %q", rec.Code, rec.Header().Get("Allow"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStaticHandlerNotFound(t *testing.T) {
|
||||||
|
renderer, _ := newPageRendererFS(minimalTemplates(), testStaticFS())
|
||||||
|
handler := renderer.staticHandler()
|
||||||
|
prefix := renderer.staticPrefix()
|
||||||
|
paths := []string{
|
||||||
|
"/static/0000000000000000/css/app.css",
|
||||||
|
"/static/css/app.css",
|
||||||
|
"/static/",
|
||||||
|
"/other/css/app.css",
|
||||||
|
prefix,
|
||||||
|
prefix + "missing.css",
|
||||||
|
prefix + "css",
|
||||||
|
prefix + "css/",
|
||||||
|
prefix + "js/",
|
||||||
|
prefix + "../css/app.css",
|
||||||
|
prefix + "css/../../css/app.css",
|
||||||
|
prefix + "css/../css/app.css",
|
||||||
|
prefix + "./css/app.css",
|
||||||
|
prefix + "/css/app.css",
|
||||||
|
prefix + "css//app.css",
|
||||||
|
prefix + "..",
|
||||||
|
prefix + "css\\app.css",
|
||||||
|
prefix + "..\\css\\app.css",
|
||||||
|
prefix + "css/app.css/",
|
||||||
|
prefix + "css/app.css\x00.png",
|
||||||
|
}
|
||||||
|
for _, p := range paths {
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||||
|
req.URL.Path = p
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
handler.ServeHTTP(rec, req)
|
||||||
|
if rec.Code != http.StatusNotFound {
|
||||||
|
t.Errorf("%q: status %d, want 404", p, rec.Code)
|
||||||
|
}
|
||||||
|
if strings.Contains(rec.Body.String(), "app.css") && strings.Contains(rec.Body.String(), "body{}") {
|
||||||
|
t.Errorf("%q: leaked a file", p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStaticHandlerEmbeddedAssets(t *testing.T) {
|
||||||
|
renderer := mustRenderer(t)
|
||||||
|
handler := renderer.staticHandler()
|
||||||
|
for _, name := range []string{"css/app.css", "js/common.js", "js/records.js", "js/zones.js", "js/zone.js", "js/import.js", "js/audit.js", "js/account.js", "js/users.js", "js/user.js"} {
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
handler.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, renderer.staticPrefix()+name, nil))
|
||||||
|
if rec.Code != http.StatusOK {
|
||||||
|
t.Errorf("%s: status %d", name, rec.Code)
|
||||||
|
}
|
||||||
|
if rec.Body.Len() == 0 {
|
||||||
|
t.Errorf("%s: empty body", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEmbeddedFilesRules(t *testing.T) {
|
||||||
|
check := func(root fs.FS, name string) {
|
||||||
|
err := fs.WalkDir(root, ".", func(p string, entry fs.DirEntry, err error) error {
|
||||||
|
if err != nil || entry.IsDir() {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
data, err := fs.ReadFile(root, p)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
text := string(data)
|
||||||
|
if strings.Contains(text, "—") {
|
||||||
|
t.Errorf("%s/%s contains an em dash", name, p)
|
||||||
|
}
|
||||||
|
if strings.HasSuffix(p, ".js") || strings.HasSuffix(p, ".css") {
|
||||||
|
if !strings.Contains(text[:min(len(text), 200)], "SPDX-License-Identifier: GPL-2.0-or-later") {
|
||||||
|
t.Errorf("%s/%s lacks the SPDX header", name, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if strings.HasSuffix(p, ".js") {
|
||||||
|
for _, banned := range []string{"innerHTML", "outerHTML", "insertAdjacentHTML", "document.write", "eval(", "setAttribute(\"style\""} {
|
||||||
|
if strings.Contains(text, banned) {
|
||||||
|
t.Errorf("%s/%s uses %s", name, p, banned)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templates, _ := fs.Sub(uiTemplateFiles, "templates/html")
|
||||||
|
static, _ := fs.Sub(uiStaticFiles, "static")
|
||||||
|
check(templates, "templates")
|
||||||
|
check(static, "static")
|
||||||
|
}
|
||||||
|
|
||||||
|
func minimalTemplates() fstest.MapFS {
|
||||||
|
return fstest.MapFS{
|
||||||
|
"layout.html": {Data: []byte(`{{define "layout"}}{{template "content" .}}{{end}}`)},
|
||||||
|
"partials/p.html": {Data: []byte(`{{define "p"}}x{{end}}`)},
|
||||||
|
"pages/home.html": {Data: []byte(`{{define "content"}}home {{.Username}}{{end}}`)},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRenderErrors(t *testing.T) {
|
||||||
|
renderer, err := newPageRendererFS(minimalTemplates(), testStaticFS())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
renderer.render(rec, http.StatusOK, "nope", pageData{})
|
||||||
|
if rec.Code != http.StatusInternalServerError {
|
||||||
|
t.Errorf("unknown page: status %d", rec.Code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRenderExecutionError(t *testing.T) {
|
||||||
|
templates := fstest.MapFS{
|
||||||
|
"layout.html": {Data: []byte(`{{define "layout"}}partial{{template "content" .}}{{end}}`)},
|
||||||
|
"partials/p.html": {Data: []byte(`{{define "p"}}x{{end}}`)},
|
||||||
|
"pages/bad.html": {Data: []byte(`{{define "content"}}{{call .Username}}{{end}}`)},
|
||||||
|
}
|
||||||
|
renderer, err := newPageRendererFS(templates, testStaticFS())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
renderer.render(rec, http.StatusOK, "bad", pageData{Username: "x"})
|
||||||
|
if rec.Code != http.StatusInternalServerError {
|
||||||
|
t.Fatalf("status %d, want 500", rec.Code)
|
||||||
|
}
|
||||||
|
if strings.Contains(rec.Body.String(), "partial") {
|
||||||
|
t.Error("partial output was written before the error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPageDataSection(t *testing.T) {
|
||||||
|
cases := map[string]string{
|
||||||
|
"zones": "zones", "zone": "zones", "import": "zones",
|
||||||
|
"users": "users", "user": "users",
|
||||||
|
"audit": "audit", "account": "account", "login": "login",
|
||||||
|
}
|
||||||
|
for page, want := range cases {
|
||||||
|
if got := (pageData{Page: page}).Section(); got != want {
|
||||||
|
t.Errorf("Section(%s) = %q, want %q", page, got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !(pageData{Role: "admin"}).IsAdmin() || (pageData{Role: "user"}).IsAdmin() || (pageData{}).IsAdmin() {
|
||||||
|
t.Error("IsAdmin is wrong")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
styleAttr = regexp.MustCompile(`(?i)\sstyle\s*=`)
|
||||||
|
eventAttr = regexp.MustCompile(`(?i)\son[a-z]+\s*=`)
|
||||||
|
inlineScript = regexp.MustCompile(`(?is)<script(\s[^>]*)?>`)
|
||||||
|
formControl = regexp.MustCompile(`(?is)<(input|select|textarea)\s[^>]*>`)
|
||||||
|
idAttr = regexp.MustCompile(`\sid="([^"]+)"`)
|
||||||
|
typeHidden = regexp.MustCompile(`type="hidden"`)
|
||||||
|
ariaLabelAttr = regexp.MustCompile(`aria-label="`)
|
||||||
|
)
|
||||||
|
|
||||||
|
func renderPage(t *testing.T, renderer *pageRenderer, page string, data pageData) (int, string, http.Header) {
|
||||||
|
t.Helper()
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
renderer.render(rec, http.StatusOK, page, data)
|
||||||
|
return rec.Code, rec.Body.String(), rec.Header()
|
||||||
|
}
|
||||||
|
|
||||||
|
var allPages = []string{"login", "zones", "zone", "import", "audit", "account", "users", "user", "not_found", "forbidden"}
|
||||||
|
|
||||||
|
func dataFor(role string) pageData {
|
||||||
|
data := pageData{AppName: "Test DNS", Zone: "example.org.", TargetUser: "bob"}
|
||||||
|
switch role {
|
||||||
|
case "admin":
|
||||||
|
data.Username, data.Role = "alice", "admin"
|
||||||
|
case "user":
|
||||||
|
data.Username, data.Role = "carol", "user"
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRenderEveryPage(t *testing.T) {
|
||||||
|
renderer := mustRenderer(t)
|
||||||
|
for _, page := range allPages {
|
||||||
|
for _, role := range []string{"admin", "user", "anonymous"} {
|
||||||
|
status, body, header := renderPage(t, renderer, page, dataFor(role))
|
||||||
|
name := page + "/" + role
|
||||||
|
if status != http.StatusOK {
|
||||||
|
t.Errorf("%s: status %d", name, status)
|
||||||
|
}
|
||||||
|
if got := header.Get("Content-Type"); got != "text/html; charset=utf-8" {
|
||||||
|
t.Errorf("%s: content type %q", name, got)
|
||||||
|
}
|
||||||
|
if header.Get("Cache-Control") != "no-store" {
|
||||||
|
t.Errorf("%s: cache control %q", name, header.Get("Cache-Control"))
|
||||||
|
}
|
||||||
|
if !strings.HasPrefix(body, "<!DOCTYPE html>") {
|
||||||
|
t.Errorf("%s: output does not start with the doctype", name)
|
||||||
|
}
|
||||||
|
if !strings.Contains(body, "<title>") || !strings.Contains(body, "- Test DNS</title>") {
|
||||||
|
t.Errorf("%s: title is wrong", name)
|
||||||
|
}
|
||||||
|
if !strings.Contains(body, renderer.staticPrefix()+"css/app.css") {
|
||||||
|
t.Errorf("%s: stylesheet missing", name)
|
||||||
|
}
|
||||||
|
if !strings.Contains(body, `aria-live="polite"`) {
|
||||||
|
t.Errorf("%s: live region missing", name)
|
||||||
|
}
|
||||||
|
if styleAttr.MatchString(body) || eventAttr.MatchString(body) {
|
||||||
|
t.Errorf("%s: inline style or event handler", name)
|
||||||
|
}
|
||||||
|
for _, m := range inlineScript.FindAllString(body, -1) {
|
||||||
|
if !strings.Contains(m, `src="`+renderer.staticPrefix()+`js/`) || !strings.Contains(m, `type="module"`) {
|
||||||
|
t.Errorf("%s: unexpected script tag %s", name, m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if strings.Contains(body, "<script") && strings.Contains(body, "</script>") {
|
||||||
|
idx := strings.Index(body, "<script")
|
||||||
|
end := strings.Index(body[idx:], "</script>")
|
||||||
|
if strings.TrimSpace(body[idx+strings.Index(body[idx:], ">")+1:idx+end]) != "" {
|
||||||
|
t.Errorf("%s: inline script body", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
checkLabels(t, name, body)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkLabels(t *testing.T, name, body string) {
|
||||||
|
t.Helper()
|
||||||
|
for _, loc := range formControl.FindAllStringIndex(body, -1) {
|
||||||
|
control := body[loc[0]:loc[1]]
|
||||||
|
if typeHidden.MatchString(control) || ariaLabelAttr.MatchString(control) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if strings.HasSuffix(body[:loc[0]], "<label class=\"choice\">") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
match := idAttr.FindStringSubmatch(control)
|
||||||
|
if match == nil {
|
||||||
|
t.Errorf("%s: control without id or label: %s", name, control)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !strings.Contains(body, `for="`+match[1]+`"`) {
|
||||||
|
t.Errorf("%s: control %s has no label", name, match[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRenderScriptsPerPage(t *testing.T) {
|
||||||
|
renderer := mustRenderer(t)
|
||||||
|
for _, page := range []string{"zones", "zone", "import", "audit", "account", "users", "user"} {
|
||||||
|
_, body, _ := renderPage(t, renderer, page, dataFor("admin"))
|
||||||
|
want := `<script type="module" src="` + renderer.staticPrefix() + `js/` + page + `.js"></script>`
|
||||||
|
if !strings.Contains(body, want) {
|
||||||
|
t.Errorf("%s: missing %s", page, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, page := range []string{"login", "not_found", "forbidden"} {
|
||||||
|
_, body, _ := renderPage(t, renderer, page, dataFor("anonymous"))
|
||||||
|
if strings.Contains(body, "<script") {
|
||||||
|
t.Errorf("%s: unexpected script", page)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRenderLayoutNavigation(t *testing.T) {
|
||||||
|
renderer := mustRenderer(t)
|
||||||
|
_, admin, _ := renderPage(t, renderer, "zones", dataFor("admin"))
|
||||||
|
_, user, _ := renderPage(t, renderer, "zones", dataFor("user"))
|
||||||
|
_, anon, _ := renderPage(t, renderer, "login", dataFor("anonymous"))
|
||||||
|
for _, want := range []string{`href="/audit"`, `href="/account"`, `action="/logout"`, `method="post"`, `href="/users"`, `aria-current="page"`, ">alice<", ">admin<"} {
|
||||||
|
if !strings.Contains(admin, want) {
|
||||||
|
t.Errorf("admin layout lacks %s", want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if strings.Contains(user, `href="/users"`) {
|
||||||
|
t.Error("user layout shows the Users link")
|
||||||
|
}
|
||||||
|
for _, want := range []string{`href="/audit"`, `href="/account"`, `action="/logout"`, ">carol<", ">user<"} {
|
||||||
|
if !strings.Contains(user, want) {
|
||||||
|
t.Errorf("user layout lacks %s", want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, unwanted := range []string{`action="/logout"`, `href="/audit"`, `href="/account"`, `href="/users"`} {
|
||||||
|
if strings.Contains(anon, unwanted) {
|
||||||
|
t.Errorf("anonymous layout shows %s", unwanted)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRenderControlsByRole(t *testing.T) {
|
||||||
|
renderer := mustRenderer(t)
|
||||||
|
type check struct {
|
||||||
|
page string
|
||||||
|
adminOnly []string
|
||||||
|
everyoneSees []string
|
||||||
|
userOnlyExtra []string
|
||||||
|
}
|
||||||
|
checks := []check{
|
||||||
|
{
|
||||||
|
page: "zones",
|
||||||
|
adminOnly: []string{`id="new-zone"`, `id="zone-dialog"`, `id="zone-form"`, `name="extra_ns"`},
|
||||||
|
everyoneSees: []string{`id="zone-search"`, `id="zones-body"`},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
page: "zone",
|
||||||
|
adminOnly: []string{`id="users-panel"`, `id="danger"`, `id="zone-delete-confirm"`, `id="zone-user-pick"`},
|
||||||
|
everyoneSees: []string{`id="record-add"`, `id="record-dialog"`, `id="soa-dialog"`, `id="bulk-delete"`, `id="filter-type"`, `id="filter-text"`, `id="export-link"`, `id="import-link"`, `id="problems-panel"`, `id="soa-managed"`},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
page: "account",
|
||||||
|
everyoneSees: []string{`id="password-form"`, `name="current"`, `name="repeat"`},
|
||||||
|
userOnlyExtra: []string{`id="account-zones"`},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, c := range checks {
|
||||||
|
_, admin, _ := renderPage(t, renderer, c.page, dataFor("admin"))
|
||||||
|
_, user, _ := renderPage(t, renderer, c.page, dataFor("user"))
|
||||||
|
for _, want := range c.adminOnly {
|
||||||
|
if !strings.Contains(admin, want) {
|
||||||
|
t.Errorf("%s: admin lacks %s", c.page, want)
|
||||||
|
}
|
||||||
|
if strings.Contains(user, want) {
|
||||||
|
t.Errorf("%s: user has %s", c.page, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, want := range c.everyoneSees {
|
||||||
|
if !strings.Contains(admin, want) || !strings.Contains(user, want) {
|
||||||
|
t.Errorf("%s: %s missing for admin or user", c.page, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, want := range c.userOnlyExtra {
|
||||||
|
if strings.Contains(admin, want) || !strings.Contains(user, want) {
|
||||||
|
t.Errorf("%s: %s should be present for users only", c.page, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRenderUserPageSelfAndOther(t *testing.T) {
|
||||||
|
renderer := mustRenderer(t)
|
||||||
|
other := dataFor("admin")
|
||||||
|
other.TargetUser = "bob"
|
||||||
|
_, body, _ := renderPage(t, renderer, "user", other)
|
||||||
|
for _, want := range []string{`id="role-form"`, `id="password-form"`, `id="zone-add-form"`, `id="user-delete-form"`, `id="user-delete-confirm"`, `id="user-readonly"`} {
|
||||||
|
if !strings.Contains(body, want) {
|
||||||
|
t.Errorf("other user: missing %s", want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self := dataFor("admin")
|
||||||
|
self.TargetUser = "alice"
|
||||||
|
_, body, _ = renderPage(t, renderer, "user", self)
|
||||||
|
for _, unwanted := range []string{`id="role-form"`, `id="password-form"`, `id="user-delete-form"`, `id="zone-add-form"`} {
|
||||||
|
if strings.Contains(body, unwanted) {
|
||||||
|
t.Errorf("own user: unexpected %s", unwanted)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !strings.Contains(body, `href="/account"`) || !strings.Contains(body, `id="user-self"`) {
|
||||||
|
t.Error("own user: link to the account page missing")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRenderUsersAndAuditAndImport(t *testing.T) {
|
||||||
|
renderer := mustRenderer(t)
|
||||||
|
_, users, _ := renderPage(t, renderer, "users", dataFor("admin"))
|
||||||
|
for _, want := range []string{`id="new-user"`, `id="show-deleted"`, `id="user-dialog"`, `name="username"`, `name="role"`, `name="password"`, `name="repeat"`} {
|
||||||
|
if !strings.Contains(users, want) {
|
||||||
|
t.Errorf("users: missing %s", want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_, audit, _ := renderPage(t, renderer, "audit", dataFor("user"))
|
||||||
|
for _, want := range []string{`name="zone"`, `name="actor"`, `name="operation"`, `name="kind"`, `name="outcome"`, `id="audit-more"`, `<option>zone_import</option>`} {
|
||||||
|
if !strings.Contains(audit, want) {
|
||||||
|
t.Errorf("audit: missing %s", want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_, imp, _ := renderPage(t, renderer, "import", dataFor("user"))
|
||||||
|
for _, want := range []string{`value="merge" checked`, `value="replace"`, `id="import-content"`, `id="import-file"`, `id="import-apply"`, `id="import-preview"`} {
|
||||||
|
if !strings.Contains(imp, want) {
|
||||||
|
t.Errorf("import: missing %s", want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRenderRootAttributes(t *testing.T) {
|
||||||
|
renderer := mustRenderer(t)
|
||||||
|
_, body, _ := renderPage(t, renderer, "zone", dataFor("user"))
|
||||||
|
for _, want := range []string{`id="app"`, `data-page="zone"`, `data-username="carol"`, `data-role="user"`, `data-zone="example.org."`, `data-target-user="bob"`} {
|
||||||
|
if !strings.Contains(body, want) {
|
||||||
|
t.Errorf("root element lacks %s", want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRenderLogin(t *testing.T) {
|
||||||
|
renderer := mustRenderer(t)
|
||||||
|
data := pageData{AppName: "Test DNS", Next: "/zones/example.org."}
|
||||||
|
_, body, _ := renderPage(t, renderer, "login", data)
|
||||||
|
for _, want := range []string{`action="/login"`, `method="post"`, `name="username"`, `name="password"`, `name="next" value="/zones/example.org."`} {
|
||||||
|
if !strings.Contains(body, want) {
|
||||||
|
t.Errorf("login: missing %s", want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if strings.Contains(body, "No administrator exists") || strings.Contains(body, `role="alert"`) {
|
||||||
|
t.Error("login: unexpected notice")
|
||||||
|
}
|
||||||
|
|
||||||
|
data.NoActiveAdmin = true
|
||||||
|
_, body, _ = renderPage(t, renderer, "login", data)
|
||||||
|
if !strings.Contains(body, "No administrator exists") || !strings.Contains(body, "user add <username> admin") {
|
||||||
|
t.Error("login: bootstrap notice missing")
|
||||||
|
}
|
||||||
|
|
||||||
|
data.BootstrapCommand = "docker exec -i web /app user add <name> admin"
|
||||||
|
data.Error = "invalid username or password"
|
||||||
|
_, body, _ = renderPage(t, renderer, "login", data)
|
||||||
|
if !strings.Contains(body, "docker exec -i web /app user add <name> admin") {
|
||||||
|
t.Error("login: custom bootstrap command missing")
|
||||||
|
}
|
||||||
|
if !strings.Contains(body, `role="alert"`) || !strings.Contains(body, "invalid username or password") {
|
||||||
|
t.Error("login: error missing")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRenderStatus(t *testing.T) {
|
||||||
|
renderer := mustRenderer(t)
|
||||||
|
for _, status := range []int{http.StatusNotFound, http.StatusForbidden, http.StatusUnauthorized, http.StatusTooManyRequests} {
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
renderer.render(rec, status, "login", pageData{AppName: "x"})
|
||||||
|
if rec.Code != status {
|
||||||
|
t.Errorf("status %d, got %d", status, rec.Code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRenderEscaping(t *testing.T) {
|
||||||
|
renderer := mustRenderer(t)
|
||||||
|
script := `<script>alert(1)</script>`
|
||||||
|
quote := `"><img src=x onerror=alert(1)>`
|
||||||
|
data := pageData{
|
||||||
|
AppName: script,
|
||||||
|
Username: script,
|
||||||
|
Role: "admin",
|
||||||
|
Zone: quote,
|
||||||
|
TargetUser: quote,
|
||||||
|
Next: quote,
|
||||||
|
Error: script,
|
||||||
|
}
|
||||||
|
for _, page := range allPages {
|
||||||
|
_, body, _ := renderPage(t, renderer, page, data)
|
||||||
|
if strings.Contains(body, script) {
|
||||||
|
t.Errorf("%s: unescaped script", page)
|
||||||
|
}
|
||||||
|
if strings.Contains(body, quote) || strings.Contains(body, "<img") {
|
||||||
|
t.Errorf("%s: unescaped attribute payload", page)
|
||||||
|
}
|
||||||
|
for _, m := range inlineScript.FindAllString(body, -1) {
|
||||||
|
if !strings.Contains(m, "src=") {
|
||||||
|
t.Errorf("%s: injected script tag %s", page, m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_, body, _ := renderPage(t, renderer, "zone", data)
|
||||||
|
if !strings.Contains(body, "<script>alert(1)</script>") {
|
||||||
|
t.Error("zone: escaped username missing")
|
||||||
|
}
|
||||||
|
if !strings.Contains(body, ""><img src=x onerror=alert(1)>") {
|
||||||
|
t.Error("zone: escaped zone name missing")
|
||||||
|
}
|
||||||
|
_, body, _ = renderPage(t, renderer, "login", data)
|
||||||
|
if !strings.Contains(body, "<script>alert(1)</script>") {
|
||||||
|
t.Error("login: escaped error missing")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,713 @@
|
|||||||
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||||
|
/* Copyright (C) 2026 Bryan Joshua Pedini */
|
||||||
|
|
||||||
|
:root {
|
||||||
|
color-scheme: light dark;
|
||||||
|
--bg: #f4f5f7;
|
||||||
|
--surface: #ffffff;
|
||||||
|
--text: #1c2128;
|
||||||
|
--muted: #5b6573;
|
||||||
|
--border: #d3d9e0;
|
||||||
|
--accent: #1f5fbf;
|
||||||
|
--accent-text: #ffffff;
|
||||||
|
--danger: #b3261e;
|
||||||
|
--danger-bg: #fdecea;
|
||||||
|
--warn: #8a5a00;
|
||||||
|
--warn-bg: #fff4d6;
|
||||||
|
--ok: #1e6b34;
|
||||||
|
--ok-bg: #e3f4e8;
|
||||||
|
--info-bg: #e5eefc;
|
||||||
|
--stripe: #f0f2f5;
|
||||||
|
--focus: #1f5fbf;
|
||||||
|
--radius: 6px;
|
||||||
|
--mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
|
||||||
|
--sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
:root {
|
||||||
|
--bg: #14181d;
|
||||||
|
--surface: #1d232b;
|
||||||
|
--text: #e6eaf0;
|
||||||
|
--muted: #9aa5b3;
|
||||||
|
--border: #36404c;
|
||||||
|
--accent: #6ea4f4;
|
||||||
|
--accent-text: #0c1624;
|
||||||
|
--danger: #ff8a80;
|
||||||
|
--danger-bg: #3a1f1d;
|
||||||
|
--warn: #f2c35c;
|
||||||
|
--warn-bg: #3a2f14;
|
||||||
|
--ok: #7bd493;
|
||||||
|
--ok-bg: #19301f;
|
||||||
|
--info-bg: #1b2a44;
|
||||||
|
--stripe: #222a33;
|
||||||
|
--focus: #8ab8ff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*,
|
||||||
|
*::before,
|
||||||
|
*::after {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
[hidden] {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
html {
|
||||||
|
-webkit-text-size-adjust: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
background: var(--bg);
|
||||||
|
color: var(--text);
|
||||||
|
font-family: var(--sans);
|
||||||
|
font-size: 1rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
h1,
|
||||||
|
h2,
|
||||||
|
h3 {
|
||||||
|
line-height: 1.25;
|
||||||
|
margin: 0 0 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: 1.125rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin: 0 0 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
code,
|
||||||
|
pre,
|
||||||
|
.mono {
|
||||||
|
font-family: var(--mono);
|
||||||
|
font-size: 0.9em;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre.code {
|
||||||
|
background: var(--stripe);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius);
|
||||||
|
margin: 0.5rem 0 0;
|
||||||
|
overflow-x: auto;
|
||||||
|
padding: 0.5rem 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
:focus-visible {
|
||||||
|
outline: 3px solid var(--focus);
|
||||||
|
outline-offset: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.visually-hidden {
|
||||||
|
border: 0;
|
||||||
|
clip: rect(0 0 0 0);
|
||||||
|
height: 1px;
|
||||||
|
margin: -1px;
|
||||||
|
overflow: hidden;
|
||||||
|
padding: 0;
|
||||||
|
position: absolute;
|
||||||
|
white-space: nowrap;
|
||||||
|
width: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skip {
|
||||||
|
background: var(--accent);
|
||||||
|
color: var(--accent-text);
|
||||||
|
left: 0.5rem;
|
||||||
|
padding: 0.5rem 0.75rem;
|
||||||
|
position: absolute;
|
||||||
|
top: -4rem;
|
||||||
|
z-index: 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skip:focus {
|
||||||
|
top: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar {
|
||||||
|
align-items: center;
|
||||||
|
background: var(--surface);
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.5rem 1rem;
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand {
|
||||||
|
color: var(--text);
|
||||||
|
font-weight: 700;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav {
|
||||||
|
display: flex;
|
||||||
|
flex: 1;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.25rem 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav a {
|
||||||
|
border-radius: var(--radius);
|
||||||
|
color: var(--text);
|
||||||
|
padding: 0.25rem 0.625rem;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav a:hover {
|
||||||
|
background: var(--stripe);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav a[aria-current="page"] {
|
||||||
|
background: var(--accent);
|
||||||
|
color: var(--accent-text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.logout {
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
gap: 0.5rem;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.who {
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page {
|
||||||
|
margin: 0 auto;
|
||||||
|
max-width: 72rem;
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page:focus {
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-head,
|
||||||
|
.section-head {
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.5rem 1rem;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-head h2 {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.crumbs {
|
||||||
|
color: var(--muted);
|
||||||
|
margin-bottom: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
background: var(--surface);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius);
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.narrow {
|
||||||
|
margin: 2rem auto;
|
||||||
|
max-width: 26rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.danger-zone {
|
||||||
|
border-color: var(--danger);
|
||||||
|
}
|
||||||
|
|
||||||
|
.danger-zone h2 {
|
||||||
|
color: var(--danger);
|
||||||
|
}
|
||||||
|
|
||||||
|
.muted {
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.actions {
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actions-cell {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
background: var(--surface);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius);
|
||||||
|
color: var(--text);
|
||||||
|
cursor: pointer;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
font: inherit;
|
||||||
|
gap: 0.25rem;
|
||||||
|
justify-content: center;
|
||||||
|
min-height: 2.25rem;
|
||||||
|
padding: 0.25rem 0.875rem;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn:hover:not(:disabled) {
|
||||||
|
border-color: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn:disabled {
|
||||||
|
cursor: not-allowed;
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary {
|
||||||
|
background: var(--accent);
|
||||||
|
border-color: var(--accent);
|
||||||
|
color: var(--accent-text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-danger {
|
||||||
|
border-color: var(--danger);
|
||||||
|
color: var(--danger);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-danger:hover:not(:disabled) {
|
||||||
|
background: var(--danger-bg);
|
||||||
|
border-color: var(--danger);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-small {
|
||||||
|
font-size: 0.875rem;
|
||||||
|
min-height: 2rem;
|
||||||
|
padding: 0.125rem 0.625rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-icon {
|
||||||
|
border-color: transparent;
|
||||||
|
font-size: 1.25rem;
|
||||||
|
line-height: 1;
|
||||||
|
min-width: 2rem;
|
||||||
|
padding: 0.125rem 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form,
|
||||||
|
.dialog-body {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field {
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field label,
|
||||||
|
fieldset.field legend {
|
||||||
|
display: block;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-bottom: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldset.field {
|
||||||
|
border: 0;
|
||||||
|
margin-left: 0;
|
||||||
|
margin-right: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="text"],
|
||||||
|
input[type="search"],
|
||||||
|
input[type="password"],
|
||||||
|
input[type="number"],
|
||||||
|
input:not([type]),
|
||||||
|
select,
|
||||||
|
textarea {
|
||||||
|
background: var(--surface);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius);
|
||||||
|
color: var(--text);
|
||||||
|
font: inherit;
|
||||||
|
max-width: 100%;
|
||||||
|
min-height: 2.25rem;
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
resize: vertical;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="checkbox"],
|
||||||
|
input[type="radio"] {
|
||||||
|
height: 1.125rem;
|
||||||
|
width: 1.125rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
[aria-invalid="true"] {
|
||||||
|
border-color: var(--danger);
|
||||||
|
}
|
||||||
|
|
||||||
|
.choice {
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
font-weight: 400;
|
||||||
|
gap: 0.5rem;
|
||||||
|
margin-bottom: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hint {
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 0.875rem;
|
||||||
|
margin: 0.25rem 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-error {
|
||||||
|
color: var(--danger);
|
||||||
|
font-size: 0.875rem;
|
||||||
|
margin: 0.25rem 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.alert {
|
||||||
|
border-radius: var(--radius);
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
padding: 0.5rem 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.alert > :last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.alert-error {
|
||||||
|
background: var(--danger-bg);
|
||||||
|
color: var(--danger);
|
||||||
|
}
|
||||||
|
|
||||||
|
.alert-warn {
|
||||||
|
background: var(--warn-bg);
|
||||||
|
color: var(--warn);
|
||||||
|
}
|
||||||
|
|
||||||
|
.alert-info {
|
||||||
|
background: var(--info-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-2 {
|
||||||
|
display: grid;
|
||||||
|
gap: 0 0.75rem;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar,
|
||||||
|
.filters,
|
||||||
|
.inline-form {
|
||||||
|
align-items: end;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar .field,
|
||||||
|
.filters .field,
|
||||||
|
.inline-form .field {
|
||||||
|
flex: 1 1 12rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar .field.grow {
|
||||||
|
flex: 3 1 14rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filters .actions,
|
||||||
|
.inline-form .btn {
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-wrap {
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table {
|
||||||
|
border-collapse: collapse;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table caption {
|
||||||
|
font-weight: 600;
|
||||||
|
padding: 0.5rem 0;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table th,
|
||||||
|
.table td {
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
padding: 0.375rem 0.5rem;
|
||||||
|
text-align: left;
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table thead th {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table tbody th {
|
||||||
|
font-weight: 600;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table tbody tr:nth-child(even) {
|
||||||
|
background: var(--stripe);
|
||||||
|
}
|
||||||
|
|
||||||
|
.table .num {
|
||||||
|
text-align: right;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table .check {
|
||||||
|
width: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table .value code {
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table .raw {
|
||||||
|
color: var(--danger);
|
||||||
|
}
|
||||||
|
|
||||||
|
.row-error {
|
||||||
|
box-shadow: inset 3px 0 0 var(--danger);
|
||||||
|
}
|
||||||
|
|
||||||
|
.row-warning {
|
||||||
|
box-shadow: inset 3px 0 0 var(--warn);
|
||||||
|
}
|
||||||
|
|
||||||
|
.row-muted {
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-row td {
|
||||||
|
background: var(--stripe);
|
||||||
|
}
|
||||||
|
|
||||||
|
.diff-changed {
|
||||||
|
background: var(--warn-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.diff-added {
|
||||||
|
background: var(--ok-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.diff-removed {
|
||||||
|
background: var(--danger-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.diff-same {
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge {
|
||||||
|
background: var(--stripe);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 999px;
|
||||||
|
display: inline-block;
|
||||||
|
font-size: 0.8125rem;
|
||||||
|
line-height: 1.4;
|
||||||
|
padding: 0 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-ok {
|
||||||
|
background: var(--ok-bg);
|
||||||
|
color: var(--ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-warning {
|
||||||
|
background: var(--warn-bg);
|
||||||
|
color: var(--warn);
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-error {
|
||||||
|
background: var(--danger-bg);
|
||||||
|
color: var(--danger);
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-muted {
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dl {
|
||||||
|
display: grid;
|
||||||
|
gap: 0.25rem 1rem;
|
||||||
|
grid-template-columns: max-content minmax(0, 1fr);
|
||||||
|
margin: 0 0 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dl dt {
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dl dd {
|
||||||
|
margin: 0;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list,
|
||||||
|
.problems {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0 0 0.75rem;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list li {
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
padding: 0.375rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.problems {
|
||||||
|
font-size: 0.875rem;
|
||||||
|
margin: 0.25rem 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pager {
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
gap: 0.75rem;
|
||||||
|
justify-content: center;
|
||||||
|
margin-top: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog {
|
||||||
|
background: var(--surface);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius);
|
||||||
|
color: var(--text);
|
||||||
|
max-height: calc(100vh - 1rem);
|
||||||
|
max-width: 34rem;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 0;
|
||||||
|
width: calc(100% - 1rem);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-small {
|
||||||
|
max-width: 24rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog::backdrop {
|
||||||
|
background: rgb(0 0 0 / 55%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-head {
|
||||||
|
align-items: center;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 0.5rem 0.75rem 0.5rem 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-head h2 {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-body {
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-actions {
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.5rem;
|
||||||
|
justify-content: flex-end;
|
||||||
|
padding: 0.75rem 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toasts {
|
||||||
|
bottom: 0.5rem;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
left: 0.5rem;
|
||||||
|
max-width: 28rem;
|
||||||
|
position: fixed;
|
||||||
|
right: 0.5rem;
|
||||||
|
z-index: 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast {
|
||||||
|
align-items: center;
|
||||||
|
background: var(--surface);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-left-width: 4px;
|
||||||
|
border-radius: var(--radius);
|
||||||
|
box-shadow: 0 2px 8px rgb(0 0 0 / 25%);
|
||||||
|
display: flex;
|
||||||
|
gap: 0.5rem;
|
||||||
|
padding: 0.5rem 0.5rem 0.5rem 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast-text {
|
||||||
|
flex: 1;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast-error {
|
||||||
|
border-left-color: var(--danger);
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast-warning {
|
||||||
|
border-left-color: var(--warn);
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast-info {
|
||||||
|
border-left-color: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 30rem) {
|
||||||
|
.page {
|
||||||
|
padding: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-2 {
|
||||||
|
grid-template-columns: minmax(0, 1fr);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dl {
|
||||||
|
grid-template-columns: minmax(0, 1fr);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dl dd {
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toasts {
|
||||||
|
max-width: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: no-preference) {
|
||||||
|
.btn {
|
||||||
|
transition: border-color 0.1s, background-color 0.1s;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
// Copyright (C) 2026 Bryan Joshua Pedini
|
||||||
|
|
||||||
|
import { $, api, bindPasswordForm, clear, h, handleError, toast, zoneLink } from "./common.js";
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
const list = $("#account-zones");
|
||||||
|
try {
|
||||||
|
const { data } = await api("GET", "/account");
|
||||||
|
$("#account-username").textContent = data.username;
|
||||||
|
$("#account-role").textContent = data.role;
|
||||||
|
if (list) {
|
||||||
|
const zones = data.zones || [];
|
||||||
|
clear(list);
|
||||||
|
for (const zone of zones) list.append(h("li", null, zoneLink(zone)));
|
||||||
|
$("#account-zones-status").textContent = zones.length === 0 ? "No zone is delegated to you." : "";
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
if (list) $("#account-zones-status").textContent = "The account could not be loaded.";
|
||||||
|
handleError(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bindPasswordForm($("#password-form"), async (form) => {
|
||||||
|
await api("PUT", "/account/password", { body: { current: form.elements.current.value, password: form.elements.password.value } });
|
||||||
|
toast("Password changed. Your other sessions ended.");
|
||||||
|
});
|
||||||
|
load();
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
// Copyright (C) 2026 Bryan Joshua Pedini
|
||||||
|
|
||||||
|
import { $, api, busy, formatTime, h, handleError, icon } from "./common.js";
|
||||||
|
|
||||||
|
const state = { nextBeforeId: null, count: 0, filters: {}, counter: 0 };
|
||||||
|
|
||||||
|
function flatten(value, prefix, out) {
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
value.forEach((item, index) => flatten(item, prefix + "[" + index + "]", out));
|
||||||
|
} else if (value !== null && typeof value === "object") {
|
||||||
|
for (const [key, item] of Object.entries(value)) flatten(item, prefix ? prefix + "." + key : key, out);
|
||||||
|
} else {
|
||||||
|
out.set(prefix, value);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
function show(value) {
|
||||||
|
return value === undefined ? "(none)" : JSON.stringify(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function diffRows(before, after) {
|
||||||
|
const left = flatten(before === undefined ? null : before, "", new Map());
|
||||||
|
const right = flatten(after === undefined ? null : after, "", new Map());
|
||||||
|
const paths = [...new Set([...left.keys(), ...right.keys()])].filter((path) => path !== "");
|
||||||
|
return paths.map((path) => {
|
||||||
|
const old = left.get(path);
|
||||||
|
const now = right.get(path);
|
||||||
|
let kind = "same";
|
||||||
|
if (!left.has(path)) kind = "added";
|
||||||
|
else if (!right.has(path)) kind = "removed";
|
||||||
|
else if (JSON.stringify(old) !== JSON.stringify(now)) kind = "changed";
|
||||||
|
return { path, kind, before: left.has(path) ? old : undefined, after: right.has(path) ? now : undefined };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function diffTable(entry) {
|
||||||
|
const rows = diffRows(entry.before, entry.after);
|
||||||
|
if (rows.length === 0) return h("p", { class: "muted", text: "No field-level data." });
|
||||||
|
return h("table", { class: "table diff" },
|
||||||
|
h("thead", null, h("tr", null, h("th", { scope: "col", text: "Field" }), h("th", { scope: "col", text: "Before" }), h("th", { scope: "col", text: "After" }))),
|
||||||
|
h("tbody", null, rows.map((row) => h("tr", { class: "diff-" + row.kind },
|
||||||
|
h("th", { scope: "row", class: "mono", text: row.path }),
|
||||||
|
h("td", { class: "mono", text: show(row.before) }),
|
||||||
|
h("td", { class: "mono", text: show(row.after) })))));
|
||||||
|
}
|
||||||
|
|
||||||
|
function entryRows(entry) {
|
||||||
|
state.counter += 1;
|
||||||
|
const detailId = "audit-detail-" + state.counter;
|
||||||
|
const hasDiff = entry.before !== null && entry.before !== undefined || entry.after !== null && entry.after !== undefined;
|
||||||
|
const target = [];
|
||||||
|
if (entry.zone) target.push(entry.zone);
|
||||||
|
if (entry.record_id !== null && entry.record_id !== undefined) target.push("record " + entry.record_id);
|
||||||
|
if (entry.target_user) target.push("user " + entry.target_user);
|
||||||
|
const failed = typeof entry.status === "number" && entry.status >= 400;
|
||||||
|
const detail = h("tr", { class: "detail-row", id: detailId, hidden: true }, h("td", { colspan: 7 }));
|
||||||
|
const toggle = h("button", {
|
||||||
|
type: "button",
|
||||||
|
class: "btn btn-small",
|
||||||
|
"aria-expanded": "false",
|
||||||
|
"aria-controls": detailId,
|
||||||
|
onclick: () => {
|
||||||
|
const open = toggle.getAttribute("aria-expanded") !== "true";
|
||||||
|
toggle.setAttribute("aria-expanded", String(open));
|
||||||
|
detail.hidden = !open;
|
||||||
|
if (open && detail.firstChild.childNodes.length === 0) detail.firstChild.append(diffTable(entry));
|
||||||
|
},
|
||||||
|
}, icon("chevron"), " Changes");
|
||||||
|
const row = h("tr", { class: failed ? "row-error" : null },
|
||||||
|
h("td", { class: "mono", text: formatTime(entry.time) }),
|
||||||
|
h("td", { text: entry.actor }),
|
||||||
|
h("td", { class: "mono", text: entry.origin }),
|
||||||
|
h("td", { class: "mono", text: entry.operation }),
|
||||||
|
h("td", null,
|
||||||
|
entry.status === null || entry.status === undefined ? "-" : h("span", { class: "badge " + (failed ? "badge-error" : "badge-ok"), text: String(entry.status) }),
|
||||||
|
entry.error ? h("div", { class: "muted", text: entry.error }) : null),
|
||||||
|
h("td", { text: target.length ? target.join(", ") : "-" }),
|
||||||
|
h("td", null, hasDiff ? toggle : "-"));
|
||||||
|
return [row, detail];
|
||||||
|
}
|
||||||
|
|
||||||
|
async function load(append) {
|
||||||
|
const body = $("#audit-body");
|
||||||
|
const status = $("#audit-status");
|
||||||
|
const query = { ...state.filters };
|
||||||
|
if (append && state.nextBeforeId !== null) query.before_id = state.nextBeforeId;
|
||||||
|
if (!append) {
|
||||||
|
body.replaceChildren();
|
||||||
|
state.count = 0;
|
||||||
|
status.textContent = "Loading...";
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const { data } = await api("GET", "/audit", { query });
|
||||||
|
const entries = data.entries || [];
|
||||||
|
for (const entry of entries) body.append(...entryRows(entry));
|
||||||
|
state.count += entries.length;
|
||||||
|
state.nextBeforeId = data.next_before_id === undefined ? null : data.next_before_id;
|
||||||
|
status.textContent = state.count === 0 ? "No audit rows match." : state.count + " rows shown.";
|
||||||
|
$("#audit-more").hidden = state.nextBeforeId === null;
|
||||||
|
} catch (err) {
|
||||||
|
status.textContent = "The audit could not be loaded.";
|
||||||
|
handleError(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function readFilters() {
|
||||||
|
const form = $("#audit-filters");
|
||||||
|
const filters = {};
|
||||||
|
for (const name of ["zone", "actor", "operation", "kind", "outcome"]) {
|
||||||
|
const value = form.elements[name].value.trim();
|
||||||
|
if (value) filters[name] = value;
|
||||||
|
}
|
||||||
|
return filters;
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#audit-filters").addEventListener("submit", (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
state.filters = readFilters();
|
||||||
|
state.nextBeforeId = null;
|
||||||
|
load(false);
|
||||||
|
});
|
||||||
|
$("#audit-filters").addEventListener("reset", () => {
|
||||||
|
setTimeout(() => {
|
||||||
|
state.filters = {};
|
||||||
|
state.nextBeforeId = null;
|
||||||
|
load(false);
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
$("#audit-more").addEventListener("click", (event) => busy(event.target, () => load(true)));
|
||||||
|
load(false);
|
||||||
@@ -0,0 +1,406 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
// Copyright (C) 2026 Bryan Joshua Pedini
|
||||||
|
|
||||||
|
const SVG_NS = "http://www.w3.org/2000/svg";
|
||||||
|
|
||||||
|
const ICONS = {
|
||||||
|
edit: "M4 20h4l10-10-4-4L4 16v4zM14 6l4 4",
|
||||||
|
trash: "M5 7h14M10 7V4h4v3M7 7l1 13h8l1-13M10 11v6M14 11v6",
|
||||||
|
alert: "M12 4l9 16H3L12 4zM12 10v4M12 17v1",
|
||||||
|
chevron: "M9 6l6 6-6 6",
|
||||||
|
plus: "M12 5v14M5 12h14",
|
||||||
|
close: "M6 6l12 12M18 6L6 18",
|
||||||
|
};
|
||||||
|
|
||||||
|
export function h(tag, attrs, ...children) {
|
||||||
|
const el = document.createElement(tag);
|
||||||
|
applyAttrs(el, attrs);
|
||||||
|
append(el, children);
|
||||||
|
return el;
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyAttrs(el, attrs) {
|
||||||
|
if (!attrs) return;
|
||||||
|
for (const [key, value] of Object.entries(attrs)) {
|
||||||
|
if (value === undefined || value === null || value === false) continue;
|
||||||
|
if (key === "class") {
|
||||||
|
el.className = value;
|
||||||
|
} else if (key === "text") {
|
||||||
|
el.textContent = value;
|
||||||
|
} else if (key.startsWith("on") && typeof value === "function") {
|
||||||
|
el.addEventListener(key.slice(2), value);
|
||||||
|
} else if (key === "value") {
|
||||||
|
el.value = value;
|
||||||
|
} else if (key === "checked" || key === "disabled" || key === "hidden" || key === "selected") {
|
||||||
|
el[key] = Boolean(value);
|
||||||
|
} else if (value === true) {
|
||||||
|
el.setAttribute(key, "");
|
||||||
|
} else {
|
||||||
|
el.setAttribute(key, String(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function append(el, children) {
|
||||||
|
for (const child of children.flat(Infinity)) {
|
||||||
|
if (child === undefined || child === null || child === false) continue;
|
||||||
|
el.append(child instanceof Node ? child : document.createTextNode(String(child)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function icon(name) {
|
||||||
|
const svg = document.createElementNS(SVG_NS, "svg");
|
||||||
|
svg.setAttribute("viewBox", "0 0 24 24");
|
||||||
|
svg.setAttribute("width", "16");
|
||||||
|
svg.setAttribute("height", "16");
|
||||||
|
svg.setAttribute("fill", "none");
|
||||||
|
svg.setAttribute("stroke", "currentColor");
|
||||||
|
svg.setAttribute("stroke-width", "2");
|
||||||
|
svg.setAttribute("stroke-linecap", "round");
|
||||||
|
svg.setAttribute("stroke-linejoin", "round");
|
||||||
|
svg.setAttribute("aria-hidden", "true");
|
||||||
|
svg.setAttribute("focusable", "false");
|
||||||
|
const path = document.createElementNS(SVG_NS, "path");
|
||||||
|
path.setAttribute("d", ICONS[name] || "");
|
||||||
|
svg.append(path);
|
||||||
|
return svg;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clear(el) {
|
||||||
|
el.replaceChildren();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function $(selector, root = document) {
|
||||||
|
return root.querySelector(selector);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function appData() {
|
||||||
|
const app = document.getElementById("app");
|
||||||
|
return {
|
||||||
|
app,
|
||||||
|
username: app.dataset.username || "",
|
||||||
|
role: app.dataset.role || "",
|
||||||
|
zone: app.dataset.zone || "",
|
||||||
|
targetUser: app.dataset.targetUser || "",
|
||||||
|
isAdmin: app.dataset.role === "admin",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ApiError extends Error {
|
||||||
|
constructor(status, body) {
|
||||||
|
const message = body && typeof body.error === "string" && body.error ? body.error : defaultMessage(status);
|
||||||
|
super(message);
|
||||||
|
this.status = status;
|
||||||
|
this.body = body;
|
||||||
|
this.fields = body && body.fields && typeof body.fields === "object" ? body.fields : {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function defaultMessage(status) {
|
||||||
|
switch (status) {
|
||||||
|
case 0: return "The server cannot be reached.";
|
||||||
|
case 403: return "You are not allowed to do this.";
|
||||||
|
case 404: return "Not found.";
|
||||||
|
case 409: return "The request conflicts with the current state.";
|
||||||
|
case 412: return "The data was changed by someone else.";
|
||||||
|
case 428: return "The request needs a current version of the data.";
|
||||||
|
case 429: return "Too many attempts. Try again later.";
|
||||||
|
case 503: return "The service is unavailable. Try again later.";
|
||||||
|
default: return "The request failed (status " + status + ").";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function api(method, path, options = {}) {
|
||||||
|
const headers = { Accept: "application/json" };
|
||||||
|
const init = { method, headers, credentials: "include" };
|
||||||
|
if (options.body !== undefined) {
|
||||||
|
headers["Content-Type"] = "application/json";
|
||||||
|
init.body = JSON.stringify(options.body);
|
||||||
|
}
|
||||||
|
if (options.ifMatch) headers["If-Match"] = options.ifMatch;
|
||||||
|
let url = "/api/v1" + path;
|
||||||
|
if (options.query) {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
for (const [key, value] of Object.entries(options.query)) {
|
||||||
|
if (value !== undefined && value !== null && value !== "") params.set(key, String(value));
|
||||||
|
}
|
||||||
|
const text = params.toString();
|
||||||
|
if (text) url += "?" + text;
|
||||||
|
}
|
||||||
|
let response;
|
||||||
|
try {
|
||||||
|
response = await fetch(url, init);
|
||||||
|
} catch (err) {
|
||||||
|
throw new ApiError(0, null);
|
||||||
|
}
|
||||||
|
if (response.status === 401) {
|
||||||
|
const next = location.pathname + location.search;
|
||||||
|
location.assign("/login?next=" + encodeURIComponent(next));
|
||||||
|
return new Promise(() => {});
|
||||||
|
}
|
||||||
|
const text = await response.text();
|
||||||
|
let data = null;
|
||||||
|
if (text) {
|
||||||
|
try {
|
||||||
|
data = JSON.parse(text);
|
||||||
|
} catch (err) {
|
||||||
|
data = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!response.ok) throw new ApiError(response.status, data);
|
||||||
|
return { status: response.status, data, etag: response.headers.get("ETag") };
|
||||||
|
}
|
||||||
|
|
||||||
|
export const zonePath = (zone) => "/zones/" + encodeURIComponent(zone);
|
||||||
|
export const userPath = (username) => "/users/" + encodeURIComponent(username);
|
||||||
|
|
||||||
|
export function toast(message, options = {}) {
|
||||||
|
const region = document.getElementById("toasts");
|
||||||
|
const kind = options.kind || "info";
|
||||||
|
const item = h("div", { class: "toast toast-" + kind });
|
||||||
|
item.append(h("span", { class: "toast-text", text: message }));
|
||||||
|
if (options.action) {
|
||||||
|
item.append(h("button", {
|
||||||
|
type: "button",
|
||||||
|
class: "btn btn-small",
|
||||||
|
text: options.action.label,
|
||||||
|
onclick: () => {
|
||||||
|
item.remove();
|
||||||
|
options.action.run();
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
const close = h("button", { type: "button", class: "btn btn-icon", "aria-label": "Dismiss notification", onclick: () => item.remove() });
|
||||||
|
close.append(icon("close"));
|
||||||
|
item.append(close);
|
||||||
|
region.append(item);
|
||||||
|
if (!options.action && kind !== "error") {
|
||||||
|
setTimeout(() => item.remove(), 8000);
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function flash(message) {
|
||||||
|
try {
|
||||||
|
sessionStorage.setItem("flash", message);
|
||||||
|
} catch (err) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function showFlash() {
|
||||||
|
let message = null;
|
||||||
|
try {
|
||||||
|
message = sessionStorage.getItem("flash");
|
||||||
|
sessionStorage.removeItem("flash");
|
||||||
|
} catch (err) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (message) toast(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearErrors(form) {
|
||||||
|
for (const el of form.querySelectorAll(".field-error, .form-error")) el.remove();
|
||||||
|
for (const el of form.querySelectorAll("[aria-invalid]")) el.removeAttribute("aria-invalid");
|
||||||
|
}
|
||||||
|
|
||||||
|
let errorCounter = 0;
|
||||||
|
|
||||||
|
export function showFormError(form, message) {
|
||||||
|
let box = form.querySelector(".form-error");
|
||||||
|
if (!box) {
|
||||||
|
box = h("p", { class: "alert alert-error form-error", role: "alert" });
|
||||||
|
const body = form.querySelector(".dialog-body") || form;
|
||||||
|
body.prepend(box);
|
||||||
|
}
|
||||||
|
box.textContent = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function showFieldErrors(form, fields, message) {
|
||||||
|
clearErrors(form);
|
||||||
|
const unmatched = [];
|
||||||
|
for (const [key, text] of Object.entries(fields || {})) {
|
||||||
|
const name = key.startsWith("data.") ? key.slice(5) : key;
|
||||||
|
const control = form.elements ? form.elements[name] : null;
|
||||||
|
if (control && control.nodeType === 1) {
|
||||||
|
errorCounter += 1;
|
||||||
|
const id = "field-error-" + errorCounter;
|
||||||
|
control.setAttribute("aria-invalid", "true");
|
||||||
|
control.setAttribute("aria-describedby", id);
|
||||||
|
control.insertAdjacentElement("afterend", h("p", { class: "field-error", id, text: String(text) }));
|
||||||
|
} else {
|
||||||
|
unmatched.push(key + ": " + text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (unmatched.length > 0 || message) {
|
||||||
|
showFormError(form, [message, ...unmatched].filter(Boolean).join(" "));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function handleError(err, options = {}) {
|
||||||
|
if (!(err instanceof ApiError)) {
|
||||||
|
toast("Unexpected error: " + (err && err.message ? err.message : "unknown"), { kind: "error" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (err.status === 422 && options.form) {
|
||||||
|
showFieldErrors(options.form, err.fields, Object.keys(err.fields).length === 0 ? err.message : "");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (err.status === 412) {
|
||||||
|
toast(err.message + " Reload to see the current data.", {
|
||||||
|
kind: "error",
|
||||||
|
action: { label: "Reload", run: options.reload || (() => location.reload()) },
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (options.form) {
|
||||||
|
showFormError(options.form, err.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
toast(err.message, { kind: "error" });
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function busy(button, task) {
|
||||||
|
if (button) button.disabled = true;
|
||||||
|
try {
|
||||||
|
return await task();
|
||||||
|
} finally {
|
||||||
|
if (button) button.disabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
||||||
|
|
||||||
|
function trapFocus(dialog, event) {
|
||||||
|
if (event.key !== "Tab") return;
|
||||||
|
const items = [...dialog.querySelectorAll(FOCUSABLE)].filter((el) => !el.hidden && el.offsetParent !== null);
|
||||||
|
if (items.length === 0) {
|
||||||
|
event.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const first = items[0];
|
||||||
|
const last = items[items.length - 1];
|
||||||
|
if (event.shiftKey && (document.activeElement === first || !dialog.contains(document.activeElement))) {
|
||||||
|
event.preventDefault();
|
||||||
|
last.focus();
|
||||||
|
} else if (!event.shiftKey && (document.activeElement === last || !dialog.contains(document.activeElement))) {
|
||||||
|
event.preventDefault();
|
||||||
|
first.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setupDialog(dialog) {
|
||||||
|
if (dialog.dataset.ready) return;
|
||||||
|
dialog.dataset.ready = "1";
|
||||||
|
dialog.addEventListener("keydown", (event) => trapFocus(dialog, event));
|
||||||
|
dialog.addEventListener("click", (event) => {
|
||||||
|
if (event.target === dialog) dialog.close();
|
||||||
|
});
|
||||||
|
for (const button of dialog.querySelectorAll("[data-close]")) {
|
||||||
|
button.addEventListener("click", () => dialog.close());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setupDialogs() {
|
||||||
|
for (const dialog of document.querySelectorAll("dialog")) setupDialog(dialog);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function openDialog(dialog) {
|
||||||
|
setupDialog(dialog);
|
||||||
|
const form = dialog.querySelector("form");
|
||||||
|
if (form) clearErrors(form);
|
||||||
|
dialog.showModal();
|
||||||
|
const first = dialog.querySelector("input:not([type=hidden]):not([disabled]), select:not([disabled]), textarea");
|
||||||
|
if (first) first.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function confirmDialog(options) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const titleId = "confirm-title";
|
||||||
|
const dialog = h("dialog", { class: "dialog dialog-small", "aria-labelledby": titleId });
|
||||||
|
let result = false;
|
||||||
|
const confirmButton = h("button", {
|
||||||
|
type: "button",
|
||||||
|
class: "btn " + (options.danger === false ? "btn-primary" : "btn-danger"),
|
||||||
|
text: options.confirm || "Confirm",
|
||||||
|
onclick: () => {
|
||||||
|
result = true;
|
||||||
|
dialog.close();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
dialog.append(
|
||||||
|
h("div", { class: "dialog-head" }, h("h2", { id: titleId, text: options.title })),
|
||||||
|
h("div", { class: "dialog-body" }, h("p", { text: options.message })),
|
||||||
|
h("div", { class: "dialog-actions" },
|
||||||
|
h("button", { type: "button", class: "btn", "data-close": true, text: "Cancel" }),
|
||||||
|
confirmButton),
|
||||||
|
);
|
||||||
|
dialog.addEventListener("close", () => {
|
||||||
|
dialog.remove();
|
||||||
|
resolve(result);
|
||||||
|
});
|
||||||
|
document.body.append(dialog);
|
||||||
|
setupDialog(dialog);
|
||||||
|
dialog.showModal();
|
||||||
|
confirmButton.focus();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatTime(iso) {
|
||||||
|
if (!iso) return "-";
|
||||||
|
const date = new Date(iso);
|
||||||
|
if (Number.isNaN(date.getTime())) return String(iso);
|
||||||
|
return date.toISOString().replace("T", " ").replace(/\.\d+Z$/, "").replace("Z", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatTTL(ttl) {
|
||||||
|
if (ttl === null || ttl === undefined) return "missing";
|
||||||
|
if (ttl === 0) return "default (360 s)";
|
||||||
|
return String(ttl);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function debounce(fn, ms) {
|
||||||
|
let timer = null;
|
||||||
|
return (...args) => {
|
||||||
|
clearTimeout(timer);
|
||||||
|
timer = setTimeout(() => fn(...args), ms);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseNumber(text) {
|
||||||
|
const value = String(text).trim();
|
||||||
|
return /^-?\d+$/.test(value) ? Number(value) : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function option(value, label, selected) {
|
||||||
|
return h("option", { value, text: label, selected: Boolean(selected) });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function plural(count, one, many) {
|
||||||
|
return count + " " + (count === 1 ? one : many);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function zoneLink(name) {
|
||||||
|
return h("a", { href: "/zones/" + encodeURIComponent(name), text: name });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function bindPasswordForm(form, submit) {
|
||||||
|
form.addEventListener("submit", async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
clearErrors(form);
|
||||||
|
const password = form.elements.password.value;
|
||||||
|
if (password !== form.elements.repeat.value) {
|
||||||
|
showFieldErrors(form, { repeat: "The two passwords differ." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const button = form.querySelector("button[type=submit]");
|
||||||
|
await busy(button, async () => {
|
||||||
|
try {
|
||||||
|
await submit(form);
|
||||||
|
form.reset();
|
||||||
|
} catch (err) {
|
||||||
|
handleError(err, { form });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,146 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
// Copyright (C) 2026 Bryan Joshua Pedini
|
||||||
|
|
||||||
|
import { $, ApiError, api, appData, busy, clear, clearErrors, flash, formatTTL, h, handleError, plural, showFieldErrors, toast, zonePath } from "./common.js";
|
||||||
|
|
||||||
|
const { zone } = appData();
|
||||||
|
const base = zonePath(zone);
|
||||||
|
const state = { fingerprint: null, mode: "merge", content: "" };
|
||||||
|
|
||||||
|
function entryTable(title, entries, withOld) {
|
||||||
|
if (!entries || entries.length === 0) return null;
|
||||||
|
const head = ["Name", "Type", "TTL", "Value"];
|
||||||
|
if (withOld) head.push("Old TTL");
|
||||||
|
return h("div", { class: "table-wrap" },
|
||||||
|
h("table", { class: "table" },
|
||||||
|
h("caption", { text: title + " (" + entries.length + ")" }),
|
||||||
|
h("thead", null, h("tr", null, head.map((label) => h("th", { scope: "col", text: label })))),
|
||||||
|
h("tbody", null, entries.map((entry) => h("tr", null,
|
||||||
|
h("th", { scope: "row", class: "mono", text: entry.name === "" ? "@" : entry.name }),
|
||||||
|
h("td", { text: entry.type }),
|
||||||
|
h("td", { class: "num", text: formatTTL(entry.ttl) }),
|
||||||
|
h("td", { class: "mono", text: entry.value }),
|
||||||
|
withOld ? h("td", { class: "num", text: formatTTL(entry.old_ttl) }) : null)))));
|
||||||
|
}
|
||||||
|
|
||||||
|
function skippedList(skipped) {
|
||||||
|
if (!skipped || skipped.length === 0) return null;
|
||||||
|
return h("div", null,
|
||||||
|
h("h3", { text: "Skipped (" + skipped.length + ")" }),
|
||||||
|
h("ul", { class: "list" }, skipped.map((item) => h("li", null,
|
||||||
|
item.line ? "Line " + item.line + ": " : "",
|
||||||
|
h("code", { class: "mono", text: item.text || "" }),
|
||||||
|
" ",
|
||||||
|
h("span", { class: "muted", text: item.reason })))));
|
||||||
|
}
|
||||||
|
|
||||||
|
function showErrors(list) {
|
||||||
|
const box = $("#import-errors");
|
||||||
|
clear(box);
|
||||||
|
box.hidden = !list || list.length === 0;
|
||||||
|
if (box.hidden) return;
|
||||||
|
box.append(h("div", { class: "alert alert-error", role: "alert" },
|
||||||
|
h("p", { text: "The file cannot be imported:" }),
|
||||||
|
h("ul", { class: "list" }, list.map((item) => h("li", { text: (item.line ? "Line " + item.line + ": " : "") + item.message })))));
|
||||||
|
}
|
||||||
|
|
||||||
|
function showPreview(data) {
|
||||||
|
const result = $("#import-result");
|
||||||
|
result.hidden = false;
|
||||||
|
showErrors([]);
|
||||||
|
const summary = $("#import-summary");
|
||||||
|
clear(summary);
|
||||||
|
const added = data.added || [];
|
||||||
|
const updated = data.updated || [];
|
||||||
|
const deleted = data.deleted || [];
|
||||||
|
const skipped = data.skipped || [];
|
||||||
|
summary.append(h("p", { text: plural(added.length, "addition", "additions") + ", " + plural(updated.length, "update", "updates") + ", " + plural(deleted.length, "deletion", "deletions") + ", " + (data.unchanged || 0) + " unchanged, " + plural(skipped.length, "skipped entry", "skipped entries") + "." }));
|
||||||
|
if (data.soa) {
|
||||||
|
summary.append(h("p", { text: "The SOA record is replaced: " + data.soa.ns + " " + data.soa.mbox + " refresh " + data.soa.refresh + " retry " + data.soa.retry + " expire " + data.soa.expire + " minimum " + data.soa.minttl + " TTL " + formatTTL(data.soa.ttl) + "." }));
|
||||||
|
}
|
||||||
|
for (const warning of data.warnings || []) {
|
||||||
|
summary.append(h("p", { class: "alert alert-warn", text: (warning.line ? "Line " + warning.line + ": " : "") + warning.message }));
|
||||||
|
}
|
||||||
|
const tables = $("#import-tables");
|
||||||
|
clear(tables);
|
||||||
|
for (const node of [entryTable("Additions", added, false), entryTable("Updates", updated, true), entryTable("Deletions", deleted, false), skippedList(skipped)]) {
|
||||||
|
if (node) tables.append(node);
|
||||||
|
}
|
||||||
|
state.fingerprint = data.fingerprint;
|
||||||
|
const total = added.length + updated.length + deleted.length + (data.soa ? 1 : 0);
|
||||||
|
$("#import-apply").hidden = total === 0;
|
||||||
|
if (total === 0) summary.append(h("p", { class: "muted", text: "Nothing to apply." }));
|
||||||
|
}
|
||||||
|
|
||||||
|
function currentInput() {
|
||||||
|
const form = $("#import-form");
|
||||||
|
return { mode: form.elements.mode.value, content: form.elements.content.value };
|
||||||
|
}
|
||||||
|
|
||||||
|
async function preview(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
const form = $("#import-form");
|
||||||
|
clearErrors(form);
|
||||||
|
const input = currentInput();
|
||||||
|
if (input.content.trim() === "") {
|
||||||
|
showFieldErrors(form, { content: "Paste a zone file or load one." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await busy($("#import-preview"), async () => {
|
||||||
|
try {
|
||||||
|
const { data } = await api("POST", base + "/import/preview", { body: input });
|
||||||
|
state.mode = input.mode;
|
||||||
|
state.content = input.content;
|
||||||
|
showPreview(data);
|
||||||
|
} catch (err) {
|
||||||
|
$("#import-apply").hidden = true;
|
||||||
|
state.fingerprint = null;
|
||||||
|
if (err instanceof ApiError && err.status === 422 && Array.isArray(err.body && err.body.errors)) {
|
||||||
|
$("#import-result").hidden = false;
|
||||||
|
clear($("#import-summary"));
|
||||||
|
clear($("#import-tables"));
|
||||||
|
showErrors(err.body.errors);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
handleError(err, { form });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function apply() {
|
||||||
|
if (!state.fingerprint) return;
|
||||||
|
await busy($("#import-apply"), async () => {
|
||||||
|
try {
|
||||||
|
const { data } = await api("POST", base + "/import/apply", { body: { mode: state.mode, content: state.content, fingerprint: state.fingerprint } });
|
||||||
|
flash("Import applied: " + plural(data.added || 0, "addition", "additions") + ", " + plural(data.updated || 0, "update", "updates") + ", " + plural(data.deleted || 0, "deletion", "deletions") + ".");
|
||||||
|
location.assign("/zones/" + encodeURIComponent(zone));
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof ApiError && err.status === 409) {
|
||||||
|
$("#import-apply").hidden = true;
|
||||||
|
state.fingerprint = null;
|
||||||
|
toast("The zone changed since the preview. Run the preview again.", { kind: "error" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
handleError(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#zone-link").href = "/zones/" + encodeURIComponent(zone);
|
||||||
|
$("#import-form").addEventListener("submit", preview);
|
||||||
|
$("#import-apply").addEventListener("click", apply);
|
||||||
|
$("#import-form").addEventListener("input", () => {
|
||||||
|
$("#import-apply").hidden = true;
|
||||||
|
state.fingerprint = null;
|
||||||
|
});
|
||||||
|
$("#import-file").addEventListener("change", async (event) => {
|
||||||
|
const file = event.target.files[0];
|
||||||
|
if (!file) return;
|
||||||
|
if (file.size > 2 * 1024 * 1024) {
|
||||||
|
toast("The file is larger than 2 MiB.", { kind: "error" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$("#import-content").value = await file.text();
|
||||||
|
$("#import-apply").hidden = true;
|
||||||
|
state.fingerprint = null;
|
||||||
|
});
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
// Copyright (C) 2026 Bryan Joshua Pedini
|
||||||
|
|
||||||
|
export const EDITABLE_TYPES = ["A", "AAAA", "CNAME", "NS", "MX", "TXT", "SRV", "CAA"];
|
||||||
|
export const KNOWN_TYPES = [...EDITABLE_TYPES, "SOA"];
|
||||||
|
|
||||||
|
export const FIELD_SPECS = {
|
||||||
|
A: [
|
||||||
|
{ key: "ip", label: "IPv4 address", placeholder: "192.0.2.10" },
|
||||||
|
],
|
||||||
|
AAAA: [
|
||||||
|
{ key: "ip", label: "IPv6 address", placeholder: "2001:db8::10" },
|
||||||
|
],
|
||||||
|
CNAME: [
|
||||||
|
{ key: "host", label: "Target host", placeholder: "target.example.org" },
|
||||||
|
],
|
||||||
|
NS: [
|
||||||
|
{ key: "host", label: "Name server host", placeholder: "ns1.example.org" },
|
||||||
|
],
|
||||||
|
MX: [
|
||||||
|
{ key: "preference", label: "Preference", placeholder: "10", numeric: true },
|
||||||
|
{ key: "host", label: "Mail host", placeholder: "mail.example.org" },
|
||||||
|
],
|
||||||
|
TXT: [
|
||||||
|
{ key: "text", label: "Text", multiline: true, placeholder: "v=spf1 -all" },
|
||||||
|
],
|
||||||
|
SRV: [
|
||||||
|
{ key: "priority", label: "Priority", placeholder: "10", numeric: true },
|
||||||
|
{ key: "weight", label: "Weight", placeholder: "5", numeric: true },
|
||||||
|
{ key: "port", label: "Port", placeholder: "443", numeric: true },
|
||||||
|
{ key: "target", label: "Target host", placeholder: "host.example.org" },
|
||||||
|
],
|
||||||
|
CAA: [
|
||||||
|
{ key: "flag", label: "Flag", options: [["0", "0 (not critical)"], ["128", "128 (critical)"]] },
|
||||||
|
{ key: "tag", label: "Tag", placeholder: "issue" },
|
||||||
|
{ key: "value", label: "Value", placeholder: "ca.example.net" },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
export function presentValue(record) {
|
||||||
|
const data = record.data;
|
||||||
|
if (!data || typeof data !== "object") return record.raw === null || record.raw === undefined ? "" : String(record.raw);
|
||||||
|
switch (record.type) {
|
||||||
|
case "A":
|
||||||
|
case "AAAA":
|
||||||
|
return String(data.ip);
|
||||||
|
case "CNAME":
|
||||||
|
case "NS":
|
||||||
|
return String(data.host);
|
||||||
|
case "MX":
|
||||||
|
return data.preference + " " + data.host;
|
||||||
|
case "TXT":
|
||||||
|
return '"' + data.text + '"';
|
||||||
|
case "SRV":
|
||||||
|
return data.priority + " " + data.weight + " " + data.port + " " + data.target;
|
||||||
|
case "CAA":
|
||||||
|
return data.flag + " " + data.tag + ' "' + data.value + '"';
|
||||||
|
case "SOA":
|
||||||
|
return [data.ns, data.MBox !== undefined ? data.MBox : data.mbox, data.serial === null || data.serial === undefined ? "dynamic" : data.serial, data.refresh, data.retry, data.expire, data.minttl].join(" ");
|
||||||
|
default:
|
||||||
|
return JSON.stringify(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function displayName(record) {
|
||||||
|
return record.name === "" ? "@" : record.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
function nameLabels(name) {
|
||||||
|
return name === "" ? [] : name.toLowerCase().split(".").reverse();
|
||||||
|
}
|
||||||
|
|
||||||
|
function compareLabels(a, b) {
|
||||||
|
const left = nameLabels(a);
|
||||||
|
const right = nameLabels(b);
|
||||||
|
const length = Math.min(left.length, right.length);
|
||||||
|
for (let i = 0; i < length; i += 1) {
|
||||||
|
if (left[i] < right[i]) return -1;
|
||||||
|
if (left[i] > right[i]) return 1;
|
||||||
|
}
|
||||||
|
return left.length - right.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
function typeRank(type) {
|
||||||
|
if (type === "SOA") return 0;
|
||||||
|
if (type === "NS") return 1;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function compareRecords(a, b) {
|
||||||
|
const byName = compareLabels(a.name, b.name);
|
||||||
|
if (byName !== 0) return byName;
|
||||||
|
const byRank = typeRank(a.type) - typeRank(b.type);
|
||||||
|
if (byRank !== 0) return byRank;
|
||||||
|
if (a.type !== b.type) return a.type < b.type ? -1 : 1;
|
||||||
|
const left = presentValue(a);
|
||||||
|
const right = presentValue(b);
|
||||||
|
return left.localeCompare(right, "en", { numeric: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sortRecords(records) {
|
||||||
|
return [...records].sort(compareRecords);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function matchesFilter(record, type, text) {
|
||||||
|
if (type && record.type !== type) return false;
|
||||||
|
if (!text) return true;
|
||||||
|
const needle = text.toLowerCase();
|
||||||
|
const haystack = [displayName(record), record.fqdn || "", record.type, presentValue(record)].join(" ").toLowerCase();
|
||||||
|
return haystack.includes(needle);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function stripDot(name) {
|
||||||
|
return name.endsWith(".") ? name.slice(0, -1) : name;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function previewName(input, zone) {
|
||||||
|
const apex = zone.endsWith(".") ? zone : zone + ".";
|
||||||
|
let text = input.trim().toLowerCase();
|
||||||
|
if (text === "" || text === "@") return { name: "", fqdn: apex, error: "" };
|
||||||
|
if (text.endsWith("." + apex)) {
|
||||||
|
text = text.slice(0, -(apex.length + 1));
|
||||||
|
} else if (text === apex) {
|
||||||
|
return { name: "", fqdn: apex, error: "" };
|
||||||
|
} else if (text.endsWith(".")) {
|
||||||
|
return { name: "", fqdn: "", error: "The name ends with a dot and is outside " + apex };
|
||||||
|
}
|
||||||
|
return { name: text, fqdn: text + "." + apex, error: "" };
|
||||||
|
}
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
// Copyright (C) 2026 Bryan Joshua Pedini
|
||||||
|
|
||||||
|
import { $, api, appData, bindPasswordForm, busy, clear, confirmDialog, flash, formatTime, h, handleError, icon, option, setupDialogs, toast, userPath, zoneLink, zonePath } from "./common.js";
|
||||||
|
|
||||||
|
const { targetUser, username: self } = appData();
|
||||||
|
const base = userPath(targetUser);
|
||||||
|
const isSelf = targetUser === self;
|
||||||
|
const state = { user: null };
|
||||||
|
|
||||||
|
function summaryRow(dl, term, value) {
|
||||||
|
dl.append(h("dt", { text: term }), h("dd", { text: value }));
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderSummary(user) {
|
||||||
|
const dl = $("#user-summary");
|
||||||
|
clear(dl);
|
||||||
|
summaryRow(dl, "Role", user.role);
|
||||||
|
summaryRow(dl, "Created (UTC)", formatTime(user.created_at));
|
||||||
|
summaryRow(dl, "Last login (UTC)", formatTime(user.last_login_at));
|
||||||
|
summaryRow(dl, "State", user.deleted_at ? "deleted " + formatTime(user.deleted_at) : "active");
|
||||||
|
$("#user-status").textContent = "";
|
||||||
|
const badge = $("#user-state");
|
||||||
|
badge.hidden = !user.deleted_at;
|
||||||
|
badge.textContent = "deleted";
|
||||||
|
}
|
||||||
|
|
||||||
|
function zoneItem(entry, removable) {
|
||||||
|
const item = h("li", null, entry.exists ? zoneLink(entry.zone) : h("span", { class: "mono", text: entry.zone }));
|
||||||
|
if (!entry.exists) item.append(" ", h("span", { class: "badge badge-warning", text: "zone not found" }));
|
||||||
|
if (removable) {
|
||||||
|
item.append(" ", h("button", { type: "button", class: "btn btn-small btn-danger", "aria-label": "Remove zone " + entry.zone, onclick: () => removeZone(entry.zone) }, icon("trash"), " Remove"));
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function renderZones(user) {
|
||||||
|
const readonly = Boolean(user.deleted_at);
|
||||||
|
const zones = user.zones || [];
|
||||||
|
if (readonly) {
|
||||||
|
const list = $("#user-zones-readonly");
|
||||||
|
clear(list);
|
||||||
|
for (const entry of zones) list.append(zoneItem(entry, false));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const list = $("#user-zones");
|
||||||
|
clear(list);
|
||||||
|
for (const entry of zones) list.append(zoneItem(entry, true));
|
||||||
|
$("#user-zones-status").textContent = zones.length === 0 ? "No zone is delegated to this user." : "";
|
||||||
|
const form = $("#zone-add-form");
|
||||||
|
const pick = $("#user-zone-pick");
|
||||||
|
clear(pick);
|
||||||
|
if (user.role === "admin") {
|
||||||
|
form.hidden = true;
|
||||||
|
$("#user-zones-status").textContent = zones.length === 0 ? "Administrators see every zone and need no delegation." : "Administrators need no delegation; these delegations apply again if the user is demoted.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
form.hidden = false;
|
||||||
|
try {
|
||||||
|
const { data } = await api("GET", "/zones");
|
||||||
|
const have = new Set(zones.map((entry) => entry.zone));
|
||||||
|
const candidates = (data.zones || []).filter((zone) => !have.has(zone.name));
|
||||||
|
for (const zone of candidates) pick.append(option(zone.name, zone.name, false));
|
||||||
|
if (candidates.length === 0) pick.append(option("", "No zone available", true));
|
||||||
|
pick.disabled = candidates.length === 0;
|
||||||
|
form.querySelector("button").disabled = candidates.length === 0;
|
||||||
|
} catch (err) {
|
||||||
|
handleError(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
try {
|
||||||
|
const { data } = await api("GET", base);
|
||||||
|
state.user = data;
|
||||||
|
} catch (err) {
|
||||||
|
$("#user-status").textContent = "The user could not be loaded.";
|
||||||
|
handleError(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const user = state.user;
|
||||||
|
renderSummary(user);
|
||||||
|
if (isSelf) return;
|
||||||
|
const deleted = Boolean(user.deleted_at);
|
||||||
|
$("#user-controls").hidden = deleted;
|
||||||
|
$("#user-readonly").hidden = !deleted;
|
||||||
|
$("#user-role").value = user.role;
|
||||||
|
await renderZones(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function removeZone(zone) {
|
||||||
|
const ok = await confirmDialog({ title: "Remove zone", message: "Remove the delegation of " + zone + " from " + targetUser + "?", confirm: "Remove" });
|
||||||
|
if (!ok) return;
|
||||||
|
try {
|
||||||
|
await api("DELETE", zonePath(zone) + "/users/" + encodeURIComponent(targetUser));
|
||||||
|
toast("Delegation removed.");
|
||||||
|
await load();
|
||||||
|
} catch (err) {
|
||||||
|
handleError(err, { reload: load });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setup() {
|
||||||
|
$("#role-form").addEventListener("submit", async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
await busy(event.target.querySelector("button"), async () => {
|
||||||
|
try {
|
||||||
|
await api("PUT", base + "/role", { body: { role: $("#user-role").value } });
|
||||||
|
toast("Role saved.");
|
||||||
|
await load();
|
||||||
|
} catch (err) {
|
||||||
|
handleError(err);
|
||||||
|
await load();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
bindPasswordForm($("#password-form"), async (form) => {
|
||||||
|
await api("PUT", base + "/password", { body: { password: form.elements.password.value } });
|
||||||
|
toast("Password set. The sessions of " + targetUser + " ended.");
|
||||||
|
});
|
||||||
|
$("#zone-add-form").addEventListener("submit", async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const zone = $("#user-zone-pick").value;
|
||||||
|
if (!zone) return;
|
||||||
|
await busy(event.target.querySelector("button"), async () => {
|
||||||
|
try {
|
||||||
|
await api("PUT", zonePath(zone) + "/users/" + encodeURIComponent(targetUser));
|
||||||
|
toast("Zone delegated.");
|
||||||
|
await load();
|
||||||
|
} catch (err) {
|
||||||
|
handleError(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
const confirmInput = $("#user-delete-confirm");
|
||||||
|
const deleteButton = $("#user-delete");
|
||||||
|
confirmInput.addEventListener("input", () => {
|
||||||
|
deleteButton.disabled = confirmInput.value.trim() !== targetUser;
|
||||||
|
});
|
||||||
|
$("#user-delete-form").addEventListener("submit", async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
if (deleteButton.disabled) return;
|
||||||
|
await busy(deleteButton, async () => {
|
||||||
|
try {
|
||||||
|
await api("DELETE", base, { body: { confirm: confirmInput.value.trim() } });
|
||||||
|
flash("User " + targetUser + " deleted.");
|
||||||
|
location.assign("/users");
|
||||||
|
} catch (err) {
|
||||||
|
handleError(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setupDialogs();
|
||||||
|
if (!isSelf) setup();
|
||||||
|
load();
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
// Copyright (C) 2026 Bryan Joshua Pedini
|
||||||
|
|
||||||
|
import { $, api, busy, clear, clearErrors, formatTime, h, handleError, openDialog, setupDialogs, showFieldErrors, toast, userPath } from "./common.js";
|
||||||
|
|
||||||
|
const state = { users: [] };
|
||||||
|
|
||||||
|
function render() {
|
||||||
|
const body = $("#users-body");
|
||||||
|
clear(body);
|
||||||
|
for (const user of state.users) {
|
||||||
|
const deleted = Boolean(user.deleted_at);
|
||||||
|
body.append(h("tr", { class: deleted ? "row-muted" : null },
|
||||||
|
h("th", { scope: "row" }, h("a", { href: userPath(user.username), text: user.username })),
|
||||||
|
h("td", { text: user.role }),
|
||||||
|
h("td", { class: "num", text: user.zone_count }),
|
||||||
|
h("td", { class: "mono", text: formatTime(user.created_at) }),
|
||||||
|
h("td", { class: "mono", text: formatTime(user.last_login_at) }),
|
||||||
|
h("td", null, deleted ? h("span", { class: "badge badge-muted", text: "deleted " + formatTime(user.deleted_at) }) : h("span", { class: "badge badge-ok", text: "active" }))));
|
||||||
|
}
|
||||||
|
$("#users-status").textContent = state.users.length === 0 ? "No users." : state.users.length + (state.users.length === 1 ? " user." : " users.");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
try {
|
||||||
|
const { data } = await api("GET", "/users", { query: { deleted: $("#show-deleted").checked ? "true" : "" } });
|
||||||
|
state.users = data.users || [];
|
||||||
|
render();
|
||||||
|
} catch (err) {
|
||||||
|
$("#users-status").textContent = "The users could not be loaded.";
|
||||||
|
handleError(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupCreate() {
|
||||||
|
const dialog = $("#user-dialog");
|
||||||
|
const form = $("#user-form");
|
||||||
|
$("#new-user").addEventListener("click", () => {
|
||||||
|
form.reset();
|
||||||
|
openDialog(dialog);
|
||||||
|
});
|
||||||
|
form.addEventListener("submit", async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
clearErrors(form);
|
||||||
|
if (form.elements.password.value !== form.elements.repeat.value) {
|
||||||
|
showFieldErrors(form, { repeat: "The two passwords differ." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await busy(form.querySelector("button[type=submit]"), async () => {
|
||||||
|
try {
|
||||||
|
await api("POST", "/users", { body: { username: form.elements.username.value.trim(), role: form.elements.role.value, password: form.elements.password.value } });
|
||||||
|
} catch (err) {
|
||||||
|
handleError(err, { form });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dialog.close();
|
||||||
|
form.reset();
|
||||||
|
toast("User created.");
|
||||||
|
await load();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setupDialogs();
|
||||||
|
setupCreate();
|
||||||
|
$("#show-deleted").addEventListener("change", load);
|
||||||
|
load();
|
||||||
@@ -0,0 +1,536 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
// Copyright (C) 2026 Bryan Joshua Pedini
|
||||||
|
|
||||||
|
import { $, api, appData, busy, clear, clearErrors, confirmDialog, flash, formatTTL, handleError, h, icon, openDialog, option, parseNumber, plural, setupDialogs, showFieldErrors, showFlash, toast, zonePath } from "./common.js";
|
||||||
|
import { EDITABLE_TYPES, FIELD_SPECS, displayName, matchesFilter, presentValue, previewName, sortRecords, stripDot } from "./records.js";
|
||||||
|
|
||||||
|
const PAGE_SIZE = 100;
|
||||||
|
const { zone: zoneParam, isAdmin } = appData();
|
||||||
|
const base = zonePath(zoneParam);
|
||||||
|
|
||||||
|
const state = {
|
||||||
|
summary: null,
|
||||||
|
records: [],
|
||||||
|
problems: [],
|
||||||
|
type: "",
|
||||||
|
text: "",
|
||||||
|
page: 0,
|
||||||
|
selected: new Set(),
|
||||||
|
};
|
||||||
|
|
||||||
|
function zoneName() {
|
||||||
|
return state.summary ? state.summary.name : zoneParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
function soaRow() {
|
||||||
|
return state.records.find((record) => record.type === "SOA" && record.name === "") || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function problemBadge(problem) {
|
||||||
|
return h("li", { class: "problem problem-" + problem.severity },
|
||||||
|
h("span", { class: "badge badge-" + (problem.severity === "error" ? "error" : "warning"), text: problem.severity }),
|
||||||
|
" ",
|
||||||
|
h("code", { text: problem.code }),
|
||||||
|
" ",
|
||||||
|
problem.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderSoa() {
|
||||||
|
const summary = $("#soa-summary");
|
||||||
|
const status = $("#soa-status");
|
||||||
|
const managed = $("#soa-managed");
|
||||||
|
const edit = $("#soa-edit");
|
||||||
|
clear(summary);
|
||||||
|
managed.hidden = true;
|
||||||
|
const soa = state.summary ? state.summary.soa : null;
|
||||||
|
edit.disabled = !(soa || soaRow());
|
||||||
|
if (!soa) {
|
||||||
|
status.textContent = soaRow() ? "The SOA record cannot be read. Edit it to replace it." : "This zone has no SOA record.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
status.textContent = "";
|
||||||
|
const dynamic = soa.serial === null || soa.serial === undefined;
|
||||||
|
const items = [
|
||||||
|
["Primary name server", soa.ns],
|
||||||
|
["Hostmaster", soa.mbox],
|
||||||
|
["Serial", dynamic ? "dynamic (Unix time)" : String(soa.serial)],
|
||||||
|
["Refresh", String(soa.refresh)],
|
||||||
|
["Retry", String(soa.retry)],
|
||||||
|
["Expire", String(soa.expire)],
|
||||||
|
["Minimum TTL", String(soa.minttl)],
|
||||||
|
["TTL", formatTTL(soa.ttl)],
|
||||||
|
];
|
||||||
|
for (const [term, value] of items) {
|
||||||
|
summary.append(h("dt", { text: term }), h("dd", { class: "mono", text: value }));
|
||||||
|
}
|
||||||
|
managed.hidden = !dynamic;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderProblems() {
|
||||||
|
const panel = $("#problems-panel");
|
||||||
|
const list = $("#problems-list");
|
||||||
|
clear(list);
|
||||||
|
panel.hidden = state.problems.length === 0;
|
||||||
|
$("#problems-title").textContent = "Problems (" + state.problems.length + ")";
|
||||||
|
for (const problem of state.problems) {
|
||||||
|
const where = problem.name === null || problem.name === undefined ? "zone" : (problem.name === "" ? "@" : problem.name) + (problem.type ? " " + problem.type : "");
|
||||||
|
const item = problemBadge(problem);
|
||||||
|
item.append(" ", h("span", { class: "muted", text: "(" + where + ")" }));
|
||||||
|
list.append(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function typeOptions() {
|
||||||
|
const select = $("#filter-type");
|
||||||
|
const types = [...new Set(state.records.map((record) => record.type))].sort();
|
||||||
|
if (state.type && !types.includes(state.type)) state.type = "";
|
||||||
|
clear(select);
|
||||||
|
select.append(option("", "All types", state.type === ""));
|
||||||
|
for (const type of types) select.append(option(type, type, state.type === type));
|
||||||
|
}
|
||||||
|
|
||||||
|
function visibleRecords() {
|
||||||
|
return sortRecords(state.records).filter((record) => matchesFilter(record, state.type, state.text));
|
||||||
|
}
|
||||||
|
|
||||||
|
function problemsCell(record) {
|
||||||
|
const list = h("ul", { class: "problems" });
|
||||||
|
for (const problem of record.problems || []) list.append(problemBadge(problem));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderRecords() {
|
||||||
|
const body = $("#records-body");
|
||||||
|
const all = visibleRecords();
|
||||||
|
const pages = Math.max(1, Math.ceil(all.length / PAGE_SIZE));
|
||||||
|
if (state.page >= pages) state.page = pages - 1;
|
||||||
|
const rows = all.slice(state.page * PAGE_SIZE, (state.page + 1) * PAGE_SIZE);
|
||||||
|
clear(body);
|
||||||
|
for (const record of rows) body.append(recordRow(record));
|
||||||
|
const status = $("#records-status");
|
||||||
|
if (state.records.length === 0) status.textContent = "This zone has no records.";
|
||||||
|
else if (all.length === 0) status.textContent = "No record matches the filter.";
|
||||||
|
else status.textContent = plural(all.length, "record", "records") + (all.length === state.records.length ? "." : " of " + state.records.length + ".");
|
||||||
|
const pager = $("#pager");
|
||||||
|
pager.hidden = all.length <= PAGE_SIZE;
|
||||||
|
$("#page-info").textContent = "Page " + (state.page + 1) + " of " + pages;
|
||||||
|
$("#page-prev").disabled = state.page === 0;
|
||||||
|
$("#page-next").disabled = state.page >= pages - 1;
|
||||||
|
updateSelection();
|
||||||
|
}
|
||||||
|
|
||||||
|
function recordRow(record) {
|
||||||
|
const label = displayName(record) + " " + record.type;
|
||||||
|
const broken = record.data === null || record.data === undefined;
|
||||||
|
const isSoa = record.type === "SOA";
|
||||||
|
const checkbox = h("input", {
|
||||||
|
type: "checkbox",
|
||||||
|
disabled: isSoa,
|
||||||
|
checked: state.selected.has(record.id),
|
||||||
|
"aria-label": "Select " + label,
|
||||||
|
onchange: (event) => {
|
||||||
|
if (event.target.checked) state.selected.add(record.id);
|
||||||
|
else state.selected.delete(record.id);
|
||||||
|
updateSelection();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const hasError = (record.problems || []).some((problem) => problem.severity === "error");
|
||||||
|
const hasWarning = (record.problems || []).length > 0;
|
||||||
|
const value = h("td", { class: "value" },
|
||||||
|
h("code", { class: broken ? "mono raw" : "mono", text: presentValue(record) }),
|
||||||
|
(record.problems || []).length > 0 ? problemsCell(record) : null);
|
||||||
|
const edit = h("button", { type: "button", class: "btn btn-small", "aria-label": "Edit " + label, onclick: () => (isSoa ? openSoa() : openRecord(record)) }, icon("edit"), " Edit");
|
||||||
|
const actions = h("td", { class: "actions-cell" }, edit);
|
||||||
|
if (!isSoa) {
|
||||||
|
actions.append(" ", h("button", { type: "button", class: "btn btn-small btn-danger", "aria-label": "Delete " + label, onclick: () => deleteRecord(record) }, icon("trash"), " Delete"));
|
||||||
|
}
|
||||||
|
return h("tr", { class: hasError ? "row-error" : hasWarning ? "row-warning" : null },
|
||||||
|
h("td", { class: "check" }, checkbox),
|
||||||
|
h("th", { scope: "row", title: record.fqdn || "" }, h("span", { class: "mono", text: displayName(record) })),
|
||||||
|
h("td", { text: record.type }),
|
||||||
|
h("td", { class: "num", text: formatTTL(record.ttl) }),
|
||||||
|
value,
|
||||||
|
actions);
|
||||||
|
}
|
||||||
|
|
||||||
|
function pageRows() {
|
||||||
|
return visibleRecords().slice(state.page * PAGE_SIZE, (state.page + 1) * PAGE_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateSelection() {
|
||||||
|
const ids = new Set(state.records.map((record) => record.id));
|
||||||
|
for (const id of state.selected) if (!ids.has(id)) state.selected.delete(id);
|
||||||
|
const button = $("#bulk-delete");
|
||||||
|
button.disabled = state.selected.size === 0;
|
||||||
|
button.textContent = state.selected.size === 0 ? "Delete selected" : "Delete selected (" + state.selected.size + ")";
|
||||||
|
const selectable = pageRows().filter((record) => record.type !== "SOA");
|
||||||
|
$("#select-all").checked = selectable.length > 0 && selectable.every((record) => state.selected.has(record.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
const results = await Promise.allSettled([
|
||||||
|
api("GET", base),
|
||||||
|
api("GET", base + "/records"),
|
||||||
|
api("GET", base + "/check"),
|
||||||
|
]);
|
||||||
|
const [summary, records, check] = results;
|
||||||
|
if (summary.status === "rejected") {
|
||||||
|
$("#soa-status").textContent = "The zone could not be loaded.";
|
||||||
|
$("#records-status").textContent = "The records could not be loaded.";
|
||||||
|
handleError(summary.reason);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
state.summary = summary.value.data;
|
||||||
|
state.records = records.status === "fulfilled" ? records.value.data.records || [] : [];
|
||||||
|
state.problems = check.status === "fulfilled" ? check.value.data.problems || [] : [];
|
||||||
|
if (records.status === "rejected") handleError(records.reason);
|
||||||
|
$("#zone-title").textContent = state.summary.name;
|
||||||
|
renderSoa();
|
||||||
|
renderProblems();
|
||||||
|
typeOptions();
|
||||||
|
renderRecords();
|
||||||
|
if (isAdmin) loadUsers();
|
||||||
|
}
|
||||||
|
|
||||||
|
function numberFields(form, names) {
|
||||||
|
const out = {};
|
||||||
|
for (const name of names) out[name] = parseNumber(form.elements[name].value);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
function soaBody(form) {
|
||||||
|
return {
|
||||||
|
ns: form.elements.ns.value.trim(),
|
||||||
|
mbox: form.elements.mbox.value.trim(),
|
||||||
|
...numberFields(form, ["ttl", "refresh", "retry", "expire", "minttl"]),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function openSoa() {
|
||||||
|
const form = $("#soa-form");
|
||||||
|
const soa = state.summary ? state.summary.soa : null;
|
||||||
|
const row = soaRow();
|
||||||
|
$("#soa-broken").hidden = Boolean(soa);
|
||||||
|
const values = soa || { ns: "", mbox: "", ttl: row && Number.isInteger(row.ttl) && row.ttl >= 0 ? row.ttl : 3600, refresh: 3600, retry: 600, expire: 604800, minttl: 300 };
|
||||||
|
for (const name of ["ns", "mbox", "ttl", "refresh", "retry", "expire", "minttl"]) form.elements[name].value = String(values[name]);
|
||||||
|
openDialog($("#soa-dialog"));
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupSoa() {
|
||||||
|
const dialog = $("#soa-dialog");
|
||||||
|
const form = $("#soa-form");
|
||||||
|
$("#soa-edit").addEventListener("click", openSoa);
|
||||||
|
form.addEventListener("submit", async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
clearErrors(form);
|
||||||
|
const etag = (state.summary && state.summary.soa ? state.summary.soa.etag : null) || (soaRow() ? soaRow().etag : null);
|
||||||
|
await busy(form.querySelector("button[type=submit]"), async () => {
|
||||||
|
try {
|
||||||
|
const { data } = await api("PUT", base + "/soa", { body: soaBody(form), ifMatch: etag });
|
||||||
|
dialog.close();
|
||||||
|
reportWarnings("SOA saved.", data);
|
||||||
|
await load();
|
||||||
|
} catch (err) {
|
||||||
|
handleError(err, { form, reload: load });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$("#soa-managed").addEventListener("click", async (event) => {
|
||||||
|
const soa = state.summary && state.summary.soa;
|
||||||
|
if (!soa) return;
|
||||||
|
await busy(event.target, async () => {
|
||||||
|
try {
|
||||||
|
const body = { ns: soa.ns, mbox: soa.mbox, ttl: soa.ttl, refresh: soa.refresh, retry: soa.retry, expire: soa.expire, minttl: soa.minttl, managed_serial: true };
|
||||||
|
await api("PUT", base + "/soa", { body, ifMatch: soa.etag });
|
||||||
|
toast("The zone now uses a managed serial.");
|
||||||
|
await load();
|
||||||
|
} catch (err) {
|
||||||
|
handleError(err, { reload: load });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function reportWarnings(message, data) {
|
||||||
|
const warnings = data && Array.isArray(data.warnings) ? data.warnings : [];
|
||||||
|
toast(message);
|
||||||
|
for (const warning of warnings) toast("Warning: " + warning.message, { kind: "warning" });
|
||||||
|
}
|
||||||
|
|
||||||
|
const recordForm = {
|
||||||
|
editing: null,
|
||||||
|
ttlTouched: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
function fieldId(key) {
|
||||||
|
return "rec-f-" + key;
|
||||||
|
}
|
||||||
|
|
||||||
|
function readTypeValues(form) {
|
||||||
|
const values = {};
|
||||||
|
for (const control of form.querySelectorAll("#rec-fields [name]")) values[control.name] = control.value;
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildTypeFields(type, values) {
|
||||||
|
const container = $("#rec-fields");
|
||||||
|
clear(container);
|
||||||
|
const specs = FIELD_SPECS[type] || [];
|
||||||
|
for (const spec of specs) {
|
||||||
|
const id = fieldId(spec.key);
|
||||||
|
let control;
|
||||||
|
const current = values[spec.key] === undefined || values[spec.key] === null ? "" : String(values[spec.key]);
|
||||||
|
if (spec.options) {
|
||||||
|
control = h("select", { id, name: spec.key }, spec.options.map(([value, label]) => option(value, label, value === current)));
|
||||||
|
} else if (spec.multiline) {
|
||||||
|
control = h("textarea", { id, name: spec.key, rows: 3, autocomplete: "off", spellcheck: "false", placeholder: spec.placeholder, value: current });
|
||||||
|
} else {
|
||||||
|
control = h("input", {
|
||||||
|
id,
|
||||||
|
name: spec.key,
|
||||||
|
type: "text",
|
||||||
|
autocomplete: "off",
|
||||||
|
autocapitalize: "none",
|
||||||
|
spellcheck: "false",
|
||||||
|
inputmode: spec.numeric ? "numeric" : null,
|
||||||
|
placeholder: spec.placeholder,
|
||||||
|
value: current,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
container.append(h("div", { class: "field" }, h("label", { for: id, text: spec.label }), control));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updatePreview() {
|
||||||
|
const form = $("#record-form");
|
||||||
|
const result = previewName(form.elements.name.value, zoneName());
|
||||||
|
const hint = $("#rec-fqdn");
|
||||||
|
hint.textContent = result.error ? result.error : "Full name: " + result.fqdn;
|
||||||
|
if (!recordForm.ttlTouched && !recordForm.editing) applyRrsetTtl(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyRrsetTtl(result) {
|
||||||
|
const form = $("#record-form");
|
||||||
|
const type = form.elements.type.value;
|
||||||
|
let ttl = 3600;
|
||||||
|
if (!result.error) {
|
||||||
|
const match = state.records.find((record) => record.name === result.name && record.type === type && Number.isInteger(record.ttl) && record.ttl >= 0);
|
||||||
|
if (match) ttl = match.ttl;
|
||||||
|
}
|
||||||
|
form.elements.ttl.value = String(ttl);
|
||||||
|
}
|
||||||
|
|
||||||
|
function openRecord(record) {
|
||||||
|
const form = $("#record-form");
|
||||||
|
const broken = Boolean(record) && (record.data === null || record.data === undefined);
|
||||||
|
const known = Boolean(record) && EDITABLE_TYPES.includes(record.type);
|
||||||
|
recordForm.editing = record || null;
|
||||||
|
recordForm.ttlTouched = Boolean(record);
|
||||||
|
$("#record-dialog-title").textContent = record ? "Edit record" : "Add record";
|
||||||
|
$("#record-broken").hidden = !broken;
|
||||||
|
$("#record-raw").textContent = broken && record.raw !== null && record.raw !== undefined ? String(record.raw) : "";
|
||||||
|
const select = form.elements.type;
|
||||||
|
clear(select);
|
||||||
|
if (record && !known) select.append(option("", "Select a type", true));
|
||||||
|
for (const type of EDITABLE_TYPES) select.append(option(type, type, record ? record.type === type : type === "A"));
|
||||||
|
select.disabled = Boolean(record) && known;
|
||||||
|
form.elements.name.value = record ? displayName(record) : "";
|
||||||
|
const ttl = record && Number.isInteger(record.ttl) && record.ttl >= 0 ? record.ttl : 3600;
|
||||||
|
form.elements.ttl.value = String(ttl);
|
||||||
|
buildTypeFields(select.value, record && !broken ? record.data : {});
|
||||||
|
$("#rec-submit").textContent = record ? "Save changes" : "Add record";
|
||||||
|
updatePreview();
|
||||||
|
openDialog($("#record-dialog"));
|
||||||
|
}
|
||||||
|
|
||||||
|
function recordBody(form) {
|
||||||
|
const type = form.elements.type.value;
|
||||||
|
const data = {};
|
||||||
|
for (const spec of FIELD_SPECS[type] || []) {
|
||||||
|
const value = form.elements[spec.key].value;
|
||||||
|
data[spec.key] = spec.numeric || spec.options ? parseNumber(value) : spec.multiline ? value : value.trim();
|
||||||
|
}
|
||||||
|
return { name: form.elements.name.value.trim(), type, ttl: parseNumber(form.elements.ttl.value), data };
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupRecordForm() {
|
||||||
|
const dialog = $("#record-dialog");
|
||||||
|
const form = $("#record-form");
|
||||||
|
$("#record-add").addEventListener("click", () => openRecord(null));
|
||||||
|
form.elements.name.addEventListener("input", updatePreview);
|
||||||
|
form.elements.ttl.addEventListener("input", () => {
|
||||||
|
recordForm.ttlTouched = true;
|
||||||
|
});
|
||||||
|
form.elements.type.addEventListener("change", () => {
|
||||||
|
buildTypeFields(form.elements.type.value, readTypeValues(form));
|
||||||
|
if (!recordForm.ttlTouched && !recordForm.editing) updatePreview();
|
||||||
|
});
|
||||||
|
form.addEventListener("submit", async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
clearErrors(form);
|
||||||
|
if (!form.elements.type.value) {
|
||||||
|
showFieldErrors(form, { type: "Select a type." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const editing = recordForm.editing;
|
||||||
|
await busy(form.querySelector("button[type=submit]"), async () => {
|
||||||
|
try {
|
||||||
|
const body = recordBody(form);
|
||||||
|
const result = editing
|
||||||
|
? await api("PUT", base + "/records/" + editing.id, { body, ifMatch: editing.etag })
|
||||||
|
: await api("POST", base + "/records", { body });
|
||||||
|
dialog.close();
|
||||||
|
reportWarnings(editing ? "Record saved." : "Record added.", result.data);
|
||||||
|
await load();
|
||||||
|
} catch (err) {
|
||||||
|
handleError(err, { form, reload: () => { dialog.close(); return load(); } });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteRecord(record) {
|
||||||
|
const label = displayName(record) + " " + record.type + " " + presentValue(record);
|
||||||
|
const ok = await confirmDialog({ title: "Delete record", message: "Delete " + label + "?", confirm: "Delete" });
|
||||||
|
if (!ok) return;
|
||||||
|
try {
|
||||||
|
await api("DELETE", base + "/records/" + record.id, { ifMatch: record.etag });
|
||||||
|
state.selected.delete(record.id);
|
||||||
|
toast("Record deleted.");
|
||||||
|
await load();
|
||||||
|
} catch (err) {
|
||||||
|
handleError(err, { reload: load });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function bulkDelete() {
|
||||||
|
const items = state.records.filter((record) => state.selected.has(record.id) && record.type !== "SOA");
|
||||||
|
if (items.length === 0) return;
|
||||||
|
const ok = await confirmDialog({ title: "Delete records", message: "Delete " + plural(items.length, "selected record", "selected records") + "? Either all of them are deleted or none.", confirm: "Delete" });
|
||||||
|
if (!ok) return;
|
||||||
|
try {
|
||||||
|
await api("POST", base + "/records/delete", { body: { records: items.map((record) => ({ id: record.id, etag: record.etag })) } });
|
||||||
|
state.selected.clear();
|
||||||
|
toast(plural(items.length, "record", "records") + " deleted.");
|
||||||
|
await load();
|
||||||
|
} catch (err) {
|
||||||
|
handleError(err, { reload: load });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupTable() {
|
||||||
|
$("#filter-type").addEventListener("change", (event) => {
|
||||||
|
state.type = event.target.value;
|
||||||
|
state.page = 0;
|
||||||
|
renderRecords();
|
||||||
|
});
|
||||||
|
$("#filter-text").addEventListener("input", (event) => {
|
||||||
|
state.text = event.target.value;
|
||||||
|
state.page = 0;
|
||||||
|
renderRecords();
|
||||||
|
});
|
||||||
|
$("#page-prev").addEventListener("click", () => {
|
||||||
|
state.page -= 1;
|
||||||
|
renderRecords();
|
||||||
|
});
|
||||||
|
$("#page-next").addEventListener("click", () => {
|
||||||
|
state.page += 1;
|
||||||
|
renderRecords();
|
||||||
|
});
|
||||||
|
$("#select-all").addEventListener("change", (event) => {
|
||||||
|
for (const record of pageRows()) {
|
||||||
|
if (record.type === "SOA") continue;
|
||||||
|
if (event.target.checked) state.selected.add(record.id);
|
||||||
|
else state.selected.delete(record.id);
|
||||||
|
}
|
||||||
|
renderRecords();
|
||||||
|
});
|
||||||
|
$("#bulk-delete").addEventListener("click", bulkDelete);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadUsers() {
|
||||||
|
const list = $("#zone-users");
|
||||||
|
const status = $("#zone-users-status");
|
||||||
|
const pick = $("#zone-user-pick");
|
||||||
|
try {
|
||||||
|
const [delegated, users] = await Promise.all([api("GET", base + "/users"), api("GET", "/users")]);
|
||||||
|
const current = delegated.data.users || [];
|
||||||
|
const names = new Set(current.map((user) => user.username));
|
||||||
|
clear(list);
|
||||||
|
for (const user of current) {
|
||||||
|
list.append(h("li", null,
|
||||||
|
h("span", { class: "mono", text: user.username }),
|
||||||
|
" ",
|
||||||
|
h("button", { type: "button", class: "btn btn-small btn-danger", "aria-label": "Remove " + user.username + " from this zone", onclick: () => removeUser(user.username) }, icon("trash"), " Remove")));
|
||||||
|
}
|
||||||
|
status.textContent = current.length === 0 ? "The zone is not delegated to any user." : "";
|
||||||
|
const candidates = (users.data.users || []).filter((user) => user.role === "user" && !names.has(user.username));
|
||||||
|
clear(pick);
|
||||||
|
for (const user of candidates) pick.append(option(user.username, user.username, false));
|
||||||
|
$("#zone-user-add").disabled = candidates.length === 0;
|
||||||
|
pick.disabled = candidates.length === 0;
|
||||||
|
if (candidates.length === 0) pick.append(option("", "No user available", true));
|
||||||
|
} catch (err) {
|
||||||
|
status.textContent = "The users could not be loaded.";
|
||||||
|
handleError(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function removeUser(username) {
|
||||||
|
const ok = await confirmDialog({ title: "Remove user", message: "Remove " + username + " from this zone?", confirm: "Remove" });
|
||||||
|
if (!ok) return;
|
||||||
|
try {
|
||||||
|
await api("DELETE", base + "/users/" + encodeURIComponent(username));
|
||||||
|
toast("Delegation removed.");
|
||||||
|
await loadUsers();
|
||||||
|
} catch (err) {
|
||||||
|
handleError(err, { reload: loadUsers });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupAdmin() {
|
||||||
|
$("#zone-user-form").addEventListener("submit", async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const username = $("#zone-user-pick").value;
|
||||||
|
if (!username) return;
|
||||||
|
await busy($("#zone-user-add"), async () => {
|
||||||
|
try {
|
||||||
|
await api("PUT", base + "/users/" + encodeURIComponent(username));
|
||||||
|
toast("Zone delegated to " + username + ".");
|
||||||
|
await loadUsers();
|
||||||
|
} catch (err) {
|
||||||
|
handleError(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
const confirmInput = $("#zone-delete-confirm");
|
||||||
|
const deleteButton = $("#zone-delete");
|
||||||
|
confirmInput.addEventListener("input", () => {
|
||||||
|
deleteButton.disabled = stripDot(confirmInput.value.trim().toLowerCase()) !== stripDot(zoneName().toLowerCase());
|
||||||
|
});
|
||||||
|
$("#zone-delete-form").addEventListener("submit", async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
if (deleteButton.disabled) return;
|
||||||
|
await busy(deleteButton, async () => {
|
||||||
|
try {
|
||||||
|
await api("DELETE", base, { body: { confirm: confirmInput.value.trim() } });
|
||||||
|
flash("Zone " + zoneName() + " deleted. The DNS server stops serving it after its next zone list reload, which happens every 10 minutes by default.");
|
||||||
|
location.assign("/");
|
||||||
|
} catch (err) {
|
||||||
|
handleError(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setupDialogs();
|
||||||
|
showFlash();
|
||||||
|
const exportLink = $("#export-link");
|
||||||
|
exportLink.href = "/api/v1" + base + "/export";
|
||||||
|
exportLink.setAttribute("download", "");
|
||||||
|
$("#import-link").href = "/zones/" + encodeURIComponent(zoneParam) + "/import";
|
||||||
|
setupSoa();
|
||||||
|
setupRecordForm();
|
||||||
|
setupTable();
|
||||||
|
if (isAdmin) setupAdmin();
|
||||||
|
load();
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
// Copyright (C) 2026 Bryan Joshua Pedini
|
||||||
|
|
||||||
|
import { $, api, appData, busy, clear, clearErrors, handleError, h, openDialog, parseNumber, plural, setupDialogs, showFlash, toast, zoneLink } from "./common.js";
|
||||||
|
|
||||||
|
const { isAdmin } = appData();
|
||||||
|
const state = { zones: [], counts: null, countsFailed: false, search: "" };
|
||||||
|
|
||||||
|
function problemCell(zone) {
|
||||||
|
const cell = h("td");
|
||||||
|
if (state.countsFailed) {
|
||||||
|
cell.textContent = "unavailable";
|
||||||
|
return cell;
|
||||||
|
}
|
||||||
|
if (state.counts === null) {
|
||||||
|
cell.textContent = "loading...";
|
||||||
|
return cell;
|
||||||
|
}
|
||||||
|
const counts = state.counts.get(zone.name) || { error: 0, warning: 0 };
|
||||||
|
if (counts.error === 0 && counts.warning === 0) {
|
||||||
|
cell.append(h("span", { class: "badge badge-ok", text: "none" }));
|
||||||
|
return cell;
|
||||||
|
}
|
||||||
|
if (counts.error > 0) cell.append(h("span", { class: "badge badge-error", text: plural(counts.error, "error", "errors") }), " ");
|
||||||
|
if (counts.warning > 0) cell.append(h("span", { class: "badge badge-warning", text: plural(counts.warning, "warning", "warnings") }));
|
||||||
|
return cell;
|
||||||
|
}
|
||||||
|
|
||||||
|
function render() {
|
||||||
|
const body = $("#zones-body");
|
||||||
|
const needle = state.search.trim().toLowerCase();
|
||||||
|
const zones = state.zones.filter((zone) => zone.name.toLowerCase().includes(needle));
|
||||||
|
clear(body);
|
||||||
|
for (const zone of zones) {
|
||||||
|
const serial = zone.serial === null || zone.serial === undefined ? "dynamic" : String(zone.serial);
|
||||||
|
body.append(h("tr", null,
|
||||||
|
h("th", { scope: "row" }, zoneLink(zone.name)),
|
||||||
|
h("td", { class: "num", text: zone.records }),
|
||||||
|
h("td", { class: "mono", text: serial }),
|
||||||
|
problemCell(zone)));
|
||||||
|
}
|
||||||
|
const status = $("#zones-status");
|
||||||
|
if (state.zones.length === 0) {
|
||||||
|
status.textContent = isAdmin ? "There are no zones yet." : "No zone is delegated to you.";
|
||||||
|
} else if (zones.length === 0) {
|
||||||
|
status.textContent = "No zone matches the search.";
|
||||||
|
} else {
|
||||||
|
status.textContent = plural(zones.length, "zone", "zones") + ".";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadCounts() {
|
||||||
|
try {
|
||||||
|
const { data } = await api("GET", "/check");
|
||||||
|
const counts = new Map();
|
||||||
|
for (const problem of data.problems || []) {
|
||||||
|
const entry = counts.get(problem.zone) || { error: 0, warning: 0 };
|
||||||
|
if (problem.severity === "error") entry.error += 1;
|
||||||
|
else entry.warning += 1;
|
||||||
|
counts.set(problem.zone, entry);
|
||||||
|
}
|
||||||
|
state.counts = counts;
|
||||||
|
} catch (err) {
|
||||||
|
state.countsFailed = true;
|
||||||
|
}
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
try {
|
||||||
|
const { data } = await api("GET", "/zones");
|
||||||
|
state.zones = data.zones || [];
|
||||||
|
} catch (err) {
|
||||||
|
$("#zones-status").textContent = "The zones could not be loaded.";
|
||||||
|
handleError(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
state.counts = null;
|
||||||
|
state.countsFailed = false;
|
||||||
|
render();
|
||||||
|
loadCounts();
|
||||||
|
}
|
||||||
|
|
||||||
|
function zoneBody(form) {
|
||||||
|
const el = form.elements;
|
||||||
|
return {
|
||||||
|
name: el.name.value.trim(),
|
||||||
|
ns: el.ns.value.trim(),
|
||||||
|
mbox: el.mbox.value.trim(),
|
||||||
|
extra_ns: el.extra_ns.value.split("\n").map((line) => line.trim()).filter(Boolean),
|
||||||
|
refresh: parseNumber(el.refresh.value),
|
||||||
|
retry: parseNumber(el.retry.value),
|
||||||
|
expire: parseNumber(el.expire.value),
|
||||||
|
minttl: parseNumber(el.minttl.value),
|
||||||
|
ttl: parseNumber(el.ttl.value),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupCreate() {
|
||||||
|
const dialog = $("#zone-dialog");
|
||||||
|
const form = $("#zone-form");
|
||||||
|
$("#new-zone").addEventListener("click", () => openDialog(dialog));
|
||||||
|
form.addEventListener("submit", async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
clearErrors(form);
|
||||||
|
await busy(form.querySelector("button[type=submit]"), async () => {
|
||||||
|
try {
|
||||||
|
await api("POST", "/zones", { body: zoneBody(form) });
|
||||||
|
} catch (err) {
|
||||||
|
handleError(err, { form });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dialog.close();
|
||||||
|
form.reset();
|
||||||
|
toast("Zone created. The DNS server serves a new zone after its next zone list reload, which happens every 10 minutes by default.");
|
||||||
|
await load();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setupDialogs();
|
||||||
|
showFlash();
|
||||||
|
$("#zone-search").addEventListener("input", (event) => {
|
||||||
|
state.search = event.target.value;
|
||||||
|
render();
|
||||||
|
});
|
||||||
|
if (isAdmin) setupCreate();
|
||||||
|
load();
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
{{- /* SPDX-License-Identifier: GPL-2.0-or-later */ -}}
|
||||||
|
{{- /* Copyright (C) 2026 Bryan Joshua Pedini */ -}}
|
||||||
|
{{define "layout"}}<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<meta name="color-scheme" content="light dark">
|
||||||
|
<title>{{template "title" .}} - {{.AppName}}</title>
|
||||||
|
<link rel="icon" href="data:,">
|
||||||
|
<link rel="stylesheet" href="{{.Static}}css/app.css">
|
||||||
|
{{if .Script}}<script type="module" src="{{.Static}}js/{{.Script}}.js"></script>
|
||||||
|
{{end}}</head>
|
||||||
|
<body>
|
||||||
|
<a class="skip" href="#app">Skip to content</a>
|
||||||
|
<header class="topbar">
|
||||||
|
<a class="brand" href="/">{{.AppName}}</a>
|
||||||
|
{{if .Username}}<nav class="nav" aria-label="Main">
|
||||||
|
<a href="/"{{if eq .Section "zones"}} aria-current="page"{{end}}>Zones</a>
|
||||||
|
<a href="/audit"{{if eq .Section "audit"}} aria-current="page"{{end}}>Audit</a>
|
||||||
|
<a href="/account"{{if eq .Section "account"}} aria-current="page"{{end}}>Account</a>
|
||||||
|
{{if .IsAdmin}}<a href="/users"{{if eq .Section "users"}} aria-current="page"{{end}}>Users</a>
|
||||||
|
{{end}}</nav>
|
||||||
|
<form class="logout" method="post" action="/logout">
|
||||||
|
<span class="who"><span class="who-name">{{.Username}}</span> <span class="badge badge-muted">{{.Role}}</span></span>
|
||||||
|
<button type="submit" class="btn btn-small">Log out</button>
|
||||||
|
</form>
|
||||||
|
{{end}}</header>
|
||||||
|
<main id="app" class="page page-{{.Page}}" tabindex="-1" data-page="{{.Page}}" data-username="{{.Username}}" data-role="{{.Role}}" data-zone="{{.Zone}}" data-target-user="{{.TargetUser}}">
|
||||||
|
{{template "content" .}}
|
||||||
|
</main>
|
||||||
|
<div id="toasts" class="toasts" role="status" aria-live="polite" aria-atomic="false"></div>
|
||||||
|
</body>
|
||||||
|
</html>{{end}}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
{{- /* SPDX-License-Identifier: GPL-2.0-or-later */ -}}
|
||||||
|
{{- /* Copyright (C) 2026 Bryan Joshua Pedini */ -}}
|
||||||
|
{{define "title"}}Account{{end}}
|
||||||
|
{{define "content"}}<div class="page-head">
|
||||||
|
<h1>Account</h1>
|
||||||
|
</div>
|
||||||
|
<section class="card" aria-labelledby="account-title">
|
||||||
|
<h2 id="account-title">Profile</h2>
|
||||||
|
<dl class="dl">
|
||||||
|
<dt>Username</dt><dd id="account-username">{{.Username}}</dd>
|
||||||
|
<dt>Role</dt><dd id="account-role">{{.Role}}</dd>
|
||||||
|
</dl>
|
||||||
|
</section>
|
||||||
|
{{if not .IsAdmin}}
|
||||||
|
<section class="card" aria-labelledby="account-zones-title">
|
||||||
|
<h2 id="account-zones-title">Delegated zones</h2>
|
||||||
|
<ul class="list" id="account-zones"></ul>
|
||||||
|
<p class="muted" id="account-zones-status" role="status">Loading...</p>
|
||||||
|
</section>
|
||||||
|
{{end}}
|
||||||
|
<section class="card" aria-labelledby="password-title">
|
||||||
|
<h2 id="password-title">Change password</h2>
|
||||||
|
<form class="form" id="password-form" novalidate>
|
||||||
|
<div class="field">
|
||||||
|
<label for="pw-current">Current password</label>
|
||||||
|
<input id="pw-current" name="current" type="password" autocomplete="current-password" maxlength="256">
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="pw-new">New password</label>
|
||||||
|
<input id="pw-new" name="password" type="password" autocomplete="new-password" maxlength="256">
|
||||||
|
<p class="hint">12 to 256 characters.</p>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="pw-repeat">Repeat the new password</label>
|
||||||
|
<input id="pw-repeat" name="repeat" type="password" autocomplete="new-password" maxlength="256">
|
||||||
|
</div>
|
||||||
|
<div class="actions">
|
||||||
|
<button type="submit" class="btn btn-primary">Change password</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
{{end}}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
{{- /* SPDX-License-Identifier: GPL-2.0-or-later */ -}}
|
||||||
|
{{- /* Copyright (C) 2026 Bryan Joshua Pedini */ -}}
|
||||||
|
{{define "title"}}Audit{{end}}
|
||||||
|
{{define "content"}}<div class="page-head">
|
||||||
|
<h1>Audit</h1>
|
||||||
|
</div>
|
||||||
|
<section class="card" aria-labelledby="audit-filter-title">
|
||||||
|
<h2 id="audit-filter-title" class="visually-hidden">Filters</h2>
|
||||||
|
<form class="filters" id="audit-filters" novalidate>
|
||||||
|
<div class="field">
|
||||||
|
<label for="af-zone">Zone</label>
|
||||||
|
<input id="af-zone" name="zone" type="text" autocomplete="off" autocapitalize="none" spellcheck="false">
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="af-actor">Actor</label>
|
||||||
|
<input id="af-actor" name="actor" type="text" autocomplete="off" autocapitalize="none" spellcheck="false">
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="af-operation">Operation</label>
|
||||||
|
<select id="af-operation" name="operation">
|
||||||
|
<option value="">Any operation</option>
|
||||||
|
<option>account_read</option><option>login</option><option>logout</option><option>password_change</option>
|
||||||
|
<option>zone_list</option><option>zone_read</option><option>zone_create</option><option>zone_delete</option>
|
||||||
|
<option>record_list</option><option>record_create</option><option>record_update</option><option>record_delete</option><option>record_bulk_delete</option><option>soa_update</option>
|
||||||
|
<option>zone_check</option><option>check_all</option>
|
||||||
|
<option>zone_export</option><option>zone_import_preview</option><option>zone_import</option>
|
||||||
|
<option>delegation_list</option><option>delegation_grant</option><option>delegation_revoke</option>
|
||||||
|
<option>user_list</option><option>user_read</option><option>user_create</option><option>user_role</option><option>user_password</option><option>user_delete</option>
|
||||||
|
<option>audit_read</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="af-kind">Kind</label>
|
||||||
|
<select id="af-kind" name="kind">
|
||||||
|
<option value="">Reads and changes</option>
|
||||||
|
<option value="read">Reads</option>
|
||||||
|
<option value="change">Changes</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="af-outcome">Outcome</label>
|
||||||
|
<select id="af-outcome" name="outcome">
|
||||||
|
<option value="">Any outcome</option>
|
||||||
|
<option value="success">Success</option>
|
||||||
|
<option value="error">Error</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="actions">
|
||||||
|
<button type="submit" class="btn btn-primary">Apply filters</button>
|
||||||
|
<button type="reset" class="btn" id="af-reset">Reset</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
<div class="table-wrap">
|
||||||
|
<table class="table" id="audit-table">
|
||||||
|
<thead>
|
||||||
|
<tr><th scope="col">Time (UTC)</th><th scope="col">Actor</th><th scope="col">Origin</th><th scope="col">Operation</th><th scope="col">Status</th><th scope="col">Target</th><th scope="col">Details</th></tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="audit-body"></tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<p class="muted" id="audit-status" role="status">Loading...</p>
|
||||||
|
<div class="actions">
|
||||||
|
<button type="button" class="btn" id="audit-more" hidden>Load older rows</button>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{{- /* SPDX-License-Identifier: GPL-2.0-or-later */ -}}
|
||||||
|
{{- /* Copyright (C) 2026 Bryan Joshua Pedini */ -}}
|
||||||
|
{{define "title"}}Forbidden{{end}}
|
||||||
|
{{define "content"}}<section class="card narrow">
|
||||||
|
<h1>Forbidden</h1>
|
||||||
|
<p>Your account is not allowed to open this page.</p>
|
||||||
|
<p><a href="/">Back to the zones</a></p>
|
||||||
|
</section>{{end}}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
{{- /* SPDX-License-Identifier: GPL-2.0-or-later */ -}}
|
||||||
|
{{- /* Copyright (C) 2026 Bryan Joshua Pedini */ -}}
|
||||||
|
{{define "title"}}Import {{.Zone}}{{end}}
|
||||||
|
{{define "content"}}<p class="crumbs"><a href="/">Zones</a> / <a id="zone-link" href="/">{{.Zone}}</a></p>
|
||||||
|
<div class="page-head">
|
||||||
|
<h1>Import into {{.Zone}}</h1>
|
||||||
|
</div>
|
||||||
|
<section class="card" aria-labelledby="import-source-title">
|
||||||
|
<h2 id="import-source-title">Zone file</h2>
|
||||||
|
<form class="form" id="import-form" novalidate>
|
||||||
|
<fieldset class="field">
|
||||||
|
<legend>Mode</legend>
|
||||||
|
<label class="choice"><input type="radio" name="mode" value="merge" checked> Merge: add missing records and update TTLs</label>
|
||||||
|
<label class="choice"><input type="radio" name="mode" value="replace"> Replace: also delete records that are not in the file</label>
|
||||||
|
</fieldset>
|
||||||
|
<div class="field">
|
||||||
|
<label for="import-file">Load a file</label>
|
||||||
|
<input id="import-file" type="file" accept=".zone,.txt,text/plain">
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="import-content">Zone file contents</label>
|
||||||
|
<textarea id="import-content" name="content" rows="14" class="mono" spellcheck="false" autocomplete="off" autocapitalize="none"></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="actions">
|
||||||
|
<button type="submit" class="btn btn-primary" id="import-preview">Preview</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="card" id="import-result" aria-labelledby="import-result-title" hidden>
|
||||||
|
<h2 id="import-result-title">Preview</h2>
|
||||||
|
<div id="import-errors" hidden></div>
|
||||||
|
<div id="import-summary"></div>
|
||||||
|
<div id="import-tables"></div>
|
||||||
|
<div class="actions">
|
||||||
|
<button type="button" class="btn btn-primary" id="import-apply" hidden>Apply import</button>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
{{end}}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
{{- /* SPDX-License-Identifier: GPL-2.0-or-later */ -}}
|
||||||
|
{{- /* Copyright (C) 2026 Bryan Joshua Pedini */ -}}
|
||||||
|
{{define "title"}}Sign in{{end}}
|
||||||
|
{{define "content"}}<section class="card narrow">
|
||||||
|
<h1>Sign in</h1>
|
||||||
|
{{if .Error}}<p class="alert alert-error" role="alert">{{.Error}}</p>
|
||||||
|
{{end}}{{if .NoActiveAdmin}}<div class="alert alert-info">
|
||||||
|
<p>No administrator exists yet. Create the first one by running this command on the host that runs the container:</p>
|
||||||
|
<pre class="code"><code>{{.BootstrapCommand}}</code></pre>
|
||||||
|
</div>
|
||||||
|
{{end}}<form class="form" method="post" action="/login">
|
||||||
|
<div class="field">
|
||||||
|
<label for="login-username">Username</label>
|
||||||
|
<input id="login-username" name="username" type="text" autocomplete="username" autocapitalize="none" spellcheck="false" maxlength="64" required autofocus>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="login-password">Password</label>
|
||||||
|
<input id="login-password" name="password" type="password" autocomplete="current-password" maxlength="256" required>
|
||||||
|
</div>
|
||||||
|
<input type="hidden" name="next" value="{{.Next}}">
|
||||||
|
<div class="actions">
|
||||||
|
<button type="submit" class="btn btn-primary">Sign in</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</section>{{end}}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{{- /* SPDX-License-Identifier: GPL-2.0-or-later */ -}}
|
||||||
|
{{- /* Copyright (C) 2026 Bryan Joshua Pedini */ -}}
|
||||||
|
{{define "title"}}Not found{{end}}
|
||||||
|
{{define "content"}}<section class="card narrow">
|
||||||
|
<h1>Not found</h1>
|
||||||
|
<p>The page you asked for does not exist.</p>
|
||||||
|
<p><a href="/">Back to the zones</a></p>
|
||||||
|
</section>{{end}}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
{{- /* SPDX-License-Identifier: GPL-2.0-or-later */ -}}
|
||||||
|
{{- /* Copyright (C) 2026 Bryan Joshua Pedini */ -}}
|
||||||
|
{{define "title"}}User {{.TargetUser}}{{end}}
|
||||||
|
{{define "content"}}<p class="crumbs"><a href="/users">Users</a></p>
|
||||||
|
<div class="page-head">
|
||||||
|
<h1 id="user-title">{{.TargetUser}}</h1>
|
||||||
|
<span class="badge badge-muted" id="user-state" hidden></span>
|
||||||
|
</div>
|
||||||
|
<section class="card" aria-labelledby="user-info-title">
|
||||||
|
<h2 id="user-info-title">Details</h2>
|
||||||
|
<dl class="dl" id="user-summary"></dl>
|
||||||
|
<p class="muted" id="user-status" role="status">Loading...</p>
|
||||||
|
</section>
|
||||||
|
{{if eq .Username .TargetUser}}
|
||||||
|
<section class="card" id="user-self">
|
||||||
|
<p>This is your own account. Role, password and deletion are not available here. <a href="/account">Open your account page</a> to change your password.</p>
|
||||||
|
</section>
|
||||||
|
{{else}}
|
||||||
|
<div id="user-controls" hidden>
|
||||||
|
<section class="card" aria-labelledby="user-role-title">
|
||||||
|
<h2 id="user-role-title">Role</h2>
|
||||||
|
<form class="inline-form" id="role-form" novalidate>
|
||||||
|
<div class="field">
|
||||||
|
<label for="user-role">Role</label>
|
||||||
|
<select id="user-role" name="role">
|
||||||
|
<option value="user">user</option>
|
||||||
|
<option value="admin">admin</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-small">Save role</button>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="card" aria-labelledby="user-password-title">
|
||||||
|
<h2 id="user-password-title">Password</h2>
|
||||||
|
<p class="muted">Setting a password ends every session of this user.</p>
|
||||||
|
<form class="form" id="password-form" novalidate>
|
||||||
|
<div class="field">
|
||||||
|
<label for="up-password">New password</label>
|
||||||
|
<input id="up-password" name="password" type="password" autocomplete="new-password" maxlength="256">
|
||||||
|
<p class="hint">12 to 256 characters.</p>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="up-repeat">Repeat the new password</label>
|
||||||
|
<input id="up-repeat" name="repeat" type="password" autocomplete="new-password" maxlength="256">
|
||||||
|
</div>
|
||||||
|
<div class="actions">
|
||||||
|
<button type="submit" class="btn btn-small">Set password</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="card" aria-labelledby="user-zones-title">
|
||||||
|
<h2 id="user-zones-title">Delegated zones</h2>
|
||||||
|
<ul class="list" id="user-zones"></ul>
|
||||||
|
<p class="muted" id="user-zones-status" role="status"></p>
|
||||||
|
<form class="inline-form" id="zone-add-form" novalidate>
|
||||||
|
<div class="field">
|
||||||
|
<label for="user-zone-pick">Delegate a zone</label>
|
||||||
|
<select id="user-zone-pick" name="zone"></select>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-small">Add zone</button>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="card danger-zone" aria-labelledby="user-danger-title">
|
||||||
|
<h2 id="user-danger-title">Danger zone</h2>
|
||||||
|
<p>Deleting the user ends their sessions and prevents them from signing in. The username stays taken and the history of the user stays in the audit.</p>
|
||||||
|
<form class="inline-form" id="user-delete-form" novalidate>
|
||||||
|
<div class="field">
|
||||||
|
<label for="user-delete-confirm">Type the username to confirm</label>
|
||||||
|
<input id="user-delete-confirm" name="confirm" type="text" autocomplete="off" autocapitalize="none" spellcheck="false">
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-danger" id="user-delete" disabled>Delete user</button>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
<section class="card" id="user-readonly" hidden>
|
||||||
|
<h2>Delegated zones</h2>
|
||||||
|
<ul class="list" id="user-zones-readonly"></ul>
|
||||||
|
</section>
|
||||||
|
{{end}}{{end}}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
{{- /* SPDX-License-Identifier: GPL-2.0-or-later */ -}}
|
||||||
|
{{- /* Copyright (C) 2026 Bryan Joshua Pedini */ -}}
|
||||||
|
{{define "title"}}Users{{end}}
|
||||||
|
{{define "content"}}<div class="page-head">
|
||||||
|
<h1>Users</h1>
|
||||||
|
<button type="button" class="btn btn-primary" id="new-user">New user</button>
|
||||||
|
</div>
|
||||||
|
<div class="toolbar">
|
||||||
|
<label class="choice" for="show-deleted"><input type="checkbox" id="show-deleted"> Show deleted users</label>
|
||||||
|
</div>
|
||||||
|
<div class="table-wrap">
|
||||||
|
<table class="table" id="users-table">
|
||||||
|
<thead>
|
||||||
|
<tr><th scope="col">Username</th><th scope="col">Role</th><th scope="col" class="num">Zones</th><th scope="col">Created (UTC)</th><th scope="col">Last login (UTC)</th><th scope="col">State</th></tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="users-body"></tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<p class="muted" id="users-status" role="status">Loading users...</p>
|
||||||
|
|
||||||
|
<dialog id="user-dialog" class="dialog" aria-labelledby="user-dialog-title">
|
||||||
|
<form id="user-form" class="form" novalidate>
|
||||||
|
<div class="dialog-head">
|
||||||
|
<h2 id="user-dialog-title">New user</h2>
|
||||||
|
<button type="button" class="btn btn-icon" data-close aria-label="Close">×</button>
|
||||||
|
</div>
|
||||||
|
<div class="dialog-body">
|
||||||
|
<div class="field">
|
||||||
|
<label for="nu-username">Username</label>
|
||||||
|
<input id="nu-username" name="username" type="text" autocomplete="off" autocapitalize="none" spellcheck="false" maxlength="64" required>
|
||||||
|
<p class="hint">Lowercase letters, digits, dot, underscore and hyphen. A username can never be reused.</p>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="nu-role">Role</label>
|
||||||
|
<select id="nu-role" name="role">
|
||||||
|
<option value="user">user</option>
|
||||||
|
<option value="admin">admin</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="nu-password">Password</label>
|
||||||
|
<input id="nu-password" name="password" type="password" autocomplete="new-password" maxlength="256" required>
|
||||||
|
<p class="hint">12 to 256 characters.</p>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="nu-repeat">Repeat the password</label>
|
||||||
|
<input id="nu-repeat" name="repeat" type="password" autocomplete="new-password" maxlength="256" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="dialog-actions">
|
||||||
|
<button type="button" class="btn" data-close>Cancel</button>
|
||||||
|
<button type="submit" class="btn btn-primary">Create user</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</dialog>
|
||||||
|
{{end}}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
{{- /* SPDX-License-Identifier: GPL-2.0-or-later */ -}}
|
||||||
|
{{- /* Copyright (C) 2026 Bryan Joshua Pedini */ -}}
|
||||||
|
{{define "title"}}{{.Zone}}{{end}}
|
||||||
|
{{define "content"}}<p class="crumbs"><a href="/">Zones</a></p>
|
||||||
|
<div class="page-head">
|
||||||
|
<h1 id="zone-title">{{.Zone}}</h1>
|
||||||
|
<div class="actions">
|
||||||
|
<a class="btn" id="export-link" href="/">Export zone file</a>
|
||||||
|
<a class="btn" id="import-link" href="/">Import zone file</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<section class="card" aria-labelledby="soa-title">
|
||||||
|
<div class="section-head">
|
||||||
|
<h2 id="soa-title">SOA</h2>
|
||||||
|
<div class="actions">
|
||||||
|
<button type="button" class="btn btn-small" id="soa-managed" hidden>Use managed serial</button>
|
||||||
|
<button type="button" class="btn btn-small" id="soa-edit" disabled>Edit SOA</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<dl class="dl" id="soa-summary"></dl>
|
||||||
|
<p class="muted" id="soa-status" role="status">Loading...</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="card" id="problems-panel" aria-labelledby="problems-title" hidden>
|
||||||
|
<h2 id="problems-title">Problems</h2>
|
||||||
|
<ul class="problems" id="problems-list"></ul>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="card" aria-labelledby="records-title">
|
||||||
|
<div class="section-head">
|
||||||
|
<h2 id="records-title">Records</h2>
|
||||||
|
<div class="actions">
|
||||||
|
<button type="button" class="btn btn-danger btn-small" id="bulk-delete" disabled>Delete selected</button>
|
||||||
|
<button type="button" class="btn btn-primary btn-small" id="record-add">Add record</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="toolbar">
|
||||||
|
<div class="field">
|
||||||
|
<label for="filter-type">Type</label>
|
||||||
|
<select id="filter-type"><option value="">All types</option></select>
|
||||||
|
</div>
|
||||||
|
<div class="field grow">
|
||||||
|
<label for="filter-text">Search records</label>
|
||||||
|
<input id="filter-text" type="search" autocomplete="off" spellcheck="false">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="table-wrap">
|
||||||
|
<table class="table" id="records-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col" class="check"><input type="checkbox" id="select-all" aria-label="Select all records on this page"></th>
|
||||||
|
<th scope="col">Name</th><th scope="col">Type</th><th scope="col">TTL</th><th scope="col">Value</th><th scope="col">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="records-body"></tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<p class="muted" id="records-status" role="status">Loading records...</p>
|
||||||
|
<div class="pager" id="pager" hidden>
|
||||||
|
<button type="button" class="btn btn-small" id="page-prev">Previous</button>
|
||||||
|
<span id="page-info"></span>
|
||||||
|
<button type="button" class="btn btn-small" id="page-next">Next</button>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
{{if .IsAdmin}}
|
||||||
|
<section class="card" id="users-panel" aria-labelledby="users-title">
|
||||||
|
<h2 id="users-title">Users</h2>
|
||||||
|
<p class="muted">Users who can see and change this zone. Administrators always can.</p>
|
||||||
|
<ul class="list" id="zone-users"></ul>
|
||||||
|
<p class="muted" id="zone-users-status" role="status">Loading...</p>
|
||||||
|
<form class="inline-form" id="zone-user-form" novalidate>
|
||||||
|
<div class="field">
|
||||||
|
<label for="zone-user-pick">Delegate this zone to</label>
|
||||||
|
<select id="zone-user-pick" name="username"></select>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-small" id="zone-user-add">Add user</button>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="card danger-zone" id="danger" aria-labelledby="danger-title">
|
||||||
|
<h2 id="danger-title">Danger zone</h2>
|
||||||
|
<p>Deleting the zone removes every record and every delegation of this zone. This cannot be undone.</p>
|
||||||
|
<form class="inline-form" id="zone-delete-form" novalidate>
|
||||||
|
<div class="field">
|
||||||
|
<label for="zone-delete-confirm">Type the zone name to confirm</label>
|
||||||
|
<input id="zone-delete-confirm" name="confirm" type="text" autocomplete="off" autocapitalize="none" spellcheck="false">
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-danger" id="zone-delete" disabled>Delete zone</button>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
{{end}}
|
||||||
|
{{template "soa_dialog" .}}
|
||||||
|
{{template "record_dialog" .}}{{end}}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
{{- /* SPDX-License-Identifier: GPL-2.0-or-later */ -}}
|
||||||
|
{{- /* Copyright (C) 2026 Bryan Joshua Pedini */ -}}
|
||||||
|
{{define "title"}}Zones{{end}}
|
||||||
|
{{define "content"}}<div class="page-head">
|
||||||
|
<h1>Zones</h1>
|
||||||
|
{{if .IsAdmin}}<button type="button" class="btn btn-primary" id="new-zone">New zone</button>
|
||||||
|
{{end}}</div>
|
||||||
|
<div class="toolbar">
|
||||||
|
<div class="field">
|
||||||
|
<label for="zone-search">Search zones</label>
|
||||||
|
<input id="zone-search" type="search" autocomplete="off" spellcheck="false">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="table-wrap">
|
||||||
|
<table class="table" id="zones-table">
|
||||||
|
<thead>
|
||||||
|
<tr><th scope="col">Zone</th><th scope="col" class="num">Records</th><th scope="col">SOA serial</th><th scope="col">Problems</th></tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="zones-body"></tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<p class="muted" id="zones-status" role="status">Loading zones...</p>
|
||||||
|
{{if .IsAdmin}}{{template "zone_create_dialog" .}}{{end}}{{end}}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
{{- /* SPDX-License-Identifier: GPL-2.0-or-later */ -}}
|
||||||
|
{{- /* Copyright (C) 2026 Bryan Joshua Pedini */ -}}
|
||||||
|
{{define "record_dialog"}}<dialog id="record-dialog" class="dialog" aria-labelledby="record-dialog-title">
|
||||||
|
<form id="record-form" class="form" novalidate>
|
||||||
|
<div class="dialog-head">
|
||||||
|
<h2 id="record-dialog-title">Add record</h2>
|
||||||
|
<button type="button" class="btn btn-icon" data-close aria-label="Close">×</button>
|
||||||
|
</div>
|
||||||
|
<div class="dialog-body">
|
||||||
|
<div class="alert alert-warn" id="record-broken" hidden>
|
||||||
|
<p>The stored row cannot be served correctly. Saving replaces it with the values below.</p>
|
||||||
|
<p>Stored content: <code class="mono" id="record-raw"></code></p>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="rec-name">Name</label>
|
||||||
|
<input id="rec-name" name="name" type="text" autocomplete="off" autocapitalize="none" spellcheck="false" placeholder="@" aria-describedby="rec-fqdn">
|
||||||
|
<p class="hint" id="rec-fqdn" aria-live="polite"></p>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="rec-type">Type</label>
|
||||||
|
<select id="rec-type" name="type"></select>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="rec-ttl">TTL (seconds)</label>
|
||||||
|
<input id="rec-ttl" name="ttl" type="text" inputmode="numeric" value="3600">
|
||||||
|
<p class="hint">0 means default (360 s).</p>
|
||||||
|
</div>
|
||||||
|
<div id="rec-fields"></div>
|
||||||
|
</div>
|
||||||
|
<div class="dialog-actions">
|
||||||
|
<button type="button" class="btn" data-close>Cancel</button>
|
||||||
|
<button type="submit" class="btn btn-primary" id="rec-submit">Save record</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</dialog>{{end}}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
{{- /* SPDX-License-Identifier: GPL-2.0-or-later */ -}}
|
||||||
|
{{- /* Copyright (C) 2026 Bryan Joshua Pedini */ -}}
|
||||||
|
{{define "soa_dialog"}}<dialog id="soa-dialog" class="dialog" aria-labelledby="soa-dialog-title">
|
||||||
|
<form id="soa-form" class="form" novalidate>
|
||||||
|
<div class="dialog-head">
|
||||||
|
<h2 id="soa-dialog-title">Edit SOA</h2>
|
||||||
|
<button type="button" class="btn btn-icon" data-close aria-label="Close">×</button>
|
||||||
|
</div>
|
||||||
|
<div class="dialog-body">
|
||||||
|
<p class="alert alert-warn" id="soa-broken" hidden>The stored SOA cannot be read. Saving replaces it with the values below.</p>
|
||||||
|
<div class="field">
|
||||||
|
<label for="soa-ns">Primary name server</label>
|
||||||
|
<input id="soa-ns" name="ns" type="text" autocomplete="off" autocapitalize="none" spellcheck="false" required>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="soa-mbox">Hostmaster mailbox</label>
|
||||||
|
<input id="soa-mbox" name="mbox" type="text" autocomplete="off" autocapitalize="none" spellcheck="false" required>
|
||||||
|
</div>
|
||||||
|
<div class="grid-2">
|
||||||
|
<div class="field">
|
||||||
|
<label for="soa-refresh">Refresh</label>
|
||||||
|
<input id="soa-refresh" name="refresh" type="text" inputmode="numeric">
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="soa-retry">Retry</label>
|
||||||
|
<input id="soa-retry" name="retry" type="text" inputmode="numeric">
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="soa-expire">Expire</label>
|
||||||
|
<input id="soa-expire" name="expire" type="text" inputmode="numeric">
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="soa-minttl">Minimum TTL</label>
|
||||||
|
<input id="soa-minttl" name="minttl" type="text" inputmode="numeric">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="soa-ttl">TTL of the SOA record</label>
|
||||||
|
<input id="soa-ttl" name="ttl" type="text" inputmode="numeric">
|
||||||
|
<p class="hint">0 means default (360 s).</p>
|
||||||
|
</div>
|
||||||
|
<p class="hint">The serial is managed by the application and increases with every change.</p>
|
||||||
|
</div>
|
||||||
|
<div class="dialog-actions">
|
||||||
|
<button type="button" class="btn" data-close>Cancel</button>
|
||||||
|
<button type="submit" class="btn btn-primary">Save SOA</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</dialog>{{end}}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
{{- /* SPDX-License-Identifier: GPL-2.0-or-later */ -}}
|
||||||
|
{{- /* Copyright (C) 2026 Bryan Joshua Pedini */ -}}
|
||||||
|
{{define "zone_create_dialog"}}<dialog id="zone-dialog" class="dialog" aria-labelledby="zone-dialog-title">
|
||||||
|
<form id="zone-form" class="form" novalidate>
|
||||||
|
<div class="dialog-head">
|
||||||
|
<h2 id="zone-dialog-title">New zone</h2>
|
||||||
|
<button type="button" class="btn btn-icon" data-close aria-label="Close">×</button>
|
||||||
|
</div>
|
||||||
|
<div class="dialog-body">
|
||||||
|
<div class="field">
|
||||||
|
<label for="nz-name">Zone name</label>
|
||||||
|
<input id="nz-name" name="name" type="text" autocomplete="off" autocapitalize="none" spellcheck="false" placeholder="example.org" required>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="nz-ns">Primary name server</label>
|
||||||
|
<input id="nz-ns" name="ns" type="text" autocomplete="off" autocapitalize="none" spellcheck="false" placeholder="ns1.example.org" required>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="nz-mbox">Hostmaster mailbox</label>
|
||||||
|
<input id="nz-mbox" name="mbox" type="text" autocomplete="off" autocapitalize="none" spellcheck="false" placeholder="hostmaster@example.org" required>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="nz-extra">Additional name servers, one per line</label>
|
||||||
|
<textarea id="nz-extra" name="extra_ns" rows="3" autocomplete="off" autocapitalize="none" spellcheck="false"></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="grid-2">
|
||||||
|
<div class="field">
|
||||||
|
<label for="nz-refresh">SOA refresh</label>
|
||||||
|
<input id="nz-refresh" name="refresh" type="text" inputmode="numeric" value="3600">
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="nz-retry">SOA retry</label>
|
||||||
|
<input id="nz-retry" name="retry" type="text" inputmode="numeric" value="600">
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="nz-expire">SOA expire</label>
|
||||||
|
<input id="nz-expire" name="expire" type="text" inputmode="numeric" value="604800">
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="nz-minttl">SOA minimum TTL</label>
|
||||||
|
<input id="nz-minttl" name="minttl" type="text" inputmode="numeric" value="300">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="nz-ttl">TTL of the SOA and NS records</label>
|
||||||
|
<input id="nz-ttl" name="ttl" type="text" inputmode="numeric" value="3600">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="dialog-actions">
|
||||||
|
<button type="button" class="btn" data-close>Cancel</button>
|
||||||
|
<button type="submit" class="btn btn-primary">Create zone</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</dialog>{{end}}
|
||||||
Reference in new issue
Block a user