| 1 | export function isSafetyCheckMessage(message) { |
| 2 | return typeof message === "string" && /关键(?:检查|检测)(?:尚未|未|失败|证据不完整)|完成关键检查|外网(?:未放行|保持关闭)|浏览器配置检查未通过/.test(message); |
| 3 | } |
| 4 | |
| 5 | export function networkState(status, now = Date.now()) { |
| 6 | if (!status?.vm_running) return { mode: "stopped", label: "环境已停止" }; |
| 7 | const gate = status.safety?.gate; |
| 8 | if (!gate) return { mode: "unknown", label: "外网状态待确认" }; |
| 9 | const until = Date.parse(gate.until); |
| 10 | if (gate.mode === "open" && Number.isFinite(until) && until > now) |
| 11 | return { mode: "open", label: "外网已放行" }; |
| 12 | if (gate.mode === "checking" && Number.isFinite(until) && until > now) |
| 13 | return { mode: "checking", label: "正在检查" }; |
| 14 | if (gate.mode === "closed" || (Number.isFinite(until) && until <= now)) |
| 15 | return { mode: "closed", label: "外网已关闭" }; |
| 16 | return { mode: "unknown", label: "外网状态待确认" }; |
| 17 | } |
| 18 | |
| 19 | export function canonicalExitPolicy(value = {}) { |
| 20 | return { |
| 21 | mode: value.mode || "dynamic", |
| 22 | scope: value.scope || "country", |
| 23 | ip: (value.ip || "").trim(), |
| 24 | country_code: (value.country_code || "").trim().toUpperCase(), |
| 25 | region: (value.region || "").trim().replace(/\s+/g, " "), |
| 26 | city: (value.city || "").trim().replace(/\s+/g, " "), |
| 27 | }; |
| 28 | } |
| 29 | |
| 30 | export function reportForSharing(report) { |
| 31 | return { |
| 32 | policy: report.policy, |
| 33 | created_at: report.created_at, |
| 34 | checks: report.checks, |
| 35 | scope: "采样与运行时策略检查;不代表平台账号资格或完整虚拟化审计", |
| 36 | }; |
| 37 | } |
| 38 | |
| 39 | export function isGuestLocalURL(value) { |
| 40 | if (value === "about:blank") return true; |
| 41 | try { |
| 42 | const url = new URL(value); |
| 43 | return ( |
| 44 | ["http:", "https:"].includes(url.protocol) && |
| 45 | ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname) |
| 46 | ); |
| 47 | } catch { |
| 48 | return false; |
| 49 | } |
| 50 | } |