Files
dawnline/web/src/admin/pages/components/awg.ts
T
Aemeath 34293fb8e5
Build packages / Version (push) Waiting to run
Dawnline 0.4.0
- 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
2026-10-16 02:14:15 +03:00

173 lines
7.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Components → AmneziaWG: the installed build, its update, and the builds for
// this firmware with the Russian translation (Build and translation).
import type { AwgSource, UpdateComponent } from '../../api';
import { E } from '../../e';
import { button } from '../../ui/button';
import { confirmDialog } from '../../ui/modal';
import { sw } from '../../ui/controls';
import { pill } from '../../ui/badges';
import { icon } from '../../../shared/icons';
import { whatsNew } from '../../updater/notes';
import type { ComponentsPage, MenuEntry } from './index';
export function awgRows(page: ComponentsPage, w: UpdateComponent | undefined): Node[] {
const st = page.st;
const kept = st.kept?.amneziawg;
const srcs = w?.sources ?? {};
const ids = Object.keys(srcs) as AwgSource[];
const cur = w?.current ?? null;
const curSrc = cur ? srcs[cur] : undefined;
const ru = !!w?.ru;
// What the router says is missing right now wins over the last check (which may predate a removal).
const missing = st.needs?.awg ?? [];
const installed = missing.length ? null : (w?.installed ?? null);
const actions: MenuEntry[] = [];
if (cur && installed)
actions.push({
label: 'Reinstall this build',
warn: true,
ic: 'reset',
run: () => page.op(`amneziawg:${cur}${ru ? ':ru' : ''}`, 'Reinstalling AmneziaWG', installed),
});
if (kept)
actions.push({
label: `Roll back to ${kept.version}`,
ic: 'archive',
warn: true,
run: async () => {
if (
await confirmDialog(
`Roll back AmneziaWG to ${kept.version}?`,
'The build kept on the router is installed again. Every AmneziaWG tunnel restarts for a few seconds.',
'Roll back',
)
)
void page.op('amneziawg:rollback', 'Rolling back AmneziaWG', installed ?? undefined);
},
});
const menu: (MenuEntry | null)[] = [
w?.release
? {
label: 'What’s new',
ic: 'file',
run: () => whatsNew('amneziawg', w.release!, `What’s new in the ${curSrc?.label ?? 'AmneziaWG'} build`, cur ?? 'slava'),
}
: null,
{
label: 'Open on GitHub',
ic: 'globe',
run: () => window.open(`https://github.com/${curSrc?.repo ?? 'Slava-Shchipunov/awg-openwrt'}`, '_blank', 'noopener'),
},
...(actions.length ? [null, ...actions] : []),
].filter((x, k, a) => x !== null || (k > 0 && a[k - 1] !== null));
const tun = st.tunnels ?? [];
const restarts = tun.length
? `Switching restarts ${tun.length === 1 ? 'the tunnel' : `${tun.length} tunnels`} for a few seconds: ${tun.join(', ')}. Devices keep their configurations.`
: 'Switching takes a few seconds. Devices keep their configurations.';
// The notice under the builds: "Switching restarts Home and Family for a few seconds."
const names = tun.length > 1 ? `${tun.slice(0, -1).join(', ')} and ${tun[tun.length - 1]}` : tun[0];
const notice = tun.length ? `Switching restarts ${names} for a few seconds.` : 'Switching takes a few seconds.';
const switchTo = async (id: AwgSource) => {
const x = srcs[id]!;
const ok = await confirmDialog(
installed ? `Switch to AmneziaWG ${x.gen}?` : `Install AmneziaWG ${x.gen}?`,
`The ${x.label} build, ${x.version}. ${restarts}${x.gen === '3.1' ? ' Devices need AmneziaVPN 3.1 or newer.' : ''}`,
installed ? 'Switch' : 'Install',
);
if (ok)
void page.op(
`amneziawg:${id}${ru ? ':ru' : ''}`,
installed ? `Switching to AmneziaWG ${x.gen}` : 'Installing AmneziaWG',
installed ?? undefined,
);
};
const build = (id: AwgSource) => {
const x = srcs[id]!;
const on = cur === id && !!installed;
return E('div', { class: 'dl-row' }, [
E('span', { class: 'dl-row-main dl-stack' }, [
E('b', {}, x.gen ? `AmneziaWG ${x.gen}` : 'AmneziaWG'),
E('span', { class: 'dl-sub' }, `${x.label} · ${x.gen === '3.1' ? 'AmneziaVPN 3.1+' : 'every app'}`),
]),
E('span', { class: 'dl-mono dl-faint dl-comp-bver' }, x.version ?? 'none yet'),
E(
'span',
{ class: 'dl-comp-bact' },
on
? pill('ok', 'Active')
: x.version
? button(installed ? 'Switch' : 'Install', () => switchTo(id), installed ? 'neutral' : 'positive', { disabled: page.busy })
: pill('', 'No build'),
),
]);
};
const newer = ids
.map((id) =>
srcs[id]?.newer ? `${srcs[id]!.label} moves to ${srcs[id]!.newer!.gen} with OpenWrt ${srcs[id]!.newer!.tag.replace(/^v/, '')}.` : '',
)
.filter(Boolean);
const ruSw = sw(ru, 'Russian translation', (v) => {
if (!cur) return;
void page.op(
`amneziawg:${cur}${v ? ':ru' : ''}`,
v ? 'Adding the Russian translation' : 'Removing the Russian translation',
installed ?? undefined,
);
});
ruSw.disabled = !cur || !installed || page.busy;
const open = page.awgOpen ?? !installed;
const fold = E('details', { class: 'dl-params dl-comp-fold', open: open ? 'open' : null }, [
E('summary', {}, [icon('chevron'), E('span', {}, 'Build and translation')]),
E('div', { class: 'dl-params-body' }, [
// The builds and the translation in one list.
E('div', { class: 'dl-list' }, [
...(ids.length
? ids.map(build)
: [E('div', { class: 'dl-row' }, E('span', { class: 'dl-sub' }, 'Check for updates to see the builds for this router.'))]),
E('div', { class: 'dl-row' }, [
E('span', { class: 'dl-row-main dl-stack' }, [
E('b', {}, 'Russian translation'),
E('span', { class: 'dl-sub' }, 'LuCI pages for AmneziaWG'),
]),
E('span', { class: 'dl-comp-bact' }, ruSw),
]),
]),
// One notice: what switching does, and what the builds will bring.
(installed && ids.length) || newer.length
? E('div', { class: `dl-comp-status ${installed && ids.length ? 'warn' : 'acc'}` }, [
icon(installed && ids.length ? 'alert' : 'download'),
E('span', {}, [installed && ids.length ? E('b', {}, notice) : '', ...newer.map((t) => ` ${t}`)]),
])
: '',
]),
]);
fold.addEventListener('toggle', () => (page.awgOpen = (fold as HTMLDetailsElement).open));
const right: Node[] = [];
if (w?.update && installed && cur)
right.push(
button(`Update to ${w.latest}`, () => page.op(`amneziawg:${cur}${ru ? ':ru' : ''}`, 'Updating AmneziaWG', installed), 'neutral', {
disabled: page.busy,
}),
);
else right.push((w || missing.length) && !installed ? pill('warn', 'Not installed') : page.state('amneziawg', w, w?.latest ?? ''));
right.push(page.round(() => page.op('check:amneziawg', 'Checking AmneziaWG', installed ?? undefined), menu));
return [
page.row(
'shield',
'AmneziaWG',
[
installed
? `${installed}${w?.release ? ` · ${w.release} build` : ''}`
: missing.length
? `missing ${missing.join(', ')}`
: w
? 'not installed'
: 'version not checked',
],
right,
),
E('div', { class: 'dl-comp-foldwrap' }, fold),
];
}