fix(ui): сохранять недоступные срезы Firewall
This commit is contained in:
1 parent
59440555cd
commit
5e6057842f
11 files changed
+228
-77
No files matched your search
@@ -1,7 +1,11 @@
|
||||
import { z } from "zod"
|
||||
|
||||
const context = { id: z.string().min(1), rosId: z.string().min(1), serverId: z.string().min(1), serverName: z.string(), family: z.enum(["ip", "ip6"]) }
|
||||
export const firewallFailureSchema = z.object({ serverId: z.string().min(1), serverName: z.string().optional(), family: z.enum(["ip", "ip6"]).optional(), table: z.enum(["filter", "nat", "mangle", "raw", "address-list"]).optional(), error: z.string() })
|
||||
export type FirewallFailure = z.infer<typeof firewallFailureSchema>
|
||||
|
||||
export const firewallResponseSchema = z.object({
|
||||
failures: z.array(firewallFailureSchema).default([]),
|
||||
rules: z.array(z.object({
|
||||
...context, table: z.enum(["filter", "nat", "mangle", "raw"]), chain: z.string(), action: z.string(),
|
||||
proto: z.string(), src: z.string(), dst: z.string(), port: z.string(), iface: z.string(),
|
||||
@@ -20,3 +24,13 @@ export const firewallServersSchema = z.array(z.object({
|
||||
})).refine(rows => new Set(rows.map(row => row.id)).size === rows.length)
|
||||
|
||||
export type FirewallBackendServer = z.infer<typeof firewallServersSchema>[number]
|
||||
|
||||
export function matchesFirewallFailure(failure: FirewallFailure, row: { serverId?: string; family?: string; table?: string }, addressList = false) {
|
||||
return failure.serverId === row.serverId && (!failure.family || failure.family === row.family)
|
||||
&& (!failure.table || failure.table === (addressList ? "address-list" : row.table))
|
||||
}
|
||||
|
||||
export function mergeFirewallRows<T extends { serverId?: string; family?: string; table?: string }>(previous: T[], incoming: T[], failures: FirewallFailure[], enabledServerIds: Set<string>, addressList = false): T[] {
|
||||
return [...incoming.filter(row => !failures.some(f => matchesFirewallFailure(f, row, addressList))),
|
||||
...previous.filter(row => !!row.serverId && enabledServerIds.has(row.serverId) && failures.some(f => matchesFirewallFailure(f, row, addressList)))]
|
||||
}
|
||||
Reference in new issue
Block a user