Build packages / CI (push) Blocked by required conditions
Build packages / Version (push) Waiting to run
CI / Web (format, types, tests, bundles) (push) Blocked by required conditions
CI / ShellCheck (push) Blocked by required conditions
CI / ucode static checks (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 24.10) (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 25.12) (push) Blocked by required conditions
- Every field says what is wrong as you type, in the router's own words,
and Save refuses what the router would: UDP port when editing a server,
MTU, keep-alive, public address, DNS for devices, person name, device
limit, end date and data limit, device names (the next free "Phone 2"
is offered), home services, circles, portal title, redirect and other
addresses, defaults, update time
- Cyrillic names give Latin ids, hostnames and file names; names are
counted in characters, the rule names the characters it refuses; end
dates must exist on the calendar; a mistyped extra portal address is
refused instead of dropped
- The public address is checked on the router as it is typed: points at
this router, at another address, behind Cloudflare, or the WAN is
private or CGNAT; the wizard says so before the first step, never
pre-fills a private WAN address and says where its suggestion came
from; the Connection card says when the server was last reached from
the internet; IPv6 names and literals work throughout
- A person can be moved to another server from their page; a server's
tunnel network can be changed in the Danger zone (devices are
renumbered and marked "Update config"); WAN and LAN zones come from the
router's actual devices; when the public IPv4 changed, one click puts
the new one in
- Over the data limit or outside the allowed hours the tunnel stays
connected and the portal explains why nothing gets through, instead of
a silent handshake failure; Health's "devices loaded" compares the
peers themselves, not their count
- Portal: install links for this platform, two first steps on a first
visit, the phone's back button closes a sheet, the file goes through
the share sheet into the app, two QR codes (AmneziaVPN camera, AmneziaWG
and WireGuard apps), the sheet notices the first connection
- Admin: Enter submits a dialog, arrow keys walk the menus, Find in People
("/" focuses it), a device of a paused, ended or over-limit person says
so, "Keep access" past its end date is said on the Overview, Allowed
hours enforce nothing until saved, the invite card shares the link
- Health warns when another package's policy routing (mwan3, pbr) sends
tunnel traffic past the home-device path
- CLI: person ls, device ls, log with -n, --since, --level, --src and
--json; exit code 2 for an unknown command and 1 when health finds an
error; person rm asks for --yes when devices would go; devices added
from the command line get their event and "issued" marker like the
UI's
- Three disguises: Off, Balanced and Maximum. Standard and Strong (1.0-style
junk only, which networks learned to spot) are no longer offered; a server
still on one keeps running and its card says to switch. A new server gets
the strongest disguise its router can run
- Portal: setting up a device is one sheet with two steps. Get the app
(AmneziaVPN first; AmneziaWG, and WireGuard with the disguise off, behind
"Another app") from the store of the device in hand, with the GitHub release
where no store has it and the version the server needs said once; then add
the connection (open in AmneziaVPN, copy the key, share or download the
file). A device set up from another device gets its link to take there, as a
QR code for a phone; a phone set up from a computer also gets the connection
as a code, one code revealed at a time so the camera cannot read the wrong one
- Portal motion: the first visit comes in once (blocks in reading order,
meters fill, the sun rises in the logo); a repaint glides cards to their
new places and brings changed values into focus; sheets slide up on
phones and can be pulled down, come into focus on a computer, follow
their content's height and turn into the next sheet in place; tabs and
segments slide, menus, tooltips and toasts grow out of what opened them,
copy buttons turn into a check, buttons waiting for the router spin;
with reduced motion only the fades remain
- Portal: while a device is set up, a card at the top shows the way from
it to the router with a light running along it; on the first connection
the way fills green, the steps fold away and the sheet closes by itself.
The first connection is the first fresh handshake, so it is no longer
missed while the watcher catches up (or after new keys), and the device's
card goes on to Connected
- Portal: QR codes are light dots on a black card, fuller on dense keys,
with "Show a light code" for scanners that read only dark on light (every
code switches, the choice is kept); the link and code a set-up sheet
hands to another device open that device's set-up there at once
- Portal: Remove and New keys ask in a small alert with the action's icon;
the open one of two cards is not a button; device names are no longer
repeated in every line of the set-up sheet; the code card lines up with
the rest of its card (a class clash gave it the page's padding); text
keeps the arrow cursor, store badges and link buttons are not underlined
131 lines
4.5 KiB
Ucode
131 lines
4.5 KiB
Ucode
// Dawnline — what the rpcd method modules (dawnline.rpc.*) share: the call
|
||
// wrapper, argument helpers, the disguise check and the portal port check.
|
||
|
||
import * as core from 'dawnline.core';
|
||
import * as awg from 'dawnline.awg';
|
||
import * as health from 'dawnline.health';
|
||
import * as schema from 'dawnline.schema';
|
||
import { uniq } from 'dawnline.util';
|
||
|
||
/**
|
||
* An rpcd handler from fn(args): an object result is passed on, anything else
|
||
* is wrapped as { result }, and a failure becomes { error } (the UI shows it).
|
||
*/
|
||
export function wrap(fn) {
|
||
return function(req) {
|
||
try {
|
||
let r = fn(req.args ?? {});
|
||
return type(r) == 'object' ? r : { result: r };
|
||
}
|
||
catch (e) {
|
||
return { error: e.message ?? `${e}` };
|
||
}
|
||
};
|
||
};
|
||
|
||
/** An argument as a trimmed string ('' for null). */
|
||
export function str(v) {
|
||
return v == null ? '' : trim(`${v}`);
|
||
};
|
||
|
||
/** Days of history a caller may ask for: 1–400, default 30. */
|
||
export function clamp_days(v) {
|
||
let n = +(v ?? 30);
|
||
return n >= 1 ? (n > 400 ? 400 : int(n)) : 30;
|
||
};
|
||
|
||
export const METHODS = [ 'off', 'balanced', 'max' ];
|
||
|
||
/** The disguise a new server gets: the strongest this router can run. */
|
||
export function default_method() {
|
||
let c = awg.caps();
|
||
return c.v3 ? 'max' : c.v2 ? 'balanced' : 'off';
|
||
};
|
||
|
||
/** A disguise method the installed AmneziaWG can run. */
|
||
export function check_method(name) {
|
||
if (index(METHODS, name) < 0)
|
||
die('Unknown disguise method.');
|
||
let c = awg.caps();
|
||
if (name == 'max' && !c.v3)
|
||
die(awg.installed()
|
||
? 'Maximum needs AmneziaWG 3.1 on the router (kmod-amneziawg, amneziawg-tools 3.1): install a 3.1 build in Dawnline → Components.'
|
||
: 'AmneziaWG is not installed: install it in Dawnline → Components, then choose Maximum.');
|
||
if (name == 'balanced' && !c.v2)
|
||
die(awg.installed()
|
||
? 'Balanced needs AmneziaWG 2.0 or newer on the router: install a current build in Dawnline → Components.'
|
||
: 'AmneziaWG is not installed: install it in Dawnline → Components, then choose Balanced.');
|
||
return name;
|
||
};
|
||
|
||
/**
|
||
* The portal's ports in the final configuration `m` (compared with `was`,
|
||
* before the change) are acceptable: its HTTPS port and, when links on IP
|
||
* addresses use plain HTTP, the next port too — both get a WAN ACCEPT rule.
|
||
* Neither may be 22, 53, 80 or 443, beyond 65535, or taken by another program.
|
||
*/
|
||
/** TCP port forwards from the servers' WAN zones: [{ from, to, name }]. */
|
||
function tcp_forwards(m) {
|
||
let out = [];
|
||
for (let z in uniq([ 'wan', ...map(values(m.servers), (s) => s.wan_zone) ]))
|
||
push(out, ...core.wan_forwards(z, 'tcp'));
|
||
return out;
|
||
}
|
||
|
||
/**
|
||
* TCP ports the portal can't take, and who holds them: [{ from, to, who }].
|
||
* The router's own (22, 53, 80, 443), other programs and port forwards from WAN.
|
||
*/
|
||
export function tcp_taken(m) {
|
||
let out = [];
|
||
let held = {};
|
||
let hold = (p, who) => {
|
||
if (!held[p]) {
|
||
held[p] = true;
|
||
push(out, { from: p, to: p, who });
|
||
}
|
||
};
|
||
for (let p in schema.RESERVED_PORTS)
|
||
hold(p, 'the router itself');
|
||
for (let p, name in health.tcp_port_programs())
|
||
hold(+p, `${name} on this router`);
|
||
for (let f in tcp_forwards(m))
|
||
push(out, { from: f.from, to: f.to, who: `port forward “${f.name}”` });
|
||
return out;
|
||
};
|
||
|
||
export function check_portal(m, was) {
|
||
let s = m.settings;
|
||
if (!s.portal_enabled)
|
||
return;
|
||
let port = s.portal_port;
|
||
if (!schema.valid_port(port) || index(schema.RESERVED_PORTS, port) >= 0)
|
||
die('Choose a free port between 1 and 65535 (not 22, 53, 80 or 443).');
|
||
let ports = [ port ];
|
||
if (core.portal_http(m)) {
|
||
let hp = core.portal_http_port(m);
|
||
if (!schema.valid_port(hp) || index(schema.RESERVED_PORTS, hp) >= 0)
|
||
die(`Links on IP addresses use plain HTTP on the next port (${hp}), which the portal cannot take. Choose another portal port.`);
|
||
push(ports, hp);
|
||
}
|
||
// Only ports the portal does not hold already: our own uhttpd is not an owner anyway.
|
||
let held = [];
|
||
if (was?.settings?.portal_enabled) {
|
||
push(held, was.settings.portal_port);
|
||
if (core.portal_http(was))
|
||
push(held, core.portal_http_port(was));
|
||
}
|
||
for (let p in ports) {
|
||
if (index(held, p) >= 0)
|
||
continue;
|
||
let owners = health.tcp_port_owners(p);
|
||
if (length(owners))
|
||
die(`TCP ${p} is already used by ${join(', ', owners)}.${p != port ? ' Links on IP addresses use plain HTTP on the port after the portal\'s.' : ''} Choose another portal port.`);
|
||
}
|
||
// A forwarded port never reaches the router: the portal would be unreachable.
|
||
for (let p in ports)
|
||
for (let f in tcp_forwards(m))
|
||
if (f.from <= p && p <= f.to)
|
||
die(`TCP ${p} is sent on by port forward “${f.name}”. Choose another portal port.`);
|
||
};
|