mirror of
https://github.com/decolua/9router.git
synced 2026-05-08 12:01:28 +00:00
Refactor cloudflared process management to improve port-specific termination and enhance tunnel management. Update Antigravity cloaking comments for clarity.
This commit is contained in:
@@ -140,12 +140,14 @@ export function translateRequest(sourceFormat, targetFormat, model, body, stream
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Antigravity cloaking/tool stripping is intentionally disabled for GitHub Copilot.
|
// Antigravity cloaking disabled
|
||||||
// Keep the translated request intact; final provider-specific sanitization happens
|
// if (provider === FORMATS.ANTIGRAVITY && body.userAgent !== FORMATS.ANTIGRAVITY) {
|
||||||
// in the Antigravity executor.
|
// const { cloakedBody, toolNameMap } = AntigravityExecutor.cloakTools(result);
|
||||||
if (provider === FORMATS.ANTIGRAVITY && clientTool === "github-copilot") {
|
// result = cloakedBody;
|
||||||
// No-op
|
// if (toolNameMap?.size > 0) {
|
||||||
}
|
// result._toolNameMap = toolNameMap;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -360,7 +360,21 @@ export async function spawnQuickTunnel(localPort, onUrlUpdate) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function killCloudflared() {
|
// Kill cloudflared processes whose command line targets the given port (any host).
|
||||||
|
// Boundary check ensures :20128 doesn't match :201280 or :202128.
|
||||||
|
function killCloudflaredByPort(port) {
|
||||||
|
if (!port) return;
|
||||||
|
try {
|
||||||
|
if (IS_WINDOWS) {
|
||||||
|
const psCmd = `Get-CimInstance Win32_Process -Filter \\"Name='cloudflared.exe'\\" | Where-Object { $_.CommandLine -match ':${port}(\\D|$)' } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force }`;
|
||||||
|
execSync(`powershell -NoProfile -Command "${psCmd}"`, { stdio: "ignore", windowsHide: true });
|
||||||
|
} else {
|
||||||
|
execSync(`pkill -f "cloudflared.*:${port}([^0-9]|$)" 2>/dev/null || true`, { stdio: "ignore", windowsHide: true });
|
||||||
|
}
|
||||||
|
} catch (e) { /* ignore */ }
|
||||||
|
}
|
||||||
|
|
||||||
|
export function killCloudflared(localPort) {
|
||||||
if (cloudflaredProcess) {
|
if (cloudflaredProcess) {
|
||||||
try {
|
try {
|
||||||
cloudflaredProcess.kill();
|
cloudflaredProcess.kill();
|
||||||
@@ -376,10 +390,7 @@ export function killCloudflared() {
|
|||||||
clearPid();
|
clearPid();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kill any remaining cloudflared processes
|
killCloudflaredByPort(localPort);
|
||||||
try {
|
|
||||||
execSync("pkill -f cloudflared 2>/dev/null || true", { stdio: "ignore", windowsHide: true });
|
|
||||||
} catch (e) { /* ignore */ }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isCloudflaredRunning() {
|
export function isCloudflaredRunning() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import { loadState, saveState, generateShortId } from "./state.js";
|
import { loadState, saveState, generateShortId } from "./state.js";
|
||||||
import { spawnQuickTunnel, killCloudflared, isCloudflaredRunning, setUnexpectedExitHandler } from "./cloudflared.js";
|
import { spawnQuickTunnel, killCloudflared, isCloudflaredRunning, setUnexpectedExitHandler } from "./cloudflared.js";
|
||||||
import { startFunnel, stopFunnel, stopDaemon, isTailscaleRunning, isTailscaleLoggedIn, startLogin, startDaemonWithPassword } from "./tailscale.js";
|
import { startFunnel, stopFunnel, isTailscaleRunning, isTailscaleLoggedIn, startLogin, startDaemonWithPassword } from "./tailscale.js";
|
||||||
import { getSettings, updateSettings } from "@/lib/localDb";
|
import { getSettings, updateSettings } from "@/lib/localDb";
|
||||||
import { getCachedPassword, loadEncryptedPassword, initDbHooks } from "@/mitm/manager";
|
import { getCachedPassword, loadEncryptedPassword, initDbHooks } from "@/mitm/manager";
|
||||||
|
|
||||||
@@ -16,6 +16,7 @@ let isReconnecting = false;
|
|||||||
let exitHandlerRegistered = false;
|
let exitHandlerRegistered = false;
|
||||||
let reconnectTimeoutId = null;
|
let reconnectTimeoutId = null;
|
||||||
let manualDisabled = false;
|
let manualDisabled = false;
|
||||||
|
let activeLocalPort = null;
|
||||||
|
|
||||||
export function isTunnelManuallyDisabled() {
|
export function isTunnelManuallyDisabled() {
|
||||||
return manualDisabled;
|
return manualDisabled;
|
||||||
@@ -47,6 +48,7 @@ async function registerTunnelUrl(shortId, tunnelUrl) {
|
|||||||
|
|
||||||
export async function enableTunnel(localPort = 20128) {
|
export async function enableTunnel(localPort = 20128) {
|
||||||
manualDisabled = false;
|
manualDisabled = false;
|
||||||
|
activeLocalPort = localPort;
|
||||||
|
|
||||||
if (isCloudflaredRunning()) {
|
if (isCloudflaredRunning()) {
|
||||||
const existing = loadState();
|
const existing = loadState();
|
||||||
@@ -56,7 +58,7 @@ export async function enableTunnel(localPort = 20128) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
killCloudflared();
|
killCloudflared(localPort);
|
||||||
|
|
||||||
const machineId = getMachineId();
|
const machineId = getMachineId();
|
||||||
const existing = loadState();
|
const existing = loadState();
|
||||||
@@ -125,7 +127,7 @@ export async function disableTunnel() {
|
|||||||
setUnexpectedExitHandler(null);
|
setUnexpectedExitHandler(null);
|
||||||
exitHandlerRegistered = false;
|
exitHandlerRegistered = false;
|
||||||
|
|
||||||
killCloudflared();
|
killCloudflared(activeLocalPort);
|
||||||
|
|
||||||
const state = loadState();
|
const state = loadState();
|
||||||
if (state) {
|
if (state) {
|
||||||
@@ -192,9 +194,8 @@ export async function enableTailscale(localPort = 20128) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function disableTailscale() {
|
export async function disableTailscale() {
|
||||||
|
// Only reset funnel — keep tailscaled daemon running to avoid breaking other apps using Tailscale
|
||||||
stopFunnel();
|
stopFunnel();
|
||||||
const sudoPass = getCachedPassword() || await loadEncryptedPassword() || "";
|
|
||||||
await stopDaemon(sudoPass);
|
|
||||||
await updateSettings({ tailscaleEnabled: false, tailscaleUrl: "" });
|
await updateSettings({ tailscaleEnabled: false, tailscaleUrl: "" });
|
||||||
return { success: true };
|
return { success: true };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user