Split the README into focused docs under docs/
Security / Vulnerability check (push) Successful in 39s
Test / Lint and test (push) Successful in 1m57s

The README had grown to 658 lines. It is now a short overview: what
Überbringer is, a quick start, a table of the docs and the licence.
Each topic it held has a document of its own:

- docs/install.md: install.sh, what it leaves behind, and upgrading.
- docs/docker.md: the image behind a reverse proxy, the env file,
  health checks, and the ntfy state volume and token file.
- docs/configuration.md: loading, environment variables, a table of
  every key in every section, and what is logged. The list of log
  messages becomes a summary of what is logged and reported.
- docs/security.md: the API secret, issuing tokens and their scopes,
  the header-file recipe that keeps tokens off command lines (moved
  from docs/api.md), the reverse proxy, image URLs, and what is never
  logged.
- docs/ntfy.md: the ntfy subscriptions, securing the topics and the
  printer's token, with the token scripts unchanged.
- docs/cli.md: the command line.
- docs/development.md: running from source, the Go version, make
  targets, the gate, generated files, the layout, CI and releases.

CLAUDE.md names the new docs: a config key is now documented in
docs/configuration.md, and the layout and Go version in
docs/development.md. docs/api.md, design.md and the job-store plan
point to the docs that now hold what they referred to in the README.
The release archives also carry the docs on running the daemon.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
57_WolveandClaude Opus 5.5 committed 2026-11-30 22:33:08 -06:00
1 parent 80a65f6083
commit 3d451eb0b7
14 files changed
+934 -678

No files matched your search

