Refactor Tunnel

This commit is contained in:
decolua
2026-05-25 16:15:34 +07:00
parent 96a9a2b36d
commit b876e0225a
35 changed files with 642 additions and 574 deletions

View File

@@ -1,5 +1,5 @@
import { NextResponse } from "next/server";
import { disableTunnel } from "@/lib/tunnel/tunnelManager";
import { disableTunnel } from "@/lib/tunnel";
export async function POST() {
try {

View File

@@ -1,5 +1,5 @@
import { NextResponse } from "next/server";
import { enableTunnel } from "@/lib/tunnel/tunnelManager";
import { enableTunnel } from "@/lib/tunnel";
const DNS_WARMUP_DELAY_MS = 8000;

View File

@@ -1,6 +1,5 @@
import { NextResponse } from "next/server";
import { getTunnelStatus, getTailscaleStatus } from "@/lib/tunnel/tunnelManager";
import { getDownloadStatus } from "@/lib/tunnel/cloudflared";
import { getTunnelStatus, getTailscaleStatus, getDownloadStatus } from "@/lib/tunnel";
export async function GET() {
try {

View File

@@ -2,7 +2,7 @@ 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/tailscale";
import { isTailscaleInstalled, isTailscaleLoggedIn, TAILSCALE_SOCKET } from "@/lib/tunnel";
import { getCachedPassword, loadEncryptedPassword } from "@/mitm/manager";
const execAsync = promisify(exec);

View File

@@ -1,5 +1,5 @@
import { NextResponse } from "next/server";
import { disableTailscale } from "@/lib/tunnel/tunnelManager";
import { disableTailscale } from "@/lib/tunnel";
export async function POST() {
try {

View File

@@ -1,5 +1,5 @@
import { NextResponse } from "next/server";
import { enableTailscale } from "@/lib/tunnel/tunnelManager";
import { enableTailscale } from "@/lib/tunnel";
export async function POST() {
try {

View File

@@ -2,10 +2,9 @@
import os from "os";
import { execSync } from "child_process";
import { installTailscale } from "@/lib/tunnel/tailscale";
import { installTailscale, loadState, generateShortId } from "@/lib/tunnel";
import { getCachedPassword, loadEncryptedPassword, initDbHooks } from "@/mitm/manager";
import { getSettings, updateSettings } from "@/lib/localDb";
import { loadState, generateShortId } from "@/lib/tunnel/state.js";
initDbHooks(getSettings, updateSettings);

View File

@@ -1,14 +0,0 @@
import { NextResponse } from "next/server";
import { startLogin } from "@/lib/tunnel/tailscale";
import { loadState, generateShortId } from "@/lib/tunnel/state.js";
export async function POST() {
try {
const shortId = loadState()?.shortId || generateShortId();
const result = await startLogin(shortId);
return NextResponse.json(result);
} catch (error) {
console.error("Tailscale login error:", error);
return NextResponse.json({ error: error.message }, { status: 500 });
}
}

View File

@@ -1,21 +0,0 @@
"use server";
import { NextResponse } from "next/server";
import { startDaemonWithPassword } from "@/lib/tunnel/tailscale";
import { getCachedPassword, loadEncryptedPassword, initDbHooks } from "@/mitm/manager";
import { getSettings, updateSettings } from "@/lib/localDb";
initDbHooks(getSettings, updateSettings);
export async function POST(request) {
try {
const body = await request.json().catch(() => ({}));
// Use provided password, or fall back to cached/stored MITM password
const password = body.sudoPassword || getCachedPassword() || await loadEncryptedPassword() || "";
await startDaemonWithPassword(password);
return NextResponse.json({ success: true });
} catch (error) {
console.error("Tailscale start daemon error:", error);
return NextResponse.json({ error: error.message }, { status: 500 });
}
}