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:
1 parent
d0955e44b8
commit
82ab86848e
50 files changed
+2166
-982
No files matched your search
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user