Dawnline 0.4.0
Build packages / Version (push) Waiting to run

- Components tab replaces Updates: Dawnline, the AmneziaWG build for this
  firmware (Slava-Shchipunov 2.0 or 2Grey 3.1, Russian translation) and
  the system packages Dawnline adds, each checked, installed, reinstalled
  or rolled back in place, with What's new, versions and an activity log
- Automatic updates: daily check, install at a set time or right away,
  per component; AmneziaWG is left out by default and an automatic run
  never switches its build or generation
- Downloads verified against GitHub's sha256; mirrors are used only when
  GitHub is unreachable and the hash is known
- New installer: checks firmware, clock, space and DNS, lets you pick a
  release, shows the plan and asks first; --dry-run
- New uninstaller removes everything Dawnline added (cron, nft, firewall,
  routing, interfaces, packages it installed); --dry-run
- Works without AmneziaWG on the router: Overview, the setup wizard,
  Health and Components say what is missing and offer to install it
- Overview shows failed health checks as notices with their fix
- People list no longer reads the config from the browser: private keys
  stay on the router; personal links are fetched on demand
- Config changes are serialized under one lock, the nft table loads
  atomically and fails closed, and Dawnline never touches network
  sections it did not create
- The portal never opens system ports, keeps disabled devices disabled,
  rate-limits per address and counts days by the router's clock
- Settings and Diagnostics load their heavy parts in the background
- Release notes are written from the commits since the previous release
- Backend and admin UI split into small single-purpose modules
This commit is contained in:
Aemeath committed 2026-10-16 02:14:15 +03:00
1 parent 70a932b8ea
commit 34293fb8e5
158 files changed
+17418 -10022

No files matched your search

