Dawnline 0.2.0

- Diagnostics page: Health and Log tabs in place of Health and Activity
- Watchdog: repairs the AmneziaWG module, tunnels, nft table, firewall
  rules, uhttpd portal setting, portal, resolver and rpcd after two bad
  checks in a row, with backoff; after 3 failed repairs logs once in red,
  keeps repairing quietly and logs "restored" when it works again
- Heartbeat cron job restarts a hung agent
- Service log: tunnel and service starts with reasons (restarted, router
  start, update, crash), stops Dawnline made itself vs unexpected ones,
  certificate renewal and expiry, WAN address changes
- Admin actions logged as "You ..." with their own icon and tint; every
  event has an icon tile; names kept for removed people and devices;
  server pill on events when there are several servers
- Log filters: All, Connections, People, System, Problems; search and the
  command palette removed
- Home network reaches people's devices: fw4 forwarding from the home
  zones, limited to people with home access
- "Devices reach each other" per server, in the Access card
- Portal: "This device" card first with a dotted border, key rotation and
  copy address in the menu, devices sorted Online/Offline/Not set up/Paused,
  over-limit slots in orange
- People cards: slot bar, Online / Never connected, add chip always shown
- Person and device pages: Add device tile, Connect at the bottom with
  File/Key/QR tabs, status text without dots; pulsing server tab dot
- Server pill: Running / Not running / Turned off
This commit is contained in:
Aemeath committed 2026-10-15 17:05:24 +03:00
1 parent d0955e44b8
commit 82ab86848e
50 files changed
+2166 -982

No files matched your search

