Dawnline 0.1.0: AmneziaWG access server for OpenWrt
Build packages / Version (push) Waiting to run

LuCI admin (people, devices, limits, disguise, health, updates, backups)
and a personal self-service portal, built as ipk (OpenWrt 24.10) and apk
(OpenWrt 25.12) with the OpenWrt SDK. Successor of openwrt-liminal.

- install.sh: checks the router, installs AmneziaWG for its firmware,
  then the release package verified against sha256sums.txt
- CI: Prettier, types, tests, committed bundles, ShellCheck, ucode checks;
  tagged releases build both packages and publish them
- Web bundles minified with esbuild (JS and CSS)
- README with framed screenshots
This commit is contained in:
Aemeath committed 2026-10-15 03:29:30 +03:00
commit a3910f8b97
105 files changed
+22278

No files matched your search

+834
View File
@@ -0,0 +1,834 @@
// Servers: a setup wizard when nothing is configured; otherwise one tab per
// server. Each opens on its Overview (who is online, traffic, map, activity)
// followed by its settings (General, Interfaces, Network, Disguise,
// Advanced); every settings section saves on its own and applies at once.
import type { Server, Status } from '../../shared/types';
import { E } from '../e';
import { api, type SetupDefaults } from '../api';
import { attempt, button, callout, closeModal, confirmDialog, copyText, modal, notify } from '../ui';
import { icon } from '../../shared/icons';
import { duration } from '../../shared/format';
import { interfacesCard } from '../interfaces';
import { card, group, input, row } 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][] = [
['overview', 'Overview'],
['people', 'People'],
['connection', 'Connection'],
['access', 'Access'],
['disguise', 'Disguise'],
['tunnel', 'Tunnel'],
];
/** Section names from before the regrouping, for old links. */
const OLD_SECTIONS: Record<string, Section> = { general: 'connection', network: 'connection', interfaces: 'access', advanced: 'tunnel' };
function choices<T extends string>(items: { v: T; title: string; text: string; ic?: string }[], initial: T, onChange: (v: T) => void) {
const el = E(
'div',
{ class: 'dl-choices' },
items.map((o) =>
E(
'button',
{
type: 'button',
class: `dl-choice${o.v === initial ? ' selected' : ''}`,
'data-v': o.v,
click: () => {
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' }, [o.ic ? icon(o.ic) : '', o.title]), E('span', { class: 'dl-choice-text' }, o.text)],
),
),
);
return el;
}
/** `.conf` names of the disguise parameters, in file order. */
const CONF: [string, string][] = [
['jc', 'Jc'],
['jmin', 'Jmin'],
['jmax', 'Jmax'],
['s1', 'S1'],
['s2', 'S2'],
['s3', 'S3'],
['s4', 'S4'],
['h1', 'H1'],
['h2', 'H2'],
['h3', 'H3'],
['h4', 'H4'],
['i1', 'I1'],
['i2', 'I2'],
['i3', 'I3'],
['i4', 'I4'],
['i5', 'I5'],
['header_protection_key', 'HeaderProtectionKey'],
['content_padding_addition', 'ContentPaddingAddition'],
['rekey_after_time', 'RekeyAfterTime'],
['rekey_timeout', 'RekeyTimeout'],
['reject_after_time', 'RejectAfterTime'],
['keepalive_timeout', 'KeepaliveTimeout'],
['max_handshake_attempts', 'MaxHandshakeAttempts'],
['random_trailers', 'RandomTrailers'],
['disable_cookies', 'DisableCookies'],
];
/**
* The applied parameters, grouped by what they do, with a plain-language
* line per group. Collapsed by default; copyable as config lines.
*/
function paramsView(o: Record<string, string>): HTMLElement | null {
const has = (k: string) => o[k] != null && o[k] !== '';
const keys = CONF.filter(([k]) => has(k));
if (!keys.length) return null;
const val = (k: string, name: string) =>
E('span', { class: 'dl-pv' }, [E('i', {}, name), E('b', {}, k === 'header_protection_key' ? `${o[k].slice(0, 6)}••••` : o[k])]);
const group = (title: string, ic: string, text: string, ks: string[]) => {
const present = CONF.filter(([k]) => ks.includes(k) && has(k));
return present.length
? E('div', { class: 'dl-pgroup' }, [
E('div', { class: 'dl-pgroup-head' }, [icon(ic), E('b', {}, title)]),
E('p', {}, text),
E(
'div',
{ class: 'dl-pvals' },
present.map(([k, n]) => val(k, n)),
),
])
: '';
};
const jc = Number(o.jc || 0);
const signature = (o.i1 ?? '').includes('0x8580')
? 'A first packet shaped like a DNS answer.'
: 'Extra packets sent before the handshake.';
const conf = keys.map(([k, n]) => `${n} = ${o[k]}`).join('\n');
const body = E('div', { class: 'dl-pgrid' }, [
group(
'Junk packets',
'zap',
jc ? `${jc} random packet${jc === 1 ? '' : 's'} of ${o.jmin}–${o.jmax} bytes before each handshake.` : 'No junk packets.',
['jc', 'jmin', 'jmax'],
),
group('Padding', 'archive', 'Random bytes in front of handshake, cookie and data packets, so their sizes do not match WireGuard.', [
's1',
's2',
's3',
's4',
]),
group('Packet types', 'key', 'The values that replace WireGuard’s recognisable message types.', ['h1', 'h2', 'h3', 'h4']),
group('Signatures', 'globe', signature, ['i1', 'i2', 'i3', 'i4', 'i5']),
group('Protection', 'lock', 'AmneziaWG 3.1: encrypted headers, random tails and extra padding on data packets.', [
'header_protection_key',
'content_padding_addition',
'random_trailers',
'disable_cookies',
]),
group('Timing', 'clock', 'Handshake and key timers vary within these ranges instead of WireGuard’s fixed values.', [
'rekey_after_time',
'rekey_timeout',
'reject_after_time',
'keepalive_timeout',
'max_handshake_attempts',
]),
]);
return E('details', { class: 'dl-params' }, [
E('summary', {}, [
icon('chevron'),
E('span', {}, 'Current parameters'),
E('span', { class: 'dl-pcount' }, String(keys.length)),
E('span', { class: 'dl-spacer' }),
E(
'button',
{
type: 'button',
class: 'dl-linkbtn',
click: (ev: Event) => {
ev.preventDefault();
copyText(conf, 'Parameters copied');
},
},
'Copy as config',
),
]),
body,
]);
}
const url = (server?: string, section?: string) => {
const q = new URLSearchParams();
if (server) q.set('server', server);
if (section && section !== 'overview') q.set('section', section);
const s = q.toString();
return `${L.url('admin/network/dawnline/server')}${s ? `?${s}` : ''}`;
};
export class ServerPage {
st!: Status;
noFooter = true;
root = E('div', { class: 'dl-root' });
section: Section = 'overview';
srvId = '';
/** Per-server sections kept between switches (the map stays mounted). */
ov: Record<string, ServerOverview> = {};
pp: Record<string, PeoplePage> = {};
tabsEl = E('div', {});
headEl = E('div', {});
secEl = E('div', {});
bodyEl = E('div', { class: 'dl-srvbody' });
async load(): Promise<[Status, SetupDefaults | null]> {
const st = await api.status(31);
const d = st.servers.length ? null : await api.setupDefaults();
return [st, d];
}
render([st, d]: [Status, SetupDefaults | null]): Node {
this.st = st;
if (!st.servers.length && d) return this.wizard(d);
// Deep links (?server=…&section=…) pick the starting tab; switching later
// happens in place, without touching the URL (the theme's router would
// treat that as a navigation and redraw the page).
const q = new URLSearchParams(location.search);
const raw = q.get('section') ?? '';
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.
poll.add(async () => {
if (this.section !== 'overview') return;
const n = await api.status(31).catch(() => null);
if (!n || !n.servers.length) return;
this.st = n;
const srv = this.current();
dom.content(this.headEl, this.head(srv));
this.paintTabs();
this.ov[srv.id]?.update(n);
}, 10);
return this.root;
}
current(): Server {
return this.st.servers.find((x) => x.id === this.srvId) ?? this.st.servers[0];
}
async refresh() {
const st = await api.status(31).catch(() => null);
if (!st) return;
this.st = st;
if (!st.servers.length) location.href = url();
else this.paint();
}
/* ---------------- page ---------------- */
/** Everything: server tabs, head, section tabs and the current section. */
paint() {
this.paintTabs();
dom.content(this.headEl, this.head(this.current()));
this.paintSections();
this.showSection(this.section);
}
paintTabs() {
const srv = this.current();
dom.content(
this.tabsEl,
E('div', { class: 'dl-srvtabs', role: 'tablist', 'aria-label': 'Servers' }, [
...this.st.servers.map((x) =>
E(
'button',
{
type: 'button',
role: 'tab',
class: `dl-srvtab${x.id === srv.id ? ' on' : ''}`,
'aria-selected': x.id === srv.id ? 'true' : 'false',
click: () => {
if (x.id === this.srvId) return;
this.srvId = x.id;
this.paint();
},
},
[E('i', { class: `dot ${x.up ? 'ok' : 'bad'}` }), E('b', {}, x.name), E('span', { class: 'dl-mono dl-faint' }, `:${x.port}`)],
),
),
E('button', { type: 'button', class: 'dl-srvtab add', click: () => this.addServer() }, [icon('plus'), 'Add server']),
]),
);
}
paintSections() {
dom.content(
this.secEl,
E(
'div',
{ class: 'dl-seg dl-srvsections', role: 'tablist', 'aria-label': 'Server' },
SECTIONS.map(([k, t]) =>
E(
'button',
{
type: 'button',
role: 'tab',
'data-section': k,
class: k === this.section ? 'on' : '',
'aria-selected': k === this.section ? 'true' : 'false',
click: () => this.showSection(k),
},
t,
),
),
),
);
}
/** Jump to a section, optionally with a People filter (from the Overview). */
go(k: Section, filter?: string) {
const pp = this.pp[this.current().id];
if (filter && pp) {
pp.filter = filter as PeoplePage['filter'];
if (pp.el) pp.decorate();
} else if (filter) {
const page = (this.pp[this.current().id] = new PeoplePage());
page.filter = filter as PeoplePage['filter'];
}
this.showSection(k);
window.scrollTo({ top: 0, behavior: 'smooth' });
}
/** Swap only the section body; the rest of the page stays as it is. */
showSection(k: Section) {
this.section = k;
this.secEl.querySelectorAll<HTMLElement>('[data-section]').forEach((b) => {
const on = b.dataset.section === k;
b.classList.toggle('on', on);
b.setAttribute('aria-selected', on ? 'true' : 'false');
});
const st = this.st;
const srv = this.current();
const body: Record<Section, () => Node> = {
overview: () => {
const ov = this.ov[srv.id];
if (!ov) return (this.ov[srv.id] = new ServerOverview(srv.id, (k, f) => this.go(k as Section, f))).mount(st);
ov.update(st);
return ov.el;
},
people: () => {
const pp = this.pp[srv.id];
if (pp?.el) {
void pp.poll();
return pp.el;
}
const holder = E('div', {}, E('p', { class: 'dl-muted' }, 'Loading people…'));
const page = (this.pp[srv.id] ??= new PeoplePage());
page.embed(st, srv.id).then((node) => {
if (holder.isConnected) dom.content(holder, node);
else holder.replaceChildren(node);
});
return holder;
},
connection: () => this.connection(srv),
access: () => this.access(srv),
disguise: () => this.disguise(srv),
tunnel: () => this.tunnel(srv),
};
dom.content(this.bodyEl, body[k]());
}
/** Name and state, the address bar, and the page actions. */
head(srv: Server): HTMLElement {
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).
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'],
async () => {
if (st.settings.paused_all && !(await attempt(() => api.pauseAll(false)))) return;
if (!srv.enabled) await this.save(srv, { enabled: '1' }, 'Server turned on');
else await this.refresh();
},
'positive',
)
: '',
]);
// Actions sit on the name's line; the address bar gets the whole next line.
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',
]),
st.settings.paused_all && srv.enabled ? E('span', { class: 'dl-pill warn' }, 'Off') : '',
E('span', { class: 'dl-spacer' }),
actions,
]),
E('div', { class: 'dl-addrbar' }, [
E(
'button',
{ type: 'button', class: 'dl-addrbar-seg main', title: 'Copy address and port', click: () => copyText(addr, 'Address copied') },
[icon('globe'), E('span', { class: 'dl-mono' }, addr), icon('copy')],
),
seg('tunnel', [E('span', { class: 'dl-mono' }, srv.ifname)]),
seg('network', [E('span', { class: 'dl-mono' }, srv.subnet)]),
srv.up ? seg('clock', [`up ${duration(srv.uptime)}`]) : '',
]),
]);
}
async save(srv: Server, values: Record<string, unknown>, ok = 'Saved') {
if (await attempt(() => api.serverUpdate(srv.id, values), ok)) await this.refresh();
}
/** How devices find the server and what goes into their configuration. */
connection(srv: Server): HTMLElement {
const name = input(srv.name, { placeholder: 'Home' });
const endpoint = input(srv.endpoint, { placeholder: 'vpn.example.com', class: 'cbi-input-text dl-mono' });
const port = input(String(srv.port), { inputmode: 'numeric', class: 'cbi-input-text dl-w-port dl-mono' });
const dns = input(srv.dns.join(', '), { placeholder: 'This router (recommended)', class: 'cbi-input-text dl-mono' });
const mtu = input(String(srv.mtu ?? ''), { placeholder: '1380', inputmode: 'numeric', class: 'cbi-input-text dl-w-port dl-mono' });
const ka = input(String(srv.keepalive ?? ''), { placeholder: '25', inputmode: 'numeric', class: 'cbi-input-text dl-w-port dl-mono' });
return card(
'Connection',
[
E('p', { class: 'dl-muted' }, 'How devices find this server, and what goes into their configuration.'),
group('router', 'Server', 'What people see', [row('Name', name, 'Shown to people in their portal.')]),
group('globe', 'Devices connect to', 'Where the tunnel answers from the internet', [
row(
'Public address',
endpoint,
'Hostname or IP of the router on the internet. A DDNS name keeps links working when your IP changes.',
),
row('UDP port', port, 'Opened on the WAN firewall automatically.'),
]),
group('file', 'In every device configuration', 'Changing these marks devices “Update config” until they import again', [
row('DNS for devices', dns, 'Empty = this router, which sends each query where your home network would.'),
row('MTU', mtu, 'Lower it if some sites hang on mobile networks.'),
row('Keep-alive', ka, 'Seconds between packets devices send to keep NAT open. 0 = off.'),
]),
],
[
E('span'),
button(
'Save',
() =>
this.save(srv, {
name: name.value,
endpoint: endpoint.value,
port: port.value,
dns: dns.value,
mtu: mtu.value,
keepalive: ka.value,
}),
'positive',
),
],
);
}
/** Where devices may go and how their traffic leaves: internet path, WAN, home network, services. */
access(srv: Server): HTMLElement {
const svcs = this.st.services;
return E('div', { class: 'dl-stack gap16' }, [
interfacesCard(srv.id, 'Access'),
card(
'Home services',
[
E(
'p',
{ class: 'dl-muted' },
'People with Home-only access can be limited to these services instead of the whole home network (chosen per person). The list is shared by all servers.',
),
E(
'div',
{ class: 'dl-list' },
svcs.length
? svcs.map((sv) =>
E('div', { class: 'dl-row' }, [
icon('home'),
E('span', { class: 'dl-row-main dl-stack' }, [
E('b', {}, sv.name),
E(
'span',
{ class: 'dl-mono dl-faint' },
`${sv.address}${sv.ports.length ? ` · ports ${sv.ports.join(', ')}` : ' · all ports'}`,
),
]),
]),
)
: [E('div', { class: 'dl-row dl-muted' }, 'No services yet.')],
),
],
[
E('span'),
E(
'a',
{ class: 'cbi-button cbi-button-neutral', href: `${L.url('admin/network/dawnline/settings')}#dl-set-services` },
'Edit in Settings',
),
],
),
]);
}
disguise(srv: Server): HTMLElement {
const current = methodInfo(srv.preset) ? (srv.preset as Method) : undefined;
let selected: Method = current ?? 'standard';
const action = button('', () => this.applyDisguise(srv, selected, selected === current), 'positive');
const label = () => {
dom.content(action, selected === current ? [icon('reset'), ' Generate new values'] : `Switch to ${methodInfo(selected)!.title}`);
};
label();
const params = paramsView(srv.obf ?? {});
return card(
'Disguise',
[
E(
'p',
{ class: 'dl-muted' },
'AmneziaWG reshapes the tunnel so networks that block VPNs do not recognise it. Every device gets these settings in its configuration.',
),
methodPicker(
this.st.awg,
selected,
(m) => {
selected = m;
label();
},
current,
),
!this.st.awg.v3
? callout('info', [
'This router runs an older AmneziaWG. ',
E('b', {}, 'Maximum'),
' becomes available with kmod-amneziawg and amneziawg-tools 3.1.',
])
: '',
params ?? '',
],
[E('span', { class: 'dl-sub' }, 'Applies at once. Every device on this server must import its configuration again.'), action],
);
}
async applyDisguise(srv: Server, m: Method, same: boolean) {
const info = methodInfo(m)!;
const people = this.st.people.filter((p) => p.server === srv.id);
const devices = people.reduce((n, p) => n + p.devices.length, 0);
const ok = await confirmDialog(
same ? 'Generate new disguise values?' : `Switch to ${info.title}?`,
`${devices} device${devices === 1 ? '' : 's'} stop connecting until they import their configuration again (from their personal link or from you).${m === 'max' ? ' They need an app with AmneziaWG 3.1.' : ''}`,
same ? 'Generate and apply' : 'Switch and apply',
true,
);
if (!ok) return;
if (await attempt(() => api.serverObfuscation(srv.id, m), same ? 'New values applied' : `${info.title} applied`)) {
notify('Devices are marked “Update config” until they import again.', 'info', 6000);
await this.refresh();
}
}
/** Technical details that rarely change, then the danger zone. */
tunnel(srv: Server): HTMLElement {
const people = this.st.people.filter((p) => p.server === srv.id).length;
const toggle = button(
srv.enabled ? 'Turn off' : 'Turn on',
async () => {
if (
srv.enabled &&
!(await confirmDialog(
`Turn off ${srv.name}?`,
`The tunnel stops and ${people} ${people === 1 ? 'person is' : 'people are'} disconnected until you turn it back on. Nothing is deleted.`,
'Turn off',
true,
))
)
return;
await this.save(srv, { enabled: srv.enabled ? '0' : '1' }, srv.enabled ? 'Server turned off' : 'Server turned on');
},
srv.enabled ? 'negative' : 'positive',
);
return E('div', { class: 'dl-stack gap16' }, [
card(
'Tunnel',
[
E('p', { class: 'dl-muted' }, 'Technical details. They are set when the server is created and rarely change.'),
row('Interface', E('span', { class: 'dl-mono' }, `${srv.ifname} · router ${srv.address}`)),
row('Tunnel subnet', E('span', { class: 'dl-mono' }, srv.subnet), 'Device addresses come from it.'),
row(
'Server public key',
E('span', { class: 'dl-keyrow' }, [
E('code', { class: 'dl-mono' }, srv.public_key),
button([icon('copy')], () => copyText(srv.public_key, 'Public key copied'), 'neutral', {
title: 'Copy',
class: 'cbi-button cbi-button-neutral dl-icon-only sm',
}),
]),
),
row('Link path', E('span', { class: 'dl-mono' }, `/${srv.id}/`), 'Changing it would break every personal link already sent.'),
],
[],
),
card(
'Danger zone',
[
E('div', { class: 'dl-setrow' }, [
E('div', { class: 'dl-stack' }, [
E('span', { class: 'dl-setrow-label' }, srv.enabled ? 'Turn off this server' : 'This server is off'),
E(
'span',
{ class: 'dl-sub' },
srv.enabled
? 'Stops the tunnel and disconnects everyone on it. Settings and people are kept.'
: 'Nobody can connect. Turn it on to bring the tunnel back.',
),
]),
E('div', { class: 'dl-setrow-ctl' }, toggle),
]),
E('div', { class: 'dl-setrow' }, [
E('div', { class: 'dl-stack' }, [
E('span', { class: 'dl-setrow-label' }, 'Remove server'),
E(
'span',
{ class: 'dl-sub' },
`Removes the tunnel, its firewall rules and ${people} ${people === 1 ? 'person' : 'people'} with all their devices. A backup is made first.`,
),
]),
E(
'div',
{ class: 'dl-setrow-ctl' },
button([icon('trash'), ' Remove'], () => this.remove(srv), 'negative'),
),
]),
],
[],
'danger',
),
]);
}
/* ---------------- add / remove ---------------- */
async addServer() {
const d = await attempt(() => api.setupDefaults());
if (!d) return;
dom.content(
this.root,
this.wizard(d, true, () => {
dom.content(this.root, [this.tabsEl, this.headEl, this.secEl, this.bodyEl]);
this.paint();
}),
);
}
async remove(srv: Server) {
const people = this.st.people.filter((p) => p.server === srv.id);
modal(
`Remove ${srv.name}?`,
[
E(
'p',
{},
`This removes the tunnel, its firewall rules and ${people.length} ${people.length === 1 ? 'person' : 'people'} with all their devices. A backup is made first.`,
),
],
[
E('button', { class: 'cbi-button cbi-button-neutral', click: closeModal }, 'Cancel'),
' ',
button(
'Remove',
async () => {
closeModal();
if (await attempt(() => api.serverDelete(srv.id), 'Server removed'))
setTimeout(() => {
location.href = url();
}, 800);
},
'negative',
),
],
);
}
/* ---------------- wizard ---------------- */
/**
* Setup wizard. `extra` adds one more server next to existing ones: the
* portal is already set up then, so that step is left out.
*/
wizard(d: SetupDefaults, extra = false, onCancel?: () => void): HTMLElement {
const state = {
id: d.id,
name: d.name,
endpoint: d.endpoint,
port: d.port,
subnet: d.subnet,
preset: 'standard' as Method,
portal: true,
portal_port: d.portal_port || 8443,
lan_zone: d.lan_zone,
wan_zone: d.wan_zone,
};
let step = 0;
const root = E('div', { class: 'dl-wizard' });
const field = (key: 'id' | 'name' | 'endpoint' | 'port' | 'subnet' | 'portal_port', attrs: Record<string, unknown> = {}) => {
const el = input(String(state[key]), attrs);
el.addEventListener('input', () => {
(state as any)[key] = key === 'port' || key === 'portal_port' ? Number(el.value) : el.value.trim();
});
return el;
};
const steps = extra ? ['Connection', 'Disguise'] : ['Connection', 'Disguise', 'Portal'];
const pages: (() => Node)[] = [
() =>
E('div', {}, [
E(
'p',
{},
'Where devices connect to. Use a hostname that always points at your router (DDNS), so links keep working when your IP changes.',
),
row('Name', field('name'), 'Shown to people in their portal.'),
row(
'Link path',
field('id', { maxlength: 24, class: 'cbi-input-text dl-mono' }),
'First part of personal links: https://address:port/<path>/<person>.',
),
row(
'Public address',
field('endpoint', { placeholder: 'vpn.example.com', class: 'cbi-input-text dl-mono' }),
'Hostname or IP address of your router on the internet.',
),
row(
'UDP port',
field('port', { inputmode: 'numeric', class: 'cbi-input-text dl-w-port dl-mono' }),
'Opened on the WAN firewall automatically. A random high port is fine.',
),
row(
'Tunnel subnet',
field('subnet', { class: 'cbi-input-text dl-mono' }),
`Addresses for devices. Must not overlap your networks (${d.taken.join(', ') || 'none found'}).`,
),
]),
() =>
E('div', {}, [
E(
'p',
{},
'AmneziaWG reshapes the tunnel so networks that block VPNs do not recognise it. Every device gets these settings automatically; you can change the method later.',
),
methodPicker(d.awg, state.preset, (m) => (state.preset = m)),
]),
() => {
const portalPort = field('portal_port', { inputmode: 'numeric', class: 'cbi-input-text dl-w-port dl-mono' });
return E('div', {}, [
callout(
'info',
'Devices reach the internet the way devices on your home network do: whatever handles home traffic on this router handles theirs too. You can change this later under Servers → Access.',
),
E('h4', {}, 'Personal portal'),
E('p', {}, 'A small page where each person adds their own devices, with their personal link. It gets its own HTTPS port on WAN.'),
choices(
[
{ v: 'on', title: 'On', ic: 'link', text: 'People manage their devices themselves within the limits you set.' },
{ v: 'off', title: 'Off', ic: 'x', text: 'Only you add devices, from LuCI.' },
],
'on',
(v) => {
state.portal = v === 'on';
portalPort.disabled = !state.portal;
},
),
row('Portal port', portalPort, 'TCP port on WAN. The whole port belongs to the portal.'),
]);
},
];
const paint = () => {
dom.content(root, [
E('h2', {}, extra ? 'Add a server' : 'Set up Dawnline'),
E(
'div',
{ class: 'dl-steps' },
steps.map((s, i) =>
E('span', { class: `dl-step${i === step ? ' current' : i < step ? ' done' : ''}` }, [
E('b', {}, i < step ? '✓' : String(i + 1)),
s,
]),
),
),
E('div', { class: 'dl-panel' }, pages[step]()),
E('div', { class: 'dl-actions' }, [
step > 0
? button('Back', () => {
step--;
paint();
})
: onCancel
? button('Cancel', onCancel)
: '',
E('span', { class: 'dl-spacer' }),
step < steps.length - 1
? button(
'Next',
() => {
if (step === 0 && (!state.endpoint || !state.port || !state.subnet)) {
notify('Fill in the public address, port and subnet.', 'warning');
return;
}
step++;
paint();
},
'positive',
)
: button(
'Create server',
async () => {
// An extra server leaves the portal settings alone (undefined is not sent).
const r = await attempt(
() =>
api.serverCreate(
state.id,
state.name,
d.ifname,
state.port,
state.subnet,
state.endpoint,
d.mtu,
state.preset,
state.lan_zone,
state.wan_zone,
true,
extra ? undefined : state.portal,
extra ? undefined : state.portal_port,
),
'Server created',
);
if (r)
setTimeout(() => {
location.href = url(r.id);
}, 1500);
},
'positive',
),
]),
]);
};
paint();
return root;
}
}