// Disguise methods: one picker for the Server page and the setup wizard. import type { AwgCaps } from '../shared/types'; import { E } from './e'; import { icon } from '../shared/icons'; export type Method = 'balanced' | 'max' | 'off'; /** The router features a method may need (the boolean ones of AwgCaps). */ export type AwgNeed = 'v2' | 'v3'; export interface MethodInfo { id: Method; title: string; ic: string; text: string; /** 0-4, shown as dots. */ stealth: number; speed: number; /** Which apps can connect. */ apps: string; /** The same, short (server header). */ short: string; /** Router capability it needs. */ needs?: AwgNeed; } export const METHODS: MethodInfo[] = [ { id: 'off', title: 'Off', ic: 'zap', stealth: 0, speed: 4, text: 'Plain WireGuard-compatible traffic. Fastest, but easy to recognise and block.', apps: 'Any WireGuard app', short: 'Any WireGuard app', }, { id: 'balanced', title: 'Balanced', ic: 'shield', stealth: 3, speed: 4, needs: 'v2', text: 'AmneziaWG 2.0: junk packets, padded packets and a first packet that looks like DNS. For networks that learned to spot 1.0-style junk.', apps: 'AmneziaVPN 4.8.12 or newer, AmneziaWG 2.0+ apps', short: 'AmneziaWG 2.0+ apps', }, { id: 'max', title: 'Maximum', ic: 'lock', stealth: 4, speed: 3, needs: 'v3', text: 'AmneziaWG 3.1: encrypted packet headers, random tails and sizes, jittered timing, and a first packet that looks like DNS.', apps: 'Apps with AmneziaWG 3.1 (current AmneziaVPN)', short: 'AmneziaWG 3.1 apps', }, ]; export const methodInfo = (id: string): MethodInfo | undefined => METHODS.find((x) => x.id === id); /** The disguise a new server gets: the strongest this router can run. */ export const defaultMethod = (caps: AwgCaps): Method => (caps.v3 ? 'max' : caps.v2 ? 'balanced' : 'off'); /** * Servers made before 0.8 may carry the old Standard or Strong disguise * (1.0-style junk only, which networks learned to spot). They keep running; * the picker offers Balanced or Maximum instead. The title for such a server, or null. */ export const legacyTitle = (preset: string): string | null => preset === 'standard' ? 'Standard (old)' : preset === 'strong' ? 'Strong (old)' : null; const NEEDS: Record = { v2: 'Needs AmneziaWG 2.0 or newer on the router (kmod-amneziawg and amneziawg-tools from July 2025 on).', v3: 'Needs AmneziaWG 3.1 on the router (kmod-amneziawg and amneziawg-tools 3.1).', }; /** The same while no AmneziaWG is installed at all ("newer" would be misleading). */ const NEEDS_NONE: Record = { v2: 'Needs AmneziaWG on the router.', v3: 'Needs AmneziaWG 3.1 on the router: install it first.', }; function dots(n: number, label: string): HTMLElement { return E('span', { class: 'dl-dots', title: `${label}: ${n} of 4` }, [ E('span', { class: 'dl-dots-label' }, label), E( 'span', { class: 'dl-dots-row' }, [0, 1, 2, 3].map((i) => E('i', { class: i < n ? 'on' : '' })), ), ]); } /** * Method cards. `current` gets a badge; unavailable methods stay visible but * disabled with the reason, so it is clear what an upgrade would bring. * `installed` is false while the router has no AmneziaWG tools at all. */ export function methodPicker( caps: AwgCaps, selected: Method, onSelect: (m: Method) => void, current?: string, installed = true, ): HTMLElement { const el = E('div', { class: 'dl-methods', role: 'radiogroup', 'aria-label': 'Disguise method' }); const paint = () => dom.content( el, METHODS.map((m) => { const ok = !m.needs || caps[m.needs]; const on = m.id === selected; return E( 'button', { type: 'button', role: 'radio', 'aria-checked': on ? 'true' : 'false', 'aria-disabled': ok ? null : 'true', class: `dl-method${on ? ' on' : ''}${ok ? '' : ' off'}`, click: () => { if (!ok || on) return; selected = m.id; paint(); onSelect(m.id); }, }, [ E('div', { class: 'dl-method-head' }, [ E('span', { class: 'dl-method-ic' }, icon(m.ic)), E('b', {}, m.title), m.id === current ? E('span', { class: 'dl-pill ok' }, 'Current') : '', ]), E('p', {}, m.text), E('div', { class: 'dl-method-meters' }, [dots(m.stealth, 'Stealth'), dots(m.speed, 'Speed')]), E( 'div', { class: 'dl-method-foot' }, ok ? [icon(m.id === 'off' ? 'wireguard' : 'amneziawg'), E('span', {}, m.apps)] : [icon('alert'), E('span', {}, (installed ? NEEDS : NEEDS_NONE)[m.needs!])], ), ], ); }), ); paint(); return el; }