+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "dawnline-web",
"version": "0.1.1",
"version": "0.2.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "dawnline-web",
"version": "0.1.1",
"version": "0.2.0",
"license": "MIT",
"dependencies": {
"qrcode-generator": "1.4.4"
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "dawnline-web",
"version": "0.1.1",
"version": "0.2.0",
"private": true,
"license": "MIT",
"type": "module",
+46 -5
View File
@@ -114,7 +114,7 @@ export interface SettingsData {
logs: LogsInfo;
}
export type LogCategory = 'connections' | 'devices' | 'people' | 'problems';
export type LogCategory = 'connections' | 'people' | 'problems';
export interface LogsInfo {
policy: {
@@ -178,7 +178,7 @@ 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 };
config: { auto_wan: boolean; wan_device: string; auto_lan: boolean; lan_devices: string[]; lan_like: boolean; device_mesh: boolean };
like_home: LikeHome;
effective: {
wan: { dev: string | null; zone: string; auto: boolean; missing: boolean };
@@ -275,6 +275,37 @@ async function status(days?: number): Promise<Status> {
return st;
}
/** One line of the service log: tunnel and service starts, stops, watchdog repairs, errors. */
export interface ServiceLogEntry {
ts: number;
src: 'awg' | 'dawnline' | 'portal';
level: 'info' | 'up' | 'down' | 'repair' | 'error';
msg: string;
detail?: string;
/** Subject shown first: a server's name, "Personal portal", "Dawnline" (older entries have none). */
who?: string;
/** The admin's own changes read "You <msg> <kind> <who> · <note>". */
by?: 'admin';
kind?: string;
note?: string;
}
export interface ServiceLog {
watchdog: {
enabled: boolean;
/** Last watchdog pass and last agent tick (null: never). */
last: number | null;
beat: number | null;
now: number;
targets: { id: string; name: string; ok: boolean; tries: number }[];
/** Repairs in the last 24 hours; id is the Health check id. */
repairs: { ts: number; id: string; name: string }[];
};
log: ServiceLogEntry[];
}
export type Health = { checks: HealthCheck[] } & ServiceLog;
export const api = {
personUpdate,
settingsGet: call<SettingsData>('settings_get'),
@@ -285,7 +316,15 @@ export const api = {
events: call<{ events: LogEvent[]; total: number; policy: LogsInfo['policy'] }>('events', ['limit']),
logsClear,
interfaces: call<InterfacesData>('interfaces', ['id']),
serverInterfaces: call<InterfacesData>('server_interfaces', ['id', 'auto_wan', 'wan_device', 'auto_lan', 'lan_devices', 'lan_like']),
serverInterfaces: call<InterfacesData>('server_interfaces', [
'id',
'auto_wan',
'wan_device',
'auto_lan',
'lan_devices',
'lan_like',
'device_mesh',
]),
usageClear: call<unknown>('usage_clear', ['scope', 'id']),
uninstall: call<unknown>('uninstall', ['confirm']),
status,
@@ -329,8 +368,10 @@ export const api = {
deviceDelete: call<unknown>('device_delete', ['id']),
deviceRotate: call<ClientConfig>('device_rotate', ['id']),
apply: call<unknown>('apply'),
health: call<{ checks: HealthCheck[] }>('health'),
healthFix: call<{ checks: HealthCheck[] }>('health_fix', ['id']),
health: call<Health>('health'),
healthFix: call<Health>('health_fix', ['id']),
serviceLog: call<ServiceLog>('service_log'),
serviceLogClear: call<{ removed: number }>('service_log_clear', ['older_days']),
backupList: call<{ backups: Backup[] }>('backup_list'),
backupCreate: call<{ name: string }>('backup_create'),
backupRestore: call<unknown>('backup_restore', ['name']),
+72 -73
View File
@@ -9,6 +9,7 @@ import { qrSvg } from '../shared/qr';
import { vpnKey } from '../shared/vpnkey';
import { ago, bytes, KIND_LABEL, KINDS } from '../shared/format';
import { icon } from '../shared/icons';
import { eventBy } from './pages/overview';
import { spark } from './charts';
import { clearLogDialog, exportEvents, resetUsageDialog } from './logs';
@@ -20,7 +21,7 @@ function iso(ts: number): string {
: '—';
}
function copyRow(label: string, value: string, mono = true): HTMLElement {
function copyRow(label: string, value: string, mono = false): HTMLElement {
return E('div', { class: 'dl-kvrow' }, [
E('span', { class: 'dl-kvrow-k' }, label),
E(
@@ -106,8 +107,8 @@ function fileCard(cfg: ClientConfig): HTMLElement {
]);
}
/** QR / key / file switcher for a client configuration. */
export async function connectBlock(cfg: ClientConfig): Promise<HTMLElement> {
/** File / key / QR switcher for a client configuration; opens on the file unless asked otherwise. */
export async function connectBlock(cfg: ClientConfig, initial: 'file' | 'key' | 'qr' = 'file'): Promise<HTMLElement> {
if (!cfg.has_private_key)
return E(
'div',
@@ -135,12 +136,12 @@ export async function connectBlock(cfg: ClientConfig): Promise<HTMLElement> {
dom.content(body, panes[id]());
};
for (const [id, label] of [
['qr', 'QR code'],
['key', 'Key'],
['file', 'File'],
['key', 'Key'],
['qr', 'QR code'],
])
seg.appendChild(E('button', { type: 'button', 'data-id': id, click: () => show(id) }, label));
show('qr');
show(initial);
return E('div', { class: 'dl-stack gap12' }, [seg, body]);
}
@@ -183,12 +184,13 @@ function drawer(title: Node, body: Node, foot: Node | null, onClose: () => void)
return handle;
}
const DEV_EVENT: Record<string, [string, string]> = {
connect: ['ok', 'Connected'],
disconnect: ['', 'Went offline'],
roam: ['', 'Changed network'],
device_added: ['accent', 'Added'],
device_removed: ['', 'Removed'],
const DEV_EVENT: Record<string, [string, string, string]> = {
connect: ['ok', 'Connected', 'plug'],
disconnect: ['', 'Went offline', 'plug'],
roam: ['', 'Changed network', 'network'],
device_added: ['ok', 'Added', 'plus'],
device_removed: ['', 'Removed', 'trash'],
device_keys: ['', 'New keys', 'reset'],
};
/** Activity of one device, newest first. */
@@ -202,21 +204,24 @@ function deviceEvents(events: LogEvent[], id: string): HTMLElement {
'div',
{ class: 'dl-dev-log' },
mine.map((e) => {
const [tone, label] = DEV_EVENT[e.type];
const [tone, label, ic] = DEV_EVENT[e.type];
// As in the main log: what happened in the text colour, the details muted.
const extra =
e.type === 'connect'
? [
e.detail ? E('span', { class: 'dl-mono' }, ` ${e.detail}`) : '',
e.where ? E('span', { class: 'dl-faint' }, ` · ${e.where}`) : '',
e.detail ? E('span', { class: 'dl-muted' }, ` from ${e.detail}`) : '',
e.where ? E('span', { class: 'dl-muted' }, ` · ${e.where}`) : '',
]
: e.type === 'roam'
? [E('span', { class: 'dl-mono dl-faint' }, ` ${e.detail ?? ''}`)]
: e.type === 'device_added'
? [E('span', { class: 'dl-faint' }, (e.detail ?? '').includes('(portal)') ? ' from the portal' : ' by you')]
? [E('span', { class: 'dl-muted' }, ` · ${e.detail ?? ''}`)]
: e.type === 'device_added' || e.type === 'device_removed' || e.type === 'device_keys'
? [E('span', { class: 'dl-muted' }, eventBy(e) === 'portal' ? ' on the portal' : eventBy(e) === 'admin' ? ' by you' : '')]
: [];
const t = new Date(e.ts * 1000);
return E('div', { class: 'dl-dev-log-row' }, [
E('span', { class: `dl-ev-dot ${tone}` }),
return E('div', { class: `dl-dev-log-row${eventBy(e) === 'admin' ? ' dl-ev-by-admin' : ''}` }, [
eventBy(e) === 'admin'
? E('span', { class: 'dl-ev-tile', title: 'Done by you in LuCI' }, icon('admin'))
: E('span', { class: `dl-ev-tile ev ${tone}` }, icon(ic)),
E('span', { class: 'dl-row-main' }, [E('span', {}, label), ...extra]),
E('span', { class: 'dl-faint dl-nowrap', title: t.toLocaleString() }, ago(e.ts)),
]);
@@ -225,10 +230,11 @@ function deviceEvents(events: LogEvent[], id: string): HTMLElement {
}
function statusLine(d: Device): HTMLElement {
if (d.disabled) return E('span', { class: 'dl-dstat' }, [E('i', { class: 'dot' }), 'Disabled']);
if (d.online) return E('span', { class: 'dl-dstat ok' }, [E('i', { class: 'dot ok' }), `Online from ${d.endpoint}`]);
if (!d.handshake) return E('span', { class: 'dl-dstat warn' }, [E('i', { class: 'dot warn' }), 'Waiting for the first connection']);
return E('span', { class: 'dl-dstat' }, [E('i', { class: 'dot' }), `Last seen ${ago(d.handshake)}`]);
// Status as coloured text, no dots (only avatars carry one).
if (d.disabled) return E('span', { class: 'dl-dstat' }, 'Disabled');
if (d.online) return E('span', { class: 'dl-dstat ok' }, 'Connected');
if (!d.handshake) return E('span', { class: 'dl-dstat warn' }, 'Waiting for the first connection');
return E('span', { class: 'dl-dstat' }, `Last seen ${ago(d.handshake)}`);
}
/** Device drawer; `refresh` reloads the page after changes. */
@@ -241,7 +247,6 @@ export async function openDevice(person: Person, dev: Device, refresh: () => unk
const titleEl = E('div', { class: 'dl-drawer-title' });
const stats = E('div', {});
const details = E('div', {});
const live = E('div', { class: 'dl-live' });
const log = E('div', {}, E('div', { class: 'dl-sub' }, 'Loading…'));
let logEvents: LogEvent[] = [];
const loadLog = async () => {
@@ -289,8 +294,8 @@ export async function openDevice(person: Person, dev: Device, refresh: () => unk
? row(
'Client IP',
E('span', {}, [
E('span', { class: 'dl-mono' }, d.endpoint),
place ? E('span', { class: 'dl-faint' }, ` · ${[place.city, place.org].filter(Boolean).join(' · ')}`) : '',
d.endpoint,
place ? E('span', { class: 'dl-muted' }, ` · ${[place.city, place.org].filter(Boolean).join(' · ')}`) : '',
]),
)
: '',
@@ -316,14 +321,6 @@ export async function openDevice(person: Person, dev: Device, refresh: () => unk
),
]),
);
dom.content(
live,
d.online
? [E('i', { class: 'dot ok' }), E('span', { class: 'dl-ok' }, 'Connected')]
: d.handshake
? [E('i', { class: 'dot' }), E('span', { class: 'dl-muted' }, `Last connected ${ago(d.handshake)}`)]
: [E('i', { class: 'dot warn pulse' }), E('span', { class: 'dl-muted' }, 'Waiting for the first connection…')],
);
dom.content(foot, [
button(
[icon(d.disabled ? 'play' : 'pause'), d.disabled ? ' Enable' : ' Disable'],
@@ -413,47 +410,49 @@ export async function openDevice(person: Person, dev: Device, refresh: () => unk
};
const foot = E('div', { class: 'dl-drawer-actions' });
const body = E('div', { class: 'dl-stack gap16' }, [
stats,
E('section', { class: 'dl-dsec' }, [
E('div', { class: 'dl-dsec-head' }, [E('h4', {}, 'Connect'), live]),
d.config_stale
? E('div', { class: 'dl-note warn' }, [
icon('alert'),
E(
'span',
{},
'This device has an older configuration: networks or DNS changed since it was set up. Import it again with the QR code, key or file below.',
),
])
: '',
connect,
]),
E('section', { class: 'dl-dsec' }, [
E('div', { class: 'dl-dsec-head' }, [
E('h4', {}, 'Activity'),
E('div', { class: 'dl-dsec-actions' }, [
const connectSec = E('section', { class: 'dl-dsec' }, [
// Whether it is connected (or still waiting) is in Status above.
E('div', { class: 'dl-dsec-head' }, [E('h4', {}, 'Connect')]),
d.config_stale
? E('div', { class: 'dl-note warn' }, [
icon('alert'),
E(
'button',
{ type: 'button', class: 'dl-linkbtn', click: () => exportEvents({ people: [p] }, logEvents, 'csv', d.id) },
'Export',
'span',
{},
'This device has an older configuration: networks or DNS changed since it was set up. Import it again with the QR code, key or file below.',
),
E(
'button',
{
type: 'button',
class: 'dl-linkbtn danger',
click: () => clearLogDialog(`Clear ${d.name}'s activity`, `Removes events about ${d.name}.`, { device: d.id }, loadLog),
},
'Clear',
),
E('a', { href: L.url('admin/network/dawnline/activity') }, 'All activity'),
]),
]),
log,
]),
E('section', { class: 'dl-dsec' }, [E('div', { class: 'dl-dsec-head' }, E('h4', {}, 'Details')), details]),
])
: '',
connect,
]);
const activitySec = E('section', { class: 'dl-dsec' }, [
E('div', { class: 'dl-dsec-head' }, [
E('h4', {}, 'Activity'),
E('div', { class: 'dl-dsec-actions' }, [
E('button', { type: 'button', class: 'dl-linkbtn', click: () => exportEvents({ people: [p] }, logEvents, 'csv', d.id) }, 'Export'),
E(
'button',
{
type: 'button',
class: 'dl-linkbtn danger',
click: () => clearLogDialog(`Clear ${d.name}'s activity`, `Removes events about ${d.name}.`, { device: d.id }, loadLog),
},
'Clear',
),
E('a', { href: `${L.url('admin/network/dawnline/diagnostics')}?tab=log` }, 'All activity'),
]),
]),
log,
]);
const detailsSec = E('section', { class: 'dl-dsec' }, [E('div', { class: 'dl-dsec-head' }, E('h4', {}, 'Details')), details]);
// Connecting is what the drawer is for until the device is set up (or its configuration is old);
// after that it goes to the bottom.
const setUp = !d.handshake || d.config_stale;
const body = E(
'div',
{ class: 'dl-stack gap16' },
setUp ? [stats, connectSec, detailsSec, activitySec] : [stats, detailsSec, activitySec, connectSec],
);
loadLog();
const watch = window.setInterval(() => {
reload();
+34 -11
View File
@@ -56,11 +56,12 @@ export function interfacesCard(serverId: string, title = 'Interfaces'): HTMLElem
let autoWan = true,
wanDev = '',
autoLan = true,
lanLike = true;
lanLike = true,
mesh = true;
let lans = new Set<string>();
let initial = '';
const snapshot = () => JSON.stringify([lanLike, autoWan, autoWan ? '' : wanDev, autoLan, [...lans].sort()]);
const snapshot = () => JSON.stringify([lanLike, mesh, 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]));
@@ -79,6 +80,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;
lans = new Set(r.config.lan_devices);
initial = snapshot();
}
@@ -129,11 +131,7 @@ export function interfacesCard(serverId: string, title = 'Interfaces'): HTMLElem
[
E('span', { class: 'dl-if-ic' }, icon(ICON[x.kind] ?? 'link')),
E('span', { class: 'dl-if-main' }, [E('span', { class: 'dl-if-name' }, x.name), E('span', { class: 'dl-if-sub' }, sub)]),
isAuto
? E('span', { class: 'dl-if-badge ok' }, [E('i', { class: 'dot ok' }), 'Auto'])
: sel
? E('span', { class: 'dl-if-check' }, icon('check'))
: '',
isAuto ? E('span', { class: 'dl-if-badge ok' }, 'Auto') : sel ? E('span', { class: 'dl-if-check' }, icon('check')) : '',
],
);
attachTip(el, () => [
@@ -197,8 +195,12 @@ 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;
const hint = (live: string | null, saved: string) =>
E('span', {}, [' Live: ', E('span', { class: 'dl-mono' }, live || '—'), ' · Saved: ', E('span', { class: 'dl-mono' }, saved || '—')]);
// 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);
@@ -212,7 +214,7 @@ export function interfacesCard(serverId: string, title = 'Interfaces'): HTMLElem
'Save',
async () => {
const r = await attempt(
() => api.serverInterfaces(serverId, autoWan, autoWan ? '' : wanDev, autoLan, [...lans], lanLike),
() => api.serverInterfaces(serverId, autoWan, autoWan ? '' : wanDev, autoLan, [...lans], lanLike, mesh),
'Interfaces saved',
);
if (!r) return;
@@ -251,6 +253,27 @@ export function interfacesCard(serverId: string, title = 'Interfaces'): HTMLElem
}),
]),
]),
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')),
@@ -292,7 +315,7 @@ export function interfacesCard(serverId: string, title = 'Interfaces'): HTMLElem
E(
'span',
{ class: 'dl-sub' },
'What people with Home access can reach. Click to add an interface; bridge ports and Wi-Fi in a bridge come with the bridge.',
'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,
+62 -25
View File
@@ -3,17 +3,21 @@
import type { LogEvent, Status } from '../shared/types';
import { E } from './e';
import { api, type LogCategory, type LogFilter } from './api';
import { api, type LogCategory, type LogFilter, type ServiceLogEntry } from './api';
import { attempt, button, closeModal, downloadFile, modal, notify } from './ui';
import { eventBy } from './pages/overview';
/** Mirrors CATEGORY in dawnline.live. */
const CATEGORY: Record<string, LogCategory> = {
connect: 'connections',
disconnect: 'connections',
roam: 'connections',
device_added: 'devices',
device_removed: 'devices',
devices_removed: 'devices',
device_added: 'people',
device_removed: 'people',
devices_removed: 'people',
device_changed: 'people',
device_keys: 'people',
link_changed: 'people',
person_added: 'people',
person_removed: 'people',
person_changed: 'people',
@@ -21,25 +25,21 @@ const CATEGORY: Record<string, LogCategory> = {
resumed: 'people',
paused_all: 'people',
resumed_all: 'people',
server_down: 'problems',
server_up: 'problems',
portal_blocked: 'problems',
};
export const CATEGORIES: LogCategory[] = ['connections', 'devices', 'people', 'problems'];
export const CATEGORIES: LogCategory[] = ['connections', 'people', 'problems'];
export const CATEGORY_LABEL: Record<LogCategory, string> = {
connections: 'Connections',
devices: 'Devices',
people: 'People',
problems: 'Problems',
};
export const CATEGORY_HELP: Record<LogCategory, string> = {
connections: 'Connects, disconnects and IP changes',
devices: 'Devices added and removed',
people: 'People added, changed, paused',
problems: 'Tunnel down, blocked portal sign-ins',
people: 'People and their devices added, changed, paused, removed',
problems: 'Blocked portal sign-ins (tunnels and services are in the service log)',
};
export const categoryOf = (type: string): LogCategory => CATEGORY[type] ?? 'problems';
@@ -55,25 +55,48 @@ function csvCell(v: unknown): string {
return /[",\n]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s;
}
/** Download events as CSV or JSON (person and device names resolved). */
export function exportEvents(st: Pick<Status, 'people'>, events: LogEvent[], format: 'csv' | 'json', suffix = '') {
export const SYSTEM_SOURCE: Record<ServiceLogEntry['src'], string> = { awg: 'AmneziaWG', dawnline: 'Dawnline', portal: 'Portal' };
/** Download events (and service log entries, category "system") as CSV or JSON, names resolved, oldest first. */
export function exportEvents(
st: Pick<Status, 'people'>,
events: LogEvent[],
format: 'csv' | 'json',
suffix = '',
system: ServiceLogEntry[] = [],
) {
const n = names(st);
const rows = events.map((e) => ({
time: new Date(e.ts * 1000).toISOString(),
category: categoryOf(e.type),
type: e.type,
person: e.person ? (n.people.get(e.person) ?? e.person) : '',
device: e.device ? (n.devices.get(e.device) ?? e.device) : '',
detail: e.detail ?? '',
where: e.where ?? '',
}));
const rows = [
...events.map((e) => ({
ts: e.ts,
category: categoryOf(e.type) as string,
type: e.type as string,
person: e.person ? (n.people.get(e.person) ?? e.pname ?? e.person) : '',
device: e.device ? (n.devices.get(e.device) ?? e.dname ?? e.device) : '',
detail: e.detail ?? '',
where: e.where ?? '',
by: eventBy(e) ?? '',
})),
...system.map((e) => ({
ts: e.ts,
category: 'system',
type: `${e.src}.${e.level}`,
person: '',
device: '',
detail: `${e.who ? `${e.who} ` : ''}${e.msg}${e.detail ? `\n${e.detail}` : ''}`,
where: SYSTEM_SOURCE[e.src] ?? e.src,
by: '',
})),
]
.sort((a, b) => a.ts - b.ts)
.map(({ ts, ...r }) => ({ time: new Date(ts * 1000).toISOString(), ...r }));
const stamp = new Date().toISOString().slice(0, 10);
const name = `dawnline-activity${suffix ? `-${suffix}` : ''}-${stamp}.${format}`;
if (format === 'json') {
downloadFile(name, JSON.stringify(rows, null, 2), 'application/json');
return;
}
const cols = ['time', 'category', 'type', 'person', 'device', 'detail', 'where'] as const;
const cols = ['time', 'category', 'type', 'person', 'device', 'detail', 'where', 'by'] as const;
const csv = [cols.join(','), ...rows.map((r) => cols.map((c) => csvCell(r[c])).join(','))].join('\n');
downloadFile(name, csv, 'text/csv');
}
@@ -89,10 +112,18 @@ const AGES: [string, string][] = [
* Ask what to clear and do it. `base` pins person/device; the dialog lets you
* pick a category (unless `category` is given) and an age.
*/
export function clearLogDialog(title: string, what: string, base: LogFilter, done: () => unknown, category?: LogCategory) {
export function clearLogDialog(
title: string,
what: string,
base: LogFilter,
done: () => unknown,
category?: LogCategory | 'system',
withSystem = false,
) {
const cat = E('select', { class: 'cbi-input-select' }, [
E('option', { value: '' }, 'All categories'),
...CATEGORIES.map((c) => E('option', { value: c, selected: c === category ? 'selected' : null }, CATEGORY_LABEL[c])),
withSystem ? E('option', { value: 'system', selected: category === 'system' ? 'selected' : null }, 'System') : '',
]) as HTMLSelectElement;
const age = E(
'select',
@@ -112,7 +143,13 @@ export function clearLogDialog(title: string, what: string, base: LogFilter, don
button(
'Clear',
async () => {
const r = await attempt(() => api.logsClear({ ...base, category: cat.value, older_days: age.value }));
// System is the service log; "All categories" clears it too where it is shown.
const r = await attempt(async () => {
const sys = withSystem && (cat.value === 'system' || cat.value === '') ? await api.serviceLogClear(age.value) : { removed: 0 };
const ev =
cat.value === 'system' ? { removed: 0 } : await api.logsClear({ ...base, category: cat.value, older_days: age.value });
return { removed: sys.removed + ev.removed };
});
if (!r) return;
closeModal();
notify(r.removed ? `${r.removed} event${r.removed === 1 ? '' : 's'} removed` : 'Nothing matched', 'success', 3000);
+2
View File
@@ -48,6 +48,8 @@ interface WidgetOptions {
}
interface LuciUI {
/** The menu is cached for the session; flush it after Dawnline's pages change. */
menu?: { flushCache(): void };
showModal(title: string | null, children: Child, ...classes: string[]): HTMLElement;
hideModal(): void;
addNotification(title: string | null, children: Child, ...classes: string[]): HTMLElement;
+21 -5
View File
@@ -4,9 +4,9 @@
import { PeoplePage } from './pages/people';
import { ServerPage } from './pages/server';
import { SettingsPage } from './pages/settings';
import { HealthPage, UpdatesPage } from './pages/maintenance';
import { UpdatesPage } from './pages/maintenance';
import { PersonPage } from './pages/person';
import { ActivityPage } from './pages/activity';
import { DiagnosticsPage } from './pages/diagnostics';
import { styleNode } from './styles';
interface Page {
@@ -44,8 +44,24 @@ const people = factory(PeoplePage, true);
const server = factory(ServerPage, false);
const settings = factory(SettingsPage, false);
const person = factory(PersonPage, false);
const activity = factory(ActivityPage, false);
const health = factory(HealthPage, false);
const diagnostics = factory(DiagnosticsPage, false);
const updates = factory(UpdatesPage, false);
export { overview, people, person, activity, server, settings, health, updates };
/** Health and Activity became Diagnostics tabs: old addresses and bookmarks go there. */
function moved(tab: '' | 'log') {
return () => ({
load: () => {
ui.menu?.flushCache();
location.replace(`${L.url('admin/network/dawnline/diagnostics')}${tab ? `?tab=${tab}` : ''}`);
return new Promise(() => {});
},
render: () => document.createElement('div'),
handleSave: null,
handleSaveApply: null,
handleReset: null,
});
}
const health = moved('');
const activity = moved('log');
export { overview, people, person, activity, server, settings, health, diagnostics, updates };
+162 -98
View File
@@ -1,22 +1,29 @@
// Activity: the full event log, grouped by day, with filters, search,
// export and clearing.
// Diagnostics → Log: people's activity and the service log (tunnel and
// service starts, stops, watchdog repairs, errors) in one list, grouped by
// day, with filters, export and clearing.
import type { LogEvent, Status } from '../../shared/types';
import { E } from '../e';
import { api, type LogCategory, type LogsInfo } from '../api';
import { api, type LogCategory, type LogsInfo, type ServiceLogEntry } from '../api';
import { button, dropdown } from '../ui';
import { icon } from '../../shared/icons';
import { installPalette } from '../palette';
import { CATEGORIES, CATEGORY_LABEL, categoryOf, clearLogDialog, exportEvents } from '../logs';
import { eventRow, eventText } from './overview';
import { CATEGORIES, CATEGORY_LABEL, SYSTEM_SOURCE, categoryOf, clearLogDialog, exportEvents } from '../logs';
import { eventRow } from './overview';
type Kind = 'all' | LogCategory;
type Loaded = [Status, Awaited<ReturnType<typeof api.events>>];
export type LogKind = 'all' | LogCategory | 'system';
type Events = Awaited<ReturnType<typeof api.events>>;
/** One line of the list: an activity event or a service log entry. */
export type LogItem = { ts: number; ev?: LogEvent; sys?: ServiceLogEntry };
/** Rows painted at a time; "Show more" adds another page. */
const PAGE = 300;
const KINDS: LogKind[] = ['all', 'connections', 'people', 'system', 'problems'];
/** Colour per service log level (tile, source and row): neutral unless something came up, was repaired or failed. */
// "down" is a tunnel that stopped without Dawnline asking (its own stops are "info").
const SYS_TONE: Record<ServiceLogEntry['level'], string> = { info: '', up: 'ok', down: 'warn', repair: 'warn', error: 'bad' };
const SYS_ICON: Record<ServiceLogEntry['src'], string> = { awg: 'tunnel', dawnline: 'sunrise', portal: 'globe' };
function dayTitle(ts: number): string {
export function dayTitle(ts: number): string {
const d = new Date(ts * 1000);
const today = new Date();
const y = new Date();
@@ -35,157 +42,214 @@ export function retentionText(p: LogsInfo['policy']): string {
return `Kept for ${age}, up to ${p.max.toLocaleString('en-GB')} events, ${where}.`;
}
export class ActivityPage {
st!: Status;
export const isProblem = (x: LogItem) =>
x.sys ? ['error', 'repair', 'down'].includes(x.sys.level) : categoryOf(x.ev!.type) === 'problems';
/** A service log line: source, message, folded details; click to unfold. */
export function systemRow(e: ServiceLogEntry, open: boolean, toggle: () => void, time: string): HTMLElement {
const admin = e.by === 'admin';
const row = E(
'div',
{
class: `dl-row dl-slog-row ${admin ? 'dl-ev-by-admin' : `dl-ev-by-system ${SYS_TONE[e.level] ?? ''}`}${e.detail ? ' has-detail' : ''}`,
},
[
admin
? E('span', { class: 'dl-ev-tile', title: 'Done by you in LuCI' }, icon('admin'))
: E('span', { class: 'dl-ev-tile sys', title: e.level }, icon(SYS_ICON[e.src] ?? 'zap')),
E(
'span',
{ class: 'dl-row-main' },
admin
? [
E('span', { class: 'dl-you' }, 'You'),
E('span', { class: 'dl-muted' }, ` ${e.msg} `),
e.kind ? E('span', { class: 'dl-ev-kind' }, `${e.kind} `) : '',
e.who ? E('b', {}, e.who) : '',
e.note ? E('span', { class: 'dl-muted' }, ` · ${e.note}`) : '',
e.detail ? E('span', { class: `dl-slog-more${open ? ' open' : ''}` }, icon('chevron')) : '',
e.detail && open ? E('pre', { class: 'dl-slog-detail' }, e.detail) : '',
]
: [
// Servers have names people chose: say it is a server. Services name themselves.
e.src === 'awg' && e.who && e.who !== 'AmneziaWG' ? E('span', { class: 'dl-ev-kind' }, 'Server ') : '',
E('b', { class: 'dl-sys-src', title: SYSTEM_SOURCE[e.src] ?? e.src }, e.who ?? SYSTEM_SOURCE[e.src] ?? e.src),
' ',
E('span', { class: 'dl-muted' }, e.msg),
e.detail ? E('span', { class: `dl-slog-more${open ? ' open' : ''}` }, icon('chevron')) : '',
e.detail && open ? E('pre', { class: 'dl-slog-detail' }, e.detail) : '',
],
),
E('span', { class: 'dl-faint dl-nowrap', title: new Date(e.ts * 1000).toLocaleString() }, time),
],
);
if (e.detail)
row.addEventListener('click', (ev) => {
if (!(ev.target as HTMLElement).closest('pre')) toggle();
});
return row;
}
export class LogTab {
st: Status;
events: LogEvent[] = [];
system: ServiceLogEntry[] = [];
policy!: LogsInfo['policy'];
kind: Kind = 'all';
query = '';
kind: LogKind = 'all';
shown = PAGE;
open = new Set<string>();
list = E('div', {});
sub = E('span', { class: 'dl-muted' });
/** Retention, for the page subtitle. */
sub = '';
tabs = E('div', { class: 'dl-seg', role: 'tablist' });
el: HTMLElement;
async load(): Promise<Loaded> {
return Promise.all([api.status(1), api.events(20000)]);
}
render([st, ev]: Loaded): HTMLElement {
constructor(st: Status, ev: Events, system: ServiceLogEntry[]) {
this.st = st;
this.take(ev);
installPalette(st);
const search = E('input', {
type: 'search',
class: 'dl-search-input',
placeholder: 'Search people, devices, IPs',
input: (e: Event) => {
this.query = (e.target as HTMLInputElement).value.trim().toLowerCase();
this.shown = PAGE;
this.paint();
},
});
this.system = system;
this.el = E('div', {}, [E('div', { class: 'dl-toolbar' }, [this.tabs]), this.list]);
this.paint();
}
/** Export and Clear, for the page head. */
actions(): HTMLElement[] {
const suffix = () => (this.kind === 'all' ? '' : this.kind);
const run = (format: 'csv' | 'json') => () => {
const items = this.filtered().reverse();
exportEvents(
this.st,
items.filter((x) => x.ev).map((x) => x.ev!),
format,
suffix(),
items.filter((x) => x.sys).map((x) => x.sys!),
);
};
const exp = button([icon('download'), ' Export'], () =>
dropdown(exp, [
{
label: 'CSV (spreadsheet)',
icon: icon('download'),
run: () => exportEvents(this.st, this.filtered().reverse(), 'csv', this.kind === 'all' ? '' : this.kind),
},
{
label: 'JSON',
icon: icon('download'),
run: () => exportEvents(this.st, this.filtered().reverse(), 'json', this.kind === 'all' ? '' : this.kind),
},
{ label: 'CSV (spreadsheet)', icon: icon('download'), run: run('csv') },
{ label: 'JSON', icon: icon('download'), run: run('json') },
]),
);
const clear = button([icon('trash'), ' Clear'], () =>
clearLogDialog(
'Clear activity',
'Clear the log',
'Removes events from the log on the router.',
{},
() => this.reload(),
this.kind === 'all' ? undefined : this.kind,
true,
),
);
this.paint();
poll.add(async () => {
const r = await api.events(20000).catch(() => null);
if (r) {
this.take(r);
this.paint();
}
}, 15);
return E('div', {}, [
E('div', { class: 'dl-pagehead' }, [
E('div', { class: 'dl-stack' }, [E('h2', { class: 'dl-h1' }, 'Activity'), this.sub]),
E('div', { class: 'dl-row-actions' }, [exp, clear]),
]),
E('div', { class: 'dl-toolbar' }, [
this.tabs,
E('span', { class: 'dl-spacer' }),
E('label', { class: 'dl-search' }, [icon('search'), search]),
]),
this.list,
]);
return [exp, clear];
}
take(r: Awaited<ReturnType<typeof api.events>>) {
take(r: Events) {
this.events = r.events;
this.policy = r.policy;
const off = CATEGORIES.filter((c) => !r.policy.categories.includes(c));
this.sub.textContent = `${retentionText(r.policy)}${off.length ? ` Not recorded: ${off.map((c) => CATEGORY_LABEL[c].toLowerCase()).join(', ')}.` : ''}`;
this.sub = `${retentionText(r.policy)}${off.length ? ` Not recorded: ${off.map((c) => CATEGORY_LABEL[c].toLowerCase()).join(', ')}.` : ''}`;
}
async reload() {
const r = await api.events(20000).catch(() => null);
if (r) {
this.take(r);
this.paint();
}
const [r, sl] = await Promise.all([api.events(20000).catch(() => null), api.serviceLog().catch(() => null)]);
if (r) this.take(r);
if (sl) this.system = sl.log;
this.paint();
}
/** Newest first, matching the current tab and search. */
filtered(): LogEvent[] {
return [...this.events].reverse().filter((e) => {
if (this.kind !== 'all' && categoryOf(e.type) !== this.kind) return false;
if (!this.query) return true;
const text = eventText(this.st, e)
.map((n) => n.textContent ?? '')
.join(' ');
return `${text} ${e.detail ?? ''} ${e.where ?? ''}`.toLowerCase().includes(this.query);
});
items(): LogItem[] {
return [...this.events.map((ev) => ({ ts: ev.ts, ev })), ...this.system.map((sys) => ({ ts: sys.ts, sys }))].sort(
(a, b) => b.ts - a.ts,
);
}
paintTabs() {
const count = (k: Kind) => (k === 'all' ? this.events.length : this.events.filter((e) => categoryOf(e.type) === k).length);
matches(x: LogItem, k: LogKind) {
if (k === 'all') return true;
if (k === 'problems') return isProblem(x);
if (k === 'system') return !!x.sys;
return !!x.ev && categoryOf(x.ev.type) === k;
}
/** Newest first, matching the current tab. */
filtered(): LogItem[] {
return this.items().filter((x) => this.matches(x, this.kind));
}
paintTabs(all: LogItem[]) {
dom.content(
this.tabs,
(['all', ...CATEGORIES] as Kind[]).map((k) =>
KINDS.map((k) =>
E(
'button',
{
type: 'button',
role: 'tab',
class: k === this.kind ? 'on' : '',
click: () => {
this.kind = k;
this.shown = PAGE;
this.paint();
},
'aria-selected': k === this.kind ? 'true' : 'false',
click: () => this.show(k),
},
[k === 'all' ? 'All' : CATEGORY_LABEL[k], E('b', {}, String(count(k)))],
[
k === 'all' ? 'All' : k === 'system' ? 'System' : CATEGORY_LABEL[k],
E('b', {}, String(all.filter((x) => this.matches(x, k)).length)),
],
),
),
);
}
show(k: LogKind) {
this.kind = k;
this.shown = PAGE;
this.paint();
}
paint() {
this.paintTabs();
const evs = this.filtered();
if (!evs.length) {
dom.content(this.list, E('div', { class: 'dl-empty' }, [E('p', {}, this.events.length ? 'No events match.' : 'The log is empty.')]));
this.paintTabs(this.items());
const items = this.filtered();
if (!items.length) {
dom.content(
this.list,
E('div', { class: 'dl-empty' }, [E('p', {}, this.events.length || this.system.length ? 'No events match.' : 'The log is empty.')]),
);
return;
}
const groups: HTMLElement[] = [];
let day = '';
let panel: HTMLElement | null = null;
for (const e of evs.slice(0, this.shown)) {
const t = dayTitle(e.ts);
for (const x of items.slice(0, this.shown)) {
const t = dayTitle(x.ts);
if (t !== day) {
day = t;
panel = E('div', { class: 'dl-panel flush' }, E('div', { class: 'dl-panel-head pad' }, E('h3', {}, t)));
groups.push(panel);
}
const row = eventRow(this.st, e);
row.lastElementChild!.textContent = new Date(e.ts * 1000).toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit' });
panel!.appendChild(row);
const time = new Date(x.ts * 1000).toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit' });
if (x.sys) {
const key = `${x.sys.ts}|${x.sys.msg}`;
panel!.appendChild(
systemRow(
x.sys,
this.open.has(key),
() => {
if (!this.open.delete(key)) this.open.add(key);
this.paint();
},
time,
),
);
} else {
const row = eventRow(this.st, x.ev!);
row.lastElementChild!.textContent = time;
panel!.appendChild(row);
}
}
if (evs.length > this.shown)
if (items.length > this.shown)
groups.push(
E(
'div',
{ class: 'dl-more-row' },
button(`Show ${Math.min(PAGE, evs.length - this.shown)} more of ${evs.length - this.shown}`, () => {
button(`Show ${Math.min(PAGE, items.length - this.shown)} more of ${items.length - this.shown}`, () => {
this.shown += PAGE;
this.paint();
}),
+94
View File
@@ -0,0 +1,94 @@
// Diagnostics: Health (watchdog, checks, recent problems) and Log (activity
// and the service log in one list) as two tabs. ?tab=log opens the Log; the
// old Health and Activity addresses come here.
import type { Status } from '../../shared/types';
import { E } from '../e';
import { api, type Health, type ServiceLog } from '../api';
import { HealthTab } from './maintenance';
import { LogTab } from './activity';
type Tab = 'health' | 'log';
type Loaded = [Status, Awaited<ReturnType<typeof api.events>>, ServiceLog, Health | null];
const TABS: [Tab, string][] = [
['health', 'Health'],
['log', 'Log'],
];
export class DiagnosticsPage {
tab: Tab = new URLSearchParams(location.search).get('tab') === 'log' ? 'log' : 'health';
health!: HealthTab;
log!: LogTab;
segEl = E('div', { class: 'dl-seg dl-srvsections dl-diag-tabs', role: 'tablist', 'aria-label': 'Diagnostics' });
subEl = E('span', { class: 'dl-muted' });
actionsEl = E('div', { class: 'dl-row-actions' });
bodyEl = E('div', {});
load(): Promise<Loaded> {
// The checks take a moment: only wait for them when Health opens first.
return Promise.all([
api.status(1),
api.events(20000),
api.serviceLog(),
this.tab === 'health' ? api.health().catch(() => null) : Promise.resolve(null),
]);
}
render([st, ev, sl, h]: Loaded): HTMLElement {
this.log = new LogTab(st, ev, sl.log);
this.health = new HealthTab(st, sl, ev.events, () => {
this.show('log');
this.log.show('problems');
});
if (h) this.health.take(h);
this.show(this.tab);
poll.add(async () => {
if (!this.bodyEl.isConnected) return;
const [n, e] = await Promise.all([api.serviceLog().catch(() => null), api.events(20000).catch(() => null)]);
if (e) this.log.take(e);
if (n) this.log.system = n.log;
if (n) this.health.paintLive(n, e?.events ?? this.health.events);
if (this.tab === 'log' && (n || e)) this.log.paint();
}, 10);
return E('div', {}, [
E('div', { class: 'dl-pagehead' }, [
E('div', { class: 'dl-stack' }, [E('h2', { class: 'dl-h1' }, 'Diagnostics'), this.subEl]),
this.actionsEl,
]),
this.segEl,
this.bodyEl,
]);
}
show(tab: Tab) {
this.tab = tab;
const url = new URL(location.href);
if (tab === 'log') url.searchParams.set('tab', 'log');
else url.searchParams.delete('tab');
history.replaceState(null, '', url);
dom.content(
this.segEl,
TABS.map(([k, t]) =>
E(
'button',
{
type: 'button',
role: 'tab',
class: k === tab ? 'on' : '',
'aria-selected': k === tab ? 'true' : 'false',
click: () => k !== this.tab && this.show(k),
},
t,
),
),
);
// Both tabs stay alive; only the visible one is in the page.
this.bodyEl.replaceChildren(tab === 'log' ? this.log.el : this.health.el);
this.subEl.textContent =
tab === 'log' ? this.log.sub : 'Everything Dawnline depends on, checked live. The watchdog repairs what it can on its own.';
dom.content(this.actionsEl, tab === 'log' ? this.log.actions() : '');
if (tab === 'log') this.log.paint();
else if (!this.health.checks) void this.health.run();
}
}
+193 -65
View File
@@ -1,93 +1,218 @@
// Health and Updates pages.
// Diagnostics → Health, and the Updates page.
import type { HealthCheck } from '../../shared/types';
import type { HealthCheck, LogEvent, Status } from '../../shared/types';
import { eventRow } from './overview';
import { isProblem, systemRow, type LogItem } from './activity';
import { E } from '../e';
import { api, type AwgSource, type Needs, type UpdatesStatus } from '../api';
import { api, type AwgSource, type Health, type Needs, type ServiceLog, type UpdatesStatus } from '../api';
import { installFeature } from '../pkgs';
import { attempt, button, callout, confirmDialog } from '../ui';
import { icon } from '../../shared/icons';
import { clock } from '../../shared/format';
import { ago, clock } from '../../shared/format';
import { sw } from '../kit';
const ICON: Record<HealthCheck['status'], string> = { ok: 'check', warn: 'alert', error: 'x', skip: 'pause' };
const FIX_LABEL: Record<string, string> = { apply: 'Repair', sync: 'Reload devices', restart: 'Restart service', updates: 'Open updates' };
export class HealthPage {
root!: HTMLElement;
/** Diagnostics → Health: the watchdog, the checks and the latest problems from the log. */
export class HealthTab {
st: Status;
el = E('div', {});
wdEl = E('div', {});
checksEl = E('div', { class: 'dl-panel' });
recentEl = E('div', { class: 'dl-panel flush dl-recent' });
sl: ServiceLog;
events: LogEvent[];
checks: HealthCheck[] | null = null;
/** Shows the Log tab on its Problems filter. */
toLog: () => void;
summary = E('div', {});
load() {
return api.health();
constructor(st: Status, sl: ServiceLog, events: LogEvent[], toLog: () => void) {
this.st = st;
this.sl = sl;
this.events = events;
this.toLog = toLog;
dom.content(this.el, [this.summary, this.wdEl, E('div', { class: 'dl-health-cols' }, [this.checksEl, this.recentEl])]);
this.paintChecks();
this.paintLive(sl, events);
}
render(r: { checks: HealthCheck[] }) {
this.root = E('div', { class: 'dl-root' });
this.paint(r.checks);
return E('div', {}, [
E('h2', {}, 'Health'),
E(
'div',
{ class: 'cbi-map-descr' },
'Everything Dawnline depends on, checked live. Problems come with a fix button where one exists.',
),
this.root,
]);
/** Run the checks (they take a moment: DNS, ports, certificates). */
async run(fix?: string) {
const r = fix ? await attempt(() => api.healthFix(fix), 'Done') : await api.health().catch(() => null);
if (!r) return;
this.take(r);
}
paint(checks: HealthCheck[]) {
take(r: Health) {
this.checks = r.checks;
this.paintChecks();
this.paintLive(r, this.events);
}
paintChecks() {
const checks = this.checks;
if (!checks) {
dom.content(this.summary, '');
dom.content(this.checksEl, [
E('div', { class: 'dl-panel-head' }, [E('h3', {}, 'Checks')]),
E('p', { class: 'dl-muted dl-loading' }, 'Running checks…'),
]);
return;
}
const bad = checks.filter((c) => c.status === 'error').length;
const warn = checks.filter((c) => c.status === 'warn').length;
dom.content(this.root, [
dom.content(
this.summary,
bad
? callout('error', `${bad} problem${bad > 1 ? 's' : ''} need attention.`)
: warn
? callout('warn', `${warn} warning${warn > 1 ? 's' : ''}.`)
: callout('ok', 'All checks passed.'),
E('div', { class: 'dl-panel' }, [
E('div', { class: 'dl-panel-head' }, [
E('h3', {}, 'Checks'),
E('span', { class: 'dl-spacer' }),
button('Run again', async () => {
const r = await attempt(() => api.health());
if (r) this.paint(r.checks);
}),
]),
E(
'ul',
{ class: 'dl-checks' },
checks.map((c) =>
E('li', {}, [
E('span', { class: `dl-check-icon ${c.status}` }, icon(ICON[c.status])),
E('div', { class: 'dl-check-body' }, [
E('div', { class: 'dl-check-title' }, c.title),
E('div', { class: 'dl-check-detail' }, c.detail),
]),
c.fix
? c.fix.startsWith('install:')
? button(
'Install',
() =>
installFeature(c.fix!.slice(8) as keyof Needs, async () => {
const r = await api.health().catch(() => null);
if (r) this.paint(r.checks);
}),
'action',
)
: c.fix === 'updates'
? E('a', { class: 'cbi-button cbi-button-action', href: L.url('admin/network/dawnline/updates') }, FIX_LABEL.updates)
: button(
FIX_LABEL[c.fix] ?? 'Fix',
async () => {
const r = await attempt(() => api.healthFix(c.fix!), 'Done');
if (r) this.paint(r.checks);
},
'action',
)
);
const repaired = new Map<string, number>();
for (const x of this.sl.watchdog.repairs) repaired.set(x.id, Math.max(repaired.get(x.id) ?? 0, x.ts));
const refresh = () => this.run();
dom.content(this.checksEl, [
E('div', { class: 'dl-panel-head' }, [E('h3', {}, 'Checks'), E('span', { class: 'dl-spacer' }), button('Run again', refresh)]),
E(
'ul',
{ class: 'dl-checks' },
checks.map((c) =>
E('li', {}, [
E('span', { class: `dl-check-icon ${c.status}` }, icon(ICON[c.status])),
E('div', { class: 'dl-check-body' }, [
E('div', { class: 'dl-check-title' }, c.title),
E('div', { class: 'dl-check-detail' }, c.detail),
repaired.has(c.id)
? E('div', { class: 'dl-check-repaired' }, `Repaired by the watchdog at ${clock(repaired.get(c.id)!)}`)
: '',
]),
),
c.fix
? c.fix.startsWith('install:')
? button('Install', () => installFeature(c.fix!.slice(8) as keyof Needs, refresh), 'action')
: c.fix === 'updates'
? E('a', { class: 'cbi-button cbi-button-action', href: L.url('admin/network/dawnline/updates') }, FIX_LABEL.updates)
: button(FIX_LABEL[c.fix] ?? 'Fix', () => this.run(c.fix!), 'action')
: '',
]),
),
]),
),
]);
}
/** The watchdog card and recent problems; refreshed by the page poll without running the checks again. */
paintLive(sl: ServiceLog, events: LogEvent[]) {
this.sl = sl;
this.events = events;
const wd = sl.watchdog;
const stale = wd.beat != null && wd.now - wd.beat > 180;
const today = wd.repairs.filter((x) => wd.now - x.ts < 86400);
const lastRep = today[today.length - 1];
const toggle = sw(wd.enabled, 'Watchdog repairs', async (v) => {
const ok = await attempt(() => api.settingsUpdate({ watchdog: v ? '1' : '0' }), v ? 'Watchdog on' : 'Watchdog off');
if (!ok) toggle.classList.toggle('on', !v);
const n = await api.serviceLog().catch(() => null);
if (n) this.paintLive(n, this.events);
});
dom.content(
this.wdEl,
E('div', { class: 'dl-panel dl-wd' }, [
E('div', { class: 'dl-wd-head' }, [
E('span', { class: `dl-wd-tile${wd.enabled ? '' : ' off'}` }, icon('shield')),
E('div', { class: 'dl-stack' }, [
E('span', { class: 'dl-wd-title' }, 'Watchdog'),
E(
'span',
{ class: 'dl-sub' },
wd.enabled
? 'Every minute it checks the tunnels and services and repairs what it can on its own.'
: 'Off: problems are only written to the log. Nothing is repaired on its own.',
),
]),
E('span', { class: 'dl-spacer' }),
toggle,
]),
E('div', { class: 'dl-wd-foot' }, [
E(
'div',
{ class: 'dl-wd-chips' },
wd.targets.map((t) =>
E(
'span',
{
class: `dl-check-chip${t.ok ? '' : ' error'}`,
title: t.ok ? 'OK' : `Not working${t.tries ? ` · ${t.tries} repair${t.tries > 1 ? 's' : ''}` : ''}`,
},
[icon(t.ok ? 'check' : 'x'), t.name],
),
),
),
E(
'span',
{ class: `dl-sub${stale ? ' dl-warn-text' : ''}` },
stale
? `The agent has not checked in for ${Math.round((wd.now - wd.beat!) / 60)} min; cron restarts it after 5.`
: [
wd.last ? `Looked ${ago(wd.last, wd.now)}` : 'Starts within a minute',
' · ',
today.length
? `${today.length} repair${today.length > 1 ? 's' : ''} today, last ${lastRep.name} at ${clock(lastRep.ts)}`
: 'no repairs today',
],
),
]),
]),
);
this.paintRecent();
}
/** Problems from the last 7 days, both kinds, newest first. */
paintRecent() {
const since = Date.now() / 1000 - 7 * 86400;
const items: LogItem[] = [...this.events.map((ev) => ({ ts: ev.ts, ev })), ...this.sl.log.map((sys) => ({ ts: sys.ts, sys }))]
.filter((x) => x.ts >= since && isProblem(x))
.sort((a, b) => b.ts - a.ts);
const head = E('div', { class: 'dl-panel-head pad' }, [
E('h3', {}, 'Recent problems'),
E('span', { class: 'dl-spacer' }),
items.length ? E('a', { href: '#', click: (e: Event) => (e.preventDefault(), this.toLog()) }, 'All in Log →') : '',
]);
if (!items.length) {
dom.content(this.recentEl, [
head,
E('div', { class: 'dl-recent-empty' }, [
E('span', { class: 'dl-check-icon ok' }, icon('check')),
'No problems in the last 7 days.',
]),
]);
return;
}
dom.content(this.recentEl, [
head,
...items.slice(0, 8).map((x) => {
if (x.sys) {
const e = x.sys;
const key = `${e.ts}|${e.msg}`;
return systemRow(
e,
this.open.has(key),
() => {
if (!this.open.delete(key)) this.open.add(key);
this.paintRecent();
},
clock(e.ts),
);
}
const row = eventRow(this.st, x.ev!);
row.lastElementChild!.textContent = clock(x.ts);
return row;
}),
]);
}
open = new Set<string>();
}
/** What Dawnline adds to OpenWrt; the portal's HTTPS and certificates only matter while it is on. */
@@ -115,7 +240,10 @@ export class UpdatesPage {
this.running = false;
this.paint(n);
// A new Dawnline is installed: load its pages instead of running the old bundle.
if (n.job?.component === 'app' && n.job.state === 'done') setTimeout(() => location.reload(), 1500);
if (n.job?.component === 'app' && n.job.state === 'done') {
ui.menu?.flushCache();
setTimeout(() => location.reload(), 1500);
}
}
}, 3);
return this.root;
+151 -30
View File
@@ -11,13 +11,13 @@ import { ago, bits, bytes, daysLeft, initials } from '../../shared/format';
import { ConnectionMap, rangeControl, type Range } from '../map';
import { attachTip } from '../charts';
import { methodInfo } from '../disguise';
import { personUrl } from '../palette';
import { personUrl } from '../urls';
const EVENT_TONE: Record<string, string> = {
connect: 'ok',
disconnect: '',
roam: '',
device_added: 'accent',
device_added: 'ok',
device_removed: '',
person_added: '',
person_removed: '',
@@ -25,63 +25,177 @@ const EVENT_TONE: Record<string, string> = {
resumed: 'ok',
paused_all: 'warn',
resumed_all: 'ok',
server_down: 'bad',
server_up: 'ok',
portal_blocked: 'bad',
person_changed: '',
devices_removed: 'warn',
};
/** The icon in an event's tile: the device's kind for device events, else what happened. */
const EVENT_ICON: Record<string, string> = {
devices_removed: 'trash',
link_changed: 'link',
person_added: 'plus',
person_removed: 'trash',
person_changed: 'edit',
paused: 'pause',
resumed: 'play',
paused_all: 'pause',
resumed_all: 'play',
};
function eventIcon(st: Status, e: LogEvent): string {
if (e.device) {
const d = st.people.flatMap((p) => p.devices).find((x) => x.id === e.device);
return d?.kind ?? e.dkind ?? 'other';
}
return EVENT_ICON[e.type] ?? 'activity';
}
const ADMIN_TYPES = ['person_added', 'person_removed', 'person_changed', 'paused_all', 'resumed_all'];
/** Who did it. Older events have no `by`: LuCI and the portal marked it in the detail. */
export function eventBy(e: LogEvent): 'admin' | 'portal' | null {
if (e.by) return e.by;
if (ADMIN_TYPES.includes(e.type) || e.detail === 'by admin' || e.detail?.endsWith(' (admin)')) return 'admin';
if (e.detail?.endsWith(' (portal)')) return 'portal';
return null;
}
/** The detail without the old "(admin)" / "(portal)" / "by admin" marks. */
function plainDetail(e: LogEvent): string {
return (e.detail ?? '').replace(/ \((admin|portal)\)$/, '').replace(/^by admin$/, '');
}
export function eventText(st: Status, e: LogEvent): Node[] {
const person = st.people.find((p) => p.id === e.person);
const who = person?.name ?? e.person ?? '';
const dev = person?.devices.find((d) => d.id === e.device)?.name ?? '';
const who = person?.name ?? e.pname ?? e.person ?? '';
const dev = person?.devices.find((d) => d.id === e.device)?.name ?? e.dname ?? '';
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);
// 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;
const detail = plainDetail(e);
const devName = detail || dev || 'a device';
// The admin's own actions start with an accent "You".
const you = (verb: string) => [E('span', { class: 'dl-you' }, 'You'), m(` ${verb} `)];
if (eventBy(e) === 'admin')
switch (e.type) {
case 'device_added':
return [...you('added'), kind('device'), b(devName), m(' for '), b(who)];
case 'device_removed':
return [...you('removed'), kind('device'), b(devName), m(' from '), b(who)];
case 'paused':
return [...you('paused'), kind('person'), b(who)];
case 'resumed':
return [...you('resumed'), kind('person'), b(who)];
case 'device_changed': {
const renamed = detail.startsWith('renamed from ');
return [
...you(renamed ? 'renamed' : detail),
kind('device'),
b(dev || 'a device'),
m(' of '),
b(who),
...(renamed ? [m(` · was ${detail.slice(13)}`)] : []),
];
}
case 'device_keys':
return [...you('issued new keys for'), kind('device'), b(devName), m(' of '), b(who), m(' · it needs its new configuration')];
case 'link_changed':
return [...you('issued a new link for'), kind('person'), b(who), m(' · the old link stopped working')];
case 'paused_all':
return [E('span', { class: 'dl-you' }, 'You'), m(' paused everyone')];
case 'resumed_all':
return [E('span', { class: 'dl-you' }, 'You'), m(' resumed everyone')];
}
switch (e.type) {
case 'connect':
return [b(wd), m(' connected'), ...(e.detail ? [m(' from '), mono(e.detail)] : []), ...(e.where ? [m(` · ${e.where}`)] : [])];
return [
kind('Device'),
b(wd),
m(' connected'),
...(e.detail ? [m(' from '), mono(e.detail)] : []),
...(e.where ? [m(` · ${e.where}`)] : []),
];
case 'disconnect':
return [b(wd), m(' went offline')];
return [kind('Device'), b(wd), m(' went offline')];
case 'roam':
return [b(wd), m(' changed network '), mono(e.detail ?? '')];
return [kind('Device'), b(wd), m(' changed network '), mono(e.detail ?? '')];
case 'device_added':
return [b(who), m(' added '), E('span', {}, e.detail ?? 'a device')];
return [
kind('Person'),
b(who),
m(' added '),
kind('device'),
b(devName),
...(eventBy(e) === 'portal' ? [m(' on their portal')] : []),
];
case 'device_removed':
return [b(who), m(' removed '), E('span', {}, e.detail ?? 'a device')];
return [
kind('Person'),
b(who),
m(' removed '),
kind('device'),
b(devName),
...(eventBy(e) === 'portal' ? [m(' on their portal')] : []),
];
case 'device_keys':
return [kind('Person'), b(who), m(' issued new keys for '), kind('device'), b(devName), m(' on their portal')];
case 'person_added':
return [m('You added '), b(e.detail ?? who)];
return [...you('added'), kind('person'), b(e.detail ?? who)];
case 'person_removed':
return [m('You removed '), b(e.detail ?? who)];
return [...you('removed'), kind('person'), b(e.detail ?? who)];
case 'person_changed':
return [m('You changed '), b(who), m(` · ${e.detail ?? ''}`)];
// The detail lists changed fields by their option names (device_limit, expire_action).
return [...you('changed'), kind('person'), b(who), ...(detail ? [m(` · ${detail.replace(/_/g, ' ')}`)] : [])];
case 'paused':
return [b(who), m(` paused — ${e.detail ?? ''}`)];
return [kind('Person'), b(who), m(` paused — ${e.detail ?? ''}`)];
case 'resumed':
return [b(who), m(' resumed'), ...(e.detail && e.detail !== 'active' ? [m(` — ${e.detail}`)] : [])];
return [kind('Person'), b(who), m(' resumed'), ...(e.detail && e.detail !== 'active' ? [m(` — ${e.detail}`)] : [])];
case 'paused_all':
return [m('Everyone paused')];
case 'resumed_all':
return [m('Everyone resumed')];
case 'server_down':
return [m('Tunnel '), mono(e.detail ?? ''), m(' went down')];
case 'server_up':
return [m('Tunnel '), mono(e.detail ?? ''), m(' is back up')];
case 'portal_blocked':
return [m('Portal blocked '), mono(e.detail ?? ''), m(' for 15 min after too many wrong codes')];
return [
E('b', { class: 'dl-sys-src' }, 'Personal portal'),
m(' blocked '),
mono(e.detail ?? ''),
m(' for 15 min after too many wrong codes'),
];
case 'devices_removed':
return [b(who), m('’s devices were removed — end date reached')];
return [kind('Person'), b(who), m(' — all devices removed, end date reached')];
default:
return [m(`${e.type}${e.detail ? `: ${e.detail}` : ''}`)];
}
}
export function eventRow(st: Status, e: LogEvent): HTMLElement {
return E('div', { class: 'dl-row' }, [
E('span', { class: `dl-ev-dot ${EVENT_TONE[e.type] ?? ''}` }),
/** Events about the router rather than people look like service log lines: icon tile, colour by outcome. */
const SYSTEM_EVENT: Record<string, [string, string]> = {
portal_blocked: ['globe', 'bad'],
};
/** With several servers, which one a person's event happened on (left out where that is clear). */
function serverPill(st: Status, e: LogEvent): HTMLElement | '' {
if (st.servers.length < 2 || !e.person) return '';
const p = st.people.find((x) => x.id === e.person);
const srv = p && st.servers.find((s) => s.id === p.server);
return srv ? E('span', { class: 'dl-ev-srv', title: 'Server' }, srv.name) : '';
}
export function eventRow(st: Status, e: LogEvent, opts: { server?: boolean } = {}): HTMLElement {
const sys = SYSTEM_EVENT[e.type];
const by = eventBy(e);
return E('div', { class: `dl-row${by === 'admin' ? ' dl-ev-by-admin' : sys ? ` dl-ev-by-system ${sys[1]}` : ''}` }, [
by === 'admin'
? E('span', { class: 'dl-ev-tile', title: 'Done by you in LuCI' }, icon('admin'))
: sys
? E('span', { class: 'dl-ev-tile sys' }, icon(sys[0]))
: E('span', { class: `dl-ev-tile ev ${EVENT_TONE[e.type] ?? ''}` }, icon(eventIcon(st, e))),
E('span', { class: 'dl-row-main' }, eventText(st, e)),
opts.server === false ? '' : serverPill(st, e),
E('span', { class: 'dl-faint dl-nowrap', title: new Date(e.ts * 1000).toLocaleString() }, ago(e.ts, st.now)),
]);
}
@@ -92,7 +206,10 @@ function attention(st: Status): { tone: string; text: (Node | string)[] }[] {
const link = (href: string, t: string) => E('a', { href }, t);
for (const s of st.servers)
if (s.enabled && !s.up)
out.push({ tone: 'bad', text: [`Tunnel ${s.ifname} is down. `, link(L.url('admin/network/dawnline/health'), 'Open Health')] });
out.push({
tone: 'bad',
text: [`Tunnel ${s.ifname} is down. `, link(L.url('admin/network/dawnline/diagnostics'), 'Open Diagnostics')],
});
if (st.settings.paused_all) out.push({ tone: 'warn', text: ['Everyone is paused.'] });
for (const p of st.people) {
if (p.state === 'quota') out.push({ tone: 'warn', text: [link(personUrl(p.id), p.name), ' reached the data limit.'] });
@@ -120,7 +237,7 @@ function attention(st: Status): { tone: string; text: (Node | string)[] }[] {
if (st.servers.some((s) => s.lan_like) && st.like_home.error)
out.push({
tone: 'warn',
text: [`Internet through the LAN is off: ${st.like_home.error} `, link(L.url('admin/network/dawnline/health'), 'Details')],
text: [`Internet through the LAN is off: ${st.like_home.error} `, link(L.url('admin/network/dawnline/diagnostics'), 'Details')],
});
if (!st.settings.portal_enabled)
out.push({ tone: '', text: ['The personal portal is off. ', link(L.url('admin/network/dawnline/settings'), 'Turn on')] });
@@ -222,7 +339,11 @@ export class ServerOverview {
return it;
}),
bad.length > 3 ? E('span', { class: 'dl-sub' }, `+${bad.length - 3} more`) : '',
E('a', { href: L.url('admin/network/dawnline/health') }, bad.some((c) => c.fix) ? 'Fix in Health →' : 'Open Health →'),
E(
'a',
{ href: L.url('admin/network/dawnline/diagnostics') },
bad.some((c) => c.fix) ? 'Fix in Diagnostics →' : 'Open Diagnostics →',
),
]),
);
}
@@ -288,7 +409,7 @@ export class ServerOverview {
E('div', { class: 'dl-panel-head pad' }, [
E('h3', {}, 'Needs attention'),
E('span', { class: 'dl-spacer' }),
E('a', { href: L.url('admin/network/dawnline/health') }, 'Health'),
E('a', { href: L.url('admin/network/dawnline/diagnostics') }, 'Health'),
]),
att.length
? att
@@ -305,7 +426,7 @@ export class ServerOverview {
E('div', { class: 'dl-panel-head pad' }, [
E('h3', {}, 'Activity'),
E('span', { class: 'dl-spacer' }),
E('a', { href: L.url('admin/network/dawnline/activity') }, 'View all'),
E('a', { href: `${L.url('admin/network/dawnline/diagnostics')}?tab=log` }, 'View all'),
]),
events.length
? events.map((e) => eventRow(st, e))
+55 -49
View File
@@ -8,11 +8,11 @@ import { api } from '../api';
import { attempt, button, closeModal, confirmDialog, copyText, dropdown, iconButton, modal, notify, type MenuItem } from '../ui';
import { addDevice, openDevice } from '../device';
import { inviteCard } from '../invite';
import { installPalette, personUrl } from '../palette';
import { personUrl } from '../urls';
import { scoped } from './overview';
import { attachTip } from '../charts';
import { icon } from '../../shared/icons';
import { ACCESS_LABEL, KIND_LABEL, STATE_LABEL, ago, bits, bytes, date, daysLeft, initials } from '../../shared/format';
import { ACCESS_LABEL, KIND_LABEL, STATE_LABEL, ago, bits, byDeviceState, bytes, date, daysLeft, initials } from '../../shared/format';
type Sid = string;
@@ -34,6 +34,23 @@ export function stateBadge(p: Person): HTMLElement | '' {
return el;
}
/** Device slots as a row of segments (one per allowed device, used ones lit) and "2 of 10". */
function slotBar(p: Person): HTMLElement {
const used = p.devices.length;
// Devices added over the limit get their own (soft orange) segments after the allowed ones.
const n = Math.max(1, p.device_limit, used);
// 22px a segment until the bar is 160px long; past that the segments get thinner, so the count stays close.
const width = Math.min(160, n * 22 + (n - 1) * 3);
return E('div', { class: 'dl-slotbar', title: `${used} of ${p.device_limit} devices` }, [
E(
'span',
{ class: 'dl-slotbar-segs', style: `width: ${width}px` },
Array.from({ length: n }, (_, i) => E('i', { class: i >= p.device_limit ? 'over' : i < used ? 'used' : '' })),
),
E('span', { class: 'dl-slotbar-text' }, `${used} of ${p.device_limit}`),
]);
}
/** What the person can reach, as icons: home network, internet, or both. */
export function accessBadge(p: Person): HTMLElement {
const kinds = p.access === 'both' ? ['lan', 'inet'] : p.access === 'lan' ? ['lan'] : ['inet'];
@@ -117,7 +134,6 @@ let addOpened = false;
export class PeoplePage {
st!: Status;
map: any;
query = '';
// `?filter=online` (from Overview) preselects a tab.
filter: Filter =
(['all', 'online', 'attention', 'paused'] as Filter[]).find((f) => f === new URLSearchParams(location.search).get('filter')) ?? 'all';
@@ -215,16 +231,6 @@ export class PeoplePage {
return m.render().then((node: HTMLElement) => {
node.classList.add('dl-map', 'dl-root');
installPalette(st);
const search = E('input', {
type: 'search',
class: 'dl-search-input',
placeholder: 'Search people, devices, IPs',
input: (ev: Event) => {
page.query = (ev.target as HTMLInputElement).value.trim().toLowerCase();
page.decorate();
},
});
const sort = E(
'select',
{
@@ -256,9 +262,8 @@ export class PeoplePage {
]),
E('div', { class: 'dl-toolbar' }, [
E('div', { class: 'dl-seg', id: 'dl-people-tabs', role: 'tablist' }),
// Search, sort and add stay together on the right, wrapping as one group.
// Sort and add stay together on the right, wrapping as one group.
E('div', { class: 'dl-toolbar-end' }, [
E('label', { class: 'dl-search' }, [icon('search'), search, E('kbd', {}, '/')]),
sort,
page.serverId ? button([icon('plus'), ' Add person'], () => page.openCreate(), 'add') : '',
]),
@@ -286,7 +291,7 @@ export class PeoplePage {
return `${t.people} ${t.people === 1 ? 'person' : 'people'} · ${t.devices} device${t.devices === 1 ? '' : 's'} · ${t.online} online`;
}
/** Row classes, counters, filter tabs, search and sort order. */
/** Row classes, counters, filter tabs and sort order. */
decorate() {
const c = document.getElementById('dl-people-count');
if (c) c.textContent = this.countText();
@@ -323,9 +328,7 @@ export class PeoplePage {
if (this.filter === 'online' && !p.online) return false;
if (this.filter === 'attention' && !needsAttention(p)) return false;
if (this.filter === 'paused' && !(p.state !== 'active' && p.state !== 'quota' && p.state !== 'expired')) return false;
if (!this.query) return true;
const hay = [p.name, p.id, ...p.devices.flatMap((d) => [d.name, d.address, d.endpoint, d.hostname])].join(' ').toLowerCase();
return hay.includes(this.query);
return true;
};
const order = [...people].sort((a, b) =>
this.sort === 'name'
@@ -349,12 +352,12 @@ export class PeoplePage {
row.classList.toggle('dl-filtered', !hit);
if (hit) shown++;
}
// Say so when the filter or search leaves nobody.
// Say so when the filter leaves nobody.
const table = tbody?.closest('.cbi-section-table') ?? tbody;
let none = document.getElementById('dl-people-none');
if (table && people.length && !shown) {
none ??= E('div', { id: 'dl-people-none', class: 'dl-empty' });
dom.content(none, E('p', {}, this.query ? `No one matches “${this.query}”.` : 'No one here right now.'));
dom.content(none, E('p', {}, 'No one here right now.'));
if (none.parentElement !== table.parentElement) table.after(none);
} else none?.remove();
}
@@ -395,7 +398,7 @@ export class PeoplePage {
}
if (p.hours) pills.push(E('span', { class: 'dl-pill-ic', title: 'Allowed hours' }, [icon('clock'), p.hours.replace('-', '–')]));
const chips = p.devices.map((d) => {
const chips = byDeviceState(p.devices).map((d) => {
return E(
'button',
{
@@ -415,22 +418,24 @@ export class PeoplePage {
],
);
});
if (free > 0)
chips.push(
E(
'button',
{
type: 'button',
class: 'dl-chip add',
title: `${p.devices.length} of ${p.device_limit} devices`,
click: (ev: Event) => {
ev.preventDefault();
addDevice(p, () => this.refresh());
},
// Always there: over the limit the admin can still add one (the slot bar turns orange).
chips.push(
E(
'button',
{
type: 'button',
// Just a "+": the slots above say how many there are.
class: 'dl-chip add',
'aria-label': 'Add device',
title: free > 0 ? 'Add device' : 'Add device · over the limit, admins can still add',
click: (ev: Event) => {
ev.preventDefault();
addDevice(p, () => this.refresh());
},
[icon('plus'), E('span', { class: 'dl-chip-name' }, 'Add device')],
),
);
},
icon('plus'),
),
);
const fixes: Node[] = [];
if (p.state === 'quota' && p.quota_period === 'month')
@@ -498,17 +503,18 @@ export class PeoplePage {
node,
E('div', { class: 'dl-pcard' }, [
E('div', { class: 'dl-pcard-main' }, [
E('div', { class: 'dl-card-head' }, [
// The avatar is centred on the name and the slots; devices follow under the name.
E('div', { class: 'dl-pcard-top' }, [
E('span', { class: `dl-avatar${p.online ? ' online' : ''}` }, initials(p.name)),
E('a', { class: 'dl-card-name', href: personUrl(p.id) }, p.name),
stateBadge(p),
accessBadge(p),
...pills,
]),
E('div', { class: 'dl-meta' }, [
E('span', {}, `${p.devices.length} of ${p.device_limit} devices`),
E('span', { class: 'dl-sep' }, '·'),
E('span', {}, p.online ? 'online now' : p.last_seen ? `seen ${ago(p.last_seen, this.st.now)}` : 'never connected'),
E('div', { class: 'dl-pcard-who' }, [
E('div', { class: 'dl-card-head' }, [
E('a', { class: 'dl-card-name', href: personUrl(p.id) }, p.name),
stateBadge(p),
accessBadge(p),
...pills,
]),
slotBar(p),
]),
]),
E('div', { class: 'dl-chips' }, chips),
fixes.length ? E('div', { class: 'dl-fixes' }, fixes) : '',
@@ -572,8 +578,8 @@ export class PeoplePage {
return E('div', { class: 'dl-pside' }, [
E('div', { class: 'dl-pside-top' }, [
live
? E('span', { class: 'dl-pside-state live' }, [E('i', { class: 'dl-dot online' }), 'Live'])
: E('span', { class: 'dl-pside-state' }, p.online ? 'Online' : p.last_seen ? 'Offline' : 'Not connected'),
? E('span', { class: 'dl-pside-state live' }, 'Online')
: E('span', { class: 'dl-pside-state' }, p.online ? 'Online' : p.last_seen ? 'Offline' : 'Never connected'),
actions,
]),
E('div', { class: 'dl-use-num' }, [
+41 -65
View File
@@ -23,10 +23,10 @@ import { addDevice, connectBlock, openDevice } from '../device';
import { inviteCard } from '../invite';
import { icon } from '../../shared/icons';
import { qrSvg } from '../../shared/qr';
import { ACCESS_LABEL, KIND_LABEL, ago, bytes, date, daysLeft, initials } from '../../shared/format';
import { ACCESS_LABEL, KIND_LABEL, ago, byDeviceState, bytes, date, daysLeft, initials } from '../../shared/format';
import { ConnectionMap, rangeControl } from '../map';
import { attachTip } from '../charts';
import { installPalette, peopleUrl } from '../palette';
import { peopleUrl } from '../urls';
import { daysTile, eventRow, eventText, speedTile } from './overview';
import { stateBadge } from './people';
@@ -48,9 +48,9 @@ export function shiftDate(cur: string, step: Step, n: number, customDays = 30):
}
const ACCESS_TEXT: Record<Person['access'], string> = {
internet: 'Browse the internet through your router. No access to devices at home.',
lan: 'Reach devices at home. Internet stays on their own connection.',
both: 'Home devices and the internet, all through your router.',
internet: 'Browse the internet through your router. No access to devices at home, and home cannot reach theirs.',
lan: 'Reach devices at home, and home reaches theirs. Internet stays on their own connection.',
both: 'Home devices and the internet, all through your router. Home reaches their devices too.',
};
export class PersonPage {
@@ -82,7 +82,6 @@ export class PersonPage {
render([st, events]: [Status, LogEvent[]]): HTMLElement {
this.st = st;
this.events = events;
installPalette(st);
const p = st.people.find((x) => x.id === this.id);
if (!p)
return E('div', { class: 'dl-empty' }, [
@@ -275,10 +274,10 @@ export class PersonPage {
const e = latest[i];
let n = 1;
while (e.type === 'roam' && latest[i + n]?.type === 'roam' && latest[i + n].device === e.device) n++;
const row = eventRow(st, e);
const row = eventRow(st, e, { server: false });
if (n > 1) {
const main = row.querySelector('.dl-row-main') as HTMLElement;
dom.content(main, [...eventText(st, e).slice(0, 2), E('span', { class: 'dl-muted' }, `${n} times`)]);
dom.content(main, [...eventText(st, e).slice(0, 3), E('span', { class: 'dl-muted' }, `${n} times`)]);
main.title = latest
.slice(i, i + n)
.map((x) => x.detail ?? '')
@@ -322,34 +321,14 @@ export class PersonPage {
}
deviceStatus(d: Device): HTMLElement {
if (d.disabled) return E('span', { class: 'dl-dstat' }, [E('i', { class: 'dot' }), 'Disabled']);
if (d.online)
return E('span', { class: 'dl-dstat ok' }, [
E('i', { class: 'dot ok' }),
`Online · ${ago(d.handshake, this.st.now).replace(' ago', '')}`,
]);
if (!d.handshake)
return E('span', { class: 'dl-dstat warn', title: 'Waiting for the first connection' }, [
E('i', { class: 'dot warn' }),
'Not set up yet',
]);
return E('span', { class: 'dl-dstat' }, [E('i', { class: 'dot' }), `Last seen ${ago(d.handshake, this.st.now)}`]);
// Status as coloured text, no dots (only avatars carry one).
if (d.disabled) return E('span', { class: 'dl-dstat' }, 'Disabled');
if (d.online) return E('span', { class: 'dl-dstat ok' }, 'Connected');
if (!d.handshake) return E('span', { class: 'dl-dstat warn', title: 'Waiting for the first connection' }, 'Not set up yet');
return E('span', { class: 'dl-dstat' }, `Last seen ${ago(d.handshake, this.st.now)}`);
}
/** While online: the client IP (copyable). Tunnel address and home name live in the device drawer. */
addrs(d: Device): HTMLElement | '' {
if (!d.online || !d.endpoint) return '';
const where = this.st.geo?.points.find((g) => g.device === d.id && g.ip === d.endpoint);
const tip = where?.city ? `Client IP · ${where.city}${where.org ? ` · ${where.org}` : ''}` : 'Client IP';
const b = E(
'button',
{ type: 'button', class: 'dl-addr wan', 'aria-label': `Copy ${d.endpoint}`, click: () => copyText(d.endpoint, 'Client IP copied') },
[icon('globe'), E('span', {}, d.endpoint)],
);
attachTip(b, () => [E('div', { class: 'dl-tip-title' }, tip), E('div', { class: 'dl-muted' }, 'Click to copy')]);
return E('div', { class: 'dl-addrs' }, b);
}
/** Daily traffic of one device over the last 30 days, today on the right. */
deviceBars(id: string): HTMLElement {
const days = (this.devSeries[id] ?? []).slice(-30);
@@ -374,7 +353,7 @@ export class PersonPage {
paintDevices() {
const p = this.p;
const refresh = () => this.refresh();
const cards = p.devices.map((d) => {
const cards = byDeviceState(p.devices).map((d) => {
const open = () => openDevice(p, d, refresh, this.st.geo);
return E('article', { class: `dl-dcard${d.online ? ' online' : ''}${d.disabled ? ' off' : ''}` }, [
E('div', { class: 'dl-dcard-head' }, [
@@ -404,31 +383,23 @@ export class PersonPage {
E('button', { type: 'button', class: 'dl-chipbtn', click: () => this.showDeviceQr(d) }, [icon('qr'), 'Show QR']),
E('button', { type: 'button', class: 'dl-chipbtn', click: () => this.downloadConfig(d) }, [icon('download'), 'Config']),
]),
this.addrs(d),
]);
});
const free = Math.max(0, p.device_limit - p.devices.length);
if (free)
cards.push(
E('button', { type: 'button', class: 'dl-dslot add', click: () => addDevice(p, refresh) }, [
E('span', { class: 'dl-dslot-ic' }, icon('plus')),
// Always the last card: admins may add over the person's limit, it says so.
const over = p.devices.length >= p.device_limit;
cards.push(
E('button', { type: 'button', class: 'dl-dslot add', click: () => addDevice(p, refresh) }, [
E('span', { class: 'dl-dslot-ic' }, icon('plus')),
E('span', { class: 'dl-stack' }, [
E('b', {}, 'Add device'),
over ? E('span', { class: 'dl-sub' }, `Over the limit · ${p.devices.length} of ${p.device_limit}`) : '',
]),
);
]),
);
dom.content(
this.parts.devices,
E('section', { class: 'dl-devsec' }, [
E('div', { class: 'dl-panel-head' }, [
E('h3', {}, 'Devices'),
E('span', { class: 'dl-sub' }, `${p.online} online`),
E('span', { class: 'dl-spacer' }),
// Over the limit there is no Add card; the admin can still add one.
free
? ''
: button([icon('plus'), ' Add device'], () => addDevice(p, refresh), 'neutral', {
title: 'Over the limit — admins can still add',
}),
]),
E('div', { class: 'dl-panel-head' }, [E('h3', {}, 'Devices'), E('span', { class: 'dl-sub' }, `${p.online} online`)]),
E('div', { class: 'dl-dgrid' }, cards),
]),
);
@@ -677,16 +648,19 @@ export class PersonPage {
dom.content(
this.parts.limits,
E('section', { class: 'dl-panel', 'aria-label': 'Access and limits' }, [
// Heading above the card, like "Devices", so both columns line up (as on the portal).
E('section', { class: 'dl-devsec', 'aria-label': 'Access and limits' }, [
E('div', { class: 'dl-panel-head' }, [E('h3', {}, 'Access & limits')]),
E('div', { class: 'dl-stack gap8' }, [
E('span', { class: 'dl-tile2-label' }, 'Can reach'),
seg,
E('span', { class: 'dl-sub' }, ACCESS_TEXT[p.access]),
p.access === 'lan' && this.st.services.length ? this.servicesPicker() : '',
p.access === 'lan' ? this.dnsPicker() : '',
E('div', { class: 'dl-panel' }, [
E('div', { class: 'dl-stack gap8' }, [
E('span', { class: 'dl-tile2-label' }, 'Can reach'),
seg,
E('span', { class: 'dl-sub' }, ACCESS_TEXT[p.access]),
p.access === 'lan' && this.st.services.length ? this.servicesPicker() : '',
p.access === 'lan' ? this.dnsPicker() : '',
]),
E('div', { class: 'dl-tiles2' }, [this.devTile(), endTile, dataTile, hoursTile]),
]),
E('div', { class: 'dl-tiles2' }, [this.devTile(), endTile, dataTile, hoursTile]),
]),
);
}
@@ -782,17 +756,19 @@ export class PersonPage {
devTile(): HTMLElement {
const p = this.p;
const slots = E('div', { class: 'dl-slots' });
for (let i = 0; i < p.device_limit; i++) {
// Devices added over the limit get their own soft orange slots after the allowed ones.
for (let i = 0; i < Math.max(p.device_limit, p.devices.length); i++) {
const d = p.devices[i];
const slot = E('i', { class: d ? 'used' : '' });
const over = i >= p.device_limit;
const slot = E('i', { class: over ? 'over' : d ? 'used' : '' });
attachTip(slot, () => [
E('div', { class: 'dl-tip-title' }, d ? d.name : 'Free slot'),
E('div', { class: 'dl-tip-title' }, d ? `${d.name}${over ? ' · over the limit' : ''}` : 'Free slot'),
E(
'div',
{ class: 'dl-muted' },
d
? d.online
? 'Online'
? 'Connected'
: d.handshake
? `Last seen ${ago(d.handshake, this.st.now)}`
: 'Not set up yet'
@@ -929,7 +905,7 @@ export class PersonPage {
async showDeviceQr(d: Device) {
const cfg = await attempt(() => api.deviceConfig(d.id));
if (!cfg) return;
modal(`Set up ${d.name}`, [await connectBlock(cfg)], [E('button', { class: 'cbi-button', click: closeModal }, 'Close')]);
modal(`Set up ${d.name}`, [await connectBlock(cfg, 'qr')], [E('button', { class: 'cbi-button', click: closeModal }, 'Close')]);
}
async downloadConfig(d: Device) {
+7 -11
View File
@@ -14,7 +14,6 @@ import { card, group, input, row, sw } from '../kit';
import { methodInfo, methodPicker, type Method } from '../disguise';
import { ServerOverview } from './overview';
import { PeoplePage } from './people';
import { installPalette, openPalette } from '../palette';
type Section = 'overview' | 'people' | 'connection' | 'access' | 'disguise' | 'tunnel';
const SECTIONS: [Section, string][] = [
@@ -176,7 +175,6 @@ export class ServerPage {
const want = (OLD_SECTIONS[raw] ?? raw) as Section;
if (SECTIONS.some(([k]) => k === want)) this.section = want;
this.srvId = (st.servers.find((x) => x.id === q.get('server')) ?? st.servers[0]).id;
installPalette(st);
dom.content(this.root, [this.tabsEl, this.headEl, this.secEl, this.bodyEl]);
this.paint();
// Live numbers on the Overview; settings forms are left alone while open.
@@ -336,13 +334,10 @@ export class ServerPage {
const st = this.st;
const seg = (ic: string, body: (Node | string)[]) => E('span', { class: 'dl-addrbar-seg' }, [icon(ic), ...body]);
const addr = `${srv.endpoint || '—'}:${srv.port}`;
// Search, plus "Turn on" while the server is off (turning off lives in Tunnel;
// the same button also lifts an old router-wide pause).
// "Turn on" while the server is off (turning off lives in Tunnel; the same
// button also lifts an old router-wide pause).
const off = !srv.enabled || st.settings.paused_all;
const actions = E('div', { class: 'dl-actions' }, [
button([icon('search'), ' Search ', E('kbd', {}, '⌘K')], () => openPalette(), 'neutral', {
class: 'cbi-button cbi-button-neutral dl-searchbtn',
}),
off
? button(
[icon('play'), ' Turn on'],
@@ -359,10 +354,11 @@ export class ServerPage {
return E('div', { class: 'dl-srvpagehead' }, [
E('div', { class: 'dl-title-row' }, [
E('h2', { class: 'dl-h1' }, srv.name),
E('span', { class: `dl-pill ${!srv.enabled ? 'off' : srv.up ? 'ok' : 'bad'}` }, [
E('i', { class: 'dl-pill-dot' }),
!srv.enabled ? 'Disabled' : srv.up ? 'Ready' : 'Down',
]),
E(
'span',
{ class: `dl-pill ${!srv.enabled ? 'off' : srv.up ? 'ok' : 'bad'}` },
!srv.enabled ? 'Turned off' : srv.up ? 'Running' : 'Not running',
),
st.settings.paused_all && srv.enabled ? E('span', { class: 'dl-pill warn' }, 'Off') : '',
E('span', { class: 'dl-spacer' }),
actions,
-2
View File
@@ -4,7 +4,6 @@ import { E } from '../e';
import { api, type Backup, type SettingsData } from '../api';
import { attempt, button, closeModal, confirmDialog, modal } from '../ui';
import { icon } from '../../shared/icons';
import { installPalette } from '../palette';
import { group, input, isOn, row, sw } from '../kit';
import { CATEGORIES, CATEGORY_HELP, CATEGORY_LABEL, clearLogDialog, exportEvents, resetUsageDialog } from '../logs';
import { retentionText } from './activity';
@@ -60,7 +59,6 @@ export class SettingsPage {
render(d: SettingsData): HTMLElement {
this.d = d;
installPalette();
this.paint();
this.loadBackups().then(() => {
if (new URLSearchParams(location.search).get('section') === 'backups')
-255
View File
@@ -1,255 +0,0 @@
// ⌘K / Ctrl+K command menu: jump to people and devices (also by IP or
// address) and run the common actions without leaving the keyboard.
import type { Person, Status } from '../shared/types';
import { E } from './e';
import { api } from './api';
import { attempt, copyText } from './ui';
import { icon } from '../shared/icons';
import { ACCESS_SHORT, initials } from '../shared/format';
interface Item {
group: string;
label: string;
hint?: string;
icon?: string;
avatar?: string;
kbd?: string;
run: () => unknown;
}
let cache: { st: Status; at: number } | null = null;
let open = false;
/** A server's People section (Servers page). */
export function peopleUrl(server?: string): string {
return `${L.url('admin/network/dawnline/server')}?${server ? `server=${encodeURIComponent(server)}&` : ''}section=people`;
}
export function personUrl(id: string, device?: string): string {
return `${L.url('admin/network/dawnline/person')}?id=${encodeURIComponent(id)}${device ? `&device=${encodeURIComponent(device)}` : ''}`;
}
function go(path: string) {
location.href = L.url(`admin/network/dawnline/${path}`);
}
function addMonths(iso: string, n: number): string {
const base = iso ? new Date(`${iso}T12:00:00`) : new Date();
const from = base.getTime() < Date.now() ? new Date() : base;
from.setMonth(from.getMonth() + n);
return `${from.getFullYear()}-${String(from.getMonth() + 1).padStart(2, '0')}-${String(from.getDate()).padStart(2, '0')}`;
}
function personActions(p: Person, done: () => void): Item[] {
const g = `Actions for ${p.name}`;
const items: Item[] = [];
if (p.link)
items.push({ group: g, label: 'Copy personal link', icon: 'link', kbd: 'C', run: () => copyText(p.link!, 'Personal link copied') });
items.push({ group: g, label: `Add device for ${p.name}`, icon: 'plus', run: () => (location.href = `${personUrl(p.id)}&add=1`) });
items.push({
group: g,
label: p.paused ? `Resume ${p.name}` : `Pause ${p.name}`,
icon: p.paused ? 'play' : 'pause',
kbd: 'P',
run: async () => {
await attempt(() => api.personPause(p.id, !p.paused), p.paused ? `${p.name} resumed` : `${p.name} paused`);
done();
},
});
items.push({
group: g,
label: 'Extend access by 1 month',
icon: 'key',
run: async () => {
await attempt(() => api.personUpdate(p.id, { expires: addMonths(p.expires, 1) }), 'Access extended');
done();
},
});
return items;
}
function build(st: Status, q: string, done: () => void): Item[] {
const query = q.trim().toLowerCase();
const items: Item[] = [];
const people = st.people.filter((p) => !query || [p.name, p.id].some((x) => x.toLowerCase().includes(query)));
for (const p of people.slice(0, 6))
items.push({
group: 'People',
label: p.name,
hint: `${ACCESS_SHORT[p.access]} · ${p.online ? `${p.online} online` : `${p.devices.length} device${p.devices.length === 1 ? '' : 's'}`}`,
avatar: initials(p.name),
run: () => (location.href = personUrl(p.id)),
});
for (const p of st.people)
for (const d of p.devices) {
const hay = [d.name, d.address, d.endpoint, d.hostname].join(' ').toLowerCase();
if (query && !hay.includes(query)) continue;
if (!query && !d.online) continue;
items.push({
group: 'Devices',
label: d.name,
hint: `${p.name} · ${d.address}${d.online ? ` · ${d.endpoint}` : ''}`,
icon: d.kind,
run: () => (location.href = personUrl(p.id, d.id)),
});
}
if (people.length === 1 || (people.length && query)) items.push(...personActions(people[0], done));
const pages: [string, string, string][] = [
['overview', 'Overview', 'globe'],
['people', 'People', 'shield'],
['activity', 'Activity', 'file'],
['server', 'Server', 'key'],
['health', 'Health', 'check'],
['settings?section=backups', 'Backups', 'archive'],
['settings', 'Settings', 'edit'],
];
for (const [path, label, ic] of pages)
if (!query || label.toLowerCase().includes(query)) items.push({ group: 'Go to', label, icon: ic, run: () => go(path) });
if (!query || 'add person'.includes(query))
items.push({
group: 'Go to',
label: 'Add person',
icon: 'plus',
run: () => (location.href = `${L.url('admin/network/dawnline/server')}?section=people&add=1`),
});
return items;
}
export async function openPalette() {
if (open) return;
open = true;
const input = E('input', {
type: 'text',
class: 'dl-pal-input',
placeholder: 'Search people, devices, IPs or actions…',
'aria-label': 'Search',
}) as HTMLInputElement;
const list = E('div', { class: 'dl-pal-list', role: 'listbox' });
const box = E('div', { class: 'dl-pal', role: 'dialog', 'aria-label': 'Command menu' }, [
E('label', { class: 'dl-pal-search' }, [icon('search'), input, E('kbd', {}, 'Esc')]),
list,
E('div', { class: 'dl-pal-foot' }, [
E('span', {}, [E('kbd', {}, '↑↓'), ' navigate']),
E('span', {}, [E('kbd', {}, '↵'), ' open']),
E('span', {}, [E('kbd', {}, '⌘K'), ' toggle']),
]),
]);
const overlay = E('div', { class: 'dl-pal-overlay dl-root' }, box);
let items: Item[] = [];
let sel = 0;
const close = () => {
overlay.remove();
document.removeEventListener('keydown', onKey, true);
open = false;
};
const render = () => {
const st = cache?.st;
if (!st) {
list.replaceChildren(E('div', { class: 'dl-pal-empty' }, 'Loading…'));
return;
}
items = build(st, input.value, () => {
cache = null;
close();
location.reload();
});
sel = Math.min(sel, Math.max(0, items.length - 1));
const nodes: Node[] = [];
let group = '';
items.forEach((it, i) => {
if (it.group !== group) {
group = it.group;
nodes.push(E('div', { class: 'dl-pal-group' }, group));
}
const row = E(
'div',
{
class: `dl-pal-item${i === sel ? ' sel' : ''}`,
role: 'option',
'aria-selected': i === sel ? 'true' : 'false',
click: () => {
close();
it.run();
},
mousemove: () => {
if (sel !== i) {
sel = i;
render();
}
},
},
[
it.avatar ? E('span', { class: 'dl-avatar sm' }, it.avatar) : it.icon ? icon(it.icon) : E('span', { class: 'dl-pal-ic' }),
E('span', { class: 'dl-pal-label' }, [it.label, it.hint ? E('span', { class: 'dl-faint' }, ` · ${it.hint}`) : '']),
it.kbd ? E('kbd', {}, it.kbd) : '',
],
);
nodes.push(row);
});
if (!items.length) nodes.push(E('div', { class: 'dl-pal-empty' }, 'Nothing found.'));
list.replaceChildren(...nodes);
list.querySelector('.sel')?.scrollIntoView({ block: 'nearest' });
};
const onKey = (ev: KeyboardEvent) => {
if (ev.key === 'Escape') {
ev.preventDefault();
close();
} else if (ev.key === 'ArrowDown') {
ev.preventDefault();
sel = Math.min(items.length - 1, sel + 1);
render();
} else if (ev.key === 'ArrowUp') {
ev.preventDefault();
sel = Math.max(0, sel - 1);
render();
} else if (ev.key === 'Enter') {
ev.preventDefault();
const it = items[sel];
if (it) {
close();
it.run();
}
}
};
input.addEventListener('input', () => {
sel = 0;
render();
});
overlay.addEventListener('click', (ev) => {
if (ev.target === overlay) close();
});
document.addEventListener('keydown', onKey, true);
document.body.appendChild(overlay);
input.focus();
render();
if (!cache || Date.now() - cache.at > 10000) {
const st = await api.status(1).catch(() => null);
if (st) cache = { st, at: Date.now() };
if (open) render();
}
}
/** Install the global shortcut once per page load. */
export function installPalette(seed?: Status) {
if (seed) cache = { st: seed, at: Date.now() };
const w = window as any;
if (w.__dlPalette) return;
w.__dlPalette = true;
// Capture phase on window, so Outline's own ⌘K search does not open too.
window.addEventListener(
'keydown',
(ev) => {
if (!location.pathname.includes('/admin/network/dawnline')) return;
const typing =
/^(INPUT|TEXTAREA|SELECT)$/.test((ev.target as HTMLElement)?.tagName ?? '') || (ev.target as HTMLElement)?.isContentEditable;
const cmdK = (ev.key === 'k' || ev.key === 'K') && (ev.metaKey || ev.ctrlKey);
const slash = ev.key === '/' && !typing && !document.body.classList.contains('modal-overlay-active');
if (!cmdK && !slash) return;
ev.preventDefault();
ev.stopImmediatePropagation();
openPalette();
},
true,
);
}
+73 -50
View File
@@ -87,6 +87,33 @@ const CSS = `
.dl-ev-dot { flex: 0 0 auto; width: 6px; height: 6px; border-radius: 50%; background: var(--dl-fg-faint); transform: translateY(-2px); }
.dl-ev-dot.ok { background: var(--dl-ok); } .dl-ev-dot.warn { background: var(--dl-warn); } .dl-ev-dot.bad { background: var(--dl-bad); }
.dl-ev-dot.accent { background: var(--dl-accent); }
/* The admin's own actions: an icon in the dot's place, taking the same room. */
.dl-row > .dl-ev-dot, .dl-dev-log-row > .dl-ev-dot { margin: 0 4px; }
.dl-ev-tile { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; margin: -2px -4px; border-radius: 7px;
background: color-mix(in srgb, var(--dl-accent) 16%, transparent); color: var(--dl-accent); align-self: center; }
.dl-ev-tile .dl-icon-wrap { display: inline-flex; } .dl-ev-tile .dl-icon { width: 14px; height: 14px; }
.dl-row.dl-ev-by-admin { background: color-mix(in srgb, var(--dl-accent) 6%, transparent); }
.dl-you { color: var(--dl-accent); font-weight: 500; }
.dl-ev-kind { color: var(--dl-fg-faint); }
.dl-slotbar { display: flex; align-items: center; gap: 8px; margin: 8px 0 0 44px; }
.dl-slotbar-segs { display: flex; gap: 3px; flex: none; max-width: 100%; }
.dl-slotbar-segs i { flex: 1; min-width: 2px; display: block; height: 4px; border-radius: 2px; background: var(--dl-soft-hover); }
.dl-slotbar-segs i.used { background: var(--dl-fg-muted); }
.dl-slotbar-text { font-size: 12px; color: var(--dl-fg-faint); font-variant-numeric: tabular-nums; }
.dl-slotbar-segs i.over { background: color-mix(in srgb, var(--dl-warn) 80%, transparent); }
.dl-ev-srv { flex: none; font-size: 11px; line-height: 18px; padding: 0 8px; border-radius: 999px; background: var(--dl-soft); color: var(--dl-fg-muted); white-space: nowrap; }
/* Service log lines: tile, source name and row tint share one colour, set by the level (--sys). */
.dl-ev-by-system { --sys: var(--dl-fg-muted); }
.dl-ev-by-system.ok { --sys: var(--dl-ok); } .dl-ev-by-system.warn { --sys: var(--dl-warn); } .dl-ev-by-system.bad { --sys: var(--dl-bad); }
.dl-ev-tile.ev { background: var(--dl-soft); color: var(--dl-fg-muted); }
.dl-ev-tile.ev.ok { background: var(--dl-ok-wash); color: var(--dl-ok); }
.dl-ev-tile.ev.warn { background: var(--dl-warn-wash); color: var(--dl-warn); }
.dl-ev-tile.ev.bad { background: var(--dl-bad-wash); color: var(--dl-bad); }
.dl-ev-tile.ev.accent { background: color-mix(in srgb, var(--dl-accent) 16%, transparent); color: var(--dl-accent); }
.dl-ev-tile.sys { background: color-mix(in srgb, var(--sys) 16%, transparent); color: var(--sys); }
.dl-row.dl-ev-by-system { background: color-mix(in srgb, var(--sys) 6%, transparent); }
.dl-sys-src { color: var(--sys); }
.dl-ev-by-system:not(.ok):not(.warn):not(.bad) .dl-sys-src { color: var(--dl-fg); }
.dl-ev-text { min-width: 0; overflow-wrap: anywhere; }
/* server summary */
@@ -122,8 +149,6 @@ const CSS = `
background: var(--dl-ok); box-shadow: 0 0 0 2px var(--dl-card); }
.dl-card-name { font-size: 16px; line-height: 24px; font-weight: 500; }
.dl-card-slug { font-size: 13px; color: var(--dl-fg-faint); font-family: var(--dl-mono); }
.dl-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; margin: 6px 0 0 44px; font-size: 13px; line-height: 20px;
color: var(--dl-fg-muted); font-variant-numeric: tabular-nums; }
.dl-quota { margin: 8px 0 0 44px; max-width: 320px; height: 6px; border-radius: 999px; background: var(--dl-track); overflow: hidden; }
.dl-quota > i { display: block; height: 100%; background: var(--dl-accent); border-radius: 999px; }
.dl-quota.warn > i { background: var(--dl-warn); } .dl-quota.bad > i { background: var(--dl-bad); }
@@ -133,7 +158,7 @@ const CSS = `
.dl-chip:hover { background: var(--dl-soft-hover); }
.dl-chip:focus-visible { outline: 2px solid var(--dl-ring); outline-offset: 2px; }
.dl-chip .dl-icon { width: 14px; height: 14px; color: var(--dl-fg-muted); }
.dl-chip.add { background: transparent; box-shadow: inset 0 0 0 1px var(--dl-line); color: var(--dl-fg-muted); }
.dl-chip.add { background: transparent; box-shadow: inset 0 0 0 1px var(--dl-line); color: var(--dl-fg-muted); aspect-ratio: 1; padding: 0; justify-content: center; }
.dl-chip.add:hover { background: var(--dl-soft); color: var(--dl-fg); }
.dl-chip.disabled .dl-chip-name { text-decoration: line-through; color: var(--dl-fg-faint); }
.dl-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@@ -146,13 +171,11 @@ const CSS = `
.dl-empty p { margin: 0 0 16px; color: var(--dl-fg-muted); font-size: 14px; }
.dl-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0 0 16px; }
.dl-toolbar .dl-muted { font-size: 13px; }
.dl-search { min-width: 240px; }
@media (max-width: 640px) {
.dl-map .cbi-section-table-row > .td.cbi-section-actions { margin-left: 0; width: 100% !important; }
.dl-map .cbi-section-table-row > .td.cbi-section-actions > div { justify-content: flex-start; flex-wrap: wrap; }
.dl-meta, .dl-chips, .dl-quota { margin-left: 0; }
.dl-slotbar, .dl-chips, .dl-quota { margin-left: 0; }
.dl-btn-label { display: none; }
.dl-search { min-width: 0; flex: 1; }
}
/* full-width rows (label above) */
@@ -233,7 +256,10 @@ const CSS = `
font-size: 13px; color: var(--dl-fg-muted); text-decoration: none !important; white-space: nowrap; }
.dl-srvtab b { font-weight: 500; }
.dl-srvtab i.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dl-fg-faint); flex: 0 0 auto; }
.dl-srvtab i.dot.ok { background: var(--dl-ok); } .dl-srvtab i.dot.bad { background: var(--dl-bad); }
.dl-srvtab i.dot.ok { background: var(--dl-ok); animation: dl-srv-pulse 2s ease-out infinite; } .dl-srvtab i.dot.bad { background: var(--dl-bad); }
/* The one status dot left: a server that is running pulses. */
@keyframes dl-srv-pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--dl-ok) 55%, transparent); } 70%, 100% { box-shadow: 0 0 0 6px transparent; } }
@media (prefers-reduced-motion: reduce) { .dl-srvtab i.dot.ok { animation: none; } }
.dl-srvtab:hover { color: var(--dl-fg); background: var(--dl-soft-hover); }
.dl-srvtab.on { background: var(--dl-card); color: var(--dl-fg); box-shadow: 0 1px 2px #0000002e, inset 0 0 0 1px var(--dl-line); }
.dl-srvtab:focus-visible { outline: 2px solid var(--dl-ring); outline-offset: 1px; }
@@ -455,11 +481,8 @@ const CSS = `
.dl-srvpagehead { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; margin: 0 0 20px; }
.dl-srvpagehead > .dl-title-row { display: flex; align-items: center; gap: 10px; width: 100%; flex-wrap: wrap; }
.dl-srvpagehead .dl-actions { margin: 0; flex-wrap: wrap; }
.dl-searchbtn { display: inline-flex !important; align-items: center; gap: 6px; }
.dl-searchbtn kbd { font-size: 11px; padding: 1px 5px; border-radius: 5px; background: var(--dl-soft); color: var(--dl-fg-muted); font-family: inherit; }
.dl-toolbar-end { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: nowrap; min-width: 0; }
.dl-toolbar-end .dl-search { flex: 0 1 300px; min-width: 160px; }
@media (max-width: 640px) { .dl-toolbar-end { flex-wrap: wrap; width: 100%; } .dl-toolbar-end .dl-search { flex: 1 1 100%; } }
@media (max-width: 640px) { .dl-toolbar-end { flex-wrap: wrap; width: 100%; } }
.dl-healthstrip { display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap; padding: 9px 14px; margin: 0 0 12px; border-radius: 12px;
border: 1px solid color-mix(in srgb, var(--dl-warn) 45%, transparent); background: var(--dl-warn-wash); font-size: 13px; color: var(--dl-fg-muted); }
.dl-healthstrip.bad { border-color: color-mix(in srgb, var(--dl-bad) 45%, transparent); background: var(--dl-bad-wash); }
@@ -491,15 +514,6 @@ const CSS = `
.dl-kinds button:focus-visible { outline: 2px solid var(--dl-ring); outline-offset: 2px; }
.dl-kinds button.on { border-color: var(--dl-accent); color: var(--dl-fg); background: color-mix(in srgb, var(--dl-accent) 10%, transparent); box-shadow: inset 0 0 0 1px var(--dl-accent); }
.dl-kinds button.on .dl-icon { color: var(--dl-accent); }
.dl-addrs { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 12px; border-top: 1px solid var(--dl-line); min-width: 0; }
.dl-addr { all: unset; box-sizing: border-box; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px 0 6px; max-width: 100%;
border-radius: 7px; background: var(--dl-soft); color: var(--dl-fg-muted); font: 500 11.5px/1 var(--dl-mono); }
.dl-addr .dl-icon { width: 12px; height: 12px; flex: 0 0 auto; opacity: .8; }
.dl-addr span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.dl-addr:hover { background: var(--dl-soft-hover); color: var(--dl-fg); }
.dl-addr:focus-visible { outline: 2px solid var(--dl-ring); outline-offset: 1px; }
.dl-addr.lan .dl-icon { color: var(--dl-accent); opacity: 1; }
.dl-addr.wan .dl-icon { color: var(--dl-ok); opacity: 1; }
.dl-choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; }
.dl-choice { all: unset; box-sizing: border-box; cursor: pointer; display: flex; flex-direction: column; gap: 4px; padding: 12px 14px;
border-radius: 12px; background: var(--dl-card); box-shadow: inset 0 0 0 1px var(--dl-line); transition: background .15s, box-shadow .15s; }
@@ -637,6 +651,36 @@ const CSS = `
.dl-check-body { flex: 1; min-width: 0; }
.dl-check-title { font-size: 14px; line-height: 20px; font-weight: 500; }
.dl-check-detail { font-size: 12px; line-height: 16px; color: var(--dl-fg-muted); overflow-wrap: anywhere; }
.dl-check-repaired { margin-top: 2px; font-size: 12px; line-height: 16px; color: var(--dl-warn); }
/* Health: watchdog card, then checks and the service log side by side. */
.dl-wd { margin: 0 0 16px; display: flex; flex-direction: column; gap: 14px; }
.dl-wd-head { display: flex; align-items: center; gap: 12px; min-width: 0; }
.dl-wd-head > .dl-stack { min-width: 0; }
.dl-wd-title { font-size: 16px; line-height: 24px; font-weight: 500; }
.dl-wd-tile { flex: none; width: 36px; height: 36px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; background: var(--dl-ok-wash); color: var(--dl-ok); }
.dl-wd-tile.off { background: var(--dl-soft); color: var(--dl-fg-faint); }
.dl-wd-tile .dl-icon { width: 18px; height: 18px; }
.dl-wd-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px; padding-top: 14px; border-top: 1px solid var(--dl-line); }
.dl-wd-chips { display: flex; flex-wrap: wrap; gap: 6px; flex: 1 1 auto; min-width: 0; }
.dl-wd-chips .dl-check-chip.error .dl-icon { color: var(--dl-bad); }
.dl-warn-text { color: var(--dl-warn) !important; }
.dl-health-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(440px, 100%), 1fr)); gap: 16px; align-items: start; }
.dl-health-cols > .dl-panel { margin: 0; min-width: 0; }
.dl-recent { display: flex; flex-direction: column; }
.dl-recent .dl-panel-head a { font-size: 13px; }
.dl-recent-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 32px 16px; color: var(--dl-fg-muted); font-size: 13px; border-top: 1px solid var(--dl-line); }
.dl-loading { margin: 0; font-size: 13px; }
.dl-diag-tabs { margin: 0 0 16px; }
.dl-row.dl-slog-row { align-items: baseline; }
.dl-slog-row .dl-ev-tile { align-self: flex-start; margin-top: -1px; }
.dl-slog-row.has-detail { cursor: pointer; }
.dl-row.dl-slog-row.has-detail:hover { background: color-mix(in srgb, var(--sys) 11%, transparent); }
.dl-slog-more { display: inline-flex; vertical-align: -2px; margin-left: 6px; color: var(--dl-fg-faint); transform: rotate(90deg); transition: transform .15s; }
.dl-slog-more .dl-icon { width: 14px; height: 14px; }
.dl-slog-more.open { transform: rotate(-90deg); }
.dl-slog-detail { margin: 8px 0 2px; padding: 8px 10px; border-radius: 8px; background: var(--dl-soft); font-family: var(--dl-mono); font-size: 12px; line-height: 17px; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--dl-fg-muted); cursor: text; }
}
/* tables inside panels */
.dl-table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 20px; }
@@ -656,8 +700,6 @@ const CSS = `
.dl-stack.gap4 { gap: 4px; } .dl-stack.gap8 { gap: 8px; }
.dl-sub { font-size: 12px; line-height: 16px; color: var(--dl-fg-muted); }
.dl-ok { color: var(--dl-ok); } .dl-warn { color: var(--dl-warn); } .dl-bad { color: var(--dl-bad); }
.dl-pill-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; display: inline-block; }
.dl-root kbd, .dl-pal kbd { font-family: var(--dl-mono); font-size: 11px; line-height: 16px; padding: 0 6px; border-radius: 4px; background: var(--dl-soft); color: var(--dl-fg-muted); }
/* Icon-only buttons are circles: width follows the theme's button height. */
.dl-icon-only { width: auto !important; min-width: 0 !important; aspect-ratio: 1 / 1; padding: 0 !important; justify-content: center; display: inline-flex !important; align-items: center; border-radius: 999px !important; }
.dl-panel.flush { padding: 0; overflow: hidden; }
@@ -831,6 +873,7 @@ const CSS = `
border-radius: 0 !important; background: transparent !important; color: inherit; font: 500 13px inherit; padding: 0 10px !important; height: 100% !important; min-width: 0 !important; }
.dl-slots { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 3px; }
.dl-slots i { height: 4px; border-radius: 999px; background: var(--dl-track); display: block; } .dl-slots i.used { background: var(--dl-fg); }
.dl-slots i.over { background: color-mix(in srgb, var(--dl-warn) 80%, transparent); }
.dl-date { display: flex; align-items: center; gap: 8px; flex: 1 1 150px; min-width: 0; box-sizing: border-box; height: 34px; padding: 0 10px; border: 1px solid var(--input, var(--dl-line)); border-radius: 8px; color: var(--dl-fg-faint); }
.dl-date input { border: 0 !important; background: transparent !important; box-shadow: none !important; padding: 0 !important; height: 32px !important; color: var(--dl-fg); flex: 1; min-width: 0 !important; width: 100% !important; }
.dl-meter { position: relative; height: 6px; border-radius: 999px; background: var(--dl-track); }
@@ -853,6 +896,10 @@ const CSS = `
.dl-map .cbi-section-create, .dl-map > .cbi-section > .cbi-button-add { display: none !important; }
.dl-pcard { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 20px; align-items: stretch; min-width: 0; }
.dl-pcard-main { min-width: 0; }
.dl-pcard-top { display: flex; align-items: center; gap: 12px; min-width: 0; }
.dl-pcard-top .dl-avatar { margin-right: 0; }
.dl-pcard-who { flex: 1; min-width: 0; }
.dl-pcard-who .dl-slotbar { margin: 3px 0 0; }
.dl-pside { display: flex; flex-direction: column; justify-content: space-between; gap: 8px; padding-left: 20px; border-left: 1px solid var(--dl-line); min-width: 0; }
.dl-pside-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dl-pside-state { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--dl-fg-muted); }
@@ -888,8 +935,8 @@ const CSS = `
.dl-card-name:hover { text-decoration: underline; }
.dl-chip-tag { font-size: 11px; line-height: 18px; padding: 0 6px; border-radius: 999px; background: var(--dl-warn-wash); color: var(--dl-warn); }
/* Online device: a soft green chip instead of a dot */
.dl-chip.live { background: color-mix(in srgb, var(--dl-ok) 6%, var(--dl-soft)); border: 1px dashed color-mix(in srgb, var(--dl-ok) 55%, transparent); }
.dl-chip.live:hover { background: color-mix(in srgb, var(--dl-ok) 11%, var(--dl-soft)); }
.dl-chip.live { background: var(--dl-ok-wash); color: color-mix(in srgb, var(--dl-ok) 35%, var(--dl-fg)); }
.dl-chip.live:hover { background: color-mix(in srgb, var(--dl-ok) 22%, transparent); }
.dl-chip.live .dl-icon { color: var(--dl-ok); }
.dl-fixes { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 0 44px; }
.dl-fix { all: unset; cursor: pointer; height: 26px; padding: 0 10px; border-radius: 999px; background: var(--dl-info-wash); color: var(--dl-info); font-size: 12px; font-weight: 500;
@@ -897,10 +944,6 @@ const CSS = `
.dl-fix:hover { filter: brightness(1.15); }
.dl-map .cbi-section-table-row.dl-attn-row { border-color: color-mix(in srgb, var(--dl-warn) 35%, transparent) !important; }
@media (max-width: 760px) { .dl-pcard { grid-template-columns: 1fr; } .dl-pside { padding: 12px 0 0; border-left: 0; border-top: 1px solid var(--dl-line); } .dl-fixes { margin-left: 0; } }
.dl-search { display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 10px 0 12px; border: 1px solid var(--input, var(--dl-line)); border-radius: 999px;
background: var(--input-bg, transparent); width: 280px; max-width: 100%; color: var(--dl-fg-faint); box-sizing: border-box; min-width: 0; }
.dl-search-input { text-overflow: ellipsis; border: 0 !important; background: transparent !important; box-shadow: none !important; outline: none; flex: 1; min-width: 0; color: var(--dl-fg);
font: inherit; font-size: 13px; padding: 0 !important; height: 32px !important; }
.dl-select { height: 34px !important; border-radius: 999px !important; min-width: 136px !important; width: auto !important; padding: 0 34px 0 14px !important;
appearance: none !important; -webkit-appearance: none !important; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b8f98' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") !important; background-repeat: no-repeat !important; background-position: right 12px center !important; background-size: 14px !important; }
.dl-savebar { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 160%); opacity: 0; transition: transform .25s cubic-bezier(.2,.8,.2,1), opacity .2s;
@@ -941,11 +984,7 @@ const CSS = `
.dl-dsec { border: 1px solid var(--dl-line); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.dl-dsec-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dl-dsec-head h4 { margin: 0 !important; padding: 0 !important; font-size: 14px !important; font-weight: 500 !important; border: 0 !important; }
.dl-live { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; }
.dl-live i.dot, .dl-dstat i.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--dl-fg-faint); display: inline-block; }
.dl-live i.dot.ok { background: var(--dl-ok); box-shadow: 0 0 0 3px var(--dl-ok-wash); } .dl-live i.dot.warn { background: var(--dl-warn); }
.dl-live i.dot.pulse { animation: dl-wait 1.6s ease-in-out infinite; }
@keyframes dl-wait { 0%, 100% { box-shadow: 0 0 0 0 var(--dl-warn-wash); } 50% { box-shadow: 0 0 0 6px transparent; } }
.dl-dstat i.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--dl-fg-faint); display: inline-block; }
.dl-connect-body { min-height: 60px; }
.dl-connect-body .dl-qr { width: min(240px, 70vw); }
.dl-kv2 { display: flex; flex-direction: column; }
@@ -961,26 +1000,10 @@ const CSS = `
@media (max-width: 560px) { .dl-drawer { width: 100%; } .dl-dstats { grid-template-columns: minmax(0, 1fr); } .dl-dstats-cell.wide { grid-column: auto; } .dl-dstats-cell + .dl-dstats-cell:not(.wide):last-child { border-left: 0; border-top: 1px solid var(--dl-line); } }
.dl-dev-log { display: flex; flex-direction: column; }
.dl-dev-log-row { display: flex; align-items: baseline; gap: 10px; padding: 7px 0; border-top: 1px solid var(--dl-line); font-size: 13px; min-width: 0; }
.dl-dev-log-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--dl-line); font-size: 13px; line-height: 20px; min-width: 0; }
.dl-dev-log-row:first-child { border-top: 0; padding-top: 0; }
.dl-dev-log-row .dl-row-main { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* command menu */
.dl-pal-overlay { position: fixed; inset: 0; z-index: 1000; background: var(--scrim, rgba(0,0,0,.5)); display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 0; }
.dl-pal { width: min(640px, 100%); background: var(--dl-elevated); color: var(--dl-fg); border-radius: 16px; overflow: hidden;
box-shadow: var(--shadow-menu, 0 16px 32px -8px rgba(0,0,0,.6)); border: 1px solid var(--dl-line); }
.dl-pal-search { display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 16px; border-bottom: 1px solid var(--dl-line); color: var(--dl-fg-faint); }
.dl-pal-input { flex: 1; border: 0 !important; background: transparent !important; box-shadow: none !important; outline: none; font: inherit; font-size: 16px; color: var(--dl-fg); padding: 0 !important; }
.dl-pal-list { max-height: 52vh; overflow: auto; padding: 8px; }
.dl-pal-group { padding: 8px 12px 4px; font-size: 12px; font-weight: 500; color: var(--dl-fg-faint); }
.dl-pal-item { display: flex; align-items: center; gap: 12px; min-height: 40px; padding: 0 12px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.dl-pal-item.sel { background: var(--dl-soft-hover); }
.dl-pal-item .dl-icon { color: var(--dl-fg-muted); }
.dl-pal-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dl-pal-ic { width: 16px; }
.dl-pal-empty { padding: 16px 12px; color: var(--dl-fg-muted); font-size: 14px; }
.dl-pal-foot { display: flex; gap: 16px; padding: 10px 16px; border-top: 1px solid var(--dl-line); font-size: 12px; color: var(--dl-fg-faint); }
/* settings */
.dl-settings-main { min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.dl-setsec { background: var(--dl-card); border: 1px solid var(--dl-line); border-radius: var(--dl-radius); overflow: hidden; scroll-margin-top: 88px; box-shadow: var(--dl-shadow); }
+10
View File
@@ -0,0 +1,10 @@
// Addresses of Dawnline's admin pages.
/** A server's People section (Servers page). */
export function peopleUrl(server?: string): string {
return `${L.url('admin/network/dawnline/server')}?${server ? `server=${encodeURIComponent(server)}&` : ''}section=people`;
}
export function personUrl(id: string, device?: string): string {
return `${L.url('admin/network/dawnline/person')}?id=${encodeURIComponent(id)}${device ? `&device=${encodeURIComponent(device)}` : ''}`;
}
+140 -38
View File
@@ -5,7 +5,7 @@
// devices on the left, access on the right.
import type { ClientConfig, Device, Kind, Person } from '../shared/types';
import { ACCESS_LABEL, KIND_LABEL, STATE_LABEL, ago, bytes, date, daysLeft, initials } from '../shared/format';
import { ACCESS_LABEL, KIND_LABEL, STATE_LABEL, ago, byDeviceState, bytes, date, daysLeft, initials } from '../shared/format';
import { iconSvg } from '../shared/icons';
import { qrSvg } from '../shared/qr';
import { vpnKey } from '../shared/vpnkey';
@@ -13,7 +13,10 @@ import { vpnKey } from '../shared/vpnkey';
interface State {
title: string;
person: Person;
server: { name: string; endpoint: string };
/** device_mesh: devices with home access reach each other through the tunnel. */
server: { name: string; endpoint: string; device_mesh?: boolean };
/** The device this page was opened from (through the tunnel), if any. */
here?: string | null;
can_add: boolean;
kinds: Kind[];
version: string;
@@ -312,7 +315,9 @@ function accessCard(st: State): HTMLElement {
if (p.quota_limit) tip(bar, () => [`${pct.toFixed(1)}% used`, `${bytes(Math.max(0, p.quota_limit - p.quota_used))} left`]);
const left = daysLeft(p.expires);
const slots = h('div', { class: 'slots' });
for (let i = 0; i < p.device_limit; i++) slots.appendChild(h('i', { class: i < p.devices.length ? 'used' : '' }));
// Devices the admin added over the limit get their own orange slots after the allowed ones.
for (let i = 0; i < Math.max(p.device_limit, p.devices.length); i++)
slots.appendChild(h('i', { class: i >= p.device_limit ? 'over' : i < p.devices.length ? 'used' : '' }));
const used = p.quota_used || p.month[0] + p.month[1];
const icon = p.access === 'internet' ? 'globe' : p.access === 'lan' ? 'home' : 'shield';
// Heading outside the card, like "Your devices", so both columns line up.
@@ -338,6 +343,7 @@ function accessCard(st: State): HTMLElement {
h('span', { class: 'muted s' }, ACCESS_TEXT[p.access]),
),
),
namesAtHome(p, !!st.server.device_mesh),
h(
'div',
{ class: 'tile' },
@@ -389,31 +395,76 @@ function accessCard(st: State): HTMLElement {
}
function deviceStatus(d: Device): HTMLElement {
if (d.disabled) return h('span', { class: 'dstat' }, h('i', { class: 'dot' }), 'Disabled by the admin');
if (d.online) return h('span', { class: 'dstat ok' }, h('i', { class: 'dot ok' }), 'Connected');
if (!d.handshake) return h('span', { class: 'dstat warn' }, h('i', { class: 'dot warn' }), 'Not set up yet');
return h('span', { class: 'dstat' }, h('i', { class: 'dot' }), `Last connected ${ago(d.handshake)}`);
// Status as coloured text, no dots (only the avatar carries one).
if (d.disabled) return h('span', { class: 'dstat' }, 'Disabled by the admin');
if (d.online) return h('span', { class: 'dstat ok' }, 'Connected');
if (!d.handshake) return h('span', { class: 'dstat warn' }, 'Not set up yet');
return h('span', { class: 'dstat' }, `Last connected ${ago(d.handshake)}`);
}
function localAddress(d: Device, p: Person): HTMLElement | null {
if (!d.hostname || p.access === 'internet') return null;
/**
* How other devices at home reach this person's devices: once, in the access card,
* instead of an address on every device card. Only with access to the home network.
*/
/**
* Whether the home network can open connections to this device: the router lets
* it through only for people with home access who are active, and devices on.
*/
function reachableFromHome(p: Person, d: Device): boolean {
return p.access !== 'internet' && p.state === 'active' && !d.disabled;
}
function namesAtHome(p: Person, mesh: boolean): HTMLElement | null {
const named = byDeviceState(p.devices).filter((d) => d.hostname && reachableFromHome(p, d));
if (!named.length) return null;
const first = named[0].hostname;
const domain = first.slice(first.indexOf('.'));
return h(
'div',
{ class: 'dfoot' },
h('span', { class: 'faint s' }, 'Local address'),
{ class: 'names' },
h(
'button',
{ type: 'button', class: 'lan-pill', 'aria-label': `Copy ${d.hostname}`, onclick: () => copy(d.hostname, 'Address copied') },
h('span', { class: 'lan-ic' }, ic('home')),
h('span', { class: 'mono' }, d.hostname),
h('span', { class: 'lan-sep' }),
ic('copy'),
'div',
{ class: 'names-head' },
h('span', { class: 'names-ic' }, ic('home')),
h(
'div',
{ class: 'stack' },
h('span', { class: 'strong s' }, 'Names at home'),
h(
'span',
{ class: 'faint s' },
mesh ? 'Devices at home and on this VPN reach yours as ' : 'Other devices at home reach yours as ',
h('span', { class: 'mono' }, `name${domain}`),
),
),
),
h(
'div',
{ class: 'names-list' },
named.map((d) => {
const dot = d.hostname.indexOf('.');
return h(
'button',
{
type: 'button',
class: 'name-chip',
title: d.name,
'aria-label': `Copy ${d.hostname}`,
onclick: () => copy(d.hostname, 'Address copied'),
},
h(
'span',
{ class: 'mono' },
dot > 0 ? [d.hostname.slice(0, dot), h('span', { class: 'faint' }, d.hostname.slice(dot))] : d.hostname,
),
ic('copy'),
);
}),
),
);
}
function deviceCard(d: Device, st: State): HTMLElement {
const p = st.person;
const more = h('button', { type: 'button', class: 'icon-btn soft', 'aria-label': `${d.name} options` }, ic('more'));
more.addEventListener('click', (ev) => {
ev.stopPropagation();
@@ -422,20 +473,37 @@ function deviceCard(d: Device, st: State): HTMLElement {
{ label: 'Copy AmneziaVPN key', icon: 'key', run: () => copyKey(d) },
{ label: 'Download .conf', icon: 'download', run: () => downloadConf(d) },
null,
// How devices at home reach it: only where the router actually lets them through.
...(reachableFromHome(st.person, d)
? [
{ label: 'Copy IP address', icon: 'copy', run: () => copy(d.address, 'IP address copied') },
...(d.hostname ? [{ label: 'Copy local address', icon: 'home', run: () => copy(d.hostname, 'Address copied') }] : []),
null,
]
: []),
{ label: 'Rename', icon: 'edit', run: () => rename(d) },
...(d.disabled ? [] : [{ label: 'New keys', icon: 'reset', run: () => rotateKeys(d, st) }]),
{ label: 'Remove', icon: 'trash', danger: true, run: () => removeDevice(d) },
]);
});
const week = d.spark.reduce((a, b) => a + b, 0);
const setUp = !d.handshake && !d.disabled;
// The device this page was opened from (through the tunnel): blue, and says so.
const here = st.here === d.id;
return h(
'article',
{ class: `dcard${d.online ? ' online' : ''}${d.disabled ? ' off' : ''}` },
{ class: `dcard${d.online ? ' online' : ''}${d.disabled ? ' off' : ''}${here ? ' here' : ''}` },
h(
'div',
{ class: 'dhead' },
h('span', { class: 'dic' }, ic(d.kind)),
h('div', { class: 'stack grow' }, h('span', { class: 'dname' }, d.name), deviceStatus(d)),
h(
'div',
{ class: 'stack grow' },
h('span', { class: 'dname' }, d.name),
// Opened through the tunnel, so it is connected: say which one it is instead.
here ? h('span', { class: 'dstat here' }, 'This device') : deviceStatus(d),
),
more,
),
setUp
@@ -446,7 +514,6 @@ function deviceCard(d: Device, st: State): HTMLElement {
ic(isMobile() ? 'open' : 'qr'),
h('span', {}, isMobile() ? 'Open in AmneziaVPN' : 'Connect this device'),
),
h('span', { class: 'faint s center' }, 'Setting up another device? QR, key and file are under ⋯'),
]
: h(
'div',
@@ -463,7 +530,6 @@ function deviceCard(d: Device, st: State): HTMLElement {
h('button', { type: 'button', class: 'btn small', onclick: () => connect(d) }, 'Update'),
)
: null,
localAddress(d, p),
);
}
@@ -497,7 +563,9 @@ function main(st: State) {
)
: null;
const cards: HTMLElement[] = p.devices.map((d) => deviceCard(d, st));
// The device this page was opened from comes first.
const order = byDeviceState(p.devices).sort((a, b) => Number(b.id === st.here) - Number(a.id === st.here));
const cards: HTMLElement[] = order.map((d) => deviceCard(d, st));
const free = Math.max(0, p.device_limit - p.devices.length);
if (free)
cards.push(
@@ -505,12 +573,8 @@ function main(st: State) {
'button',
{ type: 'button', class: 'slot add', onclick: addDevice },
h('span', { class: 'slot-ic' }, ic('plus')),
h(
'span',
{ class: 'stack' },
h('span', { class: 'strong' }, 'Add device'),
h('span', { class: 'faint s' }, `${free} slot${free === 1 ? '' : 's'} free`),
),
// How many are left is in "Your devices 3 of 10" and the Devices tile.
h('span', { class: 'strong' }, 'Add device'),
),
);
@@ -523,8 +587,8 @@ function main(st: State) {
h(
'div',
{ class: 'row-baseline' },
// How many (the Devices tile) and which are online (the cards) are shown already.
h('h2', {}, 'Your devices'),
h('span', { class: 'faint s' }, `${p.devices.length} of ${p.device_limit} · ${p.online} online`),
),
),
h('div', { class: 'dgrid' }, cards),
@@ -548,11 +612,12 @@ function main(st: State) {
h(
'div',
{ class: 'stack' },
h('div', { class: 'row' }, h('h1', {}, `Hi, ${p.name}`), h('span', { class: `pill ${stateTone(p)}` }, STATE_LABEL[p.state])),
// Only when something is wrong: an "Active" pill says nothing.
h(
'span',
{ class: 'faint s' },
`${p.online ? `${p.online} device${p.online === 1 ? '' : 's'} online` : 'Nothing connected right now'} · ${bytes(p.month[0] + p.month[1])} this month`,
'div',
{ class: 'row' },
h('h1', {}, `Hi, ${p.name}`),
p.state === 'active' ? null : h('span', { class: `pill ${stateTone(p)}` }, STATE_LABEL[p.state]),
),
),
),
@@ -720,10 +785,9 @@ async function connect(d: Device, initial?: 'app' | 'qr' | 'key' | 'file', cfgIn
const live = h('div', { class: 'waiting' });
const paintLive = (dev: Device | undefined) => {
if (dev?.online) live.replaceChildren(h('i', { class: 'dot ok' }), h('span', { class: 'ok' }, `${d.name} is connected`));
else if (dev?.handshake)
live.replaceChildren(h('i', { class: 'dot' }), h('span', { class: 'muted' }, `Last connected ${ago(dev.handshake)}`));
else live.replaceChildren(h('i', { class: 'dot warn pulse' }), h('span', { class: 'muted' }, 'Waiting for the first connection…'));
if (dev?.online) live.replaceChildren(h('span', { class: 'ok' }, `${d.name} is connected`));
else if (dev?.handshake) live.replaceChildren(h('span', { class: 'muted' }, `Last connected ${ago(dev.handshake)}`));
else live.replaceChildren(h('span', { class: 'warn' }, 'Waiting for the first connection…'));
};
paintLive(d);
const watch = window.setInterval(async () => {
@@ -777,6 +841,44 @@ function rename(d: Device) {
setTimeout(() => name.select(), 50);
}
/** New keys for a device: the old configuration stops working, the new one is shown right away. */
function rotateKeys(d: Device, st: State) {
const here = st.here === d.id;
sheet(
`New keys for ${d.name}?`,
null,
h(
'p',
{ class: 'muted' },
here
? 'This device is connected through the configuration it has now: it disconnects a few seconds after you confirm. Import the new configuration that opens next.'
: 'Its current configuration stops working. Set the device up again with the new one that opens next.',
),
h(
'div',
{ class: 'row gap' },
h('button', { class: 'btn block', onclick: () => closeSheet() }, 'Cancel'),
h(
'button',
{
class: 'btn primary block',
onclick: async () => {
try {
const r = await call<{ config: ClientConfig; state: State }>(`devices/${d.id}`, { action: 'rotate' });
state = r.state;
main(state);
connect(d, undefined, r.config);
} catch (er) {
toast((er as Error).message, true);
}
},
},
'New keys',
),
),
);
}
function removeDevice(d: Device) {
sheet(
`Remove ${d.name}?`,
+69 -59
View File
@@ -454,6 +454,9 @@ h2 {
.slots i.used {
background: var(--text);
}
.slots i.over {
background: color-mix(in srgb, var(--warn) 80%, transparent);
}
/* devices */
.dgrid {
@@ -512,6 +515,21 @@ h2 {
background: var(--ok-wash);
color: var(--ok);
}
/* The device this page was opened from: blue tile, blue status, blue border. */
.dcard.here {
border: 1.5px dotted color-mix(in srgb, var(--accent) 80%, transparent);
}
.dcard.here .dic {
background: color-mix(in srgb, var(--accent) 16%, transparent);
color: var(--info);
}
.dstat.here {
color: var(--info);
}
.dot.here {
background: var(--accent);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.dname {
font-weight: 500;
white-space: nowrap;
@@ -586,78 +604,70 @@ h2 {
opacity: 1;
filter: brightness(1.2);
}
.dfoot {
/* Names at home (access card) */
.names {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 8px;
padding-top: 12px;
border-top: 1px solid var(--line);
flex-direction: column;
gap: 10px;
padding: 12px;
border-radius: 12px;
border: 1px solid var(--line);
}
.dfoot > .faint {
white-space: nowrap;
.names-head {
display: flex;
gap: 10px;
align-items: flex-start;
}
.lan-pill {
all: unset;
cursor: pointer;
display: inline-flex;
align-items: center;
height: 26px;
padding: 0 3px;
border-radius: 999px;
max-width: 100%;
min-width: 0;
background: linear-gradient(180deg, color-mix(in srgb, var(--text) 6%, transparent), color-mix(in srgb, var(--text) 2.5%, transparent));
box-shadow:
inset 0 0 0 1px var(--line),
0 1px 2px #0003;
}
.lan-pill:hover {
box-shadow:
inset 0 0 0 1px var(--input),
0 1px 2px #0003;
}
.lan-pill:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.lan-ic {
width: 20px;
height: 20px;
border-radius: 50%;
.names-ic {
width: 28px;
height: 28px;
border-radius: 8px;
display: inline-flex;
align-items: center;
justify-content: center;
flex: 0 0 auto;
flex: none;
background: color-mix(in srgb, var(--info) 14%, transparent);
color: var(--info);
}
.lan-ic .ic-svg {
width: 11px;
height: 11px;
.names-ic .ic-svg {
width: 15px;
height: 15px;
}
.lan-pill .mono {
padding: 0 8px 0 7px;
font-weight: 500;
white-space: nowrap;
.names-list {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.name-chip {
all: unset;
box-sizing: border-box;
cursor: pointer;
display: inline-flex;
align-items: center;
gap: 6px;
height: 28px;
max-width: 100%;
padding: 0 9px 0 10px;
border-radius: 999px;
background: var(--soft);
}
.name-chip:hover {
background: var(--soft-hover);
}
.name-chip:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.name-chip .mono {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
min-width: 0;
}
.lan-sep {
width: 1px;
height: 14px;
background: var(--line);
flex: 0 0 auto;
}
.lan-pill > .ic:last-child {
width: 22px;
justify-content: center;
color: var(--muted);
}
.lan-pill > .ic:last-child .ic-svg {
width: 12px;
height: 12px;
.name-chip .ic-svg {
width: 13px;
height: 13px;
color: var(--faint);
}
.slot.add {
all: unset;
+9
View File
@@ -118,3 +118,12 @@ export function slugify(s: string): string {
.replace(/^-+|-+$/g, '')
.slice(0, 32);
}
/** Online, then offline, then not set up yet, then turned off; the order they were added within each. */
export function byDeviceState<T extends { online: boolean; handshake: number; disabled: boolean }>(list: T[]): T[] {
const rank = (d: T) => (d.disabled ? 3 : d.online ? 0 : d.handshake ? 1 : 2);
return list
.map((d, i) => [d, i] as const)
.sort((a, b) => rank(a[0]) - rank(b[0]) || a[1] - b[1])
.map(([d]) => d);
}
+2 -1
View File
@@ -30,6 +30,8 @@ const P: Record<string, string> = {
play: '<path d="M7 4l13 8-13 8z"/>',
key: '<circle cx="8" cy="15" r="4"/><path d="M11 12l8-8M16 7l2 2"/>',
out: '<path d="M14 4h6v16h-6M10 8l-4 4 4 4M6 12h10"/>',
admin:
'<path d="M6 21v-2a4 4 0 0 1 4-4h2"/><path d="M22 16c0 4-2.5 6-3.5 6s-3.5-2-3.5-6c1 0 2.5-.5 3.5-1.5 1 1 2.5 1.5 3.5 1.5z"/><circle cx="10" cy="7" r="4"/>',
shield: '<path d="M12 3l8 3v6c0 5-3.5 8-8 9-4.5-1-8-4-8-9V6z"/>',
shieldplus: '<path d="M12 3l8 3v6c0 5-3.5 8-8 9-4.5-1-8-4-8-9V6z"/><path d="M12 9v6M9 12h6"/>',
lock: '<rect x="5" y="10.5" width="14" height="10" rx="2"/><path d="M8 10.5V8a4 4 0 0 1 8 0v2.5"/><path d="M12 14.5v2"/>',
@@ -41,7 +43,6 @@ const P: Record<string, string> = {
home: '<path d="M3 11l9-7 9 7"/><path d="M5 10v10h14V10"/>',
open: '<path d="M14 4h6v6M20 4l-9 9M18 14v6H4V6h6"/>',
file: '<path d="M6 3h8l4 4v14H6z"/><path d="M14 3v4h4"/>',
search: '<circle cx="11" cy="11" r="7"/><path d="M20 20l-4-4"/>',
network:
'<circle cx="12" cy="12" r="2.5"/><circle cx="5" cy="5" r="1.8"/><circle cx="19" cy="5" r="1.8"/><circle cx="5" cy="19" r="1.8"/><circle cx="19" cy="19" r="1.8"/><path d="m6.4 6.4 3.8 3.8M17.6 6.4l-3.8 3.8M6.4 17.6l3.8-3.8M17.6 17.6l-3.8-3.8"/>',
moon: '<path d="M20 14.5A8 8 0 1 1 9.5 4a6.5 6.5 0 0 0 10.5 10.5z"/>',
+8
View File
@@ -75,6 +75,8 @@ export interface Server {
enabled: boolean;
/** Internet traffic enters the router from the LAN, like a home device's. */
lan_like: boolean;
/** Devices of people with home access reach each other through the tunnel. */
device_mesh: boolean;
preset: string;
mtu: number;
keepalive: number;
@@ -107,6 +109,12 @@ export interface LogEvent {
detail?: string;
/** City · network operator, when known at the time of the event. */
where?: string | null;
/** Who did it, when a person did: the admin in LuCI or the person on their portal. */
by?: 'admin' | 'portal';
/** Names at the time of the event, for people and devices removed since. */
pname?: string;
dname?: string;
dkind?: string;
}
export interface GeoPoint {
+9 -1
View File
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
import { inflateSync } from 'node:zlib';
import { bytes, daysLeft, initials, quotaText, slugify } from '../src/shared/format';
import { byDeviceState, bytes, daysLeft, initials, quotaText, slugify } from '../src/shared/format';
import { amneziaJson, base64Url, fromBase64Url, vpnKey, withPrivateKey } from '../src/shared/vpnkey';
import type { ClientConfig } from '../src/shared/types';
@@ -89,3 +89,11 @@ describe('vpn:// keys', () => {
expect(c.amnezia.client_priv_key).toBe('ZZZ=');
});
});
describe('byDeviceState', () => {
it('puts online first, then offline, not set up and turned off, keeping the order within each', () => {
const d = (name: string, online: boolean, handshake: number, disabled = false) => ({ name, online, handshake, disabled });
const list = [d('off', false, 5, true), d('new', false, 0), d('away1', false, 9), d('live', true, 10), d('away2', false, 3)];
expect(byDeviceState(list).map((x) => x.name)).toEqual(['live', 'away1', 'away2', 'new', 'off']);
});
});