2023-10-31 14:55:15 +00:00
|
|
|
import { APIClient } from "./ApiClient";
|
|
|
|
|
|
|
|
export interface IpConfig {
|
|
|
|
bridge_address: string;
|
|
|
|
prefix: number;
|
|
|
|
dhcp_range?: [string, string];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface NetworkInfo {
|
|
|
|
name: string;
|
2023-12-04 19:16:32 +00:00
|
|
|
uuid?: string;
|
2023-10-31 14:55:15 +00:00
|
|
|
title?: string;
|
|
|
|
description?: string;
|
|
|
|
forward_mode: "NAT" | "Isolated";
|
|
|
|
device?: string;
|
|
|
|
dns_server?: string;
|
|
|
|
domain?: string;
|
|
|
|
ip_v4?: IpConfig;
|
|
|
|
ip_v6?: IpConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function NetworkURL(n: NetworkInfo, edit: boolean = false): string {
|
|
|
|
return `/net/${n.uuid}${edit ? "/edit" : ""}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class NetworkApi {
|
2023-12-04 19:16:32 +00:00
|
|
|
/**
|
|
|
|
* Create a new network
|
|
|
|
*/
|
|
|
|
static async Create(n: NetworkInfo): Promise<{ uid: string }> {
|
|
|
|
return (
|
|
|
|
await APIClient.exec({
|
|
|
|
method: "POST",
|
|
|
|
uri: "/network/create",
|
|
|
|
jsonData: n,
|
|
|
|
})
|
|
|
|
).data;
|
|
|
|
}
|
|
|
|
|
2023-10-31 14:55:15 +00:00
|
|
|
/**
|
|
|
|
* Get the entire list of networks
|
|
|
|
*/
|
|
|
|
static async GetList(): Promise<NetworkInfo[]> {
|
|
|
|
return (
|
|
|
|
await APIClient.exec({
|
|
|
|
method: "GET",
|
|
|
|
uri: "/network/list",
|
|
|
|
})
|
|
|
|
).data;
|
|
|
|
}
|
|
|
|
|
2023-12-04 19:16:32 +00:00
|
|
|
/**
|
|
|
|
* Get the information about a single network
|
|
|
|
*/
|
|
|
|
static async GetSingle(uuid: string): Promise<NetworkInfo> {
|
|
|
|
return (
|
|
|
|
await APIClient.exec({
|
|
|
|
method: "GET",
|
|
|
|
uri: `/network/${uuid}`,
|
|
|
|
})
|
|
|
|
).data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update an existing network
|
|
|
|
*/
|
|
|
|
static async Update(n: NetworkInfo): Promise<{ uid: string }> {
|
|
|
|
return (
|
|
|
|
await APIClient.exec({
|
|
|
|
method: "PUT",
|
|
|
|
uri: `/network/${n.uuid}`,
|
|
|
|
jsonData: n,
|
|
|
|
})
|
|
|
|
).data;
|
|
|
|
}
|
|
|
|
|
2023-10-31 14:55:15 +00:00
|
|
|
/**
|
|
|
|
* Delete a network
|
|
|
|
*/
|
|
|
|
static async Delete(n: NetworkInfo): Promise<NetworkInfo[]> {
|
|
|
|
return (
|
|
|
|
await APIClient.exec({
|
|
|
|
method: "DELETE",
|
|
|
|
uri: `/network/${n.uuid}`,
|
|
|
|
})
|
|
|
|
).data;
|
|
|
|
}
|
|
|
|
}
|