diff options
| author | Jason McCormick <jason@mfamily.org> | 2026-11-05 18:20:34 -0500 |
|---|---|---|
| committer | Jason McCormick <jason@mfamily.org> | 2026-11-05 18:20:34 -0500 |
| commit | 75719aa37f7317f3a8feeb516f1444edb4274410 (patch) | |
| tree | 36e7e0454ad0044ebc72a253935790afc389843c /README.md | |
| parent | 67383e6863fcff8b49e680b5b861b3154f8cb518 (diff) | |
feat: TOML config and upload notification watcher
Replace allowed-uris.txt with config.toml: [GLOBAL] holds SMTP settings
(send_as, smtp_server, smtp_port, tls, starttls) and every other stanza is
an upload URI with a recipient and optional view_url_prefix.
Add watcher.py, run every 5 minutes by a systemd timer, which emails each
drop's recipient once per run when new images appeared in the last slot.
The email links each image under view_url_prefix and includes its .txt
submission details.
Fix the service unit and Makefile to use CONFIG_FILE, install the watcher
and its units, and validate the config before restarting.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 41 |
1 files changed, 37 insertions, 4 deletions
@@ -2,7 +2,7 @@ A small, dependency-free web application for private single-image submissions. It collects the submitter's amateur radio callsign, name, email address, and a brief file description. It accepts JPG, PNG, and HEIC files up to 10 MiB, verifies the file signature, replaces the original filename, and stores the image outside the HTTP-served directory. The submission details are stored in a UTF-8 `.txt` sidecar with the same private basename as the image. -Upload forms are available only at named, single-segment targets listed in `allowed-uris.txt`, such as `/logo-contest` or `/911u19jasdl`. Blank lines and lines beginning with `#` are ignored. The bare `/` path is rejected with HTTP 418. Each target stores its submissions in a separate private directory beneath the configured upload directory. +Upload forms are available only at named, single-segment targets configured in `config.toml`, such as `/logo-contest` or `/911u19jasdl`. The bare `/` path is rejected with HTTP 418. Each target stores its submissions in a separate private directory beneath the configured upload directory. ## Run locally @@ -12,7 +12,40 @@ python3 server.py Open a target such as <http://127.0.0.1:8000/logo-contest>. By default, its uploads are written to `data/uploads/logo-contest/`, while the server only exposes allow-listed frontend assets. Uploaded files therefore have no HTTP route. -For local use, edit `allowed-uris.txt` and restart the server after making changes. URI entries must contain exactly one segment composed of letters, numbers, underscores, or hyphens, with a maximum length of 64 characters. +## Configuration + +`config.toml` holds one `[GLOBAL]` stanza for outgoing mail. Every other stanza is an upload URI, and its `recipient` is the address that gets notified about new uploads there: + +```toml +[GLOBAL] +send_as = "uploads@example.com" # From address +smtp_server = "smtp.example.com" +smtp_port = 587 +tls = false # implicit TLS (typically port 465) +starttls = true # STARTTLS upgrade (typically port 587) + +[logo-contest] +recipient = "reviewer@example.com" +view_url_prefix = "https://review.example.com/logo-contest/" # optional + +["911u19jasdl"] # quote names that TOML would not accept bare +recipient = "other@example.com" +``` + +Stanza names must be a single segment made of letters, numbers, underscores, or hyphens, at most 64 characters long. `tls` and `starttls` cannot both be `true`. Restart the server after changing the URI stanzas. The watcher re-reads the file on every run. + +## Upload notifications + +`watcher.py` is run every 5 minutes by `blind-uploader-watcher.timer`, which fires at :00, :05, :10, and so on. It checks each configured drop for an image modified during the last 5-minute slot. If it finds one, it sends a single email to that drop's recipient. The email has no attachment. It includes the submission details (callsign, name, email, and description) from each new image's `.txt` sidecar. If the stanza sets `view_url_prefix`, the email links to each new image as `<view_url_prefix><stored filename>`, for example `https://review.example.com/logo-contest/3f9c…a1.png`. The prefix must be an absolute `http`/`https` URL, and a trailing `/` is added if missing. It should point at the separately protected nginx location that serves this drop's upload directory. Without a prefix, the email contains only the generic message. Nothing is stored between runs. If the system is down or the timer is stopped during a slot, uploads from that slot are never reported. + +If your SMTP server requires authentication, put the credentials in `/etc/default/blind-uploader-watcher` and make the file `root:root` mode `0600`: + +```ini +SMTP_USERNAME=uploads@example.com +SMTP_PASSWORD=... +``` + +To check that it works, run `sudo systemctl start blind-uploader-watcher.service` and `journalctl -u blind-uploader-watcher.service`. For production, choose a private directory on a persistent disk and bind to the needed interface: @@ -46,7 +79,7 @@ To install the application, systemd unit, and nginx configuration in one step, r sudo make install DOMAIN=upload.example.com ``` -This validates the nginx configuration before starting the service and reloading nginx. It requires Python 3, systemd, nginx, `make`, Debian's `www-data` account, and standard Unix installation tools to already be installed. For `DOMAIN=upload.example.com`, the generated nginx configuration is `/etc/nginx/sites-available/upload.example.com`. Subsequent installs preserve both that nginx configuration and the URI allowlist at `/etc/blind-uploader/allowed-uris`, so local changes are not overwritten. +This validates the nginx configuration before starting the service and reloading nginx. It requires Python 3, systemd, nginx, `make`, Debian's `www-data` account, and standard Unix installation tools to already be installed. For `DOMAIN=upload.example.com`, the generated nginx configuration is `/etc/nginx/sites-available/upload.example.com`. Subsequent installs preserve both that nginx configuration and `/etc/blind-uploader/config.toml`, so local changes are not overwritten. The installer validates the config, installs both units, and enables the notification timer. An existing `/etc/blind-uploader/allowed-uris` from an earlier install is no longer read, and the installer prints a warning if it finds one. Re-running the installer restarts the service so updated server code takes effect. To run the test suite without installing anything: @@ -64,7 +97,7 @@ sudo systemctl enable --now blind-uploader.service sudo systemctl status blind-uploader.service ``` -The unit runs as Debian's existing `www-data:www-data` account and uses systemd's `StateDirectory` feature for private writable storage. Application files remain root-owned and read-only to the daemon. The URI allowlist is root-owned, group-readable by `www-data`, and otherwise private. Optional overrides can be placed in Debian's standard `/etc/default/blind-uploader` environment file, for example: +The unit runs as Debian's existing `www-data:www-data` account and uses systemd's `StateDirectory` feature for private writable storage. Application files remain root-owned and read-only to the daemon. The configuration file is root-owned, group-readable by `www-data`, and otherwise private. Optional overrides can be placed in Debian's standard `/etc/default/blind-uploader` environment file, for example: ```ini PORT=8080 |