+195 -244
View File
@@ -1,39 +1,41 @@
// People: a native GridSection over `person` sections rendered as cards.
// Edits in the modal are staged (Save & Apply with rollback); creating,
// pausing and device actions take effect immediately through RPC.
// People: one card per person, built from the status (the config itself,
// with keys, is never read by the browser). Creating, editing, pausing and
// device actions take effect immediately through RPC.
import type { Person, Status } from '../../shared/types';
import { E } from '../e';
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 { button, iconButton } from '../ui/button';
import { cancelButton, closeModal, confirmDialog, modal } from '../ui/modal';
import { copyText } from '../ui/files';
import { dropdown, type MenuItem } from '../ui/menu';
import { attempt, notify } from '../ui/toast';
import { attachTip } from '../ui/tooltip';
import { accessBadge, stateBadge } from '../ui/badges';
import { addDevice, openDevice, type DeviceOpts } from '../device';
import { copyPersonLink, inviteCard } from '../invite';
import { personUrl } from '../urls';
import { scoped } from './overview';
import { attachTip } from '../charts';
import { scoped } from '../state/scope';
import { createPoller, focusInside, type Poller } from '../state/poller';
import { accessPicker } from '../widgets/access-picker';
import { coreFor } from '../cores';
import { icon } from '../../shared/icons';
import { ACCESS_LABEL, KIND_LABEL, STATE_LABEL, ago, bits, byDeviceState, bytes, date, daysLeft, initials } from '../../shared/format';
import {
KIND_LABEL,
addMonthsClamped,
ago,
bits,
byDeviceState,
bytes,
date,
dayDiff,
daysLeft,
initials,
todayOf,
} from '../../shared/format';
type Sid = string;
const STATE_ICON: Record<Person['state'], string> = {
active: '',
paused: 'pause',
paused_all: 'pause',
expired: 'calendar',
quota: 'chart',
hours: 'clock',
no_server: 'alert',
};
/** Nothing while active; otherwise a small icon with the state as tooltip. */
export function stateBadge(p: Person): HTMLElement | '' {
if (p.state === 'active') return '';
const el = E('span', { class: `dl-ibadge ${stateTone(p)}`, 'aria-label': STATE_LABEL[p.state] }, icon(STATE_ICON[p.state] || 'alert'));
attachTip(el, () => [E('div', { class: 'dl-tip-title' }, STATE_LABEL[p.state])]);
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;
@@ -51,69 +53,11 @@ function slotBar(p: Person): HTMLElement {
]);
}
/** 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'];
const el = E(
'span',
{ class: 'dl-access', 'aria-label': ACCESS_LABEL[p.access] },
kinds.map((k) => E('span', { class: `dl-ibadge ${k}` }, icon(k === 'lan' ? 'home' : 'globe'))),
);
attachTip(el, () => [
E('div', { class: 'dl-tip-title' }, ACCESS_LABEL[p.access]),
p.access === 'lan' && p.services?.length
? E('div', { class: 'dl-muted' }, `${p.services.length} home service${p.services.length === 1 ? '' : 's'} only`)
: '',
]);
return el;
}
export function stateTone(p: Person): string {
if (p.state === 'active') return 'ok';
if (p.state === 'quota' || p.state === 'expired') return 'bad';
return 'warn';
}
/** Access choice cards; returns the element and a getter. */
export function accessPicker(initial: Person['access'], onChange?: (v: Person['access']) => void) {
let value = initial;
const opts: { v: Person['access']; ic: string; text: string }[] = [
{ v: 'internet', ic: 'globe', text: 'Browse the internet through your router. No access to devices at home.' },
{ v: 'lan', ic: 'home', text: 'Reach devices at home (NAS, printer, cameras). Internet stays on their own connection.' },
{ v: 'both', ic: 'shield', text: 'Home devices and the internet, all through your router.' },
];
const el = E(
'div',
{ class: 'dl-choices' },
opts.map((o) =>
E(
'button',
{
type: 'button',
class: `dl-choice${o.v === value ? ' selected' : ''}`,
'data-v': o.v,
click: () => {
value = o.v;
el.querySelectorAll('.dl-choice').forEach((c) => c.classList.toggle('selected', (c as HTMLElement).dataset.v === o.v));
onChange?.(o.v);
},
},
[E('span', { class: 'dl-choice-title' }, [icon(o.ic), ACCESS_LABEL[o.v]]), E('span', { class: 'dl-choice-text' }, o.text)],
),
),
);
return { el, get: () => value };
}
function isoDate(d: Date): string {
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
}
type Filter = 'all' | 'online' | 'attention' | 'paused';
type SortBy = 'seen' | 'name' | 'usage';
function needsAttention(p: Person): boolean {
const left = daysLeft(p.expires);
function needsAttention(p: Person, today: string): boolean {
const left = daysLeft(p.expires, today);
return (
p.state === 'quota' ||
p.state === 'expired' ||
@@ -122,18 +66,23 @@ function needsAttention(p: Person): boolean {
);
}
function addMonth(iso: string): string {
const d = iso ? new Date(`${iso}T12:00:00`) : new Date();
const from = d.getTime() < Date.now() ? new Date() : d;
from.setMonth(from.getMonth() + 1);
return `${from.getFullYear()}-${String(from.getMonth() + 1).padStart(2, '0')}-${String(from.getDate()).padStart(2, '0')}`;
/** A month more, from the end date or from today once it has passed. */
function addMonth(end: string, today: string): string {
return addMonthsClamped(end && dayDiff(end, today) >= 0 ? end : today, 1);
}
const ids = (st: Status) =>
st.people
.map((p) => p.id)
.sort()
.join(' ');
let addOpened = false;
export class PeoplePage {
st!: Status;
map: any;
/** The cards, one per person, in the current sort order. */
private list: HTMLElement = E('div', { class: 'dl-plist', role: 'list' });
// `?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';
@@ -141,8 +90,8 @@ export class PeoplePage {
noFooter = true;
/** Set when shown as a server's People section: only that server's people. */
serverId: string | null = null;
polling = false;
el: HTMLElement | null = null;
poller?: Poller<Status>;
async load(): Promise<Status> {
return api.status(30);
@@ -163,127 +112,144 @@ export class PeoplePage {
return this.st.people.find((p) => p.id === sid);
}
/**
* Status for this page, newest request wins: a poll that started before an
* edit must not paint its older answer over the refresh that follows it.
*/
private statusSeq = 0;
private statusShown = 0;
async latestStatus(): Promise<Status | null> {
const seq = ++this.statusSeq;
const st = await api.status(30).catch(() => null);
if (!st || seq < this.statusShown) return null;
this.statusShown = seq;
return st;
get today(): string {
return todayOf(this.st.series);
}
/** What a device drawer opened from here gets. */
deviceOpts(p: Person): DeviceOpts {
return {
refresh: () => this.refresh(),
geo: this.st.geo,
now: this.st.now,
today: this.today,
core: coreFor(this.st.servers, p.server),
};
}
/**
* A new status (newest answer wins, see the poller). People added or removed
* elsewhere re-render the list; otherwise the cards repaint in place.
*/
take(stAll: Status, quiet: boolean) {
const st = this.scope(stAll);
const changed = ids(st) !== ids(this.st);
this.st = st;
if (changed) this.rebuild();
else {
this.paintCards(quiet);
this.decorate(quiet);
}
}
/** Repaint the cards from a fresh status (after a change made here). */
async update() {
await this.poller?.refresh();
}
/** Everything again, the form's sections too (after adding or removing someone). */
async refresh() {
const st = await this.latestStatus();
this.poller?.claim();
const st = await api.status(30).catch(() => null);
if (!st) return;
this.st = this.scope(st);
uci.unload('dawnline');
await this.map.load();
await this.map.reset();
// The map keeps cards it already drew: paint them from the new status, like poll().
this.paintCards();
this.rebuild();
}
/** One card per person (cards already shown are kept and repainted), or the empty state. */
rebuild() {
const old = new Map<string, HTMLElement>();
for (const el of Array.from(this.list.children) as HTMLElement[]) if (el.dataset.sid) old.set(el.dataset.sid, el);
const cards = this.st.people.map((p) => {
const card = old.get(p.id) ?? E('div', { class: 'dl-card', role: 'listitem', 'data-sid': p.id });
return this.renderCard(card, p.id);
});
dom.content(
this.list,
cards.length
? cards
: E(
'div',
{ class: 'dl-plist-none' },
this.st.servers.length
? 'No people yet. Add someone and send them their personal link.'
: 'Set up the server first, then add people.',
),
);
this.decorate();
}
paintCards() {
/** `quiet` (a periodic repaint) leaves alone a card that has the keyboard focus. */
paintCards(quiet = false) {
for (const p of this.st.people) {
const card = document.getElementById(`dl-card-${p.id}`);
if (card) this.renderCard(card, p.id);
const card = this.card(p.id);
if (card && !(quiet && focusInside(card))) this.renderCard(card, p.id);
}
}
/** This page's card for a person (a server's People section has its own list). */
card(sid: Sid): HTMLElement | null {
return this.list.querySelector<HTMLElement>(`[data-sid="${CSS.escape(sid)}"]`);
}
render(stAll: Status): Promise<Node> {
const st = this.scope(stAll);
this.st = st;
const page = this;
let o: any;
const m = new form.Map('dawnline');
this.map = m;
const s = m.section(form.GridSection, 'person');
s.anonymous = true;
s.addremove = true;
s.addbtntitle = 'Add person';
s.nodescriptions = true;
s.renderSectionPlaceholder = () =>
E(
'em',
{},
st.servers.length ? 'No people yet. Add someone and send them their personal link.' : 'Set up the server first, then add people.',
);
// As a server section: only rows of people on that server.
if (page.serverId) s.filter = (sid: Sid) => page.st.people.some((p) => p.id === sid);
s.handleAdd = () => page.openCreate();
s.handleRemove = (sid: Sid) => page.remove(sid);
// Actions live inside the card (title row).
s.renderRowActions = () => E('div', { class: 'dl-none' });
o = s.option(form.DummyValue, '_card');
o.modalonly = false;
o.textvalue = (sid: Sid) => page.renderCard(E('div', { class: 'dl-card', id: `dl-card-${sid}` }), sid);
return m.render().then((node: HTMLElement) => {
node.classList.add('dl-map', 'dl-root');
const sort = E(
'select',
{
class: 'dl-select',
'aria-label': 'Sort',
change: (ev: Event) => {
page.sort = (ev.target as HTMLSelectElement).value as SortBy;
page.decorate();
},
const sort = E(
'select',
{
class: 'dl-select',
'aria-label': 'Sort',
change: (ev: Event) => {
page.sort = (ev.target as HTMLSelectElement).value as SortBy;
page.decorate();
},
[E('option', { value: 'seen' }, 'Last seen'), E('option', { value: 'name' }, 'Name'), E('option', { value: 'usage' }, 'Usage')],
);
const wrap = E('div', { class: 'dl-root' }, [
page.serverId
? ''
: E('div', { class: 'dl-pagehead' }, [
E('div', { class: 'dl-stack' }, [
E('h2', { class: 'dl-h1' }, 'People'),
E('span', { class: 'dl-muted', id: 'dl-people-count' }, this.countText()),
]),
st.servers.length ? button([icon('plus'), ' Add person'], () => page.openCreate(), 'add') : '',
},
[E('option', { value: 'seen' }, 'Last seen'), E('option', { value: 'name' }, 'Name'), E('option', { value: 'usage' }, 'Usage')],
);
const wrap = E('div', { class: 'dl-root' }, [
page.serverId
? ''
: E('div', { class: 'dl-pagehead' }, [
E('div', { class: 'dl-stack' }, [
E('h2', { class: 'dl-h1' }, 'People'),
E('span', { class: 'dl-muted dl-people-count' }, this.countText()),
]),
st.servers.length
? ''
: E('div', { class: 'alert-message warning' }, [
'No server yet. ',
E('a', { href: L.url('admin/network/dawnline/server') }, 'Run the setup wizard'),
' before adding people.',
]),
E('div', { class: 'dl-toolbar' }, [
E('div', { class: 'dl-seg', id: 'dl-people-tabs', role: 'tablist' }),
// Sort and add stay together on the right, wrapping as one group.
E('div', { class: 'dl-toolbar-end' }, [
sort,
page.serverId ? button([icon('plus'), ' Add person'], () => page.openCreate(), 'add') : '',
st.servers.length ? button([icon('plus'), ' Add person'], () => page.openCreate(), 'add') : '',
]),
st.servers.length
? ''
: E('div', { class: 'alert-message warning' }, [
'No server yet. ',
E('a', { href: L.url('admin/network/dawnline/server') }, 'Run the setup wizard'),
' before adding people.',
]),
E('div', { class: 'dl-toolbar' }, [
E('div', { class: 'dl-seg dl-people-tabs', role: 'tablist' }),
// Sort and add stay together on the right, wrapping as one group.
E('div', { class: 'dl-toolbar-end' }, [
sort,
page.serverId ? button([icon('plus'), ' Add person'], () => page.openCreate(), 'add') : '',
]),
node,
]);
this.el = wrap;
requestAnimationFrame(() => this.decorate());
if (!this.polling) {
this.polling = true;
// Only while visible (a server section may be swapped out).
poll.add(() => (page.el?.isConnected ? page.poll() : Promise.resolve()), 10);
}
// ?add=1 opens Add person once, not again on every server's People tab.
if (!addOpened && new URLSearchParams(location.search).get('add')) {
addOpened = true;
setTimeout(() => page.openCreate(), 100);
}
return wrap;
]),
this.list,
]);
this.el = wrap;
this.rebuild();
// Only while visible (a server section may be swapped out).
this.poller ??= createPoller({
fetch: () => api.status(30),
every: 10,
active: () => !!page.el?.isConnected,
apply: (st, quiet) => page.take(st, quiet),
});
// ?add=1 opens Add person once, not again on every server's People tab.
if (!addOpened && new URLSearchParams(location.search).get('add')) {
addOpened = true;
setTimeout(() => page.openCreate(), 100);
}
return Promise.resolve(wrap);
}
countText(): string {
@@ -291,19 +257,21 @@ 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 and sort order. */
decorate() {
const c = document.getElementById('dl-people-count');
/** Row classes, counters, filter tabs and sort order; a `quiet` repaint keeps focused tabs. */
decorate(quiet = false) {
const c = this.el?.querySelector('.dl-people-count');
if (c) c.textContent = this.countText();
const people = this.st.people;
const today = this.today;
const attn = (p: Person) => needsAttention(p, today);
const counts: Record<Filter, number> = {
all: people.length,
online: people.filter((p) => p.online > 0).length,
attention: people.filter(needsAttention).length,
attention: people.filter(attn).length,
paused: people.filter((p) => p.state !== 'active' && p.state !== 'quota' && p.state !== 'expired').length,
};
const tabs = document.getElementById('dl-people-tabs');
if (tabs) {
const tabs = this.el?.querySelector<HTMLElement>('.dl-people-tabs');
if (tabs && !(quiet && focusInside(tabs))) {
const label: Record<Filter, string> = { all: 'All', online: 'Online', attention: 'Needs attention', paused: 'Paused' };
dom.content(
tabs,
@@ -326,7 +294,7 @@ export class PeoplePage {
}
const match = (p: Person) => {
if (this.filter === 'online' && !p.online) return false;
if (this.filter === 'attention' && !needsAttention(p)) return false;
if (this.filter === 'attention' && !attn(p)) return false;
if (this.filter === 'paused' && !(p.state !== 'active' && p.state !== 'quota' && p.state !== 'expired')) return false;
return true;
};
@@ -337,52 +305,40 @@ export class PeoplePage {
? b.month[0] + b.month[1] - (a.month[0] + a.month[1])
: b.online - a.online || b.last_seen - a.last_seen,
);
let tbody: Element | null = null;
let shown = 0;
for (const p of order) {
const card = document.getElementById(`dl-card-${p.id}`);
const row = card?.closest('.cbi-section-table-row') as HTMLElement | null;
if (!row) continue;
tbody ??= row.parentElement;
tbody?.appendChild(row);
row.classList.toggle('dl-off', p.state !== 'active');
row.classList.toggle('dl-attn-row', p.state === 'quota' || p.state === 'expired');
// A class, not an inline style: the card layout sets display with !important.
const card = this.card(p.id);
if (!card) continue;
this.list.appendChild(card);
card.classList.toggle('dl-off', p.state !== 'active');
card.classList.toggle('dl-attn-row', p.state === 'quota' || p.state === 'expired');
const hit = match(p);
row.classList.toggle('dl-filtered', !hit);
card.classList.toggle('dl-filtered', !hit);
if (hit) shown++;
}
// 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', {}, 'No one here right now.'));
if (none.parentElement !== table.parentElement) table.after(none);
let none = this.el?.querySelector<HTMLElement>('.dl-people-none') ?? null;
if (people.length && !shown) {
none ??= E('div', { class: 'dl-empty dl-people-none' }, E('p', {}, 'No one here right now.'));
if (none.previousElementSibling !== this.list) this.list.after(none);
} else none?.remove();
}
async poll() {
const stAll = await this.latestStatus();
if (!stAll) return;
const st = this.scope(stAll);
this.st = st;
this.paintCards();
this.decorate();
}
async quick(p: Person, patch: Parameters<typeof api.personUpdate>[1], ok: string) {
if (await attempt(() => api.personUpdate(p.id, patch), ok)) await this.poll();
if (await attempt(() => api.personUpdate(p.id, patch), ok)) await this.update();
}
renderCard(node: HTMLElement, sid: Sid): HTMLElement {
const p = this.person(sid);
if (!p) {
dom.content(node, E('em', {}, 'Not saved yet — use “Save & Apply”.'));
dom.content(node, E('em', {}, 'This person was just removed.'));
return node;
}
const left = daysLeft(p.expires);
const today = this.today;
const left = daysLeft(p.expires, today);
const free = Math.max(0, p.device_limit - p.devices.length);
// The link itself is not in the status (person_links asks for it).
const portal = p.has_link ?? this.st.settings.portal_enabled;
// Term and hours sit by the name; online/last seen lives in the strip below.
const pills: Node[] = [];
@@ -407,7 +363,7 @@ export class PeoplePage {
title: `${KIND_LABEL[d.kind]} · ${d.address}${d.online ? ` · online from ${d.endpoint}` : d.handshake ? ` · seen ${ago(d.handshake, this.st.now)}` : ''}`,
click: (ev: Event) => {
ev.preventDefault();
openDevice(p, d, () => this.refresh(), this.st.geo);
void openDevice(p, d, this.deviceOpts(p));
},
},
[
@@ -430,7 +386,7 @@ export class PeoplePage {
title: free > 0 ? 'Add device' : 'Add device · over the limit, admins can still add',
click: (ev: Event) => {
ev.preventDefault();
addDevice(p, () => this.refresh());
addDevice(p, this.deviceOpts(p));
},
},
icon('plus'),
@@ -454,7 +410,7 @@ export class PeoplePage {
fixes.push(
E(
'button',
{ type: 'button', class: 'dl-fix', click: () => this.quick(p, { expires: addMonth(p.expires) }, 'Extended by 1 month') },
{ type: 'button', class: 'dl-fix', click: () => this.quick(p, { expires: addMonth(p.expires, today) }, 'Extended by 1 month') },
'Extend 1 month',
),
);
@@ -473,14 +429,14 @@ export class PeoplePage {
location.href = personUrl(p.id);
},
},
p.link
portal
? {
label: 'Invite card',
icon: icon('qr'),
run: () => inviteCard(p, this.st.servers.find((s) => s.id === p.server)?.name ?? 'Home'),
}
: null,
free > 0 ? { label: 'Add device', icon: icon('plus'), run: () => addDevice(p, () => this.refresh()) } : null,
free > 0 ? { label: 'Add device', icon: icon('plus'), run: () => addDevice(p, this.deviceOpts(p)) } : null,
null,
{
label: p.paused ? 'Resume' : 'Pause',
@@ -495,7 +451,7 @@ export class PeoplePage {
'dl-icon-only',
);
const actions = E('div', { class: 'dl-pcard-actions' }, [
p.link ? iconButton('link', 'Copy link', () => copyText(p.link!, 'Personal link copied'), 'neutral', 'dl-icon-only') : '',
portal ? iconButton('link', 'Copy link', () => copyPersonLink(p.id), 'neutral', 'dl-icon-only') : '',
more,
]);
@@ -642,12 +598,7 @@ export class PeoplePage {
type: 'button',
class: 'cbi-button cbi-button-neutral',
click: () => {
if (!months) expires.value = '';
else {
const d = new Date();
d.setMonth(d.getMonth() + months);
expires.value = isoDate(d);
}
expires.value = months ? addMonthsClamped(todayOf(st.series), months) : '';
},
},
label,
@@ -686,7 +637,7 @@ export class PeoplePage {
row('Monthly data (GB)', quota, 'Optional. They are paused when it runs out and resumed next month.'),
],
[
E('button', { class: 'cbi-button cbi-button-neutral', click: closeModal }, 'Cancel'),
cancelButton(),
' ',
button(
'Create and copy link',
@@ -697,9 +648,9 @@ export class PeoplePage {
'',
server?.value ?? srv.id,
access.get(),
Number(limit.value) || st.settings.default_device_limit,
String(Number(limit.value) || st.settings.default_device_limit),
expires.value,
Number(quota.value) || 0,
quota.value.trim(),
'month',
),
);