[fix] fix mitm for docker and enhance dockerfile (#381)

* [fix] macos

* chore: clean up .gitignore by removing unnecessary start.sh entry

---------

Co-authored-by: lokinh <locnh@uniultra.xyz>
This commit is contained in:
Loc Nguyen Huu
2026-03-23 09:23:14 +07:00
committed by GitHub
co-authored by lokinh
parent 4d7ddbfffe
commit 8c0b4a3e84
6 changed files with 66 additions and 20 deletions
+23 -7
View File
@@ -1,4 +1,4 @@
const { exec, spawn } = require("child_process");
const { exec, spawn, execSync } = require("child_process");
const fs = require("fs");
const path = require("path");
const os = require("os");
@@ -59,14 +59,27 @@ function executeElevatedPowerShell(psScriptPath, timeoutMs = 30000) {
});
}
/** True when `sudo` exists (e.g. missing on minimal Docker images like Alpine). */
function isSudoAvailable() {
if (IS_WIN) return false;
try {
execSync("command -v sudo", { stdio: "ignore" });
return true;
} catch {
return false;
}
}
/**
* Execute command with sudo password via stdin (macOS/Linux only)
* Execute command with sudo password via stdin (macOS/Linux only).
* Without sudo in PATH (containers), runs via sh — same user, no elevation.
*/
function execWithPassword(command, password) {
return new Promise((resolve, reject) => {
const child = spawn("sudo", ["-S", "sh", "-c", command], {
stdio: ["pipe", "pipe", "pipe"]
});
const useSudo = isSudoAvailable();
const child = useSudo
? spawn("sudo", ["-S", "sh", "-c", command], { stdio: ["pipe", "pipe", "pipe"] })
: spawn("sh", ["-c", command], { stdio: ["ignore", "pipe", "pipe"] });
let stdout = "";
let stderr = "";
@@ -78,8 +91,10 @@ function execWithPassword(command, password) {
else reject(new Error(stderr || `Exit code ${code}`));
});
child.stdin.write(`${password}\n`);
child.stdin.end();
if (useSudo) {
child.stdin.write(`${password}\n`);
child.stdin.end();
}
});
}
@@ -212,6 +227,7 @@ module.exports = {
removeDNSEntry,
removeAllDNSEntries,
execWithPassword,
isSudoAvailable,
executeElevatedPowerShell,
checkDNSEntry,
checkAllDNSStatus,