Dawnline 0.11.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
- Russian translation. The admin pages, the LuCI menu and the router's messages (errors, Health checks, update steps, the service log) come in Russian with the new luci-i18n-dawnline-ru package, released beside the app. LuCI shows it when its language is Russian, or "auto" with a Russian browser - The translation installs with install.sh when LuCI is in Russian (or with --lang ru), follows every Dawnline update and rollback, and can be added or removed in Components → Dawnline → Translation - The portal speaks the visitor's language: it opens in the system's language and switches between English and Russian in place, from the language pill beside its QR code. It carries its own translation and needs no package - Set-up steps quote the apps' own menus word for word, in Russian too: AmneziaVPN is "+ → Insert → Continue" (it has no "Add server"), and the Mac and Windows menus of WireGuard and AmneziaWG have their real names - Questions in the portal (Reconnect, Remove) read from the left edge and close with Cancel, without × - Numbers, sizes and dates follow the page's language. A server that can't start says why in one sentence; event details and service log lines read as whole sentences - README in Russian (README_ru.md). rules/i18n.md: how strings are written and translated; CI checks the catalogs (npm run i18n:check)
This commit is contained in:
1 parent
caed976e63
commit
2f2aaf6c34
173 files changed
+25645
-2823
No files matched your search
+132
-89
@@ -1,12 +1,14 @@
|
||||
// Log rows: an activity event as a sentence ("You added device Phone for
|
||||
// Myata"), its tile and time, and a service log line.
|
||||
// Myata", one translated sentence per event with the names in it), its tile
|
||||
// and time, and a service log line (its text comes from the router).
|
||||
|
||||
import type { LogEvent, Status } from '../../shared/types';
|
||||
import type { ServiceLogEntry } from '../api';
|
||||
import { E } from '../e';
|
||||
import { icon } from '../../shared/icons';
|
||||
import { ago } from '../../shared/format';
|
||||
import { SYSTEM_SOURCE, eventBy, plainDetail } from './model';
|
||||
import { ago, fmtDay } from '../../shared/format';
|
||||
import { fill, fmt, locale, num } from '../../shared/i18n';
|
||||
import { adminName, adminSentence, changedText, daysOf, eventBy, logText, noteText, plainDetail, reasonText, sourceName } from './model';
|
||||
|
||||
/** What the people and servers in the log are called now. */
|
||||
export type Names = Pick<Status, 'people' | 'servers'>;
|
||||
@@ -49,6 +51,9 @@ function eventIcon(st: Names, e: LogEvent): string {
|
||||
return EVENT_ICON[e.type] ?? 'activity';
|
||||
}
|
||||
|
||||
/** A router day (YYYY-MM-DD) in the page's language; anything else as it came. */
|
||||
const routerDay = (s: string) => (/^\d{4}-\d{2}-\d{2}$/.test(s) ? fmtDay(s) : s);
|
||||
|
||||
export function eventText(st: Pick<Status, 'people'>, e: LogEvent): Node[] {
|
||||
const person = st.people.find((p) => p.id === e.person);
|
||||
const who = person?.name ?? e.pname ?? e.person ?? '';
|
||||
@@ -61,101 +66,97 @@ export function eventText(st: Pick<Status, 'people'>, e: LogEvent): Node[] {
|
||||
e.hosts?.[ip]
|
||||
? [E('span', { class: 'dl-ev-host' }, [E('b', {}, e.hosts[ip]), E('span', { class: 'dl-faint' }, ` (${ip})`)])]
|
||||
: [mono(ip)];
|
||||
// What the bold name is (a person, a device), said before it in grey.
|
||||
const kind = (t: string) => E('span', { class: 'dl-ev-kind' }, `${t} `);
|
||||
const wd = dev ? `${who} · ${dev}` : who;
|
||||
const detail = plainDetail(e);
|
||||
const devName = detail || dev || 'a device';
|
||||
// A sentence in grey around its bold names, people and devices.
|
||||
const say = (s: string, ...args: Node[]): Node[] => fill(s, ...args).map((x) => (typeof x === 'string' ? m(x) : x));
|
||||
// The admin's own actions start with an accent "You".
|
||||
const you = (verb: string) => [E('span', { class: 'dl-you' }, 'You'), m(` ${verb} `)];
|
||||
if (eventBy(e) === 'admin')
|
||||
const you = (s: string, ...args: Node[]): Node[] => {
|
||||
const w = _('You');
|
||||
return s.startsWith(`${w} `) ? [E('span', { class: 'dl-you' }, w), ...say(s.slice(w.length), ...args)] : say(s, ...args);
|
||||
};
|
||||
const wd = b(dev ? `${who} · ${dev}` : who);
|
||||
const detail = plainDetail(e);
|
||||
const devName = b(detail || dev || _('a device'));
|
||||
const by = eventBy(e);
|
||||
if (by === 'admin')
|
||||
switch (e.type) {
|
||||
case 'device_added':
|
||||
return [...you('added'), kind('device'), b(devName), m(' for '), b(who)];
|
||||
return you(_('You added device %s for %s'), devName, b(who));
|
||||
case 'device_removed':
|
||||
return [...you('removed'), kind('device'), b(devName), m(' from '), b(who)];
|
||||
return you(_('You removed device %s from %s'), devName, b(who));
|
||||
case 'paused':
|
||||
return [...you('paused'), kind('person'), b(who)];
|
||||
return you(_('You paused person %s'), b(who));
|
||||
case 'resumed':
|
||||
return [...you('resumed'), kind('person'), b(who)];
|
||||
return you(_('You resumed person %s'), b(who));
|
||||
case 'device_changed': {
|
||||
const renamed = detail.startsWith('renamed from ');
|
||||
return [
|
||||
...you(renamed ? 'renamed' : detail),
|
||||
kind('device'),
|
||||
b(dev || 'a device'),
|
||||
m(' of '),
|
||||
b(who),
|
||||
...(renamed ? [m(` · was ${detail.slice(13)}`)] : []),
|
||||
];
|
||||
const d = b(dev || _('a device'));
|
||||
if (detail.startsWith('renamed from '))
|
||||
return [...you(_('You renamed device %s of %s'), d, b(who)), m(` · ${fmt(_('was %s'), detail.slice(13))}`)];
|
||||
if (detail === 'turned off') return you(_('You turned off device %s of %s'), d, b(who));
|
||||
if (detail === 'turned on') return you(_('You turned on device %s of %s'), d, b(who));
|
||||
return [...you(_('You changed device %s of %s'), d, b(who)), ...(detail ? [m(` · ${detail}`)] : [])];
|
||||
}
|
||||
case 'device_keys':
|
||||
return [...you('issued new keys for'), kind('device'), b(devName), m(' of '), b(who), m(' · it needs its new configuration')];
|
||||
return [...you(_('You issued new keys for device %s of %s'), devName, b(who)), m(` · ${_('it needs its new configuration')}`)];
|
||||
case 'link_changed':
|
||||
return [...you('issued a new link for'), kind('person'), b(who), m(' · the old link stopped working')];
|
||||
return [...you(_('You issued a new link for person %s'), b(who)), m(` · ${_('the old link stopped working')}`)];
|
||||
}
|
||||
switch (e.type) {
|
||||
case 'connect':
|
||||
return [
|
||||
kind('Device'),
|
||||
b(wd),
|
||||
m(' connected'),
|
||||
...(e.detail ? [m(' from '), ...addr(e.detail)] : []),
|
||||
...(e.detail ? say(_('Device %s connected from %s'), wd, E('span', {}, addr(e.detail))) : say(_('Device %s connected'), wd)),
|
||||
...(e.where ? [m(` · ${e.where}`)] : []),
|
||||
];
|
||||
case 'disconnect':
|
||||
return [kind('Device'), b(wd), m(' went offline')];
|
||||
return say(_('Device %s went offline'), wd);
|
||||
case 'roam':
|
||||
return [
|
||||
kind('Device'),
|
||||
b(wd),
|
||||
m(' changed network '),
|
||||
...(e.detail ?? '').split(' → ').flatMap((ip, i) => (i ? [m(' → '), ...addr(ip)] : addr(ip))),
|
||||
];
|
||||
return say(
|
||||
_('Device %s changed network %s'),
|
||||
wd,
|
||||
E(
|
||||
'span',
|
||||
{},
|
||||
(e.detail ?? '').split(' → ').flatMap((ip, i) => (i ? [m(' → '), ...addr(ip)] : addr(ip))),
|
||||
),
|
||||
);
|
||||
case 'device_added':
|
||||
return [
|
||||
kind('Person'),
|
||||
b(who),
|
||||
m(' added '),
|
||||
kind('device'),
|
||||
b(devName),
|
||||
...(eventBy(e) === 'portal' ? [m(' on their portal')] : []),
|
||||
];
|
||||
return by === 'portal'
|
||||
? say(_('Person %s added device %s on their portal'), b(who), devName)
|
||||
: say(_('Person %s added device %s'), b(who), devName);
|
||||
case 'device_removed':
|
||||
return [
|
||||
kind('Person'),
|
||||
b(who),
|
||||
m(' removed '),
|
||||
kind('device'),
|
||||
b(devName),
|
||||
...(eventBy(e) === 'portal' ? [m(' on their portal')] : []),
|
||||
];
|
||||
return by === 'portal'
|
||||
? say(_('Person %s removed device %s on their portal'), b(who), devName)
|
||||
: say(_('Person %s removed device %s'), b(who), devName);
|
||||
case 'device_keys':
|
||||
return [kind('Person'), b(who), m(' issued new keys for '), kind('device'), b(devName), m(' on their portal')];
|
||||
return say(_('Person %s issued new keys for device %s on their portal'), b(who), devName);
|
||||
case 'person_added':
|
||||
return [...you('added'), kind('person'), b(e.detail ?? who)];
|
||||
return you(_('You added person %s'), b(e.detail ?? who));
|
||||
case 'person_removed':
|
||||
return [...you('removed'), kind('person'), b(e.detail ?? who)];
|
||||
return you(_('You removed person %s'), b(e.detail ?? who));
|
||||
case 'person_changed':
|
||||
// The detail lists changed fields by their option names (device_limit, expire_action).
|
||||
return [...you('changed'), kind('person'), b(who), ...(detail ? [m(` · ${detail.replace(/_/g, ' ')}`)] : [])];
|
||||
case 'expiring':
|
||||
return [kind('Person'), b(who), m(`’s access ends in ${e.detail ?? 'a few days'}`)];
|
||||
return [...you(_('You changed person %s'), b(who)), ...(detail ? [m(` · ${changedText(detail)}`)] : [])];
|
||||
case 'expiring': {
|
||||
const n = daysOf(e.detail ?? '');
|
||||
return n != null
|
||||
? say(N_(n, 'Person %s’s access ends in %s day', 'Person %s’s access ends in %s days'), b(who), m(num(n)))
|
||||
: say(_('Person %s’s access ends in a few days'), b(who));
|
||||
}
|
||||
case 'expired_kept':
|
||||
return [kind('Person'), b(who), m(`’s end date passed (${e.detail ?? ''}) · access kept`)];
|
||||
return say(_('Person %s’s end date passed (%s) · access kept'), b(who), m(routerDay(e.detail ?? '')));
|
||||
case 'paused':
|
||||
return [kind('Person'), b(who), m(` paused — ${e.detail ?? ''}`)];
|
||||
return e.detail ? say(_('Person %s paused - %s'), b(who), m(reasonText(e.detail))) : say(_('Person %s paused'), b(who));
|
||||
case 'resumed':
|
||||
return [kind('Person'), b(who), m(' resumed'), ...(e.detail && e.detail !== 'active' ? [m(` — ${e.detail}`)] : [])];
|
||||
return e.detail && e.detail !== 'active'
|
||||
? say(_('Person %s resumed - %s'), b(who), m(reasonText(e.detail)))
|
||||
: say(_('Person %s resumed'), b(who));
|
||||
case 'portal_blocked':
|
||||
return [
|
||||
E('b', { class: 'dl-sys-src' }, 'Personal portal'),
|
||||
m(' blocked '),
|
||||
mono(e.detail ?? ''),
|
||||
m(' for 15 min after too many wrong codes'),
|
||||
];
|
||||
return say(
|
||||
_('%s blocked %s for 15 min after too many wrong codes'),
|
||||
E('b', { class: 'dl-sys-src' }, _('Personal portal')),
|
||||
e.detail === 'all Cloudflare visitors' ? m(_('all Cloudflare visitors')) : mono(e.detail ?? ''),
|
||||
);
|
||||
case 'devices_removed':
|
||||
return [kind('Person'), b(who), m(' — all devices removed, end date reached')];
|
||||
return say(_('Person %s - all devices removed, end date reached'), b(who));
|
||||
default:
|
||||
return [m(`${e.type}${e.detail ? `: ${e.detail}` : ''}`)];
|
||||
}
|
||||
@@ -171,7 +172,7 @@ function serverPill(st: Names, e: LogEvent): HTMLElement | '' {
|
||||
if (st.servers.length < 2 || !e.person) return '';
|
||||
const p = st.people.find((x) => x.id === e.person);
|
||||
const srv = p && st.servers.find((s) => s.id === p.server);
|
||||
return srv ? E('span', { class: 'dl-ev-srv', title: 'Server' }, srv.name) : '';
|
||||
return srv ? E('span', { class: 'dl-ev-srv', title: _('Server') }, srv.name) : '';
|
||||
}
|
||||
|
||||
/** An activity event as a row; `time` replaces the "5 min ago" (`now` is the router's clock). */
|
||||
@@ -180,13 +181,13 @@ export function eventRow(st: Names & { now?: number }, e: LogEvent, opts: { serv
|
||||
const by = eventBy(e);
|
||||
return E('div', { class: `dl-row${by === 'admin' ? ' dl-ev-by-admin' : sys ? ` dl-ev-by-system ${sys[1]}` : ''}` }, [
|
||||
by === 'admin'
|
||||
? E('span', { class: 'dl-ev-tile', title: 'Done by you in LuCI' }, icon('admin'))
|
||||
? E('span', { class: 'dl-ev-tile', title: _('Done by you in LuCI') }, icon('admin'))
|
||||
: sys
|
||||
? E('span', { class: 'dl-ev-tile sys' }, icon(sys[0]))
|
||||
: E('span', { class: `dl-ev-tile ev ${EVENT_TONE[e.type] ?? ''}` }, icon(eventIcon(st, e))),
|
||||
E('span', { class: 'dl-row-main' }, eventText(st, e)),
|
||||
opts.server === false ? '' : serverPill(st, e),
|
||||
E('span', { class: 'dl-faint dl-nowrap', title: new Date(e.ts * 1000).toLocaleString() }, opts.time ?? ago(e.ts, st.now)),
|
||||
E('span', { class: 'dl-faint dl-nowrap', title: new Date(e.ts * 1000).toLocaleString(locale()) }, opts.time ?? ago(e.ts, st.now)),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -195,9 +196,47 @@ export function eventRow(st: Names & { now?: number }, e: LogEvent, opts: { serv
|
||||
const SYS_TONE: Record<ServiceLogEntry['level'], string> = { info: '', up: 'ok', down: 'warn', repair: 'warn', error: 'bad' };
|
||||
const SYS_ICON: Record<ServiceLogEntry['src'], string> = { awg: 'tunnel', dawnline: 'sunrise', portal: 'globe' };
|
||||
|
||||
/** A service log level as its tile's tooltip says it. */
|
||||
function levelLabel(l: ServiceLogEntry['level']): string {
|
||||
return { info: _('info'), up: _('up'), down: _('down'), repair: _('repair'), error: _('error') }[l] ?? l;
|
||||
}
|
||||
|
||||
/**
|
||||
* The admin's own change: "You changed server Home" as one sentence of the
|
||||
* page's language, "You" in the accent; one this page does not know is put
|
||||
* together from the router's words as before.
|
||||
*/
|
||||
function adminLine(e: ServiceLogEntry): (Node | string)[] {
|
||||
const s = adminSentence(e.msg, e.kind, e.who);
|
||||
const you = _('You');
|
||||
if (!s)
|
||||
return [
|
||||
E('span', { class: 'dl-you' }, you),
|
||||
E('span', { class: 'dl-muted' }, ` ${e.msg} `),
|
||||
e.kind ? E('span', { class: 'dl-ev-kind' }, `${e.kind} `) : '',
|
||||
e.who ? E('b', {}, e.who) : '',
|
||||
];
|
||||
const parts = (s.named ? fill<Node | string>(s.text, E('b', {}, adminName(e.msg, e.who ?? ''))) : [s.text]).map((x) =>
|
||||
typeof x === 'string' ? E('span', { class: 'dl-muted' }, x) : x,
|
||||
);
|
||||
// The accent on "You" where the sentence starts with it.
|
||||
const first = parts[0]?.textContent ?? '';
|
||||
return first.startsWith(`${you} `)
|
||||
? [E('span', { class: 'dl-you' }, you), E('span', { class: 'dl-muted' }, first.slice(you.length)), ...parts.slice(1)]
|
||||
: parts;
|
||||
}
|
||||
|
||||
/** A log line's details: its sentences in the page's language, command output as it is. */
|
||||
const detailText = (d: string) =>
|
||||
d
|
||||
.split('\n')
|
||||
.map((l) => logText(l))
|
||||
.join('\n');
|
||||
|
||||
/** A service log line: source, message, folded details; click to unfold. */
|
||||
export function systemRow(e: ServiceLogEntry, open: boolean, toggle: () => void, time: string): HTMLElement {
|
||||
const admin = e.by === 'admin';
|
||||
const msg = logText(e.msg);
|
||||
const row = E(
|
||||
'div',
|
||||
{
|
||||
@@ -205,32 +244,35 @@ export function systemRow(e: ServiceLogEntry, open: boolean, toggle: () => void,
|
||||
},
|
||||
[
|
||||
admin
|
||||
? E('span', { class: 'dl-ev-tile', title: 'Done by you in LuCI' }, icon('admin'))
|
||||
: E('span', { class: 'dl-ev-tile sys', title: e.level }, icon(SYS_ICON[e.src] ?? 'zap')),
|
||||
? E('span', { class: 'dl-ev-tile', title: _('Done by you in LuCI') }, icon('admin'))
|
||||
: E('span', { class: 'dl-ev-tile sys', title: levelLabel(e.level) }, icon(SYS_ICON[e.src] ?? 'zap')),
|
||||
E(
|
||||
'span',
|
||||
{ class: 'dl-row-main' },
|
||||
admin
|
||||
? [
|
||||
E('span', { class: 'dl-you' }, 'You'),
|
||||
E('span', { class: 'dl-muted' }, ` ${e.msg} `),
|
||||
e.kind ? E('span', { class: 'dl-ev-kind' }, `${e.kind} `) : '',
|
||||
e.who ? E('b', {}, e.who) : '',
|
||||
e.note ? E('span', { class: 'dl-muted' }, ` · ${e.note}`) : '',
|
||||
...adminLine(e),
|
||||
e.note ? E('span', { class: 'dl-muted' }, ` · ${noteText(e.note)}`) : '',
|
||||
e.detail ? E('span', { class: `dl-slog-more${open ? ' open' : ''}` }, icon('chevron')) : '',
|
||||
e.detail && open ? E('pre', { class: 'dl-slog-detail' }, e.detail) : '',
|
||||
e.detail && open ? E('pre', { class: 'dl-slog-detail' }, detailText(e.detail)) : '',
|
||||
]
|
||||
: [
|
||||
// Servers have names people chose: say it is a server. Services name themselves.
|
||||
e.src === 'awg' && e.who && e.who !== 'AmneziaWG' ? E('span', { class: 'dl-ev-kind' }, 'Server ') : '',
|
||||
E('b', { class: 'dl-sys-src', title: SYSTEM_SOURCE[e.src] ?? e.src }, e.who ?? SYSTEM_SOURCE[e.src] ?? e.src),
|
||||
' ',
|
||||
E('span', { class: 'dl-muted' }, e.msg),
|
||||
e.src === 'awg' && e.who && e.who !== 'AmneziaWG' ? E('span', { class: 'dl-ev-kind' }, `${_('Server')} `) : '',
|
||||
// A server's name as it is; Dawnline's own subjects ("Access rules") in the page's language.
|
||||
E(
|
||||
'b',
|
||||
{ class: 'dl-sys-src', title: sourceName(e.src) },
|
||||
e.who ? (e.src === 'awg' ? e.who : logText(e.who)) : sourceName(e.src),
|
||||
),
|
||||
// A translation may go on from the subject with a colon ("Home: AmneziaWG isn't running").
|
||||
/^[:,]/.test(msg) ? '' : ' ',
|
||||
E('span', { class: 'dl-muted' }, msg),
|
||||
e.detail ? E('span', { class: `dl-slog-more${open ? ' open' : ''}` }, icon('chevron')) : '',
|
||||
e.detail && open ? E('pre', { class: 'dl-slog-detail' }, e.detail) : '',
|
||||
e.detail && open ? E('pre', { class: 'dl-slog-detail' }, detailText(e.detail)) : '',
|
||||
],
|
||||
),
|
||||
E('span', { class: 'dl-faint dl-nowrap', title: new Date(e.ts * 1000).toLocaleString() }, time),
|
||||
E('span', { class: 'dl-faint dl-nowrap', title: new Date(e.ts * 1000).toLocaleString(locale()) }, time),
|
||||
],
|
||||
);
|
||||
if (e.detail)
|
||||
@@ -240,13 +282,14 @@ export function systemRow(e: ServiceLogEntry, open: boolean, toggle: () => void,
|
||||
return row;
|
||||
}
|
||||
|
||||
/** "Today", "Yesterday" or "Monday 12 October". */
|
||||
/** "Today", "Yesterday" or "Monday 12 October" (capitalised: Russian names weekdays in lower case). */
|
||||
export function dayTitle(ts: number): string {
|
||||
const d = new Date(ts * 1000);
|
||||
const today = new Date();
|
||||
const y = new Date();
|
||||
y.setDate(today.getDate() - 1);
|
||||
if (d.toDateString() === today.toDateString()) return 'Today';
|
||||
if (d.toDateString() === y.toDateString()) return 'Yesterday';
|
||||
return d.toLocaleDateString('en-GB', { weekday: 'long', day: 'numeric', month: 'long' });
|
||||
if (d.toDateString() === today.toDateString()) return _('Today');
|
||||
if (d.toDateString() === y.toDateString()) return _('Yesterday');
|
||||
const t = d.toLocaleDateString(locale(), { weekday: 'long', day: 'numeric', month: 'long' });
|
||||
return t.charAt(0).toLocaleUpperCase(locale()) + t.slice(1);
|
||||
}
|
||||
Reference in new issue
Block a user