From 82ab86848e4b40166f866f02f9b8eab7b81cb360 Mon Sep 17 00:00:00 2001 From: Aemeath <35622087+tickcount@users.noreply.github.com> Date: Thu, 15 Oct 2026 17:05:24 +0300 Subject: [PATCH] Dawnline 0.2.0 - Diagnostics page: Health and Log tabs in place of Health and Activity - Watchdog: repairs the AmneziaWG module, tunnels, nft table, firewall rules, uhttpd portal setting, portal, resolver and rpcd after two bad checks in a row, with backoff; after 3 failed repairs logs once in red, keeps repairing quietly and logs "restored" when it works again - Heartbeat cron job restarts a hung agent - Service log: tunnel and service starts with reasons (restarted, router start, update, crash), stops Dawnline made itself vs unexpected ones, certificate renewal and expiry, WAN address changes - Admin actions logged as "You ..." with their own icon and tint; every event has an icon tile; names kept for removed people and devices; server pill on events when there are several servers - Log filters: All, Connections, People, System, Problems; search and the command palette removed - Home network reaches people's devices: fw4 forwarding from the home zones, limited to people with home access - "Devices reach each other" per server, in the Access card - Portal: "This device" card first with a dotted border, key rotation and copy address in the menu, devices sorted Online/Offline/Not set up/Paused, over-limit slots in orange - People cards: slot bar, Online / Never connected, add chip always shown - Person and device pages: Add device tile, Connect at the bottom with File/Key/QR tabs, status text without dots; pulsing server tab dot - Server pill: Running / Not running / Turned off --- .github/workflows/ci.yml | 3 +- README.md | 16 +- package/luci-app-dawnline/Makefile | 2 +- .../luci-static/resources/dawnline/app.js | 19 +- .../resources/view/dawnline/diagnostics.js | 5 + .../root/etc/hotplug.d/iface/95-dawnline | 10 +- .../root/etc/init.d/dawnline | 6 + .../root/etc/uci-defaults/90_dawnline | 7 + .../luci-app-dawnline/root/usr/bin/dawnline | 44 ++- .../root/usr/libexec/dawnline/agent | 134 +++++++-- .../root/usr/libexec/dawnline/heartbeat | 24 ++ .../root/usr/libexec/dawnline/updater | 24 +- .../share/dawnline/portal/assets/portal.css | 2 +- .../share/dawnline/portal/assets/portal.js | 12 +- .../share/dawnline/portal/www/cgi-bin/portal | 32 ++- .../share/luci/menu.d/luci-app-dawnline.json | 12 +- .../share/rpcd/acl.d/luci-app-dawnline.json | 1 + .../root/usr/share/rpcd/ucode/luci.dawnline | 160 +++++++++-- .../root/usr/share/ucode/dawnline/apply.uc | 130 +++++++-- .../root/usr/share/ucode/dawnline/core.uc | 10 +- .../root/usr/share/ucode/dawnline/live.uc | 30 +- .../root/usr/share/ucode/dawnline/loop.uc | 27 +- .../root/usr/share/ucode/dawnline/ops.uc | 12 +- .../root/usr/share/ucode/dawnline/util.uc | 127 ++++++++- .../root/usr/share/ucode/dawnline/watchdog.uc | 190 +++++++++++++ web/package-lock.json | 4 +- web/package.json | 2 +- web/src/admin/api.ts | 51 +++- web/src/admin/device.ts | 145 +++++----- web/src/admin/interfaces.ts | 45 ++- web/src/admin/logs.ts | 87 ++++-- web/src/admin/luci.d.ts | 2 + web/src/admin/main.ts | 26 +- web/src/admin/pages/activity.ts | 260 +++++++++++------- web/src/admin/pages/diagnostics.ts | 94 +++++++ web/src/admin/pages/maintenance.ts | 258 ++++++++++++----- web/src/admin/pages/overview.ts | 181 ++++++++++-- web/src/admin/pages/people.ts | 104 +++---- web/src/admin/pages/person.ts | 106 +++---- web/src/admin/pages/server.ts | 18 +- web/src/admin/pages/settings.ts | 2 - web/src/admin/palette.ts | 255 ----------------- web/src/admin/styles.ts | 123 +++++---- web/src/admin/urls.ts | 10 + web/src/portal/main.ts | 178 +++++++++--- web/src/portal/portal.css | 128 +++++---- web/src/shared/format.ts | 9 + web/src/shared/icons.ts | 3 +- web/src/shared/types.ts | 8 + web/tests/shared.test.ts | 10 +- 50 files changed, 2166 insertions(+), 982 deletions(-) create mode 100644 package/luci-app-dawnline/htdocs/luci-static/resources/view/dawnline/diagnostics.js mode change 100644 => 100755 package/luci-app-dawnline/root/etc/hotplug.d/iface/95-dawnline create mode 100755 package/luci-app-dawnline/root/usr/libexec/dawnline/heartbeat create mode 100644 package/luci-app-dawnline/root/usr/share/ucode/dawnline/watchdog.uc create mode 100644 web/src/admin/pages/diagnostics.ts delete mode 100644 web/src/admin/palette.ts create mode 100644 web/src/admin/urls.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e54e375..b15e48e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -87,6 +87,7 @@ jobs: 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 ucode: @@ -102,7 +103,7 @@ jobs: - 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 \ + 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 [ -x "$f" ] || { echo "::error file=$f::not executable (git update-index --chmod=+x $f)"; exit 1; } done diff --git a/README.md b/README.md index 9dbc131..94126ba 100644 --- a/README.md +++ b/README.md @@ -52,9 +52,14 @@ limits, live traffic and a LuCI admin that follows a modern design. per-tool integration. - **Overview.** Who is online with what, speed now, today and the last 30 days, and a map of where people connect from (city level). -- **Health** checks with one-click fixes, including the ones that matter for - reaching the portal from outside (DNS, port forwards, reply routing behind - proxies such as SSClash/Mihomo, certificate coverage). +- **Diagnostics.** Health checks with one-click fixes, including the ones that + matter for reaching the portal from outside (DNS, port forwards, reply + routing behind proxies such as SSClash/Mihomo, certificate coverage). A + watchdog checks the tunnels, access rules, portal, resolver and LuCI link + every minute and repairs them on its own (a cron job looks after the agent + itself). One log holds people's activity and the service log: tunnel starts + and stops with netifd's reasons, repairs and errors (`dawnline log` on the + router). - **Updates.** Dawnline itself, AmneziaWG builds for your firmware (choose between [Slava-Shchipunov](https://github.com/Slava-Shchipunov/awg-openwrt) and [2Grey](https://github.com/2Grey/awg-openwrt), AmneziaWG 2.0 or 3.1), and @@ -110,8 +115,9 @@ sections named `dawnline_*`, the `inet dawnline` nft table, `/tmp/hosts/dawnline the `dawnline` network namespace with its two veth links (`dlx0`, `dll0`, the latter a port of the LAN bridge), policy rules for the tunnel interfaces with one routing table, a second dnsmasq instance on port 5354 -(`/var/etc/dawnline-dns.conf`) and, while the portal is on, a uhttpd instance -for it. `dawnline teardown` removes all of them. +(`/var/etc/dawnline-dns.conf`), a cron line for the agent's heartbeat check +and, while the portal is on, a uhttpd instance for it. `dawnline teardown` +removes all of them. Data lives in `/etc/config/dawnline` (mode 0600, contains private keys) and `/etc/dawnline/` (usage, events, issued configurations, backups). Live counters diff --git a/package/luci-app-dawnline/Makefile b/package/luci-app-dawnline/Makefile index c8fca6b..e853196 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.1.1 +PKG_VERSION:=0.2.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 2d077a6..7bea7c6 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 @@ -7,13 +7,14 @@ 'require rpc'; 'require uci'; 'require ui'; -var yn=Object.create;var Ft=Object.defineProperty;var kn=Object.getOwnPropertyDescriptor;var $n=Object.getOwnPropertyNames;var _n=Object.getPrototypeOf,Mn=Object.prototype.hasOwnProperty;var Ln=(o,t)=>()=>(t||o((t={exports:{}}).exports,t),t.exports);var Sn=(o,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of $n(t))!Mn.call(o,i)&&i!==n&&Ft(o,i,{get:()=>t[i],enumerable:!(a=kn(t,i))||a.enumerable});return o};var Tn=(o,t,n)=>(n=o!=null?yn(_n(o)):{},Sn(t||!o||!o.__esModule?Ft(n,"default",{value:o,enumerable:!0}):n,o));var Jt=Ln((Vt,Yt)=>{"use strict";var Kt=(function(){var o=function(y,D){var T=236,f=17,g=y,_=n[D],c=null,u=0,C=null,v=[],b={},j=function(M,S){u=g*4+17,c=(function(x){for(var E=new Array(x),A=0;A=7&&ie(M),C==null&&(C=yt(g,_,v)),fe(C,S)},q=function(M,S){for(var x=-1;x<=7;x+=1)if(!(M+x<=-1||u<=M+x))for(var E=-1;E<=7;E+=1)S+E<=-1||u<=S+E||(0<=x&&x<=6&&(E==0||E==6)||0<=E&&E<=6&&(x==0||x==6)||2<=x&&x<=4&&2<=E&&E<=4?c[M+x][S+E]=!0:c[M+x][S+E]=!1)},I=function(){for(var M=0,S=0,x=0;x<8;x+=1){j(!0,x);var E=i.getLostPoint(b);(x==0||M>E)&&(M=E,S=x)}return S},Z=function(){for(var M=8;M>x&1)==1;c[Math.floor(x/3)][x%3+u-8-3]=E}for(var x=0;x<18;x+=1){var E=!M&&(S>>x&1)==1;c[x%3+u-8-3][Math.floor(x/3)]=E}},he=function(M,S){for(var x=_<<3|S,E=i.getBCHTypeInfo(x),A=0;A<15;A+=1){var B=!M&&(E>>A&1)==1;A<6?c[A][8]=B:A<8?c[A+1][8]=B:c[u-15+A][8]=B}for(var A=0;A<15;A+=1){var B=!M&&(E>>A&1)==1;A<8?c[8][u-A-1]=B:A<9?c[8][15-A-1+1]=B:c[8][15-A-1]=B}c[u-8][8]=!M},fe=function(M,S){for(var x=-1,E=u-1,A=7,B=0,G=i.getMaskFunction(S),U=u-1;U>0;U-=2)for(U==6&&(U-=1);;){for(var te=0;te<2;te+=1)if(c[E][U-te]==null){var de=!1;B>>A&1)==1);var W=G(E,U-te);W&&(de=!de),c[E][U-te]=de,A-=1,A==-1&&(B+=1,A=7)}if(E+=x,E<0||u<=E){E-=x,x=-x;break}}},Te=function(M,S){for(var x=0,E=0,A=0,B=new Array(S.length),G=new Array(S.length),U=0;U=0?qt.getAt(Ut):0}}for(var Gt=0,W=0;WU*8)throw"code length overflow. ("+A.getLengthInBits()+">"+U*8+")";for(A.getLengthInBits()+4<=U*8&&A.put(0,4);A.getLengthInBits()%8!=0;)A.putBit(!1);for(;!(A.getLengthInBits()>=U*8||(A.put(T,8),A.getLengthInBits()>=U*8));)A.put(f,8);return Te(A,E)};b.addData=function(M,S){S=S||"Byte";var x=null;switch(S){case"Numeric":x=h(M);break;case"Alphanumeric":x=m(M);break;case"Byte":x=p(M);break;case"Kanji":x=$(M);break;default:throw"mode:"+S}v.push(x),C=null},b.isDark=function(M,S){if(M<0||u<=M||S<0||u<=S)throw M+","+S;return c[M][S]},b.getModuleCount=function(){return u},b.make=function(){if(g<1){for(var M=1;M<40;M++){for(var S=l.getRSBlocks(M,_),x=d(),E=0;E"u"?M*4:S;var x="";x+='";for(var A=0;A';x+=""}return x+="",x+="
",x},b.createSvgTag=function(M,S,x,E){var A={};typeof arguments[0]=="object"&&(A=arguments[0],M=A.cellSize,S=A.margin,x=A.alt,E=A.title),M=M||2,S=typeof S>"u"?M*4:S,x=typeof x=="string"?{text:x}:x||{},x.text=x.text||null,x.id=x.text?x.id||"qrcode-description":null,E=typeof E=="string"?{text:E}:E||{},E.text=E.text||null,E.id=E.text?E.id||"qrcode-title":null;var B=b.getModuleCount()*M+S*2,G,U,te,de,W="",me;for(me="l"+M+",0 0,"+M+" -"+M+",0 0,-"+M+"z ",W+=''+R(E.text)+"":"",W+=x.text?''+R(x.text)+"":"",W+='',W+='"u"?M*4:S;var x=b.getModuleCount()*M+S*2,E=S,A=x-S;return H(x,x,function(B,G){if(E<=B&&B"u"?M*4:S;var E=b.getModuleCount()*M+S*2,A="";return A+="",A};var R=function(M){for(var S="",x=0;x":S+=">";break;case"&":S+="&";break;case'"':S+=""";break;default:S+=E;break}}return S},se=function(M){var S=1;M=typeof M>"u"?S*2:M;var x=b.getModuleCount()*S+M*2,E=M,A=x-M,B,G,U,te,de,W={"██":"█","█ ":"▀"," █":"▄"," ":" "},me={"██":"▀","█ ":"▀"," █":" "," ":" "},ge="";for(B=0;B=A?me[de]:W[de];ge+=` -`}return x%2&&M>0?ge.substring(0,ge.length-x-1)+Array(x+1).join("▀"):ge.substring(0,ge.length-1)};return b.createASCII=function(M,S){if(M=M||1,M<2)return se(S);M-=1,S=typeof S>"u"?M*2:S;var x=b.getModuleCount()*M+S*2,E=S,A=x-S,B,G,U,te,de=Array(M+1).join("██"),W=Array(M+1).join(" "),me="",ge="";for(B=0;B>>8),_.push(C&255)):_.push(f)}}return _}};var t={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},n={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},i=(function(){var y=[[],[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]],D=1335,T=7973,f=21522,g={},_=function(c){for(var u=0;c!=0;)u+=1,c>>>=1;return u};return g.getBCHTypeInfo=function(c){for(var u=c<<10;_(u)-_(D)>=0;)u^=D<<_(u)-_(D);return(c<<10|u)^f},g.getBCHTypeNumber=function(c){for(var u=c<<12;_(u)-_(T)>=0;)u^=T<<_(u)-_(T);return c<<12|u},g.getPatternPosition=function(c){return y[c-1]},g.getMaskFunction=function(c){switch(c){case a.PATTERN000:return function(u,C){return(u+C)%2==0};case a.PATTERN001:return function(u,C){return u%2==0};case a.PATTERN010:return function(u,C){return C%3==0};case a.PATTERN011:return function(u,C){return(u+C)%3==0};case a.PATTERN100:return function(u,C){return(Math.floor(u/2)+Math.floor(C/3))%2==0};case a.PATTERN101:return function(u,C){return u*C%2+u*C%3==0};case a.PATTERN110:return function(u,C){return(u*C%2+u*C%3)%2==0};case a.PATTERN111:return function(u,C){return(u*C%3+(u+C)%2)%2==0};default:throw"bad maskPattern:"+c}},g.getErrorCorrectPolynomial=function(c){for(var u=r([1],0),C=0;C5&&(C+=3+j-5)}for(var v=0;v=256;)g-=255;return y[g]},f})();function r(y,D){if(typeof y.length>"u")throw y.length+"/"+D;var T=(function(){for(var g=0;g"u")throw"bad rs block @ typeNumber:"+g+"/errorCorrectionLevel:"+_;for(var u=c.length/3,C=[],v=0;v>>7-f%8&1)==1},T.put=function(f,g){for(var _=0;_>>g-_-1&1)==1)},T.getLengthInBits=function(){return D},T.putBit=function(f){var g=Math.floor(D/8);y.length<=g&&y.push(0),f&&(y[g]|=128>>>D%8),D+=1},T},h=function(y){var D=t.MODE_NUMBER,T=y,f={};f.getMode=function(){return D},f.getLength=function(c){return T.length},f.write=function(c){for(var u=T,C=0;C+2>>8&255)*192+(v&255),c.put(v,13),C+=2}if(C>>8)},D.writeBytes=function(T,f,g){f=f||0,g=g||T.length;for(var _=0;_0&&(T+=","),T+=y[f];return T+="]",T},D},z=function(){var y=0,D=0,T=0,f="",g={},_=function(u){f+=String.fromCharCode(c(u&63))},c=function(u){if(!(u<0)){if(u<26)return 65+u;if(u<52)return 97+(u-26);if(u<62)return 48+(u-52);if(u==62)return 43;if(u==63)return 47}throw"n:"+u};return g.writeByte=function(u){for(y=y<<8|u&255,D+=8,T+=1;D>=6;)_(y>>>D-6),D-=6},g.flush=function(){if(D>0&&(_(y<<6-D),y=0,D=0),T%3!=0)for(var u=3-T%3,C=0;C=D.length){if(g==0)return-1;throw"unexpected end of file./"+g}var u=D.charAt(T);if(T+=1,u=="=")return g=0,-1;if(u.match(/^\s$/))continue;f=f<<6|c(u.charCodeAt(0)),g+=6}var C=f>>>g-8&255;return g-=8,C};var c=function(u){if(65<=u&&u<=90)return u-65;if(97<=u&&u<=122)return u-97+26;if(48<=u&&u<=57)return u-48+52;if(u==43)return 62;if(u==47)return 63;throw"c:"+u};return _},F=function(y,D){var T=y,f=D,g=new Array(y*D),_={};_.setPixel=function(v,b,j){g[b*T+v]=j},_.write=function(v){v.writeString("GIF87a"),v.writeShort(T),v.writeShort(f),v.writeByte(128),v.writeByte(0),v.writeByte(0),v.writeByte(0),v.writeByte(0),v.writeByte(0),v.writeByte(255),v.writeByte(255),v.writeByte(255),v.writeString(","),v.writeShort(0),v.writeShort(0),v.writeShort(T),v.writeShort(f),v.writeByte(0);var b=2,j=u(b);v.writeByte(b);for(var q=0;j.length-q>255;)v.writeByte(255),v.writeBytes(j,q,255),q+=255;v.writeByte(j.length-q),v.writeBytes(j,q,j.length-q),v.writeByte(0),v.writeString(";")};var c=function(v){var b=v,j=0,q=0,I={};return I.write=function(Z,ee){if(Z>>>ee)throw"length over";for(;j+ee>=8;)b.writeByte(255&(Z<>>=8-j,q=0,j=0;q=Z<0&&b.writeByte(q)},I},u=function(v){for(var b=1<>6,128|s&63):s<55296||s>=57344?a.push(224|s>>12,128|s>>6&63,128|s&63):(i++,s=65536+((s&1023)<<10|n.charCodeAt(i)&1023),a.push(240|s>>18,128|s>>12&63,128|s>>6&63,128|s&63))}return a}return t(o)}})();(function(o){typeof define=="function"&&define.amd?define([],o):typeof Vt=="object"&&(Yt.exports=o())})(function(){return Kt})});function $t(o,t){return o==null||o===!1||o===""||(Array.isArray(o)?o.forEach(n=>$t(n,t)):t.push(o instanceof Node?o:String(o))),t}function e(o,t,n){let a=window.E,i=t!=null&&typeof t=="object"&&!Array.isArray(t)&&!(t instanceof Node);return!i&&n===void 0?a(o,{},$t(t,[])):a(o,i?t:{},$t(n,[]))}function K(o,t=[]){let n=rpc.declare({object:"luci.dawnline",method:o,params:t});return async(...a)=>{let i=await n(...a);if(i&&typeof i=="object"&&typeof i.error=="string")throw new Error(i.error);return i}}var En=K("logs_clear",["person","device","category","older_days"]),Cn=(o={})=>En(o.person??"",o.device??"",o.category??"",o.older_days??""),Dn=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"]});async function An(o,t){let a=[o,...["name","access","device_limit","expires","expire_action","expire_warn","quota_gb","quota_period","bonus_gb","hours","note","dns_mode"].map(s=>t[s]),t.paused,t.services],i=await Dn(...a);if(i&&typeof i.error=="string")throw new Error(i.error);return i}var Pn=K("status",["days"]),zn=0;async function Nn(o){let t=await Pn(o);return zn=Date.now(),t}var P={personUpdate:An,settingsGet:K("settings_get"),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:Cn,interfaces:K("interfaces",["id"]),serverInterfaces:K("server_interfaces",["id","auto_wan","wan_device","auto_lan","lan_devices","lan_like"]),usageClear:K("usage_clear",["scope","id"]),uninstall:K("uninstall",["confirm"]),status:Nn,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"]),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"]),pauseAll:K("pause_all",["paused"]),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"]),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"])};var Wt={phone:'',computer:'',tablet:'',router:'',other:'',ethernet:'',bridge:'',wifi:'',tunnel:'',plus:'',chart:'',reset:'',package:'',code:'',plug:'',sunrise:'',refresh:'',archive:'',qr:'',copy:'',download:'',link:'',trash:'',edit:'',pause:'',play:'',key:'',out:'',shield:'',shieldplus:'',lock:'',zap:'',check:'',alert:'',x:'',globe:'',home:'',open:'',file:'',search:'',network:'',moon:'',chevron:'',clock:'',calendar:'',minus:'',more:'',pin:'',activity:''};function _t(o,t="dl-icon"){let n=Wt[o]??Wt.phone;return``}function w(o,t="dl-icon"){let n=document.createElement("span");return n.className="dl-icon-wrap",n.innerHTML=_t(o,t),n}function N(o,t,n="neutral",a={}){let{disabled:i,...s}=a,r=e("button",{class:`cbi-button cbi-button-${n}`,type:"button",...s,click:async l=>{if(l.preventDefault(),l.stopPropagation(),!r.disabled){r.disabled=!0,r.classList.add("spinning");try{await t(l)}catch(d){X(Mt(d),"error")}finally{r.disabled=!1,r.classList.remove("spinning")}}}},o);return r.disabled=!!i,r}function ye(o,t,n,a="neutral",i=""){return N([w(o),e("span",{class:"dl-btn-label"},t)],n,a,{title:t,class:`cbi-button cbi-button-${a} dl-icon-btn ${i}`.trim()})}function X(o,t="info",n=0){let a=document.querySelector(".dl-toasts");a||(a=e("div",{class:"dl-toasts dl-root",role:"status","aria-live":"polite"}),document.body.appendChild(a));let i=t==="error"?"x":t==="warning"?"alert":t==="success"?"check":null,s=()=>{r.classList.remove("show"),setTimeout(()=>r.remove(),200)},r=e("div",{class:`dl-toast ${t}`},[i?w(i):"",e("span",{},o),t==="error"?e("button",{type:"button","aria-label":"Close",click:s},w("x")):""]);a.appendChild(r),requestAnimationFrame(()=>r.classList.add("show")),setTimeout(s,n||(t==="error"?8e3:t==="warning"?5e3:2600))}function Mt(o){return o instanceof Error?o.message:String(o)}async function O(o,t){try{let n=await o();return t&&X(t,"success",3500),n}catch(n){X(Mt(n),"error",1e4);return}}function ne(o,t,n,a=""){ui.showModal(o,[e("div",{class:`dl-modal ${a}`},t),e("div",{class:"button-row"},n)])}function J(){ui.hideModal()}function ae(o,t,n="Confirm",a=!1){return new Promise(i=>{ne(o,t,[e("button",{class:"cbi-button cbi-button-neutral",type:"button",click:()=>{J(),i(!1)}},"Cancel")," ",e("button",{class:`cbi-button ${a?"cbi-button-negative":"cbi-button-positive"}`,type:"button",click:()=>{J(),i(!0)}},n)])})}async function re(o,t="Copied to clipboard"){try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(o);else{let n=e("textarea",{style:"position:fixed;opacity:0"},o);document.body.appendChild(n),n.select(),document.execCommand("copy"),n.remove()}X(t,"success",2500)}catch(n){X(Mt(n),"error")}}function ve(o,t,n="text/plain"){let a=globalThis,i=typeof t=="string"?new a.Blob([t],{type:n}):t,s=URL.createObjectURL(i),r=e("a",{href:s,download:o,style:"display:none"});document.body.appendChild(r),r.click(),setTimeout(()=>{URL.revokeObjectURL(s),r.remove()},1e3)}function Ae(o,t){let n={ok:"success",warn:"warning",error:"error",info:"notice"}[o];return e("div",{class:`alert-message ${n}`},t)}function Pe(o,t=""){let n=e("div",{class:t});return n.innerHTML=o,n}function Lt(o,t){return new Promise(n=>{let a=e("input",{type:"file",accept:o,style:"display:none"});a.addEventListener("cancel",()=>{a.remove(),n(null)}),a.addEventListener("change",()=>{let i=a.files?.[0];if(a.remove(),!i)return n(null);let s=new FileReader;s.onload=()=>{let r=String(s.result??"");n({name:i.name,data:t==="base64"?r.replace(/^data:[^,]*,/,""):r})},s.onerror=()=>n(null),t==="base64"?s.readAsDataURL(i):s.readAsText(i)}),document.body.appendChild(a),a.click()})}function ke(o,t){let n=document.querySelector(".dl-dd");if(n&&(n.dlClose?n.dlClose():n.remove(),n.dlAnchor===o))return;let a=e("div",{class:"dl-dd dl-root",role:"menu"},t.map(m=>m?e("button",{type:"button",role:"menuitem",class:m.danger?"danger":m.warn?"warn":"",click:()=>{h(),m.run()}},[m.icon??"",e("span",{},m.label)]):e("hr")));document.body.appendChild(a);let i=o.getBoundingClientRect(),s=a.offsetWidth,r=a.offsetHeight;a.style.top=`${i.bottom+6+r>window.innerHeight-8&&i.top-6-r>8?i.top-6-r:i.bottom+6}px`,a.style.left=`${Math.max(8,Math.min(i.right-s,window.innerWidth-s-8))}px`;let l=m=>{!a.contains(m.target)&&!o.contains(m.target)&&h()},d=m=>{m.key==="Escape"&&h()};a.dlAnchor=o,a.dlClose=h;function h(){a.remove(),document.removeEventListener("mousedown",l,!0),document.removeEventListener("keydown",d,!0),window.removeEventListener("scroll",h,!0)}setTimeout(()=>{document.addEventListener("mousedown",l,!0),document.addEventListener("keydown",d,!0),window.addEventListener("scroll",h,!0)}),a.querySelector("button")?.focus({preventScroll:!0})}var Qt=Tn(Jt(),1),Rn='';function Be(o,t=3,n=!0){let a=(0,Qt.default)(0,o.length>300?"Q":"H");a.addData(o,"Byte"),a.make();let i=a.getModuleCount(),s=i+t*2,r=n?Math.round(i*.22):0;r&&(i-r)%2&&r++;let l=(i-r)/2,d=l+r,h=($,k)=>r>0&&$>=l&&$=l&&k${Rn}`}return`${p}`}var Hn={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:""},In={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 Bn(o){let t={};for(let[n,a]of Object.entries(In))o[n]!=null&&o[n]!==""&&(t[a]=String(o[n]));return t}function jn(o,t){let n=o.amnezia,a=n.obfuscation??{},i=d=>a[d]!=null&&a[d]!==""?String(a[d]):Hn[d],s=n.host.replace(/^\[(.*)\]$/,"$1"),r={H1:i("h1"),H2:i("h2"),H3:i("h3"),H4:i("h4"),I1:i("i1"),I2:i("i2"),I3:i("i3"),I4:i("i4"),I5:i("i5"),Jc:i("jc"),Jmin:i("jmin"),Jmax:i("jmax"),S1:i("s1"),S2:i("s2"),S3:i("s3"),S4:i("s4"),...Bn(a),allowed_ips:n.allowed_ips,client_ip:n.client_ip,client_priv_key:n.client_priv_key,client_pub_key:n.client_pub_key,config:o.conf.replace(/\r?\n/g,`\r -`),hostName:s,mtu:n.mtu,persistent_keep_alive:n.persistent_keep_alive,port:Number(n.port),psk_key:n.psk_key,server_pub_key:n.server_pub_key},l={containers:[{container:"amnezia-awg",awg:{isThirdPartyConfig:!0,last_config:JSON.stringify(r),port:String(n.port),protocol_version:a.header_protection_key?"3.1":"2",transport_proto:"udp"}}],defaultContainer:"amnezia-awg",description:t,hostName:s};return n.dns[0]&&(l.dns1=n.dns[0]),n.dns[1]&&(l.dns2=n.dns[1]),l}function On(o){let t="";for(let n=0;n"u")return null;try{let n=new t.Blob([o]).stream().pipeThrough(new t.CompressionStream("deflate")),a=new Uint8Array(await new t.Response(n).arrayBuffer()),i=new Uint8Array(4+a.length);return new DataView(i.buffer).setUint32(0,o.length,!1),i.set(a,4),i}catch{return null}}async function Zt(o,t,n=!0){let a=new TextEncoder().encode(JSON.stringify(jn(o,t))),i=n?await qn(a):null;return`vpn://${On(i??a)}`}function V(o){if(!o||o<0)return"0 B";let t=["B","KB","MB","GB","TB"],n=0,a=o;for(;a>=1024&&n=100||n===0?Math.round(a):a.toFixed(1)} ${t[n]}`}function $e(o){let t=o*8;return t<1e3?`${Math.round(t)} bit/s`:t<1e6?`${(t/1e3).toFixed(t<1e4?1:0)} kbit/s`:t<1e9?`${(t/1e6).toFixed(t<1e7?1:0)} Mbit/s`:`${(t/1e9).toFixed(1)} Gbit/s`}function ce(o,t=Date.now()/1e3){if(!o)return"never";let n=Math.max(0,Math.round(t-o));return n<60?"just now":n<3600?`${Math.floor(n/60)} min ago`:n<86400?`${Math.floor(n/3600)} h ago`:n<86400*30?`${Math.floor(n/86400)} d ago`:new Date(o*1e3).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function Xt(o){if(!o||o<0)return"—";let t=Math.floor(o/86400),n=Math.floor(o%86400/3600),a=Math.floor(o%3600/60);return t?`${t}d ${n}h`:n?`${n}h ${a}m`:`${a}m`}function St(o){let t=new Date(o*1e3),n=new Date,a=t.toDateString()===n.toDateString(),i=t.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"});return a?i:`${t.toLocaleDateString("en-GB",{day:"numeric",month:"short"})} ${i}`}function _e(o){if(!o)return"";let[t,n,a]=o.split("-").map(Number);return new Date(t,n-1,a).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function ze(o,t=Date.now()){if(!o)return null;let[n,a,i]=o.split("-").map(Number),s=new Date(n,a-1,i,23,59,59).getTime();return Math.ceil((s-t)/864e5)}var je={lan:"Home network",internet:"Internet",both:"Home network + Internet"},en={lan:"LAN",internet:"Internet",both:"LAN + Internet"},tn=["computer","phone","tablet","router","other"],Me={computer:"PC",phone:"Phone",tablet:"Tablet",router:"Router",other:"Other"},Tt={active:"Active",paused:"Paused",paused_all:"Paused (everyone)",expired:"Expired",quota:"Data limit reached",hours:"Outside allowed hours",no_server:"No server"};function Le(o){let t=o.trim().split(/\s+/).filter(Boolean);if(!t.length)return"?";let n=t[0][0]??"",a=t.length>1?t[t.length-1][0]??"":t[0][1]??"";return(n+a).toUpperCase()}var Ne=null;function le(o,t){let n=a=>{Ne??(Ne=document.body.appendChild(e("div",{class:"dl-tip dl-tip-float dl-root"}))),Ne.replaceChildren(...t().map(i=>typeof i=="string"?document.createTextNode(i):i)),Ne.style.display="",Ne.style.left=`${a.clientX}px`,Ne.style.top=`${a.clientY-10}px`};o.addEventListener("mouseenter",n),o.addEventListener("mousemove",n),o.addEventListener("mouseleave",()=>Ne&&(Ne.style.display="none"))}function nn(o,t=120,n=26){let a=Math.max(1,...o),i=e("div",{class:"dl-spark"});i.style.width=`${t}px`,i.style.height=`${n}px`;let s=Date.now();return o.forEach((r,l)=>{let d=e("i");d.style.height=`${Math.max(6,r/a*100)}%`,r||d.classList.add("zero");let h=o.length-1-l,m=new Date(s-h*864e5);le(d,()=>[e("div",{class:"dl-tip-title"},h===0?"Today":h===1?"Yesterday":m.toLocaleDateString("en-GB",{weekday:"short",day:"numeric",month:"short"})),e("div",{class:"dl-muted"},V(r))]),i.appendChild(d)}),i}var Un={connect:"connections",disconnect:"connections",roam:"connections",device_added:"devices",device_removed:"devices",devices_removed:"devices",person_added:"people",person_removed:"people",person_changed:"people",paused:"people",resumed:"people",paused_all:"people",resumed_all:"people",server_down:"problems",server_up:"problems",portal_blocked:"problems"},Oe=["connections","devices","people","problems"],qe={connections:"Connections",devices:"Devices",people:"People",problems:"Problems"},an={connections:"Connects, disconnects and IP changes",devices:"Devices added and removed",people:"People added, changed, paused",problems:"Tunnel down, blocked portal sign-ins"},rt=o=>Un[o]??"problems";function Gn(o){let t=new Map(o.people.map(a=>[a.id,a.name])),n=new Map(o.people.flatMap(a=>a.devices.map(i=>[i.id,i.name])));return{people:t,devices:n}}function Fn(o){let t=o==null?"":String(o);return/[",\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t}function be(o,t,n,a=""){let i=Gn(o),s=t.map(m=>({time:new Date(m.ts*1e3).toISOString(),category:rt(m.type),type:m.type,person:m.person?i.people.get(m.person)??m.person:"",device:m.device?i.devices.get(m.device)??m.device:"",detail:m.detail??"",where:m.where??""})),r=new Date().toISOString().slice(0,10),l=`dawnline-activity${a?`-${a}`:""}-${r}.${n}`;if(n==="json"){ve(l,JSON.stringify(s,null,2),"application/json");return}let d=["time","category","type","person","device","detail","where"],h=[d.join(","),...s.map(m=>d.map(p=>Fn(m[p])).join(","))].join(` -`);ve(l,h,"text/csv")}var Wn=[["","Everything"],["7","Older than 7 days"],["30","Older than 30 days"],["90","Older than 90 days"]];function Ee(o,t,n,a,i){let s=e("select",{class:"cbi-input-select"},[e("option",{value:""},"All categories"),...Oe.map(l=>e("option",{value:l,selected:l===i?"selected":null},qe[l]))]),r=e("select",{class:"cbi-input-select"},Wn.map(([l,d])=>e("option",{value:l},d)));ne(o,[e("p",{class:"dl-muted"},`${t} This cannot be undone; export first if you want a copy.`),e("label",{class:"dl-fld"},[e("span",{class:"dl-fld-label"},"Category"),s]),e("label",{class:"dl-fld"},[e("span",{class:"dl-fld-label"},"Which events"),r])],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",N("Clear",async()=>{let l=await O(()=>P.logsClear({...n,category:s.value,older_days:r.value}));l&&(J(),X(l.removed?`${l.removed} event${l.removed===1?"":"s"} removed`:"Nothing matched","success",3e3),a())},"negative")])}function Ue(o,t,n,a){let i=o==="device"?`Clears ${n}'s daily and monthly traffic history. Their person's totals and data limit are not changed.`:o==="person"?`Clears ${n}'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.";ne(o==="all"?"Reset all traffic history?":`Reset traffic history for ${n}?`,[e("p",{class:"dl-muted"},i)],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",N("Reset",async()=>{await O(()=>P.usageClear(o,t),"Traffic history reset")&&(J(),a())},"negative")])}var lt=null;function Kn(o){return o?new Date(o*1e3).toLocaleString("en-GB",{day:"numeric",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"}):"—"}function on(o,t,n=!0){return e("div",{class:"dl-kvrow"},[e("span",{class:"dl-kvrow-k"},o),e("button",{type:"button",class:`dl-kvrow-v copy${n?" dl-mono":""}`,title:"Copy",click:()=>re(t,`${o} copied`)},[e("span",{},t),w("copy")])])}function dt(o,t){return e("div",{class:"dl-kvrow"},[e("span",{class:"dl-kvrow-k"},o),e("span",{class:"dl-kvrow-v"},t)])}function sn(o,t){if(/^\s*\[.+\]\s*$/.test(o))return e("span",{class:"dl-conf-sec"},o);let n=/^(\s*[A-Za-z0-9]+\s*=)\s*(.*)$/.exec(o);if(!n)return document.createTextNode(o);let a=/^(\s*)(PrivateKey|PresharedKey)\b/.test(o);return e("span",{},[e("span",{class:"dl-conf-k"},n[1])," ",a&&!t?e("span",{class:"dl-conf-mask"},"••••••••••••••••"):n[2]])}function Vn(o){let t=!1,n=e("pre",{class:"dl-conf"}),a=()=>dom.content(n,o.conf.split(` +var $n=Object.create;var Kt=Object.defineProperty;var _n=Object.getOwnPropertyDescriptor;var Ln=Object.getOwnPropertyNames;var Sn=Object.getPrototypeOf,Mn=Object.prototype.hasOwnProperty;var En=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports);var Tn=(s,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ln(t))!Mn.call(s,i)&&i!==n&&Kt(s,i,{get:()=>t[i],enumerable:!(a=_n(t,i))||a.enumerable});return s};var Cn=(s,t,n)=>(n=s!=null?$n(Sn(s)):{},Tn(t||!s||!s.__esModule?Kt(n,"default",{value:s,enumerable:!0}):n,s));var Zt=En((Jt,Qt)=>{"use strict";var Yt=(function(){var s=function(w,D){var E=236,M=17,u=w,$=n[D],h=null,p=0,T=null,m=[],y={},P=function(_,S){p=u*4+17,h=(function(x){for(var C=new Array(x),A=0;A=7&&ie(_),T==null&&(T=$t(u,$,m)),ue(T,S)},O=function(_,S){for(var x=-1;x<=7;x+=1)if(!(_+x<=-1||p<=_+x))for(var C=-1;C<=7;C+=1)S+C<=-1||p<=S+C||(0<=x&&x<=6&&(C==0||C==6)||0<=C&&C<=6&&(x==0||x==6)||2<=x&&x<=4&&2<=C&&C<=4?h[_+x][S+C]=!0:h[_+x][S+C]=!1)},H=function(){for(var _=0,S=0,x=0;x<8;x+=1){P(!0,x);var C=i.getLostPoint(y);(x==0||_>C)&&(_=C,S=x)}return S},Z=function(){for(var _=8;_>x&1)==1;h[Math.floor(x/3)][x%3+p-8-3]=C}for(var x=0;x<18;x+=1){var C=!_&&(S>>x&1)==1;h[x%3+p-8-3][Math.floor(x/3)]=C}},he=function(_,S){for(var x=$<<3|S,C=i.getBCHTypeInfo(x),A=0;A<15;A+=1){var j=!_&&(C>>A&1)==1;A<6?h[A][8]=j:A<8?h[A+1][8]=j:h[p-15+A][8]=j}for(var A=0;A<15;A+=1){var j=!_&&(C>>A&1)==1;A<8?h[8][p-A-1]=j:A<9?h[8][15-A-1+1]=j:h[8][15-A-1]=j}h[p-8][8]=!_},ue=function(_,S){for(var x=-1,C=p-1,A=7,j=0,G=i.getMaskFunction(S),q=p-1;q>0;q-=2)for(q==6&&(q-=1);;){for(var te=0;te<2;te+=1)if(h[C][q-te]==null){var re=!1;j<_.length&&(re=(_[j]>>>A&1)==1);var W=G(C,q-te);W&&(re=!re),h[C][q-te]=re,A-=1,A==-1&&(j+=1,A=7)}if(C+=x,C<0||p<=C){C-=x,x=-x;break}}},Ee=function(_,S){for(var x=0,C=0,A=0,j=new Array(S.length),G=new Array(S.length),q=0;q=0?Gt.getAt(Wt):0}}for(var Ft=0,W=0;Wq*8)throw"code length overflow. ("+A.getLengthInBits()+">"+q*8+")";for(A.getLengthInBits()+4<=q*8&&A.put(0,4);A.getLengthInBits()%8!=0;)A.putBit(!1);for(;!(A.getLengthInBits()>=q*8||(A.put(E,8),A.getLengthInBits()>=q*8));)A.put(M,8);return Ee(A,C)};y.addData=function(_,S){S=S||"Byte";var x=null;switch(S){case"Numeric":x=g(_);break;case"Alphanumeric":x=f(_);break;case"Byte":x=c(_);break;case"Kanji":x=k(_);break;default:throw"mode:"+S}m.push(x),T=null},y.isDark=function(_,S){if(_<0||p<=_||S<0||p<=S)throw _+","+S;return h[_][S]},y.getModuleCount=function(){return p},y.make=function(){if(u<1){for(var _=1;_<40;_++){for(var S=l.getRSBlocks(_,$),x=d(),C=0;C"u"?_*4:S;var x="";x+='";for(var A=0;A';x+=""}return x+="",x+="
",x},y.createSvgTag=function(_,S,x,C){var A={};typeof arguments[0]=="object"&&(A=arguments[0],_=A.cellSize,S=A.margin,x=A.alt,C=A.title),_=_||2,S=typeof S>"u"?_*4:S,x=typeof x=="string"?{text:x}:x||{},x.text=x.text||null,x.id=x.text?x.id||"qrcode-description":null,C=typeof C=="string"?{text:C}:C||{},C.text=C.text||null,C.id=C.text?C.id||"qrcode-title":null;var j=y.getModuleCount()*_+S*2,G,q,te,re,W="",ge;for(ge="l"+_+",0 0,"+_+" -"+_+",0 0,-"+_+"z ",W+=''+I(C.text)+"":"",W+=x.text?''+I(x.text)+"":"",W+='',W+='"u"?_*4:S;var x=y.getModuleCount()*_+S*2,C=S,A=x-S;return B(x,x,function(j,G){if(C<=j&&j"u"?_*4:S;var C=y.getModuleCount()*_+S*2,A="";return A+="",A};var I=function(_){for(var S="",x=0;x<_.length;x+=1){var C=_.charAt(x);switch(C){case"<":S+="<";break;case">":S+=">";break;case"&":S+="&";break;case'"':S+=""";break;default:S+=C;break}}return S},oe=function(_){var S=1;_=typeof _>"u"?S*2:_;var x=y.getModuleCount()*S+_*2,C=_,A=x-_,j,G,q,te,re,W={"██":"█","█ ":"▀"," █":"▄"," ":" "},ge={"██":"▀","█ ":"▀"," █":" "," ":" "},me="";for(j=0;j=A?ge[re]:W[re];me+=` +`}return x%2&&_>0?me.substring(0,me.length-x-1)+Array(x+1).join("▀"):me.substring(0,me.length-1)};return y.createASCII=function(_,S){if(_=_||1,_<2)return oe(S);_-=1,S=typeof S>"u"?_*2:S;var x=y.getModuleCount()*_+S*2,C=S,A=x-S,j,G,q,te,re=Array(_+1).join("██"),W=Array(_+1).join(" "),ge="",me="";for(j=0;j>>8),$.push(T&255)):$.push(M)}}return $}};var t={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},n={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},i=(function(){var w=[[],[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]],D=1335,E=7973,M=21522,u={},$=function(h){for(var p=0;h!=0;)p+=1,h>>>=1;return p};return u.getBCHTypeInfo=function(h){for(var p=h<<10;$(p)-$(D)>=0;)p^=D<<$(p)-$(D);return(h<<10|p)^M},u.getBCHTypeNumber=function(h){for(var p=h<<12;$(p)-$(E)>=0;)p^=E<<$(p)-$(E);return h<<12|p},u.getPatternPosition=function(h){return w[h-1]},u.getMaskFunction=function(h){switch(h){case a.PATTERN000:return function(p,T){return(p+T)%2==0};case a.PATTERN001:return function(p,T){return p%2==0};case a.PATTERN010:return function(p,T){return T%3==0};case a.PATTERN011:return function(p,T){return(p+T)%3==0};case a.PATTERN100:return function(p,T){return(Math.floor(p/2)+Math.floor(T/3))%2==0};case a.PATTERN101:return function(p,T){return p*T%2+p*T%3==0};case a.PATTERN110:return function(p,T){return(p*T%2+p*T%3)%2==0};case a.PATTERN111:return function(p,T){return(p*T%3+(p+T)%2)%2==0};default:throw"bad maskPattern:"+h}},u.getErrorCorrectPolynomial=function(h){for(var p=r([1],0),T=0;T5&&(T+=3+P-5)}for(var m=0;m=256;)u-=255;return w[u]},M})();function r(w,D){if(typeof w.length>"u")throw w.length+"/"+D;var E=(function(){for(var u=0;u"u")throw"bad rs block @ typeNumber:"+u+"/errorCorrectionLevel:"+$;for(var p=h.length/3,T=[],m=0;m>>7-M%8&1)==1},E.put=function(M,u){for(var $=0;$>>u-$-1&1)==1)},E.getLengthInBits=function(){return D},E.putBit=function(M){var u=Math.floor(D/8);w.length<=u&&w.push(0),M&&(w[u]|=128>>>D%8),D+=1},E},g=function(w){var D=t.MODE_NUMBER,E=w,M={};M.getMode=function(){return D},M.getLength=function(h){return E.length},M.write=function(h){for(var p=E,T=0;T+2>>8&255)*192+(m&255),h.put(m,13),T+=2}if(T>>8)},D.writeBytes=function(E,M,u){M=M||0,u=u||E.length;for(var $=0;$0&&(E+=","),E+=w[M];return E+="]",E},D},R=function(){var w=0,D=0,E=0,M="",u={},$=function(p){M+=String.fromCharCode(h(p&63))},h=function(p){if(!(p<0)){if(p<26)return 65+p;if(p<52)return 97+(p-26);if(p<62)return 48+(p-52);if(p==62)return 43;if(p==63)return 47}throw"n:"+p};return u.writeByte=function(p){for(w=w<<8|p&255,D+=8,E+=1;D>=6;)$(w>>>D-6),D-=6},u.flush=function(){if(D>0&&($(w<<6-D),w=0,D=0),E%3!=0)for(var p=3-E%3,T=0;T=D.length){if(u==0)return-1;throw"unexpected end of file./"+u}var p=D.charAt(E);if(E+=1,p=="=")return u=0,-1;if(p.match(/^\s$/))continue;M=M<<6|h(p.charCodeAt(0)),u+=6}var T=M>>>u-8&255;return u-=8,T};var h=function(p){if(65<=p&&p<=90)return p-65;if(97<=p&&p<=122)return p-97+26;if(48<=p&&p<=57)return p-48+52;if(p==43)return 62;if(p==47)return 63;throw"c:"+p};return $},V=function(w,D){var E=w,M=D,u=new Array(w*D),$={};$.setPixel=function(m,y,P){u[y*E+m]=P},$.write=function(m){m.writeString("GIF87a"),m.writeShort(E),m.writeShort(M),m.writeByte(128),m.writeByte(0),m.writeByte(0),m.writeByte(0),m.writeByte(0),m.writeByte(0),m.writeByte(255),m.writeByte(255),m.writeByte(255),m.writeString(","),m.writeShort(0),m.writeShort(0),m.writeShort(E),m.writeShort(M),m.writeByte(0);var y=2,P=p(y);m.writeByte(y);for(var O=0;P.length-O>255;)m.writeByte(255),m.writeBytes(P,O,255),O+=255;m.writeByte(P.length-O),m.writeBytes(P,O,P.length-O),m.writeByte(0),m.writeString(";")};var h=function(m){var y=m,P=0,O=0,H={};return H.write=function(Z,ee){if(Z>>>ee)throw"length over";for(;P+ee>=8;)y.writeByte(255&(Z<>>=8-P,O=0,P=0;O=Z<0&&y.writeByte(O)},H},p=function(m){for(var y=1<>6,128|o&63):o<55296||o>=57344?a.push(224|o>>12,128|o>>6&63,128|o&63):(i++,o=65536+((o&1023)<<10|n.charCodeAt(i)&1023),a.push(240|o>>18,128|o>>12&63,128|o>>6&63,128|o&63))}return a}return t(s)}})();(function(s){typeof define=="function"&&define.amd?define([],s):typeof Jt=="object"&&(Qt.exports=s())})(function(){return Yt})});function Lt(s,t){return s==null||s===!1||s===""||(Array.isArray(s)?s.forEach(n=>Lt(n,t)):t.push(s instanceof Node?s:String(s))),t}function e(s,t,n){let a=window.E,i=t!=null&&typeof t=="object"&&!Array.isArray(t)&&!(t instanceof Node);return!i&&n===void 0?a(s,{},Lt(t,[])):a(s,i?t:{},Lt(n,[]))}function F(s,t=[]){let n=rpc.declare({object:"luci.dawnline",method:s,params:t});return async(...a)=>{let i=await n(...a);if(i&&typeof i=="object"&&typeof i.error=="string")throw new Error(i.error);return i}}var Dn=F("logs_clear",["person","device","category","older_days"]),An=(s={})=>Dn(s.person??"",s.device??"",s.category??"",s.older_days??""),Pn=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"]});async function Nn(s,t){let a=[s,...["name","access","device_limit","expires","expire_action","expire_warn","quota_gb","quota_period","bonus_gb","hours","note","dns_mode"].map(o=>t[o]),t.paused,t.services],i=await Pn(...a);if(i&&typeof i.error=="string")throw new Error(i.error);return i}var zn=F("status",["days"]),Rn=0;async function Hn(s){let t=await zn(s);return Rn=Date.now(),t}var N={personUpdate:Nn,settingsGet:F("settings_get"),settingsUpdate:F("settings_update",["values"]),serviceSet:F("service_set",["id","name","address","ports"]),serviceDelete:F("service_delete",["id"]),geoClear:F("geo_clear"),events:F("events",["limit"]),logsClear:An,interfaces:F("interfaces",["id"]),serverInterfaces:F("server_interfaces",["id","auto_wan","wan_device","auto_lan","lan_devices","lan_like","device_mesh"]),usageClear:F("usage_clear",["scope","id"]),uninstall:F("uninstall",["confirm"]),status:Hn,setupDefaults:F("setup_defaults"),serverCreate:F("server_create",["id","name","ifname","port","subnet","endpoint","mtu","preset","lan_zone","wan_zone","lan_like","portal_enabled","portal_port"]),serverObfuscation:F("server_obfuscation",["id","preset"]),serverUpdate:F("server_update",["id","values"]),serverDelete:F("server_delete",["id"]),personCreate:F("person_create",["name","slug","server","access","device_limit","expires","quota_gb","quota_period"]),personPause:F("person_pause",["id","paused"]),personRegen:F("person_regen",["id"]),personDelete:F("person_delete",["id"]),personUsage:F("person_usage",["id","days"]),pauseAll:F("pause_all",["paused"]),deviceCreate:F("device_create",["person","name","kind"]),deviceConfig:F("device_config",["id"]),deviceUpdate:F("device_update",["id","name","disabled"]),deviceDelete:F("device_delete",["id"]),deviceRotate:F("device_rotate",["id"]),apply:F("apply"),health:F("health"),healthFix:F("health_fix",["id"]),serviceLog:F("service_log"),serviceLogClear:F("service_log_clear",["older_days"]),backupList:F("backup_list"),backupCreate:F("backup_create"),backupRestore:F("backup_restore",["name"]),backupDelete:F("backup_delete",["name"]),backupRead:F("backup_read",["name"]),backupUpload:F("backup_upload",["data"]),exportJson:F("export"),importJson:F("import",["data"]),updatesStatus:F("updates_status"),updatesRun:F("updates_run",["what"])};var Vt={phone:'',computer:'',tablet:'',router:'',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 St(s,t="dl-icon"){let n=Vt[s]??Vt.phone;return``}function v(s,t="dl-icon"){let n=document.createElement("span");return n.className="dl-icon-wrap",n.innerHTML=St(s,t),n}function z(s,t,n="neutral",a={}){let{disabled:i,...o}=a,r=e("button",{class:`cbi-button cbi-button-${n}`,type:"button",...o,click:async l=>{if(l.preventDefault(),l.stopPropagation(),!r.disabled){r.disabled=!0,r.classList.add("spinning");try{await t(l)}catch(d){X(Mt(d),"error")}finally{r.disabled=!1,r.classList.remove("spinning")}}}},s);return r.disabled=!!i,r}function we(s,t,n,a="neutral",i=""){return z([v(s),e("span",{class:"dl-btn-label"},t)],n,a,{title:t,class:`cbi-button cbi-button-${a} dl-icon-btn ${i}`.trim()})}function X(s,t="info",n=0){let a=document.querySelector(".dl-toasts");a||(a=e("div",{class:"dl-toasts dl-root",role:"status","aria-live":"polite"}),document.body.appendChild(a));let i=t==="error"?"x":t==="warning"?"alert":t==="success"?"check":null,o=()=>{r.classList.remove("show"),setTimeout(()=>r.remove(),200)},r=e("div",{class:`dl-toast ${t}`},[i?v(i):"",e("span",{},s),t==="error"?e("button",{type:"button","aria-label":"Close",click:o},v("x")):""]);a.appendChild(r),requestAnimationFrame(()=>r.classList.add("show")),setTimeout(o,n||(t==="error"?8e3:t==="warning"?5e3:2600))}function Mt(s){return s instanceof Error?s.message:String(s)}async function U(s,t){try{let n=await s();return t&&X(t,"success",3500),n}catch(n){X(Mt(n),"error",1e4);return}}function ne(s,t,n,a=""){ui.showModal(s,[e("div",{class:`dl-modal ${a}`},t),e("div",{class:"button-row"},n)])}function J(){ui.hideModal()}function ae(s,t,n="Confirm",a=!1){return new Promise(i=>{ne(s,t,[e("button",{class:"cbi-button cbi-button-neutral",type:"button",click:()=>{J(),i(!1)}},"Cancel")," ",e("button",{class:`cbi-button ${a?"cbi-button-negative":"cbi-button-positive"}`,type:"button",click:()=>{J(),i(!0)}},n)])})}async function de(s,t="Copied to clipboard"){try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(s);else{let n=e("textarea",{style:"position:fixed;opacity:0"},s);document.body.appendChild(n),n.select(),document.execCommand("copy"),n.remove()}X(t,"success",2500)}catch(n){X(Mt(n),"error")}}function fe(s,t,n="text/plain"){let a=globalThis,i=typeof t=="string"?new a.Blob([t],{type:n}):t,o=URL.createObjectURL(i),r=e("a",{href:o,download:s,style:"display:none"});document.body.appendChild(r),r.click(),setTimeout(()=>{URL.revokeObjectURL(o),r.remove()},1e3)}function De(s,t){let n={ok:"success",warn:"warning",error:"error",info:"notice"}[s];return e("div",{class:`alert-message ${n}`},t)}function Ae(s,t=""){let n=e("div",{class:t});return n.innerHTML=s,n}function Et(s,t){return new Promise(n=>{let a=e("input",{type:"file",accept:s,style:"display:none"});a.addEventListener("cancel",()=>{a.remove(),n(null)}),a.addEventListener("change",()=>{let i=a.files?.[0];if(a.remove(),!i)return n(null);let o=new FileReader;o.onload=()=>{let r=String(o.result??"");n({name:i.name,data:t==="base64"?r.replace(/^data:[^,]*,/,""):r})},o.onerror=()=>n(null),t==="base64"?o.readAsDataURL(i):o.readAsText(i)}),document.body.appendChild(a),a.click()})}function ye(s,t){let n=document.querySelector(".dl-dd");if(n&&(n.dlClose?n.dlClose():n.remove(),n.dlAnchor===s))return;let a=e("div",{class:"dl-dd dl-root",role:"menu"},t.map(f=>f?e("button",{type:"button",role:"menuitem",class:f.danger?"danger":f.warn?"warn":"",click:()=>{g(),f.run()}},[f.icon??"",e("span",{},f.label)]):e("hr")));document.body.appendChild(a);let i=s.getBoundingClientRect(),o=a.offsetWidth,r=a.offsetHeight;a.style.top=`${i.bottom+6+r>window.innerHeight-8&&i.top-6-r>8?i.top-6-r:i.bottom+6}px`,a.style.left=`${Math.max(8,Math.min(i.right-o,window.innerWidth-o-8))}px`;let l=f=>{!a.contains(f.target)&&!s.contains(f.target)&&g()},d=f=>{f.key==="Escape"&&g()};a.dlAnchor=s,a.dlClose=g;function g(){a.remove(),document.removeEventListener("mousedown",l,!0),document.removeEventListener("keydown",d,!0),window.removeEventListener("scroll",g,!0)}setTimeout(()=>{document.addEventListener("mousedown",l,!0),document.addEventListener("keydown",d,!0),window.addEventListener("scroll",g,!0)}),a.querySelector("button")?.focus({preventScroll:!0})}var Xt=Cn(Zt(),1),In='';function je(s,t=3,n=!0){let a=(0,Xt.default)(0,s.length>300?"Q":"H");a.addData(s,"Byte"),a.make();let i=a.getModuleCount(),o=i+t*2,r=n?Math.round(i*.22):0;r&&(i-r)%2&&r++;let l=(i-r)/2,d=l+r,g=(k,b)=>r>0&&k>=l&&k=l&&b${In}`}return`${c}`}var Bn={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:""},jn={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 On(s){let t={};for(let[n,a]of Object.entries(jn))s[n]!=null&&s[n]!==""&&(t[a]=String(s[n]));return t}function Un(s,t){let n=s.amnezia,a=n.obfuscation??{},i=d=>a[d]!=null&&a[d]!==""?String(a[d]):Bn[d],o=n.host.replace(/^\[(.*)\]$/,"$1"),r={H1:i("h1"),H2:i("h2"),H3:i("h3"),H4:i("h4"),I1:i("i1"),I2:i("i2"),I3:i("i3"),I4:i("i4"),I5:i("i5"),Jc:i("jc"),Jmin:i("jmin"),Jmax:i("jmax"),S1:i("s1"),S2:i("s2"),S3:i("s3"),S4:i("s4"),...On(a),allowed_ips:n.allowed_ips,client_ip:n.client_ip,client_priv_key:n.client_priv_key,client_pub_key:n.client_pub_key,config:s.conf.replace(/\r?\n/g,`\r +`),hostName:o,mtu:n.mtu,persistent_keep_alive:n.persistent_keep_alive,port:Number(n.port),psk_key:n.psk_key,server_pub_key:n.server_pub_key},l={containers:[{container:"amnezia-awg",awg:{isThirdPartyConfig:!0,last_config:JSON.stringify(r),port:String(n.port),protocol_version:a.header_protection_key?"3.1":"2",transport_proto:"udp"}}],defaultContainer:"amnezia-awg",description:t,hostName:o};return n.dns[0]&&(l.dns1=n.dns[0]),n.dns[1]&&(l.dns2=n.dns[1]),l}function qn(s){let t="";for(let n=0;n"u")return null;try{let n=new t.Blob([s]).stream().pipeThrough(new t.CompressionStream("deflate")),a=new Uint8Array(await new t.Response(n).arrayBuffer()),i=new Uint8Array(4+a.length);return new DataView(i.buffer).setUint32(0,s.length,!1),i.set(a,4),i}catch{return null}}async function en(s,t,n=!0){let a=new TextEncoder().encode(JSON.stringify(Un(s,t))),i=n?await Gn(a):null;return`vpn://${qn(i??a)}`}function K(s){if(!s||s<0)return"0 B";let t=["B","KB","MB","GB","TB"],n=0,a=s;for(;a>=1024&&n=100||n===0?Math.round(a):a.toFixed(1)} ${t[n]}`}function ke(s){let t=s*8;return t<1e3?`${Math.round(t)} bit/s`:t<1e6?`${(t/1e3).toFixed(t<1e4?1:0)} kbit/s`:t<1e9?`${(t/1e6).toFixed(t<1e7?1:0)} Mbit/s`:`${(t/1e9).toFixed(1)} Gbit/s`}function ce(s,t=Date.now()/1e3){if(!s)return"never";let n=Math.max(0,Math.round(t-s));return n<60?"just now":n<3600?`${Math.floor(n/60)} min ago`:n<86400?`${Math.floor(n/3600)} h ago`:n<86400*30?`${Math.floor(n/86400)} d ago`:new Date(s*1e3).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function tn(s){if(!s||s<0)return"—";let t=Math.floor(s/86400),n=Math.floor(s%86400/3600),a=Math.floor(s%3600/60);return t?`${t}d ${n}h`:n?`${n}h ${a}m`:`${a}m`}function Pe(s){let t=new Date(s*1e3),n=new Date,a=t.toDateString()===n.toDateString(),i=t.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"});return a?i:`${t.toLocaleDateString("en-GB",{day:"numeric",month:"short"})} ${i}`}function $e(s){if(!s)return"";let[t,n,a]=s.split("-").map(Number);return new Date(t,n-1,a).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function Ne(s,t=Date.now()){if(!s)return null;let[n,a,i]=s.split("-").map(Number),o=new Date(n,a-1,i,23,59,59).getTime();return Math.ceil((o-t)/864e5)}var Oe={lan:"Home network",internet:"Internet",both:"Home network + Internet"};var nn=["computer","phone","tablet","router","other"],_e={computer:"PC",phone:"Phone",tablet:"Tablet",router:"Router",other:"Other"},Tt={active:"Active",paused:"Paused",paused_all:"Paused (everyone)",expired:"Expired",quota:"Data limit reached",hours:"Outside allowed hours",no_server:"No server"};function ze(s){let t=s.trim().split(/\s+/).filter(Boolean);if(!t.length)return"?";let n=t[0][0]??"",a=t.length>1?t[t.length-1][0]??"":t[0][1]??"";return(n+a).toUpperCase()}function st(s){let t=n=>n.disabled?3:n.online?0:n.handshake?1:2;return s.map((n,a)=>[n,a]).sort((n,a)=>t(n[0])-t(a[0])||n[1]-a[1]).map(([n])=>n)}var an="https://unpkg.com/maplibre-gl@4.7.1/dist/maplibre-gl",Wn="https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json",Fn="https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",Kn={online:0,"24h":86400,"7d":7*86400,"30d":30*86400},Ye=null;function Vn(s){let t=window;return s.appendChild(e("link",{rel:"stylesheet",href:`${an}.css`})),t.maplibregl?Promise.resolve(t.maplibregl):Ye||(Ye=new Promise((n,a)=>{let i=e("script",{src:`${an}.js`});i.onload=()=>t.maplibregl?n(t.maplibregl):a(new Error("MapLibre failed to load")),i.onerror=()=>{Ye=null,a(new Error("Could not load the map library (no internet access from this browser?)"))},s.appendChild(i)}),Ye)}function ot(){let s=document.documentElement.getAttribute("data-darkmode");return s!=null?s==="true":window.matchMedia?.("(prefers-color-scheme: dark)").matches??!1}function Yn(s,t,n=48){let a=(s[0]+t[0])/2,i=(s[1]+t[1])/2,o=t[0]-s[0],r=t[1]-s[1],l=Math.hypot(o,r)||1,d=Math.min(.25*l,12),g=a-r/l*d,f=i+o/l*d,c=[];for(let k=0;k<=n;k++){let b=k/n,R=1-b;c.push([R*R*s[0]+2*R*b*g+b*b*t[0],R*R*s[1]+2*R*b*f+b*b*t[1]])}return c}function Jn(s,t){let n=new Map;for(let a of s.geo.points){if(s.person&&a.person!==s.person||(t==="online"?!a.online:s.now-a.ts>Kn[t]))continue;let i=n.get(a.device);(!i||a.online&&!i.online||a.online===i.online&&a.ts>i.ts)&&n.set(a.device,a)}return[...n.values()]}var Ue=class{constructor(t,n="online",a=380){this.cb=t;this.map=null;this.gl=null;this.markers=[];this.popup=null;this.anim=0;this.data=null;this.fitted=!1;this.range=n,this.status=e("div",{class:"dl-map-status"}),this.el=e("div",{class:"dl-geomap",style:`height:${a}px`},this.status)}async mount(t){this.data=t;try{this.gl=await Vn(this.el)}catch(n){this.status.textContent=n.message;return}this.map=new this.gl.Map({container:this.el,style:ot()?Wn:Fn,center:[t.geo.home?.lon??20,t.geo.home?.lat??50],zoom:3,attributionControl:{compact:!0},dragRotate:!1,pitchWithRotate:!1,cooperativeGestures:!0}),this.map.addControl(new this.gl.NavigationControl({showCompass:!1}),"bottom-right"),this.map.on("load",()=>{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"],"#40c977",ot()?"#ededed":"#0d0d0d"],"circle-opacity":["case",["get","online"],.12,.06],"circle-stroke-width":1,"circle-stroke-color":["case",["get","online"],"#40c977",ot()?"#ededed":"#0d0d0d"],"circle-stroke-opacity":["case",["get","online"],.35,.15]}}),this.map.addSource("dl-arcs",{type:"geojson",data:{type:"FeatureCollection",features:[]}}),this.map.addLayer({id:"dl-arc-recent",type:"line",source:"dl-arcs",filter:["==",["get","online"],!1],layout:{"line-cap":"round"},paint:{"line-color":ot()?"#ededed":"#0d0d0d","line-opacity":.35,"line-width":1.5,"line-dasharray":[2,3]}}),this.map.addLayer({id:"dl-arc-glow",type:"line",source:"dl-arcs",filter:["==",["get","online"],!0],layout:{"line-cap":"round"},paint:{"line-color":"#40c977","line-opacity":.18,"line-width":7}}),this.map.addLayer({id:"dl-arc-live",type:"line",source:"dl-arcs",filter:["==",["get","online"],!0],layout:{"line-cap":"round"},paint:{"line-color":"#40c977","line-width":2}}),this.map.addLayer({id:"dl-arc-flow",type:"line",source:"dl-arcs",filter:["==",["get","online"],!0],layout:{"line-cap":"round"},paint:{"line-color":"#ffffff","line-width":2,"line-opacity":.8,"line-dasharray":[0,4,3]}}),this.animate(),this.draw()})}setRange(t){this.range=t,this.fitted=!1,this.draw()}update(t){this.data=t,this.draw()}destroy(){cancelAnimationFrame(this.anim),this.map?.remove(),this.map=null}animate(){let t=[[0,4,3],[.5,4,2.5],[1,4,2],[1.5,4,1.5],[2,4,1],[2.5,4,.5],[3,4,0],[0,.5,3,3.5],[0,1,3,3],[0,1.5,3,2.5],[0,2,3,2],[0,2.5,3,1.5],[0,3,3,1],[0,3.5,3,.5]],n=-1,a=0,i=o=>{this.map&&(o-a>70&&(a=o,n=(n+1)%t.length,this.map.getLayer("dl-arc-flow")&&this.map.setPaintProperty("dl-arc-flow","line-dasharray",t[n])),this.anim=requestAnimationFrame(i))};this.anim=requestAnimationFrame(i)}groups(t){let n=new Map;for(let a of t){let i=`${a.asn||a.org||a.ip}|${a.city}|${a.cc}`,o=n.get(i);o||(o={key:i,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:[]},n.set(i,o)),o.points.push(a),o.online||(o.online=a.online),o.ts=Math.max(o.ts,a.ts)}return[...n.values()]}draw(){if(!this.map||!this.data||!this.map.getSource("dl-arcs"))return;let t=this.data,n=this.groups(Jn(t,this.range)),a=t.geo.home;for(let r of this.markers)r.remove();this.markers=[];let i=new Map,o=n.map(r=>{let l=`${r.lat.toFixed(2)},${r.lon.toFixed(2)}`,d=i.get(l)??0;return i.set(l,d+1),{g:r,at:[r.lon+d*.25,r.lat]}});if(this.map.getSource("dl-areas").setData({type:"FeatureCollection",features:o.map(({g:r,at:l})=>({type:"Feature",properties:{online:r.online},geometry:{type:"Point",coordinates:l}}))}),this.map.getSource("dl-arcs").setData({type:"FeatureCollection",features:a?o.map(({g:r,at:l})=>({type:"Feature",properties:{online:r.online},geometry:{type:"LineString",coordinates:Yn([a.lon,a.lat],l)}})):[]}),a){let r=e("div",{class:"dl-mk-home",title:`Home router${a.city?` · ${a.city}`:""}${a.org?` · ${a.org}`:""}`});r.innerHTML=St("home","dl-mk-home-ic"),this.markers.push(new this.gl.Marker({element:r}).setLngLat([a.lon,a.lat]).addTo(this.map))}for(let{g:r,at:l}of o){let d=r.points.length,g=e("button",{type:"button",class:`dl-mk${r.online?" online":""}${d>1?" multi":""}`,"aria-label":`${d} device${d===1?"":"s"} via ${r.org||"unknown network"} in ${r.city||"unknown city"}`},d>1?e("span",{class:"dl-mk-count"},String(d)):e("span",{class:"dl-mk-dot"})),c=!!a&&Math.abs(l[0]-a.lon)<.02&&Math.abs(l[1]-a.lat)<.02?[22,-16]:[0,0];g.addEventListener("click",k=>{k.stopPropagation(),this.openPopup(r,l,c)}),this.markers.push(new this.gl.Marker({element:g,offset:c}).setLngLat(l).addTo(this.map))}if(!this.fitted){let r=o.map(l=>l.at);a&&(r.length===0||this.range!=="online"||o.some(l=>l.g.online))&&r.push([a.lon,a.lat]),this.fit(r),this.fitted=!0}this.status.textContent=o.length||a?"":"No locations yet",this.status.style.display=this.status.textContent?"":"none"}fit(t){if(!t.length)return;let n=(d,g)=>{let f=Math.PI/180,c=(g[1]-d[1])*f,k=(g[0]-d[0])*f,b=Math.sin(c/2)**2+Math.cos(d[1]*f)*Math.cos(g[1]*f)*Math.sin(k/2)**2;return 12742*Math.asin(Math.sqrt(b))},a=[t.reduce((d,g)=>d+g[0],0)/t.length,t.reduce((d,g)=>d+g[1],0)/t.length],i=t;if(t.length>=5){let d=[...t].sort((g,f)=>n(a,g)-n(a,f));i=d.slice(0,Math.ceil(d.length*.9))}if(Math.max(...i.map(d=>n(a,d)))<25){this.map.jumpTo({center:a,zoom:9.5});return}let r=new this.gl.LngLatBounds(i[0],i[0]);i.forEach(d=>r.extend(d));let l=this.el.clientHeight||380;this.map.fitBounds(r,{padding:{top:Math.min(90,l/4),bottom:Math.min(70,l/5),left:60,right:60},maxZoom:9,duration:0})}openPopup(t,n,a=[0,0]){let i=this.data;this.popup?.remove();let o=[t.city,t.cc||t.country].filter(Boolean).join(", "),r=[...new Set(t.points.map(f=>f.person))],l=t.points.sort((f,c)=>Number(c.online)-Number(f.online)||c.ts-f.ts).map(f=>{let c=i.people.find(b=>b.id===f.person),k=c?.devices.find(b=>b.id===f.device);return e("button",{type:"button",class:"dl-pop-row",click:()=>this.cb.openDevice(f.person,f.device)},[e("span",{class:`dl-pop-dot${f.online?" on":""}`}),e("span",{class:"dl-pop-name"},[e("b",{},c?.name??f.person),` · ${k?.name??"device"}`]),e("span",{class:"dl-faint dl-nowrap"},f.online?"now":ce(f.ts,i.now))])}),d=e("div",{class:"dl-pop"},[e("div",{class:"dl-pop-head"},[e("span",{class:"dl-pop-net"},v("globe")),e("div",{class:"dl-stack"},[e("strong",{},t.org||"Unknown network"),e("span",{class:"dl-faint"},[t.asn?`AS${t.asn} · `:"",o?`${o} · approximate`:"approximate location"])])]),e("div",{class:"dl-pop-list"},l),r.length===1?e("div",{class:"dl-pop-actions"},[e("button",{type:"button",class:"cbi-button cbi-button-positive important",click:()=>this.cb.openPerson(r[0])},`Open ${i.people.find(f=>f.id===r[0])?.name??"person"}`)]):""]),g=this.el.clientHeight||380;this.map.easeTo({center:n,offset:[0,Math.min(140,g*.32)],duration:300}),this.popup=new this.gl.Popup({offset:[a[0],a[1]-18],anchor:"bottom",closeButton:!1,focusAfterOpen:!1,maxWidth:"300px",className:"dl-popup"}).setLngLat(n).setDOMContent(d).addTo(this.map)}};function rt(s,t,n=!0){let a=[["online","Online now"],["24h","24h"],["7d","7 days"],["30d","30 days"]],i=e("div",{class:"dl-seg",role:"tablist"});for(let[o,r]of a)o==="online"&&!n||i.appendChild(e("button",{type:"button",role:"tab",class:o===s?"on":"","data-v":o,click:()=>{i.querySelectorAll("button").forEach(l=>l.classList.toggle("on",l.dataset.v===o)),t(o)}},r));return i}var Re=null;function le(s,t){let n=a=>{Re??(Re=document.body.appendChild(e("div",{class:"dl-tip dl-tip-float dl-root"}))),Re.replaceChildren(...t().map(i=>typeof i=="string"?document.createTextNode(i):i)),Re.style.display="",Re.style.left=`${a.clientX}px`,Re.style.top=`${a.clientY-10}px`};s.addEventListener("mouseenter",n),s.addEventListener("mousemove",n),s.addEventListener("mouseleave",()=>Re&&(Re.style.display="none"))}function sn(s,t=120,n=26){let a=Math.max(1,...s),i=e("div",{class:"dl-spark"});i.style.width=`${t}px`,i.style.height=`${n}px`;let o=Date.now();return s.forEach((r,l)=>{let d=e("i");d.style.height=`${Math.max(6,r/a*100)}%`,r||d.classList.add("zero");let g=s.length-1-l,f=new Date(o-g*864e5);le(d,()=>[e("div",{class:"dl-tip-title"},g===0?"Today":g===1?"Yesterday":f.toLocaleDateString("en-GB",{weekday:"short",day:"numeric",month:"short"})),e("div",{class:"dl-muted"},K(r))]),i.appendChild(d)}),i}var rn=[{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"}],qe=s=>rn.find(t=>t.id===s),Qn={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)."};function on(s,t){return e("span",{class:"dl-dots",title:`${t}: ${s} of 4`},[e("span",{class:"dl-dots-label"},t),e("span",{class:"dl-dots-row"},[0,1,2,3].map(n=>e("i",{class:ndom.content(i,rn.map(r=>{let l=!r.needs||s[r.needs],d=r.id===t;return e("button",{type:"button",role:"radio","aria-checked":d?"true":"false","aria-disabled":l?null:"true",class:`dl-method${d?" on":""}${l?"":" off"}`,click:()=>{!l||d||(t=r.id,o(),n(r.id))}},[e("div",{class:"dl-method-head"},[e("span",{class:"dl-method-ic"},v(r.ic)),e("b",{},r.title),r.id===a?e("span",{class:"dl-pill ok"},"Current"):""]),e("p",{},r.text),e("div",{class:"dl-method-meters"},[on(r.stealth,"Stealth"),on(r.speed,"Speed")]),e("div",{class:"dl-method-foot"},l?[v("phone"),e("span",{},r.apps)]:[v("alert"),e("span",{},Qn[r.needs])])])}));return o(),i}function Je(s){return`${L.url("admin/network/dawnline/server")}?${s?`server=${encodeURIComponent(s)}&`:""}section=people`}function ve(s,t){return`${L.url("admin/network/dawnline/person")}?id=${encodeURIComponent(s)}${t?`&device=${encodeURIComponent(t)}`:""}`}var Zn={connect:"ok",disconnect:"",roam:"",device_added:"ok",device_removed:"",person_added:"",person_removed:"",paused:"warn",resumed:"ok",paused_all:"warn",resumed_all:"ok",portal_blocked:"bad",person_changed:"",devices_removed:"warn"},Xn={devices_removed:"trash",link_changed:"link",person_added:"plus",person_removed:"trash",person_changed:"edit",paused:"pause",resumed:"play",paused_all:"pause",resumed_all:"play"};function ea(s,t){return t.device?s.people.flatMap(a=>a.devices).find(a=>a.id===t.device)?.kind??t.dkind??"other":Xn[t.type]??"activity"}var ta=["person_added","person_removed","person_changed","paused_all","resumed_all"];function be(s){return s.by?s.by:ta.includes(s.type)||s.detail==="by admin"||s.detail?.endsWith(" (admin)")?"admin":s.detail?.endsWith(" (portal)")?"portal":null}function na(s){return(s.detail??"").replace(/ \((admin|portal)\)$/,"").replace(/^by admin$/,"")}function Dt(s,t){let n=s.people.find(b=>b.id===t.person),a=n?.name??t.pname??t.person??"",i=n?.devices.find(b=>b.id===t.device)?.name??t.dname??"",o=b=>e("b",{},b),r=b=>e("span",{class:"dl-muted"},b),l=b=>e("span",{class:"dl-mono"},b),d=b=>e("span",{class:"dl-ev-kind"},`${b} `),g=i?`${a} · ${i}`:a,f=na(t),c=f||i||"a device",k=b=>[e("span",{class:"dl-you"},"You"),r(` ${b} `)];if(be(t)==="admin")switch(t.type){case"device_added":return[...k("added"),d("device"),o(c),r(" for "),o(a)];case"device_removed":return[...k("removed"),d("device"),o(c),r(" from "),o(a)];case"paused":return[...k("paused"),d("person"),o(a)];case"resumed":return[...k("resumed"),d("person"),o(a)];case"device_changed":{let b=f.startsWith("renamed from ");return[...k(b?"renamed":f),d("device"),o(i||"a device"),r(" of "),o(a),...b?[r(` · was ${f.slice(13)}`)]:[]]}case"device_keys":return[...k("issued new keys for"),d("device"),o(c),r(" of "),o(a),r(" · it needs its new configuration")];case"link_changed":return[...k("issued a new link for"),d("person"),o(a),r(" · the old link stopped working")];case"paused_all":return[e("span",{class:"dl-you"},"You"),r(" paused everyone")];case"resumed_all":return[e("span",{class:"dl-you"},"You"),r(" resumed everyone")]}switch(t.type){case"connect":return[d("Device"),o(g),r(" connected"),...t.detail?[r(" from "),l(t.detail)]:[],...t.where?[r(` · ${t.where}`)]:[]];case"disconnect":return[d("Device"),o(g),r(" went offline")];case"roam":return[d("Device"),o(g),r(" changed network "),l(t.detail??"")];case"device_added":return[d("Person"),o(a),r(" added "),d("device"),o(c),...be(t)==="portal"?[r(" on their portal")]:[]];case"device_removed":return[d("Person"),o(a),r(" removed "),d("device"),o(c),...be(t)==="portal"?[r(" on their portal")]:[]];case"device_keys":return[d("Person"),o(a),r(" issued new keys for "),d("device"),o(c),r(" on their portal")];case"person_added":return[...k("added"),d("person"),o(t.detail??a)];case"person_removed":return[...k("removed"),d("person"),o(t.detail??a)];case"person_changed":return[...k("changed"),d("person"),o(a),...f?[r(` · ${f.replace(/_/g," ")}`)]:[]];case"paused":return[d("Person"),o(a),r(` paused — ${t.detail??""}`)];case"resumed":return[d("Person"),o(a),r(" resumed"),...t.detail&&t.detail!=="active"?[r(` — ${t.detail}`)]:[]];case"paused_all":return[r("Everyone paused")];case"resumed_all":return[r("Everyone resumed")];case"portal_blocked":return[e("b",{class:"dl-sys-src"},"Personal portal"),r(" blocked "),l(t.detail??""),r(" for 15 min after too many wrong codes")];case"devices_removed":return[d("Person"),o(a),r(" — all devices removed, end date reached")];default:return[r(`${t.type}${t.detail?`: ${t.detail}`:""}`)]}}var aa={portal_blocked:["globe","bad"]};function ia(s,t){if(s.servers.length<2||!t.person)return"";let n=s.people.find(i=>i.id===t.person),a=n&&s.servers.find(i=>i.id===n.server);return a?e("span",{class:"dl-ev-srv",title:"Server"},a.name):""}function He(s,t,n={}){let a=aa[t.type],i=be(t);return e("div",{class:`dl-row${i==="admin"?" dl-ev-by-admin":a?` dl-ev-by-system ${a[1]}`:""}`},[i==="admin"?e("span",{class:"dl-ev-tile",title:"Done by you in LuCI"},v("admin")):a?e("span",{class:"dl-ev-tile sys"},v(a[0])):e("span",{class:`dl-ev-tile ev ${Zn[t.type]??""}`},v(ea(s,t))),e("span",{class:"dl-row-main"},Dt(s,t)),n.server===!1?"":ia(s,t),e("span",{class:"dl-faint dl-nowrap",title:new Date(t.ts*1e3).toLocaleString()},ce(t.ts,s.now))])}function sa(s){let t=[],n=(i,o)=>e("a",{href:i},o);for(let i of s.servers)i.enabled&&!i.up&&t.push({tone:"bad",text:[`Tunnel ${i.ifname} is down. `,n(L.url("admin/network/dawnline/diagnostics"),"Open Diagnostics")]});s.settings.paused_all&&t.push({tone:"warn",text:["Everyone is paused."]});for(let i of s.people)if(i.state==="quota")t.push({tone:"warn",text:[n(ve(i.id),i.name)," reached the data limit."]});else if(i.state==="expired")t.push({tone:"warn",text:[n(ve(i.id),i.name),"’s access has ended."]});else{let o=Ne(i.expires);o!=null&&o>=0&&o<=Math.max(i.expire_warn,3)&&t.push({tone:"",text:[n(ve(i.id),i.name),`’s access ends in ${o} day${o===1?"":"s"}.`]}),i.quota_limit&&i.quota_used>=i.quota_limit*.9&&t.push({tone:"",text:[n(ve(i.id),i.name)," has used 90% of the data limit."]})}let a=s.people.flatMap(i=>i.devices.filter(o=>o.config_stale).map(o=>[i,o]));return a.length&&t.push({tone:"warn",text:a.length===1?[n(ve(a[0][0].id,a[0][1].id),`${a[0][0].name} · ${a[0][1].name}`)," needs its configuration again."]:[`${a.length} devices need their configuration again (networks or DNS changed).`]}),s.servers.some(i=>i.lan_like)&&s.like_home.error&&t.push({tone:"warn",text:[`Internet through the LAN is off: ${s.like_home.error} `,n(L.url("admin/network/dawnline/diagnostics"),"Details")]}),s.settings.portal_enabled||t.push({tone:"",text:["The personal portal is off. ",n(L.url("admin/network/dawnline/settings"),"Turn on")]}),t}function lt(s,t){let n=s.servers.find(d=>d.id===t)??s.servers[0],a=s.people.filter(d=>d.server===n.id),i=new Set(a.map(d=>d.id)),o=a.flatMap(d=>d.devices),r=d=>a.reduce((g,f)=>{let c=d(f);return[g[0]+c[0],g[1]+c[1]]},[0,0]),l=n.series?.[n.series.length-1];return{...s,servers:[n],people:a,series:n.series??s.series,events:s.events.filter(d=>d.person?i.has(d.person):!0),geo:{...s.geo,points:s.geo.points.filter(d=>i.has(d.person))},totals:{people:a.length,devices:o.length,online:o.filter(d=>d.online).length,active:a.filter(d=>d.state==="active").length,today:l?[l.rx,l.tx]:[0,0],month:r(d=>d.month)}}}var dt=class{constructor(t,n){this.srvId=t;this.go=n;this.el=e("div",{class:"dl-srvov"});this.map=null;this.range="online";this.parts={};this.healthAt=0}mount(t){this.st=lt(t,this.srvId);for(let n of["health","bento","side","activity"])this.parts[n]=e("div",{});return dom.content(this.el,[this.parts.health,this.parts.bento,this.mapCard(),e("div",{class:"dl-grid2"},[this.parts.activity,this.parts.side])]),this.paint(),this.loadHealth(),this.el}update(t){this.st=lt(t,this.srvId),this.paint(),this.map?.update(this.mapData()),Date.now()-this.healthAt>6e4&&this.loadHealth()}async loadHealth(){this.healthAt=Date.now();let t=await N.health().catch(()=>null);if(!t)return;let n=t.checks.filter(o=>o.status==="warn"||o.status==="error");if(!n.length){dom.content(this.parts.health,"");return}let a=n.filter(o=>o.status==="error").length,i=`${n.length} ${a?n.length===1?"problem":"problems":n.length===1?"warning":"warnings"}`;dom.content(this.parts.health,e("div",{class:`dl-healthstrip ${a?"bad":"warn"}`},[e("span",{class:"dl-healthstrip-title"},[v("alert"),i]),...n.slice(0,3).map(o=>{let r=e("span",{class:"dl-healthstrip-item"},o.title);return le(r,()=>[e("div",{class:"dl-tip-title"},o.title),e("div",{class:"dl-muted"},o.detail)]),r}),n.length>3?e("span",{class:"dl-sub"},`+${n.length-3} more`):"",e("a",{href:L.url("admin/network/dawnline/diagnostics")},n.some(o=>o.fix)?"Fix in Diagnostics →":"Open Diagnostics →")]))}mapData(){return{geo:this.st.geo,people:this.st.people,now:this.st.now}}mapCard(){let t=this.st,n=e("div",{class:"dl-panel-head pad"},[e("div",{class:"dl-stack"},[e("h3",{},"Where people connect from"),e("span",{class:"dl-sub"},"City-level, from the client IP · locations cached on the router")]),e("span",{class:"dl-spacer"}),rt(this.range,o=>{this.range=o,this.map?.setRange(o)})]);if(!t.geo.enabled)return e("div",{class:"dl-panel flush"},[n,e("div",{class:"dl-map-off"},["Locations are off. ",e("a",{href:L.url("admin/network/dawnline/settings")},"Turn them on in Settings"),"."])]);this.map=new Ue({openPerson:o=>location.href=ve(o),openDevice:(o,r)=>location.href=ve(o,r)},this.range);let a=e("div",{class:"dl-map-legend"},[e("span",{},[e("i",{class:"dot ok"}),"Online"]),e("span",{},[e("i",{class:"dot"}),"Seen recently"]),e("span",{},[e("i",{class:"line"}),"Live tunnel"])]),i=e("div",{class:"dl-map-wrap"},[this.map.el,a]);return requestAnimationFrame(()=>this.map.mount(this.mapData())),e("div",{class:"dl-panel flush"},[n,i])}paint(){let t=this.st,n=t.servers[0],a=t.people.reduce((l,d)=>l+Math.max(0,d.device_limit-d.devices.length),0),i=t.people.flatMap(l=>l.devices.filter(d=>d.online));dom.content(this.parts.bento,e("div",{class:"dl-bento"},[this.onlineTile(i),this.speedTile(),this.disguiseTile(n),this.monthTile(a)]));let o=sa(t);dom.content(this.parts.side,e("div",{class:"dl-panel flush"},[e("div",{class:"dl-panel-head pad"},[e("h3",{},"Needs attention"),e("span",{class:"dl-spacer"}),e("a",{href:L.url("admin/network/dawnline/diagnostics")},"Health")]),o.length?o.slice(0,8).map(l=>e("div",{class:"dl-attn-item dl-row"},[e("span",{class:`dl-ev-dot ${l.tone}`}),e("span",{},l.text)])):e("div",{class:"dl-row dl-muted"},[v("check"),"All good. Nothing needs you right now."])]));let r=[...t.events].reverse().slice(0,8);dom.content(this.parts.activity,e("div",{class:"dl-panel flush"},[e("div",{class:"dl-panel-head pad"},[e("h3",{},"Activity"),e("span",{class:"dl-spacer"}),e("a",{href:`${L.url("admin/network/dawnline/diagnostics")}?tab=log`},"View all")]),r.length?r.map(l=>He(t,l)):e("div",{class:"dl-row dl-muted"},"Nothing yet. Connections, new devices and pauses appear here.")]))}onlineTile(t){let n=this.st,a=12,i=B=>B.spark[B.spark.length-1]??0,o=B=>n.geo.points.find(w=>w.device===B.id&&w.city)?.city,r=B=>/^(10\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.)/.test(B.endpoint??""),l=B=>(r(B)?"home":o(B))??"",d=B=>[...n.events].reverse().find(w=>w.type==="connect"&&w.device===B.id)?.ts??0,g=n.people.map(B=>({p:B,devs:B.devices.filter(w=>w.online).sort((w,D)=>i(D)-i(w))})).filter(B=>B.devs.length).sort((B,w)=>w.devs.reduce((D,E)=>D+i(E),0)-B.devs.reduce((D,E)=>D+i(E),0)),f=g.length<=2,c=({p:B,devs:w})=>{let D=w.map(d).filter(Boolean),E=D.length?Math.min(...D):0,M=(B.rate??[]).slice(-15),u=M[M.length-1],$=u&&n.now-u[0]<180?u:null,h=200,p=30,T=Math.max(1,...M.map(H=>Math.max(H[1],H[2]))),m=H=>M.map((Z,ee)=>`${M.length>1?ee/(M.length-1)*h:h},${p-2-Z[H]/T*(p-6)}`),y=M.length>1?Ae(``):"",P=!$||$[1]<64&&$[2]<64,O=B.access==="both"?["home","globe"]:B.access==="lan"?["home"]:["globe"];return[e("div",{class:"dl-hc"},[e("div",{class:"dl-hc-head"},[e("span",{class:"dl-onl-av sm"},ze(B.name)),e("span",{class:"dl-stack"},[e("b",{},B.name),e("span",{class:"dl-hc-since"},E?`online for ${ce(E,n.now).replace(" ago","")}`:"online")]),e("span",{class:"dl-hc-reach"},O.map(H=>e("span",{class:`dl-ibadge ${H==="home"?"lan":"inet"}`},v(H))))]),e("div",{class:"dl-hc-speed"},[e("div",{class:"dl-hc-speed-row"},P?[e("span",{class:"dl-faint"},"Idle right now")]:[e("span",{},[e("span",{class:"dl-dn"},"↓"),` ${ke($[2])}`]),e("span",{},[e("span",{class:"dl-up"},"↑"),` ${ke($[1])}`]),e("span",{class:"dl-spacer"}),e("span",{class:"dl-faint"},"15 min")]),y]),e("div",{class:"dl-hc-devs"},w.map(H=>e("span",{class:"dl-hc-dev"},[v(H.kind),[H.name,l(H)].filter(Boolean).join(" · ")]))),e("div",{class:"dl-hc-foot"},[e("span",{class:"dl-faint"},`${K(w.reduce((H,Z)=>H+i(Z),0))} today · ${K(B.month[0]+B.month[1])} this month`)])])]},k=B=>{let{p:w,devs:D}=B,E=e("span",{class:"dl-onl-dev"},D.length>1?String(D.length):v(D[0].kind)),M=e("a",{class:`dl-onl-p${f?"":" sm"}`,href:ve(w.id),"aria-label":`${w.name}, online`},[e("span",{class:"dl-onl-av"},[ze(w.name),E]),f?e("span",{class:"dl-onl-name"},w.name):"",f?e("span",{class:"dl-onl-meta"},[...D.slice(0,3).map(u=>v(u.kind)),D.length>3?`+${D.length-3}`:"",l(D[0])?e("span",{},` · ${l(D[0])}`):""]):""]);return le(M,()=>c(B)),M},b=e("b",{class:`dl-onl-count${g.length?"":" none"}`},String(g.length)),R=g.reduce((B,w)=>B+w.devs.length,0);g.length&&le(b,()=>[`${g.length} ${g.length===1?"person":"people"} · ${R} device${R===1?"":"s"}`]);let Y=g.length>a?g.slice(0,a-1):g,V=n.people.flatMap(B=>B.devices.map(w=>({p:B,d:w}))).filter(B=>B.d.handshake).sort((B,w)=>w.d.handshake-B.d.handshake)[0];return e("div",{class:"dl-bento-tile online"},[e("div",{class:"dl-bento-head"},[e("span",{class:"dl-metric-label"},"Online"),b]),g.length?e("div",{class:`dl-onl-row${f?"":" grid"}`},[...Y.map(k),g.length>a?e("a",{class:"dl-onl-p sm more",href:`${L.url("admin/network/dawnline/server")}?server=${encodeURIComponent(this.srvId)}§ion=people&filter=online`,title:"Everyone online",click:B=>{this.go&&(B.preventDefault(),this.go("people","online"))}},[e("span",{class:"dl-onl-av"},`+${g.length-Y.length}`)]):""]):e("div",{class:"dl-onl-empty"},[e("span",{},"Nobody is connected"),V?e("span",{class:"dl-sub"},`Last: ${V.p.name}, ${ce(V.d.handshake,n.now)}`):e("span",{class:"dl-sub"},"No device has connected yet")])])}speedTile(){return At(this.st.servers[0]?.rate??[],this.st.now,this.st.totals.today)}disguiseTile(t){let n=qe(t.preset),a=t.obf??{},i=(l,d)=>e("span",{class:`dl-segs ${d}`},[0,1,2,3].map(g=>e("i",{class:g+a[l]).map(l=>`${l.toUpperCase()} ${a[l]}`);return r.length&&o.push(r.slice(0,2).join(" · ")+(r.length>2?` +${r.length-2}`:"")),["h1","h2","h3","h4"].some(l=>a[l]&&a[l]!==String(["h1","h2","h3","h4"].indexOf(l)+1))&&o.push("H1–H4 random"),a.i1&&o.push(a.i1.includes("0x8580")?"DNS-like first packet":"Signature packets"),a.header_protection_key&&o.push("Encrypted headers"),o.length||o.push(n?.id==="off"?"Plain WireGuard":"No values yet"),e("div",{class:"dl-bento-tile dl-disg"},[e("div",{class:"dl-bento-head"},[e("span",{class:"dl-metric-label"},"Disguise"),e("a",{href:`${L.url("admin/network/dawnline/server")}?server=${encodeURIComponent(t.id)}§ion=disguise`},"Change")]),e("div",{class:"dl-disg-id"},[e("span",{class:"dl-disg-ic"},v(n?.ic??"shield")),e("span",{class:"dl-stack"},[e("b",{},n?n.title:"Custom"),e("span",{class:"dl-sub"},n?n.short:"Set by hand")])]),n?e("div",{class:"dl-disg-meters"},[e("span",{},"Stealth"),i(n.stealth,"acc"),e("span",{},"Speed"),i(n.speed,"ok")]):"",e("div",{class:"dl-disg-chips"},o.map(l=>e("span",{},l)))])}monthTile(t){let n=this.st.totals,a=this.st.people.filter(i=>i.state!=="active").length;return Pt(this.st.series,`${n.people} ${n.people===1?"person":"people"}${a?` · ${a} paused`:""} · ${t} device slot${t===1?"":"s"} free`)}};function At(s,t,n){let a=s.slice(-15),i=a[a.length-1],o=i&&t-i[0]<180,r=o?i[2]:0,l=o?i[1]:0,[d,g]=n,f=200,c=40,k=Math.max(1,...a.map(w=>Math.max(w[1],w[2]))),b=w=>a.map((D,E)=>`${a.length>1?E/(a.length-1)*f:f},${c-2-D[w]/k*(c-6)}`),R=b(2),Y=b(1),V=a.length>1?Ae(``):e("div",{class:"dl-speed-wait"},[e("i"),e("span",{},"Collecting… 1 point a minute")]),B=(w,D,E,M)=>e("div",{class:"dl-speed-col"},[e("span",{class:"dl-sub"},[e("span",{class:E},D),` ${w}`]),e("span",{class:"dl-speed-val"},ke(M))]);return a.length>1&&le(V,()=>{let w=a[a.length-1];return[e("div",{class:"dl-tip-title"},new Date(w[0]*1e3).toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"})),e("div",{},`↓ ${ke(w[2])} · ↑ ${ke(w[1])}`)]}),e("div",{class:"dl-bento-tile"},[e("div",{class:"dl-bento-head"},[e("span",{class:"dl-metric-label"},"Speed now"),e("span",{class:"dl-sub"},"last 15 min")]),e("div",{class:"dl-speed-cols"},[B("Download","↓","dl-dn",r),B("Upload","↑","dl-up",l)]),V,e("div",{class:"dl-speed-today"},[e("span",{},["Today ",e("b",{},K(d+g))]),e("span",{},[e("span",{class:"dl-dn"},"↓"),` ${K(g)} `,e("span",{class:"dl-up"},"↑"),` ${K(d)}`])])])}function Pt(s,t){let n=s.slice(-30),a=n.map(g=>g.rx+g.tx),i=Math.max(1,...a),o=a.reduce((g,f)=>g+f,0),r=a.reduce((g,f,c)=>f>a[g]?c:g,0),l=g=>new Date(`${g}T12:00:00`).toLocaleDateString("en-GB",{day:"numeric",month:"short"}),d=e("div",{class:"dl-bento-bars"},n.map((g,f)=>{let c=a[f],k=e("i",{class:f===n.length-1?"hi":"",style:`height:${Math.max(4,c/i*100)}%`});return le(k,()=>[e("div",{class:"dl-tip-title"},f===n.length-1?`Today · ${l(g.day)}`:l(g.day)),e("div",{},K(c)),e("div",{class:"dl-muted dl-mono"},`↓ ${K(g.tx)} ↑ ${K(g.rx)}`)]),k}));return e("div",{class:"dl-bento-tile month"},[e("div",{class:"dl-bento-head"},[e("span",{},[e("span",{class:"dl-metric-label"},"Last 30 days"),e("b",{class:"dl-bento-total"},K(o))]),a[r]>0?e("span",{class:"dl-sub"},`peak ${K(a[r])} · ${l(n[r].day)}`):""]),n.length?d:e("p",{class:"dl-muted"},"No traffic yet."),e("div",{class:"dl-bento-head"},[e("span",{class:"dl-sub"},n.length?l(n[0].day):""),e("span",{class:"dl-sub"},t),e("span",{class:"dl-sub"},"today")])])}var oa={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",paused_all:"people",resumed_all:"people",portal_blocked:"problems"},Qe=["connections","people","problems"],Ge={connections:"Connections",people:"People",problems:"Problems"},ln={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)"},ct=s=>oa[s]??"problems";function ra(s){let t=new Map(s.people.map(a=>[a.id,a.name])),n=new Map(s.people.flatMap(a=>a.devices.map(i=>[i.id,i.name])));return{people:t,devices:n}}function la(s){let t=s==null?"":String(s);return/[",\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t}var pt={awg:"AmneziaWG",dawnline:"Dawnline",portal:"Portal"};function Le(s,t,n,a="",i=[]){let o=ra(s),r=[...t.map(c=>({ts:c.ts,category:ct(c.type),type:c.type,person:c.person?o.people.get(c.person)??c.pname??c.person:"",device:c.device?o.devices.get(c.device)??c.dname??c.device:"",detail:c.detail??"",where:c.where??"",by:be(c)??""})),...i.map(c=>({ts:c.ts,category:"system",type:`${c.src}.${c.level}`,person:"",device:"",detail:`${c.who?`${c.who} `:""}${c.msg}${c.detail?` +${c.detail}`:""}`,where:pt[c.src]??c.src,by:""}))].sort((c,k)=>c.ts-k.ts).map(({ts:c,...k})=>({time:new Date(c*1e3).toISOString(),...k})),l=new Date().toISOString().slice(0,10),d=`dawnline-activity${a?`-${a}`:""}-${l}.${n}`;if(n==="json"){fe(d,JSON.stringify(r,null,2),"application/json");return}let g=["time","category","type","person","device","detail","where","by"],f=[g.join(","),...r.map(c=>g.map(k=>la(c[k])).join(","))].join(` +`);fe(d,f,"text/csv")}var da=[["","Everything"],["7","Older than 7 days"],["30","Older than 30 days"],["90","Older than 90 days"]];function Te(s,t,n,a,i,o=!1){let r=e("select",{class:"cbi-input-select"},[e("option",{value:""},"All categories"),...Qe.map(d=>e("option",{value:d,selected:d===i?"selected":null},Ge[d])),o?e("option",{value:"system",selected:i==="system"?"selected":null},"System"):""]),l=e("select",{class:"cbi-input-select"},da.map(([d,g])=>e("option",{value:d},g)));ne(s,[e("p",{class:"dl-muted"},`${t} This cannot be undone; export first if you want a copy.`),e("label",{class:"dl-fld"},[e("span",{class:"dl-fld-label"},"Category"),r]),e("label",{class:"dl-fld"},[e("span",{class:"dl-fld-label"},"Which events"),l])],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",z("Clear",async()=>{let d=await U(async()=>{let g=o&&(r.value==="system"||r.value==="")?await N.serviceLogClear(l.value):{removed:0},f=r.value==="system"?{removed:0}:await N.logsClear({...n,category:r.value,older_days:l.value});return{removed:g.removed+f.removed}});d&&(J(),X(d.removed?`${d.removed} event${d.removed===1?"":"s"} removed`:"Nothing matched","success",3e3),a())},"negative")])}function We(s,t,n,a){let i=s==="device"?`Clears ${n}'s daily and monthly traffic history. Their person's totals and data limit are not changed.`:s==="person"?`Clears ${n}'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.";ne(s==="all"?"Reset all traffic history?":`Reset traffic history for ${n}?`,[e("p",{class:"dl-muted"},i)],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",z("Reset",async()=>{await U(()=>N.usageClear(s,t),"Traffic history reset")&&(J(),a())},"negative")])}var ht=null;function ca(s){return s?new Date(s*1e3).toLocaleString("en-GB",{day:"numeric",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"}):"—"}function dn(s,t,n=!1){return e("div",{class:"dl-kvrow"},[e("span",{class:"dl-kvrow-k"},s),e("button",{type:"button",class:`dl-kvrow-v copy${n?" dl-mono":""}`,title:"Copy",click:()=>de(t,`${s} copied`)},[e("span",{},t),v("copy")])])}function ut(s,t){return e("div",{class:"dl-kvrow"},[e("span",{class:"dl-kvrow-k"},s),e("span",{class:"dl-kvrow-v"},t)])}function cn(s,t){if(/^\s*\[.+\]\s*$/.test(s))return e("span",{class:"dl-conf-sec"},s);let n=/^(\s*[A-Za-z0-9]+\s*=)\s*(.*)$/.exec(s);if(!n)return document.createTextNode(s);let a=/^(\s*)(PrivateKey|PresharedKey)\b/.test(s);return e("span",{},[e("span",{class:"dl-conf-k"},n[1])," ",a&&!t?e("span",{class:"dl-conf-mask"},"••••••••••••••••"):n[2]])}function pa(s){let t=!1,n=e("pre",{class:"dl-conf"}),a=()=>dom.content(n,s.conf.split(` `).flatMap((r,l)=>l?[` -`,sn(r,t)]:[sn(r,t)])),i=e("button",{type:"button",class:"dl-chipbtn",click:r=>{r.preventDefault(),t=!t,dom.content(i,[w(t?"x":"key"),t?"Hide key":"Show key"]),a()}},[w("key"),"Show key"]);a();let s=new Blob([o.conf]).size;return e("div",{class:"dl-stack gap8"},[e("div",{class:"dl-filecard"},[e("span",{class:"dl-filecard-ic"},".conf"),e("span",{class:"dl-stack"},[e("span",{class:"dl-mono dl-ellipsis"},o.filename),e("span",{class:"dl-sub"},`AmneziaWG · ${s} bytes · import it in the app`)]),N([w("download")," Download"],()=>ve(o.filename,o.conf,"application/octet-stream"),"positive")]),e("details",{class:"dl-params"},[e("summary",{},[w("chevron"),e("span",{},"Configuration"),e("span",{class:"dl-spacer"}),i,e("button",{type:"button",class:"dl-chipbtn",click:r=>{r.preventDefault(),re(o.conf,"Configuration copied")}},[w("copy"),"Copy"])]),n])])}async function Et(o){if(!o.has_private_key)return e("div",{class:"dl-hint"},"This device generated its own keys in the browser, so its full configuration only exists on that device.");let t=await Zt(o,`${o.server} · ${o.person} · ${o.name}`),n={qr:()=>e("div",{class:"dl-qr-pane"},[Pe(Be(o.conf),"dl-qr"),e("span",{class:"dl-sub"},"Scan with AmneziaVPN or AmneziaWG on the device.")]),key:()=>e("div",{class:"dl-stack gap8"},[e("div",{class:"dl-linkbox"},[e("span",{class:"dl-mono"},t),N("Copy",()=>re(t,"Key copied"))]),e("span",{class:"dl-sub"},"AmneziaVPN → Add server → Insert key. Keep it private.")]),file:()=>Vn(o)},a=e("div",{class:"dl-connect-body"}),i=e("div",{class:"dl-seg"}),s=r=>{i.querySelectorAll("button").forEach(l=>l.classList.toggle("on",l.dataset.id===r)),dom.content(a,n[r]())};for(let[r,l]of[["qr","QR code"],["key","Key"],["file","File"]])i.appendChild(e("button",{type:"button","data-id":r,click:()=>s(r)},l));return s("qr"),e("div",{class:"dl-stack gap12"},[i,a])}function Yn(o,t,n,a){lt?.close();let i=e("aside",{class:"dl-drawer",role:"dialog","aria-modal":"true"},[e("div",{class:"dl-drawer-head"},[o,e("button",{type:"button",class:"dl-drawer-x","aria-label":"Close",click:()=>l()},w("x"))]),e("div",{class:"dl-drawer-body"},t),n?e("div",{class:"dl-drawer-foot"},n):""]),s=e("div",{class:"dl-drawer-overlay dl-root",click:h=>{h.target===s&&l()}},i),r=h=>{h.key==="Escape"&&!document.body.classList.contains("modal-overlay-active")&&l()};function l(){document.removeEventListener("keydown",r),s.classList.remove("open"),setTimeout(()=>s.remove(),220),lt===d&&(lt=null),a()}let d={close:l,panel:i};return document.addEventListener("keydown",r),document.body.appendChild(s),requestAnimationFrame(()=>s.classList.add("open")),lt=d,d}var rn={connect:["ok","Connected"],disconnect:["","Went offline"],roam:["","Changed network"],device_added:["accent","Added"],device_removed:["","Removed"]};function Jn(o,t){let n=o.filter(a=>a.device===t&&rn[a.type]).reverse().slice(0,12);return n.length?e("div",{class:"dl-dev-log"},n.map(a=>{let[i,s]=rn[a.type],r=a.type==="connect"?[a.detail?e("span",{class:"dl-mono"},` ${a.detail}`):"",a.where?e("span",{class:"dl-faint"},` · ${a.where}`):""]:a.type==="roam"?[e("span",{class:"dl-mono dl-faint"},` ${a.detail??""}`)]:a.type==="device_added"?[e("span",{class:"dl-faint"},(a.detail??"").includes("(portal)")?" from the portal":" by you")]:[],l=new Date(a.ts*1e3);return e("div",{class:"dl-dev-log-row"},[e("span",{class:`dl-ev-dot ${i}`}),e("span",{class:"dl-row-main"},[e("span",{},s),...r]),e("span",{class:"dl-faint dl-nowrap",title:l.toLocaleString()},ce(a.ts))])})):e("div",{class:"dl-sub"},"No activity yet.")}function Qn(o){return o.disabled?e("span",{class:"dl-dstat"},[e("i",{class:"dot"}),"Disabled"]):o.online?e("span",{class:"dl-dstat ok"},[e("i",{class:"dot ok"}),`Online from ${o.endpoint}`]):o.handshake?e("span",{class:"dl-dstat"},[e("i",{class:"dot"}),`Last seen ${ce(o.handshake)}`]):e("span",{class:"dl-dstat warn"},[e("i",{class:"dot warn"}),"Waiting for the first connection"])}async function Ce(o,t,n,a){let i=await O(()=>P.deviceConfig(t.id));if(!i)return;let s=t,r=o,l=await Et(i),d=e("div",{class:"dl-drawer-title"}),h=e("div",{}),m=e("div",{}),p=e("div",{class:"dl-live"}),$=e("div",{},e("div",{class:"dl-sub"},"Loading…")),k=[],z=async()=>{let g=await P.events(5e3).catch(()=>null);g&&(k=g.events.filter(_=>_.device===s.id),dom.content($,Jn(g.events,s.id)))},Y=()=>{let g=a?.points.find(c=>c.device===s.id&&c.ip===s.endpoint);dom.content(d,[e("span",{class:`dl-dcard-ic${s.online?" on":""}`},w(s.kind)),e("div",{class:"dl-stack"},[e("div",{class:"dl-title-row"},[e("h3",{},s.name),N([w("edit")],()=>H(),"neutral",{title:"Rename",class:"cbi-button cbi-button-neutral dl-icon-only sm"})]),e("span",{class:"dl-sub"},[`${r.name} · ${Me[s.kind]}`])])]);let _=s.spark.reduce((c,u)=>c+u,0);dom.content(h,e("div",{class:"dl-dstats"},[e("div",{class:"dl-dstats-cell wide"},[e("span",{class:"dl-metric-label"},"Status"),Qn(s)]),e("div",{class:"dl-dstats-cell"},[e("span",{class:"dl-metric-label"},"This month"),e("b",{},V(s.month[0]+s.month[1])),e("span",{class:"dl-sub dl-mono"},`↓ ${V(s.month[1])} ↑ ${V(s.month[0])}`)]),e("div",{class:"dl-dstats-cell"},[e("span",{class:"dl-metric-label"},"Last 7 days"),e("b",{},V(_)),nn(s.spark,120,22)])])),dom.content(m,e("div",{class:"dl-kv2"},[on("Tunnel address",s.address),s.hostname&&r.access!=="internet"?on("Local address",s.hostname):"",s.endpoint?dt("Client IP",e("span",{},[e("span",{class:"dl-mono"},s.endpoint),g?e("span",{class:"dl-faint"},` · ${[g.city,g.org].filter(Boolean).join(" · ")}`):""])):"",dt("Total",e("span",{class:"dl-kv-act"},[`↓ ${V(s.total[1])} · ↑ ${V(s.total[0])}`,e("button",{type:"button",class:"dl-linkbtn danger",click:()=>Ue("device",s.id,s.name,()=>setTimeout(F,300))},"Reset")])),dt("Added",`${Kn(s.created)} · ${s.created_by==="portal"?"from the portal":"by you"}`),dt("Public key",e("span",{class:"dl-mono dl-faint"},i.amnezia.client_pub_key?`${i.amnezia.client_pub_key.slice(0,16)}…`:"—"))])),dom.content(p,s.online?[e("i",{class:"dot ok"}),e("span",{class:"dl-ok"},"Connected")]:s.handshake?[e("i",{class:"dot"}),e("span",{class:"dl-muted"},`Last connected ${ce(s.handshake)}`)]:[e("i",{class:"dot warn pulse"}),e("span",{class:"dl-muted"},"Waiting for the first connection…")]),dom.content(y,[N([w(s.disabled?"play":"pause"),s.disabled?" Enable":" Disable"],async()=>{await O(()=>P.deviceUpdate(s.id,void 0,!s.disabled),s.disabled?"Device enabled":"Device disabled")&&await F()},"neutral",s.disabled?{}:{class:"cbi-button cbi-button-neutral dl-btn-warn"}),N([w("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;if(await O(()=>P.deviceRotate(s.id),"New keys generated")){n(),f.close();let u=await P.status(1),C=u.people.find(b=>b.id===r.id),v=C?.devices.find(b=>b.id===s.id);C&&v&&Ce(C,v,n,u.geo)}}),e("span",{class:"dl-spacer"}),N([w("trash")," Remove"],async()=>{await ae(`Remove ${s.name}?`,"The device is disconnected immediately and its configuration stops working.","Remove",!0)&&await O(()=>P.deviceDelete(s.id),"Device removed")&&(f.close(),n())},"negative")])},F=async()=>{let g=await P.status(1).catch(()=>null),_=g?.people.find(u=>u.id===r.id),c=_?.devices.find(u=>u.id===s.id);!g||!_||!c||(r=_,s=c,a=g.geo,Y(),n())},H=()=>{let g=e("input",{type:"text",class:"cbi-input-text",value:s.name,maxlength:48});ne(`Rename ${s.name}`,[e("div",{class:"cbi-value"},[e("label",{class:"cbi-value-title"},"Name"),e("div",{class:"cbi-value-field"},g)])],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",N("Save",async()=>{await O(()=>P.deviceUpdate(s.id,g.value,void 0),"Renamed")&&(J(),await F())},"positive")]),setTimeout(()=>g.select(),50)},y=e("div",{class:"dl-drawer-actions"}),D=e("div",{class:"dl-stack gap16"},[h,e("section",{class:"dl-dsec"},[e("div",{class:"dl-dsec-head"},[e("h4",{},"Connect"),p]),s.config_stale?e("div",{class:"dl-note warn"},[w("alert"),e("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.")]):"",l]),e("section",{class:"dl-dsec"},[e("div",{class:"dl-dsec-head"},[e("h4",{},"Activity"),e("div",{class:"dl-dsec-actions"},[e("button",{type:"button",class:"dl-linkbtn",click:()=>be({people:[r]},k,"csv",s.id)},"Export"),e("button",{type:"button",class:"dl-linkbtn danger",click:()=>Ee(`Clear ${s.name}'s activity`,`Removes events about ${s.name}.`,{device:s.id},z)},"Clear"),e("a",{href:L.url("admin/network/dawnline/activity")},"All activity")])]),$]),e("section",{class:"dl-dsec"},[e("div",{class:"dl-dsec-head"},e("h4",{},"Details")),m])]);z();let T=window.setInterval(()=>{F(),z()},8e3),f=Yn(d,D,y,()=>clearInterval(T));Y()}function Re(o,t){let n=e("input",{type:"text",class:"cbi-input-text",placeholder:Me.phone,maxlength:48}),a="phone",i=e("div",{class:"dl-kinds",role:"radiogroup","aria-label":"Type"},tn.map(r=>e("button",{type:"button",role:"radio",class:r===a?"on":"","aria-checked":r===a?"true":"false","data-kind":r,click:()=>{a=r,i.querySelectorAll("button").forEach(l=>{let d=l.dataset.kind===r;l.classList.toggle("on",d),l.setAttribute("aria-checked",d?"true":"false")}),n.placeholder=Me[r]}},[w(r),e("span",{},Me[r])]))),s=o.devices.length>=o.device_limit;ne(`Add a device for ${o.name}`,[s?e("p",{class:"dl-hint"},`${o.name} already has ${o.devices.length} of ${o.device_limit} devices. As admin you can still add one.`):"",e("div",{class:"dl-fld"},[e("span",{class:"dl-fld-label"},"Type"),i]),e("label",{class:"dl-fld"},[e("span",{class:"dl-fld-label"},"Name"),n])],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",N("Add device",async()=>{let r=n.value.trim()||n.placeholder.replace(/^e\.g\. /,""),l=await O(()=>P.deviceCreate(o.id,r,a));if(!l)return;J(),X(`${r} added`,"success",3e3),t();let d=await P.status(1),h=d.people.find(p=>p.id===o.id),m=h?.devices.find(p=>p.id===l.id);h&&m&&Ce(h,m,t,d.geo)},"positive")]),setTimeout(()=>n.focus(),50)}var Se=1080,Je=1512,xe=96,Zn="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif",Xn="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",Ye=o=>o.replace(/[&<>"']/g,t=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[t]);function ea(o,t,n){let a=new URL(n),i=a.pathname.slice(1),s=Math.min(92,Math.floor((Se-2*xe)/(.58*(4+o.name.length)))),r=Se-2*xe,l=392,d=40,h=Be(n,2).replace("`${Y}`;return``+m(xe+82,xe+42,36,"#a3a3a3",Ye(t))+m(xe,276,s,"#ffffff",`Hi, ${Ye(o.name)}`,'font-weight="600"')+m(xe,340,40,"#8a8a8a",`Scan to connect to ${Ye(t)}`)+``+h+`${Ye(i)}`+m(Se/2,l+r+156,34,"#737373",Ye(a.host),'text-anchor="middle"')+""}async function ta(o){let t=new Image;t.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(o)}`,await t.decode();let n=document.createElement("canvas");return n.width=Se,n.height=Je,n.getContext("2d").drawImage(t,0,0,Se,Je),new Promise((a,i)=>n.toBlob(s=>s?a(s):i(new Error("Could not draw the card")),"image/png"))}async function Qe(o,t,n={}){if(!o.link){X("The personal portal is off. Turn it on in Settings.","warning");return}let a=o.link,i=await O(()=>ta(ea(o,t,a)));if(!i)return;let s=new File([i],`${o.id}-invite.png`,{type:"image/png"}),r=URL.createObjectURL(i),l=navigator,d=!!l.canShare?.({files:[s]}),h=()=>{URL.revokeObjectURL(r),J()},m=d?N([w("link")," Share card"],async()=>{try{await l.share({files:[s],title:`Invite ${o.name}`})}catch{}},"positive"):N([w("download")," Download card"],()=>ve(s.name,i),"positive");ne(n.title??`Invite ${o.name}`,e("div",{class:"dl-invite"},[e("img",{src:r,alt:`Invite card for ${o.name}`}),e("div",{class:"dl-invite-side"},[e("p",{class:"dl-muted"},n.lead??`Send ${o.name} the card or the link. They open it, add their devices and connect — no account needed.`),e("button",{type:"button",class:"dl-invite-link",title:"Copy link",click:()=>re(a,"Personal link copied")},[e("span",{},a.replace(/^https:\/\//,"")),w("copy")]),...(o.links??[]).filter(p=>p!==a).map(p=>e("button",{type:"button",class:"dl-invite-link alt",title:"Copy this link",click:()=>re(p,"Link copied")},[e("span",{},p.replace(/^https?:\/\//,"")),e("span",{class:`dl-pill ${p.startsWith("http:")?"warn":""}`},p.startsWith("http:")?"HTTP":"Also"),w("copy")])),e("ol",{class:"dl-invite-steps"},[e("li",{},["Install ",e("b",{},"AmneziaVPN")," on the device"]),e("li",{},"Open the link or scan the code"),e("li",{},"Add the device and connect")]),e("div",{class:"dl-invite-actions"},[m,N([w("copy")," Copy link"],()=>re(a,"Personal link copied"))])])]),[e("button",{class:"cbi-button cbi-button-neutral",click:h},"Done")],"wide")}var Ge=null,ct=!1;function Ze(o){return`${L.url("admin/network/dawnline/server")}?${o?`server=${encodeURIComponent(o)}&`:""}section=people`}function pe(o,t){return`${L.url("admin/network/dawnline/person")}?id=${encodeURIComponent(o)}${t?`&device=${encodeURIComponent(t)}`:""}`}function na(o){location.href=L.url(`admin/network/dawnline/${o}`)}function aa(o,t){let n=o?new Date(`${o}T12:00:00`):new Date,a=n.getTime()re(o.link,"Personal link copied")}),a.push({group:n,label:`Add device for ${o.name}`,icon:"plus",run:()=>location.href=`${pe(o.id)}&add=1`}),a.push({group:n,label:o.paused?`Resume ${o.name}`:`Pause ${o.name}`,icon:o.paused?"play":"pause",kbd:"P",run:async()=>{await O(()=>P.personPause(o.id,!o.paused),o.paused?`${o.name} resumed`:`${o.name} paused`),t()}}),a.push({group:n,label:"Extend access by 1 month",icon:"key",run:async()=>{await O(()=>P.personUpdate(o.id,{expires:aa(o.expires,1)}),"Access extended"),t()}}),a}function oa(o,t,n){let a=t.trim().toLowerCase(),i=[],s=o.people.filter(l=>!a||[l.name,l.id].some(d=>d.toLowerCase().includes(a)));for(let l of s.slice(0,6))i.push({group:"People",label:l.name,hint:`${en[l.access]} · ${l.online?`${l.online} online`:`${l.devices.length} device${l.devices.length===1?"":"s"}`}`,avatar:Le(l.name),run:()=>location.href=pe(l.id)});for(let l of o.people)for(let d of l.devices){let h=[d.name,d.address,d.endpoint,d.hostname].join(" ").toLowerCase();a&&!h.includes(a)||!a&&!d.online||i.push({group:"Devices",label:d.name,hint:`${l.name} · ${d.address}${d.online?` · ${d.endpoint}`:""}`,icon:d.kind,run:()=>location.href=pe(l.id,d.id)})}(s.length===1||s.length&&a)&&i.push(...ia(s[0],n));let r=[["overview","Overview","globe"],["people","People","shield"],["activity","Activity","file"],["server","Server","key"],["health","Health","check"],["settings?section=backups","Backups","archive"],["settings","Settings","edit"]];for(let[l,d,h]of r)(!a||d.toLowerCase().includes(a))&&i.push({group:"Go to",label:d,icon:h,run:()=>na(l)});return(!a||"add person".includes(a))&&i.push({group:"Go to",label:"Add person",icon:"plus",run:()=>location.href=`${L.url("admin/network/dawnline/server")}?section=people&add=1`}),i}async function Ct(){if(ct)return;ct=!0;let o=e("input",{type:"text",class:"dl-pal-input",placeholder:"Search people, devices, IPs or actions…","aria-label":"Search"}),t=e("div",{class:"dl-pal-list",role:"listbox"}),n=e("div",{class:"dl-pal",role:"dialog","aria-label":"Command menu"},[e("label",{class:"dl-pal-search"},[w("search"),o,e("kbd",{},"Esc")]),t,e("div",{class:"dl-pal-foot"},[e("span",{},[e("kbd",{},"↑↓")," navigate"]),e("span",{},[e("kbd",{},"↵")," open"]),e("span",{},[e("kbd",{},"⌘K")," toggle"])])]),a=e("div",{class:"dl-pal-overlay dl-root"},n),i=[],s=0,r=()=>{a.remove(),document.removeEventListener("keydown",d,!0),ct=!1},l=()=>{let h=Ge?.st;if(!h){t.replaceChildren(e("div",{class:"dl-pal-empty"},"Loading…"));return}i=oa(h,o.value,()=>{Ge=null,r(),location.reload()}),s=Math.min(s,Math.max(0,i.length-1));let m=[],p="";i.forEach(($,k)=>{$.group!==p&&(p=$.group,m.push(e("div",{class:"dl-pal-group"},p)));let z=e("div",{class:`dl-pal-item${k===s?" sel":""}`,role:"option","aria-selected":k===s?"true":"false",click:()=>{r(),$.run()},mousemove:()=>{s!==k&&(s=k,l())}},[$.avatar?e("span",{class:"dl-avatar sm"},$.avatar):$.icon?w($.icon):e("span",{class:"dl-pal-ic"}),e("span",{class:"dl-pal-label"},[$.label,$.hint?e("span",{class:"dl-faint"},` · ${$.hint}`):""]),$.kbd?e("kbd",{},$.kbd):""]);m.push(z)}),i.length||m.push(e("div",{class:"dl-pal-empty"},"Nothing found.")),t.replaceChildren(...m),t.querySelector(".sel")?.scrollIntoView({block:"nearest"})},d=h=>{if(h.key==="Escape")h.preventDefault(),r();else if(h.key==="ArrowDown")h.preventDefault(),s=Math.min(i.length-1,s+1),l();else if(h.key==="ArrowUp")h.preventDefault(),s=Math.max(0,s-1),l();else if(h.key==="Enter"){h.preventDefault();let m=i[s];m&&(r(),m.run())}};if(o.addEventListener("input",()=>{s=0,l()}),a.addEventListener("click",h=>{h.target===a&&r()}),document.addEventListener("keydown",d,!0),document.body.appendChild(a),o.focus(),l(),!Ge||Date.now()-Ge.at>1e4){let h=await P.status(1).catch(()=>null);h&&(Ge={st:h,at:Date.now()}),ct&&l()}}function we(o){o&&(Ge={st:o,at:Date.now()});let t=window;t.__dlPalette||(t.__dlPalette=!0,window.addEventListener("keydown",n=>{if(!location.pathname.includes("/admin/network/dawnline"))return;let a=/^(INPUT|TEXTAREA|SELECT)$/.test(n.target?.tagName??"")||n.target?.isContentEditable,i=(n.key==="k"||n.key==="K")&&(n.metaKey||n.ctrlKey),s=n.key==="/"&&!a&&!document.body.classList.contains("modal-overlay-active");!i&&!s||(n.preventDefault(),n.stopImmediatePropagation(),Ct())},!0))}var ln="https://unpkg.com/maplibre-gl@4.7.1/dist/maplibre-gl",sa="https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json",ra="https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",la={online:0,"24h":86400,"7d":7*86400,"30d":30*86400},Xe=null;function da(o){let t=window;return o.appendChild(e("link",{rel:"stylesheet",href:`${ln}.css`})),t.maplibregl?Promise.resolve(t.maplibregl):Xe||(Xe=new Promise((n,a)=>{let i=e("script",{src:`${ln}.js`});i.onload=()=>t.maplibregl?n(t.maplibregl):a(new Error("MapLibre failed to load")),i.onerror=()=>{Xe=null,a(new Error("Could not load the map library (no internet access from this browser?)"))},o.appendChild(i)}),Xe)}function pt(){let o=document.documentElement.getAttribute("data-darkmode");return o!=null?o==="true":window.matchMedia?.("(prefers-color-scheme: dark)").matches??!1}function ca(o,t,n=48){let a=(o[0]+t[0])/2,i=(o[1]+t[1])/2,s=t[0]-o[0],r=t[1]-o[1],l=Math.hypot(s,r)||1,d=Math.min(.25*l,12),h=a-r/l*d,m=i+s/l*d,p=[];for(let $=0;$<=n;$++){let k=$/n,z=1-k;p.push([z*z*o[0]+2*z*k*h+k*k*t[0],z*z*o[1]+2*z*k*m+k*k*t[1]])}return p}function pa(o,t){let n=new Map;for(let a of o.geo.points){if(o.person&&a.person!==o.person||(t==="online"?!a.online:o.now-a.ts>la[t]))continue;let i=n.get(a.device);(!i||a.online&&!i.online||a.online===i.online&&a.ts>i.ts)&&n.set(a.device,a)}return[...n.values()]}var Fe=class{constructor(t,n="online",a=380){this.cb=t;this.map=null;this.gl=null;this.markers=[];this.popup=null;this.anim=0;this.data=null;this.fitted=!1;this.range=n,this.status=e("div",{class:"dl-map-status"}),this.el=e("div",{class:"dl-geomap",style:`height:${a}px`},this.status)}async mount(t){this.data=t;try{this.gl=await da(this.el)}catch(n){this.status.textContent=n.message;return}this.map=new this.gl.Map({container:this.el,style:pt()?sa:ra,center:[t.geo.home?.lon??20,t.geo.home?.lat??50],zoom:3,attributionControl:{compact:!0},dragRotate:!1,pitchWithRotate:!1,cooperativeGestures:!0}),this.map.addControl(new this.gl.NavigationControl({showCompass:!1}),"bottom-right"),this.map.on("load",()=>{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"],"#40c977",pt()?"#ededed":"#0d0d0d"],"circle-opacity":["case",["get","online"],.12,.06],"circle-stroke-width":1,"circle-stroke-color":["case",["get","online"],"#40c977",pt()?"#ededed":"#0d0d0d"],"circle-stroke-opacity":["case",["get","online"],.35,.15]}}),this.map.addSource("dl-arcs",{type:"geojson",data:{type:"FeatureCollection",features:[]}}),this.map.addLayer({id:"dl-arc-recent",type:"line",source:"dl-arcs",filter:["==",["get","online"],!1],layout:{"line-cap":"round"},paint:{"line-color":pt()?"#ededed":"#0d0d0d","line-opacity":.35,"line-width":1.5,"line-dasharray":[2,3]}}),this.map.addLayer({id:"dl-arc-glow",type:"line",source:"dl-arcs",filter:["==",["get","online"],!0],layout:{"line-cap":"round"},paint:{"line-color":"#40c977","line-opacity":.18,"line-width":7}}),this.map.addLayer({id:"dl-arc-live",type:"line",source:"dl-arcs",filter:["==",["get","online"],!0],layout:{"line-cap":"round"},paint:{"line-color":"#40c977","line-width":2}}),this.map.addLayer({id:"dl-arc-flow",type:"line",source:"dl-arcs",filter:["==",["get","online"],!0],layout:{"line-cap":"round"},paint:{"line-color":"#ffffff","line-width":2,"line-opacity":.8,"line-dasharray":[0,4,3]}}),this.animate(),this.draw()})}setRange(t){this.range=t,this.fitted=!1,this.draw()}update(t){this.data=t,this.draw()}destroy(){cancelAnimationFrame(this.anim),this.map?.remove(),this.map=null}animate(){let t=[[0,4,3],[.5,4,2.5],[1,4,2],[1.5,4,1.5],[2,4,1],[2.5,4,.5],[3,4,0],[0,.5,3,3.5],[0,1,3,3],[0,1.5,3,2.5],[0,2,3,2],[0,2.5,3,1.5],[0,3,3,1],[0,3.5,3,.5]],n=-1,a=0,i=s=>{this.map&&(s-a>70&&(a=s,n=(n+1)%t.length,this.map.getLayer("dl-arc-flow")&&this.map.setPaintProperty("dl-arc-flow","line-dasharray",t[n])),this.anim=requestAnimationFrame(i))};this.anim=requestAnimationFrame(i)}groups(t){let n=new Map;for(let a of t){let i=`${a.asn||a.org||a.ip}|${a.city}|${a.cc}`,s=n.get(i);s||(s={key:i,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:[]},n.set(i,s)),s.points.push(a),s.online||(s.online=a.online),s.ts=Math.max(s.ts,a.ts)}return[...n.values()]}draw(){if(!this.map||!this.data||!this.map.getSource("dl-arcs"))return;let t=this.data,n=this.groups(pa(t,this.range)),a=t.geo.home;for(let r of this.markers)r.remove();this.markers=[];let i=new Map,s=n.map(r=>{let l=`${r.lat.toFixed(2)},${r.lon.toFixed(2)}`,d=i.get(l)??0;return i.set(l,d+1),{g:r,at:[r.lon+d*.25,r.lat]}});if(this.map.getSource("dl-areas").setData({type:"FeatureCollection",features:s.map(({g:r,at:l})=>({type:"Feature",properties:{online:r.online},geometry:{type:"Point",coordinates:l}}))}),this.map.getSource("dl-arcs").setData({type:"FeatureCollection",features:a?s.map(({g:r,at:l})=>({type:"Feature",properties:{online:r.online},geometry:{type:"LineString",coordinates:ca([a.lon,a.lat],l)}})):[]}),a){let r=e("div",{class:"dl-mk-home",title:`Home router${a.city?` · ${a.city}`:""}${a.org?` · ${a.org}`:""}`});r.innerHTML=_t("home","dl-mk-home-ic"),this.markers.push(new this.gl.Marker({element:r}).setLngLat([a.lon,a.lat]).addTo(this.map))}for(let{g:r,at:l}of s){let d=r.points.length,h=e("button",{type:"button",class:`dl-mk${r.online?" online":""}${d>1?" multi":""}`,"aria-label":`${d} device${d===1?"":"s"} via ${r.org||"unknown network"} in ${r.city||"unknown city"}`},d>1?e("span",{class:"dl-mk-count"},String(d)):e("span",{class:"dl-mk-dot"})),p=!!a&&Math.abs(l[0]-a.lon)<.02&&Math.abs(l[1]-a.lat)<.02?[22,-16]:[0,0];h.addEventListener("click",$=>{$.stopPropagation(),this.openPopup(r,l,p)}),this.markers.push(new this.gl.Marker({element:h,offset:p}).setLngLat(l).addTo(this.map))}if(!this.fitted){let r=s.map(l=>l.at);a&&(r.length===0||this.range!=="online"||s.some(l=>l.g.online))&&r.push([a.lon,a.lat]),this.fit(r),this.fitted=!0}this.status.textContent=s.length||a?"":"No locations yet",this.status.style.display=this.status.textContent?"":"none"}fit(t){if(!t.length)return;let n=(d,h)=>{let m=Math.PI/180,p=(h[1]-d[1])*m,$=(h[0]-d[0])*m,k=Math.sin(p/2)**2+Math.cos(d[1]*m)*Math.cos(h[1]*m)*Math.sin($/2)**2;return 12742*Math.asin(Math.sqrt(k))},a=[t.reduce((d,h)=>d+h[0],0)/t.length,t.reduce((d,h)=>d+h[1],0)/t.length],i=t;if(t.length>=5){let d=[...t].sort((h,m)=>n(a,h)-n(a,m));i=d.slice(0,Math.ceil(d.length*.9))}if(Math.max(...i.map(d=>n(a,d)))<25){this.map.jumpTo({center:a,zoom:9.5});return}let r=new this.gl.LngLatBounds(i[0],i[0]);i.forEach(d=>r.extend(d));let l=this.el.clientHeight||380;this.map.fitBounds(r,{padding:{top:Math.min(90,l/4),bottom:Math.min(70,l/5),left:60,right:60},maxZoom:9,duration:0})}openPopup(t,n,a=[0,0]){let i=this.data;this.popup?.remove();let s=[t.city,t.cc||t.country].filter(Boolean).join(", "),r=[...new Set(t.points.map(m=>m.person))],l=t.points.sort((m,p)=>Number(p.online)-Number(m.online)||p.ts-m.ts).map(m=>{let p=i.people.find(k=>k.id===m.person),$=p?.devices.find(k=>k.id===m.device);return e("button",{type:"button",class:"dl-pop-row",click:()=>this.cb.openDevice(m.person,m.device)},[e("span",{class:`dl-pop-dot${m.online?" on":""}`}),e("span",{class:"dl-pop-name"},[e("b",{},p?.name??m.person),` · ${$?.name??"device"}`]),e("span",{class:"dl-faint dl-nowrap"},m.online?"now":ce(m.ts,i.now))])}),d=e("div",{class:"dl-pop"},[e("div",{class:"dl-pop-head"},[e("span",{class:"dl-pop-net"},w("globe")),e("div",{class:"dl-stack"},[e("strong",{},t.org||"Unknown network"),e("span",{class:"dl-faint"},[t.asn?`AS${t.asn} · `:"",s?`${s} · approximate`:"approximate location"])])]),e("div",{class:"dl-pop-list"},l),r.length===1?e("div",{class:"dl-pop-actions"},[e("button",{type:"button",class:"cbi-button cbi-button-positive important",click:()=>this.cb.openPerson(r[0])},`Open ${i.people.find(m=>m.id===r[0])?.name??"person"}`)]):""]),h=this.el.clientHeight||380;this.map.easeTo({center:n,offset:[0,Math.min(140,h*.32)],duration:300}),this.popup=new this.gl.Popup({offset:[a[0],a[1]-18],anchor:"bottom",closeButton:!1,focusAfterOpen:!1,maxWidth:"300px",className:"dl-popup"}).setLngLat(n).setDOMContent(d).addTo(this.map)}};function ut(o,t,n=!0){let a=[["online","Online now"],["24h","24h"],["7d","7 days"],["30d","30 days"]],i=e("div",{class:"dl-seg",role:"tablist"});for(let[s,r]of a)s==="online"&&!n||i.appendChild(e("button",{type:"button",role:"tab",class:s===o?"on":"","data-v":s,click:()=>{i.querySelectorAll("button").forEach(l=>l.classList.toggle("on",l.dataset.v===s)),t(s)}},r));return i}var cn=[{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"}],We=o=>cn.find(t=>t.id===o),ua={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)."};function dn(o,t){return e("span",{class:"dl-dots",title:`${t}: ${o} of 4`},[e("span",{class:"dl-dots-label"},t),e("span",{class:"dl-dots-row"},[0,1,2,3].map(n=>e("i",{class:ndom.content(i,cn.map(r=>{let l=!r.needs||o[r.needs],d=r.id===t;return e("button",{type:"button",role:"radio","aria-checked":d?"true":"false","aria-disabled":l?null:"true",class:`dl-method${d?" on":""}${l?"":" off"}`,click:()=>{!l||d||(t=r.id,s(),n(r.id))}},[e("div",{class:"dl-method-head"},[e("span",{class:"dl-method-ic"},w(r.ic)),e("b",{},r.title),r.id===a?e("span",{class:"dl-pill ok"},"Current"):""]),e("p",{},r.text),e("div",{class:"dl-method-meters"},[dn(r.stealth,"Stealth"),dn(r.speed,"Speed")]),e("div",{class:"dl-method-foot"},l?[w("phone"),e("span",{},r.apps)]:[w("alert"),e("span",{},ua[r.needs])])])}));return s(),i}var ha={connect:"ok",disconnect:"",roam:"",device_added:"accent",device_removed:"",person_added:"",person_removed:"",paused:"warn",resumed:"ok",paused_all:"warn",resumed_all:"ok",server_down:"bad",server_up:"ok",portal_blocked:"bad",person_changed:"",devices_removed:"warn"};function et(o,t){let n=o.people.find(h=>h.id===t.person),a=n?.name??t.person??"",i=n?.devices.find(h=>h.id===t.device)?.name??"",s=h=>e("b",{},h),r=h=>e("span",{class:"dl-muted"},h),l=h=>e("span",{class:"dl-mono"},h),d=i?`${a} · ${i}`:a;switch(t.type){case"connect":return[s(d),r(" connected"),...t.detail?[r(" from "),l(t.detail)]:[],...t.where?[r(` · ${t.where}`)]:[]];case"disconnect":return[s(d),r(" went offline")];case"roam":return[s(d),r(" changed network "),l(t.detail??"")];case"device_added":return[s(a),r(" added "),e("span",{},t.detail??"a device")];case"device_removed":return[s(a),r(" removed "),e("span",{},t.detail??"a device")];case"person_added":return[r("You added "),s(t.detail??a)];case"person_removed":return[r("You removed "),s(t.detail??a)];case"person_changed":return[r("You changed "),s(a),r(` · ${t.detail??""}`)];case"paused":return[s(a),r(` paused — ${t.detail??""}`)];case"resumed":return[s(a),r(" resumed"),...t.detail&&t.detail!=="active"?[r(` — ${t.detail}`)]:[]];case"paused_all":return[r("Everyone paused")];case"resumed_all":return[r("Everyone resumed")];case"server_down":return[r("Tunnel "),l(t.detail??""),r(" went down")];case"server_up":return[r("Tunnel "),l(t.detail??""),r(" is back up")];case"portal_blocked":return[r("Portal blocked "),l(t.detail??""),r(" for 15 min after too many wrong codes")];case"devices_removed":return[s(a),r("’s devices were removed — end date reached")];default:return[r(`${t.type}${t.detail?`: ${t.detail}`:""}`)]}}function tt(o,t){return e("div",{class:"dl-row"},[e("span",{class:`dl-ev-dot ${ha[t.type]??""}`}),e("span",{class:"dl-row-main"},et(o,t)),e("span",{class:"dl-faint dl-nowrap",title:new Date(t.ts*1e3).toLocaleString()},ce(t.ts,o.now))])}function fa(o){let t=[],n=(i,s)=>e("a",{href:i},s);for(let i of o.servers)i.enabled&&!i.up&&t.push({tone:"bad",text:[`Tunnel ${i.ifname} is down. `,n(L.url("admin/network/dawnline/health"),"Open Health")]});o.settings.paused_all&&t.push({tone:"warn",text:["Everyone is paused."]});for(let i of o.people)if(i.state==="quota")t.push({tone:"warn",text:[n(pe(i.id),i.name)," reached the data limit."]});else if(i.state==="expired")t.push({tone:"warn",text:[n(pe(i.id),i.name),"’s access has ended."]});else{let s=ze(i.expires);s!=null&&s>=0&&s<=Math.max(i.expire_warn,3)&&t.push({tone:"",text:[n(pe(i.id),i.name),`’s access ends in ${s} day${s===1?"":"s"}.`]}),i.quota_limit&&i.quota_used>=i.quota_limit*.9&&t.push({tone:"",text:[n(pe(i.id),i.name)," has used 90% of the data limit."]})}let a=o.people.flatMap(i=>i.devices.filter(s=>s.config_stale).map(s=>[i,s]));return a.length&&t.push({tone:"warn",text:a.length===1?[n(pe(a[0][0].id,a[0][1].id),`${a[0][0].name} · ${a[0][1].name}`)," needs its configuration again."]:[`${a.length} devices need their configuration again (networks or DNS changed).`]}),o.servers.some(i=>i.lan_like)&&o.like_home.error&&t.push({tone:"warn",text:[`Internet through the LAN is off: ${o.like_home.error} `,n(L.url("admin/network/dawnline/health"),"Details")]}),o.settings.portal_enabled||t.push({tone:"",text:["The personal portal is off. ",n(L.url("admin/network/dawnline/settings"),"Turn on")]}),t}function ht(o,t){let n=o.servers.find(d=>d.id===t)??o.servers[0],a=o.people.filter(d=>d.server===n.id),i=new Set(a.map(d=>d.id)),s=a.flatMap(d=>d.devices),r=d=>a.reduce((h,m)=>{let p=d(m);return[h[0]+p[0],h[1]+p[1]]},[0,0]),l=n.series?.[n.series.length-1];return{...o,servers:[n],people:a,series:n.series??o.series,events:o.events.filter(d=>d.person?i.has(d.person):!0),geo:{...o.geo,points:o.geo.points.filter(d=>i.has(d.person))},totals:{people:a.length,devices:s.length,online:s.filter(d=>d.online).length,active:a.filter(d=>d.state==="active").length,today:l?[l.rx,l.tx]:[0,0],month:r(d=>d.month)}}}var ft=class{constructor(t,n){this.srvId=t;this.go=n;this.el=e("div",{class:"dl-srvov"});this.map=null;this.range="online";this.parts={};this.healthAt=0}mount(t){this.st=ht(t,this.srvId);for(let n of["health","bento","side","activity"])this.parts[n]=e("div",{});return dom.content(this.el,[this.parts.health,this.parts.bento,this.mapCard(),e("div",{class:"dl-grid2"},[this.parts.activity,this.parts.side])]),this.paint(),this.loadHealth(),this.el}update(t){this.st=ht(t,this.srvId),this.paint(),this.map?.update(this.mapData()),Date.now()-this.healthAt>6e4&&this.loadHealth()}async loadHealth(){this.healthAt=Date.now();let t=await P.health().catch(()=>null);if(!t)return;let n=t.checks.filter(s=>s.status==="warn"||s.status==="error");if(!n.length){dom.content(this.parts.health,"");return}let a=n.filter(s=>s.status==="error").length,i=`${n.length} ${a?n.length===1?"problem":"problems":n.length===1?"warning":"warnings"}`;dom.content(this.parts.health,e("div",{class:`dl-healthstrip ${a?"bad":"warn"}`},[e("span",{class:"dl-healthstrip-title"},[w("alert"),i]),...n.slice(0,3).map(s=>{let r=e("span",{class:"dl-healthstrip-item"},s.title);return le(r,()=>[e("div",{class:"dl-tip-title"},s.title),e("div",{class:"dl-muted"},s.detail)]),r}),n.length>3?e("span",{class:"dl-sub"},`+${n.length-3} more`):"",e("a",{href:L.url("admin/network/dawnline/health")},n.some(s=>s.fix)?"Fix in Health →":"Open Health →")]))}mapData(){return{geo:this.st.geo,people:this.st.people,now:this.st.now}}mapCard(){let t=this.st,n=e("div",{class:"dl-panel-head pad"},[e("div",{class:"dl-stack"},[e("h3",{},"Where people connect from"),e("span",{class:"dl-sub"},"City-level, from the client IP · locations cached on the router")]),e("span",{class:"dl-spacer"}),ut(this.range,s=>{this.range=s,this.map?.setRange(s)})]);if(!t.geo.enabled)return e("div",{class:"dl-panel flush"},[n,e("div",{class:"dl-map-off"},["Locations are off. ",e("a",{href:L.url("admin/network/dawnline/settings")},"Turn them on in Settings"),"."])]);this.map=new Fe({openPerson:s=>location.href=pe(s),openDevice:(s,r)=>location.href=pe(s,r)},this.range);let a=e("div",{class:"dl-map-legend"},[e("span",{},[e("i",{class:"dot ok"}),"Online"]),e("span",{},[e("i",{class:"dot"}),"Seen recently"]),e("span",{},[e("i",{class:"line"}),"Live tunnel"])]),i=e("div",{class:"dl-map-wrap"},[this.map.el,a]);return requestAnimationFrame(()=>this.map.mount(this.mapData())),e("div",{class:"dl-panel flush"},[n,i])}paint(){let t=this.st,n=t.servers[0],a=t.people.reduce((l,d)=>l+Math.max(0,d.device_limit-d.devices.length),0),i=t.people.flatMap(l=>l.devices.filter(d=>d.online));dom.content(this.parts.bento,e("div",{class:"dl-bento"},[this.onlineTile(i),this.speedTile(),this.disguiseTile(n),this.monthTile(a)]));let s=fa(t);dom.content(this.parts.side,e("div",{class:"dl-panel flush"},[e("div",{class:"dl-panel-head pad"},[e("h3",{},"Needs attention"),e("span",{class:"dl-spacer"}),e("a",{href:L.url("admin/network/dawnline/health")},"Health")]),s.length?s.slice(0,8).map(l=>e("div",{class:"dl-attn-item dl-row"},[e("span",{class:`dl-ev-dot ${l.tone}`}),e("span",{},l.text)])):e("div",{class:"dl-row dl-muted"},[w("check"),"All good. Nothing needs you right now."])]));let r=[...t.events].reverse().slice(0,8);dom.content(this.parts.activity,e("div",{class:"dl-panel flush"},[e("div",{class:"dl-panel-head pad"},[e("h3",{},"Activity"),e("span",{class:"dl-spacer"}),e("a",{href:L.url("admin/network/dawnline/activity")},"View all")]),r.length?r.map(l=>tt(t,l)):e("div",{class:"dl-row dl-muted"},"Nothing yet. Connections, new devices and pauses appear here.")]))}onlineTile(t){let n=this.st,a=12,i=H=>H.spark[H.spark.length-1]??0,s=H=>n.geo.points.find(y=>y.device===H.id&&y.city)?.city,r=H=>/^(10\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.)/.test(H.endpoint??""),l=H=>(r(H)?"home":s(H))??"",d=H=>[...n.events].reverse().find(y=>y.type==="connect"&&y.device===H.id)?.ts??0,h=n.people.map(H=>({p:H,devs:H.devices.filter(y=>y.online).sort((y,D)=>i(D)-i(y))})).filter(H=>H.devs.length).sort((H,y)=>y.devs.reduce((D,T)=>D+i(T),0)-H.devs.reduce((D,T)=>D+i(T),0)),m=h.length<=2,p=({p:H,devs:y})=>{let D=y.map(d).filter(Boolean),T=D.length?Math.min(...D):0,f=(H.rate??[]).slice(-15),g=f[f.length-1],_=g&&n.now-g[0]<180?g:null,c=200,u=30,C=Math.max(1,...f.map(I=>Math.max(I[1],I[2]))),v=I=>f.map((Z,ee)=>`${f.length>1?ee/(f.length-1)*c:c},${u-2-Z[I]/C*(u-6)}`),b=f.length>1?Pe(``):"",j=!_||_[1]<64&&_[2]<64,q=H.access==="both"?["home","globe"]:H.access==="lan"?["home"]:["globe"];return[e("div",{class:"dl-hc"},[e("div",{class:"dl-hc-head"},[e("span",{class:"dl-onl-av sm"},Le(H.name)),e("span",{class:"dl-stack"},[e("b",{},H.name),e("span",{class:"dl-hc-since"},T?`online for ${ce(T,n.now).replace(" ago","")}`:"online")]),e("span",{class:"dl-hc-reach"},q.map(I=>e("span",{class:`dl-ibadge ${I==="home"?"lan":"inet"}`},w(I))))]),e("div",{class:"dl-hc-speed"},[e("div",{class:"dl-hc-speed-row"},j?[e("span",{class:"dl-faint"},"Idle right now")]:[e("span",{},[e("span",{class:"dl-dn"},"↓"),` ${$e(_[2])}`]),e("span",{},[e("span",{class:"dl-up"},"↑"),` ${$e(_[1])}`]),e("span",{class:"dl-spacer"}),e("span",{class:"dl-faint"},"15 min")]),b]),e("div",{class:"dl-hc-devs"},y.map(I=>e("span",{class:"dl-hc-dev"},[w(I.kind),[I.name,l(I)].filter(Boolean).join(" · ")]))),e("div",{class:"dl-hc-foot"},[e("span",{class:"dl-faint"},`${V(y.reduce((I,Z)=>I+i(Z),0))} today · ${V(H.month[0]+H.month[1])} this month`)])])]},$=H=>{let{p:y,devs:D}=H,T=e("span",{class:"dl-onl-dev"},D.length>1?String(D.length):w(D[0].kind)),f=e("a",{class:`dl-onl-p${m?"":" sm"}`,href:pe(y.id),"aria-label":`${y.name}, online`},[e("span",{class:"dl-onl-av"},[Le(y.name),T]),m?e("span",{class:"dl-onl-name"},y.name):"",m?e("span",{class:"dl-onl-meta"},[...D.slice(0,3).map(g=>w(g.kind)),D.length>3?`+${D.length-3}`:"",l(D[0])?e("span",{},` · ${l(D[0])}`):""]):""]);return le(f,()=>p(H)),f},k=e("b",{class:`dl-onl-count${h.length?"":" none"}`},String(h.length)),z=h.reduce((H,y)=>H+y.devs.length,0);h.length&&le(k,()=>[`${h.length} ${h.length===1?"person":"people"} · ${z} device${z===1?"":"s"}`]);let Y=h.length>a?h.slice(0,a-1):h,F=n.people.flatMap(H=>H.devices.map(y=>({p:H,d:y}))).filter(H=>H.d.handshake).sort((H,y)=>y.d.handshake-H.d.handshake)[0];return e("div",{class:"dl-bento-tile online"},[e("div",{class:"dl-bento-head"},[e("span",{class:"dl-metric-label"},"Online"),k]),h.length?e("div",{class:`dl-onl-row${m?"":" grid"}`},[...Y.map($),h.length>a?e("a",{class:"dl-onl-p sm more",href:`${L.url("admin/network/dawnline/server")}?server=${encodeURIComponent(this.srvId)}§ion=people&filter=online`,title:"Everyone online",click:H=>{this.go&&(H.preventDefault(),this.go("people","online"))}},[e("span",{class:"dl-onl-av"},`+${h.length-Y.length}`)]):""]):e("div",{class:"dl-onl-empty"},[e("span",{},"Nobody is connected"),F?e("span",{class:"dl-sub"},`Last: ${F.p.name}, ${ce(F.d.handshake,n.now)}`):e("span",{class:"dl-sub"},"No device has connected yet")])])}speedTile(){return At(this.st.servers[0]?.rate??[],this.st.now,this.st.totals.today)}disguiseTile(t){let n=We(t.preset),a=t.obf??{},i=(l,d)=>e("span",{class:`dl-segs ${d}`},[0,1,2,3].map(h=>e("i",{class:h+a[l]).map(l=>`${l.toUpperCase()} ${a[l]}`);return r.length&&s.push(r.slice(0,2).join(" · ")+(r.length>2?` +${r.length-2}`:"")),["h1","h2","h3","h4"].some(l=>a[l]&&a[l]!==String(["h1","h2","h3","h4"].indexOf(l)+1))&&s.push("H1–H4 random"),a.i1&&s.push(a.i1.includes("0x8580")?"DNS-like first packet":"Signature packets"),a.header_protection_key&&s.push("Encrypted headers"),s.length||s.push(n?.id==="off"?"Plain WireGuard":"No values yet"),e("div",{class:"dl-bento-tile dl-disg"},[e("div",{class:"dl-bento-head"},[e("span",{class:"dl-metric-label"},"Disguise"),e("a",{href:`${L.url("admin/network/dawnline/server")}?server=${encodeURIComponent(t.id)}§ion=disguise`},"Change")]),e("div",{class:"dl-disg-id"},[e("span",{class:"dl-disg-ic"},w(n?.ic??"shield")),e("span",{class:"dl-stack"},[e("b",{},n?n.title:"Custom"),e("span",{class:"dl-sub"},n?n.short:"Set by hand")])]),n?e("div",{class:"dl-disg-meters"},[e("span",{},"Stealth"),i(n.stealth,"acc"),e("span",{},"Speed"),i(n.speed,"ok")]):"",e("div",{class:"dl-disg-chips"},s.map(l=>e("span",{},l)))])}monthTile(t){let n=this.st.totals,a=this.st.people.filter(i=>i.state!=="active").length;return Pt(this.st.series,`${n.people} ${n.people===1?"person":"people"}${a?` · ${a} paused`:""} · ${t} device slot${t===1?"":"s"} free`)}};function At(o,t,n){let a=o.slice(-15),i=a[a.length-1],s=i&&t-i[0]<180,r=s?i[2]:0,l=s?i[1]:0,[d,h]=n,m=200,p=40,$=Math.max(1,...a.map(y=>Math.max(y[1],y[2]))),k=y=>a.map((D,T)=>`${a.length>1?T/(a.length-1)*m:m},${p-2-D[y]/$*(p-6)}`),z=k(2),Y=k(1),F=a.length>1?Pe(``):e("div",{class:"dl-speed-wait"},[e("i"),e("span",{},"Collecting… 1 point a minute")]),H=(y,D,T,f)=>e("div",{class:"dl-speed-col"},[e("span",{class:"dl-sub"},[e("span",{class:T},D),` ${y}`]),e("span",{class:"dl-speed-val"},$e(f))]);return a.length>1&&le(F,()=>{let y=a[a.length-1];return[e("div",{class:"dl-tip-title"},new Date(y[0]*1e3).toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"})),e("div",{},`↓ ${$e(y[2])} · ↑ ${$e(y[1])}`)]}),e("div",{class:"dl-bento-tile"},[e("div",{class:"dl-bento-head"},[e("span",{class:"dl-metric-label"},"Speed now"),e("span",{class:"dl-sub"},"last 15 min")]),e("div",{class:"dl-speed-cols"},[H("Download","↓","dl-dn",r),H("Upload","↑","dl-up",l)]),F,e("div",{class:"dl-speed-today"},[e("span",{},["Today ",e("b",{},V(d+h))]),e("span",{},[e("span",{class:"dl-dn"},"↓"),` ${V(h)} `,e("span",{class:"dl-up"},"↑"),` ${V(d)}`])])])}function Pt(o,t){let n=o.slice(-30),a=n.map(h=>h.rx+h.tx),i=Math.max(1,...a),s=a.reduce((h,m)=>h+m,0),r=a.reduce((h,m,p)=>m>a[h]?p:h,0),l=h=>new Date(`${h}T12:00:00`).toLocaleDateString("en-GB",{day:"numeric",month:"short"}),d=e("div",{class:"dl-bento-bars"},n.map((h,m)=>{let p=a[m],$=e("i",{class:m===n.length-1?"hi":"",style:`height:${Math.max(4,p/i*100)}%`});return le($,()=>[e("div",{class:"dl-tip-title"},m===n.length-1?`Today · ${l(h.day)}`:l(h.day)),e("div",{},V(p)),e("div",{class:"dl-muted dl-mono"},`↓ ${V(h.tx)} ↑ ${V(h.rx)}`)]),$}));return e("div",{class:"dl-bento-tile month"},[e("div",{class:"dl-bento-head"},[e("span",{},[e("span",{class:"dl-metric-label"},"Last 30 days"),e("b",{class:"dl-bento-total"},V(s))]),a[r]>0?e("span",{class:"dl-sub"},`peak ${V(a[r])} · ${l(n[r].day)}`):""]),n.length?d:e("p",{class:"dl-muted"},"No traffic yet."),e("div",{class:"dl-bento-head"},[e("span",{class:"dl-sub"},n.length?l(n[0].day):""),e("span",{class:"dl-sub"},t),e("span",{class:"dl-sub"},"today")])])}var ma={active:"",paused:"pause",paused_all:"pause",expired:"calendar",quota:"chart",hours:"clock",no_server:"alert"};function zt(o){if(o.state==="active")return"";let t=e("span",{class:`dl-ibadge ${va(o)}`,"aria-label":Tt[o.state]},w(ma[o.state]||"alert"));return le(t,()=>[e("div",{class:"dl-tip-title"},Tt[o.state])]),t}function ga(o){let t=o.access==="both"?["lan","inet"]:o.access==="lan"?["lan"]:["inet"],n=e("span",{class:"dl-access","aria-label":je[o.access]},t.map(a=>e("span",{class:`dl-ibadge ${a}`},w(a==="lan"?"home":"globe"))));return le(n,()=>[e("div",{class:"dl-tip-title"},je[o.access]),o.access==="lan"&&o.services?.length?e("div",{class:"dl-muted"},`${o.services.length} home service${o.services.length===1?"":"s"} only`):""]),n}function va(o){return o.state==="active"?"ok":o.state==="quota"||o.state==="expired"?"bad":"warn"}function ba(o,t){let n=o,i=e("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(s=>e("button",{type:"button",class:`dl-choice${s.v===n?" selected":""}`,"data-v":s.v,click:()=>{n=s.v,i.querySelectorAll(".dl-choice").forEach(r=>r.classList.toggle("selected",r.dataset.v===s.v)),t?.(s.v)}},[e("span",{class:"dl-choice-title"},[w(s.ic),je[s.v]]),e("span",{class:"dl-choice-text"},s.text)])));return{el:i,get:()=>n}}function xa(o){return`${o.getFullYear()}-${String(o.getMonth()+1).padStart(2,"0")}-${String(o.getDate()).padStart(2,"0")}`}function pn(o){let t=ze(o.expires);return o.state==="quota"||o.state==="expired"||t!=null&&t<=Math.max(o.expire_warn,3)||!!o.quota_limit&&o.quota_used>=o.quota_limit*.9}function wa(o){let t=o?new Date(`${o}T12:00:00`):new Date,n=t.getTime()t===new URLSearchParams(location.search).get("filter"))??"all";this.sort="seen";this.noFooter=!0;this.serverId=null;this.polling=!1;this.el=null;this.statusSeq=0;this.statusShown=0}async load(){return P.status(30)}scope(t){return this.serverId?ht(t,this.serverId):t}embed(t,n){return this.serverId=n,this.render(t)}person(t){return this.st.people.find(n=>n.id===t)}async latestStatus(){let t=++this.statusSeq,n=await P.status(30).catch(()=>null);return!n||te("em",{},n.servers.length?"No people yet. Add someone and send them their personal link.":"Set up the server first, then add people."),a.serverId&&(r.filter=l=>a.st.people.some(d=>d.id===l)),r.handleAdd=()=>a.openCreate(),r.handleRemove=l=>a.remove(l),r.renderRowActions=()=>e("div",{class:"dl-none"}),i=r.option(form.DummyValue,"_card"),i.modalonly=!1,i.textvalue=l=>a.renderCard(e("div",{class:"dl-card",id:`dl-card-${l}`}),l),s.render().then(l=>{l.classList.add("dl-map","dl-root"),we(n);let d=e("input",{type:"search",class:"dl-search-input",placeholder:"Search people, devices, IPs",input:p=>{a.query=p.target.value.trim().toLowerCase(),a.decorate()}}),h=e("select",{class:"dl-select","aria-label":"Sort",change:p=>{a.sort=p.target.value,a.decorate()}},[e("option",{value:"seen"},"Last seen"),e("option",{value:"name"},"Name"),e("option",{value:"usage"},"Usage")]),m=e("div",{class:"dl-root"},[a.serverId?"":e("div",{class:"dl-pagehead"},[e("div",{class:"dl-stack"},[e("h2",{class:"dl-h1"},"People"),e("span",{class:"dl-muted",id:"dl-people-count"},this.countText())]),n.servers.length?N([w("plus")," Add person"],()=>a.openCreate(),"add"):""]),n.servers.length?"":e("div",{class:"alert-message warning"},["No server yet. ",e("a",{href:L.url("admin/network/dawnline/server")},"Run the setup wizard")," before adding people."]),e("div",{class:"dl-toolbar"},[e("div",{class:"dl-seg",id:"dl-people-tabs",role:"tablist"}),e("div",{class:"dl-toolbar-end"},[e("label",{class:"dl-search"},[w("search"),d,e("kbd",{},"/")]),h,a.serverId?N([w("plus")," Add person"],()=>a.openCreate(),"add"):""])]),l]);return this.el=m,requestAnimationFrame(()=>this.decorate()),this.polling||(this.polling=!0,poll.add(()=>a.el?.isConnected?a.poll():Promise.resolve(),10)),!un&&new URLSearchParams(location.search).get("add")&&(un=!0,setTimeout(()=>a.openCreate(),100)),m})}countText(){let t=this.st.totals;return`${t.people} ${t.people===1?"person":"people"} · ${t.devices} device${t.devices===1?"":"s"} · ${t.online} online`}decorate(){let t=document.getElementById("dl-people-count");t&&(t.textContent=this.countText());let n=this.st.people,a={all:n.length,online:n.filter(p=>p.online>0).length,attention:n.filter(pn).length,paused:n.filter(p=>p.state!=="active"&&p.state!=="quota"&&p.state!=="expired").length},i=document.getElementById("dl-people-tabs");if(i){let p={all:"All",online:"Online",attention:"Needs attention",paused:"Paused"};dom.content(i,Object.keys(p).map($=>e("button",{type:"button",role:"tab",class:$===this.filter?"on":"",click:()=>{this.filter=$,this.decorate()}},[p[$],e("b",{class:$==="attention"&&a[$]?"warn":""},String(a[$]))])))}let s=p=>this.filter==="online"&&!p.online||this.filter==="attention"&&!pn(p)||this.filter==="paused"&&!(p.state!=="active"&&p.state!=="quota"&&p.state!=="expired")?!1:this.query?[p.name,p.id,...p.devices.flatMap(k=>[k.name,k.address,k.endpoint,k.hostname])].join(" ").toLowerCase().includes(this.query):!0,r=[...n].sort((p,$)=>this.sort==="name"?p.name.localeCompare($.name):this.sort==="usage"?$.month[0]+$.month[1]-(p.month[0]+p.month[1]):$.online-p.online||$.last_seen-p.last_seen),l=null,d=0;for(let p of r){let k=document.getElementById(`dl-card-${p.id}`)?.closest(".cbi-section-table-row");if(!k)continue;l??(l=k.parentElement),l?.appendChild(k),k.classList.toggle("dl-off",p.state!=="active"),k.classList.toggle("dl-attn-row",p.state==="quota"||p.state==="expired");let z=s(p);k.classList.toggle("dl-filtered",!z),z&&d++}let h=l?.closest(".cbi-section-table")??l,m=document.getElementById("dl-people-none");h&&n.length&&!d?(m??(m=e("div",{id:"dl-people-none",class:"dl-empty"})),dom.content(m,e("p",{},this.query?`No one matches “${this.query}”.`:"No one here right now.")),m.parentElement!==h.parentElement&&h.after(m)):m?.remove()}async poll(){let t=await this.latestStatus();if(!t)return;let n=this.scope(t);this.st=n,this.paintCards(),this.decorate()}async quick(t,n,a){await O(()=>P.personUpdate(t.id,n),a)&&await this.poll()}renderCard(t,n){let a=this.person(n);if(!a)return dom.content(t,e("em",{},"Not saved yet — use “Save & Apply”.")),t;let i=ze(a.expires),s=Math.max(0,a.device_limit-a.devices.length),r=[];if(a.expires){let p=i!=null&&i>=0&&i<=Math.max(a.expire_warn,3),$=i!=null&&i<0;r.push(e("span",{class:`dl-pill-ic${$?" bad":p?" warn":""}`,title:`Access ends ${_e(a.expires)}`},[w("calendar"),$?`ended ${_e(a.expires)}`:p?`ends in ${i} day${i===1?"":"s"}`:`until ${_e(a.expires)}`]))}a.hours&&r.push(e("span",{class:"dl-pill-ic",title:"Allowed hours"},[w("clock"),a.hours.replace("-","–")]));let l=a.devices.map(p=>e("button",{type:"button",class:`dl-chip${p.disabled?" disabled":""}${p.online?" live":""}`,title:`${Me[p.kind]} · ${p.address}${p.online?` · online from ${p.endpoint}`:p.handshake?` · seen ${ce(p.handshake,this.st.now)}`:""}`,click:$=>{$.preventDefault(),Ce(a,p,()=>this.refresh(),this.st.geo)}},[w(p.kind),e("span",{class:"dl-chip-name"},p.name),!p.handshake&&!p.disabled?e("span",{class:"dl-chip-tag"},"not set up"):""]));s>0&&l.push(e("button",{type:"button",class:"dl-chip add",title:`${a.devices.length} of ${a.device_limit} devices`,click:p=>{p.preventDefault(),Re(a,()=>this.refresh())}},[w("plus"),e("span",{class:"dl-chip-name"},"Add device")]));let d=[];a.state==="quota"&&a.quota_period==="month"&&d.push(e("button",{type:"button",class:"dl-fix",click:()=>this.quick(a,{bonus_gb:String((a.bonus_gb||0)+10)},"+10 GB this month")},"+10 GB this month")),a.expires&&i!=null&&i<=Math.max(a.expire_warn,3)&&d.push(e("button",{type:"button",class:"dl-fix",click:()=>this.quick(a,{expires:wa(a.expires)},"Extended by 1 month")},"Extend 1 month"));let h=ye("more","More",p=>ke(p.currentTarget,[{label:"Open",icon:w("open"),run:()=>{location.href=pe(a.id)}},a.link?{label:"Invite card",icon:w("qr"),run:()=>Qe(a,this.st.servers.find($=>$.id===a.server)?.name??"Home")}:null,s>0?{label:"Add device",icon:w("plus"),run:()=>Re(a,()=>this.refresh())}:null,null,{label:a.paused?"Resume":"Pause",icon:w(a.paused?"play":"pause"),warn:!a.paused,run:()=>this.togglePause(a)},{label:"Delete",icon:w("trash"),danger:!0,run:()=>this.remove(a.id)}].filter(($,k,z)=>$||k>0&&z[k-1])),"neutral","dl-icon-only"),m=e("div",{class:"dl-pcard-actions"},[a.link?ye("link","Copy link",()=>re(a.link,"Personal link copied"),"neutral","dl-icon-only"):"",h]);return dom.content(t,e("div",{class:"dl-pcard"},[e("div",{class:"dl-pcard-main"},[e("div",{class:"dl-card-head"},[e("span",{class:`dl-avatar${a.online?" online":""}`},Le(a.name)),e("a",{class:"dl-card-name",href:pe(a.id)},a.name),zt(a),ga(a),...r]),e("div",{class:"dl-meta"},[e("span",{},`${a.devices.length} of ${a.device_limit} devices`),e("span",{class:"dl-sep"},"·"),e("span",{},a.online?"online now":a.last_seen?`seen ${ce(a.last_seen,this.st.now)}`:"never connected")]),e("div",{class:"dl-chips"},l),d.length?e("div",{class:"dl-fixes"},d):""]),this.usageSide(a,m)])),t}usageSide(t,n){let a=t.quota_used||t.month[0]+t.month[1],i=t.quota_limit?Math.min(100,t.quota_used/t.quota_limit*100):0,s=t.devices.reduce((m,p)=>m+(p.spark[p.spark.length-1]??0),0),r=t.rate?.[t.rate.length-1],l=t.online&&r&&this.st.now-r[0]<180,d=e("div",{class:`dl-usebar${i>=100?" bad":i>=90?" warn":""}`});if(t.quota_limit){let m=e("i",{class:"fill"});m.style.width=`${i}%`,d.appendChild(m),le(d,()=>[e("div",{class:"dl-tip-title"},`${i.toFixed(1)}% used`),e("div",{class:"dl-muted"},`${V(t.quota_used)} of ${V(t.quota_limit)} · ${V(Math.max(0,t.quota_limit-t.quota_used))} left`),e("div",{class:"dl-faint"},t.quota_period==="total"?"In total":`This month${t.bonus_gb?` · includes +${t.bonus_gb} GB extra`:""}`)])}else{let m=t.devices.map(p=>({d:p,v:p.month[0]+p.month[1]})).filter(p=>p.v>0).sort((p,$)=>$.v-p.v);m.forEach((p,$)=>{let k=e("i",{class:`c${Math.min($,4)}`});k.style.flexGrow=String(p.v),d.appendChild(k)}),m.length&&le(d,()=>[e("div",{class:"dl-tip-title"},"This month by device"),...m.map((p,$)=>e("div",{class:"dl-tip-row"},[e("span",{class:`dl-swatch c${Math.min($,4)}`}),e("span",{},p.d.name),e("b",{},V(p.v))]))])}let h=t.quota_limit?`${V(Math.max(0,t.quota_limit-t.quota_used))} left`:"no limit";return e("div",{class:"dl-pside"},[e("div",{class:"dl-pside-top"},[l?e("span",{class:"dl-pside-state live"},[e("i",{class:"dl-dot online"}),"Live"]):e("span",{class:"dl-pside-state"},t.online?"Online":t.last_seen?"Offline":"Not connected"),n]),e("div",{class:"dl-use-num"},[e("b",{class:a?"":"dl-faint"},V(a)),e("span",{class:"dl-faint"},t.quota_limit?`of ${V(t.quota_limit)}`:t.quota_period==="total"&&t.quota_gb?"in total":"this month")]),d,l?e("div",{class:"dl-use-live",title:"Right now"},[`↓ ${$e(r[2])}`,e("span",{class:"dl-faint"},`↑ ${$e(r[1])}`)]):e("div",{class:"dl-faint dl-pside-foot"},s?`today ${V(s)} · ${h}`:h)])}async togglePause(t){await O(()=>P.personPause(t.id,!t.paused),t.paused?`${t.name} resumed`:`${t.name} paused`)&&await this.refresh()}async remove(t){let n=this.person(t);await ae(`Remove ${n?.name??t}?`,`All ${n?.devices.length??0} devices are disconnected immediately and the personal link stops working. Usage history is kept in backups.`,"Remove",!0)&&await O(()=>P.personDelete(t),"Person removed")&&await this.refresh()}openCreate(){let t=this.st;if(!t.servers.length){X("Set up the server first.","warning");return}let n=e("input",{type:"text",class:"cbi-input-text",placeholder:"e.g. Myata",maxlength:48}),a=ba("internet"),i=e("input",{type:"number",class:"cbi-input-text",min:1,max:32,value:t.settings.default_device_limit}),s=e("input",{type:"date",class:"cbi-input-text"}),r=e("input",{type:"number",class:"cbi-input-text",min:0,step:"any",placeholder:"Unlimited"}),l=(p,$)=>e("button",{type:"button",class:"cbi-button cbi-button-neutral",click:()=>{if(!$)s.value="";else{let k=new Date;k.setMonth(k.getMonth()+$),s.value=xa(k)}}},p),d=t.servers[0],h=!this.serverId&&t.servers.length>1?e("select",{class:"cbi-input-select"},t.servers.map(p=>e("option",{value:p.id},p.name))):null,m=(p,$,k)=>e("div",{class:"cbi-value"},[e("label",{class:"cbi-value-title"},p),e("div",{class:"cbi-value-field"},[$,k?e("div",{class:"cbi-value-description"},k):""])]);ne("Add person",[m("Name",n),h?m("Server",h):"",e("div",{class:"cbi-value dl-block"},[e("label",{class:"cbi-value-title"},"Access"),e("div",{class:"cbi-value-field"},a.el)]),m("Devices",i,"How many devices they can add themselves."),m("End date",e("div",{class:"dl-actions"},[s,l("1 month",1),l("3 months",3),l("1 year",12),l("None",0)]),"Optional."),m("Monthly data (GB)",r,"Optional. They are paused when it runs out and resumed next month.")],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",N("Create and copy link",async()=>{let p=await O(()=>P.personCreate(n.value.trim(),"",h?.value??d.id,a.get(),Number(i.value)||t.settings.default_device_limit,s.value,Number(r.value)||0,"month"));p&&(p.link&&await re(p.link,"Personal link copied"),this.showCreated(p.id,n.value.trim(),p.link,t.servers.find($=>$.id===(h?.value??d.id))?.name??d.name),await this.refresh())},"positive")]),setTimeout(()=>n.focus(),50)}showCreated(t,n,a,i){if(a){Qe({id:t,name:n,link:a},i,{title:`${n} is ready`,lead:`Send ${n} the card or the link. They open it, add their devices and connect — no account needed.`});return}ne(`${n} is ready`,[e("p",{},"Created. Turn on the personal portal in Settings to get a link, or add devices for them here.")],[e("button",{class:"cbi-button cbi-button-positive",click:J},"Done")])}};var ya={https:"HTTPS for the portal",acme:"ACME certificates",home:"the home-like link"},ka=300*1e3;async function nt(o,t,n){if(!t.length)return!0;if(!await ae(`Install ${ya[o]}?`,`${t.join(", ")} from the OpenWrt feeds. Dawnline sets the rest up when they arrive.`,"Install"))return!1;let i=(await P.updatesStatus().catch(()=>null))?.job?.started??0;if(!await O(()=>P.updatesRun(`pkgs:${t.join(",")}`)))return!1;X(`Installing ${t.join(", ")}…`,"info",4e3);let s=Date.now()+ka;for(;Date.now()setTimeout(d,2e3));let l=(await P.updatesStatus().catch(()=>null))?.job;if(!(!l||l.started===i||l.state==="running"))return l.state==="done"?(X(`${t.join(", ")} installed`,"success"),setTimeout(()=>n?.(),4e3),!0):(X(l.error??"Installation failed","error"),!1)}return X("Still installing: see Updates for the log.","warning"),!1}async function hn(o,t){let n=await O(()=>P.updatesStatus());return n?nt(o,n.needs?.[o]??[],t):!1}var $a=[["wan","WAN"],["ethernet","Ethernet"],["wifi","Wi-Fi"],["vpn","VPN & tunnels"],["other","Other"]],_a={wan:"globe",ethernet:"ethernet",bridge:"bridge",wifi:"wifi",vpn:"tunnel",other:"link"};function Nt(o,t,n){let a=e("button",{type:"button",role:"switch",class:`dl-switch${o?" on":""}`,"aria-checked":o?"true":"false","aria-label":t,click:()=>{let i=!a.classList.contains("on");a.classList.toggle("on",i),a.setAttribute("aria-checked",i?"true":"false"),n(i)}},e("i"));return a}function fn(o,t="Interfaces"){let n=e("section",{class:"dl-setsec dl-ifcard"},e("div",{class:"dl-setsec-body"},e("p",{class:"dl-muted"},"Loading interfaces…"))),a,i=!0,s="",r=!0,l=!0,d=new Set,h="",m=()=>JSON.stringify([l,i,i?"":s,r,[...d].sort()]),p=()=>a.detected.lan||a.saved.lan||"",$=()=>(i?a.detected.wan||a.saved.wan:s)||"",k=()=>new Map(a.devices.map(f=>[f.name,f])),z=()=>{let f=k();return[...r&&p()?[p()]:[],...[...d].filter(_=>_!==p())].filter(_=>_!==$()).map(_=>f.get(_)??{name:_,nets:[],missing:!0})},Y=(f,g)=>{a=f,g&&(i=f.config.auto_wan,s=f.config.wan_device||f.detected.wan||f.saved.wan||"",r=f.config.auto_lan,l=f.config.lan_like,d=new Set(f.config.lan_devices),h=m()),T()},F=async f=>{let g=await P.interfaces(o).catch(_=>(X(_.message,"error"),null));g&&Y(g,f)};function H(f){let g=r&&f.name===p(),_=f.name===$(),c=!g&&d.has(f.name),C=!(!!f.own||!!f.master||_||g)&&(f.nets.length>0||c||!!f.missing),v=(c||g)&&!f.zone&&!f.missing,b=f.missing?"Not present right now":f.own?"This server":f.master?`Port of ${f.master}`:_?`Internet${f.zone?` · zone ${f.zone}`:""}`:f.nets.length?f.nets.join(", "):"No IPv4 network",j=e("button",{type:"button",class:`dl-if${c?" sel":""}${g?" auto":""}${!C&&!c&&!g?" off":""}${v?" warn":""}`,"aria-pressed":c||g?"true":"false","aria-disabled":C?null:"true",click:()=>{C&&(d.has(f.name)?d.delete(f.name):d.add(f.name),T())}},[e("span",{class:"dl-if-ic"},w(_a[f.kind]??"link")),e("span",{class:"dl-if-main"},[e("span",{class:"dl-if-name"},f.name),e("span",{class:"dl-if-sub"},b)]),g?e("span",{class:"dl-if-badge ok"},[e("i",{class:"dot ok"}),"Auto"]):c?e("span",{class:"dl-if-check"},w("check")):""]);return le(j,()=>[e("div",{class:"dl-tip-title"},f.name),e("div",{class:"dl-muted"},[f.logical?`Interface ${f.logical}`:"No netifd interface",f.zone?` · zone ${f.zone}`:" · no firewall zone"]),f.members.length?e("div",{class:"dl-muted"},`Ports: ${f.members.join(", ")}`):"",f.nets.length?e("div",{class:"dl-mono"},f.nets.join(", ")):"",v?e("div",{class:"dl-warn"},"Not in a firewall zone: the firewall rejects this traffic."):"",f.master?e("div",{class:"dl-muted"},`Choose ${f.master} to include it.`):""]),j}function y(){let f=a.like_home;return!l||!a.config.lan_like?"":!a.needs?.length&&f.active&&f.bridged?"ok":"warn"}function D(){let f=a.like_home;return l?a.needs?.length?[e("span",{class:"dl-warn"},`Needs ${a.needs.join(" and ")}.`)," Until they are installed, internet traffic goes straight to the WAN."]:a.config.lan_like?f.active&&f.bridged?["Internet traffic enters ",e("span",{class:"dl-mono"},f.dev??"")," as ",e("span",{class:"dl-mono"},f.address??""),", so whatever handles home traffic (proxies, filters, DNS) handles it too."]:[e("span",{class:"dl-warn"},`Not working: ${f.error??"the link is down"}`)," Internet traffic goes straight to the WAN for now."]:["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."]}function T(){let f=e("select",{class:"cbi-input-select","aria-label":"Internet interface",change:b=>{s=b.target.value,T()}},a.devices.filter(b=>!b.own&&!b.master&&b.zone&&!b.missing).map(b=>e("option",{value:b.name,selected:b.name===s?"selected":null},`${b.name} · zone ${b.zone}`))),g=(b,j)=>e("span",{},[" Live: ",e("span",{class:"dl-mono"},b||"—")," · Saved: ",e("span",{class:"dl-mono"},j||"—")]),_=$a.map(([b,j])=>{let q=a.devices.filter(I=>I.category===b);return q.length?e("div",{class:"dl-ifgroup"},[e("h4",{},j),e("div",{class:"dl-ifgrid"},q.map(H))]):""}),u=z().flatMap(b=>b.nets.map(j=>[j,b.name])),C=m()!==h,v=N("Save",async()=>{let b=await O(()=>P.serverInterfaces(o,i,i?"":s,r,[...d],l),"Interfaces saved");b&&(Y(b,!0),b.nets_changed&&b.lan_only&&X(`${b.lan_only} ${b.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:!C});dom.content(n,[e("div",{class:"dl-setsec-body"},[e("div",{class:"dl-panel-head"},[e("h3",{},t),e("span",{class:"dl-spacer"}),N([w("reset")," Rescan"],()=>F(!1),"neutral",{title:"Read the interfaces again"})]),e("div",{class:"dl-setrow"},[e("div",{class:"dl-lh-main"},[e("span",{class:`dl-need-ic ${y()}`},w("home")),e("div",{class:"dl-stack"},[e("span",{class:"dl-setrow-label"},"Internet like a home device"),e("span",{class:"dl-sub"},D())])]),e("div",{class:"dl-setrow-ctl dl-if-wanctl"},[l&&a.needs?.length?N("Install",()=>nt("home",a.needs,()=>F(!1)),"positive"):"",Nt(l,"Internet like a home device",b=>{l=b,T()})])]),e("div",{class:"dl-setrow"},[e("div",{class:"dl-lh-main"},[e("span",{class:"dl-need-ic"},w("globe")),e("div",{class:"dl-stack"},[e("span",{class:"dl-setrow-label"},"Auto-detect WAN"),e("span",{class:"dl-sub"},["The interface with the default route: the server port opens there and Internet access leaves through it.",g(a.detected.wan,a.saved.wan)])])]),e("div",{class:"dl-setrow-ctl dl-if-wanctl"},[i?"":f,Nt(i,"Auto-detect WAN",b=>{i=b,T()})])]),e("div",{class:"dl-setrow"},[e("div",{class:"dl-lh-main"},[e("span",{class:"dl-need-ic"},w("network")),e("div",{class:"dl-stack"},[e("span",{class:"dl-setrow-label"},"Auto-detect LAN"),e("span",{class:"dl-sub"},["Adds the detected LAN to the home network.",g(a.detected.lan,a.saved.lan)])])]),e("div",{class:"dl-setrow-ctl"},Nt(r,"Auto-detect LAN",b=>{r=b,T()}))]),e("div",{class:"dl-iflead"},[e("b",{},"Home network"),e("span",{class:"dl-sub"},"What people with Home access can reach. Click to add an interface; bridge ports and Wi-Fi in a bridge come with the bridge.")]),..._]),e("div",{class:"dl-setsec-foot"},[e("span",{class:"dl-sub dl-if-summary"},u.length?["Home access reaches ",...u.flatMap(([b,j],q)=>[q?", ":"",e("span",{class:"dl-mono"},b),` (${j})`]),l?" · Internet like a home device":$()?` · Internet via ${$()}`:""]:["No home network: Home access reaches nothing but this router.",$()?` Internet via ${$()}.`:""]),v])])}return F(!0),n}function Ie(o,t,n){let a=e("button",{type:"button",role:"switch",class:`dl-switch${o?" on":""}`,"aria-checked":o?"true":"false","aria-label":t,click:()=>{let i=!a.classList.contains("on");a.classList.toggle("on",i),a.setAttribute("aria-checked",i?"true":"false"),n?.(i)}},e("i"));return a}var Ke=o=>o.classList.contains("on");function oe(o,t={}){return e("input",{type:"text",class:"cbi-input-text",value:o,...t})}function Q(o,t,n){return e("div",{class:"dl-setrow"},[e("div",{class:"dl-stack"},[e("span",{class:"dl-setrow-label"},o),n?e("span",{class:"dl-sub"},n):""]),e("div",{class:"dl-setrow-ctl"},t)])}function Ve(o,t,n,a=""){return e("section",{class:`dl-setsec ${a}`},[e("div",{class:"dl-setsec-body"},[o?e("h3",{},o):"",...t]),n.length?e("div",{class:"dl-setsec-foot"},n):""])}function ue(o,t,n,a){return e("div",{class:"dl-group"},[e("div",{class:"dl-group-head"},[e("span",{class:"dl-group-ic"},w(o)),e("span",{class:"dl-stack"},[e("b",{},t),n?e("span",{class:"dl-sub"},n):""])]),e("div",{class:"dl-group-body"},a.filter(i=>i!==""))])}var mn=[["overview","Overview"],["people","People"],["connection","Connection"],["access","Access"],["disguise","Disguise"],["tunnel","Tunnel"]],Ma={general:"connection",network:"connection",interfaces:"access",advanced:"tunnel"},gn=[["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 La(o){let t=h=>o[h]!=null&&o[h]!=="",n=gn.filter(([h])=>t(h));if(!n.length)return null;let a=(h,m)=>e("span",{class:"dl-pv"},[e("i",{},m),e("b",{},h==="header_protection_key"?`${o[h].slice(0,6)}••••`:o[h])]),i=(h,m,p,$)=>{let k=gn.filter(([z])=>$.includes(z)&&t(z));return k.length?e("div",{class:"dl-pgroup"},[e("div",{class:"dl-pgroup-head"},[w(m),e("b",{},h)]),e("p",{},p),e("div",{class:"dl-pvals"},k.map(([z,Y])=>a(z,Y)))]):""},s=Number(o.jc||0),r=(o.i1??"").includes("0x8580")?"A first packet shaped like a DNS answer.":"Extra packets sent before the handshake.",l=n.map(([h,m])=>`${m} = ${o[h]}`).join(` -`),d=e("div",{class:"dl-pgrid"},[i("Junk packets","zap",s?`${s} random packet${s===1?"":"s"} of ${o.jmin}–${o.jmax} bytes before each handshake.`:"No junk packets.",["jc","jmin","jmax"]),i("Padding","archive","Random bytes in front of handshake, cookie and data packets, so their sizes do not match WireGuard.",["s1","s2","s3","s4"]),i("Packet types","key","The values that replace WireGuard’s recognisable message types.",["h1","h2","h3","h4"]),i("Signatures","globe",r,["i1","i2","i3","i4","i5"]),i("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"]),i("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 e("details",{class:"dl-params"},[e("summary",{},[w("chevron"),e("span",{},"Current parameters"),e("span",{class:"dl-pcount"},String(n.length)),e("span",{class:"dl-spacer"}),e("button",{type:"button",class:"dl-linkbtn",click:h=>{h.preventDefault(),re(l,"Parameters copied")}},"Copy as config")]),d])}var Rt=(o,t)=>{let n=new URLSearchParams;o&&n.set("server",o),t&&t!=="overview"&&n.set("section",t);let a=n.toString();return`${L.url("admin/network/dawnline/server")}${a?`?${a}`:""}`},at=class{constructor(){this.noFooter=!0;this.root=e("div",{class:"dl-root"});this.section="overview";this.srvId="";this.ov={};this.pp={};this.tabsEl=e("div",{});this.headEl=e("div",{});this.secEl=e("div",{});this.bodyEl=e("div",{class:"dl-srvbody"})}async load(){let t=await P.status(31),n=t.servers.length?null:await P.setupDefaults();return[t,n]}render([t,n]){if(this.st=t,!t.servers.length&&n)return this.wizard(n);let a=new URLSearchParams(location.search),i=a.get("section")??"",s=Ma[i]??i;return mn.some(([r])=>r===s)&&(this.section=s),this.srvId=(t.servers.find(r=>r.id===a.get("server"))??t.servers[0]).id,we(t),dom.content(this.root,[this.tabsEl,this.headEl,this.secEl,this.bodyEl]),this.paint(),poll.add(async()=>{if(this.section!=="overview")return;let r=await P.status(31).catch(()=>null);if(!r||!r.servers.length)return;this.st=r;let l=this.current();dom.content(this.headEl,this.head(l)),this.paintTabs(),this.ov[l.id]?.update(r)},10),this.root}current(){return this.st.servers.find(t=>t.id===this.srvId)??this.st.servers[0]}async refresh(){let t=await P.status(31).catch(()=>null);t&&(this.st=t,t.servers.length?this.paint():location.href=Rt())}paint(){this.paintTabs(),dom.content(this.headEl,this.head(this.current())),this.paintSections(),this.showSection(this.section)}paintTabs(){let t=this.current();dom.content(this.tabsEl,e("div",{class:"dl-srvtabs",role:"tablist","aria-label":"Servers"},[...this.st.servers.map(n=>e("button",{type:"button",role:"tab",class:`dl-srvtab${n.id===t.id?" on":""}`,"aria-selected":n.id===t.id?"true":"false",click:()=>{n.id!==this.srvId&&(this.srvId=n.id,this.paint())}},[e("i",{class:`dot ${n.up?"ok":"bad"}`}),e("b",{},n.name),e("span",{class:"dl-mono dl-faint"},`:${n.port}`)])),e("button",{type:"button",class:"dl-srvtab add",click:()=>this.addServer()},[w("plus"),"Add server"])]))}paintSections(){dom.content(this.secEl,e("div",{class:"dl-seg dl-srvsections",role:"tablist","aria-label":"Server"},mn.map(([t,n])=>e("button",{type:"button",role:"tab","data-section":t,class:t===this.section?"on":"","aria-selected":t===this.section?"true":"false",click:()=>this.showSection(t)},n))))}go(t,n){let a=this.pp[this.current().id];if(n&&a)a.filter=n,a.el&&a.decorate();else if(n){let i=this.pp[this.current().id]=new He;i.filter=n}this.showSection(t),window.scrollTo({top:0,behavior:"smooth"})}detachKept(){let t=[...Object.values(this.ov).map(n=>n.el),...Object.values(this.pp).map(n=>n.el)];for(let n of t)n&&this.bodyEl.contains(n)&&n.remove()}showSection(t){this.section=t,this.secEl.querySelectorAll("[data-section]").forEach(r=>{let l=r.dataset.section===t;r.classList.toggle("on",l),r.setAttribute("aria-selected",l?"true":"false")});let n=this.st,a=this.current(),s={overview:()=>{let r=this.ov[a.id];return r?(r.update(n),r.el):(this.ov[a.id]=new ft(a.id,(l,d)=>this.go(l,d))).mount(n)},people:()=>{var h,m;let r=this.pp[a.id];if(r?.el)return r.poll(),r.el;let l=e("div",{},e("p",{class:"dl-muted"},"Loading people…"));return((h=this.pp)[m=a.id]??(h[m]=new He)).embed(n,a.id).then(p=>{l.isConnected?dom.content(l,p):l.replaceChildren(p)}),l},connection:()=>this.connection(a),access:()=>this.access(a),disguise:()=>this.disguise(a),tunnel:()=>this.tunnel(a)}[t]();this.detachKept(),dom.content(this.bodyEl,s)}head(t){let n=this.st,a=(l,d)=>e("span",{class:"dl-addrbar-seg"},[w(l),...d]),i=`${t.endpoint||"—"}:${t.port}`,s=!t.enabled||n.settings.paused_all,r=e("div",{class:"dl-actions"},[N([w("search")," Search ",e("kbd",{},"⌘K")],()=>Ct(),"neutral",{class:"cbi-button cbi-button-neutral dl-searchbtn"}),s?N([w("play")," Turn on"],async()=>{n.settings.paused_all&&!await O(()=>P.pauseAll(!1))||(t.enabled?await this.refresh():await this.save(t,{enabled:"1"},"Server turned on"))},"positive"):""]);return e("div",{class:"dl-srvpagehead"},[e("div",{class:"dl-title-row"},[e("h2",{class:"dl-h1"},t.name),e("span",{class:`dl-pill ${t.enabled?t.up?"ok":"bad":"off"}`},[e("i",{class:"dl-pill-dot"}),t.enabled?t.up?"Ready":"Down":"Disabled"]),n.settings.paused_all&&t.enabled?e("span",{class:"dl-pill warn"},"Off"):"",e("span",{class:"dl-spacer"}),r]),e("div",{class:"dl-addrbar"},[e("button",{type:"button",class:"dl-addrbar-seg main",title:"Copy address and port",click:()=>re(i,"Address copied")},[w("globe"),e("span",{class:"dl-mono"},i),w("copy")]),a("tunnel",[e("span",{class:"dl-mono"},t.ifname)]),a("network",[e("span",{class:"dl-mono"},t.subnet)]),t.up?a("clock",[`up ${Xt(t.uptime)}`]):""])])}async save(t,n,a="Saved"){await O(()=>P.serverUpdate(t.id,n),a)&&await this.refresh()}connection(t){let n=oe(t.name,{placeholder:"Home"}),a=oe(t.endpoint,{placeholder:"vpn.example.com",class:"cbi-input-text dl-mono"}),i=oe(String(t.port),{inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),s=oe(t.dns.join(", "),{placeholder:"This router (recommended)",class:"cbi-input-text dl-mono"}),r=oe(String(t.mtu??""),{placeholder:"1380",inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),l=oe(String(t.keepalive??""),{placeholder:"25",inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"});return Ve("Connection",[e("p",{class:"dl-muted"},"How devices find this server, and what goes into their configuration."),ue("router","Server","What people see",[Q("Name",n,"Shown to people in their portal.")]),ue("globe","Devices connect to","Where the tunnel answers from the internet",[Q("Public address",a,"Hostname or IP of the router on the internet. A DDNS name keeps links working when your IP changes."),Q("UDP port",i,"Opened on the WAN firewall automatically.")]),ue("file","In every device configuration","Changing these marks devices “Update config” until they import again",[Q("DNS for devices",s,"Empty = this router, which sends each query where your home network would."),Q("MTU",r,"Lower it if some sites hang on mobile networks."),Q("Keep-alive",l,"Seconds between packets devices send to keep NAT open. 0 = off.")])],[e("span"),N("Save",()=>this.save(t,{name:n.value,endpoint:a.value,port:i.value,dns:s.value,mtu:r.value,keepalive:l.value}),"positive")])}access(t){let n=this.st.services;return e("div",{class:"dl-stack gap16"},[fn(t.id,"Access"),Ve("Home services",[e("p",{class:"dl-muted"},"People with Home-only access can be limited to these services instead of the whole home network (chosen per person). The list is shared by all servers."),e("div",{class:"dl-list"},n.length?n.map(a=>e("div",{class:"dl-row"},[w("home"),e("span",{class:"dl-row-main dl-stack"},[e("b",{},a.name),e("span",{class:"dl-mono dl-faint"},`${a.address}${a.ports.length?` · ports ${a.ports.join(", ")}`:" · all ports"}`)])])):[e("div",{class:"dl-row dl-muted"},"No services yet.")])],[e("span"),e("a",{class:"cbi-button cbi-button-neutral",href:`${L.url("admin/network/dawnline/settings")}#dl-set-services`},"Edit in Settings")])])}disguise(t){let n=We(t.preset)?t.preset:void 0,a=n??"standard",i=N("",()=>this.applyDisguise(t,a,a===n),"positive"),s=()=>{dom.content(i,a===n?[w("reset")," Generate new values"]:`Switch to ${We(a).title}`)};s();let r=La(t.obf??{});return Ve("Disguise",[e("p",{class:"dl-muted"},"AmneziaWG reshapes the tunnel so networks that block VPNs do not recognise it. Every device gets these settings in its configuration."),Dt(this.st.awg,a,l=>{a=l,s()},n),this.st.awg.v3?"":Ae("info",["This router runs an older AmneziaWG. ",e("b",{},"Maximum")," becomes available with kmod-amneziawg and amneziawg-tools 3.1."]),r??""],[e("span",{class:"dl-sub"},"Applies at once. Every device on this server must import its configuration again."),i])}async applyDisguise(t,n,a){let i=We(n),r=this.st.people.filter(d=>d.server===t.id).reduce((d,h)=>d+h.devices.length,0);await ae(a?"Generate new disguise values?":`Switch to ${i.title}?`,`${r} device${r===1?"":"s"} stop connecting until they import their configuration again (from their personal link or from you).${n==="max"?" They need an app with AmneziaWG 3.1.":""}`,a?"Generate and apply":"Switch and apply",!0)&&await O(()=>P.serverObfuscation(t.id,n),a?"New values applied":`${i.title} applied`)&&(X("Devices are marked “Update config” until they import again.","info",6e3),await this.refresh())}tunnel(t){let n=this.st.people.filter(i=>i.server===t.id).length,a=N(t.enabled?"Turn off":"Turn on",async()=>{t.enabled&&!await ae(`Turn off ${t.name}?`,`The tunnel stops and ${n} ${n===1?"person is":"people are"} disconnected until you turn it back on. Nothing is deleted.`,"Turn off",!0)||await this.save(t,{enabled:t.enabled?"0":"1"},t.enabled?"Server turned off":"Server turned on")},t.enabled?"negative":"positive");return e("div",{class:"dl-stack gap16"},[Ve("Tunnel",[e("p",{class:"dl-muted"},"Technical details. They are set when the server is created and rarely change."),Q("Interface",e("span",{class:"dl-mono"},`${t.ifname} · router ${t.address}`)),Q("Tunnel subnet",e("span",{class:"dl-mono"},t.subnet),"Device addresses come from it."),Q("Server public key",e("span",{class:"dl-keyrow"},[e("code",{class:"dl-mono"},t.public_key),N([w("copy")],()=>re(t.public_key,"Public key copied"),"neutral",{title:"Copy",class:"cbi-button cbi-button-neutral dl-icon-only sm"})]))],[]),Ve("Danger zone",[e("div",{class:"dl-setrow"},[e("div",{class:"dl-stack"},[e("span",{class:"dl-setrow-label"},t.enabled?"Turn off this server":"This server is off"),e("span",{class:"dl-sub"},t.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.")]),e("div",{class:"dl-setrow-ctl"},a)]),e("div",{class:"dl-setrow"},[e("div",{class:"dl-stack"},[e("span",{class:"dl-setrow-label"},"Remove server"),e("span",{class:"dl-sub"},`Removes the tunnel, its firewall rules and ${n} ${n===1?"person":"people"} with all their devices. A backup is made first.`)]),e("div",{class:"dl-setrow-ctl"},N([w("trash")," Remove"],()=>this.remove(t),"negative"))])],[],"danger")])}async addServer(){let t=await O(()=>P.setupDefaults());t&&dom.content(this.root,this.wizard(t,!0,()=>{dom.content(this.root,[this.tabsEl,this.headEl,this.secEl,this.bodyEl]),this.paint()}))}async remove(t){let n=this.st.people.filter(a=>a.server===t.id);ne(`Remove ${t.name}?`,[e("p",{},`This removes the tunnel, its firewall rules and ${n.length} ${n.length===1?"person":"people"} with all their devices. A backup is made first.`)],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",N("Remove",async()=>{J(),await O(()=>P.serverDelete(t.id),"Server removed")&&setTimeout(()=>{location.href=Rt()},800)},"negative")])}wizard(t,n=!1,a){let i={id:t.id,name:t.name,endpoint:t.endpoint,port:t.port,subnet:t.subnet,preset:"standard",portal:!1,portal_port:t.portal_port||8443,lan_like:!0,lan_zone:t.lan_zone,wan_zone:t.wan_zone},s=0,r=e("div",{class:"dl-wizard"}),l=(p,$={})=>{let k=oe(String(i[p]),$);return k.addEventListener("input",()=>{i[p]=p==="port"||p==="portal_port"?Number(k.value):k.value.trim()}),k},d=n?["Connection","Disguise"]:["Connection","Disguise","Portal"],h=[()=>e("div",{class:"dl-wizard-groups"},[e("p",{class:"dl-muted"},"Where devices connect to. A hostname that always points at your router (DDNS) keeps links working when your IP changes."),ue("router","Server","What people see",[Q("Name",l("name"),"Shown to people in their portal.")]),ue("globe","Devices connect to","Where the tunnel answers from the internet",[Q("Public address",l("endpoint",{placeholder:"vpn.example.com",class:"cbi-input-text dl-mono"}),"Hostname or IP address of your router on the internet."),Q("UDP port",l("port",{inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),"Opened on the WAN firewall automatically. A random high port is fine.")]),ue("network","Tunnel network","Addresses devices get inside the tunnel",[Q("Tunnel subnet",l("subnet",{class:"cbi-input-text dl-mono"}),`Must not overlap your networks (${t.taken.join(", ")||"none found"}).`)])]),()=>e("div",{},[e("p",{},"AmneziaWG reshapes the tunnel so networks that block VPNs do not recognise it. Every device gets these settings automatically; you can change the method later."),Dt(t.awg,i.preset,p=>i.preset=p)]),()=>{let p=l("portal_port",{inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),$=Q("Listening port",p,"TCP port on WAN for the portal; the whole port belongs to it.");$.hidden=!i.portal;let k=e("div",{class:"dl-seg",role:"radiogroup","aria-label":"Personal portal"},["off","on"].map(z=>e("button",{type:"button",role:"radio",class:z==="on"===i.portal?"on":"","aria-checked":z==="on"===i.portal?"true":"false",click:Y=>{i.portal=z==="on",$.hidden=!i.portal,k.querySelectorAll("button").forEach(F=>{let H=F===Y.currentTarget;F.classList.toggle("on",H),F.setAttribute("aria-checked",H?"true":"false")})}},z==="on"?"On":"Off")));return e("div",{class:"dl-wizard-groups"},[ue("home","Internet like a home device","How devices reach the internet",[Q("Through the home network",Ie(i.lan_like,"Internet like a home device",z=>i.lan_like=z),"Whatever handles home traffic on this router (proxies, filters, DNS) handles theirs too. Change it later under Servers → Access.")]),ue("link","Personal portal","A page where each person adds their own devices with their personal link",[Q("Portal",k,"Off: only you add devices, from LuCI. On: people manage their devices within the limits you set."),$])])}],m=()=>{dom.content(r,[e("h2",{},n?"Add a server":"Set up Dawnline"),e("div",{class:"dl-steps"},d.map((p,$)=>e("span",{class:`dl-step${$===s?" current":$0?N("Back",()=>{s--,m()}):a?N("Cancel",a):"",e("span",{class:"dl-spacer"}),s{if(s===0&&(!i.endpoint||!i.port||!i.subnet)){X("Fill in the public address, port and subnet.","warning");return}s++,m()},"positive"):N("Create server",async()=>{let p=await O(()=>P.serverCreate(i.id,i.name,t.ifname,i.port,i.subnet,i.endpoint,t.mtu,i.preset,i.lan_zone,i.wan_zone,i.lan_like,n?void 0:i.portal,n?void 0:i.portal_port),"Server created");p&&setTimeout(()=>{location.href=Rt(p.id)},1500)},"positive")])])};return m(),r}};var it=300;function Sa(o){let t=new Date(o*1e3),n=new Date,a=new Date;return a.setDate(n.getDate()-1),t.toDateString()===n.toDateString()?"Today":t.toDateString()===a.toDateString()?"Yesterday":t.toLocaleDateString("en-GB",{weekday:"long",day:"numeric",month:"long"})}function Ht(o){let t=o.keep_days>0?`${o.keep_days} day${o.keep_days===1?"":"s"}`:"no age limit",n=o.persist==="off"?"kept in memory only (lost on reboot)":`saved to flash ${o.persist==="10min"?"every 10 minutes":"hourly"}`;return`Kept for ${t}, up to ${o.max.toLocaleString("en-GB")} events, ${n}.`}var mt=class{constructor(){this.events=[];this.kind="all";this.query="";this.shown=it;this.list=e("div",{});this.sub=e("span",{class:"dl-muted"});this.tabs=e("div",{class:"dl-seg",role:"tablist"})}async load(){return Promise.all([P.status(1),P.events(2e4)])}render([t,n]){this.st=t,this.take(n),we(t);let a=e("input",{type:"search",class:"dl-search-input",placeholder:"Search people, devices, IPs",input:r=>{this.query=r.target.value.trim().toLowerCase(),this.shown=it,this.paint()}}),i=N([w("download")," Export"],()=>ke(i,[{label:"CSV (spreadsheet)",icon:w("download"),run:()=>be(this.st,this.filtered().reverse(),"csv",this.kind==="all"?"":this.kind)},{label:"JSON",icon:w("download"),run:()=>be(this.st,this.filtered().reverse(),"json",this.kind==="all"?"":this.kind)}])),s=N([w("trash")," Clear"],()=>Ee("Clear activity","Removes events from the log on the router.",{},()=>this.reload(),this.kind==="all"?void 0:this.kind));return this.paint(),poll.add(async()=>{let r=await P.events(2e4).catch(()=>null);r&&(this.take(r),this.paint())},15),e("div",{},[e("div",{class:"dl-pagehead"},[e("div",{class:"dl-stack"},[e("h2",{class:"dl-h1"},"Activity"),this.sub]),e("div",{class:"dl-row-actions"},[i,s])]),e("div",{class:"dl-toolbar"},[this.tabs,e("span",{class:"dl-spacer"}),e("label",{class:"dl-search"},[w("search"),a])]),this.list])}take(t){this.events=t.events,this.policy=t.policy;let n=Oe.filter(a=>!t.policy.categories.includes(a));this.sub.textContent=`${Ht(t.policy)}${n.length?` Not recorded: ${n.map(a=>qe[a].toLowerCase()).join(", ")}.`:""}`}async reload(){let t=await P.events(2e4).catch(()=>null);t&&(this.take(t),this.paint())}filtered(){return[...this.events].reverse().filter(t=>this.kind!=="all"&&rt(t.type)!==this.kind?!1:this.query?`${et(this.st,t).map(a=>a.textContent??"").join(" ")} ${t.detail??""} ${t.where??""}`.toLowerCase().includes(this.query):!0)}paintTabs(){let t=n=>n==="all"?this.events.length:this.events.filter(a=>rt(a.type)===n).length;dom.content(this.tabs,["all",...Oe].map(n=>e("button",{type:"button",role:"tab",class:n===this.kind?"on":"",click:()=>{this.kind=n,this.shown=it,this.paint()}},[n==="all"?"All":qe[n],e("b",{},String(t(n)))])))}paint(){this.paintTabs();let t=this.filtered();if(!t.length){dom.content(this.list,e("div",{class:"dl-empty"},[e("p",{},this.events.length?"No events match.":"The log is empty.")]));return}let n=[],a="",i=null;for(let s of t.slice(0,this.shown)){let r=Sa(s.ts);r!==a&&(a=r,i=e("div",{class:"dl-panel flush"},e("div",{class:"dl-panel-head pad"},e("h3",{},r))),n.push(i));let l=tt(this.st,s);l.lastElementChild.textContent=new Date(s.ts*1e3).toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"}),i.appendChild(l)}t.length>this.shown&&n.push(e("div",{class:"dl-more-row"},N(`Show ${Math.min(it,t.length-this.shown)} more of ${t.length-this.shown}`,()=>{this.shown+=it,this.paint()}))),dom.content(this.list,n)}};var Ta={manual:"Manual",auto:"Nightly","pre-restore":"Before restore","pre-import":"Before import","pre-delete":"Before removing a server","pre-update":"Before update"},vn=3;function It(o){let t=new Date(o*1e3),n=t.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"}),a=Math.round((new Date(new Date().toDateString()).getTime()-new Date(t.toDateString()).getTime())/864e5);return`${a===0?"Today":a===1?"Yesterday":t.toLocaleDateString("en-GB",{day:"numeric",month:"short"})}, ${n}`}async function Ea(o){let t=await O(()=>P.backupRead(o.name));if(!t)return;let n=atob(t.data),a=new Uint8Array(n.length);for(let s=0;sEa(o),"neutral","dl-icon-only"),ye("more","More",n=>ke(n.currentTarget,[{label:"Restore",icon:w("reset"),run:async()=>{await ae("Restore this backup?",`Everything returns to ${It(o.created)}. The current state is backed up first.`,"Restore",!0)&&await O(()=>P.backupRestore(o.name),"Restored")&&t()}},{label:"Delete",icon:w("trash"),danger:!0,run:async()=>{await ae("Delete this backup?",`The backup from ${It(o.created)} is removed from the router.`,"Delete",!0)&&await O(()=>P.backupDelete(o.name),"Backup deleted")&&t()}}]),"neutral","dl-icon-only")])])}function Bt(o,t){let n=o.slice(0,vn).map(d=>bn(d,t)),a=o.slice(vn),i=o.length?e("div",{class:"dl-list"},[...n,a.length?e("details",{class:"dl-bk-older"},[e("summary",{},[w("chevron"),`${a.length} older backup${a.length===1?"":"s"}`]),...a.map(d=>bn(d,t))]):""]):e("div",{class:"dl-list"},[e("div",{class:"dl-row dl-muted"},"No backups yet.")]),s=N("Restore from file",async()=>{let d=await Lt(".tar.gz,.tgz,application/gzip","base64");if(!d)return;await ae("Restore from file?",`Replace the current Dawnline configuration with ${d.name}? The current state is backed up first.`,"Restore",!0)&&await O(()=>P.backupUpload(d.data),"Restored")&&t()}),r=N("Export JSON",async()=>{let d=await O(()=>P.exportJson());d&&ve(`dawnline-export-${new Date().toISOString().slice(0,10)}.json`,JSON.stringify(d,null,2),"application/json")}),l=N("Import JSON",async()=>{let d=await Lt(".json,application/json","text");if(!d)return;let h;try{h=JSON.parse(d.data)}catch{X("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 O(()=>P.importJson(h),"Imported")&&t()});return e("section",{class:"dl-setsec",id:"dl-set-backups"},[e("div",{class:"dl-setsec-body"},[e("div",{class:"dl-setsec-head"},[e("div",{class:"dl-stack"},[e("h3",{},"Backups"),e("span",{class:"dl-sub"},"Nightly when something changed, and before every restore, import or update. The last 10 are kept.")]),e("span",{class:"dl-spacer"}),N([w("plus")," Back up now"],async()=>{await O(()=>P.backupCreate(),"Backup created")&&t()},"positive")]),i]),e("div",{class:"dl-setsec-foot"},[e("span",{class:"dl-sub"},"Backups contain private keys: keep downloads safe. JSON moves everything except usage history to another router."),e("span",{class:"dl-row-actions dl-bk-actions"},[s,r,l])])])}function ot(o,t,n){o.some(([s])=>s===t)||(o=[...o,[t,t]]);let a=e("div",{class:"dl-seg sm",role:"radiogroup","aria-label":n,"data-value":t}),i=()=>dom.content(a,o.map(([s,r])=>e("button",{type:"button",role:"radio",class:s===a.dataset.value?"on":"","aria-checked":s===a.dataset.value?"true":"false",click:()=>{a.dataset.value=s,i()}},r)));return i(),a}function jt(o,t,n=`${t}s`){return`${o.toLocaleString("en-GB")} ${o===1?t:n}`}function gt(o){return o<1024?`${o} B`:o<1048576?`${(o/1024).toFixed(o<10240?1:0)} KB`:`${(o/1048576).toFixed(1)} MB`}var vt=class{constructor(){this.root=e("div",{class:"dl-settings-main"});this.backups=[]}load(){return P.settingsGet()}render(t){return this.d=t,we(),this.paint(),this.loadBackups().then(()=>{new URLSearchParams(location.search).get("section")==="backups"&&document.getElementById("dl-set-backups")?.scrollIntoView({block:"start"})}),e("div",{},[e("div",{class:"dl-pagehead"},[e("h2",{class:"dl-h1"},"Settings")]),this.root])}async save(t,n="Saved"){let a=await O(()=>P.settingsUpdate(t),n);a&&(this.d=a,this.paint())}section(t,n,a,i,s="",r=[]){return e("section",{class:`dl-setsec ${s}`,id:`dl-set-${t}`},[e("div",{class:"dl-setsec-body"},[r.length?e("div",{class:"dl-setsec-head"},[e("h3",{},n),e("span",{class:"dl-spacer"}),...r]):e("h3",{},n),...a]),i.length?e("div",{class:"dl-setsec-foot"},i):""])}portalSection(){let t=this.d.settings,n=this.d.effective,a=this.d.cert,i=this.d.portal_candidates??[],s=this.d.portal_checks??[],r=Ie(n.portal_enabled,"Enable portal"),l=oe(t.portal_port,{placeholder:"8443",inputmode:"numeric",class:"cbi-input-text dl-w-port"}),d=Ie(n.portal_443,"Standard ports",()=>f()),h=oe(t.portal_title,{placeholder:"Dawnline"}),m=oe(t.portal_redirect,{placeholder:"Show “Not found”",class:"cbi-input-text dl-mono"}),p=oe("",{placeholder:"vpn.example.com or an IP","aria-label":"Other address"}),$=R=>/^\d{1,3}(\.\d{1,3}){3}$/.test(R),k=[n.portal_host,...n.portal_alt??[]].filter((R,se,M)=>R&&M.indexOf(R)===se);!k.length&&i[0]&&(k=[i[0].host]);let z=[...i],Y=R=>{R&&!z.some(se=>se.host===R)&&z.push({host:R,kind:$(R)?"ip":"name",ips:[],here:!1,cloudflare:!1,cert:!1})};k.forEach(Y);let F=R=>R.kind==="ip"?e("span",{class:"dl-addr-warn"},[w("alert"),"Plain HTTP: the link and VPN keys travel unencrypted"]):e("span",{class:"dl-sub"},R.cloudflare?"Behind Cloudflare · often stalls in Russia":R.ips.length?R.here?`Points at this router${R.cert?" · Let’s Encrypt certificate":" · no certificate yet"}`:`Points at ${R.ips.join(", ")}, not this router`:"Your address"),H=e("div",{class:"dl-addr-opts",role:"group","aria-label":"Portal addresses"}),y=R=>{k.includes(R)?k.length>1&&(k=k.filter(se=>se!==R)):k=[...k,R],D(),f()},D=()=>dom.content(H,[...z.map(R=>{let se=k.includes(R.host),M=k[0]===R.host;return e("div",{class:`dl-addr-opt${se?" on":""}`,role:"checkbox","aria-checked":se?"true":"false",tabindex:"0",click:()=>y(R.host),keydown:S=>{(S.key===" "||S.key==="Enter")&&(S.preventDefault(),y(R.host))}},[e("i",{class:"dl-addr-check"},se?w("check"):""),e("span",{class:"dl-stack"},[e("span",{class:"dl-mono"},R.host),F(R)]),M?e("span",{class:"dl-pill info"},"Main"):se?e("button",{type:"button",class:"dl-linkbtn",click:S=>{S.stopPropagation(),k=[R.host,...k.filter(x=>x!==R.host)],D(),f()}},"Make main"):R.cloudflare?e("span",{class:"dl-pill warn"},"Cloudflare"):R.kind==="ip"?e("span",{class:"dl-pill"},"IP"):R.here&&R.cert?e("span",{class:"dl-pill ok"},"Recommended"):""])}),e("div",{class:"dl-addr-opt other"},[e("i",{class:"dl-addr-check"},w("plus")),p,N("Add",()=>{let R=p.value.trim().toLowerCase();R&&(Y(R),k.includes(R)||(k=[...k,R]),p.value="",D(),f())})])]);p.addEventListener("keydown",R=>{R.key==="Enter"&&(R.preventDefault(),p.nextElementSibling?.click())});let T=e("div",{class:"dl-links"}),f=()=>{let R=Ke(d),se=Number(l.value)||n.portal_port;dom.content(T,k.map((M,S)=>{let x=$(M),E=x?R?80:se+1:R&&!this.d.wan443_taken?443:se,A=`${x?"http":"https"}://${M}${E===(x?80:443)?"":`:${E}`}/`;return e("div",{class:"dl-link-row"},[e("span",{class:`dl-link-ic ${x?"warn":"ok"}`},w(x?"alert":"lock")),e("span",{class:"dl-mono dl-link-url"},[A,e("b",{},"kamiro-telosu-bavine")]),S===0?e("span",{class:"dl-pill info"},"Main"):x?e("span",{class:"dl-pill warn"},"HTTP"):""])}))};D(),f(),l.addEventListener("input",()=>f());let g={portal:"Portal running",portal_dns:"Points here",portal_reply:"Answers reach visitors",portal_443:"Port 443",portal_lan:"Works at home",portal_http:"Plain HTTP",cert:"Certificate"},_=s.filter(R=>R.status!=="skip"),c=_.filter(R=>R.status==="error"||R.status==="warn"),u=_.some(R=>R.status==="error")?"error":c.length?"warn":"ok",C=e("div",{class:"dl-ready-details",hidden:!0},_.map(R=>e("div",{class:`dl-ready-item ${R.status}`},[w(R.status==="ok"?"check":"alert"),e("span",{class:"dl-stack"},[e("span",{},R.title),e("span",{class:"dl-sub"},R.detail)])]))),v=e("div",{class:"dl-stack gap8"},[e("div",{class:`dl-ready-sum ${u}`},[w(u==="ok"?"check":"alert"),e("span",{class:"dl-stack"},[e("b",{},u==="ok"?`All ${_.length} checks passed`:`${_.length-c.length} of ${_.length} checks passed`),c.length?e("span",{class:"dl-sub"},c.map(R=>R.detail).join(" ")):e("span",{class:"dl-sub"},"Links will open for the people you send them to.")]),e("button",{type:"button",class:"dl-linkbtn",click:R=>{C.hidden=!C.hidden,R.currentTarget.textContent=C.hidden?"Details":"Hide"}},"Details")]),e("div",{class:"dl-chips-row"},_.map(R=>e("span",{class:`dl-check-chip ${R.status}`,title:R.detail},[w(R.status==="ok"?"check":"alert"),g[R.id]??R.title]))),C]),b=a&&!a.self_signed&&a.expires?new Date(a.expires).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"}):"",j=Q("Standard ports",d,this.d.wan443_taken?"Port 443 is already forwarded to another device, so HTTPS links keep the listening port.":"Links without a port: 443 for names, 80 for IP addresses. Mobile networks often drop other ports. From the internet these reach only the portal; LuCI stays closed."),q=Q("Listening port",l,this.d.port_owners.length?`Port ${n.portal_port} is used by ${this.d.port_owners.join(", ")}.`:`Where the portal runs on the router: HTTPS here, plain HTTP for IP addresses on ${n.portal_port+1}.`),I=!!(t.portal_cert&&t.portal_key),Z=a?I?"Your files":a.self_signed?"Self-signed":"Let’s Encrypt":"Portal is off",ee=()=>{let R=oe(t.portal_cert,{placeholder:"/etc/ssl/…/fullchain.crt"}),se=oe(t.portal_key,{placeholder:"/etc/ssl/…/key"});ne("Use your own certificate",[e("p",{class:"dl-muted"},"Paths on the router. Leave both empty to pick a certificate automatically."),Q("Certificate file",R),Q("Key file",se)],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",N("Save",()=>{J(),this.save({portal_cert:R.value.trim(),portal_key:se.value.trim()},"Certificate saved")},"positive")])},ie=this.d.needs??{https:[],acme:[],home:[]},he=(R,se,M,S,x,E)=>e("div",{class:`dl-row dl-need-row ${se}`},[se?e("span",{class:"dl-need-ic"},w(R)):w(R),e("span",{class:"dl-row-main dl-stack"},[e("b",{},M),e("span",{class:"dl-sub"},S)]),N(E,()=>nt(x,ie[x],()=>this.reload()),"positive")]),fe=ie.https.length?he("lock","bad","HTTPS isn’t available on this router",`The portal needs ${ie.https.join(" and ")}. It can’t start without them.`,"https","Install"):"",Te=ie.acme.length&&(!a||a.self_signed)?he("lock","","Free certificate from Let’s Encrypt",`ACME isn’t installed. With it the router gets a certificate${t.portal_host?` for ${t.portal_host}`:""} and browsers stop warning.`,"acme","Install ACME"):"",yt=[e("div",{class:"dl-row"},[w("lock"),e("span",{class:"dl-row-main dl-stack"},[e("b",{},[Z,b?e("span",{class:"dl-faint"},` · until ${b}`):""]),e("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.":`${I?"Your files":"Found automatically"} · ${a.path}`:"Turn the portal on to see its certificate.")])]),e("div",{class:"dl-row"},[w("file"),e("span",{class:"dl-row-main dl-stack"},[e("b",{},"Your own files"),e("span",{class:"dl-sub"},I?`${t.portal_cert} · ${t.portal_key}`:"Not set: the certificate is picked automatically.")]),I?N("Reset",()=>this.save({portal_cert:"",portal_key:""},"Automatic certificate"),"negative"):"",N(I?"Change":"Use files",ee)]),Te];return this.section("portal","Personal portal",[e("span",{class:"dl-muted"},"A page where each person adds and manages their devices with their personal link."),fe?e("div",{class:"dl-list"},[fe]):"",ue("network","Ports","How the portal listens",[j,q]),ue("edit","Appearance","What people see",[Q("Title",h,"Shown at the top of the portal."),Q("Unknown links",m,"Where a wrong or old link goes, for example your website. Empty shows a plain “Not found”.")]),ue("link","Addresses","Pick one or more; the first is the main link",[H,e("div",{class:"dl-stack gap8"},[T,e("span",{class:"dl-sub"},"Example code; each person gets their own three words.")])]),ue("lock","Certificate","Used for HTTPS links",yt),n.portal_enabled&&_.length?ue("check","Ready to share","The portal’s checks from Health",[v]):""],[e("span"),N("Save",()=>this.save({portal_enabled:Ke(r)?"1":"0",portal_443:Ke(d)?"1":"0",portal_host:k[0]??"",portal_alt:k.slice(1),portal_port:l.value,portal_title:h.value,portal_redirect:m.value.trim()}),"positive")],"",[n.portal_enabled?ie.https.length?e("span",{class:"dl-pill bad"},"Can’t start"):e("span",{class:`dl-pill ${u==="ok"?"ok":u==="error"?"bad":"warn"}`},u==="error"?"Needs attention":"Ready"):"",r])}paint(){let t=this.d.settings,n=this.d.effective,a=this.portalSection(),i=oe(t.default_device_limit,{placeholder:"3",inputmode:"numeric",class:"cbi-input-text dl-w-port"}),s=Ie(n.hostnames,"Device hostnames"),r=oe(t.domain,{placeholder:"lan",class:"cbi-input-text dl-w-port"}),l=oe(t.home_dns_fallback==="none"?"":t.home_dns_fallback||n.home_dns_fallback||"",{placeholder:"None",inputmode:"decimal",class:"cbi-input-text dl-w-ip dl-mono"}),d=this.section("defaults","Defaults",[Q("Devices per person",i,"Pre-filled when you add someone."),Q("Device hostnames",e("div",{class:"dl-hostport"},[s,e("span",{class:"dl-faint dl-mono"},"phone.myata."),r]),"Name devices in your home DNS."),Q("Fallback DNS",l,"For Home-only devices using home names: the second DNS server, used by the device when the tunnel is down. Empty = none.")],[e("span"),N("Save",()=>this.save({default_device_limit:i.value,hostnames:Ke(s)?"1":"0",domain:r.value,home_dns_fallback:l.value}),"positive")]),h=Ie(n.geo_enabled,"Locations"),m=e("select",{class:"cbi-input-select"},[e("option",{value:"ipwho.is",selected:n.geo_provider!=="ipapi.co"?"selected":null},"ipwho.is (fallback: ipapi.co)"),e("option",{value:"ipapi.co",selected:n.geo_provider==="ipapi.co"?"selected":null},"ipapi.co (fallback: ipwho.is)")]),p=this.section("map","Map & locations",[e("div",{class:"dl-setrow head"},[e("span",{class:"dl-muted"},"Show where people connect from on the Overview and person pages, at city level."),h]),Q("Provider",m)],[e("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."),N("Save",()=>this.save({geo_enabled:Ke(h)?"1":"0",geo_provider:m.value}),"positive")]),$=this.logsSection(),k=this.d.services.map(H=>e("div",{class:"dl-row"},[w("home"),e("span",{class:"dl-row-main dl-stack"},[e("b",{},H.name),e("span",{class:"dl-mono dl-faint"},`${H.address}${H.ports.length?` · ports ${H.ports.join(", ")}`:" · all ports"}`)]),N("Edit",()=>this.editService(H)),N([w("trash")],async()=>{await ae(`Remove ${H.name}?`,"People limited to this service lose access to it.","Remove",!0)&&await O(()=>P.serviceDelete(H.id),"Removed")&&this.reload()},"negative",{title:"Remove"})])),z=this.section("services","Home services",[e("p",{class:"dl-muted"},"Give people with home-network access only specific services instead of the whole network (choose them per person)."),e("div",{class:"dl-list"},k.length?k:[e("div",{class:"dl-row dl-muted"},"No services yet.")])],[e("span"),N([w("plus")," Add service"],()=>this.editService(null),"add")]),Y=this.section("danger","Remove Dawnline from this router",[e("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.")],[e("span"),N("Remove",()=>this.uninstall(),"negative")],"danger"),F=Bt(this.backups,()=>{this.reload(),this.loadBackups()});dom.content(this.root,[a,d,p,$,z,F,Y])}logsSection(){let t=this.d.logs,n=t.policy,a=ot([["7","7 days"],["30","30 days"],["90","90 days"],["365","1 year"],["0","No limit"]],String(n.keep_days),"Keep activity"),i=ot([["500","500"],["2000","2,000"],["5000","5,000"],["20000","20,000"]],String(n.max),"Maximum events"),s=ot([["10min","Every 10 min"],["hourly","Hourly"],["off","Memory only"]],n.persist,"Save to flash"),r=ot([["31","1 month"],["62","2 months"],["180","6 months"],["365","1 year"],["730","2 years"]],String(n.usage_days),"Daily traffic"),l=ot([["12","1 year"],["24","2 years"],["60","5 years"],["120","10 years"]],String(n.usage_months),"Monthly traffic"),d=new Set(n.categories),h=e("div",{class:"dl-chips-row"},Oe.map(z=>{let Y=e("button",{type:"button",class:`dl-chipbtn${d.has(z)?" on":""}`,title:an[z],click:()=>{d.has(z)?d.delete(z):d.add(z),Y.classList.toggle("on",d.has(z))}},[qe[z],e("b",{},String(t.by_category[z]??0))]);return Y})),m=z=>new Date(z).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"}),p=t.oldest?m(new Date(t.oldest*1e3)):"",$=(z,Y,F,H)=>e("div",{class:"dl-row"},[w(z),e("span",{class:"dl-row-main dl-stack"},[e("b",{},Y),e("span",{class:"dl-sub"},F)]),...H]),k=z=>N(z.toUpperCase(),async()=>{let[Y,F]=await Promise.all([P.status(1),P.events(2e4)]);be(Y,F.events,z)},"neutral",{title:`Download the log as ${z.toUpperCase()}`});return this.section("logs","Logs & history",[e("p",{class:"dl-muted"},Ht(n)),Q("Keep activity",a,"Older events are removed automatically."),Q("Maximum size",i,"Newest events are kept when the log is full."),Q("Record",h,"Switched-off categories are not logged from now on."),Q("Save to flash",s,"The log lives in memory and is copied to flash. Memory only saves flash writes but is lost on reboot."),Q("Daily traffic",r,"Per-day history behind the charts."),Q("Monthly traffic",l,"Per-month totals; data limits use the current month."),e("h4",{class:"dl-setsub"},"Stored data"),e("div",{class:"dl-list"},[$("activity","Activity log",t.events?`${jt(t.events,"event")} since ${p} · ${gt(t.log_ram)} in memory${n.persist==="off"?"":`, ${gt(t.log_flash)} on flash`}`:"Empty",[k("csv"),k("json"),N("Clear",()=>Ee("Clear activity","Removes events from the log on the router.",{},()=>this.reload()),"negative")]),$("chart","Traffic history",t.usage_days?`${jt(t.usage_days,"day")} since ${m(t.usage_since)} · ${gt(t.usage_flash)} on flash`:"Empty",[N("Reset",()=>Ue("all","","",()=>setTimeout(()=>this.reload(),300)),"negative")]),$("pin","Location cache",`${jt(this.d.geo_cached,"address","addresses")} · ${gt(t.geo_flash)} on flash`,[N("Clear",async()=>{await O(()=>P.geoClear(),"Location cache cleared")&&this.reload()},"negative")])])],[e("span",{class:"dl-sub"},"Clear one person or device from their own page."),N("Save",()=>this.save({log_keep_days:a.dataset.value,log_max:i.dataset.value,log_persist:s.dataset.value,usage_keep_days:r.dataset.value,usage_keep_months:l.dataset.value,log_category:[...d]}),"positive")])}async loadBackups(){let t=await P.backupList().catch(()=>null);if(t){this.backups=t.backups;let n=document.getElementById("dl-set-backups");n&&n.replaceWith(Bt(this.backups,()=>{this.reload(),this.loadBackups()}))}}async reload(){let t=await P.settingsGet().catch(()=>null);t&&(this.d=t,this.paint())}editService(t){let n=oe(t?.name??"",{placeholder:"NAS"}),a=oe(t?.address??"",{placeholder:"192.168.1.10"}),i=oe(t?.ports.join(", ")??"",{placeholder:"All ports, or e.g. 445, 5000"});ne(t?`Edit ${t.name}`:"Add service",[e("div",{class:"cbi-value"},[e("label",{class:"cbi-value-title"},"Name"),e("div",{class:"cbi-value-field"},n)]),e("div",{class:"cbi-value"},[e("label",{class:"cbi-value-title"},"Address"),e("div",{class:"cbi-value-field"},a)]),e("div",{class:"cbi-value"},[e("label",{class:"cbi-value-title"},"Ports"),e("div",{class:"cbi-value-field"},i)])],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",N("Save",async()=>{let s=i.value.split(/[ ,]+/).filter(Boolean);await O(()=>P.serviceSet(t?.id??"",n.value,a.value,s),"Saved")&&(J(),this.reload())},"positive")])}uninstall(){let t=oe("",{placeholder:"remove"});ne("Remove Dawnline?",[e("p",{},"Everyone is disconnected and the tunnel, firewall rules and portal are removed. A backup is made first. Type “remove” to confirm."),t],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",N("Remove Dawnline",async()=>{await O(()=>P.uninstall(t.value.trim()),"Dawnline removed")&&(J(),setTimeout(()=>location.reload(),800))},"negative")])}};var Ca={ok:"check",warn:"alert",error:"x",skip:"pause"},xn={apply:"Repair",sync:"Reload devices",restart:"Restart service",updates:"Open updates"},bt=class{load(){return P.health()}render(t){return this.root=e("div",{class:"dl-root"}),this.paint(t.checks),e("div",{},[e("h2",{},"Health"),e("div",{class:"cbi-map-descr"},"Everything Dawnline depends on, checked live. Problems come with a fix button where one exists."),this.root])}paint(t){let n=t.filter(i=>i.status==="error").length,a=t.filter(i=>i.status==="warn").length;dom.content(this.root,[n?Ae("error",`${n} problem${n>1?"s":""} need attention.`):a?Ae("warn",`${a} warning${a>1?"s":""}.`):Ae("ok","All checks passed."),e("div",{class:"dl-panel"},[e("div",{class:"dl-panel-head"},[e("h3",{},"Checks"),e("span",{class:"dl-spacer"}),N("Run again",async()=>{let i=await O(()=>P.health());i&&this.paint(i.checks)})]),e("ul",{class:"dl-checks"},t.map(i=>e("li",{},[e("span",{class:`dl-check-icon ${i.status}`},w(Ca[i.status])),e("div",{class:"dl-check-body"},[e("div",{class:"dl-check-title"},i.title),e("div",{class:"dl-check-detail"},i.detail)]),i.fix?i.fix.startsWith("install:")?N("Install",()=>hn(i.fix.slice(8),async()=>{let s=await P.health().catch(()=>null);s&&this.paint(s.checks)}),"action"):i.fix==="updates"?e("a",{class:"cbi-button cbi-button-action",href:L.url("admin/network/dawnline/updates")},xn.updates):N(xn[i.fix]??"Fix",async()=>{let s=await O(()=>P.healthFix(i.fix),"Done");s&&this.paint(s.checks)},"action"):""])))])])}},Da=[{title:"ip-full · veth",sub:"Policy routing and the home-like link",pkgs:["ip-full","kmod-veth"],feature:"home"},{title:"OpenSSL",sub:"HTTPS for the personal portal",pkgs:["libustream-openssl","openssl-util"],feature:"https"},{title:"ACME",sub:"Let’s Encrypt certificate for the portal",pkgs:["acme","acme-acmesh-dnsapi"],feature:"acme",optional:!0}],xt=class{constructor(){this.running=!1}load(){return P.updatesStatus()}render(t){return this.root=e("div",{class:"dl-root dl-upd"}),this.paint(t),poll.add(async()=>{let n=await P.updatesStatus().catch(()=>null);n&&n.job?.state==="running"?this.paint(n):n&&this.running&&(this.running=!1,this.paint(n),n.job?.component==="app"&&n.job.state==="done"&&setTimeout(()=>location.reload(),1500))},3),this.root}paint(t){let n=t.job;this.running=n?.state==="running";let a=t.check?.components??{},i=t.firmware,s=a.app,r=a.amneziawg,l=a.packages,d={disabled:this.running},h=(v,b)=>e("span",{class:`dl-pill ${v}`},b),m=(v,b,j)=>e("div",{class:"dl-upd-row"},[e("span",{class:"dl-stack"},[e("span",{class:"dl-upd-name"},v),e("span",{class:"dl-sub"},b)]),j]),p=(v,b,j,q,I=[])=>e("section",{class:"dl-setsec dl-upd-sec"},[e("div",{class:"dl-upd-head"},[e("span",{class:"dl-group-ic"},w(v)),e("span",{class:"dl-stack"},[e("b",{},b),e("span",{class:"dl-sub"},j)]),q]),...I]),$=v=>v?new Date(v).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"}):"",k=p("sunrise","Dawnline",s?.repo?`${t.version} · ${s.repo}`:t.version,s?s.update?N(`Update to ${s.latest}`,()=>this.run("app"),"positive",d):s.latest?h("ok","Up to date"):h("","No releases yet"):h("","Not checked")),z=r?.sources??{},F=Object.keys(z).map(v=>{let b=z[v],j=r?.current===v,q=[b.version?`${b.tag} build${b.date?` · ${$(b.date)}`:""} · ${b.gen==="3.1"?"devices need AmneziaVPN with 3.1":"works with every AmneziaWG app"}`:`No build for OpenWrt ${i?.version??""}`],I=b.version?j?r?.update?N("Update",()=>this.runAwg(v,!!r.ru,b.gen),"positive",d):h("ok","Installed"):N("Switch",()=>this.runAwg(v,!!r?.ru,b.gen),"neutral",d):h("","No build");return m([b.gen?`AmneziaWG ${b.gen}`:"AmneziaWG",e("span",{class:"dl-faint"},` · ${b.label}`)],q,I)});r?.current&&z[r.current]?.version&&F.push(m("Russian translation","LuCI pages for AmneziaWG in Russian",N(r.ru?"Remove":"Add",()=>this.runAwg(r.current,!r.ru,r.gen),"neutral",d)));let H=p("shield","AmneziaWG",r?.installed?`${r.gen?`${r.gen} · `:""}${r.installed} · changing it restarts every tunnel`:"Not installed",r?"":h("","Not checked"),F.length?F:[m("Builds for this router","Check for updates to see them.","")]),y=l?.pkgs??{},D=[],T=Da.filter(v=>v.feature==="home"?t.home:t.portal);for(let v of T){let b=v.pkgs.filter(I=>y[I]?.installed),j=[...new Set(b.flatMap(I=>[...y[I]?.latest?[I]:[],...y[I]?.with??[]]))],q=t.needs?.[v.feature]??v.pkgs.filter(I=>!y[I]?.installed);if(q.length)D.push(m(v.title,v.optional?`Not installed · ${v.sub}`:e("span",{class:"dl-upd-bad"},`Missing ${q.join(", ")} · ${v.sub}`),N("Install",()=>this.runPkgs(q,v.title),"neutral",d)));else if(j.length){let I=b.find(ie=>y[ie]?.latest),Z=I?[e("span",{class:"dl-mono"},[`${y[I].installed} → `,e("b",{},y[I].latest)])]:[],ee=j.filter(ie=>ie!==I);ee.length&&Z.push(`${I?" · ":""}${ee.length<=2?`${I?"with ":""}${ee.join(", ")}`:`${I?"+":""}${ee.length} related packages`}`),D.push(m(v.title,Z,N("Update",()=>this.runPkgs(b.filter(ie=>y[ie]?.latest||y[ie]?.with?.length),v.title,j),"neutral",d)))}else D.push(m(v.title,v.sub,h("ok","Up to date")))}let f=T.flatMap(v=>v.pkgs).filter(v=>y[v]?.installed),g=[...new Set(f.flatMap(v=>[...y[v].latest?[v]:[],...y[v].with??[]]))],_=p("package","System packages",l?g.length?`${g.length} update${g.length===1?"":"s"} from the OpenWrt ${i?.version?.replace(/\.\d+$/,"")??""} feeds`:"What Dawnline adds to OpenWrt is current":"What Dawnline adds to OpenWrt",l?g.length?N("Update all",()=>this.runPkgs(f.filter(v=>y[v].latest||y[v].with?.length),"all packages",g),"positive",d):"":h("","Not checked"),l?D:[]),c=n?e("details",{class:"dl-params dl-upd-job",open:this.running?"open":null},[e("summary",{},[w("chevron"),e("span",{},"Last job"),h(n.state==="done"?"ok":n.state==="failed"?"bad":"warn",n.state==="running"?n.phase||"Running":n.state==="done"?"Finished":"Failed"),e("span",{class:"dl-sub"},`${n.action==="check"?"check":n.component??""} · ${St(n.started)}${n.finished?` · ${n.finished-n.started} s`:""}`)]),n.error?Ae("error",n.error):"",e("pre",{class:"dl-log"},n.log.join(` -`))]):"",u=g.length+(s?.update?1:0)+(r?.update?1:0),C=[i?.version?`OpenWrt ${i.version} · ${i.target}`:"",t.check?u?`${u} update${u===1?"":"s"} ready`:"everything is current":"not checked yet",t.check?`checked ${St(t.check.time)}`:""].filter(Boolean).join(" · ");dom.content(this.root,[e("div",{class:"dl-pagehead"},[e("div",{class:"dl-stack"},[e("h2",{class:"dl-h1"},"Updates"),e("span",{class:"dl-faint"},C)]),N([w("refresh")," Check now"],()=>this.run("check"),"neutral",d)]),k,H,_,c])}async runAwg(t,n,a){await ae(a?`Install AmneziaWG ${a}?`:"Install AmneziaWG?","Every AmneziaWG tunnel on the router restarts for a few seconds, HomeTunnel too. Devices stay configured.","Install")&&this.start(`amneziawg:${t}${n?":ru":""}`)}async runPkgs(t,n,a=t){await ae(`Update ${n}?`,`${a.join(", ")} from the OpenWrt feeds. Services that use them restart for a moment.`,"Update")&&this.start(`pkgs:${t.join(",")}`)}async run(t){t!=="check"&&!await ae(`Update ${t==="app"?"Dawnline":t}?`,"A backup is made first. The page reloads when it finishes.","Update")||this.start(t)}async start(t){if(await O(()=>P.updatesRun(t))){this.running=!0;let n=await P.updatesStatus().catch(()=>null);n&&this.paint(n)}}};function Ot(o){return`${o.getFullYear()}-${String(o.getMonth()+1).padStart(2,"0")}-${String(o.getDate()).padStart(2,"0")}`}function Aa(o,t,n,a=30){let i=o?new Date(`${o}T12:00:00`):new Date;return t==="day"?i.setDate(i.getDate()+n):t==="week"?i.setDate(i.getDate()+7*n):t==="month"?i.setMonth(i.getMonth()+n):t==="year"?i.setFullYear(i.getFullYear()+n):i.setDate(i.getDate()+a*n),Ot(i)}var Pa={internet:"Browse the internet through your router. No access to devices at home.",lan:"Reach devices at home. Internet stays on their own connection.",both:"Home devices and the internet, all through your router."},wt=class{constructor(){this.id="";this.events=[];this.mapOpen=!1;this.map=null;this.parts={};this.series=[];this.devSeries={};this.refreshSeq=0;this.refreshShown=0}async load(){this.id=new URLSearchParams(location.search).get("id")??"";let[t,n,a]=await Promise.all([P.status(30),P.events(5e3).catch(()=>({events:[]})),P.personUsage(this.id,30).catch(()=>null)]);return this.series=a?.person??[],this.devSeries=a?.devices??{},[t,n.events]}render([t,n]){this.st=t,this.events=n,we(t);let a=t.people.find(l=>l.id===this.id);if(!a)return e("div",{class:"dl-empty"},[e("h3",{},"Person not found"),e("p",{},"They may have been removed."),e("a",{class:"cbi-button",href:L.url("admin/network/dawnline/server")},"Back to Servers")]);this.p=a;for(let l of["head","devices","traffic","places","activity","limits"])this.parts[l]=e("div",{});this.parts.devices.className="dl-person-devices";let i=e("div",{},[e("nav",{class:"dl-crumbs","aria-label":"Breadcrumb"},[e("a",{href:Ze(a.server)},t.servers.find(l=>l.id===a.server)?.name??"Servers"),e("span",{},"/"),e("a",{href:Ze(a.server)},"People"),e("span",{},"/"),e("span",{},a.name)]),this.parts.head,e("div",{class:"dl-grid-person"},[e("div",{class:"dl-col"},[this.parts.devices,this.parts.traffic,this.parts.places,this.parts.activity]),e("div",{class:"dl-col"},[this.parts.limits])])]);this.paint();let s=new URLSearchParams(location.search),r=s.get("device")&&a.devices.find(l=>l.id===s.get("device"));return r?setTimeout(()=>Ce(this.p,r,()=>this.refresh(),this.st.geo),50):s.get("add")&&setTimeout(()=>Re(this.p,()=>this.refresh()),50),poll.add(()=>this.refresh(!0),15),i}async refresh(t=!1){let n=++this.refreshSeq,[a,i,s]=await Promise.all([P.status(30).catch(()=>null),P.events(5e3).catch(()=>null),P.personUsage(this.id,30).catch(()=>null)]);if(!a||nl.id===this.id);if(!r){t||(location.href=Ze(this.p?.server));return}this.p=r,this.paint(),this.map?.update(this.mapData())}async patch(t,n){var s;let a=await O(()=>P.personUpdate(this.p.id,t),n);if(!a)return;let i=this.st.people.findIndex(r=>r.id===this.p.id);(s=a.person).rate??(s.rate=this.p.rate),i>=0&&(this.st.people[i]=a.person),this.p=a.person,this.paint()}mapData(){return{geo:this.st.geo,people:this.st.people,now:this.st.now,person:this.p.id}}mapCard(){let t=e("div",{class:"dl-panel-head pad"},[e("h3",{},"Locations"),e("span",{class:"dl-spacer"}),this.st.geo.enabled?ut("30d",n=>this.map?.setRange(n),!1):"",N("Hide",()=>{this.mapOpen=!1,this.map?.destroy(),this.map=null,this.paintPlaces()},"neutral")]);return this.st.geo.enabled?(this.map=new Fe({openPerson:()=>{},openDevice:(n,a)=>{let i=this.p.devices.find(s=>s.id===a);i&&Ce(this.p,i,()=>this.refresh(),this.st.geo)}},"30d",280),requestAnimationFrame(()=>this.map.mount(this.mapData())),e("div",{class:"dl-panel flush"},[t,this.map.el])):e("div",{class:"dl-panel flush"},[t,e("div",{class:"dl-map-off"},["Locations are off. ",e("a",{href:L.url("admin/network/dawnline/settings")},"Turn them on in Settings"),"."])])}paint(){let t=this.p,n=this.st,a=t.online?"online now":t.last_seen?`last seen ${ce(t.last_seen,n.now)}`:"never connected",i=this.series.find(p=>p.day===Ot(new Date));dom.content(this.parts.traffic,e("div",{class:`dl-person-live${t.online?"":" solo"}`},[t.online?At(t.rate??[],n.now,i?[i.rx,i.tx]:[0,0]):"",Pt(this.series,`${V(t.month[0]+t.month[1])} this month`)]));let s=t.created?`Added ${_e(Ot(new Date(t.created*1e3)))}`:"",r=[{label:"Rename",icon:w("edit"),run:()=>this.rename()},{label:t.note?"Edit note":"Add note",icon:w("file"),run:()=>this.editNote()},...t.link?[null,{label:"Invite card",icon:w("qr"),run:()=>this.invite()},{label:"New link",icon:w("key"),run:()=>this.newLink()}]:[],null,{label:t.paused?"Resume":"Pause",icon:w(t.paused?"play":"pause"),warn:!t.paused,run:()=>this.patch({paused:!t.paused},t.paused?"Resumed":"Paused")},{label:"Delete",icon:w("trash"),danger:!0,run:()=>this.remove()}];dom.content(this.parts.head,e("div",{class:"dl-person-head"},[e("div",{class:"dl-pagehead"},[e("div",{class:"dl-person-id"},[e("span",{class:`dl-avatar lg${t.online?" online":""}`},Le(t.name)),e("div",{class:"dl-stack"},[e("div",{class:"dl-title-row"},[e("h2",{class:"dl-h1"},t.name),zt(t)]),e("span",{class:"dl-faint",title:s},`${t.devices.length} of ${t.device_limit} devices · ${a}`)])]),e("div",{class:"dl-pcard-actions"},[t.link?ye("link","Copy link",()=>re(t.link,"Personal link copied"),"neutral","dl-icon-only"):"",ye("more","More",p=>ke(p.currentTarget,r),"neutral","dl-icon-only")])]),t.note?e("button",{type:"button",class:"dl-pnote",title:"Edit note",click:()=>this.editNote()},[w("file"),e("span",{},t.note)]):""])),this.paintDevices(),this.paintLimits(),this.paintPlaces();let l=this.events.filter(p=>p.person===t.id),d=[],h=[...l].reverse();for(let p=0;p1){let Y=z.querySelector(".dl-row-main");dom.content(Y,[...et(n,$).slice(0,2),e("span",{class:"dl-muted"},`${k} times`)]),Y.title=h.slice(p,p+k).map(F=>F.detail??"").join(` -`)}d.push(z),p+=k-1}let m=N([w("more")],()=>ke(m,[{label:"Export CSV",icon:w("download"),run:()=>be(this.st,l,"csv",t.id)},{label:"Export JSON",icon:w("download"),run:()=>be(this.st,l,"json",t.id)},null,{label:`Clear ${t.name}'s activity`,icon:w("trash"),danger:!0,run:()=>Ee(`Clear ${t.name}'s activity`,`Removes events about ${t.name} and their devices.`,{person:t.id},()=>this.refresh())}]),"neutral",{title:"Export or clear",class:"cbi-button cbi-button-neutral dl-icon-only"});dom.content(this.parts.activity,e("div",{class:"dl-panel flush"},[e("div",{class:"dl-panel-head pad"},[e("h3",{},"Activity"),e("span",{class:"dl-sub"},l.length>10?`latest 10 of ${l.length}`:""),e("span",{class:"dl-spacer"}),m]),d.length?d:e("div",{class:"dl-row dl-muted"},"Nothing yet.")]))}deviceStatus(t){return t.disabled?e("span",{class:"dl-dstat"},[e("i",{class:"dot"}),"Disabled"]):t.online?e("span",{class:"dl-dstat ok"},[e("i",{class:"dot ok"}),`Online · ${ce(t.handshake,this.st.now).replace(" ago","")}`]):t.handshake?e("span",{class:"dl-dstat"},[e("i",{class:"dot"}),`Last seen ${ce(t.handshake,this.st.now)}`]):e("span",{class:"dl-dstat warn",title:"Waiting for the first connection"},[e("i",{class:"dot warn"}),"Not set up yet"])}addrs(t){if(!t.online||!t.endpoint)return"";let n=this.st.geo?.points.find(s=>s.device===t.id&&s.ip===t.endpoint),a=n?.city?`Client IP · ${n.city}${n.org?` · ${n.org}`:""}`:"Client IP",i=e("button",{type:"button",class:"dl-addr wan","aria-label":`Copy ${t.endpoint}`,click:()=>re(t.endpoint,"Client IP copied")},[w("globe"),e("span",{},t.endpoint)]);return le(i,()=>[e("div",{class:"dl-tip-title"},a),e("div",{class:"dl-muted"},"Click to copy")]),e("div",{class:"dl-addrs"},i)}deviceBars(t){let n=(this.devSeries[t]??[]).slice(-30),a=n.map(r=>r.rx+r.tx),i=Math.max(1,...a),s=r=>new Date(`${r}T12:00:00`).toLocaleDateString("en-GB",{day:"numeric",month:"short"});return e("div",{class:"dl-dbars"},n.map((r,l)=>{let d=e("i",{class:`${a[l]?"":"zero"}${l===n.length-1?" hi":""}`});return d.style.height=`${Math.max(8,a[l]/i*100)}%`,le(d,()=>[e("div",{class:"dl-tip-title"},l===n.length-1?`Today · ${s(r.day)}`:s(r.day)),e("div",{},V(a[l]))]),d}))}paintDevices(){let t=this.p,n=()=>this.refresh(),a=t.devices.map(s=>{let r=()=>Ce(t,s,n,this.st.geo);return e("article",{class:`dl-dcard${s.online?" online":""}${s.disabled?" off":""}`},[e("div",{class:"dl-dcard-head"},[e("span",{class:"dl-dcard-ic"},w(s.kind)),e("button",{type:"button",class:"dl-dcard-title",click:r},[e("b",{},s.name),this.deviceStatus(s),s.config_stale?e("span",{class:"dl-pill warn dl-stale"},"Update config"):""]),N([w("more")],r,"neutral",{title:`${s.name}: connect, rename, keys, remove`,class:"cbi-button cbi-button-neutral dl-icon-only"})]),s.handshake?e("div",{class:"dl-dcard-trend"},[e("div",{class:"dl-stack"},[e("b",{},V(s.month[0]+s.month[1])),e("span",{class:"dl-sub"},"this month")]),this.deviceBars(s.id)]):s.disabled?e("div",{class:"dl-sub"},`${Me[s.kind]} · created ${ce(s.created,this.st.now)} ${s.created_by==="portal"?"in the portal":"by you"}.`):e("div",{class:"dl-chips-row"},[e("button",{type:"button",class:"dl-chipbtn",click:()=>this.showDeviceQr(s)},[w("qr"),"Show QR"]),e("button",{type:"button",class:"dl-chipbtn",click:()=>this.downloadConfig(s)},[w("download"),"Config"])]),this.addrs(s)])}),i=Math.max(0,t.device_limit-t.devices.length);i&&a.push(e("button",{type:"button",class:"dl-dslot add",click:()=>Re(t,n)},[e("span",{class:"dl-dslot-ic"},w("plus")),e("b",{},"Add device")])),dom.content(this.parts.devices,e("section",{class:"dl-devsec"},[e("div",{class:"dl-panel-head"},[e("h3",{},"Devices"),e("span",{class:"dl-sub"},`${t.online} online`),e("span",{class:"dl-spacer"}),i?"":N([w("plus")," Add device"],()=>Re(t,n),"neutral",{title:"Over the limit — admins can still add"})]),e("div",{class:"dl-dgrid"},a)]))}paintLimits(){let t=this.p,n=e("div",{class:"dl-seg wide",role:"radiogroup","aria-label":"Access"},["internet","lan","both"].map(c=>e("button",{type:"button",role:"radio",class:t.access===c?"on":"","aria-checked":t.access===c?"true":"false",click:()=>t.access!==c&&this.patch({access:c},`Access: ${je[c]}`)},[w(c==="internet"?"globe":c==="lan"?"home":"shield"),c==="internet"?"Internet":c==="lan"?"Home":"Both"]))),a=ze(t.expires),i=e("input",{type:"date",class:"dl-date-hidden",value:t.expires,tabindex:"-1","aria-hidden":"true"});i.addEventListener("change",()=>i.value&&this.patch({expires:i.value},`Access until ${_e(i.value)}`));let s=(c,u,C)=>{let v=Aa(t.expires&&(a??-1)>=0?t.expires:"",c,u);return this.patch({expires:v},`Access until ${_e(v)}`),C},r=[["week",1,"+1 week"],["month",1,"+1 month"],["month",3,"+3 months"],["year",1,"+1 year"]].map(([c,u,C])=>e("button",{type:"button",class:"dl-chipbtn",click:()=>s(c,u,C)},C)),l=e("span",{class:"dl-datechip"},[e("button",{type:"button",class:"dl-chipbtn",click:()=>{try{i.showPicker()}catch{i.focus()}}},[w("calendar"),t.expires?_e(t.expires):"Date"]),i]),d={pause:"pause access",notify:"keep access",remove:"remove their devices"}[t.expire_action],h=e("div",{class:"dl-tile2"},[e("div",{class:"dl-tile2-label"},[e("span",{},"Access ends"),t.expires?e("span",{class:a!=null&&a<0?"dl-bad":a!=null&&a<=t.expire_warn?"dl-warn":"dl-ok"},a!=null&&a<0?"ended":`${a} day${a===1?"":"s"} left`):e("span",{class:"dl-faint"},"no end date")]),e("div",{class:"dl-chips-row"},[...r,l,t.expires?e("button",{type:"button",class:"dl-chipbtn",click:()=>this.patch({expires:""},"No end date")},"No end"):""]),e("div",{class:"dl-tile2-foot"},[e("span",{class:"dl-muted"},`When it ends: ${d}${t.expire_warn?`, warn ${t.expire_warn} day${t.expire_warn===1?"":"s"} before`:""}`),e("a",{href:"#",click:c=>{c.preventDefault(),this.endSettings()}},"Change")])]),m=t.quota_used||t.month[0]+t.month[1],p=t.quota_limit?Math.min(100,t.quota_used/t.quota_limit*100):0,$=e("div",{class:`dl-meter${p>=100?" bad":p>=90?" warn":""}`},[e("i"),t.quota_limit?e("span",{class:"mark",title:"Alert at 90%"}):""]);$.firstChild.style.width=`${p}%`,t.quota_limit&&le($,()=>[e("div",{class:"dl-tip-title"},`${p.toFixed(1)}% used`),e("div",{class:"dl-muted"},`${V(t.quota_used)} of ${V(t.quota_limit)} · ${V(Math.max(0,t.quota_limit-t.quota_used))} left`),e("div",{class:"dl-faint"},"Alert at 90%")]);let k=e("div",{class:"dl-seg sm"},["month","total"].map(c=>e("button",{type:"button",class:t.quota_period===c?"on":"",click:()=>t.quota_period!==c&&this.patch({quota_period:c})},c==="month"?"Monthly":"Total"))),z=[10,50,100].map(c=>e("button",{type:"button",class:`dl-chipbtn${t.quota_gb===c?" on":""}`,click:()=>this.patch({quota_gb:String(c)},`Data limit ${c} GB`)},`${c} GB`));z.push(e("button",{type:"button",class:`dl-chipbtn${t.quota_gb?"":" on"}`,click:()=>this.patch({quota_gb:""},"No data limit")},"Unlimited")),z.push(e("button",{type:"button",class:"dl-chipbtn",click:()=>{let c=prompt("Data limit in GB",t.quota_gb?String(t.quota_gb):"");c!=null&&c.trim()!==""&&Number(c)>0&&this.patch({quota_gb:c.trim()},`Data limit ${c.trim()} GB`)}},"Custom"));let Y=e("div",{class:"dl-tile2"},[e("div",{class:"dl-tile2-label"},[e("span",{},"Data"),k]),e("div",{class:"dl-tile2-row"},[e("span",{class:"dl-tile2-value"},[V(m),t.quota_limit?e("span",{class:"dl-faint"},` of ${V(t.quota_limit)}`):e("span",{class:"dl-faint"}," · no limit")]),t.quota_period==="month"?e("span",{class:"dl-sub"},"resets on the 1st"):""]),t.quota_limit?$:"",e("div",{class:"dl-chips-row"},z),t.quota_gb&&t.quota_period==="month"?e("div",{class:"dl-tile2-foot"},[e("span",{class:"dl-muted"},t.bonus_gb?`Includes +${t.bonus_gb} GB extra this month`:"Need a little more this month?"),e("a",{href:"#",click:c=>{c.preventDefault(),this.patch({bonus_gb:String((t.bonus_gb||0)+10)},"+10 GB this month")}},"+10 GB this month")]):"",e("div",{class:"dl-tile2-foot"},[e("span",{class:"dl-muted"},`${V(t.total[0]+t.total[1])} in total`),e("button",{type:"button",class:"dl-linkbtn danger",click:()=>Ue("person",t.id,t.name,()=>setTimeout(()=>this.refresh(),300))},"Reset usage")])]),F=!!t.hours,[H,y]=(t.hours||"07:00-23:00").split("-"),D=e("input",{type:"time",class:"cbi-input-text",value:H}),T=e("input",{type:"time",class:"cbi-input-text",value:y}),f=()=>this.patch({hours:`${D.value}-${T.value}`},`Allowed ${D.value}–${T.value}`);D.addEventListener("change",f),T.addEventListener("change",f);let g=e("button",{type:"button",role:"switch","aria-checked":F?"true":"false",class:`dl-switch${F?" on":""}`,"aria-label":"Limit hours",click:()=>this.patch({hours:F?"":"07:00-23:00"},F?"Any time":"Allowed 07:00–23:00")},e("i")),_=e("div",{class:"dl-tile2"},[e("div",{class:"dl-tile2-row"},[e("div",{class:"dl-stack"},[e("span",{class:"dl-tile2-label"},"Allowed hours"),e("span",{},F?`${H} – ${y} (router time)`:"Any time")]),g]),F?e("div",{class:"dl-tile2-row"},[D,e("span",{class:"dl-faint"},"to"),T]):""]);dom.content(this.parts.limits,e("section",{class:"dl-panel","aria-label":"Access and limits"},[e("div",{class:"dl-panel-head"},[e("h3",{},"Access & limits")]),e("div",{class:"dl-stack gap8"},[e("span",{class:"dl-tile2-label"},"Can reach"),n,e("span",{class:"dl-sub"},Pa[t.access]),t.access==="lan"&&this.st.services.length?this.servicesPicker():"",t.access==="lan"?this.dnsPicker():""]),e("div",{class:"dl-tiles2"},[this.devTile(),h,Y,_])]))}dnsPicker(){let t=this.p,n=e("div",{class:"dl-seg sm",role:"radiogroup","aria-label":"DNS"},[["device","Device’s own DNS"],["home","Home names"]].map(([i,s])=>e("button",{type:"button",role:"radio",class:t.dns_mode===i?"on":"","aria-checked":t.dns_mode===i?"true":"false",click:()=>t.dns_mode!==i&&this.patch({dns_mode:i},i==="home"?"Home names on — devices need their configuration again":"Device DNS — devices need their configuration again")},s))),a=this.st.settings.home_dns_fallback;return e("div",{class:"dl-stack gap4 dl-dnspick"},[e("div",{class:"dl-row-actions"},[e("span",{class:"dl-sub"},"DNS"),n]),e("span",{class:"dl-sub"},t.dns_mode==="home"?["Names like ",e("span",{class:"dl-mono"},`nas.${this.st.settings.domain}`)," work. Internet names are resolved at home, so they depend on the tunnel",a?[" (",e("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.")])}servicesPicker(){let t=new Set(this.p.services??[]);return e("div",{class:"dl-stack gap4"},[e("div",{class:"dl-chips-row"},this.st.services.map(n=>e("button",{type:"button",class:`dl-chipbtn${t.has(n.id)?" on":""}`,title:`${n.address}${n.ports.length?` · ${n.ports.join(", ")}`:""}`,click:()=>{t.has(n.id)?t.delete(n.id):t.add(n.id),this.patch({services:[...t]},t.size?"Home services updated":"Whole home network")}},n.name))),e("span",{class:"dl-sub"},t.size?"Only the selected services at home.":"Whole home network. Pick services to narrow it down.")])}devTile(){let t=this.p,n=e("div",{class:"dl-slots"});for(let s=0;s[e("div",{class:"dl-tip-title"},r?r.name:"Free slot"),e("div",{class:"dl-muted"},r?r.online?"Online":r.handshake?`Last seen ${ce(r.handshake,this.st.now)}`:"Not set up yet":"They can add a device here")]),n.appendChild(l)}let a=Math.max(1,t.devices.length),i=e("button",{type:"button","aria-label":"Allow fewer devices",disabled:t.device_limit<=a?"disabled":null,click:()=>this.patch({device_limit:String(t.device_limit-1)})},"−");return t.device_limit<=a&&t.devices.length>1&&le(i,()=>[e("div",{class:"dl-tip-title"},`${t.devices.length} devices in use`),e("div",{class:"dl-muted"},"Remove a device first to lower the limit")]),e("div",{class:"dl-tile2"},[e("div",{class:"dl-tile2-label"},"Devices"),e("div",{class:"dl-tile2-row"},[e("span",{class:"dl-tile2-value"},[String(t.devices.length),e("span",{class:"dl-faint"},` / ${t.device_limit}`)]),e("div",{class:"dl-stepper"},[i,e("button",{type:"button","aria-label":"Allow more devices",disabled:t.device_limit>=32?"disabled":null,click:()=>this.patch({device_limit:String(t.device_limit+1)})},"+")])]),n])}paintPlaces(){let t=this.st;if(!t.geo.enabled){dom.content(this.parts.places,e("div",{class:"dl-places"},[w("pin"),e("div",{class:"dl-stack"},[e("span",{},"Locations are off"),e("span",{class:"dl-sub"},"City-level, from the client IP")]),e("span",{class:"dl-spacer"}),e("a",{class:"cbi-button cbi-button-neutral",href:L.url("admin/network/dawnline/settings")},"Turn on")]));return}if(this.mapOpen){(!this.map||!this.parts.places.contains(this.map.el))&&dom.content(this.parts.places,this.mapCard());return}let n=t.now-30*86400,a=t.geo.points.filter(r=>r.person===this.p.id&&r.ts>=n).sort((r,l)=>l.ts-r.ts),i=[...new Set(a.map(r=>r.city||r.country).filter(Boolean))],s=a[0];dom.content(this.parts.places,e("div",{class:"dl-places"},[w("pin"),e("div",{class:"dl-stack"},[e("span",{},s?s.city||s.country:"No locations yet"),e("span",{class:"dl-sub"},s?`${i.length} place${i.length===1?"":"s"} in 30 days${s.org?` · ${s.org}`:""}`:"Shown after a device connects")]),e("span",{class:"dl-spacer"}),a.length?N("Show map",()=>{this.mapOpen=!0,this.paintPlaces()},"neutral"):""]))}invite(){let t=this.st.servers.find(n=>n.id===this.p.server)?.name??"Home";Qe(this.p,t)}showQr(){let t=this.p;t.link&&ne(`${t.name}’s link`,[e("div",{class:"dl-qr-pane"},[Pe(Be(t.link),"dl-qr"),e("div",{class:"dl-hint"},"Scan with the phone camera to open the portal.")])],[e("button",{class:"cbi-button",click:J},"Close")])}async newLink(){let t=this.p;if(!await ae("Create a new link?","The old link stops working right away.","Create new link",!0))return;let n=await O(()=>P.personRegen(t.id),"New link created");n?.link&&(t.link=n.link,re(n.link,"New link copied"),this.paint())}async showDeviceQr(t){let n=await O(()=>P.deviceConfig(t.id));n&&ne(`Set up ${t.name}`,[await Et(n)],[e("button",{class:"cbi-button",click:J},"Close")])}async downloadConfig(t){let n=await O(()=>P.deviceConfig(t.id));if(n){if(!n.has_private_key){X("This device made its own keys in the browser; its configuration only exists there.","warning");return}ve(n.filename,n.conf,"application/octet-stream")}}editNote(){let t=e("textarea",{class:"cbi-input-textarea dl-note-input",rows:3,maxlength:500,placeholder:"Only you see this"},this.p.note??"");ne("Note",[t],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",N("Save",async()=>{J(),await this.patch({note:t.value.trim()},t.value.trim()?"Note saved":"Note removed")},"positive")]),setTimeout(()=>t.focus(),50)}endSettings(){let t=this.p,n=e("select",{class:"cbi-input-select"},[e("option",{value:"pause",selected:t.expire_action==="pause"?"selected":null},"Pause access"),e("option",{value:"notify",selected:t.expire_action==="notify"?"selected":null},"Keep access"),e("option",{value:"remove",selected:t.expire_action==="remove"?"selected":null},"Remove their devices")]),a=e("select",{class:"cbi-input-select"},[0,1,3,7,14].map(i=>e("option",{value:i,selected:t.expire_warn===i?"selected":null},i?`${i} day${i===1?"":"s"} before`:"Don’t warn")));ne("When access ends",[e("div",{class:"cbi-value"},[e("label",{class:"cbi-value-title"},"Then"),e("div",{class:"cbi-value-field"},n)]),e("div",{class:"cbi-value"},[e("label",{class:"cbi-value-title"},"Warn"),e("div",{class:"cbi-value-field"},[a,e("div",{class:"cbi-value-description"},"Shown in their portal and on the Overview.")])])],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",N("Save",async()=>{J(),await this.patch({expire_action:n.value,expire_warn:a.value},"Saved")},"positive")])}rename(){let t=e("input",{type:"text",class:"cbi-input-text",value:this.p.name,maxlength:48});ne("Rename",[e("div",{class:"cbi-value"},[e("label",{class:"cbi-value-title"},"Name"),e("div",{class:"cbi-value-field"},t)])],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",N("Save",async()=>{J(),await this.patch({name:t.value},"Renamed")},"positive")]),setTimeout(()=>t.select(),50)}async remove(){let t=this.p;await ae(`Delete ${t.name}?`,`All ${t.devices.length} devices are disconnected immediately and the personal link stops working.`,"Delete",!0)&&await O(()=>P.personDelete(t.id),"Deleted")&&(location.href=Ze(t.server))}};var za=`: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-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-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}.dl-map .cbi-section,.dl-map .cbi-section-node{border:0!important;background:none!important;box-shadow:none!important;padding:0!important}.dl-map .table.cbi-section-table,.dl-map .cbi-section-table>.tbody,.dl-map .cbi-section-table>tbody{display:block!important;width:100%;border:0!important;background:none!important;box-shadow:none!important;border-radius:0!important}.dl-map .cbi-section-table-titles,.dl-map .cbi-section-table-descr,.dl-map .thead{display:none!important}.dl-map .cbi-section-table-row{display:flex!important;flex-wrap:wrap;align-items:flex-start;gap:12px 16px;margin:0 0 12px;padding:16px!important;background:var(--dl-card)!important;border:1px solid var(--dl-line)!important;border-radius:var(--dl-radius)!important;box-shadow:var(--dl-shadow)}.dl-map .cbi-section-table-row.dl-filtered{display:none!important}.dl-map .cbi-section-table-row:hover{background:var(--dl-card)!important}.dl-map .cbi-section-table-row>.td{display:block!important;border:0!important;padding:0!important;background:none!important;width:auto!important}.dl-map .cbi-section-table-row>.td:first-child{flex:1 1 26em;min-width:0}.dl-map .cbi-section-table-row>.td.cbi-section-actions{flex:0 0 auto;margin-left:auto}.dl-map .cbi-section-table-row>.td.cbi-section-actions>div{display:flex;flex-wrap:nowrap;gap:6px;justify-content:flex-end}.dl-map .cbi-section-table-row>.td.cbi-section-actions>div>*{margin:0!important;flex:0 0 auto}.dl-map .cbi-section-table-row>.td:before{display:none!important}.dl-map .cbi-section-table-row.placeholder{color:var(--dl-fg-muted);display:flex!important;justify-content:center;align-items:center;min-height:0!important;height:auto!important;padding:28px 16px!important;text-align:center}.dl-map .cbi-section-table-row.placeholder>*{position:static!important;padding:0!important;margin:0!important;border:0!important;flex:0 1 auto!important}.dl-map .cbi-section-table-row.dl-off .dl-card-name,.dl-map .cbi-section-table-row.dl-off .dl-avatar{opacity:.6}.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-meta{display:flex;flex-wrap:wrap;align-items:baseline;gap:2px 8px;margin:6px 0 0 44px;font-size:13px;line-height:20px;color:var(--dl-fg-muted);font-variant-numeric:tabular-nums}.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)}.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}.dl-search{min-width:240px}@media(max-width:640px){.dl-map .cbi-section-table-row>.td.cbi-section-actions{margin-left:0;width:100%!important}.dl-map .cbi-section-table-row>.td.cbi-section-actions>div{justify-content:flex-start;flex-wrap:wrap}.dl-meta,.dl-chips,.dl-quota{margin-left:0}.dl-btn-label{display:none}.dl-search{min-width:0;flex:1}}.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}#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-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)}.dl-srvtab i.dot.bad{background:var(--dl-bad)}.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}.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)}.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:-5px;bottom:-5px;width:20px;height:20px;border-radius:7px;background:var(--dl-card);box-shadow:0 0 0 1.5px 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.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-searchbtn{display:inline-flex!important;align-items:center;gap:6px}.dl-searchbtn kbd{font-size:11px;padding:1px 5px;border-radius:5px;background:var(--dl-soft);color:var(--dl-fg-muted);font-family:inherit}.dl-toolbar-end{display:flex;align-items:center;gap:8px;margin-left:auto;flex-wrap:nowrap;min-width:0}.dl-toolbar-end .dl-search{flex:0 1 300px;min-width:160px}@media(max-width:640px){.dl-toolbar-end{flex-wrap:wrap;width:100%}.dl-toolbar-end .dl-search{flex:1 1 100%}}.dl-healthstrip{display:flex;align-items:center;gap:8px 16px;flex-wrap:wrap;padding:9px 14px;margin:0 0 12px;border-radius:12px;border:1px solid color-mix(in srgb,var(--dl-warn) 45%,transparent);background:var(--dl-warn-wash);font-size:13px;color:var(--dl-fg-muted)}.dl-healthstrip.bad{border-color:color-mix(in srgb,var(--dl-bad) 45%,transparent);background:var(--dl-bad-wash)}.dl-healthstrip-title{display:inline-flex;align-items:center;gap:6px;font-weight:500;color:var(--dl-warn)}.dl-healthstrip.bad .dl-healthstrip-title{color:var(--dl-bad)}.dl-healthstrip-title .dl-icon{width:15px;height:15px}.dl-healthstrip-item{cursor:default}.dl-healthstrip a{margin-left:auto;font-size:12px;font-weight:500;color:var(--dl-fg);text-decoration:none;padding:3px 9px;border-radius:8px}.dl-healthstrip a:hover{background:var(--dl-soft)}.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-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-addrs{display:flex;flex-wrap:wrap;gap:6px;padding-top:12px;border-top:1px solid var(--dl-line);min-width:0}.dl-addr{all:unset;box-sizing:border-box;cursor:pointer;display:inline-flex;align-items:center;gap:6px;height:24px;padding:0 8px 0 6px;max-width:100%;border-radius:7px;background:var(--dl-soft);color:var(--dl-fg-muted);font:500 11.5px/1 var(--dl-mono)}.dl-addr .dl-icon{width:12px;height:12px;flex:0 0 auto;opacity:.8}.dl-addr span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.dl-addr:hover{background:var(--dl-soft-hover);color:var(--dl-fg)}.dl-addr:focus-visible{outline:2px solid var(--dl-ring);outline-offset:1px}.dl-addr.lan .dl-icon{color:var(--dl-accent);opacity:1}.dl-addr.wan .dl-icon{color:var(--dl-ok);opacity:1}.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-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}.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}.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-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)}.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-pill-dot{width:6px;height:6px;border-radius:50%;background:currentColor;display:inline-block}.dl-root kbd,.dl-pal kbd{font-family:var(--dl-mono);font-size:11px;line-height:16px;padding:0 6px;border-radius:4px;background:var(--dl-soft);color:var(--dl-fg-muted)}.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)}.dl-geomap{position:relative;border-top:1px solid var(--dl-line);background:var(--dl-soft)}.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.dot{width:8px;height:8px;border-radius:50%;background:var(--dl-fg-faint)}.dl-map-legend i.dot.ok{background:var(--dl-ok)}.dl-map-legend i.line{width:14px;height:2px;border-radius:2px;background:var(--dl-ok)}.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;width:18px;height:18px;display:inline-flex;align-items:center;justify-content:center;position:relative}.dl-mk-dot{width:12px;height:12px;border-radius:50%;background:#8f8f8f;box-shadow:0 0 0 3px #0000008c}.dl-mk.online .dl-mk-dot{width:14px;height:14px;background:#40c977}.dl-mk.online:before{content:"";position:absolute;inset:-9px;border-radius:50%;background:#40c97747;animation:dl-pulse 2s ease-out infinite}@keyframes dl-pulse{0%{transform:scale(.5);opacity:1}to{transform:scale(1.4);opacity:0}}@media(prefers-reduced-motion:reduce){.dl-mk.online:before{animation:none}}.dl-mk-home{width:22px;height:22px;border-radius:7px;background:#ededed;display:flex;align-items:center;justify-content:center;box-shadow:0 0 0 4px #ededed2e,0 2px 6px #00000080;color:#131313}.dl-mk-home-ic{width:13px;height:13px}.dl-popup{z-index:4}.dl-popup .maplibregl-popup-content{background:var(--dl-elevated);color:var(--dl-fg);border:1px solid var(--dl-line);border-radius:12px;padding:12px;box-shadow:var(--shadow-xl, 0 8px 16px -4px rgba(0,0,0,.4));font:inherit}.dl-popup .maplibregl-popup-tip{border-top-color:var(--dl-elevated)!important;border-bottom-color:var(--dl-elevated)!important}.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-mk.multi{width:26px;height:26px}.dl-mk-count{min-width:22px;height:22px;padding:0 6px;border-radius:999px;background:#8f8f8f;color:#0a0a0a;font:600 11px/22px var(--dl-mono);text-align:center;box-shadow:0 0 0 3px #0000008c;box-sizing:border-box}.dl-mk.online .dl-mk-count{background:#40c977}.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 -4px 0}.dl-pop-row{all:unset;cursor:pointer;display:flex;align-items:center;gap:8px;padding:5px 4px;border-radius:6px}.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}.maplibregl-ctrl-attrib{font-size:10px}.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}.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-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-map .cbi-section-create,.dl-map>.cbi-section>.cbi-button-add{display:none!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-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-map .cbi-section-table-row>.td:has(.dl-pcard){flex:1 1 100%;max-width:none!important;width:100%!important;margin:0!important}.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:color-mix(in srgb,var(--dl-ok) 6%,var(--dl-soft));border:1px dashed color-mix(in srgb,var(--dl-ok) 55%,transparent)}.dl-chip.live:hover{background:color-mix(in srgb,var(--dl-ok) 11%,var(--dl-soft))}.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)}.dl-map .cbi-section-table-row.dl-attn-row{border-color:color-mix(in srgb,var(--dl-warn) 35%,transparent)!important}@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-search{display:flex;align-items:center;gap:8px;height:34px;padding:0 10px 0 12px;border:1px solid var(--input, var(--dl-line));border-radius:999px;background:var(--input-bg, transparent);width:280px;max-width:100%;color:var(--dl-fg-faint);box-sizing:border-box;min-width:0}.dl-search-input{text-overflow:ellipsis;border:0!important;background:transparent!important;box-shadow:none!important;outline:none;flex:1;min-width:0;color:var(--dl-fg);font:inherit;font-size:13px;padding:0!important;height:32px!important}.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}.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-live{display:inline-flex;align-items:center;gap:8px;font-size:12px}.dl-live i.dot,.dl-dstat i.dot{width:6px;height:6px;border-radius:50%;background:var(--dl-fg-faint);display:inline-block}.dl-live i.dot.ok{background:var(--dl-ok);box-shadow:0 0 0 3px var(--dl-ok-wash)}.dl-live i.dot.warn{background:var(--dl-warn)}.dl-live i.dot.pulse{animation:dl-wait 1.6s ease-in-out infinite}@keyframes dl-wait{0%,to{box-shadow:0 0 0 0 var(--dl-warn-wash)}50%{box-shadow:0 0 0 6px transparent}}.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:baseline;gap:10px;padding:7px 0;border-top:1px solid var(--dl-line);font-size:13px;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}.dl-pal-overlay{position:fixed;inset:0;z-index:1000;background:var(--scrim, rgba(0,0,0,.5));display:flex;justify-content:center;align-items:flex-start;padding:12vh 16px 0}.dl-pal{width:min(640px,100%);background:var(--dl-elevated);color:var(--dl-fg);border-radius:16px;overflow:hidden;box-shadow:var(--shadow-menu, 0 16px 32px -8px rgba(0,0,0,.6));border:1px solid var(--dl-line)}.dl-pal-search{display:flex;align-items:center;gap:12px;height:56px;padding:0 16px;border-bottom:1px solid var(--dl-line);color:var(--dl-fg-faint)}.dl-pal-input{flex:1;border:0!important;background:transparent!important;box-shadow:none!important;outline:none;font:inherit;font-size:16px;color:var(--dl-fg);padding:0!important}.dl-pal-list{max-height:52vh;overflow:auto;padding:8px}.dl-pal-group{padding:8px 12px 4px;font-size:12px;font-weight:500;color:var(--dl-fg-faint)}.dl-pal-item{display:flex;align-items:center;gap:12px;min-height:40px;padding:0 12px;border-radius:8px;cursor:pointer;font-size:14px}.dl-pal-item.sel{background:var(--dl-soft-hover)}.dl-pal-item .dl-icon{color:var(--dl-fg-muted)}.dl-pal-label{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.dl-pal-ic{width:16px}.dl-pal-empty{padding:16px 12px;color:var(--dl-fg-muted);font-size:14px}.dl-pal-foot{display:flex;gap:16px;padding:10px 16px;border-top:1px solid var(--dl-line);font-size:12px;color:var(--dl-fg-faint)}.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>*+*{border-top:1px solid var(--dl-line)}.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-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-head{display:flex;align-items:center;gap:12px;padding:16px 20px}.dl-upd-head>.dl-stack{flex:1;min-width:0}.dl-upd-head>.dl-stack>b{font-size:15px;font-weight:500}.dl-upd-row{display:flex;align-items:center;justify-content:space-between;gap:16px;padding:12px 20px;border-top:1px solid var(--dl-line);min-height:40px}.dl-upd-row>.dl-stack{min-width:0}.dl-upd-name{font-size:14px}.dl-upd-row .dl-mono{font-size:11px}.dl-upd-row .dl-mono b{color:var(--dl-fg);font-weight:500}.dl-upd-row>.dl-pill,.dl-upd-row>button,.dl-upd-head>.dl-pill,.dl-upd-head>button{flex:none}.dl-upd-bad{color:var(--dl-bad)}.dl-upd-job>.dl-log,.dl-upd-job>.alert-message{margin:0 14px 14px}`;function wn(){let o=document.createElement("style");return o.dataset.dawnline="1",o.textContent=za,o}function De(o,t){return()=>{let n=new o,a={load:()=>n.load(),render:async i=>{let s=await n.render(i),r=document.createElement("div");return r.className="dl-root",r.append(wn(),s),r},addFooter(){return n.noFooter?document.createElement("div"):this.super("addFooter",[])}};return t||Object.assign(a,{handleSave:null,handleSaveApply:null,handleReset:null}),a}}var ys=De(at,!1),ks=De(He,!0),$s=De(at,!1),_s=De(vt,!1),Ms=De(wt,!1),Ls=De(mt,!1),Ss=De(bt,!1),Ts=De(xt,!1);return baseclass.extend({ activity: Ls, health: Ss, overview: ys, people: ks, person: Ms, server: $s, settings: _s, updates: Ts }); +`,cn(r,t)]:[cn(r,t)])),i=e("button",{type:"button",class:"dl-chipbtn",click:r=>{r.preventDefault(),t=!t,dom.content(i,[v(t?"x":"key"),t?"Hide key":"Show key"]),a()}},[v("key"),"Show key"]);a();let o=new Blob([s.conf]).size;return e("div",{class:"dl-stack gap8"},[e("div",{class:"dl-filecard"},[e("span",{class:"dl-filecard-ic"},".conf"),e("span",{class:"dl-stack"},[e("span",{class:"dl-mono dl-ellipsis"},s.filename),e("span",{class:"dl-sub"},`AmneziaWG · ${o} bytes · import it in the app`)]),z([v("download")," Download"],()=>fe(s.filename,s.conf,"application/octet-stream"),"positive")]),e("details",{class:"dl-params"},[e("summary",{},[v("chevron"),e("span",{},"Configuration"),e("span",{class:"dl-spacer"}),i,e("button",{type:"button",class:"dl-chipbtn",click:r=>{r.preventDefault(),de(s.conf,"Configuration copied")}},[v("copy"),"Copy"])]),n])])}async function Nt(s,t="file"){if(!s.has_private_key)return e("div",{class:"dl-hint"},"This device generated its own keys in the browser, so its full configuration only exists on that device.");let n=await en(s,`${s.server} · ${s.person} · ${s.name}`),a={qr:()=>e("div",{class:"dl-qr-pane"},[Ae(je(s.conf),"dl-qr"),e("span",{class:"dl-sub"},"Scan with AmneziaVPN or AmneziaWG on the device.")]),key:()=>e("div",{class:"dl-stack gap8"},[e("div",{class:"dl-linkbox"},[e("span",{class:"dl-mono"},n),z("Copy",()=>de(n,"Key copied"))]),e("span",{class:"dl-sub"},"AmneziaVPN → Add server → Insert key. Keep it private.")]),file:()=>pa(s)},i=e("div",{class:"dl-connect-body"}),o=e("div",{class:"dl-seg"}),r=l=>{o.querySelectorAll("button").forEach(d=>d.classList.toggle("on",d.dataset.id===l)),dom.content(i,a[l]())};for(let[l,d]of[["file","File"],["key","Key"],["qr","QR code"]])o.appendChild(e("button",{type:"button","data-id":l,click:()=>r(l)},d));return r(t),e("div",{class:"dl-stack gap12"},[o,i])}function ha(s,t,n,a){ht?.close();let i=e("aside",{class:"dl-drawer",role:"dialog","aria-modal":"true"},[e("div",{class:"dl-drawer-head"},[s,e("button",{type:"button",class:"dl-drawer-x","aria-label":"Close",click:()=>l()},v("x"))]),e("div",{class:"dl-drawer-body"},t),n?e("div",{class:"dl-drawer-foot"},n):""]),o=e("div",{class:"dl-drawer-overlay dl-root",click:g=>{g.target===o&&l()}},i),r=g=>{g.key==="Escape"&&!document.body.classList.contains("modal-overlay-active")&&l()};function l(){document.removeEventListener("keydown",r),o.classList.remove("open"),setTimeout(()=>o.remove(),220),ht===d&&(ht=null),a()}let d={close:l,panel:i};return document.addEventListener("keydown",r),document.body.appendChild(o),requestAnimationFrame(()=>o.classList.add("open")),ht=d,d}var pn={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 ua(s,t){let n=s.filter(a=>a.device===t&&pn[a.type]).reverse().slice(0,12);return n.length?e("div",{class:"dl-dev-log"},n.map(a=>{let[i,o,r]=pn[a.type],l=a.type==="connect"?[a.detail?e("span",{class:"dl-muted"},` from ${a.detail}`):"",a.where?e("span",{class:"dl-muted"},` · ${a.where}`):""]:a.type==="roam"?[e("span",{class:"dl-muted"},` · ${a.detail??""}`)]:a.type==="device_added"||a.type==="device_removed"||a.type==="device_keys"?[e("span",{class:"dl-muted"},be(a)==="portal"?" on the portal":be(a)==="admin"?" by you":"")]:[],d=new Date(a.ts*1e3);return e("div",{class:`dl-dev-log-row${be(a)==="admin"?" dl-ev-by-admin":""}`},[be(a)==="admin"?e("span",{class:"dl-ev-tile",title:"Done by you in LuCI"},v("admin")):e("span",{class:`dl-ev-tile ev ${i}`},v(r)),e("span",{class:"dl-row-main"},[e("span",{},o),...l]),e("span",{class:"dl-faint dl-nowrap",title:d.toLocaleString()},ce(a.ts))])})):e("div",{class:"dl-sub"},"No activity yet.")}function ga(s){return s.disabled?e("span",{class:"dl-dstat"},"Disabled"):s.online?e("span",{class:"dl-dstat ok"},"Connected"):s.handshake?e("span",{class:"dl-dstat"},`Last seen ${ce(s.handshake)}`):e("span",{class:"dl-dstat warn"},"Waiting for the first connection")}async function Ce(s,t,n,a){let i=await U(()=>N.deviceConfig(t.id));if(!i)return;let o=t,r=s,l=await Nt(i),d=e("div",{class:"dl-drawer-title"}),g=e("div",{}),f=e("div",{}),c=e("div",{},e("div",{class:"dl-sub"},"Loading…")),k=[],b=async()=>{let p=await N.events(5e3).catch(()=>null);p&&(k=p.events.filter(T=>T.device===o.id),dom.content(c,ua(p.events,o.id)))},R=()=>{let p=a?.points.find(m=>m.device===o.id&&m.ip===o.endpoint);dom.content(d,[e("span",{class:`dl-dcard-ic${o.online?" on":""}`},v(o.kind)),e("div",{class:"dl-stack"},[e("div",{class:"dl-title-row"},[e("h3",{},o.name),z([v("edit")],()=>V(),"neutral",{title:"Rename",class:"cbi-button cbi-button-neutral dl-icon-only sm"})]),e("span",{class:"dl-sub"},[`${r.name} · ${_e[o.kind]}`])])]);let T=o.spark.reduce((m,y)=>m+y,0);dom.content(g,e("div",{class:"dl-dstats"},[e("div",{class:"dl-dstats-cell wide"},[e("span",{class:"dl-metric-label"},"Status"),ga(o)]),e("div",{class:"dl-dstats-cell"},[e("span",{class:"dl-metric-label"},"This month"),e("b",{},K(o.month[0]+o.month[1])),e("span",{class:"dl-sub dl-mono"},`↓ ${K(o.month[1])} ↑ ${K(o.month[0])}`)]),e("div",{class:"dl-dstats-cell"},[e("span",{class:"dl-metric-label"},"Last 7 days"),e("b",{},K(T)),sn(o.spark,120,22)])])),dom.content(f,e("div",{class:"dl-kv2"},[dn("Tunnel address",o.address),o.hostname&&r.access!=="internet"?dn("Local address",o.hostname):"",o.endpoint?ut("Client IP",e("span",{},[o.endpoint,p?e("span",{class:"dl-muted"},` · ${[p.city,p.org].filter(Boolean).join(" · ")}`):""])):"",ut("Total",e("span",{class:"dl-kv-act"},[`↓ ${K(o.total[1])} · ↑ ${K(o.total[0])}`,e("button",{type:"button",class:"dl-linkbtn danger",click:()=>We("device",o.id,o.name,()=>setTimeout(Y,300))},"Reset")])),ut("Added",`${ca(o.created)} · ${o.created_by==="portal"?"from the portal":"by you"}`),ut("Public key",e("span",{class:"dl-mono dl-faint"},i.amnezia.client_pub_key?`${i.amnezia.client_pub_key.slice(0,16)}…`:"—"))])),dom.content(B,[z([v(o.disabled?"play":"pause"),o.disabled?" Enable":" Disable"],async()=>{await U(()=>N.deviceUpdate(o.id,void 0,!o.disabled),o.disabled?"Device enabled":"Device disabled")&&await Y()},"neutral",o.disabled?{}:{class:"cbi-button cbi-button-neutral dl-btn-warn"}),z([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;if(await U(()=>N.deviceRotate(o.id),"New keys generated")){n(),h.close();let y=await N.status(1),P=y.people.find(H=>H.id===r.id),O=P?.devices.find(H=>H.id===o.id);P&&O&&Ce(P,O,n,y.geo)}}),e("span",{class:"dl-spacer"}),z([v("trash")," Remove"],async()=>{await ae(`Remove ${o.name}?`,"The device is disconnected immediately and its configuration stops working.","Remove",!0)&&await U(()=>N.deviceDelete(o.id),"Device removed")&&(h.close(),n())},"negative")])},Y=async()=>{let p=await N.status(1).catch(()=>null),T=p?.people.find(y=>y.id===r.id),m=T?.devices.find(y=>y.id===o.id);!p||!T||!m||(r=T,o=m,a=p.geo,R(),n())},V=()=>{let p=e("input",{type:"text",class:"cbi-input-text",value:o.name,maxlength:48});ne(`Rename ${o.name}`,[e("div",{class:"cbi-value"},[e("label",{class:"cbi-value-title"},"Name"),e("div",{class:"cbi-value-field"},p)])],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",z("Save",async()=>{await U(()=>N.deviceUpdate(o.id,p.value,void 0),"Renamed")&&(J(),await Y())},"positive")]),setTimeout(()=>p.select(),50)},B=e("div",{class:"dl-drawer-actions"}),w=e("section",{class:"dl-dsec"},[e("div",{class:"dl-dsec-head"},[e("h4",{},"Connect")]),o.config_stale?e("div",{class:"dl-note warn"},[v("alert"),e("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.")]):"",l]),D=e("section",{class:"dl-dsec"},[e("div",{class:"dl-dsec-head"},[e("h4",{},"Activity"),e("div",{class:"dl-dsec-actions"},[e("button",{type:"button",class:"dl-linkbtn",click:()=>Le({people:[r]},k,"csv",o.id)},"Export"),e("button",{type:"button",class:"dl-linkbtn danger",click:()=>Te(`Clear ${o.name}'s activity`,`Removes events about ${o.name}.`,{device:o.id},b)},"Clear"),e("a",{href:`${L.url("admin/network/dawnline/diagnostics")}?tab=log`},"All activity")])]),c]),E=e("section",{class:"dl-dsec"},[e("div",{class:"dl-dsec-head"},e("h4",{},"Details")),f]),M=!o.handshake||o.config_stale,u=e("div",{class:"dl-stack gap16"},M?[g,w,E,D]:[g,E,D,w]);b();let $=window.setInterval(()=>{Y(),b()},8e3),h=ha(d,u,B,()=>clearInterval($));R()}function Fe(s,t){let n=e("input",{type:"text",class:"cbi-input-text",placeholder:_e.phone,maxlength:48}),a="phone",i=e("div",{class:"dl-kinds",role:"radiogroup","aria-label":"Type"},nn.map(r=>e("button",{type:"button",role:"radio",class:r===a?"on":"","aria-checked":r===a?"true":"false","data-kind":r,click:()=>{a=r,i.querySelectorAll("button").forEach(l=>{let d=l.dataset.kind===r;l.classList.toggle("on",d),l.setAttribute("aria-checked",d?"true":"false")}),n.placeholder=_e[r]}},[v(r),e("span",{},_e[r])]))),o=s.devices.length>=s.device_limit;ne(`Add a device for ${s.name}`,[o?e("p",{class:"dl-hint"},`${s.name} already has ${s.devices.length} of ${s.device_limit} devices. As admin you can still add one.`):"",e("div",{class:"dl-fld"},[e("span",{class:"dl-fld-label"},"Type"),i]),e("label",{class:"dl-fld"},[e("span",{class:"dl-fld-label"},"Name"),n])],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",z("Add device",async()=>{let r=n.value.trim()||n.placeholder.replace(/^e\.g\. /,""),l=await U(()=>N.deviceCreate(s.id,r,a));if(!l)return;J(),X(`${r} added`,"success",3e3),t();let d=await N.status(1),g=d.people.find(c=>c.id===s.id),f=g?.devices.find(c=>c.id===l.id);g&&f&&Ce(g,f,t,d.geo)},"positive")]),setTimeout(()=>n.focus(),50)}var Se=1080,Xe=1512,xe=96,ma="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif",fa="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",Ze=s=>s.replace(/[&<>"']/g,t=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[t]);function va(s,t,n){let a=new URL(n),i=a.pathname.slice(1),o=Math.min(92,Math.floor((Se-2*xe)/(.58*(4+s.name.length)))),r=Se-2*xe,l=392,d=40,g=je(n,2).replace("`${Y}`;return``+f(xe+82,xe+42,36,"#a3a3a3",Ze(t))+f(xe,276,o,"#ffffff",`Hi, ${Ze(s.name)}`,'font-weight="600"')+f(xe,340,40,"#8a8a8a",`Scan to connect to ${Ze(t)}`)+``+g+`${Ze(i)}`+f(Se/2,l+r+156,34,"#737373",Ze(a.host),'text-anchor="middle"')+""}async function ba(s){let t=new Image;t.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(s)}`,await t.decode();let n=document.createElement("canvas");return n.width=Se,n.height=Xe,n.getContext("2d").drawImage(t,0,0,Se,Xe),new Promise((a,i)=>n.toBlob(o=>o?a(o):i(new Error("Could not draw the card")),"image/png"))}async function et(s,t,n={}){if(!s.link){X("The personal portal is off. Turn it on in Settings.","warning");return}let a=s.link,i=await U(()=>ba(va(s,t,a)));if(!i)return;let o=new File([i],`${s.id}-invite.png`,{type:"image/png"}),r=URL.createObjectURL(i),l=navigator,d=!!l.canShare?.({files:[o]}),g=()=>{URL.revokeObjectURL(r),J()},f=d?z([v("link")," Share card"],async()=>{try{await l.share({files:[o],title:`Invite ${s.name}`})}catch{}},"positive"):z([v("download")," Download card"],()=>fe(o.name,i),"positive");ne(n.title??`Invite ${s.name}`,e("div",{class:"dl-invite"},[e("img",{src:r,alt:`Invite card for ${s.name}`}),e("div",{class:"dl-invite-side"},[e("p",{class:"dl-muted"},n.lead??`Send ${s.name} the card or the link. They open it, add their devices and connect — no account needed.`),e("button",{type:"button",class:"dl-invite-link",title:"Copy link",click:()=>de(a,"Personal link copied")},[e("span",{},a.replace(/^https:\/\//,"")),v("copy")]),...(s.links??[]).filter(c=>c!==a).map(c=>e("button",{type:"button",class:"dl-invite-link alt",title:"Copy this link",click:()=>de(c,"Link copied")},[e("span",{},c.replace(/^https?:\/\//,"")),e("span",{class:`dl-pill ${c.startsWith("http:")?"warn":""}`},c.startsWith("http:")?"HTTP":"Also"),v("copy")])),e("ol",{class:"dl-invite-steps"},[e("li",{},["Install ",e("b",{},"AmneziaVPN")," on the device"]),e("li",{},"Open the link or scan the code"),e("li",{},"Add the device and connect")]),e("div",{class:"dl-invite-actions"},[f,z([v("copy")," Copy link"],()=>de(a,"Personal link copied"))])])]),[e("button",{class:"cbi-button cbi-button-neutral",click:g},"Done")],"wide")}var xa={active:"",paused:"pause",paused_all:"pause",expired:"calendar",quota:"chart",hours:"clock",no_server:"alert"};function zt(s){if(s.state==="active")return"";let t=e("span",{class:`dl-ibadge ${ka(s)}`,"aria-label":Tt[s.state]},v(xa[s.state]||"alert"));return le(t,()=>[e("div",{class:"dl-tip-title"},Tt[s.state])]),t}function wa(s){let t=s.devices.length,n=Math.max(1,s.device_limit,t),a=Math.min(160,n*22+(n-1)*3);return e("div",{class:"dl-slotbar",title:`${t} of ${s.device_limit} devices`},[e("span",{class:"dl-slotbar-segs",style:`width: ${a}px`},Array.from({length:n},(i,o)=>e("i",{class:o>=s.device_limit?"over":oe("span",{class:`dl-ibadge ${a}`},v(a==="lan"?"home":"globe"))));return le(n,()=>[e("div",{class:"dl-tip-title"},Oe[s.access]),s.access==="lan"&&s.services?.length?e("div",{class:"dl-muted"},`${s.services.length} home service${s.services.length===1?"":"s"} only`):""]),n}function ka(s){return s.state==="active"?"ok":s.state==="quota"||s.state==="expired"?"bad":"warn"}function $a(s,t){let n=s,i=e("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(o=>e("button",{type:"button",class:`dl-choice${o.v===n?" selected":""}`,"data-v":o.v,click:()=>{n=o.v,i.querySelectorAll(".dl-choice").forEach(r=>r.classList.toggle("selected",r.dataset.v===o.v)),t?.(o.v)}},[e("span",{class:"dl-choice-title"},[v(o.ic),Oe[o.v]]),e("span",{class:"dl-choice-text"},o.text)])));return{el:i,get:()=>n}}function _a(s){return`${s.getFullYear()}-${String(s.getMonth()+1).padStart(2,"0")}-${String(s.getDate()).padStart(2,"0")}`}function hn(s){let t=Ne(s.expires);return s.state==="quota"||s.state==="expired"||t!=null&&t<=Math.max(s.expire_warn,3)||!!s.quota_limit&&s.quota_used>=s.quota_limit*.9}function La(s){let t=s?new Date(`${s}T12:00:00`):new Date,n=t.getTime()t===new URLSearchParams(location.search).get("filter"))??"all";this.sort="seen";this.noFooter=!0;this.serverId=null;this.polling=!1;this.el=null;this.statusSeq=0;this.statusShown=0}async load(){return N.status(30)}scope(t){return this.serverId?lt(t,this.serverId):t}embed(t,n){return this.serverId=n,this.render(t)}person(t){return this.st.people.find(n=>n.id===t)}async latestStatus(){let t=++this.statusSeq,n=await N.status(30).catch(()=>null);return!n||te("em",{},n.servers.length?"No people yet. Add someone and send them their personal link.":"Set up the server first, then add people."),a.serverId&&(r.filter=l=>a.st.people.some(d=>d.id===l)),r.handleAdd=()=>a.openCreate(),r.handleRemove=l=>a.remove(l),r.renderRowActions=()=>e("div",{class:"dl-none"}),i=r.option(form.DummyValue,"_card"),i.modalonly=!1,i.textvalue=l=>a.renderCard(e("div",{class:"dl-card",id:`dl-card-${l}`}),l),o.render().then(l=>{l.classList.add("dl-map","dl-root");let d=e("select",{class:"dl-select","aria-label":"Sort",change:f=>{a.sort=f.target.value,a.decorate()}},[e("option",{value:"seen"},"Last seen"),e("option",{value:"name"},"Name"),e("option",{value:"usage"},"Usage")]),g=e("div",{class:"dl-root"},[a.serverId?"":e("div",{class:"dl-pagehead"},[e("div",{class:"dl-stack"},[e("h2",{class:"dl-h1"},"People"),e("span",{class:"dl-muted",id:"dl-people-count"},this.countText())]),n.servers.length?z([v("plus")," Add person"],()=>a.openCreate(),"add"):""]),n.servers.length?"":e("div",{class:"alert-message warning"},["No server yet. ",e("a",{href:L.url("admin/network/dawnline/server")},"Run the setup wizard")," before adding people."]),e("div",{class:"dl-toolbar"},[e("div",{class:"dl-seg",id:"dl-people-tabs",role:"tablist"}),e("div",{class:"dl-toolbar-end"},[d,a.serverId?z([v("plus")," Add person"],()=>a.openCreate(),"add"):""])]),l]);return this.el=g,requestAnimationFrame(()=>this.decorate()),this.polling||(this.polling=!0,poll.add(()=>a.el?.isConnected?a.poll():Promise.resolve(),10)),!un&&new URLSearchParams(location.search).get("add")&&(un=!0,setTimeout(()=>a.openCreate(),100)),g})}countText(){let t=this.st.totals;return`${t.people} ${t.people===1?"person":"people"} · ${t.devices} device${t.devices===1?"":"s"} · ${t.online} online`}decorate(){let t=document.getElementById("dl-people-count");t&&(t.textContent=this.countText());let n=this.st.people,a={all:n.length,online:n.filter(c=>c.online>0).length,attention:n.filter(hn).length,paused:n.filter(c=>c.state!=="active"&&c.state!=="quota"&&c.state!=="expired").length},i=document.getElementById("dl-people-tabs");if(i){let c={all:"All",online:"Online",attention:"Needs attention",paused:"Paused"};dom.content(i,Object.keys(c).map(k=>e("button",{type:"button",role:"tab",class:k===this.filter?"on":"",click:()=>{this.filter=k,this.decorate()}},[c[k],e("b",{class:k==="attention"&&a[k]?"warn":""},String(a[k]))])))}let o=c=>!(this.filter==="online"&&!c.online||this.filter==="attention"&&!hn(c)||this.filter==="paused"&&!(c.state!=="active"&&c.state!=="quota"&&c.state!=="expired")),r=[...n].sort((c,k)=>this.sort==="name"?c.name.localeCompare(k.name):this.sort==="usage"?k.month[0]+k.month[1]-(c.month[0]+c.month[1]):k.online-c.online||k.last_seen-c.last_seen),l=null,d=0;for(let c of r){let b=document.getElementById(`dl-card-${c.id}`)?.closest(".cbi-section-table-row");if(!b)continue;l??(l=b.parentElement),l?.appendChild(b),b.classList.toggle("dl-off",c.state!=="active"),b.classList.toggle("dl-attn-row",c.state==="quota"||c.state==="expired");let R=o(c);b.classList.toggle("dl-filtered",!R),R&&d++}let g=l?.closest(".cbi-section-table")??l,f=document.getElementById("dl-people-none");g&&n.length&&!d?(f??(f=e("div",{id:"dl-people-none",class:"dl-empty"})),dom.content(f,e("p",{},"No one here right now.")),f.parentElement!==g.parentElement&&g.after(f)):f?.remove()}async poll(){let t=await this.latestStatus();if(!t)return;let n=this.scope(t);this.st=n,this.paintCards(),this.decorate()}async quick(t,n,a){await U(()=>N.personUpdate(t.id,n),a)&&await this.poll()}renderCard(t,n){let a=this.person(n);if(!a)return dom.content(t,e("em",{},"Not saved yet — use “Save & Apply”.")),t;let i=Ne(a.expires),o=Math.max(0,a.device_limit-a.devices.length),r=[];if(a.expires){let c=i!=null&&i>=0&&i<=Math.max(a.expire_warn,3),k=i!=null&&i<0;r.push(e("span",{class:`dl-pill-ic${k?" bad":c?" warn":""}`,title:`Access ends ${$e(a.expires)}`},[v("calendar"),k?`ended ${$e(a.expires)}`:c?`ends in ${i} day${i===1?"":"s"}`:`until ${$e(a.expires)}`]))}a.hours&&r.push(e("span",{class:"dl-pill-ic",title:"Allowed hours"},[v("clock"),a.hours.replace("-","–")]));let l=st(a.devices).map(c=>e("button",{type:"button",class:`dl-chip${c.disabled?" disabled":""}${c.online?" live":""}`,title:`${_e[c.kind]} · ${c.address}${c.online?` · online from ${c.endpoint}`:c.handshake?` · seen ${ce(c.handshake,this.st.now)}`:""}`,click:k=>{k.preventDefault(),Ce(a,c,()=>this.refresh(),this.st.geo)}},[v(c.kind),e("span",{class:"dl-chip-name"},c.name),!c.handshake&&!c.disabled?e("span",{class:"dl-chip-tag"},"not set up"):""]));l.push(e("button",{type:"button",class:"dl-chip add","aria-label":"Add device",title:o>0?"Add device":"Add device · over the limit, admins can still add",click:c=>{c.preventDefault(),Fe(a,()=>this.refresh())}},v("plus")));let d=[];a.state==="quota"&&a.quota_period==="month"&&d.push(e("button",{type:"button",class:"dl-fix",click:()=>this.quick(a,{bonus_gb:String((a.bonus_gb||0)+10)},"+10 GB this month")},"+10 GB this month")),a.expires&&i!=null&&i<=Math.max(a.expire_warn,3)&&d.push(e("button",{type:"button",class:"dl-fix",click:()=>this.quick(a,{expires:La(a.expires)},"Extended by 1 month")},"Extend 1 month"));let g=we("more","More",c=>ye(c.currentTarget,[{label:"Open",icon:v("open"),run:()=>{location.href=ve(a.id)}},a.link?{label:"Invite card",icon:v("qr"),run:()=>et(a,this.st.servers.find(k=>k.id===a.server)?.name??"Home")}:null,o>0?{label:"Add device",icon:v("plus"),run:()=>Fe(a,()=>this.refresh())}: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,b,R)=>k||b>0&&R[b-1])),"neutral","dl-icon-only"),f=e("div",{class:"dl-pcard-actions"},[a.link?we("link","Copy link",()=>de(a.link,"Personal link copied"),"neutral","dl-icon-only"):"",g]);return dom.content(t,e("div",{class:"dl-pcard"},[e("div",{class:"dl-pcard-main"},[e("div",{class:"dl-pcard-top"},[e("span",{class:`dl-avatar${a.online?" online":""}`},ze(a.name)),e("div",{class:"dl-pcard-who"},[e("div",{class:"dl-card-head"},[e("a",{class:"dl-card-name",href:ve(a.id)},a.name),zt(a),ya(a),...r]),wa(a)])]),e("div",{class:"dl-chips"},l),d.length?e("div",{class:"dl-fixes"},d):""]),this.usageSide(a,f)])),t}usageSide(t,n){let a=t.quota_used||t.month[0]+t.month[1],i=t.quota_limit?Math.min(100,t.quota_used/t.quota_limit*100):0,o=t.devices.reduce((f,c)=>f+(c.spark[c.spark.length-1]??0),0),r=t.rate?.[t.rate.length-1],l=t.online&&r&&this.st.now-r[0]<180,d=e("div",{class:`dl-usebar${i>=100?" bad":i>=90?" warn":""}`});if(t.quota_limit){let f=e("i",{class:"fill"});f.style.width=`${i}%`,d.appendChild(f),le(d,()=>[e("div",{class:"dl-tip-title"},`${i.toFixed(1)}% used`),e("div",{class:"dl-muted"},`${K(t.quota_used)} of ${K(t.quota_limit)} · ${K(Math.max(0,t.quota_limit-t.quota_used))} left`),e("div",{class:"dl-faint"},t.quota_period==="total"?"In total":`This month${t.bonus_gb?` · includes +${t.bonus_gb} GB extra`:""}`)])}else{let f=t.devices.map(c=>({d:c,v:c.month[0]+c.month[1]})).filter(c=>c.v>0).sort((c,k)=>k.v-c.v);f.forEach((c,k)=>{let b=e("i",{class:`c${Math.min(k,4)}`});b.style.flexGrow=String(c.v),d.appendChild(b)}),f.length&&le(d,()=>[e("div",{class:"dl-tip-title"},"This month by device"),...f.map((c,k)=>e("div",{class:"dl-tip-row"},[e("span",{class:`dl-swatch c${Math.min(k,4)}`}),e("span",{},c.d.name),e("b",{},K(c.v))]))])}let g=t.quota_limit?`${K(Math.max(0,t.quota_limit-t.quota_used))} left`:"no limit";return e("div",{class:"dl-pside"},[e("div",{class:"dl-pside-top"},[l?e("span",{class:"dl-pside-state live"},"Online"):e("span",{class:"dl-pside-state"},t.online?"Online":t.last_seen?"Offline":"Never connected"),n]),e("div",{class:"dl-use-num"},[e("b",{class:a?"":"dl-faint"},K(a)),e("span",{class:"dl-faint"},t.quota_limit?`of ${K(t.quota_limit)}`:t.quota_period==="total"&&t.quota_gb?"in total":"this month")]),d,l?e("div",{class:"dl-use-live",title:"Right now"},[`↓ ${ke(r[2])}`,e("span",{class:"dl-faint"},`↑ ${ke(r[1])}`)]):e("div",{class:"dl-faint dl-pside-foot"},o?`today ${K(o)} · ${g}`:g)])}async togglePause(t){await U(()=>N.personPause(t.id,!t.paused),t.paused?`${t.name} resumed`:`${t.name} paused`)&&await this.refresh()}async remove(t){let n=this.person(t);await ae(`Remove ${n?.name??t}?`,`All ${n?.devices.length??0} devices are disconnected immediately and the personal link stops working. Usage history is kept in backups.`,"Remove",!0)&&await U(()=>N.personDelete(t),"Person removed")&&await this.refresh()}openCreate(){let t=this.st;if(!t.servers.length){X("Set up the server first.","warning");return}let n=e("input",{type:"text",class:"cbi-input-text",placeholder:"e.g. Myata",maxlength:48}),a=$a("internet"),i=e("input",{type:"number",class:"cbi-input-text",min:1,max:32,value:t.settings.default_device_limit}),o=e("input",{type:"date",class:"cbi-input-text"}),r=e("input",{type:"number",class:"cbi-input-text",min:0,step:"any",placeholder:"Unlimited"}),l=(c,k)=>e("button",{type:"button",class:"cbi-button cbi-button-neutral",click:()=>{if(!k)o.value="";else{let b=new Date;b.setMonth(b.getMonth()+k),o.value=_a(b)}}},c),d=t.servers[0],g=!this.serverId&&t.servers.length>1?e("select",{class:"cbi-input-select"},t.servers.map(c=>e("option",{value:c.id},c.name))):null,f=(c,k,b)=>e("div",{class:"cbi-value"},[e("label",{class:"cbi-value-title"},c),e("div",{class:"cbi-value-field"},[k,b?e("div",{class:"cbi-value-description"},b):""])]);ne("Add person",[f("Name",n),g?f("Server",g):"",e("div",{class:"cbi-value dl-block"},[e("label",{class:"cbi-value-title"},"Access"),e("div",{class:"cbi-value-field"},a.el)]),f("Devices",i,"How many devices they can add themselves."),f("End date",e("div",{class:"dl-actions"},[o,l("1 month",1),l("3 months",3),l("1 year",12),l("None",0)]),"Optional."),f("Monthly data (GB)",r,"Optional. They are paused when it runs out and resumed next month.")],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",z("Create and copy link",async()=>{let c=await U(()=>N.personCreate(n.value.trim(),"",g?.value??d.id,a.get(),Number(i.value)||t.settings.default_device_limit,o.value,Number(r.value)||0,"month"));c&&(c.link&&await de(c.link,"Personal link copied"),this.showCreated(c.id,n.value.trim(),c.link,t.servers.find(k=>k.id===(g?.value??d.id))?.name??d.name),await this.refresh())},"positive")]),setTimeout(()=>n.focus(),50)}showCreated(t,n,a,i){if(a){et({id:t,name:n,link:a},i,{title:`${n} is ready`,lead:`Send ${n} the card or the link. They open it, add their devices and connect — no account needed.`});return}ne(`${n} is ready`,[e("p",{},"Created. Turn on the personal portal in Settings to get a link, or add devices for them here.")],[e("button",{class:"cbi-button cbi-button-positive",click:J},"Done")])}};var Sa={https:"HTTPS for the portal",acme:"ACME certificates",home:"the home-like link"},Ma=300*1e3;async function tt(s,t,n){if(!t.length)return!0;if(!await ae(`Install ${Sa[s]}?`,`${t.join(", ")} from the OpenWrt feeds. Dawnline sets the rest up when they arrive.`,"Install"))return!1;let i=(await N.updatesStatus().catch(()=>null))?.job?.started??0;if(!await U(()=>N.updatesRun(`pkgs:${t.join(",")}`)))return!1;X(`Installing ${t.join(", ")}…`,"info",4e3);let o=Date.now()+Ma;for(;Date.now()setTimeout(d,2e3));let l=(await N.updatesStatus().catch(()=>null))?.job;if(!(!l||l.started===i||l.state==="running"))return l.state==="done"?(X(`${t.join(", ")} installed`,"success"),setTimeout(()=>n?.(),4e3),!0):(X(l.error??"Installation failed","error"),!1)}return X("Still installing: see Updates for the log.","warning"),!1}async function gn(s,t){let n=await U(()=>N.updatesStatus());return n?tt(s,n.needs?.[s]??[],t):!1}var Ea=[["wan","WAN"],["ethernet","Ethernet"],["wifi","Wi-Fi"],["vpn","VPN & tunnels"],["other","Other"]],Ta={wan:"globe",ethernet:"ethernet",bridge:"bridge",wifi:"wifi",vpn:"tunnel",other:"link"};function gt(s,t,n){let a=e("button",{type:"button",role:"switch",class:`dl-switch${s?" on":""}`,"aria-checked":s?"true":"false","aria-label":t,click:()=>{let i=!a.classList.contains("on");a.classList.toggle("on",i),a.setAttribute("aria-checked",i?"true":"false"),n(i)}},e("i"));return a}function mn(s,t="Interfaces"){let n=e("section",{class:"dl-setsec dl-ifcard"},e("div",{class:"dl-setsec-body"},e("p",{class:"dl-muted"},"Loading interfaces…"))),a,i=!0,o="",r=!0,l=!0,d=!0,g=new Set,f="",c=()=>JSON.stringify([l,d,i,i?"":o,r,[...g].sort()]),k=()=>a.detected.lan||a.saved.lan||"",b=()=>(i?a.detected.wan||a.saved.wan:o)||"",R=()=>new Map(a.devices.map(u=>[u.name,u])),Y=()=>{let u=R();return[...r&&k()?[k()]:[],...[...g].filter(h=>h!==k())].filter(h=>h!==b()).map(h=>u.get(h)??{name:h,nets:[],missing:!0})},V=(u,$)=>{a=u,$&&(i=u.config.auto_wan,o=u.config.wan_device||u.detected.wan||u.saved.wan||"",r=u.config.auto_lan,l=u.config.lan_like,d=u.config.device_mesh,g=new Set(u.config.lan_devices),f=c()),M()},B=async u=>{let $=await N.interfaces(s).catch(h=>(X(h.message,"error"),null));$&&V($,u)};function w(u){let $=r&&u.name===k(),h=u.name===b(),p=!$&&g.has(u.name),m=!(!!u.own||!!u.master||h||$)&&(u.nets.length>0||p||!!u.missing),y=(p||$)&&!u.zone&&!u.missing,P=u.missing?"Not present right now":u.own?"This server":u.master?`Port of ${u.master}`:h?`Internet${u.zone?` · zone ${u.zone}`:""}`:u.nets.length?u.nets.join(", "):"No IPv4 network",O=e("button",{type:"button",class:`dl-if${p?" sel":""}${$?" auto":""}${!m&&!p&&!$?" off":""}${y?" warn":""}`,"aria-pressed":p||$?"true":"false","aria-disabled":m?null:"true",click:()=>{m&&(g.has(u.name)?g.delete(u.name):g.add(u.name),M())}},[e("span",{class:"dl-if-ic"},v(Ta[u.kind]??"link")),e("span",{class:"dl-if-main"},[e("span",{class:"dl-if-name"},u.name),e("span",{class:"dl-if-sub"},P)]),$?e("span",{class:"dl-if-badge ok"},"Auto"):p?e("span",{class:"dl-if-check"},v("check")):""]);return le(O,()=>[e("div",{class:"dl-tip-title"},u.name),e("div",{class:"dl-muted"},[u.logical?`Interface ${u.logical}`:"No netifd interface",u.zone?` · zone ${u.zone}`:" · no firewall zone"]),u.members.length?e("div",{class:"dl-muted"},`Ports: ${u.members.join(", ")}`):"",u.nets.length?e("div",{class:"dl-mono"},u.nets.join(", ")):"",y?e("div",{class:"dl-warn"},"Not in a firewall zone: the firewall rejects this traffic."):"",u.master?e("div",{class:"dl-muted"},`Choose ${u.master} to include it.`):""]),O}function D(){let u=a.like_home;return!l||!a.config.lan_like?"":!a.needs?.length&&u.active&&u.bridged?"ok":"warn"}function E(){let u=a.like_home;return l?a.needs?.length?[e("span",{class:"dl-warn"},`Needs ${a.needs.join(" and ")}.`)," Until they are installed, internet traffic goes straight to the WAN."]:a.config.lan_like?u.active&&u.bridged?["Internet traffic enters ",e("span",{class:"dl-mono"},u.dev??"")," as ",e("span",{class:"dl-mono"},u.address??""),", so whatever handles home traffic (proxies, filters, DNS) handles it too."]:[e("span",{class:"dl-warn"},`Not working: ${u.error??"the link is down"}`)," Internet traffic goes straight to the WAN for now."]:["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."]}function M(){let u=e("select",{class:"cbi-input-select","aria-label":"Internet interface",change:P=>{o=P.target.value,M()}},a.devices.filter(P=>!P.own&&!P.master&&P.zone&&!P.missing).map(P=>e("option",{value:P.name,selected:P.name===o?"selected":null},`${P.name} · zone ${P.zone}`))),$=(P,O)=>{let H=Z=>e("span",{class:"dl-mono"},Z);return P?e("span",{},[" Now: ",H(P),...O&&O!==P?[", was ",H(O)]:[],"."]):e("span",{},O?[" Not found now: using ",H(O),"."]:[" Not found."])},h=Ea.map(([P,O])=>{let H=a.devices.filter(Z=>Z.category===P);return H.length?e("div",{class:"dl-ifgroup"},[e("h4",{},O),e("div",{class:"dl-ifgrid"},H.map(w))]):""}),T=Y().flatMap(P=>P.nets.map(O=>[O,P.name])),m=c()!==f,y=z("Save",async()=>{let P=await U(()=>N.serverInterfaces(s,i,i?"":o,r,[...g],l,d),"Interfaces saved");P&&(V(P,!0),P.nets_changed&&P.lan_only&&X(`${P.lan_only} ${P.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:!m});dom.content(n,[e("div",{class:"dl-setsec-body"},[e("div",{class:"dl-panel-head"},[e("h3",{},t),e("span",{class:"dl-spacer"}),z([v("reset")," Rescan"],()=>B(!1),"neutral",{title:"Read the interfaces again"})]),e("div",{class:"dl-setrow"},[e("div",{class:"dl-lh-main"},[e("span",{class:`dl-need-ic ${D()}`},v("home")),e("div",{class:"dl-stack"},[e("span",{class:"dl-setrow-label"},"Internet like a home device"),e("span",{class:"dl-sub"},E())])]),e("div",{class:"dl-setrow-ctl dl-if-wanctl"},[l&&a.needs?.length?z("Install",()=>tt("home",a.needs,()=>B(!1)),"positive"):"",gt(l,"Internet like a home device",P=>{l=P,M()})])]),e("div",{class:"dl-setrow"},[e("div",{class:"dl-lh-main"},[e("span",{class:"dl-need-ic"},v("link")),e("div",{class:"dl-stack"},[e("span",{class:"dl-setrow-label"},"Devices reach each other"),e("span",{class:"dl-sub"},"Devices of people with Home access can open connections to each other on this server, like home devices do. Internet-only people never.")])]),e("div",{class:"dl-setrow-ctl"},gt(d,"Devices reach each other",P=>{d=P,M()}))]),e("div",{class:"dl-setrow"},[e("div",{class:"dl-lh-main"},[e("span",{class:"dl-need-ic"},v("globe")),e("div",{class:"dl-stack"},[e("span",{class:"dl-setrow-label"},"Auto-detect WAN"),e("span",{class:"dl-sub"},["The interface with the default route: the server port opens there and Internet access leaves through it.",$(a.detected.wan,a.saved.wan)])])]),e("div",{class:"dl-setrow-ctl dl-if-wanctl"},[i?"":u,gt(i,"Auto-detect WAN",P=>{i=P,M()})])]),e("div",{class:"dl-setrow"},[e("div",{class:"dl-lh-main"},[e("span",{class:"dl-need-ic"},v("network")),e("div",{class:"dl-stack"},[e("span",{class:"dl-setrow-label"},"Auto-detect LAN"),e("span",{class:"dl-sub"},["Adds the detected LAN to the home network.",$(a.detected.lan,a.saved.lan)])])]),e("div",{class:"dl-setrow-ctl"},gt(r,"Auto-detect LAN",P=>{r=P,M()}))]),e("div",{class:"dl-iflead"},[e("b",{},"Home network"),e("span",{class:"dl-sub"},"What people with Home access can reach, and where their devices can be reached from. Click to add an interface; bridge ports and Wi-Fi in a bridge come with the bridge.")]),...h]),e("div",{class:"dl-setsec-foot"},[e("span",{class:"dl-sub dl-if-summary"},T.length?["Home access reaches ",...T.flatMap(([P,O],H)=>[H?", ":"",e("span",{class:"dl-mono"},P),` (${O})`]),l?" · Internet like a home device":b()?` · Internet via ${b()}`:""]:["No home network: Home access reaches nothing but this router.",b()?` Internet via ${b()}.`:""]),y])])}return B(!0),n}function Me(s,t,n){let a=e("button",{type:"button",role:"switch",class:`dl-switch${s?" on":""}`,"aria-checked":s?"true":"false","aria-label":t,click:()=>{let i=!a.classList.contains("on");a.classList.toggle("on",i),a.setAttribute("aria-checked",i?"true":"false"),n?.(i)}},e("i"));return a}var Ke=s=>s.classList.contains("on");function se(s,t={}){return e("input",{type:"text",class:"cbi-input-text",value:s,...t})}function Q(s,t,n){return e("div",{class:"dl-setrow"},[e("div",{class:"dl-stack"},[e("span",{class:"dl-setrow-label"},s),n?e("span",{class:"dl-sub"},n):""]),e("div",{class:"dl-setrow-ctl"},t)])}function Ve(s,t,n,a=""){return e("section",{class:`dl-setsec ${a}`},[e("div",{class:"dl-setsec-body"},[s?e("h3",{},s):"",...t]),n.length?e("div",{class:"dl-setsec-foot"},n):""])}function pe(s,t,n,a){return e("div",{class:"dl-group"},[e("div",{class:"dl-group-head"},[e("span",{class:"dl-group-ic"},v(s)),e("span",{class:"dl-stack"},[e("b",{},t),n?e("span",{class:"dl-sub"},n):""])]),e("div",{class:"dl-group-body"},a.filter(i=>i!==""))])}var fn=[["overview","Overview"],["people","People"],["connection","Connection"],["access","Access"],["disguise","Disguise"],["tunnel","Tunnel"]],Ca={general:"connection",network:"connection",interfaces:"access",advanced:"tunnel"},vn=[["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 Da(s){let t=g=>s[g]!=null&&s[g]!=="",n=vn.filter(([g])=>t(g));if(!n.length)return null;let a=(g,f)=>e("span",{class:"dl-pv"},[e("i",{},f),e("b",{},g==="header_protection_key"?`${s[g].slice(0,6)}••••`:s[g])]),i=(g,f,c,k)=>{let b=vn.filter(([R])=>k.includes(R)&&t(R));return b.length?e("div",{class:"dl-pgroup"},[e("div",{class:"dl-pgroup-head"},[v(f),e("b",{},g)]),e("p",{},c),e("div",{class:"dl-pvals"},b.map(([R,Y])=>a(R,Y)))]):""},o=Number(s.jc||0),r=(s.i1??"").includes("0x8580")?"A first packet shaped like a DNS answer.":"Extra packets sent before the handshake.",l=n.map(([g,f])=>`${f} = ${s[g]}`).join(` +`),d=e("div",{class:"dl-pgrid"},[i("Junk packets","zap",o?`${o} random packet${o===1?"":"s"} of ${s.jmin}–${s.jmax} bytes before each handshake.`:"No junk packets.",["jc","jmin","jmax"]),i("Padding","archive","Random bytes in front of handshake, cookie and data packets, so their sizes do not match WireGuard.",["s1","s2","s3","s4"]),i("Packet types","key","The values that replace WireGuard’s recognisable message types.",["h1","h2","h3","h4"]),i("Signatures","globe",r,["i1","i2","i3","i4","i5"]),i("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"]),i("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 e("details",{class:"dl-params"},[e("summary",{},[v("chevron"),e("span",{},"Current parameters"),e("span",{class:"dl-pcount"},String(n.length)),e("span",{class:"dl-spacer"}),e("button",{type:"button",class:"dl-linkbtn",click:g=>{g.preventDefault(),de(l,"Parameters copied")}},"Copy as config")]),d])}var Rt=(s,t)=>{let n=new URLSearchParams;s&&n.set("server",s),t&&t!=="overview"&&n.set("section",t);let a=n.toString();return`${L.url("admin/network/dawnline/server")}${a?`?${a}`:""}`},nt=class{constructor(){this.noFooter=!0;this.root=e("div",{class:"dl-root"});this.section="overview";this.srvId="";this.ov={};this.pp={};this.tabsEl=e("div",{});this.headEl=e("div",{});this.secEl=e("div",{});this.bodyEl=e("div",{class:"dl-srvbody"})}async load(){let t=await N.status(31),n=t.servers.length?null:await N.setupDefaults();return[t,n]}render([t,n]){if(this.st=t,!t.servers.length&&n)return this.wizard(n);let a=new URLSearchParams(location.search),i=a.get("section")??"",o=Ca[i]??i;return fn.some(([r])=>r===o)&&(this.section=o),this.srvId=(t.servers.find(r=>r.id===a.get("server"))??t.servers[0]).id,dom.content(this.root,[this.tabsEl,this.headEl,this.secEl,this.bodyEl]),this.paint(),poll.add(async()=>{if(this.section!=="overview")return;let r=await N.status(31).catch(()=>null);if(!r||!r.servers.length)return;this.st=r;let l=this.current();dom.content(this.headEl,this.head(l)),this.paintTabs(),this.ov[l.id]?.update(r)},10),this.root}current(){return this.st.servers.find(t=>t.id===this.srvId)??this.st.servers[0]}async refresh(){let t=await N.status(31).catch(()=>null);t&&(this.st=t,t.servers.length?this.paint():location.href=Rt())}paint(){this.paintTabs(),dom.content(this.headEl,this.head(this.current())),this.paintSections(),this.showSection(this.section)}paintTabs(){let t=this.current();dom.content(this.tabsEl,e("div",{class:"dl-srvtabs",role:"tablist","aria-label":"Servers"},[...this.st.servers.map(n=>e("button",{type:"button",role:"tab",class:`dl-srvtab${n.id===t.id?" on":""}`,"aria-selected":n.id===t.id?"true":"false",click:()=>{n.id!==this.srvId&&(this.srvId=n.id,this.paint())}},[e("i",{class:`dot ${n.up?"ok":"bad"}`}),e("b",{},n.name),e("span",{class:"dl-mono dl-faint"},`:${n.port}`)])),e("button",{type:"button",class:"dl-srvtab add",click:()=>this.addServer()},[v("plus"),"Add server"])]))}paintSections(){dom.content(this.secEl,e("div",{class:"dl-seg dl-srvsections",role:"tablist","aria-label":"Server"},fn.map(([t,n])=>e("button",{type:"button",role:"tab","data-section":t,class:t===this.section?"on":"","aria-selected":t===this.section?"true":"false",click:()=>this.showSection(t)},n))))}go(t,n){let a=this.pp[this.current().id];if(n&&a)a.filter=n,a.el&&a.decorate();else if(n){let i=this.pp[this.current().id]=new Ie;i.filter=n}this.showSection(t),window.scrollTo({top:0,behavior:"smooth"})}detachKept(){let t=[...Object.values(this.ov).map(n=>n.el),...Object.values(this.pp).map(n=>n.el)];for(let n of t)n&&this.bodyEl.contains(n)&&n.remove()}showSection(t){this.section=t,this.secEl.querySelectorAll("[data-section]").forEach(r=>{let l=r.dataset.section===t;r.classList.toggle("on",l),r.setAttribute("aria-selected",l?"true":"false")});let n=this.st,a=this.current(),o={overview:()=>{let r=this.ov[a.id];return r?(r.update(n),r.el):(this.ov[a.id]=new dt(a.id,(l,d)=>this.go(l,d))).mount(n)},people:()=>{var g,f;let r=this.pp[a.id];if(r?.el)return r.poll(),r.el;let l=e("div",{},e("p",{class:"dl-muted"},"Loading people…"));return((g=this.pp)[f=a.id]??(g[f]=new Ie)).embed(n,a.id).then(c=>{l.isConnected?dom.content(l,c):l.replaceChildren(c)}),l},connection:()=>this.connection(a),access:()=>this.access(a),disguise:()=>this.disguise(a),tunnel:()=>this.tunnel(a)}[t]();this.detachKept(),dom.content(this.bodyEl,o)}head(t){let n=this.st,a=(l,d)=>e("span",{class:"dl-addrbar-seg"},[v(l),...d]),i=`${t.endpoint||"—"}:${t.port}`,o=!t.enabled||n.settings.paused_all,r=e("div",{class:"dl-actions"},[o?z([v("play")," Turn on"],async()=>{n.settings.paused_all&&!await U(()=>N.pauseAll(!1))||(t.enabled?await this.refresh():await this.save(t,{enabled:"1"},"Server turned on"))},"positive"):""]);return e("div",{class:"dl-srvpagehead"},[e("div",{class:"dl-title-row"},[e("h2",{class:"dl-h1"},t.name),e("span",{class:`dl-pill ${t.enabled?t.up?"ok":"bad":"off"}`},t.enabled?t.up?"Running":"Not running":"Turned off"),n.settings.paused_all&&t.enabled?e("span",{class:"dl-pill warn"},"Off"):"",e("span",{class:"dl-spacer"}),r]),e("div",{class:"dl-addrbar"},[e("button",{type:"button",class:"dl-addrbar-seg main",title:"Copy address and port",click:()=>de(i,"Address copied")},[v("globe"),e("span",{class:"dl-mono"},i),v("copy")]),a("tunnel",[e("span",{class:"dl-mono"},t.ifname)]),a("network",[e("span",{class:"dl-mono"},t.subnet)]),t.up?a("clock",[`up ${tn(t.uptime)}`]):""])])}async save(t,n,a="Saved"){await U(()=>N.serverUpdate(t.id,n),a)&&await this.refresh()}connection(t){let n=se(t.name,{placeholder:"Home"}),a=se(t.endpoint,{placeholder:"vpn.example.com",class:"cbi-input-text dl-mono"}),i=se(String(t.port),{inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),o=se(t.dns.join(", "),{placeholder:"This router (recommended)",class:"cbi-input-text dl-mono"}),r=se(String(t.mtu??""),{placeholder:"1380",inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),l=se(String(t.keepalive??""),{placeholder:"25",inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"});return Ve("Connection",[e("p",{class:"dl-muted"},"How devices find this server, and what goes into their configuration."),pe("router","Server","What people see",[Q("Name",n,"Shown to people in their portal.")]),pe("globe","Devices connect to","Where the tunnel answers from the internet",[Q("Public address",a,"Hostname or IP of the router on the internet. A DDNS name keeps links working when your IP changes."),Q("UDP port",i,"Opened on the WAN firewall automatically.")]),pe("file","In every device configuration","Changing these marks devices “Update config” until they import again",[Q("DNS for devices",o,"Empty = this router, which sends each query where your home network would."),Q("MTU",r,"Lower it if some sites hang on mobile networks."),Q("Keep-alive",l,"Seconds between packets devices send to keep NAT open. 0 = off.")])],[e("span"),z("Save",()=>this.save(t,{name:n.value,endpoint:a.value,port:i.value,dns:o.value,mtu:r.value,keepalive:l.value}),"positive")])}access(t){let n=this.st.services;return e("div",{class:"dl-stack gap16"},[mn(t.id,"Access"),Ve("Home services",[e("p",{class:"dl-muted"},"People with Home-only access can be limited to these services instead of the whole home network (chosen per person). The list is shared by all servers."),e("div",{class:"dl-list"},n.length?n.map(a=>e("div",{class:"dl-row"},[v("home"),e("span",{class:"dl-row-main dl-stack"},[e("b",{},a.name),e("span",{class:"dl-mono dl-faint"},`${a.address}${a.ports.length?` · ports ${a.ports.join(", ")}`:" · all ports"}`)])])):[e("div",{class:"dl-row dl-muted"},"No services yet.")])],[e("span"),e("a",{class:"cbi-button cbi-button-neutral",href:`${L.url("admin/network/dawnline/settings")}#dl-set-services`},"Edit in Settings")])])}disguise(t){let n=qe(t.preset)?t.preset:void 0,a=n??"standard",i=z("",()=>this.applyDisguise(t,a,a===n),"positive"),o=()=>{dom.content(i,a===n?[v("reset")," Generate new values"]:`Switch to ${qe(a).title}`)};o();let r=Da(t.obf??{});return Ve("Disguise",[e("p",{class:"dl-muted"},"AmneziaWG reshapes the tunnel so networks that block VPNs do not recognise it. Every device gets these settings in its configuration."),Ct(this.st.awg,a,l=>{a=l,o()},n),this.st.awg.v3?"":De("info",["This router runs an older AmneziaWG. ",e("b",{},"Maximum")," becomes available with kmod-amneziawg and amneziawg-tools 3.1."]),r??""],[e("span",{class:"dl-sub"},"Applies at once. Every device on this server must import its configuration again."),i])}async applyDisguise(t,n,a){let i=qe(n),r=this.st.people.filter(d=>d.server===t.id).reduce((d,g)=>d+g.devices.length,0);await ae(a?"Generate new disguise values?":`Switch to ${i.title}?`,`${r} device${r===1?"":"s"} stop connecting until they import their configuration again (from their personal link or from you).${n==="max"?" They need an app with AmneziaWG 3.1.":""}`,a?"Generate and apply":"Switch and apply",!0)&&await U(()=>N.serverObfuscation(t.id,n),a?"New values applied":`${i.title} applied`)&&(X("Devices are marked “Update config” until they import again.","info",6e3),await this.refresh())}tunnel(t){let n=this.st.people.filter(i=>i.server===t.id).length,a=z(t.enabled?"Turn off":"Turn on",async()=>{t.enabled&&!await ae(`Turn off ${t.name}?`,`The tunnel stops and ${n} ${n===1?"person is":"people are"} disconnected until you turn it back on. Nothing is deleted.`,"Turn off",!0)||await this.save(t,{enabled:t.enabled?"0":"1"},t.enabled?"Server turned off":"Server turned on")},t.enabled?"negative":"positive");return e("div",{class:"dl-stack gap16"},[Ve("Tunnel",[e("p",{class:"dl-muted"},"Technical details. They are set when the server is created and rarely change."),Q("Interface",e("span",{class:"dl-mono"},`${t.ifname} · router ${t.address}`)),Q("Tunnel subnet",e("span",{class:"dl-mono"},t.subnet),"Device addresses come from it."),Q("Server public key",e("span",{class:"dl-keyrow"},[e("code",{class:"dl-mono"},t.public_key),z([v("copy")],()=>de(t.public_key,"Public key copied"),"neutral",{title:"Copy",class:"cbi-button cbi-button-neutral dl-icon-only sm"})]))],[]),Ve("Danger zone",[e("div",{class:"dl-setrow"},[e("div",{class:"dl-stack"},[e("span",{class:"dl-setrow-label"},t.enabled?"Turn off this server":"This server is off"),e("span",{class:"dl-sub"},t.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.")]),e("div",{class:"dl-setrow-ctl"},a)]),e("div",{class:"dl-setrow"},[e("div",{class:"dl-stack"},[e("span",{class:"dl-setrow-label"},"Remove server"),e("span",{class:"dl-sub"},`Removes the tunnel, its firewall rules and ${n} ${n===1?"person":"people"} with all their devices. A backup is made first.`)]),e("div",{class:"dl-setrow-ctl"},z([v("trash")," Remove"],()=>this.remove(t),"negative"))])],[],"danger")])}async addServer(){let t=await U(()=>N.setupDefaults());t&&dom.content(this.root,this.wizard(t,!0,()=>{dom.content(this.root,[this.tabsEl,this.headEl,this.secEl,this.bodyEl]),this.paint()}))}async remove(t){let n=this.st.people.filter(a=>a.server===t.id);ne(`Remove ${t.name}?`,[e("p",{},`This removes the tunnel, its firewall rules and ${n.length} ${n.length===1?"person":"people"} with all their devices. A backup is made first.`)],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",z("Remove",async()=>{J(),await U(()=>N.serverDelete(t.id),"Server removed")&&setTimeout(()=>{location.href=Rt()},800)},"negative")])}wizard(t,n=!1,a){let i={id:t.id,name:t.name,endpoint:t.endpoint,port:t.port,subnet:t.subnet,preset:"standard",portal:!1,portal_port:t.portal_port||8443,lan_like:!0,lan_zone:t.lan_zone,wan_zone:t.wan_zone},o=0,r=e("div",{class:"dl-wizard"}),l=(c,k={})=>{let b=se(String(i[c]),k);return b.addEventListener("input",()=>{i[c]=c==="port"||c==="portal_port"?Number(b.value):b.value.trim()}),b},d=n?["Connection","Disguise"]:["Connection","Disguise","Portal"],g=[()=>e("div",{class:"dl-wizard-groups"},[e("p",{class:"dl-muted"},"Where devices connect to. A hostname that always points at your router (DDNS) keeps links working when your IP changes."),pe("router","Server","What people see",[Q("Name",l("name"),"Shown to people in their portal.")]),pe("globe","Devices connect to","Where the tunnel answers from the internet",[Q("Public address",l("endpoint",{placeholder:"vpn.example.com",class:"cbi-input-text dl-mono"}),"Hostname or IP address of your router on the internet."),Q("UDP port",l("port",{inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),"Opened on the WAN firewall automatically. A random high port is fine.")]),pe("network","Tunnel network","Addresses devices get inside the tunnel",[Q("Tunnel subnet",l("subnet",{class:"cbi-input-text dl-mono"}),`Must not overlap your networks (${t.taken.join(", ")||"none found"}).`)])]),()=>e("div",{},[e("p",{},"AmneziaWG reshapes the tunnel so networks that block VPNs do not recognise it. Every device gets these settings automatically; you can change the method later."),Ct(t.awg,i.preset,c=>i.preset=c)]),()=>{let c=l("portal_port",{inputmode:"numeric",class:"cbi-input-text dl-w-port dl-mono"}),k=Q("Listening port",c,"TCP port on WAN for the portal; the whole port belongs to it.");k.hidden=!i.portal;let b=e("div",{class:"dl-seg",role:"radiogroup","aria-label":"Personal portal"},["off","on"].map(R=>e("button",{type:"button",role:"radio",class:R==="on"===i.portal?"on":"","aria-checked":R==="on"===i.portal?"true":"false",click:Y=>{i.portal=R==="on",k.hidden=!i.portal,b.querySelectorAll("button").forEach(V=>{let B=V===Y.currentTarget;V.classList.toggle("on",B),V.setAttribute("aria-checked",B?"true":"false")})}},R==="on"?"On":"Off")));return e("div",{class:"dl-wizard-groups"},[pe("home","Internet like a home device","How devices reach the internet",[Q("Through the home network",Me(i.lan_like,"Internet like a home device",R=>i.lan_like=R),"Whatever handles home traffic on this router (proxies, filters, DNS) handles theirs too. Change it later under Servers → Access.")]),pe("link","Personal portal","A page where each person adds their own devices with their personal link",[Q("Portal",b,"Off: only you add devices, from LuCI. On: people manage their devices within the limits you set."),k])])}],f=()=>{dom.content(r,[e("h2",{},n?"Add a server":"Set up Dawnline"),e("div",{class:"dl-steps"},d.map((c,k)=>e("span",{class:`dl-step${k===o?" current":k0?z("Back",()=>{o--,f()}):a?z("Cancel",a):"",e("span",{class:"dl-spacer"}),o{if(o===0&&(!i.endpoint||!i.port||!i.subnet)){X("Fill in the public address, port and subnet.","warning");return}o++,f()},"positive"):z("Create server",async()=>{let c=await U(()=>N.serverCreate(i.id,i.name,t.ifname,i.port,i.subnet,i.endpoint,t.mtu,i.preset,i.lan_zone,i.wan_zone,i.lan_like,n?void 0:i.portal,n?void 0:i.portal_port),"Server created");c&&setTimeout(()=>{location.href=Rt(c.id)},1500)},"positive")])])};return f(),r}};var mt=300,Aa=["all","connections","people","system","problems"],Pa={info:"",up:"ok",down:"warn",repair:"warn",error:"bad"},Na={awg:"tunnel",dawnline:"sunrise",portal:"globe"};function za(s){let t=new Date(s*1e3),n=new Date,a=new Date;return a.setDate(n.getDate()-1),t.toDateString()===n.toDateString()?"Today":t.toDateString()===a.toDateString()?"Yesterday":t.toLocaleDateString("en-GB",{weekday:"long",day:"numeric",month:"long"})}function Ht(s){let t=s.keep_days>0?`${s.keep_days} day${s.keep_days===1?"":"s"}`:"no age limit",n=s.persist==="off"?"kept in memory only (lost on reboot)":`saved to flash ${s.persist==="10min"?"every 10 minutes":"hourly"}`;return`Kept for ${t}, up to ${s.max.toLocaleString("en-GB")} events, ${n}.`}var It=s=>s.sys?["error","repair","down"].includes(s.sys.level):ct(s.ev.type)==="problems";function Bt(s,t,n,a){let i=s.by==="admin",o=e("div",{class:`dl-row dl-slog-row ${i?"dl-ev-by-admin":`dl-ev-by-system ${Pa[s.level]??""}`}${s.detail?" has-detail":""}`},[i?e("span",{class:"dl-ev-tile",title:"Done by you in LuCI"},v("admin")):e("span",{class:"dl-ev-tile sys",title:s.level},v(Na[s.src]??"zap")),e("span",{class:"dl-row-main"},i?[e("span",{class:"dl-you"},"You"),e("span",{class:"dl-muted"},` ${s.msg} `),s.kind?e("span",{class:"dl-ev-kind"},`${s.kind} `):"",s.who?e("b",{},s.who):"",s.note?e("span",{class:"dl-muted"},` · ${s.note}`):"",s.detail?e("span",{class:`dl-slog-more${t?" open":""}`},v("chevron")):"",s.detail&&t?e("pre",{class:"dl-slog-detail"},s.detail):""]:[s.src==="awg"&&s.who&&s.who!=="AmneziaWG"?e("span",{class:"dl-ev-kind"},"Server "):"",e("b",{class:"dl-sys-src",title:pt[s.src]??s.src},s.who??pt[s.src]??s.src)," ",e("span",{class:"dl-muted"},s.msg),s.detail?e("span",{class:`dl-slog-more${t?" open":""}`},v("chevron")):"",s.detail&&t?e("pre",{class:"dl-slog-detail"},s.detail):""]),e("span",{class:"dl-faint dl-nowrap",title:new Date(s.ts*1e3).toLocaleString()},a)]);return s.detail&&o.addEventListener("click",r=>{r.target.closest("pre")||n()}),o}var ft=class{constructor(t,n,a){this.events=[];this.system=[];this.kind="all";this.shown=mt;this.open=new Set;this.list=e("div",{});this.sub="";this.tabs=e("div",{class:"dl-seg",role:"tablist"});this.st=t,this.take(n),this.system=a,this.el=e("div",{},[e("div",{class:"dl-toolbar"},[this.tabs]),this.list]),this.paint()}actions(){let t=()=>this.kind==="all"?"":this.kind,n=o=>()=>{let r=this.filtered().reverse();Le(this.st,r.filter(l=>l.ev).map(l=>l.ev),o,t(),r.filter(l=>l.sys).map(l=>l.sys))},a=z([v("download")," Export"],()=>ye(a,[{label:"CSV (spreadsheet)",icon:v("download"),run:n("csv")},{label:"JSON",icon:v("download"),run:n("json")}])),i=z([v("trash")," Clear"],()=>Te("Clear the log","Removes events from the log on the router.",{},()=>this.reload(),this.kind==="all"?void 0:this.kind,!0));return[a,i]}take(t){this.events=t.events,this.policy=t.policy;let n=Qe.filter(a=>!t.policy.categories.includes(a));this.sub=`${Ht(t.policy)}${n.length?` Not recorded: ${n.map(a=>Ge[a].toLowerCase()).join(", ")}.`:""}`}async reload(){let[t,n]=await Promise.all([N.events(2e4).catch(()=>null),N.serviceLog().catch(()=>null)]);t&&this.take(t),n&&(this.system=n.log),this.paint()}items(){return[...this.events.map(t=>({ts:t.ts,ev:t})),...this.system.map(t=>({ts:t.ts,sys:t}))].sort((t,n)=>n.ts-t.ts)}matches(t,n){return n==="all"?!0:n==="problems"?It(t):n==="system"?!!t.sys:!!t.ev&&ct(t.ev.type)===n}filtered(){return this.items().filter(t=>this.matches(t,this.kind))}paintTabs(t){dom.content(this.tabs,Aa.map(n=>e("button",{type:"button",role:"tab",class:n===this.kind?"on":"","aria-selected":n===this.kind?"true":"false",click:()=>this.show(n)},[n==="all"?"All":n==="system"?"System":Ge[n],e("b",{},String(t.filter(a=>this.matches(a,n)).length))])))}show(t){this.kind=t,this.shown=mt,this.paint()}paint(){this.paintTabs(this.items());let t=this.filtered();if(!t.length){dom.content(this.list,e("div",{class:"dl-empty"},[e("p",{},this.events.length||this.system.length?"No events match.":"The log is empty.")]));return}let n=[],a="",i=null;for(let o of t.slice(0,this.shown)){let r=za(o.ts);r!==a&&(a=r,i=e("div",{class:"dl-panel flush"},e("div",{class:"dl-panel-head pad"},e("h3",{},r))),n.push(i));let l=new Date(o.ts*1e3).toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"});if(o.sys){let d=`${o.sys.ts}|${o.sys.msg}`;i.appendChild(Bt(o.sys,this.open.has(d),()=>{this.open.delete(d)||this.open.add(d),this.paint()},l))}else{let d=He(this.st,o.ev);d.lastElementChild.textContent=l,i.appendChild(d)}}t.length>this.shown&&n.push(e("div",{class:"dl-more-row"},z(`Show ${Math.min(mt,t.length-this.shown)} more of ${t.length-this.shown}`,()=>{this.shown+=mt,this.paint()}))),dom.content(this.list,n)}};var Ra={manual:"Manual",auto:"Nightly","pre-restore":"Before restore","pre-import":"Before import","pre-delete":"Before removing a server","pre-update":"Before update"},bn=3;function jt(s){let t=new Date(s*1e3),n=t.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"}),a=Math.round((new Date(new Date().toDateString()).getTime()-new Date(t.toDateString()).getTime())/864e5);return`${a===0?"Today":a===1?"Yesterday":t.toLocaleDateString("en-GB",{day:"numeric",month:"short"})}, ${n}`}async function Ha(s){let t=await U(()=>N.backupRead(s.name));if(!t)return;let n=atob(t.data),a=new Uint8Array(n.length);for(let o=0;oHa(s),"neutral","dl-icon-only"),we("more","More",n=>ye(n.currentTarget,[{label:"Restore",icon:v("reset"),run:async()=>{await ae("Restore this backup?",`Everything returns to ${jt(s.created)}. The current state is backed up first.`,"Restore",!0)&&await U(()=>N.backupRestore(s.name),"Restored")&&t()}},{label:"Delete",icon:v("trash"),danger:!0,run:async()=>{await ae("Delete this backup?",`The backup from ${jt(s.created)} is removed from the router.`,"Delete",!0)&&await U(()=>N.backupDelete(s.name),"Backup deleted")&&t()}}]),"neutral","dl-icon-only")])])}function Ot(s,t){let n=s.slice(0,bn).map(d=>xn(d,t)),a=s.slice(bn),i=s.length?e("div",{class:"dl-list"},[...n,a.length?e("details",{class:"dl-bk-older"},[e("summary",{},[v("chevron"),`${a.length} older backup${a.length===1?"":"s"}`]),...a.map(d=>xn(d,t))]):""]):e("div",{class:"dl-list"},[e("div",{class:"dl-row dl-muted"},"No backups yet.")]),o=z("Restore from file",async()=>{let d=await Et(".tar.gz,.tgz,application/gzip","base64");if(!d)return;await ae("Restore from file?",`Replace the current Dawnline configuration with ${d.name}? The current state is backed up first.`,"Restore",!0)&&await U(()=>N.backupUpload(d.data),"Restored")&&t()}),r=z("Export JSON",async()=>{let d=await U(()=>N.exportJson());d&&fe(`dawnline-export-${new Date().toISOString().slice(0,10)}.json`,JSON.stringify(d,null,2),"application/json")}),l=z("Import JSON",async()=>{let d=await Et(".json,application/json","text");if(!d)return;let g;try{g=JSON.parse(d.data)}catch{X("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 U(()=>N.importJson(g),"Imported")&&t()});return e("section",{class:"dl-setsec",id:"dl-set-backups"},[e("div",{class:"dl-setsec-body"},[e("div",{class:"dl-setsec-head"},[e("div",{class:"dl-stack"},[e("h3",{},"Backups"),e("span",{class:"dl-sub"},"Nightly when something changed, and before every restore, import or update. The last 10 are kept.")]),e("span",{class:"dl-spacer"}),z([v("plus")," Back up now"],async()=>{await U(()=>N.backupCreate(),"Backup created")&&t()},"positive")]),i]),e("div",{class:"dl-setsec-foot"},[e("span",{class:"dl-sub"},"Backups contain private keys: keep downloads safe. JSON moves everything except usage history to another router."),e("span",{class:"dl-row-actions dl-bk-actions"},[o,r,l])])])}function at(s,t,n){s.some(([o])=>o===t)||(s=[...s,[t,t]]);let a=e("div",{class:"dl-seg sm",role:"radiogroup","aria-label":n,"data-value":t}),i=()=>dom.content(a,s.map(([o,r])=>e("button",{type:"button",role:"radio",class:o===a.dataset.value?"on":"","aria-checked":o===a.dataset.value?"true":"false",click:()=>{a.dataset.value=o,i()}},r)));return i(),a}function Ut(s,t,n=`${t}s`){return`${s.toLocaleString("en-GB")} ${s===1?t:n}`}function vt(s){return s<1024?`${s} B`:s<1048576?`${(s/1024).toFixed(s<10240?1:0)} KB`:`${(s/1048576).toFixed(1)} MB`}var bt=class{constructor(){this.root=e("div",{class:"dl-settings-main"});this.backups=[]}load(){return N.settingsGet()}render(t){return this.d=t,this.paint(),this.loadBackups().then(()=>{new URLSearchParams(location.search).get("section")==="backups"&&document.getElementById("dl-set-backups")?.scrollIntoView({block:"start"})}),e("div",{},[e("div",{class:"dl-pagehead"},[e("h2",{class:"dl-h1"},"Settings")]),this.root])}async save(t,n="Saved"){let a=await U(()=>N.settingsUpdate(t),n);a&&(this.d=a,this.paint())}section(t,n,a,i,o="",r=[]){return e("section",{class:`dl-setsec ${o}`,id:`dl-set-${t}`},[e("div",{class:"dl-setsec-body"},[r.length?e("div",{class:"dl-setsec-head"},[e("h3",{},n),e("span",{class:"dl-spacer"}),...r]):e("h3",{},n),...a]),i.length?e("div",{class:"dl-setsec-foot"},i):""])}portalSection(){let t=this.d.settings,n=this.d.effective,a=this.d.cert,i=this.d.portal_candidates??[],o=this.d.portal_checks??[],r=Me(n.portal_enabled,"Enable portal"),l=se(t.portal_port,{placeholder:"8443",inputmode:"numeric",class:"cbi-input-text dl-w-port"}),d=Me(n.portal_443,"Standard ports",()=>M()),g=se(t.portal_title,{placeholder:"Dawnline"}),f=se(t.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"}),k=I=>/^\d{1,3}(\.\d{1,3}){3}$/.test(I),b=[n.portal_host,...n.portal_alt??[]].filter((I,oe,_)=>I&&_.indexOf(I)===oe);!b.length&&i[0]&&(b=[i[0].host]);let R=[...i],Y=I=>{I&&!R.some(oe=>oe.host===I)&&R.push({host:I,kind:k(I)?"ip":"name",ips:[],here:!1,cloudflare:!1,cert:!1})};b.forEach(Y);let V=I=>I.kind==="ip"?e("span",{class:"dl-addr-warn"},[v("alert"),"Plain HTTP: the link and VPN keys travel unencrypted"]):e("span",{class:"dl-sub"},I.cloudflare?"Behind Cloudflare · often stalls in Russia":I.ips.length?I.here?`Points at this router${I.cert?" · Let’s Encrypt certificate":" · no certificate yet"}`:`Points at ${I.ips.join(", ")}, not this router`:"Your address"),B=e("div",{class:"dl-addr-opts",role:"group","aria-label":"Portal addresses"}),w=I=>{b.includes(I)?b.length>1&&(b=b.filter(oe=>oe!==I)):b=[...b,I],D(),M()},D=()=>dom.content(B,[...R.map(I=>{let oe=b.includes(I.host),_=b[0]===I.host;return e("div",{class:`dl-addr-opt${oe?" on":""}`,role:"checkbox","aria-checked":oe?"true":"false",tabindex:"0",click:()=>w(I.host),keydown:S=>{(S.key===" "||S.key==="Enter")&&(S.preventDefault(),w(I.host))}},[e("i",{class:"dl-addr-check"},oe?v("check"):""),e("span",{class:"dl-stack"},[e("span",{class:"dl-mono"},I.host),V(I)]),_?e("span",{class:"dl-pill info"},"Main"):oe?e("button",{type:"button",class:"dl-linkbtn",click:S=>{S.stopPropagation(),b=[I.host,...b.filter(x=>x!==I.host)],D(),M()}},"Make main"):I.cloudflare?e("span",{class:"dl-pill warn"},"Cloudflare"):I.kind==="ip"?e("span",{class:"dl-pill"},"IP"):I.here&&I.cert?e("span",{class:"dl-pill ok"},"Recommended"):""])}),e("div",{class:"dl-addr-opt other"},[e("i",{class:"dl-addr-check"},v("plus")),c,z("Add",()=>{let I=c.value.trim().toLowerCase();I&&(Y(I),b.includes(I)||(b=[...b,I]),c.value="",D(),M())})])]);c.addEventListener("keydown",I=>{I.key==="Enter"&&(I.preventDefault(),c.nextElementSibling?.click())});let E=e("div",{class:"dl-links"}),M=()=>{let I=Ke(d),oe=Number(l.value)||n.portal_port;dom.content(E,b.map((_,S)=>{let x=k(_),C=x?I?80:oe+1:I&&!this.d.wan443_taken?443:oe,A=`${x?"http":"https"}://${_}${C===(x?80:443)?"":`:${C}`}/`;return e("div",{class:"dl-link-row"},[e("span",{class:`dl-link-ic ${x?"warn":"ok"}`},v(x?"alert":"lock")),e("span",{class:"dl-mono dl-link-url"},[A,e("b",{},"kamiro-telosu-bavine")]),S===0?e("span",{class:"dl-pill info"},"Main"):x?e("span",{class:"dl-pill warn"},"HTTP"):""])}))};D(),M(),l.addEventListener("input",()=>M());let u={portal:"Portal running",portal_dns:"Points here",portal_reply:"Answers reach visitors",portal_443:"Port 443",portal_lan:"Works at home",portal_http:"Plain HTTP",cert:"Certificate"},$=o.filter(I=>I.status!=="skip"),h=$.filter(I=>I.status==="error"||I.status==="warn"),p=$.some(I=>I.status==="error")?"error":h.length?"warn":"ok",T=e("div",{class:"dl-ready-details",hidden:!0},$.map(I=>e("div",{class:`dl-ready-item ${I.status}`},[v(I.status==="ok"?"check":"alert"),e("span",{class:"dl-stack"},[e("span",{},I.title),e("span",{class:"dl-sub"},I.detail)])]))),m=e("div",{class:"dl-stack gap8"},[e("div",{class:`dl-ready-sum ${p}`},[v(p==="ok"?"check":"alert"),e("span",{class:"dl-stack"},[e("b",{},p==="ok"?`All ${$.length} checks passed`:`${$.length-h.length} of ${$.length} checks passed`),h.length?e("span",{class:"dl-sub"},h.map(I=>I.detail).join(" ")):e("span",{class:"dl-sub"},"Links will open for the people you send them to.")]),e("button",{type:"button",class:"dl-linkbtn",click:I=>{T.hidden=!T.hidden,I.currentTarget.textContent=T.hidden?"Details":"Hide"}},"Details")]),e("div",{class:"dl-chips-row"},$.map(I=>e("span",{class:`dl-check-chip ${I.status}`,title:I.detail},[v(I.status==="ok"?"check":"alert"),u[I.id]??I.title]))),T]),y=a&&!a.self_signed&&a.expires?new Date(a.expires).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"}):"",P=Q("Standard ports",d,this.d.wan443_taken?"Port 443 is already forwarded to another device, so HTTPS links keep the listening port.":"Links without a port: 443 for names, 80 for IP addresses. Mobile networks often drop other ports. From the internet these reach only the portal; LuCI stays closed."),O=Q("Listening port",l,this.d.port_owners.length?`Port ${n.portal_port} is used by ${this.d.port_owners.join(", ")}.`:`Where the portal runs on the router: HTTPS here, plain HTTP for IP addresses on ${n.portal_port+1}.`),H=!!(t.portal_cert&&t.portal_key),Z=a?H?"Your files":a.self_signed?"Self-signed":"Let’s Encrypt":"Portal is off",ee=()=>{let I=se(t.portal_cert,{placeholder:"/etc/ssl/…/fullchain.crt"}),oe=se(t.portal_key,{placeholder:"/etc/ssl/…/key"});ne("Use your own certificate",[e("p",{class:"dl-muted"},"Paths on the router. Leave both empty to pick a certificate automatically."),Q("Certificate file",I),Q("Key file",oe)],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",z("Save",()=>{J(),this.save({portal_cert:I.value.trim(),portal_key:oe.value.trim()},"Certificate saved")},"positive")])},ie=this.d.needs??{https:[],acme:[],home:[]},he=(I,oe,_,S,x,C)=>e("div",{class:`dl-row dl-need-row ${oe}`},[oe?e("span",{class:"dl-need-ic"},v(I)):v(I),e("span",{class:"dl-row-main dl-stack"},[e("b",{},_),e("span",{class:"dl-sub"},S)]),z(C,()=>tt(x,ie[x],()=>this.reload()),"positive")]),ue=ie.https.length?he("lock","bad","HTTPS isn’t available on this router",`The portal needs ${ie.https.join(" and ")}. It can’t start without them.`,"https","Install"):"",Ee=ie.acme.length&&(!a||a.self_signed)?he("lock","","Free certificate from Let’s Encrypt",`ACME isn’t installed. With it the router gets a certificate${t.portal_host?` for ${t.portal_host}`:""} and browsers stop warning.`,"acme","Install ACME"):"",$t=[e("div",{class:"dl-row"},[v("lock"),e("span",{class:"dl-row-main dl-stack"},[e("b",{},[Z,y?e("span",{class:"dl-faint"},` · until ${y}`):""]),e("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.":`${H?"Your files":"Found automatically"} · ${a.path}`:"Turn the portal on to see its certificate.")])]),e("div",{class:"dl-row"},[v("file"),e("span",{class:"dl-row-main dl-stack"},[e("b",{},"Your own files"),e("span",{class:"dl-sub"},H?`${t.portal_cert} · ${t.portal_key}`:"Not set: the certificate is picked automatically.")]),H?z("Reset",()=>this.save({portal_cert:"",portal_key:""},"Automatic certificate"),"negative"):"",z(H?"Change":"Use files",ee)]),Ee];return this.section("portal","Personal portal",[e("span",{class:"dl-muted"},"A page where each person adds and manages their devices with their personal link."),ue?e("div",{class:"dl-list"},[ue]):"",pe("network","Ports","How the portal listens",[P,O]),pe("edit","Appearance","What people see",[Q("Title",g,"Shown at the top of the portal."),Q("Unknown links",f,"Where a wrong or old link goes, for example your website. Empty shows a plain “Not found”.")]),pe("link","Addresses","Pick one or more; the first is the main link",[B,e("div",{class:"dl-stack gap8"},[E,e("span",{class:"dl-sub"},"Example code; each person gets their own three words.")])]),pe("lock","Certificate","Used for HTTPS links",$t),n.portal_enabled&&$.length?pe("check","Ready to share","The portal’s checks from Health",[m]):""],[e("span"),z("Save",()=>this.save({portal_enabled:Ke(r)?"1":"0",portal_443:Ke(d)?"1":"0",portal_host:b[0]??"",portal_alt:b.slice(1),portal_port:l.value,portal_title:g.value,portal_redirect:f.value.trim()}),"positive")],"",[n.portal_enabled?ie.https.length?e("span",{class:"dl-pill bad"},"Can’t start"):e("span",{class:`dl-pill ${p==="ok"?"ok":p==="error"?"bad":"warn"}`},p==="error"?"Needs attention":"Ready"):"",r])}paint(){let t=this.d.settings,n=this.d.effective,a=this.portalSection(),i=se(t.default_device_limit,{placeholder:"3",inputmode:"numeric",class:"cbi-input-text dl-w-port"}),o=Me(n.hostnames,"Device hostnames"),r=se(t.domain,{placeholder:"lan",class:"cbi-input-text dl-w-port"}),l=se(t.home_dns_fallback==="none"?"":t.home_dns_fallback||n.home_dns_fallback||"",{placeholder:"None",inputmode:"decimal",class:"cbi-input-text dl-w-ip dl-mono"}),d=this.section("defaults","Defaults",[Q("Devices per person",i,"Pre-filled when you add someone."),Q("Device hostnames",e("div",{class:"dl-hostport"},[o,e("span",{class:"dl-faint dl-mono"},"phone.myata."),r]),"Name devices in your home DNS."),Q("Fallback DNS",l,"For Home-only devices using home names: the second DNS server, used by the device when the tunnel is down. Empty = none.")],[e("span"),z("Save",()=>this.save({default_device_limit:i.value,hostnames:Ke(o)?"1":"0",domain:r.value,home_dns_fallback:l.value}),"positive")]),g=Me(n.geo_enabled,"Locations"),f=e("select",{class:"cbi-input-select"},[e("option",{value:"ipwho.is",selected:n.geo_provider!=="ipapi.co"?"selected":null},"ipwho.is (fallback: ipapi.co)"),e("option",{value:"ipapi.co",selected:n.geo_provider==="ipapi.co"?"selected":null},"ipapi.co (fallback: ipwho.is)")]),c=this.section("map","Map & locations",[e("div",{class:"dl-setrow head"},[e("span",{class:"dl-muted"},"Show where people connect from on the Overview and person pages, at city level."),g]),Q("Provider",f)],[e("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."),z("Save",()=>this.save({geo_enabled:Ke(g)?"1":"0",geo_provider:f.value}),"positive")]),k=this.logsSection(),b=this.d.services.map(B=>e("div",{class:"dl-row"},[v("home"),e("span",{class:"dl-row-main dl-stack"},[e("b",{},B.name),e("span",{class:"dl-mono dl-faint"},`${B.address}${B.ports.length?` · ports ${B.ports.join(", ")}`:" · all ports"}`)]),z("Edit",()=>this.editService(B)),z([v("trash")],async()=>{await ae(`Remove ${B.name}?`,"People limited to this service lose access to it.","Remove",!0)&&await U(()=>N.serviceDelete(B.id),"Removed")&&this.reload()},"negative",{title:"Remove"})])),R=this.section("services","Home services",[e("p",{class:"dl-muted"},"Give people with home-network access only specific services instead of the whole network (choose them per person)."),e("div",{class:"dl-list"},b.length?b:[e("div",{class:"dl-row dl-muted"},"No services yet.")])],[e("span"),z([v("plus")," Add service"],()=>this.editService(null),"add")]),Y=this.section("danger","Remove Dawnline from this router",[e("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.")],[e("span"),z("Remove",()=>this.uninstall(),"negative")],"danger"),V=Ot(this.backups,()=>{this.reload(),this.loadBackups()});dom.content(this.root,[a,d,c,k,R,V,Y])}logsSection(){let t=this.d.logs,n=t.policy,a=at([["7","7 days"],["30","30 days"],["90","90 days"],["365","1 year"],["0","No limit"]],String(n.keep_days),"Keep activity"),i=at([["500","500"],["2000","2,000"],["5000","5,000"],["20000","20,000"]],String(n.max),"Maximum events"),o=at([["10min","Every 10 min"],["hourly","Hourly"],["off","Memory only"]],n.persist,"Save to flash"),r=at([["31","1 month"],["62","2 months"],["180","6 months"],["365","1 year"],["730","2 years"]],String(n.usage_days),"Daily traffic"),l=at([["12","1 year"],["24","2 years"],["60","5 years"],["120","10 years"]],String(n.usage_months),"Monthly traffic"),d=new Set(n.categories),g=e("div",{class:"dl-chips-row"},Qe.map(R=>{let Y=e("button",{type:"button",class:`dl-chipbtn${d.has(R)?" on":""}`,title:ln[R],click:()=>{d.has(R)?d.delete(R):d.add(R),Y.classList.toggle("on",d.has(R))}},[Ge[R],e("b",{},String(t.by_category[R]??0))]);return Y})),f=R=>new Date(R).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"}),c=t.oldest?f(new Date(t.oldest*1e3)):"",k=(R,Y,V,B)=>e("div",{class:"dl-row"},[v(R),e("span",{class:"dl-row-main dl-stack"},[e("b",{},Y),e("span",{class:"dl-sub"},V)]),...B]),b=R=>z(R.toUpperCase(),async()=>{let[Y,V]=await Promise.all([N.status(1),N.events(2e4)]);Le(Y,V.events,R)},"neutral",{title:`Download the log as ${R.toUpperCase()}`});return this.section("logs","Logs & history",[e("p",{class:"dl-muted"},Ht(n)),Q("Keep activity",a,"Older events are removed automatically."),Q("Maximum size",i,"Newest events are kept when the log is full."),Q("Record",g,"Switched-off categories are not logged from now on."),Q("Save to flash",o,"The log lives in memory and is copied to flash. Memory only saves flash writes but is lost on reboot."),Q("Daily traffic",r,"Per-day history behind the charts."),Q("Monthly traffic",l,"Per-month totals; data limits use the current month."),e("h4",{class:"dl-setsub"},"Stored data"),e("div",{class:"dl-list"},[k("activity","Activity log",t.events?`${Ut(t.events,"event")} since ${c} · ${vt(t.log_ram)} in memory${n.persist==="off"?"":`, ${vt(t.log_flash)} on flash`}`:"Empty",[b("csv"),b("json"),z("Clear",()=>Te("Clear activity","Removes events from the log on the router.",{},()=>this.reload()),"negative")]),k("chart","Traffic history",t.usage_days?`${Ut(t.usage_days,"day")} since ${f(t.usage_since)} · ${vt(t.usage_flash)} on flash`:"Empty",[z("Reset",()=>We("all","","",()=>setTimeout(()=>this.reload(),300)),"negative")]),k("pin","Location cache",`${Ut(this.d.geo_cached,"address","addresses")} · ${vt(t.geo_flash)} on flash`,[z("Clear",async()=>{await U(()=>N.geoClear(),"Location cache cleared")&&this.reload()},"negative")])])],[e("span",{class:"dl-sub"},"Clear one person or device from their own page."),z("Save",()=>this.save({log_keep_days:a.dataset.value,log_max:i.dataset.value,log_persist:o.dataset.value,usage_keep_days:r.dataset.value,usage_keep_months:l.dataset.value,log_category:[...d]}),"positive")])}async loadBackups(){let t=await N.backupList().catch(()=>null);if(t){this.backups=t.backups;let n=document.getElementById("dl-set-backups");n&&n.replaceWith(Ot(this.backups,()=>{this.reload(),this.loadBackups()}))}}async reload(){let t=await N.settingsGet().catch(()=>null);t&&(this.d=t,this.paint())}editService(t){let n=se(t?.name??"",{placeholder:"NAS"}),a=se(t?.address??"",{placeholder:"192.168.1.10"}),i=se(t?.ports.join(", ")??"",{placeholder:"All ports, or e.g. 445, 5000"});ne(t?`Edit ${t.name}`:"Add service",[e("div",{class:"cbi-value"},[e("label",{class:"cbi-value-title"},"Name"),e("div",{class:"cbi-value-field"},n)]),e("div",{class:"cbi-value"},[e("label",{class:"cbi-value-title"},"Address"),e("div",{class:"cbi-value-field"},a)]),e("div",{class:"cbi-value"},[e("label",{class:"cbi-value-title"},"Ports"),e("div",{class:"cbi-value-field"},i)])],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",z("Save",async()=>{let o=i.value.split(/[ ,]+/).filter(Boolean);await U(()=>N.serviceSet(t?.id??"",n.value,a.value,o),"Saved")&&(J(),this.reload())},"positive")])}uninstall(){let t=se("",{placeholder:"remove"});ne("Remove Dawnline?",[e("p",{},"Everyone is disconnected and the tunnel, firewall rules and portal are removed. A backup is made first. Type “remove” to confirm."),t],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",z("Remove Dawnline",async()=>{await U(()=>N.uninstall(t.value.trim()),"Dawnline removed")&&(J(),setTimeout(()=>location.reload(),800))},"negative")])}};var Ia={ok:"check",warn:"alert",error:"x",skip:"pause"},wn={apply:"Repair",sync:"Reload devices",restart:"Restart service",updates:"Open updates"},xt=class{constructor(t,n,a,i){this.el=e("div",{});this.wdEl=e("div",{});this.checksEl=e("div",{class:"dl-panel"});this.recentEl=e("div",{class:"dl-panel flush dl-recent"});this.checks=null;this.summary=e("div",{});this.open=new Set;this.st=t,this.sl=n,this.events=a,this.toLog=i,dom.content(this.el,[this.summary,this.wdEl,e("div",{class:"dl-health-cols"},[this.checksEl,this.recentEl])]),this.paintChecks(),this.paintLive(n,a)}async run(t){let n=t?await U(()=>N.healthFix(t),"Done"):await N.health().catch(()=>null);n&&this.take(n)}take(t){this.checks=t.checks,this.paintChecks(),this.paintLive(t,this.events)}paintChecks(){let t=this.checks;if(!t){dom.content(this.summary,""),dom.content(this.checksEl,[e("div",{class:"dl-panel-head"},[e("h3",{},"Checks")]),e("p",{class:"dl-muted dl-loading"},"Running checks…")]);return}let n=t.filter(r=>r.status==="error").length,a=t.filter(r=>r.status==="warn").length;dom.content(this.summary,n?De("error",`${n} problem${n>1?"s":""} need attention.`):a?De("warn",`${a} warning${a>1?"s":""}.`):De("ok","All checks passed."));let i=new Map;for(let r of this.sl.watchdog.repairs)i.set(r.id,Math.max(i.get(r.id)??0,r.ts));let o=()=>this.run();dom.content(this.checksEl,[e("div",{class:"dl-panel-head"},[e("h3",{},"Checks"),e("span",{class:"dl-spacer"}),z("Run again",o)]),e("ul",{class:"dl-checks"},t.map(r=>e("li",{},[e("span",{class:`dl-check-icon ${r.status}`},v(Ia[r.status])),e("div",{class:"dl-check-body"},[e("div",{class:"dl-check-title"},r.title),e("div",{class:"dl-check-detail"},r.detail),i.has(r.id)?e("div",{class:"dl-check-repaired"},`Repaired by the watchdog at ${Pe(i.get(r.id))}`):""]),r.fix?r.fix.startsWith("install:")?z("Install",()=>gn(r.fix.slice(8),o),"action"):r.fix==="updates"?e("a",{class:"cbi-button cbi-button-action",href:L.url("admin/network/dawnline/updates")},wn.updates):z(wn[r.fix]??"Fix",()=>this.run(r.fix),"action"):""])))])}paintLive(t,n){this.sl=t,this.events=n;let a=t.watchdog,i=a.beat!=null&&a.now-a.beat>180,o=a.repairs.filter(d=>a.now-d.ts<86400),r=o[o.length-1],l=Me(a.enabled,"Watchdog repairs",async d=>{await U(()=>N.settingsUpdate({watchdog:d?"1":"0"}),d?"Watchdog on":"Watchdog off")||l.classList.toggle("on",!d);let f=await N.serviceLog().catch(()=>null);f&&this.paintLive(f,this.events)});dom.content(this.wdEl,e("div",{class:"dl-panel dl-wd"},[e("div",{class:"dl-wd-head"},[e("span",{class:`dl-wd-tile${a.enabled?"":" off"}`},v("shield")),e("div",{class:"dl-stack"},[e("span",{class:"dl-wd-title"},"Watchdog"),e("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.")]),e("span",{class:"dl-spacer"}),l]),e("div",{class:"dl-wd-foot"},[e("div",{class:"dl-wd-chips"},a.targets.map(d=>e("span",{class:`dl-check-chip${d.ok?"":" error"}`,title:d.ok?"OK":`Not working${d.tries?` · ${d.tries} repair${d.tries>1?"s":""}`:""}`},[v(d.ok?"check":"x"),d.name]))),e("span",{class:`dl-sub${i?" dl-warn-text":""}`},i?`The agent has not checked in for ${Math.round((a.now-a.beat)/60)} min; cron restarts it after 5.`:[a.last?`Looked ${ce(a.last,a.now)}`:"Starts within a minute"," · ",o.length?`${o.length} repair${o.length>1?"s":""} today, last ${r.name} at ${Pe(r.ts)}`:"no repairs today"])])])),this.paintRecent()}paintRecent(){let t=Date.now()/1e3-604800,n=[...this.events.map(i=>({ts:i.ts,ev:i})),...this.sl.log.map(i=>({ts:i.ts,sys:i}))].filter(i=>i.ts>=t&&It(i)).sort((i,o)=>o.ts-i.ts),a=e("div",{class:"dl-panel-head pad"},[e("h3",{},"Recent problems"),e("span",{class:"dl-spacer"}),n.length?e("a",{href:"#",click:i=>(i.preventDefault(),this.toLog())},"All in Log →"):""]);if(!n.length){dom.content(this.recentEl,[a,e("div",{class:"dl-recent-empty"},[e("span",{class:"dl-check-icon ok"},v("check")),"No problems in the last 7 days."])]);return}dom.content(this.recentEl,[a,...n.slice(0,8).map(i=>{if(i.sys){let r=i.sys,l=`${r.ts}|${r.msg}`;return Bt(r,this.open.has(l),()=>{this.open.delete(l)||this.open.add(l),this.paintRecent()},Pe(r.ts))}let o=He(this.st,i.ev);return o.lastElementChild.textContent=Pe(i.ts),o})])}},Ba=[{title:"ip-full · veth",sub:"Policy routing and the home-like link",pkgs:["ip-full","kmod-veth"],feature:"home"},{title:"OpenSSL",sub:"HTTPS for the personal portal",pkgs:["libustream-openssl","openssl-util"],feature:"https"},{title:"ACME",sub:"Let’s Encrypt certificate for the portal",pkgs:["acme","acme-acmesh-dnsapi"],feature:"acme",optional:!0}],wt=class{constructor(){this.running=!1}load(){return N.updatesStatus()}render(t){return this.root=e("div",{class:"dl-root dl-upd"}),this.paint(t),poll.add(async()=>{let n=await N.updatesStatus().catch(()=>null);n&&n.job?.state==="running"?this.paint(n):n&&this.running&&(this.running=!1,this.paint(n),n.job?.component==="app"&&n.job.state==="done"&&(ui.menu?.flushCache(),setTimeout(()=>location.reload(),1500)))},3),this.root}paint(t){let n=t.job;this.running=n?.state==="running";let a=t.check?.components??{},i=t.firmware,o=a.app,r=a.amneziawg,l=a.packages,d={disabled:this.running},g=(m,y)=>e("span",{class:`dl-pill ${m}`},y),f=(m,y,P)=>e("div",{class:"dl-upd-row"},[e("span",{class:"dl-stack"},[e("span",{class:"dl-upd-name"},m),e("span",{class:"dl-sub"},y)]),P]),c=(m,y,P,O,H=[])=>e("section",{class:"dl-setsec dl-upd-sec"},[e("div",{class:"dl-upd-head"},[e("span",{class:"dl-group-ic"},v(m)),e("span",{class:"dl-stack"},[e("b",{},y),e("span",{class:"dl-sub"},P)]),O]),...H]),k=m=>m?new Date(m).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"}):"",b=c("sunrise","Dawnline",o?.repo?`${t.version} · ${o.repo}`:t.version,o?o.update?z(`Update to ${o.latest}`,()=>this.run("app"),"positive",d):o.latest?g("ok","Up to date"):g("","No releases yet"):g("","Not checked")),R=r?.sources??{},V=Object.keys(R).map(m=>{let y=R[m],P=r?.current===m,O=[y.version?`${y.tag} build${y.date?` · ${k(y.date)}`:""} · ${y.gen==="3.1"?"devices need AmneziaVPN with 3.1":"works with every AmneziaWG app"}`:`No build for OpenWrt ${i?.version??""}`],H=y.version?P?r?.update?z("Update",()=>this.runAwg(m,!!r.ru,y.gen),"positive",d):g("ok","Installed"):z("Switch",()=>this.runAwg(m,!!r?.ru,y.gen),"neutral",d):g("","No build");return f([y.gen?`AmneziaWG ${y.gen}`:"AmneziaWG",e("span",{class:"dl-faint"},` · ${y.label}`)],O,H)});r?.current&&R[r.current]?.version&&V.push(f("Russian translation","LuCI pages for AmneziaWG in Russian",z(r.ru?"Remove":"Add",()=>this.runAwg(r.current,!r.ru,r.gen),"neutral",d)));let B=c("shield","AmneziaWG",r?.installed?`${r.gen?`${r.gen} · `:""}${r.installed} · changing it restarts every tunnel`:"Not installed",r?"":g("","Not checked"),V.length?V:[f("Builds for this router","Check for updates to see them.","")]),w=l?.pkgs??{},D=[],E=Ba.filter(m=>m.feature==="home"?t.home:t.portal);for(let m of E){let y=m.pkgs.filter(H=>w[H]?.installed),P=[...new Set(y.flatMap(H=>[...w[H]?.latest?[H]:[],...w[H]?.with??[]]))],O=t.needs?.[m.feature]??m.pkgs.filter(H=>!w[H]?.installed);if(O.length)D.push(f(m.title,m.optional?`Not installed · ${m.sub}`:e("span",{class:"dl-upd-bad"},`Missing ${O.join(", ")} · ${m.sub}`),z("Install",()=>this.runPkgs(O,m.title),"neutral",d)));else if(P.length){let H=y.find(ie=>w[ie]?.latest),Z=H?[e("span",{class:"dl-mono"},[`${w[H].installed} → `,e("b",{},w[H].latest)])]:[],ee=P.filter(ie=>ie!==H);ee.length&&Z.push(`${H?" · ":""}${ee.length<=2?`${H?"with ":""}${ee.join(", ")}`:`${H?"+":""}${ee.length} related packages`}`),D.push(f(m.title,Z,z("Update",()=>this.runPkgs(y.filter(ie=>w[ie]?.latest||w[ie]?.with?.length),m.title,P),"neutral",d)))}else D.push(f(m.title,m.sub,g("ok","Up to date")))}let M=E.flatMap(m=>m.pkgs).filter(m=>w[m]?.installed),u=[...new Set(M.flatMap(m=>[...w[m].latest?[m]:[],...w[m].with??[]]))],$=c("package","System packages",l?u.length?`${u.length} update${u.length===1?"":"s"} from the OpenWrt ${i?.version?.replace(/\.\d+$/,"")??""} feeds`:"What Dawnline adds to OpenWrt is current":"What Dawnline adds to OpenWrt",l?u.length?z("Update all",()=>this.runPkgs(M.filter(m=>w[m].latest||w[m].with?.length),"all packages",u),"positive",d):"":g("","Not checked"),l?D:[]),h=n?e("details",{class:"dl-params dl-upd-job",open:this.running?"open":null},[e("summary",{},[v("chevron"),e("span",{},"Last job"),g(n.state==="done"?"ok":n.state==="failed"?"bad":"warn",n.state==="running"?n.phase||"Running":n.state==="done"?"Finished":"Failed"),e("span",{class:"dl-sub"},`${n.action==="check"?"check":n.component??""} · ${Pe(n.started)}${n.finished?` · ${n.finished-n.started} s`:""}`)]),n.error?De("error",n.error):"",e("pre",{class:"dl-log"},n.log.join(` +`))]):"",p=u.length+(o?.update?1:0)+(r?.update?1:0),T=[i?.version?`OpenWrt ${i.version} · ${i.target}`:"",t.check?p?`${p} update${p===1?"":"s"} ready`:"everything is current":"not checked yet",t.check?`checked ${Pe(t.check.time)}`:""].filter(Boolean).join(" · ");dom.content(this.root,[e("div",{class:"dl-pagehead"},[e("div",{class:"dl-stack"},[e("h2",{class:"dl-h1"},"Updates"),e("span",{class:"dl-faint"},T)]),z([v("refresh")," Check now"],()=>this.run("check"),"neutral",d)]),b,B,$,h])}async runAwg(t,n,a){await ae(a?`Install AmneziaWG ${a}?`:"Install AmneziaWG?","Every AmneziaWG tunnel on the router restarts for a few seconds, HomeTunnel too. Devices stay configured.","Install")&&this.start(`amneziawg:${t}${n?":ru":""}`)}async runPkgs(t,n,a=t){await ae(`Update ${n}?`,`${a.join(", ")} from the OpenWrt feeds. Services that use them restart for a moment.`,"Update")&&this.start(`pkgs:${t.join(",")}`)}async run(t){t!=="check"&&!await ae(`Update ${t==="app"?"Dawnline":t}?`,"A backup is made first. The page reloads when it finishes.","Update")||this.start(t)}async start(t){if(await U(()=>N.updatesRun(t))){this.running=!0;let n=await N.updatesStatus().catch(()=>null);n&&this.paint(n)}}};function qt(s){return`${s.getFullYear()}-${String(s.getMonth()+1).padStart(2,"0")}-${String(s.getDate()).padStart(2,"0")}`}function ja(s,t,n,a=30){let i=s?new Date(`${s}T12:00:00`):new Date;return t==="day"?i.setDate(i.getDate()+n):t==="week"?i.setDate(i.getDate()+7*n):t==="month"?i.setMonth(i.getMonth()+n):t==="year"?i.setFullYear(i.getFullYear()+n):i.setDate(i.getDate()+a*n),qt(i)}var Oa={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."},yt=class{constructor(){this.id="";this.events=[];this.mapOpen=!1;this.map=null;this.parts={};this.series=[];this.devSeries={};this.refreshSeq=0;this.refreshShown=0}async load(){this.id=new URLSearchParams(location.search).get("id")??"";let[t,n,a]=await Promise.all([N.status(30),N.events(5e3).catch(()=>({events:[]})),N.personUsage(this.id,30).catch(()=>null)]);return this.series=a?.person??[],this.devSeries=a?.devices??{},[t,n.events]}render([t,n]){this.st=t,this.events=n;let a=t.people.find(l=>l.id===this.id);if(!a)return e("div",{class:"dl-empty"},[e("h3",{},"Person not found"),e("p",{},"They may have been removed."),e("a",{class:"cbi-button",href:L.url("admin/network/dawnline/server")},"Back to Servers")]);this.p=a;for(let l of["head","devices","traffic","places","activity","limits"])this.parts[l]=e("div",{});this.parts.devices.className="dl-person-devices";let i=e("div",{},[e("nav",{class:"dl-crumbs","aria-label":"Breadcrumb"},[e("a",{href:Je(a.server)},t.servers.find(l=>l.id===a.server)?.name??"Servers"),e("span",{},"/"),e("a",{href:Je(a.server)},"People"),e("span",{},"/"),e("span",{},a.name)]),this.parts.head,e("div",{class:"dl-grid-person"},[e("div",{class:"dl-col"},[this.parts.devices,this.parts.traffic,this.parts.places,this.parts.activity]),e("div",{class:"dl-col"},[this.parts.limits])])]);this.paint();let o=new URLSearchParams(location.search),r=o.get("device")&&a.devices.find(l=>l.id===o.get("device"));return r?setTimeout(()=>Ce(this.p,r,()=>this.refresh(),this.st.geo),50):o.get("add")&&setTimeout(()=>Fe(this.p,()=>this.refresh()),50),poll.add(()=>this.refresh(!0),15),i}async refresh(t=!1){let n=++this.refreshSeq,[a,i,o]=await Promise.all([N.status(30).catch(()=>null),N.events(5e3).catch(()=>null),N.personUsage(this.id,30).catch(()=>null)]);if(!a||nl.id===this.id);if(!r){t||(location.href=Je(this.p?.server));return}this.p=r,this.paint(),this.map?.update(this.mapData())}async patch(t,n){var o;let a=await U(()=>N.personUpdate(this.p.id,t),n);if(!a)return;let i=this.st.people.findIndex(r=>r.id===this.p.id);(o=a.person).rate??(o.rate=this.p.rate),i>=0&&(this.st.people[i]=a.person),this.p=a.person,this.paint()}mapData(){return{geo:this.st.geo,people:this.st.people,now:this.st.now,person:this.p.id}}mapCard(){let t=e("div",{class:"dl-panel-head pad"},[e("h3",{},"Locations"),e("span",{class:"dl-spacer"}),this.st.geo.enabled?rt("30d",n=>this.map?.setRange(n),!1):"",z("Hide",()=>{this.mapOpen=!1,this.map?.destroy(),this.map=null,this.paintPlaces()},"neutral")]);return this.st.geo.enabled?(this.map=new Ue({openPerson:()=>{},openDevice:(n,a)=>{let i=this.p.devices.find(o=>o.id===a);i&&Ce(this.p,i,()=>this.refresh(),this.st.geo)}},"30d",280),requestAnimationFrame(()=>this.map.mount(this.mapData())),e("div",{class:"dl-panel flush"},[t,this.map.el])):e("div",{class:"dl-panel flush"},[t,e("div",{class:"dl-map-off"},["Locations are off. ",e("a",{href:L.url("admin/network/dawnline/settings")},"Turn them on in Settings"),"."])])}paint(){let t=this.p,n=this.st,a=t.online?"online now":t.last_seen?`last seen ${ce(t.last_seen,n.now)}`:"never connected",i=this.series.find(c=>c.day===qt(new Date));dom.content(this.parts.traffic,e("div",{class:`dl-person-live${t.online?"":" solo"}`},[t.online?At(t.rate??[],n.now,i?[i.rx,i.tx]:[0,0]):"",Pt(this.series,`${K(t.month[0]+t.month[1])} this month`)]));let o=t.created?`Added ${$e(qt(new Date(t.created*1e3)))}`:"",r=[{label:"Rename",icon:v("edit"),run:()=>this.rename()},{label:t.note?"Edit note":"Add note",icon:v("file"),run:()=>this.editNote()},...t.link?[null,{label:"Invite card",icon:v("qr"),run:()=>this.invite()},{label:"New link",icon:v("key"),run:()=>this.newLink()}]:[],null,{label:t.paused?"Resume":"Pause",icon:v(t.paused?"play":"pause"),warn:!t.paused,run:()=>this.patch({paused:!t.paused},t.paused?"Resumed":"Paused")},{label:"Delete",icon:v("trash"),danger:!0,run:()=>this.remove()}];dom.content(this.parts.head,e("div",{class:"dl-person-head"},[e("div",{class:"dl-pagehead"},[e("div",{class:"dl-person-id"},[e("span",{class:`dl-avatar lg${t.online?" online":""}`},ze(t.name)),e("div",{class:"dl-stack"},[e("div",{class:"dl-title-row"},[e("h2",{class:"dl-h1"},t.name),zt(t)]),e("span",{class:"dl-faint",title:o},`${t.devices.length} of ${t.device_limit} devices · ${a}`)])]),e("div",{class:"dl-pcard-actions"},[t.link?we("link","Copy link",()=>de(t.link,"Personal link copied"),"neutral","dl-icon-only"):"",we("more","More",c=>ye(c.currentTarget,r),"neutral","dl-icon-only")])]),t.note?e("button",{type:"button",class:"dl-pnote",title:"Edit note",click:()=>this.editNote()},[v("file"),e("span",{},t.note)]):""])),this.paintDevices(),this.paintLimits(),this.paintPlaces();let l=this.events.filter(c=>c.person===t.id),d=[],g=[...l].reverse();for(let c=0;c1){let Y=R.querySelector(".dl-row-main");dom.content(Y,[...Dt(n,k).slice(0,3),e("span",{class:"dl-muted"},`${b} times`)]),Y.title=g.slice(c,c+b).map(V=>V.detail??"").join(` +`)}d.push(R),c+=b-1}let f=z([v("more")],()=>ye(f,[{label:"Export CSV",icon:v("download"),run:()=>Le(this.st,l,"csv",t.id)},{label:"Export JSON",icon:v("download"),run:()=>Le(this.st,l,"json",t.id)},null,{label:`Clear ${t.name}'s activity`,icon:v("trash"),danger:!0,run:()=>Te(`Clear ${t.name}'s activity`,`Removes events about ${t.name} and their devices.`,{person:t.id},()=>this.refresh())}]),"neutral",{title:"Export or clear",class:"cbi-button cbi-button-neutral dl-icon-only"});dom.content(this.parts.activity,e("div",{class:"dl-panel flush"},[e("div",{class:"dl-panel-head pad"},[e("h3",{},"Activity"),e("span",{class:"dl-sub"},l.length>10?`latest 10 of ${l.length}`:""),e("span",{class:"dl-spacer"}),f]),d.length?d:e("div",{class:"dl-row dl-muted"},"Nothing yet.")]))}deviceStatus(t){return t.disabled?e("span",{class:"dl-dstat"},"Disabled"):t.online?e("span",{class:"dl-dstat ok"},"Connected"):t.handshake?e("span",{class:"dl-dstat"},`Last seen ${ce(t.handshake,this.st.now)}`):e("span",{class:"dl-dstat warn",title:"Waiting for the first connection"},"Not set up yet")}deviceBars(t){let n=(this.devSeries[t]??[]).slice(-30),a=n.map(r=>r.rx+r.tx),i=Math.max(1,...a),o=r=>new Date(`${r}T12:00:00`).toLocaleDateString("en-GB",{day:"numeric",month:"short"});return e("div",{class:"dl-dbars"},n.map((r,l)=>{let d=e("i",{class:`${a[l]?"":"zero"}${l===n.length-1?" hi":""}`});return d.style.height=`${Math.max(8,a[l]/i*100)}%`,le(d,()=>[e("div",{class:"dl-tip-title"},l===n.length-1?`Today · ${o(r.day)}`:o(r.day)),e("div",{},K(a[l]))]),d}))}paintDevices(){let t=this.p,n=()=>this.refresh(),a=st(t.devices).map(o=>{let r=()=>Ce(t,o,n,this.st.geo);return e("article",{class:`dl-dcard${o.online?" online":""}${o.disabled?" off":""}`},[e("div",{class:"dl-dcard-head"},[e("span",{class:"dl-dcard-ic"},v(o.kind)),e("button",{type:"button",class:"dl-dcard-title",click:r},[e("b",{},o.name),this.deviceStatus(o),o.config_stale?e("span",{class:"dl-pill warn dl-stale"},"Update config"):""]),z([v("more")],r,"neutral",{title:`${o.name}: connect, rename, keys, remove`,class:"cbi-button cbi-button-neutral dl-icon-only"})]),o.handshake?e("div",{class:"dl-dcard-trend"},[e("div",{class:"dl-stack"},[e("b",{},K(o.month[0]+o.month[1])),e("span",{class:"dl-sub"},"this month")]),this.deviceBars(o.id)]):o.disabled?e("div",{class:"dl-sub"},`${_e[o.kind]} · created ${ce(o.created,this.st.now)} ${o.created_by==="portal"?"in the portal":"by you"}.`):e("div",{class:"dl-chips-row"},[e("button",{type:"button",class:"dl-chipbtn",click:()=>this.showDeviceQr(o)},[v("qr"),"Show QR"]),e("button",{type:"button",class:"dl-chipbtn",click:()=>this.downloadConfig(o)},[v("download"),"Config"])])])}),i=t.devices.length>=t.device_limit;a.push(e("button",{type:"button",class:"dl-dslot add",click:()=>Fe(t,n)},[e("span",{class:"dl-dslot-ic"},v("plus")),e("span",{class:"dl-stack"},[e("b",{},"Add device"),i?e("span",{class:"dl-sub"},`Over the limit · ${t.devices.length} of ${t.device_limit}`):""])])),dom.content(this.parts.devices,e("section",{class:"dl-devsec"},[e("div",{class:"dl-panel-head"},[e("h3",{},"Devices"),e("span",{class:"dl-sub"},`${t.online} online`)]),e("div",{class:"dl-dgrid"},a)]))}paintLimits(){let t=this.p,n=e("div",{class:"dl-seg wide",role:"radiogroup","aria-label":"Access"},["internet","lan","both"].map(h=>e("button",{type:"button",role:"radio",class:t.access===h?"on":"","aria-checked":t.access===h?"true":"false",click:()=>t.access!==h&&this.patch({access:h},`Access: ${Oe[h]}`)},[v(h==="internet"?"globe":h==="lan"?"home":"shield"),h==="internet"?"Internet":h==="lan"?"Home":"Both"]))),a=Ne(t.expires),i=e("input",{type:"date",class:"dl-date-hidden",value:t.expires,tabindex:"-1","aria-hidden":"true"});i.addEventListener("change",()=>i.value&&this.patch({expires:i.value},`Access until ${$e(i.value)}`));let o=(h,p,T)=>{let m=ja(t.expires&&(a??-1)>=0?t.expires:"",h,p);return this.patch({expires:m},`Access until ${$e(m)}`),T},r=[["week",1,"+1 week"],["month",1,"+1 month"],["month",3,"+3 months"],["year",1,"+1 year"]].map(([h,p,T])=>e("button",{type:"button",class:"dl-chipbtn",click:()=>o(h,p,T)},T)),l=e("span",{class:"dl-datechip"},[e("button",{type:"button",class:"dl-chipbtn",click:()=>{try{i.showPicker()}catch{i.focus()}}},[v("calendar"),t.expires?$e(t.expires):"Date"]),i]),d={pause:"pause access",notify:"keep access",remove:"remove their devices"}[t.expire_action],g=e("div",{class:"dl-tile2"},[e("div",{class:"dl-tile2-label"},[e("span",{},"Access ends"),t.expires?e("span",{class:a!=null&&a<0?"dl-bad":a!=null&&a<=t.expire_warn?"dl-warn":"dl-ok"},a!=null&&a<0?"ended":`${a} day${a===1?"":"s"} left`):e("span",{class:"dl-faint"},"no end date")]),e("div",{class:"dl-chips-row"},[...r,l,t.expires?e("button",{type:"button",class:"dl-chipbtn",click:()=>this.patch({expires:""},"No end date")},"No end"):""]),e("div",{class:"dl-tile2-foot"},[e("span",{class:"dl-muted"},`When it ends: ${d}${t.expire_warn?`, warn ${t.expire_warn} day${t.expire_warn===1?"":"s"} before`:""}`),e("a",{href:"#",click:h=>{h.preventDefault(),this.endSettings()}},"Change")])]),f=t.quota_used||t.month[0]+t.month[1],c=t.quota_limit?Math.min(100,t.quota_used/t.quota_limit*100):0,k=e("div",{class:`dl-meter${c>=100?" bad":c>=90?" warn":""}`},[e("i"),t.quota_limit?e("span",{class:"mark",title:"Alert at 90%"}):""]);k.firstChild.style.width=`${c}%`,t.quota_limit&&le(k,()=>[e("div",{class:"dl-tip-title"},`${c.toFixed(1)}% used`),e("div",{class:"dl-muted"},`${K(t.quota_used)} of ${K(t.quota_limit)} · ${K(Math.max(0,t.quota_limit-t.quota_used))} left`),e("div",{class:"dl-faint"},"Alert at 90%")]);let b=e("div",{class:"dl-seg sm"},["month","total"].map(h=>e("button",{type:"button",class:t.quota_period===h?"on":"",click:()=>t.quota_period!==h&&this.patch({quota_period:h})},h==="month"?"Monthly":"Total"))),R=[10,50,100].map(h=>e("button",{type:"button",class:`dl-chipbtn${t.quota_gb===h?" on":""}`,click:()=>this.patch({quota_gb:String(h)},`Data limit ${h} GB`)},`${h} GB`));R.push(e("button",{type:"button",class:`dl-chipbtn${t.quota_gb?"":" on"}`,click:()=>this.patch({quota_gb:""},"No data limit")},"Unlimited")),R.push(e("button",{type:"button",class:"dl-chipbtn",click:()=>{let h=prompt("Data limit in GB",t.quota_gb?String(t.quota_gb):"");h!=null&&h.trim()!==""&&Number(h)>0&&this.patch({quota_gb:h.trim()},`Data limit ${h.trim()} GB`)}},"Custom"));let Y=e("div",{class:"dl-tile2"},[e("div",{class:"dl-tile2-label"},[e("span",{},"Data"),b]),e("div",{class:"dl-tile2-row"},[e("span",{class:"dl-tile2-value"},[K(f),t.quota_limit?e("span",{class:"dl-faint"},` of ${K(t.quota_limit)}`):e("span",{class:"dl-faint"}," · no limit")]),t.quota_period==="month"?e("span",{class:"dl-sub"},"resets on the 1st"):""]),t.quota_limit?k:"",e("div",{class:"dl-chips-row"},R),t.quota_gb&&t.quota_period==="month"?e("div",{class:"dl-tile2-foot"},[e("span",{class:"dl-muted"},t.bonus_gb?`Includes +${t.bonus_gb} GB extra this month`:"Need a little more this month?"),e("a",{href:"#",click:h=>{h.preventDefault(),this.patch({bonus_gb:String((t.bonus_gb||0)+10)},"+10 GB this month")}},"+10 GB this month")]):"",e("div",{class:"dl-tile2-foot"},[e("span",{class:"dl-muted"},`${K(t.total[0]+t.total[1])} in total`),e("button",{type:"button",class:"dl-linkbtn danger",click:()=>We("person",t.id,t.name,()=>setTimeout(()=>this.refresh(),300))},"Reset usage")])]),V=!!t.hours,[B,w]=(t.hours||"07:00-23:00").split("-"),D=e("input",{type:"time",class:"cbi-input-text",value:B}),E=e("input",{type:"time",class:"cbi-input-text",value:w}),M=()=>this.patch({hours:`${D.value}-${E.value}`},`Allowed ${D.value}–${E.value}`);D.addEventListener("change",M),E.addEventListener("change",M);let u=e("button",{type:"button",role:"switch","aria-checked":V?"true":"false",class:`dl-switch${V?" on":""}`,"aria-label":"Limit hours",click:()=>this.patch({hours:V?"":"07:00-23:00"},V?"Any time":"Allowed 07:00–23:00")},e("i")),$=e("div",{class:"dl-tile2"},[e("div",{class:"dl-tile2-row"},[e("div",{class:"dl-stack"},[e("span",{class:"dl-tile2-label"},"Allowed hours"),e("span",{},V?`${B} – ${w} (router time)`:"Any time")]),u]),V?e("div",{class:"dl-tile2-row"},[D,e("span",{class:"dl-faint"},"to"),E]):""]);dom.content(this.parts.limits,e("section",{class:"dl-devsec","aria-label":"Access and limits"},[e("div",{class:"dl-panel-head"},[e("h3",{},"Access & limits")]),e("div",{class:"dl-panel"},[e("div",{class:"dl-stack gap8"},[e("span",{class:"dl-tile2-label"},"Can reach"),n,e("span",{class:"dl-sub"},Oa[t.access]),t.access==="lan"&&this.st.services.length?this.servicesPicker():"",t.access==="lan"?this.dnsPicker():""]),e("div",{class:"dl-tiles2"},[this.devTile(),g,Y,$])])]))}dnsPicker(){let t=this.p,n=e("div",{class:"dl-seg sm",role:"radiogroup","aria-label":"DNS"},[["device","Device’s own DNS"],["home","Home names"]].map(([i,o])=>e("button",{type:"button",role:"radio",class:t.dns_mode===i?"on":"","aria-checked":t.dns_mode===i?"true":"false",click:()=>t.dns_mode!==i&&this.patch({dns_mode:i},i==="home"?"Home names on — devices need their configuration again":"Device DNS — devices need their configuration again")},o))),a=this.st.settings.home_dns_fallback;return e("div",{class:"dl-stack gap4 dl-dnspick"},[e("div",{class:"dl-row-actions"},[e("span",{class:"dl-sub"},"DNS"),n]),e("span",{class:"dl-sub"},t.dns_mode==="home"?["Names like ",e("span",{class:"dl-mono"},`nas.${this.st.settings.domain}`)," work. Internet names are resolved at home, so they depend on the tunnel",a?[" (",e("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.")])}servicesPicker(){let t=new Set(this.p.services??[]);return e("div",{class:"dl-stack gap4"},[e("div",{class:"dl-chips-row"},this.st.services.map(n=>e("button",{type:"button",class:`dl-chipbtn${t.has(n.id)?" on":""}`,title:`${n.address}${n.ports.length?` · ${n.ports.join(", ")}`:""}`,click:()=>{t.has(n.id)?t.delete(n.id):t.add(n.id),this.patch({services:[...t]},t.size?"Home services updated":"Whole home network")}},n.name))),e("span",{class:"dl-sub"},t.size?"Only the selected services at home.":"Whole home network. Pick services to narrow it down.")])}devTile(){let t=this.p,n=e("div",{class:"dl-slots"});for(let o=0;o=t.device_limit,d=e("i",{class:l?"over":r?"used":""});le(d,()=>[e("div",{class:"dl-tip-title"},r?`${r.name}${l?" · over the limit":""}`:"Free slot"),e("div",{class:"dl-muted"},r?r.online?"Connected":r.handshake?`Last seen ${ce(r.handshake,this.st.now)}`:"Not set up yet":"They can add a device here")]),n.appendChild(d)}let a=Math.max(1,t.devices.length),i=e("button",{type:"button","aria-label":"Allow fewer devices",disabled:t.device_limit<=a?"disabled":null,click:()=>this.patch({device_limit:String(t.device_limit-1)})},"−");return t.device_limit<=a&&t.devices.length>1&&le(i,()=>[e("div",{class:"dl-tip-title"},`${t.devices.length} devices in use`),e("div",{class:"dl-muted"},"Remove a device first to lower the limit")]),e("div",{class:"dl-tile2"},[e("div",{class:"dl-tile2-label"},"Devices"),e("div",{class:"dl-tile2-row"},[e("span",{class:"dl-tile2-value"},[String(t.devices.length),e("span",{class:"dl-faint"},` / ${t.device_limit}`)]),e("div",{class:"dl-stepper"},[i,e("button",{type:"button","aria-label":"Allow more devices",disabled:t.device_limit>=32?"disabled":null,click:()=>this.patch({device_limit:String(t.device_limit+1)})},"+")])]),n])}paintPlaces(){let t=this.st;if(!t.geo.enabled){dom.content(this.parts.places,e("div",{class:"dl-places"},[v("pin"),e("div",{class:"dl-stack"},[e("span",{},"Locations are off"),e("span",{class:"dl-sub"},"City-level, from the client IP")]),e("span",{class:"dl-spacer"}),e("a",{class:"cbi-button cbi-button-neutral",href:L.url("admin/network/dawnline/settings")},"Turn on")]));return}if(this.mapOpen){(!this.map||!this.parts.places.contains(this.map.el))&&dom.content(this.parts.places,this.mapCard());return}let n=t.now-30*86400,a=t.geo.points.filter(r=>r.person===this.p.id&&r.ts>=n).sort((r,l)=>l.ts-r.ts),i=[...new Set(a.map(r=>r.city||r.country).filter(Boolean))],o=a[0];dom.content(this.parts.places,e("div",{class:"dl-places"},[v("pin"),e("div",{class:"dl-stack"},[e("span",{},o?o.city||o.country:"No locations yet"),e("span",{class:"dl-sub"},o?`${i.length} place${i.length===1?"":"s"} in 30 days${o.org?` · ${o.org}`:""}`:"Shown after a device connects")]),e("span",{class:"dl-spacer"}),a.length?z("Show map",()=>{this.mapOpen=!0,this.paintPlaces()},"neutral"):""]))}invite(){let t=this.st.servers.find(n=>n.id===this.p.server)?.name??"Home";et(this.p,t)}showQr(){let t=this.p;t.link&&ne(`${t.name}’s link`,[e("div",{class:"dl-qr-pane"},[Ae(je(t.link),"dl-qr"),e("div",{class:"dl-hint"},"Scan with the phone camera to open the portal.")])],[e("button",{class:"cbi-button",click:J},"Close")])}async newLink(){let t=this.p;if(!await ae("Create a new link?","The old link stops working right away.","Create new link",!0))return;let n=await U(()=>N.personRegen(t.id),"New link created");n?.link&&(t.link=n.link,de(n.link,"New link copied"),this.paint())}async showDeviceQr(t){let n=await U(()=>N.deviceConfig(t.id));n&&ne(`Set up ${t.name}`,[await Nt(n,"qr")],[e("button",{class:"cbi-button",click:J},"Close")])}async downloadConfig(t){let n=await U(()=>N.deviceConfig(t.id));if(n){if(!n.has_private_key){X("This device made its own keys in the browser; its configuration only exists there.","warning");return}fe(n.filename,n.conf,"application/octet-stream")}}editNote(){let t=e("textarea",{class:"cbi-input-textarea dl-note-input",rows:3,maxlength:500,placeholder:"Only you see this"},this.p.note??"");ne("Note",[t],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",z("Save",async()=>{J(),await this.patch({note:t.value.trim()},t.value.trim()?"Note saved":"Note removed")},"positive")]),setTimeout(()=>t.focus(),50)}endSettings(){let t=this.p,n=e("select",{class:"cbi-input-select"},[e("option",{value:"pause",selected:t.expire_action==="pause"?"selected":null},"Pause access"),e("option",{value:"notify",selected:t.expire_action==="notify"?"selected":null},"Keep access"),e("option",{value:"remove",selected:t.expire_action==="remove"?"selected":null},"Remove their devices")]),a=e("select",{class:"cbi-input-select"},[0,1,3,7,14].map(i=>e("option",{value:i,selected:t.expire_warn===i?"selected":null},i?`${i} day${i===1?"":"s"} before`:"Don’t warn")));ne("When access ends",[e("div",{class:"cbi-value"},[e("label",{class:"cbi-value-title"},"Then"),e("div",{class:"cbi-value-field"},n)]),e("div",{class:"cbi-value"},[e("label",{class:"cbi-value-title"},"Warn"),e("div",{class:"cbi-value-field"},[a,e("div",{class:"cbi-value-description"},"Shown in their portal and on the Overview.")])])],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",z("Save",async()=>{J(),await this.patch({expire_action:n.value,expire_warn:a.value},"Saved")},"positive")])}rename(){let t=e("input",{type:"text",class:"cbi-input-text",value:this.p.name,maxlength:48});ne("Rename",[e("div",{class:"cbi-value"},[e("label",{class:"cbi-value-title"},"Name"),e("div",{class:"cbi-value-field"},t)])],[e("button",{class:"cbi-button cbi-button-neutral",click:J},"Cancel")," ",z("Save",async()=>{J(),await this.patch({name:t.value},"Renamed")},"positive")]),setTimeout(()=>t.select(),50)}async remove(){let t=this.p;await ae(`Delete ${t.name}?`,`All ${t.devices.length} devices are disconnected immediately and the personal link stops working.`,"Delete",!0)&&await U(()=>N.personDelete(t.id),"Deleted")&&(location.href=Je(t.server))}};var Ua=[["health","Health"],["log","Log"]],kt=class{constructor(){this.tab=new URLSearchParams(location.search).get("tab")==="log"?"log":"health";this.segEl=e("div",{class:"dl-seg dl-srvsections dl-diag-tabs",role:"tablist","aria-label":"Diagnostics"});this.subEl=e("span",{class:"dl-muted"});this.actionsEl=e("div",{class:"dl-row-actions"});this.bodyEl=e("div",{})}load(){return Promise.all([N.status(1),N.events(2e4),N.serviceLog(),this.tab==="health"?N.health().catch(()=>null):Promise.resolve(null)])}render([t,n,a,i]){return this.log=new ft(t,n,a.log),this.health=new xt(t,a,n.events,()=>{this.show("log"),this.log.show("problems")}),i&&this.health.take(i),this.show(this.tab),poll.add(async()=>{if(!this.bodyEl.isConnected)return;let[o,r]=await Promise.all([N.serviceLog().catch(()=>null),N.events(2e4).catch(()=>null)]);r&&this.log.take(r),o&&(this.log.system=o.log),o&&this.health.paintLive(o,r?.events??this.health.events),this.tab==="log"&&(o||r)&&this.log.paint()},10),e("div",{},[e("div",{class:"dl-pagehead"},[e("div",{class:"dl-stack"},[e("h2",{class:"dl-h1"},"Diagnostics"),this.subEl]),this.actionsEl]),this.segEl,this.bodyEl])}show(t){this.tab=t;let n=new URL(location.href);t==="log"?n.searchParams.set("tab","log"):n.searchParams.delete("tab"),history.replaceState(null,"",n),dom.content(this.segEl,Ua.map(([a,i])=>e("button",{type:"button",role:"tab",class:a===t?"on":"","aria-selected":a===t?"true":"false",click:()=>a!==this.tab&&this.show(a)},i))),this.bodyEl.replaceChildren(t==="log"?this.log.el:this.health.el),this.subEl.textContent=t==="log"?this.log.sub:"Everything Dawnline depends on, checked live. The watchdog repairs what it can on its own.",dom.content(this.actionsEl,t==="log"?this.log.actions():""),t==="log"?this.log.paint():this.health.checks||this.health.run()}};var qa=`: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-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}.dl-map .cbi-section,.dl-map .cbi-section-node{border:0!important;background:none!important;box-shadow:none!important;padding:0!important}.dl-map .table.cbi-section-table,.dl-map .cbi-section-table>.tbody,.dl-map .cbi-section-table>tbody{display:block!important;width:100%;border:0!important;background:none!important;box-shadow:none!important;border-radius:0!important}.dl-map .cbi-section-table-titles,.dl-map .cbi-section-table-descr,.dl-map .thead{display:none!important}.dl-map .cbi-section-table-row{display:flex!important;flex-wrap:wrap;align-items:flex-start;gap:12px 16px;margin:0 0 12px;padding:16px!important;background:var(--dl-card)!important;border:1px solid var(--dl-line)!important;border-radius:var(--dl-radius)!important;box-shadow:var(--dl-shadow)}.dl-map .cbi-section-table-row.dl-filtered{display:none!important}.dl-map .cbi-section-table-row:hover{background:var(--dl-card)!important}.dl-map .cbi-section-table-row>.td{display:block!important;border:0!important;padding:0!important;background:none!important;width:auto!important}.dl-map .cbi-section-table-row>.td:first-child{flex:1 1 26em;min-width:0}.dl-map .cbi-section-table-row>.td.cbi-section-actions{flex:0 0 auto;margin-left:auto}.dl-map .cbi-section-table-row>.td.cbi-section-actions>div{display:flex;flex-wrap:nowrap;gap:6px;justify-content:flex-end}.dl-map .cbi-section-table-row>.td.cbi-section-actions>div>*{margin:0!important;flex:0 0 auto}.dl-map .cbi-section-table-row>.td:before{display:none!important}.dl-map .cbi-section-table-row.placeholder{color:var(--dl-fg-muted);display:flex!important;justify-content:center;align-items:center;min-height:0!important;height:auto!important;padding:28px 16px!important;text-align:center}.dl-map .cbi-section-table-row.placeholder>*{position:static!important;padding:0!important;margin:0!important;border:0!important;flex:0 1 auto!important}.dl-map .cbi-section-table-row.dl-off .dl-card-name,.dl-map .cbi-section-table-row.dl-off .dl-avatar{opacity:.6}.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-map .cbi-section-table-row>.td.cbi-section-actions{margin-left:0;width:100%!important}.dl-map .cbi-section-table-row>.td.cbi-section-actions>div{justify-content:flex-start;flex-wrap:wrap}.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}#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-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)}@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}.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)}.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:-5px;bottom:-5px;width:20px;height:20px;border-radius:7px;background:var(--dl-card);box-shadow:0 0 0 1.5px 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.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-healthstrip{display:flex;align-items:center;gap:8px 16px;flex-wrap:wrap;padding:9px 14px;margin:0 0 12px;border-radius:12px;border:1px solid color-mix(in srgb,var(--dl-warn) 45%,transparent);background:var(--dl-warn-wash);font-size:13px;color:var(--dl-fg-muted)}.dl-healthstrip.bad{border-color:color-mix(in srgb,var(--dl-bad) 45%,transparent);background:var(--dl-bad-wash)}.dl-healthstrip-title{display:inline-flex;align-items:center;gap:6px;font-weight:500;color:var(--dl-warn)}.dl-healthstrip.bad .dl-healthstrip-title{color:var(--dl-bad)}.dl-healthstrip-title .dl-icon{width:15px;height:15px}.dl-healthstrip-item{cursor:default}.dl-healthstrip a{margin-left:auto;font-size:12px;font-weight:500;color:var(--dl-fg);text-decoration:none;padding:3px 9px;border-radius:8px}.dl-healthstrip a:hover{background:var(--dl-soft)}.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-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-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}.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}.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)}.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)}.dl-geomap{position:relative;border-top:1px solid var(--dl-line);background:var(--dl-soft)}.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.dot{width:8px;height:8px;border-radius:50%;background:var(--dl-fg-faint)}.dl-map-legend i.dot.ok{background:var(--dl-ok)}.dl-map-legend i.line{width:14px;height:2px;border-radius:2px;background:var(--dl-ok)}.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;width:18px;height:18px;display:inline-flex;align-items:center;justify-content:center;position:relative}.dl-mk-dot{width:12px;height:12px;border-radius:50%;background:#8f8f8f;box-shadow:0 0 0 3px #0000008c}.dl-mk.online .dl-mk-dot{width:14px;height:14px;background:#40c977}.dl-mk.online:before{content:"";position:absolute;inset:-9px;border-radius:50%;background:#40c97747;animation:dl-pulse 2s ease-out infinite}@keyframes dl-pulse{0%{transform:scale(.5);opacity:1}to{transform:scale(1.4);opacity:0}}@media(prefers-reduced-motion:reduce){.dl-mk.online:before{animation:none}}.dl-mk-home{width:22px;height:22px;border-radius:7px;background:#ededed;display:flex;align-items:center;justify-content:center;box-shadow:0 0 0 4px #ededed2e,0 2px 6px #00000080;color:#131313}.dl-mk-home-ic{width:13px;height:13px}.dl-popup{z-index:4}.dl-popup .maplibregl-popup-content{background:var(--dl-elevated);color:var(--dl-fg);border:1px solid var(--dl-line);border-radius:12px;padding:12px;box-shadow:var(--shadow-xl, 0 8px 16px -4px rgba(0,0,0,.4));font:inherit}.dl-popup .maplibregl-popup-tip{border-top-color:var(--dl-elevated)!important;border-bottom-color:var(--dl-elevated)!important}.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-mk.multi{width:26px;height:26px}.dl-mk-count{min-width:22px;height:22px;padding:0 6px;border-radius:999px;background:#8f8f8f;color:#0a0a0a;font:600 11px/22px var(--dl-mono);text-align:center;box-shadow:0 0 0 3px #0000008c;box-sizing:border-box}.dl-mk.online .dl-mk-count{background:#40c977}.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 -4px 0}.dl-pop-row{all:unset;cursor:pointer;display:flex;align-items:center;gap:8px;padding:5px 4px;border-radius:6px}.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}.maplibregl-ctrl-attrib{font-size:10px}.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}.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-map .cbi-section-create,.dl-map>.cbi-section>.cbi-button-add{display:none!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-map .cbi-section-table-row>.td:has(.dl-pcard){flex:1 1 100%;max-width:none!important;width:100%!important;margin:0!important}.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)}.dl-map .cbi-section-table-row.dl-attn-row{border-color:color-mix(in srgb,var(--dl-warn) 35%,transparent)!important}@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}.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}.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>*+*{border-top:1px solid var(--dl-line)}.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-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-head{display:flex;align-items:center;gap:12px;padding:16px 20px}.dl-upd-head>.dl-stack{flex:1;min-width:0}.dl-upd-head>.dl-stack>b{font-size:15px;font-weight:500}.dl-upd-row{display:flex;align-items:center;justify-content:space-between;gap:16px;padding:12px 20px;border-top:1px solid var(--dl-line);min-height:40px}.dl-upd-row>.dl-stack{min-width:0}.dl-upd-name{font-size:14px}.dl-upd-row .dl-mono{font-size:11px}.dl-upd-row .dl-mono b{color:var(--dl-fg);font-weight:500}.dl-upd-row>.dl-pill,.dl-upd-row>button,.dl-upd-head>.dl-pill,.dl-upd-head>button{flex:none}.dl-upd-bad{color:var(--dl-bad)}.dl-upd-job>.dl-log,.dl-upd-job>.alert-message{margin:0 14px 14px}`;function yn(){let s=document.createElement("style");return s.dataset.dawnline="1",s.textContent=qa,s}function Be(s,t){return()=>{let n=new s,a={load:()=>n.load(),render:async i=>{let o=await n.render(i),r=document.createElement("div");return r.className="dl-root",r.append(yn(),o),r},addFooter(){return n.noFooter?document.createElement("div"):this.super("addFooter",[])}};return t||Object.assign(a,{handleSave:null,handleSaveApply:null,handleReset:null}),a}}var Ao=Be(nt,!1),Po=Be(Ie,!0),No=Be(nt,!1),zo=Be(bt,!1),Ro=Be(yt,!1),Ho=Be(kt,!1),Io=Be(wt,!1);function kn(s){return()=>({load:()=>(ui.menu?.flushCache(),location.replace(`${L.url("admin/network/dawnline/diagnostics")}${s?`?tab=${s}`:""}`),new Promise(()=>{})),render:()=>document.createElement("div"),handleSave:null,handleSaveApply:null,handleReset:null})}var Bo=kn(""),jo=kn("log");return baseclass.extend({ activity: jo, diagnostics: Ho, health: Bo, overview: Ao, people: Po, person: Ro, server: No, settings: zo, updates: Io }); diff --git a/package/luci-app-dawnline/htdocs/luci-static/resources/view/dawnline/diagnostics.js b/package/luci-app-dawnline/htdocs/luci-static/resources/view/dawnline/diagnostics.js new file mode 100644 index 0000000..d6e2d85 --- /dev/null +++ b/package/luci-app-dawnline/htdocs/luci-static/resources/view/dawnline/diagnostics.js @@ -0,0 +1,5 @@ +'use strict'; +'require view'; +'require dawnline.app as app'; + +return view.extend(app.diagnostics()); diff --git a/package/luci-app-dawnline/root/etc/hotplug.d/iface/95-dawnline b/package/luci-app-dawnline/root/etc/hotplug.d/iface/95-dawnline old mode 100644 new mode 100755 index 00abe6c..b9b242a --- a/package/luci-app-dawnline/root/etc/hotplug.d/iface/95-dawnline +++ b/package/luci-app-dawnline/root/etc/hotplug.d/iface/95-dawnline @@ -1,5 +1,9 @@ #!/bin/sh -# Load devices into a Dawnline tunnel whenever netifd (re)creates it. -[ "$ACTION" = ifup ] || exit 0 +# Dawnline tunnels: log starts and stops to the service log, and load devices +# whenever netifd (re)creates one. +case "$ACTION" in ifup|ifdown|ifup-failed) ;; *) exit 0 ;; esac [ -n "$(uci -q get "network.$INTERFACE._dawnline")" ] || exit 0 -/usr/bin/dawnline sync >/dev/null 2>&1 & +# In order (a quick down/up must not log up first). +/usr/bin/dawnline iface-event "$ACTION" "$INTERFACE" >/dev/null 2>&1 +[ "$ACTION" = ifup ] && /usr/bin/dawnline sync >/dev/null 2>&1 & +exit 0 diff --git a/package/luci-app-dawnline/root/etc/init.d/dawnline b/package/luci-app-dawnline/root/etc/init.d/dawnline index d8e0a67..2466623 100755 --- a/package/luci-app-dawnline/root/etc/init.d/dawnline +++ b/package/luci-app-dawnline/root/etc/init.d/dawnline @@ -55,6 +55,12 @@ start_service() { start_resolver } +# Noted for the service log: the next agent start is a restart, not a crash or a boot. +stop_service() { + mkdir -p /var/run/dawnline + date +%s > /var/run/dawnline/agent.stopped +} + reload_service() { /usr/bin/dawnline apply >/dev/null 2>&1 start 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 6b77c98..654a8cd 100755 --- a/package/luci-app-dawnline/root/etc/uci-defaults/90_dawnline +++ b/package/luci-app-dawnline/root/etc/uci-defaults/90_dawnline @@ -24,6 +24,13 @@ rm -rf /usr/share/dawnline/portal/www/assets rm -f /tmp/luci-indexcache* /tmp/luci-modulecache/* 2>/dev/null touch /usr/lib/opkg/status 2>/dev/null +# Cron restarts the agent when it stops ticking (Health → Watchdog). +mkdir -p /etc/crontabs +grep -qs /usr/libexec/dawnline/heartbeat /etc/crontabs/root || { + echo '*/5 * * * * /usr/libexec/dawnline/heartbeat' >> /etc/crontabs/root + /etc/init.d/cron restart 2>/dev/null +} + /etc/init.d/rpcd reload # A reload keeps LuCI logins but sometimes misses the plugin; restart only then. sleep 2 diff --git a/package/luci-app-dawnline/root/usr/bin/dawnline b/package/luci-app-dawnline/root/usr/bin/dawnline index 743efac..f31da95 100755 --- a/package/luci-app-dawnline/root/usr/bin/dawnline +++ b/package/luci-app-dawnline/root/usr/bin/dawnline @@ -7,7 +7,8 @@ import * as live from 'dawnline.live'; import * as apply from 'dawnline.apply'; import * as view from 'dawnline.view'; import * as ops from 'dawnline.ops'; -import { VERSION } from 'dawnline.util'; +import * as watchdog from 'dawnline.watchdog'; +import { VERSION, slog, sh_out, q, take_iface_intent } from 'dawnline.util'; const args = ARGV; const cmd = args[0] ?? 'help'; @@ -42,6 +43,7 @@ Usage: dawnline backup Create a backup in /etc/dawnline/backups portal-cert Print the certificate and key the portal uses portal-http-port Print the plain-HTTP port when an IP is among the portal addresses + log Service log: tunnel and service starts, stops, repairs (newest first) teardown Remove everything Dawnline created on the router version`); } @@ -112,6 +114,46 @@ try { if (core.portal_http(m)) out(`${core.portal_http_port(m)}`); } + else if (cmd == 'log') { + for (let e in watchdog.view(core.load()).log) { + let t = localtime(e.ts); + let text = e.by == 'admin' + ? join(' ', filter([ 'You', e.msg, e.kind, e.who, e.note ? '· ' + e.note : null ], (x) => x)) + : (e.who ? e.who + ' ' : '') + e.msg; + out(sprintf('%02d-%02d %02d:%02d %-8s %-6s %s', t.mon, t.mday, t.hour, t.min, e.src, e.level, text)); + if (e.detail) + out(' ' + replace(e.detail, '\n', '\n ')); + } + } + else if (cmd == 'iface-event') { + // From the iface hotplug script: a tunnel started, stopped or failed to start. + let ifname = args[2] ?? ''; + if (!match(ifname, /^[a-z][a-z0-9_]{0,15}$/)) + die('Bad interface.'); + // Dawnline leaves a note before it takes a tunnel down itself; anything else is unexpected. + let it = args[1] == 'ifdown' ? take_iface_intent(ifname) : null; + let who = it?.name ?? ifname; + for (let id, srv in core.load().servers) + if (srv.ifname == ifname) + who = srv.name; + if (args[1] == 'ifup') { + let port = sh_out(`awg show ${q(ifname)} listen-port 2>/dev/null`); + slog('awg', 'up', port ? `started · accepting connections on port ${port}` : 'started', null, who); + } + else if (args[1] == 'ifdown') { + // Stops Dawnline made itself are explained by the admin's own line + // (changed, turned off, removed); only an AmneziaWG update gets one here. + if (it?.reason == 'update') + slog('awg', 'info', 'restarting for the AmneziaWG update', null, who); + else if (!it) + slog('awg', 'down', 'stopped unexpectedly', join('\n', filter([ + "Dawnline didn't stop it: the router's network restarted, someone stopped it by hand, or it failed.", + watchdog.iface_errors(ifname), + ], (x) => x)), who); + } + else if (args[1] == 'ifup-failed') + slog('awg', 'error', "couldn't start", watchdog.iface_errors(ifname), who); + } else if (cmd == 'teardown') apply.teardown(); else if (cmd == 'version') diff --git a/package/luci-app-dawnline/root/usr/libexec/dawnline/agent b/package/luci-app-dawnline/root/usr/libexec/dawnline/agent index 4629db2..baa0eee 100755 --- a/package/luci-app-dawnline/root/usr/libexec/dawnline/agent +++ b/package/luci-app-dawnline/root/usr/libexec/dawnline/agent @@ -5,17 +5,21 @@ // * keeps the "like a home device" path and the Home-only resolver up // * logs connects, disconnects and roaming // * enforces end dates, quotas, schedules and pauses (peers + nft sets) -// * watches the tunnel interfaces +// * watches the tunnel interfaces and repairs what it can (dawnline.watchdog) 'use strict'; import * as uloop from 'uloop'; -import { readfile, stat, unlink } from 'fs'; -import { read_json, write_json, ensure_dir, sh_out, q, DATA_DIR, RUN_DIR } from 'dawnline.util'; +import { readfile, writefile, stat, unlink } from 'fs'; +import { + read_json, write_json, ensure_dir, sh_out, q, slog, slog_trim, slog_restore, DATA_DIR, RUN_DIR, VERSION +} from 'dawnline.util'; import * as core from 'dawnline.core'; import * as live from 'dawnline.live'; import * as apply from 'dawnline.apply'; import * as ops from 'dawnline.ops'; import * as geo from 'dawnline.geo'; +import * as watchdog from 'dawnline.watchdog'; +import * as net from 'dawnline.net'; const TICK = 60 * 1000; const FLUSH_EVERY = 3600; @@ -30,7 +34,6 @@ let presence = read_json(`${RUN_DIR}/presence.json`, {}); let last_online = presence.online ?? {}; let last_endpoint = presence.endpoint ?? {}; let offline_ticks = {}; -let iface_down = {}; let last_flush = time(); let last_log_flush = time(); let last_net = null; @@ -103,7 +106,10 @@ function check_people(m, states, events) { let ts = time(); for (let id, p in m.people) { let st = states[id], prev = last_states?.[id]; - if (prev != null && prev != st) + // The admin's own pauses are logged by rpcd when they happen; here only + // what changes on its own (end date, data limit, allowed hours). + let by_admin = (x) => x == 'paused' || x == 'paused_all'; + if (prev != null && prev != st && !by_admin(prev) && !by_admin(st)) push(events, { type: st == 'active' ? 'resumed' : 'paused', person: id, detail: REASON[st] ?? st }); // "Remove their devices" when the end date passes. if (core.person_expired(p, ts) && p.expire_action == 'remove' && length(p.devices)) { @@ -182,24 +188,22 @@ function check_devices(m, lv, events) { write_json(`${RUN_DIR}/presence.json`, { online: last_online, endpoint: last_endpoint }, 0o600); } -function check_servers(m, dmp, events) { - for (let id, srv in m.servers) { - if (!srv.enabled || !srv.private_key) - continue; - let up = dmp.ifaces[srv.ifname] != null; - if (!up) { - iface_down[id] = (iface_down[id] ?? 0) + 1; - if (iface_down[id] == 2) { - push(events, { type: 'server_down', server: id, detail: srv.ifname }); - } - } - else { - if ((iface_down[id] ?? 0) >= 2) { - push(events, { type: 'server_up', server: id, detail: srv.ifname }); - } - iface_down[id] = 0; - } - } +// What the service log was already told. On flash: the public address often +// changes with a reboot (PPPoE), and that is when it matters. Written rarely. +const NOTES = `${DATA_DIR}/notes.json`; +let notes = read_json(NOTES, {}); +let last_cert_check = 0; + +function note(k, v) { + notes[k] = v; + ensure_dir(DATA_DIR, 0o700); + write_json(NOTES, notes, 0o600); +} + +/** "Jan 1 2027" from the certificate, or null. */ +function cert_end(path) { + let m = match(sh_out(`openssl x509 -enddate -noout -in ${q(path)} 2>/dev/null`) ?? '', /notAfter=([A-Za-z]+) +([0-9]+) [0-9:]+ ([0-9]+)/); + return m ? `${m[1]} ${m[2]} ${m[3]}` : null; } function check_cert(m) { @@ -207,9 +211,42 @@ function check_cert(m) { return; let c = ops.portal_cert(m.settings); let mt = stat(c.cert)?.mtime; - if (cert_mtime != null && mt != null && mt != cert_mtime) + if (cert_mtime != null && mt != null && mt != cert_mtime) { + slog('portal', 'up', `certificate renewed · valid until ${cert_end(c.cert) ?? '?'}`, null, 'Personal portal'); system('/etc/init.d/dawnline reload >/dev/null 2>&1 &'); + } cert_mtime = mt; + // Running out soon (ACME did not renew it): once per certificate, checked hourly. + if (mt == null || c.self_signed || time() - last_cert_check < 3600) + return; + last_cert_check = time(); + if (notes.cert_warned != mt && system(`openssl x509 -checkend 604800 -noout -in ${q(c.cert)} >/dev/null 2>&1`) != 0) { + slog('portal', 'error', `certificate expires ${cert_end(c.cert) ?? 'within 7 days'}`, + 'Browsers will refuse the portal after that. Renew it with ACME, or choose another certificate in Settings.', 'Personal portal'); + note('cert_warned', mt); + } +} + +/** + * The router's public IPv4 changed. Devices whose configuration holds the + * address itself (a server's public address is an IP) cannot connect until + * they get a new one; with a hostname only the DNS record must follow. + */ +function check_wan(m) { + let srv = filter(values(m.servers), (x) => x.enabled && x.private_key)[0]; + let ip = srv ? net.wan_address(srv) : null; + if (!ip || ip == notes.wan) + return; + let was = notes.wan; + note('wan', ip); + if (!was) + return; + let stuck = map(filter(values(m.servers), (x) => core.endpoint_host(m, x) == was), (x) => x.name); + if (length(stuck)) + slog('dawnline', 'error', `public address changed · ${was} → ${ip}`, + `${join(', ', stuck)} still give${length(stuck) == 1 ? 's' : ''} devices the old address: set the public address in the server settings (a DDNS name keeps working), then devices need new configurations.`, 'Router'); + else + slog('dawnline', 'info', `public address changed · ${was} → ${ip}`, null, 'Router'); } let last_backup_day = null; @@ -247,6 +284,8 @@ function check_usage_reset(m) { } 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) usage = live.load_usage(); @@ -264,7 +303,7 @@ function tick() { check_devices(m, lv, events); check_people(m, states, events); - check_servers(m, dmp, events); + // Tunnels going down and up are in the service log (hotplug, watchdog), with names and reasons. let changed = last_states == null || sprintf('%J', states) != sprintf('%J', last_states); if (changed || time() - last_sync > RESYNC_EVERY) { @@ -277,6 +316,7 @@ function tick() { let persist = reset || time() - last_flush >= FLUSH_EVERY; live.save_usage(usage, persist); + slog_trim(persist); if (persist) last_flush = time(); if (pol.persist == 'off' || time() - last_log_flush >= LOG_FLUSH[pol.persist]) { @@ -288,16 +328,26 @@ function tick() { // The router's network changed under us: re-derive everything. let sig = apply.net_signature(m); if (last_net != null && sig != last_net) { - system(`logger -t dawnline-agent 'network changed, re-applying'`); + slog('dawnline', 'info', 'network changed — Dawnline set itself up again', null, 'Router'); apply.apply(); sig = apply.net_signature(core.load()); } last_net = sig; } catch (e) { - system(`logger -t dawnline-agent ${q('like-home: ' + e.message)}`); + slog('dawnline', 'error', `failed: ${e.message}`, null, 'Internet like a home device'); + } + try { + watchdog.run(core.load()); + } + catch (e) { + slog('dawnline', 'error', `failed: ${e.message}`, null, 'Watchdog'); } check_cert(m); + try { + check_wan(m); + } + catch (e) {} nightly_backup(); try { check_geo(m); @@ -310,8 +360,36 @@ function tick() { function shutdown() { live.save_usage(usage, true); live.persist_events(); + slog_trim(true); + // A clean stop: the next start is not a crash. + unlink(watchdog.BEAT); } +// Why this start: the heartbeat file outlives an agent that died (crash, out +// of memory, kill -9); the init script notes a stop; the version on flash +// changes with an update; a fresh uptime means the router just booted. +let crashed = stat(watchdog.BEAT) != null; +let stopped = +(readfile(`${RUN_DIR}/agent.stopped`) ?? 0); +unlink(`${RUN_DIR}/agent.stopped`); +let was = trim(readfile(`${DATA_DIR}/version`) ?? ''); +if (was != VERSION) { + ensure_dir(DATA_DIR, 0o700); + writefile(`${DATA_DIR}/version`, VERSION); +} +slog_restore(); +if (was && was != VERSION) + slog('dawnline', 'up', `updated · ${was} → ${VERSION}`, null, 'Dawnline'); +else if (crashed) + slog('dawnline', 'repair', 'stopped unexpectedly — started again', + // Why, when syslog knows: procd, the kernel (out of memory, segfault), ucode errors. + sh_out('logread -l 400 2>/dev/null | grep -iE "kernel:.*(out of memory|killed process|oom-kill|segfault)|procd:.*dawnline|dawnline/agent" | tail -n 6'), 'Dawnline'); +else if (stopped && time() - stopped < 300) + slog('dawnline', 'info', `restarted · version ${VERSION}`, null, 'Dawnline'); +else if (live.uptime() < 600) + slog('dawnline', 'info', `started with the router · version ${VERSION}`, null, 'Dawnline'); +else + slog('dawnline', 'info', `started · version ${VERSION}`, null, 'Dawnline'); + uloop.init(); let timer; @@ -320,7 +398,7 @@ timer = uloop.timer(1000, function() { tick(); } catch (e) { - system(`logger -t dawnline-agent ${q('tick failed: ' + e.message)}`); + slog('dawnline', 'error', `background check failed: ${e.message}`, e.stacktrace?.[0]?.context, 'Dawnline'); } timer.set(TICK); }); diff --git a/package/luci-app-dawnline/root/usr/libexec/dawnline/heartbeat b/package/luci-app-dawnline/root/usr/libexec/dawnline/heartbeat new file mode 100755 index 0000000..9578c41 --- /dev/null +++ b/package/luci-app-dawnline/root/usr/libexec/dawnline/heartbeat @@ -0,0 +1,24 @@ +#!/bin/sh +# Cron, every 5 minutes: the watchdog lives in the agent, so this looks after +# the agent itself and kills it when it runs but has stopped ticking (procd +# starts it again). Off with the watchdog (Health → Watchdog). +[ "$(uci -q get dawnline.settings.watchdog)" = 0 ] && exit 0 +pid="$(ubus call service list '{"name":"dawnline"}' 2>/dev/null | jsonfilter -q -e '@.dawnline.instances.agent.pid')" +[ -n "$pid" ] && [ -r "/proc/$pid/stat" ] || exit 0 + +now="$(date +%s)" +last="$(cat /var/run/dawnline/agent.beat 2>/dev/null)" +# Seconds the agent has been running: uptime minus its start time (field 22, in 1/100 s). +age="$(awk -v up="$(cut -d. -f1 /proc/uptime)" '{ print up - int($22 / 100) }' "/proc/$pid/stat")" +[ "${age:-0}" -gt 300 ] || exit 0 +[ $((now - ${last:-0})) -gt 300 ] || exit 0 + +kill -9 "$pid" +# Logged here; the restarted agent should not report a crash as well. +rm -f /var/run/dawnline/agent.beat +if [ -n "$last" ]; then detail="No check for $((now - last)) s." +else detail="It never completed a check."; fi +msg="stopped responding — restarted" +mkdir -p /var/run/dawnline +printf '{"ts":%s,"src":"dawnline","level":"repair","who":"Dawnline","msg":"%s","detail":"%s"}\n' "$now" "$msg" "$detail" >> /var/run/dawnline/service.log +logger -t dawnline "Dawnline $msg" diff --git a/package/luci-app-dawnline/root/usr/libexec/dawnline/updater b/package/luci-app-dawnline/root/usr/libexec/dawnline/updater index 992cf5f..5054528 100755 --- a/package/luci-app-dawnline/root/usr/libexec/dawnline/updater +++ b/package/luci-app-dawnline/root/usr/libexec/dawnline/updater @@ -11,7 +11,7 @@ import * as fs from 'fs'; import { cursor } from 'uci'; import { connect } from 'ubus'; -import { VERSION, REPO } from 'dawnline.util'; +import { VERSION, REPO, slog, iface_intent } from 'dawnline.util'; const STATE_DIR = '/var/run/dawnline'; const JOB_FILE = `${STATE_DIR}/update-job.json`; @@ -358,8 +358,10 @@ function install_awg(arg) { push(ifaces, s['.name']); }); phase(`Reloading the kernel module (${length(ifaces)} tunnel(s) restart)`); - for (let i in ifaces) + for (let i in ifaces) { + iface_intent(i, 'update', c.get('network', i, '_dawnline_name') ?? i); run(`ifdown ${q(i)}`); + } run('rmmod amneziawg'); run_logged('modprobe amneziawg'); for (let i in ifaces) @@ -472,6 +474,19 @@ function install_pkgs(arg) { const CHECKS = { app: check_app, amneziawg: check_awg, packages: check_pkgs }; const INSTALLS = { app: install_app, amneziawg: install_awg, pkgs: install_pkgs }; +const UPDATE_WHO = { app: 'Dawnline', amneziawg: 'AmneziaWG', pkgs: 'System packages' }; + +/** A line in the service log for each finished update (nothing when there was nothing to do). */ +function log_update(name, r) { + // Dawnline's own update is logged by the new agent when it starts (also after install.sh). + if (name == 'amneziawg') { + let b = r?.before?.['kmod-amneziawg'], a = r?.after?.['kmod-amneziawg']; + slog('awg', 'up', b && a && b != a ? `updated · ${b} → ${a}` : `installed the ${AWG_SOURCES[r?.build]?.label ?? r?.build} build${a ? ' · ' + a : ''}`, + null, 'AmneziaWG'); + } + else if (name == 'pkgs' && length([ ...(r?.updated ?? []), ...(r?.installed ?? []) ])) + slog('dawnline', 'up', `updated · ${join(', ', [ ...(r.updated ?? []), ...(r.installed ?? []) ])}`, null, 'System packages'); +} if (!fs.access(STATE_DIR)) @@ -503,6 +518,7 @@ try { die(`Unknown component ${name}`); phase(`Updating ${name}`); job.result[name] = INSTALLS[name](arg); + log_update(name, job.result[name]); } } else @@ -514,6 +530,10 @@ catch (e) { job.state = 'failed'; job.error = e.message; log(`Error: ${e.message}`); + if (job.action == 'install') { + let name = split(job.component, ':')[0]; + slog(name == 'amneziawg' ? 'awg' : 'dawnline', 'error', 'update failed', e.message, UPDATE_WHO[name] ?? 'Dawnline'); + } } run(`rm -rf ${WORK_DIR}`); diff --git a/package/luci-app-dawnline/root/usr/share/dawnline/portal/assets/portal.css b/package/luci-app-dawnline/root/usr/share/dawnline/portal/assets/portal.css index 6ecd9b6..a50c2ab 100644 --- a/package/luci-app-dawnline/root/usr/share/dawnline/portal/assets/portal.css +++ b/package/luci-app-dawnline/root/usr/share/dawnline/portal/assets/portal.css @@ -1 +1 @@ -@font-face{font-family:Geist;src:url(geist-latin-wght-normal.woff2) format("woff2");font-weight:100 900;font-display:swap;unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+2000-206F,U+20AC,U+2122,U+2190-21FF,U+2212,U+2215}@font-face{font-family:Geist;src:url(geist-cyrillic-wght-normal.woff2) format("woff2");font-weight:100 900;font-display:swap;unicode-range:U+0301,U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116}@font-face{font-family:Geist Mono;src:url(geist-mono-latin-wght-normal.woff2) format("woff2");font-weight:100 900;font-display:swap}:root{--bg: #fcfcfc;--card: #ffffff;--elevated: #ffffff;--text: #0d0d0d;--muted: #5d5d5d;--faint: #8f8f8f;--line: #0000001a;--input: #00000026;--soft: #0d0d0d0d;--soft-hover: #0d0d0d1a;--primary: #0d0d0d;--primary-fg: #ffffff;--accent: #3a83f7;--info: #2c67c5;--ok: #00a240;--ok-wash: #00a24026;--warn: #e25507;--warn-wash: #e2550726;--bad: #e02e2a;--bad-wash: #e02e2a1f;--chart: #3a83f7;--track: #0d0d0d1a;--scrim: #00000040;--shadow: 0 1px 2px -1px #00000014;--shadow-xl: 0 8px 16px -4px #0000001f;--radius: 16px;--mono: "Geist Mono", ui-monospace, Menlo, monospace;color-scheme:light dark}@media(prefers-color-scheme:dark){:root{--bg: #000000;--card: #0a0a0a;--elevated: #131313;--text: #ededed;--muted: #edededa6;--faint: #ededed78;--line: #ededed13;--input: #ededed24;--soft: #ededed0d;--soft-hover: #ededed1a;--primary: #ededed;--primary-fg: #131313;--accent: #006efe;--info: #5ba2fe;--ok: #40c977;--ok-wash: #40c97726;--warn: #ff8549;--warn-wash: #ff854926;--bad: #ff6764;--bad-wash: #ff676422;--chart: #3a83f7;--track: #ededed1a;--scrim: #00000099;--shadow: none;--shadow-xl: 0 8px 16px -4px #00000080}}*{box-sizing:border-box}html,body{margin:0}body{background:var(--bg);color:var(--text);font:400 15px/22px Geist,-apple-system,system-ui,Segoe UI,sans-serif;-webkit-font-smoothing:antialiased;min-height:100vh;min-height:100dvh}body.locked{overflow:hidden}a{color:var(--info);text-decoration:none}a:hover{text-decoration:underline}h1,h2{margin:0;font-weight:500;letter-spacing:-.01em}h1{font-size:24px;line-height:32px}h2{font-size:16px;line-height:24px}.muted{color:var(--muted)}.faint{color:var(--faint)}.s{font-size:13px;line-height:18px}.ok{color:var(--ok)}.warn{color:var(--warn)}.strong{font-weight:500}.center{text-align:center}.mono{font-family:var(--mono);font-size:12px}.stack{display:flex;flex-direction:column;gap:2px;min-width:0}.stack.gap{gap:10px}.grow{flex:1}.row{display:flex;align-items:center;gap:8px;flex-wrap:wrap}.row.gap{gap:8px;flex-wrap:nowrap}.row-baseline{display:flex;align-items:baseline;gap:10px;flex-wrap:wrap}.offscreen{position:fixed;left:-9999px;opacity:0}.top{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:max(12px,env(safe-area-inset-top)) 16px 12px;border-bottom:1px solid var(--line);position:sticky;top:0;background:color-mix(in srgb,var(--bg) 85%,transparent);backdrop-filter:saturate(180%) blur(12px);z-index:5}.brand{display:flex;align-items:center;gap:8px;font-weight:500;min-width:0}.brand .faint{font-weight:400}.logo{display:inline-flex;width:22px;height:22px;color:var(--text)}.logo svg{width:100%;height:100%}.wrap{width:100%;max-width:1048px;margin:0 auto;padding:20px 16px max(32px,env(safe-area-inset-bottom));display:flex;flex-direction:column;gap:20px}.hello{display:flex;align-items:center;gap:12px}.avatar{width:44px;height:44px;border-radius:50%;background:var(--soft-hover);display:inline-flex;align-items:center;justify-content:center;font-size:14px;font-weight:600;position:relative;flex:0 0 auto}.avatar.online:after{content:"";position:absolute;right:0;bottom:0;width:10px;height:10px;border-radius:50%;background:var(--ok);box-shadow:0 0 0 3px var(--bg)}.pill{display:inline-flex;align-items:center;height:22px;padding:0 9px;border-radius:999px;font-size:12px;font-weight:500;background:var(--soft);color:var(--muted)}.pill.ok{background:var(--ok-wash);color:var(--ok)}.pill.warn{background:var(--warn-wash);color:var(--warn)}.pill.bad{background:var(--bad-wash);color:var(--bad)}.notice{display:flex;gap:10px;align-items:flex-start;padding:12px 14px;border-radius:12px;background:var(--warn-wash);font-size:14px}.notice.bad{background:var(--bad-wash)}.notice .ic{color:var(--warn)}.notice.bad .ic{color:var(--bad)}.layout{display:grid;grid-template-columns:minmax(0,1fr);gap:20px;grid-template-areas:"access" "devices"}.access{grid-area:access}.devices{grid-area:devices;display:flex;flex-direction:column;gap:12px;min-width:0}.desktop-only{display:none!important}@media(min-width:960px){.top{padding-left:max(16px,calc((100vw - 1048px)/2 + 16px));padding-right:max(16px,calc((100vw - 1048px)/2 + 16px))}.layout{grid-template-columns:minmax(0,1.7fr) minmax(0,1fr);grid-template-areas:"devices access";align-items:start;gap:16px}.desktop-only{display:inline-flex!important}.wrap{padding-top:28px}}.card{background:var(--card);border:1px solid var(--line);border-radius:var(--radius);padding:16px;box-shadow:var(--shadow);min-width:0}.card-head{display:flex;align-items:center;justify-content:space-between;gap:12px}.access{display:flex;flex-direction:column;gap:12px;min-width:0}.access-card{display:flex;flex-direction:column;gap:12px}.reach{display:flex;align-items:center;gap:12px;padding:12px;border-radius:12px;background:var(--soft)}.reach-ic{width:36px;height:36px;border-radius:10px;display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;background:color-mix(in srgb,var(--info) 14%,transparent);color:var(--info)}.tile{border:1px solid var(--line);border-radius:14px;padding:14px;display:flex;flex-direction:column;gap:8px;min-width:0}.tiles2{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}.tile-label{display:flex;justify-content:space-between;gap:8px;font-size:12px;font-weight:500;color:var(--faint)}.tile-value{font-size:20px;line-height:28px;font-weight:500;letter-spacing:-.01em;font-variant-numeric:tabular-nums}.tile-value.sm{font-size:16px}.tile-value .faint{font-size:14px;font-weight:400}.meter{position:relative;height:6px;border-radius:999px;background:var(--track);cursor:default}.meter i{display:block;height:100%;border-radius:999px;background:var(--accent)}.meter.warn i{background:var(--warn)}.meter.bad i{background:var(--bad)}.slots{display:grid;grid-auto-flow:column;grid-auto-columns:minmax(0,1fr);gap:3px}.slots i{display:block;height:4px;border-radius:999px;background:var(--track)}.slots i.used{background:var(--text)}.dgrid{display:grid;grid-template-columns:minmax(0,1fr);gap:10px}@media(min-width:640px){.dgrid{grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}}.dgrid>.slot.add:only-child{grid-column:1 / -1}.dcard{background:var(--card);border:1px solid var(--line);border-radius:var(--radius);padding:14px;display:flex;flex-direction:column;gap:12px;min-width:0;box-shadow:var(--shadow)}.dcard.online{border-color:color-mix(in srgb,var(--ok) 35%,transparent)}.dcard.off{opacity:.7}.dhead{display:flex;align-items:center;gap:12px}.dic{width:40px;height:40px;border-radius:12px;background:var(--soft);display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;color:var(--muted)}.dic .ic-svg{width:20px;height:20px}.dcard.online .dic{background:var(--ok-wash);color:var(--ok)}.dname{font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.dstat{display:inline-flex;align-items:center;gap:6px;font-size:13px;color:var(--muted)}.dstat.ok{color:var(--ok)}.dstat.warn{color:var(--warn)}.dot{width:6px;height:6px;border-radius:50%;background:var(--faint);display:inline-block;flex:0 0 auto}.dot.ok{background:var(--ok);box-shadow:0 0 0 3px var(--ok-wash)}.dot.warn{background:var(--warn)}.dot.pulse{animation:pulse 1.6s ease-in-out infinite}@keyframes pulse{0%,to{box-shadow:0 0 0 0 var(--warn-wash)}50%{box-shadow:0 0 0 6px transparent}}.duse{display:flex;align-items:flex-end;justify-content:space-between;gap:12px}.spark{display:flex;align-items:flex-end;gap:3px;height:26px;width:128px}.spark i{flex:1;display:block;border-radius:2px 2px 0 0;background:var(--chart);opacity:.85;cursor:default}.spark i.zero{opacity:.22}.spark i:hover{opacity:1;filter:brightness(1.2)}.dfoot{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:8px;padding-top:12px;border-top:1px solid var(--line)}.dfoot>.faint{white-space:nowrap}.lan-pill{all:unset;cursor:pointer;display:inline-flex;align-items:center;height:26px;padding:0 3px;border-radius:999px;max-width:100%;min-width:0;background:linear-gradient(180deg,color-mix(in srgb,var(--text) 6%,transparent),color-mix(in srgb,var(--text) 2.5%,transparent));box-shadow:inset 0 0 0 1px var(--line),0 1px 2px #0003}.lan-pill:hover{box-shadow:inset 0 0 0 1px var(--input),0 1px 2px #0003}.lan-pill:focus-visible{outline:2px solid var(--accent);outline-offset:2px}.lan-ic{width:20px;height:20px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;background:color-mix(in srgb,var(--info) 14%,transparent);color:var(--info)}.lan-ic .ic-svg{width:11px;height:11px}.lan-pill .mono{padding:0 8px 0 7px;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.lan-sep{width:1px;height:14px;background:var(--line);flex:0 0 auto}.lan-pill>.ic:last-child{width:22px;justify-content:center;color:var(--muted)}.lan-pill>.ic:last-child .ic-svg{width:12px;height:12px}.slot.add{all:unset;box-sizing:border-box;cursor:pointer;display:flex;align-items:center;gap:14px;padding:16px;min-height:72px;border:1px dashed var(--input);border-radius:var(--radius);color:var(--text);text-align:left;transition:background .15s,border-color .15s}.slot.add:hover{background:var(--soft);border-color:color-mix(in srgb,var(--text) 30%,transparent)}.slot-ic{width:40px;height:40px;border-radius:12px;background:var(--soft);display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;color:var(--muted)}.slot.add:hover .slot-ic{background:var(--primary);color:var(--primary-fg)}.slot.add:focus-visible{outline:2px solid var(--accent);outline-offset:2px}@media(min-width:960px){.slot.add{flex-direction:column;justify-content:center;gap:10px;min-height:140px;text-align:center;color:var(--muted)}.slot.add .stack{align-items:center}.slot.add .strong{color:var(--text)}.slot.add .slot-ic{border-radius:999px;width:36px;height:36px}}.ic{display:inline-flex;line-height:0}.ic-svg{width:16px;height:16px}.btn{all:unset;box-sizing:border-box;cursor:pointer;display:inline-flex;align-items:center;justify-content:center;gap:8px;height:40px;padding:0 16px;border-radius:999px;font-size:14px;font-weight:500;background:var(--soft);color:var(--text);-webkit-tap-highlight-color:transparent;white-space:nowrap}.btn:hover{background:var(--soft-hover)}.btn.primary{background:var(--primary);color:var(--primary-fg)}.btn.primary:hover{opacity:.9}.btn.danger-solid{background:var(--bad);color:#fff}.btn.small{height:32px;padding:0 12px;font-size:13px}.btn.big{height:48px;font-size:15px}.btn.block{display:flex;width:100%}.btn[disabled]{opacity:.45;cursor:not-allowed}.btn:focus-visible,.kind:focus-visible,.icon-btn:focus-visible,.slot:focus-visible{outline:2px solid var(--accent);outline-offset:2px}.icon-btn{all:unset;cursor:pointer;width:36px;height:36px;display:inline-flex;align-items:center;justify-content:center;border-radius:50%;color:var(--muted);flex:0 0 auto}.icon-btn:hover{background:var(--soft);color:var(--text)}.icon-btn.soft{background:var(--soft)}@media(pointer:coarse){.icon-btn{width:40px;height:40px}}input[type=text]{width:100%;font:inherit;color:var(--text);background:var(--card);border:1px solid var(--input);border-radius:10px;padding:0 12px;height:44px}input[type=text]:focus{outline:2px solid color-mix(in srgb,var(--accent) 60%,transparent);outline-offset:0;border-color:transparent}.lbl{display:block;font-size:13px;font-weight:500;color:var(--muted);margin:14px 2px 6px}.err{color:var(--bad);min-height:1.2em;margin:8px 2px;font-size:14px}.kinds{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:6px}.kind{all:unset;box-sizing:border-box;cursor:pointer;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6px;height:68px;min-width:0;border-radius:12px;box-shadow:inset 0 0 0 1px var(--line);color:var(--muted);font-size:12.5px;font-weight:500;text-align:center}.kind .ic-svg{width:20px;height:20px}.kind:hover{color:var(--text);background:color-mix(in srgb,var(--text) 4%,transparent)}.kind.on{box-shadow:inset 0 0 0 1.5px var(--accent);color:var(--text);background:color-mix(in srgb,var(--accent) 10%,transparent)}.kind.on .ic{color:var(--accent)}.signin{text-align:center;max-width:420px;margin:8vh auto 0;width:100%;padding:28px 20px;display:flex;flex-direction:column;gap:10px}.hero-ic{width:52px;height:52px;margin:0 auto 6px;border-radius:16px;display:grid;place-items:center;background:var(--primary);color:var(--primary-fg)}.hero-ic .ic-svg{width:24px;height:24px}.signin input{text-align:center;margin-top:8px}.menu{position:absolute;z-index:30;width:230px;padding:4px;border-radius:14px;background:var(--elevated);border:1px solid var(--line);box-shadow:var(--shadow-xl)}.menu-item{all:unset;box-sizing:border-box;cursor:pointer;display:flex;align-items:center;gap:10px;width:100%;height:40px;padding:0 12px;border-radius:10px;font-size:14px}.menu-item:hover,.menu-item:focus-visible{background:var(--soft-hover)}.menu-item .ic{color:var(--muted)}.menu-item.danger,.menu-item.danger .ic{color:var(--bad)}.menu-sep{height:1px;background:var(--line);margin:4px 8px}@media(pointer:coarse){.menu-item{height:44px}}.sheet{position:fixed;inset:0;z-index:20;display:flex;align-items:flex-end;justify-content:center;background:transparent;transition:background .2s}.sheet.open{background:var(--scrim)}.sheet-panel{width:100%;max-width:520px;max-height:92vh;max-height:92dvh;overflow:auto;background:var(--elevated);border-radius:20px 20px 0 0;border:1px solid var(--line);border-bottom:0;padding:6px 16px max(20px,env(safe-area-inset-bottom));transform:translateY(100%);transition:transform .25s cubic-bezier(.2,.8,.2,1)}.sheet.open .sheet-panel{transform:none}.grab{width:36px;height:4px;border-radius:999px;background:var(--input);margin:4px auto 8px}.sheet-head{display:flex;align-items:flex-start;justify-content:space-between;gap:8px;padding:4px 0 12px}.sheet-head h2{font-size:20px;line-height:28px;font-weight:600}.sheet-body{display:flex;flex-direction:column;gap:14px}@media(min-width:640px){.sheet{align-items:center}.sheet-panel{border-radius:16px;border-bottom:1px solid var(--line);padding:20px;max-width:480px;transform:scale(.97);opacity:0;transition:transform .18s ease,opacity .18s ease}.sheet.open .sheet-panel{transform:none;opacity:1}.grab{display:none}}.tabs{display:flex;gap:4px;padding:4px;background:var(--soft);border-radius:999px}.tabs button{all:unset;cursor:pointer;flex:1 1 auto;white-space:nowrap;text-align:center;padding:7px 10px;border-radius:999px;font-weight:500;font-size:13px;color:var(--muted)}.tabs button.on{background:var(--soft-hover);color:var(--text)}.pane{display:flex;flex-direction:column;gap:10px}.pane.center{align-items:center;text-align:center}.qr{width:min(240px,70vw);aspect-ratio:1;background:#fff;border-radius:12px;padding:10px;box-shadow:inset 0 0 0 1px var(--line)}.qr svg{display:block;width:100%;height:100%}.steps{margin:4px 0 0;padding:14px 16px 14px 34px;border-radius:14px;border:1px solid var(--line);background:var(--card);display:flex;flex-direction:column;gap:8px;font-size:14px}.keybox{display:flex;align-items:center;gap:8px;height:44px;padding:0 6px 0 12px;border:1px solid var(--input);border-radius:10px}.keybox .mono{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:var(--muted)}.filecard{display:flex;align-items:center;gap:12px;padding:12px;border-radius:14px;background:var(--soft);min-width:0}.filecard>.stack{flex:1;min-width:0}.filecard-ic{width:40px;height:46px;border-radius:8px;flex:none;display:inline-flex;align-items:center;justify-content:center;font:10px var(--mono);color:var(--muted);background:var(--card);box-shadow:inset 0 0 0 1px var(--line)}.ellipsis{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}@media(max-width:480px){.filecard .ellipsis{white-space:normal;overflow-wrap:anywhere}}.confbox{border:1px solid var(--line);border-radius:12px}.confbox>summary{list-style:none;display:flex;align-items:center;gap:8px;padding:8px 10px 8px 12px;color:var(--text)}.confbox>summary::-webkit-details-marker{display:none}.confbox>summary>.ic:first-child{transition:transform .15s;color:var(--muted)}.confbox[open]>summary>.ic:first-child{transform:rotate(90deg)}.confbox .grow{flex:1}.confbox>.conf{margin:0;border-top:1px solid var(--line);border-radius:0 0 12px 12px;background:none}.conf-sec{color:var(--accent, var(--info))}.conf-k{color:var(--faint)}.conf-mask{padding:0 6px;border-radius:4px;background:var(--soft);color:var(--muted)}.conf{white-space:pre-wrap;word-break:break-all;font:12px/18px var(--mono);background:var(--soft);border-radius:10px;padding:12px;max-height:16rem;overflow:auto}details>summary{cursor:pointer;color:var(--muted);font-size:13px;font-weight:500}.waiting{display:flex;align-items:center;gap:10px;padding:12px 14px;border-radius:12px;background:var(--soft);font-size:14px}.tip{position:fixed;z-index:50;transform:translate(-50%,-100%);padding:6px 10px;border-radius:10px;font-size:12px;line-height:17px;white-space:nowrap;background:var(--elevated);border:1px solid var(--line);box-shadow:var(--shadow-xl);pointer-events:none}.tip-title{font-weight:500}.toast{position:fixed;left:50%;bottom:max(20px,env(safe-area-inset-bottom));transform:translate(-50%,20px);opacity:0;z-index:60;background:var(--primary);color:var(--primary-fg);padding:10px 16px;border-radius:999px;font-weight:500;font-size:14px;transition:all .25s;max-width:90vw}.toast.show{opacity:1;transform:translate(-50%)}.toast.bad{background:var(--bad);color:#fff}@media(prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}} +@font-face{font-family:Geist;src:url(geist-latin-wght-normal.woff2) format("woff2");font-weight:100 900;font-display:swap;unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+2000-206F,U+20AC,U+2122,U+2190-21FF,U+2212,U+2215}@font-face{font-family:Geist;src:url(geist-cyrillic-wght-normal.woff2) format("woff2");font-weight:100 900;font-display:swap;unicode-range:U+0301,U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116}@font-face{font-family:Geist Mono;src:url(geist-mono-latin-wght-normal.woff2) format("woff2");font-weight:100 900;font-display:swap}:root{--bg: #fcfcfc;--card: #ffffff;--elevated: #ffffff;--text: #0d0d0d;--muted: #5d5d5d;--faint: #8f8f8f;--line: #0000001a;--input: #00000026;--soft: #0d0d0d0d;--soft-hover: #0d0d0d1a;--primary: #0d0d0d;--primary-fg: #ffffff;--accent: #3a83f7;--info: #2c67c5;--ok: #00a240;--ok-wash: #00a24026;--warn: #e25507;--warn-wash: #e2550726;--bad: #e02e2a;--bad-wash: #e02e2a1f;--chart: #3a83f7;--track: #0d0d0d1a;--scrim: #00000040;--shadow: 0 1px 2px -1px #00000014;--shadow-xl: 0 8px 16px -4px #0000001f;--radius: 16px;--mono: "Geist Mono", ui-monospace, Menlo, monospace;color-scheme:light dark}@media(prefers-color-scheme:dark){:root{--bg: #000000;--card: #0a0a0a;--elevated: #131313;--text: #ededed;--muted: #edededa6;--faint: #ededed78;--line: #ededed13;--input: #ededed24;--soft: #ededed0d;--soft-hover: #ededed1a;--primary: #ededed;--primary-fg: #131313;--accent: #006efe;--info: #5ba2fe;--ok: #40c977;--ok-wash: #40c97726;--warn: #ff8549;--warn-wash: #ff854926;--bad: #ff6764;--bad-wash: #ff676422;--chart: #3a83f7;--track: #ededed1a;--scrim: #00000099;--shadow: none;--shadow-xl: 0 8px 16px -4px #00000080}}*{box-sizing:border-box}html,body{margin:0}body{background:var(--bg);color:var(--text);font:400 15px/22px Geist,-apple-system,system-ui,Segoe UI,sans-serif;-webkit-font-smoothing:antialiased;min-height:100vh;min-height:100dvh}body.locked{overflow:hidden}a{color:var(--info);text-decoration:none}a:hover{text-decoration:underline}h1,h2{margin:0;font-weight:500;letter-spacing:-.01em}h1{font-size:24px;line-height:32px}h2{font-size:16px;line-height:24px}.muted{color:var(--muted)}.faint{color:var(--faint)}.s{font-size:13px;line-height:18px}.ok{color:var(--ok)}.warn{color:var(--warn)}.strong{font-weight:500}.center{text-align:center}.mono{font-family:var(--mono);font-size:12px}.stack{display:flex;flex-direction:column;gap:2px;min-width:0}.stack.gap{gap:10px}.grow{flex:1}.row{display:flex;align-items:center;gap:8px;flex-wrap:wrap}.row.gap{gap:8px;flex-wrap:nowrap}.row-baseline{display:flex;align-items:baseline;gap:10px;flex-wrap:wrap}.offscreen{position:fixed;left:-9999px;opacity:0}.top{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:max(12px,env(safe-area-inset-top)) 16px 12px;border-bottom:1px solid var(--line);position:sticky;top:0;background:color-mix(in srgb,var(--bg) 85%,transparent);backdrop-filter:saturate(180%) blur(12px);z-index:5}.brand{display:flex;align-items:center;gap:8px;font-weight:500;min-width:0}.brand .faint{font-weight:400}.logo{display:inline-flex;width:22px;height:22px;color:var(--text)}.logo svg{width:100%;height:100%}.wrap{width:100%;max-width:1048px;margin:0 auto;padding:20px 16px max(32px,env(safe-area-inset-bottom));display:flex;flex-direction:column;gap:20px}.hello{display:flex;align-items:center;gap:12px}.avatar{width:44px;height:44px;border-radius:50%;background:var(--soft-hover);display:inline-flex;align-items:center;justify-content:center;font-size:14px;font-weight:600;position:relative;flex:0 0 auto}.avatar.online:after{content:"";position:absolute;right:0;bottom:0;width:10px;height:10px;border-radius:50%;background:var(--ok);box-shadow:0 0 0 3px var(--bg)}.pill{display:inline-flex;align-items:center;height:22px;padding:0 9px;border-radius:999px;font-size:12px;font-weight:500;background:var(--soft);color:var(--muted)}.pill.ok{background:var(--ok-wash);color:var(--ok)}.pill.warn{background:var(--warn-wash);color:var(--warn)}.pill.bad{background:var(--bad-wash);color:var(--bad)}.notice{display:flex;gap:10px;align-items:flex-start;padding:12px 14px;border-radius:12px;background:var(--warn-wash);font-size:14px}.notice.bad{background:var(--bad-wash)}.notice .ic{color:var(--warn)}.notice.bad .ic{color:var(--bad)}.layout{display:grid;grid-template-columns:minmax(0,1fr);gap:20px;grid-template-areas:"access" "devices"}.access{grid-area:access}.devices{grid-area:devices;display:flex;flex-direction:column;gap:12px;min-width:0}.desktop-only{display:none!important}@media(min-width:960px){.top{padding-left:max(16px,calc((100vw - 1048px)/2 + 16px));padding-right:max(16px,calc((100vw - 1048px)/2 + 16px))}.layout{grid-template-columns:minmax(0,1.7fr) minmax(0,1fr);grid-template-areas:"devices access";align-items:start;gap:16px}.desktop-only{display:inline-flex!important}.wrap{padding-top:28px}}.card{background:var(--card);border:1px solid var(--line);border-radius:var(--radius);padding:16px;box-shadow:var(--shadow);min-width:0}.card-head{display:flex;align-items:center;justify-content:space-between;gap:12px}.access{display:flex;flex-direction:column;gap:12px;min-width:0}.access-card{display:flex;flex-direction:column;gap:12px}.reach{display:flex;align-items:center;gap:12px;padding:12px;border-radius:12px;background:var(--soft)}.reach-ic{width:36px;height:36px;border-radius:10px;display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;background:color-mix(in srgb,var(--info) 14%,transparent);color:var(--info)}.tile{border:1px solid var(--line);border-radius:14px;padding:14px;display:flex;flex-direction:column;gap:8px;min-width:0}.tiles2{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}.tile-label{display:flex;justify-content:space-between;gap:8px;font-size:12px;font-weight:500;color:var(--faint)}.tile-value{font-size:20px;line-height:28px;font-weight:500;letter-spacing:-.01em;font-variant-numeric:tabular-nums}.tile-value.sm{font-size:16px}.tile-value .faint{font-size:14px;font-weight:400}.meter{position:relative;height:6px;border-radius:999px;background:var(--track);cursor:default}.meter i{display:block;height:100%;border-radius:999px;background:var(--accent)}.meter.warn i{background:var(--warn)}.meter.bad i{background:var(--bad)}.slots{display:grid;grid-auto-flow:column;grid-auto-columns:minmax(0,1fr);gap:3px}.slots i{display:block;height:4px;border-radius:999px;background:var(--track)}.slots i.used{background:var(--text)}.slots i.over{background:color-mix(in srgb,var(--warn) 80%,transparent)}.dgrid{display:grid;grid-template-columns:minmax(0,1fr);gap:10px}@media(min-width:640px){.dgrid{grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}}.dgrid>.slot.add:only-child{grid-column:1 / -1}.dcard{background:var(--card);border:1px solid var(--line);border-radius:var(--radius);padding:14px;display:flex;flex-direction:column;gap:12px;min-width:0;box-shadow:var(--shadow)}.dcard.online{border-color:color-mix(in srgb,var(--ok) 35%,transparent)}.dcard.off{opacity:.7}.dhead{display:flex;align-items:center;gap:12px}.dic{width:40px;height:40px;border-radius:12px;background:var(--soft);display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;color:var(--muted)}.dic .ic-svg{width:20px;height:20px}.dcard.online .dic{background:var(--ok-wash);color:var(--ok)}.dcard.here{border:1.5px dotted color-mix(in srgb,var(--accent) 80%,transparent)}.dcard.here .dic{background:color-mix(in srgb,var(--accent) 16%,transparent);color:var(--info)}.dstat.here{color:var(--info)}.dot.here{background:var(--accent);box-shadow:0 0 0 3px color-mix(in srgb,var(--accent) 22%,transparent)}.dname{font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.dstat{display:inline-flex;align-items:center;gap:6px;font-size:13px;color:var(--muted)}.dstat.ok{color:var(--ok)}.dstat.warn{color:var(--warn)}.dot{width:6px;height:6px;border-radius:50%;background:var(--faint);display:inline-block;flex:0 0 auto}.dot.ok{background:var(--ok);box-shadow:0 0 0 3px var(--ok-wash)}.dot.warn{background:var(--warn)}.dot.pulse{animation:pulse 1.6s ease-in-out infinite}@keyframes pulse{0%,to{box-shadow:0 0 0 0 var(--warn-wash)}50%{box-shadow:0 0 0 6px transparent}}.duse{display:flex;align-items:flex-end;justify-content:space-between;gap:12px}.spark{display:flex;align-items:flex-end;gap:3px;height:26px;width:128px}.spark i{flex:1;display:block;border-radius:2px 2px 0 0;background:var(--chart);opacity:.85;cursor:default}.spark i.zero{opacity:.22}.spark i:hover{opacity:1;filter:brightness(1.2)}.names{display:flex;flex-direction:column;gap:10px;padding:12px;border-radius:12px;border:1px solid var(--line)}.names-head{display:flex;gap:10px;align-items:flex-start}.names-ic{width:28px;height:28px;border-radius:8px;display:inline-flex;align-items:center;justify-content:center;flex:none;background:color-mix(in srgb,var(--info) 14%,transparent);color:var(--info)}.names-ic .ic-svg{width:15px;height:15px}.names-list{display:flex;flex-wrap:wrap;gap:6px}.name-chip{all:unset;box-sizing:border-box;cursor:pointer;display:inline-flex;align-items:center;gap:6px;height:28px;max-width:100%;padding:0 9px 0 10px;border-radius:999px;background:var(--soft)}.name-chip:hover{background:var(--soft-hover)}.name-chip:focus-visible{outline:2px solid var(--accent);outline-offset:2px}.name-chip .mono{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.name-chip .ic-svg{width:13px;height:13px;color:var(--faint)}.slot.add{all:unset;box-sizing:border-box;cursor:pointer;display:flex;align-items:center;gap:14px;padding:16px;min-height:72px;border:1px dashed var(--input);border-radius:var(--radius);color:var(--text);text-align:left;transition:background .15s,border-color .15s}.slot.add:hover{background:var(--soft);border-color:color-mix(in srgb,var(--text) 30%,transparent)}.slot-ic{width:40px;height:40px;border-radius:12px;background:var(--soft);display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;color:var(--muted)}.slot.add:hover .slot-ic{background:var(--primary);color:var(--primary-fg)}.slot.add:focus-visible{outline:2px solid var(--accent);outline-offset:2px}@media(min-width:960px){.slot.add{flex-direction:column;justify-content:center;gap:10px;min-height:140px;text-align:center;color:var(--muted)}.slot.add .stack{align-items:center}.slot.add .strong{color:var(--text)}.slot.add .slot-ic{border-radius:999px;width:36px;height:36px}}.ic{display:inline-flex;line-height:0}.ic-svg{width:16px;height:16px}.btn{all:unset;box-sizing:border-box;cursor:pointer;display:inline-flex;align-items:center;justify-content:center;gap:8px;height:40px;padding:0 16px;border-radius:999px;font-size:14px;font-weight:500;background:var(--soft);color:var(--text);-webkit-tap-highlight-color:transparent;white-space:nowrap}.btn:hover{background:var(--soft-hover)}.btn.primary{background:var(--primary);color:var(--primary-fg)}.btn.primary:hover{opacity:.9}.btn.danger-solid{background:var(--bad);color:#fff}.btn.small{height:32px;padding:0 12px;font-size:13px}.btn.big{height:48px;font-size:15px}.btn.block{display:flex;width:100%}.btn[disabled]{opacity:.45;cursor:not-allowed}.btn:focus-visible,.kind:focus-visible,.icon-btn:focus-visible,.slot:focus-visible{outline:2px solid var(--accent);outline-offset:2px}.icon-btn{all:unset;cursor:pointer;width:36px;height:36px;display:inline-flex;align-items:center;justify-content:center;border-radius:50%;color:var(--muted);flex:0 0 auto}.icon-btn:hover{background:var(--soft);color:var(--text)}.icon-btn.soft{background:var(--soft)}@media(pointer:coarse){.icon-btn{width:40px;height:40px}}input[type=text]{width:100%;font:inherit;color:var(--text);background:var(--card);border:1px solid var(--input);border-radius:10px;padding:0 12px;height:44px}input[type=text]:focus{outline:2px solid color-mix(in srgb,var(--accent) 60%,transparent);outline-offset:0;border-color:transparent}.lbl{display:block;font-size:13px;font-weight:500;color:var(--muted);margin:14px 2px 6px}.err{color:var(--bad);min-height:1.2em;margin:8px 2px;font-size:14px}.kinds{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:6px}.kind{all:unset;box-sizing:border-box;cursor:pointer;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6px;height:68px;min-width:0;border-radius:12px;box-shadow:inset 0 0 0 1px var(--line);color:var(--muted);font-size:12.5px;font-weight:500;text-align:center}.kind .ic-svg{width:20px;height:20px}.kind:hover{color:var(--text);background:color-mix(in srgb,var(--text) 4%,transparent)}.kind.on{box-shadow:inset 0 0 0 1.5px var(--accent);color:var(--text);background:color-mix(in srgb,var(--accent) 10%,transparent)}.kind.on .ic{color:var(--accent)}.signin{text-align:center;max-width:420px;margin:8vh auto 0;width:100%;padding:28px 20px;display:flex;flex-direction:column;gap:10px}.hero-ic{width:52px;height:52px;margin:0 auto 6px;border-radius:16px;display:grid;place-items:center;background:var(--primary);color:var(--primary-fg)}.hero-ic .ic-svg{width:24px;height:24px}.signin input{text-align:center;margin-top:8px}.menu{position:absolute;z-index:30;width:230px;padding:4px;border-radius:14px;background:var(--elevated);border:1px solid var(--line);box-shadow:var(--shadow-xl)}.menu-item{all:unset;box-sizing:border-box;cursor:pointer;display:flex;align-items:center;gap:10px;width:100%;height:40px;padding:0 12px;border-radius:10px;font-size:14px}.menu-item:hover,.menu-item:focus-visible{background:var(--soft-hover)}.menu-item .ic{color:var(--muted)}.menu-item.danger,.menu-item.danger .ic{color:var(--bad)}.menu-sep{height:1px;background:var(--line);margin:4px 8px}@media(pointer:coarse){.menu-item{height:44px}}.sheet{position:fixed;inset:0;z-index:20;display:flex;align-items:flex-end;justify-content:center;background:transparent;transition:background .2s}.sheet.open{background:var(--scrim)}.sheet-panel{width:100%;max-width:520px;max-height:92vh;max-height:92dvh;overflow:auto;background:var(--elevated);border-radius:20px 20px 0 0;border:1px solid var(--line);border-bottom:0;padding:6px 16px max(20px,env(safe-area-inset-bottom));transform:translateY(100%);transition:transform .25s cubic-bezier(.2,.8,.2,1)}.sheet.open .sheet-panel{transform:none}.grab{width:36px;height:4px;border-radius:999px;background:var(--input);margin:4px auto 8px}.sheet-head{display:flex;align-items:flex-start;justify-content:space-between;gap:8px;padding:4px 0 12px}.sheet-head h2{font-size:20px;line-height:28px;font-weight:600}.sheet-body{display:flex;flex-direction:column;gap:14px}@media(min-width:640px){.sheet{align-items:center}.sheet-panel{border-radius:16px;border-bottom:1px solid var(--line);padding:20px;max-width:480px;transform:scale(.97);opacity:0;transition:transform .18s ease,opacity .18s ease}.sheet.open .sheet-panel{transform:none;opacity:1}.grab{display:none}}.tabs{display:flex;gap:4px;padding:4px;background:var(--soft);border-radius:999px}.tabs button{all:unset;cursor:pointer;flex:1 1 auto;white-space:nowrap;text-align:center;padding:7px 10px;border-radius:999px;font-weight:500;font-size:13px;color:var(--muted)}.tabs button.on{background:var(--soft-hover);color:var(--text)}.pane{display:flex;flex-direction:column;gap:10px}.pane.center{align-items:center;text-align:center}.qr{width:min(240px,70vw);aspect-ratio:1;background:#fff;border-radius:12px;padding:10px;box-shadow:inset 0 0 0 1px var(--line)}.qr svg{display:block;width:100%;height:100%}.steps{margin:4px 0 0;padding:14px 16px 14px 34px;border-radius:14px;border:1px solid var(--line);background:var(--card);display:flex;flex-direction:column;gap:8px;font-size:14px}.keybox{display:flex;align-items:center;gap:8px;height:44px;padding:0 6px 0 12px;border:1px solid var(--input);border-radius:10px}.keybox .mono{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:var(--muted)}.filecard{display:flex;align-items:center;gap:12px;padding:12px;border-radius:14px;background:var(--soft);min-width:0}.filecard>.stack{flex:1;min-width:0}.filecard-ic{width:40px;height:46px;border-radius:8px;flex:none;display:inline-flex;align-items:center;justify-content:center;font:10px var(--mono);color:var(--muted);background:var(--card);box-shadow:inset 0 0 0 1px var(--line)}.ellipsis{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}@media(max-width:480px){.filecard .ellipsis{white-space:normal;overflow-wrap:anywhere}}.confbox{border:1px solid var(--line);border-radius:12px}.confbox>summary{list-style:none;display:flex;align-items:center;gap:8px;padding:8px 10px 8px 12px;color:var(--text)}.confbox>summary::-webkit-details-marker{display:none}.confbox>summary>.ic:first-child{transition:transform .15s;color:var(--muted)}.confbox[open]>summary>.ic:first-child{transform:rotate(90deg)}.confbox .grow{flex:1}.confbox>.conf{margin:0;border-top:1px solid var(--line);border-radius:0 0 12px 12px;background:none}.conf-sec{color:var(--accent, var(--info))}.conf-k{color:var(--faint)}.conf-mask{padding:0 6px;border-radius:4px;background:var(--soft);color:var(--muted)}.conf{white-space:pre-wrap;word-break:break-all;font:12px/18px var(--mono);background:var(--soft);border-radius:10px;padding:12px;max-height:16rem;overflow:auto}details>summary{cursor:pointer;color:var(--muted);font-size:13px;font-weight:500}.waiting{display:flex;align-items:center;gap:10px;padding:12px 14px;border-radius:12px;background:var(--soft);font-size:14px}.tip{position:fixed;z-index:50;transform:translate(-50%,-100%);padding:6px 10px;border-radius:10px;font-size:12px;line-height:17px;white-space:nowrap;background:var(--elevated);border:1px solid var(--line);box-shadow:var(--shadow-xl);pointer-events:none}.tip-title{font-weight:500}.toast{position:fixed;left:50%;bottom:max(20px,env(safe-area-inset-bottom));transform:translate(-50%,20px);opacity:0;z-index:60;background:var(--primary);color:var(--primary-fg);padding:10px 16px;border-radius:999px;font-weight:500;font-size:14px;transition:all .25s;max-width:90vw}.toast.show{opacity:1;transform:translate(-50%)}.toast.bad{background:var(--bad);color:#fff}@media(prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}} 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 0e21338..6c387e9 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 tt=Object.create;var $e=Object.defineProperty;var nt=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var at=Object.getPrototypeOf,it=Object.prototype.hasOwnProperty;var st=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var ot=(n,e,a,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let v of rt(e))!it.call(n,v)&&v!==a&&$e(n,v,{get:()=>e[v],enumerable:!(o=nt(e,v))||o.enumerable});return n};var lt=(n,e,a)=>(a=n!=null?tt(at(n)):{},ot(e||!n||!n.__esModule?$e(a,"default",{value:n,enumerable:!0}):a,n));var Ue=st((Oe,Ke)=>{"use strict";var Ie=(function(){var n=function(M,k){var w=236,b=17,l=M,m=a[k],i=null,r=0,y=null,f=[],g={},T=function(c,u){r=l*4+17,i=(function(s){for(var d=new Array(s),h=0;h=7&&z(c),y==null&&(y=Xe(l,m,f)),W(y,u)},E=function(c,u){for(var s=-1;s<=7;s+=1)if(!(c+s<=-1||r<=c+s))for(var d=-1;d<=7;d+=1)u+d<=-1||r<=u+d||(0<=s&&s<=6&&(d==0||d==6)||0<=d&&d<=6&&(s==0||s==6)||2<=s&&s<=4&&2<=d&&d<=4?i[c+s][u+d]=!0:i[c+s][u+d]=!1)},P=function(){for(var c=0,u=0,s=0;s<8;s+=1){T(!0,s);var d=v.getLostPoint(g);(s==0||c>d)&&(c=d,u=s)}return u},I=function(){for(var c=8;c>s&1)==1;i[Math.floor(s/3)][s%3+r-8-3]=d}for(var s=0;s<18;s+=1){var d=!c&&(u>>s&1)==1;i[s%3+r-8-3][Math.floor(s/3)]=d}},Q=function(c,u){for(var s=m<<3|u,d=v.getBCHTypeInfo(s),h=0;h<15;h+=1){var x=!c&&(d>>h&1)==1;h<6?i[h][8]=x:h<8?i[h+1][8]=x:i[r-15+h][8]=x}for(var h=0;h<15;h+=1){var x=!c&&(d>>h&1)==1;h<8?i[8][r-h-1]=x:h<9?i[8][15-h-1+1]=x:i[8][15-h-1]=x}i[r-8][8]=!c},W=function(c,u){for(var s=-1,d=r-1,h=7,x=0,C=v.getMaskFunction(u),A=r-1;A>0;A-=2)for(A==6&&(A-=1);;){for(var S=0;S<2;S+=1)if(i[d][A-S]==null){var K=!1;x>>h&1)==1);var L=C(d,A-S);L&&(K=!K),i[d][A-S]=K,h-=1,h==-1&&(x+=1,h=7)}if(d+=s,d<0||r<=d){d-=s,s=-s;break}}},re=function(c,u){for(var s=0,d=0,h=0,x=new Array(u.length),C=new Array(u.length),A=0;A=0?Ee.getAt(Be):0}}for(var De=0,L=0;LA*8)throw"code length overflow. ("+h.getLengthInBits()+">"+A*8+")";for(h.getLengthInBits()+4<=A*8&&h.put(0,4);h.getLengthInBits()%8!=0;)h.putBit(!1);for(;!(h.getLengthInBits()>=A*8||(h.put(w,8),h.getLengthInBits()>=A*8));)h.put(b,8);return re(h,d)};g.addData=function(c,u){u=u||"Byte";var s=null;switch(u){case"Numeric":s=D(c);break;case"Alphanumeric":s=F(c);break;case"Byte":s=J(c);break;case"Kanji":s=U(c);break;default:throw"mode:"+u}f.push(s),y=null},g.isDark=function(c,u){if(c<0||r<=c||u<0||r<=u)throw c+","+u;return i[c][u]},g.getModuleCount=function(){return r},g.make=function(){if(l<1){for(var c=1;c<40;c++){for(var u=$.getRSBlocks(c,m),s=B(),d=0;d";for(var h=0;h';s+=""}return s+="",s+="",s},g.createSvgTag=function(c,u,s,d){var h={};typeof arguments[0]=="object"&&(h=arguments[0],c=h.cellSize,u=h.margin,s=h.alt,d=h.title),c=c||2,u=typeof u=="undefined"?c*4:u,s=typeof s=="string"?{text:s}:s||{},s.text=s.text||null,s.id=s.text?s.id||"qrcode-description":null,d=typeof d=="string"?{text:d}:d||{},d.text=d.text||null,d.id=d.text?d.id||"qrcode-title":null;var x=g.getModuleCount()*c+u*2,C,A,S,K,L="",Y;for(Y="l"+c+",0 0,"+c+" -"+c+",0 0,-"+c+"z ",L+=''+ae(d.text)+"":"",L+=s.text?''+ae(s.text)+"":"",L+='',L+='":u+=">";break;case"&":u+="&";break;case'"':u+=""";break;default:u+=d;break}}return u},et=function(c){var u=1;c=typeof c=="undefined"?u*2:c;var s=g.getModuleCount()*u+c*2,d=c,h=s-c,x,C,A,S,K,L={"██":"█","█ ":"▀"," █":"▄"," ":" "},Y={"██":"▀","█ ":"▀"," █":" "," ":" "},j="";for(x=0;x=h?Y[K]:L[K];j+=` -`}return s%2&&c>0?j.substring(0,j.length-s-1)+Array(s+1).join("▀"):j.substring(0,j.length-1)};return g.createASCII=function(c,u){if(c=c||1,c<2)return et(u);c-=1,u=typeof u=="undefined"?c*2:u;var s=g.getModuleCount()*c+u*2,d=u,h=s-u,x,C,A,S,K=Array(c+1).join("██"),L=Array(c+1).join(" "),Y="",j="";for(x=0;x>>8),m.push(y&255)):m.push(b)}}return m}};var e={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},a={L:1,M:0,Q:3,H:2},o={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},v=(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]],k=1335,w=7973,b=21522,l={},m=function(i){for(var r=0;i!=0;)r+=1,i>>>=1;return r};return l.getBCHTypeInfo=function(i){for(var r=i<<10;m(r)-m(k)>=0;)r^=k<=0;)r^=w<5&&(y+=3+T-5)}for(var f=0;f=256;)l-=255;return M[l]},b})();function _(M,k){if(typeof M.length=="undefined")throw M.length+"/"+k;var w=(function(){for(var l=0;l>>7-b%8&1)==1},w.put=function(b,l){for(var m=0;m>>l-m-1&1)==1)},w.getLengthInBits=function(){return k},w.putBit=function(b){var l=Math.floor(k/8);M.length<=l&&M.push(0),b&&(M[l]|=128>>>k%8),k+=1},w},D=function(M){var k=e.MODE_NUMBER,w=M,b={};b.getMode=function(){return k},b.getLength=function(i){return w.length},b.write=function(i){for(var r=w,y=0;y+2>>8&255)*192+(f&255),i.put(f,13),y+=2}if(y>>8)},k.writeBytes=function(w,b,l){b=b||0,l=l||w.length;for(var m=0;m0&&(w+=","),w+=M[b];return w+="]",w},k},G=function(){var M=0,k=0,w=0,b="",l={},m=function(r){b+=String.fromCharCode(i(r&63))},i=function(r){if(!(r<0)){if(r<26)return 65+r;if(r<52)return 97+(r-26);if(r<62)return 48+(r-52);if(r==62)return 43;if(r==63)return 47}throw"n:"+r};return l.writeByte=function(r){for(M=M<<8|r&255,k+=8,w+=1;k>=6;)m(M>>>k-6),k-=6},l.flush=function(){if(k>0&&(m(M<<6-k),M=0,k=0),w%3!=0)for(var r=3-w%3,y=0;y=k.length){if(l==0)return-1;throw"unexpected end of file./"+l}var r=k.charAt(w);if(w+=1,r=="=")return l=0,-1;if(r.match(/^\s$/))continue;b=b<<6|i(r.charCodeAt(0)),l+=6}var y=b>>>l-8&255;return l-=8,y};var i=function(r){if(65<=r&&r<=90)return r-65;if(97<=r&&r<=122)return r-97+26;if(48<=r&&r<=57)return r-48+52;if(r==43)return 62;if(r==47)return 63;throw"c:"+r};return m},ne=function(M,k){var w=M,b=k,l=new Array(M*k),m={};m.setPixel=function(f,g,T){l[g*w+f]=T},m.write=function(f){f.writeString("GIF87a"),f.writeShort(w),f.writeShort(b),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(w),f.writeShort(b),f.writeByte(0);var g=2,T=r(g);f.writeByte(g);for(var E=0;T.length-E>255;)f.writeByte(255),f.writeBytes(T,E,255),E+=255;f.writeByte(T.length-E),f.writeBytes(T,E,T.length-E),f.writeByte(0),f.writeString(";")};var i=function(f){var g=f,T=0,E=0,P={};return P.write=function(I,q){if(I>>>q)throw"length over";for(;T+q>=8;)g.writeByte(255&(I<>>=8-T,E=0,T=0;E=I<0&&g.writeByte(E)},P},r=function(f){for(var g=1<>6,128|p&63):p<55296||p>=57344?o.push(224|p>>12,128|p>>6&63,128|p&63):(v++,p=65536+((p&1023)<<10|a.charCodeAt(v)&1023),o.push(240|p>>18,128|p>>12&63,128|p>>6&63,128|p&63))}return o}return e(n)}})();(function(n){typeof define=="function"&&define.amd?define([],n):typeof Oe=="object"&&(Ke.exports=n())})(function(){return Ie})});function ee(n){if(!n||n<0)return"0 B";let e=["B","KB","MB","GB","TB"],a=0,o=n;for(;o>=1024&&a=100||a===0?Math.round(o):o.toFixed(1)} ${e[a]}`}function ye(n,e=Date.now()/1e3){if(!n)return"never";let a=Math.max(0,Math.round(e-n));return a<60?"just now":a<3600?`${Math.floor(a/60)} min ago`:a<86400?`${Math.floor(a/3600)} h ago`:a<86400*30?`${Math.floor(a/86400)} d ago`:new Date(n*1e3).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function we(n){if(!n)return"";let[e,a,o]=n.split("-").map(Number);return new Date(e,a-1,o).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function be(n,e=Date.now()){if(!n)return null;let[a,o,v]=n.split("-").map(Number),p=new Date(a,o-1,v,23,59,59).getTime();return Math.ceil((p-e)/864e5)}var Pe={lan:"Home network",internet:"Internet",both:"Home network + Internet"};var ue={computer:"PC",phone:"Phone",tablet:"Tablet",router:"Router",other:"Other"},Se={active:"Active",paused:"Paused",paused_all:"Paused (everyone)",expired:"Expired",quota:"Data limit reached",hours:"Outside allowed hours",no_server:"No server"};function Re(n){var v,p,_;let e=n.trim().split(/\s+/).filter(Boolean);if(!e.length)return"?";let a=(v=e[0][0])!=null?v:"",o=e.length>1?(p=e[e.length-1][0])!=null?p:"":(_=e[0][1])!=null?_:"";return(a+o).toUpperCase()}var Ne={phone:'',computer:'',tablet:'',router:'',other:'',ethernet:'',bridge:'',wifi:'',tunnel:'',plus:'',chart:'',reset:'',package:'',code:'',plug:'',sunrise:'',refresh:'',archive:'',qr:'',copy:'',download:'',link:'',trash:'',edit:'',pause:'',play:'',key:'',out:'',shield:'',shieldplus:'',lock:'',zap:'',check:'',alert:'',x:'',globe:'',home:'',open:'',file:'',search:'',network:'',moon:'',chevron:'',clock:'',calendar:'',minus:'',more:'',pin:'',activity:''};function He(n,e="dl-icon"){var o;let a=(o=Ne[n])!=null?o:Ne.phone;return``}var Ge=lt(Ue(),1),ct='';function qe(n,e=3,a=!0){let o=(0,Ge.default)(0,n.length>300?"Q":"H");o.addData(n,"Byte"),o.make();let v=o.getModuleCount(),p=v+e*2,_=a?Math.round(v*.22):0;_&&(v-_)%2&&_++;let $=(v-_)/2,B=$+_,D=(U,N)=>_>0&&U>=$&&U=$&&N${ct}`}return`${J}`}var ut={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:""},ft={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 dt(n){let e={};for(let[a,o]of Object.entries(ft))n[a]!=null&&n[a]!==""&&(e[o]=String(n[a]));return e}function ht(n,e){var B;let a=n.amnezia,o=(B=a.obfuscation)!=null?B:{},v=D=>o[D]!=null&&o[D]!==""?String(o[D]):ut[D],p=a.host.replace(/^\[(.*)\]$/,"$1"),_={H1:v("h1"),H2:v("h2"),H3:v("h3"),H4:v("h4"),I1:v("i1"),I2:v("i2"),I3:v("i3"),I4:v("i4"),I5:v("i5"),Jc:v("jc"),Jmin:v("jmin"),Jmax:v("jmax"),S1:v("s1"),S2:v("s2"),S3:v("s3"),S4:v("s4"),...dt(o),allowed_ips:a.allowed_ips,client_ip:a.client_ip,client_priv_key:a.client_priv_key,client_pub_key:a.client_pub_key,config:n.conf.replace(/\r?\n/g,`\r -`),hostName:p,mtu:a.mtu,persistent_keep_alive:a.persistent_keep_alive,port:Number(a.port),psk_key:a.psk_key,server_pub_key:a.server_pub_key},$={containers:[{container:"amnezia-awg",awg:{isThirdPartyConfig:!0,last_config:JSON.stringify(_),port:String(a.port),protocol_version:o.header_protection_key?"3.1":"2",transport_proto:"udp"}}],defaultContainer:"amnezia-awg",description:e,hostName:p};return a.dns[0]&&($.dns1=a.dns[0]),a.dns[1]&&($.dns2=a.dns[1]),$}function vt(n){let e="";for(let a=0;a{p==null||p===!1||(Array.isArray(p)?p.forEach(v):o.appendChild(typeof p=="string"?document.createTextNode(p):p))};return a.forEach(v),o}function O(n){let e=t("span",{class:"ic"});return e.innerHTML=He(n,"ic-svg"),e}var gt='',Ce=document.getElementById("app"),Ye,de=(Ye=Ce.dataset.base)!=null?Ye:"",mt=Ce.dataset.title||"Dawnline",ke=()=>window.matchMedia("(max-width: 959px)").matches||/Android|iPhone|iPad/.test(navigator.userAgent),R=null,Fe=0,yt=/^\/[a-z]{6}-[a-z]{6}-[a-z]{6}$/.test(de)?de.slice(1):"",Ae=class extends Error{constructor(a,o){super(o);this.status=a}};async function oe(n,e){var v;let a=await fetch(`${de}/api/${n}`,{method:e===void 0?"GET":"POST",credentials:"omit",headers:e===void 0?{}:{"Content-Type":"application/json"},body:e===void 0?void 0:JSON.stringify(e),cache:"no-store"}),o=null;try{o=await a.json()}catch{}if(!a.ok)throw new Ae(a.status,(v=o==null?void 0:o.error)!=null?v:`Request failed (${a.status})`);return o}function se(n,e=!1){let a=t("div",{class:`toast${e?" bad":""}`,role:"status"},n);document.body.appendChild(a),requestAnimationFrame(()=>a.classList.add("show")),setTimeout(()=>{a.classList.remove("show"),setTimeout(()=>a.remove(),300)},2600)}async function ve(n,e="Copied"){try{await navigator.clipboard.writeText(n)}catch{let a=t("textarea",{class:"offscreen"},n);document.body.appendChild(a),a.select(),document.execCommand("copy"),a.remove()}se(e)}function je(n,e){let a=URL.createObjectURL(new Blob([e],{type:"application/octet-stream"})),o=t("a",{href:a,download:n,class:"offscreen"});document.body.appendChild(o),o.click(),setTimeout(()=>{URL.revokeObjectURL(a),o.remove()},1e3)}var Z=null;function ze(n,e){let a=o=>{Z!=null||(Z=document.body.appendChild(t("div",{class:"tip"}))),Z.replaceChildren(...e().map((v,p)=>t("div",{class:p?"muted":"tip-title"},v))),Z.style.display="",Z.style.left=`${o.clientX}px`,Z.style.top=`${o.clientY-10}px`};n.addEventListener("mouseenter",a),n.addEventListener("mousemove",a),n.addEventListener("mouseleave",()=>Z&&(Z.style.display="none"))}function wt(n){let e=Math.max(1,...n),a=t("div",{class:"spark"});return n.forEach((o,v)=>{let p=t("i",{class:o?"":"zero"});p.style.height=`${Math.max(8,o/e*100)}%`;let _=n.length-1-v,$=new Date(Date.now()-_*864e5);ze(p,()=>[_===0?"Today":_===1?"Yesterday":$.toLocaleDateString("en-GB",{weekday:"short",day:"numeric",month:"short"}),ee(o)]),a.appendChild(p)}),a}var ie=null,le=null;function te(n=!1){if(!ie)return;let e=ie;if(ie=null,document.body.classList.remove("locked"),le==null||le(),le=null,n){e.remove();return}e.classList.remove("open"),setTimeout(()=>e.remove(),250)}function pe(n,e,...a){let o=!!ie;te(!0);let v=t("div",{class:"sheet-panel",role:"dialog","aria-modal":"true","aria-label":n},t("div",{class:"grab"}),t("div",{class:"sheet-head"},t("div",{class:"stack"},t("h2",{},n),e?t("span",{class:"muted s"},e):null),t("button",{class:"icon-btn","aria-label":"Close",onclick:()=>te()},O("x"))),t("div",{class:"sheet-body"},...a)),p=t("div",{class:"sheet",onclick:_=>{_.target===p&&te()}},v);return document.body.appendChild(p),document.body.classList.add("locked"),o?p.classList.add("open"):requestAnimationFrame(()=>p.classList.add("open")),ie=p,v}document.addEventListener("keydown",n=>{n.key==="Escape"&&(he(),te())});var X=null;function he(){X==null||X.remove(),X=null}document.addEventListener("click",n=>{X&&!X.contains(n.target)&&he()});function bt(n,e){he();let a=t("div",{class:"menu",role:"menu"},e.map(p=>p?t("button",{type:"button",role:"menuitem",class:`menu-item${p.danger?" danger":""}`,onclick:()=>{he(),p.run()}},O(p.icon),t("span",{},p.label)):t("div",{class:"menu-sep"})));document.body.appendChild(a);let o=n.getBoundingClientRect(),v=230;a.style.left=`${Math.max(8,Math.min(window.innerWidth-v-8,o.right-v))}px`,a.style.top=`${o.bottom+6+window.scrollY}px`,X=a}function Le(...n){Ce.replaceChildren(t("header",{class:"top"},t("div",{class:"brand"},(()=>{let e=t("span",{class:"logo"});return e.innerHTML=gt,e})(),t("span",{},(R==null?void 0:R.server.name)||mt),t("span",{class:"faint"},"· Dawnline"))),t("main",{class:"wrap"},...n))}function Je(){Le(t("div",{class:"card signin"},t("div",{class:"hero-ic"},O("key")),t("h1",{},"This link no longer works"),t("p",{class:"muted"},"Ask for a new personal link.")))}function xt(n){return n.state==="active"?"ok":n.state==="quota"||n.state==="expired"?"bad":"warn"}var Mt={internet:"The internet, through the router",lan:"Devices at home",both:"Devices at home and the internet, through the router"};function kt(n){let e=n.person,a=e.quota_limit?Math.min(100,e.quota_used/e.quota_limit*100):0,o=t("div",{class:`meter${a>=100?" bad":a>=90?" warn":""}`},t("i"));o.firstChild.style.width=`${a}%`,e.quota_limit&&ze(o,()=>[`${a.toFixed(1)}% used`,`${ee(Math.max(0,e.quota_limit-e.quota_used))} left`]);let v=be(e.expires),p=t("div",{class:"slots"});for(let B=0;B=0?`${v} day${v===1?"":"s"} left`:"ended"):null)),t("span",{class:"faint s"},e.hours?`Available ${e.hours.replace("-","–")} (router time). Need a change? Ask the admin.`:"Need a change? Ask the admin.")))}function At(n){return n.disabled?t("span",{class:"dstat"},t("i",{class:"dot"}),"Disabled by the admin"):n.online?t("span",{class:"dstat ok"},t("i",{class:"dot ok"}),"Connected"):n.handshake?t("span",{class:"dstat"},t("i",{class:"dot"}),`Last connected ${ye(n.handshake)}`):t("span",{class:"dstat warn"},t("i",{class:"dot warn"}),"Not set up yet")}function _t(n,e){return!n.hostname||e.access==="internet"?null:t("div",{class:"dfoot"},t("span",{class:"faint s"},"Local address"),t("button",{type:"button",class:"lan-pill","aria-label":`Copy ${n.hostname}`,onclick:()=>ve(n.hostname,"Address copied")},t("span",{class:"lan-ic"},O("home")),t("span",{class:"mono"},n.hostname),t("span",{class:"lan-sep"}),O("copy")))}function Ct(n,e){let a=e.person,o=t("button",{type:"button",class:"icon-btn soft","aria-label":`${n.name} options`},O("more"));o.addEventListener("click",_=>{_.stopPropagation(),bt(o,[{label:"Show QR code",icon:"qr",run:()=>fe(n,"qr")},{label:"Copy AmneziaVPN key",icon:"key",run:()=>Lt(n)},{label:"Download .conf",icon:"download",run:()=>Tt(n)},null,{label:"Rename",icon:"edit",run:()=>Bt(n)},{label:"Remove",icon:"trash",danger:!0,run:()=>Dt(n)}])});let v=n.spark.reduce((_,$)=>_+$,0),p=!n.handshake&&!n.disabled;return t("article",{class:`dcard${n.online?" online":""}${n.disabled?" off":""}`},t("div",{class:"dhead"},t("span",{class:"dic"},O(n.kind)),t("div",{class:"stack grow"},t("span",{class:"dname"},n.name),At(n)),o),p?[t("button",{type:"button",class:"btn primary block",onclick:()=>fe(n)},O(ke()?"open":"qr"),t("span",{},ke()?"Open in AmneziaVPN":"Connect this device")),t("span",{class:"faint s center"},"Setting up another device? QR, key and file are under ⋯")]:t("div",{class:"duse"},t("div",{class:"stack"},t("span",{class:"faint s"},"Last 7 days"),t("span",{class:"mono"},ee(v))),wt(n.spark)),n.config_stale&&!p?t("div",{class:"notice"},O("alert"),t("span",{class:"grow"},"Connection settings changed. Update this device to keep everything working."),t("button",{type:"button",class:"btn small",onclick:()=>fe(n)},"Update")):null,_t(n,a))}function ge(n){let e=n.person,a=be(e.expires),o=e.state!=="active"?t("div",{class:"notice bad"},O("alert"),t("span",{},e.state==="quota"?"You have used all your data for this period. Your devices are paused until it resets.":e.state==="expired"?"Your access has ended. Ask the admin to extend it.":e.state==="hours"?`Access is available ${e.hours.replace("-","–")} (router time).`:"Your access is paused by the admin.")):a!=null&&a>=0&&a<=Math.max(e.expire_warn,1)?t("div",{class:"notice"},O("alert"),t("span",{},`Your access ends ${a===0?"today":`in ${a} day${a===1?"":"s"}`} (${we(e.expires)}).`)):null,v=e.devices.map($=>Ct($,n)),p=Math.max(0,e.device_limit-e.devices.length);p&&v.push(t("button",{type:"button",class:"slot add",onclick:Rt},t("span",{class:"slot-ic"},O("plus")),t("span",{class:"stack"},t("span",{class:"strong"},"Add device"),t("span",{class:"faint s"},`${p} slot${p===1?"":"s"} free`))));let _=t("section",{class:"devices","aria-label":"Your devices"},t("div",{class:"card-head"},t("div",{class:"row-baseline"},t("h2",{},"Your devices"),t("span",{class:"faint s"},`${e.devices.length} of ${e.device_limit} · ${e.online} online`))),t("div",{class:"dgrid"},v),n.can_add?null:t("span",{class:"faint s"},`You have reached your limit of ${e.device_limit} devices. Remove one or ask the admin for more.`),t("span",{class:"faint s"},"New device? Install ",t("a",{href:"https://amnezia.org/downloads",target:"_blank",rel:"noopener noreferrer"},"AmneziaVPN")," on it first."));Le(t("div",{class:"hello"},t("span",{class:`avatar${e.online?" online":""}`},Re(e.name)),t("div",{class:"stack"},t("div",{class:"row"},t("h1",{},`Hi, ${e.name}`),t("span",{class:`pill ${xt(e)}`},Se[e.state])),t("span",{class:"faint s"},`${e.online?`${e.online} device${e.online===1?"":"s"} online`:"Nothing connected right now"} · ${ee(e.month[0]+e.month[1])} this month`))),o,t("div",{class:"layout"},kt(n),_))}async function Te(n){try{return await oe(`devices/${n.id}/config`)}catch(e){return se(e.message,!0),null}}async function Lt(n){let e=await Te(n);e&&ve(await xe(e,`${e.server} · ${e.name}`),"Key copied")}async function Tt(n){let e=await Te(n);e&&je(e.filename,e.conf)}function Ve(n,e){if(/^\s*\[.+\]\s*$/.test(n))return t("span",{class:"conf-sec"},n);let a=/^(\s*[A-Za-z0-9]+\s*=)\s*(.*)$/.exec(n);if(!a)return document.createTextNode(n);let o=/^(\s*)(PrivateKey|PresharedKey)\b/.test(n);return t("span",{},t("span",{class:"conf-k"},a[1])," ",o&&!e?t("span",{class:"conf-mask"},"••••••••••••••••"):a[2])}function Et(n){let e=!1,a=t("pre",{class:"conf"}),o=()=>a.replaceChildren(...n.conf.split(` -`).flatMap((p,_)=>_?[` -`,Ve(p,e)]:[Ve(p,e)])),v=t("button",{class:"btn small",onclick:p=>{p.preventDefault(),e=!e,v.replaceChildren(O(e?"x":"key"),t("span",{},e?"Hide key":"Show key")),o()}},O("key"),t("span",{},"Show key"));return o(),t("div",{class:"pane"},t("div",{class:"filecard"},t("span",{class:"filecard-ic"},".conf"),t("span",{class:"stack"},t("span",{class:"mono ellipsis"},n.filename),t("span",{class:"faint s"},"For computers and routers: import it in AmneziaWG or AmneziaVPN")),t("button",{class:"btn primary",onclick:()=>je(n.filename,n.conf)},O("download"),t("span",{},"Download"))),t("details",{class:"confbox"},t("summary",{},O("chevron"),t("span",{},"Configuration"),t("span",{class:"grow"}),v,t("button",{class:"btn small",onclick:p=>{p.preventDefault(),ve(n.conf,"Configuration copied")}},O("copy"),t("span",{},"Copy"))),a))}async function fe(n,e,a){let o=a!=null?a:await Te(n);if(!o)return;let v=await xe(o,`${o.server} · ${o.name}`),p=ke(),_={app:()=>t("div",{class:"pane"},t("a",{class:"btn primary block big",href:v},O("open"),t("span",{},"Open in AmneziaVPN")),t("ol",{class:"steps"},t("li",{},"No AmneziaVPN yet? ",t("a",{href:"https://amnezia.org/downloads",target:"_blank",rel:"noopener noreferrer"},"Get it here"),"."),t("li",{},"Tap ",t("b",{},"Open in AmneziaVPN")," and confirm the import."),t("li",{},"Turn the connection on — this page shows ",t("span",{class:"ok"},"Connected")," within a minute."))),qr:()=>{let H=t("div",{class:"qr"});return H.innerHTML=qe(o.conf),t("div",{class:"pane center"},H,t("p",{class:"muted s"},"Scan with the phone’s camera or AmneziaVPN / AmneziaWG."))},key:()=>t("div",{class:"pane"},t("p",{class:"muted s"},"In AmneziaVPN choose “Add server → Insert key”."),t("div",{class:"keybox"},t("span",{class:"mono"},v),t("button",{class:"btn small",onclick:()=>ve(v,"Key copied")},"Copy")),t("p",{class:"faint s"},"Keep it private: anyone with the key can use your connection.")),file:()=>Et(o)},$=p?["app","qr","key","file"]:["qr","key","file"],B={app:"Open in app",qr:"QR code",key:"Key",file:"File"},D=t("div",{class:"tab-body"}),F=t("div",{class:"tabs",role:"tablist"}),J=H=>{F.querySelectorAll("button").forEach(ne=>ne.classList.toggle("on",ne.dataset.id===H)),D.replaceChildren(_[H]())};for(let H of $)F.appendChild(t("button",{role:"tab","data-id":H,onclick:()=>J(H)},B[H]));J(e&&$.includes(e)?e:$[0]);let U=t("div",{class:"waiting"}),N=H=>{H!=null&&H.online?U.replaceChildren(t("i",{class:"dot ok"}),t("span",{class:"ok"},`${n.name} is connected`)):H!=null&&H.handshake?U.replaceChildren(t("i",{class:"dot"}),t("span",{class:"muted"},`Last connected ${ye(H.handshake)}`)):U.replaceChildren(t("i",{class:"dot warn pulse"}),t("span",{class:"muted"},"Waiting for the first connection…"))};N(n);let G=window.setInterval(async()=>{try{let H=await oe("state");R=H,N(H.person.devices.find(ne=>ne.id===n.id))}catch{}},5e3);pe(n.handshake?`Connect ${n.name}`:`${n.name} is ready`,p?"Add it to AmneziaVPN on this phone":"Scan with the phone’s camera or AmneziaVPN",F,D,U),le=()=>{clearInterval(G),R&&ge(R)}}function Bt(n){let e=t("input",{type:"text",value:n.name,maxlength:48,"aria-label":"Device name"});pe(`Rename ${n.name}`,null,t("form",{class:"stack gap",onsubmit:async a=>{a.preventDefault();try{R=(await oe(`devices/${n.id}`,{action:"rename",name:e.value})).state,te(),ge(R),se("Renamed")}catch(o){se(o.message,!0)}}},e,t("button",{class:"btn primary block",type:"submit"},"Save"))),setTimeout(()=>e.select(),50)}function Dt(n){pe(`Remove ${n.name}?`,null,t("p",{class:"muted"},"Its connection stops working immediately. You can add it again later."),t("div",{class:"row gap"},t("button",{class:"btn block",onclick:()=>te()},"Cancel"),t("button",{class:"btn danger-solid block",onclick:async()=>{try{R=(await oe(`devices/${n.id}`,{action:"delete"})).state,te(),ge(R),se("Device removed")}catch(e){se(e.message,!0)}}},"Remove")))}var V=navigator.userAgent,Qe=/iPad/.test(V)||/Macintosh/.test(V)&&navigator.maxTouchPoints>1;function Me(){return Qe||/Tablet/i.test(V)||/Android/.test(V)&&!/Mobile/.test(V)?"tablet":/Android|iPhone|Mobile/i.test(V)?"phone":"computer"}var $t=[[/^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"]],_e="",Pt=(async()=>{var e;let n=navigator.userAgentData;if(!n||!/Android/.test(V))return"";try{let a=((e=(await n.getHighEntropyValues(["model"])).model)!=null?e:"").trim();if(!a||a==="K")return"";let o=$t.find(([v])=>v.test(a));_e=o?`${o[1]} (${a})`:/^SM-/.test(a)?`Galaxy ${a}`:a}catch{}return _e})();function St(n){return/iPhone/.test(V)?"iPhone":Qe?"iPad":/Android/.test(V)?_e||(n==="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":ue[n]}function Rt(){if(!R)return;let n=Me(),e=new Set(R.person.devices.map(B=>B.name.toLowerCase())),a=B=>{let D=B===Me()?St(B):ue[B];if(!e.has(D.toLowerCase()))return D;for(let F=2;F<20;F++)if(!e.has(`${D} ${F}`.toLowerCase()))return`${D} ${F}`;return D},o=t("input",{type:"text",value:a(n),maxlength:48,"aria-label":"Device name",required:!0}),v=!1;o.addEventListener("input",()=>v=!0),Pt.then(()=>{!v&&n===Me()&&(o.value=a(n))});let p=t("div",{class:"kinds"},R.kinds.map(B=>t("button",{type:"button",class:`kind${B===n?" on":""}`,"data-k":B,onclick:()=>{n=B,p.querySelectorAll(".kind").forEach(D=>D.classList.toggle("on",D.dataset.k===B)),v||(o.value=a(B))}},O(B),t("span",{},ue[B])))),_=t("p",{class:"err"}),$=t("button",{class:"btn primary block",type:"submit"},"Create connection");pe("Add a device",`${R.person.device_limit-R.person.devices.length} of ${R.person.device_limit} slots free`,t("form",{class:"add",onsubmit:async B=>{B.preventDefault(),$.disabled=!0,_.textContent="";try{let D=await oe("devices",{name:o.value.trim(),kind:n});R=D.state;let F=D.state.person.devices.find(J=>J.id===D.id);await fe(F,void 0,D.config)}catch(D){_.textContent=D.message,$.disabled=!1}}},t("label",{class:"lbl"},"What is it?"),p,t("label",{class:"lbl"},"Name"),o,_,$))}async function We(){try{R=await oe("state"),document.title=`${R.person.name} · ${R.title}`,!ie&&!X&&ge(R)}catch(n){let e=n;e.status===404||e.status===401?(R=null,Je()):R||Le(t("div",{class:"card"},t("p",{},e.message)))}}function Nt(){clearInterval(Fe),Fe=window.setInterval(()=>{R&&document.visibilityState==="visible"&&We()},15e3)}!de||!yt?Je():(We(),Nt());})(); +"use strict";(()=>{var rt=Object.create;var Pe=Object.defineProperty;var at=Object.getOwnPropertyDescriptor;var st=Object.getOwnPropertyNames;var it=Object.getPrototypeOf,ot=Object.prototype.hasOwnProperty;var lt=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var ct=(t,e,a,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let v of st(e))!ot.call(t,v)&&v!==a&&Pe(t,v,{get:()=>e[v],enumerable:!(i=at(e,v))||i.enumerable});return t};var ut=(t,e,a)=>(a=t!=null?rt(it(t)):{},ct(e||!t||!t.__esModule?Pe(a,"default",{value:t,enumerable:!0}):a,t));var Ge=lt((Ke,Ue)=>{"use strict";var Oe=(function(){var t=function(M,k){var b=236,w=17,l=M,m=a[k],s=null,r=0,y=null,f=[],g={},T=function(c,u){r=l*4+17,s=(function(o){for(var d=new Array(o),p=0;p=7&&z(c),y==null&&(y=tt(l,m,f)),W(y,u)},E=function(c,u){for(var o=-1;o<=7;o+=1)if(!(c+o<=-1||r<=c+o))for(var d=-1;d<=7;d+=1)u+d<=-1||r<=u+d||(0<=o&&o<=6&&(d==0||d==6)||0<=d&&d<=6&&(o==0||o==6)||2<=o&&o<=4&&2<=d&&d<=4?s[c+o][u+d]=!0:s[c+o][u+d]=!1)},P=function(){for(var c=0,u=0,o=0;o<8;o+=1){T(!0,o);var d=v.getLostPoint(g);(o==0||c>d)&&(c=d,u=o)}return u},H=function(){for(var c=8;c>o&1)==1;s[Math.floor(o/3)][o%3+r-8-3]=d}for(var o=0;o<18;o+=1){var d=!c&&(u>>o&1)==1;s[o%3+r-8-3][Math.floor(o/3)]=d}},Q=function(c,u){for(var o=m<<3|u,d=v.getBCHTypeInfo(o),p=0;p<15;p+=1){var x=!c&&(d>>p&1)==1;p<6?s[p][8]=x:p<8?s[p+1][8]=x:s[r-15+p][8]=x}for(var p=0;p<15;p+=1){var x=!c&&(d>>p&1)==1;p<8?s[8][r-p-1]=x:p<9?s[8][15-p-1+1]=x:s[8][15-p-1]=x}s[r-8][8]=!c},W=function(c,u){for(var o=-1,d=r-1,p=7,x=0,C=v.getMaskFunction(u),_=r-1;_>0;_-=2)for(_==6&&(_-=1);;){for(var R=0;R<2;R+=1)if(s[d][_-R]==null){var K=!1;x>>p&1)==1);var L=C(d,_-R);L&&(K=!K),s[d][_-R]=K,p-=1,p==-1&&(x+=1,p=7)}if(d+=o,d<0||r<=d){d-=o,o=-o;break}}},ae=function(c,u){for(var o=0,d=0,p=0,x=new Array(u.length),C=new Array(u.length),_=0;_=0?De.getAt(Be):0}}for(var $e=0,L=0;L_*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(w,8);return ae(p,d)};g.addData=function(c,u){u=u||"Byte";var o=null;switch(u){case"Numeric":o=B(c);break;case"Alphanumeric":o=F(c);break;case"Byte":o=J(c);break;case"Kanji":o=U(c);break;default:throw"mode:"+u}f.push(o),y=null},g.isDark=function(c,u){if(c<0||r<=c||u<0||r<=u)throw c+","+u;return s[c][u]},g.getModuleCount=function(){return r},g.make=function(){if(l<1){for(var c=1;c<40;c++){for(var u=$.getRSBlocks(c,m),o=D(),d=0;d";for(var p=0;p';o+=""}return o+="",o+="",o},g.createSvgTag=function(c,u,o,d){var p={};typeof arguments[0]=="object"&&(p=arguments[0],c=p.cellSize,u=p.margin,o=p.alt,d=p.title),c=c||2,u=typeof u=="undefined"?c*4:u,o=typeof o=="string"?{text:o}:o||{},o.text=o.text||null,o.id=o.text?o.id||"qrcode-description":null,d=typeof d=="string"?{text:d}:d||{},d.text=d.text||null,d.id=d.text?d.id||"qrcode-title":null;var x=g.getModuleCount()*c+u*2,C,_,R,K,L="",Y;for(Y="l"+c+",0 0,"+c+" -"+c+",0 0,-"+c+"z ",L+=''+se(d.text)+"":"",L+=o.text?''+se(o.text)+"":"",L+='',L+='":u+=">";break;case"&":u+="&";break;case'"':u+=""";break;default:u+=d;break}}return u},nt=function(c){var u=1;c=typeof c=="undefined"?u*2:c;var o=g.getModuleCount()*u+c*2,d=c,p=o-c,x,C,_,R,K,L={"██":"█","█ ":"▀"," █":"▄"," ":" "},Y={"██":"▀","█ ":"▀"," █":" "," ":" "},j="";for(x=0;x=p?Y[K]:L[K];j+=` +`}return o%2&&c>0?j.substring(0,j.length-o-1)+Array(o+1).join("▀"):j.substring(0,j.length-1)};return g.createASCII=function(c,u){if(c=c||1,c<2)return nt(u);c-=1,u=typeof u=="undefined"?c*2:u;var o=g.getModuleCount()*c+u*2,d=u,p=o-u,x,C,_,R,K=Array(c+1).join("██"),L=Array(c+1).join(" "),Y="",j="";for(x=0;x>>8),m.push(y&255)):m.push(w)}}return m}};var e={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},a={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},v=(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]],k=1335,b=7973,w=21522,l={},m=function(s){for(var r=0;s!=0;)r+=1,s>>>=1;return r};return l.getBCHTypeInfo=function(s){for(var r=s<<10;m(r)-m(k)>=0;)r^=k<=0;)r^=b<5&&(y+=3+T-5)}for(var f=0;f=256;)l-=255;return M[l]},w})();function A(M,k){if(typeof M.length=="undefined")throw M.length+"/"+k;var b=(function(){for(var l=0;l>>7-w%8&1)==1},b.put=function(w,l){for(var m=0;m>>l-m-1&1)==1)},b.getLengthInBits=function(){return k},b.putBit=function(w){var l=Math.floor(k/8);M.length<=l&&M.push(0),w&&(M[l]|=128>>>k%8),k+=1},b},B=function(M){var k=e.MODE_NUMBER,b=M,w={};w.getMode=function(){return k},w.getLength=function(s){return b.length},w.write=function(s){for(var r=b,y=0;y+2>>8&255)*192+(f&255),s.put(f,13),y+=2}if(y>>8)},k.writeBytes=function(b,w,l){w=w||0,l=l||b.length;for(var m=0;m0&&(b+=","),b+=M[w];return b+="]",b},k},G=function(){var M=0,k=0,b=0,w="",l={},m=function(r){w+=String.fromCharCode(s(r&63))},s=function(r){if(!(r<0)){if(r<26)return 65+r;if(r<52)return 97+(r-26);if(r<62)return 48+(r-52);if(r==62)return 43;if(r==63)return 47}throw"n:"+r};return l.writeByte=function(r){for(M=M<<8|r&255,k+=8,b+=1;k>=6;)m(M>>>k-6),k-=6},l.flush=function(){if(k>0&&(m(M<<6-k),M=0,k=0),b%3!=0)for(var r=3-b%3,y=0;y=k.length){if(l==0)return-1;throw"unexpected end of file./"+l}var r=k.charAt(b);if(b+=1,r=="=")return l=0,-1;if(r.match(/^\s$/))continue;w=w<<6|s(r.charCodeAt(0)),l+=6}var y=w>>>l-8&255;return l-=8,y};var s=function(r){if(65<=r&&r<=90)return r-65;if(97<=r&&r<=122)return r-97+26;if(48<=r&&r<=57)return r-48+52;if(r==43)return 62;if(r==47)return 63;throw"c:"+r};return m},re=function(M,k){var b=M,w=k,l=new Array(M*k),m={};m.setPixel=function(f,g,T){l[g*b+f]=T},m.write=function(f){f.writeString("GIF87a"),f.writeShort(b),f.writeShort(w),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(w),f.writeByte(0);var g=2,T=r(g);f.writeByte(g);for(var E=0;T.length-E>255;)f.writeByte(255),f.writeBytes(T,E,255),E+=255;f.writeByte(T.length-E),f.writeBytes(T,E,T.length-E),f.writeByte(0),f.writeString(";")};var s=function(f){var g=f,T=0,E=0,P={};return P.write=function(H,q){if(H>>>q)throw"length over";for(;T+q>=8;)g.writeByte(255&(H<>>=8-T,E=0,T=0;E=H<0&&g.writeByte(E)},P},r=function(f){for(var g=1<>6,128|h&63):h<55296||h>=57344?i.push(224|h>>12,128|h>>6&63,128|h&63):(v++,h=65536+((h&1023)<<10|a.charCodeAt(v)&1023),i.push(240|h>>18,128|h>>12&63,128|h>>6&63,128|h&63))}return i}return e(t)}})();(function(t){typeof define=="function"&&define.amd?define([],t):typeof Ke=="object"&&(Ue.exports=t())})(function(){return Oe})});function ie(t){if(!t||t<0)return"0 B";let e=["B","KB","MB","GB","TB"],a=0,i=t;for(;i>=1024&&a=100||a===0?Math.round(i):i.toFixed(1)} ${e[a]}`}function ye(t,e=Date.now()/1e3){if(!t)return"never";let a=Math.max(0,Math.round(e-t));return a<60?"just now":a<3600?`${Math.floor(a/60)} min ago`:a<86400?`${Math.floor(a/3600)} h ago`:a<86400*30?`${Math.floor(a/86400)} d ago`:new Date(t*1e3).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function be(t){if(!t)return"";let[e,a,i]=t.split("-").map(Number);return new Date(e,a-1,i).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function we(t,e=Date.now()){if(!t)return null;let[a,i,v]=t.split("-").map(Number),h=new Date(a,i-1,v,23,59,59).getTime();return Math.ceil((h-e)/864e5)}var Se={lan:"Home network",internet:"Internet",both:"Home network + Internet"};var ve={computer:"PC",phone:"Phone",tablet:"Tablet",router:"Router",other:"Other"},Re={active:"Active",paused:"Paused",paused_all:"Paused (everyone)",expired:"Expired",quota:"Data limit reached",hours:"Outside allowed hours",no_server:"No server"};function Ne(t){var v,h,A;let e=t.trim().split(/\s+/).filter(Boolean);if(!e.length)return"?";let a=(v=e[0][0])!=null?v:"",i=e.length>1?(h=e[e.length-1][0])!=null?h:"":(A=e[0][1])!=null?A:"";return(a+i).toUpperCase()}function xe(t){let e=a=>a.disabled?3:a.online?0:a.handshake?1:2;return t.map((a,i)=>[a,i]).sort((a,i)=>e(a[0])-e(i[0])||a[1]-i[1]).map(([a])=>a)}var Ie={phone:'',computer:'',tablet:'',router:'',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 He(t,e="dl-icon"){var i;let a=(i=Ie[t])!=null?i:Ie.phone;return``}var qe=ut(Ge(),1),ft='';function Fe(t,e=3,a=!0){let i=(0,qe.default)(0,t.length>300?"Q":"H");i.addData(t,"Byte"),i.make();let v=i.getModuleCount(),h=v+e*2,A=a?Math.round(v*.22):0;A&&(v-A)%2&&A++;let $=(v-A)/2,D=$+A,B=(U,N)=>A>0&&U>=$&&U=$&&N${ft}`}return`${J}`}var dt={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:""},ht={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 vt(t){let e={};for(let[a,i]of Object.entries(ht))t[a]!=null&&t[a]!==""&&(e[i]=String(t[a]));return e}function pt(t,e){var D;let a=t.amnezia,i=(D=a.obfuscation)!=null?D:{},v=B=>i[B]!=null&&i[B]!==""?String(i[B]):dt[B],h=a.host.replace(/^\[(.*)\]$/,"$1"),A={H1:v("h1"),H2:v("h2"),H3:v("h3"),H4:v("h4"),I1:v("i1"),I2:v("i2"),I3:v("i3"),I4:v("i4"),I5:v("i5"),Jc:v("jc"),Jmin:v("jmin"),Jmax:v("jmax"),S1:v("s1"),S2:v("s2"),S3:v("s3"),S4:v("s4"),...vt(i),allowed_ips:a.allowed_ips,client_ip:a.client_ip,client_priv_key:a.client_priv_key,client_pub_key:a.client_pub_key,config:t.conf.replace(/\r?\n/g,`\r +`),hostName:h,mtu:a.mtu,persistent_keep_alive:a.persistent_keep_alive,port:Number(a.port),psk_key:a.psk_key,server_pub_key:a.server_pub_key},$={containers:[{container:"amnezia-awg",awg:{isThirdPartyConfig:!0,last_config:JSON.stringify(A),port:String(a.port),protocol_version:i.header_protection_key?"3.1":"2",transport_proto:"udp"}}],defaultContainer:"amnezia-awg",description:e,hostName:h};return a.dns[0]&&($.dns1=a.dns[0]),a.dns[1]&&($.dns2=a.dns[1]),$}function gt(t){let e="";for(let a=0;a{h==null||h===!1||(Array.isArray(h)?h.forEach(v):i.appendChild(typeof h=="string"?document.createTextNode(h):h))};return a.forEach(v),i}function O(t){let e=n("span",{class:"ic"});return e.innerHTML=He(t,"ic-svg"),e}var yt='',Le=document.getElementById("app"),je,pe=(je=Le.dataset.base)!=null?je:"",bt=Le.dataset.title||"Dawnline",Ae=()=>window.matchMedia("(max-width: 959px)").matches||/Android|iPhone|iPad/.test(navigator.userAgent),S=null,Ve=0,wt=/^\/[a-z]{6}-[a-z]{6}-[a-z]{6}$/.test(pe)?pe.slice(1):"",_e=class extends Error{constructor(a,i){super(i);this.status=a}};async function ne(t,e){var v;let a=await fetch(`${pe}/api/${t}`,{method:e===void 0?"GET":"POST",credentials:"omit",headers:e===void 0?{}:{"Content-Type":"application/json"},body:e===void 0?void 0:JSON.stringify(e),cache:"no-store"}),i=null;try{i=await a.json()}catch{}if(!a.ok)throw new _e(a.status,(v=i==null?void 0:i.error)!=null?v:`Request failed (${a.status})`);return i}function te(t,e=!1){let a=n("div",{class:`toast${e?" bad":""}`,role:"status"},t);document.body.appendChild(a),requestAnimationFrame(()=>a.classList.add("show")),setTimeout(()=>{a.classList.remove("show"),setTimeout(()=>a.remove(),300)},2600)}async function le(t,e="Copied"){try{await navigator.clipboard.writeText(t)}catch{let a=n("textarea",{class:"offscreen"},t);document.body.appendChild(a),a.select(),document.execCommand("copy"),a.remove()}te(e)}function ze(t,e){let a=URL.createObjectURL(new Blob([e],{type:"application/octet-stream"})),i=n("a",{href:a,download:t,class:"offscreen"});document.body.appendChild(i),i.click(),setTimeout(()=>{URL.revokeObjectURL(a),i.remove()},1e3)}var Z=null;function Je(t,e){let a=i=>{Z!=null||(Z=document.body.appendChild(n("div",{class:"tip"}))),Z.replaceChildren(...e().map((v,h)=>n("div",{class:h?"muted":"tip-title"},v))),Z.style.display="",Z.style.left=`${i.clientX}px`,Z.style.top=`${i.clientY-10}px`};t.addEventListener("mouseenter",a),t.addEventListener("mousemove",a),t.addEventListener("mouseleave",()=>Z&&(Z.style.display="none"))}function xt(t){let e=Math.max(1,...t),a=n("div",{class:"spark"});return t.forEach((i,v)=>{let h=n("i",{class:i?"":"zero"});h.style.height=`${Math.max(8,i/e*100)}%`;let A=t.length-1-v,$=new Date(Date.now()-A*864e5);Je(h,()=>[A===0?"Today":A===1?"Yesterday":$.toLocaleDateString("en-GB",{weekday:"short",day:"numeric",month:"short"}),ie(i)]),a.appendChild(h)}),a}var oe=null,ce=null;function ee(t=!1){if(!oe)return;let e=oe;if(oe=null,document.body.classList.remove("locked"),ce==null||ce(),ce=null,t){e.remove();return}e.classList.remove("open"),setTimeout(()=>e.remove(),250)}function fe(t,e,...a){let i=!!oe;ee(!0);let v=n("div",{class:"sheet-panel",role:"dialog","aria-modal":"true","aria-label":t},n("div",{class:"grab"}),n("div",{class:"sheet-head"},n("div",{class:"stack"},n("h2",{},t),e?n("span",{class:"muted s"},e):null),n("button",{class:"icon-btn","aria-label":"Close",onclick:()=>ee()},O("x"))),n("div",{class:"sheet-body"},...a)),h=n("div",{class:"sheet",onclick:A=>{A.target===h&&ee()}},v);return document.body.appendChild(h),document.body.classList.add("locked"),i?h.classList.add("open"):requestAnimationFrame(()=>h.classList.add("open")),oe=h,v}document.addEventListener("keydown",t=>{t.key==="Escape"&&(ge(),ee())});var X=null;function ge(){X==null||X.remove(),X=null}document.addEventListener("click",t=>{X&&!X.contains(t.target)&&ge()});function Mt(t,e){ge();let a=n("div",{class:"menu",role:"menu"},e.map(h=>h?n("button",{type:"button",role:"menuitem",class:`menu-item${h.danger?" danger":""}`,onclick:()=>{ge(),h.run()}},O(h.icon),n("span",{},h.label)):n("div",{class:"menu-sep"})));document.body.appendChild(a);let i=t.getBoundingClientRect(),v=230;a.style.left=`${Math.max(8,Math.min(window.innerWidth-v-8,i.right-v))}px`,a.style.top=`${i.bottom+6+window.scrollY}px`,X=a}function Te(...t){Le.replaceChildren(n("header",{class:"top"},n("div",{class:"brand"},(()=>{let e=n("span",{class:"logo"});return e.innerHTML=yt,e})(),n("span",{},(S==null?void 0:S.server.name)||bt),n("span",{class:"faint"},"· Dawnline"))),n("main",{class:"wrap"},...t))}function Qe(){Te(n("div",{class:"card signin"},n("div",{class:"hero-ic"},O("key")),n("h1",{},"This link no longer works"),n("p",{class:"muted"},"Ask for a new personal link.")))}function kt(t){return t.state==="active"?"ok":t.state==="quota"||t.state==="expired"?"bad":"warn"}var At={internet:"The internet, through the router",lan:"Devices at home",both:"Devices at home and the internet, through the router"};function _t(t){let e=t.person,a=e.quota_limit?Math.min(100,e.quota_used/e.quota_limit*100):0,i=n("div",{class:`meter${a>=100?" bad":a>=90?" warn":""}`},n("i"));i.firstChild.style.width=`${a}%`,e.quota_limit&&Je(i,()=>[`${a.toFixed(1)}% used`,`${ie(Math.max(0,e.quota_limit-e.quota_used))} left`]);let v=we(e.expires),h=n("div",{class:"slots"});for(let D=0;D=e.device_limit?"over":D=0?`${v} day${v===1?"":"s"} left`:"ended"):null)),n("span",{class:"faint s"},e.hours?`Available ${e.hours.replace("-","–")} (router time). Need a change? Ask the admin.`:"Need a change? Ask the admin.")))}function Ct(t){return t.disabled?n("span",{class:"dstat"},"Disabled by the admin"):t.online?n("span",{class:"dstat ok"},"Connected"):t.handshake?n("span",{class:"dstat"},`Last connected ${ye(t.handshake)}`):n("span",{class:"dstat warn"},"Not set up yet")}function We(t,e){return t.access!=="internet"&&t.state==="active"&&!e.disabled}function Lt(t,e){let a=xe(t.devices).filter(h=>h.hostname&&We(t,h));if(!a.length)return null;let i=a[0].hostname,v=i.slice(i.indexOf("."));return n("div",{class:"names"},n("div",{class:"names-head"},n("span",{class:"names-ic"},O("home")),n("div",{class:"stack"},n("span",{class:"strong s"},"Names at home"),n("span",{class:"faint s"},e?"Devices at home and on this VPN reach yours as ":"Other devices at home reach yours as ",n("span",{class:"mono"},`name${v}`)))),n("div",{class:"names-list"},a.map(h=>{let A=h.hostname.indexOf(".");return n("button",{type:"button",class:"name-chip",title:h.name,"aria-label":`Copy ${h.hostname}`,onclick:()=>le(h.hostname,"Address copied")},n("span",{class:"mono"},A>0?[h.hostname.slice(0,A),n("span",{class:"faint"},h.hostname.slice(A))]:h.hostname),O("copy"))})))}function Tt(t,e){let a=n("button",{type:"button",class:"icon-btn soft","aria-label":`${t.name} options`},O("more"));a.addEventListener("click",A=>{A.stopPropagation(),Mt(a,[{label:"Show QR code",icon:"qr",run:()=>ue(t,"qr")},{label:"Copy AmneziaVPN key",icon:"key",run:()=>Et(t)},{label:"Download .conf",icon:"download",run:()=>Dt(t)},null,...We(e.person,t)?[{label:"Copy IP address",icon:"copy",run:()=>le(t.address,"IP address copied")},...t.hostname?[{label:"Copy local address",icon:"home",run:()=>le(t.hostname,"Address copied")}]:[],null]:[],{label:"Rename",icon:"edit",run:()=>$t(t)},...t.disabled?[]:[{label:"New keys",icon:"reset",run:()=>Pt(t,e)}],{label:"Remove",icon:"trash",danger:!0,run:()=>St(t)}])});let i=t.spark.reduce((A,$)=>A+$,0),v=!t.handshake&&!t.disabled,h=e.here===t.id;return n("article",{class:`dcard${t.online?" online":""}${t.disabled?" off":""}${h?" here":""}`},n("div",{class:"dhead"},n("span",{class:"dic"},O(t.kind)),n("div",{class:"stack grow"},n("span",{class:"dname"},t.name),h?n("span",{class:"dstat here"},"This device"):Ct(t)),a),v?[n("button",{type:"button",class:"btn primary block",onclick:()=>ue(t)},O(Ae()?"open":"qr"),n("span",{},Ae()?"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))),xt(t.spark)),t.config_stale&&!v?n("div",{class:"notice"},O("alert"),n("span",{class:"grow"},"Connection settings changed. Update this device to keep everything working."),n("button",{type:"button",class:"btn small",onclick:()=>ue(t)},"Update")):null)}function de(t){let e=t.person,a=we(e.expires),i=e.state!=="active"?n("div",{class:"notice bad"},O("alert"),n("span",{},e.state==="quota"?"You have used all your data for this period. Your devices are paused until it resets.":e.state==="expired"?"Your access has ended. Ask the admin to extend it.":e.state==="hours"?`Access is available ${e.hours.replace("-","–")} (router time).`:"Your access is paused by the admin.")):a!=null&&a>=0&&a<=Math.max(e.expire_warn,1)?n("div",{class:"notice"},O("alert"),n("span",{},`Your access ends ${a===0?"today":`in ${a} day${a===1?"":"s"}`} (${be(e.expires)}).`)):null,h=xe(e.devices).sort((D,B)=>+(B.id===t.here)-+(D.id===t.here)).map(D=>Tt(D,t));Math.max(0,e.device_limit-e.devices.length)&&h.push(n("button",{type:"button",class:"slot add",onclick:Ht},n("span",{class:"slot-ic"},O("plus")),n("span",{class:"strong"},"Add device")));let $=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"},h),t.can_add?null:n("span",{class:"faint s"},`You have reached your limit of ${e.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."));Te(n("div",{class:"hello"},n("span",{class:`avatar${e.online?" online":""}`},Ne(e.name)),n("div",{class:"stack"},n("div",{class:"row"},n("h1",{},`Hi, ${e.name}`),e.state==="active"?null:n("span",{class:`pill ${kt(e)}`},Re[e.state])))),i,n("div",{class:"layout"},_t(t),$))}async function Ee(t){try{return await ne(`devices/${t.id}/config`)}catch(e){return te(e.message,!0),null}}async function Et(t){let e=await Ee(t);e&&le(await Me(e,`${e.server} · ${e.name}`),"Key copied")}async function Dt(t){let e=await Ee(t);e&&ze(e.filename,e.conf)}function Ye(t,e){if(/^\s*\[.+\]\s*$/.test(t))return n("span",{class:"conf-sec"},t);let a=/^(\s*[A-Za-z0-9]+\s*=)\s*(.*)$/.exec(t);if(!a)return document.createTextNode(t);let i=/^(\s*)(PrivateKey|PresharedKey)\b/.test(t);return n("span",{},n("span",{class:"conf-k"},a[1])," ",i&&!e?n("span",{class:"conf-mask"},"••••••••••••••••"):a[2])}function Bt(t){let e=!1,a=n("pre",{class:"conf"}),i=()=>a.replaceChildren(...t.conf.split(` +`).flatMap((h,A)=>A?[` +`,Ye(h,e)]:[Ye(h,e)])),v=n("button",{class:"btn small",onclick:h=>{h.preventDefault(),e=!e,v.replaceChildren(O(e?"x":"key"),n("span",{},e?"Hide key":"Show key")),i()}},O("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"},t.filename),n("span",{class:"faint s"},"For computers and routers: import it in AmneziaWG or AmneziaVPN")),n("button",{class:"btn primary",onclick:()=>ze(t.filename,t.conf)},O("download"),n("span",{},"Download"))),n("details",{class:"confbox"},n("summary",{},O("chevron"),n("span",{},"Configuration"),n("span",{class:"grow"}),v,n("button",{class:"btn small",onclick:h=>{h.preventDefault(),le(t.conf,"Configuration copied")}},O("copy"),n("span",{},"Copy"))),a))}async function ue(t,e,a){let i=a!=null?a:await Ee(t);if(!i)return;let v=await Me(i,`${i.server} · ${i.name}`),h=Ae(),A={app:()=>n("div",{class:"pane"},n("a",{class:"btn primary block big",href:v},O("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 I=n("div",{class:"qr"});return I.innerHTML=Fe(i.conf),n("div",{class:"pane center"},I,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"},v),n("button",{class:"btn small",onclick:()=>le(v,"Key copied")},"Copy")),n("p",{class:"faint s"},"Keep it private: anyone with the key can use your connection.")),file:()=>Bt(i)},$=h?["app","qr","key","file"]:["qr","key","file"],D={app:"Open in app",qr:"QR code",key:"Key",file:"File"},B=n("div",{class:"tab-body"}),F=n("div",{class:"tabs",role:"tablist"}),J=I=>{F.querySelectorAll("button").forEach(re=>re.classList.toggle("on",re.dataset.id===I)),B.replaceChildren(A[I]())};for(let I of $)F.appendChild(n("button",{role:"tab","data-id":I,onclick:()=>J(I)},D[I]));J(e&&$.includes(e)?e:$[0]);let U=n("div",{class:"waiting"}),N=I=>{I!=null&&I.online?U.replaceChildren(n("span",{class:"ok"},`${t.name} is connected`)):I!=null&&I.handshake?U.replaceChildren(n("span",{class:"muted"},`Last connected ${ye(I.handshake)}`)):U.replaceChildren(n("span",{class:"warn"},"Waiting for the first connection…"))};N(t);let G=window.setInterval(async()=>{try{let I=await ne("state");S=I,N(I.person.devices.find(re=>re.id===t.id))}catch{}},5e3);fe(t.handshake?`Connect ${t.name}`:`${t.name} is ready`,h?"Add it to AmneziaVPN on this phone":"Scan with the phone’s camera or AmneziaVPN",F,B,U),ce=()=>{clearInterval(G),S&&de(S)}}function $t(t){let e=n("input",{type:"text",value:t.name,maxlength:48,"aria-label":"Device name"});fe(`Rename ${t.name}`,null,n("form",{class:"stack gap",onsubmit:async a=>{a.preventDefault();try{S=(await ne(`devices/${t.id}`,{action:"rename",name:e.value})).state,ee(),de(S),te("Renamed")}catch(i){te(i.message,!0)}}},e,n("button",{class:"btn primary block",type:"submit"},"Save"))),setTimeout(()=>e.select(),50)}function Pt(t,e){let a=e.here===t.id;fe(`New keys for ${t.name}?`,null,n("p",{class:"muted"},a?"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:async()=>{try{let i=await ne(`devices/${t.id}`,{action:"rotate"});S=i.state,de(S),ue(t,void 0,i.config)}catch(i){te(i.message,!0)}}},"New keys")))}function St(t){fe(`Remove ${t.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:async()=>{try{S=(await ne(`devices/${t.id}`,{action:"delete"})).state,ee(),de(S),te("Device removed")}catch(e){te(e.message,!0)}}},"Remove")))}var V=navigator.userAgent,Ze=/iPad/.test(V)||/Macintosh/.test(V)&&navigator.maxTouchPoints>1;function ke(){return Ze||/Tablet/i.test(V)||/Android/.test(V)&&!/Mobile/.test(V)?"tablet":/Android|iPhone|Mobile/i.test(V)?"phone":"computer"}var Rt=[[/^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"]],Ce="",Nt=(async()=>{var e;let t=navigator.userAgentData;if(!t||!/Android/.test(V))return"";try{let a=((e=(await t.getHighEntropyValues(["model"])).model)!=null?e:"").trim();if(!a||a==="K")return"";let i=Rt.find(([v])=>v.test(a));Ce=i?`${i[1]} (${a})`:/^SM-/.test(a)?`Galaxy ${a}`:a}catch{}return Ce})();function It(t){return/iPhone/.test(V)?"iPhone":Ze?"iPad":/Android/.test(V)?Ce||(t==="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":ve[t]}function Ht(){if(!S)return;let t=ke(),e=new Set(S.person.devices.map(D=>D.name.toLowerCase())),a=D=>{let B=D===ke()?It(D):ve[D];if(!e.has(B.toLowerCase()))return B;for(let F=2;F<20;F++)if(!e.has(`${B} ${F}`.toLowerCase()))return`${B} ${F}`;return B},i=n("input",{type:"text",value:a(t),maxlength:48,"aria-label":"Device name",required:!0}),v=!1;i.addEventListener("input",()=>v=!0),Nt.then(()=>{!v&&t===ke()&&(i.value=a(t))});let h=n("div",{class:"kinds"},S.kinds.map(D=>n("button",{type:"button",class:`kind${D===t?" on":""}`,"data-k":D,onclick:()=>{t=D,h.querySelectorAll(".kind").forEach(B=>B.classList.toggle("on",B.dataset.k===D)),v||(i.value=a(D))}},O(D),n("span",{},ve[D])))),A=n("p",{class:"err"}),$=n("button",{class:"btn primary block",type:"submit"},"Create connection");fe("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(),$.disabled=!0,A.textContent="";try{let B=await ne("devices",{name:i.value.trim(),kind:t});S=B.state;let F=B.state.person.devices.find(J=>J.id===B.id);await ue(F,void 0,B.config)}catch(B){A.textContent=B.message,$.disabled=!1}}},n("label",{class:"lbl"},"What is it?"),h,n("label",{class:"lbl"},"Name"),i,A,$))}async function Xe(){try{S=await ne("state"),document.title=`${S.person.name} · ${S.title}`,!oe&&!X&&de(S)}catch(t){let e=t;e.status===404||e.status===401?(S=null,Qe()):S||Te(n("div",{class:"card"},n("p",{},e.message)))}}function Ot(){clearInterval(Ve),Ve=window.setInterval(()=>{S&&document.visibilityState==="visible"&&Xe()},15e3)}!pe||!wt?Qe():(Xe(),Ot());})(); 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 935ea37..5b163bb 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 @@ -22,7 +22,7 @@ import { stdin, stat, unlink, readfile } from 'fs'; import { - read_json, write_json, ensure_dir, lock, unlock, cloudflare_ip, ip2int, VERSION, RUN_DIR, DATA_DIR + read_json, write_json, ensure_dir, lock, unlock, cloudflare_ip, ip2int, sh_bg, VERSION, RUN_DIR, DATA_DIR } from 'dawnline.util'; import * as core from 'dawnline.core'; import * as live from 'dawnline.live'; @@ -191,6 +191,7 @@ function not_found() { } const title = m.settings.portal_title || 'Dawnline'; + // Plain HTTP only for an IP address chosen in Settings (no certificate exists // for it); names, and LuCI's web server at home, stay HTTPS-only. if (getenv('HTTPS') != 'on') { @@ -259,10 +260,16 @@ function state() { let dmp = live.dump(); let v = view.person_view(m, person, usage, dmp, view.states(m, usage)); let srv = m.servers[person.server]; + // The device this page was opened from, when it came through the tunnel. + let here = null; + for (let id, d in m.devices) + if (d.person == person.id && d.address == peer) + here = id; return { title, person: v, - server: { name: srv?.name, endpoint: core.endpoint_host(m, srv) }, + here, + server: { name: srv?.name, endpoint: core.endpoint_host(m, srv), device_mesh: !!srv?.device_mesh }, can_add: length(person.devices) < person.device_limit, kinds: core.KINDS, version: VERSION, @@ -299,7 +306,7 @@ if (api[0] == 'devices' && length(api) == 1 && method == 'POST') { apply.sync(); m = core.load(); person = m.people[person_id]; - live.add_event({ type: 'device_added', person: person.id, device: id, detail: `${m.devices[id].name} (portal)` }); + live.add_event({ type: 'device_added', person: person.id, device: id, detail: m.devices[id].name, by: 'portal' }); core.mark_issued(m, id); send_json('200 OK', { id, config: core.client_config(m, m.devices[id]), state: state() }); } @@ -319,10 +326,15 @@ if (api[0] == 'devices' && length(api) == 2 && method == 'POST') { m = core.load(c); if (b.action == 'rename') core.rename_device(c, m, api[1], b.name); + else if (b.action == 'rotate') { + if (m.devices[api[1]].disabled) + die('The admin has turned this device off.'); + core.rotate_device(c, m, api[1]); + } else if (b.action == 'delete') { let d = m.devices[api[1]]; core.delete_device(c, m, api[1]); - live.add_event({ type: 'device_removed', person: person.id, device: api[1], detail: `${d.name} (portal)` }); + live.add_event({ type: 'device_removed', person: person.id, device: api[1], detail: d.name, dname: d.name, dkind: d.kind, by: 'portal' }); } else die('Unknown action.'); @@ -338,6 +350,18 @@ if (api[0] == 'devices' && length(api) == 2 && method == 'POST') { apply.sync(); m = core.load(); person = m.people[person_id]; + if (b.action == 'rotate') { + let d = m.devices[api[1]]; + live.add_event({ type: 'device_keys', person: person.id, device: d.id, detail: d.name, by: 'portal' }); + // The device this page came through would lose its tunnel before the + // answer gets out: load the new key a moment after answering. + if (d.address == peer) + sh_bg('sleep 3; /usr/bin/dawnline sync'); + else + apply.sync(); + core.mark_issued(m, d.id); + send_json('200 OK', { ok: true, config: core.client_config(m, d), state: state() }); + } send_json('200 OK', { ok: true, state: state() }); } diff --git a/package/luci-app-dawnline/root/usr/share/luci/menu.d/luci-app-dawnline.json b/package/luci-app-dawnline/root/usr/share/luci/menu.d/luci-app-dawnline.json index e147483..ff6d080 100644 --- a/package/luci-app-dawnline/root/usr/share/luci/menu.d/luci-app-dawnline.json +++ b/package/luci-app-dawnline/root/usr/share/luci/menu.d/luci-app-dawnline.json @@ -28,8 +28,6 @@ } }, "admin/network/dawnline/activity": { - "title": "Activity", - "order": 25, "action": { "type": "view", "path": "dawnline/activity" @@ -49,9 +47,15 @@ "path": "dawnline/server" } }, - "admin/network/dawnline/health": { - "title": "Health", + "admin/network/dawnline/diagnostics": { + "title": "Diagnostics", "order": 40, + "action": { + "type": "view", + "path": "dawnline/diagnostics" + } + }, + "admin/network/dawnline/health": { "action": { "type": "view", "path": "dawnline/health" diff --git a/package/luci-app-dawnline/root/usr/share/rpcd/acl.d/luci-app-dawnline.json b/package/luci-app-dawnline/root/usr/share/rpcd/acl.d/luci-app-dawnline.json index 96b13d1..bfef708 100644 --- a/package/luci-app-dawnline/root/usr/share/rpcd/acl.d/luci-app-dawnline.json +++ b/package/luci-app-dawnline/root/usr/share/rpcd/acl.d/luci-app-dawnline.json @@ -7,6 +7,7 @@ "status", "setup_defaults", "health", + "service_log", "backup_list", "updates_status", "person_usage", diff --git a/package/luci-app-dawnline/root/usr/share/rpcd/ucode/luci.dawnline b/package/luci-app-dawnline/root/usr/share/rpcd/ucode/luci.dawnline index 96b3eb4..62d6b74 100644 --- a/package/luci-app-dawnline/root/usr/share/rpcd/ucode/luci.dawnline +++ b/package/luci-app-dawnline/root/usr/share/rpcd/ucode/luci.dawnline @@ -5,7 +5,7 @@ import { cursor } from 'uci'; import { readfile, stat } from 'fs'; import { q, sh, sh_out, sh_bg, ensure_dir, read_json, write_json, parse_cidr, cidr_str, cidr_overlaps, int2ip, - ip2int, valid_host, rand_int, lock, unlock, uniq, VERSION, RUN_DIR, DATA_DIR + ip2int, valid_host, rand_int, lock, unlock, uniq, slog_clear, admin_log, VERSION, RUN_DIR, DATA_DIR } from 'dawnline.util'; import * as core from 'dawnline.core'; import * as live from 'dawnline.live'; @@ -15,6 +15,7 @@ import * as ops from 'dawnline.ops'; import * as geo from 'dawnline.geo'; import * as net from 'dawnline.net'; import * as loop from 'dawnline.loop'; +import * as watchdog from 'dawnline.watchdog'; function wrap(fn) { return function(req) { @@ -116,7 +117,7 @@ function status(a) { push(servers, { id, name: srv.name, ifname: srv.ifname, port: srv.port, subnet: srv.subnet, endpoint: core.endpoint_host(m, srv), public_key: srv.public_key, enabled: srv.enabled, - lan_like: srv.lan_like, preset: srv.preset, mtu: srv.mtu, keepalive: srv.keepalive, dns: srv.dns, + lan_like: srv.lan_like, device_mesh: srv.device_mesh, preset: srv.preset, mtu: srv.mtu, keepalive: srv.keepalive, dns: srv.dns, address: core.server_address(srv), up: !!st?.up, uptime: st?.uptime ?? 0, peers, online, obf: srv.obf, // Bytes per second, one point a minute: [ts, rx, tx] (rx = from devices). @@ -365,6 +366,8 @@ function server_create(a) { l = null; let r = apply.apply(); system('/etc/init.d/dawnline enabled || /etc/init.d/dawnline enable'); + let made = core.load().servers[id]; + admin_log('awg', 'created', 'server', made?.name ?? id, made ? `port ${made.port}` : null); sh_bg('/etc/init.d/dawnline restart'); return { id, applied: r }; } @@ -402,7 +405,8 @@ function interfaces_view(srv, snap) { ifname: srv.ifname, detected: { wan: snap.wan, lan: snap.lan }, saved: { wan: srv.detected_wan, lan: srv.detected_lan }, - config: { auto_wan: srv.auto_wan, wan_device: srv.wan_device, auto_lan: srv.auto_lan, lan_devices: srv.lan_devices, lan_like: srv.lan_like }, + config: { auto_wan: srv.auto_wan, wan_device: srv.wan_device, auto_lan: srv.auto_lan, lan_devices: srv.lan_devices, lan_like: srv.lan_like, + device_mesh: srv.device_mesh }, like_home: loop.status(), needs: ops.needs().home, effective: sn, @@ -451,6 +455,8 @@ function server_interfaces(a) { lans = uniq(lans); if (a.lan_like != null) c.set('dawnline', srv.id, 'lan_like', a.lan_like === false || a.lan_like === '0' ? '0' : '1'); + if (a.device_mesh != null) + c.set('dawnline', srv.id, 'device_mesh', a.device_mesh === false || a.device_mesh === '0' ? '0' : '1'); c.set('dawnline', srv.id, 'auto_wan', auto_wan ? '1' : '0'); c.set('dawnline', srv.id, 'auto_lan', auto_lan ? '1' : '0'); if (auto_wan || wan_dev == '') @@ -476,6 +482,19 @@ function server_interfaces(a) { c.commit('dawnline'); system('chmod 600 /etc/config/dawnline'); let before = join(',', net.server_net(srv, snap).nets); + // What the admin changed here: the networks, and/or whether devices reach each other. + let mesh = a.device_mesh == null ? srv.device_mesh : !(a.device_mesh === false || a.device_mesh === '0'); + let sig = (x) => { + let sn = net.server_net(x, snap); + return `${join(',', sn.nets)}|${sn.wan.dev}|${x.lan_like}`; + }; + let what = []; + if (sig(core.load(c).servers[srv.id]) != sig(srv)) + push(what, 'home network and internet path'); + if (mesh != srv.device_mesh) + push(what, mesh ? 'devices reach each other' : 'devices kept apart'); + if (length(what)) + admin_log('awg', 'changed', 'server', srv.name, join(', ', what)); apply.apply(); let m3 = core.load(); let view = interfaces_view(m3.servers[srv.id], net.snapshot(true)); @@ -513,6 +532,8 @@ function server_update(a) { } if (v.enabled != null) set('enabled', v.enabled === true || v.enabled == '1' ? '1' : '0'); + if (v.device_mesh != null) + set('device_mesh', v.device_mesh === true || v.device_mesh == '1' ? '1' : '0'); if (v.mtu != null) { if (str(v.mtu) != '' && (!match(str(v.mtu), /^[0-9]+$/) || +v.mtu < 1280 || +v.mtu > 1500)) die('MTU must be 1280-1500.'); @@ -533,7 +554,28 @@ function server_update(a) { else c.delete('dawnline', srv.id, 'dns'); } - return commit(c, true); + // For the log: what changed, in words. Turning on or off is its own line. + let labels = { name: 'name', endpoint: 'public address', port: 'port', mtu: 'MTU', keepalive: 'keep-alive', dns: 'DNS' }; + let what = []; + for (let k, label in labels) { + if (v[k] == null) + continue; + let was = k == 'dns' ? join(' ', srv.dns ?? []) : `${srv[k] ?? ''}`; + let now = k == 'dns' ? join(' ', type(v.dns) == 'array' ? v.dns : split(str(v.dns), /[ ,]+/)) : str(v[k]); + if (trim(was) != trim(now)) + push(what, label); + } + let on = v.enabled == null ? null : (v.enabled === true || v.enabled == '1'); + let mesh = v.device_mesh == null ? null : (v.device_mesh === true || v.device_mesh == '1'); + let name = v.name != null ? str(v.name) : srv.name; + let r = commit(c, true); + if (on != null && on != srv.enabled) + admin_log('awg', on ? 'turned on' : 'turned off', 'server', name); + if (length(what)) + admin_log('awg', 'changed', 'server', name, join(', ', what)); + if (mesh != null && mesh != srv.device_mesh) + admin_log('awg', 'changed', 'server', name, mesh ? 'devices reach each other' : 'devices kept apart'); + return r; } function server_obfuscation(a) { @@ -548,7 +590,9 @@ function server_obfuscation(a) { for (let k, v in o) c.set('dawnline', a.id, k, v); c.set('dawnline', a.id, 'preset', a.preset ?? 'standard'); - return commit(c, true); + let r = commit(c, true); + admin_log('awg', 'changed', 'server', srv.name, `disguise: ${a.preset || 'standard'}`); + return r; } function server_delete(a) { @@ -557,11 +601,16 @@ function server_delete(a) { if (!m.servers[a.id]) die('Unknown server.'); ops.backup_create('pre-delete'); + let gone = 0; for (let pid, p in m.people) - if (p.server == a.id) + if (p.server == a.id) { core.delete_person(c, m, pid); + gone++; + } c.delete('dawnline', a.id); - return commit(c, true); + let r = commit(c, true); + admin_log('awg', 'removed', 'server', m.servers[a.id].name, gone ? `with ${gone} ${gone == 1 ? 'person' : 'people'}` : null); + return r; } /* ---------- people ---------- */ @@ -580,7 +629,7 @@ function person_create(a) { unlock(l); l = null; let m2 = core.load(); - live.add_event({ type: 'person_added', person: slug, detail: m2.people[slug].name }); + live.add_event({ type: 'person_added', person: slug, detail: m2.people[slug].name, by: 'admin' }); return { id: slug, link: core.portal_url(m2, m2.people[slug]) }; } catch (e) { @@ -600,7 +649,7 @@ function person_pause(a) { c.set('dawnline', a.id, 'paused', '1'); else c.delete('dawnline', a.id, 'paused'); - live.add_event({ type: a.paused ? 'paused' : 'resumed', person: a.id, detail: 'by admin' }); + live.add_event({ type: a.paused ? 'paused' : 'resumed', person: a.id, by: 'admin' }); return commit(c); } @@ -612,6 +661,7 @@ function person_regen(a) { die('Unknown person.'); c.set('dawnline', a.id, 'code', core.new_code()); c.commit('dawnline'); + live.add_event({ type: 'link_changed', person: a.id, by: 'admin' }); // The old link stops working at once: every portal request carries the code. let m2 = core.load(); return { link: core.portal_url(m2, m2.people[a.id]) }; @@ -622,7 +672,7 @@ function person_delete(a) { let m = core.load(c); let name = m.people[a.id]?.name; core.delete_person(c, m, a.id); - live.add_event({ type: 'person_removed', person: a.id, detail: name }); + live.add_event({ type: 'person_removed', person: a.id, detail: name, pname: name, by: 'admin' }); return commit(c); } @@ -630,7 +680,7 @@ function pause_all(a) { let c = core.open_cursor(); c.set('dawnline', 'settings', 'settings'); c.set('dawnline', 'settings', 'paused_all', a.paused ? '1' : '0'); - live.add_event({ type: a.paused ? 'paused_all' : 'resumed_all' }); + live.add_event({ type: a.paused ? 'paused_all' : 'resumed_all', by: 'admin' }); return commit(c); } @@ -647,7 +697,7 @@ function device_create(a) { unlock(l); l = null; apply.sync(); - live.add_event({ type: 'device_added', person: a.person, device: id, detail: `${a.name} (admin)` }); + live.add_event({ type: 'device_added', person: a.person, device: id, detail: a.name, by: 'admin' }); let m2 = core.load(); core.mark_issued(m2, id); return { id, config: core.client_config(m2, m2.devices[id]) }; @@ -682,7 +732,12 @@ function device_update(a) { else c.delete('dawnline', a.id, 'disabled'); } - return commit(c); + let r = commit(c); + if (a.disabled != null && !!a.disabled != !!d.disabled) + live.add_event({ type: 'device_changed', person: d.person, device: a.id, detail: a.disabled ? 'turned off' : 'turned on', by: 'admin' }); + else if (a.name != null && a.name != d.name) + live.add_event({ type: 'device_changed', person: d.person, device: a.id, detail: `renamed from ${d.name}`, by: 'admin' }); + return r; } function device_delete(a) { @@ -690,7 +745,7 @@ function device_delete(a) { let m = core.load(c); let d = m.devices[a.id]; core.delete_device(c, m, a.id); - live.add_event({ type: 'device_removed', person: d?.person, device: a.id, detail: `${d?.name} (admin)` }); + live.add_event({ type: 'device_removed', person: d?.person, device: a.id, detail: d?.name, dname: d?.name, dkind: d?.kind, by: 'admin' }); return commit(c); } @@ -699,6 +754,7 @@ function device_rotate(a) { let m = core.load(c); core.rotate_device(c, m, a.id); commit(c); + live.add_event({ type: 'device_keys', person: m.devices[a.id]?.person, device: a.id, detail: m.devices[a.id]?.name, by: 'admin' }); let m2 = core.load(); core.mark_issued(m2, a.id); return core.client_config(m2, m2.devices[a.id]); @@ -775,7 +831,7 @@ function person_update(a) { l = null; let changes = join(', ', filter(keys(fields), (k) => k != 'note')); if (changes) - live.add_event_merged({ type: 'person_changed', person: a.id, detail: changes }, 120); + 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 m2 = core.load(); @@ -790,7 +846,7 @@ function person_update(a) { } const SETTING_KEYS = [ 'portal_enabled', 'portal_host', 'portal_alt', 'portal_port', 'portal_443', 'portal_title', 'portal_redirect', 'portal_cert', 'portal_key', - 'default_device_limit', 'hostnames', 'domain', 'geo_enabled', 'geo_provider', 'log_connections', + 'default_device_limit', 'hostnames', 'domain', 'geo_enabled', 'geo_provider', 'log_connections', 'watchdog', 'log_keep_days', 'log_max', 'log_persist', 'usage_keep_days', 'usage_keep_months', 'home_dns_fallback' ]; function file_size(path) { @@ -928,6 +984,29 @@ function settings_update(a) { system('/etc/init.d/dawnline reload >/dev/null 2>&1'); else apply.sync(); + // The changes worth a line: the portal and the watchdog (other settings are housekeeping). + let now = core.load().settings, was = m.settings; + if (now.portal_enabled != was.portal_enabled) + admin_log('portal', now.portal_enabled ? 'turned on' : 'turned off', null, 'the personal portal', now.portal_enabled ? `port ${now.portal_port}` : null); + else if (now.portal_enabled) { + let what = []; + if (now.portal_port != was.portal_port) + push(what, `port ${now.portal_port}`); + if (now.portal_host != was.portal_host) + push(what, `address ${now.portal_host}`); + if (join(' ', now.portal_alt) != join(' ', was.portal_alt)) + push(what, 'other addresses'); + if (now.portal_cert != was.portal_cert || now.portal_key != was.portal_key) + push(what, 'certificate'); + if (now.portal_443 != was.portal_443) + push(what, now.portal_443 ? 'links without a port' : 'links with the port'); + if (now.portal_redirect != was.portal_redirect) + push(what, 'redirect'); + if (length(what)) + admin_log('portal', 'changed', null, 'the personal portal', join(', ', what)); + } + 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({}); } @@ -978,7 +1057,8 @@ function service_delete(a) { } function events_list(a) { - let ev = live.load_events(); + // Tunnel down/up events of older versions: the service log tells it better (names, reasons). + let ev = filter(live.load_events(), (e) => e.type != 'server_down' && e.type != 'server_up'); let n = +a.limit || 300; return { events: slice(ev, length(ev) > n ? length(ev) - n : 0), total: length(ev), policy: live.policy() }; } @@ -1004,7 +1084,12 @@ function logs_clear(a) { die('Older than must be a number of days.'); f.before = time() - +a.older_days * 86400; } - return { ok: true, removed: live.clear_events(f) }; + let removed = live.clear_events(f); + if (removed) + admin_log('dawnline', 'cleared', null, 'the activity log', + join(' · ', filter([ `${removed} event${removed == 1 ? '' : 's'}`, f.category, f.person ? m.people[f.person].name : null, + a.older_days ? `older than ${a.older_days} days` : null ], (x) => x))); + return { ok: true, removed }; } /** @@ -1032,6 +1117,8 @@ function usage_clear(a) { live.reset_usage(usage, m, a.scope, a.id); write_json(`${RUN_DIR}/usage.json`, usage, 0o600); } + admin_log('dawnline', 'reset traffic history', null, + a.scope == 'all' ? 'for everyone' : a.scope == 'person' ? `for ${m.people[a.id].name}` : `for ${m.devices[a.id].name} (${m.people[m.devices[a.id].person]?.name})`); return { ok: true }; } @@ -1065,7 +1152,7 @@ const methods = { server_obfuscation: { args: { id: '', preset: '' }, call: wrap(server_obfuscation) }, server_update: { args: { id: '', values: {} }, call: wrap(server_update) }, interfaces: { args: { id: '' }, call: wrap(interfaces_get) }, - server_interfaces: { args: { id: '', auto_wan: false, wan_device: '', auto_lan: false, lan_devices: [], lan_like: false }, call: wrap(server_interfaces) }, + server_interfaces: { args: { id: '', auto_wan: false, wan_device: '', auto_lan: false, lan_devices: [], lan_like: false, device_mesh: true }, call: wrap(server_interfaces) }, server_delete: { args: { id: '' }, call: wrap(server_delete) }, person_create: { args: { name: '', slug: '', server: '', access: '', device_limit: 0, expires: '', quota_gb: 0, quota_period: '' }, @@ -1082,16 +1169,39 @@ const methods = { device_delete: { args: { id: '' }, call: wrap(device_delete) }, device_rotate: { args: { id: '' }, call: wrap(device_rotate) }, apply: { call: wrap((a) => apply.apply()) }, - health: { call: wrap((a) => ({ checks: ops.health() })) }, - health_fix: { args: { id: '' }, call: wrap((a) => ({ result: ops.fix(a.id), checks: ops.health() })) }, + health: { call: wrap((a) => ({ checks: ops.health(), ...watchdog.view(core.load()) })) }, + health_fix: { args: { id: '' }, call: wrap((a) => ({ result: ops.fix(a.id), checks: ops.health(), ...watchdog.view(core.load()) })) }, + service_log: { call: wrap((a) => watchdog.view(core.load())) }, + service_log_clear: { args: { older_days: '' }, call: wrap((a) => { + let removed = slog_clear(+a.older_days || 0); + if (removed) + admin_log('dawnline', 'cleared', null, 'the service log', `${removed} entr${removed == 1 ? 'y' : 'ies'}${+a.older_days ? ` older than ${a.older_days} days` : ''}`); + return { removed }; + }) }, backup_list: { call: wrap((a) => ({ backups: ops.backup_list() })) }, backup_create: { call: wrap((a) => ({ name: ops.backup_create(null) })) }, - backup_restore: { args: { name: '' }, call: wrap((a) => ops.backup_restore(a.name)) }, + backup_restore: { args: { name: '' }, call: wrap((a) => { + let r = ops.backup_restore(a.name); + admin_log('dawnline', 'restored', 'backup', a.name); + return r; + }) }, backup_delete: { args: { name: '' }, call: wrap((a) => ({ ok: ops.backup_delete(a.name) })) }, backup_read: { args: { name: '' }, call: wrap((a) => ({ data: ops.backup_read(a.name) })) }, - backup_upload: { args: { data: '' }, call: wrap((a) => ops.backup_upload(a.data)) }, - export: { call: wrap((a) => ops.export_json()) }, - import: { args: { data: {} }, call: wrap((a) => ops.import_json(a.data)) }, + backup_upload: { args: { data: '' }, call: wrap((a) => { + let r = ops.backup_upload(a.data); + admin_log('dawnline', 'restored', 'backup', 'from a file'); + return r; + }) }, + export: { call: wrap((a) => { + let r = ops.export_json(); + admin_log('dawnline', 'exported', null, 'all settings', 'the file holds private keys'); + return r; + }) }, + import: { args: { data: {} }, call: wrap((a) => { + let r = ops.import_json(a.data); + admin_log('dawnline', 'imported', null, 'settings from a file'); + return r; + }) }, updates_status: { call: wrap(updates_status) }, updates_run: { args: { what: '' }, call: wrap(updates_run) }, person_update: { 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 aaecb5b..2b2b376 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 @@ -10,7 +10,7 @@ import { cursor } from 'uci'; import { readfile, writefile, stat, unlink } from 'fs'; import { q, sh, sh_out, sh_bg, ensure_dir, write_file, write_json, read_json, parse_cidr, int2ip, uniq, - lock, unlock, RUN_DIR + lock, unlock, slog, iface_intent, RUN_DIR } from 'dawnline.util'; import * as core from 'dawnline.core'; import * as net from 'dawnline.net'; @@ -26,8 +26,8 @@ const HOSTS_FILE = '/tmp/hosts/dawnline'; */ const PREF_REPLY = 90; -function log(msg) { - system(`logger -t dawnline ${q(msg)}`); +function log(who, msg, level, detail) { + slog('dawnline', level ?? 'info', msg, detail, who); } /* ---------- helpers ---------- */ @@ -103,20 +103,30 @@ function sync_network(m) { want[ifn] = true; let addr = core.server_address(srv); let pc = parse_cidr(srv.subnet); - let before = changed; - changed = ensure_section(c, 'network', ifn, 'interface') || changed; - changed = put(c, 'network', ifn, 'proto', 'amneziawg') || changed; - changed = put(c, 'network', ifn, 'private_key', srv.private_key) || changed; - changed = put(c, 'network', ifn, 'listen_port', srv.port) || changed; - changed = put(c, 'network', ifn, 'addresses', [ `${addr}/${pc.prefix}` ]) || changed; - changed = put(c, 'network', ifn, 'mtu', srv.mtu) || changed; - changed = put(c, 'network', ifn, 'disabled', srv.enabled ? null : '1') || changed; - changed = put(c, 'network', ifn, 'auto', srv.enabled ? null : '0') || changed; - changed = put(c, 'network', ifn, '_dawnline', id) || changed; + // Per server: with several, each changed one has to be brought up again. + let mine = ensure_section(c, 'network', ifn, 'interface'); + let set = (opt, val) => { + if (put(c, 'network', ifn, opt, val)) + mine = true; + }; + set('proto', 'amneziawg'); + set('private_key', srv.private_key); + set('listen_port', srv.port); + set('addresses', [ `${addr}/${pc.prefix}` ]); + set('mtu', srv.mtu); + set('disabled', srv.enabled ? null : '1'); + set('auto', srv.enabled ? null : '0'); + set('_dawnline', id); + // For the log once the server is gone. + set('_dawnline_name', srv.name); for (let k in core.OBF_KEYS) - changed = put(c, 'network', ifn, `awg_${k}`, srv.obf[k]) || changed; - if (changed != before) + set(`awg_${k}`, srv.obf[k]); + if (mine) { + changed = true; push(touched, ifn); + // The hotplug log says why the tunnel goes down (not a failure). + iface_intent(ifn, srv.enabled ? 'settings' : 'off', srv.name); + } } // Remove interfaces Dawnline created for servers that no longer exist. @@ -126,6 +136,7 @@ function sync_network(m) { push(stale, s['.name']); }); for (let ifn in stale) { + iface_intent(ifn, 'removed', c.get('network', ifn, '_dawnline_name') ?? ifn); system(`ifdown ${q(ifn)} 2>/dev/null`); c.delete('network', ifn); changed = true; @@ -138,7 +149,8 @@ function sync_network(m) { for (let ifn in touched) if (m.servers[c.get('network', ifn, '_dawnline')]?.enabled) system(`ifup ${q(ifn)}`); - log(`network updated (${join(', ', touched) || 'removed ' + join(', ', stale)})`); + // Each tunnel's own line (restarting, turned off, removed) comes from hotplug. + system(`logger -t dawnline ${q('network updated: ' + join(', ', [ ...touched, ...stale ]))}`); } return changed; } @@ -147,7 +159,8 @@ function sync_network(m) { const LOOP_ZONE = 'dl_loop'; -function sync_firewall(m) { +/** With `dry`, only says whether the firewall config differs from what Dawnline wants. */ +function sync_firewall(m, dry) { let c = cursor(); c.load('firewall'); let changed = false, want = {}; @@ -168,14 +181,20 @@ function sync_firewall(m) { let sn = net.server_net(srv, snap); portal_zone ??= sn.wan.zone; sec(`${z}_zone`, 'zone', { + // Forward within the zone (device to device) is decided by the inet dawnline table. name: srv.ifname, network: [ srv.ifname ], - input: 'ACCEPT', output: 'ACCEPT', forward: 'REJECT', + input: 'ACCEPT', output: 'ACCEPT', forward: 'ACCEPT', }); // Access per person is enforced by the inet dawnline table; the zone // only needs to be allowed to reach each home-network zone and WAN. + // The home network may open connections to the devices too (a router + // or a NAS on the tunnel); their answers pass the table as established. for (let i, zone in sn.zones) - if (zone != sn.wan.zone && zone != srv.ifname) - sec(i == 0 ? `${z}_lan` : `${z}_lan_${replace(zone, /[^A-Za-z0-9_]/g, '_')}`, 'forwarding', { src: srv.ifname, dest: zone }); + if (zone != sn.wan.zone && zone != srv.ifname) { + let sfx = i == 0 ? '' : `_${replace(zone, /[^A-Za-z0-9_]/g, '_')}`; + sec(`${z}_lan${sfx}`, 'forwarding', { src: srv.ifname, dest: zone }); + sec(`${z}_from_lan${sfx}`, 'forwarding', { src: zone, dest: srv.ifname }); + } sec(`${z}_wan`, 'forwarding', { src: srv.ifname, dest: sn.wan.zone }); if (srv.lan_like) { sec(`${z}_loop`, 'forwarding', { src: srv.ifname, dest: LOOP_ZONE }); @@ -232,12 +251,14 @@ function sync_firewall(m) { c.delete('firewall', s); changed = true; } + if (dry) + return changed; if (changed) { c.commit('firewall'); ack_config([ 'firewall' ]); system('fw4 -q reload'); - log('firewall updated'); + system("logger -t dawnline 'firewall updated'"); } return changed; } @@ -313,11 +334,32 @@ function nft_table(m, sets) { // 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 saddr @lan_ok accept'); + // Devices with home access are part of home: they reach each other, where the + // server allows it. Within one server: the firewall has no forwarding between + // different servers' zones. + for (let id, srv in m.servers) + if (srv.private_key && srv.device_mesh) + push(t, ` iifname "${srv.ifname}" ip saddr @lan_ok ip daddr @lan_ok accept`); push(t, ' meta l4proto { tcp, udp } ip saddr . ip daddr . th dport @svc_ok accept'); push(t, ` ip daddr { ${join(', ', PRIVATE4)} } counter drop`); push(t, ' ip saddr @inet_ok accept'); push(t, ' counter drop'); push(t, ' }'); + // The other way: fw4 lets the server's home zones reach the tunnel; here + // only connections from its home networks to people with home access pass + // (paused, ended and internet-only people are not reachable). The admin's + // own port forwards (DNAT) stay with fw4. + push(t, ' chain inbound {'); + push(t, ' type filter hook forward priority filter - 5; policy accept;'); + if (length(ifs)) + push(t, ` oifname { ${join(', ', ifs)} } iifname != { ${join(', ', ifs)} } ct state new jump to_device`); + push(t, ' }'); + push(t, ' chain to_device {'); + push(t, ' meta nfproto ipv6 drop'); + push(t, ' ct status dnat accept'); + push(t, ' ip saddr @lan_nets ip daddr @lan_ok accept'); + push(t, ' counter reject with icmpx admin-prohibited'); + push(t, ' }'); // Devices ask the tunnel address; send each query where it belongs. let to_resolver = rt.mode == 'ns' ? `dnat ip to ${rt.address}:53` : `redirect to :${rt.port}`; let lan_dns = loop.lan_dns(); @@ -345,7 +387,7 @@ function nft_load(script) { writefile(f, script); let r = sh(`nft -f ${f}`); if (r.code != 0) - log(`nft failed: ${trim(r.out)}`); + log('Access rules', "couldn't load", 'error', trim(r.out)); return r.code == 0; } @@ -399,7 +441,7 @@ export function sync_peers(m, states) { unlink(f); res[id] = r.code == 0 ? 'ok' : trim(r.out); if (r.code != 0) - log(`awg syncconf ${srv.ifname}: ${trim(r.out)}`); + slog('awg', 'error', "couldn't load devices into the tunnel", trim(r.out), srv.name); } return res; }; @@ -514,10 +556,45 @@ function sync_uhttpd(m) { if (changed) { c.commit('uhttpd'); system('/etc/init.d/uhttpd reload >/dev/null 2>&1'); - log(want ? 'portal answers on 443 at home too' : 'portal removed from the LuCI web server'); + system(`logger -t dawnline ${q(want ? 'portal answers through the LuCI web server' : 'portal removed from the LuCI web server')}`); } } +/** + * For the watchdog: what is wrong with Dawnline's firewall, or null. + * 'off': fw4 is not running at all (not ours to start); 'changed': the config + * lost or changed Dawnline's sections; 'not loaded': fw4 runs without them. + */ +export function firewall_drift(m) { + let t = sh_out('nft -t list table inet fw4 2>/dev/null') ?? ''; + if (t == '') + return 'off'; + if (sync_firewall(m, true)) + return 'changed'; + // Named rules show up in fw4's ruleset as comments. + let names = []; + for (let id, srv in m.servers) + if (srv.private_key && srv.enabled) + push(names, `Dawnline-${srv.ifname}`); + if (m.settings.portal_enabled) + push(names, 'Dawnline-Portal'); + for (let n in names) + if (index(t, `${n}"`) < 0) + return 'not loaded'; + return null; +}; + +/** For the watchdog: LuCI's web server should hand portal links to the portal, but does not. */ +export function uhttpd_drift(m) { + if (!(m.settings.portal_enabled && core.portal_public_port(m) == 443 && m.settings.portal_port != 443)) + return false; + let c = cursor(); + c.load('uhttpd'); + let cur = c.get('uhttpd', 'main', 'error_page'); + // Someone else's error page is theirs: Health explains, nothing to repair. + return cur == null || (cur == LAN_CGI_URL && !stat(LAN_CGI)); +}; + /** One `ipproto

sport lookup main` rule per listening port and family. */ function sync_reply_routes(m) { let want = []; @@ -580,7 +657,7 @@ function ensure_word_codes() { if (changed) { c.commit('dawnline'); system('chmod 600 /etc/config/dawnline'); - log('personal links moved to word codes'); + log('Personal links', 'moved to word codes'); } } @@ -618,4 +695,7 @@ export function teardown() { remove_nft(); unlink(HOSTS_FILE); system('killall -HUP dnsmasq 2>/dev/null'); + // The agent's heartbeat check. + if (system('grep -qs /usr/libexec/dawnline/heartbeat /etc/crontabs/root') == 0) + system("sed -i '\\#/usr/libexec/dawnline/heartbeat#d' /etc/crontabs/root; /etc/init.d/cron restart >/dev/null 2>&1"); }; 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 1fec678..1d2dc84 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 @@ -87,6 +87,8 @@ export function load(c) { hostnames: bool(s.hostnames, true), domain: s.domain ?? 'lan', log_connections: bool(s.log_connections, true), + // Repair tunnels and services on its own (the agent, every minute). + watchdog: bool(s.watchdog, true), // 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'), // Raw retention values; dawnline.live policy() interprets them. @@ -126,6 +128,8 @@ export function load(c) { detected_wan: r.detected_wan ?? '', detected_lan: r.detected_lan ?? '', lan_like: bool(r.lan_like, true), + // Devices of people with home access reach each other through the tunnel. + device_mesh: bool(r.device_mesh, true), enabled: bool(r.enabled, true), obf: {}, }; @@ -459,8 +463,12 @@ export function client_dns(m, srv, p) { export function allowed_ips(m, srv, p) { if (p.access == 'lan') { let nets = net.server_net(srv).nets; + // With devices reaching each other, the whole tunnel network (the router's + // address is in it); otherwise only the router's own address. let a = server_address(srv); - if (a) + if (srv.device_mesh && srv.subnet) + push(nets, srv.subnet); + else if (a) push(nets, `${a}/32`); // The resolver address must be reachable through the tunnel too (not the fallback). let dns = client_dns(m, srv, p)[0]; 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 5df432c..eb06494 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 @@ -21,12 +21,14 @@ const KEEP_EVENTS = 2000; /** Event type → log category (what Settings lets you switch off or clear). */ export const CATEGORY = { connect: 'connections', disconnect: 'connections', roam: 'connections', - device_added: 'devices', device_removed: 'devices', devices_removed: 'devices', + // People and their devices: one category (devices used to have their own). + 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', paused_all: 'people', resumed_all: 'people', server_down: 'problems', server_up: 'problems', portal_blocked: 'problems', }; -export const CATEGORIES = [ 'connections', 'devices', 'people', 'problems' ]; +export const CATEGORIES = [ 'connections', 'people', 'problems' ]; export function category_of(type) { return CATEGORY[type] ?? 'problems'; @@ -55,7 +57,7 @@ export function policy(s) { cats = (s.log_connections == '0') ? filter(CATEGORIES, (x) => x != 'connections') : CATEGORIES; else if (type(cats) != 'array') cats = split(cats, /[ ,]+/); - cats = filter(cats, (x) => index(CATEGORIES, x) >= 0); + cats = uniq(filter(map(cats, (x) => x == 'devices' ? 'people' : x), (x) => index(CATEGORIES, x) >= 0)); return { keep_days: int_or(s.log_keep_days, 30), max: min(max(int_or(s.log_max, KEEP_EVENTS), 100), 20000), @@ -298,17 +300,33 @@ export function load_events() { return read_json(`${RUN_DIR}/events.json`, null) ?? read_json(`${DATA_DIR}/events.json`, []); }; +/* + * Names as they are now (pname, dname, dkind), so the log still reads well + * once the person or device is gone. Callers that delete first pass them. + */ +function with_names(e, c) { + if (e.person && !e.pname) + e.pname = c.get('dawnline', e.person, 'name'); + if (e.device && !e.dname) + e.dname = c.get('dawnline', e.device, 'name'); + if (e.device && !e.dkind) + e.dkind = c.get('dawnline', e.device, 'kind'); + return e; +} + export function add_events(list, pol) { pol ??= policy(); list = filter(list ?? [], (e) => index(pol.categories, category_of(e.type)) >= 0); if (!length(list)) return; + let c = cursor(); + c.load('dawnline'); let l = lock('events'); let ev = load_events(); let ts = time(); for (let e in list) { e.ts ??= ts; - push(ev, e); + push(ev, with_names(e, c)); } ev = trim_events(ev, pol); ensure_dir(RUN_DIR); @@ -335,8 +353,10 @@ export function add_event_merged(e, window) { last.ts = ts; } else { + let c = cursor(); + c.load('dawnline'); e.ts = ts; - push(ev, e); + push(ev, with_names(e, c)); } ev = trim_events(ev, pol); ensure_dir(RUN_DIR); diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/loop.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/loop.uc index 934d8ee..fc941c8 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/loop.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/loop.uc @@ -27,7 +27,7 @@ import { readfile, writefile, readlink, stat, unlink } from 'fs'; import { cursor } from 'uci'; -import { sh, sh_out, q, ip2int, int2ip, ensure_dir, read_json, write_json, uniq, RUN_DIR } from 'dawnline.util'; +import { sh, sh_out, q, ip2int, int2ip, ensure_dir, read_json, write_json, uniq, slog, RUN_DIR } from 'dawnline.util'; import * as net from 'dawnline.net'; export const NS = 'dawnline'; @@ -40,8 +40,10 @@ const RESOLVER_PID = '/var/run/dawnline-dns.pid'; const STATE = `${RUN_DIR}/loop.json`; const FALLBACK_DNS = [ '1.1.1.1', '8.8.8.8' ]; -function log(msg) { - system(`logger -t dawnline ${q(msg)}`); +const WHO = 'Internet like a home device'; + +function log(msg, level, detail) { + slog('dawnline', level ?? 'info', msg, detail, WHO); } function run(cmds) { @@ -289,8 +291,9 @@ table inet dawnline { function current_rules(ifnames) { let out = []; try { + // Ours, plus ours left behind by a removed tunnel (its interface is gone). for (let r in json(sh_out('ip -j -4 rule show') || '[]') ?? []) - if (r.priority >= 5200 && r.priority < 5300 && r.iif && index(ifnames, r.iif) >= 0) + if (r.priority >= 5200 && r.priority < 5300 && r.iif && (index(ifnames, r.iif) >= 0 || 'iif_detached' in r)) push(out, r); } catch (e) {} @@ -299,6 +302,9 @@ function current_rules(ifnames) { function rule_key(pref, iif, to, table) { + // `ip -j rule` shows a /32 destination without its length. + if (to && index(to, '/') < 0) + to += '/32'; return `${pref} ${iif} ${to ?? 'all'} ${table}`; } @@ -360,9 +366,10 @@ export function ensure(m, force) { if (stat(STATE) || exists(TX_ROOT) || exists(LAN_ROOT) || length(current_rules(ifnames))) remove(ifnames); ensure_dir(RUN_DIR); + let was = read_json(STATE, {}); write_json(STATE, { error: p.error, off: !!p.off }, 0o644); - if (p.error) - log(`like-home routing off: ${p.error}`); + if (p.error && p.error != was.error) + log('is off', 'error', p.error); return p; } let last = read_json(STATE, {}); @@ -410,7 +417,8 @@ export function ensure(m, force) { push(errs, ...run(sync_rules(p, ifnames))); if (length(errs)) { - log(`like-home routing failed, using the direct path: ${errs[0]}`); + if (read_json(STATE, {}).error != `Setup failed: ${errs[0]}`) + log('failed — internet goes out directly for now', 'error', errs[0]); remove(ifnames); write_json(STATE, { error: `Setup failed: ${errs[0]}` }, 0o644); return { error: errs[0] }; @@ -426,7 +434,10 @@ export function ensure(m, force) { } ensure_dir(RUN_DIR); write_json(STATE, { applied: time(), plan: p, transit: p.transit }, 0o644); - log(`like-home routing: ${p.dev} as ${p.address}`); + if (!last.applied || last.plan?.dev != p.dev || last.plan?.address != p.address) + log(`is on · traffic enters ${p.dev} as ${p.address}`, 'up'); + else if (!healthy) + log(`was broken — set up again (${p.dev} as ${p.address})`, 'repair'); return p; }; diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/ops.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/ops.uc index 1ed9f9c..d45a7b5 100644 --- a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/ops.uc +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/ops.uc @@ -93,15 +93,15 @@ function check(id, title, status, detail, fix) { return { id, title, status, detail: detail ?? '', fix: fix ?? null }; } -function udp_listening(port) { +export function udp_listening(port) { let hex = sprintf(':%04X ', port); for (let f in [ '/proc/net/udp', '/proc/net/udp6' ]) if (index(readfile(f) ?? '', hex) >= 0) return true; return false; -} +}; -function tcp_listening(port) { +export function tcp_listening(port) { let hex = sprintf(':%04X ', port); for (let f in [ '/proc/net/tcp', '/proc/net/tcp6' ]) for (let line in split(readfile(f) ?? '', '\n')) @@ -109,7 +109,7 @@ function tcp_listening(port) { if (index(line, hex) > 0 && match(line, / 0A /)) return true; return false; -} +}; /** Processes other than our portal listening on a TCP port: [ "name" ]. */ export function tcp_port_owners(port) { @@ -202,7 +202,7 @@ export function portal_candidates(m) { return sort(out, (a, b) => score(b) - score(a)); }; -function service_running(name, instance) { +export function service_running(name, instance) { let s = sh_out(`ubus call service list '{"name":"${name}"}' 2>/dev/null`); if (!s) return false; @@ -214,7 +214,7 @@ function service_running(name, instance) { catch (e) { return false; } -} +}; function other_subnets(srv_id) { let out = []; 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 38888a3..e1d49dd 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 @@ -3,7 +3,7 @@ import { open, readfile, writefile, rename, mkdir, stat, unlink, popen, lsdir } from 'fs'; -export const VERSION = '0.1.1'; +export const VERSION = '0.2.0'; /** GitHub repository with Dawnline releases (updates and the installer). */ export const REPO = 'tickcount/luci-app-dawnline'; export const RUN_DIR = '/var/run/dawnline'; @@ -126,6 +126,131 @@ export function unlock(f) { } }; +/* ---------- service log ---------- */ + +/* + * Tunnel and service starts and stops, watchdog repairs and errors: one JSON + * object per line in tmpfs (appends from several processes stay whole), a + * copy on flash that the agent refreshes hourly, and a line in syslog. + * src: awg | dawnline | portal; level: info | up | down | repair | error. + */ +export const SLOG = `${RUN_DIR}/service.log`; +export const SLOG_SAVED = `${DATA_DIR}/service.log`; +const SLOG_KEEP = 300; + +export function slog(src, level, msg, detail, who, extra) { + let e = { ts: time(), src, level, msg }; + // The subject, shown first and bold: a server's name, "Personal portal", "Dawnline". + if (who) + e.who = `${who}`; + // The admin's own changes: { by: 'admin', kind: 'server', note: 'port 50115' } + // read "You · ". + for (let k in [ 'by', 'kind', 'note' ]) + if (extra?.[k]) + e[k] = `${extra[k]}`; + if (detail) + e.detail = substr(trim(`${detail}`), 0, 2000); + ensure_dir(RUN_DIR); + let f = open(SLOG, 'a', 0o600); + if (f) { + f.write(sprintf('%J\n', e)); + f.close(); + } + let line = e.by == 'admin' ? join(' ', filter([ 'admin', msg, e.kind, who, e.note ? '· ' + e.note : null ], (x) => x)) : who ? `${who} ${msg}` : msg; + system(`logger -t dawnline${level == 'error' ? ' -p user.err' : ''} ${q(line)}`); +}; + +/** A change the admin made in LuCI, for the service log. */ +export function admin_log(src, msg, kind, who, note, detail) { + slog(src, 'info', msg, detail, who, { by: 'admin', kind, note }); +}; + +/* + * Why Dawnline itself is about to take a tunnel down, so the hotplug log can + * tell that from a tunnel that stopped on its own. reason: settings | off | + * removed | update. Kept for two minutes. + */ +const INTENT = `${RUN_DIR}/iface-intent.json`; + +export function iface_intent(ifname, reason, name) { + let all = read_json(INTENT, {}); + all[ifname] = { reason, name, ts: time() }; + ensure_dir(RUN_DIR); + write_json(INTENT, all, 0o600); +}; + +export function take_iface_intent(ifname) { + let all = read_json(INTENT, {}); + let it = all[ifname]; + if (!it) + return null; + delete all[ifname]; + write_json(INTENT, all, 0o600); + return time() - it.ts < 120 ? it : null; +}; + +/** Newest first. */ +export function slog_read(limit) { + let lines = split(readfile(SLOG) ?? readfile(SLOG_SAVED) ?? '', '\n'); + let out = []; + for (let i = length(lines) - 1; i >= 0 && length(out) < (limit ?? SLOG_KEEP); i--) { + if (lines[i] == '') + continue; + try { + let e = json(lines[i]); + if (type(e) == 'object' && e.ts) + push(out, e); + } + catch (err) {} + } + return out; +}; + +/** Keep the last entries only, and save them to flash when asked. */ +export function slog_trim(save) { + let lines = filter(split(readfile(SLOG) ?? '', '\n'), (l) => l != ''); + if (length(lines) > SLOG_KEEP + 50) { + lines = slice(lines, -SLOG_KEEP); + write_file(SLOG, join('\n', lines) + '\n'); + } + if (save && length(lines) && stat(SLOG)?.mtime > (stat(SLOG_SAVED)?.mtime ?? 0)) { + ensure_dir(DATA_DIR, 0o700); + write_file(SLOG_SAVED, join('\n', lines) + '\n'); + } +}; + +/** Remove entries (all, or older than `days`); returns how many went. */ +export function slog_clear(days) { + let keep = [], removed = 0, cut = days > 0 ? time() - days * 86400 : null; + for (let l in split(readfile(SLOG) ?? readfile(SLOG_SAVED) ?? '', '\n')) { + if (l == '') + continue; + let e = null; + try { + e = json(l); + } + catch (err) {} + if (cut != null && e?.ts >= cut) + push(keep, l); + else + removed++; + } + let data = length(keep) ? join('\n', keep) + '\n' : ''; + ensure_dir(RUN_DIR); + write_file(SLOG, data); + if (stat(SLOG_SAVED)) + write_file(SLOG_SAVED, data); + return removed; +}; + +/** After a reboot tmpfs is empty: continue the log saved on flash. */ +export function slog_restore() { + if (!stat(SLOG) && stat(SLOG_SAVED)) { + ensure_dir(RUN_DIR); + write_file(SLOG, readfile(SLOG_SAVED) ?? ''); + } +}; + /* ---------- IPv4 ---------- */ export function ip2int(ip) { diff --git a/package/luci-app-dawnline/root/usr/share/ucode/dawnline/watchdog.uc b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/watchdog.uc new file mode 100644 index 0000000..17b5f87 --- /dev/null +++ b/package/luci-app-dawnline/root/usr/share/ucode/dawnline/watchdog.uc @@ -0,0 +1,190 @@ +// Dawnline — watchdog. The agent runs it every minute: it checks what keeps +// people connected and repairs what it can, waiting longer after each repair +// that did not help. What it finds goes to the service log; its state to +// RUN_DIR for the Health page. A cron job (libexec/dawnline/heartbeat) looks +// after the agent itself. + +import { stat } from 'fs'; +import { sh_out, q, read_json, write_json, slog, slog_read, RUN_DIR } from 'dawnline.util'; +import * as core from 'dawnline.core'; +import * as live from 'dawnline.live'; +import * as apply from 'dawnline.apply'; +import * as loop from 'dawnline.loop'; +import * as ops from 'dawnline.ops'; + +export const STATE = `${RUN_DIR}/watchdog.json`; +/** The agent writes the time here on every tick. */ +export const BEAT = `${RUN_DIR}/agent.beat`; +// Seconds before the next repair, by the number of repairs so far. +const WAIT = [ 0, 120, 600, 1800, 3600 ]; + +/** Why a tunnel is down, from netifd and the last related syslog lines. */ +export function iface_errors(ifname) { + let s = live.iface_status(ifname); + let errs = map(s?.errors ?? [], (e) => e.code + (length(e.data ?? []) ? ` (${join(' ', e.data)})` : '')); + // Only what explains a failure, not the ordinary "is now up/down" lines. + let lines = sh_out(`logread -l 400 2>/dev/null | grep -E ${q(`${ifname}|amneziawg`)} | grep -iE 'error|fail|invalid|unrecogni|cannot|unable|not found|refused|denied' | tail -n 6`); + return join('\n', filter([ length(errs) ? `netifd: ${join(', ', errs)}` : null, lines ], (x) => x)); +}; + +function restart_services() { + // procd keeps unchanged instances (the agent running this) and starts missing ones. + system('/etc/init.d/dawnline start >/dev/null 2>&1'); +} + +/** + * What to look at: { id (= the Health check id), src, name (chip), who (the log's subject), ok, + * problem, back, detail?, repair: { what, run }? }. The log reads " — ". + */ +function probes(m) { + let out = []; + // The kernel module first: without it no tunnel can run (they come back on the next pass). + if (length(filter(values(m.servers), (x) => x.enabled && x.private_key)) && stat('/usr/bin/awg')) + push(out, { + id: 'awg', src: 'awg', name: 'AmneziaWG', who: 'AmneziaWG', ok: stat('/sys/module/amneziawg') != null, + problem: "kernel module isn't loaded", back: 'kernel module is loaded again', + detail: () => sh_out("modprobe amneziawg 2>&1; dmesg 2>/dev/null | grep -i amneziawg | grep -iE 'error|fail|invalid|unknown|disagrees|taint' | tail -n 4"), + repair: { what: 'loading it', run: () => system('modprobe amneziawg >/dev/null 2>&1') }, + }); + for (let id, srv in m.servers) { + if (!srv.enabled || !srv.private_key) + continue; + let s = live.iface_status(srv.ifname); + let up = !!s?.up; + push(out, { + id: `up_${id}`, src: 'awg', name: srv.name, who: srv.name, ok: up && ops.udp_listening(srv.port), + problem: !s ? 'is missing from the router' : !up ? "isn't running" : `isn't accepting connections on port ${srv.port}`, + back: `is running again · accepting connections on port ${srv.port}`, + detail: () => iface_errors(srv.ifname), + repair: s ? { what: 'restarting it', run: () => system(`ifup ${q(srv.ifname)}`) } : { what: 'setting it up again', run: () => apply.apply() }, + }); + } + if (length(m.servers)) + push(out, { + id: 'nft', src: 'dawnline', name: 'Access rules', who: 'Access rules', ok: system('nft list table inet dawnline >/dev/null 2>&1') == 0, + problem: 'are missing', back: 'are loaded again', + repair: { what: 'loading them again', run: () => apply.apply() }, + }); + + if (length(filter(values(m.servers), (x) => x.private_key))) { + let fw = apply.firewall_drift(m); + push(out, { + id: 'fw', src: 'dawnline', name: 'Firewall', who: 'Firewall', ok: fw == null, + problem: fw == 'off' ? "isn't running on this router (fw4): tunnels and the portal are closed" + : fw == 'changed' ? "rules for Dawnline were changed or removed" : "rules for Dawnline aren't loaded", + back: 'rules for Dawnline are in place again', + // fw4 stopped on purpose is the admin's call: report it, do not start it. + repair: fw == 'off' ? null : { what: 'restoring them', run: () => { apply.apply(); system('fw4 -q reload'); } }, + }); + } + + let s = m.settings; + if (s.portal_enabled && core.portal_public_port(m) == 443 && s.portal_port != 443) + push(out, { + id: 'portal_lan', src: 'portal', name: 'Portal at home', who: 'Personal portal', ok: !apply.uhttpd_drift(m), + problem: "links don't open at home (LuCI's web server lost the setting)", back: 'links open at home again', + repair: { what: 'restoring it', run: () => apply.apply() }, + }); + if (s.portal_enabled && !length(ops.needs().https) && !length(ops.tcp_port_owners(s.portal_port))) + push(out, { + id: 'portal', src: 'portal', name: 'Portal', who: 'Personal portal', ok: ops.tcp_listening(s.portal_port), + problem: `isn't answering on port ${s.portal_port}`, back: 'answers again', + detail: () => sh_out("logread -l 400 2>/dev/null | grep 'uhttpd' | grep -iE 'error|fail|cert|key|bind|address' | tail -n 4"), + repair: { what: 'restarting it', run: restart_services }, + }); + + if (stat(loop.RESOLVER.conf)) + push(out, { + id: 'resolver', src: 'dawnline', name: 'Resolver', who: 'DNS for Home-only devices', ok: loop.resolver_running(), + problem: "isn't running", back: 'runs again', + repair: { what: 'restarting it', run: restart_services }, + }); + + push(out, { + id: 'rpc', src: 'dawnline', name: 'LuCI link', who: 'LuCI', ok: system('ubus list luci.dawnline >/dev/null 2>&1') == 0, + problem: "can't reach Dawnline (luci.dawnline is missing in rpcd)", back: 'reaches Dawnline again', + detail: () => sh_out('logread -l 400 2>/dev/null | grep rpcd | tail -n 4'), + // A reload keeps LuCI logins; a restart (second try) signs everyone out. + repair: { what: 'reloading rpcd', run: (n) => system(n > 1 ? '/etc/init.d/rpcd restart >/dev/null 2>&1' : '/etc/init.d/rpcd reload >/dev/null 2>&1') }, + }); + return out; +} + +/** One pass. With repairs off it only reports. */ +export function run(m) { + let now = time(); + let fix = m.settings.watchdog; + let st = read_json(STATE, {}); + let t = type(st.targets) == 'object' ? st.targets : {}; + let repairs = filter(st.repairs ?? [], (r) => now - r.ts < 86400); + let seen = {}; + for (let p in probes(m)) { + seen[p.id] = true; + let x = t[p.id] ??= { bad: 0, tries: 0, next: 0 }; + x.name = p.name; + x.ok = p.ok; + if (p.ok) { + if (x.reported) + slog(p.src, 'up', p.back + (x.stuck ? ' · restored' : x.tries ? ` (after ${x.tries} repair${x.tries > 1 ? 's' : ''})` : ''), null, p.who); + x.bad = 0; + x.tries = 0; + x.next = 0; + x.reported = false; + x.stuck = false; + continue; + } + // One bad minute can be a restart in progress. + if (++x.bad < 2) + continue; + if (!fix || !p.repair) { + if (!x.reported) + slog(p.src, 'error', p.problem, p.detail?.(), p.who); + x.reported = true; + continue; + } + // Three repairs did not help: say so once, in red, and from then on keep + // trying quietly until it works again (that is logged). + if (x.tries >= 3 && !x.stuck && now - (x.last ?? 0) >= 50) { + x.stuck = true; + slog(p.src, 'error', `${p.problem} — ${x.tries} repairs didn't help`, p.detail?.(), p.who); + } + if (now < x.next) + continue; + x.tries++; + x.last = now; + x.next = now + WAIT[min(x.tries, length(WAIT) - 1)]; + x.reported = true; + if (!x.stuck) + slog(p.src, 'repair', `${p.problem} — ${p.repair.what}`, p.detail?.(), p.who); + try { + p.repair.run(x.tries); + } + catch (e) { + if (!x.stuck) + slog(p.src, 'error', `couldn't be repaired: ${e.message}`, null, p.who); + } + if (!x.stuck) + push(repairs, { ts: now, id: p.id, name: p.name }); + } + for (let id in keys(t)) + if (!seen[id]) + delete t[id]; + write_json(STATE, { last: now, targets: t, repairs }, 0o644); +}; + +/** For the Health page: the watchdog's state and the newest log entries. */ +export function view(m) { + let st = read_json(STATE, {}); + let beat = +(read_json(BEAT, 0) ?? 0); + // The agent itself: fine while it ticks (cron restarts it after 5 minutes without). + let targets = [ { id: 'agent', name: 'Agent', ok: beat > 0 && time() - beat < 180, tries: 0 } ]; + for (let id, x in (type(st.targets) == 'object' ? st.targets : {})) + push(targets, { id, name: x.name, ok: !!x.ok, tries: x.tries ?? 0 }); + return { + watchdog: { + enabled: m.settings.watchdog, last: st.last ?? null, beat: beat || null, now: time(), + targets, repairs: st.repairs ?? [], + }, + log: slog_read(200), + }; +}; diff --git a/web/package-lock.json b/web/package-lock.json index cc1f8c9..f14a340 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -1,12 +1,12 @@ { "name": "dawnline-web", - "version": "0.1.1", + "version": "0.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "dawnline-web", - "version": "0.1.1", + "version": "0.2.0", "license": "MIT", "dependencies": { "qrcode-generator": "1.4.4" diff --git a/web/package.json b/web/package.json index f61ec0a..fb31fec 100644 --- a/web/package.json +++ b/web/package.json @@ -1,6 +1,6 @@ { "name": "dawnline-web", - "version": "0.1.1", + "version": "0.2.0", "private": true, "license": "MIT", "type": "module", diff --git a/web/src/admin/api.ts b/web/src/admin/api.ts index 5684f3a..fcfff72 100644 --- a/web/src/admin/api.ts +++ b/web/src/admin/api.ts @@ -114,7 +114,7 @@ export interface SettingsData { logs: LogsInfo; } -export type LogCategory = 'connections' | 'devices' | 'people' | 'problems'; +export type LogCategory = 'connections' | 'people' | 'problems'; export interface LogsInfo { policy: { @@ -178,7 +178,7 @@ export interface InterfacesData { ifname: string; detected: { wan: string | null; lan: string | null }; saved: { wan: string; lan: string }; - config: { auto_wan: boolean; wan_device: string; auto_lan: boolean; lan_devices: string[]; lan_like: boolean }; + config: { auto_wan: boolean; wan_device: string; auto_lan: boolean; lan_devices: string[]; lan_like: boolean; device_mesh: boolean }; like_home: LikeHome; effective: { wan: { dev: string | null; zone: string; auto: boolean; missing: boolean }; @@ -275,6 +275,37 @@ async function status(days?: number): Promise { return st; } +/** One line of the service log: tunnel and service starts, stops, watchdog repairs, errors. */ +export interface ServiceLogEntry { + ts: number; + src: 'awg' | 'dawnline' | 'portal'; + level: 'info' | 'up' | 'down' | 'repair' | 'error'; + msg: string; + detail?: string; + /** Subject shown first: a server's name, "Personal portal", "Dawnline" (older entries have none). */ + who?: string; + /** The admin's own changes read "You · ". */ + by?: 'admin'; + kind?: string; + note?: string; +} + +export interface ServiceLog { + watchdog: { + enabled: boolean; + /** Last watchdog pass and last agent tick (null: never). */ + last: number | null; + beat: number | null; + now: number; + targets: { id: string; name: string; ok: boolean; tries: number }[]; + /** Repairs in the last 24 hours; id is the Health check id. */ + repairs: { ts: number; id: string; name: string }[]; + }; + log: ServiceLogEntry[]; +} + +export type Health = { checks: HealthCheck[] } & ServiceLog; + export const api = { personUpdate, settingsGet: call('settings_get'), @@ -285,7 +316,15 @@ export const api = { events: call<{ events: LogEvent[]; total: number; policy: LogsInfo['policy'] }>('events', ['limit']), logsClear, interfaces: call('interfaces', ['id']), - serverInterfaces: call('server_interfaces', ['id', 'auto_wan', 'wan_device', 'auto_lan', 'lan_devices', 'lan_like']), + serverInterfaces: call('server_interfaces', [ + 'id', + 'auto_wan', + 'wan_device', + 'auto_lan', + 'lan_devices', + 'lan_like', + 'device_mesh', + ]), usageClear: call('usage_clear', ['scope', 'id']), uninstall: call('uninstall', ['confirm']), status, @@ -329,8 +368,10 @@ export const api = { deviceDelete: call('device_delete', ['id']), deviceRotate: call('device_rotate', ['id']), apply: call('apply'), - health: call<{ checks: HealthCheck[] }>('health'), - healthFix: call<{ checks: HealthCheck[] }>('health_fix', ['id']), + health: call('health'), + healthFix: call('health_fix', ['id']), + serviceLog: call('service_log'), + serviceLogClear: call<{ removed: number }>('service_log_clear', ['older_days']), backupList: call<{ backups: Backup[] }>('backup_list'), backupCreate: call<{ name: string }>('backup_create'), backupRestore: call('backup_restore', ['name']), diff --git a/web/src/admin/device.ts b/web/src/admin/device.ts index 48a311a..a77eccf 100644 --- a/web/src/admin/device.ts +++ b/web/src/admin/device.ts @@ -9,6 +9,7 @@ import { qrSvg } from '../shared/qr'; import { vpnKey } from '../shared/vpnkey'; import { ago, bytes, KIND_LABEL, KINDS } from '../shared/format'; import { icon } from '../shared/icons'; +import { eventBy } from './pages/overview'; import { spark } from './charts'; import { clearLogDialog, exportEvents, resetUsageDialog } from './logs'; @@ -20,7 +21,7 @@ function iso(ts: number): string { : '—'; } -function copyRow(label: string, value: string, mono = true): HTMLElement { +function copyRow(label: string, value: string, mono = false): HTMLElement { return E('div', { class: 'dl-kvrow' }, [ E('span', { class: 'dl-kvrow-k' }, label), E( @@ -106,8 +107,8 @@ function fileCard(cfg: ClientConfig): HTMLElement { ]); } -/** QR / key / file switcher for a client configuration. */ -export async function connectBlock(cfg: ClientConfig): Promise { +/** File / key / QR switcher for a client configuration; opens on the file unless asked otherwise. */ +export async function connectBlock(cfg: ClientConfig, initial: 'file' | 'key' | 'qr' = 'file'): Promise { if (!cfg.has_private_key) return E( 'div', @@ -135,12 +136,12 @@ export async function connectBlock(cfg: ClientConfig): Promise { dom.content(body, panes[id]()); }; for (const [id, label] of [ - ['qr', 'QR code'], - ['key', 'Key'], ['file', 'File'], + ['key', 'Key'], + ['qr', 'QR code'], ]) seg.appendChild(E('button', { type: 'button', 'data-id': id, click: () => show(id) }, label)); - show('qr'); + show(initial); return E('div', { class: 'dl-stack gap12' }, [seg, body]); } @@ -183,12 +184,13 @@ function drawer(title: Node, body: Node, foot: Node | null, onClose: () => void) return handle; } -const DEV_EVENT: Record = { - connect: ['ok', 'Connected'], - disconnect: ['', 'Went offline'], - roam: ['', 'Changed network'], - device_added: ['accent', 'Added'], - device_removed: ['', 'Removed'], +const DEV_EVENT: Record = { + 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'], }; /** Activity of one device, newest first. */ @@ -202,21 +204,24 @@ function deviceEvents(events: LogEvent[], id: string): HTMLElement { 'div', { class: 'dl-dev-log' }, mine.map((e) => { - const [tone, label] = DEV_EVENT[e.type]; + const [tone, label, ic] = DEV_EVENT[e.type]; + // As in the main log: what happened in the text colour, the details muted. const extra = e.type === 'connect' ? [ - e.detail ? E('span', { class: 'dl-mono' }, ` ${e.detail}`) : '', - e.where ? E('span', { class: 'dl-faint' }, ` · ${e.where}`) : '', + e.detail ? E('span', { class: 'dl-muted' }, ` from ${e.detail}`) : '', + e.where ? E('span', { class: 'dl-muted' }, ` · ${e.where}`) : '', ] : e.type === 'roam' - ? [E('span', { class: 'dl-mono dl-faint' }, ` ${e.detail ?? ''}`)] - : e.type === 'device_added' - ? [E('span', { class: 'dl-faint' }, (e.detail ?? '').includes('(portal)') ? ' from the portal' : ' by you')] + ? [E('span', { class: 'dl-muted' }, ` · ${e.detail ?? ''}`)] + : e.type === 'device_added' || e.type === 'device_removed' || e.type === 'device_keys' + ? [E('span', { class: 'dl-muted' }, eventBy(e) === 'portal' ? ' on the portal' : eventBy(e) === 'admin' ? ' by you' : '')] : []; const t = new Date(e.ts * 1000); - return E('div', { class: 'dl-dev-log-row' }, [ - E('span', { class: `dl-ev-dot ${tone}` }), + return E('div', { class: `dl-dev-log-row${eventBy(e) === 'admin' ? ' dl-ev-by-admin' : ''}` }, [ + eventBy(e) === 'admin' + ? E('span', { class: 'dl-ev-tile', title: 'Done by you in LuCI' }, icon('admin')) + : E('span', { class: `dl-ev-tile ev ${tone}` }, icon(ic)), E('span', { class: 'dl-row-main' }, [E('span', {}, label), ...extra]), E('span', { class: 'dl-faint dl-nowrap', title: t.toLocaleString() }, ago(e.ts)), ]); @@ -225,10 +230,11 @@ function deviceEvents(events: LogEvent[], id: string): HTMLElement { } function statusLine(d: Device): HTMLElement { - if (d.disabled) return E('span', { class: 'dl-dstat' }, [E('i', { class: 'dot' }), 'Disabled']); - if (d.online) return E('span', { class: 'dl-dstat ok' }, [E('i', { class: 'dot ok' }), `Online from ${d.endpoint}`]); - if (!d.handshake) return E('span', { class: 'dl-dstat warn' }, [E('i', { class: 'dot warn' }), 'Waiting for the first connection']); - return E('span', { class: 'dl-dstat' }, [E('i', { class: 'dot' }), `Last seen ${ago(d.handshake)}`]); + // Status as coloured text, no dots (only avatars carry one). + if (d.disabled) return E('span', { class: 'dl-dstat' }, 'Disabled'); + if (d.online) return E('span', { class: 'dl-dstat ok' }, 'Connected'); + if (!d.handshake) return E('span', { class: 'dl-dstat warn' }, 'Waiting for the first connection'); + return E('span', { class: 'dl-dstat' }, `Last seen ${ago(d.handshake)}`); } /** Device drawer; `refresh` reloads the page after changes. */ @@ -241,7 +247,6 @@ export async function openDevice(person: Person, dev: Device, refresh: () => unk const titleEl = E('div', { class: 'dl-drawer-title' }); const stats = E('div', {}); const details = E('div', {}); - const live = E('div', { class: 'dl-live' }); const log = E('div', {}, E('div', { class: 'dl-sub' }, 'Loading…')); let logEvents: LogEvent[] = []; const loadLog = async () => { @@ -289,8 +294,8 @@ export async function openDevice(person: Person, dev: Device, refresh: () => unk ? row( 'Client IP', E('span', {}, [ - E('span', { class: 'dl-mono' }, d.endpoint), - place ? E('span', { class: 'dl-faint' }, ` · ${[place.city, place.org].filter(Boolean).join(' · ')}`) : '', + d.endpoint, + place ? E('span', { class: 'dl-muted' }, ` · ${[place.city, place.org].filter(Boolean).join(' · ')}`) : '', ]), ) : '', @@ -316,14 +321,6 @@ export async function openDevice(person: Person, dev: Device, refresh: () => unk ), ]), ); - dom.content( - live, - d.online - ? [E('i', { class: 'dot ok' }), E('span', { class: 'dl-ok' }, 'Connected')] - : d.handshake - ? [E('i', { class: 'dot' }), E('span', { class: 'dl-muted' }, `Last connected ${ago(d.handshake)}`)] - : [E('i', { class: 'dot warn pulse' }), E('span', { class: 'dl-muted' }, 'Waiting for the first connection…')], - ); dom.content(foot, [ button( [icon(d.disabled ? 'play' : 'pause'), d.disabled ? ' Enable' : ' Disable'], @@ -413,47 +410,49 @@ export async function openDevice(person: Person, dev: Device, refresh: () => unk }; const foot = E('div', { class: 'dl-drawer-actions' }); - const body = E('div', { class: 'dl-stack gap16' }, [ - stats, - E('section', { class: 'dl-dsec' }, [ - E('div', { class: 'dl-dsec-head' }, [E('h4', {}, 'Connect'), live]), - d.config_stale - ? E('div', { class: 'dl-note warn' }, [ - icon('alert'), - E( - '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.', - ), - ]) - : '', - connect, - ]), - E('section', { class: 'dl-dsec' }, [ - E('div', { class: 'dl-dsec-head' }, [ - E('h4', {}, 'Activity'), - E('div', { class: 'dl-dsec-actions' }, [ + const connectSec = E('section', { class: 'dl-dsec' }, [ + // Whether it is connected (or still waiting) is in Status above. + E('div', { class: 'dl-dsec-head' }, [E('h4', {}, 'Connect')]), + d.config_stale + ? E('div', { class: 'dl-note warn' }, [ + icon('alert'), E( - 'button', - { type: 'button', class: 'dl-linkbtn', click: () => exportEvents({ people: [p] }, logEvents, 'csv', d.id) }, - 'Export', + '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.', ), - E( - 'button', - { - type: 'button', - class: 'dl-linkbtn danger', - click: () => clearLogDialog(`Clear ${d.name}'s activity`, `Removes events about ${d.name}.`, { device: d.id }, loadLog), - }, - 'Clear', - ), - E('a', { href: L.url('admin/network/dawnline/activity') }, 'All activity'), - ]), - ]), - log, - ]), - E('section', { class: 'dl-dsec' }, [E('div', { class: 'dl-dsec-head' }, E('h4', {}, 'Details')), details]), + ]) + : '', + connect, ]); + const activitySec = E('section', { class: 'dl-dsec' }, [ + E('div', { class: 'dl-dsec-head' }, [ + E('h4', {}, 'Activity'), + E('div', { class: 'dl-dsec-actions' }, [ + E('button', { type: 'button', class: 'dl-linkbtn', click: () => exportEvents({ people: [p] }, logEvents, 'csv', d.id) }, 'Export'), + E( + 'button', + { + type: 'button', + class: 'dl-linkbtn danger', + click: () => clearLogDialog(`Clear ${d.name}'s activity`, `Removes events about ${d.name}.`, { device: d.id }, loadLog), + }, + 'Clear', + ), + E('a', { href: `${L.url('admin/network/dawnline/diagnostics')}?tab=log` }, 'All activity'), + ]), + ]), + log, + ]); + const detailsSec = E('section', { class: 'dl-dsec' }, [E('div', { class: 'dl-dsec-head' }, E('h4', {}, 'Details')), details]); + // Connecting is what the drawer is for until the device is set up (or its configuration is old); + // after that it goes to the bottom. + const setUp = !d.handshake || d.config_stale; + const body = E( + 'div', + { class: 'dl-stack gap16' }, + setUp ? [stats, connectSec, detailsSec, activitySec] : [stats, detailsSec, activitySec, connectSec], + ); loadLog(); const watch = window.setInterval(() => { reload(); diff --git a/web/src/admin/interfaces.ts b/web/src/admin/interfaces.ts index 83bf725..313c062 100644 --- a/web/src/admin/interfaces.ts +++ b/web/src/admin/interfaces.ts @@ -56,11 +56,12 @@ export function interfacesCard(serverId: string, title = 'Interfaces'): HTMLElem let autoWan = true, wanDev = '', autoLan = true, - lanLike = true; + lanLike = true, + mesh = true; let lans = new Set(); let initial = ''; - const snapshot = () => JSON.stringify([lanLike, autoWan, autoWan ? '' : wanDev, autoLan, [...lans].sort()]); + const snapshot = () => JSON.stringify([lanLike, mesh, autoWan, autoWan ? '' : wanDev, autoLan, [...lans].sort()]); const liveLan = () => d.detected.lan || d.saved.lan || ''; const currentWan = () => (autoWan ? d.detected.wan || d.saved.wan : wanDev) || ''; const byName = () => new Map(d.devices.map((x) => [x.name, x])); @@ -79,6 +80,7 @@ export function interfacesCard(serverId: string, title = 'Interfaces'): HTMLElem wanDev = r.config.wan_device || r.detected.wan || r.saved.wan || ''; autoLan = r.config.auto_lan; lanLike = r.config.lan_like; + mesh = r.config.device_mesh; lans = new Set(r.config.lan_devices); initial = snapshot(); } @@ -129,11 +131,7 @@ export function interfacesCard(serverId: string, title = 'Interfaces'): HTMLElem [ E('span', { class: 'dl-if-ic' }, icon(ICON[x.kind] ?? 'link')), E('span', { class: 'dl-if-main' }, [E('span', { class: 'dl-if-name' }, x.name), E('span', { class: 'dl-if-sub' }, sub)]), - isAuto - ? E('span', { class: 'dl-if-badge ok' }, [E('i', { class: 'dot ok' }), 'Auto']) - : sel - ? E('span', { class: 'dl-if-check' }, icon('check')) - : '', + isAuto ? E('span', { class: 'dl-if-badge ok' }, 'Auto') : sel ? E('span', { class: 'dl-if-check' }, icon('check')) : '', ], ); attachTip(el, () => [ @@ -197,8 +195,12 @@ export function interfacesCard(serverId: string, title = 'Interfaces'): HTMLElem .map((x) => E('option', { value: x.name, selected: x.name === wanDev ? 'selected' : null }, `${x.name} · zone ${x.zone}`)), ) as HTMLSelectElement; - const hint = (live: string | null, saved: string) => - E('span', {}, [' Live: ', E('span', { class: 'dl-mono' }, live || '—'), ' · Saved: ', E('span', { class: 'dl-mono' }, saved || '—')]); + // What auto-detection finds now; the remembered one (used when nothing is found) only when it differs. + const hint = (live: string | null, saved: string) => { + const mono = (t: string) => E('span', { class: 'dl-mono' }, t); + if (live) return E('span', {}, [' Now: ', mono(live), ...(saved && saved !== live ? [', was ', mono(saved)] : []), '.']); + return E('span', {}, saved ? [' Not found now: using ', mono(saved), '.'] : [' Not found.']); + }; const groups = GROUPS.map(([cat, label]) => { const list = d.devices.filter((x) => x.category === cat); @@ -212,7 +214,7 @@ export function interfacesCard(serverId: string, title = 'Interfaces'): HTMLElem 'Save', async () => { const r = await attempt( - () => api.serverInterfaces(serverId, autoWan, autoWan ? '' : wanDev, autoLan, [...lans], lanLike), + () => api.serverInterfaces(serverId, autoWan, autoWan ? '' : wanDev, autoLan, [...lans], lanLike, mesh), 'Interfaces saved', ); if (!r) return; @@ -251,6 +253,27 @@ export function interfacesCard(serverId: string, title = 'Interfaces'): HTMLElem }), ]), ]), + E('div', { class: 'dl-setrow' }, [ + E('div', { class: 'dl-lh-main' }, [ + E('span', { class: 'dl-need-ic' }, icon('link')), + E('div', { class: 'dl-stack' }, [ + E('span', { class: 'dl-setrow-label' }, 'Devices reach each other'), + E( + 'span', + { class: 'dl-sub' }, + 'Devices of people with Home access can open connections to each other on this server, like home devices do. Internet-only people never.', + ), + ]), + ]), + E( + 'div', + { class: 'dl-setrow-ctl' }, + sw(mesh, 'Devices reach each other', (v) => { + mesh = v; + paint(); + }), + ), + ]), E('div', { class: 'dl-setrow' }, [ E('div', { class: 'dl-lh-main' }, [ E('span', { class: 'dl-need-ic' }, icon('globe')), @@ -292,7 +315,7 @@ export function interfacesCard(serverId: string, title = 'Interfaces'): HTMLElem E( 'span', { class: 'dl-sub' }, - 'What people with Home access can reach. Click to add an interface; bridge ports and Wi-Fi in a bridge come with the bridge.', + 'What people with Home access can reach, and where their devices can be reached from. Click to add an interface; bridge ports and Wi-Fi in a bridge come with the bridge.', ), ]), ...groups, diff --git a/web/src/admin/logs.ts b/web/src/admin/logs.ts index 63871d5..793e45d 100644 --- a/web/src/admin/logs.ts +++ b/web/src/admin/logs.ts @@ -3,17 +3,21 @@ import type { LogEvent, Status } from '../shared/types'; import { E } from './e'; -import { api, type LogCategory, type LogFilter } from './api'; +import { api, type LogCategory, type LogFilter, type ServiceLogEntry } from './api'; import { attempt, button, closeModal, downloadFile, modal, notify } from './ui'; +import { eventBy } from './pages/overview'; /** Mirrors CATEGORY in dawnline.live. */ const CATEGORY: Record = { connect: 'connections', disconnect: 'connections', roam: 'connections', - device_added: 'devices', - device_removed: 'devices', - devices_removed: 'devices', + 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', @@ -21,25 +25,21 @@ const CATEGORY: Record = { resumed: 'people', paused_all: 'people', resumed_all: 'people', - server_down: 'problems', - server_up: 'problems', portal_blocked: 'problems', }; -export const CATEGORIES: LogCategory[] = ['connections', 'devices', 'people', 'problems']; +export const CATEGORIES: LogCategory[] = ['connections', 'people', 'problems']; export const CATEGORY_LABEL: Record = { connections: 'Connections', - devices: 'Devices', people: 'People', problems: 'Problems', }; export const CATEGORY_HELP: Record = { connections: 'Connects, disconnects and IP changes', - devices: 'Devices added and removed', - people: 'People added, changed, paused', - problems: 'Tunnel down, blocked portal sign-ins', + people: 'People and their devices added, changed, paused, removed', + problems: 'Blocked portal sign-ins (tunnels and services are in the service log)', }; export const categoryOf = (type: string): LogCategory => CATEGORY[type] ?? 'problems'; @@ -55,25 +55,48 @@ function csvCell(v: unknown): string { return /[",\n]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s; } -/** Download events as CSV or JSON (person and device names resolved). */ -export function exportEvents(st: Pick, events: LogEvent[], format: 'csv' | 'json', suffix = '') { +export const SYSTEM_SOURCE: Record = { awg: 'AmneziaWG', dawnline: 'Dawnline', portal: 'Portal' }; + +/** Download events (and service log entries, category "system") as CSV or JSON, names resolved, oldest first. */ +export function exportEvents( + st: Pick, + events: LogEvent[], + format: 'csv' | 'json', + suffix = '', + system: ServiceLogEntry[] = [], +) { const n = names(st); - const rows = events.map((e) => ({ - time: new Date(e.ts * 1000).toISOString(), - category: categoryOf(e.type), - type: e.type, - person: e.person ? (n.people.get(e.person) ?? e.person) : '', - device: e.device ? (n.devices.get(e.device) ?? e.device) : '', - detail: e.detail ?? '', - where: e.where ?? '', - })); + const rows = [ + ...events.map((e) => ({ + ts: e.ts, + category: categoryOf(e.type) as string, + type: e.type as string, + person: e.person ? (n.people.get(e.person) ?? e.pname ?? e.person) : '', + device: e.device ? (n.devices.get(e.device) ?? e.dname ?? e.device) : '', + detail: e.detail ?? '', + where: e.where ?? '', + by: eventBy(e) ?? '', + })), + ...system.map((e) => ({ + ts: e.ts, + category: 'system', + type: `${e.src}.${e.level}`, + person: '', + device: '', + detail: `${e.who ? `${e.who} ` : ''}${e.msg}${e.detail ? `\n${e.detail}` : ''}`, + where: SYSTEM_SOURCE[e.src] ?? e.src, + by: '', + })), + ] + .sort((a, b) => a.ts - b.ts) + .map(({ ts, ...r }) => ({ time: new Date(ts * 1000).toISOString(), ...r })); const stamp = new Date().toISOString().slice(0, 10); const name = `dawnline-activity${suffix ? `-${suffix}` : ''}-${stamp}.${format}`; if (format === 'json') { downloadFile(name, JSON.stringify(rows, null, 2), 'application/json'); return; } - const cols = ['time', 'category', 'type', 'person', 'device', 'detail', 'where'] as const; + const cols = ['time', 'category', 'type', 'person', 'device', 'detail', 'where', 'by'] as const; const csv = [cols.join(','), ...rows.map((r) => cols.map((c) => csvCell(r[c])).join(','))].join('\n'); downloadFile(name, csv, 'text/csv'); } @@ -89,10 +112,18 @@ const AGES: [string, string][] = [ * Ask what to clear and do it. `base` pins person/device; the dialog lets you * pick a category (unless `category` is given) and an age. */ -export function clearLogDialog(title: string, what: string, base: LogFilter, done: () => unknown, category?: LogCategory) { +export function clearLogDialog( + title: string, + what: string, + base: LogFilter, + done: () => unknown, + category?: LogCategory | 'system', + withSystem = false, +) { const cat = E('select', { class: 'cbi-input-select' }, [ E('option', { value: '' }, 'All categories'), ...CATEGORIES.map((c) => E('option', { value: c, selected: c === category ? 'selected' : null }, CATEGORY_LABEL[c])), + withSystem ? E('option', { value: 'system', selected: category === 'system' ? 'selected' : null }, 'System') : '', ]) as HTMLSelectElement; const age = E( 'select', @@ -112,7 +143,13 @@ export function clearLogDialog(title: string, what: string, base: LogFilter, don button( 'Clear', async () => { - const r = await attempt(() => api.logsClear({ ...base, category: cat.value, older_days: age.value })); + // System is the service log; "All categories" clears it too where it is shown. + const r = await attempt(async () => { + const sys = withSystem && (cat.value === 'system' || cat.value === '') ? await api.serviceLogClear(age.value) : { removed: 0 }; + const ev = + cat.value === 'system' ? { removed: 0 } : await api.logsClear({ ...base, category: cat.value, older_days: age.value }); + return { removed: sys.removed + ev.removed }; + }); if (!r) return; closeModal(); notify(r.removed ? `${r.removed} event${r.removed === 1 ? '' : 's'} removed` : 'Nothing matched', 'success', 3000); diff --git a/web/src/admin/luci.d.ts b/web/src/admin/luci.d.ts index 9a3872e..8287cdd 100644 --- a/web/src/admin/luci.d.ts +++ b/web/src/admin/luci.d.ts @@ -48,6 +48,8 @@ interface WidgetOptions { } interface LuciUI { + /** The menu is cached for the session; flush it after Dawnline's pages change. */ + menu?: { flushCache(): void }; showModal(title: string | null, children: Child, ...classes: string[]): HTMLElement; hideModal(): void; addNotification(title: string | null, children: Child, ...classes: string[]): HTMLElement; diff --git a/web/src/admin/main.ts b/web/src/admin/main.ts index a4def25..8ee9172 100644 --- a/web/src/admin/main.ts +++ b/web/src/admin/main.ts @@ -4,9 +4,9 @@ import { PeoplePage } from './pages/people'; import { ServerPage } from './pages/server'; import { SettingsPage } from './pages/settings'; -import { HealthPage, UpdatesPage } from './pages/maintenance'; +import { UpdatesPage } from './pages/maintenance'; import { PersonPage } from './pages/person'; -import { ActivityPage } from './pages/activity'; +import { DiagnosticsPage } from './pages/diagnostics'; import { styleNode } from './styles'; interface Page { @@ -44,8 +44,24 @@ const people = factory(PeoplePage, true); const server = factory(ServerPage, false); const settings = factory(SettingsPage, false); const person = factory(PersonPage, false); -const activity = factory(ActivityPage, false); -const health = factory(HealthPage, false); +const diagnostics = factory(DiagnosticsPage, false); const updates = factory(UpdatesPage, false); -export { overview, people, person, activity, server, settings, health, updates }; +/** Health and Activity became Diagnostics tabs: old addresses and bookmarks go there. */ +function moved(tab: '' | 'log') { + return () => ({ + load: () => { + ui.menu?.flushCache(); + location.replace(`${L.url('admin/network/dawnline/diagnostics')}${tab ? `?tab=${tab}` : ''}`); + return new Promise(() => {}); + }, + render: () => document.createElement('div'), + handleSave: null, + handleSaveApply: null, + handleReset: null, + }); +} +const health = moved(''); +const activity = moved('log'); + +export { overview, people, person, activity, server, settings, health, diagnostics, updates }; diff --git a/web/src/admin/pages/activity.ts b/web/src/admin/pages/activity.ts index 78c9444..bb74748 100644 --- a/web/src/admin/pages/activity.ts +++ b/web/src/admin/pages/activity.ts @@ -1,22 +1,29 @@ -// Activity: the full event log, grouped by day, with filters, search, -// export and clearing. +// Diagnostics → Log: people's activity and the service log (tunnel and +// service starts, stops, watchdog repairs, errors) in one list, grouped by +// day, with filters, export and clearing. import type { LogEvent, Status } from '../../shared/types'; import { E } from '../e'; -import { api, type LogCategory, type LogsInfo } from '../api'; +import { api, type LogCategory, type LogsInfo, type ServiceLogEntry } from '../api'; import { button, dropdown } from '../ui'; import { icon } from '../../shared/icons'; -import { installPalette } from '../palette'; -import { CATEGORIES, CATEGORY_LABEL, categoryOf, clearLogDialog, exportEvents } from '../logs'; -import { eventRow, eventText } from './overview'; +import { CATEGORIES, CATEGORY_LABEL, SYSTEM_SOURCE, categoryOf, clearLogDialog, exportEvents } from '../logs'; +import { eventRow } from './overview'; -type Kind = 'all' | LogCategory; -type Loaded = [Status, Awaited>]; +export type LogKind = 'all' | LogCategory | 'system'; +type Events = Awaited>; +/** One line of the list: an activity event or a service log entry. */ +export type LogItem = { ts: number; ev?: LogEvent; sys?: ServiceLogEntry }; /** Rows painted at a time; "Show more" adds another page. */ const PAGE = 300; +const KINDS: LogKind[] = ['all', 'connections', 'people', 'system', 'problems']; +/** Colour per service log level (tile, source and row): neutral unless something came up, was repaired or failed. */ +// "down" is a tunnel that stopped without Dawnline asking (its own stops are "info"). +const SYS_TONE: Record = { info: '', up: 'ok', down: 'warn', repair: 'warn', error: 'bad' }; +const SYS_ICON: Record = { awg: 'tunnel', dawnline: 'sunrise', portal: 'globe' }; -function dayTitle(ts: number): string { +export function dayTitle(ts: number): string { const d = new Date(ts * 1000); const today = new Date(); const y = new Date(); @@ -35,157 +42,214 @@ export function retentionText(p: LogsInfo['policy']): string { return `Kept for ${age}, up to ${p.max.toLocaleString('en-GB')} events, ${where}.`; } -export class ActivityPage { - st!: Status; +export const isProblem = (x: LogItem) => + x.sys ? ['error', 'repair', 'down'].includes(x.sys.level) : categoryOf(x.ev!.type) === 'problems'; + +/** A service log line: source, message, folded details; click to unfold. */ +export function systemRow(e: ServiceLogEntry, open: boolean, toggle: () => void, time: string): HTMLElement { + const admin = e.by === 'admin'; + const row = E( + 'div', + { + class: `dl-row dl-slog-row ${admin ? 'dl-ev-by-admin' : `dl-ev-by-system ${SYS_TONE[e.level] ?? ''}`}${e.detail ? ' has-detail' : ''}`, + }, + [ + admin + ? E('span', { class: 'dl-ev-tile', title: 'Done by you in LuCI' }, icon('admin')) + : E('span', { class: 'dl-ev-tile sys', title: e.level }, icon(SYS_ICON[e.src] ?? 'zap')), + E( + 'span', + { class: 'dl-row-main' }, + admin + ? [ + E('span', { class: 'dl-you' }, 'You'), + E('span', { class: 'dl-muted' }, ` ${e.msg} `), + e.kind ? E('span', { class: 'dl-ev-kind' }, `${e.kind} `) : '', + e.who ? E('b', {}, e.who) : '', + e.note ? E('span', { class: 'dl-muted' }, ` · ${e.note}`) : '', + e.detail ? E('span', { class: `dl-slog-more${open ? ' open' : ''}` }, icon('chevron')) : '', + e.detail && open ? E('pre', { class: 'dl-slog-detail' }, e.detail) : '', + ] + : [ + // Servers have names people chose: say it is a server. Services name themselves. + e.src === 'awg' && e.who && e.who !== 'AmneziaWG' ? E('span', { class: 'dl-ev-kind' }, 'Server ') : '', + E('b', { class: 'dl-sys-src', title: SYSTEM_SOURCE[e.src] ?? e.src }, e.who ?? SYSTEM_SOURCE[e.src] ?? e.src), + ' ', + E('span', { class: 'dl-muted' }, e.msg), + e.detail ? E('span', { class: `dl-slog-more${open ? ' open' : ''}` }, icon('chevron')) : '', + e.detail && open ? E('pre', { class: 'dl-slog-detail' }, e.detail) : '', + ], + ), + E('span', { class: 'dl-faint dl-nowrap', title: new Date(e.ts * 1000).toLocaleString() }, time), + ], + ); + if (e.detail) + row.addEventListener('click', (ev) => { + if (!(ev.target as HTMLElement).closest('pre')) toggle(); + }); + return row; +} + +export class LogTab { + st: Status; events: LogEvent[] = []; + system: ServiceLogEntry[] = []; policy!: LogsInfo['policy']; - kind: Kind = 'all'; - query = ''; + kind: LogKind = 'all'; shown = PAGE; + open = new Set(); list = E('div', {}); - sub = E('span', { class: 'dl-muted' }); + /** Retention, for the page subtitle. */ + sub = ''; tabs = E('div', { class: 'dl-seg', role: 'tablist' }); + el: HTMLElement; - async load(): Promise { - return Promise.all([api.status(1), api.events(20000)]); - } - - render([st, ev]: Loaded): HTMLElement { + constructor(st: Status, ev: Events, system: ServiceLogEntry[]) { this.st = st; this.take(ev); - installPalette(st); - const search = E('input', { - type: 'search', - class: 'dl-search-input', - placeholder: 'Search people, devices, IPs', - input: (e: Event) => { - this.query = (e.target as HTMLInputElement).value.trim().toLowerCase(); - this.shown = PAGE; - this.paint(); - }, - }); + this.system = system; + this.el = E('div', {}, [E('div', { class: 'dl-toolbar' }, [this.tabs]), this.list]); + this.paint(); + } + + /** Export and Clear, for the page head. */ + actions(): HTMLElement[] { + const suffix = () => (this.kind === 'all' ? '' : this.kind); + const run = (format: 'csv' | 'json') => () => { + const items = this.filtered().reverse(); + exportEvents( + this.st, + items.filter((x) => x.ev).map((x) => x.ev!), + format, + suffix(), + items.filter((x) => x.sys).map((x) => x.sys!), + ); + }; const exp = button([icon('download'), ' Export'], () => dropdown(exp, [ - { - label: 'CSV (spreadsheet)', - icon: icon('download'), - run: () => exportEvents(this.st, this.filtered().reverse(), 'csv', this.kind === 'all' ? '' : this.kind), - }, - { - label: 'JSON', - icon: icon('download'), - run: () => exportEvents(this.st, this.filtered().reverse(), 'json', this.kind === 'all' ? '' : this.kind), - }, + { label: 'CSV (spreadsheet)', icon: icon('download'), run: run('csv') }, + { label: 'JSON', icon: icon('download'), run: run('json') }, ]), ); const clear = button([icon('trash'), ' Clear'], () => clearLogDialog( - 'Clear activity', + 'Clear the log', 'Removes events from the log on the router.', {}, () => this.reload(), this.kind === 'all' ? undefined : this.kind, + true, ), ); - this.paint(); - poll.add(async () => { - const r = await api.events(20000).catch(() => null); - if (r) { - this.take(r); - this.paint(); - } - }, 15); - return E('div', {}, [ - E('div', { class: 'dl-pagehead' }, [ - E('div', { class: 'dl-stack' }, [E('h2', { class: 'dl-h1' }, 'Activity'), this.sub]), - E('div', { class: 'dl-row-actions' }, [exp, clear]), - ]), - E('div', { class: 'dl-toolbar' }, [ - this.tabs, - E('span', { class: 'dl-spacer' }), - E('label', { class: 'dl-search' }, [icon('search'), search]), - ]), - this.list, - ]); + return [exp, clear]; } - take(r: Awaited>) { + take(r: Events) { this.events = r.events; this.policy = r.policy; const off = CATEGORIES.filter((c) => !r.policy.categories.includes(c)); - this.sub.textContent = `${retentionText(r.policy)}${off.length ? ` Not recorded: ${off.map((c) => CATEGORY_LABEL[c].toLowerCase()).join(', ')}.` : ''}`; + this.sub = `${retentionText(r.policy)}${off.length ? ` Not recorded: ${off.map((c) => CATEGORY_LABEL[c].toLowerCase()).join(', ')}.` : ''}`; } async reload() { - const r = await api.events(20000).catch(() => null); - if (r) { - this.take(r); - this.paint(); - } + const [r, sl] = await Promise.all([api.events(20000).catch(() => null), api.serviceLog().catch(() => null)]); + if (r) this.take(r); + if (sl) this.system = sl.log; + this.paint(); } - /** Newest first, matching the current tab and search. */ - filtered(): LogEvent[] { - return [...this.events].reverse().filter((e) => { - if (this.kind !== 'all' && categoryOf(e.type) !== this.kind) return false; - if (!this.query) return true; - const text = eventText(this.st, e) - .map((n) => n.textContent ?? '') - .join(' '); - return `${text} ${e.detail ?? ''} ${e.where ?? ''}`.toLowerCase().includes(this.query); - }); + items(): LogItem[] { + return [...this.events.map((ev) => ({ ts: ev.ts, ev })), ...this.system.map((sys) => ({ ts: sys.ts, sys }))].sort( + (a, b) => b.ts - a.ts, + ); } - paintTabs() { - const count = (k: Kind) => (k === 'all' ? this.events.length : this.events.filter((e) => categoryOf(e.type) === k).length); + matches(x: LogItem, k: LogKind) { + if (k === 'all') return true; + if (k === 'problems') return isProblem(x); + if (k === 'system') return !!x.sys; + return !!x.ev && categoryOf(x.ev.type) === k; + } + + /** Newest first, matching the current tab. */ + filtered(): LogItem[] { + return this.items().filter((x) => this.matches(x, this.kind)); + } + + paintTabs(all: LogItem[]) { dom.content( this.tabs, - (['all', ...CATEGORIES] as Kind[]).map((k) => + KINDS.map((k) => E( 'button', { type: 'button', role: 'tab', class: k === this.kind ? 'on' : '', - click: () => { - this.kind = k; - this.shown = PAGE; - this.paint(); - }, + 'aria-selected': k === this.kind ? 'true' : 'false', + click: () => this.show(k), }, - [k === 'all' ? 'All' : CATEGORY_LABEL[k], E('b', {}, String(count(k)))], + [ + k === 'all' ? 'All' : k === 'system' ? 'System' : CATEGORY_LABEL[k], + E('b', {}, String(all.filter((x) => this.matches(x, k)).length)), + ], ), ), ); } + show(k: LogKind) { + this.kind = k; + this.shown = PAGE; + this.paint(); + } + paint() { - this.paintTabs(); - const evs = this.filtered(); - if (!evs.length) { - dom.content(this.list, E('div', { class: 'dl-empty' }, [E('p', {}, this.events.length ? 'No events match.' : 'The log is empty.')])); + this.paintTabs(this.items()); + const items = this.filtered(); + if (!items.length) { + dom.content( + this.list, + E('div', { class: 'dl-empty' }, [E('p', {}, this.events.length || this.system.length ? 'No events match.' : 'The log is empty.')]), + ); return; } const groups: HTMLElement[] = []; let day = ''; let panel: HTMLElement | null = null; - for (const e of evs.slice(0, this.shown)) { - const t = dayTitle(e.ts); + for (const x of items.slice(0, this.shown)) { + const t = dayTitle(x.ts); if (t !== day) { day = t; panel = E('div', { class: 'dl-panel flush' }, E('div', { class: 'dl-panel-head pad' }, E('h3', {}, t))); groups.push(panel); } - const row = eventRow(this.st, e); - row.lastElementChild!.textContent = new Date(e.ts * 1000).toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit' }); - panel!.appendChild(row); + const time = new Date(x.ts * 1000).toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit' }); + if (x.sys) { + const key = `${x.sys.ts}|${x.sys.msg}`; + panel!.appendChild( + systemRow( + x.sys, + this.open.has(key), + () => { + if (!this.open.delete(key)) this.open.add(key); + this.paint(); + }, + time, + ), + ); + } else { + const row = eventRow(this.st, x.ev!); + row.lastElementChild!.textContent = time; + panel!.appendChild(row); + } } - if (evs.length > this.shown) + if (items.length > this.shown) groups.push( E( 'div', { class: 'dl-more-row' }, - button(`Show ${Math.min(PAGE, evs.length - this.shown)} more of ${evs.length - this.shown}`, () => { + button(`Show ${Math.min(PAGE, items.length - this.shown)} more of ${items.length - this.shown}`, () => { this.shown += PAGE; this.paint(); }), diff --git a/web/src/admin/pages/diagnostics.ts b/web/src/admin/pages/diagnostics.ts new file mode 100644 index 0000000..f7f6b7d --- /dev/null +++ b/web/src/admin/pages/diagnostics.ts @@ -0,0 +1,94 @@ +// Diagnostics: Health (watchdog, checks, recent problems) and Log (activity +// and the service log in one list) as two tabs. ?tab=log opens the Log; the +// old Health and Activity addresses come here. + +import type { Status } from '../../shared/types'; +import { E } from '../e'; +import { api, type Health, type ServiceLog } from '../api'; +import { HealthTab } from './maintenance'; +import { LogTab } from './activity'; + +type Tab = 'health' | 'log'; +type Loaded = [Status, Awaited>, ServiceLog, Health | null]; + +const TABS: [Tab, string][] = [ + ['health', 'Health'], + ['log', 'Log'], +]; + +export class DiagnosticsPage { + tab: Tab = new URLSearchParams(location.search).get('tab') === 'log' ? 'log' : 'health'; + health!: HealthTab; + log!: LogTab; + segEl = E('div', { class: 'dl-seg dl-srvsections dl-diag-tabs', role: 'tablist', 'aria-label': 'Diagnostics' }); + subEl = E('span', { class: 'dl-muted' }); + actionsEl = E('div', { class: 'dl-row-actions' }); + bodyEl = E('div', {}); + + load(): Promise { + // The checks take a moment: only wait for them when Health opens first. + return Promise.all([ + api.status(1), + api.events(20000), + api.serviceLog(), + this.tab === 'health' ? api.health().catch(() => null) : Promise.resolve(null), + ]); + } + + render([st, ev, sl, h]: Loaded): HTMLElement { + this.log = new LogTab(st, ev, sl.log); + this.health = new HealthTab(st, sl, ev.events, () => { + this.show('log'); + this.log.show('problems'); + }); + if (h) this.health.take(h); + this.show(this.tab); + poll.add(async () => { + if (!this.bodyEl.isConnected) return; + const [n, e] = await Promise.all([api.serviceLog().catch(() => null), api.events(20000).catch(() => null)]); + if (e) this.log.take(e); + if (n) this.log.system = n.log; + if (n) this.health.paintLive(n, e?.events ?? this.health.events); + if (this.tab === 'log' && (n || e)) this.log.paint(); + }, 10); + return E('div', {}, [ + E('div', { class: 'dl-pagehead' }, [ + E('div', { class: 'dl-stack' }, [E('h2', { class: 'dl-h1' }, 'Diagnostics'), this.subEl]), + this.actionsEl, + ]), + this.segEl, + this.bodyEl, + ]); + } + + show(tab: Tab) { + this.tab = tab; + const url = new URL(location.href); + if (tab === 'log') url.searchParams.set('tab', 'log'); + else url.searchParams.delete('tab'); + history.replaceState(null, '', url); + dom.content( + this.segEl, + TABS.map(([k, t]) => + E( + 'button', + { + type: 'button', + role: 'tab', + class: k === tab ? 'on' : '', + 'aria-selected': k === tab ? 'true' : 'false', + click: () => k !== this.tab && this.show(k), + }, + t, + ), + ), + ); + // Both tabs stay alive; only the visible one is in the page. + this.bodyEl.replaceChildren(tab === 'log' ? this.log.el : this.health.el); + this.subEl.textContent = + tab === 'log' ? this.log.sub : 'Everything Dawnline depends on, checked live. The watchdog repairs what it can on its own.'; + dom.content(this.actionsEl, tab === 'log' ? this.log.actions() : ''); + if (tab === 'log') this.log.paint(); + else if (!this.health.checks) void this.health.run(); + } +} diff --git a/web/src/admin/pages/maintenance.ts b/web/src/admin/pages/maintenance.ts index 95c8525..b71c4f4 100644 --- a/web/src/admin/pages/maintenance.ts +++ b/web/src/admin/pages/maintenance.ts @@ -1,93 +1,218 @@ -// Health and Updates pages. +// Diagnostics → Health, and the Updates page. -import type { HealthCheck } from '../../shared/types'; +import type { HealthCheck, LogEvent, Status } from '../../shared/types'; +import { eventRow } from './overview'; +import { isProblem, systemRow, type LogItem } from './activity'; import { E } from '../e'; -import { api, type AwgSource, type Needs, type UpdatesStatus } from '../api'; +import { api, type AwgSource, type Health, type Needs, type ServiceLog, type UpdatesStatus } from '../api'; import { installFeature } from '../pkgs'; import { attempt, button, callout, confirmDialog } from '../ui'; import { icon } from '../../shared/icons'; -import { clock } from '../../shared/format'; +import { ago, clock } from '../../shared/format'; +import { sw } from '../kit'; const ICON: Record = { ok: 'check', warn: 'alert', error: 'x', skip: 'pause' }; const FIX_LABEL: Record = { apply: 'Repair', sync: 'Reload devices', restart: 'Restart service', updates: 'Open updates' }; -export class HealthPage { - root!: HTMLElement; +/** Diagnostics → Health: the watchdog, the checks and the latest problems from the log. */ +export class HealthTab { + st: Status; + el = E('div', {}); + wdEl = E('div', {}); + checksEl = E('div', { class: 'dl-panel' }); + recentEl = E('div', { class: 'dl-panel flush dl-recent' }); + sl: ServiceLog; + events: LogEvent[]; + checks: HealthCheck[] | null = null; + /** Shows the Log tab on its Problems filter. */ + toLog: () => void; + summary = E('div', {}); - load() { - return api.health(); + constructor(st: Status, sl: ServiceLog, events: LogEvent[], toLog: () => void) { + this.st = st; + this.sl = sl; + this.events = events; + this.toLog = toLog; + dom.content(this.el, [this.summary, this.wdEl, E('div', { class: 'dl-health-cols' }, [this.checksEl, this.recentEl])]); + this.paintChecks(); + this.paintLive(sl, events); } - render(r: { checks: HealthCheck[] }) { - this.root = E('div', { class: 'dl-root' }); - this.paint(r.checks); - return E('div', {}, [ - E('h2', {}, 'Health'), - E( - 'div', - { class: 'cbi-map-descr' }, - 'Everything Dawnline depends on, checked live. Problems come with a fix button where one exists.', - ), - this.root, - ]); + /** Run the checks (they take a moment: DNS, ports, certificates). */ + async run(fix?: string) { + const r = fix ? await attempt(() => api.healthFix(fix), 'Done') : await api.health().catch(() => null); + if (!r) return; + this.take(r); } - paint(checks: HealthCheck[]) { + take(r: Health) { + this.checks = r.checks; + this.paintChecks(); + this.paintLive(r, this.events); + } + + paintChecks() { + const checks = this.checks; + if (!checks) { + dom.content(this.summary, ''); + dom.content(this.checksEl, [ + E('div', { class: 'dl-panel-head' }, [E('h3', {}, 'Checks')]), + E('p', { class: 'dl-muted dl-loading' }, 'Running checks…'), + ]); + return; + } const bad = checks.filter((c) => c.status === 'error').length; const warn = checks.filter((c) => c.status === 'warn').length; - dom.content(this.root, [ + dom.content( + this.summary, bad ? callout('error', `${bad} problem${bad > 1 ? 's' : ''} need attention.`) : warn ? callout('warn', `${warn} warning${warn > 1 ? 's' : ''}.`) : callout('ok', 'All checks passed.'), - E('div', { class: 'dl-panel' }, [ - E('div', { class: 'dl-panel-head' }, [ - E('h3', {}, 'Checks'), - E('span', { class: 'dl-spacer' }), - button('Run again', async () => { - const r = await attempt(() => api.health()); - if (r) this.paint(r.checks); - }), - ]), - E( - 'ul', - { class: 'dl-checks' }, - checks.map((c) => - E('li', {}, [ - E('span', { class: `dl-check-icon ${c.status}` }, icon(ICON[c.status])), - E('div', { class: 'dl-check-body' }, [ - E('div', { class: 'dl-check-title' }, c.title), - E('div', { class: 'dl-check-detail' }, c.detail), - ]), - c.fix - ? c.fix.startsWith('install:') - ? button( - 'Install', - () => - installFeature(c.fix!.slice(8) as keyof Needs, async () => { - const r = await api.health().catch(() => null); - if (r) this.paint(r.checks); - }), - 'action', - ) - : c.fix === 'updates' - ? E('a', { class: 'cbi-button cbi-button-action', href: L.url('admin/network/dawnline/updates') }, FIX_LABEL.updates) - : button( - FIX_LABEL[c.fix] ?? 'Fix', - async () => { - const r = await attempt(() => api.healthFix(c.fix!), 'Done'); - if (r) this.paint(r.checks); - }, - 'action', - ) + ); + const repaired = new Map(); + for (const x of this.sl.watchdog.repairs) repaired.set(x.id, Math.max(repaired.get(x.id) ?? 0, x.ts)); + const refresh = () => this.run(); + dom.content(this.checksEl, [ + E('div', { class: 'dl-panel-head' }, [E('h3', {}, 'Checks'), E('span', { class: 'dl-spacer' }), button('Run again', refresh)]), + E( + 'ul', + { class: 'dl-checks' }, + checks.map((c) => + E('li', {}, [ + E('span', { class: `dl-check-icon ${c.status}` }, icon(ICON[c.status])), + E('div', { class: 'dl-check-body' }, [ + E('div', { class: 'dl-check-title' }, c.title), + E('div', { class: 'dl-check-detail' }, c.detail), + repaired.has(c.id) + ? E('div', { class: 'dl-check-repaired' }, `Repaired by the watchdog at ${clock(repaired.get(c.id)!)}`) : '', ]), - ), + c.fix + ? c.fix.startsWith('install:') + ? button('Install', () => installFeature(c.fix!.slice(8) as keyof Needs, refresh), 'action') + : c.fix === 'updates' + ? E('a', { class: 'cbi-button cbi-button-action', href: L.url('admin/network/dawnline/updates') }, FIX_LABEL.updates) + : button(FIX_LABEL[c.fix] ?? 'Fix', () => this.run(c.fix!), 'action') + : '', + ]), ), - ]), + ), ]); } + + /** The watchdog card and recent problems; refreshed by the page poll without running the checks again. */ + paintLive(sl: ServiceLog, events: LogEvent[]) { + this.sl = sl; + this.events = events; + const wd = sl.watchdog; + const stale = wd.beat != null && wd.now - wd.beat > 180; + const today = wd.repairs.filter((x) => wd.now - x.ts < 86400); + const lastRep = today[today.length - 1]; + const toggle = sw(wd.enabled, 'Watchdog repairs', async (v) => { + const ok = await attempt(() => api.settingsUpdate({ watchdog: v ? '1' : '0' }), v ? 'Watchdog on' : 'Watchdog off'); + if (!ok) toggle.classList.toggle('on', !v); + const n = await api.serviceLog().catch(() => null); + if (n) this.paintLive(n, this.events); + }); + dom.content( + this.wdEl, + E('div', { class: 'dl-panel dl-wd' }, [ + E('div', { class: 'dl-wd-head' }, [ + E('span', { class: `dl-wd-tile${wd.enabled ? '' : ' off'}` }, icon('shield')), + E('div', { class: 'dl-stack' }, [ + E('span', { class: 'dl-wd-title' }, 'Watchdog'), + E( + 'span', + { class: 'dl-sub' }, + wd.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.', + ), + ]), + E('span', { class: 'dl-spacer' }), + toggle, + ]), + E('div', { class: 'dl-wd-foot' }, [ + E( + 'div', + { class: 'dl-wd-chips' }, + wd.targets.map((t) => + E( + 'span', + { + class: `dl-check-chip${t.ok ? '' : ' error'}`, + title: t.ok ? 'OK' : `Not working${t.tries ? ` · ${t.tries} repair${t.tries > 1 ? 's' : ''}` : ''}`, + }, + [icon(t.ok ? 'check' : 'x'), t.name], + ), + ), + ), + E( + 'span', + { class: `dl-sub${stale ? ' dl-warn-text' : ''}` }, + stale + ? `The agent has not checked in for ${Math.round((wd.now - wd.beat!) / 60)} min; cron restarts it after 5.` + : [ + wd.last ? `Looked ${ago(wd.last, wd.now)}` : 'Starts within a minute', + ' · ', + today.length + ? `${today.length} repair${today.length > 1 ? 's' : ''} today, last ${lastRep.name} at ${clock(lastRep.ts)}` + : 'no repairs today', + ], + ), + ]), + ]), + ); + this.paintRecent(); + } + + /** Problems from the last 7 days, both kinds, newest first. */ + paintRecent() { + const since = Date.now() / 1000 - 7 * 86400; + const items: LogItem[] = [...this.events.map((ev) => ({ ts: ev.ts, ev })), ...this.sl.log.map((sys) => ({ ts: sys.ts, sys }))] + .filter((x) => x.ts >= since && isProblem(x)) + .sort((a, b) => b.ts - a.ts); + const head = E('div', { class: 'dl-panel-head pad' }, [ + E('h3', {}, 'Recent problems'), + E('span', { class: 'dl-spacer' }), + items.length ? E('a', { href: '#', click: (e: Event) => (e.preventDefault(), this.toLog()) }, 'All in Log →') : '', + ]); + if (!items.length) { + dom.content(this.recentEl, [ + head, + E('div', { class: 'dl-recent-empty' }, [ + E('span', { class: 'dl-check-icon ok' }, icon('check')), + 'No problems in the last 7 days.', + ]), + ]); + return; + } + dom.content(this.recentEl, [ + head, + ...items.slice(0, 8).map((x) => { + if (x.sys) { + const e = x.sys; + const key = `${e.ts}|${e.msg}`; + return systemRow( + e, + this.open.has(key), + () => { + if (!this.open.delete(key)) this.open.add(key); + this.paintRecent(); + }, + clock(e.ts), + ); + } + const row = eventRow(this.st, x.ev!); + row.lastElementChild!.textContent = clock(x.ts); + return row; + }), + ]); + } + + open = new Set(); } /** What Dawnline adds to OpenWrt; the portal's HTTPS and certificates only matter while it is on. */ @@ -115,7 +240,10 @@ export class UpdatesPage { this.running = false; this.paint(n); // A new Dawnline is installed: load its pages instead of running the old bundle. - if (n.job?.component === 'app' && n.job.state === 'done') setTimeout(() => location.reload(), 1500); + if (n.job?.component === 'app' && n.job.state === 'done') { + ui.menu?.flushCache(); + setTimeout(() => location.reload(), 1500); + } } }, 3); return this.root; diff --git a/web/src/admin/pages/overview.ts b/web/src/admin/pages/overview.ts index de13e4c..dffb094 100644 --- a/web/src/admin/pages/overview.ts +++ b/web/src/admin/pages/overview.ts @@ -11,13 +11,13 @@ import { ago, bits, bytes, daysLeft, initials } from '../../shared/format'; import { ConnectionMap, rangeControl, type Range } from '../map'; import { attachTip } from '../charts'; import { methodInfo } from '../disguise'; -import { personUrl } from '../palette'; +import { personUrl } from '../urls'; const EVENT_TONE: Record = { connect: 'ok', disconnect: '', roam: '', - device_added: 'accent', + device_added: 'ok', device_removed: '', person_added: '', person_removed: '', @@ -25,63 +25,177 @@ const EVENT_TONE: Record = { resumed: 'ok', paused_all: 'warn', resumed_all: 'ok', - server_down: 'bad', - server_up: 'ok', portal_blocked: 'bad', person_changed: '', devices_removed: 'warn', }; +/** The icon in an event's tile: the device's kind for device events, else what happened. */ +const EVENT_ICON: Record = { + devices_removed: 'trash', + link_changed: 'link', + person_added: 'plus', + person_removed: 'trash', + person_changed: 'edit', + paused: 'pause', + resumed: 'play', + paused_all: 'pause', + resumed_all: 'play', +}; + +function eventIcon(st: Status, e: LogEvent): string { + if (e.device) { + const d = st.people.flatMap((p) => p.devices).find((x) => x.id === e.device); + return d?.kind ?? e.dkind ?? 'other'; + } + return EVENT_ICON[e.type] ?? 'activity'; +} + +const ADMIN_TYPES = ['person_added', 'person_removed', 'person_changed', 'paused_all', 'resumed_all']; + +/** Who did it. Older events have no `by`: LuCI and the portal marked it in the detail. */ +export function eventBy(e: LogEvent): 'admin' | 'portal' | null { + if (e.by) return e.by; + if (ADMIN_TYPES.includes(e.type) || e.detail === 'by admin' || e.detail?.endsWith(' (admin)')) return 'admin'; + if (e.detail?.endsWith(' (portal)')) return 'portal'; + return null; +} + +/** The detail without the old "(admin)" / "(portal)" / "by admin" marks. */ +function plainDetail(e: LogEvent): string { + return (e.detail ?? '').replace(/ \((admin|portal)\)$/, '').replace(/^by admin$/, ''); +} + export function eventText(st: Status, e: LogEvent): Node[] { const person = st.people.find((p) => p.id === e.person); - const who = person?.name ?? e.person ?? ''; - const dev = person?.devices.find((d) => d.id === e.device)?.name ?? ''; + const who = person?.name ?? e.pname ?? e.person ?? ''; + const dev = person?.devices.find((d) => d.id === e.device)?.name ?? e.dname ?? ''; const b = (t: string) => E('b', {}, t); const m = (t: string) => E('span', { class: 'dl-muted' }, t); const mono = (t: string) => E('span', { class: 'dl-mono' }, t); + // What the bold name is (a person, a device), said before it in grey. + const kind = (t: string) => E('span', { class: 'dl-ev-kind' }, `${t} `); const wd = dev ? `${who} · ${dev}` : who; + const detail = plainDetail(e); + const devName = detail || dev || 'a device'; + // The admin's own actions start with an accent "You". + const you = (verb: string) => [E('span', { class: 'dl-you' }, 'You'), m(` ${verb} `)]; + if (eventBy(e) === 'admin') + switch (e.type) { + case 'device_added': + return [...you('added'), kind('device'), b(devName), m(' for '), b(who)]; + case 'device_removed': + return [...you('removed'), kind('device'), b(devName), m(' from '), b(who)]; + case 'paused': + return [...you('paused'), kind('person'), b(who)]; + case 'resumed': + return [...you('resumed'), kind('person'), b(who)]; + case 'device_changed': { + const renamed = detail.startsWith('renamed from '); + return [ + ...you(renamed ? 'renamed' : detail), + kind('device'), + b(dev || 'a device'), + m(' of '), + b(who), + ...(renamed ? [m(` · was ${detail.slice(13)}`)] : []), + ]; + } + case 'device_keys': + return [...you('issued new keys for'), kind('device'), b(devName), m(' of '), b(who), m(' · it needs its new configuration')]; + case 'link_changed': + return [...you('issued a new link for'), kind('person'), b(who), m(' · the old link stopped working')]; + case 'paused_all': + return [E('span', { class: 'dl-you' }, 'You'), m(' paused everyone')]; + case 'resumed_all': + return [E('span', { class: 'dl-you' }, 'You'), m(' resumed everyone')]; + } switch (e.type) { case 'connect': - return [b(wd), m(' connected'), ...(e.detail ? [m(' from '), mono(e.detail)] : []), ...(e.where ? [m(` · ${e.where}`)] : [])]; + return [ + kind('Device'), + b(wd), + m(' connected'), + ...(e.detail ? [m(' from '), mono(e.detail)] : []), + ...(e.where ? [m(` · ${e.where}`)] : []), + ]; case 'disconnect': - return [b(wd), m(' went offline')]; + return [kind('Device'), b(wd), m(' went offline')]; case 'roam': - return [b(wd), m(' changed network '), mono(e.detail ?? '')]; + return [kind('Device'), b(wd), m(' changed network '), mono(e.detail ?? '')]; case 'device_added': - return [b(who), m(' added '), E('span', {}, e.detail ?? 'a device')]; + return [ + kind('Person'), + b(who), + m(' added '), + kind('device'), + b(devName), + ...(eventBy(e) === 'portal' ? [m(' on their portal')] : []), + ]; case 'device_removed': - return [b(who), m(' removed '), E('span', {}, e.detail ?? 'a device')]; + return [ + kind('Person'), + b(who), + m(' removed '), + kind('device'), + b(devName), + ...(eventBy(e) === 'portal' ? [m(' on their portal')] : []), + ]; + case 'device_keys': + return [kind('Person'), b(who), m(' issued new keys for '), kind('device'), b(devName), m(' on their portal')]; case 'person_added': - return [m('You added '), b(e.detail ?? who)]; + return [...you('added'), kind('person'), b(e.detail ?? who)]; case 'person_removed': - return [m('You removed '), b(e.detail ?? who)]; + return [...you('removed'), kind('person'), b(e.detail ?? who)]; case 'person_changed': - return [m('You changed '), b(who), m(` · ${e.detail ?? ''}`)]; + // The detail lists changed fields by their option names (device_limit, expire_action). + return [...you('changed'), kind('person'), b(who), ...(detail ? [m(` · ${detail.replace(/_/g, ' ')}`)] : [])]; case 'paused': - return [b(who), m(` paused — ${e.detail ?? ''}`)]; + return [kind('Person'), b(who), m(` paused — ${e.detail ?? ''}`)]; case 'resumed': - return [b(who), m(' resumed'), ...(e.detail && e.detail !== 'active' ? [m(` — ${e.detail}`)] : [])]; + return [kind('Person'), b(who), m(' resumed'), ...(e.detail && e.detail !== 'active' ? [m(` — ${e.detail}`)] : [])]; case 'paused_all': return [m('Everyone paused')]; case 'resumed_all': return [m('Everyone resumed')]; - case 'server_down': - return [m('Tunnel '), mono(e.detail ?? ''), m(' went down')]; - case 'server_up': - return [m('Tunnel '), mono(e.detail ?? ''), m(' is back up')]; case 'portal_blocked': - return [m('Portal blocked '), mono(e.detail ?? ''), m(' for 15 min after too many wrong codes')]; + return [ + E('b', { class: 'dl-sys-src' }, 'Personal portal'), + m(' blocked '), + mono(e.detail ?? ''), + m(' for 15 min after too many wrong codes'), + ]; case 'devices_removed': - return [b(who), m('’s devices were removed — end date reached')]; + return [kind('Person'), b(who), m(' — all devices removed, end date reached')]; default: return [m(`${e.type}${e.detail ? `: ${e.detail}` : ''}`)]; } } -export function eventRow(st: Status, e: LogEvent): HTMLElement { - return E('div', { class: 'dl-row' }, [ - E('span', { class: `dl-ev-dot ${EVENT_TONE[e.type] ?? ''}` }), +/** Events about the router rather than people look like service log lines: icon tile, colour by outcome. */ +const SYSTEM_EVENT: Record = { + portal_blocked: ['globe', 'bad'], +}; + +/** With several servers, which one a person's event happened on (left out where that is clear). */ +function serverPill(st: Status, e: LogEvent): HTMLElement | '' { + if (st.servers.length < 2 || !e.person) return ''; + const p = st.people.find((x) => x.id === e.person); + const srv = p && st.servers.find((s) => s.id === p.server); + return srv ? E('span', { class: 'dl-ev-srv', title: 'Server' }, srv.name) : ''; +} + +export function eventRow(st: Status, e: LogEvent, opts: { server?: boolean } = {}): HTMLElement { + const sys = SYSTEM_EVENT[e.type]; + const by = eventBy(e); + return E('div', { class: `dl-row${by === 'admin' ? ' dl-ev-by-admin' : sys ? ` dl-ev-by-system ${sys[1]}` : ''}` }, [ + by === 'admin' + ? E('span', { class: 'dl-ev-tile', title: 'Done by you in LuCI' }, icon('admin')) + : sys + ? E('span', { class: 'dl-ev-tile sys' }, icon(sys[0])) + : E('span', { class: `dl-ev-tile ev ${EVENT_TONE[e.type] ?? ''}` }, icon(eventIcon(st, e))), E('span', { class: 'dl-row-main' }, eventText(st, e)), + opts.server === false ? '' : serverPill(st, e), E('span', { class: 'dl-faint dl-nowrap', title: new Date(e.ts * 1000).toLocaleString() }, ago(e.ts, st.now)), ]); } @@ -92,7 +206,10 @@ function attention(st: Status): { tone: string; text: (Node | string)[] }[] { const link = (href: string, t: string) => E('a', { href }, t); for (const s of st.servers) if (s.enabled && !s.up) - out.push({ tone: 'bad', text: [`Tunnel ${s.ifname} is down. `, link(L.url('admin/network/dawnline/health'), 'Open Health')] }); + out.push({ + tone: 'bad', + text: [`Tunnel ${s.ifname} is down. `, link(L.url('admin/network/dawnline/diagnostics'), 'Open Diagnostics')], + }); if (st.settings.paused_all) out.push({ tone: 'warn', text: ['Everyone is paused.'] }); for (const p of st.people) { if (p.state === 'quota') out.push({ tone: 'warn', text: [link(personUrl(p.id), p.name), ' reached the data limit.'] }); @@ -120,7 +237,7 @@ function attention(st: Status): { tone: string; text: (Node | string)[] }[] { if (st.servers.some((s) => s.lan_like) && st.like_home.error) out.push({ tone: 'warn', - text: [`Internet through the LAN is off: ${st.like_home.error} `, link(L.url('admin/network/dawnline/health'), 'Details')], + text: [`Internet through the LAN is off: ${st.like_home.error} `, link(L.url('admin/network/dawnline/diagnostics'), 'Details')], }); if (!st.settings.portal_enabled) out.push({ tone: '', text: ['The personal portal is off. ', link(L.url('admin/network/dawnline/settings'), 'Turn on')] }); @@ -222,7 +339,11 @@ export class ServerOverview { return it; }), bad.length > 3 ? E('span', { class: 'dl-sub' }, `+${bad.length - 3} more`) : '', - E('a', { href: L.url('admin/network/dawnline/health') }, bad.some((c) => c.fix) ? 'Fix in Health →' : 'Open Health →'), + E( + 'a', + { href: L.url('admin/network/dawnline/diagnostics') }, + bad.some((c) => c.fix) ? 'Fix in Diagnostics →' : 'Open Diagnostics →', + ), ]), ); } @@ -288,7 +409,7 @@ export class ServerOverview { E('div', { class: 'dl-panel-head pad' }, [ E('h3', {}, 'Needs attention'), E('span', { class: 'dl-spacer' }), - E('a', { href: L.url('admin/network/dawnline/health') }, 'Health'), + E('a', { href: L.url('admin/network/dawnline/diagnostics') }, 'Health'), ]), att.length ? att @@ -305,7 +426,7 @@ export class ServerOverview { E('div', { class: 'dl-panel-head pad' }, [ E('h3', {}, 'Activity'), E('span', { class: 'dl-spacer' }), - E('a', { href: L.url('admin/network/dawnline/activity') }, 'View all'), + E('a', { href: `${L.url('admin/network/dawnline/diagnostics')}?tab=log` }, 'View all'), ]), events.length ? events.map((e) => eventRow(st, e)) diff --git a/web/src/admin/pages/people.ts b/web/src/admin/pages/people.ts index 62885bf..041a742 100644 --- a/web/src/admin/pages/people.ts +++ b/web/src/admin/pages/people.ts @@ -8,11 +8,11 @@ import { api } from '../api'; import { attempt, button, closeModal, confirmDialog, copyText, dropdown, iconButton, modal, notify, type MenuItem } from '../ui'; import { addDevice, openDevice } from '../device'; import { inviteCard } from '../invite'; -import { installPalette, personUrl } from '../palette'; +import { personUrl } from '../urls'; import { scoped } from './overview'; import { attachTip } from '../charts'; import { icon } from '../../shared/icons'; -import { ACCESS_LABEL, KIND_LABEL, STATE_LABEL, ago, bits, bytes, date, daysLeft, initials } from '../../shared/format'; +import { ACCESS_LABEL, KIND_LABEL, STATE_LABEL, ago, bits, byDeviceState, bytes, date, daysLeft, initials } from '../../shared/format'; type Sid = string; @@ -34,6 +34,23 @@ export function stateBadge(p: Person): HTMLElement | '' { return el; } +/** Device slots as a row of segments (one per allowed device, used ones lit) and "2 of 10". */ +function slotBar(p: Person): HTMLElement { + const used = p.devices.length; + // Devices added over the limit get their own (soft orange) segments after the allowed ones. + const n = Math.max(1, p.device_limit, used); + // 22px a segment until the bar is 160px long; past that the segments get thinner, so the count stays close. + const width = Math.min(160, n * 22 + (n - 1) * 3); + return E('div', { class: 'dl-slotbar', title: `${used} of ${p.device_limit} devices` }, [ + E( + 'span', + { class: 'dl-slotbar-segs', style: `width: ${width}px` }, + Array.from({ length: n }, (_, i) => E('i', { class: i >= p.device_limit ? 'over' : i < used ? 'used' : '' })), + ), + E('span', { class: 'dl-slotbar-text' }, `${used} of ${p.device_limit}`), + ]); +} + /** What the person can reach, as icons: home network, internet, or both. */ export function accessBadge(p: Person): HTMLElement { const kinds = p.access === 'both' ? ['lan', 'inet'] : p.access === 'lan' ? ['lan'] : ['inet']; @@ -117,7 +134,6 @@ let addOpened = false; export class PeoplePage { st!: Status; map: any; - query = ''; // `?filter=online` (from Overview) preselects a tab. filter: Filter = (['all', 'online', 'attention', 'paused'] as Filter[]).find((f) => f === new URLSearchParams(location.search).get('filter')) ?? 'all'; @@ -215,16 +231,6 @@ export class PeoplePage { return m.render().then((node: HTMLElement) => { node.classList.add('dl-map', 'dl-root'); - installPalette(st); - const search = E('input', { - type: 'search', - class: 'dl-search-input', - placeholder: 'Search people, devices, IPs', - input: (ev: Event) => { - page.query = (ev.target as HTMLInputElement).value.trim().toLowerCase(); - page.decorate(); - }, - }); const sort = E( 'select', { @@ -256,9 +262,8 @@ export class PeoplePage { ]), E('div', { class: 'dl-toolbar' }, [ E('div', { class: 'dl-seg', id: 'dl-people-tabs', role: 'tablist' }), - // Search, sort and add stay together on the right, wrapping as one group. + // Sort and add stay together on the right, wrapping as one group. E('div', { class: 'dl-toolbar-end' }, [ - E('label', { class: 'dl-search' }, [icon('search'), search, E('kbd', {}, '/')]), sort, page.serverId ? button([icon('plus'), ' Add person'], () => page.openCreate(), 'add') : '', ]), @@ -286,7 +291,7 @@ export class PeoplePage { return `${t.people} ${t.people === 1 ? 'person' : 'people'} · ${t.devices} device${t.devices === 1 ? '' : 's'} · ${t.online} online`; } - /** Row classes, counters, filter tabs, search and sort order. */ + /** Row classes, counters, filter tabs and sort order. */ decorate() { const c = document.getElementById('dl-people-count'); if (c) c.textContent = this.countText(); @@ -323,9 +328,7 @@ export class PeoplePage { if (this.filter === 'online' && !p.online) return false; if (this.filter === 'attention' && !needsAttention(p)) return false; if (this.filter === 'paused' && !(p.state !== 'active' && p.state !== 'quota' && p.state !== 'expired')) return false; - if (!this.query) return true; - const hay = [p.name, p.id, ...p.devices.flatMap((d) => [d.name, d.address, d.endpoint, d.hostname])].join(' ').toLowerCase(); - return hay.includes(this.query); + return true; }; const order = [...people].sort((a, b) => this.sort === 'name' @@ -349,12 +352,12 @@ export class PeoplePage { row.classList.toggle('dl-filtered', !hit); if (hit) shown++; } - // Say so when the filter or search leaves nobody. + // Say so when the filter leaves nobody. const table = tbody?.closest('.cbi-section-table') ?? tbody; let none = document.getElementById('dl-people-none'); if (table && people.length && !shown) { none ??= E('div', { id: 'dl-people-none', class: 'dl-empty' }); - dom.content(none, E('p', {}, this.query ? `No one matches “${this.query}”.` : 'No one here right now.')); + dom.content(none, E('p', {}, 'No one here right now.')); if (none.parentElement !== table.parentElement) table.after(none); } else none?.remove(); } @@ -395,7 +398,7 @@ export class PeoplePage { } if (p.hours) pills.push(E('span', { class: 'dl-pill-ic', title: 'Allowed hours' }, [icon('clock'), p.hours.replace('-', '–')])); - const chips = p.devices.map((d) => { + const chips = byDeviceState(p.devices).map((d) => { return E( 'button', { @@ -415,22 +418,24 @@ export class PeoplePage { ], ); }); - if (free > 0) - chips.push( - E( - 'button', - { - type: 'button', - class: 'dl-chip add', - title: `${p.devices.length} of ${p.device_limit} devices`, - click: (ev: Event) => { - ev.preventDefault(); - addDevice(p, () => this.refresh()); - }, + // Always there: over the limit the admin can still add one (the slot bar turns orange). + chips.push( + E( + 'button', + { + type: 'button', + // Just a "+": the slots above say how many there are. + class: 'dl-chip add', + 'aria-label': 'Add device', + title: free > 0 ? 'Add device' : 'Add device · over the limit, admins can still add', + click: (ev: Event) => { + ev.preventDefault(); + addDevice(p, () => this.refresh()); }, - [icon('plus'), E('span', { class: 'dl-chip-name' }, 'Add device')], - ), - ); + }, + icon('plus'), + ), + ); const fixes: Node[] = []; if (p.state === 'quota' && p.quota_period === 'month') @@ -498,17 +503,18 @@ export class PeoplePage { node, E('div', { class: 'dl-pcard' }, [ E('div', { class: 'dl-pcard-main' }, [ - E('div', { class: 'dl-card-head' }, [ + // The avatar is centred on the name and the slots; devices follow under the name. + E('div', { class: 'dl-pcard-top' }, [ E('span', { class: `dl-avatar${p.online ? ' online' : ''}` }, initials(p.name)), - E('a', { class: 'dl-card-name', href: personUrl(p.id) }, p.name), - stateBadge(p), - accessBadge(p), - ...pills, - ]), - E('div', { class: 'dl-meta' }, [ - E('span', {}, `${p.devices.length} of ${p.device_limit} devices`), - E('span', { class: 'dl-sep' }, '·'), - E('span', {}, p.online ? 'online now' : p.last_seen ? `seen ${ago(p.last_seen, this.st.now)}` : 'never connected'), + E('div', { class: 'dl-pcard-who' }, [ + E('div', { class: 'dl-card-head' }, [ + E('a', { class: 'dl-card-name', href: personUrl(p.id) }, p.name), + stateBadge(p), + accessBadge(p), + ...pills, + ]), + slotBar(p), + ]), ]), E('div', { class: 'dl-chips' }, chips), fixes.length ? E('div', { class: 'dl-fixes' }, fixes) : '', @@ -572,8 +578,8 @@ export class PeoplePage { return E('div', { class: 'dl-pside' }, [ E('div', { class: 'dl-pside-top' }, [ live - ? E('span', { class: 'dl-pside-state live' }, [E('i', { class: 'dl-dot online' }), 'Live']) - : E('span', { class: 'dl-pside-state' }, p.online ? 'Online' : p.last_seen ? 'Offline' : 'Not connected'), + ? E('span', { class: 'dl-pside-state live' }, 'Online') + : E('span', { class: 'dl-pside-state' }, p.online ? 'Online' : p.last_seen ? 'Offline' : 'Never connected'), actions, ]), E('div', { class: 'dl-use-num' }, [ diff --git a/web/src/admin/pages/person.ts b/web/src/admin/pages/person.ts index 780b0c6..e958c6a 100644 --- a/web/src/admin/pages/person.ts +++ b/web/src/admin/pages/person.ts @@ -23,10 +23,10 @@ import { addDevice, connectBlock, openDevice } from '../device'; import { inviteCard } from '../invite'; import { icon } from '../../shared/icons'; import { qrSvg } from '../../shared/qr'; -import { ACCESS_LABEL, KIND_LABEL, ago, bytes, date, daysLeft, initials } from '../../shared/format'; +import { ACCESS_LABEL, KIND_LABEL, ago, byDeviceState, bytes, date, daysLeft, initials } from '../../shared/format'; import { ConnectionMap, rangeControl } from '../map'; import { attachTip } from '../charts'; -import { installPalette, peopleUrl } from '../palette'; +import { peopleUrl } from '../urls'; import { daysTile, eventRow, eventText, speedTile } from './overview'; import { stateBadge } from './people'; @@ -48,9 +48,9 @@ export function shiftDate(cur: string, step: Step, n: number, customDays = 30): } const ACCESS_TEXT: Record = { - internet: 'Browse the internet through your router. No access to devices at home.', - lan: 'Reach devices at home. Internet stays on their own connection.', - both: 'Home devices and the internet, all through your router.', + 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.', }; export class PersonPage { @@ -82,7 +82,6 @@ export class PersonPage { render([st, events]: [Status, LogEvent[]]): HTMLElement { this.st = st; this.events = events; - installPalette(st); const p = st.people.find((x) => x.id === this.id); if (!p) return E('div', { class: 'dl-empty' }, [ @@ -275,10 +274,10 @@ export class PersonPage { const e = latest[i]; let n = 1; while (e.type === 'roam' && latest[i + n]?.type === 'roam' && latest[i + n].device === e.device) n++; - const row = eventRow(st, e); + const row = eventRow(st, e, { server: false }); if (n > 1) { const main = row.querySelector('.dl-row-main') as HTMLElement; - dom.content(main, [...eventText(st, e).slice(0, 2), E('span', { class: 'dl-muted' }, `${n} times`)]); + dom.content(main, [...eventText(st, e).slice(0, 3), E('span', { class: 'dl-muted' }, `${n} times`)]); main.title = latest .slice(i, i + n) .map((x) => x.detail ?? '') @@ -322,34 +321,14 @@ export class PersonPage { } deviceStatus(d: Device): HTMLElement { - if (d.disabled) return E('span', { class: 'dl-dstat' }, [E('i', { class: 'dot' }), 'Disabled']); - if (d.online) - return E('span', { class: 'dl-dstat ok' }, [ - E('i', { class: 'dot ok' }), - `Online · ${ago(d.handshake, this.st.now).replace(' ago', '')}`, - ]); - if (!d.handshake) - return E('span', { class: 'dl-dstat warn', title: 'Waiting for the first connection' }, [ - E('i', { class: 'dot warn' }), - 'Not set up yet', - ]); - return E('span', { class: 'dl-dstat' }, [E('i', { class: 'dot' }), `Last seen ${ago(d.handshake, this.st.now)}`]); + // Status as coloured text, no dots (only avatars carry one). + if (d.disabled) return E('span', { class: 'dl-dstat' }, 'Disabled'); + if (d.online) return E('span', { class: 'dl-dstat ok' }, 'Connected'); + if (!d.handshake) return E('span', { class: 'dl-dstat warn', title: 'Waiting for the first connection' }, 'Not set up yet'); + return E('span', { class: 'dl-dstat' }, `Last seen ${ago(d.handshake, this.st.now)}`); } /** While online: the client IP (copyable). Tunnel address and home name live in the device drawer. */ - addrs(d: Device): HTMLElement | '' { - if (!d.online || !d.endpoint) return ''; - const where = this.st.geo?.points.find((g) => g.device === d.id && g.ip === d.endpoint); - const tip = where?.city ? `Client IP · ${where.city}${where.org ? ` · ${where.org}` : ''}` : 'Client IP'; - const b = E( - 'button', - { type: 'button', class: 'dl-addr wan', 'aria-label': `Copy ${d.endpoint}`, click: () => copyText(d.endpoint, 'Client IP copied') }, - [icon('globe'), E('span', {}, d.endpoint)], - ); - attachTip(b, () => [E('div', { class: 'dl-tip-title' }, tip), E('div', { class: 'dl-muted' }, 'Click to copy')]); - return E('div', { class: 'dl-addrs' }, b); - } - /** Daily traffic of one device over the last 30 days, today on the right. */ deviceBars(id: string): HTMLElement { const days = (this.devSeries[id] ?? []).slice(-30); @@ -374,7 +353,7 @@ export class PersonPage { paintDevices() { const p = this.p; const refresh = () => this.refresh(); - const cards = p.devices.map((d) => { + const cards = byDeviceState(p.devices).map((d) => { const open = () => openDevice(p, d, refresh, this.st.geo); return E('article', { class: `dl-dcard${d.online ? ' online' : ''}${d.disabled ? ' off' : ''}` }, [ E('div', { class: 'dl-dcard-head' }, [ @@ -404,31 +383,23 @@ export class PersonPage { E('button', { type: 'button', class: 'dl-chipbtn', click: () => this.showDeviceQr(d) }, [icon('qr'), 'Show QR']), E('button', { type: 'button', class: 'dl-chipbtn', click: () => this.downloadConfig(d) }, [icon('download'), 'Config']), ]), - this.addrs(d), ]); }); - const free = Math.max(0, p.device_limit - p.devices.length); - if (free) - cards.push( - E('button', { type: 'button', class: 'dl-dslot add', click: () => addDevice(p, refresh) }, [ - E('span', { class: 'dl-dslot-ic' }, icon('plus')), + // Always the last card: admins may add over the person's limit, it says so. + const over = p.devices.length >= p.device_limit; + cards.push( + E('button', { type: 'button', class: 'dl-dslot add', click: () => addDevice(p, refresh) }, [ + E('span', { class: 'dl-dslot-ic' }, icon('plus')), + E('span', { class: 'dl-stack' }, [ E('b', {}, 'Add device'), + over ? E('span', { class: 'dl-sub' }, `Over the limit · ${p.devices.length} of ${p.device_limit}`) : '', ]), - ); + ]), + ); dom.content( this.parts.devices, E('section', { class: 'dl-devsec' }, [ - E('div', { class: 'dl-panel-head' }, [ - E('h3', {}, 'Devices'), - E('span', { class: 'dl-sub' }, `${p.online} online`), - E('span', { class: 'dl-spacer' }), - // Over the limit there is no Add card; the admin can still add one. - free - ? '' - : button([icon('plus'), ' Add device'], () => addDevice(p, refresh), 'neutral', { - title: 'Over the limit — admins can still add', - }), - ]), + E('div', { class: 'dl-panel-head' }, [E('h3', {}, 'Devices'), E('span', { class: 'dl-sub' }, `${p.online} online`)]), E('div', { class: 'dl-dgrid' }, cards), ]), ); @@ -677,16 +648,19 @@ export class PersonPage { dom.content( this.parts.limits, - E('section', { class: 'dl-panel', 'aria-label': 'Access and limits' }, [ + // Heading above the card, like "Devices", so both columns line up (as on the portal). + E('section', { class: 'dl-devsec', 'aria-label': 'Access and limits' }, [ E('div', { class: 'dl-panel-head' }, [E('h3', {}, 'Access & limits')]), - E('div', { class: 'dl-stack gap8' }, [ - E('span', { class: 'dl-tile2-label' }, 'Can reach'), - seg, - E('span', { class: 'dl-sub' }, ACCESS_TEXT[p.access]), - p.access === 'lan' && this.st.services.length ? this.servicesPicker() : '', - p.access === 'lan' ? this.dnsPicker() : '', + E('div', { class: 'dl-panel' }, [ + E('div', { class: 'dl-stack gap8' }, [ + E('span', { class: 'dl-tile2-label' }, 'Can reach'), + seg, + E('span', { class: 'dl-sub' }, ACCESS_TEXT[p.access]), + p.access === 'lan' && this.st.services.length ? this.servicesPicker() : '', + p.access === 'lan' ? this.dnsPicker() : '', + ]), + E('div', { class: 'dl-tiles2' }, [this.devTile(), endTile, dataTile, hoursTile]), ]), - E('div', { class: 'dl-tiles2' }, [this.devTile(), endTile, dataTile, hoursTile]), ]), ); } @@ -782,17 +756,19 @@ export class PersonPage { devTile(): HTMLElement { const p = this.p; const slots = E('div', { class: 'dl-slots' }); - for (let i = 0; i < p.device_limit; i++) { + // Devices added over the limit get their own soft orange slots after the allowed ones. + for (let i = 0; i < Math.max(p.device_limit, p.devices.length); i++) { const d = p.devices[i]; - const slot = E('i', { class: d ? 'used' : '' }); + const over = i >= p.device_limit; + const slot = E('i', { class: over ? 'over' : d ? 'used' : '' }); attachTip(slot, () => [ - E('div', { class: 'dl-tip-title' }, d ? d.name : 'Free slot'), + E('div', { class: 'dl-tip-title' }, d ? `${d.name}${over ? ' · over the limit' : ''}` : 'Free slot'), E( 'div', { class: 'dl-muted' }, d ? d.online - ? 'Online' + ? 'Connected' : d.handshake ? `Last seen ${ago(d.handshake, this.st.now)}` : 'Not set up yet' @@ -929,7 +905,7 @@ export class PersonPage { async showDeviceQr(d: Device) { const cfg = await attempt(() => api.deviceConfig(d.id)); if (!cfg) return; - modal(`Set up ${d.name}`, [await connectBlock(cfg)], [E('button', { class: 'cbi-button', click: closeModal }, 'Close')]); + modal(`Set up ${d.name}`, [await connectBlock(cfg, 'qr')], [E('button', { class: 'cbi-button', click: closeModal }, 'Close')]); } async downloadConfig(d: Device) { diff --git a/web/src/admin/pages/server.ts b/web/src/admin/pages/server.ts index 2f2e9af..9394cd0 100644 --- a/web/src/admin/pages/server.ts +++ b/web/src/admin/pages/server.ts @@ -14,7 +14,6 @@ import { card, group, input, row, sw } from '../kit'; import { methodInfo, methodPicker, type Method } from '../disguise'; import { ServerOverview } from './overview'; import { PeoplePage } from './people'; -import { installPalette, openPalette } from '../palette'; type Section = 'overview' | 'people' | 'connection' | 'access' | 'disguise' | 'tunnel'; const SECTIONS: [Section, string][] = [ @@ -176,7 +175,6 @@ export class ServerPage { const want = (OLD_SECTIONS[raw] ?? raw) as Section; if (SECTIONS.some(([k]) => k === want)) this.section = want; this.srvId = (st.servers.find((x) => x.id === q.get('server')) ?? st.servers[0]).id; - installPalette(st); dom.content(this.root, [this.tabsEl, this.headEl, this.secEl, this.bodyEl]); this.paint(); // Live numbers on the Overview; settings forms are left alone while open. @@ -336,13 +334,10 @@ export class ServerPage { const st = this.st; const seg = (ic: string, body: (Node | string)[]) => E('span', { class: 'dl-addrbar-seg' }, [icon(ic), ...body]); const addr = `${srv.endpoint || '—'}:${srv.port}`; - // Search, plus "Turn on" while the server is off (turning off lives in Tunnel; - // the same button also lifts an old router-wide pause). + // "Turn on" while the server is off (turning off lives in Tunnel; the same + // button also lifts an old router-wide pause). const off = !srv.enabled || st.settings.paused_all; const actions = E('div', { class: 'dl-actions' }, [ - button([icon('search'), ' Search ', E('kbd', {}, '⌘K')], () => openPalette(), 'neutral', { - class: 'cbi-button cbi-button-neutral dl-searchbtn', - }), off ? button( [icon('play'), ' Turn on'], @@ -359,10 +354,11 @@ export class ServerPage { return E('div', { class: 'dl-srvpagehead' }, [ E('div', { class: 'dl-title-row' }, [ E('h2', { class: 'dl-h1' }, srv.name), - E('span', { class: `dl-pill ${!srv.enabled ? 'off' : srv.up ? 'ok' : 'bad'}` }, [ - E('i', { class: 'dl-pill-dot' }), - !srv.enabled ? 'Disabled' : srv.up ? 'Ready' : 'Down', - ]), + E( + 'span', + { class: `dl-pill ${!srv.enabled ? 'off' : srv.up ? 'ok' : 'bad'}` }, + !srv.enabled ? 'Turned off' : srv.up ? 'Running' : 'Not running', + ), st.settings.paused_all && srv.enabled ? E('span', { class: 'dl-pill warn' }, 'Off') : '', E('span', { class: 'dl-spacer' }), actions, diff --git a/web/src/admin/pages/settings.ts b/web/src/admin/pages/settings.ts index fdfd39f..f0f5ef6 100644 --- a/web/src/admin/pages/settings.ts +++ b/web/src/admin/pages/settings.ts @@ -4,7 +4,6 @@ import { E } from '../e'; import { api, type Backup, type SettingsData } from '../api'; import { attempt, button, closeModal, confirmDialog, modal } from '../ui'; import { icon } from '../../shared/icons'; -import { installPalette } from '../palette'; import { group, input, isOn, row, sw } from '../kit'; import { CATEGORIES, CATEGORY_HELP, CATEGORY_LABEL, clearLogDialog, exportEvents, resetUsageDialog } from '../logs'; import { retentionText } from './activity'; @@ -60,7 +59,6 @@ export class SettingsPage { render(d: SettingsData): HTMLElement { this.d = d; - installPalette(); this.paint(); this.loadBackups().then(() => { if (new URLSearchParams(location.search).get('section') === 'backups') diff --git a/web/src/admin/palette.ts b/web/src/admin/palette.ts deleted file mode 100644 index ecdedd5..0000000 --- a/web/src/admin/palette.ts +++ /dev/null @@ -1,255 +0,0 @@ -// ⌘K / Ctrl+K command menu: jump to people and devices (also by IP or -// address) and run the common actions without leaving the keyboard. - -import type { Person, Status } from '../shared/types'; -import { E } from './e'; -import { api } from './api'; -import { attempt, copyText } from './ui'; -import { icon } from '../shared/icons'; -import { ACCESS_SHORT, initials } from '../shared/format'; - -interface Item { - group: string; - label: string; - hint?: string; - icon?: string; - avatar?: string; - kbd?: string; - run: () => unknown; -} - -let cache: { st: Status; at: number } | null = null; -let open = false; - -/** A server's People section (Servers page). */ -export function peopleUrl(server?: string): string { - return `${L.url('admin/network/dawnline/server')}?${server ? `server=${encodeURIComponent(server)}&` : ''}section=people`; -} - -export function personUrl(id: string, device?: string): string { - return `${L.url('admin/network/dawnline/person')}?id=${encodeURIComponent(id)}${device ? `&device=${encodeURIComponent(device)}` : ''}`; -} - -function go(path: string) { - location.href = L.url(`admin/network/dawnline/${path}`); -} - -function addMonths(iso: string, n: number): string { - const base = iso ? new Date(`${iso}T12:00:00`) : new Date(); - const from = base.getTime() < Date.now() ? new Date() : base; - from.setMonth(from.getMonth() + n); - return `${from.getFullYear()}-${String(from.getMonth() + 1).padStart(2, '0')}-${String(from.getDate()).padStart(2, '0')}`; -} - -function personActions(p: Person, done: () => void): Item[] { - const g = `Actions for ${p.name}`; - const items: Item[] = []; - if (p.link) - items.push({ group: g, label: 'Copy personal link', icon: 'link', kbd: 'C', run: () => copyText(p.link!, 'Personal link copied') }); - items.push({ group: g, label: `Add device for ${p.name}`, icon: 'plus', run: () => (location.href = `${personUrl(p.id)}&add=1`) }); - items.push({ - group: g, - label: p.paused ? `Resume ${p.name}` : `Pause ${p.name}`, - icon: p.paused ? 'play' : 'pause', - kbd: 'P', - run: async () => { - await attempt(() => api.personPause(p.id, !p.paused), p.paused ? `${p.name} resumed` : `${p.name} paused`); - done(); - }, - }); - items.push({ - group: g, - label: 'Extend access by 1 month', - icon: 'key', - run: async () => { - await attempt(() => api.personUpdate(p.id, { expires: addMonths(p.expires, 1) }), 'Access extended'); - done(); - }, - }); - return items; -} - -function build(st: Status, q: string, done: () => void): Item[] { - const query = q.trim().toLowerCase(); - const items: Item[] = []; - const people = st.people.filter((p) => !query || [p.name, p.id].some((x) => x.toLowerCase().includes(query))); - for (const p of people.slice(0, 6)) - items.push({ - group: 'People', - label: p.name, - hint: `${ACCESS_SHORT[p.access]} · ${p.online ? `${p.online} online` : `${p.devices.length} device${p.devices.length === 1 ? '' : 's'}`}`, - avatar: initials(p.name), - run: () => (location.href = personUrl(p.id)), - }); - for (const p of st.people) - for (const d of p.devices) { - const hay = [d.name, d.address, d.endpoint, d.hostname].join(' ').toLowerCase(); - if (query && !hay.includes(query)) continue; - if (!query && !d.online) continue; - items.push({ - group: 'Devices', - label: d.name, - hint: `${p.name} · ${d.address}${d.online ? ` · ${d.endpoint}` : ''}`, - icon: d.kind, - run: () => (location.href = personUrl(p.id, d.id)), - }); - } - if (people.length === 1 || (people.length && query)) items.push(...personActions(people[0], done)); - const pages: [string, string, string][] = [ - ['overview', 'Overview', 'globe'], - ['people', 'People', 'shield'], - ['activity', 'Activity', 'file'], - ['server', 'Server', 'key'], - ['health', 'Health', 'check'], - ['settings?section=backups', 'Backups', 'archive'], - ['settings', 'Settings', 'edit'], - ]; - for (const [path, label, ic] of pages) - if (!query || label.toLowerCase().includes(query)) items.push({ group: 'Go to', label, icon: ic, run: () => go(path) }); - if (!query || 'add person'.includes(query)) - items.push({ - group: 'Go to', - label: 'Add person', - icon: 'plus', - run: () => (location.href = `${L.url('admin/network/dawnline/server')}?section=people&add=1`), - }); - return items; -} - -export async function openPalette() { - if (open) return; - open = true; - const input = E('input', { - type: 'text', - class: 'dl-pal-input', - placeholder: 'Search people, devices, IPs or actions…', - 'aria-label': 'Search', - }) as HTMLInputElement; - const list = E('div', { class: 'dl-pal-list', role: 'listbox' }); - const box = E('div', { class: 'dl-pal', role: 'dialog', 'aria-label': 'Command menu' }, [ - E('label', { class: 'dl-pal-search' }, [icon('search'), input, E('kbd', {}, 'Esc')]), - list, - E('div', { class: 'dl-pal-foot' }, [ - E('span', {}, [E('kbd', {}, '↑↓'), ' navigate']), - E('span', {}, [E('kbd', {}, '↵'), ' open']), - E('span', {}, [E('kbd', {}, '⌘K'), ' toggle']), - ]), - ]); - const overlay = E('div', { class: 'dl-pal-overlay dl-root' }, box); - let items: Item[] = []; - let sel = 0; - const close = () => { - overlay.remove(); - document.removeEventListener('keydown', onKey, true); - open = false; - }; - const render = () => { - const st = cache?.st; - if (!st) { - list.replaceChildren(E('div', { class: 'dl-pal-empty' }, 'Loading…')); - return; - } - items = build(st, input.value, () => { - cache = null; - close(); - location.reload(); - }); - sel = Math.min(sel, Math.max(0, items.length - 1)); - const nodes: Node[] = []; - let group = ''; - items.forEach((it, i) => { - if (it.group !== group) { - group = it.group; - nodes.push(E('div', { class: 'dl-pal-group' }, group)); - } - const row = E( - 'div', - { - class: `dl-pal-item${i === sel ? ' sel' : ''}`, - role: 'option', - 'aria-selected': i === sel ? 'true' : 'false', - click: () => { - close(); - it.run(); - }, - mousemove: () => { - if (sel !== i) { - sel = i; - render(); - } - }, - }, - [ - it.avatar ? E('span', { class: 'dl-avatar sm' }, it.avatar) : it.icon ? icon(it.icon) : E('span', { class: 'dl-pal-ic' }), - E('span', { class: 'dl-pal-label' }, [it.label, it.hint ? E('span', { class: 'dl-faint' }, ` · ${it.hint}`) : '']), - it.kbd ? E('kbd', {}, it.kbd) : '', - ], - ); - nodes.push(row); - }); - if (!items.length) nodes.push(E('div', { class: 'dl-pal-empty' }, 'Nothing found.')); - list.replaceChildren(...nodes); - list.querySelector('.sel')?.scrollIntoView({ block: 'nearest' }); - }; - const onKey = (ev: KeyboardEvent) => { - if (ev.key === 'Escape') { - ev.preventDefault(); - close(); - } else if (ev.key === 'ArrowDown') { - ev.preventDefault(); - sel = Math.min(items.length - 1, sel + 1); - render(); - } else if (ev.key === 'ArrowUp') { - ev.preventDefault(); - sel = Math.max(0, sel - 1); - render(); - } else if (ev.key === 'Enter') { - ev.preventDefault(); - const it = items[sel]; - if (it) { - close(); - it.run(); - } - } - }; - input.addEventListener('input', () => { - sel = 0; - render(); - }); - overlay.addEventListener('click', (ev) => { - if (ev.target === overlay) close(); - }); - document.addEventListener('keydown', onKey, true); - document.body.appendChild(overlay); - input.focus(); - render(); - if (!cache || Date.now() - cache.at > 10000) { - const st = await api.status(1).catch(() => null); - if (st) cache = { st, at: Date.now() }; - if (open) render(); - } -} - -/** Install the global shortcut once per page load. */ -export function installPalette(seed?: Status) { - if (seed) cache = { st: seed, at: Date.now() }; - const w = window as any; - if (w.__dlPalette) return; - w.__dlPalette = true; - // Capture phase on window, so Outline's own ⌘K search does not open too. - window.addEventListener( - 'keydown', - (ev) => { - if (!location.pathname.includes('/admin/network/dawnline')) return; - const typing = - /^(INPUT|TEXTAREA|SELECT)$/.test((ev.target as HTMLElement)?.tagName ?? '') || (ev.target as HTMLElement)?.isContentEditable; - const cmdK = (ev.key === 'k' || ev.key === 'K') && (ev.metaKey || ev.ctrlKey); - const slash = ev.key === '/' && !typing && !document.body.classList.contains('modal-overlay-active'); - if (!cmdK && !slash) return; - ev.preventDefault(); - ev.stopImmediatePropagation(); - openPalette(); - }, - true, - ); -} diff --git a/web/src/admin/styles.ts b/web/src/admin/styles.ts index 8aacf00..81a799d 100644 --- a/web/src/admin/styles.ts +++ b/web/src/admin/styles.ts @@ -87,6 +87,33 @@ const CSS = ` .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); } +/* The admin's own actions: an icon in the dot's place, taking the same room. */ +.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; } +/* Service log lines: tile, source name and row tint share one colour, set by the level (--sys). */ +.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; } /* server summary */ @@ -122,8 +149,6 @@ const CSS = ` 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-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; margin: 6px 0 0 44px; font-size: 13px; line-height: 20px; - color: var(--dl-fg-muted); font-variant-numeric: tabular-nums; } .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); } @@ -133,7 +158,7 @@ const CSS = ` .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); } +.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; } @@ -146,13 +171,11 @@ const CSS = ` .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; } -.dl-search { min-width: 240px; } @media (max-width: 640px) { .dl-map .cbi-section-table-row > .td.cbi-section-actions { margin-left: 0; width: 100% !important; } .dl-map .cbi-section-table-row > .td.cbi-section-actions > div { justify-content: flex-start; flex-wrap: wrap; } - .dl-meta, .dl-chips, .dl-quota { margin-left: 0; } + .dl-slotbar, .dl-chips, .dl-quota { margin-left: 0; } .dl-btn-label { display: none; } - .dl-search { min-width: 0; flex: 1; } } /* full-width rows (label above) */ @@ -233,7 +256,10 @@ const CSS = ` 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); } .dl-srvtab i.dot.bad { background: var(--dl-bad); } +.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); } +/* The one status dot left: a server that is running pulses. */ +@keyframes dl-srv-pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--dl-ok) 55%, transparent); } 70%, 100% { 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; } @@ -455,11 +481,8 @@ const CSS = ` .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-searchbtn { display: inline-flex !important; align-items: center; gap: 6px; } -.dl-searchbtn kbd { font-size: 11px; padding: 1px 5px; border-radius: 5px; background: var(--dl-soft); color: var(--dl-fg-muted); font-family: inherit; } .dl-toolbar-end { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: nowrap; min-width: 0; } -.dl-toolbar-end .dl-search { flex: 0 1 300px; min-width: 160px; } -@media (max-width: 640px) { .dl-toolbar-end { flex-wrap: wrap; width: 100%; } .dl-toolbar-end .dl-search { flex: 1 1 100%; } } +@media (max-width: 640px) { .dl-toolbar-end { flex-wrap: wrap; width: 100%; } } .dl-healthstrip { display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap; padding: 9px 14px; margin: 0 0 12px; border-radius: 12px; border: 1px solid color-mix(in srgb, var(--dl-warn) 45%, transparent); background: var(--dl-warn-wash); font-size: 13px; color: var(--dl-fg-muted); } .dl-healthstrip.bad { border-color: color-mix(in srgb, var(--dl-bad) 45%, transparent); background: var(--dl-bad-wash); } @@ -491,15 +514,6 @@ const CSS = ` .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-addrs { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 12px; border-top: 1px solid var(--dl-line); min-width: 0; } -.dl-addr { all: unset; box-sizing: border-box; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px 0 6px; max-width: 100%; - border-radius: 7px; background: var(--dl-soft); color: var(--dl-fg-muted); font: 500 11.5px/1 var(--dl-mono); } -.dl-addr .dl-icon { width: 12px; height: 12px; flex: 0 0 auto; opacity: .8; } -.dl-addr span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; } -.dl-addr:hover { background: var(--dl-soft-hover); color: var(--dl-fg); } -.dl-addr:focus-visible { outline: 2px solid var(--dl-ring); outline-offset: 1px; } -.dl-addr.lan .dl-icon { color: var(--dl-accent); opacity: 1; } -.dl-addr.wan .dl-icon { color: var(--dl-ok); opacity: 1; } .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; } @@ -637,6 +651,36 @@ const CSS = ` .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); } + +/* Health: watchdog card, then checks and the service log side by side. */ +.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; } +} /* tables inside panels */ .dl-table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 20px; } @@ -656,8 +700,6 @@ const CSS = ` .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-pill-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; display: inline-block; } -.dl-root kbd, .dl-pal kbd { font-family: var(--dl-mono); font-size: 11px; line-height: 16px; padding: 0 6px; border-radius: 4px; background: var(--dl-soft); color: var(--dl-fg-muted); } /* Icon-only buttons are circles: width follows the theme's button height. */ .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; } @@ -831,6 +873,7 @@ const CSS = ` 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); } @@ -853,6 +896,10 @@ const CSS = ` .dl-map .cbi-section-create, .dl-map > .cbi-section > .cbi-button-add { display: none !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); } @@ -888,8 +935,8 @@ const CSS = ` .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); } /* Online device: a soft green chip instead of a dot */ -.dl-chip.live { background: color-mix(in srgb, var(--dl-ok) 6%, var(--dl-soft)); border: 1px dashed color-mix(in srgb, var(--dl-ok) 55%, transparent); } -.dl-chip.live:hover { background: color-mix(in srgb, var(--dl-ok) 11%, var(--dl-soft)); } +.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; @@ -897,10 +944,6 @@ const CSS = ` .dl-fix:hover { filter: brightness(1.15); } .dl-map .cbi-section-table-row.dl-attn-row { border-color: color-mix(in srgb, var(--dl-warn) 35%, transparent) !important; } @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-search { display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 10px 0 12px; border: 1px solid var(--input, var(--dl-line)); border-radius: 999px; - background: var(--input-bg, transparent); width: 280px; max-width: 100%; color: var(--dl-fg-faint); box-sizing: border-box; min-width: 0; } -.dl-search-input { text-overflow: ellipsis; border: 0 !important; background: transparent !important; box-shadow: none !important; outline: none; flex: 1; min-width: 0; color: var(--dl-fg); - font: inherit; font-size: 13px; padding: 0 !important; height: 32px !important; } .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; @@ -941,11 +984,7 @@ const CSS = ` .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-live { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; } -.dl-live i.dot, .dl-dstat i.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--dl-fg-faint); display: inline-block; } -.dl-live i.dot.ok { background: var(--dl-ok); box-shadow: 0 0 0 3px var(--dl-ok-wash); } .dl-live i.dot.warn { background: var(--dl-warn); } -.dl-live i.dot.pulse { animation: dl-wait 1.6s ease-in-out infinite; } -@keyframes dl-wait { 0%, 100% { box-shadow: 0 0 0 0 var(--dl-warn-wash); } 50% { box-shadow: 0 0 0 6px transparent; } } +.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; } @@ -961,26 +1000,10 @@ const CSS = ` @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: baseline; gap: 10px; padding: 7px 0; border-top: 1px solid var(--dl-line); font-size: 13px; min-width: 0; } +.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; } -/* command menu */ -.dl-pal-overlay { position: fixed; inset: 0; z-index: 1000; background: var(--scrim, rgba(0,0,0,.5)); display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 0; } -.dl-pal { width: min(640px, 100%); background: var(--dl-elevated); color: var(--dl-fg); border-radius: 16px; overflow: hidden; - box-shadow: var(--shadow-menu, 0 16px 32px -8px rgba(0,0,0,.6)); border: 1px solid var(--dl-line); } -.dl-pal-search { display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 16px; border-bottom: 1px solid var(--dl-line); color: var(--dl-fg-faint); } -.dl-pal-input { flex: 1; border: 0 !important; background: transparent !important; box-shadow: none !important; outline: none; font: inherit; font-size: 16px; color: var(--dl-fg); padding: 0 !important; } -.dl-pal-list { max-height: 52vh; overflow: auto; padding: 8px; } -.dl-pal-group { padding: 8px 12px 4px; font-size: 12px; font-weight: 500; color: var(--dl-fg-faint); } -.dl-pal-item { display: flex; align-items: center; gap: 12px; min-height: 40px; padding: 0 12px; border-radius: 8px; cursor: pointer; font-size: 14px; } -.dl-pal-item.sel { background: var(--dl-soft-hover); } -.dl-pal-item .dl-icon { color: var(--dl-fg-muted); } -.dl-pal-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } -.dl-pal-ic { width: 16px; } -.dl-pal-empty { padding: 16px 12px; color: var(--dl-fg-muted); font-size: 14px; } -.dl-pal-foot { display: flex; gap: 16px; padding: 10px 16px; border-top: 1px solid var(--dl-line); font-size: 12px; color: var(--dl-fg-faint); } - /* settings */ .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); } diff --git a/web/src/admin/urls.ts b/web/src/admin/urls.ts new file mode 100644 index 0000000..da71a74 --- /dev/null +++ b/web/src/admin/urls.ts @@ -0,0 +1,10 @@ +// Addresses of Dawnline's admin pages. + +/** A server's People section (Servers page). */ +export function peopleUrl(server?: string): string { + return `${L.url('admin/network/dawnline/server')}?${server ? `server=${encodeURIComponent(server)}&` : ''}section=people`; +} + +export function personUrl(id: string, device?: string): string { + return `${L.url('admin/network/dawnline/person')}?id=${encodeURIComponent(id)}${device ? `&device=${encodeURIComponent(device)}` : ''}`; +} diff --git a/web/src/portal/main.ts b/web/src/portal/main.ts index a0994c0..da46d15 100644 --- a/web/src/portal/main.ts +++ b/web/src/portal/main.ts @@ -5,7 +5,7 @@ // devices on the left, access on the right. import type { ClientConfig, Device, Kind, Person } from '../shared/types'; -import { ACCESS_LABEL, KIND_LABEL, STATE_LABEL, ago, bytes, date, daysLeft, initials } from '../shared/format'; +import { ACCESS_LABEL, KIND_LABEL, STATE_LABEL, ago, byDeviceState, bytes, date, daysLeft, initials } from '../shared/format'; import { iconSvg } from '../shared/icons'; import { qrSvg } from '../shared/qr'; import { vpnKey } from '../shared/vpnkey'; @@ -13,7 +13,10 @@ import { vpnKey } from '../shared/vpnkey'; interface State { title: string; person: Person; - server: { name: string; endpoint: string }; + /** device_mesh: devices with home access reach each other through the tunnel. */ + server: { name: string; endpoint: string; device_mesh?: boolean }; + /** The device this page was opened from (through the tunnel), if any. */ + here?: string | null; can_add: boolean; kinds: Kind[]; version: string; @@ -312,7 +315,9 @@ function accessCard(st: State): HTMLElement { if (p.quota_limit) tip(bar, () => [`${pct.toFixed(1)}% used`, `${bytes(Math.max(0, p.quota_limit - p.quota_used))} left`]); const left = daysLeft(p.expires); const slots = h('div', { class: 'slots' }); - for (let i = 0; i < p.device_limit; i++) slots.appendChild(h('i', { class: i < p.devices.length ? 'used' : '' })); + // Devices the admin added over the limit get their own orange slots after the allowed ones. + for (let i = 0; i < Math.max(p.device_limit, p.devices.length); i++) + slots.appendChild(h('i', { class: i >= p.device_limit ? 'over' : i < p.devices.length ? 'used' : '' })); const used = p.quota_used || p.month[0] + p.month[1]; const icon = p.access === 'internet' ? 'globe' : p.access === 'lan' ? 'home' : 'shield'; // Heading outside the card, like "Your devices", so both columns line up. @@ -338,6 +343,7 @@ function accessCard(st: State): HTMLElement { h('span', { class: 'muted s' }, ACCESS_TEXT[p.access]), ), ), + namesAtHome(p, !!st.server.device_mesh), h( 'div', { class: 'tile' }, @@ -389,31 +395,76 @@ function accessCard(st: State): HTMLElement { } function deviceStatus(d: Device): HTMLElement { - if (d.disabled) return h('span', { class: 'dstat' }, h('i', { class: 'dot' }), 'Disabled by the admin'); - if (d.online) return h('span', { class: 'dstat ok' }, h('i', { class: 'dot ok' }), 'Connected'); - if (!d.handshake) return h('span', { class: 'dstat warn' }, h('i', { class: 'dot warn' }), 'Not set up yet'); - return h('span', { class: 'dstat' }, h('i', { class: 'dot' }), `Last connected ${ago(d.handshake)}`); + // Status as coloured text, no dots (only the avatar carries one). + if (d.disabled) return h('span', { class: 'dstat' }, 'Disabled by the admin'); + if (d.online) return h('span', { class: 'dstat ok' }, 'Connected'); + if (!d.handshake) return h('span', { class: 'dstat warn' }, 'Not set up yet'); + return h('span', { class: 'dstat' }, `Last connected ${ago(d.handshake)}`); } -function localAddress(d: Device, p: Person): HTMLElement | null { - if (!d.hostname || p.access === 'internet') return null; +/** + * How other devices at home reach this person's devices: once, in the access card, + * instead of an address on every device card. Only with access to the home network. + */ +/** + * Whether the home network can open connections to this device: the router lets + * it through only for people with home access who are active, and devices on. + */ +function reachableFromHome(p: Person, d: Device): boolean { + return p.access !== 'internet' && p.state === 'active' && !d.disabled; +} + +function namesAtHome(p: Person, mesh: boolean): HTMLElement | null { + const named = byDeviceState(p.devices).filter((d) => d.hostname && reachableFromHome(p, d)); + if (!named.length) return null; + const first = named[0].hostname; + const domain = first.slice(first.indexOf('.')); return h( 'div', - { class: 'dfoot' }, - h('span', { class: 'faint s' }, 'Local address'), + { class: 'names' }, h( - 'button', - { type: 'button', class: 'lan-pill', 'aria-label': `Copy ${d.hostname}`, onclick: () => copy(d.hostname, 'Address copied') }, - h('span', { class: 'lan-ic' }, ic('home')), - h('span', { class: 'mono' }, d.hostname), - h('span', { class: 'lan-sep' }), - ic('copy'), + 'div', + { class: 'names-head' }, + h('span', { class: 'names-ic' }, ic('home')), + h( + 'div', + { class: 'stack' }, + h('span', { class: 'strong s' }, 'Names at home'), + h( + 'span', + { class: 'faint s' }, + mesh ? 'Devices at home and on this VPN reach yours as ' : 'Other devices at home reach yours as ', + h('span', { class: 'mono' }, `name${domain}`), + ), + ), + ), + h( + 'div', + { class: 'names-list' }, + named.map((d) => { + const dot = d.hostname.indexOf('.'); + return h( + 'button', + { + type: 'button', + class: 'name-chip', + title: d.name, + 'aria-label': `Copy ${d.hostname}`, + onclick: () => copy(d.hostname, 'Address copied'), + }, + h( + 'span', + { class: 'mono' }, + dot > 0 ? [d.hostname.slice(0, dot), h('span', { class: 'faint' }, d.hostname.slice(dot))] : d.hostname, + ), + ic('copy'), + ); + }), ), ); } function deviceCard(d: Device, st: State): HTMLElement { - const p = st.person; const more = h('button', { type: 'button', class: 'icon-btn soft', 'aria-label': `${d.name} options` }, ic('more')); more.addEventListener('click', (ev) => { ev.stopPropagation(); @@ -422,20 +473,37 @@ function deviceCard(d: Device, st: State): HTMLElement { { label: 'Copy AmneziaVPN key', icon: 'key', run: () => copyKey(d) }, { label: 'Download .conf', icon: 'download', run: () => downloadConf(d) }, null, + // How devices at home reach it: only where the router actually lets them through. + ...(reachableFromHome(st.person, d) + ? [ + { label: 'Copy IP address', icon: 'copy', run: () => copy(d.address, 'IP address copied') }, + ...(d.hostname ? [{ label: 'Copy local address', icon: 'home', run: () => copy(d.hostname, 'Address copied') }] : []), + null, + ] + : []), { label: 'Rename', icon: 'edit', run: () => rename(d) }, + ...(d.disabled ? [] : [{ label: 'New keys', icon: 'reset', run: () => rotateKeys(d, st) }]), { label: 'Remove', icon: 'trash', danger: true, run: () => removeDevice(d) }, ]); }); const week = d.spark.reduce((a, b) => a + b, 0); const setUp = !d.handshake && !d.disabled; + // The device this page was opened from (through the tunnel): blue, and says so. + const here = st.here === d.id; return h( 'article', - { class: `dcard${d.online ? ' online' : ''}${d.disabled ? ' off' : ''}` }, + { class: `dcard${d.online ? ' online' : ''}${d.disabled ? ' off' : ''}${here ? ' here' : ''}` }, h( 'div', { class: 'dhead' }, h('span', { class: 'dic' }, ic(d.kind)), - h('div', { class: 'stack grow' }, h('span', { class: 'dname' }, d.name), deviceStatus(d)), + h( + 'div', + { class: 'stack grow' }, + h('span', { class: 'dname' }, d.name), + // Opened through the tunnel, so it is connected: say which one it is instead. + here ? h('span', { class: 'dstat here' }, 'This device') : deviceStatus(d), + ), more, ), setUp @@ -446,7 +514,6 @@ function deviceCard(d: Device, st: State): HTMLElement { ic(isMobile() ? 'open' : 'qr'), h('span', {}, isMobile() ? 'Open in AmneziaVPN' : 'Connect this device'), ), - h('span', { class: 'faint s center' }, 'Setting up another device? QR, key and file are under ⋯'), ] : h( 'div', @@ -463,7 +530,6 @@ function deviceCard(d: Device, st: State): HTMLElement { h('button', { type: 'button', class: 'btn small', onclick: () => connect(d) }, 'Update'), ) : null, - localAddress(d, p), ); } @@ -497,7 +563,9 @@ function main(st: State) { ) : null; - const cards: HTMLElement[] = p.devices.map((d) => deviceCard(d, st)); + // The device this page was opened from comes first. + const order = byDeviceState(p.devices).sort((a, b) => Number(b.id === st.here) - Number(a.id === st.here)); + const cards: HTMLElement[] = order.map((d) => deviceCard(d, st)); const free = Math.max(0, p.device_limit - p.devices.length); if (free) cards.push( @@ -505,12 +573,8 @@ function main(st: State) { 'button', { type: 'button', class: 'slot add', onclick: addDevice }, h('span', { class: 'slot-ic' }, ic('plus')), - h( - 'span', - { class: 'stack' }, - h('span', { class: 'strong' }, 'Add device'), - h('span', { class: 'faint s' }, `${free} slot${free === 1 ? '' : 's'} free`), - ), + // How many are left is in "Your devices 3 of 10" and the Devices tile. + h('span', { class: 'strong' }, 'Add device'), ), ); @@ -523,8 +587,8 @@ function main(st: State) { h( 'div', { class: 'row-baseline' }, + // How many (the Devices tile) and which are online (the cards) are shown already. h('h2', {}, 'Your devices'), - h('span', { class: 'faint s' }, `${p.devices.length} of ${p.device_limit} · ${p.online} online`), ), ), h('div', { class: 'dgrid' }, cards), @@ -548,11 +612,12 @@ function main(st: State) { h( 'div', { class: 'stack' }, - h('div', { class: 'row' }, h('h1', {}, `Hi, ${p.name}`), h('span', { class: `pill ${stateTone(p)}` }, STATE_LABEL[p.state])), + // Only when something is wrong: an "Active" pill says nothing. h( - 'span', - { class: 'faint s' }, - `${p.online ? `${p.online} device${p.online === 1 ? '' : 's'} online` : 'Nothing connected right now'} · ${bytes(p.month[0] + p.month[1])} this month`, + 'div', + { class: 'row' }, + h('h1', {}, `Hi, ${p.name}`), + p.state === 'active' ? null : h('span', { class: `pill ${stateTone(p)}` }, STATE_LABEL[p.state]), ), ), ), @@ -720,10 +785,9 @@ async function connect(d: Device, initial?: 'app' | 'qr' | 'key' | 'file', cfgIn const live = h('div', { class: 'waiting' }); const paintLive = (dev: Device | undefined) => { - if (dev?.online) live.replaceChildren(h('i', { class: 'dot ok' }), h('span', { class: 'ok' }, `${d.name} is connected`)); - else if (dev?.handshake) - live.replaceChildren(h('i', { class: 'dot' }), h('span', { class: 'muted' }, `Last connected ${ago(dev.handshake)}`)); - else live.replaceChildren(h('i', { class: 'dot warn pulse' }), h('span', { class: 'muted' }, 'Waiting for the first connection…')); + if (dev?.online) live.replaceChildren(h('span', { class: 'ok' }, `${d.name} is connected`)); + else if (dev?.handshake) live.replaceChildren(h('span', { class: 'muted' }, `Last connected ${ago(dev.handshake)}`)); + else live.replaceChildren(h('span', { class: 'warn' }, 'Waiting for the first connection…')); }; paintLive(d); const watch = window.setInterval(async () => { @@ -777,6 +841,44 @@ function rename(d: Device) { setTimeout(() => name.select(), 50); } +/** New keys for a device: the old configuration stops working, the new one is shown right away. */ +function rotateKeys(d: Device, st: State) { + const here = st.here === d.id; + sheet( + `New keys for ${d.name}?`, + null, + h( + 'p', + { class: 'muted' }, + here + ? '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.', + ), + h( + 'div', + { class: 'row gap' }, + h('button', { class: 'btn block', onclick: () => closeSheet() }, 'Cancel'), + h( + 'button', + { + class: 'btn primary block', + onclick: async () => { + try { + const r = await call<{ config: ClientConfig; state: State }>(`devices/${d.id}`, { action: 'rotate' }); + state = r.state; + main(state); + connect(d, undefined, r.config); + } catch (er) { + toast((er as Error).message, true); + } + }, + }, + 'New keys', + ), + ), + ); +} + function removeDevice(d: Device) { sheet( `Remove ${d.name}?`, diff --git a/web/src/portal/portal.css b/web/src/portal/portal.css index 18463fd..826f51c 100644 --- a/web/src/portal/portal.css +++ b/web/src/portal/portal.css @@ -454,6 +454,9 @@ h2 { .slots i.used { background: var(--text); } +.slots i.over { + background: color-mix(in srgb, var(--warn) 80%, transparent); +} /* devices */ .dgrid { @@ -512,6 +515,21 @@ h2 { background: var(--ok-wash); color: var(--ok); } +/* The device this page was opened from: blue tile, blue status, blue border. */ +.dcard.here { + border: 1.5px dotted color-mix(in srgb, var(--accent) 80%, transparent); +} +.dcard.here .dic { + background: color-mix(in srgb, var(--accent) 16%, transparent); + color: var(--info); +} +.dstat.here { + color: var(--info); +} +.dot.here { + background: var(--accent); + box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); +} .dname { font-weight: 500; white-space: nowrap; @@ -586,78 +604,70 @@ h2 { opacity: 1; filter: brightness(1.2); } -.dfoot { +/* Names at home (access card) */ +.names { display: flex; - flex-wrap: wrap; - align-items: center; - justify-content: space-between; - gap: 8px; - padding-top: 12px; - border-top: 1px solid var(--line); + flex-direction: column; + gap: 10px; + padding: 12px; + border-radius: 12px; + border: 1px solid var(--line); } -.dfoot > .faint { - white-space: nowrap; +.names-head { + display: flex; + gap: 10px; + align-items: flex-start; } -.lan-pill { - all: unset; - cursor: pointer; - display: inline-flex; - align-items: center; - height: 26px; - padding: 0 3px; - border-radius: 999px; - max-width: 100%; - min-width: 0; - background: linear-gradient(180deg, color-mix(in srgb, var(--text) 6%, transparent), color-mix(in srgb, var(--text) 2.5%, transparent)); - box-shadow: - inset 0 0 0 1px var(--line), - 0 1px 2px #0003; -} -.lan-pill:hover { - box-shadow: - inset 0 0 0 1px var(--input), - 0 1px 2px #0003; -} -.lan-pill:focus-visible { - outline: 2px solid var(--accent); - outline-offset: 2px; -} -.lan-ic { - width: 20px; - height: 20px; - border-radius: 50%; +.names-ic { + width: 28px; + height: 28px; + border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; - flex: 0 0 auto; + flex: none; background: color-mix(in srgb, var(--info) 14%, transparent); color: var(--info); } -.lan-ic .ic-svg { - width: 11px; - height: 11px; +.names-ic .ic-svg { + width: 15px; + height: 15px; } -.lan-pill .mono { - padding: 0 8px 0 7px; - font-weight: 500; - white-space: nowrap; +.names-list { + display: flex; + flex-wrap: wrap; + gap: 6px; +} +.name-chip { + all: unset; + box-sizing: border-box; + cursor: pointer; + display: inline-flex; + align-items: center; + gap: 6px; + height: 28px; + max-width: 100%; + padding: 0 9px 0 10px; + border-radius: 999px; + background: var(--soft); +} +.name-chip:hover { + background: var(--soft-hover); +} +.name-chip:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; +} +.name-chip .mono { overflow: hidden; text-overflow: ellipsis; + white-space: nowrap; + min-width: 0; } -.lan-sep { - width: 1px; - height: 14px; - background: var(--line); - flex: 0 0 auto; -} -.lan-pill > .ic:last-child { - width: 22px; - justify-content: center; - color: var(--muted); -} -.lan-pill > .ic:last-child .ic-svg { - width: 12px; - height: 12px; +.name-chip .ic-svg { + width: 13px; + height: 13px; + color: var(--faint); } .slot.add { all: unset; diff --git a/web/src/shared/format.ts b/web/src/shared/format.ts index 3bfc1d7..6da5968 100644 --- a/web/src/shared/format.ts +++ b/web/src/shared/format.ts @@ -118,3 +118,12 @@ export function slugify(s: string): string { .replace(/^-+|-+$/g, '') .slice(0, 32); } + +/** Online, then offline, then not set up yet, then turned off; the order they were added within each. */ +export function byDeviceState(list: T[]): T[] { + const rank = (d: T) => (d.disabled ? 3 : d.online ? 0 : d.handshake ? 1 : 2); + return list + .map((d, i) => [d, i] as const) + .sort((a, b) => rank(a[0]) - rank(b[0]) || a[1] - b[1]) + .map(([d]) => d); +} diff --git a/web/src/shared/icons.ts b/web/src/shared/icons.ts index 5d5707c..e9ffbc5 100644 --- a/web/src/shared/icons.ts +++ b/web/src/shared/icons.ts @@ -30,6 +30,8 @@ const P: Record = { play: '', key: '', out: '', + admin: + '', shield: '', shieldplus: '', lock: '', @@ -41,7 +43,6 @@ const P: Record = { home: '', open: '', file: '', - search: '', network: '', moon: '', diff --git a/web/src/shared/types.ts b/web/src/shared/types.ts index add34e7..dc53620 100644 --- a/web/src/shared/types.ts +++ b/web/src/shared/types.ts @@ -75,6 +75,8 @@ export interface Server { enabled: boolean; /** Internet traffic enters the router from the LAN, like a home device's. */ lan_like: boolean; + /** Devices of people with home access reach each other through the tunnel. */ + device_mesh: boolean; preset: string; mtu: number; keepalive: number; @@ -107,6 +109,12 @@ export interface LogEvent { detail?: string; /** City · network operator, when known at the time of the event. */ where?: string | null; + /** Who did it, when a person did: the admin in LuCI or the person on their portal. */ + by?: 'admin' | 'portal'; + /** Names at the time of the event, for people and devices removed since. */ + pname?: string; + dname?: string; + dkind?: string; } export interface GeoPoint { diff --git a/web/tests/shared.test.ts b/web/tests/shared.test.ts index 88ca270..b741f32 100644 --- a/web/tests/shared.test.ts +++ b/web/tests/shared.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; import { inflateSync } from 'node:zlib'; -import { bytes, daysLeft, initials, quotaText, slugify } from '../src/shared/format'; +import { byDeviceState, bytes, daysLeft, initials, quotaText, slugify } from '../src/shared/format'; import { amneziaJson, base64Url, fromBase64Url, vpnKey, withPrivateKey } from '../src/shared/vpnkey'; import type { ClientConfig } from '../src/shared/types'; @@ -89,3 +89,11 @@ describe('vpn:// keys', () => { expect(c.amnezia.client_priv_key).toBe('ZZZ='); }); }); + +describe('byDeviceState', () => { + it('puts online first, then offline, not set up and turned off, keeping the order within each', () => { + const d = (name: string, online: boolean, handshake: number, disabled = false) => ({ name, online, handshake, disabled }); + const list = [d('off', false, 5, true), d('new', false, 0), d('away1', false, 9), d('live', true, 10), d('away2', false, 3)]; + expect(byDeviceState(list).map((x) => x.name)).toEqual(['live', 'away1', 'away2', 'new', 'off']); + }); +});