mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-23 04:09:49 +00:00
Refactor execSync and spawn calls to include windowsHide option for better compatibility on Windows environments.
This commit is contained in:
@@ -29,10 +29,10 @@ function checkCertInstalledMac(certPath) {
|
||||
try {
|
||||
const fingerprint = getCertFingerprint(certPath).replace(/:/g, "");
|
||||
// security verify-cert returns 0 only if cert is trusted by system policy
|
||||
exec(`security verify-cert -c "${certPath}" -p ssl -k /Library/Keychains/System.keychain 2>/dev/null`, (error) => {
|
||||
exec(`security verify-cert -c "${certPath}" -p ssl -k /Library/Keychains/System.keychain 2>/dev/null`, { windowsHide: true }, (error) => {
|
||||
if (!error) return resolve(true);
|
||||
// Fallback: check if fingerprint appears in System keychain with trust
|
||||
exec(`security dump-trust-settings -d 2>/dev/null | grep -i "${fingerprint}"`, (err2, stdout2) => {
|
||||
exec(`security dump-trust-settings -d 2>/dev/null | grep -i "${fingerprint}"`, { windowsHide: true }, (err2, stdout2) => {
|
||||
resolve(!err2 && !!stdout2?.trim());
|
||||
});
|
||||
});
|
||||
|
||||
@@ -63,7 +63,7 @@ function executeElevatedPowerShell(psScriptPath, timeoutMs = 30000) {
|
||||
function isSudoAvailable() {
|
||||
if (IS_WIN) return false;
|
||||
try {
|
||||
execSync("command -v sudo", { stdio: "ignore" });
|
||||
execSync("command -v sudo", { stdio: "ignore", windowsHide: true });
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
@@ -78,8 +78,8 @@ function execWithPassword(command, password) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const useSudo = isSudoAvailable();
|
||||
const child = useSudo
|
||||
? spawn("sudo", ["-S", "sh", "-c", command], { stdio: ["pipe", "pipe", "pipe"] })
|
||||
: spawn("sh", ["-c", command], { stdio: ["ignore", "pipe", "pipe"] });
|
||||
? spawn("sudo", ["-S", "sh", "-c", command], { stdio: ["pipe", "pipe", "pipe"], windowsHide: true })
|
||||
: spawn("sh", ["-c", command], { stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
|
||||
|
||||
let stdout = "";
|
||||
let stderr = "";
|
||||
|
||||
+7
-6
@@ -76,7 +76,7 @@ function getProcessUsingPort443() {
|
||||
if (processMatch) return processMatch[1].replace(".exe", "");
|
||||
}
|
||||
} else {
|
||||
const result = execSync("lsof -i :443", { encoding: "utf8" });
|
||||
const result = execSync("lsof -i :443", { encoding: "utf8", windowsHide: true });
|
||||
const lines = result.trim().split("\n");
|
||||
if (lines.length > 1) return lines[1].split(/\s+/)[0];
|
||||
}
|
||||
@@ -110,9 +110,9 @@ function killProcess(pid, force = false, sudoPassword = null) {
|
||||
const cmd = `pkill -${sig} -P ${pid} 2>/dev/null; kill -${sig} ${pid} 2>/dev/null`;
|
||||
if (sudoPassword) {
|
||||
const { execWithPassword } = require("./dns/dnsConfig");
|
||||
execWithPassword(cmd, sudoPassword).catch(() => exec(cmd, () => { }));
|
||||
execWithPassword(cmd, sudoPassword).catch(() => exec(cmd, { windowsHide: true }, () => { }));
|
||||
} else {
|
||||
exec(cmd, () => { });
|
||||
exec(cmd, { windowsHide: true }, () => { });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -216,7 +216,7 @@ function getPort443Owner(sudoPassword) {
|
||||
});
|
||||
});
|
||||
} else {
|
||||
exec(`ps aux | grep "[s]erver.js"`, (err, stdout) => {
|
||||
exec(`ps aux | grep "[s]erver.js"`, { windowsHide: true }, (err, stdout) => {
|
||||
if (!stdout?.trim()) return resolve(null);
|
||||
for (const line of stdout.split("\n")) {
|
||||
const parts = line.trim().split(/\s+/);
|
||||
@@ -252,7 +252,7 @@ async function killLeftoverMitm(sudoPassword) {
|
||||
const { execWithPassword } = require("./dns/dnsConfig");
|
||||
await execWithPassword(`pkill -SIGKILL -f "${escaped}" 2>/dev/null || true`, sudoPassword).catch(() => { });
|
||||
} else {
|
||||
exec(`pkill -SIGKILL -f "${escaped}" 2>/dev/null || true`, () => { });
|
||||
exec(`pkill -SIGKILL -f "${escaped}" 2>/dev/null || true`, { windowsHide: true }, () => { });
|
||||
}
|
||||
await new Promise(r => setTimeout(r, 500));
|
||||
} catch { /* ignore */ }
|
||||
@@ -489,7 +489,7 @@ async function startServer(apiKey, sudoPassword) {
|
||||
].join(" ");
|
||||
serverProcess = spawn(
|
||||
"sudo", ["-S", "-E", "sh", "-c", inlineCmd],
|
||||
{ detached: false, stdio: ["pipe", "pipe", "pipe"] }
|
||||
{ detached: false, windowsHide: true, stdio: ["pipe", "pipe", "pipe"] }
|
||||
);
|
||||
serverProcess.stdin.write(`${sudoPassword}\n`);
|
||||
serverProcess.stdin.end();
|
||||
@@ -497,6 +497,7 @@ async function startServer(apiKey, sudoPassword) {
|
||||
// Docker/minimal images: no sudo — same as Windows-style direct spawn
|
||||
serverProcess = spawn(process.execPath, [SERVER_PATH], {
|
||||
detached: false,
|
||||
windowsHide: true,
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
env: {
|
||||
...process.env,
|
||||
|
||||
+1
-1
@@ -222,7 +222,7 @@ const server = https.createServer(sslOptions, async (req, res) => {
|
||||
// Kill any process occupying LOCAL_PORT before binding
|
||||
function killPort(port) {
|
||||
try {
|
||||
const pids = execSync(`lsof -ti :${port}`, { encoding: "utf-8" }).trim();
|
||||
const pids = execSync(`lsof -ti :${port}`, { encoding: "utf-8", windowsHide: true }).trim();
|
||||
if (!pids) return;
|
||||
const pidList = pids.split("\n");
|
||||
pidList.forEach(pid => {
|
||||
|
||||
Reference in New Issue
Block a user