webui

package
v0.2.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package webui is the session, auth and rendering plumbing behind the reostream daemon's operator page -- one process, one page, covering both the fleet and the cameras on it. It holds no policy about that page, only the mechanism.

Index

Constants

View Source
const SessionTTL = 12 * time.Hour

SessionTTL is an absolute expiry from issue, not a sliding window: these pages can read and write camera credentials, so a session that lives forever on a shared machine is a real exposure, and there is no renewal on activity to defeat it. A long-lived response such as a log stream in particular must not count as activity; it is not evidence anyone is still at the keyboard.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	Store           *SessionStore
	Password        string
	AllowNoPassword bool
	LoginPath       string
	CookieName      string
}

Auth gates a handler on a session. LoginPath is where an unauthenticated request is sent.

CookieName is supplied by the consumer, not a shared package constant. There is one surface today, the daemon's operator page, and this package holds nothing that assumes it. Two surfaces on one host that shared a cookie name would each run their own SessionStore, so logging into one would silently log the other out, intermittently, whenever the browser resent whichever cookie it last set for that name. That is exactly what happened while this project had a second page, and making every caller name its own cookie is what stops a second one reintroducing it.

func (Auth) Check

func (a Auth) Check(password string) bool

Check compares a submitted password in constant time, so a wrong one cannot be found a character at a time by measuring the reply.

Derived first, rather than compared directly, for two separate reasons.

Length: subtle.ConstantTimeCompare returns 0 immediately when the two lengths differ, so comparing the raw strings is constant time in their CONTENT and not in their LENGTH. A guesser could learn how long the real password is by timing replies. Two derived keys are always the same size, so the comparison below cannot short circuit on anything.

Cost: see loginKDFIterations. Both sides are derived on every call, not just the submitted one. Deriving the configured password once and caching it would save the operator ~83ms and halve the attacker's cost per guess, which is the wrong way round.

func (Auth) Wrap

func (a Auth) Wrap(h http.Handler) http.Handler

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

Renderer parses a set of page templates against a shared layout.

func NewRenderer

func NewRenderer(fsys fs.FS, glob string, funcs template.FuncMap) (*Renderer, error)

NewRenderer parses every template matching glob in fsys as the base set. funcs is registered before parsing, so a template body may call anything in it; nil is fine for a caller with no functions to add.

func (*Renderer) Render

func (r *Renderer) Render(w http.ResponseWriter, page string, data any)

Render writes one page. The base set is cloned and the page parsed into the clone on every call, because each page defines its own "body" block and a single shared set would have them collide.

func (*Renderer) RenderWith added in v0.2.5

func (r *Renderer) RenderWith(w http.ResponseWriter, page string, data any, funcs template.FuncMap)

RenderWith is Render with funcs replacing, for this one page, functions of the same names registered at NewRenderer. It is how a value that belongs to one request, such as the path prefix the page is served under, reaches every template without every page's data carrying it. The clone is this call's own, so this is safe while other requests render with other values.

type SessionStore

type SessionStore struct {
	// contains filtered or unexported fields
}

func NewSessionStore

func NewSessionStore() *SessionStore

func (*SessionStore) Issue

func (s *SessionStore) Issue() (string, error)

func (*SessionStore) Revoke added in v0.1.3

func (s *SessionStore) Revoke(tok string)

Revoke ends one session, for a sign out. A token that is not there is not an error: a cookie can outlive the session it names.

func (*SessionStore) RevokeAll added in v0.1.3

func (s *SessionStore) RevokeAll()

RevokeAll ends every session.

This is what a password change has to call. Changing the password without it leaves every browser that was already signed in signed in, including the one whose access was the reason for changing it, which makes the change worth very little.

func (*SessionStore) SetClock

func (s *SessionStore) SetClock(now func() time.Time)

SetClock overrides the clock so a test can move time instead of sleeping out the TTL.

func (*SessionStore) Valid

func (s *SessionStore) Valid(tok string) bool

Valid reports whether tok is a live session. Every call sweeps the whole map, not just tok: a token nobody ever presents again, an abandoned cookie or a browser that never returns, would otherwise never be checked and never removed, and the map would grow without bound.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL