webui

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: AGPL-3.0 Imports: 10 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.

Hashed first, rather than compared directly. 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, and on a page with no rate limit that is a free head start. Two SHA-256 sums are always the same size, so the comparison below cannot short circuit on anything.

The claim token compare in internal/control was built to avoid exactly this and this one was not; they now agree.

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.

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