firewall api and FE
All checks were successful
Build and Deploy MITM Webserver / build (push) Successful in 9s
All checks were successful
Build and Deploy MITM Webserver / build (push) Successful in 9s
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// src/apiClient.ts
|
||||
import axios from "axios";
|
||||
import { RulesetModel } from "../types/firewall";
|
||||
import {
|
||||
BridgeCreateRequest,
|
||||
BridgeInfo,
|
||||
@@ -8,6 +9,7 @@ import {
|
||||
InterfaceInfo,
|
||||
RouteInfo,
|
||||
} from "../types/network";
|
||||
import { EnableRequest, ScriptInfo } from "../types/scripting";
|
||||
import {
|
||||
SnifferStatusResponse,
|
||||
} from "../types/sniffer";
|
||||
@@ -36,30 +38,6 @@ api.interceptors.response.use(
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Local lightweight types for a few endpoints where a dedicated project type
|
||||
* wasn't imported above. If you already have these in your codebase, replace
|
||||
* these with imports instead.
|
||||
*/
|
||||
export type RawCmdRequest = {
|
||||
cmd: string;
|
||||
};
|
||||
|
||||
export type RulesetOut = {
|
||||
ruleset: string;
|
||||
};
|
||||
|
||||
export type ScriptInfo = {
|
||||
name: string;
|
||||
path: string;
|
||||
};
|
||||
|
||||
export type EnableRequest = {
|
||||
qnum: number;
|
||||
service_name?: string | null;
|
||||
extra_args?: string | null;
|
||||
enable_at_boot?: boolean | null;
|
||||
};
|
||||
|
||||
/* -------------------------
|
||||
Basic endpoints
|
||||
@@ -150,33 +128,30 @@ export const fetchPackets = async (limit = 100): Promise<any> => {
|
||||
Firewall
|
||||
------------------------- */
|
||||
|
||||
export const listFirewallRules = async (): Promise<RulesetOut> => {
|
||||
const res = await api.get<RulesetOut>("/firewall/rules");
|
||||
/**
|
||||
* GET /firewall/rules
|
||||
* Returns: { ruleset: RulesetModel | string | null }
|
||||
* - If the server returns a raw textual fallback (string), the caller should handle it.
|
||||
*/
|
||||
export const fetchRuleset = async (): Promise<{ ruleset: RulesetModel | string | null }> => {
|
||||
const res = await api.get<{ ruleset: RulesetModel | string | null }>("/firewall/rules");
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const createFirewallRuleText = async (req: RawCmdRequest): Promise<any> => {
|
||||
// Executes textual nft command, returns raw stdout (201 expected per spec)
|
||||
const res = await api.post("/firewall/rules", req);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const deleteFirewallRule = async (
|
||||
/**
|
||||
* DELETE /firewall/rules/{handle}?family=...&table=...&chain=...
|
||||
* On success the backend returns 204 No Content. This function resolves to void.
|
||||
*/
|
||||
export const deleteRule = async (
|
||||
handle: number,
|
||||
options?: { family?: string; table?: string; chain?: string }
|
||||
family: string,
|
||||
table: string,
|
||||
chain: string
|
||||
): Promise<void> => {
|
||||
// returns 204 on success (no content)
|
||||
const params: Record<string, any> = {};
|
||||
if (options?.family) params.family = options.family;
|
||||
if (options?.table) params.table = options.table;
|
||||
if (options?.chain) params.chain = options.chain;
|
||||
|
||||
await api.delete(`/firewall/rules/${handle}`, { params });
|
||||
};
|
||||
|
||||
export const execFirewallRaw = async (req: RawCmdRequest): Promise<any> => {
|
||||
// Execute arbitrary textual nft command and return {rc, stdout, stderr}
|
||||
const res = await api.post("/firewall/raw", req);
|
||||
const res = await api.delete(`/firewall/rules/${encodeURIComponent(String(handle))}`, {
|
||||
params: { family, table, chain },
|
||||
});
|
||||
// axios resolves non-2xx as reject; server uses 204 No Content so nothing to return
|
||||
return res.data;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user