serverinfo

package
v0.18.3 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package serverinfo backs the read-only "Server" tab: it sizes Mooring's own on-disk footprint, lists release artifacts for cleanup, and serves an allow-listed, read-only file view. Everything here is deliberately bounded and fail-closed — it is a LOOK-but-don't-break tool. The only mutation any of it performs is deleting an OLD downloaded mooring *.deb (DebManager), which the web layer gates behind password+TOTP re-auth.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned for an unknown root name or a missing path.
	ErrNotFound = errors.New("serverinfo: not found")
	// ErrDenied is returned for anything outside an allow-listed root, anything
	// under a denied prefix, or a traversal/symlink-escape attempt.
	ErrDenied = errors.New("serverinfo: denied")
	// ErrTooBig is returned when a file exceeds the read cap.
	ErrTooBig = errors.New("serverinfo: file too large to view")
)
View Source
var ErrNotADeb = errors.New("serverinfo: not a mooring .deb")

ErrNotADeb is returned when a delete target isn't a recognized Mooring .deb.

View Source
var ErrRunningDeb = errors.New("serverinfo: refusing to delete the running version")

ErrRunningDeb is returned when a delete target is the currently-running version.

Functions

func DeleteDeb

func DeleteDeb(dir, name, runningVersion string) error

DeleteDeb removes one Mooring .deb from dir. It is intentionally narrow: name must be a bare filename (no path separators) matching debRe exactly, must not be the running version, and the resolved file must be a regular file located directly in dir (re-checked after symlink resolution so a symlinked name can't escape). The web layer additionally gates this behind password+TOTP re-auth.

Types

type Deb

type Deb struct {
	Name    string
	Version string
	Arch    string
	Size    uint64
	Mod     time.Time
	Running bool // version matches the running binary → never deletable
}

Deb is one Mooring release package found in the configured cache dir.

func ListDebs

func ListDebs(dir, runningVersion string) ([]Deb, error)

ListDebs returns the Mooring .deb files directly inside dir (non-recursive), newest first, marking the one matching runningVersion as Running. A missing dir yields an empty list (not an error) — the feature is simply "nothing to clean".

type Entry

type Entry struct {
	Name  string
	IsDir bool
	Size  uint64
	Mod   time.Time
}

Entry is one listed directory child.

type FileBrowser

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

FileBrowser serves an allow-listed, read-only view of the filesystem. Two independent gates apply to EVERY path, after resolving symlinks on the final target: (1) it must stay within one declared root; (2) it must not fall under any denied prefix (secrets, keys, the DB, the config). The deny list wins.

func NewFileBrowser

func NewFileBrowser(roots []Root, deny []string, maxList int, maxRead int64) *FileBrowser

NewFileBrowser canonicalizes the given roots and denied prefixes (resolving symlinks so the containment checks compare real paths). Roots that don't exist or resolve under a denied prefix are dropped (fail-closed). With no usable roots the browser lists/reads nothing.

func (*FileBrowser) Enabled

func (b *FileBrowser) Enabled() bool

Enabled reports whether any root is browsable.

func (*FileBrowser) List

func (b *FileBrowser) List(rootName, rel string) ([]Entry, error)

List returns the children of rel within the named root (rel "" = the root).

func (*FileBrowser) Read

func (b *FileBrowser) Read(rootName, rel string) (content []byte, binary bool, err error)

Read returns a regular file's contents, capped at maxRead. binary=true (with no content) when the file looks binary, so the UI can refuse to render it inline.

func (*FileBrowser) Roots

func (b *FileBrowser) Roots() []Root

Roots returns the usable allow-listed roots (for the UI's root picker).

type Footprint

type Footprint struct {
	At      time.Time
	Groups  []Usage
	Total   uint64
	Files   int
	Partial bool // a group's walk hit the budget/timeout and may undercount
}

Footprint is Mooring's measured on-disk usage, grouped by purpose, plus the wall-clock time the measurement took (so the UI can warn if it's getting slow).

func MeasureFootprint

func MeasureFootprint(ctx context.Context, targets []Target) Footprint

MeasureFootprint sizes each target subtree. It is intended to run on the slow monitor cadence (NOT per request) because a WalkDir over large git stores can be slow; a per-target deadline (derived from ctx) keeps one huge tree from stalling the whole measurement. Missing directories contribute zero (not an error) — Mooring creates them lazily. A walk that trips the context budget marks the result Partial rather than failing.

type Root

type Root struct {
	Name string // stable key used in the UI + URL (e.g. "logs")
	Path string // absolute, symlink-resolved root directory
}

Root is one allow-listed directory the operator may browse, read-only.

type Target

type Target struct {
	Label string
	Path  string
}

Target names a directory to size and the label to show for it.

type Usage

type Usage struct {
	Label string // human label, e.g. "App run dirs"
	Path  string // the directory measured
	Bytes uint64 // total size of regular files in the subtree
	Files int    // number of regular files counted
}

Usage is the size + entry count of one directory subtree.

Jump to

Keyboard shortcuts

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