mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-23 04:09:49 +00:00
Fix MITM window
This commit is contained in:
@@ -17,6 +17,7 @@ export default function MitmServerCard({ apiKeys, cloudEnabled, onStatusChange }
|
||||
const [pendingAction, setPendingAction] = useState(null); // "start" | "stop"
|
||||
|
||||
const isWindows = typeof navigator !== "undefined" && navigator.userAgent?.includes("Windows");
|
||||
const isAdmin = status?.isAdmin !== false; // default true until status loaded
|
||||
|
||||
useEffect(() => {
|
||||
if (apiKeys?.length > 0 && !selectedApiKey) {
|
||||
@@ -188,7 +189,7 @@ export default function MitmServerCard({ apiKeys, cloudEnabled, onStatusChange }
|
||||
{/* Action button */}
|
||||
<div className="flex items-center gap-2 flex-wrap" data-i18n-skip="true">
|
||||
{/* Trust Cert button — only when cert exists but not trusted */}
|
||||
{status?.certExists && !status?.certTrusted && !isRunning && (
|
||||
{status?.certExists && !status?.certTrusted && (
|
||||
<button
|
||||
onClick={() => handleAction("trust-cert")}
|
||||
disabled={loading}
|
||||
@@ -210,7 +211,7 @@ export default function MitmServerCard({ apiKeys, cloudEnabled, onStatusChange }
|
||||
) : (
|
||||
<button
|
||||
onClick={() => handleAction("start")}
|
||||
disabled={loading}
|
||||
disabled={loading || (isWindows && !isAdmin)}
|
||||
className="px-4 py-1.5 rounded-lg bg-primary/10 border border-primary/30 text-primary font-medium text-xs flex items-center gap-1.5 hover:bg-primary/20 transition-colors disabled:opacity-50"
|
||||
>
|
||||
<span className="material-symbols-outlined text-[16px]">play_circle</span>
|
||||
@@ -223,10 +224,10 @@ export default function MitmServerCard({ apiKeys, cloudEnabled, onStatusChange }
|
||||
</div>
|
||||
|
||||
{/* Windows admin warning */}
|
||||
{!isRunning && isWindows && (
|
||||
<div className="flex items-center gap-2 px-2 py-1.5 rounded text-xs bg-yellow-500/10 text-yellow-600 border border-yellow-500/20">
|
||||
<span className="material-symbols-outlined text-[14px]">warning</span>
|
||||
<span>Windows: Run 9Router terminal as Administrator</span>
|
||||
{isWindows && !isAdmin && (
|
||||
<div className="flex items-center gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600 border border-red-500/20">
|
||||
<span className="material-symbols-outlined text-[14px]">shield_lock</span>
|
||||
<span>Administrator required — restart 9Router as Administrator to use MITM</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -23,6 +23,16 @@ function getPassword(provided) {
|
||||
return provided || getCachedPassword() || null;
|
||||
}
|
||||
|
||||
function checkIsAdmin() {
|
||||
if (!isWin) return true;
|
||||
try {
|
||||
require("child_process").execSync("net session >nul 2>&1", { windowsHide: true });
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// GET - Full MITM status (server + per-tool DNS)
|
||||
export async function GET() {
|
||||
try {
|
||||
@@ -34,6 +44,7 @@ export async function GET() {
|
||||
certTrusted: status.certTrusted || false,
|
||||
dnsStatus: status.dnsStatus || {},
|
||||
hasCachedPassword: !!getCachedPassword(),
|
||||
isAdmin: checkIsAdmin(),
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("Error getting MITM status:", error.message);
|
||||
|
||||
@@ -162,7 +162,7 @@ export async function GET() {
|
||||
} catch {
|
||||
// Try loading from global node_modules (user ran: npm i better-sqlite3 -g)
|
||||
try {
|
||||
const globalRoot = execSync("npm root -g", { timeout: 5000 }).toString().trim();
|
||||
const globalRoot = execSync("npm root -g", { timeout: 5000, windowsHide: true }).toString().trim();
|
||||
const requireGlobal = createRequire(join(globalRoot, "better-sqlite3", "package.json"));
|
||||
Database = requireGlobal("better-sqlite3");
|
||||
} catch { /* fall through to sqlite3 CLI strategy */ }
|
||||
|
||||
Reference in New Issue
Block a user