Files
uberbringer/README.md
T
57_WolveandClaude Opus 5.5 1335ed0687
Security / Vulnerability check (push) Successful in 41s
Test / Lint and test (push) Successful in 1m57s
Add the notify and ntfy modules and scoped tokens
Breaking: a job with a raw element prints only with a token issued with
uberbringer token --raw. Every other token, every existing one included,
gets 403 token_scope for it, with the raw elements in details, and keeps
every other route.

The notify module prints a notification card from a title, message,
priority and tags, with topic, click, up to three actions, image,
markdown and time as options; it decodes strictly and refuses a payload
over its length caps. The ntfy module takes one ntfy message as ntfy
sends it, such as the ntfy client's $NTFY_RAW, ignores fields it does
not know, cuts text over the caps, and answers 204 for other events and
binary bodies. Both print every message plain: one message cannot tell
the first of a sequence from a replacement, since a publisher may choose
the sequence ID. internal/pkg/ntfy holds ntfy's message types.

Both print the same card. The priority picks the form: a dark URGENT
rule and a double box, a double box headed HIGH, a single box with the
title in its border, or a rule with no box. Tags print as markers in
front of the title, the rest on a Tags row; links print as QR codes with
their labels; attached PNG, JPEG, GIF and WebP images print after the
card. A line-level markdown subset is laid out without a dependency,
keeping marks inside code spans and URLs, and emoji are removed after a
few typed ones become markers. A card that cannot be laid out prints as
a plain receipt, and the server logs the fault once at ERROR and reports
it to Sentry once. [ntfy.format] and [ntfy.markers] shape the cards; the
markers table is a setting with the user's own keys, also settable as
UBERBRINGER_NTFY_MARKERS=name=value,...

uberbringer token --modules issues a token limited to those modules'
print and preview routes, job status and the module list; each route in
the table says which tokens it takes, and a scope claim that could read
as absent makes the token invalid. image elements take optional, which
also shrinks a too-wide image to the paper; a QR code that could be too
wide for the paper prints with smaller modules; box takes title_bold.
Submit takes a Meta whose source shows in job status and, with a copy
of the request ID, in every worker log line of the job.

The four ntfy cards passed on the TM-T88IV, posted as the client recipe
posts them, and their bytes are pinned in TestPaperReceipts. docs/api.md
describes the modules, the card and the client recipe, with tokens read
from a header file; docs/swagger.json is regenerated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 13:57:08 -06:00

20 KiB
Raw Blame History

Überbringer

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: print ntfy messages as they arrive, through the ntfy client with no other tools, 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.

Note

Pre-refactor code: no AI was used. The original Überbringer (v0.1.x), up to commit bb73348 from January 2025, was written without any AI. That commit shows the code as it was before the 0.2 refactor.

Contents

Quick start

Debian/Ubuntu server with Caddy and TLS

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 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.
  • Change the systemd unit with systemctl edit uberbringer.
  • The install log is /var/log/uberbringer-install.log.

Docker

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). 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:

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
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.

From source

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 is the API reference: the routes, the print elements and blocks, the modules, and the error codes. 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 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:

  • 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.

  • 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 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 of the notify and ntfy modules:

    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
  • [ntfy.markers] adds or changes the markers printed for tags, at most 16 characters each, and "" hides a tag: backup = "[B]", nas01 = "".

  • 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.
    • 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.

Command line

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

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, 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 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.
make check      # the CI gate, below
make build      # bin/uberbringer
make fmt        # gofmt + goimports
make vuln       # govulncheck
make openapi    # regenerate docs/swagger.json (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. openapi-check: go generate ./... must leave docs/swagger.json 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.

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.

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
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/genopenapi/           Generates docs/swagger.json from the route table
docs/                       API reference, OpenAPI document, design notes and feature plans

docs/design.md explains why the daemon is shaped as it is. 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 docs/swagger.json is 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, 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.

License

Copyright © 2025-2026 William Gill.

Licensed under the European Union Public Licence v. 1.2 (EUPL-1.2). The full text is in LICENSE.txt, and translations into every official EU language are equally valid. Releases up to and including 0.1.2 were published under the GNU Affero General Public License v3.0.