diff --git a/DESIGN.md b/DESIGN.md index cd1eb8a..5150487 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -819,7 +819,7 @@ The ⋯ menu, the pick pills' popups and the page code card are one kind of thin - Card: `raised`, radius 28, padding 8, gap 8. - Top row (padding `8 6 6 10`, gap 12): a 32 px glass icon (blue on "this device", else grey), the name (16/22 500, one line), the status (13/18, one line, full wording in `title`), and the ⋯ knob. - Bottom, one of three: - - **Usage** (`field`, radius 20, padding `12 14 12 16`, min-height 66): "Last 7 days" 13/18 `text-2` over the total 17/24 500 tabular. Spark of 7 bars at the right: 6 px wide, gap 4, ≤ 34 px high, min 3, radius 3, `--bar`, today in accent. Hovering a bar puts that day's name and bytes in place of the label and total instantly, with no morph. + - **Usage** (`field`, radius 20, padding `12 14 12 16`, min-height 66): "Last 7 days" 13/18 `text-2` over the total 17/24 500 tabular. Spark of 7 bars at the right: 6 px wide, gap 4, ≤ 34 px high, min 3, radius 3, `--bar`, today in accent. A day under the pointer, tapped (it stays until a tap elsewhere) or picked with ← → once the bars have focus (*Reading the bars* below) puts its name and bytes in place of the label and total instantly, with no morph; a day with nothing adds "· not used". - **Reconnect** (instead of the week): a `tint` block button with the refresh icon. - **Connect**: a `tint` block button with the QR icon. - A status is one line, and Reconnect or Connect takes the week's place. The button is lower than the week (48 against 66), so a card alone in its row is lower too; when its bottom changes, the card glides to its new height (see *Motion → Repaint choreography*). @@ -869,11 +869,13 @@ A longer reason sits in `title` and, for a screen reader, in hidden text right a | Row | Head | Body | |---|---|---| | **What it reaches** (shield, home or globe glass) | Title only | Two **reach tiles** (radius 16, `field`, padding `12 12 12 14`, glass 28, title 14/20 500, sub 12/16; a 20 px round mark at the top right: ok-soft check or knob minus, the tile dimmed when off). Then a sentence with the hostname pattern in mono, and **name chips** (32 high, radius 10, mono 13, the domain part in `text-3`, a copy icon 14). | -| **Data this month** (chart glass) | A 16 px **ring** (track `--bar`, arc accent, warn ≥ 90%, bad ≥ 100%) and "38.6 GB / 100 GB"; hidden while open | The **month**: one bar per day (flex, gap 3, 64 high, radius 2.5, min 3; days to come at 45% bar; today accent), an axis 11 px `text-3` with "Today" in accent under its bar (the month's ends hide when it comes close), the total line (`bad` when out), a 6 px **meter** (same tone thresholds), and a `.desc`. Hovering a bar puts that day's total in place of the total instantly. | -| **Access until** (calendar glass) | "30 Nov" plus "42 days" in ok, warn when soon, or "ended" in bad | The **until block** (`field`, radius 16, padding `14 16`): the days left as a 36/40 600 number (warn when soon), "days left", the end date in `text-3`, and a **calendar** of the weeks to the end. 7 columns of 10 px cells with gap 5 and radius 3: past at text 5%, left at text 16%, today in accent, the last day ringed 1.5 px accent; warn colours when soon. Under it the **hours bar**: 8 px track, the allowed window in ok 70%, a 2 × 16 "now" marker (`text`, warn when outside, with a 2 px field ring), and axis 00/06/12/18/24 at 10 px. With nothing to open, the row is still. | +| **Data this month** (chart glass) | A 16 px **ring** (track `--bar`, arc accent, warn ≥ 90%, bad ≥ 100%) and "38.6 GB / 100 GB"; hidden while open | The **month**: one bar per day (flex, gap 3, 64 high, radius 2.5, min 3; days to come at 45% bar; today accent), an axis 11 px `text-3` with "Today" in accent under its bar (the month's ends hide when it comes close), the total line (`bad` when out), a 6 px **meter** (same tone thresholds), and a `.desc`. A picked day (*Reading the bars*) puts its down and up in place of the total and "21 Oct · +62%" (its date and how it compares with the month's other days; today "so far") in place of what is left, instantly. With a limit not reached, a line under the meter (12/16 `text-2`, warn when it fills within a week): the pace lately (the devices' last 7 days) and when the limit fills at it, or what a monthly one reaches by the reset (`shared/pace.ts`). | +| **Access until** (calendar glass) | "30 Nov" plus "42 days" in ok, warn when soon, or "ended" in bad | The **until block** (`field`, radius 16, padding `14 16`): the days left as a 36/40 600 number (warn when soon), "days left", the end date in `text-3`, and a **calendar** of the weeks to the end. 7 columns of 10 px cells with gap 5 and radius 3: past at text 5%, left at text 16%, today in accent, the last day ringed 1.5 px accent; warn colours when soon. Under it the **hours bar**: 8 px track, the allowed window in ok 70%, a 2 × 16 "now" marker (`text`, warn when outside, with a 2 px field ring), and axis 00/06/12/18/24 at 10 px, then how long the window still runs ("3h 20m left") or, outside it in warn, when it opens (12/16 `text-2`). With nothing to open, the row is still. | A repaint keeps the rows on the page and changes what they hold in place, the same row open (see *Motion → Repaint choreography*). +**Reading the bars** (`ui/bars.ts` `readBars`, `shared/scrub.ts`, the same rule as the admin's charts): the pointer picks the day under it; a tap picks one and it stays until a tap elsewhere (a tap on it again lets go), so a touch screen reads a day without it flickering back; with the bars focused (a 2 px accent 55% ring, radius 6) ← → Home End walk the days and Esc lets go, each day read out to a screen reader. The picked column takes the hover look (`.on`). + ### Sheet · `ui/sheet.ts` **Shape:** `raised`, radius 36, `--sheet-shadow`, `overflow: hidden`. diff --git a/package/luci-app-dawnline/Makefile b/package/luci-app-dawnline/Makefile index 5173cf7..0136f7f 100644 --- a/package/luci-app-dawnline/Makefile +++ b/package/luci-app-dawnline/Makefile @@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-dawnline -PKG_VERSION:=0.16.3 +PKG_VERSION:=0.17.0 PKG_RELEASE:=1 PKG_LICENSE:=MIT # po//dawnline.po becomes luci-i18n-dawnline- (luci.mk), released diff --git a/package/luci-app-dawnline/po/ru/dawnline.po b/package/luci-app-dawnline/po/ru/dawnline.po index 674c395..9e91f85 100644 --- a/package/luci-app-dawnline/po/ru/dawnline.po +++ b/package/luci-app-dawnline/po/ru/dawnline.po @@ -126,6 +126,10 @@ msgstr[2] "%s устройств AmneziaWG перестанут подключа msgid "%s MB free: settings may stop saving. Remove old backups (Settings → Backups) or shorten the history." msgstr "Свободно %s МБ: настройки могут перестать сохраняться. Удалите старые резервные копии («Настройки» → «Резервные копии») или сократите историю." +#: web/src/shared/pace.ts +msgid "%s a day lately" +msgstr "%s в день за последние дни" + #: web/src/admin/access.ts #: web/src/admin/device.ts msgid "%s added" @@ -263,6 +267,13 @@ msgstr "Сервер %s не может использовать сетевой msgid "%s check failed" msgstr "%s: ошибка проверки" +#: web/src/admin/pages/overview.ts +msgid "%s city" +msgid_plural "%s cities" +msgstr[0] "%s город" +msgstr[1] "%s города" +msgstr[2] "%s городов" + #: web/src/admin/device.ts msgid "%s copied" msgstr "Скопировано: %s" @@ -696,6 +707,10 @@ msgstr "осталось %s" msgid "%s may not contain # or a line break." msgstr "%s не может содержать # или перенос строки." +#: web/src/admin/widgets/readouts.ts +msgid "%s min %s s ago" +msgstr "%s мин %s с назад" + #: web/src/shared/format.ts msgid "%s min ago" msgstr "%s мин назад" @@ -912,6 +927,10 @@ msgstr "%s: доступ возобновлён" msgid "%s s" msgstr "%s с" +#: web/src/admin/widgets/readouts.ts +msgid "%s s ago" +msgstr "%s с назад" + #: web/src/admin/pages/settings/logs.ts msgid "%s since %s" msgstr "%s с %s" @@ -1107,6 +1126,10 @@ msgstr[0] "Ещё %s пункт в «Что нового»" msgstr[1] "Ещё %s пункта в «Что нового»" msgstr[2] "Ещё %s пунктов в «Что нового»" +#: web/src/admin/widgets/readouts.ts +msgid "+%s%% vs average" +msgstr "+%s%% к среднему" + #: web/src/admin/pages/person/limits.ts msgid "+1 month" msgstr "+1 месяц" @@ -1140,6 +1163,10 @@ msgstr "1 год" msgid "15 min" msgstr "15 мин" +#: web/src/admin/pages/overview.ts +msgid "2 min" +msgstr "2 мин" + #: web/src/admin/map.ts msgid "24h" msgstr "24 ч" @@ -2236,10 +2263,6 @@ msgstr "Часы не настроены" msgid "Close" msgstr "Закрыть" -#: web/src/admin/widgets/tiles.ts -msgid "Collecting… 1 point a minute" -msgstr "Сбор данных… 1 точка в минуту" - #: web/src/admin/widgets/tiles.ts msgid "Collecting… 1 point a second" msgstr "Сбор данных… 1 точка в секунду" @@ -2557,6 +2580,10 @@ msgstr "Dawnline обновлён до %s" msgid "Dawnline was updated to %s: reload the page." msgstr "Dawnline обновлён до версии %s: перезагрузите страницу." +#: web/src/admin/widgets/tiles.ts +msgid "Days this device was used" +msgstr "Дни с трафиком на устройстве" + #: package/luci-app-dawnline/root/usr/share/ucode/dawnline/schema.uc msgid "Default device limit must be 1-32." msgstr "Лимит устройств по умолчанию: от 1 до 32." @@ -3906,6 +3933,7 @@ msgid "Last 30 days" msgstr "За 30 дней" #: web/src/admin/device.ts +#: web/src/admin/widgets/spark.ts msgid "Last 7 days" msgstr "За 7 дней" @@ -4697,6 +4725,10 @@ msgstr "Не настроено." msgid "Not set: the certificate is picked automatically." msgstr "Не заданы: сертификат выбирается автоматически." +#: web/src/admin/widgets/readouts.ts +msgid "Not used" +msgstr "Без трафика" + #: web/src/admin/pages/diagnostics/health.ts msgid "Not working" msgstr "Не работает" @@ -6171,6 +6203,10 @@ msgstr "Скорость" msgid "Speed now" msgstr "Скорость сейчас" +#: web/src/admin/widgets/tiles.ts +msgid "Speed over the last 2 minutes" +msgstr "Скорость за последние 2 минуты" + #: web/src/admin/disguise.ts msgid "Standard (old)" msgstr "Стандартная (старая)" @@ -6382,6 +6418,10 @@ msgstr "Резервная копия (%s) будет удалена с роут msgid "The build kept on the router is installed again. Every AmneziaWG tunnel restarts for a few seconds." msgstr "Снова установится сборка, сохранённая на роутере. Все туннели AmneziaWG перезапустятся на несколько секунд." +#: web/src/admin/widgets/readouts.ts +msgid "The busiest of the %s days" +msgstr "Самый загруженный из %s дней" + #: package/luci-app-dawnline/root/usr/share/ucode/dawnline/backup.uc msgid "The configuration in this file cannot be read." msgstr "Не удаётся прочитать конфигурацию из этого файла." @@ -6763,8 +6803,7 @@ msgstr "Чтобы оставить старую маскировку части #: web/src/admin/events/render.ts #: web/src/admin/places/model.ts -#: web/src/admin/widgets/spark.ts -#: web/src/admin/widgets/tiles.ts +#: web/src/admin/widgets/readouts.ts msgid "Today" msgstr "Сегодня" @@ -6801,6 +6840,10 @@ msgstr "История трафика" msgid "Traffic history reset" msgstr "История трафика сброшена" +#: web/src/admin/widgets/tiles.ts +msgid "Traffic, last 30 days" +msgstr "Трафик за последние 30 дней" + #: web/src/admin/pages/components/hero.ts msgid "Translation" msgstr "Перевод" @@ -7212,6 +7255,13 @@ msgstr "Порт занят: %s. Выберите другой." msgid "Used for HTTPS links" msgstr "Для ссылок HTTPS" +#: web/src/admin/widgets/readouts.ts +msgid "Used on %s of %s day" +msgid_plural "Used on %s of %s days" +msgstr[0] "С трафиком %s из %s дня" +msgstr[1] "С трафиком %s из %s дней" +msgstr[2] "С трафиком %s из %s дней" + #: package/luci-app-dawnline/root/usr/share/ucode/dawnline/health.uc msgid "Using a self-signed certificate: browsers will show a warning." msgstr "Используется самоподписанный сертификат: браузеры покажут предупреждение." @@ -7401,7 +7451,7 @@ msgstr "По неверной ссылке откроется просто «Not #: web/src/admin/events/render.ts #: web/src/admin/places/model.ts -#: web/src/admin/widgets/spark.ts +#: web/src/admin/widgets/readouts.ts msgid "Yesterday" msgstr "Вчера" @@ -7649,6 +7699,14 @@ msgstr "без имени" msgid "a new build needs a manual switch in Components" msgstr ": новую сборку нужно включить вручную в «Компонентах»" +#: web/src/shared/pace.ts +msgid "about %s by the reset on %s" +msgstr "около %s к сбросу %s" + +#: web/src/admin/widgets/readouts.ts +msgid "about average" +msgstr "около среднего" + #: web/src/admin/events/model.ts msgid "access" msgstr "доступ" @@ -7953,6 +8011,13 @@ msgstr ": ошибка (%s)" msgid "from the portal" msgstr "через портал" +#: web/src/shared/pace.ts +msgid "full in about %s day, %s" +msgid_plural "full in about %s days, %s" +msgstr[0] "закончится примерно через %s день, %s" +msgstr[1] "закончится примерно через %s дня, %s" +msgstr[2] "закончится примерно через %s дней, %s" + #: package/luci-app-dawnline/root/usr/share/ucode/dawnline/awg.uc msgid "has an invalid interface name \"%s\"" msgstr ": недопустимое имя интерфейса «%s»" @@ -8101,10 +8166,6 @@ msgstr ": модуль ядра не установлен, туннели не msgid "kernel module isn't loaded" msgstr ": модуль ядра не загружен" -#: web/src/admin/widgets/tiles.ts -msgid "last 15 min" -msgstr "за 15 мин" - #: web/src/admin/widgets/tiles.ts msgid "last 2 min" msgstr "за 2 мин" @@ -8239,6 +8300,7 @@ msgstr "не настроено" #: web/src/admin/map.ts #: web/src/admin/places/render.ts +#: web/src/admin/widgets/readouts.ts msgid "now" msgstr "сейчас" @@ -8298,10 +8360,6 @@ msgstr "приостановить доступ" msgid "paused by admin" msgstr "приостановлено администратором" -#: web/src/admin/widgets/tiles.ts -msgid "peak %s" -msgstr "пик %s" - #: web/src/admin/events/model.ts msgid "port %s" msgstr "порт %s" @@ -8446,6 +8504,10 @@ msgstr "настраиваем заново" msgid "sha256 matches the release (%s…)" msgstr "sha256 совпадает с релизом (%s…)" +#: web/src/admin/widgets/readouts.ts +msgid "so far" +msgstr "пока" + #: package/luci-app-dawnline/root/usr/bin/dawnline msgid "started" msgstr ": запущен" @@ -8623,3 +8685,7 @@ msgstr "«%s» - не IP-адрес. Несколько адресов разд #: web/src/admin/pages/components/hero.ts msgid "← Newer" msgstr "← Новее" + +#: web/src/admin/widgets/readouts.ts +msgid "−%s%% vs average" +msgstr "−%s%% к среднему" diff --git a/package/luci-app-dawnline/po/templates/dawnline.pot b/package/luci-app-dawnline/po/templates/dawnline.pot index c7367bd..8c95e41 100644 --- a/package/luci-app-dawnline/po/templates/dawnline.pot +++ b/package/luci-app-dawnline/po/templates/dawnline.pot @@ -117,6 +117,10 @@ msgstr[1] "" msgid "%s MB free: settings may stop saving. Remove old backups (Settings → Backups) or shorten the history." msgstr "" +#: web/src/shared/pace.ts +msgid "%s a day lately" +msgstr "" + #: web/src/admin/access.ts #: web/src/admin/device.ts msgid "%s added" @@ -250,6 +254,12 @@ msgstr "" msgid "%s check failed" msgstr "" +#: web/src/admin/pages/overview.ts +msgid "%s city" +msgid_plural "%s cities" +msgstr[0] "" +msgstr[1] "" + #: web/src/admin/device.ts msgid "%s copied" msgstr "" @@ -665,6 +675,10 @@ msgstr "" msgid "%s may not contain # or a line break." msgstr "" +#: web/src/admin/widgets/readouts.ts +msgid "%s min %s s ago" +msgstr "" + #: web/src/shared/format.ts msgid "%s min ago" msgstr "" @@ -869,6 +883,10 @@ msgstr "" msgid "%s s" msgstr "" +#: web/src/admin/widgets/readouts.ts +msgid "%s s ago" +msgstr "" + #: web/src/admin/pages/settings/logs.ts msgid "%s since %s" msgstr "" @@ -1055,6 +1073,10 @@ msgid_plural "+%s more in What’s new" msgstr[0] "" msgstr[1] "" +#: web/src/admin/widgets/readouts.ts +msgid "+%s%% vs average" +msgstr "" + #: web/src/admin/pages/person/limits.ts msgid "+1 month" msgstr "" @@ -1088,6 +1110,10 @@ msgstr "" msgid "15 min" msgstr "" +#: web/src/admin/pages/overview.ts +msgid "2 min" +msgstr "" + #: web/src/admin/map.ts msgid "24h" msgstr "" @@ -2179,10 +2205,6 @@ msgstr "" msgid "Close" msgstr "" -#: web/src/admin/widgets/tiles.ts -msgid "Collecting… 1 point a minute" -msgstr "" - #: web/src/admin/widgets/tiles.ts msgid "Collecting… 1 point a second" msgstr "" @@ -2500,6 +2522,10 @@ msgstr "" msgid "Dawnline was updated to %s: reload the page." msgstr "" +#: web/src/admin/widgets/tiles.ts +msgid "Days this device was used" +msgstr "" + #: package/luci-app-dawnline/root/usr/share/ucode/dawnline/schema.uc msgid "Default device limit must be 1-32." msgstr "" @@ -3849,6 +3875,7 @@ msgid "Last 30 days" msgstr "" #: web/src/admin/device.ts +#: web/src/admin/widgets/spark.ts msgid "Last 7 days" msgstr "" @@ -4639,6 +4666,10 @@ msgstr "" msgid "Not set: the certificate is picked automatically." msgstr "" +#: web/src/admin/widgets/readouts.ts +msgid "Not used" +msgstr "" + #: web/src/admin/pages/diagnostics/health.ts msgid "Not working" msgstr "" @@ -6108,6 +6139,10 @@ msgstr "" msgid "Speed now" msgstr "" +#: web/src/admin/widgets/tiles.ts +msgid "Speed over the last 2 minutes" +msgstr "" + #: web/src/admin/disguise.ts msgid "Standard (old)" msgstr "" @@ -6318,6 +6353,10 @@ msgstr "" msgid "The build kept on the router is installed again. Every AmneziaWG tunnel restarts for a few seconds." msgstr "" +#: web/src/admin/widgets/readouts.ts +msgid "The busiest of the %s days" +msgstr "" + #: package/luci-app-dawnline/root/usr/share/ucode/dawnline/backup.uc msgid "The configuration in this file cannot be read." msgstr "" @@ -6696,8 +6735,7 @@ msgstr "" #: web/src/admin/events/render.ts #: web/src/admin/places/model.ts -#: web/src/admin/widgets/spark.ts -#: web/src/admin/widgets/tiles.ts +#: web/src/admin/widgets/readouts.ts msgid "Today" msgstr "" @@ -6734,6 +6772,10 @@ msgstr "" msgid "Traffic history reset" msgstr "" +#: web/src/admin/widgets/tiles.ts +msgid "Traffic, last 30 days" +msgstr "" + #: web/src/admin/pages/components/hero.ts msgid "Translation" msgstr "" @@ -7144,6 +7186,12 @@ msgstr "" msgid "Used for HTTPS links" msgstr "" +#: web/src/admin/widgets/readouts.ts +msgid "Used on %s of %s day" +msgid_plural "Used on %s of %s days" +msgstr[0] "" +msgstr[1] "" + #: package/luci-app-dawnline/root/usr/share/ucode/dawnline/health.uc msgid "Using a self-signed certificate: browsers will show a warning." msgstr "" @@ -7332,7 +7380,7 @@ msgstr "" #: web/src/admin/events/render.ts #: web/src/admin/places/model.ts -#: web/src/admin/widgets/spark.ts +#: web/src/admin/widgets/readouts.ts msgid "Yesterday" msgstr "" @@ -7580,6 +7628,14 @@ msgstr "" msgid "a new build needs a manual switch in Components" msgstr "" +#: web/src/shared/pace.ts +msgid "about %s by the reset on %s" +msgstr "" + +#: web/src/admin/widgets/readouts.ts +msgid "about average" +msgstr "" + #: web/src/admin/events/model.ts msgid "access" msgstr "" @@ -7883,6 +7939,12 @@ msgstr "" msgid "from the portal" msgstr "" +#: web/src/shared/pace.ts +msgid "full in about %s day, %s" +msgid_plural "full in about %s days, %s" +msgstr[0] "" +msgstr[1] "" + #: package/luci-app-dawnline/root/usr/share/ucode/dawnline/awg.uc msgid "has an invalid interface name \"%s\"" msgstr "" @@ -8031,10 +8093,6 @@ msgstr "" msgid "kernel module isn't loaded" msgstr "" -#: web/src/admin/widgets/tiles.ts -msgid "last 15 min" -msgstr "" - #: web/src/admin/widgets/tiles.ts msgid "last 2 min" msgstr "" @@ -8169,6 +8227,7 @@ msgstr "" #: web/src/admin/map.ts #: web/src/admin/places/render.ts +#: web/src/admin/widgets/readouts.ts msgid "now" msgstr "" @@ -8227,10 +8286,6 @@ msgstr "" msgid "paused by admin" msgstr "" -#: web/src/admin/widgets/tiles.ts -msgid "peak %s" -msgstr "" - #: web/src/admin/events/model.ts msgid "port %s" msgstr "" @@ -8375,6 +8430,10 @@ msgstr "" msgid "sha256 matches the release (%s…)" msgstr "" +#: web/src/admin/widgets/readouts.ts +msgid "so far" +msgstr "" + #: package/luci-app-dawnline/root/usr/bin/dawnline msgid "started" msgstr "" @@ -8550,3 +8609,7 @@ msgstr "" #: web/src/admin/pages/components/hero.ts msgid "← Newer" msgstr "" + +#: web/src/admin/widgets/readouts.ts +msgid "−%s%% vs average" +msgstr "" diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/meter.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/meter.uc index 29ae17d..eeb1076 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/meter.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/meter.uc @@ -1,5 +1,6 @@ -// Dawnline — the live meter (the Overview's Speed now): each server's -// throughput, one point a second over the last two minutes. +// Dawnline — the live meter (Speed now on the Overview, the People list and a +// person's page): each server's throughput and that of each device moving +// traffic, one point a second over the last two minutes. // // The meter RPC (dawnline.rpc.status) calls want() and read(); the agent's // watcher makes a point from every read it already does (sample(), point()) @@ -8,8 +9,8 @@ // while WANT is younger than WANT_FOR seconds: the first second of a look, // then with each new point. When WANT goes stale it removes FILE: with nobody // looking the watcher pays a little arithmetic and one stat() a second, and -// writes nothing. FILE holds server ids and byte rates only, no keys, names -// or personal codes. Who is online and the per-minute rates are not here +// writes nothing. FILE holds server and device ids and byte rates only, no +// keys, names or personal codes. Who is online and the per-minute rates are not here // (dawnline.live, the agent's tick). // // Bytes are the peers' counters (dawnline.awg.dump): tx includes the @@ -95,26 +96,31 @@ function delta(a, b) { /** * The point between samples `a` and `b`, null when they are not a second or * so apart (the first sample, a stalled watcher): { ts, servers: { server - * id: [ rx, tx ] } }, bytes per second of its devices together (rx what came - * from them, tx what went to them, as a server's per-minute `rate`), for - * every server whose tunnel `b` read ([ 0, 0 ] when nothing moved). A device - * is counted from its second sample on, on the server it was on in both. + * id: [ rx, tx ] }, dev: { device id: [ rx, tx ] } }, bytes per second of + * each server's devices together (rx what came from them, tx what went to + * them, as a server's per-minute `rate`), for every server whose tunnel `b` + * read ([ 0, 0 ] when nothing moved), and of each device that moved + * something (one left out moved nothing, while its server was read). A + * device is counted from its second sample on, on the server it was on in both. */ export function point(a, b) { let dt = b.t - a.t; if (!(dt > 0.2 && dt < 5)) return null; - let sum = {}; + let sum = {}, dev = {}; for (let sid in b.servers) sum[sid] = [ 0, 0 ]; for (let id, v in b.dev) { let o = a.dev[id]; if (!o || o[2] != v[2]) continue; - sum[v[2]][0] += delta(o[0], v[0]); - sum[v[2]][1] += delta(o[1], v[1]); + let rx = delta(o[0], v[0]), tx = delta(o[1], v[1]); + sum[v[2]][0] += rx; + sum[v[2]][1] += tx; + if (rx || tx) + dev[id] = [ int(rx / dt), int(tx / dt) ]; } - let p = { ts: b.ts, servers: {} }; + let p = { ts: b.ts, servers: {}, dev }; for (let sid, v in sum) p.servers[sid] = [ int(v[0] / dt), int(v[1] / dt) ]; return p; diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/nft.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/nft.uc index 9be782d..55c1cbd 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/nft.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/nft.uc @@ -216,6 +216,13 @@ function table(m, sets, ctx) { if (length(ifs)) // Home names (and no LAN DNS at all): the plain resolver, whatever address was asked. push(t, ` iifname { ${join(', ', ifs)} } ip saddr @dns_real meta l4proto { tcp, udp } th dport 53 ${to_resolver}`); + push(t, ' }'); + // After the LAN's own DNS interceptors (transparent proxies redirect port 53 + // at dstnat - 1): only the first NAT of a connection counts, so a DNAT here + // first would hand the query to the plain resolver behind their back. When + // none of them takes the tunnel, this sends it to the LAN's DNS. + push(t, ' chain dns_lan {'); + push(t, ' type nat hook prerouting priority dstnat + 5; policy accept;'); for (let id, srv in m.servers) for (let tn in core.tunnels(srv)) { // Everyone else: the LAN's DNS, through the netns (from the LAN side) when internet goes that way. diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/util.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/util.uc index 5fcd498..31eae30 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/util.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/util.uc @@ -5,7 +5,7 @@ import { open, readfile, writefile, rename, mkdir, stat, unlink, popen, lsdir } from 'fs'; import { _ } from 'dawnline.i18n'; -export const VERSION = '0.16.3'; +export const VERSION = '0.17.0'; /** GitHub repository with Dawnline releases (updates and the installer). */ export const REPO = 'tickcount/luci-app-dawnline'; export const RUN_DIR = '/var/run/dawnline'; diff --git a/tests/ucode/fixtures/nft-table.txt b/tests/ucode/fixtures/nft-table.txt index aa81b09..67bc890 100644 --- a/tests/ucode/fixtures/nft-table.txt +++ b/tests/ucode/fixtures/nft-table.txt @@ -51,6 +51,9 @@ table inet dawnline { chain dns { type nat hook prerouting priority dstnat - 5; policy accept; iifname { "awghome", "awgwork" } ip saddr @dns_real meta l4proto { tcp, udp } th dport 53 dnat ip to 169.254.77.2:53 + } + chain dns_lan { + type nat hook prerouting priority dstnat + 5; policy accept; iifname "awghome" ip daddr 10.9.0.1 meta l4proto { tcp, udp } th dport 53 dnat ip to 192.168.1.250:53 iifname "awgwork" ip daddr 10.9.1.1 meta l4proto { tcp, udp } th dport 53 dnat ip to 192.168.1.1:53 } diff --git a/tests/ucode/meter.test.uc b/tests/ucode/meter.test.uc index ca53911..3db39e4 100644 --- a/tests/ucode/meter.test.uc +++ b/tests/ucode/meter.test.uc @@ -1,5 +1,5 @@ -// dawnline.meter: the point between two samples (each server's bytes per -// second), the sample taken from a dump, the two minutes kept, and the file +// dawnline.meter: the point between two samples (each server's and each +// moving device's bytes per second), the sample taken from a dump, the two minutes kept, and the file // the watcher writes and the RPC reads (in RUN_DIR, removed after). import * as meter from 'dawnline.meter'; import { stat, unlink } from 'fs'; @@ -14,13 +14,15 @@ test('point', () => { // d_2 sent nothing; d_3's peer was added again (counters from zero); d_4 is new; d_5 moved to s_1. dev: { d_1: [ 3000, 12000, 's_1' ], d_2: [ 500, 500, 's_1' ], d_3: [ 100, 300, 's_1' ], d_4: [ 10, 10, 's_1' ], d_5: [ 50, 50, 's_1' ] }, }; - eq(meter.point(a, b), { ts: 5001, servers: { s_1: [ 2000, 10000 ], s_2: [ 0, 0 ] } }, - 'bytes per second of each server\'s devices together; a server read with nothing moving is 0'); + eq(meter.point(a, b), { ts: 5001, servers: { s_1: [ 2000, 10000 ], s_2: [ 0, 0 ] }, dev: { d_1: [ 2000, 10000 ] } }, + 'bytes per second of each server\'s devices together; a server read with nothing moving is 0; only devices that moved'); + eq(meter.point(a, { ...b, t: 102.0 }).dev, { d_1: [ 1000, 5000 ] }, 'a device over two seconds'); eq(meter.point(a, { ...b, t: 102.0 }).servers.s_1, [ 1000, 5000 ], 'over two seconds'); eq(meter.point(a, { ...b, t: 100.0 }), null, 'no time passed'); eq(meter.point(a, { ...b, t: 110.0 }), null, 'the watcher stalled'); eq(meter.point(a, { ...b, servers: [ 's_2' ], dev: { d_5: [ 50, 50, 's_2' ] } }).servers, { s_2: [ 50, 50 ] }, 'only servers read in the newer sample'); eq(meter.point({ ...a, dev: {} }, b).servers, { s_1: [ 0, 0 ], s_2: [ 0, 0 ] }, 'a first look at every device: nothing yet'); + eq(meter.point({ ...a, dev: {} }, b).dev, {}, 'and no device either'); }); test('sample', () => { @@ -37,7 +39,7 @@ test('sample', () => { }); test('keep', () => { - let pt = (ts) => ({ ts: ts, servers: { s_1: [ ts, 0 ] } }); + let pt = (ts) => ({ ts: ts, servers: { s_1: [ ts, 0 ] }, dev: { d_1: [ ts, 0 ] } }); let ring = []; for (let ts = 1000; ts < 1000 + meter.POINTS + 5; ts++) meter.keep(ring, pt(ts)); diff --git a/tests/ucode/nft.test.uc b/tests/ucode/nft.test.uc index 5e93b51..6843570 100644 --- a/tests/ucode/nft.test.uc +++ b/tests/ucode/nft.test.uc @@ -1,6 +1,6 @@ // dawnline.nft: the access table rendered for a model with two servers (one // sending everyone like a home device, one direct) and the router read as a -// fixed context: exactly what 0.13.0 renders (fixtures/nft-table.txt, made by +// fixed context: what 0.13.0 rendered (fixtures/nft-table.txt, made by // that version from this model). import { readfile } from 'fs'; import * as nft from 'dawnline.nft'; diff --git a/web/package-lock.json b/web/package-lock.json index d66c206..7273658 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -1,12 +1,12 @@ { "name": "dawnline-web", - "version": "0.16.3", + "version": "0.17.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "dawnline-web", - "version": "0.16.3", + "version": "0.17.0", "license": "MIT", "dependencies": { "qrcode-generator": "2.0.4" diff --git a/web/package.json b/web/package.json index 561daca..5e18a4a 100644 --- a/web/package.json +++ b/web/package.json @@ -1,6 +1,6 @@ { "name": "dawnline-web", - "version": "0.16.3", + "version": "0.17.0", "private": true, "license": "MIT", "type": "module", diff --git a/web/src/admin/api.ts b/web/src/admin/api.ts index cb9378f..12a68bc 100644 --- a/web/src/admin/api.ts +++ b/web/src/admin/api.ts @@ -82,10 +82,14 @@ export interface EndpointProbe { 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). */ +/** + * One second of the live meter: each server whose tunnel was read, [rx, tx] in bytes/s (rx = from devices, as + * Server.rate), and each device that moved something (one left out moved nothing; an older agent sends none). + */ export interface MeterPoint { ts: number; servers: Record; + dev?: Record; } /** diff --git a/web/src/admin/device.ts b/web/src/admin/device.ts index dc4dea8..2caaf18 100644 --- a/web/src/admin/device.ts +++ b/web/src/admin/device.ts @@ -235,8 +235,7 @@ export async function openDevice(person: Person, dev: Device, o: DeviceOpts) { E('span', { class: 'dl-sub' }, `${p.name} · ${kindLabel(d.kind)}`), ]), ]); - const days = d.spark.map(([rx, tx]) => rx + tx); - const week = days.reduce((a, b) => a + b, 0); + const week = d.spark.reduce((a, [rx, tx]) => a + rx + tx, 0); dom.content( stats, E('div', { class: 'dl-dstats' }, [ @@ -253,7 +252,7 @@ export async function openDevice(person: Person, dev: Device, o: DeviceOpts) { E('div', { class: 'dl-dstats-cell' }, [ E('span', { class: 'dl-metric-label' }, _('Last 7 days')), E('b', {}, bytes(week)), - spark(days, 120, 22, today), + spark(d.spark, 120, 22, today), ]), ]), ); diff --git a/web/src/admin/pages/overview.ts b/web/src/admin/pages/overview.ts index 7123e12..59e7b2b 100644 --- a/web/src/admin/pages/overview.ts +++ b/web/src/admin/pages/overview.ts @@ -2,11 +2,10 @@ // 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 type { Device, GeoPoint, Person, Status } from '../../shared/types'; import { E } from '../e'; import { api } from '../api'; -import { svg } from '../ui/layout'; -import { attachTip } from '../ui/tooltip'; +import { attachTip, refreshTip } from '../ui/tooltip'; import { icon } from '../../shared/icons'; import { ago, bits, bytes, date, daysLeft, duration, endsIn, endsSoon, initials, todayOf } from '../../shared/format'; import { fill, fmt, plural } from '../../shared/i18n'; @@ -17,6 +16,7 @@ import { scoped } from '../state/scope'; import { focusInside, repaint } from '../state/poller'; import type { LiveMeter } from '../state/meter'; import { daysTile, LiveSpeedTile } from '../widgets/tiles'; +import { SpeedLines } from '../widgets/lines'; import { coreOf } from '../cores'; import { healthNotices, runFix } from '../widgets/health'; import { attempt } from '../ui/toast'; @@ -316,7 +316,11 @@ export class ServerOverview { const [rx, tx] = d.spark[d.spark.length - 1] ?? [0, 0]; return rx + tx; }; - const cityOf = (d: Device) => st.geo.points.find((g) => g.device === d.id && g.city)?.city; + // The address it is connected from now, else the newest one (the points come oldest first). + const cityOf = (d: Device) => { + const pts = st.geo.points.filter((g) => g.device === d.id && g.city); + return (pts.find((g) => g.online) ?? pts.reduce((a, g) => (a && a.ts >= g.ts ? a : g), undefined))?.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). @@ -331,20 +335,22 @@ export class ServerOverview { 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); + // The live meter's last 2 minutes of their devices while it has them (the card is drawn again each + // second it shows, paintSpeed), else their last 15 minutes. + const ls = this.meter.speed( + p.server, + Date.now(), + p.devices.map((d) => d.id), + ); + const live = ls.pts.length > 1; + const pts = live ? ls.pts : (p.rate ?? []).slice(-15); + const xs = live ? ls.xs : pts.map((_x, i) => (pts.length > 1 ? i / (pts.length - 1) : 1)); 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( - ``, - ) - : ''; + const fresh = live ? ([0, ls.rx, ls.tx] as const) : last && st.now - last[0] < 180 ? last : null; + // The card's speed box is 228 px inside (280, less the card's and the box's padding). + const lines = pts.length > 1 ? new SpeedLines(30, true, 228) : null; + lines?.set(pts, xs); + const chart = lines?.el ?? ''; const idle = !fresh || (fresh[1] < 64 && fresh[2] < 64); const reach = p.access === 'both' ? ['home', 'globe'] : p.access === 'lan' ? ['home'] : ['globe']; return [ @@ -371,7 +377,7 @@ export class ServerOverview { 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')), + E('span', { class: 'dl-faint' }, live ? _('2 min') : _('15 min')), ], ), chart, @@ -395,17 +401,32 @@ export class ServerOverview { 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)); + // Every place their devices are, once, the busiest device's first: "Krasnodar · Moscow", or + // "Krasnodar +1" when two do not fit under the avatar, "3 cities" from three on (the card names each). + const places = [...new Set(devs.map((d) => where(d)).filter(Boolean))]; + const full = places.length > 2 ? plural(places.length, '%s city', '%s cities') : places.join(' · '); + const place = E('span', {}, full ? [' · ', full] : ''); + const meta = big + ? E('span', { class: 'dl-onl-meta' }, [ + ...devs.slice(0, 3).map((d) => icon(d.kind)), + devs.length > 3 ? `+${devs.length - 3}` : '', + place, + ]) + : ''; const el = E('a', { class: `dl-onl-p${big ? '' : ' sm'}`, href: personUrl(p.id), 'aria-label': fmt(_('%s, online'), p.name) }, [ 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])]) : '', - ]) - : '', + meta, ]); + if (meta && places.length === 2) { + // Measured where it stands (the person is a fixed width, so swapping the words never resizes what is observed). + const fit = new ResizeObserver(() => { + if (!el.isConnected) return fit.disconnect(); + place.textContent = ` · ${full}`; + if (meta.scrollWidth > meta.clientWidth) place.textContent = ` · ${places[0]} +1`; + }); + fit.observe(el); + } attachTip(el, () => card(x)); return el; }; @@ -465,6 +486,8 @@ export class ServerOverview { if (!this.st) return; const srv = this.st.servers[0]; this.speed.update(this.meter.speed(this.srvId, Date.now()), this.st.totals.today, srv ? !srv.enabled : false); + // A person's card under the pointer follows the same second. + refreshTip(); } /** The last 30 days, today on the right, with the peak. */ diff --git a/web/src/admin/pages/people.ts b/web/src/admin/pages/people.ts index 3c930e0..4066c78 100644 --- a/web/src/admin/pages/people.ts +++ b/web/src/admin/pages/people.ts @@ -10,13 +10,16 @@ import { cancelButton, closeModal, confirmDialog, modal } from '../ui/modal'; import { copyText } from '../ui/files'; import { dropdown, type MenuItem } from '../ui/menu'; import { attempt, notify } from '../ui/toast'; -import { attachTip } from '../ui/tooltip'; +import { pointTip } from '../ui/glide'; +import { limitMeter, splitMeter } from '../widgets/meter'; +import { paceOf, paceWords, weekAhead } from '../../shared/pace'; import { accessBadge } from '../ui/badges'; import { addDevice, openDevice, type DeviceOpts } from '../device'; import { copyPersonLink, inviteCard } from '../invite'; import { personUrl } from '../urls'; import { scoped } from '../state/scope'; import { createPoller, focusInside, type Poller } from '../state/poller'; +import type { LiveMeter, Rate } from '../state/meter'; import { onNavigate } from '../ui/nav'; import { accessPicker } from '../widgets/access-picker'; import { firstBad, liveField } from '../ui/layout'; @@ -122,6 +125,11 @@ export class PeoplePage { serverId: string | null = null; el: HTMLElement | null = null; poller?: Poller; + /** Each online person's speed in their card, put in place each second from the meter (a server's People list). */ + private speedEls = new Map(); + + /** `meter`: the Servers page's live meter, which it polls while this list shows (none on its own page). */ + constructor(private meter?: LiveMeter) {} async load(): Promise { return api.status(30); @@ -601,49 +609,60 @@ export class PeoplePage { const used = p.quota_used || p.month[0] + p.month[1]; const pct = p.quota_limit ? Math.min(100, (p.quota_used / p.quota_limit) * 100) : 0; const today = p.devices.reduce((a, d) => a + (d.spark[d.spark.length - 1] ?? [0, 0]).reduce((x, y) => x + y), 0); - const r = p.rate?.[p.rate.length - 1]; - const live = p.online && r && this.st.now - r[0] < 180; + const r = p.online ? this.speedOf(p) : null; + const live = !!r; - const bar = E('div', { class: `dl-usebar${pct >= 100 ? ' bad' : pct >= 90 ? ' warn' : ''}` }); + // The pace lately: their devices' days added up (each device's last 7, today last). + const week = Array.from({ length: 7 }, (_x, k) => p.devices.reduce((a, d) => a + (d.spark[k]?.[0] ?? 0) + (d.spark[k]?.[1] ?? 0), 0)); + const pace = paceOf(week); + const paceText = paceWords(used, p.quota_limit, pace, p.quota_period === 'month', this.today); + let bar: HTMLElement; if (p.quota_limit) { - const fill = E('i', { class: 'fill' }); - fill.style.width = `${pct}%`; - bar.appendChild(fill); - attachTip(bar, () => [ - E('div', { class: 'dl-tip-title' }, fmt(_('%s%% used'), num(pct, 1))), - E( - 'div', - { class: 'dl-muted' }, - `${fmt(_('%s of %s'), bytes(p.quota_used), bytes(p.quota_limit))} · ${fmt(_('%s left'), bytes(Math.max(0, p.quota_limit - p.quota_used)))}`, - ), - E( - 'div', - { class: 'dl-faint' }, - p.quota_period === 'total' - ? _('In total') - : [_('This month'), p.bonus_gb ? fmt(_('includes +%s GB extra'), num(p.bonus_gb)) : ''].filter(Boolean).join(' · '), - ), - ]); + bar = limitMeter(pct, weekAhead(p.quota_used, p.quota_limit, pace)); + // Above where the fill ends: the value's own place. + pointTip( + bar, + () => [ + E('div', { class: 'dl-glide-head' }, [ + E('b', {}, fmt(_('%s%% used'), num(pct, 1))), + E( + 'span', + { class: 'dl-faint' }, + p.quota_period === 'total' + ? _('In total') + : [_('This month'), p.bonus_gb ? fmt(_('includes +%s GB extra'), num(p.bonus_gb)) : ''].filter(Boolean).join(' · '), + ), + ]), + E( + 'div', + { class: 'dl-muted' }, + `${fmt(_('%s of %s'), bytes(p.quota_used), bytes(p.quota_limit))} · ${fmt(_('%s left'), bytes(Math.max(0, p.quota_limit - p.quota_used)))}`, + ), + pct < 100 && paceText ? E('div', { class: 'dl-glide-note' }, paceText) : '', + ], + () => { + const r = bar.getBoundingClientRect(); + return [r.left + (r.width * pct) / 100, r.top]; + }, + ); } else { const devs = p.devices .map((d) => ({ d, v: d.month[0] + d.month[1] })) .filter((x) => x.v > 0) .sort((a, b) => b.v - a.v); - devs.forEach((x, i) => { - const seg = E('i', { class: `c${Math.min(i, 4)}` }); - seg.style.flexGrow = String(x.v); - bar.appendChild(seg); - }); + bar = splitMeter(devs.map((x) => x.v)); if (devs.length) - attachTip(bar, () => [ - E('div', { class: 'dl-tip-title' }, _('This month by device')), + pointTip(bar, () => [ + E('div', { class: 'dl-glide-head' }, [E('b', {}, _('This month by device')), E('span', { class: 'dl-faint' }, bytes(used))]), ...devs.map((x, i) => E('div', { class: 'dl-tip-row' }, [ E('span', { class: `dl-swatch c${Math.min(i, 4)}` }), E('span', {}, x.d.name), + E('span', { class: 'dl-faint' }, `${num(Math.round((x.v / Math.max(1, used)) * 100))}%`), E('b', {}, bytes(x.v)), ]), ), + paceText ? E('div', { class: 'dl-glide-note' }, paceText) : '', ]); } @@ -668,15 +687,42 @@ export class PeoplePage { ), ]), bar, - live - ? E('div', { class: 'dl-use-live', title: _('Right now') }, [ - `↓ ${bits(r![2])}`, - E('span', { class: 'dl-faint' }, `↑ ${bits(r![1])}`), - ]) + r + ? this.speedRow(p, r) : E('div', { class: 'dl-faint dl-pside-foot' }, today ? `${fmt(_('today %s'), bytes(today))} · ${limitText}` : limitText), ]); } + /** Their speed now ([ts, rx, tx]): the live meter's while it has points, else their newest minute while it is recent. */ + private speedOf(p: Person): Rate | null { + const s = this.meter?.speed( + p.server, + Date.now(), + p.devices.map((d) => d.id), + ); + if (s?.pts.length) return [0, s.rx, s.tx]; + const r = p.rate?.[p.rate.length - 1]; + return r && this.st.now - r[0] < 180 ? r : null; + } + + private speedRow(p: Person, r: Rate): HTMLElement { + const down = E('span', {}, `↓ ${bits(r[2])}`); + const up = E('span', { class: 'dl-faint' }, `↑ ${bits(r[1])}`); + this.speedEls.set(p.id, { p, down, up }); + return E('div', { class: 'dl-use-live', title: _('Right now') }, [down, up]); + } + + /** Each second's meter answer: the speeds in the cards on screen (whether someone is online waits for the status). */ + paintSpeed() { + for (const { p, down, up } of this.speedEls.values()) { + if (!down.isConnected) continue; + const r = this.speedOf(p); + if (!r) continue; + down.textContent = `↓ ${bits(r[2])}`; + up.textContent = `↑ ${bits(r[1])}`; + } + } + async togglePause(p: Person) { if (await attempt(() => api.personPause(p.id, !p.paused), fmt(p.paused ? _('%s resumed') : _('%s paused'), p.name))) await this.refresh(); diff --git a/web/src/admin/pages/person/header.ts b/web/src/admin/pages/person/header.ts index 413908a..e007c9b 100644 --- a/web/src/admin/pages/person/header.ts +++ b/web/src/admin/pages/person/header.ts @@ -8,7 +8,7 @@ import { icon } from '../../../shared/icons'; import { ago, bytes, date, initials, isoDay } from '../../../shared/format'; import { fmt } from '../../../shared/i18n'; import { copyPersonLink } from '../../invite'; -import { daysTile, speedTile } from '../../widgets/tiles'; +import { daysTile } from '../../widgets/tiles'; import { editNote, invite, moveToServer, newLink, remove, rename } from './dialogs'; import type { PersonPage } from './index'; @@ -66,13 +66,12 @@ export function headPart(page: PersonPage): HTMLElement { ]); } -/** Speed now and the last 30 days, the same tiles as the server Overview; speed only while a device is online. */ +/** Speed now (live) and the last 30 days, the same tiles as the server Overview; speed only while a device is online. */ export function trafficPart(page: PersonPage): HTMLElement { const p = page.p; - // Today on the router: the last day of the series. - const todayUse = page.series[page.series.length - 1]; + if (p.online) page.paintSpeed(); return E('div', { class: `dl-person-live${p.online ? '' : ' solo'}` }, [ - p.online ? speedTile(p.rate ?? [], page.st.now, todayUse ? [todayUse.rx, todayUse.tx] : [0, 0]) : '', + p.online ? page.speed.el : '', daysTile(page.series, fmt(_('%s this month'), bytes(p.month[0] + p.month[1]))), ]); } diff --git a/web/src/admin/pages/person/index.ts b/web/src/admin/pages/person/index.ts index e025eb9..6ba73bd 100644 --- a/web/src/admin/pages/person/index.ts +++ b/web/src/admin/pages/person/index.ts @@ -13,6 +13,9 @@ import { peopleUrl } from '../../urls'; import { addDevice, openDevice, type DeviceOpts } from '../../device'; import { coreFor, type Core } from '../../cores'; import { createPoller, repaint, type Poller } from '../../state/poller'; +import { LiveMeter, type MeterAnswer } from '../../state/meter'; +import { pollMeter } from '../../state/meterpoll'; +import { LiveSpeedTile } from '../../widgets/tiles'; import { headPart, trafficPart } from './header'; import { devicesPart } from './devices'; import { limitsPart } from './limits'; @@ -40,6 +43,10 @@ export class PersonPage { /** The same per device. */ devSeries: Record = {}; poller?: Poller; + /** Speed now, live (the meter's last 2 minutes of their devices): one tile for the page's life, and its poller. */ + meter = new LiveMeter(); + speed = new LiveSpeedTile(); + meterPoller?: Poller; /** Status every 15 s; the log and the traffic history every fourth time (and after a change). */ private ticks = 0; private fullNext = false; @@ -96,9 +103,30 @@ export class PersonPage { active: () => root.isConnected, apply: (data, quiet) => this.apply(data, quiet), }); + // One meter call a second while a device of theirs is online on a running server. + this.meterPoller?.stop(); + this.meterPoller = pollMeter( + this.meter, + () => root.isConnected && this.p.online > 0 && !!this.st.servers.find((x) => x.id === this.p.server)?.enabled, + () => this.paintSpeed(), + ); return root; } + /** The speed tile from the meter as it stands, with today's traffic. */ + paintSpeed() { + const day = this.series[this.series.length - 1]; + this.speed.update( + this.meter.speed( + this.p.server, + Date.now(), + this.p.devices.map((d) => d.id), + ), + day ? [day.rx, day.tx] : [0, 0], + false, + ); + } + private take(d: Loaded) { this.st = d.st; if (d.ev) this.events = d.ev; diff --git a/web/src/admin/pages/person/limits.ts b/web/src/admin/pages/person/limits.ts index a0e088c..f759e21 100644 --- a/web/src/admin/pages/person/limits.ts +++ b/web/src/admin/pages/person/limits.ts @@ -9,7 +9,9 @@ import { button } from '../../ui/button'; import { cancelButton, closeModal, modal } from '../../ui/modal'; import { liveField } from '../../ui/layout'; import { quotaHelp } from '../../netcheck'; -import { attachTip } from '../../ui/tooltip'; +import { pointTip } from '../../ui/glide'; +import { limitMeter } from '../../widgets/meter'; +import { paceOf, paceWords, weekAhead } from '../../../shared/pace'; import { icon } from '../../../shared/icons'; import { accessLabel, bytes, date, daysLeft, endsSoon, shiftDay } from '../../../shared/format'; import { fmt, num, plural } from '../../../shared/i18n'; @@ -128,21 +130,31 @@ function dataTile(page: PersonPage): HTMLElement { const p = page.p; const used = p.quota_used || p.month[0] + p.month[1]; const pct = p.quota_limit ? Math.min(100, (p.quota_used / p.quota_limit) * 100) : 0; - const bar = E('div', { class: `dl-meter${pct >= 100 ? ' bad' : pct >= 90 ? ' warn' : ''}` }, [ - E('i'), - p.quota_limit ? E('span', { class: 'mark', title: _('Alert at 90%') }) : '', - ]); - (bar.firstChild as HTMLElement).style.width = `${pct}%`; - if (p.quota_limit) - attachTip(bar, () => [ - E('div', { class: 'dl-tip-title' }, fmt(_('%s%% used'), num(pct, 1))), - E( - 'div', - { class: 'dl-muted' }, - `${fmt(_('%s of %s'), bytes(p.quota_used), bytes(p.quota_limit))} · ${fmt(_('%s left'), bytes(Math.max(0, p.quota_limit - p.quota_used)))}`, - ), - E('div', { class: 'dl-faint' }, _('Alert at 90%')), - ]); + // The pace lately (the person's days) and where a week at it takes them, dashed past the fill. + const pace = paceOf(page.series.map((d) => d.rx + d.tx)); + const bar = limitMeter(pct, p.quota_limit ? weekAhead(p.quota_used, p.quota_limit, pace) : 0, p.quota_limit ? 0.9 : undefined); + if (p.quota_limit) { + const paceText = paceWords(p.quota_used, p.quota_limit, pace, p.quota_period === 'month', page.today); + pointTip( + bar, + () => [ + E('div', { class: 'dl-glide-head' }, [ + E('b', {}, fmt(_('%s%% used'), num(pct, 1))), + E('span', { class: 'dl-faint' }, _('Alert at 90%')), + ]), + E( + 'div', + { class: 'dl-muted' }, + `${fmt(_('%s of %s'), bytes(p.quota_used), bytes(p.quota_limit))} · ${fmt(_('%s left'), bytes(Math.max(0, p.quota_limit - p.quota_used)))}`, + ), + pct < 100 && paceText ? E('div', { class: 'dl-glide-note' }, paceText) : '', + ], + () => { + const r = bar.getBoundingClientRect(); + return [r.left + (r.width * pct) / 100, r.top]; + }, + ); + } const period = seg( [ ['month', _('Monthly')], diff --git a/web/src/admin/pages/server.ts b/web/src/admin/pages/server.ts index eb920b7..5684c60 100644 --- a/web/src/admin/pages/server.ts +++ b/web/src/admin/pages/server.ts @@ -24,6 +24,7 @@ import { coreOf } from '../cores'; import { installAwg } from '../pkgs'; import { createPoller, focusInside, repaint, type Poller } from '../state/poller'; import { LiveMeter, type MeterAnswer } from '../state/meter'; +import { pollMeter } from '../state/meterpoll'; import { ServerOverview } from './overview'; import { PeoplePage } from './people'; @@ -65,7 +66,7 @@ export class ServerPage { secEl = E('div', {}); bodyEl = E('div', { class: 'dl-srvbody' }); poller?: Poller; - /** The live meter's last 2 minutes, every server's (the Overviews' Speed now), and its poller. */ + /** The live meter's last 2 minutes, every server's (Speed now on the Overviews and People lists), and its poller. */ meter = new LiveMeter(); meterPoller?: Poller; @@ -104,23 +105,16 @@ export class ServerPage { this.ov[this.current().id]?.update(n, quiet); }, }); - // Speed now, live: one meter call a second while the Overview of a running server is on screen - // (the router keeps the last two minutes and writes them out while someone asks). A failed call is said in the tile, not in a - // second "not answering" toast beside the status poller's. + // Speed now, live, while the Overview of a running server or its People list is on screen. this.meterPoller?.stop(); - this.meterPoller = createPoller({ - fetch: () => - api.meter(this.meter.since(Date.now())).then( - (meter) => ({ meter }), - (e) => ({ error: errorText(e) }), - ), - every: 1, - active: () => this.section === 'overview' && this.root.isConnected && this.current().enabled, - apply: (r) => { - this.meter.take(r, Date.now()); + this.meterPoller = pollMeter( + this.meter, + () => (this.section === 'overview' || this.section === 'people') && this.root.isConnected && this.current().enabled, + () => { this.ov[this.current().id]?.paintSpeed(); + this.pp[this.current().id]?.paintSpeed(); }, - }); + ); return this.root; } @@ -220,7 +214,7 @@ export class ServerPage { pp.filter = filter as PeoplePage['filter']; if (pp.el) pp.decorate(); } else if (filter) { - const page = (this.pp[this.current().id] = new PeoplePage()); + const page = (this.pp[this.current().id] = new PeoplePage(this.meter)); page.filter = filter as PeoplePage['filter']; } this.showSection(k); @@ -261,7 +255,7 @@ export class ServerPage { return pp.el; } const holder = E('div', {}, E('p', { class: 'dl-muted' }, _('Loading people…'))); - const page = (this.pp[srv.id] ??= new PeoplePage()); + const page = (this.pp[srv.id] ??= new PeoplePage(this.meter)); page .embed(st, srv.id) .then((node) => { diff --git a/web/src/admin/state/meter.ts b/web/src/admin/state/meter.ts index 38d532a..ef70b7c 100644 --- a/web/src/admin/state/meter.ts +++ b/web/src/admin/state/meter.ts @@ -1,7 +1,8 @@ -// The live meter as the Servers page keeps it (rpc meter, polled once a -// second while an Overview is on screen): the answers merged into the last two -// minutes, and one server's part of them for its Speed now tile. No DOM and no -// RPC here: the poller is the page's (pages/server.ts), the tile widgets/tiles. +// The live meter as a page keeps it (rpc meter, polled once a second while a +// speed is on screen): the answers merged into the last two minutes, and one +// server's part of them, or one person's devices on it, for Speed now. No DOM +// and no RPC here: the poller is the page's (pages/server.ts, pages/person), +// the tile widgets/tiles. import type { Meter, MeterPoint } from '../api'; @@ -84,12 +85,26 @@ export class LiveMeter { this.error = ''; } - /** Server `id`'s points at page time `ms` (none once they are not live), placed against the meter's newest point. */ - speed(id: string, ms: number): LiveSpeed { + /** + * Server `id`'s points at page time `ms` (none once they are not live), placed against the meter's newest point; + * with `devices`, only theirs added up (a person's speed). + */ + speed(id: string, ms: number, devices?: string[]): LiveSpeed { const error = this.failed >= LOST_AFTER ? this.error : null; const live = this.live(ms) ? this.points : []; + const sum = (p: MeterPoint): Rate => { + if (!devices) return [p.ts, p.servers[id][0], p.servers[id][1]]; + const r: Rate = [p.ts, 0, 0]; + for (const d of devices) { + const v = p.dev?.[d]; + if (!v) continue; + r[1] += v[0]; + r[2] += v[1]; + } + return r; + }; // A second its tunnel was not read has no point of its own. - const pts = live.flatMap((p): Rate[] => (p.servers[id] ? [[p.ts, p.servers[id][0], p.servers[id][1]]] : [])); + const pts = live.flatMap((p): Rate[] => (p.servers[id] ? [sum(p)] : [])); const end = live.length ? live[live.length - 1].ts : 0; const span = this.keep - 1; const last = pts[pts.length - 1]; diff --git a/web/src/admin/state/meterpoll.ts b/web/src/admin/state/meterpoll.ts new file mode 100644 index 0000000..f165ad3 --- /dev/null +++ b/web/src/admin/state/meterpoll.ts @@ -0,0 +1,25 @@ +// The live meter's poller: one meter call a second while a speed is on screen +// (the router keeps the last two minutes and writes them out while someone +// asks). A failed call is said in the tile, not in a second "not answering" +// toast beside the page's status poller. + +import { api } from '../api'; +import { errorText } from '../ui/toast'; +import { createPoller, type Poller } from './poller'; +import type { LiveMeter, MeterAnswer } from './meter'; + +export function pollMeter(meter: LiveMeter, active: () => boolean, paint: () => void): Poller { + return createPoller({ + fetch: () => + api.meter(meter.since(Date.now())).then( + (m) => ({ meter: m }), + (e) => ({ error: errorText(e) }), + ), + every: 1, + active, + apply: (r) => { + meter.take(r, Date.now()); + paint(); + }, + }); +} diff --git a/web/src/admin/styles/base.css b/web/src/admin/styles/base.css index 1adc287..12ac352 100644 --- a/web/src/admin/styles/base.css +++ b/web/src/admin/styles/base.css @@ -21,7 +21,9 @@ --dl-info-wash: var(--info-a15, color-mix(in srgb, var(--dl-info) 15%, transparent)); --dl-track: var(--foreground-a10, color-mix(in srgb, var(--dl-fg) 10%, transparent)); --dl-chart-1: var(--chart-blue, #3a83f7); - --dl-chart-2: var(--chart-green, var(--dl-ok)); + /* The connection map's arcs (map.ts LIVE and RECENT, mapcn's): every chart draws live and past in them. */ + --dl-live: #3b82f6; + --dl-recent: #8a8a8a; --dl-ring: var(--ring, #3a83f7); --dl-primary: var(--primary, var(--dl-fg)); --dl-primary-fg: var(--primary-foreground, var(--dl-elevated)); @@ -78,14 +80,6 @@ .dl-grid2 { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); gap: 0 16px; } @media (max-width: 960px) { .dl-grid2 { grid-template-columns: minmax(0, 1fr); } } -/* chart */ -.dl-chart { display: block; width: 100%; height: 120px; } -.dl-bar-down { fill: var(--dl-chart-1); } -.dl-bar-up { fill: var(--dl-chart-2); opacity: .8; } -.dl-legend { display: flex; gap: 16px; font-size: 12px; color: var(--dl-fg-muted); margin-top: 8px; } -.dl-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 999px; margin-right: 6px; vertical-align: 0; } -.dl-legend .down { background: var(--dl-chart-1); } .dl-legend .up { background: var(--dl-chart-2); } - /* activity */ .dl-events { list-style: none; margin: 0; padding: 0; } .dl-events li { display: flex; gap: 12px; align-items: baseline; padding: 8px 0; border-top: 1px solid var(--dl-line); font-size: 14px; line-height: 20px; min-width: 0; } diff --git a/web/src/admin/styles/charts.css b/web/src/admin/styles/charts.css new file mode 100644 index 0000000..dc477b7 --- /dev/null +++ b/web/src/admin/styles/charts.css @@ -0,0 +1,90 @@ +/* Charts (ui/plot.ts, widgets/lines.ts, days.ts, meter.ts). The speed lines, markers, ticks and meters speak the + connection map's language: live is its blue and solid, the past its grey, lines 2 px with round ends, what is + secondary dashed like an arc, a soft zone under a line, ringed markers with a halo while live, the replay's tick + for a picked moment. Days of traffic are stacked bars in the colours of the tiles' ↓ and ↑ numbers. Reading a + chart (shared/scrub.ts) and its tooltip (ui/glide.ts). */ + +.dl-plot { position: relative; width: 100%; min-width: 0; } +.dl-plot svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; display: block; } +.dl-plot .ln { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; opacity: .85; } +.dl-plot .ln.live { stroke: var(--dl-live); } +.dl-plot .ln.past { stroke: var(--dl-recent); } +.dl-plot .ln.thin { stroke-width: 1.5; } +.dl-plot .dash { stroke-dasharray: 4 4; } +.dl-plot .live.z0 { stop-color: var(--dl-live); stop-opacity: .2; } +.dl-plot .live.z1 { stop-color: var(--dl-live); stop-opacity: 0; } +.dl-plot .mk { fill: color-mix(in srgb, var(--dl-recent) 22%, var(--dl-elevated)); stroke: var(--dl-recent); stroke-width: 2; } +.dl-plot .mk.live { fill: color-mix(in srgb, var(--dl-live) 22%, var(--dl-elevated)); stroke: var(--dl-live); } +.dl-plot .mk.on { fill: var(--dl-fg); stroke: var(--dl-card); } +.dl-plot .halo { fill: var(--dl-live); transform-box: fill-box; transform-origin: center; animation: dl-halo 2s ease-out infinite; pointer-events: none; } +@keyframes dl-halo { 0% { transform: scale(1); opacity: .35; } 100% { transform: scale(3.2); opacity: 0; } } +.dl-plot .tick-ring { stroke: var(--dl-card); stroke-width: 6; stroke-linecap: round; } +.dl-plot .tick { stroke: var(--dl-fg); stroke-width: 2; stroke-linecap: round; } +.dl-plot .band { fill: var(--dl-fg); opacity: .06; } +.dl-plot .none { fill: var(--dl-recent); opacity: .5; } +/* Stacked days: download at the base, upload on top, the colours of the ↓ and ↑ numbers (.dl-dn, .dl-up). */ +.dl-plot .dn { fill: var(--dl-accent); opacity: .9; } +.dl-plot .up { fill: var(--dl-ok); opacity: .9; } +.dl-plot .dim { opacity: .35; } +.dl-plot .on { opacity: 1; } +.dl-plot rect.none { fill: var(--dl-track); opacity: 1; } +.dl-days-key { display: inline-flex; gap: 14px; font-variant-numeric: tabular-nums; } +.dl-days-key > span { display: inline-flex; align-items: center; gap: 6px; } +.dl-days-key i { width: 8px; height: 8px; border-radius: 2px; } +.dl-days-key i.dn { background: var(--dl-accent); } +.dl-days-key i.up { background: var(--dl-ok); } +/* A device's strip: the places strip's track and segments. */ +.dl-plot .track { fill: var(--dl-track); } +.dl-plot .seg { fill: var(--dl-recent); } +.dl-plot .seg.live { fill: var(--dl-live); } +.dl-dstrip { flex: 1; } + +/* Reading a chart: it takes focus, the pointer is a crosshair, the picked point's words are the accent. */ +.scrub { outline: none; cursor: crosshair; border-radius: 6px; } +.scrub:focus-visible { box-shadow: 0 0 0 2px var(--dl-ring); } +.dl-picked .dl-metric-label, .dl-sub.dl-picked, .dl-picked > .dl-sub { color: var(--dl-accent); font-variant-numeric: tabular-nums; } +.dl-speed-cols.dl-picked .dl-speed-val { color: color-mix(in oklab, var(--dl-accent) 55%, var(--dl-fg)); } +.offscreen { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } + +/* The chart tooltip: anchored above a point, gliding to the next; a map chip's blur. */ +.dl-glide { left: 0; top: 0; display: flex; flex-direction: column; gap: 6px; min-width: 150px; padding: 10px 12px; border-radius: 12px; pointer-events: none; + background: color-mix(in srgb, var(--dl-elevated) 88%, transparent); backdrop-filter: blur(8px); } +.dl-glide.glides { transition: transform .18s cubic-bezier(.23, 1, .32, 1); } +.dl-glide-head { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; } +.dl-glide-head b { font-weight: 500; } +.dl-glide-big { font-size: 18px; line-height: 22px; font-weight: 500; letter-spacing: -.01em; font-variant-numeric: tabular-nums; } +.dl-glide-note { font-size: 11.5px; color: var(--dl-fg-muted); white-space: normal; max-width: 240px; } +.dl-glide-note.bad { color: var(--dl-bad); } +.dl-glide-split { display: flex; gap: 2px; height: 6px; width: 150px; } +.dl-glide-split i { display: block; border-radius: 3px; min-width: 3px; } +.dl-glide-split .dn { background: var(--dl-accent); } +.dl-glide-split .up { background: var(--dl-ok); } +.dl-glide .dl-tip-row .dl-swatch { width: 8px; height: 8px; border-radius: 50%; } + +/* The meter: a places strip's track and fill; the week ahead dashed; the alert the replay's tick. */ +.dl-smeter { position: relative; height: 6px; border-radius: 3px; background: var(--dl-track); margin: 4px 0; outline: none; } +.dl-smeter > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; background: var(--dl-live); } +.dl-smeter.warn > i { background: var(--dl-warn); } +.dl-smeter.bad > i { background: var(--dl-bad); } +.dl-smeter > b { position: absolute; top: 2px; height: 2px; margin-left: 4px; opacity: .85; color: var(--dl-live); + background: repeating-linear-gradient(90deg, currentColor 0 4px, transparent 4px 8px); } +.dl-smeter.warn > b { color: var(--dl-warn); } +.dl-smeter .mark { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; border-radius: 1px; background: var(--dl-fg); box-shadow: 0 0 0 2px var(--dl-card); } +.dl-smeter.parts { display: flex; gap: 2px; background: none; } +.dl-smeter.parts > i { position: static; flex: 1 1 0; min-width: 3px; } +.dl-smeter:focus-visible { box-shadow: 0 0 0 2px var(--dl-ring); } + +/* Speed now, waiting: the dashed track where the line will stand; while collecting, a shimmer runs along it + (the map's replay along an arc). */ +.dl-speed-wait i { display: block; height: 2px; order: 2; position: relative; opacity: .6; + background: repeating-linear-gradient(90deg, var(--dl-recent) 0 4px, transparent 4px 8px); } +.dl-speed-wait i.run { opacity: 1; + background: linear-gradient(90deg, transparent, var(--dl-live), transparent) no-repeat -40% 0 / 40% 100%, repeating-linear-gradient(90deg, color-mix(in srgb, var(--dl-recent) 60%, transparent) 0 4px, transparent 4px 8px); + -webkit-mask: repeating-linear-gradient(90deg, #000 0 4px, transparent 4px 8px); mask: repeating-linear-gradient(90deg, #000 0 4px, transparent 4px 8px); + animation: dl-run 1.6s linear infinite; } +@keyframes dl-run { to { background-position: 140% 0, 0 0; } } + +@media (prefers-reduced-motion: reduce) { + .dl-plot .halo { animation: none; opacity: 0; } + .dl-speed-wait i.run { animation: none; } +} diff --git a/web/src/admin/styles/index.ts b/web/src/admin/styles/index.ts index 3693181..b555ef1 100644 --- a/web/src/admin/styles/index.ts +++ b/web/src/admin/styles/index.ts @@ -26,6 +26,7 @@ import drawer from './drawer.css'; import settings from './settings.css'; import components from './components.css'; import access from './access.css'; +import charts from './charts.css'; const CSS = [ base, @@ -43,6 +44,7 @@ const CSS = [ settings, components, access, + charts, ].join('\n'); /** A