Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f8130e39a8 | ||
|
|
18e3013047 |
No files matched your search
@@ -544,7 +544,7 @@ Glass icons (`ui/glass.ts`) draw a tinted back shape, the same shape blurred beh
|
||||
| `t-grey` | `#cfcfcd` → `#5a5a59` | `#a9a9a7` → `#3d3d3c` | Device cards (default), access rows, Add |
|
||||
| `t-blue` | `#a6d9ff` → `#1d84e6` | `#7cc4ff` → `#0a6fd6` | This device, first device, kinds, reach tiles that are on, the LAN Bypass row when on, lock |
|
||||
| `t-green` | `#a8f29c` → `#30d158` | `#82e070` → `#30d158` | "Everything works" (demo) |
|
||||
| `t-orange` | `#ffc08f` → `#ff8d28` | *same as dark* | Warn notices, Reconnect question |
|
||||
| `t-orange` | `#ffc08f` → `#ff8d28` | *same as dark* | Warn notices |
|
||||
| `t-red` | `#ffadad` → `#ff383c` | `#ff9090` → `#ff383c` | Bad notices, Remove question |
|
||||
|
||||
Frosted pane: dark `--gi-a .58 / --gi-b .14` white with a `.5` rim and no edge stroke. Light uses a `.72 / .5` grey pane, a `.9` rim and an `rgba(0,0,0,.11)` edge, with dark detail strokes.
|
||||
@@ -779,7 +779,8 @@ The ⋯ menu, the pick pills' popups and the page code card are one kind of thin
|
||||
|
||||
| Variant | Fill / text | Weight | Use |
|
||||
|---|---|---|---|
|
||||
| `accent` | accent / white | 600 | The one primary action: Add this device, Reconnect, Open securely, Download (router) |
|
||||
| `accent` | accent / white | 600 | The one primary action: Add this device, Open securely, Download (router) |
|
||||
| `warn` | warn / `#241300` | 600 | Reconnect (its sheet): the colour Reconnect has in the ⋯ menu; dark ink, white on it reads at 2.3:1 |
|
||||
| `tint` | accent 13% / accent | 600 | A card's **Connect** (quiet primary) |
|
||||
| `soft` | knob / text | 500 | Cancel, "Add it from the device", Show key, Copy, Start over |
|
||||
| `red` | bad / white | 600 | Remove |
|
||||
@@ -819,7 +820,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 +870,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, kept inside the axis (each of the month's ends hides where "Today" comes within 6 px of it, measured: the words' widths follow the language), 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`.
|
||||
@@ -904,13 +907,15 @@ A repaint keeps the rows on the page and changes what they hold in place, the sa
|
||||
|
||||
- **Tooltip:** one 26 px pill in toast colours under the keys. It appears after 420 ms of hover, then follows the pointer (or Tab) from key to key at once, gliding from where it stands, and says "Copied" after a copy. Back on a key while it still fades out, it turns back from there.
|
||||
|
||||
**Question view** (`.ask`: Reconnect, Remove):
|
||||
**Question view** (`.ask`: Remove):
|
||||
|
||||
- left-aligned, as iOS asks now, with 24 px top padding;
|
||||
- a 64 px glass icon in the action's tone, a 20/28 500 question and a 15/21 `text-2` paragraph;
|
||||
- two equal buttons: **Cancel** (soft) and the action (accent for Reconnect, red for Remove);
|
||||
- two equal buttons: **Cancel** (soft) and the action (red for Remove);
|
||||
- no × beside them.
|
||||
|
||||
**Reconnect view** (`flows/device-actions.ts`): Add a device without its name. The head ("Reconnect Phone"), what happens as its subline, the kinds with what it is now ringed, the LAN Bypass row as it stands, and a `warn` block **Reconnect** (refresh icon) where the name field would be, 12 px under the row. × stays.
|
||||
|
||||
**Secure view:** centred lock glass, an accent "Open securely" button and a short note.
|
||||
|
||||
### ⋯ Menu · `ui/menu.ts`
|
||||
@@ -919,7 +924,7 @@ Apple's iOS 26 menu (Figma kit, "Menu – iPhone"), made compact: smaller type a
|
||||
|
||||
**Surface:** a dropdown (see *Dropdowns*): at least 210 wide, radius 24, padding `6 0`.
|
||||
|
||||
**Rows**, 6 px in, in groups (copy actions, then Rename, Reconnect, Remove): 8 px above and below the words (34 high, 50 with a line under the label), radius 18 (concentric); the icon 14 px in from the rounded edge, more than the 10 px from it to the words, so it doesn't crowd the curve; 12 px at the right end: a 16 px icon, a 14 px 400 label (line 18) and an 11.5 px subtitle under it where the item has one (the address it copies, tabular figures), 1 px apart. Reconnect `warn`, Remove destructive.
|
||||
**Rows**, 6 px in, in groups (copy actions; LAN Bypass; then Rename, Reconnect, Remove): 8 px above and below the words (34 high, 50 with a line under the label), radius 18 (concentric); the icon 14 px in from the rounded edge, more than the 10 px from it to the words, so it doesn't crowd the curve; 12 px at the right end: a 16 px icon, a 14 px 400 label (line 18) and an 11.5 px subtitle under it where the item has one (the address it copies, tabular figures; On or Off under LAN Bypass), 1 px apart. Reconnect `warn`, Remove destructive.
|
||||
|
||||
**Separators** between groups: 13 px high, their 1 px line 16 px in from the edge.
|
||||
|
||||
@@ -935,12 +940,14 @@ Apple's iOS 26 menu (Figma kit, "Menu – iPhone"), made compact: smaller type a
|
||||
|
||||
### App picker · `ui/seg.ts`
|
||||
|
||||
- **Track:** 48 high, radius 16, `field`, padding `0 4`.
|
||||
- **Track:** 48 high, radius 16, `field`, padding `0 4`. The sheet opens on AmneziaWG, the first item (or the app the device was set up with).
|
||||
- **WireGuard has no item of its own** except for a router (its own package): with the disguise off it takes AmneziaWG's file and code through the same menus, so AmneziaWG's item is both. The words name both ("In AmneziaWG or WireGuard:", "Open AmneziaWG or WireGuard", "import … in AmneziaWG or WireGuard"), a hint line under AmneziaWG's store says WireGuard works too (its name links to its store), and the share badge's small line says "Straight into the app" (two names do not fit it). On Linux a last step gives wireguard-tools' `wg-quick`.
|
||||
- **Items:** icons only (20 px) at 56 px each. The picked item takes the remaining width (`flex-grow`) and shows its name.
|
||||
- **Pill:** 40 px, radius 12. It stretches like skiper21's tabs: the leading edge reaches the new item first and the trailing edge follows. At rest it sits on its item by layout alone (4 px and the items before it on the left, the items after it on the right, each 56 or 44 px), so the sheet changing width carries it along with nothing watching.
|
||||
- **Item colours:** idle `text-3`, hover `text-2`, picked `text`.
|
||||
- **A name too long for its place** (four apps on a phone): it fades to nothing at the edge it runs past (an 18 px alpha mask, the right edge at its start). Under the pointer, or with the keyboard's focus, it glides to its end a beat later (240 ms) at 40 px/s, eased at both ends, the fade sliding to the left edge (320 ms, `--fade-l`/`--fade-r` as registered properties); it glides back as the pointer leaves, from where it stands. On touch a tap on the picked item glides it there and back. Another pick puts every name back at its start.
|
||||
|
||||
### Kinds picker · `flows/add.ts`
|
||||
### Kinds picker · `flows/device-form.ts` (Add a device, Reconnect)
|
||||
|
||||
- **Tiles:** four in a grid (`--n` columns, gap 8): PC, Mobile, Router, Other. Each is 56 high, radius 14, `field`.
|
||||
- **Icons and labels:** a 26 px blue glass icon, greyscale at 55% opacity until picked. The label sits under the tile at 12/16 500.
|
||||
@@ -964,7 +971,7 @@ One choice with a switch (Add a device's **LAN Bypass**). A line that unfolds un
|
||||
- Two lines: top 12/16 `text-2`, main 15/20 500.
|
||||
- A 16 px trailing mark: chevron for an action, "open" for a page in a new tab.
|
||||
- `.primary` (the one thing to tap in a step): the icon tile is accent-soft / accent.
|
||||
- `.badges2`: two side by side, no trailing mark.
|
||||
- `.badges2`: two side by side, no trailing mark, while each has 150 px, room for its words on one line (a store's name never wraps); narrower, one under the other.
|
||||
- Inside an inset row: knob 65% over field, hover `knob`, one step above the row.
|
||||
|
||||
### Set-up sheet · `flows/setup-view.ts`
|
||||
@@ -975,7 +982,7 @@ One choice with a switch (Add a device's **LAN Bypass**). A line that unfolds un
|
||||
|
||||
**"How to" path:** `Open AmneziaWG › + › Import Tunnel(s) from File…` in 13 px `text-2`, the app's own words in `text` 500.
|
||||
|
||||
**Scan line:** "In WireGuard: + › Create from QR code". Where iOS and Android name a step differently, that word alternates every 3 s, with the or Android mark beside it.
|
||||
**Scan line:** "In AmneziaWG: + › Create from QR code" ("In AmneziaWG or WireGuard:" with the disguise off). Where iOS and Android name a step differently, that word alternates every 3 s, with the or Android mark beside it.
|
||||
|
||||
**The way:** a picture of the connection, with no buttons.
|
||||
|
||||
@@ -1475,7 +1482,7 @@ CSS hover and press transitions (`scale(.8–.98)`, colours, the switch) are not
|
||||
- **Short, plain and whole.** "Your devices can't connect until it's resumed." A sentence that adds to a title never repeats it. Full rules for strings and Russian: `rules/i18n.md`.
|
||||
- **Buttons are verbs, with no ellipsis:** Connect, Update, Add device, Reconnect, Remove, Cancel, Open securely, Show key, Copy.
|
||||
- **Statuses are short and fit one line.** The full wording goes in the tooltip: "Settings changed, update needed".
|
||||
- **Other apps are quoted word for word, in each language:** "+ › Insert › Continue" for AmneziaVPN, "Import Tunnel(s) from File…" for WireGuard.
|
||||
- **Other apps are quoted word for word, in each language:** "+ › Insert › Continue" for AmneziaVPN, "Import Tunnel(s) from File…" for WireGuard, "+ › Import config from Clipboard" for V2RayTun on Android, "+ › Import from clipboard" on Windows.
|
||||
- **Honest warnings sit where the choice is made**, said once: one line where space is short, the why in `title`.
|
||||
- **Numbers, sizes and dates** follow the page's language.
|
||||
- **The language pill switches in place.**
|
||||
|
||||
@@ -315,8 +315,10 @@ By hand: <kbd>Settings</kbd> › <kbd>Remove Dawnline from this router</kbd>
|
||||
|
||||
<br>
|
||||
|
||||
AmneziaVPN or AmneziaWG on phones and computers, and plain WireGuard when the
|
||||
disguise is off. The portal shows each person the app for their system and how
|
||||
AmneziaVPN or AmneziaWG on phones and computers, V2RayTun on Android (its
|
||||
`awg://` link; not with the Maximum disguise, which it cannot
|
||||
run yet),
|
||||
and plain WireGuard when the disguise is off. The portal shows each person the app for their system and how
|
||||
to add the connection in it.
|
||||
|
||||
</details>
|
||||
@@ -378,6 +380,14 @@ are kept in `/var/run/dawnline` and flushed to flash at most hourly. Access
|
||||
changes reach the tunnel with `awg syncconf`, without restarting the interface;
|
||||
`dawnline log` on the router shows the service log.
|
||||
|
||||
Everything service-related also goes to the router's system log, one line per
|
||||
event with its syslog priority: `logread -e dawnline` shows
|
||||
`[info] [service] starting`, `[info] [apply] configuration applied in 310 ms · …`,
|
||||
tunnels and the portal going down and back, crashes with what syslog knew about
|
||||
them, every settings change (`admin changed settings · domain: lan → home`) and
|
||||
people's and devices' changes. Settings → Logs & history → System log picks the
|
||||
level: errors, warnings, normal or verbose (each step of a start and an apply).
|
||||
|
||||
## 🧰 Development
|
||||
|
||||
```
|
||||
|
||||
+13
-2
@@ -318,8 +318,10 @@ sh /tmp/dawnline-uninstall.sh --dry-run
|
||||
|
||||
<br>
|
||||
|
||||
AmneziaVPN или AmneziaWG на телефонах и компьютерах, а обычный WireGuard, если
|
||||
маскировка выключена. Портал показывает каждому приложение для его системы и
|
||||
AmneziaVPN или AmneziaWG на телефонах и компьютерах, V2RayTun на Android (по
|
||||
ссылке `awg://`; кроме максимальной маскировки, её он пока не
|
||||
умеет), а
|
||||
обычный WireGuard, если маскировка выключена. Портал показывает каждому приложение для его системы и
|
||||
как добавить в нём подключение.
|
||||
|
||||
</details>
|
||||
@@ -382,6 +384,15 @@ AmneziaVPN или AmneziaWG на телефонах и компьютерах,
|
||||
чаще раза в час. Изменения доступа доходят до туннеля через `awg syncconf`, без
|
||||
перезапуска интерфейса; `dawnline log` на роутере показывает журнал служб.
|
||||
|
||||
Всё, что касается служб, попадает и в системный журнал роутера, строкой на
|
||||
событие с приоритетом syslog: `logread -e dawnline` покажет
|
||||
`[info] [service] starting`, `[info] [apply] configuration applied in 310 ms · …`,
|
||||
падения и восстановление туннелей и портала, сбои с тем, что о них знал syslog,
|
||||
каждое изменение настроек (`admin changed settings · domain: lan → home`) и
|
||||
изменения людей и устройств. Уровень выбирается в «Настройки → Журналы и
|
||||
история → Системный журнал»: ошибки, предупреждения, обычный или подробный
|
||||
(каждый шаг запуска и применения настроек).
|
||||
|
||||
## 🧰 Разработка
|
||||
|
||||
```
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-dawnline
|
||||
PKG_VERSION:=0.16.3
|
||||
PKG_VERSION:=0.18.0
|
||||
PKG_RELEASE:=1
|
||||
PKG_LICENSE:=MIT
|
||||
# po/<lang>/dawnline.po becomes luci-i18n-dawnline-<lang> (luci.mk), released
|
||||
|
||||
@@ -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"
|
||||
@@ -378,6 +389,10 @@ msgstr "Интерфейса %s нет."
|
||||
msgid "%s does not overlap other networks."
|
||||
msgstr "%s не пересекается с другими сетями."
|
||||
|
||||
#: web/src/admin/cores/awg.ts
|
||||
msgid "%s does not resolve right now, and V2RayTun on Android connects by IP address only."
|
||||
msgstr "Сейчас не удаётся узнать IP-адрес %s, а V2RayTun на Android подключается только по IP-адресу."
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/health.uc
|
||||
msgid "%s does not resolve."
|
||||
msgstr "%s не разрешается в IP-адрес."
|
||||
@@ -696,6 +711,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 +931,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"
|
||||
@@ -1068,6 +1091,10 @@ msgstr "%s: %s из 4"
|
||||
msgid "%s: <%s> is not a tag AmneziaWG apps accept: use <b 0x…> with an even number of hex digits, <r N>, <rc N> or <rd N> with N from 1 to 1000, or <t>."
|
||||
msgstr "%s: тег <%s> не примут приложения AmneziaWG: используйте <b 0x…> с чётным числом шестнадцатеричных цифр, <r N>, <rc N> или <rd N> с N от 1 до 1000 либо <t>."
|
||||
|
||||
#: web/src/admin/events/model.ts
|
||||
msgid "%s: automatic"
|
||||
msgstr "%s: автоматически"
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/access.uc
|
||||
msgid "%s: the device's own network handles it."
|
||||
msgstr "%s: этот трафик идёт через собственную сеть устройства."
|
||||
@@ -1107,6 +1134,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 +1171,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 ч"
|
||||
@@ -2155,6 +2190,10 @@ msgstr "Выберите свободный порт от 1 до 65535 (кром
|
||||
msgid "Choose a server on their page"
|
||||
msgstr "Выберите сервер на странице человека"
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/schema.uc
|
||||
msgid "Choose a system log level: errors, warnings, normal or verbose."
|
||||
msgstr "Выберите уровень системного журнала: ошибки, предупреждения, обычный или подробный."
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/awg.uc
|
||||
msgid "Choose another interface name in the server settings."
|
||||
msgstr "Выберите другое имя интерфейса в настройках сервера."
|
||||
@@ -2236,10 +2275,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 +2592,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."
|
||||
@@ -2626,6 +2665,10 @@ msgstr "Устройство %s: настройки изменены"
|
||||
msgid "Device %s changed network %s"
|
||||
msgstr "Устройство %s сменило сеть %s"
|
||||
|
||||
#: web/src/admin/events/render.ts
|
||||
msgid "Device %s changed on the portal"
|
||||
msgstr "Устройство %s: настройки изменены через портал"
|
||||
|
||||
#: web/src/admin/events/render.ts
|
||||
msgid "Device %s connected"
|
||||
msgstr "Устройство %s подключилось"
|
||||
@@ -3054,6 +3097,10 @@ msgstr "Укажите оба времени, например 07:00 и 23:00."
|
||||
msgid "Error: %s"
|
||||
msgstr "Ошибка: %s"
|
||||
|
||||
#: web/src/admin/pages/settings/logs.ts
|
||||
msgid "Errors only"
|
||||
msgstr "Только ошибки"
|
||||
|
||||
#: web/src/admin/pages/settings/logs.ts
|
||||
msgid "Every 10 min"
|
||||
msgstr "Каждые 10 мин"
|
||||
@@ -3500,6 +3547,21 @@ msgstr "Импортировать"
|
||||
msgid "Import JSON"
|
||||
msgstr "Импорт JSON"
|
||||
|
||||
#: web/src/admin/cores/awg.ts
|
||||
msgctxt "V2RayTun app"
|
||||
msgid "Import config from Clipboard"
|
||||
msgstr "Импорт из буфера обмена"
|
||||
|
||||
#: web/src/admin/cores/awg.ts
|
||||
msgctxt "V2RayTun app"
|
||||
msgid "Import config from QRcode"
|
||||
msgstr "Импорт из QR-кода"
|
||||
|
||||
#: web/src/admin/cores/awg.ts
|
||||
msgctxt "V2RayTun app"
|
||||
msgid "Import from clipboard"
|
||||
msgstr "Импорт из буфера обмена"
|
||||
|
||||
#: web/src/admin/pages/settings/backups.ts
|
||||
msgid "Import?"
|
||||
msgstr "Импортировать?"
|
||||
@@ -3901,11 +3963,20 @@ msgstr "Не удалось создать ключ."
|
||||
msgid "LAN Bypass"
|
||||
msgstr "Обход локальной сети"
|
||||
|
||||
#: web/src/admin/events/model.ts
|
||||
msgid "LAN Bypass off"
|
||||
msgstr "обход локальной сети выкл."
|
||||
|
||||
#: web/src/admin/events/model.ts
|
||||
msgid "LAN Bypass on"
|
||||
msgstr "обход локальной сети вкл."
|
||||
|
||||
#: web/src/admin/widgets/tiles.ts
|
||||
msgid "Last 30 days"
|
||||
msgstr "За 30 дней"
|
||||
|
||||
#: web/src/admin/device.ts
|
||||
#: web/src/admin/widgets/spark.ts
|
||||
msgid "Last 7 days"
|
||||
msgstr "За 7 дней"
|
||||
|
||||
@@ -3947,6 +4018,7 @@ msgstr "Сертификат Let’s Encrypt для портала"
|
||||
msgid "Limit hours"
|
||||
msgstr "Ограничить часы"
|
||||
|
||||
#: web/src/admin/cores/awg.ts
|
||||
#: web/src/admin/invite.ts
|
||||
msgid "Link copied"
|
||||
msgstr "Ссылка скопирована"
|
||||
@@ -4623,6 +4695,10 @@ msgstr "Бессрочно"
|
||||
msgid "None: without the tunnel those devices have no DNS."
|
||||
msgstr "Нет: без туннеля у этих устройств не будет DNS."
|
||||
|
||||
#: web/src/admin/pages/settings/logs.ts
|
||||
msgid "Normal"
|
||||
msgstr "Обычный"
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/backup.uc
|
||||
msgid "Not a Dawnline export."
|
||||
msgstr "Файл не является экспортом Dawnline."
|
||||
@@ -4697,6 +4773,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 "Не работает"
|
||||
@@ -5130,6 +5210,10 @@ msgstr "%s: добавлено устройство %s"
|
||||
msgid "Person %s added device %s on their portal"
|
||||
msgstr "%s: добавлено устройство %s через портал"
|
||||
|
||||
#: web/src/admin/events/render.ts
|
||||
msgid "Person %s changed device %s on their portal"
|
||||
msgstr "Пользователь %s изменил настройки устройства %s в личном портале"
|
||||
|
||||
#: web/src/admin/events/render.ts
|
||||
msgid "Person %s issued new keys for device %s on their portal"
|
||||
msgstr "%s: выпущены новые ключи для устройства %s через портал"
|
||||
@@ -6171,6 +6255,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 "Стандартная (старая)"
|
||||
@@ -6278,6 +6366,10 @@ msgstr "Переход на AmneziaWG %s"
|
||||
msgid "System"
|
||||
msgstr "Система"
|
||||
|
||||
#: web/src/admin/pages/settings/logs.ts
|
||||
msgid "System log"
|
||||
msgstr "Системный журнал"
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/libexec/dawnline/updater
|
||||
#: web/src/admin/pages/components/activity.ts
|
||||
#: web/src/admin/pages/settings/updates.ts
|
||||
@@ -6382,6 +6474,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 "Не удаётся прочитать конфигурацию из этого файла."
|
||||
@@ -6462,6 +6558,10 @@ msgstr "Модуль ядра не загружается: %s Переустан
|
||||
msgid "The latest release is %s"
|
||||
msgstr "Последний релиз - %s"
|
||||
|
||||
#: web/src/admin/cores/awg.ts
|
||||
msgid "The link has the server’s IP address, not its name: if the address changes, set the device up again."
|
||||
msgstr "В ссылке IP-адрес сервера, а не его имя: если адрес сменится, настройте устройство заново."
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/health.uc
|
||||
msgid "The link is up but not attached to %s."
|
||||
msgstr "Домашний маршрут поднят, но не подключён к %s."
|
||||
@@ -6763,8 +6863,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 +6900,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 "Перевод"
|
||||
@@ -6829,6 +6932,11 @@ msgstr "Пробуем зеркало %s"
|
||||
msgid "Tunnel"
|
||||
msgstr "Туннель"
|
||||
|
||||
#: web/src/admin/cores/awg.ts
|
||||
msgctxt "V2RayTun app"
|
||||
msgid "Tunnel"
|
||||
msgstr "Туннель"
|
||||
|
||||
#: web/src/admin/pages/overview.ts
|
||||
msgid "Tunnel %s is down."
|
||||
msgstr "Туннель %s не работает."
|
||||
@@ -6959,6 +7067,10 @@ msgstr "Неизвестный город"
|
||||
msgid "Unknown component %s"
|
||||
msgstr "Неизвестный компонент: %s"
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/core.uc
|
||||
msgid "Unknown device type."
|
||||
msgstr "Неизвестный тип устройства."
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/core.uc
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/devices.uc
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/rpc/people.uc
|
||||
@@ -7212,6 +7324,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 "Используется самоподписанный сертификат: браузеры покажут предупреждение."
|
||||
@@ -7220,10 +7339,22 @@ msgstr "Используется самоподписанный сертифик
|
||||
msgid "Using a self-signed certificate: browsers will show a warning. ACME can get a free Let’s Encrypt one."
|
||||
msgstr "Используется самоподписанный сертификат: браузеры покажут предупреждение. Через ACME можно получить бесплатный сертификат Let’s Encrypt."
|
||||
|
||||
#: web/src/admin/cores/awg.ts
|
||||
msgid "V2RayTun on Android: %s, or copy the link and %s."
|
||||
msgstr "V2RayTun на Android: %s или скопируйте ссылку и %s."
|
||||
|
||||
#: web/src/admin/cores/awg.ts
|
||||
msgid "V2RayTun on Windows: %s, then set its mode to %s and connect. That mode needs administrator rights: the app offers to restart with them."
|
||||
msgstr "V2RayTun на Windows: %s, затем выберите режим «%s» и подключитесь. Для этого режима нужны права администратора: приложение предложит перезапуститься с ними."
|
||||
|
||||
#: web/src/admin/interfaces.ts
|
||||
msgid "VPN & tunnels"
|
||||
msgstr "VPN и туннели"
|
||||
|
||||
#: web/src/admin/pages/settings/logs.ts
|
||||
msgid "Verbose (debug)"
|
||||
msgstr "Подробный (отладка)"
|
||||
|
||||
#: web/src/admin/pages/components/hero.ts
|
||||
msgid "Versions"
|
||||
msgstr "Версии"
|
||||
@@ -7265,6 +7396,10 @@ msgstr "Внимание: не удалось сохранить %s: %s"
|
||||
msgid "Warning: the installed build is no longer published, nothing to keep for rollback"
|
||||
msgstr "Внимание: установленная сборка больше не публикуется, сохранить для отката нечего"
|
||||
|
||||
#: web/src/admin/pages/settings/logs.ts
|
||||
msgid "Warnings and errors"
|
||||
msgstr "Предупреждения и ошибки"
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/libexec/dawnline/agent
|
||||
#: web/src/admin/pages/diagnostics/health.ts
|
||||
msgid "Watchdog"
|
||||
@@ -7294,6 +7429,10 @@ msgstr "Раз в неделю"
|
||||
msgid "Went offline"
|
||||
msgstr "Вышло из сети"
|
||||
|
||||
#: web/src/admin/pages/settings/logs.ts
|
||||
msgid "What Dawnline writes to the router’s system log (logread -e dawnline). Verbose adds each step of a start and of applying settings."
|
||||
msgstr "Что Dawnline пишет в системный журнал роутера (logread -e dawnline). Подробный добавляет каждый шаг запуска и применения настроек."
|
||||
|
||||
#: web/src/admin/pages/server.ts
|
||||
#: web/src/admin/pages/settings/portal.ts
|
||||
msgid "What people see"
|
||||
@@ -7401,7 +7540,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 +7788,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 +8100,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»"
|
||||
@@ -8085,6 +8239,10 @@ msgstr "сохранить доступ"
|
||||
msgid "keep-alive"
|
||||
msgstr "keep-alive"
|
||||
|
||||
#: web/src/admin/events/model.ts
|
||||
msgid "keep-alive %s s"
|
||||
msgstr "keep-alive %s с"
|
||||
|
||||
#: web/src/admin/events/model.ts
|
||||
msgid "kept in memory only (lost on reboot)"
|
||||
msgstr "только в памяти (пропадают при перезагрузке)"
|
||||
@@ -8101,10 +8259,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 +8393,7 @@ msgstr "не настроено"
|
||||
|
||||
#: web/src/admin/map.ts
|
||||
#: web/src/admin/places/render.ts
|
||||
#: web/src/admin/widgets/readouts.ts
|
||||
msgid "now"
|
||||
msgstr "сейчас"
|
||||
|
||||
@@ -8298,10 +8453,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 +8597,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 ": запущен"
|
||||
@@ -8520,6 +8675,14 @@ msgstr "сегодня %s"
|
||||
msgid "tunnel network"
|
||||
msgstr "сеть туннеля"
|
||||
|
||||
#: web/src/admin/events/model.ts
|
||||
msgid "type"
|
||||
msgstr "тип"
|
||||
|
||||
#: web/src/admin/events/model.ts
|
||||
msgid "type: %s"
|
||||
msgstr "тип: %s"
|
||||
|
||||
#: web/src/admin/pages/people.ts
|
||||
#: web/src/admin/pages/settings/portal.ts
|
||||
msgid "until %s"
|
||||
@@ -8623,3 +8786,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%% к среднему"
|
||||
@@ -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 ""
|
||||
@@ -353,6 +363,10 @@ msgstr ""
|
||||
msgid "%s does not overlap other networks."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/cores/awg.ts
|
||||
msgid "%s does not resolve right now, and V2RayTun on Android connects by IP address only."
|
||||
msgstr ""
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/health.uc
|
||||
msgid "%s does not resolve."
|
||||
msgstr ""
|
||||
@@ -665,6 +679,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 +887,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 ""
|
||||
@@ -1017,6 +1039,10 @@ msgstr ""
|
||||
msgid "%s: <%s> is not a tag AmneziaWG apps accept: use <b 0x…> with an even number of hex digits, <r N>, <rc N> or <rd N> with N from 1 to 1000, or <t>."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/events/model.ts
|
||||
msgid "%s: automatic"
|
||||
msgstr ""
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/access.uc
|
||||
msgid "%s: the device's own network handles it."
|
||||
msgstr ""
|
||||
@@ -1055,6 +1081,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 +1118,10 @@ msgstr ""
|
||||
msgid "15 min"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/pages/overview.ts
|
||||
msgid "2 min"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/map.ts
|
||||
msgid "24h"
|
||||
msgstr ""
|
||||
@@ -2098,6 +2132,10 @@ msgstr ""
|
||||
msgid "Choose a server on their page"
|
||||
msgstr ""
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/schema.uc
|
||||
msgid "Choose a system log level: errors, warnings, normal or verbose."
|
||||
msgstr ""
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/awg.uc
|
||||
msgid "Choose another interface name in the server settings."
|
||||
msgstr ""
|
||||
@@ -2179,10 +2217,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 +2534,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 ""
|
||||
@@ -2569,6 +2607,10 @@ msgstr ""
|
||||
msgid "Device %s changed network %s"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/events/render.ts
|
||||
msgid "Device %s changed on the portal"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/events/render.ts
|
||||
msgid "Device %s connected"
|
||||
msgstr ""
|
||||
@@ -2997,6 +3039,10 @@ msgstr ""
|
||||
msgid "Error: %s"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/pages/settings/logs.ts
|
||||
msgid "Errors only"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/pages/settings/logs.ts
|
||||
msgid "Every 10 min"
|
||||
msgstr ""
|
||||
@@ -3443,6 +3489,21 @@ msgstr ""
|
||||
msgid "Import JSON"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/cores/awg.ts
|
||||
msgctxt "V2RayTun app"
|
||||
msgid "Import config from Clipboard"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/cores/awg.ts
|
||||
msgctxt "V2RayTun app"
|
||||
msgid "Import config from QRcode"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/cores/awg.ts
|
||||
msgctxt "V2RayTun app"
|
||||
msgid "Import from clipboard"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/pages/settings/backups.ts
|
||||
msgid "Import?"
|
||||
msgstr ""
|
||||
@@ -3844,11 +3905,20 @@ msgstr ""
|
||||
msgid "LAN Bypass"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/events/model.ts
|
||||
msgid "LAN Bypass off"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/events/model.ts
|
||||
msgid "LAN Bypass on"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/widgets/tiles.ts
|
||||
msgid "Last 30 days"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/device.ts
|
||||
#: web/src/admin/widgets/spark.ts
|
||||
msgid "Last 7 days"
|
||||
msgstr ""
|
||||
|
||||
@@ -3890,6 +3960,7 @@ msgstr ""
|
||||
msgid "Limit hours"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/cores/awg.ts
|
||||
#: web/src/admin/invite.ts
|
||||
msgid "Link copied"
|
||||
msgstr ""
|
||||
@@ -4565,6 +4636,10 @@ msgstr ""
|
||||
msgid "None: without the tunnel those devices have no DNS."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/pages/settings/logs.ts
|
||||
msgid "Normal"
|
||||
msgstr ""
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/backup.uc
|
||||
msgid "Not a Dawnline export."
|
||||
msgstr ""
|
||||
@@ -4639,6 +4714,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 ""
|
||||
@@ -5071,6 +5150,10 @@ msgstr ""
|
||||
msgid "Person %s added device %s on their portal"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/events/render.ts
|
||||
msgid "Person %s changed device %s on their portal"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/events/render.ts
|
||||
msgid "Person %s issued new keys for device %s on their portal"
|
||||
msgstr ""
|
||||
@@ -6108,6 +6191,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 ""
|
||||
@@ -6214,6 +6301,10 @@ msgstr ""
|
||||
msgid "System"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/pages/settings/logs.ts
|
||||
msgid "System log"
|
||||
msgstr ""
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/libexec/dawnline/updater
|
||||
#: web/src/admin/pages/components/activity.ts
|
||||
#: web/src/admin/pages/settings/updates.ts
|
||||
@@ -6318,6 +6409,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 ""
|
||||
@@ -6398,6 +6493,10 @@ msgstr ""
|
||||
msgid "The latest release is %s"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/cores/awg.ts
|
||||
msgid "The link has the server’s IP address, not its name: if the address changes, set the device up again."
|
||||
msgstr ""
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/health.uc
|
||||
msgid "The link is up but not attached to %s."
|
||||
msgstr ""
|
||||
@@ -6696,8 +6795,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 +6832,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 ""
|
||||
@@ -6762,6 +6864,11 @@ msgstr ""
|
||||
msgid "Tunnel"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/cores/awg.ts
|
||||
msgctxt "V2RayTun app"
|
||||
msgid "Tunnel"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/pages/overview.ts
|
||||
msgid "Tunnel %s is down."
|
||||
msgstr ""
|
||||
@@ -6892,6 +6999,10 @@ msgstr ""
|
||||
msgid "Unknown component %s"
|
||||
msgstr ""
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/core.uc
|
||||
msgid "Unknown device type."
|
||||
msgstr ""
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/core.uc
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/devices.uc
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/rpc/people.uc
|
||||
@@ -7144,6 +7255,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 ""
|
||||
@@ -7152,10 +7269,22 @@ msgstr ""
|
||||
msgid "Using a self-signed certificate: browsers will show a warning. ACME can get a free Let’s Encrypt one."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/cores/awg.ts
|
||||
msgid "V2RayTun on Android: %s, or copy the link and %s."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/cores/awg.ts
|
||||
msgid "V2RayTun on Windows: %s, then set its mode to %s and connect. That mode needs administrator rights: the app offers to restart with them."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/interfaces.ts
|
||||
msgid "VPN & tunnels"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/pages/settings/logs.ts
|
||||
msgid "Verbose (debug)"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/pages/components/hero.ts
|
||||
msgid "Versions"
|
||||
msgstr ""
|
||||
@@ -7197,6 +7326,10 @@ msgstr ""
|
||||
msgid "Warning: the installed build is no longer published, nothing to keep for rollback"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/pages/settings/logs.ts
|
||||
msgid "Warnings and errors"
|
||||
msgstr ""
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/libexec/dawnline/agent
|
||||
#: web/src/admin/pages/diagnostics/health.ts
|
||||
msgid "Watchdog"
|
||||
@@ -7226,6 +7359,10 @@ msgstr ""
|
||||
msgid "Went offline"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/pages/settings/logs.ts
|
||||
msgid "What Dawnline writes to the router’s system log (logread -e dawnline). Verbose adds each step of a start and of applying settings."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/pages/server.ts
|
||||
#: web/src/admin/pages/settings/portal.ts
|
||||
msgid "What people see"
|
||||
@@ -7332,7 +7469,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 +7717,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 +8028,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 ""
|
||||
@@ -8015,6 +8166,10 @@ msgstr ""
|
||||
msgid "keep-alive"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/events/model.ts
|
||||
msgid "keep-alive %s s"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/events/model.ts
|
||||
msgid "kept in memory only (lost on reboot)"
|
||||
msgstr ""
|
||||
@@ -8031,10 +8186,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 +8320,7 @@ msgstr ""
|
||||
|
||||
#: web/src/admin/map.ts
|
||||
#: web/src/admin/places/render.ts
|
||||
#: web/src/admin/widgets/readouts.ts
|
||||
msgid "now"
|
||||
msgstr ""
|
||||
|
||||
@@ -8227,10 +8379,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 +8523,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 ""
|
||||
@@ -8449,6 +8601,14 @@ msgstr ""
|
||||
msgid "tunnel network"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/events/model.ts
|
||||
msgid "type"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/events/model.ts
|
||||
msgid "type: %s"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/pages/people.ts
|
||||
#: web/src/admin/pages/settings/portal.ts
|
||||
msgid "until %s"
|
||||
@@ -8550,3 +8710,7 @@ msgstr ""
|
||||
#: web/src/admin/pages/components/hero.ts
|
||||
msgid "← Newer"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/admin/widgets/readouts.ts
|
||||
msgid "−%s%% vs average"
|
||||
msgstr ""
|
||||
@@ -8,15 +8,33 @@ USE_PROCD=1
|
||||
|
||||
PORTAL_ROOT=/usr/share/dawnline/portal/www
|
||||
|
||||
# A line in syslog as dawnline.util syslog() writes them: "dawnline: [info] [service] …" at the
|
||||
# matching priority, when the admin's level (settings.log_level: error|warn|info|debug) takes it.
|
||||
log() {
|
||||
local lvl="$1" want rank prio
|
||||
shift
|
||||
want="$(uci -q get dawnline.settings.log_level)"
|
||||
case "$lvl" in error) rank=0 prio=err ;; warn) rank=1 prio=warning ;; debug) rank=3 prio=debug ;; *) rank=2 prio=info ;; esac
|
||||
case "$want" in error) want=0 ;; warn) want=1 ;; debug) want=3 ;; *) want=2 ;; esac
|
||||
[ "$rank" -le "$want" ] || return 0
|
||||
logger -t dawnline -p "daemon.$prio" "[$lvl] [service] $*"
|
||||
}
|
||||
|
||||
start_portal() {
|
||||
local enabled port certs cert key hport http
|
||||
config_get_bool enabled settings portal_enabled 0
|
||||
[ "$enabled" = 1 ] || return 0
|
||||
if [ "$enabled" != 1 ]; then
|
||||
log info "personal portal is off"
|
||||
return 0
|
||||
fi
|
||||
config_get port settings portal_port 8443
|
||||
certs="$(/usr/bin/dawnline portal-cert 2>/dev/null)"
|
||||
cert="${certs% *}"
|
||||
key="${certs#* }"
|
||||
[ -f "$cert" ] && [ -f "$key" ] || return 0
|
||||
if ! [ -f "$cert" ] || ! [ -f "$key" ]; then
|
||||
log warn "personal portal not started: no certificate (${cert:-none}): choose one in Settings, or save the portal settings again"
|
||||
return 0
|
||||
fi
|
||||
# IP addresses in links get plain HTTP on the next port (names stay HTTPS-only).
|
||||
hport="$(/usr/bin/dawnline portal-http-port 2>/dev/null)"
|
||||
[ -n "$hport" ] && http="-p 0.0.0.0:$hport -p [::]:$hport"
|
||||
@@ -34,23 +52,30 @@ start_portal() {
|
||||
procd_set_param file "$cert"
|
||||
procd_set_param respawn 3600 5 0
|
||||
procd_close_instance
|
||||
log info "personal portal on port $port (HTTPS${hport:+, plain HTTP on $hport for links with an IP address}) · certificate $cert$(openssl x509 -enddate -noout -in "$cert" 2>/dev/null | sed 's/^notAfter=/ until /') · $procs processes"
|
||||
}
|
||||
|
||||
# Plain DNS for Home-only tunnel devices (config written by `dawnline apply`).
|
||||
start_resolver() {
|
||||
[ -f /var/etc/dawnline-dns.conf ] || return 0
|
||||
if ! [ -f /var/etc/dawnline-dns.conf ]; then
|
||||
log debug "no DNS for Home-only devices (nobody needs it)"
|
||||
return 0
|
||||
fi
|
||||
procd_open_instance dns
|
||||
procd_set_param command /usr/libexec/dawnline/resolver
|
||||
procd_set_param file /var/etc/dawnline-dns.conf
|
||||
# A new config kills it (dawnline.resolver): back within a second, not five.
|
||||
procd_set_param respawn 3600 1 0
|
||||
procd_close_instance
|
||||
log info "DNS for Home-only devices started (/var/etc/dawnline-dns.conf)"
|
||||
}
|
||||
|
||||
start_service() {
|
||||
config_load dawnline
|
||||
mkdir -p /var/run/dawnline
|
||||
/usr/bin/dawnline apply >/dev/null 2>&1
|
||||
log info "starting"
|
||||
# The apply writes its own lines: what it came to and how long it took (each step at debug).
|
||||
/usr/bin/dawnline apply >/dev/null 2>&1 || log error "applying the configuration failed: run \"dawnline apply\" to see why"
|
||||
|
||||
procd_open_instance agent
|
||||
procd_set_param command /usr/libexec/dawnline/agent
|
||||
@@ -60,10 +85,12 @@ start_service() {
|
||||
|
||||
start_portal
|
||||
start_resolver
|
||||
log info "started"
|
||||
}
|
||||
|
||||
# Noted for the service log: the next agent start is a restart, not a crash or a boot.
|
||||
stop_service() {
|
||||
log info "stopping"
|
||||
mkdir -p /var/run/dawnline
|
||||
date +%s > /var/run/dawnline/agent.stopped
|
||||
# Copies procd doesn't know about (started by hand, or left by an older version) go too.
|
||||
@@ -71,7 +98,8 @@ stop_service() {
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
/usr/bin/dawnline apply >/dev/null 2>&1
|
||||
log info "reloading: settings changed"
|
||||
/usr/bin/dawnline apply >/dev/null 2>&1 || log error "applying the configuration failed: run \"dawnline apply\" to see why"
|
||||
start
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import * as store from 'dawnline.store';
|
||||
import * as devices from 'dawnline.devices';
|
||||
import { L_ } from 'dawnline.i18n';
|
||||
import {
|
||||
VERSION, slog, slog_read, sh_out, q, take_iface_intent, read_json, write_json, ensure_dir, with_lock, RUN_DIR
|
||||
VERSION, slog, syslog, slog_read, sh_out, q, take_iface_intent, read_json, write_json, ensure_dir, with_lock, RUN_DIR
|
||||
} from 'dawnline.util';
|
||||
|
||||
/** Options that take no value. */
|
||||
@@ -338,5 +338,7 @@ try {
|
||||
}
|
||||
catch (e) {
|
||||
warn(`dawnline: ${e.message}\n`);
|
||||
// Run from the init script or cron, stderr goes nowhere: syslog keeps why.
|
||||
syslog('error', 'cli', `dawnline ${cmd} failed: ${e.message}`);
|
||||
exit(1);
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
import * as uloop from 'uloop';
|
||||
import { open, readfile, writefile, stat, unlink } from 'fs';
|
||||
import {
|
||||
read_json, write_json, ensure_dir, sh_out, q, uniq, slog, slog_trim, slog_restore, date_end, DATA_DIR, RUN_DIR, VERSION
|
||||
read_json, write_json, ensure_dir, sh_out, q, uniq, slog, syslog, slog_trim, slog_restore, date_end, DATA_DIR, RUN_DIR, VERSION
|
||||
} from 'dawnline.util';
|
||||
import * as core from 'dawnline.core';
|
||||
import * as live from 'dawnline.live';
|
||||
@@ -641,8 +641,9 @@ function nightly_backup() {
|
||||
let st = read_json(`${DATA_DIR}/backup-state.json`, {});
|
||||
if (sum && sum != st.auto) {
|
||||
try {
|
||||
backup.backup_create('auto');
|
||||
let b = backup.backup_create('auto');
|
||||
write_json(`${DATA_DIR}/backup-state.json`, { auto: sum }, 0o600);
|
||||
syslog('info', 'backup', `nightly backup saved${b ? ': ' + b : ''}`);
|
||||
}
|
||||
catch (e) {
|
||||
// Tried again tomorrow; meanwhile the admin should know (a full flash, mostly).
|
||||
@@ -794,9 +795,11 @@ function step(i, s, fn) {
|
||||
delete step_err[i];
|
||||
}
|
||||
catch (e) {
|
||||
system(`logger -t dawnline-agent ${q(`${s.who}: ${e.message}`)}`);
|
||||
// A new error goes to the service log (and from there to syslog); a repeat, or a quiet step's, to syslog alone.
|
||||
if (!s.quiet && step_err[i] != e.message)
|
||||
slog('dawnline', 'error', sprintf(L_('failed: %s'), e.message), e.stacktrace?.[0]?.context, s.who);
|
||||
else
|
||||
syslog('error', 'agent', `${s.who}: ${e.message}`);
|
||||
step_err[i] = e.message;
|
||||
}
|
||||
}
|
||||
@@ -835,7 +838,14 @@ function tick() {
|
||||
});
|
||||
}
|
||||
|
||||
// Once: a signal ends the loop and calls it, and so does the line after uloop.run().
|
||||
let stopping = false;
|
||||
|
||||
function shutdown() {
|
||||
if (stopping)
|
||||
return;
|
||||
stopping = true;
|
||||
syslog('info', 'agent', 'stopping · saving the counters and the logs');
|
||||
live.save_usage(usage, true);
|
||||
live.persist_events();
|
||||
geo.flush();
|
||||
@@ -876,6 +886,7 @@ else if (live.uptime() < 600)
|
||||
slog('dawnline', 'info', sprintf(L_('started with the router · version %s'), VERSION), null, 'Dawnline');
|
||||
else
|
||||
slog('dawnline', 'info', sprintf(L_('started · version %s'), VERSION), null, 'Dawnline');
|
||||
syslog('debug', 'agent', sprintf('watching connections every %d ms, checking the rest every %d ms', WATCH, TICK));
|
||||
// A module Dawnline did not install has no record of its kernel: without one
|
||||
// Health cannot tell a firmware upgrade from a missing module.
|
||||
builds.adopt();
|
||||
|
||||
@@ -29,4 +29,4 @@ else detail="It never completed a check."; fi
|
||||
msg="stopped responding — restarted"
|
||||
mkdir -p /var/run/dawnline
|
||||
printf '{"ts":%s,"src":"dawnline","level":"repair","who":"Dawnline","msg":"%s","detail":"%s"}\n' "$now" "$msg" "$detail" >> /var/run/dawnline/service.log
|
||||
logger -t dawnline "Dawnline $msg"
|
||||
logger -t dawnline -p daemon.warning "[warn] [agent] Dawnline $msg - $detail"
|
||||
@@ -31,13 +31,13 @@ while [ "$i" -lt 12 ]; do
|
||||
up && exit 0
|
||||
done
|
||||
|
||||
logger -t dawnline "update to $to failed its check: luci.dawnline or the agent is not up"
|
||||
logger -t dawnline -p daemon.err "[error] [update] update to $to failed its check: luci.dawnline or the agent is not up"
|
||||
set --
|
||||
for f in "$KEEP"/*.ipk "$KEEP"/*.apk; do
|
||||
[ -f "$f" ] && set -- "$@" "$f"
|
||||
done
|
||||
if [ "$#" -eq 0 ]; then
|
||||
logger -t dawnline "no previous version is kept: nothing to roll back to"
|
||||
logger -t dawnline -p daemon.err "[error] [update] no previous version is kept: nothing to roll back to"
|
||||
exit 1
|
||||
fi
|
||||
if command -v apk >/dev/null 2>&1; then
|
||||
@@ -50,5 +50,5 @@ fi
|
||||
mkdir -p "$RUN"
|
||||
# The restored agent reports it in the service log on its start.
|
||||
echo "$to" > "$RUN/update-rolled-back"
|
||||
logger -t dawnline "rolled back from $to to the kept version"
|
||||
logger -t dawnline -p daemon.warning "[warn] [update] rolled back from $to to the kept version"
|
||||
exit 0
|
||||
@@ -13,7 +13,7 @@
|
||||
// (dawnline.store) is never taken while 'apply' is held.
|
||||
|
||||
import { readfile, writefile, stat, unlink } from 'fs';
|
||||
import { ensure_dir, write_file, write_json, with_lock, ip2int, slog, RUN_DIR } from 'dawnline.util';
|
||||
import { ensure_dir, write_file, write_json, with_lock, ip2int, slog, syslog, log_on, RUN_DIR } from 'dawnline.util';
|
||||
import * as core from 'dawnline.core';
|
||||
import * as net from 'dawnline.net';
|
||||
import * as loop from 'dawnline.loop';
|
||||
@@ -54,8 +54,10 @@ export function sync_hosts(m) {
|
||||
let body = length(lines) ? join('\n', lines) + '\n' : '';
|
||||
// dnsmasq runs as its own user; rpcd's umask would leave the file 0600.
|
||||
let readable = ((stat(HOSTS_FILE)?.perm?.other_read) ?? false);
|
||||
if ((readfile(HOSTS_FILE) ?? '') == body && (body == '' || readable))
|
||||
if ((readfile(HOSTS_FILE) ?? '') == body && (body == '' || readable)) {
|
||||
syslog('debug', 'dns', `${HOSTS_FILE}: unchanged · ${length(lines)} names`);
|
||||
return false;
|
||||
}
|
||||
ensure_dir('/tmp/hosts');
|
||||
if (body == '')
|
||||
unlink(HOSTS_FILE);
|
||||
@@ -63,6 +65,7 @@ export function sync_hosts(m) {
|
||||
writefile(HOSTS_FILE, body);
|
||||
system(`chmod 644 ${HOSTS_FILE}`);
|
||||
}
|
||||
syslog('info', 'dns', body == '' ? `${HOSTS_FILE}: removed (no device names)` : `${HOSTS_FILE}: ${length(lines)} names written (*.${m.settings.domain}) · killall -HUP dnsmasq`);
|
||||
system('killall -HUP dnsmasq 2>/dev/null');
|
||||
return true;
|
||||
};
|
||||
@@ -154,6 +157,21 @@ function sync_warning(m, table, peers) {
|
||||
return length(out) ? join(' ', [ ...out, _('Open Diagnostics → Health.') ]) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The same as sync_warning for syslog: in English whatever the admin's
|
||||
* language (a log is read by anyone, searched and sent on), with what nft or
|
||||
* awg said. Null when all went in.
|
||||
*/
|
||||
function sync_facts(m, table, peers) {
|
||||
let out = [];
|
||||
if (table != null)
|
||||
push(out, `access rules ${nft.present() ? 'not updated, the previous ones stay' : 'not loaded, no device loaded'}: ${table}`);
|
||||
for (let id, r in peers)
|
||||
if (r != 'ok' && r != 'down')
|
||||
push(out, `${m.servers[id]?.name ?? id}: devices not loaded: ${r}`);
|
||||
return length(out) ? join(' · ', out) : null;
|
||||
}
|
||||
|
||||
/*
|
||||
* With the lock held: access sets first, then devices into the tunnels.
|
||||
* Fail closed: without the table the firewall would let every loaded device
|
||||
@@ -226,24 +244,60 @@ export function sync_loop(m, usage, force) {
|
||||
|
||||
/* ---------- entry points ---------- */
|
||||
|
||||
/** Full reconcile: router configuration + runtime state. */
|
||||
/** Milliseconds on the monotonic clock, for how long an apply's steps take. */
|
||||
function ms() {
|
||||
let c = clock(true);
|
||||
return c[0] * 1000 + c[1] / 1000000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Full reconcile: router configuration + runtime state. In syslog: what it
|
||||
* came to, with how long it took (info; warn when it did not fully take), and
|
||||
* each step with its result at the debug level.
|
||||
*/
|
||||
export function apply(opts) {
|
||||
opts ??= {};
|
||||
let t0 = ms();
|
||||
let debug = log_on('debug');
|
||||
// One step, timed; `show` picks what of its result goes in the line (never the model: it holds keys).
|
||||
let step = (name, fn, show) => {
|
||||
let t = ms();
|
||||
let out = fn();
|
||||
let what = show ? show(out) : out;
|
||||
if (debug)
|
||||
syslog('debug', 'apply', sprintf('%s done in %d ms%s', name, ms() - t,
|
||||
what == null ? '' : ` · ${type(what) == 'string' ? what : sprintf('%J', what)}`));
|
||||
return out;
|
||||
};
|
||||
if (debug)
|
||||
syslog('debug', 'apply', 'applying the configuration');
|
||||
migrate.run();
|
||||
let r = with_lock('apply', () => {
|
||||
let m = core.load();
|
||||
let usage = core.load_usage();
|
||||
let network = netifd.sync(m);
|
||||
let firewall = fw.sync(m);
|
||||
let lp = loop.ensure(m, true);
|
||||
loop.sync_resolver(m);
|
||||
fw.sync_reply_routes(m);
|
||||
let s = locked_sync(m, usage, true);
|
||||
let changed = (x) => x ? 'changed' : 'unchanged';
|
||||
let network = step('network (netifd)', () => netifd.sync(m), changed);
|
||||
let firewall = step('firewall (fw4)', () => fw.sync(m), changed);
|
||||
let lp = step('internet like a home device', () => loop.ensure(m, true));
|
||||
step('resolver for Home-only devices', () => { loop.sync_resolver(m); });
|
||||
step('reply routes', () => { fw.sync_reply_routes(m); });
|
||||
let s = step('access rules and devices', () => locked_sync(m, usage, true), (x) => ({ table: x.table, peers: x.peers }));
|
||||
ensure_dir(RUN_DIR);
|
||||
write_file(NET_SIG, net_signature(m), 0o644);
|
||||
return { network, firewall, lp, peers: s.peers, warning: s.warning };
|
||||
return { network, firewall, lp, peers: s.peers, warning: s.warning, facts: sync_facts(m, s.table, s.peers),
|
||||
counts: [ length(keys(m.servers)), length(keys(m.people)), length(keys(m.devices)) ] };
|
||||
});
|
||||
loop.remember(r.lp);
|
||||
let n = (k, one, many) => `${k} ${k == 1 ? one : many}`;
|
||||
let took = sprintf('configuration applied in %d ms · %s, %s, %s', ms() - t0,
|
||||
n(r.counts[0], 'server', 'servers'), n(r.counts[1], 'person', 'people'), n(r.counts[2], 'device', 'devices'));
|
||||
// Syslog in English (sync_facts, loop.error_note); the admin's answer carries the words in their language.
|
||||
if (r.facts)
|
||||
syslog('warn', 'apply', `${took} · ${r.facts}`);
|
||||
else
|
||||
syslog('info', 'apply', took);
|
||||
if (r.lp.error)
|
||||
syslog('warn', 'apply', `internet like a home device: ${type(r.lp.error) == 'object' ? loop.error_note(r.lp.error) : r.lp.error}`);
|
||||
return { network: r.network, firewall: r.firewall, like_home: r.lp.error ? { error: loop.error_text(r.lp.error) } : !r.lp.off, peers: r.peers, warning: r.warning };
|
||||
};
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import { readfile, stat, unlink } from 'fs';
|
||||
import {
|
||||
q, sh, sh_out, rand_int, rand_bytes, valid_key, ip2int, tunnel_name, ensure_dir, write_file, read_json, write_json, lock, unlock,
|
||||
slog, iface_status, DATA_DIR, RUN_DIR
|
||||
slog, syslog, some_of, iface_status, DATA_DIR, RUN_DIR
|
||||
} from 'dawnline.util';
|
||||
import * as core from 'dawnline.core';
|
||||
import * as net from 'dawnline.net';
|
||||
@@ -763,32 +763,58 @@ export function peer_diff(devs, dmp, ifname) {
|
||||
};
|
||||
|
||||
/** Push the peer list of every server to the kernel without restarting it. */
|
||||
// Each tunnel's peers as last loaded ({ ifname: [ "Person · Device (address)" ] }), so a log line can say who came and went.
|
||||
const PEERS_SEEN = `${RUN_DIR}/peers-seen.json`;
|
||||
|
||||
export function sync_peers(m, states) {
|
||||
ensure_dir(RUN_DIR);
|
||||
let res = {};
|
||||
let seen = read_json(PEERS_SEEN, {}), now = {};
|
||||
for (let id, srv in m.servers) {
|
||||
// Only Dawnline's own interfaces: never another tunnel of the same name (core.tunnels).
|
||||
if (!srv.enabled || !length(core.tunnels(srv)))
|
||||
continue;
|
||||
if (system(`awg show ${q(srv.ifname)} public-key >/dev/null 2>&1`) != 0) {
|
||||
res[id] = 'down';
|
||||
syslog('debug', 'awg', `interface ${srv.ifname} (${srv.name}): down, no devices to load`);
|
||||
continue;
|
||||
}
|
||||
let lines = [ '[Interface]', `PrivateKey = ${srv.private_key}`, `ListenPort = ${srv.port}`, '' ];
|
||||
let who = [];
|
||||
for (let d in tunnel_devices(m, id, states)) {
|
||||
push(lines, '[Peer]', `PublicKey = ${d.public_key}`);
|
||||
if (d.preshared_key)
|
||||
push(lines, `PresharedKey = ${d.preshared_key}`);
|
||||
push(lines, `AllowedIPs = ${d.address}/32`, '');
|
||||
push(who, `${m.people[d.person]?.name ?? d.person} · ${d.name} (${d.address})`);
|
||||
}
|
||||
let f = `${RUN_DIR}/${srv.ifname}.conf`;
|
||||
write_file(f, join('\n', lines));
|
||||
let r = sh(`awg syncconf ${q(srv.ifname)} ${f}`);
|
||||
unlink(f);
|
||||
res[id] = r.code == 0 ? 'ok' : trim(r.out);
|
||||
if (r.code != 0)
|
||||
if (r.code != 0) {
|
||||
slog('awg', 'error', L_("couldn't load devices into the tunnel"), trim(r.out), srv.name);
|
||||
continue;
|
||||
}
|
||||
// Who came in and who left since the last load: info; the same peers: debug.
|
||||
now[srv.ifname] = who;
|
||||
let was = seen[srv.ifname];
|
||||
let head = `interface ${srv.ifname} (${srv.name}): awg syncconf · listen port ${srv.port} · ${length(who)} ${length(who) == 1 ? 'peer' : 'peers'}`;
|
||||
// The first load since the router started (or since the tunnel came up): how many, the names at debug.
|
||||
if (was == null) {
|
||||
syslog('info', 'awg', `${head} loaded`);
|
||||
syslog('debug', 'awg', `interface ${srv.ifname}: ${join(', ', who)}`);
|
||||
continue;
|
||||
}
|
||||
let add = filter(who, (x) => index(was, x) < 0), del = filter(was, (x) => index(who, x) < 0);
|
||||
if (length(add) || length(del))
|
||||
syslog('info', 'awg', `${head}${length(add) ? ' · added ' + some_of(add) : ''}${length(del) ? ' · removed ' + some_of(del) : ''}`);
|
||||
else
|
||||
syslog('debug', 'awg', `${head}, unchanged`);
|
||||
}
|
||||
if (sprintf('%J', now) != sprintf('%J', seen))
|
||||
write_json(PEERS_SEEN, now, 0o600);
|
||||
return res;
|
||||
};
|
||||
|
||||
|
||||
@@ -90,6 +90,8 @@ export function load(c) {
|
||||
hostnames: g('hostnames'),
|
||||
domain: g('domain'),
|
||||
log_connections: g('log_connections'),
|
||||
// What goes to syslog (dawnline.util syslog).
|
||||
log_level: g('log_level'),
|
||||
// Repair tunnels and services on its own (the agent, every minute).
|
||||
watchdog: g('watchdog'),
|
||||
// Second DNS for "home names" devices, used by the device when the tunnel is down.
|
||||
@@ -789,6 +791,24 @@ export function set_device_link(c, m, id, a) {
|
||||
return changed;
|
||||
};
|
||||
|
||||
/**
|
||||
* Change what a device is (one of KINDS): true when it changed, false when it
|
||||
* already was. Its configuration follows (device_mtu: phones and tablets take
|
||||
* smaller packets); nothing on the router changes.
|
||||
*/
|
||||
export function set_device_kind(c, m, id, kind) {
|
||||
let d = m.devices[id];
|
||||
if (!d)
|
||||
fail(_('Unknown device.'));
|
||||
if (index(KINDS, kind) < 0)
|
||||
fail(_('Unknown device type.'));
|
||||
if (kind == d.kind)
|
||||
return false;
|
||||
c.set(CONFIG, id, 'kind', kind);
|
||||
d.kind = kind;
|
||||
return true;
|
||||
};
|
||||
|
||||
export function delete_device(c, m, id) {
|
||||
let d = m.devices[id];
|
||||
if (!d)
|
||||
|
||||
@@ -29,6 +29,22 @@ export function need_awg() {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* What a device_changed event says changed: each option with its new value
|
||||
* ("lan_bypass=on", "mtu=1400", "keepalive=auto": '' is the server's again,
|
||||
* "kind=phone"), so the activity log can say what it became.
|
||||
*/
|
||||
function change_detail(names, ch) {
|
||||
return join(', ', map(names, (k) => {
|
||||
if (k == 'lan_bypass')
|
||||
return `lan_bypass=${ch.lan_bypass === true ? 'on' : 'off'}`;
|
||||
if (k == 'kind')
|
||||
return `kind=${ch.kind}`;
|
||||
let v = trim(`${ch[k] ?? ''}`);
|
||||
return `${k}=${v == '' ? 'auto' : v}`;
|
||||
}));
|
||||
}
|
||||
|
||||
/** The device `id` as `opts` may touch it (inside a transaction's model). */
|
||||
function own(m, id, opts) {
|
||||
let d = m.devices[id];
|
||||
@@ -58,9 +74,11 @@ export function add(person, name, kind, opts) {
|
||||
/**
|
||||
* Rename and/or turn a device off or on, or change how it connects (`ch` =
|
||||
* { name?, disabled?, mtu?, keepalive?, lan_bypass? }, see
|
||||
* core.set_device_link); only the admin turns devices off or changes the
|
||||
* rest. Returns the runtime sync ({} after a change of the link values alone:
|
||||
* they are in the device's configuration, nothing on the router changes).
|
||||
* core.set_device_link); only the admin turns devices off or sets the MTU and
|
||||
* keep-alive, the portal may switch LAN Bypass (the device then takes its
|
||||
* updated configuration, keys unchanged). Returns the runtime sync ({} after a
|
||||
* change of the link values alone: they are in the device's configuration,
|
||||
* nothing on the router changes).
|
||||
*/
|
||||
export function update(id, ch, opts) {
|
||||
opts ??= {};
|
||||
@@ -68,7 +86,7 @@ export function update(id, ch, opts) {
|
||||
if (ch.disabled != null && by != 'admin')
|
||||
die(_('Only the admin can turn devices off.'));
|
||||
let link = ch.mtu != null || ch.keepalive != null || ch.lan_bypass != null;
|
||||
if (link && by != 'admin')
|
||||
if ((ch.mtu != null || ch.keepalive != null) && by != 'admin')
|
||||
die(_('Only the admin can change how a device connects.'));
|
||||
let linked = [];
|
||||
let d0 = store.transact((c, m) => {
|
||||
@@ -91,9 +109,9 @@ export function update(id, ch, opts) {
|
||||
live.add_event({ type: 'device_changed', person: d0.person, device: id, detail: ch.disabled ? 'turned off' : 'turned on', by });
|
||||
else if (ch.name != null && ch.name != d0.name)
|
||||
live.add_event({ type: 'device_changed', person: d0.person, device: id, detail: `renamed from ${d0.name}`, by });
|
||||
// The option names, as person_changed lists a person's.
|
||||
// The options with what they became (change_detail).
|
||||
if (length(linked))
|
||||
live.add_event({ type: 'device_changed', person: d0.person, device: id, detail: join(', ', linked), by });
|
||||
live.add_event({ type: 'device_changed', person: d0.person, device: id, detail: change_detail(linked, ch), by });
|
||||
return r;
|
||||
};
|
||||
|
||||
@@ -106,10 +124,19 @@ export function update(id, ch, opts) {
|
||||
function rotate(id, opts) {
|
||||
opts ??= {};
|
||||
let by = opts.by ?? 'admin';
|
||||
store.transact((c, m) => {
|
||||
own(m, id, opts);
|
||||
let changed = [];
|
||||
let person = store.transact((c, m) => {
|
||||
let d = own(m, id, opts);
|
||||
if (opts.kind != null && core.set_device_kind(c, m, id, opts.kind))
|
||||
push(changed, 'kind');
|
||||
if (opts.lan_bypass != null)
|
||||
push(changed, ...core.set_device_link(c, m, id, { lan_bypass: opts.lan_bypass === true }));
|
||||
core.rotate_device(c, m, id, awg.new_keys());
|
||||
return d.person;
|
||||
});
|
||||
if (length(changed))
|
||||
live.add_event({ type: 'device_changed', person, device: id, by,
|
||||
detail: change_detail(changed, { kind: opts.kind, lan_bypass: opts.lan_bypass === true }) });
|
||||
// The device a portal page came through would lose its tunnel before the
|
||||
// answer gets out: load the new key a moment after answering.
|
||||
let s = null;
|
||||
@@ -132,8 +159,10 @@ function rotate(id, opts) {
|
||||
* the admin changed; the portal's Reconnect and the admin's New keys): new
|
||||
* keys, so the configuration it holds stops working with the sync, and it
|
||||
* counts as not set up until it connects with the new one. The usage keeps
|
||||
* the old keys' last handshake: awg.handshake_since hides it. Returns the new
|
||||
* configuration (with `warning` when the sync did not fully take).
|
||||
* the old keys' last handshake: awg.handshake_since hides it. `opts.kind` and
|
||||
* `opts.lan_bypass` (the portal's Reconnect: what it is, LAN Bypass) change
|
||||
* with the keys, in the same write. Returns the new configuration (with
|
||||
* `warning` when the sync did not fully take).
|
||||
*/
|
||||
export function reconnect(id, opts) {
|
||||
opts ??= {};
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// named dawnline_* are ever changed.
|
||||
|
||||
import { readfile, unlink } from 'fs';
|
||||
import { q, sh, sh_out, uniq, in_nets, uci_put, uci_section, ack_config, write_file, RUN_DIR } from 'dawnline.util';
|
||||
import { sh, sh_out, uniq, in_nets, uci_put, uci_section, ack_config, write_file, syslog, opts_text, RUN_DIR } from 'dawnline.util';
|
||||
import { cursor } from 'uci';
|
||||
import * as core from 'dawnline.core';
|
||||
import * as net from 'dawnline.net';
|
||||
@@ -33,12 +33,21 @@ export function sync(m, dry) {
|
||||
let c = cursor();
|
||||
c.load('firewall');
|
||||
let changed = false, want = {};
|
||||
// What changed, section by section, for syslog once it is saved (a dry run says nothing).
|
||||
let notes = [];
|
||||
|
||||
let sec = (name, stype, opts) => {
|
||||
want[name] = true;
|
||||
changed = uci_section(c, 'firewall', name, stype) || changed;
|
||||
let created = uci_section(c, 'firewall', name, stype), diff = {};
|
||||
for (let k, v in opts)
|
||||
changed = uci_put(c, 'firewall', name, k, v) || changed;
|
||||
if (uci_put(c, 'firewall', name, k, v))
|
||||
diff[k] = v;
|
||||
if (created || length(keys(diff))) {
|
||||
changed = true;
|
||||
push(notes, [ 'info', `${stype} ${name}: ${created ? 'created' : 'updated'} · ${opts_text(created ? opts : diff)}` ]);
|
||||
}
|
||||
else
|
||||
push(notes, [ 'debug', `${stype} ${name}: unchanged` ]);
|
||||
};
|
||||
|
||||
let snap = net.snapshot(true);
|
||||
@@ -130,17 +139,20 @@ export function sync(m, dry) {
|
||||
push(stale, s['.name']);
|
||||
});
|
||||
for (let s in stale) {
|
||||
push(notes, [ 'info', `${c.get('firewall', s) ?? 'section'} ${s}: removed` ]);
|
||||
c.delete('firewall', s);
|
||||
changed = true;
|
||||
}
|
||||
if (dry)
|
||||
return changed;
|
||||
|
||||
for (let n in notes)
|
||||
syslog(n[0], 'firewall', n[1]);
|
||||
if (changed) {
|
||||
c.commit('firewall');
|
||||
ack_config([ 'firewall' ]);
|
||||
syslog('info', 'firewall', 'fw4 -q reload');
|
||||
system('fw4 -q reload');
|
||||
system("logger -t dawnline 'firewall updated'");
|
||||
}
|
||||
return changed;
|
||||
};
|
||||
@@ -268,18 +280,24 @@ export function sync_reply_routes(m) {
|
||||
}
|
||||
let s = reply_script(m, proxy_diverts());
|
||||
if (s == '') {
|
||||
if (reply_loaded())
|
||||
if (reply_loaded()) {
|
||||
syslog('info', 'nftables', `table inet ${REPLY_TABLE}: removed (no proxy to keep Dawnline's answers out of)`);
|
||||
system(`nft delete table inet ${REPLY_TABLE} 2>/dev/null`);
|
||||
}
|
||||
unlink(REPLY_SIG);
|
||||
return;
|
||||
}
|
||||
if (s == readfile(REPLY_SIG) && reply_loaded())
|
||||
if (s == readfile(REPLY_SIG) && reply_loaded()) {
|
||||
syslog('debug', 'nftables', `table inet ${REPLY_TABLE}: unchanged`);
|
||||
return;
|
||||
}
|
||||
let err = nft.load(`table inet ${REPLY_TABLE}\ndelete table inet ${REPLY_TABLE}\n${s}`);
|
||||
if (err) {
|
||||
unlink(REPLY_SIG);
|
||||
system(`logger -t dawnline -p user.err ${q('reply table: ' + err)}`);
|
||||
syslog('error', 'nftables', `table inet ${REPLY_TABLE}: loading failed · ${err}`);
|
||||
return;
|
||||
}
|
||||
syslog('info', 'nftables', `table inet ${REPLY_TABLE}: loaded · ${length(match(s, /\n/g) ?? []) + 1} lines (Dawnline's own answers kept out of proxies)`);
|
||||
syslog('debug', 'nftables', `table inet ${REPLY_TABLE}: ${s}`);
|
||||
write_file(REPLY_SIG, s, 0o644);
|
||||
};
|
||||
@@ -7,7 +7,7 @@
|
||||
import { readfile, stat, unlink } from 'fs';
|
||||
import { cursor } from 'uci';
|
||||
import {
|
||||
ensure_dir, read_json, write_json, lock, unlock, month_key, day_key, day_key_ago, uniq,
|
||||
ensure_dir, read_json, write_json, lock, unlock, month_key, day_key, day_key_ago, uniq, syslog,
|
||||
iface_status as util_iface_status, RUN_DIR, DATA_DIR
|
||||
} from 'dawnline.util';
|
||||
import * as awg from 'dawnline.awg';
|
||||
@@ -422,13 +422,51 @@ function with_names(e, c) {
|
||||
return e;
|
||||
}
|
||||
|
||||
// Events about someone's connection, not about the system: they stay out of syslog
|
||||
// (the activity log has them). Connects, roams, a device's link trouble and its end.
|
||||
const NOT_SYSTEM = [ 'connect', 'disconnect', 'roam', 'device_failing', 'device_recovered' ];
|
||||
|
||||
/**
|
||||
* An activity event at its syslog level, or null when it stays out (a
|
||||
* connection: syslog says what the system does). People and their devices
|
||||
* (what changes the tunnels and the rules) are info, problems warn and their
|
||||
* end ("…_up") info.
|
||||
*/
|
||||
export function event_level(e) {
|
||||
let cat = category_of(e.type);
|
||||
if (cat == 'connections' || index(NOT_SYSTEM, e.type) >= 0)
|
||||
return null;
|
||||
if (cat == 'problems' && !match(e.type, /_up$/))
|
||||
return 'warn';
|
||||
return 'info';
|
||||
};
|
||||
|
||||
/** An activity event as a syslog line: "Myata · Phone device changed · kind=phone, lan_bypass=on (portal)". */
|
||||
export function event_line(e) {
|
||||
let who = join(' · ', filter([ e.pname ?? e.person, e.dname ?? e.device ], (x) => x != null && x != ''));
|
||||
return join(' ', filter([ who, replace(e.type ?? 'event', /_/g, ' '), e.detail ? `· ${e.detail}` : '', e.by ? `(${e.by})` : '' ], (x) => x != ''));
|
||||
};
|
||||
|
||||
/** The system's events to syslog, whatever the activity log records (its categories are the admin's choice for the page). */
|
||||
function syslog_events(list, c) {
|
||||
for (let e in list) {
|
||||
let lvl = event_level(e);
|
||||
if (lvl)
|
||||
syslog(lvl, category_of(e.type), event_line(with_names(e, c)));
|
||||
}
|
||||
}
|
||||
|
||||
export function add_events(list, pol) {
|
||||
pol ??= policy();
|
||||
list = filter(list ?? [], (e) => index(pol.categories, category_of(e.type)) >= 0);
|
||||
list ??= [];
|
||||
if (!length(list))
|
||||
return;
|
||||
let c = cursor();
|
||||
c.load('dawnline');
|
||||
syslog_events(list, c);
|
||||
list = filter(list, (e) => index(pol.categories, category_of(e.type)) >= 0);
|
||||
if (!length(list))
|
||||
return;
|
||||
let l = lock('events');
|
||||
let ev = load_events();
|
||||
let ts = time();
|
||||
@@ -451,6 +489,9 @@ export function add_event(e) {
|
||||
* and device (when it has one) within `window` s.
|
||||
*/
|
||||
export function add_event_merged(e, window) {
|
||||
let c0 = cursor();
|
||||
c0.load('dawnline');
|
||||
syslog_events([ { ...e } ], c0);
|
||||
let pol = policy();
|
||||
if (index(pol.categories, category_of(e.type)) < 0)
|
||||
return;
|
||||
|
||||
@@ -84,6 +84,18 @@ export function resolve(host) {
|
||||
return resolve_all([ host ])[host] ?? [];
|
||||
};
|
||||
|
||||
/**
|
||||
* The address to give an app that takes no name for the server (V2RayTun's
|
||||
* Android core hands the endpoint over as it is): IPv4 first, as a phone on
|
||||
* mobile data may have no IPv6. The host itself when it is an IP; null when
|
||||
* the name does not resolve.
|
||||
*/
|
||||
export function host_ip(host) {
|
||||
let ips = resolve(host);
|
||||
let v4 = filter(ips, (x) => ip2int(x) != null);
|
||||
return v4[0] ?? ips[0] ?? null;
|
||||
};
|
||||
|
||||
/** The IPv4 address of a netifd interface (a zone name for older configs). */
|
||||
export function wan_ipv4(zone) {
|
||||
let st = live.iface_status(zone == 'wan' ? 'wan' : zone);
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
import { readfile, writefile, readlink, stat, unlink } from 'fs';
|
||||
import { cursor } from 'uci';
|
||||
import {
|
||||
sh, sh_out, q, ip2int, int2ip, parse_cidr, cidr_any, ensure_dir, read_json, write_json, slog, RUN_DIR
|
||||
sh, sh_out, q, ip2int, int2ip, parse_cidr, cidr_any, ensure_dir, read_json, write_json, slog, syslog, syslog_lines, RUN_DIR
|
||||
} from 'dawnline.util';
|
||||
import * as net from 'dawnline.net';
|
||||
import * as core from 'dawnline.core';
|
||||
@@ -60,12 +60,20 @@ function log(msg, level, detail) {
|
||||
slog('dawnline', level ?? 'info', msg, detail, WHO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the commands that set the path up or take it down, each in syslog as
|
||||
* it is given ("$ ip netns add dawnline"), a failure with what it said.
|
||||
* Only called when something changes (ensure() returns early otherwise).
|
||||
*/
|
||||
function run(cmds) {
|
||||
let errs = [];
|
||||
syslog_lines('info', 'loop', join('\n', cmds), '$ ');
|
||||
for (let c in cmds) {
|
||||
let r = sh(c);
|
||||
if (r.code != 0)
|
||||
if (r.code != 0) {
|
||||
push(errs, `${c}: ${trim(r.out)}`);
|
||||
syslog('error', 'loop', `failed: ${c} · ${trim(r.out)}`);
|
||||
}
|
||||
}
|
||||
return errs;
|
||||
}
|
||||
@@ -232,8 +240,8 @@ function pick_table(saved) {
|
||||
* { code: 'setup', detail } a command failed (detail: it and what it said)
|
||||
*/
|
||||
|
||||
/** A reason from plan() for the service log: English, like every log line. */
|
||||
function error_note(e) {
|
||||
/** A reason from plan() for the service log and syslog: English, like every log line. */
|
||||
export function error_note(e) {
|
||||
if (e.code == 'no_lan')
|
||||
return L_('No LAN detected.');
|
||||
if (e.code == 'not_bridge')
|
||||
@@ -245,7 +253,7 @@ function error_note(e) {
|
||||
if (e.code == 'no_transit')
|
||||
return L_('No free link-local range for the internal link.');
|
||||
return L_('No free routing table.');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Why "like a home device" is off (a reason above), as a sentence in the
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { cursor } from 'uci';
|
||||
import { stat, unlink } from 'fs';
|
||||
import { q, slog } from 'dawnline.util';
|
||||
import { slog, syslog } from 'dawnline.util';
|
||||
import * as core from 'dawnline.core';
|
||||
import * as store from 'dawnline.store';
|
||||
import { L_ } from 'dawnline.i18n';
|
||||
@@ -47,7 +47,7 @@ export function uhttpd() {
|
||||
c.delete('uhttpd', 'main', 'error_page');
|
||||
c.commit('uhttpd');
|
||||
system('/etc/init.d/uhttpd reload >/dev/null 2>&1');
|
||||
system(`logger -t dawnline ${q('portal removed from the LuCI web server')}`);
|
||||
syslog('info', 'portal', 'portal removed from the LuCI web server');
|
||||
}
|
||||
if (stat(LAN_CGI))
|
||||
unlink(LAN_CGI);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import { cursor } from 'uci';
|
||||
import { stat, unlink, writefile } from 'fs';
|
||||
import { q, uci_put, uci_section, ack_config, iface_intent, ensure_dir, read_json, write_json, slog, RUN_DIR } from 'dawnline.util';
|
||||
import { q, uci_put, uci_section, ack_config, iface_intent, ensure_dir, read_json, write_json, slog, syslog, opts_text, RUN_DIR } from 'dawnline.util';
|
||||
import * as core from 'dawnline.core';
|
||||
import * as awg from 'dawnline.awg';
|
||||
import { L_ } from 'dawnline.i18n';
|
||||
@@ -95,10 +95,17 @@ export function sync(m) {
|
||||
if (!tools)
|
||||
continue;
|
||||
// Per server: with several, each changed one has to be brought up again.
|
||||
let mine = uci_section(c, 'network', ifn, 'interface');
|
||||
let created = uci_section(c, 'network', ifn, 'interface');
|
||||
let mine = created, diff = {};
|
||||
for (let k, v in options(srv))
|
||||
if (uci_put(c, 'network', ifn, k, v))
|
||||
if (uci_put(c, 'network', ifn, k, v)) {
|
||||
mine = true;
|
||||
diff[k] = v;
|
||||
}
|
||||
if (mine)
|
||||
syslog('info', 'network', `interface ${ifn} (${srv.name}): ${created ? 'created' : 'updated'} · ${opts_text(diff)}`);
|
||||
else
|
||||
syslog('debug', 'network', `interface ${ifn} (${srv.name}): unchanged · ${opts_text(options(srv))}`);
|
||||
// The markers are saved, but netifd does not read them: a renamed server
|
||||
// keeps its tunnel and every session in it.
|
||||
if (uci_put(c, 'network', ifn, '_dawnline', id))
|
||||
@@ -127,6 +134,7 @@ export function sync(m) {
|
||||
});
|
||||
for (let ifn in stale) {
|
||||
iface_intent(ifn, 'removed', c.get('network', ifn, '_dawnline_name') ?? ifn);
|
||||
syslog('info', 'network', `interface ${ifn} (${c.get('network', ifn, '_dawnline_name') ?? 'a removed server'}): removed, ifdown ${ifn}`);
|
||||
system(`ifdown ${q(ifn)} 2>/dev/null`);
|
||||
c.delete('network', ifn);
|
||||
changed = true;
|
||||
@@ -138,12 +146,14 @@ export function sync(m) {
|
||||
}
|
||||
// Only the markers changed: nothing for netifd to read (it ignores them, and so does a reload).
|
||||
if (length(touched) || length(stale)) {
|
||||
syslog('info', 'network', 'ubus call network reload');
|
||||
system('ubus call network reload');
|
||||
for (let ifn in touched)
|
||||
if (m.servers[c.get('network', ifn, '_dawnline')]?.enabled)
|
||||
if (m.servers[c.get('network', ifn, '_dawnline')]?.enabled) {
|
||||
syslog('info', 'network', `ifup ${ifn}`);
|
||||
system(`ifup ${q(ifn)}`);
|
||||
}
|
||||
// Each tunnel's own line (restarting, turned off, removed) comes from hotplug.
|
||||
system(`logger -t dawnline ${q('network updated: ' + join(', ', [ ...touched, ...stale ]))}`);
|
||||
}
|
||||
return changed;
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// changes often (update, one atomic transaction).
|
||||
|
||||
import { unlink } from 'fs';
|
||||
import { sh, ensure_dir, write_file, rand_hex, ip2int, uniq, RUN_DIR } from 'dawnline.util';
|
||||
import { sh, ensure_dir, write_file, rand_hex, ip2int, uniq, read_json, write_json, syslog, syslog_lines, some_of, RUN_DIR } from 'dawnline.util';
|
||||
import * as core from 'dawnline.core';
|
||||
import * as net from 'dawnline.net';
|
||||
import * as loop from 'dawnline.loop';
|
||||
@@ -14,6 +14,55 @@ import * as loop from 'dawnline.loop';
|
||||
export const PRIVATE4 = [ '10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16', '100.64.0.0/10', '169.254.0.0/16', '224.0.0.0/3' ];
|
||||
/** The sets whose members change at run time (update replaces them together). */
|
||||
const SETS = [ 'lan_ok', 'lan_all', 'lan_part', 'mesh_pairs', 'inet_ok', 'svc_ok', 'svc_host', 'dns_real' ];
|
||||
// The sets' members as last loaded, so a log line can say what changed.
|
||||
const SETS_SEEN = `${RUN_DIR}/nft-sets.json`;
|
||||
|
||||
/** What a table script holds: its chains, its sets and the rules in its chains (for a log line). */
|
||||
export function shape(t) {
|
||||
let n = { chains: 0, sets: 0, rules: 0 }, in_chain = false;
|
||||
for (let l in split(t ?? '', '\n')) {
|
||||
l = trim(l);
|
||||
if (substr(l, 0, 6) == 'chain ') {
|
||||
n.chains++;
|
||||
in_chain = true;
|
||||
}
|
||||
else if (substr(l, 0, 4) == 'set ')
|
||||
n.sets++;
|
||||
else if (in_chain && l == '}')
|
||||
in_chain = false;
|
||||
else if (in_chain && l != '' && substr(l, 0, 5) != 'type ' && substr(l, 0, 7) != 'policy ' && substr(l, 0, 1) != '#')
|
||||
n.rules++;
|
||||
}
|
||||
return n;
|
||||
};
|
||||
|
||||
/**
|
||||
* The sets in syslog: info with each set that changed ("inet_ok 3 → 4: +10.8.0.5"),
|
||||
* debug when none did; remembered for the next time.
|
||||
*/
|
||||
function log_sets(sets, how) {
|
||||
let first = read_json(SETS_SEEN, null) == null;
|
||||
let was = read_json(SETS_SEEN, {}), now = {}, diff = [];
|
||||
for (let name in SETS) {
|
||||
let a = uniq(was[name] ?? []), b = uniq(sets[name] ?? []);
|
||||
now[name] = b;
|
||||
let add = filter(b, (x) => index(a, x) < 0), del = filter(a, (x) => index(b, x) < 0);
|
||||
if (length(add) || length(del))
|
||||
push(diff, `${name} ${length(a)} → ${length(b)}${length(add) ? ': +' + some_of(add) : ''}${length(del) ? (length(add) ? ' ' : ': ') + '-' + some_of(del) : ''}`);
|
||||
}
|
||||
write_json(SETS_SEEN, now, 0o600);
|
||||
// The first load since the router started: how many in each set (the members at debug).
|
||||
if (first) {
|
||||
syslog('info', 'nftables', `table inet dawnline: ${how} · ${join(', ', map(SETS, (n) => `${n} ${length(now[n])}`))}`);
|
||||
for (let n in SETS)
|
||||
if (length(now[n]))
|
||||
syslog('debug', 'nftables', `set ${n}: ${join(' ', now[n])}`);
|
||||
}
|
||||
else if (length(diff))
|
||||
syslog('info', 'nftables', `table inet dawnline: ${how} · ${join('; ', diff)}`);
|
||||
else
|
||||
syslog('debug', 'nftables', `table inet dawnline: ${how} · sets unchanged (${join(', ', map(SETS, (n) => `${n} ${length(now[n])}`))})`);
|
||||
}
|
||||
|
||||
function ip4(a) {
|
||||
return ip2int(a ?? '') != null;
|
||||
@@ -216,6 +265,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.
|
||||
@@ -253,7 +309,17 @@ export function render(m, sets, ctx) {
|
||||
|
||||
/** Full table rebuild (structure changes: servers, home networks, DNS paths); null or the error. */
|
||||
export function rebuild(m, sets) {
|
||||
return load('table inet dawnline\ndelete table inet dawnline\n' + table(m, sets));
|
||||
let t = table(m, sets);
|
||||
let err = load('table inet dawnline\ndelete table inet dawnline\n' + t);
|
||||
if (err) {
|
||||
syslog('error', 'nftables', `table inet dawnline: rebuild failed · ${err}`);
|
||||
return err;
|
||||
}
|
||||
let n = shape(t);
|
||||
syslog('info', 'nftables', sprintf('table inet dawnline: rebuilt · %d chains, %d sets, %d rules', n.chains, n.sets, n.rules));
|
||||
syslog_lines('debug', 'nftables', t, 'nft: ');
|
||||
log_sets(sets, 'sets loaded with the table');
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -269,7 +335,12 @@ export function update(sets) {
|
||||
if (length(members))
|
||||
s += `add element inet dawnline ${name} { ${join(', ', members)} }\n`;
|
||||
}
|
||||
return load(s);
|
||||
let err = load(s);
|
||||
if (err)
|
||||
syslog('warn', 'nftables', `table inet dawnline: set update failed, rebuilding · ${err}`);
|
||||
else
|
||||
log_sets(sets, 'sets updated');
|
||||
return err;
|
||||
};
|
||||
|
||||
/** Is the table loaded (watchdog). */
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// GET /<code>/api/state
|
||||
// POST /<code>/api/devices { name, kind, public_key?, lan_bypass? }
|
||||
// GET /<code>/api/devices/<id>/config
|
||||
// POST /<code>/api/devices/<id> { action: rename|rotate|delete, name? }
|
||||
// POST /<code>/api/devices/<id> { action: rename|reconnect|bypass|delete, name?, kind?, lan_bypass?, on? }
|
||||
//
|
||||
// The personal link is the key: every request carries its code, there are
|
||||
// no sessions. Without a valid code every path answers the same bare 404 —
|
||||
@@ -33,10 +33,11 @@
|
||||
// that answers anything not shaped like a link (its not_found() twin).
|
||||
|
||||
import { stat, readfile } from 'fs';
|
||||
import { read_json, write_json, ensure_dir, lock, unlock, cloudflare_ip, ip2int, today, VERSION, RUN_DIR } from 'dawnline.util';
|
||||
import { read_json, write_json, ensure_dir, lock, unlock, cloudflare_ip, ip2int, today, syslog, VERSION, RUN_DIR } from 'dawnline.util';
|
||||
import * as core from 'dawnline.core';
|
||||
import * as awg from 'dawnline.awg';
|
||||
import * as live from 'dawnline.live';
|
||||
import * as lookup from 'dawnline.lookup';
|
||||
import * as view from 'dawnline.view';
|
||||
import * as schema from 'dawnline.schema';
|
||||
import * as devices from 'dawnline.devices';
|
||||
@@ -423,6 +424,17 @@ function api_state(r) {
|
||||
send_json(r, '200 OK', state(r));
|
||||
}
|
||||
|
||||
/**
|
||||
* A configuration as the portal sends it: with the server's address as an IP
|
||||
* too (amnezia.host_ip, lookup.host_ip()), for V2RayTun on Android, which
|
||||
* takes no name for AmneziaWG. Lookups are cached for minutes (lookup.uc).
|
||||
*/
|
||||
function with_ip(cfg) {
|
||||
if (cfg?.amnezia)
|
||||
cfg.amnezia.host_ip = lookup.host_ip(cfg.amnezia.host);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
function api_add(r) {
|
||||
need_open(r);
|
||||
need_https(r);
|
||||
@@ -433,7 +445,7 @@ function api_add(r) {
|
||||
// lan_bypass: JSON true keeps the device's own local network out of the tunnel; anything else is off.
|
||||
let res = guard(r, () => devices.add(r.person.id, b.name, b.kind, { by: 'portal', public_key: b.public_key, lan_bypass: b.lan_bypass === true }));
|
||||
reload(r);
|
||||
send_json(r, '200 OK', { id: res.id, config: res.config, state: state(r) });
|
||||
send_json(r, '200 OK', { id: res.id, config: with_ip(res.config), state: state(r) });
|
||||
}
|
||||
|
||||
function api_config(r, id) {
|
||||
@@ -441,7 +453,7 @@ function api_config(r, id) {
|
||||
need_open(r);
|
||||
need_https(r);
|
||||
awg.mark_issued(r.m, d.id);
|
||||
send_json(r, '200 OK', awg.client_config(r.m, d));
|
||||
send_json(r, '200 OK', with_ip(awg.client_config(r.m, d)));
|
||||
}
|
||||
|
||||
/** POST /devices/<id> { action }: what each action does; the answer carries the new state. */
|
||||
@@ -455,8 +467,20 @@ const ACTIONS = {
|
||||
need_https(r);
|
||||
if (!devices.ready())
|
||||
fail(r, '503 Service Unavailable', not_ready());
|
||||
let config = guard(r, () => devices.reconnect(d.id, { by: 'portal', person: r.person.id, defer: d.address == r.peer }));
|
||||
return { config };
|
||||
// What it is and LAN Bypass may change with the keys (the sheet asks again); left out, they stay.
|
||||
let kind = type(b.kind) == 'string' ? b.kind : null;
|
||||
let bypass = type(b.lan_bypass) == 'bool' ? b.lan_bypass : null;
|
||||
let config = guard(r, () => devices.reconnect(d.id, { by: 'portal', person: r.person.id, defer: d.address == r.peer,
|
||||
kind, lan_bypass: bypass }));
|
||||
return { config: with_ip(config) };
|
||||
},
|
||||
// LAN Bypass on or off, keys unchanged: the device takes its updated configuration (the set-up sheet opens on it).
|
||||
bypass: (r, d, b) => {
|
||||
need_https(r);
|
||||
if (type(b.on) != 'bool')
|
||||
fail(r, '400 Bad Request', _('Unknown action.'));
|
||||
guard(r, () => devices.update(d.id, { lan_bypass: b.on }, { by: 'portal', person: r.person.id }));
|
||||
return {};
|
||||
},
|
||||
'delete': (r, d, b) => {
|
||||
guard(r, () => devices.remove(d.id, { by: 'portal', person: r.person.id }));
|
||||
@@ -590,7 +614,11 @@ export function serve(io) {
|
||||
handle(io);
|
||||
}
|
||||
catch (e) {
|
||||
if (e.message != DONE)
|
||||
if (e.message != DONE) {
|
||||
// What broke and where; the path without its first part (the person's link code is a secret).
|
||||
let path = replace(split(io.env.REQUEST_URI ?? '', '?')[0], /^\/[^\/]*/, '/<link>');
|
||||
syslog('error', 'portal', `${io.env.REQUEST_METHOD ?? '?'} ${path}: 500 · ${e.message}${e.stacktrace?.[0]?.context ? ' · ' + replace(e.stacktrace[0].context, /[\r\n\t]+/g, ' ') : ''}`);
|
||||
io.write(`Status: 500 Internal Server Error\r\nContent-Type: text/plain\r\n\r\nError\n`);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
import { readfile, writefile, stat } from 'fs';
|
||||
import { cursor } from 'uci';
|
||||
import { ensure_dir, iface_status, uniq } from 'dawnline.util';
|
||||
import { ensure_dir, iface_status, uniq, syslog, syslog_lines } from 'dawnline.util';
|
||||
import * as net from 'dawnline.net';
|
||||
import * as core from 'dawnline.core';
|
||||
|
||||
@@ -90,10 +90,15 @@ export function sync(m, target, lan) {
|
||||
for (let d in lan_domain(m))
|
||||
push(lines, `server=/${d}/${lan}`);
|
||||
let conf = join('\n', lines) + '\n';
|
||||
if ((readfile(CONF) ?? '') == conf)
|
||||
let where = target.mode == 'ns' ? `${target.address}:${target.port} in the netns` : length(ifs) ? `port ${target.port} on ${join(', ', ifs)}` : 'loopback only (no tunnel on)';
|
||||
if ((readfile(CONF) ?? '') == conf) {
|
||||
syslog('debug', 'dns', `resolver for Home-only devices: unchanged · ${where}`);
|
||||
return false;
|
||||
}
|
||||
writefile(CONF, conf);
|
||||
system(`chmod 644 ${CONF}`);
|
||||
syslog('info', 'dns', `resolver for Home-only devices: ${CONF} written · ${where} · upstream ${join(' ', wan_dns()) || 'none'}${lan ? ` · home names via ${lan}` : ''}; restarting it`);
|
||||
syslog_lines('debug', 'dns', conf, 'dnsmasq: ');
|
||||
let pid = trim(readfile(PID) ?? '');
|
||||
if (match(pid, /^[0-9]+$/))
|
||||
system(`kill ${pid} 2>/dev/null`);
|
||||
|
||||
@@ -8,6 +8,7 @@ import * as view from 'dawnline.view';
|
||||
import * as awg from 'dawnline.awg';
|
||||
import * as store from 'dawnline.store';
|
||||
import * as devices from 'dawnline.devices';
|
||||
import * as lookup from 'dawnline.lookup';
|
||||
import { wrap, str, clamp_days } from 'dawnline.rpc.common';
|
||||
import { _ } from 'dawnline.i18n';
|
||||
|
||||
@@ -155,7 +156,13 @@ function device_config(a) {
|
||||
die(_('Unknown device.'));
|
||||
if (a.issue === true)
|
||||
awg.mark_issued(m, d.id);
|
||||
return awg.client_config(m, d);
|
||||
let cfg = awg.client_config(m, d);
|
||||
// V2RayTun on Android takes the server by its IP (the admin's set-up shows its link for phones, tablets and
|
||||
// other devices): only where it can connect at all, and AmneziaWG 3.1 (Maximum) is beyond it.
|
||||
let srv = m.servers[m.people[d.person]?.server];
|
||||
if (cfg && d.kind != 'router' && d.kind != 'computer' && srv?.preset != 'max')
|
||||
cfg.amnezia.host_ip = lookup.host_ip(cfg.amnezia.host);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
/** Name, on/off and the link values (mtu, keepalive: strings, '' = the server's; lan_bypass: true or false). */
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// history, updates). What may be saved is dawnline.schema's.
|
||||
|
||||
import { stat } from 'fs';
|
||||
import { q, sh_out, admin_log, RUN_DIR, DATA_DIR } from 'dawnline.util';
|
||||
import { q, sh_out, admin_log, syslog, RUN_DIR, DATA_DIR } from 'dawnline.util';
|
||||
import * as core from 'dawnline.core';
|
||||
import * as live from 'dawnline.live';
|
||||
import * as apply from 'dawnline.apply';
|
||||
@@ -96,16 +96,25 @@ function settings_update(a) {
|
||||
die(_('Nothing to save.'));
|
||||
let res = store.transact((c, m) => {
|
||||
let restart = false;
|
||||
// What each key was and became, as uci holds them (for syslog: every change, not only those worth a line).
|
||||
let diff = [];
|
||||
let note = (k, to) => {
|
||||
let from = c.get(core.CONFIG, 'settings', k);
|
||||
if (!same(to, from))
|
||||
push(diff, { k, from, to });
|
||||
};
|
||||
c.set(core.CONFIG, 'settings', 'settings');
|
||||
for (let k, val in v) {
|
||||
if (k == 'log_category') {
|
||||
let lst = filter(type(val) == 'array' ? val : [], (x) => index(live.CATEGORIES, x) >= 0);
|
||||
note(k, length(lst) ? lst : [ '' ]);
|
||||
c.set(core.CONFIG, 'settings', 'log_category', length(lst) ? lst : [ '' ]);
|
||||
// Superseded by the category list.
|
||||
c.delete(core.CONFIG, 'settings', 'log_connections');
|
||||
continue;
|
||||
}
|
||||
let nv = schema.validate(k, val);
|
||||
note(k, nv);
|
||||
if (schema.SETTINGS[k].restart && !same(nv, c.get(core.CONFIG, 'settings', k)))
|
||||
restart = true;
|
||||
if (nv == null)
|
||||
@@ -114,8 +123,13 @@ function settings_update(a) {
|
||||
c.set(core.CONFIG, 'settings', k, nv);
|
||||
}
|
||||
check_portal(core.load(c), m);
|
||||
return { restart, was: m.settings };
|
||||
return { restart, was: m.settings, diff };
|
||||
});
|
||||
// Every setting that changed, in syslog: "admin changed settings · log_keep_days: 30 → 90, domain: lan → home".
|
||||
if (length(res.diff)) {
|
||||
let val = (x) => x == null || x == '' ? 'default' : type(x) == 'array' ? join(' ', filter(x, (y) => y != '')) || 'none' : `${x}`;
|
||||
syslog('info', 'settings', `admin changed settings · ${join(', ', map(res.diff, (d) => `${d.k}: ${val(d.from)} → ${val(d.to)}`))}`);
|
||||
}
|
||||
let s = null;
|
||||
if (res.restart)
|
||||
system('/etc/init.d/dawnline reload >/dev/null 2>&1');
|
||||
|
||||
@@ -127,6 +127,8 @@ export const SETTINGS = {
|
||||
geo_enabled: { type: 'bool', dflt: false },
|
||||
geo_provider: { type: 'enum', dflt: 'ipwho.is', values: [ 'ipwho.is', 'ipapi.co' ] },
|
||||
log_connections: { type: 'bool', dflt: true },
|
||||
// What goes to syslog (dawnline.util syslog): error | warn | info | debug (each step of a start or an apply).
|
||||
log_level: { type: 'enum', dflt: 'info', values: [ 'error', 'warn', 'info', 'debug' ] },
|
||||
watchdog: { type: 'bool', dflt: true },
|
||||
log_keep_days: { type: 'int', dflt: 30, min: 0, max: 9999 },
|
||||
log_max: { type: 'int', dflt: 2000, min: 100, max: 20000 },
|
||||
@@ -158,6 +160,7 @@ function messages() {
|
||||
default_device_limit: _('Default device limit must be 1-32.'),
|
||||
domain: _('Domain may use lowercase letters, digits, dashes and dots.'),
|
||||
geo_provider: _('Unknown location service.'),
|
||||
log_level: _('Choose a system log level: errors, warnings, normal or verbose.'),
|
||||
log_keep_days: _('Keep activity for 0 (no age limit) to 9999 days.'),
|
||||
log_max: _('Log size must be 100-20000 events.'),
|
||||
log_persist: _('Save the log every 10min, hourly or off.'),
|
||||
|
||||
@@ -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.18.0';
|
||||
/** GitHub repository with Dawnline releases (updates and the installer). */
|
||||
export const REPO = 'tickcount/luci-app-dawnline';
|
||||
export const RUN_DIR = '/var/run/dawnline';
|
||||
@@ -226,6 +226,96 @@ export function ack_config(confs) {
|
||||
writefile(md5f, join('\n', lines) + '\n');
|
||||
};
|
||||
|
||||
/* ---------- syslog ---------- */
|
||||
|
||||
/*
|
||||
* Every line Dawnline puts in syslog, as podkop and sing-box do it:
|
||||
* dawnline: [info] [awg] Home started · accepting connections on port 51820
|
||||
* with the matching priority (daemon.err, .warning, .info, .debug), so
|
||||
* `logread -e dawnline` or a remote syslog filters by level. The admin's
|
||||
* level (settings.log_level) decides what goes out: error | warn | info
|
||||
* (the default) | debug (each step of a start or an apply).
|
||||
*/
|
||||
const LOG_RANK = { error: 0, warn: 1, info: 2, debug: 3 };
|
||||
const LOG_PRIO = { error: 'err', warn: 'warning', info: 'info', debug: 'debug' };
|
||||
const LOG_LEVEL_RE = regexp("option log_level '?(error|warn|info|debug)'?");
|
||||
// The level as last read, and the config file's mtime it was read at (a long-running agent sees a change).
|
||||
let log_cfg = { mtime: -1, level: 'info' };
|
||||
|
||||
/** The admin's syslog level (settings.log_level): error | warn | info | debug; info when not set. */
|
||||
export function log_level() {
|
||||
let mt = stat('/etc/config/dawnline')?.mtime ?? 0;
|
||||
if (mt != log_cfg.mtime) {
|
||||
let m = match(readfile('/etc/config/dawnline') ?? '', LOG_LEVEL_RE);
|
||||
log_cfg = { mtime: mt, level: m?.[1] ?? 'info' };
|
||||
}
|
||||
return log_cfg.level;
|
||||
};
|
||||
|
||||
/** Does a line at `level` go out at the admin's level? */
|
||||
export function log_on(level) {
|
||||
return (LOG_RANK[level] ?? 2) <= LOG_RANK[log_level()];
|
||||
};
|
||||
|
||||
// A line break or a tab with the blanks around it: one space in a syslog line (compiled once, syslog runs often).
|
||||
const LOG_BREAK = /[ \t\r\n]*[\t\r\n][ \t\r\n]*/g;
|
||||
|
||||
/** One syslog line's words: "[level] [src] line", on one line, at most 1000 characters. */
|
||||
export function syslog_line(level, src, line) {
|
||||
let one = replace(trim(`${line ?? ''}`), LOG_BREAK, ' ');
|
||||
return substr(`[${LOG_RANK[level] != null ? level : 'info'}] [${src ?? 'dawnline'}] ${one}`, 0, 1000);
|
||||
};
|
||||
|
||||
/**
|
||||
* A line in syslog at `level` (error | warn | info | debug) from `src`
|
||||
* (dawnline, awg, portal, apply, agent, service, settings, people, …), when
|
||||
* the admin's level takes it. Nothing is kept anywhere else: what the admin UI
|
||||
* shows goes through slog() below, which calls this too.
|
||||
*/
|
||||
export function syslog(level, src, line) {
|
||||
if (!log_on(level))
|
||||
return;
|
||||
system(`logger -t dawnline -p daemon.${LOG_PRIO[level] ?? 'info'} ${q(syslog_line(level, src, line))}`);
|
||||
};
|
||||
|
||||
// Option names whose values never go in a log line: private, preshared and header-protection keys.
|
||||
const SECRET_OPT = /(private|preshared|protection)_?key/;
|
||||
|
||||
/**
|
||||
* Options as a log line's words: "listen_port=51820, addresses=10.8.0.1/24,
|
||||
* private_key=***" (arrays joined with spaces, null as "-", secrets masked).
|
||||
*/
|
||||
export function opts_text(o) {
|
||||
let out = [];
|
||||
for (let k, v in o ?? {}) {
|
||||
let s = v == null ? '-' : type(v) == 'array' ? join(' ', v) : `${v}`;
|
||||
push(out, `${k}=${match(k, SECRET_OPT) ? '***' : s}`);
|
||||
}
|
||||
return join(', ', out);
|
||||
};
|
||||
|
||||
/**
|
||||
* A block of text in syslog, a line per line (an nft script, a peer list),
|
||||
* each "[level] [src] <prefix><line>": one logger for all of them.
|
||||
*/
|
||||
export function syslog_lines(level, src, text, prefix) {
|
||||
if (!log_on(level) || trim(`${text ?? ''}`) == '')
|
||||
return;
|
||||
let p = popen(`logger -t dawnline -p daemon.${LOG_PRIO[level] ?? 'info'}`, 'w');
|
||||
if (!p)
|
||||
return;
|
||||
for (let l in split(`${text ?? ''}`, '\n'))
|
||||
if (trim(l) != '')
|
||||
p.write(syslog_line(level, src, `${prefix ?? ''}${trim(l)}`) + '\n');
|
||||
p.close();
|
||||
};
|
||||
|
||||
/** A list in a log line: the first `n` (10) and how many more ("a, b, c and 12 more"). */
|
||||
export function some_of(list, n) {
|
||||
n ??= 10;
|
||||
return length(list) <= n ? join(', ', list) : `${join(', ', slice(list, 0, n))} and ${length(list) - n} more`;
|
||||
};
|
||||
|
||||
/* ---------- service log ---------- */
|
||||
|
||||
/*
|
||||
@@ -257,7 +347,11 @@ export function slog(src, level, msg, detail, who, extra) {
|
||||
f.close();
|
||||
}
|
||||
let line = e.by == 'admin' ? join(' ', filter([ 'admin', msg, e.kind, who, e.note ? '· ' + e.note : null ], (x) => x)) : who ? `${who} ${msg}` : msg;
|
||||
system(`logger -t dawnline${level == 'error' ? ' -p user.err' : ''} ${q(line)}`);
|
||||
// Problems carry what went wrong (the service log's detail: an error's text, the syslog lines around a crash).
|
||||
let lvl = { error: 'error', repair: 'warn', down: 'warn' }[level] ?? 'info';
|
||||
if (e.detail && lvl != 'info')
|
||||
line += ` · ${substr(replace(e.detail, /[\r\n\t]+/g, ' | '), 0, 400)}`;
|
||||
syslog(lvl, src, line);
|
||||
};
|
||||
|
||||
/** A change the admin made in LuCI, for the service log. */
|
||||
|
||||
@@ -154,6 +154,18 @@ function recorder() {
|
||||
return { w, c: { set: (cfg, s, k, v) => { w[`${s}.${k}`] = v; }, delete: (cfg, s, k) => { w[`${s}.${k}`] = null; } } };
|
||||
}
|
||||
|
||||
test('set_device_kind', () => {
|
||||
let mm = { devices: { d: { id: 'd', kind: 'phone' } } };
|
||||
let r = recorder();
|
||||
eq(core.set_device_kind(r.c, mm, 'd', 'tablet'), true, 'changed');
|
||||
eq([ r.w, mm.devices.d.kind ], [ { 'd.kind': 'tablet' }, 'tablet' ], 'written, and the model follows');
|
||||
r = recorder();
|
||||
eq(core.set_device_kind(r.c, mm, 'd', 'tablet'), false, 'the same kind changes nothing');
|
||||
eq(r.w, {}, 'nothing written');
|
||||
throws(() => core.set_device_kind(r.c, mm, 'd', 'toaster'), /^Unknown device type\.$/, 'not a kind');
|
||||
throws(() => core.set_device_kind(r.c, mm, 'x', 'phone'), /^Unknown device\.$/, 'unknown device');
|
||||
});
|
||||
|
||||
test('set_device_link', () => {
|
||||
let mm = { devices: { d: { id: 'd', mtu: 0, keepalive: null, lan_bypass: false } } };
|
||||
let r = recorder();
|
||||
|
||||
@@ -4,14 +4,16 @@
|
||||
// sync's nft and awg steps fail harmlessly in the container. /etc/config/dawnline
|
||||
// and the issued and reconnect marks are put back after.
|
||||
import { readfile, writefile, unlink } from 'fs';
|
||||
import { DATA_DIR, ensure_dir } from 'dawnline.util';
|
||||
import { DATA_DIR, RUN_DIR, ensure_dir } from 'dawnline.util';
|
||||
import * as core from 'dawnline.core';
|
||||
import * as awg from 'dawnline.awg';
|
||||
import * as people from 'dawnline.rpc.people';
|
||||
import * as devices from 'dawnline.devices';
|
||||
|
||||
const CONFIG = '/etc/config/dawnline';
|
||||
const ISSUED = `${DATA_DIR}/issued.json`;
|
||||
const RECONNECT = `${DATA_DIR}/reconnect.json`;
|
||||
const EVENTS = `${RUN_DIR}/events.json`;
|
||||
|
||||
// fn(), then the files as they were, whatever fn did.
|
||||
function kept(paths, fn) {
|
||||
@@ -65,3 +67,20 @@ test('device_rotate: New keys set the device up again', () => {
|
||||
});
|
||||
eq(core.load().devices.alice_phone.private_key, '', 'the fixture is back');
|
||||
});
|
||||
|
||||
test('portal: Reconnect changes what it is and LAN Bypass with the keys; LAN Bypass alone keeps them', () => {
|
||||
ensure_dir(RUN_DIR);
|
||||
kept([ CONFIG, ISSUED, RECONNECT, EVENTS ], () => {
|
||||
let mine = { by: 'portal', person: 'alice' };
|
||||
devices.reconnect('alice_phone', { ...mine, kind: 'tablet', lan_bypass: true });
|
||||
let d = core.load().devices.alice_phone;
|
||||
eq([ d.kind, d.lan_bypass ], [ 'tablet', true ], 'changed in the same write as the keys');
|
||||
let keys = d.public_key;
|
||||
devices.update('alice_phone', { lan_bypass: false }, mine);
|
||||
d = core.load().devices.alice_phone;
|
||||
eq([ d.lan_bypass, d.public_key ], [ false, keys ], 'LAN Bypass off, the keys as they were');
|
||||
throws(() => devices.update('alice_phone', { mtu: '1400' }, mine), /^Only the admin can change how a device connects\.$/, "the MTU stays the admin's");
|
||||
throws(() => devices.reconnect('alice_phone', { ...mine, kind: 'toaster' }), /^Unknown device type\.$/, 'not a kind');
|
||||
throws(() => devices.update('alice_phone', { lan_bypass: true }, { by: 'portal', person: 'bob' }), /^Device not found\.$/, "another person's device");
|
||||
});
|
||||
});
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -180,3 +180,15 @@ test('add_event_merged: per device', () => {
|
||||
eq(live.category_of('device_recovered'), 'problems', 'and so is its end');
|
||||
had == null ? unlink(path) : writefile(path, had);
|
||||
});
|
||||
|
||||
test('event_level and event_line: the system\'s events in syslog', () => {
|
||||
eq(live.event_level({ type: 'connect' }), null, 'a connection stays out of syslog');
|
||||
eq(live.event_level({ type: 'roam' }), null, 'so does a device moving networks');
|
||||
eq(live.event_level({ type: 'device_failing' }), null, "and a device's link trouble");
|
||||
eq(live.event_level({ type: 'device_changed' }), 'info', 'people and devices are info');
|
||||
eq(live.event_level({ type: 'server_down' }), 'warn', 'a problem is warn');
|
||||
eq(live.event_level({ type: 'server_up' }), 'info', 'its end is info');
|
||||
eq(live.event_line({ type: 'device_changed', pname: 'Myata', dname: 'Phone', detail: 'kind=phone, lan_bypass=on', by: 'portal' }),
|
||||
'Myata · Phone device changed · kind=phone, lan_bypass=on (portal)', 'names, what, detail, by whom');
|
||||
eq(live.event_line({ type: 'paused', person: 'p1' }), 'p1 paused', 'the id where there is no name');
|
||||
});
|
||||
@@ -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));
|
||||
|
||||
@@ -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';
|
||||
@@ -47,3 +47,9 @@ test('render: the table as it was', () => {
|
||||
m.devices.b1.lan_bypass = true;
|
||||
eq(render(m), golden, 'a device that keeps its own local network out of the tunnel changes nothing here');
|
||||
});
|
||||
|
||||
test('shape: chains, sets and rules of a table script', () => {
|
||||
let t = 'table inet dawnline {\n\tset inet_ok {\n\t\ttype ipv4_addr\n\t}\n\tchain forward {\n\t\ttype filter hook forward priority 0; policy accept;\n\t\tiifname "dawn0" ip saddr @inet_ok accept\n\t\t# a note\n\t\tiifname "dawn0" drop\n\t}\n}\n';
|
||||
eq(nft.shape(t), { chains: 1, sets: 1, rules: 2 }, 'the hook line, the policy and a comment are no rules');
|
||||
eq(nft.shape(''), { chains: 0, sets: 0, rules: 0 }, 'nothing');
|
||||
});
|
||||
@@ -26,6 +26,8 @@ test('validate: int', () => {
|
||||
test('validate: enum', () => {
|
||||
eq(schema.validate('geo_provider', 'ipapi.co'), 'ipapi.co', 'known');
|
||||
throws(() => schema.validate('geo_provider', 'maxmind'), /Unknown location service/, 'unknown');
|
||||
eq(schema.validate('log_level', 'debug'), 'debug', 'a syslog level');
|
||||
throws(() => schema.validate('log_level', 'trace'), /system log level/, 'not a syslog level');
|
||||
eq(schema.validate('update_interval', '7d'), '7d', 'interval from dawnline.updates');
|
||||
throws(() => schema.validate('update_interval', '2d'), /6h, 12h, 1d or 7d/, 'unknown interval');
|
||||
});
|
||||
|
||||
@@ -318,3 +318,18 @@ test('host_label, tunnel_name, slugify: dashes trimmed without a regex', () => {
|
||||
}
|
||||
same(null);
|
||||
});
|
||||
|
||||
test('syslog_line', () => {
|
||||
eq(util.syslog_line('warn', 'awg', 'Home stopped unexpectedly'), '[warn] [awg] Home stopped unexpectedly', 'level, source, words');
|
||||
eq(util.syslog_line('error', 'apply', 'failed:\n no table\tthere'), '[error] [apply] failed: no table there', 'one line');
|
||||
eq(util.syslog_line('loud', null, 'x'), '[info] [dawnline] x', 'an unknown level is info, no source is dawnline');
|
||||
eq(length(util.syslog_line('info', 'x', replace(sprintf('%1500s', ''), ' ', 'y'))), 1000, 'at most 1000 characters');
|
||||
});
|
||||
|
||||
test('opts_text: options in a log line, keys masked', () => {
|
||||
eq(util.opts_text({ listen_port: 51820, addresses: [ '10.8.0.1/24' ], private_key: 'abc=', mtu: null }),
|
||||
'listen_port=51820, addresses=10.8.0.1/24, private_key=***, mtu=-', 'values, lists, a secret, nothing');
|
||||
eq(util.opts_text({ preshared_key: 'x', awg_header_protection_key: 'y', public_key: 'z' }),
|
||||
'preshared_key=***, awg_header_protection_key=***, public_key=z', 'a public key is no secret');
|
||||
eq(util.opts_text(null), '', 'none');
|
||||
});
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "dawnline-web",
|
||||
"version": "0.16.3",
|
||||
"version": "0.18.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "dawnline-web",
|
||||
"version": "0.16.3",
|
||||
"version": "0.18.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"qrcode-generator": "2.0.4"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dawnline-web",
|
||||
"version": "0.16.3",
|
||||
"version": "0.18.0",
|
||||
"private": true,
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
|
||||
@@ -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<string, Pair>;
|
||||
dev?: Record<string, Pair>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+84
-16
@@ -1,8 +1,8 @@
|
||||
// The AmneziaWG core in the admin: how a device connects (.conf, AmneziaVPN
|
||||
// key, QR), the disguise and its parameters, and the core's own settings on
|
||||
// key, QR, V2RayTun's link), the disguise and its parameters, and the core's own settings on
|
||||
// Server → AmneziaWG. Plain WireGuard is AmneziaWG with the disguise off.
|
||||
|
||||
import type { AwgConfig, Server, Status } from '../../shared/types';
|
||||
import type { AwgConfig, Kind, Server, Status } from '../../shared/types';
|
||||
import { E } from '../e';
|
||||
import { api } from '../api';
|
||||
import { button } from '../ui/button';
|
||||
@@ -14,10 +14,12 @@ import { callout, card, firstBad, group, liveRow, row } from '../ui/layout';
|
||||
import { qrCode } from '../ui/qr';
|
||||
import { keepaliveHelp, mtuHelp, portHelp, type PortHold } from '../netcheck';
|
||||
import { vpnKey } from '../../shared/vpnkey';
|
||||
import { awgLink, v2rFits } from '../../shared/awglink';
|
||||
import { V2R_WINDOWS } from '../../shared/flags';
|
||||
import { icon } from '../../shared/icons';
|
||||
import { methodInfo, methodPicker, type Method, defaultMethod, legacyTitle } from '../disguise';
|
||||
import { fmt, fill, num, plural } from '../../shared/i18n';
|
||||
import { coreHead, type Core, type CoreCtx } from './common';
|
||||
import { coreHead, type ConnectView, type Core, type CoreCtx } from './common';
|
||||
|
||||
/** `.conf` names of the disguise parameters, in file order. */
|
||||
const CONF: [string, string][] = [
|
||||
@@ -219,8 +221,71 @@ export function plainWg(cfg: AwgConfig): boolean {
|
||||
return Object.entries(o).every(([k, v]) => v == null || v === '' || v === (neutral[k] ?? '0'));
|
||||
}
|
||||
|
||||
/** File / key / QR switcher for a client configuration; opens on the file unless asked otherwise. */
|
||||
async function connectBlock(cfg: AwgConfig, initial: 'file' | 'key' | 'qr' = 'file'): Promise<HTMLElement> {
|
||||
/**
|
||||
* V2RayTun's way in: the connection as its awg:// link (shared/awglink.ts;
|
||||
* the app's own words are in portal/setup.ts, with where they come from). A
|
||||
* computer runs it on Windows, whose core looks the server's name up itself:
|
||||
* the link keeps the name. That one is off for now (shared/flags.ts
|
||||
* V2R_WINDOWS: its core leaves the server's DNS unused). Anything else is
|
||||
* taken for Android, whose core takes no name: the link has the server's IP
|
||||
* (amnezia.host_ip, from device_config).
|
||||
*/
|
||||
function v2rPane(cfg: AwgConfig, kind: Kind): HTMLElement {
|
||||
const win = kind === 'computer';
|
||||
const host = cfg.amnezia.host.replace(/^\[(.*)\]$/, '$1');
|
||||
const ip = win ? null : (cfg.amnezia.host_ip ?? null);
|
||||
const link = awgLink(cfg.conf, cfg.server, ip);
|
||||
const box = E('div', { class: 'dl-linkbox' }, [
|
||||
E('span', { class: 'dl-mono', title: link }, link),
|
||||
button(_('Copy'), () => copyText(link, _('Link copied'))),
|
||||
]);
|
||||
if (win)
|
||||
return E('div', { class: 'dl-stack gap8' }, [
|
||||
box,
|
||||
E(
|
||||
'span',
|
||||
{ class: 'dl-sub' },
|
||||
fmt(
|
||||
_(
|
||||
'V2RayTun on Windows: %s, then set its mode to %s and connect. That mode needs administrator rights: the app offers to restart with them.',
|
||||
),
|
||||
['+', _('Import from clipboard', 'V2RayTun app')].join(' → '),
|
||||
_('Tunnel', 'V2RayTun app'),
|
||||
),
|
||||
),
|
||||
]);
|
||||
return E('div', { class: 'dl-qr-pane' }, [
|
||||
qrCode(link),
|
||||
E(
|
||||
'span',
|
||||
{ class: 'dl-sub' },
|
||||
fmt(
|
||||
_('V2RayTun on Android: %s, or copy the link and %s.'),
|
||||
['+', _('Import config from QRcode', 'V2RayTun app')].join(' → '),
|
||||
['+', _('Import config from Clipboard', 'V2RayTun app')].join(' → '),
|
||||
),
|
||||
),
|
||||
box,
|
||||
// Honest about what the IP costs, and about a name that gives none.
|
||||
ip && ip !== host
|
||||
? E(
|
||||
'div',
|
||||
{ class: 'dl-hint' },
|
||||
_('The link has the server’s IP address, not its name: if the address changes, set the device up again.'),
|
||||
)
|
||||
: !ip
|
||||
? callout('warn', fmt(_('%s does not resolve right now, and V2RayTun on Android connects by IP address only.'), host))
|
||||
: '',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* File / key / QR / V2RayTun switcher for a client configuration of a device
|
||||
* of this kind; opens on the file unless asked otherwise. V2RayTun is left out
|
||||
* for a router, for a computer while V2R_WINDOWS is off (shared/flags.ts) and
|
||||
* for AmneziaWG 3.1 (the Maximum disguise), which it lacks.
|
||||
*/
|
||||
async function connectBlock(cfg: AwgConfig, kind: Kind, initial: ConnectView = 'file'): Promise<HTMLElement> {
|
||||
if (!cfg.has_private_key)
|
||||
return E(
|
||||
'div',
|
||||
@@ -228,7 +293,7 @@ async function connectBlock(cfg: AwgConfig, initial: 'file' | 'key' | 'qr' = 'fi
|
||||
_('This device generated its own keys in the browser, so its full configuration only exists on that device.'),
|
||||
);
|
||||
const key = await vpnKey(cfg, cfg.server);
|
||||
const panes: Record<string, () => Node> = {
|
||||
const panes: Partial<Record<ConnectView, () => Node>> = {
|
||||
qr: () =>
|
||||
E('div', { class: 'dl-qr-pane' }, [
|
||||
qrCode(cfg.conf),
|
||||
@@ -252,19 +317,22 @@ async function connectBlock(cfg: AwgConfig, initial: 'file' | 'key' | 'qr' = 'fi
|
||||
]),
|
||||
file: () => fileCard(cfg),
|
||||
};
|
||||
const body = E('div', { class: 'dl-connect-body' });
|
||||
const seg = E('div', { class: 'dl-seg' });
|
||||
const show = (id: string) => {
|
||||
seg.querySelectorAll('button').forEach((b) => b.classList.toggle('on', b.dataset.id === id));
|
||||
dom.content(body, panes[id]());
|
||||
};
|
||||
for (const [id, label] of [
|
||||
if (kind !== 'router' && (kind !== 'computer' || V2R_WINDOWS) && v2rFits(cfg.conf)) panes.v2r = () => v2rPane(cfg, kind);
|
||||
const labels: [ConnectView, string][] = [
|
||||
['file', _('File')],
|
||||
['key', _('Key')],
|
||||
['qr', _('QR code')],
|
||||
])
|
||||
seg.appendChild(E('button', { type: 'button', 'data-id': id, click: () => show(id) }, label));
|
||||
show(initial);
|
||||
['v2r', 'V2RayTun'],
|
||||
];
|
||||
const body = E('div', { class: 'dl-connect-body' });
|
||||
const seg = E('div', { class: 'dl-seg' });
|
||||
const show = (id: ConnectView) => {
|
||||
seg.querySelectorAll('button').forEach((b) => b.classList.toggle('on', b.dataset.id === id));
|
||||
dom.content(body, panes[id]!());
|
||||
};
|
||||
for (const [id, label] of labels)
|
||||
if (panes[id]) seg.appendChild(E('button', { type: 'button', 'data-id': id, click: () => show(id) }, label));
|
||||
show(panes[initial] ? initial : 'file');
|
||||
return E('div', { class: 'dl-stack gap12' }, [seg, body]);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
// What every tunnel core gives the admin (cores/index.ts holds the registry),
|
||||
// what a core's settings card gets from the Server page, and that card's head.
|
||||
|
||||
import type { ClientConfig, Server, Status } from '../../shared/types';
|
||||
import type { ClientConfig, Kind, Server, Status } from '../../shared/types';
|
||||
import { E } from '../e';
|
||||
|
||||
/** The ways a device takes its configuration, as the set-up switcher names them. */
|
||||
export type ConnectView = 'file' | 'key' | 'qr' | 'v2r';
|
||||
|
||||
/** What the Server page hands a core's settings card. */
|
||||
export interface CoreCtx {
|
||||
st: Status;
|
||||
@@ -21,8 +24,8 @@ export interface Core {
|
||||
settingsCard(ctx: CoreCtx, srv: Server): HTMLElement;
|
||||
/** Overview: how the tunnel looks on the wire (the disguise tile). */
|
||||
overviewTile(srv: Server): HTMLElement;
|
||||
/** How a device connects: file / key / QR. */
|
||||
connectBlock(cfg: ClientConfig, initial?: 'file' | 'key' | 'qr'): Promise<HTMLElement>;
|
||||
/** How a device of this kind connects: file / key / QR / V2RayTun's link, opening on `initial`. */
|
||||
connectBlock(cfg: ClientConfig, kind: Kind, initial?: ConnectView): Promise<HTMLElement>;
|
||||
/** What a QR code for the device carries. */
|
||||
qrText(cfg: ClientConfig): string;
|
||||
/** The key the device's app imports (⋯ → Copy key), with the menu label. */
|
||||
|
||||
@@ -189,7 +189,7 @@ export async function openDevice(person: Person, dev: Device, o: DeviceOpts) {
|
||||
let today = o.today ?? isoDay(new Date());
|
||||
let srv = o.server;
|
||||
// Phones and tablets are set up by scanning; computers and routers by a file.
|
||||
const block = (c: ClientConfig) => core.connectBlock(c, dev.kind === 'phone' || dev.kind === 'tablet' ? 'qr' : 'file');
|
||||
const block = (c: ClientConfig) => core.connectBlock(c, dev.kind, dev.kind === 'phone' || dev.kind === 'tablet' ? 'qr' : 'file');
|
||||
// An older configuration on the device: the new one waits for a click (the inline QR code is itself a delivery).
|
||||
// `relinked`: its MTU or keep-alive was just changed here, which outdates the configuration on screen even where
|
||||
// the router keeps no record of what the device got (never "stale" then, e.g. after a JSON import).
|
||||
@@ -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),
|
||||
]),
|
||||
]),
|
||||
);
|
||||
@@ -666,8 +665,8 @@ export function addDevice(person: Person, o: DeviceOpts) {
|
||||
),
|
||||
),
|
||||
);
|
||||
// LAN Bypass: off unless chosen (the person chooses it on the portal, the admin here).
|
||||
const bypass = sw(false, _('LAN Bypass'));
|
||||
// LAN Bypass: on unless turned off (the person chooses it on the portal, the admin here).
|
||||
const bypass = sw(true, _('LAN Bypass'));
|
||||
const over = person.devices.length >= person.device_limit;
|
||||
modal(
|
||||
fmt(_('Add a device for %s'), person.name),
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// The activity log's vocabulary: categories, who did what, problems, retention.
|
||||
// No DOM and no RPC here (see ./render for rows).
|
||||
|
||||
import type { LogEvent } from '../../shared/types';
|
||||
import type { Kind, LogEvent } from '../../shared/types';
|
||||
import { kindLabel } from '../../shared/format';
|
||||
import type { LogCategory, LogsInfo, ServiceLogEntry } from '../api';
|
||||
import { fmt, known, plural } from '../../shared/i18n';
|
||||
import { LOG_TEMPLATES } from './log-templates';
|
||||
@@ -136,13 +137,25 @@ export function changedText(detail: string): string {
|
||||
.join(', ');
|
||||
}
|
||||
|
||||
/** A device's settings a device_changed event lists (its link options, "mtu, keepalive"); anything else as written. */
|
||||
/**
|
||||
* A device's settings a device_changed event lists: each with what it became
|
||||
* ("lan_bypass=on", "kind=phone", "mtu=1400", "keepalive=auto": the server's),
|
||||
* or by name alone as events before 0.18 have them ("mtu, keepalive");
|
||||
* anything else as written.
|
||||
*/
|
||||
export function deviceChangedText(detail: string): string {
|
||||
const f: Record<string, string> = { mtu: 'MTU', keepalive: _('keep-alive'), lan_bypass: _('LAN Bypass') };
|
||||
return detail
|
||||
.split(', ')
|
||||
.map((k) => f[k] ?? k)
|
||||
.join(', ');
|
||||
const f: Record<string, string> = { mtu: 'MTU', keepalive: _('keep-alive'), lan_bypass: _('LAN Bypass'), kind: _('type') };
|
||||
const one = (part: string): string => {
|
||||
const at = part.indexOf('=');
|
||||
if (at < 0) return f[part] ?? part;
|
||||
const k = part.slice(0, at);
|
||||
const v = part.slice(at + 1);
|
||||
if (k === 'lan_bypass') return v === 'on' ? _('LAN Bypass on') : _('LAN Bypass off');
|
||||
if (k === 'kind') return fmt(_('type: %s'), ['computer', 'phone', 'tablet', 'router', 'other'].includes(v) ? kindLabel(v as Kind) : v);
|
||||
if (v === 'auto') return fmt(_('%s: automatic'), f[k] ?? k);
|
||||
return k === 'keepalive' ? fmt(_('keep-alive %s s'), v) : `${f[k] ?? k} ${v}`;
|
||||
};
|
||||
return detail.split(', ').map(one).join(', ');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -179,6 +179,14 @@ export function eventText(st: Pick<Status, 'people'>, e: LogEvent, personId?: st
|
||||
];
|
||||
if (detail === 'turned off') return say(_('Device %s turned off'), wd);
|
||||
if (detail === 'turned on') return say(_('Device %s turned on'), wd);
|
||||
// On the portal: LAN Bypass from its ⋯ menu, what it is and LAN Bypass with Reconnect.
|
||||
if (by === 'portal')
|
||||
return [
|
||||
...(scoped
|
||||
? say(_('Device %s changed on the portal'), b(dev || _('a device')))
|
||||
: say(_('Person %s changed device %s on their portal'), b(who), b(dev || _('a device')))),
|
||||
...(detail ? [m(` · ${deviceChangedText(detail)}`)] : []),
|
||||
];
|
||||
return [...say(_('Device %s changed'), wd), ...(detail ? [m(` · ${deviceChangedText(detail)}`)] : [])];
|
||||
case 'device_keys':
|
||||
return scoped
|
||||
|
||||
@@ -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<GeoPoint | undefined>((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(
|
||||
`<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 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. */
|
||||
|
||||
@@ -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<Status>;
|
||||
/** 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<string, { p: Person; down: HTMLElement; up: HTMLElement }>();
|
||||
|
||||
/** `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<Status> {
|
||||
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();
|
||||
|
||||
@@ -19,7 +19,7 @@ import type { PersonPage } from './index';
|
||||
async function showDeviceQr(page: PersonPage, d: Device) {
|
||||
const cfg = await attempt(() => api.deviceConfig(d.id, true));
|
||||
if (!cfg) return;
|
||||
modal(fmt(_('Set up %s'), d.name), [await page.core.connectBlock(cfg, 'qr')], [cancelButton(_('Close'))]);
|
||||
modal(fmt(_('Set up %s'), d.name), [await page.core.connectBlock(cfg, d.kind, 'qr')], [cancelButton(_('Close'))]);
|
||||
}
|
||||
|
||||
async function downloadConfig(page: PersonPage, d: Device) {
|
||||
|
||||
@@ -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]))),
|
||||
]);
|
||||
}
|
||||
@@ -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<string, DayUsage[]> = {};
|
||||
poller?: Poller<Loaded>;
|
||||
/** 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<MeterAnswer>;
|
||||
/** 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;
|
||||
|
||||
@@ -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')],
|
||||
|
||||
@@ -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<Status>;
|
||||
/** 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<MeterAnswer>;
|
||||
|
||||
@@ -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<MeterAnswer>({
|
||||
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) => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// Settings → Logs & history: retention, what is recorded, and the stored data.
|
||||
// Settings → Logs & history: retention, what is recorded, what goes to the
|
||||
// router's system log, and the stored data.
|
||||
|
||||
import { E } from '../../e';
|
||||
import { api } from '../../api';
|
||||
@@ -67,6 +68,17 @@ export function logsCard(host: SettingsHost): HTMLElement {
|
||||
String(p.usage_months),
|
||||
_('Monthly traffic'),
|
||||
);
|
||||
// The router's system log (logread): dawnline.util syslog() writes at these levels.
|
||||
const level = select(
|
||||
[
|
||||
['error', _('Errors only')],
|
||||
['warn', _('Warnings and errors')],
|
||||
['info', _('Normal')],
|
||||
['debug', _('Verbose (debug)')],
|
||||
],
|
||||
String(host.d.effective.log_level ?? 'info'),
|
||||
_('System log'),
|
||||
);
|
||||
const cats = multiSelect(
|
||||
CATEGORIES.map((c): [string, Node] => [
|
||||
c,
|
||||
@@ -111,6 +123,13 @@ export function logsCard(host: SettingsHost): HTMLElement {
|
||||
persist,
|
||||
_('The log lives in memory and is copied to flash. Memory only saves flash writes but is lost on reboot.'),
|
||||
),
|
||||
row(
|
||||
_('System log'),
|
||||
level,
|
||||
_(
|
||||
'What Dawnline writes to the router’s system log (logread -e dawnline). Verbose adds each step of a start and of applying settings.',
|
||||
),
|
||||
),
|
||||
row(_('Daily traffic'), days, _('Per-day history behind the charts.')),
|
||||
row(_('Monthly traffic'), months, _('Per-month totals; data limits use the current month.')),
|
||||
E('h4', { class: 'dl-setsub' }, _('Stored data')),
|
||||
@@ -173,6 +192,7 @@ export function logsCard(host: SettingsHost): HTMLElement {
|
||||
usage_keep_days: days.value,
|
||||
usage_keep_months: months.value,
|
||||
log_category: cats.value(),
|
||||
log_level: level.value,
|
||||
},
|
||||
_('Saved'),
|
||||
'logs',
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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<MeterAnswer> {
|
||||
return createPoller<MeterAnswer>({
|
||||
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();
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -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; }
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -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 <style> element for the view root (see the note at the top). */
|
||||
|
||||
@@ -230,29 +230,9 @@
|
||||
.dl-pop-actions { display: flex; gap: 6px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--dl-line); }
|
||||
.dl-pop-actions .cbi-button { flex: 1; height: 28px !important; font-size: 12px !important; justify-content: center; }
|
||||
|
||||
/* charts */
|
||||
.dl-chartbox { position: relative; }
|
||||
.dl-bars { display: flex; align-items: flex-end; gap: 4px; border-bottom: 1px solid var(--dl-line); }
|
||||
.dl-bar { flex: 1; height: 100%; display: flex; flex-direction: column-reverse; gap: 1px; cursor: default; min-width: 3px; }
|
||||
.dl-bar i { display: block; border-radius: 3px 3px 0 0; }
|
||||
.dl-bar i.down { background: var(--dl-chart-1); }
|
||||
.dl-bar i.up { background: var(--dl-chart-2); opacity: .75; border-radius: 3px 3px 0 0; }
|
||||
.dl-bar:hover i { filter: brightness(1.25); }
|
||||
.dl-bar.empty { background: linear-gradient(to top, var(--dl-line) 2px, transparent 2px); }
|
||||
/* tooltips (charts: charts.css) */
|
||||
.dl-tip { position: absolute; top: -8px; transform: translate(-50%, -100%); padding: 8px 10px; border-radius: 10px; font-size: 12px; line-height: 18px; white-space: nowrap;
|
||||
background: var(--dl-elevated); border: 1px solid var(--dl-line); box-shadow: var(--shadow-xl, 0 8px 16px -4px rgba(0,0,0,.4)); pointer-events: none; z-index: 3; }
|
||||
.dl-tip-title { font-weight: 500; }
|
||||
.dl-tip-float { position: fixed; z-index: 2000; color: var(--dl-fg); }
|
||||
.dl-meter, .dl-slots { cursor: default; }
|
||||
.dl-axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--dl-fg-faint); margin-top: 6px; }
|
||||
.dl-legend i.down { background: var(--dl-chart-1); } .dl-legend i.up { background: var(--dl-chart-2); }
|
||||
.dl-spark { display: flex; align-items: flex-end; flex: 0 0 auto; --dl-gap: 2px; }
|
||||
.dl-spark i { flex: 1; display: block; border-radius: 2px 2px 0 0; background: var(--dl-chart-1); opacity: .85; }
|
||||
.dl-spark i.zero { opacity: .22; }
|
||||
.dl-spark > span:hover i:not(.zero) { opacity: 1; filter: brightness(1.25); }
|
||||
/* A day's column in the daily charts (spark, a device card's bars, the last 30 days): the chart's full height and
|
||||
half the gap on either side, so its tooltip answers above a short bar and between two bars. The outer columns
|
||||
keep no outer half, so the bars stand where a plain gap would put them. */
|
||||
.dl-spark > span, .dl-dbars > span, .dl-bento-bars > span { flex: 1; min-width: 0; height: 100%; display: flex; align-items: flex-end; padding: 0 calc(var(--dl-gap) / 2); }
|
||||
.dl-spark > span:first-child, .dl-dbars > span:first-child, .dl-bento-bars > span:first-child { padding-left: 0; }
|
||||
.dl-spark > span:last-child, .dl-dbars > span:last-child, .dl-bento-bars > span:last-child { padding-right: 0; }
|
||||
.dl-slots { cursor: default; }
|
||||
@@ -25,11 +25,6 @@
|
||||
.dl-dcard-trend { display: flex; align-items: flex-end; gap: 12px; min-width: 0; }
|
||||
.dl-dcard-trend > .dl-stack { flex: none; }
|
||||
.dl-dcard-trend b { font-size: 16px; font-weight: 500; font-variant-numeric: tabular-nums; }
|
||||
.dl-dbars { flex: 1; min-width: 0; height: 32px; display: flex; align-items: flex-end; --dl-gap: 2px; }
|
||||
.dl-dbars i { flex: 1; min-width: 0; border-radius: 2px; background: var(--dl-chart-1); opacity: .55; }
|
||||
.dl-dbars i.zero { background: var(--dl-track); opacity: 1; }
|
||||
.dl-dbars i.hi { opacity: 1; }
|
||||
.dl-dbars > span:hover i { opacity: 1; filter: brightness(1.2); }
|
||||
.dl-datechip { position: relative; display: inline-flex; }
|
||||
.dl-date-hidden { position: absolute !important; left: 0; bottom: 0; width: 1px !important; min-width: 0 !important; height: 1px !important; opacity: 0; pointer-events: none; border: 0 !important; padding: 0 !important; margin: 0 !important; }
|
||||
.dl-chipbtn .dl-icon { width: 13px; height: 13px; }
|
||||
@@ -85,10 +80,6 @@
|
||||
.dl-hc-reach { display: inline-flex; gap: 4px; }
|
||||
.dl-hc-speed { border-radius: 12px; background: var(--dl-soft); padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
|
||||
.dl-hc-speed-row { display: flex; align-items: baseline; gap: 12px; font-size: 13px; font-variant-numeric: tabular-nums; }
|
||||
.dl-hc-chart { display: block; width: 100%; height: 30px; }
|
||||
.dl-hc-chart .area { fill: color-mix(in srgb, var(--dl-chart-1) 16%, transparent); }
|
||||
.dl-hc-chart .dn { fill: none; stroke: var(--dl-chart-1); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
|
||||
.dl-hc-chart .up { fill: none; stroke: var(--dl-ok); stroke-width: 1.2; vector-effect: non-scaling-stroke; }
|
||||
.dl-hc-devs { display: flex; flex-wrap: wrap; gap: 6px; }
|
||||
.dl-hc-dev { display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px; border-radius: 999px; background: var(--dl-soft); font-size: 11.5px; }
|
||||
.dl-hc-dev .dl-icon-wrap { display: inline-flex; } .dl-hc-dev .dl-icon { width: 12px; height: 12px; color: var(--dl-fg-muted); }
|
||||
@@ -143,15 +134,7 @@
|
||||
.dl-dn { color: var(--dl-accent); } .dl-up { color: var(--dl-ok); }
|
||||
.dl-bento-method { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 500; }
|
||||
.dl-bento-method .dl-icon { width: 20px; height: 20px; color: var(--dl-accent); }
|
||||
.dl-meter { display: inline-flex; gap: 3px; }
|
||||
.dl-meter i { width: 16px; height: 4px; border-radius: 2px; background: var(--dl-line); }
|
||||
.dl-meter i.on { background: var(--dl-accent); }
|
||||
.dl-bento-total { font-size: 16px; font-weight: 500; margin-left: 8px; }
|
||||
.dl-bento-bars { display: flex; align-items: flex-end; height: 54px; --dl-gap: 3px; }
|
||||
.dl-bento-bars i { flex: 1; min-width: 0; border-radius: 3px 3px 0 0; background: var(--dl-soft-hover); transition: background .15s; }
|
||||
.dl-bento-bars i.future { height: 4px; background: var(--dl-soft); }
|
||||
.dl-bento-bars > span:hover i:not(.hi) { background: var(--dl-fg-faint); }
|
||||
.dl-bento-bars i.hi { background: var(--dl-accent); }
|
||||
@media (max-width: 700px) { .dl-addrbar { flex-wrap: wrap; } }
|
||||
@media (max-width: 900px) { .dl-bento { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .dl-bento-tile.online { grid-column: span 2; } }
|
||||
@media (max-width: 560px) { .dl-bento { grid-template-columns: minmax(0, 1fr); } .dl-bento-tile.online, .dl-bento-tile.month { grid-column: auto; } }
|
||||
@@ -170,12 +153,7 @@
|
||||
.dl-speed-val { font-size: 20px; line-height: 26px; font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.dl-speed-today { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--dl-fg-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
|
||||
.dl-speed-today b { font-weight: 500; color: var(--dl-fg); }
|
||||
.dl-speed-chart { display: block; width: 100%; height: 44px; }
|
||||
.dl-speed-chart .area { fill: color-mix(in srgb, var(--dl-accent) 16%, transparent); }
|
||||
.dl-speed-chart .line { fill: none; stroke: var(--dl-accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
|
||||
.dl-speed-chart .line.up { stroke: var(--dl-ok); stroke-width: 1.2; opacity: .85; }
|
||||
.dl-speed-wait { height: 44px; display: flex; flex-direction: column; justify-content: flex-end; gap: 6px; font-size: 11px; color: var(--dl-fg-faint); }
|
||||
.dl-speed-wait i { display: block; height: 1px; background: var(--dl-line); order: 2; }
|
||||
.dl-speed-val.off { color: var(--dl-fg-faint); }
|
||||
.dl-fld { display: flex; flex-direction: column; gap: 8px; margin: 0 0 16px; }
|
||||
.dl-fld-label { font-size: 13px; font-weight: 500; color: var(--dl-fg); }
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
.dl-plist > .dl-card.dl-filtered { display: none; }
|
||||
/* Stopped (paused, ended, over a limit): the card fades, its strip and actions stay bright. */
|
||||
.dl-plist > .dl-card.dl-off :is(.dl-card-name, .dl-avatar, .dl-access, .dl-slotbar, .dl-chips, .dl-pill-ic, .dl-use-num, .dl-pside-foot, .dl-pside-state) { opacity: .45; }
|
||||
.dl-plist > .dl-card.dl-off .dl-usebar i { background: var(--dl-fg-faint); }
|
||||
.dl-plist > .dl-card.dl-off .dl-smeter > i { background: var(--dl-fg-faint); }
|
||||
.dl-plist > .dl-card.dl-off .dl-chip-tag { background: var(--dl-soft); color: var(--dl-fg-muted); }
|
||||
/* Why, across the card's bottom edge, with the action that lifts it */
|
||||
.dl-pcard:has(> .dl-pstrip) { row-gap: 14px; }
|
||||
|
||||
@@ -70,11 +70,6 @@
|
||||
.dl-slots i.over { background: color-mix(in srgb, var(--dl-warn) 80%, transparent); }
|
||||
.dl-date { display: flex; align-items: center; gap: 8px; flex: 1 1 150px; min-width: 0; box-sizing: border-box; height: 34px; padding: 0 10px; border: 1px solid var(--input, var(--dl-line)); border-radius: 8px; color: var(--dl-fg-faint); }
|
||||
.dl-date input { border: 0 !important; background: transparent !important; box-shadow: none !important; padding: 0 !important; height: 32px !important; color: var(--dl-fg); flex: 1; min-width: 0 !important; width: 100% !important; }
|
||||
.dl-meter { position: relative; height: 6px; border-radius: 999px; background: var(--dl-track); }
|
||||
.dl-meter > i { display: block; height: 100%; border-radius: 999px; background: var(--dl-accent); }
|
||||
.dl-meter.warn > i { background: var(--dl-warn); } .dl-meter.bad > i { background: var(--dl-bad); }
|
||||
.dl-meter .mark { position: absolute; left: 90%; top: -3px; width: 1px; height: 12px; background: var(--dl-warn); }
|
||||
.dl-meter.sm { height: 4px; }
|
||||
.dl-chips-row { display: flex; flex-wrap: wrap; gap: 4px; }
|
||||
.dl-chipbtn { all: unset; cursor: pointer; height: 26px; padding: 0 10px; border-radius: 999px; background: var(--dl-soft); font-size: 12px; font-weight: 500; display: inline-flex; align-items: center; }
|
||||
.dl-chipbtn:hover { background: var(--dl-soft-hover); } .dl-chipbtn.on { background: var(--dl-primary); color: var(--dl-primary-fg); }
|
||||
@@ -111,15 +106,11 @@
|
||||
.dl-use-num { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
|
||||
.dl-use-num b { font-size: 15px; font-weight: 500; }
|
||||
.dl-use-live { display: flex; align-items: center; gap: 8px; font-size: 12px; font-variant-numeric: tabular-nums; }
|
||||
.dl-usebar { display: flex; gap: 2px; height: 6px; border-radius: 999px; overflow: hidden; background: var(--dl-track); }
|
||||
.dl-usebar i { display: block; height: 100%; min-width: 3px; flex: 0 1 0; }
|
||||
.dl-usebar i.fill { flex: none; min-width: 0; border-radius: 999px; background: var(--dl-accent); }
|
||||
.dl-usebar.warn i.fill { background: var(--dl-warn); } .dl-usebar.bad i.fill { background: var(--dl-bad); }
|
||||
.dl-usebar .c0, .dl-swatch.c0 { background: var(--dl-chart-1); }
|
||||
.dl-usebar .c1, .dl-swatch.c1 { background: #8b7cf6; }
|
||||
.dl-usebar .c2, .dl-swatch.c2 { background: #2fb889; }
|
||||
.dl-usebar .c3, .dl-swatch.c3 { background: #d9a03f; }
|
||||
.dl-usebar .c4, .dl-swatch.c4 { background: var(--dl-fg-faint); }
|
||||
.dl-smeter .c0, .dl-swatch.c0 { background: var(--dl-chart-1); }
|
||||
.dl-smeter .c1, .dl-swatch.c1 { background: #8b7cf6; }
|
||||
.dl-smeter .c2, .dl-swatch.c2 { background: #2fb889; }
|
||||
.dl-smeter .c3, .dl-swatch.c3 { background: #d9a03f; }
|
||||
.dl-smeter .c4, .dl-swatch.c4 { background: var(--dl-fg-faint); }
|
||||
.dl-tip-row { display: flex; align-items: center; gap: 8px; min-width: 160px; }
|
||||
.dl-tip-row b { margin-left: auto; font-weight: 500; }
|
||||
.dl-swatch { width: 8px; height: 8px; border-radius: 2px; flex: none; }
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
// The chart tooltip: one card anchored above a point of a chart (not under the
|
||||
// pointer, see tooltip.ts for that), gliding from one point to the next while a
|
||||
// chart is read (shared/scrub.ts). Its numbers swap at once; only the card moves.
|
||||
// It hides when the page navigates, on scrolling, and when its owner lets go.
|
||||
|
||||
import { E } from '../e';
|
||||
import { onNavigate } from './nav';
|
||||
|
||||
let card: HTMLElement | null = null;
|
||||
let owner: object | null = null;
|
||||
const still = () => matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||
|
||||
/** Show `kids` above page point (x, y) for `who`; the same owner's next point glides there. */
|
||||
export function showGlide(who: object, x: number, y: number, kids: (Node | string)[]): void {
|
||||
card ??= document.body.appendChild(E('div', { class: 'dl-tip dl-tip-float dl-root dl-glide' }));
|
||||
card.replaceChildren(...kids.map((k) => (typeof k === 'string' ? document.createTextNode(k) : k)));
|
||||
card.style.display = '';
|
||||
// Kept inside the window: measured with its new content, before it moves.
|
||||
const w = card.offsetWidth;
|
||||
const cx = Math.min(innerWidth - 8 - w / 2, Math.max(8 + w / 2, x));
|
||||
card.classList.toggle('glides', owner === who && !still());
|
||||
card.style.transform = `translate(${cx}px, ${y - 10}px) translate(-50%, -100%)`;
|
||||
card.classList.add('on');
|
||||
owner = who;
|
||||
}
|
||||
|
||||
/** Hide the card (only if `who` owns it, when given). */
|
||||
export function hideGlide(who?: object): void {
|
||||
if (!card || (who && who !== owner)) return;
|
||||
card.classList.remove('on', 'glides');
|
||||
card.style.display = 'none';
|
||||
owner = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A tooltip for a piece that is one value (a meter): above `anchor` (the piece's
|
||||
* top centre by default) while the pointer is on it, after a tap (until a tap
|
||||
* elsewhere), or while it has focus.
|
||||
*/
|
||||
export function pointTip(el: HTMLElement, content: () => (Node | string)[], anchor?: () => [number, number]): void {
|
||||
const at = (): [number, number] => {
|
||||
if (anchor) return anchor();
|
||||
const r = el.getBoundingClientRect();
|
||||
return [r.left + r.width / 2, r.top];
|
||||
};
|
||||
let shown = false;
|
||||
const show = () => {
|
||||
shown = true;
|
||||
const [x, y] = at();
|
||||
showGlide(el, x, y, content());
|
||||
document.addEventListener('pointerdown', away, true);
|
||||
};
|
||||
const hide = () => {
|
||||
shown = false;
|
||||
hideGlide(el);
|
||||
document.removeEventListener('pointerdown', away, true);
|
||||
};
|
||||
const away = (ev: PointerEvent) => !el.contains(ev.target as Node) && hide();
|
||||
el.tabIndex = 0;
|
||||
el.addEventListener('pointerenter', (ev) => ev.pointerType === 'mouse' && show());
|
||||
el.addEventListener('pointerleave', (ev) => ev.pointerType === 'mouse' && hide());
|
||||
el.addEventListener('pointerup', (ev) => ev.pointerType !== 'mouse' && (shown ? hide() : show()));
|
||||
el.addEventListener('focus', show);
|
||||
el.addEventListener('blur', hide);
|
||||
}
|
||||
|
||||
onNavigate(() => hideGlide());
|
||||
window.addEventListener('scroll', () => owner && hideGlide(), { capture: true, passive: true });
|
||||
@@ -0,0 +1,111 @@
|
||||
// Charts drawn in the connection map's language (map.ts, styles/map.css): an SVG
|
||||
// sized to its box in real pixels (so the arcs' dashes and the markers stay true
|
||||
// at any width), and the map's marks: the person marker (a ringed circle, a halo
|
||||
// while live), the replay's tick for a picked moment, the soft accuracy zone
|
||||
// under a line. Colours and strokes are CSS (styles/charts.css), so a theme
|
||||
// switch needs no redraw. What a chart draws is the subclass's.
|
||||
|
||||
let ids = 0;
|
||||
|
||||
export abstract class Plot {
|
||||
readonly el: HTMLElement;
|
||||
protected svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
||||
/** The box in CSS pixels; 0 until it is laid out. */
|
||||
protected W = 0;
|
||||
protected H = 0;
|
||||
/** Unique within the page, for the gradients a chart defines. */
|
||||
protected id = `dl-plot${++ids}`;
|
||||
|
||||
/**
|
||||
* `width`: a box whose size is known up front (a tooltip's chart, built anew
|
||||
* each time it shows) is drawn at once, without waiting to be laid out.
|
||||
*/
|
||||
constructor(cls: string, height: number, width?: number) {
|
||||
this.el = document.createElement('div');
|
||||
this.el.className = `dl-plot ${cls}`;
|
||||
this.el.style.height = `${height}px`;
|
||||
this.svg.setAttribute('aria-hidden', 'true');
|
||||
this.el.appendChild(this.svg);
|
||||
if (width) {
|
||||
this.el.style.width = `${width}px`;
|
||||
this.W = width;
|
||||
this.H = height;
|
||||
this.svg.setAttribute('viewBox', `0 0 ${width} ${height}`);
|
||||
return;
|
||||
}
|
||||
const ro = new ResizeObserver(() => {
|
||||
// A chart a repaint replaced lets go of its observer.
|
||||
if (!this.el.isConnected && this.W) return ro.disconnect();
|
||||
const r = this.el.getBoundingClientRect();
|
||||
const w = Math.round(r.width),
|
||||
h = Math.round(r.height);
|
||||
if (!w || (w === this.W && h === this.H)) return;
|
||||
this.W = w;
|
||||
this.H = h;
|
||||
this.svg.setAttribute('viewBox', `0 0 ${w} ${h}`);
|
||||
this.draw();
|
||||
});
|
||||
ro.observe(this.el);
|
||||
}
|
||||
|
||||
/** Draw what the chart holds now (nothing before it has a size). */
|
||||
abstract draw(): void;
|
||||
|
||||
protected put(markup: string): void {
|
||||
this.svg.innerHTML = markup;
|
||||
}
|
||||
|
||||
/** Page x of a point at x inside the box, and page y of a y inside it. */
|
||||
protected page(x: number, y: number): [number, number] {
|
||||
const r = this.el.getBoundingClientRect();
|
||||
return [r.left + x, r.top + y];
|
||||
}
|
||||
}
|
||||
|
||||
const f = (n: number) => n.toFixed(1);
|
||||
|
||||
/** A marker: the map's person circle, live blue or the recent grey; `halo`: it breathes. */
|
||||
export const marker = (x: number, y: number, live: boolean, r = 4, halo = false): string =>
|
||||
(halo && live ? `<circle class="halo" cx="${f(x)}" cy="${f(y)}" r="${r}"/>` : '') +
|
||||
`<circle class="mk${live ? ' live' : ''}" cx="${f(x)}" cy="${f(y)}" r="${r}"/>`;
|
||||
|
||||
/** The picked point on a chart: a marker in the text colour with a ring of the card. */
|
||||
export const picked = (x: number, y: number, r = 4.5): string => `<circle class="mk on" cx="${f(x)}" cy="${f(y)}" r="${r}"/>`;
|
||||
|
||||
/** The replay's tick: 2 px in the text colour, a ring of the card around it. */
|
||||
export const tick = (x: number, y0: number, y1: number): string =>
|
||||
`<line class="tick-ring" x1="${f(x)}" x2="${f(x)}" y1="${y0}" y2="${y1}"/><line class="tick" x1="${f(x)}" x2="${f(x)}" y1="${y0}" y2="${y1}"/>`;
|
||||
|
||||
/** A vertical soft zone (the accuracy circle's fill fading to nothing), as a gradient `id` of class `cls`. */
|
||||
export const zone = (id: string, cls: string): string =>
|
||||
`<linearGradient id="${id}" x1="0" x2="0" y1="0" y2="1"><stop class="${cls} z0" offset="0"/><stop class="${cls} z1" offset="1"/></linearGradient>`;
|
||||
|
||||
/** A smooth path through points that never overshoots them (monotone cubic): a quiet stretch stays flat, never dips. */
|
||||
export function smooth(p: [number, number][]): string {
|
||||
const n = p.length;
|
||||
if (n < 2) return n ? `M${f(p[0][0])},${f(p[0][1])}` : '';
|
||||
const d: number[] = [];
|
||||
for (let i = 0; i < n - 1; i++) d.push((p[i + 1][1] - p[i][1]) / Math.max(1e-6, p[i + 1][0] - p[i][0]));
|
||||
const m = [d[0], ...d.slice(1).map((v, i) => (d[i] * v <= 0 ? 0 : (d[i] + v) / 2)), d[n - 2]];
|
||||
// Fritsch–Carlson: tangents scaled down where they would overshoot.
|
||||
for (let i = 0; i < n - 1; i++) {
|
||||
if (d[i] === 0) {
|
||||
m[i] = m[i + 1] = 0;
|
||||
continue;
|
||||
}
|
||||
const a = m[i] / d[i],
|
||||
b = m[i + 1] / d[i],
|
||||
s = a * a + b * b;
|
||||
if (s > 9) {
|
||||
const t = 3 / Math.sqrt(s);
|
||||
m[i] = t * a * d[i];
|
||||
m[i + 1] = t * b * d[i];
|
||||
}
|
||||
}
|
||||
let out = `M${f(p[0][0])},${f(p[0][1])}`;
|
||||
for (let i = 0; i < n - 1; i++) {
|
||||
const h = (p[i + 1][0] - p[i][0]) / 3;
|
||||
out += ` C${f(p[i][0] + h)},${f(p[i][1] + m[i] * h)} ${f(p[i + 1][0] - h)},${f(p[i + 1][1] - m[i + 1] * h)} ${f(p[i + 1][0])},${f(p[i + 1][1])}`;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -9,11 +9,17 @@ import { onNavigate } from './nav';
|
||||
|
||||
let floating: HTMLElement | null = null;
|
||||
let anchor: HTMLElement | null = null;
|
||||
/** What the shown tooltip is drawn from. */
|
||||
let drawn: (() => (Node | string)[]) | null = null;
|
||||
let watch = 0;
|
||||
|
||||
const draw = (content: () => (Node | string)[]) =>
|
||||
floating!.replaceChildren(...content().map((c) => (typeof c === 'string' ? document.createTextNode(c) : c)));
|
||||
|
||||
function hideTip() {
|
||||
if (floating) floating.style.display = 'none';
|
||||
anchor = null;
|
||||
drawn = null;
|
||||
clearInterval(watch);
|
||||
watch = 0;
|
||||
}
|
||||
@@ -21,7 +27,8 @@ function hideTip() {
|
||||
export function attachTip(el: HTMLElement, content: () => (Node | string)[]) {
|
||||
const show = (ev: MouseEvent) => {
|
||||
floating ??= document.body.appendChild(E('div', { class: 'dl-tip dl-tip-float dl-root' }));
|
||||
floating.replaceChildren(...content().map((c) => (typeof c === 'string' ? document.createTextNode(c) : c)));
|
||||
draw(content);
|
||||
drawn = content;
|
||||
floating.style.display = '';
|
||||
floating.style.left = `${ev.clientX}px`;
|
||||
floating.style.top = `${ev.clientY - 10}px`;
|
||||
@@ -43,6 +50,11 @@ export function attachTip(el: HTMLElement, content: () => (Node | string)[]) {
|
||||
});
|
||||
}
|
||||
|
||||
/** Draw the shown tooltip again where it stands (live numbers in it); nothing when none shows. */
|
||||
export function refreshTip() {
|
||||
if (drawn && anchor?.isConnected) draw(drawn);
|
||||
}
|
||||
|
||||
onNavigate(hideTip);
|
||||
window.addEventListener('scroll', () => anchor && hideTip(), { capture: true, passive: true });
|
||||
document.addEventListener(
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
// Days as charts: stacked rounded bars (download at the base, upload on top, in
|
||||
// the colours of the tiles' ↓ and ↑ numbers), and the strip of the device
|
||||
// panel's places (a track with a segment for each day used, today the map's live
|
||||
// blue). The picked day (shared/scrub.ts) stays bright over a soft band while the
|
||||
// others dim, or gets the replay's tick on a strip. Days are [rx, tx] oldest
|
||||
// first, today last.
|
||||
|
||||
import type { Pair } from '../../shared/types';
|
||||
import type { Readable } from '../../shared/scrub';
|
||||
import { Plot, tick } from '../ui/plot';
|
||||
|
||||
const f = (n: number) => n.toFixed(1);
|
||||
|
||||
/** A chart with a column per day: which column a pointer is over, where a column's top stands. */
|
||||
abstract class DayPlot extends Plot implements Readable {
|
||||
protected hov = -1;
|
||||
/** Each day's top (box y) in the last paint, for the tooltip's anchor. */
|
||||
protected tops: number[] = [];
|
||||
|
||||
constructor(
|
||||
cls: string,
|
||||
height: number,
|
||||
protected days: Pair[],
|
||||
) {
|
||||
super(cls, height);
|
||||
}
|
||||
|
||||
mark(i: number): void {
|
||||
this.hov = i;
|
||||
this.draw();
|
||||
}
|
||||
|
||||
protected cx(i: number): number {
|
||||
return ((i + 0.5) * this.W) / this.days.length;
|
||||
}
|
||||
|
||||
/** The day under a pointer: each column's share of the width, the gaps included. */
|
||||
indexAt(clientX: number): number {
|
||||
const i = Math.floor(((clientX - this.el.getBoundingClientRect().left) / Math.max(1, this.W)) * this.days.length);
|
||||
return i >= 0 && i < this.days.length ? i : -1;
|
||||
}
|
||||
|
||||
anchor(i: number): [number, number] {
|
||||
return this.page(this.cx(i), this.tops[i] ?? 0);
|
||||
}
|
||||
|
||||
/** The picked day's soft band, under everything. */
|
||||
protected band(): string {
|
||||
if (this.hov < 0) return '';
|
||||
const w = this.W / this.days.length;
|
||||
return `<rect class="band" x="${f(this.cx(this.hov) - w / 2)}" y="0" width="${f(w)}" height="${this.H}" rx="4"/>`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Days as stacked rounded bars, one a day on one scale: the download at the base
|
||||
* and the upload on top, in the colours of the tile's ↓ and ↑ numbers, so a
|
||||
* bar's height is the day's total and its colours the split. The picked day
|
||||
* stays bright over a soft band while the others dim. `maxW`: the widest a bar
|
||||
* gets (px).
|
||||
*/
|
||||
export class DayStack extends DayPlot {
|
||||
constructor(
|
||||
days: Pair[],
|
||||
height: number,
|
||||
private maxW = 14,
|
||||
) {
|
||||
super('dl-stack-bars', height, days);
|
||||
}
|
||||
|
||||
draw(): void {
|
||||
const { W, H, days } = this;
|
||||
if (!W) return;
|
||||
const max = Math.max(1, ...days.map((d) => d[0] + d[1]));
|
||||
const w = Math.min(this.maxW, Math.max(3, (W / days.length) * 0.62));
|
||||
const r = Math.min(2.5, w / 2);
|
||||
let s = this.band();
|
||||
days.forEach(([rx, tx], i) => {
|
||||
const x = this.cx(i) - w / 2;
|
||||
const cls = i === this.hov ? ' on' : this.hov >= 0 ? ' dim' : '';
|
||||
const down = (tx / max) * H,
|
||||
up = (rx / max) * H;
|
||||
// A gap of 1 px between the parts when both show.
|
||||
const gap = down >= 1 && up >= 1 ? 1 : 0;
|
||||
this.tops[i] = H - down - up - gap;
|
||||
if (!rx && !tx) {
|
||||
s += `<rect class="none" x="${f(x)}" y="${H - 2}" width="${f(w)}" height="2" rx="1"/>`;
|
||||
return;
|
||||
}
|
||||
if (down)
|
||||
s += `<rect class="dn${cls}" x="${f(x)}" y="${f(H - Math.max(2, down))}" width="${f(w)}" height="${f(Math.max(2, down))}" rx="${r}"/>`;
|
||||
if (up) s += `<rect class="up${cls}" x="${f(x)}" y="${f(this.tops[i])}" width="${f(w)}" height="${f(Math.max(2, up))}" rx="${r}"/>`;
|
||||
});
|
||||
this.put(s);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Which days a device was used, as the device panel's places strip: a 6 px track,
|
||||
* a segment on each day used (stronger the more), today live blue; the picked
|
||||
* day gets the replay's tick.
|
||||
*/
|
||||
export class DayStrip extends DayPlot {
|
||||
constructor(days: Pair[], height: number) {
|
||||
super('dl-dstrip', height, days);
|
||||
}
|
||||
|
||||
draw(): void {
|
||||
const { W, H, days } = this;
|
||||
if (!W) return;
|
||||
const n = days.length;
|
||||
const vals = days.map((d) => d[0] + d[1]);
|
||||
const max = Math.max(1, ...vals);
|
||||
const y0 = H / 2 - 3,
|
||||
w = W / n;
|
||||
let s = `<rect class="track" x="0" y="${f(y0)}" width="${W}" height="6" rx="3"/>`;
|
||||
vals.forEach((v, i) => {
|
||||
this.tops[i] = y0 - 4;
|
||||
if (!v) return;
|
||||
const live = i === n - 1;
|
||||
s += `<rect class="seg${live ? ' live' : ''}" x="${f(i * w + 0.5)}" y="${f(y0)}" width="${f(Math.max(2, w - 1))}" height="6" rx="2"${
|
||||
live ? '' : ` opacity="${(0.35 + 0.65 * Math.sqrt(v / max)).toFixed(2)}"`
|
||||
}/>`;
|
||||
});
|
||||
if (this.hov >= 0) s += tick(this.cx(this.hov), y0 - 4, y0 + 10);
|
||||
this.put(s);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
// The speed chart (Speed now, an online person's hover card): download as the
|
||||
// map's live line over its zone, upload as a recent grey dashed line on the same
|
||||
// scale, the newest second a live marker that breathes. Read point by point
|
||||
// (shared/scrub.ts): the picked second gets the replay's tick and a marker on each
|
||||
// line. Waiting, an unreadable meter and a server that is off are the tile's.
|
||||
|
||||
import type { Rate } from '../state/meter';
|
||||
import type { Readable } from '../../shared/scrub';
|
||||
import { Plot, marker, picked, smooth, tick, zone } from '../ui/plot';
|
||||
|
||||
/** Room at the ends for the markers. */
|
||||
const PAD = 5;
|
||||
|
||||
export class SpeedLines extends Plot implements Readable {
|
||||
private pts: Rate[] = [];
|
||||
private xs: number[] = [];
|
||||
private hov = -1;
|
||||
|
||||
/** `small`: the hover card's, with smaller marks, at a known `width`. */
|
||||
constructor(
|
||||
height: number,
|
||||
private small = false,
|
||||
width?: number,
|
||||
) {
|
||||
super('dl-lines', height, width);
|
||||
}
|
||||
|
||||
get points(): Rate[] {
|
||||
return this.pts;
|
||||
}
|
||||
|
||||
/** The points ([ts, rx, tx], oldest first) and where each sits across (0–1, the newest at 1). */
|
||||
set(pts: Rate[], xs: number[]): void {
|
||||
this.pts = pts;
|
||||
this.xs = xs;
|
||||
this.draw();
|
||||
}
|
||||
|
||||
mark(i: number): void {
|
||||
this.hov = i;
|
||||
this.draw();
|
||||
}
|
||||
|
||||
private x(i: number): number {
|
||||
return PAD + this.xs[i] * (this.W - 2 * PAD);
|
||||
}
|
||||
|
||||
indexAt(clientX: number): number {
|
||||
if (this.pts.length < 2 || !this.W) return -1;
|
||||
const f = (clientX - this.el.getBoundingClientRect().left - PAD) / (this.W - 2 * PAD);
|
||||
// Left of the first point (the meter still filling its two minutes) is nothing.
|
||||
if (f < this.xs[0] - 0.02) return -1;
|
||||
let best = 0;
|
||||
this.xs.forEach((x, i) => {
|
||||
if (Math.abs(x - f) < Math.abs(this.xs[best] - f)) best = i;
|
||||
});
|
||||
return best;
|
||||
}
|
||||
|
||||
draw(): void {
|
||||
const { W, H, pts } = this;
|
||||
const n = pts.length;
|
||||
if (!W || n < 2) return this.put('');
|
||||
const max = Math.max(1, ...pts.map((p) => Math.max(p[1], p[2])));
|
||||
const y = (v: number) => H - 3 - (v / max) * (H - 3 - PAD);
|
||||
const dn = pts.map((p, i): [number, number] => [this.x(i), y(p[2])]);
|
||||
const up = pts.map((p, i): [number, number] => [this.x(i), y(p[1])]);
|
||||
const d = smooth(dn);
|
||||
const r = this.small ? 3 : 3.5;
|
||||
let s = `<defs>${zone(`${this.id}z`, 'live')}</defs>`;
|
||||
s += `<path class="area" fill="url(#${this.id}z)" d="${d} L${dn[n - 1][0]},${H} L${dn[0][0]},${H}Z"/>`;
|
||||
s += `<path class="ln past dash thin" d="${smooth(up)}"/><path class="ln live" d="${d}"/>`;
|
||||
const h = this.hov >= 0 && this.hov < n ? this.hov : -1;
|
||||
if (h >= 0) {
|
||||
s += tick(dn[h][0], 1, H - 1) + marker(up[h][0], up[h][1], false, r) + picked(dn[h][0], dn[h][1], r + 0.5);
|
||||
}
|
||||
// The newest second, breathing while nothing is picked.
|
||||
if (h !== n - 1) s += marker(dn[n - 1][0], dn[n - 1][1], true, r, h < 0);
|
||||
this.put(s);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// A usage meter in the connection map's language (the device panel's places
|
||||
// strip): a 6 px track and a rounded fill, live blue, orange when nearly full,
|
||||
// red when full. Past the fill, dashed like an arc, where a week at the recent
|
||||
// pace takes it (shared/pace.ts). The alert level is the replay's tick. Without a
|
||||
// limit, the month split by device: a rounded segment each (c0–c4, the swatch
|
||||
// colours), a gap between. Tooltips are the caller's (ui/glide.ts pointTip).
|
||||
|
||||
type MeterTone = 'live' | 'warn' | 'bad';
|
||||
|
||||
/** The tone for a share used: full at 100%, nearly full from 90%. */
|
||||
const toneOf = (pct: number): MeterTone => (pct >= 100 ? 'bad' : pct >= 90 ? 'warn' : 'live');
|
||||
|
||||
/** `pct` used of the limit; `ahead`: where a week at this pace takes it (both 0–100); `mark`: the alert (0–1). */
|
||||
export function limitMeter(pct: number, ahead = 0, mark?: number): HTMLElement {
|
||||
const el = document.createElement('div');
|
||||
el.className = `dl-smeter ${toneOf(pct)}`;
|
||||
const fill = el.appendChild(document.createElement('i'));
|
||||
fill.style.width = `${pct}%`;
|
||||
if (ahead > pct) {
|
||||
const dash = el.appendChild(document.createElement('b'));
|
||||
dash.style.left = `${pct}%`;
|
||||
dash.style.width = `${ahead - pct}%`;
|
||||
}
|
||||
if (mark != null) {
|
||||
const m = el.appendChild(document.createElement('span'));
|
||||
m.className = 'mark';
|
||||
m.style.left = `${mark * 100}%`;
|
||||
}
|
||||
return el;
|
||||
}
|
||||
|
||||
/** The month split by device, largest first (values in bytes; colours c0–c4 in that order). */
|
||||
export function splitMeter(values: number[]): HTMLElement {
|
||||
const el = document.createElement('div');
|
||||
el.className = 'dl-smeter parts';
|
||||
values.forEach((v, i) => {
|
||||
const seg = el.appendChild(document.createElement('i'));
|
||||
seg.className = `c${Math.min(i, 4)}`;
|
||||
seg.style.flexGrow = String(v);
|
||||
});
|
||||
return el;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
// What a picked point says: a day of traffic in a chart's tooltip (ui/glide.ts:
|
||||
// its name, its total against the average, the down/up split as a strip, the
|
||||
// busiest of the span), and when a second of the live speed was, for the tile's
|
||||
// head. Content only; anchoring and gliding are the tooltip's, sums shared/pace.ts.
|
||||
|
||||
import { E } from '../e';
|
||||
import { addDays, bytes, parseDay } from '../../shared/format';
|
||||
import { fmt, locale, num } from '../../shared/i18n';
|
||||
import { vsAverage } from '../../shared/pace';
|
||||
|
||||
/** "Today", "Yesterday", "Sat 31 Oct", on the router's calendar (`today`). */
|
||||
export function dayName(day: string, today: string): string {
|
||||
if (day === today) return _('Today');
|
||||
if (day === addDays(today, -1)) return _('Yesterday');
|
||||
return parseDay(day).toLocaleDateString(locale(), { weekday: 'short', day: 'numeric', month: 'short' });
|
||||
}
|
||||
|
||||
/** A day against the average of the others: "+62% vs average", "about average"; today is "so far". */
|
||||
function againstAverage(totals: number[], i: number): string {
|
||||
if (i === totals.length - 1) return _('so far');
|
||||
const p = vsAverage(totals, i);
|
||||
if (Math.abs(p) < 5) return _('about average');
|
||||
return p > 0 ? fmt(_('+%s%% vs average'), num(p)) : fmt(_('−%s%% vs average'), num(-p));
|
||||
}
|
||||
|
||||
/** Down and up as one strip: download the live blue, upload the past grey. */
|
||||
function split(tx: number, rx: number): HTMLElement {
|
||||
const dn = E('i', { class: 'dn' }),
|
||||
up = E('i', { class: 'up' });
|
||||
dn.style.flexGrow = String(tx);
|
||||
up.style.flexGrow = String(rx);
|
||||
return E('div', { class: 'dl-glide-split' }, rx || tx ? [dn, up] : []);
|
||||
}
|
||||
|
||||
/** "↓ 8.3 GB ↑ 1.1 GB". */
|
||||
export const downUp = (tx: number, rx: number) => [
|
||||
E('span', { class: 'dl-dn' }, '↓'),
|
||||
` ${bytes(tx)} `,
|
||||
E('span', { class: 'dl-up' }, '↑'),
|
||||
` ${bytes(rx)}`,
|
||||
];
|
||||
|
||||
/** Day i of `days` ([rx, tx], today last): its name and how it compares, its total, the split. */
|
||||
export function dayTip(days: { day: string; rx: number; tx: number }[], i: number, today: string): (Node | string)[] {
|
||||
const totals = days.map((d) => d.rx + d.tx);
|
||||
const d = days[i];
|
||||
return [
|
||||
E('div', { class: 'dl-glide-head' }, [E('b', {}, dayName(d.day, today)), E('span', { class: 'dl-faint' }, againstAverage(totals, i))]),
|
||||
E('div', { class: 'dl-glide-big' }, bytes(totals[i])),
|
||||
split(d.tx, d.rx),
|
||||
E('div', { class: 'dl-muted dl-mono' }, downUp(d.tx, d.rx)),
|
||||
totals[i] > 0 && totals[i] === Math.max(...totals)
|
||||
? E('div', { class: 'dl-glide-note' }, fmt(_('The busiest of the %s days'), num(days.length)))
|
||||
: '',
|
||||
];
|
||||
}
|
||||
|
||||
/** A device's day: its name, what it moved or that it was not used, and on how many days of the span it was. */
|
||||
export function deviceDayTip(days: { day: string; rx: number; tx: number }[], i: number, today: string): (Node | string)[] {
|
||||
const d = days[i],
|
||||
v = d.rx + d.tx;
|
||||
const used = days.filter((x) => x.rx + x.tx > 0).length;
|
||||
return [
|
||||
E('div', { class: 'dl-glide-head' }, [
|
||||
E('b', {}, dayName(d.day, today)),
|
||||
E('span', { class: 'dl-faint' }, v ? bytes(v) : _('Not used')),
|
||||
]),
|
||||
v ? split(d.tx, d.rx) : '',
|
||||
E(
|
||||
'div',
|
||||
{ class: 'dl-glide-note' },
|
||||
fmt(N_(days.length, 'Used on %s of %s day', 'Used on %s of %s days'), num(used), num(days.length)),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/** When a second was against the newest: "now", "12 s ago", "1 min 40 s ago". */
|
||||
export function secondsAgo(s: number): string {
|
||||
if (s < 1) return _('now');
|
||||
return s < 60 ? fmt(_('%s s ago'), num(s)) : fmt(_('%s min %s s ago'), num(Math.floor(s / 60)), num(s % 60));
|
||||
}
|
||||
|
||||
/** A second's time on the clock, with seconds. */
|
||||
export const timeOf = (ts: number) =>
|
||||
new Date(ts * 1000).toLocaleTimeString(locale(), { hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
||||
@@ -1,36 +1,28 @@
|
||||
// Tiny daily sparkline (oldest first, the last bar is today) with per-day tooltips.
|
||||
// A device's last 7 days as small stacked bars (oldest first, the last is
|
||||
// today; download at the base, upload on top), read day by day with the
|
||||
// tooltip above the picked one.
|
||||
|
||||
import { E } from '../e';
|
||||
import { addDays, bytes, isoDay, parseDay } from '../../shared/format';
|
||||
import { attachTip } from '../ui/tooltip';
|
||||
import { locale } from '../../shared/i18n';
|
||||
import type { Pair } from '../../shared/types';
|
||||
import { addDays, bytes, isoDay } from '../../shared/format';
|
||||
import { scrub } from '../../shared/scrub';
|
||||
import { hideGlide, showGlide } from '../ui/glide';
|
||||
import { DayStack } from './days';
|
||||
import { dayName, deviceDayTip } from './readouts';
|
||||
|
||||
/** `today` is the router's day (YYYY-MM-DD), so the labels follow its calendar. */
|
||||
export function spark(values: number[], width = 120, height = 26, today = isoDay(new Date())): HTMLElement {
|
||||
const max = Math.max(1, ...values);
|
||||
const el = E('div', { class: 'dl-spark' });
|
||||
el.style.width = `${width}px`;
|
||||
el.style.height = `${height}px`;
|
||||
values.forEach((v, i) => {
|
||||
const b = E('i');
|
||||
b.style.height = `${Math.max(6, (v / max) * 100)}%`;
|
||||
if (!v) b.classList.add('zero');
|
||||
// The day's column carries the tooltip: it answers above a short bar and between two bars.
|
||||
const col = E('span', {}, [b]);
|
||||
const back = values.length - 1 - i;
|
||||
attachTip(col, () => [
|
||||
E(
|
||||
'div',
|
||||
{ class: 'dl-tip-title' },
|
||||
back === 0
|
||||
? _('Today')
|
||||
: back === 1
|
||||
? _('Yesterday')
|
||||
: parseDay(addDays(today, -back)).toLocaleDateString(locale(), { weekday: 'short', day: 'numeric', month: 'short' }),
|
||||
),
|
||||
E('div', { class: 'dl-muted' }, bytes(v)),
|
||||
]);
|
||||
el.appendChild(col);
|
||||
/** `days` are [rx, tx]; `today` is the router's day (YYYY-MM-DD), so the names follow its calendar. */
|
||||
export function spark(days: Pair[], width = 120, height = 22, today = isoDay(new Date())): HTMLElement {
|
||||
const chart = new DayStack(days, height, 10);
|
||||
chart.el.style.width = `${width}px`;
|
||||
const dated = days.map(([rx, tx], i) => ({ day: addDays(today, i - (days.length - 1)), rx, tx }));
|
||||
scrub(chart.el, chart, {
|
||||
count: () => days.length,
|
||||
pick: (i) => {
|
||||
if (i < 0) return hideGlide(chart.el);
|
||||
const [x, y] = chart.anchor(i);
|
||||
showGlide(chart.el, x, y, deviceDayTip(dated, i, today));
|
||||
},
|
||||
label: _('Last 7 days'),
|
||||
say: (i) => `${dayName(dated[i].day, today)}: ${bytes(dated[i].rx + dated[i].tx)}`,
|
||||
});
|
||||
return el;
|
||||
return chart.el;
|
||||
}
|
||||
+135
-135
@@ -1,33 +1,22 @@
|
||||
// Bento tiles shared by the server Overview and the person page: speed now
|
||||
// (from the minute samples, or live on the Overview) and the last 30 days.
|
||||
// (live, from the meter) and the last 30 days, plus
|
||||
// a device card's 30 days. The charts are in the connection map's language
|
||||
// (widgets/lines.ts, days.ts) and read point by point (shared/scrub.ts): the
|
||||
// speed in the tile's own head, a day in a tooltip above it (ui/glide.ts).
|
||||
|
||||
import type { DayUsage } from '../../shared/types';
|
||||
import type { LiveSpeed, Rate } from '../state/meter';
|
||||
import type { LiveSpeed } from '../state/meter';
|
||||
import { E } from '../e';
|
||||
import { bits, bytes, parseDay } from '../../shared/format';
|
||||
import { fill, fmt, locale } from '../../shared/i18n';
|
||||
import { attachTip } from '../ui/tooltip';
|
||||
import { svg } from '../ui/layout';
|
||||
import { scrub, type Scrub } from '../../shared/scrub';
|
||||
import { hideGlide, showGlide } from '../ui/glide';
|
||||
import { SpeedLines } from './lines';
|
||||
import { DayStack, DayStrip } from './days';
|
||||
import { dayTip, deviceDayTip, downUp, secondsAgo, timeOf } from './readouts';
|
||||
|
||||
const dayLabel = (day: string) => parseDay(day).toLocaleDateString(locale(), { day: 'numeric', month: 'short' });
|
||||
|
||||
/** The speed chart's box (its viewBox; CSS stretches it to the tile). */
|
||||
const W = 200,
|
||||
H = 40;
|
||||
|
||||
/** The speed chart's lines through `pts` at `xs` (0–1 across): download filled, upload over it. */
|
||||
function chartPaths(pts: Rate[], xs: number[]): { area: string; down: string; up: string } {
|
||||
const max = Math.max(1, ...pts.map((p) => Math.max(p[1], p[2])));
|
||||
const line = (k: 1 | 2) => pts.map((p, i) => `${xs[i] * W},${H - 2 - (p[k] / max) * (H - 6)}`);
|
||||
const dl = line(2),
|
||||
ul = line(1);
|
||||
return {
|
||||
area: `M${dl.join(' L')} L${xs[xs.length - 1] * W},${H} L${xs[0] * W},${H}Z`,
|
||||
down: `M${dl.join(' L')}`,
|
||||
up: `M${ul.join(' L')}`,
|
||||
};
|
||||
}
|
||||
|
||||
/** One of the two speeds: its arrow and label, then the value. */
|
||||
const speedCol = (label: string, ic: string, cls: string, val: HTMLElement) =>
|
||||
E('div', { class: 'dl-speed-col' }, [E('span', { class: 'dl-sub' }, [E('span', { class: cls }, ic), ` ${label}`]), val]);
|
||||
@@ -35,76 +24,84 @@ const speedCol = (label: string, ic: string, cls: string, val: HTMLElement) =>
|
||||
/** Today's traffic under the chart (`today` is [rx, tx]). */
|
||||
const todayParts = ([rx, tx]: [number, number]) => [
|
||||
E('span', {}, fill(_('Today %s'), E('b', {}, bytes(rx + tx)))),
|
||||
E('span', {}, [E('span', { class: 'dl-dn' }, '↓'), ` ${bytes(tx)} `, E('span', { class: 'dl-up' }, '↑'), ` ${bytes(rx)}`]),
|
||||
E('span', {}, downUp(tx, rx)),
|
||||
];
|
||||
|
||||
/**
|
||||
* Throughput over the last 15 minutes plus today's total. `off`: the server is
|
||||
* turned off, so there is no speed to show (dashes, not zeros) and no chart.
|
||||
* A speed tile's head, numbers and chart, read in place: the picked point's
|
||||
* speeds take the numbers' place and the span says when it was ("14:32:07 · 12 s
|
||||
* ago"); letting go puts the newest back. Shared by both speed tiles.
|
||||
*/
|
||||
export function speedTile(rate: Rate[], now: number, today: [number, number], off = false): HTMLElement {
|
||||
const pts = rate.slice(-15);
|
||||
const last = pts[pts.length - 1];
|
||||
const fresh = last && now - last[0] < 180;
|
||||
const down = fresh ? last[2] : 0,
|
||||
up = fresh ? last[1] : 0;
|
||||
let chart: HTMLElement;
|
||||
if (pts.length > 1 && !off) {
|
||||
const d = chartPaths(
|
||||
pts,
|
||||
pts.map((_x, i) => i / (pts.length - 1)),
|
||||
);
|
||||
chart = svg(
|
||||
`<svg viewBox="0 0 ${W} ${H}" preserveAspectRatio="none" class="dl-speed-chart" aria-hidden="true">` +
|
||||
`<path d="${d.area}" class="area"/><path d="${d.down}" class="line"/><path d="${d.up}" class="line up"/></svg>`,
|
||||
);
|
||||
attachTip(chart, () => {
|
||||
const p = pts[pts.length - 1];
|
||||
return [
|
||||
E('div', { class: 'dl-tip-title' }, new Date(p[0] * 1000).toLocaleTimeString(locale(), { hour: '2-digit', minute: '2-digit' })),
|
||||
E('div', {}, `↓ ${bits(p[2])} · ↑ ${bits(p[1])}`),
|
||||
];
|
||||
});
|
||||
} else chart = E('div', { class: 'dl-speed-wait' }, [E('i'), off ? '' : E('span', {}, _('Collecting… 1 point a minute'))]);
|
||||
const val = (v: number) => (off ? E('span', { class: 'dl-speed-val off' }, '—') : E('span', { class: 'dl-speed-val' }, bits(v)));
|
||||
return E('div', { class: 'dl-bento-tile' }, [
|
||||
E('div', { class: 'dl-bento-head' }, [
|
||||
E('span', { class: 'dl-metric-label' }, _('Speed now')),
|
||||
off ? '' : E('span', { class: 'dl-sub' }, _('last 15 min')),
|
||||
]),
|
||||
E('div', { class: 'dl-speed-cols' }, [
|
||||
speedCol(_('Download', 'speed'), '↓', 'dl-dn', val(down)),
|
||||
speedCol(_('Upload', 'speed'), '↑', 'dl-up', val(up)),
|
||||
]),
|
||||
chart,
|
||||
E('div', { class: 'dl-speed-today' }, todayParts(today)),
|
||||
class SpeedHead {
|
||||
readonly span: HTMLElement;
|
||||
private down = E('span', { class: 'dl-speed-val' });
|
||||
private up = E('span', { class: 'dl-speed-val' });
|
||||
readonly cols = E('div', { class: 'dl-speed-cols' }, [
|
||||
speedCol(_('Download', 'speed'), '↓', 'dl-dn', this.down),
|
||||
speedCol(_('Upload', 'speed'), '↑', 'dl-up', this.up),
|
||||
]);
|
||||
readonly chart: SpeedLines;
|
||||
readonly read: Scrub;
|
||||
/** What the numbers say when nothing is picked: [rx, tx], or null for dashes. */
|
||||
private now: [number, number] | null = null;
|
||||
|
||||
constructor(
|
||||
private spanText: string,
|
||||
label: string,
|
||||
) {
|
||||
this.span = E('span', { class: 'dl-sub' }, spanText);
|
||||
this.chart = new SpeedLines(44);
|
||||
this.read = scrub(this.chart.el, this.chart, {
|
||||
count: () => this.chart.points.length,
|
||||
pick: () => this.paint(),
|
||||
label,
|
||||
say: (i) => {
|
||||
const p = this.chart.points[i];
|
||||
return `${timeOf(p[0])}: ↓ ${bits(p[2])}, ↑ ${bits(p[1])}`;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/** The numbers when nothing is picked (null: dashes, the server is off or the meter unreadable). */
|
||||
set(now: [number, number] | null): void {
|
||||
this.now = now;
|
||||
this.paint();
|
||||
}
|
||||
|
||||
private paint(): void {
|
||||
const pts = this.chart.points;
|
||||
const i = this.read.current();
|
||||
const p = i >= 0 ? pts[i] : null;
|
||||
const newest = pts.length ? pts[pts.length - 1][0] : 0;
|
||||
this.span.textContent = p ? `${timeOf(p[0])} · ${secondsAgo(newest - p[0])}` : this.spanText;
|
||||
this.span.classList.toggle('dl-picked', !!p);
|
||||
this.cols.classList.toggle('dl-picked', !!p);
|
||||
const v = p ? ([p[1], p[2]] as [number, number]) : this.now;
|
||||
for (const [el, x] of [
|
||||
[this.down, v?.[1]],
|
||||
[this.up, v?.[0]],
|
||||
] as const) {
|
||||
el.className = `dl-speed-val${v ? '' : ' off'}`;
|
||||
el.textContent = v ? bits(x!) : '—';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Speed now, live (the server Overview): speedTile's tile, its chart the last
|
||||
* Speed now, live (the server Overview, a person's page): its chart the last
|
||||
* 2 minutes one point a second (state/meter.ts). Built once; update() puts each
|
||||
* second's numbers and lines in place. No tooltip: the numbers above the chart
|
||||
* are its newest point already.
|
||||
* second's numbers and line in place. A second picked on the chart stays under a
|
||||
* still pointer as the line moves on, so its "ago" keeps counting.
|
||||
*/
|
||||
export class LiveSpeedTile {
|
||||
private span = E('span', { class: 'dl-sub' }, _('last 2 min'));
|
||||
private down = E('span', { class: 'dl-speed-val' });
|
||||
private up = E('span', { class: 'dl-speed-val' });
|
||||
private chart = svg(
|
||||
`<svg viewBox="0 0 ${W} ${H}" preserveAspectRatio="none" class="dl-speed-chart" aria-hidden="true">` +
|
||||
`<path class="area"/><path class="line"/><path class="line up"/></svg>`,
|
||||
);
|
||||
private head = new SpeedHead(_('last 2 min'), _('Speed over the last 2 minutes'));
|
||||
private wait = E('div', { class: 'dl-speed-wait' });
|
||||
/** The chart or the waiting line, whichever is in the tile. */
|
||||
private shown = this.wait;
|
||||
private today = E('div', { class: 'dl-speed-today' });
|
||||
readonly el = E('div', { class: 'dl-bento-tile' }, [
|
||||
E('div', { class: 'dl-bento-head' }, [E('span', { class: 'dl-metric-label' }, _('Speed now')), this.span]),
|
||||
E('div', { class: 'dl-speed-cols' }, [
|
||||
speedCol(_('Download', 'speed'), '↓', 'dl-dn', this.down),
|
||||
speedCol(_('Upload', 'speed'), '↑', 'dl-up', this.up),
|
||||
]),
|
||||
E('div', { class: 'dl-bento-head' }, [E('span', { class: 'dl-metric-label' }, _('Speed now')), this.head.span]),
|
||||
this.head.cols,
|
||||
this.wait,
|
||||
this.today,
|
||||
]);
|
||||
@@ -112,70 +109,82 @@ export class LiveSpeedTile {
|
||||
/**
|
||||
* This second's speed and today's traffic ([rx, tx]). `off`: the server is
|
||||
* turned off (dashes, no chart); a meter that cannot be read says why in
|
||||
* the chart's place, with dashes for the speeds.
|
||||
* the chart's place, with dashes for the speeds. While collecting, a shimmer
|
||||
* runs along the dashed track.
|
||||
*/
|
||||
update(s: LiveSpeed, today: [number, number], off: boolean): void {
|
||||
const none = off || !!s.error;
|
||||
this.span.style.display = off ? 'none' : '';
|
||||
for (const [el, v] of [
|
||||
[this.down, s.tx],
|
||||
[this.up, s.rx],
|
||||
] as const) {
|
||||
el.className = `dl-speed-val${none ? ' off' : ''}`;
|
||||
el.textContent = none ? '—' : bits(v);
|
||||
}
|
||||
this.head.span.style.display = off ? 'none' : '';
|
||||
const lines = !none && s.pts.length > 1;
|
||||
if (lines) {
|
||||
const p = chartPaths(s.pts, s.xs);
|
||||
const [area, down, up] = this.chart.querySelectorAll('path');
|
||||
area.setAttribute('d', p.area);
|
||||
down.setAttribute('d', p.down);
|
||||
up.setAttribute('d', p.up);
|
||||
} else
|
||||
dom.content(this.wait, [
|
||||
E('i'),
|
||||
if (lines) this.head.chart.set(s.pts, s.xs);
|
||||
else {
|
||||
const words =
|
||||
off || (s.early && !s.error)
|
||||
? ''
|
||||
: E('span', {}, s.error ? fmt(_("Couldn't read the live speed: %s"), s.error) : _('Collecting… 1 point a second')),
|
||||
]);
|
||||
const want = lines ? this.chart : this.wait;
|
||||
: s.error
|
||||
? fmt(_("Couldn't read the live speed: %s"), s.error)
|
||||
: _('Collecting… 1 point a second');
|
||||
dom.content(this.wait, [E('i', { class: !none && !s.early ? 'run' : '' }), words ? E('span', {}, words) : '']);
|
||||
}
|
||||
const want = lines ? this.head.chart.el : this.wait;
|
||||
if (want !== this.shown) {
|
||||
this.shown.replaceWith(want);
|
||||
this.shown = want;
|
||||
}
|
||||
this.head.set(none ? null : [s.rx, s.tx]);
|
||||
if (lines) this.head.read.refresh();
|
||||
dom.content(this.today, todayParts(today));
|
||||
}
|
||||
}
|
||||
|
||||
/** Daily traffic for the last 30 days, today on the right. */
|
||||
/**
|
||||
* A chart of days read with the tooltip above the picked day: the pointer, a tap
|
||||
* or the arrow keys pick one; the tooltip glides from day to day.
|
||||
*/
|
||||
function readDays(chart: DayStack | DayStrip, days: DayUsage[], label: string, tip: (i: number) => (Node | string)[]): void {
|
||||
scrub(chart.el, chart, {
|
||||
count: () => days.length,
|
||||
pick: (i) => {
|
||||
if (i < 0) return hideGlide(chart.el);
|
||||
const [x, y] = chart.anchor(i);
|
||||
showGlide(chart.el, x, y, tip(i));
|
||||
},
|
||||
label,
|
||||
say: (i) => `${dayLabel(days[i].day)}: ${bytes(days[i].rx + days[i].tx)}`,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Daily traffic for the last 30 days, today on the right: a stacked bar a day,
|
||||
* download at the base and upload on top; the head's legend is the 30 days'
|
||||
* down and up in the same colours.
|
||||
*/
|
||||
export function daysTile(series: DayUsage[], note: string): HTMLElement {
|
||||
const days = series.slice(-30);
|
||||
const vals = days.map((d) => d.rx + d.tx);
|
||||
const max = Math.max(1, ...vals);
|
||||
const total = vals.reduce((a, v) => a + v, 0);
|
||||
const peakI = vals.reduce((a, v, i) => (v > vals[a] ? i : a), 0);
|
||||
const bars = E(
|
||||
'div',
|
||||
{ class: 'dl-bento-bars' },
|
||||
days.map((d, i) => {
|
||||
const v = vals[i];
|
||||
const bar = E('i', { class: i === days.length - 1 ? 'hi' : '', style: `height:${Math.max(4, (v / max) * 100)}%` });
|
||||
// The day's column carries the tooltip: it answers above a short bar and between two bars.
|
||||
const col = E('span', {}, [bar]);
|
||||
attachTip(col, () => [
|
||||
E('div', { class: 'dl-tip-title' }, i === days.length - 1 ? `${_('Today')} · ${dayLabel(d.day)}` : dayLabel(d.day)),
|
||||
E('div', {}, bytes(v)),
|
||||
E('div', { class: 'dl-muted dl-mono' }, `↓ ${bytes(d.tx)} ↑ ${bytes(d.rx)}`),
|
||||
]);
|
||||
return col;
|
||||
}),
|
||||
);
|
||||
const total = days.reduce((a, d) => a + d.rx + d.tx, 0);
|
||||
const down = days.reduce((a, d) => a + d.tx, 0),
|
||||
up = days.reduce((a, d) => a + d.rx, 0);
|
||||
const today = days.length ? days[days.length - 1].day : '';
|
||||
let chart: HTMLElement;
|
||||
if (days.length) {
|
||||
const bars = new DayStack(
|
||||
days.map((d) => [d.rx, d.tx]),
|
||||
64,
|
||||
);
|
||||
readDays(bars, days, _('Traffic, last 30 days'), (i) => dayTip(days, i, today));
|
||||
chart = bars.el;
|
||||
} else chart = E('p', { class: 'dl-muted' }, _('No traffic yet.'));
|
||||
return E('div', { class: 'dl-bento-tile month' }, [
|
||||
E('div', { class: 'dl-bento-head' }, [
|
||||
E('span', {}, [E('span', { class: 'dl-metric-label' }, _('Last 30 days')), E('b', { class: 'dl-bento-total' }, bytes(total))]),
|
||||
vals[peakI] > 0 ? E('span', { class: 'dl-sub' }, `${fmt(_('peak %s'), bytes(vals[peakI]))} · ${dayLabel(days[peakI].day)}`) : '',
|
||||
total > 0
|
||||
? E('span', { class: 'dl-sub dl-days-key' }, [
|
||||
E('span', {}, [E('i', { class: 'dn' }), `↓ ${bytes(down)}`]),
|
||||
E('span', {}, [E('i', { class: 'up' }), `↑ ${bytes(up)}`]),
|
||||
])
|
||||
: '',
|
||||
]),
|
||||
days.length ? bars : E('p', { class: 'dl-muted' }, _('No traffic yet.')),
|
||||
chart,
|
||||
E('div', { class: 'dl-bento-head' }, [
|
||||
E('span', { class: 'dl-sub' }, days.length ? dayLabel(days[0].day) : ''),
|
||||
E('span', { class: 'dl-sub' }, note),
|
||||
@@ -184,23 +193,14 @@ export function daysTile(series: DayUsage[], note: string): HTMLElement {
|
||||
]);
|
||||
}
|
||||
|
||||
/** Daily traffic of one device over the last 30 days, today on the right (person page device cards). */
|
||||
/** Which of the last 30 days one device was used, today on the right (person page device cards). */
|
||||
export function dayBars(series: DayUsage[]): HTMLElement {
|
||||
const days = series.slice(-30);
|
||||
const vals = days.map((x) => x.rx + x.tx);
|
||||
const max = Math.max(1, ...vals);
|
||||
return E(
|
||||
'div',
|
||||
{ class: 'dl-dbars' },
|
||||
days.map((x, i) => {
|
||||
const bar = E('i', { class: `${vals[i] ? '' : 'zero'}${i === days.length - 1 ? ' hi' : ''}` });
|
||||
bar.style.height = `${Math.max(8, (vals[i] / max) * 100)}%`;
|
||||
const col = E('span', {}, [bar]);
|
||||
attachTip(col, () => [
|
||||
E('div', { class: 'dl-tip-title' }, i === days.length - 1 ? `${_('Today')} · ${dayLabel(x.day)}` : dayLabel(x.day)),
|
||||
E('div', {}, bytes(vals[i])),
|
||||
]);
|
||||
return col;
|
||||
}),
|
||||
const strip = new DayStrip(
|
||||
days.map((d) => [d.rx, d.tx]),
|
||||
18,
|
||||
);
|
||||
const today = days.length ? days[days.length - 1].day : '';
|
||||
readDays(strip, days, _('Days this device was used'), (i) => deviceDayTip(days, i, today));
|
||||
return strip.el;
|
||||
}
|
||||
@@ -62,6 +62,8 @@ export interface DemoDevice {
|
||||
created: number;
|
||||
by: 'admin' | 'portal';
|
||||
stale: boolean;
|
||||
/** LAN Bypass (unset: off). */
|
||||
bypass?: boolean;
|
||||
/** A set-up state the visitor picked in the sheet (way-pick.ts), held until they pick another; none: as it comes. */
|
||||
way?: DemoWay;
|
||||
/** When it was picked: the knocks' or the handshake's time. */
|
||||
@@ -168,7 +170,7 @@ function device(d: DemoDevice, t: number, st: Person['state']): Device {
|
||||
hostname: `${label(d.name)}.user.lan`,
|
||||
browser_key: false,
|
||||
config_stale: d.stale,
|
||||
lan_bypass: false,
|
||||
lan_bypass: !!d.bypass,
|
||||
mtu: 0,
|
||||
keepalive: null,
|
||||
// The server's for its kind, as the router works it out (the portal never shows it).
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// The demo's router: portal.uc's API (state, add a device, its settings,
|
||||
// rename / reconnect / remove) answered from the demo's own devices, which it
|
||||
// rename / reconnect / LAN Bypass / remove) answered from the demo's own devices, which it
|
||||
// keeps per visitor. The refusals are the router's (paused, ended, plain HTTP,
|
||||
// no free slot, a name taken). Nothing is installed and no tunnel exists: the
|
||||
// keys are random and the server's address never resolves. The page state
|
||||
@@ -158,6 +158,7 @@ export function createRouter(o: RouterOpts) {
|
||||
created: clock(),
|
||||
by: 'portal',
|
||||
stale: false,
|
||||
bypass: b.lan_bypass === true,
|
||||
};
|
||||
db.devs.push(d);
|
||||
issued = d.id;
|
||||
@@ -182,12 +183,24 @@ export function createRouter(o: RouterOpts) {
|
||||
if (b.action === 'rename') d.name = checkName(b.name, d);
|
||||
else if (b.action === 'reconnect') {
|
||||
needHttps();
|
||||
// What it is and LAN Bypass change with the keys, as on the router.
|
||||
if (typeof b.kind === 'string') {
|
||||
if (!KINDS.includes(b.kind as Kind)) refuse(400, 'Unknown device type.');
|
||||
d.kind = b.kind as Kind;
|
||||
}
|
||||
if (typeof b.lan_bypass === 'boolean') d.bypass = b.lan_bypass;
|
||||
// New keys: the old handshake no longer counts, the device connects again once set up.
|
||||
d.hs = 0;
|
||||
d.stale = false;
|
||||
d.connectAt = soon();
|
||||
issued = d.id;
|
||||
extra = { config: config(d) };
|
||||
} else if (b.action === 'bypass') {
|
||||
needHttps();
|
||||
if (typeof b.on !== 'boolean') refuse(400, 'Unknown action.');
|
||||
// The keys stay; the configuration it holds is out of date until it takes the updated one.
|
||||
d.bypass = b.on as boolean;
|
||||
d.stale = true;
|
||||
} else if (b.action === 'delete') db.devs = db.devs.filter((x) => x !== d);
|
||||
else refuse(400, 'Unknown action.');
|
||||
return { ok: true, ...extra, state: state() };
|
||||
|
||||
+12
-103
@@ -1,40 +1,29 @@
|
||||
// Adding a device: what it is (four kinds; phones and tablets are one choice,
|
||||
// the same apps and the same smaller packets), whether the local network it is
|
||||
// on stays reachable while connected (LAN Bypass, off unless they turn it on;
|
||||
// it stays as chosen: the admin's drawer shows it, neither page changes it)
|
||||
// and its name, guessed from the browser when it is this device; then straight
|
||||
// on to its set-up. Or the page opens on the device itself, from a code, ready
|
||||
// to add it there.
|
||||
// on stays reachable while connected (LAN Bypass, on unless they turn it off;
|
||||
// Reconnect and the card's ⋯ menu change it later: device-actions.ts) and its
|
||||
// name, guessed from the browser when it is this device; then straight on to
|
||||
// its set-up. Or the page opens on the device itself, from a code, ready to add
|
||||
// it there. The kinds and the switch are device-form.ts.
|
||||
|
||||
import type { ClientConfig, Kind } from '../../shared/types';
|
||||
import { defaultName, fitName, netsLabel, pickLabel, pickOf, PICKS, type KindPick } from '../../shared/format';
|
||||
import { defaultName, fitName, pickOf, PICKS, type KindPick } from '../../shared/format';
|
||||
import { guardDeviceName } from '../../shared/name-guard';
|
||||
import { shake } from '../../shared/shake';
|
||||
import { fmt, num, plural } from '../../shared/i18n';
|
||||
import { ApiError, call } from '../api';
|
||||
import { h, ic } from '../dom';
|
||||
import { SMOOTH, play } from '../motion';
|
||||
import { addLink } from '../setup';
|
||||
import { pageUrl, repaint, setState, state, type State } from '../state';
|
||||
import { smoothCaret } from '../ui/caret';
|
||||
import { linkRow, qrBox } from '../ui/codes';
|
||||
import { once, toast } from '../ui/feedback';
|
||||
import { badLine } from '../ui/bad-line';
|
||||
import { glass } from '../ui/glass';
|
||||
import { go, head, openSheet, sub, type View } from '../ui/sheet';
|
||||
import { secureFirst, showSecure } from './secure';
|
||||
import { IPAD, UA, guessKind, kindOf, kindTiles, lanSwitch } from './device-form';
|
||||
import { continueSetup } from './setup-view';
|
||||
|
||||
// Best guess at the device this page is open on (the browser never tells its real name).
|
||||
const UA = navigator.userAgent;
|
||||
const IPAD = /iPad/.test(UA) || (/Macintosh/.test(UA) && navigator.maxTouchPoints > 1);
|
||||
|
||||
function guessKind(): Kind {
|
||||
if (IPAD || /Tablet/i.test(UA) || (/Android/.test(UA) && !/Mobile/.test(UA))) return 'tablet';
|
||||
if (/Android|iPhone|Mobile/i.test(UA)) return 'phone';
|
||||
return 'computer';
|
||||
}
|
||||
|
||||
/** Samsung model codes → names people know (S and A series; the code stays in brackets). */
|
||||
const GALAXY: [RegExp, string][] = [
|
||||
[/^SM-S93/, 'Galaxy S25'],
|
||||
@@ -77,9 +66,6 @@ function guessName(kind: Kind): string {
|
||||
return defaultName(kind);
|
||||
}
|
||||
|
||||
// Mobile is a tablet when this page is open on one (see KindPick).
|
||||
const kindOf = (p: KindPick): Kind => (p !== 'mobile' ? p : guessKind() === 'tablet' ? 'tablet' : 'phone');
|
||||
|
||||
/**
|
||||
* What they chose so far, kept outside the view: Back from "Open on the device"
|
||||
* builds the view again, and it comes back as they left it. `name`: what they
|
||||
@@ -91,33 +77,6 @@ interface Draft {
|
||||
name?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* A line in a block opens or folds away: height, opacity and blur on SMOOTH, as the set-up steps fold, from
|
||||
* where it is on screen (flicking the switch never snaps). The block's 1 px gap goes with it.
|
||||
*/
|
||||
function foldLine(el: HTMLElement, open: boolean) {
|
||||
const cs = getComputedStyle(el);
|
||||
const from = el.hidden
|
||||
? { h: 0, o: 0, b: 4, m: -1 }
|
||||
: {
|
||||
h: el.getBoundingClientRect().height,
|
||||
o: +cs.opacity,
|
||||
b: +(cs.filter.match(/blur\(([\d.]+)px\)/)?.[1] ?? 0),
|
||||
m: parseFloat(cs.marginTop) || 0,
|
||||
};
|
||||
el.getAnimations().forEach((a) => a.cancel());
|
||||
el.hidden = false;
|
||||
el.style.overflow = 'hidden';
|
||||
const to = open ? { h: el.scrollHeight, o: 1, b: 0, m: 0 } : { h: 0, o: 0, b: 4, m: -1 };
|
||||
const frame = (v: typeof from) => ({ height: `${v.h}px`, opacity: v.o, filter: v.b ? `blur(${v.b}px)` : 'none', marginTop: `${v.m}px` });
|
||||
const a = play(el, [frame(from), frame(to)], { duration: SMOOTH.duration, easing: SMOOTH.easing, fill: 'forwards' });
|
||||
a.onfinish = () => {
|
||||
el.hidden = !open;
|
||||
el.style.overflow = '';
|
||||
a.cancel();
|
||||
};
|
||||
}
|
||||
|
||||
export function startAdd() {
|
||||
const st = state();
|
||||
if (!st || st.locked) return;
|
||||
@@ -127,7 +86,7 @@ export function startAdd() {
|
||||
true,
|
||||
);
|
||||
if (secureFirst()) return;
|
||||
const draft: Draft = { bypass: false };
|
||||
const draft: Draft = { bypass: true };
|
||||
openSheet(() => vAdd(draft));
|
||||
}
|
||||
|
||||
@@ -147,53 +106,8 @@ function vAdd(draft: Draft): View {
|
||||
return fitName(n);
|
||||
};
|
||||
|
||||
const kinds = h('div', { class: 'kinds', role: 'radiogroup', 'aria-label': _('What is it?') });
|
||||
kinds.style.setProperty('--n', String(picks.length));
|
||||
const tiles = picks.map((k) => {
|
||||
const t = h(
|
||||
'button',
|
||||
{ type: 'button', class: 'kind', role: 'radio', 'aria-label': pickLabel(k), onclick: () => choose(k) },
|
||||
h('span', { class: 'kind-tile' }, glass(k, 'blue')),
|
||||
h('span', { class: 'kind-lbl' }, pickLabel(k)),
|
||||
);
|
||||
kinds.appendChild(t);
|
||||
return t;
|
||||
});
|
||||
// With home access, the home networks still go into the tunnel: a local network on the same addresses is out
|
||||
// of reach, and the row says so while LAN Bypass is on.
|
||||
const home = st.server.home ?? [];
|
||||
const except = home.length
|
||||
? h(
|
||||
'span',
|
||||
{ class: 'sw-sub sw-note', hidden: !draft.bypass },
|
||||
fmt(_('Except %s: those addresses lead to the home network.'), netsLabel(home)),
|
||||
)
|
||||
: null;
|
||||
// The whole row is the switch. Built as they left it, before it is on the page: nothing slides.
|
||||
const lan = h(
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
class: draft.bypass ? 'swrow on' : 'swrow',
|
||||
role: 'switch',
|
||||
'aria-checked': String(draft.bypass),
|
||||
onclick: () => {
|
||||
draft.bypass = !draft.bypass;
|
||||
lan.classList.toggle('on', draft.bypass);
|
||||
lan.setAttribute('aria-checked', String(draft.bypass));
|
||||
if (except) foldLine(except, draft.bypass);
|
||||
},
|
||||
},
|
||||
glass('lan', 'blue'),
|
||||
h(
|
||||
'span',
|
||||
{ class: 'sw-t' },
|
||||
h('b', {}, _('LAN Bypass')),
|
||||
h('span', { class: 'sw-sub' }, _('Your local network stays reachable while connected.')),
|
||||
except,
|
||||
),
|
||||
h('span', { class: 'sw', 'aria-hidden': 'true' }),
|
||||
);
|
||||
const kinds = kindTiles(picks, (k) => choose(k));
|
||||
const lan = lanSwitch(draft.bypass, st.server.home ?? [], (on) => (draft.bypass = on));
|
||||
const input = h('input', {
|
||||
type: 'text',
|
||||
// Not `required`: the browser's own check would stop an empty submit before the field can shake.
|
||||
@@ -222,14 +136,9 @@ function vAdd(draft: Draft): View {
|
||||
void modelReady.then(() => {
|
||||
if (draft.name === undefined && pick === pickOf(guessKind())) input.value = suggest(pick);
|
||||
});
|
||||
// The picked tile rings itself where it stands (the ring does not travel between tiles).
|
||||
function choose(k: KindPick) {
|
||||
pick = draft.pick = k;
|
||||
tiles.forEach((t, i) => {
|
||||
const on = picks[i] === k;
|
||||
t.classList.toggle('on', on);
|
||||
t.setAttribute('aria-checked', String(on));
|
||||
});
|
||||
kinds.set(k);
|
||||
if (draft.name === undefined) {
|
||||
input.value = suggest(k);
|
||||
goBtn.classList.add('ready');
|
||||
@@ -278,7 +187,7 @@ function vAdd(draft: Draft): View {
|
||||
{ class: 'view' },
|
||||
head(_('Add a device')),
|
||||
sub(fmt(N_(p.device_limit, '%s of %s slot free', '%s of %s slots free'), num(free), num(p.device_limit))),
|
||||
kinds,
|
||||
kinds.el,
|
||||
lan,
|
||||
form,
|
||||
err,
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
// A device's own actions from its ⋯ menu: Reconnect (new keys, then the set-up
|
||||
// of the new ones) and Remove (Rename edits the name on the card: rename.ts). A
|
||||
// question comes before what cannot be undone; the action's button stays busy
|
||||
// until the router answers.
|
||||
// A device's own actions from its ⋯ menu: Reconnect (new keys, what it is and
|
||||
// LAN Bypass asked again, then the set-up of the new ones), LAN Bypass on or
|
||||
// off (the same keys, then the set-up of the updated configuration) and Remove
|
||||
// (Rename edits the name on the card: rename.ts). A question comes before what
|
||||
// cannot be undone; the action's button stays busy until the router answers.
|
||||
|
||||
import type { ClientConfig, Device } from '../../shared/types';
|
||||
import { pickOf, PICKS, type KindPick } from '../../shared/format';
|
||||
import { fmt } from '../../shared/i18n';
|
||||
import { call } from '../api';
|
||||
import { h } from '../dom';
|
||||
import { h, ic } from '../dom';
|
||||
import { EASE_IN, play } from '../motion';
|
||||
import { repaint, setState, state, type State } from '../state';
|
||||
import { once, toast } from '../ui/feedback';
|
||||
import { glass, type Tone } from '../ui/glass';
|
||||
import { closeSheet, onClosed, openSheet, type View } from '../ui/sheet';
|
||||
import { closeSheet, head, onClosed, openSheet, sub, type View } from '../ui/sheet';
|
||||
import { kindOf, kindTiles, lanSwitch } from './device-form';
|
||||
import { secureFirst } from './secure';
|
||||
import { continueSetup } from './setup-view';
|
||||
import { continueSetup, openSetup } from './setup-view';
|
||||
|
||||
/** A question before something that cannot be undone: the action's icon in its colour, what happens (on the left edge), Cancel and the action. */
|
||||
function ask(o: { icon: string; tone: Tone; title: string; text: string; action: string; cls: string; run: () => Promise<void> }): View {
|
||||
@@ -41,35 +44,82 @@ function ask(o: { icon: string; tone: Tone; title: string; text: string; action:
|
||||
/**
|
||||
* Set a device up from scratch (a new phone, the app reinstalled, settings the
|
||||
* admin changed): new keys, so what it holds stops working; it shows "Not set
|
||||
* up yet" until it connects with the new configuration, which the sheet goes on to.
|
||||
* up yet" until it connects with the new configuration, which the sheet goes on
|
||||
* to. The sheet asks again what it is and about LAN Bypass, as Add a device does
|
||||
* (device-form.ts), as they stand now; the name stays.
|
||||
*/
|
||||
export function reconnect(d: Device) {
|
||||
if (secureFirst()) return;
|
||||
const here = state()?.here === d.id;
|
||||
openSheet(() =>
|
||||
ask({
|
||||
icon: 'refresh',
|
||||
tone: 'orange',
|
||||
title: fmt(_('Reconnect %s?'), d.name),
|
||||
text: here
|
||||
openSheet(() => vReconnect(d));
|
||||
}
|
||||
|
||||
function vReconnect(d: Device): View {
|
||||
const st = state()!;
|
||||
const here = st.here === d.id;
|
||||
// The kinds this router takes, as the four choices; what it is now ringed.
|
||||
const picks = PICKS.filter((k) => st.kinds.some((x) => pickOf(x) === k));
|
||||
let pick: KindPick = picks.includes(pickOf(d.kind)) ? pickOf(d.kind) : picks[0];
|
||||
let bypass = d.lan_bypass;
|
||||
const kinds = kindTiles(picks, (k) => (pick = k));
|
||||
kinds.set(pick);
|
||||
const lan = lanSwitch(bypass, st.server.home ?? [], (on) => (bypass = on));
|
||||
const run = async () => {
|
||||
try {
|
||||
const r = await call<{ config: ClientConfig; state: State }>(`devices/${d.id}`, {
|
||||
action: 'reconnect',
|
||||
kind: kindOf(pick, d.kind),
|
||||
lan_bypass: bypass,
|
||||
});
|
||||
setState(r.state);
|
||||
repaint();
|
||||
await continueSetup(r.state.person.devices.find((x) => x.id === d.id) ?? { ...d, handshake: 0 }, r.config);
|
||||
} catch (er) {
|
||||
toast((er as Error).message, true);
|
||||
}
|
||||
};
|
||||
const go = h(
|
||||
'button',
|
||||
{ type: 'button', class: 'btn warn block', onclick: (ev: Event) => once(ev.currentTarget as HTMLButtonElement, run) },
|
||||
ic('refresh'),
|
||||
h('span', {}, _('Reconnect')),
|
||||
);
|
||||
const title = fmt(_('Reconnect %s'), d.name);
|
||||
const el = h(
|
||||
'div',
|
||||
{ class: 'view' },
|
||||
head(title),
|
||||
sub(
|
||||
here
|
||||
? _(
|
||||
'It gets new keys. This device is connected through its current settings: it disconnects a few seconds after you confirm. Add the new ones that open next.',
|
||||
)
|
||||
: _('It gets new keys and its current settings stop working. Set it up again with the new ones that open next.'),
|
||||
action: _('Reconnect'),
|
||||
cls: 'accent',
|
||||
run: async () => {
|
||||
try {
|
||||
const r = await call<{ config: ClientConfig; state: State }>(`devices/${d.id}`, { action: 'reconnect' });
|
||||
setState(r.state);
|
||||
repaint();
|
||||
await continueSetup(r.state.person.devices.find((x) => x.id === d.id) ?? { ...d, handshake: 0 }, r.config);
|
||||
} catch (er) {
|
||||
toast((er as Error).message, true);
|
||||
}
|
||||
},
|
||||
}),
|
||||
),
|
||||
kinds.el,
|
||||
lan,
|
||||
go,
|
||||
);
|
||||
return { el, label: title };
|
||||
}
|
||||
|
||||
/**
|
||||
* LAN Bypass on or off from the ⋯ menu: the keys stay, the device needs its
|
||||
* updated configuration (its own local network in or out of the tunnel is in
|
||||
* there), so its set-up opens on it.
|
||||
*/
|
||||
export async function toggleBypass(d: Device) {
|
||||
if (secureFirst()) return;
|
||||
const on = !d.lan_bypass;
|
||||
try {
|
||||
const r = await call<{ state: State }>(`devices/${d.id}`, { action: 'bypass', on });
|
||||
setState(r.state);
|
||||
repaint();
|
||||
toast(on ? _('LAN Bypass is on: add the updated connection') : _('LAN Bypass is off: add the updated connection'));
|
||||
const dev = r.state.person.devices.find((x) => x.id === d.id);
|
||||
if (dev) await openSetup(dev);
|
||||
} catch (er) {
|
||||
toast((er as Error).message, true);
|
||||
}
|
||||
}
|
||||
|
||||
export function removeDevice(d: Device) {
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
// What a device is and how it connects, as Add a device and Reconnect ask it:
|
||||
// the kinds as four tiles (phones and tablets are one choice, the same apps and
|
||||
// the same smaller packets) and LAN Bypass, the whole row a switch.
|
||||
|
||||
import type { Kind } from '../../shared/types';
|
||||
import { netsLabel, pickLabel, pickOf, type KindPick } from '../../shared/format';
|
||||
import { fmt } from '../../shared/i18n';
|
||||
import { h } from '../dom';
|
||||
import { SMOOTH, play } from '../motion';
|
||||
import { glass } from '../ui/glass';
|
||||
|
||||
export const UA = navigator.userAgent;
|
||||
export const IPAD = /iPad/.test(UA) || (/Macintosh/.test(UA) && navigator.maxTouchPoints > 1);
|
||||
|
||||
/** Best guess at the kind of device this page is open on (the browser never tells). */
|
||||
export function guessKind(): Kind {
|
||||
if (IPAD || /Tablet/i.test(UA) || (/Android/.test(UA) && !/Mobile/.test(UA))) return 'tablet';
|
||||
if (/Android|iPhone|Mobile/i.test(UA)) return 'phone';
|
||||
return 'computer';
|
||||
}
|
||||
|
||||
/** The kind a pick keeps: Mobile is a tablet when this page is open on one, or when the device was one already (`was`). */
|
||||
export function kindOf(p: KindPick, was?: Kind): Kind {
|
||||
if (was && pickOf(was) === p) return was;
|
||||
return p !== 'mobile' ? p : guessKind() === 'tablet' ? 'tablet' : 'phone';
|
||||
}
|
||||
|
||||
/**
|
||||
* A line in a block opens or folds away: height, opacity and blur on SMOOTH, as the set-up steps fold, from
|
||||
* where it is on screen (flicking the switch never snaps). The block's 1 px gap goes with it.
|
||||
*/
|
||||
function foldLine(el: HTMLElement, open: boolean) {
|
||||
const cs = getComputedStyle(el);
|
||||
const from = el.hidden
|
||||
? { h: 0, o: 0, b: 4, m: -1 }
|
||||
: {
|
||||
h: el.getBoundingClientRect().height,
|
||||
o: +cs.opacity,
|
||||
b: +(cs.filter.match(/blur\(([\d.]+)px\)/)?.[1] ?? 0),
|
||||
m: parseFloat(cs.marginTop) || 0,
|
||||
};
|
||||
el.getAnimations().forEach((a) => a.cancel());
|
||||
el.hidden = false;
|
||||
el.style.overflow = 'hidden';
|
||||
const to = open ? { h: el.scrollHeight, o: 1, b: 0, m: 0 } : { h: 0, o: 0, b: 4, m: -1 };
|
||||
const frame = (v: typeof from) => ({ height: `${v.h}px`, opacity: v.o, filter: v.b ? `blur(${v.b}px)` : 'none', marginTop: `${v.m}px` });
|
||||
const a = play(el, [frame(from), frame(to)], { duration: SMOOTH.duration, easing: SMOOTH.easing, fill: 'forwards' });
|
||||
a.onfinish = () => {
|
||||
el.hidden = !open;
|
||||
el.style.overflow = '';
|
||||
a.cancel();
|
||||
};
|
||||
}
|
||||
|
||||
export interface KindTiles {
|
||||
el: HTMLElement;
|
||||
/** Ring this one (the ring does not travel between tiles: the picked tile rings itself where it stands). */
|
||||
set(k: KindPick): void;
|
||||
}
|
||||
|
||||
/** The kinds a router takes, as tiles; `onPick` on a tap, after the ring moved. */
|
||||
export function kindTiles(picks: KindPick[], onPick: (k: KindPick) => void): KindTiles {
|
||||
const el = h('div', { class: 'kinds', role: 'radiogroup', 'aria-label': _('What is it?') });
|
||||
el.style.setProperty('--n', String(picks.length));
|
||||
const set = (k: KindPick) =>
|
||||
tiles.forEach((t, i) => {
|
||||
const on = picks[i] === k;
|
||||
t.classList.toggle('on', on);
|
||||
t.setAttribute('aria-checked', String(on));
|
||||
});
|
||||
const tiles = picks.map((k) => {
|
||||
const t = h(
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
class: 'kind',
|
||||
role: 'radio',
|
||||
'aria-label': pickLabel(k),
|
||||
onclick: () => {
|
||||
set(k);
|
||||
onPick(k);
|
||||
},
|
||||
},
|
||||
h('span', { class: 'kind-tile' }, glass(k, 'blue')),
|
||||
h('span', { class: 'kind-lbl' }, pickLabel(k)),
|
||||
);
|
||||
el.appendChild(t);
|
||||
return t;
|
||||
});
|
||||
return { el, set };
|
||||
}
|
||||
|
||||
/**
|
||||
* LAN Bypass, the whole row the switch, built as it is (`on`) before it is on
|
||||
* the page: nothing slides. With home access the home networks still go into
|
||||
* the tunnel: a local network on the same addresses is out of reach, and the
|
||||
* row says so while it is on.
|
||||
*/
|
||||
export function lanSwitch(on: boolean, home: string[], onChange: (on: boolean) => void): HTMLElement {
|
||||
const except = home.length
|
||||
? h('span', { class: 'sw-sub sw-note', hidden: !on }, fmt(_('Except %s: those addresses lead to the home network.'), netsLabel(home)))
|
||||
: null;
|
||||
const row = h(
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
class: on ? 'swrow on' : 'swrow',
|
||||
role: 'switch',
|
||||
'aria-checked': String(on),
|
||||
onclick: () => {
|
||||
on = !on;
|
||||
row.classList.toggle('on', on);
|
||||
row.setAttribute('aria-checked', String(on));
|
||||
if (except) foldLine(except, on);
|
||||
onChange(on);
|
||||
},
|
||||
},
|
||||
glass('lan', 'blue'),
|
||||
h(
|
||||
'span',
|
||||
{ class: 'sw-t' },
|
||||
h('b', {}, _('LAN Bypass')),
|
||||
h('span', { class: 'sw-sub' }, _('Your local network stays reachable while connected.')),
|
||||
except,
|
||||
),
|
||||
h('span', { class: 'sw', 'aria-hidden': 'true' }),
|
||||
);
|
||||
return row;
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import { h, ic, type Kid } from '../dom';
|
||||
import { EASE_IN, EASE_OUT, POP, SMOOTH, play } from '../motion';
|
||||
import {
|
||||
APP_NAME,
|
||||
appName,
|
||||
importPath,
|
||||
importSteps,
|
||||
keyFileName,
|
||||
@@ -18,6 +19,7 @@ import {
|
||||
routerStore,
|
||||
scanPath,
|
||||
vpnContinue,
|
||||
v2rTunnelMode,
|
||||
storeFor,
|
||||
type AppId,
|
||||
type Platform,
|
||||
@@ -29,14 +31,14 @@ import { glass } from '../ui/glass';
|
||||
import { menuLine, morphText, setText } from '../ui/morph';
|
||||
import { hint } from '../ui/sheet';
|
||||
|
||||
export const APP_ICON: Record<AppId, string> = { vpn: 'amnezia', awg: 'amneziawg', wg: 'wireguard' };
|
||||
export const APP_ICON: Record<AppId, string> = { vpn: 'amnezia', awg: 'amneziawg', v2r: 'v2raytun', wg: 'wireguard' };
|
||||
|
||||
/** The app a device was set up with last time, so the sheet reopens on it. */
|
||||
const memo = (d: Device) => `dl.app.${d.id}`;
|
||||
export function recallApp(d: Device): AppId | null {
|
||||
try {
|
||||
const v = localStorage.getItem(memo(d));
|
||||
return v === 'vpn' || v === 'awg' || v === 'wg' ? v : null;
|
||||
return v === 'vpn' || v === 'awg' || v === 'v2r' || v === 'wg' ? v : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
@@ -49,11 +51,17 @@ export function rememberApp(d: Device, app: AppId) {
|
||||
}
|
||||
}
|
||||
|
||||
/** What the steps work with: the device, its configuration, the key, and the choices made. */
|
||||
/** What the steps work with: the device, its configuration, the key, the link, and the choices made. */
|
||||
export interface SetupCtx {
|
||||
d: Device;
|
||||
cfg: ClientConfig;
|
||||
key: string;
|
||||
/** The connection as V2RayTun's awg:// link (shared/awglink.ts). */
|
||||
link: string;
|
||||
/** The link names the server by an IP in place of its name (false: the address is an IP already, or did not resolve). */
|
||||
byIp: boolean;
|
||||
/** The disguise is off and this is no router: AmneziaWG's choice is WireGuard's too (setup.ts appName). */
|
||||
wgToo: boolean;
|
||||
/** The platform this page is open on. */
|
||||
pf: Platform;
|
||||
/** "the phone": the device in a sentence. */
|
||||
@@ -83,13 +91,26 @@ function badge(
|
||||
return h('a', { class: cls, href: st.href, target: app ? null : '_blank', rel: 'noopener noreferrer' }, inner);
|
||||
}
|
||||
|
||||
/** Where the app comes from: the store (and, on Android, the APK beside it), or a line to go and get it. */
|
||||
export function storeBlock(app: AppId, os: Platform, router: boolean): Kid[] {
|
||||
/**
|
||||
* Where the app comes from: the store (and, on Android, the APK beside it), or
|
||||
* a line to go and get it. With the disguise off (`wgToo`), a line under
|
||||
* AmneziaWG's says WireGuard takes the connection too, its name a link to its
|
||||
* store here.
|
||||
*/
|
||||
export function storeBlock(app: AppId, os: Platform, router: boolean, wgToo = false): Kid[] {
|
||||
const st: Store | null = router ? routerStore(app) : storeFor(app, os);
|
||||
if (!st) return [hint(fmt(_('Get %s on the %s and come back here.'), APP_NAME[app], platformLabel(os)))];
|
||||
const wg = wgToo && app === 'awg' && !router ? wgLine(os) : null;
|
||||
if (!st) return [hint(fmt(_('Get %s on the %s and come back here.'), appName(app, wgToo && !router), platformLabel(os)))];
|
||||
// Android: the store can fail (no Google Play, or it hides the app), so the APK sits beside it.
|
||||
if (st.alt) return [h('div', { class: 'badges2' }, badge(st), badge(st.alt)), hint(st.alt.why)];
|
||||
return [badge(st)];
|
||||
if (st.alt) return [h('div', { class: 'badges2' }, badge(st), badge(st.alt)), hint(st.alt.why), wg];
|
||||
return [badge(st), wg];
|
||||
}
|
||||
|
||||
/** "WireGuard works too, if it is already there": the name links to its store on this platform. */
|
||||
function wgLine(os: Platform): HTMLElement {
|
||||
const st = storeFor('wg', os);
|
||||
const name = st ? h('a', { href: st.href, target: '_blank', rel: 'noopener noreferrer' }, APP_NAME.wg) : h('b', {}, APP_NAME.wg);
|
||||
return hint(...fill<Node | string>(_('%s works too, if it is already there: the disguise is off.'), name));
|
||||
}
|
||||
|
||||
const howto = (steps: [string, string][]) =>
|
||||
@@ -101,10 +122,42 @@ const howto = (steps: [string, string][]) =>
|
||||
|
||||
const linkBtn = (label: string, run: (ev: Event) => void) => h('button', { type: 'button', onclick: run }, label);
|
||||
|
||||
/** Step 2: a link for AmneziaVPN, the file for the others, in the words of where they go. */
|
||||
/** V2RayTun has the server by its IP, not its name: once the router's address changes, the connection goes stale. The IP itself stays off the page. */
|
||||
const byIpWords = () =>
|
||||
_('V2RayTun reaches the server by its IP address, not its hostname: if the address changes, add the connection again.');
|
||||
|
||||
/** V2RayTun takes the connection as a link from the clipboard: copied, then "+ › Import config from Clipboard". */
|
||||
function v2rKids(c: SetupCtx): Kid[] {
|
||||
// The words of the app on this device when the page is open on it (Windows has its own); else Android's.
|
||||
const os = c.same() ? c.pf : 'unknown';
|
||||
const path = importPath('v2r', os);
|
||||
const win = os === 'windows';
|
||||
return [
|
||||
badge(
|
||||
{
|
||||
top: _('The connection as one link'),
|
||||
main: _('Copy the link'),
|
||||
mark: 'copy',
|
||||
onclick: (ev) => copy(c.link, _('Link copied'), ev.currentTarget),
|
||||
},
|
||||
true,
|
||||
),
|
||||
howto([
|
||||
[fmt(_('Open %s', 'step'), APP_NAME.v2r), ''],
|
||||
[path.replace(/ → [^→]*$/, ' → '), path.replace(/^.* → /, '')],
|
||||
// On Windows AmneziaWG runs in its Tunnel mode (the Mode switch on its main screen), which needs administrator rights.
|
||||
win ? [fmt(_('Switch to %s mode and connect', 'step'), v2rTunnelMode()), ''] : [_('Connect', 'step'), ''],
|
||||
]),
|
||||
win ? hint(_('V2RayTun needs administrator rights for this mode: it offers to restart with them.')) : null,
|
||||
c.byIp ? hint(byIpWords()) : null,
|
||||
];
|
||||
}
|
||||
|
||||
/** Step 2: a link for AmneziaVPN and V2RayTun, the file for the others, in the words of where they go. */
|
||||
export function connectKids(c: SetupCtx): Kid[] {
|
||||
const app = c.app();
|
||||
const name = APP_NAME[app];
|
||||
const name = appName(app, c.wgToo);
|
||||
if (app === 'v2r') return v2rKids(c);
|
||||
const hereHandheld = c.pf === 'ios' || c.pf === 'android';
|
||||
// On the phone being set up, a link opens AmneziaVPN only on Android; an
|
||||
// iPhone takes the key as a .vpn file from the share sheet.
|
||||
@@ -141,7 +194,12 @@ export function connectKids(c: SetupCtx): Kid[] {
|
||||
share
|
||||
? badge(
|
||||
{
|
||||
top: c.same() ? fmt(_('Straight into %s'), name) : fmt(_('Send it to the %s'), c.there),
|
||||
// Two apps' names do not fit the badge's small line: "the app" then.
|
||||
top: c.same()
|
||||
? c.wgToo && app === 'awg'
|
||||
? _('Straight into the app')
|
||||
: fmt(_('Straight into %s'), name)
|
||||
: fmt(_('Send it to the %s'), c.there),
|
||||
main: _('Share the file'),
|
||||
mark: 'share',
|
||||
onclick: () => void share(),
|
||||
@@ -158,15 +216,29 @@ export function connectKids(c: SetupCtx): Kid[] {
|
||||
true,
|
||||
),
|
||||
// In the words of the app where the file goes: the phone in hand, or the computer's system.
|
||||
howto(importSteps(app, c.pf, c.cfg.filename, !!share && c.same())),
|
||||
howto(importSteps(app, c.pf, c.cfg.filename, !!share && c.same(), c.wgToo)),
|
||||
];
|
||||
}
|
||||
|
||||
/** A computer set up from elsewhere: the connection to send there, as the key or the file. */
|
||||
/** A computer (or a TV, a box) set up from elsewhere: the connection to send there, as the key, the link or the file. */
|
||||
export function sendKids(c: SetupCtx): Kid[] {
|
||||
const app = c.app();
|
||||
const btn = (icon: string, label: string, run: (ev: Event) => void) =>
|
||||
h('button', { type: 'button', class: 'btn soft sm', onclick: run }, ic(icon), h('span', { class: 'lbl' }, label));
|
||||
if (app === 'v2r')
|
||||
return [
|
||||
h(
|
||||
'p',
|
||||
{ class: 'desc' },
|
||||
fmt(_('Send it to the %s in a message or a note, then in V2RayTun: %s.'), c.there, importPath('v2r').replace(/ → /g, ' › ')),
|
||||
),
|
||||
h(
|
||||
'div',
|
||||
{ class: 'btnrow2' },
|
||||
btn('copy', _('Copy the link'), (ev) => copy(c.link, _('Link copied'), ev.currentTarget)),
|
||||
),
|
||||
c.byIp ? hint(byIpWords()) : null,
|
||||
];
|
||||
if (app === 'vpn') {
|
||||
const file = keyFileName(c.cfg.filename);
|
||||
const share = !!shareFile(file, c.key);
|
||||
@@ -189,7 +261,7 @@ export function sendKids(c: SetupCtx): Kid[] {
|
||||
h(
|
||||
'p',
|
||||
{ class: 'desc' },
|
||||
...fill<Node | string>(_('Send it to the %s, then import %s in %s.'), c.there, h('b', {}, c.cfg.filename), APP_NAME[app]),
|
||||
...fill<Node | string>(_('Send it to the %s, then import %s in %s.'), c.there, h('b', {}, c.cfg.filename), appName(app, c.wgToo)),
|
||||
),
|
||||
h(
|
||||
'div',
|
||||
@@ -315,15 +387,26 @@ export interface ScanLine {
|
||||
set(app: AppId): void;
|
||||
}
|
||||
|
||||
/** "In AmneziaWG: + › Create from QR code", with both phone systems' wording where they differ. */
|
||||
export function scanLine(app: AppId): ScanLine {
|
||||
const name = h('span', { class: 'osm-p' }, APP_NAME[app]);
|
||||
/**
|
||||
* "In AmneziaWG: + › Create from QR code", with both phone systems' wording
|
||||
* where they differ ("In AmneziaWG or WireGuard:" with the disguise off,
|
||||
* `wgToo`: the same code and menus). For V2RayTun, where the link names the
|
||||
* server by its IP (`byIp`), a line under it says what that means.
|
||||
*/
|
||||
export function scanLine(app: AppId, byIp = false, wgToo = false): ScanLine {
|
||||
const name = h('span', { class: 'osm-p' }, appName(app, wgToo));
|
||||
const path = menuLine(scanPath(app, 'ios'), scanPath(app, 'android'));
|
||||
const note = byIp ? hint(byIpWords()) : null;
|
||||
const shows = (a: AppId) => {
|
||||
if (note) note.hidden = a !== 'v2r';
|
||||
};
|
||||
shows(app);
|
||||
return {
|
||||
el: h('span', { class: 'scanline' }, h('span', {}, ...fill(_('In %s:'), name)), path.el),
|
||||
el: h('div', { class: 'scanwrap' }, h('span', { class: 'scanline' }, h('span', {}, ...fill(_('In %s:'), name)), path.el), note),
|
||||
set(a) {
|
||||
morphText(name, APP_NAME[a], undefined, { whole: true });
|
||||
morphText(name, appName(a, wgToo), undefined, { whole: true });
|
||||
path.set(scanPath(a, 'ios'), scanPath(a, 'android'));
|
||||
shows(a);
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -342,7 +425,7 @@ export interface ConnPill {
|
||||
* still fades out), each move from where it stands. Copied: a check, and the
|
||||
* tooltip says so.
|
||||
*/
|
||||
export function connPill(get: () => { text: string; msg: string; file: string; app: string }): ConnPill {
|
||||
export function connPill(get: () => { text: string; msg: string; file: string; app: string; link?: boolean }): ConnPill {
|
||||
const tt = h('span', { class: 'tt' });
|
||||
const tm = h('span', { class: 'tt-m' });
|
||||
const tip = h('span', { class: 'hp-tip', 'aria-hidden': 'true' }, tt, tm);
|
||||
@@ -473,9 +556,9 @@ export function connPill(get: () => { text: string; msg: string; file: string; a
|
||||
return {
|
||||
el,
|
||||
sync() {
|
||||
const app = get().app;
|
||||
dl.setAttribute('aria-label', fmt(_('Download %s config'), app));
|
||||
cp.setAttribute('aria-label', fmt(_('Copy %s config'), app));
|
||||
const { app, link } = get();
|
||||
dl.setAttribute('aria-label', link ? fmt(_('Download %s link'), app) : fmt(_('Download %s config'), app));
|
||||
cp.setAttribute('aria-label', link ? fmt(_('Copy %s link'), app) : fmt(_('Copy %s config'), app));
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -11,11 +11,12 @@
|
||||
|
||||
import type { ClientConfig, Device } from '../../shared/types';
|
||||
import { fmt } from '../../shared/i18n';
|
||||
import { awgLink } from '../../shared/awglink';
|
||||
import { vpnKey, vpnQrText } from '../../shared/vpnkey';
|
||||
import { ApiError, call } from '../api';
|
||||
import { h, put } from '../dom';
|
||||
import { SMOOTH, play } from '../motion';
|
||||
import { APP_NAME, appsFor, deviceNoun, inWebview, keyFileName, sameDevice, setupLink, type AppId } from '../setup';
|
||||
import { APP_NAME, appsFor, appsOn, deviceNoun, inWebview, keyFileName, sameDevice, setupLink, type AppId } from '../setup';
|
||||
import { pageUrl, platform, preset, repaint } from '../state';
|
||||
import { accordion, regrow } from '../ui/accordion';
|
||||
import { codeRow, linkRow, type CodeRow } from '../ui/codes';
|
||||
@@ -124,11 +125,22 @@ function setupView(d: Device, cfg: ClientConfig, key: string, here = false): Vie
|
||||
const layout: Layout = same ? 'same' : router ? 'router' : handheld ? 'away' : 'pc-away';
|
||||
const there = deviceNoun(d.kind);
|
||||
const thereOn = deviceNoun(d.kind, true);
|
||||
// A router takes AmneziaWG (or WireGuard), never AmneziaVPN.
|
||||
const choices = apps.filter((a) => !router || a.id !== 'vpn');
|
||||
let app: AppId = recallApp(d) ?? (router ? 'awg' : 'vpn');
|
||||
// A router takes AmneziaWG or WireGuard, never AmneziaVPN; elsewhere WireGuard is AmneziaWG's choice; V2RayTun
|
||||
// is for Android and Windows (setup.ts appsOn).
|
||||
const choices = appsOn(d.kind, apps, same ? pf : null);
|
||||
// AmneziaWG first, as the picker lists it; a device set up before opens on the app it was set up with.
|
||||
let app: AppId = recallApp(d) ?? 'awg';
|
||||
if (!choices.some((a) => a.id === app)) app = choices[0].id;
|
||||
const c: SetupCtx = { d, cfg, key, pf, there, app: () => app, same: () => same };
|
||||
// V2RayTun takes the server by its IP (shared/awglink.ts): only when the address is a name do the words say what that means.
|
||||
const ip = cfg.amnezia.host_ip;
|
||||
// Its Windows app resolves the name itself (amneziawg-windows, before the tunnel starts): there the link keeps
|
||||
// the name, so a new address at home does not break it, and nothing needs saying.
|
||||
const named = same && pf === 'windows';
|
||||
const link = awgLink(cfg.conf, cfg.server, named ? null : ip);
|
||||
const byIp = !named && !!ip && ip !== cfg.amnezia.host.replace(/^\[(.*)\]$/, '$1');
|
||||
// The disguise off: WireGuard takes AmneziaWG's file and code (one choice, both names; a router keeps both packages).
|
||||
const wgToo = preset() === 'off' && !router;
|
||||
const c: SetupCtx = { d, cfg, key, link, byIp, wgToo, pf, there, app: () => app, same: () => same };
|
||||
|
||||
// The pickers and the boxes a pick changes live across repaints: a pick only
|
||||
// refills what it changes, so the pills glide and nothing else in the sheet moves.
|
||||
@@ -178,9 +190,13 @@ function setupView(d: Device, cfg: ClientConfig, key: string, here = false): Vie
|
||||
const pill =
|
||||
layout === 'away'
|
||||
? connPill(() => ({
|
||||
// V2RayTun: its link, copied or as a .txt. Its "Import config from locally" takes a file line by line,
|
||||
// each line a link: a .conf does not import that way (and its server's name would not connect either).
|
||||
...(app === 'vpn'
|
||||
? { text: key, msg: _('Key copied'), file: keyFileName(cfg.filename) }
|
||||
: { text: cfg.conf, msg: _('Configuration copied'), file: cfg.filename }),
|
||||
: app === 'v2r'
|
||||
? { text: link, msg: _('Link copied'), file: cfg.filename.replace(/\.conf$/i, '.txt'), link: true }
|
||||
: { text: cfg.conf, msg: _('Configuration copied'), file: cfg.filename }),
|
||||
app: APP_NAME[app],
|
||||
}))
|
||||
: null;
|
||||
@@ -188,13 +204,14 @@ function setupView(d: Device, cfg: ClientConfig, key: string, here = false): Vie
|
||||
/** Everything a pick changes, refilled in place. */
|
||||
function fill() {
|
||||
morphText(title1, router ? fmt(_('Get %s on the router'), APP_NAME[app]) : fmt(_('Get %s'), APP_NAME[app]), undefined, { whole: true });
|
||||
morphInto(getBox, storeBlock(app, pf, router));
|
||||
morphInto(getBox, storeBlock(app, pf, router, wgToo));
|
||||
// The router's file is the same for either app: it stays as it is (a folded configuration stays folded).
|
||||
if (!router) morphInto(addBox, connectKids(c));
|
||||
else if (!addBox.firstChild) put(addBox, filePane(cfg));
|
||||
// The connection as a code: only a phone or a tablet set up from here shows one.
|
||||
if (layout === 'away') {
|
||||
const text = app === 'vpn' ? vpnQrText(key) : cfg.conf;
|
||||
// V2RayTun scans its link: a .conf would come in named by the clock, the link carries the server's name.
|
||||
const text = app === 'vpn' ? vpnQrText(key) : app === 'v2r' ? link : cfg.conf;
|
||||
// Another app: its words morph in place, the code changes only when it holds something else (codes.ts).
|
||||
if (code && scan && code.el.isConnected) {
|
||||
if (codeApp !== app) {
|
||||
@@ -202,7 +219,7 @@ function setupView(d: Device, cfg: ClientConfig, key: string, here = false): Vie
|
||||
scan.set(app);
|
||||
}
|
||||
} else {
|
||||
scan = scanLine(app);
|
||||
scan = scanLine(app, byIp, wgToo);
|
||||
code = codeRow(text, [scan.el], tooLong);
|
||||
codeBox.replaceChildren(code.el);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,10 @@ msgstr ""
|
||||
msgid "%s (router time)"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/shared/pace.ts
|
||||
msgid "%s a day lately"
|
||||
msgstr ""
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/core.uc
|
||||
msgid "%s already has %d device. Remove one first to lower the limit to %d."
|
||||
msgid_plural "%s already has %d devices. Remove one first to lower the limit to %d."
|
||||
@@ -153,14 +157,26 @@ msgstr[1] ""
|
||||
msgid "%s options"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgid "%s or %s"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/shared/format.ts
|
||||
msgid "%s this month"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
msgid "%s works too, if it is already there: the disguise is off."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/page/notices.ts
|
||||
msgid "%s your time"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/page/devices.ts
|
||||
msgid "%s, last 7 days"
|
||||
msgstr ""
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/awg.uc
|
||||
msgid "%s: <%s> is not a tag AmneziaWG apps accept: use <b 0x…> with an even number of hex digits, <r N>, <rc N> or <rd N> with N from 1 to 1000, or <t>."
|
||||
msgstr ""
|
||||
@@ -291,6 +307,10 @@ msgstr ""
|
||||
msgid "Can’t finish connecting"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgid "Channel on"
|
||||
msgstr ""
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/core.uc
|
||||
msgid "Circle %s: server %s does not exist."
|
||||
msgstr ""
|
||||
@@ -320,6 +340,11 @@ msgstr ""
|
||||
msgid "Connect"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
msgctxt "step"
|
||||
msgid "Connect"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/page/devices.ts
|
||||
msgid "Connected"
|
||||
msgstr ""
|
||||
@@ -366,6 +391,10 @@ msgstr ""
|
||||
msgid "Copy %s config"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
msgid "Copy %s link"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/page/devices.ts
|
||||
msgid "Copy IP address"
|
||||
msgstr ""
|
||||
@@ -396,6 +425,7 @@ msgid "Copy the key"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/page-code.ts
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
#: web/src/portal/ui/codes.ts
|
||||
msgid "Copy the link"
|
||||
msgstr ""
|
||||
@@ -531,6 +561,10 @@ msgstr ""
|
||||
msgid "Download %s config"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
msgid "Download %s link"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgid "Download for Linux"
|
||||
msgstr ""
|
||||
@@ -579,7 +613,7 @@ msgstr ""
|
||||
msgid "Enter a device name: up to %d letters, digits, spaces and - _ ."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/add.ts
|
||||
#: web/src/portal/flows/device-form.ts
|
||||
msgid "Except %s: those addresses lead to the home network."
|
||||
msgstr ""
|
||||
|
||||
@@ -665,6 +699,21 @@ msgctxt "WireGuard app"
|
||||
msgid "Import Tunnel(s) from File…"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgctxt "V2RayTun app"
|
||||
msgid "Import config from Clipboard"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgctxt "V2RayTun app"
|
||||
msgid "Import config from QRcode"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgctxt "V2RayTun app"
|
||||
msgid "Import from clipboard"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgctxt "WireGuard app"
|
||||
msgid "Import from file or archive"
|
||||
@@ -767,10 +816,19 @@ msgstr ""
|
||||
msgid "Key generation failed."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/add.ts
|
||||
#: web/src/portal/flows/device-form.ts
|
||||
#: web/src/portal/page/devices.ts
|
||||
msgid "LAN Bypass"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/device-actions.ts
|
||||
msgid "LAN Bypass is off: add the updated connection"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/device-actions.ts
|
||||
msgid "LAN Bypass is on: add the updated connection"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/page/frame.ts
|
||||
msgid "Language"
|
||||
msgstr ""
|
||||
@@ -784,6 +842,8 @@ msgid "Last connected %s"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/page-code.ts
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
#: web/src/portal/flows/setup-view.ts
|
||||
#: web/src/portal/ui/codes.ts
|
||||
msgid "Link copied"
|
||||
msgstr ""
|
||||
@@ -884,10 +944,18 @@ msgstr ""
|
||||
msgid "OR"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/page/devices.ts
|
||||
msgid "Off"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgid "Official release on GitHub"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/page/devices.ts
|
||||
msgid "On"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/page/notices.ts
|
||||
msgid "On %s."
|
||||
msgstr ""
|
||||
@@ -971,6 +1039,10 @@ msgstr ""
|
||||
msgid "OpenWrt packages + kmod"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgid "Or, with wireguard-tools,"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/shared/format.ts
|
||||
msgid "Other"
|
||||
msgstr ""
|
||||
@@ -1053,14 +1125,11 @@ msgstr ""
|
||||
msgid "Reconnect"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/device-actions.ts
|
||||
#: web/src/portal/page/devices.ts
|
||||
msgid "Reconnect %s"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/device-actions.ts
|
||||
msgid "Reconnect %s?"
|
||||
msgstr ""
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/awg.uc
|
||||
msgid "RejectAfterTime must be at most 180 seconds."
|
||||
msgstr ""
|
||||
@@ -1123,6 +1192,10 @@ msgstr ""
|
||||
msgid "Send it to the %s in a message or a note, then in AmneziaVPN: %s."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
msgid "Send it to the %s in a message or a note, then in V2RayTun: %s."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
msgid "Send it to the %s, then import %s in %s."
|
||||
msgstr ""
|
||||
@@ -1181,6 +1254,10 @@ msgstr ""
|
||||
msgid "Straight into %s"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
msgid "Straight into the app"
|
||||
msgstr ""
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/core.uc
|
||||
msgid "Subnet must look like 10.77.0.0/24."
|
||||
msgstr ""
|
||||
@@ -1189,6 +1266,11 @@ msgstr ""
|
||||
msgid "Subnet overlaps %s."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
msgctxt "step"
|
||||
msgid "Switch to %s mode and connect"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/shared/format.ts
|
||||
msgid "TB"
|
||||
msgstr ""
|
||||
@@ -1233,6 +1315,10 @@ msgstr ""
|
||||
msgid "The connection as one key"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
msgid "The connection as one link"
|
||||
msgstr ""
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/awg.uc
|
||||
msgid "The header protection key is not a key."
|
||||
msgstr ""
|
||||
@@ -1307,6 +1393,11 @@ msgstr ""
|
||||
msgid "Too many changes in a short time. Try again in a few minutes."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgctxt "V2RayTun app"
|
||||
msgid "Tunnel"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/setup-view.ts
|
||||
msgid "Two steps, about a minute"
|
||||
msgstr ""
|
||||
@@ -1331,6 +1422,10 @@ msgstr ""
|
||||
msgid "Unknown circle."
|
||||
msgstr ""
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/core.uc
|
||||
msgid "Unknown device type."
|
||||
msgstr ""
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/core.uc
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/devices.uc
|
||||
msgid "Unknown device."
|
||||
@@ -1360,6 +1455,18 @@ msgstr ""
|
||||
msgid "Uploaded"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
msgid "V2RayTun needs administrator rights for this mode: it offers to restart with them."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
msgid "V2RayTun reaches the server by its IP address, not its hostname: if the address changes, add the connection again."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgid "V2RayTun’s own channel: news and updates of the app."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/wait.ts
|
||||
msgid "Waiting for the connection"
|
||||
msgstr ""
|
||||
@@ -1368,7 +1475,7 @@ msgstr ""
|
||||
msgid "Warning must be 0-60 days."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/add.ts
|
||||
#: web/src/portal/flows/device-form.ts
|
||||
msgid "What is it?"
|
||||
msgstr ""
|
||||
|
||||
@@ -1412,6 +1519,10 @@ msgstr ""
|
||||
msgid "Your access is paused."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/page/access.ts
|
||||
msgid "Your data this month"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/page/devices.ts
|
||||
msgid "Your devices"
|
||||
msgstr ""
|
||||
@@ -1428,7 +1539,7 @@ msgstr ""
|
||||
msgid "Your devices can’t connect until it’s resumed."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/flows/add.ts
|
||||
#: web/src/portal/flows/device-form.ts
|
||||
msgid "Your local network stays reachable while connected."
|
||||
msgstr ""
|
||||
|
||||
@@ -1436,6 +1547,14 @@ msgstr ""
|
||||
msgid "Your network may be blocking the connection."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/shared/pace.ts
|
||||
msgid "about %s by the reset on %s"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/page/access.ts
|
||||
msgid "about average"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/shared/format.ts
|
||||
msgid "bit/s"
|
||||
msgstr ""
|
||||
@@ -1482,6 +1601,12 @@ msgstr ""
|
||||
msgid "ends tomorrow"
|
||||
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] ""
|
||||
|
||||
#: web/src/shared/format.ts
|
||||
msgid "just now"
|
||||
msgstr ""
|
||||
@@ -1502,6 +1627,14 @@ msgstr ""
|
||||
msgid "no limit"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/page/devices.ts
|
||||
msgid "not used"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/page/access.ts
|
||||
msgid "opens in %s"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgid "phone"
|
||||
msgstr ""
|
||||
@@ -1520,6 +1653,10 @@ msgctxt "on the"
|
||||
msgid "router"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/page/access.ts
|
||||
msgid "so far"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgid "tablet"
|
||||
msgstr ""
|
||||
|
||||
+146
-8
@@ -25,6 +25,10 @@ msgstr "%s (на Android: %s)"
|
||||
msgid "%s (router time)"
|
||||
msgstr "%s (по времени роутера)"
|
||||
|
||||
#: web/src/shared/pace.ts
|
||||
msgid "%s a day lately"
|
||||
msgstr "%s в день за последние дни"
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/core.uc
|
||||
msgid "%s already has %d device. Remove one first to lower the limit to %d."
|
||||
msgid_plural "%s already has %d devices. Remove one first to lower the limit to %d."
|
||||
@@ -158,14 +162,26 @@ msgstr[2] "Свободно %s из %s мест"
|
||||
msgid "%s options"
|
||||
msgstr "Действия с устройством %s"
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgid "%s or %s"
|
||||
msgstr "%s или %s"
|
||||
|
||||
#: web/src/shared/format.ts
|
||||
msgid "%s this month"
|
||||
msgstr "%s в этом месяце"
|
||||
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
msgid "%s works too, if it is already there: the disguise is off."
|
||||
msgstr "Подойдёт и %s, если он уже стоит: маскировка выключена."
|
||||
|
||||
#: web/src/portal/page/notices.ts
|
||||
msgid "%s your time"
|
||||
msgstr "%s по вашему времени"
|
||||
|
||||
#: web/src/portal/page/devices.ts
|
||||
msgid "%s, last 7 days"
|
||||
msgstr "%s, последние 7 дней"
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/awg.uc
|
||||
msgid "%s: <%s> is not a tag AmneziaWG apps accept: use <b 0x…> with an even number of hex digits, <r N>, <rc N> or <rd N> with N from 1 to 1000, or <t>."
|
||||
msgstr "%s: тег <%s> не примут приложения AmneziaWG: используйте <b 0x…> с чётным числом шестнадцатеричных цифр, <r N>, <rc N> или <rd N> с N от 1 до 1000 либо <t>."
|
||||
@@ -296,6 +312,10 @@ msgstr "Отмена"
|
||||
msgid "Can’t finish connecting"
|
||||
msgstr "Не удаётся подключиться"
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgid "Channel on"
|
||||
msgstr "Канал в"
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/core.uc
|
||||
msgid "Circle %s: server %s does not exist."
|
||||
msgstr "Круг %s: сервера %s нет."
|
||||
@@ -325,6 +345,11 @@ msgstr "Подтвердите импорт и подключитесь"
|
||||
msgid "Connect"
|
||||
msgstr "Подключить"
|
||||
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
msgctxt "step"
|
||||
msgid "Connect"
|
||||
msgstr "Подключитесь"
|
||||
|
||||
#: web/src/portal/page/devices.ts
|
||||
msgid "Connected"
|
||||
msgstr "Подключено"
|
||||
@@ -371,6 +396,10 @@ msgstr "Скопировать %s"
|
||||
msgid "Copy %s config"
|
||||
msgstr "Скопировать конфигурацию %s"
|
||||
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
msgid "Copy %s link"
|
||||
msgstr "Скопировать ссылку %s"
|
||||
|
||||
#: web/src/portal/page/devices.ts
|
||||
msgid "Copy IP address"
|
||||
msgstr "Скопировать IP-адрес"
|
||||
@@ -401,6 +430,7 @@ msgid "Copy the key"
|
||||
msgstr "Скопируйте ключ"
|
||||
|
||||
#: web/src/portal/flows/page-code.ts
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
#: web/src/portal/ui/codes.ts
|
||||
msgid "Copy the link"
|
||||
msgstr "Скопировать ссылку"
|
||||
@@ -536,6 +566,10 @@ msgstr "Скачать"
|
||||
msgid "Download %s config"
|
||||
msgstr "Скачать конфигурацию %s"
|
||||
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
msgid "Download %s link"
|
||||
msgstr "Скачать ссылку %s"
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgid "Download for Linux"
|
||||
msgstr "Скачать для Linux"
|
||||
@@ -584,7 +618,7 @@ msgstr "Закончится %s"
|
||||
msgid "Enter a device name: up to %d letters, digits, spaces and - _ ."
|
||||
msgstr "Введите название устройства: до %d букв, цифр, пробелов и - _ ."
|
||||
|
||||
#: web/src/portal/flows/add.ts
|
||||
#: web/src/portal/flows/device-form.ts
|
||||
msgid "Except %s: those addresses lead to the home network."
|
||||
msgstr "Кроме %s: эти адреса ведут в домашнюю сеть."
|
||||
|
||||
@@ -670,6 +704,21 @@ msgctxt "WireGuard app"
|
||||
msgid "Import Tunnel(s) from File…"
|
||||
msgstr "Импорт туннелей из файла…"
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgctxt "V2RayTun app"
|
||||
msgid "Import config from Clipboard"
|
||||
msgstr "Импорт из буфера обмена"
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgctxt "V2RayTun app"
|
||||
msgid "Import config from QRcode"
|
||||
msgstr "Импорт из QR-кода"
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgctxt "V2RayTun app"
|
||||
msgid "Import from clipboard"
|
||||
msgstr "Импорт из буфера обмена"
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgctxt "WireGuard app"
|
||||
msgid "Import from file or archive"
|
||||
@@ -772,10 +821,19 @@ msgstr "Не удалось создать ключ (нет случайных
|
||||
msgid "Key generation failed."
|
||||
msgstr "Не удалось создать ключ."
|
||||
|
||||
#: web/src/portal/flows/add.ts
|
||||
#: web/src/portal/flows/device-form.ts
|
||||
#: web/src/portal/page/devices.ts
|
||||
msgid "LAN Bypass"
|
||||
msgstr "Обход локальной сети"
|
||||
|
||||
#: web/src/portal/flows/device-actions.ts
|
||||
msgid "LAN Bypass is off: add the updated connection"
|
||||
msgstr "Обход локальной сети выключен: добавьте обновлённое подключение"
|
||||
|
||||
#: web/src/portal/flows/device-actions.ts
|
||||
msgid "LAN Bypass is on: add the updated connection"
|
||||
msgstr "Обход локальной сети включён: добавьте обновлённое подключение"
|
||||
|
||||
#: web/src/portal/page/frame.ts
|
||||
msgid "Language"
|
||||
msgstr "Язык"
|
||||
@@ -789,6 +847,8 @@ msgid "Last connected %s"
|
||||
msgstr "В сети %s"
|
||||
|
||||
#: web/src/portal/flows/page-code.ts
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
#: web/src/portal/flows/setup-view.ts
|
||||
#: web/src/portal/ui/codes.ts
|
||||
msgid "Link copied"
|
||||
msgstr "Ссылка скопирована"
|
||||
@@ -889,10 +949,18 @@ msgstr "Сейчас %s"
|
||||
msgid "OR"
|
||||
msgstr "ИЛИ"
|
||||
|
||||
#: web/src/portal/page/devices.ts
|
||||
msgid "Off"
|
||||
msgstr "Выкл."
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgid "Official release on GitHub"
|
||||
msgstr "Официальная версия на GitHub"
|
||||
|
||||
#: web/src/portal/page/devices.ts
|
||||
msgid "On"
|
||||
msgstr "Вкл."
|
||||
|
||||
#: web/src/portal/page/notices.ts
|
||||
msgid "On %s."
|
||||
msgstr "Дата окончания - %s."
|
||||
@@ -976,6 +1044,10 @@ msgstr "Пакеты OpenWrt"
|
||||
msgid "OpenWrt packages + kmod"
|
||||
msgstr "Пакеты OpenWrt + kmod"
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgid "Or, with wireguard-tools,"
|
||||
msgstr "Или через wireguard-tools:"
|
||||
|
||||
#: web/src/shared/format.ts
|
||||
msgid "Other"
|
||||
msgstr "Другое"
|
||||
@@ -1058,14 +1130,11 @@ msgstr "QR-код"
|
||||
msgid "Reconnect"
|
||||
msgstr "Переподключить"
|
||||
|
||||
#: web/src/portal/flows/device-actions.ts
|
||||
#: web/src/portal/page/devices.ts
|
||||
msgid "Reconnect %s"
|
||||
msgstr "Переподключить %s"
|
||||
|
||||
#: web/src/portal/flows/device-actions.ts
|
||||
msgid "Reconnect %s?"
|
||||
msgstr "Переподключить «%s»?"
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/awg.uc
|
||||
msgid "RejectAfterTime must be at most 180 seconds."
|
||||
msgstr "RejectAfterTime: не больше 180 секунд."
|
||||
@@ -1128,6 +1197,10 @@ msgstr "Отправить на %s"
|
||||
msgid "Send it to the %s in a message or a note, then in AmneziaVPN: %s."
|
||||
msgstr "Отправьте его на %s в сообщении или заметке, затем в AmneziaVPN: %s."
|
||||
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
msgid "Send it to the %s in a message or a note, then in V2RayTun: %s."
|
||||
msgstr "Отправьте её на %s в сообщении или заметке, затем в V2RayTun: %s."
|
||||
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
msgid "Send it to the %s, then import %s in %s."
|
||||
msgstr "Отправьте его на %s, затем импортируйте %s в %s."
|
||||
@@ -1186,6 +1259,10 @@ msgstr "Показать ключ"
|
||||
msgid "Straight into %s"
|
||||
msgstr "Сразу в %s"
|
||||
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
msgid "Straight into the app"
|
||||
msgstr "Сразу в приложение"
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/core.uc
|
||||
msgid "Subnet must look like 10.77.0.0/24."
|
||||
msgstr "Подсеть указывается так: 10.77.0.0/24."
|
||||
@@ -1194,6 +1271,11 @@ msgstr "Подсеть указывается так: 10.77.0.0/24."
|
||||
msgid "Subnet overlaps %s."
|
||||
msgstr "Подсеть пересекается с %s."
|
||||
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
msgctxt "step"
|
||||
msgid "Switch to %s mode and connect"
|
||||
msgstr "Включите режим «%s» и подключитесь"
|
||||
|
||||
#: web/src/shared/format.ts
|
||||
msgid "TB"
|
||||
msgstr "ТБ"
|
||||
@@ -1238,6 +1320,10 @@ msgstr "Подключение"
|
||||
msgid "The connection as one key"
|
||||
msgstr "Подключение одним ключом"
|
||||
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
msgid "The connection as one link"
|
||||
msgstr "Подключение одной ссылкой"
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/awg.uc
|
||||
msgid "The header protection key is not a key."
|
||||
msgstr "Ключ защиты заголовков некорректен."
|
||||
@@ -1312,6 +1398,11 @@ msgstr "Сегодня"
|
||||
msgid "Too many changes in a short time. Try again in a few minutes."
|
||||
msgstr "Слишком много изменений за короткое время. Попробуйте ещё раз через несколько минут."
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgctxt "V2RayTun app"
|
||||
msgid "Tunnel"
|
||||
msgstr "Туннель"
|
||||
|
||||
#: web/src/portal/flows/setup-view.ts
|
||||
msgid "Two steps, about a minute"
|
||||
msgstr "Два шага, около минуты"
|
||||
@@ -1336,6 +1427,10 @@ msgstr "Неизвестное действие."
|
||||
msgid "Unknown circle."
|
||||
msgstr "Неизвестный круг."
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/core.uc
|
||||
msgid "Unknown device type."
|
||||
msgstr "Неизвестный тип устройства."
|
||||
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/core.uc
|
||||
#: package/luci-app-dawnline/root/usr/share/ucode/dawnline/devices.uc
|
||||
msgid "Unknown device."
|
||||
@@ -1365,6 +1460,18 @@ msgstr "Не больше %s символов."
|
||||
msgid "Uploaded"
|
||||
msgstr "Отправлено"
|
||||
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
msgid "V2RayTun needs administrator rights for this mode: it offers to restart with them."
|
||||
msgstr "Для этого режима V2RayTun нужны права администратора: приложение предложит перезапуститься с ними."
|
||||
|
||||
#: web/src/portal/flows/setup-parts.ts
|
||||
msgid "V2RayTun reaches the server by its IP address, not its hostname: if the address changes, add the connection again."
|
||||
msgstr "V2RayTun подключается к серверу по IP-адресу, а не по доменному имени: если адрес сменится, добавьте подключение заново."
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgid "V2RayTun’s own channel: news and updates of the app."
|
||||
msgstr "Канал самого V2RayTun: новости и обновления приложения."
|
||||
|
||||
#: web/src/portal/flows/wait.ts
|
||||
msgid "Waiting for the connection"
|
||||
msgstr "Ждём подключения"
|
||||
@@ -1373,7 +1480,7 @@ msgstr "Ждём подключения"
|
||||
msgid "Warning must be 0-60 days."
|
||||
msgstr "Предупреждать можно за 0–60 дней."
|
||||
|
||||
#: web/src/portal/flows/add.ts
|
||||
#: web/src/portal/flows/device-form.ts
|
||||
msgid "What is it?"
|
||||
msgstr "Что это за устройство?"
|
||||
|
||||
@@ -1419,6 +1526,10 @@ msgstr "Ваш доступ закончился."
|
||||
msgid "Your access is paused."
|
||||
msgstr "Ваш доступ на паузе."
|
||||
|
||||
#: web/src/portal/page/access.ts
|
||||
msgid "Your data this month"
|
||||
msgstr "Ваш трафик за месяц"
|
||||
|
||||
#: web/src/portal/page/devices.ts
|
||||
msgid "Your devices"
|
||||
msgstr "Ваши устройства"
|
||||
@@ -1435,7 +1546,7 @@ msgstr "Ваши устройства не подключатся, пока до
|
||||
msgid "Your devices can’t connect until it’s resumed."
|
||||
msgstr "Ваши устройства не подключатся, пока доступ не возобновят."
|
||||
|
||||
#: web/src/portal/flows/add.ts
|
||||
#: web/src/portal/flows/device-form.ts
|
||||
msgid "Your local network stays reachable while connected."
|
||||
msgstr "Ваша локальная сеть остаётся доступной при подключении."
|
||||
|
||||
@@ -1443,6 +1554,14 @@ msgstr "Ваша локальная сеть остаётся доступной
|
||||
msgid "Your network may be blocking the connection."
|
||||
msgstr "Возможно, ваша сеть блокирует подключение."
|
||||
|
||||
#: web/src/shared/pace.ts
|
||||
msgid "about %s by the reset on %s"
|
||||
msgstr "около %s к сбросу %s"
|
||||
|
||||
#: web/src/portal/page/access.ts
|
||||
msgid "about average"
|
||||
msgstr "около среднего"
|
||||
|
||||
#: web/src/shared/format.ts
|
||||
msgid "bit/s"
|
||||
msgstr "бит/с"
|
||||
@@ -1491,6 +1610,13 @@ msgstr "закончится сегодня"
|
||||
msgid "ends tomorrow"
|
||||
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"
|
||||
|
||||
#: web/src/shared/format.ts
|
||||
msgid "just now"
|
||||
msgstr "только что"
|
||||
@@ -1511,6 +1637,14 @@ msgstr "никогда"
|
||||
msgid "no limit"
|
||||
msgstr "без лимита"
|
||||
|
||||
#: web/src/portal/page/devices.ts
|
||||
msgid "not used"
|
||||
msgstr "без трафика"
|
||||
|
||||
#: web/src/portal/page/access.ts
|
||||
msgid "opens in %s"
|
||||
msgstr "откроется через %s"
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgid "phone"
|
||||
msgstr "телефон"
|
||||
@@ -1529,6 +1663,10 @@ msgctxt "on the"
|
||||
msgid "router"
|
||||
msgstr "роутере"
|
||||
|
||||
#: web/src/portal/page/access.ts
|
||||
msgid "so far"
|
||||
msgstr "пока"
|
||||
|
||||
#: web/src/portal/setup.ts
|
||||
msgid "tablet"
|
||||
msgstr "планшет"
|
||||
|
||||
@@ -6,14 +6,15 @@
|
||||
// keeps the rows on the page and changes what they hold in place.
|
||||
|
||||
import type { Pair, Person } from '../../shared/types';
|
||||
import { accessLabel, byDeviceState, bytes, date, daysLeft, endsSoon, parseDay } from '../../shared/format';
|
||||
import { accessLabel, byDeviceState, bytes, date, daysLeft, duration, endsSoon, parseDay } from '../../shared/format';
|
||||
import { paceOf, paceWords, vsAverage } from '../../shared/pace';
|
||||
import { fill, fmt, locale, num, plural } from '../../shared/i18n';
|
||||
import { h, ic, markup } from '../dom';
|
||||
import { calendar, clockOf, hoursFor, minuteAt, monthOf, stretches } from '../days';
|
||||
import { SMOOTH, play } from '../motion';
|
||||
import { now, today, type State } from '../state';
|
||||
import { accordion, regrow, type Accordion } from '../ui/accordion';
|
||||
import { bars, upDown } from '../ui/bars';
|
||||
import { bars, readBars, upDown } from '../ui/bars';
|
||||
import { copy } from '../ui/feedback';
|
||||
import { glass } from '../ui/glass';
|
||||
import { morphChanged, morphInto, setText, textOf, textsOf } from '../ui/morph';
|
||||
@@ -107,28 +108,57 @@ function month(p: Person, used: number, pct: number): HTMLElement {
|
||||
const read = upDown('m');
|
||||
const left = p.quota_limit ? fmt(_('%s left'), bytes(Math.max(0, p.quota_limit - used))) : _('No limit');
|
||||
const side = h('span', { class: 'num', 'data-t': 'm-left' }, left);
|
||||
const say = (v: Pair, d?: number) => {
|
||||
read.set(v);
|
||||
setText(side, d ? short(d) : left);
|
||||
side.classList.toggle('bad-t', !d && p.state === 'quota');
|
||||
const totals = series.map(([rx, tx]) => rx + tx);
|
||||
// A picked day says its date and how it compares with the month's other days ("21 Oct · +62%").
|
||||
const against = (i: number) => {
|
||||
if (i === totals.length - 1) return _('so far');
|
||||
const v = vsAverage(totals, i);
|
||||
return Math.abs(v) < 5 ? _('about average') : v > 0 ? `+${num(v)}%` : `−${num(-v)}%`;
|
||||
};
|
||||
say(p.month);
|
||||
const say = (i: number) => {
|
||||
read.set(i >= 0 ? series[i] : p.month);
|
||||
setText(side, i >= 0 ? `${short(i + 1)} · ${against(i)}` : left);
|
||||
side.classList.toggle('bad-t', i < 0 && p.state === 'quota');
|
||||
};
|
||||
say(-1);
|
||||
const chart = bars(series, 'bars-month', 64, days - day);
|
||||
chart.cols.forEach((col, i) => {
|
||||
col.addEventListener('pointerenter', () => say(series[i], i + 1));
|
||||
col.addEventListener('pointerleave', () => say(p.month));
|
||||
});
|
||||
// "Today" under its bar; the month's ends step aside when it comes close.
|
||||
readBars(chart, _('Your data this month'), say);
|
||||
// "Today" under its bar, kept inside the axis; the month's ends step aside where it comes within 6 px of
|
||||
// either of them, measured (the words' widths follow the language and the axis the screen). Until the first
|
||||
// measure, which comes before the first paint: under its bar, and the ends by the day.
|
||||
const td = h('span', { class: 'td' }, _('Today'));
|
||||
td.style.left = pc(day - 0.5, days);
|
||||
const axis = h(
|
||||
const first = h('span', { class: day <= 4 ? 'hide' : '' }, short(1));
|
||||
const last = h('span', { class: day >= days - 3 ? 'hide' : '' }, short(days));
|
||||
const axis = h('div', { class: 'month-axis' }, first, td, last);
|
||||
const fit = () => {
|
||||
const room = axis.clientWidth;
|
||||
const w = td.offsetWidth;
|
||||
if (!room || !w) return;
|
||||
const x = Math.min(Math.max(((day - 0.5) / days) * room, w / 2), room - w / 2);
|
||||
td.style.left = `${x}px`;
|
||||
first.classList.toggle('hide', x - w / 2 < first.offsetWidth + 6);
|
||||
last.classList.toggle('hide', x + w / 2 > room - last.offsetWidth - 6);
|
||||
};
|
||||
// The axis on another width (a phone turned, the card's columns), or the words on theirs (the font arrived).
|
||||
const ro = new ResizeObserver(fit);
|
||||
for (const x of [axis, td, first, last]) ro.observe(x);
|
||||
// With a limit not yet reached: the pace lately (the devices' last 7 days, so the month's first days have one
|
||||
// too) and when the limit fills at it, orange within a week.
|
||||
const pace = paceOf(
|
||||
Array.from({ length: 7 }, (_x, k) => p.devices.reduce((a, d) => a + (d.spark[k]?.[0] ?? 0) + (d.spark[k]?.[1] ?? 0), 0)),
|
||||
);
|
||||
const words = p.quota_limit && used < p.quota_limit ? paceWords(used, p.quota_limit, pace, p.quota_period === 'month', today()) : '';
|
||||
const soon = pace > 0 && (p.quota_limit - used) / pace <= 7;
|
||||
return h(
|
||||
'div',
|
||||
{ class: 'month-axis' },
|
||||
h('span', { class: day <= 4 ? 'hide' : '' }, short(1)),
|
||||
td,
|
||||
h('span', { class: day >= days - 3 ? 'hide' : '' }, short(days)),
|
||||
{ class: 'month' },
|
||||
chart.el,
|
||||
axis,
|
||||
h('div', { class: 'month-read' }, read.el, side),
|
||||
p.quota_limit ? meter(pct) : null,
|
||||
words ? h('div', { class: `month-pace${soon ? ' warn-t' : ''}` }, words) : null,
|
||||
);
|
||||
return h('div', { class: 'month' }, chart.el, axis, h('div', { class: 'month-read' }, read.el, side), p.quota_limit ? meter(pct) : null);
|
||||
}
|
||||
|
||||
/** The days left as a number over a calendar of the weeks to the end (the last day ringed). */
|
||||
@@ -190,6 +220,10 @@ function hoursBar(hours: string, tzOffset: number | undefined): HTMLElement | nu
|
||||
const mark = h('span', { class: `hours-now${inside ? '' : ' out'}`, title: fmt(_('Now, %s'), clockOf(at)) });
|
||||
mark.style.left = pc(at, 1440);
|
||||
bar.appendChild(mark);
|
||||
// How long the window still runs, or until it opens (a stretch may run past midnight: the next starts are a day on).
|
||||
const end = segs.find(([a, b]) => at >= a && at < b)?.[1];
|
||||
const next = Math.min(...segs.map(([a]) => (a > at ? a : a + 1440)));
|
||||
const runs = inside ? fmt(_('%s left'), duration((end! - at) * 60)) : fmt(_('opens in %s'), duration((next - at) * 60));
|
||||
return h(
|
||||
'div',
|
||||
{ class: 'hours' },
|
||||
@@ -205,6 +239,7 @@ function hoursBar(hours: string, tzOffset: number | undefined): HTMLElement | nu
|
||||
{ class: 'hours-axis' },
|
||||
['00', '06', '12', '18', '24'].map((x) => h('span', {}, x)),
|
||||
),
|
||||
h('div', { class: `hours-left${inside ? '' : ' warn-t'}` }, runs),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,13 +11,13 @@ import { fmt, locale, num, plural } from '../../shared/i18n';
|
||||
import { h, ic } from '../dom';
|
||||
import { BOUNCY, EASE_IN, EASE_OUT, SMOOTH, calm, play } from '../motion';
|
||||
import { now, today, type RepaintOpts, type State } from '../state';
|
||||
import { bars, sumDays, upDown } from '../ui/bars';
|
||||
import { bars, readBars, sumDays, upDown } from '../ui/bars';
|
||||
import { copy } from '../ui/feedback';
|
||||
import { glass } from '../ui/glass';
|
||||
import { openMenu, type MenuItem } from '../ui/menu';
|
||||
import { appear, fadeAway, look, morphChanged, morphText, setText, textsOf, type Look } from '../ui/morph';
|
||||
import { startAdd } from '../flows/add';
|
||||
import { reconnect, removeDevice } from '../flows/device-actions';
|
||||
import { reconnect, removeDevice, toggleBypass } from '../flows/device-actions';
|
||||
import { renameOnCard } from '../flows/rename';
|
||||
import { openSetup } from '../flows/setup-view';
|
||||
|
||||
@@ -108,6 +108,10 @@ function menuItems(d: Device, st: State): (MenuItem | null)[] {
|
||||
...(d.disabled
|
||||
? []
|
||||
: [
|
||||
// A setting in a group of its own: on or off now, under it; a tap switches it and opens the set-up of the
|
||||
// updated configuration. Then what is done to the device itself.
|
||||
{ label: _('LAN Bypass'), icon: 'ethernet', sub: d.lan_bypass ? _('On') : _('Off'), run: () => toggleBypass(d) },
|
||||
null,
|
||||
{ label: _('Rename'), icon: 'edit', run: () => renameHere(d) },
|
||||
{ label: _('Reconnect'), icon: 'refresh', tone: 'warn' as const, run: () => reconnect(d) },
|
||||
{ label: _('Remove'), icon: 'trash', tone: 'bad' as const, run: () => removeDevice(d) },
|
||||
@@ -129,17 +133,17 @@ function usage(d: Device): HTMLElement {
|
||||
const val = upDown(d.id);
|
||||
val.set(week);
|
||||
const chart = bars(d.spark, 'bars-week', 34);
|
||||
chart.cols.forEach((col, i) => {
|
||||
const back = d.spark.length - 1 - i;
|
||||
// What the pointer reads off the bars changes at once: no morph while it moves.
|
||||
col.addEventListener('pointerenter', () => {
|
||||
setText(lbl, dayName(back));
|
||||
val.set(d.spark[i]);
|
||||
});
|
||||
col.addEventListener('pointerleave', () => {
|
||||
// What the pointer, a tap or the keys pick changes at once: no morph while it moves. A day with nothing says so.
|
||||
readBars(chart, fmt(_('%s, last 7 days'), d.name), (i) => {
|
||||
if (i < 0) {
|
||||
setText(lbl, _('Last 7 days'));
|
||||
val.set(week);
|
||||
});
|
||||
return;
|
||||
}
|
||||
const [rx, tx] = d.spark[i];
|
||||
const name = dayName(d.spark.length - 1 - i);
|
||||
setText(lbl, rx || tx ? name : `${name} · ${_('not used')}`);
|
||||
val.set(d.spark[i]);
|
||||
});
|
||||
return h('div', { class: 'dev-use' }, h('div', { class: 'use-txt' }, lbl, h('span', { class: 'use-val' }, val.el)), chart.el);
|
||||
}
|
||||
|
||||
+101
-13
@@ -3,13 +3,14 @@
|
||||
|
||||
import type { Kind } from '../shared/types';
|
||||
import { fmt } from '../shared/i18n';
|
||||
import { V2R_WINDOWS } from '../shared/flags';
|
||||
|
||||
export type Platform = 'ios' | 'android' | 'windows' | 'mac' | 'linux' | 'unknown';
|
||||
export type AppId = 'vpn' | 'awg' | 'wg';
|
||||
export type AppId = 'vpn' | 'awg' | 'v2r' | 'wg';
|
||||
/** The server's disguise generation as the portal sees it. */
|
||||
export type Preset = 'off' | 'balanced' | 'max' | 'legacy';
|
||||
|
||||
export const APP_NAME: Record<AppId, string> = { vpn: 'AmneziaVPN', awg: 'AmneziaWG', wg: 'WireGuard' };
|
||||
export const APP_NAME: Record<AppId, string> = { vpn: 'AmneziaVPN', awg: 'AmneziaWG', v2r: 'V2RayTun', wg: 'WireGuard' };
|
||||
|
||||
/** The platform the page is open on. iPadOS Safari calls itself a Mac; touch points tell. */
|
||||
export function platformOf(ua: string, touchPoints = 0): Platform {
|
||||
@@ -45,17 +46,50 @@ export interface AppChoice {
|
||||
name: string;
|
||||
}
|
||||
|
||||
/** The apps that connect to a server with this disguise, the recommended one first; any WireGuard app without one. */
|
||||
/**
|
||||
* The apps that connect to a server with this disguise, in the picker's order:
|
||||
* the tunnel apps first (AmneziaWG; any WireGuard app without a disguise), then
|
||||
* AmneziaVPN and V2RayTun. The sheet opens on the first, AmneziaWG (flows/setup-view.ts).
|
||||
* V2RayTun runs AmneziaWG 2.0 (amneziawg-go 0.2.16 on Android, 0.2.18 on
|
||||
* Windows), not 3.1: Maximum leaves it out.
|
||||
*/
|
||||
export function appsFor(preset: Preset): AppChoice[] {
|
||||
const out: AppChoice[] = [
|
||||
{ id: 'vpn', name: APP_NAME.vpn },
|
||||
{ id: 'awg', name: APP_NAME.awg },
|
||||
];
|
||||
const out: AppChoice[] = [{ id: 'awg', name: APP_NAME.awg }];
|
||||
if (preset === 'off') out.push({ id: 'wg', name: APP_NAME.wg });
|
||||
out.push({ id: 'vpn', name: APP_NAME.vpn });
|
||||
if (preset !== 'max') out.push({ id: 'v2r', name: APP_NAME.v2r });
|
||||
return out;
|
||||
}
|
||||
|
||||
type Mark = 'appstore' | 'googleplay' | 'windows' | 'apple' | 'linux' | 'openwrt' | 'github' | 'site';
|
||||
/**
|
||||
* The apps a device can take. A router takes AmneziaWG or WireGuard (its
|
||||
* packages, one choice each). Anything else takes WireGuard under AmneziaWG's
|
||||
* choice (the same file, code and menus: appName says both). V2RayTun has AmneziaWG in its Android app (phones, tablets,
|
||||
* Android TV) and its Windows app, not on iOS, macOS or Linux (`os`: the
|
||||
* device's own system where the page is open on it, else null). A phone or
|
||||
* something else set up from elsewhere may be on Android; a computer only
|
||||
* where the page is open on it under Windows (its link opens it there), and
|
||||
* only while Windows is on (`windows`, shared/flags.ts V2R_WINDOWS).
|
||||
*/
|
||||
export function appsOn(kind: Kind, apps: AppChoice[], os: Platform | null = null, windows = V2R_WINDOWS): AppChoice[] {
|
||||
return apps.filter((a) => {
|
||||
if (kind === 'router') return a.id !== 'vpn' && a.id !== 'v2r';
|
||||
if (a.id === 'wg') return false;
|
||||
if (a.id !== 'v2r') return true;
|
||||
if (os === 'android' || (windows && os === 'windows')) return true;
|
||||
return os === null && kind !== 'computer';
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* An app's name in a sentence: with the disguise off (`wgToo`), AmneziaWG's
|
||||
* choice is WireGuard's too ("AmneziaWG or WireGuard"), as their apps take the
|
||||
* same file and code through the same menus.
|
||||
*/
|
||||
export const appName = (app: AppId, wgToo = false): string =>
|
||||
wgToo && app === 'awg' ? fmt(_('%s or %s'), APP_NAME.awg, APP_NAME.wg) : APP_NAME[app];
|
||||
|
||||
type Mark = 'appstore' | 'googleplay' | 'windows' | 'apple' | 'linux' | 'openwrt' | 'github' | 'telegram' | 'site';
|
||||
|
||||
export interface Store {
|
||||
href: string;
|
||||
@@ -63,11 +97,19 @@ export interface Store {
|
||||
top: string;
|
||||
main: string;
|
||||
mark: Mark;
|
||||
/** A second source shown beside the first, where the store can fail (Android). */
|
||||
/** A second source shown beside the first: where the store can fail (Android), or the app's own channel. */
|
||||
alt?: { href: string; top: string; main: string; mark: Mark; why: string };
|
||||
}
|
||||
|
||||
const GH_CLIENT = 'https://github.com/amnezia-vpn/amnezia-client/releases/latest';
|
||||
/** V2RayTun's channel (linked from v2raytun.com): its news and updates, beside its store. */
|
||||
const v2rChannel = (): NonNullable<Store['alt']> => ({
|
||||
href: 'https://t.me/v2raytun',
|
||||
top: _('Channel on'),
|
||||
main: 'Telegram',
|
||||
mark: 'telegram',
|
||||
why: _('V2RayTun’s own channel: news and updates of the app.'),
|
||||
});
|
||||
const apk = (href: string): NonNullable<Store['alt']> => ({
|
||||
href,
|
||||
top: _('APK file on'),
|
||||
@@ -118,6 +160,24 @@ export function storeFor(app: AppId, platform: Platform): Store | null {
|
||||
},
|
||||
linux: { href: 'https://github.com/amnezia-vpn/amneziawg-tools', top: _('On GitHub'), main: 'amneziawg-tools', mark: 'linux' },
|
||||
},
|
||||
v2r: {
|
||||
android: {
|
||||
href: 'https://play.google.com/store/apps/details?id=com.v2raytun.android',
|
||||
top: onPlay,
|
||||
main: 'Google Play',
|
||||
mark: 'googleplay',
|
||||
// Its site's Android download is this store page too: the channel goes beside it.
|
||||
alt: v2rChannel(),
|
||||
},
|
||||
// The installer the official site (v2raytun.com) links to.
|
||||
windows: {
|
||||
href: 'https://storage.v2raytun.com/v2RayTun_Setup.exe',
|
||||
top: _('Download from'),
|
||||
main: 'v2raytun.com',
|
||||
mark: 'windows',
|
||||
alt: v2rChannel(),
|
||||
},
|
||||
},
|
||||
wg: {
|
||||
ios: { href: 'https://apps.apple.com/app/wireguard/id1441195209', top: onAppStore, main: 'App Store', mark: 'appstore' },
|
||||
android: {
|
||||
@@ -179,16 +239,42 @@ function tunnelMenu(platform: Platform): { file: string; qr?: string } | undefin
|
||||
return menus[platform];
|
||||
}
|
||||
|
||||
/*
|
||||
* V2RayTun, read from its apps in November 2026 (its sources are closed).
|
||||
* Android 5.26.83: the + at the top of its server list (menu_main); both items
|
||||
* hand the text to one importer, which takes an amneziawg:// or awg:// link or a .conf.
|
||||
* Windows (the Flutter app of v2RayTun_Setup.exe, read from its Dart snapshot):
|
||||
* a + (tooltip "Import") at the top of the connection screen opens Import from
|
||||
* clipboard, Type manually, Import from file, Import from QR code (an image
|
||||
* file) and Import from phone. The clipboard takes an awg:// link (its parser
|
||||
* refuses the amneziawg:// scheme) or a whole .conf;
|
||||
* "Import from file" offers .txt and .json only and reads them line by line,
|
||||
* a link a line. AmneziaWG runs there in its Tunnel mode (or Proxy + Tunnel),
|
||||
* picked under "Mode" on the same screen.
|
||||
*/
|
||||
const v2rScan = () => menu('+', _('Import config from QRcode', 'V2RayTun app'));
|
||||
const v2rImport = (platform: Platform) =>
|
||||
menu('+', platform === 'windows' ? _('Import from clipboard', 'V2RayTun app') : _('Import config from Clipboard', 'V2RayTun app'));
|
||||
|
||||
/** V2RayTun's mode AmneziaWG needs on Windows, in its own words (it restarts as administrator for it). */
|
||||
export const v2rTunnelMode = () => _('Tunnel', 'V2RayTun app');
|
||||
|
||||
/** Where the app scans a code; a phone of either kind gets both wordings. */
|
||||
export function scanPath(app: AppId, platform: Platform = 'unknown'): string {
|
||||
if (app === 'vpn') return menu('+', _('QR code', 'AmneziaVPN app'));
|
||||
if (app === 'v2r') return v2rScan();
|
||||
const qr = tunnelMenu(platform)?.qr;
|
||||
return qr ?? fmt(_('%s (Android: %s)'), tunnelMenu('ios')!.qr, tunnelMenu('android')!.qr!.replace(/^.* → /, ''));
|
||||
}
|
||||
|
||||
/** Where the app takes a file (AmneziaVPN: the key, pasted by its Insert button); elsewhere, the Android app's words. */
|
||||
/**
|
||||
* Where the app takes the connection: a file, or what is copied (AmneziaVPN:
|
||||
* the key, pasted by its Insert button; V2RayTun: the link, from the
|
||||
* clipboard); elsewhere, the Android app's words.
|
||||
*/
|
||||
export function importPath(app: AppId, platform: Platform = 'unknown'): string {
|
||||
if (app === 'vpn') return menu('+', _('Insert', 'AmneziaVPN app'));
|
||||
if (app === 'v2r') return v2rImport(platform);
|
||||
return (tunnelMenu(platform) ?? tunnelMenu('android')!).file;
|
||||
}
|
||||
|
||||
@@ -198,18 +284,20 @@ export const vpnContinue = () => fmt(_('Tap “%s” and connect'), _('Continue'
|
||||
/**
|
||||
* The file into the app, step by step: [text, the part in bold]. Linux has no
|
||||
* app, only the tools: the file goes up straight from where it was saved
|
||||
* (its name is a valid interface name, see tunnel_name on the router).
|
||||
* (its name is a valid interface name, see tunnel_name on the router); with
|
||||
* the disguise off (`wgToo`) wireguard-tools' wg-quick takes it too.
|
||||
*/
|
||||
export function importSteps(app: AppId, platform: Platform, file: string, shared: boolean): [string, string][] {
|
||||
export function importSteps(app: AppId, platform: Platform, file: string, shared: boolean, wgToo = false): [string, string][] {
|
||||
if (platform === 'linux')
|
||||
return [
|
||||
[_('Open a terminal in the folder with the file'), ''],
|
||||
// The command comes after the word, in bold: "Run sudo awg-quick up …".
|
||||
[`${_('Run')} `, `sudo ${app === 'wg' ? 'wg-quick' : 'awg-quick'} up ./${file}`],
|
||||
...(wgToo && app === 'awg' ? ([[`${_('Or, with wireguard-tools,')} `, `sudo wg-quick up ./${file}`]] as [string, string][]) : []),
|
||||
];
|
||||
const path = importPath(app, platform);
|
||||
return [
|
||||
[fmt(_('Open %s', 'step'), APP_NAME[app]), ''],
|
||||
[fmt(_('Open %s', 'step'), appName(app, wgToo)), ''],
|
||||
[path.replace(/ → [^→]*$/, ' → '), path.replace(/^.* → /, '')],
|
||||
[shared ? _('Confirm the import and connect') : _('Pick the file and connect'), ''],
|
||||
];
|
||||
|
||||
@@ -158,6 +158,11 @@
|
||||
font-size: 15px;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
.month-pace {
|
||||
font-size: 12px;
|
||||
line-height: 16px;
|
||||
color: var(--text-2);
|
||||
}
|
||||
.meter {
|
||||
height: 6px;
|
||||
border-radius: 3px;
|
||||
@@ -312,6 +317,15 @@
|
||||
.hours-now.out {
|
||||
background: var(--warn);
|
||||
}
|
||||
.hours-left {
|
||||
font-size: 12px;
|
||||
line-height: 16px;
|
||||
color: var(--text-2);
|
||||
}
|
||||
.month-pace.warn-t,
|
||||
.hours-left.warn-t {
|
||||
color: var(--warn);
|
||||
}
|
||||
.hours-axis {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
|
||||
@@ -65,15 +65,24 @@
|
||||
.bars .today .up {
|
||||
background: color-mix(in srgb, var(--accent) 45%, transparent);
|
||||
}
|
||||
.bars .col:not(.future):hover .dn {
|
||||
/* A day under the pointer, or picked by a tap or the keys (.on, ui/bars.ts readBars). */
|
||||
.bars .col:not(.future):is(:hover, .on) .dn {
|
||||
background: var(--text-2);
|
||||
}
|
||||
.bars .col:not(.future):hover .up {
|
||||
.bars .col:not(.future):is(:hover, .on) .up {
|
||||
background: color-mix(in srgb, var(--text-2) 50%, transparent);
|
||||
}
|
||||
.bars .today:hover .dn {
|
||||
.bars .today:is(:hover, .on) .dn {
|
||||
background: color-mix(in srgb, var(--accent) 75%, var(--text));
|
||||
}
|
||||
/* Read with the keys: focus shows as a ring around the bars; the pointer keeps its arrow. */
|
||||
.bars.scrub {
|
||||
outline: none;
|
||||
border-radius: 6px;
|
||||
}
|
||||
.bars.scrub:focus-visible {
|
||||
box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 55%, transparent);
|
||||
}
|
||||
.bars .future i {
|
||||
height: 3px;
|
||||
background: color-mix(in srgb, var(--bar) 45%, transparent);
|
||||
|
||||
@@ -97,6 +97,15 @@
|
||||
.btn.red:hover {
|
||||
background: color-mix(in srgb, var(--bad) 82%, transparent);
|
||||
}
|
||||
/* Reconnect: the warn colour it has in the ⋯ menu and on the card's status. Dark ink: white on it reads at 2.3:1. */
|
||||
.btn.warn {
|
||||
background: var(--warn);
|
||||
color: #241300;
|
||||
font-weight: 600;
|
||||
}
|
||||
.btn.warn:hover {
|
||||
background: color-mix(in srgb, var(--warn) 82%, transparent);
|
||||
}
|
||||
/* Waiting for the router: the button keeps its size, its content blurs away and an orb comes up in
|
||||
its place (ui/busy.ts runs the change). The orb is B4 Converge from aicss.dev's Orbs, at its own
|
||||
28px stage and twice its speed: one circle walks a triangle, sharp at each corner and smaller,
|
||||
@@ -510,12 +519,43 @@
|
||||
opacity: 1;
|
||||
margin-left: 0;
|
||||
}
|
||||
/* A name wider than its place (ui/seg.ts marquee): it fades to nothing at the edge it runs past, the right one
|
||||
at its start, the left one at its end, the fade sliding across as the name glides. */
|
||||
@property --fade-l {
|
||||
syntax: '<length>';
|
||||
inherits: false;
|
||||
initial-value: 0px;
|
||||
}
|
||||
@property --fade-r {
|
||||
syntax: '<length>';
|
||||
inherits: false;
|
||||
initial-value: 0px;
|
||||
}
|
||||
.appseg .seg-l {
|
||||
-webkit-mask-image: linear-gradient(to right, transparent, #000 var(--fade-l), #000 calc(100% - var(--fade-r)), transparent);
|
||||
mask-image: linear-gradient(to right, transparent, #000 var(--fade-l), #000 calc(100% - var(--fade-r)), transparent);
|
||||
transition:
|
||||
--fade-l 320ms var(--ease-out),
|
||||
--fade-r 320ms var(--ease-out);
|
||||
}
|
||||
.appseg .seg-l.clip {
|
||||
--fade-r: 18px;
|
||||
}
|
||||
.appseg .seg-l.clip.end {
|
||||
--fade-l: 18px;
|
||||
--fade-r: 0px;
|
||||
}
|
||||
.appseg .seg-t {
|
||||
display: inline-block;
|
||||
}
|
||||
/* Three apps on a phone: the icons take less room, so the picked one's name fits whole. */
|
||||
.appseg {
|
||||
container-type: inline-size;
|
||||
}
|
||||
/* The pill takes the narrow width too: a container query reaches only what is inside the track, never the track
|
||||
itself, so --b is set on the pill (on .appseg it would stay 56 and the pill fall short of its item). */
|
||||
@container (max-width: 300px) {
|
||||
.appseg {
|
||||
.appseg .seg-pill {
|
||||
--b: 44px;
|
||||
}
|
||||
.appseg .seg-b {
|
||||
@@ -770,11 +810,19 @@
|
||||
background: var(--accent-soft);
|
||||
color: var(--accent);
|
||||
}
|
||||
/* Two side by side while each has room for its words on one line (a store's name never wraps); else one under
|
||||
the other. */
|
||||
.badges2 {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
|
||||
gap: 8px;
|
||||
}
|
||||
.badges2 .b-top,
|
||||
.badges2 .b-main {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.badges2 .badge {
|
||||
padding: 0 10px;
|
||||
gap: 10px;
|
||||
|
||||
@@ -439,6 +439,12 @@
|
||||
align-items: baseline;
|
||||
column-gap: 0.3em;
|
||||
}
|
||||
/* The scan line and, for V2RayTun reached by IP, the line under it. */
|
||||
.scanwrap {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
.scanline .osm {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
import type { Pair } from '../../shared/types';
|
||||
import { bytes } from '../../shared/format';
|
||||
import { scrub } from '../../shared/scrub';
|
||||
import { h, ic } from '../dom';
|
||||
import { setText } from './morph';
|
||||
|
||||
@@ -57,6 +58,27 @@ export function bars(days: Pair[], cls: string, height: number, future = 0): Bar
|
||||
return { el, cols };
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the bars a day at a time (shared/scrub.ts): the pointer, a tap that stays
|
||||
* until a tap elsewhere, ← → with the chart focused. The picked column looks as
|
||||
* under the pointer (.on); `pick` gets its index, -1 when let go.
|
||||
*/
|
||||
export function readBars(b: Bars, label: string, pick: (i: number) => void): void {
|
||||
b.el.removeAttribute('aria-hidden');
|
||||
scrub(
|
||||
b.el,
|
||||
{
|
||||
indexAt: (x) =>
|
||||
b.cols.findIndex((c) => {
|
||||
const r = c.getBoundingClientRect();
|
||||
return x >= r.left && x < r.right;
|
||||
}),
|
||||
mark: (i) => b.cols.forEach((c, k) => c.classList.toggle('on', k === i)),
|
||||
},
|
||||
{ count: () => b.cols.length, pick, label },
|
||||
);
|
||||
}
|
||||
|
||||
export interface UpDown {
|
||||
el: HTMLElement;
|
||||
/** Show these, at once (a repaint morphs them by their keys). */
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
// they stay right while the sheet around them changes width. At rest the pill
|
||||
// stands where CSS puts it (its item's place among the others: controls.css), so
|
||||
// a sheet changing width, a phone turned, carry it along with nothing to watch;
|
||||
// only a pick moves it from here.
|
||||
// only a pick moves it from here. A name wider than its place fades out at
|
||||
// the edge it runs past and glides to its end on hover (marquee()).
|
||||
|
||||
import { h, ic } from '../dom';
|
||||
import { EASE_OUT, LEAD, SMOOTH, calm, play } from '../motion';
|
||||
@@ -42,21 +43,104 @@ export function labelFade(at: LabelAt, picked: boolean): { duration: number; del
|
||||
return { duration: left > 0.01 ? 220 * left : 0, delay: 0 };
|
||||
}
|
||||
|
||||
/** How fast a name too long for its place glides to its end (px/s): slow enough to read along. */
|
||||
const GLIDE_SPEED = 40;
|
||||
/** In and out of the glide, gently at both ends. */
|
||||
const GLIDE_EASE = 'cubic-bezier(.45, 0, .55, 1)';
|
||||
|
||||
interface Marquee {
|
||||
/** Glide to the name's end, or back to its start (`now`: at once). */
|
||||
go(end: boolean, now?: boolean): void;
|
||||
/** At the start, at once (another item picked). */
|
||||
reset(): void;
|
||||
/** At the end: back; at the start: to the end (a tap on the picked item, where there is no hover). */
|
||||
toggle(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* A name in its place (`l`, its words the inline block inside): wider than
|
||||
* the place, it is `.clip` and fades to nothing at the edge it runs past
|
||||
* (controls.css); at its end (`.end`) the fade moves to the other edge. It
|
||||
* glides from where it stands, at GLIDE_SPEED, a beat after the pointer comes.
|
||||
*/
|
||||
function marquee(l: HTMLElement): Marquee {
|
||||
const t = l.firstElementChild as HTMLElement;
|
||||
let atEnd = false;
|
||||
/** The glide under way, if any. */
|
||||
let glide: Animation | null = null;
|
||||
const over = () => Math.max(0, t.offsetWidth - l.clientWidth);
|
||||
/** To the end or the start, from where it stands; `delay` before it sets off (a beat on hover, none to follow a moved end). */
|
||||
function go(end: boolean, now = false, delay = end ? 240 : 0) {
|
||||
const o = end ? over() : 0;
|
||||
atEnd = end && o > 0;
|
||||
l.classList.toggle('end', atEnd);
|
||||
const from = new DOMMatrix(getComputedStyle(t).transform).m41;
|
||||
t.getAnimations().forEach((a) => a.cancel());
|
||||
glide = null;
|
||||
t.style.transform = o ? `translateX(${-o}px)` : '';
|
||||
const dist = Math.abs(-o - from);
|
||||
if (now || dist < 0.5) return;
|
||||
const a = play(t, [{ transform: `translateX(${from}px)` }, { transform: `translateX(${-o}px)` }], {
|
||||
duration: Math.max(420, (dist / GLIDE_SPEED) * 1000),
|
||||
delay,
|
||||
easing: GLIDE_EASE,
|
||||
fill: 'backwards',
|
||||
});
|
||||
glide = a;
|
||||
// The place changed while it glided (a pick still opening it, the sheet still gliding to its width): on to
|
||||
// the end it has now, from where it landed, without a jump.
|
||||
a.onfinish = () => {
|
||||
if (glide !== a) return;
|
||||
glide = null;
|
||||
if (atEnd && Math.abs(over() - o) > 0.5) go(true, false, 0);
|
||||
};
|
||||
}
|
||||
// Its place changes (a pick opens or folds it, the sheet changes width): clipped or not. At its end and still,
|
||||
// it glides to where the end is now (back to the start if it fits); a glide under way corrects when it lands.
|
||||
new ResizeObserver(() => {
|
||||
l.classList.toggle('clip', over() > 0.5);
|
||||
if (atEnd && !glide) go(true, false, 0);
|
||||
}).observe(l);
|
||||
return { go, reset: () => go(false, true), toggle: () => go(!atEnd) };
|
||||
}
|
||||
|
||||
export function iconSeg<T extends string>(items: SegItem<T>[], value: T, onPick: (v: T) => void): IconSeg<T> {
|
||||
const pill = h('span', { class: 'seg-pill' });
|
||||
const el = h('div', { class: 'seg appseg', role: 'tablist' }, pill);
|
||||
// A touch has no hover: a tap on the picked item glides its name instead.
|
||||
let touch = false;
|
||||
const btns = items.map((it) => {
|
||||
const b = h(
|
||||
'button',
|
||||
{ type: 'button', class: 'seg-b', role: 'tab', 'aria-label': it.label, title: it.label, onclick: () => pick(it.value) },
|
||||
{
|
||||
type: 'button',
|
||||
class: 'seg-b',
|
||||
role: 'tab',
|
||||
'aria-label': it.label,
|
||||
title: it.label,
|
||||
onclick: () => (it.value === value ? touch && marquees[btns.indexOf(b)].toggle() : pick(it.value)),
|
||||
},
|
||||
ic(it.icon),
|
||||
h('span', { class: 'seg-l' }, it.label),
|
||||
h('span', { class: 'seg-l' }, h('span', { class: 'seg-t' }, it.label)),
|
||||
);
|
||||
b.dataset.v = it.value;
|
||||
b.addEventListener('pointerdown', (e) => (touch = e.pointerType !== 'mouse'));
|
||||
// The picked item's name glides to its end while the pointer (or the keyboard's focus) is on it.
|
||||
b.addEventListener('pointerenter', (e) => {
|
||||
if (e.pointerType === 'mouse' && b.classList.contains('on')) marquees[btns.indexOf(b)].go(true);
|
||||
});
|
||||
b.addEventListener('pointerleave', (e) => {
|
||||
if (e.pointerType === 'mouse') marquees[btns.indexOf(b)].go(false);
|
||||
});
|
||||
b.addEventListener('focus', () => {
|
||||
if (b.matches(':focus-visible') && b.classList.contains('on')) marquees[btns.indexOf(b)].go(true);
|
||||
});
|
||||
b.addEventListener('blur', () => marquees[btns.indexOf(b)].go(false));
|
||||
el.appendChild(b);
|
||||
return b;
|
||||
});
|
||||
const labelOf = (b: HTMLElement) => b.querySelector('.seg-l') as HTMLElement;
|
||||
const marquees = btns.map((b) => marquee(labelOf(b)));
|
||||
const mark = () =>
|
||||
btns.forEach((b) => {
|
||||
const on = b.dataset.v === value;
|
||||
@@ -102,10 +186,18 @@ export function iconSeg<T extends string>(items: SegItem<T>[], value: T, onPick:
|
||||
return { width: l.getBoundingClientRect().width, opacity: +s.opacity, filter: s.filter, marginLeft: s.marginLeft };
|
||||
});
|
||||
[...btns, ...labels].forEach((x) => x.getAnimations().forEach((a) => a.cancel()));
|
||||
// Every name back at its start; the picked one glides once it has its place, if the pointer is still on it.
|
||||
marquees.forEach((m) => m.reset());
|
||||
window.setTimeout(() => {
|
||||
if (value === v && btns[to].matches(':hover') && !touch) marquees[to].go(true);
|
||||
}, SMOOTH.duration);
|
||||
value = v;
|
||||
mark();
|
||||
// The picked name's whole width, as it will stand once its item has its share.
|
||||
const w1 = labels[to].getBoundingClientRect().width;
|
||||
// The picked name's own width (its words, up to the 180 px CSS gives a picked name), not the room it has
|
||||
// now: the room changes while it opens (AmneziaVPN's dense code widens the sheet), and a width measured
|
||||
// before that would jump to the new room when the animation hands back to CSS. Where there is less room,
|
||||
// the item squeezes the name (it shrinks to its place: controls.css), so the end is where CSS puts it.
|
||||
const w1 = Math.min(180, (labels[to].firstElementChild as HTMLElement).offsetWidth);
|
||||
btns.forEach((b, i) => {
|
||||
const g1 = i === to ? 1 : 0;
|
||||
const f1 = getComputedStyle(b).flexBasis;
|
||||
@@ -184,6 +276,7 @@ export function iconSeg<T extends string>(items: SegItem<T>[], value: T, onPick:
|
||||
sync(v) {
|
||||
if (v === value) return;
|
||||
value = v;
|
||||
marquees.forEach((m) => m.reset());
|
||||
mark();
|
||||
placePill();
|
||||
},
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
// The connection as an `awg://` link, the form V2RayTun imports (its Android
|
||||
// app since 5.24.76 and its Windows app, both with AmneziaWG 2.0):
|
||||
//
|
||||
// awg://<private key>@<host>:<port>?publickey=…&address=…&dns=…#<name>
|
||||
//
|
||||
// Every other line of the .conf goes in as a parameter under its own name in
|
||||
// lower case (PresharedKey → presharedkey, Jc → jc, I1 → i1), its value
|
||||
// percent-encoded; lists lose the spaces after their commas. Made from the
|
||||
// .conf itself, so the link always says what the file says.
|
||||
//
|
||||
// Why awg:// and not amneziawg:// (Android's own export): both apps pick the
|
||||
// AmneziaWG parser for either prefix, but the Windows one (AwgParser.
|
||||
// tryParseAwgUri in its Dart snapshot) then refuses any scheme but "awg", and
|
||||
// the import ends in "Error". Android's parser never looks at the scheme.
|
||||
//
|
||||
// What V2RayTun 5.26.83 reads (its parser, from the APK; Windows reads the
|
||||
// same names): the keys in lower case; jc, jmin, jmax, s1–s4 as whole numbers,
|
||||
// h1–h4 and i1–i5 as text (ranges and tags pass); no AmneziaWG 3.1 keys (its
|
||||
// cores have none). The name is the fragment: a .conf imported there is named
|
||||
// by the clock instead (and "Import from file" reads a file line by line, a
|
||||
// link a line: a .txt with the link imports, a .conf does not). It hands the
|
||||
// endpoint to its core as it is, and its Android core takes no name: `ip`,
|
||||
// where given, goes in place of the server's name. Its Windows core
|
||||
// (amneziawg-windows) resolves the name itself, so there it stays.
|
||||
|
||||
/** AmneziaWG 3.1's own lines (Maximum): V2RayTun's cores (amneziawg-go 0.2.16/0.2.18) have none. */
|
||||
const V31 =
|
||||
/^\s*(HeaderProtectionKey|ContentPaddingAddition|RandomTrailers|DisableCookies|RekeyAfterTime|RekeyTimeout|RejectAfterTime|KeepaliveTimeout|MaxHandshakeAttempts)\s*=/im;
|
||||
|
||||
/** Whether V2RayTun can take this configuration: false for AmneziaWG 3.1 (the Maximum disguise). */
|
||||
export const v2rFits = (conf: string): boolean => !V31.test(conf);
|
||||
|
||||
/** In the order V2RayTun's own export writes them; the disguise after them. */
|
||||
const FIRST = ['publickey', 'address', 'dns', 'mtu', 'presharedkey', 'allowedips', 'persistentkeepalive'];
|
||||
/** Lines that are lists: "1.1.1.1, 1.0.0.1" goes in as "1.1.1.1,1.0.0.1". */
|
||||
const LISTS = new Set(['address', 'dns', 'allowedips']);
|
||||
|
||||
export function awgLink(conf: string, name: string, ip?: string | null): string {
|
||||
const lines = new Map<string, string>();
|
||||
for (const line of conf.split(/\r?\n/)) {
|
||||
const m = /^\s*([A-Za-z0-9]+)\s*=\s*(.*?)\s*$/.exec(line);
|
||||
if (m) lines.set(m[1].toLowerCase(), m[2]);
|
||||
}
|
||||
const priv = lines.get('privatekey') ?? '';
|
||||
// The last colon splits the port off, so a bracketed IPv6 host keeps its own.
|
||||
const ep = lines.get('endpoint') ?? '';
|
||||
const at = ep.lastIndexOf(':');
|
||||
const host = ip ? (ip.includes(':') ? `[${ip}]` : ip) : at > 0 ? ep.slice(0, at) : ep;
|
||||
const port = at > 0 ? ep.slice(at + 1) : '';
|
||||
lines.delete('privatekey');
|
||||
lines.delete('endpoint');
|
||||
const keys = [...FIRST.filter((k) => lines.has(k)), ...[...lines.keys()].filter((k) => !FIRST.includes(k))];
|
||||
const query = keys
|
||||
.map((k) => {
|
||||
const v = lines.get(k)!;
|
||||
return `${k}=${encodeURIComponent(LISTS.has(k) ? v.replace(/,\s+/g, ',') : v)}`;
|
||||
})
|
||||
.join('&');
|
||||
return `awg://${encodeURIComponent(priv)}@${host}${port ? `:${port}` : ''}?${query}#${encodeURIComponent(name)}`;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Features that are built but kept off: each flag says why it is off and what
|
||||
// turns it back on. Read at build time; the admin and the portal share them.
|
||||
|
||||
/**
|
||||
* V2RayTun on Windows (the admin's set-up of a computer, the portal's picker
|
||||
* on a Windows computer). Off since November 2026: its AmneziaWG core
|
||||
* (awgcore.dll from v2RayTun 3.10.15) never gives the tunnel the server's DNS
|
||||
* (main.configureInterface has no SetDNS), so Windows keeps its own DNS, and
|
||||
* with a full tunnel its firewall lets DNS reach the server's DNS alone: no
|
||||
* names at all. Reported to V2RayTun; turn it on once a release fixes it
|
||||
* (check that the tunnel adapter gets the DNS line of the .conf).
|
||||
*/
|
||||
export const V2R_WINDOWS = false;
|
||||
@@ -36,11 +36,17 @@ const P: Record<string, string> = {
|
||||
'<g fill="currentColor" stroke="none" fill-rule="evenodd" transform="scale(.0467)"><path d="M195.7 492.3C196.5 490.2 198.3 483.3 199.6 477.0C205.9 447.1 210.2 441.9 228.7 441.9C234.0 441.9 241.9 442.5 246.2 443.1C254.7 444.3 265.4 444.0 284.6 441.9C301.1 440.2 303.8 440.9 307.4 448.5C310.3 454.6 314.0 467.5 314.0 471.4C314.0 476.0 319.2 488.2 322.7 491.6C329.7 498.7 335.1 493.9 341.0 475.5C341.7 473.3 343.3 469.9 344.5 468.0C345.7 466.1 348.3 461.1 350.2 456.9C360.1 435.6 392.7 402.2 425.2 380.2C431.2 376.1 441.1 365.0 444.5 358.6C446.0 355.8 449.9 349.4 453.2 344.4C460.0 333.9 464.1 323.2 467.4 307.0C470.0 294.9 471.5 289.8 474.8 283.4C481.7 269.8 484.0 246.8 479.6 236.2C474.6 224.1 471.8 193.1 474.1 175.0C475.9 161.2 476.7 149.7 476.0 147.0C475.3 144.1 468.2 140.2 463.6 140.1C455.1 139.9 448.8 133.7 442.5 119.1C440.2 113.8 437.1 107.2 435.7 104.3C432.5 98.0 432.4 95.7 435.0 84.8C439.6 65.1 442.1 18.0 438.5 18.0C436.5 18.0 431.4 26.1 424.2 40.7C408.7 72.1 404.8 76.3 395.0 72.4C390.1 70.4 387.6 66.6 384.0 55.2C382.4 50.5 380.4 46.0 379.3 45.2C376.5 43.1 368.4 44.3 361.3 47.9C353.7 51.8 351.8 51.8 339.5 47.6C317.5 40.2 314.1 39.1 305.0 37.1C276.2 30.5 218.2 30.4 198.0 37.0C188.6 40.1 163.2 52.8 151.2 60.4C142.6 65.9 140.2 67.0 136.6 67.0C132.5 67.0 132.0 67.3 128.0 72.5C123.5 78.3 112.5 89.0 111.0 89.0C109.9 89.0 109.3 86.9 108.4 80.5C107.5 73.4 100.4 52.6 96.6 45.5C90.3 34.0 86.5 28.1 85.5 28.4C81.5 29.5 77.7 67.2 80.1 81.8C80.6 84.9 81.0 94.3 80.9 102.6C80.8 121.3 80.0 123.3 66.7 139.0C63.0 143.3 53.3 163.1 49.5 174.0C43.4 191.5 42.3 196.1 41.1 209.0C40.4 215.9 39.0 228.7 38.0 237.5C34.9 263.0 35.1 270.8 39.0 283.5C40.1 286.8 41.6 292.4 42.5 296.0C46.4 311.3 62.6 345.6 72.4 359.0C90.2 383.5 120.7 409.9 135.1 413.3C139.2 414.3 152.5 423.4 155.3 427.1C157.6 430.2 169.4 454.7 175.0 468.0C186.7 495.8 191.7 501.7 195.7 492.3ZM243.5 407.9C241.3 407.5 237.4 407.1 234.7 407.1C230.6 407.0 229.4 406.5 225.5 402.9C220.2 398.0 220.1 397.6 224.0 389.5C225.6 386.1 227.7 380.3 228.5 376.6C229.4 372.9 230.7 368.2 231.5 366.2C234.2 359.2 237.8 345.5 240.5 332.5C244.8 311.7 249.0 296.7 254.2 284.0C256.1 279.3 258.0 274.3 258.4 272.8C260.1 265.8 264.5 274.9 269.1 294.5C269.7 297.2 271.3 303.1 272.6 307.5C273.9 311.9 275.4 318.2 275.9 321.5C277.1 329.3 285.1 358.9 288.0 366.6C291.3 375.3 291.8 386.5 289.2 391.5C282.5 404.7 262.4 411.9 243.5 407.9ZM184.8 381.8C180.9 377.6 176.4 366.0 173.9 353.6C173.3 350.8 170.3 339.5 167.3 328.5C160.2 302.8 156.8 289.4 151.9 269.0C149.7 259.9 147.0 248.9 145.9 244.5C143.9 236.3 141.8 227.4 137.5 209.0C136.1 203.2 134.2 193.0 133.1 186.2C132.0 179.5 130.8 173.5 130.5 173.0C130.2 172.5 129.5 168.4 128.9 163.8C128.4 159.2 126.8 151.0 125.5 145.5C124.1 140.0 123.0 133.9 123.0 131.9C123.0 130.0 122.5 127.9 121.9 127.3C119.1 124.5 126.3 115.6 137.7 107.7C152.0 97.7 178.7 87.0 203.0 81.5C233.5 74.6 230.5 74.9 262.0 74.8C296.3 74.7 303.8 76.3 327.4 88.2C337.4 93.2 344.8 96.0 348.6 96.0C350.5 96.0 372.4 109.2 379.6 114.7C384.3 118.2 385.6 122.0 384.2 128.2C383.5 130.9 383.0 134.8 383.0 136.8C383.0 138.9 382.5 142.1 382.0 144.0C380.3 149.7 378.2 165.7 377.5 177.0C377.0 186.5 376.4 190.9 373.0 210.5C372.5 213.8 371.7 219.2 371.4 222.5C371.1 225.8 370.2 231.0 369.4 234.0C368.6 237.0 368.0 240.3 368.0 241.5C368.0 242.6 367.2 246.2 366.1 249.5C362.8 259.8 359.8 271.2 358.5 278.5C357.8 282.4 356.3 289.3 355.1 294.0C354.0 298.7 352.4 307.4 351.5 313.5C347.4 343.1 339.0 369.4 330.6 379.5C328.2 382.3 328.1 382.4 326.1 380.6C323.5 378.3 318.4 364.4 311.6 341.5C309.2 333.5 305.8 324.8 300.0 312.4C295.9 303.5 293.0 292.7 293.0 286.3C293.0 282.8 291.5 276.7 288.5 267.6C286.0 260.1 284.0 252.8 284.0 251.4C284.0 249.0 282.9 241.8 279.9 224.6C279.3 221.4 277.5 214.6 275.9 209.6C270.0 191.3 268.1 185.3 265.5 176.8C264.1 171.9 262.6 168.0 262.2 168.0C261.3 168.0 253.1 188.4 249.5 199.5C247.1 207.1 245.0 215.9 241.5 233.5C240.6 237.9 239.3 244.2 238.5 247.5C234.6 264.6 232.9 272.2 231.4 279.5C230.5 283.9 228.0 291.8 225.8 297.0C222.3 305.3 214.6 326.6 199.6 369.8C193.4 387.3 191.4 389.0 184.8 381.8ZM370.4 368.5C370.0 367.6 371.1 362.7 372.9 357.7C378.0 343.2 379.9 335.4 381.5 323.0C383.2 310.2 383.9 306.6 386.8 296.5C391.2 280.9 396.2 258.4 397.1 249.7C397.6 244.7 398.5 239.2 399.0 237.5C399.5 235.8 400.6 230.2 401.5 225.0C402.3 219.8 403.5 213.2 404.0 210.5C404.5 207.8 405.2 203.0 405.6 200.0C405.9 197.0 407.0 191.8 408.0 188.5C409.0 185.2 410.1 179.9 410.5 176.8C411.3 169.8 412.1 169.7 417.4 175.4C424.5 182.9 427.3 189.6 430.0 205.7C435.9 240.1 430.9 279.3 417.1 306.7C415.0 311.0 412.1 317.8 410.6 321.8C407.1 331.5 405.8 333.9 397.9 345.1C384.7 363.8 372.5 374.1 370.4 368.5ZM116.2 361.0C108.1 357.3 94.1 343.1 89.3 333.6C88.5 331.9 85.3 326.7 82.4 322.0C76.7 312.9 65.8 287.4 63.5 277.5C60.9 266.7 63.1 223.5 66.9 210.4C70.4 198.3 86.0 170.5 88.0 172.7C92.4 177.1 99.3 193.3 106.5 216.0C109.0 224.0 112.1 232.3 113.4 234.5C116.9 240.6 120.6 252.8 124.5 271.5C126.4 280.9 129.1 293.9 130.5 300.5C134.9 321.0 134.7 353.9Line truncated
|
||||
wireguard:
|
||||
'<g fill="currentColor" stroke="none" transform="scale(.046875)"><path d="M511.6 248.4S523.4 0 250.4 0C8.9 0 1.4 238.3 1.4 238.3S-34.1 512 255.9 512c278.3 0 255.7-263.6 255.7-263.6M174 161.6c51.2-31.3 116.7-12.2 141.2 34.9 4.6 8.9 5.2 22.7 2.3 32-10.2 32.4-34.2 50.5-67.1 58.2 9.7-8.3 17.4-17.7 19.9-30.8 2.6-12.5-.2-25.5-7.8-35.8-12-16.5-33.4-23-52.6-16-20.3 7.7-31.4 26.2-29.4 49 1.9 21.1 17.9 34.8 47.9 40-4.5 2.4-7.9 4.1-11.3 6-13.7 7.5-25.7 17.9-35.1 30.5-3 4.1-5.1 4.4-9.8 1.6-60.2-36.7-64.1-129.3 1.8-169.6m-45.2 227.9c-9.7 2.5-19.1 6.1-29 9.3 4.8-32.7 43.1-62.8 75.5-59.4-9.4 12.9-14.8 28.3-15.8 44.2-10.7 2.1-20.8 3.4-30.7 5.9M335 70.4c9.6.4 19.2.2 28.8.4 2.4.2 4.8.5 7.1 1-2.1 3.3-4.6 6.4-7.2 9.3-3.4 3.2-7.3 6.3-12.2 1.5-1.2-1.2-4-.9-6.1-.9-9.5-.1-19.1-.4-28.6-.1-8.3.3-16.5 1.1-24.6 2.5-1.5.3-3.8 5.3-3.1 7.2 1.6 4.4 4.1 9.3 7.6 12.1 13.2 10.4 27.3 19.8 40.5 30.1 12.9 10.1 24.9 21.1 32.2 36.3 9.5 19.8 9.8 40.5 5.7 61.4-6.9 34.8-24.5 63.6-53 84.5-11.5 8.4-25.7 13.2-38.8 19.3-11.6 5.3-23.5 9.9-35.1 15.2-20.9 9.5-32.7 32.2-29.2 55.8 3.2 21.6 22.2 39.7 43.9 43.4 26.1 4.5 53-12.5 59.4-39 7.2-29.8-9-56.5-39.4-64.5-1.3-.4-2.7-.7-5.5-1.4 8.1-3.6 15.1-6.2 21.6-9.8 11.3-6.2 22.4-12.8 33.2-19.7 3.2-2 4.9-2 7.7.3 20.9 18 33.3 40.5 36.8 68 5.8 45.5-15.8 87.4-56.4 108.8-62.9 33.2-139.9-4.6-153.8-74.3-11.9-59.7 30.3-113.9 81-124.4 21.8-4.5 41.8-13.6 57.3-30.4 10-10.8 14.9-20.1 16.5-24.4 3.1-7.9 4.7-16.2 4.6-24.7-.3-7.3-2-14.5-5.1-21.2-5.3-12.1-25.6-31.3-30.6-35.3L242.6 120c-1.7-1.4-3.6-1.3-7.7-1-4.9.3-17.4 1-22.8-.4 4.4-3.3 16.2-8.1 21.3-12-15.5-10.5-33.2-6.7-49.4-9.8 3.7-7 22.3-17.7 32.9-18.9-.6-5.9-1.6-11.8-2.9-17.6-.6-2.4-3.3-4.7-5.6-6-5.6-3.3-11.6-6-18-9.3 5.8-3.7 12.5-5.8 19.3-6 6.5-.2 13 .4 19.4 1.9 11.5 2.6 20.7.9 29.8-6.9-7.2-2.9-14.4-5.6-21.4-8.7q-10.35-4.65-20.1-10.5c18.1 2.5 35.7 9.3 54.2 6.8l.5-2.5-42.9-10c25.7-2.4 49.6-2.7 72.2 8.3 6.4 3.1 13 5.7 19.1 9.2 3 1.7 5 5.1 7.4 7.8 1.9 2.1 3.5 4.9 5.9 6.2 9 4.8 19 5 29.2 4.8l.2-3.4c10.2 3.2 21.7 15 21.7 23.6-16.5 0-33.1-.1-49.6.1-1.8 0-3.5 1.3-5.3 2 1.6.9 3.3 2.6 5 2.7m-21.3-24.5c-1.2.7-1.5 2.3-.8 3.5.1.2.3.4.5.6 1 1.8 3.4 2.5 5.2 1.4 1.6-.8 3.2-1.7 5.1-2.7-1.6-1.3-2.8-2.4-4.1-3.5-2.3-1.8-4.1-.7-5.9.7"/></g>',
|
||||
// V2RayTun: its logo, a filled Apple squircle (continuous corners) with V2R in SF Rounded Heavy cut out (256 px art).
|
||||
v2raytun:
|
||||
'<g fill="currentColor" stroke="none" fill-rule="evenodd" transform="scale(.09375)"><path d="M168.4 0C193.6 0 206.2 0 219.8 4.3C234.6 9.7 246.3 21.4 251.7 36.2C256 49.8 256 62.4 256 87.6L256 168.4C256 193.6 256 206.2 251.7 219.8C246.3 234.6 234.6 246.3 219.8 251.7C206.2 256 193.6 256 168.4 256L87.6 256C62.4 256 49.8 256 36.2 251.7C21.4 246.3 9.7 234.6 4.3 219.8C0 206.2 0 193.6 0 168.4L0 87.6C0 62.4 0 49.8 4.3 36.2C9.7 21.4 21.4 9.7 36.2 4.3C49.8 0 62.4 0 87.6 0ZM170 163.9Q166.2 163.9 164 161.6Q161.9 159.4 161.9 155.4L161.9 102.7Q161.9 98.7 164 96.4Q166.2 94.2 170 94.2L190.8 94.2Q199.1 94.2 204.8 96.9Q210.6 99.6 213.5 104.6Q216.5 109.6 216.5 116.6Q216.5 122.7 213.7 127.8Q210.8 132.9 205.4 135.5L214.4 150.8Q215.5 152.6 215.8 153.8Q216.1 155 216.1 156.4Q216.1 159.7 213.8 161.8Q211.5 163.9 208 163.9Q206 163.9 204.6 163.3Q203.3 162.8 202.1 161.4Q201 160 199.6 157.6L189 138.4L178.2 138.4L178.2 155.4Q178.2 159.4 176 161.6Q173.9 163.9 170 163.9ZM71 163.8Q66.1 163.8 63 161.5Q59.9 159.2 58 154L40.3 105.6Q39.5 103.4 39.5 101Q39.5 97.6 41.9 95.4Q44.3 93.2 48.1 93.2Q54.6 93.2 56.5 99.7L71.2 146.6L71.5 146.6L86.1 99.5Q88 93.2 94.2 93.2Q98 93.2 100.3 95.3Q102.6 97.4 102.6 100.8Q102.6 103 101.8 105.1L83.9 154.1Q82.1 159.1 79 161.5Q75.9 163.8 71 163.8ZM113.8 162.8Q109.9 162.8 108 160.8Q106.1 158.9 106.1 155.8Q106.1 153.5 107.1 151.7Q108.2 149.9 110.6 147.8L130.5 129.4Q134.6 125.5 136.9 123Q139.1 120.4 140 118.3Q140.9 116.2 140.9 113.9Q140.9 111.3 139.6 109.3Q138.4 107.3 136.2 106.1Q134 105 131.2 105Q128.7 105 126.7 105.8Q124.8 106.6 123.2 108.2Q121.7 109.8 120.4 112.3Q118.9 114.7 117.3 115.8Q115.7 116.8 113.2 116.8Q110 116.8 108.2 115.1Q106.3 113.3 106.3 110.3Q106.3 108.5 107 106.8Q108.4 102.9 111.7 99.7Q115 96.4 120 94.5Q125 92.6 131.3 92.6Q139 92.6 144.7 95.1Q150.4 97.7 153.5 102.3Q156.7 106.8 156.7 112.8Q156.7 117.2 155.1 120.6Q153.6 124.1 150.2 127.9Q146.9 131.6 141.3 136.7L127.3 149.8L127.3 150.1L151.8 150.1Q154.9 150.1 156.6 151.9Q158.4 153.6 158.4 156.5Q158.4 159.3 156.6 161Q154.9 162.8 151.8 162.8ZM178.2 127L189.2 127Q194.2 127 197 124.3Q199.8 121.6 199.8 116.9Q199.8 112.3 196.9 109.5Q194 106.7 189.1 106.7L178.2 106.7Z"/></g>',
|
||||
// Store and platform marks for the portal's set-up sheet (filled, 512 px art scaled to 24).
|
||||
appstore:
|
||||
'<g fill="currentColor" stroke="none" transform="scale(.046875)"><path d="M401 0H111C49.7 0 0 49.7 0 111v290c0 61.3 49.7 111 111 111h290c61.3 0 111-49.7 111-111V111C512 49.7 462.3 0 401 0M147.8 400.9c-1.3 2.2-2.6 4.5-4 6.6-1.3 2-2.7 3.8-4.4 5.5-3.5 3.5-8.1 5.7-13 6.3s-9.9-.4-14.2-2.8c-4.3-2.5-7.6-6.3-9.6-10.9-1.9-4.6-2.2-9.6-1-14.4.6-2.3 1.5-4.4 2.5-6.5 1.2-2.3 2.5-4.5 3.8-6.8l12.5-21.6c30.5-7.9 44 11.1 45.4 13.3zM306.2 341c-.6 2.1-1.3 3.5-1.5 4H102.4c-2.1 0-4.3 0-6.4-.1-2.3-.1-4.6-.4-6.9-1.1-4.8-1.3-8.9-4.2-12-8.2-3-4-4.6-8.8-4.6-13.8s1.6-9.8 4.6-13.8 7.2-6.8 12-8.2c2.3-.6 4.5-.9 6.9-1.1 2.6-.1 5.1-.1 7.7-.1h51.1L229.4 168l-19.2-33.6c-1.3-2.2-2.6-4.5-3.7-6.8-1-2.1-1.9-4.2-2.5-6.6-1.2-4.8-.9-9.9 1-14.5s5.2-8.5 9.5-11 9.2-3.5 14.1-2.9 9.4 2.9 13 6.4c1.7 1.7 3.1 3.5 4.3 5.5 1.4 2.2 2.7 4.4 4 6.7l5.9 10.4 5.9-10.4c1.3-2.2 2.6-4.5 4-6.7 1.3-2 2.7-3.8 4.3-5.5 3.5-3.5 8-5.7 13-6.4 4.9-.6 9.9.4 14.1 2.9 4.3 2.5 7.6 6.3 9.5 11 1.9 4.6 2.2 9.7 1 14.5-.6 2.3-1.5 4.4-2.5 6.6-1.2 2.3-2.5 4.6-3.7 6.8l-93.8 164.3H275c21.8 0 37.6 21.2 31.2 42.3m128.7-5.5c-3 4-7.2 6.8-12 8.2-2.3.6-4.6.9-6.9 1.1-2.2.1-4.3.1-6.5.1h-25.9l18.8 32.7c1.3 2.3 2.6 4.5 3.8 6.8 1.1 2.1 2 4.3 2.5 6.6 1.2 4.9.9 9.9-1 14.6-1.9 4.6-5.3 8.5-9.6 11s-9.3 3.5-14.2 2.9c-5-.6-9.5-2.9-13-6.4-1.7-1.7-3.1-3.5-4.4-5.5-1.4-2.2-2.7-4.4-4-6.7l-81.4-141.8c-7.9-13.7-11-29.7-8.4-45.3 1.8-10.8 6.4-22.6 16.6-33.2l67.7 118h51.3c2.6 0 5.2 0 7.8.1 2.3.1 4.6.4 6.9 1.1 4.8 1.3 9 4.2 12 8.2s4.6 8.8 4.6 13.8-1.7 9.7-4.7 13.7"/></g>',
|
||||
googleplay:
|
||||
'<g fill="currentColor" stroke="none" transform="scale(.046875)"><path d="M241.9 246.7 27.5 35C35.1 14.2 55.1 0 77.4 0h.1c9.6 0 19.1 2.6 27.4 7.5L345 145zM24.6 52.1v409l37.6-37.2L232.3 256l-2.7-2.7-205-202.4zm26.9 453.1c12.4 6.9 26.7 8.6 40.4 4.8 4.3-1.2 8.4-2.9 12.2-5.2l240.4-136.9-102.7-102.4L27.5 477c4.4 12 12.8 21.9 24 28.2M357 151.9 251.3 256.1l81.3 81.1 23.9 23.9 103.2-58.7c25.2-13.2 35-44.5 21.8-69.7-4.9-9.4-11.4-14.6-21.8-21.8"/></g>',
|
||||
// Telegram's paper plane alone, as the other store marks are glyphs alone (Simple Icons' path, CC0), centred and grown.
|
||||
telegram:
|
||||
'<path fill="currentColor" stroke="none" transform="translate(12 12) scale(1.45) translate(-10.9 -12.3)" d="M16.906 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z"/>',
|
||||
github:
|
||||
'<g fill="currentColor" stroke="none" transform="scale(.046875)"><path d="M256 6.3C114.6 6.3 0 120.9 0 262.3c0 113.3 73.3 209 175 242.9 12.8 2.2 17.6-5.4 17.6-12.2 0-6.1-.3-26.2-.3-47.7-64.3 11.8-81-15.7-86.1-30.1-2.9-7.4-15.4-30.1-26.2-36.2-9-4.8-21.8-16.6-.3-17 20.2-.3 34.6 18.6 39.4 26.2 23 38.7 59.8 27.8 74.6 21.1 2.2-16.6 9-27.8 16.3-34.2-57-6.4-116.5-28.5-116.5-126.4 0-27.8 9.9-50.9 26.2-68.8-2.6-6.4-11.5-32.6 2.6-67.8 0 0 21.4-6.7 70.4 26.2 20.5-5.8 42.2-8.6 64-8.6s43.5 2.9 64 8.6c49-33.3 70.4-26.2 70.4-26.2 14.1 35.2 5.1 61.4 2.6 67.8 16.3 17.9 26.2 40.6 26.2 68.8 0 98.2-59.8 120-116.8 126.4 9.3 8 17.3 23.4 17.3 47.4 0 34.2-.3 61.8-.3 70.4 0 6.7 4.8 14.7 17.6 12.2C438.7 471.3 512 375.3 512 262.3c0-141.4-114.6-256-256-256"/></g>',
|
||||
openwrt:
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
// How fast someone uses data lately, and where that leads against their limit,
|
||||
// on the router's calendar; and that in one line of words, which the admin's
|
||||
// meter tooltips and the portal's data row show.
|
||||
|
||||
import { addDays, addMonthsClamped, bytes, dayDiff, parseDay } from './format';
|
||||
import { fmt, locale, num } from './i18n';
|
||||
|
||||
/** Days the pace looks back over. */
|
||||
const SPAN = 7;
|
||||
|
||||
/**
|
||||
* Bytes a day lately: the average of the complete days before today (today is
|
||||
* still running), the last 7 at most. `days` are totals, oldest first, today last.
|
||||
*/
|
||||
export function paceOf(days: number[]): number {
|
||||
const done = days.slice(Math.max(0, days.length - 1 - SPAN), -1);
|
||||
return done.length ? done.reduce((a, v) => a + v, 0) / done.length : 0;
|
||||
}
|
||||
|
||||
/** A day against the average of the complete days (today left out): +62 is 62% over it. */
|
||||
export function vsAverage(days: number[], i: number): number {
|
||||
const done = days.slice(0, -1);
|
||||
const avg = done.reduce((a, v) => a + v, 0) / Math.max(1, done.length);
|
||||
return avg > 0 ? Math.round(((days[i] - avg) / avg) * 100) : 0;
|
||||
}
|
||||
|
||||
export type Forecast =
|
||||
/** At this pace the limit fills in `days`, on `on`. */
|
||||
| { kind: 'fills'; days: number; on: string }
|
||||
/** A monthly limit that holds until the reset on `on`, with about `reach` used by then. */
|
||||
| { kind: 'holds'; on: string; reach: number }
|
||||
/** Nothing to say: no limit, already full, or no use lately. */
|
||||
| { kind: 'none' };
|
||||
|
||||
/**
|
||||
* Where the pace leads: when the limit fills, or (monthly) what is used by the
|
||||
* reset on the 1st when that comes first. `today` is the router's day.
|
||||
*/
|
||||
export function forecast(used: number, limit: number, pace: number, monthly: boolean, today: string): Forecast {
|
||||
if (!limit || used >= limit || pace <= 0) return { kind: 'none' };
|
||||
const days = Math.ceil((limit - used) / pace);
|
||||
const reset = addMonthsClamped(`${today.slice(0, 8)}01`, 1);
|
||||
const on = addDays(today, days);
|
||||
if (monthly && dayDiff(on, reset) >= 0) return { kind: 'holds', on: reset, reach: used + pace * dayDiff(reset, today) };
|
||||
return { kind: 'fills', days, on };
|
||||
}
|
||||
|
||||
/** Where a week at this pace takes them, as a share of the limit (0..100). */
|
||||
export function weekAhead(used: number, limit: number, pace: number): number {
|
||||
return limit ? Math.min(100, ((used + SPAN * pace) / limit) * 100) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The pace in words: "2.1 GB a day lately · full in about 2 days, 4 Nov", or for a
|
||||
* monthly limit the reset comes first: "… · about 36 GB by the reset on 1 Dec".
|
||||
* Empty when there was no use lately.
|
||||
*/
|
||||
export function paceWords(used: number, limit: number, pace: number, monthly: boolean, today: string): string {
|
||||
if (pace <= 0) return '';
|
||||
const base = fmt(_('%s a day lately'), bytes(pace));
|
||||
const f = forecast(used, limit, pace, monthly, today);
|
||||
const on = (d: string) => parseDay(d).toLocaleDateString(locale(), { day: 'numeric', month: 'short' });
|
||||
if (f.kind === 'fills')
|
||||
return `${base} · ${fmt(N_(f.days, 'full in about %s day, %s', 'full in about %s days, %s'), num(f.days), on(f.on))}`;
|
||||
if (f.kind === 'holds') return `${base} · ${fmt(_('about %s by the reset on %s'), bytes(f.reach), on(f.on))}`;
|
||||
return base;
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
// Reading a chart point by point, the same way in the admin UI and the portal:
|
||||
// the pointer picks the point under it, a tap keeps one until a tap elsewhere,
|
||||
// and with the chart focused ← → Home End walk the points (Esc lets go). The
|
||||
// chart marks the picked point; what its numbers are and where they show (the
|
||||
// tile's own head, a tooltip) is the caller's. No drawing and no text here.
|
||||
|
||||
/** A chart that can be read: the point under a pointer, and marking one (-1: none). */
|
||||
export interface Readable {
|
||||
indexAt(clientX: number): number;
|
||||
mark(i: number): void;
|
||||
}
|
||||
|
||||
export interface ScrubOpts {
|
||||
/** How many points; the last is the newest, where the keys start. */
|
||||
count: () => number;
|
||||
/** Point i was picked (-1: let go). */
|
||||
pick: (i: number) => void;
|
||||
/** The chart's name for assistive technology. */
|
||||
label: string;
|
||||
/** A point in words, read out as the keys move. */
|
||||
say?: (i: number) => string;
|
||||
}
|
||||
|
||||
export interface Scrub {
|
||||
/** The points moved under a still pointer (a live chart's new second): pick what is under it now. */
|
||||
refresh(): void;
|
||||
/** The picked point, or -1. */
|
||||
current(): number;
|
||||
}
|
||||
|
||||
/** Wire `host` (the chart's element, or its box) for reading. */
|
||||
export function scrub(host: HTMLElement, chart: Readable, o: ScrubOpts): Scrub {
|
||||
let cur = -1;
|
||||
/** Where a mouse rests over the chart (null: it is not over it), so a moving chart can re-pick under it. */
|
||||
let restX: number | null = null;
|
||||
const words = document.createElement('span');
|
||||
words.className = 'offscreen';
|
||||
words.setAttribute('aria-live', 'polite');
|
||||
host.append(words);
|
||||
host.classList.add('scrub');
|
||||
host.tabIndex = 0;
|
||||
host.setAttribute('role', 'group');
|
||||
host.setAttribute('aria-label', o.label);
|
||||
|
||||
const pick = (i: number, force = false) => {
|
||||
if (i === cur && !force) return;
|
||||
const was = cur;
|
||||
cur = i;
|
||||
chart.mark(i);
|
||||
o.pick(i);
|
||||
if (i >= 0 && i !== was && o.say) words.textContent = o.say(i);
|
||||
// A tap's pick lasts until a tap elsewhere, a scroll or leaving the page section.
|
||||
if (i >= 0 && restX == null) document.addEventListener('pointerdown', away, true);
|
||||
else document.removeEventListener('pointerdown', away, true);
|
||||
};
|
||||
const away = (ev: PointerEvent) => {
|
||||
if (!host.contains(ev.target as Node)) pick(-1);
|
||||
};
|
||||
|
||||
host.addEventListener('pointermove', (ev) => {
|
||||
if (ev.pointerType !== 'mouse') return;
|
||||
restX = ev.clientX;
|
||||
pick(chart.indexAt(ev.clientX));
|
||||
});
|
||||
host.addEventListener('pointerleave', (ev) => {
|
||||
if (ev.pointerType !== 'mouse') return;
|
||||
restX = null;
|
||||
pick(-1);
|
||||
});
|
||||
// No hover on a touch screen: a tap picks, a tap on the same point lets go.
|
||||
host.addEventListener('pointerup', (ev) => {
|
||||
if (ev.pointerType === 'mouse') return;
|
||||
const i = chart.indexAt(ev.clientX);
|
||||
pick(i === cur ? -1 : i);
|
||||
});
|
||||
host.addEventListener('keydown', (ev) => {
|
||||
const n = o.count();
|
||||
if (!n) return;
|
||||
const from = cur < 0 ? n : cur;
|
||||
const to =
|
||||
ev.key === 'ArrowLeft'
|
||||
? Math.max(0, from - 1)
|
||||
: ev.key === 'ArrowRight'
|
||||
? Math.min(n - 1, cur < 0 ? n - 1 : from + 1)
|
||||
: ev.key === 'Home'
|
||||
? 0
|
||||
: ev.key === 'End'
|
||||
? n - 1
|
||||
: ev.key === 'Escape'
|
||||
? -1
|
||||
: null;
|
||||
if (to == null) return;
|
||||
ev.preventDefault();
|
||||
restX = null;
|
||||
pick(to);
|
||||
});
|
||||
host.addEventListener('blur', () => restX == null && pick(-1));
|
||||
|
||||
return {
|
||||
refresh() {
|
||||
if (restX != null) pick(chart.indexAt(restX), true);
|
||||
else if (cur >= 0) pick(Math.min(cur, o.count() - 1), true);
|
||||
},
|
||||
current: () => cur,
|
||||
};
|
||||
}
|
||||
@@ -292,6 +292,8 @@ interface AmneziaFields {
|
||||
server_pub_key: string;
|
||||
persistent_keep_alive: string;
|
||||
obfuscation: Record<string, string>;
|
||||
/** The server's address as an IP, from the portal (null: the name does not resolve; older routers leave it out). */
|
||||
host_ip?: string | null;
|
||||
}
|
||||
|
||||
export interface AwgConfig {
|
||||
|
||||
@@ -135,6 +135,14 @@ describe('a device’s link', () => {
|
||||
'You changed device Phone of Myata · MTU',
|
||||
);
|
||||
});
|
||||
it('says what each option became, and names the portal where a person changed it', () => {
|
||||
expect(deviceChangedText('lan_bypass=on, kind=tablet')).toBe('LAN Bypass on, type: Tablet');
|
||||
expect(deviceChangedText('lan_bypass=off, mtu=1400, keepalive=25')).toBe('LAN Bypass off, MTU 1400, keep-alive 25 s');
|
||||
expect(deviceChangedText('mtu=auto, keepalive=auto')).toBe('MTU: automatic, keep-alive: automatic');
|
||||
const change = ev({ type: 'device_changed', by: 'portal', person: 'p1', device: 'd1', detail: 'kind=phone, lan_bypass=on' });
|
||||
expect(text(eventText({ people }, change))).toBe('Person Myata changed device Phone on their portal · type: Phone, LAN Bypass on');
|
||||
expect(text(eventText({ people }, change, 'p1'))).toBe('Device Phone changed on the portal · type: Phone, LAN Bypass on');
|
||||
});
|
||||
});
|
||||
|
||||
describe('the router’s words', () => {
|
||||
|
||||
@@ -114,3 +114,25 @@ describe('live meter', () => {
|
||||
expect(m.speed('a', 4000).error).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('live meter, a person', () => {
|
||||
it('adds up their devices; a device left out of a second moved nothing', () => {
|
||||
const m = new LiveMeter();
|
||||
const pts: MeterPoint[] = [
|
||||
{ ts: 1001, servers: { a: [30, 60] }, dev: { d1: [10, 20], d2: [20, 40] } },
|
||||
{ ts: 1002, servers: { a: [5, 5] }, dev: { d3: [5, 5] } },
|
||||
// Server a was not read this second: no point for anyone on it.
|
||||
{ ts: 1003, servers: {} },
|
||||
{ ts: 1004, servers: { a: [7, 9] }, dev: { d1: [7, 9] } },
|
||||
];
|
||||
m.take({ meter: meter(pts) }, 0);
|
||||
const s = m.speed('a', 0, ['d1', 'd2']);
|
||||
expect(s.pts).toEqual([
|
||||
[1001, 30, 60],
|
||||
[1002, 0, 0],
|
||||
[1004, 7, 9],
|
||||
]);
|
||||
expect(s).toMatchObject({ rx: 7, tx: 9 });
|
||||
expect(m.speed('a', 0, []).pts.map((p) => p[1])).toEqual([0, 0, 0]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { forecast, paceOf, vsAverage, weekAhead } from '../src/shared/pace';
|
||||
|
||||
const GB = 1024 ** 3;
|
||||
|
||||
describe('pace', () => {
|
||||
it('averages the complete days before today, the last 7 at most', () => {
|
||||
// Ten days, today (999) left out: the 7 before it are 1..7.
|
||||
expect(paceOf([50, 50, 1, 2, 3, 4, 5, 6, 7, 999])).toBe(4);
|
||||
expect(paceOf([3, 5, 100])).toBe(4);
|
||||
expect(paceOf([100])).toBe(0);
|
||||
expect(paceOf([])).toBe(0);
|
||||
});
|
||||
|
||||
it('compares a day with the average, today left out', () => {
|
||||
expect(vsAverage([10, 10, 10, 20, 0], 3)).toBe(60);
|
||||
expect(vsAverage([10, 30, 5], 0)).toBe(-50);
|
||||
expect(vsAverage([0, 0, 5], 2)).toBe(0);
|
||||
});
|
||||
|
||||
it('says when a limit fills at this pace', () => {
|
||||
expect(forecast(46 * GB, 50 * GB, 2 * GB, false, '2026-11-02')).toEqual({ kind: 'fills', days: 2, on: '2026-11-04' });
|
||||
// A monthly limit filling before the 1st is the same.
|
||||
expect(forecast(40 * GB, 50 * GB, 1 * GB, true, '2026-11-15')).toEqual({ kind: 'fills', days: 10, on: '2026-11-25' });
|
||||
});
|
||||
|
||||
it('says what a monthly limit reaches by the reset when that comes first', () => {
|
||||
const f = forecast(12 * GB, 100 * GB, 1 * GB, true, '2026-11-02');
|
||||
expect(f).toEqual({ kind: 'holds', on: '2026-12-01', reach: 41 * GB });
|
||||
});
|
||||
|
||||
it('has nothing to say without a limit, when full or idle', () => {
|
||||
expect(forecast(5, 0, 1, true, '2026-11-02').kind).toBe('none');
|
||||
expect(forecast(10, 10, 1, true, '2026-11-02').kind).toBe('none');
|
||||
expect(forecast(1, 10, 0, true, '2026-11-02').kind).toBe('none');
|
||||
});
|
||||
|
||||
it('takes a week ahead, capped at the limit', () => {
|
||||
expect(weekAhead(10, 100, 1)).toBe(17);
|
||||
expect(weekAhead(90, 100, 5)).toBe(100);
|
||||
expect(weekAhead(5, 0, 1)).toBe(0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { smooth } from '../src/admin/ui/plot';
|
||||
|
||||
/** Every y a path's points and control points reach. */
|
||||
const ys = (d: string) => [...d.matchAll(/(-?[\d.]+),(-?[\d.]+)/g)].map((m) => Number(m[2]));
|
||||
|
||||
describe('smooth line', () => {
|
||||
it('never overshoots its points, so a quiet stretch stays flat', () => {
|
||||
const pts: [number, number][] = [
|
||||
[0, 40],
|
||||
[10, 40],
|
||||
[20, 2],
|
||||
[30, 40],
|
||||
[40, 40],
|
||||
];
|
||||
const y = ys(smooth(pts));
|
||||
expect(Math.min(...y)).toBeGreaterThanOrEqual(2);
|
||||
expect(Math.max(...y)).toBeLessThanOrEqual(40);
|
||||
});
|
||||
|
||||
it('draws one point as a move and nothing as nothing', () => {
|
||||
expect(smooth([[3, 4]])).toBe('M3.0,4.0');
|
||||
expect(smooth([])).toBe('');
|
||||
});
|
||||
});
|
||||
+112
-3
@@ -1,7 +1,10 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { awgLink, v2rFits } from '../src/shared/awglink';
|
||||
import {
|
||||
addLink,
|
||||
appsFor,
|
||||
appName,
|
||||
appsOn,
|
||||
importPath,
|
||||
importSteps,
|
||||
inWebview,
|
||||
@@ -80,9 +83,99 @@ describe('setup', () => {
|
||||
expect(sameDevice('router', 'linux', true)).toBe(false);
|
||||
});
|
||||
|
||||
it('lists the apps a disguise allows, AmneziaVPN first', () => {
|
||||
expect(appsFor('max').map((a) => a.id)).toEqual(['vpn', 'awg']);
|
||||
expect(appsFor('off').map((a) => a.id)).toEqual(['vpn', 'awg', 'wg']);
|
||||
it('lists the apps a disguise allows, the tunnel apps first, V2RayTun short of 3.1', () => {
|
||||
expect(appsFor('max').map((a) => a.id)).toEqual(['awg', 'vpn']);
|
||||
expect(appsFor('balanced').map((a) => a.id)).toEqual(['awg', 'vpn', 'v2r']);
|
||||
expect(appsFor('legacy').map((a) => a.id)).toEqual(['awg', 'vpn', 'v2r']);
|
||||
expect(appsFor('off').map((a) => a.id)).toEqual(['awg', 'wg', 'vpn', 'v2r']);
|
||||
});
|
||||
|
||||
it('offers V2RayTun on Android and Windows only, and a router its packages', () => {
|
||||
// V2RayTun on Windows as when its flag is on (shared/flags.ts); off, below.
|
||||
const ids = (kind: Parameters<typeof appsOn>[0], os: Parameters<typeof appsOn>[2] = null) =>
|
||||
appsOn(kind, appsFor('off'), os, true).map((a) => a.id);
|
||||
expect(ids('router')).toEqual(['awg', 'wg']);
|
||||
expect(ids('computer', 'windows')).toEqual(['awg', 'vpn', 'v2r']);
|
||||
expect(ids('computer', 'mac')).not.toContain('v2r');
|
||||
expect(ids('computer', 'linux')).not.toContain('v2r');
|
||||
expect(ids('computer')).not.toContain('v2r');
|
||||
expect(ids('phone')).toContain('v2r');
|
||||
expect(ids('phone', 'android')).toContain('v2r');
|
||||
expect(ids('phone', 'ios')).not.toContain('v2r');
|
||||
expect(ids('other', 'android')).toContain('v2r');
|
||||
expect(ids('other', 'windows')).toContain('v2r');
|
||||
expect(ids('other', 'mac')).not.toContain('v2r');
|
||||
const off = (kind: Parameters<typeof appsOn>[0], os: Parameters<typeof appsOn>[2]) =>
|
||||
appsOn(kind, appsFor('off'), os, false).map((a) => a.id);
|
||||
expect(off('computer', 'windows')).not.toContain('v2r');
|
||||
expect(off('other', 'windows')).not.toContain('v2r');
|
||||
expect(off('phone', 'android')).toContain('v2r');
|
||||
expect(off('phone', null)).toContain('v2r');
|
||||
expect(storeFor('v2r', 'android')?.href).toContain('com.v2raytun.android');
|
||||
expect(storeFor('v2r', 'android')?.alt?.href).toBe('https://t.me/v2raytun');
|
||||
expect(storeFor('v2r', 'ios')).toBeNull();
|
||||
expect(storeFor('v2r', 'windows')?.href).toBe('https://storage.v2raytun.com/v2RayTun_Setup.exe');
|
||||
expect(storeFor('v2r', 'mac')).toBeNull();
|
||||
expect(importPath('v2r', 'windows')).toBe('+ → Import from clipboard');
|
||||
expect(scanPath('v2r', 'android')).toBe('+ → Import config from QRcode');
|
||||
expect(importPath('v2r')).toBe('+ → Import config from Clipboard');
|
||||
});
|
||||
|
||||
it('writes the .conf as V2RayTun’s awg:// link, word for word as its own', () => {
|
||||
const conf = [
|
||||
'[Interface]',
|
||||
'PrivateKey = To5H+v75ph8CwYDGaWIV+rpmLfig46SzvpJYucuyRp8=',
|
||||
'Address = 10.8.48.141/32',
|
||||
'DNS = 1.1.1.1, 1.0.0.1',
|
||||
'MTU = 1380',
|
||||
'Jc = 6',
|
||||
'Jmin = 40',
|
||||
'Jmax = 1000',
|
||||
'S1 = 67',
|
||||
'S2 = 41',
|
||||
'H1 = 1225345823',
|
||||
'H2 = 1000314123',
|
||||
'H3 = 827179548',
|
||||
'H4 = 962210412',
|
||||
'',
|
||||
'[Peer]',
|
||||
'PublicKey = Aif5mPmmTkPNf3uUOH1TSWnerLIV6hRgxC8oXyqTFDM=',
|
||||
'AllowedIPs = 0.0.0.0/0, ::/0',
|
||||
'Endpoint = hel-01.v2tun.net:51820',
|
||||
'PersistentKeepalive = 25',
|
||||
'',
|
||||
].join('\n');
|
||||
expect(awgLink(conf, '1793854167195')).toBe(
|
||||
'awg://To5H%2Bv75ph8CwYDGaWIV%2BrpmLfig46SzvpJYucuyRp8%3D@hel-01.v2tun.net:51820' +
|
||||
'?publickey=Aif5mPmmTkPNf3uUOH1TSWnerLIV6hRgxC8oXyqTFDM%3D&address=10.8.48.141%2F32&dns=1.1.1.1%2C1.0.0.1' +
|
||||
'&mtu=1380&allowedips=0.0.0.0%2F0%2C%3A%3A%2F0&persistentkeepalive=25&jc=6&jmin=40&jmax=1000&s1=67&s2=41' +
|
||||
'&h1=1225345823&h2=1000314123&h3=827179548&h4=962210412#1793854167195',
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps the preshared key, AmneziaWG 2.0 lines and an IPv6 endpoint in the link', () => {
|
||||
const conf =
|
||||
'[Interface]\nPrivateKey = a/b=\nAddress = 10.0.0.2/32\nS3 = 20\nH1 = 100-200\nI1 = <r 2><b 0x8580>\n\n' +
|
||||
'[Peer]\nPublicKey = c+d=\nPresharedKey = e=\nAllowedIPs = 0.0.0.0/0\nEndpoint = [2001:db8::1]:51820\n';
|
||||
const url = awgLink(conf, 'Home Server');
|
||||
expect(url.startsWith('awg://a%2Fb%3D@[2001:db8::1]:51820?publickey=c%2Bd%3D&address=10.0.0.2%2F32&presharedkey=e%3D&')).toBe(true);
|
||||
expect(url).toContain('&s3=20&h1=100-200&i1=%3Cr%202%3E%3Cb%200x8580%3E');
|
||||
expect(url.endsWith('#Home%20Server')).toBe(true);
|
||||
});
|
||||
|
||||
it('names the server by its IP in the link where one is given (V2RayTun’s core takes no name)', () => {
|
||||
const conf = '[Interface]\nPrivateKey = k=\n\n[Peer]\nPublicKey = p=\nEndpoint = engage.example.eu:4500\n';
|
||||
expect(awgLink(conf, 'Home', '203.0.113.7')).toBe('awg://k%3D@203.0.113.7:4500?publickey=p%3D#Home');
|
||||
expect(awgLink(conf, 'Home', '2001:db8::7')).toContain('@[2001:db8::7]:4500?');
|
||||
expect(awgLink(conf, 'Home', null)).toContain('@engage.example.eu:4500?');
|
||||
});
|
||||
|
||||
it('offers V2RayTun for AmneziaWG 2.0 and plain WireGuard, never for 3.1 (Maximum)', () => {
|
||||
const v2 = '[Interface]\nPrivateKey = k=\nJc = 4\nS3 = 20\nI1 = <r 2>\n\n[Peer]\nPublicKey = p=\n';
|
||||
expect(v2rFits(v2)).toBe(true);
|
||||
expect(v2rFits('[Interface]\nPrivateKey = k=\n')).toBe(true);
|
||||
expect(v2rFits(v2.replace('S3 = 20', 'HeaderProtectionKey = h=\nRandomTrailers = on'))).toBe(false);
|
||||
expect(v2rFits(v2.replace('S3 = 20', 'ContentPaddingAddition = 10-100'))).toBe(false);
|
||||
});
|
||||
|
||||
it('sends people to the store first and to GitHub where no store has the app', () => {
|
||||
@@ -121,6 +214,22 @@ describe('setup', () => {
|
||||
expect(importSteps('wg', 'linux', 'Outline-Home.conf', false)[1][1]).toContain('wg-quick up');
|
||||
});
|
||||
|
||||
it('gives WireGuard AmneziaWG’s choice where the disguise is off, and a router both packages', () => {
|
||||
const ids = (kind: Parameters<typeof appsOn>[0]) => appsOn(kind, appsFor('off'), 'android').map((a) => a.id);
|
||||
expect(ids('phone')).not.toContain('wg');
|
||||
expect(ids('computer')).not.toContain('wg');
|
||||
expect(ids('router')).toEqual(['awg', 'wg']);
|
||||
expect(appName('awg', true)).toBe('AmneziaWG or WireGuard');
|
||||
expect(appName('awg')).toBe('AmneziaWG');
|
||||
expect(appName('vpn', true)).toBe('AmneziaVPN');
|
||||
expect(importSteps('awg', 'mac', 'Home.conf', false, true)[0]).toEqual(['Open AmneziaWG or WireGuard', '']);
|
||||
expect(importSteps('awg', 'linux', 'Home.conf', false, true)[2]).toEqual([
|
||||
'Or, with wireguard-tools, ',
|
||||
'sudo wg-quick up ./Home.conf',
|
||||
]);
|
||||
expect(importSteps('awg', 'linux', 'Home.conf', false)).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('spots in-app browsers', () => {
|
||||
expect(inWebview(`${ANDROID} Telegram-Android/10.0`)).toBe(true);
|
||||
expect(inWebview(IPHONE)).toBe(false);
|
||||
|
||||
Loaded 100 of 101 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user