Both pages share style.css and a top bar with Dashboard and Setup tabs. The dashboard gains summary tiles, card sections and friendly kind names. The setup page puts each collector in a collapsible section with its own Generate key button, which picks a free name, copies the key and fills it into that collector's steps. Command blocks get Copy buttons. Co-Authored-By: Claude Opus 5.5 <[email protected]>
49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
// Package web holds the dashboard pages, which read /api/v1 with the main
|
|
// site's session cookies, and the browser userscript.
|
|
package web
|
|
|
|
import (
|
|
_ "embed"
|
|
"net/http"
|
|
)
|
|
|
|
var (
|
|
//go:embed index.html
|
|
Index []byte
|
|
// LoginRedirect is served instead of a page when the visitor isn't the
|
|
// site's admin.
|
|
//go:embed login.html
|
|
LoginRedirect []byte
|
|
//go:embed setup.html
|
|
Setup []byte
|
|
//go:embed tracker.user.js
|
|
userScript []byte
|
|
//go:embed style.css
|
|
style []byte
|
|
)
|
|
|
|
// Style serves the stylesheet the pages share. It's public: the login
|
|
// redirect doesn't use it, but there's nothing private in it either.
|
|
func Style(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "text/css; charset=utf-8")
|
|
w.Header().Set("Cache-Control", "no-cache")
|
|
w.Write(style)
|
|
}
|
|
|
|
// Page serves a static HTML page.
|
|
func Page(page []byte) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
w.Header().Set("Cache-Control", "no-store")
|
|
w.Write(page)
|
|
}
|
|
}
|
|
|
|
// UserScript serves the browser collector. Opening a *.user.js URL in a
|
|
// browser with Violentmonkey installed offers to install it, and Violentmonkey
|
|
// then checks the same URL for updates. It holds no secrets, so it is public.
|
|
func UserScript(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "text/javascript; charset=utf-8")
|
|
w.Write(userScript)
|
|
}
|