fix(wireguard): исправить endpoint и поля клиентского шаблона

This commit is contained in:
Denozordec committed 2026-10-08 23:21:45 +07:00
1 parent 206255b856
commit c82e8fa12b
13 files changed
+128 -29

No files matched your search

+11
View File
@@ -1,5 +1,16 @@
import { z } from "zod"
/** The client's remote endpoint belongs to the exporting interface, not its peer. */
export function resolveWgClientEndpoint(clientEndpoint: string | undefined, serverHost: string | undefined, listenPort: number): string | undefined {
const value = clientEndpoint?.trim() || serverHost?.trim()
if (!value || /[\s/]/.test(value) || !Number.isInteger(listenPort) || listenPort < 1 || listenPort > 65535) return undefined
const explicit = value.match(/^(\[[^\]]+\]|[^:]+):(\d+)$/)
if (explicit) return Number(explicit[2]) >= 1 && Number(explicit[2]) <= 65535 ? value : undefined
if (value.startsWith("[")) return value.endsWith("]") ? `${value}:${listenPort}` : undefined
if (value.includes(":")) return value.split(":").length > 2 && /^[\da-f:]+$/i.test(value) ? `[${value}]:${listenPort}` : undefined
return `${value}:${listenPort}`
}
export const wgStatusSchema = z.enum(["up", "down"])
export const wgPeerDtoSchema = z.object({