services

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package services implements Roost's emulated network services (HTTP, HTTPS, DNS, SSH, dashboard) over a shared device.State.

Index

Constants

This section is empty.

Variables

View Source
var Version = "0.1.0"

Version is the roost release, surfaced by the `version`/`ver` commands and the CLI. Override at build time with:

go build -ldflags "-X github.com/stevenssparks/roost/services.Version=1.2.3"

Functions

func NewDNSHandler

func NewDNSHandler(st *device.State, answerIP string) dns.Handler

NewDNSHandler answers every A/ANY query for any name with answerIP (TTL 30) and records the lookup, mirroring the board's wildcard DNS funnel.

func NewDashboard

func NewDashboard(st *device.State, indexHTML []byte) http.Handler

NewDashboard serves the live console. indexHTML is the embedded dashboard page (passed in so this package stays free of embed wiring).

func NewHandler

func NewHandler(st *device.State, service string) http.Handler

NewHandler builds the shared router used by both HTTP and HTTPS. service is "HTTP" or "HTTPS" and tags every logged hit.

func SelectCertificate

func SelectCertificate(certDir, domain string) (tls.Certificate, string, error)

SelectCertificate returns the image's real cert if certDir holds a valid fullchain.pem + privkey.pem (source "real"); otherwise a freshly generated self-signed cert for domain (source "self-signed"). It only errors if generating the fallback itself fails. An empty certDir always falls back.

func StartDNS

func StartDNS(st *device.State, addr, answerIP string) (*dns.Server, error)

StartDNS starts a UDP DNS server on addr and returns once it is bound. The caller keeps the server for shutdown.

func StartSSH

func StartSSH(st *device.State, addr, user, pass, hostKeyPath string, shellProto Shell) error

StartSSH runs the gliderlabs SSH server (blocking; run it in a goroutine). shellProto carries the image identity (prompt/ssid/title/hostname/extended); each session gets a copy bound to st. The session is driven as a raw interactive terminal so it works with a real `ssh` client (PTY, CR line endings, local echo).

Types

type Shell

type Shell struct {
	St        *device.State
	Extended  bool
	Prompt    string
	SSID      string
	Title     string
	Hostname  string
	User      string
	Motd      string // optional login message-of-the-day (from the image manifest)
	DNSAnswer string // the IP the DNS service funnels every name to
	// contains filtered or unexported fields
}

Shell is the device mini-shell. Its identity (prompt, ssid, title, hostname, user) comes from the image manifest so the same binary can present as "friendlyportal#" or "roost#".

func (*Shell) Banner

func (sh *Shell) Banner() string

Banner is the login MOTD shown on SSH connect: a unix-style welcome with live system stats. Uses \n line endings; the SSH transport converts to \r\n on PTYs.

func (*Shell) Complete

func (sh *Shell) Complete(line string) (string, []string)

Complete returns a possibly-extended version of line for tab completion, plus a list of candidates to display when the completion is ambiguous with no further progress. The returned line always has the input as a prefix (tab only extends), so the SSH transport can just echo the added characters.

func (*Shell) Run

func (sh *Shell) Run(cmd string) string

Run executes one command (except transport commands like tail/exit, handled by the SSH loop) and returns its output.

Jump to

Keyboard shortcuts

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