Dawnline 0.9.0
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
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
This commit is contained in:
1 parent
7a6370aa9e
commit
edeb1506fd
22 files changed
+401
-486
No files matched your search
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "dawnline-web",
|
||||
"version": "0.8.1",
|
||||
"version": "0.9.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "dawnline-web",
|
||||
"version": "0.8.1",
|
||||
"version": "0.9.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"qrcode-generator": "1.4.4"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dawnline-web",
|
||||
"version": "0.8.1",
|
||||
"version": "0.9.0",
|
||||
"private": true,
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
|
||||
@@ -214,7 +214,7 @@ export async function connectBlock(cfg: AwgConfig, initial: 'file' | 'key' | 'qr
|
||||
{ class: 'dl-hint' },
|
||||
'This device generated its own keys in the browser, so its full configuration only exists on that device.',
|
||||
);
|
||||
const key = await vpnKey(cfg, `${cfg.server} · ${cfg.person} · ${cfg.name}`);
|
||||
const key = await vpnKey(cfg, cfg.server);
|
||||
const panes: Record<string, () => Node> = {
|
||||
qr: () =>
|
||||
E('div', { class: 'dl-qr-pane' }, [
|
||||
@@ -437,6 +437,6 @@ export const awg: Core = {
|
||||
overviewTile,
|
||||
connectBlock,
|
||||
qrText: (cfg) => cfg.conf,
|
||||
appKey: { label: 'Copy AmneziaVPN key', make: (cfg) => vpnKey(cfg, `${cfg.server} · ${cfg.person} · ${cfg.name}`) },
|
||||
appKey: { label: 'Copy AmneziaVPN key', make: (cfg) => vpnKey(cfg, cfg.server) },
|
||||
file: { label: 'Download .conf', make: (cfg) => ({ name: cfg.filename, text: cfg.conf }) },
|
||||
};
|
||||
+121
-274
@@ -22,32 +22,18 @@ import {
|
||||
} from '../shared/format';
|
||||
import { iconSvg } from '../shared/icons';
|
||||
import { denseQr, qrSvg } from '../shared/qr';
|
||||
import { vpnKey } from '../shared/vpnkey';
|
||||
import { vpnKey, vpnQrText } from '../shared/vpnkey';
|
||||
import { h, ic, type Kid } from './dom';
|
||||
import { waitPath, type Way } from './waitpath';
|
||||
import {
|
||||
beat,
|
||||
busy,
|
||||
calm,
|
||||
copied,
|
||||
fold,
|
||||
followHeight,
|
||||
intro,
|
||||
leave,
|
||||
pullToClose,
|
||||
replay,
|
||||
restyle,
|
||||
settle,
|
||||
slider,
|
||||
snap,
|
||||
swap,
|
||||
} from './motion';
|
||||
import { beat, busy, calm, copied, fold, followHeight, intro, leave, pullToClose, replay, restyle, settle, snap, swap } from './motion';
|
||||
import {
|
||||
APP_NAME,
|
||||
appsFor,
|
||||
hereLabel,
|
||||
deviceNoun,
|
||||
importPath,
|
||||
importSteps,
|
||||
keyFileName,
|
||||
opensKeyLinks,
|
||||
setupFromHash,
|
||||
setupLink,
|
||||
inWebview,
|
||||
@@ -172,20 +158,23 @@ async function copy(text: string, what = 'Copied', from?: EventTarget | null) {
|
||||
* download would land in Files. Returns the action, or null where files
|
||||
* cannot be shared.
|
||||
*/
|
||||
function shareFile(cfg: ClientConfig): (() => Promise<void>) | null {
|
||||
function shareFile(name: string, text: string): (() => Promise<void>) | null {
|
||||
const nav = navigator as Navigator & { canShare?: (d: unknown) => boolean };
|
||||
// Desktop browsers claim they can share files and then do nothing, or open a
|
||||
// sheet with nowhere useful: there a download is the right thing anyway.
|
||||
if (!/Android|iPhone|iPad/.test(navigator.userAgent)) return null;
|
||||
// Only iOS: there AmneziaWG, WireGuard and AmneziaVPN take a file from the
|
||||
// share sheet. On Android neither app is a share target (and Chrome does not
|
||||
// share .conf files), so a download goes into the app's own file picker;
|
||||
// desktop browsers claim they can share files and then do nothing.
|
||||
if (platform() !== 'ios') return null;
|
||||
if (typeof nav.share !== 'function' || typeof File === 'undefined') return null;
|
||||
const file = new File([cfg.conf], cfg.filename, { type: 'application/octet-stream' });
|
||||
const file = new File([text], name, { type: 'application/octet-stream' });
|
||||
if (!nav.canShare?.({ files: [file] })) return null;
|
||||
return async () => {
|
||||
try {
|
||||
await nav.share({ files: [file], title: cfg.filename });
|
||||
// The file alone: with a title, "Save to Files" also writes the title as a .txt.
|
||||
await nav.share({ files: [file] });
|
||||
} catch (e) {
|
||||
// Cancelled: nothing to do. Refused by the browser: the file still has to get out.
|
||||
if ((e as Error)?.name !== 'AbortError') download(cfg.filename, cfg.conf);
|
||||
if ((e as Error)?.name !== 'AbortError') download(name, text);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -356,7 +345,7 @@ function sheet(title: string, sub: string | null, ...content: Kid[]) {
|
||||
}
|
||||
|
||||
/**
|
||||
* A question before something that cannot be undone (Remove, New keys): narrow
|
||||
* A question before something that cannot be undone (Remove, Reconnect): narrow
|
||||
* and centred, the action's icon in its colour, one line of what happens, Cancel
|
||||
* and the action (no ×: Cancel says it). `run` holds the action's button busy.
|
||||
*/
|
||||
@@ -430,7 +419,7 @@ document.addEventListener('click', (e) => {
|
||||
if (menuEl && !menuEl.contains(e.target as Node)) closeMenu();
|
||||
});
|
||||
|
||||
function menu(anchor: HTMLElement, all: ({ label: string; icon: string; danger?: boolean; run: () => unknown } | null)[]) {
|
||||
function menu(anchor: HTMLElement, all: ({ label: string; icon: string; danger?: boolean; warn?: boolean; run: () => unknown } | null)[]) {
|
||||
if (menuFor === anchor) return closeMenu();
|
||||
closeMenu();
|
||||
// Separators only between items.
|
||||
@@ -445,7 +434,7 @@ function menu(anchor: HTMLElement, all: ({ label: string; icon: string; danger?:
|
||||
{
|
||||
type: 'button',
|
||||
role: 'menuitem',
|
||||
class: `menu-item${it.danger ? ' danger' : ''}`,
|
||||
class: `menu-item${it.danger ? ' danger' : it.warn ? ' warn' : ''}`,
|
||||
onclick: () => {
|
||||
closeMenu();
|
||||
it.run();
|
||||
@@ -748,30 +737,28 @@ function deviceCard(d: Device, st: State): HTMLElement {
|
||||
{ type: 'button', class: 'icon-btn soft', 'aria-label': `${d.name} options`, 'aria-haspopup': 'menu', 'aria-expanded': 'false' },
|
||||
ic('more'),
|
||||
);
|
||||
// The connection itself comes from the set-up sheet (Reconnect), not from here.
|
||||
const items = [
|
||||
// How devices at home reach it: only where the router actually lets them through.
|
||||
...(reachableFromHome(st.person, d)
|
||||
? [
|
||||
{ label: 'Copy IP address', icon: 'copy', run: () => copy(d.address, 'IP address copied') },
|
||||
...(d.hostname ? [{ label: 'Copy local address', icon: 'home', run: () => copy(d.hostname, 'Address copied') }] : []),
|
||||
null,
|
||||
]
|
||||
: []),
|
||||
// A device the admin turned off can't be renamed, set up again or removed here (the router refuses).
|
||||
...(d.disabled
|
||||
? []
|
||||
: [
|
||||
{ label: 'Rename', icon: 'edit', run: () => rename(d) },
|
||||
{ label: 'Reconnect', icon: 'refresh', warn: true, run: () => reconnect(d, st) },
|
||||
{ label: 'Remove', icon: 'trash', danger: true, run: () => removeDevice(d) },
|
||||
]),
|
||||
];
|
||||
more.addEventListener('click', (ev) => {
|
||||
ev.stopPropagation();
|
||||
menu(more, [
|
||||
{ label: 'Show QR code', icon: 'qr', run: () => connect(d, 'qr') },
|
||||
{ label: 'Copy AmneziaVPN key', icon: 'key', run: () => copyKey(d) },
|
||||
{ label: 'Download .conf', icon: 'download', run: () => downloadConf(d) },
|
||||
null,
|
||||
// How devices at home reach it: only where the router actually lets them through.
|
||||
...(reachableFromHome(st.person, d)
|
||||
? [
|
||||
{ label: 'Copy IP address', icon: 'copy', run: () => copy(d.address, 'IP address copied') },
|
||||
...(d.hostname ? [{ label: 'Copy local address', icon: 'home', run: () => copy(d.hostname, 'Address copied') }] : []),
|
||||
null,
|
||||
]
|
||||
: []),
|
||||
// A device the admin turned off can't be renamed, rekeyed or removed here (the router refuses).
|
||||
...(d.disabled
|
||||
? []
|
||||
: [
|
||||
{ label: 'Rename', icon: 'edit', run: () => rename(d) },
|
||||
{ label: 'New keys', icon: 'reset', run: () => rotateKeys(d, st) },
|
||||
{ label: 'Remove', icon: 'trash', danger: true, run: () => removeDevice(d) },
|
||||
]),
|
||||
]);
|
||||
menu(more, items);
|
||||
});
|
||||
const week = d.spark.reduce((a, b) => a + b, 0);
|
||||
const setUp = !d.handshake && !d.disabled;
|
||||
@@ -791,7 +778,7 @@ function deviceCard(d: Device, st: State): HTMLElement {
|
||||
{ class: 'dhead' },
|
||||
h('span', { class: 'dic' }, ic(d.kind)),
|
||||
h('div', { class: 'stack grow' }, h('span', { class: 'dname', 'data-v': `name:${d.id}` }, d.name), status),
|
||||
locked ? null : more,
|
||||
locked || !items.length ? null : more,
|
||||
),
|
||||
setUp && locked
|
||||
? null
|
||||
@@ -819,7 +806,7 @@ function deviceCard(d: Device, st: State): HTMLElement {
|
||||
d.config_stale && !setUp && !locked
|
||||
? h(
|
||||
'button',
|
||||
{ type: 'button', class: 'btn block', onclick: () => connect(d) },
|
||||
{ type: 'button', class: 'btn block', onclick: () => reconnect(d, st) },
|
||||
ic('refresh'),
|
||||
h('span', {}, 'Update the connection'),
|
||||
)
|
||||
@@ -913,16 +900,6 @@ function main(st: State) {
|
||||
);
|
||||
}
|
||||
|
||||
/** Where to get the app on this platform: the store on phones, the downloads page elsewhere. */
|
||||
function appLink(): { href: string; label: string } {
|
||||
const pf = platform();
|
||||
const st = storeFor('vpn', pf);
|
||||
return {
|
||||
href: st?.href ?? 'https://github.com/amnezia-vpn/amnezia-client/releases/latest',
|
||||
label: `Get AmneziaVPN${pf === 'ios' ? ' for iPhone' : pf === 'android' ? ' for Android' : ''}`,
|
||||
};
|
||||
}
|
||||
|
||||
/** The platform this page is open on (iPad on Safari says Mac; touch points tell). */
|
||||
const platform = (): Platform => platformOf(navigator.userAgent, navigator.maxTouchPoints);
|
||||
/** The server's disguise generation, for which apps and versions connect. */
|
||||
@@ -1037,17 +1014,6 @@ async function getConfig(d: Device): Promise<ClientConfig | null> {
|
||||
}
|
||||
}
|
||||
|
||||
async function copyKey(d: Device) {
|
||||
const cfg = await getConfig(d);
|
||||
if (cfg) copy(await vpnKey(cfg, `${cfg.server} · ${cfg.name}`), 'Key copied');
|
||||
}
|
||||
|
||||
async function downloadConf(d: Device) {
|
||||
const cfg = await getConfig(d);
|
||||
if (cfg) download(cfg.filename, cfg.conf);
|
||||
}
|
||||
|
||||
/** Connection sheet: open-in-app / QR / key / file, plus live status. */
|
||||
/** One configuration line, highlighted; private and preshared keys masked unless shown. */
|
||||
function confLine(line: string, reveal: boolean): Node {
|
||||
if (/^\s*\[.+\]\s*$/.test(line)) return h('span', { class: 'conf-sec' }, line);
|
||||
@@ -1107,8 +1073,13 @@ function filePane(cfg: ClientConfig): HTMLElement {
|
||||
: 'For computers and routers: import it in AmneziaWG or AmneziaVPN',
|
||||
),
|
||||
),
|
||||
shareFile(cfg)
|
||||
? h('button', { class: 'btn primary', onclick: () => shareFile(cfg)!() }, ic('open'), h('span', {}, 'Share file'))
|
||||
shareFile(cfg.filename, cfg.conf)
|
||||
? h(
|
||||
'button',
|
||||
{ class: 'btn primary', onclick: () => shareFile(cfg.filename, cfg.conf)!() },
|
||||
ic('open'),
|
||||
h('span', {}, 'Share file'),
|
||||
)
|
||||
: h('button', { class: 'btn primary', onclick: () => download(cfg.filename, cfg.conf) }, ic('download'), h('span', {}, 'Download')),
|
||||
),
|
||||
h(
|
||||
@@ -1139,152 +1110,6 @@ function filePane(cfg: ClientConfig): HTMLElement {
|
||||
);
|
||||
}
|
||||
|
||||
async function connect(d: Device, initial?: 'app' | 'qr' | 'key' | 'file', cfgIn?: ClientConfig) {
|
||||
const cfg = cfgIn ?? (await getConfig(d));
|
||||
if (!cfg) return;
|
||||
const key = await vpnKey(cfg, `${cfg.server} · ${cfg.name}`);
|
||||
const mobile = isMobile();
|
||||
// What is being set up decides what comes first: a phone from a phone opens
|
||||
// the app, a phone seen from a computer shows the code, a computer or
|
||||
// router takes the file.
|
||||
const handheld = d.kind === 'phone' || d.kind === 'tablet';
|
||||
const panes: Record<string, () => HTMLElement> = {
|
||||
app: () =>
|
||||
h(
|
||||
'div',
|
||||
{ class: 'pane' },
|
||||
h('a', { class: 'btn primary block big', href: key }, ic('amnezia'), h('span', {}, 'Open in AmneziaVPN')),
|
||||
h(
|
||||
'ol',
|
||||
{ class: 'steps' },
|
||||
h(
|
||||
'li',
|
||||
{},
|
||||
'No AmneziaVPN yet? ',
|
||||
h('a', { href: appLink().href, target: '_blank', rel: 'noopener noreferrer' }, appLink().label),
|
||||
'.',
|
||||
),
|
||||
h('li', {}, 'Tap ', h('b', {}, 'Open in AmneziaVPN'), ' and confirm the import.'),
|
||||
h('li', {}, 'Turn the connection on — this page shows ', h('span', { class: 'ok' }, 'Connected'), ' within a minute.'),
|
||||
),
|
||||
),
|
||||
qr: () => {
|
||||
// Two codes: AmneziaVPN reads its own key (the phone's camera opens it in
|
||||
// the app); the AmneziaWG and WireGuard apps read the configuration text.
|
||||
const q = h('div', { class: 'qr' });
|
||||
const cap = h('p', { class: 'muted s' });
|
||||
const seg = h('div', { class: 'seg' });
|
||||
let mode: 'vpn' | 'conf' = plainWg() ? 'conf' : 'vpn';
|
||||
let glide = () => {};
|
||||
// The other code comes into focus where the last one was.
|
||||
const paint = (switched = false) => {
|
||||
const text = mode === 'vpn' ? key : cfg.conf;
|
||||
// A dense code is drawn as large as the sheet allows: a phone camera needs the modules.
|
||||
paintQr(q, text);
|
||||
cap.textContent =
|
||||
mode === 'vpn'
|
||||
? 'Scan with the phone’s camera or inside AmneziaVPN.'
|
||||
: plainWg()
|
||||
? 'Scan inside the AmneziaWG, WireGuard or AmneziaVPN app.'
|
||||
: 'Scan inside the AmneziaWG app (or AmneziaVPN).';
|
||||
seg.querySelectorAll<HTMLElement>(':scope > button').forEach((b) => b.classList.toggle('on', b.dataset.m === mode));
|
||||
glide();
|
||||
if (switched) {
|
||||
replay(q, 'swap');
|
||||
replay(cap, 'swap');
|
||||
}
|
||||
};
|
||||
for (const [m, label] of [
|
||||
['vpn', 'AmneziaVPN'],
|
||||
['conf', plainWg() ? 'WireGuard app' : 'AmneziaWG app'],
|
||||
] as const)
|
||||
seg.appendChild(
|
||||
h(
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
'data-m': m,
|
||||
onclick: () => {
|
||||
if (mode === m) return;
|
||||
mode = m;
|
||||
paint(true);
|
||||
},
|
||||
},
|
||||
label,
|
||||
),
|
||||
);
|
||||
paint();
|
||||
glide = slider(seg);
|
||||
return h('div', { class: 'pane center' }, seg, q, cap, qrFlip());
|
||||
},
|
||||
key: () =>
|
||||
h(
|
||||
'div',
|
||||
{ class: 'pane' },
|
||||
h('p', { class: 'muted s' }, 'In AmneziaVPN choose “Add server → Insert key”.'),
|
||||
h(
|
||||
'div',
|
||||
{ class: 'keybox' },
|
||||
h('span', { class: 'mono' }, key),
|
||||
h('button', { class: 'btn small', onclick: (ev: Event) => copy(key, 'Key copied', ev.currentTarget) }, 'Copy'),
|
||||
),
|
||||
h('p', { class: 'faint s' }, 'Keep it private: anyone with the key can use your connection.'),
|
||||
),
|
||||
file: () => filePane(cfg),
|
||||
};
|
||||
const order = mobile && handheld ? ['app', 'qr', 'key', 'file'] : handheld ? ['qr', 'key', 'file'] : ['file', 'key', 'qr'];
|
||||
const labels: Record<string, string> = { app: 'Open in app', qr: 'QR code', key: 'Key', file: 'File' };
|
||||
const body = h('div', { class: 'tab-body' });
|
||||
const tabs = h('div', { class: 'tabs', role: 'tablist' });
|
||||
// The highlight slides to the tab; its pane comes in from that side.
|
||||
let current = -1;
|
||||
let glide = () => {};
|
||||
const show = (id: string) => {
|
||||
const i = order.indexOf(id);
|
||||
tabs.querySelectorAll<HTMLElement>(':scope > button').forEach((b) => {
|
||||
b.classList.toggle('on', b.dataset.id === id);
|
||||
b.setAttribute('aria-selected', String(b.dataset.id === id));
|
||||
});
|
||||
glide();
|
||||
if (current < 0) body.replaceChildren(panes[id]());
|
||||
else if (i !== current) swap(body, [panes[id]()], Math.sign(i - current));
|
||||
current = i;
|
||||
};
|
||||
for (const id of order) tabs.appendChild(h('button', { role: 'tab', 'data-id': id, onclick: () => show(id) }, labels[id]));
|
||||
show(initial && order.includes(initial) ? initial : order[0]);
|
||||
glide = slider(tabs);
|
||||
|
||||
// Never connected: the way to the router waits on top, and once it fills the
|
||||
// code and the file have done their job and leave. Connected before: one line.
|
||||
const way = d.handshake || d.disabled ? null : waitPath(d.kind);
|
||||
const stop = way ? watchFirstConnection(d, () => void arrive(way, [tabs, body]), way.gaveUp) : () => undefined;
|
||||
sheet(
|
||||
d.handshake ? `Connect ${d.name}` : `${d.name} is ready`,
|
||||
mobile && handheld
|
||||
? 'Add it to AmneziaVPN on this phone'
|
||||
: handheld
|
||||
? 'Scan with the phone’s camera or AmneziaVPN'
|
||||
: 'Import the file in AmneziaWG or AmneziaVPN',
|
||||
way?.el,
|
||||
tabs,
|
||||
body,
|
||||
d.handshake ? liveLine(d) : null,
|
||||
);
|
||||
sheetClosed = () => {
|
||||
stop();
|
||||
if (state) main(state);
|
||||
};
|
||||
}
|
||||
|
||||
/** How a device that connected before is doing: one line under the sheet. */
|
||||
function liveLine(d: Device): HTMLElement {
|
||||
return h(
|
||||
'div',
|
||||
{ class: 'waiting' },
|
||||
d.online ? h('span', { class: 'ok' }, 'Connected') : h('span', { class: 'muted' }, `Last connected ${ago(d.handshake, now())}`),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The first connection arrived. The way fills green (the sheet goes back up to
|
||||
* it if it was scrolled) and says so; then everything under it, which did its
|
||||
@@ -1405,6 +1230,14 @@ function rememberApp(d: Device, app: AppId) {
|
||||
}
|
||||
|
||||
const APP_ICON: Record<AppId, string> = { vpn: 'amnezia', awg: 'amneziawg', wg: 'wireguard' };
|
||||
const OS_ICON: Record<Platform, string> = {
|
||||
ios: 'apple',
|
||||
android: 'googleplay',
|
||||
windows: 'windows',
|
||||
mac: 'apple',
|
||||
linux: 'linux',
|
||||
unknown: 'other',
|
||||
};
|
||||
|
||||
/**
|
||||
* A store badge: the mark in a tile, two lines, a chevron. `primary` = the one thing to tap.
|
||||
@@ -1486,18 +1319,22 @@ function linkRow(url: string): HTMLElement {
|
||||
async function setup(d: Device, cfgIn?: ClientConfig) {
|
||||
const cfg = cfgIn ?? (await getConfig(d));
|
||||
if (!cfg) return;
|
||||
const key = await vpnKey(cfg, `${cfg.server} · ${cfg.name}`);
|
||||
const key = await vpnKey(cfg, cfg.server);
|
||||
const apps = appsFor(preset());
|
||||
const pf = platform();
|
||||
const same = sameDevice(d.kind, pf);
|
||||
const handheld = d.kind === 'phone' || d.kind === 'tablet';
|
||||
const router = d.kind === 'router';
|
||||
const hereHandheld = pf === 'ios' || pf === 'android';
|
||||
const osChoices = osGroup(d.kind);
|
||||
let app: AppId = recallApp(d) ?? (router ? 'awg' : 'vpn');
|
||||
if (!apps.some((a) => a.id === app)) app = router ? 'awg' : 'vpn';
|
||||
// Which system a computer runs is the person's call; the browser's guess comes first.
|
||||
// Which system a computer (or an "other" device) runs is the person's call; the browser's guess comes first.
|
||||
let os: Platform = osChoices.length ? (osChoices.includes(pf) ? pf : 'windows') : pf;
|
||||
// With a system to pick, the page is on the device being set up when the pick is this browser's own.
|
||||
const sameKind = sameDevice(d.kind, pf);
|
||||
const same = () => (osChoices.length ? os === pf : sameKind);
|
||||
// The device being set up is a phone or a tablet: its link goes there as a code for the camera.
|
||||
const mobileTarget = () => handheld || os === 'ios' || os === 'android';
|
||||
let picker = false,
|
||||
away = false,
|
||||
open: 'link' | 'app' = 'app',
|
||||
@@ -1533,7 +1370,7 @@ async function setup(d: Device, cfgIn?: ClientConfig) {
|
||||
osChoices.map((o) => ({
|
||||
id: o,
|
||||
label: o === pf ? hereLabel(o) : PLATFORM_LABEL[o],
|
||||
icon: o === 'windows' ? 'windows' : o === 'mac' ? 'apple' : 'linux',
|
||||
icon: OS_ICON[o],
|
||||
on: o === os,
|
||||
pick: () => {
|
||||
os = o;
|
||||
@@ -1591,15 +1428,25 @@ async function setup(d: Device, cfgIn?: ClientConfig) {
|
||||
// Step 2 follows the app and the device: a link for AmneziaVPN, the file for the others.
|
||||
const connectStep = () => {
|
||||
const name = APP_NAME[app];
|
||||
if (app === 'vpn' && hereHandheld)
|
||||
// On the phone being set up, a link opens AmneziaVPN only on Android; an
|
||||
// iPhone takes the key as a .vpn file from the share sheet.
|
||||
const inHand = same() && hereHandheld;
|
||||
const send = app === 'vpn' && inHand && !opensKeyLinks(pf) ? shareFile(keyFileName(cfg.filename), key) : null;
|
||||
if (app === 'vpn' && inHand && (opensKeyLinks(pf) || send))
|
||||
return step(
|
||||
'2',
|
||||
'Add the connection',
|
||||
badge({ href: key, top: 'Then come back here and tap', main: 'Open in AmneziaVPN', mark: 'amnezia' }, true, 'connect'),
|
||||
send
|
||||
? badge(
|
||||
{ top: 'Then come back here and tap', main: 'Send to AmneziaVPN', mark: 'amnezia', onclick: () => void send() },
|
||||
true,
|
||||
'connect',
|
||||
)
|
||||
: badge({ href: key, top: 'Then come back here and tap', main: 'Open in AmneziaVPN', mark: 'amnezia' }, true, 'connect'),
|
||||
h(
|
||||
'span',
|
||||
{ class: 'faint s' },
|
||||
'Nothing opened? ',
|
||||
send ? 'Pick AmneziaVPN in the share sheet. Not there? ' : 'Nothing opened? ',
|
||||
h('a', { href: '#', onclick: (ev: Event) => (ev.preventDefault(), copy(key, 'Key copied', ev.currentTarget)) }, 'Copy the key'),
|
||||
' and add it in the app.',
|
||||
),
|
||||
@@ -1625,14 +1472,22 @@ async function setup(d: Device, cfgIn?: ClientConfig) {
|
||||
h('li', {}, 'Add server → ', h('b', {}, 'Insert key')),
|
||||
h('li', {}, 'Paste the key and connect'),
|
||||
),
|
||||
h('span', { class: 'faint s' }, 'Have the app open? ', h('a', { href: key }, 'Open in AmneziaVPN')),
|
||||
);
|
||||
const share = hereHandheld ? shareFile(cfg) : null;
|
||||
const share = hereHandheld ? shareFile(cfg.filename, cfg.conf) : null;
|
||||
return step(
|
||||
'2',
|
||||
'Add the connection',
|
||||
share
|
||||
? badge({ top: `Straight into ${name}`, main: 'Share the file', mark: 'share', onclick: () => share() }, true, 'connect')
|
||||
? badge(
|
||||
{
|
||||
top: same() ? `Straight into ${name}` : `Send it to the ${there}`,
|
||||
main: 'Share the file',
|
||||
mark: 'share',
|
||||
onclick: () => share(),
|
||||
},
|
||||
true,
|
||||
'connect',
|
||||
)
|
||||
: badge(
|
||||
{
|
||||
top: 'Then import it in the app',
|
||||
@@ -1646,9 +1501,8 @@ async function setup(d: Device, cfgIn?: ClientConfig) {
|
||||
h(
|
||||
'ol',
|
||||
{ class: 'howto', 'data-m': 'howto' },
|
||||
h('li', {}, `Open ${name}`),
|
||||
h('li', {}, importPath(app).replace(/ → .*$/, ' → '), h('b', {}, importPath(app).replace(/^.* → /, ''))),
|
||||
h('li', {}, share ? 'Confirm the import and connect' : 'Pick the file and connect'),
|
||||
// In the words of the app where the file goes: the computer's system, or the phone in hand.
|
||||
importSteps(app, os, cfg.filename, !!share && same()).map(([text, bold]) => h('li', {}, text, bold ? h('b', {}, bold) : null)),
|
||||
),
|
||||
);
|
||||
};
|
||||
@@ -1698,27 +1552,28 @@ async function setup(d: Device, cfgIn?: ClientConfig) {
|
||||
// Not on the device: the link goes there (as a code for a phone's camera), the rest happens there.
|
||||
// It names the device, so the page there opens straight on its set-up.
|
||||
const linkThere = setupLink(location.origin + location.pathname, d.id);
|
||||
const awayCard = (easiest = false, fold = false) =>
|
||||
h(
|
||||
const awayCard = ({ easiest = false, fold = false, or = false } = {}) => {
|
||||
const title = `${or ? 'Or open' : 'Open'} your link on the ${there}`;
|
||||
return h(
|
||||
'div',
|
||||
{ class: `step${fold && open !== 'link' ? ' folded' : ''}` },
|
||||
fold
|
||||
? foldHead(
|
||||
'link',
|
||||
h('span', { class: 'step-title grow' }, `Open your link on the ${there}`),
|
||||
h('span', { class: 'step-title grow' }, title),
|
||||
easiest ? h('span', { class: 'chip', 'data-glide': 'easiest' }, 'Easiest') : null,
|
||||
)
|
||||
: h(
|
||||
'div',
|
||||
{ class: 'step-head' },
|
||||
h('span', { class: 'step-title grow' }, `Open your link on the ${there}`),
|
||||
h('span', { class: 'step-title grow' }, title),
|
||||
easiest ? h('span', { class: 'chip' }, 'Easiest') : null,
|
||||
),
|
||||
...(fold && open !== 'link'
|
||||
? []
|
||||
: unfolded(entered === 'link', [
|
||||
h('span', { class: 'muted s step-sub' }, 'The same page there does both steps for that device.'),
|
||||
handheld
|
||||
mobileTarget()
|
||||
? h(
|
||||
'div',
|
||||
{ class: 'code-row' },
|
||||
@@ -1734,6 +1589,7 @@ async function setup(d: Device, cfgIn?: ClientConfig) {
|
||||
linkRow(linkThere),
|
||||
])),
|
||||
);
|
||||
};
|
||||
const awayFold = () =>
|
||||
away
|
||||
? (() => {
|
||||
@@ -1772,7 +1628,7 @@ async function setup(d: Device, cfgIn?: ClientConfig) {
|
||||
h(
|
||||
'div',
|
||||
{ class: 'code-row' },
|
||||
qrOf('app-qr', app === 'vpn' ? key : cfg.conf),
|
||||
qrOf('app-qr', app === 'vpn' ? vpnQrText(key) : cfg.conf),
|
||||
h(
|
||||
'span',
|
||||
{ class: 'stack' },
|
||||
@@ -1781,12 +1637,6 @@ async function setup(d: Device, cfgIn?: ClientConfig) {
|
||||
qrFlip(),
|
||||
),
|
||||
),
|
||||
h(
|
||||
'span',
|
||||
{ class: 'faint s' },
|
||||
'Prefer the file or the key? ',
|
||||
h('a', { href: '#', onclick: (ev: Event) => (ev.preventDefault(), connect(d, 'file', cfg)) }, 'Connection details'),
|
||||
),
|
||||
])),
|
||||
);
|
||||
|
||||
@@ -1802,7 +1652,7 @@ async function setup(d: Device, cfgIn?: ClientConfig) {
|
||||
h('span', { class: 'grow' }, 'Open this page in Safari or Chrome: the store opens from here, but the app handoff does not.'),
|
||||
),
|
||||
);
|
||||
if (same) parts.push(getStep(), connectStep(), awayFold());
|
||||
if (same()) parts.push(getStep(), connectStep(), awayFold());
|
||||
else if (router)
|
||||
parts.push(
|
||||
step(
|
||||
@@ -1813,24 +1663,14 @@ async function setup(d: Device, cfgIn?: ClientConfig) {
|
||||
),
|
||||
step('2', 'Import the configuration', filePane(cfg)),
|
||||
);
|
||||
else if (handheld) parts.push(awayCard(true, true), appCodeCard());
|
||||
else if (handheld) parts.push(awayCard({ easiest: true, fold: true }), appCodeCard());
|
||||
// A computer set up from a phone: the same two steps for the app on the computer, then the link that does both there.
|
||||
else
|
||||
parts.push(
|
||||
h('span', { class: 'muted s' }, `The app goes on the ${there}. Which one is it?`),
|
||||
osPills(),
|
||||
awayCard(true),
|
||||
step(
|
||||
'',
|
||||
[h('span', { class: 'grow', 'data-m': 'get' }, `${APP_NAME[app]} for ${PLATFORM_LABEL[os]}`)],
|
||||
h('span', { class: 'faint s' }, 'Or download the installer here and move it to the PC'),
|
||||
...storeBlock(),
|
||||
),
|
||||
h(
|
||||
'span',
|
||||
{ class: 'faint s center' },
|
||||
`Already has ${APP_NAME[app]}? `,
|
||||
h('a', { href: '#', onclick: (ev: Event) => (ev.preventDefault(), copy(key, 'Key copied', ev.currentTarget)) }, 'Copy the key'),
|
||||
),
|
||||
h('span', { class: 'muted s' }, `The app goes on the ${there}.`),
|
||||
getStep(),
|
||||
connectStep(),
|
||||
awayCard({ easiest: true, or: true }),
|
||||
);
|
||||
restyle(body, () => body.replaceChildren(...parts.flat().filter((x): x is Node => x instanceof Node)));
|
||||
entered = null;
|
||||
@@ -1844,7 +1684,7 @@ async function setup(d: Device, cfgIn?: ClientConfig) {
|
||||
},
|
||||
way.gaveUp,
|
||||
);
|
||||
sheet(`Set up ${d.name}`, same ? 'Two steps, about a minute' : router ? 'The packages and the file for OpenWrt' : null, way.el, body);
|
||||
sheet(`Set up ${d.name}`, same() ? 'Two steps, about a minute' : router ? 'The packages and the file for OpenWrt' : null, way.el, body);
|
||||
sheetClosed = () => {
|
||||
stop();
|
||||
if (state) main(state);
|
||||
@@ -1883,24 +1723,31 @@ function rename(d: Device) {
|
||||
setTimeout(() => name.select(), 50);
|
||||
}
|
||||
|
||||
/** New keys for a device: the old configuration stops working, the new one is shown right away. */
|
||||
function rotateKeys(d: Device, st: State) {
|
||||
/**
|
||||
* Set a device up from scratch (a new phone, the app reinstalled, settings the
|
||||
* admin changed): new keys, so what it holds stops working; it shows "Not set
|
||||
* up yet" until it connects with the new configuration, which the set-up sheet
|
||||
* opens on.
|
||||
*/
|
||||
function reconnect(d: Device, st: State) {
|
||||
const twin = httpsTwin();
|
||||
if (twin) return secureSheet(twin);
|
||||
ask({
|
||||
icon: 'key',
|
||||
icon: 'refresh',
|
||||
tone: 'warn',
|
||||
title: `New keys for ${d.name}?`,
|
||||
title: `Reconnect ${d.name}?`,
|
||||
text:
|
||||
st.here === d.id
|
||||
? 'This device is connected through its current settings: it disconnects a few seconds after you confirm. Import the new ones that open next.'
|
||||
: 'Its current settings stop working. Set it up again with the new ones that open next.',
|
||||
action: 'New keys',
|
||||
? 'It gets new keys. This device is connected through its current settings: it disconnects a few seconds after you confirm. Add the new ones that open next.'
|
||||
: 'It gets new keys and its current settings stop working. Set it up again with the new ones that open next.',
|
||||
action: 'Reconnect',
|
||||
actionClass: 'primary',
|
||||
run: async () => {
|
||||
try {
|
||||
const r = await call<{ config: ClientConfig; state: State }>(`devices/${d.id}`, { action: 'rotate' });
|
||||
const r = await call<{ config: ClientConfig; state: State }>(`devices/${d.id}`, { action: 'reconnect' });
|
||||
state = r.state;
|
||||
main(state);
|
||||
await setup({ ...d, handshake: 0 }, r.config);
|
||||
await setup(state.person.devices.find((x) => x.id === d.id) ?? { ...d, handshake: 0 }, r.config);
|
||||
} catch (er) {
|
||||
toast((er as Error).message, true);
|
||||
}
|
||||
|
||||
@@ -366,41 +366,6 @@ export function restyle(root: ParentNode, paint: () => void) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A row of choices whose highlight slides to the one picked: a copy of the row
|
||||
* drawn in the picked look on top, clipped to the picked button, so the colour
|
||||
* changes exactly where the highlight is (clip-path tabs). The real buttons keep
|
||||
* `.on`; call the returned function after changing it.
|
||||
*/
|
||||
export function slider(row: HTMLElement): () => void {
|
||||
const hl = row.cloneNode(true) as HTMLElement;
|
||||
hl.classList.add('slide-hl');
|
||||
hl.setAttribute('aria-hidden', 'true');
|
||||
hl.inert = true;
|
||||
hl.removeAttribute('role');
|
||||
hl.querySelectorAll('[role]').forEach((b) => b.removeAttribute('role'));
|
||||
row.classList.add('slides');
|
||||
row.appendChild(hl);
|
||||
let placed = false;
|
||||
const move = () => {
|
||||
const on = row.querySelector<HTMLElement>(':scope > .on');
|
||||
if (!on || !row.isConnected) return;
|
||||
const w = row.clientWidth,
|
||||
h = row.clientHeight;
|
||||
const l = on.offsetLeft,
|
||||
t = on.offsetTop;
|
||||
hl.classList.toggle('placed', placed);
|
||||
hl.style.clipPath = `inset(${t}px ${w - l - on.offsetWidth}px ${h - t - on.offsetHeight}px ${l}px round 999px)`;
|
||||
placed = true;
|
||||
};
|
||||
// Fonts and the sheet's own layout settle after the first call: place it again, without a glide.
|
||||
new ResizeObserver(() => {
|
||||
placed = false;
|
||||
move();
|
||||
}).observe(row);
|
||||
return move;
|
||||
}
|
||||
|
||||
/** A copy button in its "Copied" moment: what to put back, and when. */
|
||||
const COPIED = new WeakMap<HTMLElement, { timer: number; icon: string | null; label: string | null }>();
|
||||
|
||||
|
||||
+7
-139
@@ -132,7 +132,6 @@ body {
|
||||
}
|
||||
input,
|
||||
textarea,
|
||||
.keybox .mono,
|
||||
.linkrow .mono,
|
||||
.conf {
|
||||
cursor: text;
|
||||
@@ -982,6 +981,11 @@ input[type='text']:focus {
|
||||
.menu-item.danger .ic {
|
||||
color: var(--bad);
|
||||
}
|
||||
/* Undoable but not harmless (Reconnect: new keys), as the admin's Pause. */
|
||||
.menu-item.warn,
|
||||
.menu-item.warn .ic {
|
||||
color: var(--warn);
|
||||
}
|
||||
.menu-sep {
|
||||
height: 1px;
|
||||
background: var(--line);
|
||||
@@ -1111,38 +1115,11 @@ input[type='text']:focus {
|
||||
padding-top: 0;
|
||||
}
|
||||
}
|
||||
.tabs {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
padding: 4px;
|
||||
background: var(--soft);
|
||||
border-radius: 999px;
|
||||
}
|
||||
.tabs button {
|
||||
all: unset;
|
||||
cursor: pointer;
|
||||
flex: 1 1 auto;
|
||||
white-space: nowrap;
|
||||
text-align: center;
|
||||
padding: 7px 10px;
|
||||
border-radius: 999px;
|
||||
font-weight: 500;
|
||||
font-size: 13px;
|
||||
color: var(--muted);
|
||||
}
|
||||
.tabs button.on {
|
||||
background: var(--soft-hover);
|
||||
color: var(--text);
|
||||
}
|
||||
.pane {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
.pane.center {
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
}
|
||||
/* The code, night look (shared/qr): light dots on a black card with a fine outline.
|
||||
`.light`: the plain look, for scanners that read only dark on light. */
|
||||
.qr {
|
||||
@@ -1164,34 +1141,6 @@ input[type='text']:focus {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.steps {
|
||||
margin: 4px 0 0;
|
||||
padding: 14px 16px 14px 34px;
|
||||
border-radius: 14px;
|
||||
border: 1px solid var(--line);
|
||||
background: var(--card);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
font-size: 14px;
|
||||
}
|
||||
.keybox {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
height: 44px;
|
||||
padding: 0 6px 0 12px;
|
||||
border: 1px solid var(--input);
|
||||
border-radius: 10px;
|
||||
}
|
||||
.keybox .mono {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
color: var(--muted);
|
||||
}
|
||||
.filecard {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -1290,15 +1239,6 @@ details > summary {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
}
|
||||
.waiting {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 12px 14px;
|
||||
border-radius: 12px;
|
||||
background: var(--soft);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
/* tooltip & toast */
|
||||
.tip {
|
||||
@@ -1351,33 +1291,6 @@ details > summary {
|
||||
margin: 0;
|
||||
font-size: 17px;
|
||||
}
|
||||
.firststeps .steps {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Which app the code is for. */
|
||||
.pane .seg {
|
||||
display: inline-flex;
|
||||
gap: 2px;
|
||||
padding: 3px;
|
||||
border-radius: 999px;
|
||||
background: var(--soft, rgba(127, 127, 127, 0.12));
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.pane .seg button {
|
||||
border: 0;
|
||||
background: none;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
font-size: 13px;
|
||||
padding: 5px 12px;
|
||||
border-radius: 999px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.pane .seg button.on {
|
||||
background: var(--card, #fff);
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
|
||||
}
|
||||
|
||||
/* ---------- setting up a device: two numbered steps ---------- */
|
||||
.setup {
|
||||
@@ -1385,11 +1298,6 @@ details > summary {
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
.setup .center {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
}
|
||||
.step {
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 16px;
|
||||
@@ -1763,8 +1671,6 @@ details > summary {
|
||||
.name-chip,
|
||||
.fold-link,
|
||||
.pill-link,
|
||||
.tabs > button,
|
||||
.seg > button,
|
||||
.menu-item {
|
||||
transition:
|
||||
transform var(--dur-press) var(--ease-out),
|
||||
@@ -1779,9 +1685,7 @@ details > summary {
|
||||
.kind:active,
|
||||
.icon-btn:active,
|
||||
.fold-link:active,
|
||||
.pill-link:active,
|
||||
.tabs > button:active,
|
||||
.seg > button:active {
|
||||
.pill-link:active {
|
||||
transform: scale(0.97);
|
||||
}
|
||||
/* Wide surfaces give less: the same press reads larger on them. */
|
||||
@@ -2018,7 +1922,6 @@ textarea {
|
||||
}
|
||||
/* What a swap lifts out of the flow while it fades (motion.ts swap): under the new content, not over it. */
|
||||
.sheet-inner,
|
||||
.tab-body,
|
||||
.setup {
|
||||
position: relative;
|
||||
isolation: isolate;
|
||||
@@ -2029,38 +1932,6 @@ textarea {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* Tabs and segments: a copy of the row in the picked look, clipped to the pick, slides (motion.ts slider). */
|
||||
.slides {
|
||||
position: relative;
|
||||
}
|
||||
.slide-hl {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
margin: 0 !important;
|
||||
pointer-events: none;
|
||||
}
|
||||
.slide-hl.placed {
|
||||
transition: clip-path 300ms var(--ease-out);
|
||||
}
|
||||
.tabs.slide-hl {
|
||||
background: var(--soft-hover);
|
||||
}
|
||||
.pane .seg.slide-hl {
|
||||
background: var(--card);
|
||||
}
|
||||
.slide-hl > button,
|
||||
.slide-hl > button.on {
|
||||
background: none;
|
||||
box-shadow: none;
|
||||
color: var(--text);
|
||||
transition: none;
|
||||
}
|
||||
.tabs.slides > button.on,
|
||||
.pane .seg.slides > button.on {
|
||||
background: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
/* Setup repaints (motion.ts restyle): what flipped starts from its other look; a card that
|
||||
just folded shows its chevron with a little spring. */
|
||||
.fold.to-off .fold-chev {
|
||||
@@ -2313,7 +2184,6 @@ textarea {
|
||||
.sheet.open .sheet-panel {
|
||||
opacity: 1;
|
||||
}
|
||||
.slide-hl.placed,
|
||||
.confbox > summary > .ic:first-child {
|
||||
transition: none;
|
||||
}
|
||||
@@ -2325,9 +2195,7 @@ textarea {
|
||||
.slot.add:active,
|
||||
.name-chip:active,
|
||||
.fold-link:active,
|
||||
.pill-link:active,
|
||||
.tabs > button:active,
|
||||
.seg > button:active {
|
||||
.pill-link:active {
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
+60
-6
@@ -33,8 +33,13 @@ export function sameDevice(kind: Kind, platform: Platform): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** The systems a kind may run: a computer's is the person's call, the rest are read from the browser. */
|
||||
export const osGroup = (kind: Kind): Platform[] => (kind === 'computer' || kind === 'other' ? ['windows', 'mac', 'linux'] : []);
|
||||
/**
|
||||
* The systems a kind may run, when that is the person's call: a computer's
|
||||
* desktop systems, any system for an "other" device (a TV box runs Android, a
|
||||
* NAS Linux). A phone's or a tablet's is read from the browser.
|
||||
*/
|
||||
export const osGroup = (kind: Kind): Platform[] =>
|
||||
kind === 'computer' ? ['windows', 'mac', 'linux'] : kind === 'other' ? ['ios', 'android', 'windows', 'mac', 'linux'] : [];
|
||||
|
||||
export interface AppChoice {
|
||||
id: AppId;
|
||||
@@ -154,10 +159,59 @@ export const routerStore = (app: AppId): Store =>
|
||||
}
|
||||
: { href: 'https://openwrt.org/packages/start', top: 'OpenWrt packages', main: 'amneziawg-tools + kmod', mark: 'openwrt' };
|
||||
|
||||
/** Inside the app: where the scanner and the importer are. */
|
||||
export const scanPath = (app: AppId): string =>
|
||||
app === 'vpn' ? 'Add server → Scan QR' : app === 'awg' ? 'Add tunnel → Scan QR code' : 'Add tunnel → Create from QR code';
|
||||
export const importPath = (app: AppId): string => (app === 'vpn' ? 'Add server → Insert key' : 'Add tunnel → Import from file');
|
||||
/**
|
||||
* Does AmneziaVPN here open a `vpn://` link? Only the Android app registers the
|
||||
* scheme: on iOS, macOS and Windows the link opens nothing ("the address is
|
||||
* invalid"), or another app that claims vpn:// gets the key.
|
||||
*/
|
||||
export const opensKeyLinks = (platform: Platform): boolean => platform === 'android';
|
||||
|
||||
/** The key as a file for the share sheet: AmneziaVPN on iOS imports `.vpn` files (the key as text). */
|
||||
export const keyFileName = (confName: string): string => `${confName.replace(/\.conf$/i, '')}.vpn`;
|
||||
|
||||
/*
|
||||
* Inside the app: where the scanner and the importer are, as each platform's
|
||||
* app words it. The WireGuard apps are the same apps as AmneziaWG (it is
|
||||
* their fork), menus included.
|
||||
*/
|
||||
const TUNNEL_MENU: Partial<Record<Platform, { file: string; qr?: string }>> = {
|
||||
ios: { file: '+ → Create from file or archive', qr: '+ → Create from QR code' },
|
||||
android: { file: '+ → Import from file or archive', qr: '+ → Scan from QR code' },
|
||||
mac: { file: '+ → Import tunnel(s) from file' },
|
||||
windows: { file: 'Add Tunnel → Import tunnel(s) from file' },
|
||||
};
|
||||
|
||||
/** Where the app scans a code; a phone of either kind gets both wordings. */
|
||||
export function scanPath(app: AppId, platform: Platform = 'unknown'): string {
|
||||
if (app === 'vpn') return 'Add server → Scan QR';
|
||||
const qr = TUNNEL_MENU[platform]?.qr;
|
||||
return qr ?? `${TUNNEL_MENU.ios!.qr} (Android: ${TUNNEL_MENU.android!.qr!.replace(/^.* → /, '')})`;
|
||||
}
|
||||
|
||||
/** Where the app takes a file (AmneziaVPN: the key). */
|
||||
export function importPath(app: AppId, platform: Platform = 'unknown'): string {
|
||||
if (app === 'vpn') return 'Add server → Insert key';
|
||||
return TUNNEL_MENU[platform]?.file ?? 'Add tunnel → Import from file';
|
||||
}
|
||||
|
||||
/**
|
||||
* The file into the app, step by step: [text, the part in bold]. Linux has no
|
||||
* app, only the tools: the file goes up straight from where it was saved
|
||||
* (its name is a valid interface name, see tunnel_name on the router).
|
||||
*/
|
||||
export function importSteps(app: AppId, platform: Platform, file: string, shared: boolean): [string, string][] {
|
||||
if (platform === 'linux')
|
||||
return [
|
||||
['Open a terminal in the folder with the file', ''],
|
||||
['Run ', `sudo ${app === 'wg' ? 'wg-quick' : 'awg-quick'} up ./${file}`],
|
||||
];
|
||||
const path = importPath(app, platform);
|
||||
return [
|
||||
[`Open ${APP_NAME[app]}`, ''],
|
||||
[path.replace(/ → [^→]*$/, ' → '), path.replace(/^.* → /, '')],
|
||||
[shared ? 'Confirm the import and connect' : 'Pick the file and connect', ''],
|
||||
];
|
||||
}
|
||||
|
||||
export const PLATFORM_LABEL: Record<Platform, string> = {
|
||||
ios: 'iPhone / iPad',
|
||||
|
||||
@@ -135,6 +135,14 @@ export async function vpnKey(cfg: ClientConfig, description: string, compress =
|
||||
return `vpn://${base64Url(packed ?? json)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* The key as AmneziaVPN's scanner reads it: the payload without "vpn://". Its
|
||||
* QR import decodes the scanned text as base64 as it is (only the paste and
|
||||
* file imports drop the prefix), and v, p and n are base64 too: with the
|
||||
* prefix the payload shifts and the import fails.
|
||||
*/
|
||||
export const vpnQrText = (key: string): string => key.replace(/^vpn:\/\//, '');
|
||||
|
||||
/** The .conf with a browser-held private key substituted in. */
|
||||
export function withPrivateKey(cfg: ClientConfig, priv: string): ClientConfig {
|
||||
return {
|
||||
|
||||
@@ -2,9 +2,15 @@ import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
appsFor,
|
||||
deviceNoun,
|
||||
importPath,
|
||||
importSteps,
|
||||
inWebview,
|
||||
keyFileName,
|
||||
opensKeyLinks,
|
||||
osGroup,
|
||||
platformOf,
|
||||
sameDevice,
|
||||
scanPath,
|
||||
setupFromHash,
|
||||
setupLink,
|
||||
storeFor,
|
||||
@@ -54,6 +60,13 @@ describe('setup', () => {
|
||||
expect(sameDevice('phone', 'unknown')).toBe(false);
|
||||
});
|
||||
|
||||
it('lets the person pick the system of a computer or an "other" device', () => {
|
||||
expect(osGroup('computer')).toEqual(['windows', 'mac', 'linux']);
|
||||
expect(osGroup('other')).toEqual(['ios', 'android', 'windows', 'mac', 'linux']);
|
||||
expect(osGroup('phone')).toEqual([]);
|
||||
expect(osGroup('router')).toEqual([]);
|
||||
});
|
||||
|
||||
it('lists the apps a disguise allows, AmneziaVPN first', () => {
|
||||
expect(appsFor('max').map((a) => a.id)).toEqual(['vpn', 'awg']);
|
||||
expect(appsFor('off').map((a) => a.id)).toEqual(['vpn', 'awg', 'wg']);
|
||||
@@ -72,6 +85,31 @@ describe('setup', () => {
|
||||
expect(storeFor('vpn', 'unknown')).toBeNull();
|
||||
});
|
||||
|
||||
it('opens vpn:// links only where AmneziaVPN registers them, and names the key file for the rest', () => {
|
||||
expect(opensKeyLinks('android')).toBe(true);
|
||||
expect(opensKeyLinks('ios')).toBe(false);
|
||||
expect(opensKeyLinks('windows')).toBe(false);
|
||||
expect(opensKeyLinks('mac')).toBe(false);
|
||||
expect(keyFileName('outline-iphone.conf')).toBe('outline-iphone.vpn');
|
||||
expect(keyFileName('home')).toBe('home.vpn');
|
||||
});
|
||||
|
||||
it('words the import as each platform’s app does', () => {
|
||||
expect(importPath('awg', 'ios')).toBe('+ → Create from file or archive');
|
||||
expect(importPath('awg', 'android')).toBe('+ → Import from file or archive');
|
||||
expect(importPath('wg', 'windows')).toBe('Add Tunnel → Import tunnel(s) from file');
|
||||
expect(importPath('vpn', 'ios')).toBe('Add server → Insert key');
|
||||
expect(scanPath('awg', 'android')).toBe('+ → Scan from QR code');
|
||||
expect(scanPath('awg')).toBe('+ → Create from QR code (Android: Scan from QR code)');
|
||||
expect(importSteps('awg', 'mac', 'Outline-Home.conf', false)).toEqual([
|
||||
['Open AmneziaWG', ''],
|
||||
['+ → ', 'Import tunnel(s) from file'],
|
||||
['Pick the file and connect', ''],
|
||||
]);
|
||||
expect(importSteps('awg', 'linux', 'Outline-Home.conf', false)[1]).toEqual(['Run ', 'sudo awg-quick up ./Outline-Home.conf']);
|
||||
expect(importSteps('wg', 'linux', 'Outline-Home.conf', false)[1][1]).toContain('wg-quick up');
|
||||
});
|
||||
|
||||
it('spots in-app browsers', () => {
|
||||
expect(inWebview(`${ANDROID} Telegram-Android/10.0`)).toBe(true);
|
||||
expect(inWebview(IPHONE)).toBe(false);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { inflateSync } from 'node:zlib';
|
||||
import { byDeviceState, bytes, daysLeft, initials, quotaText, slugify } from '../src/shared/format';
|
||||
import { amneziaJson, base64Url, fromBase64Url, vpnKey, withPrivateKey } from '../src/shared/vpnkey';
|
||||
import { amneziaJson, base64Url, fromBase64Url, vpnKey, vpnQrText, withPrivateKey } from '../src/shared/vpnkey';
|
||||
import type { ClientConfig } from '../src/shared/types';
|
||||
|
||||
const cfg: ClientConfig = {
|
||||
@@ -80,6 +80,14 @@ describe('vpn:// keys', () => {
|
||||
expect(JSON.parse(json).hostName).toBe('vpn.example.com');
|
||||
});
|
||||
|
||||
it('puts the bare payload in the QR code: AmneziaVPN’s scanner does not drop vpn://', async () => {
|
||||
const key = await vpnKey(cfg, 'x');
|
||||
const qr = vpnQrText(key);
|
||||
expect(qr).toBe(key.slice(6));
|
||||
expect(qr).toMatch(/^[A-Za-z0-9_-]+$/);
|
||||
expect(vpnQrText(qr)).toBe(qr);
|
||||
});
|
||||
|
||||
it('substitutes a browser-held private key', () => {
|
||||
const c = withPrivateKey(
|
||||
{ ...cfg, has_private_key: false, conf: cfg.conf.replace('AAA=', '<private key stays on your device>') },
|
||||
|
||||
Reference in new issue
Block a user