- Access split into Internet and Home network cards; network tiles inline, Auto-detect LAN beside them, other interfaces folded by kind - Devices reach each other: Off, Everyone or Circles (per server); circles with names, colours and members; a person's own devices always see each other while it is not off - Per-person home networks: people can be kept out of some of the server's networks (nft lan_part set, AllowedIPs follow) - Home services moved from Settings to Access, added from the devices the router sees over DHCP (ports they announce over Bonjour when umdns runs) - Who reaches what (rules summed up per access) and Check access (walks the same rules as nft and the client configuration, step by step) - Find home devices (Bonjour): umdns services published as DNS-SD records in dnsmasq; installs umdns from Access - Connections from home show the DHCP name with the address in brackets - Repaints keep the scroll position
This commit is contained in:
1 parent
82ab86848e
commit
aa8256bc60
26 files changed
+1661
-289
No files matched your search
@@ -0,0 +1,441 @@
|
||||
// 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 { attempt, button, closeModal, confirmDialog, modal } from './ui';
|
||||
import { input } from './kit';
|
||||
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: () => void) {
|
||||
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 field = (label: string, el: Node) =>
|
||||
E('div', { class: 'cbi-value' }, [E('label', { class: 'cbi-value-title' }, label), E('div', { class: 'cbi-value-field' }, el)]);
|
||||
modal(
|
||||
sv ? `Edit ${sv.name}` : 'Add service',
|
||||
[field('Name', name), field('Address', addr), field('Ports', ports)],
|
||||
[
|
||||
E('button', { class: 'cbi-button cbi-button-neutral', click: closeModal }, 'Cancel'),
|
||||
' ',
|
||||
button(
|
||||
'Save',
|
||||
async () => {
|
||||
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;
|
||||
}
|
||||
|
||||
/** Services shared by all servers, and the devices at home to add them from. */
|
||||
export function homeServices(st: Status, serverId: string, reload: () => void): HTMLElement {
|
||||
const services = st.services;
|
||||
const picker = E('div', { class: 'dl-stack gap8' }, E('span', { class: 'dl-sub' }, 'Looking for devices at home…'));
|
||||
|
||||
const rows = 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'))
|
||||
)
|
||||
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) {
|
||||
const sv = 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) reload();
|
||||
}
|
||||
|
||||
function hostRow(h: HomeHost): HTMLElement {
|
||||
const sv = services.find((s) => s.address === h.address);
|
||||
const all = !!sv && !sv.ports.length;
|
||||
const chosen = new Set(sv?.ports ?? []);
|
||||
const chip = (label: string, on: boolean, click: () => void) =>
|
||||
E('button', { type: 'button', class: `dl-chipbtn${on ? ' on' : ''}`, 'aria-pressed': on ? 'true' : 'false', click }, label);
|
||||
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);
|
||||
});
|
||||
}),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
api
|
||||
.homeHosts(serverId)
|
||||
.then((r) => {
|
||||
const open = r.hosts.some((h) => services.some((s) => s.address === h.address)) && !services.length;
|
||||
dom.content(
|
||||
picker,
|
||||
r.hosts.length
|
||||
? E('details', { class: 'dl-params', open: open ? '' : 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)),
|
||||
]),
|
||||
])
|
||||
: E('span', { class: 'dl-sub' }, 'No devices found in the home network right now.'),
|
||||
);
|
||||
})
|
||||
.catch(() => dom.content(picker, E('span', { class: 'dl-sub' }, "Couldn't read the devices at home.")));
|
||||
|
||||
return 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.',
|
||||
),
|
||||
]),
|
||||
E('div', { class: 'dl-list' }, rows),
|
||||
picker,
|
||||
]);
|
||||
}
|
||||
|
||||
/* ---------- Circles ---------- */
|
||||
|
||||
export function circleDialog(st: Status, serverId: string, ci: Circle | null, onDone: () => void) {
|
||||
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)]);
|
||||
|
||||
modal(
|
||||
ci ? `Edit ${ci.name}` : 'New circle',
|
||||
[
|
||||
field('Name', name),
|
||||
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' }),
|
||||
E('button', { class: 'cbi-button cbi-button-neutral', click: closeModal }, 'Cancel'),
|
||||
' ',
|
||||
button(
|
||||
'Save',
|
||||
async () => {
|
||||
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: () => void): 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,
|
||||
]),
|
||||
]);
|
||||
}
|
||||
+36
-4
@@ -1,6 +1,6 @@
|
||||
// luci.dawnline RPC bindings. The backend reports failures as { error }.
|
||||
|
||||
import type { AwgCaps, ClientConfig, DayUsage, HealthCheck, LogEvent, Person, Status } from '../shared/types';
|
||||
import type { AwgCaps, Circle, ClientConfig, DayUsage, HealthCheck, LogEvent, MeshMode, Person, Status } from '../shared/types';
|
||||
|
||||
function call<T>(method: string, params: string[] = []) {
|
||||
const fn = rpc.declare<any>({ object: 'luci.dawnline', method, params });
|
||||
@@ -95,6 +95,7 @@ export interface Needs {
|
||||
https: string[];
|
||||
acme: string[];
|
||||
home: string[];
|
||||
bonjour: string[];
|
||||
}
|
||||
|
||||
export interface SettingsData {
|
||||
@@ -178,8 +179,18 @@ export interface InterfacesData {
|
||||
ifname: string;
|
||||
detected: { wan: string | null; lan: string | null };
|
||||
saved: { wan: string; lan: string };
|
||||
config: { auto_wan: boolean; wan_device: string; auto_lan: boolean; lan_devices: string[]; lan_like: boolean; device_mesh: boolean };
|
||||
config: {
|
||||
auto_wan: boolean;
|
||||
wan_device: string;
|
||||
auto_lan: boolean;
|
||||
lan_devices: string[];
|
||||
lan_like: boolean;
|
||||
device_mesh: boolean;
|
||||
mesh: MeshMode;
|
||||
};
|
||||
like_home: LikeHome;
|
||||
/** Find home devices: published from umdns as DNS-SD records. */
|
||||
bonjour: { on: boolean; needs: string[]; running: boolean; services: number };
|
||||
effective: {
|
||||
wan: { dev: string | null; zone: string; auto: boolean; missing: boolean };
|
||||
home: { dev: string; auto: boolean; nets: string[]; zone: string | null; missing: boolean }[];
|
||||
@@ -193,6 +204,20 @@ export interface InterfacesData {
|
||||
nets_changed?: boolean;
|
||||
}
|
||||
|
||||
/** "Check access": each rule on the way, in order; it stops at the first that fails. */
|
||||
export interface AccessCheck {
|
||||
ok: boolean;
|
||||
steps: { ok: boolean; title: string; detail: string }[];
|
||||
}
|
||||
|
||||
/** A device at home (DHCP lease or static host) and the services it announces over Bonjour. */
|
||||
export interface HomeHost {
|
||||
address: string;
|
||||
name: string;
|
||||
mac: string;
|
||||
services: { type: string; name: string; port: number }[];
|
||||
}
|
||||
|
||||
/** Filters for logs_clear; all empty clears the whole log. */
|
||||
export interface LogFilter {
|
||||
person?: string;
|
||||
@@ -221,7 +246,7 @@ export type PersonPatch = Partial<
|
||||
| 'dns_mode',
|
||||
string
|
||||
>
|
||||
> & { paused?: boolean; services?: string[] };
|
||||
> & { paused?: boolean; services?: string[]; circle?: string; home_nets?: string[] };
|
||||
|
||||
const personUpdateRaw = rpc.declare<any>({
|
||||
object: 'luci.dawnline',
|
||||
@@ -242,6 +267,8 @@ const personUpdateRaw = rpc.declare<any>({
|
||||
'dns_mode',
|
||||
'paused',
|
||||
'services',
|
||||
'circle',
|
||||
'home_nets',
|
||||
],
|
||||
});
|
||||
|
||||
@@ -260,7 +287,7 @@ async function personUpdate(id: string, patch: PersonPatch): Promise<{ person: P
|
||||
'note',
|
||||
'dns_mode',
|
||||
] as const;
|
||||
const args: unknown[] = [id, ...keys.map((k) => patch[k]), patch.paused, patch.services];
|
||||
const args: unknown[] = [id, ...keys.map((k) => patch[k]), patch.paused, patch.services, patch.circle, patch.home_nets];
|
||||
const r = await personUpdateRaw(...args);
|
||||
if (r && typeof r.error === 'string') throw new Error(r.error);
|
||||
return r;
|
||||
@@ -324,7 +351,12 @@ export const api = {
|
||||
'lan_devices',
|
||||
'lan_like',
|
||||
'device_mesh',
|
||||
'mesh',
|
||||
]),
|
||||
circleSet: call<{ id: string; circles: Circle[] }>('circle_set', ['id', 'server', 'name', 'color', 'members']),
|
||||
circleDelete: call<{ circles: Circle[] }>('circle_delete', ['id']),
|
||||
accessCheck: call<AccessCheck>('access_check', ['from', 'to']),
|
||||
homeHosts: call<{ hosts: HomeHost[]; mdns: boolean }>('home_hosts', ['id']),
|
||||
usageClear: call<unknown>('usage_clear', ['scope', 'id']),
|
||||
uninstall: call<unknown>('uninstall', ['confirm']),
|
||||
status,
|
||||
|
||||
+258
-119
@@ -1,8 +1,10 @@
|
||||
// Interfaces card (Server page): auto-detected WAN and LAN, plus a picker for
|
||||
// the interfaces that make up a server's home network.
|
||||
|
||||
import type { MeshMode, Server, Status } from '../shared/types';
|
||||
import { E } from './e';
|
||||
import { api, type IfaceCategory, type InterfacesData, type NetDevice } from './api';
|
||||
import { circleChips, homeServices } from './access';
|
||||
import { attempt, button, notify } from './ui';
|
||||
import { installMissing } from './pkgs';
|
||||
import { attachTip } from './charts';
|
||||
@@ -46,22 +48,32 @@ function sw(on: boolean, label: string, onChange: (v: boolean) => void): HTMLBut
|
||||
return b;
|
||||
}
|
||||
|
||||
export function interfacesCard(serverId: string, title = 'Interfaces'): HTMLElement {
|
||||
/**
|
||||
* Server → Access: how internet traffic leaves (Internet) and what home access
|
||||
* reaches (Home network: networks, devices reaching each other, services).
|
||||
* Both cards share one draft; either Save stores it.
|
||||
*/
|
||||
export function accessCards(srv: Server, st: Status, reload: () => void): HTMLElement {
|
||||
const serverId = srv.id;
|
||||
const root = E(
|
||||
'section',
|
||||
{ class: 'dl-setsec dl-ifcard' },
|
||||
E('div', { class: 'dl-setsec-body' }, E('p', { class: 'dl-muted' }, 'Loading interfaces…')),
|
||||
'div',
|
||||
{ class: 'dl-stack gap16' },
|
||||
E('section', { class: 'dl-setsec' }, E('div', { class: 'dl-setsec-body' }, E('p', { class: 'dl-muted' }, 'Loading interfaces…'))),
|
||||
);
|
||||
let d: InterfacesData;
|
||||
let autoWan = true,
|
||||
wanDev = '',
|
||||
autoLan = true,
|
||||
lanLike = true,
|
||||
mesh = true;
|
||||
mesh: MeshMode = 'all';
|
||||
// "Other interfaces" stays open or folded across repaints.
|
||||
let otherOpen = false;
|
||||
// Built once: it reads the devices at home, which should not happen on every repaint.
|
||||
const services = homeServices(st, serverId, reload);
|
||||
let lans = new Set<string>();
|
||||
let initial = '';
|
||||
|
||||
const snapshot = () => JSON.stringify([lanLike, mesh, autoWan, autoWan ? '' : wanDev, autoLan, [...lans].sort()]);
|
||||
const snapshot = () => JSON.stringify([lanLike, autoWan, autoWan ? '' : wanDev, autoLan, [...lans].sort()]);
|
||||
const liveLan = () => d.detected.lan || d.saved.lan || '';
|
||||
const currentWan = () => (autoWan ? d.detected.wan || d.saved.wan : wanDev) || '';
|
||||
const byName = () => new Map(d.devices.map((x) => [x.name, x]));
|
||||
@@ -80,7 +92,7 @@ export function interfacesCard(serverId: string, title = 'Interfaces'): HTMLElem
|
||||
wanDev = r.config.wan_device || r.detected.wan || r.saved.wan || '';
|
||||
autoLan = r.config.auto_lan;
|
||||
lanLike = r.config.lan_like;
|
||||
mesh = r.config.device_mesh;
|
||||
mesh = r.config.mesh ?? (r.config.device_mesh ? 'all' : 'off');
|
||||
lans = new Set(r.config.lan_devices);
|
||||
initial = snapshot();
|
||||
}
|
||||
@@ -95,6 +107,13 @@ export function interfacesCard(serverId: string, title = 'Interfaces'): HTMLElem
|
||||
if (r) take(r, reset);
|
||||
};
|
||||
|
||||
/** Can be part of the home network (or already is). */
|
||||
function pickable(x: NetDevice): boolean {
|
||||
const isAuto = autoLan && x.name === liveLan();
|
||||
const blocked = !!x.own || !!x.master || x.name === currentWan() || isAuto;
|
||||
return isAuto || lans.has(x.name) || (!blocked && (x.nets.length > 0 || !!x.missing));
|
||||
}
|
||||
|
||||
function tile(x: NetDevice): HTMLElement {
|
||||
const isAuto = autoLan && x.name === liveLan();
|
||||
const isWan = x.name === currentWan();
|
||||
@@ -179,6 +198,35 @@ export function interfacesCard(serverId: string, title = 'Interfaces'): HTMLElem
|
||||
];
|
||||
}
|
||||
|
||||
const MESH_TEXT: Record<MeshMode, string> = {
|
||||
off: "Devices of different people never reach each other; a person's own devices don't either.",
|
||||
all: 'Devices of people with home access reach each other, like home devices do. Internet-only people never.',
|
||||
circles: 'Within a circle: family sees family, guests see guests. Everyone reaches their own devices. Internet-only people never.',
|
||||
};
|
||||
|
||||
function setrow(
|
||||
ic: string,
|
||||
label: (Node | string)[] | string,
|
||||
sub: (Node | string)[] | string,
|
||||
ctl: Node | (Node | string)[] | '',
|
||||
tone = '',
|
||||
below?: Node,
|
||||
) {
|
||||
return E('div', { class: below ? 'dl-setrow head' : 'dl-setrow' }, [
|
||||
E('div', { class: 'dl-lh-main' }, [
|
||||
E('span', { class: `dl-need-ic ${tone}` }, icon(ic)),
|
||||
E('div', { class: 'dl-stack' }, [E('span', { class: 'dl-setrow-label' }, label), E('span', { class: 'dl-sub' }, sub), below ?? '']),
|
||||
]),
|
||||
E('div', { class: 'dl-setrow-ctl' }, ctl),
|
||||
]);
|
||||
}
|
||||
|
||||
const hint = (live: string | null, saved: string) => {
|
||||
const mono = (t: string) => E('span', { class: 'dl-mono' }, t);
|
||||
if (live) return E('span', {}, [' Now: ', mono(live), ...(saved && saved !== live ? [', was ', mono(saved)] : []), '.']);
|
||||
return E('span', {}, saved ? [' Not found now: using ', mono(saved), '.'] : [' Not found.']);
|
||||
};
|
||||
|
||||
function paint() {
|
||||
const wanSel = E(
|
||||
'select',
|
||||
@@ -195,146 +243,237 @@ export function interfacesCard(serverId: string, title = 'Interfaces'): HTMLElem
|
||||
.map((x) => E('option', { value: x.name, selected: x.name === wanDev ? 'selected' : null }, `${x.name} · zone ${x.zone}`)),
|
||||
) as HTMLSelectElement;
|
||||
|
||||
// What auto-detection finds now; the remembered one (used when nothing is found) only when it differs.
|
||||
const hint = (live: string | null, saved: string) => {
|
||||
const mono = (t: string) => E('span', { class: 'dl-mono' }, t);
|
||||
if (live) return E('span', {}, [' Now: ', mono(live), ...(saved && saved !== live ? [', was ', mono(saved)] : []), '.']);
|
||||
return E('span', {}, saved ? [' Not found now: using ', mono(saved), '.'] : [' Not found.']);
|
||||
};
|
||||
|
||||
const groups = GROUPS.map(([cat, label]) => {
|
||||
const list = d.devices.filter((x) => x.category === cat);
|
||||
return list.length ? E('div', { class: 'dl-ifgroup' }, [E('h4', {}, label), E('div', { class: 'dl-ifgrid' }, list.map(tile))]) : '';
|
||||
});
|
||||
|
||||
const home = homeDevs();
|
||||
const nets = home.flatMap((x) => x.nets.map((n) => [n, x.name] as const));
|
||||
const dirty = snapshot() !== initial;
|
||||
const save = button(
|
||||
'Save',
|
||||
async () => {
|
||||
const r = await attempt(
|
||||
() => api.serverInterfaces(serverId, autoWan, autoWan ? '' : wanDev, autoLan, [...lans], lanLike, mesh),
|
||||
'Interfaces saved',
|
||||
);
|
||||
if (!r) return;
|
||||
take(r, true);
|
||||
if (r.nets_changed && r.lan_only)
|
||||
notify(
|
||||
`${r.lan_only} ${r.lan_only === 1 ? 'person has' : 'people have'} Home-only access: their devices need the configuration again to reach the new networks.`,
|
||||
'warning',
|
||||
10000,
|
||||
// Draft vs saved, per card: [lanLike, autoWan, wan, autoLan, lans].
|
||||
const now = JSON.parse(snapshot()) as unknown[];
|
||||
const was = JSON.parse(initial) as unknown[];
|
||||
const changed = (...i: number[]) => i.some((k) => JSON.stringify(now[k]) !== JSON.stringify(was[k]));
|
||||
const netDirty = changed(0, 1, 2);
|
||||
const homeDirty = changed(3, 4);
|
||||
const save = (on: boolean) =>
|
||||
button(
|
||||
'Save',
|
||||
async () => {
|
||||
const r = await attempt(
|
||||
() => api.serverInterfaces(serverId, autoWan, autoWan ? '' : wanDev, autoLan, [...lans], lanLike, mesh !== 'off', mesh),
|
||||
'Access saved',
|
||||
);
|
||||
},
|
||||
'positive',
|
||||
{ disabled: !dirty },
|
||||
);
|
||||
if (!r) return;
|
||||
take(r, true);
|
||||
if (r.nets_changed && r.lan_only)
|
||||
notify(
|
||||
`${r.lan_only} ${r.lan_only === 1 ? 'person has' : 'people have'} Home-only access: their devices need the configuration again to reach the new networks.`,
|
||||
'warning',
|
||||
10000,
|
||||
);
|
||||
},
|
||||
'positive',
|
||||
{ disabled: !on },
|
||||
);
|
||||
|
||||
dom.content(root, [
|
||||
const internet = E('section', { class: 'dl-setsec dl-ifcard' }, [
|
||||
E('div', { class: 'dl-setsec-body' }, [
|
||||
E('div', { class: 'dl-panel-head' }, [
|
||||
E('h3', {}, title),
|
||||
E('h3', {}, 'Internet'),
|
||||
E('span', { class: 'dl-spacer' }),
|
||||
button([icon('reset'), ' Rescan'], () => load(false), 'neutral', { title: 'Read the interfaces again' }),
|
||||
E('span', { class: 'dl-sub' }, 'People with Internet or Both'),
|
||||
]),
|
||||
E('div', { class: 'dl-setrow' }, [
|
||||
E('div', { class: 'dl-lh-main' }, [
|
||||
E('span', { class: `dl-need-ic ${likeHomeTone()}` }, icon('home')),
|
||||
E('div', { class: 'dl-stack' }, [
|
||||
E('span', { class: 'dl-setrow-label' }, 'Internet like a home device'),
|
||||
E('span', { class: 'dl-sub' }, likeHomeText()),
|
||||
]),
|
||||
]),
|
||||
E('div', { class: 'dl-setrow-ctl dl-if-wanctl' }, [
|
||||
setrow(
|
||||
'home',
|
||||
'Internet like a home device',
|
||||
likeHomeText(),
|
||||
[
|
||||
lanLike && d.needs?.length ? button('Install', () => installMissing('home', d.needs!, () => load(false)), 'positive') : '',
|
||||
sw(lanLike, 'Internet like a home device', (v) => {
|
||||
lanLike = v;
|
||||
paint();
|
||||
}),
|
||||
]),
|
||||
]),
|
||||
E('div', { class: 'dl-setrow' }, [
|
||||
E('div', { class: 'dl-lh-main' }, [
|
||||
E('span', { class: 'dl-need-ic' }, icon('link')),
|
||||
E('div', { class: 'dl-stack' }, [
|
||||
E('span', { class: 'dl-setrow-label' }, 'Devices reach each other'),
|
||||
E(
|
||||
'span',
|
||||
{ class: 'dl-sub' },
|
||||
'Devices of people with Home access can open connections to each other on this server, like home devices do. Internet-only people never.',
|
||||
),
|
||||
]),
|
||||
]),
|
||||
E(
|
||||
'div',
|
||||
{ class: 'dl-setrow-ctl' },
|
||||
sw(mesh, 'Devices reach each other', (v) => {
|
||||
mesh = v;
|
||||
paint();
|
||||
}),
|
||||
),
|
||||
]),
|
||||
E('div', { class: 'dl-setrow' }, [
|
||||
E('div', { class: 'dl-lh-main' }, [
|
||||
E('span', { class: 'dl-need-ic' }, icon('globe')),
|
||||
E('div', { class: 'dl-stack' }, [
|
||||
E('span', { class: 'dl-setrow-label' }, 'Auto-detect WAN'),
|
||||
E('span', { class: 'dl-sub' }, [
|
||||
'The interface with the default route: the server port opens there and Internet access leaves through it.',
|
||||
hint(d.detected.wan, d.saved.wan),
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
E('div', { class: 'dl-setrow-ctl dl-if-wanctl' }, [
|
||||
],
|
||||
likeHomeTone(),
|
||||
),
|
||||
setrow(
|
||||
'globe',
|
||||
'Auto-detect WAN',
|
||||
[
|
||||
'The interface with the default route: the server port opens there and Internet access leaves through it.',
|
||||
hint(d.detected.wan, d.saved.wan),
|
||||
],
|
||||
[
|
||||
autoWan ? '' : wanSel,
|
||||
sw(autoWan, 'Auto-detect WAN', (v) => {
|
||||
autoWan = v;
|
||||
paint();
|
||||
}),
|
||||
]),
|
||||
],
|
||||
),
|
||||
]),
|
||||
E('div', { class: 'dl-setsec-foot' }, [
|
||||
E(
|
||||
'span',
|
||||
{ class: 'dl-sub' },
|
||||
lanLike
|
||||
? ['Internet like a home device', currentWan() ? [' · leaves through ', E('span', { class: 'dl-mono' }, currentWan())] : '']
|
||||
: currentWan()
|
||||
? ['Internet straight to ', E('span', { class: 'dl-mono' }, currentWan())]
|
||||
: 'No WAN found',
|
||||
),
|
||||
save(netDirty),
|
||||
]),
|
||||
]);
|
||||
|
||||
const meshSeg = E(
|
||||
'div',
|
||||
{ class: 'dl-seg sm', role: 'radiogroup', 'aria-label': 'Devices reach each other' },
|
||||
(
|
||||
[
|
||||
['off', 'Off'],
|
||||
['all', 'Everyone'],
|
||||
['circles', 'Circles'],
|
||||
] as const
|
||||
).map(([v, t]) =>
|
||||
E(
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
role: 'radio',
|
||||
class: mesh === v ? 'on' : '',
|
||||
'aria-checked': mesh === v ? 'true' : 'false',
|
||||
// Applies at once, like the choices on a person's page.
|
||||
click: async () => {
|
||||
if (mesh === v) return;
|
||||
if (await attempt(() => api.serverUpdate(serverId, { mesh: v }), `Devices reach each other: ${t}`)) reload();
|
||||
},
|
||||
},
|
||||
t,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
const homeCard = E('section', { class: 'dl-setsec dl-ifcard' }, [
|
||||
E('div', { class: 'dl-setsec-body' }, [
|
||||
E('div', { class: 'dl-panel-head' }, [
|
||||
E('h3', {}, 'Home network'),
|
||||
E('span', { class: 'dl-spacer' }),
|
||||
E('span', { class: 'dl-sub' }, 'People with Home or Both'),
|
||||
button([icon('reset'), ' Rescan'], () => load(false), 'neutral', { title: 'Read the interfaces again' }),
|
||||
]),
|
||||
E('div', { class: 'dl-setrow' }, [
|
||||
E('div', { class: 'dl-lh-main' }, [
|
||||
E('span', { class: 'dl-need-ic' }, icon('network')),
|
||||
E('div', { class: 'dl-stack' }, [
|
||||
E('span', { class: 'dl-setrow-label' }, 'Auto-detect LAN'),
|
||||
E('span', { class: 'dl-sub' }, ['Adds the detected LAN to the home network.', hint(d.detected.lan, d.saved.lan)]),
|
||||
]),
|
||||
]),
|
||||
E(
|
||||
'div',
|
||||
{ class: 'dl-setrow-ctl' },
|
||||
sw(autoLan, 'Auto-detect LAN', (v) => {
|
||||
autoLan = v;
|
||||
paint();
|
||||
}),
|
||||
),
|
||||
]),
|
||||
E('div', { class: 'dl-iflead' }, [
|
||||
E('b', {}, 'Home network'),
|
||||
E(
|
||||
'span',
|
||||
{ class: 'dl-sub' },
|
||||
'What people with Home access can reach, and where their devices can be reached from. Click to add an interface; bridge ports and Wi-Fi in a bridge come with the bridge.',
|
||||
),
|
||||
]),
|
||||
...groups,
|
||||
setrow(
|
||||
'network',
|
||||
'Networks',
|
||||
'Everyone with home access reaches these, unless their page leaves one out; their devices can be reached from here too. Click one to add or remove it.',
|
||||
'',
|
||||
'',
|
||||
netPicker(),
|
||||
),
|
||||
setrow(
|
||||
'link',
|
||||
'Devices reach each other',
|
||||
MESH_TEXT[mesh],
|
||||
meshSeg,
|
||||
'',
|
||||
mesh === 'circles' ? circleChips(st, serverId, reload) : undefined,
|
||||
),
|
||||
bonjourRow(),
|
||||
services,
|
||||
]),
|
||||
E('div', { class: 'dl-setsec-foot' }, [
|
||||
E(
|
||||
'span',
|
||||
{ class: 'dl-sub dl-if-summary' },
|
||||
nets.length
|
||||
? [
|
||||
'Home access reaches ',
|
||||
...nets.flatMap(([n, dev], i) => [i ? ', ' : '', E('span', { class: 'dl-mono' }, n), ` (${dev})`]),
|
||||
lanLike ? ' · Internet like a home device' : currentWan() ? ` · Internet via ${currentWan()}` : '',
|
||||
]
|
||||
: ['No home network: Home access reaches nothing but this router.', currentWan() ? ` Internet via ${currentWan()}.` : ''],
|
||||
? ['Home access reaches ', ...nets.flatMap(([n, dev], i) => [i ? ', ' : '', E('span', { class: 'dl-mono' }, n), ` (${dev})`])]
|
||||
: 'No home network: Home access reaches nothing but this router.',
|
||||
),
|
||||
save,
|
||||
save(homeDirty),
|
||||
]),
|
||||
]);
|
||||
|
||||
// Keep the page where it is: replacing the cards would otherwise jump to the top.
|
||||
const y = window.scrollY;
|
||||
root.style.minHeight = `${root.offsetHeight}px`;
|
||||
dom.content(root, [internet, homeCard]);
|
||||
root.style.minHeight = '';
|
||||
window.scrollTo({ top: y });
|
||||
}
|
||||
|
||||
/** Find home devices: AirPlay, printers and shared Macs listed on Apple devices over the tunnel. */
|
||||
function bonjourRow(): HTMLElement {
|
||||
const b = d.bonjour;
|
||||
const set = async (on: boolean) => {
|
||||
if (await attempt(() => api.serverUpdate(serverId, { bonjour: on }), on ? 'Finding home devices' : 'Home devices no longer listed'))
|
||||
load(false);
|
||||
};
|
||||
const state = b.needs.length
|
||||
? E('span', { class: 'dl-warn' }, ` Needs ${b.needs.join(', ')}.`)
|
||||
: b.on && !b.running
|
||||
? E('span', { class: 'dl-warn' }, ' umdns is not running.')
|
||||
: b.on
|
||||
? ` Listing ${b.services} service${b.services === 1 ? '' : 's'} from home now.`
|
||||
: '';
|
||||
return setrow(
|
||||
'wifi',
|
||||
['Find home devices ', E('span', { class: 'dl-faint dl-w400' }, '· Bonjour')],
|
||||
[
|
||||
'iPhone, iPad and Mac on the VPN see AirPlay, printers and shared Macs at home, as on Wi-Fi. Android and Chromecast look only on the local network.',
|
||||
state,
|
||||
],
|
||||
b.needs.length
|
||||
? button('Install', () => installMissing('bonjour', b.needs, () => load(false)), 'positive')
|
||||
: sw(b.on, 'Find home devices', (v) => set(v)),
|
||||
b.on && b.running ? 'ok' : '',
|
||||
);
|
||||
}
|
||||
|
||||
/** Interfaces that can be home networks as tiles; the rest folded, by kind. */
|
||||
function netPicker(): HTMLElement {
|
||||
const avail = d.devices.filter(pickable);
|
||||
const rest = d.devices.filter((x) => !pickable(x));
|
||||
return E('div', { class: 'dl-stack gap8 dl-netpick' }, [
|
||||
avail.length
|
||||
? E('div', { class: 'dl-ifgrid' }, avail.map(tile))
|
||||
: E('span', { class: 'dl-warn' }, 'No home network: Home access reaches nothing but this router.'),
|
||||
E('label', { class: 'dl-boxrow' }, [
|
||||
E('span', { class: 'dl-stack' }, [
|
||||
E('span', {}, 'Auto-detect LAN'),
|
||||
E('span', { class: 'dl-sub' }, ['Adds the LAN this router uses.', hint(d.detected.lan, d.saved.lan)]),
|
||||
]),
|
||||
sw(autoLan, 'Auto-detect LAN', (v) => {
|
||||
autoLan = v;
|
||||
paint();
|
||||
}),
|
||||
]),
|
||||
rest.length
|
||||
? E(
|
||||
'details',
|
||||
{
|
||||
class: 'dl-params',
|
||||
open: otherOpen ? '' : null,
|
||||
toggle: (ev: Event) => (otherOpen = (ev.currentTarget as HTMLDetailsElement).open),
|
||||
},
|
||||
[
|
||||
E('summary', {}, [
|
||||
icon('chevron'),
|
||||
E('span', {}, 'Other interfaces'),
|
||||
E('span', { class: 'dl-pcount' }, String(rest.length)),
|
||||
]),
|
||||
E('div', { class: 'dl-params-body' }, [
|
||||
E(
|
||||
'span',
|
||||
{ class: 'dl-sub' },
|
||||
'The WAN, this server, ports and Wi-Fi of a bridge (they come with it) and interfaces without an IPv4 network.',
|
||||
),
|
||||
...GROUPS.map(([cat, label]) => {
|
||||
const list = rest.filter((x) => x.category === cat);
|
||||
return list.length
|
||||
? E('div', { class: 'dl-ifgroup' }, [E('h4', {}, label), E('div', { class: 'dl-ifgrid' }, list.map(tile))])
|
||||
: '';
|
||||
}),
|
||||
]),
|
||||
],
|
||||
)
|
||||
: '',
|
||||
]);
|
||||
}
|
||||
|
||||
load(true);
|
||||
|
||||
@@ -73,6 +73,11 @@ export function eventText(st: Status, e: LogEvent): Node[] {
|
||||
const b = (t: string) => E('b', {}, t);
|
||||
const m = (t: string) => E('span', { class: 'dl-muted' }, t);
|
||||
const mono = (t: string) => E('span', { class: 'dl-mono' }, t);
|
||||
/** An address; at home, the name of the device that has it, with the address in brackets. */
|
||||
const addr = (ip: string) =>
|
||||
e.hosts?.[ip]
|
||||
? [E('span', { class: 'dl-ev-host' }, [E('b', {}, e.hosts[ip]), E('span', { class: 'dl-faint' }, ` (${ip})`)])]
|
||||
: [mono(ip)];
|
||||
// What the bold name is (a person, a device), said before it in grey.
|
||||
const kind = (t: string) => E('span', { class: 'dl-ev-kind' }, `${t} `);
|
||||
const wd = dev ? `${who} · ${dev}` : who;
|
||||
@@ -116,13 +121,18 @@ export function eventText(st: Status, e: LogEvent): Node[] {
|
||||
kind('Device'),
|
||||
b(wd),
|
||||
m(' connected'),
|
||||
...(e.detail ? [m(' from '), mono(e.detail)] : []),
|
||||
...(e.detail ? [m(' from '), ...addr(e.detail)] : []),
|
||||
...(e.where ? [m(` · ${e.where}`)] : []),
|
||||
];
|
||||
case 'disconnect':
|
||||
return [kind('Device'), b(wd), m(' went offline')];
|
||||
case 'roam':
|
||||
return [kind('Device'), b(wd), m(' changed network '), mono(e.detail ?? '')];
|
||||
return [
|
||||
kind('Device'),
|
||||
b(wd),
|
||||
m(' changed network '),
|
||||
...(e.detail ?? '').split(' → ').flatMap((ip, i) => (i ? [m(' → '), ...addr(ip)] : addr(ip))),
|
||||
];
|
||||
case 'device_added':
|
||||
return [
|
||||
kind('Person'),
|
||||
|
||||
@@ -29,6 +29,7 @@ import { attachTip } from '../charts';
|
||||
import { peopleUrl } from '../urls';
|
||||
import { daysTile, eventRow, eventText, speedTile } from './overview';
|
||||
import { stateBadge } from './people';
|
||||
import { circleDialog, circleDot, homeAccess } from '../access';
|
||||
|
||||
type Step = 'day' | 'week' | 'month' | 'year' | 'custom';
|
||||
|
||||
@@ -657,9 +658,10 @@ export class PersonPage {
|
||||
seg,
|
||||
E('span', { class: 'dl-sub' }, ACCESS_TEXT[p.access]),
|
||||
p.access === 'lan' && this.st.services.length ? this.servicesPicker() : '',
|
||||
homeAccess(p) ? this.netsPicker() : '',
|
||||
p.access === 'lan' ? this.dnsPicker() : '',
|
||||
]),
|
||||
E('div', { class: 'dl-tiles2' }, [this.devTile(), endTile, dataTile, hoursTile]),
|
||||
E('div', { class: 'dl-tiles2' }, [this.devTile(), this.circleTile(), endTile, dataTile, hoursTile]),
|
||||
]),
|
||||
]),
|
||||
);
|
||||
@@ -720,6 +722,87 @@ export class PersonPage {
|
||||
]);
|
||||
}
|
||||
|
||||
/** Home networks this person reaches, when the server has more than one. */
|
||||
netsPicker(): HTMLElement | '' {
|
||||
const p = this.p;
|
||||
const srv = this.st.servers.find((x) => x.id === p.server);
|
||||
const all = srv?.home ?? [];
|
||||
if (all.length < 2) return '';
|
||||
const picked = new Set(p.home_nets?.length ? p.home_nets : all.map((h) => h.dev));
|
||||
return E('div', { class: 'dl-stack gap4' }, [
|
||||
E(
|
||||
'div',
|
||||
{ class: 'dl-chips-row' },
|
||||
all.map((h) =>
|
||||
E(
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
class: `dl-chipbtn${picked.has(h.dev) ? ' on' : ''}`,
|
||||
'aria-pressed': picked.has(h.dev) ? 'true' : 'false',
|
||||
title: h.nets.join(', '),
|
||||
click: () => {
|
||||
const next = new Set(picked);
|
||||
if (!next.delete(h.dev)) next.add(h.dev);
|
||||
if (!next.size) return notify('Keep at least one network, or choose Internet only.', 'warning', 5000);
|
||||
const list = next.size === all.length ? [] : [...next];
|
||||
this.patch(
|
||||
{ home_nets: list },
|
||||
list.length ? `${p.name} reaches ${list.join(', ')}` : `${p.name} reaches every home network`,
|
||||
);
|
||||
},
|
||||
},
|
||||
h.dev,
|
||||
),
|
||||
),
|
||||
),
|
||||
E(
|
||||
'span',
|
||||
{ class: 'dl-sub' },
|
||||
p.home_nets?.length
|
||||
? `Home networks ${p.name} reaches. Networks added to the server later stay out.`
|
||||
: `Home networks ${p.name} reaches: all of them. Untick one to keep ${p.name} out of it.`,
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/** The circle this person's devices share (servers where devices reach each other in circles). */
|
||||
circleTile(): HTMLElement | '' {
|
||||
const p = this.p;
|
||||
const srv = this.st.servers.find((x) => x.id === p.server);
|
||||
if (srv?.mesh !== 'circles' || !homeAccess(p)) return '';
|
||||
const circles = this.st.circles.filter((c) => c.server === p.server);
|
||||
const ci = circles.find((c) => c.id === p.circle);
|
||||
const mates = ci ? this.st.people.filter((x) => x.id !== p.id && x.circle === ci.id && homeAccess(x)).map((x) => x.name) : [];
|
||||
const change: HTMLElement = button('Change', () =>
|
||||
dropdown(change, [
|
||||
...circles.map((c) => ({
|
||||
label: c.name,
|
||||
icon: circleDot(c),
|
||||
run: () => c.id !== p.circle && this.patch({ circle: c.id }, `${p.name} is in ${c.name}`),
|
||||
})),
|
||||
p.circle ? { label: 'No circle', icon: icon('x'), run: () => this.patch({ circle: '' }, `${p.name} is in no circle`) } : null,
|
||||
{ label: 'New circle', icon: icon('plus'), run: () => circleDialog(this.st, p.server, null, () => this.refresh()) },
|
||||
]),
|
||||
);
|
||||
return E('div', { class: 'dl-tile2' }, [
|
||||
E('span', { class: 'dl-tile2-label' }, ['Devices see each other', E('span', { class: 'dl-faint dl-w400' }, 'circle')]),
|
||||
E('div', { class: 'dl-tile2-row' }, [
|
||||
E('span', { class: 'dl-circle-name' }, ci ? [circleDot(ci), ci.name] : E('span', { class: 'dl-muted' }, 'No circle')),
|
||||
change,
|
||||
]),
|
||||
E(
|
||||
'span',
|
||||
{ class: 'dl-sub' },
|
||||
!ci
|
||||
? `Only ${p.name}'s own devices see each other.`
|
||||
: mates.length
|
||||
? `${p.name}'s devices and ${mates.join(', ')}'s see each other. Others don't.`
|
||||
: `Nobody else in ${ci.name} yet: only ${p.name}'s own devices see each other.`,
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/** Optional narrowing of home-network access to selected services. */
|
||||
servicesPicker(): HTMLElement {
|
||||
const chosen = new Set(this.p.services ?? []);
|
||||
|
||||
@@ -9,7 +9,8 @@ import { api, type SetupDefaults } from '../api';
|
||||
import { attempt, button, callout, closeModal, confirmDialog, copyText, modal, notify } from '../ui';
|
||||
import { icon } from '../../shared/icons';
|
||||
import { duration } from '../../shared/format';
|
||||
import { interfacesCard } from '../interfaces';
|
||||
import { accessCards } from '../interfaces';
|
||||
import { checkAccess, whoReaches } from '../access';
|
||||
import { card, group, input, row, sw } from '../kit';
|
||||
import { methodInfo, methodPicker, type Method } from '../disguise';
|
||||
import { ServerOverview } from './overview';
|
||||
@@ -426,48 +427,12 @@ export class ServerPage {
|
||||
);
|
||||
}
|
||||
|
||||
/** Where devices may go and how their traffic leaves: internet path, WAN, home network, services. */
|
||||
/** Where devices may go and how their traffic leaves: internet path, home network, services, circles. */
|
||||
access(srv: Server): HTMLElement {
|
||||
const svcs = this.st.services;
|
||||
const reload = () => this.refresh();
|
||||
return E('div', { class: 'dl-stack gap16' }, [
|
||||
interfacesCard(srv.id, 'Access'),
|
||||
card(
|
||||
'Home services',
|
||||
[
|
||||
E(
|
||||
'p',
|
||||
{ class: 'dl-muted' },
|
||||
'People with Home-only access can be limited to these services instead of the whole home network (chosen per person). The list is shared by all servers.',
|
||||
),
|
||||
E(
|
||||
'div',
|
||||
{ class: 'dl-list' },
|
||||
svcs.length
|
||||
? svcs.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'}`,
|
||||
),
|
||||
]),
|
||||
]),
|
||||
)
|
||||
: [E('div', { class: 'dl-row dl-muted' }, 'No services yet.')],
|
||||
),
|
||||
],
|
||||
[
|
||||
E('span'),
|
||||
E(
|
||||
'a',
|
||||
{ class: 'cbi-button cbi-button-neutral', href: `${L.url('admin/network/dawnline/settings')}#dl-set-services` },
|
||||
'Edit in Settings',
|
||||
),
|
||||
],
|
||||
),
|
||||
accessCards(srv, this.st, reload),
|
||||
E('div', { class: 'dl-health-cols' }, [whoReaches(this.st, srv), checkAccess(this.st, srv)]),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { E } from '../e';
|
||||
import { api, type Backup, type SettingsData } from '../api';
|
||||
import { attempt, button, closeModal, confirmDialog, modal } from '../ui';
|
||||
import { attempt, button, closeModal, modal } from '../ui';
|
||||
import { icon } from '../../shared/icons';
|
||||
import { group, input, isOn, row, sw } from '../kit';
|
||||
import { CATEGORIES, CATEGORY_HELP, CATEGORY_LABEL, clearLogDialog, exportEvents, resetUsageDialog } from '../logs';
|
||||
@@ -525,43 +525,6 @@ export class SettingsPage {
|
||||
|
||||
const logs = this.logsSection();
|
||||
|
||||
// Home services
|
||||
const svcRows = this.d.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', () => this.editService(sv)),
|
||||
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'))
|
||||
)
|
||||
this.reload();
|
||||
},
|
||||
'negative',
|
||||
{ title: 'Remove' },
|
||||
),
|
||||
]),
|
||||
);
|
||||
const services = this.section(
|
||||
'services',
|
||||
'Home services',
|
||||
[
|
||||
E(
|
||||
'p',
|
||||
{ class: 'dl-muted' },
|
||||
'Give people with home-network access only specific services instead of the whole network (choose them per person).',
|
||||
),
|
||||
E('div', { class: 'dl-list' }, svcRows.length ? svcRows : [E('div', { class: 'dl-row dl-muted' }, 'No services yet.')]),
|
||||
],
|
||||
[E('span'), button([icon('plus'), ' Add service'], () => this.editService(null), 'add')],
|
||||
);
|
||||
|
||||
const danger = this.section(
|
||||
'danger',
|
||||
'Remove Dawnline from this router',
|
||||
@@ -580,7 +543,7 @@ export class SettingsPage {
|
||||
this.reload();
|
||||
this.loadBackups();
|
||||
});
|
||||
dom.content(this.root, [portal, defaults, map, logs, services, backups, danger]);
|
||||
dom.content(this.root, [portal, defaults, map, logs, backups, danger]);
|
||||
}
|
||||
|
||||
logsSection(): HTMLElement {
|
||||
@@ -771,41 +734,6 @@ export class SettingsPage {
|
||||
}
|
||||
}
|
||||
|
||||
editService(sv: SettingsData['services'][number] | null) {
|
||||
const name = input(sv?.name ?? '', { placeholder: 'NAS' });
|
||||
const addr = input(sv?.address ?? '', { placeholder: '192.168.1.10' });
|
||||
const ports = input(sv?.ports.join(', ') ?? '', { placeholder: 'All ports, or e.g. 445, 5000' });
|
||||
modal(
|
||||
sv ? `Edit ${sv.name}` : 'Add service',
|
||||
[
|
||||
E('div', { class: 'cbi-value' }, [E('label', { class: 'cbi-value-title' }, 'Name'), E('div', { class: 'cbi-value-field' }, name)]),
|
||||
E('div', { class: 'cbi-value' }, [
|
||||
E('label', { class: 'cbi-value-title' }, 'Address'),
|
||||
E('div', { class: 'cbi-value-field' }, addr),
|
||||
]),
|
||||
E('div', { class: 'cbi-value' }, [
|
||||
E('label', { class: 'cbi-value-title' }, 'Ports'),
|
||||
E('div', { class: 'cbi-value-field' }, ports),
|
||||
]),
|
||||
],
|
||||
[
|
||||
E('button', { class: 'cbi-button cbi-button-neutral', click: closeModal }, 'Cancel'),
|
||||
' ',
|
||||
button(
|
||||
'Save',
|
||||
async () => {
|
||||
const list = ports.value.split(/[ ,]+/).filter(Boolean);
|
||||
if (await attempt(() => api.serviceSet(sv?.id ?? '', name.value, addr.value, list), 'Saved')) {
|
||||
closeModal();
|
||||
this.reload();
|
||||
}
|
||||
},
|
||||
'positive',
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
uninstall() {
|
||||
const confirmInput = input('', { placeholder: 'remove' });
|
||||
modal(
|
||||
|
||||
@@ -4,7 +4,12 @@
|
||||
import { api, type Needs } from './api';
|
||||
import { attempt, confirmDialog, notify } from './ui';
|
||||
|
||||
const WHAT: Record<keyof Needs, string> = { https: 'HTTPS for the portal', acme: 'ACME certificates', home: 'the home-like link' };
|
||||
const WHAT: Record<keyof Needs, string> = {
|
||||
https: 'HTTPS for the portal',
|
||||
acme: 'ACME certificates',
|
||||
home: 'the home-like link',
|
||||
bonjour: 'Bonjour for home devices',
|
||||
};
|
||||
const WAIT_MS = 5 * 60 * 1000;
|
||||
|
||||
/** Install `names` for `feature`; resolves true when the job finished, then calls `done`. */
|
||||
|
||||
@@ -1072,6 +1072,46 @@ const CSS = `
|
||||
.dl-upd-row > .dl-pill, .dl-upd-row > button, .dl-upd-head > .dl-pill, .dl-upd-head > button { flex: none; }
|
||||
.dl-upd-bad { color: var(--dl-bad); }
|
||||
.dl-upd-job > .dl-log, .dl-upd-job > .alert-message { margin: 0 14px 14px; }
|
||||
|
||||
/* Server → Access: networks as chips, circles, services from home, who reaches what, check access. */
|
||||
.dl-chip.static { cursor: default; } .dl-chip.static:hover { background: var(--dl-soft); }
|
||||
.dl-chip.static .dl-chip-name { font-weight: 500; }
|
||||
.dl-setrow.head .dl-chips-row { margin-top: 8px; }
|
||||
.dl-setrow.head > .dl-lh-main, .dl-setrow.head > .dl-lh-main > .dl-stack { flex: 1 1 auto; min-width: 0; }
|
||||
.dl-setrow.head > .dl-setrow-ctl:empty { display: none; }
|
||||
.dl-setrow.head:has(> .dl-lh-main) { align-items: flex-start; }
|
||||
.dl-setrow.head > .dl-setrow-ctl { align-items: center; min-height: 30px; }
|
||||
.dl-netpick { margin-top: 10px; }
|
||||
.dl-boxrow { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 0; padding: 10px 14px; border: 1px solid var(--dl-line); border-radius: 12px; font-size: 13px; cursor: pointer; }
|
||||
.dl-boxrow > .dl-switch { flex: none; }
|
||||
.dl-ifpick { display: flex; flex-direction: column; gap: 12px; padding: 14px; border: 1px solid var(--dl-line); border-radius: 14px; }
|
||||
.dl-iflead-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
||||
.dl-host-ports { justify-content: flex-end; }
|
||||
@media (max-width: 760px) { .dl-host-ports { justify-content: flex-start; } }
|
||||
.dl-circle-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }
|
||||
.dl-circles .dl-chip b { font-weight: 500; }
|
||||
.dl-circle-name { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; }
|
||||
.dl-w400 { font-weight: 400; }
|
||||
.dl-swatches { display: flex; flex-wrap: wrap; gap: 8px; }
|
||||
.dl-swatch { all: unset; cursor: pointer; width: 22px; height: 22px; border-radius: 50%; background: var(--sw); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--dl-fg) 12%, transparent); }
|
||||
.dl-swatch.on { box-shadow: 0 0 0 2px var(--dl-card), 0 0 0 4px var(--sw); }
|
||||
.dl-swatch:focus-visible { outline: 2px solid var(--dl-ring); outline-offset: 3px; }
|
||||
.dl-circle-modal .dl-chipbtn b { margin-left: 6px; font-weight: 500; font-size: 11px; opacity: .6; }
|
||||
.dl-reach td:first-child b { font-weight: 500; }
|
||||
.dl-ev-host { white-space: nowrap; } .dl-ev-host b { font-weight: 500; color: var(--dl-fg); }
|
||||
.dl-reach { font-size: 13px; } .dl-reach th, .dl-reach td { white-space: nowrap; padding-left: 6px; padding-right: 6px; }
|
||||
.dl-reach-wrap { overflow-x: auto; }
|
||||
.dl-yes { display: inline-flex; align-items: center; gap: 4px; color: var(--dl-ok); }
|
||||
.dl-yes .dl-icon-wrap { display: inline-flex; } .dl-yes .dl-icon { width: 14px; height: 14px; }
|
||||
.dl-check-form { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto; align-items: start; gap: 8px; }
|
||||
.dl-check-form > .dl-faint { line-height: 36px; }
|
||||
.dl-check-end { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
|
||||
.dl-check-end > * { width: 100% !important; min-width: 0; }
|
||||
@media (max-width: 560px) { .dl-check-form { grid-template-columns: minmax(0, 1fr); } .dl-check-form > .dl-faint { display: none; } }
|
||||
.dl-verdict { display: flex; align-items: baseline; gap: 10px; padding: 10px 12px; border-radius: 12px; }
|
||||
.dl-verdict b { font-weight: 500; }
|
||||
.dl-verdict.ok { background: var(--dl-ok-wash); } .dl-verdict.ok b { color: var(--dl-ok); }
|
||||
.dl-verdict.bad { background: var(--dl-bad-wash); } .dl-verdict.bad b { color: var(--dl-bad); }
|
||||
`;
|
||||
|
||||
/** A <style> element for the view root (see the note at the top). */
|
||||
|
||||
Reference in new issue
Block a user