fix(ipsec): показывать подключённых клиентов и адрес mode-config

This commit is contained in:
Denozordec committed 2026-10-09 15:14:41 +07:00
1 parent f80d9b7637
commit b9a8615b8b
8 files changed
+204 -14

No files matched your search

+18 -8
View File
@@ -108,6 +108,11 @@ export interface RosIpsecActivePeer {
"remote-id"?: string
identity?: string
established?: string
id?: string
state?: string
"remote-address"?: string
"dynamic-address"?: string
uptime?: string
}
type RosCertRow = Record<string, string | undefined>
@@ -238,10 +243,15 @@ export function mapClients(state: IpsecServerState): IpsecClientDto[] {
const activeByRemote = new Map<string, RosIpsecActivePeer>()
for (const a of state.active) {
const rid = String(a["remote-id"] ?? "").trim()
if (a.state !== "established") continue
const rid = String(a.id ?? a["remote-id"] ?? "").trim()
if (rid) activeByRemote.set(rid, a)
}
// RouterOS 7 active-peers.id contains the received value without its configured type prefix.
const findActive = (remoteId: string) => activeByRemote.get(remoteId)
?? activeByRemote.get(remoteId.replace(/^(key-id|fqdn|user-fqdn|address):/, ""))
const identityByRemoteCert = new Map<string, RosIpsecIdentity>()
for (const i of state.identities) {
const rc = (i["remote-certificate"] ?? "").trim()
@@ -270,8 +280,8 @@ export function mapClients(state: IpsecServerState): IpsecClientDto[] {
const comment = identity?.comment ?? ""
const mcName = (identity?.["mode-config"] ?? "").trim()
const cn = String(cert["common-name"] ?? "").trim()
const active = (cn ? activeByRemote.get(cn) : undefined)
?? (identity?.["remote-id"] ? activeByRemote.get(String(identity["remote-id"]).trim()) : undefined)
const active = (cn ? findActive(cn) : undefined)
?? (identity?.["remote-id"] ? findActive(String(identity["remote-id"]).trim()) : undefined)
out.push({
id: `${server.id}:${identity ? "identity" : "cert"}:${String(identity?.[".id"] ?? cert[".id"] ?? certName)}`,
rosId: `${identity ? "identity" : "cert"}:${String(identity?.[".id"] ?? cert[".id"] ?? certName)}`,
@@ -289,8 +299,8 @@ export function mapClients(state: IpsecServerState): IpsecClientDto[] {
modeConfigName: mcName || undefined,
peerName: (identity?.peer ?? "").trim() || undefined,
online: Boolean(active),
activeAddress: active?.address || undefined,
activeSince: active?.established || undefined,
activeAddress: active?.["dynamic-address"] || active?.["remote-address"] || active?.address || undefined,
activeSince: active?.uptime || active?.established || undefined,
disabled: asBool(identity?.disabled),
comment: comment || undefined,
managed: isUser || isIpsecManagedComment(comment),
@@ -306,7 +316,7 @@ export function mapClients(state: IpsecServerState): IpsecClientDto[] {
if (!managed && !isIke2RemoteAccessIdentity(i, ike2PeerNames)) continue
const mcName = (i["mode-config"] ?? "").trim()
const remoteId = (i["remote-id"] ?? "").trim()
const active = remoteId ? activeByRemote.get(remoteId) : undefined
const active = remoteId ? findActive(remoteId) : undefined
out.push({
id: `${server.id}:identity:${rosId}`,
rosId: `identity:${rosId}`,
@@ -320,8 +330,8 @@ export function mapClients(state: IpsecServerState): IpsecClientDto[] {
modeConfigName: mcName || undefined,
peerName: (i.peer ?? "").trim() || undefined,
online: Boolean(active),
activeAddress: active?.address || undefined,
activeSince: active?.established || undefined,
activeAddress: active?.["dynamic-address"] || active?.["remote-address"] || active?.address || undefined,
activeSince: active?.uptime || active?.established || undefined,
disabled: asBool(i.disabled),
comment: i.comment || undefined,
managed,