mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-16 20:22:21 +03:00
fix(cli): per-agent DNS, startup guards, and batched Windows hosts writes (#6338)
DNS toggle in AgentBridge was broken for 8 of 9 agents: addDNSEntry/ removeDNSEntry always resolved the legacy Antigravity default hosts regardless of which agent's dns_enabled flag was flipped. Both now accept an optional agentId and resolve hosts via ALL_TARGETS; the [id]/dns route passes id through and returns 404 for an unknown agent instead of silently falling back to the defaults. startMitmInternal() now wraps generateCert(), the provisionDnsEntries() call, and the PID-file write in try/catch so a mid-startup failure can't orphan the already-spawned MITM child process. On Windows, addDNSEntries/removeDNSEntries batch every missing/present entry into a single elevated PowerShell invocation instead of one UAC prompt per host line. Scope note: this PR originally bundled an unrelated SkillOpt feature (DB migration, 6 API routes, dashboard UI) and a checks-free CI build workflow alongside this DNS/startup fix. Both were dropped here as out-of-scope per review-group-prs analysis (2-implementing plan); only the DNS/startup-guard delta (dnsConfig.ts, manager.ts, the [id]/dns route, and their tests) is applied. Co-authored-by: hamsa0x7 <hamsa0x7@users.noreply.github.com> Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
This commit is contained in:
@@ -11,6 +11,7 @@ import { upsertAgentBridgeState } from "@/lib/db/agentBridgeState";
|
||||
import { getCachedPassword } from "@/mitm/manager";
|
||||
import { sanitizeErrorMessage } from "@omniroute/open-sse/utils/error";
|
||||
import { createErrorResponse } from "@/lib/api/errorResponse";
|
||||
import { ALL_TARGETS } from "@/mitm/targets/index";
|
||||
|
||||
type Params = { params: { id: string } };
|
||||
|
||||
@@ -33,6 +34,12 @@ export async function POST(request: Request, { params }: Params): Promise<Respon
|
||||
});
|
||||
}
|
||||
|
||||
// Validate the agent ID maps to a known target.
|
||||
const target = ALL_TARGETS.find((t) => t.id === id);
|
||||
if (!target) {
|
||||
return createErrorResponse({ status: 404, message: `Unknown agent: ${id}` });
|
||||
}
|
||||
|
||||
const { enabled } = parsed.data;
|
||||
const raw = body as Record<string, unknown>;
|
||||
const sudoPassword =
|
||||
@@ -40,9 +47,9 @@ export async function POST(request: Request, { params }: Params): Promise<Respon
|
||||
|
||||
try {
|
||||
if (enabled) {
|
||||
await addDNSEntry(sudoPassword);
|
||||
await addDNSEntry(sudoPassword, id);
|
||||
} else {
|
||||
await removeDNSEntry(sudoPassword);
|
||||
await removeDNSEntry(sudoPassword, id);
|
||||
}
|
||||
|
||||
upsertAgentBridgeState({ agent_id: id, dns_enabled: enabled });
|
||||
|
||||
Reference in New Issue
Block a user