Files
ianitor/crates/control/src/messages.rs
T

415 lines
22 KiB
Rust
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.
// SPDX-License-Identifier: CPAL-1.0
// Copyright (c) 2026 Marek Novák. Part of Ianitor, under the Common Public Attribution
// License 1.0: see LICENSE (its Exhibit A is this file's notice).
//! Every user-facing message, by code, in the words of docs/ui-api.md §3. `{x}` is filled from
//! the params; a missing param leaves a plain gap rather than a placeholder.
use std::collections::BTreeMap;
pub type Params = BTreeMap<String, String>;
fn template(code: &str) -> &'static str {
match code {
// 3.1 host form
"host.hostname.missing" => "Enter the address people will type, like wiki.home.example.",
"host.hostname.uppercase" => "Use lowercase letters only: {suggestion}.",
"host.hostname.characters" => "Use only letters a–z, digits, dots and dashes.",
"host.hostname.spaces" => "Remove the spaces from the address.",
"host.hostname.wildcard" => {
"Addresses with * are not supported yet. Add each name as its own host."
}
"host.hostname.trailing_dot" => "Remove the dot at the end.",
"host.hostname.empty_label" => "There are two dots in a row. Remove one.",
"host.hostname.label_dash" => "A part of the address cannot start or end with a dash.",
"host.hostname.label_long" => "Each part between dots can be at most 63 characters.",
"host.hostname.too_long" => "The address can be at most 253 characters.",
"host.hostname.numeric" => {
"That looks like an IP address. Use a name, like wiki.home.example."
}
"host.hostname.taken" => "{hostname} is already a host.",
"host.hostname.mismatch" => {
"The address in the form ({hostname}) is not the host you are editing ({path_hostname})."
}
"host.file_name" => "The address does not match the file it is stored in.",
"host.upstreams.missing" => {
"Enter where Ianitor should send traffic, like http://10.0.0.23:3000."
}
"host.upstream.not_url" => "Write it as a full address, like http://10.0.0.23:3000.",
"host.upstream.scheme" => "Start the address with http:// or https://.",
"host.upstream.unix_path" => {
"Write a socket as unix:/absolute/path.sock, with letters, digits, dots, dashes and underscores only."
}
"host.upstream.unix_socket" => {
"Only the web UI's admin host can use a socket, and only control's own ([ui] socket in control.toml)."
}
"host.upstream.no_host" => "Add the server's name or IP address after http://.",
"host.upstream.host_name" => {
"The server name is not usable. Use letters a–z, digits, dots and dashes, or an IP address."
}
"host.upstream.no_port" => "Add the port at the end, like :3000.",
"host.upstream.port_zero" => {
"Port 0 cannot be used. Enter the port the service listens on."
}
"host.upstream.path" => "Leave out the path after the port. Visitors keep their own path.",
"host.upstream.query" | "host.upstream.fragment" => "Leave out everything after ? or #.",
"host.upstream.credentials" => {
"Leave out the user name and password. Put them in a header rule with a secret instead."
}
"host.upstream.duplicate" => "This address is listed twice.",
"host.upstream.mixed_schemes" => {
"All addresses for one host must start the same way: all http:// or all https://."
}
"host.upstream.too_many" => "One host can send traffic to at most {max} addresses.",
"host.auth.not_configured" => {
"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."
}
"host.header.name" => "\"{name}\" cannot be a header name. Use letters, digits and dashes.",
"host.header.value" => {
"This value has characters a header cannot carry. Use visible characters and spaces only."
}
"host.header.empty" => "Enter a value, or choose Remove to drop the header.",
"host.header.protected" => "Ianitor sets {name} itself, so a rule cannot change it.",
"host.header.duplicate" => "{name} already has a rule in this list.",
"host.header.both" => "Choose a fixed value or a secret, not both.",
"host.header.remove_value" => "Remove needs only the header name.",
"host.header.secret_unknown" => {
"There is no secret named {secret}. Secrets are listed in ianitor.toml and loaded from the server's credentials."
}
"host.header.secret_response" => {
"Secrets can only be sent to your service, never back to visitors."
}
"host.health.path" => "Start with / and use plain characters, like /health.",
"host.health.interval" => "Check every 1 to 3600 seconds.",
"host.field.unknown" => "Ianitor does not know the setting \"{field}\".",
"host.field.invalid" | "file.field.invalid" => {
"One of the settings has a value Ianitor cannot use. Show details to see which."
}
"file.field.missing" => "The setting \"{field}\" is missing.",
"change.conflict" => {
"{hostname} was changed at {time} (\"{summary}\") after you opened it. Your edits are still here. Check them, then Apply again."
}
"change.unchanged" => "This is the same as what is live now, so nothing changed.",
"host.not_found" => "{hostname} is no longer a host.",
"host.share.no_signin" => {
"Anyone can already open {hostname}, so a share link changes nothing."
}
// 3.2 apply, undo, restore, repository
"apply.queued" => "Waiting for \"{summary}\" to finish, about {seconds} s.",
"apply.kept" => "{hostname} is live. Health checks passed for {seconds} s.",
"apply.kept.no_watch" => {
"{hostname} is live. It has no health check, so Ianitor only checked that it answers."
}
"apply.kept.removed" => "{hostname} is removed.",
"apply.kept.no_edge" => {
"Saved. No proxy is attached (development mode), so nothing was checked."
}
"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."
}
"apply.reverted.timeout" => {
"{hostname} was not {verb}. {upstream} did not answer within 5 seconds on {count} of {of} checks. Ianitor undid the change."
}
"apply.reverted.not_found" => {
"{hostname} was not {verb}. {upstream} says {path} does not exist. Check the health check address. Ianitor undid the change."
}
"apply.reverted.server_error" => {
"{hostname} was not {verb}. {upstream} answered with an error page on {count} of {of} checks. Ianitor undid the change."
}
"apply.reverted.redirect" => {
"{hostname} was not {verb}. {upstream} sent visitors elsewhere instead of answering {path}. Use an address that answers directly, like /health."
}
"apply.reverted.sign_in" => {
"{hostname} was not {verb}. {upstream} asked for a sign-in on {path}. Use an address that answers without signing in."
}
"apply.reverted.name" => {
"{hostname} was not {verb}. The name {upstream_host} could not be found on this network."
}
"apply.reverted.tls" => {
"{hostname} was not {verb}. {upstream} uses https://, but its certificate could not be checked."
}
"apply.reverted.no_answer" => {
"{hostname} was not {verb}. No health check finished within {seconds} s. Ianitor undid the change."
}
"apply.reverted.edge_lost" => {
"The proxy restarted during the check, so it went back to the last good settings. Ianitor undid the change to match."
}
"apply.failed.reload" => {
"{engine} did not take the new settings, so nothing changed. Every host kept running."
}
"apply.failed.build" => {
"Ianitor could not build the settings for this change, so nothing changed."
}
"apply.failed.validation" => {
"This change no longer fits with the routes: {first_error} Nothing changed."
}
"apply.failed.edge_unreachable" => {
"Ianitor cannot reach the proxy right now, so nothing changed. Traffic is not affected."
}
"apply.interrupted" => {
"Ianitor restarted during the check, so it undid the change to be safe."
}
"apply.interrupted.queued" => {
"Ianitor restarted before this change ran, so nothing changed. Try again."
}
"apply.cancelled" => "Cancelled before it started. Nothing changed.",
"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."
}
"push.failed.unreachable" => {
"Kept, but not yet saved to {remote}: {remote} did not answer. Ianitor tries again at {time}."
}
"push.failed.rejected" => {
"Kept, but {remote} has changes Ianitor does not have, so nothing was sent. Nothing is lost on this server."
}
"push.failed.auth" => {
"Kept, but {remote} refused Ianitor's access key. Check the key in Custos."
}
"undo.nothing" => "Nothing to undo yet.",
"undo.watching" => "Wait for the check to finish ({seconds} s).",
"undo.paused" => "Changes are paused, so Undo is not available.",
"undo.target_moved" => {
"The last change is now \"{summary}\", so Undo did nothing. Look again and choose."
}
"restore.same" => "This version is the same as the current one. Nothing to restore.",
"restore.not_kept" => {
"This change was undone at the time, so there is nothing to go back to."
}
"change.not_found" => "There is no change with that id.",
"repo.unreadable" => {
"{file} in the routes repository cannot be read. Changes are paused until it is fixed."
}
"repo.unexpected_file" => "{file} does not belong in the routes repository.",
"repo.no_remote" => "No place to push to is set up.",
// 3.4 share links
"share.disabled" => {
"Share links are off for {hostname}. Turning them on is a change to the host, checked like any other."
}
"share.prefix" => "Start with /, like /share/summer-2026. / shares the whole site.",
"share.expiry" => "Choose between 1 hour and 90 days.",
"share.password_short" => "Use at least 8 characters.",
"share.password_long" => "Use at most 128 characters.",
"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.unavailable" => {
"Share links are not set up on this server: the share-link key is missing from the credentials."
}
"share.too_many" => {
"There are 2,000 active share links already. Stop some, or stop all, then try again."
}
"share.not_found" => "There is no share link with that id.",
"share.replaces" => "The link to replace is not a link for {hostname}.",
// 3.5 tokens, limits
"token.missing" => "This request needs an API token. Make one in Settings, API.",
"token.unknown" => {
"This API token is not one Ianitor issued, or it was copied incompletely."
}
"token.expired" => {
"This API token expired on {date}. Make a new one in Settings, API, then revoke this one."
}
"token.revoked" => "This API token was revoked on {date}.",
"token.not_found" => "There is no API token with that id.",
"token.name" => "Use 1 to 64 letters, digits, spaces, dots, dashes or underscores.",
"token.expiry" => "Choose between 1 and 3650 days, or never.",
"rate.limited" => "Too many requests in a short time. Try again in {seconds} s.",
"control.files_unwritten" => {
"The change is live, but Ianitor could not save the proxy settings to disk. Changes are paused until Ianitor restarts and saves them."
}
"control.paused" => "Changes are paused: {reason} Traffic keeps flowing.",
// request shape
"request.body" => "The request body is not valid: {problem}",
"request.body_unknown_field" => "Ianitor does not know the field \"{field}\".",
"request.too_large" => "The request body is too large.",
"request.csrf" => {
"This request came from a browser page without Ianitor's UI header, so it was refused."
}
"request.host" => "This request was sent to an address Ianitor does not answer on.",
"request.not_found" => "There is no such API call.",
"request.method" => "This API call does not take that method.",
"request.in_progress" => {
"The first request with this Idempotency-Key is still being handled. Try again in a moment."
}
"request.idempotency" => "This Idempotency-Key was already used for a different request.",
"request.base_rev" => "base_rev is not a commit in the routes history.",
"health.unavailable" => {
"Ianitor cannot read health from {engine} right now. Traffic is not affected."
}
// 3.6 PKI
"pki.waiting" => {
"Open Custos on your phone. Approve only if it shows the same code: {code}."
}
"pki.waiting.manual" => {
"Approve it on the server: run ianitor-control pki approve {code}. Approve only if the code matches."
}
"pki.renew.manual" => {
"Sign this request on the offline computer and check that its fingerprint matches (Sign by hand shows both), then install the certificate."
}
"pki.denied" => "The request was turned down. Nothing was issued.",
"pki.expired" => "Nobody approved it in time, so the request closed. Nothing was issued.",
"pki.custos_unreachable" => "Custos is not answering, so the request could not be sent.",
"pki.device_name_taken" => {
"A device with this name already has a certificate or an open request. Use another name, or revoke the old one first."
}
"pki.device_name" => "Give the device a name of 1 to 64 characters.",
"pki.device_kind" => "Choose phone, computer or app.",
"pki.issued" => "{name} has a certificate.",
"pki.bundle_used" => {
"This download was already used or has expired. Make a new one from the device's row."
}
"pki.renew_due" => "The Domi intermediate certificate expires in {days} days, on {date}.",
"pki.renew_urgent" => {
"The Domi intermediate certificate expires in {days} days. After that, Domi certificates stop working."
}
"pki.intermediate_expired" => {
"The Domi intermediate certificate has expired. Hosts with a Domi certificate are not trusted until it is renewed."
}
"pki.renewed" => "Renewed. The Domi intermediate certificate is now valid until {date}.",
"pki.not_configured" => {
"The Domi certificate authority is not set up on this server. See docs/pki.md."
}
"pki.no_password" => {
"The password for the Domi certificate keys is missing from the server's credentials, so nothing can be issued."
}
"pki.wrong_password" => {
"The password for the Domi certificate keys does not open them. Check the pki-password credential."
}
"pki.no_intermediate" => {
"There is no Domi intermediate certificate yet, so Domi certificates cannot be issued. Set it up first in Certificates."
}
"pki.not_our_root" => {
"This certificate was not signed by the Domi root this server trusts."
}
"pki.wrong_key" => {
"This certificate was made for another request. Sign the request shown here, then try again."
}
"pki.bad_certificate" => {
"This is not a Domi intermediate certificate Ianitor can use. It must be a CA with path length 0 that is valid now."
}
"pki.request_not_found" => "There is no such request.",
"pki.request_closed" => "This request is closed. Start a new one.",
"pki.wrong_code" => "That code does not match the request.",
"pki.too_many_requests" => "Too many requests are open. Finish or cancel some first.",
"pki.device_not_found" => "There is no such device.",
"pki.device_not_valid" => {
"This device's certificate is revoked or expired, so it cannot be installed. Issue a new one."
}
"pki.revoked" => {
"Revoked. {name} can no longer reach hosts that need a device certificate."
}
// UI sign-in
"ui.no_proof" => {
"This request carries a sign-in header but did not come through Ianitor's proxy, so it was refused."
}
"ui.no_user" => "The sign-in did not say who you are. Sign in again.",
// engine switch
"engine.unmanaged" => {
"This server does not let Ianitor switch engines (no engine settings in control.toml)."
}
"engine.same" => "{engine} is already serving.",
"engine.switching" => "A switch is already running. Wait for it to finish.",
"engine.busy" => "A change is being applied. Switch when it has finished.",
"engine.switched" => "{engine} is serving now.",
"engine.switch_failed" => {
"{engine} did not start, so Ianitor went back to {previous}. Traffic is served as before."
}
"host.header.proof" => {
"Only a host behind sign-in can send the ui-proof secret. Choose Sign in first, or remove the rule."
}
"host.header.proof_host" => {
"Only the web UI's admin host can send the ui-proof secret, and {hostname} is not it ([ui] hostname in control.toml)."
}
"pki.manual.not_ca" => {
"This certificate cannot sign other certificates. Sign it again with the signing settings file (.ext)."
}
"pki.manual.eku" => {
"This certificate is limited to some uses, so it could not issue both host and device certificates. Sign it again with the signing settings file (.ext)."
}
"pki.manual.dates" => {
"This certificate is not valid yet, has already expired, or lasts longer than the Domi root. Check the offline computer's clock and use -days 365."
}
"pki.devices_unwritten" => {
"The device list could not be saved or handed to the proxy, so the change is not in force yet. Ianitor keeps trying; try again in a moment."
}
"engine.not_ready" => {
"Caddy is not ready: its settings could not be built from the current routes."
}
// The eight codes the UI hand-off gave sentences for (handoff §12.2, decision Q12).
"repo.duplicate_file" => {
"Two files in the routes repository describe {hostname}. Remove one, then Ianitor picks it up."
}
"file.syntax" => {
"{file} in the routes repository has a typing mistake. Changes are paused until it is fixed."
}
"file.too_large" => {
"{file} in the routes repository is too large to read. Changes are paused until it is fixed."
}
"site.field.unknown" => "ianitor.toml has a setting Ianitor does not know: \"{field}\".",
"site.forward_auth" => {
"The sign-in settings in ianitor.toml cannot be used. Show details to see why."
}
"site.forward_auth.header" => {
"ianitor.toml asks sign-in to pass on \"{name}\", which cannot be a header name."
}
"site.secret.name" => {
"\"{name}\" cannot be a secret name in ianitor.toml. Use letters, digits, dashes and underscores."
}
"site.acme" => {
"The Let's Encrypt settings in ianitor.toml cannot be used. Show details to see why."
}
"share.engine_caddy" => {
"Share links are paused while Caddy serves. They work again after switching back."
}
"internal" => "Something went wrong inside Ianitor control. Show details for more.",
_ => "Something went wrong.",
}
}
/// The message for `code`, with params filled in.
pub fn message(code: &str, params: &Params) -> String {
let t = template(code);
let mut out = String::with_capacity(t.len() + 32);
let mut rest = t;
while let Some(start) = rest.find('{') {
out.push_str(&rest[..start]);
let after = &rest[start + 1..];
match after.find('}') {
Some(end) => {
let key = &after[..end];
if let Some(v) = params.get(key) {
out.push_str(v);
}
rest = &after[end + 1..];
}
None => {
out.push_str(&rest[start..]);
rest = "";
}
}
}
out.push_str(rest);
out
}
pub fn params<const N: usize>(pairs: [(&str, String); N]) -> Params {
pairs.into_iter().map(|(k, v)| (k.to_owned(), v)).collect()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn placeholders_are_filled() {
let p = params([("hostname", "a.test".into()), ("max", "64".into())]);
assert_eq!(
message("host.hostname.taken", &p),
"a.test is already a host."
);
assert_eq!(
message("host.upstream.too_many", &p),
"One host can send traffic to at most 64 addresses."
);
assert!(!message("token.revoked", &Params::new()).contains('{'));
}
}