From 31a2065f0552850c92e94ac822139f6890b823cf Mon Sep 17 00:00:00 2001 From: Aemeath <35622087+tickcount@users.noreply.github.com> Date: Sun, 18 Oct 2026 15:32:27 +0300 Subject: [PATCH] Dawnline 0.6.0 - Access rules fail closed: when the table cannot load, no device is loaded into the tunnels (the firewall alone would let every loaded device reach everything); an older table that survived a failed rebuild keeps its rules and a revoked device still leaves. The agent re-syncs within a minute when the table is gone - A change the router saved but could not put into effect (access rules that did not load, a server that refused its devices) is said in the admin UI instead of a plain "Saved" - The guard judges every packet, not only a connection's first: a change of access, a pause or a limit now cuts open connections too - Each server's home networks are its own: with several servers, "all home" on one no longer reaches the other's networks where firewall zones overlap - People limited to some home networks reach the router only on the addresses in those networks (LuCI and SSH on the main LAN stay closed) - Internet-only people can open their personal portal with the VPN on - Tunnel DNS reaches the resolver and the LAN's DNS from servers that do not forward to those zones on their own (Home-only names on servers without "like a home device", LAN DNS on servers with no home network) - A new personal link offers to remove the devices added through the old one, so a leaked link is really contained - Import and restore refuse an inconsistent file (devices with addresses outside their server, shared addresses, malformed keys, broken references); Health reports one, and the sync leaves such a device out instead of failing its server. A config write that did not reach flash is an error, not a silent success - Backups are kept per kind (nightly ones no longer push out manual or pre-delete ones), nightly and pre-change backups hold the config only, archives are written whole or not at all, and a failed nightly backup is logged. A restore no longer has its history overwritten by the agent's in-memory counters - Settings defaults and ranges come from one place (dawnline.schema) - Portal: anything not shaped like a personal link is answered by a shell before ucode starts (a scan on the root costs nothing); 4 portal processes at once instead of 16; a link may make 40 changes a quarter hour; over plain HTTP the page shows but configurations, new devices and new keys are refused with the HTTPS twin of the link; the connect sheet polls only while the first connection is awaited, with backoff, and stops once the link stopped working - Updates: after Dawnline's own package changes, a shell checks that LuCI reaches it and the agent runs, and puts the kept previous version back when they do not (automatic runs always keep it); the AmneziaWG module reload verifies rmmod and modprobe; installs check free space; on apk a reinstall that changed nothing is an error; uninstall.sh hands the update lock to the removal it calls; an upgrade restarts the service only where it was enabled; the release workflow pins the SDK images by digest and the actions by commit - AmneziaWG: features count only when both the tools and the kernel module have them; a server whose disguise this build cannot run (a 3.1 preset after a rollback to 2.0) is kept down and reported; Components tells 1.0 builds from 2.0 ones; `awg show dump` is parsed by shape; Maximum's DNS-shaped signature packets are made for each server and its keep-alive is a 25-35 s range - CI compiles every ucode file and runs the new tests/ucode unit tests (54 tests on the real libuci) in OpenWrt 24.10 and 25.12 rootfs containers; scripts/compile-ucode.sh does the same wherever ucode runs and scripts/ucode-container.sh locally with docker; lint-ucode checks POSIX regexes and module layering; a tag builds only after CI passes --- .github/workflows/build.yml | 29 ++-- .github/workflows/ci.yml | 81 ++++++++-- AGENTS.md | 11 +- package/luci-app-dawnline/Makefile | 2 +- .../luci-static/resources/dawnline/app.js | 32 ++-- .../root/etc/init.d/dawnline | 4 +- .../root/etc/uci-defaults/90_dawnline | 10 +- .../root/usr/libexec/dawnline/agent | 28 +++- .../root/usr/libexec/dawnline/postupdate | 51 ++++++ .../root/usr/libexec/dawnline/updater | 19 ++- .../share/dawnline/portal/assets/portal.js | 12 +- .../root/usr/share/dawnline/portal/cgi.uc | 22 +++ .../share/dawnline/portal/www/cgi-bin/portal | 64 +++++--- .../root/usr/share/ucode/dawnline/access.uc | 18 ++- .../root/usr/share/ucode/dawnline/apply.uc | 70 ++++++--- .../root/usr/share/ucode/dawnline/awg.uc | 126 ++++++++++++--- .../usr/share/ucode/dawnline/awg_builds.uc | 16 +- .../root/usr/share/ucode/dawnline/backup.uc | 99 ++++++++---- .../root/usr/share/ucode/dawnline/core.uc | 118 +++++++++++--- .../root/usr/share/ucode/dawnline/devices.uc | 12 +- .../root/usr/share/ucode/dawnline/fw.uc | 24 ++- .../root/usr/share/ucode/dawnline/health.uc | 9 +- .../root/usr/share/ucode/dawnline/live.uc | 34 ++-- .../root/usr/share/ucode/dawnline/net.uc | 4 +- .../root/usr/share/ucode/dawnline/netifd.uc | 9 ++ .../root/usr/share/ucode/dawnline/nft.uc | 63 ++++++-- .../root/usr/share/ucode/dawnline/pkg.uc | 48 +++++- .../root/usr/share/ucode/dawnline/portal.uc | 54 ++++++- .../root/usr/share/ucode/dawnline/rpc/home.uc | 16 +- .../usr/share/ucode/dawnline/rpc/people.uc | 30 +++- .../usr/share/ucode/dawnline/rpc/servers.uc | 2 +- .../usr/share/ucode/dawnline/rpc/settings.uc | 8 +- .../root/usr/share/ucode/dawnline/store.uc | 9 +- .../root/usr/share/ucode/dawnline/upd_app.uc | 7 +- .../root/usr/share/ucode/dawnline/upd_awg.uc | 8 +- .../root/usr/share/ucode/dawnline/util.uc | 2 +- .../root/usr/share/ucode/dawnline/view.uc | 1 + rules/backend.md | 3 +- scripts/build-release.sh | 4 +- scripts/check-ucode.sh | 24 +-- scripts/compile-ucode.sh | 30 ++++ scripts/lint-ucode.py | 48 +++++- scripts/ucode-container.sh | 51 ++++++ tests/ucode/awg.test.uc | 90 +++++++++++ tests/ucode/core.test.uc | 138 +++++++++++++++++ tests/ucode/fixtures/awg-dump-1.0.txt | 3 + tests/ucode/fixtures/awg-dump-2.0.txt | 2 + tests/ucode/fixtures/awg-dump-3.1.txt | 3 + tests/ucode/fixtures/bin/awg | 10 ++ tests/ucode/fixtures/config/dawnline | 43 ++++++ tests/ucode/fixtures/config/uhttpd | 8 + tests/ucode/live.test.uc | 47 ++++++ tests/ucode/migrate.test.uc | 44 ++++++ tests/ucode/run.sh | 17 ++ tests/ucode/run.uc | 68 ++++++++ tests/ucode/schema.test.uc | 145 ++++++++++++++++++ tests/ucode/updates.test.uc | 54 +++++++ tests/ucode/util.test.uc | 114 ++++++++++++++ uninstall.sh | 4 + web/package-lock.json | 22 ++- web/package.json | 5 +- web/src/admin/api.ts | 27 ++-- web/src/admin/disguise.ts | 8 +- web/src/admin/pages/person/dialogs.ts | 35 ++++- web/src/admin/styles/dialogs.css | 4 + web/src/admin/widgets/health.ts | 1 + web/src/portal/main.ts | 96 +++++++++++- web/src/shared/types.ts | 7 + web/tsconfig.json | 3 +- web/tsconfig.test.json | 5 + 70 files changed, 2008 insertions(+), 307 deletions(-) create mode 100755 package/luci-app-dawnline/root/usr/libexec/dawnline/postupdate create mode 100755 package/luci-app-dawnline/root/usr/share/dawnline/portal/cgi.uc create mode 100755 scripts/compile-ucode.sh create mode 100755 scripts/ucode-container.sh create mode 100644 tests/ucode/awg.test.uc create mode 100644 tests/ucode/core.test.uc create mode 100644 tests/ucode/fixtures/awg-dump-1.0.txt create mode 100644 tests/ucode/fixtures/awg-dump-2.0.txt create mode 100644 tests/ucode/fixtures/awg-dump-3.1.txt create mode 100755 tests/ucode/fixtures/bin/awg create mode 100644 tests/ucode/fixtures/config/dawnline create mode 100644 tests/ucode/fixtures/config/uhttpd create mode 100644 tests/ucode/live.test.uc create mode 100644 tests/ucode/migrate.test.uc create mode 100755 tests/ucode/run.sh create mode 100644 tests/ucode/run.uc create mode 100644 tests/ucode/schema.test.uc create mode 100644 tests/ucode/updates.test.uc create mode 100644 tests/ucode/util.test.uc create mode 100644 web/tsconfig.test.json diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ec6fe68..a30f492 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,10 +12,19 @@ on: workflow_dispatch: # Read-only by default; only the release job may write (publish the release). +# Everything that runs here is pinned to a digest or a commit: the packages +# it publishes are installed as root on every router with automatic updates +# on, so a re-pointed tag must not be able to change what gets built. permissions: contents: read jobs: + # The same checks as on main (ci.yml), on the tag itself: nothing is built or + # published until they pass. + ci: + name: CI + uses: ./.github/workflows/ci.yml + version: name: Version runs-on: ubuntu-24.04 @@ -23,7 +32,7 @@ jobs: version: ${{ steps.version.outputs.version }} steps: - name: Checkout - uses: actions/checkout@v5 + uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5 with: persist-credentials: false @@ -44,21 +53,21 @@ jobs: build: name: Build ${{ matrix.type }} runs-on: ubuntu-24.04 - needs: version + needs: [version, ci] strategy: fail-fast: true matrix: include: - - { type: ipk, sdk: 'itdoginfo/openwrt-sdk-ipk:24.10.6' } - - { type: apk, sdk: 'itdoginfo/openwrt-sdk-apk:25.12.3' } + - { type: ipk, sdk: 'itdoginfo/openwrt-sdk-ipk:24.10.6@sha256:a6bd28c380b251ebdb1d6d5f83e55ecb0a3c1808b5a8f4841424abc8019a903f' } + - { type: apk, sdk: 'itdoginfo/openwrt-sdk-apk:25.12.3@sha256:6d832008ddd1b8ec4edc84f5e6e0bf22a13ba2d6888083a8e69fa26d752c276f' } steps: - name: Checkout - uses: actions/checkout@v5 + uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5 with: persist-credentials: false - name: Setup Node.js - uses: actions/setup-node@v5 + uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5 with: node-version: '22' cache: npm @@ -77,7 +86,7 @@ jobs: run: scripts/build-packages.sh ${{ matrix.type }} - name: Upload - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 with: name: package-${{ matrix.type }} path: dist/luci-app-dawnline-${{ needs.version.outputs.version }}.${{ matrix.type }} @@ -94,7 +103,7 @@ jobs: steps: # The whole history and the tags: the notes list the commits since the previous tag. - name: Checkout - uses: actions/checkout@v5 + uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5 with: persist-credentials: false fetch-depth: 0 @@ -105,7 +114,7 @@ jobs: cat notes.md - name: Download packages - uses: actions/download-artifact@v4 + uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4 with: pattern: package-* path: release @@ -118,7 +127,7 @@ jobs: cat sha256sums.txt - name: Publish the release - uses: softprops/action-gh-release@v2 + uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2 with: name: Dawnline ${{ github.ref_name }} tag_name: ${{ github.ref_name }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e64e30..7858ea0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,9 +1,12 @@ name: CI +# Every push to main and every pull request; also called by build.yml, so a +# tag never publishes a release without these checks passing on it. on: push: branches: [main] pull_request: + workflow_call: permissions: contents: read @@ -43,6 +46,7 @@ jobs: exit 1 fi + # Sources and the test files (tsconfig.test.json). - name: Type check id: types run: npm run --silent typecheck @@ -51,12 +55,17 @@ jobs: id: tests run: npm test + # The bundles under package/ are committed: a build must change nothing + # and leave no new file behind (an output nobody added to git would be + # missing from the package). - name: Build bundles and check they are committed id: build run: | npm run --silent build - if ! git diff --exit-code -- ../package; then - echo "::error::The committed bundles are out of date. Run 'npm run build' in web/ and commit the result." + changed="$(git status --porcelain --untracked-files=all -- ../package)" + if [ -n "$changed" ]; then + echo "$changed" + echo "::error::The committed bundles are out of date or the build left new files. Run 'npm run build' in web/ and commit the result." exit 1 fi @@ -83,17 +92,25 @@ jobs: with: persist-credentials: false + # Every shell script by its shebang (the init script's is "/bin/sh + # /etc/rc.common"), so a new hotplug or libexec script is covered the + # day it appears. Files without a shebang (keep.d lists) are not shell. - name: ShellCheck run: | shellcheck --version - shellcheck -S warning \ - install.sh \ - uninstall.sh \ - package/luci-app-dawnline/root/etc/init.d/dawnline \ - package/luci-app-dawnline/root/etc/uci-defaults/90_dawnline \ - package/luci-app-dawnline/root/etc/hotplug.d/iface/95-dawnline \ - package/luci-app-dawnline/root/usr/libexec/dawnline/heartbeat \ - scripts/*.sh + files="$(grep -rlIE '^#!(/usr)?/bin/(sh|bash|env (sh|bash))( |$)' \ + install.sh uninstall.sh package/luci-app-dawnline/root scripts tests | sort)" + echo "$files" + for f in package/luci-app-dawnline/root/etc/init.d/dawnline \ + package/luci-app-dawnline/root/etc/hotplug.d/iface/95-dawnline \ + package/luci-app-dawnline/root/usr/libexec/dawnline/resolver \ + package/luci-app-dawnline/root/usr/libexec/dawnline/heartbeat \ + package/luci-app-dawnline/root/usr/libexec/dawnline/postupdate \ + package/luci-app-dawnline/root/usr/share/dawnline/portal/www/cgi-bin/portal; do + echo "$files" | grep -qx "$f" || { echo "::error file=$f::not found by the shebang scan"; exit 1; } + done + # shellcheck disable=SC2086 + shellcheck -S warning $files ucode: name: ucode static checks @@ -104,20 +121,52 @@ jobs: with: persist-credentials: false - - name: Use before definition + - name: Lint (use before definition, exports, POSIX regexes, rpcd methods) run: python3 scripts/lint-ucode.py - name: Executables keep their mode run: | - cd package/luci-app-dawnline/root - for f in usr/bin/dawnline usr/libexec/dawnline/agent usr/libexec/dawnline/updater usr/libexec/dawnline/resolver usr/libexec/dawnline/heartbeat \ - etc/init.d/dawnline etc/uci-defaults/90_dawnline usr/share/dawnline/portal/www/cgi-bin/portal; do + for f in usr/bin/dawnline usr/libexec/dawnline/agent usr/libexec/dawnline/updater usr/libexec/dawnline/resolver usr/libexec/dawnline/heartbeat usr/libexec/dawnline/postupdate \ + etc/init.d/dawnline etc/uci-defaults/90_dawnline usr/share/dawnline/portal/www/cgi-bin/portal usr/share/dawnline/portal/cgi.uc; do + [ -x "package/luci-app-dawnline/root/$f" ] || { echo "::error file=package/luci-app-dawnline/root/$f::not executable (git update-index --chmod=+x $f)"; exit 1; } + done + for f in scripts/check-ucode.sh scripts/compile-ucode.sh scripts/ucode-container.sh tests/ucode/run.sh tests/ucode/fixtures/bin/awg; do [ -x "$f" ] || { echo "::error file=$f::not executable (git update-index --chmod=+x $f)"; exit 1; } done - name: Versions agree run: | v="$(sed -n 's/^PKG_VERSION:=//p' package/luci-app-dawnline/Makefile)" - grep -q "^export const VERSION = '$v';" package/luci-app-dawnline/root/usr/share/ucode/dawnline/util.uc - grep -q "\"version\": \"$v\"" web/package.json + grep -q "^export const VERSION = '$v';" package/luci-app-dawnline/root/usr/share/ucode/dawnline/util.uc || + { echo "::error::util.uc VERSION differs from the Makefile ($v)"; exit 1; } + grep -q "\"version\": \"$v\"" web/package.json || + { echo "::error::web/package.json version differs from the Makefile ($v)"; exit 1; } + python3 - "$v" <<'PY' + import json, sys + v = sys.argv[1] + lock = json.load(open('web/package-lock.json')) + got = (lock.get('version'), lock.get('packages', {}).get('', {}).get('version')) + if got != (v, v): + print(f"::error::web/package-lock.json says {got}, the Makefile {v}: run 'npm install' in web/") + sys.exit(1) + PY echo "Version $v" + + ucode-compile: + # scripts/compile-ucode.sh and tests/ucode on the release's own ucode and + # libuci, in the OpenWrt rootfs containers scripts/ucode-container.sh pins + # by digest (24.10 = opkg, 25.12 = apk: the two the packages are built for). + name: ucode compiles and tests pass (OpenWrt ${{ matrix.release }}) + runs-on: ubuntu-24.04 + strategy: + fail-fast: false + matrix: + release: ['24.10', '25.12'] + steps: + - name: Checkout + uses: actions/checkout@v5 + with: + persist-credentials: false + + - name: Compile every ucode file and run tests/ucode + run: scripts/ucode-container.sh ${{ matrix.release }} diff --git a/AGENTS.md b/AGENTS.md index ae85211..e469334 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -17,13 +17,16 @@ This repo usually sits inside the router-admin workspace (`../AGENTS.md`). Its r - `package/luci-app-dawnline/root/` — what lands on the router: ucode modules in `usr/share/ucode/dawnline/` (`rpc/` for the LuCI backend), the agent and updater in `usr/libexec/dawnline/`, the portal in `usr/share/dawnline/portal/`, the init script, rpcd ACL. - `web/` — TypeScript sources of the admin UI (`src/admin`) and the portal (`src/portal`), shared code in `src/shared`; the built bundles are committed under `package/`. - `install.sh`, `uninstall.sh` — the standalone installer and uninstaller (both have `--dry-run`). -- `scripts/` — `lint-ucode.py`, `check-ucode.sh` (compiles every module on the router without installing), `deploy.sh` (dev deploy over SSH), `build-packages.sh`, `build-release.sh`, `release-notes.sh`. +- `scripts/` — `lint-ucode.py`, `compile-ucode.sh` (compiles every ucode file of a tree wherever ucode runs), `check-ucode.sh` (the same on the router, without installing), `ucode-container.sh` (compile and unit tests in the OpenWrt rootfs containers CI uses), `deploy.sh` (dev deploy over SSH), `build-packages.sh`, `build-release.sh`, `release-notes.sh`. +- `tests/ucode/` — unit tests of the ucode modules (`run.uc` runs every `*.test.uc`; fixtures for `/etc/config` and a stand-in `awg`), run in a container by `run.sh`. ## Checks before a commit or deploy -- `python3 scripts/lint-ucode.py` and `scripts/check-ucode.sh` (needs the router); new ucode entry points are added to the compile list there and to the executables list in `.github/workflows/ci.yml`. -- In `web/`: `npm run format:check`, `npm run typecheck`, `npm test`, `npm run build` — and commit the rebuilt bundles. -- `shellcheck -S warning` for the shell scripts (CI runs it). +- `python3 scripts/lint-ucode.py` (use before definition, exports, POSIX regexes, rpcd methods; layering notes are informational). +- `scripts/ucode-container.sh` (needs docker): compiles every ucode file and runs `tests/ucode` on OpenWrt 24.10 and 25.12, exactly what CI does. `scripts/check-ucode.sh` compiles on the router instead when there is no docker. New ucode entry points are added to the compile list in `scripts/compile-ucode.sh`, to `lint-ucode.py`, and to the executables list in `.github/workflows/ci.yml`; a pure function gets a case in `tests/ucode/.test.uc`. +- In `web/`: `npm run format:check`, `npm run typecheck` (sources and tests), `npm test`, `npm run build` — and commit the rebuilt bundles (CI fails on a changed or new file under `package/`). +- `shellcheck -S warning` for the shell scripts (CI finds them by shebang). +- A tag builds only after CI passes on it (`build.yml` calls `ci.yml`). ## Releases diff --git a/package/luci-app-dawnline/Makefile b/package/luci-app-dawnline/Makefile index 4a7fdb5..1bf146e 100644 --- a/package/luci-app-dawnline/Makefile +++ b/package/luci-app-dawnline/Makefile @@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-dawnline -PKG_VERSION:=0.5.2 +PKG_VERSION:=0.6.0 PKG_RELEASE:=1 PKG_LICENSE:=MIT diff --git a/package/luci-app-dawnline/htdocs/luci-static/resources/dawnline/app.js b/package/luci-app-dawnline/htdocs/luci-static/resources/dawnline/app.js index ce8b695..ad38294 100644 --- a/package/luci-app-dawnline/htdocs/luci-static/resources/dawnline/app.js +++ b/package/luci-app-dawnline/htdocs/luci-static/resources/dawnline/app.js @@ -5,25 +5,25 @@ 'require poll'; 'require rpc'; 'require ui'; -var ur=Object.create;var oo=Object.defineProperty;var mr=Object.getOwnPropertyDescriptor;var hr=Object.getOwnPropertyNames;var fr=Object.getPrototypeOf,gr=Object.prototype.hasOwnProperty;var vr=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var br=(n,e,o,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of hr(e))!gr.call(n,r)&&r!==o&&oo(n,r,{get:()=>e[r],enumerable:!(a=mr(e,r))||a.enumerable});return n};var xr=(n,e,o)=>(o=n!=null?ur(fr(n)):{},br(e||!n||!n.__esModule?oo(o,"default",{value:n,enumerable:!0}):o,n));var go=vr((ho,fo)=>{"use strict";var mo=(function(){var n=function(E,y){var S=236,b=17,x=E,M=o[y],h=null,f=0,R=null,C=[],I={},Q=function(_,A){f=x*4+17,h=(function($){for(var N=new Array($),T=0;T<$;T+=1){N[T]=new Array($);for(var j=0;j<$;j+=1)N[T][j]=null}return N})(f),G(0,0),G(f-7,0),G(0,f-7),q(),z(),de(_,A),x>=7&&X(_),R==null&&(R=U(x,M,C)),fe(R,A)},G=function(_,A){for(var $=-1;$<=7;$+=1)if(!(_+$<=-1||f<=_+$))for(var N=-1;N<=7;N+=1)A+N<=-1||f<=A+N||(0<=$&&$<=6&&(N==0||N==6)||0<=N&&N<=6&&($==0||$==6)||2<=$&&$<=4&&2<=N&&N<=4?h[_+$][A+N]=!0:h[_+$][A+N]=!1)},V=function(){for(var _=0,A=0,$=0;$<8;$+=1){Q(!0,$);var N=r.getLostPoint(I);($==0||_>N)&&(_=N,A=$)}return A},z=function(){for(var _=8;_>$&1)==1;h[Math.floor($/3)][$%3+f-8-3]=N}for(var $=0;$<18;$+=1){var N=!_&&(A>>$&1)==1;h[$%3+f-8-3][Math.floor($/3)]=N}},de=function(_,A){for(var $=M<<3|A,N=r.getBCHTypeInfo($),T=0;T<15;T+=1){var j=!_&&(N>>T&1)==1;T<6?h[T][8]=j:T<8?h[T+1][8]=j:h[f-15+T][8]=j}for(var T=0;T<15;T+=1){var j=!_&&(N>>T&1)==1;T<8?h[8][f-T-1]=j:T<9?h[8][15-T-1+1]=j:h[8][15-T-1]=j}h[f-8][8]=!_},fe=function(_,A){for(var $=-1,N=f-1,T=7,j=0,Y=r.getMaskFunction(A),J=f-1;J>0;J-=2)for(J==6&&(J-=1);;){for(var pe=0;pe<2;pe+=1)if(h[N][J-pe]==null){var be=!1;j<_.length&&(be=(_[j]>>>T&1)==1);var ee=Y(N,J-pe);ee&&(be=!be),h[N][J-pe]=be,T-=1,T==-1&&(j+=1,T=7)}if(N+=$,N<0||f<=N){N-=$,$=-$;break}}},O=function(_,A){for(var $=0,N=0,T=0,j=new Array(A.length),Y=new Array(A.length),J=0;J=0?eo.getAt(to):0}}for(var no=0,ee=0;eeJ*8)throw"code length overflow. ("+T.getLengthInBits()+">"+J*8+")";for(T.getLengthInBits()+4<=J*8&&T.put(0,4);T.getLengthInBits()%8!=0;)T.putBit(!1);for(;!(T.getLengthInBits()>=J*8||(T.put(S,8),T.getLengthInBits()>=J*8));)T.put(b,8);return O(T,N)};I.addData=function(_,A){A=A||"Byte";var $=null;switch(A){case"Numeric":$=d(_);break;case"Alphanumeric":$=p(_);break;case"Byte":$=u(_);break;case"Kanji":$=w(_);break;default:throw"mode:"+A}C.push($),R=null},I.isDark=function(_,A){if(_<0||f<=_||A<0||f<=A)throw _+","+A;return h[_][A]},I.getModuleCount=function(){return f},I.make=function(){if(x<1){for(var _=1;_<40;_++){for(var A=l.getRSBlocks(_,M),$=c(),N=0;N"u"?_*4:A;var $="";$+='";for(var T=0;T';$+=""}return $+="",$+="
",$},I.createSvgTag=function(_,A,$,N){var T={};typeof arguments[0]=="object"&&(T=arguments[0],_=T.cellSize,A=T.margin,$=T.alt,N=T.title),_=_||2,A=typeof A>"u"?_*4:A,$=typeof $=="string"?{text:$}:$||{},$.text=$.text||null,$.id=$.text?$.id||"qrcode-description":null,N=typeof N=="string"?{text:N}:N||{},N.text=N.text||null,N.id=N.text?N.id||"qrcode-title":null;var j=I.getModuleCount()*_+A*2,Y,J,pe,be,ee="",Se;for(Se="l"+_+",0 0,"+_+" -"+_+",0 0,-"+_+"z ",ee+=''+F(N.text)+"":"",ee+=$.text?''+F($.text)+"":"",ee+='',ee+='"u"?_*4:A;var $=I.getModuleCount()*_+A*2,N=A,T=$-A;return B($,$,function(j,Y){if(N<=j&&j"u"?_*4:A;var N=I.getModuleCount()*_+A*2,T="";return T+="",T};var F=function(_){for(var A="",$=0;$<_.length;$+=1){var N=_.charAt($);switch(N){case"<":A+="<";break;case">":A+=">";break;case"&":A+="&";break;case'"':A+=""";break;default:A+=N;break}}return A},oe=function(_){var A=1;_=typeof _>"u"?A*2:_;var $=I.getModuleCount()*A+_*2,N=_,T=$-_,j,Y,J,pe,be,ee={"██":"█","█ ":"▀"," █":"▄"," ":" "},Se={"██":"▀","█ ":"▀"," █":" "," ":" "},_e="";for(j=0;j<$;j+=2){for(J=Math.floor((j-N)/A),pe=Math.floor((j+1-N)/A),Y=0;Y<$;Y+=1)be="█",N<=Y&&Y=T?Se[be]:ee[be];_e+=` -`}return $%2&&_>0?_e.substring(0,_e.length-$-1)+Array($+1).join("▀"):_e.substring(0,_e.length-1)};return I.createASCII=function(_,A){if(_=_||1,_<2)return oe(A);_-=1,A=typeof A>"u"?_*2:A;var $=I.getModuleCount()*_+A*2,N=A,T=$-A,j,Y,J,pe,be=Array(_+1).join("██"),ee=Array(_+1).join(" "),Se="",_e="";for(j=0;j<$;j+=1){for(J=Math.floor((j-N)/_),_e="",Y=0;Y<$;Y+=1)pe=1,N<=Y&&Y>>8),M.push(R&255)):M.push(b)}}return M}};var e={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},o={L:1,M:0,Q:3,H:2},a={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},r=(function(){var E=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],y=1335,S=7973,b=21522,x={},M=function(h){for(var f=0;h!=0;)f+=1,h>>>=1;return f};return x.getBCHTypeInfo=function(h){for(var f=h<<10;M(f)-M(y)>=0;)f^=y<=0;)f^=S<5&&(R+=3+Q-5)}for(var C=0;C=256;)x-=255;return E[x]},b})();function s(E,y){if(typeof E.length>"u")throw E.length+"/"+y;var S=(function(){for(var x=0;x"u")throw"bad rs block @ typeNumber:"+x+"/errorCorrectionLevel:"+M;for(var f=h.length/3,R=[],C=0;C>>7-b%8&1)==1},S.put=function(b,x){for(var M=0;M>>x-M-1&1)==1)},S.getLengthInBits=function(){return y},S.putBit=function(b){var x=Math.floor(y/8);E.length<=x&&E.push(0),b&&(E[x]|=128>>>y%8),y+=1},S},d=function(E){var y=e.MODE_NUMBER,S=E,b={};b.getMode=function(){return y},b.getLength=function(h){return S.length},b.write=function(h){for(var f=S,R=0;R+2>>8&255)*192+(C&255),h.put(C,13),R+=2}if(R>>8)},y.writeBytes=function(S,b,x){b=b||0,x=x||S.length;for(var M=0;M0&&(S+=","),S+=E[b];return S+="]",S},y},m=function(){var E=0,y=0,S=0,b="",x={},M=function(f){b+=String.fromCharCode(h(f&63))},h=function(f){if(!(f<0)){if(f<26)return 65+f;if(f<52)return 97+(f-26);if(f<62)return 48+(f-52);if(f==62)return 43;if(f==63)return 47}throw"n:"+f};return x.writeByte=function(f){for(E=E<<8|f&255,y+=8,S+=1;y>=6;)M(E>>>y-6),y-=6},x.flush=function(){if(y>0&&(M(E<<6-y),E=0,y=0),S%3!=0)for(var f=3-S%3,R=0;R=y.length){if(x==0)return-1;throw"unexpected end of file./"+x}var f=y.charAt(S);if(S+=1,f=="=")return x=0,-1;if(f.match(/^\s$/))continue;b=b<<6|h(f.charCodeAt(0)),x+=6}var R=b>>>x-8&255;return x-=8,R};var h=function(f){if(65<=f&&f<=90)return f-65;if(97<=f&&f<=122)return f-97+26;if(48<=f&&f<=57)return f-48+52;if(f==43)return 62;if(f==47)return 63;throw"c:"+f};return M},H=function(E,y){var S=E,b=y,x=new Array(E*y),M={};M.setPixel=function(C,I,Q){x[I*S+C]=Q},M.write=function(C){C.writeString("GIF87a"),C.writeShort(S),C.writeShort(b),C.writeByte(128),C.writeByte(0),C.writeByte(0),C.writeByte(0),C.writeByte(0),C.writeByte(0),C.writeByte(255),C.writeByte(255),C.writeByte(255),C.writeString(","),C.writeShort(0),C.writeShort(0),C.writeShort(S),C.writeShort(b),C.writeByte(0);var I=2,Q=f(I);C.writeByte(I);for(var G=0;Q.length-G>255;)C.writeByte(255),C.writeBytes(Q,G,255),G+=255;C.writeByte(Q.length-G),C.writeBytes(Q,G,Q.length-G),C.writeByte(0),C.writeString(";")};var h=function(C){var I=C,Q=0,G=0,V={};return V.write=function(z,q){if(z>>>q)throw"length over";for(;Q+q>=8;)I.writeByte(255&(z<>>=8-Q,G=0,Q=0;G=z<0&&I.writeByte(G)},V},f=function(C){for(var I=1<>6,128|i&63):i<55296||i>=57344?a.push(224|i>>12,128|i>>6&63,128|i&63):(r++,i=65536+((i&1023)<<10|o.charCodeAt(r)&1023),a.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|i&63))}return a}return e(n)}})();(function(n){typeof define=="function"&&define.amd?define([],n):typeof ho=="object"&&(fo.exports=n())})(function(){return mo})});function Mn(n,e){return n==null||n===!1||n===""||(Array.isArray(n)?n.forEach(o=>Mn(o,e)):e.push(n instanceof Node?n:String(n))),e}function t(n,e,o){let a=window.E,r=e!=null&&typeof e=="object"&&!Array.isArray(e)&&!(e instanceof Node);return!r&&o===void 0?a(n,{},Mn(e,[])):a(n,r?e:{},Mn(o,[]))}function K(n,e=[]){let o=rpc.declare({object:"luci.dawnline",method:n,params:e});return async(...a)=>{let r=await o(...a);if(r&&typeof r=="object"&&typeof r.error=="string")throw new Error(r.error);return r}}var wr=K("logs_clear",["person","device","category","older_days"]),yr=(n={})=>wr(n.person??"",n.device??"",n.category??"",n.older_days??""),kr=rpc.declare({object:"luci.dawnline",method:"person_update",params:["id","name","access","device_limit","expires","expire_action","expire_warn","quota_gb","quota_period","bonus_gb","hours","note","dns_mode","paused","services","circle","home_nets"]});async function $r(n,e){let a=[n,...["name","access","device_limit","expires","expire_action","expire_warn","quota_gb","quota_period","bonus_gb","hours","note","dns_mode"].map(i=>e[i]),e.paused,e.services,e.circle,e.home_nets],r=await kr(...a);if(r&&typeof r.error=="string")throw new Error(r.error);return r}var Er=K("status",["days"]),P={rev:K("rev"),personUpdate:$r,settingsGet:K("settings_get"),portalInfo:K("portal_info"),settingsUpdate:K("settings_update",["values"]),serviceSet:K("service_set",["id","name","address","ports"]),serviceDelete:K("service_delete",["id"]),geoClear:K("geo_clear"),events:K("events",["limit"]),logsClear:yr,interfaces:K("interfaces",["id"]),serverInterfaces:K("server_interfaces",["id","auto_wan","wan_device","auto_lan","lan_devices","lan_like","device_mesh","mesh"]),circleSet:K("circle_set",["id","server","name","color","members"]),circleDelete:K("circle_delete",["id"]),accessCheck:K("access_check",["from","to"]),homeHosts:K("home_hosts",["id"]),usageClear:K("usage_clear",["scope","id"]),uninstall:K("uninstall",["confirm"]),status:Er,setupDefaults:K("setup_defaults"),serverCreate:K("server_create",["id","name","ifname","port","subnet","endpoint","mtu","preset","lan_zone","wan_zone","lan_like","portal_enabled","portal_port"]),serverObfuscation:K("server_obfuscation",["id","preset"]),serverUpdate:K("server_update",["id","values"]),serverDelete:K("server_delete",["id"]),personLinks:K("person_links",["id"]),personCreate:K("person_create",["name","slug","server","access","device_limit","expires","quota_gb","quota_period"]),personPause:K("person_pause",["id","paused"]),personRegen:K("person_regen",["id"]),personDelete:K("person_delete",["id"]),personUsage:K("person_usage",["id","days"]),deviceCreate:K("device_create",["person","name","kind"]),deviceConfig:K("device_config",["id"]),deviceUpdate:K("device_update",["id","name","disabled"]),deviceDelete:K("device_delete",["id"]),deviceRotate:K("device_rotate",["id"]),apply:K("apply"),health:K("health"),healthFix:K("health_fix",["id"]),serviceLog:K("service_log"),serviceLogClear:K("service_log_clear",["older_days"]),backupList:K("backup_list"),backupCreate:K("backup_create"),backupRestore:K("backup_restore",["name"]),backupDelete:K("backup_delete",["name"]),backupRead:K("backup_read",["name"]),backupUpload:K("backup_upload",["data"]),exportJson:K("export"),importJson:K("import",["data"]),updatesStatus:K("updates_status"),updatesRun:K("updates_run",["what"]),updatesReleases:K("updates_releases",["page"]),updatesNotes:K("updates_notes",["component","tag","build"]),updatesChanges:K("updates_changes",["from","to"])};var ao={phone:'',computer:'',tablet:'',router:'',server:'',other:'',ethernet:'',bridge:'',wifi:'',tunnel:'',plus:'',chart:'',reset:'',package:'',code:'',plug:'',sunrise:'',refresh:'',archive:'',qr:'',copy:'',download:'',link:'',trash:'',edit:'',pause:'',play:'',key:'',out:'',admin:'',shield:'',shieldplus:'',lock:'',zap:'',check:'',alert:'',x:'',globe:'',home:'',open:'',file:'',network:'',moon:'',chevron:'',clock:'',calendar:'',minus:'',more:'',pin:'',activity:''};function $t(n,e="dl-icon"){let o=ao[n]??ao.phone;return``}function v(n,e="dl-icon"){let o=document.createElement("span");return o.className="dl-icon-wrap",o.innerHTML=$t(n,e),o}function Z(n,e="info",o=0){let a=document.querySelector(".dl-toasts");a||(a=t("div",{class:"dl-toasts dl-root",role:"status","aria-live":"polite"}),document.body.appendChild(a));let r=e==="error"?"x":e==="warning"?"alert":e==="success"?"check":null,i=()=>{s.classList.remove("show"),setTimeout(()=>s.remove(),200)},s=t("div",{class:`dl-toast ${e}`},[r?v(r):"",t("span",{},n),e==="error"?t("button",{type:"button","aria-label":"Close",click:i},v("x")):""]);a.appendChild(s),requestAnimationFrame(()=>s.classList.add("show")),setTimeout(i,o||(e==="error"?8e3:e==="warning"?5e3:2600))}function ve(n){return n instanceof Error?n.message:String(n)}async function W(n,e){try{let o=await n();return e&&Z(e,"success",3500),o}catch(o){Z(ve(o),"error",1e4);return}}function ro(n){try{let e=n();e&&typeof e.then=="function"&&e.catch(o=>Z(ve(o),"error"))}catch(e){Z(ve(e),"error")}}function D(n,e,o="neutral",a={}){let{disabled:r,...i}=a,s=t("button",{class:`cbi-button cbi-button-${o}`,type:"button",...i,click:async l=>{if(l.preventDefault(),l.stopPropagation(),!s.disabled){s.disabled=!0,s.classList.add("spinning");try{await e(l)}catch(c){Z(ve(c),"error")}finally{s.disabled=!1,s.classList.remove("spinning")}}}},n);return s.disabled=!!r,s}function $e(n,e,o,a="neutral",r=""){return D([v(n),t("span",{class:"dl-btn-label"},e)],o,a,{title:e,class:`cbi-button cbi-button-${a} dl-icon-btn ${r}`.trim()})}function Ae(n){return document.addEventListener("luci-navigate",n),()=>document.removeEventListener("luci-navigate",n)}var dt=null;function Sn(n=!1){let e=dt;dt=null,e?.(n)}function re(n,e,o,a=""){Sn(),ui.showModal(n,[t("div",{class:`dl-modal ${a}`},e),t("div",{class:"button-row"},o)])}function ce(){Sn(),ui.hideModal()}function le(n="Cancel",e=!1){return t("button",{class:`cbi-button ${e?"cbi-button-negative":"cbi-button-neutral"}`,type:"button",click:ce},n)}function ae(n,e,o="Confirm",a=!1){return new Promise(r=>{re(n,e,[le()," ",t("button",{class:`cbi-button ${a?"cbi-button-negative":"cbi-button-positive"}`,type:"button",click:()=>{let i=dt;dt=null,ui.hideModal(),i?.(!0)}},o)]),dt=r})}Ae(()=>{dt&&(Sn(),ui.hideModal())});async function ue(n,e="Copied to clipboard"){try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(n);else{let o=t("textarea",{style:"position:fixed;opacity:0"},n);document.body.appendChild(o),o.select();let a=document.execCommand("copy");if(o.remove(),!a)throw new Error("Copying is blocked here. Select the text and copy it by hand.")}Z(e,"success",2500)}catch(o){Z(ve(o),"error")}}function Ee(n,e,o="text/plain"){let a=globalThis,r=typeof e=="string"?new a.Blob([e],{type:o}):e,i=URL.createObjectURL(r),s=t("a",{href:i,download:n,style:"display:none"});document.body.appendChild(s),s.click(),setTimeout(()=>{URL.revokeObjectURL(i),s.remove()},1e3)}function _n(n,e){return new Promise(o=>{let a=t("input",{type:"file",accept:n,style:"display:none"});a.addEventListener("cancel",()=>{a.remove(),o(null)}),a.addEventListener("change",()=>{let r=a.files?.[0];if(a.remove(),!r)return o(null);let i=new FileReader;i.onload=()=>{let s=String(i.result??"");o({name:r.name,data:e==="base64"?s.replace(/^data:[^,]*,/,""):s})},i.onerror=()=>o(null),e==="base64"?i.readAsDataURL(r):i.readAsText(r)}),document.body.appendChild(a),a.click()})}function we(n,e){let o=document.querySelector(".dl-dd");if(o&&(o.dlClose?o.dlClose():o.remove(),o.dlAnchor===n))return;let a=t("div",{class:"dl-dd dl-root",role:"menu"},e.map(u=>u?t("button",{type:"button",role:"menuitem",class:u.danger?"danger":u.warn?"warn":"",click:()=>{p(),ro(u.run)}},[u.icon??"",t("span",{},u.label)]):t("hr")));document.body.appendChild(a);let r=n.getBoundingClientRect(),i=a.offsetWidth,s=a.offsetHeight;a.style.top=`${r.bottom+6+s>window.innerHeight-8&&r.top-6-s>8?r.top-6-s:r.bottom+6}px`,a.style.left=`${Math.max(8,Math.min(r.right-i,window.innerWidth-i-8))}px`;let l=u=>{!a.contains(u.target)&&!n.contains(u.target)&&p()},c=u=>{u.key==="Escape"&&p()},d=Ae(p);a.dlAnchor=n,a.dlClose=p;function p(){a.remove(),d(),document.removeEventListener("mousedown",l,!0),document.removeEventListener("keydown",c,!0),window.removeEventListener("scroll",p,!0)}setTimeout(()=>{document.addEventListener("mousedown",l,!0),document.addEventListener("keydown",c,!0),window.addEventListener("scroll",p,!0)}),a.querySelector("button")?.focus({preventScroll:!0})}var et=null,tt=null,Tn=0;function Et(){et&&(et.style.display="none"),tt=null,clearInterval(Tn),Tn=0}function me(n,e){let o=a=>{et??(et=document.body.appendChild(t("div",{class:"dl-tip dl-tip-float dl-root"}))),et.replaceChildren(...e().map(r=>typeof r=="string"?document.createTextNode(r):r)),et.style.display="",et.style.left=`${a.clientX}px`,et.style.top=`${a.clientY-10}px`,tt=n,Tn||(Tn=window.setInterval(()=>{(!tt?.isConnected||!tt.getClientRects().length)&&Et()},400))};n.addEventListener("mouseenter",o),n.addEventListener("mousemove",o),n.addEventListener("mouseleave",Et)}Ae(Et);window.addEventListener("scroll",()=>tt&&Et(),{capture:!0,passive:!0});document.addEventListener("pointerdown",n=>{tt&&!tt.contains(n.target)&&Et()},!0);function te(n){if(!n||n<0)return"0 B";let e=["B","KB","MB","GB","TB"],o=0,a=n;for(;a>=1024&&o=100||o===0?Math.round(a):a.toFixed(1)} ${e[o]}`}function ze(n){let e=n*8;return e<1e3?`${Math.round(e)} bit/s`:e<1e6?`${(e/1e3).toFixed(e<1e4?1:0)} kbit/s`:e<1e9?`${(e/1e6).toFixed(e<1e7?1:0)} Mbit/s`:`${(e/1e9).toFixed(1)} Gbit/s`}function ie(n,e=Date.now()/1e3){if(!n)return"never";let o=Math.max(0,Math.round(e-n));return o<60?"just now":o<3600?`${Math.floor(o/60)} min ago`:o<86400?`${Math.floor(o/3600)} h ago`:o<86400*30?`${Math.floor(o/86400)} d ago`:new Date(n*1e3).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function pt(n){if(!n||n<0)return"—";let e=Math.floor(n/86400),o=Math.floor(n%86400/3600),a=Math.floor(n%3600/60);return e?`${e}d ${o}h`:o?`${o}h ${a}m`:`${a}m`}function Mt(n){let e=new Date(n*1e3),o=new Date,a=e.toDateString()===o.toDateString(),r=e.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"});return a?r:`${e.toLocaleDateString("en-GB",{day:"numeric",month:"short"})} ${r}`}function He(n){return`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,"0")}-${String(n.getDate()).padStart(2,"0")}`}function ut(n){let[e,o,a]=n.split("-").map(Number);return new Date(e,(o||1)-1,a||1,12)}function Ne(n){return(typeof n=="string"?/^\d{4}-\d{2}-\d{2}$/.test(n)?ut(n):new Date(n):n).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function Te(n){return n?Ne(n):""}function Cn(n,e){let o=a=>{let[r,i,s]=a.split("-").map(Number);return Date.UTC(r,i-1,s)};return Math.round((o(n)-o(e))/864e5)}function Lt(n,e){let o=ut(n);return o.setDate(o.getDate()+e),He(o)}function ct(n,e){let[o,a,r]=n.split("-").map(Number),i=new Date(o,a-1+e,1,12),s=new Date(i.getFullYear(),i.getMonth()+1,0).getDate();return i.setDate(Math.min(r,s)),He(i)}function Re(n){return n?.length?n[n.length-1].day:He(new Date)}function io(n,e,o,a,r=30){let i=n||a;return e==="day"?Lt(i,o):e==="week"?Lt(i,7*o):e==="month"?ct(i,o):e==="year"?ct(i,12*o):Lt(i,r*o)}function nt(n,e=Date.now()){if(!n)return null;let o=typeof e=="number"?He(new Date(e)):e,a=Cn(n,o);return a>=0?a+1:a}function Fe(n,e){return e!=null&&e>0&&n.expire_warn>0&&e<=n.expire_warn}function Wt(n){return n<=1?"ends today":n===2?"ends tomorrow":`ends in ${n} days`}function Gt(n,e,o=`${e}s`){return`${n.toLocaleString("en-GB")} ${n===1?e:o}`}function St(n){return n<1024?`${n} B`:n<1048576?`${(n/1024).toFixed(n<10240?1:0)} KB`:`${(n/1048576).toFixed(1)} MB`}var ot={lan:"Home network",internet:"Internet",both:"Home network + Internet"};var so=["computer","phone","tablet","router","other"],je={computer:"PC",phone:"Phone",tablet:"Tablet",router:"Router",other:"Other"},lo={active:"Active",paused:"Paused",expired:"Expired",quota:"Data limit reached",hours:"Outside allowed hours",no_server:"No server",server_off:"Server is turned off"};function Ce(n){let e=n.trim().split(/\s+/).filter(Boolean);if(!e.length)return"?";let o=e[0][0]??"",a=e.length>1?e[e.length-1][0]??"":e[0][1]??"";return(o+a).toUpperCase()}function Ft(n){let e=o=>o.disabled?3:o.online?0:o.handshake?1:2;return n.map((o,a)=>[o,a]).sort((o,a)=>e(o[0])-e(a[0])||o[1]-a[1]).map(([o])=>o)}function ye(n,e,o){return t("span",{class:`dl-pill ${n}`,title:o??null},e)}function Lr(n){return n.state==="active"?"ok":n.state==="quota"||n.state==="expired"?"bad":"warn"}function Mr(n){return n.state==="server_off"&&n.paused?"paused":n.state}function co(n){let e=Mr(n);return e==="active"||e==="server_off"?"":ye(Lr({...n,state:e}),lo[e])}function po(n){let e=n.access==="both"?["lan","inet"]:n.access==="lan"?["lan"]:["inet"],o=t("span",{class:"dl-access","aria-label":ot[n.access]},e.map(a=>t("span",{class:`dl-ibadge ${a}`},v(a==="lan"?"home":"globe"))));return me(o,()=>[t("div",{class:"dl-tip-title"},ot[n.access]),n.access==="lan"&&n.services?.length?t("div",{class:"dl-muted"},`${n.services.length} home service${n.services.length===1?"":"s"} only`):""]),o}function qt(n,e,o="Not set up yet"){return n.disabled?t("span",{class:"dl-dstat"},"Disabled"):n.online?t("span",{class:"dl-dstat ok"},"Connected"):n.handshake?t("span",{class:"dl-dstat"},`Last seen ${ie(n.handshake,e)}`):t("span",{class:"dl-dstat warn",title:"Waiting for the first connection"},o)}var Kt=null;function uo(n,e,o,a){Kt?.close();let r=t("aside",{class:"dl-drawer",role:"dialog","aria-modal":"true"},[t("div",{class:"dl-drawer-head"},[n,t("button",{type:"button",class:"dl-drawer-x","aria-label":"Close",click:()=>d()},v("x"))]),t("div",{class:"dl-drawer-body"},e),o?t("div",{class:"dl-drawer-foot"},o):""]),i=t("div",{class:"dl-drawer-overlay dl-root",click:u=>{u.target===i&&d()}},r),s=u=>{u.key==="Escape"&&!document.body.classList.contains("modal-overlay-active")&&d()},l=!1,c=Ae(()=>d());function d(){l||(l=!0,c(),document.removeEventListener("keydown",s),i.classList.remove("open"),setTimeout(()=>i.remove(),220),Kt===p&&(Kt=null),a())}let p={close:d,panel:r};return document.addEventListener("keydown",s),document.body.appendChild(i),requestAnimationFrame(()=>i.classList.add("open")),Kt=p,p}function ne(n,e,o){return t("div",{class:"dl-setrow"},[t("div",{class:"dl-stack"},[t("span",{class:"dl-setrow-label"},n),o?t("span",{class:"dl-sub"},o):""]),t("div",{class:"dl-setrow-ctl"},e)])}function mt(n,e,o,a=e){let r=ne(n,a," "),i=r.querySelector(".dl-sub"),s=()=>{let l=o();i.textContent=l.text,i.classList.toggle("bad",l.bad),e.classList.toggle("cbi-input-invalid",l.bad)};return e.addEventListener("input",s),r.refresh=s,s(),r}function _t(n,e,o,a=""){return t("section",{class:`dl-setsec ${a}`},[t("div",{class:"dl-setsec-body"},[n?t("h3",{},n):"",...e]),o.length?t("div",{class:"dl-setsec-foot"},o):""])}function he(n,e,o,a){return t("div",{class:"dl-group"},[t("div",{class:"dl-group-head"},[t("span",{class:"dl-group-ic"},v(n)),t("span",{class:"dl-stack"},[t("b",{},e),o?t("span",{class:"dl-sub"},o):""])]),t("div",{class:"dl-group-body"},a.filter(r=>r!==""))])}function at(n,e,o,a,r){return t("div",{class:`dl-row dl-need-row ${e}`},[e?t("span",{class:"dl-need-ic"},v(n)):v(n),t("span",{class:"dl-row-main dl-stack"},[t("b",{},o),t("span",{class:"dl-sub"},a)]),r])}function ht(n,e){let o={ok:"success",warn:"warning",error:"error",info:"notice"}[n];return t("div",{class:`alert-message ${o}`},e)}function qe(n,e=""){let o=t("div",{class:e});return o.innerHTML=n,o}var vo=xr(go(),1),Sr='';function ft(n,e=3,o=!0){let a=(0,vo.default)(0,n.length>300?"Q":"H");a.addData(n,"Byte"),a.make();let r=a.getModuleCount(),i=r+e*2,s=o?Math.round(r*.22):0;s&&(r-s)%2&&s++;let l=(r-s)/2,c=l+s,d=(w,g)=>s>0&&w>=l&&w=l&&g${Sr}`}return`${u}`}var _r={connect:"connections",disconnect:"connections",roam:"connections",device_added:"people",device_removed:"people",devices_removed:"people",device_changed:"people",device_keys:"people",link_changed:"people",person_added:"people",person_removed:"people",person_changed:"people",paused:"people",resumed:"people",portal_blocked:"problems"},gt=["connections","people","problems"],rt={connections:"Connections",people:"People",problems:"Problems"},bo={connections:"Connects, disconnects and IP changes",people:"People and their devices added, changed, paused, removed",problems:"Blocked portal sign-ins (tunnels and services are in the service log)"},Tt=n=>_r[n]??"problems",Ct={awg:"AmneziaWG",dawnline:"Dawnline",portal:"Portal"},Tr=["person_added","person_removed","person_changed"];function Pe(n){return n.by?n.by:Tr.includes(n.type)||n.detail==="by admin"||n.detail?.endsWith(" (admin)")?"admin":n.detail?.endsWith(" (portal)")?"portal":null}function xo(n){return(n.detail??"").replace(/ \((admin|portal)\)$/,"").replace(/^by admin$/,"")}var Jt=n=>n.sys?["error","repair","down"].includes(n.sys.level):Tt(n.ev.type)==="problems";function Vt(n){let e=n.keep_days>0?`${n.keep_days} day${n.keep_days===1?"":"s"}`:"no age limit",o=n.persist==="off"?"kept in memory only (lost on reboot)":`saved to flash ${n.persist==="10min"?"every 10 minutes":"hourly"}`;return`Kept for ${e}, up to ${n.max.toLocaleString("en-GB")} events, ${o}.`}function wo(n,e=120,o=26,a=He(new Date)){let r=Math.max(1,...n),i=t("div",{class:"dl-spark"});return i.style.width=`${e}px`,i.style.height=`${o}px`,n.forEach((s,l)=>{let c=t("i");c.style.height=`${Math.max(6,s/r*100)}%`,s||c.classList.add("zero");let d=n.length-1-l;me(c,()=>[t("div",{class:"dl-tip-title"},d===0?"Today":d===1?"Yesterday":ut(Lt(a,-d)).toLocaleDateString("en-GB",{weekday:"short",day:"numeric",month:"short"})),t("div",{class:"dl-muted"},te(s))]),i.appendChild(c)}),i}function Cr(n){let e=n==null?"":String(n);return/^[=+\-@\t\r]/.test(e)&&(e=`'${e}`),/[",\r\n]/.test(e)?`"${e.replace(/"/g,'""')}"`:e}function yo(n,e){return[n.join(","),...e.map(o=>n.map(a=>Cr(o[a])).join(","))].join(` -`)}function Pr(n){let e=new Map(n.people.map(a=>[a.id,a.name])),o=new Map(n.people.flatMap(a=>a.devices.map(r=>[r.id,r.name])));return{people:e,devices:o}}function Ue(n,e,o,a="",r=[]){let i=Pr(n),s=[...e.map(p=>({ts:p.ts,category:Tt(p.type),type:p.type,person:p.person?i.people.get(p.person)??p.pname??p.person:"",device:p.device?i.devices.get(p.device)??p.dname??p.device:"",detail:p.detail??"",where:p.where??"",by:Pe(p)??""})),...r.map(p=>({ts:p.ts,category:"system",type:`${p.src}.${p.level}`,person:"",device:"",detail:`${p.who?`${p.who} `:""}${p.msg}${p.detail?` -${p.detail}`:""}`,where:Ct[p.src]??p.src,by:""}))].sort((p,u)=>p.ts-u.ts).map(({ts:p,...u})=>({time:new Date(p*1e3).toISOString(),...u})),l=new Date().toISOString().slice(0,10),c=`dawnline-activity${a?`-${a}`:""}-${l}.${o}`;if(o==="json"){Ee(c,JSON.stringify(s,null,2),"application/json");return}Ee(c,yo(["time","category","type","person","device","detail","where","by"],s),"text/csv")}var Dr=[["","Everything"],["7","Older than 7 days"],["30","Older than 30 days"],["90","Older than 90 days"]],ko=n=>n?`${n} event${n===1?"":"s"} removed`:"Nothing matched";function Ke(n,e,o,a,r,i=!1){let s=t("select",{class:"cbi-input-select"},[t("option",{value:""},"All categories"),...gt.map(c=>t("option",{value:c,selected:c===r?"selected":null},rt[c])),i?t("option",{value:"system",selected:r==="system"?"selected":null},"System"):""]),l=t("select",{class:"cbi-input-select"},Dr.map(([c,d])=>t("option",{value:c},d)));re(n,[t("p",{class:"dl-muted"},`${e} This cannot be undone; export first if you want a copy.`),t("label",{class:"dl-fld"},[t("span",{class:"dl-fld-label"},"Category"),s]),t("label",{class:"dl-fld"},[t("span",{class:"dl-fld-label"},"Which events"),l])],[le()," ",D("Clear",async()=>{let c=0;if(s.value!=="system")try{c+=(await P.logsClear({...o,category:s.value,older_days:l.value})).removed}catch(d){Z(ve(d),"error",1e4);return}if(i&&(s.value==="system"||s.value===""))try{c+=(await P.serviceLogClear(l.value)).removed}catch(d){ce(),Z(`${s.value==="system"?"":`Activity: ${ko(c).toLowerCase()}. `}The service log was not cleared: ${ve(d)}`,"error",1e4),a();return}ce(),Z(ko(c),"success",3e3),a()},"negative")])}function vt(n,e,o,a){let r=n==="device"?`Clears ${o}'s daily and monthly traffic history. Their person's totals and data limit are not changed.`:n==="person"?`Clears ${o}'s traffic history and that of their devices. Their data limit starts again from zero.`:"Clears traffic history for everyone. Data limits start again from zero.";re(n==="all"?"Reset all traffic history?":`Reset traffic history for ${o}?`,[t("p",{class:"dl-muted"},r)],[le()," ",D("Reset",async()=>{await W(()=>P.usageClear(n,e),"Traffic history reset")&&(ce(),a())},"negative")])}function ge(n,e,o){let a=t("button",{type:"button",role:"switch",class:`dl-switch${n?" on":""}`,"aria-checked":n?"true":"false","aria-label":e,click:()=>{let r=!a.classList.contains("on");Pn(a,r),o?.(r)}},t("i"));return a}function Pn(n,e){n.classList.toggle("on",e),n.setAttribute("aria-checked",e?"true":"false")}var Me=n=>n.classList.contains("on");function xe(n,e,o={}){n.some(([i])=>i===e)||(n=[...n,[e,e]]);let a=t("div",{class:`dl-seg${o.cls?` ${o.cls}`:""}`,role:"radiogroup","aria-label":o.label??null,"data-value":e}),r=()=>a.querySelectorAll(":scope > button").forEach(i=>{let s=i.dataset.v===a.dataset.value;i.classList.toggle("on",s),i.setAttribute("aria-checked",s?"true":"false")});for(let[i,s]of n)a.appendChild(t("button",{type:"button",role:"radio","data-v":i,click:()=>{i!==a.dataset.value&&(o.optimistic!==!1&&(a.dataset.value=i,r()),o.onChange?.(i))}},s));return r(),a}function We(n,e,o,a={}){return t("button",{type:"button",...a,class:`dl-chipbtn${e?" on":""}${a.class?` ${a.class}`:""}`,"aria-pressed":e?"true":"false",click:o},n)}function Yt(n,e){n.classList.toggle("on",e),n.setAttribute("aria-pressed",e?"true":"false")}function se(n,e={}){return t("input",{type:"text",class:"cbi-input-text",value:n,...e})}var Ar={jc:"0",jmin:"0",jmax:"0",s1:"0",s2:"0",s3:"0",s4:"0",h1:"1",h2:"2",h3:"3",h4:"4",i1:"",i2:"",i3:"",i4:"",i5:""},zr={header_protection_key:"HeaderProtectionKey",content_padding_addition:"ContentPaddingAddition",rekey_after_time:"RekeyAfterTime",rekey_timeout:"RekeyTimeout",reject_after_time:"RejectAfterTime",keepalive_timeout:"KeepaliveTimeout",max_handshake_attempts:"MaxHandshakeAttempts",random_trailers:"RandomTrailers",disable_cookies:"DisableCookies"};function Hr(n){let e={};for(let[o,a]of Object.entries(zr))n[o]!=null&&n[o]!==""&&(e[a]=String(n[o]));return e}function Nr(n,e){let o=n.amnezia,a=o.obfuscation??{},r=c=>a[c]!=null&&a[c]!==""?String(a[c]):Ar[c],i=o.host.replace(/^\[(.*)\]$/,"$1"),s={H1:r("h1"),H2:r("h2"),H3:r("h3"),H4:r("h4"),I1:r("i1"),I2:r("i2"),I3:r("i3"),I4:r("i4"),I5:r("i5"),Jc:r("jc"),Jmin:r("jmin"),Jmax:r("jmax"),S1:r("s1"),S2:r("s2"),S3:r("s3"),S4:r("s4"),...Hr(a),allowed_ips:o.allowed_ips,client_ip:o.client_ip,client_priv_key:o.client_priv_key,client_pub_key:o.client_pub_key,config:n.conf.replace(/\r?\n/g,`\r -`),hostName:i,mtu:o.mtu,persistent_keep_alive:o.persistent_keep_alive,port:Number(o.port),psk_key:o.psk_key,server_pub_key:o.server_pub_key},l={containers:[{container:"amnezia-awg",awg:{isThirdPartyConfig:!0,last_config:JSON.stringify(s),port:String(o.port),protocol_version:a.header_protection_key?"3.1":"2",transport_proto:"udp"}}],defaultContainer:"amnezia-awg",description:e,hostName:i};return o.dns[0]&&(l.dns1=o.dns[0]),o.dns[1]&&(l.dns2=o.dns[1]),l}function Rr(n){let e="";for(let o=0;o"u")return null;try{let o=new e.Blob([n]).stream().pipeThrough(new e.CompressionStream("deflate")),a=new Uint8Array(await new e.Response(o).arrayBuffer()),r=new Uint8Array(4+a.length);return new DataView(r.buffer).setUint32(0,n.length,!1),r.set(a,4),r}catch{return null}}async function Dn(n,e,o=!0){let a=new TextEncoder().encode(JSON.stringify(Nr(n,e))),r=o?await Ir(a):null;return`vpn://${Rr(r??a)}`}var Eo=[{id:"off",title:"Off",ic:"zap",stealth:0,speed:4,text:"Plain WireGuard-compatible traffic. Fastest, but easy to recognise and block.",apps:"Any WireGuard app",short:"Any WireGuard app"},{id:"standard",title:"Standard",ic:"shield",stealth:2,speed:4,text:"Junk packets and random headers. Gets through most VPN blocking with no speed cost.",apps:"Every AmneziaWG and AmneziaVPN app",short:"Any AmneziaWG app"},{id:"strong",title:"Strong",ic:"shieldplus",stealth:3,speed:3,text:"More and larger junk packets for networks that block VPNs aggressively. Connects a little slower.",apps:"Every AmneziaWG and AmneziaVPN app",short:"Any AmneziaWG app"},{id:"max",title:"Maximum",ic:"lock",stealth:4,speed:3,needs:"v3",text:"AmneziaWG 3.1: encrypted packet headers, random tails and sizes, jittered timing, and a first packet that looks like DNS.",apps:"Apps with AmneziaWG 3.1 (current AmneziaVPN)",short:"AmneziaWG 3.1 apps"}],Pt=n=>Eo.find(e=>e.id===n),Br={v2:"Needs AmneziaWG 1.5 or newer on the router.",v3:"Needs AmneziaWG 3.1 on the router (kmod-amneziawg and amneziawg-tools 3.1)."},Or={v2:"Needs AmneziaWG on the router.",v3:"Needs AmneziaWG 3.1 on the router: install it first."};function $o(n,e){return t("span",{class:"dl-dots",title:`${e}: ${n} of 4`},[t("span",{class:"dl-dots-label"},e),t("span",{class:"dl-dots-row"},[0,1,2,3].map(o=>t("i",{class:odom.content(i,Eo.map(l=>{let c=!l.needs||n[l.needs],d=l.id===e;return t("button",{type:"button",role:"radio","aria-checked":d?"true":"false","aria-disabled":c?null:"true",class:`dl-method${d?" on":""}${c?"":" off"}`,click:()=>{!c||d||(e=l.id,s(),o(l.id))}},[t("div",{class:"dl-method-head"},[t("span",{class:"dl-method-ic"},v(l.ic)),t("b",{},l.title),l.id===a?t("span",{class:"dl-pill ok"},"Current"):""]),t("p",{},l.text),t("div",{class:"dl-method-meters"},[$o(l.stealth,"Stealth"),$o(l.speed,"Speed")]),t("div",{class:"dl-method-foot"},c?[v("phone"),t("span",{},l.apps)]:[v("alert"),t("span",{},(r?Br:Or)[l.needs])])])}));return s(),i}function Lo(n,e){return t("div",{class:"dl-corehead"},[t("h3",{},n),e?t("span",{class:"dl-sub"},e):""])}var Mo=[["jc","Jc"],["jmin","Jmin"],["jmax","Jmax"],["s1","S1"],["s2","S2"],["s3","S3"],["s4","S4"],["h1","H1"],["h2","H2"],["h3","H3"],["h4","H4"],["i1","I1"],["i2","I2"],["i3","I3"],["i4","I4"],["i5","I5"],["header_protection_key","HeaderProtectionKey"],["content_padding_addition","ContentPaddingAddition"],["rekey_after_time","RekeyAfterTime"],["rekey_timeout","RekeyTimeout"],["reject_after_time","RejectAfterTime"],["keepalive_timeout","KeepaliveTimeout"],["max_handshake_attempts","MaxHandshakeAttempts"],["random_trailers","RandomTrailers"],["disable_cookies","DisableCookies"]];function jr(n){let e=d=>n[d]!=null&&n[d]!=="",o=Mo.filter(([d])=>e(d));if(!o.length)return null;let a=(d,p)=>t("span",{class:"dl-pv"},[t("i",{},p),t("b",{},d==="header_protection_key"?`${n[d].slice(0,6)}••••`:n[d])]),r=(d,p,u,w)=>{let g=Mo.filter(([m])=>w.includes(m)&&e(m));return g.length?t("div",{class:"dl-pgroup"},[t("div",{class:"dl-pgroup-head"},[v(p),t("b",{},d)]),t("p",{},u),t("div",{class:"dl-pvals"},g.map(([m,k])=>a(m,k)))]):""},i=Number(n.jc||0),s=(n.i1??"").includes("0x8580")?"A first packet shaped like a DNS answer.":"Extra packets sent before the handshake.",l=o.map(([d,p])=>`${p} = ${n[d]}`).join(` -`),c=t("div",{class:"dl-pgrid"},[r("Junk packets","zap",i?`${i} random packet${i===1?"":"s"} of ${n.jmin}–${n.jmax} bytes before each handshake.`:"No junk packets.",["jc","jmin","jmax"]),r("Padding","archive","Random bytes in front of handshake, cookie and data packets, so their sizes do not match WireGuard.",["s1","s2","s3","s4"]),r("Packet types","key","The values that replace WireGuard’s recognisable message types.",["h1","h2","h3","h4"]),r("Signatures","globe",s,["i1","i2","i3","i4","i5"]),r("Protection","lock","AmneziaWG 3.1: encrypted headers, random tails and extra padding on data packets.",["header_protection_key","content_padding_addition","random_trailers","disable_cookies"]),r("Timing","clock","Handshake and key timers vary within these ranges instead of WireGuard’s fixed values.",["rekey_after_time","rekey_timeout","reject_after_time","keepalive_timeout","max_handshake_attempts"])]);return t("details",{class:"dl-params"},[t("summary",{},[v("chevron"),t("span",{},"Current parameters"),t("span",{class:"dl-pcount"},String(o.length)),t("span",{class:"dl-spacer"}),t("button",{type:"button",class:"dl-linkbtn",click:d=>{d.preventDefault(),ue(l,"Parameters copied")}},"Copy as config")]),c])}function So(n,e){if(/^\s*\[.+\]\s*$/.test(n))return t("span",{class:"dl-conf-sec"},n);let o=/^(\s*[A-Za-z0-9]+\s*=)\s*(.*)$/.exec(n);if(!o)return document.createTextNode(n);let a=/^(\s*)(PrivateKey|PresharedKey)\b/.test(n);return t("span",{},[t("span",{class:"dl-conf-k"},o[1])," ",a&&!e?t("span",{class:"dl-conf-mask"},"••••••••••••••••"):o[2]])}function Ur(n){let e=!1,o=t("pre",{class:"dl-conf"}),a=()=>dom.content(o,n.conf.split(` +var mr=Object.create;var oo=Object.defineProperty;var hr=Object.getOwnPropertyDescriptor;var fr=Object.getOwnPropertyNames;var gr=Object.getPrototypeOf,vr=Object.prototype.hasOwnProperty;var br=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var xr=(n,e,o,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of fr(e))!vr.call(n,r)&&r!==o&&oo(n,r,{get:()=>e[r],enumerable:!(a=hr(e,r))||a.enumerable});return n};var wr=(n,e,o)=>(o=n!=null?mr(gr(n)):{},xr(e||!n||!n.__esModule?oo(o,"default",{value:n,enumerable:!0}):o,n));var vo=br((fo,go)=>{"use strict";var ho=(function(){var n=function(E,y){var S=236,b=17,x=E,M=o[y],h=null,f=0,R=null,C=[],I={},Q=function(_,A){f=x*4+17,h=(function($){for(var N=new Array($),T=0;T<$;T+=1){N[T]=new Array($);for(var j=0;j<$;j+=1)N[T][j]=null}return N})(f),G(0,0),G(f-7,0),G(0,f-7),q(),z(),ce(_,A),x>=7&&X(_),R==null&&(R=U(x,M,C)),fe(R,A)},G=function(_,A){for(var $=-1;$<=7;$+=1)if(!(_+$<=-1||f<=_+$))for(var N=-1;N<=7;N+=1)A+N<=-1||f<=A+N||(0<=$&&$<=6&&(N==0||N==6)||0<=N&&N<=6&&($==0||$==6)||2<=$&&$<=4&&2<=N&&N<=4?h[_+$][A+N]=!0:h[_+$][A+N]=!1)},Y=function(){for(var _=0,A=0,$=0;$<8;$+=1){Q(!0,$);var N=r.getLostPoint(I);($==0||_>N)&&(_=N,A=$)}return A},z=function(){for(var _=8;_>$&1)==1;h[Math.floor($/3)][$%3+f-8-3]=N}for(var $=0;$<18;$+=1){var N=!_&&(A>>$&1)==1;h[$%3+f-8-3][Math.floor($/3)]=N}},ce=function(_,A){for(var $=M<<3|A,N=r.getBCHTypeInfo($),T=0;T<15;T+=1){var j=!_&&(N>>T&1)==1;T<6?h[T][8]=j:T<8?h[T+1][8]=j:h[f-15+T][8]=j}for(var T=0;T<15;T+=1){var j=!_&&(N>>T&1)==1;T<8?h[8][f-T-1]=j:T<9?h[8][15-T-1+1]=j:h[8][15-T-1]=j}h[f-8][8]=!_},fe=function(_,A){for(var $=-1,N=f-1,T=7,j=0,Z=r.getMaskFunction(A),V=f-1;V>0;V-=2)for(V==6&&(V-=1);;){for(var pe=0;pe<2;pe+=1)if(h[N][V-pe]==null){var be=!1;j<_.length&&(be=(_[j]>>>T&1)==1);var ee=Z(N,V-pe);ee&&(be=!be),h[N][V-pe]=be,T-=1,T==-1&&(j+=1,T=7)}if(N+=$,N<0||f<=N){N-=$,$=-$;break}}},O=function(_,A){for(var $=0,N=0,T=0,j=new Array(A.length),Z=new Array(A.length),V=0;V=0?eo.getAt(to):0}}for(var no=0,ee=0;eeV*8)throw"code length overflow. ("+T.getLengthInBits()+">"+V*8+")";for(T.getLengthInBits()+4<=V*8&&T.put(0,4);T.getLengthInBits()%8!=0;)T.putBit(!1);for(;!(T.getLengthInBits()>=V*8||(T.put(S,8),T.getLengthInBits()>=V*8));)T.put(b,8);return O(T,N)};I.addData=function(_,A){A=A||"Byte";var $=null;switch(A){case"Numeric":$=d(_);break;case"Alphanumeric":$=p(_);break;case"Byte":$=u(_);break;case"Kanji":$=w(_);break;default:throw"mode:"+A}C.push($),R=null},I.isDark=function(_,A){if(_<0||f<=_||A<0||f<=A)throw _+","+A;return h[_][A]},I.getModuleCount=function(){return f},I.make=function(){if(x<1){for(var _=1;_<40;_++){for(var A=l.getRSBlocks(_,M),$=c(),N=0;N"u"?_*4:A;var $="";$+='";for(var T=0;T';$+=""}return $+="",$+="
",$},I.createSvgTag=function(_,A,$,N){var T={};typeof arguments[0]=="object"&&(T=arguments[0],_=T.cellSize,A=T.margin,$=T.alt,N=T.title),_=_||2,A=typeof A>"u"?_*4:A,$=typeof $=="string"?{text:$}:$||{},$.text=$.text||null,$.id=$.text?$.id||"qrcode-description":null,N=typeof N=="string"?{text:N}:N||{},N.text=N.text||null,N.id=N.text?N.id||"qrcode-title":null;var j=I.getModuleCount()*_+A*2,Z,V,pe,be,ee="",Se;for(Se="l"+_+",0 0,"+_+" -"+_+",0 0,-"+_+"z ",ee+=''+F(N.text)+"":"",ee+=$.text?''+F($.text)+"":"",ee+='',ee+='"u"?_*4:A;var $=I.getModuleCount()*_+A*2,N=A,T=$-A;return B($,$,function(j,Z){if(N<=j&&j"u"?_*4:A;var N=I.getModuleCount()*_+A*2,T="";return T+="",T};var F=function(_){for(var A="",$=0;$<_.length;$+=1){var N=_.charAt($);switch(N){case"<":A+="<";break;case">":A+=">";break;case"&":A+="&";break;case'"':A+=""";break;default:A+=N;break}}return A},oe=function(_){var A=1;_=typeof _>"u"?A*2:_;var $=I.getModuleCount()*A+_*2,N=_,T=$-_,j,Z,V,pe,be,ee={"██":"█","█ ":"▀"," █":"▄"," ":" "},Se={"██":"▀","█ ":"▀"," █":" "," ":" "},_e="";for(j=0;j<$;j+=2){for(V=Math.floor((j-N)/A),pe=Math.floor((j+1-N)/A),Z=0;Z<$;Z+=1)be="█",N<=Z&&Z=T?Se[be]:ee[be];_e+=` +`}return $%2&&_>0?_e.substring(0,_e.length-$-1)+Array($+1).join("▀"):_e.substring(0,_e.length-1)};return I.createASCII=function(_,A){if(_=_||1,_<2)return oe(A);_-=1,A=typeof A>"u"?_*2:A;var $=I.getModuleCount()*_+A*2,N=A,T=$-A,j,Z,V,pe,be=Array(_+1).join("██"),ee=Array(_+1).join(" "),Se="",_e="";for(j=0;j<$;j+=1){for(V=Math.floor((j-N)/_),_e="",Z=0;Z<$;Z+=1)pe=1,N<=Z&&Z>>8),M.push(R&255)):M.push(b)}}return M}};var e={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},o={L:1,M:0,Q:3,H:2},a={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},r=(function(){var E=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],y=1335,S=7973,b=21522,x={},M=function(h){for(var f=0;h!=0;)f+=1,h>>>=1;return f};return x.getBCHTypeInfo=function(h){for(var f=h<<10;M(f)-M(y)>=0;)f^=y<=0;)f^=S<5&&(R+=3+Q-5)}for(var C=0;C=256;)x-=255;return E[x]},b})();function s(E,y){if(typeof E.length>"u")throw E.length+"/"+y;var S=(function(){for(var x=0;x"u")throw"bad rs block @ typeNumber:"+x+"/errorCorrectionLevel:"+M;for(var f=h.length/3,R=[],C=0;C>>7-b%8&1)==1},S.put=function(b,x){for(var M=0;M>>x-M-1&1)==1)},S.getLengthInBits=function(){return y},S.putBit=function(b){var x=Math.floor(y/8);E.length<=x&&E.push(0),b&&(E[x]|=128>>>y%8),y+=1},S},d=function(E){var y=e.MODE_NUMBER,S=E,b={};b.getMode=function(){return y},b.getLength=function(h){return S.length},b.write=function(h){for(var f=S,R=0;R+2>>8&255)*192+(C&255),h.put(C,13),R+=2}if(R>>8)},y.writeBytes=function(S,b,x){b=b||0,x=x||S.length;for(var M=0;M0&&(S+=","),S+=E[b];return S+="]",S},y},m=function(){var E=0,y=0,S=0,b="",x={},M=function(f){b+=String.fromCharCode(h(f&63))},h=function(f){if(!(f<0)){if(f<26)return 65+f;if(f<52)return 97+(f-26);if(f<62)return 48+(f-52);if(f==62)return 43;if(f==63)return 47}throw"n:"+f};return x.writeByte=function(f){for(E=E<<8|f&255,y+=8,S+=1;y>=6;)M(E>>>y-6),y-=6},x.flush=function(){if(y>0&&(M(E<<6-y),E=0,y=0),S%3!=0)for(var f=3-S%3,R=0;R=y.length){if(x==0)return-1;throw"unexpected end of file./"+x}var f=y.charAt(S);if(S+=1,f=="=")return x=0,-1;if(f.match(/^\s$/))continue;b=b<<6|h(f.charCodeAt(0)),x+=6}var R=b>>>x-8&255;return x-=8,R};var h=function(f){if(65<=f&&f<=90)return f-65;if(97<=f&&f<=122)return f-97+26;if(48<=f&&f<=57)return f-48+52;if(f==43)return 62;if(f==47)return 63;throw"c:"+f};return M},H=function(E,y){var S=E,b=y,x=new Array(E*y),M={};M.setPixel=function(C,I,Q){x[I*S+C]=Q},M.write=function(C){C.writeString("GIF87a"),C.writeShort(S),C.writeShort(b),C.writeByte(128),C.writeByte(0),C.writeByte(0),C.writeByte(0),C.writeByte(0),C.writeByte(0),C.writeByte(255),C.writeByte(255),C.writeByte(255),C.writeString(","),C.writeShort(0),C.writeShort(0),C.writeShort(S),C.writeShort(b),C.writeByte(0);var I=2,Q=f(I);C.writeByte(I);for(var G=0;Q.length-G>255;)C.writeByte(255),C.writeBytes(Q,G,255),G+=255;C.writeByte(Q.length-G),C.writeBytes(Q,G,Q.length-G),C.writeByte(0),C.writeString(";")};var h=function(C){var I=C,Q=0,G=0,Y={};return Y.write=function(z,q){if(z>>>q)throw"length over";for(;Q+q>=8;)I.writeByte(255&(z<>>=8-Q,G=0,Q=0;G=z<0&&I.writeByte(G)},Y},f=function(C){for(var I=1<>6,128|i&63):i<55296||i>=57344?a.push(224|i>>12,128|i>>6&63,128|i&63):(r++,i=65536+((i&1023)<<10|o.charCodeAt(r)&1023),a.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|i&63))}return a}return e(n)}})();(function(n){typeof define=="function"&&define.amd?define([],n):typeof fo=="object"&&(go.exports=n())})(function(){return ho})});function Mn(n,e){return n==null||n===!1||n===""||(Array.isArray(n)?n.forEach(o=>Mn(o,e)):e.push(n instanceof Node?n:String(n))),e}function t(n,e,o){let a=window.E,r=e!=null&&typeof e=="object"&&!Array.isArray(e)&&!(e instanceof Node);return!r&&o===void 0?a(n,{},Mn(e,[])):a(n,r?e:{},Mn(o,[]))}var ao={phone:'',computer:'',tablet:'',router:'',server:'',other:'',ethernet:'',bridge:'',wifi:'',tunnel:'',plus:'',chart:'',reset:'',package:'',code:'',plug:'',sunrise:'',refresh:'',archive:'',qr:'',copy:'',download:'',link:'',trash:'',edit:'',pause:'',play:'',key:'',out:'',admin:'',shield:'',shieldplus:'',lock:'',zap:'',check:'',alert:'',x:'',globe:'',home:'',open:'',file:'',network:'',moon:'',chevron:'',clock:'',calendar:'',minus:'',more:'',pin:'',activity:''};function $t(n,e="dl-icon"){let o=ao[n]??ao.phone;return``}function v(n,e="dl-icon"){let o=document.createElement("span");return o.className="dl-icon-wrap",o.innerHTML=$t(n,e),o}function K(n,e="info",o=0){let a=document.querySelector(".dl-toasts");a||(a=t("div",{class:"dl-toasts dl-root",role:"status","aria-live":"polite"}),document.body.appendChild(a));let r=e==="error"?"x":e==="warning"?"alert":e==="success"?"check":null,i=()=>{s.classList.remove("show"),setTimeout(()=>s.remove(),200)},s=t("div",{class:`dl-toast ${e}`},[r?v(r):"",t("span",{},n),e==="error"?t("button",{type:"button","aria-label":"Close",click:i},v("x")):""]);a.appendChild(s),requestAnimationFrame(()=>s.classList.add("show")),setTimeout(i,o||(e==="error"?8e3:e==="warning"?5e3:2600))}function ve(n){return n instanceof Error?n.message:String(n)}async function W(n,e){try{let o=await n();return e&&K(e,"success",3500),o}catch(o){K(ve(o),"error",1e4);return}}function ro(n){try{let e=n();e&&typeof e.then=="function"&&e.catch(o=>K(ve(o),"error"))}catch(e){K(ve(e),"error")}}function io(n){if(n&&typeof n=="object"){if(typeof n.error=="string")throw new Error(n.error);typeof n.warning=="string"&&n.warning&&K(n.warning,"warning",12e3)}return n}function J(n,e=[]){let o=rpc.declare({object:"luci.dawnline",method:n,params:e});return async(...a)=>io(await o(...a))}var yr=J("logs_clear",["person","device","category","older_days"]),kr=(n={})=>yr(n.person??"",n.device??"",n.category??"",n.older_days??""),$r=rpc.declare({object:"luci.dawnline",method:"person_update",params:["id","name","access","device_limit","expires","expire_action","expire_warn","quota_gb","quota_period","bonus_gb","hours","note","dns_mode","paused","services","circle","home_nets"]});async function Er(n,e){let a=[n,...["name","access","device_limit","expires","expire_action","expire_warn","quota_gb","quota_period","bonus_gb","hours","note","dns_mode"].map(r=>e[r]),e.paused,e.services,e.circle,e.home_nets];return io(await $r(...a))}var Lr=J("status",["days"]),P={rev:J("rev"),personUpdate:Er,settingsGet:J("settings_get"),portalInfo:J("portal_info"),settingsUpdate:J("settings_update",["values"]),serviceSet:J("service_set",["id","name","address","ports"]),serviceDelete:J("service_delete",["id"]),geoClear:J("geo_clear"),events:J("events",["limit"]),logsClear:kr,interfaces:J("interfaces",["id"]),serverInterfaces:J("server_interfaces",["id","auto_wan","wan_device","auto_lan","lan_devices","lan_like","device_mesh","mesh"]),circleSet:J("circle_set",["id","server","name","color","members"]),circleDelete:J("circle_delete",["id"]),accessCheck:J("access_check",["from","to"]),homeHosts:J("home_hosts",["id"]),usageClear:J("usage_clear",["scope","id"]),uninstall:J("uninstall",["confirm"]),status:Lr,setupDefaults:J("setup_defaults"),serverCreate:J("server_create",["id","name","ifname","port","subnet","endpoint","mtu","preset","lan_zone","wan_zone","lan_like","portal_enabled","portal_port"]),serverObfuscation:J("server_obfuscation",["id","preset"]),serverUpdate:J("server_update",["id","values"]),serverDelete:J("server_delete",["id"]),personLinks:J("person_links",["id"]),personCreate:J("person_create",["name","slug","server","access","device_limit","expires","quota_gb","quota_period"]),personPause:J("person_pause",["id","paused"]),personRegen:J("person_regen",["id","remove"]),personDelete:J("person_delete",["id"]),personUsage:J("person_usage",["id","days"]),deviceCreate:J("device_create",["person","name","kind"]),deviceConfig:J("device_config",["id"]),deviceUpdate:J("device_update",["id","name","disabled"]),deviceDelete:J("device_delete",["id"]),deviceRotate:J("device_rotate",["id"]),apply:J("apply"),health:J("health"),healthFix:J("health_fix",["id"]),serviceLog:J("service_log"),serviceLogClear:J("service_log_clear",["older_days"]),backupList:J("backup_list"),backupCreate:J("backup_create"),backupRestore:J("backup_restore",["name"]),backupDelete:J("backup_delete",["name"]),backupRead:J("backup_read",["name"]),backupUpload:J("backup_upload",["data"]),exportJson:J("export"),importJson:J("import",["data"]),updatesStatus:J("updates_status"),updatesRun:J("updates_run",["what"]),updatesReleases:J("updates_releases",["page"]),updatesNotes:J("updates_notes",["component","tag","build"]),updatesChanges:J("updates_changes",["from","to"])};function D(n,e,o="neutral",a={}){let{disabled:r,...i}=a,s=t("button",{class:`cbi-button cbi-button-${o}`,type:"button",...i,click:async l=>{if(l.preventDefault(),l.stopPropagation(),!s.disabled){s.disabled=!0,s.classList.add("spinning");try{await e(l)}catch(c){K(ve(c),"error")}finally{s.disabled=!1,s.classList.remove("spinning")}}}},n);return s.disabled=!!r,s}function $e(n,e,o,a="neutral",r=""){return D([v(n),t("span",{class:"dl-btn-label"},e)],o,a,{title:e,class:`cbi-button cbi-button-${a} dl-icon-btn ${r}`.trim()})}function Ae(n){return document.addEventListener("luci-navigate",n),()=>document.removeEventListener("luci-navigate",n)}var dt=null;function Sn(n=!1){let e=dt;dt=null,e?.(n)}function ae(n,e,o,a=""){Sn(),ui.showModal(n,[t("div",{class:`dl-modal ${a}`},e),t("div",{class:"button-row"},o)])}function de(){Sn(),ui.hideModal()}function le(n="Cancel",e=!1){return t("button",{class:`cbi-button ${e?"cbi-button-negative":"cbi-button-neutral"}`,type:"button",click:de},n)}function re(n,e,o="Confirm",a=!1){return new Promise(r=>{ae(n,e,[le()," ",t("button",{class:`cbi-button ${a?"cbi-button-negative":"cbi-button-positive"}`,type:"button",click:()=>{let i=dt;dt=null,ui.hideModal(),i?.(!0)}},o)]),dt=r})}Ae(()=>{dt&&(Sn(),ui.hideModal())});async function ue(n,e="Copied to clipboard"){try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(n);else{let o=t("textarea",{style:"position:fixed;opacity:0"},n);document.body.appendChild(o),o.select();let a=document.execCommand("copy");if(o.remove(),!a)throw new Error("Copying is blocked here. Select the text and copy it by hand.")}K(e,"success",2500)}catch(o){K(ve(o),"error")}}function Ee(n,e,o="text/plain"){let a=globalThis,r=typeof e=="string"?new a.Blob([e],{type:o}):e,i=URL.createObjectURL(r),s=t("a",{href:i,download:n,style:"display:none"});document.body.appendChild(s),s.click(),setTimeout(()=>{URL.revokeObjectURL(i),s.remove()},1e3)}function _n(n,e){return new Promise(o=>{let a=t("input",{type:"file",accept:n,style:"display:none"});a.addEventListener("cancel",()=>{a.remove(),o(null)}),a.addEventListener("change",()=>{let r=a.files?.[0];if(a.remove(),!r)return o(null);let i=new FileReader;i.onload=()=>{let s=String(i.result??"");o({name:r.name,data:e==="base64"?s.replace(/^data:[^,]*,/,""):s})},i.onerror=()=>o(null),e==="base64"?i.readAsDataURL(r):i.readAsText(r)}),document.body.appendChild(a),a.click()})}function we(n,e){let o=document.querySelector(".dl-dd");if(o&&(o.dlClose?o.dlClose():o.remove(),o.dlAnchor===n))return;let a=t("div",{class:"dl-dd dl-root",role:"menu"},e.map(u=>u?t("button",{type:"button",role:"menuitem",class:u.danger?"danger":u.warn?"warn":"",click:()=>{p(),ro(u.run)}},[u.icon??"",t("span",{},u.label)]):t("hr")));document.body.appendChild(a);let r=n.getBoundingClientRect(),i=a.offsetWidth,s=a.offsetHeight;a.style.top=`${r.bottom+6+s>window.innerHeight-8&&r.top-6-s>8?r.top-6-s:r.bottom+6}px`,a.style.left=`${Math.max(8,Math.min(r.right-i,window.innerWidth-i-8))}px`;let l=u=>{!a.contains(u.target)&&!n.contains(u.target)&&p()},c=u=>{u.key==="Escape"&&p()},d=Ae(p);a.dlAnchor=n,a.dlClose=p;function p(){a.remove(),d(),document.removeEventListener("mousedown",l,!0),document.removeEventListener("keydown",c,!0),window.removeEventListener("scroll",p,!0)}setTimeout(()=>{document.addEventListener("mousedown",l,!0),document.addEventListener("keydown",c,!0),window.addEventListener("scroll",p,!0)}),a.querySelector("button")?.focus({preventScroll:!0})}var et=null,tt=null,Tn=0;function Et(){et&&(et.style.display="none"),tt=null,clearInterval(Tn),Tn=0}function me(n,e){let o=a=>{et??(et=document.body.appendChild(t("div",{class:"dl-tip dl-tip-float dl-root"}))),et.replaceChildren(...e().map(r=>typeof r=="string"?document.createTextNode(r):r)),et.style.display="",et.style.left=`${a.clientX}px`,et.style.top=`${a.clientY-10}px`,tt=n,Tn||(Tn=window.setInterval(()=>{(!tt?.isConnected||!tt.getClientRects().length)&&Et()},400))};n.addEventListener("mouseenter",o),n.addEventListener("mousemove",o),n.addEventListener("mouseleave",Et)}Ae(Et);window.addEventListener("scroll",()=>tt&&Et(),{capture:!0,passive:!0});document.addEventListener("pointerdown",n=>{tt&&!tt.contains(n.target)&&Et()},!0);function te(n){if(!n||n<0)return"0 B";let e=["B","KB","MB","GB","TB"],o=0,a=n;for(;a>=1024&&o=100||o===0?Math.round(a):a.toFixed(1)} ${e[o]}`}function ze(n){let e=n*8;return e<1e3?`${Math.round(e)} bit/s`:e<1e6?`${(e/1e3).toFixed(e<1e4?1:0)} kbit/s`:e<1e9?`${(e/1e6).toFixed(e<1e7?1:0)} Mbit/s`:`${(e/1e9).toFixed(1)} Gbit/s`}function ie(n,e=Date.now()/1e3){if(!n)return"never";let o=Math.max(0,Math.round(e-n));return o<60?"just now":o<3600?`${Math.floor(o/60)} min ago`:o<86400?`${Math.floor(o/3600)} h ago`:o<86400*30?`${Math.floor(o/86400)} d ago`:new Date(n*1e3).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function pt(n){if(!n||n<0)return"—";let e=Math.floor(n/86400),o=Math.floor(n%86400/3600),a=Math.floor(n%3600/60);return e?`${e}d ${o}h`:o?`${o}h ${a}m`:`${a}m`}function Mt(n){let e=new Date(n*1e3),o=new Date,a=e.toDateString()===o.toDateString(),r=e.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"});return a?r:`${e.toLocaleDateString("en-GB",{day:"numeric",month:"short"})} ${r}`}function He(n){return`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,"0")}-${String(n.getDate()).padStart(2,"0")}`}function ut(n){let[e,o,a]=n.split("-").map(Number);return new Date(e,(o||1)-1,a||1,12)}function Ne(n){return(typeof n=="string"?/^\d{4}-\d{2}-\d{2}$/.test(n)?ut(n):new Date(n):n).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function Te(n){return n?Ne(n):""}function Cn(n,e){let o=a=>{let[r,i,s]=a.split("-").map(Number);return Date.UTC(r,i-1,s)};return Math.round((o(n)-o(e))/864e5)}function Lt(n,e){let o=ut(n);return o.setDate(o.getDate()+e),He(o)}function ct(n,e){let[o,a,r]=n.split("-").map(Number),i=new Date(o,a-1+e,1,12),s=new Date(i.getFullYear(),i.getMonth()+1,0).getDate();return i.setDate(Math.min(r,s)),He(i)}function Re(n){return n?.length?n[n.length-1].day:He(new Date)}function so(n,e,o,a,r=30){let i=n||a;return e==="day"?Lt(i,o):e==="week"?Lt(i,7*o):e==="month"?ct(i,o):e==="year"?ct(i,12*o):Lt(i,r*o)}function nt(n,e=Date.now()){if(!n)return null;let o=typeof e=="number"?He(new Date(e)):e,a=Cn(n,o);return a>=0?a+1:a}function Fe(n,e){return e!=null&&e>0&&n.expire_warn>0&&e<=n.expire_warn}function Wt(n){return n<=1?"ends today":n===2?"ends tomorrow":`ends in ${n} days`}function Gt(n,e,o=`${e}s`){return`${n.toLocaleString("en-GB")} ${n===1?e:o}`}function St(n){return n<1024?`${n} B`:n<1048576?`${(n/1024).toFixed(n<10240?1:0)} KB`:`${(n/1048576).toFixed(1)} MB`}var ot={lan:"Home network",internet:"Internet",both:"Home network + Internet"};var lo=["computer","phone","tablet","router","other"],je={computer:"PC",phone:"Phone",tablet:"Tablet",router:"Router",other:"Other"},co={active:"Active",paused:"Paused",expired:"Expired",quota:"Data limit reached",hours:"Outside allowed hours",no_server:"No server",server_off:"Server is turned off"};function Ce(n){let e=n.trim().split(/\s+/).filter(Boolean);if(!e.length)return"?";let o=e[0][0]??"",a=e.length>1?e[e.length-1][0]??"":e[0][1]??"";return(o+a).toUpperCase()}function Ft(n){let e=o=>o.disabled?3:o.online?0:o.handshake?1:2;return n.map((o,a)=>[o,a]).sort((o,a)=>e(o[0])-e(a[0])||o[1]-a[1]).map(([o])=>o)}function ye(n,e,o){return t("span",{class:`dl-pill ${n}`,title:o??null},e)}function Mr(n){return n.state==="active"?"ok":n.state==="quota"||n.state==="expired"?"bad":"warn"}function Sr(n){return n.state==="server_off"&&n.paused?"paused":n.state}function po(n){let e=Sr(n);return e==="active"||e==="server_off"?"":ye(Mr({...n,state:e}),co[e])}function uo(n){let e=n.access==="both"?["lan","inet"]:n.access==="lan"?["lan"]:["inet"],o=t("span",{class:"dl-access","aria-label":ot[n.access]},e.map(a=>t("span",{class:`dl-ibadge ${a}`},v(a==="lan"?"home":"globe"))));return me(o,()=>[t("div",{class:"dl-tip-title"},ot[n.access]),n.access==="lan"&&n.services?.length?t("div",{class:"dl-muted"},`${n.services.length} home service${n.services.length===1?"":"s"} only`):""]),o}function qt(n,e,o="Not set up yet"){return n.disabled?t("span",{class:"dl-dstat"},"Disabled"):n.online?t("span",{class:"dl-dstat ok"},"Connected"):n.handshake?t("span",{class:"dl-dstat"},`Last seen ${ie(n.handshake,e)}`):t("span",{class:"dl-dstat warn",title:"Waiting for the first connection"},o)}var Kt=null;function mo(n,e,o,a){Kt?.close();let r=t("aside",{class:"dl-drawer",role:"dialog","aria-modal":"true"},[t("div",{class:"dl-drawer-head"},[n,t("button",{type:"button",class:"dl-drawer-x","aria-label":"Close",click:()=>d()},v("x"))]),t("div",{class:"dl-drawer-body"},e),o?t("div",{class:"dl-drawer-foot"},o):""]),i=t("div",{class:"dl-drawer-overlay dl-root",click:u=>{u.target===i&&d()}},r),s=u=>{u.key==="Escape"&&!document.body.classList.contains("modal-overlay-active")&&d()},l=!1,c=Ae(()=>d());function d(){l||(l=!0,c(),document.removeEventListener("keydown",s),i.classList.remove("open"),setTimeout(()=>i.remove(),220),Kt===p&&(Kt=null),a())}let p={close:d,panel:r};return document.addEventListener("keydown",s),document.body.appendChild(i),requestAnimationFrame(()=>i.classList.add("open")),Kt=p,p}function ne(n,e,o){return t("div",{class:"dl-setrow"},[t("div",{class:"dl-stack"},[t("span",{class:"dl-setrow-label"},n),o?t("span",{class:"dl-sub"},o):""]),t("div",{class:"dl-setrow-ctl"},e)])}function mt(n,e,o,a=e){let r=ne(n,a," "),i=r.querySelector(".dl-sub"),s=()=>{let l=o();i.textContent=l.text,i.classList.toggle("bad",l.bad),e.classList.toggle("cbi-input-invalid",l.bad)};return e.addEventListener("input",s),r.refresh=s,s(),r}function _t(n,e,o,a=""){return t("section",{class:`dl-setsec ${a}`},[t("div",{class:"dl-setsec-body"},[n?t("h3",{},n):"",...e]),o.length?t("div",{class:"dl-setsec-foot"},o):""])}function he(n,e,o,a){return t("div",{class:"dl-group"},[t("div",{class:"dl-group-head"},[t("span",{class:"dl-group-ic"},v(n)),t("span",{class:"dl-stack"},[t("b",{},e),o?t("span",{class:"dl-sub"},o):""])]),t("div",{class:"dl-group-body"},a.filter(r=>r!==""))])}function at(n,e,o,a,r){return t("div",{class:`dl-row dl-need-row ${e}`},[e?t("span",{class:"dl-need-ic"},v(n)):v(n),t("span",{class:"dl-row-main dl-stack"},[t("b",{},o),t("span",{class:"dl-sub"},a)]),r])}function ht(n,e){let o={ok:"success",warn:"warning",error:"error",info:"notice"}[n];return t("div",{class:`alert-message ${o}`},e)}function qe(n,e=""){let o=t("div",{class:e});return o.innerHTML=n,o}var bo=wr(vo(),1),_r='';function ft(n,e=3,o=!0){let a=(0,bo.default)(0,n.length>300?"Q":"H");a.addData(n,"Byte"),a.make();let r=a.getModuleCount(),i=r+e*2,s=o?Math.round(r*.22):0;s&&(r-s)%2&&s++;let l=(r-s)/2,c=l+s,d=(w,g)=>s>0&&w>=l&&w=l&&g${_r}`}return`${u}`}var Tr={connect:"connections",disconnect:"connections",roam:"connections",device_added:"people",device_removed:"people",devices_removed:"people",device_changed:"people",device_keys:"people",link_changed:"people",person_added:"people",person_removed:"people",person_changed:"people",paused:"people",resumed:"people",portal_blocked:"problems"},gt=["connections","people","problems"],rt={connections:"Connections",people:"People",problems:"Problems"},xo={connections:"Connects, disconnects and IP changes",people:"People and their devices added, changed, paused, removed",problems:"Blocked portal sign-ins (tunnels and services are in the service log)"},Tt=n=>Tr[n]??"problems",Ct={awg:"AmneziaWG",dawnline:"Dawnline",portal:"Portal"},Cr=["person_added","person_removed","person_changed"];function Pe(n){return n.by?n.by:Cr.includes(n.type)||n.detail==="by admin"||n.detail?.endsWith(" (admin)")?"admin":n.detail?.endsWith(" (portal)")?"portal":null}function wo(n){return(n.detail??"").replace(/ \((admin|portal)\)$/,"").replace(/^by admin$/,"")}var Jt=n=>n.sys?["error","repair","down"].includes(n.sys.level):Tt(n.ev.type)==="problems";function Vt(n){let e=n.keep_days>0?`${n.keep_days} day${n.keep_days===1?"":"s"}`:"no age limit",o=n.persist==="off"?"kept in memory only (lost on reboot)":`saved to flash ${n.persist==="10min"?"every 10 minutes":"hourly"}`;return`Kept for ${e}, up to ${n.max.toLocaleString("en-GB")} events, ${o}.`}function yo(n,e=120,o=26,a=He(new Date)){let r=Math.max(1,...n),i=t("div",{class:"dl-spark"});return i.style.width=`${e}px`,i.style.height=`${o}px`,n.forEach((s,l)=>{let c=t("i");c.style.height=`${Math.max(6,s/r*100)}%`,s||c.classList.add("zero");let d=n.length-1-l;me(c,()=>[t("div",{class:"dl-tip-title"},d===0?"Today":d===1?"Yesterday":ut(Lt(a,-d)).toLocaleDateString("en-GB",{weekday:"short",day:"numeric",month:"short"})),t("div",{class:"dl-muted"},te(s))]),i.appendChild(c)}),i}function Pr(n){let e=n==null?"":String(n);return/^[=+\-@\t\r]/.test(e)&&(e=`'${e}`),/[",\r\n]/.test(e)?`"${e.replace(/"/g,'""')}"`:e}function ko(n,e){return[n.join(","),...e.map(o=>n.map(a=>Pr(o[a])).join(","))].join(` +`)}function Dr(n){let e=new Map(n.people.map(a=>[a.id,a.name])),o=new Map(n.people.flatMap(a=>a.devices.map(r=>[r.id,r.name])));return{people:e,devices:o}}function Ue(n,e,o,a="",r=[]){let i=Dr(n),s=[...e.map(p=>({ts:p.ts,category:Tt(p.type),type:p.type,person:p.person?i.people.get(p.person)??p.pname??p.person:"",device:p.device?i.devices.get(p.device)??p.dname??p.device:"",detail:p.detail??"",where:p.where??"",by:Pe(p)??""})),...r.map(p=>({ts:p.ts,category:"system",type:`${p.src}.${p.level}`,person:"",device:"",detail:`${p.who?`${p.who} `:""}${p.msg}${p.detail?` +${p.detail}`:""}`,where:Ct[p.src]??p.src,by:""}))].sort((p,u)=>p.ts-u.ts).map(({ts:p,...u})=>({time:new Date(p*1e3).toISOString(),...u})),l=new Date().toISOString().slice(0,10),c=`dawnline-activity${a?`-${a}`:""}-${l}.${o}`;if(o==="json"){Ee(c,JSON.stringify(s,null,2),"application/json");return}Ee(c,ko(["time","category","type","person","device","detail","where","by"],s),"text/csv")}var Ar=[["","Everything"],["7","Older than 7 days"],["30","Older than 30 days"],["90","Older than 90 days"]],$o=n=>n?`${n} event${n===1?"":"s"} removed`:"Nothing matched";function Ke(n,e,o,a,r,i=!1){let s=t("select",{class:"cbi-input-select"},[t("option",{value:""},"All categories"),...gt.map(c=>t("option",{value:c,selected:c===r?"selected":null},rt[c])),i?t("option",{value:"system",selected:r==="system"?"selected":null},"System"):""]),l=t("select",{class:"cbi-input-select"},Ar.map(([c,d])=>t("option",{value:c},d)));ae(n,[t("p",{class:"dl-muted"},`${e} This cannot be undone; export first if you want a copy.`),t("label",{class:"dl-fld"},[t("span",{class:"dl-fld-label"},"Category"),s]),t("label",{class:"dl-fld"},[t("span",{class:"dl-fld-label"},"Which events"),l])],[le()," ",D("Clear",async()=>{let c=0;if(s.value!=="system")try{c+=(await P.logsClear({...o,category:s.value,older_days:l.value})).removed}catch(d){K(ve(d),"error",1e4);return}if(i&&(s.value==="system"||s.value===""))try{c+=(await P.serviceLogClear(l.value)).removed}catch(d){de(),K(`${s.value==="system"?"":`Activity: ${$o(c).toLowerCase()}. `}The service log was not cleared: ${ve(d)}`,"error",1e4),a();return}de(),K($o(c),"success",3e3),a()},"negative")])}function vt(n,e,o,a){let r=n==="device"?`Clears ${o}'s daily and monthly traffic history. Their person's totals and data limit are not changed.`:n==="person"?`Clears ${o}'s traffic history and that of their devices. Their data limit starts again from zero.`:"Clears traffic history for everyone. Data limits start again from zero.";ae(n==="all"?"Reset all traffic history?":`Reset traffic history for ${o}?`,[t("p",{class:"dl-muted"},r)],[le()," ",D("Reset",async()=>{await W(()=>P.usageClear(n,e),"Traffic history reset")&&(de(),a())},"negative")])}function ge(n,e,o){let a=t("button",{type:"button",role:"switch",class:`dl-switch${n?" on":""}`,"aria-checked":n?"true":"false","aria-label":e,click:()=>{let r=!a.classList.contains("on");Pn(a,r),o?.(r)}},t("i"));return a}function Pn(n,e){n.classList.toggle("on",e),n.setAttribute("aria-checked",e?"true":"false")}var Me=n=>n.classList.contains("on");function xe(n,e,o={}){n.some(([i])=>i===e)||(n=[...n,[e,e]]);let a=t("div",{class:`dl-seg${o.cls?` ${o.cls}`:""}`,role:"radiogroup","aria-label":o.label??null,"data-value":e}),r=()=>a.querySelectorAll(":scope > button").forEach(i=>{let s=i.dataset.v===a.dataset.value;i.classList.toggle("on",s),i.setAttribute("aria-checked",s?"true":"false")});for(let[i,s]of n)a.appendChild(t("button",{type:"button",role:"radio","data-v":i,click:()=>{i!==a.dataset.value&&(o.optimistic!==!1&&(a.dataset.value=i,r()),o.onChange?.(i))}},s));return r(),a}function We(n,e,o,a={}){return t("button",{type:"button",...a,class:`dl-chipbtn${e?" on":""}${a.class?` ${a.class}`:""}`,"aria-pressed":e?"true":"false",click:o},n)}function Yt(n,e){n.classList.toggle("on",e),n.setAttribute("aria-pressed",e?"true":"false")}function se(n,e={}){return t("input",{type:"text",class:"cbi-input-text",value:n,...e})}var zr={jc:"0",jmin:"0",jmax:"0",s1:"0",s2:"0",s3:"0",s4:"0",h1:"1",h2:"2",h3:"3",h4:"4",i1:"",i2:"",i3:"",i4:"",i5:""},Hr={header_protection_key:"HeaderProtectionKey",content_padding_addition:"ContentPaddingAddition",rekey_after_time:"RekeyAfterTime",rekey_timeout:"RekeyTimeout",reject_after_time:"RejectAfterTime",keepalive_timeout:"KeepaliveTimeout",max_handshake_attempts:"MaxHandshakeAttempts",random_trailers:"RandomTrailers",disable_cookies:"DisableCookies"};function Nr(n){let e={};for(let[o,a]of Object.entries(Hr))n[o]!=null&&n[o]!==""&&(e[a]=String(n[o]));return e}function Rr(n,e){let o=n.amnezia,a=o.obfuscation??{},r=c=>a[c]!=null&&a[c]!==""?String(a[c]):zr[c],i=o.host.replace(/^\[(.*)\]$/,"$1"),s={H1:r("h1"),H2:r("h2"),H3:r("h3"),H4:r("h4"),I1:r("i1"),I2:r("i2"),I3:r("i3"),I4:r("i4"),I5:r("i5"),Jc:r("jc"),Jmin:r("jmin"),Jmax:r("jmax"),S1:r("s1"),S2:r("s2"),S3:r("s3"),S4:r("s4"),...Nr(a),allowed_ips:o.allowed_ips,client_ip:o.client_ip,client_priv_key:o.client_priv_key,client_pub_key:o.client_pub_key,config:n.conf.replace(/\r?\n/g,`\r +`),hostName:i,mtu:o.mtu,persistent_keep_alive:o.persistent_keep_alive,port:Number(o.port),psk_key:o.psk_key,server_pub_key:o.server_pub_key},l={containers:[{container:"amnezia-awg",awg:{isThirdPartyConfig:!0,last_config:JSON.stringify(s),port:String(o.port),protocol_version:a.header_protection_key?"3.1":"2",transport_proto:"udp"}}],defaultContainer:"amnezia-awg",description:e,hostName:i};return o.dns[0]&&(l.dns1=o.dns[0]),o.dns[1]&&(l.dns2=o.dns[1]),l}function Ir(n){let e="";for(let o=0;o"u")return null;try{let o=new e.Blob([n]).stream().pipeThrough(new e.CompressionStream("deflate")),a=new Uint8Array(await new e.Response(o).arrayBuffer()),r=new Uint8Array(4+a.length);return new DataView(r.buffer).setUint32(0,n.length,!1),r.set(a,4),r}catch{return null}}async function Dn(n,e,o=!0){let a=new TextEncoder().encode(JSON.stringify(Rr(n,e))),r=o?await Br(a):null;return`vpn://${Ir(r??a)}`}var Lo=[{id:"off",title:"Off",ic:"zap",stealth:0,speed:4,text:"Plain WireGuard-compatible traffic. Fastest, but easy to recognise and block.",apps:"Any WireGuard app",short:"Any WireGuard app"},{id:"standard",title:"Standard",ic:"shield",stealth:2,speed:4,text:"Junk packets and random headers. Gets through most VPN blocking with no speed cost.",apps:"Every AmneziaWG and AmneziaVPN app",short:"Any AmneziaWG app"},{id:"strong",title:"Strong",ic:"shieldplus",stealth:3,speed:3,text:"More and larger junk packets for networks that block VPNs aggressively. Connects a little slower.",apps:"Every AmneziaWG and AmneziaVPN app",short:"Any AmneziaWG app"},{id:"max",title:"Maximum",ic:"lock",stealth:4,speed:3,needs:"v3",text:"AmneziaWG 3.1: encrypted packet headers, random tails and sizes, jittered timing, and a first packet that looks like DNS.",apps:"Apps with AmneziaWG 3.1 (current AmneziaVPN)",short:"AmneziaWG 3.1 apps"}],Pt=n=>Lo.find(e=>e.id===n),Or={v2:"Needs AmneziaWG 1.5 or newer on the router.",v3:"Needs AmneziaWG 3.1 on the router (kmod-amneziawg and amneziawg-tools 3.1)."},jr={v2:"Needs AmneziaWG on the router.",v3:"Needs AmneziaWG 3.1 on the router: install it first."};function Eo(n,e){return t("span",{class:"dl-dots",title:`${e}: ${n} of 4`},[t("span",{class:"dl-dots-label"},e),t("span",{class:"dl-dots-row"},[0,1,2,3].map(o=>t("i",{class:odom.content(i,Lo.map(l=>{let c=!l.needs||n[l.needs],d=l.id===e;return t("button",{type:"button",role:"radio","aria-checked":d?"true":"false","aria-disabled":c?null:"true",class:`dl-method${d?" on":""}${c?"":" off"}`,click:()=>{!c||d||(e=l.id,s(),o(l.id))}},[t("div",{class:"dl-method-head"},[t("span",{class:"dl-method-ic"},v(l.ic)),t("b",{},l.title),l.id===a?t("span",{class:"dl-pill ok"},"Current"):""]),t("p",{},l.text),t("div",{class:"dl-method-meters"},[Eo(l.stealth,"Stealth"),Eo(l.speed,"Speed")]),t("div",{class:"dl-method-foot"},c?[v("phone"),t("span",{},l.apps)]:[v("alert"),t("span",{},(r?Or:jr)[l.needs])])])}));return s(),i}function Mo(n,e){return t("div",{class:"dl-corehead"},[t("h3",{},n),e?t("span",{class:"dl-sub"},e):""])}var So=[["jc","Jc"],["jmin","Jmin"],["jmax","Jmax"],["s1","S1"],["s2","S2"],["s3","S3"],["s4","S4"],["h1","H1"],["h2","H2"],["h3","H3"],["h4","H4"],["i1","I1"],["i2","I2"],["i3","I3"],["i4","I4"],["i5","I5"],["header_protection_key","HeaderProtectionKey"],["content_padding_addition","ContentPaddingAddition"],["rekey_after_time","RekeyAfterTime"],["rekey_timeout","RekeyTimeout"],["reject_after_time","RejectAfterTime"],["keepalive_timeout","KeepaliveTimeout"],["max_handshake_attempts","MaxHandshakeAttempts"],["random_trailers","RandomTrailers"],["disable_cookies","DisableCookies"]];function Ur(n){let e=d=>n[d]!=null&&n[d]!=="",o=So.filter(([d])=>e(d));if(!o.length)return null;let a=(d,p)=>t("span",{class:"dl-pv"},[t("i",{},p),t("b",{},d==="header_protection_key"?`${n[d].slice(0,6)}••••`:n[d])]),r=(d,p,u,w)=>{let g=So.filter(([m])=>w.includes(m)&&e(m));return g.length?t("div",{class:"dl-pgroup"},[t("div",{class:"dl-pgroup-head"},[v(p),t("b",{},d)]),t("p",{},u),t("div",{class:"dl-pvals"},g.map(([m,k])=>a(m,k)))]):""},i=Number(n.jc||0),s=(n.i1??"").includes("0x8580")?"A first packet shaped like a DNS answer.":"Extra packets sent before the handshake.",l=o.map(([d,p])=>`${p} = ${n[d]}`).join(` +`),c=t("div",{class:"dl-pgrid"},[r("Junk packets","zap",i?`${i} random packet${i===1?"":"s"} of ${n.jmin}–${n.jmax} bytes before each handshake.`:"No junk packets.",["jc","jmin","jmax"]),r("Padding","archive","Random bytes in front of handshake, cookie and data packets, so their sizes do not match WireGuard.",["s1","s2","s3","s4"]),r("Packet types","key","The values that replace WireGuard’s recognisable message types.",["h1","h2","h3","h4"]),r("Signatures","globe",s,["i1","i2","i3","i4","i5"]),r("Protection","lock","AmneziaWG 3.1: encrypted headers, random tails and extra padding on data packets.",["header_protection_key","content_padding_addition","random_trailers","disable_cookies"]),r("Timing","clock","Handshake and key timers vary within these ranges instead of WireGuard’s fixed values.",["rekey_after_time","rekey_timeout","reject_after_time","keepalive_timeout","max_handshake_attempts"])]);return t("details",{class:"dl-params"},[t("summary",{},[v("chevron"),t("span",{},"Current parameters"),t("span",{class:"dl-pcount"},String(o.length)),t("span",{class:"dl-spacer"}),t("button",{type:"button",class:"dl-linkbtn",click:d=>{d.preventDefault(),ue(l,"Parameters copied")}},"Copy as config")]),c])}function _o(n,e){if(/^\s*\[.+\]\s*$/.test(n))return t("span",{class:"dl-conf-sec"},n);let o=/^(\s*[A-Za-z0-9]+\s*=)\s*(.*)$/.exec(n);if(!o)return document.createTextNode(n);let a=/^(\s*)(PrivateKey|PresharedKey)\b/.test(n);return t("span",{},[t("span",{class:"dl-conf-k"},o[1])," ",a&&!e?t("span",{class:"dl-conf-mask"},"••••••••••••••••"):o[2]])}function Wr(n){let e=!1,o=t("pre",{class:"dl-conf"}),a=()=>dom.content(o,n.conf.split(` `).flatMap((s,l)=>l?[` -`,So(s,e)]:[So(s,e)])),r=t("button",{type:"button",class:"dl-chipbtn",click:s=>{s.preventDefault(),e=!e,dom.content(r,[v(e?"x":"key"),e?"Hide key":"Show key"]),a()}},[v("key"),"Show key"]);a();let i=new Blob([n.conf]).size;return t("div",{class:"dl-stack gap8"},[t("div",{class:"dl-filecard"},[t("span",{class:"dl-filecard-ic"},".conf"),t("span",{class:"dl-stack"},[t("span",{class:"dl-mono dl-ellipsis"},n.filename),t("span",{class:"dl-sub"},`AmneziaWG · ${i} bytes · import it in the app`)]),D([v("download")," Download"],()=>Ee(n.filename,n.conf,"application/octet-stream"),"positive")]),t("details",{class:"dl-params"},[t("summary",{},[v("chevron"),t("span",{},"Configuration"),t("span",{class:"dl-spacer"}),r,t("button",{type:"button",class:"dl-chipbtn",click:s=>{s.preventDefault(),ue(n.conf,"Configuration copied")}},[v("copy"),"Copy"])]),o])])}async function Wr(n,e="file"){if(!n.has_private_key)return t("div",{class:"dl-hint"},"This device generated its own keys in the browser, so its full configuration only exists on that device.");let o=await Dn(n,`${n.server} · ${n.person} · ${n.name}`),a={qr:()=>t("div",{class:"dl-qr-pane"},[qe(ft(n.conf),"dl-qr"),t("span",{class:"dl-sub"},"Scan with AmneziaVPN or AmneziaWG on the device.")]),key:()=>t("div",{class:"dl-stack gap8"},[t("div",{class:"dl-linkbox"},[t("span",{class:"dl-mono"},o),D("Copy",()=>ue(o,"Key copied"))]),t("span",{class:"dl-sub"},"AmneziaVPN → Add server → Insert key. Keep it private.")]),file:()=>Ur(n)},r=t("div",{class:"dl-connect-body"}),i=t("div",{class:"dl-seg"}),s=l=>{i.querySelectorAll("button").forEach(c=>c.classList.toggle("on",c.dataset.id===l)),dom.content(r,a[l]())};for(let[l,c]of[["file","File"],["key","Key"],["qr","QR code"]])i.appendChild(t("button",{type:"button","data-id":l,click:()=>s(l)},c));return s(e),t("div",{class:"dl-stack gap12"},[i,r])}async function Gr(n,e,o,a){let r=Pt(o),s=n.st.people.filter(c=>c.server===e.id).reduce((c,d)=>c+d.devices.length,0);await ae(a?"Generate new disguise values?":`Switch to ${r.title}?`,`${s} AmneziaWG device${s===1?"":"s"} stop connecting until they import their configuration again (from their personal link or from you).${o==="max"?" They need an app with AmneziaWG 3.1.":""}`,a?"Generate and apply":"Switch and apply",!0)&&await W(()=>P.serverObfuscation(e.id,o),a?"New values applied":`${r.title} applied`)&&(Z("Devices are marked “Update config” until they import again.","info",6e3),await n.refresh())}function Fr(n,e){let o=n.st,a=se(String(e.port),{inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),r=se(e.mtu?String(e.mtu):"",{placeholder:"Auto",inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),i=`${e.mtus.computer} for computers and routers, ${e.mtus.phone} for phones and tablets`,s=e.mtu?`Now ${i}. Empty = automatic.`:`Automatic by device type and disguise: now ${i}. Lower it if some sites hang.`,l=se(String(e.keepalive??""),{placeholder:"25",inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),c=Pt(e.preset)?e.preset:void 0,d=c??"standard",p=D("",()=>Gr(n,e,d,d===c),"neutral"),u=()=>dom.content(p,d===c?[v("reset")," Generate new values"]:[`Switch to ${Pt(d).title}`]);u();let w=o.awg_state?.tools!==!1;return _t("",[Lo("AmneziaWG",e.ifname),he("globe","Listening","Where devices reach this core from the internet",[ne("UDP port",a,"Opened on the WAN firewall automatically.")]),he("file","In every device configuration","Changing these marks devices “Update config” until they import again",[ne("MTU",r,s),ne("Keep-alive",l,"Seconds between packets devices send to keep NAT open. 0 = off.")]),he("shield","Disguise","So networks that block VPNs do not recognise the tunnel. Off = plain WireGuard",[Zt(o.awg,d,g=>{d=g,u()},c,w),w&&!o.awg.v3?ht("info",["This router runs an older AmneziaWG. ",t("b",{},"Maximum")," becomes available with kmod-amneziawg and amneziawg-tools 3.1."]):"",jr(e.obf??{})??"",t("div",{class:"dl-row-end"},[t("span",{class:"dl-sub"},"Applies at once: every AmneziaWG device imports its configuration again."),p])]),t("details",{class:"dl-params"},[t("summary",{},[v("chevron"),t("span",{},"Tunnel"),t("span",{class:"dl-pcount"},"3")]),t("div",{class:"dl-params-body"},[ne("Interface",t("span",{class:"dl-mono"},`${e.ifname} · router ${e.address}`)),ne("Tunnel subnet",t("span",{class:"dl-mono"},e.subnet),"Device addresses come from it."),ne("Server public key",t("span",{class:"dl-keyrow"},[t("code",{class:"dl-mono"},e.public_key),D([v("copy")],()=>ue(e.public_key,"Public key copied"),"neutral",{title:"Copy",class:"cbi-button cbi-button-neutral dl-icon-only sm"})]))])])],[t("span",{class:"dl-sub"},"Port, MTU and keep-alive apply at once."),D("Save",()=>n.save({port:a.value,mtu:r.value,keepalive:l.value},"AmneziaWG saved"),"positive")])}function qr(n){let e=Pt(n.preset),o=n.obf??{},a=(s,l)=>t("span",{class:`dl-segs ${l}`},[0,1,2,3].map(c=>t("i",{class:c+o[s]).map(s=>`${s.toUpperCase()} ${o[s]}`);return i.length&&r.push(i.slice(0,2).join(" · ")+(i.length>2?` +${i.length-2}`:"")),["h1","h2","h3","h4"].some(s=>o[s]&&o[s]!==String(["h1","h2","h3","h4"].indexOf(s)+1))&&r.push("H1–H4 random"),o.i1&&r.push(o.i1.includes("0x8580")?"DNS-like first packet":"Signature packets"),o.header_protection_key&&r.push("Encrypted headers"),r.length||r.push(e?.id==="off"?"Plain WireGuard":"No values yet"),t("div",{class:"dl-bento-tile dl-disg"},[t("div",{class:"dl-bento-head"},[t("span",{class:"dl-metric-label"},"Disguise"),t("a",{href:`${L.url("admin/network/dawnline/server")}?server=${encodeURIComponent(n.id)}§ion=awg`},"Change")]),t("div",{class:"dl-disg-id"},[t("span",{class:"dl-disg-ic"},v(e?.ic??"shield")),t("span",{class:"dl-stack"},[t("b",{},e?e.title:"Custom"),t("span",{class:"dl-sub"},e?e.short:"Set by hand")])]),e?t("div",{class:"dl-disg-meters"},[t("span",{},"Stealth"),a(e.stealth,"acc"),t("span",{},"Speed"),a(e.speed,"ok")]):"",t("div",{class:"dl-disg-chips"},r.map(s=>t("span",{},s)))])}var An={id:"awg",label:"AmneziaWG",settingsCard:Fr,overviewTile:qr,connectBlock:Wr,qrText:n=>n.conf,appKey:{label:"Copy AmneziaVPN key",make:n=>Dn(n,`${n.server} · ${n.person} · ${n.name}`)},file:{label:"Download .conf",make:n=>({name:n.filename,text:n.conf})}};var Kr={awg:An};function Ie(n){return Kr[n?.core||"awg"]??An}function bt(n,e){return Ie(n.find(o=>o.id===e))}var Jr=2,Qt=new Set,zn=null,_o=!1;async function Vr(){if(document.visibilityState!=="visible"||!Qt.size)return;let n=await P.rev().catch(()=>null);if(!n)return;let e=zn!=null&&n.rev!==zn;zn=n.rev,e&&Qt.forEach(o=>o())}function Xt(n){return Qt.add(n),_o||(_o=!0,poll.add(Vr,Jr)),()=>Qt.delete(n)}var Hn="https://unpkg.com/maplibre-gl@6.14.0/dist",To="https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json",Co="https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",Yr={online:0,"24h":86400,"7d":7*86400,"30d":30*86400},Dt=null;function Zr(n){return n.appendChild(t("link",{rel:"stylesheet",href:`${Hn}/maplibre-gl.css`})),Dt||(Dt=import(`${Hn}/maplibre-gl.mjs`).then(o=>(o.getWorkerUrl()||o.setWorkerUrl(`${Hn}/maplibre-gl-worker.mjs`),o),()=>{throw Dt=null,new Error("Could not load the map library (no internet access from this browser?)")}),Dt)}function en(){let n=document.documentElement.getAttribute("data-darkmode");return n!=null?n==="true":window.matchMedia?.("(prefers-color-scheme: dark)").matches??!1}var Qr=10,Po=30,Xr=62,Do=4.5,ei=7,Nn="#3b82f6",tn="#8a8a8a";function Ao(n,e,o=.2,a=64){let[r,i]=n,[s,l]=e,c=s-r,d=c>180?s-360:c<-180?s+360:s,p=d-r,u=l-i,w=Math.hypot(p,u);if(w===0||o===0)return[n,[d,l]];let g=-u/w,m=p/w,k=w*o,H=(r+d)/2+g*k,B=(i+l)/2+m*k,E=[],y=Math.max(2,Math.floor(a));for(let S=0;S<=y;S+=1){let b=S/y,x=1-b;E.push([x*x*r+2*x*b*H+b*b*d,x*x*i+2*x*b*B+b*b*l])}return E}function Rn(n,e){let o=new Map;for(let a of n.geo.points){if(n.person&&a.person!==n.person||n.device&&a.device!==n.device||(e==="online"?!a.online:n.now-a.ts>Yr[e]))continue;let r=n.device?`${a.city}|${a.cc}`:n.person?`${a.device}|${a.city}|${a.cc}`:a.device,i=o.get(r);(!i||a.online&&!i.online||a.online===i.online&&a.ts>i.ts)&&o.set(r,a)}return[...o.values()]}function In(n,e){let o=0;return Rn(n,e).sort((a,r)=>Number(r.online)-Number(a.online)||r.ts-a.ts).map(a=>({...a,n:a.online?0:++o}))}var Je=class{constructor(e,o="online",a=380){this.cb=e;this.map=null;this.gl=null;this.markers=[];this.popup=null;this.theme=null;this.resize=null;this.fitBlind=!1;this.data=null;this.fitted=!1;this.fitKey=null;this.people=[];this.slots=[];this.merged=[];this.piles=new Map;this.dock=null;this.dockKey="";this.dockQuiet=!1;this.piledKeys=new Set;this.foldedKeys=new Set;this.targetZoom=null;this.before=null;this.hiddenKey="";this.focused=null;this.range=o,this.status=t("div",{class:"dl-map-status"}),this.card=t("div",{class:"dl-map-card","aria-live":"polite"}),this.el=t("div",{class:"dl-geomap",style:`height:${a}px`},[this.status,this.card])}async mount(e){this.data=e;try{this.gl=await Zr(this.el)}catch(a){this.status.textContent=a.message;return}this.map=new this.gl.Map({container:this.el,style:en()?To:Co,center:[e.geo.home?.lon??20,e.geo.home?.lat??50],zoom:1,renderWorldCopies:!1,attributionControl:{compact:!0},minZoom:1}),this.map.on("style.load",()=>this.layers()),this.map.on("move",()=>this.declutter()),this.map.once("idle",()=>{let a=this.el.querySelector(".maplibregl-ctrl-attrib");a?.classList.remove("maplibregl-compact-show"),a?.removeAttribute("open")}),this.resize=new ResizeObserver(()=>{!this.map||!this.el.clientWidth||!this.el.clientHeight||(this.map.resize(),this.fitBlind&&(this.fitKey=null,this.draw()))}),this.resize.observe(this.el);let o=en();this.theme=new MutationObserver(()=>{!this.map||en()===o||(o=en(),this.map.setStyle(o?To:Co))}),this.theme.observe(document.documentElement,{attributes:!0,attributeFilter:["data-darkmode"]})}layers(){if(this.map){this.hiddenKey="",this.map.setProjection({type:"globe"}),this.map.addSource("dl-areas",{type:"geojson",data:{type:"FeatureCollection",features:[]}}),this.map.addLayer({id:"dl-area",type:"circle",source:"dl-areas",paint:{"circle-radius":["interpolate",["exponential",2],["zoom"],2,6,6,26,9,140,12,900],"circle-color":["case",["get","online"],Nn,tn],"circle-opacity":["case",["get","online"],.12,.06],"circle-stroke-width":1,"circle-stroke-color":["case",["get","online"],Nn,tn],"circle-stroke-opacity":["case",["get","online"],.35,.15]}}),this.map.addSource("dl-trail",{type:"geojson",data:{type:"FeatureCollection",features:[]}}),this.map.addLayer({id:"dl-trail",type:"line",source:"dl-trail",layout:{"line-join":"round","line-cap":"round"},paint:{"line-color":tn,"line-width":1.5,"line-opacity":.85,"line-dasharray":[0,2.5]}}),this.map.addSource("dl-arcs",{type:"geojson",data:{type:"FeatureCollection",features:[]}});for(let e of[!1,!0])this.map.addLayer({id:e?"dl-arc-live":"dl-arc-recent",type:"line",source:"dl-arcs",filter:["==",["get","online"],e],layout:{"line-join":"round","line-cap":"round"},paint:{"line-color":e?Nn:tn,"line-width":2,"line-opacity":.85,"line-dasharray":[2,2]}});this.draw()}}setRange(e){this.range=e,this.fitKey=null,this.draw()}update(e){this.data=e,this.draw()}destroy(){this.dropCard();for(let e of this.piles.values())e.marker.remove();this.piles.clear(),this.theme?.disconnect(),this.resize?.disconnect(),this.map?.remove(),this.map=null}groups(e){let o=new Map;for(let a of e){let r=`${a.person}|${a.city||`${a.lat.toFixed(1)},${a.lon.toFixed(1)}`}|${a.cc}`,i=o.get(r);i||(i={key:r,person:a.person,lat:a.lat,lon:a.lon,city:a.city,country:a.country,cc:a.cc,asn:a.asn,org:a.org,online:!1,ts:0,points:[]},o.set(r,i)),i.points.push(a),i.online||(i.online=a.online),i.ts=Math.max(i.ts,a.ts)}return[...o.values()]}draw(){if(!this.map||!this.data||!this.map.getSource("dl-arcs"))return;let e=this.data,o=this.groups(Rn(e,this.range)),a=e.person||e.device?null:e.geo.home;for(let d of this.markers)d.remove();this.markers=[];let r=e.person||e.device?null:ni(o,a),i=o.map(d=>({g:d,at:r?.get(d.key)??[d.lon,d.lat]}));if(this.slots=[],this.map.getSource("dl-areas").setData({type:"FeatureCollection",features:i.map(({g:d})=>({type:"Feature",properties:{online:d.online,key:d.key},geometry:{type:"Point",coordinates:[d.lon,d.lat]}}))}),this.map.getSource("dl-arcs").setData({type:"FeatureCollection",features:a?i.map(({g:d,at:p})=>({type:"Feature",properties:{online:d.online,person:d.person,key:d.key},geometry:{type:"LineString",coordinates:Ao([a.lon,a.lat],p)}})):[]}),a){let d=t("span",{class:"dl-mk-host"});d.innerHTML=`${$t("server","dl-mk-host-ic")}`,this.dock=d.appendChild(t("span",{class:"dl-mk-dock"})),this.dockQuiet=this.dockKey!=="",this.dockKey="";let p=t("div",{class:"dl-mk-hub",title:`Home router${a.city?` · ${a.city}`:""}${a.org?` · ${a.org}`:""}`},[d,t("span",{class:"dl-mk-label chip"},a.city||"Home")]);p.addEventListener("mouseenter",()=>this.showMerged(a.city||"the server")),p.addEventListener("mouseleave",()=>this.focus(this.focused)),p.addEventListener("click",()=>this.zoomToMerged()),this.add(p,[a.lon,a.lat],!0)}let s=e.device?[...i].sort((d,p)=>Number(d.g.online)-Number(p.g.online)||d.g.ts-p.g.ts):[];this.map.getSource("dl-trail")?.setData({type:"FeatureCollection",features:s.length>1?[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:s.slice(1).flatMap((d,p)=>Ao(s[p].at,d.at))}}]:[]});let l=new Map(e.device?In(e,this.range).map(d=>[`${d.city}|${d.cc}`,d.n]):[]);this.people=[];for(let{g:d,at:p}of i){let u=d.points.length,w=e.people.find(H=>H.id===d.person);if(e.person){let H=e.device?this.stepMarker(d,p,w,l.get(`${d.points[0].city}|${d.points[0].cc}`)??0):this.placeMarker(d,p,w);this.add(H,p);continue}let g=d.points.map(H=>w?.devices.find(B=>B.id===H.device)?.kind??"other"),m=t("span",{class:"dl-mk-badge"});m.innerHTML=u<=2?g.map(H=>$t(H,"dl-mk-badge-ic")).join(""):String(u);let k=t("button",{type:"button",class:`dl-mk${d.online?" online":""}`,"aria-label":`${w?.name??"Someone"}: ${u} device${u===1?"":"s"} in ${d.city||"an unknown city"}`},[t("span",{class:"dl-mk-av"},[Ce(w?.name??"?"),m]),t("span",{class:"dl-mk-label below"},d.city||d.cc||"?")]);k.addEventListener("mouseenter",()=>this.focus(d.person)),k.addEventListener("mouseleave",()=>this.focus(null)),this.people.push({el:k,person:d.person}),k.addEventListener("click",H=>{H.stopPropagation(),this.openPopup(d,p,k)}),this.add(k,p,!1,w?.name??"Someone",`${d.city||d.cc||"?"} · ${d.online?"now":ie(d.ts,e.now)}`,d.key,d)}this.declutter();let c=i.map(d=>d.g.key).sort().join(";");if(c!==this.fitKey&&!this.popup){let d=this.fitted&&!this.fitBlind;if(this.fitBlind=!this.el.clientWidth||!this.el.clientHeight,this.fitKey=c,this.fitted=!0,a&&!i.length){let p={center:[a.lon,a.lat],zoom:12};d?this.glide(12,()=>this.map.flyTo({...p,duration:1200})):this.map.jumpTo(p)}else{let p=i.map(u=>u.at);a&&(p.length===0||this.range!=="online"||i.some(u=>u.g.online))&&p.push([a.lon,a.lat]),this.fit(p,d)}}this.status.textContent=i.length||a?"":"No locations yet",this.status.style.display=this.status.textContent?"":"none",this.focus(this.focused&&this.people.some(d=>d.person===this.focused)?this.focused:null)}add(e,o,a=!1,r,i,s,l){s&&this.foldedKeys.has(s)&&e.classList.add("merged"),s&&this.piledKeys.has(s)&&e.classList.add("piled"),e.dataset.key=s??"",e.classList.add("dl-mk-new"),requestAnimationFrame(()=>requestAnimationFrame(()=>e.classList.remove("dl-mk-new")));let c=new this.gl.Marker({element:e}).setLngLat(o).addTo(this.map);this.markers.push(c),this.slots.push({marker:c,el:e,at:o,fixed:a,who:r,where:i,g:l})}declutter(){if(!this.map)return;let e=this.map.getZoom();this.el.classList.toggle("dl-lod-far",e=Do&&e{let l=this.map.project(s.at),c=s.el.querySelector(":scope > .dl-mk-host, :scope > .dl-mk-av, :scope > .dl-mk-tile");return{x:l.x,y:l.y,r:(c?.offsetWidth||24)/2+3,fixed:s.fixed}}),a=o.filter(s=>s.fixed);this.merged=[],this.foldedKeys.clear();let r=this.targetZoom==null?1:Math.min(1,2**(this.targetZoom-this.map.getZoom()));o.forEach((s,l)=>{if(s.fixed)return;let c=this.slots[l],d=c.el.classList.contains("merged")?12:6,p=a.find(u=>Math.hypot(u.x-s.x,u.y-s.y)*r{let d=this.slots[c];!d||d.fixed||(o[c].fixed&&([s,l]=[0,0]),d.marker.setOffset([s,l]),ai(d.el,s,l))})}closePopup(e=!1){let o=this.popup;if(!o||o.card.classList.contains("leaving"))return;o.card.classList.add("leaving"),setTimeout(()=>{this.popup===o&&this.dropCard()},140);let a=this.before;if(this.before=null,!a)return;let r=()=>this.map?.flyTo({...a,duration:800});if(!e)return r();let i=!1,s=()=>{i||(i=!0,window.removeEventListener("pointerup",s,!0),window.removeEventListener("pointercancel",s,!0),setTimeout(r,0))};window.addEventListener("pointerup",s,!0),window.addEventListener("pointercancel",s,!0),setTimeout(s,1500)}dropCard(){this.popup?.off(),this.popup?.card.remove(),this.popup=null}showMerged(e){this.merged.length&&(dom.content(this.card,[t("div",{class:"dl-map-card-head"},[t("b",{},`Near ${e}`)," · click to zoom in"]),...this.merged.map(o=>t("div",{class:"dl-map-card-row"},[t("span",{},o.who),t("span",{class:"dl-faint"},o.where)]))]),this.card.classList.add("on"))}paintDock(){let e=this.dock;if(!e)return;let o=this.merged.map(r=>`${r.key}:${r.online?1:0}`).join("|");if(o===this.dockKey)return;this.dockKey=o,e.parentElement?.classList.toggle("docked",this.merged.length>0);let a=this.slots.find(r=>r.fixed).at;this.merged.length&&Ho(e,this.merged,this.faceActions(()=>[a]),this.dockQuiet),this.dockQuiet=!1}faceActions(e){return{click:(o,a)=>this.openFace(o,a,e()),hover:o=>this.focus(o?.g?.person??null)}}pileUp(e){let o=new Set;if(!this.data?.person&&!this.data?.device){let a=e.flatMap((l,c)=>!l.fixed&&this.slots[c].el.querySelector(":scope > .dl-mk-av")?[c]:[]),r=new Map(a.map(l=>[l,l])),i=l=>r.get(l)===l?l:i(r.get(l));for(let l of a)for(let c of a){if(c<=l)continue;let d=this.slots[l].el.classList.contains("piled")&&this.slots[c].el.classList.contains("piled");Math.hypot(e[l].x-e[c].x,e[l].y-e[c].y)this.slots[k]),d=c.map(zo),p=d.map(k=>k.key).sort().join(",");o.add(p);let u=[c.reduce((k,H)=>k+H.at[0],0)/c.length,c.reduce((k,H)=>k+H.at[1],0)/c.length],w=this.piles.get(p);if(!w){let k=t("span",{class:"dl-mk-pile-box"}),H=[...new Set(c.map(y=>y.g?.city||y.g?.cc||"?"))],B=t("div",{class:"dl-mk-pile"},[k,t("span",{class:"dl-mk-label below"},H.length===1?H[0]:`${c.length} people`)]);w={marker:new this.gl.Marker({element:B}).setLngLat(u).addTo(this.map),el:B,box:k,faces:d},B.addEventListener("mouseleave",()=>this.focus(this.focused));let E=w;B.addEventListener("click",y=>{y.stopPropagation(),this.zoomInTo(E.faces.map(S=>S.at),!1)}),this.piles.set(p,w)}w.faces=d;let g=w;Ho(w.box,d,this.faceActions(()=>g.faces.map(k=>k.at)));for(let k of l)this.slots[k].el.classList.add("piled"),Object.assign(e[k],{r:0,fixed:!0});let m=this.map.project(u);e.push({x:m.x,y:m.y,r:(w.el.offsetWidth||60)/2+3,fixed:!0})}}this.piledKeys=new Set(this.slots.filter(a=>a.el.classList.contains("piled")).map(a=>a.el.dataset.key??"")),this.slots.forEach((a,r)=>{(!e[r].fixed||a.fixed||a.el.classList.contains("merged"))&&a.el.classList.remove("piled")});for(let[a,r]of this.piles)o.has(a)||(this.piles.delete(a),r.el.classList.add("out"),setTimeout(()=>r.marker.remove(),200))}zoomToMerged(){!this.map||!this.merged.length||this.zoomInTo([this.slots.find(e=>e.fixed).at,...this.merged.map(e=>e.at)],!1)}openFace(e,o,a){if(!e.g)return;if(a.every(i=>nn(i,e.at)<1))return this.openPopup(e.g,e.at,o);let r=()=>{let i=this.slots.find(s=>s.el.dataset.key===e.key);i?.g&&!i.el.classList.contains("merged")&&!i.el.classList.contains("piled")&&this.openPopup(i.g,i.at,i.el)};this.zoomInTo(this.nearby(e.at),!0)?this.map.once("moveend",r):r()}nearby(e){return[e,...this.slots.filter(o=>!o.fixed&&o.at!==e&&nn(o.at,e)<=Po).map(o=>o.at)]}zoomInTo(e,o){let a=new this.gl.LngLatBounds;for(let p of e)a.extend(p);let r=e.some(p=>e.some(u=>nn(p,u)>Po)),i=this.map.cameraForBounds(a,{padding:50,maxZoom:r?12:Qr}),s=this.map.getZoom(),l=e.map(p=>this.map.project(p)),c=0;l.forEach((p,u)=>l.slice(u+1).forEach(w=>{let g=Math.hypot(p.x-w.x,p.y-w.y),m=s+Math.log2(Xr/Math.max(g,1e-6));m<=12&&(c=Math.max(c,m))}));let d=Math.min(12,Math.max(i?.zoom??0,c));return d<=s+.05?!1:(o&&!this.before&&(this.before={center:this.map.getCenter().toArray(),zoom:s}),this.map.flyTo({center:i?.center??a.getCenter(),zoom:d,duration:800}),!0)}placeMarker(e,o,a){let r=this.data.now,i=[...e.points].sort((u,w)=>Number(w.online)-Number(u.online)||w.ts-u.ts)[0],s=a?.devices.find(u=>u.id===i.device)?.kind??"other",l=e.points.length,c=t("span",{class:"dl-mk-tile"});c.innerHTML=$t(s,"dl-mk-tile-ic")+(l>1?`${l}`:"");let d=e.online?"now":ie(e.ts,r),p=t("button",{type:"button",class:`dl-mk place${e.online?" online":""}`,style:e.online?null:`--dl-mk-fade:${Math.max(.4,1-.6*(r-e.ts)/(30*86400)).toFixed(2)}`,"aria-label":`${l} device${l===1?"":"s"} in ${e.city||"an unknown city"}, ${d}`},[c,t("span",{class:"dl-mk-label below"},[e.city||e.cc||"?",t("span",{class:"dl-mk-when"},d)])]);return p.addEventListener("click",u=>{u.stopPropagation(),this.openPopup(e,o,p)}),p}stepMarker(e,o,a,r){if(e.online)return this.placeMarker(e,o,a);let i=ie(e.ts,this.data.now),s=t("button",{type:"button",class:"dl-mk place step","aria-label":`${r}: ${e.city||"an unknown city"}, ${i}`},[t("span",{class:"dl-mk-tile sm"},String(r)),t("span",{class:"dl-mk-label below"},[e.city||e.cc||"?",` · ${i}`])]);return s.addEventListener("click",l=>{l.stopPropagation(),this.openPopup(e,o,s)}),s}focus(e){this.focused=e;for(let s of this.people)s.el.classList.toggle("dim",!!e&&s.person!==e),s.el.classList.toggle("hl",s.person===e);let o=e?["case",["==",["get","person"],e],.85,.15]:.85;for(let s of["dl-arc-live","dl-arc-recent"])this.map?.getLayer(s)&&this.map.setPaintProperty(s,"line-opacity",o);if(this.card.classList.toggle("on",!!e),!e||!this.data)return;let a=this.data,r=a.people.find(s=>s.id===e),i=Rn(a,this.range).filter(s=>s.person===e).sort((s,l)=>Number(l.online)-Number(s.online)||l.ts-s.ts);dom.content(this.card,[t("div",{class:"dl-map-card-head"},[t("b",{},r?.name??e),` · ${i.length} device${i.length===1?"":"s"}`]),...i.map(s=>t("div",{class:"dl-map-card-row"},[t("span",{},r?.devices.find(l=>l.id===s.device)?.name??"Device"),t("span",{class:"dl-faint"},`${s.city||s.cc||"?"} · ${s.online?"now":ie(s.ts,a.now)}`)]))])}fit(e,o=!1){if(!e.length)return;let a=(d,p)=>{let u=Math.PI/180,w=(p[1]-d[1])*u,g=(p[0]-d[0])*u,m=Math.sin(w/2)**2+Math.cos(d[1]*u)*Math.cos(p[1]*u)*Math.sin(g/2)**2;return 12742*Math.asin(Math.sqrt(m))},r=[e.reduce((d,p)=>d+p[0],0)/e.length,e.reduce((d,p)=>d+p[1],0)/e.length],i=e;if(e.length>=5){let d=[...e].sort((p,u)=>a(r,p)-a(r,u));i=d.slice(0,Math.ceil(d.length*.9))}let s=new this.gl.LngLatBounds(i[0],i[0]);i.forEach(d=>s.extend(d));let l=this.el.clientHeight||380,c={padding:{top:Math.min(60,l/5),bottom:Math.min(40,l/8),left:48,right:48},maxZoom:this.data?.person?11:12};o?this.glide(this.map.cameraForBounds(s,c)?.zoom??null,()=>this.map.fitBounds(s,{...c,duration:1200})):this.map.fitBounds(s,{...c,duration:0})}glide(e,o){this.targetZoom=e,this.declutter(),this.map.once("moveend",()=>{this.targetZoom=null,this.declutter()}),o()}openPopup(e,o,a){let r=this.data,i=[e.city,e.cc||e.country].filter(Boolean).join(", "),s=[...new Set(e.points.map(y=>y.person))],l=e.points.sort((y,S)=>Number(S.online)-Number(y.online)||S.ts-y.ts).map(y=>{let S=r.people.find(x=>x.id===y.person),b=S?.devices.find(x=>x.id===y.device);return t("button",{type:"button",class:"dl-pop-row",click:()=>this.cb.openDevice(y.person,y.device)},[t("span",{class:`dl-pop-dot${y.online?" on":""}`}),t("span",{class:"dl-pop-name"},[t("b",{},S?.name??y.person),` · ${b?.name??"device"}`]),t("span",{class:"dl-faint dl-nowrap"},y.online?"now":ie(y.ts,r.now))])}),c=t("div",{class:"dl-pop"},[t("div",{class:"dl-pop-head"},[t("span",{class:"dl-pop-net"},v("globe")),t("div",{class:"dl-stack"},[t("strong",{},e.org||"Unknown network"),t("span",{class:"dl-faint"},[e.asn?`AS${e.asn} · `:"",i?`${i} · approximate`:"approximate location"])])]),t("div",{class:"dl-pop-list"},l),s.length===1?t("div",{class:"dl-pop-actions"},[t("button",{type:"button",class:"cbi-button cbi-button-positive important",click:()=>this.cb.openPerson(s[0])},`Open ${r.people.find(y=>y.id===s[0])?.name??"person"}`)]):""]);this.zoomInTo(this.nearby(o),!0),this.dropCard();let d=t("div",{class:"dl-root dl-popcard",role:"dialog"},[t("span",{class:"dl-popcard-tip"}),c]);document.body.appendChild(d);let p=this.el,u=a?.querySelector(".dl-mk-av, .dl-mk-tile")??a??null,w=()=>{if(!u)return;let y=u.getBoundingClientRect(),S=p.getBoundingClientRect(),b=y.left+y.width/2,x=y.top+y.height/2;d.classList.toggle("away",bS.right||xS.bottom);let M=d.offsetWidth,h=d.offsetHeight,f=y.top-h-12>=8||y.top>window.innerHeight-y.bottom,R=Math.min(Math.max(8,b-M/2),window.innerWidth-M-8);d.classList.toggle("above",f),d.classList.toggle("below",!f),d.style.left=`${R}px`,d.style.top=`${f?y.top-h-12:y.bottom+12}px`,d.style.setProperty("--tip-x",`${b-R}px`)},g=y=>{y.target?.closest(".dl-popcard, .maplibregl-marker")||this.closePopup(!0)},m=y=>{y.key==="Escape"&&this.closePopup()},k=y=>{y.target instanceof Element&&y.target.closest(".dl-popcard")||this.closePopup()},H=()=>this.closePopup();this.map.on("move",w),window.addEventListener("scroll",k,{capture:!0,passive:!0}),window.addEventListener("resize",w),document.addEventListener("pointerdown",g,!0),document.addEventListener("keydown",m);let B=Ae(H);window.addEventListener("pagehide",H),this.popup={card:d,off:()=>{this.map?.off("move",w),window.removeEventListener("scroll",k,!0),window.removeEventListener("resize",w),document.removeEventListener("pointerdown",g,!0),document.removeEventListener("keydown",m),B(),window.removeEventListener("pagehide",H)}};let E=window.setInterval(()=>{if(this.popup?.card!==d)return clearInterval(E);(!p.isConnected||!p.getClientRects().length)&&this.dropCard()},400);w()}};function ti(n,e=6){let o=n.map(a=>({x:a.x,y:a.y}));for(let a=0;a<16;a++){let r=!1;for(let i=0;i[a.x-n[r].x,a.y-n[r].y])}function ni(n,e){let o=new Map,a=e?[[e.lon,e.lat]]:[],r=i=>a.some(s=>nn(i,s)<1.3);for(let i of[...n].sort((s,l)=>s.key>>12)/1048575),c=(s&4095)/4096*2*Math.PI,d=[i.lon,i.lat];for(let p=0;p<24;p++){let u=c+p*2.39996,w=Math.min(8,l+p*.25);if(d=[i.lon+w*Math.sin(u)/(111.32*Math.cos(i.lat*Math.PI/180)),i.lat+w*Math.cos(u)/111.32],!r(d))break}a.push(d),o.set(i.key,d)}return o}function oi(n){let e=2166136261;for(let o=0;o>>0}function zo(n){return{key:n.el.dataset.key??"",who:n.who??"Someone",where:n.where??"",online:!!n.g?.online,at:n.at,badge:n.el.querySelector(".dl-mk-badge")?.innerHTML??"",g:n.g}}function Ho(n,e,o,a=!1){let r=e.length>3,i=()=>[...n.children].filter(m=>!m.classList.contains("out")),s=new Map(i().map(m=>[m,m.getBoundingClientRect().left])),l=n.getBoundingClientRect().width,c=new Map;n.querySelectorAll(".dl-mk-face:not(.out)").forEach(m=>c.set(m.dataset.key??"",m));let d=n.querySelector(".dl-mk-more:not(.out)"),p=m=>{Object.assign(m.style,{position:"absolute",left:`${m.offsetLeft}px`,top:`${m.offsetTop}px`,transform:""}),m.classList.add("out"),setTimeout(()=>m.remove(),200)},u=[];for(let m of e.slice(0,r?2:3)){let k=c.get(m.key);if(c.delete(m.key),!k){let E=t("button",{type:"button",class:`dl-mk-face${a?"":" in"}`,"data-key":m.key},[t("span",{class:"dl-mk-av"},Ce(m.who)),t("span",{class:"dl-mk-badge"})]);E.addEventListener("animationend",()=>E.classList.remove("in"),{once:!0}),k=E}let H=k,B=H.querySelector(".dl-mk-badge");B.innerHTML!==m.badge&&(B.innerHTML=m.badge),H.title=`${m.who} · ${m.where}`,H.setAttribute("aria-label",`${m.who}, ${m.where}`),H.classList.toggle("on",m.online),H.onclick=E=>{E.stopPropagation(),o.click(m,H)},H.onmouseenter=()=>o.hover(m),H.onmouseleave=()=>o.hover(null),u.push(H)}for(let m of c.values())p(m);if(r){if(!d){d=t("span",{class:`dl-mk-more${a?"":" in"}`});let m=d;m.addEventListener("animationend",()=>m.classList.remove("in"),{once:!0})}d.textContent=`+${e.length-2}`,u.push(d)}else d&&p(d);let w=null;for(let m of u)(w?w.nextElementSibling:n.firstElementChild)!==m&&(w?w.after(m):n.prepend(m)),w=m;for(let m of u){let k=s.get(m);if(k==null)continue;let H=k-m.getBoundingClientRect().left;Math.abs(H)<.5||(m.style.transition="none",m.style.transform=`translateX(${H}px)`,m.offsetWidth,m.style.transition="",m.style.transform="")}n.style.width="";let g=n.getBoundingClientRect().width;if(l&&Math.abs(g-l)>.5){n.style.width=`${l}px`,n.offsetWidth,n.style.width=`${g}px`;let m=()=>{n.style.width="",n.removeEventListener("transitionend",m)};n.addEventListener("transitionend",m),setTimeout(m,400)}}function nn(n,e){let o=Math.PI/180,a=Math.sin((e[1]-n[1])*o/2)**2+Math.cos(n[1]*o)*Math.cos(e[1]*o)*Math.sin((e[0]-n[0])*o/2)**2;return 12742*Math.asin(Math.min(1,Math.sqrt(a)))}function ai(n,e,o){let a=n.querySelector(":scope > .dl-mk-ptr"),r=Math.hypot(e,o);if(r<1){a?.remove();return}a||(a=t("span",{class:"dl-mk-ptr"},[t("i",{class:"line"}),t("i",{class:"spot"})]),n.prepend(a));let i=a.firstElementChild,s=a.lastElementChild;i.style.width=`${r}px`,i.style.transform=`rotate(${Math.atan2(-o,-e)}rad)`,s.style.transform=`translate(${-e}px, ${-o}px)`}function xt(n,e,o=!0){let a=[["online","Online now"],["24h","24h"],["7d","7 days"],["30d","30 days"]],r=t("div",{class:"dl-seg",role:"tablist"});for(let[i,s]of a)i==="online"&&!o||r.appendChild(t("button",{type:"button",role:"tab",class:i===n?"on":"","data-v":i,click:()=>{r.querySelectorAll("button").forEach(l=>l.classList.toggle("on",l.dataset.v===i)),e(i)}},s));return r}function wt(n){return`${L.url("admin/network/dawnline/server")}?${n?`server=${encodeURIComponent(n)}&`:""}section=people`}function ke(n,e){return`${L.url("admin/network/dawnline/person")}?id=${encodeURIComponent(n)}${e?`&device=${encodeURIComponent(e)}`:""}`}function ri(n){return n?new Date(n*1e3).toLocaleString("en-GB",{day:"numeric",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"}):"—"}function No(n,e,o=!1){return t("div",{class:"dl-kvrow"},[t("span",{class:"dl-kvrow-k"},n),t("button",{type:"button",class:`dl-kvrow-v copy${o?" dl-mono":""}`,title:"Copy",click:()=>ue(e,`${n} copied`)},[t("span",{},e),v("copy")])])}function on(n,e){return t("div",{class:"dl-kvrow"},[t("span",{class:"dl-kvrow-k"},n),t("span",{class:"dl-kvrow-v"},e)])}var Ro={connect:["ok","Connected","plug"],disconnect:["","Went offline","plug"],roam:["","Changed network","network"],device_added:["ok","Added","plus"],device_removed:["","Removed","trash"],device_keys:["","New keys","reset"]};function ii(n,e,o){let a=n.filter(r=>r.device===e&&Ro[r.type]).reverse().slice(0,12);return a.length?t("div",{class:"dl-dev-log"},a.map(r=>{let[i,s,l]=Ro[r.type],c=r.type==="connect"?[r.detail?t("span",{class:"dl-muted"},` from ${r.detail}`):"",r.where?t("span",{class:"dl-muted"},` · ${r.where}`):""]:r.type==="roam"?[t("span",{class:"dl-muted"},` · ${r.detail??""}`)]:r.type==="device_added"||r.type==="device_removed"||r.type==="device_keys"?[t("span",{class:"dl-muted"},Pe(r)==="portal"?" on the portal":Pe(r)==="admin"?" by you":"")]:[],d=new Date(r.ts*1e3);return t("div",{class:`dl-dev-log-row${Pe(r)==="admin"?" dl-ev-by-admin":""}`},[Pe(r)==="admin"?t("span",{class:"dl-ev-tile",title:"Done by you in LuCI"},v("admin")):t("span",{class:`dl-ev-tile ev ${i}`},v(l)),t("span",{class:"dl-row-main"},[t("span",{},s),...c]),t("span",{class:"dl-faint dl-nowrap",title:d.toLocaleString()},ie(r.ts,o))])})):t("div",{class:"dl-sub"},"No activity yet.")}async function Io(n,e,o){let a=await P.status(1).catch(()=>null),r=a?.people.find(s=>s.id===n),i=r?.devices.find(s=>s.id===e);a&&r&&i&&Be(r,i,{...o,geo:a.geo,now:a.now,today:Re(a.series),core:bt(a.servers,r.server)})}async function Be(n,e,o){let a=await W(()=>P.deviceConfig(e.id));if(!a)return;let r=o.core??Ie(null),i=e,s=n,l=o.geo,c=o.now,d=o.today??He(new Date),p=await r.connectBlock(a),u=t("div",{class:"dl-drawer-title"}),w=t("div",{}),g=t("div",{}),m=t("div",{},t("div",{class:"dl-sub"},"Loading…")),k=[],H=U=>{k=U.filter(F=>F.device===i.id),dom.content(m,ii(U,i.id,c))},B=async(U=!1)=>{let F=o.events?.();if(F&&!U)return H(F);let oe=await P.events(5e3).catch(()=>null);oe&&H(oe.events)},E="30d",y=null,S=t("div",{class:"dl-dplaces"}),b=()=>({geo:l,people:[s],now:c??Date.now()/1e3,person:s.id,device:i.id}),x=()=>{if(!l?.enabled)return;let U=In(b(),E);dom.content(S,U.length?U.map(F=>t("div",{class:"dl-dplace-row"},[t("span",{class:`dl-dplace-n${F.online?" live":""}`},F.online?v(i.kind):String(F.n)),t("span",{class:"dl-row-main dl-stack"},[t("span",{},[F.city||F.cc||"Unknown city",F.org?t("span",{class:"dl-muted"},` · ${F.org}`):""]),t("span",{class:"dl-mono dl-faint"},F.ip)]),t("span",{class:F.online?"dl-dplace-now":"dl-faint dl-nowrap"},F.online?"now":ie(F.ts,c))])):t("div",{class:"dl-sub"},"No locations in this period."))},M=()=>{dom.content(u,[t("span",{class:`dl-dcard-ic${i.online?" on":""}`},v(i.kind)),t("div",{class:"dl-stack"},[t("div",{class:"dl-title-row"},[t("h3",{},i.name),D([v("edit")],()=>R(),"neutral",{title:"Rename",class:"cbi-button cbi-button-neutral dl-icon-only sm"})]),t("span",{class:"dl-sub"},`${s.name} · ${je[i.kind]}`)])]);let U=i.spark.reduce((F,oe)=>F+oe,0);dom.content(w,t("div",{class:"dl-dstats"},[t("div",{class:"dl-dstats-cell wide"},[t("span",{class:"dl-metric-label"},"Status"),qt(i,c,"Waiting for the first connection")]),t("div",{class:"dl-dstats-cell"},[t("span",{class:"dl-metric-label"},"This month"),t("b",{},te(i.month[0]+i.month[1])),t("span",{class:"dl-sub dl-mono"},`↓ ${te(i.month[1])} ↑ ${te(i.month[0])}`)]),t("div",{class:"dl-dstats-cell"},[t("span",{class:"dl-metric-label"},"Last 7 days"),t("b",{},te(U)),wo(i.spark,120,22,d)])])),dom.content(g,t("div",{class:"dl-kv2"},[No("Tunnel address",i.address),i.hostname&&s.access!=="internet"?No("Local address",i.hostname):"",i.endpoint&&!l?.points.some(F=>F.device===i.id&&F.ip===i.endpoint)?on("Client IP",i.endpoint):"",on("Total",t("span",{class:"dl-kv-act"},[`↓ ${te(i.total[1])} · ↑ ${te(i.total[0])}`,t("button",{type:"button",class:"dl-linkbtn danger",click:()=>vt("device",i.id,i.name,()=>setTimeout(f,300))},"Reset")])),on("Added",`${ri(i.created)} · ${i.created_by==="portal"?"from the portal":"by you"}`),on("Public key",t("span",{class:"dl-mono dl-faint"},a.amnezia.client_pub_key?`${a.amnezia.client_pub_key.slice(0,16)}…`:"—"))])),dom.content(C,[D([v(i.disabled?"play":"pause"),i.disabled?" Enable":" Disable"],async()=>{await W(()=>P.deviceUpdate(i.id,void 0,!i.disabled),i.disabled?"Device enabled":"Device disabled")&&await f()},"neutral",i.disabled?{}:{class:"cbi-button cbi-button-neutral dl-btn-warn"}),D([v("key")," New keys"],async()=>{if(!await ae("Generate new keys?","The current configuration on this device stops working until it is imported again.","Generate",!0))return;await W(()=>P.deviceRotate(i.id),"New keys generated")&&(o.refresh(),O.close(),await Io(s.id,i.id,o))}),t("span",{class:"dl-spacer"}),D([v("trash")," Remove"],async()=>{await ae(`Remove ${i.name}?`,"The device is disconnected immediately and its configuration stops working.","Remove",!0)&&await W(()=>P.deviceDelete(i.id),"Device removed")&&(O.close(),o.refresh())},"negative")])},h=async()=>{let U=await P.status(1).catch(()=>null),F=U?.people.find(_=>_.id===s.id),oe=F?.devices.find(_=>_.id===i.id);!U||!F||!oe||(s=F,i=oe,l=U.geo,c=U.now,d=Re(U.series),M(),y?.update(b()),x())},f=async()=>{await h(),o.refresh()},R=()=>{let U=t("input",{type:"text",class:"cbi-input-text",value:i.name,maxlength:48});re(`Rename ${i.name}`,[t("div",{class:"cbi-value"},[t("label",{class:"cbi-value-title"},"Name"),t("div",{class:"cbi-value-field"},U)])],[le()," ",D("Save",async()=>{await W(()=>P.deviceUpdate(i.id,U.value,void 0),"Renamed")&&(ce(),await f())},"positive")]),setTimeout(()=>U.select(),50)},C=t("div",{class:"dl-drawer-actions"}),I=t("section",{class:"dl-dsec"},[t("div",{class:"dl-dsec-head"},[t("h4",{},"Connect")]),i.config_stale?t("div",{class:"dl-note warn"},[v("alert"),t("span",{},"This device has an older configuration: networks or DNS changed since it was set up. Import it again with the QR code, key or file below.")]):"",p]),Q=t("section",{class:"dl-dsec"},[t("div",{class:"dl-dsec-head"},[t("h4",{},"Activity"),t("div",{class:"dl-dsec-actions"},[t("button",{type:"button",class:"dl-linkbtn",click:()=>Ue({people:[s]},k,"csv",i.id)},"Export"),t("button",{type:"button",class:"dl-linkbtn danger",click:()=>Ke(`Clear ${i.name}'s activity`,`Removes events about ${i.name}.`,{device:i.id},()=>{B(!0),o.refresh()})},"Clear"),t("a",{href:`${L.url("admin/network/dawnline/diagnostics")}?tab=log`},"All activity")])]),m]),G=t("section",{class:"dl-dsec"},[t("div",{class:"dl-dsec-head"},t("h4",{},"Details")),g]),V="";l?.enabled&&(y=new Je({openPerson:U=>location.href=ke(U),openDevice:(U,F)=>location.href=ke(U,F)},E,220),V=t("section",{class:"dl-dsec"},[t("div",{class:"dl-dsec-head"},[t("h4",{},"Locations"),xt(E,U=>{E=U,y?.setRange(U),x()},!1)]),t("div",{class:"dl-dmap"},y.el),S]),x());let z=!i.handshake||i.config_stale,q=t("div",{class:"dl-stack gap16"},z?[w,I,G,V,Q]:[w,G,V,Q,I]);B();let X=()=>{h(),B()},de=Xt(X),fe=window.setInterval(X,3e4),O=uo(u,q,C,()=>{clearInterval(fe),de(),y?.destroy()});M(),y&&requestAnimationFrame(()=>y?.mount(b()))}function Bo(n,e,o,a){let r=a.core??Ie(null),i=()=>W(()=>P.deviceConfig(o.id)),s=[{label:"Show QR code",icon:v("qr"),run:async()=>{let l=await i();l&&re(`${o.name} · QR code`,t("div",{class:"dl-qr-pane"},[qe(ft(r.qrText(l)),"dl-qr"),t("span",{class:"dl-sub"},"Scan with AmneziaVPN or AmneziaWG on the device.")]),le("Close"))}},{label:r.file.label,icon:v("download"),run:async()=>{let l=await i();if(!l)return;let c=r.file.make(l);Ee(c.name,c.text,"application/octet-stream")}},r.appKey?{label:r.appKey.label,icon:v("copy"),run:async()=>{let l=await i();l&&ue(await r.appKey.make(l),"Key copied")}}:null,null,{label:"Rename",icon:v("edit"),run:()=>Be(e,o,a)},{label:"New keys",icon:v("key"),run:async()=>{await ae("Generate new keys?","The current configuration on this device stops working until it is imported again.","Generate",!0)&&await W(()=>P.deviceRotate(o.id),"New keys generated")&&a.refresh()}},{label:o.disabled?"Enable":"Disable",icon:v(o.disabled?"play":"pause"),warn:!o.disabled,run:async()=>{await W(()=>P.deviceUpdate(o.id,void 0,!o.disabled),o.disabled?"Device enabled":"Device disabled")&&a.refresh()}},{label:"Delete",icon:v("trash"),danger:!0,run:async()=>{await ae(`Remove ${o.name}?`,"The device is disconnected immediately and its configuration stops working.","Remove",!0)&&await W(()=>P.deviceDelete(o.id),"Device removed")&&a.refresh()}}];we(n,s)}function it(n,e){let o=t("input",{type:"text",class:"cbi-input-text",placeholder:je.phone,maxlength:48}),a="phone",r=t("div",{class:"dl-kinds",role:"radiogroup","aria-label":"Type"},so.map(s=>t("button",{type:"button",role:"radio",class:s===a?"on":"","aria-checked":s===a?"true":"false","data-kind":s,click:()=>{a=s,r.querySelectorAll("button").forEach(l=>{let c=l.dataset.kind===s;l.classList.toggle("on",c),l.setAttribute("aria-checked",c?"true":"false")}),o.placeholder=je[s]}},[v(s),t("span",{},je[s])]))),i=n.devices.length>=n.device_limit;re(`Add a device for ${n.name}`,[i?t("p",{class:"dl-hint"},`${n.name} already has ${n.devices.length} of ${n.device_limit} devices. As admin you can still add one.`):"",t("div",{class:"dl-fld"},[t("span",{class:"dl-fld-label"},"Type"),r]),t("label",{class:"dl-fld"},[t("span",{class:"dl-fld-label"},"Name"),o])],[le()," ",D("Add device",async()=>{let s=o.value.trim()||o.placeholder.replace(/^e\.g\. /,""),l=await W(()=>P.deviceCreate(n.id,s,a));l&&(ce(),Z(`${s} added`,"success",3e3),e.refresh(),await Io(n.id,l.id,e))},"positive")]),setTimeout(()=>o.focus(),50)}var Ge=1080,zt=1512,Oe=96,si="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif",li="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",At=n=>n.replace(/[&<>"']/g,e=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[e]);function di(n,e,o){let a=new URL(o),r=a.pathname.slice(1),i=Math.min(92,Math.floor((Ge-2*Oe)/(.58*(4+n.name.length)))),s=Ge-2*Oe,l=392,c=40,d=ft(o,2).replace("`${k}`;return``+p(Oe+82,Oe+42,36,"#a3a3a3",At(e))+p(Oe,276,i,"#ffffff",`Hi, ${At(n.name)}`,'font-weight="600"')+p(Oe,340,40,"#8a8a8a",`Scan to connect to ${At(e)}`)+``+d+`${At(r)}`+p(Ge/2,l+s+156,34,"#737373",At(a.host),'text-anchor="middle"')+""}async function ci(n){let e=new Image;e.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n)}`,await e.decode();let o=document.createElement("canvas");return o.width=Ge,o.height=zt,o.getContext("2d").drawImage(e,0,0,Ge,zt),new Promise((a,r)=>o.toBlob(i=>i?a(i):r(new Error("Could not draw the card")),"image/png"))}async function Oo(n){let e=await W(()=>P.personLinks(n));return e?e.link?{link:e.link,links:e.links??[]}:(Z("The personal portal is off. Turn it on in Settings.","warning"),null):null}async function an(n){let e=await Oo(n);e&&await ue(e.link,"Personal link copied")}async function Ht(n,e,o={}){let a=n.link,r=n.links;if(a===void 0){let g=await Oo(n.id);if(!g)return;a=g.link,r=g.links}if(!a){Z("The personal portal is off. Turn it on in Settings.","warning");return}let i=a,s=await W(()=>ci(di(n,e,i)));if(!s)return;let l=new File([s],`${n.id}-invite.png`,{type:"image/png"}),c=URL.createObjectURL(s),d=navigator,p=!!d.canShare?.({files:[l]}),u=()=>{URL.revokeObjectURL(c),ce()},w=p?D([v("link")," Share card"],async()=>{try{await d.share({files:[l],title:`Invite ${n.name}`})}catch{}},"positive"):D([v("download")," Download card"],()=>Ee(l.name,s),"positive");re(o.title??`Invite ${n.name}`,t("div",{class:"dl-invite"},[t("img",{src:c,alt:`Invite card for ${n.name}`}),t("div",{class:"dl-invite-side"},[t("p",{class:"dl-muted"},o.lead??`Send ${n.name} the card or the link. They open it, add their devices and connect — no account needed.`),t("button",{type:"button",class:"dl-invite-link",title:"Copy link",click:()=>ue(i,"Personal link copied")},[t("span",{},i.replace(/^https:\/\//,"")),v("copy")]),...(r??[]).filter(g=>g!==i).map(g=>t("button",{type:"button",class:"dl-invite-link alt",title:"Copy this link",click:()=>ue(g,"Link copied")},[t("span",{},g.replace(/^https?:\/\//,"")),t("span",{class:`dl-pill ${g.startsWith("http:")?"warn":""}`},g.startsWith("http:")?"HTTP":"Also"),v("copy")])),t("ol",{class:"dl-invite-steps"},[t("li",{},["Install ",t("b",{},"AmneziaVPN")," on the device"]),t("li",{},"Open the link or scan the code"),t("li",{},"Add the device and connect")]),t("div",{class:"dl-invite-actions"},[w,D([v("copy")," Copy link"],()=>ue(i,"Personal link copied"))])])]),[t("button",{class:"cbi-button cbi-button-neutral",click:u},"Done")],"wide")}function Nt(n,e){let o=n.servers.find(c=>c.id===e)??n.servers[0],a=n.people.filter(c=>c.server===o.id),r=new Set(a.map(c=>c.id)),i=a.flatMap(c=>c.devices),s=c=>a.reduce((d,p)=>{let u=c(p);return[d[0]+u[0],d[1]+u[1]]},[0,0]),l=o.series?.[o.series.length-1];return{...n,servers:[o],people:a,series:o.series??n.series,events:n.events.filter(c=>c.person?r.has(c.person):!0),geo:{...n.geo,points:n.geo.points.filter(c=>r.has(c.person))},totals:{people:a.length,devices:i.length,online:i.filter(c=>c.online).length,active:a.filter(c=>c.state==="active").length,today:l?[l.rx,l.tx]:[0,0],month:s(c=>c.month)}}}var Bn=class{constructor(){this.n=0;this.shown=0}next(){return++this.n}take(e){return e{let c=e.next(),d=await n.fetch(l).catch(()=>null);return d==null||!e.take(c)?null:(n.apply(d,s),d)},a=(s=!1)=>o(s,!1),r=()=>n.active?.()??!0?o(!0,!1):Promise.resolve(null);poll.add(r,n.every);let i=n.live?Xt(()=>void((n.active?.()??!0)&&o(!0,!0))):null;return{refresh:a,claim:()=>e.claim(),stop:()=>{poll.remove(r),i?.()}}}function yt(n){let e=document.activeElement;return!!n&&!!e&&e!==document.body&&n.contains(e)}function Le(n,e,o=!1){return o&&yt(n)?!1:(dom.content(n,e),!0)}function jo(n,e){let o=n,r=t("div",{class:"dl-choices"},[{v:"internet",ic:"globe",text:"Browse the internet through your router. No access to devices at home."},{v:"lan",ic:"home",text:"Reach devices at home (NAS, printer, cameras). Internet stays on their own connection."},{v:"both",ic:"shield",text:"Home devices and the internet, all through your router."}].map(i=>t("button",{type:"button",class:`dl-choice${i.v===o?" selected":""}`,"data-v":i.v,click:()=>{o=i.v,r.querySelectorAll(".dl-choice").forEach(s=>s.classList.toggle("selected",s.dataset.v===i.v)),e?.(i.v)}},[t("span",{class:"dl-choice-title"},[v(i.ic),ot[i.v]]),t("span",{class:"dl-choice-text"},i.text)])));return{el:r,get:()=>o}}function pi(n){let e=n.devices.length,o=Math.max(1,n.device_limit,e),a=Math.min(160,o*22+(o-1)*3);return t("div",{class:"dl-slotbar",title:`${e} of ${n.device_limit} devices`},[t("span",{class:"dl-slotbar-segs",style:`width: ${a}px`},Array.from({length:o},(r,i)=>t("i",{class:i>=n.device_limit?"over":in.state==="server_off"?n.paused:!["active","quota","expired"].includes(n.state),On=n=>n.state==="server_off"?n.paused:n.state!=="active",Wo=n=>On(n)?n.state==="server_off"?"paused":n.state:null;function mi(n,e){let o=nt(n.expires,e);return n.state==="quota"||n.state==="expired"||Fe(n,o)||!!n.quota_limit&&n.quota_used>=n.quota_limit*.9}function Go(n,e){return ct(n&&Cn(n,e)>=0?n:e,1)}var Fo=n=>n.people.map(e=>e.id).sort().join(" "),qo=!1,st=class{constructor(){this.list=t("div",{class:"dl-plist",role:"list"});this.filter=["all","online","attention","paused"].find(e=>e===new URLSearchParams(location.search).get("filter"))??"all";this.sort="seen";this.noFooter=!0;this.serverId=null;this.el=null}async load(){return P.status(30)}scope(e){return this.serverId?Nt(e,this.serverId):e}embed(e,o){return this.serverId=o,this.render(e)}person(e){return this.st.people.find(o=>o.id===e)}get today(){return Re(this.st.series)}deviceOpts(e){return{refresh:()=>this.refresh(),geo:this.st.geo,now:this.st.now,today:this.today,core:bt(this.st.servers,e.server)}}take(e,o){let a=this.scope(e),r=Fo(a)!==Fo(this.st);this.st=a,r?this.rebuild():(this.paintCards(o),this.decorate(o))}async update(){await this.poller?.refresh()}async refresh(){this.poller?.claim();let e=await P.status(30).catch(()=>null);e&&(this.st=this.scope(e),this.rebuild())}rebuild(){let e=new Map;for(let a of Array.from(this.list.children))a.dataset.sid&&e.set(a.dataset.sid,a);let o=this.st.people.map(a=>{let r=e.get(a.id)??t("div",{class:"dl-card",role:"listitem","data-sid":a.id});return this.renderCard(r,a.id)});dom.content(this.list,o.length?o:t("div",{class:"dl-plist-none"},this.st.servers.length?"No people yet. Add someone and send them their personal link.":"Set up the server first, then add people.")),this.decorate()}paintCards(e=!1){for(let o of this.st.people){let a=this.card(o.id);a&&!(e&&yt(a))&&this.renderCard(a,o.id)}}card(e){return this.list.querySelector(`[data-sid="${CSS.escape(e)}"]`)}render(e){let o=this.scope(e);this.st=o;let a=this,r=t("select",{class:"dl-select","aria-label":"Sort",change:s=>{a.sort=s.target.value,a.decorate()}},[t("option",{value:"seen"},"Last seen"),t("option",{value:"name"},"Name"),t("option",{value:"usage"},"Usage")]),i=t("div",{class:"dl-root"},[a.serverId?"":t("div",{class:"dl-pagehead"},[t("div",{class:"dl-stack"},[t("h2",{class:"dl-h1"},"People"),t("span",{class:"dl-muted dl-people-count"},this.countText())]),o.servers.length?D([v("plus")," Add person"],()=>a.openCreate(),"add"):""]),o.servers.length?"":t("div",{class:"alert-message warning"},["No server yet. ",t("a",{href:L.url("admin/network/dawnline/server")},"Run the setup wizard")," before adding people."]),t("div",{class:"dl-toolbar"},[t("div",{class:"dl-seg dl-people-tabs",role:"tablist"}),t("div",{class:"dl-toolbar-end"},[r,a.serverId?D([v("plus")," Add person"],()=>a.openCreate(),"add"):""])]),this.list]);return this.el=i,this.rebuild(),this.poller??(this.poller=Ve({fetch:()=>P.status(30),every:30,live:!0,active:()=>!!a.el?.isConnected,apply:(s,l)=>a.take(s,l)})),!qo&&new URLSearchParams(location.search).get("add")&&(qo=!0,setTimeout(()=>a.openCreate(),100)),Promise.resolve(i)}countText(){let e=this.st.totals;return`${e.people} ${e.people===1?"person":"people"} · ${e.devices} device${e.devices===1?"":"s"} · ${e.online} online`}decorate(e=!1){let o=this.el?.querySelector(".dl-people-count");o&&(o.textContent=this.countText());let a=this.st.people,r=this.today,i=g=>mi(g,r),s={all:a.length,online:a.filter(g=>g.online>0).length,attention:a.filter(i).length,paused:a.filter(g=>Uo(g)).length},l=this.el?.querySelector(".dl-people-tabs");if(l&&!(e&&yt(l))){let g={all:"All",online:"Online",attention:"Needs attention",paused:"Paused"};dom.content(l,Object.keys(g).map(m=>t("button",{type:"button",role:"tab",class:m===this.filter?"on":"",click:()=>{this.filter=m,this.decorate()}},[g[m],t("b",{class:m==="attention"&&s[m]?"warn":""},String(s[m]))])))}let c=g=>!(this.filter==="online"&&!g.online||this.filter==="attention"&&!i(g)||this.filter==="paused"&&!Uo(g)),d=g=>Wo(g)==="paused"?2:On(g)?1:0,p=[...a].sort((g,m)=>d(g)-d(m)||(this.sort==="name"?g.name.localeCompare(m.name):this.sort==="usage"?m.month[0]+m.month[1]-(g.month[0]+g.month[1]):m.online-g.online||m.last_seen-g.last_seen)),u=0;for(let g of p){let m=this.card(g.id);if(!m)continue;this.list.appendChild(m),m.classList.toggle("dl-off",On(g));let k=c(g);m.classList.toggle("dl-filtered",!k),k&&u++}let w=this.el?.querySelector(".dl-people-none")??null;a.length&&!u?(w??(w=t("div",{class:"dl-empty dl-people-none"},t("p",{},"No one here right now."))),w.previousElementSibling!==this.list&&this.list.after(w)):w?.remove()}async quick(e,o,a){await W(()=>P.personUpdate(e.id,o),a)&&await this.update()}renderCard(e,o){let a=this.person(o);if(!a)return dom.content(e,t("em",{},"This person was just removed.")),e;let r=this.today,i=nt(a.expires,r),s=Math.max(0,a.device_limit-a.devices.length),l=a.has_link??this.st.settings.portal_enabled,c=[],d=Wo(a);if(a.expires&&d!=="expired"){let m=Fe(a,i),k=i!=null&&i<0;c.push(t("span",{class:`dl-pill-ic${k?" bad":m?" warn":""}`,title:`Access ends ${Te(a.expires)}`},[v("calendar"),k?`ended ${Te(a.expires)}`:m?Wt(i):`until ${Te(a.expires)}`]))}a.hours&&d!=="hours"&&c.push(t("span",{class:"dl-pill-ic",title:"Allowed hours"},[v("clock"),a.hours.replace("-","–")]));let p=Ft(a.devices).map(m=>t("button",{type:"button",class:`dl-chip${m.disabled?" disabled":""}${m.online?" live":""}`,title:`${je[m.kind]} · ${m.address}${m.online?` · online from ${m.endpoint}`:m.handshake?` · seen ${ie(m.handshake,this.st.now)}`:""}`,click:k=>{k.preventDefault(),Be(a,m,this.deviceOpts(a))}},[v(m.kind),t("span",{class:"dl-chip-name"},m.name),!m.handshake&&!m.disabled?t("span",{class:"dl-chip-tag"},"not set up"):""]));p.push(t("button",{type:"button",class:"dl-chip add","aria-label":"Add device",title:s>0?"Add device":"Add device · over the limit, admins can still add",click:m=>{m.preventDefault(),it(a,this.deviceOpts(a))}},v("plus")));let u=[];a.expires&&Fe(a,i)&&d!=="expired"&&u.push(t("button",{type:"button",class:"dl-fix",click:()=>this.quick(a,{expires:Go(a.expires,r)},"Extended by 1 month")},"Extend 1 month"));let w=$e("more","More",m=>we(m.currentTarget,[{label:"Open",icon:v("open"),run:()=>{location.href=ke(a.id)}},l?{label:"Invite card",icon:v("qr"),run:()=>Ht(a,this.st.servers.find(k=>k.id===a.server)?.name??"Home")}:null,s>0?{label:"Add device",icon:v("plus"),run:()=>it(a,this.deviceOpts(a))}:null,null,{label:a.paused?"Resume":"Pause",icon:v(a.paused?"play":"pause"),warn:!a.paused,run:()=>this.togglePause(a)},{label:"Delete",icon:v("trash"),danger:!0,run:()=>this.remove(a.id)}].filter((k,H,B)=>k||H>0&&B[H-1])),"neutral","dl-icon-only"),g=t("div",{class:"dl-pcard-actions"},[l?$e("link","Copy link",()=>an(a.id),"neutral","dl-icon-only"):"",w]);return dom.content(e,t("div",{class:"dl-pcard"},[t("div",{class:"dl-pcard-main"},[t("div",{class:"dl-pcard-top"},[t("span",{class:`dl-avatar${a.online?" online":""}`},Ce(a.name)),t("div",{class:"dl-pcard-who"},[t("div",{class:"dl-card-head"},[t("a",{class:"dl-card-name",href:ke(a.id)},a.name),po(a),...c]),pi(a)])]),t("div",{class:"dl-chips"},p),u.length?t("div",{class:"dl-fixes"},u):""]),this.usageSide(a,g),d?this.stopStrip(a,d):""])),e}stopStrip(e,o){let a=this.today,r=ct(`${a.slice(0,8)}01`,1),i=()=>this.quick(e,{bonus_gb:String((e.bonus_gb||0)+10)},"+10 GB this month"),s={paused:["pause","warn","Paused","Devices can’t connect until you resume",["play","Resume",()=>this.togglePause(e)]],quota:e.quota_period==="month"?["chart","bad","Data limit reached",`Paused until it resets on ${Te(r)}`,["plus","+10 GB this month",i]]:["chart","bad","Data limit reached","Paused until the limit is raised",["edit","Change limit",()=>location.href=ke(e.id)]],expired:["calendar","bad",`Access ended ${Te(e.expires)}`,"Devices can’t connect",["calendar","Extend 1 month",()=>this.quick(e,{expires:Go(e.expires,a)},"Extended by 1 month")]],hours:["clock","warn","Outside allowed hours",`Access ${e.hours.replace("-","–")} (router time)`,null],no_server:["alert","warn","No server","Choose a server on their page",null]},[l,c,d,p,u]=s[o];return t("div",{class:`dl-pstrip ${c}`},[t("span",{class:`dl-need-ic ${c}`},v(l)),t("span",{class:"dl-pstrip-text"},[t("b",{},d),t("span",{class:"dl-faint"},p)]),u?D([v(u[0]),` ${u[1]}`],u[2]):""])}usageSide(e,o){let a=e.quota_used||e.month[0]+e.month[1],r=e.quota_limit?Math.min(100,e.quota_used/e.quota_limit*100):0,i=e.devices.reduce((p,u)=>p+(u.spark[u.spark.length-1]??0),0),s=e.rate?.[e.rate.length-1],l=e.online&&s&&this.st.now-s[0]<180,c=t("div",{class:`dl-usebar${r>=100?" bad":r>=90?" warn":""}`});if(e.quota_limit){let p=t("i",{class:"fill"});p.style.width=`${r}%`,c.appendChild(p),me(c,()=>[t("div",{class:"dl-tip-title"},`${r.toFixed(1)}% used`),t("div",{class:"dl-muted"},`${te(e.quota_used)} of ${te(e.quota_limit)} · ${te(Math.max(0,e.quota_limit-e.quota_used))} left`),t("div",{class:"dl-faint"},e.quota_period==="total"?"In total":`This month${e.bonus_gb?` · includes +${e.bonus_gb} GB extra`:""}`)])}else{let p=e.devices.map(u=>({d:u,v:u.month[0]+u.month[1]})).filter(u=>u.v>0).sort((u,w)=>w.v-u.v);p.forEach((u,w)=>{let g=t("i",{class:`c${Math.min(w,4)}`});g.style.flexGrow=String(u.v),c.appendChild(g)}),p.length&&me(c,()=>[t("div",{class:"dl-tip-title"},"This month by device"),...p.map((u,w)=>t("div",{class:"dl-tip-row"},[t("span",{class:`dl-swatch c${Math.min(w,4)}`}),t("span",{},u.d.name),t("b",{},te(u.v))]))])}let d=e.quota_limit?`${te(Math.max(0,e.quota_limit-e.quota_used))} left`:"no limit";return t("div",{class:"dl-pside"},[t("div",{class:"dl-pside-top"},[l?t("span",{class:"dl-pside-state live"},"Online"):t("span",{class:"dl-pside-state"},e.online?"Online":e.last_seen?"Offline":"Never connected"),o]),t("div",{class:"dl-use-num"},[t("b",{class:a?"":"dl-faint"},te(a)),t("span",{class:"dl-faint"},e.quota_limit?`of ${te(e.quota_limit)}`:e.quota_period==="total"&&e.quota_gb?"in total":"this month")]),c,l?t("div",{class:"dl-use-live",title:"Right now"},[`↓ ${ze(s[2])}`,t("span",{class:"dl-faint"},`↑ ${ze(s[1])}`)]):t("div",{class:"dl-faint dl-pside-foot"},i?`today ${te(i)} · ${d}`:d)])}async togglePause(e){await W(()=>P.personPause(e.id,!e.paused),e.paused?`${e.name} resumed`:`${e.name} paused`)&&await this.refresh()}async remove(e){let o=this.person(e);await ae(`Remove ${o?.name??e}?`,`All ${o?.devices.length??0} devices are disconnected immediately and the personal link stops working. Usage history is kept in backups.`,"Remove",!0)&&await W(()=>P.personDelete(e),"Person removed")&&await this.refresh()}openCreate(){let e=this.st;if(!e.servers.length){Z("Set up the server first.","warning");return}let o=t("input",{type:"text",class:"cbi-input-text",placeholder:"e.g. Myata",maxlength:48}),a=jo("internet"),r=t("input",{type:"number",class:"cbi-input-text",min:1,max:32,value:e.settings.default_device_limit}),i=t("input",{type:"date",class:"cbi-input-text"}),s=t("input",{type:"number",class:"cbi-input-text",min:0,step:"any",placeholder:"Unlimited"}),l=(u,w)=>t("button",{type:"button",class:"cbi-button cbi-button-neutral",click:()=>{i.value=w?ct(Re(e.series),w):""}},u),c=e.servers[0],d=!this.serverId&&e.servers.length>1?t("select",{class:"cbi-input-select"},e.servers.map(u=>t("option",{value:u.id},u.name))):null,p=(u,w,g)=>t("div",{class:"cbi-value"},[t("label",{class:"cbi-value-title"},u),t("div",{class:"cbi-value-field"},[w,g?t("div",{class:"cbi-value-description"},g):""])]);re("Add person",[p("Name",o),d?p("Server",d):"",t("div",{class:"cbi-value dl-block"},[t("label",{class:"cbi-value-title"},"Access"),t("div",{class:"cbi-value-field"},a.el)]),p("Devices",r,"How many devices they can add themselves."),p("End date",t("div",{class:"dl-actions"},[i,l("1 month",1),l("3 months",3),l("1 year",12),l("None",0)]),"Optional."),p("Monthly data (GB)",s,"Optional. They are paused when it runs out and resumed next month.")],[le()," ",D("Create and copy link",async()=>{let u=await W(()=>P.personCreate(o.value.trim(),"",d?.value??c.id,a.get(),String(Number(r.value)||e.settings.default_device_limit),i.value,s.value.trim(),"month"));u&&(u.link&&await ue(u.link,"Personal link copied"),this.showCreated(u.id,o.value.trim(),u.link,e.servers.find(w=>w.id===(d?.value??c.id))?.name??c.name),await this.refresh())},"positive")]),setTimeout(()=>o.focus(),50)}showCreated(e,o,a,r){if(a){Ht({id:e,name:o,link:a},r,{title:`${o} is ready`,lead:`Send ${o} the card or the link. They open it, add their devices and connect — no account needed.`});return}re(`${o} is ready`,[t("p",{},"Created. Turn on the personal portal in Settings to get a link, or add devices for them here.")],[t("button",{class:"cbi-button cbi-button-positive",click:ce},"Done")])}};function jn(n){let e=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\/(\d{1,2})$/.exec(n.trim());if(!e)return null;let[o,a,r,i]=e.slice(1,5).map(Number),s=Number(e[5]);if([o,a,r,i].some(d=>d>255)||s<8||s>30)return null;let l=o*2**24+a*2**16+r*2**8+i,c=2**(32-s);return{net:l-l%c,size:c}}var hi=(n,e)=>n.netjn(n));function rn(n){return n.split("/")[0].split(".").slice(0,3).join(".")}function Un(n){return`${n.trim()}.0/24`}function Ko(n,e,o){let a=n.trim(),r=/^\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(a)?jn(Un(a)):null;if(!r)return{text:"Three numbers, like 10.77.0.",bad:!0};if(!fi.some(s=>r.net>=s.net&&r.net+r.size<=s.net+s.size))return{text:"Use a private range: 10.x.x, 172.16–31.x or 192.168.x.",bad:!0};let i=e.find(s=>{let l=jn(s.cidr);return l!=null&&hi(r,l)});if(i){let s=i.cidr.endsWith("/24")?`${rn(i.cidr)}.x`:i.cidr,l=o&&o!==a?` Try ${o}.`:"";return{text:`${i.name} already uses ${s}.${l}`,bad:!0}}return{text:`Devices get ${a}.2 – ${a}.254, the router ${a}.1.`,bad:!1}}var Jo=(n,e)=>e.find(o=>o.from<=n&&n<=o.to)?.who??null,gi=n=>Number.isInteger(n)&&n>=1&&n<=65535;function Wn(n,e,o){if(!gi(n))return{text:"Use a port from 1 to 65535.",bad:!0};let a=Jo(n,e);return a?{text:`Used by ${a}. Choose another port.`,bad:!0}:{text:o,bad:!1}}function Rt(n,e,o){let a=o?`HTTPS here, plain HTTP for links on IP addresses on ${n+1}.`:"HTTPS on this port, opened on WAN.",r=Wn(n,e,a);if(r.bad||!o)return r;if(n===65535)return{text:"Links on IP addresses also need the next port: choose a lower one.",bad:!0};let i=Jo(n+1,e);return i?{text:`Links on IP addresses also need ${n+1}, used by ${i}. Choose another port.`,bad:!0}:r}var sn=["#3a83f7","#a78bfa","#f472b6","#f59e0b","#10b981","#22d3ee","#ef4444","#84cc16"],Gn=n=>t("i",{class:"dl-circle-dot",style:`background:${sn[n?.color??0]??sn[0]}`}),Ye=n=>n.access==="both"||n.access==="lan"&&!n.services?.length;function Vo(n,e,o){let a=se(n?.name??e.name??"",{placeholder:"NAS"}),r=se(n?.address??e.address??"",{placeholder:"192.168.1.10",class:"cbi-input-text dl-mono"}),i=se((n?.ports??e.ports??[]).join(", "),{placeholder:"All ports, or e.g. 445, 5000",class:"cbi-input-text dl-mono"}),s=(l,c)=>t("div",{class:"cbi-value"},[t("label",{class:"cbi-value-title"},l),t("div",{class:"cbi-value-field"},c)]);re(n?`Edit ${n.name}`:"Add service",[s("Name",a),s("Address",r),s("Ports",i)],[le()," ",D("Save",async()=>{let l=i.value.split(/[ ,]+/).filter(Boolean);await W(()=>P.serviceSet(n?.id??"",a.value,r.value,l),"Saved")&&(ce(),o())},"positive")])}var vi={_smb:"SMB",_afpovertcp:"AFP",_http:"Web",_https:"Web",_ssh:"SSH",_sftp:"SFTP","_sftp-ssh":"SFTP",_ipp:"Printer",_ipps:"Printer",_printer:"Printer","_pdl-datastream":"Printer",_airplay:"AirPlay",_raop:"AirPlay",_rfb:"Screen sharing",_googlecast:"Cast",_hap:"HomeKit",_rdp:"Remote desktop",_ftp:"FTP"},bi=[["Web",["80","443"]],["SMB",["445"]],["SSH",["22"]]];function xi(n){let e=new Map;for(let o of n.services){let a=vi[o.type.split(".")[0]];!a||!o.port||(e.get(a)??e.set(a,new Set).get(a)).add(String(o.port))}return e.size?[...e].map(([o,a])=>[o,[...a].sort((r,i)=>+r-+i)]):bi}function Yo(n,e,o){let a=n,r=null,i=!1,s=null,l=new Set,c=t("div",{class:"dl-list"}),d=t("div",{class:"dl-stack gap8"},t("span",{class:"dl-sub"},"Looking for devices at home…")),p=()=>{let k=a.services;dom.content(c,k.length?k.map(H=>t("div",{class:"dl-row"},[v("home"),t("span",{class:"dl-row-main dl-stack"},[t("b",{},H.name),t("span",{class:"dl-mono dl-faint"},`${H.address}${H.ports.length?` · ports ${H.ports.join(", ")}`:" · all ports"}`)]),D("Edit",()=>Vo(H,{},o)),D([v("trash")],async()=>{await ae(`Remove ${H.name}?`,"People limited to this service lose access to it.","Remove",!0)&&await W(()=>P.serviceDelete(H.id),"Removed")&&await o()},"neutral",{title:"Remove","aria-label":`Remove ${H.name}`})])):[t("div",{class:"dl-row dl-muted"},"No services yet: pick ports of a device below.")])};async function u(k,H){if(!l.has(k.address)){l.add(k.address),g();try{let B=a.services.find(y=>y.address===k.address);(H===null?B&&await W(()=>P.serviceDelete(B.id),`${B.name} removed`):await W(()=>P.serviceSet(B?.id??"",B?.name??(k.name||k.address),k.address,H),B?`${B.name} updated`:`${k.name||k.address} added`))&&await o()}finally{l.delete(k.address),g()}}}function w(k){let H=a.services.find(b=>b.address===k.address),B=!!H&&!H.ports.length,E=new Set(H?.ports??[]),y=l.has(k.address),S=(b,x,M)=>We(b,x,M,{disabled:y?"disabled":null,"aria-busy":y?"true":null});return t("div",{class:"dl-row"},[v(k.services.some(b=>b.type.startsWith("_ipp")||b.type.startsWith("_printer"))?"file":"computer"),t("span",{class:"dl-row-main dl-stack"},[t("b",{},k.name||k.address),t("span",{class:"dl-mono dl-faint"},k.address)]),t("div",{class:"dl-chips-row dl-host-ports"},[S("All ports",B,()=>u(k,B?null:[])),...xi(k).map(([b,x])=>{let M=!B&&x.every(h=>E.has(h));return S(`${b} ${x.join(", ")}`,M,()=>{let h=new Set(B?[]:E);for(let f of x)M?h.delete(f):h.add(f);u(k,h.size?[...h]:null)})})])])}function g(){if(i)return dom.content(d,t("span",{class:"dl-sub"},"Couldn't read the devices at home."));if(!r)return;let k=r;if(!k.hosts.length)return dom.content(d,t("span",{class:"dl-sub"},"No devices found in the home network right now."));let H=t("details",{class:"dl-params",open:s??!a.services.length?"":null},[t("summary",{},[v("chevron"),t("span",{},"Add from devices at home"),t("span",{class:"dl-pcount"},String(k.hosts.length))]),t("div",{class:"dl-params-body"},[t("span",{class:"dl-sub"},k.mdns?"Ports they announce over Bonjour. Pick what to open, or all ports.":"Devices that got an address from this router. Pick the ports to open, or all ports."),t("div",{class:"dl-list"},k.hosts.map(w))])]);H.addEventListener("toggle",()=>s=H.open),dom.content(d,H)}return P.homeHosts(e).then(k=>{r=k,g()}).catch(()=>{i=!0,g()}),p(),{el:t("div",{class:"dl-stack gap8"},[t("div",{class:"dl-iflead"},[t("div",{class:"dl-iflead-row"},[t("b",{},"Home services"),D([v("plus")," Add service"],()=>Vo(null,{},o))]),t("span",{class:"dl-sub"},"Home-only people can be limited to these instead of whole networks (chosen on their page). Shared by all servers.")]),c,d]),update(k){a=k,p(),g()}}}function ln(n,e,o,a){let r=new Set(n.circles.filter(g=>g.server===e).map(g=>g.color)),i=o?.color??sn.findIndex((g,m)=>!r.has(m));i<0&&(i=0);let s=se(o?.name??"",{placeholder:"Family"}),l=n.people.filter(g=>g.server===e).sort((g,m)=>g.name.localeCompare(m.name)),c=new Set(l.filter(g=>o&&g.circle===o.id).map(g=>g.id)),d=t("div",{class:"dl-swatches",role:"radiogroup","aria-label":"Colour"}),p=()=>dom.content(d,sn.map((g,m)=>t("button",{type:"button",role:"radio",class:`dl-swatch${m===i?" on":""}`,style:`--sw:${g}`,"aria-checked":m===i?"true":"false","aria-label":`Colour ${m+1}`,click:()=>{i=m,p()}})));p();let u=t("div",{class:"dl-chips-row"},l.map(g=>{let m=g.circle&&g.circle!==o?.id?n.circles.find(k=>k.id===g.circle):void 0;return t("button",{type:"button",class:`dl-chipbtn${c.has(g.id)?" on":""}`,title:Ye(g)?m?`Now in ${m.name}`:"":`${g.name} has no home access: their devices aren't reachable anyway`,click:k=>{c.delete(g.id)||c.add(g.id),k.currentTarget.classList.toggle("on",c.has(g.id))}},[g.name,Ye(g)?m?t("b",{},m.name):"":t("b",{},"internet")])})),w=(g,m)=>t("div",{class:"cbi-value"},[t("label",{class:"cbi-value-title"},g),t("div",{class:"cbi-value-field"},m)]);re(o?`Edit ${o.name}`:"New circle",[w("Name",s),w("Colour",d),w("People",u),t("p",{class:"dl-sub"},"Devices of people in one circle reach each other. A person is in one circle at a time.")],[o?D("Delete",async()=>{await W(()=>P.circleDelete(o.id),`${o.name} deleted`)&&(ce(),a())},"negative"):"",t("span",{class:"dl-spacer"}),le()," ",D("Save",async()=>{await W(()=>P.circleSet(o?.id??"",e,s.value,i,[...c]),"Saved")&&(ce(),a())},"positive")],"dl-circle-modal")}function Zo(n,e,o){let a=n.circles.filter(r=>r.server===e);return t("div",{class:"dl-chips-row dl-circles"},[...a.map(r=>{let i=n.people.filter(s=>s.circle===r.id).map(s=>s.name);return t("button",{type:"button",class:"dl-chip",title:`Edit ${r.name}`,click:()=>ln(n,e,r,o)},[Gn(r),t("b",{},r.name),t("span",{class:"dl-faint"},i.length?i.join(", "):"nobody yet")])}),t("button",{type:"button",class:"dl-chip add",title:"New circle","aria-label":"New circle",click:()=>ln(n,e,null,o)},v("plus"))])}function Fn(n,e){let o=n.people.filter(p=>p.server===e.id),a=(p="")=>t("span",{class:"dl-yes"},[v("check"),p]),r=()=>t("span",{class:"dl-faint"},"—"),i=p=>{let u=new Set(p.map(w=>w.access==="lan"&&w.services?.length?"services":w.home_nets?.length?"some":"all"));return u.size||u.add("all"),a([...u].map(w=>({all:"all networks",some:"their networks",services:"services"})[w]).join(" / "))},s=()=>e.mesh==="off"?r():e.mesh==="circles"?a("circle"):a(),l=e.lan_like?"like home":"direct",c=(p,u,w)=>t("tr",{},[t("td",{},[t("b",{},p),t("div",{class:"dl-sub"},`${u.length} ${u.length===1?"person":"people"}`)]),...w.map(g=>t("td",{},g))]),d=p=>o.filter(u=>u.access===p);return t("section",{class:"dl-setsec"},[t("div",{class:"dl-setsec-body"},[t("div",{class:"dl-panel-head"},[t("h3",{},"Who reaches what"),t("span",{class:"dl-spacer"}),t("span",{class:"dl-sub"},"From the rules on this server")]),t("div",{class:"dl-reach-wrap"},t("table",{class:"dl-table dl-reach"},[t("tr",{},["","Internet","Home","This router","Each other"].map(p=>t("th",{},p))),c("Internet",d("internet"),[a(l),r(),t("span",{class:"dl-faint"},"DNS"),r()]),c("Home",d("lan"),[t("span",{class:"dl-faint"},"their own"),i(d("lan")),a(),s()]),c("Both",d("both"),[a(l),i(d("both")),a(),s()])])),t("p",{class:"dl-sub"},"Home devices reach the devices of people with home access, on the networks those people reach. Paused, ended and over-the-limit people reach nothing.")])])}function Qo(n,e){let o=n.people.filter(d=>d.server===e.id).flatMap(d=>d.devices.map(p=>({id:p.id,label:`${d.name} · ${p.name}`}))).sort((d,p)=>d.label.localeCompare(p.label)),a="@addr",r=(d,p)=>{let u=t("select",{class:"cbi-input-select","aria-label":d},[...o.map(k=>t("option",{value:k.id,selected:k.id===p?"selected":null},k.label)),t("option",{value:a,selected:p===a?"selected":null},"Address")]),w=se("",{placeholder:d,class:"cbi-input-text dl-mono"}),g=t("div",{class:"dl-check-end"},[u,w]),m=()=>w.hidden=u.value!==a;return u.addEventListener("change",m),m(),{el:g,value:()=>u.value===a?w.value.trim():u.value}},i=r("10.0.1.11",o[0]?.id??a),s=r("10.0.1.20:445",a),l=t("div",{class:"dl-stack gap8"}),c=async()=>{let d=await W(()=>P.accessCheck(i.value(),s.value()));if(!d)return;let p=d.steps.findIndex(u=>!u.ok);dom.content(l,[t("div",{class:`dl-verdict ${d.ok?"ok":"bad"}`},[t("b",{},d.ok?"Allowed":"Blocked"),t("span",{class:"dl-sub"},d.ok?"Every step lets it through":`Stops at step ${p+1} of ${d.steps.length}`)]),t("ul",{class:"dl-checks"},d.steps.map(u=>t("li",{},[t("span",{class:`dl-check-icon ${u.ok?"ok":"error"}`},v(u.ok?"check":"x")),t("div",{class:"dl-check-body"},[t("div",{class:"dl-check-title"},u.title),u.detail?t("div",{class:"dl-check-detail"},u.detail):""])])))])};return t("section",{class:"dl-setsec"},[t("div",{class:"dl-setsec-body"},[t("div",{class:"dl-panel-head"},[t("h3",{},"Check access"),t("span",{class:"dl-spacer"}),t("span",{class:"dl-sub"},"Why something does or does not connect")]),t("div",{class:"dl-check-form"},[i.el,t("span",{class:"dl-faint"},"→"),s.el,D("Check",c)]),l])])}var dn={app:"Dawnline",amneziawg:"AmneziaWG",packages:"System packages",pkgs:"System packages"};function Ze(n){return(n.startsWith("check")?n.slice(6)||"all":n).split(/[:@ ]/)[0]}function cn(n){return Ze(n.action==="check"?`check:${n.component??""}`:n.component??"")}function Xo(n){return n=Math.max(0,Math.floor(n)),`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function ea(n,e){return!n?.from&&!n?.to?e:n.from&&n.to&&n.from!==n.to?`${n.from} → ${n.to}`:n.to??n.from??e}function ta(n,e){let o=n.check?.components??{},a=e==="all"?["app","amneziawg","packages"]:[e],r=[],i;for(let l of a){let c=o[l];if(c){if(c.error)return{tone:"warn",text:c.error};l==="packages"&&c.updates?r.push(`${c.updates} system package${c.updates===1?"":"s"}`):l!=="packages"&&c.update&&c.installed&&c.latest&&(r.push(`${dn[l]} ${c.latest}`),e!=="all"&&(i=c.latest))}}if(r.length)return{tone:"acc",text:`Update available: ${r.join(", ")}`,update:i};let s=a.length===1?o[a[0]]:null;return s?.status==="dev"?{tone:"acc",text:`Installed version is newer than the release (${s.latest})`}:s?.note?{tone:"warn",text:s.note}:{tone:"ok",text:a.length>1?"Everything is up to date":"Latest version is installed"}}function na(n,e,o,a){return e?n.id===e:o&&n.id===o?!1:n.state==="running"||a>0&&n.started>=a}var oa=n=>new Promise(e=>setTimeout(e,n));async function It(n,e,o){let a=o?cn(o):Ze(n),r=o?o.action==="check":n.startsWith("check"),i=Date.now(),s=t("b",{},dn[a]??(a==="all"?"All components":"Dawnline")),l=t("span",{class:"dl-pill dl-mono"},e.version??""),c=t("span",{class:"dl-pill info",hidden:!0}),d=t("span",{},"0:00"),p=t("pre",{class:"dl-log"},"Operation started. Waiting for log output…"),u=t("div",{}),w=t("div",{class:"dl-op-actions"}),g=[],m=h=>dom.content(w,h),k=(h=!1)=>le("Close",h);re(e.title,t("div",{class:"dl-op"},[t("div",{class:"dl-op-head"},[s,e.version?l:"",c,t("span",{class:"dl-spacer"}),t("span",{class:"dl-faint dl-op-timer"},[v("clock"),d])]),t("div",{class:"dl-op-loghead"},[t("b",{},"Operation log"),$e("copy","Copy log",()=>ue(g.join(` -`),"Log copied"))]),p,u]),[w],"wide"),m([t("button",{class:"cbi-button cbi-button-neutral spinning",type:"button",disabled:"disabled"},r?"Checking…":"Working…")]);let H=o??null,B=o?.id,E,y=0,S=h=>{B!==h.id&&(B=h.id,e.onJob?.(h))};if(o)e.onJob?.(o);else try{let h=await P.updatesStatus().catch(()=>null);E=h?.job?.id,y=h?.now??0;let f=await P.updatesRun(n);f.job&&f.job.state==="running"&&f.job.id!==E&&(H=f.job,S(f.job))}catch(h){return g=[ve(h)],p.textContent=g[0],dom.content(u,t("div",{class:"dl-comp-status warn"},[v("alert"),t("span",{},ve(h))])),m([k(!0)]),Z(ve(h),"error"),null}let b=null,x=0;for(;;){if(await oa(1e3),b=await P.updatesStatus().catch(()=>null),!b){if(++x>60)break;continue}x=0;let h=b.job;if(!h||!na(h,B,E,y)){if(Date.now()-i>15e3)break;continue}if(S(h),H=h,h.log.length){g=h.log;let f=p.scrollTop+p.clientHeight>=p.scrollHeight-8;p.textContent=g.join(` -`),f&&(p.scrollTop=p.scrollHeight)}if(l.textContent=ea(h,e.version??""),!l.isConnected&&l.textContent&&s.after(l),d.textContent=Xo((h.finished??b.now)-h.started),h.state==="running"){c.hidden=!h.phase,c.textContent=h.phase;continue}break}if(p.scrollTop=p.scrollHeight,c.hidden=!1,!H||H.state==="running")return c.className="dl-pill warn",c.textContent="No answer",dom.content(u,t("div",{class:"dl-comp-status warn"},[v("alert"),t("span",{},"The router stopped answering. The job may still finish: reopen Components in a minute.")])),m([k()]),e.onDone?.(b),H;if(H.state==="failed")return c.className="dl-pill bad",c.textContent="Failed",dom.content(u,t("div",{class:"dl-comp-status bad"},[v("x"),t("span",{},[t("b",{},H.error??"Operation failed"),r?"":". Nothing else was changed."])])),m([D("Copy log",()=>ue(g.join(` -`),"Log copied")),k(!0)]),Z(`${dn[a]??"Update"}: ${H.error??"failed"}`,"error"),e.onDone?.(b),H;if(c.className="dl-pill ok",c.textContent="Finished",r&&b){let h=ta(b,a);if(dom.content(u,t("div",{class:`dl-comp-status ${h.tone}`},[v(h.tone==="ok"?"check":h.tone==="warn"?"alert":"download"),t("span",{},h.text)])),Z(h.text,h.tone==="warn"?"warning":"success"),e.onDone?.(b),h.update&&e.onUpdate){let f=b;m([k(),D(`Update to ${h.update}`,()=>e.onUpdate(f),"positive")])}else m([k()]),h.tone==="ok"&&setTimeout(()=>u.isConnected&&ce(),1200);return H}if(a==="app"&&H.to){let h=H.to,f=t("span",{},"Waiting for the router to restart its services…");dom.content(u,t("div",{class:"dl-comp-status ok"},[v("check"),t("span",{},[t("b",{},`Dawnline ${h} is installed. `),f])]));let R=()=>{ui.menu?.flushCache(),location.reload()};m([k(),D("Reload now",R,"positive")]),Z(`Dawnline updated to ${h}`,"success",6e3);for(let C=1;C<=30;C++)if(f.textContent=`Waiting for the router to restart its services (${C} of 30)…`,await oa(1500),(await P.updatesStatus().catch(()=>null))?.version===h)return f.textContent="Services are back. Reloading…",setTimeout(R,800),H;return f.textContent="Services restarted. Reload the page to use the new version.",H}let M=a==="pkgs"?`Updated ${[...H.result?.pkgs?.updated??[],...H.result?.pkgs?.installed??[]].join(", ")||"system packages"}`:a==="amneziawg"?`AmneziaWG${H.to?` ${H.to}`:""} is installed`:"Operation completed";return dom.content(u,t("div",{class:"dl-comp-status ok"},[v("check"),t("span",{},M)])),m([k()]),Z(M,"success"),e.onDone?.(b),H}var wi={https:"HTTPS for the portal",acme:"ACME certificates",home:"the home-like link",awg:"AmneziaWG"};async function aa(n,e,o,a){return!await ae(`Install ${e}?`,o,"Install")||(await It(n,{title:`Installing ${e}`}))?.state!=="done"?!1:(setTimeout(()=>a?.(),4e3),!0)}function pn(n){return aa("amneziawg:auto","AmneziaWG","Dawnline installs the AmneziaWG build made for this firmware and loads it. If the network service has to restart to learn it, connections drop for a few seconds.",n)}async function Bt(n,e,o){return n==="awg"?pn(o):e.length?aa(`pkgs:${e.join(",")}`,wi[n],`${e.join(", ")} from the OpenWrt feeds. Dawnline sets the rest up when they arrive.`,o):!0}async function ra(n,e){if(n==="awg")return pn(e);let o=await W(()=>P.updatesStatus());return o?Bt(n,o.needs?.[n]??[],e):!1}var yi=[["wan","WAN"],["ethernet","Ethernet"],["wifi","Wi-Fi"],["vpn","VPN & tunnels"],["other","Other"]],ki={wan:"globe",ethernet:"ethernet",bridge:"bridge",wifi:"wifi",vpn:"tunnel",other:"link"};function ia(n,e,o){let a=n.id,r=e,i=t("div",{class:"dl-stack gap16"},t("section",{class:"dl-setsec"},t("div",{class:"dl-setsec-body"},t("p",{class:"dl-muted"},"Loading interfaces…")))),s,l=!0,c="",d=!0,p=!0,u="all",w=!1,g=Yo(r,a,o),m=new Set,k="",H=()=>JSON.stringify([p,l,l?"":c,d,[...m].sort()]),B=()=>s.detected.lan||s.saved.lan||"",E=()=>(l?s.detected.wan||s.saved.wan:c)||"",y=()=>new Map(s.devices.map(z=>[z.name,z])),S=()=>{let z=y();return[...d&&B()?[B()]:[],...[...m].filter(X=>X!==B())].filter(X=>X!==E()).map(X=>z.get(X)??{name:X,nets:[],missing:!0})},b=(z,q)=>{s=z,q&&(l=z.config.auto_wan,c=z.config.wan_device||z.detected.wan||z.saved.wan||"",d=z.config.auto_lan,p=z.config.lan_like,u=z.config.mesh??(z.config.device_mesh?"all":"off"),m=new Set(z.config.lan_devices),k=H()),G()},x=async z=>{let q=await P.interfaces(a).catch(X=>(Z(X.message,"error"),null));q&&b(q,z)};function M(z){let q=d&&z.name===B(),X=!!z.own||!!z.master||z.name===E()||q;return q||m.has(z.name)||!X&&(z.nets.length>0||!!z.missing)}function h(z){let q=d&&z.name===B(),X=z.name===E(),de=!q&&m.has(z.name),O=!(!!z.own||!!z.master||X||q)&&(z.nets.length>0||de||!!z.missing),U=(de||q)&&!z.zone&&!z.missing,F=z.missing?"Not present right now":z.own?"This server":z.master?`Port of ${z.master}`:X?`Internet${z.zone?` · zone ${z.zone}`:""}`:z.nets.length?z.nets.join(", "):"No IPv4 network",oe=t("button",{type:"button",class:`dl-if${de?" sel":""}${q?" auto":""}${!O&&!de&&!q?" off":""}${U?" warn":""}`,"aria-pressed":de||q?"true":"false","aria-disabled":O?null:"true",click:()=>{O&&(m.has(z.name)?m.delete(z.name):m.add(z.name),G())}},[t("span",{class:"dl-if-ic"},v(ki[z.kind]??"link")),t("span",{class:"dl-if-main"},[t("span",{class:"dl-if-name"},z.name),t("span",{class:"dl-if-sub"},F)]),q?t("span",{class:"dl-if-badge ok"},"Auto"):de?t("span",{class:"dl-if-check"},v("check")):""]);return me(oe,()=>[t("div",{class:"dl-tip-title"},z.name),t("div",{class:"dl-muted"},[z.logical?`Interface ${z.logical}`:"No netifd interface",z.zone?` · zone ${z.zone}`:" · no firewall zone"]),z.members.length?t("div",{class:"dl-muted"},`Ports: ${z.members.join(", ")}`):"",z.nets.length?t("div",{class:"dl-mono"},z.nets.join(", ")):"",U?t("div",{class:"dl-warn"},"Not in a firewall zone: the firewall rejects this traffic."):"",z.master?t("div",{class:"dl-muted"},`Choose ${z.master} to include it.`):""]),oe}function f(){let z=s.like_home;return!p||!s.config.lan_like||!n.enabled?"":!s.needs?.length&&z.active&&z.bridged?"ok":"warn"}function R(){let z=s.like_home;return p?s.needs?.length?[t("span",{class:"dl-warn"},`Needs ${s.needs.join(" and ")}.`)," Until they are installed, internet traffic goes straight to the WAN."]:s.config.lan_like?n.enabled?z.active&&z.bridged?["Internet traffic enters ",t("span",{class:"dl-mono"},z.dev??"")," as ",t("span",{class:"dl-mono"},z.address??""),", so whatever handles home traffic (proxies, filters, DNS) handles it too."]:[t("span",{class:"dl-warn"},`Not working: ${z.error??"the link is down"}`)," Internet traffic goes straight to the WAN for now."]:["Internet traffic enters the router from your LAN, so whatever handles home traffic (proxies, filters, DNS) handles it too."]:["Internet traffic will enter the router from your LAN, so it is handled like any home device. Save to turn on."]:["Off: internet traffic goes straight to the WAN, past whatever handles home traffic on this router."]}let C={off:"Devices of different people never reach each other; a person's own devices don't either.",all:"Devices of people with home access reach each other, like home devices do. Internet-only people never.",circles:"Within a circle: family sees family, guests see guests. Everyone reaches their own devices. Internet-only people never."};function I(z,q,X,de,fe="",O){return t("div",{class:O?"dl-setrow head":"dl-setrow"},[t("div",{class:"dl-lh-main"},[t("span",{class:`dl-need-ic ${fe}`},v(z)),t("div",{class:"dl-stack"},[t("span",{class:"dl-setrow-label"},q),t("span",{class:"dl-sub"},X),O??""])]),t("div",{class:"dl-setrow-ctl"},de)])}let Q=(z,q)=>{let X=de=>t("span",{class:"dl-mono"},de);return z?t("span",{},[" Now: ",X(z),...q&&q!==z?[", was ",X(q)]:[],"."]):t("span",{},q?[" Not found now: using ",X(q),"."]:[" Not found."])};function G(){let z=t("select",{class:"cbi-input-select","aria-label":"Internet interface",change:T=>{c=T.target.value,G()}},s.devices.filter(T=>!T.own&&!T.master&&T.zone&&!T.missing).map(T=>t("option",{value:T.name,selected:T.name===c?"selected":null},`${T.name} · zone ${T.zone}`))),X=S().flatMap(T=>T.nets.map(j=>[j,T.name])),de=JSON.parse(H()),fe=JSON.parse(k),O=(...T)=>T.some(j=>JSON.stringify(de[j])!==JSON.stringify(fe[j])),U=O(0,1,2),F=O(3,4),oe=T=>D("Save",async()=>{let j=await W(()=>P.serverInterfaces(a,l,l?"":c,d,[...m],p,u!=="off",u),"Access saved");j&&(b(j,!0),j.nets_changed&&j.lan_only&&Z(`${j.lan_only} ${j.lan_only===1?"person has":"people have"} Home-only access: their devices need the configuration again to reach the new networks.`,"warning",1e4))},"positive",{disabled:!T}),_=t("section",{class:"dl-setsec dl-ifcard"},[t("div",{class:"dl-setsec-body"},[t("div",{class:"dl-panel-head"},[t("h3",{},"Internet"),t("span",{class:"dl-spacer"}),t("span",{class:"dl-sub"},"People with Internet or Both")]),I("home","Internet like a home device",R(),[p&&s.needs?.length?D("Install",()=>Bt("home",s.needs,()=>x(!1)),"positive"):"",ge(p,"Internet like a home device",T=>{p=T,G()})],f()),I("globe","Auto-detect WAN",["The interface with the default route: the server port opens there and Internet access leaves through it.",Q(s.detected.wan,s.saved.wan)],[l?"":z,ge(l,"Auto-detect WAN",T=>{l=T,G()})])]),t("div",{class:"dl-setsec-foot"},[t("span",{class:"dl-sub"},p?["Internet like a home device",E()?[" · leaves through ",t("span",{class:"dl-mono"},E())]:""]:E()?["Internet straight to ",t("span",{class:"dl-mono"},E())]:"No WAN found"),oe(U)])]),A=xe([["off","Off"],["all","Everyone"],["circles","Circles"]],u,{label:"Devices reach each other",cls:"sm",optimistic:!1,onChange:async T=>{let j={off:"Off",all:"Everyone",circles:"Circles"}[T];await W(()=>P.serverUpdate(a,{mesh:T}),`Devices reach each other: ${j}`)&&(u=T,s.config.mesh=T,G(),await o())}}),$=t("section",{class:"dl-setsec dl-ifcard"},[t("div",{class:"dl-setsec-body"},[t("div",{class:"dl-panel-head"},[t("h3",{},"Home network"),t("span",{class:"dl-spacer"}),t("span",{class:"dl-sub"},"People with Home or Both"),D([v("reset")," Rescan"],()=>x(!1),"neutral",{title:"Read the interfaces again"})]),I("network","Networks","Everyone with home access reaches these, unless their page leaves one out; their devices can be reached from here too. Click one to add or remove it.","","",V()),I("link","Devices reach each other",C[u],A,"",u==="circles"?Zo(r,a,o):void 0),g.el]),t("div",{class:"dl-setsec-foot"},[t("span",{class:"dl-sub dl-if-summary"},X.length?["Home access reaches ",...X.flatMap(([T,j],Y)=>[Y?", ":"",t("span",{class:"dl-mono"},T),` (${j})`])]:"No home network: Home access reaches nothing but this router."),oe(F)])]),N=window.scrollY;i.style.minHeight=`${i.offsetHeight}px`,dom.content(i,[_,$]),i.style.minHeight="",window.scrollTo({top:N})}function V(){let z=s.devices.filter(M),q=s.devices.filter(X=>!M(X));return t("div",{class:"dl-stack gap8 dl-netpick"},[z.length?t("div",{class:"dl-ifgrid"},z.map(h)):t("span",{class:"dl-warn"},"No home network: Home access reaches nothing but this router."),t("label",{class:"dl-boxrow"},[t("span",{class:"dl-stack"},[t("span",{},"Auto-detect LAN"),t("span",{class:"dl-sub"},["Adds the LAN this router uses.",Q(s.detected.lan,s.saved.lan)])]),ge(d,"Auto-detect LAN",X=>{d=X,G()})]),q.length?t("details",{class:"dl-params",open:w?"":null,toggle:X=>w=X.currentTarget.open},[t("summary",{},[v("chevron"),t("span",{},"Other interfaces"),t("span",{class:"dl-pcount"},String(q.length))]),t("div",{class:"dl-params-body"},[t("span",{class:"dl-sub"},"The WAN, this server, ports and Wi-Fi of a bridge (they come with it) and interfaces without an IPv4 network."),...yi.map(([X,de])=>{let fe=q.filter(O=>O.category===X);return fe.length?t("div",{class:"dl-ifgroup"},[t("h4",{},de),t("div",{class:"dl-ifgrid"},fe.map(h))]):""})])]):""])}return x(!0),{el:i,update(z){r=z,g.update(z),s&&G()}}}var $i={connect:"ok",disconnect:"",roam:"",device_added:"ok",device_removed:"",person_added:"",person_removed:"",paused:"warn",resumed:"ok",portal_blocked:"bad",person_changed:"",devices_removed:"warn"},Ei={devices_removed:"trash",link_changed:"link",person_added:"plus",person_removed:"trash",person_changed:"edit",paused:"pause",resumed:"play"};function Li(n,e){return e.device?n.people.flatMap(a=>a.devices).find(a=>a.id===e.device)?.kind??e.dkind??"other":Ei[e.type]??"activity"}function qn(n,e){let o=n.people.find(m=>m.id===e.person),a=o?.name??e.pname??e.person??"",r=o?.devices.find(m=>m.id===e.device)?.name??e.dname??"",i=m=>t("b",{},m),s=m=>t("span",{class:"dl-muted"},m),l=m=>t("span",{class:"dl-mono"},m),c=m=>e.hosts?.[m]?[t("span",{class:"dl-ev-host"},[t("b",{},e.hosts[m]),t("span",{class:"dl-faint"},` (${m})`)])]:[l(m)],d=m=>t("span",{class:"dl-ev-kind"},`${m} `),p=r?`${a} · ${r}`:a,u=xo(e),w=u||r||"a device",g=m=>[t("span",{class:"dl-you"},"You"),s(` ${m} `)];if(Pe(e)==="admin")switch(e.type){case"device_added":return[...g("added"),d("device"),i(w),s(" for "),i(a)];case"device_removed":return[...g("removed"),d("device"),i(w),s(" from "),i(a)];case"paused":return[...g("paused"),d("person"),i(a)];case"resumed":return[...g("resumed"),d("person"),i(a)];case"device_changed":{let m=u.startsWith("renamed from ");return[...g(m?"renamed":u),d("device"),i(r||"a device"),s(" of "),i(a),...m?[s(` · was ${u.slice(13)}`)]:[]]}case"device_keys":return[...g("issued new keys for"),d("device"),i(w),s(" of "),i(a),s(" · it needs its new configuration")];case"link_changed":return[...g("issued a new link for"),d("person"),i(a),s(" · the old link stopped working")]}switch(e.type){case"connect":return[d("Device"),i(p),s(" connected"),...e.detail?[s(" from "),...c(e.detail)]:[],...e.where?[s(` · ${e.where}`)]:[]];case"disconnect":return[d("Device"),i(p),s(" went offline")];case"roam":return[d("Device"),i(p),s(" changed network "),...(e.detail??"").split(" → ").flatMap((m,k)=>k?[s(" → "),...c(m)]:c(m))];case"device_added":return[d("Person"),i(a),s(" added "),d("device"),i(w),...Pe(e)==="portal"?[s(" on their portal")]:[]];case"device_removed":return[d("Person"),i(a),s(" removed "),d("device"),i(w),...Pe(e)==="portal"?[s(" on their portal")]:[]];case"device_keys":return[d("Person"),i(a),s(" issued new keys for "),d("device"),i(w),s(" on their portal")];case"person_added":return[...g("added"),d("person"),i(e.detail??a)];case"person_removed":return[...g("removed"),d("person"),i(e.detail??a)];case"person_changed":return[...g("changed"),d("person"),i(a),...u?[s(` · ${u.replace(/_/g," ")}`)]:[]];case"paused":return[d("Person"),i(a),s(` paused — ${e.detail??""}`)];case"resumed":return[d("Person"),i(a),s(" resumed"),...e.detail&&e.detail!=="active"?[s(` — ${e.detail}`)]:[]];case"portal_blocked":return[t("b",{class:"dl-sys-src"},"Personal portal"),s(" blocked "),l(e.detail??""),s(" for 15 min after too many wrong codes")];case"devices_removed":return[d("Person"),i(a),s(" — all devices removed, end date reached")];default:return[s(`${e.type}${e.detail?`: ${e.detail}`:""}`)]}}var Mi={portal_blocked:["globe","bad"]};function Si(n,e){if(n.servers.length<2||!e.person)return"";let o=n.people.find(r=>r.id===e.person),a=o&&n.servers.find(r=>r.id===o.server);return a?t("span",{class:"dl-ev-srv",title:"Server"},a.name):""}function Qe(n,e,o={}){let a=Mi[e.type],r=Pe(e);return t("div",{class:`dl-row${r==="admin"?" dl-ev-by-admin":a?` dl-ev-by-system ${a[1]}`:""}`},[r==="admin"?t("span",{class:"dl-ev-tile",title:"Done by you in LuCI"},v("admin")):a?t("span",{class:"dl-ev-tile sys"},v(a[0])):t("span",{class:`dl-ev-tile ev ${$i[e.type]??""}`},v(Li(n,e))),t("span",{class:"dl-row-main"},qn(n,e)),o.server===!1?"":Si(n,e),t("span",{class:"dl-faint dl-nowrap",title:new Date(e.ts*1e3).toLocaleString()},o.time??ie(e.ts,n.now))])}var _i={info:"",up:"ok",down:"warn",repair:"warn",error:"bad"},Ti={awg:"tunnel",dawnline:"sunrise",portal:"globe"};function un(n,e,o,a){let r=n.by==="admin",i=t("div",{class:`dl-row dl-slog-row ${r?"dl-ev-by-admin":`dl-ev-by-system ${_i[n.level]??""}`}${n.detail?" has-detail":""}`},[r?t("span",{class:"dl-ev-tile",title:"Done by you in LuCI"},v("admin")):t("span",{class:"dl-ev-tile sys",title:n.level},v(Ti[n.src]??"zap")),t("span",{class:"dl-row-main"},r?[t("span",{class:"dl-you"},"You"),t("span",{class:"dl-muted"},` ${n.msg} `),n.kind?t("span",{class:"dl-ev-kind"},`${n.kind} `):"",n.who?t("b",{},n.who):"",n.note?t("span",{class:"dl-muted"},` · ${n.note}`):"",n.detail?t("span",{class:`dl-slog-more${e?" open":""}`},v("chevron")):"",n.detail&&e?t("pre",{class:"dl-slog-detail"},n.detail):""]:[n.src==="awg"&&n.who&&n.who!=="AmneziaWG"?t("span",{class:"dl-ev-kind"},"Server "):"",t("b",{class:"dl-sys-src",title:Ct[n.src]??n.src},n.who??Ct[n.src]??n.src)," ",t("span",{class:"dl-muted"},n.msg),n.detail?t("span",{class:`dl-slog-more${e?" open":""}`},v("chevron")):"",n.detail&&e?t("pre",{class:"dl-slog-detail"},n.detail):""]),t("span",{class:"dl-faint dl-nowrap",title:new Date(n.ts*1e3).toLocaleString()},a)]);return n.detail&&i.addEventListener("click",s=>{s.target.closest("pre")||o()}),i}function sa(n){let e=new Date(n*1e3),o=new Date,a=new Date;return a.setDate(o.getDate()-1),e.toDateString()===o.toDateString()?"Today":e.toDateString()===a.toDateString()?"Yesterday":e.toLocaleDateString("en-GB",{weekday:"long",day:"numeric",month:"long"})}var kt=n=>ut(n).toLocaleDateString("en-GB",{day:"numeric",month:"short"});function mn(n,e,o,a=!1){let r=n.slice(-15),i=r[r.length-1],s=i&&e-i[0]<180,l=s?i[2]:0,c=s?i[1]:0,[d,p]=o,u=200,w=40,g=Math.max(1,...r.map(y=>Math.max(y[1],y[2]))),m=y=>r.map((S,b)=>`${r.length>1?b/(r.length-1)*u:u},${w-2-S[y]/g*(w-6)}`),k=m(2),H=m(1),B=r.length>1&&!a?qe(``):t("div",{class:"dl-speed-wait"},[t("i"),a?"":t("span",{},"Collecting… 1 point a minute")]),E=(y,S,b,x)=>t("div",{class:"dl-speed-col"},[t("span",{class:"dl-sub"},[t("span",{class:b},S),` ${y}`]),a?t("span",{class:"dl-speed-val off"},"—"):t("span",{class:"dl-speed-val"},ze(x))]);return r.length>1&&!a&&me(B,()=>{let y=r[r.length-1];return[t("div",{class:"dl-tip-title"},new Date(y[0]*1e3).toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"})),t("div",{},`↓ ${ze(y[2])} · ↑ ${ze(y[1])}`)]}),t("div",{class:"dl-bento-tile"},[t("div",{class:"dl-bento-head"},[t("span",{class:"dl-metric-label"},"Speed now"),a?"":t("span",{class:"dl-sub"},"last 15 min")]),t("div",{class:"dl-speed-cols"},[E("Download","↓","dl-dn",l),E("Upload","↑","dl-up",c)]),B,t("div",{class:"dl-speed-today"},[t("span",{},["Today ",t("b",{},te(d+p))]),t("span",{},[t("span",{class:"dl-dn"},"↓"),` ${te(p)} `,t("span",{class:"dl-up"},"↑"),` ${te(d)}`])])])}function hn(n,e){let o=n.slice(-30),a=o.map(c=>c.rx+c.tx),r=Math.max(1,...a),i=a.reduce((c,d)=>c+d,0),s=a.reduce((c,d,p)=>d>a[c]?p:c,0),l=t("div",{class:"dl-bento-bars"},o.map((c,d)=>{let p=a[d],u=t("i",{class:d===o.length-1?"hi":"",style:`height:${Math.max(4,p/r*100)}%`});return me(u,()=>[t("div",{class:"dl-tip-title"},d===o.length-1?`Today · ${kt(c.day)}`:kt(c.day)),t("div",{},te(p)),t("div",{class:"dl-muted dl-mono"},`↓ ${te(c.tx)} ↑ ${te(c.rx)}`)]),u}));return t("div",{class:"dl-bento-tile month"},[t("div",{class:"dl-bento-head"},[t("span",{},[t("span",{class:"dl-metric-label"},"Last 30 days"),t("b",{class:"dl-bento-total"},te(i))]),a[s]>0?t("span",{class:"dl-sub"},`peak ${te(a[s])} · ${kt(o[s].day)}`):""]),o.length?l:t("p",{class:"dl-muted"},"No traffic yet."),t("div",{class:"dl-bento-head"},[t("span",{class:"dl-sub"},o.length?kt(o[0].day):""),t("span",{class:"dl-sub"},e),t("span",{class:"dl-sub"},"today")])])}function la(n){let e=n.slice(-30),o=e.map(r=>r.rx+r.tx),a=Math.max(1,...o);return t("div",{class:"dl-dbars"},e.map((r,i)=>{let s=t("i",{class:`${o[i]?"":"zero"}${i===e.length-1?" hi":""}`});return s.style.height=`${Math.max(8,o[i]/a*100)}%`,me(s,()=>[t("div",{class:"dl-tip-title"},i===e.length-1?`Today · ${kt(r.day)}`:kt(r.day)),t("div",{},te(o[i]))]),s}))}var da={apply:"Repair",sync:"Reload devices",restart:"Restart service",netrestart:"Restart network",updates:"Open Components"};async function fn(n){return n==="netrestart"&&!await ae("Restart the network?","Every interface restarts. Connections drop for a few seconds.","Restart network")?null:await W(()=>P.healthFix(n),"Done")??null}function Kn(n,e,o,a="action"){let r=n.fix;return r?r.startsWith("install:")?D("Install",()=>ra(r.slice(8),o),a):r==="updates"?t("a",{class:`cbi-button cbi-button-${a}`,href:L.url("admin/network/dawnline/updates")},da.updates):D(da[r]??"Fix",()=>e(r),a):""}function Ci(n){return/^(awg|up_|peers_|fw_|reply_|port_|subnet_)/.test(n)?"shield":/^(portal|cert)/.test(n)?"link":/^(ep_|home_|resolver)/.test(n)?"globe":n==="clock"?"clock":n==="agent"?"activity":n==="nft"?"lock":"alert"}function ca(n,e,o,a=3){let r=n.filter(s=>s.status==="error"||s.status==="warn").sort((s,l)=>s.status===l.status?0:s.status==="error"?-1:1);if(!r.length)return"";let i=r.length-a;return t("div",{class:"dl-list dl-notices"},[...r.slice(0,a).map(s=>at(Ci(s.id),s.status==="error"?"bad":"warn",s.problem??s.title,s.detail,Kn(s,e,o,s.status==="error"?"positive":"neutral"))),i>0?t("a",{class:"dl-row dl-notices-more",href:L.url("admin/network/dawnline/diagnostics")},[`${i} more in Diagnostics`,t("span",{class:"dl-spacer"}),"→"]):""])}function Pi(n){let e=[],o=(s,l)=>t("a",{href:s},l),a=Re(n.series),r=!!n.awg_state&&!n.awg_state.ok;for(let s of n.servers)s.enabled&&s.blocked?e.push({tone:"bad",text:[`${s.name} ${s.blocked}. `,o(L.url("admin/network/dawnline/diagnostics"),"Open Diagnostics")]}):s.enabled&&!s.up&&!r&&e.push({tone:"bad",text:[`Tunnel ${s.ifname} is down. `,o(L.url("admin/network/dawnline/diagnostics"),"Open Diagnostics")]});for(let s of n.people)if(s.state==="quota")e.push({tone:"warn",text:[o(ke(s.id),s.name)," reached the data limit."]});else if(s.state==="expired")e.push({tone:"warn",text:[o(ke(s.id),s.name),"’s access has ended."]});else{let l=nt(s.expires,a);Fe(s,l)&&e.push({tone:"",text:[o(ke(s.id),s.name),`’s access ${Wt(l)}.`]}),s.quota_limit&&s.quota_used>=s.quota_limit*.9&&e.push({tone:"",text:[o(ke(s.id),s.name)," has used 90% of the data limit."]})}let i=n.people.flatMap(s=>s.devices.filter(l=>l.config_stale).map(l=>[s,l]));return i.length&&e.push({tone:"warn",text:i.length===1?[o(ke(i[0][0].id,i[0][1].id),`${i[0][0].name} · ${i[0][1].name}`)," needs its configuration again."]:[`${i.length} devices need their configuration again (networks or DNS changed).`]}),n.servers.some(s=>s.lan_like)&&n.like_home.error&&e.push({tone:"warn",text:[`Internet through the LAN is off: ${n.like_home.error} `,o(L.url("admin/network/dawnline/diagnostics"),"Details")]}),n.settings.portal_enabled||e.push({tone:"",text:["The personal portal is off. ",o(L.url("admin/network/dawnline/settings"),"Turn on")]}),e}var gn=class{constructor(e,o){this.srvId=e;this.go=o;this.el=t("div",{class:"dl-srvov"});this.map=null;this.range="online";this.parts={};this.healthAt=0}mount(e){this.st=Nt(e,this.srvId);for(let o of["health","bento","side","activity"])this.parts[o]=t("div",{});return dom.content(this.el,[this.parts.health,this.parts.bento,this.mapCard(),t("div",{class:"dl-grid2"},[this.parts.activity,this.parts.side])]),this.paint(),this.loadHealth(),this.el}update(e,o=!1){this.st=Nt(e,this.srvId),this.paint(o),this.map?.update(this.mapData()),Date.now()-this.healthAt>6e4&&this.loadHealth()}async loadHealth(){this.healthAt=Date.now();let e=await P.health().catch(()=>null);if(!e)return;let o=()=>void this.loadHealth(),a=async r=>{await fn(r)&&(o(),r==="netrestart"&&setTimeout(o,5e3))};Le(this.parts.health,ca(e.checks,r=>void a(r),o),!0)}mapData(){return{geo:this.st.geo,people:this.st.people,now:this.st.now}}mapCard(){let e=this.st,o=t("div",{class:"dl-panel-head pad"},[t("div",{class:"dl-stack"},[t("h3",{},"Where people connect from"),t("span",{class:"dl-sub"},"City-level, from the client IP · locations cached on the router")]),t("span",{class:"dl-spacer"}),xt(this.range,i=>{this.range=i,this.map?.setRange(i)})]);if(!e.geo.enabled)return t("div",{class:"dl-panel flush"},[o,t("div",{class:"dl-map-off"},["Locations are off. ",t("a",{href:L.url("admin/network/dawnline/settings")},"Turn them on in Settings"),"."])]);this.map=new Je({openPerson:i=>location.href=ke(i),openDevice:(i,s)=>location.href=ke(i,s)},this.range);let a=t("div",{class:"dl-map-legend"},[t("span",{},[t("i",{class:"line live"}),"Live tunnel"]),t("span",{},[t("i",{class:"line"}),"Seen recently"])]),r=t("div",{class:"dl-map-wrap"},[this.map.el,a]);return requestAnimationFrame(()=>this.map.mount(this.mapData())),t("div",{class:"dl-panel flush"},[o,r])}paint(e=!1){let o=this.st,a=o.servers[0];Le(this.parts.bento,t("div",{class:"dl-bento"},[this.onlineTile(),this.speedTile(),Ie(a).overviewTile(a),this.monthTile()]),e);let r=Pi(o);Le(this.parts.side,t("div",{class:"dl-panel flush"},[t("div",{class:"dl-panel-head pad"},[t("h3",{},"Needs attention"),t("span",{class:"dl-spacer"}),t("a",{href:L.url("admin/network/dawnline/diagnostics")},"Health")]),r.length?r.slice(0,8).map(s=>t("div",{class:"dl-attn-item dl-row"},[t("span",{class:`dl-ev-dot ${s.tone}`}),t("span",{},s.text),s.action??""])):t("div",{class:"dl-row dl-muted"},[v("check"),"All good. Nothing needs you right now."])]),e);let i=[...o.events].reverse().slice(0,8);Le(this.parts.activity,t("div",{class:"dl-panel flush"},[t("div",{class:"dl-panel-head pad"},[t("h3",{},"Activity"),t("span",{class:"dl-spacer"}),t("a",{href:`${L.url("admin/network/dawnline/diagnostics")}?tab=log`},"View all")]),i.length?i.map(s=>Qe(o,s)):t("div",{class:"dl-row dl-muted"},"Nothing yet. Connections, new devices and pauses appear here.")]),e)}onlineTile(){let e=this.st,o=e.servers[0]?!e.servers[0].enabled:!1,a=12,r=B=>B.spark[B.spark.length-1]??0,i=B=>e.geo.points.find(E=>E.device===B.id&&E.city)?.city,s=B=>/^(10\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.)/.test(B.endpoint??""),l=(B,E=!1)=>s(B)?E&&B.endpoint?`LAN · ${B.endpoint}`:"LAN":i(B)??"",c=B=>[...e.events].reverse().find(E=>E.type==="connect"&&E.device===B.id)?.ts??0,d=e.people.map(B=>({p:B,devs:B.devices.filter(E=>E.online).sort((E,y)=>r(y)-r(E))})).filter(B=>B.devs.length).sort((B,E)=>E.devs.reduce((y,S)=>y+r(S),0)-B.devs.reduce((y,S)=>y+r(S),0)),p=d.length<=2,u=({p:B,devs:E})=>{let y=E.map(c).filter(Boolean),S=y.length?Math.min(...y):0,b=(B.rate??[]).slice(-15),x=b[b.length-1],M=x&&e.now-x[0]<180?x:null,h=200,f=30,R=Math.max(1,...b.map(V=>Math.max(V[1],V[2]))),C=V=>b.map((z,q)=>`${b.length>1?q/(b.length-1)*h:h},${f-2-z[V]/R*(f-6)}`),I=b.length>1?qe(``):"",Q=!M||M[1]<64&&M[2]<64,G=B.access==="both"?["home","globe"]:B.access==="lan"?["home"]:["globe"];return[t("div",{class:"dl-hc"},[t("div",{class:"dl-hc-head"},[t("span",{class:"dl-onl-av sm"},Ce(B.name)),t("span",{class:"dl-stack"},[t("b",{},B.name),t("span",{class:"dl-hc-since"},S?`online for ${ie(S,e.now).replace(" ago","")}`:"online")]),t("span",{class:"dl-hc-reach"},G.map(V=>t("span",{class:`dl-ibadge ${V==="home"?"lan":"inet"}`},v(V))))]),t("div",{class:"dl-hc-speed"},[t("div",{class:"dl-hc-speed-row"},Q?[t("span",{class:"dl-faint"},"Idle right now")]:[t("span",{},[t("span",{class:"dl-dn"},"↓"),` ${ze(M[2])}`]),t("span",{},[t("span",{class:"dl-up"},"↑"),` ${ze(M[1])}`]),t("span",{class:"dl-spacer"}),t("span",{class:"dl-faint"},"15 min")]),I]),t("div",{class:"dl-hc-devs"},E.map(V=>t("span",{class:"dl-hc-dev"},[v(V.kind),V.name,l(V)?[" · ",l(V,!0)]:""]))),t("div",{class:"dl-hc-foot"},[t("span",{class:"dl-faint"},`${te(E.reduce((V,z)=>V+r(z),0))} today · ${te(B.month[0]+B.month[1])} this month`)])])]},w=B=>{let{p:E,devs:y}=B,S=t("span",{class:"dl-onl-dev"},y.length>1?String(y.length):v(y[0].kind)),b=t("a",{class:`dl-onl-p${p?"":" sm"}`,href:ke(E.id),"aria-label":`${E.name}, online`},[t("span",{class:"dl-onl-av"},[Ce(E.name),S]),p?t("span",{class:"dl-onl-name"},E.name):"",p?t("span",{class:"dl-onl-meta"},[...y.slice(0,3).map(x=>v(x.kind)),y.length>3?`+${y.length-3}`:"",l(y[0])?t("span",{},[" · ",l(y[0])]):""]):""]);return me(b,()=>u(B)),b},g=t("b",{class:`dl-onl-count${d.length?"":" none"}`},String(d.length)),m=d.reduce((B,E)=>B+E.devs.length,0);d.length&&me(g,()=>[`${d.length} ${d.length===1?"person":"people"} · ${m} device${m===1?"":"s"}`]);let k=d.length>a?d.slice(0,a-1):d,H=e.people.flatMap(B=>B.devices.map(E=>({p:B,d:E}))).filter(B=>B.d.handshake).sort((B,E)=>E.d.handshake-B.d.handshake)[0];return t("div",{class:"dl-bento-tile online"},[t("div",{class:"dl-bento-head"},[t("span",{class:"dl-metric-label"},"Online"),g]),d.length?t("div",{class:`dl-onl-row${p?"":" grid"}`},[...k.map(w),d.length>a?t("a",{class:"dl-onl-p sm more",href:`${L.url("admin/network/dawnline/server")}?server=${encodeURIComponent(this.srvId)}§ion=people&filter=online`,title:"Everyone online",click:B=>{this.go&&(B.preventDefault(),this.go("people","online"))}},[t("span",{class:"dl-onl-av"},`+${d.length-k.length}`)]):""]):t("div",{class:"dl-onl-empty"},[t("span",{},o?"The server is turned off":"Nobody is connected"),H?t("span",{class:"dl-sub"},`Last: ${H.p.name}, ${ie(H.d.handshake,e.now)}`):t("span",{class:"dl-sub"},o?"Devices connect once it is on":"No device has connected yet")])])}speedTile(){let e=this.st.servers[0];return mn(e?.rate??[],this.st.now,this.st.totals.today,e?!e.enabled:!1)}monthTile(){return hn(this.st.series,"")}};var pa=[["overview","Overview"],["people","People"],["connection","Connection"],["access","Access"],["awg",""]],Di={general:"connection",network:"connection",interfaces:"access",advanced:"awg",disguise:"awg",tunnel:"awg",core:"awg"},Jn=(n,e)=>{let o=new URLSearchParams;n&&o.set("server",n),e&&e!=="overview"&&o.set("section",e);let a=o.toString();return`${L.url("admin/network/dawnline/server")}${a?`?${a}`:""}`},Ot=class{constructor(){this.noFooter=!0;this.root=t("div",{class:"dl-root"});this.section="overview";this.srvId="";this.ov={};this.pp={};this.tabsEl=t("div",{});this.headEl=t("div",{});this.secEl=t("div",{});this.bodyEl=t("div",{class:"dl-srvbody"})}async load(){let e=await P.status(31),o=e.servers.length?null:await P.setupDefaults();return[e,o]}render([e,o]){if(this.st=e,!e.servers.length&&o)return this.wizard(o);let a=new URLSearchParams(location.search),r=a.get("section")??"",i=Di[r]??r;return pa.some(([s])=>s===i)&&(this.section=i),this.srvId=(e.servers.find(s=>s.id===a.get("server"))??e.servers[0]).id,dom.content(this.root,[this.tabsEl,this.headEl,this.secEl,this.bodyEl]),this.paint(),this.poller=Ve({fetch:()=>P.status(31),every:30,live:!0,active:()=>this.section==="overview"&&this.root.isConnected,apply:(s,l)=>{s.servers.length&&(this.st=s,this.paintHead(l),this.ov[this.current().id]?.update(s,l))}}),this.root}paintHead(e=!1){Le(this.headEl,this.head(this.current()),e),(!e||!yt(this.tabsEl))&&this.paintTabs()}async refreshStatus(){let e=await P.status(31).catch(()=>null);return e?.servers.length?(this.st=e,this.paintHead(),e):null}current(){return this.st.servers.find(e=>e.id===this.srvId)??this.st.servers[0]}async refresh(){let e=await P.status(31).catch(()=>null);e&&(this.st=e,e.servers.length?this.paint():location.href=Jn())}paint(){this.paintTabs(),dom.content(this.headEl,this.head(this.current())),this.paintSections(),this.showSection(this.section)}paintTabs(){let e=this.current();dom.content(this.tabsEl,t("div",{class:"dl-srvtabs",role:"tablist","aria-label":"Servers"},[...this.st.servers.map(o=>t("button",{type:"button",role:"tab",class:`dl-srvtab${o.id===e.id?" on":""}`,"aria-selected":o.id===e.id?"true":"false",click:()=>{o.id!==this.srvId&&(this.srvId=o.id,this.paint())}},[t("i",{class:`dot ${o.enabled?o.up?"ok":"bad":"warn"}`}),t("b",{},o.name)])),t("button",{type:"button",class:"dl-srvtab add",click:()=>this.addServer()},[v("plus"),"Add server"])]))}paintSections(){let e=Ie(this.current());dom.content(this.secEl,t("div",{class:"dl-seg dl-srvsections",role:"tablist","aria-label":"Server"},pa.map(([o,a])=>t("button",{type:"button",role:"tab","data-section":o,class:o===this.section?"on":"","aria-selected":o===this.section?"true":"false",click:()=>this.showSection(o)},o==="awg"?e.label:a))))}go(e,o){let a=this.pp[this.current().id];if(o&&a)a.filter=o,a.el&&a.decorate();else if(o){let r=this.pp[this.current().id]=new st;r.filter=o}this.showSection(e),window.scrollTo({top:0,behavior:"smooth"})}detachKept(){let e=[...Object.values(this.ov).map(o=>o.el),...Object.values(this.pp).map(o=>o.el)];for(let o of e)o&&this.bodyEl.contains(o)&&o.remove()}showSection(e){this.section=e,this.secEl.querySelectorAll("[data-section]").forEach(s=>{let l=s.dataset.section===e;s.classList.toggle("on",l),s.setAttribute("aria-selected",l?"true":"false")});let o=this.st,a=this.current(),i={overview:()=>{let s=this.ov[a.id];return s?(s.update(o),s.el):(this.ov[a.id]=new gn(a.id,(l,c)=>this.go(l,c))).mount(o)},people:()=>{var d,p;let s=this.pp[a.id];if(s?.el)return s.update(),s.el;let l=t("div",{},t("p",{class:"dl-muted"},"Loading people…"));return((d=this.pp)[p=a.id]??(d[p]=new st)).embed(o,a.id).then(u=>{l.isConnected?dom.content(l,u):l.replaceChildren(u)}).catch(u=>{delete this.pp[a.id],dom.content(l,t("p",{class:"dl-muted"},`Couldn't show people: ${ve(u)}`))}),l},connection:()=>this.connection(a),access:()=>this.access(a),awg:()=>this.awg(a)}[e]();this.detachKept(),dom.content(this.bodyEl,i)}head(e){let o=(i,s)=>t("span",{class:"dl-addrbar-seg"},[v(i),...s]),a=e.endpoint||"—",r=t("div",{class:"dl-actions"},[e.enabled?"":D([v("play")," Turn on"],()=>this.save(e,{enabled:"1"},"Server turned on"),"add")]);return t("div",{class:"dl-srvpagehead"},[t("div",{class:"dl-title-row"},[t("h2",{class:"dl-h1"},e.name),t("span",{class:`dl-pill ${e.enabled?e.up?"ok":"bad":"warn"}`},e.enabled?e.up?"Running":e.blocked?"Can’t start":"Not running":"Turned off"),t("span",{class:"dl-spacer"}),r]),t("div",{class:"dl-addrbar"},[t("button",{type:"button",class:"dl-addrbar-seg main",title:"Copy address",click:()=>ue(a,"Address copied")},[v("globe"),t("span",{class:"dl-mono"},a),v("copy")]),o("tunnel",[t("span",{class:"dl-mono"},`${Ie(e).label} :${e.port}`)]),e.up?o("clock",[`up ${pt(e.uptime)}`]):""]),e.blocked?t("div",{class:"dl-note warn"},[v("alert"),t("span",{},`${e.name} ${e.blocked}.`)]):""])}async save(e,o,a="Saved"){await W(()=>P.serverUpdate(e.id,o),a)&&await this.refresh()}connection(e){let o=se(e.name,{placeholder:"Home"}),a=se(e.endpoint,{placeholder:"vpn.example.com",class:"cbi-input-text dl-mono"}),r=se(e.dns.join(", "),{placeholder:"This router (recommended)",class:"cbi-input-text dl-mono"}),i=this.st.people.filter(l=>l.server===e.id).length,s=D(e.enabled?"Turn off":"Turn on",async()=>{e.enabled&&!await ae(`Turn off ${e.name}?`,`The tunnel stops and ${i} ${i===1?"person is":"people are"} disconnected until you turn it back on. Nothing is deleted.`,"Turn off",!0)||await this.save(e,{enabled:e.enabled?"0":"1"},e.enabled?"Server turned off":"Server turned on")},e.enabled?"negative":"positive");return t("div",{class:"dl-stack gap16"},[_t("Connection",[t("p",{class:"dl-muted"},"The name people see, where devices find the router, and DNS. The port is on AmneziaWG."),he("router","Server","What people see",[ne("Name",o,"Shown to people in their portal and apps.")]),he("globe","Devices connect to","Where the router answers from the internet",[ne("Public address",a,"Hostname or IP of the router on the internet. A DDNS name keeps links working when your IP changes. It must not go through Cloudflare: use a DNS-only name or an IP.")]),he("file","For every device","Changing it marks devices “Update config” until they import again",[ne("DNS for devices",r,"Empty = this router, which sends each query where your home network would.")])],[t("span"),D("Save",()=>this.save(e,{name:o.value,endpoint:a.value,dns:r.value}),"positive")]),_t("Danger zone",[t("div",{class:"dl-setrow"},[t("div",{class:"dl-stack"},[t("span",{class:"dl-setrow-label"},e.enabled?"Turn off this server":"This server is off"),t("span",{class:"dl-sub"},e.enabled?"Stops the tunnel and disconnects everyone on it. Settings and people are kept.":"Nobody can connect. Turn it on to bring the tunnel back.")]),t("div",{class:"dl-setrow-ctl"},s)]),t("div",{class:"dl-setrow"},[t("div",{class:"dl-stack"},[t("span",{class:"dl-setrow-label"},"Remove server"),t("span",{class:"dl-sub"},`Removes the tunnel, its firewall rules and ${i} ${i===1?"person":"people"} with all their devices. A backup is made first.`)]),t("div",{class:"dl-setrow-ctl"},D([v("trash")," Remove"],()=>this.remove(e),"negative"))])],[],"danger")])}access(e){let o=Fn(this.st,e),a=ia(e,this.st,async()=>{let r=await this.refreshStatus();if(!r)return;let i=r.servers.find(l=>l.id===e.id)??e;a.update(r);let s=Fn(r,i);o.replaceWith(s),o=s});return t("div",{class:"dl-stack gap16"},[a.el,t("div",{class:"dl-health-cols"},[o,Qo(this.st,e)])])}awg(e){let o={st:this.st,save:(a,r)=>this.save(e,a,r),refresh:()=>this.refresh()};return t("div",{class:"dl-stack gap16"},[Ie(e).settingsCard(o,e)])}async addServer(){let e=await W(()=>P.setupDefaults());e&&dom.content(this.root,this.wizard(e,!0,()=>{dom.content(this.root,[this.tabsEl,this.headEl,this.secEl,this.bodyEl]),this.paint()}))}async remove(e){let o=this.st.people.filter(a=>a.server===e.id);re(`Remove ${e.name}?`,[t("p",{},`This removes the tunnel, its firewall rules and ${o.length} ${o.length===1?"person":"people"} with all their devices. A backup is made first.`)],[le()," ",D("Remove",async()=>{ce(),await W(()=>P.serverDelete(e.id),"Server removed")&&setTimeout(()=>{location.href=Jn()},800)},"negative")])}wizard(e,o=!1,a){let r={id:e.id,name:e.name,endpoint:e.endpoint,port:e.port,range:rn(e.subnet),preset:"standard",portal:!1,portal_port:e.portal_port||8443,lan_like:!0,lan_zone:e.lan_zone,wan_zone:e.wan_zone},i=0,s=!o&&r.portal_port===r.port,l=()=>/^\d{1,3}(\.\d{1,3}){3}$/.test(r.endpoint),c=()=>Wn(r.port,e.udp_taken??[],"Opened on the WAN firewall automatically."),d=()=>Ko(r.range,e.networks??[],rn(e.subnet)),p=()=>Rt(r.portal_port,e.tcp_taken??[],l()),u=t("div",{class:"dl-wizard"}),w=(b,x={})=>{let M=se(String(r[b]),x);return M.addEventListener("input",()=>{b==="port"||b==="portal_port"?r[b]=M.value.trim()===""?0:Number(M.value):r[b]=M.value.trim(),b==="port"&&s&&(r.portal_port=r.port),b==="portal_port"&&(s=r.portal_port===r.port)}),M},g={id:"server",title:"Server",render:()=>t("div",{class:"dl-wizard-groups"},[t("p",{class:"dl-muted"},"Where devices connect to. A hostname that always points at your router (DDNS) keeps links working when your IP changes."),he("router","Server","What people see",[ne("Name",w("name"),"Shown to people in their portal and apps.")]),he("globe","Devices connect to","Where the router answers from the internet",[ne("Public address",w("endpoint",{placeholder:"vpn.example.com",class:"cbi-input-text dl-mono"}),"Hostname or IP address of your router on the internet. Not through Cloudflare: use a DNS-only name or an IP.")])]),check:()=>r.endpoint?null:"Fill in the public address."},m={id:"awg",title:"AmneziaWG",render:()=>t("div",{class:"dl-wizard-groups"},[he("globe","Listening","Where devices reach AmneziaWG from the internet",[mt("UDP port",w("port",{inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),c)]),he("network","Tunnel network","Addresses devices get inside the tunnel",[(()=>{let b=w("range",{class:"cbi-input-text dl-w-range dl-mono","aria-label":"First three numbers of the device addresses"});return mt("Device addresses",b,d,t("span",{class:"dl-suffixed"},[b,t("span",{class:"dl-mono"},".x")]))})()]),he("shield","Disguise","So networks that block VPNs do not recognise the tunnel. Off = plain WireGuard",[Zt(e.awg,r.preset,b=>r.preset=b,void 0,e.awg_state?.tools!==!1)])]),check:()=>{let b=c();if(b.bad)return`UDP port: ${b.text}`;let x=d();return x.bad?`Device addresses: ${x.text}`:null}},k={id:"portal",title:"Portal",render:()=>{let b=w("portal_port",{inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),x=mt("Listening port",b,p);x.hidden=!r.portal;let M=xe([["off","Off"],["on","On"]],r.portal?"on":"off",{label:"Personal portal",onChange:h=>{r.portal=h==="on",x.hidden=!r.portal}});return t("div",{class:"dl-wizard-groups"},[he("home","Internet like a home device","How devices reach the internet",[ne("Through the home network",ge(r.lan_like,"Internet like a home device",h=>r.lan_like=h),"Whatever handles home traffic on this router (proxies, filters, DNS) handles theirs too. Change it later under Servers → Access.")]),he("link","Personal portal","A page where each person adds their own devices with their personal link",[ne("Portal",M,"Off: only you add devices, from LuCI. On: people manage their devices within the limits you set."),x])])},check:()=>{if(!r.portal)return null;let b=p();return b.bad?`Portal port: ${b.text}`:null}},H=()=>[g,m,o?null:k].filter(b=>b!=null),B=e.awg_state,E=B?.missing??[],y=E.length?t("div",{class:"dl-list dl-notices"},[at("shield","bad","AmneziaWG isn’t installed",`The tunnel needs ${E.join(" and ")}. Install the build made for this firmware, then create the server.`,D("Install",()=>pn(()=>location.reload()),"positive"))]):B&&!B.loaded?t("div",{class:"dl-list dl-notices"},[at("shield","warn","AmneziaWG’s kernel module doesn’t load on this firmware","Try another build in Components, or update OpenWrt. The server can’t start until it loads.",t("a",{class:"cbi-button cbi-button-neutral",href:L.url("admin/network/dawnline/updates")},"Open Components"))]):"",S=()=>{let b=H();i>=b.length&&(i=b.length-1),dom.content(u,[t("h2",{},o?"Add a server":"Set up Dawnline"),y,t("div",{class:"dl-steps"},b.map((x,M)=>t("span",{class:`dl-step${M===i?" current":M0?D("Back",()=>{i--,S()}):a?D("Cancel",a):"",t("span",{class:"dl-spacer"}),i{let x=b[i].check?.();if(x){Z(x,"warning");return}i++,S()},"positive"):D("Create server",async()=>{for(let M of b){let h=M.check?.();if(h){Z(h,"warning");return}}let x=await W(()=>P.serverCreate(r.id,r.name,e.ifname,r.port,Un(r.range),r.endpoint,e.mtu,r.preset,r.lan_zone,r.wan_zone,r.lan_like,o?void 0:r.portal,o?void 0:r.portal_port),"Server created");x&&(x.network_restart&&Z("Restarting the network so it knows AmneziaWG: back in a few seconds"),setTimeout(()=>{location.href=Jn(x.id)},x.network_restart?1e4:1500))},"positive",{disabled:E.length>0,title:E.length?"Install AmneziaWG first":null})])])};return S(),u}};function Xe(n){let e={el:n(),refresh(){let o=n();e.el.replaceWith(o),e.el=o}};return e}function De(n,e,o,a,r="",i=[]){return t("section",{class:`dl-setsec ${r}`,id:`dl-set-${n}`},[t("div",{class:"dl-setsec-body"},[i.length?t("div",{class:"dl-setsec-head"},[t("h3",{},e),t("span",{class:"dl-spacer"}),...i]):t("h3",{},e),...o]),a.length?t("div",{class:"dl-setsec-foot"},a):""])}function ua(n){let e=n.filter(r=>r.status!=="skip"),o=e.filter(r=>r.status==="error"||r.status==="warn"),a=e.some(r=>r.status==="error")?"error":o.length?"warn":"ok";return{bad:o,worst:a}}function ma(n){let e=n.d.settings,o=n.d.effective,a=n.d.cert,r=ge(o.portal_enabled,"Enable portal"),i=se(e.portal_port,{placeholder:"8443",inputmode:"numeric",class:"cbi-input-text dl-w-port"}),s=se(e.portal_title,{placeholder:"Dawnline"}),l=se(e.portal_redirect,{placeholder:"Show “Not found”",class:"cbi-input-text dl-mono"}),c=se("",{placeholder:"vpn.example.com or an IP","aria-label":"Other address"}),d=O=>/^\d{1,3}(\.\d{1,3}){3}$/.test(O),p=[o.portal_host,...o.portal_alt??[]].filter((O,U,F)=>O&&F.indexOf(O)===U),u=!!n.portal,w=[],g=O=>{O&&!w.some(U=>U.host===O)&&w.push({host:O,kind:d(O)?"ip":"name",ips:[],here:!1,cloudflare:!1,cert:!1})},m=O=>{w=[...O,...w.filter(U=>!O.some(F=>F.host===U.host))],!p.length&&O[0]&&(p=[O[0].host])};n.portal&&m(n.portal.candidates),p.forEach(g);let k=O=>O.kind==="ip"?t("span",{class:"dl-addr-warn"},[v("alert"),"Plain HTTP: the link and VPN keys travel unencrypted"]):t("span",{class:"dl-sub"},O.cloudflare?"Behind Cloudflare · often stalls in Russia":O.ips.length?O.here?`Points at this router${O.cert?" · Let’s Encrypt certificate":" · no certificate yet"}`:`Points at ${O.ips.join(", ")}, not this router`:u?"Your address":"Checking where it points…"),H=t("div",{class:"dl-addr-opts",role:"group","aria-label":"Portal addresses"}),B=O=>{p.includes(O)?p.length>1&&(p=p.filter(U=>U!==O)):p=[...p,O],E(),b()},E=()=>dom.content(H,[...w.map(O=>{let U=p.includes(O.host),F=p[0]===O.host;return t("div",{class:`dl-addr-opt${U?" on":""}`,role:"checkbox","aria-checked":U?"true":"false",tabindex:"0",click:()=>B(O.host),keydown:oe=>{(oe.key===" "||oe.key==="Enter")&&(oe.preventDefault(),B(O.host))}},[t("i",{class:"dl-addr-check"},U?v("check"):""),t("span",{class:"dl-stack"},[t("span",{class:"dl-mono"},O.host),k(O)]),F?t("span",{class:"dl-pill info"},"Main"):U?t("button",{type:"button",class:"dl-linkbtn",click:oe=>{oe.stopPropagation(),p=[O.host,...p.filter(_=>_!==O.host)],E(),b()}},"Make main"):O.cloudflare?t("span",{class:"dl-pill warn"},"Cloudflare"):O.kind==="ip"?t("span",{class:"dl-pill"},"IP"):O.here&&O.cert?t("span",{class:"dl-pill ok"},"Recommended"):""])}),t("div",{class:"dl-addr-opt other"},[t("i",{class:"dl-addr-check"},v("plus")),c,D("Add",()=>{let O=c.value.trim().toLowerCase();O&&(g(O),p.includes(O)||(p=[...p,O]),c.value="",E(),b())})])]);c.addEventListener("keydown",O=>{O.key==="Enter"&&(O.preventDefault(),c.nextElementSibling?.click())});let y=t("div",{class:"dl-links"}),S=()=>{},b=()=>{S();let O=Number(i.value)||o.portal_port;dom.content(y,p.map((U,F)=>{let oe=d(U),_=oe?O+1:O,A=`${oe?"http":"https"}://${U}${_===(oe?80:443)?"":`:${_}`}/`;return t("div",{class:"dl-link-row"},[t("span",{class:`dl-link-ic ${oe?"warn":"ok"}`},v(oe?"alert":"lock")),t("span",{class:"dl-mono dl-link-url"},[A,t("b",{},"kamiro-telosu-bavine")]),F===0?t("span",{class:"dl-pill info"},"Main"):oe?t("span",{class:"dl-pill warn"},"HTTP"):""])}))};E(),b(),i.addEventListener("input",()=>b());let x={portal:"Portal running",portal_dns:"Points here",portal_reply:"Answers reach visitors",portal_http:"Plain HTTP",cert:"Certificate"},M=n.d.needs??{https:[],acme:[],home:[]},h=O=>{if(!o.portal_enabled)return t("div",{hidden:!0});if(!O)return he("check","Ready to share","The portal’s checks from Health",[t("p",{class:"dl-muted dl-loading"},"Running checks…")]);let U=O.filter($=>$.status!=="skip");if(!U.length)return t("div",{hidden:!0});let{bad:F,worst:oe}=ua(O),_=t("div",{class:"dl-ready-details",hidden:!0},U.map($=>t("div",{class:`dl-ready-item ${$.status}`},[v($.status==="ok"?"check":"alert"),t("span",{class:"dl-stack"},[t("span",{},$.title),t("span",{class:"dl-sub"},$.detail)])]))),A=t("div",{class:"dl-stack gap8"},[t("div",{class:`dl-ready-sum ${oe}`},[v(oe==="ok"?"check":"alert"),t("span",{class:"dl-stack"},[t("b",{},oe==="ok"?`All ${U.length} checks passed`:`${U.length-F.length} of ${U.length} checks passed`),F.length?t("span",{class:"dl-sub"},F.map($=>$.detail).join(" ")):t("span",{class:"dl-sub"},"Links will open for the people you send them to.")]),t("button",{type:"button",class:"dl-linkbtn",click:$=>{_.hidden=!_.hidden,$.currentTarget.textContent=_.hidden?"Details":"Hide"}},"Details")]),t("div",{class:"dl-chips-row"},U.map($=>t("span",{class:`dl-check-chip ${$.status}`,title:$.detail},[v($.status==="ok"?"check":"alert"),x[$.id]??$.title]))),_]);return he("check","Ready to share","The portal’s checks from Health",[A])},f=O=>{if(!o.portal_enabled||!O&&!M.https.length)return t("span",{hidden:!0});if(M.https.length)return t("span",{class:"dl-pill bad"},"Can’t start");let{worst:U}=ua(O);return t("span",{class:`dl-pill ${U==="ok"?"ok":U==="error"?"bad":"warn"}`},U==="error"?"Needs attention":"Ready")},R=h(n.portal?.checks??null),C=f(n.portal?.checks??null);n.portalFill=O=>{u=!0,m(O.candidates),E(),b();let U=h(O.checks);R.replaceWith(U),R=U;let F=f(O.checks);C.replaceWith(F),C=F};let I=a&&!a.self_signed&&a.expires?Ne(a.expires):"",Q=mt("Listening port",i,()=>Rt(i.value.trim()===""?o.portal_port:Number(i.value),n.d.tcp_taken??[],p.some(d)));S=Q.refresh;let G=!!(e.portal_cert&&e.portal_key),V=a?G?"Your files":a.self_signed?"Self-signed":"Let’s Encrypt":"Portal is off",z=()=>{let O=se(e.portal_cert,{placeholder:"/etc/ssl/…/fullchain.crt"}),U=se(e.portal_key,{placeholder:"/etc/ssl/…/key"});re("Use your own certificate",[t("p",{class:"dl-muted"},"Paths on the router. Leave both empty to pick a certificate automatically."),ne("Certificate file",O),ne("Key file",U)],[le()," ",D("Save",()=>{ce(),n.save({portal_cert:O.value.trim(),portal_key:U.value.trim()},"Certificate saved","portal")},"positive")])},q=(O,U,F,oe,_,A)=>at(O,U,F,oe,D(A,()=>Bt(_,M[_],()=>n.reload("portal")),"positive")),X=M.https.length?q("lock","bad","HTTPS isn’t available on this router",`The portal needs ${M.https.join(" and ")}. It can’t start without them.`,"https","Install"):"",de=M.acme.length&&(!a||a.self_signed)?q("lock","","Free certificate from Let’s Encrypt",`ACME isn’t installed. With it the router gets a certificate${e.portal_host?` for ${e.portal_host}`:""} and browsers stop warning.`,"acme","Install ACME"):"",fe=[t("div",{class:"dl-row"},[v("lock"),t("span",{class:"dl-row-main dl-stack"},[t("b",{},[V,I?t("span",{class:"dl-faint"},` · until ${I}`):""]),t("span",{class:"dl-sub dl-ellipsis",title:a?.path??""},a?a.self_signed?"Made by the router: browsers warn until a certificate covers the address.":`${G?"Your files":"Found automatically"} · ${a.path}`:"Turn the portal on to see its certificate.")])]),t("div",{class:"dl-row"},[v("file"),t("span",{class:"dl-row-main dl-stack"},[t("b",{},"Your own files"),t("span",{class:"dl-sub"},G?`${e.portal_cert} · ${e.portal_key}`:"Not set: the certificate is picked automatically.")]),G?D("Reset",()=>n.save({portal_cert:"",portal_key:""},"Automatic certificate","portal"),"negative"):"",D(G?"Change":"Use files",z)]),de];return De("portal","Personal portal",[t("span",{class:"dl-muted"},"A page where each person adds and manages their devices with their personal link."),X?t("div",{class:"dl-list"},[X]):"",he("network","Port","How the portal listens (80 and 443 stay free)",[Q]),he("edit","Appearance","What people see",[ne("Title",s,"Shown at the top of the portal."),ne("Unknown links",l,"Where a wrong or old link goes, for example your website. Empty shows a plain “Not found”.")]),he("link","Addresses","Pick one or more; the first is the main link",[H,t("div",{class:"dl-stack gap8"},[y,t("span",{class:"dl-sub"},"Example code; each person gets their own three words.")])]),he("lock","Certificate","Used for HTTPS links",fe),R],[t("span"),D("Save",()=>{let O=Rt(i.value.trim()===""?o.portal_port:Number(i.value),n.d.tcp_taken??[],p.some(d));if(O.bad){Z(`Listening port: ${O.text}`,"warning");return}return n.save({portal_enabled:Me(r)?"1":"0",portal_host:p[0]??"",portal_alt:p.slice(1),portal_port:i.value,portal_title:s.value,portal_redirect:l.value.trim()},"Saved","portal")},"positive")],"",[C,r])}function ha(n){let e=n.d.settings,o=n.d.effective,a=se(e.default_device_limit,{placeholder:"3",inputmode:"numeric",class:"cbi-input-text dl-w-port"}),r=ge(o.hostnames,"Device hostnames"),i=se(e.domain,{placeholder:"lan",class:"cbi-input-text dl-w-port"}),s=se(e.home_dns_fallback==="none"?"":e.home_dns_fallback||o.home_dns_fallback||"",{placeholder:"None",inputmode:"decimal",class:"cbi-input-text dl-w-ip dl-mono"});return De("defaults","Defaults",[ne("Devices per person",a,"Pre-filled when you add someone."),ne("Device hostnames",t("div",{class:"dl-hostport"},[r,t("span",{class:"dl-faint dl-mono"},"phone.myata."),i]),"Name devices in your home DNS."),ne("Fallback DNS",s,"For Home-only devices using home names: the second DNS server, used by the device when the tunnel is down. Empty = none.")],[t("span"),D("Save",()=>n.save({default_device_limit:a.value,hostnames:Me(r)?"1":"0",domain:i.value,home_dns_fallback:s.value},"Saved","defaults"),"positive")])}function fa(n){let e=n.d.effective,o=ge(e.geo_enabled,"Locations"),a=t("select",{class:"cbi-input-select"},[t("option",{value:"ipwho.is",selected:e.geo_provider!=="ipapi.co"?"selected":null},"ipwho.is (fallback: ipapi.co)"),t("option",{value:"ipapi.co",selected:e.geo_provider==="ipapi.co"?"selected":null},"ipapi.co (fallback: ipwho.is)")]);return De("map","Map & locations",[t("div",{class:"dl-setrow head"},[t("span",{class:"dl-muted"},"Show where people connect from on the Overview and person pages, at city level."),o]),ne("Provider",a)],[t("span",{class:"dl-sub"},"The router sends each new client IP to the provider once and caches the city. Map tiles load in your browser from CARTO; people never see the map."),D("Save",()=>n.save({geo_enabled:Me(o)?"1":"0",geo_provider:a.value},"Saved","map"),"positive")])}var Ai=[["app","Dawnline"],["amneziawg","AmneziaWG"],["packages","System packages"]];function ga(n){let e=n.d.effective.updates,o=ge(e.check,"Check automatically",m=>g(m,Me(r))),a=xe([["6h","Every 6 h"],["12h","Every 12 h"],["1d","Daily"],["7d","Weekly"]],e.interval,{label:"How often",cls:"sm"}),r=ge(e.auto,"Install automatically",m=>g(Me(o),m)),i=se(e.time,{placeholder:"04:00",inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono","aria-label":"Time"}),s=xe([["scheduled","At a set time"],["immediate","As soon as found"]],e.mode,{label:"When",cls:"sm",onChange:m=>i.hidden=m!=="scheduled"});i.hidden=e.mode!=="scheduled";let l=new Set(e.targets),c=t("div",{class:"dl-chips-row"},Ai.map(([m,k])=>{let H=We(k,l.has(m),()=>{l.delete(m)||l.add(m),Yt(H,l.has(m))});return H})),d=ge(e.keep,"Keep the previous version"),p=ge(e.mirrors,"GitHub mirrors"),u=ne("How often",a),w=[ne("When",t("div",{class:"dl-hostport"},[s,i]),"A set time keeps tunnel restarts out of the evening; the run happens within an hour of it."),ne("Components",c,"AmneziaWG is off by default: a new kernel module restarts every tunnel.")],g=(m,k)=>{u.hidden=!m;for(let H of w)H.hidden=!k};return g(e.check,e.auto),De("updates","Updates",[t("span",{class:"dl-muted"},"How Dawnline keeps its components current. Every Dawnline update makes a backup of the settings first."),ne("Check automatically",o,"Looks for new versions in the background; Components shows what it found and the service log names it."),u,ne("Install automatically",r,"Downloads and installs new versions of the components below."),...w,ne("Keep the previous version",d,"Saves the replaced Dawnline or AmneziaWG package on flash, so Roll back works without internet. Under 1 MB."),ne("GitHub mirrors",p,"When GitHub is unreachable, download through mirrors. Checksums are still verified.")],[t("span",{class:"dl-sub"},"Run a check or an update by hand in Components."),D("Save",()=>n.save({update_check:Me(o)?"1":"0",update_interval:a.dataset.value,update_auto:Me(r)?"1":"0",update_mode:s.dataset.value,update_time:i.value.trim(),update_targets:[...l],update_keep:Me(d)?"1":"0",update_mirrors:Me(p)?"1":"0"},"Saved","updates"),"positive")])}function va(n){let e=n.d.logs,o=e.policy,a=xe([["7","7 days"],["30","30 days"],["90","90 days"],["365","1 year"],["0","No limit"]],String(o.keep_days),{label:"Keep activity",cls:"sm"}),r=xe([["500","500"],["2000","2,000"],["5000","5,000"],["20000","20,000"]],String(o.max),{label:"Maximum events",cls:"sm"}),i=xe([["10min","Every 10 min"],["hourly","Hourly"],["off","Memory only"]],o.persist,{label:"Save to flash",cls:"sm"}),s=xe([["31","1 month"],["62","2 months"],["180","6 months"],["365","1 year"],["730","2 years"]],String(o.usage_days),{label:"Daily traffic",cls:"sm"}),l=xe([["12","1 year"],["24","2 years"],["60","5 years"],["120","10 years"]],String(o.usage_months),{label:"Monthly traffic",cls:"sm"}),c=new Set(o.categories),d=t("div",{class:"dl-chips-row"},gt.map(g=>{let m=We([rt[g],t("b",{},String(e.by_category[g]??0))],c.has(g),()=>{c.delete(g)||c.add(g),Yt(m,c.has(g))},{title:bo[g]});return m})),p=e.oldest?Ne(new Date(e.oldest*1e3)):"",u=(g,m,k,H)=>t("div",{class:"dl-row"},[v(g),t("span",{class:"dl-row-main dl-stack"},[t("b",{},m),t("span",{class:"dl-sub"},k)]),...H]),w=g=>D(g.toUpperCase(),async()=>{let[m,k]=await Promise.all([P.status(1),P.events(2e4)]);Ue(m,k.events,g)},"neutral",{title:`Download the log as ${g.toUpperCase()}`});return De("logs","Logs & history",[t("p",{class:"dl-muted"},Vt(o)),ne("Keep activity",a,"Older events are removed automatically."),ne("Maximum size",r,"Newest events are kept when the log is full."),ne("Record",d,"Switched-off categories are not logged from now on."),ne("Save to flash",i,"The log lives in memory and is copied to flash. Memory only saves flash writes but is lost on reboot."),ne("Daily traffic",s,"Per-day history behind the charts."),ne("Monthly traffic",l,"Per-month totals; data limits use the current month."),t("h4",{class:"dl-setsub"},"Stored data"),t("div",{class:"dl-list"},[u("activity","Activity log",e.events?`${Gt(e.events,"event")} since ${p} · ${St(e.log_ram)} in memory${o.persist==="off"?"":`, ${St(e.log_flash)} on flash`}`:"Empty",[w("csv"),w("json"),D("Clear",()=>Ke("Clear activity","Removes events from the log on the router.",{},()=>n.reload("logs")),"negative")]),u("chart","Traffic history",e.usage_days?`${Gt(e.usage_days,"day")} since ${Ne(e.usage_since)} · ${St(e.usage_flash)} on flash`:"Empty",[D("Reset",()=>vt("all","","",()=>setTimeout(()=>n.reload("logs"),300)),"negative")]),u("pin","Location cache",`${Gt(n.d.geo_cached,"address","addresses")} · ${St(e.geo_flash)} on flash`,[D("Clear",async()=>{await W(()=>P.geoClear(),"Location cache cleared")&&await n.reload("logs")},"negative")])])],[t("span",{class:"dl-sub"},"Clear one person or device from their own page."),D("Save",()=>n.save({log_keep_days:a.dataset.value,log_max:r.dataset.value,log_persist:i.dataset.value,usage_keep_days:s.dataset.value,usage_keep_months:l.dataset.value,log_category:[...c]},"Saved","logs"),"positive")])}var zi={manual:"Manual",auto:"Nightly","pre-restore":"Before restore","pre-import":"Before import","pre-delete":"Before removing a server","pre-update":"Before update"},ba=3;function Vn(n){let e=new Date(n*1e3),o=e.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"}),a=Math.round((new Date(new Date().toDateString()).getTime()-new Date(e.toDateString()).getTime())/864e5);return`${a===0?"Today":a===1?"Yesterday":e.toLocaleDateString("en-GB",{day:"numeric",month:"short"})}, ${o}`}async function Hi(n){let e=await W(()=>P.backupRead(n.name));if(!e)return;let o=atob(e.data),a=new Uint8Array(o.length);for(let i=0;iHi(n),"neutral","dl-icon-only"),$e("more","More",o=>we(o.currentTarget,[{label:"Restore",icon:v("reset"),run:async()=>{await ae("Restore this backup?",`Everything returns to ${Vn(n.created)}. The current state is backed up first.`,"Restore",!0)&&await W(()=>P.backupRestore(n.name),"Restored")&&e(!0)}},{label:"Delete",icon:v("trash"),danger:!0,run:async()=>{await ae("Delete this backup?",`The backup from ${Vn(n.created)} is removed from the router.`,"Delete",!0)&&await W(()=>P.backupDelete(n.name),"Backup deleted")&&e()}}]),"neutral","dl-icon-only")])])}function wa(n,e){let o=n.slice(0,ba).map(c=>xa(c,e)),a=n.slice(ba),r=n.length?t("div",{class:"dl-list"},[...o,a.length?t("details",{class:"dl-bk-older"},[t("summary",{},[v("chevron"),`${a.length} older backup${a.length===1?"":"s"}`]),...a.map(c=>xa(c,e))]):""]):t("div",{class:"dl-list"},[t("div",{class:"dl-row dl-muted"},"No backups yet.")]),i=D("Restore from file",async()=>{let c=await _n(".tar.gz,.tgz,application/gzip","base64");if(!c)return;await ae("Restore from file?",`Replace the current Dawnline configuration with ${c.name}? The current state is backed up first.`,"Restore",!0)&&await W(()=>P.backupUpload(c.data),"Restored")&&e(!0)}),s=D("Export JSON",async()=>{let c=await W(()=>P.exportJson());c&&Ee(`dawnline-export-${new Date().toISOString().slice(0,10)}.json`,JSON.stringify(c,null,2),"application/json")}),l=D("Import JSON",async()=>{let c=await _n(".json,application/json","text");if(!c)return;let d;try{d=JSON.parse(c.data)}catch{Z("Not a JSON file.","error");return}await ae("Import?","This replaces the whole Dawnline configuration on this router. The current state is backed up first.","Import",!0)&&await W(()=>P.importJson(d),"Imported")&&e(!0)});return t("section",{class:"dl-setsec",id:"dl-set-backups"},[t("div",{class:"dl-setsec-body"},[t("div",{class:"dl-setsec-head"},[t("div",{class:"dl-stack"},[t("h3",{},"Backups"),t("span",{class:"dl-sub"},"Nightly when something changed, and before every restore, import or update. The last 10 are kept.")]),t("span",{class:"dl-spacer"}),D([v("plus")," Back up now"],async()=>{await W(()=>P.backupCreate(),"Backup created")&&e()},"positive")]),r]),t("div",{class:"dl-setsec-foot"},[t("span",{class:"dl-sub"},"Backups contain private keys: keep downloads safe. JSON moves everything except usage history to another router."),t("span",{class:"dl-row-actions dl-bk-actions"},[i,s,l])])])}function Ni(){let n=se("",{placeholder:"remove"}),e=D("Remove Dawnline",async()=>{await W(()=>P.uninstall(n.value.trim()),"Dawnline removed")&&(ce(),setTimeout(()=>location.reload(),800))},"negative",{disabled:!0});n.addEventListener("input",()=>{e.disabled=n.value.trim()!=="remove"}),re("Remove Dawnline?",[t("p",{},"Everyone is disconnected and the tunnel, firewall rules and portal are removed. A backup is made first. Type “remove” to confirm."),n],[le()," ",e])}function ya(){return De("danger","Remove Dawnline from this router",[t("p",{class:"dl-muted"},"Deletes the tunnel, firewall rules, access table and hostnames Dawnline created, and stops the service. People and keys are kept in a backup.")],[t("span"),D("Remove",()=>Ni(),"negative")],"danger")}var vn=class{constructor(){this.root=t("div",{class:"dl-settings-main"});this.backups=[];this.portal=null;this.portalSeq=0;this.cards={}}load(){return P.settingsGet()}render(e){this.d=e,this.cards={portal:Xe(()=>ma(this)),defaults:Xe(()=>ha(this)),map:Xe(()=>fa(this)),updates:Xe(()=>ga(this)),logs:Xe(()=>va(this)),backups:Xe(()=>wa(this.backups,r=>this.loadBackups(r))),danger:Xe(()=>ya())};let o=["portal","defaults","map","updates","logs","backups","danger"];dom.content(this.root,o.map(r=>this.cards[r].el)),this.loadBackups().then(()=>{new URLSearchParams(location.search).get("section")==="backups"&&document.getElementById("dl-set-backups")?.scrollIntoView({block:"start"})}),this.loadPortal();let a=new URLSearchParams(location.search).get("section");return a&&a!=="backups"&&requestAnimationFrame(()=>document.getElementById(`dl-set-${a}`)?.scrollIntoView({block:"start"})),t("div",{},[t("div",{class:"dl-pagehead"},[t("h2",{class:"dl-h1"},"Settings")]),this.root])}async save(e,o,a){let r=await W(()=>P.settingsUpdate(e),o);r&&(this.d=r,this.cards[a].refresh(),a==="portal"&&this.loadPortal())}async loadPortal(){let e=++this.portalSeq,o=await P.portalInfo().catch(()=>null);e===this.portalSeq&&(this.portal=o??this.portal??{candidates:[],checks:[]},this.portalFill?.(this.portal))}async loadBackups(e=!1){e&&await this.reload();let o=await P.backupList().catch(()=>null);o&&(this.backups=o.backups,this.cards.backups?.refresh())}async reload(e){let o=await P.settingsGet().catch(()=>null);if(o){if(this.d=o,e)this.cards[e].refresh();else for(let a of Object.values(this.cards))a.refresh();(!e||e==="portal")&&this.loadPortal()}}};function ka(n,e=!1){return n&&(e?/^https?:\/\//i:/^https:\/\//i).test(n)?n:null}function $a(n){let e=[],o=l=>{let c=[],d=/(`[^`]+`)|(\*\*[^*]+\*\*)|(\[[^\]]+\]\((https?:\/\/[^)\s]+)\))|(https?:\/\/[^\s<>()]+[^\s<>().,;:!?])/g,p=0;for(let u;u=d.exec(l);)u.index>p&&c.push(l.slice(p,u.index)),u[1]?c.push(t("code",{},u[1].slice(1,-1))):u[2]?c.push(t("b",{},u[2].slice(2,-2))):u[3]?c.push(t("a",{href:u[4],target:"_blank",rel:"noopener"},u[3].replace(/^\[|\]\(.*$/g,""))):u[5]&&c.push(t("a",{href:u[5],target:"_blank",rel:"noopener"},u[5].replace(/^https?:\/\/(github\.com\/)?/,""))),p=u.index+u[0].length;return p{r.length&&e.push(t("p",{},o(r.join(" ")))),r=[],a=null};for(let l of n.replace(/\r/g,"").split(` +`,_o(s,e)]:[_o(s,e)])),r=t("button",{type:"button",class:"dl-chipbtn",click:s=>{s.preventDefault(),e=!e,dom.content(r,[v(e?"x":"key"),e?"Hide key":"Show key"]),a()}},[v("key"),"Show key"]);a();let i=new Blob([n.conf]).size;return t("div",{class:"dl-stack gap8"},[t("div",{class:"dl-filecard"},[t("span",{class:"dl-filecard-ic"},".conf"),t("span",{class:"dl-stack"},[t("span",{class:"dl-mono dl-ellipsis"},n.filename),t("span",{class:"dl-sub"},`AmneziaWG · ${i} bytes · import it in the app`)]),D([v("download")," Download"],()=>Ee(n.filename,n.conf,"application/octet-stream"),"positive")]),t("details",{class:"dl-params"},[t("summary",{},[v("chevron"),t("span",{},"Configuration"),t("span",{class:"dl-spacer"}),r,t("button",{type:"button",class:"dl-chipbtn",click:s=>{s.preventDefault(),ue(n.conf,"Configuration copied")}},[v("copy"),"Copy"])]),o])])}async function Gr(n,e="file"){if(!n.has_private_key)return t("div",{class:"dl-hint"},"This device generated its own keys in the browser, so its full configuration only exists on that device.");let o=await Dn(n,`${n.server} · ${n.person} · ${n.name}`),a={qr:()=>t("div",{class:"dl-qr-pane"},[qe(ft(n.conf),"dl-qr"),t("span",{class:"dl-sub"},"Scan with AmneziaVPN or AmneziaWG on the device.")]),key:()=>t("div",{class:"dl-stack gap8"},[t("div",{class:"dl-linkbox"},[t("span",{class:"dl-mono"},o),D("Copy",()=>ue(o,"Key copied"))]),t("span",{class:"dl-sub"},"AmneziaVPN → Add server → Insert key. Keep it private.")]),file:()=>Wr(n)},r=t("div",{class:"dl-connect-body"}),i=t("div",{class:"dl-seg"}),s=l=>{i.querySelectorAll("button").forEach(c=>c.classList.toggle("on",c.dataset.id===l)),dom.content(r,a[l]())};for(let[l,c]of[["file","File"],["key","Key"],["qr","QR code"]])i.appendChild(t("button",{type:"button","data-id":l,click:()=>s(l)},c));return s(e),t("div",{class:"dl-stack gap12"},[i,r])}async function Fr(n,e,o,a){let r=Pt(o),s=n.st.people.filter(c=>c.server===e.id).reduce((c,d)=>c+d.devices.length,0);await re(a?"Generate new disguise values?":`Switch to ${r.title}?`,`${s} AmneziaWG device${s===1?"":"s"} stop connecting until they import their configuration again (from their personal link or from you).${o==="max"?" They need an app with AmneziaWG 3.1.":""}`,a?"Generate and apply":"Switch and apply",!0)&&await W(()=>P.serverObfuscation(e.id,o),a?"New values applied":`${r.title} applied`)&&(K("Devices are marked “Update config” until they import again.","info",6e3),await n.refresh())}function qr(n,e){let o=n.st,a=se(String(e.port),{inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),r=se(e.mtu?String(e.mtu):"",{placeholder:"Auto",inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),i=`${e.mtus.computer} for computers and routers, ${e.mtus.phone} for phones and tablets`,s=e.mtu?`Now ${i}. Empty = automatic.`:`Automatic by device type and disguise: now ${i}. Lower it if some sites hang.`,l=se(String(e.keepalive??""),{placeholder:"25",inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),c=Pt(e.preset)?e.preset:void 0,d=c??"standard",p=D("",()=>Fr(n,e,d,d===c),"neutral"),u=()=>dom.content(p,d===c?[v("reset")," Generate new values"]:[`Switch to ${Pt(d).title}`]);u();let w=o.awg_state?.tools!==!1;return _t("",[Mo("AmneziaWG",e.ifname),he("globe","Listening","Where devices reach this core from the internet",[ne("UDP port",a,"Opened on the WAN firewall automatically.")]),he("file","In every device configuration","Changing these marks devices “Update config” until they import again",[ne("MTU",r,s),ne("Keep-alive",l,"Seconds between packets devices send to keep NAT open. 0 = off.")]),he("shield","Disguise","So networks that block VPNs do not recognise the tunnel. Off = plain WireGuard",[Zt(o.awg,d,g=>{d=g,u()},c,w),w&&!o.awg.v3?ht("info",["This router runs an older AmneziaWG. ",t("b",{},"Maximum")," becomes available with kmod-amneziawg and amneziawg-tools 3.1."]):"",Ur(e.obf??{})??"",t("div",{class:"dl-row-end"},[t("span",{class:"dl-sub"},"Applies at once: every AmneziaWG device imports its configuration again."),p])]),t("details",{class:"dl-params"},[t("summary",{},[v("chevron"),t("span",{},"Tunnel"),t("span",{class:"dl-pcount"},"3")]),t("div",{class:"dl-params-body"},[ne("Interface",t("span",{class:"dl-mono"},`${e.ifname} · router ${e.address}`)),ne("Tunnel subnet",t("span",{class:"dl-mono"},e.subnet),"Device addresses come from it."),ne("Server public key",t("span",{class:"dl-keyrow"},[t("code",{class:"dl-mono"},e.public_key),D([v("copy")],()=>ue(e.public_key,"Public key copied"),"neutral",{title:"Copy",class:"cbi-button cbi-button-neutral dl-icon-only sm"})]))])])],[t("span",{class:"dl-sub"},"Port, MTU and keep-alive apply at once."),D("Save",()=>n.save({port:a.value,mtu:r.value,keepalive:l.value},"AmneziaWG saved"),"positive")])}function Kr(n){let e=Pt(n.preset),o=n.obf??{},a=(s,l)=>t("span",{class:`dl-segs ${l}`},[0,1,2,3].map(c=>t("i",{class:c+o[s]).map(s=>`${s.toUpperCase()} ${o[s]}`);return i.length&&r.push(i.slice(0,2).join(" · ")+(i.length>2?` +${i.length-2}`:"")),["h1","h2","h3","h4"].some(s=>o[s]&&o[s]!==String(["h1","h2","h3","h4"].indexOf(s)+1))&&r.push("H1–H4 random"),o.i1&&r.push(o.i1.includes("0x8580")?"DNS-like first packet":"Signature packets"),o.header_protection_key&&r.push("Encrypted headers"),r.length||r.push(e?.id==="off"?"Plain WireGuard":"No values yet"),t("div",{class:"dl-bento-tile dl-disg"},[t("div",{class:"dl-bento-head"},[t("span",{class:"dl-metric-label"},"Disguise"),t("a",{href:`${L.url("admin/network/dawnline/server")}?server=${encodeURIComponent(n.id)}§ion=awg`},"Change")]),t("div",{class:"dl-disg-id"},[t("span",{class:"dl-disg-ic"},v(e?.ic??"shield")),t("span",{class:"dl-stack"},[t("b",{},e?e.title:"Custom"),t("span",{class:"dl-sub"},e?e.short:"Set by hand")])]),e?t("div",{class:"dl-disg-meters"},[t("span",{},"Stealth"),a(e.stealth,"acc"),t("span",{},"Speed"),a(e.speed,"ok")]):"",t("div",{class:"dl-disg-chips"},r.map(s=>t("span",{},s)))])}var An={id:"awg",label:"AmneziaWG",settingsCard:qr,overviewTile:Kr,connectBlock:Gr,qrText:n=>n.conf,appKey:{label:"Copy AmneziaVPN key",make:n=>Dn(n,`${n.server} · ${n.person} · ${n.name}`)},file:{label:"Download .conf",make:n=>({name:n.filename,text:n.conf})}};var Jr={awg:An};function Ie(n){return Jr[n?.core||"awg"]??An}function bt(n,e){return Ie(n.find(o=>o.id===e))}var Vr=2,Qt=new Set,zn=null,To=!1;async function Yr(){if(document.visibilityState!=="visible"||!Qt.size)return;let n=await P.rev().catch(()=>null);if(!n)return;let e=zn!=null&&n.rev!==zn;zn=n.rev,e&&Qt.forEach(o=>o())}function Xt(n){return Qt.add(n),To||(To=!0,poll.add(Yr,Vr)),()=>Qt.delete(n)}var Hn="https://unpkg.com/maplibre-gl@6.14.0/dist",Co="https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json",Po="https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",Zr={online:0,"24h":86400,"7d":7*86400,"30d":30*86400},Dt=null;function Qr(n){return n.appendChild(t("link",{rel:"stylesheet",href:`${Hn}/maplibre-gl.css`})),Dt||(Dt=import(`${Hn}/maplibre-gl.mjs`).then(o=>(o.getWorkerUrl()||o.setWorkerUrl(`${Hn}/maplibre-gl-worker.mjs`),o),()=>{throw Dt=null,new Error("Could not load the map library (no internet access from this browser?)")}),Dt)}function en(){let n=document.documentElement.getAttribute("data-darkmode");return n!=null?n==="true":window.matchMedia?.("(prefers-color-scheme: dark)").matches??!1}var Xr=10,Do=30,ei=62,Ao=4.5,ti=7,Nn="#3b82f6",tn="#8a8a8a";function zo(n,e,o=.2,a=64){let[r,i]=n,[s,l]=e,c=s-r,d=c>180?s-360:c<-180?s+360:s,p=d-r,u=l-i,w=Math.hypot(p,u);if(w===0||o===0)return[n,[d,l]];let g=-u/w,m=p/w,k=w*o,H=(r+d)/2+g*k,B=(i+l)/2+m*k,E=[],y=Math.max(2,Math.floor(a));for(let S=0;S<=y;S+=1){let b=S/y,x=1-b;E.push([x*x*r+2*x*b*H+b*b*d,x*x*i+2*x*b*B+b*b*l])}return E}function Rn(n,e){let o=new Map;for(let a of n.geo.points){if(n.person&&a.person!==n.person||n.device&&a.device!==n.device||(e==="online"?!a.online:n.now-a.ts>Zr[e]))continue;let r=n.device?`${a.city}|${a.cc}`:n.person?`${a.device}|${a.city}|${a.cc}`:a.device,i=o.get(r);(!i||a.online&&!i.online||a.online===i.online&&a.ts>i.ts)&&o.set(r,a)}return[...o.values()]}function In(n,e){let o=0;return Rn(n,e).sort((a,r)=>Number(r.online)-Number(a.online)||r.ts-a.ts).map(a=>({...a,n:a.online?0:++o}))}var Je=class{constructor(e,o="online",a=380){this.cb=e;this.map=null;this.gl=null;this.markers=[];this.popup=null;this.theme=null;this.resize=null;this.fitBlind=!1;this.data=null;this.fitted=!1;this.fitKey=null;this.people=[];this.slots=[];this.merged=[];this.piles=new Map;this.dock=null;this.dockKey="";this.dockQuiet=!1;this.piledKeys=new Set;this.foldedKeys=new Set;this.targetZoom=null;this.before=null;this.hiddenKey="";this.focused=null;this.range=o,this.status=t("div",{class:"dl-map-status"}),this.card=t("div",{class:"dl-map-card","aria-live":"polite"}),this.el=t("div",{class:"dl-geomap",style:`height:${a}px`},[this.status,this.card])}async mount(e){this.data=e;try{this.gl=await Qr(this.el)}catch(a){this.status.textContent=a.message;return}this.map=new this.gl.Map({container:this.el,style:en()?Co:Po,center:[e.geo.home?.lon??20,e.geo.home?.lat??50],zoom:1,renderWorldCopies:!1,attributionControl:{compact:!0},minZoom:1}),this.map.on("style.load",()=>this.layers()),this.map.on("move",()=>this.declutter()),this.map.once("idle",()=>{let a=this.el.querySelector(".maplibregl-ctrl-attrib");a?.classList.remove("maplibregl-compact-show"),a?.removeAttribute("open")}),this.resize=new ResizeObserver(()=>{!this.map||!this.el.clientWidth||!this.el.clientHeight||(this.map.resize(),this.fitBlind&&(this.fitKey=null,this.draw()))}),this.resize.observe(this.el);let o=en();this.theme=new MutationObserver(()=>{!this.map||en()===o||(o=en(),this.map.setStyle(o?Co:Po))}),this.theme.observe(document.documentElement,{attributes:!0,attributeFilter:["data-darkmode"]})}layers(){if(this.map){this.hiddenKey="",this.map.setProjection({type:"globe"}),this.map.addSource("dl-areas",{type:"geojson",data:{type:"FeatureCollection",features:[]}}),this.map.addLayer({id:"dl-area",type:"circle",source:"dl-areas",paint:{"circle-radius":["interpolate",["exponential",2],["zoom"],2,6,6,26,9,140,12,900],"circle-color":["case",["get","online"],Nn,tn],"circle-opacity":["case",["get","online"],.12,.06],"circle-stroke-width":1,"circle-stroke-color":["case",["get","online"],Nn,tn],"circle-stroke-opacity":["case",["get","online"],.35,.15]}}),this.map.addSource("dl-trail",{type:"geojson",data:{type:"FeatureCollection",features:[]}}),this.map.addLayer({id:"dl-trail",type:"line",source:"dl-trail",layout:{"line-join":"round","line-cap":"round"},paint:{"line-color":tn,"line-width":1.5,"line-opacity":.85,"line-dasharray":[0,2.5]}}),this.map.addSource("dl-arcs",{type:"geojson",data:{type:"FeatureCollection",features:[]}});for(let e of[!1,!0])this.map.addLayer({id:e?"dl-arc-live":"dl-arc-recent",type:"line",source:"dl-arcs",filter:["==",["get","online"],e],layout:{"line-join":"round","line-cap":"round"},paint:{"line-color":e?Nn:tn,"line-width":2,"line-opacity":.85,"line-dasharray":[2,2]}});this.draw()}}setRange(e){this.range=e,this.fitKey=null,this.draw()}update(e){this.data=e,this.draw()}destroy(){this.dropCard();for(let e of this.piles.values())e.marker.remove();this.piles.clear(),this.theme?.disconnect(),this.resize?.disconnect(),this.map?.remove(),this.map=null}groups(e){let o=new Map;for(let a of e){let r=`${a.person}|${a.city||`${a.lat.toFixed(1)},${a.lon.toFixed(1)}`}|${a.cc}`,i=o.get(r);i||(i={key:r,person:a.person,lat:a.lat,lon:a.lon,city:a.city,country:a.country,cc:a.cc,asn:a.asn,org:a.org,online:!1,ts:0,points:[]},o.set(r,i)),i.points.push(a),i.online||(i.online=a.online),i.ts=Math.max(i.ts,a.ts)}return[...o.values()]}draw(){if(!this.map||!this.data||!this.map.getSource("dl-arcs"))return;let e=this.data,o=this.groups(Rn(e,this.range)),a=e.person||e.device?null:e.geo.home;for(let d of this.markers)d.remove();this.markers=[];let r=e.person||e.device?null:oi(o,a),i=o.map(d=>({g:d,at:r?.get(d.key)??[d.lon,d.lat]}));if(this.slots=[],this.map.getSource("dl-areas").setData({type:"FeatureCollection",features:i.map(({g:d})=>({type:"Feature",properties:{online:d.online,key:d.key},geometry:{type:"Point",coordinates:[d.lon,d.lat]}}))}),this.map.getSource("dl-arcs").setData({type:"FeatureCollection",features:a?i.map(({g:d,at:p})=>({type:"Feature",properties:{online:d.online,person:d.person,key:d.key},geometry:{type:"LineString",coordinates:zo([a.lon,a.lat],p)}})):[]}),a){let d=t("span",{class:"dl-mk-host"});d.innerHTML=`${$t("server","dl-mk-host-ic")}`,this.dock=d.appendChild(t("span",{class:"dl-mk-dock"})),this.dockQuiet=this.dockKey!=="",this.dockKey="";let p=t("div",{class:"dl-mk-hub",title:`Home router${a.city?` · ${a.city}`:""}${a.org?` · ${a.org}`:""}`},[d,t("span",{class:"dl-mk-label chip"},a.city||"Home")]);p.addEventListener("mouseenter",()=>this.showMerged(a.city||"the server")),p.addEventListener("mouseleave",()=>this.focus(this.focused)),p.addEventListener("click",()=>this.zoomToMerged()),this.add(p,[a.lon,a.lat],!0)}let s=e.device?[...i].sort((d,p)=>Number(d.g.online)-Number(p.g.online)||d.g.ts-p.g.ts):[];this.map.getSource("dl-trail")?.setData({type:"FeatureCollection",features:s.length>1?[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:s.slice(1).flatMap((d,p)=>zo(s[p].at,d.at))}}]:[]});let l=new Map(e.device?In(e,this.range).map(d=>[`${d.city}|${d.cc}`,d.n]):[]);this.people=[];for(let{g:d,at:p}of i){let u=d.points.length,w=e.people.find(H=>H.id===d.person);if(e.person){let H=e.device?this.stepMarker(d,p,w,l.get(`${d.points[0].city}|${d.points[0].cc}`)??0):this.placeMarker(d,p,w);this.add(H,p);continue}let g=d.points.map(H=>w?.devices.find(B=>B.id===H.device)?.kind??"other"),m=t("span",{class:"dl-mk-badge"});m.innerHTML=u<=2?g.map(H=>$t(H,"dl-mk-badge-ic")).join(""):String(u);let k=t("button",{type:"button",class:`dl-mk${d.online?" online":""}`,"aria-label":`${w?.name??"Someone"}: ${u} device${u===1?"":"s"} in ${d.city||"an unknown city"}`},[t("span",{class:"dl-mk-av"},[Ce(w?.name??"?"),m]),t("span",{class:"dl-mk-label below"},d.city||d.cc||"?")]);k.addEventListener("mouseenter",()=>this.focus(d.person)),k.addEventListener("mouseleave",()=>this.focus(null)),this.people.push({el:k,person:d.person}),k.addEventListener("click",H=>{H.stopPropagation(),this.openPopup(d,p,k)}),this.add(k,p,!1,w?.name??"Someone",`${d.city||d.cc||"?"} · ${d.online?"now":ie(d.ts,e.now)}`,d.key,d)}this.declutter();let c=i.map(d=>d.g.key).sort().join(";");if(c!==this.fitKey&&!this.popup){let d=this.fitted&&!this.fitBlind;if(this.fitBlind=!this.el.clientWidth||!this.el.clientHeight,this.fitKey=c,this.fitted=!0,a&&!i.length){let p={center:[a.lon,a.lat],zoom:12};d?this.glide(12,()=>this.map.flyTo({...p,duration:1200})):this.map.jumpTo(p)}else{let p=i.map(u=>u.at);a&&(p.length===0||this.range!=="online"||i.some(u=>u.g.online))&&p.push([a.lon,a.lat]),this.fit(p,d)}}this.status.textContent=i.length||a?"":"No locations yet",this.status.style.display=this.status.textContent?"":"none",this.focus(this.focused&&this.people.some(d=>d.person===this.focused)?this.focused:null)}add(e,o,a=!1,r,i,s,l){s&&this.foldedKeys.has(s)&&e.classList.add("merged"),s&&this.piledKeys.has(s)&&e.classList.add("piled"),e.dataset.key=s??"",e.classList.add("dl-mk-new"),requestAnimationFrame(()=>requestAnimationFrame(()=>e.classList.remove("dl-mk-new")));let c=new this.gl.Marker({element:e}).setLngLat(o).addTo(this.map);this.markers.push(c),this.slots.push({marker:c,el:e,at:o,fixed:a,who:r,where:i,g:l})}declutter(){if(!this.map)return;let e=this.map.getZoom();this.el.classList.toggle("dl-lod-far",e=Ao&&e{let l=this.map.project(s.at),c=s.el.querySelector(":scope > .dl-mk-host, :scope > .dl-mk-av, :scope > .dl-mk-tile");return{x:l.x,y:l.y,r:(c?.offsetWidth||24)/2+3,fixed:s.fixed}}),a=o.filter(s=>s.fixed);this.merged=[],this.foldedKeys.clear();let r=this.targetZoom==null?1:Math.min(1,2**(this.targetZoom-this.map.getZoom()));o.forEach((s,l)=>{if(s.fixed)return;let c=this.slots[l],d=c.el.classList.contains("merged")?12:6,p=a.find(u=>Math.hypot(u.x-s.x,u.y-s.y)*r{let d=this.slots[c];!d||d.fixed||(o[c].fixed&&([s,l]=[0,0]),d.marker.setOffset([s,l]),ri(d.el,s,l))})}closePopup(e=!1){let o=this.popup;if(!o||o.card.classList.contains("leaving"))return;o.card.classList.add("leaving"),setTimeout(()=>{this.popup===o&&this.dropCard()},140);let a=this.before;if(this.before=null,!a)return;let r=()=>this.map?.flyTo({...a,duration:800});if(!e)return r();let i=!1,s=()=>{i||(i=!0,window.removeEventListener("pointerup",s,!0),window.removeEventListener("pointercancel",s,!0),setTimeout(r,0))};window.addEventListener("pointerup",s,!0),window.addEventListener("pointercancel",s,!0),setTimeout(s,1500)}dropCard(){this.popup?.off(),this.popup?.card.remove(),this.popup=null}showMerged(e){this.merged.length&&(dom.content(this.card,[t("div",{class:"dl-map-card-head"},[t("b",{},`Near ${e}`)," · click to zoom in"]),...this.merged.map(o=>t("div",{class:"dl-map-card-row"},[t("span",{},o.who),t("span",{class:"dl-faint"},o.where)]))]),this.card.classList.add("on"))}paintDock(){let e=this.dock;if(!e)return;let o=this.merged.map(r=>`${r.key}:${r.online?1:0}`).join("|");if(o===this.dockKey)return;this.dockKey=o,e.parentElement?.classList.toggle("docked",this.merged.length>0);let a=this.slots.find(r=>r.fixed).at;this.merged.length&&No(e,this.merged,this.faceActions(()=>[a]),this.dockQuiet),this.dockQuiet=!1}faceActions(e){return{click:(o,a)=>this.openFace(o,a,e()),hover:o=>this.focus(o?.g?.person??null)}}pileUp(e){let o=new Set;if(!this.data?.person&&!this.data?.device){let a=e.flatMap((l,c)=>!l.fixed&&this.slots[c].el.querySelector(":scope > .dl-mk-av")?[c]:[]),r=new Map(a.map(l=>[l,l])),i=l=>r.get(l)===l?l:i(r.get(l));for(let l of a)for(let c of a){if(c<=l)continue;let d=this.slots[l].el.classList.contains("piled")&&this.slots[c].el.classList.contains("piled");Math.hypot(e[l].x-e[c].x,e[l].y-e[c].y)this.slots[k]),d=c.map(Ho),p=d.map(k=>k.key).sort().join(",");o.add(p);let u=[c.reduce((k,H)=>k+H.at[0],0)/c.length,c.reduce((k,H)=>k+H.at[1],0)/c.length],w=this.piles.get(p);if(!w){let k=t("span",{class:"dl-mk-pile-box"}),H=[...new Set(c.map(y=>y.g?.city||y.g?.cc||"?"))],B=t("div",{class:"dl-mk-pile"},[k,t("span",{class:"dl-mk-label below"},H.length===1?H[0]:`${c.length} people`)]);w={marker:new this.gl.Marker({element:B}).setLngLat(u).addTo(this.map),el:B,box:k,faces:d},B.addEventListener("mouseleave",()=>this.focus(this.focused));let E=w;B.addEventListener("click",y=>{y.stopPropagation(),this.zoomInTo(E.faces.map(S=>S.at),!1)}),this.piles.set(p,w)}w.faces=d;let g=w;No(w.box,d,this.faceActions(()=>g.faces.map(k=>k.at)));for(let k of l)this.slots[k].el.classList.add("piled"),Object.assign(e[k],{r:0,fixed:!0});let m=this.map.project(u);e.push({x:m.x,y:m.y,r:(w.el.offsetWidth||60)/2+3,fixed:!0})}}this.piledKeys=new Set(this.slots.filter(a=>a.el.classList.contains("piled")).map(a=>a.el.dataset.key??"")),this.slots.forEach((a,r)=>{(!e[r].fixed||a.fixed||a.el.classList.contains("merged"))&&a.el.classList.remove("piled")});for(let[a,r]of this.piles)o.has(a)||(this.piles.delete(a),r.el.classList.add("out"),setTimeout(()=>r.marker.remove(),200))}zoomToMerged(){!this.map||!this.merged.length||this.zoomInTo([this.slots.find(e=>e.fixed).at,...this.merged.map(e=>e.at)],!1)}openFace(e,o,a){if(!e.g)return;if(a.every(i=>nn(i,e.at)<1))return this.openPopup(e.g,e.at,o);let r=()=>{let i=this.slots.find(s=>s.el.dataset.key===e.key);i?.g&&!i.el.classList.contains("merged")&&!i.el.classList.contains("piled")&&this.openPopup(i.g,i.at,i.el)};this.zoomInTo(this.nearby(e.at),!0)?this.map.once("moveend",r):r()}nearby(e){return[e,...this.slots.filter(o=>!o.fixed&&o.at!==e&&nn(o.at,e)<=Do).map(o=>o.at)]}zoomInTo(e,o){let a=new this.gl.LngLatBounds;for(let p of e)a.extend(p);let r=e.some(p=>e.some(u=>nn(p,u)>Do)),i=this.map.cameraForBounds(a,{padding:50,maxZoom:r?12:Xr}),s=this.map.getZoom(),l=e.map(p=>this.map.project(p)),c=0;l.forEach((p,u)=>l.slice(u+1).forEach(w=>{let g=Math.hypot(p.x-w.x,p.y-w.y),m=s+Math.log2(ei/Math.max(g,1e-6));m<=12&&(c=Math.max(c,m))}));let d=Math.min(12,Math.max(i?.zoom??0,c));return d<=s+.05?!1:(o&&!this.before&&(this.before={center:this.map.getCenter().toArray(),zoom:s}),this.map.flyTo({center:i?.center??a.getCenter(),zoom:d,duration:800}),!0)}placeMarker(e,o,a){let r=this.data.now,i=[...e.points].sort((u,w)=>Number(w.online)-Number(u.online)||w.ts-u.ts)[0],s=a?.devices.find(u=>u.id===i.device)?.kind??"other",l=e.points.length,c=t("span",{class:"dl-mk-tile"});c.innerHTML=$t(s,"dl-mk-tile-ic")+(l>1?`${l}`:"");let d=e.online?"now":ie(e.ts,r),p=t("button",{type:"button",class:`dl-mk place${e.online?" online":""}`,style:e.online?null:`--dl-mk-fade:${Math.max(.4,1-.6*(r-e.ts)/(30*86400)).toFixed(2)}`,"aria-label":`${l} device${l===1?"":"s"} in ${e.city||"an unknown city"}, ${d}`},[c,t("span",{class:"dl-mk-label below"},[e.city||e.cc||"?",t("span",{class:"dl-mk-when"},d)])]);return p.addEventListener("click",u=>{u.stopPropagation(),this.openPopup(e,o,p)}),p}stepMarker(e,o,a,r){if(e.online)return this.placeMarker(e,o,a);let i=ie(e.ts,this.data.now),s=t("button",{type:"button",class:"dl-mk place step","aria-label":`${r}: ${e.city||"an unknown city"}, ${i}`},[t("span",{class:"dl-mk-tile sm"},String(r)),t("span",{class:"dl-mk-label below"},[e.city||e.cc||"?",` · ${i}`])]);return s.addEventListener("click",l=>{l.stopPropagation(),this.openPopup(e,o,s)}),s}focus(e){this.focused=e;for(let s of this.people)s.el.classList.toggle("dim",!!e&&s.person!==e),s.el.classList.toggle("hl",s.person===e);let o=e?["case",["==",["get","person"],e],.85,.15]:.85;for(let s of["dl-arc-live","dl-arc-recent"])this.map?.getLayer(s)&&this.map.setPaintProperty(s,"line-opacity",o);if(this.card.classList.toggle("on",!!e),!e||!this.data)return;let a=this.data,r=a.people.find(s=>s.id===e),i=Rn(a,this.range).filter(s=>s.person===e).sort((s,l)=>Number(l.online)-Number(s.online)||l.ts-s.ts);dom.content(this.card,[t("div",{class:"dl-map-card-head"},[t("b",{},r?.name??e),` · ${i.length} device${i.length===1?"":"s"}`]),...i.map(s=>t("div",{class:"dl-map-card-row"},[t("span",{},r?.devices.find(l=>l.id===s.device)?.name??"Device"),t("span",{class:"dl-faint"},`${s.city||s.cc||"?"} · ${s.online?"now":ie(s.ts,a.now)}`)]))])}fit(e,o=!1){if(!e.length)return;let a=(d,p)=>{let u=Math.PI/180,w=(p[1]-d[1])*u,g=(p[0]-d[0])*u,m=Math.sin(w/2)**2+Math.cos(d[1]*u)*Math.cos(p[1]*u)*Math.sin(g/2)**2;return 12742*Math.asin(Math.sqrt(m))},r=[e.reduce((d,p)=>d+p[0],0)/e.length,e.reduce((d,p)=>d+p[1],0)/e.length],i=e;if(e.length>=5){let d=[...e].sort((p,u)=>a(r,p)-a(r,u));i=d.slice(0,Math.ceil(d.length*.9))}let s=new this.gl.LngLatBounds(i[0],i[0]);i.forEach(d=>s.extend(d));let l=this.el.clientHeight||380,c={padding:{top:Math.min(60,l/5),bottom:Math.min(40,l/8),left:48,right:48},maxZoom:this.data?.person?11:12};o?this.glide(this.map.cameraForBounds(s,c)?.zoom??null,()=>this.map.fitBounds(s,{...c,duration:1200})):this.map.fitBounds(s,{...c,duration:0})}glide(e,o){this.targetZoom=e,this.declutter(),this.map.once("moveend",()=>{this.targetZoom=null,this.declutter()}),o()}openPopup(e,o,a){let r=this.data,i=[e.city,e.cc||e.country].filter(Boolean).join(", "),s=[...new Set(e.points.map(y=>y.person))],l=e.points.sort((y,S)=>Number(S.online)-Number(y.online)||S.ts-y.ts).map(y=>{let S=r.people.find(x=>x.id===y.person),b=S?.devices.find(x=>x.id===y.device);return t("button",{type:"button",class:"dl-pop-row",click:()=>this.cb.openDevice(y.person,y.device)},[t("span",{class:`dl-pop-dot${y.online?" on":""}`}),t("span",{class:"dl-pop-name"},[t("b",{},S?.name??y.person),` · ${b?.name??"device"}`]),t("span",{class:"dl-faint dl-nowrap"},y.online?"now":ie(y.ts,r.now))])}),c=t("div",{class:"dl-pop"},[t("div",{class:"dl-pop-head"},[t("span",{class:"dl-pop-net"},v("globe")),t("div",{class:"dl-stack"},[t("strong",{},e.org||"Unknown network"),t("span",{class:"dl-faint"},[e.asn?`AS${e.asn} · `:"",i?`${i} · approximate`:"approximate location"])])]),t("div",{class:"dl-pop-list"},l),s.length===1?t("div",{class:"dl-pop-actions"},[t("button",{type:"button",class:"cbi-button cbi-button-positive important",click:()=>this.cb.openPerson(s[0])},`Open ${r.people.find(y=>y.id===s[0])?.name??"person"}`)]):""]);this.zoomInTo(this.nearby(o),!0),this.dropCard();let d=t("div",{class:"dl-root dl-popcard",role:"dialog"},[t("span",{class:"dl-popcard-tip"}),c]);document.body.appendChild(d);let p=this.el,u=a?.querySelector(".dl-mk-av, .dl-mk-tile")??a??null,w=()=>{if(!u)return;let y=u.getBoundingClientRect(),S=p.getBoundingClientRect(),b=y.left+y.width/2,x=y.top+y.height/2;d.classList.toggle("away",bS.right||xS.bottom);let M=d.offsetWidth,h=d.offsetHeight,f=y.top-h-12>=8||y.top>window.innerHeight-y.bottom,R=Math.min(Math.max(8,b-M/2),window.innerWidth-M-8);d.classList.toggle("above",f),d.classList.toggle("below",!f),d.style.left=`${R}px`,d.style.top=`${f?y.top-h-12:y.bottom+12}px`,d.style.setProperty("--tip-x",`${b-R}px`)},g=y=>{y.target?.closest(".dl-popcard, .maplibregl-marker")||this.closePopup(!0)},m=y=>{y.key==="Escape"&&this.closePopup()},k=y=>{y.target instanceof Element&&y.target.closest(".dl-popcard")||this.closePopup()},H=()=>this.closePopup();this.map.on("move",w),window.addEventListener("scroll",k,{capture:!0,passive:!0}),window.addEventListener("resize",w),document.addEventListener("pointerdown",g,!0),document.addEventListener("keydown",m);let B=Ae(H);window.addEventListener("pagehide",H),this.popup={card:d,off:()=>{this.map?.off("move",w),window.removeEventListener("scroll",k,!0),window.removeEventListener("resize",w),document.removeEventListener("pointerdown",g,!0),document.removeEventListener("keydown",m),B(),window.removeEventListener("pagehide",H)}};let E=window.setInterval(()=>{if(this.popup?.card!==d)return clearInterval(E);(!p.isConnected||!p.getClientRects().length)&&this.dropCard()},400);w()}};function ni(n,e=6){let o=n.map(a=>({x:a.x,y:a.y}));for(let a=0;a<16;a++){let r=!1;for(let i=0;i[a.x-n[r].x,a.y-n[r].y])}function oi(n,e){let o=new Map,a=e?[[e.lon,e.lat]]:[],r=i=>a.some(s=>nn(i,s)<1.3);for(let i of[...n].sort((s,l)=>s.key>>12)/1048575),c=(s&4095)/4096*2*Math.PI,d=[i.lon,i.lat];for(let p=0;p<24;p++){let u=c+p*2.39996,w=Math.min(8,l+p*.25);if(d=[i.lon+w*Math.sin(u)/(111.32*Math.cos(i.lat*Math.PI/180)),i.lat+w*Math.cos(u)/111.32],!r(d))break}a.push(d),o.set(i.key,d)}return o}function ai(n){let e=2166136261;for(let o=0;o>>0}function Ho(n){return{key:n.el.dataset.key??"",who:n.who??"Someone",where:n.where??"",online:!!n.g?.online,at:n.at,badge:n.el.querySelector(".dl-mk-badge")?.innerHTML??"",g:n.g}}function No(n,e,o,a=!1){let r=e.length>3,i=()=>[...n.children].filter(m=>!m.classList.contains("out")),s=new Map(i().map(m=>[m,m.getBoundingClientRect().left])),l=n.getBoundingClientRect().width,c=new Map;n.querySelectorAll(".dl-mk-face:not(.out)").forEach(m=>c.set(m.dataset.key??"",m));let d=n.querySelector(".dl-mk-more:not(.out)"),p=m=>{Object.assign(m.style,{position:"absolute",left:`${m.offsetLeft}px`,top:`${m.offsetTop}px`,transform:""}),m.classList.add("out"),setTimeout(()=>m.remove(),200)},u=[];for(let m of e.slice(0,r?2:3)){let k=c.get(m.key);if(c.delete(m.key),!k){let E=t("button",{type:"button",class:`dl-mk-face${a?"":" in"}`,"data-key":m.key},[t("span",{class:"dl-mk-av"},Ce(m.who)),t("span",{class:"dl-mk-badge"})]);E.addEventListener("animationend",()=>E.classList.remove("in"),{once:!0}),k=E}let H=k,B=H.querySelector(".dl-mk-badge");B.innerHTML!==m.badge&&(B.innerHTML=m.badge),H.title=`${m.who} · ${m.where}`,H.setAttribute("aria-label",`${m.who}, ${m.where}`),H.classList.toggle("on",m.online),H.onclick=E=>{E.stopPropagation(),o.click(m,H)},H.onmouseenter=()=>o.hover(m),H.onmouseleave=()=>o.hover(null),u.push(H)}for(let m of c.values())p(m);if(r){if(!d){d=t("span",{class:`dl-mk-more${a?"":" in"}`});let m=d;m.addEventListener("animationend",()=>m.classList.remove("in"),{once:!0})}d.textContent=`+${e.length-2}`,u.push(d)}else d&&p(d);let w=null;for(let m of u)(w?w.nextElementSibling:n.firstElementChild)!==m&&(w?w.after(m):n.prepend(m)),w=m;for(let m of u){let k=s.get(m);if(k==null)continue;let H=k-m.getBoundingClientRect().left;Math.abs(H)<.5||(m.style.transition="none",m.style.transform=`translateX(${H}px)`,m.offsetWidth,m.style.transition="",m.style.transform="")}n.style.width="";let g=n.getBoundingClientRect().width;if(l&&Math.abs(g-l)>.5){n.style.width=`${l}px`,n.offsetWidth,n.style.width=`${g}px`;let m=()=>{n.style.width="",n.removeEventListener("transitionend",m)};n.addEventListener("transitionend",m),setTimeout(m,400)}}function nn(n,e){let o=Math.PI/180,a=Math.sin((e[1]-n[1])*o/2)**2+Math.cos(n[1]*o)*Math.cos(e[1]*o)*Math.sin((e[0]-n[0])*o/2)**2;return 12742*Math.asin(Math.min(1,Math.sqrt(a)))}function ri(n,e,o){let a=n.querySelector(":scope > .dl-mk-ptr"),r=Math.hypot(e,o);if(r<1){a?.remove();return}a||(a=t("span",{class:"dl-mk-ptr"},[t("i",{class:"line"}),t("i",{class:"spot"})]),n.prepend(a));let i=a.firstElementChild,s=a.lastElementChild;i.style.width=`${r}px`,i.style.transform=`rotate(${Math.atan2(-o,-e)}rad)`,s.style.transform=`translate(${-e}px, ${-o}px)`}function xt(n,e,o=!0){let a=[["online","Online now"],["24h","24h"],["7d","7 days"],["30d","30 days"]],r=t("div",{class:"dl-seg",role:"tablist"});for(let[i,s]of a)i==="online"&&!o||r.appendChild(t("button",{type:"button",role:"tab",class:i===n?"on":"","data-v":i,click:()=>{r.querySelectorAll("button").forEach(l=>l.classList.toggle("on",l.dataset.v===i)),e(i)}},s));return r}function wt(n){return`${L.url("admin/network/dawnline/server")}?${n?`server=${encodeURIComponent(n)}&`:""}section=people`}function ke(n,e){return`${L.url("admin/network/dawnline/person")}?id=${encodeURIComponent(n)}${e?`&device=${encodeURIComponent(e)}`:""}`}function ii(n){return n?new Date(n*1e3).toLocaleString("en-GB",{day:"numeric",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"}):"—"}function Ro(n,e,o=!1){return t("div",{class:"dl-kvrow"},[t("span",{class:"dl-kvrow-k"},n),t("button",{type:"button",class:`dl-kvrow-v copy${o?" dl-mono":""}`,title:"Copy",click:()=>ue(e,`${n} copied`)},[t("span",{},e),v("copy")])])}function on(n,e){return t("div",{class:"dl-kvrow"},[t("span",{class:"dl-kvrow-k"},n),t("span",{class:"dl-kvrow-v"},e)])}var Io={connect:["ok","Connected","plug"],disconnect:["","Went offline","plug"],roam:["","Changed network","network"],device_added:["ok","Added","plus"],device_removed:["","Removed","trash"],device_keys:["","New keys","reset"]};function si(n,e,o){let a=n.filter(r=>r.device===e&&Io[r.type]).reverse().slice(0,12);return a.length?t("div",{class:"dl-dev-log"},a.map(r=>{let[i,s,l]=Io[r.type],c=r.type==="connect"?[r.detail?t("span",{class:"dl-muted"},` from ${r.detail}`):"",r.where?t("span",{class:"dl-muted"},` · ${r.where}`):""]:r.type==="roam"?[t("span",{class:"dl-muted"},` · ${r.detail??""}`)]:r.type==="device_added"||r.type==="device_removed"||r.type==="device_keys"?[t("span",{class:"dl-muted"},Pe(r)==="portal"?" on the portal":Pe(r)==="admin"?" by you":"")]:[],d=new Date(r.ts*1e3);return t("div",{class:`dl-dev-log-row${Pe(r)==="admin"?" dl-ev-by-admin":""}`},[Pe(r)==="admin"?t("span",{class:"dl-ev-tile",title:"Done by you in LuCI"},v("admin")):t("span",{class:`dl-ev-tile ev ${i}`},v(l)),t("span",{class:"dl-row-main"},[t("span",{},s),...c]),t("span",{class:"dl-faint dl-nowrap",title:d.toLocaleString()},ie(r.ts,o))])})):t("div",{class:"dl-sub"},"No activity yet.")}async function Bo(n,e,o){let a=await P.status(1).catch(()=>null),r=a?.people.find(s=>s.id===n),i=r?.devices.find(s=>s.id===e);a&&r&&i&&Be(r,i,{...o,geo:a.geo,now:a.now,today:Re(a.series),core:bt(a.servers,r.server)})}async function Be(n,e,o){let a=await W(()=>P.deviceConfig(e.id));if(!a)return;let r=o.core??Ie(null),i=e,s=n,l=o.geo,c=o.now,d=o.today??He(new Date),p=await r.connectBlock(a),u=t("div",{class:"dl-drawer-title"}),w=t("div",{}),g=t("div",{}),m=t("div",{},t("div",{class:"dl-sub"},"Loading…")),k=[],H=U=>{k=U.filter(F=>F.device===i.id),dom.content(m,si(U,i.id,c))},B=async(U=!1)=>{let F=o.events?.();if(F&&!U)return H(F);let oe=await P.events(5e3).catch(()=>null);oe&&H(oe.events)},E="30d",y=null,S=t("div",{class:"dl-dplaces"}),b=()=>({geo:l,people:[s],now:c??Date.now()/1e3,person:s.id,device:i.id}),x=()=>{if(!l?.enabled)return;let U=In(b(),E);dom.content(S,U.length?U.map(F=>t("div",{class:"dl-dplace-row"},[t("span",{class:`dl-dplace-n${F.online?" live":""}`},F.online?v(i.kind):String(F.n)),t("span",{class:"dl-row-main dl-stack"},[t("span",{},[F.city||F.cc||"Unknown city",F.org?t("span",{class:"dl-muted"},` · ${F.org}`):""]),t("span",{class:"dl-mono dl-faint"},F.ip)]),t("span",{class:F.online?"dl-dplace-now":"dl-faint dl-nowrap"},F.online?"now":ie(F.ts,c))])):t("div",{class:"dl-sub"},"No locations in this period."))},M=()=>{dom.content(u,[t("span",{class:`dl-dcard-ic${i.online?" on":""}`},v(i.kind)),t("div",{class:"dl-stack"},[t("div",{class:"dl-title-row"},[t("h3",{},i.name),D([v("edit")],()=>R(),"neutral",{title:"Rename",class:"cbi-button cbi-button-neutral dl-icon-only sm"})]),t("span",{class:"dl-sub"},`${s.name} · ${je[i.kind]}`)])]);let U=i.spark.reduce((F,oe)=>F+oe,0);dom.content(w,t("div",{class:"dl-dstats"},[t("div",{class:"dl-dstats-cell wide"},[t("span",{class:"dl-metric-label"},"Status"),qt(i,c,"Waiting for the first connection")]),t("div",{class:"dl-dstats-cell"},[t("span",{class:"dl-metric-label"},"This month"),t("b",{},te(i.month[0]+i.month[1])),t("span",{class:"dl-sub dl-mono"},`↓ ${te(i.month[1])} ↑ ${te(i.month[0])}`)]),t("div",{class:"dl-dstats-cell"},[t("span",{class:"dl-metric-label"},"Last 7 days"),t("b",{},te(U)),yo(i.spark,120,22,d)])])),dom.content(g,t("div",{class:"dl-kv2"},[Ro("Tunnel address",i.address),i.hostname&&s.access!=="internet"?Ro("Local address",i.hostname):"",i.endpoint&&!l?.points.some(F=>F.device===i.id&&F.ip===i.endpoint)?on("Client IP",i.endpoint):"",on("Total",t("span",{class:"dl-kv-act"},[`↓ ${te(i.total[1])} · ↑ ${te(i.total[0])}`,t("button",{type:"button",class:"dl-linkbtn danger",click:()=>vt("device",i.id,i.name,()=>setTimeout(f,300))},"Reset")])),on("Added",`${ii(i.created)} · ${i.created_by==="portal"?"from the portal":"by you"}`),on("Public key",t("span",{class:"dl-mono dl-faint"},a.amnezia.client_pub_key?`${a.amnezia.client_pub_key.slice(0,16)}…`:"—"))])),dom.content(C,[D([v(i.disabled?"play":"pause"),i.disabled?" Enable":" Disable"],async()=>{await W(()=>P.deviceUpdate(i.id,void 0,!i.disabled),i.disabled?"Device enabled":"Device disabled")&&await f()},"neutral",i.disabled?{}:{class:"cbi-button cbi-button-neutral dl-btn-warn"}),D([v("key")," New keys"],async()=>{if(!await re("Generate new keys?","The current configuration on this device stops working until it is imported again.","Generate",!0))return;await W(()=>P.deviceRotate(i.id),"New keys generated")&&(o.refresh(),O.close(),await Bo(s.id,i.id,o))}),t("span",{class:"dl-spacer"}),D([v("trash")," Remove"],async()=>{await re(`Remove ${i.name}?`,"The device is disconnected immediately and its configuration stops working.","Remove",!0)&&await W(()=>P.deviceDelete(i.id),"Device removed")&&(O.close(),o.refresh())},"negative")])},h=async()=>{let U=await P.status(1).catch(()=>null),F=U?.people.find(_=>_.id===s.id),oe=F?.devices.find(_=>_.id===i.id);!U||!F||!oe||(s=F,i=oe,l=U.geo,c=U.now,d=Re(U.series),M(),y?.update(b()),x())},f=async()=>{await h(),o.refresh()},R=()=>{let U=t("input",{type:"text",class:"cbi-input-text",value:i.name,maxlength:48});ae(`Rename ${i.name}`,[t("div",{class:"cbi-value"},[t("label",{class:"cbi-value-title"},"Name"),t("div",{class:"cbi-value-field"},U)])],[le()," ",D("Save",async()=>{await W(()=>P.deviceUpdate(i.id,U.value,void 0),"Renamed")&&(de(),await f())},"positive")]),setTimeout(()=>U.select(),50)},C=t("div",{class:"dl-drawer-actions"}),I=t("section",{class:"dl-dsec"},[t("div",{class:"dl-dsec-head"},[t("h4",{},"Connect")]),i.config_stale?t("div",{class:"dl-note warn"},[v("alert"),t("span",{},"This device has an older configuration: networks or DNS changed since it was set up. Import it again with the QR code, key or file below.")]):"",p]),Q=t("section",{class:"dl-dsec"},[t("div",{class:"dl-dsec-head"},[t("h4",{},"Activity"),t("div",{class:"dl-dsec-actions"},[t("button",{type:"button",class:"dl-linkbtn",click:()=>Ue({people:[s]},k,"csv",i.id)},"Export"),t("button",{type:"button",class:"dl-linkbtn danger",click:()=>Ke(`Clear ${i.name}'s activity`,`Removes events about ${i.name}.`,{device:i.id},()=>{B(!0),o.refresh()})},"Clear"),t("a",{href:`${L.url("admin/network/dawnline/diagnostics")}?tab=log`},"All activity")])]),m]),G=t("section",{class:"dl-dsec"},[t("div",{class:"dl-dsec-head"},t("h4",{},"Details")),g]),Y="";l?.enabled&&(y=new Je({openPerson:U=>location.href=ke(U),openDevice:(U,F)=>location.href=ke(U,F)},E,220),Y=t("section",{class:"dl-dsec"},[t("div",{class:"dl-dsec-head"},[t("h4",{},"Locations"),xt(E,U=>{E=U,y?.setRange(U),x()},!1)]),t("div",{class:"dl-dmap"},y.el),S]),x());let z=!i.handshake||i.config_stale,q=t("div",{class:"dl-stack gap16"},z?[w,I,G,Y,Q]:[w,G,Y,Q,I]);B();let X=()=>{h(),B()},ce=Xt(X),fe=window.setInterval(X,3e4),O=mo(u,q,C,()=>{clearInterval(fe),ce(),y?.destroy()});M(),y&&requestAnimationFrame(()=>y?.mount(b()))}function Oo(n,e,o,a){let r=a.core??Ie(null),i=()=>W(()=>P.deviceConfig(o.id)),s=[{label:"Show QR code",icon:v("qr"),run:async()=>{let l=await i();l&&ae(`${o.name} · QR code`,t("div",{class:"dl-qr-pane"},[qe(ft(r.qrText(l)),"dl-qr"),t("span",{class:"dl-sub"},"Scan with AmneziaVPN or AmneziaWG on the device.")]),le("Close"))}},{label:r.file.label,icon:v("download"),run:async()=>{let l=await i();if(!l)return;let c=r.file.make(l);Ee(c.name,c.text,"application/octet-stream")}},r.appKey?{label:r.appKey.label,icon:v("copy"),run:async()=>{let l=await i();l&&ue(await r.appKey.make(l),"Key copied")}}:null,null,{label:"Rename",icon:v("edit"),run:()=>Be(e,o,a)},{label:"New keys",icon:v("key"),run:async()=>{await re("Generate new keys?","The current configuration on this device stops working until it is imported again.","Generate",!0)&&await W(()=>P.deviceRotate(o.id),"New keys generated")&&a.refresh()}},{label:o.disabled?"Enable":"Disable",icon:v(o.disabled?"play":"pause"),warn:!o.disabled,run:async()=>{await W(()=>P.deviceUpdate(o.id,void 0,!o.disabled),o.disabled?"Device enabled":"Device disabled")&&a.refresh()}},{label:"Delete",icon:v("trash"),danger:!0,run:async()=>{await re(`Remove ${o.name}?`,"The device is disconnected immediately and its configuration stops working.","Remove",!0)&&await W(()=>P.deviceDelete(o.id),"Device removed")&&a.refresh()}}];we(n,s)}function it(n,e){let o=t("input",{type:"text",class:"cbi-input-text",placeholder:je.phone,maxlength:48}),a="phone",r=t("div",{class:"dl-kinds",role:"radiogroup","aria-label":"Type"},lo.map(s=>t("button",{type:"button",role:"radio",class:s===a?"on":"","aria-checked":s===a?"true":"false","data-kind":s,click:()=>{a=s,r.querySelectorAll("button").forEach(l=>{let c=l.dataset.kind===s;l.classList.toggle("on",c),l.setAttribute("aria-checked",c?"true":"false")}),o.placeholder=je[s]}},[v(s),t("span",{},je[s])]))),i=n.devices.length>=n.device_limit;ae(`Add a device for ${n.name}`,[i?t("p",{class:"dl-hint"},`${n.name} already has ${n.devices.length} of ${n.device_limit} devices. As admin you can still add one.`):"",t("div",{class:"dl-fld"},[t("span",{class:"dl-fld-label"},"Type"),r]),t("label",{class:"dl-fld"},[t("span",{class:"dl-fld-label"},"Name"),o])],[le()," ",D("Add device",async()=>{let s=o.value.trim()||o.placeholder.replace(/^e\.g\. /,""),l=await W(()=>P.deviceCreate(n.id,s,a));l&&(de(),K(`${s} added`,"success",3e3),e.refresh(),await Bo(n.id,l.id,e))},"positive")]),setTimeout(()=>o.focus(),50)}var Ge=1080,zt=1512,Oe=96,li="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif",di="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",At=n=>n.replace(/[&<>"']/g,e=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[e]);function ci(n,e,o){let a=new URL(o),r=a.pathname.slice(1),i=Math.min(92,Math.floor((Ge-2*Oe)/(.58*(4+n.name.length)))),s=Ge-2*Oe,l=392,c=40,d=ft(o,2).replace("`${k}`;return``+p(Oe+82,Oe+42,36,"#a3a3a3",At(e))+p(Oe,276,i,"#ffffff",`Hi, ${At(n.name)}`,'font-weight="600"')+p(Oe,340,40,"#8a8a8a",`Scan to connect to ${At(e)}`)+``+d+`${At(r)}`+p(Ge/2,l+s+156,34,"#737373",At(a.host),'text-anchor="middle"')+""}async function pi(n){let e=new Image;e.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n)}`,await e.decode();let o=document.createElement("canvas");return o.width=Ge,o.height=zt,o.getContext("2d").drawImage(e,0,0,Ge,zt),new Promise((a,r)=>o.toBlob(i=>i?a(i):r(new Error("Could not draw the card")),"image/png"))}async function jo(n){let e=await W(()=>P.personLinks(n));return e?e.link?{link:e.link,links:e.links??[]}:(K("The personal portal is off. Turn it on in Settings.","warning"),null):null}async function an(n){let e=await jo(n);e&&await ue(e.link,"Personal link copied")}async function Ht(n,e,o={}){let a=n.link,r=n.links;if(a===void 0){let g=await jo(n.id);if(!g)return;a=g.link,r=g.links}if(!a){K("The personal portal is off. Turn it on in Settings.","warning");return}let i=a,s=await W(()=>pi(ci(n,e,i)));if(!s)return;let l=new File([s],`${n.id}-invite.png`,{type:"image/png"}),c=URL.createObjectURL(s),d=navigator,p=!!d.canShare?.({files:[l]}),u=()=>{URL.revokeObjectURL(c),de()},w=p?D([v("link")," Share card"],async()=>{try{await d.share({files:[l],title:`Invite ${n.name}`})}catch{}},"positive"):D([v("download")," Download card"],()=>Ee(l.name,s),"positive");ae(o.title??`Invite ${n.name}`,t("div",{class:"dl-invite"},[t("img",{src:c,alt:`Invite card for ${n.name}`}),t("div",{class:"dl-invite-side"},[t("p",{class:"dl-muted"},o.lead??`Send ${n.name} the card or the link. They open it, add their devices and connect — no account needed.`),t("button",{type:"button",class:"dl-invite-link",title:"Copy link",click:()=>ue(i,"Personal link copied")},[t("span",{},i.replace(/^https:\/\//,"")),v("copy")]),...(r??[]).filter(g=>g!==i).map(g=>t("button",{type:"button",class:"dl-invite-link alt",title:"Copy this link",click:()=>ue(g,"Link copied")},[t("span",{},g.replace(/^https?:\/\//,"")),t("span",{class:`dl-pill ${g.startsWith("http:")?"warn":""}`},g.startsWith("http:")?"HTTP":"Also"),v("copy")])),t("ol",{class:"dl-invite-steps"},[t("li",{},["Install ",t("b",{},"AmneziaVPN")," on the device"]),t("li",{},"Open the link or scan the code"),t("li",{},"Add the device and connect")]),t("div",{class:"dl-invite-actions"},[w,D([v("copy")," Copy link"],()=>ue(i,"Personal link copied"))])])]),[t("button",{class:"cbi-button cbi-button-neutral",click:u},"Done")],"wide")}function Nt(n,e){let o=n.servers.find(c=>c.id===e)??n.servers[0],a=n.people.filter(c=>c.server===o.id),r=new Set(a.map(c=>c.id)),i=a.flatMap(c=>c.devices),s=c=>a.reduce((d,p)=>{let u=c(p);return[d[0]+u[0],d[1]+u[1]]},[0,0]),l=o.series?.[o.series.length-1];return{...n,servers:[o],people:a,series:o.series??n.series,events:n.events.filter(c=>c.person?r.has(c.person):!0),geo:{...n.geo,points:n.geo.points.filter(c=>r.has(c.person))},totals:{people:a.length,devices:i.length,online:i.filter(c=>c.online).length,active:a.filter(c=>c.state==="active").length,today:l?[l.rx,l.tx]:[0,0],month:s(c=>c.month)}}}var Bn=class{constructor(){this.n=0;this.shown=0}next(){return++this.n}take(e){return e{let c=e.next(),d=await n.fetch(l).catch(()=>null);return d==null||!e.take(c)?null:(n.apply(d,s),d)},a=(s=!1)=>o(s,!1),r=()=>n.active?.()??!0?o(!0,!1):Promise.resolve(null);poll.add(r,n.every);let i=n.live?Xt(()=>void((n.active?.()??!0)&&o(!0,!0))):null;return{refresh:a,claim:()=>e.claim(),stop:()=>{poll.remove(r),i?.()}}}function yt(n){let e=document.activeElement;return!!n&&!!e&&e!==document.body&&n.contains(e)}function Le(n,e,o=!1){return o&&yt(n)?!1:(dom.content(n,e),!0)}function Uo(n,e){let o=n,r=t("div",{class:"dl-choices"},[{v:"internet",ic:"globe",text:"Browse the internet through your router. No access to devices at home."},{v:"lan",ic:"home",text:"Reach devices at home (NAS, printer, cameras). Internet stays on their own connection."},{v:"both",ic:"shield",text:"Home devices and the internet, all through your router."}].map(i=>t("button",{type:"button",class:`dl-choice${i.v===o?" selected":""}`,"data-v":i.v,click:()=>{o=i.v,r.querySelectorAll(".dl-choice").forEach(s=>s.classList.toggle("selected",s.dataset.v===i.v)),e?.(i.v)}},[t("span",{class:"dl-choice-title"},[v(i.ic),ot[i.v]]),t("span",{class:"dl-choice-text"},i.text)])));return{el:r,get:()=>o}}function mi(n){let e=n.devices.length,o=Math.max(1,n.device_limit,e),a=Math.min(160,o*22+(o-1)*3);return t("div",{class:"dl-slotbar",title:`${e} of ${n.device_limit} devices`},[t("span",{class:"dl-slotbar-segs",style:`width: ${a}px`},Array.from({length:o},(r,i)=>t("i",{class:i>=n.device_limit?"over":in.state==="server_off"?n.paused:!["active","quota","expired"].includes(n.state),On=n=>n.state==="server_off"?n.paused:n.state!=="active",Go=n=>On(n)?n.state==="server_off"?"paused":n.state:null;function hi(n,e){let o=nt(n.expires,e);return n.state==="quota"||n.state==="expired"||Fe(n,o)||!!n.quota_limit&&n.quota_used>=n.quota_limit*.9}function Fo(n,e){return ct(n&&Cn(n,e)>=0?n:e,1)}var qo=n=>n.people.map(e=>e.id).sort().join(" "),Ko=!1,st=class{constructor(){this.list=t("div",{class:"dl-plist",role:"list"});this.filter=["all","online","attention","paused"].find(e=>e===new URLSearchParams(location.search).get("filter"))??"all";this.sort="seen";this.noFooter=!0;this.serverId=null;this.el=null}async load(){return P.status(30)}scope(e){return this.serverId?Nt(e,this.serverId):e}embed(e,o){return this.serverId=o,this.render(e)}person(e){return this.st.people.find(o=>o.id===e)}get today(){return Re(this.st.series)}deviceOpts(e){return{refresh:()=>this.refresh(),geo:this.st.geo,now:this.st.now,today:this.today,core:bt(this.st.servers,e.server)}}take(e,o){let a=this.scope(e),r=qo(a)!==qo(this.st);this.st=a,r?this.rebuild():(this.paintCards(o),this.decorate(o))}async update(){await this.poller?.refresh()}async refresh(){this.poller?.claim();let e=await P.status(30).catch(()=>null);e&&(this.st=this.scope(e),this.rebuild())}rebuild(){let e=new Map;for(let a of Array.from(this.list.children))a.dataset.sid&&e.set(a.dataset.sid,a);let o=this.st.people.map(a=>{let r=e.get(a.id)??t("div",{class:"dl-card",role:"listitem","data-sid":a.id});return this.renderCard(r,a.id)});dom.content(this.list,o.length?o:t("div",{class:"dl-plist-none"},this.st.servers.length?"No people yet. Add someone and send them their personal link.":"Set up the server first, then add people.")),this.decorate()}paintCards(e=!1){for(let o of this.st.people){let a=this.card(o.id);a&&!(e&&yt(a))&&this.renderCard(a,o.id)}}card(e){return this.list.querySelector(`[data-sid="${CSS.escape(e)}"]`)}render(e){let o=this.scope(e);this.st=o;let a=this,r=t("select",{class:"dl-select","aria-label":"Sort",change:s=>{a.sort=s.target.value,a.decorate()}},[t("option",{value:"seen"},"Last seen"),t("option",{value:"name"},"Name"),t("option",{value:"usage"},"Usage")]),i=t("div",{class:"dl-root"},[a.serverId?"":t("div",{class:"dl-pagehead"},[t("div",{class:"dl-stack"},[t("h2",{class:"dl-h1"},"People"),t("span",{class:"dl-muted dl-people-count"},this.countText())]),o.servers.length?D([v("plus")," Add person"],()=>a.openCreate(),"add"):""]),o.servers.length?"":t("div",{class:"alert-message warning"},["No server yet. ",t("a",{href:L.url("admin/network/dawnline/server")},"Run the setup wizard")," before adding people."]),t("div",{class:"dl-toolbar"},[t("div",{class:"dl-seg dl-people-tabs",role:"tablist"}),t("div",{class:"dl-toolbar-end"},[r,a.serverId?D([v("plus")," Add person"],()=>a.openCreate(),"add"):""])]),this.list]);return this.el=i,this.rebuild(),this.poller??(this.poller=Ve({fetch:()=>P.status(30),every:30,live:!0,active:()=>!!a.el?.isConnected,apply:(s,l)=>a.take(s,l)})),!Ko&&new URLSearchParams(location.search).get("add")&&(Ko=!0,setTimeout(()=>a.openCreate(),100)),Promise.resolve(i)}countText(){let e=this.st.totals;return`${e.people} ${e.people===1?"person":"people"} · ${e.devices} device${e.devices===1?"":"s"} · ${e.online} online`}decorate(e=!1){let o=this.el?.querySelector(".dl-people-count");o&&(o.textContent=this.countText());let a=this.st.people,r=this.today,i=g=>hi(g,r),s={all:a.length,online:a.filter(g=>g.online>0).length,attention:a.filter(i).length,paused:a.filter(g=>Wo(g)).length},l=this.el?.querySelector(".dl-people-tabs");if(l&&!(e&&yt(l))){let g={all:"All",online:"Online",attention:"Needs attention",paused:"Paused"};dom.content(l,Object.keys(g).map(m=>t("button",{type:"button",role:"tab",class:m===this.filter?"on":"",click:()=>{this.filter=m,this.decorate()}},[g[m],t("b",{class:m==="attention"&&s[m]?"warn":""},String(s[m]))])))}let c=g=>!(this.filter==="online"&&!g.online||this.filter==="attention"&&!i(g)||this.filter==="paused"&&!Wo(g)),d=g=>Go(g)==="paused"?2:On(g)?1:0,p=[...a].sort((g,m)=>d(g)-d(m)||(this.sort==="name"?g.name.localeCompare(m.name):this.sort==="usage"?m.month[0]+m.month[1]-(g.month[0]+g.month[1]):m.online-g.online||m.last_seen-g.last_seen)),u=0;for(let g of p){let m=this.card(g.id);if(!m)continue;this.list.appendChild(m),m.classList.toggle("dl-off",On(g));let k=c(g);m.classList.toggle("dl-filtered",!k),k&&u++}let w=this.el?.querySelector(".dl-people-none")??null;a.length&&!u?(w??(w=t("div",{class:"dl-empty dl-people-none"},t("p",{},"No one here right now."))),w.previousElementSibling!==this.list&&this.list.after(w)):w?.remove()}async quick(e,o,a){await W(()=>P.personUpdate(e.id,o),a)&&await this.update()}renderCard(e,o){let a=this.person(o);if(!a)return dom.content(e,t("em",{},"This person was just removed.")),e;let r=this.today,i=nt(a.expires,r),s=Math.max(0,a.device_limit-a.devices.length),l=a.has_link??this.st.settings.portal_enabled,c=[],d=Go(a);if(a.expires&&d!=="expired"){let m=Fe(a,i),k=i!=null&&i<0;c.push(t("span",{class:`dl-pill-ic${k?" bad":m?" warn":""}`,title:`Access ends ${Te(a.expires)}`},[v("calendar"),k?`ended ${Te(a.expires)}`:m?Wt(i):`until ${Te(a.expires)}`]))}a.hours&&d!=="hours"&&c.push(t("span",{class:"dl-pill-ic",title:"Allowed hours"},[v("clock"),a.hours.replace("-","–")]));let p=Ft(a.devices).map(m=>t("button",{type:"button",class:`dl-chip${m.disabled?" disabled":""}${m.online?" live":""}`,title:`${je[m.kind]} · ${m.address}${m.online?` · online from ${m.endpoint}`:m.handshake?` · seen ${ie(m.handshake,this.st.now)}`:""}`,click:k=>{k.preventDefault(),Be(a,m,this.deviceOpts(a))}},[v(m.kind),t("span",{class:"dl-chip-name"},m.name),!m.handshake&&!m.disabled?t("span",{class:"dl-chip-tag"},"not set up"):""]));p.push(t("button",{type:"button",class:"dl-chip add","aria-label":"Add device",title:s>0?"Add device":"Add device · over the limit, admins can still add",click:m=>{m.preventDefault(),it(a,this.deviceOpts(a))}},v("plus")));let u=[];a.expires&&Fe(a,i)&&d!=="expired"&&u.push(t("button",{type:"button",class:"dl-fix",click:()=>this.quick(a,{expires:Fo(a.expires,r)},"Extended by 1 month")},"Extend 1 month"));let w=$e("more","More",m=>we(m.currentTarget,[{label:"Open",icon:v("open"),run:()=>{location.href=ke(a.id)}},l?{label:"Invite card",icon:v("qr"),run:()=>Ht(a,this.st.servers.find(k=>k.id===a.server)?.name??"Home")}:null,s>0?{label:"Add device",icon:v("plus"),run:()=>it(a,this.deviceOpts(a))}:null,null,{label:a.paused?"Resume":"Pause",icon:v(a.paused?"play":"pause"),warn:!a.paused,run:()=>this.togglePause(a)},{label:"Delete",icon:v("trash"),danger:!0,run:()=>this.remove(a.id)}].filter((k,H,B)=>k||H>0&&B[H-1])),"neutral","dl-icon-only"),g=t("div",{class:"dl-pcard-actions"},[l?$e("link","Copy link",()=>an(a.id),"neutral","dl-icon-only"):"",w]);return dom.content(e,t("div",{class:"dl-pcard"},[t("div",{class:"dl-pcard-main"},[t("div",{class:"dl-pcard-top"},[t("span",{class:`dl-avatar${a.online?" online":""}`},Ce(a.name)),t("div",{class:"dl-pcard-who"},[t("div",{class:"dl-card-head"},[t("a",{class:"dl-card-name",href:ke(a.id)},a.name),uo(a),...c]),mi(a)])]),t("div",{class:"dl-chips"},p),u.length?t("div",{class:"dl-fixes"},u):""]),this.usageSide(a,g),d?this.stopStrip(a,d):""])),e}stopStrip(e,o){let a=this.today,r=ct(`${a.slice(0,8)}01`,1),i=()=>this.quick(e,{bonus_gb:String((e.bonus_gb||0)+10)},"+10 GB this month"),s={paused:["pause","warn","Paused","Devices can’t connect until you resume",["play","Resume",()=>this.togglePause(e)]],quota:e.quota_period==="month"?["chart","bad","Data limit reached",`Paused until it resets on ${Te(r)}`,["plus","+10 GB this month",i]]:["chart","bad","Data limit reached","Paused until the limit is raised",["edit","Change limit",()=>location.href=ke(e.id)]],expired:["calendar","bad",`Access ended ${Te(e.expires)}`,"Devices can’t connect",["calendar","Extend 1 month",()=>this.quick(e,{expires:Fo(e.expires,a)},"Extended by 1 month")]],hours:["clock","warn","Outside allowed hours",`Access ${e.hours.replace("-","–")} (router time)`,null],no_server:["alert","warn","No server","Choose a server on their page",null]},[l,c,d,p,u]=s[o];return t("div",{class:`dl-pstrip ${c}`},[t("span",{class:`dl-need-ic ${c}`},v(l)),t("span",{class:"dl-pstrip-text"},[t("b",{},d),t("span",{class:"dl-faint"},p)]),u?D([v(u[0]),` ${u[1]}`],u[2]):""])}usageSide(e,o){let a=e.quota_used||e.month[0]+e.month[1],r=e.quota_limit?Math.min(100,e.quota_used/e.quota_limit*100):0,i=e.devices.reduce((p,u)=>p+(u.spark[u.spark.length-1]??0),0),s=e.rate?.[e.rate.length-1],l=e.online&&s&&this.st.now-s[0]<180,c=t("div",{class:`dl-usebar${r>=100?" bad":r>=90?" warn":""}`});if(e.quota_limit){let p=t("i",{class:"fill"});p.style.width=`${r}%`,c.appendChild(p),me(c,()=>[t("div",{class:"dl-tip-title"},`${r.toFixed(1)}% used`),t("div",{class:"dl-muted"},`${te(e.quota_used)} of ${te(e.quota_limit)} · ${te(Math.max(0,e.quota_limit-e.quota_used))} left`),t("div",{class:"dl-faint"},e.quota_period==="total"?"In total":`This month${e.bonus_gb?` · includes +${e.bonus_gb} GB extra`:""}`)])}else{let p=e.devices.map(u=>({d:u,v:u.month[0]+u.month[1]})).filter(u=>u.v>0).sort((u,w)=>w.v-u.v);p.forEach((u,w)=>{let g=t("i",{class:`c${Math.min(w,4)}`});g.style.flexGrow=String(u.v),c.appendChild(g)}),p.length&&me(c,()=>[t("div",{class:"dl-tip-title"},"This month by device"),...p.map((u,w)=>t("div",{class:"dl-tip-row"},[t("span",{class:`dl-swatch c${Math.min(w,4)}`}),t("span",{},u.d.name),t("b",{},te(u.v))]))])}let d=e.quota_limit?`${te(Math.max(0,e.quota_limit-e.quota_used))} left`:"no limit";return t("div",{class:"dl-pside"},[t("div",{class:"dl-pside-top"},[l?t("span",{class:"dl-pside-state live"},"Online"):t("span",{class:"dl-pside-state"},e.online?"Online":e.last_seen?"Offline":"Never connected"),o]),t("div",{class:"dl-use-num"},[t("b",{class:a?"":"dl-faint"},te(a)),t("span",{class:"dl-faint"},e.quota_limit?`of ${te(e.quota_limit)}`:e.quota_period==="total"&&e.quota_gb?"in total":"this month")]),c,l?t("div",{class:"dl-use-live",title:"Right now"},[`↓ ${ze(s[2])}`,t("span",{class:"dl-faint"},`↑ ${ze(s[1])}`)]):t("div",{class:"dl-faint dl-pside-foot"},i?`today ${te(i)} · ${d}`:d)])}async togglePause(e){await W(()=>P.personPause(e.id,!e.paused),e.paused?`${e.name} resumed`:`${e.name} paused`)&&await this.refresh()}async remove(e){let o=this.person(e);await re(`Remove ${o?.name??e}?`,`All ${o?.devices.length??0} devices are disconnected immediately and the personal link stops working. Usage history is kept in backups.`,"Remove",!0)&&await W(()=>P.personDelete(e),"Person removed")&&await this.refresh()}openCreate(){let e=this.st;if(!e.servers.length){K("Set up the server first.","warning");return}let o=t("input",{type:"text",class:"cbi-input-text",placeholder:"e.g. Myata",maxlength:48}),a=Uo("internet"),r=t("input",{type:"number",class:"cbi-input-text",min:1,max:32,value:e.settings.default_device_limit}),i=t("input",{type:"date",class:"cbi-input-text"}),s=t("input",{type:"number",class:"cbi-input-text",min:0,step:"any",placeholder:"Unlimited"}),l=(u,w)=>t("button",{type:"button",class:"cbi-button cbi-button-neutral",click:()=>{i.value=w?ct(Re(e.series),w):""}},u),c=e.servers[0],d=!this.serverId&&e.servers.length>1?t("select",{class:"cbi-input-select"},e.servers.map(u=>t("option",{value:u.id},u.name))):null,p=(u,w,g)=>t("div",{class:"cbi-value"},[t("label",{class:"cbi-value-title"},u),t("div",{class:"cbi-value-field"},[w,g?t("div",{class:"cbi-value-description"},g):""])]);ae("Add person",[p("Name",o),d?p("Server",d):"",t("div",{class:"cbi-value dl-block"},[t("label",{class:"cbi-value-title"},"Access"),t("div",{class:"cbi-value-field"},a.el)]),p("Devices",r,"How many devices they can add themselves."),p("End date",t("div",{class:"dl-actions"},[i,l("1 month",1),l("3 months",3),l("1 year",12),l("None",0)]),"Optional."),p("Monthly data (GB)",s,"Optional. They are paused when it runs out and resumed next month.")],[le()," ",D("Create and copy link",async()=>{let u=await W(()=>P.personCreate(o.value.trim(),"",d?.value??c.id,a.get(),String(Number(r.value)||e.settings.default_device_limit),i.value,s.value.trim(),"month"));u&&(u.link&&await ue(u.link,"Personal link copied"),this.showCreated(u.id,o.value.trim(),u.link,e.servers.find(w=>w.id===(d?.value??c.id))?.name??c.name),await this.refresh())},"positive")]),setTimeout(()=>o.focus(),50)}showCreated(e,o,a,r){if(a){Ht({id:e,name:o,link:a},r,{title:`${o} is ready`,lead:`Send ${o} the card or the link. They open it, add their devices and connect — no account needed.`});return}ae(`${o} is ready`,[t("p",{},"Created. Turn on the personal portal in Settings to get a link, or add devices for them here.")],[t("button",{class:"cbi-button cbi-button-positive",click:de},"Done")])}};function jn(n){let e=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\/(\d{1,2})$/.exec(n.trim());if(!e)return null;let[o,a,r,i]=e.slice(1,5).map(Number),s=Number(e[5]);if([o,a,r,i].some(d=>d>255)||s<8||s>30)return null;let l=o*2**24+a*2**16+r*2**8+i,c=2**(32-s);return{net:l-l%c,size:c}}var fi=(n,e)=>n.netjn(n));function rn(n){return n.split("/")[0].split(".").slice(0,3).join(".")}function Un(n){return`${n.trim()}.0/24`}function Jo(n,e,o){let a=n.trim(),r=/^\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(a)?jn(Un(a)):null;if(!r)return{text:"Three numbers, like 10.77.0.",bad:!0};if(!gi.some(s=>r.net>=s.net&&r.net+r.size<=s.net+s.size))return{text:"Use a private range: 10.x.x, 172.16–31.x or 192.168.x.",bad:!0};let i=e.find(s=>{let l=jn(s.cidr);return l!=null&&fi(r,l)});if(i){let s=i.cidr.endsWith("/24")?`${rn(i.cidr)}.x`:i.cidr,l=o&&o!==a?` Try ${o}.`:"";return{text:`${i.name} already uses ${s}.${l}`,bad:!0}}return{text:`Devices get ${a}.2 – ${a}.254, the router ${a}.1.`,bad:!1}}var Vo=(n,e)=>e.find(o=>o.from<=n&&n<=o.to)?.who??null,vi=n=>Number.isInteger(n)&&n>=1&&n<=65535;function Wn(n,e,o){if(!vi(n))return{text:"Use a port from 1 to 65535.",bad:!0};let a=Vo(n,e);return a?{text:`Used by ${a}. Choose another port.`,bad:!0}:{text:o,bad:!1}}function Rt(n,e,o){let a=o?`HTTPS here, plain HTTP for links on IP addresses on ${n+1}.`:"HTTPS on this port, opened on WAN.",r=Wn(n,e,a);if(r.bad||!o)return r;if(n===65535)return{text:"Links on IP addresses also need the next port: choose a lower one.",bad:!0};let i=Vo(n+1,e);return i?{text:`Links on IP addresses also need ${n+1}, used by ${i}. Choose another port.`,bad:!0}:r}var sn=["#3a83f7","#a78bfa","#f472b6","#f59e0b","#10b981","#22d3ee","#ef4444","#84cc16"],Gn=n=>t("i",{class:"dl-circle-dot",style:`background:${sn[n?.color??0]??sn[0]}`}),Ye=n=>n.access==="both"||n.access==="lan"&&!n.services?.length;function Yo(n,e,o){let a=se(n?.name??e.name??"",{placeholder:"NAS"}),r=se(n?.address??e.address??"",{placeholder:"192.168.1.10",class:"cbi-input-text dl-mono"}),i=se((n?.ports??e.ports??[]).join(", "),{placeholder:"All ports, or e.g. 445, 5000",class:"cbi-input-text dl-mono"}),s=(l,c)=>t("div",{class:"cbi-value"},[t("label",{class:"cbi-value-title"},l),t("div",{class:"cbi-value-field"},c)]);ae(n?`Edit ${n.name}`:"Add service",[s("Name",a),s("Address",r),s("Ports",i)],[le()," ",D("Save",async()=>{let l=i.value.split(/[ ,]+/).filter(Boolean);await W(()=>P.serviceSet(n?.id??"",a.value,r.value,l),"Saved")&&(de(),o())},"positive")])}var bi={_smb:"SMB",_afpovertcp:"AFP",_http:"Web",_https:"Web",_ssh:"SSH",_sftp:"SFTP","_sftp-ssh":"SFTP",_ipp:"Printer",_ipps:"Printer",_printer:"Printer","_pdl-datastream":"Printer",_airplay:"AirPlay",_raop:"AirPlay",_rfb:"Screen sharing",_googlecast:"Cast",_hap:"HomeKit",_rdp:"Remote desktop",_ftp:"FTP"},xi=[["Web",["80","443"]],["SMB",["445"]],["SSH",["22"]]];function wi(n){let e=new Map;for(let o of n.services){let a=bi[o.type.split(".")[0]];!a||!o.port||(e.get(a)??e.set(a,new Set).get(a)).add(String(o.port))}return e.size?[...e].map(([o,a])=>[o,[...a].sort((r,i)=>+r-+i)]):xi}function Zo(n,e,o){let a=n,r=null,i=!1,s=null,l=new Set,c=t("div",{class:"dl-list"}),d=t("div",{class:"dl-stack gap8"},t("span",{class:"dl-sub"},"Looking for devices at home…")),p=()=>{let k=a.services;dom.content(c,k.length?k.map(H=>t("div",{class:"dl-row"},[v("home"),t("span",{class:"dl-row-main dl-stack"},[t("b",{},H.name),t("span",{class:"dl-mono dl-faint"},`${H.address}${H.ports.length?` · ports ${H.ports.join(", ")}`:" · all ports"}`)]),D("Edit",()=>Yo(H,{},o)),D([v("trash")],async()=>{await re(`Remove ${H.name}?`,"People limited to this service lose access to it.","Remove",!0)&&await W(()=>P.serviceDelete(H.id),"Removed")&&await o()},"neutral",{title:"Remove","aria-label":`Remove ${H.name}`})])):[t("div",{class:"dl-row dl-muted"},"No services yet: pick ports of a device below.")])};async function u(k,H){if(!l.has(k.address)){l.add(k.address),g();try{let B=a.services.find(y=>y.address===k.address);(H===null?B&&await W(()=>P.serviceDelete(B.id),`${B.name} removed`):await W(()=>P.serviceSet(B?.id??"",B?.name??(k.name||k.address),k.address,H),B?`${B.name} updated`:`${k.name||k.address} added`))&&await o()}finally{l.delete(k.address),g()}}}function w(k){let H=a.services.find(b=>b.address===k.address),B=!!H&&!H.ports.length,E=new Set(H?.ports??[]),y=l.has(k.address),S=(b,x,M)=>We(b,x,M,{disabled:y?"disabled":null,"aria-busy":y?"true":null});return t("div",{class:"dl-row"},[v(k.services.some(b=>b.type.startsWith("_ipp")||b.type.startsWith("_printer"))?"file":"computer"),t("span",{class:"dl-row-main dl-stack"},[t("b",{},k.name||k.address),t("span",{class:"dl-mono dl-faint"},k.address)]),t("div",{class:"dl-chips-row dl-host-ports"},[S("All ports",B,()=>u(k,B?null:[])),...wi(k).map(([b,x])=>{let M=!B&&x.every(h=>E.has(h));return S(`${b} ${x.join(", ")}`,M,()=>{let h=new Set(B?[]:E);for(let f of x)M?h.delete(f):h.add(f);u(k,h.size?[...h]:null)})})])])}function g(){if(i)return dom.content(d,t("span",{class:"dl-sub"},"Couldn't read the devices at home."));if(!r)return;let k=r;if(!k.hosts.length)return dom.content(d,t("span",{class:"dl-sub"},"No devices found in the home network right now."));let H=t("details",{class:"dl-params",open:s??!a.services.length?"":null},[t("summary",{},[v("chevron"),t("span",{},"Add from devices at home"),t("span",{class:"dl-pcount"},String(k.hosts.length))]),t("div",{class:"dl-params-body"},[t("span",{class:"dl-sub"},k.mdns?"Ports they announce over Bonjour. Pick what to open, or all ports.":"Devices that got an address from this router. Pick the ports to open, or all ports."),t("div",{class:"dl-list"},k.hosts.map(w))])]);H.addEventListener("toggle",()=>s=H.open),dom.content(d,H)}return P.homeHosts(e).then(k=>{r=k,g()}).catch(()=>{i=!0,g()}),p(),{el:t("div",{class:"dl-stack gap8"},[t("div",{class:"dl-iflead"},[t("div",{class:"dl-iflead-row"},[t("b",{},"Home services"),D([v("plus")," Add service"],()=>Yo(null,{},o))]),t("span",{class:"dl-sub"},"Home-only people can be limited to these instead of whole networks (chosen on their page). Shared by all servers.")]),c,d]),update(k){a=k,p(),g()}}}function ln(n,e,o,a){let r=new Set(n.circles.filter(g=>g.server===e).map(g=>g.color)),i=o?.color??sn.findIndex((g,m)=>!r.has(m));i<0&&(i=0);let s=se(o?.name??"",{placeholder:"Family"}),l=n.people.filter(g=>g.server===e).sort((g,m)=>g.name.localeCompare(m.name)),c=new Set(l.filter(g=>o&&g.circle===o.id).map(g=>g.id)),d=t("div",{class:"dl-swatches",role:"radiogroup","aria-label":"Colour"}),p=()=>dom.content(d,sn.map((g,m)=>t("button",{type:"button",role:"radio",class:`dl-swatch${m===i?" on":""}`,style:`--sw:${g}`,"aria-checked":m===i?"true":"false","aria-label":`Colour ${m+1}`,click:()=>{i=m,p()}})));p();let u=t("div",{class:"dl-chips-row"},l.map(g=>{let m=g.circle&&g.circle!==o?.id?n.circles.find(k=>k.id===g.circle):void 0;return t("button",{type:"button",class:`dl-chipbtn${c.has(g.id)?" on":""}`,title:Ye(g)?m?`Now in ${m.name}`:"":`${g.name} has no home access: their devices aren't reachable anyway`,click:k=>{c.delete(g.id)||c.add(g.id),k.currentTarget.classList.toggle("on",c.has(g.id))}},[g.name,Ye(g)?m?t("b",{},m.name):"":t("b",{},"internet")])})),w=(g,m)=>t("div",{class:"cbi-value"},[t("label",{class:"cbi-value-title"},g),t("div",{class:"cbi-value-field"},m)]);ae(o?`Edit ${o.name}`:"New circle",[w("Name",s),w("Colour",d),w("People",u),t("p",{class:"dl-sub"},"Devices of people in one circle reach each other. A person is in one circle at a time.")],[o?D("Delete",async()=>{await W(()=>P.circleDelete(o.id),`${o.name} deleted`)&&(de(),a())},"negative"):"",t("span",{class:"dl-spacer"}),le()," ",D("Save",async()=>{await W(()=>P.circleSet(o?.id??"",e,s.value,i,[...c]),"Saved")&&(de(),a())},"positive")],"dl-circle-modal")}function Qo(n,e,o){let a=n.circles.filter(r=>r.server===e);return t("div",{class:"dl-chips-row dl-circles"},[...a.map(r=>{let i=n.people.filter(s=>s.circle===r.id).map(s=>s.name);return t("button",{type:"button",class:"dl-chip",title:`Edit ${r.name}`,click:()=>ln(n,e,r,o)},[Gn(r),t("b",{},r.name),t("span",{class:"dl-faint"},i.length?i.join(", "):"nobody yet")])}),t("button",{type:"button",class:"dl-chip add",title:"New circle","aria-label":"New circle",click:()=>ln(n,e,null,o)},v("plus"))])}function Fn(n,e){let o=n.people.filter(p=>p.server===e.id),a=(p="")=>t("span",{class:"dl-yes"},[v("check"),p]),r=()=>t("span",{class:"dl-faint"},"—"),i=p=>{let u=new Set(p.map(w=>w.access==="lan"&&w.services?.length?"services":w.home_nets?.length?"some":"all"));return u.size||u.add("all"),a([...u].map(w=>({all:"all networks",some:"their networks",services:"services"})[w]).join(" / "))},s=()=>e.mesh==="off"?r():e.mesh==="circles"?a("circle"):a(),l=e.lan_like?"like home":"direct",c=(p,u,w)=>t("tr",{},[t("td",{},[t("b",{},p),t("div",{class:"dl-sub"},`${u.length} ${u.length===1?"person":"people"}`)]),...w.map(g=>t("td",{},g))]),d=p=>o.filter(u=>u.access===p);return t("section",{class:"dl-setsec"},[t("div",{class:"dl-setsec-body"},[t("div",{class:"dl-panel-head"},[t("h3",{},"Who reaches what"),t("span",{class:"dl-spacer"}),t("span",{class:"dl-sub"},"From the rules on this server")]),t("div",{class:"dl-reach-wrap"},t("table",{class:"dl-table dl-reach"},[t("tr",{},["","Internet","Home","This router","Each other"].map(p=>t("th",{},p))),c("Internet",d("internet"),[a(l),r(),t("span",{class:"dl-faint"},"DNS"),r()]),c("Home",d("lan"),[t("span",{class:"dl-faint"},"their own"),i(d("lan")),a(),s()]),c("Both",d("both"),[a(l),i(d("both")),a(),s()])])),t("p",{class:"dl-sub"},"Home devices reach the devices of people with home access, on the networks those people reach. Paused, ended and over-the-limit people reach nothing.")])])}function Xo(n,e){let o=n.people.filter(d=>d.server===e.id).flatMap(d=>d.devices.map(p=>({id:p.id,label:`${d.name} · ${p.name}`}))).sort((d,p)=>d.label.localeCompare(p.label)),a="@addr",r=(d,p)=>{let u=t("select",{class:"cbi-input-select","aria-label":d},[...o.map(k=>t("option",{value:k.id,selected:k.id===p?"selected":null},k.label)),t("option",{value:a,selected:p===a?"selected":null},"Address")]),w=se("",{placeholder:d,class:"cbi-input-text dl-mono"}),g=t("div",{class:"dl-check-end"},[u,w]),m=()=>w.hidden=u.value!==a;return u.addEventListener("change",m),m(),{el:g,value:()=>u.value===a?w.value.trim():u.value}},i=r("10.0.1.11",o[0]?.id??a),s=r("10.0.1.20:445",a),l=t("div",{class:"dl-stack gap8"}),c=async()=>{let d=await W(()=>P.accessCheck(i.value(),s.value()));if(!d)return;let p=d.steps.findIndex(u=>!u.ok);dom.content(l,[t("div",{class:`dl-verdict ${d.ok?"ok":"bad"}`},[t("b",{},d.ok?"Allowed":"Blocked"),t("span",{class:"dl-sub"},d.ok?"Every step lets it through":`Stops at step ${p+1} of ${d.steps.length}`)]),t("ul",{class:"dl-checks"},d.steps.map(u=>t("li",{},[t("span",{class:`dl-check-icon ${u.ok?"ok":"error"}`},v(u.ok?"check":"x")),t("div",{class:"dl-check-body"},[t("div",{class:"dl-check-title"},u.title),u.detail?t("div",{class:"dl-check-detail"},u.detail):""])])))])};return t("section",{class:"dl-setsec"},[t("div",{class:"dl-setsec-body"},[t("div",{class:"dl-panel-head"},[t("h3",{},"Check access"),t("span",{class:"dl-spacer"}),t("span",{class:"dl-sub"},"Why something does or does not connect")]),t("div",{class:"dl-check-form"},[i.el,t("span",{class:"dl-faint"},"→"),s.el,D("Check",c)]),l])])}var dn={app:"Dawnline",amneziawg:"AmneziaWG",packages:"System packages",pkgs:"System packages"};function Ze(n){return(n.startsWith("check")?n.slice(6)||"all":n).split(/[:@ ]/)[0]}function cn(n){return Ze(n.action==="check"?`check:${n.component??""}`:n.component??"")}function ea(n){return n=Math.max(0,Math.floor(n)),`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function ta(n,e){return!n?.from&&!n?.to?e:n.from&&n.to&&n.from!==n.to?`${n.from} → ${n.to}`:n.to??n.from??e}function na(n,e){let o=n.check?.components??{},a=e==="all"?["app","amneziawg","packages"]:[e],r=[],i;for(let l of a){let c=o[l];if(c){if(c.error)return{tone:"warn",text:c.error};l==="packages"&&c.updates?r.push(`${c.updates} system package${c.updates===1?"":"s"}`):l!=="packages"&&c.update&&c.installed&&c.latest&&(r.push(`${dn[l]} ${c.latest}`),e!=="all"&&(i=c.latest))}}if(r.length)return{tone:"acc",text:`Update available: ${r.join(", ")}`,update:i};let s=a.length===1?o[a[0]]:null;return s?.status==="dev"?{tone:"acc",text:`Installed version is newer than the release (${s.latest})`}:s?.note?{tone:"warn",text:s.note}:{tone:"ok",text:a.length>1?"Everything is up to date":"Latest version is installed"}}function oa(n,e,o,a){return e?n.id===e:o&&n.id===o?!1:n.state==="running"||a>0&&n.started>=a}var aa=n=>new Promise(e=>setTimeout(e,n));async function It(n,e,o){let a=o?cn(o):Ze(n),r=o?o.action==="check":n.startsWith("check"),i=Date.now(),s=t("b",{},dn[a]??(a==="all"?"All components":"Dawnline")),l=t("span",{class:"dl-pill dl-mono"},e.version??""),c=t("span",{class:"dl-pill info",hidden:!0}),d=t("span",{},"0:00"),p=t("pre",{class:"dl-log"},"Operation started. Waiting for log output…"),u=t("div",{}),w=t("div",{class:"dl-op-actions"}),g=[],m=h=>dom.content(w,h),k=(h=!1)=>le("Close",h);ae(e.title,t("div",{class:"dl-op"},[t("div",{class:"dl-op-head"},[s,e.version?l:"",c,t("span",{class:"dl-spacer"}),t("span",{class:"dl-faint dl-op-timer"},[v("clock"),d])]),t("div",{class:"dl-op-loghead"},[t("b",{},"Operation log"),$e("copy","Copy log",()=>ue(g.join(` +`),"Log copied"))]),p,u]),[w],"wide"),m([t("button",{class:"cbi-button cbi-button-neutral spinning",type:"button",disabled:"disabled"},r?"Checking…":"Working…")]);let H=o??null,B=o?.id,E,y=0,S=h=>{B!==h.id&&(B=h.id,e.onJob?.(h))};if(o)e.onJob?.(o);else try{let h=await P.updatesStatus().catch(()=>null);E=h?.job?.id,y=h?.now??0;let f=await P.updatesRun(n);f.job&&f.job.state==="running"&&f.job.id!==E&&(H=f.job,S(f.job))}catch(h){return g=[ve(h)],p.textContent=g[0],dom.content(u,t("div",{class:"dl-comp-status warn"},[v("alert"),t("span",{},ve(h))])),m([k(!0)]),K(ve(h),"error"),null}let b=null,x=0;for(;;){if(await aa(1e3),b=await P.updatesStatus().catch(()=>null),!b){if(++x>60)break;continue}x=0;let h=b.job;if(!h||!oa(h,B,E,y)){if(Date.now()-i>15e3)break;continue}if(S(h),H=h,h.log.length){g=h.log;let f=p.scrollTop+p.clientHeight>=p.scrollHeight-8;p.textContent=g.join(` +`),f&&(p.scrollTop=p.scrollHeight)}if(l.textContent=ta(h,e.version??""),!l.isConnected&&l.textContent&&s.after(l),d.textContent=ea((h.finished??b.now)-h.started),h.state==="running"){c.hidden=!h.phase,c.textContent=h.phase;continue}break}if(p.scrollTop=p.scrollHeight,c.hidden=!1,!H||H.state==="running")return c.className="dl-pill warn",c.textContent="No answer",dom.content(u,t("div",{class:"dl-comp-status warn"},[v("alert"),t("span",{},"The router stopped answering. The job may still finish: reopen Components in a minute.")])),m([k()]),e.onDone?.(b),H;if(H.state==="failed")return c.className="dl-pill bad",c.textContent="Failed",dom.content(u,t("div",{class:"dl-comp-status bad"},[v("x"),t("span",{},[t("b",{},H.error??"Operation failed"),r?"":". Nothing else was changed."])])),m([D("Copy log",()=>ue(g.join(` +`),"Log copied")),k(!0)]),K(`${dn[a]??"Update"}: ${H.error??"failed"}`,"error"),e.onDone?.(b),H;if(c.className="dl-pill ok",c.textContent="Finished",r&&b){let h=na(b,a);if(dom.content(u,t("div",{class:`dl-comp-status ${h.tone}`},[v(h.tone==="ok"?"check":h.tone==="warn"?"alert":"download"),t("span",{},h.text)])),K(h.text,h.tone==="warn"?"warning":"success"),e.onDone?.(b),h.update&&e.onUpdate){let f=b;m([k(),D(`Update to ${h.update}`,()=>e.onUpdate(f),"positive")])}else m([k()]),h.tone==="ok"&&setTimeout(()=>u.isConnected&&de(),1200);return H}if(a==="app"&&H.to){let h=H.to,f=t("span",{},"Waiting for the router to restart its services…");dom.content(u,t("div",{class:"dl-comp-status ok"},[v("check"),t("span",{},[t("b",{},`Dawnline ${h} is installed. `),f])]));let R=()=>{ui.menu?.flushCache(),location.reload()};m([k(),D("Reload now",R,"positive")]),K(`Dawnline updated to ${h}`,"success",6e3);for(let C=1;C<=30;C++)if(f.textContent=`Waiting for the router to restart its services (${C} of 30)…`,await aa(1500),(await P.updatesStatus().catch(()=>null))?.version===h)return f.textContent="Services are back. Reloading…",setTimeout(R,800),H;return f.textContent="Services restarted. Reload the page to use the new version.",H}let M=a==="pkgs"?`Updated ${[...H.result?.pkgs?.updated??[],...H.result?.pkgs?.installed??[]].join(", ")||"system packages"}`:a==="amneziawg"?`AmneziaWG${H.to?` ${H.to}`:""} is installed`:"Operation completed";return dom.content(u,t("div",{class:"dl-comp-status ok"},[v("check"),t("span",{},M)])),m([k()]),K(M,"success"),e.onDone?.(b),H}var yi={https:"HTTPS for the portal",acme:"ACME certificates",home:"the home-like link",awg:"AmneziaWG"};async function ra(n,e,o,a){return!await re(`Install ${e}?`,o,"Install")||(await It(n,{title:`Installing ${e}`}))?.state!=="done"?!1:(setTimeout(()=>a?.(),4e3),!0)}function pn(n){return ra("amneziawg:auto","AmneziaWG","Dawnline installs the AmneziaWG build made for this firmware and loads it. If the network service has to restart to learn it, connections drop for a few seconds.",n)}async function Bt(n,e,o){return n==="awg"?pn(o):e.length?ra(`pkgs:${e.join(",")}`,yi[n],`${e.join(", ")} from the OpenWrt feeds. Dawnline sets the rest up when they arrive.`,o):!0}async function ia(n,e){if(n==="awg")return pn(e);let o=await W(()=>P.updatesStatus());return o?Bt(n,o.needs?.[n]??[],e):!1}var ki=[["wan","WAN"],["ethernet","Ethernet"],["wifi","Wi-Fi"],["vpn","VPN & tunnels"],["other","Other"]],$i={wan:"globe",ethernet:"ethernet",bridge:"bridge",wifi:"wifi",vpn:"tunnel",other:"link"};function sa(n,e,o){let a=n.id,r=e,i=t("div",{class:"dl-stack gap16"},t("section",{class:"dl-setsec"},t("div",{class:"dl-setsec-body"},t("p",{class:"dl-muted"},"Loading interfaces…")))),s,l=!0,c="",d=!0,p=!0,u="all",w=!1,g=Zo(r,a,o),m=new Set,k="",H=()=>JSON.stringify([p,l,l?"":c,d,[...m].sort()]),B=()=>s.detected.lan||s.saved.lan||"",E=()=>(l?s.detected.wan||s.saved.wan:c)||"",y=()=>new Map(s.devices.map(z=>[z.name,z])),S=()=>{let z=y();return[...d&&B()?[B()]:[],...[...m].filter(X=>X!==B())].filter(X=>X!==E()).map(X=>z.get(X)??{name:X,nets:[],missing:!0})},b=(z,q)=>{s=z,q&&(l=z.config.auto_wan,c=z.config.wan_device||z.detected.wan||z.saved.wan||"",d=z.config.auto_lan,p=z.config.lan_like,u=z.config.mesh??(z.config.device_mesh?"all":"off"),m=new Set(z.config.lan_devices),k=H()),G()},x=async z=>{let q=await P.interfaces(a).catch(X=>(K(X.message,"error"),null));q&&b(q,z)};function M(z){let q=d&&z.name===B(),X=!!z.own||!!z.master||z.name===E()||q;return q||m.has(z.name)||!X&&(z.nets.length>0||!!z.missing)}function h(z){let q=d&&z.name===B(),X=z.name===E(),ce=!q&&m.has(z.name),O=!(!!z.own||!!z.master||X||q)&&(z.nets.length>0||ce||!!z.missing),U=(ce||q)&&!z.zone&&!z.missing,F=z.missing?"Not present right now":z.own?"This server":z.master?`Port of ${z.master}`:X?`Internet${z.zone?` · zone ${z.zone}`:""}`:z.nets.length?z.nets.join(", "):"No IPv4 network",oe=t("button",{type:"button",class:`dl-if${ce?" sel":""}${q?" auto":""}${!O&&!ce&&!q?" off":""}${U?" warn":""}`,"aria-pressed":ce||q?"true":"false","aria-disabled":O?null:"true",click:()=>{O&&(m.has(z.name)?m.delete(z.name):m.add(z.name),G())}},[t("span",{class:"dl-if-ic"},v($i[z.kind]??"link")),t("span",{class:"dl-if-main"},[t("span",{class:"dl-if-name"},z.name),t("span",{class:"dl-if-sub"},F)]),q?t("span",{class:"dl-if-badge ok"},"Auto"):ce?t("span",{class:"dl-if-check"},v("check")):""]);return me(oe,()=>[t("div",{class:"dl-tip-title"},z.name),t("div",{class:"dl-muted"},[z.logical?`Interface ${z.logical}`:"No netifd interface",z.zone?` · zone ${z.zone}`:" · no firewall zone"]),z.members.length?t("div",{class:"dl-muted"},`Ports: ${z.members.join(", ")}`):"",z.nets.length?t("div",{class:"dl-mono"},z.nets.join(", ")):"",U?t("div",{class:"dl-warn"},"Not in a firewall zone: the firewall rejects this traffic."):"",z.master?t("div",{class:"dl-muted"},`Choose ${z.master} to include it.`):""]),oe}function f(){let z=s.like_home;return!p||!s.config.lan_like||!n.enabled?"":!s.needs?.length&&z.active&&z.bridged?"ok":"warn"}function R(){let z=s.like_home;return p?s.needs?.length?[t("span",{class:"dl-warn"},`Needs ${s.needs.join(" and ")}.`)," Until they are installed, internet traffic goes straight to the WAN."]:s.config.lan_like?n.enabled?z.active&&z.bridged?["Internet traffic enters ",t("span",{class:"dl-mono"},z.dev??"")," as ",t("span",{class:"dl-mono"},z.address??""),", so whatever handles home traffic (proxies, filters, DNS) handles it too."]:[t("span",{class:"dl-warn"},`Not working: ${z.error??"the link is down"}`)," Internet traffic goes straight to the WAN for now."]:["Internet traffic enters the router from your LAN, so whatever handles home traffic (proxies, filters, DNS) handles it too."]:["Internet traffic will enter the router from your LAN, so it is handled like any home device. Save to turn on."]:["Off: internet traffic goes straight to the WAN, past whatever handles home traffic on this router."]}let C={off:"Devices of different people never reach each other; a person's own devices don't either.",all:"Devices of people with home access reach each other, like home devices do. Internet-only people never.",circles:"Within a circle: family sees family, guests see guests. Everyone reaches their own devices. Internet-only people never."};function I(z,q,X,ce,fe="",O){return t("div",{class:O?"dl-setrow head":"dl-setrow"},[t("div",{class:"dl-lh-main"},[t("span",{class:`dl-need-ic ${fe}`},v(z)),t("div",{class:"dl-stack"},[t("span",{class:"dl-setrow-label"},q),t("span",{class:"dl-sub"},X),O??""])]),t("div",{class:"dl-setrow-ctl"},ce)])}let Q=(z,q)=>{let X=ce=>t("span",{class:"dl-mono"},ce);return z?t("span",{},[" Now: ",X(z),...q&&q!==z?[", was ",X(q)]:[],"."]):t("span",{},q?[" Not found now: using ",X(q),"."]:[" Not found."])};function G(){let z=t("select",{class:"cbi-input-select","aria-label":"Internet interface",change:T=>{c=T.target.value,G()}},s.devices.filter(T=>!T.own&&!T.master&&T.zone&&!T.missing).map(T=>t("option",{value:T.name,selected:T.name===c?"selected":null},`${T.name} · zone ${T.zone}`))),X=S().flatMap(T=>T.nets.map(j=>[j,T.name])),ce=JSON.parse(H()),fe=JSON.parse(k),O=(...T)=>T.some(j=>JSON.stringify(ce[j])!==JSON.stringify(fe[j])),U=O(0,1,2),F=O(3,4),oe=T=>D("Save",async()=>{let j=await W(()=>P.serverInterfaces(a,l,l?"":c,d,[...m],p,u!=="off",u),"Access saved");j&&(b(j,!0),j.nets_changed&&j.lan_only&&K(`${j.lan_only} ${j.lan_only===1?"person has":"people have"} Home-only access: their devices need the configuration again to reach the new networks.`,"warning",1e4))},"positive",{disabled:!T}),_=t("section",{class:"dl-setsec dl-ifcard"},[t("div",{class:"dl-setsec-body"},[t("div",{class:"dl-panel-head"},[t("h3",{},"Internet"),t("span",{class:"dl-spacer"}),t("span",{class:"dl-sub"},"People with Internet or Both")]),I("home","Internet like a home device",R(),[p&&s.needs?.length?D("Install",()=>Bt("home",s.needs,()=>x(!1)),"positive"):"",ge(p,"Internet like a home device",T=>{p=T,G()})],f()),I("globe","Auto-detect WAN",["The interface with the default route: the server port opens there and Internet access leaves through it.",Q(s.detected.wan,s.saved.wan)],[l?"":z,ge(l,"Auto-detect WAN",T=>{l=T,G()})])]),t("div",{class:"dl-setsec-foot"},[t("span",{class:"dl-sub"},p?["Internet like a home device",E()?[" · leaves through ",t("span",{class:"dl-mono"},E())]:""]:E()?["Internet straight to ",t("span",{class:"dl-mono"},E())]:"No WAN found"),oe(U)])]),A=xe([["off","Off"],["all","Everyone"],["circles","Circles"]],u,{label:"Devices reach each other",cls:"sm",optimistic:!1,onChange:async T=>{let j={off:"Off",all:"Everyone",circles:"Circles"}[T];await W(()=>P.serverUpdate(a,{mesh:T}),`Devices reach each other: ${j}`)&&(u=T,s.config.mesh=T,G(),await o())}}),$=t("section",{class:"dl-setsec dl-ifcard"},[t("div",{class:"dl-setsec-body"},[t("div",{class:"dl-panel-head"},[t("h3",{},"Home network"),t("span",{class:"dl-spacer"}),t("span",{class:"dl-sub"},"People with Home or Both"),D([v("reset")," Rescan"],()=>x(!1),"neutral",{title:"Read the interfaces again"})]),I("network","Networks","Everyone with home access reaches these, unless their page leaves one out; their devices can be reached from here too. Click one to add or remove it.","","",Y()),I("link","Devices reach each other",C[u],A,"",u==="circles"?Qo(r,a,o):void 0),g.el]),t("div",{class:"dl-setsec-foot"},[t("span",{class:"dl-sub dl-if-summary"},X.length?["Home access reaches ",...X.flatMap(([T,j],Z)=>[Z?", ":"",t("span",{class:"dl-mono"},T),` (${j})`])]:"No home network: Home access reaches nothing but this router."),oe(F)])]),N=window.scrollY;i.style.minHeight=`${i.offsetHeight}px`,dom.content(i,[_,$]),i.style.minHeight="",window.scrollTo({top:N})}function Y(){let z=s.devices.filter(M),q=s.devices.filter(X=>!M(X));return t("div",{class:"dl-stack gap8 dl-netpick"},[z.length?t("div",{class:"dl-ifgrid"},z.map(h)):t("span",{class:"dl-warn"},"No home network: Home access reaches nothing but this router."),t("label",{class:"dl-boxrow"},[t("span",{class:"dl-stack"},[t("span",{},"Auto-detect LAN"),t("span",{class:"dl-sub"},["Adds the LAN this router uses.",Q(s.detected.lan,s.saved.lan)])]),ge(d,"Auto-detect LAN",X=>{d=X,G()})]),q.length?t("details",{class:"dl-params",open:w?"":null,toggle:X=>w=X.currentTarget.open},[t("summary",{},[v("chevron"),t("span",{},"Other interfaces"),t("span",{class:"dl-pcount"},String(q.length))]),t("div",{class:"dl-params-body"},[t("span",{class:"dl-sub"},"The WAN, this server, ports and Wi-Fi of a bridge (they come with it) and interfaces without an IPv4 network."),...ki.map(([X,ce])=>{let fe=q.filter(O=>O.category===X);return fe.length?t("div",{class:"dl-ifgroup"},[t("h4",{},ce),t("div",{class:"dl-ifgrid"},fe.map(h))]):""})])]):""])}return x(!0),{el:i,update(z){r=z,g.update(z),s&&G()}}}var Ei={connect:"ok",disconnect:"",roam:"",device_added:"ok",device_removed:"",person_added:"",person_removed:"",paused:"warn",resumed:"ok",portal_blocked:"bad",person_changed:"",devices_removed:"warn"},Li={devices_removed:"trash",link_changed:"link",person_added:"plus",person_removed:"trash",person_changed:"edit",paused:"pause",resumed:"play"};function Mi(n,e){return e.device?n.people.flatMap(a=>a.devices).find(a=>a.id===e.device)?.kind??e.dkind??"other":Li[e.type]??"activity"}function qn(n,e){let o=n.people.find(m=>m.id===e.person),a=o?.name??e.pname??e.person??"",r=o?.devices.find(m=>m.id===e.device)?.name??e.dname??"",i=m=>t("b",{},m),s=m=>t("span",{class:"dl-muted"},m),l=m=>t("span",{class:"dl-mono"},m),c=m=>e.hosts?.[m]?[t("span",{class:"dl-ev-host"},[t("b",{},e.hosts[m]),t("span",{class:"dl-faint"},` (${m})`)])]:[l(m)],d=m=>t("span",{class:"dl-ev-kind"},`${m} `),p=r?`${a} · ${r}`:a,u=wo(e),w=u||r||"a device",g=m=>[t("span",{class:"dl-you"},"You"),s(` ${m} `)];if(Pe(e)==="admin")switch(e.type){case"device_added":return[...g("added"),d("device"),i(w),s(" for "),i(a)];case"device_removed":return[...g("removed"),d("device"),i(w),s(" from "),i(a)];case"paused":return[...g("paused"),d("person"),i(a)];case"resumed":return[...g("resumed"),d("person"),i(a)];case"device_changed":{let m=u.startsWith("renamed from ");return[...g(m?"renamed":u),d("device"),i(r||"a device"),s(" of "),i(a),...m?[s(` · was ${u.slice(13)}`)]:[]]}case"device_keys":return[...g("issued new keys for"),d("device"),i(w),s(" of "),i(a),s(" · it needs its new configuration")];case"link_changed":return[...g("issued a new link for"),d("person"),i(a),s(" · the old link stopped working")]}switch(e.type){case"connect":return[d("Device"),i(p),s(" connected"),...e.detail?[s(" from "),...c(e.detail)]:[],...e.where?[s(` · ${e.where}`)]:[]];case"disconnect":return[d("Device"),i(p),s(" went offline")];case"roam":return[d("Device"),i(p),s(" changed network "),...(e.detail??"").split(" → ").flatMap((m,k)=>k?[s(" → "),...c(m)]:c(m))];case"device_added":return[d("Person"),i(a),s(" added "),d("device"),i(w),...Pe(e)==="portal"?[s(" on their portal")]:[]];case"device_removed":return[d("Person"),i(a),s(" removed "),d("device"),i(w),...Pe(e)==="portal"?[s(" on their portal")]:[]];case"device_keys":return[d("Person"),i(a),s(" issued new keys for "),d("device"),i(w),s(" on their portal")];case"person_added":return[...g("added"),d("person"),i(e.detail??a)];case"person_removed":return[...g("removed"),d("person"),i(e.detail??a)];case"person_changed":return[...g("changed"),d("person"),i(a),...u?[s(` · ${u.replace(/_/g," ")}`)]:[]];case"paused":return[d("Person"),i(a),s(` paused — ${e.detail??""}`)];case"resumed":return[d("Person"),i(a),s(" resumed"),...e.detail&&e.detail!=="active"?[s(` — ${e.detail}`)]:[]];case"portal_blocked":return[t("b",{class:"dl-sys-src"},"Personal portal"),s(" blocked "),l(e.detail??""),s(" for 15 min after too many wrong codes")];case"devices_removed":return[d("Person"),i(a),s(" — all devices removed, end date reached")];default:return[s(`${e.type}${e.detail?`: ${e.detail}`:""}`)]}}var Si={portal_blocked:["globe","bad"]};function _i(n,e){if(n.servers.length<2||!e.person)return"";let o=n.people.find(r=>r.id===e.person),a=o&&n.servers.find(r=>r.id===o.server);return a?t("span",{class:"dl-ev-srv",title:"Server"},a.name):""}function Qe(n,e,o={}){let a=Si[e.type],r=Pe(e);return t("div",{class:`dl-row${r==="admin"?" dl-ev-by-admin":a?` dl-ev-by-system ${a[1]}`:""}`},[r==="admin"?t("span",{class:"dl-ev-tile",title:"Done by you in LuCI"},v("admin")):a?t("span",{class:"dl-ev-tile sys"},v(a[0])):t("span",{class:`dl-ev-tile ev ${Ei[e.type]??""}`},v(Mi(n,e))),t("span",{class:"dl-row-main"},qn(n,e)),o.server===!1?"":_i(n,e),t("span",{class:"dl-faint dl-nowrap",title:new Date(e.ts*1e3).toLocaleString()},o.time??ie(e.ts,n.now))])}var Ti={info:"",up:"ok",down:"warn",repair:"warn",error:"bad"},Ci={awg:"tunnel",dawnline:"sunrise",portal:"globe"};function un(n,e,o,a){let r=n.by==="admin",i=t("div",{class:`dl-row dl-slog-row ${r?"dl-ev-by-admin":`dl-ev-by-system ${Ti[n.level]??""}`}${n.detail?" has-detail":""}`},[r?t("span",{class:"dl-ev-tile",title:"Done by you in LuCI"},v("admin")):t("span",{class:"dl-ev-tile sys",title:n.level},v(Ci[n.src]??"zap")),t("span",{class:"dl-row-main"},r?[t("span",{class:"dl-you"},"You"),t("span",{class:"dl-muted"},` ${n.msg} `),n.kind?t("span",{class:"dl-ev-kind"},`${n.kind} `):"",n.who?t("b",{},n.who):"",n.note?t("span",{class:"dl-muted"},` · ${n.note}`):"",n.detail?t("span",{class:`dl-slog-more${e?" open":""}`},v("chevron")):"",n.detail&&e?t("pre",{class:"dl-slog-detail"},n.detail):""]:[n.src==="awg"&&n.who&&n.who!=="AmneziaWG"?t("span",{class:"dl-ev-kind"},"Server "):"",t("b",{class:"dl-sys-src",title:Ct[n.src]??n.src},n.who??Ct[n.src]??n.src)," ",t("span",{class:"dl-muted"},n.msg),n.detail?t("span",{class:`dl-slog-more${e?" open":""}`},v("chevron")):"",n.detail&&e?t("pre",{class:"dl-slog-detail"},n.detail):""]),t("span",{class:"dl-faint dl-nowrap",title:new Date(n.ts*1e3).toLocaleString()},a)]);return n.detail&&i.addEventListener("click",s=>{s.target.closest("pre")||o()}),i}function la(n){let e=new Date(n*1e3),o=new Date,a=new Date;return a.setDate(o.getDate()-1),e.toDateString()===o.toDateString()?"Today":e.toDateString()===a.toDateString()?"Yesterday":e.toLocaleDateString("en-GB",{weekday:"long",day:"numeric",month:"long"})}var kt=n=>ut(n).toLocaleDateString("en-GB",{day:"numeric",month:"short"});function mn(n,e,o,a=!1){let r=n.slice(-15),i=r[r.length-1],s=i&&e-i[0]<180,l=s?i[2]:0,c=s?i[1]:0,[d,p]=o,u=200,w=40,g=Math.max(1,...r.map(y=>Math.max(y[1],y[2]))),m=y=>r.map((S,b)=>`${r.length>1?b/(r.length-1)*u:u},${w-2-S[y]/g*(w-6)}`),k=m(2),H=m(1),B=r.length>1&&!a?qe(``):t("div",{class:"dl-speed-wait"},[t("i"),a?"":t("span",{},"Collecting… 1 point a minute")]),E=(y,S,b,x)=>t("div",{class:"dl-speed-col"},[t("span",{class:"dl-sub"},[t("span",{class:b},S),` ${y}`]),a?t("span",{class:"dl-speed-val off"},"—"):t("span",{class:"dl-speed-val"},ze(x))]);return r.length>1&&!a&&me(B,()=>{let y=r[r.length-1];return[t("div",{class:"dl-tip-title"},new Date(y[0]*1e3).toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"})),t("div",{},`↓ ${ze(y[2])} · ↑ ${ze(y[1])}`)]}),t("div",{class:"dl-bento-tile"},[t("div",{class:"dl-bento-head"},[t("span",{class:"dl-metric-label"},"Speed now"),a?"":t("span",{class:"dl-sub"},"last 15 min")]),t("div",{class:"dl-speed-cols"},[E("Download","↓","dl-dn",l),E("Upload","↑","dl-up",c)]),B,t("div",{class:"dl-speed-today"},[t("span",{},["Today ",t("b",{},te(d+p))]),t("span",{},[t("span",{class:"dl-dn"},"↓"),` ${te(p)} `,t("span",{class:"dl-up"},"↑"),` ${te(d)}`])])])}function hn(n,e){let o=n.slice(-30),a=o.map(c=>c.rx+c.tx),r=Math.max(1,...a),i=a.reduce((c,d)=>c+d,0),s=a.reduce((c,d,p)=>d>a[c]?p:c,0),l=t("div",{class:"dl-bento-bars"},o.map((c,d)=>{let p=a[d],u=t("i",{class:d===o.length-1?"hi":"",style:`height:${Math.max(4,p/r*100)}%`});return me(u,()=>[t("div",{class:"dl-tip-title"},d===o.length-1?`Today · ${kt(c.day)}`:kt(c.day)),t("div",{},te(p)),t("div",{class:"dl-muted dl-mono"},`↓ ${te(c.tx)} ↑ ${te(c.rx)}`)]),u}));return t("div",{class:"dl-bento-tile month"},[t("div",{class:"dl-bento-head"},[t("span",{},[t("span",{class:"dl-metric-label"},"Last 30 days"),t("b",{class:"dl-bento-total"},te(i))]),a[s]>0?t("span",{class:"dl-sub"},`peak ${te(a[s])} · ${kt(o[s].day)}`):""]),o.length?l:t("p",{class:"dl-muted"},"No traffic yet."),t("div",{class:"dl-bento-head"},[t("span",{class:"dl-sub"},o.length?kt(o[0].day):""),t("span",{class:"dl-sub"},e),t("span",{class:"dl-sub"},"today")])])}function da(n){let e=n.slice(-30),o=e.map(r=>r.rx+r.tx),a=Math.max(1,...o);return t("div",{class:"dl-dbars"},e.map((r,i)=>{let s=t("i",{class:`${o[i]?"":"zero"}${i===e.length-1?" hi":""}`});return s.style.height=`${Math.max(8,o[i]/a*100)}%`,me(s,()=>[t("div",{class:"dl-tip-title"},i===e.length-1?`Today · ${kt(r.day)}`:kt(r.day)),t("div",{},te(o[i]))]),s}))}var ca={apply:"Repair",sync:"Reload devices",restart:"Restart service",netrestart:"Restart network",updates:"Open Components"};async function fn(n){return n==="netrestart"&&!await re("Restart the network?","Every interface restarts. Connections drop for a few seconds.","Restart network")?null:await W(()=>P.healthFix(n),"Done")??null}function Kn(n,e,o,a="action"){let r=n.fix;return r?r.startsWith("install:")?D("Install",()=>ia(r.slice(8),o),a):r==="updates"?t("a",{class:`cbi-button cbi-button-${a}`,href:L.url("admin/network/dawnline/updates")},ca.updates):D(ca[r]??"Fix",()=>e(r),a):""}function Pi(n){return/^(awg|up_|peers_|fw_|reply_|port_|subnet_)/.test(n)?"shield":/^(portal|cert)/.test(n)?"link":/^(ep_|home_|resolver)/.test(n)?"globe":n==="clock"?"clock":n==="agent"?"activity":n==="nft"?"lock":n==="data"?"users":"alert"}function pa(n,e,o,a=3){let r=n.filter(s=>s.status==="error"||s.status==="warn").sort((s,l)=>s.status===l.status?0:s.status==="error"?-1:1);if(!r.length)return"";let i=r.length-a;return t("div",{class:"dl-list dl-notices"},[...r.slice(0,a).map(s=>at(Pi(s.id),s.status==="error"?"bad":"warn",s.problem??s.title,s.detail,Kn(s,e,o,s.status==="error"?"positive":"neutral"))),i>0?t("a",{class:"dl-row dl-notices-more",href:L.url("admin/network/dawnline/diagnostics")},[`${i} more in Diagnostics`,t("span",{class:"dl-spacer"}),"→"]):""])}function Di(n){let e=[],o=(s,l)=>t("a",{href:s},l),a=Re(n.series),r=!!n.awg_state&&!n.awg_state.ok;for(let s of n.servers)s.enabled&&s.blocked?e.push({tone:"bad",text:[`${s.name} ${s.blocked}. `,o(L.url("admin/network/dawnline/diagnostics"),"Open Diagnostics")]}):s.enabled&&!s.up&&!r&&e.push({tone:"bad",text:[`Tunnel ${s.ifname} is down. `,o(L.url("admin/network/dawnline/diagnostics"),"Open Diagnostics")]});for(let s of n.people)if(s.state==="quota")e.push({tone:"warn",text:[o(ke(s.id),s.name)," reached the data limit."]});else if(s.state==="expired")e.push({tone:"warn",text:[o(ke(s.id),s.name),"’s access has ended."]});else{let l=nt(s.expires,a);Fe(s,l)&&e.push({tone:"",text:[o(ke(s.id),s.name),`’s access ${Wt(l)}.`]}),s.quota_limit&&s.quota_used>=s.quota_limit*.9&&e.push({tone:"",text:[o(ke(s.id),s.name)," has used 90% of the data limit."]})}let i=n.people.flatMap(s=>s.devices.filter(l=>l.config_stale).map(l=>[s,l]));return i.length&&e.push({tone:"warn",text:i.length===1?[o(ke(i[0][0].id,i[0][1].id),`${i[0][0].name} · ${i[0][1].name}`)," needs its configuration again."]:[`${i.length} devices need their configuration again (networks or DNS changed).`]}),n.servers.some(s=>s.lan_like)&&n.like_home.error&&e.push({tone:"warn",text:[`Internet through the LAN is off: ${n.like_home.error} `,o(L.url("admin/network/dawnline/diagnostics"),"Details")]}),n.settings.portal_enabled||e.push({tone:"",text:["The personal portal is off. ",o(L.url("admin/network/dawnline/settings"),"Turn on")]}),e}var gn=class{constructor(e,o){this.srvId=e;this.go=o;this.el=t("div",{class:"dl-srvov"});this.map=null;this.range="online";this.parts={};this.healthAt=0}mount(e){this.st=Nt(e,this.srvId);for(let o of["health","bento","side","activity"])this.parts[o]=t("div",{});return dom.content(this.el,[this.parts.health,this.parts.bento,this.mapCard(),t("div",{class:"dl-grid2"},[this.parts.activity,this.parts.side])]),this.paint(),this.loadHealth(),this.el}update(e,o=!1){this.st=Nt(e,this.srvId),this.paint(o),this.map?.update(this.mapData()),Date.now()-this.healthAt>6e4&&this.loadHealth()}async loadHealth(){this.healthAt=Date.now();let e=await P.health().catch(()=>null);if(!e)return;let o=()=>void this.loadHealth(),a=async r=>{await fn(r)&&(o(),r==="netrestart"&&setTimeout(o,5e3))};Le(this.parts.health,pa(e.checks,r=>void a(r),o),!0)}mapData(){return{geo:this.st.geo,people:this.st.people,now:this.st.now}}mapCard(){let e=this.st,o=t("div",{class:"dl-panel-head pad"},[t("div",{class:"dl-stack"},[t("h3",{},"Where people connect from"),t("span",{class:"dl-sub"},"City-level, from the client IP · locations cached on the router")]),t("span",{class:"dl-spacer"}),xt(this.range,i=>{this.range=i,this.map?.setRange(i)})]);if(!e.geo.enabled)return t("div",{class:"dl-panel flush"},[o,t("div",{class:"dl-map-off"},["Locations are off. ",t("a",{href:L.url("admin/network/dawnline/settings")},"Turn them on in Settings"),"."])]);this.map=new Je({openPerson:i=>location.href=ke(i),openDevice:(i,s)=>location.href=ke(i,s)},this.range);let a=t("div",{class:"dl-map-legend"},[t("span",{},[t("i",{class:"line live"}),"Live tunnel"]),t("span",{},[t("i",{class:"line"}),"Seen recently"])]),r=t("div",{class:"dl-map-wrap"},[this.map.el,a]);return requestAnimationFrame(()=>this.map.mount(this.mapData())),t("div",{class:"dl-panel flush"},[o,r])}paint(e=!1){let o=this.st,a=o.servers[0];Le(this.parts.bento,t("div",{class:"dl-bento"},[this.onlineTile(),this.speedTile(),Ie(a).overviewTile(a),this.monthTile()]),e);let r=Di(o);Le(this.parts.side,t("div",{class:"dl-panel flush"},[t("div",{class:"dl-panel-head pad"},[t("h3",{},"Needs attention"),t("span",{class:"dl-spacer"}),t("a",{href:L.url("admin/network/dawnline/diagnostics")},"Health")]),r.length?r.slice(0,8).map(s=>t("div",{class:"dl-attn-item dl-row"},[t("span",{class:`dl-ev-dot ${s.tone}`}),t("span",{},s.text),s.action??""])):t("div",{class:"dl-row dl-muted"},[v("check"),"All good. Nothing needs you right now."])]),e);let i=[...o.events].reverse().slice(0,8);Le(this.parts.activity,t("div",{class:"dl-panel flush"},[t("div",{class:"dl-panel-head pad"},[t("h3",{},"Activity"),t("span",{class:"dl-spacer"}),t("a",{href:`${L.url("admin/network/dawnline/diagnostics")}?tab=log`},"View all")]),i.length?i.map(s=>Qe(o,s)):t("div",{class:"dl-row dl-muted"},"Nothing yet. Connections, new devices and pauses appear here.")]),e)}onlineTile(){let e=this.st,o=e.servers[0]?!e.servers[0].enabled:!1,a=12,r=B=>B.spark[B.spark.length-1]??0,i=B=>e.geo.points.find(E=>E.device===B.id&&E.city)?.city,s=B=>/^(10\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.)/.test(B.endpoint??""),l=(B,E=!1)=>s(B)?E&&B.endpoint?`LAN · ${B.endpoint}`:"LAN":i(B)??"",c=B=>[...e.events].reverse().find(E=>E.type==="connect"&&E.device===B.id)?.ts??0,d=e.people.map(B=>({p:B,devs:B.devices.filter(E=>E.online).sort((E,y)=>r(y)-r(E))})).filter(B=>B.devs.length).sort((B,E)=>E.devs.reduce((y,S)=>y+r(S),0)-B.devs.reduce((y,S)=>y+r(S),0)),p=d.length<=2,u=({p:B,devs:E})=>{let y=E.map(c).filter(Boolean),S=y.length?Math.min(...y):0,b=(B.rate??[]).slice(-15),x=b[b.length-1],M=x&&e.now-x[0]<180?x:null,h=200,f=30,R=Math.max(1,...b.map(Y=>Math.max(Y[1],Y[2]))),C=Y=>b.map((z,q)=>`${b.length>1?q/(b.length-1)*h:h},${f-2-z[Y]/R*(f-6)}`),I=b.length>1?qe(``):"",Q=!M||M[1]<64&&M[2]<64,G=B.access==="both"?["home","globe"]:B.access==="lan"?["home"]:["globe"];return[t("div",{class:"dl-hc"},[t("div",{class:"dl-hc-head"},[t("span",{class:"dl-onl-av sm"},Ce(B.name)),t("span",{class:"dl-stack"},[t("b",{},B.name),t("span",{class:"dl-hc-since"},S?`online for ${ie(S,e.now).replace(" ago","")}`:"online")]),t("span",{class:"dl-hc-reach"},G.map(Y=>t("span",{class:`dl-ibadge ${Y==="home"?"lan":"inet"}`},v(Y))))]),t("div",{class:"dl-hc-speed"},[t("div",{class:"dl-hc-speed-row"},Q?[t("span",{class:"dl-faint"},"Idle right now")]:[t("span",{},[t("span",{class:"dl-dn"},"↓"),` ${ze(M[2])}`]),t("span",{},[t("span",{class:"dl-up"},"↑"),` ${ze(M[1])}`]),t("span",{class:"dl-spacer"}),t("span",{class:"dl-faint"},"15 min")]),I]),t("div",{class:"dl-hc-devs"},E.map(Y=>t("span",{class:"dl-hc-dev"},[v(Y.kind),Y.name,l(Y)?[" · ",l(Y,!0)]:""]))),t("div",{class:"dl-hc-foot"},[t("span",{class:"dl-faint"},`${te(E.reduce((Y,z)=>Y+r(z),0))} today · ${te(B.month[0]+B.month[1])} this month`)])])]},w=B=>{let{p:E,devs:y}=B,S=t("span",{class:"dl-onl-dev"},y.length>1?String(y.length):v(y[0].kind)),b=t("a",{class:`dl-onl-p${p?"":" sm"}`,href:ke(E.id),"aria-label":`${E.name}, online`},[t("span",{class:"dl-onl-av"},[Ce(E.name),S]),p?t("span",{class:"dl-onl-name"},E.name):"",p?t("span",{class:"dl-onl-meta"},[...y.slice(0,3).map(x=>v(x.kind)),y.length>3?`+${y.length-3}`:"",l(y[0])?t("span",{},[" · ",l(y[0])]):""]):""]);return me(b,()=>u(B)),b},g=t("b",{class:`dl-onl-count${d.length?"":" none"}`},String(d.length)),m=d.reduce((B,E)=>B+E.devs.length,0);d.length&&me(g,()=>[`${d.length} ${d.length===1?"person":"people"} · ${m} device${m===1?"":"s"}`]);let k=d.length>a?d.slice(0,a-1):d,H=e.people.flatMap(B=>B.devices.map(E=>({p:B,d:E}))).filter(B=>B.d.handshake).sort((B,E)=>E.d.handshake-B.d.handshake)[0];return t("div",{class:"dl-bento-tile online"},[t("div",{class:"dl-bento-head"},[t("span",{class:"dl-metric-label"},"Online"),g]),d.length?t("div",{class:`dl-onl-row${p?"":" grid"}`},[...k.map(w),d.length>a?t("a",{class:"dl-onl-p sm more",href:`${L.url("admin/network/dawnline/server")}?server=${encodeURIComponent(this.srvId)}§ion=people&filter=online`,title:"Everyone online",click:B=>{this.go&&(B.preventDefault(),this.go("people","online"))}},[t("span",{class:"dl-onl-av"},`+${d.length-k.length}`)]):""]):t("div",{class:"dl-onl-empty"},[t("span",{},o?"The server is turned off":"Nobody is connected"),H?t("span",{class:"dl-sub"},`Last: ${H.p.name}, ${ie(H.d.handshake,e.now)}`):t("span",{class:"dl-sub"},o?"Devices connect once it is on":"No device has connected yet")])])}speedTile(){let e=this.st.servers[0];return mn(e?.rate??[],this.st.now,this.st.totals.today,e?!e.enabled:!1)}monthTile(){return hn(this.st.series,"")}};var ua=[["overview","Overview"],["people","People"],["connection","Connection"],["access","Access"],["awg",""]],Ai={general:"connection",network:"connection",interfaces:"access",advanced:"awg",disguise:"awg",tunnel:"awg",core:"awg"},Jn=(n,e)=>{let o=new URLSearchParams;n&&o.set("server",n),e&&e!=="overview"&&o.set("section",e);let a=o.toString();return`${L.url("admin/network/dawnline/server")}${a?`?${a}`:""}`},Ot=class{constructor(){this.noFooter=!0;this.root=t("div",{class:"dl-root"});this.section="overview";this.srvId="";this.ov={};this.pp={};this.tabsEl=t("div",{});this.headEl=t("div",{});this.secEl=t("div",{});this.bodyEl=t("div",{class:"dl-srvbody"})}async load(){let e=await P.status(31),o=e.servers.length?null:await P.setupDefaults();return[e,o]}render([e,o]){if(this.st=e,!e.servers.length&&o)return this.wizard(o);let a=new URLSearchParams(location.search),r=a.get("section")??"",i=Ai[r]??r;return ua.some(([s])=>s===i)&&(this.section=i),this.srvId=(e.servers.find(s=>s.id===a.get("server"))??e.servers[0]).id,dom.content(this.root,[this.tabsEl,this.headEl,this.secEl,this.bodyEl]),this.paint(),this.poller=Ve({fetch:()=>P.status(31),every:30,live:!0,active:()=>this.section==="overview"&&this.root.isConnected,apply:(s,l)=>{s.servers.length&&(this.st=s,this.paintHead(l),this.ov[this.current().id]?.update(s,l))}}),this.root}paintHead(e=!1){Le(this.headEl,this.head(this.current()),e),(!e||!yt(this.tabsEl))&&this.paintTabs()}async refreshStatus(){let e=await P.status(31).catch(()=>null);return e?.servers.length?(this.st=e,this.paintHead(),e):null}current(){return this.st.servers.find(e=>e.id===this.srvId)??this.st.servers[0]}async refresh(){let e=await P.status(31).catch(()=>null);e&&(this.st=e,e.servers.length?this.paint():location.href=Jn())}paint(){this.paintTabs(),dom.content(this.headEl,this.head(this.current())),this.paintSections(),this.showSection(this.section)}paintTabs(){let e=this.current();dom.content(this.tabsEl,t("div",{class:"dl-srvtabs",role:"tablist","aria-label":"Servers"},[...this.st.servers.map(o=>t("button",{type:"button",role:"tab",class:`dl-srvtab${o.id===e.id?" on":""}`,"aria-selected":o.id===e.id?"true":"false",click:()=>{o.id!==this.srvId&&(this.srvId=o.id,this.paint())}},[t("i",{class:`dot ${o.enabled?o.up?"ok":"bad":"warn"}`}),t("b",{},o.name)])),t("button",{type:"button",class:"dl-srvtab add",click:()=>this.addServer()},[v("plus"),"Add server"])]))}paintSections(){let e=Ie(this.current());dom.content(this.secEl,t("div",{class:"dl-seg dl-srvsections",role:"tablist","aria-label":"Server"},ua.map(([o,a])=>t("button",{type:"button",role:"tab","data-section":o,class:o===this.section?"on":"","aria-selected":o===this.section?"true":"false",click:()=>this.showSection(o)},o==="awg"?e.label:a))))}go(e,o){let a=this.pp[this.current().id];if(o&&a)a.filter=o,a.el&&a.decorate();else if(o){let r=this.pp[this.current().id]=new st;r.filter=o}this.showSection(e),window.scrollTo({top:0,behavior:"smooth"})}detachKept(){let e=[...Object.values(this.ov).map(o=>o.el),...Object.values(this.pp).map(o=>o.el)];for(let o of e)o&&this.bodyEl.contains(o)&&o.remove()}showSection(e){this.section=e,this.secEl.querySelectorAll("[data-section]").forEach(s=>{let l=s.dataset.section===e;s.classList.toggle("on",l),s.setAttribute("aria-selected",l?"true":"false")});let o=this.st,a=this.current(),i={overview:()=>{let s=this.ov[a.id];return s?(s.update(o),s.el):(this.ov[a.id]=new gn(a.id,(l,c)=>this.go(l,c))).mount(o)},people:()=>{var d,p;let s=this.pp[a.id];if(s?.el)return s.update(),s.el;let l=t("div",{},t("p",{class:"dl-muted"},"Loading people…"));return((d=this.pp)[p=a.id]??(d[p]=new st)).embed(o,a.id).then(u=>{l.isConnected?dom.content(l,u):l.replaceChildren(u)}).catch(u=>{delete this.pp[a.id],dom.content(l,t("p",{class:"dl-muted"},`Couldn't show people: ${ve(u)}`))}),l},connection:()=>this.connection(a),access:()=>this.access(a),awg:()=>this.awg(a)}[e]();this.detachKept(),dom.content(this.bodyEl,i)}head(e){let o=(i,s)=>t("span",{class:"dl-addrbar-seg"},[v(i),...s]),a=e.endpoint||"—",r=t("div",{class:"dl-actions"},[e.enabled?"":D([v("play")," Turn on"],()=>this.save(e,{enabled:"1"},"Server turned on"),"add")]);return t("div",{class:"dl-srvpagehead"},[t("div",{class:"dl-title-row"},[t("h2",{class:"dl-h1"},e.name),t("span",{class:`dl-pill ${e.enabled?e.up?"ok":"bad":"warn"}`},e.enabled?e.up?"Running":e.blocked?"Can’t start":"Not running":"Turned off"),t("span",{class:"dl-spacer"}),r]),t("div",{class:"dl-addrbar"},[t("button",{type:"button",class:"dl-addrbar-seg main",title:"Copy address",click:()=>ue(a,"Address copied")},[v("globe"),t("span",{class:"dl-mono"},a),v("copy")]),o("tunnel",[t("span",{class:"dl-mono"},`${Ie(e).label} :${e.port}`)]),e.up?o("clock",[`up ${pt(e.uptime)}`]):""]),e.blocked?t("div",{class:"dl-note warn"},[v("alert"),t("span",{},`${e.name} ${e.blocked}.`)]):""])}async save(e,o,a="Saved"){await W(()=>P.serverUpdate(e.id,o),a)&&await this.refresh()}connection(e){let o=se(e.name,{placeholder:"Home"}),a=se(e.endpoint,{placeholder:"vpn.example.com",class:"cbi-input-text dl-mono"}),r=se(e.dns.join(", "),{placeholder:"This router (recommended)",class:"cbi-input-text dl-mono"}),i=this.st.people.filter(l=>l.server===e.id).length,s=D(e.enabled?"Turn off":"Turn on",async()=>{e.enabled&&!await re(`Turn off ${e.name}?`,`The tunnel stops and ${i} ${i===1?"person is":"people are"} disconnected until you turn it back on. Nothing is deleted.`,"Turn off",!0)||await this.save(e,{enabled:e.enabled?"0":"1"},e.enabled?"Server turned off":"Server turned on")},e.enabled?"negative":"positive");return t("div",{class:"dl-stack gap16"},[_t("Connection",[t("p",{class:"dl-muted"},"The name people see, where devices find the router, and DNS. The port is on AmneziaWG."),he("router","Server","What people see",[ne("Name",o,"Shown to people in their portal and apps.")]),he("globe","Devices connect to","Where the router answers from the internet",[ne("Public address",a,"Hostname or IP of the router on the internet. A DDNS name keeps links working when your IP changes. It must not go through Cloudflare: use a DNS-only name or an IP.")]),he("file","For every device","Changing it marks devices “Update config” until they import again",[ne("DNS for devices",r,"Empty = this router, which sends each query where your home network would.")])],[t("span"),D("Save",()=>this.save(e,{name:o.value,endpoint:a.value,dns:r.value}),"positive")]),_t("Danger zone",[t("div",{class:"dl-setrow"},[t("div",{class:"dl-stack"},[t("span",{class:"dl-setrow-label"},e.enabled?"Turn off this server":"This server is off"),t("span",{class:"dl-sub"},e.enabled?"Stops the tunnel and disconnects everyone on it. Settings and people are kept.":"Nobody can connect. Turn it on to bring the tunnel back.")]),t("div",{class:"dl-setrow-ctl"},s)]),t("div",{class:"dl-setrow"},[t("div",{class:"dl-stack"},[t("span",{class:"dl-setrow-label"},"Remove server"),t("span",{class:"dl-sub"},`Removes the tunnel, its firewall rules and ${i} ${i===1?"person":"people"} with all their devices. A backup is made first.`)]),t("div",{class:"dl-setrow-ctl"},D([v("trash")," Remove"],()=>this.remove(e),"negative"))])],[],"danger")])}access(e){let o=Fn(this.st,e),a=sa(e,this.st,async()=>{let r=await this.refreshStatus();if(!r)return;let i=r.servers.find(l=>l.id===e.id)??e;a.update(r);let s=Fn(r,i);o.replaceWith(s),o=s});return t("div",{class:"dl-stack gap16"},[a.el,t("div",{class:"dl-health-cols"},[o,Xo(this.st,e)])])}awg(e){let o={st:this.st,save:(a,r)=>this.save(e,a,r),refresh:()=>this.refresh()};return t("div",{class:"dl-stack gap16"},[Ie(e).settingsCard(o,e)])}async addServer(){let e=await W(()=>P.setupDefaults());e&&dom.content(this.root,this.wizard(e,!0,()=>{dom.content(this.root,[this.tabsEl,this.headEl,this.secEl,this.bodyEl]),this.paint()}))}async remove(e){let o=this.st.people.filter(a=>a.server===e.id);ae(`Remove ${e.name}?`,[t("p",{},`This removes the tunnel, its firewall rules and ${o.length} ${o.length===1?"person":"people"} with all their devices. A backup is made first.`)],[le()," ",D("Remove",async()=>{de(),await W(()=>P.serverDelete(e.id),"Server removed")&&setTimeout(()=>{location.href=Jn()},800)},"negative")])}wizard(e,o=!1,a){let r={id:e.id,name:e.name,endpoint:e.endpoint,port:e.port,range:rn(e.subnet),preset:"standard",portal:!1,portal_port:e.portal_port||8443,lan_like:!0,lan_zone:e.lan_zone,wan_zone:e.wan_zone},i=0,s=!o&&r.portal_port===r.port,l=()=>/^\d{1,3}(\.\d{1,3}){3}$/.test(r.endpoint),c=()=>Wn(r.port,e.udp_taken??[],"Opened on the WAN firewall automatically."),d=()=>Jo(r.range,e.networks??[],rn(e.subnet)),p=()=>Rt(r.portal_port,e.tcp_taken??[],l()),u=t("div",{class:"dl-wizard"}),w=(b,x={})=>{let M=se(String(r[b]),x);return M.addEventListener("input",()=>{b==="port"||b==="portal_port"?r[b]=M.value.trim()===""?0:Number(M.value):r[b]=M.value.trim(),b==="port"&&s&&(r.portal_port=r.port),b==="portal_port"&&(s=r.portal_port===r.port)}),M},g={id:"server",title:"Server",render:()=>t("div",{class:"dl-wizard-groups"},[t("p",{class:"dl-muted"},"Where devices connect to. A hostname that always points at your router (DDNS) keeps links working when your IP changes."),he("router","Server","What people see",[ne("Name",w("name"),"Shown to people in their portal and apps.")]),he("globe","Devices connect to","Where the router answers from the internet",[ne("Public address",w("endpoint",{placeholder:"vpn.example.com",class:"cbi-input-text dl-mono"}),"Hostname or IP address of your router on the internet. Not through Cloudflare: use a DNS-only name or an IP.")])]),check:()=>r.endpoint?null:"Fill in the public address."},m={id:"awg",title:"AmneziaWG",render:()=>t("div",{class:"dl-wizard-groups"},[he("globe","Listening","Where devices reach AmneziaWG from the internet",[mt("UDP port",w("port",{inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),c)]),he("network","Tunnel network","Addresses devices get inside the tunnel",[(()=>{let b=w("range",{class:"cbi-input-text dl-w-range dl-mono","aria-label":"First three numbers of the device addresses"});return mt("Device addresses",b,d,t("span",{class:"dl-suffixed"},[b,t("span",{class:"dl-mono"},".x")]))})()]),he("shield","Disguise","So networks that block VPNs do not recognise the tunnel. Off = plain WireGuard",[Zt(e.awg,r.preset,b=>r.preset=b,void 0,e.awg_state?.tools!==!1)])]),check:()=>{let b=c();if(b.bad)return`UDP port: ${b.text}`;let x=d();return x.bad?`Device addresses: ${x.text}`:null}},k={id:"portal",title:"Portal",render:()=>{let b=w("portal_port",{inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),x=mt("Listening port",b,p);x.hidden=!r.portal;let M=xe([["off","Off"],["on","On"]],r.portal?"on":"off",{label:"Personal portal",onChange:h=>{r.portal=h==="on",x.hidden=!r.portal}});return t("div",{class:"dl-wizard-groups"},[he("home","Internet like a home device","How devices reach the internet",[ne("Through the home network",ge(r.lan_like,"Internet like a home device",h=>r.lan_like=h),"Whatever handles home traffic on this router (proxies, filters, DNS) handles theirs too. Change it later under Servers → Access.")]),he("link","Personal portal","A page where each person adds their own devices with their personal link",[ne("Portal",M,"Off: only you add devices, from LuCI. On: people manage their devices within the limits you set."),x])])},check:()=>{if(!r.portal)return null;let b=p();return b.bad?`Portal port: ${b.text}`:null}},H=()=>[g,m,o?null:k].filter(b=>b!=null),B=e.awg_state,E=B?.missing??[],y=E.length?t("div",{class:"dl-list dl-notices"},[at("shield","bad","AmneziaWG isn’t installed",`The tunnel needs ${E.join(" and ")}. Install the build made for this firmware, then create the server.`,D("Install",()=>pn(()=>location.reload()),"positive"))]):B&&!B.loaded?t("div",{class:"dl-list dl-notices"},[at("shield","warn","AmneziaWG’s kernel module doesn’t load on this firmware","Try another build in Components, or update OpenWrt. The server can’t start until it loads.",t("a",{class:"cbi-button cbi-button-neutral",href:L.url("admin/network/dawnline/updates")},"Open Components"))]):"",S=()=>{let b=H();i>=b.length&&(i=b.length-1),dom.content(u,[t("h2",{},o?"Add a server":"Set up Dawnline"),y,t("div",{class:"dl-steps"},b.map((x,M)=>t("span",{class:`dl-step${M===i?" current":M0?D("Back",()=>{i--,S()}):a?D("Cancel",a):"",t("span",{class:"dl-spacer"}),i{let x=b[i].check?.();if(x){K(x,"warning");return}i++,S()},"positive"):D("Create server",async()=>{for(let M of b){let h=M.check?.();if(h){K(h,"warning");return}}let x=await W(()=>P.serverCreate(r.id,r.name,e.ifname,r.port,Un(r.range),r.endpoint,e.mtu,r.preset,r.lan_zone,r.wan_zone,r.lan_like,o?void 0:r.portal,o?void 0:r.portal_port),"Server created");x&&(x.network_restart&&K("Restarting the network so it knows AmneziaWG: back in a few seconds"),setTimeout(()=>{location.href=Jn(x.id)},x.network_restart?1e4:1500))},"positive",{disabled:E.length>0,title:E.length?"Install AmneziaWG first":null})])])};return S(),u}};function Xe(n){let e={el:n(),refresh(){let o=n();e.el.replaceWith(o),e.el=o}};return e}function De(n,e,o,a,r="",i=[]){return t("section",{class:`dl-setsec ${r}`,id:`dl-set-${n}`},[t("div",{class:"dl-setsec-body"},[i.length?t("div",{class:"dl-setsec-head"},[t("h3",{},e),t("span",{class:"dl-spacer"}),...i]):t("h3",{},e),...o]),a.length?t("div",{class:"dl-setsec-foot"},a):""])}function ma(n){let e=n.filter(r=>r.status!=="skip"),o=e.filter(r=>r.status==="error"||r.status==="warn"),a=e.some(r=>r.status==="error")?"error":o.length?"warn":"ok";return{bad:o,worst:a}}function ha(n){let e=n.d.settings,o=n.d.effective,a=n.d.cert,r=ge(o.portal_enabled,"Enable portal"),i=se(e.portal_port,{placeholder:"8443",inputmode:"numeric",class:"cbi-input-text dl-w-port"}),s=se(e.portal_title,{placeholder:"Dawnline"}),l=se(e.portal_redirect,{placeholder:"Show “Not found”",class:"cbi-input-text dl-mono"}),c=se("",{placeholder:"vpn.example.com or an IP","aria-label":"Other address"}),d=O=>/^\d{1,3}(\.\d{1,3}){3}$/.test(O),p=[o.portal_host,...o.portal_alt??[]].filter((O,U,F)=>O&&F.indexOf(O)===U),u=!!n.portal,w=[],g=O=>{O&&!w.some(U=>U.host===O)&&w.push({host:O,kind:d(O)?"ip":"name",ips:[],here:!1,cloudflare:!1,cert:!1})},m=O=>{w=[...O,...w.filter(U=>!O.some(F=>F.host===U.host))],!p.length&&O[0]&&(p=[O[0].host])};n.portal&&m(n.portal.candidates),p.forEach(g);let k=O=>O.kind==="ip"?t("span",{class:"dl-addr-warn"},[v("alert"),"Plain HTTP: the link and VPN keys travel unencrypted"]):t("span",{class:"dl-sub"},O.cloudflare?"Behind Cloudflare · often stalls in Russia":O.ips.length?O.here?`Points at this router${O.cert?" · Let’s Encrypt certificate":" · no certificate yet"}`:`Points at ${O.ips.join(", ")}, not this router`:u?"Your address":"Checking where it points…"),H=t("div",{class:"dl-addr-opts",role:"group","aria-label":"Portal addresses"}),B=O=>{p.includes(O)?p.length>1&&(p=p.filter(U=>U!==O)):p=[...p,O],E(),b()},E=()=>dom.content(H,[...w.map(O=>{let U=p.includes(O.host),F=p[0]===O.host;return t("div",{class:`dl-addr-opt${U?" on":""}`,role:"checkbox","aria-checked":U?"true":"false",tabindex:"0",click:()=>B(O.host),keydown:oe=>{(oe.key===" "||oe.key==="Enter")&&(oe.preventDefault(),B(O.host))}},[t("i",{class:"dl-addr-check"},U?v("check"):""),t("span",{class:"dl-stack"},[t("span",{class:"dl-mono"},O.host),k(O)]),F?t("span",{class:"dl-pill info"},"Main"):U?t("button",{type:"button",class:"dl-linkbtn",click:oe=>{oe.stopPropagation(),p=[O.host,...p.filter(_=>_!==O.host)],E(),b()}},"Make main"):O.cloudflare?t("span",{class:"dl-pill warn"},"Cloudflare"):O.kind==="ip"?t("span",{class:"dl-pill"},"IP"):O.here&&O.cert?t("span",{class:"dl-pill ok"},"Recommended"):""])}),t("div",{class:"dl-addr-opt other"},[t("i",{class:"dl-addr-check"},v("plus")),c,D("Add",()=>{let O=c.value.trim().toLowerCase();O&&(g(O),p.includes(O)||(p=[...p,O]),c.value="",E(),b())})])]);c.addEventListener("keydown",O=>{O.key==="Enter"&&(O.preventDefault(),c.nextElementSibling?.click())});let y=t("div",{class:"dl-links"}),S=()=>{},b=()=>{S();let O=Number(i.value)||o.portal_port;dom.content(y,p.map((U,F)=>{let oe=d(U),_=oe?O+1:O,A=`${oe?"http":"https"}://${U}${_===(oe?80:443)?"":`:${_}`}/`;return t("div",{class:"dl-link-row"},[t("span",{class:`dl-link-ic ${oe?"warn":"ok"}`},v(oe?"alert":"lock")),t("span",{class:"dl-mono dl-link-url"},[A,t("b",{},"kamiro-telosu-bavine")]),F===0?t("span",{class:"dl-pill info"},"Main"):oe?t("span",{class:"dl-pill warn"},"HTTP"):""])}))};E(),b(),i.addEventListener("input",()=>b());let x={portal:"Portal running",portal_dns:"Points here",portal_reply:"Answers reach visitors",portal_http:"Plain HTTP",cert:"Certificate"},M=n.d.needs??{https:[],acme:[],home:[]},h=O=>{if(!o.portal_enabled)return t("div",{hidden:!0});if(!O)return he("check","Ready to share","The portal’s checks from Health",[t("p",{class:"dl-muted dl-loading"},"Running checks…")]);let U=O.filter($=>$.status!=="skip");if(!U.length)return t("div",{hidden:!0});let{bad:F,worst:oe}=ma(O),_=t("div",{class:"dl-ready-details",hidden:!0},U.map($=>t("div",{class:`dl-ready-item ${$.status}`},[v($.status==="ok"?"check":"alert"),t("span",{class:"dl-stack"},[t("span",{},$.title),t("span",{class:"dl-sub"},$.detail)])]))),A=t("div",{class:"dl-stack gap8"},[t("div",{class:`dl-ready-sum ${oe}`},[v(oe==="ok"?"check":"alert"),t("span",{class:"dl-stack"},[t("b",{},oe==="ok"?`All ${U.length} checks passed`:`${U.length-F.length} of ${U.length} checks passed`),F.length?t("span",{class:"dl-sub"},F.map($=>$.detail).join(" ")):t("span",{class:"dl-sub"},"Links will open for the people you send them to.")]),t("button",{type:"button",class:"dl-linkbtn",click:$=>{_.hidden=!_.hidden,$.currentTarget.textContent=_.hidden?"Details":"Hide"}},"Details")]),t("div",{class:"dl-chips-row"},U.map($=>t("span",{class:`dl-check-chip ${$.status}`,title:$.detail},[v($.status==="ok"?"check":"alert"),x[$.id]??$.title]))),_]);return he("check","Ready to share","The portal’s checks from Health",[A])},f=O=>{if(!o.portal_enabled||!O&&!M.https.length)return t("span",{hidden:!0});if(M.https.length)return t("span",{class:"dl-pill bad"},"Can’t start");let{worst:U}=ma(O);return t("span",{class:`dl-pill ${U==="ok"?"ok":U==="error"?"bad":"warn"}`},U==="error"?"Needs attention":"Ready")},R=h(n.portal?.checks??null),C=f(n.portal?.checks??null);n.portalFill=O=>{u=!0,m(O.candidates),E(),b();let U=h(O.checks);R.replaceWith(U),R=U;let F=f(O.checks);C.replaceWith(F),C=F};let I=a&&!a.self_signed&&a.expires?Ne(a.expires):"",Q=mt("Listening port",i,()=>Rt(i.value.trim()===""?o.portal_port:Number(i.value),n.d.tcp_taken??[],p.some(d)));S=Q.refresh;let G=!!(e.portal_cert&&e.portal_key),Y=a?G?"Your files":a.self_signed?"Self-signed":"Let’s Encrypt":"Portal is off",z=()=>{let O=se(e.portal_cert,{placeholder:"/etc/ssl/…/fullchain.crt"}),U=se(e.portal_key,{placeholder:"/etc/ssl/…/key"});ae("Use your own certificate",[t("p",{class:"dl-muted"},"Paths on the router. Leave both empty to pick a certificate automatically."),ne("Certificate file",O),ne("Key file",U)],[le()," ",D("Save",()=>{de(),n.save({portal_cert:O.value.trim(),portal_key:U.value.trim()},"Certificate saved","portal")},"positive")])},q=(O,U,F,oe,_,A)=>at(O,U,F,oe,D(A,()=>Bt(_,M[_],()=>n.reload("portal")),"positive")),X=M.https.length?q("lock","bad","HTTPS isn’t available on this router",`The portal needs ${M.https.join(" and ")}. It can’t start without them.`,"https","Install"):"",ce=M.acme.length&&(!a||a.self_signed)?q("lock","","Free certificate from Let’s Encrypt",`ACME isn’t installed. With it the router gets a certificate${e.portal_host?` for ${e.portal_host}`:""} and browsers stop warning.`,"acme","Install ACME"):"",fe=[t("div",{class:"dl-row"},[v("lock"),t("span",{class:"dl-row-main dl-stack"},[t("b",{},[Y,I?t("span",{class:"dl-faint"},` · until ${I}`):""]),t("span",{class:"dl-sub dl-ellipsis",title:a?.path??""},a?a.self_signed?"Made by the router: browsers warn until a certificate covers the address.":`${G?"Your files":"Found automatically"} · ${a.path}`:"Turn the portal on to see its certificate.")])]),t("div",{class:"dl-row"},[v("file"),t("span",{class:"dl-row-main dl-stack"},[t("b",{},"Your own files"),t("span",{class:"dl-sub"},G?`${e.portal_cert} · ${e.portal_key}`:"Not set: the certificate is picked automatically.")]),G?D("Reset",()=>n.save({portal_cert:"",portal_key:""},"Automatic certificate","portal"),"negative"):"",D(G?"Change":"Use files",z)]),ce];return De("portal","Personal portal",[t("span",{class:"dl-muted"},"A page where each person adds and manages their devices with their personal link."),X?t("div",{class:"dl-list"},[X]):"",he("network","Port","How the portal listens (80 and 443 stay free)",[Q]),he("edit","Appearance","What people see",[ne("Title",s,"Shown at the top of the portal."),ne("Unknown links",l,"Where a wrong or old link goes, for example your website. Empty shows a plain “Not found”.")]),he("link","Addresses","Pick one or more; the first is the main link",[H,t("div",{class:"dl-stack gap8"},[y,t("span",{class:"dl-sub"},"Example code; each person gets their own three words.")])]),he("lock","Certificate","Used for HTTPS links",fe),R],[t("span"),D("Save",()=>{let O=Rt(i.value.trim()===""?o.portal_port:Number(i.value),n.d.tcp_taken??[],p.some(d));if(O.bad){K(`Listening port: ${O.text}`,"warning");return}return n.save({portal_enabled:Me(r)?"1":"0",portal_host:p[0]??"",portal_alt:p.slice(1),portal_port:i.value,portal_title:s.value,portal_redirect:l.value.trim()},"Saved","portal")},"positive")],"",[C,r])}function fa(n){let e=n.d.settings,o=n.d.effective,a=se(e.default_device_limit,{placeholder:"3",inputmode:"numeric",class:"cbi-input-text dl-w-port"}),r=ge(o.hostnames,"Device hostnames"),i=se(e.domain,{placeholder:"lan",class:"cbi-input-text dl-w-port"}),s=se(e.home_dns_fallback==="none"?"":e.home_dns_fallback||o.home_dns_fallback||"",{placeholder:"None",inputmode:"decimal",class:"cbi-input-text dl-w-ip dl-mono"});return De("defaults","Defaults",[ne("Devices per person",a,"Pre-filled when you add someone."),ne("Device hostnames",t("div",{class:"dl-hostport"},[r,t("span",{class:"dl-faint dl-mono"},"phone.myata."),i]),"Name devices in your home DNS."),ne("Fallback DNS",s,"For Home-only devices using home names: the second DNS server, used by the device when the tunnel is down. Empty = none.")],[t("span"),D("Save",()=>n.save({default_device_limit:a.value,hostnames:Me(r)?"1":"0",domain:i.value,home_dns_fallback:s.value},"Saved","defaults"),"positive")])}function ga(n){let e=n.d.effective,o=ge(e.geo_enabled,"Locations"),a=t("select",{class:"cbi-input-select"},[t("option",{value:"ipwho.is",selected:e.geo_provider!=="ipapi.co"?"selected":null},"ipwho.is (fallback: ipapi.co)"),t("option",{value:"ipapi.co",selected:e.geo_provider==="ipapi.co"?"selected":null},"ipapi.co (fallback: ipwho.is)")]);return De("map","Map & locations",[t("div",{class:"dl-setrow head"},[t("span",{class:"dl-muted"},"Show where people connect from on the Overview and person pages, at city level."),o]),ne("Provider",a)],[t("span",{class:"dl-sub"},"The router sends each new client IP to the provider once and caches the city. Map tiles load in your browser from CARTO; people never see the map."),D("Save",()=>n.save({geo_enabled:Me(o)?"1":"0",geo_provider:a.value},"Saved","map"),"positive")])}var zi=[["app","Dawnline"],["amneziawg","AmneziaWG"],["packages","System packages"]];function va(n){let e=n.d.effective.updates,o=ge(e.check,"Check automatically",m=>g(m,Me(r))),a=xe([["6h","Every 6 h"],["12h","Every 12 h"],["1d","Daily"],["7d","Weekly"]],e.interval,{label:"How often",cls:"sm"}),r=ge(e.auto,"Install automatically",m=>g(Me(o),m)),i=se(e.time,{placeholder:"04:00",inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono","aria-label":"Time"}),s=xe([["scheduled","At a set time"],["immediate","As soon as found"]],e.mode,{label:"When",cls:"sm",onChange:m=>i.hidden=m!=="scheduled"});i.hidden=e.mode!=="scheduled";let l=new Set(e.targets),c=t("div",{class:"dl-chips-row"},zi.map(([m,k])=>{let H=We(k,l.has(m),()=>{l.delete(m)||l.add(m),Yt(H,l.has(m))});return H})),d=ge(e.keep,"Keep the previous version"),p=ge(e.mirrors,"GitHub mirrors"),u=ne("How often",a),w=[ne("When",t("div",{class:"dl-hostport"},[s,i]),"A set time keeps tunnel restarts out of the evening; the run happens within an hour of it."),ne("Components",c,"AmneziaWG is off by default: a new kernel module restarts every tunnel.")],g=(m,k)=>{u.hidden=!m;for(let H of w)H.hidden=!k};return g(e.check,e.auto),De("updates","Updates",[t("span",{class:"dl-muted"},"How Dawnline keeps its components current. Every Dawnline update makes a backup of the settings first."),ne("Check automatically",o,"Looks for new versions in the background; Components shows what it found and the service log names it."),u,ne("Install automatically",r,"Downloads and installs new versions of the components below."),...w,ne("Keep the previous version",d,"Saves the replaced Dawnline or AmneziaWG package on flash, so Roll back works without internet. Under 1 MB."),ne("GitHub mirrors",p,"When GitHub is unreachable, download through mirrors. Checksums are still verified.")],[t("span",{class:"dl-sub"},"Run a check or an update by hand in Components."),D("Save",()=>n.save({update_check:Me(o)?"1":"0",update_interval:a.dataset.value,update_auto:Me(r)?"1":"0",update_mode:s.dataset.value,update_time:i.value.trim(),update_targets:[...l],update_keep:Me(d)?"1":"0",update_mirrors:Me(p)?"1":"0"},"Saved","updates"),"positive")])}function ba(n){let e=n.d.logs,o=e.policy,a=xe([["7","7 days"],["30","30 days"],["90","90 days"],["365","1 year"],["0","No limit"]],String(o.keep_days),{label:"Keep activity",cls:"sm"}),r=xe([["500","500"],["2000","2,000"],["5000","5,000"],["20000","20,000"]],String(o.max),{label:"Maximum events",cls:"sm"}),i=xe([["10min","Every 10 min"],["hourly","Hourly"],["off","Memory only"]],o.persist,{label:"Save to flash",cls:"sm"}),s=xe([["31","1 month"],["62","2 months"],["180","6 months"],["365","1 year"],["730","2 years"]],String(o.usage_days),{label:"Daily traffic",cls:"sm"}),l=xe([["12","1 year"],["24","2 years"],["60","5 years"],["120","10 years"]],String(o.usage_months),{label:"Monthly traffic",cls:"sm"}),c=new Set(o.categories),d=t("div",{class:"dl-chips-row"},gt.map(g=>{let m=We([rt[g],t("b",{},String(e.by_category[g]??0))],c.has(g),()=>{c.delete(g)||c.add(g),Yt(m,c.has(g))},{title:xo[g]});return m})),p=e.oldest?Ne(new Date(e.oldest*1e3)):"",u=(g,m,k,H)=>t("div",{class:"dl-row"},[v(g),t("span",{class:"dl-row-main dl-stack"},[t("b",{},m),t("span",{class:"dl-sub"},k)]),...H]),w=g=>D(g.toUpperCase(),async()=>{let[m,k]=await Promise.all([P.status(1),P.events(2e4)]);Ue(m,k.events,g)},"neutral",{title:`Download the log as ${g.toUpperCase()}`});return De("logs","Logs & history",[t("p",{class:"dl-muted"},Vt(o)),ne("Keep activity",a,"Older events are removed automatically."),ne("Maximum size",r,"Newest events are kept when the log is full."),ne("Record",d,"Switched-off categories are not logged from now on."),ne("Save to flash",i,"The log lives in memory and is copied to flash. Memory only saves flash writes but is lost on reboot."),ne("Daily traffic",s,"Per-day history behind the charts."),ne("Monthly traffic",l,"Per-month totals; data limits use the current month."),t("h4",{class:"dl-setsub"},"Stored data"),t("div",{class:"dl-list"},[u("activity","Activity log",e.events?`${Gt(e.events,"event")} since ${p} · ${St(e.log_ram)} in memory${o.persist==="off"?"":`, ${St(e.log_flash)} on flash`}`:"Empty",[w("csv"),w("json"),D("Clear",()=>Ke("Clear activity","Removes events from the log on the router.",{},()=>n.reload("logs")),"negative")]),u("chart","Traffic history",e.usage_days?`${Gt(e.usage_days,"day")} since ${Ne(e.usage_since)} · ${St(e.usage_flash)} on flash`:"Empty",[D("Reset",()=>vt("all","","",()=>setTimeout(()=>n.reload("logs"),300)),"negative")]),u("pin","Location cache",`${Gt(n.d.geo_cached,"address","addresses")} · ${St(e.geo_flash)} on flash`,[D("Clear",async()=>{await W(()=>P.geoClear(),"Location cache cleared")&&await n.reload("logs")},"negative")])])],[t("span",{class:"dl-sub"},"Clear one person or device from their own page."),D("Save",()=>n.save({log_keep_days:a.dataset.value,log_max:r.dataset.value,log_persist:i.dataset.value,usage_keep_days:s.dataset.value,usage_keep_months:l.dataset.value,log_category:[...c]},"Saved","logs"),"positive")])}var Hi={manual:"Manual",auto:"Nightly","pre-restore":"Before restore","pre-import":"Before import","pre-delete":"Before removing a server","pre-update":"Before update"},xa=3;function Vn(n){let e=new Date(n*1e3),o=e.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"}),a=Math.round((new Date(new Date().toDateString()).getTime()-new Date(e.toDateString()).getTime())/864e5);return`${a===0?"Today":a===1?"Yesterday":e.toLocaleDateString("en-GB",{day:"numeric",month:"short"})}, ${o}`}async function Ni(n){let e=await W(()=>P.backupRead(n.name));if(!e)return;let o=atob(e.data),a=new Uint8Array(o.length);for(let i=0;iNi(n),"neutral","dl-icon-only"),$e("more","More",o=>we(o.currentTarget,[{label:"Restore",icon:v("reset"),run:async()=>{await re("Restore this backup?",`Everything returns to ${Vn(n.created)}. The current state is backed up first.`,"Restore",!0)&&await W(()=>P.backupRestore(n.name),"Restored")&&e(!0)}},{label:"Delete",icon:v("trash"),danger:!0,run:async()=>{await re("Delete this backup?",`The backup from ${Vn(n.created)} is removed from the router.`,"Delete",!0)&&await W(()=>P.backupDelete(n.name),"Backup deleted")&&e()}}]),"neutral","dl-icon-only")])])}function ya(n,e){let o=n.slice(0,xa).map(c=>wa(c,e)),a=n.slice(xa),r=n.length?t("div",{class:"dl-list"},[...o,a.length?t("details",{class:"dl-bk-older"},[t("summary",{},[v("chevron"),`${a.length} older backup${a.length===1?"":"s"}`]),...a.map(c=>wa(c,e))]):""]):t("div",{class:"dl-list"},[t("div",{class:"dl-row dl-muted"},"No backups yet.")]),i=D("Restore from file",async()=>{let c=await _n(".tar.gz,.tgz,application/gzip","base64");if(!c)return;await re("Restore from file?",`Replace the current Dawnline configuration with ${c.name}? The current state is backed up first.`,"Restore",!0)&&await W(()=>P.backupUpload(c.data),"Restored")&&e(!0)}),s=D("Export JSON",async()=>{let c=await W(()=>P.exportJson());c&&Ee(`dawnline-export-${new Date().toISOString().slice(0,10)}.json`,JSON.stringify(c,null,2),"application/json")}),l=D("Import JSON",async()=>{let c=await _n(".json,application/json","text");if(!c)return;let d;try{d=JSON.parse(c.data)}catch{K("Not a JSON file.","error");return}await re("Import?","This replaces the whole Dawnline configuration on this router. The current state is backed up first.","Import",!0)&&await W(()=>P.importJson(d),"Imported")&&e(!0)});return t("section",{class:"dl-setsec",id:"dl-set-backups"},[t("div",{class:"dl-setsec-body"},[t("div",{class:"dl-setsec-head"},[t("div",{class:"dl-stack"},[t("h3",{},"Backups"),t("span",{class:"dl-sub"},"Nightly when something changed, and before every restore, import or update. The last 10 are kept.")]),t("span",{class:"dl-spacer"}),D([v("plus")," Back up now"],async()=>{await W(()=>P.backupCreate(),"Backup created")&&e()},"positive")]),r]),t("div",{class:"dl-setsec-foot"},[t("span",{class:"dl-sub"},"Backups contain private keys: keep downloads safe. JSON moves everything except usage history to another router."),t("span",{class:"dl-row-actions dl-bk-actions"},[i,s,l])])])}function Ri(){let n=se("",{placeholder:"remove"}),e=D("Remove Dawnline",async()=>{await W(()=>P.uninstall(n.value.trim()),"Dawnline removed")&&(de(),setTimeout(()=>location.reload(),800))},"negative",{disabled:!0});n.addEventListener("input",()=>{e.disabled=n.value.trim()!=="remove"}),ae("Remove Dawnline?",[t("p",{},"Everyone is disconnected and the tunnel, firewall rules and portal are removed. A backup is made first. Type “remove” to confirm."),n],[le()," ",e])}function ka(){return De("danger","Remove Dawnline from this router",[t("p",{class:"dl-muted"},"Deletes the tunnel, firewall rules, access table and hostnames Dawnline created, and stops the service. People and keys are kept in a backup.")],[t("span"),D("Remove",()=>Ri(),"negative")],"danger")}var vn=class{constructor(){this.root=t("div",{class:"dl-settings-main"});this.backups=[];this.portal=null;this.portalSeq=0;this.cards={}}load(){return P.settingsGet()}render(e){this.d=e,this.cards={portal:Xe(()=>ha(this)),defaults:Xe(()=>fa(this)),map:Xe(()=>ga(this)),updates:Xe(()=>va(this)),logs:Xe(()=>ba(this)),backups:Xe(()=>ya(this.backups,r=>this.loadBackups(r))),danger:Xe(()=>ka())};let o=["portal","defaults","map","updates","logs","backups","danger"];dom.content(this.root,o.map(r=>this.cards[r].el)),this.loadBackups().then(()=>{new URLSearchParams(location.search).get("section")==="backups"&&document.getElementById("dl-set-backups")?.scrollIntoView({block:"start"})}),this.loadPortal();let a=new URLSearchParams(location.search).get("section");return a&&a!=="backups"&&requestAnimationFrame(()=>document.getElementById(`dl-set-${a}`)?.scrollIntoView({block:"start"})),t("div",{},[t("div",{class:"dl-pagehead"},[t("h2",{class:"dl-h1"},"Settings")]),this.root])}async save(e,o,a){let r=await W(()=>P.settingsUpdate(e),o);r&&(this.d=r,this.cards[a].refresh(),a==="portal"&&this.loadPortal())}async loadPortal(){let e=++this.portalSeq,o=await P.portalInfo().catch(()=>null);e===this.portalSeq&&(this.portal=o??this.portal??{candidates:[],checks:[]},this.portalFill?.(this.portal))}async loadBackups(e=!1){e&&await this.reload();let o=await P.backupList().catch(()=>null);o&&(this.backups=o.backups,this.cards.backups?.refresh())}async reload(e){let o=await P.settingsGet().catch(()=>null);if(o){if(this.d=o,e)this.cards[e].refresh();else for(let a of Object.values(this.cards))a.refresh();(!e||e==="portal")&&this.loadPortal()}}};function $a(n,e=!1){return n&&(e?/^https?:\/\//i:/^https:\/\//i).test(n)?n:null}function Ea(n){let e=[],o=l=>{let c=[],d=/(`[^`]+`)|(\*\*[^*]+\*\*)|(\[[^\]]+\]\((https?:\/\/[^)\s]+)\))|(https?:\/\/[^\s<>()]+[^\s<>().,;:!?])/g,p=0;for(let u;u=d.exec(l);)u.index>p&&c.push(l.slice(p,u.index)),u[1]?c.push(t("code",{},u[1].slice(1,-1))):u[2]?c.push(t("b",{},u[2].slice(2,-2))):u[3]?c.push(t("a",{href:u[4],target:"_blank",rel:"noopener"},u[3].replace(/^\[|\]\(.*$/g,""))):u[5]&&c.push(t("a",{href:u[5],target:"_blank",rel:"noopener"},u[5].replace(/^https?:\/\/(github\.com\/)?/,""))),p=u.index+u[0].length;return p{r.length&&e.push(t("p",{},o(r.join(" ")))),r=[],a=null};for(let l of n.replace(/\r/g,"").split(` `)){let c=l.trimEnd();if(i){/^```/.test(c.trim())?(e.push(t("pre",{},i.join(` `))),i=null):i.push(l);continue}if(/^```/.test(c.trim())){s(),i=[];continue}let d=/^(#{1,6})\s+(.*)$/.exec(c),p=/^\s*[-*+]\s+(.*)$/.exec(c)??/^\s*\d+[.)]\s+(.*)$/.exec(c);d?(s(),e.push(t("h5",{},o(d[2])))):p?(r.length&&s(),a||(a=t("ul",{}),e.push(a)),a.appendChild(t("li",{},o(p[1])))):c.trim()?(a&&(a=null),r.push(c.trim())):s()}return i&&e.push(t("pre",{},i.join(` -`))),s(),e}function Ea(n){let e=[],o=!1;for(let a of n.replace(/\r/g,"").split(` +`))),s(),e}function La(n){let e=[],o=!1;for(let a of n.replace(/\r/g,"").split(` `)){let r=/^#{1,6}\s+(.*)$/.exec(a);if(r){if(o=/^install\b/i.test(r[1].trim()),/^what.s new$/i.test(r[1].trim()))continue}else/^\*\*Full Changelog\*\*/.test(a)&&(o=!1);o||e.push(a)}return e.join(` `).replace(/\n{3,}/g,` -`).trim()}async function jt(n,e,o,a){let r=t("div",{class:"dl-notes"},t("p",{class:"dl-muted dl-loading"},"Loading release notes…")),i=t("div",{class:"dl-op-head"}),s="";re(o,[i,r],[D([v("copy")," Copy"],()=>ue(s,"Release notes copied"))," ",le("Close")],"wide");try{let l=await P.updatesNotes(n,e,a??"");s=Ea(l.body||"");let c=ka(l.url);dom.content(i,[l.published?t("span",{class:"dl-pill"},Ne(l.published)):"",l.prerelease?t("span",{class:"dl-pill warn"},"Pre-release"):"",t("span",{class:"dl-spacer"}),c?t("a",{href:c,target:"_blank",rel:"noopener",class:"dl-linkbtn"},["On GitHub ",v("open")]):""]),dom.content(r,s.trim()?$a(s):t("p",{class:"dl-muted"},"This release has no notes."))}catch(l){dom.content(r,t("p",{class:"dl-muted"},ve(l)))}}var La={"6h":"every 6 h","12h":"every 12 h","1d":"daily","7d":"weekly"},Yn=n=>n?Ne(n):"";function Ri(n){let e=/^(.{20,}?)(?:;\s|:\s)/.exec(n)?.[1];return e||(n.length<=90?n:`${n.slice(0,90).replace(/[\s,;:]+\S*$/,"")}…`)}function Sa(n,e){let o=n.st,a=o.policy,r=o.kept?.app,i=e?.update&&e.tag?e.tag:o.version,s=w=>()=>jt("app",w,`What’s new in Dawnline ${w.replace(/^v/,"")}`),l=e?.tag&&(e.update||e.status==="latest")?Ii(n,e.tag,e.update?o.version:""):null,c=e?.tag??i,d=a.check&&o.auto?.check?o.auto.check+({"6h":6,"12h":12,"1d":24,"7d":168}[a.interval]??24)*3600:0,p=(w,g)=>t("div",{class:"dl-stack gap4"},[t("span",{class:"dl-metric-label"},w),t("span",{class:"dl-comp-side-v"},g)]),u=[{label:"What’s new",ic:"file",run:s(i)},{label:"Open on GitHub",ic:"globe",run:()=>window.open(`https://github.com/${o.repo}`,"_blank","noopener")},null,{label:`Reinstall ${o.version}`,ic:"reset",warn:!0,run:()=>n.op("app:reinstall","Reinstalling Dawnline",o.version)},r?{label:`Roll back to ${r.version}`,ic:"archive",warn:!0,run:async()=>{await ae(`Roll back to Dawnline ${r.version}?`,`The copy kept on the router replaces ${o.version}. A backup of the settings is made first.`,"Roll back")&&n.op("app:rollback","Rolling back Dawnline",o.version)}}:null];return t("section",{class:"dl-panel flush dl-comp-hero"},[t("div",{class:"dl-comp-hero-main"},[t("div",{class:"dl-comp-hero-head"},[t("span",{class:"dl-group-ic"},v("sunrise")),t("b",{class:"dl-comp-name"},"Dawnline"),n.state("app",e,e?.latest??""),t("span",{class:"dl-spacer"}),n.round(()=>n.op("check:app","Checking Dawnline",o.version),u,!0)]),t("div",{class:"dl-comp-verrow"},[t("div",{class:"dl-stack"},[t("div",{class:"dl-comp-big"},[o.version,e?.update?t("small",{},`→ ${e.latest}`):e?.status==="dev"&&e.latest?t("small",{class:"dl-faint"},`release ${e.latest}`):""]),t("span",{class:"dl-faint dl-comp-meta"},e?.error?"":e?.update?e.published?`released ${Yn(e.published)}`:"":e?.status==="dev"?"ahead of the latest release":e?`latest release${e.published?` · released ${Yn(e.published)}`:""}`:"not checked yet")])]),l?.items.length?t("div",{class:"dl-stack gap4"},[t("ul",{class:"dl-comp-bullets"},l.items.map(w=>t("li",{},w))),l.total>l.items.length?t("button",{type:"button",class:"dl-linkbtn dl-comp-more",click:s(c)},`+${l.total-l.items.length} more in What’s new`):""]):"",e?.error?t("p",{class:"dl-sub dl-comp-lead dl-upd-bad"},e.error):"",e?.update?t("div",{class:"dl-comp-btns"},[D("Update now",()=>n.op("app","Updating Dawnline",o.version),"positive",{disabled:n.busy}),D("What’s new",s(i))]):"",Bi(n)]),t("div",{class:"dl-comp-hero-side"},[p("Source",[v("globe"),t("a",{href:`https://github.com/${o.repo}`,target:"_blank",rel:"noopener"},o.repo)]),p("Auto-update",[a.auto?ye("ok","On"):ye("","Off"),t("span",{class:"dl-muted"},a.auto?a.mode==="immediate"?"as soon as found":`${La[a.interval]==="weekly"?"weekly":"daily"} at ${a.time}`:a.check?`checks ${La[a.interval]}`:"checks off")]),p("Last check",o.check?[ie(o.check.time,o.now),d>o.now?t("span",{class:"dl-faint"},`· next in ${pt(d-o.now)}`):""]:["Never"]),p("Rollback",r?[t("span",{class:"dl-mono"},r.version),t("span",{class:"dl-faint"},"kept on flash")]:[t("span",{class:"dl-muted"},a.keep?"Kept after the next update":"Off")])])])}function Ii(n,e,o){if(n.notes.has(e))return n.notes.get(e)??null;n.notes.set(e,null);let a=r=>r.replace(/\*\*|`|\[([^\]]+)\]\([^)]*\)/g,(i,s)=>s??"").trim();return(async()=>{let i=((await P.updatesNotes("app",e,"").catch(()=>null))?.body??"").split(` -`).map(l=>/^\s*[-*+]\s+(.*)$/.exec(l)?.[1]).filter(l=>!!l);i.length||(i=(await P.updatesChanges(o,e).catch(()=>null))?.items??[]);let s={items:i.slice(0,3).map(l=>Ri(a(l))),total:i.length};n.notes.set(e,s),s.items.length&&n.root.isConnected&&n.paint()})(),null}function Bi(n){let e=t("div",{class:"dl-params-body"}),o=t("details",{class:"dl-params dl-comp-vers",open:n.versOpen?"open":null},[t("summary",{},[v("chevron"),t("span",{},"Versions"),t("span",{class:"dl-sub"},"install any release")]),e]);return o.addEventListener("toggle",()=>{n.versOpen=o.open,n.versOpen&&bn(n,e)}),n.versOpen&&bn(n,e),o}async function bn(n,e){let o=se("",{placeholder:"Tag, e.g. 0.3.1",class:"cbi-input-text dl-mono","aria-label":"Release tag"}),a=p=>{if(p=p.trim(),!/^v?[0-9][0-9A-Za-z.+~-]{0,40}$/.test(p))return Z("Enter a release tag like 0.3.1","warning");Ma(n,p)};o.addEventListener("keydown",p=>{p.key==="Enter"&&(p.preventDefault(),a(o.value))});let r=t("div",{class:"dl-comp-tag"},[o,D("Install",()=>a(o.value),"neutral",{disabled:n.busy})]),i=n.versPage,s=p=>{n.versPage=Math.max(1,n.versPage+p),bn(n,e)},l=p=>t("div",{class:"dl-comp-pager"},[t("button",{type:"button",class:"dl-linkbtn",disabled:i<=1?"disabled":null,click:()=>s(-1)},"← Newer"),t("span",{class:"dl-faint"},`Page ${i}`),t("button",{type:"button",class:"dl-linkbtn",disabled:p?null:"disabled",click:()=>s(1)},"Older →")]),c=n.versCache.get(i);if(!c){dom.content(e,[r,t("p",{class:"dl-muted dl-loading"},"Loading versions…")]);try{c=(await P.updatesReleases(i)).releases}catch(p){if(i!==n.versPage||!e.isConnected)return;dom.content(e,[r,t("div",{class:"dl-row-actions"},[t("span",{class:"dl-muted"},`Failed to load versions: ${ve(p)}`),D("Try again",()=>bn(n,e))]),l(!1)]);return}if(n.versCache.set(i,c),i!==n.versPage||!e.isConnected)return}if(!c.length)return dom.content(e,[r,t("p",{class:"dl-muted"},i>1?"No more versions.":"No versions found."),l(!1)]);let d=n.st.version;dom.content(e,[r,...c.map(p=>{let u=p.tag.replace(/^v/,"");return t("div",{class:"dl-comp-ver"},[t("span",{class:"dl-mono"},u),t("span",{class:"dl-sub"},Yn(p.published)),p.prerelease?ye("warn","Pre-release"):"",t("span",{class:"dl-comp-ic"},$e("file","What’s new",()=>jt("app",p.tag,`What’s new in Dawnline ${u}`))),u===d?ye("ok","Installed"):D("Install",()=>Ma(n,p.tag),"neutral",{disabled:n.busy})])}),l(c.length>=5)])}async function Ma(n,e){let o=e.replace(/^v/,"");o.localeCompare(n.st.version,void 0,{numeric:!0})<0&&!await ae(`Install Dawnline ${o}?`,`It is older than ${n.st.version}. A backup of the settings is made first; restore it from Settings if something looks wrong.`,"Install")||n.op(`app@${e}`,`Installing Dawnline ${o}`,n.st.version)}function _a(n,e){let o=n.st,a=o.kept?.amneziawg,r=e?.sources??{},i=Object.keys(r),s=e?.current??null,l=s?r[s]:void 0,c=!!e?.ru,d=o.needs?.awg??[],p=d.length?null:e?.installed??null,u=[];s&&p&&u.push({label:"Reinstall this build",warn:!0,ic:"reset",run:()=>n.op(`amneziawg:${s}${c?":ru":""}`,"Reinstalling AmneziaWG",p)}),a&&u.push({label:`Roll back to ${a.version}`,ic:"archive",warn:!0,run:async()=>{await ae(`Roll back AmneziaWG to ${a.version}?`,"The build kept on the router is installed again. Every AmneziaWG tunnel restarts for a few seconds.","Roll back")&&n.op("amneziawg:rollback","Rolling back AmneziaWG",p??void 0)}});let w=[e?.release?{label:"What’s new",ic:"file",run:()=>jt("amneziawg",e.release,`What’s new in the ${l?.label??"AmneziaWG"} build`,s??"slava")}:null,{label:"Open on GitHub",ic:"globe",run:()=>window.open(`https://github.com/${l?.repo??"Slava-Shchipunov/awg-openwrt"}`,"_blank","noopener")},...u.length?[null,...u]:[]].filter((h,f,R)=>h!==null||f>0&&R[f-1]!==null),g=o.tunnels??[],m=g.length?`Switching restarts ${g.length===1?"the tunnel":`${g.length} tunnels`} for a few seconds: ${g.join(", ")}. Devices keep their configurations.`:"Switching takes a few seconds. Devices keep their configurations.",k=g.length>1?`${g.slice(0,-1).join(", ")} and ${g[g.length-1]}`:g[0],H=g.length?`Switching restarts ${k} for a few seconds.`:"Switching takes a few seconds.",B=async h=>{let f=r[h];await ae(p?`Switch to AmneziaWG ${f.gen}?`:`Install AmneziaWG ${f.gen}?`,`The ${f.label} build, ${f.version}. ${m}${f.gen==="3.1"?" Devices need AmneziaVPN 3.1 or newer.":""}`,p?"Switch":"Install")&&n.op(`amneziawg:${h}${c?":ru":""}`,p?`Switching to AmneziaWG ${f.gen}`:"Installing AmneziaWG",p??void 0)},E=h=>{let f=r[h],R=s===h&&!!p;return t("div",{class:"dl-row"},[t("span",{class:"dl-row-main dl-stack"},[t("b",{},f.gen?`AmneziaWG ${f.gen}`:"AmneziaWG"),t("span",{class:"dl-sub"},`${f.label} · ${f.gen==="3.1"?"AmneziaVPN 3.1+":"every app"}`)]),t("span",{class:"dl-mono dl-faint dl-comp-bver"},f.version??"none yet"),t("span",{class:"dl-comp-bact"},R?ye("ok","Active"):f.version?D(p?"Switch":"Install",()=>B(h),p?"neutral":"positive",{disabled:n.busy}):ye("","No build"))])},y=i.map(h=>r[h]?.newer?`${r[h].label} moves to ${r[h].newer.gen} with OpenWrt ${r[h].newer.tag.replace(/^v/,"")}.`:"").filter(Boolean),S=ge(c,"Russian translation",h=>{s&&n.op(`amneziawg:${s}${h?":ru":""}`,h?"Adding the Russian translation":"Removing the Russian translation",p??void 0)});S.disabled=!s||!p||n.busy;let b=n.awgOpen??!p,x=t("details",{class:"dl-params dl-comp-fold",open:b?"open":null},[t("summary",{},[v("chevron"),t("span",{},"Build and translation")]),t("div",{class:"dl-params-body"},[t("div",{class:"dl-list"},[...i.length?i.map(E):[t("div",{class:"dl-row"},t("span",{class:"dl-sub"},"Check for updates to see the builds for this router."))],t("div",{class:"dl-row"},[t("span",{class:"dl-row-main dl-stack"},[t("b",{},"Russian translation"),t("span",{class:"dl-sub"},"LuCI pages for AmneziaWG")]),t("span",{class:"dl-comp-bact"},S)])]),p&&i.length||y.length?t("div",{class:`dl-comp-status ${p&&i.length?"warn":"acc"}`},[v(p&&i.length?"alert":"download"),t("span",{},[p&&i.length?t("b",{},H):"",...y.map(h=>` ${h}`)])]):""])]);x.addEventListener("toggle",()=>n.awgOpen=x.open);let M=[];return e?.update&&p&&s?M.push(D(`Update to ${e.latest}`,()=>n.op(`amneziawg:${s}${c?":ru":""}`,"Updating AmneziaWG",p),"neutral",{disabled:n.busy})):M.push((e||d.length)&&!p?ye("warn","Not installed"):n.state("amneziawg",e,e?.latest??"")),M.push(n.round(()=>n.op("check:amneziawg","Checking AmneziaWG",p??void 0),w)),[n.row("shield","AmneziaWG",[p?`${p}${e?.release?` · ${e.release} build`:""}`:d.length?`missing ${d.join(", ")}`:e?"not installed":"version not checked"],M),t("div",{class:"dl-comp-foldwrap"},x)]}var Oi=[{title:"Home-like link",sub:"Policy routing and the veth pair",pkgs:["ip-full","kmod-veth"],feature:"home"},{title:"HTTPS for the portal",sub:"OpenSSL for uhttpd",pkgs:["libustream-openssl","openssl-util"],feature:"https"},{title:"Certificates (ACME)",sub:"Let’s Encrypt certificate for the portal",pkgs:["acme","acme-acmesh-dnsapi"],feature:"acme",optional:!0}],Zn={home:"network",https:"lock",acme:"file"};function Ta(n,e){let o=n.st,a=e?.pkgs??{},r=Oi.filter(d=>d.feature==="home"?o.home:o.portal),i=async(d,p,u=d)=>{await ae(`Update ${p}?`,`${u.join(", ")} from the OpenWrt feeds. Services that use them restart for a moment.`,"Update")&&n.op(`pkgs:${d.join(",")}`,`Updating ${p}`)},s=[{label:"Check system packages",ic:"refresh",run:()=>n.op("check:packages","Checking system packages")},{label:"Open the OpenWrt package list",ic:"globe",run:()=>window.open("https://openwrt.org/packages/start","_blank","noopener")}],l=0;return{rows:r.map(d=>{let p=d.pkgs.filter(k=>a[k]?.installed),u=[...new Set(p.flatMap(k=>[...a[k]?.latest?[k]:[],...a[k]?.with??[]]))],w=o.needs?.[d.feature]??d.pkgs.filter(k=>!a[k]?.installed),g=p.find(k=>a[k]?.latest),m=p.map(k=>`${k} ${a[k]?.installed??""}`).join(", ");return w.length?n.row(Zn[d.feature],d.title,[`${d.optional?"not installed":`missing ${w.join(", ")}`}`],[D("Install",()=>n.op(`pkgs:${w.join(",")}`,`Installing ${d.title}`),d.optional?"neutral":"positive",{disabled:n.busy}),t("span",{class:"dl-comp-ic"},n.more(s))]):e&&u.length?(l++,n.row(Zn[d.feature],d.title,g?[`${a[g].installed} → ${a[g].latest}`,u.length>1?` · +${u.length-1}`:""]:[u.join(", ")],[D("Update",()=>i(p.filter(k=>a[k]?.latest||a[k]?.with?.length),d.title,u),"neutral",{disabled:n.busy}),t("span",{class:"dl-comp-ic"},n.more(s))])):n.row(Zn[d.feature],d.title,[m||d.sub],[n.state("pkgs",e,""),t("span",{class:"dl-comp-ic"},n.more(s))])}),updates:l,total:r.length}}var ji={app:"Dawnline",amneziawg:"AmneziaWG",pkgs:"System packages",all:"Components"};function Ca(n){let e=n.st,o=r=>{let i=Ze(r.component??"app"),s=ji[i]??"Components",l=r.auto?"automatically":"by you",c="ok",d="check",p;if(r.kind==="found")c="accent",d="download",p=[t("b",{},(r.items??[]).join(", ")),` found by ${r.auto?"the automatic check":"a check"}`];else if(r.state==="failed")c="bad",d="x",p=[t("b",{},s),` ${r.kind==="install"?"update":"check"} failed${r.error?` · ${r.error}`:""}`];else{let u=r.from&&r.to&&r.from!==r.to?` ${r.from} → ${r.to}`:r.to?` ${r.to}`:"";p=[t("b",{},s),`${u} ${u?"":"updated "}${l}${r.took?` · ${pt(r.took)}`:""}`.replace(/\s+/g," ")]}return t("div",{class:"dl-row"},[t("span",{class:`dl-ev-tile ev ${c}`},v(d)),t("span",{class:"dl-row-main"},p),t("span",{class:"dl-faint dl-nowrap",title:new Date(r.ts*1e3).toLocaleString()},ie(r.ts,e.now))])},a=e.history??[];return t("section",{class:"dl-panel flush"},[t("div",{class:"dl-panel-head pad"},[t("h3",{},"Activity"),t("span",{class:"dl-spacer"}),t("a",{href:`${L.url("admin/network/dawnline/diagnostics")}?tab=log`},"All in Log →")]),a.length?t("div",{},a.slice(0,8).map(o)):t("p",{class:"dl-sub dl-comp-empty"},"Updates, and checks that found something, show up here.")])}var xn=class{constructor(){this.root=t("div",{class:"dl-upd"});this.following=null;this.versOpen=!1;this.versPage=1;this.versCache=new Map;this.notes=new Map;this.awgOpen=null}load(){return P.updatesStatus()}render(e){return this.st=e,this.paint(),e.job?.state==="running"&&this.follow(e.job),poll.add(async()=>{if(!this.root.isConnected)return;let o=await P.updatesStatus().catch(()=>null);if(!o)return;let a=this.st;this.st=o,o.job?.state==="running"&&this.following!=="starting"&&o.job.id!==this.following&&this.follow(o.job),(o.job?.id!==a.job?.id||o.job?.state!==a.job?.state||o.job?.phase!==a.job?.phase||o.check?.time!==a.check?.time)&&this.paint()},5),this.root}get busy(){return this.st.job?.state==="running"}async refresh(e){this.st=e??await P.updatesStatus().catch(()=>null)??this.st,this.paint()}async op(e,o,a){if(this.busy||this.following==="starting"){Z("Another component action is already running","warning");return}this.following="starting",this.paint();let r=Ze(e),i=await It(e,{title:o,version:a,onJob:s=>this.following=s.id,onDone:s=>this.refresh(s),onUpdate:s=>{let l=s.check?.components??{};r==="amneziawg"&&l.amneziawg?.current?this.op(`amneziawg:${l.amneziawg.current}${l.amneziawg.ru?":ru":""}`,"Updating AmneziaWG",l.amneziawg.installed??void 0):this.op("app","Updating Dawnline",this.st.version)}});this.following==="starting"&&(this.following=i?.id??null),this.refresh()}async follow(e){this.following=e.id;let o=cn(e),a={app:"Dawnline",amneziawg:"AmneziaWG",pkgs:"system packages",all:"components"}[o]??"components";await It(null,{title:`${e.action==="check"?"Checking":e.auto?"Automatic update:":"Updating"} ${a}`,onDone:r=>this.refresh(r)},e)}paint(){let e=this.st,o=e.check?.components??{},a=e.firmware,r=Ta(this,o.packages),i=(e.needs?.awg??[]).length>0,l=(!i&&o.amneziawg?.update&&o.amneziawg.installed?1:0)+r.updates;dom.content(this.root,[t("div",{class:"dl-pagehead"},[t("div",{class:"dl-stack"},[t("h2",{class:"dl-h1"},"Components"),t("span",{class:"dl-faint"},[a?.version?`OpenWrt ${a.version} · ${a.target}`:"",e.check?`checked ${ie(e.check.time,e.now)}`:"not checked yet"].filter(Boolean).join(" · "))]),t("div",{class:"dl-row-actions"},[t("a",{class:"cbi-button cbi-button-neutral dl-icon-btn",href:`${L.url("admin/network/dawnline/settings")}?section=updates`},[v("edit")," Settings"]),D([v("refresh")," Check all"],()=>this.op("check","Checking all components"),"neutral",{disabled:this.busy})])]),Sa(this,o.app),t("div",{class:"dl-comp-cols"},[t("section",{class:"dl-panel flush"},[t("div",{class:"dl-panel-head pad"},[t("h3",{},"Components"),t("span",{class:"dl-spacer"}),t("span",{class:"dl-faint dl-comp-count"},i?l?`AmneziaWG not installed · ${l} update${l===1?"":"s"}`:"AmneziaWG not installed":!o.amneziawg&&!o.packages?"":l?`${l} of ${1+r.total} need${l===1?"s":""} an update`:"Everything is up to date")]),t("div",{},[..._a(this,o.amneziawg),...r.rows])]),Ca(this)])])}state(e,o,a){let r=this.st.job;if(r?.state==="running"){let i=l=>l==="packages"?"pkgs":l,s=r.action==="check"?[i(r.component||"all")]:(r.component??"").split(" ").map(l=>i(Ze(l)));if(s.includes(e)||s.includes("all"))return t("button",{type:"button",class:"dl-pill info dl-comp-run",title:"Show progress",click:()=>this.follow(r)},[r.action==="check"?"Checking":"Updating","…"])}return o?o.error?ye("warn","Check failed",o.error):o.update?ye("info","Update available"):o.status==="dev"?ye("info","Newer than release",`The latest release is ${a}`):ye("ok","Up to date"):ye("","Not checked")}more(e){let o=D([v("more")],()=>we(o,e.filter((a,r,i)=>a!==null||r>0&&ra?{label:a.label,icon:v(a.ic),warn:a.warn,run:a.run}:null)),"neutral",{title:"More","aria-label":"More"});return o}round(e,o,a=!1){let r=this.busy?" is-busy":"",i;return a?i=D([v("refresh")," Check"],e,"neutral",{class:`cbi-button cbi-button-neutral dl-comp-check${r}`,"aria-label":"Check for updates"}):(i=$e("refresh","Check for updates",e,"neutral",r.trim()),i.removeAttribute("title"),i.setAttribute("aria-label","Check for updates"),me(i,()=>["Check for updates"])),t("span",{class:"dl-comp-ic"},[i,this.more(o)])}row(e,o,a,r){return t("div",{class:"dl-row"},[t("span",{class:"dl-group-ic"},v(e)),t("span",{class:"dl-row-main dl-stack"},[t("b",{},o),t("span",{class:"dl-mono dl-faint dl-comp-sub"},a)]),...r])}};var Pa=(n,e)=>t("div",{class:"cbi-value"},[t("label",{class:"cbi-value-title"},n),t("div",{class:"cbi-value-field"},e)]);function Da(n){let e=n.st.servers.find(o=>o.id===n.p.server)?.name??"Home";Ht(n.p,e)}async function Aa(n){let e=n.p;if(!await ae("Create a new link?","The old link stops working right away.","Create new link",!0))return;let o=await W(()=>P.personRegen(e.id),"New link created");o?.link&&await ue(o.link,"New link copied")}function Qn(n){let e=t("textarea",{class:"cbi-input-textarea dl-note-input",rows:3,maxlength:500,placeholder:"Only you see this"},n.p.note??"");re("Note",[e],[le()," ",D("Save",async()=>{ce(),await n.patch({note:e.value.trim()},e.value.trim()?"Note saved":"Note removed")},"positive")]),setTimeout(()=>e.focus(),50)}function za(n){let e=n.p,o=t("select",{class:"cbi-input-select"},[t("option",{value:"pause",selected:e.expire_action==="pause"?"selected":null},"Pause access"),t("option",{value:"notify",selected:e.expire_action==="notify"?"selected":null},"Keep access"),t("option",{value:"remove",selected:e.expire_action==="remove"?"selected":null},"Remove their devices")]),a=t("select",{class:"cbi-input-select"},[0,1,3,7,14].map(r=>t("option",{value:r,selected:e.expire_warn===r?"selected":null},r?`${r} day${r===1?"":"s"} before`:"Don’t warn")));re("When access ends",[Pa("Then",o),t("div",{class:"cbi-value"},[t("label",{class:"cbi-value-title"},"Warn"),t("div",{class:"cbi-value-field"},[a,t("div",{class:"cbi-value-description"},"Shown in their portal and on the Overview.")])])],[le()," ",D("Save",async()=>{ce(),await n.patch({expire_action:o.value,expire_warn:a.value},"Saved")},"positive")])}function Ha(n){let e=t("input",{type:"text",class:"cbi-input-text",value:n.p.name,maxlength:48});re("Rename",[Pa("Name",e)],[le()," ",D("Save",async()=>{await n.patch({name:e.value.trim()},"Renamed")&&ce()},"positive")]),setTimeout(()=>e.select(),50)}async function Na(n){let e=n.p;await ae(`Delete ${e.name}?`,`All ${e.devices.length} devices are disconnected immediately and the personal link stops working.`,"Delete",!0)&&await W(()=>P.personDelete(e.id),"Deleted")&&(location.href=wt(e.server))}function Ra(n){let e=n.p,o=n.st,a=e.online?"online now":e.last_seen?`last seen ${ie(e.last_seen,o.now)}`:"never connected",r=e.created?`Added ${Te(He(new Date(e.created*1e3)))}`:"",i=e.has_link??o.settings.portal_enabled,s=[{label:"Rename",icon:v("edit"),run:()=>Ha(n)},{label:e.note?"Edit note":"Add note",icon:v("file"),run:()=>Qn(n)},...i?[null,{label:"Invite card",icon:v("qr"),run:()=>Da(n)},{label:"New link",icon:v("key"),run:()=>Aa(n)}]:[],null,...e.paused?[]:[{label:"Pause",icon:v("pause"),warn:!0,run:()=>n.patch({paused:!0},"Paused")}],{label:"Delete",icon:v("trash"),danger:!0,run:()=>Na(n)}];return t("div",{class:"dl-person-head"},[t("div",{class:"dl-pagehead"},[t("div",{class:"dl-person-id"},[t("span",{class:`dl-avatar lg${e.online?" online":""}`},Ce(e.name)),t("div",{class:"dl-stack"},[t("div",{class:"dl-title-row"},[t("h2",{class:"dl-h1"},e.name),co(e)]),t("span",{class:"dl-faint",title:r},`${e.devices.length} of ${e.device_limit} devices · ${a}`)])]),t("div",{class:"dl-pcard-actions"},[e.paused?D([v("play")," Resume"],()=>n.patch({paused:!1},"Resumed"),"add"):"",i?$e("link","Copy link",()=>an(e.id),"neutral","dl-icon-only"):"",$e("more","More",l=>we(l.currentTarget,s),"neutral","dl-icon-only")])]),e.note?t("button",{type:"button",class:"dl-pnote",title:"Edit note",click:()=>Qn(n)},[v("file"),t("span",{},e.note)]):""])}function Ia(n){let e=n.p,o=n.series[n.series.length-1];return t("div",{class:`dl-person-live${e.online?"":" solo"}`},[e.online?mn(e.rate??[],n.st.now,o?[o.rx,o.tx]:[0,0]):"",hn(n.series,`${te(e.month[0]+e.month[1])} this month`)])}async function Ui(n,e){let o=await W(()=>P.deviceConfig(e.id));o&&re(`Set up ${e.name}`,[await n.core.connectBlock(o,"qr")],[le("Close")])}async function Wi(n,e){let o=await W(()=>P.deviceConfig(e.id));if(!o)return;if(!o.has_private_key){Z("This device made its own keys in the browser; its configuration only exists there.","warning");return}let a=n.core.file.make(o);Ee(a.name,a.text,"application/octet-stream")}function Ba(n){let e=n.p,o=n.st.now,a=c=>Be(e,c,n.deviceOpts()),r=c=>d=>{d.target.closest("button:not(.dl-dcard-title), a")||a(c)},i=c=>D([v("more")],d=>Bo(d.currentTarget,e,c,n.deviceOpts()),"neutral",{title:"QR, file, key, rename, new keys, remove",class:"cbi-button cbi-button-neutral dl-icon-only"}),s=Ft(e.devices).map(c=>{let d=t("div",{class:"dl-dcard-head"},[t("span",{class:"dl-dcard-ic"},v(c.kind)),t("button",{type:"button",class:"dl-dcard-title",click:()=>a(c)},[t("b",{},c.name),qt(c,o),c.config_stale?t("span",{class:"dl-pill warn dl-stale"},"Update config"):""]),i(c)]),p=t("div",{class:"dl-dcard-trend"},[t("div",{class:"dl-stack"},[t("b",{},te(c.month[0]+c.month[1])),t("span",{class:"dl-sub"},"this month")]),la(n.devSeries[c.id]??[])]);return t("article",{class:`dl-dcard clickable${c.online?" online":""}${c.disabled?" off":""}`,click:r(c)},[d,c.handshake?p:c.disabled?t("div",{class:"dl-sub"},`${je[c.kind]} · created ${ie(c.created,o)} ${c.created_by==="portal"?"in the portal":"by you"}.`):t("div",{class:"dl-chips-row"},[t("button",{type:"button",class:"dl-chipbtn",click:()=>Ui(n,c)},[v("qr"),"Show QR"]),t("button",{type:"button",class:"dl-chipbtn",click:()=>Wi(n,c)},[v("download"),"Config"])])])}),l=e.devices.length>=e.device_limit;return s.push(t("button",{type:"button",class:"dl-dslot add",click:()=>it(e,n.deviceOpts())},[t("span",{class:"dl-dslot-ic"},v("plus")),t("span",{class:"dl-stack"},[t("b",{},"Add device"),t("span",{class:"dl-sub"},l?`Over the limit · ${e.devices.length} of ${e.device_limit}`:`${e.devices.length} of ${e.device_limit}`)])])),t("section",{class:"dl-devsec"},[t("div",{class:"dl-panel-head"},[t("h3",{},"Devices"),t("span",{class:"dl-sub"},`${e.online} online`)]),t("div",{class:"dl-dgrid"},s)])}function Oa(n){let e=n.p,o=xe([["device","Device’s own DNS"],["home","Home names"]],e.dns_mode,{label:"DNS",cls:"sm",optimistic:!1,onChange:r=>n.patch({dns_mode:r},r==="home"?"Home names on — devices need their configuration again":"Device DNS — devices need their configuration again")}),a=n.st.settings.home_dns_fallback;return t("div",{class:"dl-stack gap4 dl-dnspick"},[t("div",{class:"dl-row-actions"},[t("span",{class:"dl-sub"},"DNS"),o]),t("span",{class:"dl-sub"},e.dns_mode==="home"?["Names like ",t("span",{class:"dl-mono"},`nas.${n.st.settings.domain}`)," work. Internet names are resolved at home, so they depend on the tunnel",a?[" (",t("span",{class:"dl-mono"},a)," takes over when it is down)."]:" — with no fallback set, they stop when it is down."]:"Internet keeps working exactly as without the VPN. Reach home devices by IP address.")])}function ja(n){let e=n.p,a=n.st.servers.find(i=>i.id===e.server)?.home??[];if(a.length<2)return"";let r=new Set(e.home_nets?.length?e.home_nets:a.map(i=>i.dev));return t("div",{class:"dl-stack gap4"},[t("div",{class:"dl-chips-row"},a.map(i=>We(i.dev,r.has(i.dev),()=>{let s=new Set(r);if(s.delete(i.dev)||s.add(i.dev),!s.size)return Z("Keep at least one network, or choose Internet only.","warning",5e3);let l=s.size===a.length?[]:[...s];n.patch({home_nets:l},l.length?`${e.name} reaches ${l.join(", ")}`:`${e.name} reaches every home network`)},{title:i.nets.join(", ")}))),t("span",{class:"dl-sub"},e.home_nets?.length?`Home networks ${e.name} reaches. Networks added to the server later stay out.`:`Home networks ${e.name} reaches: all of them. Untick one to keep ${e.name} out of it.`)])}function Ua(n){let e=new Set(n.p.services??[]);return t("div",{class:"dl-stack gap4"},[t("div",{class:"dl-chips-row"},n.st.services.map(o=>We(o.name,e.has(o.id),()=>{let a=new Set(e);a.delete(o.id)||a.add(o.id),n.patch({services:[...a]},a.size?"Home services updated":"Whole home network")},{title:`${o.address}${o.ports.length?` · ${o.ports.join(", ")}`:""}`}))),t("span",{class:"dl-sub"},e.size?"Only the selected services at home.":"Whole home network. Pick services to narrow it down.")])}function Wa(n){let e=n.p,o=n.st;if(o.servers.find(d=>d.id===e.server)?.mesh!=="circles"||!Ye(e))return"";let r=o.circles.filter(d=>d.server===e.server),i=r.find(d=>d.id===e.circle),s=i?o.people.filter(d=>d.id!==e.id&&d.circle===i.id&&Ye(d)).map(d=>d.name):[],l=t("button",{type:"button",class:"dl-chipbtn",click:()=>we(l,[...r.map(d=>({label:d.name,icon:Gn(d),run:()=>d.id!==e.circle&&n.patch({circle:d.id},`${e.name} is in ${d.name}`)})),e.circle?{label:"No circle",icon:v("x"),run:()=>n.patch({circle:""},`${e.name} is in no circle`)}:null,{label:"New circle",icon:v("plus"),run:()=>ln(o,e.server,null,()=>n.refresh())}])},"Change"),c=i?o.people.filter(d=>d.circle===i.id&&Ye(d)):[e];return t("div",{class:"dl-tile2"},[t("div",{class:"dl-tile2-label"},[t("span",{},"Devices see each other"),l]),t("div",{class:"dl-tile2-row"},[t("span",{class:"dl-tile2-value"},i?i.name:"No circle"),t("span",{class:"dl-avstack",title:c.map(d=>d.name).join(", ")},c.slice(0,5).map(d=>t("span",{class:"dl-avatar sm"},Ce(d.name))))]),t("span",{class:"dl-sub"},i?s.length?[e.name,...s].join(", "):`Nobody else in ${i.name} yet`:`Only ${e.name}'s own devices`)])}function Ga(n){let e=n.p,o=n.st.now,a=t("div",{class:"dl-slots"});for(let s=0;s=e.device_limit,d=t("i",{class:c?"over":l?"used":""});me(d,()=>[t("div",{class:"dl-tip-title"},l?`${l.name}${c?" · over the limit":""}`:"Free slot"),t("div",{class:"dl-muted"},l?l.online?"Connected":l.handshake?`Last seen ${ie(l.handshake,o)}`:"Not set up yet":"They can add a device here")]),a.appendChild(d)}let r=Math.max(1,e.devices.length),i=t("button",{type:"button","aria-label":"Allow fewer devices",disabled:e.device_limit<=r?"disabled":null,click:()=>n.patch({device_limit:String(e.device_limit-1)})},"−");return e.device_limit<=r&&e.devices.length>1&&me(i,()=>[t("div",{class:"dl-tip-title"},`${e.devices.length} devices in use`),t("div",{class:"dl-muted"},"Remove a device first to lower the limit")]),t("div",{class:"dl-tile2"},[t("div",{class:"dl-tile2-label"},"Devices"),t("div",{class:"dl-tile2-row"},[t("span",{class:"dl-tile2-value"},[String(e.devices.length),t("span",{class:"dl-faint"},` / ${e.device_limit}`)]),t("div",{class:"dl-stepper"},[i,t("button",{type:"button","aria-label":"Allow more devices",disabled:e.device_limit>=32?"disabled":null,click:()=>n.patch({device_limit:String(e.device_limit+1)})},"+")])]),a])}var Gi={internet:"Browse the internet through your router. No access to devices at home, and home cannot reach theirs.",lan:"Reach devices at home, and home reaches theirs. Internet stays on their own connection.",both:"Home devices and the internet, all through your router. Home reaches their devices too."},Fa=/^([01]\d|2[0-3]):[0-5]\d$/;function Fi(n){let e=n.p,o=n.today,a=nt(e.expires,o),r=t("input",{type:"date",class:"dl-date-hidden",value:e.expires,tabindex:"-1","aria-hidden":"true"});r.addEventListener("change",()=>r.value&&n.patch({expires:r.value},`Access until ${Te(r.value)}`));let i=(d,p)=>{let u=io(e.expires&&(a??-1)>=0?e.expires:"",d,p,o);n.patch({expires:u},`Access until ${Te(u)}`)},s=[["week",1,"+1 week"],["month",1,"+1 month"],["month",3,"+3 months"],["year",1,"+1 year"]].map(([d,p,u])=>t("button",{type:"button",class:"dl-chipbtn",click:()=>i(d,p)},u)),l=t("span",{class:"dl-datechip"},[t("button",{type:"button",class:"dl-chipbtn",click:()=>{r.focus({preventScroll:!0});try{r.showPicker()}catch{}}},[v("calendar"),e.expires?Te(e.expires):"Date"]),r]),c={pause:"pause access",notify:"keep access",remove:"remove their devices"}[e.expire_action];return t("div",{class:"dl-tile2"},[t("div",{class:"dl-tile2-label"},[t("span",{},"Access ends"),e.expires?t("span",{class:a!=null&&a<0?"dl-bad":Fe(e,a)?"dl-warn":"dl-ok"},a!=null&&a<0?"ended":`${a} day${a===1?"":"s"} left`):t("span",{class:"dl-faint"},"no end date")]),t("div",{class:"dl-chips-row"},[...s,l,e.expires?t("button",{type:"button",class:"dl-chipbtn",click:()=>n.patch({expires:""},"No end date")},"No end"):""]),t("div",{class:"dl-tile2-foot"},[t("span",{class:"dl-muted"},`When it ends: ${c}${e.expire_warn?`, warn ${e.expire_warn} day${e.expire_warn===1?"":"s"} before`:""}`),t("a",{href:"#",click:d=>{d.preventDefault(),za(n)}},"Change")])])}function qi(n){let e=n.p,o=e.quota_used||e.month[0]+e.month[1],a=e.quota_limit?Math.min(100,e.quota_used/e.quota_limit*100):0,r=t("div",{class:`dl-meter${a>=100?" bad":a>=90?" warn":""}`},[t("i"),e.quota_limit?t("span",{class:"mark",title:"Alert at 90%"}):""]);r.firstChild.style.width=`${a}%`,e.quota_limit&&me(r,()=>[t("div",{class:"dl-tip-title"},`${a.toFixed(1)}% used`),t("div",{class:"dl-muted"},`${te(e.quota_used)} of ${te(e.quota_limit)} · ${te(Math.max(0,e.quota_limit-e.quota_used))} left`),t("div",{class:"dl-faint"},"Alert at 90%")]);let i=xe([["month","Monthly"],["total","Total"]],e.quota_period,{label:"Data limit period",cls:"sm",optimistic:!1,onChange:l=>n.patch({quota_period:l})}),s=[10,50,100].map(l=>t("button",{type:"button",class:`dl-chipbtn${e.quota_gb===l?" on":""}`,click:()=>n.patch({quota_gb:String(l)},`Data limit ${l} GB`)},`${l} GB`));return s.push(t("button",{type:"button",class:`dl-chipbtn${e.quota_gb?"":" on"}`,click:()=>n.patch({quota_gb:""},"No data limit")},"Unlimited")),s.push(t("button",{type:"button",class:"dl-chipbtn",click:()=>{let l=prompt("Data limit in GB",e.quota_gb?String(e.quota_gb):"");l!=null&&l.trim()!==""&&Number(l)>0&&n.patch({quota_gb:l.trim()},`Data limit ${l.trim()} GB`)}},"Custom")),t("div",{class:"dl-tile2"},[t("div",{class:"dl-tile2-label"},[t("span",{},"Data"),i]),t("div",{class:"dl-tile2-row"},[t("span",{class:"dl-tile2-value"},[te(o),e.quota_limit?t("span",{class:"dl-faint"},` of ${te(e.quota_limit)}`):t("span",{class:"dl-faint"}," · no limit")]),e.quota_period==="month"?t("span",{class:"dl-sub"},"resets on the 1st"):""]),e.quota_limit?r:"",t("div",{class:"dl-chips-row"},s),e.quota_gb&&e.quota_period==="month"?t("div",{class:"dl-tile2-foot"},[t("span",{class:"dl-muted"},e.bonus_gb?`Includes +${e.bonus_gb} GB extra this month`:"Need a little more this month?"),t("a",{href:"#",click:l=>{l.preventDefault(),n.patch({bonus_gb:String((e.bonus_gb||0)+10)},"+10 GB this month")}},"+10 GB this month")]):"",t("div",{class:"dl-tile2-foot"},[t("span",{class:"dl-muted"},`${te(e.total[0]+e.total[1])} in total`),t("button",{type:"button",class:"dl-linkbtn danger",click:()=>vt("person",e.id,e.name,()=>setTimeout(()=>n.refresh(),300))},"Reset usage")])])}function Ki(n){let e=n.p,o=!!e.hours,[a,r]=(e.hours||"07:00-23:00").split("-"),i=t("input",{type:"time",class:"cbi-input-text",value:a,"aria-label":"From"}),s=t("input",{type:"time",class:"cbi-input-text",value:r,"aria-label":"To"}),l=t("div",{class:"dl-tile2-row"},[i,t("span",{class:"dl-faint"},"to"),s]),c=()=>{let p=`${i.value}-${s.value}`;if(p!==e.hours){if(!Fa.test(i.value)||!Fa.test(s.value))return Z("Enter both times, like 07:00 and 23:00.","warning");if(i.value===s.value)return Z("The start and the end must differ.","warning");n.patch({hours:p},`Allowed ${i.value}–${s.value}`)}};l.addEventListener("focusout",p=>{l.contains(p.relatedTarget)||c()});for(let p of[i,s])p.addEventListener("keydown",u=>{u.key==="Enter"&&(u.preventDefault(),c())});let d=t("button",{type:"button",role:"switch","aria-checked":o?"true":"false",class:`dl-switch${o?" on":""}`,"aria-label":"Limit hours",click:()=>n.patch({hours:o?"":"07:00-23:00"},o?"Any time":"Allowed 07:00–23:00")},t("i"));return t("div",{class:"dl-tile2"},[t("div",{class:"dl-tile2-row"},[t("div",{class:"dl-stack"},[t("span",{class:"dl-tile2-label"},"Allowed hours"),t("span",{},o?`${a} – ${r} (router time)`:"Any time")]),d]),o?l:""])}function qa(n){let e=n.p,o=xe(["internet","lan","both"].map(a=>[a,[v(a==="internet"?"globe":a==="lan"?"home":"shield"),a==="internet"?"Internet":a==="lan"?"Home":"Both"]]),e.access,{label:"Access",cls:"wide",optimistic:!1,onChange:a=>n.patch({access:a},`Access: ${ot[a]}`)});return t("section",{class:"dl-devsec","aria-label":"Access and limits"},[t("div",{class:"dl-panel-head"},[t("h3",{},"Access & limits")]),t("div",{class:"dl-panel"},[t("div",{class:"dl-stack gap8"},[t("span",{class:"dl-tile2-label"},"Can reach"),o,t("span",{class:"dl-sub"},Gi[e.access]),e.access==="lan"&&n.st.services.length?Ua(n):"",Ye(e)?ja(n):"",e.access==="lan"?Oa(n):""]),t("div",{class:"dl-tiles2"},[Ga(n),Wa(n),Fi(n),qi(n),Ki(n)])])])}function Ji(n){let e=n.st,o=t("div",{class:"dl-panel-head pad"},[t("h3",{},"Locations"),t("span",{class:"dl-spacer"}),e.geo.enabled?xt("30d",r=>n.map?.setRange(r),!1):"",D("Hide",()=>{n.mapOpen=!1,n.map?.destroy(),n.map=null,n.paintPlaces()},"neutral")]);if(!e.geo.enabled)return t("div",{class:"dl-panel flush"},[o,t("div",{class:"dl-map-off"},["Locations are off. ",t("a",{href:L.url("admin/network/dawnline/settings")},"Turn them on in Settings"),"."])]);let a=new Je({openPerson:()=>{},openDevice:(r,i)=>{let s=n.p.devices.find(l=>l.id===i);s&&Be(n.p,s,n.deviceOpts())}},"30d",280);return n.map=a,requestAnimationFrame(()=>a.mount(n.mapData())),t("div",{class:"dl-panel flush"},[o,a.el])}function Ka(n){let e=n.st;if(!e.geo.enabled)return t("div",{class:"dl-places"},[v("pin"),t("div",{class:"dl-stack"},[t("span",{},"Locations are off"),t("span",{class:"dl-sub"},"City-level, from the client IP")]),t("span",{class:"dl-spacer"}),t("a",{class:"cbi-button cbi-button-neutral",href:L.url("admin/network/dawnline/settings")},"Turn on")]);if(n.mapOpen)return n.map&&n.parts.places.contains(n.map.el)?null:Ji(n);let o=e.now-30*86400,a=e.geo.points.filter(s=>s.person===n.p.id&&s.ts>=o).sort((s,l)=>l.ts-s.ts),r=[...new Set(a.map(s=>s.city||s.country).filter(Boolean))],i=a[0];return t("div",{class:"dl-places"},[v("pin"),t("div",{class:"dl-stack"},[t("span",{},i?i.city||i.country:"No locations yet"),t("span",{class:"dl-sub"},i?`${r.length} place${r.length===1?"":"s"} in 30 days${i.org?` · ${i.org}`:""}`:"Shown after a device connects")]),t("span",{class:"dl-spacer"}),a.length?D("Show map",()=>{n.mapOpen=!0,n.paintPlaces()},"neutral"):""])}function Ja(n){let e=n.p,o=n.st,a=n.events.filter(l=>l.person===e.id),r=[],i=[...a].reverse();for(let l=0;l1){let u=p.querySelector(".dl-row-main");dom.content(u,[...qn(o,c).slice(0,3),t("span",{class:"dl-muted"},`${d} times`)]),u.title=i.slice(l,l+d).map(w=>w.detail??"").join(` -`)}r.push(p),l+=d-1}let s=D([v("more")],()=>we(s,[{label:"Export CSV",icon:v("download"),run:()=>Ue(o,a,"csv",e.id)},{label:"Export JSON",icon:v("download"),run:()=>Ue(o,a,"json",e.id)},null,{label:`Clear ${e.name}'s activity`,icon:v("trash"),danger:!0,run:()=>Ke(`Clear ${e.name}'s activity`,`Removes events about ${e.name} and their devices.`,{person:e.id},()=>n.refresh())}]),"neutral",{title:"Export or clear",class:"cbi-button cbi-button-neutral dl-icon-only"});return t("div",{class:"dl-panel flush"},[t("div",{class:"dl-panel-head pad"},[t("h3",{},"Activity"),t("span",{class:"dl-sub"},a.length>10?`latest 10 of ${a.length}`:""),t("span",{class:"dl-spacer"}),s]),r.length?r:t("div",{class:"dl-row dl-muted"},"Nothing yet.")])}var wn=class{constructor(){this.id="";this.events=[];this.mapOpen=!1;this.map=null;this.parts={};this.series=[];this.devSeries={};this.ticks=0;this.fullNext=!1}async fetch(e){let[o,a,r]=await Promise.all([P.status(30),e?P.events(5e3).catch(()=>null):Promise.resolve(null),e?P.personUsage(this.id,30).catch(()=>null):Promise.resolve(null)]);return{st:o,ev:a?.events??null,use:r}}async load(){return this.id=new URLSearchParams(location.search).get("id")??"",this.fetch(!0)}render(e){this.take(e);let o=this.st.people.find(s=>s.id===this.id);if(!o)return t("div",{class:"dl-empty"},[t("h3",{},"Person not found"),t("p",{},"They may have been removed."),t("a",{class:"cbi-button",href:L.url("admin/network/dawnline/server")},"Back to Servers")]);this.p=o;for(let s of["head","devices","traffic","places","activity","limits"])this.parts[s]=t("div",{});this.parts.devices.className="dl-person-devices";let a=t("div",{},[t("nav",{class:"dl-crumbs","aria-label":"Breadcrumb"},[t("a",{href:wt(o.server)},this.st.servers.find(s=>s.id===o.server)?.name??"Servers"),t("span",{},"/"),t("a",{href:wt(o.server)},"People"),t("span",{},"/"),t("span",{},o.name)]),this.parts.head,t("div",{class:"dl-grid-person"},[t("div",{class:"dl-col"},[this.parts.devices,this.parts.traffic,this.parts.places,this.parts.activity]),t("div",{class:"dl-col"},[this.parts.limits])])]);this.paint();let r=new URLSearchParams(location.search),i=r.get("device")&&o.devices.find(s=>s.id===r.get("device"));return i?setTimeout(()=>Be(this.p,i,this.deviceOpts()),50):r.get("add")&&setTimeout(()=>it(this.p,this.deviceOpts()),50),this.poller=Ve({fetch:s=>{let l=s||this.fullNext||++this.ticks%4===0;return this.fullNext=!1,this.fetch(l)},every:15,live:!0,active:()=>a.isConnected,apply:(s,l)=>this.apply(s,l)}),a}take(e){this.st=e.st,e.ev&&(this.events=e.ev),e.use&&(this.series=e.use.person,this.devSeries=e.use.devices)}apply(e,o){this.take(e);let a=this.st.people.find(r=>r.id===this.id);if(!a){o||(location.href=wt(this.p?.server));return}this.p=a,this.paint(o),this.map?.update(this.mapData())}async refresh(){this.fullNext=!0,await this.poller?.refresh()}async patch(e,o){var i;this.poller?.claim();let a=await W(()=>P.personUpdate(this.p.id,e),o);if(!a)return!1;this.poller?.claim();let r=this.st.people.findIndex(s=>s.id===this.p.id);return(i=a.person).rate??(i.rate=this.p.rate),r>=0&&(this.st.people[r]=a.person),this.p=a.person,this.paint(),!0}get today(){return Re(this.series.length?this.series:this.st.series)}get core(){return bt(this.st.servers,this.p.server)}deviceOpts(){return{refresh:()=>this.refresh(),geo:this.st.geo,now:this.st.now,today:this.today,core:this.core,events:()=>this.events}}mapData(){return{geo:this.st.geo,people:this.st.people,now:this.st.now,person:this.p.id}}paint(e=!1){Le(this.parts.head,Ra(this),e),Le(this.parts.traffic,Ia(this),e),Le(this.parts.devices,Ba(this),e),Le(this.parts.limits,qa(this),e),this.paintPlaces(e),Le(this.parts.activity,Ja(this),e)}paintPlaces(e=!1){let o=Ka(this);o&&Le(this.parts.places,o,e&&!this.mapOpen)}};var Vi={ok:"check",warn:"alert",error:"x",skip:"pause"},yn=class{constructor(e,o,a,r){this.el=t("div",{});this.wdEl=t("div",{});this.checksEl=t("div",{class:"dl-panel"});this.recentEl=t("div",{class:"dl-panel flush dl-recent"});this.checks=null;this.summary=t("div",{});this.open=new Set;this.st=e,this.sl=o,this.events=a,this.toLog=r,dom.content(this.el,[this.summary,this.wdEl,t("div",{class:"dl-health-cols"},[this.checksEl,this.recentEl])]),this.paintChecks(),this.paintLive(o,a)}async run(e){let o=e?await fn(e):await P.health().catch(()=>null);o&&(this.take(o),e==="netrestart"&&setTimeout(()=>this.el.isConnected&&void this.run(),5e3))}take(e){this.checks=e.checks,this.paintChecks(),this.paintLive(e,this.events)}paintChecks(){let e=this.checks;if(!e){dom.content(this.summary,""),dom.content(this.checksEl,[t("div",{class:"dl-panel-head"},[t("h3",{},"Checks")]),t("p",{class:"dl-muted dl-loading"},"Running checks…")]);return}let o=e.filter(s=>s.status==="error").length,a=e.filter(s=>s.status==="warn").length;dom.content(this.summary,o?ht("error",`${o} problem${o>1?"s":""} need attention.`):a?ht("warn",`${a} warning${a>1?"s":""}.`):ht("ok","All checks passed."));let r=new Map;for(let s of this.sl.watchdog.repairs)r.set(s.id,Math.max(r.get(s.id)??0,s.ts));let i=()=>this.run();dom.content(this.checksEl,[t("div",{class:"dl-panel-head"},[t("h3",{},"Checks"),t("span",{class:"dl-spacer"}),D("Run again",i)]),t("ul",{class:"dl-checks"},e.map(s=>t("li",{},[t("span",{class:`dl-check-icon ${s.status}`},v(Vi[s.status])),t("div",{class:"dl-check-body"},[t("div",{class:"dl-check-title"},s.title),t("div",{class:"dl-check-detail"},s.detail),r.has(s.id)?t("div",{class:"dl-check-repaired"},`Repaired by the watchdog at ${Mt(r.get(s.id))}`):""]),Kn(s,l=>void this.run(l),i)])))])}paintLive(e,o){this.sl=e,this.events=o;let a=e.watchdog,r=a.beat!=null&&a.now-a.beat>180,i=a.repairs.filter(c=>a.now-c.ts<86400),s=i[i.length-1],l=ge(a.enabled,"Watchdog repairs",async c=>{await W(()=>P.settingsUpdate({watchdog:c?"1":"0"}),c?"Watchdog on":"Watchdog off")||Pn(l,!c);let p=await P.serviceLog().catch(()=>null);p&&this.paintLive(p,this.events)});dom.content(this.wdEl,t("div",{class:"dl-panel dl-wd"},[t("div",{class:"dl-wd-head"},[t("span",{class:`dl-wd-tile${a.enabled?"":" off"}`},v("shield")),t("div",{class:"dl-stack"},[t("span",{class:"dl-wd-title"},"Watchdog"),t("span",{class:"dl-sub"},a.enabled?"Every minute it checks the tunnels and services and repairs what it can on its own.":"Off: problems are only written to the log. Nothing is repaired on its own.")]),t("span",{class:"dl-spacer"}),l]),t("div",{class:"dl-wd-foot"},[t("div",{class:"dl-wd-chips"},a.targets.map(c=>t("span",{class:`dl-check-chip${c.ok?"":" error"}`,title:c.ok?"OK":`Not working${c.tries?` · ${c.tries} repair${c.tries>1?"s":""}`:""}`},[v(c.ok?"check":"x"),c.name]))),t("span",{class:`dl-sub${r?" dl-warn-text":""}`},r?`The agent has not checked in for ${Math.round((a.now-a.beat)/60)} min; cron restarts it after 5.`:[a.last?`Looked ${ie(a.last,a.now)}`:"Starts within a minute"," · ",i.length?`${i.length} repair${i.length>1?"s":""} today, last ${s.name} at ${Mt(s.ts)}`:"no repairs today"])])])),this.paintRecent()}paintRecent(){let e=(this.sl.watchdog.now||Date.now()/1e3)-604800,o=[...this.events.map(r=>({ts:r.ts,ev:r})),...this.sl.log.map(r=>({ts:r.ts,sys:r}))].filter(r=>r.ts>=e&&Jt(r)).sort((r,i)=>i.ts-r.ts),a=t("div",{class:"dl-panel-head pad"},[t("h3",{},"Recent problems"),t("span",{class:"dl-spacer"}),o.length?t("a",{href:"#",click:r=>(r.preventDefault(),this.toLog())},"All in Log →"):""]);if(!o.length){dom.content(this.recentEl,[a,t("div",{class:"dl-recent-empty"},[t("span",{class:"dl-check-icon ok"},v("check")),"No problems in the last 7 days."])]);return}dom.content(this.recentEl,[a,...o.slice(0,8).map(r=>{if(r.sys){let i=r.sys,s=`${i.ts}|${i.msg}`;return un(i,this.open.has(s),()=>{this.open.delete(s)||this.open.add(s),this.paintRecent()},Mt(i.ts))}return Qe(this.st,r.ev,{time:Mt(r.ts)})})])}};var kn=300,Yi=["all","connections","people","system","problems"],$n=class{constructor(e,o,a){this.events=[];this.system=[];this.kind="all";this.shown=kn;this.open=new Set;this.list=t("div",{});this.sub="";this.tabs=t("div",{class:"dl-seg",role:"tablist"});this.st=e,this.take(o),this.system=a,this.el=t("div",{},[t("div",{class:"dl-toolbar"},[this.tabs]),this.list]),this.paint()}actions(){let e=()=>this.kind==="all"?"":this.kind,o=i=>()=>{let s=this.filtered().reverse();Ue(this.st,s.filter(l=>l.ev).map(l=>l.ev),i,e(),s.filter(l=>l.sys).map(l=>l.sys))},a=D([v("download")," Export"],()=>we(a,[{label:"CSV (spreadsheet)",icon:v("download"),run:o("csv")},{label:"JSON",icon:v("download"),run:o("json")}])),r=D([v("trash")," Clear"],()=>Ke("Clear the log","Removes events from the log on the router.",{},()=>this.reload(),this.kind==="all"?void 0:this.kind,!0));return[a,r]}take(e){this.events=e.events,this.policy=e.policy;let o=gt.filter(a=>!e.policy.categories.includes(a));this.sub=`${Vt(e.policy)}${o.length?` Not recorded: ${o.map(a=>rt[a].toLowerCase()).join(", ")}.`:""}`}async reload(){let[e,o]=await Promise.all([P.events(2e4).catch(()=>null),P.serviceLog().catch(()=>null)]);e&&this.take(e),o&&(this.system=o.log),this.paint()}items(){return[...this.events.map(e=>({ts:e.ts,ev:e})),...this.system.map(e=>({ts:e.ts,sys:e}))].sort((e,o)=>o.ts-e.ts)}matches(e,o){return o==="all"?!0:o==="problems"?Jt(e):o==="system"?!!e.sys:!!e.ev&&Tt(e.ev.type)===o}filtered(){return this.items().filter(e=>this.matches(e,this.kind))}paintTabs(e){dom.content(this.tabs,Yi.map(o=>t("button",{type:"button",role:"tab",class:o===this.kind?"on":"","aria-selected":o===this.kind?"true":"false",click:()=>this.show(o)},[o==="all"?"All":o==="system"?"System":rt[o],t("b",{},String(e.filter(a=>this.matches(a,o)).length))])))}show(e){this.kind=e,this.shown=kn,this.paint()}paint(){this.paintTabs(this.items());let e=this.filtered();if(!e.length){dom.content(this.list,t("div",{class:"dl-empty"},[t("p",{},this.events.length||this.system.length?"No events match.":"The log is empty.")]));return}let o=[],a="",r=null;for(let i of e.slice(0,this.shown)){let s=sa(i.ts);s!==a&&(a=s,r=t("div",{class:"dl-panel flush"},t("div",{class:"dl-panel-head pad"},t("h3",{},s))),o.push(r));let l=new Date(i.ts*1e3).toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"});if(i.sys){let c=`${i.sys.ts}|${i.sys.msg}`;r.appendChild(un(i.sys,this.open.has(c),()=>{this.open.delete(c)||this.open.add(c),this.paint()},l))}else r.appendChild(Qe(this.st,i.ev,{time:l}))}e.length>this.shown&&o.push(t("div",{class:"dl-more-row"},D(`Show ${Math.min(kn,e.length-this.shown)} more of ${e.length-this.shown}`,()=>{this.shown+=kn,this.paint()}))),dom.content(this.list,o)}};var Zi=[["health","Health"],["log","Log"]],Xn=2e4,En=class{constructor(){this.tab=new URLSearchParams(location.search).get("tab")==="log"?"log":"health";this.segEl=t("div",{class:"dl-seg dl-srvsections dl-diag-tabs",role:"tablist","aria-label":"Diagnostics"});this.subEl=t("span",{class:"dl-muted"});this.actionsEl=t("div",{class:"dl-row-actions"});this.bodyEl=t("div",{});this.eventsAt=0}load(){return this.eventsAt=Date.now(),Promise.all([P.status(1),P.events(Xn),P.serviceLog()])}render([e,o,a]){return this.log=new $n(e,o,a.log),this.health=new yn(e,a,o.events,()=>{this.show("log"),this.log.show("problems")}),this.show(this.tab),Ve({fetch:async()=>{let r=this.tab==="log",[i,s]=await Promise.all([P.serviceLog().catch(()=>null),r?P.events(Xn).catch(()=>null):Promise.resolve(null)]);return i||s?{n:i,e:s}:null},every:10,active:()=>this.bodyEl.isConnected,apply:({n:r,e:i})=>this.take(r,i)}),t("div",{},[t("div",{class:"dl-pagehead"},[t("div",{class:"dl-stack"},[t("h2",{class:"dl-h1"},"Diagnostics"),this.subEl]),this.actionsEl]),this.segEl,this.bodyEl])}take(e,o){o&&(this.log.take(o),this.eventsAt=Date.now()),e&&(this.log.system=e.log),e&&this.health.paintLive(e,o?.events??this.health.events),this.tab==="log"&&this.log.paint()}show(e){this.tab=e,dom.content(this.segEl,Zi.map(([o,a])=>t("button",{type:"button",role:"tab",class:o===e?"on":"","aria-selected":o===e?"true":"false",click:()=>o!==this.tab&&this.show(o)},a))),this.bodyEl.replaceChildren(e==="log"?this.log.el:this.health.el),this.subEl.textContent=e==="log"?this.log.sub:"Everything Dawnline depends on, checked live. The watchdog repairs what it can on its own.",dom.content(this.actionsEl,e==="log"?this.log.actions():""),e==="log"?(this.log.paint(),Date.now()-this.eventsAt>1e4&&P.events(Xn).then(o=>this.take(null,o)).catch(()=>null)):this.health.checks||this.health.run()}};var Va=":root{--dl-card: var(--panel-bg, var(--background-color-high, transparent));--dl-elevated: var(--elevated, var(--background-color-high, Canvas));--dl-line: var(--border, var(--border-color-medium, color-mix(in srgb, currentColor 14%, transparent)));--dl-soft: var(--muted, color-mix(in srgb, currentColor 5%, transparent));--dl-soft-hover: var(--soft-hover, color-mix(in srgb, currentColor 10%, transparent));--dl-fg: var(--foreground, var(--text-color-highest, inherit));--dl-fg-muted: var(--muted-foreground, color-mix(in srgb, currentColor 65%, transparent));--dl-fg-faint: var(--text-tertiary, color-mix(in srgb, currentColor 50%, transparent));--dl-accent: var(--accent, #3a83f7);--dl-ok: var(--success, #00a240);--dl-warn: var(--warning, #e25507);--dl-bad: var(--danger, #e02e2a);--dl-ok-wash: var(--success-a15, color-mix(in srgb, #00a240 15%, transparent));--dl-warn-wash: var(--warning-a15, color-mix(in srgb, #e25507 15%, transparent));--dl-bad-wash: var(--destructive-a15, color-mix(in srgb, #e02e2a 15%, transparent));--dl-info-wash: var(--info-a15, color-mix(in srgb, #3a83f7 15%, transparent));--dl-info: var(--info, #2c67c5);--dl-track: var(--foreground-a10, color-mix(in srgb, currentColor 10%, transparent));--dl-chart-1: var(--chart-blue, #3a83f7);--dl-chart-2: var(--chart-green, #00a240);--dl-ring: var(--ring, #3a83f7);--dl-primary: var(--primary, #0d0d0d);--dl-primary-fg: var(--primary-foreground, #fff);--dl-mono: var(--font-mono, ui-monospace, Menlo, Consolas, monospace);--dl-shadow: var(--shadow-sm, none);--dl-radius: 16px}.dl-root,.dl-modal{cursor:default}:is(.dl-root,.dl-modal) :is(input:not([type=checkbox],[type=radio],[type=range],[type=button],[type=submit]),textarea,[contenteditable=true]){cursor:text}.dl-icon-wrap{display:inline-flex;align-items:center;justify-content:center;line-height:0}.dl-icon{width:16px;height:16px}.dl-icon-btn{display:inline-flex!important;align-items:center;gap:6px}.dl-muted{color:var(--dl-fg-muted)}.dl-faint,.dl-sep{color:var(--dl-fg-faint)}.dl-nowrap{white-space:nowrap}.dl-mono{font-family:var(--dl-mono);font-size:13px}.dl-spacer{flex:1}.dl-pill{display:inline-flex;align-items:center;gap:4px;height:20px;padding:0 8px;border-radius:999px;font-size:12px;line-height:20px;font-weight:500;white-space:nowrap;background:var(--dl-soft);color:var(--dl-fg-muted)}.dl-pill.ok{background:var(--dl-ok-wash);color:var(--dl-ok)}.dl-pill.warn{background:var(--dl-warn-wash);color:var(--dl-warn)}.dl-pill.bad{background:var(--dl-bad-wash);color:var(--dl-bad)}.dl-pill.accent{background:var(--dl-info-wash);color:var(--dl-info)}.dl-pill.off{opacity:.75}.dl-panel{background:var(--dl-card);border:1px solid var(--dl-line);border-radius:var(--dl-radius);padding:16px;margin:0 0 16px;min-width:0;box-shadow:var(--dl-shadow)}.dl-panel-head{display:flex;align-items:center;flex-wrap:wrap;gap:8px 12px;margin:0 0 12px}.dl-panel-head h3{margin:0!important;padding:0;font-size:16px;line-height:24px;font-weight:500;border:0;background:none}.dl-tiles{display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:12px;margin:0 0 16px}.dl-tile{background:var(--dl-card);border:1px solid var(--dl-line);border-radius:var(--dl-radius);padding:14px 16px;min-width:0;box-shadow:var(--dl-shadow)}.dl-tile-label{font-size:12px;line-height:16px;font-weight:500;color:var(--dl-fg-faint)}.dl-tile-value{font-size:24px;line-height:32px;font-weight:500;margin-top:4px;font-variant-numeric:tabular-nums;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;letter-spacing:-.01em}.dl-tile-sub{font-size:12px;line-height:16px;color:var(--dl-fg-muted);margin-top:2px;font-variant-numeric:tabular-nums}.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)}}.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)}.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}.dl-events li:first-child{border-top:0;padding-top:0}.dl-ev-time{flex:0 0 88px;color:var(--dl-fg-faint);font-variant-numeric:tabular-nums;white-space:nowrap;font-size:13px}.dl-ev-dot{flex:0 0 auto;width:6px;height:6px;border-radius:50%;background:var(--dl-fg-faint);transform:translateY(-2px)}.dl-ev-dot.ok{background:var(--dl-ok)}.dl-ev-dot.warn{background:var(--dl-warn)}.dl-ev-dot.bad{background:var(--dl-bad)}.dl-ev-dot.accent{background:var(--dl-accent)}.dl-row>.dl-ev-dot,.dl-dev-log-row>.dl-ev-dot{margin:0 4px}.dl-ev-tile{flex:none;display:inline-flex;align-items:center;justify-content:center;width:22px;height:22px;margin:-2px -4px;border-radius:7px;background:color-mix(in srgb,var(--dl-accent) 16%,transparent);color:var(--dl-accent);align-self:center}.dl-ev-tile .dl-icon-wrap{display:inline-flex}.dl-ev-tile .dl-icon{width:14px;height:14px}.dl-row.dl-ev-by-admin{background:color-mix(in srgb,var(--dl-accent) 6%,transparent)}.dl-you{color:var(--dl-accent);font-weight:500}.dl-ev-kind{color:var(--dl-fg-faint)}.dl-slotbar{display:flex;align-items:center;gap:8px;margin:8px 0 0 44px}.dl-slotbar-segs{display:flex;gap:3px;flex:none;max-width:100%}.dl-slotbar-segs i{flex:1;min-width:2px;display:block;height:4px;border-radius:2px;background:var(--dl-soft-hover)}.dl-slotbar-segs i.used{background:var(--dl-fg-muted)}.dl-slotbar-text{font-size:12px;color:var(--dl-fg-faint);font-variant-numeric:tabular-nums}.dl-slotbar-segs i.over{background:color-mix(in srgb,var(--dl-warn) 80%,transparent)}.dl-ev-srv{flex:none;font-size:11px;line-height:18px;padding:0 8px;border-radius:999px;background:var(--dl-soft);color:var(--dl-fg-muted);white-space:nowrap}.dl-ev-by-system{--sys: var(--dl-fg-muted)}.dl-ev-by-system.ok{--sys: var(--dl-ok)}.dl-ev-by-system.warn{--sys: var(--dl-warn)}.dl-ev-by-system.bad{--sys: var(--dl-bad)}.dl-ev-tile.ev{background:var(--dl-soft);color:var(--dl-fg-muted)}.dl-ev-tile.ev.ok{background:var(--dl-ok-wash);color:var(--dl-ok)}.dl-ev-tile.ev.warn{background:var(--dl-warn-wash);color:var(--dl-warn)}.dl-ev-tile.ev.bad{background:var(--dl-bad-wash);color:var(--dl-bad)}.dl-ev-tile.ev.accent{background:color-mix(in srgb,var(--dl-accent) 16%,transparent);color:var(--dl-accent)}.dl-ev-tile.sys{background:color-mix(in srgb,var(--sys) 16%,transparent);color:var(--sys)}.dl-row.dl-ev-by-system{background:color-mix(in srgb,var(--sys) 6%,transparent)}.dl-sys-src{color:var(--sys)}.dl-ev-by-system:not(.ok):not(.warn):not(.bad) .dl-sys-src{color:var(--dl-fg)}.dl-ev-text{min-width:0;overflow-wrap:anywhere}.dl-server{display:flex;flex-wrap:wrap;align-items:center;gap:8px 10px}.dl-server-name{font-size:16px;line-height:24px;font-weight:500}.dl-kv{display:grid;grid-template-columns:max-content minmax(0,1fr);gap:6px 24px;margin:12px 0 0;font-size:14px;line-height:20px}.dl-kv dt{color:var(--dl-fg-muted);font-weight:400;margin:0}.dl-kv dd{margin:0;overflow-wrap:anywhere;font-variant-numeric:tabular-nums}";var Ya='.dl-plist{display:block}.dl-plist>.dl-card{display:block;margin:0 0 12px;padding:16px;min-width:0;background:var(--dl-card);border:1px solid var(--dl-line);border-radius:var(--dl-radius);box-shadow:var(--dl-shadow)}.dl-plist>.dl-card.dl-filtered{display:none}.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-chip-tag{background:var(--dl-soft);color:var(--dl-fg-muted)}.dl-pcard:has(>.dl-pstrip){row-gap:14px}.dl-pstrip{grid-column:1 / -1;display:flex;align-items:center;flex-wrap:wrap;gap:8px 12px;margin:0 -16px -16px;padding:10px 16px;border-top:1px solid var(--dl-line);border-radius:0 0 var(--dl-radius) var(--dl-radius);font-size:14px;line-height:20px}.dl-pstrip.warn{background:color-mix(in srgb,var(--dl-warn) 7%,transparent)}.dl-pstrip.bad{background:color-mix(in srgb,var(--dl-bad) 7%,transparent)}.dl-pstrip-text{flex:1;min-width:0;display:flex;flex-wrap:wrap;align-items:baseline;gap:0 8px}.dl-pstrip-text b{font-weight:500}.dl-pstrip>.cbi-button{flex:none;height:32px!important}.dl-plist-none{color:var(--dl-fg-muted);text-align:center;padding:28px 16px;background:var(--dl-card);border:1px solid var(--dl-line);border-radius:var(--dl-radius)}.dl-card-head{display:flex;align-items:center;flex-wrap:wrap;gap:6px 8px}.dl-avatar{flex:0 0 auto;width:32px;height:32px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;font-size:12px;font-weight:600;color:var(--dl-fg);background:var(--dl-soft);position:relative;margin-right:4px;letter-spacing:.02em}.dl-avatar.online:after{content:"";position:absolute;right:-1px;bottom:-1px;width:9px;height:9px;border-radius:50%;background:var(--dl-ok);box-shadow:0 0 0 2px var(--dl-card)}.dl-card-name{font-size:16px;line-height:24px;font-weight:500}.dl-card-slug{font-size:13px;color:var(--dl-fg-faint);font-family:var(--dl-mono)}.dl-quota{margin:8px 0 0 44px;max-width:320px;height:6px;border-radius:999px;background:var(--dl-track);overflow:hidden}.dl-quota>i{display:block;height:100%;background:var(--dl-accent);border-radius:999px}.dl-quota.warn>i{background:var(--dl-warn)}.dl-quota.bad>i{background:var(--dl-bad)}.dl-chips{display:flex;flex-wrap:wrap;gap:6px;margin:12px 0 0 44px}.dl-chip{all:unset;box-sizing:border-box;cursor:pointer;display:inline-flex;align-items:center;gap:6px;max-width:240px;height:28px;padding:0 12px 0 10px;border-radius:999px;font-size:13px;background:var(--dl-soft);color:var(--dl-fg);transition:background .15s}.dl-chip:hover{background:var(--dl-soft-hover)}.dl-chip:focus-visible{outline:2px solid var(--dl-ring);outline-offset:2px}.dl-chip .dl-icon{width:14px;height:14px;color:var(--dl-fg-muted)}.dl-chip.add{background:transparent;box-shadow:inset 0 0 0 1px var(--dl-line);color:var(--dl-fg-muted);aspect-ratio:1;padding:0;justify-content:center}.dl-chip.add:hover{background:var(--dl-soft);color:var(--dl-fg)}.dl-chip.disabled .dl-chip-name{text-decoration:line-through;color:var(--dl-fg-faint)}.dl-chip-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-dot{flex:0 0 auto;width:6px;height:6px;border-radius:50%;background:var(--dl-fg-faint);opacity:.6}.dl-dot.online{background:var(--dl-ok);opacity:1;box-shadow:0 0 0 3px var(--dl-ok-wash)}.dl-empty{text-align:center;padding:40px 16px;background:var(--dl-card);border:1px solid var(--dl-line);border-radius:var(--dl-radius)}.dl-empty .dl-icon-wrap{width:40px;height:40px;border-radius:12px;background:var(--dl-soft);margin-bottom:12px}.dl-empty .dl-icon{width:20px;height:20px}.dl-empty h3{margin:0 0 4px!important;font-size:16px;font-weight:500}.dl-empty p{margin:0 0 16px;color:var(--dl-fg-muted);font-size:14px}.dl-toolbar{display:flex;flex-wrap:wrap;align-items:center;gap:8px 12px;margin:0 0 16px}.dl-toolbar .dl-muted{font-size:13px}@media(max-width:640px){.dl-slotbar,.dl-chips,.dl-quota{margin-left:0}.dl-btn-label{display:none}}.cbi-value.dl-block{display:block!important}.cbi-value.dl-block>.cbi-value-title{display:block;width:auto;float:none;text-align:left;padding:0 0 8px}.cbi-value.dl-block>.cbi-value-field{display:block;width:100%;margin:0}';var Za="#modal_overlay{z-index:1100!important}.dl-dd{position:fixed;z-index:1200;min-width:200px;padding:4px;border-radius:12px;background:var(--dl-elevated);border:1px solid var(--dl-line);box-shadow:0 12px 32px #0000004d;display:flex;flex-direction:column}.dl-dd button{all:unset;cursor:pointer;display:flex;align-items:center;gap:10px;padding:7px 10px;border-radius:8px;font-size:13px;color:var(--dl-fg)}.dl-dd button .dl-icon{width:15px;height:15px;color:var(--dl-fg-muted)}.dl-dd button:hover,.dl-dd button:focus-visible{background:var(--dl-soft)}.dl-dd button.danger,.dl-dd button.danger .dl-icon{color:var(--dl-bad, #e5484d)}.dl-dd button.warn,.dl-dd button.warn .dl-icon{color:var(--dl-warn)}.dl-dd hr{border:0;border-top:1px solid var(--dl-line);margin:4px 0}.dl-chipbtn b{font-weight:500;font-size:11px;margin-left:6px;opacity:.6}.dl-setsub{margin:20px 0 8px!important;font-size:13px;font-weight:500;color:var(--dl-fg)}.dl-row-actions{display:flex;flex-wrap:wrap;gap:8px;align-items:center}.dl-more-row{display:flex;justify-content:center;padding:8px 0 16px}.dl-dsec-actions{display:flex;align-items:center;gap:12px}.dl-kv-act{display:inline-flex;align-items:center;gap:12px;flex-wrap:wrap}.dl-linkbtn,.dl-bento-head a,.dl-bento-foot a,.dl-panel-head a,.dl-dsec-head a,.dl-tile2-foot a{all:unset;box-sizing:border-box;cursor:pointer;display:inline-flex;align-items:center;gap:4px;height:26px;padding:0 9px;margin:-4px -6px;border-radius:8px;font-size:12px;font-weight:500;color:var(--dl-fg-muted);text-decoration:none!important;white-space:nowrap;transition:background .12s,color .12s}.dl-bento-head a,.dl-bento-foot a,.dl-panel-head a,.dl-dsec-head a,.dl-tile2-foot a{color:var(--dl-accent)}.dl-linkbtn:hover,.dl-bento-head a:hover,.dl-bento-foot a:hover,.dl-panel-head a:hover,.dl-dsec-head a:hover,.dl-tile2-foot a:hover{background:var(--dl-soft);color:var(--dl-fg);text-decoration:none!important}.dl-bento-head a:hover,.dl-bento-foot a:hover,.dl-panel-head a:hover,.dl-dsec-head a:hover,.dl-tile2-foot a:hover{background:color-mix(in srgb,var(--dl-accent) 12%,transparent);color:var(--dl-accent)}.dl-linkbtn:focus-visible,.dl-bento-head a:focus-visible,.dl-bento-foot a:focus-visible,.dl-panel-head a:focus-visible{outline:2px solid var(--dl-ring);outline-offset:1px}.dl-linkbtn.danger:hover{color:var(--dl-bad);background:var(--dl-bad-wash)}.dl-ifcards{display:flex;flex-direction:column;gap:20px;margin:24px 0}.dl-ifcard .dl-setsec-body{gap:14px}.dl-iflead{display:flex;flex-direction:column;gap:2px;padding-top:14px;border-top:1px solid var(--dl-line)}.dl-iflead b{font-size:14px;font-weight:500}.dl-ifgroup h4{margin:0 0 8px!important;padding:0!important;font-size:11px!important;font-weight:500!important;letter-spacing:.06em;text-transform:uppercase;color:var(--dl-fg-muted);border:0!important;background:none!important}.dl-ifgrid{display:grid;grid-template-columns:repeat(auto-fill,minmax(210px,1fr));gap:8px}.dl-if{all:unset;box-sizing:border-box;cursor:pointer;display:flex;align-items:center;gap:10px;min-height:52px;padding:8px 12px 8px 10px;min-width:0;border:1px solid var(--dl-line);border-radius:10px;background:var(--dl-card);transition:background .15s,border-color .15s}.dl-if:hover{background:var(--dl-soft)}.dl-if:focus-visible{outline:2px solid var(--dl-ring);outline-offset:2px}.dl-if-ic{width:30px;height:30px;border-radius:8px;background:var(--dl-soft);display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;color:var(--dl-fg-muted)}.dl-if-ic .dl-icon{width:16px;height:16px}.dl-if-main{display:flex;flex-direction:column;min-width:0;flex:1}.dl-if-name{font-size:13.5px;font-weight:500;color:var(--dl-fg);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.dl-if-sub{font:11px/16px var(--dl-mono);color:var(--dl-fg-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.dl-if.sel{border-color:var(--dl-accent);background:color-mix(in srgb,var(--dl-accent) 9%,transparent)}.dl-if.sel .dl-if-ic{background:color-mix(in srgb,var(--dl-accent) 18%,transparent);color:var(--dl-accent)}.dl-if-check{color:var(--dl-accent);display:inline-flex}.dl-if-check .dl-icon{width:16px;height:16px}.dl-if.auto{border-color:color-mix(in srgb,var(--dl-ok) 55%,transparent);background:var(--dl-ok-wash);cursor:default}.dl-if.auto .dl-if-ic{background:color-mix(in srgb,var(--dl-ok) 18%,transparent);color:var(--dl-ok)}.dl-if-badge{display:inline-flex;align-items:center;gap:5px;font-size:10.5px;font-weight:600;letter-spacing:.05em;text-transform:uppercase;flex:0 0 auto}.dl-if-badge.ok{color:var(--dl-ok)}.dl-if.off{cursor:default;opacity:.5}.dl-if.off:hover{background:var(--dl-card)}.dl-if.warn{border-color:color-mix(in srgb,var(--dl-warn) 60%,transparent)}.dl-if-wanctl{gap:10px;align-items:center}.dl-if-wanctl select{max-width:240px}.dl-if-summary{min-width:0;line-height:18px}.dl-warn{color:var(--dl-warn)}.dl-w-ip{width:160px}.dl-dnspick{padding-top:8px;border-top:1px solid var(--dl-line)}.dl-dnspick .dl-row-actions{gap:10px}.dl-note{display:flex;gap:8px;align-items:flex-start;padding:10px 12px;border-radius:10px;font-size:12.5px;line-height:18px;margin:0 0 10px;background:var(--dl-soft)}.dl-note.warn{background:var(--dl-warn-wash, color-mix(in srgb, var(--dl-warn) 14%, transparent))}.dl-note .dl-icon{width:15px;height:15px;flex:0 0 auto;margin-top:1px;color:var(--dl-warn)}.dl-stale{align-self:flex-start;margin-top:4px;font-size:10.5px}.dl-root .cbi-button.dl-btn-warn,.dl-btn-warn.cbi-button{background:var(--dl-warn-wash)!important;color:var(--dl-warn)!important;border-color:color-mix(in srgb,var(--dl-warn) 35%,transparent)!important}.dl-root .cbi-button.dl-btn-warn:hover,.dl-btn-warn.cbi-button:hover{background:color-mix(in srgb,var(--dl-warn) 24%,transparent)!important}.dl-btn-warn .dl-icon{color:var(--dl-warn)}.dl-srvtabs{display:flex;flex-wrap:wrap;gap:6px;padding:4px;margin:0 0 20px;border-radius:12px;background:var(--dl-soft);width:fit-content;max-width:100%}.dl-srvtab{all:unset;box-sizing:border-box;cursor:pointer;display:inline-flex;align-items:center;gap:8px;height:34px;padding:0 14px;border-radius:9px;font-size:13px;color:var(--dl-fg-muted);text-decoration:none!important;white-space:nowrap}.dl-srvtab b{font-weight:500}.dl-srvtab i.dot{width:7px;height:7px;border-radius:50%;background:var(--dl-fg-faint);flex:0 0 auto}.dl-srvtab i.dot.ok{background:var(--dl-ok);animation:dl-srv-pulse 2s ease-out infinite}.dl-srvtab i.dot.bad{background:var(--dl-bad)}.dl-srvtab i.dot.warn{background:var(--dl-warn)}@keyframes dl-srv-pulse{0%{box-shadow:0 0 color-mix(in srgb,var(--dl-ok) 55%,transparent)}70%,to{box-shadow:0 0 0 6px transparent}}@media(prefers-reduced-motion:reduce){.dl-srvtab i.dot.ok{animation:none}}.dl-srvtab:hover{color:var(--dl-fg);background:var(--dl-soft-hover)}.dl-srvtab.on{background:var(--dl-card);color:var(--dl-fg);box-shadow:0 1px 2px #0000002e,inset 0 0 0 1px var(--dl-line)}.dl-srvtab:focus-visible{outline:2px solid var(--dl-ring);outline-offset:1px}.dl-srvtab.add{color:var(--dl-fg-muted)}.dl-srvtab.add .dl-icon{width:14px;height:14px}.dl-srvhead{display:flex;flex-direction:column;gap:14px;margin:0 0 20px}.dl-srvhead .dl-title-row{display:flex;align-items:center;gap:10px}.dl-srvhead .dl-h1{margin:0!important}.dl-metrics.compact .dl-metric{padding:14px 18px}.dl-metrics.compact .dl-metric-value{display:flex;align-items:center;gap:6px;font-size:18px;line-height:26px;min-width:0}.dl-metrics.compact .dl-metric-value>span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.dl-metrics.compact .dl-metric-value .dl-mono{font-size:15px}.dl-metrics.compact .cbi-button{flex:0 0 auto}.dl-srvsections{margin:0 0 16px}.dl-srvbody>.dl-setsec,.dl-srvbody>.dl-ifcards{margin:0}.dl-srvbody .dl-ifcards{margin:0}.dl-metric-ic{display:inline-flex;align-items:center;gap:8px;font-size:16px}.dl-metric-ic .dl-icon{width:18px;height:18px;color:var(--dl-accent)}.dl-keyrow{display:inline-flex;align-items:center;gap:8px;min-width:0}.dl-keyrow code{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:12px;background:none;padding:0}.dl-params{border:1px solid var(--dl-line);border-radius:12px;background:var(--dl-card)}.dl-params>summary{list-style:none;cursor:pointer;display:flex;align-items:center;gap:8px;padding:10px 14px;font-size:13px;color:var(--dl-fg);user-select:none}.dl-params>summary::-webkit-details-marker{display:none}.dl-params>summary>.dl-icon-wrap{display:inline-flex;color:var(--dl-fg-muted);transition:transform .15s}.dl-params>summary>.dl-icon-wrap .dl-icon{width:15px;height:15px}.dl-params[open]>summary>.dl-icon-wrap{transform:rotate(90deg)}.dl-params>summary:focus{outline:none}.dl-params>summary:focus-visible{outline:2px solid var(--dl-ring);outline-offset:-2px;border-radius:12px}.dl-params>summary:hover{background:var(--dl-soft);border-radius:12px}.dl-pcount{font-size:11px;padding:0 6px;border-radius:999px;background:var(--dl-soft);color:var(--dl-fg-muted)}.dl-pgrid{display:grid;grid-template-columns:repeat(auto-fill,minmax(260px,1fr));gap:10px;padding:4px 14px 14px}.dl-pgroup{display:flex;flex-direction:column;gap:6px;padding:12px;border-radius:10px;background:var(--dl-soft);min-width:0}.dl-pgroup-head{display:flex;align-items:center;gap:8px;font-size:13px}.dl-pgroup-head b{font-weight:500}.dl-pgroup-head .dl-icon{width:14px;height:14px;color:var(--dl-fg-muted)}.dl-pgroup p{margin:0!important;font-size:12px;line-height:17px;color:var(--dl-fg-muted)}.dl-pvals{display:flex;flex-wrap:wrap;gap:4px;margin-top:2px}.dl-pv{display:inline-flex;align-items:stretch;max-width:100%;border-radius:6px;overflow:hidden;font:500 11.5px/22px var(--dl-mono);box-shadow:inset 0 0 0 1px var(--dl-line)}.dl-pv i{font-style:normal;padding:0 6px;background:var(--dl-card);color:var(--dl-fg-faint)}.dl-pv b{font-weight:500;padding:0 7px;color:var(--dl-fg);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}";var Qa=".dl-methods{display:grid;grid-template-columns:repeat(auto-fit,minmax(210px,1fr));gap:10px}.dl-method{all:unset;box-sizing:border-box;cursor:pointer;display:flex;flex-direction:column;gap:10px;padding:14px;border-radius:12px;border:1px solid var(--dl-line);background:var(--dl-card);transition:border-color .15s,background .15s;min-width:0}.dl-method:hover{background:var(--dl-soft)}.dl-method:focus-visible{outline:2px solid var(--dl-ring);outline-offset:2px}.dl-method.on{border-color:var(--dl-accent);background:color-mix(in srgb,var(--dl-accent) 8%,transparent);box-shadow:inset 0 0 0 1px var(--dl-accent)}.dl-method.off{cursor:not-allowed;opacity:.55}.dl-method.off:hover{background:var(--dl-card)}.dl-method-head{display:flex;flex-wrap:wrap;align-items:center;gap:8px 10px}.dl-method-head .dl-pill{flex:none}.dl-method-head b{font-weight:500;font-size:14.5px;flex:1}.dl-method-ic{width:32px;height:32px;border-radius:9px;background:var(--dl-soft);display:inline-flex;align-items:center;justify-content:center;color:var(--dl-fg-muted);flex:0 0 auto}.dl-method-ic .dl-icon{width:17px;height:17px}.dl-method.on .dl-method-ic{background:color-mix(in srgb,var(--dl-accent) 18%,transparent);color:var(--dl-accent)}.dl-method p{margin:0!important;font-size:12.5px;line-height:18px;color:var(--dl-fg-muted);flex:1}.dl-method-meters{display:flex;gap:16px}.dl-dots{display:inline-flex;align-items:center;gap:6px;font-size:11px;color:var(--dl-fg-faint)}.dl-dots-row{display:inline-flex;gap:3px}.dl-dots-row i{width:6px;height:6px;border-radius:50%;background:var(--dl-line)}.dl-dots-row i.on{background:var(--dl-fg-muted)}.dl-method.on .dl-dots-row i.on{background:var(--dl-accent)}.dl-method-foot{display:flex;align-items:center;gap:6px;font-size:11.5px;color:var(--dl-fg-faint);padding-top:8px;border-top:1px solid var(--dl-line)}.dl-method-foot .dl-icon{width:13px;height:13px;flex:0 0 auto}.dl-method.off .dl-method-foot{color:var(--dl-warn)}.dl-ibadge{display:inline-flex;align-items:center;gap:3px;height:22px;padding:0 6px;border-radius:999px;background:var(--dl-soft);color:var(--dl-fg-muted);flex:0 0 auto}.dl-ibadge .dl-icon{width:13px;height:13px}.dl-ibadge.warn{background:var(--dl-warn-wash);color:var(--dl-warn)}.dl-ibadge.bad{background:var(--dl-bad-wash);color:var(--dl-bad)}.dl-access{display:inline-flex;gap:4px;flex:0 0 auto}.dl-ibadge.lan{background:color-mix(in srgb,var(--dl-accent) 16%,transparent);color:var(--dl-accent)}.dl-ibadge.inet{background:var(--dl-ok-wash);color:var(--dl-ok)}";var Xa=".dl-addrbar{display:inline-flex;align-items:stretch;flex-wrap:nowrap;max-width:100%;margin-top:4px;border:1px solid var(--dl-line);border-radius:10px;background:var(--dl-card);overflow:hidden}.dl-addrbar-seg{all:unset;box-sizing:border-box;display:inline-flex;align-items:center;gap:7px;padding:6px 12px;font-size:13px;color:var(--dl-fg-muted);border-left:1px solid var(--dl-line);white-space:nowrap;min-width:0}.dl-addrbar-seg:first-child{border-left:0}.dl-addrbar-seg .dl-icon{width:14px;height:14px;color:var(--dl-fg-faint);flex:0 0 auto}.dl-addrbar-seg .dl-mono{font-size:12.5px}.dl-addrbar-seg.main{cursor:pointer;color:var(--dl-fg)}.dl-addrbar-seg.main:hover{background:var(--dl-soft)}.dl-addrbar-seg.main:focus-visible{outline:2px solid var(--dl-ring);outline-offset:-2px}.dl-addrbar-seg.main>.dl-icon-wrap:last-child .dl-icon{opacity:.7}.dl-bento{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));grid-template-rows:auto auto;gap:10px;margin:0 0 20px}.dl-person-devices{margin-bottom:16px}.dl-person-head{display:flex;flex-direction:column;margin:0 0 20px}.dl-person-head>.dl-pagehead{margin-bottom:0;align-items:flex-start}.dl-pnote{all:unset;box-sizing:border-box;cursor:pointer;align-self:flex-start;display:inline-flex;align-items:flex-start;gap:6px;margin:10px 0 0 62px;max-width:60ch;padding:6px 12px 6px 10px;border-radius:10px;font-size:13px;line-height:18px;white-space:pre-line;background:var(--dl-soft);color:var(--dl-fg);box-shadow:inset 0 0 0 1px var(--dl-line)}.dl-pnote:hover{background:var(--dl-soft-hover)}.dl-pnote .dl-icon{width:14px;height:14px;flex:none;margin-top:2px;color:var(--dl-fg-muted)}.dl-note-input{width:100%;box-sizing:border-box;min-height:80px;resize:vertical}.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;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 i:hover{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}.dl-chipbtn:has(.dl-icon){display:inline-flex;align-items:center;gap:5px}.dl-places{display:flex;align-items:center;gap:12px;padding:12px 16px;border:1px solid var(--dl-line);border-radius:var(--dl-radius);background:var(--dl-card);font-size:14px}.dl-places>.dl-icon{width:18px;height:18px;color:var(--dl-fg-muted);flex:none}.dl-person-live{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:10px}.dl-person-live .dl-bento-head{flex-wrap:nowrap;white-space:nowrap;min-width:0}.dl-person-live .dl-bento-head>*{min-width:0;overflow:hidden;text-overflow:ellipsis}.dl-person-live .dl-bento-head>:first-child{flex:none}.dl-person-live.solo{grid-template-columns:minmax(0,1fr)}.dl-person-live:not(.solo) .dl-bento-tile.month>.dl-bento-head:first-child{flex-wrap:wrap;row-gap:2px}.dl-person-live:not(.solo) .dl-bento-tile.month>.dl-bento-head:first-child>.dl-sub{flex-basis:100%}.dl-person-live>.dl-bento-tile,.dl-person-live>.dl-bento-tile.month{grid-column:auto;grid-row:auto}@media(max-width:760px){.dl-person-live{grid-template-columns:minmax(0,1fr)}}.dl-bento-tile{background:var(--dl-card);border:1px solid var(--dl-line);border-radius:var(--dl-radius);padding:14px 16px;display:flex;flex-direction:column;gap:10px;min-width:0;box-shadow:var(--dl-shadow)}.dl-bento-tile.month{grid-column:1 / -1}.dl-onl-count{font-size:13px;line-height:22px;min-width:22px;padding:0 8px;border-radius:999px;background:var(--dl-soft);text-align:center;font-weight:500;font-variant-numeric:tabular-nums}.dl-onl-count.none{color:var(--dl-fg-faint)}.dl-onl-row{flex:1;display:flex;align-items:center;justify-content:center;gap:12px;min-width:0}.dl-onl-p{display:flex;flex-direction:column;align-items:center;gap:5px;width:104px;min-width:0;padding:6px 2px;border-radius:12px;color:var(--dl-fg)!important;text-decoration:none!important}.dl-onl-p:hover{background:var(--dl-soft)}.dl-onl-av{position:relative;width:42px;height:42px;border-radius:50%;background:var(--dl-soft);display:inline-flex;align-items:center;justify-content:center;font-size:13px;font-weight:500;box-shadow:0 0 0 2px var(--dl-ok)}.dl-onl-p.more .dl-onl-av{box-shadow:0 0 0 1px var(--dl-line);color:var(--dl-fg-muted)}.dl-onl-dev{position:absolute;right:-6.5px;bottom:-6.5px;width:20px;height:20px;border-radius:8.5px;border:1.5px solid transparent;background:var(--dl-card);display:inline-flex;align-items:center;justify-content:center;font-size:10px;color:var(--dl-fg-muted)}.dl-onl-dev .dl-icon-wrap{display:inline-flex}.dl-onl-dev .dl-icon{width:12px;height:12px}.dl-onl-name{font-size:12.5px;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-onl-p .dl-sub{font-size:11px;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-onl-row.grid{flex-wrap:wrap;align-content:center;gap:10px 8px;max-height:108px;overflow:hidden}.dl-onl-p.sm{width:auto;padding:4px}.dl-onl-p:hover .dl-onl-dev{background:linear-gradient(var(--dl-soft),var(--dl-soft)),var(--dl-card)}.dl-onl-p.sm:hover{background:none}.dl-onl-p.sm:hover .dl-onl-dev{background:var(--dl-card)}.dl-onl-p.sm .dl-onl-av{transition:box-shadow .15s ease}.dl-onl-p.sm:hover .dl-onl-av{box-shadow:0 0 0 2px var(--dl-ok),0 0 0 6px var(--dl-soft)}.dl-onl-p.sm.more:hover .dl-onl-av{box-shadow:0 0 0 1px var(--dl-line),0 0 0 6px var(--dl-soft)}.dl-onl-p.sm .dl-onl-av{width:36px;height:36px;font-size:11.5px}.dl-onl-meta{display:inline-flex;align-items:center;gap:3px;font-size:11px;color:var(--dl-fg-faint);max-width:100%;white-space:nowrap;overflow:hidden}.dl-onl-meta .dl-icon-wrap{display:inline-flex}.dl-onl-meta .dl-icon{width:12px;height:12px}.dl-onl-av.sm{width:34px;height:34px;font-size:11.5px}.dl-tip-float:has(.dl-hc){padding:0;white-space:normal;border-radius:16px}.dl-hc{width:280px;padding:14px;display:flex;flex-direction:column;gap:10px}.dl-hc-head{display:flex;align-items:center;gap:10px}.dl-hc-head .dl-stack{flex:1;min-width:0}.dl-hc-head b{font-size:14px;font-weight:500}.dl-hc-since{font-size:11.5px;color:var(--dl-ok)}.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)}.dl-hc-foot{display:flex;align-items:center;gap:8px;font-size:11.5px}.dl-disg-id{display:flex;align-items:center;gap:10px}.dl-disg-id b{font-size:16px;font-weight:500}.dl-disg-ic{width:36px;height:36px;border-radius:11px;background:color-mix(in srgb,var(--dl-accent) 14%,transparent);color:var(--dl-accent);display:inline-flex;align-items:center;justify-content:center;flex:none}.dl-disg-ic .dl-icon-wrap{display:inline-flex}.dl-disg-ic .dl-icon{width:18px;height:18px}.dl-disg-meters{display:grid;grid-template-columns:auto 1fr;gap:6px 10px;align-items:center;font-size:12px;color:var(--dl-fg-muted)}.dl-segs{display:inline-flex;gap:3px}.dl-segs i{width:18px;height:5px;border-radius:3px;background:var(--dl-track)}.dl-segs.acc i.on{background:var(--dl-accent)}.dl-segs.ok i.on{background:var(--dl-ok)}.dl-disg-chips{margin-top:auto;display:flex;flex-wrap:wrap;gap:5px}.dl-disg-chips span{font:11px/20px var(--dl-mono);padding:0 8px;border-radius:999px;background:var(--dl-soft);color:var(--dl-fg-muted);white-space:nowrap}.dl-onl-empty{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;font-size:13px;text-align:center}.dl-bento-head{display:flex;align-items:center;justify-content:space-between;gap:10px;min-width:0}.dl-bento-head.start{justify-content:flex-start}.dl-bento-big{font-family:inherit;font-size:28px;line-height:34px;font-weight:500;letter-spacing:-.01em;font-variant-numeric:tabular-nums;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.dl-bento-big small{font-size:13px;font-weight:400;color:var(--dl-fg-faint);letter-spacing:0}.dl-avstack{display:inline-flex}.dl-avstack .dl-avatar{margin-left:-7px;box-shadow:0 0 0 2px var(--dl-card)}.dl-avstack .dl-avatar:first-child{margin-left:0}.dl-avatar.more{background:var(--dl-soft);color:var(--dl-fg-muted)}.dl-bento-list{display:flex;flex-direction:column;gap:2px}.dl-bento-row{display:flex;align-items:center;gap:10px;padding:8px;margin:0 -8px;border-radius:10px;color:var(--dl-fg)!important;text-decoration:none!important;min-width:0;transition:background .12s}.dl-bento-row:hover{background:var(--dl-soft)}.dl-bento-row:hover b{text-decoration:none}.dl-bento-row:focus-visible{outline:2px solid var(--dl-ring);outline-offset:-2px}.dl-bento-row-main{display:flex;flex-direction:column;gap:1px;flex:1;min-width:0}.dl-bento-row-main b{font-weight:500;font-size:13.5px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-bento-row-main .dl-sub{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-bento-row.off b{color:var(--dl-fg-muted);font-weight:400}.dl-bento-row-val{display:flex;flex-direction:column;align-items:flex-end;font-size:13px;font-variant-numeric:tabular-nums;white-space:nowrap}.dl-bento-row-val small{font-size:11px;color:var(--dl-fg-faint)}.dl-bento-sep{font-size:11px;color:var(--dl-fg-faint);padding:12px 0 4px}.dl-bento-devs{display:inline-flex;gap:3px;color:var(--dl-fg-faint)}.dl-bento-devs .dl-icon{width:13px;height:13px}.dl-bento-devs .on{color:var(--dl-ok)}.dl-bento-foot{display:flex;align-items:center;gap:10px;margin-top:auto;padding-top:10px;border-top:1px solid var(--dl-line);color:var(--dl-fg)!important;text-decoration:none!important}.dl-bento-foot.split,.dl-bento-foot.end{justify-content:space-between}.dl-bento-foot.end>a:only-child{margin-left:auto}.dl-bento-empty{display:flex;align-items:center;gap:10px;padding:14px 0;font-size:13.5px;color:var(--dl-fg-muted)}.dl-bento-empty .dl-icon{width:18px;height:18px}.dl-split{display:flex;height:6px;border-radius:3px;overflow:hidden;background:var(--dl-soft)}.dl-split i{display:block;height:100%}.dl-split i.dn{background:var(--dl-accent)}.dl-split i.up{background:var(--dl-ok)}.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;gap:3px;height:54px}.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 i:hover{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}}.dl-srvpagehead{display:flex;flex-direction:column;align-items:flex-start;gap:10px;margin:0 0 20px}.dl-srvpagehead>.dl-title-row{display:flex;align-items:center;gap:10px;width:100%;flex-wrap:wrap}.dl-srvpagehead .dl-actions{margin:0;flex-wrap:wrap}.dl-toolbar-end{display:flex;align-items:center;gap:8px;margin-left:auto;flex-wrap:nowrap;min-width:0}@media(max-width:640px){.dl-toolbar-end{flex-wrap:wrap;width:100%}}.dl-notices{margin:0 0 16px}.dl-notices .dl-need-row .dl-sub{overflow-wrap:anywhere}.dl-notices-more{font-size:13px;color:var(--dl-fg-muted);text-decoration:none}.dl-notices-more:hover{background:var(--dl-soft);color:var(--dl-fg)}.dl-speed-cols{display:grid;grid-template-columns:1fr 1fr;gap:12px}.dl-speed-col{display:flex;flex-direction:column;gap:2px;min-width:0}.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)}.dl-fld .cbi-input-text{width:100%;box-sizing:border-box}.dl-kinds{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:6px}.dl-kinds button{all:unset;box-sizing:border-box;cursor:pointer;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6px;height:68px;border-radius:10px;border:1px solid var(--dl-line);color:var(--dl-fg-muted);font-size:12px;font-weight:500;text-align:center;min-width:0}.dl-kinds button .dl-icon{width:20px;height:20px}.dl-kinds button:hover{background:var(--dl-soft);color:var(--dl-fg)}.dl-kinds button:focus-visible{outline:2px solid var(--dl-ring);outline-offset:2px}.dl-kinds button.on{border-color:var(--dl-accent);color:var(--dl-fg);background:color-mix(in srgb,var(--dl-accent) 10%,transparent);box-shadow:inset 0 0 0 1px var(--dl-accent)}.dl-kinds button.on .dl-icon{color:var(--dl-accent)}.dl-choices{display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:8px}.dl-choice{all:unset;box-sizing:border-box;cursor:pointer;display:flex;flex-direction:column;gap:4px;padding:12px 14px;border-radius:12px;background:var(--dl-card);box-shadow:inset 0 0 0 1px var(--dl-line);transition:background .15s,box-shadow .15s}.dl-choice:hover{background:var(--dl-soft)}.dl-choice:focus-visible{outline:2px solid var(--dl-ring);outline-offset:2px}.dl-choice.selected{box-shadow:inset 0 0 0 2px var(--dl-accent);background:var(--accent-a10, color-mix(in srgb, var(--dl-accent) 8%, transparent))}.dl-choice-title{display:flex;align-items:center;gap:8px;font-size:14px;font-weight:500;color:var(--dl-fg)}.dl-choice-text{font-size:12px;line-height:16px;color:var(--dl-fg-muted)}.dl-attn-item>.cbi-button{margin-left:auto;flex:none;align-self:center}";var er='.dl-steps{display:flex;align-items:center;gap:8px;margin:0 0 16px;flex-wrap:wrap}.dl-step{display:flex;align-items:center;gap:8px;font-size:14px;font-weight:500;color:var(--dl-fg-faint)}.dl-step b{display:inline-flex;width:24px;height:24px;align-items:center;justify-content:center;border-radius:50%;background:var(--dl-soft);font-size:12px;font-weight:600}.dl-step.current{color:var(--dl-fg)}.dl-step.current b{background:var(--dl-primary);color:var(--dl-primary-fg)}.dl-step.done{color:var(--dl-fg-muted)}.dl-step.done b{background:var(--dl-ok-wash);color:var(--dl-ok)}.dl-step+.dl-step:before{content:"";width:24px;height:1px;background:var(--dl-line)}.dl-wizard .dl-panel>div{display:flex;flex-direction:column;gap:16px}.dl-wizard .dl-panel>div>p{margin:0!important;color:var(--dl-fg-muted)}.dl-wizard .dl-panel>div>.cbi-value{margin:0}.dl-wizard h4{font-size:14px;font-weight:500;margin:8px 0 -6px!important}.dl-wizard h4:first-child{margin-top:0!important}.dl-modal .cbi-tabmenu{margin-bottom:16px}.dl-invite{display:grid;grid-template-columns:250px minmax(0,1fr);gap:22px;align-items:start}.dl-invite img{display:block;width:100%;border-radius:18px;box-shadow:0 0 0 1px var(--dl-line)}.dl-invite-side{display:flex;flex-direction:column;gap:14px;min-width:0}.dl-invite-side>p{margin:0!important}.dl-invite-link{all:unset;box-sizing:border-box;cursor:pointer;display:flex;align-items:center;gap:10px;min-width:0;padding:11px 14px;border-radius:12px;background:var(--dl-soft);font:13px/18px var(--dl-mono);color:var(--dl-fg)}.dl-invite-link>span:first-child{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-invite-link>.dl-icon-wrap{flex:none;display:inline-flex}.dl-invite-link .dl-icon{width:15px;height:15px;color:var(--dl-fg-muted);flex:none}.dl-invite-link:hover{background:var(--dl-soft-hover)}.dl-invite-link.alt{padding:8px 14px;font-size:12px;color:var(--dl-fg-muted)}.dl-invite-link>.dl-pill{flex:none}.dl-invite-steps{margin:0;padding-left:20px;list-style:decimal!important;font-size:13px;line-height:24px;color:var(--dl-fg-muted)}.dl-invite-steps b{color:var(--dl-fg);font-weight:500}.dl-invite-steps li{display:list-item!important;list-style:inherit!important;padding-left:4px}.dl-invite-actions{display:flex;gap:8px;flex-wrap:wrap}.modal:has(.dl-modal.wide){max-width:min(760px,94vw)!important;width:100%!important}@media(max-width:640px){.dl-invite{grid-template-columns:minmax(0,1fr)}.dl-invite img{max-width:260px;margin:0 auto}}.dl-toasts{position:fixed;left:50%;bottom:max(24px,env(safe-area-inset-bottom));transform:translate(-50%);z-index:100000;display:flex;flex-direction:column;align-items:center;gap:8px;pointer-events:none}.dl-toast{pointer-events:auto;display:inline-flex;align-items:center;gap:8px;max-width:min(520px,92vw);padding:10px 16px;border-radius:999px;background:var(--dl-fg);color:var(--dl-card);font-size:13px;line-height:18px;box-shadow:0 10px 30px #0000004d;opacity:0;transform:translateY(12px);transition:opacity .18s,transform .18s}.dl-toast.show{opacity:1;transform:none}.dl-toast .dl-icon-wrap{display:inline-flex}.dl-toast .dl-icon{width:15px;height:15px}.dl-toast.success .dl-icon{color:var(--dl-ok)}.dl-toast.error{background:var(--dl-bad);color:#fff}.dl-toast.error .dl-icon{color:#fff}.dl-toast.warning{background:var(--dl-warn);color:#111}.dl-toast.warning .dl-icon{color:#111}.dl-toast button{all:unset;cursor:pointer;display:inline-flex;margin-left:4px;opacity:.8}.dl-toast button:hover{opacity:1}';var tr=".dl-setblock{display:flex;flex-direction:column;gap:8px;margin:0}.dl-addr-opts{display:flex;flex-direction:column;gap:6px}.dl-addr-opt{all:unset;box-sizing:border-box;cursor:pointer;display:grid;grid-template-columns:16px minmax(0,1fr) auto;gap:12px;align-items:center;padding:10px 14px;border-radius:12px;box-shadow:inset 0 0 0 1px var(--dl-line);min-width:0}.dl-addr-opt:hover{background:var(--dl-soft)}.dl-addr-opt.on{box-shadow:inset 0 0 0 1.5px var(--dl-accent);background:color-mix(in srgb,var(--dl-accent) 7%,transparent)}.dl-addr-opt .dl-mono{font-size:13px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-addr-opt .dl-stack{min-width:0}.dl-addr-opt input{width:100%}.dl-addr-opt.other{cursor:default}.dl-addr-opt.other:hover{background:none}.dl-addr-opt.other input{width:100%}.dl-addr-check{width:16px;height:16px;border-radius:5px;box-shadow:inset 0 0 0 1.5px var(--dl-fg-faint);display:inline-flex;align-items:center;justify-content:center}.dl-addr-check .dl-icon-wrap{display:inline-flex}.dl-addr-check .dl-icon{width:12px;height:12px}.dl-addr-opt.on .dl-addr-check{background:var(--dl-accent);box-shadow:none;color:#fff}.dl-addr-opt.other .dl-addr-check{box-shadow:none;color:var(--dl-fg-muted)}.dl-addr-warn{display:inline-flex;align-items:center;gap:5px;font-size:12px;line-height:17px;color:var(--dl-warn)}.dl-addr-warn .dl-icon-wrap{display:inline-flex}.dl-addr-warn .dl-icon{width:13px;height:13px}.dl-pill.info{background:color-mix(in srgb,var(--dl-accent) 14%,transparent);color:var(--dl-accent)}.dl-links{border-radius:12px;background:var(--dl-soft);overflow:hidden}.dl-link-row{display:grid;grid-template-columns:18px minmax(0,1fr) auto;gap:10px;align-items:center;padding:11px 14px}.dl-link-row+.dl-link-row{border-top:1px solid var(--dl-line)}.dl-link-ic{display:inline-flex}.dl-link-ic .dl-icon{width:15px;height:15px}.dl-link-ic.ok .dl-icon{color:var(--dl-ok)}.dl-link-ic.warn .dl-icon{color:var(--dl-warn)}.dl-link-url{font-size:13px;color:var(--dl-fg-muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-link-url b{font-weight:500;color:var(--dl-accent)}@media(max-width:640px){.dl-link-url,.dl-addr-opt .dl-mono,.dl-filecard .dl-ellipsis,.dl-invite-link>span:first-child{white-space:normal;overflow-wrap:anywhere}}.dl-ready-sum{display:flex;align-items:center;gap:12px;padding:12px 14px;border-radius:12px}.dl-ready-sum>.dl-icon-wrap{display:inline-flex}.dl-ready-sum>.dl-icon-wrap .dl-icon{width:18px;height:18px}.dl-ready-sum .dl-stack{flex:1;min-width:0}.dl-ready-sum b{font-weight:500;font-size:13px}.dl-ready-sum.ok{background:var(--dl-ok-wash)}.dl-ready-sum.ok b,.dl-ready-sum.ok .dl-icon{color:var(--dl-ok)}.dl-ready-sum.warn{background:var(--dl-warn-wash)}.dl-ready-sum.warn b,.dl-ready-sum.warn .dl-icon{color:var(--dl-warn)}.dl-ready-sum.error{background:var(--dl-bad-wash)}.dl-ready-sum.error b,.dl-ready-sum.error .dl-icon{color:var(--dl-bad)}.dl-check-chip{display:inline-flex;align-items:center;gap:5px;height:26px;padding:0 10px;border-radius:999px;background:var(--dl-soft);font-size:12px;color:var(--dl-fg-muted)}.dl-check-chip .dl-icon-wrap{display:inline-flex}.dl-check-chip .dl-icon{width:13px;height:13px;color:var(--dl-ok)}.dl-check-chip.warn{background:var(--dl-warn-wash);color:var(--dl-warn)}.dl-check-chip.warn .dl-icon{color:var(--dl-warn)}.dl-check-chip.error{background:var(--dl-bad-wash);color:var(--dl-bad)}.dl-check-chip.error .dl-icon{color:var(--dl-bad)}.dl-ready-details{display:flex;flex-direction:column;gap:8px;padding:4px 2px}.dl-ready-details[hidden]{display:none}.dl-ready-item{display:flex;align-items:flex-start;gap:8px;font-size:13px;line-height:18px;min-width:0}.dl-ready-item .dl-icon-wrap{display:inline-flex;margin-top:1px}.dl-ready-item .dl-icon{width:15px;height:15px}.dl-ready-item.ok .dl-icon{color:var(--dl-ok)}.dl-ready-item.warn .dl-icon{color:var(--dl-warn)}.dl-ready-item.error .dl-icon{color:var(--dl-bad)}.dl-params-body{display:flex;flex-direction:column;gap:14px;padding:6px 14px 14px}.dl-params-body>.dl-setrow{margin:0;padding:0}.dl-pgrid.flush{padding:0;grid-template-columns:repeat(2,minmax(0,1fr))}@media(max-width:640px){.dl-pgrid.flush{grid-template-columns:minmax(0,1fr)}}.dl-qr-pane{display:flex;flex-direction:column;align-items:center;gap:8px;text-align:center}.dl-qr{width:min(280px,72vw);aspect-ratio:1;background:#fff;padding:8px;border-radius:12px;box-shadow:inset 0 0 0 1px var(--dl-line)}.dl-qr svg{display:block;width:100%;height:100%}.dl-filecard{display:flex;align-items:center;gap:12px;padding:12px;border-radius:14px;background:var(--dl-soft);min-width:0}.dl-filecard>.dl-stack{flex:1;min-width:0}.dl-filecard-ic{width:40px;height:46px;border-radius:8px;flex:none;display:inline-flex;align-items:center;justify-content:center;font:10px var(--dl-mono);color:var(--dl-fg-muted);background:var(--dl-card);box-shadow:inset 0 0 0 1px var(--dl-line)}.dl-params>.dl-conf{margin:0;border-top:1px solid var(--dl-line);border-radius:0 0 12px 12px;background:none}.dl-conf-sec{color:var(--dl-accent)}.dl-conf-k{color:var(--dl-fg-faint)}.dl-conf-mask{padding:0 6px;border-radius:4px;background:var(--dl-soft);color:var(--dl-fg-muted)}.dl-params>summary .dl-chipbtn{height:26px;font-size:12px}.dl-conf{white-space:pre-wrap;word-break:break-all;max-height:22em;overflow:auto;font-family:var(--dl-mono);font-size:12px;line-height:18px;margin:0;padding:12px;border-radius:12px;background:var(--dl-soft)}.dl-key{width:100%;box-sizing:border-box;font-family:var(--dl-mono);font-size:12px;word-break:break-all;min-height:7em}.dl-actions{display:flex;align-items:center;gap:6px;flex-wrap:wrap;margin:12px 0 0}.dl-link-box{display:flex;gap:6px;align-items:center;flex-wrap:wrap}.dl-link-box input{flex:1 1 18em;min-width:0;font-family:var(--dl-mono);font-size:12px}.dl-hint{font-size:12px;line-height:16px;color:var(--dl-fg-muted);margin:8px 0}.dl-divider{border:0;border-top:1px solid var(--dl-line);margin:16px 0}";var nr=".dl-checks{list-style:none;margin:0;padding:0}.dl-checks li{display:flex;align-items:center;gap:12px;padding:12px 0;border-top:1px solid var(--dl-line)}.dl-checks li:first-child{border-top:0;padding-top:0}.dl-checks li:last-child{padding-bottom:0}.dl-check-icon{flex:0 0 auto;width:28px;height:28px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center}.dl-check-icon .dl-icon{width:14px;height:14px}.dl-check-icon.ok{background:var(--dl-ok-wash);color:var(--dl-ok)}.dl-check-icon.warn{background:var(--dl-warn-wash);color:var(--dl-warn)}.dl-check-icon.error{background:var(--dl-bad-wash);color:var(--dl-bad)}.dl-check-icon.skip{background:var(--dl-soft);color:var(--dl-fg-faint)}.dl-check-body{flex:1;min-width:0}.dl-check-title{font-size:14px;line-height:20px;font-weight:500}.dl-check-detail{font-size:12px;line-height:16px;color:var(--dl-fg-muted);overflow-wrap:anywhere}.dl-check-repaired{margin-top:2px;font-size:12px;line-height:16px;color:var(--dl-warn)}.dl-wd{margin:0 0 16px;display:flex;flex-direction:column;gap:14px}.dl-wd-head{display:flex;align-items:center;gap:12px;min-width:0}.dl-wd-head>.dl-stack{min-width:0}.dl-wd-title{font-size:16px;line-height:24px;font-weight:500}.dl-wd-tile{flex:none;width:36px;height:36px;border-radius:10px;display:inline-flex;align-items:center;justify-content:center;background:var(--dl-ok-wash);color:var(--dl-ok)}.dl-wd-tile.off{background:var(--dl-soft);color:var(--dl-fg-faint)}.dl-wd-tile .dl-icon{width:18px;height:18px}.dl-wd-foot{display:flex;align-items:center;flex-wrap:wrap;gap:8px 16px;padding-top:14px;border-top:1px solid var(--dl-line)}.dl-wd-chips{display:flex;flex-wrap:wrap;gap:6px;flex:1 1 auto;min-width:0}.dl-wd-chips .dl-check-chip.error .dl-icon{color:var(--dl-bad)}.dl-warn-text{color:var(--dl-warn)!important}.dl-health-cols{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(440px,100%),1fr));gap:16px;align-items:start}.dl-health-cols>.dl-panel{margin:0;min-width:0}.dl-recent{display:flex;flex-direction:column}.dl-recent .dl-panel-head a{font-size:13px}.dl-recent-empty{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;padding:32px 16px;color:var(--dl-fg-muted);font-size:13px;border-top:1px solid var(--dl-line)}.dl-loading{margin:0;font-size:13px}.dl-diag-tabs{margin:0 0 16px}.dl-row.dl-slog-row{align-items:baseline}.dl-slog-row .dl-ev-tile{align-self:flex-start;margin-top:-1px}.dl-slog-row.has-detail{cursor:pointer}.dl-row.dl-slog-row.has-detail:hover{background:color-mix(in srgb,var(--sys) 11%,transparent)}.dl-slog-more{display:inline-flex;vertical-align:-2px;margin-left:6px;color:var(--dl-fg-faint);transform:rotate(90deg);transition:transform .15s}.dl-slog-more .dl-icon{width:14px;height:14px}.dl-slog-more.open{transform:rotate(-90deg)}.dl-slog-detail{margin:8px 0 2px;padding:8px 10px;border-radius:8px;background:var(--dl-soft);font-family:var(--dl-mono);font-size:12px;line-height:17px;white-space:pre-wrap;overflow-wrap:anywhere;color:var(--dl-fg-muted);cursor:text}.dl-table{width:100%;border-collapse:collapse;font-size:14px;line-height:20px}.dl-table th{text-align:left;font-weight:500;color:var(--dl-fg-faint);padding:0 8px 8px;border-bottom:1px solid var(--dl-line)}.dl-table td{padding:10px 8px;border-bottom:1px solid var(--dl-line);vertical-align:middle}.dl-table th:first-child,.dl-table td:first-child{padding-left:0}.dl-table th:last-child,.dl-table td:last-child{padding-right:0}.dl-table tr:last-child td{border-bottom:0}.dl-table .dl-right{text-align:right;white-space:nowrap}.dl-log{max-height:18em;overflow:auto;font-family:var(--dl-mono);font-size:12px;line-height:18px;margin:8px 0 0;padding:12px;white-space:pre-wrap;border-radius:12px;background:var(--dl-soft)}";var or=".dl-pagehead{display:flex;align-items:flex-end;justify-content:space-between;gap:16px;flex-wrap:wrap;margin:0 0 20px}.dl-h1{margin:0!important;padding:0!important;font-size:24px!important;line-height:32px!important;font-weight:500!important;border:0!important}.dl-title-row{display:flex;align-items:center;gap:10px;flex-wrap:wrap}.dl-stack{display:flex;flex-direction:column;gap:2px;min-width:0}.dl-stack.gap4{gap:4px}.dl-stack.gap8{gap:8px}.dl-sub{font-size:12px;line-height:16px;color:var(--dl-fg-muted)}.dl-ok{color:var(--dl-ok)}.dl-warn{color:var(--dl-warn)}.dl-bad{color:var(--dl-bad)}.dl-icon-only{width:auto!important;min-width:0!important;aspect-ratio:1 / 1;padding:0!important;justify-content:center;display:inline-flex!important;align-items:center;border-radius:999px!important}.dl-panel.flush{padding:0;overflow:hidden}.dl-panel-head.pad{padding:16px 16px 12px;margin:0}.dl-col{display:flex;flex-direction:column;gap:16px;min-width:0}.dl-col>.dl-panel,.dl-col>section.dl-panel{margin:0}.dl-crumbs{display:flex;gap:8px;align-items:center;font-size:14px;margin:0 0 16px;color:var(--dl-fg-faint)}.dl-crumbs a{color:var(--dl-fg-faint)}.dl-crumbs a:hover{color:var(--dl-fg)}.dl-crumbs span:last-child{color:var(--dl-fg)}.dl-metrics{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));background:var(--dl-card);border:1px solid var(--dl-line);border-radius:var(--dl-radius);margin:0 0 16px;box-shadow:var(--dl-shadow)}.dl-metric{display:flex;flex-direction:column;gap:4px;padding:16px 20px;min-width:0}.dl-metric+.dl-metric{border-left:1px solid var(--dl-line)}.dl-metric-label{font-size:12px;font-weight:500;color:var(--dl-fg-faint)}.dl-metric-value{font-size:28px;line-height:36px;font-weight:500;letter-spacing:-.01em;font-variant-numeric:tabular-nums;white-space:nowrap}.dl-metric-value .dl-faint{font-size:16px}.dl-metric-sub{font-size:12px;color:var(--dl-fg-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}@media(max-width:900px){.dl-metrics{grid-template-columns:repeat(2,minmax(0,1fr))}.dl-metric:nth-child(3){border-left:0}.dl-metric:nth-child(n+3){border-top:1px solid var(--dl-line)}}.dl-seg{display:inline-flex;gap:2px;padding:3px;border-radius:999px;background:var(--dl-soft);flex-wrap:wrap}.dl-seg button{all:unset;cursor:pointer;display:inline-flex;align-items:center;gap:6px;padding:4px 12px;border-radius:999px;font-size:13px;font-weight:500;color:var(--dl-fg-muted);white-space:nowrap}.dl-seg button:hover{color:var(--dl-fg)}.dl-seg button.on{background:var(--dl-soft-hover);color:var(--dl-fg)}.dl-seg.dl-srvsections{flex-wrap:nowrap;max-width:100%;overflow-x:auto;scrollbar-width:none}.dl-seg.dl-srvsections::-webkit-scrollbar{display:none}.dl-seg.dl-srvsections button{flex:none;white-space:nowrap}.dl-seg button:focus-visible{outline:2px solid var(--dl-ring)}.dl-seg button b{font-weight:500;font-size:11px;padding:0 6px;border-radius:999px;background:var(--dl-soft)}.dl-seg button b.warn{background:var(--dl-warn-wash);color:var(--dl-warn)}.dl-seg.sm button{padding:2px 9px;font-size:11px}.dl-seg.wide{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));border-radius:12px;padding:4px}.dl-seg.wide button{flex-direction:column;justify-content:center;padding:8px 6px;border-radius:9px;gap:3px}.dl-seg.wide button.on{background:var(--dl-primary);color:var(--dl-primary-fg)}";var ar=`.dl-geomap{position:relative;border-top:1px solid var(--dl-line);background:transparent}.dl-map-status{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;color:var(--dl-fg-muted);font-size:13px;z-index:1;pointer-events:none}.dl-map-wrap{position:relative}.dl-map-legend{position:absolute;left:12px;bottom:12px;display:flex;gap:12px;align-items:center;padding:6px 12px;border-radius:999px;font-size:12px;background:color-mix(in srgb,var(--dl-card) 88%,transparent);border:1px solid var(--dl-line);backdrop-filter:blur(6px);z-index:2}.dl-map-legend span{display:inline-flex;align-items:center;gap:6px;color:var(--dl-fg-muted)}.dl-map-legend i.line{width:14px;height:0;border-top:2px dashed #8a8a8a}.dl-map-legend i.line.live{border-top-color:#3b82f6}.dl-map-off{padding:32px 16px;text-align:center;color:var(--dl-fg-muted);border-top:1px solid var(--dl-line)}.dl-mk{all:unset;cursor:pointer;position:relative;display:flex;align-items:center;justify-content:center;transition:opacity .2s}.dl-mk-hub{position:relative;display:flex;align-items:center;justify-content:center}.dl-mk-host{box-sizing:border-box;width:40px;height:40px;border-radius:11px;display:flex;align-items:center;justify-content:center;background:color-mix(in srgb,var(--dl-elevated) 60%,transparent);border:1px solid var(--dl-line);backdrop-filter:blur(6px);box-shadow:0 6px 16px #00000059}.dl-mk-host-tile{width:26px;height:26px;border-radius:7px;display:flex;align-items:center;justify-content:center;background:var(--dl-fg);color:var(--background, var(--dl-elevated))}.dl-mk-host-ic{width:14px;height:14px}.dl-mk-av{position:relative;box-sizing:border-box;width:28px;height:28px;border-radius:50%;display:flex;align-items:center;justify-content:center;font-size:10px;font-weight:500;line-height:1;border:2px solid #8a8a8a;background:var(--dl-elevated);color:var(--dl-fg-muted);transition:box-shadow .2s}.dl-mk.online .dl-mk-av{border-color:#3b82f6;background:color-mix(in srgb,#3b82f6 22%,var(--dl-elevated));color:var(--dl-fg)}.dl-mk-badge{position:absolute;left:16px;bottom:-6px;height:16px;min-width:16px;padding:0 3px;border-radius:8px;border:2px solid var(--dl-elevated);background:#6b6b6b;color:#fff;display:flex;align-items:center;justify-content:center;gap:1px;font-size:9px;font-weight:600;white-space:nowrap;box-sizing:content-box}.dl-mk.online .dl-mk-badge{background:#3b82f6}.dl-mk-badge-ic{width:10px;height:10px;stroke-width:2.2}.dl-mk-badge:has(>svg:only-child){width:16px;min-width:0;padding:0}.dl-mk-tile{position:relative;width:26px;height:26px;border-radius:7px;display:flex;align-items:center;justify-content:center;background:color-mix(in srgb,var(--dl-fg) 18%,var(--dl-elevated));color:var(--dl-fg)}.dl-mk.place.online .dl-mk-tile{background:#3b82f6;color:#fff;box-shadow:0 2px 8px #3b82f659}.dl-mk-tile-ic{width:14px;height:14px}.dl-mk-tile-n{position:absolute;right:-5px;top:-5px;min-width:14px;height:14px;padding:0 3px;box-sizing:border-box;border-radius:7px;background:var(--dl-fg);color:var(--dl-elevated);font-size:9px;font-weight:600;line-height:14px;text-align:center}.dl-mk-when{display:block;text-align:center;color:var(--dl-fg-faint);font-weight:400}.dl-mk.place.online .dl-mk-when{color:#3b82f6}.dl-mk-tile.sm{width:18px;height:18px;border-radius:5px;font-size:9px;font-weight:600}.dl-dmap{border:1px solid var(--dl-line);border-radius:12px;overflow:hidden}.dl-dmap .dl-geomap{border-top:0}.dl-dplaces{display:flex;flex-direction:column;margin-top:4px}.dl-dplace-row{display:flex;align-items:center;gap:10px;padding:9px 2px;border-top:1px solid var(--dl-line);font-size:13px}.dl-dplace-row:first-child{border-top:0}.dl-dplace-n{flex:0 0 auto;width:20px;height:20px;border-radius:5px;display:flex;align-items:center;justify-content:center;font-size:10px;font-weight:600;background:color-mix(in srgb,var(--dl-fg) 18%,var(--dl-elevated));color:var(--dl-fg)}.dl-dplace-n.live{background:#3b82f6;color:#fff}.dl-dplace-n .dl-icon{width:12px;height:12px}.dl-dplace-now{color:#3b82f6}.dl-mk>*{transition:opacity .15s;opacity:var(--dl-mk-fade, 1)}.dl-mk.merged,.dl-mk.piled{pointer-events:none}.dl-mk.dl-mk-new>*{transition:none}.dl-mk.merged>*,.dl-mk.piled>*{opacity:0}.dl-mk-hub{cursor:default}.dl-mk-host{position:relative}.dl-mk-host{transition:border-radius .22s ease,border-right-color .22s ease}.dl-mk-host.docked{border-top-right-radius:0;border-bottom-right-radius:0;border-right-color:transparent}.dl-mk-dock{position:absolute;left:100%;top:-1px;height:40px;box-sizing:border-box;display:flex;align-items:center;gap:6px;padding:0 10px 0 2px;border:1px solid var(--dl-line);border-left:0;border-radius:0 11px 11px 0;background:color-mix(in srgb,var(--dl-elevated) 60%,transparent);backdrop-filter:blur(6px);box-shadow:0 6px 16px #00000059;pointer-events:none;opacity:0;clip-path:inset(-24px 100% -24px 0);transition:clip-path .28s cubic-bezier(.2,.8,.2,1),opacity .2s ease}.dl-mk-host.docked .dl-mk-dock{pointer-events:auto;opacity:1;clip-path:inset(-24px -24px -24px 0)}.dl-mk-new .dl-mk-host,.dl-mk-new .dl-mk-dock{transition:none}.dl-mk-pile{position:relative;display:flex;justify-content:center}.dl-mk-pile-box{box-sizing:border-box;height:40px;display:flex;align-items:center;gap:6px;padding:0 10px 0 6px;border-radius:20px;cursor:zoom-in;background:color-mix(in srgb,var(--dl-elevated) 60%,transparent);border:1px solid var(--dl-line);backdrop-filter:blur(6px);box-shadow:0 6px 16px #00000059;animation:dl-plate-in .26s cubic-bezier(.2,.8,.2,1) both;transition:opacity .18s ease,transform .18s ease}.dl-mk-pile.out{pointer-events:none}.dl-mk-pile.out>*{opacity:0;transform:scale(.85);transition:opacity .18s ease,transform .18s ease}@keyframes dl-plate-in{0%{opacity:0;transform:scale(.85)}}.dl-mk-face{all:unset;position:relative;display:flex;cursor:pointer;transition:transform .18s ease,opacity .18s ease}.dl-mk-face>.dl-mk-badge{position:relative;left:auto;bottom:-8px;margin-left:-12px;align-self:center}.dl-mk-face.on .dl-mk-av{border-color:#3b82f6;background:color-mix(in srgb,#3b82f6 22%,var(--dl-elevated));color:var(--dl-fg)}.dl-mk-face.on .dl-mk-badge{background:#3b82f6}.dl-mk-face:hover .dl-mk-av{box-shadow:0 0 0 4px #3b82f640}.dl-mk-face.in{animation:dl-dock-in .24s cubic-bezier(.2,.8,.2,1) both}.dl-mk-face.out{transform:scale(.4);opacity:0;pointer-events:none}@keyframes dl-dock-in{0%{transform:scale(.4);opacity:0}}.dl-mk-more{font-size:11px;font-weight:600;color:var(--dl-fg-muted)}.dl-mk-av,.dl-mk-tile{transition:box-shadow .2s,transform .24s cubic-bezier(.2,.8,.2,1)}.dl-mk.merged .dl-mk-av,.dl-mk.merged .dl-mk-tile,.dl-mk.piled .dl-mk-av{transform:scale(.5)}.dl-mk-host,.dl-mk-dock,.dl-mk-pile-box{transition-property:border-radius,border-right-color,clip-path,opacity,height,width,padding,gap}.dl-mk-dock,.dl-mk-pile-box{transition-duration:.22s;transition-timing-function:cubic-bezier(.2,.8,.2,1)}.dl-mk-pile-box{position:relative}.dl-mk-more{transition:transform .22s cubic-bezier(.2,.8,.2,1),opacity .18s ease}.dl-mk-more.in{animation:dl-dock-in .24s ease both}.dl-mk-more.out{transform:scale(.4);opacity:0}.dl-mk-face .dl-mk-av{transition:box-shadow .2s,transform .24s cubic-bezier(.2,.8,.2,1),width .2s ease,height .2s ease,font-size .2s ease}.dl-mk-face{transition:transform .22s cubic-bezier(.2,.8,.2,1),opacity .18s ease,margin .2s ease}.dl-mk-face>.dl-mk-badge{max-width:48px;overflow:hidden;transition:opacity .2s ease,transform .2s ease,max-width .22s ease,margin .22s ease,padding .22s ease,border-width .22s ease,height .22s ease,min-width .22s ease,width .22s ease,bottom .22s ease}.dl-lod-far .dl-mk-host{width:32px;height:32px;border-radius:9px}.dl-lod-far .dl-mk-host.docked{border-radius:9px 0 0 9px}.dl-lod-far .dl-mk-host-tile{width:20px;height:20px;border-radius:6px}.dl-lod-far .dl-mk-host-ic{width:11px;height:11px}.dl-lod-far .dl-mk-dock{height:32px;gap:0;padding:0 4px 0 0;border-radius:0 9px 9px 0}.dl-lod-far .dl-mk-pile-box{height:32px;gap:0;padding:0 4px;border-radius:16px}.dl-lod-far .dl-mk-face+.dl-mk-face{margin-left:-6px}.dl-lod-far .dl-mk-face .dl-mk-av{width:22px;height:22px;font-size:8px;box-shadow:0 0 0 2px var(--dl-elevated)}.dl-lod-far .dl-mk-face>.dl-mk-badge{max-width:0;min-width:0;padding:0;margin-left:0;border-width:0;opacity:0;transform:scale(.5);pointer-events:none}.dl-lod-far .dl-mk-more{margin-left:4px;font-size:10px}.dl-mk-label{transition:opacity .2s ease}.dl-lod-far .dl-mk-label{opacity:0}.dl-lod-mid .dl-mk-host{width:36px;height:36px}.dl-lod-mid .dl-mk-dock,.dl-lod-mid .dl-mk-pile-box{height:36px}.dl-lod-mid .dl-mk-face .dl-mk-av{width:24px;height:24px;font-size:9px}.dl-lod-mid .dl-mk-face>.dl-mk-badge{height:12px;min-width:12px;margin-left:-10px;bottom:-7px}.dl-lod-mid .dl-mk-face>.dl-mk-badge:has(>svg:only-child){width:12px}.dl-lod-mid .dl-mk-face>.dl-mk-badge .dl-mk-badge-ic{width:8px;height:8px}@media(prefers-reduced-motion:reduce){.dl-mk-dock,.dl-mk-pile-box,.dl-mk-face,.dl-mk-av,.dl-mk-tile,.dl-mk-host,.dl-mk-face>.dl-mk-badge{transition:none;animation:none}}.dl-mk-hub:has(.dl-mk-host.docked) .dl-mk-host{cursor:zoom-in}.dl-mk-ptr{position:absolute;left:50%;top:50%;width:0;height:0;z-index:-1;pointer-events:none}.dl-mk-ptr .line{position:absolute;left:0;top:-.5px;height:1px;background:var(--dl-fg-faint);transform-origin:0 50%}.dl-mk-ptr .spot{position:absolute;left:-3.5px;top:-3.5px;width:7px;height:7px;border-radius:50%;box-sizing:border-box;border:1.5px solid #fff;background:#8a8a8a}.dl-mk.online .dl-mk-ptr .spot,.dl-mk.place.online .dl-mk-ptr .spot{background:#3b82f6}.dl-mk.dim>*{opacity:.18}.dl-mk.hl .dl-mk-av{box-shadow:0 0 0 4px #3b82f640}.dl-mk-label{position:absolute;left:50%;bottom:100%;margin-bottom:4px;transform:translate(-50%);white-space:nowrap;pointer-events:none;font-size:10px;line-height:14px;font-weight:500;color:var(--dl-fg)}.dl-mk-label.below{bottom:auto;top:100%;margin:4px 0 0}.dl-mk-label.chip{padding:2px 6px;border-radius:4px;font-size:11px;line-height:16px;font-weight:600;background:color-mix(in srgb,var(--background, var(--dl-card)) 80%,transparent);backdrop-filter:blur(8px)}.dl-geomap .maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib.maplibregl-compact{margin:0 10px 10px 0;min-height:28px;padding:0;border-radius:8px;background:var(--dl-elevated);border:1px solid var(--dl-line);color:var(--dl-fg-muted);box-shadow:none;font-size:11px;line-height:26px}.dl-geomap .maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib.maplibregl-compact:not(.maplibregl-compact-show){width:28px;height:28px;box-sizing:border-box}.dl-geomap .maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib.maplibregl-compact.maplibregl-compact-show{padding:0 32px 0 10px}.dl-geomap .maplibregl-ctrl-attrib a{color:var(--dl-fg-muted)}.dl-geomap .maplibregl-ctrl-attrib-button{top:0;right:0;width:26px;height:26px;margin:0;border-radius:8px;background:none}.dl-geomap .maplibregl-ctrl-attrib-button:after{content:"";position:absolute;inset:5px;background:var(--dl-fg);-webkit-mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill-rule='evenodd' d='M12 2a10 10 0 1 1 0 20 10 10 0 0 1 0-20Zm-1.2 8.2h2.4V17h-2.4v-6.8ZM12 6a1.4 1.4 0 1 0 0 2.8A1.4 1.4 0 0 0 12 6Z'/%3E%3C/svg%3E") center / contain no-repeat;mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill-rule='evenodd' d='M12 2a10 10 0 1 1 0 20 10 10 0 0 1 0-20Zm-1.2 8.2h2.4V17h-2.4v-6.8ZM12 6a1.4 1.4 0 1 0 0 2.8A1.4 1.4 0 0 0 12 6Z'/%3E%3C/svg%3E") center / contain no-repeat}.dl-geomap .maplibregl-ctrl-attrib-button:focus{outline:none;box-shadow:none}.dl-geomap .maplibregl-ctrl-attrib-button:focus-visible{outline:2px solid var(--dl-ring)}.dl-map-card{position:absolute;right:12px;top:12px;z-index:3;min-width:200px;max-width:260px;padding:10px 12px;border-radius:10px;font-size:12px;line-height:20px;background:var(--dl-elevated);color:var(--dl-fg);border:1px solid var(--dl-line);box-shadow:var(--shadow-xl, 0 8px 16px -4px rgba(0,0,0,.4));opacity:0;transition:opacity .2s;pointer-events:none}.dl-map-card.on{opacity:1}.dl-map-card-head b{font-weight:500}.dl-map-card-row{display:flex;justify-content:space-between;gap:12px;white-space:nowrap}.dl-popcard{position:fixed;z-index:2100;width:max-content;max-width:300px;padding:12px;border-radius:12px;box-sizing:border-box;background:var(--dl-elevated);color:var(--dl-fg);border:1px solid var(--dl-line);box-shadow:var(--shadow-xl, 0 8px 16px -4px rgba(0,0,0,.4))}.dl-popcard.away{visibility:hidden}.dl-popcard.leaving{pointer-events:none}.dl-popcard-tip{position:absolute;left:var(--tip-x, 50%);width:10px;height:10px;margin-left:-6px;box-sizing:border-box;background:var(--dl-elevated);border:solid var(--dl-line);transform:rotate(45deg)}.dl-popcard.above .dl-popcard-tip{bottom:-6px;border-width:0 1px 1px 0}.dl-popcard.below .dl-popcard-tip{top:-6px;border-width:1px 0 0 1px}.dl-popcard.above{transform-origin:var(--tip-x, 50%) 100%}.dl-popcard.below{transform-origin:var(--tip-x, 50%) 0}@media(prefers-reduced-motion:no-preference){.dl-popcard{animation:dl-pop-in .16s ease-out}.dl-popcard.leaving{animation:dl-pop-out .14s ease-in forwards}}@keyframes dl-pop-in{0%{opacity:0;transform:scale(.94)}to{opacity:1;transform:none}}@keyframes dl-pop-out{0%{opacity:1;transform:none}to{opacity:0;transform:scale(.94)}}.dl-pop{display:flex;flex-direction:column;gap:4px;font-size:12px;line-height:18px;min-width:210px}.dl-pop-head{display:flex;align-items:center;gap:8px;font-size:13px;margin-bottom:2px}.dl-pop-net{width:30px;height:30px;border-radius:9px;background:var(--dl-soft);display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;color:var(--dl-fg-muted)}.dl-pop-list{display:flex;flex-direction:column;margin:6px 0 0;max-height:116px;overflow-y:auto}.dl-pop-row{all:unset;cursor:pointer;display:flex;align-items:center;gap:8px;padding:6px 8px;border-radius:8px}.dl-pop-row:hover{background:var(--dl-soft)}.dl-pop-row:focus{outline:none}.dl-pop-row:focus-visible{outline:2px solid var(--dl-ring)}.dl-pop-name{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.dl-pop-name b{font-weight:500}.dl-pop-dot{width:6px;height:6px;border-radius:50%;background:var(--dl-fg-faint);flex:0 0 auto}.dl-pop-dot.on{background:var(--dl-ok);box-shadow:0 0 0 3px var(--dl-ok-wash)}.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}.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)}.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-spark i:hover{opacity:1;filter:brightness(1.25)}.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;gap:2px;flex:0 0 auto}.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}`;var rr=`.dl-row{display:flex;align-items:center;gap:12px;padding:12px 16px;border-top:1px solid var(--dl-line);font-size:14px;line-height:20px;min-width:0}.dl-row.link{color:inherit;text-decoration:none}.dl-row.link:hover{background:var(--dl-soft)}.dl-row-main{flex:1;min-width:0;overflow-wrap:anywhere}.dl-row-main b{font-weight:500}.dl-attn{display:flex;flex-direction:column;gap:10px;padding:16px;border-top:1px solid var(--dl-line)}.dl-attn-item{display:flex;gap:10px;align-items:baseline;font-size:13px;color:var(--dl-fg-muted)}.dl-avatar.sm{width:26px;height:26px;font-size:10px;margin:0}.dl-avatar.lg{width:48px;height:48px;font-size:15px;margin:0}.dl-avatar.lg.online:after{width:12px;height:12px}.dl-list{border:1px solid var(--dl-line);border-radius:12px;overflow:hidden}.dl-list>.dl-row:first-child{border-top:0}.dl-ellipsis{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.dl-row-main.dl-stack{min-width:0}.dl-person-id{display:flex;align-items:center;gap:14px;min-width:0}.dl-grid-person{display:grid;grid-template-columns:minmax(0,1.7fr) minmax(0,1fr);gap:16px;align-items:start}@media(max-width:1000px){.dl-grid-person{grid-template-columns:minmax(0,1fr)}}.dl-devsec{display:flex;flex-direction:column;gap:12px}.dl-devsec .dl-panel-head{margin:0}.dl-dgrid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}.dl-dcard>.dl-dcard-head+*{margin-top:auto}@media(max-width:700px){.dl-dgrid{grid-template-columns:minmax(0,1fr)}}.dl-dgrid>.dl-dslot.add:only-child{grid-column:1 / -1}.dl-dcard{background:var(--dl-card);border:1px solid var(--dl-line);border-radius:14px;padding:14px;display:flex;flex-direction:column;gap:12px;min-width:0;box-shadow:var(--dl-shadow)}.dl-dcard.online{border-color:color-mix(in srgb,var(--dl-ok) 35%,transparent)}.dl-dcard.off{opacity:.7}.dl-dcard-head{display:flex;align-items:center;gap:12px}.dl-dcard-ic{width:40px;height:40px;border-radius:12px;background:var(--dl-soft);display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;color:var(--dl-fg-muted)}.dl-dcard-ic .dl-icon{width:20px;height:20px}.dl-dcard.online .dl-dcard-ic{background:var(--dl-ok-wash);color:var(--dl-ok)}.dl-dcard-title{all:unset;cursor:pointer;flex:1;min-width:0;display:flex;flex-direction:column}.dl-dcard-title b{font-weight:500;font-size:15px}.dl-dstat{display:inline-flex;align-items:center;gap:6px;font-size:12px;color:var(--dl-fg-muted);white-space:nowrap;min-width:0}.dl-dstat i.dot{flex:none}.dl-dstat.ok{color:var(--dl-ok)}.dl-dstat.warn{color:var(--dl-warn)}.dl-dstat i.dot,.dl-savebar i.dot{width:6px;height:6px;border-radius:50%;background:var(--dl-fg-faint)}.dl-dstat i.dot.ok{background:var(--dl-ok);box-shadow:0 0 0 3px var(--dl-ok-wash)}.dl-dstat i.dot.warn{background:var(--dl-warn)}.dl-dcard-use{display:flex;align-items:flex-end;justify-content:space-between;gap:12px}.dl-dcard-foot{padding-top:10px;border-top:1px solid var(--dl-line);font-size:11px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.dl-dslot.add{all:unset;box-sizing:border-box;cursor:pointer;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;padding:14px;min-height:0;border:1px dashed color-mix(in srgb,currentColor 18%,transparent);border-radius:14px;text-align:center;color:var(--dl-fg-muted);transition:background .15s,border-color .15s,color .15s}.dl-dslot.add .dl-stack{align-items:center}.dl-dslot.add:hover{border-color:color-mix(in srgb,currentColor 35%,transparent);color:var(--dl-fg)}.dl-dslot.add:focus-visible{outline:2px solid var(--dl-ring);outline-offset:2px}.dl-dslot.add b{font-weight:500}.dl-dslot.add:hover{background:var(--dl-soft)}.dl-dslot-ic{width:36px;height:36px;border-radius:999px;background:var(--dl-soft);display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;color:var(--dl-fg-muted)}.dl-dslot.add:hover .dl-dslot-ic{background:var(--dl-primary);color:var(--dl-primary-fg)}.dl-tiles2{display:grid;gap:10px;margin-top:16px}.dl-tile2{border:1px solid var(--dl-line);border-radius:14px;padding:14px;display:flex;flex-direction:column;gap:10px;min-width:0}.dl-tile2-label{display:flex;align-items:center;justify-content:space-between;gap:8px;font-size:12px;font-weight:500;color:var(--dl-fg-faint)}.dl-tile2-row{display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap}.dl-tile2-value{font-size:20px;line-height:28px;font-weight:500;letter-spacing:-.01em;font-variant-numeric:tabular-nums}.dl-tile2-value .dl-faint{font-size:14px;font-weight:400}.dl-tile2-foot{display:flex;align-items:center;justify-content:space-between;gap:12px;padding-top:10px;border-top:1px solid var(--dl-line);font-size:12px}.dl-stepper{display:inline-flex;align-items:stretch;height:32px;border:1px solid var(--input, var(--dl-line));border-radius:8px;overflow:hidden}.dl-stepper button{all:unset;cursor:pointer;width:32px;display:inline-flex;align-items:center;justify-content:center;font-size:16px;color:var(--dl-fg)}.dl-stepper button:hover{background:var(--dl-soft)}.dl-stepper button[disabled]{opacity:.35;cursor:not-allowed}.dl-stepper+.dl-stepper{margin-left:4px}.dl-step-select{border:0!important;border-left:1px solid var(--input, var(--dl-line))!important;border-right:1px solid var(--input, var(--dl-line))!important;border-radius:0!important;background:transparent!important;color:inherit;font:500 13px inherit;padding:0 10px!important;height:100%!important;min-width:0!important}.dl-slots{display:grid;grid-auto-flow:column;grid-auto-columns:minmax(0,1fr);gap:3px}.dl-slots i{height:4px;border-radius:999px;background:var(--dl-track);display:block}.dl-slots i.used{background:var(--dl-fg)}.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)}.dl-switch{all:unset;cursor:pointer;position:relative;width:32px;height:20px;border-radius:999px;background:var(--switch-off, var(--dl-track));flex:0 0 auto;transition:background .15s}.dl-switch i{position:absolute;left:2px;top:2px;width:16px;height:16px;border-radius:50%;background:#fff;transition:left .15s;box-shadow:0 1px 2px #0000004d}.dl-switch.on{background:var(--dl-accent)}.dl-switch.on i{left:14px}.dl-switch:focus-visible{outline:2px solid var(--dl-ring);outline-offset:2px}.dl-linkbox{display:flex;align-items:center;gap:8px;height:36px;padding:0 4px 0 12px;border:1px solid var(--input, var(--dl-line));border-radius:8px;background:var(--input-bg, transparent)}.dl-linkbox .dl-mono{flex:1;min-width:0;font-size:12px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:var(--dl-fg-muted)}.dl-linkbox .cbi-button{height:28px!important}.dl-pcard{display:grid;grid-template-columns:minmax(0,1fr) 260px;gap:20px;align-items:stretch;min-width:0}.dl-pcard-main{min-width:0}.dl-pcard-top{display:flex;align-items:center;gap:12px;min-width:0}.dl-pcard-top .dl-avatar{margin-right:0}.dl-pcard-who{flex:1;min-width:0}.dl-pcard-who .dl-slotbar{margin:3px 0 0}.dl-pside{display:flex;flex-direction:column;justify-content:space-between;gap:8px;padding-left:20px;border-left:1px solid var(--dl-line);min-width:0}.dl-pside-top{display:flex;align-items:center;justify-content:space-between;gap:8px}.dl-pside-state{display:inline-flex;align-items:center;gap:6px;font-size:13px;color:var(--dl-fg-muted)}.dl-pside-state.live{color:var(--dl-ok)}.dl-pside-foot{font-size:12px}.dl-pside .dl-use-num b{font-size:20px}.dl-none{display:none!important}.dl-pcard-actions{display:flex;gap:6px;flex:0 0 auto}.dl-pcard-actions .cbi-button{height:32px!important}.dl-icon-only .dl-btn-label{display:none}.dl-pill-ic{display:inline-flex;align-items:center;gap:4px;height:22px;padding:0 8px;border-radius:999px;font-size:12px;white-space:nowrap;background:var(--dl-soft);color:var(--dl-fg-muted)}.dl-pill-ic .dl-icon{width:12px;height:12px}.dl-pill-ic.warn{background:var(--dl-warn-wash);color:var(--dl-warn)}.dl-pill-ic.bad{background:var(--dl-bad-wash);color:var(--dl-bad)}.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-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}.dl-card-name{color:var(--dl-fg)!important;text-decoration:none}.dl-card-name:hover{text-decoration:underline}.dl-chip-tag{font-size:11px;line-height:18px;padding:0 6px;border-radius:999px;background:var(--dl-warn-wash);color:var(--dl-warn)}.dl-chip.live{background:var(--dl-ok-wash);color:color-mix(in srgb,var(--dl-ok) 35%,var(--dl-fg))}.dl-chip.live:hover{background:color-mix(in srgb,var(--dl-ok) 22%,transparent)}.dl-chip.live .dl-icon{color:var(--dl-ok)}.dl-fixes{display:flex;gap:6px;flex-wrap:wrap;margin:10px 0 0 44px}.dl-fix{all:unset;cursor:pointer;height:26px;padding:0 10px;border-radius:999px;background:var(--dl-info-wash);color:var(--dl-info);font-size:12px;font-weight:500;display:inline-flex;align-items:center}.dl-fix:hover{filter:brightness(1.15)}@media(max-width:760px){.dl-pcard{grid-template-columns:1fr}.dl-pside{padding:12px 0 0;border-left:0;border-top:1px solid var(--dl-line)}.dl-fixes{margin-left:0}}.dl-select{height:34px!important;border-radius:999px!important;min-width:136px!important;width:auto!important;padding:0 34px 0 14px!important;appearance:none!important;-webkit-appearance:none!important;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b8f98' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E")!important;background-repeat:no-repeat!important;background-position:right 12px center!important;background-size:14px!important}.dl-savebar{position:fixed;left:50%;bottom:24px;transform:translate(-50%,160%);opacity:0;transition:transform .25s cubic-bezier(.2,.8,.2,1),opacity .2s;display:flex;align-items:center;gap:10px;padding:8px 8px 8px 18px;border-radius:999px;background:var(--dl-elevated);border:1px solid var(--dl-line);box-shadow:var(--shadow-2xl, 0 16px 32px -8px rgba(0,0,0,.5));z-index:60;pointer-events:none}.dl-savebar.show{transform:translate(-50%);opacity:1;pointer-events:auto}.dl-savebar-text{display:inline-flex;align-items:center;gap:8px;font-size:13px;font-weight:500}`;var ir=".dl-toast strong{display:block;font-weight:500}.dl-toast div{opacity:.8;font-size:13px}.dl-drawer-overlay{position:fixed;inset:0;z-index:900;display:flex;justify-content:flex-end;background:transparent;transition:background .2s}.dl-drawer-overlay.open{background:var(--scrim, rgba(0,0,0,.45))}.dl-drawer{width:min(520px,100%);height:100%;display:flex;flex-direction:column;background:var(--dialog-bg, var(--dl-elevated));color:var(--dl-fg);border-left:1px solid var(--dl-line);box-shadow:var(--shadow-2xl, -16px 0 32px -8px rgba(0,0,0,.5));transform:translate(100%);transition:transform .22s cubic-bezier(.2,.8,.2,1)}.dl-drawer-overlay.open .dl-drawer{transform:none}.dl-drawer-head{display:flex;align-items:center;gap:12px;padding:16px 20px;border-bottom:1px solid var(--dl-line)}.dl-drawer-title{flex:1;min-width:0;display:flex;align-items:center;gap:12px}.dl-drawer-title h3{margin:0!important;padding:0!important;border:0!important;font-size:18px!important;line-height:26px;font-weight:500!important}.dl-drawer-x{all:unset;cursor:pointer;width:32px;height:32px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;color:var(--dl-fg-muted)}.dl-drawer-x:hover{background:var(--dl-soft);color:var(--dl-fg)}.dl-drawer-body{flex:1;overflow:auto;padding:20px}.dl-drawer-foot{padding:12px 20px;border-top:1px solid var(--dl-line)}.dl-drawer-actions{display:flex;align-items:center;gap:8px}.dl-dcard-ic.on{background:var(--dl-ok-wash);color:var(--dl-ok)}.dl-icon-only.sm{width:28px;height:28px!important}.dl-stack.gap12{gap:12px}.dl-stack.gap16{gap:16px}.dl-dstats{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));border:1px solid var(--dl-line);border-radius:14px;overflow:hidden}.dl-dstats-cell{display:flex;flex-direction:column;gap:4px;padding:12px 14px;min-width:0}.dl-dstats-cell.wide{grid-column:span 2;border-bottom:1px solid var(--dl-line)}.dl-dstats-cell+.dl-dstats-cell:not(.wide):last-child{border-left:1px solid var(--dl-line)}.dl-dstats-cell b{font-size:16px;font-weight:500;font-variant-numeric:tabular-nums}.dl-dstats-cell .dl-dstat{font-size:14px}.dl-dsec{border:1px solid var(--dl-line);border-radius:14px;padding:16px;display:flex;flex-direction:column;gap:12px}.dl-dsec-head{display:flex;align-items:center;justify-content:space-between;gap:12px}.dl-dsec-head h4{margin:0!important;padding:0!important;font-size:14px!important;font-weight:500!important;border:0!important}.dl-dstat i.dot{width:6px;height:6px;border-radius:50%;background:var(--dl-fg-faint);display:inline-block}.dl-connect-body{min-height:60px}.dl-connect-body .dl-qr{width:min(240px,70vw)}.dl-kv2{display:flex;flex-direction:column}.dl-kvrow{display:flex;align-items:center;justify-content:space-between;gap:16px;padding:9px 0;border-top:1px solid var(--dl-line);font-size:13px;min-width:0}.dl-kvrow:first-child{border-top:0;padding-top:0}.dl-kvrow-k{color:var(--dl-fg-muted);flex:0 0 auto}.dl-kvrow-v{min-width:0;text-align:right;overflow-wrap:anywhere}.dl-kvrow-v.copy{all:unset;cursor:pointer;display:inline-flex;align-items:center;gap:6px;min-width:0;color:var(--dl-fg)}.dl-kvrow-v.copy span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-kvrow-v.copy .dl-icon{width:13px;height:13px;color:var(--dl-fg-faint)}.dl-kvrow-v.copy:hover .dl-icon{color:var(--dl-fg)}@media(max-width:560px){.dl-drawer{width:100%}.dl-dstats{grid-template-columns:minmax(0,1fr)}.dl-dstats-cell.wide{grid-column:auto}.dl-dstats-cell+.dl-dstats-cell:not(.wide):last-child{border-left:0;border-top:1px solid var(--dl-line)}}.dl-dev-log{display:flex;flex-direction:column}.dl-dev-log-row{display:flex;align-items:center;gap:10px;padding:8px 0;border-top:1px solid var(--dl-line);font-size:13px;line-height:20px;min-width:0}.dl-dev-log-row:first-child{border-top:0;padding-top:0}.dl-dev-log-row .dl-row-main{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}";var sr=".dl-settings-main{min-width:0;display:flex;flex-direction:column;gap:20px}.dl-setsec{background:var(--dl-card);border:1px solid var(--dl-line);border-radius:var(--dl-radius);overflow:hidden;scroll-margin-top:88px;box-shadow:var(--dl-shadow)}.dl-setsec-body{padding:20px;display:flex;flex-direction:column;gap:14px}.dl-setsec-body h3{margin:0!important;padding:0!important;font-size:18px!important;line-height:26px;font-weight:500!important;border:0!important}.dl-setsec-body p{margin:0}.dl-setsec-head{display:flex;align-items:center;gap:10px}.dl-group{border:1px solid var(--dl-line);border-radius:14px;padding:2px 16px}.dl-group-head{display:flex;align-items:center;gap:12px;padding:14px 0 10px}.dl-group-head b{font-size:15px;font-weight:500}.dl-group-ic{width:32px;height:32px;border-radius:10px;background:var(--dl-soft);color:var(--dl-fg-muted);display:inline-flex;align-items:center;justify-content:center;flex:none}.dl-group-ic .dl-icon-wrap{display:inline-flex}.dl-group-ic .dl-icon{width:16px;height:16px}.dl-group-body>*{padding:12px 0;margin:0!important}.dl-group-body>*+*:not(.alert-message):not(.dl-params){border-top:1px solid var(--dl-line)}.dl-group-body>.alert-message,.dl-group-body>.dl-params{margin:12px 0!important}.dl-group-body>.alert-message{padding:10px 14px}.dl-group-body>.dl-params{padding:0}.dl-group-body>.alert-message+*,.dl-group-body>.dl-params+*{border-top:0}.dl-group-body>.dl-row{border-left:0;border-right:0;border-bottom:0;padding-left:0;padding-right:0;background:none}.dl-group-body>.dl-row:first-child{border-top:0}.dl-setsec-foot{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:10px 16px;padding:12px 20px;border-top:1px solid var(--dl-line);background:var(--dl-soft)}.dl-setsec.danger{border-color:color-mix(in srgb,var(--dl-bad) 40%,transparent)}.dl-setsec.danger .dl-setsec-foot{background:color-mix(in srgb,var(--dl-bad) 6%,transparent)}.dl-setrow{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,420px);align-items:center;gap:8px 24px}.dl-setrow.head{display:flex;justify-content:space-between;gap:16px}.dl-setrow-label{font-size:14px;font-weight:500}.dl-setrow-ctl{display:flex;justify-content:flex-end;min-width:0}.dl-setrow-ctl .dl-chips-row{justify-content:flex-end}.dl-setrow-ctl>input{width:100%}.dl-hostport{display:flex;align-items:center;gap:8px;flex:1;min-width:0;justify-content:flex-end}.dl-hostport input{flex:1;min-width:0}.dl-root input.dl-w-port,.dl-hostport input.dl-w-port{flex:0 0 90px;width:90px}.dl-root input.dl-w-range{flex:0 0 130px;width:130px}.dl-setrow .dl-sub.bad{color:var(--dl-bad)}.dl-suffixed{display:inline-flex;align-items:center;gap:6px}.dl-suffixed>span{color:var(--dl-fg-muted)}.dl-more summary{cursor:pointer;color:var(--dl-fg-muted);font-size:13px;margin-bottom:10px}.dl-more .dl-setrow+.dl-setrow{margin-top:10px}@media(max-width:760px){.dl-setrow:not(.head){grid-template-columns:minmax(0,1fr)}.dl-setrow-ctl,.dl-setrow-ctl .dl-chips-row{justify-content:flex-start}}.dl-need-ic{width:30px;height:30px;border-radius:9px;background:var(--dl-soft);color:var(--dl-fg-muted);display:inline-flex;align-items:center;justify-content:center;flex:none}.dl-need-ic .dl-icon-wrap{display:inline-flex}.dl-need-ic .dl-icon{width:15px;height:15px}.dl-need-row.bad .dl-need-ic,.dl-need-ic.bad{background:var(--dl-bad-wash);color:var(--dl-bad)}.dl-need-row.warn .dl-need-ic,.dl-need-ic.warn{background:var(--dl-warn-wash);color:var(--dl-warn)}.dl-need-ic.ok{background:var(--dl-ok-wash);color:var(--dl-ok)}.dl-lh-main{display:flex;align-items:flex-start;gap:12px;min-width:0}.dl-lh-main>.dl-need-ic{margin-top:1px}.dl-sub .dl-mono{font-size:.92em}.dl-need-row>.cbi-button{flex:none}.dl-bk-row .dl-group-ic{width:30px;height:30px}.dl-bk-older>summary{list-style:none;cursor:pointer;display:flex;align-items:center;gap:8px;padding:11px 16px;border-top:1px solid var(--dl-line);font-size:13px;color:var(--dl-fg-muted);user-select:none}.dl-bk-older>summary::-webkit-details-marker{display:none}.dl-bk-older>summary:hover{background:var(--dl-soft);color:var(--dl-fg)}.dl-bk-older>summary .dl-icon-wrap{display:inline-flex;transition:transform .15s}.dl-bk-older>summary .dl-icon{width:14px;height:14px}.dl-bk-older[open]>summary .dl-icon-wrap{transform:rotate(90deg)}#dl-set-backups .dl-setsec-head h3+.dl-sub{margin-top:2px}#dl-set-backups .dl-setsec-foot>.dl-sub{flex:1 1 260px}.dl-bk-actions{flex:0 1 auto;justify-content:flex-end}@media(max-width:640px){#dl-set-backups .dl-setsec-foot>.dl-sub{flex-basis:100%}.dl-bk-actions{justify-content:flex-start}}.dl-upd{display:flex;flex-direction:column;gap:16px}.dl-upd>.dl-pagehead{margin:0 0 4px}.dl-upd-bad{color:var(--dl-bad)}";var lr=".dl-comp-hero{display:grid;grid-template-columns:minmax(0,1.5fr) minmax(0,1fr)}.dl-comp-hero-main{padding:20px;display:flex;flex-direction:column;gap:12px;min-width:0}.dl-comp-hero-side{padding:20px;border-left:1px solid var(--dl-line);display:flex;flex-direction:column;gap:14px;min-width:0}.dl-comp-name{font-size:16px;font-weight:500}.dl-comp-hero-head{display:flex;align-items:center;gap:10px;flex-wrap:wrap;min-width:0}.dl-comp-hero-head .dl-spacer{flex:1}.dl-comp-big{font-family:var(--dl-mono);font-size:26px;line-height:34px;letter-spacing:-.02em;display:flex;align-items:baseline;gap:10px}.dl-comp-big small{font-size:14px;color:var(--dl-accent)}.dl-comp-big small.dl-faint{color:var(--dl-fg-faint)}.dl-comp-verrow{display:flex;align-items:center;gap:4px 12px;flex-wrap:wrap;min-width:0}.dl-comp-verrow .dl-spacer{flex:1}.dl-comp-meta{font-size:13px}.dl-comp-bullets{margin:0;padding-left:18px;display:flex;flex-direction:column;gap:4px;color:var(--dl-fg-muted);font-size:13px}.dl-comp-bullets li{list-style:disc}.dl-comp-lead{margin:0}.dl-comp-more{align-self:flex-start;font-size:12px;color:var(--dl-fg-faint);margin-left:18px;padding:0!important}.dl-comp-more:hover{color:var(--dl-accent);background:none!important;text-decoration:underline;text-underline-offset:2px}.dl-comp-hero-main>.dl-comp-vers{margin-top:auto}.dl-comp-btns{display:flex;gap:8px;flex-wrap:nowrap;align-items:center;flex:none}.dl-comp-side-v{display:flex;align-items:center;gap:8px;font-size:14px;min-width:0;flex-wrap:wrap}.dl-comp-side-v .dl-icon{width:15px;height:15px;color:var(--dl-fg-muted)}.dl-comp-side-v a{color:inherit;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-comp-side-v a:hover{color:var(--dl-accent)}.dl-comp-cols{display:grid;grid-template-columns:minmax(0,1.5fr) minmax(0,1fr);gap:16px;align-items:start}.dl-comp-cols>.dl-panel>div>.dl-row:first-child{border-top:1px solid var(--dl-line)}.dl-comp-count{font-size:13px}.dl-comp-sub{font-size:11px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-comp-ic{display:inline-flex;gap:4px;flex:none}.dl-comp-ic .cbi-button{width:30px;height:30px;padding:0!important;justify-content:center;border-radius:999px!important}.dl-comp-ic .dl-btn-label{display:none}.dl-comp-ic .dl-icon{width:14px;height:14px}.dl-comp-ic .is-busy{pointer-events:none;opacity:.5}.dl-comp-ic .cbi-button.dl-comp-check{width:auto;padding:0 12px 0 10px!important;gap:6px;display:inline-flex;align-items:center;font-size:13px}.dl-row>.dl-pill,.dl-row>.cbi-button,.dl-row>.dl-comp-ic{flex:none}button.dl-pill.dl-comp-run{all:unset;display:inline-flex;align-items:center;height:20px;padding:0 8px;border-radius:999px;font-size:12px;cursor:pointer;background:color-mix(in srgb,var(--dl-accent) 14%,transparent);color:var(--dl-accent)}.dl-comp-foldwrap{padding:0 16px 14px 60px}.dl-comp-fold .dl-params-body{gap:12px}.dl-comp-fold .dl-list>.dl-row{padding:10px 14px}.dl-comp-bver{font-size:12px;width:130px;text-align:right;flex:none;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-comp-bact{width:84px;flex:none;display:flex;justify-content:flex-end}.dl-comp-warn{display:flex;align-items:flex-start;gap:8px;font-size:12px;line-height:18px;color:var(--dl-fg-muted)}.dl-comp-warn .dl-icon-wrap{display:inline-flex;flex:none;margin-top:2px}.dl-comp-warn .dl-icon{width:14px;height:14px;color:var(--dl-warn)}.dl-comp-empty{margin:0;padding:4px 16px 16px}@media(max-width:760px){.dl-comp-hero,.dl-comp-cols{grid-template-columns:minmax(0,1fr)}.dl-comp-hero-side{border-left:0;border-top:1px solid var(--dl-line)}.dl-comp-foldwrap{padding-left:16px}.dl-comp-bver{display:none}}.dl-comp-status{display:flex;align-items:center;gap:8px;font-size:13px;padding:9px 12px;border-radius:10px;background:var(--dl-soft);min-width:0}.dl-comp-status>.dl-icon-wrap{display:inline-flex;flex:none}.dl-comp-status .dl-icon{width:15px;height:15px}.dl-comp-status.ok{background:var(--dl-ok-wash);color:var(--dl-ok)}.dl-comp-status.acc{background:color-mix(in srgb,var(--dl-accent) 12%,transparent);color:var(--dl-accent)}.dl-comp-status.warn{background:var(--dl-warn-wash);color:var(--dl-warn)}.dl-comp-status.bad{background:var(--dl-bad-wash);color:var(--dl-bad)}.dl-comp-status b{font-weight:600}.dl-comp-vers .dl-params-body{gap:0;padding:4px 14px 12px}.dl-comp-tag{display:flex;gap:6px;padding:6px 0 10px}.dl-comp-tag input{flex:1;min-width:0}.dl-comp-ver{display:flex;align-items:center;gap:8px;padding:7px 0;border-top:1px solid var(--dl-line);font-size:13px}.dl-comp-ver .dl-mono{min-width:52px}.dl-comp-ver .dl-sub{flex:1}.dl-comp-ver .cbi-button:not(.dl-icon-btn){height:26px!important;font-size:12px!important}.dl-comp-pager{display:flex;align-items:center;justify-content:space-between;padding-top:10px;border-top:1px solid var(--dl-line);font-size:12px}.dl-comp-pager .dl-linkbtn[disabled]{opacity:.4;cursor:default}.dl-comp-vers .dl-loading,.dl-comp-vers .dl-params-body>p{padding:6px 0 10px}.dl-op-head{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-bottom:14px}.dl-op-head .dl-spacer{flex:1}.dl-op-timer{display:inline-flex;align-items:center;gap:5px;font-variant-numeric:tabular-nums}.dl-op-timer .dl-icon,.dl-op-head .dl-linkbtn .dl-icon{width:14px;height:14px}.dl-op-loghead{display:flex;align-items:center;justify-content:space-between}.dl-op-loghead b{font-weight:500;font-size:13px}.dl-op .dl-log{max-height:16em;min-height:12em;margin-top:8px}.dl-op .dl-comp-status{margin:14px 0 0}.dl-op-actions{display:flex;gap:8px;justify-content:flex-end;flex-wrap:wrap;width:100%}.dl-notes{max-height:55vh;overflow:auto;border-radius:12px;background:var(--dl-soft);padding:14px 16px;font-size:13px;line-height:20px;overflow-wrap:anywhere}.dl-notes h5{margin:10px 0 6px;font-size:14px;font-weight:500}.dl-notes h5:first-child{margin-top:0}.dl-notes p{margin:0 0 8px}.dl-notes ul{margin:0 0 10px;padding-left:18px}.dl-notes li{list-style:disc}.dl-notes code{font-family:var(--dl-mono);font-size:12px;padding:1px 5px;border-radius:6px;background:var(--dl-soft-hover)}.dl-notes pre{font-family:var(--dl-mono);font-size:12px;padding:10px;border-radius:8px;background:var(--dl-soft-hover);white-space:pre-wrap;margin:0 0 10px}.dl-notes a{color:var(--dl-accent)}";var dr=".dl-chip.static{cursor:default}.dl-chip.static:hover{background:var(--dl-soft)}.dl-chip.static .dl-chip-name{font-weight:500}.dl-setrow.head .dl-chips-row{margin-top:8px}.dl-setrow.head>.dl-lh-main,.dl-setrow.head>.dl-lh-main>.dl-stack{flex:1 1 auto;min-width:0}.dl-setrow.head>.dl-setrow-ctl:empty{display:none}.dl-setrow.head:has(>.dl-lh-main){align-items:flex-start}.dl-setrow.head>.dl-setrow-ctl{align-items:center;min-height:30px}.dl-netpick{margin-top:10px}.dl-boxrow{display:flex;align-items:center;justify-content:space-between;gap:16px;margin:0;padding:10px 14px;border:1px solid var(--dl-line);border-radius:12px;font-size:13px;cursor:pointer}.dl-boxrow>.dl-switch{flex:none}.dl-ifpick{display:flex;flex-direction:column;gap:12px;padding:14px;border:1px solid var(--dl-line);border-radius:14px}.dl-iflead-row{display:flex;align-items:center;justify-content:space-between;gap:12px}.dl-host-ports{justify-content:flex-end}@media(max-width:760px){.dl-host-ports{justify-content:flex-start}}.dl-circle-dot{display:inline-block;width:8px;height:8px;border-radius:50%;flex:none}.dl-circles .dl-chip b{font-weight:500}.dl-circle-name{display:inline-flex;align-items:center;gap:8px;font-size:14px;font-weight:500}.dl-w400{font-weight:400}.dl-swatches{display:flex;flex-wrap:wrap;gap:8px}.dl-swatch{all:unset;cursor:pointer;width:22px;height:22px;border-radius:50%;background:var(--sw);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dl-fg) 12%,transparent)}.dl-swatch.on{box-shadow:0 0 0 2px var(--dl-card),0 0 0 4px var(--sw)}.dl-swatch:focus-visible{outline:2px solid var(--dl-ring);outline-offset:3px}.dl-circle-modal .dl-chipbtn b{margin-left:6px;font-weight:500;font-size:11px;opacity:.6}.dl-reach td:first-child b{font-weight:500}.dl-ev-host{white-space:nowrap}.dl-ev-host b{font-weight:500;color:var(--dl-fg)}.dl-reach{font-size:13px}.dl-reach th,.dl-reach td{white-space:nowrap;padding-left:6px;padding-right:6px}.dl-reach-wrap{overflow-x:auto}.dl-yes{display:inline-flex;align-items:center;gap:4px;color:var(--dl-ok)}.dl-yes .dl-icon-wrap{display:inline-flex}.dl-yes .dl-icon{width:14px;height:14px}.dl-check-form{display:grid;grid-template-columns:minmax(0,1fr) auto minmax(0,1fr) auto;align-items:start;gap:8px}.dl-check-form>.dl-faint{line-height:36px}.dl-check-end{display:flex;flex-direction:column;gap:6px;min-width:0}.dl-check-end>*{width:100%!important;min-width:0}@media(max-width:560px){.dl-check-form{grid-template-columns:minmax(0,1fr)}.dl-check-form>.dl-faint{display:none}}.dl-verdict{display:flex;align-items:baseline;gap:10px;padding:10px 12px;border-radius:12px}.dl-verdict b{font-weight:500}.dl-verdict.ok{background:var(--dl-ok-wash)}.dl-verdict.ok b{color:var(--dl-ok)}.dl-verdict.bad{background:var(--dl-bad-wash)}.dl-verdict.bad b{color:var(--dl-bad)}.dl-corehead{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin:0 0 4px}.dl-corehead h3{margin:0!important}.dl-row-end{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap}.dl-dcard.clickable{cursor:pointer}.dl-dcard.clickable:hover{border-color:color-mix(in srgb,var(--dl-fg) 22%,transparent)}";var ms=[Va,Ya,Za,Qa,Xa,er,tr,nr,or,ar,rr,ir,sr,lr,dr].join(` -`);function cr(){let n=document.createElement("style");return n.dataset.dawnline="1",n.textContent=ms,n}function lt(n){return()=>{let e=new n;return Object.assign({load:()=>e.load(),render:async a=>{let r=await e.render(a),i=document.createElement("div");return i.className="dl-root",i.append(cr(),r),i},addFooter(){return e.noFooter?document.createElement("div"):this.super("addFooter",[])}},{handleSave:null,handleSaveApply:null,handleReset:null})}}var Mg=lt(Ot),Sg=lt(st),_g=lt(Ot),Tg=lt(vn),Cg=lt(wn),Pg=lt(En),Dg=lt(xn);function pr(n){return()=>({load:()=>(ui.menu?.flushCache(),location.replace(`${L.url("admin/network/dawnline/diagnostics")}${n?`?tab=${n}`:""}`),new Promise(()=>{})),render:()=>document.createElement("div"),handleSave:null,handleSaveApply:null,handleReset:null})}var Ag=pr(""),zg=pr("log");return baseclass.extend({ activity: zg, diagnostics: Pg, health: Ag, overview: Mg, people: Sg, person: Cg, server: _g, settings: Tg, updates: Dg }); +`).trim()}async function jt(n,e,o,a){let r=t("div",{class:"dl-notes"},t("p",{class:"dl-muted dl-loading"},"Loading release notes…")),i=t("div",{class:"dl-op-head"}),s="";ae(o,[i,r],[D([v("copy")," Copy"],()=>ue(s,"Release notes copied"))," ",le("Close")],"wide");try{let l=await P.updatesNotes(n,e,a??"");s=La(l.body||"");let c=$a(l.url);dom.content(i,[l.published?t("span",{class:"dl-pill"},Ne(l.published)):"",l.prerelease?t("span",{class:"dl-pill warn"},"Pre-release"):"",t("span",{class:"dl-spacer"}),c?t("a",{href:c,target:"_blank",rel:"noopener",class:"dl-linkbtn"},["On GitHub ",v("open")]):""]),dom.content(r,s.trim()?Ea(s):t("p",{class:"dl-muted"},"This release has no notes."))}catch(l){dom.content(r,t("p",{class:"dl-muted"},ve(l)))}}var Ma={"6h":"every 6 h","12h":"every 12 h","1d":"daily","7d":"weekly"},Yn=n=>n?Ne(n):"";function Ii(n){let e=/^(.{20,}?)(?:;\s|:\s)/.exec(n)?.[1];return e||(n.length<=90?n:`${n.slice(0,90).replace(/[\s,;:]+\S*$/,"")}…`)}function _a(n,e){let o=n.st,a=o.policy,r=o.kept?.app,i=e?.update&&e.tag?e.tag:o.version,s=w=>()=>jt("app",w,`What’s new in Dawnline ${w.replace(/^v/,"")}`),l=e?.tag&&(e.update||e.status==="latest")?Bi(n,e.tag,e.update?o.version:""):null,c=e?.tag??i,d=a.check&&o.auto?.check?o.auto.check+({"6h":6,"12h":12,"1d":24,"7d":168}[a.interval]??24)*3600:0,p=(w,g)=>t("div",{class:"dl-stack gap4"},[t("span",{class:"dl-metric-label"},w),t("span",{class:"dl-comp-side-v"},g)]),u=[{label:"What’s new",ic:"file",run:s(i)},{label:"Open on GitHub",ic:"globe",run:()=>window.open(`https://github.com/${o.repo}`,"_blank","noopener")},null,{label:`Reinstall ${o.version}`,ic:"reset",warn:!0,run:()=>n.op("app:reinstall","Reinstalling Dawnline",o.version)},r?{label:`Roll back to ${r.version}`,ic:"archive",warn:!0,run:async()=>{await re(`Roll back to Dawnline ${r.version}?`,`The copy kept on the router replaces ${o.version}. A backup of the settings is made first.`,"Roll back")&&n.op("app:rollback","Rolling back Dawnline",o.version)}}:null];return t("section",{class:"dl-panel flush dl-comp-hero"},[t("div",{class:"dl-comp-hero-main"},[t("div",{class:"dl-comp-hero-head"},[t("span",{class:"dl-group-ic"},v("sunrise")),t("b",{class:"dl-comp-name"},"Dawnline"),n.state("app",e,e?.latest??""),t("span",{class:"dl-spacer"}),n.round(()=>n.op("check:app","Checking Dawnline",o.version),u,!0)]),t("div",{class:"dl-comp-verrow"},[t("div",{class:"dl-stack"},[t("div",{class:"dl-comp-big"},[o.version,e?.update?t("small",{},`→ ${e.latest}`):e?.status==="dev"&&e.latest?t("small",{class:"dl-faint"},`release ${e.latest}`):""]),t("span",{class:"dl-faint dl-comp-meta"},e?.error?"":e?.update?e.published?`released ${Yn(e.published)}`:"":e?.status==="dev"?"ahead of the latest release":e?`latest release${e.published?` · released ${Yn(e.published)}`:""}`:"not checked yet")])]),l?.items.length?t("div",{class:"dl-stack gap4"},[t("ul",{class:"dl-comp-bullets"},l.items.map(w=>t("li",{},w))),l.total>l.items.length?t("button",{type:"button",class:"dl-linkbtn dl-comp-more",click:s(c)},`+${l.total-l.items.length} more in What’s new`):""]):"",e?.error?t("p",{class:"dl-sub dl-comp-lead dl-upd-bad"},e.error):"",e?.update?t("div",{class:"dl-comp-btns"},[D("Update now",()=>n.op("app","Updating Dawnline",o.version),"positive",{disabled:n.busy}),D("What’s new",s(i))]):"",Oi(n)]),t("div",{class:"dl-comp-hero-side"},[p("Source",[v("globe"),t("a",{href:`https://github.com/${o.repo}`,target:"_blank",rel:"noopener"},o.repo)]),p("Auto-update",[a.auto?ye("ok","On"):ye("","Off"),t("span",{class:"dl-muted"},a.auto?a.mode==="immediate"?"as soon as found":`${Ma[a.interval]==="weekly"?"weekly":"daily"} at ${a.time}`:a.check?`checks ${Ma[a.interval]}`:"checks off")]),p("Last check",o.check?[ie(o.check.time,o.now),d>o.now?t("span",{class:"dl-faint"},`· next in ${pt(d-o.now)}`):""]:["Never"]),p("Rollback",r?[t("span",{class:"dl-mono"},r.version),t("span",{class:"dl-faint"},"kept on flash")]:[t("span",{class:"dl-muted"},a.keep?"Kept after the next update":"Off")])])])}function Bi(n,e,o){if(n.notes.has(e))return n.notes.get(e)??null;n.notes.set(e,null);let a=r=>r.replace(/\*\*|`|\[([^\]]+)\]\([^)]*\)/g,(i,s)=>s??"").trim();return(async()=>{let i=((await P.updatesNotes("app",e,"").catch(()=>null))?.body??"").split(` +`).map(l=>/^\s*[-*+]\s+(.*)$/.exec(l)?.[1]).filter(l=>!!l);i.length||(i=(await P.updatesChanges(o,e).catch(()=>null))?.items??[]);let s={items:i.slice(0,3).map(l=>Ii(a(l))),total:i.length};n.notes.set(e,s),s.items.length&&n.root.isConnected&&n.paint()})(),null}function Oi(n){let e=t("div",{class:"dl-params-body"}),o=t("details",{class:"dl-params dl-comp-vers",open:n.versOpen?"open":null},[t("summary",{},[v("chevron"),t("span",{},"Versions"),t("span",{class:"dl-sub"},"install any release")]),e]);return o.addEventListener("toggle",()=>{n.versOpen=o.open,n.versOpen&&bn(n,e)}),n.versOpen&&bn(n,e),o}async function bn(n,e){let o=se("",{placeholder:"Tag, e.g. 0.3.1",class:"cbi-input-text dl-mono","aria-label":"Release tag"}),a=p=>{if(p=p.trim(),!/^v?[0-9][0-9A-Za-z.+~-]{0,40}$/.test(p))return K("Enter a release tag like 0.3.1","warning");Sa(n,p)};o.addEventListener("keydown",p=>{p.key==="Enter"&&(p.preventDefault(),a(o.value))});let r=t("div",{class:"dl-comp-tag"},[o,D("Install",()=>a(o.value),"neutral",{disabled:n.busy})]),i=n.versPage,s=p=>{n.versPage=Math.max(1,n.versPage+p),bn(n,e)},l=p=>t("div",{class:"dl-comp-pager"},[t("button",{type:"button",class:"dl-linkbtn",disabled:i<=1?"disabled":null,click:()=>s(-1)},"← Newer"),t("span",{class:"dl-faint"},`Page ${i}`),t("button",{type:"button",class:"dl-linkbtn",disabled:p?null:"disabled",click:()=>s(1)},"Older →")]),c=n.versCache.get(i);if(!c){dom.content(e,[r,t("p",{class:"dl-muted dl-loading"},"Loading versions…")]);try{c=(await P.updatesReleases(i)).releases}catch(p){if(i!==n.versPage||!e.isConnected)return;dom.content(e,[r,t("div",{class:"dl-row-actions"},[t("span",{class:"dl-muted"},`Failed to load versions: ${ve(p)}`),D("Try again",()=>bn(n,e))]),l(!1)]);return}if(n.versCache.set(i,c),i!==n.versPage||!e.isConnected)return}if(!c.length)return dom.content(e,[r,t("p",{class:"dl-muted"},i>1?"No more versions.":"No versions found."),l(!1)]);let d=n.st.version;dom.content(e,[r,...c.map(p=>{let u=p.tag.replace(/^v/,"");return t("div",{class:"dl-comp-ver"},[t("span",{class:"dl-mono"},u),t("span",{class:"dl-sub"},Yn(p.published)),p.prerelease?ye("warn","Pre-release"):"",t("span",{class:"dl-comp-ic"},$e("file","What’s new",()=>jt("app",p.tag,`What’s new in Dawnline ${u}`))),u===d?ye("ok","Installed"):D("Install",()=>Sa(n,p.tag),"neutral",{disabled:n.busy})])}),l(c.length>=5)])}async function Sa(n,e){let o=e.replace(/^v/,"");o.localeCompare(n.st.version,void 0,{numeric:!0})<0&&!await re(`Install Dawnline ${o}?`,`It is older than ${n.st.version}. A backup of the settings is made first; restore it from Settings if something looks wrong.`,"Install")||n.op(`app@${e}`,`Installing Dawnline ${o}`,n.st.version)}function Ta(n,e){let o=n.st,a=o.kept?.amneziawg,r=e?.sources??{},i=Object.keys(r),s=e?.current??null,l=s?r[s]:void 0,c=!!e?.ru,d=o.needs?.awg??[],p=d.length?null:e?.installed??null,u=[];s&&p&&u.push({label:"Reinstall this build",warn:!0,ic:"reset",run:()=>n.op(`amneziawg:${s}${c?":ru":""}`,"Reinstalling AmneziaWG",p)}),a&&u.push({label:`Roll back to ${a.version}`,ic:"archive",warn:!0,run:async()=>{await re(`Roll back AmneziaWG to ${a.version}?`,"The build kept on the router is installed again. Every AmneziaWG tunnel restarts for a few seconds.","Roll back")&&n.op("amneziawg:rollback","Rolling back AmneziaWG",p??void 0)}});let w=[e?.release?{label:"What’s new",ic:"file",run:()=>jt("amneziawg",e.release,`What’s new in the ${l?.label??"AmneziaWG"} build`,s??"slava")}:null,{label:"Open on GitHub",ic:"globe",run:()=>window.open(`https://github.com/${l?.repo??"Slava-Shchipunov/awg-openwrt"}`,"_blank","noopener")},...u.length?[null,...u]:[]].filter((h,f,R)=>h!==null||f>0&&R[f-1]!==null),g=o.tunnels??[],m=g.length?`Switching restarts ${g.length===1?"the tunnel":`${g.length} tunnels`} for a few seconds: ${g.join(", ")}. Devices keep their configurations.`:"Switching takes a few seconds. Devices keep their configurations.",k=g.length>1?`${g.slice(0,-1).join(", ")} and ${g[g.length-1]}`:g[0],H=g.length?`Switching restarts ${k} for a few seconds.`:"Switching takes a few seconds.",B=async h=>{let f=r[h];await re(p?`Switch to AmneziaWG ${f.gen}?`:`Install AmneziaWG ${f.gen}?`,`The ${f.label} build, ${f.version}. ${m}${f.gen==="3.1"?" Devices need AmneziaVPN 3.1 or newer.":""}`,p?"Switch":"Install")&&n.op(`amneziawg:${h}${c?":ru":""}`,p?`Switching to AmneziaWG ${f.gen}`:"Installing AmneziaWG",p??void 0)},E=h=>{let f=r[h],R=s===h&&!!p;return t("div",{class:"dl-row"},[t("span",{class:"dl-row-main dl-stack"},[t("b",{},f.gen?`AmneziaWG ${f.gen}`:"AmneziaWG"),t("span",{class:"dl-sub"},`${f.label} · ${f.gen==="3.1"?"AmneziaVPN 3.1+":"every app"}`)]),t("span",{class:"dl-mono dl-faint dl-comp-bver"},f.version??"none yet"),t("span",{class:"dl-comp-bact"},R?ye("ok","Active"):f.version?D(p?"Switch":"Install",()=>B(h),p?"neutral":"positive",{disabled:n.busy}):ye("","No build"))])},y=i.map(h=>r[h]?.newer?`${r[h].label} moves to ${r[h].newer.gen} with OpenWrt ${r[h].newer.tag.replace(/^v/,"")}.`:"").filter(Boolean),S=ge(c,"Russian translation",h=>{s&&n.op(`amneziawg:${s}${h?":ru":""}`,h?"Adding the Russian translation":"Removing the Russian translation",p??void 0)});S.disabled=!s||!p||n.busy;let b=n.awgOpen??!p,x=t("details",{class:"dl-params dl-comp-fold",open:b?"open":null},[t("summary",{},[v("chevron"),t("span",{},"Build and translation")]),t("div",{class:"dl-params-body"},[t("div",{class:"dl-list"},[...i.length?i.map(E):[t("div",{class:"dl-row"},t("span",{class:"dl-sub"},"Check for updates to see the builds for this router."))],t("div",{class:"dl-row"},[t("span",{class:"dl-row-main dl-stack"},[t("b",{},"Russian translation"),t("span",{class:"dl-sub"},"LuCI pages for AmneziaWG")]),t("span",{class:"dl-comp-bact"},S)])]),p&&i.length||y.length?t("div",{class:`dl-comp-status ${p&&i.length?"warn":"acc"}`},[v(p&&i.length?"alert":"download"),t("span",{},[p&&i.length?t("b",{},H):"",...y.map(h=>` ${h}`)])]):""])]);x.addEventListener("toggle",()=>n.awgOpen=x.open);let M=[];return e?.update&&p&&s?M.push(D(`Update to ${e.latest}`,()=>n.op(`amneziawg:${s}${c?":ru":""}`,"Updating AmneziaWG",p),"neutral",{disabled:n.busy})):M.push((e||d.length)&&!p?ye("warn","Not installed"):n.state("amneziawg",e,e?.latest??"")),M.push(n.round(()=>n.op("check:amneziawg","Checking AmneziaWG",p??void 0),w)),[n.row("shield","AmneziaWG",[p?`${p}${e?.release?` · ${e.release} build`:""}`:d.length?`missing ${d.join(", ")}`:e?"not installed":"version not checked"],M),t("div",{class:"dl-comp-foldwrap"},x)]}var ji=[{title:"Home-like link",sub:"Policy routing and the veth pair",pkgs:["ip-full","kmod-veth"],feature:"home"},{title:"HTTPS for the portal",sub:"OpenSSL for uhttpd",pkgs:["libustream-openssl","openssl-util"],feature:"https"},{title:"Certificates (ACME)",sub:"Let’s Encrypt certificate for the portal",pkgs:["acme","acme-acmesh-dnsapi"],feature:"acme",optional:!0}],Zn={home:"network",https:"lock",acme:"file"};function Ca(n,e){let o=n.st,a=e?.pkgs??{},r=ji.filter(d=>d.feature==="home"?o.home:o.portal),i=async(d,p,u=d)=>{await re(`Update ${p}?`,`${u.join(", ")} from the OpenWrt feeds. Services that use them restart for a moment.`,"Update")&&n.op(`pkgs:${d.join(",")}`,`Updating ${p}`)},s=[{label:"Check system packages",ic:"refresh",run:()=>n.op("check:packages","Checking system packages")},{label:"Open the OpenWrt package list",ic:"globe",run:()=>window.open("https://openwrt.org/packages/start","_blank","noopener")}],l=0;return{rows:r.map(d=>{let p=d.pkgs.filter(k=>a[k]?.installed),u=[...new Set(p.flatMap(k=>[...a[k]?.latest?[k]:[],...a[k]?.with??[]]))],w=o.needs?.[d.feature]??d.pkgs.filter(k=>!a[k]?.installed),g=p.find(k=>a[k]?.latest),m=p.map(k=>`${k} ${a[k]?.installed??""}`).join(", ");return w.length?n.row(Zn[d.feature],d.title,[`${d.optional?"not installed":`missing ${w.join(", ")}`}`],[D("Install",()=>n.op(`pkgs:${w.join(",")}`,`Installing ${d.title}`),d.optional?"neutral":"positive",{disabled:n.busy}),t("span",{class:"dl-comp-ic"},n.more(s))]):e&&u.length?(l++,n.row(Zn[d.feature],d.title,g?[`${a[g].installed} → ${a[g].latest}`,u.length>1?` · +${u.length-1}`:""]:[u.join(", ")],[D("Update",()=>i(p.filter(k=>a[k]?.latest||a[k]?.with?.length),d.title,u),"neutral",{disabled:n.busy}),t("span",{class:"dl-comp-ic"},n.more(s))])):n.row(Zn[d.feature],d.title,[m||d.sub],[n.state("pkgs",e,""),t("span",{class:"dl-comp-ic"},n.more(s))])}),updates:l,total:r.length}}var Ui={app:"Dawnline",amneziawg:"AmneziaWG",pkgs:"System packages",all:"Components"};function Pa(n){let e=n.st,o=r=>{let i=Ze(r.component??"app"),s=Ui[i]??"Components",l=r.auto?"automatically":"by you",c="ok",d="check",p;if(r.kind==="found")c="accent",d="download",p=[t("b",{},(r.items??[]).join(", ")),` found by ${r.auto?"the automatic check":"a check"}`];else if(r.state==="failed")c="bad",d="x",p=[t("b",{},s),` ${r.kind==="install"?"update":"check"} failed${r.error?` · ${r.error}`:""}`];else{let u=r.from&&r.to&&r.from!==r.to?` ${r.from} → ${r.to}`:r.to?` ${r.to}`:"";p=[t("b",{},s),`${u} ${u?"":"updated "}${l}${r.took?` · ${pt(r.took)}`:""}`.replace(/\s+/g," ")]}return t("div",{class:"dl-row"},[t("span",{class:`dl-ev-tile ev ${c}`},v(d)),t("span",{class:"dl-row-main"},p),t("span",{class:"dl-faint dl-nowrap",title:new Date(r.ts*1e3).toLocaleString()},ie(r.ts,e.now))])},a=e.history??[];return t("section",{class:"dl-panel flush"},[t("div",{class:"dl-panel-head pad"},[t("h3",{},"Activity"),t("span",{class:"dl-spacer"}),t("a",{href:`${L.url("admin/network/dawnline/diagnostics")}?tab=log`},"All in Log →")]),a.length?t("div",{},a.slice(0,8).map(o)):t("p",{class:"dl-sub dl-comp-empty"},"Updates, and checks that found something, show up here.")])}var xn=class{constructor(){this.root=t("div",{class:"dl-upd"});this.following=null;this.versOpen=!1;this.versPage=1;this.versCache=new Map;this.notes=new Map;this.awgOpen=null}load(){return P.updatesStatus()}render(e){return this.st=e,this.paint(),e.job?.state==="running"&&this.follow(e.job),poll.add(async()=>{if(!this.root.isConnected)return;let o=await P.updatesStatus().catch(()=>null);if(!o)return;let a=this.st;this.st=o,o.job?.state==="running"&&this.following!=="starting"&&o.job.id!==this.following&&this.follow(o.job),(o.job?.id!==a.job?.id||o.job?.state!==a.job?.state||o.job?.phase!==a.job?.phase||o.check?.time!==a.check?.time)&&this.paint()},5),this.root}get busy(){return this.st.job?.state==="running"}async refresh(e){this.st=e??await P.updatesStatus().catch(()=>null)??this.st,this.paint()}async op(e,o,a){if(this.busy||this.following==="starting"){K("Another component action is already running","warning");return}this.following="starting",this.paint();let r=Ze(e),i=await It(e,{title:o,version:a,onJob:s=>this.following=s.id,onDone:s=>this.refresh(s),onUpdate:s=>{let l=s.check?.components??{};r==="amneziawg"&&l.amneziawg?.current?this.op(`amneziawg:${l.amneziawg.current}${l.amneziawg.ru?":ru":""}`,"Updating AmneziaWG",l.amneziawg.installed??void 0):this.op("app","Updating Dawnline",this.st.version)}});this.following==="starting"&&(this.following=i?.id??null),this.refresh()}async follow(e){this.following=e.id;let o=cn(e),a={app:"Dawnline",amneziawg:"AmneziaWG",pkgs:"system packages",all:"components"}[o]??"components";await It(null,{title:`${e.action==="check"?"Checking":e.auto?"Automatic update:":"Updating"} ${a}`,onDone:r=>this.refresh(r)},e)}paint(){let e=this.st,o=e.check?.components??{},a=e.firmware,r=Ca(this,o.packages),i=(e.needs?.awg??[]).length>0,l=(!i&&o.amneziawg?.update&&o.amneziawg.installed?1:0)+r.updates;dom.content(this.root,[t("div",{class:"dl-pagehead"},[t("div",{class:"dl-stack"},[t("h2",{class:"dl-h1"},"Components"),t("span",{class:"dl-faint"},[a?.version?`OpenWrt ${a.version} · ${a.target}`:"",e.check?`checked ${ie(e.check.time,e.now)}`:"not checked yet"].filter(Boolean).join(" · "))]),t("div",{class:"dl-row-actions"},[t("a",{class:"cbi-button cbi-button-neutral dl-icon-btn",href:`${L.url("admin/network/dawnline/settings")}?section=updates`},[v("edit")," Settings"]),D([v("refresh")," Check all"],()=>this.op("check","Checking all components"),"neutral",{disabled:this.busy})])]),_a(this,o.app),t("div",{class:"dl-comp-cols"},[t("section",{class:"dl-panel flush"},[t("div",{class:"dl-panel-head pad"},[t("h3",{},"Components"),t("span",{class:"dl-spacer"}),t("span",{class:"dl-faint dl-comp-count"},i?l?`AmneziaWG not installed · ${l} update${l===1?"":"s"}`:"AmneziaWG not installed":!o.amneziawg&&!o.packages?"":l?`${l} of ${1+r.total} need${l===1?"s":""} an update`:"Everything is up to date")]),t("div",{},[...Ta(this,o.amneziawg),...r.rows])]),Pa(this)])])}state(e,o,a){let r=this.st.job;if(r?.state==="running"){let i=l=>l==="packages"?"pkgs":l,s=r.action==="check"?[i(r.component||"all")]:(r.component??"").split(" ").map(l=>i(Ze(l)));if(s.includes(e)||s.includes("all"))return t("button",{type:"button",class:"dl-pill info dl-comp-run",title:"Show progress",click:()=>this.follow(r)},[r.action==="check"?"Checking":"Updating","…"])}return o?o.error?ye("warn","Check failed",o.error):o.update?ye("info","Update available"):o.status==="dev"?ye("info","Newer than release",`The latest release is ${a}`):ye("ok","Up to date"):ye("","Not checked")}more(e){let o=D([v("more")],()=>we(o,e.filter((a,r,i)=>a!==null||r>0&&ra?{label:a.label,icon:v(a.ic),warn:a.warn,run:a.run}:null)),"neutral",{title:"More","aria-label":"More"});return o}round(e,o,a=!1){let r=this.busy?" is-busy":"",i;return a?i=D([v("refresh")," Check"],e,"neutral",{class:`cbi-button cbi-button-neutral dl-comp-check${r}`,"aria-label":"Check for updates"}):(i=$e("refresh","Check for updates",e,"neutral",r.trim()),i.removeAttribute("title"),i.setAttribute("aria-label","Check for updates"),me(i,()=>["Check for updates"])),t("span",{class:"dl-comp-ic"},[i,this.more(o)])}row(e,o,a,r){return t("div",{class:"dl-row"},[t("span",{class:"dl-group-ic"},v(e)),t("span",{class:"dl-row-main dl-stack"},[t("b",{},o),t("span",{class:"dl-mono dl-faint dl-comp-sub"},a)]),...r])}};var Da=(n,e)=>t("div",{class:"cbi-value"},[t("label",{class:"cbi-value-title"},n),t("div",{class:"cbi-value-field"},e)]);function Aa(n){let e=n.st.servers.find(o=>o.id===n.p.server)?.name??"Home";Ht(n.p,e)}async function za(n){let e=n.p,o=e.code_set??0,a=e.devices.filter(l=>l.created_by==="portal"&&l.created>=o),r=a.map(l=>t("input",{type:"checkbox",id:`dl-rm-${l.id}`,checked:"checked","data-id":l.id})),i=[t("p",{},"The old link stops working right away.")];a.length&&i.push(t("p",{},"Devices added through the old link keep working until they are removed. Remove them too:"),t("div",{class:"dl-checklist"},a.map((l,c)=>t("label",{for:`dl-rm-${l.id}`},[r[c],` ${l.name}`]))));let s=async()=>{let l=r.filter(d=>d.checked).map(d=>d.dataset.id),c=await W(()=>P.personRegen(e.id,l),l.length?`New link created, ${l.length} device${l.length===1?"":"s"} removed`:"New link created");c&&(de(),l.length&&await n.refresh(),c.link&&await ue(c.link,"New link copied"))};ae("Create a new link?",i,[le()," ",D("Create new link",s,"negative")])}function Qn(n){let e=t("textarea",{class:"cbi-input-textarea dl-note-input",rows:3,maxlength:500,placeholder:"Only you see this"},n.p.note??"");ae("Note",[e],[le()," ",D("Save",async()=>{de(),await n.patch({note:e.value.trim()},e.value.trim()?"Note saved":"Note removed")},"positive")]),setTimeout(()=>e.focus(),50)}function Ha(n){let e=n.p,o=t("select",{class:"cbi-input-select"},[t("option",{value:"pause",selected:e.expire_action==="pause"?"selected":null},"Pause access"),t("option",{value:"notify",selected:e.expire_action==="notify"?"selected":null},"Keep access"),t("option",{value:"remove",selected:e.expire_action==="remove"?"selected":null},"Remove their devices")]),a=t("select",{class:"cbi-input-select"},[0,1,3,7,14].map(r=>t("option",{value:r,selected:e.expire_warn===r?"selected":null},r?`${r} day${r===1?"":"s"} before`:"Don’t warn")));ae("When access ends",[Da("Then",o),t("div",{class:"cbi-value"},[t("label",{class:"cbi-value-title"},"Warn"),t("div",{class:"cbi-value-field"},[a,t("div",{class:"cbi-value-description"},"Shown in their portal and on the Overview.")])])],[le()," ",D("Save",async()=>{de(),await n.patch({expire_action:o.value,expire_warn:a.value},"Saved")},"positive")])}function Na(n){let e=t("input",{type:"text",class:"cbi-input-text",value:n.p.name,maxlength:48});ae("Rename",[Da("Name",e)],[le()," ",D("Save",async()=>{await n.patch({name:e.value.trim()},"Renamed")&&de()},"positive")]),setTimeout(()=>e.select(),50)}async function Ra(n){let e=n.p;await re(`Delete ${e.name}?`,`All ${e.devices.length} devices are disconnected immediately and the personal link stops working.`,"Delete",!0)&&await W(()=>P.personDelete(e.id),"Deleted")&&(location.href=wt(e.server))}function Ia(n){let e=n.p,o=n.st,a=e.online?"online now":e.last_seen?`last seen ${ie(e.last_seen,o.now)}`:"never connected",r=e.created?`Added ${Te(He(new Date(e.created*1e3)))}`:"",i=e.has_link??o.settings.portal_enabled,s=[{label:"Rename",icon:v("edit"),run:()=>Na(n)},{label:e.note?"Edit note":"Add note",icon:v("file"),run:()=>Qn(n)},...i?[null,{label:"Invite card",icon:v("qr"),run:()=>Aa(n)},{label:"New link",icon:v("key"),run:()=>za(n)}]:[],null,...e.paused?[]:[{label:"Pause",icon:v("pause"),warn:!0,run:()=>n.patch({paused:!0},"Paused")}],{label:"Delete",icon:v("trash"),danger:!0,run:()=>Ra(n)}];return t("div",{class:"dl-person-head"},[t("div",{class:"dl-pagehead"},[t("div",{class:"dl-person-id"},[t("span",{class:`dl-avatar lg${e.online?" online":""}`},Ce(e.name)),t("div",{class:"dl-stack"},[t("div",{class:"dl-title-row"},[t("h2",{class:"dl-h1"},e.name),po(e)]),t("span",{class:"dl-faint",title:r},`${e.devices.length} of ${e.device_limit} devices · ${a}`)])]),t("div",{class:"dl-pcard-actions"},[e.paused?D([v("play")," Resume"],()=>n.patch({paused:!1},"Resumed"),"add"):"",i?$e("link","Copy link",()=>an(e.id),"neutral","dl-icon-only"):"",$e("more","More",l=>we(l.currentTarget,s),"neutral","dl-icon-only")])]),e.note?t("button",{type:"button",class:"dl-pnote",title:"Edit note",click:()=>Qn(n)},[v("file"),t("span",{},e.note)]):""])}function Ba(n){let e=n.p,o=n.series[n.series.length-1];return t("div",{class:`dl-person-live${e.online?"":" solo"}`},[e.online?mn(e.rate??[],n.st.now,o?[o.rx,o.tx]:[0,0]):"",hn(n.series,`${te(e.month[0]+e.month[1])} this month`)])}async function Wi(n,e){let o=await W(()=>P.deviceConfig(e.id));o&&ae(`Set up ${e.name}`,[await n.core.connectBlock(o,"qr")],[le("Close")])}async function Gi(n,e){let o=await W(()=>P.deviceConfig(e.id));if(!o)return;if(!o.has_private_key){K("This device made its own keys in the browser; its configuration only exists there.","warning");return}let a=n.core.file.make(o);Ee(a.name,a.text,"application/octet-stream")}function Oa(n){let e=n.p,o=n.st.now,a=c=>Be(e,c,n.deviceOpts()),r=c=>d=>{d.target.closest("button:not(.dl-dcard-title), a")||a(c)},i=c=>D([v("more")],d=>Oo(d.currentTarget,e,c,n.deviceOpts()),"neutral",{title:"QR, file, key, rename, new keys, remove",class:"cbi-button cbi-button-neutral dl-icon-only"}),s=Ft(e.devices).map(c=>{let d=t("div",{class:"dl-dcard-head"},[t("span",{class:"dl-dcard-ic"},v(c.kind)),t("button",{type:"button",class:"dl-dcard-title",click:()=>a(c)},[t("b",{},c.name),qt(c,o),c.config_stale?t("span",{class:"dl-pill warn dl-stale"},"Update config"):""]),i(c)]),p=t("div",{class:"dl-dcard-trend"},[t("div",{class:"dl-stack"},[t("b",{},te(c.month[0]+c.month[1])),t("span",{class:"dl-sub"},"this month")]),da(n.devSeries[c.id]??[])]);return t("article",{class:`dl-dcard clickable${c.online?" online":""}${c.disabled?" off":""}`,click:r(c)},[d,c.handshake?p:c.disabled?t("div",{class:"dl-sub"},`${je[c.kind]} · created ${ie(c.created,o)} ${c.created_by==="portal"?"in the portal":"by you"}.`):t("div",{class:"dl-chips-row"},[t("button",{type:"button",class:"dl-chipbtn",click:()=>Wi(n,c)},[v("qr"),"Show QR"]),t("button",{type:"button",class:"dl-chipbtn",click:()=>Gi(n,c)},[v("download"),"Config"])])])}),l=e.devices.length>=e.device_limit;return s.push(t("button",{type:"button",class:"dl-dslot add",click:()=>it(e,n.deviceOpts())},[t("span",{class:"dl-dslot-ic"},v("plus")),t("span",{class:"dl-stack"},[t("b",{},"Add device"),t("span",{class:"dl-sub"},l?`Over the limit · ${e.devices.length} of ${e.device_limit}`:`${e.devices.length} of ${e.device_limit}`)])])),t("section",{class:"dl-devsec"},[t("div",{class:"dl-panel-head"},[t("h3",{},"Devices"),t("span",{class:"dl-sub"},`${e.online} online`)]),t("div",{class:"dl-dgrid"},s)])}function ja(n){let e=n.p,o=xe([["device","Device’s own DNS"],["home","Home names"]],e.dns_mode,{label:"DNS",cls:"sm",optimistic:!1,onChange:r=>n.patch({dns_mode:r},r==="home"?"Home names on — devices need their configuration again":"Device DNS — devices need their configuration again")}),a=n.st.settings.home_dns_fallback;return t("div",{class:"dl-stack gap4 dl-dnspick"},[t("div",{class:"dl-row-actions"},[t("span",{class:"dl-sub"},"DNS"),o]),t("span",{class:"dl-sub"},e.dns_mode==="home"?["Names like ",t("span",{class:"dl-mono"},`nas.${n.st.settings.domain}`)," work. Internet names are resolved at home, so they depend on the tunnel",a?[" (",t("span",{class:"dl-mono"},a)," takes over when it is down)."]:" — with no fallback set, they stop when it is down."]:"Internet keeps working exactly as without the VPN. Reach home devices by IP address.")])}function Ua(n){let e=n.p,a=n.st.servers.find(i=>i.id===e.server)?.home??[];if(a.length<2)return"";let r=new Set(e.home_nets?.length?e.home_nets:a.map(i=>i.dev));return t("div",{class:"dl-stack gap4"},[t("div",{class:"dl-chips-row"},a.map(i=>We(i.dev,r.has(i.dev),()=>{let s=new Set(r);if(s.delete(i.dev)||s.add(i.dev),!s.size)return K("Keep at least one network, or choose Internet only.","warning",5e3);let l=s.size===a.length?[]:[...s];n.patch({home_nets:l},l.length?`${e.name} reaches ${l.join(", ")}`:`${e.name} reaches every home network`)},{title:i.nets.join(", ")}))),t("span",{class:"dl-sub"},e.home_nets?.length?`Home networks ${e.name} reaches. Networks added to the server later stay out.`:`Home networks ${e.name} reaches: all of them. Untick one to keep ${e.name} out of it.`)])}function Wa(n){let e=new Set(n.p.services??[]);return t("div",{class:"dl-stack gap4"},[t("div",{class:"dl-chips-row"},n.st.services.map(o=>We(o.name,e.has(o.id),()=>{let a=new Set(e);a.delete(o.id)||a.add(o.id),n.patch({services:[...a]},a.size?"Home services updated":"Whole home network")},{title:`${o.address}${o.ports.length?` · ${o.ports.join(", ")}`:""}`}))),t("span",{class:"dl-sub"},e.size?"Only the selected services at home.":"Whole home network. Pick services to narrow it down.")])}function Ga(n){let e=n.p,o=n.st;if(o.servers.find(d=>d.id===e.server)?.mesh!=="circles"||!Ye(e))return"";let r=o.circles.filter(d=>d.server===e.server),i=r.find(d=>d.id===e.circle),s=i?o.people.filter(d=>d.id!==e.id&&d.circle===i.id&&Ye(d)).map(d=>d.name):[],l=t("button",{type:"button",class:"dl-chipbtn",click:()=>we(l,[...r.map(d=>({label:d.name,icon:Gn(d),run:()=>d.id!==e.circle&&n.patch({circle:d.id},`${e.name} is in ${d.name}`)})),e.circle?{label:"No circle",icon:v("x"),run:()=>n.patch({circle:""},`${e.name} is in no circle`)}:null,{label:"New circle",icon:v("plus"),run:()=>ln(o,e.server,null,()=>n.refresh())}])},"Change"),c=i?o.people.filter(d=>d.circle===i.id&&Ye(d)):[e];return t("div",{class:"dl-tile2"},[t("div",{class:"dl-tile2-label"},[t("span",{},"Devices see each other"),l]),t("div",{class:"dl-tile2-row"},[t("span",{class:"dl-tile2-value"},i?i.name:"No circle"),t("span",{class:"dl-avstack",title:c.map(d=>d.name).join(", ")},c.slice(0,5).map(d=>t("span",{class:"dl-avatar sm"},Ce(d.name))))]),t("span",{class:"dl-sub"},i?s.length?[e.name,...s].join(", "):`Nobody else in ${i.name} yet`:`Only ${e.name}'s own devices`)])}function Fa(n){let e=n.p,o=n.st.now,a=t("div",{class:"dl-slots"});for(let s=0;s=e.device_limit,d=t("i",{class:c?"over":l?"used":""});me(d,()=>[t("div",{class:"dl-tip-title"},l?`${l.name}${c?" · over the limit":""}`:"Free slot"),t("div",{class:"dl-muted"},l?l.online?"Connected":l.handshake?`Last seen ${ie(l.handshake,o)}`:"Not set up yet":"They can add a device here")]),a.appendChild(d)}let r=Math.max(1,e.devices.length),i=t("button",{type:"button","aria-label":"Allow fewer devices",disabled:e.device_limit<=r?"disabled":null,click:()=>n.patch({device_limit:String(e.device_limit-1)})},"−");return e.device_limit<=r&&e.devices.length>1&&me(i,()=>[t("div",{class:"dl-tip-title"},`${e.devices.length} devices in use`),t("div",{class:"dl-muted"},"Remove a device first to lower the limit")]),t("div",{class:"dl-tile2"},[t("div",{class:"dl-tile2-label"},"Devices"),t("div",{class:"dl-tile2-row"},[t("span",{class:"dl-tile2-value"},[String(e.devices.length),t("span",{class:"dl-faint"},` / ${e.device_limit}`)]),t("div",{class:"dl-stepper"},[i,t("button",{type:"button","aria-label":"Allow more devices",disabled:e.device_limit>=32?"disabled":null,click:()=>n.patch({device_limit:String(e.device_limit+1)})},"+")])]),a])}var Fi={internet:"Browse the internet through your router. No access to devices at home, and home cannot reach theirs.",lan:"Reach devices at home, and home reaches theirs. Internet stays on their own connection.",both:"Home devices and the internet, all through your router. Home reaches their devices too."},qa=/^([01]\d|2[0-3]):[0-5]\d$/;function qi(n){let e=n.p,o=n.today,a=nt(e.expires,o),r=t("input",{type:"date",class:"dl-date-hidden",value:e.expires,tabindex:"-1","aria-hidden":"true"});r.addEventListener("change",()=>r.value&&n.patch({expires:r.value},`Access until ${Te(r.value)}`));let i=(d,p)=>{let u=so(e.expires&&(a??-1)>=0?e.expires:"",d,p,o);n.patch({expires:u},`Access until ${Te(u)}`)},s=[["week",1,"+1 week"],["month",1,"+1 month"],["month",3,"+3 months"],["year",1,"+1 year"]].map(([d,p,u])=>t("button",{type:"button",class:"dl-chipbtn",click:()=>i(d,p)},u)),l=t("span",{class:"dl-datechip"},[t("button",{type:"button",class:"dl-chipbtn",click:()=>{r.focus({preventScroll:!0});try{r.showPicker()}catch{}}},[v("calendar"),e.expires?Te(e.expires):"Date"]),r]),c={pause:"pause access",notify:"keep access",remove:"remove their devices"}[e.expire_action];return t("div",{class:"dl-tile2"},[t("div",{class:"dl-tile2-label"},[t("span",{},"Access ends"),e.expires?t("span",{class:a!=null&&a<0?"dl-bad":Fe(e,a)?"dl-warn":"dl-ok"},a!=null&&a<0?"ended":`${a} day${a===1?"":"s"} left`):t("span",{class:"dl-faint"},"no end date")]),t("div",{class:"dl-chips-row"},[...s,l,e.expires?t("button",{type:"button",class:"dl-chipbtn",click:()=>n.patch({expires:""},"No end date")},"No end"):""]),t("div",{class:"dl-tile2-foot"},[t("span",{class:"dl-muted"},`When it ends: ${c}${e.expire_warn?`, warn ${e.expire_warn} day${e.expire_warn===1?"":"s"} before`:""}`),t("a",{href:"#",click:d=>{d.preventDefault(),Ha(n)}},"Change")])])}function Ki(n){let e=n.p,o=e.quota_used||e.month[0]+e.month[1],a=e.quota_limit?Math.min(100,e.quota_used/e.quota_limit*100):0,r=t("div",{class:`dl-meter${a>=100?" bad":a>=90?" warn":""}`},[t("i"),e.quota_limit?t("span",{class:"mark",title:"Alert at 90%"}):""]);r.firstChild.style.width=`${a}%`,e.quota_limit&&me(r,()=>[t("div",{class:"dl-tip-title"},`${a.toFixed(1)}% used`),t("div",{class:"dl-muted"},`${te(e.quota_used)} of ${te(e.quota_limit)} · ${te(Math.max(0,e.quota_limit-e.quota_used))} left`),t("div",{class:"dl-faint"},"Alert at 90%")]);let i=xe([["month","Monthly"],["total","Total"]],e.quota_period,{label:"Data limit period",cls:"sm",optimistic:!1,onChange:l=>n.patch({quota_period:l})}),s=[10,50,100].map(l=>t("button",{type:"button",class:`dl-chipbtn${e.quota_gb===l?" on":""}`,click:()=>n.patch({quota_gb:String(l)},`Data limit ${l} GB`)},`${l} GB`));return s.push(t("button",{type:"button",class:`dl-chipbtn${e.quota_gb?"":" on"}`,click:()=>n.patch({quota_gb:""},"No data limit")},"Unlimited")),s.push(t("button",{type:"button",class:"dl-chipbtn",click:()=>{let l=prompt("Data limit in GB",e.quota_gb?String(e.quota_gb):"");l!=null&&l.trim()!==""&&Number(l)>0&&n.patch({quota_gb:l.trim()},`Data limit ${l.trim()} GB`)}},"Custom")),t("div",{class:"dl-tile2"},[t("div",{class:"dl-tile2-label"},[t("span",{},"Data"),i]),t("div",{class:"dl-tile2-row"},[t("span",{class:"dl-tile2-value"},[te(o),e.quota_limit?t("span",{class:"dl-faint"},` of ${te(e.quota_limit)}`):t("span",{class:"dl-faint"}," · no limit")]),e.quota_period==="month"?t("span",{class:"dl-sub"},"resets on the 1st"):""]),e.quota_limit?r:"",t("div",{class:"dl-chips-row"},s),e.quota_gb&&e.quota_period==="month"?t("div",{class:"dl-tile2-foot"},[t("span",{class:"dl-muted"},e.bonus_gb?`Includes +${e.bonus_gb} GB extra this month`:"Need a little more this month?"),t("a",{href:"#",click:l=>{l.preventDefault(),n.patch({bonus_gb:String((e.bonus_gb||0)+10)},"+10 GB this month")}},"+10 GB this month")]):"",t("div",{class:"dl-tile2-foot"},[t("span",{class:"dl-muted"},`${te(e.total[0]+e.total[1])} in total`),t("button",{type:"button",class:"dl-linkbtn danger",click:()=>vt("person",e.id,e.name,()=>setTimeout(()=>n.refresh(),300))},"Reset usage")])])}function Ji(n){let e=n.p,o=!!e.hours,[a,r]=(e.hours||"07:00-23:00").split("-"),i=t("input",{type:"time",class:"cbi-input-text",value:a,"aria-label":"From"}),s=t("input",{type:"time",class:"cbi-input-text",value:r,"aria-label":"To"}),l=t("div",{class:"dl-tile2-row"},[i,t("span",{class:"dl-faint"},"to"),s]),c=()=>{let p=`${i.value}-${s.value}`;if(p!==e.hours){if(!qa.test(i.value)||!qa.test(s.value))return K("Enter both times, like 07:00 and 23:00.","warning");if(i.value===s.value)return K("The start and the end must differ.","warning");n.patch({hours:p},`Allowed ${i.value}–${s.value}`)}};l.addEventListener("focusout",p=>{l.contains(p.relatedTarget)||c()});for(let p of[i,s])p.addEventListener("keydown",u=>{u.key==="Enter"&&(u.preventDefault(),c())});let d=t("button",{type:"button",role:"switch","aria-checked":o?"true":"false",class:`dl-switch${o?" on":""}`,"aria-label":"Limit hours",click:()=>n.patch({hours:o?"":"07:00-23:00"},o?"Any time":"Allowed 07:00–23:00")},t("i"));return t("div",{class:"dl-tile2"},[t("div",{class:"dl-tile2-row"},[t("div",{class:"dl-stack"},[t("span",{class:"dl-tile2-label"},"Allowed hours"),t("span",{},o?`${a} – ${r} (router time)`:"Any time")]),d]),o?l:""])}function Ka(n){let e=n.p,o=xe(["internet","lan","both"].map(a=>[a,[v(a==="internet"?"globe":a==="lan"?"home":"shield"),a==="internet"?"Internet":a==="lan"?"Home":"Both"]]),e.access,{label:"Access",cls:"wide",optimistic:!1,onChange:a=>n.patch({access:a},`Access: ${ot[a]}`)});return t("section",{class:"dl-devsec","aria-label":"Access and limits"},[t("div",{class:"dl-panel-head"},[t("h3",{},"Access & limits")]),t("div",{class:"dl-panel"},[t("div",{class:"dl-stack gap8"},[t("span",{class:"dl-tile2-label"},"Can reach"),o,t("span",{class:"dl-sub"},Fi[e.access]),e.access==="lan"&&n.st.services.length?Wa(n):"",Ye(e)?Ua(n):"",e.access==="lan"?ja(n):""]),t("div",{class:"dl-tiles2"},[Fa(n),Ga(n),qi(n),Ki(n),Ji(n)])])])}function Vi(n){let e=n.st,o=t("div",{class:"dl-panel-head pad"},[t("h3",{},"Locations"),t("span",{class:"dl-spacer"}),e.geo.enabled?xt("30d",r=>n.map?.setRange(r),!1):"",D("Hide",()=>{n.mapOpen=!1,n.map?.destroy(),n.map=null,n.paintPlaces()},"neutral")]);if(!e.geo.enabled)return t("div",{class:"dl-panel flush"},[o,t("div",{class:"dl-map-off"},["Locations are off. ",t("a",{href:L.url("admin/network/dawnline/settings")},"Turn them on in Settings"),"."])]);let a=new Je({openPerson:()=>{},openDevice:(r,i)=>{let s=n.p.devices.find(l=>l.id===i);s&&Be(n.p,s,n.deviceOpts())}},"30d",280);return n.map=a,requestAnimationFrame(()=>a.mount(n.mapData())),t("div",{class:"dl-panel flush"},[o,a.el])}function Ja(n){let e=n.st;if(!e.geo.enabled)return t("div",{class:"dl-places"},[v("pin"),t("div",{class:"dl-stack"},[t("span",{},"Locations are off"),t("span",{class:"dl-sub"},"City-level, from the client IP")]),t("span",{class:"dl-spacer"}),t("a",{class:"cbi-button cbi-button-neutral",href:L.url("admin/network/dawnline/settings")},"Turn on")]);if(n.mapOpen)return n.map&&n.parts.places.contains(n.map.el)?null:Vi(n);let o=e.now-30*86400,a=e.geo.points.filter(s=>s.person===n.p.id&&s.ts>=o).sort((s,l)=>l.ts-s.ts),r=[...new Set(a.map(s=>s.city||s.country).filter(Boolean))],i=a[0];return t("div",{class:"dl-places"},[v("pin"),t("div",{class:"dl-stack"},[t("span",{},i?i.city||i.country:"No locations yet"),t("span",{class:"dl-sub"},i?`${r.length} place${r.length===1?"":"s"} in 30 days${i.org?` · ${i.org}`:""}`:"Shown after a device connects")]),t("span",{class:"dl-spacer"}),a.length?D("Show map",()=>{n.mapOpen=!0,n.paintPlaces()},"neutral"):""])}function Va(n){let e=n.p,o=n.st,a=n.events.filter(l=>l.person===e.id),r=[],i=[...a].reverse();for(let l=0;l1){let u=p.querySelector(".dl-row-main");dom.content(u,[...qn(o,c).slice(0,3),t("span",{class:"dl-muted"},`${d} times`)]),u.title=i.slice(l,l+d).map(w=>w.detail??"").join(` +`)}r.push(p),l+=d-1}let s=D([v("more")],()=>we(s,[{label:"Export CSV",icon:v("download"),run:()=>Ue(o,a,"csv",e.id)},{label:"Export JSON",icon:v("download"),run:()=>Ue(o,a,"json",e.id)},null,{label:`Clear ${e.name}'s activity`,icon:v("trash"),danger:!0,run:()=>Ke(`Clear ${e.name}'s activity`,`Removes events about ${e.name} and their devices.`,{person:e.id},()=>n.refresh())}]),"neutral",{title:"Export or clear",class:"cbi-button cbi-button-neutral dl-icon-only"});return t("div",{class:"dl-panel flush"},[t("div",{class:"dl-panel-head pad"},[t("h3",{},"Activity"),t("span",{class:"dl-sub"},a.length>10?`latest 10 of ${a.length}`:""),t("span",{class:"dl-spacer"}),s]),r.length?r:t("div",{class:"dl-row dl-muted"},"Nothing yet.")])}var wn=class{constructor(){this.id="";this.events=[];this.mapOpen=!1;this.map=null;this.parts={};this.series=[];this.devSeries={};this.ticks=0;this.fullNext=!1}async fetch(e){let[o,a,r]=await Promise.all([P.status(30),e?P.events(5e3).catch(()=>null):Promise.resolve(null),e?P.personUsage(this.id,30).catch(()=>null):Promise.resolve(null)]);return{st:o,ev:a?.events??null,use:r}}async load(){return this.id=new URLSearchParams(location.search).get("id")??"",this.fetch(!0)}render(e){this.take(e);let o=this.st.people.find(s=>s.id===this.id);if(!o)return t("div",{class:"dl-empty"},[t("h3",{},"Person not found"),t("p",{},"They may have been removed."),t("a",{class:"cbi-button",href:L.url("admin/network/dawnline/server")},"Back to Servers")]);this.p=o;for(let s of["head","devices","traffic","places","activity","limits"])this.parts[s]=t("div",{});this.parts.devices.className="dl-person-devices";let a=t("div",{},[t("nav",{class:"dl-crumbs","aria-label":"Breadcrumb"},[t("a",{href:wt(o.server)},this.st.servers.find(s=>s.id===o.server)?.name??"Servers"),t("span",{},"/"),t("a",{href:wt(o.server)},"People"),t("span",{},"/"),t("span",{},o.name)]),this.parts.head,t("div",{class:"dl-grid-person"},[t("div",{class:"dl-col"},[this.parts.devices,this.parts.traffic,this.parts.places,this.parts.activity]),t("div",{class:"dl-col"},[this.parts.limits])])]);this.paint();let r=new URLSearchParams(location.search),i=r.get("device")&&o.devices.find(s=>s.id===r.get("device"));return i?setTimeout(()=>Be(this.p,i,this.deviceOpts()),50):r.get("add")&&setTimeout(()=>it(this.p,this.deviceOpts()),50),this.poller=Ve({fetch:s=>{let l=s||this.fullNext||++this.ticks%4===0;return this.fullNext=!1,this.fetch(l)},every:15,live:!0,active:()=>a.isConnected,apply:(s,l)=>this.apply(s,l)}),a}take(e){this.st=e.st,e.ev&&(this.events=e.ev),e.use&&(this.series=e.use.person,this.devSeries=e.use.devices)}apply(e,o){this.take(e);let a=this.st.people.find(r=>r.id===this.id);if(!a){o||(location.href=wt(this.p?.server));return}this.p=a,this.paint(o),this.map?.update(this.mapData())}async refresh(){this.fullNext=!0,await this.poller?.refresh()}async patch(e,o){var i;this.poller?.claim();let a=await W(()=>P.personUpdate(this.p.id,e),o);if(!a)return!1;this.poller?.claim();let r=this.st.people.findIndex(s=>s.id===this.p.id);return(i=a.person).rate??(i.rate=this.p.rate),r>=0&&(this.st.people[r]=a.person),this.p=a.person,this.paint(),!0}get today(){return Re(this.series.length?this.series:this.st.series)}get core(){return bt(this.st.servers,this.p.server)}deviceOpts(){return{refresh:()=>this.refresh(),geo:this.st.geo,now:this.st.now,today:this.today,core:this.core,events:()=>this.events}}mapData(){return{geo:this.st.geo,people:this.st.people,now:this.st.now,person:this.p.id}}paint(e=!1){Le(this.parts.head,Ia(this),e),Le(this.parts.traffic,Ba(this),e),Le(this.parts.devices,Oa(this),e),Le(this.parts.limits,Ka(this),e),this.paintPlaces(e),Le(this.parts.activity,Va(this),e)}paintPlaces(e=!1){let o=Ja(this);o&&Le(this.parts.places,o,e&&!this.mapOpen)}};var Yi={ok:"check",warn:"alert",error:"x",skip:"pause"},yn=class{constructor(e,o,a,r){this.el=t("div",{});this.wdEl=t("div",{});this.checksEl=t("div",{class:"dl-panel"});this.recentEl=t("div",{class:"dl-panel flush dl-recent"});this.checks=null;this.summary=t("div",{});this.open=new Set;this.st=e,this.sl=o,this.events=a,this.toLog=r,dom.content(this.el,[this.summary,this.wdEl,t("div",{class:"dl-health-cols"},[this.checksEl,this.recentEl])]),this.paintChecks(),this.paintLive(o,a)}async run(e){let o=e?await fn(e):await P.health().catch(()=>null);o&&(this.take(o),e==="netrestart"&&setTimeout(()=>this.el.isConnected&&void this.run(),5e3))}take(e){this.checks=e.checks,this.paintChecks(),this.paintLive(e,this.events)}paintChecks(){let e=this.checks;if(!e){dom.content(this.summary,""),dom.content(this.checksEl,[t("div",{class:"dl-panel-head"},[t("h3",{},"Checks")]),t("p",{class:"dl-muted dl-loading"},"Running checks…")]);return}let o=e.filter(s=>s.status==="error").length,a=e.filter(s=>s.status==="warn").length;dom.content(this.summary,o?ht("error",`${o} problem${o>1?"s":""} need attention.`):a?ht("warn",`${a} warning${a>1?"s":""}.`):ht("ok","All checks passed."));let r=new Map;for(let s of this.sl.watchdog.repairs)r.set(s.id,Math.max(r.get(s.id)??0,s.ts));let i=()=>this.run();dom.content(this.checksEl,[t("div",{class:"dl-panel-head"},[t("h3",{},"Checks"),t("span",{class:"dl-spacer"}),D("Run again",i)]),t("ul",{class:"dl-checks"},e.map(s=>t("li",{},[t("span",{class:`dl-check-icon ${s.status}`},v(Yi[s.status])),t("div",{class:"dl-check-body"},[t("div",{class:"dl-check-title"},s.title),t("div",{class:"dl-check-detail"},s.detail),r.has(s.id)?t("div",{class:"dl-check-repaired"},`Repaired by the watchdog at ${Mt(r.get(s.id))}`):""]),Kn(s,l=>void this.run(l),i)])))])}paintLive(e,o){this.sl=e,this.events=o;let a=e.watchdog,r=a.beat!=null&&a.now-a.beat>180,i=a.repairs.filter(c=>a.now-c.ts<86400),s=i[i.length-1],l=ge(a.enabled,"Watchdog repairs",async c=>{await W(()=>P.settingsUpdate({watchdog:c?"1":"0"}),c?"Watchdog on":"Watchdog off")||Pn(l,!c);let p=await P.serviceLog().catch(()=>null);p&&this.paintLive(p,this.events)});dom.content(this.wdEl,t("div",{class:"dl-panel dl-wd"},[t("div",{class:"dl-wd-head"},[t("span",{class:`dl-wd-tile${a.enabled?"":" off"}`},v("shield")),t("div",{class:"dl-stack"},[t("span",{class:"dl-wd-title"},"Watchdog"),t("span",{class:"dl-sub"},a.enabled?"Every minute it checks the tunnels and services and repairs what it can on its own.":"Off: problems are only written to the log. Nothing is repaired on its own.")]),t("span",{class:"dl-spacer"}),l]),t("div",{class:"dl-wd-foot"},[t("div",{class:"dl-wd-chips"},a.targets.map(c=>t("span",{class:`dl-check-chip${c.ok?"":" error"}`,title:c.ok?"OK":`Not working${c.tries?` · ${c.tries} repair${c.tries>1?"s":""}`:""}`},[v(c.ok?"check":"x"),c.name]))),t("span",{class:`dl-sub${r?" dl-warn-text":""}`},r?`The agent has not checked in for ${Math.round((a.now-a.beat)/60)} min; cron restarts it after 5.`:[a.last?`Looked ${ie(a.last,a.now)}`:"Starts within a minute"," · ",i.length?`${i.length} repair${i.length>1?"s":""} today, last ${s.name} at ${Mt(s.ts)}`:"no repairs today"])])])),this.paintRecent()}paintRecent(){let e=(this.sl.watchdog.now||Date.now()/1e3)-604800,o=[...this.events.map(r=>({ts:r.ts,ev:r})),...this.sl.log.map(r=>({ts:r.ts,sys:r}))].filter(r=>r.ts>=e&&Jt(r)).sort((r,i)=>i.ts-r.ts),a=t("div",{class:"dl-panel-head pad"},[t("h3",{},"Recent problems"),t("span",{class:"dl-spacer"}),o.length?t("a",{href:"#",click:r=>(r.preventDefault(),this.toLog())},"All in Log →"):""]);if(!o.length){dom.content(this.recentEl,[a,t("div",{class:"dl-recent-empty"},[t("span",{class:"dl-check-icon ok"},v("check")),"No problems in the last 7 days."])]);return}dom.content(this.recentEl,[a,...o.slice(0,8).map(r=>{if(r.sys){let i=r.sys,s=`${i.ts}|${i.msg}`;return un(i,this.open.has(s),()=>{this.open.delete(s)||this.open.add(s),this.paintRecent()},Mt(i.ts))}return Qe(this.st,r.ev,{time:Mt(r.ts)})})])}};var kn=300,Zi=["all","connections","people","system","problems"],$n=class{constructor(e,o,a){this.events=[];this.system=[];this.kind="all";this.shown=kn;this.open=new Set;this.list=t("div",{});this.sub="";this.tabs=t("div",{class:"dl-seg",role:"tablist"});this.st=e,this.take(o),this.system=a,this.el=t("div",{},[t("div",{class:"dl-toolbar"},[this.tabs]),this.list]),this.paint()}actions(){let e=()=>this.kind==="all"?"":this.kind,o=i=>()=>{let s=this.filtered().reverse();Ue(this.st,s.filter(l=>l.ev).map(l=>l.ev),i,e(),s.filter(l=>l.sys).map(l=>l.sys))},a=D([v("download")," Export"],()=>we(a,[{label:"CSV (spreadsheet)",icon:v("download"),run:o("csv")},{label:"JSON",icon:v("download"),run:o("json")}])),r=D([v("trash")," Clear"],()=>Ke("Clear the log","Removes events from the log on the router.",{},()=>this.reload(),this.kind==="all"?void 0:this.kind,!0));return[a,r]}take(e){this.events=e.events,this.policy=e.policy;let o=gt.filter(a=>!e.policy.categories.includes(a));this.sub=`${Vt(e.policy)}${o.length?` Not recorded: ${o.map(a=>rt[a].toLowerCase()).join(", ")}.`:""}`}async reload(){let[e,o]=await Promise.all([P.events(2e4).catch(()=>null),P.serviceLog().catch(()=>null)]);e&&this.take(e),o&&(this.system=o.log),this.paint()}items(){return[...this.events.map(e=>({ts:e.ts,ev:e})),...this.system.map(e=>({ts:e.ts,sys:e}))].sort((e,o)=>o.ts-e.ts)}matches(e,o){return o==="all"?!0:o==="problems"?Jt(e):o==="system"?!!e.sys:!!e.ev&&Tt(e.ev.type)===o}filtered(){return this.items().filter(e=>this.matches(e,this.kind))}paintTabs(e){dom.content(this.tabs,Zi.map(o=>t("button",{type:"button",role:"tab",class:o===this.kind?"on":"","aria-selected":o===this.kind?"true":"false",click:()=>this.show(o)},[o==="all"?"All":o==="system"?"System":rt[o],t("b",{},String(e.filter(a=>this.matches(a,o)).length))])))}show(e){this.kind=e,this.shown=kn,this.paint()}paint(){this.paintTabs(this.items());let e=this.filtered();if(!e.length){dom.content(this.list,t("div",{class:"dl-empty"},[t("p",{},this.events.length||this.system.length?"No events match.":"The log is empty.")]));return}let o=[],a="",r=null;for(let i of e.slice(0,this.shown)){let s=la(i.ts);s!==a&&(a=s,r=t("div",{class:"dl-panel flush"},t("div",{class:"dl-panel-head pad"},t("h3",{},s))),o.push(r));let l=new Date(i.ts*1e3).toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"});if(i.sys){let c=`${i.sys.ts}|${i.sys.msg}`;r.appendChild(un(i.sys,this.open.has(c),()=>{this.open.delete(c)||this.open.add(c),this.paint()},l))}else r.appendChild(Qe(this.st,i.ev,{time:l}))}e.length>this.shown&&o.push(t("div",{class:"dl-more-row"},D(`Show ${Math.min(kn,e.length-this.shown)} more of ${e.length-this.shown}`,()=>{this.shown+=kn,this.paint()}))),dom.content(this.list,o)}};var Qi=[["health","Health"],["log","Log"]],Xn=2e4,En=class{constructor(){this.tab=new URLSearchParams(location.search).get("tab")==="log"?"log":"health";this.segEl=t("div",{class:"dl-seg dl-srvsections dl-diag-tabs",role:"tablist","aria-label":"Diagnostics"});this.subEl=t("span",{class:"dl-muted"});this.actionsEl=t("div",{class:"dl-row-actions"});this.bodyEl=t("div",{});this.eventsAt=0}load(){return this.eventsAt=Date.now(),Promise.all([P.status(1),P.events(Xn),P.serviceLog()])}render([e,o,a]){return this.log=new $n(e,o,a.log),this.health=new yn(e,a,o.events,()=>{this.show("log"),this.log.show("problems")}),this.show(this.tab),Ve({fetch:async()=>{let r=this.tab==="log",[i,s]=await Promise.all([P.serviceLog().catch(()=>null),r?P.events(Xn).catch(()=>null):Promise.resolve(null)]);return i||s?{n:i,e:s}:null},every:10,active:()=>this.bodyEl.isConnected,apply:({n:r,e:i})=>this.take(r,i)}),t("div",{},[t("div",{class:"dl-pagehead"},[t("div",{class:"dl-stack"},[t("h2",{class:"dl-h1"},"Diagnostics"),this.subEl]),this.actionsEl]),this.segEl,this.bodyEl])}take(e,o){o&&(this.log.take(o),this.eventsAt=Date.now()),e&&(this.log.system=e.log),e&&this.health.paintLive(e,o?.events??this.health.events),this.tab==="log"&&this.log.paint()}show(e){this.tab=e,dom.content(this.segEl,Qi.map(([o,a])=>t("button",{type:"button",role:"tab",class:o===e?"on":"","aria-selected":o===e?"true":"false",click:()=>o!==this.tab&&this.show(o)},a))),this.bodyEl.replaceChildren(e==="log"?this.log.el:this.health.el),this.subEl.textContent=e==="log"?this.log.sub:"Everything Dawnline depends on, checked live. The watchdog repairs what it can on its own.",dom.content(this.actionsEl,e==="log"?this.log.actions():""),e==="log"?(this.log.paint(),Date.now()-this.eventsAt>1e4&&P.events(Xn).then(o=>this.take(null,o)).catch(()=>null)):this.health.checks||this.health.run()}};var Ya=":root{--dl-card: var(--panel-bg, var(--background-color-high, transparent));--dl-elevated: var(--elevated, var(--background-color-high, Canvas));--dl-line: var(--border, var(--border-color-medium, color-mix(in srgb, currentColor 14%, transparent)));--dl-soft: var(--muted, color-mix(in srgb, currentColor 5%, transparent));--dl-soft-hover: var(--soft-hover, color-mix(in srgb, currentColor 10%, transparent));--dl-fg: var(--foreground, var(--text-color-highest, inherit));--dl-fg-muted: var(--muted-foreground, color-mix(in srgb, currentColor 65%, transparent));--dl-fg-faint: var(--text-tertiary, color-mix(in srgb, currentColor 50%, transparent));--dl-accent: var(--accent, #3a83f7);--dl-ok: var(--success, #00a240);--dl-warn: var(--warning, #e25507);--dl-bad: var(--danger, #e02e2a);--dl-ok-wash: var(--success-a15, color-mix(in srgb, #00a240 15%, transparent));--dl-warn-wash: var(--warning-a15, color-mix(in srgb, #e25507 15%, transparent));--dl-bad-wash: var(--destructive-a15, color-mix(in srgb, #e02e2a 15%, transparent));--dl-info-wash: var(--info-a15, color-mix(in srgb, #3a83f7 15%, transparent));--dl-info: var(--info, #2c67c5);--dl-track: var(--foreground-a10, color-mix(in srgb, currentColor 10%, transparent));--dl-chart-1: var(--chart-blue, #3a83f7);--dl-chart-2: var(--chart-green, #00a240);--dl-ring: var(--ring, #3a83f7);--dl-primary: var(--primary, #0d0d0d);--dl-primary-fg: var(--primary-foreground, #fff);--dl-mono: var(--font-mono, ui-monospace, Menlo, Consolas, monospace);--dl-shadow: var(--shadow-sm, none);--dl-radius: 16px}.dl-root,.dl-modal{cursor:default}:is(.dl-root,.dl-modal) :is(input:not([type=checkbox],[type=radio],[type=range],[type=button],[type=submit]),textarea,[contenteditable=true]){cursor:text}.dl-icon-wrap{display:inline-flex;align-items:center;justify-content:center;line-height:0}.dl-icon{width:16px;height:16px}.dl-icon-btn{display:inline-flex!important;align-items:center;gap:6px}.dl-muted{color:var(--dl-fg-muted)}.dl-faint,.dl-sep{color:var(--dl-fg-faint)}.dl-nowrap{white-space:nowrap}.dl-mono{font-family:var(--dl-mono);font-size:13px}.dl-spacer{flex:1}.dl-pill{display:inline-flex;align-items:center;gap:4px;height:20px;padding:0 8px;border-radius:999px;font-size:12px;line-height:20px;font-weight:500;white-space:nowrap;background:var(--dl-soft);color:var(--dl-fg-muted)}.dl-pill.ok{background:var(--dl-ok-wash);color:var(--dl-ok)}.dl-pill.warn{background:var(--dl-warn-wash);color:var(--dl-warn)}.dl-pill.bad{background:var(--dl-bad-wash);color:var(--dl-bad)}.dl-pill.accent{background:var(--dl-info-wash);color:var(--dl-info)}.dl-pill.off{opacity:.75}.dl-panel{background:var(--dl-card);border:1px solid var(--dl-line);border-radius:var(--dl-radius);padding:16px;margin:0 0 16px;min-width:0;box-shadow:var(--dl-shadow)}.dl-panel-head{display:flex;align-items:center;flex-wrap:wrap;gap:8px 12px;margin:0 0 12px}.dl-panel-head h3{margin:0!important;padding:0;font-size:16px;line-height:24px;font-weight:500;border:0;background:none}.dl-tiles{display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:12px;margin:0 0 16px}.dl-tile{background:var(--dl-card);border:1px solid var(--dl-line);border-radius:var(--dl-radius);padding:14px 16px;min-width:0;box-shadow:var(--dl-shadow)}.dl-tile-label{font-size:12px;line-height:16px;font-weight:500;color:var(--dl-fg-faint)}.dl-tile-value{font-size:24px;line-height:32px;font-weight:500;margin-top:4px;font-variant-numeric:tabular-nums;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;letter-spacing:-.01em}.dl-tile-sub{font-size:12px;line-height:16px;color:var(--dl-fg-muted);margin-top:2px;font-variant-numeric:tabular-nums}.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)}}.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)}.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}.dl-events li:first-child{border-top:0;padding-top:0}.dl-ev-time{flex:0 0 88px;color:var(--dl-fg-faint);font-variant-numeric:tabular-nums;white-space:nowrap;font-size:13px}.dl-ev-dot{flex:0 0 auto;width:6px;height:6px;border-radius:50%;background:var(--dl-fg-faint);transform:translateY(-2px)}.dl-ev-dot.ok{background:var(--dl-ok)}.dl-ev-dot.warn{background:var(--dl-warn)}.dl-ev-dot.bad{background:var(--dl-bad)}.dl-ev-dot.accent{background:var(--dl-accent)}.dl-row>.dl-ev-dot,.dl-dev-log-row>.dl-ev-dot{margin:0 4px}.dl-ev-tile{flex:none;display:inline-flex;align-items:center;justify-content:center;width:22px;height:22px;margin:-2px -4px;border-radius:7px;background:color-mix(in srgb,var(--dl-accent) 16%,transparent);color:var(--dl-accent);align-self:center}.dl-ev-tile .dl-icon-wrap{display:inline-flex}.dl-ev-tile .dl-icon{width:14px;height:14px}.dl-row.dl-ev-by-admin{background:color-mix(in srgb,var(--dl-accent) 6%,transparent)}.dl-you{color:var(--dl-accent);font-weight:500}.dl-ev-kind{color:var(--dl-fg-faint)}.dl-slotbar{display:flex;align-items:center;gap:8px;margin:8px 0 0 44px}.dl-slotbar-segs{display:flex;gap:3px;flex:none;max-width:100%}.dl-slotbar-segs i{flex:1;min-width:2px;display:block;height:4px;border-radius:2px;background:var(--dl-soft-hover)}.dl-slotbar-segs i.used{background:var(--dl-fg-muted)}.dl-slotbar-text{font-size:12px;color:var(--dl-fg-faint);font-variant-numeric:tabular-nums}.dl-slotbar-segs i.over{background:color-mix(in srgb,var(--dl-warn) 80%,transparent)}.dl-ev-srv{flex:none;font-size:11px;line-height:18px;padding:0 8px;border-radius:999px;background:var(--dl-soft);color:var(--dl-fg-muted);white-space:nowrap}.dl-ev-by-system{--sys: var(--dl-fg-muted)}.dl-ev-by-system.ok{--sys: var(--dl-ok)}.dl-ev-by-system.warn{--sys: var(--dl-warn)}.dl-ev-by-system.bad{--sys: var(--dl-bad)}.dl-ev-tile.ev{background:var(--dl-soft);color:var(--dl-fg-muted)}.dl-ev-tile.ev.ok{background:var(--dl-ok-wash);color:var(--dl-ok)}.dl-ev-tile.ev.warn{background:var(--dl-warn-wash);color:var(--dl-warn)}.dl-ev-tile.ev.bad{background:var(--dl-bad-wash);color:var(--dl-bad)}.dl-ev-tile.ev.accent{background:color-mix(in srgb,var(--dl-accent) 16%,transparent);color:var(--dl-accent)}.dl-ev-tile.sys{background:color-mix(in srgb,var(--sys) 16%,transparent);color:var(--sys)}.dl-row.dl-ev-by-system{background:color-mix(in srgb,var(--sys) 6%,transparent)}.dl-sys-src{color:var(--sys)}.dl-ev-by-system:not(.ok):not(.warn):not(.bad) .dl-sys-src{color:var(--dl-fg)}.dl-ev-text{min-width:0;overflow-wrap:anywhere}.dl-server{display:flex;flex-wrap:wrap;align-items:center;gap:8px 10px}.dl-server-name{font-size:16px;line-height:24px;font-weight:500}.dl-kv{display:grid;grid-template-columns:max-content minmax(0,1fr);gap:6px 24px;margin:12px 0 0;font-size:14px;line-height:20px}.dl-kv dt{color:var(--dl-fg-muted);font-weight:400;margin:0}.dl-kv dd{margin:0;overflow-wrap:anywhere;font-variant-numeric:tabular-nums}";var Za='.dl-plist{display:block}.dl-plist>.dl-card{display:block;margin:0 0 12px;padding:16px;min-width:0;background:var(--dl-card);border:1px solid var(--dl-line);border-radius:var(--dl-radius);box-shadow:var(--dl-shadow)}.dl-plist>.dl-card.dl-filtered{display:none}.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-chip-tag{background:var(--dl-soft);color:var(--dl-fg-muted)}.dl-pcard:has(>.dl-pstrip){row-gap:14px}.dl-pstrip{grid-column:1 / -1;display:flex;align-items:center;flex-wrap:wrap;gap:8px 12px;margin:0 -16px -16px;padding:10px 16px;border-top:1px solid var(--dl-line);border-radius:0 0 var(--dl-radius) var(--dl-radius);font-size:14px;line-height:20px}.dl-pstrip.warn{background:color-mix(in srgb,var(--dl-warn) 7%,transparent)}.dl-pstrip.bad{background:color-mix(in srgb,var(--dl-bad) 7%,transparent)}.dl-pstrip-text{flex:1;min-width:0;display:flex;flex-wrap:wrap;align-items:baseline;gap:0 8px}.dl-pstrip-text b{font-weight:500}.dl-pstrip>.cbi-button{flex:none;height:32px!important}.dl-plist-none{color:var(--dl-fg-muted);text-align:center;padding:28px 16px;background:var(--dl-card);border:1px solid var(--dl-line);border-radius:var(--dl-radius)}.dl-card-head{display:flex;align-items:center;flex-wrap:wrap;gap:6px 8px}.dl-avatar{flex:0 0 auto;width:32px;height:32px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;font-size:12px;font-weight:600;color:var(--dl-fg);background:var(--dl-soft);position:relative;margin-right:4px;letter-spacing:.02em}.dl-avatar.online:after{content:"";position:absolute;right:-1px;bottom:-1px;width:9px;height:9px;border-radius:50%;background:var(--dl-ok);box-shadow:0 0 0 2px var(--dl-card)}.dl-card-name{font-size:16px;line-height:24px;font-weight:500}.dl-card-slug{font-size:13px;color:var(--dl-fg-faint);font-family:var(--dl-mono)}.dl-quota{margin:8px 0 0 44px;max-width:320px;height:6px;border-radius:999px;background:var(--dl-track);overflow:hidden}.dl-quota>i{display:block;height:100%;background:var(--dl-accent);border-radius:999px}.dl-quota.warn>i{background:var(--dl-warn)}.dl-quota.bad>i{background:var(--dl-bad)}.dl-chips{display:flex;flex-wrap:wrap;gap:6px;margin:12px 0 0 44px}.dl-chip{all:unset;box-sizing:border-box;cursor:pointer;display:inline-flex;align-items:center;gap:6px;max-width:240px;height:28px;padding:0 12px 0 10px;border-radius:999px;font-size:13px;background:var(--dl-soft);color:var(--dl-fg);transition:background .15s}.dl-chip:hover{background:var(--dl-soft-hover)}.dl-chip:focus-visible{outline:2px solid var(--dl-ring);outline-offset:2px}.dl-chip .dl-icon{width:14px;height:14px;color:var(--dl-fg-muted)}.dl-chip.add{background:transparent;box-shadow:inset 0 0 0 1px var(--dl-line);color:var(--dl-fg-muted);aspect-ratio:1;padding:0;justify-content:center}.dl-chip.add:hover{background:var(--dl-soft);color:var(--dl-fg)}.dl-chip.disabled .dl-chip-name{text-decoration:line-through;color:var(--dl-fg-faint)}.dl-chip-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-dot{flex:0 0 auto;width:6px;height:6px;border-radius:50%;background:var(--dl-fg-faint);opacity:.6}.dl-dot.online{background:var(--dl-ok);opacity:1;box-shadow:0 0 0 3px var(--dl-ok-wash)}.dl-empty{text-align:center;padding:40px 16px;background:var(--dl-card);border:1px solid var(--dl-line);border-radius:var(--dl-radius)}.dl-empty .dl-icon-wrap{width:40px;height:40px;border-radius:12px;background:var(--dl-soft);margin-bottom:12px}.dl-empty .dl-icon{width:20px;height:20px}.dl-empty h3{margin:0 0 4px!important;font-size:16px;font-weight:500}.dl-empty p{margin:0 0 16px;color:var(--dl-fg-muted);font-size:14px}.dl-toolbar{display:flex;flex-wrap:wrap;align-items:center;gap:8px 12px;margin:0 0 16px}.dl-toolbar .dl-muted{font-size:13px}@media(max-width:640px){.dl-slotbar,.dl-chips,.dl-quota{margin-left:0}.dl-btn-label{display:none}}.cbi-value.dl-block{display:block!important}.cbi-value.dl-block>.cbi-value-title{display:block;width:auto;float:none;text-align:left;padding:0 0 8px}.cbi-value.dl-block>.cbi-value-field{display:block;width:100%;margin:0}';var Qa="#modal_overlay{z-index:1100!important}.dl-dd{position:fixed;z-index:1200;min-width:200px;padding:4px;border-radius:12px;background:var(--dl-elevated);border:1px solid var(--dl-line);box-shadow:0 12px 32px #0000004d;display:flex;flex-direction:column}.dl-dd button{all:unset;cursor:pointer;display:flex;align-items:center;gap:10px;padding:7px 10px;border-radius:8px;font-size:13px;color:var(--dl-fg)}.dl-dd button .dl-icon{width:15px;height:15px;color:var(--dl-fg-muted)}.dl-dd button:hover,.dl-dd button:focus-visible{background:var(--dl-soft)}.dl-dd button.danger,.dl-dd button.danger .dl-icon{color:var(--dl-bad, #e5484d)}.dl-dd button.warn,.dl-dd button.warn .dl-icon{color:var(--dl-warn)}.dl-dd hr{border:0;border-top:1px solid var(--dl-line);margin:4px 0}.dl-chipbtn b{font-weight:500;font-size:11px;margin-left:6px;opacity:.6}.dl-setsub{margin:20px 0 8px!important;font-size:13px;font-weight:500;color:var(--dl-fg)}.dl-row-actions{display:flex;flex-wrap:wrap;gap:8px;align-items:center}.dl-more-row{display:flex;justify-content:center;padding:8px 0 16px}.dl-dsec-actions{display:flex;align-items:center;gap:12px}.dl-kv-act{display:inline-flex;align-items:center;gap:12px;flex-wrap:wrap}.dl-linkbtn,.dl-bento-head a,.dl-bento-foot a,.dl-panel-head a,.dl-dsec-head a,.dl-tile2-foot a{all:unset;box-sizing:border-box;cursor:pointer;display:inline-flex;align-items:center;gap:4px;height:26px;padding:0 9px;margin:-4px -6px;border-radius:8px;font-size:12px;font-weight:500;color:var(--dl-fg-muted);text-decoration:none!important;white-space:nowrap;transition:background .12s,color .12s}.dl-bento-head a,.dl-bento-foot a,.dl-panel-head a,.dl-dsec-head a,.dl-tile2-foot a{color:var(--dl-accent)}.dl-linkbtn:hover,.dl-bento-head a:hover,.dl-bento-foot a:hover,.dl-panel-head a:hover,.dl-dsec-head a:hover,.dl-tile2-foot a:hover{background:var(--dl-soft);color:var(--dl-fg);text-decoration:none!important}.dl-bento-head a:hover,.dl-bento-foot a:hover,.dl-panel-head a:hover,.dl-dsec-head a:hover,.dl-tile2-foot a:hover{background:color-mix(in srgb,var(--dl-accent) 12%,transparent);color:var(--dl-accent)}.dl-linkbtn:focus-visible,.dl-bento-head a:focus-visible,.dl-bento-foot a:focus-visible,.dl-panel-head a:focus-visible{outline:2px solid var(--dl-ring);outline-offset:1px}.dl-linkbtn.danger:hover{color:var(--dl-bad);background:var(--dl-bad-wash)}.dl-ifcards{display:flex;flex-direction:column;gap:20px;margin:24px 0}.dl-ifcard .dl-setsec-body{gap:14px}.dl-iflead{display:flex;flex-direction:column;gap:2px;padding-top:14px;border-top:1px solid var(--dl-line)}.dl-iflead b{font-size:14px;font-weight:500}.dl-ifgroup h4{margin:0 0 8px!important;padding:0!important;font-size:11px!important;font-weight:500!important;letter-spacing:.06em;text-transform:uppercase;color:var(--dl-fg-muted);border:0!important;background:none!important}.dl-ifgrid{display:grid;grid-template-columns:repeat(auto-fill,minmax(210px,1fr));gap:8px}.dl-if{all:unset;box-sizing:border-box;cursor:pointer;display:flex;align-items:center;gap:10px;min-height:52px;padding:8px 12px 8px 10px;min-width:0;border:1px solid var(--dl-line);border-radius:10px;background:var(--dl-card);transition:background .15s,border-color .15s}.dl-if:hover{background:var(--dl-soft)}.dl-if:focus-visible{outline:2px solid var(--dl-ring);outline-offset:2px}.dl-if-ic{width:30px;height:30px;border-radius:8px;background:var(--dl-soft);display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;color:var(--dl-fg-muted)}.dl-if-ic .dl-icon{width:16px;height:16px}.dl-if-main{display:flex;flex-direction:column;min-width:0;flex:1}.dl-if-name{font-size:13.5px;font-weight:500;color:var(--dl-fg);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.dl-if-sub{font:11px/16px var(--dl-mono);color:var(--dl-fg-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.dl-if.sel{border-color:var(--dl-accent);background:color-mix(in srgb,var(--dl-accent) 9%,transparent)}.dl-if.sel .dl-if-ic{background:color-mix(in srgb,var(--dl-accent) 18%,transparent);color:var(--dl-accent)}.dl-if-check{color:var(--dl-accent);display:inline-flex}.dl-if-check .dl-icon{width:16px;height:16px}.dl-if.auto{border-color:color-mix(in srgb,var(--dl-ok) 55%,transparent);background:var(--dl-ok-wash);cursor:default}.dl-if.auto .dl-if-ic{background:color-mix(in srgb,var(--dl-ok) 18%,transparent);color:var(--dl-ok)}.dl-if-badge{display:inline-flex;align-items:center;gap:5px;font-size:10.5px;font-weight:600;letter-spacing:.05em;text-transform:uppercase;flex:0 0 auto}.dl-if-badge.ok{color:var(--dl-ok)}.dl-if.off{cursor:default;opacity:.5}.dl-if.off:hover{background:var(--dl-card)}.dl-if.warn{border-color:color-mix(in srgb,var(--dl-warn) 60%,transparent)}.dl-if-wanctl{gap:10px;align-items:center}.dl-if-wanctl select{max-width:240px}.dl-if-summary{min-width:0;line-height:18px}.dl-warn{color:var(--dl-warn)}.dl-w-ip{width:160px}.dl-dnspick{padding-top:8px;border-top:1px solid var(--dl-line)}.dl-dnspick .dl-row-actions{gap:10px}.dl-note{display:flex;gap:8px;align-items:flex-start;padding:10px 12px;border-radius:10px;font-size:12.5px;line-height:18px;margin:0 0 10px;background:var(--dl-soft)}.dl-note.warn{background:var(--dl-warn-wash, color-mix(in srgb, var(--dl-warn) 14%, transparent))}.dl-note .dl-icon{width:15px;height:15px;flex:0 0 auto;margin-top:1px;color:var(--dl-warn)}.dl-stale{align-self:flex-start;margin-top:4px;font-size:10.5px}.dl-root .cbi-button.dl-btn-warn,.dl-btn-warn.cbi-button{background:var(--dl-warn-wash)!important;color:var(--dl-warn)!important;border-color:color-mix(in srgb,var(--dl-warn) 35%,transparent)!important}.dl-root .cbi-button.dl-btn-warn:hover,.dl-btn-warn.cbi-button:hover{background:color-mix(in srgb,var(--dl-warn) 24%,transparent)!important}.dl-btn-warn .dl-icon{color:var(--dl-warn)}.dl-srvtabs{display:flex;flex-wrap:wrap;gap:6px;padding:4px;margin:0 0 20px;border-radius:12px;background:var(--dl-soft);width:fit-content;max-width:100%}.dl-srvtab{all:unset;box-sizing:border-box;cursor:pointer;display:inline-flex;align-items:center;gap:8px;height:34px;padding:0 14px;border-radius:9px;font-size:13px;color:var(--dl-fg-muted);text-decoration:none!important;white-space:nowrap}.dl-srvtab b{font-weight:500}.dl-srvtab i.dot{width:7px;height:7px;border-radius:50%;background:var(--dl-fg-faint);flex:0 0 auto}.dl-srvtab i.dot.ok{background:var(--dl-ok);animation:dl-srv-pulse 2s ease-out infinite}.dl-srvtab i.dot.bad{background:var(--dl-bad)}.dl-srvtab i.dot.warn{background:var(--dl-warn)}@keyframes dl-srv-pulse{0%{box-shadow:0 0 color-mix(in srgb,var(--dl-ok) 55%,transparent)}70%,to{box-shadow:0 0 0 6px transparent}}@media(prefers-reduced-motion:reduce){.dl-srvtab i.dot.ok{animation:none}}.dl-srvtab:hover{color:var(--dl-fg);background:var(--dl-soft-hover)}.dl-srvtab.on{background:var(--dl-card);color:var(--dl-fg);box-shadow:0 1px 2px #0000002e,inset 0 0 0 1px var(--dl-line)}.dl-srvtab:focus-visible{outline:2px solid var(--dl-ring);outline-offset:1px}.dl-srvtab.add{color:var(--dl-fg-muted)}.dl-srvtab.add .dl-icon{width:14px;height:14px}.dl-srvhead{display:flex;flex-direction:column;gap:14px;margin:0 0 20px}.dl-srvhead .dl-title-row{display:flex;align-items:center;gap:10px}.dl-srvhead .dl-h1{margin:0!important}.dl-metrics.compact .dl-metric{padding:14px 18px}.dl-metrics.compact .dl-metric-value{display:flex;align-items:center;gap:6px;font-size:18px;line-height:26px;min-width:0}.dl-metrics.compact .dl-metric-value>span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.dl-metrics.compact .dl-metric-value .dl-mono{font-size:15px}.dl-metrics.compact .cbi-button{flex:0 0 auto}.dl-srvsections{margin:0 0 16px}.dl-srvbody>.dl-setsec,.dl-srvbody>.dl-ifcards{margin:0}.dl-srvbody .dl-ifcards{margin:0}.dl-metric-ic{display:inline-flex;align-items:center;gap:8px;font-size:16px}.dl-metric-ic .dl-icon{width:18px;height:18px;color:var(--dl-accent)}.dl-keyrow{display:inline-flex;align-items:center;gap:8px;min-width:0}.dl-keyrow code{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:12px;background:none;padding:0}.dl-params{border:1px solid var(--dl-line);border-radius:12px;background:var(--dl-card)}.dl-params>summary{list-style:none;cursor:pointer;display:flex;align-items:center;gap:8px;padding:10px 14px;font-size:13px;color:var(--dl-fg);user-select:none}.dl-params>summary::-webkit-details-marker{display:none}.dl-params>summary>.dl-icon-wrap{display:inline-flex;color:var(--dl-fg-muted);transition:transform .15s}.dl-params>summary>.dl-icon-wrap .dl-icon{width:15px;height:15px}.dl-params[open]>summary>.dl-icon-wrap{transform:rotate(90deg)}.dl-params>summary:focus{outline:none}.dl-params>summary:focus-visible{outline:2px solid var(--dl-ring);outline-offset:-2px;border-radius:12px}.dl-params>summary:hover{background:var(--dl-soft);border-radius:12px}.dl-pcount{font-size:11px;padding:0 6px;border-radius:999px;background:var(--dl-soft);color:var(--dl-fg-muted)}.dl-pgrid{display:grid;grid-template-columns:repeat(auto-fill,minmax(260px,1fr));gap:10px;padding:4px 14px 14px}.dl-pgroup{display:flex;flex-direction:column;gap:6px;padding:12px;border-radius:10px;background:var(--dl-soft);min-width:0}.dl-pgroup-head{display:flex;align-items:center;gap:8px;font-size:13px}.dl-pgroup-head b{font-weight:500}.dl-pgroup-head .dl-icon{width:14px;height:14px;color:var(--dl-fg-muted)}.dl-pgroup p{margin:0!important;font-size:12px;line-height:17px;color:var(--dl-fg-muted)}.dl-pvals{display:flex;flex-wrap:wrap;gap:4px;margin-top:2px}.dl-pv{display:inline-flex;align-items:stretch;max-width:100%;border-radius:6px;overflow:hidden;font:500 11.5px/22px var(--dl-mono);box-shadow:inset 0 0 0 1px var(--dl-line)}.dl-pv i{font-style:normal;padding:0 6px;background:var(--dl-card);color:var(--dl-fg-faint)}.dl-pv b{font-weight:500;padding:0 7px;color:var(--dl-fg);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}";var Xa=".dl-methods{display:grid;grid-template-columns:repeat(auto-fit,minmax(210px,1fr));gap:10px}.dl-method{all:unset;box-sizing:border-box;cursor:pointer;display:flex;flex-direction:column;gap:10px;padding:14px;border-radius:12px;border:1px solid var(--dl-line);background:var(--dl-card);transition:border-color .15s,background .15s;min-width:0}.dl-method:hover{background:var(--dl-soft)}.dl-method:focus-visible{outline:2px solid var(--dl-ring);outline-offset:2px}.dl-method.on{border-color:var(--dl-accent);background:color-mix(in srgb,var(--dl-accent) 8%,transparent);box-shadow:inset 0 0 0 1px var(--dl-accent)}.dl-method.off{cursor:not-allowed;opacity:.55}.dl-method.off:hover{background:var(--dl-card)}.dl-method-head{display:flex;flex-wrap:wrap;align-items:center;gap:8px 10px}.dl-method-head .dl-pill{flex:none}.dl-method-head b{font-weight:500;font-size:14.5px;flex:1}.dl-method-ic{width:32px;height:32px;border-radius:9px;background:var(--dl-soft);display:inline-flex;align-items:center;justify-content:center;color:var(--dl-fg-muted);flex:0 0 auto}.dl-method-ic .dl-icon{width:17px;height:17px}.dl-method.on .dl-method-ic{background:color-mix(in srgb,var(--dl-accent) 18%,transparent);color:var(--dl-accent)}.dl-method p{margin:0!important;font-size:12.5px;line-height:18px;color:var(--dl-fg-muted);flex:1}.dl-method-meters{display:flex;gap:16px}.dl-dots{display:inline-flex;align-items:center;gap:6px;font-size:11px;color:var(--dl-fg-faint)}.dl-dots-row{display:inline-flex;gap:3px}.dl-dots-row i{width:6px;height:6px;border-radius:50%;background:var(--dl-line)}.dl-dots-row i.on{background:var(--dl-fg-muted)}.dl-method.on .dl-dots-row i.on{background:var(--dl-accent)}.dl-method-foot{display:flex;align-items:center;gap:6px;font-size:11.5px;color:var(--dl-fg-faint);padding-top:8px;border-top:1px solid var(--dl-line)}.dl-method-foot .dl-icon{width:13px;height:13px;flex:0 0 auto}.dl-method.off .dl-method-foot{color:var(--dl-warn)}.dl-ibadge{display:inline-flex;align-items:center;gap:3px;height:22px;padding:0 6px;border-radius:999px;background:var(--dl-soft);color:var(--dl-fg-muted);flex:0 0 auto}.dl-ibadge .dl-icon{width:13px;height:13px}.dl-ibadge.warn{background:var(--dl-warn-wash);color:var(--dl-warn)}.dl-ibadge.bad{background:var(--dl-bad-wash);color:var(--dl-bad)}.dl-access{display:inline-flex;gap:4px;flex:0 0 auto}.dl-ibadge.lan{background:color-mix(in srgb,var(--dl-accent) 16%,transparent);color:var(--dl-accent)}.dl-ibadge.inet{background:var(--dl-ok-wash);color:var(--dl-ok)}";var er=".dl-addrbar{display:inline-flex;align-items:stretch;flex-wrap:nowrap;max-width:100%;margin-top:4px;border:1px solid var(--dl-line);border-radius:10px;background:var(--dl-card);overflow:hidden}.dl-addrbar-seg{all:unset;box-sizing:border-box;display:inline-flex;align-items:center;gap:7px;padding:6px 12px;font-size:13px;color:var(--dl-fg-muted);border-left:1px solid var(--dl-line);white-space:nowrap;min-width:0}.dl-addrbar-seg:first-child{border-left:0}.dl-addrbar-seg .dl-icon{width:14px;height:14px;color:var(--dl-fg-faint);flex:0 0 auto}.dl-addrbar-seg .dl-mono{font-size:12.5px}.dl-addrbar-seg.main{cursor:pointer;color:var(--dl-fg)}.dl-addrbar-seg.main:hover{background:var(--dl-soft)}.dl-addrbar-seg.main:focus-visible{outline:2px solid var(--dl-ring);outline-offset:-2px}.dl-addrbar-seg.main>.dl-icon-wrap:last-child .dl-icon{opacity:.7}.dl-bento{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));grid-template-rows:auto auto;gap:10px;margin:0 0 20px}.dl-person-devices{margin-bottom:16px}.dl-person-head{display:flex;flex-direction:column;margin:0 0 20px}.dl-person-head>.dl-pagehead{margin-bottom:0;align-items:flex-start}.dl-pnote{all:unset;box-sizing:border-box;cursor:pointer;align-self:flex-start;display:inline-flex;align-items:flex-start;gap:6px;margin:10px 0 0 62px;max-width:60ch;padding:6px 12px 6px 10px;border-radius:10px;font-size:13px;line-height:18px;white-space:pre-line;background:var(--dl-soft);color:var(--dl-fg);box-shadow:inset 0 0 0 1px var(--dl-line)}.dl-pnote:hover{background:var(--dl-soft-hover)}.dl-pnote .dl-icon{width:14px;height:14px;flex:none;margin-top:2px;color:var(--dl-fg-muted)}.dl-note-input{width:100%;box-sizing:border-box;min-height:80px;resize:vertical}.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;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 i:hover{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}.dl-chipbtn:has(.dl-icon){display:inline-flex;align-items:center;gap:5px}.dl-places{display:flex;align-items:center;gap:12px;padding:12px 16px;border:1px solid var(--dl-line);border-radius:var(--dl-radius);background:var(--dl-card);font-size:14px}.dl-places>.dl-icon{width:18px;height:18px;color:var(--dl-fg-muted);flex:none}.dl-person-live{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:10px}.dl-person-live .dl-bento-head{flex-wrap:nowrap;white-space:nowrap;min-width:0}.dl-person-live .dl-bento-head>*{min-width:0;overflow:hidden;text-overflow:ellipsis}.dl-person-live .dl-bento-head>:first-child{flex:none}.dl-person-live.solo{grid-template-columns:minmax(0,1fr)}.dl-person-live:not(.solo) .dl-bento-tile.month>.dl-bento-head:first-child{flex-wrap:wrap;row-gap:2px}.dl-person-live:not(.solo) .dl-bento-tile.month>.dl-bento-head:first-child>.dl-sub{flex-basis:100%}.dl-person-live>.dl-bento-tile,.dl-person-live>.dl-bento-tile.month{grid-column:auto;grid-row:auto}@media(max-width:760px){.dl-person-live{grid-template-columns:minmax(0,1fr)}}.dl-bento-tile{background:var(--dl-card);border:1px solid var(--dl-line);border-radius:var(--dl-radius);padding:14px 16px;display:flex;flex-direction:column;gap:10px;min-width:0;box-shadow:var(--dl-shadow)}.dl-bento-tile.month{grid-column:1 / -1}.dl-onl-count{font-size:13px;line-height:22px;min-width:22px;padding:0 8px;border-radius:999px;background:var(--dl-soft);text-align:center;font-weight:500;font-variant-numeric:tabular-nums}.dl-onl-count.none{color:var(--dl-fg-faint)}.dl-onl-row{flex:1;display:flex;align-items:center;justify-content:center;gap:12px;min-width:0}.dl-onl-p{display:flex;flex-direction:column;align-items:center;gap:5px;width:104px;min-width:0;padding:6px 2px;border-radius:12px;color:var(--dl-fg)!important;text-decoration:none!important}.dl-onl-p:hover{background:var(--dl-soft)}.dl-onl-av{position:relative;width:42px;height:42px;border-radius:50%;background:var(--dl-soft);display:inline-flex;align-items:center;justify-content:center;font-size:13px;font-weight:500;box-shadow:0 0 0 2px var(--dl-ok)}.dl-onl-p.more .dl-onl-av{box-shadow:0 0 0 1px var(--dl-line);color:var(--dl-fg-muted)}.dl-onl-dev{position:absolute;right:-6.5px;bottom:-6.5px;width:20px;height:20px;border-radius:8.5px;border:1.5px solid transparent;background:var(--dl-card);display:inline-flex;align-items:center;justify-content:center;font-size:10px;color:var(--dl-fg-muted)}.dl-onl-dev .dl-icon-wrap{display:inline-flex}.dl-onl-dev .dl-icon{width:12px;height:12px}.dl-onl-name{font-size:12.5px;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-onl-p .dl-sub{font-size:11px;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-onl-row.grid{flex-wrap:wrap;align-content:center;gap:10px 8px;max-height:108px;overflow:hidden}.dl-onl-p.sm{width:auto;padding:4px}.dl-onl-p:hover .dl-onl-dev{background:linear-gradient(var(--dl-soft),var(--dl-soft)),var(--dl-card)}.dl-onl-p.sm:hover{background:none}.dl-onl-p.sm:hover .dl-onl-dev{background:var(--dl-card)}.dl-onl-p.sm .dl-onl-av{transition:box-shadow .15s ease}.dl-onl-p.sm:hover .dl-onl-av{box-shadow:0 0 0 2px var(--dl-ok),0 0 0 6px var(--dl-soft)}.dl-onl-p.sm.more:hover .dl-onl-av{box-shadow:0 0 0 1px var(--dl-line),0 0 0 6px var(--dl-soft)}.dl-onl-p.sm .dl-onl-av{width:36px;height:36px;font-size:11.5px}.dl-onl-meta{display:inline-flex;align-items:center;gap:3px;font-size:11px;color:var(--dl-fg-faint);max-width:100%;white-space:nowrap;overflow:hidden}.dl-onl-meta .dl-icon-wrap{display:inline-flex}.dl-onl-meta .dl-icon{width:12px;height:12px}.dl-onl-av.sm{width:34px;height:34px;font-size:11.5px}.dl-tip-float:has(.dl-hc){padding:0;white-space:normal;border-radius:16px}.dl-hc{width:280px;padding:14px;display:flex;flex-direction:column;gap:10px}.dl-hc-head{display:flex;align-items:center;gap:10px}.dl-hc-head .dl-stack{flex:1;min-width:0}.dl-hc-head b{font-size:14px;font-weight:500}.dl-hc-since{font-size:11.5px;color:var(--dl-ok)}.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)}.dl-hc-foot{display:flex;align-items:center;gap:8px;font-size:11.5px}.dl-disg-id{display:flex;align-items:center;gap:10px}.dl-disg-id b{font-size:16px;font-weight:500}.dl-disg-ic{width:36px;height:36px;border-radius:11px;background:color-mix(in srgb,var(--dl-accent) 14%,transparent);color:var(--dl-accent);display:inline-flex;align-items:center;justify-content:center;flex:none}.dl-disg-ic .dl-icon-wrap{display:inline-flex}.dl-disg-ic .dl-icon{width:18px;height:18px}.dl-disg-meters{display:grid;grid-template-columns:auto 1fr;gap:6px 10px;align-items:center;font-size:12px;color:var(--dl-fg-muted)}.dl-segs{display:inline-flex;gap:3px}.dl-segs i{width:18px;height:5px;border-radius:3px;background:var(--dl-track)}.dl-segs.acc i.on{background:var(--dl-accent)}.dl-segs.ok i.on{background:var(--dl-ok)}.dl-disg-chips{margin-top:auto;display:flex;flex-wrap:wrap;gap:5px}.dl-disg-chips span{font:11px/20px var(--dl-mono);padding:0 8px;border-radius:999px;background:var(--dl-soft);color:var(--dl-fg-muted);white-space:nowrap}.dl-onl-empty{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;font-size:13px;text-align:center}.dl-bento-head{display:flex;align-items:center;justify-content:space-between;gap:10px;min-width:0}.dl-bento-head.start{justify-content:flex-start}.dl-bento-big{font-family:inherit;font-size:28px;line-height:34px;font-weight:500;letter-spacing:-.01em;font-variant-numeric:tabular-nums;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.dl-bento-big small{font-size:13px;font-weight:400;color:var(--dl-fg-faint);letter-spacing:0}.dl-avstack{display:inline-flex}.dl-avstack .dl-avatar{margin-left:-7px;box-shadow:0 0 0 2px var(--dl-card)}.dl-avstack .dl-avatar:first-child{margin-left:0}.dl-avatar.more{background:var(--dl-soft);color:var(--dl-fg-muted)}.dl-bento-list{display:flex;flex-direction:column;gap:2px}.dl-bento-row{display:flex;align-items:center;gap:10px;padding:8px;margin:0 -8px;border-radius:10px;color:var(--dl-fg)!important;text-decoration:none!important;min-width:0;transition:background .12s}.dl-bento-row:hover{background:var(--dl-soft)}.dl-bento-row:hover b{text-decoration:none}.dl-bento-row:focus-visible{outline:2px solid var(--dl-ring);outline-offset:-2px}.dl-bento-row-main{display:flex;flex-direction:column;gap:1px;flex:1;min-width:0}.dl-bento-row-main b{font-weight:500;font-size:13.5px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-bento-row-main .dl-sub{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-bento-row.off b{color:var(--dl-fg-muted);font-weight:400}.dl-bento-row-val{display:flex;flex-direction:column;align-items:flex-end;font-size:13px;font-variant-numeric:tabular-nums;white-space:nowrap}.dl-bento-row-val small{font-size:11px;color:var(--dl-fg-faint)}.dl-bento-sep{font-size:11px;color:var(--dl-fg-faint);padding:12px 0 4px}.dl-bento-devs{display:inline-flex;gap:3px;color:var(--dl-fg-faint)}.dl-bento-devs .dl-icon{width:13px;height:13px}.dl-bento-devs .on{color:var(--dl-ok)}.dl-bento-foot{display:flex;align-items:center;gap:10px;margin-top:auto;padding-top:10px;border-top:1px solid var(--dl-line);color:var(--dl-fg)!important;text-decoration:none!important}.dl-bento-foot.split,.dl-bento-foot.end{justify-content:space-between}.dl-bento-foot.end>a:only-child{margin-left:auto}.dl-bento-empty{display:flex;align-items:center;gap:10px;padding:14px 0;font-size:13.5px;color:var(--dl-fg-muted)}.dl-bento-empty .dl-icon{width:18px;height:18px}.dl-split{display:flex;height:6px;border-radius:3px;overflow:hidden;background:var(--dl-soft)}.dl-split i{display:block;height:100%}.dl-split i.dn{background:var(--dl-accent)}.dl-split i.up{background:var(--dl-ok)}.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;gap:3px;height:54px}.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 i:hover{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}}.dl-srvpagehead{display:flex;flex-direction:column;align-items:flex-start;gap:10px;margin:0 0 20px}.dl-srvpagehead>.dl-title-row{display:flex;align-items:center;gap:10px;width:100%;flex-wrap:wrap}.dl-srvpagehead .dl-actions{margin:0;flex-wrap:wrap}.dl-toolbar-end{display:flex;align-items:center;gap:8px;margin-left:auto;flex-wrap:nowrap;min-width:0}@media(max-width:640px){.dl-toolbar-end{flex-wrap:wrap;width:100%}}.dl-notices{margin:0 0 16px}.dl-notices .dl-need-row .dl-sub{overflow-wrap:anywhere}.dl-notices-more{font-size:13px;color:var(--dl-fg-muted);text-decoration:none}.dl-notices-more:hover{background:var(--dl-soft);color:var(--dl-fg)}.dl-speed-cols{display:grid;grid-template-columns:1fr 1fr;gap:12px}.dl-speed-col{display:flex;flex-direction:column;gap:2px;min-width:0}.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)}.dl-fld .cbi-input-text{width:100%;box-sizing:border-box}.dl-kinds{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:6px}.dl-kinds button{all:unset;box-sizing:border-box;cursor:pointer;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6px;height:68px;border-radius:10px;border:1px solid var(--dl-line);color:var(--dl-fg-muted);font-size:12px;font-weight:500;text-align:center;min-width:0}.dl-kinds button .dl-icon{width:20px;height:20px}.dl-kinds button:hover{background:var(--dl-soft);color:var(--dl-fg)}.dl-kinds button:focus-visible{outline:2px solid var(--dl-ring);outline-offset:2px}.dl-kinds button.on{border-color:var(--dl-accent);color:var(--dl-fg);background:color-mix(in srgb,var(--dl-accent) 10%,transparent);box-shadow:inset 0 0 0 1px var(--dl-accent)}.dl-kinds button.on .dl-icon{color:var(--dl-accent)}.dl-choices{display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:8px}.dl-choice{all:unset;box-sizing:border-box;cursor:pointer;display:flex;flex-direction:column;gap:4px;padding:12px 14px;border-radius:12px;background:var(--dl-card);box-shadow:inset 0 0 0 1px var(--dl-line);transition:background .15s,box-shadow .15s}.dl-choice:hover{background:var(--dl-soft)}.dl-choice:focus-visible{outline:2px solid var(--dl-ring);outline-offset:2px}.dl-choice.selected{box-shadow:inset 0 0 0 2px var(--dl-accent);background:var(--accent-a10, color-mix(in srgb, var(--dl-accent) 8%, transparent))}.dl-choice-title{display:flex;align-items:center;gap:8px;font-size:14px;font-weight:500;color:var(--dl-fg)}.dl-choice-text{font-size:12px;line-height:16px;color:var(--dl-fg-muted)}.dl-attn-item>.cbi-button{margin-left:auto;flex:none;align-self:center}";var tr='.dl-steps{display:flex;align-items:center;gap:8px;margin:0 0 16px;flex-wrap:wrap}.dl-step{display:flex;align-items:center;gap:8px;font-size:14px;font-weight:500;color:var(--dl-fg-faint)}.dl-step b{display:inline-flex;width:24px;height:24px;align-items:center;justify-content:center;border-radius:50%;background:var(--dl-soft);font-size:12px;font-weight:600}.dl-step.current{color:var(--dl-fg)}.dl-step.current b{background:var(--dl-primary);color:var(--dl-primary-fg)}.dl-step.done{color:var(--dl-fg-muted)}.dl-step.done b{background:var(--dl-ok-wash);color:var(--dl-ok)}.dl-step+.dl-step:before{content:"";width:24px;height:1px;background:var(--dl-line)}.dl-wizard .dl-panel>div{display:flex;flex-direction:column;gap:16px}.dl-wizard .dl-panel>div>p{margin:0!important;color:var(--dl-fg-muted)}.dl-wizard .dl-panel>div>.cbi-value{margin:0}.dl-wizard h4{font-size:14px;font-weight:500;margin:8px 0 -6px!important}.dl-wizard h4:first-child{margin-top:0!important}.dl-modal .cbi-tabmenu{margin-bottom:16px}.dl-checklist{display:flex;flex-direction:column;gap:6px;margin:4px 0 8px}.dl-checklist label{display:flex;align-items:center;gap:8px;font-size:14px;cursor:pointer}.dl-checklist input{margin:0}.dl-invite{display:grid;grid-template-columns:250px minmax(0,1fr);gap:22px;align-items:start}.dl-invite img{display:block;width:100%;border-radius:18px;box-shadow:0 0 0 1px var(--dl-line)}.dl-invite-side{display:flex;flex-direction:column;gap:14px;min-width:0}.dl-invite-side>p{margin:0!important}.dl-invite-link{all:unset;box-sizing:border-box;cursor:pointer;display:flex;align-items:center;gap:10px;min-width:0;padding:11px 14px;border-radius:12px;background:var(--dl-soft);font:13px/18px var(--dl-mono);color:var(--dl-fg)}.dl-invite-link>span:first-child{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-invite-link>.dl-icon-wrap{flex:none;display:inline-flex}.dl-invite-link .dl-icon{width:15px;height:15px;color:var(--dl-fg-muted);flex:none}.dl-invite-link:hover{background:var(--dl-soft-hover)}.dl-invite-link.alt{padding:8px 14px;font-size:12px;color:var(--dl-fg-muted)}.dl-invite-link>.dl-pill{flex:none}.dl-invite-steps{margin:0;padding-left:20px;list-style:decimal!important;font-size:13px;line-height:24px;color:var(--dl-fg-muted)}.dl-invite-steps b{color:var(--dl-fg);font-weight:500}.dl-invite-steps li{display:list-item!important;list-style:inherit!important;padding-left:4px}.dl-invite-actions{display:flex;gap:8px;flex-wrap:wrap}.modal:has(.dl-modal.wide){max-width:min(760px,94vw)!important;width:100%!important}@media(max-width:640px){.dl-invite{grid-template-columns:minmax(0,1fr)}.dl-invite img{max-width:260px;margin:0 auto}}.dl-toasts{position:fixed;left:50%;bottom:max(24px,env(safe-area-inset-bottom));transform:translate(-50%);z-index:100000;display:flex;flex-direction:column;align-items:center;gap:8px;pointer-events:none}.dl-toast{pointer-events:auto;display:inline-flex;align-items:center;gap:8px;max-width:min(520px,92vw);padding:10px 16px;border-radius:999px;background:var(--dl-fg);color:var(--dl-card);font-size:13px;line-height:18px;box-shadow:0 10px 30px #0000004d;opacity:0;transform:translateY(12px);transition:opacity .18s,transform .18s}.dl-toast.show{opacity:1;transform:none}.dl-toast .dl-icon-wrap{display:inline-flex}.dl-toast .dl-icon{width:15px;height:15px}.dl-toast.success .dl-icon{color:var(--dl-ok)}.dl-toast.error{background:var(--dl-bad);color:#fff}.dl-toast.error .dl-icon{color:#fff}.dl-toast.warning{background:var(--dl-warn);color:#111}.dl-toast.warning .dl-icon{color:#111}.dl-toast button{all:unset;cursor:pointer;display:inline-flex;margin-left:4px;opacity:.8}.dl-toast button:hover{opacity:1}';var nr=".dl-setblock{display:flex;flex-direction:column;gap:8px;margin:0}.dl-addr-opts{display:flex;flex-direction:column;gap:6px}.dl-addr-opt{all:unset;box-sizing:border-box;cursor:pointer;display:grid;grid-template-columns:16px minmax(0,1fr) auto;gap:12px;align-items:center;padding:10px 14px;border-radius:12px;box-shadow:inset 0 0 0 1px var(--dl-line);min-width:0}.dl-addr-opt:hover{background:var(--dl-soft)}.dl-addr-opt.on{box-shadow:inset 0 0 0 1.5px var(--dl-accent);background:color-mix(in srgb,var(--dl-accent) 7%,transparent)}.dl-addr-opt .dl-mono{font-size:13px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-addr-opt .dl-stack{min-width:0}.dl-addr-opt input{width:100%}.dl-addr-opt.other{cursor:default}.dl-addr-opt.other:hover{background:none}.dl-addr-opt.other input{width:100%}.dl-addr-check{width:16px;height:16px;border-radius:5px;box-shadow:inset 0 0 0 1.5px var(--dl-fg-faint);display:inline-flex;align-items:center;justify-content:center}.dl-addr-check .dl-icon-wrap{display:inline-flex}.dl-addr-check .dl-icon{width:12px;height:12px}.dl-addr-opt.on .dl-addr-check{background:var(--dl-accent);box-shadow:none;color:#fff}.dl-addr-opt.other .dl-addr-check{box-shadow:none;color:var(--dl-fg-muted)}.dl-addr-warn{display:inline-flex;align-items:center;gap:5px;font-size:12px;line-height:17px;color:var(--dl-warn)}.dl-addr-warn .dl-icon-wrap{display:inline-flex}.dl-addr-warn .dl-icon{width:13px;height:13px}.dl-pill.info{background:color-mix(in srgb,var(--dl-accent) 14%,transparent);color:var(--dl-accent)}.dl-links{border-radius:12px;background:var(--dl-soft);overflow:hidden}.dl-link-row{display:grid;grid-template-columns:18px minmax(0,1fr) auto;gap:10px;align-items:center;padding:11px 14px}.dl-link-row+.dl-link-row{border-top:1px solid var(--dl-line)}.dl-link-ic{display:inline-flex}.dl-link-ic .dl-icon{width:15px;height:15px}.dl-link-ic.ok .dl-icon{color:var(--dl-ok)}.dl-link-ic.warn .dl-icon{color:var(--dl-warn)}.dl-link-url{font-size:13px;color:var(--dl-fg-muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-link-url b{font-weight:500;color:var(--dl-accent)}@media(max-width:640px){.dl-link-url,.dl-addr-opt .dl-mono,.dl-filecard .dl-ellipsis,.dl-invite-link>span:first-child{white-space:normal;overflow-wrap:anywhere}}.dl-ready-sum{display:flex;align-items:center;gap:12px;padding:12px 14px;border-radius:12px}.dl-ready-sum>.dl-icon-wrap{display:inline-flex}.dl-ready-sum>.dl-icon-wrap .dl-icon{width:18px;height:18px}.dl-ready-sum .dl-stack{flex:1;min-width:0}.dl-ready-sum b{font-weight:500;font-size:13px}.dl-ready-sum.ok{background:var(--dl-ok-wash)}.dl-ready-sum.ok b,.dl-ready-sum.ok .dl-icon{color:var(--dl-ok)}.dl-ready-sum.warn{background:var(--dl-warn-wash)}.dl-ready-sum.warn b,.dl-ready-sum.warn .dl-icon{color:var(--dl-warn)}.dl-ready-sum.error{background:var(--dl-bad-wash)}.dl-ready-sum.error b,.dl-ready-sum.error .dl-icon{color:var(--dl-bad)}.dl-check-chip{display:inline-flex;align-items:center;gap:5px;height:26px;padding:0 10px;border-radius:999px;background:var(--dl-soft);font-size:12px;color:var(--dl-fg-muted)}.dl-check-chip .dl-icon-wrap{display:inline-flex}.dl-check-chip .dl-icon{width:13px;height:13px;color:var(--dl-ok)}.dl-check-chip.warn{background:var(--dl-warn-wash);color:var(--dl-warn)}.dl-check-chip.warn .dl-icon{color:var(--dl-warn)}.dl-check-chip.error{background:var(--dl-bad-wash);color:var(--dl-bad)}.dl-check-chip.error .dl-icon{color:var(--dl-bad)}.dl-ready-details{display:flex;flex-direction:column;gap:8px;padding:4px 2px}.dl-ready-details[hidden]{display:none}.dl-ready-item{display:flex;align-items:flex-start;gap:8px;font-size:13px;line-height:18px;min-width:0}.dl-ready-item .dl-icon-wrap{display:inline-flex;margin-top:1px}.dl-ready-item .dl-icon{width:15px;height:15px}.dl-ready-item.ok .dl-icon{color:var(--dl-ok)}.dl-ready-item.warn .dl-icon{color:var(--dl-warn)}.dl-ready-item.error .dl-icon{color:var(--dl-bad)}.dl-params-body{display:flex;flex-direction:column;gap:14px;padding:6px 14px 14px}.dl-params-body>.dl-setrow{margin:0;padding:0}.dl-pgrid.flush{padding:0;grid-template-columns:repeat(2,minmax(0,1fr))}@media(max-width:640px){.dl-pgrid.flush{grid-template-columns:minmax(0,1fr)}}.dl-qr-pane{display:flex;flex-direction:column;align-items:center;gap:8px;text-align:center}.dl-qr{width:min(280px,72vw);aspect-ratio:1;background:#fff;padding:8px;border-radius:12px;box-shadow:inset 0 0 0 1px var(--dl-line)}.dl-qr svg{display:block;width:100%;height:100%}.dl-filecard{display:flex;align-items:center;gap:12px;padding:12px;border-radius:14px;background:var(--dl-soft);min-width:0}.dl-filecard>.dl-stack{flex:1;min-width:0}.dl-filecard-ic{width:40px;height:46px;border-radius:8px;flex:none;display:inline-flex;align-items:center;justify-content:center;font:10px var(--dl-mono);color:var(--dl-fg-muted);background:var(--dl-card);box-shadow:inset 0 0 0 1px var(--dl-line)}.dl-params>.dl-conf{margin:0;border-top:1px solid var(--dl-line);border-radius:0 0 12px 12px;background:none}.dl-conf-sec{color:var(--dl-accent)}.dl-conf-k{color:var(--dl-fg-faint)}.dl-conf-mask{padding:0 6px;border-radius:4px;background:var(--dl-soft);color:var(--dl-fg-muted)}.dl-params>summary .dl-chipbtn{height:26px;font-size:12px}.dl-conf{white-space:pre-wrap;word-break:break-all;max-height:22em;overflow:auto;font-family:var(--dl-mono);font-size:12px;line-height:18px;margin:0;padding:12px;border-radius:12px;background:var(--dl-soft)}.dl-key{width:100%;box-sizing:border-box;font-family:var(--dl-mono);font-size:12px;word-break:break-all;min-height:7em}.dl-actions{display:flex;align-items:center;gap:6px;flex-wrap:wrap;margin:12px 0 0}.dl-link-box{display:flex;gap:6px;align-items:center;flex-wrap:wrap}.dl-link-box input{flex:1 1 18em;min-width:0;font-family:var(--dl-mono);font-size:12px}.dl-hint{font-size:12px;line-height:16px;color:var(--dl-fg-muted);margin:8px 0}.dl-divider{border:0;border-top:1px solid var(--dl-line);margin:16px 0}";var or=".dl-checks{list-style:none;margin:0;padding:0}.dl-checks li{display:flex;align-items:center;gap:12px;padding:12px 0;border-top:1px solid var(--dl-line)}.dl-checks li:first-child{border-top:0;padding-top:0}.dl-checks li:last-child{padding-bottom:0}.dl-check-icon{flex:0 0 auto;width:28px;height:28px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center}.dl-check-icon .dl-icon{width:14px;height:14px}.dl-check-icon.ok{background:var(--dl-ok-wash);color:var(--dl-ok)}.dl-check-icon.warn{background:var(--dl-warn-wash);color:var(--dl-warn)}.dl-check-icon.error{background:var(--dl-bad-wash);color:var(--dl-bad)}.dl-check-icon.skip{background:var(--dl-soft);color:var(--dl-fg-faint)}.dl-check-body{flex:1;min-width:0}.dl-check-title{font-size:14px;line-height:20px;font-weight:500}.dl-check-detail{font-size:12px;line-height:16px;color:var(--dl-fg-muted);overflow-wrap:anywhere}.dl-check-repaired{margin-top:2px;font-size:12px;line-height:16px;color:var(--dl-warn)}.dl-wd{margin:0 0 16px;display:flex;flex-direction:column;gap:14px}.dl-wd-head{display:flex;align-items:center;gap:12px;min-width:0}.dl-wd-head>.dl-stack{min-width:0}.dl-wd-title{font-size:16px;line-height:24px;font-weight:500}.dl-wd-tile{flex:none;width:36px;height:36px;border-radius:10px;display:inline-flex;align-items:center;justify-content:center;background:var(--dl-ok-wash);color:var(--dl-ok)}.dl-wd-tile.off{background:var(--dl-soft);color:var(--dl-fg-faint)}.dl-wd-tile .dl-icon{width:18px;height:18px}.dl-wd-foot{display:flex;align-items:center;flex-wrap:wrap;gap:8px 16px;padding-top:14px;border-top:1px solid var(--dl-line)}.dl-wd-chips{display:flex;flex-wrap:wrap;gap:6px;flex:1 1 auto;min-width:0}.dl-wd-chips .dl-check-chip.error .dl-icon{color:var(--dl-bad)}.dl-warn-text{color:var(--dl-warn)!important}.dl-health-cols{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(440px,100%),1fr));gap:16px;align-items:start}.dl-health-cols>.dl-panel{margin:0;min-width:0}.dl-recent{display:flex;flex-direction:column}.dl-recent .dl-panel-head a{font-size:13px}.dl-recent-empty{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;padding:32px 16px;color:var(--dl-fg-muted);font-size:13px;border-top:1px solid var(--dl-line)}.dl-loading{margin:0;font-size:13px}.dl-diag-tabs{margin:0 0 16px}.dl-row.dl-slog-row{align-items:baseline}.dl-slog-row .dl-ev-tile{align-self:flex-start;margin-top:-1px}.dl-slog-row.has-detail{cursor:pointer}.dl-row.dl-slog-row.has-detail:hover{background:color-mix(in srgb,var(--sys) 11%,transparent)}.dl-slog-more{display:inline-flex;vertical-align:-2px;margin-left:6px;color:var(--dl-fg-faint);transform:rotate(90deg);transition:transform .15s}.dl-slog-more .dl-icon{width:14px;height:14px}.dl-slog-more.open{transform:rotate(-90deg)}.dl-slog-detail{margin:8px 0 2px;padding:8px 10px;border-radius:8px;background:var(--dl-soft);font-family:var(--dl-mono);font-size:12px;line-height:17px;white-space:pre-wrap;overflow-wrap:anywhere;color:var(--dl-fg-muted);cursor:text}.dl-table{width:100%;border-collapse:collapse;font-size:14px;line-height:20px}.dl-table th{text-align:left;font-weight:500;color:var(--dl-fg-faint);padding:0 8px 8px;border-bottom:1px solid var(--dl-line)}.dl-table td{padding:10px 8px;border-bottom:1px solid var(--dl-line);vertical-align:middle}.dl-table th:first-child,.dl-table td:first-child{padding-left:0}.dl-table th:last-child,.dl-table td:last-child{padding-right:0}.dl-table tr:last-child td{border-bottom:0}.dl-table .dl-right{text-align:right;white-space:nowrap}.dl-log{max-height:18em;overflow:auto;font-family:var(--dl-mono);font-size:12px;line-height:18px;margin:8px 0 0;padding:12px;white-space:pre-wrap;border-radius:12px;background:var(--dl-soft)}";var ar=".dl-pagehead{display:flex;align-items:flex-end;justify-content:space-between;gap:16px;flex-wrap:wrap;margin:0 0 20px}.dl-h1{margin:0!important;padding:0!important;font-size:24px!important;line-height:32px!important;font-weight:500!important;border:0!important}.dl-title-row{display:flex;align-items:center;gap:10px;flex-wrap:wrap}.dl-stack{display:flex;flex-direction:column;gap:2px;min-width:0}.dl-stack.gap4{gap:4px}.dl-stack.gap8{gap:8px}.dl-sub{font-size:12px;line-height:16px;color:var(--dl-fg-muted)}.dl-ok{color:var(--dl-ok)}.dl-warn{color:var(--dl-warn)}.dl-bad{color:var(--dl-bad)}.dl-icon-only{width:auto!important;min-width:0!important;aspect-ratio:1 / 1;padding:0!important;justify-content:center;display:inline-flex!important;align-items:center;border-radius:999px!important}.dl-panel.flush{padding:0;overflow:hidden}.dl-panel-head.pad{padding:16px 16px 12px;margin:0}.dl-col{display:flex;flex-direction:column;gap:16px;min-width:0}.dl-col>.dl-panel,.dl-col>section.dl-panel{margin:0}.dl-crumbs{display:flex;gap:8px;align-items:center;font-size:14px;margin:0 0 16px;color:var(--dl-fg-faint)}.dl-crumbs a{color:var(--dl-fg-faint)}.dl-crumbs a:hover{color:var(--dl-fg)}.dl-crumbs span:last-child{color:var(--dl-fg)}.dl-metrics{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));background:var(--dl-card);border:1px solid var(--dl-line);border-radius:var(--dl-radius);margin:0 0 16px;box-shadow:var(--dl-shadow)}.dl-metric{display:flex;flex-direction:column;gap:4px;padding:16px 20px;min-width:0}.dl-metric+.dl-metric{border-left:1px solid var(--dl-line)}.dl-metric-label{font-size:12px;font-weight:500;color:var(--dl-fg-faint)}.dl-metric-value{font-size:28px;line-height:36px;font-weight:500;letter-spacing:-.01em;font-variant-numeric:tabular-nums;white-space:nowrap}.dl-metric-value .dl-faint{font-size:16px}.dl-metric-sub{font-size:12px;color:var(--dl-fg-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}@media(max-width:900px){.dl-metrics{grid-template-columns:repeat(2,minmax(0,1fr))}.dl-metric:nth-child(3){border-left:0}.dl-metric:nth-child(n+3){border-top:1px solid var(--dl-line)}}.dl-seg{display:inline-flex;gap:2px;padding:3px;border-radius:999px;background:var(--dl-soft);flex-wrap:wrap}.dl-seg button{all:unset;cursor:pointer;display:inline-flex;align-items:center;gap:6px;padding:4px 12px;border-radius:999px;font-size:13px;font-weight:500;color:var(--dl-fg-muted);white-space:nowrap}.dl-seg button:hover{color:var(--dl-fg)}.dl-seg button.on{background:var(--dl-soft-hover);color:var(--dl-fg)}.dl-seg.dl-srvsections{flex-wrap:nowrap;max-width:100%;overflow-x:auto;scrollbar-width:none}.dl-seg.dl-srvsections::-webkit-scrollbar{display:none}.dl-seg.dl-srvsections button{flex:none;white-space:nowrap}.dl-seg button:focus-visible{outline:2px solid var(--dl-ring)}.dl-seg button b{font-weight:500;font-size:11px;padding:0 6px;border-radius:999px;background:var(--dl-soft)}.dl-seg button b.warn{background:var(--dl-warn-wash);color:var(--dl-warn)}.dl-seg.sm button{padding:2px 9px;font-size:11px}.dl-seg.wide{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));border-radius:12px;padding:4px}.dl-seg.wide button{flex-direction:column;justify-content:center;padding:8px 6px;border-radius:9px;gap:3px}.dl-seg.wide button.on{background:var(--dl-primary);color:var(--dl-primary-fg)}";var rr=`.dl-geomap{position:relative;border-top:1px solid var(--dl-line);background:transparent}.dl-map-status{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;color:var(--dl-fg-muted);font-size:13px;z-index:1;pointer-events:none}.dl-map-wrap{position:relative}.dl-map-legend{position:absolute;left:12px;bottom:12px;display:flex;gap:12px;align-items:center;padding:6px 12px;border-radius:999px;font-size:12px;background:color-mix(in srgb,var(--dl-card) 88%,transparent);border:1px solid var(--dl-line);backdrop-filter:blur(6px);z-index:2}.dl-map-legend span{display:inline-flex;align-items:center;gap:6px;color:var(--dl-fg-muted)}.dl-map-legend i.line{width:14px;height:0;border-top:2px dashed #8a8a8a}.dl-map-legend i.line.live{border-top-color:#3b82f6}.dl-map-off{padding:32px 16px;text-align:center;color:var(--dl-fg-muted);border-top:1px solid var(--dl-line)}.dl-mk{all:unset;cursor:pointer;position:relative;display:flex;align-items:center;justify-content:center;transition:opacity .2s}.dl-mk-hub{position:relative;display:flex;align-items:center;justify-content:center}.dl-mk-host{box-sizing:border-box;width:40px;height:40px;border-radius:11px;display:flex;align-items:center;justify-content:center;background:color-mix(in srgb,var(--dl-elevated) 60%,transparent);border:1px solid var(--dl-line);backdrop-filter:blur(6px);box-shadow:0 6px 16px #00000059}.dl-mk-host-tile{width:26px;height:26px;border-radius:7px;display:flex;align-items:center;justify-content:center;background:var(--dl-fg);color:var(--background, var(--dl-elevated))}.dl-mk-host-ic{width:14px;height:14px}.dl-mk-av{position:relative;box-sizing:border-box;width:28px;height:28px;border-radius:50%;display:flex;align-items:center;justify-content:center;font-size:10px;font-weight:500;line-height:1;border:2px solid #8a8a8a;background:var(--dl-elevated);color:var(--dl-fg-muted);transition:box-shadow .2s}.dl-mk.online .dl-mk-av{border-color:#3b82f6;background:color-mix(in srgb,#3b82f6 22%,var(--dl-elevated));color:var(--dl-fg)}.dl-mk-badge{position:absolute;left:16px;bottom:-6px;height:16px;min-width:16px;padding:0 3px;border-radius:8px;border:2px solid var(--dl-elevated);background:#6b6b6b;color:#fff;display:flex;align-items:center;justify-content:center;gap:1px;font-size:9px;font-weight:600;white-space:nowrap;box-sizing:content-box}.dl-mk.online .dl-mk-badge{background:#3b82f6}.dl-mk-badge-ic{width:10px;height:10px;stroke-width:2.2}.dl-mk-badge:has(>svg:only-child){width:16px;min-width:0;padding:0}.dl-mk-tile{position:relative;width:26px;height:26px;border-radius:7px;display:flex;align-items:center;justify-content:center;background:color-mix(in srgb,var(--dl-fg) 18%,var(--dl-elevated));color:var(--dl-fg)}.dl-mk.place.online .dl-mk-tile{background:#3b82f6;color:#fff;box-shadow:0 2px 8px #3b82f659}.dl-mk-tile-ic{width:14px;height:14px}.dl-mk-tile-n{position:absolute;right:-5px;top:-5px;min-width:14px;height:14px;padding:0 3px;box-sizing:border-box;border-radius:7px;background:var(--dl-fg);color:var(--dl-elevated);font-size:9px;font-weight:600;line-height:14px;text-align:center}.dl-mk-when{display:block;text-align:center;color:var(--dl-fg-faint);font-weight:400}.dl-mk.place.online .dl-mk-when{color:#3b82f6}.dl-mk-tile.sm{width:18px;height:18px;border-radius:5px;font-size:9px;font-weight:600}.dl-dmap{border:1px solid var(--dl-line);border-radius:12px;overflow:hidden}.dl-dmap .dl-geomap{border-top:0}.dl-dplaces{display:flex;flex-direction:column;margin-top:4px}.dl-dplace-row{display:flex;align-items:center;gap:10px;padding:9px 2px;border-top:1px solid var(--dl-line);font-size:13px}.dl-dplace-row:first-child{border-top:0}.dl-dplace-n{flex:0 0 auto;width:20px;height:20px;border-radius:5px;display:flex;align-items:center;justify-content:center;font-size:10px;font-weight:600;background:color-mix(in srgb,var(--dl-fg) 18%,var(--dl-elevated));color:var(--dl-fg)}.dl-dplace-n.live{background:#3b82f6;color:#fff}.dl-dplace-n .dl-icon{width:12px;height:12px}.dl-dplace-now{color:#3b82f6}.dl-mk>*{transition:opacity .15s;opacity:var(--dl-mk-fade, 1)}.dl-mk.merged,.dl-mk.piled{pointer-events:none}.dl-mk.dl-mk-new>*{transition:none}.dl-mk.merged>*,.dl-mk.piled>*{opacity:0}.dl-mk-hub{cursor:default}.dl-mk-host{position:relative}.dl-mk-host{transition:border-radius .22s ease,border-right-color .22s ease}.dl-mk-host.docked{border-top-right-radius:0;border-bottom-right-radius:0;border-right-color:transparent}.dl-mk-dock{position:absolute;left:100%;top:-1px;height:40px;box-sizing:border-box;display:flex;align-items:center;gap:6px;padding:0 10px 0 2px;border:1px solid var(--dl-line);border-left:0;border-radius:0 11px 11px 0;background:color-mix(in srgb,var(--dl-elevated) 60%,transparent);backdrop-filter:blur(6px);box-shadow:0 6px 16px #00000059;pointer-events:none;opacity:0;clip-path:inset(-24px 100% -24px 0);transition:clip-path .28s cubic-bezier(.2,.8,.2,1),opacity .2s ease}.dl-mk-host.docked .dl-mk-dock{pointer-events:auto;opacity:1;clip-path:inset(-24px -24px -24px 0)}.dl-mk-new .dl-mk-host,.dl-mk-new .dl-mk-dock{transition:none}.dl-mk-pile{position:relative;display:flex;justify-content:center}.dl-mk-pile-box{box-sizing:border-box;height:40px;display:flex;align-items:center;gap:6px;padding:0 10px 0 6px;border-radius:20px;cursor:zoom-in;background:color-mix(in srgb,var(--dl-elevated) 60%,transparent);border:1px solid var(--dl-line);backdrop-filter:blur(6px);box-shadow:0 6px 16px #00000059;animation:dl-plate-in .26s cubic-bezier(.2,.8,.2,1) both;transition:opacity .18s ease,transform .18s ease}.dl-mk-pile.out{pointer-events:none}.dl-mk-pile.out>*{opacity:0;transform:scale(.85);transition:opacity .18s ease,transform .18s ease}@keyframes dl-plate-in{0%{opacity:0;transform:scale(.85)}}.dl-mk-face{all:unset;position:relative;display:flex;cursor:pointer;transition:transform .18s ease,opacity .18s ease}.dl-mk-face>.dl-mk-badge{position:relative;left:auto;bottom:-8px;margin-left:-12px;align-self:center}.dl-mk-face.on .dl-mk-av{border-color:#3b82f6;background:color-mix(in srgb,#3b82f6 22%,var(--dl-elevated));color:var(--dl-fg)}.dl-mk-face.on .dl-mk-badge{background:#3b82f6}.dl-mk-face:hover .dl-mk-av{box-shadow:0 0 0 4px #3b82f640}.dl-mk-face.in{animation:dl-dock-in .24s cubic-bezier(.2,.8,.2,1) both}.dl-mk-face.out{transform:scale(.4);opacity:0;pointer-events:none}@keyframes dl-dock-in{0%{transform:scale(.4);opacity:0}}.dl-mk-more{font-size:11px;font-weight:600;color:var(--dl-fg-muted)}.dl-mk-av,.dl-mk-tile{transition:box-shadow .2s,transform .24s cubic-bezier(.2,.8,.2,1)}.dl-mk.merged .dl-mk-av,.dl-mk.merged .dl-mk-tile,.dl-mk.piled .dl-mk-av{transform:scale(.5)}.dl-mk-host,.dl-mk-dock,.dl-mk-pile-box{transition-property:border-radius,border-right-color,clip-path,opacity,height,width,padding,gap}.dl-mk-dock,.dl-mk-pile-box{transition-duration:.22s;transition-timing-function:cubic-bezier(.2,.8,.2,1)}.dl-mk-pile-box{position:relative}.dl-mk-more{transition:transform .22s cubic-bezier(.2,.8,.2,1),opacity .18s ease}.dl-mk-more.in{animation:dl-dock-in .24s ease both}.dl-mk-more.out{transform:scale(.4);opacity:0}.dl-mk-face .dl-mk-av{transition:box-shadow .2s,transform .24s cubic-bezier(.2,.8,.2,1),width .2s ease,height .2s ease,font-size .2s ease}.dl-mk-face{transition:transform .22s cubic-bezier(.2,.8,.2,1),opacity .18s ease,margin .2s ease}.dl-mk-face>.dl-mk-badge{max-width:48px;overflow:hidden;transition:opacity .2s ease,transform .2s ease,max-width .22s ease,margin .22s ease,padding .22s ease,border-width .22s ease,height .22s ease,min-width .22s ease,width .22s ease,bottom .22s ease}.dl-lod-far .dl-mk-host{width:32px;height:32px;border-radius:9px}.dl-lod-far .dl-mk-host.docked{border-radius:9px 0 0 9px}.dl-lod-far .dl-mk-host-tile{width:20px;height:20px;border-radius:6px}.dl-lod-far .dl-mk-host-ic{width:11px;height:11px}.dl-lod-far .dl-mk-dock{height:32px;gap:0;padding:0 4px 0 0;border-radius:0 9px 9px 0}.dl-lod-far .dl-mk-pile-box{height:32px;gap:0;padding:0 4px;border-radius:16px}.dl-lod-far .dl-mk-face+.dl-mk-face{margin-left:-6px}.dl-lod-far .dl-mk-face .dl-mk-av{width:22px;height:22px;font-size:8px;box-shadow:0 0 0 2px var(--dl-elevated)}.dl-lod-far .dl-mk-face>.dl-mk-badge{max-width:0;min-width:0;padding:0;margin-left:0;border-width:0;opacity:0;transform:scale(.5);pointer-events:none}.dl-lod-far .dl-mk-more{margin-left:4px;font-size:10px}.dl-mk-label{transition:opacity .2s ease}.dl-lod-far .dl-mk-label{opacity:0}.dl-lod-mid .dl-mk-host{width:36px;height:36px}.dl-lod-mid .dl-mk-dock,.dl-lod-mid .dl-mk-pile-box{height:36px}.dl-lod-mid .dl-mk-face .dl-mk-av{width:24px;height:24px;font-size:9px}.dl-lod-mid .dl-mk-face>.dl-mk-badge{height:12px;min-width:12px;margin-left:-10px;bottom:-7px}.dl-lod-mid .dl-mk-face>.dl-mk-badge:has(>svg:only-child){width:12px}.dl-lod-mid .dl-mk-face>.dl-mk-badge .dl-mk-badge-ic{width:8px;height:8px}@media(prefers-reduced-motion:reduce){.dl-mk-dock,.dl-mk-pile-box,.dl-mk-face,.dl-mk-av,.dl-mk-tile,.dl-mk-host,.dl-mk-face>.dl-mk-badge{transition:none;animation:none}}.dl-mk-hub:has(.dl-mk-host.docked) .dl-mk-host{cursor:zoom-in}.dl-mk-ptr{position:absolute;left:50%;top:50%;width:0;height:0;z-index:-1;pointer-events:none}.dl-mk-ptr .line{position:absolute;left:0;top:-.5px;height:1px;background:var(--dl-fg-faint);transform-origin:0 50%}.dl-mk-ptr .spot{position:absolute;left:-3.5px;top:-3.5px;width:7px;height:7px;border-radius:50%;box-sizing:border-box;border:1.5px solid #fff;background:#8a8a8a}.dl-mk.online .dl-mk-ptr .spot,.dl-mk.place.online .dl-mk-ptr .spot{background:#3b82f6}.dl-mk.dim>*{opacity:.18}.dl-mk.hl .dl-mk-av{box-shadow:0 0 0 4px #3b82f640}.dl-mk-label{position:absolute;left:50%;bottom:100%;margin-bottom:4px;transform:translate(-50%);white-space:nowrap;pointer-events:none;font-size:10px;line-height:14px;font-weight:500;color:var(--dl-fg)}.dl-mk-label.below{bottom:auto;top:100%;margin:4px 0 0}.dl-mk-label.chip{padding:2px 6px;border-radius:4px;font-size:11px;line-height:16px;font-weight:600;background:color-mix(in srgb,var(--background, var(--dl-card)) 80%,transparent);backdrop-filter:blur(8px)}.dl-geomap .maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib.maplibregl-compact{margin:0 10px 10px 0;min-height:28px;padding:0;border-radius:8px;background:var(--dl-elevated);border:1px solid var(--dl-line);color:var(--dl-fg-muted);box-shadow:none;font-size:11px;line-height:26px}.dl-geomap .maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib.maplibregl-compact:not(.maplibregl-compact-show){width:28px;height:28px;box-sizing:border-box}.dl-geomap .maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib.maplibregl-compact.maplibregl-compact-show{padding:0 32px 0 10px}.dl-geomap .maplibregl-ctrl-attrib a{color:var(--dl-fg-muted)}.dl-geomap .maplibregl-ctrl-attrib-button{top:0;right:0;width:26px;height:26px;margin:0;border-radius:8px;background:none}.dl-geomap .maplibregl-ctrl-attrib-button:after{content:"";position:absolute;inset:5px;background:var(--dl-fg);-webkit-mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill-rule='evenodd' d='M12 2a10 10 0 1 1 0 20 10 10 0 0 1 0-20Zm-1.2 8.2h2.4V17h-2.4v-6.8ZM12 6a1.4 1.4 0 1 0 0 2.8A1.4 1.4 0 0 0 12 6Z'/%3E%3C/svg%3E") center / contain no-repeat;mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill-rule='evenodd' d='M12 2a10 10 0 1 1 0 20 10 10 0 0 1 0-20Zm-1.2 8.2h2.4V17h-2.4v-6.8ZM12 6a1.4 1.4 0 1 0 0 2.8A1.4 1.4 0 0 0 12 6Z'/%3E%3C/svg%3E") center / contain no-repeat}.dl-geomap .maplibregl-ctrl-attrib-button:focus{outline:none;box-shadow:none}.dl-geomap .maplibregl-ctrl-attrib-button:focus-visible{outline:2px solid var(--dl-ring)}.dl-map-card{position:absolute;right:12px;top:12px;z-index:3;min-width:200px;max-width:260px;padding:10px 12px;border-radius:10px;font-size:12px;line-height:20px;background:var(--dl-elevated);color:var(--dl-fg);border:1px solid var(--dl-line);box-shadow:var(--shadow-xl, 0 8px 16px -4px rgba(0,0,0,.4));opacity:0;transition:opacity .2s;pointer-events:none}.dl-map-card.on{opacity:1}.dl-map-card-head b{font-weight:500}.dl-map-card-row{display:flex;justify-content:space-between;gap:12px;white-space:nowrap}.dl-popcard{position:fixed;z-index:2100;width:max-content;max-width:300px;padding:12px;border-radius:12px;box-sizing:border-box;background:var(--dl-elevated);color:var(--dl-fg);border:1px solid var(--dl-line);box-shadow:var(--shadow-xl, 0 8px 16px -4px rgba(0,0,0,.4))}.dl-popcard.away{visibility:hidden}.dl-popcard.leaving{pointer-events:none}.dl-popcard-tip{position:absolute;left:var(--tip-x, 50%);width:10px;height:10px;margin-left:-6px;box-sizing:border-box;background:var(--dl-elevated);border:solid var(--dl-line);transform:rotate(45deg)}.dl-popcard.above .dl-popcard-tip{bottom:-6px;border-width:0 1px 1px 0}.dl-popcard.below .dl-popcard-tip{top:-6px;border-width:1px 0 0 1px}.dl-popcard.above{transform-origin:var(--tip-x, 50%) 100%}.dl-popcard.below{transform-origin:var(--tip-x, 50%) 0}@media(prefers-reduced-motion:no-preference){.dl-popcard{animation:dl-pop-in .16s ease-out}.dl-popcard.leaving{animation:dl-pop-out .14s ease-in forwards}}@keyframes dl-pop-in{0%{opacity:0;transform:scale(.94)}to{opacity:1;transform:none}}@keyframes dl-pop-out{0%{opacity:1;transform:none}to{opacity:0;transform:scale(.94)}}.dl-pop{display:flex;flex-direction:column;gap:4px;font-size:12px;line-height:18px;min-width:210px}.dl-pop-head{display:flex;align-items:center;gap:8px;font-size:13px;margin-bottom:2px}.dl-pop-net{width:30px;height:30px;border-radius:9px;background:var(--dl-soft);display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;color:var(--dl-fg-muted)}.dl-pop-list{display:flex;flex-direction:column;margin:6px 0 0;max-height:116px;overflow-y:auto}.dl-pop-row{all:unset;cursor:pointer;display:flex;align-items:center;gap:8px;padding:6px 8px;border-radius:8px}.dl-pop-row:hover{background:var(--dl-soft)}.dl-pop-row:focus{outline:none}.dl-pop-row:focus-visible{outline:2px solid var(--dl-ring)}.dl-pop-name{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.dl-pop-name b{font-weight:500}.dl-pop-dot{width:6px;height:6px;border-radius:50%;background:var(--dl-fg-faint);flex:0 0 auto}.dl-pop-dot.on{background:var(--dl-ok);box-shadow:0 0 0 3px var(--dl-ok-wash)}.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}.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)}.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-spark i:hover{opacity:1;filter:brightness(1.25)}.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;gap:2px;flex:0 0 auto}.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}`;var ir=`.dl-row{display:flex;align-items:center;gap:12px;padding:12px 16px;border-top:1px solid var(--dl-line);font-size:14px;line-height:20px;min-width:0}.dl-row.link{color:inherit;text-decoration:none}.dl-row.link:hover{background:var(--dl-soft)}.dl-row-main{flex:1;min-width:0;overflow-wrap:anywhere}.dl-row-main b{font-weight:500}.dl-attn{display:flex;flex-direction:column;gap:10px;padding:16px;border-top:1px solid var(--dl-line)}.dl-attn-item{display:flex;gap:10px;align-items:baseline;font-size:13px;color:var(--dl-fg-muted)}.dl-avatar.sm{width:26px;height:26px;font-size:10px;margin:0}.dl-avatar.lg{width:48px;height:48px;font-size:15px;margin:0}.dl-avatar.lg.online:after{width:12px;height:12px}.dl-list{border:1px solid var(--dl-line);border-radius:12px;overflow:hidden}.dl-list>.dl-row:first-child{border-top:0}.dl-ellipsis{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.dl-row-main.dl-stack{min-width:0}.dl-person-id{display:flex;align-items:center;gap:14px;min-width:0}.dl-grid-person{display:grid;grid-template-columns:minmax(0,1.7fr) minmax(0,1fr);gap:16px;align-items:start}@media(max-width:1000px){.dl-grid-person{grid-template-columns:minmax(0,1fr)}}.dl-devsec{display:flex;flex-direction:column;gap:12px}.dl-devsec .dl-panel-head{margin:0}.dl-dgrid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}.dl-dcard>.dl-dcard-head+*{margin-top:auto}@media(max-width:700px){.dl-dgrid{grid-template-columns:minmax(0,1fr)}}.dl-dgrid>.dl-dslot.add:only-child{grid-column:1 / -1}.dl-dcard{background:var(--dl-card);border:1px solid var(--dl-line);border-radius:14px;padding:14px;display:flex;flex-direction:column;gap:12px;min-width:0;box-shadow:var(--dl-shadow)}.dl-dcard.online{border-color:color-mix(in srgb,var(--dl-ok) 35%,transparent)}.dl-dcard.off{opacity:.7}.dl-dcard-head{display:flex;align-items:center;gap:12px}.dl-dcard-ic{width:40px;height:40px;border-radius:12px;background:var(--dl-soft);display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;color:var(--dl-fg-muted)}.dl-dcard-ic .dl-icon{width:20px;height:20px}.dl-dcard.online .dl-dcard-ic{background:var(--dl-ok-wash);color:var(--dl-ok)}.dl-dcard-title{all:unset;cursor:pointer;flex:1;min-width:0;display:flex;flex-direction:column}.dl-dcard-title b{font-weight:500;font-size:15px}.dl-dstat{display:inline-flex;align-items:center;gap:6px;font-size:12px;color:var(--dl-fg-muted);white-space:nowrap;min-width:0}.dl-dstat i.dot{flex:none}.dl-dstat.ok{color:var(--dl-ok)}.dl-dstat.warn{color:var(--dl-warn)}.dl-dstat i.dot,.dl-savebar i.dot{width:6px;height:6px;border-radius:50%;background:var(--dl-fg-faint)}.dl-dstat i.dot.ok{background:var(--dl-ok);box-shadow:0 0 0 3px var(--dl-ok-wash)}.dl-dstat i.dot.warn{background:var(--dl-warn)}.dl-dcard-use{display:flex;align-items:flex-end;justify-content:space-between;gap:12px}.dl-dcard-foot{padding-top:10px;border-top:1px solid var(--dl-line);font-size:11px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.dl-dslot.add{all:unset;box-sizing:border-box;cursor:pointer;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;padding:14px;min-height:0;border:1px dashed color-mix(in srgb,currentColor 18%,transparent);border-radius:14px;text-align:center;color:var(--dl-fg-muted);transition:background .15s,border-color .15s,color .15s}.dl-dslot.add .dl-stack{align-items:center}.dl-dslot.add:hover{border-color:color-mix(in srgb,currentColor 35%,transparent);color:var(--dl-fg)}.dl-dslot.add:focus-visible{outline:2px solid var(--dl-ring);outline-offset:2px}.dl-dslot.add b{font-weight:500}.dl-dslot.add:hover{background:var(--dl-soft)}.dl-dslot-ic{width:36px;height:36px;border-radius:999px;background:var(--dl-soft);display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;color:var(--dl-fg-muted)}.dl-dslot.add:hover .dl-dslot-ic{background:var(--dl-primary);color:var(--dl-primary-fg)}.dl-tiles2{display:grid;gap:10px;margin-top:16px}.dl-tile2{border:1px solid var(--dl-line);border-radius:14px;padding:14px;display:flex;flex-direction:column;gap:10px;min-width:0}.dl-tile2-label{display:flex;align-items:center;justify-content:space-between;gap:8px;font-size:12px;font-weight:500;color:var(--dl-fg-faint)}.dl-tile2-row{display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap}.dl-tile2-value{font-size:20px;line-height:28px;font-weight:500;letter-spacing:-.01em;font-variant-numeric:tabular-nums}.dl-tile2-value .dl-faint{font-size:14px;font-weight:400}.dl-tile2-foot{display:flex;align-items:center;justify-content:space-between;gap:12px;padding-top:10px;border-top:1px solid var(--dl-line);font-size:12px}.dl-stepper{display:inline-flex;align-items:stretch;height:32px;border:1px solid var(--input, var(--dl-line));border-radius:8px;overflow:hidden}.dl-stepper button{all:unset;cursor:pointer;width:32px;display:inline-flex;align-items:center;justify-content:center;font-size:16px;color:var(--dl-fg)}.dl-stepper button:hover{background:var(--dl-soft)}.dl-stepper button[disabled]{opacity:.35;cursor:not-allowed}.dl-stepper+.dl-stepper{margin-left:4px}.dl-step-select{border:0!important;border-left:1px solid var(--input, var(--dl-line))!important;border-right:1px solid var(--input, var(--dl-line))!important;border-radius:0!important;background:transparent!important;color:inherit;font:500 13px inherit;padding:0 10px!important;height:100%!important;min-width:0!important}.dl-slots{display:grid;grid-auto-flow:column;grid-auto-columns:minmax(0,1fr);gap:3px}.dl-slots i{height:4px;border-radius:999px;background:var(--dl-track);display:block}.dl-slots i.used{background:var(--dl-fg)}.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)}.dl-switch{all:unset;cursor:pointer;position:relative;width:32px;height:20px;border-radius:999px;background:var(--switch-off, var(--dl-track));flex:0 0 auto;transition:background .15s}.dl-switch i{position:absolute;left:2px;top:2px;width:16px;height:16px;border-radius:50%;background:#fff;transition:left .15s;box-shadow:0 1px 2px #0000004d}.dl-switch.on{background:var(--dl-accent)}.dl-switch.on i{left:14px}.dl-switch:focus-visible{outline:2px solid var(--dl-ring);outline-offset:2px}.dl-linkbox{display:flex;align-items:center;gap:8px;height:36px;padding:0 4px 0 12px;border:1px solid var(--input, var(--dl-line));border-radius:8px;background:var(--input-bg, transparent)}.dl-linkbox .dl-mono{flex:1;min-width:0;font-size:12px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:var(--dl-fg-muted)}.dl-linkbox .cbi-button{height:28px!important}.dl-pcard{display:grid;grid-template-columns:minmax(0,1fr) 260px;gap:20px;align-items:stretch;min-width:0}.dl-pcard-main{min-width:0}.dl-pcard-top{display:flex;align-items:center;gap:12px;min-width:0}.dl-pcard-top .dl-avatar{margin-right:0}.dl-pcard-who{flex:1;min-width:0}.dl-pcard-who .dl-slotbar{margin:3px 0 0}.dl-pside{display:flex;flex-direction:column;justify-content:space-between;gap:8px;padding-left:20px;border-left:1px solid var(--dl-line);min-width:0}.dl-pside-top{display:flex;align-items:center;justify-content:space-between;gap:8px}.dl-pside-state{display:inline-flex;align-items:center;gap:6px;font-size:13px;color:var(--dl-fg-muted)}.dl-pside-state.live{color:var(--dl-ok)}.dl-pside-foot{font-size:12px}.dl-pside .dl-use-num b{font-size:20px}.dl-none{display:none!important}.dl-pcard-actions{display:flex;gap:6px;flex:0 0 auto}.dl-pcard-actions .cbi-button{height:32px!important}.dl-icon-only .dl-btn-label{display:none}.dl-pill-ic{display:inline-flex;align-items:center;gap:4px;height:22px;padding:0 8px;border-radius:999px;font-size:12px;white-space:nowrap;background:var(--dl-soft);color:var(--dl-fg-muted)}.dl-pill-ic .dl-icon{width:12px;height:12px}.dl-pill-ic.warn{background:var(--dl-warn-wash);color:var(--dl-warn)}.dl-pill-ic.bad{background:var(--dl-bad-wash);color:var(--dl-bad)}.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-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}.dl-card-name{color:var(--dl-fg)!important;text-decoration:none}.dl-card-name:hover{text-decoration:underline}.dl-chip-tag{font-size:11px;line-height:18px;padding:0 6px;border-radius:999px;background:var(--dl-warn-wash);color:var(--dl-warn)}.dl-chip.live{background:var(--dl-ok-wash);color:color-mix(in srgb,var(--dl-ok) 35%,var(--dl-fg))}.dl-chip.live:hover{background:color-mix(in srgb,var(--dl-ok) 22%,transparent)}.dl-chip.live .dl-icon{color:var(--dl-ok)}.dl-fixes{display:flex;gap:6px;flex-wrap:wrap;margin:10px 0 0 44px}.dl-fix{all:unset;cursor:pointer;height:26px;padding:0 10px;border-radius:999px;background:var(--dl-info-wash);color:var(--dl-info);font-size:12px;font-weight:500;display:inline-flex;align-items:center}.dl-fix:hover{filter:brightness(1.15)}@media(max-width:760px){.dl-pcard{grid-template-columns:1fr}.dl-pside{padding:12px 0 0;border-left:0;border-top:1px solid var(--dl-line)}.dl-fixes{margin-left:0}}.dl-select{height:34px!important;border-radius:999px!important;min-width:136px!important;width:auto!important;padding:0 34px 0 14px!important;appearance:none!important;-webkit-appearance:none!important;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b8f98' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E")!important;background-repeat:no-repeat!important;background-position:right 12px center!important;background-size:14px!important}.dl-savebar{position:fixed;left:50%;bottom:24px;transform:translate(-50%,160%);opacity:0;transition:transform .25s cubic-bezier(.2,.8,.2,1),opacity .2s;display:flex;align-items:center;gap:10px;padding:8px 8px 8px 18px;border-radius:999px;background:var(--dl-elevated);border:1px solid var(--dl-line);box-shadow:var(--shadow-2xl, 0 16px 32px -8px rgba(0,0,0,.5));z-index:60;pointer-events:none}.dl-savebar.show{transform:translate(-50%);opacity:1;pointer-events:auto}.dl-savebar-text{display:inline-flex;align-items:center;gap:8px;font-size:13px;font-weight:500}`;var sr=".dl-toast strong{display:block;font-weight:500}.dl-toast div{opacity:.8;font-size:13px}.dl-drawer-overlay{position:fixed;inset:0;z-index:900;display:flex;justify-content:flex-end;background:transparent;transition:background .2s}.dl-drawer-overlay.open{background:var(--scrim, rgba(0,0,0,.45))}.dl-drawer{width:min(520px,100%);height:100%;display:flex;flex-direction:column;background:var(--dialog-bg, var(--dl-elevated));color:var(--dl-fg);border-left:1px solid var(--dl-line);box-shadow:var(--shadow-2xl, -16px 0 32px -8px rgba(0,0,0,.5));transform:translate(100%);transition:transform .22s cubic-bezier(.2,.8,.2,1)}.dl-drawer-overlay.open .dl-drawer{transform:none}.dl-drawer-head{display:flex;align-items:center;gap:12px;padding:16px 20px;border-bottom:1px solid var(--dl-line)}.dl-drawer-title{flex:1;min-width:0;display:flex;align-items:center;gap:12px}.dl-drawer-title h3{margin:0!important;padding:0!important;border:0!important;font-size:18px!important;line-height:26px;font-weight:500!important}.dl-drawer-x{all:unset;cursor:pointer;width:32px;height:32px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;color:var(--dl-fg-muted)}.dl-drawer-x:hover{background:var(--dl-soft);color:var(--dl-fg)}.dl-drawer-body{flex:1;overflow:auto;padding:20px}.dl-drawer-foot{padding:12px 20px;border-top:1px solid var(--dl-line)}.dl-drawer-actions{display:flex;align-items:center;gap:8px}.dl-dcard-ic.on{background:var(--dl-ok-wash);color:var(--dl-ok)}.dl-icon-only.sm{width:28px;height:28px!important}.dl-stack.gap12{gap:12px}.dl-stack.gap16{gap:16px}.dl-dstats{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));border:1px solid var(--dl-line);border-radius:14px;overflow:hidden}.dl-dstats-cell{display:flex;flex-direction:column;gap:4px;padding:12px 14px;min-width:0}.dl-dstats-cell.wide{grid-column:span 2;border-bottom:1px solid var(--dl-line)}.dl-dstats-cell+.dl-dstats-cell:not(.wide):last-child{border-left:1px solid var(--dl-line)}.dl-dstats-cell b{font-size:16px;font-weight:500;font-variant-numeric:tabular-nums}.dl-dstats-cell .dl-dstat{font-size:14px}.dl-dsec{border:1px solid var(--dl-line);border-radius:14px;padding:16px;display:flex;flex-direction:column;gap:12px}.dl-dsec-head{display:flex;align-items:center;justify-content:space-between;gap:12px}.dl-dsec-head h4{margin:0!important;padding:0!important;font-size:14px!important;font-weight:500!important;border:0!important}.dl-dstat i.dot{width:6px;height:6px;border-radius:50%;background:var(--dl-fg-faint);display:inline-block}.dl-connect-body{min-height:60px}.dl-connect-body .dl-qr{width:min(240px,70vw)}.dl-kv2{display:flex;flex-direction:column}.dl-kvrow{display:flex;align-items:center;justify-content:space-between;gap:16px;padding:9px 0;border-top:1px solid var(--dl-line);font-size:13px;min-width:0}.dl-kvrow:first-child{border-top:0;padding-top:0}.dl-kvrow-k{color:var(--dl-fg-muted);flex:0 0 auto}.dl-kvrow-v{min-width:0;text-align:right;overflow-wrap:anywhere}.dl-kvrow-v.copy{all:unset;cursor:pointer;display:inline-flex;align-items:center;gap:6px;min-width:0;color:var(--dl-fg)}.dl-kvrow-v.copy span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-kvrow-v.copy .dl-icon{width:13px;height:13px;color:var(--dl-fg-faint)}.dl-kvrow-v.copy:hover .dl-icon{color:var(--dl-fg)}@media(max-width:560px){.dl-drawer{width:100%}.dl-dstats{grid-template-columns:minmax(0,1fr)}.dl-dstats-cell.wide{grid-column:auto}.dl-dstats-cell+.dl-dstats-cell:not(.wide):last-child{border-left:0;border-top:1px solid var(--dl-line)}}.dl-dev-log{display:flex;flex-direction:column}.dl-dev-log-row{display:flex;align-items:center;gap:10px;padding:8px 0;border-top:1px solid var(--dl-line);font-size:13px;line-height:20px;min-width:0}.dl-dev-log-row:first-child{border-top:0;padding-top:0}.dl-dev-log-row .dl-row-main{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}";var lr=".dl-settings-main{min-width:0;display:flex;flex-direction:column;gap:20px}.dl-setsec{background:var(--dl-card);border:1px solid var(--dl-line);border-radius:var(--dl-radius);overflow:hidden;scroll-margin-top:88px;box-shadow:var(--dl-shadow)}.dl-setsec-body{padding:20px;display:flex;flex-direction:column;gap:14px}.dl-setsec-body h3{margin:0!important;padding:0!important;font-size:18px!important;line-height:26px;font-weight:500!important;border:0!important}.dl-setsec-body p{margin:0}.dl-setsec-head{display:flex;align-items:center;gap:10px}.dl-group{border:1px solid var(--dl-line);border-radius:14px;padding:2px 16px}.dl-group-head{display:flex;align-items:center;gap:12px;padding:14px 0 10px}.dl-group-head b{font-size:15px;font-weight:500}.dl-group-ic{width:32px;height:32px;border-radius:10px;background:var(--dl-soft);color:var(--dl-fg-muted);display:inline-flex;align-items:center;justify-content:center;flex:none}.dl-group-ic .dl-icon-wrap{display:inline-flex}.dl-group-ic .dl-icon{width:16px;height:16px}.dl-group-body>*{padding:12px 0;margin:0!important}.dl-group-body>*+*:not(.alert-message):not(.dl-params){border-top:1px solid var(--dl-line)}.dl-group-body>.alert-message,.dl-group-body>.dl-params{margin:12px 0!important}.dl-group-body>.alert-message{padding:10px 14px}.dl-group-body>.dl-params{padding:0}.dl-group-body>.alert-message+*,.dl-group-body>.dl-params+*{border-top:0}.dl-group-body>.dl-row{border-left:0;border-right:0;border-bottom:0;padding-left:0;padding-right:0;background:none}.dl-group-body>.dl-row:first-child{border-top:0}.dl-setsec-foot{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:10px 16px;padding:12px 20px;border-top:1px solid var(--dl-line);background:var(--dl-soft)}.dl-setsec.danger{border-color:color-mix(in srgb,var(--dl-bad) 40%,transparent)}.dl-setsec.danger .dl-setsec-foot{background:color-mix(in srgb,var(--dl-bad) 6%,transparent)}.dl-setrow{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,420px);align-items:center;gap:8px 24px}.dl-setrow.head{display:flex;justify-content:space-between;gap:16px}.dl-setrow-label{font-size:14px;font-weight:500}.dl-setrow-ctl{display:flex;justify-content:flex-end;min-width:0}.dl-setrow-ctl .dl-chips-row{justify-content:flex-end}.dl-setrow-ctl>input{width:100%}.dl-hostport{display:flex;align-items:center;gap:8px;flex:1;min-width:0;justify-content:flex-end}.dl-hostport input{flex:1;min-width:0}.dl-root input.dl-w-port,.dl-hostport input.dl-w-port{flex:0 0 90px;width:90px}.dl-root input.dl-w-range{flex:0 0 130px;width:130px}.dl-setrow .dl-sub.bad{color:var(--dl-bad)}.dl-suffixed{display:inline-flex;align-items:center;gap:6px}.dl-suffixed>span{color:var(--dl-fg-muted)}.dl-more summary{cursor:pointer;color:var(--dl-fg-muted);font-size:13px;margin-bottom:10px}.dl-more .dl-setrow+.dl-setrow{margin-top:10px}@media(max-width:760px){.dl-setrow:not(.head){grid-template-columns:minmax(0,1fr)}.dl-setrow-ctl,.dl-setrow-ctl .dl-chips-row{justify-content:flex-start}}.dl-need-ic{width:30px;height:30px;border-radius:9px;background:var(--dl-soft);color:var(--dl-fg-muted);display:inline-flex;align-items:center;justify-content:center;flex:none}.dl-need-ic .dl-icon-wrap{display:inline-flex}.dl-need-ic .dl-icon{width:15px;height:15px}.dl-need-row.bad .dl-need-ic,.dl-need-ic.bad{background:var(--dl-bad-wash);color:var(--dl-bad)}.dl-need-row.warn .dl-need-ic,.dl-need-ic.warn{background:var(--dl-warn-wash);color:var(--dl-warn)}.dl-need-ic.ok{background:var(--dl-ok-wash);color:var(--dl-ok)}.dl-lh-main{display:flex;align-items:flex-start;gap:12px;min-width:0}.dl-lh-main>.dl-need-ic{margin-top:1px}.dl-sub .dl-mono{font-size:.92em}.dl-need-row>.cbi-button{flex:none}.dl-bk-row .dl-group-ic{width:30px;height:30px}.dl-bk-older>summary{list-style:none;cursor:pointer;display:flex;align-items:center;gap:8px;padding:11px 16px;border-top:1px solid var(--dl-line);font-size:13px;color:var(--dl-fg-muted);user-select:none}.dl-bk-older>summary::-webkit-details-marker{display:none}.dl-bk-older>summary:hover{background:var(--dl-soft);color:var(--dl-fg)}.dl-bk-older>summary .dl-icon-wrap{display:inline-flex;transition:transform .15s}.dl-bk-older>summary .dl-icon{width:14px;height:14px}.dl-bk-older[open]>summary .dl-icon-wrap{transform:rotate(90deg)}#dl-set-backups .dl-setsec-head h3+.dl-sub{margin-top:2px}#dl-set-backups .dl-setsec-foot>.dl-sub{flex:1 1 260px}.dl-bk-actions{flex:0 1 auto;justify-content:flex-end}@media(max-width:640px){#dl-set-backups .dl-setsec-foot>.dl-sub{flex-basis:100%}.dl-bk-actions{justify-content:flex-start}}.dl-upd{display:flex;flex-direction:column;gap:16px}.dl-upd>.dl-pagehead{margin:0 0 4px}.dl-upd-bad{color:var(--dl-bad)}";var dr=".dl-comp-hero{display:grid;grid-template-columns:minmax(0,1.5fr) minmax(0,1fr)}.dl-comp-hero-main{padding:20px;display:flex;flex-direction:column;gap:12px;min-width:0}.dl-comp-hero-side{padding:20px;border-left:1px solid var(--dl-line);display:flex;flex-direction:column;gap:14px;min-width:0}.dl-comp-name{font-size:16px;font-weight:500}.dl-comp-hero-head{display:flex;align-items:center;gap:10px;flex-wrap:wrap;min-width:0}.dl-comp-hero-head .dl-spacer{flex:1}.dl-comp-big{font-family:var(--dl-mono);font-size:26px;line-height:34px;letter-spacing:-.02em;display:flex;align-items:baseline;gap:10px}.dl-comp-big small{font-size:14px;color:var(--dl-accent)}.dl-comp-big small.dl-faint{color:var(--dl-fg-faint)}.dl-comp-verrow{display:flex;align-items:center;gap:4px 12px;flex-wrap:wrap;min-width:0}.dl-comp-verrow .dl-spacer{flex:1}.dl-comp-meta{font-size:13px}.dl-comp-bullets{margin:0;padding-left:18px;display:flex;flex-direction:column;gap:4px;color:var(--dl-fg-muted);font-size:13px}.dl-comp-bullets li{list-style:disc}.dl-comp-lead{margin:0}.dl-comp-more{align-self:flex-start;font-size:12px;color:var(--dl-fg-faint);margin-left:18px;padding:0!important}.dl-comp-more:hover{color:var(--dl-accent);background:none!important;text-decoration:underline;text-underline-offset:2px}.dl-comp-hero-main>.dl-comp-vers{margin-top:auto}.dl-comp-btns{display:flex;gap:8px;flex-wrap:nowrap;align-items:center;flex:none}.dl-comp-side-v{display:flex;align-items:center;gap:8px;font-size:14px;min-width:0;flex-wrap:wrap}.dl-comp-side-v .dl-icon{width:15px;height:15px;color:var(--dl-fg-muted)}.dl-comp-side-v a{color:inherit;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-comp-side-v a:hover{color:var(--dl-accent)}.dl-comp-cols{display:grid;grid-template-columns:minmax(0,1.5fr) minmax(0,1fr);gap:16px;align-items:start}.dl-comp-cols>.dl-panel>div>.dl-row:first-child{border-top:1px solid var(--dl-line)}.dl-comp-count{font-size:13px}.dl-comp-sub{font-size:11px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-comp-ic{display:inline-flex;gap:4px;flex:none}.dl-comp-ic .cbi-button{width:30px;height:30px;padding:0!important;justify-content:center;border-radius:999px!important}.dl-comp-ic .dl-btn-label{display:none}.dl-comp-ic .dl-icon{width:14px;height:14px}.dl-comp-ic .is-busy{pointer-events:none;opacity:.5}.dl-comp-ic .cbi-button.dl-comp-check{width:auto;padding:0 12px 0 10px!important;gap:6px;display:inline-flex;align-items:center;font-size:13px}.dl-row>.dl-pill,.dl-row>.cbi-button,.dl-row>.dl-comp-ic{flex:none}button.dl-pill.dl-comp-run{all:unset;display:inline-flex;align-items:center;height:20px;padding:0 8px;border-radius:999px;font-size:12px;cursor:pointer;background:color-mix(in srgb,var(--dl-accent) 14%,transparent);color:var(--dl-accent)}.dl-comp-foldwrap{padding:0 16px 14px 60px}.dl-comp-fold .dl-params-body{gap:12px}.dl-comp-fold .dl-list>.dl-row{padding:10px 14px}.dl-comp-bver{font-size:12px;width:130px;text-align:right;flex:none;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dl-comp-bact{width:84px;flex:none;display:flex;justify-content:flex-end}.dl-comp-warn{display:flex;align-items:flex-start;gap:8px;font-size:12px;line-height:18px;color:var(--dl-fg-muted)}.dl-comp-warn .dl-icon-wrap{display:inline-flex;flex:none;margin-top:2px}.dl-comp-warn .dl-icon{width:14px;height:14px;color:var(--dl-warn)}.dl-comp-empty{margin:0;padding:4px 16px 16px}@media(max-width:760px){.dl-comp-hero,.dl-comp-cols{grid-template-columns:minmax(0,1fr)}.dl-comp-hero-side{border-left:0;border-top:1px solid var(--dl-line)}.dl-comp-foldwrap{padding-left:16px}.dl-comp-bver{display:none}}.dl-comp-status{display:flex;align-items:center;gap:8px;font-size:13px;padding:9px 12px;border-radius:10px;background:var(--dl-soft);min-width:0}.dl-comp-status>.dl-icon-wrap{display:inline-flex;flex:none}.dl-comp-status .dl-icon{width:15px;height:15px}.dl-comp-status.ok{background:var(--dl-ok-wash);color:var(--dl-ok)}.dl-comp-status.acc{background:color-mix(in srgb,var(--dl-accent) 12%,transparent);color:var(--dl-accent)}.dl-comp-status.warn{background:var(--dl-warn-wash);color:var(--dl-warn)}.dl-comp-status.bad{background:var(--dl-bad-wash);color:var(--dl-bad)}.dl-comp-status b{font-weight:600}.dl-comp-vers .dl-params-body{gap:0;padding:4px 14px 12px}.dl-comp-tag{display:flex;gap:6px;padding:6px 0 10px}.dl-comp-tag input{flex:1;min-width:0}.dl-comp-ver{display:flex;align-items:center;gap:8px;padding:7px 0;border-top:1px solid var(--dl-line);font-size:13px}.dl-comp-ver .dl-mono{min-width:52px}.dl-comp-ver .dl-sub{flex:1}.dl-comp-ver .cbi-button:not(.dl-icon-btn){height:26px!important;font-size:12px!important}.dl-comp-pager{display:flex;align-items:center;justify-content:space-between;padding-top:10px;border-top:1px solid var(--dl-line);font-size:12px}.dl-comp-pager .dl-linkbtn[disabled]{opacity:.4;cursor:default}.dl-comp-vers .dl-loading,.dl-comp-vers .dl-params-body>p{padding:6px 0 10px}.dl-op-head{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-bottom:14px}.dl-op-head .dl-spacer{flex:1}.dl-op-timer{display:inline-flex;align-items:center;gap:5px;font-variant-numeric:tabular-nums}.dl-op-timer .dl-icon,.dl-op-head .dl-linkbtn .dl-icon{width:14px;height:14px}.dl-op-loghead{display:flex;align-items:center;justify-content:space-between}.dl-op-loghead b{font-weight:500;font-size:13px}.dl-op .dl-log{max-height:16em;min-height:12em;margin-top:8px}.dl-op .dl-comp-status{margin:14px 0 0}.dl-op-actions{display:flex;gap:8px;justify-content:flex-end;flex-wrap:wrap;width:100%}.dl-notes{max-height:55vh;overflow:auto;border-radius:12px;background:var(--dl-soft);padding:14px 16px;font-size:13px;line-height:20px;overflow-wrap:anywhere}.dl-notes h5{margin:10px 0 6px;font-size:14px;font-weight:500}.dl-notes h5:first-child{margin-top:0}.dl-notes p{margin:0 0 8px}.dl-notes ul{margin:0 0 10px;padding-left:18px}.dl-notes li{list-style:disc}.dl-notes code{font-family:var(--dl-mono);font-size:12px;padding:1px 5px;border-radius:6px;background:var(--dl-soft-hover)}.dl-notes pre{font-family:var(--dl-mono);font-size:12px;padding:10px;border-radius:8px;background:var(--dl-soft-hover);white-space:pre-wrap;margin:0 0 10px}.dl-notes a{color:var(--dl-accent)}";var cr=".dl-chip.static{cursor:default}.dl-chip.static:hover{background:var(--dl-soft)}.dl-chip.static .dl-chip-name{font-weight:500}.dl-setrow.head .dl-chips-row{margin-top:8px}.dl-setrow.head>.dl-lh-main,.dl-setrow.head>.dl-lh-main>.dl-stack{flex:1 1 auto;min-width:0}.dl-setrow.head>.dl-setrow-ctl:empty{display:none}.dl-setrow.head:has(>.dl-lh-main){align-items:flex-start}.dl-setrow.head>.dl-setrow-ctl{align-items:center;min-height:30px}.dl-netpick{margin-top:10px}.dl-boxrow{display:flex;align-items:center;justify-content:space-between;gap:16px;margin:0;padding:10px 14px;border:1px solid var(--dl-line);border-radius:12px;font-size:13px;cursor:pointer}.dl-boxrow>.dl-switch{flex:none}.dl-ifpick{display:flex;flex-direction:column;gap:12px;padding:14px;border:1px solid var(--dl-line);border-radius:14px}.dl-iflead-row{display:flex;align-items:center;justify-content:space-between;gap:12px}.dl-host-ports{justify-content:flex-end}@media(max-width:760px){.dl-host-ports{justify-content:flex-start}}.dl-circle-dot{display:inline-block;width:8px;height:8px;border-radius:50%;flex:none}.dl-circles .dl-chip b{font-weight:500}.dl-circle-name{display:inline-flex;align-items:center;gap:8px;font-size:14px;font-weight:500}.dl-w400{font-weight:400}.dl-swatches{display:flex;flex-wrap:wrap;gap:8px}.dl-swatch{all:unset;cursor:pointer;width:22px;height:22px;border-radius:50%;background:var(--sw);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dl-fg) 12%,transparent)}.dl-swatch.on{box-shadow:0 0 0 2px var(--dl-card),0 0 0 4px var(--sw)}.dl-swatch:focus-visible{outline:2px solid var(--dl-ring);outline-offset:3px}.dl-circle-modal .dl-chipbtn b{margin-left:6px;font-weight:500;font-size:11px;opacity:.6}.dl-reach td:first-child b{font-weight:500}.dl-ev-host{white-space:nowrap}.dl-ev-host b{font-weight:500;color:var(--dl-fg)}.dl-reach{font-size:13px}.dl-reach th,.dl-reach td{white-space:nowrap;padding-left:6px;padding-right:6px}.dl-reach-wrap{overflow-x:auto}.dl-yes{display:inline-flex;align-items:center;gap:4px;color:var(--dl-ok)}.dl-yes .dl-icon-wrap{display:inline-flex}.dl-yes .dl-icon{width:14px;height:14px}.dl-check-form{display:grid;grid-template-columns:minmax(0,1fr) auto minmax(0,1fr) auto;align-items:start;gap:8px}.dl-check-form>.dl-faint{line-height:36px}.dl-check-end{display:flex;flex-direction:column;gap:6px;min-width:0}.dl-check-end>*{width:100%!important;min-width:0}@media(max-width:560px){.dl-check-form{grid-template-columns:minmax(0,1fr)}.dl-check-form>.dl-faint{display:none}}.dl-verdict{display:flex;align-items:baseline;gap:10px;padding:10px 12px;border-radius:12px}.dl-verdict b{font-weight:500}.dl-verdict.ok{background:var(--dl-ok-wash)}.dl-verdict.ok b{color:var(--dl-ok)}.dl-verdict.bad{background:var(--dl-bad-wash)}.dl-verdict.bad b{color:var(--dl-bad)}.dl-corehead{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin:0 0 4px}.dl-corehead h3{margin:0!important}.dl-row-end{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap}.dl-dcard.clickable{cursor:pointer}.dl-dcard.clickable:hover{border-color:color-mix(in srgb,var(--dl-fg) 22%,transparent)}";var hs=[Ya,Za,Qa,Xa,er,tr,nr,or,ar,rr,ir,sr,lr,dr,cr].join(` +`);function pr(){let n=document.createElement("style");return n.dataset.dawnline="1",n.textContent=hs,n}function lt(n){return()=>{let e=new n;return Object.assign({load:()=>e.load(),render:async a=>{let r=await e.render(a),i=document.createElement("div");return i.className="dl-root",i.append(pr(),r),i},addFooter(){return e.noFooter?document.createElement("div"):this.super("addFooter",[])}},{handleSave:null,handleSaveApply:null,handleReset:null})}}var _g=lt(Ot),Tg=lt(st),Cg=lt(Ot),Pg=lt(vn),Dg=lt(wn),Ag=lt(En),zg=lt(xn);function ur(n){return()=>({load:()=>(ui.menu?.flushCache(),location.replace(`${L.url("admin/network/dawnline/diagnostics")}${n?`?tab=${n}`:""}`),new Promise(()=>{})),render:()=>document.createElement("div"),handleSave:null,handleSaveApply:null,handleReset:null})}var Hg=ur(""),Ng=ur("log");return baseclass.extend({ activity: Ng, diagnostics: Ag, health: Hg, overview: _g, people: Tg, person: Dg, server: Cg, settings: Pg, updates: zg }); diff --git a/package/luci-app-dawnline/root/etc/init.d/dawnline b/package/luci-app-dawnline/root/etc/init.d/dawnline index e339fc2..815fe90 100755 --- a/package/luci-app-dawnline/root/etc/init.d/dawnline +++ b/package/luci-app-dawnline/root/etc/init.d/dawnline @@ -21,9 +21,11 @@ start_portal() { hport="$(/usr/bin/dawnline portal-http-port 2>/dev/null)" [ -n "$hport" ] && http="-p 0.0.0.0:$hport -p [::]:$hport" + # Four portal processes at once (each loads the whole model: a burst of 16 + # could empty a 128 MB router); the rest of 64 connections wait their turn. procd_open_instance portal procd_set_param command /usr/sbin/uhttpd -f -h "$PORTAL_ROOT" -x /cgi-bin -E /cgi-bin/portal \ - -D -n 16 -N 64 -t 20 -T 30 -k 10 -A 1 \ + -D -n 4 -N 64 -t 20 -T 30 -k 10 -A 1 \ -s "0.0.0.0:$port" -s "[::]:$port" -C "$cert" -K "$key" $http procd_set_param file "$cert" procd_set_param respawn 3600 5 0 diff --git a/package/luci-app-dawnline/root/etc/uci-defaults/90_dawnline b/package/luci-app-dawnline/root/etc/uci-defaults/90_dawnline index 98ab8c3..4073e49 100755 --- a/package/luci-app-dawnline/root/etc/uci-defaults/90_dawnline +++ b/package/luci-app-dawnline/root/etc/uci-defaults/90_dawnline @@ -57,6 +57,12 @@ grep -qs /usr/libexec/dawnline/heartbeat /etc/crontabs/root || { # A reload keeps LuCI logins but sometimes misses the plugin; restart only then. sleep 2 ubus list luci.dawnline >/dev/null 2>&1 || { /etc/init.d/rpcd restart; sleep 2; } -/etc/init.d/dawnline enable -/etc/init.d/dawnline restart +# A fresh install starts the service; an upgrade restarts it only where the +# admin had it on (a disabled Dawnline stays that way). +if [ "$PKG_UPGRADE" = 1 ]; then + /etc/init.d/dawnline enabled && /etc/init.d/dawnline restart +else + /etc/init.d/dawnline enable + /etc/init.d/dawnline restart +fi exit 0 diff --git a/package/luci-app-dawnline/root/usr/libexec/dawnline/agent b/package/luci-app-dawnline/root/usr/libexec/dawnline/agent index 78428c0..fd51eed 100755 --- a/package/luci-app-dawnline/root/usr/libexec/dawnline/agent +++ b/package/luci-app-dawnline/root/usr/libexec/dawnline/agent @@ -360,7 +360,10 @@ function nightly_backup() { backup.backup_create('auto'); write_json(`${DATA_DIR}/backup-state.json`, { auto: sum }, 0o600); } - catch (e) {} + catch (e) { + // Tried again tomorrow; meanwhile the admin should know (a full flash, mostly). + slog('dawnline', 'error', `nightly backup failed: ${e.message}`, null, 'Backup'); + } } } @@ -391,7 +394,9 @@ function check_usage_reset(m) { /* * Push devices and access rules when people's states changed, the config - * file was written (by anyone: rpcd, the portal, the CLI, a restore), or + * file was written (by anyone: rpcd, the portal, the CLI, a restore), the + * access table is gone (a flushed ruleset: the firewall alone would let every + * device reach everything, so the sync unloads them until it is back), or * every RESYNC_EVERY seconds anyway. apply.sync reads the model again itself. */ function sync_runtime(t) { @@ -400,7 +405,7 @@ function sync_runtime(t) { let mt = st ? `${st.mtime}/${st.inode}` : null; let changed = last_states == null || sprintf('%J', t.states) != sprintf('%J', last_states) || (conf_mtime != null && mt != conf_mtime); - if (changed || time() - last_sync > RESYNC_EVERY) { + if (changed || time() - last_sync > RESYNC_EVERY || (length(t.m.servers) && !apply.table_present())) { apply.sync(t.m, usage); last_sync = time(); } @@ -491,8 +496,13 @@ function step(i, s, fn) { function tick() { ensure_dir(RUN_DIR); writefile(watchdog.BEAT, `${time()}`); - // A restore or import drops the live counters; start over from flash. - if (!stat(`${RUN_DIR}/usage.json`) && usage.updated) + // A restore or import put other counters on flash (dawnline.backup leaves + // a marker): start over from them, whatever the watcher wrote since. + if (stat(live.USAGE_RELOAD)) { + unlink(live.USAGE_RELOAD); + usage = live.load_usage(true); + } + else if (!stat(`${RUN_DIR}/usage.json`) && usage.updated) usage = live.load_usage(); let t = { m: null, pol: null, reset: false, events: [] }; for (let i, s in STEPS) @@ -535,7 +545,13 @@ if (was != VERSION) { writefile(`${DATA_DIR}/version`, VERSION); } slog_restore(); -if (was && was != VERSION) +// postupdate put this (kept) version back because the new one did not come up. +let rolled = trim(readfile(`${RUN_DIR}/update-rolled-back`) ?? ''); +unlink(`${RUN_DIR}/update-rolled-back`); +if (rolled) + slog('dawnline', 'error', `update to ${rolled} failed its check — rolled back to ${VERSION}`, + 'The new version did not answer in LuCI or its agent did not start. Try again from Components, or install it with install.sh to see why.', 'Dawnline'); +else if (was && was != VERSION) slog('dawnline', 'up', `updated · ${was} → ${VERSION}`, null, 'Dawnline'); else if (crashed) slog('dawnline', 'repair', 'stopped unexpectedly — started again', diff --git a/package/luci-app-dawnline/root/usr/libexec/dawnline/postupdate b/package/luci-app-dawnline/root/usr/libexec/dawnline/postupdate new file mode 100755 index 0000000..71533ff --- /dev/null +++ b/package/luci-app-dawnline/root/usr/libexec/dawnline/postupdate @@ -0,0 +1,51 @@ +#!/bin/sh +# Dawnline — after its own package was replaced: restart, check that the new +# version answers (the LuCI link and the agent), and put the kept previous +# version back when it does not. Started detached by the updater +# (usr/libexec/dawnline/updater) with the version being installed. +# postupdate +# Plain shell on purpose: a release whose ucode does not compile cannot check +# or repair itself, and the admin cannot click Roll back in a page that this +# same backend serves. +RUN=/var/run/dawnline +KEEP=/etc/dawnline/keep/app +to="${1:-?}" + +sleep 2 +/etc/init.d/rpcd reload >/dev/null 2>&1 +/etc/init.d/dawnline restart >/dev/null 2>&1 + +up() { + ubus list luci.dawnline >/dev/null 2>&1 || return 1 + ubus -t 10 call luci.dawnline rev >/dev/null 2>&1 || return 1 + pgrep -f '^/usr/bin/ucode /usr/libexec/dawnline/agent' >/dev/null 2>&1 +} + +i=0 +while [ "$i" -lt 12 ]; do + sleep 5 + i=$((i + 1)) + up && exit 0 +done + +logger -t dawnline "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" + exit 1 +fi +if command -v apk >/dev/null 2>&1; then + apk add --allow-untrusted "$@" >/dev/null 2>&1 +else + opkg install --force-reinstall --force-downgrade "$@" >/dev/null 2>&1 +fi +/etc/init.d/rpcd restart >/dev/null 2>&1 +/etc/init.d/dawnline restart >/dev/null 2>&1 +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" +exit 0 diff --git a/package/luci-app-dawnline/root/usr/libexec/dawnline/updater b/package/luci-app-dawnline/root/usr/libexec/dawnline/updater index ebaed58..e9ec1e8 100755 --- a/package/luci-app-dawnline/root/usr/libexec/dawnline/updater +++ b/package/luci-app-dawnline/root/usr/libexec/dawnline/updater @@ -72,6 +72,8 @@ const ctx = { pol: POL, work: `/tmp/dawnline-update.${PID}`, log, phase, run, save, + // An automatic run (nobody is watching: the previous version is always kept). + auto: () => job.auto, versions: (from, to) => { job.from = from; job.to = to; @@ -241,16 +243,23 @@ function auto() { install(todo); } -/** The restarts the job asked for, in one go, after its final state is saved. */ +/** + * The restarts the job asked for, in one go, after its final state is saved. + * Dawnline's own package is restarted by postupdate, a shell that also checks + * the new version and rolls back to the kept one when it does not come up. + */ function restarts() { + if (after.app) { + let to = replace(`${job.to ?? ''}`, /[^A-Za-z0-9.-]/g, ''); + system(`/usr/libexec/dawnline/postupdate '${to}' /dev/null 2>&1 &`); + return; + } let cmds = []; - if (after.app) - push(cmds, '/etc/init.d/rpcd reload'); - else if (after.apply) + if (after.apply) push(cmds, '/usr/bin/dawnline apply'); if (after.uhttpd) push(cmds, '/etc/init.d/uhttpd restart'); - if (after.app || after.apply || after.uhttpd) + if (after.apply || after.uhttpd) push(cmds, '/etc/init.d/dawnline restart'); if (length(cmds)) system(`( sleep 2; ${join('; ', cmds)} ) /dev/null 2>&1 &`); diff --git a/package/luci-app-dawnline/root/usr/share/dawnline/portal/assets/portal.js b/package/luci-app-dawnline/root/usr/share/dawnline/portal/assets/portal.js index 9cdd88f..53e3199 100644 --- a/package/luci-app-dawnline/root/usr/share/dawnline/portal/assets/portal.js +++ b/package/luci-app-dawnline/root/usr/share/dawnline/portal/assets/portal.js @@ -1,6 +1,6 @@ -"use strict";(()=>{var ct=Object.create;var Ie=Object.defineProperty;var lt=Object.getOwnPropertyDescriptor;var ut=Object.getOwnPropertyNames;var dt=Object.getPrototypeOf,ft=Object.prototype.hasOwnProperty;var ht=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var vt=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let u of ut(t))!ft.call(e,u)&&u!==r&&Ie(e,u,{get:()=>t[u],enumerable:!(i=lt(t,u))||i.enumerable});return e};var pt=(e,t,r)=>(r=e!=null?ct(dt(e)):{},vt(t||!e||!e.__esModule?Ie(r,"default",{value:e,enumerable:!0}):r,e));var ze=ht((Ye,je)=>{"use strict";var Ve=(function(){var e=function(M,A){var b=236,x=17,c=M,m=r[A],s=null,a=0,y=null,f=[],g={},L=function(l,d){a=c*4+17,s=(function(o){for(var h=new Array(o),p=0;p=7&&z(l),y==null&&(y=it(c,m,f)),W(y,d)},E=function(l,d){for(var o=-1;o<=7;o+=1)if(!(l+o<=-1||a<=l+o))for(var h=-1;h<=7;h+=1)d+h<=-1||a<=d+h||(0<=o&&o<=6&&(h==0||h==6)||0<=h&&h<=6&&(o==0||o==6)||2<=o&&o<=4&&2<=h&&h<=4?s[l+o][d+h]=!0:s[l+o][d+h]=!1)},P=function(){for(var l=0,d=0,o=0;o<8;o+=1){L(!0,o);var h=u.getLostPoint(g);(o==0||l>h)&&(l=h,d=o)}return d},I=function(){for(var l=8;l>o&1)==1;s[Math.floor(o/3)][o%3+a-8-3]=h}for(var o=0;o<18;o+=1){var h=!l&&(d>>o&1)==1;s[o%3+a-8-3][Math.floor(o/3)]=h}},Q=function(l,d){for(var o=m<<3|d,h=u.getBCHTypeInfo(o),p=0;p<15;p+=1){var w=!l&&(h>>p&1)==1;p<6?s[p][8]=w:p<8?s[p+1][8]=w:s[a-15+p][8]=w}for(var p=0;p<15;p+=1){var w=!l&&(h>>p&1)==1;p<8?s[8][a-p-1]=w:p<9?s[8][15-p-1+1]=w:s[8][15-p-1]=w}s[a-8][8]=!l},W=function(l,d){for(var o=-1,h=a-1,p=7,w=0,C=u.getMaskFunction(d),_=a-1;_>0;_-=2)for(_==6&&(_-=1);;){for(var N=0;N<2;N+=1)if(s[h][_-N]==null){var O=!1;w>>p&1)==1);var T=C(h,_-N);T&&(O=!O),s[h][_-N]=O,p-=1,p==-1&&(w+=1,p=7)}if(h+=o,h<0||a<=h){h-=o,o=-o;break}}},ae=function(l,d){for(var o=0,h=0,p=0,w=new Array(d.length),C=new Array(d.length),_=0;_=0?Ne.getAt(Re):0}}for(var He=0,T=0;T_*8)throw"code length overflow. ("+p.getLengthInBits()+">"+_*8+")";for(p.getLengthInBits()+4<=_*8&&p.put(0,4);p.getLengthInBits()%8!=0;)p.putBit(!1);for(;!(p.getLengthInBits()>=_*8||(p.put(b,8),p.getLengthInBits()>=_*8));)p.put(x,8);return ae(p,h)};g.addData=function(l,d){d=d||"Byte";var o=null;switch(d){case"Numeric":o=$(l);break;case"Alphanumeric":o=q(l);break;case"Byte":o=J(l);break;case"Kanji":o=U(l);break;default:throw"mode:"+d}f.push(o),y=null},g.isDark=function(l,d){if(l<0||a<=l||d<0||a<=d)throw l+","+d;return s[l][d]},g.getModuleCount=function(){return a},g.make=function(){if(c<1){for(var l=1;l<40;l++){for(var d=B.getRSBlocks(l,m),o=D(),h=0;h";for(var p=0;p';o+=""}return o+="",o+="",o},g.createSvgTag=function(l,d,o,h){var p={};typeof arguments[0]=="object"&&(p=arguments[0],l=p.cellSize,d=p.margin,o=p.alt,h=p.title),l=l||2,d=typeof d=="undefined"?l*4:d,o=typeof o=="string"?{text:o}:o||{},o.text=o.text||null,o.id=o.text?o.id||"qrcode-description":null,h=typeof h=="string"?{text:h}:h||{},h.text=h.text||null,h.id=h.text?h.id||"qrcode-title":null;var w=g.getModuleCount()*l+d*2,C,_,N,O,T="",Y;for(Y="l"+l+",0 0,"+l+" -"+l+",0 0,-"+l+"z ",T+=''+se(h.text)+"":"",T+=o.text?''+se(o.text)+"":"",T+='',T+='":d+=">";break;case"&":d+="&";break;case'"':d+=""";break;default:d+=h;break}}return d},ot=function(l){var d=1;l=typeof l=="undefined"?d*2:l;var o=g.getModuleCount()*d+l*2,h=l,p=o-l,w,C,_,N,O,T={"██":"█","█ ":"▀"," █":"▄"," ":" "},Y={"██":"▀","█ ":"▀"," █":" "," ":" "},j="";for(w=0;w=p?Y[O]:T[O];j+=` -`}return o%2&&l>0?j.substring(0,j.length-o-1)+Array(o+1).join("▀"):j.substring(0,j.length-1)};return g.createASCII=function(l,d){if(l=l||1,l<2)return ot(d);l-=1,d=typeof d=="undefined"?l*2:d;var o=g.getModuleCount()*l+d*2,h=d,p=o-d,w,C,_,N,O=Array(l+1).join("██"),T=Array(l+1).join(" "),Y="",j="";for(w=0;w>>8),m.push(y&255)):m.push(x)}}return m}};var t={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},r={L:1,M:0,Q:3,H:2},i={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},u=(function(){var M=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],A=1335,b=7973,x=21522,c={},m=function(s){for(var a=0;s!=0;)a+=1,s>>>=1;return a};return c.getBCHTypeInfo=function(s){for(var a=s<<10;m(a)-m(A)>=0;)a^=A<=0;)a^=b<5&&(y+=3+L-5)}for(var f=0;f=256;)c-=255;return M[c]},x})();function k(M,A){if(typeof M.length=="undefined")throw M.length+"/"+A;var b=(function(){for(var c=0;c>>7-x%8&1)==1},b.put=function(x,c){for(var m=0;m>>c-m-1&1)==1)},b.getLengthInBits=function(){return A},b.putBit=function(x){var c=Math.floor(A/8);M.length<=c&&M.push(0),x&&(M[c]|=128>>>A%8),A+=1},b},$=function(M){var A=t.MODE_NUMBER,b=M,x={};x.getMode=function(){return A},x.getLength=function(s){return b.length},x.write=function(s){for(var a=b,y=0;y+2>>8&255)*192+(f&255),s.put(f,13),y+=2}if(y>>8)},A.writeBytes=function(b,x,c){x=x||0,c=c||b.length;for(var m=0;m0&&(b+=","),b+=M[x];return b+="]",b},A},F=function(){var M=0,A=0,b=0,x="",c={},m=function(a){x+=String.fromCharCode(s(a&63))},s=function(a){if(!(a<0)){if(a<26)return 65+a;if(a<52)return 97+(a-26);if(a<62)return 48+(a-52);if(a==62)return 43;if(a==63)return 47}throw"n:"+a};return c.writeByte=function(a){for(M=M<<8|a&255,A+=8,b+=1;A>=6;)m(M>>>A-6),A-=6},c.flush=function(){if(A>0&&(m(M<<6-A),M=0,A=0),b%3!=0)for(var a=3-b%3,y=0;y=A.length){if(c==0)return-1;throw"unexpected end of file./"+c}var a=A.charAt(b);if(b+=1,a=="=")return c=0,-1;if(a.match(/^\s$/))continue;x=x<<6|s(a.charCodeAt(0)),c+=6}var y=x>>>c-8&255;return c-=8,y};var s=function(a){if(65<=a&&a<=90)return a-65;if(97<=a&&a<=122)return a-97+26;if(48<=a&&a<=57)return a-48+52;if(a==43)return 62;if(a==47)return 63;throw"c:"+a};return m},re=function(M,A){var b=M,x=A,c=new Array(M*A),m={};m.setPixel=function(f,g,L){c[g*b+f]=L},m.write=function(f){f.writeString("GIF87a"),f.writeShort(b),f.writeShort(x),f.writeByte(128),f.writeByte(0),f.writeByte(0),f.writeByte(0),f.writeByte(0),f.writeByte(0),f.writeByte(255),f.writeByte(255),f.writeByte(255),f.writeString(","),f.writeShort(0),f.writeShort(0),f.writeShort(b),f.writeShort(x),f.writeByte(0);var g=2,L=a(g);f.writeByte(g);for(var E=0;L.length-E>255;)f.writeByte(255),f.writeBytes(L,E,255),E+=255;f.writeByte(L.length-E),f.writeBytes(L,E,L.length-E),f.writeByte(0),f.writeString(";")};var s=function(f){var g=f,L=0,E=0,P={};return P.write=function(I,G){if(I>>>G)throw"length over";for(;L+G>=8;)g.writeByte(255&(I<>>=8-L,E=0,L=0;E=I<0&&g.writeByte(E)},P},a=function(f){for(var g=1<>6,128|v&63):v<55296||v>=57344?i.push(224|v>>12,128|v>>6&63,128|v&63):(u++,v=65536+((v&1023)<<10|r.charCodeAt(u)&1023),i.push(240|v>>18,128|v>>12&63,128|v>>6&63,128|v&63))}return i}return t(e)}})();(function(e){typeof define=="function"&&define.amd?define([],e):typeof Ye=="object"&&(je.exports=e())})(function(){return Ve})});function ie(e){if(!e||e<0)return"0 B";let t=["B","KB","MB","GB","TB"],r=0,i=e;for(;i>=1024&&r=100||r===0?Math.round(i):i.toFixed(1)} ${t[r]}`}function xe(e,t=Date.now()/1e3){if(!e)return"never";let r=Math.max(0,Math.round(t-e));return r<60?"just now":r<3600?`${Math.floor(r/60)} min ago`:r<86400?`${Math.floor(r/3600)} h ago`:r<86400*30?`${Math.floor(r/86400)} d ago`:new Date(e*1e3).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function ve(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}function pe(e){let[t,r,i]=e.split("-").map(Number);return new Date(t,(r||1)-1,i||1,12)}function gt(e){return(typeof e=="string"?/^\d{4}-\d{2}-\d{2}$/.test(e)?pe(e):new Date(e):e).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function we(e){return e?gt(e):""}function mt(e,t){let r=i=>{let[u,v,k]=i.split("-").map(Number);return Date.UTC(u,v-1,k)};return Math.round((r(e)-r(t))/864e5)}function Oe(e,t){let r=pe(e);return r.setDate(r.getDate()+t),ve(r)}function Me(e,t=Date.now()){if(!e)return null;let r=typeof t=="number"?ve(new Date(t)):t,i=mt(e,r);return i>=0?i+1:i}function ke(e,t){return t!=null&&t>0&&e.expire_warn>0&&t<=e.expire_warn}function Ke(e){return e<=1?"ends today":e===2?"ends tomorrow":`ends in ${e} days`}var Ue={lan:"Home network",internet:"Internet",both:"Home network + Internet"};var ge={computer:"PC",phone:"Phone",tablet:"Tablet",router:"Router",other:"Other"};function Fe(e){var u,v,k;let t=e.trim().split(/\s+/).filter(Boolean);if(!t.length)return"?";let r=(u=t[0][0])!=null?u:"",i=t.length>1?(v=t[t.length-1][0])!=null?v:"":(k=t[0][1])!=null?k:"";return(r+i).toUpperCase()}function Ae(e){let t=r=>r.disabled?3:r.online?0:r.handshake?1:2;return e.map((r,i)=>[r,i]).sort((r,i)=>t(r[0])-t(i[0])||r[1]-i[1]).map(([r])=>r)}var Ge={phone:'',computer:'',tablet:'',router:'',server:'',other:'',ethernet:'',bridge:'',wifi:'',tunnel:'',plus:'',chart:'',reset:'',package:'',code:'',plug:'',sunrise:'',refresh:'',archive:'',qr:'',copy:'',download:'',link:'',trash:'',edit:'',pause:'',play:'',key:'',out:'',admin:'',shield:'',shieldplus:'',lock:'',zap:'',check:'',alert:'',x:'',globe:'',home:'',open:'',file:'',network:'',moon:'',chevron:'',clock:'',calendar:'',minus:'',more:'',pin:'',activity:''};function qe(e,t="dl-icon"){var i;let r=(i=Ge[e])!=null?i:Ge.phone;return``}var Je=pt(ze(),1),yt='';function Qe(e,t=3,r=!0){let i=(0,Je.default)(0,e.length>300?"Q":"H");i.addData(e,"Byte"),i.make();let u=i.getModuleCount(),v=u+t*2,k=r?Math.round(u*.22):0;k&&(u-k)%2&&k++;let B=(u-k)/2,D=B+k,$=(U,R)=>k>0&&U>=B&&U=B&&R${yt}`}return`${J}`}var bt={jc:"0",jmin:"0",jmax:"0",s1:"0",s2:"0",s3:"0",s4:"0",h1:"1",h2:"2",h3:"3",h4:"4",i1:"",i2:"",i3:"",i4:"",i5:""},xt={header_protection_key:"HeaderProtectionKey",content_padding_addition:"ContentPaddingAddition",rekey_after_time:"RekeyAfterTime",rekey_timeout:"RekeyTimeout",reject_after_time:"RejectAfterTime",keepalive_timeout:"KeepaliveTimeout",max_handshake_attempts:"MaxHandshakeAttempts",random_trailers:"RandomTrailers",disable_cookies:"DisableCookies"};function wt(e){let t={};for(let[r,i]of Object.entries(xt))e[r]!=null&&e[r]!==""&&(t[i]=String(e[r]));return t}function Mt(e,t){var D;let r=e.amnezia,i=(D=r.obfuscation)!=null?D:{},u=$=>i[$]!=null&&i[$]!==""?String(i[$]):bt[$],v=r.host.replace(/^\[(.*)\]$/,"$1"),k={H1:u("h1"),H2:u("h2"),H3:u("h3"),H4:u("h4"),I1:u("i1"),I2:u("i2"),I3:u("i3"),I4:u("i4"),I5:u("i5"),Jc:u("jc"),Jmin:u("jmin"),Jmax:u("jmax"),S1:u("s1"),S2:u("s2"),S3:u("s3"),S4:u("s4"),...wt(i),allowed_ips:r.allowed_ips,client_ip:r.client_ip,client_priv_key:r.client_priv_key,client_pub_key:r.client_pub_key,config:e.conf.replace(/\r?\n/g,`\r -`),hostName:v,mtu:r.mtu,persistent_keep_alive:r.persistent_keep_alive,port:Number(r.port),psk_key:r.psk_key,server_pub_key:r.server_pub_key},B={containers:[{container:"amnezia-awg",awg:{isThirdPartyConfig:!0,last_config:JSON.stringify(k),port:String(r.port),protocol_version:i.header_protection_key?"3.1":"2",transport_proto:"udp"}}],defaultContainer:"amnezia-awg",description:t,hostName:v};return r.dns[0]&&(B.dns1=r.dns[0]),r.dns[1]&&(B.dns2=r.dns[1]),B}function kt(e){let t="";for(let r=0;r{var e;return(e=S==null?void 0:S.today)!=null?e:ve(new Date)};function n(e,t={},...r){let i=document.createElement(e);for(let[v,k]of Object.entries(t))k==null||k===!1||(v.startsWith("on")&&typeof k=="function"?i.addEventListener(v.slice(2),k):v==="class"?i.className=String(k):k===!0?i.setAttribute(v,""):i.setAttribute(v,String(k)));let u=v=>{v==null||v===!1||(Array.isArray(v)?v.forEach(u):i.appendChild(typeof v=="string"?document.createTextNode(v):v))};return r.forEach(u),i}function K(e){let t=n("span",{class:"ic"});return t.innerHTML=qe(e,"ic-svg"),t}var _t='',Be=document.getElementById("app"),Xe,me=(Xe=Be.dataset.base)!=null?Xe:"",Ct=Be.dataset.title||"Dawnline",Te=()=>window.matchMedia("(max-width: 959px)").matches||/Android|iPhone|iPad/.test(navigator.userAgent),S=null,Tt=/^\/[a-z]{6}-[a-z]{6}-[a-z]{6}$/.test(me)?me.slice(1):"",Le=class extends Error{constructor(r,i){super(i);this.status=r}};async function ne(e,t){var u;let r=await fetch(`${me}/api/${e}`,{method:t===void 0?"GET":"POST",credentials:"omit",headers:t===void 0?{}:{"Content-Type":"application/json"},body:t===void 0?void 0:JSON.stringify(t),cache:"no-store"}),i=null;try{i=await r.json()}catch{}if(!r.ok)throw new Le(r.status,(u=i==null?void 0:i.error)!=null?u:`Request failed (${r.status})`);return i}function te(e,t=!1){let r=n("div",{class:`toast${t?" bad":""}`,role:"status"},e);document.body.appendChild(r),requestAnimationFrame(()=>r.classList.add("show")),setTimeout(()=>{r.classList.remove("show"),setTimeout(()=>r.remove(),300)},2600)}async function ce(e,t="Copied"){try{await navigator.clipboard.writeText(e)}catch{let r=n("textarea",{class:"offscreen"},e);document.body.appendChild(r),r.select();let i=document.execCommand("copy");if(r.remove(),!i)return te("Copying is blocked here. Select the text and copy it by hand.",!0)}te(t)}function et(e,t){let r=URL.createObjectURL(new Blob([t],{type:"application/octet-stream"})),i=n("a",{href:r,download:e,class:"offscreen"});document.body.appendChild(i),i.click(),setTimeout(()=>{URL.revokeObjectURL(r),i.remove()},1e3)}var Z=null;function tt(e,t){let r=i=>{Z!=null||(Z=document.body.appendChild(n("div",{class:"tip"}))),Z.replaceChildren(...t().map((u,v)=>n("div",{class:v?"muted":"tip-title"},u))),Z.style.display="",Z.style.left=`${i.clientX}px`,Z.style.top=`${i.clientY-10}px`};e.addEventListener("mouseenter",r),e.addEventListener("mousemove",r),e.addEventListener("mouseleave",()=>Z&&(Z.style.display="none"))}function Lt(e){let t=Math.max(1,...e),r=n("div",{class:"spark"});return e.forEach((i,u)=>{let v=n("i",{class:i?"":"zero"});v.style.height=`${Math.max(8,i/t*100)}%`;let k=e.length-1-u;tt(v,()=>[k===0?"Today":k===1?"Yesterday":pe(Oe(Ee(),-k)).toLocaleDateString("en-GB",{weekday:"short",day:"numeric",month:"short"}),ie(i)]),r.appendChild(v)}),r}async function $e(e,t){if(!e.disabled){e.disabled=!0;try{await t()}finally{e.disabled=!1}}}var oe=null,le=null;function ee(e=!1){if(!oe)return;let t=oe;if(oe=null,document.body.classList.remove("locked"),le==null||le(),le=null,e){t.remove();return}t.classList.remove("open"),setTimeout(()=>t.remove(),250)}function de(e,t,...r){let i=!!oe;ee(!0);let u=n("div",{class:"sheet-panel",role:"dialog","aria-modal":"true","aria-label":e},n("div",{class:"grab"}),n("div",{class:"sheet-head"},n("div",{class:"stack"},n("h2",{},e),t?n("span",{class:"muted s"},t):null),n("button",{class:"icon-btn","aria-label":"Close",onclick:()=>ee()},K("x"))),n("div",{class:"sheet-body"},...r)),v=n("div",{class:"sheet",onclick:k=>{k.target===v&&ee()}},u);return document.body.appendChild(v),document.body.classList.add("locked"),i?v.classList.add("open"):requestAnimationFrame(()=>v.classList.add("open")),oe=v,u}document.addEventListener("keydown",e=>{e.key==="Escape"&&(ye(),ee())});var X=null;function ye(){X==null||X.remove(),X=null}document.addEventListener("click",e=>{X&&!X.contains(e.target)&&ye()});function Dt(e,t){ye();let r=t.filter((k,B)=>k||B>0&&t[B-1]&&t.slice(B+1).some(Boolean)),i=n("div",{class:"menu",role:"menu"},r.map(k=>k?n("button",{type:"button",role:"menuitem",class:`menu-item${k.danger?" danger":""}`,onclick:()=>{ye(),k.run()}},K(k.icon),n("span",{},k.label)):n("div",{class:"menu-sep"})));document.body.appendChild(i);let u=e.getBoundingClientRect(),v=230;i.style.left=`${Math.max(8,Math.min(window.innerWidth-v-8,u.right-v))}px`,i.style.top=`${u.bottom+6+window.scrollY}px`,X=i}function Se(...e){Be.replaceChildren(n("header",{class:"top"},n("div",{class:"brand"},(()=>{let t=n("span",{class:"logo"});return t.innerHTML=_t,t})(),n("span",{},(S==null?void 0:S.server.name)||Ct),n("span",{class:"faint"},"· Dawnline"))),n("main",{class:"wrap"},...e))}function nt(){Se(n("div",{class:"card signin"},n("div",{class:"hero-ic"},K("key")),n("h1",{},"This link no longer works"),n("p",{class:"muted"},"Ask for a new personal link.")))}function Et(e){switch(e.state){case"server_off":return["server","The server is turned off","Your devices can’t connect until the admin turns it on again."];case"no_server":return["server","No server yet","Ask the admin to add you to a server."];case"quota":return["chart","You have used all your data","Your devices are paused until it resets."];case"expired":return["calendar","Your access has ended","Ask the admin to extend it."];case"hours":return["clock","Outside your hours",`Access is available ${e.hours.replace("-","–")} (router time).`];default:return["pause","Your access is paused by the admin","Your devices can’t connect until the admin resumes it."]}}function We(e,t,r,i){return n("div",{class:"alert"},n("span",{class:`alert-ic ${e}`},K(t)),n("div",{class:"stack"},n("span",{class:"strong"},r),n("span",{class:"muted s"},i)))}function Bt(e){return e.state==="active"?"ok":e.state==="quota"||e.state==="expired"?"bad":"warn"}var $t={internet:"The internet, through the router",lan:"Devices at home",both:"Devices at home and the internet, through the router"};function St(e){let t=e.person,r=t.quota_limit?Math.min(100,t.quota_used/t.quota_limit*100):0,i=n("div",{class:`meter${r>=100?" bad":r>=90?" warn":""}`},n("i"));i.firstChild.style.width=`${r}%`,t.quota_limit&&tt(i,()=>[`${r.toFixed(1)}% used`,`${ie(Math.max(0,t.quota_limit-t.quota_used))} left`]);let u=Me(t.expires,Ee()),v=n("div",{class:"slots"});for(let D=0;D=t.device_limit?"over":D=0?`${u} day${u===1?"":"s"} left`:"ended"):null)),n("span",{class:"faint s"},t.hours?`Available ${t.hours.replace("-","–")} (router time). Need a change? Ask the admin.`:"Need a change? Ask the admin.")))}function Pt(e){return e.disabled?n("span",{class:"dstat"},"Disabled by the admin"):e.online?n("span",{class:"dstat ok"},"Connected"):e.handshake?n("span",{class:"dstat"},`Last connected ${xe(e.handshake)}`):n("span",{class:"dstat warn"},"Not set up yet")}function rt(e,t){return e.access!=="internet"&&e.state==="active"&&!t.disabled}function Nt(e,t){let r=Ae(e.devices).filter(v=>v.hostname&&rt(e,v));if(!r.length)return null;let i=r[0].hostname,u=i.slice(i.indexOf("."));return n("div",{class:"names"},n("div",{class:"names-head"},n("span",{class:"names-ic"},K("home")),n("div",{class:"stack"},n("span",{class:"strong s"},"Names at home"),n("span",{class:"faint s"},t?"Devices at home and on this VPN reach yours as ":"Other devices at home reach yours as ",n("span",{class:"mono"},`name${u}`)))),n("div",{class:"names-list"},r.map(v=>{let k=v.hostname.indexOf(".");return n("button",{type:"button",class:"name-chip",title:v.name,"aria-label":`Copy ${v.hostname}`,onclick:()=>ce(v.hostname,"Address copied")},n("span",{class:"mono"},k>0?[v.hostname.slice(0,k),n("span",{class:"faint"},v.hostname.slice(k))]:v.hostname),K("copy"))})))}function Rt(e,t){let r=n("button",{type:"button",class:"icon-btn soft","aria-label":`${e.name} options`},K("more"));r.addEventListener("click",B=>{B.stopPropagation(),Dt(r,[{label:"Show QR code",icon:"qr",run:()=>ue(e,"qr")},{label:"Copy AmneziaVPN key",icon:"key",run:()=>Ht(e)},{label:"Download .conf",icon:"download",run:()=>It(e)},null,...rt(t.person,e)?[{label:"Copy IP address",icon:"copy",run:()=>ce(e.address,"IP address copied")},...e.hostname?[{label:"Copy local address",icon:"home",run:()=>ce(e.hostname,"Address copied")}]:[],null]:[],...e.disabled?[]:[{label:"Rename",icon:"edit",run:()=>Kt(e)},{label:"New keys",icon:"reset",run:()=>Ut(e,t)},{label:"Remove",icon:"trash",danger:!0,run:()=>Ft(e)}]])});let i=e.spark.reduce((B,D)=>B+D,0),u=!e.handshake&&!e.disabled,v=!!t.locked,k=t.here===e.id;return n("article",{class:`dcard${e.online?" online":""}${e.disabled?" off":""}${k?" here":""}`},n("div",{class:"dhead"},n("span",{class:"dic"},K(e.kind)),n("div",{class:"stack grow"},n("span",{class:"dname"},e.name),k?n("span",{class:"dstat here"},"This device"):Pt(e)),v?null:r),u&&v?null:u?[n("button",{type:"button",class:"btn primary block",onclick:()=>ue(e)},K(Te()?"open":"qr"),n("span",{},Te()?"Open in AmneziaVPN":"Connect this device"))]:n("div",{class:"duse"},n("div",{class:"stack"},n("span",{class:"faint s"},"Last 7 days"),n("span",{class:"mono"},ie(i))),Lt(e.spark)),e.config_stale&&!u&&!v?n("div",{class:"notice"},K("alert"),n("span",{class:"grow"},"Connection settings changed. Update this device to keep everything working."),n("button",{type:"button",class:"btn small",onclick:()=>ue(e)},"Update")):null)}function fe(e){let t=e.person,r=Me(t.expires,Ee()),i=t.state!=="active"?We(Bt(t),...Et(t)):ke(t,r)?We("warn","calendar",`Your access ${Ke(r)}`,`On ${we(t.expires)}. Ask the admin to extend it.`):null,v=Ae(t.devices).sort((D,$)=>+($.id===e.here)-+(D.id===e.here)).map(D=>Rt(D,e));(e.locked?0:Math.max(0,t.device_limit-t.devices.length))&&v.push(n("button",{type:"button",class:"slot add",onclick:Yt},n("span",{class:"slot-ic"},K("plus")),n("span",{class:"strong"},"Add device")));let B=n("section",{class:"devices","aria-label":"Your devices"},n("div",{class:"card-head"},n("div",{class:"row-baseline"},n("h2",{},"Your devices"))),n("div",{class:"dgrid"},v),e.locked?null:[e.can_add?null:n("span",{class:"faint s"},`You have reached your limit of ${t.device_limit} devices. Remove one or ask the admin for more.`),n("span",{class:"faint s"},"New device? Install ",n("a",{href:"https://amnezia.org/downloads",target:"_blank",rel:"noopener noreferrer"},"AmneziaVPN")," on it first.")]);Se(i,n("div",{class:"hello"},n("span",{class:`avatar${t.online?" online":""}`},Fe(t.name)),n("h1",{},`Hi, ${t.name}`)),n("div",{class:"layout"},St(e),B))}async function Pe(e){try{return await ne(`devices/${e.id}/config`)}catch(t){return te(t.message,!0),null}}async function Ht(e){let t=await Pe(e);t&&ce(await _e(t,`${t.server} · ${t.name}`),"Key copied")}async function It(e){let t=await Pe(e);t&&et(t.filename,t.conf)}function Ze(e,t){if(/^\s*\[.+\]\s*$/.test(e))return n("span",{class:"conf-sec"},e);let r=/^(\s*[A-Za-z0-9]+\s*=)\s*(.*)$/.exec(e);if(!r)return document.createTextNode(e);let i=/^(\s*)(PrivateKey|PresharedKey)\b/.test(e);return n("span",{},n("span",{class:"conf-k"},r[1])," ",i&&!t?n("span",{class:"conf-mask"},"••••••••••••••••"):r[2])}function Ot(e){let t=!1,r=n("pre",{class:"conf"}),i=()=>r.replaceChildren(...e.conf.split(` -`).flatMap((v,k)=>k?[` -`,Ze(v,t)]:[Ze(v,t)])),u=n("button",{class:"btn small",onclick:v=>{v.preventDefault(),t=!t,u.replaceChildren(K(t?"x":"key"),n("span",{},t?"Hide key":"Show key")),i()}},K("key"),n("span",{},"Show key"));return i(),n("div",{class:"pane"},n("div",{class:"filecard"},n("span",{class:"filecard-ic"},".conf"),n("span",{class:"stack"},n("span",{class:"mono ellipsis"},e.filename),n("span",{class:"faint s"},"For computers and routers: import it in AmneziaWG or AmneziaVPN")),n("button",{class:"btn primary",onclick:()=>et(e.filename,e.conf)},K("download"),n("span",{},"Download"))),n("details",{class:"confbox"},n("summary",{},K("chevron"),n("span",{},"Configuration"),n("span",{class:"grow"}),u,n("button",{class:"btn small",onclick:v=>{v.preventDefault(),ce(e.conf,"Configuration copied")}},K("copy"),n("span",{},"Copy"))),r))}async function ue(e,t,r){let i=r!=null?r:await Pe(e);if(!i)return;let u=await _e(i,`${i.server} · ${i.name}`),v=Te(),k={app:()=>n("div",{class:"pane"},n("a",{class:"btn primary block big",href:u},K("open"),n("span",{},"Open in AmneziaVPN")),n("ol",{class:"steps"},n("li",{},"No AmneziaVPN yet? ",n("a",{href:"https://amnezia.org/downloads",target:"_blank",rel:"noopener noreferrer"},"Get it here"),"."),n("li",{},"Tap ",n("b",{},"Open in AmneziaVPN")," and confirm the import."),n("li",{},"Turn the connection on — this page shows ",n("span",{class:"ok"},"Connected")," within a minute."))),qr:()=>{let H=n("div",{class:"qr"});return H.innerHTML=Qe(i.conf),n("div",{class:"pane center"},H,n("p",{class:"muted s"},"Scan with the phone’s camera or AmneziaVPN / AmneziaWG."))},key:()=>n("div",{class:"pane"},n("p",{class:"muted s"},"In AmneziaVPN choose “Add server → Insert key”."),n("div",{class:"keybox"},n("span",{class:"mono"},u),n("button",{class:"btn small",onclick:()=>ce(u,"Key copied")},"Copy")),n("p",{class:"faint s"},"Keep it private: anyone with the key can use your connection.")),file:()=>Ot(i)},B=v?["app","qr","key","file"]:["qr","key","file"],D={app:"Open in app",qr:"QR code",key:"Key",file:"File"},$=n("div",{class:"tab-body"}),q=n("div",{class:"tabs",role:"tablist"}),J=H=>{q.querySelectorAll("button").forEach(re=>re.classList.toggle("on",re.dataset.id===H)),$.replaceChildren(k[H]())};for(let H of B)q.appendChild(n("button",{role:"tab","data-id":H,onclick:()=>J(H)},D[H]));J(t&&B.includes(t)?t:B[0]);let U=n("div",{class:"waiting"}),R=H=>{H!=null&&H.online?U.replaceChildren(n("span",{class:"ok"},`${e.name} is connected`)):H!=null&&H.handshake?U.replaceChildren(n("span",{class:"muted"},`Last connected ${xe(H.handshake)}`)):U.replaceChildren(n("span",{class:"warn"},"Waiting for the first connection…"))};R(e);let F=window.setInterval(async()=>{try{let H=await ne("state");S=H,R(H.person.devices.find(re=>re.id===e.id))}catch{}},5e3);de(e.handshake?`Connect ${e.name}`:`${e.name} is ready`,v?"Add it to AmneziaVPN on this phone":"Scan with the phone’s camera or AmneziaVPN",q,$,U),le=()=>{clearInterval(F),S&&fe(S)}}function Kt(e){let t=n("input",{type:"text",value:e.name,maxlength:48,"aria-label":"Device name"}),r=n("button",{class:"btn primary block",type:"submit"},"Save");de(`Rename ${e.name}`,null,n("form",{class:"stack gap",onsubmit:i=>{i.preventDefault(),$e(r,async()=>{try{S=(await ne(`devices/${e.id}`,{action:"rename",name:t.value})).state,ee(),fe(S),te("Renamed")}catch(u){te(u.message,!0)}})}},t,r)),setTimeout(()=>t.select(),50)}function Ut(e,t){let r=t.here===e.id;de(`New keys for ${e.name}?`,null,n("p",{class:"muted"},r?"This device is connected through the configuration it has now: it disconnects a few seconds after you confirm. Import the new configuration that opens next.":"Its current configuration stops working. Set the device up again with the new one that opens next."),n("div",{class:"row gap"},n("button",{class:"btn block",onclick:()=>ee()},"Cancel"),n("button",{class:"btn primary block",onclick:i=>$e(i.currentTarget,async()=>{try{let u=await ne(`devices/${e.id}`,{action:"rotate"});S=u.state,fe(S),await ue(e,void 0,u.config)}catch(u){te(u.message,!0)}})},"New keys")))}function Ft(e){de(`Remove ${e.name}?`,null,n("p",{class:"muted"},"Its connection stops working immediately. You can add it again later."),n("div",{class:"row gap"},n("button",{class:"btn block",onclick:()=>ee()},"Cancel"),n("button",{class:"btn danger-solid block",onclick:t=>$e(t.currentTarget,async()=>{try{S=(await ne(`devices/${e.id}`,{action:"delete"})).state,ee(),fe(S),te("Device removed")}catch(r){te(r.message,!0)}})},"Remove")))}var V=navigator.userAgent,at=/iPad/.test(V)||/Macintosh/.test(V)&&navigator.maxTouchPoints>1;function Ce(){return at||/Tablet/i.test(V)||/Android/.test(V)&&!/Mobile/.test(V)?"tablet":/Android|iPhone|Mobile/i.test(V)?"phone":"computer"}var Gt=[[/^SM-S93/,"Galaxy S25"],[/^SM-S92/,"Galaxy S24"],[/^SM-S91/,"Galaxy S23"],[/^SM-S90/,"Galaxy S22"],[/^SM-G99/,"Galaxy S21"],[/^SM-F9/,"Galaxy Z Fold"],[/^SM-F7/,"Galaxy Z Flip"],[/^SM-A5/,"Galaxy A5x"],[/^SM-A3/,"Galaxy A3x"],[/^SM-X/,"Galaxy Tab"]],De="",qt=(async()=>{var t;let e=navigator.userAgentData;if(!e||!/Android/.test(V))return"";try{let r=((t=(await e.getHighEntropyValues(["model"])).model)!=null?t:"").trim();if(!r||r==="K")return"";let i=Gt.find(([u])=>u.test(r));De=i?`${i[1]} (${r})`:/^SM-/.test(r)?`Galaxy ${r}`:r}catch{}return De})();function Vt(e){return/iPhone/.test(V)?"iPhone":at?"iPad":/Android/.test(V)?De||(e==="tablet"?"Android tablet":"Android phone"):/CrOS/.test(V)?"Chromebook":/Mac OS X/.test(V)?"Mac":/Windows/.test(V)?"Windows PC":/Linux/.test(V)?"Linux PC":ge[e]}function Yt(){if(!S)return;let e=Ce(),t=new Set(S.person.devices.map(D=>D.name.toLowerCase())),r=D=>{let $=D===Ce()?Vt(D):ge[D];if(!t.has($.toLowerCase()))return $;for(let q=2;q<20;q++)if(!t.has(`${$} ${q}`.toLowerCase()))return`${$} ${q}`;return $},i=n("input",{type:"text",value:r(e),maxlength:48,"aria-label":"Device name",required:!0}),u=!1;i.addEventListener("input",()=>u=!0),qt.then(()=>{!u&&e===Ce()&&(i.value=r(e))});let v=n("div",{class:"kinds"},S.kinds.map(D=>n("button",{type:"button",class:`kind${D===e?" on":""}`,"data-k":D,onclick:()=>{e=D,v.querySelectorAll(".kind").forEach($=>$.classList.toggle("on",$.dataset.k===D)),u||(i.value=r(D))}},K(D),n("span",{},ge[D])))),k=n("p",{class:"err"}),B=n("button",{class:"btn primary block",type:"submit"},"Create connection");de("Add a device",`${S.person.device_limit-S.person.devices.length} of ${S.person.device_limit} slots free`,n("form",{class:"add",onsubmit:async D=>{D.preventDefault(),B.disabled=!0,k.textContent="";try{let $=await ne("devices",{name:i.value.trim(),kind:e});S=$.state;let q=$.state.person.devices.find(J=>J.id===$.id);await ue(q,void 0,$.config)}catch($){k.textContent=$.message,B.disabled=!1}}},n("label",{class:"lbl"},"What is it?"),v,n("label",{class:"lbl"},"Name"),i,k,B))}async function jt(){try{S=await ne("state"),document.title=`${S.person.name} · ${S.title}`,!oe&&!X&&fe(S)}catch(e){let t=e;t.status===404||t.status===401?(S=null,nt()):S||Se(n("div",{class:"card"},n("p",{},t.message)))}}!me||!Tt?nt():jt();})(); +"use strict";(()=>{var ut=Object.create;var Ke=Object.defineProperty;var dt=Object.getOwnPropertyDescriptor;var ft=Object.getOwnPropertyNames;var ht=Object.getPrototypeOf,pt=Object.prototype.hasOwnProperty;var vt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var gt=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of ft(t))!pt.call(e,l)&&l!==r&&Ke(e,l,{get:()=>t[l],enumerable:!(s=dt(t,l))||s.enumerable});return e};var mt=(e,t,r)=>(r=e!=null?ut(ht(e)):{},gt(t||!e||!e.__esModule?Ke(r,"default",{value:e,enumerable:!0}):r,e));var Qe=vt((ze,Je)=>{"use strict";var je=(function(){var e=function(x,k){var b=236,f=17,c=x,y=r[k],i=null,a=0,w=null,h=[],m={},L=function(u,d){a=c*4+17,i=(function(o){for(var p=new Array(o),g=0;g=7&&z(u),w==null&&(w=ct(c,y,h)),Q(w,d)},D=function(u,d){for(var o=-1;o<=7;o+=1)if(!(u+o<=-1||a<=u+o))for(var p=-1;p<=7;p+=1)d+p<=-1||a<=d+p||(0<=o&&o<=6&&(p==0||p==6)||0<=p&&p<=6&&(o==0||o==6)||2<=o&&o<=4&&2<=p&&p<=4?i[u+o][d+p]=!0:i[u+o][d+p]=!1)},S=function(){for(var u=0,d=0,o=0;o<8;o+=1){L(!0,o);var p=l.getLostPoint(m);(o==0||u>p)&&(u=p,d=o)}return d},K=function(){for(var u=8;u>o&1)==1;i[Math.floor(o/3)][o%3+a-8-3]=p}for(var o=0;o<18;o+=1){var p=!u&&(d>>o&1)==1;i[o%3+a-8-3][Math.floor(o/3)]=p}},J=function(u,d){for(var o=y<<3|d,p=l.getBCHTypeInfo(o),g=0;g<15;g+=1){var M=!u&&(p>>g&1)==1;g<6?i[g][8]=M:g<8?i[g+1][8]=M:i[a-15+g][8]=M}for(var g=0;g<15;g+=1){var M=!u&&(p>>g&1)==1;g<8?i[8][a-g-1]=M:g<9?i[8][15-g-1+1]=M:i[8][15-g-1]=M}i[a-8][8]=!u},Q=function(u,d){for(var o=-1,p=a-1,g=7,M=0,C=l.getMaskFunction(d),_=a-1;_>0;_-=2)for(_==6&&(_-=1);;){for(var R=0;R<2;R+=1)if(i[p][_-R]==null){var F=!1;M>>g&1)==1);var T=C(p,_-R);T&&(F=!F),i[p][_-R]=F,g-=1,g==-1&&(M+=1,g=7)}if(p+=o,p<0||a<=p){p-=o,o=-o;break}}},re=function(u,d){for(var o=0,p=0,g=0,M=new Array(d.length),C=new Array(d.length),_=0;_=0?He.getAt(Ie):0}}for(var Oe=0,T=0;T_*8)throw"code length overflow. ("+g.getLengthInBits()+">"+_*8+")";for(g.getLengthInBits()+4<=_*8&&g.put(0,4);g.getLengthInBits()%8!=0;)g.putBit(!1);for(;!(g.getLengthInBits()>=_*8||(g.put(b,8),g.getLengthInBits()>=_*8));)g.put(f,8);return re(g,p)};m.addData=function(u,d){d=d||"Byte";var o=null;switch(d){case"Numeric":o=$(u);break;case"Alphanumeric":o=P(u);break;case"Byte":o=q(u);break;case"Kanji":o=O(u);break;default:throw"mode:"+d}h.push(o),w=null},m.isDark=function(u,d){if(u<0||a<=u||d<0||a<=d)throw u+","+d;return i[u][d]},m.getModuleCount=function(){return a},m.make=function(){if(c<1){for(var u=1;u<40;u++){for(var d=E.getRSBlocks(u,y),o=N(),p=0;p";for(var g=0;g';o+=""}return o+="",o+="",o},m.createSvgTag=function(u,d,o,p){var g={};typeof arguments[0]=="object"&&(g=arguments[0],u=g.cellSize,d=g.margin,o=g.alt,p=g.title),u=u||2,d=typeof d=="undefined"?u*4:d,o=typeof o=="string"?{text:o}:o||{},o.text=o.text||null,o.id=o.text?o.id||"qrcode-description":null,p=typeof p=="string"?{text:p}:p||{},p.text=p.text||null,p.id=p.text?p.id||"qrcode-title":null;var M=m.getModuleCount()*u+d*2,C,_,R,F,T="",Y;for(Y="l"+u+",0 0,"+u+" -"+u+",0 0,-"+u+"z ",T+=''+ae(p.text)+"":"",T+=o.text?''+ae(o.text)+"":"",T+='',T+='":d+=">";break;case"&":d+="&";break;case'"':d+=""";break;default:d+=p;break}}return d},lt=function(u){var d=1;u=typeof u=="undefined"?d*2:u;var o=m.getModuleCount()*d+u*2,p=u,g=o-u,M,C,_,R,F,T={"██":"█","█ ":"▀"," █":"▄"," ":" "},Y={"██":"▀","█ ":"▀"," █":" "," ":" "},j="";for(M=0;M=g?Y[F]:T[F];j+=` +`}return o%2&&u>0?j.substring(0,j.length-o-1)+Array(o+1).join("▀"):j.substring(0,j.length-1)};return m.createASCII=function(u,d){if(u=u||1,u<2)return lt(d);u-=1,d=typeof d=="undefined"?u*2:d;var o=m.getModuleCount()*u+d*2,p=d,g=o-d,M,C,_,R,F=Array(u+1).join("██"),T=Array(u+1).join(" "),Y="",j="";for(M=0;M>>8),y.push(w&255)):y.push(f)}}return y}};var t={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},r={L:1,M:0,Q:3,H:2},s={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},l=(function(){var x=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],k=1335,b=7973,f=21522,c={},y=function(i){for(var a=0;i!=0;)a+=1,i>>>=1;return a};return c.getBCHTypeInfo=function(i){for(var a=i<<10;y(a)-y(k)>=0;)a^=k<=0;)a^=b<5&&(w+=3+L-5)}for(var h=0;h=256;)c-=255;return x[c]},f})();function A(x,k){if(typeof x.length=="undefined")throw x.length+"/"+k;var b=(function(){for(var c=0;c>>7-f%8&1)==1},b.put=function(f,c){for(var y=0;y>>c-y-1&1)==1)},b.getLengthInBits=function(){return k},b.putBit=function(f){var c=Math.floor(k/8);x.length<=c&&x.push(0),f&&(x[c]|=128>>>k%8),k+=1},b},$=function(x){var k=t.MODE_NUMBER,b=x,f={};f.getMode=function(){return k},f.getLength=function(i){return b.length},f.write=function(i){for(var a=b,w=0;w+2>>8&255)*192+(h&255),i.put(h,13),w+=2}if(w>>8)},k.writeBytes=function(b,f,c){f=f||0,c=c||b.length;for(var y=0;y0&&(b+=","),b+=x[f];return b+="]",b},k},I=function(){var x=0,k=0,b=0,f="",c={},y=function(a){f+=String.fromCharCode(i(a&63))},i=function(a){if(!(a<0)){if(a<26)return 65+a;if(a<52)return 97+(a-26);if(a<62)return 48+(a-52);if(a==62)return 43;if(a==63)return 47}throw"n:"+a};return c.writeByte=function(a){for(x=x<<8|a&255,k+=8,b+=1;k>=6;)y(x>>>k-6),k-=6},c.flush=function(){if(k>0&&(y(x<<6-k),x=0,k=0),b%3!=0)for(var a=3-b%3,w=0;w=k.length){if(c==0)return-1;throw"unexpected end of file./"+c}var a=k.charAt(b);if(b+=1,a=="=")return c=0,-1;if(a.match(/^\s$/))continue;f=f<<6|i(a.charCodeAt(0)),c+=6}var w=f>>>c-8&255;return c-=8,w};var i=function(a){if(65<=a&&a<=90)return a-65;if(97<=a&&a<=122)return a-97+26;if(48<=a&&a<=57)return a-48+52;if(a==43)return 62;if(a==47)return 63;throw"c:"+a};return y},Z=function(x,k){var b=x,f=k,c=new Array(x*k),y={};y.setPixel=function(h,m,L){c[m*b+h]=L},y.write=function(h){h.writeString("GIF87a"),h.writeShort(b),h.writeShort(f),h.writeByte(128),h.writeByte(0),h.writeByte(0),h.writeByte(0),h.writeByte(0),h.writeByte(0),h.writeByte(255),h.writeByte(255),h.writeByte(255),h.writeString(","),h.writeShort(0),h.writeShort(0),h.writeShort(b),h.writeShort(f),h.writeByte(0);var m=2,L=a(m);h.writeByte(m);for(var D=0;L.length-D>255;)h.writeByte(255),h.writeBytes(L,D,255),D+=255;h.writeByte(L.length-D),h.writeBytes(L,D,L.length-D),h.writeByte(0),h.writeString(";")};var i=function(h){var m=h,L=0,D=0,S={};return S.write=function(K,G){if(K>>>G)throw"length over";for(;L+G>=8;)m.writeByte(255&(K<>>=8-L,D=0,L=0;D=K<0&&m.writeByte(D)},S},a=function(h){for(var m=1<>6,128|v&63):v<55296||v>=57344?s.push(224|v>>12,128|v>>6&63,128|v&63):(l++,v=65536+((v&1023)<<10|r.charCodeAt(l)&1023),s.push(240|v>>18,128|v>>12&63,128|v>>6&63,128|v&63))}return s}return t(e)}})();(function(e){typeof define=="function"&&define.amd?define([],e):typeof ze=="object"&&(Je.exports=e())})(function(){return je})});function se(e){if(!e||e<0)return"0 B";let t=["B","KB","MB","GB","TB"],r=0,s=e;for(;s>=1024&&r=100||r===0?Math.round(s):s.toFixed(1)} ${t[r]}`}function Me(e,t=Date.now()/1e3){if(!e)return"never";let r=Math.max(0,Math.round(t-e));return r<60?"just now":r<3600?`${Math.floor(r/60)} min ago`:r<86400?`${Math.floor(r/3600)} h ago`:r<86400*30?`${Math.floor(r/86400)} d ago`:new Date(e*1e3).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function pe(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}function ve(e){let[t,r,s]=e.split("-").map(Number);return new Date(t,(r||1)-1,s||1,12)}function yt(e){return(typeof e=="string"?/^\d{4}-\d{2}-\d{2}$/.test(e)?ve(e):new Date(e):e).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function ke(e){return e?yt(e):""}function bt(e,t){let r=s=>{let[l,v,A]=s.split("-").map(Number);return Date.UTC(l,v-1,A)};return Math.round((r(e)-r(t))/864e5)}function Ue(e,t){let r=ve(e);return r.setDate(r.getDate()+t),pe(r)}function Ae(e,t=Date.now()){if(!e)return null;let r=typeof t=="number"?pe(new Date(t)):t,s=bt(e,r);return s>=0?s+1:s}function _e(e,t){return t!=null&&t>0&&e.expire_warn>0&&t<=e.expire_warn}function Fe(e){return e<=1?"ends today":e===2?"ends tomorrow":`ends in ${e} days`}var Ge={lan:"Home network",internet:"Internet",both:"Home network + Internet"};var ge={computer:"PC",phone:"Phone",tablet:"Tablet",router:"Router",other:"Other"};function qe(e){var l,v,A;let t=e.trim().split(/\s+/).filter(Boolean);if(!t.length)return"?";let r=(l=t[0][0])!=null?l:"",s=t.length>1?(v=t[t.length-1][0])!=null?v:"":(A=t[0][1])!=null?A:"";return(r+s).toUpperCase()}function Ce(e){let t=r=>r.disabled?3:r.online?0:r.handshake?1:2;return e.map((r,s)=>[r,s]).sort((r,s)=>t(r[0])-t(s[0])||r[1]-s[1]).map(([r])=>r)}var Ve={phone:'',computer:'',tablet:'',router:'',server:'',other:'',ethernet:'',bridge:'',wifi:'',tunnel:'',plus:'',chart:'',reset:'',package:'',code:'',plug:'',sunrise:'',refresh:'',archive:'',qr:'',copy:'',download:'',link:'',trash:'',edit:'',pause:'',play:'',key:'',out:'',admin:'',shield:'',shieldplus:'',lock:'',zap:'',check:'',alert:'',x:'',globe:'',home:'',open:'',file:'',network:'',moon:'',chevron:'',clock:'',calendar:'',minus:'',more:'',pin:'',activity:''};function Ye(e,t="dl-icon"){var s;let r=(s=Ve[e])!=null?s:Ve.phone;return``}var We=mt(Qe(),1),wt='';function Ze(e,t=3,r=!0){let s=(0,We.default)(0,e.length>300?"Q":"H");s.addData(e,"Byte"),s.make();let l=s.getModuleCount(),v=l+t*2,A=r?Math.round(l*.22):0;A&&(l-A)%2&&A++;let E=(l-A)/2,N=E+A,$=(O,H)=>A>0&&O>=E&&O=E&&H${wt}`}return`${q}`}var xt={jc:"0",jmin:"0",jmax:"0",s1:"0",s2:"0",s3:"0",s4:"0",h1:"1",h2:"2",h3:"3",h4:"4",i1:"",i2:"",i3:"",i4:"",i5:""},Mt={header_protection_key:"HeaderProtectionKey",content_padding_addition:"ContentPaddingAddition",rekey_after_time:"RekeyAfterTime",rekey_timeout:"RekeyTimeout",reject_after_time:"RejectAfterTime",keepalive_timeout:"KeepaliveTimeout",max_handshake_attempts:"MaxHandshakeAttempts",random_trailers:"RandomTrailers",disable_cookies:"DisableCookies"};function kt(e){let t={};for(let[r,s]of Object.entries(Mt))e[r]!=null&&e[r]!==""&&(t[s]=String(e[r]));return t}function At(e,t){var N;let r=e.amnezia,s=(N=r.obfuscation)!=null?N:{},l=$=>s[$]!=null&&s[$]!==""?String(s[$]):xt[$],v=r.host.replace(/^\[(.*)\]$/,"$1"),A={H1:l("h1"),H2:l("h2"),H3:l("h3"),H4:l("h4"),I1:l("i1"),I2:l("i2"),I3:l("i3"),I4:l("i4"),I5:l("i5"),Jc:l("jc"),Jmin:l("jmin"),Jmax:l("jmax"),S1:l("s1"),S2:l("s2"),S3:l("s3"),S4:l("s4"),...kt(s),allowed_ips:r.allowed_ips,client_ip:r.client_ip,client_priv_key:r.client_priv_key,client_pub_key:r.client_pub_key,config:e.conf.replace(/\r?\n/g,`\r +`),hostName:v,mtu:r.mtu,persistent_keep_alive:r.persistent_keep_alive,port:Number(r.port),psk_key:r.psk_key,server_pub_key:r.server_pub_key},E={containers:[{container:"amnezia-awg",awg:{isThirdPartyConfig:!0,last_config:JSON.stringify(A),port:String(r.port),protocol_version:s.header_protection_key?"3.1":"2",transport_proto:"udp"}}],defaultContainer:"amnezia-awg",description:t,hostName:v};return r.dns[0]&&(E.dns1=r.dns[0]),r.dns[1]&&(E.dns2=r.dns[1]),E}function _t(e){let t="";for(let r=0;r{var e;return(e=B==null?void 0:B.today)!=null?e:pe(new Date)};function n(e,t={},...r){let s=document.createElement(e);for(let[v,A]of Object.entries(t))A==null||A===!1||(v.startsWith("on")&&typeof A=="function"?s.addEventListener(v.slice(2),A):v==="class"?s.className=String(A):A===!0?s.setAttribute(v,""):s.setAttribute(v,String(A)));let l=v=>{v==null||v===!1||(Array.isArray(v)?v.forEach(l):s.appendChild(typeof v=="string"?document.createTextNode(v):v))};return r.forEach(l),s}function U(e){let t=n("span",{class:"ic"});return t.innerHTML=Ye(e,"ic-svg"),t}var Tt='',Se=document.getElementById("app"),tt,me=(tt=Se.dataset.base)!=null?tt:"",Lt=Se.dataset.title||"Dawnline",De=()=>window.matchMedia("(max-width: 959px)").matches||/Android|iPhone|iPad/.test(navigator.userAgent),B=null,Dt=/^\/[a-z]{6}-[a-z]{6}-[a-z]{6}$/.test(me)?me.slice(1):"",Ee=class extends Error{constructor(r,s,l){super(s);this.status=r;this.httpsUrl=l}};async function ne(e,t){var l;let r=await fetch(`${me}/api/${e}`,{method:t===void 0?"GET":"POST",credentials:"omit",headers:t===void 0?{}:{"Content-Type":"application/json"},body:t===void 0?void 0:JSON.stringify(t),cache:"no-store"}),s=null;try{s=await r.json()}catch{}if(!r.ok)throw new Ee(r.status,(l=s==null?void 0:s.error)!=null?l:`Request failed (${r.status})`,(s==null?void 0:s.https_url)||void 0);return s}function te(e,t=!1){let r=n("div",{class:`toast${t?" bad":""}`,role:"status"},e);document.body.appendChild(r),requestAnimationFrame(()=>r.classList.add("show")),setTimeout(()=>{r.classList.remove("show"),setTimeout(()=>r.remove(),300)},2600)}async function oe(e,t="Copied"){try{await navigator.clipboard.writeText(e)}catch{let r=n("textarea",{class:"offscreen"},e);document.body.appendChild(r),r.select();let s=document.execCommand("copy");if(r.remove(),!s)return te("Copying is blocked here. Select the text and copy it by hand.",!0)}te(t)}function nt(e,t){let r=URL.createObjectURL(new Blob([t],{type:"application/octet-stream"})),s=n("a",{href:r,download:e,class:"offscreen"});document.body.appendChild(s),s.click(),setTimeout(()=>{URL.revokeObjectURL(r),s.remove()},1e3)}var W=null;function rt(e,t){let r=s=>{W!=null||(W=document.body.appendChild(n("div",{class:"tip"}))),W.replaceChildren(...t().map((l,v)=>n("div",{class:v?"muted":"tip-title"},l))),W.style.display="",W.style.left=`${s.clientX}px`,W.style.top=`${s.clientY-10}px`};e.addEventListener("mouseenter",r),e.addEventListener("mousemove",r),e.addEventListener("mouseleave",()=>W&&(W.style.display="none"))}function Et(e){let t=Math.max(1,...e),r=n("div",{class:"spark"});return e.forEach((s,l)=>{let v=n("i",{class:s?"":"zero"});v.style.height=`${Math.max(8,s/t*100)}%`;let A=e.length-1-l;rt(v,()=>[A===0?"Today":A===1?"Yesterday":ve(Ue($e(),-A)).toLocaleDateString("en-GB",{weekday:"short",day:"numeric",month:"short"}),se(s)]),r.appendChild(v)}),r}async function Pe(e,t){if(!e.disabled){e.disabled=!0;try{await t()}finally{e.disabled=!1}}}var ie=null,ue=null;function ee(e=!1){if(!ie)return;let t=ie;if(ie=null,document.body.classList.remove("locked"),ue==null||ue(),ue=null,e){t.remove();return}t.classList.remove("open"),setTimeout(()=>t.remove(),250)}function ce(e,t,...r){let s=!!ie;ee(!0);let l=n("div",{class:"sheet-panel",role:"dialog","aria-modal":"true","aria-label":e},n("div",{class:"grab"}),n("div",{class:"sheet-head"},n("div",{class:"stack"},n("h2",{},e),t?n("span",{class:"muted s"},t):null),n("button",{class:"icon-btn","aria-label":"Close",onclick:()=>ee()},U("x"))),n("div",{class:"sheet-body"},...r)),v=n("div",{class:"sheet",onclick:A=>{A.target===v&&ee()}},l);return document.body.appendChild(v),document.body.classList.add("locked"),s?v.classList.add("open"):requestAnimationFrame(()=>v.classList.add("open")),ie=v,l}document.addEventListener("keydown",e=>{e.key==="Escape"&&(ye(),ee())});var X=null;function ye(){X==null||X.remove(),X=null}document.addEventListener("click",e=>{X&&!X.contains(e.target)&&ye()});function Bt(e,t){ye();let r=t.filter((A,E)=>A||E>0&&t[E-1]&&t.slice(E+1).some(Boolean)),s=n("div",{class:"menu",role:"menu"},r.map(A=>A?n("button",{type:"button",role:"menuitem",class:`menu-item${A.danger?" danger":""}`,onclick:()=>{ye(),A.run()}},U(A.icon),n("span",{},A.label)):n("div",{class:"menu-sep"})));document.body.appendChild(s);let l=e.getBoundingClientRect(),v=230;s.style.left=`${Math.max(8,Math.min(window.innerWidth-v-8,l.right-v))}px`,s.style.top=`${l.bottom+6+window.scrollY}px`,X=s}function Ne(...e){Se.replaceChildren(n("header",{class:"top"},n("div",{class:"brand"},(()=>{let t=n("span",{class:"logo"});return t.innerHTML=Tt,t})(),n("span",{},(B==null?void 0:B.server.name)||Lt),n("span",{class:"faint"},"· Dawnline"))),n("main",{class:"wrap"},...e))}function at(){Ne(n("div",{class:"card signin"},n("div",{class:"hero-ic"},U("key")),n("h1",{},"This link no longer works"),n("p",{class:"muted"},"Ask for a new personal link.")))}function $t(e){switch(e.state){case"server_off":return["server","The server is turned off","Your devices can’t connect until the admin turns it on again."];case"no_server":return["server","No server yet","Ask the admin to add you to a server."];case"quota":return["chart","You have used all your data","Your devices are paused until it resets."];case"expired":return["calendar","Your access has ended","Ask the admin to extend it."];case"hours":return["clock","Outside your hours",`Access is available ${e.hours.replace("-","–")} (router time).`];default:return["pause","Your access is paused by the admin","Your devices can’t connect until the admin resumes it."]}}function Xe(e,t,r,s){return n("div",{class:"alert"},n("span",{class:`alert-ic ${e}`},U(t)),n("div",{class:"stack"},n("span",{class:"strong"},r),n("span",{class:"muted s"},s)))}function St(e){return e.state==="active"?"ok":e.state==="quota"||e.state==="expired"?"bad":"warn"}var Pt={internet:"The internet, through the router",lan:"Devices at home",both:"Devices at home and the internet, through the router"};function Nt(e){let t=e.person,r=t.quota_limit?Math.min(100,t.quota_used/t.quota_limit*100):0,s=n("div",{class:`meter${r>=100?" bad":r>=90?" warn":""}`},n("i"));s.firstChild.style.width=`${r}%`,t.quota_limit&&rt(s,()=>[`${r.toFixed(1)}% used`,`${se(Math.max(0,t.quota_limit-t.quota_used))} left`]);let l=Ae(t.expires,$e()),v=n("div",{class:"slots"});for(let N=0;N=t.device_limit?"over":N=0?`${l} day${l===1?"":"s"} left`:"ended"):null)),n("span",{class:"faint s"},t.hours?`Available ${t.hours.replace("-","–")} (router time). Need a change? Ask the admin.`:"Need a change? Ask the admin.")))}function Rt(e){return e.disabled?n("span",{class:"dstat"},"Disabled by the admin"):e.online?n("span",{class:"dstat ok"},"Connected"):e.handshake?n("span",{class:"dstat"},`Last connected ${Me(e.handshake)}`):n("span",{class:"dstat warn"},"Not set up yet")}function st(e,t){return e.access!=="internet"&&e.state==="active"&&!t.disabled}function Ht(e,t){let r=Ce(e.devices).filter(v=>v.hostname&&st(e,v));if(!r.length)return null;let s=r[0].hostname,l=s.slice(s.indexOf("."));return n("div",{class:"names"},n("div",{class:"names-head"},n("span",{class:"names-ic"},U("home")),n("div",{class:"stack"},n("span",{class:"strong s"},"Names at home"),n("span",{class:"faint s"},t?"Devices at home and on this VPN reach yours as ":"Other devices at home reach yours as ",n("span",{class:"mono"},`name${l}`)))),n("div",{class:"names-list"},r.map(v=>{let A=v.hostname.indexOf(".");return n("button",{type:"button",class:"name-chip",title:v.name,"aria-label":`Copy ${v.hostname}`,onclick:()=>oe(v.hostname,"Address copied")},n("span",{class:"mono"},A>0?[v.hostname.slice(0,A),n("span",{class:"faint"},v.hostname.slice(A))]:v.hostname),U("copy"))})))}function It(e,t){let r=n("button",{type:"button",class:"icon-btn soft","aria-label":`${e.name} options`},U("more"));r.addEventListener("click",E=>{E.stopPropagation(),Bt(r,[{label:"Show QR code",icon:"qr",run:()=>de(e,"qr")},{label:"Copy AmneziaVPN key",icon:"key",run:()=>Ot(e)},{label:"Download .conf",icon:"download",run:()=>Kt(e)},null,...st(t.person,e)?[{label:"Copy IP address",icon:"copy",run:()=>oe(e.address,"IP address copied")},...e.hostname?[{label:"Copy local address",icon:"home",run:()=>oe(e.hostname,"Address copied")}]:[],null]:[],...e.disabled?[]:[{label:"Rename",icon:"edit",run:()=>Ft(e)},{label:"New keys",icon:"reset",run:()=>Gt(e,t)},{label:"Remove",icon:"trash",danger:!0,run:()=>qt(e)}]])});let s=e.spark.reduce((E,N)=>E+N,0),l=!e.handshake&&!e.disabled,v=!!t.locked,A=t.here===e.id;return n("article",{class:`dcard${e.online?" online":""}${e.disabled?" off":""}${A?" here":""}`},n("div",{class:"dhead"},n("span",{class:"dic"},U(e.kind)),n("div",{class:"stack grow"},n("span",{class:"dname"},e.name),A?n("span",{class:"dstat here"},"This device"):Rt(e)),v?null:r),l&&v?null:l?[n("button",{type:"button",class:"btn primary block",onclick:()=>de(e)},U(De()?"open":"qr"),n("span",{},De()?"Open in AmneziaVPN":"Connect this device"))]:n("div",{class:"duse"},n("div",{class:"stack"},n("span",{class:"faint s"},"Last 7 days"),n("span",{class:"mono"},se(s))),Et(e.spark)),e.config_stale&&!l&&!v?n("div",{class:"notice"},U("alert"),n("span",{class:"grow"},"Connection settings changed. Update this device to keep everything working."),n("button",{type:"button",class:"btn small",onclick:()=>de(e)},"Update")):null)}function fe(e){let t=e.person,r=Ae(t.expires,$e()),s=t.state!=="active"?Xe(St(t),...$t(t)):_e(t,r)?Xe("warn","calendar",`Your access ${Fe(r)}`,`On ${ke(t.expires)}. Ask the admin to extend it.`):null,v=Ce(t.devices).sort((N,$)=>+($.id===e.here)-+(N.id===e.here)).map(N=>It(N,e));(e.locked?0:Math.max(0,t.device_limit-t.devices.length))&&v.push(n("button",{type:"button",class:"slot add",onclick:zt},n("span",{class:"slot-ic"},U("plus")),n("span",{class:"strong"},"Add device")));let E=n("section",{class:"devices","aria-label":"Your devices"},n("div",{class:"card-head"},n("div",{class:"row-baseline"},n("h2",{},"Your devices"))),n("div",{class:"dgrid"},v),e.locked?null:[e.can_add?null:n("span",{class:"faint s"},`You have reached your limit of ${t.device_limit} devices. Remove one or ask the admin for more.`),n("span",{class:"faint s"},"New device? Install ",n("a",{href:"https://amnezia.org/downloads",target:"_blank",rel:"noopener noreferrer"},"AmneziaVPN")," on it first.")]);Ne(s,n("div",{class:"hello"},n("span",{class:`avatar${t.online?" online":""}`},qe(t.name)),n("h1",{},`Hi, ${t.name}`)),n("div",{class:"layout"},Nt(e),E))}function be(e){ce("Open the link securely","Connection settings only travel encrypted",n("div",{class:"stack gap"},n("p",{class:"muted"},"This page is open without encryption. To add or set up a device, open the same link over HTTPS:"),n("a",{class:"btn primary block big",href:e},U("lock"),n("span",{},"Open securely")),n("p",{class:"faint s"},"The browser may warn that the certificate is not trusted: it is this router’s own. Choose to continue (“Advanced” → “Proceed”).")))}var it=()=>(B==null?void 0:B.https_url)||null;async function Re(e){let t=it();if(t)return be(t),null;try{return await ne(`devices/${e.id}/config`)}catch(r){let s=r;return s.httpsUrl?be(s.httpsUrl):te(s.message,!0),null}}async function Ot(e){let t=await Re(e);t&&oe(await Te(t,`${t.server} · ${t.name}`),"Key copied")}async function Kt(e){let t=await Re(e);t&&nt(t.filename,t.conf)}function et(e,t){if(/^\s*\[.+\]\s*$/.test(e))return n("span",{class:"conf-sec"},e);let r=/^(\s*[A-Za-z0-9]+\s*=)\s*(.*)$/.exec(e);if(!r)return document.createTextNode(e);let s=/^(\s*)(PrivateKey|PresharedKey)\b/.test(e);return n("span",{},n("span",{class:"conf-k"},r[1])," ",s&&!t?n("span",{class:"conf-mask"},"••••••••••••••••"):r[2])}function Ut(e){let t=!1,r=n("pre",{class:"conf"}),s=()=>r.replaceChildren(...e.conf.split(` +`).flatMap((v,A)=>A?[` +`,et(v,t)]:[et(v,t)])),l=n("button",{class:"btn small",onclick:v=>{v.preventDefault(),t=!t,l.replaceChildren(U(t?"x":"key"),n("span",{},t?"Hide key":"Show key")),s()}},U("key"),n("span",{},"Show key"));return s(),n("div",{class:"pane"},n("div",{class:"filecard"},n("span",{class:"filecard-ic"},".conf"),n("span",{class:"stack"},n("span",{class:"mono ellipsis"},e.filename),n("span",{class:"faint s"},"For computers and routers: import it in AmneziaWG or AmneziaVPN")),n("button",{class:"btn primary",onclick:()=>nt(e.filename,e.conf)},U("download"),n("span",{},"Download"))),n("details",{class:"confbox"},n("summary",{},U("chevron"),n("span",{},"Configuration"),n("span",{class:"grow"}),l,n("button",{class:"btn small",onclick:v=>{v.preventDefault(),oe(e.conf,"Configuration copied")}},U("copy"),n("span",{},"Copy"))),r))}async function de(e,t,r){let s=r!=null?r:await Re(e);if(!s)return;let l=await Te(s,`${s.server} · ${s.name}`),v=De(),A={app:()=>n("div",{class:"pane"},n("a",{class:"btn primary block big",href:l},U("open"),n("span",{},"Open in AmneziaVPN")),n("ol",{class:"steps"},n("li",{},"No AmneziaVPN yet? ",n("a",{href:"https://amnezia.org/downloads",target:"_blank",rel:"noopener noreferrer"},"Get it here"),"."),n("li",{},"Tap ",n("b",{},"Open in AmneziaVPN")," and confirm the import."),n("li",{},"Turn the connection on — this page shows ",n("span",{class:"ok"},"Connected")," within a minute."))),qr:()=>{let f=n("div",{class:"qr"});return f.innerHTML=Ze(s.conf),n("div",{class:"pane center"},f,n("p",{class:"muted s"},"Scan with the phone’s camera or AmneziaVPN / AmneziaWG."))},key:()=>n("div",{class:"pane"},n("p",{class:"muted s"},"In AmneziaVPN choose “Add server → Insert key”."),n("div",{class:"keybox"},n("span",{class:"mono"},l),n("button",{class:"btn small",onclick:()=>oe(l,"Key copied")},"Copy")),n("p",{class:"faint s"},"Keep it private: anyone with the key can use your connection.")),file:()=>Ut(s)},E=v?["app","qr","key","file"]:["qr","key","file"],N={app:"Open in app",qr:"QR code",key:"Key",file:"File"},$=n("div",{class:"tab-body"}),P=n("div",{class:"tabs",role:"tablist"}),q=f=>{P.querySelectorAll("button").forEach(c=>c.classList.toggle("on",c.dataset.id===f)),$.replaceChildren(A[f]())};for(let f of E)P.appendChild(n("button",{role:"tab","data-id":f,onclick:()=>q(f)},N[f]));q(t&&E.includes(t)?t:E[0]);let O=n("div",{class:"waiting"}),H=f=>{f!=null&&f.online?O.replaceChildren(n("span",{class:"ok"},`${e.name} is connected`)):f!=null&&f.handshake?O.replaceChildren(n("span",{class:"muted"},`Last connected ${Me(f.handshake)}`)):O.replaceChildren(n("span",{class:"warn"},"Waiting for the first connection…"))};H(e);let I=0,le=0,Z=!!e.handshake||e.disabled,we=Date.now(),x=async()=>{if(I=0,!(Z||Date.now()-we>6e5)){if(document.hidden){k();return}try{let f=await ne("state");B=f;let c=f.person.devices.find(y=>y.id===e.id);if(H(c),c!=null&&c.online||c!=null&&c.handshake){Z=!0;return}}catch(f){if(f.status===404||f.status===401){Z=!0;return}}le++,k()}},k=()=>{!Z&&!I&&(I=window.setTimeout(x,le<6?5e3:le<12?15e3:3e4))},b=()=>{!document.hidden&&!Z&&!I&&x()};document.addEventListener("visibilitychange",b),k(),ce(e.handshake?`Connect ${e.name}`:`${e.name} is ready`,v?"Add it to AmneziaVPN on this phone":"Scan with the phone’s camera or AmneziaVPN",P,$,O),ue=()=>{Z=!0,I&&clearTimeout(I),document.removeEventListener("visibilitychange",b),B&&fe(B)}}function Ft(e){let t=n("input",{type:"text",value:e.name,maxlength:48,"aria-label":"Device name"}),r=n("button",{class:"btn primary block",type:"submit"},"Save");ce(`Rename ${e.name}`,null,n("form",{class:"stack gap",onsubmit:s=>{s.preventDefault(),Pe(r,async()=>{try{B=(await ne(`devices/${e.id}`,{action:"rename",name:t.value})).state,ee(),fe(B),te("Renamed")}catch(l){te(l.message,!0)}})}},t,r)),setTimeout(()=>t.select(),50)}function Gt(e,t){let r=t.here===e.id;ce(`New keys for ${e.name}?`,null,n("p",{class:"muted"},r?"This device is connected through the configuration it has now: it disconnects a few seconds after you confirm. Import the new configuration that opens next.":"Its current configuration stops working. Set the device up again with the new one that opens next."),n("div",{class:"row gap"},n("button",{class:"btn block",onclick:()=>ee()},"Cancel"),n("button",{class:"btn primary block",onclick:s=>Pe(s.currentTarget,async()=>{try{let l=await ne(`devices/${e.id}`,{action:"rotate"});B=l.state,fe(B),await de(e,void 0,l.config)}catch(l){te(l.message,!0)}})},"New keys")))}function qt(e){ce(`Remove ${e.name}?`,null,n("p",{class:"muted"},"Its connection stops working immediately. You can add it again later."),n("div",{class:"row gap"},n("button",{class:"btn block",onclick:()=>ee()},"Cancel"),n("button",{class:"btn danger-solid block",onclick:t=>Pe(t.currentTarget,async()=>{try{B=(await ne(`devices/${e.id}`,{action:"delete"})).state,ee(),fe(B),te("Device removed")}catch(r){te(r.message,!0)}})},"Remove")))}var V=navigator.userAgent,ot=/iPad/.test(V)||/Macintosh/.test(V)&&navigator.maxTouchPoints>1;function Le(){return ot||/Tablet/i.test(V)||/Android/.test(V)&&!/Mobile/.test(V)?"tablet":/Android|iPhone|Mobile/i.test(V)?"phone":"computer"}var Vt=[[/^SM-S93/,"Galaxy S25"],[/^SM-S92/,"Galaxy S24"],[/^SM-S91/,"Galaxy S23"],[/^SM-S90/,"Galaxy S22"],[/^SM-G99/,"Galaxy S21"],[/^SM-F9/,"Galaxy Z Fold"],[/^SM-F7/,"Galaxy Z Flip"],[/^SM-A5/,"Galaxy A5x"],[/^SM-A3/,"Galaxy A3x"],[/^SM-X/,"Galaxy Tab"]],Be="",Yt=(async()=>{var t;let e=navigator.userAgentData;if(!e||!/Android/.test(V))return"";try{let r=((t=(await e.getHighEntropyValues(["model"])).model)!=null?t:"").trim();if(!r||r==="K")return"";let s=Vt.find(([l])=>l.test(r));Be=s?`${s[1]} (${r})`:/^SM-/.test(r)?`Galaxy ${r}`:r}catch{}return Be})();function jt(e){return/iPhone/.test(V)?"iPhone":ot?"iPad":/Android/.test(V)?Be||(e==="tablet"?"Android tablet":"Android phone"):/CrOS/.test(V)?"Chromebook":/Mac OS X/.test(V)?"Mac":/Windows/.test(V)?"Windows PC":/Linux/.test(V)?"Linux PC":ge[e]}function zt(){if(!B)return;let e=it();if(e){be(e);return}let t=Le(),r=new Set(B.person.devices.map($=>$.name.toLowerCase())),s=$=>{let P=$===Le()?jt($):ge[$];if(!r.has(P.toLowerCase()))return P;for(let q=2;q<20;q++)if(!r.has(`${P} ${q}`.toLowerCase()))return`${P} ${q}`;return P},l=n("input",{type:"text",value:s(t),maxlength:48,"aria-label":"Device name",required:!0}),v=!1;l.addEventListener("input",()=>v=!0),Yt.then(()=>{!v&&t===Le()&&(l.value=s(t))});let A=n("div",{class:"kinds"},B.kinds.map($=>n("button",{type:"button",class:`kind${$===t?" on":""}`,"data-k":$,onclick:()=>{t=$,A.querySelectorAll(".kind").forEach(P=>P.classList.toggle("on",P.dataset.k===$)),v||(l.value=s($))}},U($),n("span",{},ge[$])))),E=n("p",{class:"err"}),N=n("button",{class:"btn primary block",type:"submit"},"Create connection");ce("Add a device",`${B.person.device_limit-B.person.devices.length} of ${B.person.device_limit} slots free`,n("form",{class:"add",onsubmit:async $=>{$.preventDefault(),N.disabled=!0,E.textContent="";try{let P=await ne("devices",{name:l.value.trim(),kind:t});B=P.state;let q=P.state.person.devices.find(O=>O.id===P.id);await de(q,void 0,P.config)}catch(P){if(P.httpsUrl){be(P.httpsUrl);return}E.textContent=P.message,N.disabled=!1}}},n("label",{class:"lbl"},"What is it?"),A,n("label",{class:"lbl"},"Name"),l,E,N))}async function Jt(){try{B=await ne("state"),document.title=`${B.person.name} · ${B.title}`,!ie&&!X&&fe(B)}catch(e){let t=e;t.status===404||t.status===401?(B=null,at()):B||Ne(n("div",{class:"card"},n("p",{},t.message)))}}!me||!Dt?at():Jt();})(); diff --git a/package/luci-app-dawnline/root/usr/share/dawnline/portal/cgi.uc b/package/luci-app-dawnline/root/usr/share/dawnline/portal/cgi.uc new file mode 100755 index 0000000..885d067 --- /dev/null +++ b/package/luci-app-dawnline/root/usr/share/dawnline/portal/cgi.uc @@ -0,0 +1,22 @@ +#!/usr/bin/ucode +// Dawnline personal portal as a CGI script: the request handling itself is +// dawnline.portal. www/cgi-bin/portal (a shell) runs it for requests shaped +// like a personal link and answers the rest itself. +'use strict'; + +import { stdin } from 'fs'; +import { serve } from 'dawnline.portal'; + +let env = {}; +for (let k in [ 'REQUEST_METHOD', 'REQUEST_URI', 'REMOTE_ADDR', 'HTTPS', 'CONTENT_LENGTH', 'CONTENT_TYPE', + 'HTTP_HOST', 'HTTP_ORIGIN', 'HTTP_USER_AGENT', 'HTTP_ACCEPT', + // The visitor behind Cloudflare (believed only when REMOTE_ADDR is Cloudflare's). + 'HTTP_CF_CONNECTING_IP' ]) + env[k] = getenv(k); + +serve({ + env, + headers: {}, + read: (n) => stdin.read(n), + write: (s) => print(s), +}); diff --git a/package/luci-app-dawnline/root/usr/share/dawnline/portal/www/cgi-bin/portal b/package/luci-app-dawnline/root/usr/share/dawnline/portal/www/cgi-bin/portal index 2a43f36..5ab4f45 100755 --- a/package/luci-app-dawnline/root/usr/share/dawnline/portal/www/cgi-bin/portal +++ b/package/luci-app-dawnline/root/usr/share/dawnline/portal/www/cgi-bin/portal @@ -1,21 +1,49 @@ -#!/usr/bin/ucode -// Dawnline personal portal as a CGI script: the request handling itself is -// dawnline.portal. -'use strict'; +#!/bin/sh +# Dawnline personal portal, the door: uhttpd runs this for every request. +# Anything that is not shaped like a personal link (/[/…]) gets +# the portal's bare answer from here, in a shell that costs nothing, so a +# scanner or a flood on the root never starts ucode (compiling the portal's +# module graph is ~140 ms of CPU). Links go on to the portal itself +# (/usr/share/dawnline/portal/cgi.uc), which judges the code. +# +# The answer here is byte for byte the portal's own not_found(): keep both +# in step (dawnline.portal headers(), SECURITY_HEADERS, not_found()). -import { stdin } from 'fs'; -import { serve } from 'dawnline.portal'; +path="${REQUEST_URI%%\?*}" +w='[a-z][a-z][a-z][a-z][a-z][a-z]' +case "$path" in + /$w-$w-$w|/$w-$w-$w/*) exec /usr/bin/ucode /usr/share/dawnline/portal/cgi.uc ;; +esac -let env = {}; -for (let k in [ 'REQUEST_METHOD', 'REQUEST_URI', 'REMOTE_ADDR', 'HTTPS', 'CONTENT_LENGTH', 'CONTENT_TYPE', - 'HTTP_HOST', 'HTTP_ORIGIN', 'HTTP_USER_AGENT', 'HTTP_ACCEPT', - // The visitor behind Cloudflare (believed only when REMOTE_ADDR is Cloudflare's). - 'HTTP_CF_CONNECTING_IP' ]) - env[k] = getenv(k); +# HSTS pins the whole name: only when the visitor is on the standard port. +hsts= +if [ "$HTTPS" = on ]; then + port="${HTTP_HOST##*:}" + case "$HTTP_HOST" in *:*) ;; *) port=443 ;; esac + case "$HTTP_HOST" in *\]) port=443 ;; esac + [ "$port" = 443 ] && hsts=1 +fi -serve({ - env, - headers: {}, - read: (n) => stdin.read(n), - write: (s) => print(s), -}); +# Files always get the 404: a missing asset must not turn into someone's website. +file= +case "$path" in + /luci-static|/luci-static/*|/cgi-bin|/cgi-bin/*|/ubus|/ubus/*) file=1 ;; + *) case "${path##*/}" in *.*) file=1 ;; esac ;; +esac +redirect= +[ -n "$file" ] || redirect="$(uci -q get dawnline.settings.portal_redirect)" + +if [ -n "$redirect" ]; then + printf 'Status: 302 Found\r\n' + printf 'X-Content-Type-Options: nosniff\r\nReferrer-Policy: no-referrer\r\nX-Frame-Options: DENY\r\nCache-Control: no-store\r\n' + printf 'Location: %s\r\nContent-Type: text/plain\r\n' "$redirect" + [ -n "$hsts" ] && printf 'Strict-Transport-Security: max-age=31536000\r\n' + printf '\r\nMoved\n' +else + printf 'Status: 404 Not Found\r\n' + printf 'X-Content-Type-Options: nosniff\r\nReferrer-Policy: no-referrer\r\nX-Frame-Options: DENY\r\nCache-Control: no-store\r\n' + printf 'Content-Type: text/plain\r\n' + [ -n "$hsts" ] && printf 'Strict-Transport-Security: max-age=31536000\r\n' + printf '\r\nNot found\n' +fi +exit 0 diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/access.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/access.uc index 902875a..ba0173b 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/access.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/access.uc @@ -154,12 +154,20 @@ function from_device(m, d, t, states, dmp, snap) { // The router itself. if (index(router_addrs(snap), t.ip) >= 0) { - if (home_access(p)) - push(steps, step(true, `${t.ip} is this router`, 'Home access includes the router.')); - else if (t.port == 53) + let portal = m.settings.portal_enabled && (t.port == m.settings.portal_port || (core.portal_http(m) && t.port == core.portal_http_port(m))); + if (t.port == 53) push(steps, step(true, `${t.ip} is this router: DNS is open to everyone`, '')); - else - return stop(steps, step(false, `${t.ip} is this router`, `${p.name} has ${ACCESS_TEXT[p.access]}: only DNS on the router.`)); + else if (portal) + push(steps, step(true, `${t.ip} is this router: the personal portal is open to everyone`, '')); + else if (!home_access(p)) + return stop(steps, step(false, `${t.ip} is this router`, `${p.name} has ${ACCESS_TEXT[p.access]}: only DNS and the portal on the router.`)); + else { + // Like any home address: only on the networks the person reaches. + let h = core.person_home(srv, p, snap); + if (!h.all && !in_nets(t.ip, h.nets)) + return stop(steps, step(false, `${t.ip} is this router on a network ${p.name} doesn't reach`, `${p.name} reaches ${join(', ', h.devs) || 'no home network'}.`)); + push(steps, step(true, `${t.ip} is this router`, h.all ? 'Home access includes the router.' : `On one of the networks ${p.name} reaches.`)); + } push(steps, via(t.ip)); return steps; } diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/apply.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/apply.uc index c4f7db4..7ebc842 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/apply.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/apply.uc @@ -82,37 +82,44 @@ export function access_sets(m, usage, states) { return nft.access_sets(m, usage, states); }; -/** Log an access-table failure once per distinct error; true when the table is in place. */ -function nft_result(err) { +/** + * Log an access-table failure once per distinct error (with what it means + * for the devices: none loaded while the table is missing, the previous rules + * kept when an older one survived the failed rebuild); the error, or null. + */ +function nft_result(err, present) { let was = readfile(NFT_ERR); if (err == null) { if (was != null) unlink(NFT_ERR); - return true; + return null; } if (was != err) { - log('Access rules', "couldn't load — devices aren't loaded into the tunnels until they do", 'error', err); + log('Access rules', present + ? "couldn't be updated — the previous rules stay, and changes to access wait until they load" + : "couldn't load — no device is loaded into the tunnels until they do", 'error', err); ensure_dir(RUN_DIR); writefile(NFT_ERR, err); } - return false; + return err; } /** * The table in place: rebuilt with `full`, otherwise members only, rebuilt - * when that fails (no table yet at boot, or an older shape) — an error only - * when the rebuild fails too. + * when that fails (no table yet at boot, or an older shape). Null, or the + * error when the rebuild fails too. */ function load_table(m, sets, full) { let err = full ? nft.rebuild(m, sets) : nft.update(sets); if (err != null && !full) err = nft.rebuild(m, sets); - return nft_result(err); + return nft_result(err, err != null && nft.present()); } -/** Full table rebuild (structure changes: servers, LAN subnets). */ +/** Full table rebuild (structure changes: servers, LAN subnets); true when it loaded. */ export function rebuild_nft(m, sets) { - return nft_result(nft.rebuild(m, sets)); + let err = nft.rebuild(m, sets); + return nft_result(err, err != null && nft.present()) == null; }; /** Atomically replace set contents only. */ @@ -131,32 +138,57 @@ export function firewall_drift(m) { /* ---------- runtime sync ---------- */ +/** + * What an admin should hear when a sync did not fully take: the access table + * failed, or a server did not accept its devices. Null when all went in. + */ +function sync_warning(m, table, peers) { + let out = []; + if (table != null) + push(out, nft.present() + ? `Access rules couldn't be updated (${table}): the previous rules stay, so this change isn't in effect yet.` + : `Access rules couldn't load (${table}): no device is loaded into the tunnels until they do.`); + for (let id, r in peers) + if (r != 'ok' && r != 'down') + push(out, `Couldn't load devices into ${m.servers[id]?.name ?? id}: ${r}.`); + return length(out) ? join(' ', out) + ' Open Diagnostics → Health.' : null; +} + /* - * With the lock held: access sets first, and devices into the tunnels only - * once the table that limits them is in place. + * With the lock held: access sets first, then devices into the tunnels. + * Fail closed: without the table the firewall would let every loaded device + * reach everything, so while it is missing no device is loaded at all. An + * older table that survived a failed rebuild keeps limiting them with the + * sets it has, and the devices still follow people's states (a revoked one + * leaves). */ function locked_sync(m, usage, full) { let states = states_for(m, usage); let sets = nft.access_sets(m, usage, states); - let peers = {}; - if (load_table(m, sets, full)) - peers = awg.sync_peers(m, states); + let table = load_table(m, sets, full); + let peers = awg.sync_peers(m, table == null || nft.present() ? states : {}); sync_hosts(m); ensure_dir(RUN_DIR); write_json(`${RUN_DIR}/states.json`, states, 0o644); - return { peers, states }; + return { peers, states, table, warning: sync_warning(m, table, peers) }; } /** * Runtime sync: devices into the tunnels (AmneziaWG peers), access sets, * hostnames. Cheap; safe to call often. The model is always read again under * the lock (`m` is accepted for older callers and not used); `usage` is the - * caller's (the agent holds the live counters). + * caller's (the agent holds the live counters). The result carries `warning` + * (a sentence for the admin) when the sync did not fully take. */ export function sync(m, usage) { return with_lock('apply', () => locked_sync(core.load(), usage ?? core.load_usage())); }; +/** Is the access table loaded (the agent's tick re-syncs when it is not). */ +export function table_present() { + return nft.present(); +}; + /** * Everything on the router that Dawnline's state is derived from: WAN and * LAN, the home networks and zones of each server, the netns address and the @@ -209,10 +241,10 @@ export function apply(opts) { let s = locked_sync(m, usage, true); ensure_dir(RUN_DIR); write_file(NET_SIG, net_signature(m), 0o644); - return { network, firewall, lp, peers: s.peers }; + return { network, firewall, lp, peers: s.peers, warning: s.warning }; }); loop.remember(r.lp); - return { network: r.network, firewall: r.firewall, like_home: r.lp.error ? { error: r.lp.error } : !r.lp.off, peers: r.peers }; + return { network: r.network, firewall: r.firewall, like_home: r.lp.error ? { error: r.lp.error } : !r.lp.off, peers: r.peers, warning: r.warning }; }; /** Remove everything Dawnline created (used by the uninstaller). */ diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/awg.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/awg.uc index 851b40a..c0d44e2 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/awg.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/awg.uc @@ -6,11 +6,13 @@ import { readfile, stat, unlink } from 'fs'; import { - q, sh, sh_out, rand_int, rand_bytes, valid_key, ensure_dir, write_file, read_json, write_json, lock, unlock, + q, sh, sh_out, rand_int, rand_bytes, valid_key, ip2int, ensure_dir, write_file, read_json, write_json, lock, unlock, slog, iface_status, DATA_DIR, RUN_DIR } from 'dawnline.util'; import * as core from 'dawnline.core'; import * as net from 'dawnline.net'; +import * as pkg from 'dawnline.pkg'; +import * as builds from 'dawnline.awg_builds'; /** Names in .conf files (and AmneziaVPN keys); netifd uses `awg_`. */ export const OBF_CONF = { @@ -132,22 +134,94 @@ function rand_h(used) { } } +// caps() answers from here while the tool, the protocol script and the module file are the same. +const CAPS = `${RUN_DIR}/awg-caps.json`; + /** - * What the installed AmneziaWG can do, from the netifd protocol script (the - * options it passes on) and the `awg` tool (the keys it accepts): + * What the installed AmneziaWG can do: the netifd protocol script (the + * options it passes on) and the `awg` tool (the keys it accepts) say what the + * tools know, the kernel module's package version what the kernel runs, and + * a feature counts only when both have it (tools 3.1 over a 2.0 module would + * configure header protection that the kernel silently lacks): * v2 — S3/S4, I1-I5, header ranges (AWG 1.5/2.0) * v3 — header protection, trailers, padding, timing (AWG 3.1) + * tools / kmod — their generations ('1.0', '2.0', '3.1'; null unknown) + * mismatch — the two differ */ export function caps() { - let script = readfile('/lib/netifd/proto/amneziawg.sh') ?? ''; + let rel = trim(readfile('/proc/sys/kernel/osrelease') ?? ''); + let key = `${stat(`/lib/modules/${rel}/amneziawg.ko`)?.mtime ?? 0}/${stat(TOOL)?.mtime ?? 0}/${stat(PROTO)?.mtime ?? 0}`; + let cached = read_json(CAPS, null); + if (cached?.key == key && cached.caps) + return cached.caps; + let script = readfile(PROTO) ?? ''; let tool = sh_out("grep -a -o -m1 'HeaderProtectionKey' /usr/bin/awg 2>/dev/null") ?? ''; - let v2 = index(script, 'awg_s3') >= 0 && index(script, 'awg_i1') >= 0; - let v3 = v2 && index(script, 'awg_header_protection_key') >= 0 && tool != ''; - return { v2, v3 }; + let t2 = index(script, 'awg_s3') >= 0 && index(script, 'awg_i1') >= 0; + let t3 = t2 && index(script, 'awg_header_protection_key') >= 0 && tool != ''; + let tools = !stat(TOOL) ? null : t3 ? '3.1' : t2 ? '2.0' : '1.0'; + // A module installed by hand has no package: then the tools are believed. + let kmod = builds.gen(pkg.version('kmod-amneziawg')); + let out = { + v2: t2 && (kmod == null || kmod != '1.0'), + v3: t3 && (kmod == null || kmod == '3.1'), + tools, kmod, mismatch: tools != null && kmod != null && tools != kmod, + }; + ensure_dir(RUN_DIR); + write_json(CAPS, { key, caps: out }, 0o644); + return out; }; -/** First junk packet shaped like a DNS answer (AmneziaVPN's own default for 3.1). */ -const DNS_MIMIC = ''; +/** + * Why this AmneziaWG cannot run a server's disguise values, or null: a 3.1 + * preset after a rollback to a 2.0 build would come up without the header + * protection every device expects, so such a server is kept down instead + * (dawnline.netifd). + */ +export function obf_unsupported(o) { + let c = caps(); + let has = (keys) => length(filter(keys, (k) => o?.[k] != null && o[k] != '')) > 0; + let v3 = [ 'header_protection_key', 'content_padding_addition', 'rekey_after_time', 'rekey_timeout', 'reject_after_time', + 'keepalive_timeout', 'max_handshake_attempts', 'random_trailers', 'disable_cookies' ]; + let v2 = [ 's3', 's4', 'i1', 'i2', 'i3', 'i4', 'i5' ]; + let ranged = length(filter([ 'h1', 'h2', 'h3', 'h4' ], (k) => match(`${o?.[k] ?? ''}`, /-/))) > 0; + if (has(v3) && !c.v3) + return `its disguise needs AmneziaWG 3.1 (installed: ${c.kmod ?? c.tools ?? 'none'})`; + if ((has(v2) || ranged) && !c.v2) + return `its disguise needs AmneziaWG 2.0 (installed: ${c.kmod ?? c.tools ?? 'none'})`; + return null; +}; + +/** + * Signature packets shaped like DNS, made fresh for each server: the same + * fixed bytes on every router (AmneziaVPN's own 3.1 default is one constant + * answer about icloud.com) would be one rule for a DPI to match. A query and + * an answer about a name of this server's own, with its own TTL and address. + * random bytes, random letters, fixed bytes + */ +function dns_name_hex() { + let hex = (s) => { + let out = ''; + for (let i = 0; i < length(s); i++) + out += sprintf('%02x', ord(s, i)); + return out; + }; + let tld = [ 'com', 'net', 'org', 'io' ][rand_int(0, 3)]; + let n = rand_int(5, 9); + return { labels: ``, len: n + length(tld) + 2 }; +} + +function dns_query() { + let name = dns_name_hex(); + // id, flags (standard query, recursion desired), 1 question, name, type A, class IN + return `${name.labels}`; +} + +function dns_answer() { + let name = dns_name_hex(); + let ttl = sprintf('%08x', rand_int(300, 86400)); + // id, flags (answer, authoritative, recursion), 1 question, 1 answer, name, A IN, pointer, A IN, ttl, 4 bytes + return `${name.labels}`; +} /** * Generate obfuscation parameters for a method: @@ -164,7 +238,7 @@ export function obf_preset(name) { jc: `${rand_int(4, 6)}`, jmin: '10', jmax: '50', s1: '12', s2: '12', s3: '12', s4: '12', h1: '1', h2: '2', h3: '3', h4: '4', - i1: DNS_MIMIC, + i1: dns_query(), i2: dns_answer(), header_protection_key: sh_out('awg genkey'), content_padding_addition: '10-100', rekey_after_time: '100-120', rekey_timeout: '3-7', reject_after_time: '150-180', @@ -299,8 +373,10 @@ export function client_config(m, dev) { push(lines, `PresharedKey = ${dev.preshared_key}`); push(lines, `AllowedIPs = ${join(', ', allowed)}`); push(lines, `Endpoint = ${ep}:${srv.port}`); + // With 3.1 (its apps take ranges) the keep-alive is jittered like the + // other timers; a fixed beat would be the one regular thing left. if (srv.keepalive > 0) - push(lines, `PersistentKeepalive = ${srv.keepalive}`); + push(lines, `PersistentKeepalive = ${srv.obf.header_protection_key ? `${srv.keepalive}-${srv.keepalive + 10}` : srv.keepalive}`); return { name: dev.name, person: p.name, @@ -361,7 +437,9 @@ export function sync_peers(m, states) { let lines = [ '[Interface]', `PrivateKey = ${srv.private_key}`, `ListenPort = ${srv.port}`, '' ]; for (let did, d in m.devices) { let p = m.people[d.person]; - if (!p || p.server != id || d.disabled || states[p.id] != 'active' || !d.public_key || !d.address) + // One malformed line makes syncconf refuse the whole server: such a device + // stays out (Health's Data check names it). + if (!p || p.server != id || d.disabled || states[p.id] != 'active' || !valid_key(d.public_key) || ip2int(d.address) == null) continue; push(lines, '[Peer]', `PublicKey = ${d.public_key}`); if (d.preshared_key) @@ -381,17 +459,24 @@ export function sync_peers(m, states) { /** * Parse `awg show all dump`. Returns { ok, ifaces: { ifname: {...} }, peers: { pubkey: {...} } }. - * Interface lines have many fields (AmneziaWG adds obfuscation values); peer - * lines always have 9. The tool fails when any one interface can't be read, - * but still prints the others: those are kept and `ok` is false, so only the - * interfaces listed in `ifaces` are known. + * Lines are told apart by their shape, not their length (each AmneziaWG + * generation adds fields to the interface line): an interface line carries + * its private and public key and a port, a peer line the peer's key, a + * preshared key or "(none)" and an endpoint. The tool fails when any one + * interface can't be read, but still prints the others: with `wanted` (the + * ifnames that matter) `ok` means those were all read, so another tunnel's + * trouble is not ours. */ -export function dump() { +export function dump(wanted) { let r = sh('awg show all dump'); let out = { ok: r.code == 0, ifaces: {}, peers: {} }; for (let line in split(r.out, '\n')) { let f = split(line, '\t'); - if (length(f) == 9) { + if (length(f) < 5 || !valid_key(f[1])) + continue; + if (valid_key(f[2]) && match(f[3] ?? '', /^[0-9]+$/)) + out.ifaces[f[0]] = { public_key: f[2], port: +f[3] }; + else if (length(f) >= 9 && (f[2] == '(none)' || valid_key(f[2]))) { let ep = f[3] == '(none)' ? '' : f[3]; out.peers[f[1]] = { ifname: f[0], @@ -401,10 +486,9 @@ export function dump() { tx: +f[7], }; } - else if (length(f) >= 5) { - out.ifaces[f[0]] = { public_key: f[2], port: +f[3] }; - } } + if (!out.ok && type(wanted) == 'array') + out.ok = length(filter(wanted, (n) => !out.ifaces[n])) == 0; return out; }; diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/awg_builds.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/awg_builds.uc index 5e556cc..7ae3a84 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/awg_builds.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/awg_builds.uc @@ -41,9 +41,21 @@ export function for_tag(fw, tag) { return { ...fw, tag, postfix: replace(fw.postfix, fw.tag, tag) }; }; -/** AmneziaWG generation of a tools version: 3.x packages carry 3.1, older ones (1.0.x) 2.0. */ +/** + * AmneziaWG generation of a package version: 3.x packages carry 3.1; 1.0.x + * ones are 2.0 (S3/S4, I1-I5, header ranges) from July 2025 on, and the + * first generation before that. A kernel module's version carries the kernel + * release in front (6.12.94.3.1.20260906): the AmneziaWG part is at the end. + */ export function gen(version) { - return version == null ? null : match(version, /^3\./) ? '3.1' : '2.0'; + if (version == null) + return null; + let v = match(`${version}`, /([0-9]+\.[0-9]+\.[0-9]{8})(-r?[0-9]+)?$/)?.[1] ?? `${version}`; + if (match(v, /^3\./)) + return '3.1'; + if (match(v, /^1\.0\.2024/) || match(v, /^1\.0\.20250[1-6]/)) + return '1.0'; + return '2.0'; }; /** The installed AmneziaWG packages: { name: version | null }. */ diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/backup.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/backup.uc index 21fe38e..4353a67 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/backup.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/backup.uc @@ -3,7 +3,7 @@ // only Dawnline's own regular files, and servers that cannot take over one of // the router's own interfaces or networks. -import { readfile, stat, unlink, lsdir } from 'fs'; +import { readfile, stat, unlink, lsdir, rename } from 'fs'; import { cursor } from 'uci'; import { q, sh, ensure_dir, read_json, write_json, write_file, file_exists, rand_hex, lock, unlock, DATA_DIR, RUN_DIR, VERSION @@ -15,24 +15,36 @@ import * as net from 'dawnline.net'; import * as health from 'dawnline.health'; const BACKUP_DIR = `${DATA_DIR}/backups`; -const KEEP_BACKUPS = 10; +/** + * How many backups of each kind stay (the newest): the nightly ones must not + * push out what the admin made by hand or what a removal left behind. + */ +const KEEP = { manual: 10, auto: 7, 'pre-delete': 5, 'pre-remove': 3, 'pre-update': 3, 'pre-restore': 3, 'pre-import': 3 }; const NAME = /^dawnline-([0-9]{8}-[0-9]{6})(-([a-z0-9-]+))?\.tar\.gz$/; /** What a backup holds (paths inside the archive, relative to /). */ const FILES = [ 'etc/config/dawnline', 'etc/dawnline/usage.json', 'etc/dawnline/events.json' ]; +/** + * Kinds that hold the config alone (about 20 KB): the history can be a + * megabyte or more, and these are made often and never to bring history + * back. Manual, pre-restore and pre-import backups protect the data that is + * about to be replaced, so they take everything. + */ +const CONFIG_ONLY = [ 'auto', 'pre-delete', 'pre-remove', 'pre-update' ]; /** The unpacked size a backup may have (the upload itself is limited to 4 MB). */ const MAX_UNPACKED = 16 * 1024 * 1024; /* ---------- checking a configuration before it is used ---------- */ /** - * What is wrong with the servers of a configuration about to replace the - * current one (cursor `c` holds it): each must have a valid, unique interface + * What is wrong with a configuration about to replace the current one + * (cursor `c` holds it): each server must have a valid, unique interface * name that is not one of the router's own interfaces, a free subnet and a - * unique port. [] when it can be used. + * unique port, and the people and devices must be consistent + * (core.model_errors). [] when it can be used. */ export function config_errors(c) { let m = core.load(c); - let errs = []; + let errs = core.model_errors(m); let nc = cursor(); nc.load('network'); let foreign = health.foreign_subnets(); @@ -92,30 +104,41 @@ export function backup_list() { }; /** - * Make a backup now; returns its name. The oldest beyond KEEP_BACKUPS are - * removed, except `keep` (the backup being restored, which must survive the - * backup made just before restoring it). + * Make a backup now; returns its name. Written whole or not at all (a half + * archive from a full flash never shows up as a backup). Of each kind the + * oldest beyond KEEP are removed, except `keep` (the backup being restored, + * which must survive the backup made just before restoring it). */ export function backup_create(reason, keep) { + let kind = reason && match(reason, /^[a-z0-9-]{1,24}$/) ? reason : 'manual'; + let config_only = index(CONFIG_ONLY, kind) >= 0; // Flush live counters first so the backup has current usage. - let u = read_json(`${RUN_DIR}/usage.json`, null); - if (u) - write_json(`${DATA_DIR}/usage.json`, u, 0o600); - live.persist_events(); + if (!config_only) { + let u = read_json(`${RUN_DIR}/usage.json`, null); + if (u) + write_json(`${DATA_DIR}/usage.json`, u, 0o600); + live.persist_events(); + } ensure_dir(BACKUP_DIR, 0o700); let t = localtime(); - let tag = reason && match(reason, /^[a-z0-9-]{1,24}$/) ? `-${reason}` : ''; - let name = sprintf('dawnline-%04d%02d%02d-%02d%02d%02d%s.tar.gz', t.year, t.mon, t.mday, t.hour, t.min, t.sec, tag); - let files = join(' ', map(filter(FILES, (f) => file_exists(`/${f}`)), q)); - let r = sh(`tar -czf ${q(BACKUP_DIR + '/' + name)} -C / ${files}`); - if (r.code != 0) - die(`Backup failed: ${trim(r.out)}`); + let name = sprintf('dawnline-%04d%02d%02d-%02d%02d%02d%s.tar.gz', t.year, t.mon, t.mday, t.hour, t.min, t.sec, kind == 'manual' ? '' : `-${kind}`); + let want = config_only ? [ FILES[0] ] : FILES; + let files = join(' ', map(filter(want, (f) => file_exists(`/${f}`)), q)); + // Not a NAME until it is complete. + let tmp = `${BACKUP_DIR}/.${name}.tmp`; + let r = sh(`tar -czf ${q(tmp)} -C / ${files}`); + if (r.code != 0 || !rename(tmp, `${BACKUP_DIR}/${name}`)) { + unlink(tmp); + die(`Backup failed: ${trim(r.out) || 'the archive could not be written (is the flash full?)'}`); + } system(`chmod 600 ${q(BACKUP_DIR + '/' + name)}`); - let all = backup_list(); - let old = filter(all, (b) => b.name != keep && b.name != name); - let room = KEEP_BACKUPS - 1 - (length(old) < length(all) - 1 ? 1 : 0); - for (let i = room; i < length(old); i++) - unlink(`${BACKUP_DIR}/${old[i].name}`); + let by_kind = {}; + for (let b in backup_list()) + if (b.name != keep && b.name != name) + push(by_kind[b.reason] ??= [], b); + for (let k, list in by_kind) + for (let i = KEEP[k] ?? 3; i < length(list); i++) + unlink(`${BACKUP_DIR}/${list[i].name}`); return name; }; @@ -155,14 +178,24 @@ function check_archive(path) { die('Backup is too large.'); } -/** Put the files unpacked in `dir` in place, under the config lock. */ +/** + * Put the files unpacked in `dir` in place, under the config lock. The + * config goes first: when it cannot be written nothing else is touched, and + * a data file that fails afterwards is reported, not ignored. + */ function install_files(dir) { ensure_dir(DATA_DIR, 0o700); let l = lock('config'); - for (let f in FILES) { - let data = readfile(`${dir}/${f}`); - if (data != null) - write_file(`/${f}`, data, 0o600); + try { + for (let f in FILES) { + let data = readfile(`${dir}/${f}`); + if (data != null && !write_file(`/${f}`, data, 0o600)) + die(`Couldn't write /${f}. Is the flash full?`); + } + } + catch (e) { + unlock(l); + die(e.message); } unlock(l); system('chmod 600 /etc/config/dawnline'); @@ -185,9 +218,11 @@ export function backup_restore(name, path) { die(e.message); } system(`rm -rf ${q(dir)}`); - // Live counters must follow the restored file. + // Live counters must follow the restored file: the agent reloads them from + // flash on its next tick (its watcher may write the old ones again before). unlink(`${RUN_DIR}/usage.json`); unlink(`${RUN_DIR}/events.json`); + write_file(live.USAGE_RELOAD, `${time()}`, 0o600); return apply.apply(); }; @@ -279,7 +314,9 @@ export function import_json(data) { system(`rm -rf ${q(dir)}`); backup_create('pre-import'); let l = lock('config'); - write_file('/etc/config/dawnline', text, 0o600); + let ok = write_file('/etc/config/dawnline', text, 0o600); unlock(l); + if (!ok) + die("Couldn't write /etc/config/dawnline. Is the flash full?"); return apply.apply(); }; diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/core.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/core.uc index 756b7ec..9fe96ff 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/core.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/core.uc @@ -8,6 +8,7 @@ import { rand_hex, rand_bytes, date_end, month_key, read_json, DATA_DIR, RUN_DIR, uniq } from 'dawnline.util'; import * as net from 'dawnline.net'; +import * as schema from 'dawnline.schema'; import { policy as updates_policy } from 'dawnline.updates'; export const CONFIG = 'dawnline'; @@ -68,28 +69,31 @@ export function open_cursor() { export function load(c) { c ??= open_cursor(); let s = c.get_all(CONFIG, 'settings') ?? {}; + // Types, defaults and ranges of the settings live in dawnline.schema (one + // place): what is read here is what settings_update would have accepted. + let g = (k) => schema.get(s, k); let m = { settings: { - portal_enabled: bool(s.portal_enabled, false), - portal_port: toint(s.portal_port, 8443), - portal_host: s.portal_host ?? '', + portal_enabled: g('portal_enabled'), + portal_port: g('portal_port'), + portal_host: g('portal_host'), // More addresses for the same links (the main one is portal_host). - portal_alt: filter(type(s.portal_alt) == 'array' ? s.portal_alt : s.portal_alt ? [ s.portal_alt ] : [], (x) => x != ''), - portal_cert: s.portal_cert ?? '', - portal_key: s.portal_key ?? '', - portal_title: s.portal_title ?? 'Dawnline', + portal_alt: g('portal_alt'), + portal_cert: g('portal_cert'), + portal_key: g('portal_key'), + portal_title: g('portal_title'), // Where unknown portal links go instead of a bare 404 (empty = 404). - portal_redirect: s.portal_redirect ?? '', - default_device_limit: toint(s.default_device_limit, 3), - geo_enabled: bool(s.geo_enabled, false), - geo_provider: s.geo_provider == 'ipapi.co' ? 'ipapi.co' : 'ipwho.is', - hostnames: bool(s.hostnames, true), - domain: s.domain ?? 'lan', - log_connections: bool(s.log_connections, true), + portal_redirect: g('portal_redirect'), + default_device_limit: g('default_device_limit'), + geo_enabled: g('geo_enabled'), + geo_provider: g('geo_provider'), + hostnames: g('hostnames'), + domain: g('domain'), + log_connections: g('log_connections'), // Repair tunnels and services on its own (the agent, every minute). - watchdog: bool(s.watchdog, true), + watchdog: g('watchdog'), // Second DNS for "home names" devices, used by the device when the tunnel is down. - home_dns_fallback: s.home_dns_fallback == 'none' ? '' : (s.home_dns_fallback ?? '1.1.1.1'), + home_dns_fallback: g('home_dns_fallback'), // Settings → Updates (automatic checks and updates of the components). updates: updates_policy(s), // Raw retention values; dawnline.live policy() interprets them. @@ -158,6 +162,8 @@ export function load(c) { access: index(ACCESS, r.access) >= 0 ? r.access : 'internet', device_limit: toint(r.device_limit, m.settings.default_device_limit), code: r.code ?? '', + // When the personal link was last made (0 for links from before this was kept). + code_set: toint(r.code_set, 0), expires: r.expires ?? '', quota_gb: num(r.quota_gb, 0), quota_period: r.quota_period == 'total' ? 'total' : 'month', @@ -236,23 +242,23 @@ function within_hours(h, ts) { return h[0] < h[1] ? (cur >= h[0] && cur < h[1]) : (cur >= h[0] || cur < h[1]); } -/** Bytes used in the person's quota period. */ -export function person_usage(p, usage) { +/** Bytes used in the person's quota period (the month of `ts`, default now). */ +export function person_usage(p, usage, ts) { let u = usage?.people?.[p.id]; if (!u) return 0; if (p.quota_period == 'total') return (u.total?.[0] ?? 0) + (u.total?.[1] ?? 0); - let mm = u.months?.[month_key()]; + let mm = u.months?.[month_key(ts)]; return mm ? mm[0] + mm[1] : 0; }; -/** Quota in bytes for the current period (base + this month's bonus), 0 = unlimited. */ -export function person_quota(p) { +/** Quota in bytes for the period of `ts` (default now): base + that month's bonus, 0 = unlimited. */ +export function person_quota(p, ts) { if (!(p.quota_gb > 0)) return 0; let gb = p.quota_gb; - if (p.bonus_gb > 0 && p.bonus_month == month_key()) + if (p.bonus_gb > 0 && p.bonus_month == month_key(ts)) gb += p.bonus_gb; return gb * 1073741824; }; @@ -272,8 +278,8 @@ export function own_state(m, p, usage, ts) { // "notify" keeps access after the end date (shown in Overview and People). if (person_expired(p, ts) && p.expire_action != 'notify') return 'expired'; - let quota = person_quota(p); - if (quota > 0 && person_usage(p, usage) >= quota) + let quota = person_quota(p, ts); + if (quota > 0 && person_usage(p, usage, ts) >= quota) return 'quota'; let h = parse_hours(p.hours); if (h && !within_hours(h, ts)) @@ -512,6 +518,7 @@ export function create_person(c, m, a) { c.set(CONFIG, slug, 'access', access); c.set(CONFIG, slug, 'device_limit', `${limit}`); c.set(CONFIG, slug, 'code', new_code()); + c.set(CONFIG, slug, 'code_set', `${time()}`); c.set(CONFIG, slug, 'created', `${time()}`); if (a.expires) c.set(CONFIG, slug, 'expires', a.expires); @@ -750,6 +757,69 @@ export function server_errors(m, srv, others_subnets) { return errs; }; +/** + * What is wrong inside a model as a whole, beyond each server: devices with + * an address outside their server's subnet, the server's own address, a + * prefix on it or one shared with another device (the access sets are keyed + * by address, and one bad peer line makes `awg syncconf` refuse the whole + * server), malformed keys, people and devices pointing at servers, people, + * circles or services that do not exist, and two people with one link. [] when + * it is consistent. Import, restore and Health check it; the runtime sync + * skips what it would reject (dawnline.awg, dawnline.nft). + */ +export function model_errors(m) { + let errs = []; + let codes = {}, addrs = {}; + for (let id, p in m.people) { + let who = `Person ${p.name}`; + if (p.server != '' && !m.servers[p.server]) + push(errs, `${who}: server ${p.server} does not exist.`); + if (p.circle != '' && !m.circles[p.circle]) + push(errs, `${who}: circle ${p.circle} does not exist.`); + for (let sid in p.services) + if (!m.services[sid]) + push(errs, `${who}: home service ${sid} does not exist.`); + if (p.code != '') { + if (codes[p.code]) + push(errs, `${who}: has the same personal link as ${codes[p.code]}.`); + codes[p.code] = p.name; + } + } + for (let id, d in m.devices) { + let p = m.people[d.person]; + let who = `Device ${d.name}${p ? ` of ${p.name}` : ''}`; + if (!p) { + push(errs, `${who}: person ${d.person} does not exist.`); + continue; + } + if (!valid_key(d.public_key)) + push(errs, `${who}: the public key is not a key.`); + if (d.private_key != '' && !valid_key(d.private_key)) + push(errs, `${who}: the private key is not a key.`); + if (d.preshared_key != '' && !valid_key(d.preshared_key)) + push(errs, `${who}: the preshared key is not a key.`); + let n = ip2int(d.address); + if (n == null) { + push(errs, `${who}: address ${d.address || '(none)'} is not a plain IPv4 address.`); + continue; + } + let srv = m.servers[p.server]; + let t = srv ? parse_cidr(srv.subnet) : null; + if (t && (n < t.first || n > t.last)) + push(errs, `${who}: address ${d.address} is outside ${srv.name}'s tunnel ${srv.subnet}.`); + else if (t && n == t.first) + push(errs, `${who}: address ${d.address} is the router's own address on ${srv.name}.`); + let key = `${p.server} ${d.address}`; + if (addrs[key]) + push(errs, `${who}: address ${d.address} is also used by ${addrs[key]}.`); + addrs[key] = who; + } + for (let id, ci in m.circles) + if (!m.servers[ci.server]) + push(errs, `Circle ${ci.name}: server ${ci.server} does not exist.`); + return errs; +}; + /** * Port forwards from `zone` for `proto` that aren't Dawnline's: [{ from, to, name }]. * A forwarded port never reaches the router itself, so nothing here can listen on it. diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/devices.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/devices.uc index 50e5ba3..cc4465c 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/devices.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/devices.uc @@ -42,11 +42,11 @@ export function add(person, name, kind, opts) { opts ??= {}; let by = opts.by ?? 'admin'; let id = store.transact((c, m) => core.create_device(c, m, person, name, kind, { by, keys: awg.new_keys(opts.public_key || null) })); - apply.sync(); + let s = apply.sync(); let m = core.load(); live.add_event({ type: 'device_added', person, device: id, detail: m.devices[id].name, by }); awg.mark_issued(m, id); - return { id, config: awg.client_config(m, m.devices[id]) }; + return { id, config: awg.client_config(m, m.devices[id]), warning: s.warning }; }; /** @@ -89,15 +89,19 @@ export function rotate(id, opts) { }); // 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; if (opts.defer) sh_bg('sleep 3; /usr/bin/dawnline sync'); else - apply.sync(); + s = apply.sync(); let m = core.load(); let d = m.devices[id]; live.add_event({ type: 'device_keys', person: d.person, device: id, detail: d.name, by }); awg.mark_issued(m, id); - return awg.client_config(m, d); + let cfg = awg.client_config(m, d); + if (s?.warning) + cfg.warning = s.warning; + return cfg; }; /** Remove a device. Returns the runtime sync. */ diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/fw.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/fw.uc index 9233a7b..234e8b8 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/fw.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/fw.uc @@ -5,11 +5,12 @@ // named dawnline_* are ever changed. import { readfile, unlink } from 'fs'; -import { q, sh, sh_out, uniq, uci_put, uci_section, ack_config, write_file, RUN_DIR } from 'dawnline.util'; +import { q, sh, sh_out, uniq, in_nets, uci_put, uci_section, ack_config, write_file, RUN_DIR } from 'dawnline.util'; import { cursor } from 'uci'; import * as core from 'dawnline.core'; import * as net from 'dawnline.net'; import * as nft from 'dawnline.nft'; +import * as loop from 'dawnline.loop'; const LOOP_ZONE = 'dl_loop'; /* @@ -42,12 +43,33 @@ export function sync(m, dry) { let snap = net.snapshot(true); let portal_zone = null, want_loop = false; + // Where tunnel DNS is sent (dawnline.nft): into the netns for home names + // while any server runs "like a home device", and to the LAN's DNS for + // everyone else. A server that does not forward to those zones on its own + // gets a rule for port 53 alone. + let any_loop = length(filter(values(m.servers), (s) => s.lan_like && length(core.tunnels(s)))) > 0; + let lan_dns = loop.lan_dns(); + let lan_dns_zone = null; + if (lan_dns) + for (let dev, d in snap.devices) + if (d.zone && in_nets(lan_dns, d.nets ?? [])) + lan_dns_zone ??= d.zone; for (let id, srv in m.servers) { if (!length(core.tunnels(srv))) continue; let z = `dawnline_${id}`; let sn = net.server_net(srv, snap); portal_zone ??= sn.wan.zone; + if (!srv.lan_like && any_loop) + sec(`${z}_loopdns`, 'rule', { + name: `Dawnline-${srv.ifname}-names`, src: srv.ifname, dest: LOOP_ZONE, + proto: 'tcp udp', dest_port: 53, target: 'ACCEPT', + }); + if (lan_dns_zone && lan_dns_zone != srv.ifname && index(sn.zones, lan_dns_zone) < 0) + sec(`${z}_landns`, 'rule', { + name: `Dawnline-${srv.ifname}-dns`, src: srv.ifname, dest: lan_dns_zone, dest_ip: lan_dns, + proto: 'tcp udp', dest_port: 53, target: 'ACCEPT', + }); sec(`${z}_zone`, 'zone', { // Forward within the zone (device to device) is decided by the inet dawnline table. name: srv.ifname, network: [ srv.ifname ], diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/health.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/health.uc index 821fd46..78b2400 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/health.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/health.uc @@ -403,9 +403,16 @@ export function health(m) { let nft_ok = system('nft list table inet dawnline >/dev/null 2>&1') == 0; push(out, check('nft', 'Access rules loaded', nft_ok ? 'ok' : 'error', - nft_ok ? 'Table inet dawnline enforces who may reach LAN and the internet.' : 'Table inet dawnline is missing: access is not enforced.', + nft_ok ? 'Table inet dawnline enforces who may reach LAN and the internet.' + : 'Table inet dawnline is missing: no device is loaded into the tunnels until it is back.', nft_ok ? null : 'apply')); + // A device the sync has to leave out (a merged import, a hand-edited config). + let data = core.model_errors(m); + push(out, check('data', 'People and devices consistent', length(data) ? 'error' : 'ok', + length(data) ? `${join(' ', slice(data, 0, 4))}${length(data) > 4 ? ` (${length(data) - 4} more)` : ''} Such devices are left out of the tunnels: fix or remove them.` + : 'Every device has a key and an address of its own inside its server.')); + let fwc = cursor(); fwc.load('firewall'); diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/live.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/live.uc index a72b29f..9dfdec3 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/live.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/live.uc @@ -11,14 +11,14 @@ import { iface_status as util_iface_status, RUN_DIR, DATA_DIR } from 'dawnline.util'; import * as awg from 'dawnline.awg'; +import * as schema from 'dawnline.schema'; // Online while the WireGuard session lives: it is dropped 180 s after its // handshake, and a device that is there renews it every 2 min (a little slack // for a renewal that needs a retry). One that left goes offline 1-3 min later. export const ONLINE_WINDOW = 190; -const KEEP_DAYS = 62; -const KEEP_MONTHS = 24; -const KEEP_EVENTS = 2000; +/** A restore put other counters on flash: the agent reloads from there (dawnline.backup writes it). */ +export const USAGE_RELOAD = `${RUN_DIR}/usage.reload`; /* ---------- retention policy ---------- */ @@ -38,9 +38,6 @@ export function category_of(type) { return CATEGORY[type] ?? 'problems'; }; -function int_or(v, d) { - return (v == null || v == '' || match(`${v}`, /[^0-9]/)) ? d : +v; -} /** * Log and history retention from /etc/config/dawnline (read fresh, the @@ -62,13 +59,14 @@ export function policy(s) { else if (type(cats) != 'array') cats = split(cats, /[ ,]+/); cats = uniq(filter(map(cats, (x) => x == 'devices' ? 'people' : x), (x) => index(CATEGORIES, x) >= 0)); + // Defaults and ranges come from dawnline.schema, like every other setting. return { - keep_days: int_or(s.log_keep_days, 30), - max: min(max(int_or(s.log_max, KEEP_EVENTS), 100), 20000), + keep_days: schema.get(s, 'log_keep_days'), + max: schema.get(s, 'log_max'), categories: cats, - persist: index([ '10min', 'hourly', 'off' ], s.log_persist) >= 0 ? s.log_persist : 'hourly', - usage_days: min(max(int_or(s.usage_keep_days, KEEP_DAYS), 7), 1830), - usage_months: min(max(int_or(s.usage_keep_months, KEEP_MONTHS), 1), 120), + persist: schema.get(s, 'log_persist'), + usage_days: schema.get(s, 'usage_keep_days'), + usage_months: schema.get(s, 'usage_keep_months'), }; }; @@ -110,7 +108,10 @@ export function presence() { * handshake, rx, tx } }, presence }. See dawnline.awg. */ export function dump(m) { - let d = awg.dump(); + // Only Dawnline's own tunnels decide `ok`: another AmneziaWG interface on + // the router that cannot be read is not our trouble. + let mine = m ? map(filter(values(m.servers), (s) => s.private_key && s.enabled), (s) => s.ifname) : null; + let d = awg.dump(mine); d.presence = presence(); return d; }; @@ -134,8 +135,13 @@ function empty_usage() { return { devices: {}, people: {}, updated: 0, flushed: 0 }; } -export function load_usage() { - let u = read_json(`${RUN_DIR}/usage.json`, null) ?? read_json(`${DATA_DIR}/usage.json`, null) ?? empty_usage(); +/** + * The usage counters: the live copy in RUN_DIR, else what flash holds. With + * `from_flash` only flash counts (a restore put new counters there, and the + * watcher may have written the old live ones again since). + */ +export function load_usage(from_flash) { + let u = (from_flash ? null : read_json(`${RUN_DIR}/usage.json`, null)) ?? read_json(`${DATA_DIR}/usage.json`, null) ?? empty_usage(); // Per-app counters of earlier test builds are not kept. delete u.clients; return u; diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/net.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/net.uc index 6c98871..09776da 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/net.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/net.uc @@ -9,8 +9,8 @@ // lan_device extra interfaces that count as the home network (list) // // Home access is enforced by destination: the networks routed out of the -// chosen interfaces form the nft `lan_nets` set, and the tunnel's firewall -// zone gets a forwarding to each of their zones. +// chosen interfaces form the server's nft `home_` set, and the tunnel's +// firewall zone gets a forwarding to each of their zones. import { readfile, readlink, lsdir, stat } from 'fs'; import { cursor } from 'uci'; diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/netifd.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/netifd.uc index cc32ba6..6e616f5 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/netifd.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/netifd.uc @@ -68,6 +68,15 @@ export function sync(m) { 'Dawnline never changes interfaces it did not create. Choose another interface name for this server.'); continue; } + // A disguise this build cannot run (a 3.1 preset after a rollback to + // 2.0): the kernel would drop those options silently and run a tunnel + // no device can reach. Down, and said so, until the build or the + // disguise is changed. + let why = tools ? awg.obf_unsupported(srv.obf) : null; + if (why) { + block(srv, `is kept down: ${why}`, 'Install that AmneziaWG build in Dawnline → Components, or switch the disguise on the Server page.'); + continue; + } delete srv.blocked; want[ifn] = true; if (!tools) diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/nft.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/nft.uc index e20be78..435bd35 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/nft.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/nft.uc @@ -5,7 +5,7 @@ // changes often (update, one atomic transaction). import { unlink } from 'fs'; -import { sh, ensure_dir, write_file, rand_hex, ip2int, RUN_DIR } from 'dawnline.util'; +import { sh, ensure_dir, write_file, rand_hex, ip2int, uniq, RUN_DIR } from 'dawnline.util'; import * as core from 'dawnline.core'; import * as net from 'dawnline.net'; import * as loop from 'dawnline.loop'; @@ -74,17 +74,33 @@ export function access_sets(m, usage, states) { return sets; }; +// Duplicate members (two devices with one address) would make the whole load fail. function set_elems(arr) { + arr = uniq(arr); return length(arr) ? `elements = { ${join(', ', arr)} }` : ''; } +/** The portal's TCP ports people may reach through the tunnel (never SSH, DNS or LuCI, whatever is stored). */ +function portal_ports(m) { + if (!m.settings.portal_enabled) + return []; + let ok = (p) => p >= 1 && p <= 65535 && index([ 22, 53, 80, 443 ], p) < 0; + let ports = filter([ m.settings.portal_port ], ok); + if (core.portal_http(m) && ok(core.portal_http_port(m))) + push(ports, core.portal_http_port(m)); + return ports; +} + function table(m, sets) { - let ifs = [], lan = [], tun = []; + let ifs = [], tun = []; let dns_addr = loop.client_dns(); if (!ip4(dns_addr)) dns_addr = null; let rt = loop.resolver_target(); let snap = net.snapshot(); + // Each server's home networks are its own: with several servers, "all + // home" on one never reaches the other's networks (set lan_). + let homes = {}; for (let id, srv in m.servers) { // Only valid interface names reach here (core.tunnels): they are written into the rules as strings. let tns = core.tunnels(srv); @@ -93,13 +109,13 @@ function table(m, sets) { push(tun, t.subnet); } if (length(tns)) - push(lan, ...net.server_net(srv, snap).nets); + homes[id] = net.collapse(net.server_net(srv, snap).nets); } - lan = net.collapse(lan); tun = net.collapse(tun); let t = []; push(t, 'table inet dawnline {'); - push(t, ` set lan_nets { type ipv4_addr; flags interval; auto-merge; ${set_elems(lan)} }`); + for (let id, nets in homes) + push(t, ` set home_${id} { type ipv4_addr; flags interval; auto-merge; ${set_elems(nets)} }`); // Tunnel subnets are never "home", even inside a wider route to the LAN. push(t, ` set tun_nets { type ipv4_addr; flags interval; auto-merge; ${set_elems(tun)} }`); push(t, ` set lan_ok { type ipv4_addr; ${set_elems(sets.lan_ok)} }`); @@ -118,15 +134,30 @@ function table(m, sets) { push(t, ' }'); push(t, ' chain guard {'); push(t, ' meta nfproto ipv6 drop'); - push(t, ' ct state established,related accept'); - push(t, ' icmp type echo-request fib daddr type local accept'); + // Every packet is judged by the rules below, not only the first of a + // connection: a change of access cuts open connections too, instead of + // letting a session or a long UDP flow run on for days. Only what has no + // rule of its own passes on its connection: errors and the like, answers + // to the admin's port forwards, and the router's own pings. + push(t, ' ct state related accept'); + push(t, ' ct status dnat accept'); + push(t, ' icmp type { echo-request, echo-reply } fib daddr type local accept'); push(t, ' fib daddr type local meta l4proto { tcp, udp } th dport 53 accept'); - push(t, ' fib daddr type local ip saddr @lan_ok accept'); + let pp = portal_ports(m); + if (length(pp)) + // Their own portal, also with the VPN on (the address may be this router's). + push(t, ` fib daddr type local tcp dport { ${join(', ', pp)} } accept`); + // The router itself is part of home: for everyone with all of it, and for + // people limited to some networks only on the addresses in those. + push(t, ' fib daddr type local ip saddr @lan_all accept'); + push(t, ' fib daddr type local ip saddr . ip daddr @lan_part accept'); push(t, ' fib daddr type local counter drop'); if (dns_addr) // DNS through the netns (it forwards to the LAN's DNS), for everyone. push(t, ` ip daddr ${dns_addr} meta l4proto { tcp, udp } th dport 53 accept`); - push(t, ' ip daddr @lan_nets ip daddr != @tun_nets ip saddr @lan_all accept'); + for (let id, nets in homes) + for (let tn in core.tunnels(m.servers[id])) + push(t, ` iifname "${tn.ifname}" ip daddr @home_${id} ip daddr != @tun_nets ip saddr @lan_all accept`); push(t, ' ip saddr . ip daddr @lan_part ip daddr != @tun_nets accept'); // Devices with home access are part of home: they reach each other, where the // server allows it (everyone, or within circles). Within one server: the @@ -155,7 +186,9 @@ function table(m, sets) { push(t, ' chain to_device {'); push(t, ' meta nfproto ipv6 drop'); push(t, ' ct status dnat accept'); - push(t, ' ip saddr @lan_nets ip saddr != @tun_nets ip daddr @lan_all accept'); + for (let id, nets in homes) + for (let tn in core.tunnels(m.servers[id])) + push(t, ` oifname "${tn.ifname}" ip saddr @home_${id} ip saddr != @tun_nets ip daddr @lan_all accept`); push(t, ' ip daddr . ip saddr @lan_part ip saddr != @tun_nets accept'); push(t, ' counter reject with icmpx admin-prohibited'); push(t, ' }'); @@ -195,6 +228,11 @@ export function load(script) { return replace(trim(r.out), f, 'rules') || `nft exited with ${r.code}`; }; +/** The table as text, for a check (`nft -c -f`) or a test; nothing is loaded. */ +export function render(m, sets) { + return table(m, sets); +}; + /** 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)); @@ -208,9 +246,10 @@ export function rebuild(m, sets) { export function update(sets) { let s = ''; for (let name in SETS) { + let members = uniq(sets[name]); s += `flush set inet dawnline ${name}\n`; - if (length(sets[name])) - s += `add element inet dawnline ${name} { ${join(', ', sets[name])} }\n`; + if (length(members)) + s += `add element inet dawnline ${name} { ${join(', ', members)} }\n`; } return load(s); }; diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/pkg.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/pkg.uc index 41c8eac..da2f56d 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/pkg.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/pkg.uc @@ -2,7 +2,7 @@ // OpenWrt 24.10, apk on 25.12. Commands that change packages take a log(line) // callback, which gets their output line by line. -import { access, popen } from 'fs'; +import { access, popen, stat } from 'fs'; import { q } from 'dawnline.util'; function run(cmd) { @@ -79,20 +79,56 @@ export function refresh(log) { return logged(is_apk() ? 'apk update' : 'opkg update', log).code == 0; }; +/** Free space on the overlay in KB (null when unknown). */ +function overlay_free_kb() { + let out = run('df -Pk /overlay 2>/dev/null || df -Pk / 2>/dev/null').out; + let m = match(out, /\n\S+\s+[0-9]+\s+[0-9]+\s+([0-9]+)\s/); + return m ? +m[1] : null; +} + +/** + * Room for `files` (or `need_kb` from the feeds): the package manager + * unpacks before it removes, so a full flash leaves half an install behind. + * Dies with the numbers. + */ +function preflight(files, need_kb, log) { + let free = overlay_free_kb(); + if (free == null) + return; + let need = need_kb ?? 512; + for (let f in files ?? []) + need += int(((stat(f)?.size ?? 0) * 3) / 1024); + if (free < need) + die(`Not enough free space on the router: ${int(free / 1024)} MB free, about ${int(need / 1024) + 1} MB needed. Remove old backups or packages first`); + log?.(` ${int(free / 1024)} MB free on the overlay`); +} + /** Package files (from a release): force also reinstalls the same version or goes back to an older one. */ export function install_files(files, force, log) { + preflight(files, 0, log); let args = join(' ', map(files, q)); - return logged(is_apk() - ? `apk add --allow-untrusted ${args}` - : `opkg install ${force ? '--force-reinstall --force-downgrade ' : ''}${args}`, log).code == 0; + if (!is_apk()) + return logged(`opkg install ${force ? '--force-reinstall --force-downgrade ' : ''}${args}`, log).code == 0; + // apk leaves an installed version alone, whatever the file: a reinstall + // that changed nothing is a failure, not a silent "done". + let marker = '/usr/share/ucode/dawnline/util.uc'; + let before = force ? stat(marker)?.mtime : null; + let ok = logged(`apk add --allow-untrusted ${args}`, log).code == 0; + if (ok && force && before != null && stat(marker)?.mtime == before) { + log?.(' apk did not reinstall the version that is already installed'); + die("apk doesn't reinstall an installed version. Install a different release, or run install.sh on the router"); + } + return ok; }; /** Packages by name from the feeds. */ export function add(names, log) { + preflight(null, 2048, log); return logged(is_apk() ? `apk add ${join(' ', map(names, q))}` : `opkg install ${join(' ', map(names, q))}`, log).code == 0; }; export function upgrade(names, log) { + preflight(null, 2048, log); return logged(is_apk() ? `apk upgrade ${join(' ', map(names, q))}` : `opkg upgrade ${join(' ', map(names, q))}`, log).code == 0; }; @@ -105,7 +141,9 @@ export function upgradable() { let up = {}; if (is_apk()) { for (let line in split(run('apk version -l "<"').out, '\n')) { - let m = match(line, /^(\S+?)-([0-9][^ ]*)\s+<\s+(\S+)/); + // "name-version-rN < newer": the version is what follows the last dash + // before the release suffix (a name may hold digits, a version no dash). + let m = match(line, /^(\S+)-([^- ]+-r[0-9]+)\s+<\s+(\S+)/); if (m) up[m[1]] = m[3]; } diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/portal.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/portal.uc index cae4302..207ec25 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/portal.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/portal.uc @@ -19,8 +19,14 @@ // other sites' logs. The portal can only manage the person's own devices // within their limits, and not those the admin turned off (dawnline.devices). // +// Changes through a link are limited too (a link is not a terminal: a few +// dozen every quarter hour), and the configurations themselves (keys, the +// disguise) only go over HTTPS: a plain-HTTP link (an IP address in Settings) +// shows the page, but gets them from its HTTPS twin. +// // handle() serves one request: `io` = { env, headers, read(n), write(s) }; the -// CGI script (www/cgi-bin/portal) is its wrapper. +// CGI script (cgi.uc) is its wrapper, behind the shell door www/cgi-bin/portal +// 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'; @@ -41,6 +47,8 @@ const SHARED_LIMIT = FAIL_LIMIT * 25; const SHARED_KEY = 'cloudflare'; // Clients remembered at most (the oldest go first). const RATE_MAX = 2000; +// Changes one link may make within FAIL_WINDOW (each one writes flash and syncs the tunnels). +const ACTION_LIMIT = 40; const BODY_MAX = 8192; // The early end of a request (a response was written). const DONE = '__dawnline_done__'; @@ -216,6 +224,21 @@ function rate_fail(r) { live.add_event({ type: 'portal_blocked', detail: k == SHARED_KEY ? 'all Cloudflare visitors' : k }); } +/** One more change through this link; refused beyond ACTION_LIMIT per window. */ +function rate_action(r) { + let key = `act:${r.person.id}`; + let l = lock('portal-rate'); + let st = rate_state(); + let v = st[key] ?? { first: time(), count: 0 }; + v.count++; + st[key] = v; + ensure_dir(RUN_DIR); + write_json(RATE, st, 0o600); + unlock(l); + if (v.count > ACTION_LIMIT) + fail(r, '429 Too Many Requests', 'Too many changes in a short time. Try again in a few minutes.'); +} + /* ---------- pages ---------- */ /** The app shell; it reads the code from its own URL and sends it along. */ @@ -295,6 +318,26 @@ function need_open(r) { fail(r, '403 Forbidden', why); } +/** The same link over HTTPS (for a plain-HTTP visitor), or null when this is it. */ +function https_url(r) { + if (r.https) + return null; + let host = r.host; + let h = match(host, /^\[/) ? match(host, /^(\[[^\]]*\])/)?.[1] : split(host, ':')[0]; + let port = r.m.settings.portal_port; + return `https://${h}${port == 443 ? '' : `:${port}`}${r.base}`; +} + +/** + * Keys and the disguise never travel in the clear: over plain HTTP a + * configuration is refused, and the answer names the HTTPS link to use. + */ +function need_https(r) { + let u = https_url(r); + if (u) + send_json(r, '403 Forbidden', { error: 'Open this link over HTTPS to get the connection settings.', https_url: u }); +} + /** Everything the page shows. */ function state(r) { let m = r.m, person = r.person; @@ -318,6 +361,8 @@ function state(r) { }, can_add: length(person.devices) < person.device_limit, locked: LOCKED[v.state] != null, + // Over plain HTTP: where the configurations are (keys only travel encrypted). + https_url: https_url(r), kinds: core.KINDS, // The router's day: access ends and usage days follow its clock, not the browser's. today: today(), @@ -339,9 +384,11 @@ function api_state(r) { function api_add(r) { need_open(r); + need_https(r); let b = body(r); if (!devices.ready()) fail(r, '503 Service Unavailable', NOT_READY); + rate_action(r); let res = guard(r, () => devices.add(r.person.id, b.name, b.kind, { by: 'portal', public_key: b.public_key })); reload(r); send_json(r, '200 OK', { id: res.id, config: res.config, state: state(r) }); @@ -350,6 +397,7 @@ function api_add(r) { function api_config(r, id) { let d = own_device(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)); } @@ -361,6 +409,7 @@ const ACTIONS = { return {}; }, rotate: (r, d, b) => { + need_https(r); if (!devices.ready()) fail(r, '503 Service Unavailable', NOT_READY); let config = guard(r, () => devices.rotate(d.id, { by: 'portal', person: r.person.id, defer: d.address == r.peer })); @@ -379,6 +428,7 @@ function api_device(r, id) { let act = ACTIONS[b.action]; if (!act) fail(r, '400 Bad Request', 'Unknown action.'); + rate_action(r); let res = act(r, d, b); reload(r); send_json(r, '200 OK', { ok: true, ...res, state: state(r) }); @@ -425,7 +475,7 @@ export function handle(io) { let host = header('host') ?? ''; let m = core.load(); let r = { - io, env, m, path, https, + io, env, m, path, https, host, method: env.REQUEST_METHOD ?? 'GET', peer: env.REMOTE_ADDR ?? '', buckets: buckets(env), diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/rpc/home.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/rpc/home.uc index 87c2f93..06cc37a 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/rpc/home.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/rpc/home.uc @@ -54,8 +54,8 @@ function service_set(a) { c.delete(core.CONFIG, id, 'port'); return id; }); - apply.sync(); - return { id }; + let s = apply.sync(); + return { id, warning: s.warning }; } function service_delete(a) { @@ -72,8 +72,8 @@ function service_delete(a) { c.delete(core.CONFIG, pid, 'service'); } }); - apply.sync(); - return { ok: true }; + let s = apply.sync(); + return { ok: true, warning: s.warning }; } /* ---------- circles ---------- */ @@ -112,9 +112,9 @@ function circle_set(a) { } return { id, edit: !!ci, server: m.servers[server].name }; }); - apply.sync(); + let s = apply.sync(); admin_log('awg', res.edit ? 'changed' : 'added', 'circle', name, res.server); - return { id: res.id, circles: values(core.load().circles) }; + return { id: res.id, circles: values(core.load().circles), warning: s.warning }; } function circle_delete(a) { @@ -128,9 +128,9 @@ function circle_delete(a) { c.delete(core.CONFIG, pid, 'circle'); return { name: ci.name, server: m.servers[ci.server]?.name }; }); - apply.sync(); + let s = apply.sync(); admin_log('awg', 'removed', 'circle', res.name, res.server); - return { circles: values(core.load().circles) }; + return { circles: values(core.load().circles), warning: s.warning }; } /* ---------- devices at home ---------- */ diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/rpc/people.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/rpc/people.uc index 9dcd0e6..5bf55f6 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/rpc/people.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/rpc/people.uc @@ -48,10 +48,10 @@ function person_update(a) { if (changes) live.add_event_merged({ type: 'person_changed', person: a.id, detail: changes, by: 'admin' }, 120); // Access changes affect the nft sets and client AllowedIPs. - apply.sync(); + let s = apply.sync(); let m = core.load(); let u = core.load_usage(); - return { person: view.person_view(m, m.people[a.id], u, live.dump(m), view.states(m, u), { admin: true }), was: before?.access }; + return { person: view.person_view(m, m.people[a.id], u, live.dump(m), view.states(m, u), { admin: true }), was: before?.access, warning: s.warning }; } function person_pause(a) { @@ -67,16 +67,34 @@ function person_pause(a) { return apply.sync(); } -/** A new personal link: the old one stops working at once (every portal request carries the code). */ +/** + * A new personal link: the old one stops working at once (every portal + * request carries the code). What the old link already handed out stays + * unless asked: `remove` lists the person's devices to take away with it. + */ function person_regen(a) { - store.transact((c, m) => { + let gone = store.transact((c, m) => { if (!m.people[a.id]) die('Unknown person.'); c.set(core.CONFIG, a.id, 'code', core.new_code()); + c.set(core.CONFIG, a.id, 'code_set', `${time()}`); + let gone = []; + for (let id in (type(a.remove) == 'array' ? a.remove : [])) + if (m.devices[id]?.person == a.id) { + push(gone, m.devices[id]); + core.delete_device(c, m, id); + } + return gone; }); live.add_event({ type: 'link_changed', person: a.id, by: 'admin' }); + let s = null; + if (length(gone)) { + for (let d in gone) + live.add_event({ type: 'device_removed', person: a.id, device: d.id, detail: d.name, dname: d.name, dkind: d.kind, by: 'admin' }); + s = apply.sync(); + } let m = core.load(); - return { link: core.portal_url(m, m.people[a.id]) }; + return { link: core.portal_url(m, m.people[a.id]), removed: length(gone), warning: s?.warning }; } /** The personal code and links (Copy link, QR, invite): admins only, unlike status. */ @@ -142,7 +160,7 @@ export const methods = { call: wrap(person_update), }, person_pause: { args: { id: '', paused: false }, call: wrap(person_pause) }, - person_regen: { args: { id: '' }, call: wrap(person_regen) }, + person_regen: { args: { id: '', remove: [] }, call: wrap(person_regen) }, person_links: { args: { id: '' }, call: wrap(person_links) }, person_delete: { args: { id: '' }, call: wrap(person_delete) }, person_usage: { args: { id: '', days: 30 }, call: wrap(person_usage) }, diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/rpc/servers.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/rpc/servers.uc index af60798..c4199ab 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/rpc/servers.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/rpc/servers.uc @@ -312,7 +312,7 @@ function server_create(a) { // after that (by hand, or by an older installer) needs a network restart. let network_restart = !awg.state().handler; sh_bg(network_restart ? '/etc/init.d/network restart; /etc/init.d/dawnline restart' : '/etc/init.d/dawnline restart'); - return { id, applied: r, network_restart }; + return { id, applied: r, network_restart, warning: r.warning }; } /* ---------- interfaces ---------- */ diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/rpc/settings.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/rpc/settings.uc index 2a66420..1fe72d2 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/rpc/settings.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/rpc/settings.uc @@ -115,10 +115,11 @@ function settings_update(a) { check_portal(core.load(c), m); return { restart, was: m.settings }; }); + let s = null; if (res.restart) system('/etc/init.d/dawnline reload >/dev/null 2>&1'); else - apply.sync(); + s = apply.sync(); // The changes worth a line: the portal and the watchdog (other settings are housekeeping). let now = core.load().settings, was = res.was; if (now.portal_enabled != was.portal_enabled) @@ -140,7 +141,10 @@ function settings_update(a) { } if (now.watchdog != was.watchdog) admin_log('dawnline', now.watchdog ? 'turned on' : 'turned off', null, 'the watchdog', now.watchdog ? null : 'problems are only logged, nothing is repaired'); - return settings_get({}); + let out = settings_get({}); + if (s?.warning) + out.warning = s.warning; + return out; } export const methods = { diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/store.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/store.uc index cd2906d..13c4f55 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/store.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/store.uc @@ -9,9 +9,14 @@ import * as core from 'dawnline.core'; /** Section names that are never ids of people, devices, servers, services or circles. */ export const RESERVED_IDS = [ 'settings', 'main', 'global', 'defaults' ]; -/** Commit the dawnline config and keep it readable by root only. */ +/** + * Commit the dawnline config and keep it readable by root only. A commit + * that did not reach flash (full or read-only overlay) is an error: the + * caller's change never happened, and nothing downstream may act on it. + */ export function commit(c) { - c.commit(core.CONFIG); + if (!c.commit(core.CONFIG)) + die(`Couldn't save /etc/config/dawnline: ${c.error() ?? 'the write failed'}. Is the flash full?`); system('chmod 600 /etc/config/dawnline'); }; diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/upd_app.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/upd_app.uc index 552cdbc..1ead852 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/upd_app.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/upd_app.uc @@ -115,8 +115,11 @@ export function install(ctx, arg) { out.to = replace(tag, /^v/, ''); ctx.versions(VERSION, out.to); let f = fetch(ctx, tag, ctx.work); - // The version being replaced, for Roll back (downloaded again: opkg keeps no package files). - if (ctx.pol.keep && out.to != VERSION && upd.kept('app')?.version != VERSION) { + // The version being replaced, for Roll back (downloaded again: opkg keeps + // no package files). Always for an automatic run: nobody is there to + // recover a router whose new version does not come up (postupdate rolls + // back to it on its own). + if ((ctx.pol.keep || ctx.auto?.()) && out.to != VERSION && upd.kept('app')?.version != VERSION) { ctx.phase(`Keeping Dawnline ${VERSION} for rollback`); try { system(`mkdir -p '${ctx.work}/keep'`); diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/upd_awg.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/upd_awg.uc index 01c7d86..061756c 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/upd_awg.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/upd_awg.uc @@ -114,8 +114,14 @@ function reload_module(ctx, before, after) { iface_intent(i, 'update', c.get('network', i, '_dawnline_name') ?? i); sh(`ifdown '${i}'`); } - sh('rmmod amneziawg'); + // Both steps must really happen: the new tools against the old module (or + // no module at all) leave every tunnel down while the job says "done". + ctx.run('rmmod amneziawg'); + if (stat('/sys/module/amneziawg')) + die('The old AmneziaWG kernel module is still loaded (another AmneziaWG interface may use it): reboot the router to finish the update'); ctx.run('modprobe amneziawg'); + if (!stat('/sys/module/amneziawg')) + die("The new AmneziaWG kernel module doesn't load on this firmware: the tunnels stay down until it does (see the log above)"); for (let i in ifaces) sh(`ifup '${i}'`); } diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/util.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/util.uc index 1d9bb59..0ab2bd8 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/util.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/util.uc @@ -4,7 +4,7 @@ import { open, readfile, writefile, rename, mkdir, stat, unlink, popen, lsdir } from 'fs'; -export const VERSION = '0.5.2'; +export const VERSION = '0.6.0'; /** GitHub repository with Dawnline releases (updates and the installer). */ export const REPO = 'tickcount/luci-app-dawnline'; export const RUN_DIR = '/var/run/dawnline'; diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/view.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/view.uc index 2223093..76b9d8a 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/view.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/view.uc @@ -96,6 +96,7 @@ export function person_view(m, p, usage, dmp, states, opts) { v.home_nets = p.home_nets; v.circle = p.circle; v.created = p.created; + v.code_set = p.code_set; } return v; }; diff --git a/rules/backend.md b/rules/backend.md index e9e1b4e..ae75a82 100644 --- a/rules/backend.md +++ b/rules/backend.md @@ -27,4 +27,5 @@ Read with `code-standards.md`. Everything here runs on a small router (2 × Cort ## Checks -- `scripts/lint-ucode.py` and `scripts/check-ucode.sh` (compiles on the router) pass before any deploy; new directories and entry points are added to both, and executables to the mode check in `.github/workflows/ci.yml`. +- `scripts/lint-ucode.py` and `scripts/ucode-container.sh` (compiles and runs `tests/ucode` in the OpenWrt rootfs containers; `scripts/check-ucode.sh` compiles on the router instead) pass before any deploy; new directories and entry points are added to `lint-ucode.py` and `scripts/compile-ucode.sh`, and executables to the mode check in `.github/workflows/ci.yml`. +- Pure functions get a case in `tests/ucode/.test.uc`; what reads the clock takes an optional `ts` so a test can pass one. diff --git a/scripts/build-release.sh b/scripts/build-release.sh index 3d6c49f..6e47dc8 100755 --- a/scripts/build-release.sh +++ b/scripts/build-release.sh @@ -19,9 +19,9 @@ grep -q "\"version\": \"$VERSION\"" "$ROOT/web/package.json" || { echo "web/pack mkdir -p "$STAGE/www" "$OUT" cp -R "$APP/root/." "$STAGE/" cp -R "$APP/htdocs/." "$STAGE/www/" -chmod 755 "$STAGE/usr/bin/dawnline" "$STAGE/usr/libexec/dawnline/agent" "$STAGE/usr/libexec/dawnline/updater" "$STAGE/usr/libexec/dawnline/resolver" \ +chmod 755 "$STAGE/usr/bin/dawnline" "$STAGE/usr/libexec/dawnline/agent" "$STAGE/usr/libexec/dawnline/updater" "$STAGE/usr/libexec/dawnline/resolver" "$STAGE/usr/libexec/dawnline/postupdate" \ "$STAGE/etc/init.d/dawnline" "$STAGE/etc/uci-defaults/90_dawnline" "$STAGE/etc/hotplug.d/iface/95-dawnline" \ - "$STAGE/usr/share/dawnline/portal/www/cgi-bin/portal" + "$STAGE/usr/share/dawnline/portal/www/cgi-bin/portal" "$STAGE/usr/share/dawnline/portal/cgi.uc" find "$STAGE" -name '.DS_Store' -delete TAR="$OUT/luci-app-dawnline-$VERSION.tar.gz" diff --git a/scripts/check-ucode.sh b/scripts/check-ucode.sh index 9fc3a24..ac1ab3c 100755 --- a/scripts/check-ucode.sh +++ b/scripts/check-ucode.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash # Compile-check every ucode file on a router without installing anything: -# the tree is unpacked under /tmp/dlc and modules are resolved from there. +# the tree is unpacked under /tmp/dlc and scripts/compile-ucode.sh runs there +# (the same check CI runs in an OpenWrt rootfs container, scripts/ucode-container.sh). # scripts/check-ucode.sh [root@host] set -euo pipefail HOST="${1:-root@outline.lan}" @@ -12,21 +13,6 @@ TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT python3 "$(dirname "$0")/lint-ucode.py" "$ROOT" ( cd "$ROOT" && COPYFILE_DISABLE=1 tar -czf "$TMP/t.tgz" usr etc ) scp -q "$TMP/t.tgz" "$HOST:/tmp/dl-check.tgz" -ssh "$HOST" sh <<'REMOTE' -rm -rf /tmp/dlc && mkdir -p /tmp/dlc && tar -xzf /tmp/dl-check.tgz -C /tmp/dlc && rm /tmp/dl-check.tgz -cd /tmp/dlc -rc=0 -# Modules by their import name: dawnline/x.uc is dawnline.x, dawnline/rpc/x.uc dawnline.rpc.x. -for f in usr/share/ucode/dawnline/*.uc usr/share/ucode/dawnline/rpc/*.uc; do - [ -f "$f" ] || continue - n=$(echo "${f#usr/share/ucode/}" | sed 's/\.uc$//; s#/#.#g') - out=$(ucode -L '/tmp/dlc/usr/share/ucode/*.uc' -e "import * as x from '$n';" 2>&1) || { echo "FAIL $f"; echo "$out" | head -8; rc=1; } -done -for f in usr/share/rpcd/ucode/luci.dawnline usr/libexec/dawnline/agent usr/libexec/dawnline/updater usr/bin/dawnline usr/share/dawnline/portal/www/cgi-bin/portal; do - [ -f "$f" ] || continue - out=$(ucode -L '/tmp/dlc/usr/share/ucode/*.uc' -c -o /dev/null "$f" 2>&1) || { echo "FAIL $f"; echo "$out" | head -8; rc=1; } -done -rm -rf /tmp/dlc -[ $rc = 0 ] && echo "all ucode files compile" -exit $rc -REMOTE +ssh "$HOST" 'rm -rf /tmp/dlc && mkdir -p /tmp/dlc && tar -xzf /tmp/dl-check.tgz -C /tmp/dlc && rm /tmp/dl-check.tgz' +# The script goes over stdin (`sh -s`), nothing of it stays on the router. +ssh "$HOST" 'sh -s /tmp/dlc; rc=$?; rm -rf /tmp/dlc; exit $rc' < "$(dirname "$0")/compile-ucode.sh" diff --git a/scripts/compile-ucode.sh b/scripts/compile-ucode.sh new file mode 100755 index 0000000..4ef1914 --- /dev/null +++ b/scripts/compile-ucode.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# Compile-check every ucode file of a Dawnline tree without installing it: +# modules are imported by name (dawnline/x.uc is dawnline.x, dawnline/rpc/x.uc +# dawnline.rpc.x) and entry points compiled with `ucode -c`. Needs ucode with +# its fs, uci, ubus and uloop modules, which is any OpenWrt box or an +# openwrt/rootfs container (scripts/ucode-container.sh); check-ucode.sh pipes +# this script to a router. +# scripts/compile-ucode.sh [ROOT] ROOT holds usr/ and etc/ (default: .) +# +# ucode resolves names at compile time and imports are static, so this catches +# a syntax error, a missing module and a named import that nothing exports. +set -eu +ROOT="$(cd "${1:-.}" && pwd)" +cd "$ROOT" +LIB="$ROOT/usr/share/ucode/*.uc" +rc=0 +for f in usr/share/ucode/dawnline/*.uc usr/share/ucode/dawnline/rpc/*.uc; do + [ -f "$f" ] || continue + n=$(echo "${f#usr/share/ucode/}" | sed 's/\.uc$//; s#/#.#g') + out=$(ucode -L "$LIB" -e "import * as x from '$n';" 2>&1) || { echo "FAIL $f"; echo "$out" | head -8; rc=1; } +done +# Entry points (ucode scripts outside the module tree); the shell ones live in +# the ShellCheck list of .github/workflows/ci.yml instead. +for f in usr/share/rpcd/ucode/luci.dawnline usr/libexec/dawnline/agent usr/libexec/dawnline/updater usr/bin/dawnline \ + usr/share/dawnline/portal/cgi.uc; do + [ -f "$f" ] || { echo "FAIL $f: missing"; rc=1; continue; } + out=$(ucode -L "$LIB" -c -o /dev/null "$f" 2>&1) || { echo "FAIL $f"; echo "$out" | head -8; rc=1; } +done +[ $rc = 0 ] && echo "all ucode files compile" +exit $rc diff --git a/scripts/lint-ucode.py b/scripts/lint-ucode.py index a9e61db..65b7974 100755 --- a/scripts/lint-ucode.py +++ b/scripts/lint-ucode.py @@ -3,8 +3,10 @@ ucode resolves names where they are used: calling a function that is declared further down the same file fails at runtime ("access to undeclared variable"). -Also: calls and named imports must match what a Dawnline module exports, and -the rpcd methods (dawnline.rpc.*) must match the plugin and its ACL. +Also: calls and named imports must match what a Dawnline module exports, the +rpcd methods (dawnline.rpc.*) must match the plugin and its ACL, and regexes +stay POSIX (rules/backend.md). Imports against the module layering are +reported as notes, not failures. Run: scripts/lint-ucode.py [package root] """ import glob @@ -22,9 +24,8 @@ files = modules + [ PLUGIN, f"{root}/usr/libexec/dawnline/agent", f"{root}/usr/libexec/dawnline/updater", - f"{root}/usr/libexec/dawnline/resolver", f"{root}/usr/bin/dawnline", - f"{root}/usr/share/dawnline/portal/www/cgi-bin/portal", + f"{root}/usr/share/dawnline/portal/cgi.uc", ] files = [f for f in files if os.path.exists(f)] bad = 0 @@ -40,6 +41,16 @@ def strip_comments(text): return re.sub(r'//[^\n]*|/\*.*?\*/', '', text, flags=re.S) +def blank_comments(text): + """Comments replaced by their newlines: line numbers stay, their text goes.""" + return re.sub(r'//[^\n]*|/\*.*?\*/', lambda m: '\n' * m.group(0).count('\n'), text, flags=re.S) + + +# A regex literal on one line: `/…/` with no slash inside, followed by flags or +# a delimiter (so a division keeps out). Good enough for how Dawnline writes them. +REGEX_LITERAL = re.compile(r'(? mine or (theirs == mine and mine < 4 and dep != mod): + print(f"note: {f}: {mod} ({LAYER_NAME[mine]}) imports dawnline.{dep} ({LAYER_NAME[theirs]}), a layer above it") + notes += 1 +if notes: + print(f"lint-ucode: {notes} layering notes (not failures)") + print(f"lint-ucode: {len(files)} files checked" + (", problems found" if bad else ", ok")) sys.exit(bad) diff --git a/scripts/ucode-container.sh b/scripts/ucode-container.sh new file mode 100755 index 0000000..a3b5599 --- /dev/null +++ b/scripts/ucode-container.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# Run the ucode checks the way CI does: in an OpenWrt rootfs container with the +# release's own ucode and libuci — compile every file (compile-ucode.sh), then +# the unit tests (tests/ucode/run.sh). Needs docker; the repository is mounted +# read-only at /src, the container is thrown away. +# scripts/ucode-container.sh [24.10|25.12|all] [test name filter] +# +# Images are the x86-64 rootfs of the OpenWrt releases the packages are built +# for (build/Dockerfile, scripts/build-packages.sh), pinned by digest so a +# retagged image cannot change what CI runs. To move to a new release change +# the tag and the digest together (docker buildx imagetools inspect ). +set -euo pipefail +REPO="$(cd "$(dirname "$0")/.." && pwd)" +image_for() { + case "$1" in + 24.10) echo 'openwrt/rootfs:x86-64-24.10.6@sha256:fd76f3afb9c390ef2915618b6e3d7187698c03ecc6c23d3a13f12b62d9c6209e' ;; + 25.12) echo 'openwrt/rootfs:x86-64-25.12.3@sha256:af882e0583954fc2ceac6b081a9d214fc739cfea36a29b48795a5f15563aa3b5' ;; + *) echo "unknown release $1 (24.10 or 25.12)" >&2; exit 2 ;; + esac +} +releases="${1:-all}" +[ "$releases" = all ] && releases='24.10 25.12' +rc=0 +for rel in $releases; do + image="$(image_for "$rel")" + echo "== OpenWrt $rel ($image)" + # The checks run from this stdin script (`sh -s`): ucode-mod-uloop is not in + # the 24.10 rootfs, so what is missing is installed from the release's feeds. + docker run --rm -i --platform linux/amd64 -v "$REPO:/src:ro" -e "FILTER=${2:-}" "$image" sh -s <<-'INNER' || rc=1 + set -eu + missing='' + command -v ucode >/dev/null || missing='ucode' + for m in fs uci ubus uloop; do + [ -e "/usr/lib/ucode/$m.so" ] || missing="$missing ucode-mod-$m" + done + if [ -n "$missing" ]; then + echo "installing:$missing" + if command -v apk >/dev/null; then + # shellcheck disable=SC2086 + apk add --quiet $missing + else + mkdir -p /var/lock + # shellcheck disable=SC2086 + opkg update >/dev/null && opkg install $missing >/dev/null + fi + fi + sh /src/scripts/compile-ucode.sh /src/package/luci-app-dawnline/root + sh /src/tests/ucode/run.sh /src "$FILTER" + INNER +done +exit $rc diff --git a/tests/ucode/awg.test.uc b/tests/ucode/awg.test.uc new file mode 100644 index 0000000..f0daa15 --- /dev/null +++ b/tests/ucode/awg.test.uc @@ -0,0 +1,90 @@ +// dawnline.awg: disguise presets against their own validation, and the parser +// of `awg show all dump` on the output formats of AmneziaWG 1.0, 2.0 and 3.1 +// (the stand-in awg in fixtures/bin prints the fixture put at AWG_DUMP). +import { readfile, writefile, unlink } from 'fs'; +import * as awg from 'dawnline.awg'; + +const AWG_DUMP = '/tmp/dawnline-tests/awg-dump'; +let fixtures = sourcepath(0, true) + '/fixtures'; + +test('obf_preset off', () => { + let o = awg.obf_preset('off'); + eq(o, { jc: '0', jmin: '0', jmax: '0', s1: '0', s2: '0', h1: '1', h2: '2', h3: '3', h4: '4' }, 'plain WireGuard headers'); + eq(awg.obf_errors(o), [], 'valid'); +}); + +test('obf_preset standard and strong', () => { + for (let name in [ 'standard', 'strong' ]) + for (let i = 0; i < 25; i++) { + let o = awg.obf_preset(name); + eq(awg.obf_errors(o), [], `${name} is valid`); + let jc = +o.jc, jmin = +o.jmin, jmax = +o.jmax; + ok(name == 'strong' ? jc >= 6 && jc <= 10 : jc >= 3 && jc <= 6, `${name} jc=${o.jc}`); + ok(jmin >= 64 && jmax > jmin && jmax <= 1024, `${name} junk sizes ${o.jmin}-${o.jmax}`); + ok(+o.s1 + 56 != +o.s2, 's1 + 56 != s2'); + eq(length(uniq([ o.h1, o.h2, o.h3, o.h4 ])), 4, 'distinct headers'); + for (let k in [ 'h1', 'h2', 'h3', 'h4' ]) + ok(+o[k] >= 5, `${k} above the reserved values`); + eq(o.s3, null, 'no 2.0 values'); + } +}); + +test('obf_preset max', () => { + let o = awg.obf_preset('max'); + eq(o.header_protection_key, 'yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk=', 'key from awg genkey'); + ok(+o.jc >= 4 && +o.jc <= 6, 'jc'); + ok(substr(o.i1, 0, 3) == ' { + eq(awg.obf_errors({}), [], 'nothing set'); + eq(awg.obf_errors({ jc: '11' }), [ 'jc=11 (0-10)' ], 'jc range'); + eq(awg.obf_errors({ jmin: '0', jmax: '0' }), [], 'zero junk sizes are allowed'); + eq(awg.obf_errors({ jmin: '2000' }), [ 'jmin=2000 (0-1024)' ], 'jmin range'); + eq(awg.obf_errors({ jmin: '200', jmax: '100' }), [ 'jmin > jmax' ], 'order'); + eq(awg.obf_errors({ s1: '5', s2: '61' }), [ 's1 + 56 = s2' ], 'the handshake size clash'); + eq(awg.obf_errors({ s4: '33' }), [ 's4=33 (0-32)' ], 's4 range'); + eq(awg.obf_errors({ jc: 'x' }), [ 'jc=x (0-10)' ], 'not a number'); + eq(awg.obf_errors({ h1: '7', h2: '7' }), [ 'h1-h4 must be distinct' ], 'duplicate headers'); + eq(awg.obf_errors({ h1: '7-9', h2: 'abc' }), [ 'h2 must be a number or range' ], 'header ranges'); + eq(awg.obf_neutral({ jc: '0', jmin: '0', jmax: '0', s1: '0', s2: '0', h1: '1', h2: '2', h3: '3', h4: '4' }), true, 'off is neutral'); + eq(awg.obf_neutral({ jc: '4', jmin: '64', jmax: '128' }), false, 'junk is not neutral'); +}); + +function dump_of(name) { + writefile(AWG_DUMP, readfile(`${fixtures}/awg-dump-${name}.txt`)); + return awg.dump(); +} + +test('dump: AmneziaWG 1.0 (14 interface fields)', () => { + let d = dump_of('1.0'); + eq(d.ok, true, 'ok'); + eq(d.ifaces, { awgmain: { public_key: 'xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg=', port: 51820 } }, 'interface'); + eq(d.peers['HIgo9xNzJMWLKASShiTqIybxZ0U3wGLiUeJ1PKf8ykw='], + { ifname: 'awgmain', endpoint: '203.0.113.7:41821', handshake: 1760000000, rx: 123456, tx: 654321 }, 'peer with a session'); + eq(d.peers['TrMvSoP4jYQlY6RIzBgbssQqY3vxI2Pi+y71lOWWXX0='], + { ifname: 'awgmain', endpoint: '', handshake: 0, rx: 0, tx: 0 }, 'peer that never connected'); +}); + +test('dump: AmneziaWG 2.0 (33 interface fields)', () => { + let d = dump_of('2.0'); + eq(d.ifaces, { awgmain: { public_key: 'xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg=', port: 51820 } }, 'interface'); + eq(keys(d.peers), [ 'HIgo9xNzJMWLKASShiTqIybxZ0U3wGLiUeJ1PKf8ykw=' ], 'one peer'); +}); + +test('dump: AmneziaWG 3.1 (33 interface fields, protection on)', () => { + let d = dump_of('3.1'); + eq(d.ifaces, { awgmain: { public_key: 'xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg=', port: 51820 } }, 'interface'); + eq(length(d.peers), 2, 'two peers'); +}); + +test('dump: the tool fails', () => { + unlink(AWG_DUMP); + let d = awg.dump(); + eq(d, { ok: false, ifaces: {}, peers: {} }, 'nothing known'); +}); diff --git a/tests/ucode/core.test.uc b/tests/ucode/core.test.uc new file mode 100644 index 0000000..28a5b1c --- /dev/null +++ b/tests/ucode/core.test.uc @@ -0,0 +1,138 @@ +// dawnline.core: the model read from the fixture config (real libuci), access +// hours, quotas and the derived person state at an explicit time, address +// allocation and the automatic MTU. +import * as core from 'dawnline.core'; + +// A local time that no time zone turns into another day. +function at(y, mo, d, h, mi) { + return timelocal({ year: y, mon: mo, mday: d, hour: h, min: mi, sec: 0 }); +} + +let m = core.load(); + +test('load reads the fixture', () => { + eq(keys(m.servers), [ 'main' ], 'servers'); + eq(sort(keys(m.people)), [ 'alice', 'bob' ], 'people'); + eq(m.servers.main.subnet, '10.9.0.0/29', 'subnet'); + eq(m.servers.main.mtu, 1380, 'stored MTU'); + eq(m.servers.main.obf, { jc: '4', jmin: '64', jmax: '128', s4: '12' }, 'disguise values as strings'); + eq(m.servers.main.mesh, 'all', 'mesh default'); + eq(m.people.alice.devices, [ 'alice_phone' ], 'devices attached to their person'); + eq(m.people.alice.access, 'both', 'access'); + eq(m.people.bob.access, 'internet', 'access default'); + eq(m.people.bob.quota_gb, 2, 'quota as a number'); + eq(m.people.bob.device_limit, 3, 'device limit from the settings default'); + eq(m.devices.alice_phone.kind, 'phone', 'kind'); + eq(m.settings.portal_enabled, true, 'bool setting'); + eq(m.settings.updates.interval, '7d', 'update policy from the same section'); + eq(m.settings.updates.targets, [ 'app' ], 'update targets list'); + eq(m.settings.retention.log_connections, '0', 'raw retention values'); +}); + +test('parse_hours', () => { + eq(core.parse_hours('07:00-23:00'), [ 420, 1380 ], 'day window'); + eq(core.parse_hours('23:00-07:00'), [ 1380, 420 ], 'overnight window'); + eq(core.parse_hours('7:00-23:00'), [ 420, 1380 ], 'one-digit hour'); + eq(core.parse_hours('00:00-24:00'), [ 0, 1440 ], 'whole day'); + eq(core.parse_hours('24:00-01:00'), null, 'start at 24:00'); + eq(core.parse_hours('10:00-10:00'), null, 'empty window'); + eq(core.parse_hours('always'), null, 'words'); + eq(core.parse_hours(''), null, 'empty'); + eq(core.parse_hours(null), null, 'null'); +}); + +test('person_quota', () => { + let march = at(2026, 3, 10, 12, 0); + eq(core.person_quota({ quota_gb: 0 }, march), 0, 'unlimited'); + eq(core.person_quota({ quota_gb: 2 }, march), 2147483648, '2 GiB'); + eq(core.person_quota({ quota_gb: 2, bonus_gb: 1, bonus_month: '2026-03' }, march), 3221225472, 'bonus this month'); + eq(core.person_quota({ quota_gb: 2, bonus_gb: 1, bonus_month: '2026-02' }, march), 2147483648, 'bonus of another month'); + eq(core.person_quota({ quota_gb: -1 }, march), 0, 'negative is unlimited'); +}); + +test('person_usage', () => { + let march = at(2026, 3, 10, 12, 0); + let usage = { people: { bob: { total: [ 100, 50 ], months: { '2026-03': [ 10, 5 ], '2026-02': [ 1000, 1000 ] } } } }; + eq(core.person_usage({ id: 'bob', quota_period: 'month' }, usage, march), 15, 'this month'); + eq(core.person_usage({ id: 'bob', quota_period: 'month' }, usage, at(2026, 4, 1, 0, 0)), 0, 'a month without traffic'); + eq(core.person_usage({ id: 'bob', quota_period: 'total' }, usage, march), 150, 'total'); + eq(core.person_usage({ id: 'nobody', quota_period: 'month' }, usage, march), 0, 'unknown person'); + eq(core.person_usage({ id: 'bob' }, null, march), 0, 'no usage data'); +}); + +test('own_state', () => { + let base = { id: 'p', paused: false, expires: '', expire_action: 'pause', quota_gb: 0, hours: '' }; + let noon = at(2026, 3, 10, 12, 0); + eq(core.own_state(m, base, null, noon), 'active', 'nothing set'); + eq(core.own_state(m, { ...base, paused: true }, null, noon), 'paused', 'paused'); + eq(core.own_state(m, { ...base, expires: '2026-03-09' }, null, noon), 'expired', 'expired yesterday'); + eq(core.own_state(m, { ...base, expires: '2026-03-10' }, null, noon), 'active', 'expires at the end of today'); + eq(core.own_state(m, { ...base, expires: '2026-03-09', expire_action: 'notify' }, null, noon), 'active', 'notify keeps access'); + let usage = { people: { p: { months: { '2026-03': [ 600000000, 600000000 ] } } } }; + eq(core.own_state(m, { ...base, quota_gb: 1 }, usage, noon), 'quota', 'over quota'); + eq(core.own_state(m, { ...base, quota_gb: 1, bonus_gb: 1, bonus_month: '2026-03' }, usage, noon), 'active', 'bonus lifts the quota'); + eq(core.own_state(m, { ...base, quota_gb: 1 }, usage, at(2026, 4, 1, 0, 0)), 'active', 'a new month resets the usage'); + eq(core.own_state(m, { ...base, hours: '09:00-17:00' }, null, noon), 'active', 'inside the hours'); + eq(core.own_state(m, { ...base, hours: '09:00-17:00' }, null, at(2026, 3, 10, 20, 0)), 'hours', 'outside the hours'); + eq(core.own_state(m, { ...base, hours: '22:00-06:00' }, null, at(2026, 3, 10, 23, 0)), 'active', 'overnight, before midnight'); + eq(core.own_state(m, { ...base, hours: '22:00-06:00' }, null, at(2026, 3, 10, 5, 59)), 'active', 'overnight, after midnight'); + eq(core.own_state(m, { ...base, hours: '22:00-06:00' }, null, noon), 'hours', 'overnight, daytime'); + eq(core.own_state(m, { ...base, paused: true, expires: '2000-01-01' }, null, noon), 'paused', 'paused wins over expired'); + eq(core.own_state(m, { ...base, expires: '2000-01-01', quota_gb: 1 }, usage, noon), 'expired', 'expired wins over quota'); +}); + +test('person_state', () => { + let noon = at(2026, 3, 10, 12, 0); + let p = { id: 'p', server: 'main', paused: false, expires: '', expire_action: 'pause', quota_gb: 0, hours: '' }; + eq(core.person_state(m, p, null, noon), 'active', 'server on'); + eq(core.person_state(m, { ...p, server: 'gone' }, null, noon), 'no_server', 'no server'); + let off = { servers: { main: { ...m.servers.main, enabled: false } } }; + eq(core.person_state(off, p, null, noon), 'server_off', 'server off'); + eq(core.person_state(off, { ...p, paused: true }, null, noon), 'server_off', 'server off is about the server'); + ok(core.person_expired({ expires: '2000-01-01' }, noon), 'person_expired'); + ok(!core.person_expired({ expires: '' }, noon), 'no end date'); + ok(!core.person_expired({ expires: 'garbage' }, noon), 'bad date is not expired'); +}); + +test('alloc_address', () => { + let srv = { id: 'main', subnet: '10.9.0.0/29' }; + let other = { id: 'other', subnet: '10.9.1.0/29' }; + let model = (addrs) => { + let mm = { servers: { main: srv, other }, people: { a: { server: 'main' }, o: { server: 'other' } }, devices: {} }; + for (let i, a in addrs) + mm.devices[`d${i}`] = { person: 'a', address: a }; + return mm; + }; + eq(core.alloc_address(model([]), srv), '10.9.0.2', 'router has the first host'); + eq(core.alloc_address(model([ '10.9.0.2', '10.9.0.3' ]), srv), '10.9.0.4', 'next free'); + eq(core.alloc_address(model([ '10.9.0.2', '10.9.0.4' ]), srv), '10.9.0.3', 'lowest gap'); + eq(core.alloc_address(model([ '10.9.0.2', '10.9.0.3', '10.9.0.4', '10.9.0.5', '10.9.0.6' ]), srv), null, 'exhausted (.7 is broadcast)'); + eq(core.alloc_address(model([ '10.9.0.2', 'garbage' ]), srv), '10.9.0.3', 'a broken address is ignored'); + let mm = model([]); + mm.devices.x = { person: 'o', address: '10.9.0.2' }; + eq(core.alloc_address(mm, srv), '10.9.0.2', 'another server\'s devices do not count'); + eq(core.alloc_address(model([]), { id: 'main', subnet: 'nonsense' }), null, 'no subnet'); + eq(core.server_address(srv), '10.9.0.1', 'server_address'); + eq(core.tunnels({ ...srv, ifname: 'awgmain', private_key: 'k' }), [ { ifname: 'awgmain', subnet: '10.9.0.0/29', address: '10.9.0.1' } ], 'tunnels'); + eq(core.tunnels({ ...srv, ifname: 'awgmain' }), [], 'no key, no tunnel'); + eq(core.tunnels({ ...srv, ifname: 'awgmain', private_key: 'k', blocked: 'taken' }), [], 'blocked interface'); + eq(core.tunnels({ ...srv, ifname: 'awg-main', private_key: 'k' }), [], 'bad interface name'); +}); + +test('tunnel_mtu / device_mtu', () => { + eq(core.tunnel_mtu({ mtu: 1420 }), 1420, 'set by hand'); + eq(core.tunnel_mtu({ mtu: 0, obf: {} }), 1380, 'automatic'); + eq(core.tunnel_mtu({ mtu: 0 }), 1380, 'automatic without disguise'); + eq(core.tunnel_mtu({ mtu: 0, obf: { s4: '12' } }), 1368, 'S4 taken off'); + eq(core.tunnel_mtu({ mtu: 0, obf: { s4: '100' } }), 1280, 'never below 1280'); + eq(core.device_mtu({ mtu: 0, obf: {} }, { kind: 'phone' }), 1280, 'phone'); + eq(core.device_mtu({ mtu: 0, obf: {} }, { kind: 'computer' }), 1380, 'computer'); + eq(core.device_mtu({ mtu: 1200 }, { kind: 'tablet' }), 1200, 'a smaller tunnel MTU stays'); +}); + +test('names and codes', () => { + ok(core.valid_ifname('awgmain') && core.valid_ifname('a') && core.valid_ifname('awg_1'), 'interface names'); + ok(!core.valid_ifname('Awg') && !core.valid_ifname('1awg') && !core.valid_ifname('awg-main') && !core.valid_ifname('awgmain123456'), 'bad interface names'); + for (let i = 0; i < 20; i++) + ok(match(core.new_code(), core.WORD_CODE), 'new_code is a word code'); +}); diff --git a/tests/ucode/fixtures/awg-dump-1.0.txt b/tests/ucode/fixtures/awg-dump-1.0.txt new file mode 100644 index 0000000..2fc8537 --- /dev/null +++ b/tests/ucode/fixtures/awg-dump-1.0.txt @@ -0,0 +1,3 @@ +awgmain yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk= xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg= 51820 off 4 64 128 20 40 1234567 2345678 3456789 4567890 +awgmain HIgo9xNzJMWLKASShiTqIybxZ0U3wGLiUeJ1PKf8ykw= (none) 203.0.113.7:41821 10.9.0.2/32 1760000000 123456 654321 off +awgmain TrMvSoP4jYQlY6RIzBgbssQqY3vxI2Pi+y71lOWWXX0= (none) (none) 10.9.0.3/32 0 0 0 off diff --git a/tests/ucode/fixtures/awg-dump-2.0.txt b/tests/ucode/fixtures/awg-dump-2.0.txt new file mode 100644 index 0000000..3873b50 --- /dev/null +++ b/tests/ucode/fixtures/awg-dump-2.0.txt @@ -0,0 +1,2 @@ +awgmain yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk= xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg= 51820 off 4 64 128 20 40 12 12 1234567 2345678 3456789 4567890 +awgmain HIgo9xNzJMWLKASShiTqIybxZ0U3wGLiUeJ1PKf8ykw= (none) 203.0.113.7:41821 10.9.0.2/32 1760000000 123456 654321 off diff --git a/tests/ucode/fixtures/awg-dump-3.1.txt b/tests/ucode/fixtures/awg-dump-3.1.txt new file mode 100644 index 0000000..e58d818 --- /dev/null +++ b/tests/ucode/fixtures/awg-dump-3.1.txt @@ -0,0 +1,3 @@ +awgmain yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk= xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg= 51820 off 4 64 128 20 40 12 12 1234567 2345678 3456789 4567890 yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk= 10-100 on on +awgmain HIgo9xNzJMWLKASShiTqIybxZ0U3wGLiUeJ1PKf8ykw= (none) 203.0.113.7:41821 10.9.0.2/32 1760000000 123456 654321 off +awgmain TrMvSoP4jYQlY6RIzBgbssQqY3vxI2Pi+y71lOWWXX0= (none) (none) 10.9.0.3/32 0 0 0 off diff --git a/tests/ucode/fixtures/bin/awg b/tests/ucode/fixtures/bin/awg new file mode 100755 index 0000000..e550469 --- /dev/null +++ b/tests/ucode/fixtures/bin/awg @@ -0,0 +1,10 @@ +#!/bin/sh +# Stand-in for amneziawg-tools in the ucode tests (no kernel module in a +# container): `genkey` prints one fixed key, `show all dump` prints the fixture +# a test has put at /tmp/dawnline-tests/awg-dump (or fails, as the tool does +# when no interface is up). Anything else fails. +case "$1 ${2:-} ${3:-}" in + 'genkey ') echo 'yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk=' ;; + 'show all dump') cat /tmp/dawnline-tests/awg-dump ;; + *) echo "awg stand-in: unsupported arguments: $*" >&2; exit 1 ;; +esac diff --git a/tests/ucode/fixtures/config/dawnline b/tests/ucode/fixtures/config/dawnline new file mode 100644 index 0000000..80150ac --- /dev/null +++ b/tests/ucode/fixtures/config/dawnline @@ -0,0 +1,43 @@ +# Test fixture: a small installation (one server, two people, one device). +# migrate.test.uc expects bob's random code, the server's stored MTU 1380 and +# uhttpd's error_page: the one-time steps remove them. + +config settings 'settings' + option portal_enabled '1' + option portal_port '8443' + option portal_host 'vpn.example.com' + option log_connections '0' + option update_interval '7d' + list update_targets 'app' + +config server 'main' + option name 'Main' + option ifname 'awgmain' + option port '51820' + option subnet '10.9.0.0/29' + option private_key 'yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk=' + option public_key 'xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg=' + option mtu '1380' + option jc '4' + option jmin '64' + option jmax '128' + option s4 '12' + +config person 'alice' + option server 'main' + option name 'Alice' + option code 'abcdef-ghijkl-mnopqr' + option access 'both' + +config person 'bob' + option server 'main' + option name 'Bob' + option code 'XyZ12345' + option quota_gb '2' + +config device 'alice_phone' + option person 'alice' + option name 'Phone' + option kind 'phone' + option address '10.9.0.2' + option public_key 'xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg=' diff --git a/tests/ucode/fixtures/config/uhttpd b/tests/ucode/fixtures/config/uhttpd new file mode 100644 index 0000000..8df773a --- /dev/null +++ b/tests/ucode/fixtures/config/uhttpd @@ -0,0 +1,8 @@ +# Test fixture: LuCI's web server as versions before 0.4 left it, with the +# portal as its error page (migrate.uhttpd removes that). + +config uhttpd 'main' + list listen_http '0.0.0.0:80' + list listen_https '0.0.0.0:443' + option home '/www' + option error_page '/cgi-bin/dawnline-portal' diff --git a/tests/ucode/live.test.uc b/tests/ucode/live.test.uc new file mode 100644 index 0000000..5de2643 --- /dev/null +++ b/tests/ucode/live.test.uc @@ -0,0 +1,47 @@ +// dawnline.live: event categories and the retention policy, from a settings +// object and from the fixture config (real libuci). +import * as live from 'dawnline.live'; + +test('category_of', () => { + eq(live.category_of('connect'), 'connections', 'connect'); + eq(live.category_of('roam'), 'connections', 'roam'); + eq(live.category_of('device_added'), 'people', 'device events are people events'); + eq(live.category_of('person_changed'), 'people', 'person'); + eq(live.category_of('server_down'), 'problems', 'server'); + eq(live.category_of('something_new'), 'problems', 'unknown types are problems'); +}); + +test('policy defaults', () => { + eq(live.policy({}), { keep_days: 30, max: 2000, categories: [ 'connections', 'people', 'problems' ], + persist: 'hourly', usage_days: 62, usage_months: 24 }, 'empty settings'); +}); + +test('policy categories', () => { + eq(live.policy({ log_connections: '0' }).categories, [ 'people', 'problems' ], 'old switch'); + eq(live.policy({ log_category: 'devices, problems' }).categories, [ 'people', 'problems' ], 'string list, devices renamed'); + eq(live.policy({ log_category: [ 'connections', 'bogus', 'connections' ] }).categories, [ 'connections' ], 'list, unknown and repeats dropped'); + eq(live.policy({ log_category: [], log_connections: '0' }).categories, [], 'explicit empty list wins'); +}); + +test('policy ranges', () => { + eq(live.policy({ log_max: '50' }).max, 100, 'max floor'); + eq(live.policy({ log_max: '99999' }).max, 20000, 'max ceiling'); + eq(live.policy({ log_max: 'abc' }).max, 2000, 'bad max'); + eq(live.policy({ log_keep_days: '0' }).keep_days, 0, 'keep forever'); + eq(live.policy({ log_keep_days: '-3' }).keep_days, 30, 'negative days'); + eq(live.policy({ log_persist: '10min' }).persist, '10min', 'persist'); + eq(live.policy({ log_persist: 'daily' }).persist, 'hourly', 'bad persist'); + eq(live.policy({ usage_keep_days: '1' }).usage_days, 7, 'usage days floor'); + eq(live.policy({ usage_keep_months: '500' }).usage_months, 120, 'usage months ceiling'); +}); + +test('policy from the config', () => { + eq(live.policy(null).categories, [ 'people', 'problems' ], 'fixture turns connections off'); + eq(live.policy(null).max, 2000, 'default where the fixture says nothing'); +}); + +test('endpoint_ip', () => { + eq(live.endpoint_ip('203.0.113.7:41821'), '203.0.113.7', 'v4'); + eq(live.endpoint_ip('[2001:db8::1]:41821'), '2001:db8::1', 'v6'); + eq(live.endpoint_ip(''), '', 'none'); +}); diff --git a/tests/ucode/migrate.test.uc b/tests/ucode/migrate.test.uc new file mode 100644 index 0000000..66a2cd0 --- /dev/null +++ b/tests/ucode/migrate.test.uc @@ -0,0 +1,44 @@ +// dawnline.migrate: the one-time steps on the fixture config (real libuci): +// each changes what it must the first time and nothing the second time. +// This test rewrites /etc/config/dawnline and /etc/config/uhttpd. +import { cursor } from 'uci'; +import { stat } from 'fs'; +import * as core from 'dawnline.core'; +import * as migrate from 'dawnline.migrate'; + +function conf(name) { + let c = cursor(); + c.load(name); + return c; +} + +test('before: the fixture holds the old state', () => { + let c = conf('dawnline'); + eq(c.get('dawnline', 'bob', 'code'), 'XyZ12345', 'random code'); + eq(c.get('dawnline', 'main', 'mtu'), '1380', 'stored MTU'); + eq(conf('uhttpd').get('uhttpd', 'main', 'error_page'), '/cgi-bin/dawnline-portal', 'portal as error page'); +}); + +test('run: the steps change what they must', () => { + migrate.run(); + let c = conf('dawnline'); + ok(match(c.get('dawnline', 'bob', 'code'), core.WORD_CODE), 'bob has a word code'); + eq(c.get('dawnline', 'alice', 'code'), 'abcdef-ghijkl-mnopqr', 'alice keeps hers'); + eq(c.get('dawnline', 'main', 'mtu'), null, 'MTU is automatic'); + eq(c.get('dawnline', 'main', 'subnet'), '10.9.0.0/29', 'the rest of the server stays'); + eq(c.get('dawnline', 'settings', 'portal_443'), null, 'no portal_443'); + eq(conf('uhttpd').get('uhttpd', 'main', 'error_page'), null, 'error page gone'); + eq(conf('uhttpd').get('uhttpd', 'main', 'home'), '/www', 'the rest of uhttpd stays'); + eq(stat('/etc/config/dawnline').perm, { setuid: false, setgid: false, sticky: false, + user_read: true, user_write: true, user_exec: false, + group_read: false, group_write: false, group_exec: false, + other_read: false, other_write: false, other_exec: false }, 'config stays private'); +}); + +test('run again: a step runs once', () => { + let before = conf('dawnline').get('dawnline', 'bob', 'code'); + let mtime = stat('/etc/config/dawnline').mtime; + migrate.run(); + eq(conf('dawnline').get('dawnline', 'bob', 'code'), before, 'the code is not drawn again'); + eq(stat('/etc/config/dawnline').mtime, mtime, 'nothing written'); +}); diff --git a/tests/ucode/run.sh b/tests/ucode/run.sh new file mode 100755 index 0000000..e277ab5 --- /dev/null +++ b/tests/ucode/run.sh @@ -0,0 +1,17 @@ +#!/bin/sh +# Run the ucode unit tests against the real libuci: the fixture configs are +# copied into /etc/config (replacing what is there), the stand-in `awg` goes on +# PATH and tests/ucode/run.uc runs every *.test.uc. For a throw-away OpenWrt +# rootfs container (scripts/ucode-container.sh); on anything else it refuses +# unless DAWNLINE_TEST_FORCE=1, because it overwrites /etc/config/dawnline. +# tests/ucode/run.sh [REPO] [test name filter] +set -eu +REPO="$(cd "${1:-$(dirname "$0")/../..}" && pwd)" +T="$REPO/tests/ucode" +if [ ! -e /.dockerenv ] && [ "${DAWNLINE_TEST_FORCE:-}" != 1 ]; then + echo "run.sh replaces /etc/config/dawnline and /etc/config/uhttpd: run it in a container (scripts/ucode-container.sh)" >&2 + exit 2 +fi +cp "$T"/fixtures/config/* /etc/config/ +mkdir -p /tmp/dawnline-tests /var/run/dawnline +PATH="$T/fixtures/bin:$PATH" ucode -L "$REPO/package/luci-app-dawnline/root/usr/share/ucode/*.uc" "$T/run.uc" "${2:-}" diff --git a/tests/ucode/run.uc b/tests/ucode/run.uc new file mode 100644 index 0000000..095e49b --- /dev/null +++ b/tests/ucode/run.uc @@ -0,0 +1,68 @@ +#!/usr/bin/ucode +'use strict'; +// Dawnline ucode unit tests. Runs every *.test.uc beside this file (in name +// order; migrate.test.uc changes /etc/config/dawnline, so it sorts after the +// tests that read the fixture as it is) with four helpers in scope: +// test(name, fn) one case; a thrown error or die() fails it +// eq(got, want, note) deep equality (JSON form), note names the case +// ok(cond, note) a true value +// throws(fn, re, note) fn must throw; the message must match re when given +// tests/ucode/run.sh prepares the fixtures and starts this with the modules +// on -L; an optional argument runs only the files whose name contains it. +import { lsdir } from 'fs'; + +let dir = sourcepath(0, true); +let passed = 0, failed = 0, file = null; + +function eq(got, want, note) { + let g = sprintf('%J', got), w = sprintf('%J', want); + if (g != w) + die(`${note ? note + ': ' : ''}got ${g}, want ${w}`); +} + +function ok(cond, note) { + if (!cond) + die(note ?? 'expected a true value'); +} + +function throws(fn, re, note) { + let msg = null; + try { + fn(); + } + catch (e) { + msg = e.message ?? `${e}`; + } + if (msg == null) + die(`${note ?? 'call'} did not throw`); + if (re && !match(msg, re)) + die(`${note ?? 'call'} threw "${msg}", not ${re}`); + return msg; +} + +function test(name, fn) { + try { + fn(); + passed++; + } + catch (e) { + failed++; + // The first frame in the test file itself (not eq()/ok() in here). + let at = filter(e.stacktrace ?? [], (f) => f.filename && index(f.filename, '/run.uc') < 0)[0]; + printf('FAIL %s: %s\n %s%s\n', file, name, e.message ?? `${e}`, at ? ` (${at.filename}:${at.line})` : ''); + } +} + +for (file in sort(lsdir(dir) ?? [])) { + if (!match(file, /\.test\.uc$/) || (ARGV[0] && index(file, ARGV[0]) < 0)) + continue; + try { + include(`${dir}/${file}`, { test, eq, ok, throws }); + } + catch (e) { + failed++; + printf('FAIL %s: could not run\n %s\n', file, e.message ?? `${e}`); + } +} +printf('%d passed, %d failed\n', passed, failed); +exit(failed ? 1 : 0); diff --git a/tests/ucode/schema.test.uc b/tests/ucode/schema.test.uc new file mode 100644 index 0000000..0a6314b --- /dev/null +++ b/tests/ucode/schema.test.uc @@ -0,0 +1,145 @@ +// dawnline.schema: what the admin may save (validate) and how stored values +// are read (get), one case per settings type. +import * as schema from 'dawnline.schema'; + +test('validate: bool', () => { + eq(schema.validate('portal_enabled', true), '1', 'true'); + eq(schema.validate('portal_enabled', false), '0', 'false'); + eq(schema.validate('portal_enabled', '1'), '1', 'string 1'); + eq(schema.validate('portal_enabled', ''), null, 'empty removes the option'); + throws(() => schema.validate('portal_enabled', 'yes'), /0 or 1/, 'yes'); +}); + +test('validate: int', () => { + eq(schema.validate('portal_port', '8443'), '8443', 'in range'); + eq(schema.validate('portal_port', ' 443 '), '443', 'trimmed'); + eq(schema.validate('portal_port', '08443'), '8443', 'leading zero dropped'); + eq(schema.validate('portal_port', 9000), '9000', 'number'); + throws(() => schema.validate('portal_port', '0'), /free port/, 'below min'); + throws(() => schema.validate('portal_port', '70000'), /free port/, 'above max'); + throws(() => schema.validate('portal_port', 'abc'), /free port/, 'letters'); + throws(() => schema.validate('portal_port', '-1'), /free port/, 'negative'); + throws(() => schema.validate('default_device_limit', '33'), /1-32/, 'device limit'); + eq(schema.validate('log_keep_days', '0'), '0', 'zero allowed where min is 0'); +}); + +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('update_interval', '7d'), '7d', 'interval from dawnline.updates'); + throws(() => schema.validate('update_interval', '2d'), /6h, 12h, 1d or 7d/, 'unknown interval'); +}); + +test('validate: host and hosts', () => { + eq(schema.validate('portal_host', 'vpn.example.com'), 'vpn.example.com', 'name'); + eq(schema.validate('portal_host', '203.0.113.7'), '203.0.113.7', 'address'); + throws(() => schema.validate('portal_host', 'bad host!'), /hostname or IP/, 'bad'); + eq(schema.validate('portal_alt', [ 'a.example.com', ' a.example.com ', 'bad host', 'b.example.com' ]), + [ 'a.example.com', 'b.example.com' ], 'trimmed, deduplicated, bad ones dropped'); + eq(schema.validate('portal_alt', []), null, 'empty list removes the option'); + eq(schema.validate('portal_alt', 'a.example.com'), null, 'not a list'); +}); + +test('validate: url', () => { + eq(schema.validate('portal_redirect', 'https://example.com/x?y=1'), 'https://example.com/x?y=1', 'https with path'); + eq(schema.validate('portal_redirect', 'http://example.com:8080'), 'http://example.com:8080', 'http with port'); + throws(() => schema.validate('portal_redirect', 'ftp://example.com'), /full http/, 'scheme'); + throws(() => schema.validate('portal_redirect', 'https://example.com/'), /full http/, 'angle brackets'); + throws(() => schema.validate('portal_redirect', 'https://example.com/' + replace(sprintf('%300s', ''), ' ', 'a')), /full http/, 'over 300 characters'); +}); + +test('validate: file', () => { + eq(schema.validate('portal_cert', '/etc/passwd'), '/etc/passwd', 'existing file'); + throws(() => schema.validate('portal_cert', '/nonexistent/cert.pem'), /does not exist/, 'missing'); + throws(() => schema.validate('portal_cert', 'cert.pem'), /does not exist/, 'relative'); +}); + +test('validate: domain', () => { + eq(schema.validate('domain', 'lan'), 'lan', 'single'); + eq(schema.validate('domain', 'home.arpa'), 'home.arpa', 'dotted'); + throws(() => schema.validate('domain', 'Lan'), /lowercase/, 'upper case'); + throws(() => schema.validate('domain', replace(sprintf('%33s', ''), ' ', 'a')), /lowercase/, '33-char label'); +}); + +test('validate: ipv4', () => { + eq(schema.validate('home_dns_fallback', '9.9.9.9'), '9.9.9.9', 'address'); + eq(schema.validate('home_dns_fallback', ''), 'none', 'empty means no fallback'); + throws(() => schema.validate('home_dns_fallback', '999.1.1.1'), /IPv4/, 'bad octet'); + throws(() => schema.validate('home_dns_fallback', 'dns.example'), /IPv4/, 'name'); +}); + +test('validate: time', () => { + eq(schema.validate('update_time', '04:00'), '04:00', 'padded'); + eq(schema.validate('update_time', '4:00'), '4:00', 'unpadded'); + eq(schema.validate('update_time', '23:59'), '23:59', 'last minute'); + throws(() => schema.validate('update_time', '24:00'), /HH:MM/, 'hour 24'); + throws(() => schema.validate('update_time', '23:60'), /HH:MM/, 'minute 60'); +}); + +test('validate: text', () => { + eq(schema.validate('portal_title', 'My VPN'), 'My VPN', 'plain'); + eq(schema.validate('portal_title', replace(sprintf('%64s', ''), ' ', 'a')), replace(sprintf('%64s', ''), ' ', 'a'), '64 characters'); + throws(() => schema.validate('portal_title', replace(sprintf('%65s', ''), ' ', 'a')), /64 characters/, '65 characters'); + throws(() => schema.validate('portal_title', 'a\nb'), /64 characters/, 'control character'); +}); + +test('validate: targets', () => { + eq(schema.validate('update_targets', [ 'app', 'bogus', 'app', 'amneziawg' ]), [ 'app', 'amneziawg' ], 'known ones, once'); + eq(schema.validate('update_targets', []), [ 'none' ], 'empty is a choice'); + eq(schema.validate('update_targets', 'app'), [ 'none' ], 'not a list'); +}); + +test('validate: unknown key', () => { + throws(() => schema.validate('nonsense', '1'), /Unknown setting/); +}); + +test('get', () => { + eq(schema.get({ portal_enabled: 'on' }, 'portal_enabled'), true, 'bool synonyms'); + eq(schema.get({ portal_enabled: 'maybe' }, 'portal_enabled'), false, 'bad bool is the default'); + eq(schema.get({}, 'portal_enabled'), false, 'missing bool'); + eq(schema.get({ portal_port: '443' }, 'portal_port'), 443, 'int'); + eq(schema.get({ portal_port: '99999' }, 'portal_port'), 8443, 'int out of range is the default'); + eq(schema.get({ portal_port: 'x' }, 'portal_port'), 8443, 'bad int'); + eq(schema.get({}, 'portal_alt'), [], 'missing list'); + eq(schema.get({ portal_alt: 'a.example.com' }, 'portal_alt'), [ 'a.example.com' ], 'single value as list'); + eq(schema.get({ portal_alt: [ 'a', '' ] }, 'portal_alt'), [ 'a' ], 'empty entries dropped'); + eq(schema.get({}, 'update_targets'), [ 'app', 'packages' ], 'default targets'); + eq(schema.get({ geo_provider: 'ipapi.co' }, 'geo_provider'), 'ipapi.co', 'enum'); + eq(schema.get({ geo_provider: 'x' }, 'geo_provider'), 'ipwho.is', 'bad enum is the default'); + eq(schema.get({ home_dns_fallback: 'none' }, 'home_dns_fallback'), '', 'none reads as empty'); + eq(schema.get({}, 'home_dns_fallback'), '1.1.1.1', 'missing ipv4'); + eq(schema.get({ home_dns_fallback: '300.1.1.1' }, 'home_dns_fallback'), '1.1.1.1', 'bad ipv4'); + eq(schema.get({}, 'portal_title'), 'Dawnline', 'missing text'); + eq(schema.get({ portal_title: '' }, 'portal_title'), 'Dawnline', 'empty text'); + eq(schema.get({ portal_host: 'vpn.example.com' }, 'portal_host'), 'vpn.example.com', 'host passes through'); + eq(schema.get({ other: 'raw' }, 'other'), 'raw', 'unknown key is the raw value'); + eq(schema.get(null, 'portal_port'), 8443, 'no section'); +}); + +test('parsing helpers', () => { + eq(schema.bool('TRUE', false), true, 'case-insensitive'); + eq(schema.bool(' 0 ', true), false, 'trimmed'); + eq(schema.bool(null, true), true, 'default'); + eq(schema.to_int('-5', 0, 0, 10), 0, 'below min'); + eq(schema.to_int('7', 0, 0, 10), 7, 'in range'); + eq(schema.to_int('7.5', 0), 0, 'not whole'); + ok(schema.valid_port('65535'), 'max port'); + ok(!schema.valid_port('0'), 'port 0'); + ok(!schema.valid_port('65536'), 'port 65536'); + ok(!schema.valid_port('12a'), 'letters'); + ok(!schema.valid_port(null), 'null'); +}); + +test('addresses', () => { + ok(schema.ipv4('10.0.0.1') && !schema.ipv4('10.0.0.256') && !schema.ipv4(null), 'ipv4'); + eq(schema.ipv6_groups('::1'), [ 0, 0, 0, 0, 0, 0, 0, 1 ], 'loopback'); + eq(schema.ipv6_groups('2001:db8::1'), [ 0x2001, 0xdb8, 0, 0, 0, 0, 0, 1 ], 'compressed'); + eq(schema.ipv6_groups('::ffff:192.0.2.1'), [ 0, 0, 0, 0, 0, 0xffff, 0xc000, 0x0201 ], 'embedded IPv4'); + eq(schema.ipv6_groups('1:2:3:4:5:6:7:8'), [ 1, 2, 3, 4, 5, 6, 7, 8 ], 'full'); + eq(schema.ipv6_groups('1:2:3:4:5:6:7:8:9'), null, 'nine groups'); + eq(schema.ipv6_groups('1:2:3:4:5:6:7'), null, 'seven groups, no gap'); + eq(schema.ipv6_groups('1::2::3'), null, 'two gaps'); + eq(schema.ipv6_groups('fe80::1%eth0'), null, 'zone id'); + eq(schema.ipv6_groups('12345::'), null, 'group too long'); + ok(schema.ip('10.0.0.1') && schema.ip('fe80::1') && !schema.ip('nope'), 'ip'); +}); diff --git a/tests/ucode/updates.test.uc b/tests/ucode/updates.test.uc new file mode 100644 index 0000000..c569d14 --- /dev/null +++ b/tests/ucode/updates.test.uc @@ -0,0 +1,54 @@ +// dawnline.updates: the update policy from raw settings, what is due at a +// given time, and release version ordering. +import * as updates from 'dawnline.updates'; + +function at(y, mo, d, h, mi) { + return timelocal({ year: y, mon: mo, mday: d, hour: h, min: mi, sec: 0 }); +} + +test('policy defaults', () => { + eq(updates.policy(null), { check: true, interval: '1d', auto: true, mode: 'scheduled', time: '04:00', + targets: [ 'app', 'packages' ], keep: false, mirrors: true }, 'no settings'); + eq(updates.policy({}), updates.policy(null), 'empty settings'); +}); + +test('policy values', () => { + let p = updates.policy({ update_check: '0', update_interval: '7d', update_auto: 'no', update_mode: 'immediate', + update_time: '23:59', update_targets: 'amneziawg', update_keep: '1', update_mirrors: 'off' }); + eq(p, { check: false, interval: '7d', auto: false, mode: 'immediate', time: '23:59', targets: [ 'amneziawg' ], keep: true, mirrors: false }, 'all set'); + eq(updates.policy({ update_interval: '2d' }).interval, '1d', 'unknown interval'); + eq(updates.policy({ update_time: '24:00' }).time, '04:00', 'bad time'); + eq(updates.policy({ update_time: '4:30' }).time, '4:30', 'unpadded time'); + eq(updates.policy({ update_mode: 'later' }).mode, 'scheduled', 'unknown mode'); + eq(updates.policy({ update_targets: [ 'packages', 'bogus', 'app' ] }).targets, [ 'packages', 'app' ], 'unknown targets dropped'); + eq(updates.policy({ update_targets: [ 'none' ] }).targets, [], '"none" is no target'); + eq(updates.policy({ update_targets: [] }).targets, [], 'empty list'); +}); + +test('due', () => { + let pol = updates.policy({ update_time: '04:00' }); + let t = at(2026, 3, 10, 4, 30); + eq(updates.due(pol, {}, t), 'install', 'in the window, never run'); + eq(updates.due(pol, { install_day: '2026-03-10' }, t), 'check', 'window spent, check is due'); + eq(updates.due(pol, { install_day: '2026-03-10', check: t - 3600 }, t), null, 'checked an hour ago'); + eq(updates.due(pol, { check: t - 90000 }, at(2026, 3, 10, 12, 0)), 'check', 'outside the window, a day has passed'); + eq(updates.due(pol, {}, at(2026, 3, 10, 5, 30)), 'check', 'window over (an hour)'); + eq(updates.due(updates.policy({ update_auto: '0', update_check: '0' }), {}, t), null, 'everything off'); + eq(updates.due(updates.policy({ update_mode: 'immediate' }), {}, t), 'check', 'immediate mode has no window'); + eq(updates.due(updates.policy({ update_targets: [] }), {}, t), 'check', 'nothing to install'); + let late = updates.policy({ update_time: '23:30' }); + eq(updates.due(late, {}, at(2026, 3, 11, 0, 15)), 'install', 'window across midnight'); + eq(updates.mark_day(late, {}, at(2026, 3, 11, 0, 15)).install_day, '2026-03-10', 'mark_day records the slot\'s day'); +}); + +test('version_cmp', () => { + eq(updates.version_cmp('0.5.1', '0.5.1'), 0, 'equal'); + eq(updates.version_cmp('v0.5.1', '0.5.1'), 0, 'v prefix'); + eq(updates.version_cmp('0.5.1', '0.5.2'), -1, 'patch'); + eq(updates.version_cmp('0.10.0', '0.9.9'), 1, 'numbers, not strings'); + eq(updates.version_cmp('0.6', '0.6.0'), 0, 'missing part is zero'); + eq(updates.version_cmp('0.6.0-rc1', '0.6.0'), -1, 'pre-release before the release'); + eq(updates.version_cmp('0.6.0-rc2', '0.6.0-rc10'), -1, 'rc numbers as numbers'); + eq(updates.version_cmp('0.6.0-beta', '0.6.0-rc1'), -1, 'beta before rc'); + eq(updates.version_cmp('garbage', '0.1'), -1, 'unparsable is lowest'); +}); diff --git a/tests/ucode/util.test.uc b/tests/ucode/util.test.uc new file mode 100644 index 0000000..0df0364 --- /dev/null +++ b/tests/ucode/util.test.uc @@ -0,0 +1,114 @@ +// dawnline.util: validation, addresses, slugs and dates (pure functions). +import * as util from 'dawnline.util'; + +test('valid_name', () => { + ok(util.valid_name('Alice'), 'plain'); + ok(util.valid_name('Мама'), 'non-ASCII letters'); + ok(!util.valid_name(''), 'empty'); + ok(!util.valid_name(' '), 'blank'); + ok(!util.valid_name(null), 'null'); + ok(!util.valid_name(42), 'number'); + ok(util.valid_name('a' + replace(sprintf('%47s', ''), ' ', 'b')), '48 bytes'); + ok(!util.valid_name('a' + replace(sprintf('%48s', ''), ' ', 'b')), '49 bytes'); + ok(!util.valid_name('a { + ok(util.valid_host('vpn.example.com'), 'name'); + ok(util.valid_host('router'), 'single label'); + ok(util.valid_host('203.0.113.7'), 'IPv4'); + ok(util.valid_host('2001:db8::1'), 'IPv6'); + ok(!util.valid_host('-a.example.com'), 'leading dash'); + ok(!util.valid_host('a..example.com'), 'empty label'); + ok(!util.valid_host('bad host'), 'space'); + ok(!util.valid_host(''), 'empty'); + ok(!util.valid_host(null), 'null'); + let label = replace(sprintf('%63s', ''), ' ', 'a'); + ok(util.valid_host(`${label}.example`), '63-char label'); + ok(!util.valid_host(`${label}a.example`), '64-char label'); + ok(!util.valid_host(join('.', [ label, label, label, label, 'x' ])), 'over 253 characters'); +}); + +test('valid_date', () => { + ok(util.valid_date('2026-01-31'), 'ISO day'); + ok(!util.valid_date('2026-1-31'), 'no padding'); + ok(!util.valid_date('20260131'), 'no dashes'); + ok(!util.valid_date('2026-01-31T00:00'), 'trailing time'); + ok(!util.valid_date(20260131), 'not a string'); +}); + +test('valid_slug and valid_key', () => { + ok(util.valid_slug('alice'), 'word'); + ok(util.valid_slug('a'), 'one character'); + ok(util.valid_slug('alice-2'), 'dash inside'); + ok(!util.valid_slug('-alice'), 'leading dash'); + ok(!util.valid_slug('Alice'), 'upper case'); + ok(!util.valid_slug(replace(sprintf('%33s', ''), ' ', 'a')), '33 characters'); + ok(util.valid_key('yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk='), 'WireGuard key'); + ok(!util.valid_key('yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk'), 'no padding'); + ok(!util.valid_key('yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmb='), 'impossible last sextet'); + ok(!util.valid_key(''), 'empty'); +}); + +test('ip2int / int2ip / cidr_any', () => { + eq(util.ip2int('10.9.0.1'), 168361985, 'ip2int'); + eq(util.int2ip(168361985), '10.9.0.1', 'int2ip'); + eq(util.ip2int('256.0.0.1'), null, 'octet over 255'); + eq(util.ip2int('1.2.3'), null, 'three octets'); + eq(util.cidr_any('10.0.0.5'), { net: util.ip2int('10.0.0.5'), prefix: 32, size: 1, ip: util.ip2int('10.0.0.5') }, 'bare address is a /32'); + eq(util.cidr_any('10.0.0.5/8'), { net: util.ip2int('10.0.0.0'), prefix: 8, size: 16777216, ip: util.ip2int('10.0.0.5') }, 'masked base'); + eq(util.cidr_any('10.0.0.0/33'), null, 'prefix over 32'); + eq(util.cidr_any(null), null, 'null'); + eq(util.in_nets('10.9.0.7', [ '192.168.0.0/16', '10.9.0.0/29' ]), '10.9.0.0/29', 'first match'); + eq(util.in_nets('10.9.0.8', [ '10.9.0.0/29' ]), null, 'just outside'); + eq(util.in_nets('nonsense', [ '10.9.0.0/29' ]), null, 'not an address'); +}); + +test('parse_cidr', () => { + let c = util.parse_cidr('10.9.0.0/24'); + eq([ util.int2ip(c.net), c.prefix, c.size, util.int2ip(c.first), util.int2ip(c.last) ], [ '10.9.0.0', 24, 256, '10.9.0.1', '10.9.0.254' ], '/24'); + eq(util.int2ip(util.parse_cidr('10.9.0.77/24').net), '10.9.0.0', 'host bits masked off'); + eq(util.cidr_str(util.parse_cidr('10.9.0.77/24')), '10.9.0.0/24', 'cidr_str'); + eq(util.parse_cidr('10.9.0.0/7'), null, 'too wide'); + eq(util.parse_cidr('10.9.0.0/31'), null, 'too narrow'); + eq(util.parse_cidr('10.9.0.0'), null, 'no prefix'); + eq(util.parse_cidr('300.0.0.0/24'), null, 'bad octet'); + eq(util.parse_cidr(null), null, 'null'); + ok(util.cidr_overlaps(util.parse_cidr('10.9.0.0/24'), util.parse_cidr('10.9.0.128/25')), 'overlap'); + ok(!util.cidr_overlaps(util.parse_cidr('10.9.0.0/24'), util.parse_cidr('10.9.1.0/24')), 'adjacent'); + ok(util.in_cidr('10.9.0.200', util.parse_cidr('10.9.0.0/24')), 'in_cidr'); + ok(!util.in_cidr('10.9.1.1', util.parse_cidr('10.9.0.0/24')), 'not in_cidr'); +}); + +test('cloudflare_ip', () => { + ok(util.cloudflare_ip('104.16.1.1'), 'v4 range'); + ok(util.cloudflare_ip('2606:4700::1'), 'v6 range'); + ok(!util.cloudflare_ip('8.8.8.8'), 'other v4'); + ok(!util.cloudflare_ip('2001:db8::1'), 'other v6'); + ok(!util.cloudflare_ip(null), 'null'); +}); + +test('slugify', () => { + eq(util.slugify('Alice Smith'), 'alice-smith', 'spaces to dashes'); + eq(util.slugify(' --Bob!! '), 'bob', 'trimmed dashes'); + eq(util.slugify(''), 'user', 'empty'); + eq(util.slugify(null), 'user', 'null'); + eq(util.slugify('Мама'), 'user', 'nothing left'); + eq(length(util.slugify(replace(sprintf('%40s', ''), ' ', 'x'))), 32, 'cut at 32'); +}); + +test('dates', () => { + let end = util.date_end('2026-02-28'); + let t = localtime(end); + eq([ t.year, t.mon, t.mday, t.hour, t.min, t.sec ], [ 2026, 2, 28, 23, 59, 59 ], 'end of the local day'); + eq(util.date_end('2026-2-28'), null, 'bad date'); + let noon = timelocal({ year: 2026, mon: 3, mday: 1, hour: 12, min: 0, sec: 0 }); + eq(util.day_key(noon), '2026-03-01', 'day_key'); + eq(util.month_key(noon), '2026-03', 'month_key'); + eq(util.day_key_ago(1, noon), '2026-02-28', 'day_key_ago crosses the month'); + eq(util.day_key_ago(0, noon), '2026-03-01', 'zero days'); + eq(util.uniq([ 'a', 'b', 'a', 'c', 'b' ]), [ 'a', 'b', 'c' ], 'uniq'); +}); diff --git a/uninstall.sh b/uninstall.sh index f7c19f8..3198b69 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -452,6 +452,10 @@ do_backup() { do_teardown() { step "Running Dawnline's own removal" if ubus list luci.dawnline >/dev/null 2>&1; then + # The removal takes the update lock itself: hand it over (the service is + # stopped first, so no automatic update can slip in between). + [ "$DRY_RUN" -eq 1 ] || /etc/init.d/dawnline stop >/dev/null 2>&1 + exec 8>&- 2>/dev/null # The same call as Settings → Remove Dawnline from this router. if act "call luci.dawnline uninstall (Settings → Remove Dawnline)" rpc \ ubus -t 120 call luci.dawnline uninstall '{"confirm":"remove"}'; then diff --git a/web/package-lock.json b/web/package-lock.json index 57a3efe..6bb7f6b 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -1,17 +1,18 @@ { "name": "dawnline-web", - "version": "0.5.2", + "version": "0.6.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "dawnline-web", - "version": "0.5.2", + "version": "0.6.0", "license": "MIT", "dependencies": { "qrcode-generator": "1.4.4" }, "devDependencies": { + "@types/node": "22.20.5", "prettier": "3.6.2", "tsup": "8.5.0", "typescript": "5.9.3", @@ -933,6 +934,16 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/node": { + "version": "22.20.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.20.5.tgz", + "integrity": "sha512-U2+DNr+wSjpsTS/wZGYHq7GcwfuSmKiKvoPvK22zwTlRhU91yOniN4qRR5KhIjvif7ysw/dz/hKmfDH0Ris4aA==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~6.21.0" + } + }, "node_modules/@vitest/expect": { "version": "3.2.4", "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-3.2.4.tgz", @@ -1973,6 +1984,13 @@ "dev": true, "license": "MIT" }, + "node_modules/undici-types": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", + "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", + "dev": true, + "license": "MIT" + }, "node_modules/vite": { "version": "7.3.7", "resolved": "https://registry.npmjs.org/vite/-/vite-7.3.7.tgz", diff --git a/web/package.json b/web/package.json index 4fd0718..9038d6e 100644 --- a/web/package.json +++ b/web/package.json @@ -1,13 +1,13 @@ { "name": "dawnline-web", - "version": "0.5.2", + "version": "0.6.0", "private": true, "license": "MIT", "type": "module", "scripts": { "build": "tsc --noEmit && tsup", "dev": "tsup --watch", - "typecheck": "tsc --noEmit", + "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json", "test": "vitest run", "format": "prettier --write .", "format:check": "prettier --check .", @@ -17,6 +17,7 @@ "qrcode-generator": "1.4.4" }, "devDependencies": { + "@types/node": "22.20.5", "prettier": "3.6.2", "tsup": "8.5.0", "typescript": "5.9.3", diff --git a/web/src/admin/api.ts b/web/src/admin/api.ts index 2cc429d..299ded8 100644 --- a/web/src/admin/api.ts +++ b/web/src/admin/api.ts @@ -1,15 +1,23 @@ -// luci.dawnline RPC bindings. The backend reports failures as { error }. +// luci.dawnline RPC bindings. The backend reports failures as { error }, and +// a change the router saved but could not fully put into effect (access rules +// that did not load, a server that refused its devices) as { warning }. import type { Network, PortHold } from './netcheck'; import type { AwgCaps, AwgState, Circle, ClientConfig, DayUsage, HealthCheck, LogEvent, MeshMode, Person, Status } from '../shared/types'; +import { notify } from './ui/toast'; + +/** Throw a backend failure; show a warning the answer carries. */ +function settle(r: any): T { + if (r && typeof r === 'object') { + if (typeof r.error === 'string') throw new Error(r.error); + if (typeof r.warning === 'string' && r.warning) notify(r.warning, 'warning', 12000); + } + return r as T; +} function call(method: string, params: string[] = []) { const fn = rpc.declare({ object: 'luci.dawnline', method, params }); - return async (...args: unknown[]): Promise => { - const r = await fn(...args); - if (r && typeof r === 'object' && typeof r.error === 'string') throw new Error(r.error); - return r as T; - }; + return async (...args: unknown[]): Promise => settle(await fn(...args)); } export interface SetupDefaults { @@ -360,9 +368,7 @@ async function personUpdate(id: string, patch: PersonPatch): Promise<{ person: P 'dns_mode', ] as const; const args: unknown[] = [id, ...keys.map((k) => patch[k]), patch.paused, patch.services, patch.circle, patch.home_nets]; - const r = await personUpdateRaw(...args); - if (r && typeof r.error === 'string') throw new Error(r.error); - return r; + return settle(await personUpdateRaw(...args)); } const status = call('status', ['days']); @@ -459,7 +465,8 @@ export const api = { 'quota_period', ]), personPause: call('person_pause', ['id', 'paused']), - personRegen: call<{ link: string | null }>('person_regen', ['id']), + /** A new link; `remove` lists devices (ids) to take away with the old one. */ + personRegen: call<{ link: string | null; removed: number }>('person_regen', ['id', 'remove']), personDelete: call('person_delete', ['id']), personUsage: call<{ person: DayUsage[]; devices: Record }>('person_usage', ['id', 'days']), deviceCreate: call<{ id: string; config: ClientConfig }>('device_create', ['person', 'name', 'kind']), diff --git a/web/src/admin/disguise.ts b/web/src/admin/disguise.ts index d251621..6e83d38 100644 --- a/web/src/admin/disguise.ts +++ b/web/src/admin/disguise.ts @@ -5,6 +5,8 @@ import { E } from './e'; import { icon } from '../shared/icons'; export type Method = 'standard' | 'strong' | 'max' | 'off'; +/** The router features a method may need (the boolean ones of AwgCaps). */ +export type AwgNeed = 'v2' | 'v3'; export interface MethodInfo { id: Method; @@ -19,7 +21,7 @@ export interface MethodInfo { /** The same, short (server header). */ short: string; /** Router capability it needs. */ - needs?: keyof AwgCaps; + needs?: AwgNeed; } export const METHODS: MethodInfo[] = [ @@ -68,13 +70,13 @@ export const METHODS: MethodInfo[] = [ export const methodInfo = (id: string): MethodInfo | undefined => METHODS.find((x) => x.id === id); -const NEEDS: Record = { +const NEEDS: Record = { v2: 'Needs AmneziaWG 1.5 or newer on the router.', v3: 'Needs AmneziaWG 3.1 on the router (kmod-amneziawg and amneziawg-tools 3.1).', }; /** The same while no AmneziaWG is installed at all ("newer" would be misleading). */ -const NEEDS_NONE: Record = { +const NEEDS_NONE: Record = { v2: 'Needs AmneziaWG on the router.', v3: 'Needs AmneziaWG 3.1 on the router: install it first.', }; diff --git a/web/src/admin/pages/person/dialogs.ts b/web/src/admin/pages/person/dialogs.ts index 494a4e1..41114df 100644 --- a/web/src/admin/pages/person/dialogs.ts +++ b/web/src/admin/pages/person/dialogs.ts @@ -18,11 +18,40 @@ export function invite(page: PersonPage) { void inviteCard(page.p, server); } +/** + * A new link locks the old one out of the portal, but not what it already + * got: devices added through it keep their tunnel. They are offered for + * removal here, ticked, so a leaked link is really contained. + */ export async function newLink(page: PersonPage) { const p = page.p; - if (!(await confirmDialog('Create a new link?', 'The old link stops working right away.', 'Create new link', true))) return; - const r = await attempt(() => api.personRegen(p.id), 'New link created'); - if (r?.link) await copyText(r.link, 'New link copied'); + const since = p.code_set ?? 0; + const suspect = p.devices.filter((d) => d.created_by === 'portal' && d.created >= since); + const boxes = suspect.map( + (d) => E('input', { type: 'checkbox', id: `dl-rm-${d.id}`, checked: 'checked', 'data-id': d.id }) as HTMLInputElement, + ); + const body: Node[] = [E('p', {}, 'The old link stops working right away.')]; + if (suspect.length) + body.push( + E('p', {}, 'Devices added through the old link keep working until they are removed. Remove them too:'), + E( + 'div', + { class: 'dl-checklist' }, + suspect.map((d, i) => E('label', { for: `dl-rm-${d.id}` }, [boxes[i], ` ${d.name}`])), + ), + ); + const go = async () => { + const remove = boxes.filter((b) => b.checked).map((b) => b.dataset.id as string); + const r = await attempt( + () => api.personRegen(p.id, remove), + remove.length ? `New link created, ${remove.length} device${remove.length === 1 ? '' : 's'} removed` : 'New link created', + ); + if (!r) return; + closeModal(); + if (remove.length) await page.refresh(); + if (r.link) await copyText(r.link, 'New link copied'); + }; + modal('Create a new link?', body, [cancelButton(), ' ', button('Create new link', go, 'negative')]); } export function editNote(page: PersonPage) { diff --git a/web/src/admin/styles/dialogs.css b/web/src/admin/styles/dialogs.css index a0cbd67..fe39cb2 100644 --- a/web/src/admin/styles/dialogs.css +++ b/web/src/admin/styles/dialogs.css @@ -16,6 +16,10 @@ /* dialogs */ .dl-modal .cbi-tabmenu { margin-bottom: 16px; } +/* A list of things to tick (devices to remove with an old link). */ +.dl-checklist { display: flex; flex-direction: column; gap: 6px; margin: 4px 0 8px; } +.dl-checklist label { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; } +.dl-checklist input { margin: 0; } .dl-invite { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 22px; align-items: start; } .dl-invite img { display: block; width: 100%; border-radius: 18px; box-shadow: 0 0 0 1px var(--dl-line); } .dl-invite-side { display: flex; flex-direction: column; gap: 14px; min-width: 0; } diff --git a/web/src/admin/widgets/health.ts b/web/src/admin/widgets/health.ts index 16a8723..15b32ee 100644 --- a/web/src/admin/widgets/health.ts +++ b/web/src/admin/widgets/health.ts @@ -51,6 +51,7 @@ function checkIcon(id: string): string { if (id === 'clock') return 'clock'; if (id === 'agent') return 'activity'; if (id === 'nft') return 'lock'; + if (id === 'data') return 'users'; return 'alert'; } diff --git a/web/src/portal/main.ts b/web/src/portal/main.ts index 870b833..a7384ae 100644 --- a/web/src/portal/main.ts +++ b/web/src/portal/main.ts @@ -34,6 +34,8 @@ interface State { can_add: boolean; /** The admin stopped the person (paused, access ended): the page only shows. */ locked?: boolean; + /** Over plain HTTP: the same link over HTTPS, where the connection settings are. */ + https_url?: string | null; kinds: Kind[]; version: string; /** The router's day (YYYY-MM-DD) when it sends one; the browser's otherwise. */ @@ -87,6 +89,8 @@ class ApiError extends Error { constructor( public status: number, message: string, + /** The HTTPS twin of this link, when the answer was "not over plain HTTP". */ + public httpsUrl?: string, ) { super(message); } @@ -106,7 +110,7 @@ async function call(path: string, body?: unknown): Promise { } catch { /* empty */ } - if (!res.ok) throw new ApiError(res.status, data?.error ?? `Request failed (${res.status})`); + if (!res.ok) throw new ApiError(res.status, data?.error ?? `Request failed (${res.status})`, data?.https_url || undefined); return data as T; } @@ -682,11 +686,44 @@ function main(st: State) { /* ---------- device flows ---------- */ +/** + * A plain-HTTP link (an IP address) shows the page, but keys only travel + * encrypted: the connection settings are on the HTTPS twin. Its certificate + * is the router's own, so the browser warns once; say so. + */ +function secureSheet(url: string) { + sheet( + 'Open the link securely', + 'Connection settings only travel encrypted', + h( + 'div', + { class: 'stack gap' }, + h('p', { class: 'muted' }, 'This page is open without encryption. To add or set up a device, open the same link over HTTPS:'), + h('a', { class: 'btn primary block big', href: url }, ic('lock'), h('span', {}, 'Open securely')), + h( + 'p', + { class: 'faint s' }, + 'The browser may warn that the certificate is not trusted: it is this router’s own. Choose to continue (“Advanced” → “Proceed”).', + ), + ), + ); +} + +/** The secure twin when this page is plain HTTP, else null. */ +const httpsTwin = () => state?.https_url || null; + async function getConfig(d: Device): Promise { + const twin = httpsTwin(); + if (twin) { + secureSheet(twin); + return null; + } try { return await call(`devices/${d.id}/config`); } catch (e) { - toast((e as Error).message, true); + const er = e as ApiError; + if (er.httpsUrl) secureSheet(er.httpsUrl); + else toast(er.message, true); return null; } } @@ -844,15 +881,47 @@ async function connect(d: Device, initial?: 'app' | 'qr' | 'key' | 'file', cfgIn else live.replaceChildren(h('span', { class: 'warn' }, 'Waiting for the first connection…')); }; paintLive(d); - const watch = window.setInterval(async () => { + // Only while the first connection is awaited (every poll is a process on + // the router): 5 s at first, then slower, for ten minutes at most, not + // while the tab is hidden, and never again once the link stopped working + // (a replaced link would otherwise count as guesses from this network). + let timer = 0, + polls = 0, + done = !!d.handshake || d.disabled; + const started = Date.now(); + const poll = async () => { + timer = 0; + if (done || Date.now() - started > 600_000) return; + if (document.hidden) { + schedule(); + return; + } try { const st = await call('state'); state = st; - paintLive(st.person.devices.find((x) => x.id === d.id)); - } catch { - /* ignore */ + const dev = st.person.devices.find((x) => x.id === d.id); + paintLive(dev); + if (dev?.online || dev?.handshake) { + done = true; + return; + } + } catch (e) { + if ((e as ApiError).status === 404 || (e as ApiError).status === 401) { + done = true; + return; + } } - }, 5000); + polls++; + schedule(); + }; + const schedule = () => { + if (!done && !timer) timer = window.setTimeout(poll, polls < 6 ? 5000 : polls < 12 ? 15000 : 30000); + }; + const onVisible = () => { + if (!document.hidden && !done && !timer) void poll(); + }; + document.addEventListener('visibilitychange', onVisible); + schedule(); sheet( d.handshake ? `Connect ${d.name}` : `${d.name} is ready`, mobile ? 'Add it to AmneziaVPN on this phone' : 'Scan with the phone’s camera or AmneziaVPN', @@ -861,7 +930,9 @@ async function connect(d: Device, initial?: 'app' | 'qr' | 'key' | 'file', cfgIn live, ); sheetClosed = () => { - clearInterval(watch); + done = true; + if (timer) clearTimeout(timer); + document.removeEventListener('visibilitychange', onVisible); if (state) main(state); }; } @@ -1023,6 +1094,11 @@ function guessName(kind: Kind): string { function addDevice() { if (!state) return; + const twin = httpsTwin(); + if (twin) { + secureSheet(twin); + return; + } let kind: Kind = guessKind(); const taken = new Set(state.person.devices.map((d) => d.name.toLowerCase())); const suggest = (k: Kind) => { @@ -1084,6 +1160,10 @@ function addDevice() { const dev = r.state.person.devices.find((d) => d.id === r.id)!; await connect(dev, undefined, r.config); } catch (er) { + if ((er as ApiError).httpsUrl) { + secureSheet((er as ApiError).httpsUrl as string); + return; + } err.textContent = (er as Error).message; submit.disabled = false; } diff --git a/web/src/shared/types.ts b/web/src/shared/types.ts index af10477..92df098 100644 --- a/web/src/shared/types.ts +++ b/web/src/shared/types.ts @@ -64,6 +64,8 @@ export interface Person { /** Circle id on their server (when the server uses circles); admin only. */ circle?: string; created?: number; + /** When the personal link was last made (0: unknown); admin only. */ + code_set?: number; } export type MeshMode = 'off' | 'all' | 'circles'; @@ -170,6 +172,11 @@ export interface Geo { export interface AwgCaps { v2: boolean; v3: boolean; + /** Generations of the tools and the kernel module ('1.0' | '2.0' | '3.1'; null unknown). */ + tools?: string | null; + kmod?: string | null; + /** The two differ: a feature counts only when both have it. */ + mismatch?: boolean; } /** Whether AmneziaWG can run here: tools and kernel module installed, the module loaded, netifd's proto handler present. */ diff --git a/web/tsconfig.json b/web/tsconfig.json index dc721b4..48ea944 100644 --- a/web/tsconfig.json +++ b/web/tsconfig.json @@ -9,7 +9,8 @@ "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, - "noEmit": true + "noEmit": true, + "types": [] }, "include": ["src"] } diff --git a/web/tsconfig.test.json b/web/tsconfig.test.json new file mode 100644 index 0000000..3946579 --- /dev/null +++ b/web/tsconfig.test.json @@ -0,0 +1,5 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { "types": ["node"] }, + "include": ["src", "tests"] +}