Refactor Tunnel
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
}
|
||||
@@ -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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user