fix(tunnel): detect system-installed Tailscale via dual-socket probe
Tailscale installed via apt/snap/brew was reported "Not Installed/Logged In" because 9Router only probed its custom userspace socket. Probe the system socket (/var/run/tailscale/tailscaled.sock) as fallback, add /usr/sbin and /snap/bin to candidate paths and EXTENDED_PATH, and report separate customDaemonRunning/systemDaemonRunning flags. Caching/non-blocking behavior preserved. Co-authored-by: Stefan Pirker <stefan.pirker86@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,11 +2,11 @@ import os from "os";
|
||||
import { exec } from "child_process";
|
||||
import { promisify } from "util";
|
||||
import { NextResponse } from "next/server";
|
||||
import { isTailscaleInstalled, isTailscaleLoggedIn, TAILSCALE_SOCKET } from "@/lib/tunnel";
|
||||
import { isTailscaleInstalled, isTailscaleLoggedIn, isSystemDaemonRunning, getTailscaleBin, TAILSCALE_SOCKET } from "@/lib/tunnel";
|
||||
import { getCachedPassword, loadEncryptedPassword } from "@/mitm/manager";
|
||||
|
||||
const execAsync = promisify(exec);
|
||||
const EXTENDED_PATH = `/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin:${process.env.PATH || ""}`;
|
||||
const EXTENDED_PATH = `/usr/local/bin:/opt/homebrew/bin:/usr/sbin:/usr/bin:/bin:/snap/bin:${process.env.PATH || ""}`;
|
||||
const PROBE_TIMEOUT_MS = 1500;
|
||||
|
||||
async function hasBrew() {
|
||||
@@ -16,9 +16,11 @@ async function hasBrew() {
|
||||
} catch { return false; }
|
||||
}
|
||||
|
||||
async function isDaemonRunning() {
|
||||
async function isCustomDaemonRunning() {
|
||||
const bin = getTailscaleBin();
|
||||
if (!bin) return false;
|
||||
try {
|
||||
await execAsync(`tailscale --socket ${TAILSCALE_SOCKET} status --json`, {
|
||||
await execAsync(`"${bin}" --socket ${TAILSCALE_SOCKET} status --json`, {
|
||||
windowsHide: true,
|
||||
env: { ...process.env, PATH: EXTENDED_PATH },
|
||||
timeout: PROBE_TIMEOUT_MS
|
||||
@@ -37,13 +39,15 @@ export async function GET() {
|
||||
const installed = isTailscaleInstalled();
|
||||
const platform = os.platform();
|
||||
// Run independent probes in parallel — none blocks the event loop
|
||||
const [brewAvailable, daemonRunning] = await Promise.all([
|
||||
const [brewAvailable, customDaemonRunning, systemDaemonRunning] = await Promise.all([
|
||||
platform === "darwin" ? hasBrew() : Promise.resolve(false),
|
||||
installed ? isDaemonRunning() : Promise.resolve(false),
|
||||
installed ? isCustomDaemonRunning() : Promise.resolve(false),
|
||||
installed ? Promise.resolve(isSystemDaemonRunning()) : Promise.resolve(false),
|
||||
]);
|
||||
const daemonRunning = customDaemonRunning || systemDaemonRunning;
|
||||
const loggedIn = daemonRunning ? isTailscaleLoggedIn() : false;
|
||||
const hasCachedPassword = !!(getCachedPassword() || await loadEncryptedPassword());
|
||||
return NextResponse.json({ installed, loggedIn, platform, brewAvailable, daemonRunning, hasCachedPassword });
|
||||
return NextResponse.json({ installed, loggedIn, platform, brewAvailable, daemonRunning, customDaemonRunning, systemDaemonRunning, hasCachedPassword });
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user