Add /receipt/, an admin-gated proxy to the receipt printer on stppi
The receipt_maker repo's `receipt serve` runs on stppi, which reaches the Epson printer over the home LAN, and serves a page for printing a note or an uploaded image. nginx gates /receipt/ on the admin session like /tracker/, strips the prefix, adds the shared X-Receipt-Token and proxies over Tailscale to RECEIPT_WEB_UPSTREAM (the one upstream off this host). When stppi is unreachable, @receipt_offline answers 503 instead of a bare 502. Both variables are defaulted in entrypoint.sh, and the token is quoted in the template, so an unset pair still renders a valid config (/receipt/ then reads "offline"). The admin panel links to the page. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -275,6 +275,18 @@ ACTIVITY_TRACKER_IMAGE_TAG=
|
||||
# IANA timezone that decides where a "day" starts in daily summaries. Blank is UTC.
|
||||
TRACKER_TZ=Europe/London
|
||||
|
||||
# --- Receipt printer (/receipt/) ---------------------------------------------
|
||||
# Not a container here: `receipt serve` (adamf/receipt_maker) runs on stppi,
|
||||
# which reaches the printer over the home LAN, and nginx proxies to it over
|
||||
# Tailscale.
|
||||
# host:port of that server, by Tailscale IP. Blank points nowhere and
|
||||
# /receipt/ answers "offline".
|
||||
RECEIPT_WEB_UPSTREAM=100.107.152.119:8765
|
||||
# Shared secret nginx adds as X-Receipt-Token; the same value as
|
||||
# RECEIPT_WEB_TOKEN in stppi's ~/.config/receipt-web.env. Generate with
|
||||
# `openssl rand -hex 32`. Changing it needs `docker compose up -d nginx`.
|
||||
RECEIPT_WEB_TOKEN=
|
||||
|
||||
# TfL Unified API key (500 req/min); used by the Python hotel finder
|
||||
TFL_APP_KEY=
|
||||
|
||||
|
||||
+2
-1
@@ -68,6 +68,7 @@ backend icecast2 gitea sb sb-pub python | |
|
||||
| certbot | `certbot` | — | — | no |
|
||||
| cloudflared | `cloudflared` | — (fixed IP `172.28.255.250`) | all of nginx, via Cloudflare | no (outbound only) |
|
||||
| dozzle (log viewer) | `dozzle` | 8080 | `/dozzle/` (admin-gated by nginx `auth_request`; reads the Docker socket) | no |
|
||||
| receipt printer (`receipt serve`, adamf/receipt_maker) | — (runs on **stppi**, not in this stack) | 8765 on stppi's Tailscale IP (`RECEIPT_WEB_UPSTREAM`) | `/receipt/`, prefix stripped (admin-gated by nginx `auth_request`; nginx adds `X-Receipt-Token`). The only upstream off this host; 503 "offline" when stppi is down | no |
|
||||
| traffic (tails the payload log) | `traffic` | — (no network) | none; its stdout is what Dozzle shows | no |
|
||||
| autoheal (restarts unhealthy nginx) | `autoheal` | — (no network) | none; reads the Docker socket | no |
|
||||
| garage (S3 object store) | `garage` | 3900 S3, 3902 web, 3903 admin | none directly; `/uploads/` falls back to its web endpoint for files not on the volume | no |
|
||||
@@ -89,7 +90,7 @@ in one step — never change one without the other.**
|
||||
- **Per-request DNS.** Upstreams go through `set $upstream_* ...` variables with
|
||||
`resolver 127.0.0.11`, so names resolve per request. nginx boots fine with a
|
||||
backend down (502s until it appears) instead of refusing to start.
|
||||
- **Admin gate.** `/sb/`, `/jobs/`, `/tracker/`, `/dozzle/`, `/garage/`, `/radio/admin/`, `/uploads/private/` and
|
||||
- **Admin gate.** `/sb/`, `/jobs/`, `/tracker/`, `/receipt/`, `/dozzle/`, `/garage/`, `/radio/admin/`, `/uploads/private/` and
|
||||
Gitea's history views and archives (`…/commit/`, `…/src/commit/`, `…/blame/commit/`, `…/archive/`, `…/compare/`; the
|
||||
branch views stay public) are
|
||||
protected by an `auth_request` subrequest to the backend's `/auth/validate-admin`; a failure
|
||||
|
||||
+8
-1
@@ -87,6 +87,11 @@
|
||||
# SILVERBULLET_PUBLIC_HOST / _PORT
|
||||
# public notes viewer upstream (defaulted below)
|
||||
# PYTHON_HOST / PYTHON_PORT FastAPI upstream (defaulted below)
|
||||
# RECEIPT_WEB_UPSTREAM host:port of the receipt printer server on
|
||||
# stppi, over Tailscale (defaulted below to
|
||||
# a dead port, so /receipt/ reads "offline")
|
||||
# RECEIPT_WEB_TOKEN shared secret nginx adds to /receipt/
|
||||
# requests (defaulted below to empty)
|
||||
# DEV_MODE "true" only via docker-compose.dev.yml
|
||||
# CERT_WATCH_INTERVAL optional, seconds between certificate-watch
|
||||
# polls (default 60). Production only.
|
||||
@@ -107,11 +112,13 @@ export SILVERBULLET_HOST="${SILVERBULLET_HOST:-silverbullet}"
|
||||
export SILVERBULLET_PORT="${SILVERBULLET_PORT:-3000}"
|
||||
export SILVERBULLET_PUBLIC_HOST="${SILVERBULLET_PUBLIC_HOST:-silverbullet-public}"
|
||||
export SILVERBULLET_PUBLIC_PORT="${SILVERBULLET_PUBLIC_PORT:-3000}"
|
||||
export RECEIPT_WEB_UPSTREAM="${RECEIPT_WEB_UPSTREAM:-127.0.0.1:9}"
|
||||
export RECEIPT_WEB_TOKEN="${RECEIPT_WEB_TOKEN:-}"
|
||||
|
||||
# The envsubst allow-list, defined once and reused by both full-config branches
|
||||
# and by every partial, so the lists cannot drift apart. It MUST stay
|
||||
# single-quoted here and be passed as "$ENVSUBST_VARS" (one argument) below.
|
||||
ENVSUBST_VARS='${DOMAIN} ${BACKEND_HOST} ${BACKEND_PORT} ${BACKEND_ENDPOINT} ${ICECAST_HOST} ${ICECAST_PORT} ${GITEA_HOST} ${GITEA_PORT} ${SILVERBULLET_HOST} ${SILVERBULLET_PORT} ${SILVERBULLET_PUBLIC_HOST} ${SILVERBULLET_PUBLIC_PORT} ${PYTHON_HOST} ${PYTHON_PORT}'
|
||||
ENVSUBST_VARS='${DOMAIN} ${BACKEND_HOST} ${BACKEND_PORT} ${BACKEND_ENDPOINT} ${ICECAST_HOST} ${ICECAST_PORT} ${GITEA_HOST} ${GITEA_PORT} ${SILVERBULLET_HOST} ${SILVERBULLET_PORT} ${SILVERBULLET_PUBLIC_HOST} ${SILVERBULLET_PUBLIC_PORT} ${PYTHON_HOST} ${PYTHON_PORT} ${RECEIPT_WEB_UPSTREAM} ${RECEIPT_WEB_TOKEN}'
|
||||
|
||||
# Render the shared proxy route table. Done ONCE, here, ahead of the three-way
|
||||
# decision, rather than inside each branch:
|
||||
|
||||
@@ -88,6 +88,11 @@
|
||||
# nginx_dev_common.conf.template) and the garage-webui admin UI.
|
||||
set $upstream_garage_web http://garage:3902;
|
||||
set $upstream_garage_webui http://garage-webui:3909;
|
||||
# The receipt printer's server is the one upstream OFF this host: it
|
||||
# runs on stppi, which reaches the printer over the home LAN, and is
|
||||
# reached over Tailscale by IP (MagicDNS names don't resolve in this
|
||||
# container).
|
||||
set $upstream_receipt "http://${RECEIPT_WEB_UPSTREAM}";
|
||||
|
||||
# ---- Backend API -----------------------------------------------------
|
||||
# Two patterns repeat through every proxied location below:
|
||||
@@ -538,6 +543,45 @@
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# ---- Receipt printer (/receipt/) ----
|
||||
# The adamf/receipt_maker repo's `receipt serve`, running on stppi
|
||||
# (not in this stack: that machine reaches the printer on the home LAN). A page
|
||||
# for printing a note or an uploaded image, plus its API. Gated like
|
||||
# /tracker/ on the admin session; the prefix IS stripped. The server
|
||||
# trusts nothing without X-Receipt-Token, which only this proxy adds
|
||||
# (proxy_set_header replaces any copy the client sent). The value is
|
||||
# quoted so an unset token still renders a valid config. When stppi
|
||||
# is off or unreachable the connect fails fast and @receipt_offline answers.
|
||||
location = /receipt {
|
||||
return 301 /receipt/;
|
||||
}
|
||||
|
||||
location ^~ /receipt/ {
|
||||
auth_request /internal/auth/admin-validate;
|
||||
error_page 401 403 = @auth_denied;
|
||||
error_page 502 504 = @receipt_offline;
|
||||
limit_req zone=api burst=10 nodelay;
|
||||
# The server caps uploads at 16 MB; this leaves room for the
|
||||
# multipart framing around one.
|
||||
client_max_body_size 17m;
|
||||
rewrite ^/receipt/(.*)$ /$1 break;
|
||||
proxy_pass $upstream_receipt;
|
||||
proxy_connect_timeout 3s;
|
||||
# An image print (connect, dither, send) takes a few seconds; a
|
||||
# dead printer socket gives up after escpos's 60 s timeout.
|
||||
proxy_read_timeout 90s;
|
||||
proxy_set_header X-Receipt-Token "${RECEIPT_WEB_TOKEN}";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
location @receipt_offline {
|
||||
default_type text/plain;
|
||||
return 503 "The receipt printer machine is offline.\n";
|
||||
}
|
||||
|
||||
# Where the tracker used to be. The SPA routes were client-side, so
|
||||
# these only catch bookmarks and typed URLs. The userscript's old
|
||||
# @updateURL lands on the third, which is how installed copies find
|
||||
@@ -552,7 +596,7 @@
|
||||
return 301 /jobs/job-capture.user.js;
|
||||
}
|
||||
|
||||
# ---- Admin gate (/sb/, /jobs/, /tracker/, /dozzle/, /garage/, /radio/admin/, /uploads/private/) ----
|
||||
# ---- Admin gate (/sb/, /jobs/, /tracker/, /receipt/, /dozzle/, /garage/, /radio/admin/, /uploads/private/) ----
|
||||
# (/uploads/private/ is declared in the including template, not here;
|
||||
# it points at the two locations below by name.)
|
||||
# `auth_request` makes nginx fire a subrequest here before serving the
|
||||
|
||||
@@ -107,6 +107,17 @@ async function handleLogout() {
|
||||
>
|
||||
Logs ↗
|
||||
</a>
|
||||
<!-- The receipt printer's page is served from stppi, which reaches
|
||||
the printer on the home LAN; nginx proxies /receipt/ there over
|
||||
Tailscale behind the admin check. -->
|
||||
<a
|
||||
class="admin-nav-link no-underline"
|
||||
href="/receipt/"
|
||||
target="_blank"
|
||||
rel="noopener"
|
||||
>
|
||||
Receipt printer ↗
|
||||
</a>
|
||||
</nav>
|
||||
|
||||
<section class="admin-panel bdr-2 bg-surface">
|
||||
|
||||
Reference in New Issue
Block a user