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
- Every field says what is wrong as you type, in the router's own words,
and Save refuses what the router would: UDP port when editing a server,
MTU, keep-alive, public address, DNS for devices, person name, device
limit, end date and data limit, device names (the next free "Phone 2"
is offered), home services, circles, portal title, redirect and other
addresses, defaults, update time
- Cyrillic names give Latin ids, hostnames and file names; names are
counted in characters, the rule names the characters it refuses; end
dates must exist on the calendar; a mistyped extra portal address is
refused instead of dropped
- The public address is checked on the router as it is typed: points at
this router, at another address, behind Cloudflare, or the WAN is
private or CGNAT; the wizard says so before the first step, never
pre-fills a private WAN address and says where its suggestion came
from; the Connection card says when the server was last reached from
the internet; IPv6 names and literals work throughout
- A person can be moved to another server from their page; a server's
tunnel network can be changed in the Danger zone (devices are
renumbered and marked "Update config"); WAN and LAN zones come from the
router's actual devices; when the public IPv4 changed, one click puts
the new one in
- Over the data limit or outside the allowed hours the tunnel stays
connected and the portal explains why nothing gets through, instead of
a silent handshake failure; Health's "devices loaded" compares the
peers themselves, not their count
- Portal: install links for this platform, two first steps on a first
visit, the phone's back button closes a sheet, the file goes through
the share sheet into the app, two QR codes (AmneziaVPN camera, AmneziaWG
and WireGuard apps), the sheet notices the first connection
- Admin: Enter submits a dialog, arrow keys walk the menus, Find in People
("/" focuses it), a device of a paused, ended or over-limit person says
so, "Keep access" past its end date is said on the Overview, Allowed
hours enforce nothing until saved, the invite card shares the link
- Health warns when another package's policy routing (mwan3, pbr) sends
tunnel traffic past the home-device path
- CLI: person ls, device ls, log with -n, --since, --level, --src and
--json; exit code 2 for an unknown command and 1 when health finds an
error; person rm asks for --yes when devices would go; devices added
from the command line get their event and "issued" marker like the
UI's
- Three disguises: Off, Balanced and Maximum. Standard and Strong (1.0-style
junk only, which networks learned to spot) are no longer offered; a server
still on one keeps running and its card says to switch. A new server gets
the strongest disguise its router can run
- Portal: setting up a device is one sheet with two steps. Get the app
(AmneziaVPN first; AmneziaWG, and WireGuard with the disguise off, behind
"Another app") from the store of the device in hand, with the GitHub release
where no store has it and the version the server needs said once; then add
the connection (open in AmneziaVPN, copy the key, share or download the
file). A device set up from another device gets its link to take there, as a
QR code for a phone; a phone set up from a computer also gets the connection
as a code, one code revealed at a time so the camera cannot read the wrong one
- Portal motion: the first visit comes in once (blocks in reading order,
meters fill, the sun rises in the logo); a repaint glides cards to their
new places and brings changed values into focus; sheets slide up on
phones and can be pulled down, come into focus on a computer, follow
their content's height and turn into the next sheet in place; tabs and
segments slide, menus, tooltips and toasts grow out of what opened them,
copy buttons turn into a check, buttons waiting for the router spin;
with reduced motion only the fades remain
- Portal: while a device is set up, a card at the top shows the way from
it to the router with a light running along it; on the first connection
the way fills green, the steps fold away and the sheet closes by itself.
The first connection is the first fresh handshake, so it is no longer
missed while the watcher catches up (or after new keys), and the device's
card goes on to Connected
- Portal: QR codes are light dots on a black card, fuller on dense keys,
with "Show a light code" for scanners that read only dark on light (every
code switches, the choice is kept); the link and code a set-up sheet
hands to another device open that device's set-up there at once
- Portal: Remove and New keys ask in a small alert with the action's icon;
the open one of two cards is not a button; device names are no longer
repeated in every line of the set-up sheet; the code card lines up with
the rest of its card (a class clash gave it the page's padding); text
keeps the arrow cursor, store badges and link buttons are not underlined
435 lines
18 KiB
TypeScript
435 lines
18 KiB
TypeScript
// A server's Overview section (first tab on the Servers page): who is
|
||
// online, traffic, disguise, the connection map, activity and what needs
|
||
// attention — all limited to the people on that server.
|
||
|
||
import type { Device, Person, Status } from '../../shared/types';
|
||
import { E } from '../e';
|
||
import { api } from '../api';
|
||
import { svg } from '../ui/layout';
|
||
import { attachTip } from '../ui/tooltip';
|
||
import { icon } from '../../shared/icons';
|
||
import { ago, bits, bytes, date, daysLeft, endsIn, endsSoon, initials, todayOf } from '../../shared/format';
|
||
import { ConnectionMap, rangeControl, type Range } from '../map';
|
||
import { personUrl } from '../urls';
|
||
import { eventRow } from '../events/render';
|
||
import { scoped } from '../state/scope';
|
||
import { repaint } from '../state/poller';
|
||
import { daysTile, speedTile } from '../widgets/tiles';
|
||
import { coreOf } from '../cores';
|
||
import { healthNotices, runFix } from '../widgets/health';
|
||
import { attempt } from '../ui/toast';
|
||
import { isIpv4 } from '../netcheck';
|
||
import { onNavigate } from '../ui/nav';
|
||
|
||
interface Attention {
|
||
tone: string;
|
||
text: (Node | string)[];
|
||
/** A button or link that deals with it. */
|
||
action?: Node;
|
||
}
|
||
|
||
/** Things worth the admin's attention, most important first. */
|
||
function attention(st: Status): Attention[] {
|
||
const out: Attention[] = [];
|
||
const link = (href: string, t: string) => E('a', { href }, t);
|
||
const today = todayOf(st.series);
|
||
// AmneziaWG itself can't run: the health notice says so once, not "Tunnel down" for every server.
|
||
const awg = !!st.awg_state && !st.awg_state.ok;
|
||
for (const s of st.servers)
|
||
if (s.enabled && s.blocked)
|
||
// The reason, not just "down": its interface name is taken by a network section Dawnline didn't make.
|
||
out.push({ tone: 'bad', text: [`${s.name} ${s.blocked}. `, link(L.url('admin/network/dawnline/diagnostics'), 'Open Diagnostics')] });
|
||
else if (s.enabled && !s.up && !awg)
|
||
out.push({
|
||
tone: 'bad',
|
||
text: [`Tunnel ${s.ifname} is down. `, link(L.url('admin/network/dawnline/diagnostics'), 'Open Diagnostics')],
|
||
});
|
||
for (const p of st.people) {
|
||
if (p.state === 'quota') out.push({ tone: 'warn', text: [link(personUrl(p.id), p.name), ' reached the data limit.'] });
|
||
else if (p.state === 'expired') out.push({ tone: 'warn', text: [link(personUrl(p.id), p.name), '’s access has ended.'] });
|
||
else {
|
||
const left = daysLeft(p.expires, today);
|
||
if (endsSoon(p, left)) out.push({ tone: '', text: [link(personUrl(p.id), p.name), `’s access ${endsIn(left as number)}.`] });
|
||
// "Keep access" at the end date: nothing changes on its own, so it is said here.
|
||
else if (left != null && left < 0 && p.expire_action === 'notify')
|
||
out.push({ tone: '', text: [link(personUrl(p.id), p.name), `’s end date passed (${date(p.expires)}) · access kept.`] });
|
||
if (p.quota_limit && p.quota_used >= p.quota_limit * 0.9)
|
||
out.push({ tone: '', text: [link(personUrl(p.id), p.name), ' has used 90% of the data limit.'] });
|
||
}
|
||
}
|
||
const stale = st.people.flatMap((p) => p.devices.filter((d) => d.config_stale).map((d) => [p, d] as const));
|
||
if (stale.length)
|
||
out.push({
|
||
tone: 'warn',
|
||
text:
|
||
stale.length === 1
|
||
? [
|
||
link(personUrl(stale[0][0].id, stale[0][1].id), `${stale[0][0].name} · ${stale[0][1].name}`),
|
||
' needs its configuration again.',
|
||
]
|
||
: [`${stale.length} devices need their configuration again (networks or DNS changed).`],
|
||
});
|
||
// A server that gives devices an IPv4 that is no longer the router's: one click puts the new one in.
|
||
for (const s of st.servers)
|
||
if (st.wan && isIpv4(s.endpoint) && s.endpoint !== st.wan)
|
||
out.push({
|
||
tone: 'warn',
|
||
text: [
|
||
`Public address changed: ${s.name} still gives devices ${s.endpoint}, the router is ${st.wan} now. `,
|
||
E(
|
||
'button',
|
||
{
|
||
type: 'button',
|
||
class: 'dl-fix',
|
||
click: async (ev: Event) => {
|
||
const b = ev.currentTarget as HTMLButtonElement;
|
||
b.disabled = true;
|
||
await attempt(
|
||
() => api.serverUpdate(s.id, { endpoint: st.wan }),
|
||
`${s.name} uses ${st.wan} now — devices need their configuration again`,
|
||
);
|
||
b.disabled = false;
|
||
},
|
||
},
|
||
'Use the new address',
|
||
),
|
||
' A DDNS name would follow it by itself.',
|
||
],
|
||
});
|
||
if (st.servers.some((s) => s.lan_like) && st.like_home.error)
|
||
out.push({
|
||
tone: 'warn',
|
||
text: [`Internet through the LAN is off: ${st.like_home.error} `, link(L.url('admin/network/dawnline/diagnostics'), 'Details')],
|
||
});
|
||
// Only while setting up: an admin who keeps the portal off has decided so.
|
||
if (!st.settings.portal_enabled && !st.people.length)
|
||
out.push({ tone: '', text: ['The personal portal is off. ', link(L.url('admin/network/dawnline/settings'), 'Turn on')] });
|
||
return out;
|
||
}
|
||
|
||
export class ServerOverview {
|
||
st!: Status;
|
||
el = E('div', { class: 'dl-srvov' });
|
||
map: ConnectionMap | null = null;
|
||
range: Range = 'online';
|
||
parts: Record<string, HTMLElement> = {};
|
||
healthAt = 0;
|
||
|
||
/** `go` switches the Servers page to another section in place. */
|
||
constructor(
|
||
readonly srvId: string,
|
||
private go?: (section: string, filter?: string) => void,
|
||
) {}
|
||
|
||
/** Build once; later calls to update() keep the map instance. */
|
||
mount(st: Status): HTMLElement {
|
||
this.st = scoped(st, this.srvId);
|
||
for (const k of ['health', 'bento', 'side', 'activity']) this.parts[k] = E('div', {});
|
||
dom.content(this.el, [
|
||
this.parts.health,
|
||
this.parts.bento,
|
||
this.mapCard(),
|
||
E('div', { class: 'dl-grid2' }, [this.parts.activity, this.parts.side]),
|
||
]);
|
||
this.paint();
|
||
void this.loadHealth();
|
||
return this.el;
|
||
}
|
||
|
||
/** New status; a `quiet` (periodic) update leaves alone a part that has the keyboard focus. */
|
||
update(st: Status, quiet = false) {
|
||
this.st = scoped(st, this.srvId);
|
||
this.paint(quiet);
|
||
this.map?.update(this.mapData());
|
||
// Health checks cost more than a status call: once a minute is plenty.
|
||
if (Date.now() - this.healthAt > 60_000) void this.loadHealth();
|
||
}
|
||
|
||
/** Notices above the bento for the checks that failed (with their fix), only while Health has any. */
|
||
async loadHealth() {
|
||
this.healthAt = Date.now();
|
||
const r = await api.health().catch(() => null);
|
||
if (!r) return;
|
||
const again = () => void this.loadHealth();
|
||
const run = async (fix: string) => {
|
||
if (!(await runFix(fix))) return;
|
||
again();
|
||
// The network restarts a second after the answer: look again once it is back.
|
||
if (fix === 'netrestart') setTimeout(again, 5000);
|
||
};
|
||
repaint(
|
||
this.parts.health,
|
||
healthNotices(r.checks, (fix) => void run(fix), again),
|
||
true,
|
||
);
|
||
}
|
||
|
||
mapData() {
|
||
return { geo: this.st.geo, people: this.st.people, now: this.st.now };
|
||
}
|
||
|
||
mapCard(): HTMLElement {
|
||
const st = this.st;
|
||
const head = E('div', { class: 'dl-panel-head pad' }, [
|
||
E('div', { class: 'dl-stack' }, [
|
||
E('h3', {}, 'Where people connect from'),
|
||
E('span', { class: 'dl-sub' }, 'City-level, from the client IP · locations cached on the router'),
|
||
]),
|
||
E('span', { class: 'dl-spacer' }),
|
||
rangeControl(this.range, (r) => {
|
||
this.range = r;
|
||
this.map?.setRange(r);
|
||
}),
|
||
]);
|
||
if (!st.geo.enabled)
|
||
return E('div', { class: 'dl-panel flush' }, [
|
||
head,
|
||
E('div', { class: 'dl-map-off' }, [
|
||
'Locations are off. ',
|
||
E('a', { href: L.url('admin/network/dawnline/settings') }, 'Turn them on in Settings'),
|
||
'.',
|
||
]),
|
||
]);
|
||
this.map?.destroy();
|
||
this.map = new ConnectionMap(
|
||
{
|
||
openPerson: (id) => (location.href = personUrl(id)),
|
||
openDevice: (id, dev) => (location.href = personUrl(id, dev)),
|
||
},
|
||
this.range,
|
||
);
|
||
// A WebGL map outlives the page's DOM unless it is told: free it when
|
||
// Outline navigates away (the page object itself may be reused).
|
||
const offNav = onNavigate(() => {
|
||
offNav();
|
||
this.map?.destroy();
|
||
this.map = null;
|
||
});
|
||
const legend = E('div', { class: 'dl-map-legend' }, [
|
||
E('span', {}, [E('i', { class: 'line live' }), 'Live tunnel']),
|
||
E('span', {}, [E('i', { class: 'line' }), 'Seen recently']),
|
||
]);
|
||
const wrap = E('div', { class: 'dl-map-wrap' }, [this.map.el, legend]);
|
||
requestAnimationFrame(() => this.map!.mount(this.mapData()));
|
||
return E('div', { class: 'dl-panel flush' }, [head, wrap]);
|
||
}
|
||
|
||
paint(quiet = false) {
|
||
const st = this.st;
|
||
const srv = st.servers[0];
|
||
|
||
repaint(
|
||
this.parts.bento,
|
||
E('div', { class: 'dl-bento' }, [this.onlineTile(), this.speedTile(), coreOf(srv).overviewTile(srv), this.monthTile()]),
|
||
quiet,
|
||
);
|
||
|
||
const att = attention(st);
|
||
repaint(
|
||
this.parts.side,
|
||
E('div', { class: 'dl-panel flush' }, [
|
||
E('div', { class: 'dl-panel-head pad' }, [
|
||
E('h3', {}, 'Needs attention'),
|
||
E('span', { class: 'dl-spacer' }),
|
||
E('a', { href: L.url('admin/network/dawnline/diagnostics') }, 'Health'),
|
||
]),
|
||
att.length
|
||
? att
|
||
.slice(0, 8)
|
||
.map((a) =>
|
||
E('div', { class: 'dl-attn-item dl-row' }, [
|
||
E('span', { class: `dl-ev-dot ${a.tone}` }),
|
||
E('span', {}, a.text),
|
||
a.action ?? '',
|
||
]),
|
||
)
|
||
: E('div', { class: 'dl-row dl-muted' }, [icon('check'), 'All good. Nothing needs you right now.']),
|
||
]),
|
||
quiet,
|
||
);
|
||
|
||
const events = [...st.events].reverse().slice(0, 8);
|
||
repaint(
|
||
this.parts.activity,
|
||
E('div', { class: 'dl-panel flush' }, [
|
||
E('div', { class: 'dl-panel-head pad' }, [
|
||
E('h3', {}, 'Activity'),
|
||
E('span', { class: 'dl-spacer' }),
|
||
E('a', { href: `${L.url('admin/network/dawnline/diagnostics')}?tab=log` }, 'View all'),
|
||
]),
|
||
events.length
|
||
? events.map((e) => eventRow(st, e))
|
||
: E('div', { class: 'dl-row dl-muted' }, 'Nothing yet. Connections, new devices and pauses appear here.'),
|
||
]),
|
||
quiet,
|
||
);
|
||
}
|
||
|
||
/**
|
||
* Who is connected right now, and nothing else. One or two people: avatar,
|
||
* name, device icons and city; three or more: a grid of avatars (two rows,
|
||
* then +N). The device badge is the main device, or a count. Hover: a live
|
||
* card with speed, devices and today's traffic. Nobody: when someone was last seen.
|
||
*/
|
||
onlineTile(): HTMLElement {
|
||
const st = this.st;
|
||
const off = st.servers[0] ? !st.servers[0].enabled : false;
|
||
const CAP = 12;
|
||
const today = (d: Device) => d.spark[d.spark.length - 1] ?? 0;
|
||
const cityOf = (d: Device) => st.geo.points.find((g) => g.device === d.id && g.city)?.city;
|
||
const home = (d: Device) => /^(10\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.)/.test(d.endpoint ?? '');
|
||
// Where a device is: its city, or "LAN" when it connects from the home network (the hover
|
||
// card adds its address there).
|
||
const where = (d: Device, ip = false): string => (home(d) ? (ip && d.endpoint ? `LAN · ${d.endpoint}` : 'LAN') : (cityOf(d) ?? ''));
|
||
const connectedAt = (d: Device) => [...st.events].reverse().find((e) => e.type === 'connect' && e.device === d.id)?.ts ?? 0;
|
||
const on = st.people
|
||
.map((p) => ({ p, devs: p.devices.filter((d) => d.online).sort((a, b) => today(b) - today(a)) }))
|
||
.filter((x) => x.devs.length)
|
||
.sort((a, b) => b.devs.reduce((n, d) => n + today(d), 0) - a.devs.reduce((n, d) => n + today(d), 0));
|
||
const big = on.length <= 2;
|
||
|
||
const card = ({ p, devs }: { p: Person; devs: Device[] }): Node[] => {
|
||
const starts = devs.map(connectedAt).filter(Boolean);
|
||
const since = starts.length ? Math.min(...starts) : 0;
|
||
const pts = (p.rate ?? []).slice(-15);
|
||
const last = pts[pts.length - 1];
|
||
const fresh = last && st.now - last[0] < 180 ? last : null;
|
||
const W = 200,
|
||
H = 30,
|
||
max = Math.max(1, ...pts.map((x) => Math.max(x[1], x[2])));
|
||
const line = (k: 1 | 2) => pts.map((x, i) => `${pts.length > 1 ? (i / (pts.length - 1)) * W : W},${H - 2 - (x[k] / max) * (H - 6)}`);
|
||
const chart =
|
||
pts.length > 1
|
||
? svg(
|
||
`<svg viewBox="0 0 ${W} ${H}" preserveAspectRatio="none" class="dl-hc-chart" aria-hidden="true">` +
|
||
`<path d="M${line(2).join(' L')} L${W},${H} L0,${H}Z" class="area"/><path d="M${line(2).join(' L')}" class="dn"/><path d="M${line(1).join(' L')}" class="up"/></svg>`,
|
||
)
|
||
: '';
|
||
const idle = !fresh || (fresh[1] < 64 && fresh[2] < 64);
|
||
const reach = p.access === 'both' ? ['home', 'globe'] : p.access === 'lan' ? ['home'] : ['globe'];
|
||
return [
|
||
E('div', { class: 'dl-hc' }, [
|
||
E('div', { class: 'dl-hc-head' }, [
|
||
E('span', { class: 'dl-onl-av sm' }, initials(p.name)),
|
||
E('span', { class: 'dl-stack' }, [
|
||
E('b', {}, p.name),
|
||
E('span', { class: 'dl-hc-since' }, since ? `online for ${ago(since, st.now).replace(' ago', '')}` : 'online'),
|
||
]),
|
||
E(
|
||
'span',
|
||
{ class: 'dl-hc-reach' },
|
||
reach.map((r) => E('span', { class: `dl-ibadge ${r === 'home' ? 'lan' : 'inet'}` }, icon(r))),
|
||
),
|
||
]),
|
||
E('div', { class: 'dl-hc-speed' }, [
|
||
E(
|
||
'div',
|
||
{ class: 'dl-hc-speed-row' },
|
||
idle
|
||
? [E('span', { class: 'dl-faint' }, 'Idle right now')]
|
||
: [
|
||
E('span', {}, [E('span', { class: 'dl-dn' }, '↓'), ` ${bits(fresh![2])}`]),
|
||
E('span', {}, [E('span', { class: 'dl-up' }, '↑'), ` ${bits(fresh![1])}`]),
|
||
E('span', { class: 'dl-spacer' }),
|
||
E('span', { class: 'dl-faint' }, '15 min'),
|
||
],
|
||
),
|
||
chart,
|
||
]),
|
||
E(
|
||
'div',
|
||
{ class: 'dl-hc-devs' },
|
||
devs.map((d) => E('span', { class: 'dl-hc-dev' }, [icon(d.kind), d.name, where(d) ? [' · ', where(d, true)] : ''])),
|
||
),
|
||
E('div', { class: 'dl-hc-foot' }, [
|
||
E(
|
||
'span',
|
||
{ class: 'dl-faint' },
|
||
`${bytes(devs.reduce((n, d) => n + today(d), 0))} today · ${bytes(p.month[0] + p.month[1])} this month`,
|
||
),
|
||
]),
|
||
]),
|
||
];
|
||
};
|
||
|
||
const person = (x: { p: Person; devs: Device[] }) => {
|
||
const { p, devs } = x;
|
||
const badge = E('span', { class: 'dl-onl-dev' }, devs.length > 1 ? String(devs.length) : icon(devs[0].kind));
|
||
const el = E('a', { class: `dl-onl-p${big ? '' : ' sm'}`, href: personUrl(p.id), 'aria-label': `${p.name}, online` }, [
|
||
E('span', { class: 'dl-onl-av' }, [initials(p.name), badge]),
|
||
big ? E('span', { class: 'dl-onl-name' }, p.name) : '',
|
||
big
|
||
? E('span', { class: 'dl-onl-meta' }, [
|
||
...devs.slice(0, 3).map((d) => icon(d.kind)),
|
||
devs.length > 3 ? `+${devs.length - 3}` : '',
|
||
where(devs[0]) ? E('span', {}, [' · ', where(devs[0])]) : '',
|
||
])
|
||
: '',
|
||
]);
|
||
attachTip(el, () => card(x));
|
||
return el;
|
||
};
|
||
|
||
const count = E('b', { class: `dl-onl-count${on.length ? '' : ' none'}` }, String(on.length));
|
||
const ndev = on.reduce((n, x) => n + x.devs.length, 0);
|
||
if (on.length)
|
||
attachTip(count, () => [`${on.length} ${on.length === 1 ? 'person' : 'people'} · ${ndev} device${ndev === 1 ? '' : 's'}`]);
|
||
const shown = on.length > CAP ? on.slice(0, CAP - 1) : on;
|
||
const last = st.people
|
||
.flatMap((p) => p.devices.map((d) => ({ p, d })))
|
||
.filter((x) => x.d.handshake)
|
||
.sort((a, b) => b.d.handshake - a.d.handshake)[0];
|
||
return E('div', { class: 'dl-bento-tile online' }, [
|
||
E('div', { class: 'dl-bento-head' }, [E('span', { class: 'dl-metric-label' }, 'Online'), count]),
|
||
on.length
|
||
? E('div', { class: `dl-onl-row${big ? '' : ' grid'}` }, [
|
||
...shown.map(person),
|
||
on.length > CAP
|
||
? E(
|
||
'a',
|
||
{
|
||
class: 'dl-onl-p sm more',
|
||
href: `${L.url('admin/network/dawnline/server')}?server=${encodeURIComponent(this.srvId)}§ion=people&filter=online`,
|
||
title: 'Everyone online',
|
||
click: (ev: Event) => {
|
||
if (this.go) {
|
||
ev.preventDefault();
|
||
this.go('people', 'online');
|
||
}
|
||
},
|
||
},
|
||
[E('span', { class: 'dl-onl-av' }, `+${on.length - shown.length}`)],
|
||
)
|
||
: '',
|
||
])
|
||
: E('div', { class: 'dl-onl-empty' }, [
|
||
// A server that is off takes no connections: say so rather than "nobody".
|
||
E('span', {}, off ? 'The server is turned off' : 'Nobody is connected'),
|
||
last
|
||
? E('span', { class: 'dl-sub' }, `Last: ${last.p.name}, ${ago(last.d.handshake, st.now)}`)
|
||
: E('span', { class: 'dl-sub' }, off ? 'Devices connect once it is on' : 'No device has connected yet'),
|
||
]),
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* Throughput right now (from the agent's minute samples): download and
|
||
* upload side by side, the last 15 minutes as a small chart, today's total.
|
||
*/
|
||
speedTile(): HTMLElement {
|
||
const srv = this.st.servers[0];
|
||
return speedTile(srv?.rate ?? [], this.st.now, this.st.totals.today, srv ? !srv.enabled : false);
|
||
}
|
||
|
||
/** The last 30 days, today on the right, with the peak. */
|
||
monthTile(): HTMLElement {
|
||
// Who used the most this month (the People sort has it too, a click away).
|
||
const top = [...this.st.people]
|
||
.map((p) => [p, p.month[0] + p.month[1]] as const)
|
||
.filter(([, n]) => n > 0)
|
||
.sort((a, b) => b[1] - a[1])
|
||
.slice(0, 2);
|
||
return daysTile(this.st.series, top.length ? `Most: ${top.map(([p, n]) => `${p.name} ${bytes(n)}`).join(' · ')}` : '');
|
||
}
|
||
}
|