Phase 1: Control Service skeleton (Go, SQLite, session login, Docker, Caddy)
- Go service with its own multi-stage Dockerfile and docker-compose.yml; runs as container webrestrict-control on port 8791. - SQLite schema for the full AGENTS.md §7 data model via versioned migrations (PRAGMA user_version); audit log is append-only. - Configuration from the process environment; the real env file is gitignored and a template is committed. No secrets in the repo. - Separate session login (signed HMAC cookie + CSRF) for Sam. - GET /health; HTMX + server-rendered dashboard styled with the Family Home Lab tokens.css (copied) and Inter fonts; dark mode; phone-friendly. - Caddy vhost for webrestrict.lab.audasmedia.com.au applied on .35 (Let's Encrypt cert issued); route recorded in deploy/caddy/webrestrict.caddy. - Unit tests for config, auth and store. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
284
internal/web/server.go
Normal file
284
internal/web/server.go
Normal file
@@ -0,0 +1,284 @@
|
||||
// Package web is the HTTP surface of the Control Service: /health, the session
|
||||
// login, and the server-rendered HTMX dashboard (AGENTS.md §5, §9).
|
||||
package web
|
||||
|
||||
import (
|
||||
"context"
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io/fs"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitea.lab.audasmedia.com.au/sam/internet_use_control/internal/auth"
|
||||
"gitea.lab.audasmedia.com.au/sam/internet_use_control/internal/config"
|
||||
"gitea.lab.audasmedia.com.au/sam/internet_use_control/internal/store"
|
||||
)
|
||||
|
||||
//go:embed templates/*.html templates/partials/*.html
|
||||
var templateFS embed.FS
|
||||
|
||||
//go:embed static
|
||||
var staticFS embed.FS
|
||||
|
||||
// Server holds the dependencies for the HTTP handlers.
|
||||
type Server struct {
|
||||
cfg *config.Config
|
||||
store *store.Store
|
||||
auth *auth.Manager
|
||||
tmpl *template.Template
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
// New builds a Server and parses the embedded templates.
|
||||
func New(cfg *config.Config, st *store.Store, am *auth.Manager, log *slog.Logger) (*Server, error) {
|
||||
funcs := template.FuncMap{
|
||||
"year": func() int { return time.Now().Year() },
|
||||
"now": func() time.Time { return time.Now() },
|
||||
"clock": func() string {
|
||||
return time.Now().Format("15:04:05 MST")
|
||||
},
|
||||
}
|
||||
tmpl, err := template.New("").Funcs(funcs).ParseFS(templateFS,
|
||||
"templates/*.html", "templates/partials/*.html")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parse templates: %w", err)
|
||||
}
|
||||
return &Server{cfg: cfg, store: st, auth: am, tmpl: tmpl, log: log}, nil
|
||||
}
|
||||
|
||||
// Handler returns the fully wrapped HTTP handler.
|
||||
func (s *Server) Handler() http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
mux.HandleFunc("GET /health", s.handleHealth)
|
||||
mux.HandleFunc("GET /login", s.handleLoginPage)
|
||||
mux.HandleFunc("POST /login", s.handleLoginSubmit)
|
||||
mux.HandleFunc("POST /logout", s.handleLogout)
|
||||
mux.HandleFunc("GET /{$}", s.requireAuth(s.handleDashboard))
|
||||
mux.HandleFunc("GET /partials/status", s.requireAuth(s.handleStatusPartial))
|
||||
|
||||
staticSub, err := fs.Sub(staticFS, "static")
|
||||
if err != nil {
|
||||
panic("web: embedded static dir missing: " + err.Error())
|
||||
}
|
||||
mux.Handle("GET /static/", http.StripPrefix("/static/", http.FileServer(http.FS(staticSub))))
|
||||
|
||||
return s.recoverer(s.securityHeaders(s.requestLogger(mux)))
|
||||
}
|
||||
|
||||
// ---------- middleware ----------
|
||||
|
||||
type statusRecorder struct {
|
||||
http.ResponseWriter
|
||||
status int
|
||||
}
|
||||
|
||||
func (r *statusRecorder) WriteHeader(code int) {
|
||||
r.status = code
|
||||
r.ResponseWriter.WriteHeader(code)
|
||||
}
|
||||
|
||||
func (s *Server) requestLogger(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
start := time.Now()
|
||||
rec := &statusRecorder{ResponseWriter: w, status: http.StatusOK}
|
||||
next.ServeHTTP(rec, r)
|
||||
s.log.Info("http",
|
||||
"method", r.Method,
|
||||
"path", r.URL.Path,
|
||||
"status", rec.status,
|
||||
"remote", r.RemoteAddr,
|
||||
"duration", time.Since(start).String(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) securityHeaders(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
h := w.Header()
|
||||
h.Set("X-Content-Type-Options", "nosniff")
|
||||
h.Set("X-Frame-Options", "DENY")
|
||||
h.Set("Referrer-Policy", "same-origin")
|
||||
h.Set("Content-Security-Policy",
|
||||
"default-src 'self'; img-src 'self' data:; style-src 'self'; script-src 'self'; form-action 'self'; frame-ancestors 'none'")
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) recoverer(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
defer func() {
|
||||
if rec := recover(); rec != nil {
|
||||
s.log.Error("panic", "err", rec, "path", r.URL.Path)
|
||||
http.Error(w, "internal server error", http.StatusInternalServerError)
|
||||
}
|
||||
}()
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) requireAuth(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if !s.auth.Authenticated(r) {
|
||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
next(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- handlers ----------
|
||||
|
||||
type healthResponse struct {
|
||||
Status string `json:"status"`
|
||||
Service string `json:"service"`
|
||||
Version string `json:"version"`
|
||||
Database string `json:"database"`
|
||||
Time string `json:"time"`
|
||||
}
|
||||
|
||||
func (s *Server) handleHealth(w http.ResponseWriter, r *http.Request) {
|
||||
resp := healthResponse{
|
||||
Status: "ok",
|
||||
Service: "control-service",
|
||||
Version: s.cfg.Version,
|
||||
Database: "ok",
|
||||
Time: time.Now().UTC().Format(time.RFC3339),
|
||||
}
|
||||
code := http.StatusOK
|
||||
if err := s.store.Ping(r.Context()); err != nil {
|
||||
resp.Status = "error"
|
||||
resp.Database = "error"
|
||||
code = http.StatusServiceUnavailable
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(code)
|
||||
_ = json.NewEncoder(w).Encode(resp)
|
||||
}
|
||||
|
||||
type loginData struct {
|
||||
CSRF string
|
||||
Error string
|
||||
Username string
|
||||
}
|
||||
|
||||
func (s *Server) handleLoginPage(w http.ResponseWriter, r *http.Request) {
|
||||
if s.auth.Authenticated(r) {
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
s.render(w, r, "login.html", loginData{CSRF: s.auth.EnsureCSRF(w, r)})
|
||||
}
|
||||
|
||||
func (s *Server) handleLoginSubmit(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, "bad request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
username := strings.TrimSpace(r.PostFormValue("username"))
|
||||
|
||||
if !s.auth.CheckCSRF(r) {
|
||||
s.log.Warn("login rejected: bad csrf token", "remote", r.RemoteAddr)
|
||||
_ = s.store.Audit(r.Context(), username, "login.csrf_rejected", nil, r.RemoteAddr)
|
||||
s.render(w, r, "login.html", loginData{
|
||||
CSRF: s.auth.EnsureCSRF(w, r),
|
||||
Error: "Session expired. Please try again.",
|
||||
Username: username,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if !s.auth.CheckCredentials(username, r.PostFormValue("password")) {
|
||||
s.log.Warn("login failed", "user", username, "remote", r.RemoteAddr)
|
||||
_ = s.store.Audit(r.Context(), username, "login.failed", nil, r.RemoteAddr)
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
s.render(w, r, "login.html", loginData{
|
||||
CSRF: s.auth.EnsureCSRF(w, r),
|
||||
Error: "Incorrect username or password.",
|
||||
Username: username,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
s.auth.Issue(w)
|
||||
_ = s.store.Audit(r.Context(), username, "login.success", nil, r.RemoteAddr)
|
||||
s.log.Info("login success", "user", username, "remote", r.RemoteAddr)
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) handleLogout(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, "bad request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if s.auth.Authenticated(r) && s.auth.CheckCSRF(r) {
|
||||
_ = s.store.Audit(r.Context(), s.cfg.AdminUsername, "logout", nil, r.RemoteAddr)
|
||||
}
|
||||
s.auth.Clear(w)
|
||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
type dashboardData struct {
|
||||
Title string
|
||||
Username string
|
||||
CSRF string
|
||||
Version string
|
||||
AppEnv string
|
||||
DBPath string
|
||||
DeviceCount int
|
||||
DBHealthy bool
|
||||
ServerTime string
|
||||
ServerUp string
|
||||
}
|
||||
|
||||
var serverStarted = time.Now()
|
||||
|
||||
func (s *Server) handleDashboard(w http.ResponseWriter, r *http.Request) {
|
||||
data := s.dashboardData(w, r)
|
||||
s.render(w, r, "dashboard.html", data)
|
||||
}
|
||||
|
||||
func (s *Server) handleStatusPartial(w http.ResponseWriter, r *http.Request) {
|
||||
data := s.dashboardData(w, r)
|
||||
s.renderFragment(w, r, "status.html", data)
|
||||
}
|
||||
|
||||
func (s *Server) dashboardData(w http.ResponseWriter, r *http.Request) dashboardData {
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 2*time.Second)
|
||||
defer cancel()
|
||||
|
||||
count, err := s.store.CountDevices(ctx)
|
||||
return dashboardData{
|
||||
Title: "Dashboard",
|
||||
Username: s.cfg.AdminUsername,
|
||||
CSRF: s.auth.EnsureCSRF(w, r),
|
||||
Version: s.cfg.Version,
|
||||
AppEnv: s.cfg.AppEnv,
|
||||
DBPath: s.cfg.DBPath,
|
||||
DeviceCount: count,
|
||||
DBHealthy: err == nil,
|
||||
ServerTime: time.Now().Format("Mon 02 Jan 2006 15:04:05"),
|
||||
ServerUp: time.Since(serverStarted).Round(time.Second).String(),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) render(w http.ResponseWriter, _ *http.Request, name string, data any) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
if err := s.tmpl.ExecuteTemplate(w, name, data); err != nil {
|
||||
s.log.Error("render", "template", name, "err", err)
|
||||
http.Error(w, "template error", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) renderFragment(w http.ResponseWriter, _ *http.Request, name string, data any) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
if err := s.tmpl.ExecuteTemplate(w, name, data); err != nil {
|
||||
s.log.Error("render fragment", "template", name, "err", err)
|
||||
http.Error(w, "template error", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
308
internal/web/static/app.css
Normal file
308
internal/web/static/app.css
Normal file
@@ -0,0 +1,308 @@
|
||||
/* Internet Use Control — Control Service UI
|
||||
Built on the Family Home Lab design tokens (tokens.css).
|
||||
Rules: canvas-soft app background, white cards, hairlines, one action blue,
|
||||
pill CTAs, 8px grid, touch targets >= 44px, dark mode from the tokens. */
|
||||
|
||||
*,
|
||||
*::before,
|
||||
*::after { box-sizing: border-box; }
|
||||
|
||||
html { font-size: 16px; }
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--canvas-soft);
|
||||
color: var(--ink-secondary);
|
||||
font: var(--type-body-md);
|
||||
-webkit-font-smoothing: antialiased;
|
||||
min-height: 100dvh;
|
||||
}
|
||||
|
||||
h1, h2, h3 { margin: 0; color: var(--ink); }
|
||||
a { color: var(--primary); text-decoration: none; }
|
||||
a:hover { text-decoration: underline; }
|
||||
code {
|
||||
font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
|
||||
font-size: 0.9em;
|
||||
background: var(--surface-2);
|
||||
padding: 1px 5px;
|
||||
border-radius: var(--rounded-xs);
|
||||
}
|
||||
|
||||
/* ---------- Login ---------- */
|
||||
|
||||
.login-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: var(--space-lg);
|
||||
padding: var(--space-lg);
|
||||
background:
|
||||
radial-gradient(1200px 600px at 15% 0%, #2b3d93 0%, transparent 60%),
|
||||
var(--secondary);
|
||||
}
|
||||
|
||||
.login-band {
|
||||
width: 100%;
|
||||
max-width: 960px;
|
||||
display: grid;
|
||||
grid-template-columns: 1.1fr 0.9fr;
|
||||
gap: var(--space-xxl);
|
||||
align-items: center;
|
||||
padding: var(--space-xxl) 0;
|
||||
}
|
||||
|
||||
.login-eyebrow {
|
||||
margin: 0 0 var(--space-sm);
|
||||
font: var(--type-eyebrow);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.14em;
|
||||
color: rgba(255, 255, 255, 0.72);
|
||||
}
|
||||
|
||||
.login-headline {
|
||||
margin: 0;
|
||||
font: var(--type-display-1);
|
||||
letter-spacing: -1.5px;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.login-sub {
|
||||
margin: var(--space-md) 0 0;
|
||||
font: var(--type-body-md);
|
||||
color: rgba(255, 255, 255, 0.78);
|
||||
}
|
||||
|
||||
.auth-card {
|
||||
background: var(--surface);
|
||||
border-radius: var(--rounded-lg);
|
||||
box-shadow: var(--shadow-level-2);
|
||||
padding: var(--space-xl);
|
||||
}
|
||||
|
||||
.auth-card__title {
|
||||
font: var(--type-heading-2);
|
||||
margin-bottom: var(--space-lg);
|
||||
}
|
||||
|
||||
.auth-form { display: grid; gap: var(--space-md); }
|
||||
|
||||
.auth-error {
|
||||
margin: 0 0 var(--space-md);
|
||||
padding: var(--space-sm) var(--space-md);
|
||||
border: 1px solid var(--sticker-red);
|
||||
border-left-width: 3px;
|
||||
border-radius: var(--rounded-sm);
|
||||
color: var(--sticker-red);
|
||||
background: color-mix(in srgb, var(--sticker-red) 8%, var(--surface));
|
||||
font: var(--type-body-sm);
|
||||
}
|
||||
|
||||
.field { display: grid; gap: var(--space-xs); }
|
||||
.field__label {
|
||||
font: var(--type-eyebrow);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
color: var(--ink-muted);
|
||||
}
|
||||
|
||||
.text-input {
|
||||
width: 100%;
|
||||
min-height: 44px;
|
||||
padding: 10px 12px;
|
||||
font: var(--type-body-md);
|
||||
color: var(--ink);
|
||||
background: var(--surface);
|
||||
border: 1px solid #dddddd;
|
||||
border-radius: var(--rounded-xs);
|
||||
}
|
||||
[data-theme="dark"] .text-input { border-color: var(--hairline); }
|
||||
.text-input:focus {
|
||||
outline: none;
|
||||
border-color: var(--primary);
|
||||
box-shadow: var(--shadow-level-1), 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent);
|
||||
}
|
||||
|
||||
/* ---------- Buttons ---------- */
|
||||
|
||||
.button-primary,
|
||||
.button-utility {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 44px;
|
||||
padding: 10px 20px;
|
||||
font: var(--type-button);
|
||||
cursor: pointer;
|
||||
transition: background 120ms ease, transform 80ms ease, box-shadow 120ms ease;
|
||||
}
|
||||
.button-primary {
|
||||
border: 0;
|
||||
border-radius: var(--rounded-full);
|
||||
background: var(--primary);
|
||||
color: var(--on-primary);
|
||||
}
|
||||
.button-primary:active { background: var(--primary-active); transform: scale(0.97); }
|
||||
.button-primary:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 35%, transparent); outline-offset: 2px; }
|
||||
|
||||
.button-utility {
|
||||
border: 1px solid var(--hairline);
|
||||
border-radius: var(--rounded-md);
|
||||
background: var(--surface);
|
||||
color: var(--ink);
|
||||
padding: 8px 14px;
|
||||
}
|
||||
.button-utility:hover { box-shadow: var(--shadow-level-1); }
|
||||
|
||||
/* ---------- App shell ---------- */
|
||||
|
||||
.app { display: flex; flex-direction: column; min-height: 100dvh; }
|
||||
|
||||
.nav-bar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 10;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: var(--space-md);
|
||||
padding: var(--space-sm) var(--space-lg);
|
||||
background: var(--surface);
|
||||
border-bottom: 1px solid var(--hairline);
|
||||
}
|
||||
.nav-bar__brand {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--space-xs);
|
||||
color: var(--ink);
|
||||
font: var(--type-title);
|
||||
}
|
||||
.nav-bar__brand:hover { text-decoration: none; }
|
||||
.nav-bar__mark {
|
||||
width: 12px; height: 12px; border-radius: var(--rounded-full);
|
||||
background: var(--primary);
|
||||
box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 18%, transparent);
|
||||
}
|
||||
.nav-bar__right { display: flex; align-items: center; gap: var(--space-md); }
|
||||
.nav-bar__user { font: var(--type-body-sm); color: var(--ink-muted); }
|
||||
.nav-bar__logout { margin: 0; }
|
||||
|
||||
.container {
|
||||
width: 100%;
|
||||
max-width: var(--container-max);
|
||||
margin: 0 auto;
|
||||
padding: var(--space-xxl) var(--space-lg);
|
||||
display: grid;
|
||||
gap: var(--space-xxl);
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.page-head { display: grid; gap: var(--space-xs); }
|
||||
.heading-1 { font: var(--type-heading-1); letter-spacing: -0.8px; }
|
||||
.heading-2 { font: var(--type-heading-2); letter-spacing: -0.25px; }
|
||||
.page-head__sub { margin: 0; color: var(--ink-muted); font: var(--type-body-md); }
|
||||
|
||||
/* ---------- Cards ---------- */
|
||||
|
||||
.card-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
|
||||
gap: var(--space-md);
|
||||
}
|
||||
|
||||
.tool-card {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--hairline);
|
||||
border-radius: var(--rounded-lg);
|
||||
padding: var(--space-lg);
|
||||
display: grid;
|
||||
gap: var(--space-xs);
|
||||
align-content: start;
|
||||
}
|
||||
.tool-card__icon {
|
||||
width: 40px; height: 40px;
|
||||
display: grid; place-items: center;
|
||||
border-radius: var(--rounded-full);
|
||||
color: #ffffff;
|
||||
font-size: 15px;
|
||||
margin-bottom: var(--space-xs);
|
||||
}
|
||||
.tool-card__icon--green { background: var(--sticker-green); }
|
||||
.tool-card__icon--sky { background: var(--sticker-sky); }
|
||||
.tool-card__icon--purple { background: var(--sticker-purple); color: var(--sticker-purple-deep); }
|
||||
.tool-card__icon--orange { background: var(--sticker-orange); }
|
||||
.tool-card__title { font: var(--type-title); }
|
||||
.tool-card__desc { margin: 0; color: var(--ink-muted); font: var(--type-body-sm); }
|
||||
|
||||
.status-pill {
|
||||
justify-self: start;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin-top: var(--space-xs);
|
||||
padding: 4px 10px;
|
||||
border: 1px solid var(--hairline);
|
||||
border-radius: var(--rounded-full);
|
||||
font: var(--type-eyebrow);
|
||||
color: var(--ink-muted);
|
||||
}
|
||||
.status-pill--on { color: var(--sticker-green); border-color: color-mix(in srgb, var(--sticker-green) 40%, var(--hairline)); }
|
||||
.status-pill--off { color: var(--sticker-red); border-color: color-mix(in srgb, var(--sticker-red) 40%, var(--hairline)); }
|
||||
|
||||
.dot { width: 8px; height: 8px; border-radius: var(--rounded-full); display: inline-block; }
|
||||
.dot--on { background: var(--sticker-green); }
|
||||
.dot--off { background: var(--sticker-red); }
|
||||
.dot--faint { background: var(--ink-faint); }
|
||||
|
||||
.category-pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 4px 8px;
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--hairline);
|
||||
border-radius: var(--rounded-full);
|
||||
font: var(--type-eyebrow);
|
||||
color: var(--ink-muted);
|
||||
}
|
||||
|
||||
/* ---------- Sections ---------- */
|
||||
|
||||
.section { display: grid; gap: var(--space-md); }
|
||||
.section__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-md); }
|
||||
|
||||
.empty-state {
|
||||
background: var(--surface);
|
||||
border: 1px dashed var(--hairline);
|
||||
border-radius: var(--rounded-lg);
|
||||
padding: var(--space-xl);
|
||||
text-align: center;
|
||||
}
|
||||
.empty-state__title { margin: 0 0 var(--space-xs); font: var(--type-title); color: var(--ink); }
|
||||
.empty-state__body { margin: 0 auto; max-width: 52ch; color: var(--ink-muted); font: var(--type-body-sm); }
|
||||
|
||||
/* ---------- Footer ---------- */
|
||||
|
||||
.app-foot,
|
||||
.login-foot {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-xs);
|
||||
padding: var(--space-lg);
|
||||
color: var(--ink-faint);
|
||||
font: var(--type-caption);
|
||||
}
|
||||
.app-foot { justify-content: center; border-top: 1px solid var(--hairline); background: var(--surface); }
|
||||
.login-foot { color: rgba(255, 255, 255, 0.6); }
|
||||
.app-foot__sep { opacity: 0.5; }
|
||||
|
||||
/* ---------- Responsive ---------- */
|
||||
|
||||
@media (max-width: 760px) {
|
||||
.login-band { grid-template-columns: 1fr; gap: var(--space-xl); text-align: left; }
|
||||
.login-headline { font: var(--type-heading-1); letter-spacing: -0.8px; }
|
||||
.container { padding: var(--space-lg) var(--space-md); gap: var(--space-xl); }
|
||||
.nav-bar { padding: var(--space-sm) var(--space-md); }
|
||||
.nav-bar__user { display: none; }
|
||||
}
|
||||
BIN
internal/web/static/fonts/inter-400.woff2
Normal file
BIN
internal/web/static/fonts/inter-400.woff2
Normal file
Binary file not shown.
BIN
internal/web/static/fonts/inter-500.woff2
Normal file
BIN
internal/web/static/fonts/inter-500.woff2
Normal file
Binary file not shown.
BIN
internal/web/static/fonts/inter-600.woff2
Normal file
BIN
internal/web/static/fonts/inter-600.woff2
Normal file
Binary file not shown.
BIN
internal/web/static/fonts/inter-700.woff2
Normal file
BIN
internal/web/static/fonts/inter-700.woff2
Normal file
Binary file not shown.
1
internal/web/static/htmx.min.js
vendored
Normal file
1
internal/web/static/htmx.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
110
internal/web/static/tokens.css
Normal file
110
internal/web/static/tokens.css
Normal file
@@ -0,0 +1,110 @@
|
||||
/* ============================================================
|
||||
Family Home Lab — Design Tokens
|
||||
Source: DESIGN.md (Notion design language)
|
||||
Only structural/semantic tokens here. All values map 1:1.
|
||||
============================================================ */
|
||||
|
||||
/* Inter (@fontsource) — self-hosted substitute for NotionInter */
|
||||
@font-face { font-family: "Inter"; font-style: normal; font-weight: 400; font-display: swap; src: url("/static/fonts/inter-400.woff2") format("woff2"); }
|
||||
@font-face { font-family: "Inter"; font-style: normal; font-weight: 500; font-display: swap; src: url("/static/fonts/inter-500.woff2") format("woff2"); }
|
||||
@font-face { font-family: "Inter"; font-style: normal; font-weight: 600; font-display: swap; src: url("/static/fonts/inter-600.woff2") format("woff2"); }
|
||||
@font-face { font-family: "Inter"; font-style: normal; font-weight: 700; font-display: swap; src: url("/static/fonts/inter-700.woff2") format("woff2"); }
|
||||
|
||||
:root {
|
||||
/* --- Surface --- */
|
||||
--canvas-soft: #f6f5f4;
|
||||
--surface: #ffffff;
|
||||
--surface-2: #f2f2f1;
|
||||
--hairline: #e6e6e6;
|
||||
|
||||
/* --- Text --- */
|
||||
--ink: #000000;
|
||||
--ink-secondary: #31302e;
|
||||
--ink-muted: #615d59;
|
||||
--ink-faint: #a39e98;
|
||||
|
||||
/* --- Structural accents --- */
|
||||
--primary: #0075de; /* the ONLY action colour */
|
||||
--primary-active: #005bab;
|
||||
--on-primary: #ffffff;
|
||||
--secondary: #213183; /* deep indigo — login band + greeting only */
|
||||
|
||||
/* --- Sticker palette (decorative only) --- */
|
||||
--sticker-sky: #62aef0; /* chat */
|
||||
--sticker-purple: #d6b6f6; /* image */
|
||||
--sticker-pink: #ff64c8; /* video */
|
||||
--sticker-orange: #dd5b00; /* audio */
|
||||
--sticker-teal: #2a9d99; /* docs */
|
||||
--sticker-green: #1aae39; /* status: online/saved */
|
||||
--sticker-red: #d33a2b; /* status: failed / error (ON_OFF.md decision) */
|
||||
--sticker-purple-deep: #391c57; /* illustration only */
|
||||
--sticker-orange-deep: #793400; /* illustration only */
|
||||
|
||||
/* --- Typography (Inter, self-hosted via @font-face) --- */
|
||||
--font-family: "Inter", -apple-system, system-ui, "Segoe UI",
|
||||
Helvetica, Arial, sans-serif;
|
||||
|
||||
/* Font-family is baked into each token below: the CSS `font` shorthand
|
||||
resets font-family to the UA default (serif) unless a family is written,
|
||||
and it cannot carry letter-spacing — so weights/sizes ship inline and the
|
||||
family is appended per token. */
|
||||
--type-display-1: 700 48px/1.05 var(--font-family);
|
||||
--type-heading-1: 700 32px/1.1 var(--font-family);
|
||||
--type-heading-2: 700 22px/1.27 var(--font-family);
|
||||
--type-title: 600 17px/1.4 var(--font-family);
|
||||
--type-body-md: 400 15px/1.5 var(--font-family);
|
||||
--type-body-sm: 400 14px/1.4 var(--font-family);
|
||||
--type-button: 500 15px/1.4 var(--font-family);
|
||||
--type-caption: 400 13px/1.43 var(--font-family);
|
||||
--type-eyebrow: 600 12px/1.33 var(--font-family);
|
||||
|
||||
/* --- Layout (base unit 8px) --- */
|
||||
--space-xxs: 4px;
|
||||
--space-xs: 8px;
|
||||
--space-sm: 12px;
|
||||
--space-md: 16px;
|
||||
--space-lg: 24px;
|
||||
--space-xl: 28px;
|
||||
--space-xxl: 32px;
|
||||
|
||||
--container-max: 1200px;
|
||||
|
||||
/* --- Elevation --- */
|
||||
--shadow-level-1: rgba(0, 0, 0, 0.01) 0 0.175px 1px,
|
||||
rgba(0, 0, 0, 0.02) 0 0.8px 3px,
|
||||
rgba(0, 0, 0, 0.027) 0 2px 8px,
|
||||
rgba(0, 0, 0, 0.04) 0 4px 18px;
|
||||
--shadow-level-2: rgba(0, 0, 0, 0.0122) 0 0.175px 1px,
|
||||
rgba(0, 0, 0, 0.024) 0 0.8px 3px,
|
||||
rgba(0, 0, 0, 0.032) 0 2px 8px,
|
||||
rgba(0, 0, 0, 0.047) 0 4px 18px,
|
||||
rgba(0, 0, 0, 0.05) 0 23px 52px;
|
||||
|
||||
/* --- Shapes --- */
|
||||
--rounded-xs: 4px;
|
||||
--rounded-sm: 5px;
|
||||
--rounded-md: 8px;
|
||||
--rounded-lg: 12px;
|
||||
--rounded-full: 9999px;
|
||||
}
|
||||
|
||||
/* Dark mode — flip the semantic tokens only (components use var(--…)). */
|
||||
[data-theme="dark"] {
|
||||
--canvas-soft: #141518;
|
||||
--surface: #1c1e22;
|
||||
--surface-2: #24262c;
|
||||
--hairline: #33363d;
|
||||
--ink: #f5f6f7;
|
||||
--ink-secondary: #dcdee2;
|
||||
--ink-muted: #a9adb6;
|
||||
--ink-faint: #727680;
|
||||
--primary: #3d8be0;
|
||||
--primary-active: #5d9ff0;
|
||||
--on-primary: #ffffff;
|
||||
--secondary: #10142a;
|
||||
--shadow-level-1: rgba(0, 0, 0, 0.45) 0 1px 3px;
|
||||
--shadow-level-2: rgba(0, 0, 0, 0.55) 0 5px 22px;
|
||||
}
|
||||
|
||||
/* Numerals: enable OpenType lnum */
|
||||
html { font-feature-settings: "lnum" 1; }
|
||||
54
internal/web/templates/dashboard.html
Normal file
54
internal/web/templates/dashboard.html
Normal file
@@ -0,0 +1,54 @@
|
||||
{{define "dashboard.html"}}<!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>{{.Title}} — Internet Use Control</title>
|
||||
<link rel="stylesheet" href="/static/tokens.css">
|
||||
<link rel="stylesheet" href="/static/app.css">
|
||||
<script src="/static/htmx.min.js" defer></script>
|
||||
</head>
|
||||
<body class="app">
|
||||
<nav class="nav-bar">
|
||||
<a class="nav-bar__brand" href="/">
|
||||
<span class="nav-bar__mark" aria-hidden="true"></span>
|
||||
Internet Use Control
|
||||
</a>
|
||||
<div class="nav-bar__right">
|
||||
<span class="nav-bar__user">{{.Username}}</span>
|
||||
<form method="post" action="/logout" class="nav-bar__logout">
|
||||
<input type="hidden" name="csrf" value="{{.CSRF}}">
|
||||
<button class="button-utility" type="submit">Sign out</button>
|
||||
</form>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main class="container">
|
||||
<header class="page-head">
|
||||
<h1 class="heading-1">Dashboard</h1>
|
||||
<p class="page-head__sub">Phase 1 skeleton — the Control Service is up and answering.</p>
|
||||
</header>
|
||||
|
||||
{{template "status.html" .}}
|
||||
|
||||
<section class="section" aria-labelledby="devices-title">
|
||||
<div class="section__head">
|
||||
<h2 id="devices-title" class="heading-2">Devices</h2>
|
||||
<span class="category-pill"><span class="dot dot--faint"></span>0 registered</span>
|
||||
</div>
|
||||
<div class="empty-state">
|
||||
<p class="empty-state__title">No devices yet</p>
|
||||
<p class="empty-state__body">Device registration arrives in Phase 2. Until then the
|
||||
dashboard, session login and <code>/health</code> are the working pieces.</p>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<footer class="app-foot">
|
||||
<span>Control Service · {{.Version}} · {{.AppEnv}}</span>
|
||||
<span class="app-foot__sep">·</span>
|
||||
<span>{{year}} Family Home Lab</span>
|
||||
</footer>
|
||||
</body>
|
||||
</html>{{end}}
|
||||
40
internal/web/templates/login.html
Normal file
40
internal/web/templates/login.html
Normal file
@@ -0,0 +1,40 @@
|
||||
{{define "login.html"}}<!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>Sign in — Internet Use Control</title>
|
||||
<link rel="stylesheet" href="/static/tokens.css">
|
||||
<link rel="stylesheet" href="/static/app.css">
|
||||
</head>
|
||||
<body class="login-page">
|
||||
<main class="login-band">
|
||||
<div class="login-band__inner">
|
||||
<p class="login-eyebrow">Internet Use Control</p>
|
||||
<h1 class="login-headline">Good to see you,<br>Sam.</h1>
|
||||
<p class="login-sub">Sign in to manage the kids' devices.</p>
|
||||
</div>
|
||||
|
||||
<section class="auth-card" aria-labelledby="signin-title">
|
||||
<h2 id="signin-title" class="auth-card__title">Sign in</h2>
|
||||
{{if .Error}}<p class="auth-error" role="alert">{{.Error}}</p>{{end}}
|
||||
<form method="post" action="/login" class="auth-form" autocomplete="on">
|
||||
<input type="hidden" name="csrf" value="{{.CSRF}}">
|
||||
<label class="field">
|
||||
<span class="field__label">Username</span>
|
||||
<input class="text-input" type="text" name="username" value="{{.Username}}"
|
||||
autocomplete="username" autocapitalize="none" spellcheck="false" required>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span class="field__label">Password</span>
|
||||
<input class="text-input" type="password" name="password"
|
||||
autocomplete="current-password" required>
|
||||
</label>
|
||||
<button class="button-primary" type="submit">Sign in</button>
|
||||
</form>
|
||||
</section>
|
||||
</main>
|
||||
<footer class="login-foot">Family Home Lab · Control Service</footer>
|
||||
</body>
|
||||
</html>{{end}}
|
||||
34
internal/web/templates/partials/status.html
Normal file
34
internal/web/templates/partials/status.html
Normal file
@@ -0,0 +1,34 @@
|
||||
{{define "status.html"}}<section class="card-grid" id="status" hx-get="/partials/status" hx-trigger="every 10s" hx-swap="outerHTML">
|
||||
<article class="tool-card">
|
||||
<div class="tool-card__icon tool-card__icon--green" aria-hidden="true">●</div>
|
||||
<h3 class="tool-card__title">Service</h3>
|
||||
<p class="tool-card__desc">
|
||||
{{if .DBHealthy}}Running{{else}}Database error{{end}}
|
||||
</p>
|
||||
<span class="status-pill {{if .DBHealthy}}status-pill--on{{else}}status-pill--off{{end}}">
|
||||
<span class="dot {{if .DBHealthy}}dot--on{{else}}dot--off{{end}}"></span>
|
||||
{{if .DBHealthy}}online{{else}}offline{{end}}
|
||||
</span>
|
||||
</article>
|
||||
|
||||
<article class="tool-card">
|
||||
<div class="tool-card__icon tool-card__icon--sky" aria-hidden="true">▤</div>
|
||||
<h3 class="tool-card__title">Database</h3>
|
||||
<p class="tool-card__desc">SQLite · source of truth</p>
|
||||
<span class="status-pill status-pill--muted">{{if .DBHealthy}}ok{{else}}error{{end}}</span>
|
||||
</article>
|
||||
|
||||
<article class="tool-card">
|
||||
<div class="tool-card__icon tool-card__icon--purple" aria-hidden="true">⏱</div>
|
||||
<h3 class="tool-card__title">Uptime</h3>
|
||||
<p class="tool-card__desc">{{.ServerUp}}</p>
|
||||
<span class="status-pill status-pill--muted">since boot</span>
|
||||
</article>
|
||||
|
||||
<article class="tool-card">
|
||||
<div class="tool-card__icon tool-card__icon--orange" aria-hidden="true">⌚</div>
|
||||
<h3 class="tool-card__title">Server time</h3>
|
||||
<p class="tool-card__desc">{{.ServerTime}}</p>
|
||||
<span class="status-pill status-pill--muted">local</span>
|
||||
</article>
|
||||
</section>{{end}}
|
||||
Reference in New Issue
Block a user