Files
dawnline/web/src/admin/api.ts
T
Aemeath dc0f159447
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
Dawnline 0.14.0
- A device is renamed where its name stands on its card: a click on the
  name, Return or Space on it, or Rename in the ⋯ menu turns it into a
  field with the name selected. Return saves, and the words shimmer until
  the router answers. Esc or a click elsewhere puts the old name back. The
  rename window is gone, and the page no longer redraws under a name being
  edited
- Device names take up to 20 characters: letters of any language, digits,
  spaces and - _ . The router refuses anything else when a device is added
  or renamed, so a name can't carry symbols into configurations, file
  names or the AmneziaVPN key. The portal and the admin turn a character
  like that away as it is typed: the field shakes, its outline goes red
  and a short line says why. Suggested names (a phone's model, "Phone 2")
  are stripped of such characters and cut to fit. Names set before this
  stay as they are
- LAN Bypass: Add a device, in the portal and in the admin, has a switch
  that keeps the device's own local network (printer, TV, NAS) reachable
  while it is connected. It is off by default and stays as chosen; the
  admin's device drawer shows it. With home and internet access the switch
  says which addresses still lead to the home network
- Health warns when a server's home network is on one of the subnets home
  routers come with (192.168.0.x, 192.168.1.x and others). People with
  home access who connect from a network on the same addresses reach your
  home instead of their own, LAN Bypass or not
- The router tells when a device can't connect properly. After the problem
  lasts three minutes, the portal card and the admin drawer name it:
  can't finish connecting (the network may block it), connected but no
  data (an outdated configuration, and the card offers Reconnect), on two
  devices at once, or a connection that keeps dropping. Activity lists
  these under Problems, one line per device per hour, and says when the
  device connects normally again
- The set-up sheet's connection line follows what the device does:
  waiting, can't finish, connected, or connected but no data. The sheet
  closes by itself only once data comes through. On the device itself and
  for a router, the steps regroup to what fixes the problem: "Set it up
  again" when the handshake never finishes, "Add the connection again"
  ("Import the configuration again" for a router) when no data comes
- Set-up in the portal: a QR code too long for a camera to read gives its
  place to a code that opens the set-up link (a LAN Bypass configuration
  or a long AmneziaVPN key can be that long). A TV, box or NAS added from
  a phone gets the steps for setting up from another device. Back from
  "Open on the device" keeps the kind, LAN Bypass and the name typed. The
  packet-size note under the kinds is gone
- The portal on phones keeps its place: nothing jumps when an access row
  opens or folds, a notice comes or goes, or Safari redraws the cards. A
  reload, or coming back from the VPN app, opens where the page was. Cards
  glide to their new height, and an animation interrupted half-way goes on
  from where it is instead of snapping. A double click no longer closes
  the sheet it just opened
- In the admin, a device's drawer has its own MTU and keep-alive (empty
  means the server's), each with a Change dialog. A change touches only
  that device's configuration and restarts nothing on the router. Opening
  the drawer no longer counts as handing out the configuration: "Update
  config" stays until the new configuration is shown as a QR code,
  downloaded or copied ("Show the new configuration"). New keys set the
  device up again, as the portal's Reconnect does
- "Speed now" on a server's Overview is live: one point a second over the
  last two minutes, all there as soon as the Overview opens. The agent
  keeps those two minutes in memory and writes them out only while someone
  is looking
- Disguise values that AmneziaWG refuses or crashes on are stopped before
  they reach the kernel. That covers overlapping H1-H4, Jmin above Jmax,
  broken I1-I5 tags, padding under 12 with header protection, and more.
  Import and restore refuse them. After a hand edit in uci, the server's
  tunnel stays down and Health and the service log say why and what to do.
  Errors are full sentences in the reader's language
- The header protection key no longer shows in the status that read-only
  users can see: the Server page says only that the key is set, and each
  device's configuration still has it. The server no longer turns off
  WireGuard's protection against handshake floods (devices keep
  DisableCookies). A device can't be added with a server's own key
