added more types
All checks were successful
Build and Deploy MITM Webserver / build (push) Successful in 10s
All checks were successful
Build and Deploy MITM Webserver / build (push) Successful in 10s
This commit is contained in:
@@ -8,7 +8,9 @@ import {
|
||||
InterfaceInfo,
|
||||
RouteInfo,
|
||||
} from "../types/network";
|
||||
import { SnifferStatusResponse } from "../types/sniffer";
|
||||
import {
|
||||
SnifferStatusResponse,
|
||||
} from "../types/sniffer";
|
||||
|
||||
const BASE = "http://mitm.lan/api";
|
||||
|
||||
@@ -34,7 +36,49 @@ api.interceptors.response.use(
|
||||
}
|
||||
);
|
||||
|
||||
// Queries
|
||||
/**
|
||||
* 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
|
||||
------------------------- */
|
||||
|
||||
export const fetchHello = async (): Promise<any> => {
|
||||
const res = await api.get("/hello");
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const fetchVersions = async (): Promise<any> => {
|
||||
const res = await api.get("/versions");
|
||||
return res.data;
|
||||
};
|
||||
|
||||
/* -------------------------
|
||||
Network queries (existing)
|
||||
------------------------- */
|
||||
|
||||
export const fetchInterfaces = async (): Promise<InterfaceInfo[]> => {
|
||||
const res = await api.get<InterfaceInfo[]>("/network/interfaces");
|
||||
return res.data;
|
||||
@@ -60,19 +104,141 @@ export const fetchFullState = async (): Promise<FullState> => {
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const createBridge = async (req: BridgeCreateRequest) => {
|
||||
const res = await api.post("/network/bridge/create", req);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const removeBridge = async (req: BridgeRemoveRequest) => {
|
||||
const res = await api.post("/network/bridge/remove", req);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
|
||||
/* -------------------------
|
||||
Sniffer
|
||||
------------------------- */
|
||||
|
||||
export const fetchSnifferStatus = async (): Promise<SnifferStatusResponse> => {
|
||||
const res = await api.get<SnifferStatusResponse>("/sniffer/status");
|
||||
return res.data;
|
||||
};
|
||||
|
||||
|
||||
// Mutations
|
||||
export const createBridge = async (req: BridgeCreateRequest) => {
|
||||
const res = await api.post("network/bridge/create", req);
|
||||
/* export const snifferStart = async (
|
||||
req: SnifferStartRequest
|
||||
): Promise<SnifferStartResponse> => {
|
||||
const res = await api.post<SnifferStartResponse>("/sniffer/start", req);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const removeBridge = async (req: BridgeRemoveRequest) => {
|
||||
const res = await api.post("network/bridge/remove", req);
|
||||
export const snifferStop = async (): Promise<SnifferStopResponse> => {
|
||||
const res = await api.post<SnifferStopResponse>("/sniffer/stop");
|
||||
return res.data;
|
||||
};
|
||||
*/
|
||||
/* -------------------------
|
||||
Packets
|
||||
------------------------- */
|
||||
|
||||
export const fetchPackets = async (limit = 100): Promise<any> => {
|
||||
// limit default mirrors OpenAPI default
|
||||
const res = await api.get("/packets/packets", { params: { limit } });
|
||||
return res.data;
|
||||
};
|
||||
|
||||
/* -------------------------
|
||||
Firewall
|
||||
------------------------- */
|
||||
|
||||
export const listFirewallRules = async (): Promise<RulesetOut> => {
|
||||
const res = await api.get<RulesetOut>("/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 (
|
||||
handle: number,
|
||||
options?: { 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);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
/* -------------------------
|
||||
Scripts
|
||||
------------------------- */
|
||||
|
||||
export const fetchScriptsStatusAll = async (): Promise<any> => {
|
||||
const res = await api.get("/scripts/scripts/status");
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const fetchScriptStatusForName = async (name: string): Promise<any> => {
|
||||
const res = await api.get(`/scripts/scripts/${encodeURIComponent(name)}/status`);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const listScripts = async (): Promise<ScriptInfo[]> => {
|
||||
const res = await api.get<ScriptInfo[]>("/scripts/scripts");
|
||||
return res.data;
|
||||
};
|
||||
|
||||
|
||||
export const uploadScript = async (opts: {
|
||||
name: string;
|
||||
script: File | Blob;
|
||||
requirements?: File | Blob | null;
|
||||
}): Promise<ScriptInfo> => {
|
||||
const fd = new FormData();
|
||||
fd.append("name", opts.name);
|
||||
fd.append("script", opts.script);
|
||||
if (opts.requirements) fd.append("requirements", opts.requirements as Blob);
|
||||
|
||||
// axios will set multipart/form-data boundary automatically when FormData passed
|
||||
const res = await api.post<ScriptInfo>("/scripts/scripts", fd, {
|
||||
headers: { "Content-Type": "multipart/form-data" },
|
||||
});
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const downloadScript = async (name: string): Promise<any> => {
|
||||
const res = await api.get(`/scripts/scripts/${encodeURIComponent(name)}`);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const deleteScript = async (name: string, qnum?: number | null): Promise<any> => {
|
||||
const params: Record<string, any> = {};
|
||||
if (typeof qnum !== "undefined") params.qnum = qnum;
|
||||
const res = await api.delete(`/scripts/scripts/${encodeURIComponent(name)}`, { params });
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const enableScript = async (name: string, req: EnableRequest): Promise<any> => {
|
||||
const res = await api.post(`/scripts/scripts/${encodeURIComponent(name)}/enable`, req);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const disableScript = async (name: string, qnum: number): Promise<any> => {
|
||||
const res = await api.post(`/scripts/scripts/${encodeURIComponent(name)}/disable`, null, {
|
||||
params: { qnum },
|
||||
});
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export default api;
|
||||
|
||||
Reference in New Issue
Block a user