Build packages / CI (push) Blocked by required conditions
Build packages / Version (push) Waiting to run
CI / Web (format, types, tests, bundles) (push) Blocked by required conditions
CI / ShellCheck (push) Blocked by required conditions
CI / ucode static checks (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 24.10) (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 25.12) (push) Blocked by required conditions
- Portal: Reconnect replaces New keys and the connection sheet (QR, Key,
File, and the menu's QR, key and .conf items). It gives the device new
keys, shows it as "Not set up yet" until it connects with them (in the
admin too) and opens the set-up sheet on the new configuration; "Update
the connection" goes the same way. Reconnect is orange in the menu
- iPhone: "Open in AmneziaVPN" is "Send to AmneziaVPN": the key goes in as
a .vpn file from the share sheet. AmneziaVPN takes vpn:// links only on
Android; on iOS Safari said the address was invalid, or another app that
claims vpn:// got the key. The desktop "Open in AmneziaVPN" link is gone
- A computer set up from a phone: get the app, add the connection, then
"Or open your link on the computer"; "Another app" offers AmneziaWG and
WireGuard there too and step 2 follows the pick. "Other" devices pick any
system (iPhone/iPad, Android, Windows, Mac, Linux); the page counts as the
device in hand only when the pick is its own system
- Import steps in each app's own words (iOS "+ → Create from file or
archive", Android "+ → Import from file or archive", Mac, Windows "Add
Tunnel → Import tunnel(s) from file"); Linux gets the awg-quick command
- Files are shared only on iOS (on Android the apps take no shared files:
a download there), and alone: with a title, "Save to Files" also wrote
the title as a .txt
- Files and tunnels are named after the server ("Outline Home" →
Outline-Home.conf and .vpn) in the form every client accepts: letters,
digits and "-", 15 characters, no Windows device names. The admin's
downloads keep the device in the name. The AmneziaVPN key's description
is the server's name alone
- The AmneziaVPN QR code holds the key without "vpn://": AmneziaVPN's
scanner decodes the text as it is and failed on the prefix
- "This device" also when the page is opened beside the tunnel: the apps
route the VPN's own address, which the portal shares, around their
tunnel, so the one online device whose tunnel comes from the page's
address is the one
- Fixed: "Already has AmneziaVPN?Copy the key" lost its space
135 lines
4.8 KiB
Ucode
135 lines
4.8 KiB
Ucode
// Dawnline — adding, changing, rotating and removing a person's devices: one
|
|
// code path for the admin UI (rpcd) and the portal, with the config lock,
|
|
// the runtime sync, the activity log and the "configuration issued" mark.
|
|
//
|
|
// opts = { by: 'admin' | 'portal', person?: the only person whose devices may
|
|
// be touched (the portal), defer?: load new keys a moment later (the portal
|
|
// page came through the device being rotated) }. The portal is held to the
|
|
// device limit (dawnline.core) and cannot touch a device the admin turned off.
|
|
|
|
import { sh_bg } from 'dawnline.util';
|
|
import * as core from 'dawnline.core';
|
|
import * as awg from 'dawnline.awg';
|
|
import * as apply from 'dawnline.apply';
|
|
import * as live from 'dawnline.live';
|
|
import * as store from 'dawnline.store';
|
|
|
|
/** AmneziaWG is on the router, so device keys can be made and loaded. */
|
|
export function ready() {
|
|
return awg.installed();
|
|
};
|
|
|
|
/** Dies with the admin's wording when AmneziaWG is missing. */
|
|
export function need_awg() {
|
|
if (!awg.installed()) {
|
|
let miss = awg.state().missing ?? [];
|
|
die(`AmneziaWG is not installed${length(miss) ? ` (${join(', ', miss)})` : ''}: install it in Dawnline → Components.`);
|
|
}
|
|
};
|
|
|
|
/** The device `id` as `opts` may touch it (inside a transaction's model). */
|
|
function own(m, id, opts) {
|
|
let d = m.devices[id];
|
|
if (!d || (opts.person != null && d.person != opts.person))
|
|
die(opts.person != null ? 'Device not found.' : 'Unknown device.');
|
|
if (opts.by == 'portal' && d.disabled)
|
|
die('The admin has turned this device off.');
|
|
return d;
|
|
}
|
|
|
|
/** New device with fresh keys (or the browser's public key): { id, config }. */
|
|
export function add(person, name, kind, opts) {
|
|
opts ??= {};
|
|
let by = opts.by ?? 'admin';
|
|
let id = store.transact((c, m) => core.create_device(c, m, person, name, kind, { by, keys: awg.new_keys(opts.public_key || null) }));
|
|
let s = apply.sync();
|
|
let m = core.load();
|
|
live.add_event({ type: 'device_added', person, device: id, detail: m.devices[id].name, by });
|
|
awg.mark_issued(m, id);
|
|
return { id, config: awg.client_config(m, m.devices[id]), warning: s.warning };
|
|
};
|
|
|
|
/**
|
|
* Rename and/or turn a device off or on (`ch` = { name?, disabled? }); only
|
|
* the admin turns devices off. Returns the runtime sync.
|
|
*/
|
|
export function update(id, ch, opts) {
|
|
opts ??= {};
|
|
let by = opts.by ?? 'admin';
|
|
if (ch.disabled != null && by != 'admin')
|
|
die('Only the admin can turn devices off.');
|
|
let d0 = store.transact((c, m) => {
|
|
let d = own(m, id, opts);
|
|
let was = { ...d };
|
|
if (ch.name != null && ch.name != d.name)
|
|
core.rename_device(c, m, id, ch.name);
|
|
if (ch.disabled != null) {
|
|
if (ch.disabled)
|
|
c.set(core.CONFIG, id, 'disabled', '1');
|
|
else
|
|
c.delete(core.CONFIG, id, 'disabled');
|
|
}
|
|
return was;
|
|
});
|
|
let r = apply.sync();
|
|
if (ch.disabled != null && !!ch.disabled != !!d0.disabled)
|
|
live.add_event({ type: 'device_changed', person: d0.person, device: id, detail: ch.disabled ? 'turned off' : 'turned on', by });
|
|
else if (ch.name != null && ch.name != d0.name)
|
|
live.add_event({ type: 'device_changed', person: d0.person, device: id, detail: `renamed from ${d0.name}`, by });
|
|
return r;
|
|
};
|
|
|
|
/** New keys for a device: returns its new configuration. */
|
|
export function rotate(id, opts) {
|
|
opts ??= {};
|
|
let by = opts.by ?? 'admin';
|
|
store.transact((c, m) => {
|
|
own(m, id, opts);
|
|
core.rotate_device(c, m, id, awg.new_keys());
|
|
});
|
|
// The device a portal page came through would lose its tunnel before the
|
|
// answer gets out: load the new key a moment after answering.
|
|
let s = null;
|
|
if (opts.defer)
|
|
sh_bg('sleep 3; /usr/bin/dawnline sync');
|
|
else
|
|
s = apply.sync();
|
|
let m = core.load();
|
|
let d = m.devices[id];
|
|
live.add_event({ type: 'device_keys', person: d.person, device: id, detail: d.name, by });
|
|
awg.mark_issued(m, id);
|
|
let cfg = awg.client_config(m, d);
|
|
if (s?.warning)
|
|
cfg.warning = s.warning;
|
|
return cfg;
|
|
};
|
|
|
|
/**
|
|
* Set a device up from scratch (a new phone, the app reinstalled, settings
|
|
* the admin changed): new keys, so the configuration it holds stops working
|
|
* with the sync, and it counts as not set up until it connects with the new
|
|
* one. The usage keeps the old keys' last handshake: awg.handshake_since hides
|
|
* it. Returns the new configuration, as rotate.
|
|
*/
|
|
export function reconnect(id, opts) {
|
|
opts ??= {};
|
|
let cfg = rotate(id, opts);
|
|
// A deferred sync (the page came through this device) lets the old keys live a few seconds more.
|
|
awg.mark_reconnect(core.load(), id, time() + (opts.defer ? 5 : 0));
|
|
return cfg;
|
|
};
|
|
|
|
/** Remove a device. Returns the runtime sync. */
|
|
export function remove(id, opts) {
|
|
opts ??= {};
|
|
let by = opts.by ?? 'admin';
|
|
let d = store.transact((c, m) => {
|
|
let d = own(m, id, opts);
|
|
core.delete_device(c, m, id);
|
|
return d;
|
|
});
|
|
let r = apply.sync();
|
|
live.add_event({ type: 'device_removed', person: d.person, device: id, detail: d.name, dname: d.name, dkind: d.kind, by });
|
|
return r;
|
|
};
|