Gate the dashboard on the site's admin login and add a setup page
Like job-tracker, the tracker forwards the visitor's cookies to the site backend's /auth/validate-admin instead of asking for an API key. Signed in, the dashboard shows every device's data. The new /setup page has instructions for each collector and creates and revokes API keys. The userscript is served publicly at /tracker.user.js. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+29
-7
@@ -1,5 +1,5 @@
|
||||
// Package web serves the dashboard, a single static page that reads the
|
||||
// /api/v1 query endpoints with an API key the viewer enters.
|
||||
// Package web holds the dashboard pages, which read /api/v1 with the main
|
||||
// site's session cookies, and the browser userscript.
|
||||
package web
|
||||
|
||||
import (
|
||||
@@ -7,10 +7,32 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//go:embed index.html
|
||||
var index []byte
|
||||
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
|
||||
)
|
||||
|
||||
func Handler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.Write(index)
|
||||
// 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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user