- An AmneziaWG update whose kernel module can't be swapped (another
  AmneziaWG interface holds the old one) no longer fails. It is installed,
  the tunnels come back on the old module, and Health and Components say
  the update starts after a reboot. On apk firmware, an install that apk
  left at the old version counts as failed. A module installed by hand is
  recorded, so after a firmware upgrade Health can tell that it is gone
- Dawnline reads only its own tunnels, each one separately. Another
  AmneziaWG interface on the router no longer slows the agent's
  once-a-second check, has its keys read or breaks Dawnline's reads. A
  portal request reads only that person's server: one process however many
  servers there are
- Fewer false disconnects: a tunnel that netifd sets up again no longer
  logs everyone as leaving and coming back, and a device with a long
  keep-alive stays online between handshakes. One configuration on two
  devices isn't logged as roaming every few seconds, and new keys end the
  old session at once. A tunnel that is missing devices is synced within a
  minute, and traffic across a tunnel restart is no longer undercounted
- Renaming a server no longer restarts its tunnel. If a tunnel's interface
  is edited outside Dawnline (LuCI, uci), the watchdog sets it up again
  with Dawnline's settings and names only the changed options. The routing
  rules for "Internet like a home device" change one at a time, new ones
  first, so traffic never falls between them. Health and the Server page
  warn when the address's AAAA record isn't this router's, or the router
  has no public IPv6: devices that prefer IPv6 fail to connect
- The README screenshots come in English and Russian; the portal's are
  taken from its demo. The demo has a switch beside × in the set-up sheet
  to show each state of the connection line. In Russian, long labels in
  the admin's wide option buttons wrap under their icon. DESIGN.md
  describes the switch, renaming on the card, the shimmer, the shake and
  how the portal scrolls. New tests cover link states, the meter, access,
  Health, firewall rules, network settings and packages
2026-10-22 00:11:50 +03:00

587 lines
19 KiB
TypeScript

