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
416 lines
16 KiB
TypeScript
416 lines
16 KiB
TypeScript
// Settings → Personal portal: the address in links (picked from what the
|
||
// router found), a preview, readiness, and the rest folded away.
|
||
|
||
import type { PortalInfo } from '../../api';
|
||
import { E } from '../../e';
|
||
import { button } from '../../ui/button';
|
||
import { cancelButton, closeModal, modal } from '../../ui/modal';
|
||
import { input, isOn, sw } from '../../ui/controls';
|
||
import { firstBad, group, liveRow, needRow, row } from '../../ui/layout';
|
||
import { hostHelp, portalPortHelp, titleHelp, urlHelp } from '../../netcheck';
|
||
import { icon } from '../../../shared/icons';
|
||
import { fmtDay } from '../../../shared/format';
|
||
import { installMissing } from '../../pkgs';
|
||
import { notify } from '../../ui/toast';
|
||
import { section, type SettingsHost } from './common';
|
||
|
||
/** Summary of the portal checks: those that failed or warn, and the worst state. */
|
||
function verdict(checks: PortalInfo['checks']) {
|
||
const shown = checks.filter((x) => x.status !== 'skip');
|
||
const bad = shown.filter((x) => x.status === 'error' || x.status === 'warn');
|
||
const worst = shown.some((x) => x.status === 'error') ? 'error' : bad.length ? 'warn' : 'ok';
|
||
return { bad, worst };
|
||
}
|
||
|
||
/** Personal portal: the address in links (picked from what the router found), a preview, readiness, and the rest folded away. */
|
||
export function portalCard(host: SettingsHost): HTMLElement {
|
||
const s = host.d.settings;
|
||
const eff = host.d.effective as Record<string, any>;
|
||
const c = host.d.cert;
|
||
const pOn = sw(eff.portal_enabled, 'Enable portal');
|
||
const port = input(s.portal_port, { placeholder: '8443', inputmode: 'numeric', class: 'cbi-input-text dl-w-port' });
|
||
const title = input(s.portal_title, { placeholder: 'Dawnline' });
|
||
const redirect = input(s.portal_redirect, { placeholder: 'Show “Not found”', class: 'cbi-input-text dl-mono' });
|
||
const other = input('', { placeholder: 'vpn.example.com or an IP', 'aria-label': 'Other address' });
|
||
const isIp = (h: string) => /^\d{1,3}(\.\d{1,3}){3}$/.test(h);
|
||
// Chosen addresses, the main one first; custom ones join the list of options.
|
||
let picked: string[] = [eff.portal_host, ...(eff.portal_alt ?? [])].filter(
|
||
(h: string, i: number, a: string[]) => h && a.indexOf(h) === i,
|
||
);
|
||
// Until the router has looked the addresses up, only the chosen ones are listed.
|
||
let found = !!host.portal;
|
||
let rows: PortalInfo['candidates'] = [];
|
||
const addRow = (h: string) => {
|
||
if (h && !rows.some((x) => x.host === h))
|
||
rows.push({ host: h, kind: isIp(h) ? 'ip' : 'name', ips: [], here: false, cloudflare: false, cert: false });
|
||
};
|
||
const takeCands = (cands: PortalInfo['candidates']) => {
|
||
// Found addresses first (best first), then the chosen and added ones the router doesn't know.
|
||
rows = [...cands, ...rows.filter((x) => !cands.some((y) => y.host === x.host))];
|
||
if (!picked.length && cands[0]) picked = [cands[0].host];
|
||
};
|
||
if (host.portal) takeCands(host.portal.candidates);
|
||
picked.forEach(addRow);
|
||
|
||
const note = (x: PortalInfo['candidates'][number]): Node =>
|
||
x.kind === 'ip'
|
||
? E('span', { class: 'dl-addr-warn' }, [icon('alert'), 'Plain HTTP: the link and VPN keys travel unencrypted'])
|
||
: E(
|
||
'span',
|
||
{ class: 'dl-sub' },
|
||
x.cloudflare
|
||
? 'Behind Cloudflare · often stalls in Russia'
|
||
: !x.ips.length
|
||
? found
|
||
? 'Your address'
|
||
: 'Checking where it points…'
|
||
: x.here
|
||
? `Points at this router${x.cert ? ' · Let’s Encrypt certificate' : ' · no certificate yet'}`
|
||
: `Points at ${x.ips.join(', ')}, not this router`,
|
||
);
|
||
const opts = E('div', { class: 'dl-addr-opts', role: 'group', 'aria-label': 'Portal addresses' });
|
||
const toggle = (h: string) => {
|
||
if (picked.includes(h)) {
|
||
if (picked.length > 1) picked = picked.filter((x) => x !== h);
|
||
} else picked = [...picked, h];
|
||
paintOpts();
|
||
paintLinks();
|
||
};
|
||
const paintOpts = () =>
|
||
dom.content(opts, [
|
||
...rows.map((x) => {
|
||
const on = picked.includes(x.host),
|
||
main = picked[0] === x.host;
|
||
return E(
|
||
'div',
|
||
{
|
||
class: `dl-addr-opt${on ? ' on' : ''}`,
|
||
role: 'checkbox',
|
||
'aria-checked': on ? 'true' : 'false',
|
||
tabindex: '0',
|
||
click: () => toggle(x.host),
|
||
keydown: (ev: KeyboardEvent) => {
|
||
if (ev.key === ' ' || ev.key === 'Enter') {
|
||
ev.preventDefault();
|
||
toggle(x.host);
|
||
}
|
||
},
|
||
},
|
||
[
|
||
E('i', { class: 'dl-addr-check' }, on ? icon('check') : ''),
|
||
E('span', { class: 'dl-stack' }, [E('span', { class: 'dl-mono' }, x.host), note(x)]),
|
||
main
|
||
? E('span', { class: 'dl-pill info' }, 'Main')
|
||
: on
|
||
? E(
|
||
'button',
|
||
{
|
||
type: 'button',
|
||
class: 'dl-linkbtn',
|
||
click: (ev: Event) => {
|
||
ev.stopPropagation();
|
||
picked = [x.host, ...picked.filter((h) => h !== x.host)];
|
||
paintOpts();
|
||
paintLinks();
|
||
},
|
||
},
|
||
'Make main',
|
||
)
|
||
: x.cloudflare
|
||
? E('span', { class: 'dl-pill warn' }, 'Cloudflare')
|
||
: x.kind === 'ip'
|
||
? E('span', { class: 'dl-pill' }, 'IP')
|
||
: x.here && x.cert
|
||
? E('span', { class: 'dl-pill ok' }, 'Recommended')
|
||
: '',
|
||
],
|
||
);
|
||
}),
|
||
E('div', { class: 'dl-addr-opt other' }, [
|
||
E('i', { class: 'dl-addr-check' }, icon('plus')),
|
||
other,
|
||
button('Add', () => {
|
||
const h = other.value.trim().toLowerCase();
|
||
if (!h) return;
|
||
// The router would refuse it on Save: say so here.
|
||
const check = hostHelp(h);
|
||
if (check.bad) {
|
||
notify(check.text, 'warning');
|
||
return;
|
||
}
|
||
addRow(h);
|
||
if (!picked.includes(h)) picked = [...picked, h];
|
||
other.value = '';
|
||
paintOpts();
|
||
paintLinks();
|
||
}),
|
||
]),
|
||
]);
|
||
other.addEventListener('keydown', (ev: KeyboardEvent) => {
|
||
if (ev.key === 'Enter') {
|
||
ev.preventDefault();
|
||
(other.nextElementSibling as HTMLElement)?.click();
|
||
}
|
||
});
|
||
|
||
// One row per link, as people will see it (example code).
|
||
const links = E('div', { class: 'dl-links' });
|
||
// The port's help depends on the links too (IP addresses use the next port); set below.
|
||
let refreshPort = () => {};
|
||
const paintLinks = () => {
|
||
refreshPort();
|
||
const lport = Number(port.value) || eff.portal_port;
|
||
dom.content(
|
||
links,
|
||
picked.map((h, i) => {
|
||
const ip = isIp(h);
|
||
// The portal keeps its own port (80 and 443 stay free for others).
|
||
const p = ip ? lport + 1 : lport;
|
||
const base = `${ip ? 'http' : 'https'}://${h}${p === (ip ? 80 : 443) ? '' : `:${p}`}/`;
|
||
return E('div', { class: 'dl-link-row' }, [
|
||
E('span', { class: `dl-link-ic ${ip ? 'warn' : 'ok'}` }, icon(ip ? 'alert' : 'lock')),
|
||
E('span', { class: 'dl-mono dl-link-url' }, [base, E('b', {}, 'kamiro-telosu-bavine')]),
|
||
i === 0 ? E('span', { class: 'dl-pill info' }, 'Main') : ip ? E('span', { class: 'dl-pill warn' }, 'HTTP') : '',
|
||
]);
|
||
}),
|
||
);
|
||
};
|
||
paintOpts();
|
||
paintLinks();
|
||
port.addEventListener('input', () => paintLinks());
|
||
|
||
// Readiness: one summary line, the checks as chips, details on demand.
|
||
const SHORT: Record<string, string> = {
|
||
portal: 'Portal running',
|
||
portal_dns: 'Points here',
|
||
portal_reply: 'Answers reach visitors',
|
||
portal_http: 'Plain HTTP',
|
||
cert: 'Certificate',
|
||
};
|
||
const need = host.d.needs ?? { https: [], acme: [], home: [] };
|
||
const readyGroup = (checks: PortalInfo['checks'] | null): HTMLElement => {
|
||
if (!eff.portal_enabled) return E('div', { hidden: true });
|
||
if (!checks)
|
||
return group('check', 'Ready to share', 'The portal’s checks from Health', [
|
||
E('p', { class: 'dl-muted dl-loading' }, 'Running checks…'),
|
||
]);
|
||
const shown = checks.filter((x) => x.status !== 'skip');
|
||
if (!shown.length) return E('div', { hidden: true });
|
||
const { bad, worst } = verdict(checks);
|
||
const details = E(
|
||
'div',
|
||
{ class: 'dl-ready-details', hidden: true },
|
||
shown.map((x) =>
|
||
E('div', { class: `dl-ready-item ${x.status}` }, [
|
||
icon(x.status === 'ok' ? 'check' : 'alert'),
|
||
E('span', { class: 'dl-stack' }, [E('span', {}, x.title), E('span', { class: 'dl-sub' }, x.detail)]),
|
||
]),
|
||
),
|
||
);
|
||
const ready = E('div', { class: 'dl-stack gap8' }, [
|
||
E('div', { class: `dl-ready-sum ${worst}` }, [
|
||
icon(worst === 'ok' ? 'check' : 'alert'),
|
||
E('span', { class: 'dl-stack' }, [
|
||
E(
|
||
'b',
|
||
{},
|
||
worst === 'ok' ? `All ${shown.length} checks passed` : `${shown.length - bad.length} of ${shown.length} checks passed`,
|
||
),
|
||
bad.length
|
||
? E('span', { class: 'dl-sub' }, bad.map((x) => x.detail).join(' '))
|
||
: E('span', { class: 'dl-sub' }, 'Links will open for the people you send them to.'),
|
||
]),
|
||
E(
|
||
'button',
|
||
{
|
||
type: 'button',
|
||
class: 'dl-linkbtn',
|
||
click: (ev: Event) => {
|
||
details.hidden = !details.hidden;
|
||
(ev.currentTarget as HTMLElement).textContent = details.hidden ? 'Details' : 'Hide';
|
||
},
|
||
},
|
||
'Details',
|
||
),
|
||
]),
|
||
E(
|
||
'div',
|
||
{ class: 'dl-chips-row' },
|
||
shown.map((x) =>
|
||
E('span', { class: `dl-check-chip ${x.status}`, title: x.detail }, [
|
||
icon(x.status === 'ok' ? 'check' : 'alert'),
|
||
SHORT[x.id] ?? x.title,
|
||
]),
|
||
),
|
||
),
|
||
details,
|
||
]);
|
||
return group('check', 'Ready to share', 'The portal’s checks from Health', [ready]);
|
||
};
|
||
// The state pill next to the switch: none until the checks are in.
|
||
const readyPill = (checks: PortalInfo['checks'] | null): HTMLElement => {
|
||
if (!eff.portal_enabled || (!checks && !need.https.length)) return E('span', { hidden: true });
|
||
if (need.https.length) return E('span', { class: 'dl-pill bad' }, 'Can’t start');
|
||
const { worst } = verdict(checks!);
|
||
return E(
|
||
'span',
|
||
{ class: `dl-pill ${worst === 'ok' ? 'ok' : worst === 'error' ? 'bad' : 'warn'}` },
|
||
worst === 'error' ? 'Needs attention' : 'Ready',
|
||
);
|
||
};
|
||
let readyEl = readyGroup(host.portal?.checks ?? null);
|
||
let pillEl = readyPill(host.portal?.checks ?? null);
|
||
host.portalFill = (p) => {
|
||
found = true;
|
||
takeCands(p.candidates);
|
||
paintOpts();
|
||
paintLinks();
|
||
const g = readyGroup(p.checks);
|
||
readyEl.replaceWith(g);
|
||
readyEl = g;
|
||
const pl = readyPill(p.checks);
|
||
pillEl.replaceWith(pl);
|
||
pillEl = pl;
|
||
};
|
||
|
||
const until = c && !c.self_signed && c.expires ? fmtDay(c.expires) : '';
|
||
// Who holds the port (our own portal doesn't count), and the next one while links use an IP address.
|
||
const listenRow = liveRow('Listening port', port, () =>
|
||
portalPortHelp(port.value.trim() === '' ? eff.portal_port : Number(port.value), host.d.tcp_taken ?? [], picked.some(isIp)),
|
||
);
|
||
refreshPort = listenRow.refresh;
|
||
const titleRow = liveRow('Title', title, () => titleHelp(title.value));
|
||
const redirectRow = liveRow('Unknown links', redirect, () => urlHelp(redirect.value));
|
||
const custom = !!(s.portal_cert && s.portal_key);
|
||
const kind = !c ? 'Portal is off' : custom ? 'Your files' : c.self_signed ? 'Self-signed' : 'Let’s Encrypt';
|
||
const certFiles = () => {
|
||
const fc = input(s.portal_cert, { placeholder: '/etc/ssl/…/fullchain.crt' });
|
||
const fk = input(s.portal_key, { placeholder: '/etc/ssl/…/key' });
|
||
modal(
|
||
'Use your own certificate',
|
||
[
|
||
E('p', { class: 'dl-muted' }, 'Paths on the router. Leave both empty to pick a certificate automatically.'),
|
||
row('Certificate file', fc),
|
||
row('Key file', fk),
|
||
],
|
||
[
|
||
cancelButton(),
|
||
' ',
|
||
button(
|
||
'Save',
|
||
() => {
|
||
closeModal();
|
||
void host.save({ portal_cert: fc.value.trim(), portal_key: fk.value.trim() }, 'Certificate saved', 'portal');
|
||
},
|
||
'positive',
|
||
),
|
||
],
|
||
);
|
||
};
|
||
const missingRow = (ic: string, tone: '' | 'bad', title: string, sub: string, feature: 'https' | 'acme', label: string) =>
|
||
needRow(
|
||
ic,
|
||
tone,
|
||
title,
|
||
sub,
|
||
button(label, () => installMissing(feature, need[feature], () => host.reload('portal')), 'positive'),
|
||
);
|
||
const httpsRow = need.https.length
|
||
? missingRow(
|
||
'lock',
|
||
'bad',
|
||
'HTTPS isn’t available on this router',
|
||
`The portal needs ${need.https.join(' and ')}. It can’t start without them.`,
|
||
'https',
|
||
'Install',
|
||
)
|
||
: '';
|
||
const acmeRow =
|
||
need.acme.length && (!c || c.self_signed)
|
||
? missingRow(
|
||
'lock',
|
||
'',
|
||
'Free certificate from Let’s Encrypt',
|
||
`ACME isn’t installed. With it the router gets a certificate${s.portal_host ? ` for ${s.portal_host}` : ''} and browsers stop warning.`,
|
||
'acme',
|
||
'Install ACME',
|
||
)
|
||
: '';
|
||
const certRows = [
|
||
E('div', { class: 'dl-row' }, [
|
||
icon('lock'),
|
||
E('span', { class: 'dl-row-main dl-stack' }, [
|
||
E('b', {}, [kind, until ? E('span', { class: 'dl-faint' }, ` · until ${until}`) : '']),
|
||
E(
|
||
'span',
|
||
{ class: 'dl-sub dl-ellipsis', title: c?.path ?? '' },
|
||
!c
|
||
? 'Turn the portal on to see its certificate.'
|
||
: c.self_signed
|
||
? 'Made by the router: browsers warn until a certificate covers the address.'
|
||
: `${custom ? 'Your files' : 'Found automatically'} · ${c.path}`,
|
||
),
|
||
]),
|
||
]),
|
||
E('div', { class: 'dl-row' }, [
|
||
icon('file'),
|
||
E('span', { class: 'dl-row-main dl-stack' }, [
|
||
E('b', {}, 'Your own files'),
|
||
E('span', { class: 'dl-sub' }, custom ? `${s.portal_cert} · ${s.portal_key}` : 'Not set: the certificate is picked automatically.'),
|
||
]),
|
||
custom ? button('Reset', () => host.save({ portal_cert: '', portal_key: '' }, 'Automatic certificate', 'portal'), 'negative') : '',
|
||
button(custom ? 'Change' : 'Use files', certFiles),
|
||
]),
|
||
acmeRow,
|
||
];
|
||
|
||
return section(
|
||
'portal',
|
||
'Personal portal',
|
||
[
|
||
E('span', { class: 'dl-muted' }, 'A page where each person adds and manages their devices with their personal link.'),
|
||
httpsRow ? E('div', { class: 'dl-list' }, [httpsRow]) : '',
|
||
group('network', 'Port', 'How the portal listens (80 and 443 stay free)', [listenRow]),
|
||
group('edit', 'Appearance', 'What people see', [titleRow, redirectRow]),
|
||
group('link', 'Addresses', 'Pick one or more; the first is the main link', [
|
||
opts,
|
||
E('div', { class: 'dl-stack gap8' }, [
|
||
links,
|
||
E('span', { class: 'dl-sub' }, 'Example code; each person gets their own three words.'),
|
||
]),
|
||
]),
|
||
group('lock', 'Certificate', 'Used for HTTPS links', certRows),
|
||
readyEl,
|
||
],
|
||
[
|
||
E('span'),
|
||
button(
|
||
'Save',
|
||
() => {
|
||
// The help lines already say what is wrong: do not send it anyway.
|
||
const bad = firstBad([listenRow, titleRow, redirectRow]);
|
||
if (bad) {
|
||
notify(bad, 'warning');
|
||
return;
|
||
}
|
||
return host.save(
|
||
{
|
||
portal_enabled: isOn(pOn) ? '1' : '0',
|
||
portal_host: picked[0] ?? '',
|
||
portal_alt: picked.slice(1),
|
||
portal_port: port.value,
|
||
portal_title: title.value,
|
||
portal_redirect: redirect.value.trim(),
|
||
},
|
||
'Saved',
|
||
'portal',
|
||
);
|
||
},
|
||
'positive',
|
||
),
|
||
],
|
||
'',
|
||
[pillEl, pOn],
|
||
);
|
||
}
|