Fix : MITM

This commit is contained in:
decolua
2026-03-14 23:59:22 +07:00
parent f264bb9a23
commit 1dd5d60724
10 changed files with 151 additions and 65 deletions
@@ -55,7 +55,19 @@ export default function MitmServerCard({ apiKeys, cloudEnabled, onStatusChange }
setLoading(true);
setMessage(null);
try {
if (action === "start") {
if (action === "trust-cert") {
const res = await fetch("/api/cli-tools/antigravity-mitm", {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ action: "trust-cert", sudoPassword: password }),
});
const data = await res.json();
if (res.ok) {
setMessage({ type: "success", text: "Certificate trusted successfully" });
} else {
setMessage({ type: "error", text: data.error || "Failed to trust certificate" });
}
} else if (action === "start") {
const keyToUse = selectedApiKey?.trim()
|| (apiKeys?.length > 0 ? apiKeys[0].key : null)
|| (!cloudEnabled ? "sk_9router" : null);
@@ -120,14 +132,15 @@ export default function MitmServerCard({ apiKeys, cloudEnabled, onStatusChange }
<Badge variant="default" size="sm">Stopped</Badge>
)}
</div>
<div className="flex items-center gap-1 text-xs text-text-muted">
<div className="flex items-center gap-1 text-xs text-text-muted" data-i18n-skip="true">
{[
{ label: "Cert", ok: status?.certExists },
{ label: "Trusted", ok: status?.certTrusted },
{ label: "Server", ok: isRunning },
].map(({ label, ok }) => (
<span key={label} className={`flex items-center gap-0.5 px-1.5 py-0.5 rounded ${ok ? "text-green-600" : "text-text-muted"}`}>
<span className={`material-symbols-outlined text-[12px]`}>
{ok ? "check_circle" : "radio_button_unchecked"}
<span className="material-symbols-outlined text-[12px]">
{ok ? "check_circle" : "cancel"}
</span>
{label}
</span>
@@ -173,7 +186,18 @@ export default function MitmServerCard({ apiKeys, cloudEnabled, onStatusChange }
)}
{/* Action button */}
<div className="flex items-center gap-2" data-i18n-skip="true">
<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 && (
<button
onClick={() => handleAction("trust-cert")}
disabled={loading}
className="px-4 py-1.5 rounded-lg bg-yellow-500/10 border border-yellow-500/30 text-yellow-600 font-medium text-xs flex items-center gap-1.5 hover:bg-yellow-500/20 transition-colors disabled:opacity-50"
>
<span className="material-symbols-outlined text-[16px]">verified_user</span>
Trust Cert
</button>
)}
{isRunning ? (
<button
onClick={() => handleAction("stop")}
@@ -109,7 +109,8 @@ export default function MitmToolCard({
if (action === "enable") {
setMessage({
type: "success",
text: `DNS enabled successfully. Please restart ${tool.name} to apply changes.`,
text: "DNS enabled successfully.",
warning: `Please restart ${tool.name} to apply changes.`,
});
} else {
setMessage({
@@ -185,9 +186,17 @@ export default function MitmToolCard({
</div>
{message && (
<div className={`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${message.type === "success" ? "bg-green-500/10 text-green-600" : "bg-red-500/10 text-red-600"}`}>
<span className="material-symbols-outlined text-[14px]">{message.type === "success" ? "check_circle" : "error"}</span>
<span>{message.text}</span>
<div className="flex flex-col gap-1">
<div className={`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${message.type === "success" ? "bg-green-500/10 text-green-600" : "bg-red-500/10 text-red-600"}`}>
<span className="material-symbols-outlined text-[14px]">{message.type === "success" ? "check_circle" : "error"}</span>
<span>{message.text}</span>
</div>
{message.warning && (
<div className="flex items-center gap-2 px-2 py-1.5 rounded text-xs bg-amber-500/10 text-amber-600 border border-amber-500/20">
<span className="material-symbols-outlined text-[14px]">warning</span>
<span className="font-medium">{message.warning}</span>
</div>
)}
</div>
)}
@@ -7,6 +7,7 @@ import {
stopServer,
enableToolDNS,
disableToolDNS,
trustCert,
getCachedPassword,
setCachedPassword,
loadEncryptedPassword,
@@ -30,6 +31,7 @@ export async function GET() {
running: status.running,
pid: status.pid || null,
certExists: status.certExists || false,
certTrusted: status.certTrusted || false,
dnsStatus: status.dnsStatus || {},
hasCachedPassword: !!getCachedPassword(),
});
@@ -100,8 +102,13 @@ export async function PATCH(request) {
await enableToolDNS(tool, pwd);
} else if (action === "disable") {
await disableToolDNS(tool, pwd);
} else if (action === "trust-cert") {
await trustCert(pwd);
if (!isWin && sudoPassword) setCachedPassword(sudoPassword);
const status = await getMitmStatus();
return NextResponse.json({ success: true, certTrusted: status.certTrusted });
} else {
return NextResponse.json({ error: "action must be enable or disable" }, { status: 400 });
return NextResponse.json({ error: "action must be enable, disable, or trust-cert" }, { status: 400 });
}
if (!isWin && sudoPassword) setCachedPassword(sudoPassword);