Documentation
¶
Overview ¶
Package web serves the browser: the console (a React application under /workspace, which calls the REST API with its session, workspacefiles.go), and the pages that must work without it. Those are the public ones at the site's root (the status pages and their badges, or a page that names the deployment), the pages people open from the chat without an account (an alert's page with its timeline and the sessions on its machines, a session's page with its replay; view-only, with a signed link from package link or a bearer credential carrying the scope the matching API route needs), and the page where a person allows an MCP client (oauth.go). They are HTML from embedded templates on the design system @openlinkos/ui (vendored under static/ol), in the configured language, readable on a phone; every page says it runs on Beacon and links to the project (brand.go).
A wrong or expired link is a plain 404, so that it reveals nothing, not even that the page exists. A person signed in to the console opens the console's own page instead. Text from outside Beacon reaches the pages cleaned by the bridge and is escaped by html/template on the way out; the pages carry no inline script or style, and their Content-Security-Policy allows nothing from elsewhere.
Index ¶
- Constants
- Variables
- type MonitorFigures
- type Server
- func (s *Server) APISession(r *http.Request) (api.ConsoleSession, bool)
- func (s *Server) Console() bool
- func (s *Server) Hosts(next http.Handler) http.Handler
- func (s *Server) Language(r *http.Request) i18n.Lang
- func (s *Server) Register(mux *http.ServeMux)
- func (s *Server) SetLanguage(w http.ResponseWriter, l i18n.Lang)
- func (s *Server) UpdateSettings(lang i18n.Lang, loc *time.Location, hooks []config.Agent, ...)
Constants ¶
const CSP = "default-src 'none'; script-src 'self' 'wasm-unsafe-eval'; style-src 'self'; font-src 'self'; img-src 'self' data:; " +
"connect-src 'self'; base-uri 'none'; form-action 'self'; frame-ancestors 'none'"
CSP is the pages' Content-Security-Policy: scripts, styles and fonts from Beacon itself only (the player's terminal runs as WebAssembly, hence wasm-unsafe-eval), no inline script or style, fetches and forms to Beacon only.
Variables ¶
var BadgeKinds = []string{"status", "uptime", "uptime-30d", "response", "cert"}
BadgeKinds are the kinds of monitor badge.
var BadgeStyles = []string{"flat", "flat-square", "plastic", "for-the-badge"}
BadgeStyles are the styles a badge may be drawn in, the default first.
Functions ¶
This section is empty.
Types ¶
type MonitorFigures ¶
type MonitorFigures struct {
Name, Status string
Uptime24h, Uptime30d *float64
LatencyMS *float64
CertDays *int
}
MonitorFigures are what a monitor's badges show.
type Server ¶
type Server struct {
Bridge *bridge.Bridge
SSH *sshgate.Gate
Auth *api.Auth
Pages *link.Pages
Lang i18n.Lang
Location *time.Location
Log *slog.Logger
Now func() time.Time
Store *store.Store
Config *configdb.Service
Hooks []config.Agent
// MonitorFigures are a monitor's figures for its public badges (monitor_badges.go); nil: no badges.
MonitorFigures func(id string) (MonitorFigures, bool)
Version string
// Status computes the public status pages (status.go); nil leaves them out.
Status *status.Service
Branding config.Branding
// OAuth is Beacon's authorization server for MCP clients (package oauth); nil leaves /oauth/authorize out.
OAuth *oauth.Server
// contains filtered or unexported fields
}
Server serves the pages. SSH is nil when the channel is off (session pages are then 404); Auth checks bearer tokens (nil: only signed links open pages); Pages checks the links' signatures and signs the links inside pages (nil: only tokens open pages, and pages link nowhere).
The console needs Store, where its sign-ins are kept: nil leaves it out, and only the pages opened from the chat are served. Config is the configuration Beacon holds (the badges read it), Hooks the agent hooks configured, and Version Beacon's own. Branding is what the public pages say of the deployment and of Beacon.
func (*Server) APISession ¶
APISession is the request's console session: who its viewer is now, its CSRF secret and its end.
func (*Server) Console ¶
Console reports whether the console is served (it needs the store for its sign-ins).
func (*Server) Hosts ¶
Hosts serves a status page's own host name: the page at /, its incidents under /incidents/, its JSON, feed and badges, robots.txt and the static files the page needs; nothing else of Beacon, the console, the API and MCP included, answers there. Other hosts go to next.
func (*Server) Register ¶
Register adds the pages' routes to mux: GET / is public (home.go), the console is under /workspace, the pages a link opens under /console, and the paths those had before they moved there send people on to their new place.
func (*Server) SetLanguage ¶
func (s *Server) SetLanguage(w http.ResponseWriter, l i18n.Lang)
SetLanguage keeps the browser's choice of language for a year.