fix(traffic,server,sandbox): fix TCP/53 false positives, add error-traffic storage toggle, and fix spawn_task/sandbox polling

- Route external TCP/53 through netstack deferred handshake and real-target DNS inspection (RFC 7766 single-write framing) instead of hijacking to host DNS.
- Preserve explicit targetServer in ProcessDNSQueryToTarget under upstream proxy so external UDP/53 probes never fall back to host DNSUpstream.
- Default error traffic storage (net_flows/dns_queries action=error) to off with hot-toggle controls synced across gateway, Proxy & Egress, and Traffic pages.
- Restore json.Unmarshal in spawn_task orchestration tool and poll live sandbox container state in chat/task controls.
This commit is contained in:
ji ruo committed 2026-12-02 15:17:42 +08:00
1 parent 07309e4530
commit d5926d6420
22 files changed
+1189 -101

No files matched your search

@@ -81,22 +81,30 @@ export function SessionSandboxControl({
const [clearWorkspace, setClearWorkspace] = React.useState(false);
const [removeOpen, setRemoveOpen] = React.useState(false);
const reqSeqRef = React.useRef(0);
const fetchInfo = React.useCallback(
async (withStats: boolean) => {
setLoading(true);
async (withStats: boolean, silent = false) => {
const seq = ++reqSeqRef.current;
if (!silent) setLoading(true);
try {
const res = await api.sandboxContainer("session", ownerID, withStats);
setInfo(res);
if (seq === reqSeqRef.current) {
setInfo(res);
}
} catch {
// Ignore transient poll errors; popover refresh button lets user retry.
} finally {
setLoading(false);
if (seq === reqSeqRef.current && !silent) {
setLoading(false);
}
}
},
[ownerID],
);
React.useEffect(() => {
reqSeqRef.current += 1;
setInfo(null);
void fetchInfo(false);
}, [fetchInfo]);
@@ -106,15 +114,42 @@ export function SessionSandboxControl({
void fetchInfo(true);
}, [open, fetchInfo]);
// Refresh container status when a chat turn completes (a tool call may have started it).
// Refresh container status whenever a chat turn starts or completes (tool calls
// lazily create/start the container mid-turn).
const prevRunningRef = React.useRef(chatRunning);
React.useEffect(() => {
if (prevRunningRef.current && !chatRunning) {
void fetchInfo(open);
if (prevRunningRef.current !== chatRunning) {
void fetchInfo(open, true);
}
prevRunningRef.current = chatRunning;
}, [chatRunning, open, fetchInfo]);
// Poll while a chat turn is running (every 2s until the container reports running,
// then every 5s) or while the popover is open so live status never stays stale.
const infoState = info?.state;
React.useEffect(() => {
if (infoState === "local") return;
if (!chatRunning && !open) return;
const intervalMs = chatRunning && infoState !== "running" ? 2000 : 5000;
const timer = window.setInterval(() => {
if (document.visibilityState === "visible") {
void fetchInfo(open, true);
}
}, intervalMs);
return () => window.clearInterval(timer);
}, [chatRunning, open, infoState, fetchInfo]);
React.useEffect(() => {
if (infoState === "local") return;
const onVisibility = () => {
if (document.visibilityState === "visible") {
void fetchInfo(open, true);
}
};
document.addEventListener("visibilitychange", onVisibility);
return () => document.removeEventListener("visibilitychange", onVisibility);
}, [open, infoState, fetchInfo]);
// Hide completely when running in local (non-Docker) mode.
if (!info || info.state === "local") {
return null;
@@ -125,18 +160,21 @@ export function SessionSandboxControl({
let stateLabel = info.state;
if (info.state === "running") stateLabel = L("沙箱运行中", "Sandbox Running");
else if (info.state === "created") stateLabel = L("沙箱启动中", "Sandbox Starting");
else if (info.state === "exited") stateLabel = L("沙箱已停止", "Sandbox Stopped");
else if (info.state === "missing") stateLabel = L("沙箱未创建", "Sandbox Standby");
else if (info.state === "error") stateLabel = L("沙箱异常", "Sandbox Error");
let dotClass = "bg-muted-foreground/50";
if (running) dotClass = "bg-emerald-500";
else if (info.state === "created") dotClass = "bg-amber-500";
else if (info.state === "error") dotClass = "bg-red-500";
const handleStart = async () => {
setBusy("start");
try {
const res = await api.startSandboxContainer("session", ownerID);
reqSeqRef.current += 1;
setInfo(res);
toast.success(L("会话沙箱容器已启动", "Session sandbox container started"));
} catch (e) {
@@ -150,6 +188,7 @@ export function SessionSandboxControl({
setBusy("stop");
try {
const res = await api.stopSandboxContainer("session", ownerID);
reqSeqRef.current += 1;
setInfo(res);
toast.success(L("会话沙箱容器已停止(内存已释放)", "Session sandbox container stopped"));
} catch (e) {
@@ -166,6 +205,7 @@ export function SessionSandboxControl({
setBusy("recreate");
try {
const res = await api.recreateSandboxContainer("session", ownerID, { clear_workspace: wipe });
reqSeqRef.current += 1;
setInfo(res);
toast.success(
wipe
@@ -192,7 +232,6 @@ export function SessionSandboxControl({
setBusy("");
}
};
return (
<>
<Popover open={open} onOpenChange={setOpen}>
@@ -74,22 +74,32 @@ export function TaskSandboxControl({ task, onTaskUpdated }: { task: Task; onTask
const [clearWorkspace, setClearWorkspace] = React.useState(false);
const [removeOpen, setRemoveOpen] = React.useState(false);
const reqSeqRef = React.useRef(0);
const taskRunning = task.status === "running" && !task.paused;
const fetchInfo = React.useCallback(
async (withStats: boolean) => {
setLoading(true);
async (withStats: boolean, silent = false) => {
const seq = ++reqSeqRef.current;
if (!silent) setLoading(true);
try {
const res = await api.taskSandbox(task.id, withStats);
setInfo(res);
if (seq === reqSeqRef.current) {
setInfo(res);
}
} catch {
// Ignore transient poll errors; detail popover lets user retry.
} finally {
setLoading(false);
if (seq === reqSeqRef.current && !silent) {
setLoading(false);
}
}
},
[task.id],
);
React.useEffect(() => {
reqSeqRef.current += 1;
setInfo(null);
void fetchInfo(false);
}, [fetchInfo]);
@@ -98,6 +108,45 @@ export function TaskSandboxControl({ task, onTaskUpdated }: { task: Task; onTask
void fetchInfo(true);
}, [open, fetchInfo]);
// Refresh when task execution state changes (starts container or triggers auto-stop).
const prevTaskRunningRef = React.useRef(taskRunning);
React.useEffect(() => {
const prev = prevTaskRunningRef.current;
prevTaskRunningRef.current = taskRunning;
if (prev === taskRunning) return;
void fetchInfo(open, true);
if (prev && !taskRunning) {
const followUp = window.setTimeout(() => void fetchInfo(open, true), 2000);
return () => window.clearTimeout(followUp);
}
}, [taskRunning, open, fetchInfo]);
// Poll while the task is running (every 2s until the container reports running,
// then every 5s) or while the popover is open so live status stays in sync.
const infoState = info?.state;
React.useEffect(() => {
if (infoState === "local") return;
if (!taskRunning && !open) return;
const intervalMs = taskRunning && infoState !== "running" ? 2000 : 5000;
const timer = window.setInterval(() => {
if (document.visibilityState === "visible") {
void fetchInfo(open, true);
}
}, intervalMs);
return () => window.clearInterval(timer);
}, [taskRunning, open, infoState, fetchInfo]);
React.useEffect(() => {
if (infoState === "local") return;
const onVisibility = () => {
if (document.visibilityState === "visible") {
void fetchInfo(open, true);
}
};
document.addEventListener("visibilitychange", onVisibility);
return () => document.removeEventListener("visibilitychange", onVisibility);
}, [open, infoState, fetchInfo]);
// Hide completely when running in local (non-Docker) mode.
if (!info || info.state === "local") {
return null;
@@ -105,27 +154,24 @@ export function TaskSandboxControl({ task, onTaskUpdated }: { task: Task; onTask
const running = info.state === "running";
const exists = info.state !== "missing";
const taskRunning = task.status === "running" && !task.paused;
const stateLabel = (() => {
switch (info.state) {
case "running":
return L("沙箱运行中", "Sandbox Running");
case "exited":
return L("沙箱已停止", "Sandbox Stopped");
case "missing":
return L("沙箱未创建", "Sandbox Not Created");
case "error":
return L("沙箱异常", "Sandbox Error");
default:
return info.state;
}
})();
let stateLabel = info.state;
if (info.state === "running") stateLabel = L("沙箱运行中", "Sandbox Running");
else if (info.state === "created") stateLabel = L("沙箱启动中", "Sandbox Starting");
else if (info.state === "exited") stateLabel = L("沙箱已停止", "Sandbox Stopped");
else if (info.state === "missing") stateLabel = L("沙箱未创建", "Sandbox Not Created");
else if (info.state === "error") stateLabel = L("沙箱异常", "Sandbox Error");
let dotClass = "bg-muted-foreground/50";
if (running) dotClass = "bg-emerald-500";
else if (info.state === "created") dotClass = "bg-amber-500";
else if (info.state === "error") dotClass = "bg-red-500";
const handleStart = async () => {
setBusy("start");
try {
const res = await api.startTaskSandbox(task.id);
reqSeqRef.current += 1;
setInfo(res);
toast.success(L("沙箱容器已启动", "Sandbox container started"));
} catch (e) {
@@ -148,6 +194,7 @@ export function TaskSandboxControl({ task, onTaskUpdated }: { task: Task; onTask
setBusy("stop");
try {
const res = await api.stopTaskSandbox(task.id, taskRunning);
reqSeqRef.current += 1;
setInfo(res);
toast.success(L("沙箱容器已停止(内存已释放)", "Sandbox container stopped"));
if (taskRunning) onTaskUpdated();
@@ -168,6 +215,7 @@ export function TaskSandboxControl({ task, onTaskUpdated }: { task: Task; onTask
pause_task: taskRunning,
clear_workspace: wipe,
});
reqSeqRef.current += 1;
setInfo(res);
toast.success(
wipe
@@ -203,11 +251,7 @@ export function TaskSandboxControl({ task, onTaskUpdated }: { task: Task; onTask
<PopoverTrigger asChild>
<Button size="sm" variant="outline" className="h-7 gap-1.5 px-2 text-xs">
<BoxIcon className="size-3.5" />
<span
className={`size-1.5 rounded-full ${
running ? "bg-emerald-500" : info.state === "error" ? "bg-red-500" : "bg-muted-foreground/50"
}`}
/>
<span className={`size-1.5 rounded-full ${dotClass}`} />
<span className="hidden sm:inline">{stateLabel}</span>
</Button>
</PopoverTrigger>
@@ -11,6 +11,7 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/com
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { Switch } from "@/components/ui/switch";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import { useLiveTranslation } from "@/i18n/use-live-translation";
import { api } from "@/lib/api";
@@ -60,6 +61,8 @@ export function ContainerRoutesTab({
const [udpPolicy, setUdpPolicy] = React.useState(routesState?.gateway.udp_policy ?? "block_on_proxy");
const [dnsUpstream, setDnsUpstream] = React.useState(routesState?.gateway.dns_upstream ?? "");
const [savingGW, setSavingGW] = React.useState(false);
const [storeErrorTraffic, setStoreErrorTraffic] = React.useState(Boolean(routesState?.gateway.store_error_traffic));
const [savingErrorToggle, setSavingErrorToggle] = React.useState(false);
const [newScope, setNewScope] = React.useState<"task" | "session">("task");
const [newOwnerID, setNewOwnerID] = React.useState("");
@@ -74,13 +77,18 @@ export function ContainerRoutesTab({
if (routesState) {
setUdpPolicy(routesState.gateway.udp_policy || "block_on_proxy");
setDnsUpstream(routesState.gateway.dns_upstream || "");
setStoreErrorTraffic(Boolean(routesState.gateway.store_error_traffic));
}
}, [routesState]);
const saveGatewaySettings = async () => {
setSavingGW(true);
try {
await api.updateGatewaySettings({ udp_policy: udpPolicy, dns_upstream: dnsUpstream.trim() });
await api.updateGatewaySettings({
udp_policy: udpPolicy,
dns_upstream: dnsUpstream.trim(),
store_error_traffic: storeErrorTraffic,
});
await onRefresh();
toast.success(L("透明网关策略已更新并热下发", "Transparent gateway policy updated"));
} catch (e) {
@@ -90,6 +98,26 @@ export function ContainerRoutesTab({
}
};
const toggleStoreErrorTraffic = async (checked: boolean) => {
const prev = storeErrorTraffic;
setStoreErrorTraffic(checked);
setSavingErrorToggle(true);
try {
await api.updateGatewaySettings({ store_error_traffic: checked });
await onRefresh();
toast.success(
checked
? L("已开启错误流量存储(连接失败/DNS 错误将落库)", "Error traffic storage enabled")
: L("已关闭错误流量存储(仅存储正常、透传与拦截流量)", "Error traffic storage disabled (default)"),
);
} catch (e) {
setStoreErrorTraffic(prev);
toast.error(e instanceof Error ? e.message : String(e));
} finally {
setSavingErrorToggle(false);
}
};
const handleAddRoute = async (e: React.FormEvent) => {
e.preventDefault();
const owner = newOwnerID.trim();
@@ -234,6 +262,28 @@ export function ContainerRoutesTab({
</div>
</div>
</div>
<div className="flex items-center justify-between gap-4 rounded-md border bg-muted/20 px-3 py-2.5">
<div className="min-w-0">
<Label htmlFor="gateway-store-error-traffic" className="font-medium text-xs">
{L(
"存储错误流量(TCP/UDP 连接失败、DNS 解析错误)",
"Store Error Traffic (failed TCP/UDP & DNS errors)",
)}
</Label>
<p className="mt-0.5 text-muted-foreground text-xs">
{L(
"默认关闭:放行、透传与黑名单拦截流量默认存储,端口扫描/超时等错误记录不落库。开启后可在「流量」页排查失败连接。",
"Off by default: allowed, passthrough, and blocked flows are stored, while connection/DNS errors are dropped. Enable to inspect failed connections on the Traffic page.",
)}
</p>
</div>
<Switch
id="gateway-store-error-traffic"
checked={storeErrorTraffic}
disabled={savingErrorToggle || savingGW}
onCheckedChange={(checked) => void toggleStoreErrorTraffic(checked)}
/>
</div>
{gw?.last_seen ? (
<p className="font-mono text-muted-foreground text-xs">
{L("网关标识:", "Gateway ID: ")}
+56 -3
View File
@@ -99,6 +99,7 @@ export default function ProxyEgressPage() {
const [newNote, setNewNote] = React.useState("");
const [addingRule, setAddingRule] = React.useState(false);
const [routesState, setRoutesState] = React.useState<ProxyRoutesState | null>(null);
const [savingStoreErrorTraffic, setSavingStoreErrorTraffic] = React.useState(false);
const applySettings = React.useCallback((s: Settings) => {
setGlobalProxyInput(s.global_proxy ?? "");
@@ -141,6 +142,30 @@ export default function ProxyEgressPage() {
setRoutesState(rt);
}, []);
const toggleStoreErrorTraffic = async (checked: boolean) => {
const prev = Boolean(routesState?.gateway.store_error_traffic);
setSavingStoreErrorTraffic(true);
setRoutesState((current) =>
current ? { ...current, gateway: { ...current.gateway, store_error_traffic: checked } } : current,
);
try {
await api.updateGatewaySettings({ store_error_traffic: checked });
await refreshRoutes().catch(() => undefined);
toast.success(
checked
? L("已开启错误流量存储(连接失败/DNS 错误将落库)", "Error traffic storage enabled")
: L("已关闭错误流量存储(仅存储正常、透传与拦截流量)", "Error traffic storage disabled (default)"),
);
} catch (e) {
setRoutesState((current) =>
current ? { ...current, gateway: { ...current.gateway, store_error_traffic: prev } } : current,
);
toast.error(e instanceof Error ? e.message : String(e));
} finally {
setSavingStoreErrorTraffic(false);
}
};
React.useEffect(() => {
void loadAll();
}, [loadAll]);
@@ -465,7 +490,15 @@ export default function ProxyEgressPage() {
</Button>
</div>
<Tabs defaultValue="pool" className="w-full min-w-0 space-y-4">
<Tabs
defaultValue="pool"
onValueChange={(value) => {
if (value === "routes") {
void refreshRoutes().catch(() => undefined);
}
}}
className="w-full min-w-0 space-y-4"
>
<TabsList>
<TabsTrigger value="pool" className="gap-1.5">
<RadioTowerIcon className="size-3.5" />
@@ -585,6 +618,26 @@ export default function ProxyEgressPage() {
/>
</div>
<div className="flex items-center justify-between gap-4 rounded-md border px-3 py-2">
<div className="min-w-0">
<Label htmlFor="proxy-store-error-traffic" className="font-normal text-sm">
{L("存储错误流量", "Store error traffic")}
</Label>
<p className="text-muted-foreground text-xs">
{L(
"默认关闭:仅存储放行、透传与拦截流量,不存储连接失败/超时及 DNS 解析错误;也可在「流量」页随时切换。",
"Off by default: stores allowed, passthrough, and blocked traffic while dropping connection/DNS errors. Also configurable on the Traffic page.",
)}
</p>
</div>
<Switch
id="proxy-store-error-traffic"
checked={Boolean(routesState?.gateway.store_error_traffic)}
disabled={!loaded || savingStoreErrorTraffic}
onCheckedChange={(checked) => void toggleStoreErrorTraffic(checked)}
/>
</div>
<details className="text-xs">
<summary className="cursor-pointer select-none text-muted-foreground">
{t("settings.customProbe")}
@@ -919,8 +972,8 @@ export default function ProxyEgressPage() {
.reverse()
.map((log) => (
<p key={`${log.at}-${log.to}`} className="text-muted-foreground">
{new Date(log.at).toLocaleTimeString(locale)} ·{" "}
{log.from || t("settings.direct")} → {log.to || t("settings.direct")} · {log.reason}
{new Date(log.at).toLocaleTimeString(locale)} · {log.from || t("settings.direct")} →{" "}
{log.to || t("settings.direct")} · {log.reason}
</p>
))}
</div>
+36 -2
View File
@@ -93,7 +93,19 @@ function FlowSourceBadge({
);
}
export function NonHTTPTrafficPanel({ mode, taskId }: { mode: "flows" | "dns"; taskId?: string }) {
export function NonHTTPTrafficPanel({
mode,
taskId,
storeErrorTraffic,
onStoreErrorTrafficSync,
onEnableStoreErrorTraffic,
}: {
mode: "flows" | "dns";
taskId?: string;
storeErrorTraffic?: boolean;
onStoreErrorTrafficSync?: (enabled: boolean) => void;
onEnableStoreErrorTraffic?: () => void;
}) {
const { isEn, locale } = useLiveTranslation();
const L = (zh: string, en: string) => (isEn ? en : zh);
const formatUpstream = (raw?: string) => (!raw || raw === "direct" ? L("直连", "Direct") : raw);
@@ -145,6 +157,9 @@ export function NonHTTPTrafficPanel({ mode, taskId }: { mode: "flows" | "dns"; t
});
setFlows(res.flows ?? []);
setTotal(res.total ?? 0);
if (typeof res.store_error_traffic === "boolean") {
onStoreErrorTrafficSync?.(res.store_error_traffic);
}
} else {
const res = await api.trafficDNS({
qtype: qtypeFilter,
@@ -156,13 +171,16 @@ export function NonHTTPTrafficPanel({ mode, taskId }: { mode: "flows" | "dns"; t
});
setDnsRows(res.queries ?? []);
setTotal(res.total ?? 0);
if (typeof res.store_error_traffic === "boolean") {
onStoreErrorTrafficSync?.(res.store_error_traffic);
}
}
} catch (e) {
toast.error(e instanceof Error ? e.message : String(e));
} finally {
setLoading(false);
}
}, [mode, protoFilter, actionFilter, qtypeFilter, taskId, queryDebounced, page, size]);
}, [mode, protoFilter, actionFilter, qtypeFilter, taskId, queryDebounced, page, size, onStoreErrorTrafficSync]);
React.useEffect(() => {
void load();
@@ -318,6 +336,22 @@ export function NonHTTPTrafficPanel({ mode, taskId }: { mode: "flows" | "dns"; t
</div>
</div>
{actionFilter === "error" && storeErrorTraffic === false ? (
<div className="flex flex-wrap items-center justify-between gap-2 rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 text-xs dark:text-amber-300">
<span>
{L(
"当前未开启错误流量存储,新的连接失败 / DNS 错误不会被落库。",
"Error traffic storage is currently off; new failed connections and DNS errors are not recorded.",
)}
</span>
{onEnableStoreErrorTraffic ? (
<Button size="sm" variant="outline" className="h-7 text-xs" onClick={onEnableStoreErrorTraffic}>
{L("立即开启", "Enable now")}
</Button>
) : null}
</div>
) : null}
{/* Table */}
<Card className="min-h-0 flex-1 overflow-auto p-0">
{mode === "flows" ? (
+71 -8
View File
@@ -39,13 +39,16 @@ import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import { Checkbox } from "@/components/ui/checkbox";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from "@/components/ui/sheet";
import { SortableHead } from "@/components/ui/sortable-head";
import { Switch } from "@/components/ui/switch";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { useLiveTranslation } from "@/i18n/use-live-translation";
import { type UITranslate, useUITranslation } from "@/i18n/use-ui-translation";
import { api } from "@/lib/api";
import { useStoredSortPreference } from "@/lib/sort-preference";
@@ -188,6 +191,8 @@ const STATUS_BUCKETS = ["2xx", "3xx", "4xx", "5xx"];
export function TrafficHistory({ taskId }: { taskId?: string }) {
const { ui, liveUI } = useUITranslation();
const { isEn } = useLiveTranslation();
const L = (zh: string, en: string) => (isEn ? en : zh);
const [protocolTab, setProtocolTab] = React.useState<"http" | "flows" | "dns">("http");
const taskScoped = Boolean(taskId);
@@ -235,6 +240,38 @@ export function TrafficHistory({ taskId }: { taskId?: string }) {
const [deleteMode, setDeleteMode] = React.useState<"filter" | "selected" | "all" | null>(null); // null = dialog closed
const [deleting, setDeleting] = React.useState(false);
const [reloadTick, setReloadTick] = React.useState(0); // manual refetch trigger
const [storeErrorTraffic, setStoreErrorTraffic] = React.useState(false);
const [savingStoreError, setSavingStoreError] = React.useState(false);
React.useEffect(() => {
if (typeof traffic?.store_error_traffic === "boolean") {
setStoreErrorTraffic(traffic.store_error_traffic);
}
}, [traffic?.store_error_traffic]);
const handleToggleStoreErrorTraffic = React.useCallback(
async (checked: boolean) => {
const prev = storeErrorTraffic;
setStoreErrorTraffic(checked);
setSavingStoreError(true);
try {
const updated = await api.updateGatewaySettings({ store_error_traffic: checked });
setStoreErrorTraffic(Boolean(updated.store_error_traffic));
setTraffic((cur) => (cur ? { ...cur, store_error_traffic: Boolean(updated.store_error_traffic) } : cur));
const enabledMsg = isEn ? "Error traffic storage enabled" : "已开启错误流量存储(连接失败/DNS 错误将落库)";
const disabledMsg = isEn
? "Error traffic storage disabled"
: "已关闭错误流量存储(默认仅存储正常、透传与拦截流量)";
toast.success(updated.store_error_traffic ? enabledMsg : disabledMsg);
} catch (e) {
setStoreErrorTraffic(prev);
toast.error(e instanceof Error ? e.message : String(e));
} finally {
setSavingStoreError(false);
}
},
[isEn, storeErrorTraffic],
);
// Debounce both filters so we don't refetch on every keystroke.
React.useEffect(() => {
@@ -542,16 +579,42 @@ export function TrafficHistory({ taskId }: { taskId?: string }) {
</div>
</div>
<Tabs value={protocolTab} onValueChange={(v) => setProtocolTab(v as "http" | "flows" | "dns")}>
<TabsList>
<TabsTrigger value="http">HTTP / HTTPS</TabsTrigger>
<TabsTrigger value="flows">TCP / UDP</TabsTrigger>
<TabsTrigger value="dns">DNS</TabsTrigger>
</TabsList>
</Tabs>
<div className="flex flex-wrap items-center justify-between gap-3">
<Tabs value={protocolTab} onValueChange={(v) => setProtocolTab(v as "http" | "flows" | "dns")}>
<TabsList>
<TabsTrigger value="http">HTTP / HTTPS</TabsTrigger>
<TabsTrigger value="flows">TCP / UDP</TabsTrigger>
<TabsTrigger value="dns">DNS</TabsTrigger>
</TabsList>
</Tabs>
<div
className="flex items-center gap-2 rounded-lg border bg-card/60 px-2.5 py-1.5"
title={L(
"默认关闭:正常、透传与黑名单拦截流量默认存储,连接失败/超时与 DNS 解析错误不落库;与「代理与出口」页配置实时同步。",
"Off by default: allowed, passthrough, and blocked traffic are stored while connection/DNS errors are dropped. Synced live with Proxy & Egress.",
)}
>
<Label htmlFor="traffic-store-error" className="cursor-pointer text-xs font-normal text-muted-foreground">
{L("存储错误流量", "Store error traffic")}
</Label>
<Switch
id="traffic-store-error"
size="sm"
checked={storeErrorTraffic}
disabled={savingStoreError}
onCheckedChange={(checked) => void handleToggleStoreErrorTraffic(checked)}
/>
</div>
</div>
{protocolTab !== "http" ? (
<NonHTTPTrafficPanel mode={protocolTab} taskId={taskId} />
<NonHTTPTrafficPanel
mode={protocolTab}
taskId={taskId}
storeErrorTraffic={storeErrorTraffic}
onStoreErrorTrafficSync={setStoreErrorTraffic}
onEnableStoreErrorTraffic={() => void handleToggleStoreErrorTraffic(true)}
/>
) : (
<>
{/* Toolbar */}
+2 -2
View File
@@ -1947,6 +1947,6 @@ export const api = {
) => put<ContainerProxyRoute>(`/proxy/routes/${encodeURIComponent(scope)}/${encodeURIComponent(ownerId)}`, body),
deleteProxyRoute: (scope: string, ownerId: string) =>
del<{ deleted: string }>(`/proxy/routes/${encodeURIComponent(scope)}/${encodeURIComponent(ownerId)}`),
updateGatewaySettings: (body: { udp_policy: string; dns_upstream: string }) =>
put<{ udp_policy: string; dns_upstream: string }>("/proxy/gateway/settings", body),
updateGatewaySettings: (body: { udp_policy?: string; dns_upstream?: string; store_error_traffic?: boolean }) =>
put<{ udp_policy: string; dns_upstream: string; store_error_traffic: boolean }>("/proxy/gateway/settings", body),
};
+4
View File
@@ -971,6 +971,7 @@ export interface TrafficExchange {
export interface TrafficResp {
enabled: boolean;
store_error_traffic?: boolean;
proxy?: string;
count?: number; // global total (unfiltered)
total?: number; // rows matching the current filter (for pagination)
@@ -2136,6 +2137,7 @@ export interface TrafficNetFlow {
export interface TrafficNetFlowsResp {
enabled: boolean;
store_error_traffic?: boolean;
count: number;
total: number;
page: number;
@@ -2165,6 +2167,7 @@ export interface TrafficDNSQuery {
export interface TrafficDNSResp {
enabled: boolean;
store_error_traffic?: boolean;
count: number;
total: number;
page: number;
@@ -2198,6 +2201,7 @@ export interface TransparentGatewayStatus {
last_seen?: string;
udp_policy: "block_on_proxy" | "block" | "direct" | string;
dns_upstream?: string;
store_error_traffic?: boolean;
}
export interface ProxyRoutesState {