Update setupWireguardHost function to grab clients from database
This commit is contained in:
@@ -9,6 +9,8 @@ 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";
|
||||
import BunSQLite from "@moduletrace/bun-sqlite";
|
||||
import type { TableType } from "@/src/types";
|
||||
|
||||
const {
|
||||
WGUI_LIB_IP_TABLES_DIR,
|
||||
@@ -18,18 +20,32 @@ const {
|
||||
} = grabDirNames();
|
||||
|
||||
type Params = {
|
||||
clients: BUN_SQLITE_WGUI_CLIENTS[];
|
||||
host?: BUN_SQLITE_WGUI_HOSTS;
|
||||
variables?: BUN_SQLITE_WGUI_VARIABLES[];
|
||||
};
|
||||
|
||||
export default async function setupWireguardHost({
|
||||
clients,
|
||||
host,
|
||||
variables,
|
||||
}: Params): Promise<APIResponseObject> {
|
||||
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 HOST_WG_IP =
|
||||
host?.wg_ip_address ||
|
||||
|
||||
Reference in New Issue
Block a user