Update setupWireguardHost function to grab clients from database
This commit is contained in:
@@ -0,0 +1,41 @@
|
|||||||
|
import type {
|
||||||
|
BUN_SQLITE_WGUI_CLIENTS,
|
||||||
|
BUN_SQLITE_WGUI_HOSTS,
|
||||||
|
BUN_SQLITE_WGUI_VARIABLES,
|
||||||
|
} from "@/db/types/db";
|
||||||
|
import { AppData } from "@/src/data/app-data";
|
||||||
|
import grabDirNames from "@/src/utils/grab-dir-names";
|
||||||
|
import { execSync } from "node:child_process";
|
||||||
|
import path from "node:path";
|
||||||
|
import grabHostNetworkInterface from "./grab-host-network-interface";
|
||||||
|
import type { APIResponseObject } from "@moduletrace/bunext/types";
|
||||||
|
|
||||||
|
const {
|
||||||
|
WGUI_LIB_IP_TABLES_DIR,
|
||||||
|
WIREGUARD_HOST_CONFIG_DIR,
|
||||||
|
WIREGUARD_PRIVATE_KEY_FILE_NAME,
|
||||||
|
WIREGUARD_PUBLIC_KEY_FILE_NAME,
|
||||||
|
} = grabDirNames();
|
||||||
|
|
||||||
|
type Params = {
|
||||||
|
client: BUN_SQLITE_WGUI_CLIENTS;
|
||||||
|
host?: BUN_SQLITE_WGUI_HOSTS;
|
||||||
|
variables?: BUN_SQLITE_WGUI_VARIABLES[];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to setup a wireguard client. This
|
||||||
|
* function will eventually call the setupWireguardHost
|
||||||
|
* function afterwards to update it
|
||||||
|
* @param param0
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export default async function setupWireguardClient({
|
||||||
|
client,
|
||||||
|
host,
|
||||||
|
variables,
|
||||||
|
}: Params): Promise<APIResponseObject> {
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -9,6 +9,8 @@ import { execSync } from "node:child_process";
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import grabHostNetworkInterface from "./grab-host-network-interface";
|
import grabHostNetworkInterface from "./grab-host-network-interface";
|
||||||
import type { APIResponseObject } from "@moduletrace/bunext/types";
|
import type { APIResponseObject } from "@moduletrace/bunext/types";
|
||||||
|
import BunSQLite from "@moduletrace/bun-sqlite";
|
||||||
|
import type { TableType } from "@/src/types";
|
||||||
|
|
||||||
const {
|
const {
|
||||||
WGUI_LIB_IP_TABLES_DIR,
|
WGUI_LIB_IP_TABLES_DIR,
|
||||||
@@ -18,18 +20,32 @@ const {
|
|||||||
} = grabDirNames();
|
} = grabDirNames();
|
||||||
|
|
||||||
type Params = {
|
type Params = {
|
||||||
clients: BUN_SQLITE_WGUI_CLIENTS[];
|
|
||||||
host?: BUN_SQLITE_WGUI_HOSTS;
|
host?: BUN_SQLITE_WGUI_HOSTS;
|
||||||
variables?: BUN_SQLITE_WGUI_VARIABLES[];
|
variables?: BUN_SQLITE_WGUI_VARIABLES[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function setupWireguardHost({
|
export default async function setupWireguardHost({
|
||||||
clients,
|
|
||||||
host,
|
host,
|
||||||
variables,
|
variables,
|
||||||
}: Params): Promise<APIResponseObject> {
|
}: Params): Promise<APIResponseObject> {
|
||||||
const host_id = host?.id || AppData["WireguardHostID"];
|
const host_id = host?.id || AppData["WireguardHostID"];
|
||||||
|
|
||||||
|
const host_clients_res = await BunSQLite.select<
|
||||||
|
BUN_SQLITE_WGUI_CLIENTS,
|
||||||
|
TableType
|
||||||
|
>({
|
||||||
|
table: "clients",
|
||||||
|
query: {
|
||||||
|
query: {
|
||||||
|
host_id: {
|
||||||
|
value: host_id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const clients = host_clients_res.payload || [];
|
||||||
|
|
||||||
const TARGET_INTERFACE = await grabHostNetworkInterface();
|
const TARGET_INTERFACE = await grabHostNetworkInterface();
|
||||||
const HOST_WG_IP =
|
const HOST_WG_IP =
|
||||||
host?.wg_ip_address ||
|
host?.wg_ip_address ||
|
||||||
|
|||||||
Reference in New Issue
Block a user