Create frames for network filters management

This commit is contained in:
2024-01-03 19:20:37 +01:00
parent 22f5acd0ff
commit c880c5e6bb
7 changed files with 397 additions and 14 deletions

View File

@ -1,4 +1,5 @@
import { APIClient } from "./ApiClient";
import { ServerApi } from "./ServerApi";
export interface NWFilterChain {
protocol: string;
@ -18,8 +19,91 @@ export interface NWFSMac {
comment?: string;
}
// TODO : complete
export type NWFSelector = NWFSAll | NWFSMac;
export interface NWFSArpOrRARP {
srcmacaddr?: string;
srcmacmask?: string;
dstmacaddr?: string;
dstmacmask?: string;
arpsrcipaddr?: string;
arpsrcipmask?: number;
arpdstipaddr?: string;
arpdstipmask?: number;
comment?: string;
}
export type NWFSArp = NWFSArpOrRARP & {
type: "arp";
};
export type NWFSRArp = NWFSArpOrRARP & {
type: "rarp";
};
export interface NWFSIPBase {
srcmacaddr?: string;
srcmacmask?: string;
dstmacaddr?: string;
dstmacmask?: string;
srcipaddr?: string;
srcipmask?: number;
dstipaddr?: string;
dstipmask?: number;
comment?: string;
}
export type NFWSIPv4 = NWFSIPBase & { type: "ipv4" };
export type NFWSIPv6 = NWFSIPBase & { type: "ipv6" };
export type Layer4State =
| "NEW"
| "ESTABLISHED"
| "RELATED"
| "INVALID"
| "NONE";
export interface NWFSLayer4Base {
srcmacaddr?: string;
srcipaddr?: string;
srcipmask?: number;
dstipaddr?: string;
dstipmask?: number;
srcipfrom?: string;
srcipto?: string;
dstipfrom?: string;
dstipto?: string;
srcportstart?: number;
srcportend?: number;
dstportstart?: number;
dstportend?: number;
state?: Layer4State;
comment?: string;
}
export type NFWSTCPv4 = NWFSLayer4Base & { type: "tcp" };
export type NFWSUDPv4 = NWFSLayer4Base & { type: "udp" };
export type NFWSSCTPv4 = NWFSLayer4Base & { type: "sctp" };
export type NFWSICMPv4 = NWFSLayer4Base & { type: "icmp" };
export type NFWSTCPv6 = NWFSLayer4Base & { type: "tcpipv6" };
export type NFWSUDPv6 = NWFSLayer4Base & { type: "udpipv6" };
export type NFWSSCTPv6 = NWFSLayer4Base & { type: "sctpipv6" };
export type NFWSICMPv6 = NWFSLayer4Base & { type: "icmpipv6" };
export type NWFSelector =
| NWFSAll
| NWFSMac
| NWFSArp
| NWFSRArp
| NFWSIPv4
| NFWSIPv6
| NFWSTCPv4
| NFWSUDPv4
| NFWSSCTPv4
| NFWSICMPv4
| NFWSTCPv6
| NFWSUDPv6
| NFWSSCTPv6
| NFWSICMPv6;
export interface NWFilterRule {
action: "drop" | "reject" | "accept" | "return" | "continue";
@ -41,6 +125,10 @@ export function NWFilterURL(n: NWFilter, edit: boolean = false): string {
return `/nwfilter/${n.uuid}${edit ? "/edit" : ""}`;
}
export function NWFilterIsBuiltin(n: NWFilter): boolean {
return ServerApi.Config.builtin_nwfilter_rules.includes(n.name);
}
export class NWFilterApi {
/**
* Get the entire list of networks
@ -57,4 +145,64 @@ export class NWFilterApi {
return list;
}
/**
* Get the information about a single network filter
*/
static async GetSingle(uuid: string): Promise<NWFilter> {
return (
await APIClient.exec({
method: "GET",
uri: `/nwfilter/${uuid}`,
})
).data;
}
/**
* Get the source XML configuration of a network filter for debugging purposes
*/
static async GetSingleXML(uuid: string): Promise<string> {
return (
await APIClient.exec({
uri: `/nwfilter/${uuid}/src`,
method: "GET",
})
).data;
}
/**
* Create a new network filter
*/
static async Create(n: NWFilter): Promise<{ uid: string }> {
return (
await APIClient.exec({
method: "POST",
uri: "/nwfilter/create",
jsonData: n,
})
).data;
}
/**
* Update an existing network filter
*/
static async Update(n: NWFilter): Promise<{ uid: string }> {
return (
await APIClient.exec({
method: "PUT",
uri: `/nwfilter/${n.uuid}`,
jsonData: n,
})
).data;
}
/**
* Delete a network filter
*/
static async Delete(n: NWFilter): Promise<void> {
await APIClient.exec({
method: "DELETE",
uri: `/nwfilter/${n.uuid}`,
});
}
}

View File

@ -160,12 +160,10 @@ export class NetworkApi {
/**
* Delete a network
*/
static async Delete(n: NetworkInfo): Promise<NetworkInfo[]> {
return (
await APIClient.exec({
method: "DELETE",
uri: `/network/${n.uuid}`,
})
).data;
static async Delete(n: NetworkInfo): Promise<void> {
await APIClient.exec({
method: "DELETE",
uri: `/network/${n.uuid}`,
});
}
}