+17 -4
View File
@@ -42,10 +42,11 @@ builds:
archives:
- formats: [tar]
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
# Listing files replaces goreleaser's defaults, so the licenses, README,
# API reference, OpenAPI document and changelog are listed too. Each
# must exist; paths are kept, and install.sh takes
# packaging/uberbringer.service from the unpacked archive.
# Listing files replaces goreleaser's defaults, so the licenses, the
# README, the docs on running the daemon, the OpenAPI document and the
# changelog are listed too. Each must exist; paths are kept, and
# install.sh takes packaging/uberbringer.service from the unpacked
# archive.
files:
- src: LICENSE.txt
info: &commit-mtime
@@ -54,8 +55,20 @@ archives:
info: *commit-mtime
- src: README.md
info: *commit-mtime
- src: docs/install.md
info: *commit-mtime
- src: docs/docker.md
info: *commit-mtime
- src: docs/configuration.md
info: *commit-mtime
- src: docs/security.md
info: *commit-mtime
- src: docs/api.md
info: *commit-mtime
- src: docs/ntfy.md
info: *commit-mtime
- src: docs/cli.md
info: *commit-mtime
- src: docs/swagger.json
info: *commit-mtime
- src: CHANGELOG.md
+5
View File
@@ -97,6 +97,11 @@ version may break callers; such changes are listed under **Breaking**.
instead of running off its edge. Its width is worked out as if its data
were bytes, so a code of digits or capitals may shrink before it
strictly has to.
- The README is a short overview. Installing, Docker, the configuration
(now every key), tokens and security, the ntfy subscriptions, the command
line and development each have a document in `docs/`. Release archives
include `docs/install.md`, `docker.md`, `configuration.md`,
`security.md`, `ntfy.md` and `cli.md` beside `docs/api.md`.
## [0.2.0] - 2026-11-30
+11 -6
View File
@@ -15,8 +15,13 @@ root `Dockerfile`.
`scripts/`, and the generated `docs/swagger.json` takes the place of
`api/`.
- `docs/api.md` is the reference for the API: routes, elements, blocks and
error codes. `README.md` covers installing,
configuration, the command line and the package layout.
error codes. `README.md` is a short overview that links to the other docs
under `docs/`: `install.md` (install.sh), `docker.md`, `configuration.md`
(every config key and the logs), `security.md` (the secret, tokens and
their scopes), `ntfy.md` (the ntfy subscriptions), `cli.md` (the command
line) and `development.md` (the Go version, the gate, the package layout,
CI and releases). The release archives carry all of them but
`development.md`; `.goreleaser.yaml` lists each file.
- `docs/swagger.json`, the OpenAPI 3.1 document, is generated
(`go generate ./...`, which runs `tools/genopenapi`) from the route table in
`internal/app/uberbringer/server/routes.go` and the Go types it names: their
@@ -40,7 +45,7 @@ root `Dockerfile`.
`cmd/uberbringer` is a thin main. `internal/app/uberbringer` holds the CLI and
the wiring, and `server/` holds the HTTP API. `internal/pkg/*` holds the
libraries. README § Development lists them. `tools/genopenapi` writes
libraries. `docs/development.md` lists them. `tools/genopenapi` writes
`docs/swagger.json`; the `docs` package embeds it, and `internal/app` hands
it to the server in its config, so the generator never builds the package
that embeds its own output. `tools/genlicenses` writes
@@ -84,14 +89,14 @@ pinned as tools in `go.mod`, so never install them separately.
place of the snapshot, on every branch push. It builds no binaries: only
`release.yml` does, for `v*` tags on main. `security.yml` runs govulncheck
weekly and on pushes to main. A change is done when the gate passes and the
docs (`README.md` or `docs/api.md`) and CHANGELOG.md say what changed.
docs under `docs/` (or `README.md`) and CHANGELOG.md say what changed.
## Go version
- The `go` line in `go.mod` (1.27.4) names the latest Go release, and there
is no `toolchain` line. That release is the minimum and the build Go: CI
tests, scans and releases with it, and a local Go that is older switches to
it. README § Development says the same.
it. `docs/development.md` says the same.
- Bump the go line to each new Go release, patch releases included, since
govulncheck flags standard-library fixes. Bump the tool modules
(golang.org/x/tools, golang.org/x/vuln, honnef.co/go/tools) in the same
@@ -123,7 +128,7 @@ docs (`README.md` or `docs/api.md`) and CHANGELOG.md say what changed.
never echo its secret.
- These changes land in one commit with their docs:
- A config key: `internal/pkg/config` (the default and the validation),
`configs/config.example.toml` and README § Configuration.
`configs/config.example.toml` and `docs/configuration.md`.
- A route, element field, status or error code: its code, its tests,
`docs/api.md` and the regenerated `docs/swagger.json`. A route is an
entry in the table in `server/routes.go`, never a direct
+39 -622
View File
@@ -3,35 +3,21 @@
*Bringer of information.* A small daemon that takes print jobs as JSON over a
REST API and prints them on an EPSON ESC/POS network receipt printer.
- **Queue with job status**: jobs return immediately with an ID and print in
order on a background worker, with retries when the printer is offline.
- **Plain-text input**: send UTF-8 text, including accents, `£ ° ±` and
box-drawing `┌─┐│└┘░▒▓`. It is transcoded to the printer's code page
(CP437 by default), and typographic quotes, dashes and the ellipsis
print as ASCII look-alikes where the code page lacks them.
- **Word wrap**: text wraps at word boundaries for the paper width and
character size, so words are never cut in half.
- **Rich elements**: bold, underline, inverse, sizes 1–8, two fonts,
alignment, QR codes, EAN/UPC/CODE39/CODE128 barcodes, images, raw ESC/POS.
- **Boxes, rules, key-value rows and lists**: single or double CP437
borders with titles, dividers and footers, and bulleted, numbered or
checkbox lists, sized to the paper when the job prints.
- **Modules**: send a few plain fields, such as a note's title, text and
checklist, and get a laid-out receipt back.
- **Notifications**: subscribe to [ntfy](https://ntfy.sh) topics from the
config and print their messages as they arrive, with no other client,
a paper budget that folds floods into one digest, and quiet hours; or
print them through the ntfy client, or post a title, message, priority
and tags from any script. Each prints as a card styled by its priority,
with links as QR codes.
- **Scoped tokens**: integration tokens reach only their modules, and only
tokens issued for it can send raw ESC/POS.
- **Preview**: see the exact lines a job prints, without using paper.
- **Images that print well**: PNG, JPEG, GIF or WebP from a URL or base64,
scaled to the paper and dithered. Image URLs can't reach internal network
addresses unless you allow it.
- **Health endpoint** with live printer status: paper low or out, cover open,
errors.
- Jobs return at once with an ID and print in order on a background worker,
with retries while the printer is offline.
- UTF-8 text is transcoded to the printer's code page and wraps at word
boundaries for the paper width.
- Text styles and sizes, QR codes, barcodes, images and raw ESC/POS.
- Boxes, rules, key-value rows and lists, laid out for the paper when the
job prints.
- Modules turn a few plain fields, such as a note or a notification, into a
laid-out receipt.
- It can subscribe to [ntfy](https://ntfy.sh) topics and print their
messages, with a paper budget and quiet hours.
- Tokens can be limited to modules, and only tokens issued for it can send
raw ESC/POS.
- A preview shows the lines a job prints without using paper, and
`/healthz` reports the printer's status.
> [!NOTE]
> **Pre-refactor code: no AI was used.** The original Überbringer (v0.1.x),
@@ -40,606 +26,37 @@ REST API and prints them on an EPSON ESC/POS network receipt printer.
> from January 2025, was written without any AI. That commit shows the
> code as it was before the 0.2 refactor.
## Contents
- [Quick start](#quick-start)
- [API](#api), in [docs/api.md](docs/api.md)
- [Configuration](#configuration)
- [ntfy subscriptions](#ntfy-subscriptions)
- [Command line](#command-line)
- [Development](#development)
- [License](#license)
## Quick start
### Debian/Ubuntu server with Caddy and TLS
On a fresh Debian or Ubuntu host whose domain points at it, this installs
the latest release as a systemd service behind Caddy, with HTTPS:
```sh
sudo ./install.sh printer.example.com you@example.com 192.168.1.245
```
- Sets up a fresh Debian or Ubuntu host: the latest release, a systemd
service, and [Caddy](https://caddyserver.com) for HTTPS with an automatic
certificate. It does not upgrade a host set up by the 0.1 script.
- Arguments: the server's domain, whose DNS must point at the server, with
ports 80 and 443 free and reachable; the email address for the certificate
account; and the printer's IP address or host name, without a port.
- A given release, v0.2.0 or later:
`sudo UBERBRINGER_VERSION=v0.2.0 ./install.sh <domain> <acme-email> <printer-address>`.
- The config is `/etc/uberbringer/config.toml`. The first API token is in
`/etc/uberbringer/initial-token`: copy it to your client, then delete the
file. Issue more with
`uberbringer token --config /etc/uberbringer/config.toml --subject <client>`.
- Re-running the script upgrades the install and keeps the config. After
editing the config, run `systemctl restart uberbringer`; after changing
`webserver.body_limit`, `bind_ip` or `port`, re-run the script instead.
- The service keeps [ntfy subscriptions](#ntfy-subscriptions)' state in
`/var/lib/uberbringer`, the only directory it may write to. A config the
script creates sets `ntfy.state_dir` to it; add that line to an older
config before adding a subscription.
- Change the systemd unit with `systemctl edit uberbringer`.
- The install log is `/var/log/uberbringer-install.log`.
### Docker
```sh
docker build -t uberbringer .
docker run -d -p 127.0.0.1:8080:8080 -v "$PWD/config.toml:/etc/uberbringer/config.toml:ro" uberbringer
```
The image is a microservice for running behind your own reverse proxy. It
contains no proxy and no TLS: it serves plain HTTP on port 8080, and the proxy
terminates HTTPS. The examples publish the port on the host's loopback
address only, for a proxy on the host; a proxy in another container reaches
it over a shared Docker network instead, with no `-p` at all. In the mounted
`config.toml`:
- Set `bind_ip = "0.0.0.0"` in `[webserver]`.
- Set `trusted_proxies` to the address the proxy's requests come from: its
container network (e.g. `["172.18.0.0/16"]`), or for a proxy on the host,
the Docker bridge's gateway (usually `172.17.0.1`). Have the proxy set
`X-Real-IP` to the client's address. Otherwise every request appears to
come from the proxy, and all clients share one rate limit.
- Let the proxy pass request bodies up to `webserver.body_limit` (4 MiB by
default).
The settings can come from environment variables instead (see
[Configuration](#configuration)). To run without a config file, set
`UBERBRINGER_CONFIG` empty and put the variables in an env file that only you
can read (`chmod 600 uberbringer.env`), so the secret stays off the command
line:
```text
UBERBRINGER_CONFIG=
UBERBRINGER_WEBSERVER_BIND_IP=0.0.0.0
UBERBRINGER_WEBSERVER_TRUSTED_PROXIES=172.18.0.0/16
UBERBRINGER_API_SECRET=<the output of uberbringer secret>
UBERBRINGER_PRINTER_ADDRESS=192.168.1.245
```
```sh
docker run -d -p 127.0.0.1:8080:8080 --env-file uberbringer.env uberbringer
```
Publish port 8080 only to the proxy, never directly to the internet. For
container health checks, use `GET /` to see whether the daemon is up.
`/healthz` answers `503` while the printer is unreachable, so it suits
alerting better than restarting the container.
[ntfy subscriptions](#ntfy-subscriptions) keep their state in
`/var/lib/uberbringer`, which the image sets as `ntfy.state_dir`. Mount a
volume there: without one the state lives in the container, and a new
container, after a pull or an upgrade, forgets what was printed and what
was held.
```sh
docker run -d -p 127.0.0.1:8080:8080 -v "$PWD/config.toml:/etc/uberbringer/config.toml:ro" \
-v uberbringer-state:/var/lib/uberbringer uberbringer
```
Subscriptions are set in `config.toml` only, so a container with one needs
the file. The image runs as user and group `10001`, so give a token file
to that ID, mode `600`, and mount it read-only next to the config:
```sh
sudo chown 10001:10001 ntfy.token && sudo chmod 600 ntfy.token
docker run ... -v "$PWD/ntfy.token:/etc/uberbringer/ntfy.token:ro" uberbringer
```
### From source
```sh
cp configs/config.example.toml config.toml
go run ./cmd/uberbringer secret # paste into api.secret
$EDITOR config.toml # set printer.address
go run ./cmd/uberbringer token # prints a bearer token
make run
```
## API
[docs/api.md](docs/api.md) is the API reference: the routes, the print
elements and blocks, the modules, and the error codes.
[docs/swagger.json](docs/swagger.json) is the OpenAPI 3.1 document,
generated from the route table; the daemon serves it at `GET /openapi.json`.
## Configuration
Copy [configs/config.example.toml](configs/config.example.toml) to
`config.toml`. Only `api.secret` (at least 32 bytes) and `printer.address` are
required; every other setting has a default, which the example shows. Configs
from 0.1 still load, because their keys are unchanged, but `printer.address`
is now required. Unknown keys are reported as errors, so a typo can't
silently fall back to a default, and so are two keys that differ only in
case. A duration is a string such as `"5s"`; a bare number is refused.
Every key can also be set by an environment variable named
`UBERBRINGER_<SECTION>_<KEY>`, such as `UBERBRINGER_PRINTER_ADDRESS` for
`printer.address`, and a variable wins over the file. The exception is
`[[ntfy.subscriptions]]`, a list of tables, which only the file sets.
- Values are written without quotes: decimal digits for a number, `true` or
`false` for a flag, `5s` for a duration. Lists take comma-separated values,
e.g. `UBERBRINGER_WEBSERVER_TRUSTED_PROXIES=127.0.0.1,::1`; an empty item,
from a doubled or trailing comma, is an error. In the file, a number, flag
or list may also be written as such a string. A table of your own entries,
`ntfy.markers`, takes `name=value` entries separated by commas, e.g.
`UBERBRINGER_NTFY_MARKERS=backup=[B],nas01=`; a value cannot hold a comma.
- An empty variable counts as unset, and one that holds only spaces is an
error. Variables that name no key are ignored, but when the configuration
fails to load, the error names them, since they are likely misspelt.
- `--config` names the file, and defaults to `config.toml` or to
`UBERBRINGER_CONFIG` when that is set. `--config ""`, or an empty
`UBERBRINGER_CONFIG`, reads no file, so the settings come from the
environment and the defaults alone.
Settings worth knowing:
- `printer.model` sets the print width and characters per line:
| Model | Printers | Width | Font A / B columns |
|-------|----------|-------|--------------------|
| `tm-t88` (default) | TM-T88IV, V, VI, VII | 512 dots (180 dpi) | 42 / 56 |
| `tm-m50` | TM-m50, TM-m50II | 512 dots (180 dpi) | 42 / 56 |
| `tm-t20` | TM-T20, II, III | 576 dots (203 dpi) | 48 / 64 |
| `generic-80mm` | other 80 mm, 203 dpi | 576 dots | 48 / 64 |
| `generic-58mm` | 58 mm paper, 203 dpi | 384 dots | 32 / 42 |
For 58 mm paper on a 180-dpi printer (TM-T88VII, TM-m50II), use a
`tm-t88` or `tm-m50` model with `paper_width = 360` (30 Font A columns).
If words break at the right edge (for example `seve` on one line and `ral`
on the next), the model is wider than the printer. `paper_width` (dots) and
`columns` (Font A characters per line) override the model.
- `printer.codepage`: `cp437` (default), `cp850`, `cp858` (has €) or
`cp1252`.
- `printer.box_line_spacing` (default `0`): the line spacing, in motion
units (ESC 3, 0–255), used while a box prints. Lines of box drawing leave
small gaps in the vertical borders at the printer's default spacing; a
value checked on paper closes them. `0` keeps the default, which was
checked on a TM-T88IV with `examples/blocks.json` and looks fine.
- `printer.cut_feed` (default `3`): blank lines, 0–255, fed before every
cut, the one after each copy and `cut` elements alike, so that the last
printed line does not sit right at the cut. They show as blank lines
before the cut in previews and count toward `format.max_lines`.
- `format.max_lines` (default `2000`): a job that would print more lines,
all copies counted, fails instead of printing. It is a backstop against
runaway text; `/api/v1/preview` answers such a job with `422`.
- `format.timezone` (default `Local`) and `format.time_layout` (default
`02 Jan 15:04`): how [modules](docs/api.md#modules) print times, such as
a note's stamp. The zone is an IANA name such as `Europe/London`, `UTC`,
or `Local` for the host's zone; the binary carries the zone database, so
names load on hosts and containers without one. The layout is Go's
notation, in which `02 Jan 2006 15:04:05` stands for the parts of a date,
e.g. `2006-01-02 15:04`. A layout that shows no part of a date is an
error.
- `[ntfy.format]` shapes the [notification cards](docs/api.md#notification-cards)
of the `notify` and `ntfy` modules and of the
[ntfy subscriptions](#ntfy-subscriptions), and their
[digests](docs/api.md#digests):
| Key | Default | Values |
|-----|---------|--------|
| `style` | `auto` | `auto` picks the form from the priority; `box` prints priorities 1 and 2 in a box too; `compact` prints every priority without a box |
| `max_lines` | `40` | 1–400 lines of the message, as written, before `... N more lines` |
| `qr` | `all` | Which links print as QR codes: `all`, `first` (the rest as text) or `none` |
| `images` | `true` | `false` names attached images on a `File` row instead of printing them |
| `markdown` | `true` | `false` prints markdown messages as written |
| `updates` | `print` | What a [subscription](#ntfy-subscriptions) does with a message that replaces one it printed: `print` marks its title `(updated)`, `skip` leaves it out |
- `[ntfy.markers]` adds or changes the [markers](docs/api.md#markers)
printed for tags, at most 16 characters each, and `""` hides a tag:
`backup = "[B]"`, `nas01 = ""`.
- `ntfy.state_dir` (no default): the directory the
[ntfy subscriptions](#ntfy-subscriptions) keep their state in, one
`ntfy-<name>.json` file each, readable by the daemon's user only.
Required with a subscription. `install.sh` and the Docker image set it to
`/var/lib/uberbringer`.
- `[[ntfy.subscriptions]]`: see [ntfy subscriptions](#ntfy-subscriptions).
- `webserver.trusted_proxies` / `proxy_header`: the real client IP for
per-client rate limits comes from the `X-Real-IP` header set by the reverse
proxy (Caddy, as `install.sh` configures it) on `127.0.0.1`.
- `sentry.dsn`: error reporting. When neither the file nor
`UBERBRINGER_SENTRY_DSN` sets it, it falls back to the `SENTRY_DSN`
environment variable, then to a DSN built into release binaries (from the
`SENTRY_DSN` CI secret). Request bodies and the `Authorization` header are never sent
to Sentry.
- `log.level` (`debug`, `info`, `warn`, `error`) and `log.format` (`text` or
`json`) control what is logged:
- Each request is logged once, as `request`: at INFO, or at WARN when the
status is 5xx. Only the path is logged, never the query string, the body
or the token.
- An unexpected failure adds one ERROR `request failed` line, with `err` and
`request_id`, and one Sentry event.
- A recovered panic adds one ERROR `panic` line, with `panic` and `stack`,
and one Sentry event.
- The worker logs each job with its `job_id`, its `source` (`print` or
`module:<name>`) and its `ref`, the ID of the request that sent it, never
with what it prints. A job that fails after its retries is logged as
ERROR `job failed` and is reported to Sentry.
- A module that builds an invalid receipt (`422` `module_failed`) is
logged as ERROR `module built an invalid receipt`, with the `module` and
the number of `problems` but not the problems themselves, and is
reported to Sentry once.
- A notification card that cannot be laid out prints as a plain receipt,
and is logged as ERROR `module printed its fallback receipt`, with the
`module`, the cause in `err` and, after a panic, its `stack`, and is
reported to Sentry once. Neither quotes the notification.
- Each [ntfy subscription](#ntfy-subscriptions) logs with its
`subscription` name, and with the message's `ntfy_id` where there is
one, never with what a message says or its topic: `ntfy connected` at
INFO; `ntfy connection lost` and `ntfy credentials refused` at WARN,
with the cause in `err` and the wait in `retry_in`; `ntfy receipt
queued` at INFO, with the `ref` (the message's ID, or `digest`) and the
`job_id`; `ntfy message waits to print` at WARN while the queue is
full. A card or digest that falls back to a plain receipt is logged at
ERROR as `ntfy card printed its fallback receipt` and reported to
Sentry once, and so is a state file that cannot be written
(`ntfy state not saved`). At DEBUG, each message's fate: held,
dropped in quiet hours, repeated or skipped.
- Refusals are never logged at ERROR and never go to Sentry. Refusals are
4xx answers other than `module_failed`, the `queue_full` and
`shutting_down` 503s, and 503s from `/healthz`.
## ntfy subscriptions
The daemon can subscribe to [ntfy](https://ntfy.sh) topics itself and print
each message as a [notification card](docs/api.md#notification-cards), so
the phone's ntfy app, or anything else that publishes, is the only client.
Each `[[ntfy.subscriptions]]` table in `config.toml` is one connection to
one server, for one or more topics:
```toml
[ntfy]
state_dir = "/var/lib/uberbringer"
[[ntfy.subscriptions]]
name = "home"
server = "https://ntfy.example.com"
topics = ["alerts", "backups"]
token_file = "/etc/uberbringer/ntfy.token"
[ntfy.subscriptions.quiet]
start = "22:00"
end = "07:00"
```
| Key | Default | Meaning |
|-----|---------|---------|
| `name` | required | 1–32 lowercase letters, digits, `-` and `_`. It names the subscription in `/healthz`, in logs, in its state file and in its jobs' source, `ntfy:<name>`; each must be unique |
| `server` | required | The server's base URL. It must be `https` unless `allow_insecure = true`. A redirect is never followed: the connection fails, and `last_error` says to set the address it points to |
| `allow_insecure` | `false` | `true` allows a plain `http` server, whose credentials and messages cross the network unencrypted |
| `topics` | required | 1–150 topic names, each 1–64 letters, digits, `-` and `_` |
| `token`, `token_file`, or `user` with `password_file` | none | The credentials, at most one kind. A file holds the secret alone; spaces and line breaks around it are ignored, and a file the group or others can read is accepted with a warning. Without any, the subscription reads as anyone may |
| `min_priority` | `1` | The lowest priority that prints; the server filters by it |
| `max_backlog` | `"1h"` | How far back messages missed during a restart or an outage still print, at most `12h`, the time ntfy keeps them by default |
| `rate_limit`, `rate_window` | `5`, `"10m"` | The paper budget: at most this many receipts in any window. Messages over it are held, and print together on one [digest](docs/api.md#digests) once the budget has room |
| `bypass_priority` | `5` | Outside quiet hours, messages of this priority and above print at once, outside the budget. During quiet hours, `quiet.min_priority` decides first |
| `keepalive` | `"45s"` | The server's keepalive interval, 5s–1h. A connection silent for twice this plus 15 s is opened again |
Quiet hours are off unless the subscription has a
`[ntfy.subscriptions.quiet]` table, which goes right after its
`[[ntfy.subscriptions]]` table:
| Key | Default | Meaning |
|-----|---------|---------|
| `start`, `end` | `"22:00"`, `"07:00"` | The window, as HH:MM. An end before the start is on the next day; the times hold on the nights the clocks change |
| `days` | every day | The days a window starts on: `mon`, `tue`, `wed`, `thu`, `fri`, `sat`, `sun`. With `["fri"]`, Friday's window runs into Saturday morning |
| `timezone` | `format.timezone` | The zone of `start` and `end` |
| `min_priority` | `5` | The lowest priority that prints during the window |
| `action` | `"digest"` | `digest` holds the other messages and prints them on one `Overnight` digest when the window ends; `drop` leaves them out |
How a subscription behaves:
- **First start.** With no state yet, it prints only messages published
from then on, also after a reconnect soon after.
- **Restarts and outages.** It keeps a cursor, the newest server time it
has dealt with, and when it reconnects or starts again it asks for the
messages since then, two minutes earlier to catch late ones. Of those,
it prints only the ones no older than `max_backlog`, measured by ntfy's
own clock as the stream tells it (the time of its first, `open` event,
or else the answer's `Date`), never by this host's, and leaves the
older ones out as they arrive; they stay out, even after a restart with
a longer backlog. It keeps the
IDs of the messages a replay could send again, at least the last 512
and at most 20,000, so a message the server sends again, after a
reconnect or as ntfy's own repeat, never prints twice, even after a
flood; past 20,000, the next replay starts after the IDs it forgot.
- **Failures.** A dropped connection is opened again after 5, 10, 20, 30,
60 and then every 120 seconds, each ± 20%, from 5 seconds again once a
connection has lasted two minutes. A `429` waits as long as its
`Retry-After` says. Refused credentials (`401` or `403`) are checked at
startup, and while the server refuses them the subscription is
`unauthorized` in `/healthz` and tries every five minutes. Printing goes
on meanwhile.
- **A full print queue** pauses the subscription: it stops reading the
stream, offers the message again after 1 second, then after twice as
long each time, up to 30 seconds, and moves its cursor only once the
message is queued. A digest that cannot be queued waits the same way.
- **Updates.** ntfy lets a publisher replace a notification with a later
message of the same sequence (`sequence_id`). When a message's sequence
printed before, on a card or a digest row (not only counted on a
digest), and is among the last 512 it remembers, its card says
`(updated)`, or with `ntfy.format.updates =
"skip"` it is left out. The first message of a sequence prints plain,
even when its publisher named the sequence.
- **State.** The cursor, the IDs, the budget and the held messages are in
`<state_dir>/ntfy-<name>.json`, written through a temporary file and a
rename, so a crash leaves the old file or the new one. It is written
within a second of a message being printed, held or left out, at most
every 10 minutes when only keepalives have moved the cursor, and at
shutdown. A damaged file is ignored with a warning, and
the subscription starts as if new. Held messages survive a restart.
- **Jobs.** Each card and digest is an ordinary job with the source
`ntfy:<name>`. Like any job, one that is still waiting when the daemon
shuts down is marked failed, and is not printed after the restart.
`/healthz` lists each subscription's state, counts and last error; see
[Health](docs/api.md#health).
> [!WARNING]
> Whoever can publish to a subscribed topic prints on your printer, and
> with priority 5 past the paper budget. On the public `ntfy.sh`, anyone
> who knows a topic's name can publish to it: reserve the topic so that
> others may not write to it, or at the very least use a long random name.
> Your own ntfy server lets everyone publish too, unless access control is
> on: set `auth-file`, set `auth-default-access` to `deny-all` (or
> `read-only`), since it defaults to `read-write`, and give write access
> only to your publishers.
On your own ntfy server, with in its `server.yml`
```yaml
auth-file: /var/lib/ntfy/user.db
auth-default-access: deny-all
```
give the printer a user of its own that may only read its topics, and
each publisher one that may only write to them:
```sh
sudo ntfy user add printer # asks for a password
sudo ntfy access printer alerts read-only # once for each topic
sudo ntfy user add phone
sudo ntfy access phone alerts write-only
```
Then create the printer's access token and write it straight into a file
only the daemon can read, so that it never shows on the screen, on a
command line or in your shell history. `ntfy token add` prints the token
on standard error up to ntfy 2.13 and on standard output since 2.14, so
the script takes both, and keeps the token in a shell variable, which
`printf`, a shell builtin, hands to `install` on its standard input.
`install` runs under `umask 077`, so the file is readable by its owner
alone from the moment it is created, also with BusyBox's `install`,
which sets the mode only after writing; it then gets mode 600 and, on the
printer's host, the daemon's user. With ntfy on the same host:
```sh
out=$(sudo ntfy token add printer 2>&1)
token=$(printf '%s\n' "$out" | grep -o 'tk_[A-Za-z0-9]*')
if [ -z "$token" ]; then
printf 'ntfy made no token:\n%s\n' "$out" | sed 's/tk_[A-Za-z0-9]*/tk_.../g' >&2
elif printf '%s\n' "$token" | (umask 077; sudo install -m 600 -o uberbringer -g uberbringer /dev/stdin /etc/uberbringer/ntfy.token); then
unset token
else
cat >&2 <<'EOF'
The token was made but not stored. Fix the cause, then run:
printf '%s\n' "$token" | (umask 077; sudo install -m 600 -o uberbringer -g uberbringer /dev/stdin /etc/uberbringer/ntfy.token) && unset token
EOF
fi
unset out
```
With ntfy on another host, write the token there into a file of your own,
`ntfy.token` in the current directory:
```sh
out=$(sudo ntfy token add printer 2>&1)
token=$(printf '%s\n' "$out" | grep -o 'tk_[A-Za-z0-9]*')
if [ -z "$token" ]; then
printf 'ntfy made no token:\n%s\n' "$out" | sed 's/tk_[A-Za-z0-9]*/tk_.../g' >&2
elif printf '%s\n' "$token" | (umask 077; install -m 600 /dev/stdin ntfy.token); then
unset token
else
cat >&2 <<'EOF'
The token was made but not stored. Fix the cause, then run:
printf '%s\n' "$token" | (umask 077; install -m 600 /dev/stdin ntfy.token) && unset token
EOF
fi
unset out
```
Copy it to the printer's host, place it there with
`sudo install -m 600 -o uberbringer -g uberbringer ntfy.token /etc/uberbringer/ntfy.token`,
and delete both copies of `ntfy.token`.
When no token comes out, the script shows what ntfy said, with any token
in it masked, such as that the user does not exist. When a token was
made but could not be stored, for example because `/etc/uberbringer` is
missing, nothing is written, and the token stays in `$token` until the
printed line stores it: never look it up with `ntfy token list`, which
prints every token in full, and removing one with `ntfy token remove`
needs the token on its command line. If the ntfy web app lets users sign
in (`enable-login: true`, which is off by default), you can also create
the token there under Account and paste it in with `sudoedit`, after
`sudo install -m 600 -o uberbringer -g uberbringer /dev/null /etc/uberbringer/ntfy.token`
has made the empty file.
## Command line
```text
uberbringer [--config config.toml] run the daemon (default command)
uberbringer secret print a new random API secret
uberbringer token [--subject s] [--ttl 720h] print a signed bearer token
[--modules ntfy,notify] [--raw] ... limited to modules, or able to print raw ESC/POS
uberbringer preview [file.json|-] show the lines a job would print
uberbringer preview --module note [file|-] show the receipt a module builds
uberbringer config get <key> print one setting, e.g. webserver.port
uberbringer version print the version
uberbringer licenses print the licenses of the third-party software
```
`token` signs a token with `api.secret`. Without flags, it may use every
route but cannot print jobs with `raw` elements:
- `--raw` lets it print them. Give it only to clients that send ESC/POS
bytes of their own.
- `--modules ntfy,notify` limits it to those modules' print and preview
routes, job status and the module list. Give integrations, such as the
[ntfy client](docs/api.md#printing-from-the-ntfy-client), one of these.
The names must be modules the daemon has, and `--raw` cannot be added.
`config get` prints a setting as the daemon would use it, from the file,
`UBERBRINGER_*` variables and the defaults, and fails when the configuration
does not load. Durations print as `15s`, lists comma-separated, and tables
as sorted `name=value` entries. It never prints `api.secret`.
Every command that reads the config takes `--config` (`-c`); see
[Configuration](#configuration) for its default and for running without a
file.
`preview` reads a job from the file, or from standard input with `-` or no
argument, and lays it out for the printer in the config, as
`/api/v1/preview` does. It prints nothing and fetches no images. On a
terminal it shows bold, underlined and inverted text as such; warnings go
to standard error. With `--module`, the input is that module's payload, as
`/api/v1/print/:module` takes it, built at the time now. It reads the same
config as the daemon, so `api.secret` and `printer.address` must be set even
though neither is used.
The daemon shuts down gracefully on SIGINT/SIGTERM. A receipt that is already
printing is finished, and jobs still waiting are marked failed.
## Development
The Go version is the `go 1.27.4` line in `go.mod`, the latest Go release:
- It is the minimum for building, and builds with `GOTOOLCHAIN=local` need at
least that. With the default `GOTOOLCHAIN=auto`, an older local Go
downloads go1.27.4 by itself.
- CI tests, scans and releases with exactly that release; the workflows read
it from `go.mod`. There is no separate `toolchain` line.
- To move to a new Go release, change the go line
(`go mod edit -go=1.27.5`). In the same commit, bump the tool modules
golang.org/x/tools, golang.org/x/vuln and honnef.co/go/tools.
```sh
make check # the CI gate, below
make build # bin/uberbringer
make fmt # gofmt + goimports
make vuln # govulncheck
make generate # regenerate docs/swagger.json and the license notices (go generate ./...)
make snapshot # release archives in dist/; publishes nothing
```
`make check` runs the same steps as `.gitea/workflows/test.yml`, in the same
order:
1. `fmt-check`: gofmt and goimports.
2. `tidy-check`: `go mod tidy -diff`.
3. `go vet`.
4. staticcheck.
5. `generate-check`: `go generate ./...` must leave `docs/swagger.json`,
`THIRD-PARTY-LICENSES.md` and its embedded copy unchanged.
6. `go test -race -timeout 5m`.
7. `release-check`: `goreleaser check`, which validates the release config
without building.
It needs goreleaser installed. govulncheck is not part of it; run
`make vuln`. `make snapshot` builds the release archives locally; run it
after changing `.goreleaser.yaml` or `packaging/`. `make` builds report the
version without the leading `v`, e.g. `0.1.2-3-gabc1234`, as release
binaries do.
`docs/swagger.json` is generated by `tools/genopenapi` from the route table
in `internal/app/uberbringer/server/routes.go`, which the server also
registers its routes from. The schemas come from the Go types the routes
name: their `json` and `jsonschema` tags and their doc comments. Never edit
the file by hand: change the route table or the types, run
`go generate ./...`, and commit the document with the change.
`THIRD-PARTY-LICENSES.md` is generated by `tools/genlicenses`. It holds the
license and notice files of the Go distribution and of every module that
`./cmd/uberbringer` links on the release platforms. A module's files come
from its root and from the directories of its linked packages, which cover
code it vendors under licenses of their own. Modules that only the tools and
tests use are left out. The generator writes the same text to
`internal/app/uberbringer/licenses_embed.md`, which the binary embeds and
`uberbringer licenses` prints. After adding, bumping or dropping a
dependency, run `go generate ./...` and commit both files with `go.mod`.
The generator fails on a module that ships no license file, or whose
license it does not recognize; teach `licenseMarkers` in
`tools/genlicenses/notices.go` its wording once the license is acceptable.
The linters are pinned as Go tools in `go.mod`, so `go tool staticcheck`,
`go tool govulncheck` and `go tool goimports` need no separate install. The
module path is `uberbringer`, so packages import as
`uberbringer/internal/...`. Build from a clone of the repository.
```text
cmd/uberbringer/ main: build info, signals, exit code
internal/app/uberbringer/ CLI commands and wiring
server/ Fiber HTTP API, auth, health
internal/pkg/config/ Config from TOML and UBERBRINGER_* variables (Viper): defaults, validation
internal/pkg/escpos/ ESC/POS command builder, code pages, barcodes, QR, raster, status, interpreter
internal/pkg/receipt/ Job format, validation, text folding, word wrap, blocks, rendering, preview
internal/pkg/modules/ Modules that build jobs from plain payloads: note, notify, ntfy; notification cards, markdown
internal/pkg/ntfy/ ntfy's message types; the subscriber: stream, cursor, repeats, paper budget, quiet hours
internal/pkg/raster/ Image decoding, scaling and dithering
internal/pkg/safehttp/ SSRF-guarded image fetching
internal/pkg/printer/ TCP printer client (port 9100) and status queries
internal/pkg/printqueue/ Job queue, worker and status history
configs/ Example configuration
examples/ Example jobs, such as the block calibration receipt
packaging/ systemd unit
tools/genlicenses/ Generates THIRD-PARTY-LICENSES.md and its embedded copy from the linked modules
tools/genopenapi/ Generates docs/swagger.json from the route table
docs/ API reference, OpenAPI document, design notes and feature plans
```
[docs/design.md](docs/design.md) explains why the daemon is shaped as it is.
[CHANGELOG.md](CHANGELOG.md) lists the changes in each release.
### CI and releases
CI runs on the Gitea runner from `.gitea/workflows/`. The repository has no
`.github/` directory.
- `test.yml` runs the `make check` gate on every branch push. It lints,
checks that the generated files are up to date, tests and validates the
release config, but builds no binaries, and it does not run on pull
requests or tags. Binaries are built only by `release.yml`.
- `security.yml` runs govulncheck on pushes to main and every Monday at
06:00 UTC. Scheduled runs use main's copy of the workflow.
- `release.yml` builds and publishes a release with goreleaser 2.20.3 when a
`v*` tag is pushed.
- It runs only for tags whose commit is on main, and refuses any other tag.
- `vX.Y.Z-rc.N` tags are published as prereleases, so they never become the
latest release that `install.sh` installs.
- Each archive holds the binary, `LICENSE.txt`, `THIRD-PARTY-LICENSES.md`,
`README.md`, `docs/api.md`, `docs/swagger.json`, `CHANGELOG.md`,
`configs/config.example.toml` and `packaging/uberbringer.service`.
- The release notes link to `CHANGELOG.md` at the tag.
The arguments are the domain, the email address for the certificate and
the printer's address. [docs/install.md](docs/install.md) covers the rest,
and [docs/docker.md](docs/docker.md) covers the Docker image.
## Documentation
| Document | Covers |
|----------|--------|
| [docs/install.md](docs/install.md) | Installing on Debian or Ubuntu with `install.sh`, and upgrading |
| [docs/docker.md](docs/docker.md) | Running the Docker image behind your own reverse proxy |
| [docs/configuration.md](docs/configuration.md) | The config file, environment variables, every setting and the logs |
| [docs/security.md](docs/security.md) | The API secret, tokens and their scopes, and what never reaches the logs |
| [docs/api.md](docs/api.md) | The HTTP API: routes, print elements, blocks, modules and error codes |
| [docs/ntfy.md](docs/ntfy.md) | Printing ntfy topics: subscriptions, digests, quiet hours and securing ntfy |
| [docs/cli.md](docs/cli.md) | The command line |
| [docs/development.md](docs/development.md) | Building and testing, the package layout, CI and releases |
| [docs/design.md](docs/design.md) | Why the daemon is shaped as it is |
| [CHANGELOG.md](CHANGELOG.md) | The changes in each release |
[docs/swagger.json](docs/swagger.json) is the OpenAPI 3.1 document of the
API, generated from the route table; the daemon serves it at
`GET /openapi.json`.
## License
+14 -22
View File
@@ -1,8 +1,8 @@
# Überbringer API
The HTTP API, the print elements and blocks, the modules, and the error
codes. [README.md](../README.md) covers installing, configuring and running
the daemon.
codes. [README.md](../README.md) links to the docs on installing,
configuring and running the daemon.
## Contents
@@ -31,17 +31,9 @@ accepted, because they leak into proxy logs.
Keep a token off command lines too, where other users of the machine can
read it. The examples here send the header from a file only you can read,
which curl 7.55 and later take as `-H @file`. On a host set up by
`install.sh`, whose config is `/etc/uberbringer/config.toml`, make it like
this. The token passes through a shell variable, never a command's
arguments or the terminal, and the file is written only if the token
command succeeded; for a client on another machine, copy the file there.
```sh
token=$(sudo uberbringer token --config /etc/uberbringer/config.toml --subject my-script) &&
(umask 077; printf 'Authorization: Bearer %s\n' "$token" > ~/.uberbringer-auth)
unset token
```
which curl 7.55 and later take as `-H @file`;
[security.md](security.md#keeping-tokens-off-command-lines) shows how to
make it.
What a token may do is set when it is issued:
@@ -133,7 +125,7 @@ curl -H @"$HOME/.uberbringer-auth" https://printer.example.com/api/v1/jobs/job_0
`status` is `queued`, `printing`, `done` or `failed`. A failed job includes an
`error` field. `source` says where the job came from: `print` for
`/api/v1/print`, `module:<name>` for a [module](#modules) route, or
`ntfy:<name>` for an [ntfy subscription](../README.md#ntfy-subscriptions)
`ntfy:<name>` for an [ntfy subscription](ntfy.md)
in the config. The last `queue.history` finished jobs are kept.
### Preview a receipt
@@ -163,7 +155,7 @@ curl -X POST https://printer.example.com/api/v1/preview \
- The preview is read back from the bytes the job renders to, so it shows
what the printer receives: wrapping, folded characters, `?` for missing
ones, the blank lines [`printer.cut_feed`](../README.md#configuration)
ones, the blank lines [`printer.cut_feed`](configuration.md#printer)
feeds before a cut (3 by default) and the final cut.
- Centred and right-aligned text is indented as the printer places it,
counted in Font A columns. Text at a larger size shows each character
@@ -192,7 +184,7 @@ With `Accept: application/json` the answer carries the styles too. For
|-------|---------|
| `columns` | Font A characters per line |
| `codepage` | The code page text is printed in |
| `line_count` | Lines the receipt prints, all copies counted: text lines, fed lines, and one for each QR code, barcode and image. [`format.max_lines`](../README.md#configuration) limits it |
| `line_count` | Lines the receipt prints, all copies counted: text lines, fed lines, and one for each QR code, barcode and image. [`format.max_lines`](configuration.md#format) limits it |
| `lines[].kind` | `text`, `qr`, `barcode`, `image`, `raw` or `cut` |
| `lines[].text` | The line as it prints, or the placeholder |
| `lines[].runs` | Styled parts of `text`, in characters from `from` up to `to`: `bold`, `underline` (1 or 2), `invert`, `font` (`b`), and `width` and `height` when scaled. Plain Font A text at size 1 has no run |
@@ -217,7 +209,7 @@ when the worker renders it, before anything is sent; its `error` reads
A printer that accepts connections but does not answer status requests is
reported as `"status": "unknown"` with HTTP `200`.
With [ntfy subscriptions](../README.md#ntfy-subscriptions) configured, an
With [ntfy subscriptions](ntfy.md) configured, an
`ntfy` array lists each one, in the order of the config. The status code
still depends on the printer alone, so a subscription that cannot connect
never turns `/healthz` to `503`:
@@ -627,7 +619,7 @@ the daemon.
A box with the text, then, when there are items, an empty line and a
checklist. The time it was built, in `format.timezone` and
`format.time_layout` ([configuration](../README.md#configuration)), goes in
`format.time_layout` ([configuration](configuration.md#format)), goes in
the bottom border. The request above prints:
```text
@@ -764,7 +756,7 @@ attachment expires:
- A message that updates an earlier one, with the same `sequence_id`,
prints as it is, like any other: one message cannot tell whether it is
the first of its sequence, since a publisher may choose the sequence ID.
An [ntfy subscription](../README.md#ntfy-subscriptions), which remembers
An [ntfy subscription](ntfy.md), which remembers
what it printed, marks such a message `(updated)`.
- A message over the [limits](#notify) of `notify` is not refused; what is
over them is cut or left out. A title, topic, tag, label or file name is
@@ -781,7 +773,7 @@ header file that only the user the client runs as can read. Both setups
below keep the token off command lines and out of shell history.
For your own client, with `~/.config/ntfy/client.yml`, make the file as
yourself, as [above](#api):
yourself, as [security.md](security.md#keeping-tokens-off-command-lines) shows:
```sh
mkdir -p ~/.config/ntfy
@@ -869,7 +861,7 @@ Prune finished
41 snapshots kept, 3 removed.
```
The settings in [`[ntfy.format]`](../README.md#configuration) shape every
The settings in [`[ntfy.format]`](configuration.md#ntfy) shape every
card: `style = "box"` gives priorities 1 and 2 the single box too, and
`style = "compact"` prints every priority without a box, with `URGENT` or
`HIGH` in front of the topic. The title is the payload's, or else the
@@ -888,7 +880,7 @@ bold, the message, then the topic and time. That is a bug: it is logged at
ERROR as `module printed its fallback receipt` and reported to Sentry, and
`uberbringer preview --module` prints a warning.
A card an [ntfy subscription](../README.md#ntfy-subscriptions) prints for
A card an [ntfy subscription](ntfy.md) prints for
a message that replaces one it printed before, of the same `sequence_id`,
has `(updated)` after its title, unless `ntfy.format.updates = "skip"`
leaves such messages out.
+66
View File
@@ -0,0 +1,66 @@
# Command line
```text
uberbringer [--config config.toml] run the daemon (default command)
uberbringer secret print a new random API secret
uberbringer token [--subject s] [--ttl 720h] print a signed bearer token
[--modules ntfy,notify] [--raw] ... limited to modules, or able to print raw ESC/POS
uberbringer preview [file.json|-] show the lines a job would print
uberbringer preview --module note [file|-] show the receipt a module builds
uberbringer config get <key> print one setting, e.g. webserver.port
uberbringer version print the version
uberbringer licenses print the licenses of the third-party software
```
Every command that reads the config takes `--config` (`-c`);
[configuration.md](configuration.md#loading) gives its default and how to
run without a file.
## The daemon
`uberbringer` with no command runs the daemon. It shuts down gracefully on
SIGINT/SIGTERM: a receipt that is already printing is finished, and jobs
still waiting are marked failed.
## secret
`secret` prints a new random secret for `api.secret`.
## token
`token` prints a bearer token signed with `api.secret`. `--subject` names
the client (default `uberbringer`), and `--ttl` sets how long the token
lasts; without it, the token never expires. Without the scope flags, a
token may use every route but cannot print jobs with `raw` elements:
- `--raw` lets it print them.
- `--modules ntfy,notify` limits it to those modules' print and preview
routes, job status and the module list. The names must be modules the
daemon has, and `--raw` cannot be added.
[security.md](security.md#issuing-tokens) says which token to give which
client and how to keep it off command lines.
## preview
`preview` reads a job from the file, or from standard input with `-` or no
argument, and lays it out for the printer in the config, as
`/api/v1/preview` does. It prints nothing and fetches no images. On a
terminal it shows bold, underlined and inverted text as such; warnings go
to standard error. With `--module`, the input is that module's payload, as
`/api/v1/print/:module` takes it, built at the time now. It reads the same
config as the daemon, so `api.secret` and `printer.address` must be set even
though neither is used.
## config get
`config get` prints a setting as the daemon would use it, from the file,
`UBERBRINGER_*` variables and the defaults, and fails when the configuration
does not load. Durations print as `15s`, lists comma-separated, and tables
as sorted `name=value` entries. It never prints `api.secret`.
## version and licenses
`version` prints the version. `licenses` prints the license and notice
texts of the third-party software in the binary, the same text as
[THIRD-PARTY-LICENSES.md](../THIRD-PARTY-LICENSES.md).
+231
View File
@@ -0,0 +1,231 @@
# Configuration
The daemon reads its settings from a TOML file and from environment
variables. [configs/config.example.toml](../configs/config.example.toml)
shows every setting with its default: copy it to `config.toml` to start.
`install.sh` and the Docker image keep the config in
`/etc/uberbringer/config.toml`.
## Contents
- [Loading](#loading)
- [Environment variables](#environment-variables)
- [Settings](#settings): [webserver](#webserver), [api](#api),
[printer](#printer), [format](#format), [ntfy](#ntfy),
[ntfy subscriptions](#ntfy-subscriptions), [queue](#queue),
[images](#images), [sentry](#sentry), [log](#log)
- [Logs](#logs)
## Loading
- Only `api.secret` and `printer.address` are required. Every other setting
has a default.
- Unknown keys are errors, so a typo can't silently fall back to a default,
and so are two keys that differ only in case.
- A duration is a string such as `"5s"` or `"1m30s"`; a bare number is
refused.
- `--config` names the file, and defaults to `config.toml` or to
`UBERBRINGER_CONFIG` when that is set. `--config ""`, or an empty
`UBERBRINGER_CONFIG`, reads no file, so the settings come from the
environment and the defaults alone.
- [`uberbringer config get <key>`](cli.md#config-get) prints a setting as
the daemon would use it.
## Environment variables
Every key can also be set by an environment variable named
`UBERBRINGER_<SECTION>_<KEY>`, such as `UBERBRINGER_PRINTER_ADDRESS` for
`printer.address`, and a variable wins over the file. The exception is the
[ntfy subscriptions](#ntfy-subscriptions), a list of tables, which only the
file sets.
- Values are written without quotes: decimal digits for a number, `true` or
`false` for a flag, `5s` for a duration. Lists take comma-separated values,
e.g. `UBERBRINGER_WEBSERVER_TRUSTED_PROXIES=127.0.0.1,::1`; an empty item,
from a doubled or trailing comma, is an error. In the file, a number, flag
or list may also be written as such a string.
- A table of your own entries, `ntfy.markers`, takes `name=value` entries
separated by commas, e.g. `UBERBRINGER_NTFY_MARKERS=backup=[B],nas01=`; a
value cannot hold a comma.
- An empty variable counts as unset, and one that holds only spaces is an
error. Variables that name no key are ignored, but when the configuration
fails to load, the error names them, since they are likely misspelt.
## Settings
### webserver
| Key | Default | Meaning |
|-----|---------|---------|
| `bind_ip` | `"127.0.0.1"` | The IP address the HTTP server listens on; `"0.0.0.0"` in [Docker](docker.md) |
| `port` | `8080` | The port it listens on, 1–65535 |
| `rate_limit`, `rate_window` | `60`, `"1m"` | Each client may make this many `/api` requests per window; more get `429` `rate_limited` |
| `trusted_proxies` | `["127.0.0.1", "::1"]` | IP addresses or CIDR ranges of reverse proxies. A request from one of them is counted, for the rate limit, against the client address in `proxy_header` |
| `proxy_header` | `"X-Real-IP"` | The header the proxy sets to the client's address. `install.sh` sets Caddy up to send it |
| `body_limit` | `4194304` | The largest request body, in bytes (4 MiB); a larger one gets `413` `body_too_large`. Raise it for large base64 images, and raise the proxy's limit with it |
| `read_timeout`, `write_timeout`, `idle_timeout` | `"15s"`, `"15s"`, `"60s"` | The HTTP server's timeouts |
`install.sh` copies `bind_ip`, `port` and `body_limit` into Caddy's config,
so on a host it set up, re-run it after changing them
([install.md](install.md#upgrading-and-changing-the-config)).
### api
| Key | Default | Meaning |
|-----|---------|---------|
| `secret` | none | Required. The key that signs bearer tokens (HS256), at least 32 bytes. `uberbringer secret` makes one; see [security.md](security.md#the-api-secret) |
### printer
| Key | Default | Meaning |
|-----|---------|---------|
| `address` | none | Required. The printer's IP address or host name |
| `port` | `9100` | The printer's TCP port, 1–65535 |
| `model` | `"tm-t88"` | The printer's profile, which sets the print width and characters per line; see below |
| `codepage` | `"cp437"` | The code page text is transcoded to: `cp437`, `cp850`, `cp858` (has €) or `cp1252` |
| `paper_width` | the model's | The printable width in dots; overrides the model |
| `columns` | from the width | Font A characters per line, for word wrap; overrides the model |
| `box_line_spacing` | `0` | The line spacing, in motion units (ESC 3, 0–255), used while a box prints. Lines of box drawing leave small gaps in the vertical borders at the printer's default spacing; a value checked on paper closes them. `0` keeps the default |
| `cut_feed` | `3` | Blank lines, 0–255, fed before every cut, the one after each copy and `cut` elements alike, so that the last printed line does not sit right at the cut. They show in previews and count toward `format.max_lines` |
| `dial_timeout`, `write_timeout` | `"5s"`, `"30s"` | How long connecting to the printer, and sending it a job, may take |
| `retries` | `3` | How many times a failed send is retried before the job fails |
| `retry_delay` | `"1s"` | The wait before the first retry; it doubles after each |
The models:
| Model | Printers | Width | Font A / B columns |
|-------|----------|-------|--------------------|
| `tm-t88` (default) | TM-T88IV, V, VI, VII | 512 dots (180 dpi) | 42 / 56 |
| `tm-m50` | TM-m50, TM-m50II | 512 dots (180 dpi) | 42 / 56 |
| `tm-t20` | TM-T20, II, III | 576 dots (203 dpi) | 48 / 64 |
| `generic-80mm` | other 80 mm, 203 dpi | 576 dots | 48 / 64 |
| `generic-58mm` | 58 mm paper, 203 dpi | 384 dots | 32 / 42 |
For 58 mm paper on a 180-dpi printer (TM-T88VII, TM-m50II), use a `tm-t88`
or `tm-m50` model with `paper_width = 360` (30 Font A columns).
If words break at the right edge (for example `seve` on one line and `ral`
on the next), the model is wider than the printer.
### format
| Key | Default | Meaning |
|-----|---------|---------|
| `max_lines` | `2000` | A job that would print more lines, all copies counted, fails instead of printing, and `/api/v1/preview` answers it with `422`. It is a backstop against runaway text |
| `timezone` | `"Local"` | The zone of the times [modules](api.md#modules) print, such as a note's stamp: an IANA name such as `Europe/London` or `UTC`, or `Local` for the host's zone. The binary carries the zone database, so names load on hosts and containers without one |
| `time_layout` | `"02 Jan 15:04"` | How those times print, in Go's notation, in which `02 Jan 2006 15:04:05` stands for the parts of a date, e.g. `2006-01-02 15:04`. A layout that shows no part of a date is an error |
### ntfy
These settings shape the [notification cards](api.md#notification-cards)
of the `notify` and `ntfy` modules and of the [ntfy subscriptions](ntfy.md),
and their [digests](api.md#digests).
| Key | Default | Meaning |
|-----|---------|---------|
| `state_dir` | none | The directory the ntfy subscriptions keep their state in, one `ntfy-<name>.json` file each, readable by the daemon's user only. Required with a subscription. `install.sh` and the Docker image set it to `/var/lib/uberbringer` |
`[ntfy.format]`:
| Key | Default | Meaning |
|-----|---------|---------|
| `style` | `"auto"` | `auto` picks the form from the priority; `box` prints priorities 1 and 2 in a box too; `compact` prints every priority without a box |
| `max_lines` | `40` | 1–400 lines of the message, as written, before `... N more lines` |
| `qr` | `"all"` | Which links print as QR codes: `all`, `first` (the rest as text) or `none` |
| `images` | `true` | `false` names attached images on a `File` row instead of printing them |
| `markdown` | `true` | `false` prints markdown messages as written |
| `updates` | `"print"` | What a subscription does with a message that replaces one it printed: `print` marks its title `(updated)`, `skip` leaves it out |
`[ntfy.markers]` adds or changes the [markers](api.md#markers) printed for
tags, at most 16 characters each, and `""` hides a tag: `backup = "[B]"`,
`nas01 = ""`.
### ntfy subscriptions
Each `[[ntfy.subscriptions]]` table is one connection to one ntfy server,
for one or more topics. They are set in the file only.
[ntfy.md](ntfy.md) shows an example and how a subscription behaves.
| Key | Default | Meaning |
|-----|---------|---------|
| `name` | required | 1–32 lowercase letters, digits, `-` and `_`. It names the subscription in `/healthz`, in logs, in its state file and in its jobs' source, `ntfy:<name>`; each must be unique |
| `server` | required | The server's base URL. It must be `https` unless `allow_insecure = true`. A redirect is never followed: the connection fails, and `last_error` says to set the address it points to |
| `allow_insecure` | `false` | `true` allows a plain `http` server, whose credentials and messages cross the network unencrypted |
| `topics` | required | 1–150 topic names, each 1–64 letters, digits, `-` and `_` |
| `token`, `token_file`, or `user` with `password_file` | none | The credentials, at most one kind. A file holds the secret alone; spaces and line breaks around it are ignored, and a file the group or others can read is accepted with a warning. Without any, the subscription reads as anyone may |
| `min_priority` | `1` | The lowest priority that prints; the server filters by it |
| `max_backlog` | `"1h"` | How far back messages missed during a restart or an outage still print, at most `12h`, the time ntfy keeps them by default |
| `rate_limit`, `rate_window` | `5`, `"10m"` | The paper budget: at most this many receipts (1–1000) in any window. Messages over it are held, and print together on one [digest](api.md#digests) once the budget has room |
| `bypass_priority` | `5` | Outside quiet hours, messages of this priority and above print at once, outside the budget. During quiet hours, `quiet.min_priority` decides first |
| `keepalive` | `"45s"` | The server's keepalive interval, 5s–1h. A connection silent for twice this plus 15 s is opened again |
Quiet hours are off unless the subscription has a
`[ntfy.subscriptions.quiet]` table, which goes right after its
`[[ntfy.subscriptions]]` table:
| Key | Default | Meaning |
|-----|---------|---------|
| `start`, `end` | `"22:00"`, `"07:00"` | The window, as HH:MM. An end before the start is on the next day; the times hold on the nights the clocks change |
| `days` | every day | The days a window starts on: `mon`, `tue`, `wed`, `thu`, `fri`, `sat`, `sun`. With `["fri"]`, Friday's window runs into Saturday morning |
| `timezone` | `format.timezone` | The zone of `start` and `end` |
| `min_priority` | `5` | The lowest priority that prints during the window |
| `action` | `"digest"` | `digest` holds the other messages and prints them on one `Overnight` digest when the window ends; `drop` leaves them out |
### queue
| Key | Default | Meaning |
|-----|---------|---------|
| `size` | `100` | Jobs that may wait to print; more get `503` `queue_full` |
| `history` | `1000` | Finished jobs whose status is kept; an older job's ID answers `404` `job_not_found` |
### images
| Key | Default | Meaning |
|-----|---------|---------|
| `timeout` | `"10s"` | How long fetching an image may take |
| `max_bytes` | `10485760` | The largest image download, in bytes (10 MiB) |
| `max_pixels` | `25000000` | The largest decoded image, in pixels, against decompression bombs |
| `max_height` | `4000` | The tallest printed image, in dots after scaling, about 50 cm |
| `allow_private_networks` | `false` | `true` lets image URLs reach loopback, private and link-local addresses |
| `allowed_hosts` | `[]` | When set, the only hosts images may come from; those hosts may be on your LAN |
An image that breaks a limit fails its job, unless the image is `optional`
([image](api.md#image)).
### sentry
| Key | Default | Meaning |
|-----|---------|---------|
| `dsn` | none | Where errors are reported. When neither the file nor `UBERBRINGER_SENTRY_DSN` sets it, it falls back to the `SENTRY_DSN` environment variable, then to a DSN built into release binaries |
| `environment` | `"production"` | The environment events are reported under |
| `debug` | `false` | `true` has the Sentry client log what it does |
Request bodies and the `Authorization` header are never sent to Sentry.
### log
| Key | Default | Meaning |
|-----|---------|---------|
| `level` | `"info"` | `debug`, `info`, `warn` or `error` |
| `format` | `"text"` | `text` or `json` |
## Logs
- Each request is logged once, as `request`: at INFO, or at WARN when the
status is 5xx. Only the path is logged, never the query string, the body
or the token.
- The worker logs each job with its `job_id`, its `source` (`print`,
`module:<name>` or `ntfy:<name>`) and its `ref`, the ID of the request or
ntfy message that sent it, never with what it prints.
- Each [ntfy subscription](ntfy.md) logs with its `subscription` name,
never with what a message says or its topic. It logs at WARN when its
connection is lost, when its credentials are refused and while the queue
is full, and at DEBUG what happens to each message.
- An unexpected failure is logged at ERROR and reported to Sentry once: a
request that fails or panics, a job that fails after its retries
(`job failed`), a module that builds an invalid receipt, a notification
card or digest that prints its plain fallback, and an ntfy state file
that cannot be written.
- Refusals are never logged at ERROR and never go to Sentry. They are the
4xx answers other than `module_failed`, the `queue_full` and
`shutting_down` 503s, and 503s from `/healthz`.
+3 -3
View File
@@ -2,8 +2,8 @@
Status: version 0.2.0, checked on paper on the TM-T88IV. Next is the work
under Planned next, each feature in its own plan in `docs/plans/`. This
page records why the daemon is shaped as it is. README.md and docs/api.md
describe how to use it.
page records why the daemon is shaped as it is. README.md and the other docs
in docs/ describe how to use it.
## Why
@@ -486,7 +486,7 @@ not yet written is described here until it is.
bandwidth budget is spent.
- Resuming by `since=<message ID>` is checked in ntfy's source first,
including what ntfy does once that ID has expired from its cache.
- The README advises, for ntfy behind Caddy, `behind-proxy: true` in
- docs/ntfy.md advises, for ntfy behind Caddy, `behind-proxy: true` in
ntfy, and a `stream_close_delay` so that Caddy's reloads do not drop
streams.
- Also covered: an ntfy-compatible publish endpoint.
+126
View File
@@ -0,0 +1,126 @@
# Development
## Contents
- [Running from source](#running-from-source)
- [Go version](#go-version)
- [Make targets](#make-targets)
- [Generated files](#generated-files)
- [Package layout](#package-layout)
- [CI and releases](#ci-and-releases)
## Running from source
Build from a clone of the repository.
```sh
cp configs/config.example.toml config.toml
go run ./cmd/uberbringer secret # paste into api.secret
$EDITOR config.toml # set printer.address
go run ./cmd/uberbringer token # prints a bearer token
make run
```
## Go version
The Go version is the `go 1.27.4` line in `go.mod`, the latest Go release:
- It is the minimum for building, and builds with `GOTOOLCHAIN=local` need at
least that. With the default `GOTOOLCHAIN=auto`, an older local Go
downloads go1.27.4 by itself.
- CI tests, scans and releases with exactly that release; the workflows read
it from `go.mod`. There is no separate `toolchain` line.
- To move to a new Go release, change the go line
(`go mod edit -go=1.27.5`). In the same commit, bump the tool modules
golang.org/x/tools, golang.org/x/vuln and honnef.co/go/tools.
## Make targets
```sh
make check # the CI gate, below
make build # bin/uberbringer
make fmt # gofmt + goimports
make vuln # govulncheck
make generate # regenerate docs/swagger.json and the license notices (go generate ./...)
make snapshot # release archives in dist/; publishes nothing
```
`make check` runs the same steps as `.gitea/workflows/test.yml`, in the same
order: gofmt and goimports, `go mod tidy -diff`, `go vet`, staticcheck, a
check that `go generate ./...` leaves the generated files unchanged,
`go test -race -timeout 5m`, and `goreleaser check`, which validates the
release config without building. It needs goreleaser installed.
govulncheck is not part of it; run `make vuln`. Run `make snapshot` after
changing `.goreleaser.yaml` or `packaging/`. `make` builds report the
version without the leading `v`, e.g. `0.1.2-3-gabc1234`, as release
binaries do.
The linters are pinned as Go tools in `go.mod`, so `go tool staticcheck`,
`go tool govulncheck` and `go tool goimports` need no separate install.
## Generated files
Never edit these by hand. Change their sources, run `go generate ./...`,
and commit the result with the change.
- `docs/swagger.json` is generated by `tools/genopenapi` from the route
table in `internal/app/uberbringer/server/routes.go`, which the server
also registers its routes from. The schemas come from the Go types the
routes name: their `json` and `jsonschema` tags and their doc comments.
- `THIRD-PARTY-LICENSES.md` and its copy
`internal/app/uberbringer/licenses_embed.md`, which the binary embeds and
`uberbringer licenses` prints, are generated by `tools/genlicenses`. They
hold the license and notice files of the Go distribution and of every
module that `./cmd/uberbringer` links on the release platforms; modules
that only the tools and tests use are left out. Regenerate them after
adding, bumping or dropping a dependency. The generator fails on a module
that ships no license file, or whose license it does not recognize; teach
`licenseMarkers` in `tools/genlicenses/notices.go` its wording once the
license is acceptable.
## Package layout
The module path is `uberbringer`, so packages import as
`uberbringer/internal/...`.
```text
cmd/uberbringer/ main: build info, signals, exit code
internal/app/uberbringer/ CLI commands and wiring
server/ Fiber HTTP API, auth, health
internal/pkg/config/ Config from TOML and UBERBRINGER_* variables (Viper): defaults, validation
internal/pkg/escpos/ ESC/POS command builder, code pages, barcodes, QR, raster, status, interpreter
internal/pkg/receipt/ Job format, validation, text folding, word wrap, blocks, rendering, preview
internal/pkg/modules/ Modules that build jobs from plain payloads: note, notify, ntfy; notification cards, markdown
internal/pkg/ntfy/ ntfy's message types; the subscriber: stream, cursor, repeats, paper budget, quiet hours
internal/pkg/raster/ Image decoding, scaling and dithering
internal/pkg/safehttp/ SSRF-guarded image fetching
internal/pkg/printer/ TCP printer client (port 9100) and status queries
internal/pkg/printqueue/ Job queue, worker and status history
configs/ Example configuration
examples/ Example jobs, such as the block calibration receipt
packaging/ systemd unit
tools/genlicenses/ Generates THIRD-PARTY-LICENSES.md and its embedded copy from the linked modules
tools/genopenapi/ Generates docs/swagger.json from the route table
docs/ User docs, API reference, OpenAPI document, design notes and feature plans
```
## CI and releases
CI runs on the Gitea runner from `.gitea/workflows/`. The repository has no
`.github/` directory.
- `test.yml` runs the `make check` gate on every branch push. It builds no
binaries, and it does not run on pull requests or tags.
- `security.yml` runs govulncheck on pushes to main and every Monday at
06:00 UTC. Scheduled runs use main's copy of the workflow.
- `release.yml` builds and publishes a release with goreleaser 2.20.3 when a
`v*` tag is pushed.
- It runs only for tags whose commit is on main, and refuses any other tag.
- `vX.Y.Z-rc.N` tags are published as prereleases, so they never become the
latest release that `install.sh` installs.
- Each archive holds the binary, `LICENSE.txt`, `THIRD-PARTY-LICENSES.md`,
`README.md`, `CHANGELOG.md`, `configs/config.example.toml`,
`packaging/uberbringer.service`, `docs/swagger.json` and, from `docs/`,
`install.md`, `docker.md`, `configuration.md`, `security.md`, `api.md`,
`ntfy.md` and `cli.md`.
- The release notes link to `CHANGELOG.md` at the tag.
+73
View File
@@ -0,0 +1,73 @@
# Running in Docker
The image built from the root `Dockerfile` is a microservice for running
behind your own reverse proxy. It contains no proxy and no TLS: it serves
plain HTTP on port 8080, and the proxy terminates HTTPS.
```sh
docker build -t uberbringer .
docker run -d -p 127.0.0.1:8080:8080 -v "$PWD/config.toml:/etc/uberbringer/config.toml:ro" uberbringer
```
The examples publish the port on the host's loopback address only, for a
proxy on the host; a proxy in another container reaches it over a shared
Docker network instead, with no `-p` at all. Publish port 8080 only to the
proxy, never directly to the internet.
## The config
In the mounted `config.toml` ([configuration.md](configuration.md)):
- Set `bind_ip = "0.0.0.0"` in `[webserver]`.
- Set `trusted_proxies` to the address the proxy's requests come from: its
container network (e.g. `["172.18.0.0/16"]`), or for a proxy on the host,
the Docker bridge's gateway (usually `172.17.0.1`). Have the proxy set
`X-Real-IP` to the client's address. Otherwise every request appears to
come from the proxy, and all clients share one rate limit.
- Let the proxy pass request bodies up to `webserver.body_limit` (4 MiB by
default).
The settings can come from
[environment variables](configuration.md#environment-variables) instead. To
run without a config file, set `UBERBRINGER_CONFIG` empty and put the
variables in an env file that only you can read
(`chmod 600 uberbringer.env`), so the secret stays off the command line:
```text
UBERBRINGER_CONFIG=
UBERBRINGER_WEBSERVER_BIND_IP=0.0.0.0
UBERBRINGER_WEBSERVER_TRUSTED_PROXIES=172.18.0.0/16
UBERBRINGER_API_SECRET=<the output of uberbringer secret>
UBERBRINGER_PRINTER_ADDRESS=192.168.1.245
```
```sh
docker run -d -p 127.0.0.1:8080:8080 --env-file uberbringer.env uberbringer
```
## Health checks
For container health checks, use `GET /` to see whether the daemon is up.
`/healthz` answers `503` while the printer is unreachable, so it suits
alerting better than restarting the container.
## ntfy subscriptions
[ntfy subscriptions](ntfy.md) keep their state in `/var/lib/uberbringer`,
which the image sets as `ntfy.state_dir`. Mount a volume there: without one
the state lives in the container, and a new container, after a pull or an
upgrade, forgets what was printed and what was held.
```sh
docker run -d -p 127.0.0.1:8080:8080 -v "$PWD/config.toml:/etc/uberbringer/config.toml:ro" \
-v uberbringer-state:/var/lib/uberbringer uberbringer
```
Subscriptions are set in `config.toml` only, so a container with one needs
the file. The image runs as user and group `10001`, so give a token file
to that ID, mode `600`, and mount it read-only next to the config:
```sh
sudo chown 10001:10001 ntfy.token && sudo chmod 600 ntfy.token
docker run ... -v "$PWD/ntfy.token:/etc/uberbringer/ntfy.token:ro" uberbringer
```
+45
View File
@@ -0,0 +1,45 @@
# Installing with install.sh
`install.sh` sets up a fresh Debian or Ubuntu host: the latest release, a
systemd service, and [Caddy](https://caddyserver.com) in front of it for
HTTPS with an automatic certificate. It does not upgrade a host set up by
the 0.1 script. For the Docker image, see [docker.md](docker.md); to run
from source, see [development.md](development.md#running-from-source).
```sh
sudo ./install.sh printer.example.com you@example.com 192.168.1.245
```
The arguments are:
1. The server's domain. Its DNS must point at the server, with ports 80 and
443 free and reachable.
2. The email address for the certificate account.
3. The printer's IP address or host name, without a port.
To install a given release, v0.2.0 or later:
```sh
sudo UBERBRINGER_VERSION=v0.2.0 ./install.sh <domain> <acme-email> <printer-address>
```
## After installing
- The config is `/etc/uberbringer/config.toml`.
[configuration.md](configuration.md) describes every setting.
- The first API token is in `/etc/uberbringer/initial-token`: copy it to
your client, then delete the file. [security.md](security.md#issuing-tokens)
shows how to issue more.
- The service may write only to `/var/lib/uberbringer`, where the
[ntfy subscriptions](ntfy.md) keep their state. A config the script
creates sets `ntfy.state_dir` to it; add that line to an older config
before adding a subscription.
- Change the systemd unit with `systemctl edit uberbringer`.
- The install log is `/var/log/uberbringer-install.log`.
## Upgrading and changing the config
Re-running the script upgrades the install and keeps the config. After
editing the config, run `systemctl restart uberbringer`. After changing
`webserver.body_limit`, `bind_ip` or `port`, re-run the script instead: it
copies them into Caddy's config.
+191
View File
@@ -0,0 +1,191 @@
# ntfy subscriptions
The daemon can subscribe to [ntfy](https://ntfy.sh) topics itself and print
each message as a [notification card](api.md#notification-cards), so the
phone's ntfy app, or anything else that publishes, is the only client. To
have the ntfy command line client post messages instead, see
[Printing from the ntfy client](api.md#printing-from-the-ntfy-client).
## Contents
- [Setting one up](#setting-one-up)
- [How a subscription behaves](#how-a-subscription-behaves)
- [Securing the topics](#securing-the-topics)
- [The printer's access token](#the-printers-access-token)
## Setting one up
Each `[[ntfy.subscriptions]]` table in `config.toml` is one connection to
one server, for one or more topics. Subscriptions are set in the file only,
not by environment variables. [configuration.md](configuration.md#ntfy-subscriptions)
lists every key, and [ntfy](configuration.md#ntfy) the settings that shape
the cards.
```toml
[ntfy]
state_dir = "/var/lib/uberbringer"
[[ntfy.subscriptions]]
name = "home"
server = "https://ntfy.example.com"
topics = ["alerts", "backups"]
token_file = "/etc/uberbringer/ntfy.token"
[ntfy.subscriptions.quiet]
start = "22:00"
end = "07:00"
```
`install.sh` and the Docker image set `state_dir` already. In Docker, mount
a volume for the state and the token file next to the config, as
[docker.md](docker.md#ntfy-subscriptions) shows.
`/healthz` lists each subscription's state, counts and last error; see
[Health](api.md#health).
## How a subscription behaves
- **First start.** With no state yet, it prints only messages published
from then on, also after a reconnect soon after.
- **Restarts and outages.** It keeps a cursor, the newest server time it
has dealt with, and when it reconnects or starts again it asks for the
messages since then, two minutes earlier to catch late ones. Of those,
it prints only the ones no older than `max_backlog`, measured by ntfy's
own clock as the stream tells it (the time of its first, `open` event,
or else the answer's `Date`), never by this host's, and leaves the
older ones out as they arrive; they stay out, even after a restart with
a longer backlog. It keeps the IDs of the messages a replay could send
again, at least the last 512 and at most 20,000, so a message the server
sends again, after a reconnect or as ntfy's own repeat, never prints
twice, even after a flood; past 20,000, the next replay starts after the
IDs it forgot.
- **Failures.** A dropped connection is opened again after 5, 10, 20, 30,
60 and then every 120 seconds, each ± 20%, from 5 seconds again once a
connection has lasted two minutes. A `429` waits as long as its
`Retry-After` says. Refused credentials (`401` or `403`) are checked at
startup, and while the server refuses them the subscription is
`unauthorized` in `/healthz` and tries every five minutes. Printing goes
on meanwhile.
- **A full print queue** pauses the subscription: it stops reading the
stream, offers the message again after 1 second, then after twice as
long each time, up to 30 seconds, and moves its cursor only once the
message is queued. A digest that cannot be queued waits the same way.
- **The paper budget.** At most `rate_limit` receipts print in any
`rate_window`, digests included. Messages over it are held and print
together on one [digest](api.md#digests) once the budget has room.
Outside quiet hours, messages of `bypass_priority` and above print at
once.
- **Quiet hours.** During the window, only `quiet.min_priority` and above
print. The rest are held for an `Overnight` digest when the window ends,
or left out with `action = "drop"`.
- **Updates.** ntfy lets a publisher replace a notification with a later
message of the same sequence (`sequence_id`). When a message's sequence
printed before, on a card or a digest row (not only counted on a
digest), and is among the last 512 it remembers, its card says
`(updated)`, or with `ntfy.format.updates = "skip"` it is left out. The
first message of a sequence prints plain, even when its publisher named
the sequence.
- **State.** The cursor, the IDs, the budget and the held messages are in
`<state_dir>/ntfy-<name>.json`, written through a temporary file and a
rename, so a crash leaves the old file or the new one. It is written
within a second of a message being printed, held or left out, at most
every 10 minutes when only keepalives have moved the cursor, and at
shutdown. A damaged file is ignored with a warning, and the subscription
starts as if new. Held messages survive a restart.
- **Jobs.** Each card and digest is an ordinary job with the source
`ntfy:<name>`. Like any job, one that is still waiting when the daemon
shuts down is marked failed, and is not printed after the restart.
## Securing the topics
> [!WARNING]
> Whoever can publish to a subscribed topic prints on your printer, and
> with priority 5 past the paper budget. On the public `ntfy.sh`, anyone
> who knows a topic's name can publish to it: reserve the topic so that
> others may not write to it, or at the very least use a long random name.
> Your own ntfy server lets everyone publish too, unless access control is
> on: set `auth-file`, set `auth-default-access` to `deny-all` (or
> `read-only`), since it defaults to `read-write`, and give write access
> only to your publishers.
On your own ntfy server, with in its `server.yml`
```yaml
auth-file: /var/lib/ntfy/user.db
auth-default-access: deny-all
```
give the printer a user of its own that may only read its topics, and
each publisher one that may only write to them:
```sh
sudo ntfy user add printer # asks for a password
sudo ntfy access printer alerts read-only # once for each topic
sudo ntfy user add phone
sudo ntfy access phone alerts write-only
```
## The printer's access token
Create the printer's access token and write it straight into a file only
the daemon can read, so that it never shows on the screen, on a command
line or in your shell history. The scripts below take both of
`ntfy token add`'s output streams, since ntfy 2.13 and earlier print the
token on standard error, and hand the token to `install` on its standard
input. `umask 077` keeps the file private from the moment it is created,
also with BusyBox's `install`, which sets the mode only after writing.
With ntfy on the same host:
```sh
out=$(sudo ntfy token add printer 2>&1)
token=$(printf '%s\n' "$out" | grep -o 'tk_[A-Za-z0-9]*')
if [ -z "$token" ]; then
printf 'ntfy made no token:\n%s\n' "$out" | sed 's/tk_[A-Za-z0-9]*/tk_.../g' >&2
elif printf '%s\n' "$token" | (umask 077; sudo install -m 600 -o uberbringer -g uberbringer /dev/stdin /etc/uberbringer/ntfy.token); then
unset token
else
cat >&2 <<'EOF'
The token was made but not stored. Fix the cause, then run:
printf '%s\n' "$token" | (umask 077; sudo install -m 600 -o uberbringer -g uberbringer /dev/stdin /etc/uberbringer/ntfy.token) && unset token
EOF
fi
unset out
```
With ntfy on another host, write the token there into a file of your own,
`ntfy.token` in the current directory:
```sh
out=$(sudo ntfy token add printer 2>&1)
token=$(printf '%s\n' "$out" | grep -o 'tk_[A-Za-z0-9]*')
if [ -z "$token" ]; then
printf 'ntfy made no token:\n%s\n' "$out" | sed 's/tk_[A-Za-z0-9]*/tk_.../g' >&2
elif printf '%s\n' "$token" | (umask 077; install -m 600 /dev/stdin ntfy.token); then
unset token
else
cat >&2 <<'EOF'
The token was made but not stored. Fix the cause, then run:
printf '%s\n' "$token" | (umask 077; install -m 600 /dev/stdin ntfy.token) && unset token
EOF
fi
unset out
```
Copy it to the printer's host, place it there with
`sudo install -m 600 -o uberbringer -g uberbringer ntfy.token /etc/uberbringer/ntfy.token`,
and delete both copies of `ntfy.token`.
When no token comes out, the script shows what ntfy said, with any token
in it masked, such as that the user does not exist. When a token was made
but could not be stored, for example because `/etc/uberbringer` is
missing, nothing is written, and the token stays in `$token` until the
printed line stores it. Never look it up with `ntfy token list`, which
prints every token in full; removing one with `ntfy token remove` needs
the token on its command line.
If the ntfy web app lets users sign in (`enable-login: true`, which is off
by default), you can also create the token there under Account and paste
it in with `sudoedit`, after
`sudo install -m 600 -o uberbringer -g uberbringer /dev/null /etc/uberbringer/ntfy.token`
has made the empty file.
+21 -21
View File
@@ -92,10 +92,10 @@ Before stage 1c:
Before stage 1d:
13. **The libc pin.** modernc requires the exact `modernc.org/libc` its go.mod pins (v1.80.1 for v1.63.0; the latest libc is v1.82.14). Assumed: the owner accepts this exception to "latest stable" for libc alone, which then moves only with `modernc.org/sqlite`. Stage 1d records it in CLAUDE.md's dependency rule and in design.md, and adds a gate check, since a routine `go get -u` would otherwise move libc and break the driver silently. The other new indirect modules are `modernc.org/mathutil`, `modernc.org/memory`, `github.com/dustin/go-humanize`, `github.com/ncruces/go-strftime` and `github.com/remyoudompheng/bigfft`; bigfft has no tagged release, so it comes in at a pseudo-version, as a few indirect modules in go.mod already do. This question falls away if question 1 picks another store.
14. **The Docker image's state directory.** Assumed: the image sets `UBERBRINGER_STATE_DIR=/var/lib/uberbringer`, so every container keeps a job store there, and it declares no `VOLUME`; the README asks for a named volume, or a bind mount owned by `10001:10001`. This is **Breaking**: a container started with `--read-only` and no volume, or with a bind mount owned by root, stops at start where 0.2.0 ran, since today only containers with subscriptions touch the directory. Trade-off: a `VOLUME` would give such containers an anonymous volume and let them start, but anonymous volumes pile up, and a new container silently starts with an empty one.
14. **The Docker image's state directory.** Assumed: the image sets `UBERBRINGER_STATE_DIR=/var/lib/uberbringer`, so every container keeps a job store there, and it declares no `VOLUME`; docs/docker.md asks for a named volume, or a bind mount owned by `10001:10001`. This is **Breaking**: a container started with `--read-only` and no volume, or with a bind mount owned by root, stops at start where 0.2.0 ran, since today only containers with subscriptions touch the directory. Trade-off: a `VOLUME` would give such containers an anonymous volume and let them start, but anonymous volumes pile up, and a new container silently starts with an empty one.
15. **Operational defaults.** Each assumed:
- A store that cannot be opened stops the daemon with an error naming the file, and the README gives the steps to move it aside. A damaged ntfy state file, by contrast, means a fresh start with a warning. Trade-off: starting with an empty store would silently forget the waiting jobs and which jobs were in doubt.
- The stop timeout must exceed `printer.write_timeout` plus about 10 s (Architecture, JOB STATES). The unit keeps systemd's 90 s default, enough at the default 30-s write; the README asks Docker users, whose default is 10 s, for `--stop-timeout 40` at the defaults. Trade-off: a shorter timeout kills a write, which leaves its job `uncertain`, never doubled.
- A store that cannot be opened stops the daemon with an error naming the file, and docs/install.md and docs/docker.md give the steps to move it aside. A damaged ntfy state file, by contrast, means a fresh start with a warning. Trade-off: starting with an empty store would silently forget the waiting jobs and which jobs were in doubt.
- The stop timeout must exceed `printer.write_timeout` plus about 10 s (Architecture, JOB STATES). The unit keeps systemd's 90 s default, enough at the default 30-s write; docs/docker.md asks Docker users, whose default is 10 s, for `--stop-timeout 40` at the defaults. Trade-off: a shorter timeout kills a write, which leaves its job `uncertain`, never doubled.
- `UMask=0077` in the unit, so the WAL and any later file are 0600 like the database. Trade-off: none known; the state directory is 0700 already.
- CI and the gate gain a `CGO_ENABLED=0` build of linux/arm (GOARM=6) and linux/arm64, and the libc check (question 13). Trade-off: a longer CI run; today nothing compiles the arm targets before a release tag.
@@ -309,7 +309,7 @@ COMPATIBILITY
- Job status keeps its shape until there are several printers; only then does it gain the `deliveries` array (Architecture, DELIVERIES AND SEVERAL PRINTERS).
- What prints does not change. TestRenderCompat and TestPaperReceipts keep passing.
- The Docker image keeps a job store in `/var/lib/uberbringer`, so a container that cannot write there stops at start (question 14, **Breaking**).
- A downgrade: an older binary refuses `[state] dir` and `queue.content_bytes` as unknown keys and ignores `jobs.db`. The CHANGELOG and README say so.
- A downgrade: an older binary refuses `[state] dir` and `queue.content_bytes` as unknown keys and ignores `jobs.db`. The CHANGELOG and docs/configuration.md say so.
INVARIANTS
1. Nothing reaches the printer unless the whole receipt rendered.
@@ -351,7 +351,7 @@ A job has one or more deliveries, one per printer it goes to (DELIVERIES AND SEV
- The stop timeout must therefore exceed `printer.write_timeout` plus about 10 s (question 15). A SIGKILL mid-write leaves the job `uncertain`.
STORE FAILURES (question 11)
- A store that cannot be opened stops the daemon with an error naming the file. The README's steps: stop the daemon, move `jobs.db` and `jobs.db-wal` aside together, start it again (`systemctl reset-failed uberbringer` first if systemd stopped restarting it). The stored jobs are forgotten, and which of the last receipts printed must be checked against the paper by hand.
- A store that cannot be opened stops the daemon with an error naming the file. The steps in docs/install.md and docs/docker.md: stop the daemon, move `jobs.db` and `jobs.db-wal` aside together, start it again (`systemctl reset-failed uberbringer` first if systemd stopped restarting it). The stored jobs are forgotten, and which of the last receipts printed must be checked against the paper by hand.
- After Open, any failed store write stops the daemon, as question 11 describes. Nothing is retried, since a write that failed once (a full disk, a damaged page) seldom succeeds a moment later.
TELLING WHICH RECEIPTS PRINTED BEFORE A CRASH
@@ -515,16 +515,16 @@ API
- Every route is an entry in the table in `server/routes.go`, written there in OpenAPI form (`{id}`; api.md writes `:id`), with its case in TestRoutesConform. Every code goes into `server/errors.go`, the table in docs/api.md and the regenerated swagger.json.
CONFIG, PACKAGING, INSTALL.SH, DOCKER, WINDOWS
- Config (question 4): `[state] dir`, with no default, required with an ntfy subscription, empty keeping the queue in memory. Stage 1c adds `queue.content_bytes`, default 67108864 (64 MiB), 0 to 1 GiB, an `int64` so 32-bit ARM can hold it. Each gets its default, validation, `configs/config.example.toml` entry and README § Configuration. `ntfy.state_dir` goes, and its `[Unreleased]` CHANGELOG entry is edited rather than listed as Breaking.
- Config (question 4): `[state] dir`, with no default, required with an ntfy subscription, empty keeping the queue in memory. Stage 1c adds `queue.content_bytes`, default 67108864 (64 MiB), 0 to 1 GiB, an `int64` so 32-bit ARM can hold it. Each gets its default, validation, `configs/config.example.toml` entry and docs/configuration.md. `ntfy.state_dir` goes, and its `[Unreleased]` CHANGELOG entry is edited rather than listed as Breaking.
- Files: `<dir>/jobs.db` and `<dir>/jobs.db-wal` (no `-shm` in exclusive mode), and `<dir>/ntfy-<name>.json`.
- The unit already has `StateDirectory=uberbringer` with mode 0700. Add `UMask=0077` (question 15), and reword the comment that names `ntfy.state_dir`.
- install.sh writes `[state] dir = "/var/lib/uberbringer"` into new configs. Re-runs keep the config, so an older config keeps the memory queue until the owner adds the line; the README says so.
- Docker (question 14): `UBERBRINGER_STATE_DIR=/var/lib/uberbringer` replaces `UBERBRINGER_NTFY_STATE_DIR`, and the comment says the directory holds the job store and the ntfy state. The README asks for a named volume there, or a bind mount owned by `10001:10001`, not a Docker Desktop bind mount, since WAL needs a local filesystem, and for a stop timeout above `printer.write_timeout` plus 10 s (`--stop-timeout 40` at the defaults).
- install.sh writes `[state] dir = "/var/lib/uberbringer"` into new configs. Re-runs keep the config, so an older config keeps the memory queue until the owner adds the line; docs/install.md says so.
- Docker (question 14): `UBERBRINGER_STATE_DIR=/var/lib/uberbringer` replaces `UBERBRINGER_NTFY_STATE_DIR`, and the comment says the directory holds the job store and the ntfy state. docs/docker.md asks for a named volume there, or a bind mount owned by `10001:10001`, not a Docker Desktop bind mount, since WAL needs a local filesystem, and for a stop timeout above `printer.write_timeout` plus 10 s (`--stop-timeout 40` at the defaults).
- Windows is for development only. modernc builds there and its WAL works (spike); it syncs with FlushFileBuffers. `state.dir` has no default, so `go run` and the tests keep the memory queue unless a directory is set.
- Builds: nothing in CI compiles the arm targets today. Stage 1d adds the arm builds and the libc check to `test.yml`, the Makefile's `check` and CLAUDE.md's gate (question 15).
LOGGING AND PRIVACY
- Print contents now rest on disk: 0600 files in a 0700 directory, `secure_delete=FAST`, and retention by question 9. README § Configuration says so.
- Print contents now rest on disk: 0600 files in a 0700 directory, `secure_delete=FAST`, and retention by question 9. docs/configuration.md says so.
- No SQL is logged, and statements take parameters. Store errors name the operation and the job, never a value. If GORM is chosen, its logger is silenced.
- At start, one INFO line gives the number of jobs resumed, and one WARN line names each delivery that start turned `uncertain` by `job_id`, `printer`, `source` and `ref`.
- A store failure is an unexpected error: logged once at ERROR and reported to Sentry once, without content.
@@ -618,7 +618,7 @@ Packaging
Docs
- configs/config.example.toml: `[state] dir` added; `[ntfy] state_dir` removed.
- README: the install note on `/var/lib/uberbringer`, the Docker paragraph, the `ntfy.state_dir` entry under Configuration (it becomes `state.dir`), the ntfy example config, and the State paragraph's `<state_dir>/ntfy-<name>.json`.
- The install note on `/var/lib/uberbringer` in docs/install.md, the ntfy paragraph of docs/docker.md, the `ntfy.state_dir` entry in docs/configuration.md (it becomes `state.dir`), and in docs/ntfy.md the example config and the State paragraph's `<state_dir>/ntfy-<name>.json`.
- design.md: the ntfy State paragraph, which names `ntfy.state_dir`.
- CHANGELOG: the `[Unreleased]` entry that adds `ntfy.state_dir`, edited.
@@ -671,7 +671,7 @@ internal/app/uberbringer/server
Docs
- docs/api.md: job status (`uncertain`, `sent_at`, and what `failed` with `sent_at` means).
- docs/swagger.json regenerated.
- README: `queue.content_bytes` under Configuration.
- docs/configuration.md: `queue.content_bytes`.
- configs/config.example.toml: `[queue] content_bytes`.
- design.md: "Jobs remember their source" (a digest's reference), and the digest paragraph of the ntfy subscriptions.
- CHANGELOG: under **Breaking**, the `uncertain` status; under Added, `sent_at` and `queue.content_bytes`; under Changed, a digest's reference in the logs.
@@ -738,14 +738,14 @@ Packaging
Docs
- design.md: replace "The queue lives in memory, on purpose" with the store the owner chose, the state machine, the sync policy and store failures, with stage 1a's numbers. Update the diagram ("printqueue (memory, 1 worker)") and "no database", the ntfy paragraph that says waiting jobs are lost, and the statement that ESC/POS has no acknowledgement. Record the libc exception (question 13). Shrink the Deferred item to the previews.
- README:
- Configuration: `state.dir` now holds the job store too; a privacy note.
- The install notes and the Docker section: the state directory, a named volume or a bind mount owned by `10001:10001`, and the stop timeout.
- The ntfy "Jobs" paragraph, which says a waiting job is lost at shutdown.
- The worker's log lines.
- The steps for a store that will not open (STORE FAILURES).
- A downgrade note.
- Development: the layout (`internal/pkg/jobstore`, `tools/libcpin`), the `make check` steps, and "CI and releases", which says test.yml builds no binaries.
- The docs:
- docs/configuration.md: `state.dir` now holds the job store too; a privacy note.
- docs/install.md and docs/docker.md: the state directory, a named volume or a bind mount owned by `10001:10001`, and the stop timeout.
- docs/ntfy.md: the "Jobs" paragraph, which says a waiting job is lost at shutdown.
- docs/configuration.md: the worker's log lines, under Logs.
- docs/install.md and docs/docker.md: the steps for a store that will not open (STORE FAILURES).
- docs/configuration.md: a downgrade note.
- docs/development.md: the layout (`internal/pkg/jobstore`, `tools/libcpin`), the `make check` steps, and "CI and releases", which says test.yml builds no binaries.
- docs/api.md: job status (what survives a restart) and the `job_not_found` row.
- CHANGELOG: under Added, jobs survive a restart; under **Breaking**, that with a state directory waiting jobs print after a restart instead of failing, and the Docker image's store (question 14); the downgrade note.
- CLAUDE.md: the layout and the imports (jobstore → printqueue; internal/app → jobstore); the gate's new steps, and line 75's "It builds no binaries"; the libc exception beside the rule that dependencies are at their latest stable release.
@@ -856,7 +856,7 @@ internal/app/uberbringer/server
Docs
- docs/api.md: the route table, a "Cancel a job" section, the `job_started` row in the error table, and the Job status section (`cancelled`).
- README: how a subscription behaves: a `message_delete` cancels the waiting receipts of its notification and drops its held digest rows, also under `min_priority` and past `max_backlog`; a `message_clear` does neither; `min_priority` is applied by the subscriber, which reads every message of its topics.
- docs/ntfy.md: how a subscription behaves: a `message_delete` cancels the waiting receipts of its notification and drops its held digest rows, also under `min_priority` and past `max_backlog`; a `message_clear` does neither; `min_priority` is applied by the subscriber, which reads every message of its topics.
- design.md: the state machine's `cancelled`, its synced commit and the delivery lock; the ntfy subscriptions paragraph (deletes cancel, clears do not, and the subscriber filters priorities itself).
- docs/plans/formatters.md: its phase 5 item "Queue.Cancel so message_delete can cancel a still-queued job" goes, since this phase builds it.
- CHANGELOG: under **Breaking**, the `cancelled` status; under Added, `DELETE /api/v1/jobs/{id}` and cancelling by ntfy deletes; under Changed, that a subscription with `min_priority` reads every message and filters itself.
@@ -964,7 +964,7 @@ internal/app/uberbringer
Docs
- docs/api.md: the preview section (the PNG, the fetch deadline, the cap) and the error row. The text and JSON previews still fetch no images; the PNG preview does.
- design.md: why the picture is drawn from the bytes rather than the layout; the font, its licence, and why box drawing is drawn rather than taken from it; "The preview reads the bytes back" ("a preview never fetches anything") and "Images are fetched by the worker" ("a slow or broken image URL holds no HTTP request"), which a PNG preview no longer keeps to.
- README: the CLI, and § Development's layout (`internal/pkg/paper`, `tools/genglyphs`).
- docs/cli.md, and the layout in docs/development.md (`internal/pkg/paper`, `tools/genglyphs`).
- CLAUDE.md: the layout and the imports (receipt → paper → escpos).
- CHANGELOG. docs/swagger.json regenerated.
+92
View File
@@ -0,0 +1,92 @@
# Tokens and security
## Contents
- [The API secret](#the-api-secret)
- [Issuing tokens](#issuing-tokens)
- [Keeping tokens off command lines](#keeping-tokens-off-command-lines)
- [Behind a reverse proxy](#behind-a-reverse-proxy)
- [Image URLs](#image-urls)
- [What is never logged](#what-is-never-logged)
## The API secret
`api.secret` signs every bearer token (HS256) and must be at least 32
bytes. `uberbringer secret` prints a new random one. `install.sh` writes it
into a config that only root and the daemon's group can read, and
`uberbringer config get` never prints it.
A token stays valid until it expires, and a token issued without `--ttl`
never does. Changing the secret invalidates every token signed with the old
one, which is the only way to withdraw a token.
## Issuing tokens
All `/api/v1` routes need an `Authorization: Bearer <token>` header; a
token in a query string is refused, since it would leak into proxy logs.
On a host set up by `install.sh`, issue a token as root, naming the client:
```sh
sudo uberbringer token --config /etc/uberbringer/config.toml --subject my-script
```
What a token may do is set when it is issued ([token](cli.md#token)):
- Without flags, it may use every route but cannot print jobs with `raw`
elements.
- `--raw` lets it print them. Give it only to clients that send ESC/POS
bytes of their own, since those bytes reach the printer as they are.
- `--modules ntfy,notify` limits it to those modules. Give integrations,
such as the [ntfy client](api.md#printing-from-the-ntfy-client), one of
these, so that they cannot send printer commands.
[api.md](api.md#api) gives the routes each token may call and the `403`
`token_scope` answer for the others.
## Keeping tokens off command lines
Keep a token off command lines, where other users of the machine can
read it, and out of shell history. The examples in [api.md](api.md) send
the header from a file only you can read, which curl 7.55 and later take
as `-H @file`. Make it like this: the token passes through a shell
variable, never a command's arguments or the terminal, and the file is
written only if the token command succeeded. For a client on another
machine, copy the file there.
```sh
token=$(sudo uberbringer token --config /etc/uberbringer/config.toml --subject my-script) &&
(umask 077; printf 'Authorization: Bearer %s\n' "$token" > ~/.uberbringer-auth)
unset token
```
[Printing from the ntfy client](api.md#printing-from-the-ntfy-client)
does the same for the ntfy client's user, and [docker.md](docker.md) keeps
the secret in an env file for a container.
## Behind a reverse proxy
The daemon serves no TLS and listens on `127.0.0.1` by default. A reverse
proxy in front terminates HTTPS: Caddy, which `install.sh` sets up, or your
own in front of the [Docker image](docker.md). The proxy sets `X-Real-IP`
to the client's address, and the daemon reads it only from the addresses
in `webserver.trusted_proxies`, so that each client has a rate limit of its
own ([webserver](configuration.md#webserver)).
## Image URLs
Images are fetched by the worker, when the job prints. URLs that resolve to
loopback, private or link-local addresses, cloud metadata endpoints
included, are refused unless `images.allow_private_networks` is true or the
host is in `images.allowed_hosts` ([images](configuration.md#images)). The
address is checked when the connection is made, so a redirect or a DNS
answer that changes cannot get round it.
## What is never logged
Print contents, tokens and the API secret never reach the logs or Sentry.
Request bodies and the `Authorization` header are never sent to Sentry. An
ntfy subscription never logs a message's text or its topic, and its
`last_error` in `/healthz` leaves out the topics, since on a public server a
topic's name can be all that keeps others from publishing to it.
[Logs](configuration.md#logs) lists what is logged, and
[ntfy.md](ntfy.md#securing-the-topics) how to keep strangers off your topics.