Files
dawnline/web/src/admin/events/model.ts
T
Aemeath dc0f159447
CI / ucode compiles and tests pass (OpenWrt 25.12) (push) Canceled after 0s
CI / ucode compiles and tests pass (OpenWrt 24.10) (push) Canceled after 0s
CI / ucode static checks (push) Canceled after 0s
CI / ShellCheck (push) Canceled after 0s
CI / Web (format, types, tests, bundles) (push) Canceled after 0s
Build packages / CI (push) Canceled after 0s
Build packages / Version (push) Canceled after 0s
Build packages / Build apk (push) Canceled after 0s
Build packages / Build ipk (push) Canceled after 0s
Build packages / Release (push) Canceled after 0s
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

302 lines
13 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// The activity log's vocabulary: categories, who did what, problems, retention.
// No DOM and no RPC here (see ./render for rows).
import type { LogEvent } from '../../shared/types';
import type { LogCategory, LogsInfo, ServiceLogEntry } from '../api';
import { fmt, known, plural } from '../../shared/i18n';
import { LOG_TEMPLATES } from './log-templates';
/** Mirrors CATEGORY in dawnline.live. */
const CATEGORY: Record<string, LogCategory> = {
connect: 'connections',
disconnect: 'connections',
roam: 'connections',
device_added: 'people',
device_removed: 'people',
devices_removed: 'people',
device_changed: 'people',
device_keys: 'people',
link_changed: 'people',
person_added: 'people',
person_removed: 'people',
person_changed: 'people',
paused: 'people',
resumed: 'people',
expiring: 'people',
expired_kept: 'people',
portal_blocked: 'problems',
device_failing: 'problems',
device_recovered: 'problems',
};
export const CATEGORIES: LogCategory[] = ['connections', 'people', 'problems'];
export function categoryLabel(c: LogCategory): string {
return { connections: _('Connections'), people: _('People'), problems: _('Problems') }[c];
}
export function categoryHelp(c: LogCategory): string {
return {
connections: _('Connects, disconnects and IP changes'),
people: _('People and their devices added, changed, paused, removed'),
problems: _('Blocked portal sign-ins and devices that can’t connect properly (tunnels and services are in the service log)'),
}[c];
}
export const categoryOf = (type: string): LogCategory => CATEGORY[type] ?? 'problems';
/** What a service log source is called; unknown ones by their id. */
export function sourceName(src: ServiceLogEntry['src']): string {
return { awg: 'AmneziaWG', dawnline: 'Dawnline', portal: _('Portal') }[src] ?? src;
}
const ADMIN_TYPES = ['person_added', 'person_removed', 'person_changed'];
/** Who did it. Older events have no `by`: LuCI and the portal marked it in the detail. */
export function eventBy(e: LogEvent): 'admin' | 'portal' | null {
if (e.by) return e.by;
if (ADMIN_TYPES.includes(e.type) || e.detail === 'by admin' || e.detail?.endsWith(' (admin)')) return 'admin';
if (e.detail?.endsWith(' (portal)')) return 'portal';
return null;
}
/** The detail without the old "(admin)" / "(portal)" / "by admin" marks. */
export function plainDetail(e: LogEvent): string {
return (e.detail ?? '').replace(/ \((admin|portal)\)$/, '').replace(/^by admin$/, '');
}
/** One line of the Log: an activity event or a service log entry. */
export type LogItem = { ts: number; ev?: LogEvent; sys?: ServiceLogEntry };
export const isProblem = (x: LogItem) =>
x.sys ? ['error', 'repair', 'down'].includes(x.sys.level) : categoryOf(x.ev!.type) === 'problems';
export function retentionText(p: LogsInfo['policy']): string {
const age = p.keep_days > 0 ? plural(p.keep_days, '%s day', '%s days') : _('no age limit');
const where =
p.persist === 'off'
? _('kept in memory only (lost on reboot)')
: p.persist === '10min'
? _('saved to flash every 10 minutes')
: _('saved to flash hourly');
return fmt(_('Kept for %s, %s, %s.'), age, plural(p.max, 'up to %s event', 'up to %s events'), where);
}
/* ---------- the router's words, put into the page's language ----------
* Events and service log lines are written once, in English, by whoever was
* running (the agent has no language) and read later in any language: the
* words below are their fixed vocabulary, translated when shown. Anything
* else stays as written. */
/** Why someone was paused or resumed (the agent's REASON words). */
export function reasonText(detail: string): string {
const t: Record<string, string> = {
'paused by admin': _('paused by admin'),
'end date reached': _('end date reached'),
'data limit reached': _('data limit reached'),
'outside allowed hours': _('outside allowed hours'),
'no server': _('no server'),
'server turned off': _('server turned off'),
};
return t[detail] ?? detail;
}
/** Days left in an "expiring" event's detail ("3 days"), or null. */
export function daysOf(detail: string): number | null {
const m = /^(\d+) days?$/.exec(detail);
return m ? Number(m[1]) : null;
}
/** The person's settings a person_changed event lists (option names, "moved to <server>"). */
export function changedText(detail: string): string {
const f: Record<string, string> = {
name: _('name'),
access: _('access'),
device_limit: _('device limit'),
expires: _('end date'),
expire_action: _('what happens at the end'),
expire_warn: _('warning before the end'),
quota_gb: _('data limit'),
quota_period: _('data limit period'),
bonus_gb: _('extra data'),
hours: _('allowed hours'),
dns_mode: _('DNS'),
paused: _('pause'),
services: _('home services'),
circle: _('circle', 'setting'),
home_nets: _('home networks'),
server: _('server'),
};
return detail
.split(', ')
.map((k) => {
const to = /^moved to (.+)$/.exec(k)?.[1];
return to ? fmt(_('moved to %s'), to) : (f[k] ?? k.replace(/_/g, ' '));
})
.join(', ');
}
/** A device's settings a device_changed event lists (its link options, "mtu, keepalive"); anything else as written. */
export function deviceChangedText(detail: string): string {
const f: Record<string, string> = { mtu: 'MTU', keepalive: _('keep-alive'), lan_bypass: _('LAN Bypass') };
return detail
.split(', ')
.map((k) => f[k] ?? k)
.join(', ');
}
/**
* A device's link failing in a named way (dawnline.link's states), said about
* the device: its title and what it means (the device drawer's Status, the
* title also in Activity). Null for a state this page does not know.
*/
export function linkStateText(state: string): { title: string; line: string } | null {
const t: Record<string, [string, string]> = {
trying: [_('Unable to complete the handshake'), _('The device’s network may be blocking the connection.')],
dropped: [_('Handshake complete, but no data'), _('This device is using an outdated configuration.')],
shared: [_('On two devices at once'), _('The same configuration connects from two places in turn. Give the other device its own.')],
unstable: [
_('Connection keeps dropping'),
_('It connects, but the connection breaks every few minutes: the network may be cutting it.'),
],
};
const w = t[state];
return w ? { title: w[0], line: w[1] } : null;
}
/** The states a device_failing event names ("trying, unstable" when two came within an hour), by their titles. */
export function linkStatesText(detail: string): string {
return detail
.split(', ')
.map((s) => linkStateText(s)?.title ?? s)
.join(', ');
}
/**
* The admin's own change in the service log ({ msg: 'changed', kind:
* 'server', who: 'Home' }), as one sentence: with %s for the name it names,
* or whole when the name is a fixed phrase ("the service log"); null for one
* this page does not know.
*/
export function adminSentence(msg: string, kind?: string | null, who?: string | null): { text: string; named: boolean } | null {
const fixed: Record<string, string> = {
'cleared|the service log': _('You cleared the service log'),
'cleared|the activity log': _('You cleared the activity log'),
'exported|all settings': _('You exported all settings'),
'imported|settings from a file': _('You imported settings from a file'),
'restored|from a file': _('You restored a backup from a file'),
'turned on|the personal portal': _('You turned on the personal portal'),
'turned off|the personal portal': _('You turned off the personal portal'),
'changed|the personal portal': _('You changed the personal portal'),
'turned on|the watchdog': _('You turned on the watchdog'),
'turned off|the watchdog': _('You turned off the watchdog'),
'reset traffic history|for everyone': _('You reset traffic history for everyone'),
};
const whole = fixed[`${msg}|${who ?? ''}`];
if (whole) return { text: whole, named: false };
const named: Record<string, string> = {
'created|server': _('You created server %s'),
'changed|server': _('You changed server %s'),
'removed|server': _('You removed server %s'),
'turned on|server': _('You turned on server %s'),
'turned off|server': _('You turned off server %s'),
'added|circle': _('You added circle %s'),
'changed|circle': _('You changed circle %s'),
'removed|circle': _('You removed circle %s'),
'restored|backup': _('You restored backup %s'),
};
const t = named[`${msg}|${kind ?? ''}`];
if (t) return { text: t, named: true };
// "reset traffic history" "for Anna": the name after "for".
const forWho = msg === 'reset traffic history' && /^for (.+)$/.exec(who ?? '')?.[1];
return forWho ? { text: _('You reset traffic history for %s'), named: true } : null;
}
/** The name in a sentence adminSentence() made with %s (its "for …" taken off). */
export const adminName = (msg: string, who: string) => (msg === 'reset traffic history' ? who.replace(/^for /, '') : who);
/** The note after an admin's change: its known pieces translated, the rest as written. */
export function noteText(note: string): string {
const one = (p: string): string => {
const t: Record<string, string> = {
'other addresses': _('other addresses'),
certificate: _('certificate'),
redirect: _('redirect'),
'devices kept apart': _('devices kept apart'),
'devices reach each other': _('devices reach each other'),
'devices reach each other in circles': _('devices reach each other in circles'),
'home network and internet path': _('home network and internet path'),
'the file holds private keys': _('the file holds private keys'),
'problems are only logged, nothing is repaired': _('problems are only logged, nothing is repaired'),
name: _('name'),
'public address': _('public address'),
'AmneziaWG port': _('AmneziaWG port'),
'tunnel network': _('tunnel network'),
connections: categoryLabel('connections'),
people: categoryLabel('people'),
problems: categoryLabel('problems'),
};
if (t[p]) return t[p];
let m: RegExpExecArray | null;
if ((m = /^port (\d+)$/.exec(p))) return fmt(_('port %s'), m[1]);
if ((m = /^address (.+)$/.exec(p))) return fmt(_('address %s'), m[1]);
if ((m = /^disguise: (.+)$/.exec(p))) return fmt(_('disguise: %s'), m[1]);
if ((m = /^(\d+) events?$/.exec(p))) return plural(Number(m[1]), '%s event', '%s events');
if ((m = /^older than (\d+) days$/.exec(p))) return plural(Number(m[1]), 'older than %s day', 'older than %s days');
if ((m = /^with (\d+) (person|people)$/.exec(p))) return plural(Number(m[1]), 'with %s person', 'with %s people');
if ((m = /^(\d+) entr(y|ies)( older than (\d+) days)?$/.exec(p)))
return m[4]
? `${plural(Number(m[1]), '%s entry', '%s entries')}, ${plural(Number(m[4]), 'older than %s day', 'older than %s days')}`
: plural(Number(m[1]), '%s entry', '%s entries');
return p;
};
return note
.split(' · ')
.map((part) => part.split(', ').map(one).join(', '))
.join(' · ');
}
/* ---------- the service log's lines ----------
* The router writes them in English from its L_() templates (the generated
* list in ./log-templates); a line is put into the page's language by the
* template it matches, its values (versions, ports, names, or another
* template's words) put back in place. Lines written before the plain dash
* have "—" where the templates have "-". */
let patterns: { t: string; re: RegExp }[] | null = null;
const LOG_EXACT = new Set(LOG_TEMPLATES);
/** The templates with values in them, the most specific (most fixed text) first. */
function logPatterns() {
return (patterns ??= LOG_TEMPLATES.filter((t) => /%[sd]/.test(t) && t.replace(/%[sd]/g, '').trim())
.map((t) => ({
t,
fixed: t.replace(/%[sd]/g, '').length,
re: new RegExp(
`^${t
.split(/(%[sd])/)
.map((p) => (p === '%s' ? '(.+?)' : p === '%d' ? '(\\d+)' : p.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')))
.join('')}$`,
),
}))
.sort((a, b) => b.fixed - a.fixed));
}
/** A service log line (or its subject, or a line of its details) in the page's language; one it does not know as written. */
export function logText(line: string, depth = 0): string {
const s = line.replace(/ — /g, ' - ');
if (LOG_EXACT.has(s)) return known(s);
if (depth > 2) return line;
for (const p of logPatterns()) {
const m = p.re.exec(s);
if (m) return fmt(known(p.t), ...m.slice(1).map((v) => logText(v, depth + 1)));
}
// A list ("Dawnline 0.3.3, 2 system packages"): each item on its own.
return s.includes(', ')
? s
.split(', ')
.map((x) => logText(x, depth + 1))
.join(', ')
: line;
}