- Rust 83.3%
- HTML 9.3%
- CSS 4.8%
- JavaScript 2.2%
- Shell 0.4%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
Describe a change ("add a port forward for UDP 27015 to aigen for cs2") and
a language model looks up the services, machines and forwards, then
prepares it with the existing planners as an ordinary pending plan. It
never applies anything: the reply links the plan, and the admin reviews
and applies it as usual.
The model is chosen under Settings -> Assistant: a local Ollama (nothing
leaves the LAN) or Anthropic's Messages API, both over plain HTTP behind
one trait. Off by default; Test connections checks it. Conversations are
kept in a new chats table.
Also adds plans::add_forwards (forward WAN ports to a machine, skipping
ones that exist and refusing shadowed ones), which the assistant uses to
add a forward to an existing service or machine.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
||
| .claude | ||
| deploy | ||
| src | ||
| static | ||
| templates | ||
| tests | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| README.md | ||
Switchboard
One place to publish a homelab service. Adding myapp.thenymans.com normally means touching the Caddyfile,
Pi-hole, Cloudflare and sometimes the router; Switchboard does all of it from one form, shows exactly what
will change, and applies it step by step.
- Web services go through Caddy: a site block (public, or LAN-only via the
lan_onlysnippet with optional extra networks), a Pi-hole record pointing at Caddy, and, when public, a Cloudflare CNAME to the domain. A port forward straight to one of a site's upstreams (address and port, like Plex's remote access on 32400) is shown as part of that site. - Game servers / other ports go straight to a machine: WAN port forwards on OPNsense (passing their own traffic, NAT reflection off), a Pi-hole record to the machine, and a Cloudflare CNAME when public.
- DHCP reservations: the machine behind a service gets a fixed address from its current lease, so forwards and upstreams can't drift. A reserved machine can be moved to a new address from its service page: the reservation changes now (and, optionally, every Caddy upstream, Pi-hole record and port forward that uses the old address), and the machine picks it up at its next lease renewal or reboot. Until then the Services page shows the move as pending.
- Drift report: the Services page reads everything live and flags mismatches: sites with no Pi-hole record, LAN-only sites listed in public DNS, public names with nothing behind them, forwards to unreserved addresses, forwards with reflection on, the secondary Pi-hole lagging, a Cloudflare wildcard, and so on. A wrong or mistyped Pi-hole record can be repointed from the service page (Pi-hole record).
- Groups and filters: file services under headings like AI or Games (a service can be in several; groups are collapsible and reorderable), and filter the table by any column. Filters stay in the URL, so a reload or a shared link keeps the view.
- Chat: describe a change in plain words ("add a port forward for UDP 27015 to aigen for cs2") and an assistant looks up the services, machines and forwards, then prepares it as an ordinary preview. It never applies anything: you open the plan it links and click Apply as usual. Choose the model under Settings → Assistant: a local Ollama (nothing leaves the LAN) or Anthropic's API (Claude). Either way the model sees your service names, addresses and forwards. Off until you pick one.
- Caddyfile editor for everything else (replaces CaddyGUI), with the same preview/apply flow.
Nothing is stored about services themselves: Caddy, Pi-hole, Cloudflare and OPNsense are the source of truth, so changes made by hand show up immediately. The database holds only the admin account, settings (secrets encrypted with a key in the data directory), the history of applied changes, which groups each name is filed under on the Services page, and the Chat conversations. All times are stored in UTC and shown in your browser's time zone.
How a change is applied
- Fill in the form. Switchboard builds a plan: the Caddyfile diff (formatted with
caddy fmtand checked withcaddy adapt), Pi-hole and Cloudflare records, router rules, and reservations. - Review the preview and click Apply.
- Each step checks the live state first (e.g. the Caddyfile hasn't changed since the preview), makes the change, and verifies it: Caddy's running config has the site, Pi-hole answers the name, Cloudflare lists the record, OPNsense lists the rule.
- If any step fails, every completed step is undone in reverse order. Nothing is left half-applied.
Deployment
It runs on the Caddy host (192.168.1.5) as the unprivileged switchboard user, on 127.0.0.1:8095, published
at https://switchboard.thenymans.com (LAN and VPN only). It may write /etc/caddy/Caddyfile and its data
directory /var/lib/switchboard, nothing else. Caddy is reloaded through its local admin API
(caddy reload), so no root access is needed.
Switchboard is a single Rust binary with its templates and assets built in.
./deploy/deploy.sh # from the repo root: builds in a Debian 13 container (podman), installs on root@192.168.1.5
The build runs in rust:1-trixie so the binary links against the host's glibc. The only startup options are
--listen (default 127.0.0.1:8095) and --data-dir (default $SB_DATA_DIR, else ./data).
Back up /var/lib/switchboard as a whole: the database is useless without secret.key next to it.
Caddyfile backups are kept in /var/lib/switchboard/caddy-backups/.
First run
Open the site, create the admin account, then fill in Settings and click Test connections:
- Pi-hole (primary, 192.168.1.3): Settings → Web interface / API → create an app password, and enable
webserver.api.app_sudounder Settings → All settings, or the app password can't change records. Your sync copies records to the secondary; Switchboard only checks the secondary over DNS. - Cloudflare: an API token with Zone → DNS → Edit for each managed domain.
- OPNsense: a dedicated user with only Firewall: NAT: Destination NAT and Services: Dnsmasq DNS/DHCP: Settings, and an API key for it.
Development
cargo test
cargo run -- --data-dir data # http://127.0.0.1:8095 (the session cookie is Secure: use it through Caddy, or localhost)
tests/live_Caddyfile is a snapshot of the real Caddyfile, used to check that edits leave everything else
byte-for-byte unchanged.
The data directory format is the same as the earlier Python version's (SQLite schema, Fernet-encrypted
settings, argon2 password hashes), so an existing /var/lib/switchboard carries over as is. Everyone has to log
in once after the switch, because the session cookie format changed.