fix(wireguard): проверять конфигурацию до импорта

This commit is contained in:
Denozordec committed 2026-10-09 08:39:36 +07:00
1 parent 7ce43adc07
commit 479f2adc78
14 files changed
+247 -30

No files matched your search

+10 -10
View File
@@ -136,8 +136,8 @@ export function parseNativeConf(content: string): WgParsedConfig {
if (section === "interface") {
if (key === "privatekey") iface.privateKey = value
else if (key === "address") iface.address = value.split(",")[0]?.trim()
else if (key === "listenport") iface.listenPort = Number.parseInt(value, 10) || undefined
else if (key === "mtu") iface.mtu = Number.parseInt(value, 10) || undefined
else if (key === "listenport") iface.listenPort = Number(value)
else if (key === "mtu") iface.mtu = Number(value)
else if (key === "name") iface.name = value || iface.name
} else if (section === "peer" && currentPeer) {
if (key === "publickey") currentPeer.publicKey = value
@@ -150,12 +150,12 @@ export function parseNativeConf(content: string): WgParsedConfig {
const lastColon = value.lastIndexOf(":")
if (lastColon > 0 && !value.includes("]:")) {
currentPeer.endpointAddress = value.slice(0, lastColon)
currentPeer.endpointPort = Number.parseInt(value.slice(lastColon + 1), 10) || undefined
currentPeer.endpointPort = Number(value.slice(lastColon + 1))
} else {
currentPeer.endpointAddress = value
}
} else if (key === "persistentkeepalive") {
currentPeer.persistentKeepalive = Number.parseInt(value, 10) || undefined
currentPeer.persistentKeepalive = Number(value)
}
}
}
@@ -179,8 +179,8 @@ export function parseMikrotikRsc(content: string): WgParsedConfig {
) {
const kv = parseKvLine(line)
if (kv.name) iface.name = kv.name
if (kv["listen-port"]) iface.listenPort = Number.parseInt(kv["listen-port"], 10) || undefined
if (kv.mtu) iface.mtu = Number.parseInt(kv.mtu, 10) || undefined
if (kv["listen-port"]) iface.listenPort = Number(kv["listen-port"])
if (kv.mtu) iface.mtu = Number(kv.mtu)
if (kv["private-key"]) iface.privateKey = kv["private-key"]
if (kv.comment) iface.comment = kv.comment
if (kv.disabled === "yes") iface.disabled = true
@@ -199,13 +199,13 @@ export function parseMikrotikRsc(content: string): WgParsedConfig {
.filter(Boolean)
peers.push({
publicKey: kv["public-key"] ?? "",
allowedAddresses: allowed.length ? allowed : ["0.0.0.0/0"],
allowedAddresses: allowed,
endpointAddress: kv["endpoint-address"],
endpointPort: kv["endpoint-port"]
? Number.parseInt(kv["endpoint-port"], 10) || undefined
? Number(kv["endpoint-port"])
: undefined,
persistentKeepalive: kv["persistent-keepalive"]
? Number.parseInt(kv["persistent-keepalive"], 10) || undefined
? Number(kv["persistent-keepalive"])
: undefined,
comment: kv.comment,
name: kv.name,
@@ -223,7 +223,7 @@ export function parseMikrotikRsc(content: string): WgParsedConfig {
}
}
if (!foundIface && peers.length === 0) {
if (!foundIface) {
throw new Error("Не удалось распознать RouterOS WireGuard .rsc")
}
return { format: "rsc", interface: iface, peers }