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
509 lines
19 KiB
TypeScript
509 lines
19 KiB
TypeScript
// Server → Access pieces: home services (picked from devices at home), circles,
|
|
// "Who reaches what" and "Check access".
|
|
|
|
import type { Circle, Person, Server, Status } from '../shared/types';
|
|
import { E } from './e';
|
|
import { api, type HomeHost } from './api';
|
|
import { button } from './ui/button';
|
|
import { cancelButton, closeModal, confirmDialog, modal } from './ui/modal';
|
|
import { attempt, notify } from './ui/toast';
|
|
import { chipToggle, input } from './ui/controls';
|
|
import { firstBad, liveField } from './ui/layout';
|
|
import { circleNameHelp, ipv4Help, nameHelp, portsHelp } from './netcheck';
|
|
import { icon } from '../shared/icons';
|
|
|
|
type Service = Status['services'][number];
|
|
|
|
/** Circle colours; the circle stores an index. */
|
|
export const CIRCLE_COLORS = ['#3a83f7', '#a78bfa', '#f472b6', '#f59e0b', '#10b981', '#22d3ee', '#ef4444', '#84cc16'];
|
|
|
|
export const circleDot = (c: Circle | undefined) =>
|
|
E('i', { class: 'dl-circle-dot', style: `background:${CIRCLE_COLORS[c?.color ?? 0] ?? CIRCLE_COLORS[0]}` });
|
|
|
|
/** People whose devices can be reached at home (the mesh and home devices). */
|
|
export const homeAccess = (p: Person) => p.access === 'both' || (p.access === 'lan' && !p.services?.length);
|
|
|
|
/* ---------- Home services ---------- */
|
|
|
|
export function serviceDialog(sv: Service | null, prefill: Partial<Service>, onSaved: () => unknown) {
|
|
const name = input(sv?.name ?? prefill.name ?? '', { placeholder: 'NAS' });
|
|
const addr = input(sv?.address ?? prefill.address ?? '', { placeholder: '192.168.1.10', class: 'cbi-input-text dl-mono' });
|
|
const ports = input((sv?.ports ?? prefill.ports ?? []).join(', '), {
|
|
placeholder: 'All ports, or e.g. 445, 5000',
|
|
class: 'cbi-input-text dl-mono',
|
|
});
|
|
const nameRow = liveField('Name', name, () => nameHelp(name.value, [], 'Shown to people who may reach it.'));
|
|
const addrRow = liveField('Address', addr, () => ipv4Help(addr.value));
|
|
const portsRow = liveField('Ports', ports, () => portsHelp(ports.value));
|
|
modal(
|
|
sv ? `Edit ${sv.name}` : 'Add service',
|
|
[nameRow, addrRow, portsRow],
|
|
[
|
|
cancelButton(),
|
|
' ',
|
|
button(
|
|
'Save',
|
|
async () => {
|
|
const bad = firstBad([nameRow, addrRow, portsRow]);
|
|
if (bad) {
|
|
notify(bad, 'warning');
|
|
return;
|
|
}
|
|
const list = ports.value.split(/[ ,]+/).filter(Boolean);
|
|
if (await attempt(() => api.serviceSet(sv?.id ?? '', name.value, addr.value, list), 'Saved')) {
|
|
closeModal();
|
|
onSaved();
|
|
}
|
|
},
|
|
'positive',
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
/** Port groups a device at home offers: what it announces over Bonjour, or the usual ones. */
|
|
const MDNS_LABEL: Record<string, string> = {
|
|
_smb: 'SMB',
|
|
_afpovertcp: 'AFP',
|
|
_http: 'Web',
|
|
_https: 'Web',
|
|
_ssh: 'SSH',
|
|
_sftp: 'SFTP',
|
|
'_sftp-ssh': 'SFTP',
|
|
_ipp: 'Printer',
|
|
_ipps: 'Printer',
|
|
_printer: 'Printer',
|
|
'_pdl-datastream': 'Printer',
|
|
_airplay: 'AirPlay',
|
|
_raop: 'AirPlay',
|
|
_rfb: 'Screen sharing',
|
|
_googlecast: 'Cast',
|
|
_hap: 'HomeKit',
|
|
_rdp: 'Remote desktop',
|
|
_ftp: 'FTP',
|
|
};
|
|
const DEFAULT_PORTS: [string, string[]][] = [
|
|
['Web', ['80', '443']],
|
|
['SMB', ['445']],
|
|
['SSH', ['22']],
|
|
];
|
|
|
|
function portGroups(h: HomeHost): [string, string[]][] {
|
|
const by = new Map<string, Set<string>>();
|
|
for (const s of h.services) {
|
|
const label = MDNS_LABEL[s.type.split('.')[0]];
|
|
if (!label || !s.port) continue;
|
|
(by.get(label) ?? by.set(label, new Set()).get(label)!).add(String(s.port));
|
|
}
|
|
return by.size ? [...by].map(([l, p]) => [l, [...p].sort((a, b) => +a - +b)]) : DEFAULT_PORTS;
|
|
}
|
|
|
|
/** Home services as a live part of Server → Access: `update` repaints it from a new status. */
|
|
export interface HomeServices {
|
|
el: HTMLElement;
|
|
update(st: Status): void;
|
|
}
|
|
|
|
/**
|
|
* Services shared by all servers, and the devices at home to add them from.
|
|
* The devices are read once; `reload` refreshes the status after a change
|
|
* (the rest of the Access section, and what is typed there, stays).
|
|
*/
|
|
export function homeServices(initial: Status, serverId: string, reload: () => Promise<unknown>): HomeServices {
|
|
let st = initial;
|
|
let hosts: { hosts: HomeHost[]; mdns: boolean } | null = null;
|
|
let failed = false;
|
|
/** The "Add from devices at home" fold, once opened or closed by hand. */
|
|
let open: boolean | null = null;
|
|
/** Devices with a change on its way: a second click would add the service twice. */
|
|
const busy = new Set<string>();
|
|
const list = E('div', { class: 'dl-list' });
|
|
const picker = E('div', { class: 'dl-stack gap8' }, E('span', { class: 'dl-sub' }, 'Looking for devices at home…'));
|
|
|
|
const paintRows = () => {
|
|
const services = st.services;
|
|
dom.content(
|
|
list,
|
|
services.length
|
|
? services.map((sv) =>
|
|
E('div', { class: 'dl-row' }, [
|
|
icon('home'),
|
|
E('span', { class: 'dl-row-main dl-stack' }, [
|
|
E('b', {}, sv.name),
|
|
E(
|
|
'span',
|
|
{ class: 'dl-mono dl-faint' },
|
|
`${sv.address}${sv.ports.length ? ` · ports ${sv.ports.join(', ')}` : ' · all ports'}`,
|
|
),
|
|
]),
|
|
button('Edit', () => serviceDialog(sv, {}, reload)),
|
|
button(
|
|
[icon('trash')],
|
|
async () => {
|
|
if (
|
|
(await confirmDialog(`Remove ${sv.name}?`, 'People limited to this service lose access to it.', 'Remove', true)) &&
|
|
(await attempt(() => api.serviceDelete(sv.id), 'Removed'))
|
|
)
|
|
await reload();
|
|
},
|
|
'neutral',
|
|
{ title: 'Remove', 'aria-label': `Remove ${sv.name}` },
|
|
),
|
|
]),
|
|
)
|
|
: [E('div', { class: 'dl-row dl-muted' }, 'No services yet: pick ports of a device below.')],
|
|
);
|
|
};
|
|
|
|
/** Ports chosen for a device: add, change or remove its service at once. */
|
|
async function choose(h: HomeHost, ports: string[] | null) {
|
|
if (busy.has(h.address)) return;
|
|
busy.add(h.address);
|
|
paintPicker();
|
|
try {
|
|
const sv = st.services.find((s) => s.address === h.address);
|
|
const ok =
|
|
ports === null
|
|
? sv && (await attempt(() => api.serviceDelete(sv.id), `${sv.name} removed`))
|
|
: await attempt(
|
|
() => api.serviceSet(sv?.id ?? '', sv?.name ?? (h.name || h.address), h.address, ports),
|
|
sv ? `${sv.name} updated` : `${h.name || h.address} added`,
|
|
);
|
|
if (ok) await reload();
|
|
} finally {
|
|
busy.delete(h.address);
|
|
paintPicker();
|
|
}
|
|
}
|
|
|
|
function hostRow(h: HomeHost): HTMLElement {
|
|
const sv = st.services.find((s) => s.address === h.address);
|
|
const all = !!sv && !sv.ports.length;
|
|
const chosen = new Set(sv?.ports ?? []);
|
|
const wait = busy.has(h.address);
|
|
const chip = (label: string, on: boolean, click: () => void) =>
|
|
chipToggle(label, on, click, { disabled: wait ? 'disabled' : null, 'aria-busy': wait ? 'true' : null });
|
|
return E('div', { class: 'dl-row' }, [
|
|
icon(h.services.some((s) => s.type.startsWith('_ipp') || s.type.startsWith('_printer')) ? 'file' : 'computer'),
|
|
E('span', { class: 'dl-row-main dl-stack' }, [E('b', {}, h.name || h.address), E('span', { class: 'dl-mono dl-faint' }, h.address)]),
|
|
E('div', { class: 'dl-chips-row dl-host-ports' }, [
|
|
chip('All ports', all, () => choose(h, all ? null : [])),
|
|
...portGroups(h).map(([label, ports]) => {
|
|
const on = !all && ports.every((p) => chosen.has(p));
|
|
return chip(`${label} ${ports.join(', ')}`, on, () => {
|
|
const next = new Set(all ? [] : chosen);
|
|
for (const p of ports) {
|
|
if (on) next.delete(p);
|
|
else next.add(p);
|
|
}
|
|
choose(h, next.size ? [...next] : null);
|
|
});
|
|
}),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
function paintPicker() {
|
|
if (failed) return dom.content(picker, E('span', { class: 'dl-sub' }, "Couldn't read the devices at home."));
|
|
if (!hosts) return;
|
|
const r = hosts;
|
|
if (!r.hosts.length) return dom.content(picker, E('span', { class: 'dl-sub' }, 'No devices found in the home network right now.'));
|
|
// Open while there are no services yet (that is where they come from), then as left.
|
|
const fold = E('details', { class: 'dl-params', open: (open ?? !st.services.length) ? '' : null }, [
|
|
E('summary', {}, [
|
|
icon('chevron'),
|
|
E('span', {}, 'Add from devices at home'),
|
|
E('span', { class: 'dl-pcount' }, String(r.hosts.length)),
|
|
]),
|
|
E('div', { class: 'dl-params-body' }, [
|
|
E(
|
|
'span',
|
|
{ class: 'dl-sub' },
|
|
r.mdns
|
|
? 'Ports they announce over Bonjour. Pick what to open, or all ports.'
|
|
: 'Devices that got an address from this router. Pick the ports to open, or all ports.',
|
|
),
|
|
E('div', { class: 'dl-list' }, r.hosts.map(hostRow)),
|
|
]),
|
|
]);
|
|
fold.addEventListener('toggle', () => (open = (fold as HTMLDetailsElement).open));
|
|
dom.content(picker, fold);
|
|
}
|
|
|
|
api
|
|
.homeHosts(serverId)
|
|
.then((r) => {
|
|
hosts = r;
|
|
paintPicker();
|
|
})
|
|
.catch(() => {
|
|
failed = true;
|
|
paintPicker();
|
|
});
|
|
paintRows();
|
|
|
|
const el = E('div', { class: 'dl-stack gap8' }, [
|
|
E('div', { class: 'dl-iflead' }, [
|
|
E('div', { class: 'dl-iflead-row' }, [
|
|
E('b', {}, 'Home services'),
|
|
button([icon('plus'), ' Add service'], () => serviceDialog(null, {}, reload)),
|
|
]),
|
|
E(
|
|
'span',
|
|
{ class: 'dl-sub' },
|
|
'Home-only people can be limited to these instead of whole networks (chosen on their page). Shared by all servers.',
|
|
),
|
|
]),
|
|
list,
|
|
picker,
|
|
]);
|
|
return {
|
|
el,
|
|
update(n: Status) {
|
|
st = n;
|
|
paintRows();
|
|
paintPicker();
|
|
},
|
|
};
|
|
}
|
|
|
|
/* ---------- Circles ---------- */
|
|
|
|
export function circleDialog(st: Status, serverId: string, ci: Circle | null, onDone: () => unknown) {
|
|
const used = new Set(st.circles.filter((c) => c.server === serverId).map((c) => c.color));
|
|
let color = ci?.color ?? CIRCLE_COLORS.findIndex((_, i) => !used.has(i));
|
|
if (color < 0) color = 0;
|
|
const name = input(ci?.name ?? '', { placeholder: 'Family' });
|
|
const people = st.people.filter((p) => p.server === serverId).sort((a, b) => a.name.localeCompare(b.name));
|
|
const members = new Set(people.filter((p) => ci && p.circle === ci.id).map((p) => p.id));
|
|
|
|
const swatches = E('div', { class: 'dl-swatches', role: 'radiogroup', 'aria-label': 'Colour' });
|
|
const paintSwatches = () =>
|
|
dom.content(
|
|
swatches,
|
|
CIRCLE_COLORS.map((c, i) =>
|
|
E('button', {
|
|
type: 'button',
|
|
role: 'radio',
|
|
class: `dl-swatch${i === color ? ' on' : ''}`,
|
|
style: `--sw:${c}`,
|
|
'aria-checked': i === color ? 'true' : 'false',
|
|
'aria-label': `Colour ${i + 1}`,
|
|
click: () => {
|
|
color = i;
|
|
paintSwatches();
|
|
},
|
|
}),
|
|
),
|
|
);
|
|
paintSwatches();
|
|
|
|
const chips = E(
|
|
'div',
|
|
{ class: 'dl-chips-row' },
|
|
people.map((p) => {
|
|
const other = p.circle && p.circle !== ci?.id ? st.circles.find((c) => c.id === p.circle) : undefined;
|
|
return E(
|
|
'button',
|
|
{
|
|
type: 'button',
|
|
class: `dl-chipbtn${members.has(p.id) ? ' on' : ''}`,
|
|
title: !homeAccess(p)
|
|
? `${p.name} has no home access: their devices aren't reachable anyway`
|
|
: other
|
|
? `Now in ${other.name}`
|
|
: '',
|
|
click: (ev: Event) => {
|
|
if (!members.delete(p.id)) members.add(p.id);
|
|
(ev.currentTarget as HTMLElement).classList.toggle('on', members.has(p.id));
|
|
},
|
|
},
|
|
[p.name, !homeAccess(p) ? E('b', {}, 'internet') : other ? E('b', {}, other.name) : ''],
|
|
);
|
|
}),
|
|
);
|
|
const field = (label: string, el: Node) =>
|
|
E('div', { class: 'cbi-value' }, [E('label', { class: 'cbi-value-title' }, label), E('div', { class: 'cbi-value-field' }, el)]);
|
|
const others = st.circles.filter((c) => c.server === serverId && c.id !== ci?.id).map((c) => c.name);
|
|
const nameRow = liveField('Name', name, () => circleNameHelp(name.value, others));
|
|
|
|
modal(
|
|
ci ? `Edit ${ci.name}` : 'New circle',
|
|
[
|
|
nameRow,
|
|
field('Colour', swatches),
|
|
field('People', chips),
|
|
E('p', { class: 'dl-sub' }, 'Devices of people in one circle reach each other. A person is in one circle at a time.'),
|
|
],
|
|
[
|
|
ci
|
|
? button(
|
|
'Delete',
|
|
async () => {
|
|
if (await attempt(() => api.circleDelete(ci.id), `${ci.name} deleted`)) {
|
|
closeModal();
|
|
onDone();
|
|
}
|
|
},
|
|
'negative',
|
|
)
|
|
: '',
|
|
E('span', { class: 'dl-spacer' }),
|
|
cancelButton(),
|
|
' ',
|
|
button(
|
|
'Save',
|
|
async () => {
|
|
const h = nameRow.help();
|
|
if (h.bad) {
|
|
notify(h.text, 'warning');
|
|
return;
|
|
}
|
|
if (await attempt(() => api.circleSet(ci?.id ?? '', serverId, name.value, color, [...members]), 'Saved')) {
|
|
closeModal();
|
|
onDone();
|
|
}
|
|
},
|
|
'positive',
|
|
),
|
|
],
|
|
'dl-circle-modal',
|
|
);
|
|
}
|
|
|
|
/** The server's circles as chips (click to edit) and a round "+" to add one. */
|
|
export function circleChips(st: Status, serverId: string, onDone: () => unknown): HTMLElement {
|
|
const list = st.circles.filter((c) => c.server === serverId);
|
|
return E('div', { class: 'dl-chips-row dl-circles' }, [
|
|
...list.map((c) => {
|
|
const who = st.people.filter((p) => p.circle === c.id).map((p) => p.name);
|
|
return E(
|
|
'button',
|
|
{ type: 'button', class: 'dl-chip', title: `Edit ${c.name}`, click: () => circleDialog(st, serverId, c, onDone) },
|
|
[circleDot(c), E('b', {}, c.name), E('span', { class: 'dl-faint' }, who.length ? who.join(', ') : 'nobody yet')],
|
|
);
|
|
}),
|
|
E(
|
|
'button',
|
|
{
|
|
type: 'button',
|
|
class: 'dl-chip add',
|
|
title: 'New circle',
|
|
'aria-label': 'New circle',
|
|
click: () => circleDialog(st, serverId, null, onDone),
|
|
},
|
|
icon('plus'),
|
|
),
|
|
]);
|
|
}
|
|
|
|
/* ---------- Who reaches what ---------- */
|
|
|
|
export function whoReaches(st: Status, srv: Server): HTMLElement {
|
|
const people = st.people.filter((p) => p.server === srv.id);
|
|
const yes = (t = '') => E('span', { class: 'dl-yes' }, [icon('check'), t]);
|
|
const no = () => E('span', { class: 'dl-faint' }, '—');
|
|
const home = (list: Person[]) => {
|
|
const kinds = new Set(list.map((p) => (p.access === 'lan' && p.services?.length ? 'services' : p.home_nets?.length ? 'some' : 'all')));
|
|
if (!kinds.size) kinds.add('all');
|
|
return yes([...kinds].map((k) => ({ all: 'all networks', some: 'their networks', services: 'services' })[k]).join(' / '));
|
|
};
|
|
const each = () => (srv.mesh === 'off' ? no() : srv.mesh === 'circles' ? yes('circle') : yes());
|
|
const net = srv.lan_like ? 'like home' : 'direct';
|
|
const row = (label: string, list: Person[], cells: Node[]) =>
|
|
E('tr', {}, [
|
|
E('td', {}, [E('b', {}, label), E('div', { class: 'dl-sub' }, `${list.length} ${list.length === 1 ? 'person' : 'people'}`)]),
|
|
...cells.map((c) => E('td', {}, c)),
|
|
]);
|
|
const by = (a: string) => people.filter((p) => p.access === a);
|
|
return E('section', { class: 'dl-setsec' }, [
|
|
E('div', { class: 'dl-setsec-body' }, [
|
|
E('div', { class: 'dl-panel-head' }, [
|
|
E('h3', {}, 'Who reaches what'),
|
|
E('span', { class: 'dl-spacer' }),
|
|
E('span', { class: 'dl-sub' }, 'From the rules on this server'),
|
|
]),
|
|
E(
|
|
'div',
|
|
{ class: 'dl-reach-wrap' },
|
|
E('table', { class: 'dl-table dl-reach' }, [
|
|
E(
|
|
'tr',
|
|
{},
|
|
['', 'Internet', 'Home', 'This router', 'Each other'].map((t) => E('th', {}, t)),
|
|
),
|
|
row('Internet', by('internet'), [yes(net), no(), E('span', { class: 'dl-faint' }, 'DNS'), no()]),
|
|
row('Home', by('lan'), [E('span', { class: 'dl-faint' }, 'their own'), home(by('lan')), yes(), each()]),
|
|
row('Both', by('both'), [yes(net), home(by('both')), yes(), each()]),
|
|
]),
|
|
),
|
|
E(
|
|
'p',
|
|
{ class: 'dl-sub' },
|
|
'Home devices reach the devices of people with home access, on the networks those people reach. Paused, ended and over-the-limit people reach nothing.',
|
|
),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
/* ---------- Check access ---------- */
|
|
|
|
export function checkAccess(st: Status, srv: Server): HTMLElement {
|
|
const devs = st.people
|
|
.filter((p) => p.server === srv.id)
|
|
.flatMap((p) => p.devices.map((d) => ({ id: d.id, label: `${p.name} · ${d.name}` })))
|
|
.sort((a, b) => a.label.localeCompare(b.label));
|
|
const ADDR = '@addr';
|
|
/** A device, or an address typed in. */
|
|
const end = (placeholder: string, initial: string) => {
|
|
const sel = E('select', { class: 'cbi-input-select', 'aria-label': placeholder }, [
|
|
...devs.map((d) => E('option', { value: d.id, selected: d.id === initial ? 'selected' : null }, d.label)),
|
|
E('option', { value: ADDR, selected: initial === ADDR ? 'selected' : null }, 'Address'),
|
|
]) as HTMLSelectElement;
|
|
const addr = input('', { placeholder, class: 'cbi-input-text dl-mono' });
|
|
const wrap = E('div', { class: 'dl-check-end' }, [sel, addr]);
|
|
const sync = () => (addr.hidden = sel.value !== ADDR);
|
|
sel.addEventListener('change', sync);
|
|
sync();
|
|
return { el: wrap, value: () => (sel.value === ADDR ? addr.value.trim() : sel.value) };
|
|
};
|
|
const from = end('10.0.1.11', devs[0]?.id ?? ADDR);
|
|
const to = end('10.0.1.20:445', ADDR);
|
|
const out = E('div', { class: 'dl-stack gap8' });
|
|
const run = async () => {
|
|
const r = await attempt(() => api.accessCheck(from.value(), to.value()));
|
|
if (!r) return;
|
|
const stop = r.steps.findIndex((s) => !s.ok);
|
|
dom.content(out, [
|
|
E('div', { class: `dl-verdict ${r.ok ? 'ok' : 'bad'}` }, [
|
|
E('b', {}, r.ok ? 'Allowed' : 'Blocked'),
|
|
E('span', { class: 'dl-sub' }, r.ok ? 'Every step lets it through' : `Stops at step ${stop + 1} of ${r.steps.length}`),
|
|
]),
|
|
E(
|
|
'ul',
|
|
{ class: 'dl-checks' },
|
|
r.steps.map((s) =>
|
|
E('li', {}, [
|
|
E('span', { class: `dl-check-icon ${s.ok ? 'ok' : 'error'}` }, icon(s.ok ? 'check' : 'x')),
|
|
E('div', { class: 'dl-check-body' }, [
|
|
E('div', { class: 'dl-check-title' }, s.title),
|
|
s.detail ? E('div', { class: 'dl-check-detail' }, s.detail) : '',
|
|
]),
|
|
]),
|
|
),
|
|
),
|
|
]);
|
|
};
|
|
return E('section', { class: 'dl-setsec' }, [
|
|
E('div', { class: 'dl-setsec-body' }, [
|
|
E('div', { class: 'dl-panel-head' }, [
|
|
E('h3', {}, 'Check access'),
|
|
E('span', { class: 'dl-spacer' }),
|
|
E('span', { class: 'dl-sub' }, 'Why something does or does not connect'),
|
|
]),
|
|
E('div', { class: 'dl-check-form' }, [from.el, E('span', { class: 'dl-faint' }, '→'), to.el, button('Check', run)]),
|
|
out,
|
|
]),
|
|
]);
|
|
}
|