// luci.dawnline RPC bindings. The backend reports failures as { error }, and
// a change the router saved but could not fully put into effect (access rules
// that did not load, a server that refused its devices) as { warning }.
import type { Network, PortHold } from './netcheck';
import type {
AwgCaps,
AwgState,
Circle,
ClientConfig,
DayUsage,
HealthCheck,
LogEvent,
MeshMode,
Pair,
Person,
Status,
} from '../shared/types';
import { notify } from './ui/toast';
import { lang } from '../shared/i18n';
/** Throw a backend failure; show a warning the answer carries. */
function settle<T>(r: any): T {
if (r && typeof r === 'object') {
if (typeof r.error === 'string') throw new Error(r.error);
if (typeof r.warning === 'string' && r.warning) notify(r.warning, 'warning', 12000);
}
return r as T;
}
/**
* A method of luci.dawnline. The page's language goes last, after the
* method's own arguments: the router writes its messages in it.
*/
function call<T>(method: string, params: string[] = []) {
const fn = rpc.declare<any>({ object: 'luci.dawnline', method, params: [...params, 'lang'] });
return async (...args: unknown[]): Promise<T> => settle<T>(await fn(...params.map((_p, i) => args[i]), lang()));
}
export interface SetupDefaults {
id: string;
name: string;
ifname: string;
port: number;
subnet: string;
endpoint: string;
mtu: number;
zones: string[];
lan_zone: string;
wan_zone: string;
portal_port: number;
/** Networks the tunnel must not overlap: the router's and the other servers'. */
networks: Network[];
/** UDP ports the server can't take, TCP ports the portal can't. */
udp_taken: PortHold[];
tcp_taken: PortHold[];
awg: AwgCaps;
awg_state?: AwgState;
/** Where the suggested address came from: ddns, cert, wan, portal ('' = nothing found). */
endpoint_from?: string;
/** What the WAN's IPv4 is: public, private (behind another router), cgnat, none. */
wan_kind?: 'public' | 'private' | 'cgnat' | 'none';
wan_ip?: string | null;
}
/** Where a public address points (rpc endpoint_probe): the facts and their verdict in words. */
export interface EndpointProbe {
host: string;
ips: string[];
wan: string | null;
kind: 'public' | 'private' | 'cgnat' | 'none';
cloudflare: boolean;
here: boolean;
v6_only: boolean;
status: 'ok' | 'warn' | 'error';
text: string;
/** The router's public IPv6 addresses ([]: none; null: not read, the name has no IPv6). */
router6?: string[] | null;
/** The name's IPv6 addresses that are not the router's (null while router6 is). */
foreign6?: string[] | null;
/** The name has IPv6 and every address is the router's. */
here6?: boolean;
}
/** One second of the live meter: each server whose tunnel was read, [rx, tx] in bytes/s (rx = from devices, as Server.rate). */
export interface MeterPoint {
ts: number;
servers: Record<string, Pair>;
}
/**
* The live meter (rpc meter): each call keeps the router sampling for `want`
* seconds more; the first point comes about 2 s after the first call.
*/
export interface Meter {
/** Router time. */
now: number;
/** Seconds the router keeps sampling after a call. */
want: number;
/** Points it keeps: one a second, the last 2 minutes. */
keep: number;
/** The newest point's time (0: none yet); it stops moving when the agent does. */
ts: number;
/** Oldest first; only those newer than `since` when it was given. */
points: MeterPoint[];
}
/**
* A device's own link values for device_update; left out = kept. Numbers go as text: '' = the server's, keep-alive
* '0' = off. LAN Bypass stays as chosen when the device was added (the RPC takes it, the admin UI never changes it).
*/
export interface DeviceLinkPatch {
mtu?: string;
keepalive?: string;
}
export interface Backup {
name: string;
created: number;
size: number;
reason: string;
}
export type AwgSource = 'slava' | 'grey';
export interface UpdateComponent {
installed?: string | null;
latest?: string | null;
update?: boolean;
/** latest | outdated | dev (installed is newer than the release) | '' (unknown). */
status?: 'latest' | 'outdated' | 'dev' | '';
/** When this component was last checked. */
time?: number;
url?: string | null;
published?: string | null;
note?: string;
error?: string;
repo?: string;
tag?: string;
packages?: Record<string, string | null>;
// AmneziaWG: the installed build and both builds for this firmware
current?: AwgSource | null;
gen?: '2.0' | '3.1' | null;
ru?: boolean;
release?: string;
sources?: Partial<
Record<
AwgSource,
{
label: string;
repo: string;
tag: string;
version: string | null;
gen: '2.0' | '3.1' | null;
date: string | null;
newer?: { tag: string; gen: '3.1' };
}
>
>;
// OpenWrt packages Dawnline uses
pkgs?: Record<string, { installed: string | null; latest: string | null; with?: string[] }>;
updates?: number;
}
export interface UpdatesStatus {
version: string;
firmware?: { version: string; target: string; arch: string };
/** The personal portal is on: its HTTPS packages are listed too. */
portal?: boolean;
/** A server uses the home-like link. */
home?: boolean;
needs?: Needs;
check: { time: number; components: Record<string, UpdateComponent> } | null;
job: UpdateJob | null;
/** Router time, for the job timer. */
now: number;
repo: string;
policy: UpdatePolicy;
/** Automatic runs: the last check and the last scheduled install day. */
auto: { check?: number; install_day?: string };
/** The version kept for Roll back, per component. */
kept: Record<'app' | 'amneziawg', { version: string; build: AwgSource | null; saved: number | null } | null>;
/** Components → Activity, newest first. */
history: UpdateEvent[];
/** AmneziaWG interfaces (their Dawnline names): switching builds restarts them. */
tunnels: string[];
/** The admin's translations installed (luci-i18n-dawnline-<lang>): "ru". */
translations?: string[];
}
export interface UpdateEvent {
ts: number;
/** found: a check found updates; install: an update ran; error: a check or an update failed. */
kind: 'found' | 'install' | 'error';
auto?: boolean;
items?: string[];
component?: string | null;
from?: string | null;
to?: string | null;
state?: 'done' | 'failed';
error?: string | null;
took?: number;
}
export interface UpdateJob {
id: string;
action: string;
component: string | null;
state: 'running' | 'done' | 'failed';
started: number;
finished: number | null;
/** Started by Settings → Updates, not by a click. */
auto?: boolean;
phase: string;
from: string | null;
to: string | null;
log: string[];
error: string | null;
result: Record<string, any> | null;
}
/** Settings → Updates. */
export interface UpdatePolicy {
check: boolean;
interval: '6h' | '12h' | '1d' | '7d';
auto: boolean;
mode: 'immediate' | 'scheduled';
time: string;
targets: ('app' | 'amneziawg' | 'packages')[];
keep: boolean;
mirrors: boolean;
}
export interface Release {
tag: string;
name: string;
published: string | null;
prerelease: boolean;
url: string | null;
body: string | null;
assets: string[];
}
/** Missing packages by feature: the portal's HTTPS, ACME certificates, the home-like link, AmneziaWG itself. */
export interface Needs {
https: string[];
acme: string[];
home: string[];
/** amneziawg-tools and/or kmod-amneziawg (older backends leave it out). */
awg?: string[];
}
/** The slow part of the portal settings, loaded after the page shows. */
export interface PortalInfo {
/** Addresses the portal could use, found on the router. */
candidates: { host: string; kind: 'name' | 'ip'; ips: string[]; here: boolean; cloudflare: boolean; cert: boolean }[];
/** The portal's checks from Health. */
checks: HealthCheck[];
}
export interface SettingsData {
settings: Record<string, string>;
needs?: Needs;
effective: Record<string, unknown>;
services: { id: string; name: string; address: string; ports: string[] }[];
cert: { path: string; self_signed: boolean; expires: string | null } | null;
/** TCP ports the portal can't take. */
tcp_taken: PortHold[];
wan443_taken?: boolean;
portal_public_port?: number;
geo_cached: number;
logs: LogsInfo;
}
export type LogCategory = 'connections' | 'people' | 'problems';
export interface LogsInfo {
policy: {
keep_days: number;
max: number;
categories: LogCategory[];
persist: '10min' | 'hourly' | 'off';
usage_days: number;
usage_months: number;
};
events: number;
oldest: number;
by_category: Record<LogCategory, number>;
log_ram: number;
log_flash: number;
usage_flash: number;
usage_since: string;
usage_days: number;
geo_flash: number;
}
/** The path that makes tunnel clients' internet traffic enter from the LAN. */
export interface LikeHome {
active: boolean;
dev?: string;
address?: string;
dns?: string;
gateway?: string;
bridged?: boolean;
off?: boolean;
error?: string;
}
export type IfaceCategory = 'wan' | 'ethernet' | 'wifi' | 'vpn' | 'other';
export interface NetDevice {
name: string;
category: IfaceCategory;
kind: 'bridge' | IfaceCategory;
up: boolean;
master: string | null;
members: string[];
nets: string[];
addrs: string[];
logical: string | null;
proto: string | null;
zone: string | null;
/** The server's own tunnel interface. */
own?: boolean;
/** Part of the server's home network (auto = via Auto-detect LAN). */
home?: boolean;
auto?: boolean;
/** Saved but not present right now. */
missing?: boolean;
}
export interface InterfacesData {
server: string;
/** Packages the home-like link still needs. */
needs?: string[];
ifname: string;
detected: { wan: string | null; lan: string | null };
saved: { wan: string; lan: string };
config: {
auto_wan: boolean;
wan_device: string;
auto_lan: boolean;
lan_devices: string[];
lan_like: boolean;
device_mesh: boolean;
mesh: MeshMode;
};
like_home: LikeHome;
effective: {
wan: { dev: string | null; zone: string; auto: boolean; missing: boolean };
home: { dev: string; auto: boolean; nets: string[]; zone: string | null; missing: boolean }[];
nets: string[];
zones: string[];
};
zones: string[];
devices: NetDevice[];
/** People on this server with Home-only access (their AllowedIPs follow the home networks). */
lan_only: number;
nets_changed?: boolean;
}
/** "Check access": each rule on the way, in order; it stops at the first that fails. */
export interface AccessCheck {
ok: boolean;
steps: { ok: boolean; title: string; detail: string }[];
}
/** A device at home (DHCP lease or static host) and the services it announces over Bonjour. */
export interface HomeHost {
address: string;
name: string;
mac: string;
services: { type: string; name: string; port: number }[];
}
/** Filters for logs_clear; all empty clears the whole log. */
export interface LogFilter {
person?: string;
device?: string;
category?: string;
older_days?: string;
}
const logsClearRaw = call<{ removed: number }>('logs_clear', ['person', 'device', 'category', 'older_days']);
const logsClear = (f: LogFilter = {}) => logsClearRaw(f.person ?? '', f.device ?? '', f.category ?? '', f.older_days ?? '');
/** Fields for person_update; send strings ('' clears an optional value). */
export type PersonPatch = Partial<
Record<
| 'name'
| 'access'
| 'device_limit'
| 'expires'
| 'expire_action'
| 'expire_warn'
| 'quota_gb'
| 'quota_period'
| 'bonus_gb'
| 'hours'
| 'note'
| 'dns_mode'
| 'server',
string
>
> & { paused?: boolean; services?: string[]; circle?: string; home_nets?: string[] };
const personUpdateRaw = rpc.declare<any>({
object: 'luci.dawnline',
method: 'person_update',
params: [
'id',
'name',
'access',
'device_limit',
'expires',
'expire_action',
'expire_warn',
'quota_gb',
'quota_period',
'bonus_gb',
'hours',
'note',
'dns_mode',
'paused',
'services',
'circle',
'home_nets',
'server',
],
});
async function personUpdate(id: string, patch: PersonPatch): Promise<{ person: Person }> {
const keys = [
'name',
'access',
'device_limit',
'expires',
'expire_action',
'expire_warn',
'quota_gb',
'quota_period',
'bonus_gb',
'hours',
'note',
'dns_mode',
] as const;
const args: unknown[] = [id, ...keys.map((k) => patch[k]), patch.paused, patch.services, patch.circle, patch.home_nets, patch.server];
return settle(await personUpdateRaw(...args));
}
const status = call<Status>('status', ['days']);
const deviceUpdateRaw = call<unknown>('device_update', ['id', 'name', 'disabled', 'mtu', 'keepalive']);
/** Rename, turn off or on, or change how a device connects; what is undefined stays as it is. */
const deviceUpdate = (id: string, name?: string, disabled?: boolean, link: DeviceLinkPatch = {}) =>
deviceUpdateRaw(id, name, disabled, link.mtu, link.keepalive);
/** One line of the service log: tunnel and service starts, stops, watchdog repairs, errors. */
export interface ServiceLogEntry {
ts: number;
src: 'awg' | 'dawnline' | 'portal';
level: 'info' | 'up' | 'down' | 'repair' | 'error';
msg: string;
detail?: string;
/** Subject shown first: a server's name, "Personal portal", "Dawnline" (older entries have none). */
who?: string;
/** The admin's own changes read "You <msg> <kind> <who> · <note>". */
by?: 'admin';
kind?: string;
note?: string;
}
export interface ServiceLog {
watchdog: {
enabled: boolean;
/** Last watchdog pass and last agent tick (null: never). */
last: number | null;
beat: number | null;
now: number;
targets: { id: string; name: string; ok: boolean; tries: number }[];
/** Repairs in the last 24 hours; id is the Health check id. */
repairs: { ts: number; id: string; name: string }[];
};
log: ServiceLogEntry[];
}
export type Health = { checks: HealthCheck[] } & ServiceLog;
export const api = {
rev: call<{ rev: number; version?: string }>('rev'),
/** The live meter's points newer than `since` (0: all); polled while the Overview shows it. */
meter: call<Meter>('meter', ['since']),
personUpdate,
settingsGet: call<SettingsData>('settings_get'),
portalInfo: call<PortalInfo>('portal_info'),
settingsUpdate: call<SettingsData>('settings_update', ['values']),
serviceSet: call<{ id: string }>('service_set', ['id', 'name', 'address', 'ports']),
serviceDelete: call<unknown>('service_delete', ['id']),
geoClear: call<unknown>('geo_clear'),
/** The newest `limit` events; a person's only, or only those after `since` (a ts), when given. */
events: call<{ events: LogEvent[]; total: number; policy: LogsInfo['policy'] }>('events', ['limit', 'person', 'since']),
logsClear,
interfaces: call<InterfacesData>('interfaces', ['id']),
serverInterfaces: call<InterfacesData>('server_interfaces', [
'id',
'auto_wan',
'wan_device',
'auto_lan',
'lan_devices',
'lan_like',
'device_mesh',
'mesh',
]),
circleSet: call<{ id: string; circles: Circle[] }>('circle_set', ['id', 'server', 'name', 'color', 'members']),
circleDelete: call<{ circles: Circle[] }>('circle_delete', ['id']),
accessCheck: call<AccessCheck>('access_check', ['from', 'to']),
homeHosts: call<{ hosts: HomeHost[]; mdns: boolean }>('home_hosts', ['id']),
usageClear: call<unknown>('usage_clear', ['scope', 'id']),
uninstall: call<unknown>('uninstall', ['confirm']),
status,
setupDefaults: call<SetupDefaults>('setup_defaults'),
serverCreate: call<{ id: string; network_restart?: boolean }>('server_create', [
'id',
'name',
'ifname',
'port',
'subnet',
'endpoint',
'mtu',
'preset',
'lan_zone',
'wan_zone',
'lan_like',
'portal_enabled',
'portal_port',
]),
serverObfuscation: call<unknown>('server_obfuscation', ['id', 'preset']),
serverUpdate: call<unknown>('server_update', ['id', 'values']),
/** What an existing server's ports and a new tunnel network must avoid (checked as you type). */
serverPorts: call<{ udp_taken: PortHold[]; tcp_taken: PortHold[]; networks?: Network[] }>('server_ports', ['id']),
/** Where a public address points, for the live help under the field (debounced by the caller). */
endpointProbe: call<EndpointProbe>('endpoint_probe', ['host', 'id', 'port']),
serverDelete: call<unknown>('server_delete', ['id']),
/** The personal link, its code and every address it works on (main first); not part of the status. */
personLinks: call<{ code: string; link: string | null; links: string[] }>('person_links', ['id']),
personCreate: call<{ id: string; link: string | null }>('person_create', [
'name',
'slug',
'server',
'access',
'device_limit',
'expires',
'quota_gb',
'quota_period',
]),
personPause: call<unknown>('person_pause', ['id', 'paused']),
/** A new link; `remove` lists devices (ids) to take away with the old one. */
personRegen: call<{ link: string | null; removed: number }>('person_regen', ['id', 'remove']),
personDelete: call<unknown>('person_delete', ['id']),
personUsage: call<{ person: DayUsage[]; devices: Record<string, DayUsage[]> }>('person_usage', ['id', 'days']),
/** A new device; `lan_bypass` (true) keeps its own local network outside the tunnel. */
deviceCreate: call<{ id: string; config: ClientConfig }>('device_create', ['person', 'name', 'kind', 'lan_bypass']),
/** A device's configuration; `issue` (true) when it goes to the device as a code, a file or a key: only that clears "Update config". */
deviceConfig: call<ClientConfig>('device_config', ['id', 'issue']),
deviceUpdate,
deviceDelete: call<unknown>('device_delete', ['id']),
deviceRotate: call<ClientConfig>('device_rotate', ['id']),
apply: call<unknown>('apply'),
health: call<Health>('health'),
healthFix: call<Health>('health_fix', ['id']),
serviceLog: call<ServiceLog>('service_log'),
serviceLogClear: call<{ removed: number }>('service_log_clear', ['older_days']),
backupList: call<{ backups: Backup[] }>('backup_list'),
backupCreate: call<{ name: string }>('backup_create'),
backupRestore: call<unknown>('backup_restore', ['name']),
backupDelete: call<unknown>('backup_delete', ['name']),
backupRead: call<{ data: string }>('backup_read', ['name']),
backupUpload: call<unknown>('backup_upload', ['data']),
exportJson: call<Record<string, unknown>>('export'),
importJson: call<unknown>('import', ['data']),
updatesStatus: call<UpdatesStatus>('updates_status'),
updatesRun: call<{ started: boolean; job: UpdateJob | null }>('updates_run', ['what']),
updatesReleases: call<{ releases: Release[]; page: number }>('updates_releases', ['page']),
updatesNotes: call<Release & { repo: string }>('updates_notes', ['component', 'tag', 'build']),
updatesChanges: call<{ items: string[] }>('updates_changes', ['from', 'to']),
};