Files
ianitor/docs/ui-api.md
T

503 lines
46 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
> This file is the web UI's contract with the control API for Phase 3 (from the designer; deviations are listed at the end).
# Ianitor Domi: what the web UI needs from the Phase 2 API
From the UI design (claude.ai/artifact/GEiCCPcGC1hiCkA2NrrH9u, 9 boards) and ROADMAP §3, §4, §6, §10.
Shapes are resource + method + fields, not OpenAPI. Sources: [D] drawn on a board, [R] ROADMAP, [C] current code, [J] my call.
## 0. Ground rules for every call
- Base path `/api/v1`, JSON, times RFC 3339 UTC. The UI formats times in the browser's zone ("Today 14:02").
- Every response carries `server_time`. The UI counts down from `ends_at - server_time`, never from the browser clock.
- Errors use one envelope:
```
{ "error": { "code": "host.hostname.taken", "message": "<plain English, shown as is>",
"field": "hostname" | null, "params": { ... }, "retry_after_s": null },
"errors": [ ...same shape, for several field errors... ], "request_id": "01J..." }
```
`code` is stable and is what the UI switches on. `message` is the §3 text, filled by the server, so curl users get the same words.
`params` holds the values in the message (hostname, address, counts, dates) so the UI can bold them.
A technical detail (core's own error text, log lines) goes only in `detail`, shown behind "Show details". It never holds a secret value or a token.
- Writes take an `Idempotency-Key` header, one per click. An apply can reload the proxy the UI talks through, so a dropped POST gets retried, and the retry must not apply twice.
- Writes that change routes take `base_rev`: the routes-tree commit the form was loaded from. The server refuses only if *the same host file* changed since then (§3 `change.conflict`). A change elsewhere in the tree is fine, so queued applies don't refuse each other.
- The UI sends `X-Ianitor-UI: 1` on every request, as a CSRF guard: control refuses browser-origin writes without it. Who the user is comes from the Authelia `Remote-User` that edge forwards (see gap G14).
## 1. Per flow
### 1.1 Main screen (desktop and phone boards) [D]
**One call: `GET /overview`.** Yes, one call is possible, as long as control keeps a cached copy of health (edge pushes it or control pulls every 2 s; see G1). The request must never wait on a live probe.
| Block | Fields | Shown as |
|:--|:--|:--|
| `counts` | `hosts, healthy, degraded, down, unknown` | "7 hosts · 5 healthy, 1 degraded, 1 down" |
| `hosts[]` | `hostname, upstreams[] (url), tls ("domi"\|"letsencrypt"), auth ("none"\|"forward-auth"), websockets, share_links, added_at` | row, chips, "Added today" |
| `hosts[].health` | `state ("healthy"\|"degraded"\|"down"\|"unknown"\|"pending"), last_check_at, latency_ms (nullable), since, failure {kind, upstream, count, of} \| null, upstreams[] {url, state, last_check_at, latency_ms, failure_kind}` | dot + word, "Checked 8 s ago · 42 ms", "Connection refused for 6 minutes" |
| `hosts[].certificate` | `state ("ok"\|"pending"\|"failed"), not_after, error_code` | extra line only when not `ok` |
| `engine` | `running ("pingora"\|"caddy"), state ("running"\|"switching"\|"stopped"), since, fallback_ready {built_at, compared, matched} \| null` | engine chip; popover (switch flow) |
| `last_apply` | the most recent apply record (§2), any outcome, or null | last-change bar: state word, summary, sub-line |
| `undo` | see §2.3 | the Undo button and its name |
| `active_apply` | `{id, state, summary, seconds_left}` \| null, plus `queued` (count) | "Applying wiki.home.example: 41 s left" when the user comes back to the main screen |
| `repo` | `name, last_push_at, unpushed (count), push_error_code` \| null | footer "Last pushed to Gitea at 14:03" |
| `intermediate` | `not_after, days_left, renewal {request_id, state, match_code, expires_at} \| null`; **null until Phase 3** | banner when `days_left <= 30` or `renewal` is open |
| `site` | `forward_auth_configured, acme_configured, secrets[] (names only), watch_seconds (60)` | add-host form: disables "Sign in first" if Authelia is not set up; secret picker in headers |
| `paused` | `{code, message}` \| null | full-width notice; disables + Host, Undo, Restore |
Health `state` rules for the UI [J]: `healthy` = every upstream passed its last check. `degraded` = some passed, some failed, or the last 5 checks were mixed. `down` = no upstream passed the last check. `unknown` = no health check set. `pending` = added but not yet checked. The drawn "slow: 2.8 s, limit is 2 s" has no basis in the schema (see G2).
Polling: every 5 s while the tab is visible, every 30 s when hidden. Send `If-None-Match` with the ETag and expect `304` when nothing changed.
Clicks on the main screen:
| Click | Call |
|:--|:--|
| + Host | none (opens the panel) |
| Undo | `POST /undo` (§1.3) |
| Renew (banner) | `POST /certs/intermediate/renewal` (Phase 3, §1.8) |
| ⋯ on a row | none (menu) |
| ⋯ → Edit host | `GET /hosts/{hostname}` → returns the full host (all §3 ROADMAP fields) + `rev` |
| ⋯ → Show in history | `GET /history?host={hostname}` |
| ⋯ → Remove host | `DELETE /hosts/{hostname}?base_rev=` → `202` apply. No confirmation dialog: Undo restores the host in 1 click [J] |
| Engine chip | none (popover from `engine`) |
### 1.2 Add host: + Host → fill → Apply = 2 clicks [D][R]
| State | Call | Shows |
|:--|:--|:--|
| Panel open | none; values come from `overview.site` | hostname focused; form defaults Domi certificate, Sign in first [D] (the UI always sends explicit values; schema defaults are letsencrypt and none [C]) |
| Typing (field blur, not a click) | `POST /hosts/validate` body = host, `?mode=create` | inline field errors (§3.1), including a taken hostname, before Apply |
| **Apply (click 2)** | `POST /hosts` body = `{host, base_rev}` | `422` with `errors[]` → keep the panel, mark the fields. `202 {apply}` → the panel shows the apply steps (§2) |
| Watching | `GET /applies/{id}` every 1 s (§2.2) | checklist + "41 s left" + progress bar |
| Kept | (final poll) | panel closes; the row appears; the bar shows `kept` + Undo |
| Reverted | (final poll) | panel stays open with the user's values; banner with the reason; "Edit and try again" focuses the field the reason names (`reason.field`, e.g. `upstreams[0]`) |
Host body (mirrors the TOML [C]):
`hostname, upstreams[] (strings), tls, auth, websockets, share_links, access_log ("off"|"truncated"), health_check {path, interval_secs} | null, request_headers[] / response_headers[] {action ("set"|"remove"), name, value | secret}`.
### 1.3 Undo last change = 1 click [D][R]
- Data: `overview.undo` (§2.3). The button reads **Undo** with the target's name beside it in the bar.
- Click: `POST /undo {target_change_id}` → `202 {apply}`, with the same states as any apply. The server refuses with `409 undo.target_moved` if the target is no longer the latest kept change, so Undo never undoes something it did not name.
- During its own watch, Undo is disabled with "Wait for the check to finish (41 s)". If a *different* apply is running, Undo is queued like any change.
### 1.4 Restore: History → pick → Restore = 3 clicks [D][R]
| Click | Call | Fields shown |
|:--|:--|:--|
| 1 History | `GET /history?limit=50` (`before=` for more) | `entries[] {change_id, summary, kind ("add"\|"edit"\|"remove"\|"undo"\|"restore"\|"share_links"), state ("kept"\|"reverted"\|"failed"\|"queued"\|"running"), at, commit_short, hosts[], reason_short}` ("port refused") |
| 2 pick | `GET /history/{change_id}/restore-preview` | `restorable` (false for reverted or failed entries, which instead offer "Edit and try again" using `GET /history/{id}` → `attempted_host`), `same_as_current`, `changes[] {hostname, effect ("added"\|"removed"\|"changed"), fields[] {field, from, to}}` |
| 3 Restore this version | `POST /restore {change_id, base_rev}` | `202 {apply}` → bar: "Restored the version of 3 Nov, 09:30" |
- History must show one entry per user action. An attempt that was reverted is one `reverted` entry, not a commit row plus a revert row. Control groups them.
- The UI writes the preview sentences from `fields[]` with this label map, so the wording is the same everywhere: hostname "address", upstreams "sends traffic to", tls "certificate", auth "who can open it", health_check.path "health check address", health_check.interval_secs "checks every", share_links "share links", access_log "visit log", websockets "websockets", headers "header rules".
- Drop the drawn line "wiki.home.example is not affected (never kept)". The preview lists only real differences.
### 1.5 Share link: ⋯ → Share link → Copy = 3 clicks [D][R]
| Click | Call | Fields |
|:--|:--|:--|
| 1 ⋯ | none | menu; "Share link" is enabled when the host's `share_links` is true (from overview) |
| 2 Share link | `POST /hosts/{hostname}/share-links {path_prefix: "/", expires_in_s: 604800}` → `201` | `id, url, expires_at, path_prefix, has_password` |
| 3 Copy link | none (client clipboard only, so the copy happens inside the click) | "Copied. Expires on 14 November 2026 at 14:20." |
| Change expiry or prefix, add a password (extra clicks) | `POST /hosts/{h}/share-links {..., replaces: <previous id>}` | the new link; the server stops the one it replaces. A link minted on open and never copied doesn't stay valid |
- Expiry options in the UI: 1, 7, 30 days. The server accepts 1 hour to 90 days [J].
- Password: `password` in the POST body; at least 8 characters [J]; never returned.
- Links off for this host: the dialog shows "Turn on share links and apply". Clicking it calls `PATCH /hosts/{h} {share_links: true, base_rev}` → `202 {apply}`. After `kept`, the UI auto-calls the mint POST and shows the link; Copy is click 4 (G10).
- Host with `auth = none`: the dialog says anyone can already open it. Mint anyway if asked; the UI does not block it.
- Settings → Share links: `GET /share-links` → `items[] {id, hostname, path_prefix, created_at, expires_at, has_password, state ("active"|"expired"|"stopped")}`. "Stop this link" calls `DELETE /share-links/{id}` → `204`. "Stop all share links" calls `POST /share-links/stop-all` (G8).
### 1.6 API token: ⚙ → API → New token = 3 clicks [D][R]
| Click | Call | Fields |
|:--|:--|:--|
| 1 Settings | `GET /settings` | `repo {name, last_push_at}, watch_seconds` (read-only in v1) |
| 2 API tab | `GET /tokens` | `items[] {id, name, created_at, last_used_at, expires_at \| null}`; never a hash or a prefix |
| 3 New token | `POST /tokens {name?}` → `201 {id, name, token, expires_at}` | the token is shown once and returned only in this response. The UI drops it from memory when the dialog closes |
| Rename (optional) | `PATCH /tokens/{id} {name}` | |
| Revoke | `DELETE /tokens/{id}` → `204` | the row goes to "Revoked today 14:40" until the next reload |
- Recommendation that removes the 4th click (G12): click 3 is **Make and copy token**. The UI calls `navigator.clipboard.write([new ClipboardItem({"text/plain": tokenPromise})])` inside the click, so the copy belongs to that click even though the POST is async. The POST must answer in under 1 s. The dialog then says "Copied. Paste it into Custos now." and keeps a Copy again button.
- Default lifetime 365 days, or "Never expires" as an option [J]. Expiry is needed for the expired-token message in §3.
### 1.7 Device certificate (Phase 3): Certificates → + Device → Issue = 3 clicks [D][R]
| State | Call | Fields |
|:--|:--|:--|
| 1 Certificates | `GET /certs` | `intermediate {subject, not_after, days_left}`, `root {offline: true}`, `devices[] {id, name, kind ("phone"\|"computer"\|"app"), not_after, state ("valid"\|"revoked"\|"expired")}`, `device_lifetime_days` |
| 2 + Device | none | form |
| 3 Issue | `POST /certs/devices {name, kind}` → `202 {request_id, match_code, expires_at}` | "47 19 83", "The request stays open for 10 minutes" |
| Waiting | `GET /pki-requests/{id}` every 2 s | `state ("waiting"\|"approved"\|"denied"\|"expired"\|"cancelled"\|"failed"), approved_at, device_id` |
| Cancel request | `DELETE /pki-requests/{id}` | |
| Issued, install (click 4) | `POST /certs/devices/{id}/bundle {format: "p12"\|"qr"}` → `{download_url, one_time_password, expires_at}` | one download only, then deleted; QR encodes `download_url` (G15) |
| Revoke a device | `DELETE /certs/devices/{id}` | |
### 1.8 Renew intermediate (Phase 3): banner Renew = 1 click [D][R]
- Click: `POST /certs/intermediate/renewal` → `202 {request_id, match_code, expires_at}`. The banner turns into the match code and "Approve it in Custos".
- Then `GET /pki-requests/{id}` every 2 s. Once `approved`, `overview.intermediate.not_after` moves on and the banner says "Renewed. The Domi intermediate certificate is now valid until 30 November 2027." for this session.
- Banner states the UI needs: `due` (≤ 30 days), `urgent` (≤ 7 days, uses the `down` colour), `waiting` (match code), `expired`, `failed` (§3.6).
### 1.9 Switch engine (not in this brief's scope, but on the main screen)
`overview.engine` is enough to draw the chip and the popover. The switch call (`POST /engine {target}` → `202`, polled like an apply) waits on Mark's decision (b) in §10.
## 2. Apply outcomes
### 2.1 The apply record
`GET /applies/{id}` (also embedded as `last_apply` and in every `202`):
```
id, change_id, kind, summary ("Added wiki.home.example"), hosts[], state, created_at, finished_at,
steps[] { key ("validate"|"compile"|"write"|"reload"|"watch"|"push"), state ("pending"|"running"|"done"|"failed"|"skipped") },
queue { position, waiting_for { apply_id, summary, seconds_left } } | null,
watch { ends_at, seconds_left, hosts[] { hostname, passed, failed, total } } | null,
reason { code, message, hostname, upstream, field, count, of } | null,
commit_short | null, push { state ("pushed"|"pending"|"failed"), at, error_code, next_try_at } | null,
undo_of | null, restore_of | null
```
| `state` | When | The UI shows (copy in §3.2) |
|:--|:--|:--|
| `queued` | another apply is running | "Waiting for 'Added recipes.home.example' to finish (about 40 s)." + Cancel (`DELETE /applies/{id}`, allowed only while queued) |
| `validating` | checking the files again in the queue | step 1 running |
| `applying` | compile, write, reload | steps 2–3 running |
| `watching` | the 60 s health watch | step 4, "41 s left", progress `60 - seconds_left` of 60 |
| `kept` | passed; committed | bar `kept`; push sub-state below |
| `kept` + `push.state = failed` | kept, but Gitea refused or did not answer | bar `kept` + "Not yet saved to Gitea" + Try now (`POST /repo/push`) |
| `reverted` | failed the watch; undone | banner `reverted` + `reason.message` + Edit and try again |
| `failed` | never went live (validation in the queue, compile, reload refused) | banner + reason; nothing changed |
| `interrupted` → `reverted` | control restarted mid-apply | reason `apply.interrupted` |
| `needs_attention` | the revert itself failed | red banner, Restore last kept version (§3.2) |
Watch rule recommendation [J]: watch only the hosts this change touches. A host that was already down before the change is no reason to revert. A touched host fails if it has no healthy upstream for 3 checks in a row, or none at the end of the 60 s. During the watch, edge checks touched hosts every 5 s whatever their interval, so a watch has about 12 checks, not 6. Removing a host has nothing to watch: `watch` is `skipped` and the result is `kept`. Hosts without a health check: see G3.
### 2.2 How the UI learns progress: polling, 1 s
**Pick: polling `GET /applies/{id}` every 1 s while the state is queued, validating, applying or watching; then stop.**
Why not SSE:
1. The browser reaches control *through the proxy the apply reloads*: edge with forward-auth, or Caddy after a switch. A graceful reload either holds the old process open for a long-lived stream or cuts it at the drain timeout. A revert reloads a second time. Every apply would break the SSE stream at its most important moment. A 1 s poll just retries.
2. Engine switches and control restarts drop every connection too. Polling needs no resume logic; SSE needs `Last-Event-ID` replay.
3. Cost is trivial: one small JSON per second on loopback, 60 per apply, one apply at a time.
4. Smoothness: the UI counts down locally from `watch.ends_at - server_time` between polls, so the seconds tick evenly even if a poll is late.
Errors while polling: retry quietly for 10 s (a reload takes about 2 s), then show `ui.lost_contact` and keep polling every 5 s.
### 2.3 What the Undo bar needs
`overview.undo`:
```
available, target { change_id, summary, kept_at, commit_short } | null,
effect ("Removes recipes.home.example"), blocked { code, message } | null
```
- The target is always the latest **kept** change, never a reverted or failed one.
- Right after a reverted apply, the bar has two lines. Line 1 is `last_apply`: "`reverted` wiki.home.example was not added. Reason: …". Line 2 is the Undo button labelled with `undo.target.summary`: "Undo: Added recipes.home.example". The two lines come from two fields, so the bar always names what Undo will touch.
- After an Undo is kept, the latest kept change *is* the undo, so Undo again redoes it. `summary` for an undo reads "Undid: Added recipes.home.example", and `effect` reads "Adds recipes.home.example back". The button then says "Undo: Undid Added recipes.home.example", with the effect line under it.
- `blocked` codes: `undo.nothing` (no kept change yet), `undo.watching` (its own apply is still running), `undo.paused` (§3.2 needs_attention or repo paused).
## 3. Every user-facing message
`{x}` are `params`. Bold in the UI: hostnames and addresses. Tone: say what happened, what still works, and what to do. No "error", "failed to", "invalid", status codes, or protocol names.
### 3.1 Host form validation (one row per core error [C]; `field` in brackets)
| Code | Field | Message | UI offers |
|:--|:--|:--|:--|
| `host.hostname.missing` | hostname | Enter the address people will type, like wiki.home.example. | focus |
| `host.hostname.uppercase` | hostname | Use lowercase letters only: {suggestion}. | "Use {suggestion}" (fills it) |
| `host.hostname.characters` | hostname | Use only letters a–z, digits, dots and dashes. | focus |
| `host.hostname.spaces` | hostname | Remove the spaces from the address. | focus |
| `host.hostname.wildcard` | hostname | Addresses with * are not supported yet. Add each name as its own host. | focus |
| `host.hostname.trailing_dot` | hostname | Remove the dot at the end. | "Use {suggestion}" |
| `host.hostname.empty_label` | hostname | There are two dots in a row. Remove one. | focus |
| `host.hostname.label_dash` | hostname | A part of the address cannot start or end with a dash. | focus |
| `host.hostname.label_long` | hostname | Each part between dots can be at most 63 characters. | focus |
| `host.hostname.too_long` | hostname | The address can be at most 253 characters. | focus |
| `host.hostname.numeric` | hostname | That looks like an IP address. Use a name, like wiki.home.example. | focus |
| `host.hostname.taken` | hostname | {hostname} is already a host. | "Open {hostname}" (edit form) |
| `host.upstreams.missing` | upstreams | Enter where Ianitor should send traffic, like http://10.0.0.23:3000. | focus |
| `host.upstream.not_url` | upstreams[i] | Write it as a full address, like http://10.0.0.23:3000. | focus |
| `host.upstream.scheme` | upstreams[i] | Start the address with http:// or https://. | focus |
| `host.upstream.no_host` | upstreams[i] | Add the server's name or IP address after http://. | focus |
| `host.upstream.no_port` | upstreams[i] | Add the port at the end, like :3000. | focus |
| `host.upstream.port_zero` | upstreams[i] | Port 0 cannot be used. Enter the port the service listens on. | focus |
| `host.upstream.path` | upstreams[i] | Leave out the path after the port. Visitors keep their own path. | "Use {suggestion}" |
| `host.upstream.query` / `.fragment` | upstreams[i] | Leave out everything after ? or #. | "Use {suggestion}" |
| `host.upstream.credentials` | upstreams[i] | Leave out the user name and password. Put them in a header rule with a secret instead. | open More options → Headers |
| `host.upstream.duplicate` | upstreams[i] | This address is listed twice. | "Remove it" |
| `host.upstream.mixed_schemes` | upstreams | All addresses for one host must start the same way: all http:// or all https://. | focus |
| `host.upstream.too_many` | upstreams | One host can send traffic to at most {max} addresses. | — |
| `host.auth.not_configured` | auth | Sign-in is not set up on this server yet, so choose Anyone for now. To set it up, add the Authelia address to ianitor.toml in the routes repository. | the option is disabled up front when `site.forward_auth_configured` is false; the hint says why |
| `host.header.name` | {list}[i].name | "{name}" cannot be a header name. Use letters, digits and dashes. | focus |
| `host.header.value` | {list}[i].value | This value has characters a header cannot carry. Use visible characters and spaces only. | focus |
| `host.header.empty` | {list}[i].value | Enter a value, or choose Remove to drop the header. | switch to Remove |
| `host.header.protected` | {list}[i].name | Ianitor sets {name} itself, so a rule cannot change it. | — |
| `host.header.duplicate` | {list}[i].name | {name} already has a rule in this list. | jump to that rule |
| `host.header.both` | {list}[i] | Choose a fixed value or a secret, not both. | — |
| `host.header.remove_value` | {list}[i] | Remove needs only the header name. | clear the value |
| `host.header.secret_unknown` | {list}[i].secret | There is no secret named {secret}. Secrets are listed in ianitor.toml and loaded from the server's credentials. | picker shows `site.secrets` |
| `host.header.secret_response` | response_headers[i] | Secrets can only be sent to your service, never back to visitors. | move to request headers |
| `host.health.path` | health_check.path | Start with / and use plain characters, like /health. | focus |
| `host.health.interval` | health_check.interval_secs | Check every 1 to 3600 seconds. | focus |
| `host.field.unknown` | {field} | Ianitor does not know the setting "{field}". | (API clients only) |
| `change.conflict` | — | {hostname} was changed at {time} ("{summary}") after you opened it. Your edits are still here. Check them, then Apply again. | "Show the new version" |
| `host.not_found` | — | {hostname} is no longer a host. It was removed at {time}. | back to the list |
Warning, not an error: `host.share.no_signin`: "Anyone can already open {hostname}, so a share link changes nothing." It appears in the share dialog and the form; it doesn't block anything.
### 3.2 Apply, undo, restore, repository
| Code | Message | UI offers |
|:--|:--|:--|
| `apply.queued` | Waiting for "{summary}" to finish, about {seconds} s. | Cancel |
| `apply.kept` | {hostname} is live. Health checks passed for 60 s. Saved and sent to Gitea. | Undo |
| `apply.kept.no_watch` | {hostname} is live. It has no health check, so Ianitor only checked that it answers. | Add a health check (edit form) |
| `apply.reverted.refused` | {hostname} was not {verb}. {upstream} refused the connection on {count} of {of} checks. Ianitor undid the change; every other host kept running. | Edit and try again |
| `apply.reverted.timeout` | {hostname} was not {verb}. {upstream} did not answer within 5 seconds on {count} of {of} checks. Ianitor undid the change. | Edit and try again |
| `apply.reverted.not_found` | {hostname} was not {verb}. {upstream} says {path} does not exist. Check the health check address. Ianitor undid the change. | Edit health check |
| `apply.reverted.server_error` | {hostname} was not {verb}. {upstream} answered with an error page on {count} of {of} checks. Ianitor undid the change. | Edit and try again |
| `apply.reverted.redirect` | {hostname} was not {verb}. {upstream} sent visitors elsewhere instead of answering {path}. Use an address that answers directly, like /health. | Edit health check |
| `apply.reverted.sign_in` | {hostname} was not {verb}. {upstream} asked for a sign-in on {path}. Use an address that answers without signing in. | Edit health check |
| `apply.reverted.name` | {hostname} was not {verb}. The name {upstream_host} could not be found on this network. | Edit and try again |
| `apply.reverted.tls` | {hostname} was not {verb}. {upstream} uses https://, but its certificate could not be checked. | Edit and try again |
| `apply.failed.reload` | {engine} did not take the new settings, so nothing changed. Every host kept running. | Show details |
| `apply.failed.build` | Ianitor could not build the settings for this change, so nothing changed. | Show details |
| `apply.failed.validation` | This change no longer fits with the routes: {first_error}. Nothing changed. | Edit and try again |
| `apply.interrupted` | Ianitor restarted during the check, so it undid the change to be safe. | Try again |
| `apply.needs_attention` | The change failed its check, and Ianitor could not undo it by itself. Visitors are served the last good settings, but the routes repository still has the change. | Restore last kept version (1 click, `POST /restore` with `undo.target`) |
| `push.failed.unreachable` | Kept, but not yet saved to Gitea: Gitea did not answer. Ianitor tries again at {time}. | Try now |
| `push.failed.rejected` | Kept, but Gitea has changes Ianitor does not have, so nothing was sent. Nothing is lost on this server. | Show details |
| `push.failed.auth` | Kept, but Gitea refused Ianitor's access key. Check the key in Custos. | Try now |
| `undo.nothing` | Nothing to undo yet. | — |
| `undo.watching` | Wait for the check to finish ({seconds} s). | — |
| `undo.target_moved` | The last change is now "{summary}", so Undo did nothing. Look again and choose. | bar refreshes |
| `restore.same` | This version is the same as the current one. Nothing to restore. | Close |
| `restore.not_kept` | This change was undone at the time, so there is nothing to go back to. | Edit and try again |
| `repo.unreadable` | {file} in the routes repository cannot be read (line {line}). Changes are paused until it is fixed. | Show details |
`{verb}` is "added", "changed" or "removed", from the change kind. `{engine}` is "Pingora" or "Caddy"; product names are allowed.
### 3.3 Host health lines (main screen) and visitor errors
| `failure.kind` | Row line |
|:--|:--|
| `refused` | Connection refused for {duration}. Visitors see a "not reachable" page. |
| `timeout` | Not answering for {duration}. Visitors see a "not reachable" page. |
| `name` | The name {upstream_host} cannot be found. Visitors see a "not reachable" page. |
| `tls` | The certificate of {upstream} cannot be checked. |
| `bad_answer` | Answering with an error page for {duration}. |
| partial (degraded) | {n} of {m} addresses answer. Visitors are sent to the ones that do. |
| `unknown` | No health check set for this host. |
| `pending` | Waiting for the first check. |
| cert `pending` | Waiting for Let's Encrypt to issue the certificate. |
| cert `failed` | Let's Encrypt could not confirm {hostname}. The name must point to this server, and port 80 must be open from the internet. — offers Try again |
| `health.unavailable` (global) | Ianitor cannot read health from {engine} right now. Traffic is not affected. |
### 3.4 Share links
Admin side:
| Code | Message | UI offers |
|:--|:--|:--|
| `share.disabled` | Share links are off for {hostname}. Turning them on is a change to the host, checked like any other. | Turn on share links and apply |
| `share.prefix` | Start with /, like /share/summer-2026. / shares the whole site. | focus |
| `share.expiry` | Choose between 1 hour and 90 days. | — |
| `share.password_short` | Use at least 8 characters. | focus |
| `share.stopped` | Stopped. The link stops working within a few seconds. | — |
| `share.stopped_all` | All share links are stopped. New ones work as usual. | — |
| `share.engine_caddy` | Share links are paused while Caddy serves. They work again after switching back. (Only if G7 is not solved.) | — |
Visitor side (pages in §4):
| Code | Heading | Text | Offers |
|:--|:--|:--|:--|
| `share.visit.password` | This link is protected | Someone shared {hostname} with you. Enter the password they gave you. | Password field, Open |
| `share.visit.wrong_password` | (same page) | That password is not right. Check it with the person who sent the link. | field cleared and focused |
| `share.visit.too_many` | (same page) | Too many tries. Wait a minute, then try again. | button disabled |
| `share.visit.expired` | This link has expired | It worked until {date}. Ask the person who sent it for a new one. | Have an account? Sign in |
| `share.visit.invalid` (stopped, altered, other host, share links turned off) | This link no longer works | It may have been stopped, or not copied in full. Ask the person who sent it for a new one. | Have an account? Sign in |
| outside the prefix | — (no page) | the request goes to the normal sign-in, as if there were no link | — |
| `visit.unreachable` | This site is not reachable right now | The service behind this address is not answering. It is not your connection. Try again in a few minutes. | Try again |
Don't tell "stopped" apart from "altered": both use `invalid`. "Expired" is told apart because the signature proves the date.
### 3.5 API tokens, sign-in, limits, connection
| Code | Message | Who sees it | Offers |
|:--|:--|:--|:--|
| `token.missing` | This request needs an API token. Make one in Settings, API. | script | — |
| `token.unknown` | This API token is not one Ianitor issued, or it was copied incompletely. | script | — |
| `token.expired` | This API token expired on {date}. Make a new one in Settings, API, then revoke this one. | script | — |
| `token.revoked` | This API token was revoked on {date}. | script | — |
| `token.created` | Copied. Paste it into Custos now. Ianitor cannot show it again. | UI | Copy again, I have saved it |
| `token.revoke_done` | Revoked. Anything using "{name}" stops working now. | UI | — |
| `rate.limited` | Too many requests in a short time. Try again in {seconds} s. | both; UI retries once by itself first | — |
| `ui.signed_out` | Your sign-in has ended. Sign in again; this page keeps what you typed. | UI | Sign in |
| `ui.lost_contact` | Ianitor's control service is not answering. Traffic keeps flowing; changes wait until it is back. | UI | retries every 5 s |
| `control.paused` | Changes are paused: {reason}. Traffic keeps flowing. | UI | per reason |
Detecting sign-out: when Authelia's session ends, edge returns its portal redirect as is. The UI uses `fetch(..., {redirect: "manual"})` and treats an `opaqueredirect` or a `401` as `ui.signed_out`. Nothing from control is needed.
Rate limits [J]: 120 requests a minute per signed-in user or token; share-link mint 30 a minute; token creation 10 an hour. Wrong share passwords: 5 a minute per link and visitor /24. Answers carry `retry_after_s`.
### 3.6 PKI (Phase 3)
| Code | Message | Offers |
|:--|:--|:--|
| `pki.waiting` | Open Custos on your phone. Approve only if it shows the same code: {code}. | Cancel request |
| `pki.denied` | The request was turned down in Custos. Nothing was issued. | Try again |
| `pki.expired` | Nobody approved it within 10 minutes, so the request closed. Nothing was issued. | Try again |
| `pki.custos_unreachable` | Custos is not answering, so the request could not be sent. | Try again |
| `pki.device_name_taken` | A device named "{name}" already has a certificate. Use another name, or revoke the old one first. | Show it |
| `pki.issued` | {name} has a certificate. Approved in Custos at {time}. | Show QR code, Download file |
| `pki.bundle_used` | This download was already used. Make a new one from the device's row. | — |
| `pki.renew_due` | The Domi intermediate certificate expires in {days} days, on {date}. | Renew |
| `pki.renew_urgent` | The Domi intermediate certificate expires in {days} days. After that, Domi certificates stop working. | Renew |
| `pki.intermediate_expired` | The Domi intermediate certificate expired on {date}. Hosts with a Domi certificate are not trusted until it is renewed. | Renew |
| `pki.renewed` | Renewed. The Domi intermediate certificate is now valid until {date}. | — |
## 4. Share-link visitor pages (served by edge)
These are four pages: password prompt (with its wrong-password and too-many states), link expired, link no longer works, and service not reachable.
**Build constraints**
- One self-contained HTML file per page with inline CSS, under 8 KB. No JavaScript, no external requests, no web fonts. These pages must work on a visitor's phone with nothing else loaded. System font stack: `system-ui, -apple-system, "Segoe UI", Roboto, sans-serif`.
- Headers: `Cache-Control: no-store`, `Referrer-Policy: no-referrer`, `X-Robots-Tag: noindex`, `Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline'; form-action 'self'`. `lang="en"`. Status codes are not visible to visitors: prompt 401, expired 410, invalid 403, not reachable 502.
- Password form: `POST` to a reserved path `/.well-known/ianitor/share` with hidden `t` (the token) and `password`. On success, edge sets an HttpOnly, Secure, SameSite=Lax cookie scoped to the host and `path_prefix` until the link's expiry. It then redirects to the prefix *without* `?share=` so the token never sits in the address bar or a referrer. A link without a password takes the same redirect at once.
- Only the hostname and the expiry date come from the request. Escape both. Nothing else from the request is echoed.
**Layout** (murex palette, same on all four)
- `body`: background `#0c0b0f` (ground), text `#f1edf3`, margin 0. Centre one card vertically and horizontally; on a phone it sits 16 px from each edge.
- Card: max-width 420 px, padding 32 px (24 px under 480 px wide), background `#18151d` (surface), border 1 px `#3c3445`, radius 18 px.
- Top of the card: the hostname in `#cfc6d4`, 0.95 rem, weight 600, the only line that changes per host. Then the heading, 1.5 rem, weight 700, `#f1edf3`. Then body text, 1 rem, line-height 1.5, `#cfc6d4`.
- A 40 px stroke icon above the heading: a lock for the prompt, a clock for expired, a broken link for invalid, a cloud with a slash for not reachable. Expired and invalid icons in `#d99a35`; not reachable in `#e2683a`; the lock in `#e0a3dc`.
- Password field: label "Password" above it, `#cfc6d4` 0.9 rem. Field height 48 px, background `#0c0b0f`, border 1 px `#7d7189`, radius 10 px, text `#f1edf3`. Focus: border `#e0a3dc` plus a 4 px ring `rgba(224,163,220,0.16)`. `autocomplete="current-password"`, `autofocus`.
- Primary button "Open": full width, 48 px high, radius 12 px. Fill: gradient top to bottom `#8d3b89` → `#76306f` 55% → `#5c2257`. Edge 1 px `#c77cc1`; label `#ffffff`, weight 700. Focus ring `#f2c9ee`.
- Error line under the field (wrong password, too many tries): `#e2683a`, 0.92 rem, with a small ring icon, announced with `role="alert"`. Never colour alone; the words carry it.
- Secondary link "Have an account? Sign in": `#e0a3dc`, underlined, 44 px tall hit area. It points to the host root without `?share=`.
- "Try again" on the not-reachable page: an outline button (border `#7d7189`, text `#f1edf3`), as a plain link to the same URL.
- Footer under the card, outside it: "IANITOR DOMI" in `#a99eb1`, 0.72 rem, letter-spacing 0.2em, uppercase. Small and plain; no other branding.
**Copy, exactly**
Password prompt:
> photos.home.example
> **This link is protected**
> Someone shared photos.home.example with you. Enter the password they gave you.
> Password [__________]
> [ Open ]
> The link works until 14 November 2026.
Wrong password: the same page, with "That password is not right. Check it with the person who sent the link." under the field, which comes back empty.
Too many tries: the same page, with "Too many tries. Wait a minute, then try again." The Open button is disabled for that response.
Link expired:
> photos.home.example
> **This link has expired**
> It worked until 14 November 2026. Ask the person who sent it for a new one.
> Have an account? Sign in
Link no longer works:
> photos.home.example
> **This link no longer works**
> It may have been stopped, or not copied in full. Ask the person who sent it for a new one.
> Have an account? Sign in
Not reachable (any host, shared or not; the main screen points to it):
> photos.home.example
> **This site is not reachable right now**
> The service behind this address is not answering. It is not your connection. Try again in a few minutes.
> [ Try again ]
## 5. Gaps, and what I recommend
| # | Gap | Recommendation |
|:--|:--|:--|
| G1 | Edge keeps health in memory with no way out [C: edge/src/health.rs keeps one healthy bit per upstream, no latency, no failure kind, no history]. The main screen, the watch and the revert reasons all need it. | Edge exposes a read-only status endpoint on a Unix socket only control can read. Per upstream: state, last check time, latency, failure kind, the last 5 results. Control caches it for `/overview`. Under Caddy, map the admin API's `/reverse_proxy/upstreams`; latency and failure kind are null there, and the UI hides them. |
| G2 | The boards show "degraded: slow, 2.8 s, limit is 2 s" and a history entry "health limit 2 s", but the schema has no latency limit (fixed 5 s timeout [C]). | No limit in v1. Degraded = some upstreams fail, or mixed results in the last 5 checks. I will correct the boards in Phase 3. |
| G3 | A host without a health check gives the 60 s watch nothing to judge, so "auto-kept or auto-reverted" is empty. A default check on / would revert apps that redirect to a login page (edge counts only 2xx as healthy [C]). | During the watch only, test each touched host without a health check by connecting and sending `GET /`; any answer below 500 counts as alive. Message `apply.kept.no_watch`. Don't add a default health check to new hosts. |
| G4 | ROADMAP doesn't say which hosts the watch judges. | Only the hosts the change touches; a host that was already down never triggers a revert. Check every 5 s during the watch. |
| G5 | Let's Encrypt issuance can take longer than 60 s and is not part of keep or revert. | Keep it out of the watch; report it as `hosts[].certificate` with its own messages and Try again. |
| G6 | Core validation errors are written per file in schema words (`{file}: upstream \`x\` is not usable: …`, "TOML") and carry no field path or stable code [C: core/src/error.rs]. | Add `code()`, `field()` and `params()` to `ValidationError`, using §3.1's codes and field paths. Keep the existing text as `detail`. The API maps code to the §3.1 message. |
| G7 | Under the Caddy fallback no one checks share tokens. Caddy cannot verify them, yet the engine popover promises "share links stay the same". | Compile share-link hosts for Caddy with `forward_auth` to a small validator on loopback, from the same core code. If that is too much for v1, show `share.engine_caddy` and change the popover copy. |
| G8 | ROADMAP revokes share links "by key rotation or a small deny list", but the key comes from systemd credentials, which control cannot rotate at runtime. A deny list that goes through the routes repo would make Stop wait 60 s and add a git commit. | Stop one link: a deny-list file outside git that edge reloads within 5 s, with no watch. Stop all: an `epoch` number inside every token and in the edge config; raising it ends every old link without changing the key. |
| G9 | "Optional password hash" inside a stateless token lets anyone holding the link guess the password offline. | The token carries only a "needs a password" flag. Edge checks `HMAC(key, link_id ‖ password)`, so guessing needs the server. Rate-limit in edge (§3.5). |
| G10 | Share link when links are off for the host: 4 clicks (handover c). Turning them on is an apply with a 60 s watch, and the clipboard needs a click after it. | Accept 4 for that path and say so in §4: "3 clicks, 4 if share links are off". The common path stays 3. |
| G11 | The link is minted when the dialog opens, so changing expiry or prefix would leave unused valid links behind. | `replaces` on the mint call stops the previous one (§1.5). |
| G12 | API token: copying is a 4th click (handover c). | Click 3 "Make and copy token" uses an async `ClipboardItem`; that needs the POST to answer in under 1 s. If Mark rejects writing a secret to the clipboard in the same click, accept 4. |
| G13 | Device cert: install is a 4th click (handover c), because approval in Custos is asynchronous. | Accept "3 to issue, +1 to install" in §4. No API change removes it. |
| G14 | The UI is identified by `Remote-User` from edge, but any local process can send that header to control on loopback. | The admin host's file sets a request header from a systemd-credential secret (an existing feature), and control requires it on every request. Alternatively, control listens on a Unix socket that only edge can reach. Plus the `X-Ianitor-UI` header against CSRF. |
| G15 | A device QR code must point to a download the tablet can reach, and control is loopback only. | A one-time download route on the admin host, served by edge to control, valid for 10 minutes and one use. Phase 3. |
| G16 | ROADMAP doesn't define Undo after an Undo. | "Revert the last kept commit" means a redo. Name it with `effect` (§2.3), so the button never surprises. |
| G17 | A reverted attempt is a commit plus a revert in git, but the UI shows one entry, and "Edit and try again" needs what was tried. | Control groups them into one history entry and keeps `attempted_host` for each reverted or failed change. |
| G18 | Engine switch: §1.6 and §3/§4 disagree (handover b). | `overview.engine` now, read only. The switch call waits on Mark's answer. |
| G19 | `websockets` defaults to true [C], so a "Websockets" chip would show on almost every row. | The UI shows a chip only when websockets are off ("No websockets"); the API needs no change. |
## 6. Where the Phase 2 API differs from this contract
Recorded by the Phase 2 implementation (branch `control/phase-2`). docs/api.md has curl
examples; `GET /api/v1/openapi.json` has every shape. Everything not listed here is built as
written above.
**Not built in Phase 2 (Phase 3 items):**
- G7: share links work only while Pingora serves. The Caddy JSON ignores `share_links`, so
under the fallback a share visitor gets the normal sign-in (fails closed). `share.engine_caddy`
is not emitted yet.
- G12, G13, G15 (clicks, device certificates and their downloads); §1.7, §1.8 and §3.6 (PKI).
- G14: control authenticates with API tokens only and trusts no `Remote-*` header; the UI in
Phase 3 needs the G14 mechanism (or a token) to call it.
- G18: `overview.engine` is read-only (`running: "pingora"`, `state: "running" | "stopped"`,
`fallback_ready: null`); no `POST /engine`.
- The "This site is not reachable right now" page (§4): edge still answers an unreachable
upstream with an empty `502`, exactly like Caddy, so the differential suite stays exact.
Serving the page needs the same page from Caddy's `handle_errors`.
- `overview.intermediate` is always `null`.
**Shapes and behaviour that differ:**
- Apply states: there is no `interrupted` state. An apply cut off by a control restart ends as
`reverted` with `reason.code = "apply.interrupted"`; one that was still queued ends as
`failed` with `apply.interrupted.queued`; a cancelled one as `failed` with `apply.cancelled`.
- A change identical to what is live is refused with `409 change.unchanged` instead of
becoming a no-op apply.
- `reason` is `{code, message, hostname, upstream, field, count, of, detail, params}`; an
apply also carries `errors[]`, the full `commit`, `effect` (undo), `actor` (token name) and
`attempted_host`. `push` is present only on kept applies; with no remote configured the
`push` step is `skipped`.
- `apply.kept` says "Health checks passed for {seconds} s." only; the push result is in
`push` / `repo`, not in that sentence. Extra codes: `apply.kept.no_watch` (host without a
health check), `apply.kept.removed`, `apply.kept.no_edge` (dev mode without a proxy),
`apply.reverted.no_answer`, `apply.reverted.edge_lost` (edge restarted or vanished during
the watch), `apply.failed.edge_unreachable`.
- The watch: touched hosts are probed every `watch_every_secs` (5 s by default). A touched host
is reverted when every one of its upstreams failed its last 3 checks, or none passed its
last check at the end; hosts that were already `down` before the change are not judged.
- `undo.blocked = undo.watching` only while an Undo itself is running; any other running apply
just queues the Undo.
- `GET /tokens` lists `id`; the id is the non-secret first part of the token
(`ian_<id>_<secret>`), so it is a prefix of the token string, but reveals nothing of the
secret. `POST /tokens` takes `{name?, expires_in_days?, never_expires?}`.
- `GET /history` entries have `reason_short` as the last word of the reason code (e.g.
"server error"), and paging uses `before=<change_id>` with `next_before` in the answer.
`GET /history/{id}` returns the full apply.
- `GET /history/{id}/restore-preview` field keys are `hostname`, `upstreams`, `tls`, `auth`,
`websockets`, `share_links`, `access_log`, `health_check.path`,
`health_check.interval_secs` and `headers`; it also has `blocked` (`restore.same`,
`restore.not_kept`).
- Share-link mint answers include `warning` (`host.share.no_signin`) for a host without
sign-in. The token is in `?share=`; edge only takes values starting `ish1.`, so an
upstream's own `share` parameter still works. The password page's "too many tries" answer
is `429`. For a password link the expired page is decided from the token's (unproven) date,
because nothing in the token can be proven before the password is given.
- `overview.site.acme_configured` is always `true` (Let's Encrypt is the default issuer);
extra fields `overview.rev`, `overview.health_error` and `site.share_links_available`.
- Health: one admin Unix socket (mode 0660) carries both the read-only `GET /v1/status` and
control's reload/trial calls, instead of a separate read-only socket. Edge keeps the last 5
results per upstream; `health.since` is tracked by control and restarts with it.
- `Idempotency-Key`s are remembered in memory for 24 h; a control restart forgets them.
- Extra error codes: `change.unchanged`, `host.hostname.mismatch`, `host.upstream.host_name`,
`request.*`, `repo.unexpected_file`, `repo.no_remote`, `share.unavailable`,
`share.not_found`, `share.replaces`, `share.password_long`, `token.not_found`, `token.name`,
`token.expiry`, `file.*`, `site.*` (problems in `ianitor.toml`).