diff --git a/plugins/registry.json b/plugins/registry.json index 7f918c38..e522c5f5 100644 --- a/plugins/registry.json +++ b/plugins/registry.json @@ -418,13 +418,13 @@ { "id": "vpn", "name": "VPN", - "version": "2.0.0", + "version": "2.1.0", "path": "plugins/vpn", "author": "neur0map ", "upstream": "https://github.com/ryoku-dev/ryostore/tree/main/plugins/vpn", "discord": "https://discord.gg/8KjBmUEyKA", - "summary": "Watch and switch your VPN from the bar: a Tailscale switch with the tunnel's dossier, and your NetworkManager VPN and WireGuard profiles,...", - "description": "Watch and switch your VPN from the bar: a Tailscale switch with the tunnel's dossier, and your NetworkManager VPN and WireGuard profiles, in a bar panel or a desktop card.", + "summary": "Watch and switch your VPN from the bar: a Tailscale switch with the tunnel's dossier, an exit-node picker with automatic route acceptance...", + "description": "Watch and switch your VPN from the bar: a Tailscale switch with the tunnel's dossier, an exit-node picker with automatic route acceptance and a clean-restart that flushes stale routing tables, plus your NetworkManager VPN and WireGuard profiles, in a bar panel or a desktop card.", "tags": [ "vpn", "network", @@ -440,15 +440,15 @@ "assets/preview-desktop.png" ], "manifest": "product-manifest.json", - "manifestSha256": "5493894e33ace5e10fd4dd4db0007e9b1a666178cee5927d106d8011e758b80c", + "manifestSha256": "ae187e9406784006fcfebbe00e0d0f23bfbf283d27839ab57b5910f195293eff", "official": false, - "tagline": "Watch and switch your VPN from the bar: a Tailscale switch with the tunnel's dossier, and your NetworkManager VPN and WireGuard profiles,...", + "tagline": "Watch and switch your VPN from the bar: a Tailscale switch with the tunnel's dossier, an exit-node picker with automatic route acceptance...", "icon": "vpn_lock", "hosts": [ "topbarGlyph", "desktopWidget" ], - "lastUpdated": "2026-09-02" + "lastUpdated": "2026-12-01" }, { "id": "public-ip", diff --git a/plugins/vpn/README.md b/plugins/vpn/README.md index 91078152..8fac38f8 100644 --- a/plugins/vpn/README.md +++ b/plugins/vpn/README.md @@ -1,98 +1,78 @@ # VPN -A community plugin for the [Ryoku](https://ryoku.dev) desktop. It watches your -VPN and lets you switch it from the top bar (a single mark that opens a panel) or -from a card on the wallpaper. It knows two backends and shows whichever you have. +Watch and switch your VPN from the Ryoku bar. A Tailscale switch with the +tunnel's dossier, an **exit-node picker**, **automatic acceptance of advertised +routes**, and a **clean restart** that flushes stale routing tables — plus your +NetworkManager VPN and WireGuard profiles. Available as a bar panel +(`topbarGlyph`) or a desktop card (`desktopWidget`). + +## Features + +### Tailscale +- One-tap **turn on / off**, with the tunnel dossier: device, MagicDNS name, + IPv4/IPv6 (copy the IP), tailnet, relay, peer count, version, and any health + warnings Tailscale reports. +- **Exit-node picker** *(new in 2.1.0)* — when connected, every peer that + advertises itself as an exit node is listed; tap **USE** to route all traffic + through it (`tailscale set --exit-node= --exit-node-allow-lan-access`). The + active node is marked **IN USE**; **STOP USING** clears it. +- **Accept advertised routes automatically** *(new in 2.1.0)* — when the + *Accept advertised subnet routes automatically* setting is on (default), a + subnet route another node announces is honoured by adding `--accept-routes` on + turn-on and when an exit node is picked. +- **Clean restart** *(new in 2.1.0)* — the **CLEAN RESTART** button (two-tap + confirm) clears the exit node, brings Tailscale down, then restarts the + `tailscaled` daemon so the policy-routing table and the `ts-*` firewall chains + are torn down and rebuilt from scratch, leaving no stale route behind after a + killed session. The daemon restart goes through the edition-agnostic + `ryoku-host` init seam. +- **Operator gate** — if Tailscale refuses a switch for want of an operator, the + panel offers a one-time **AUTHORISE** that sets the current user as operator so + later switches need no password. + +### NetworkManager +- Lists your VPN and WireGuard profiles (never a `tun` device or an + externally-managed connection); turn each on/off by UUID, with per-active + address, gateway and DNS. -![VPN widget on the bar](assets/preview-widget.png) -![VPN card on the desktop](assets/preview-desktop.png) +## Settings -## What it does +| Key | Type | Default | What it does | +|---|---|---|---| +| `poll` | int (3–60) | 10 | Refresh cadence in seconds. | +| `barLabel` | choice | `name` | What rides beside the bar mark: nothing, the connection name, or the IPv4. | +| `confirmOff` | toggle | on | Ask before turning off an exit-node tunnel. | +| `acceptRoutes` | toggle | on | Accept advertised subnet routes automatically. | -- **On the bar** it rides as one Material mark, `vpn_lock` in the accent when a - tunnel is up and `vpn_key_off` in the dim ink when none is, with the - connection name or IP beside it. A left click opens the plugin's bar panel; the - mark itself never changes the network. -- **The panel** (and the desktop card) show the tunnel's details and the switches - that turn it on or off. +## What it runs, reads and writes -### Backends +- **Reads** VPN state by running `tailscale status --json` and + `nmcli -t … connection/device show`. No files are read or written outside the + plugin's own state. +- **Writes** only Tailscale/NetworkManager preferences, and only on an explicit + tap: `tailscale up|down|set`, `nmcli connection up|down`. -**Tailscale** (when the `tailscale` command is present). The panel shows a switch -and the dossier: device (host name), name (MagicDNS name), IPv4 (with a COPY -button), IPv6, tailnet, exit node (with STOP USING when one is active), relay, -peers online/total, and version, plus any health warnings Tailscale reports. An -ADMIN CONSOLE button opens your machines page. +### Capabilities -**NetworkManager**. Every VPN and WireGuard profile NetworkManager knows, each -with a switch; an active profile also shows its device, IPv4 and gateway. +- **network**: `login.tailscale.com` — opening the admin console + (`xdg-open`), on the **ADMIN CONSOLE** tap only. +- **privileged** (via `pkexec`, on an explicit tap only, polkit asks once): + - `pkexec tailscale set --operator` — the one-time operator authorisation. + - `pkexec ryoku-host svc --system restart tailscaled` — the clean-restart + daemon flush, routed through the `ryoku-host` init seam so it works on any + Ryoku edition (systemd, dinit, …). -## Settings +### Dependencies -| Key | Type | Default | What it does | -|---|---|---|---| -| `poll` | int (3..60) | `10` | Seconds between refreshes. | -| `barLabel` | choice `none`/`name`/`ip` | `name` | What rides beside the bar mark. | -| `confirmOff` | toggle | `true` | Ask before turning off a VPN that is using an exit node. | - -Turning off an exit-node Tailscale tunnel arms once (`TURN OFF? traffic leaves -the exit node`) and only acts on the second tap, so you never drop your exit node -by accident. The arm clears after three seconds. - -## What it runs - -Every external command, and exactly when: - -| Command | When | -|---|---| -| `tailscale status --json` | on load, every `poll` seconds, and 1 s after any action (also the probe that decides Tailscale is installed) | -| `tailscale up` | the switch, turning Tailscale on | -| `tailscale down` | the switch, turning Tailscale off | -| `tailscale set --exit-node=` | the exit node's STOP USING button | -| `pkexec tailscale set --operator=` | the panel's AUTHORISE button only (see below) | -| `nmcli -t -f NAME,UUID,TYPE,DEVICE,STATE connection show` | on load and every `poll` seconds | -| `nmcli -t -f IP4.ADDRESS,IP6.ADDRESS,IP4.GATEWAY,IP4.DNS device show ` | for each active profile after a poll | -| `nmcli connection up\|down uuid ` | a NetworkManager profile's switch | -| `wl-copy ` | the IPv4 COPY button | -| `xdg-open https://login.tailscale.com/admin/machines` | the ADMIN CONSOLE button | - -`` is `$USER` from the shell's environment. - -## What it never does - -- **It never touches a `tun` device through `nmcli`, and never a connection - NetworkManager reports as external or unmanaged.** Those are other software's - tunnels (a Tailscale `tun`, a container link, a VPN a different tool brought - up); switching them off from here would fight whatever owns them, so the - NetworkManager backend only ever lists and toggles real `vpn` and `wireguard` - profiles. -- **No mutation ever happens on a bar-mark click.** The mark only opens the - panel; every up/down/stop is a deliberate button in the panel or the card. - -## The operator note - -Tailscale only lets its *operator* change its state without root. On a machine -where no operator is set, `tailscale up` (and the other switches) fail with -`Access denied: prefs write access denied`. When that happens the panel shows an -AUTHORISE button that runs `pkexec tailscale set --operator=` once: polkit -asks for your password, sets you as the operator, and the action you tried is -retried automatically. After that, the switches work without a prompt. This is -the plugin's only privileged command, it runs only on that explicit click, and -it is declared in the manifest's `capabilities.privileged`. - -## Requirements - -- **Tailscale** (`tailscale` on `PATH`) for the Tailscale backend, and/or - **NetworkManager** (`nmcli`) for the NetworkManager backend. The plugin shows - whichever it finds; with neither, the panel says so. -- `wl-copy` (wl-clipboard) for the COPY button and `xdg-open` for ADMIN CONSOLE. - -## Where it lists - -This is a community plugin (`official: false`), so it appears under **QS Bar -Settings > Community** with the store's community warning, its author, its switch -and its settings. +`tailscale`, `nmcli`, `wl-copy`, `xdg-open`, and `ryoku-host` (the platform init +seam, used for the clean restart) with a `tailscaled` service. + +## Credits + +Created and maintained by **neur0map** ``. +Exit-node picker, automatic route acceptance and clean-restart (2.1.0) +contributed by **Jarek Armengol** ([@Glitchboi-sudo](https://github.com/Glitchboi-sudo)). ## License -MIT (c) neur0map. See [LICENSE](LICENSE). +MIT. diff --git a/plugins/vpn/assets/preview-widget.png b/plugins/vpn/assets/preview-widget.png index 1e9f025e..d0557310 100644 Binary files a/plugins/vpn/assets/preview-widget.png and b/plugins/vpn/assets/preview-widget.png differ diff --git a/plugins/vpn/content/Panel.qml b/plugins/vpn/content/Panel.qml index e324a7e8..37f40ed2 100644 --- a/plugins/vpn/content/Panel.qml +++ b/plugins/vpn/content/Panel.qml @@ -154,6 +154,9 @@ Item { // arm state for the confirm-off flow property bool armed: false Timer { id: disarm; interval: 3000; repeat: false; onTriggered: tsCard.armed = false } + // arm state for the clean-restart flow (privileged, disruptive) + property bool resetArmed: false + Timer { id: resetDisarm; interval: 3000; repeat: false; onTriggered: tsCard.resetArmed = false } Eyebrow { label: "Tailscale"; s: root.s } @@ -236,6 +239,48 @@ Item { InfoRow { s: root.s; label: qsTr("Version"); value: root.ts ? root.ts.version : "" } } + // ── exit-node picker ────────────────────────────────────────── + // The peers that advertise themselves as exit nodes; tap USE to route + // through one (accepting advertised routes when that setting is on). + Column { + width: parent.width + spacing: 6 * root.s + visible: root.ts && root.ts.up && root.ts.exitNodes.length > 0 + + Divider {} + Eyebrow { label: "Exit nodes"; s: root.s } + + Repeater { + model: root.ts ? root.ts.exitNodes : [] + delegate: Item { + id: exrow + required property var modelData + width: parent ? parent.width : 0 + height: 24 * root.s + Text { + anchors.left: parent.left + anchors.right: exBtn.left + anchors.rightMargin: 8 * root.s + anchors.verticalCenter: parent.verticalCenter + text: exrow.modelData.name + color: exrow.modelData.active ? Theme.accent : Theme.cream + font.family: Theme.font + font.pixelSize: 11.5 * root.s + font.weight: exrow.modelData.active ? Font.DemiBold : Font.Normal + elide: Text.ElideRight + } + Btn { + id: exBtn + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + enabledAction: !exrow.modelData.active + label: exrow.modelData.active ? qsTr("IN USE") : qsTr("USE") + onTapped: if (root.ts) root.ts.useExitNode(exrow.modelData.addr) + } + } + } + } + // health warnings, when tailscale reports any Column { width: parent.width @@ -274,7 +319,8 @@ Item { Divider {} - // footer + // footer: admin console + a clean restart that flushes the routing + // tables (clears the exit node, downs Tailscale, restarts the daemon). Item { width: parent.width height: 24 * root.s @@ -284,6 +330,35 @@ Item { label: qsTr("ADMIN CONSOLE") onTapped: if (root.ts) root.ts.openAdmin() } + Btn { + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + strong: tsCard.resetArmed + label: tsCard.resetArmed ? qsTr("CONFIRM RESET") : qsTr("CLEAN RESTART") + onTapped: { + if (!root.ts) return; + if (!tsCard.resetArmed) { + tsCard.resetArmed = true; + resetDisarm.restart(); + } else { + tsCard.resetArmed = false; + resetDisarm.stop(); + root.ts.resetClean(); + } + } + } + } + + // what the clean restart will do, shown only while armed + Text { + width: parent.width + visible: tsCard.resetArmed + text: qsTr("CONFIRM? downs Tailscale and restarts the daemon to clear stale routes (asks for your password)") + color: Theme.gold + font.family: Theme.mono + font.pixelSize: 9.5 * root.s + font.letterSpacing: 0.6 * root.s + wrapMode: Text.WordWrap } } diff --git a/plugins/vpn/manifest.json b/plugins/vpn/manifest.json index 51518f10..aa9a92cc 100644 --- a/plugins/vpn/manifest.json +++ b/plugins/vpn/manifest.json @@ -1,9 +1,9 @@ { "id": "vpn", "name": "VPN", - "version": "2.0.0", + "version": "2.1.0", "author": "neur0map ", - "description": "Watch and switch your VPN from the bar: a Tailscale switch with the tunnel's dossier, and your NetworkManager VPN and WireGuard profiles, in a bar panel or a desktop card.", + "description": "Watch and switch your VPN from the bar: a Tailscale switch with the tunnel's dossier, an exit-node picker with automatic route acceptance and a clean-restart that flushes stale routing tables, plus your NetworkManager VPN and WireGuard profiles, in a bar panel or a desktop card.", "license": "MIT", "official": false, "tags": [ @@ -37,7 +37,8 @@ "login.tailscale.com" ], "privileged": [ - "pkexec tailscale set --operator" + "pkexec tailscale set --operator", + "pkexec ryoku-host svc --system restart tailscaled" ] }, "hosts": [ @@ -89,6 +90,13 @@ "label": "Ask before turning off an exit-node VPN", "group": "VPN", "default": true + }, + { + "key": "acceptRoutes", + "type": "toggle", + "label": "Accept advertised subnet routes automatically", + "group": "VPN", + "default": true } ] } diff --git a/plugins/vpn/product-manifest.json b/plugins/vpn/product-manifest.json index 232b753f..8dfd8e47 100644 --- a/plugins/vpn/product-manifest.json +++ b/plugins/vpn/product-manifest.json @@ -2,7 +2,7 @@ "schema": 1, "id": "vpn", "category": "plugins", - "version": "2.0.0", + "version": "2.1.0", "destination": "ryoku/plugins/vpn", "files": [ { @@ -16,9 +16,9 @@ { "source": "README.md", "destination": "README.md", - "sha256": "16a13daf4dea10d5040fda3e9e990e6ee5f43480cda63651972e7a35fc6ed6db", + "sha256": "c7514a324325bd5f391177ba2b09813feedad2d7629b23ce986e6cd9a8d19a68", "mode": "0644", - "size": 4572, + "size": 3607, "install": false }, { @@ -32,9 +32,9 @@ { "source": "assets/preview-widget.png", "destination": "assets/preview-widget.png", - "sha256": "7f06135117d1ee94e1665f04c193d87bc9abdfdc72e2e277cd4a32707404e9ad", + "sha256": "1e2b5e89fe8ad386dc710b76dc7070b60bc8608912857e4c8dbae766ee5bafb7", "mode": "0644", - "size": 51983, + "size": 79376, "install": false }, { @@ -46,12 +46,12 @@ "install": true }, { - "source": "content/Glyph.qml", - "destination": "content/Glyph.qml", - "sha256": "302fb0a2163bbf88ab8d73f2ebd57c8b01b69ab5fdaf36534deffaf2df6b57a5", - "mode": "0644", - "size": 4046, - "install": true + "source": "content/Glyph.qml", + "destination": "content/Glyph.qml", + "sha256": "302fb0a2163bbf88ab8d73f2ebd57c8b01b69ab5fdaf36534deffaf2df6b57a5", + "mode": "0644", + "size": 4046, + "install": true }, { "source": "content/InfoRow.qml", @@ -64,9 +64,9 @@ { "source": "content/Panel.qml", "destination": "content/Panel.qml", - "sha256": "0ca1e6e135d1142178b3d104773f8fc0d71d86ced122d3dd71fcf68881705268", + "sha256": "b5c24c61d63e2989155351631e995877afb189abce1d74e871301f79c33dc609", "mode": "0644", - "size": 15288, + "size": 19067, "install": true }, { @@ -80,17 +80,17 @@ { "source": "manifest.json", "destination": "manifest.json", - "sha256": "af8cf7da1c281b130d7973fc1c9ccbea5aba043fbff95d2fc272eb7d65c13b77", + "sha256": "9bcf2e052b76b4b7af06cae8ab8e0889786d8d169d9bbd25607e08f1d146b6ab", "mode": "0644", - "size": 2010, + "size": 2365, "install": true }, { "source": "service/Main.qml", "destination": "service/Main.qml", - "sha256": "02725bbdb386da47fc16c4273137e6da77634b7cd823fb7d7dfe8a108a5a1b7f", + "sha256": "6669bbbb3c39a9dc0689d75b4f133a3d34064e7badbe92900db88f023a74497c", "mode": "0644", - "size": 20304, + "size": 25804, "install": true } ] diff --git a/plugins/vpn/service/Main.qml b/plugins/vpn/service/Main.qml index 0a8cff91..8863a947 100644 --- a/plugins/vpn/service/Main.qml +++ b/plugins/vpn/service/Main.qml @@ -42,6 +42,10 @@ Item { // Whether turning off an exit-node VPN asks first. A UI arm the views honour; // the service only exposes the flag and the exitNodeActive state it keys on. readonly property bool confirmOff: _bool("confirmOff", true) + // Whether to accept subnet routes advertised by tailnet peers. When on, a + // route another node announces is honoured automatically on turn-on and when + // an exit node is picked (tailscale --accept-routes). + readonly property bool acceptRoutes: _bool("acceptRoutes", true) // ── shared nmcli terse-line splitter ───────────────────────────────────── // Split one nmcli terse line on unescaped ':'. Terse mode backslash-escapes @@ -145,7 +149,12 @@ Item { // Raised when a mutation is refused for want of an operator; cleared by // authorise(), which then re-runs the action that tripped it. property bool needsOperator: false - property string _pending: "" // "up" | "down" | "exitoff" + property var _pendingCmd: null // the exact command to retry after authorise + property string _pendingTag: "" // its tag, for the lastAction label + // Peers advertising themselves as exit nodes, for the picker. + // [{id, name, dns, addr, active}] sorted by name; addr is the peer's + // Tailscale IPv4, the value passed to --exit-node. + property var exitNodes: [] function _apply(text) { var j; @@ -171,18 +180,35 @@ Item { ts.tailnet = ct.Name || ""; ts.magicDns = j.MagicDNSSuffix || ""; ts.version = j.Version || ""; - // exit node: ExitNodeStatus.ID resolved against the peer table. + // exit node: ExitNodeStatus.ID resolved against the peer table, plus + // the roster of peers offering themselves as exit nodes, for the picker. var es = j.ExitNodeStatus || null; ts.exitNodeActive = !!es; var en = ""; var peers = j.Peer || ({}); var keys = Object.keys(peers); var online = 0; + var opts = []; for (var k = 0; k < keys.length; k++) { var p = peers[keys[k]]; - if (p && p.Online === true) online++; - if (es && p && p.ID === es.ID) en = p.HostName || ""; + if (!p) continue; + if (p.Online === true) online++; + var isActive = !!(es && p.ID === es.ID); + if (isActive) en = p.HostName || ""; + if (p.ExitNodeOption === true) { + var pips = p.TailscaleIPs || []; + var paddr = ""; + for (var pi = 0; pi < pips.length; pi++) { + if (String(pips[pi]).indexOf(":") < 0) { paddr = pips[pi]; break; } + } + var pdn = p.DNSName || ""; + if (pdn.length > 0 && pdn.charAt(pdn.length - 1) === ".") pdn = pdn.slice(0, -1); + opts.push({ id: p.ID, name: p.HostName || pdn || paddr, + dns: pdn, addr: paddr || pdn, active: isActive }); + } } + opts.sort(function (a, b) { return a.name < b.name ? -1 : (a.name > b.name ? 1 : 0); }); + ts.exitNodes = opts; ts.exitNodeName = en; ts.peersTotal = keys.length; ts.peersOnline = online; @@ -232,16 +258,18 @@ Item { } function _label(tag) { return tag === "up" ? "up" : tag === "down" ? "down" - : tag === "exitoff" ? "exit-node off" : tag; + : tag === "exitoff" ? "exit-node off" + : tag === "exiton" ? "exit-node" + : tag === "routes" ? "accept-routes" : tag; } function _afterAct(code) { var err = String(ts._actErr).trim(); if (code !== 0 && /access denied|--operator|\boperator\b/i.test(err)) { - // Refused for want of an operator: remember what to retry and ask - // the UI to offer AUTHORISE. + // Refused for want of an operator: remember the exact command to + // retry and ask the UI to offer AUTHORISE. ts.needsOperator = true; - if (ts._actTag === "up" || ts._actTag === "down" || ts._actTag === "exitoff") - ts._pending = ts._actTag; + ts._pendingCmd = _act.command; + ts._pendingTag = ts._actTag; svc.lastAction = "tailscale " + ts._label(ts._actTag) + ": needs operator"; } else if (code !== 0) { svc.lastAction = "tailscale " + ts._label(ts._actTag) + ": " @@ -252,9 +280,27 @@ Item { svc._bumpSoon(); } - function turnOn() { ts._run(["tailscale", "up"], "up"); } + // The accept-routes flag, always passed with an explicit value so turning + // the setting off actually clears Tailscale's persisted preference rather + // than leaving a previously-enabled one in force. + function _acceptFlag() { return "--accept-routes=" + (svc.acceptRoutes ? "true" : "false"); } + + function turnOn() { ts._run(["tailscale", "up", ts._acceptFlag()], "up"); } function turnOff() { ts._run(["tailscale", "down"], "down"); } function stopExitNode() { ts._run(["tailscale", "set", "--exit-node="], "exitoff"); } + // Route all traffic through the named peer. addr is its Tailscale IP (the + // most reliable value for --exit-node). LAN access stays on so local + // devices remain reachable, and the accept-routes preference is set + // explicitly to match the acceptRoutes setting. + function useExitNode(addr) { + if (!addr || String(addr).length === 0) return; + ts._run(["tailscale", "set", "--exit-node=" + addr, + "--exit-node-allow-lan-access", ts._acceptFlag()], "exiton"); + } + // Accept (or stop accepting) subnet routes advertised by tailnet peers. + function setAcceptRoutes(on) { + ts._run(["tailscale", "set", "--accept-routes=" + (on ? "true" : "false")], "routes"); + } // The one privileged action, from the panel's AUTHORISE tap only: set // this user as the operator so future up/down need no root. pkexec asks @@ -276,11 +322,10 @@ Item { if (code === 0) { ts.needsOperator = false; svc.lastAction = "operator set; retrying"; - var p = ts._pending; - ts._pending = ""; - if (p === "up") ts.turnOn(); - else if (p === "down") ts.turnOff(); - else if (p === "exitoff") ts.stopExitNode(); + var cmd = ts._pendingCmd, tag = ts._pendingTag; + ts._pendingCmd = null; + ts._pendingTag = ""; + if (cmd) ts._run(cmd, tag); svc._bumpSoon(); } else { svc.lastAction = "authorise cancelled"; @@ -291,6 +336,57 @@ Item { // clipboard selection or a browser handle. function copyIp() { if (ts.ip4.length > 0) Quickshell.execDetached(["wl-copy", ts.ip4]); } function openAdmin() { Quickshell.execDetached(["xdg-open", "https://login.tailscale.com/admin/machines"]); } + + // Clean restart, in two steps so only the daemon restart needs root: + // 1) non-privileged teardown — clear the exit node and bring Tailscale + // down (the operator is allowed to, so no password here); + // 2) privileged restart of tailscaled through the ryoku-host init seam + // (edition-agnostic: systemd, dinit, …) — tears down and rebuilds the + // policy-routing table and the ts-* firewall chains from scratch, so no + // stale route survives a killed session. pkexec asks once. + // The down in step 1 lands before the restart, so the daemon comes back + // with wantRunning=false and stays cleanly off. + property string _resetDownErr: "" + property Process _resetDown: Process { + // non-privileged; `&&` so a failed clear skips the down and the exit + // code reflects the first failure. stderr is kept, not discarded. + command: ["sh", "-c", "tailscale set --exit-node= && tailscale down"] + stderr: StdioCollector { onStreamFinished: ts._resetDownErr = text } + onExited: (code) => { + if (code !== 0) { + // Teardown failed — do NOT restart the daemon, or it would come + // back up with the old exit node while we falsely report "ok". + var e = String(ts._resetDownErr).trim(); + if (/access denied|--operator|\boperator\b/i.test(e)) { + ts.needsOperator = true; + svc.lastAction = "clean restart: teardown needs operator"; + } else { + svc.lastAction = "clean restart: teardown failed" + + (e.length > 0 ? " — " + e.split("\n")[0] : ""); + } + svc._bumpSoon(); + return; + } + ts._resetRestart.running = true; + } + } + property string _resetErr: "" + property Process _resetRestart: Process { + command: ["pkexec", "ryoku-host", "svc", "--system", "restart", "tailscaled"] + stderr: StdioCollector { onStreamFinished: ts._resetErr = text } + onExited: (code) => { + var e = String(ts._resetErr).trim(); + svc.lastAction = code === 0 ? "clean restart: ok" + : (e.length > 0 ? "clean restart: " + e.split("\n")[0] + : "clean restart cancelled"); + svc._bumpSoon(); + } + } + function resetClean() { + if (_resetDown.running || _resetRestart.running) return; + ts._resetErr = ""; + _resetDown.running = true; + } } // ── NetworkManager backend ───────────────────────────────────────────────