diff --git a/db/types/db.ts b/db/types/db.ts index 3e9433d..c59a846 100644 --- a/db/types/db.ts +++ b/db/types/db.ts @@ -175,7 +175,7 @@ export type BUN_SQLITE_WGUI_VARIABLES = { * The time when the record was updated. (Unix Timestamp) */ updated_at?: number | ""; - key?: "main_host_wg_ip_address" | "main_host_public_ip_address" | "main_host_wg_public_key" | "main_host_wg_private_key" | "main_host_public_interface" | ""; + key?: "test_var" | ""; value?: string; } diff --git a/deploy/deploy-prod.sh b/deploy/deploy-prod.sh index 6cef277..0f8673f 100755 --- a/deploy/deploy-prod.sh +++ b/deploy/deploy-prod.sh @@ -29,4 +29,4 @@ docker run --name bunext-mariadb -d \ -v server-data:/data \ --restart unless-stopped \ bunext-mariadb:latest -EOF \ No newline at end of file +EOF diff --git a/src/components/general/delete-host-button.tsx b/src/components/general/delete-host-button.tsx new file mode 100644 index 0000000..23a72c1 --- /dev/null +++ b/src/components/general/delete-host-button.tsx @@ -0,0 +1,50 @@ +import { useState } from "react"; +import { Trash2 } from "lucide-react"; +import Button from "@/src/components/twui/layout/Button"; +import fetchApi from "@/src/components/twui/utils/fetch/fetchApi"; +import type { ApiReqParams } from "@/src/types"; +import type { APIResponseObject } from "@moduletrace/bunext/types"; + +export default function DeleteHostButton({ host_id }: { host_id: number }) { + const [deleting, setDeleting] = useState(false); + + async function handleDelete() { + if ( + !window.confirm( + `Delete host #${host_id}? All clients and their configurations will be removed.`, + ) + ) { + return; + } + + setDeleting(true); + + const res = await fetchApi( + `/api/admin/delete-host`, + { + method: "DELETE", + body: { host_id }, + }, + ); + + if (!res.success) { + setDeleting(false); + window.alert(res.msg || "Could not delete the host"); + return; + } + + window.location.pathname = "/admin/hosts"; + } + + return ( + + + - + {host.public_ip_address ? ( + + + {host.public_ip_address} :{" "} + {host.listen_port || AppData["DefaultWGListenPort"]} + + + ) : null} + {client_count || 0}{" "} {client_count == 1 ? "client" : "clients"} - - {host.public_ip_address ? ( - - {host.public_ip_address} - - ) : null} + ); -} \ No newline at end of file +} diff --git a/src/pages/admin/hosts/(sections)/interface-config-section.tsx b/src/pages/admin/hosts/(sections)/interface-config-section.tsx index 67ee696..24941de 100644 --- a/src/pages/admin/hosts/(sections)/interface-config-section.tsx +++ b/src/pages/admin/hosts/(sections)/interface-config-section.tsx @@ -8,11 +8,7 @@ import Row from "@/src/components/twui/layout/Row"; import Span from "@/src/components/twui/layout/Span"; import Stack from "@/src/components/twui/layout/Stack"; import deriveHostConfig from "../(functions)/derive-host-config"; -import type { - BUN_SQLITE_WGUI_CLIENTS, - BUN_SQLITE_WGUI_HOSTS, - BUN_SQLITE_WGUI_VARIABLES, -} from "@/db/types/db"; +import type { BUN_SQLITE_WGUI_CLIENTS } from "@/db/types/db"; import Divider from "@/src/components/twui/layout/Divider"; import H3 from "@/src/components/twui/layout/H3"; import type { BUN_SQLITE_WGUI_HOSTS_JOIN } from "@/src/types/sql-joins"; @@ -21,13 +17,11 @@ import { AppContext } from "@/src/pages/__root"; type Props = { host?: BUN_SQLITE_WGUI_HOSTS_JOIN; - variables?: BUN_SQLITE_WGUI_VARIABLES[]; clients?: BUN_SQLITE_WGUI_CLIENTS[]; }; export default function InterfaceConfigSection({ host, - variables, clients, }: Props) { const { pageProps } = useContext(AppContext); @@ -38,7 +32,7 @@ export default function InterfaceConfigSection({ dir_names: pageProps?.main_host_dir_names || undefined, }; - const config = deriveHostConfig({ host: final_host, variables, clients }); + const config = deriveHostConfig({ host: final_host, clients }); const rows = [ { keyName: "Address", value: config.address || "—" }, diff --git a/src/pages/admin/hosts/(sections)/main-host-status-section.tsx b/src/pages/admin/hosts/(sections)/main-host-status-section.tsx index a636216..ee382ac 100644 --- a/src/pages/admin/hosts/(sections)/main-host-status-section.tsx +++ b/src/pages/admin/hosts/(sections)/main-host-status-section.tsx @@ -5,20 +5,16 @@ import Span from "@/src/components/twui/layout/Span"; import Stack from "@/src/components/twui/layout/Stack"; import deriveHostConfig from "../(functions)/derive-host-config"; import { twMerge } from "tailwind-merge"; -import type { - BUN_SQLITE_WGUI_CLIENTS, - BUN_SQLITE_WGUI_VARIABLES, -} from "@/db/types/db"; +import type { BUN_SQLITE_WGUI_CLIENTS } from "@/db/types/db"; import type { BUN_SQLITE_WGUI_HOSTS_JOIN } from "@/src/types/sql-joins"; type Props = { host?: BUN_SQLITE_WGUI_HOSTS_JOIN; - variables?: BUN_SQLITE_WGUI_VARIABLES[]; clients?: BUN_SQLITE_WGUI_CLIENTS[]; }; -export default function MainHostStatusSection({ host, variables, clients }: Props) { - const config = deriveHostConfig({ host, variables, clients }); +export default function MainHostStatusSection({ host, clients }: Props) { + const config = deriveHostConfig({ host, clients }); const stats = [ { diff --git a/src/pages/admin/hosts/[host_id]/clients/[client_id]/index.server.ts b/src/pages/admin/hosts/[host_id]/clients/[client_id]/index.server.ts index 35a60ec..6bb2bec 100644 --- a/src/pages/admin/hosts/[host_id]/clients/[client_id]/index.server.ts +++ b/src/pages/admin/hosts/[host_id]/clients/[client_id]/index.server.ts @@ -28,14 +28,12 @@ const server: BunextPageServerFn = async ({ query }) => { const client = client_res.singleRes || null; const host_id = Number( - client?.host_id || - page_query.host_id || - AppData["WireguardHostID"], + client?.host_id || page_query.host_id || AppData["WireguardMainHostID"], ); let host: BUN_SQLITE_WGUI_HOSTS | null = null; - if (host_id && host_id != AppData["WireguardHostID"]) { + if (host_id && host_id != AppData["WireguardMainHostID"]) { const host_res = await BunSQLite.select< BUN_SQLITE_WGUI_HOSTS, TableType @@ -72,4 +70,4 @@ const server: BunextPageServerFn = async ({ query }) => { }; }; -export default server; \ No newline at end of file +export default server; diff --git a/src/pages/admin/hosts/[host_id]/clients/add-client/(functions)/grab-next-available-client-ip.ts b/src/pages/admin/hosts/[host_id]/clients/add-client/(functions)/grab-next-available-client-ip.ts index 09048a4..bdeb7c3 100644 --- a/src/pages/admin/hosts/[host_id]/clients/add-client/(functions)/grab-next-available-client-ip.ts +++ b/src/pages/admin/hosts/[host_id]/clients/add-client/(functions)/grab-next-available-client-ip.ts @@ -21,7 +21,7 @@ export default async function grabNextAvailableClientIp({ }, ); - if (!res?.success || !res.msg) { + if (!res?.success || !res.stringRes) { return { success: false, msg: res?.msg || `Couldn't grab the next available client IP`, @@ -30,8 +30,8 @@ export default async function grabNextAvailableClientIp({ setForm((prev) => ({ ...prev, - wg_ip_address: res.msg, - allowed_ips: `${res.msg}/24`, + wg_ip_address: res.stringRes || "", + allowed_ips: `${res.stringRes}/24`, })); return { diff --git a/src/pages/admin/hosts/[host_id]/clients/add-client/(functions)/submit-add-client-form.ts b/src/pages/admin/hosts/[host_id]/clients/add-client/(functions)/submit-add-client-form.ts index ec87e30..e689485 100644 --- a/src/pages/admin/hosts/[host_id]/clients/add-client/(functions)/submit-add-client-form.ts +++ b/src/pages/admin/hosts/[host_id]/clients/add-client/(functions)/submit-add-client-form.ts @@ -24,6 +24,7 @@ export default async function submitAddClientForm( form, existing_full, app_context, + clearLocalForm, }: ReturnType>, { host_id, rules }: Params, ) { @@ -113,6 +114,8 @@ export default async function submitAddClientForm( } if (res.success) { + clearLocalForm(); + if (existing_full?.id) { window.location.pathname = `/admin/hosts/${final_host_id}/clients/${existing_full.id}`; } else { diff --git a/src/pages/admin/hosts/[host_id]/clients/add-client/(partials)/client-form/add-client-form.tsx b/src/pages/admin/hosts/[host_id]/clients/add-client/(partials)/client-form/add-client-form.tsx index f49d2f4..0f915ae 100644 --- a/src/pages/admin/hosts/[host_id]/clients/add-client/(partials)/client-form/add-client-form.tsx +++ b/src/pages/admin/hosts/[host_id]/clients/add-client/(partials)/client-form/add-client-form.tsx @@ -38,6 +38,15 @@ export default function AddClientForm({ existing: existing_client, existing_full: existing_client_full, title: "Add Client", + async before_ready_function(params) { + params.setForm((prev) => ({ + ...prev, + wg_ip_address: + existing_client_full?.wg_ip_address || + params.app_context.pageProps?.next_available_client_ip || + "", + })); + }, }); const [rules, setRules] = useState( diff --git a/src/pages/admin/hosts/[host_id]/clients/add-client/index.server.ts b/src/pages/admin/hosts/[host_id]/clients/add-client/index.server.ts index 9965d85..887b4a6 100644 --- a/src/pages/admin/hosts/[host_id]/clients/add-client/index.server.ts +++ b/src/pages/admin/hosts/[host_id]/clients/add-client/index.server.ts @@ -1,4 +1,5 @@ import type { BUN_SQLITE_WGUI_HOSTS } from "@/db/types/db"; +import grabNextAvailableClientIPAddress from "@/src/functions/backend/setup/grab-next-available-client-ip"; import type { PagePropsType, PageQueryObject, TableType } from "@/src/types"; import BunSQLite from "@moduletrace/bun-sqlite"; import type { BunextPageServerFn } from "@moduletrace/bunext/types"; @@ -11,9 +12,27 @@ const server: BunextPageServerFn = async ({ query }) => { TableType >({ table: "hosts", targetId: page_query.host_id }); + const host_record = host_record_res.singleRes || null; + + if (!host_record) { + return { + redirect: { + destination: `/admin/hosts`, + }, + }; + } + + const next_available_client_ip_res = await grabNextAvailableClientIPAddress( + { + host: host_record, + }, + ); + return { props: { - host: host_record_res.singleRes || null, + host: host_record, + next_available_client_ip: + next_available_client_ip_res.stringRes || null, }, }; }; diff --git a/src/pages/admin/hosts/[host_id]/edit/index.server.ts b/src/pages/admin/hosts/[host_id]/edit/index.server.ts index 125a91c..c366ab5 100644 --- a/src/pages/admin/hosts/[host_id]/edit/index.server.ts +++ b/src/pages/admin/hosts/[host_id]/edit/index.server.ts @@ -1,8 +1,4 @@ -import type { - BUN_SQLITE_WGUI_HOSTS, - BUN_SQLITE_WGUI_VARIABLES, -} from "@/db/types/db"; -import { AppData } from "@/src/data/app-data"; +import type { BUN_SQLITE_WGUI_HOSTS } from "@/db/types/db"; import type { PagePropsType, PageQueryObject, TableType } from "@/src/types"; import BunSQLite from "@moduletrace/bun-sqlite"; import type { BunextPageServerFn } from "@moduletrace/bunext/types"; @@ -10,9 +6,7 @@ import type { BunextPageServerFn } from "@moduletrace/bunext/types"; const server: BunextPageServerFn = async ({ query }) => { const page_query = query as PageQueryObject; - const host_id = Number( - page_query.host_id || AppData["WireguardHostID"], - ); + const host_id = Number(page_query.host_id || 0); const host_res = await BunSQLite.select< BUN_SQLITE_WGUI_HOSTS, @@ -22,31 +16,7 @@ const server: BunextPageServerFn = async ({ query }) => { targetId: host_id, }); - let host = host_res.singleRes || null; - - if (!host && host_id == AppData["WireguardHostID"]) { - const variables_res = await BunSQLite.select< - BUN_SQLITE_WGUI_VARIABLES, - TableType - >({ - table: "variables", - }); - - const variables = variables_res.payload || []; - - host = { - id: AppData["WireguardHostID"], - wg_ip_address: - variables.find((v) => v.key == "main_host_wg_ip_address") - ?.value || "", - public_ip_address: - variables.find((v) => v.key == "main_host_public_ip_address") - ?.value || "", - public_key: - variables.find((v) => v.key == "main_host_wg_public_key") - ?.value || "", - }; - } + const host = host_res.singleRes || null; return { props: { @@ -55,4 +25,4 @@ const server: BunextPageServerFn = async ({ query }) => { }; }; -export default server; \ No newline at end of file +export default server; diff --git a/src/pages/admin/hosts/[host_id]/index.server.ts b/src/pages/admin/hosts/[host_id]/index.server.ts index e5daf95..1d8d9e8 100644 --- a/src/pages/admin/hosts/[host_id]/index.server.ts +++ b/src/pages/admin/hosts/[host_id]/index.server.ts @@ -1,8 +1,4 @@ -import type { - BUN_SQLITE_WGUI_CLIENTS, - BUN_SQLITE_WGUI_HOSTS, - BUN_SQLITE_WGUI_VARIABLES, -} from "@/db/types/db"; +import type { BUN_SQLITE_WGUI_CLIENTS, BUN_SQLITE_WGUI_HOSTS } from "@/db/types/db"; import grabHostDirnames from "@/src/functions/backend/setup/grab-host-dir-names"; import type { PagePropsType, PageQueryObject, TableType } from "@/src/types"; import BunSQLite from "@moduletrace/bun-sqlite"; @@ -43,18 +39,12 @@ const server: BunextPageServerFn = async ({ }, }); - const variables_res = await BunSQLite.select< - BUN_SQLITE_WGUI_VARIABLES, - TableType - >({ table: "variables" }); - return { props: { host, clients: host_clients.payload || null, - variables: variables_res.payload || null, }, }; }; -export default server; \ No newline at end of file +export default server; diff --git a/src/pages/admin/hosts/[host_id]/index.tsx b/src/pages/admin/hosts/[host_id]/index.tsx index 2b1fc6b..9f31dd0 100644 --- a/src/pages/admin/hosts/[host_id]/index.tsx +++ b/src/pages/admin/hosts/[host_id]/index.tsx @@ -1,6 +1,7 @@ import type { BunextPageModuleMeta } from "@moduletrace/bunext/types"; import { useContext } from "react"; import AdminHero from "@/src/components/general/admin-hero"; +import DeleteHostButton from "@/src/components/general/delete-host-button"; import { SiteData } from "@/src/data/site-data"; import Button from "@/src/components/twui/layout/Button"; import Divider from "@/src/components/twui/layout/Divider"; @@ -17,11 +18,8 @@ export default function AdminSingleHostPage() { const host_id = Number(query?.host_id || pageProps?.host?.id || 0); const host = pageProps?.host || undefined; - const variables = pageProps?.variables || []; const clients = pageProps?.clients || []; - const is_main_host = !host || host_id == 0; - if (!pageProps?.host && host_id != 0) { return ( <> @@ -37,13 +35,23 @@ export default function AdminSingleHostPage() { ); } + const title = host_id == 0 ? "Main Host" : `Host #${host_id}`; + return ( <> + - + } /> @@ -76,26 +76,12 @@ export default function AdminSingleHostPage() { - + v.key == "main_host_public_ip_address", - )?.value || - "" - } - /> - + ); @@ -104,4 +90,4 @@ export default function AdminSingleHostPage() { export const meta: BunextPageModuleMeta = { title: `Host | ${SiteData["SiteName"]}`, description: `WireGuard host page`, -}; \ No newline at end of file +}; diff --git a/src/pages/admin/hosts/add/(functions)/submit-add-host-form.ts b/src/pages/admin/hosts/add/(functions)/submit-add-host-form.ts index b88d514..02ee276 100644 --- a/src/pages/admin/hosts/add/(functions)/submit-add-host-form.ts +++ b/src/pages/admin/hosts/add/(functions)/submit-add-host-form.ts @@ -8,6 +8,8 @@ export default async function submitAddHostForm({ setLoading, setStatus, form, + app_context, + clearLocalForm, }: ReturnType>) { try { if (!window.confirm("Create this new host?")) { @@ -26,12 +28,17 @@ export default async function submitAddHostForm({ interface: form.interface || "", name: form.name || "", short_description: form.short_description || "", - listen_port: form.listen_port != null ? Number(form.listen_port) : null, + listen_port: + form.listen_port != null + ? Number(form.listen_port) + : null, + is_main_host: app_context.pageProps?.is_main_host, }, }, ); - if (res.success && res.numberRes) { + if (res.success) { + clearLocalForm(); window.location.pathname = `/admin/hosts/${res.numberRes}`; return; } @@ -46,4 +53,4 @@ export default async function submitAddHostForm({ setLoading(false); } -} \ No newline at end of file +} diff --git a/src/pages/admin/hosts/add/(partials)/add-host-form/add-host-form-name.tsx b/src/pages/admin/hosts/add/(partials)/add-host-form/add-host-form-name.tsx index 541414a..dff1fe7 100644 --- a/src/pages/admin/hosts/add/(partials)/add-host-form/add-host-form-name.tsx +++ b/src/pages/admin/hosts/add/(partials)/add-host-form/add-host-form-name.tsx @@ -20,6 +20,7 @@ export default function AddHostFormName({ form, setForm }: Props) { name: v, })); }} + required /> ); diff --git a/src/pages/admin/hosts/add/index.server.ts b/src/pages/admin/hosts/add/index.server.ts index a309e77..a00904f 100644 --- a/src/pages/admin/hosts/add/index.server.ts +++ b/src/pages/admin/hosts/add/index.server.ts @@ -1,16 +1,31 @@ +import type { BUN_SQLITE_WGUI_HOSTS } from "@/db/types/db"; +import { AppData } from "@/src/data/app-data"; import getNextAvailableListenPort from "@/src/functions/backend/setup/get-next-available-listen-port"; import grabHostNetworkInterfaces from "@/src/functions/backend/setup/grab-host-network-interfaces"; -import type { PagePropsType } from "@/src/types"; +import type { PagePropsType, TableType } from "@/src/types"; +import BunSQLite from "@moduletrace/bun-sqlite"; import type { BunextPageServerFn } from "@moduletrace/bunext/types"; const server: BunextPageServerFn = async ({ req }) => { const network_interfaces = await grabHostNetworkInterfaces(); const next_listen_port = await getNextAvailableListenPort(); + const main_host_record_res = await BunSQLite.select< + BUN_SQLITE_WGUI_HOSTS, + TableType + >({ + table: "hosts", + targetId: AppData["WireguardMainHostID"], + }); + + const main_host_record = main_host_record_res.singleRes || null; + return { props: { network_interfaces, next_listen_port, + is_main_host: + main_host_record?.id !== AppData["WireguardMainHostID"], }, }; }; diff --git a/src/pages/admin/hosts/add/index.tsx b/src/pages/admin/hosts/add/index.tsx index 0691fd5..ec0c0a2 100644 --- a/src/pages/admin/hosts/add/index.tsx +++ b/src/pages/admin/hosts/add/index.tsx @@ -6,13 +6,30 @@ import Divider from "@/src/components/twui/layout/Divider"; import Stack from "@/src/components/twui/layout/Stack"; import { ArrowLeft } from "lucide-react"; import AddHostFormSection from "./(sections)/add-host-form-section"; +import { useContext } from "react"; +import { AppContext } from "@/src/pages/__root"; export default function AdminAddHostPage() { + const { pageProps } = useContext(AppContext); + return ( <> + Create the main wireguard host (wgui0){" "} + for this server + + ) : ( + "Create a new WireGuard host with a dedicated private subnet" + ) + } buttons={ - @@ -73,49 +28,10 @@ export default function AdminHostPage() { - -

Main Host

- - - - - -
- - - -
- - -

Other Hosts

- {other_hosts[0] ? ( + {hosts?.[0] ? ( - {other_hosts.map((host) => ( - ( + = async (ctx) => { + const props = ctx.props as PagePropsType; + + if (!props.main_host?.name) { + return { + redirect: { + destination: `/admin/hosts/add`, + permanent: false, + }, + }; + } + + return { + props: {}, + }; +}; + +export default server; diff --git a/src/pages/admin/index.tsx b/src/pages/admin/index.tsx index c84b90d..cc31d4c 100644 --- a/src/pages/admin/index.tsx +++ b/src/pages/admin/index.tsx @@ -8,7 +8,7 @@ import KpiSecondarySection from "./(sections)/kpi-secondary-section"; import PeersTableSection from "./(sections)/peers-table-section"; export default function AdminDashboardPage() { - const { clients, hosts, variables } = useDashboardData(); + const { clients, hosts } = useDashboardData(); return ( <> @@ -21,7 +21,6 @@ export default function AdminDashboardPage() { diff --git a/src/pages/admin/setup/index.tsx b/src/pages/admin/setup/index.tsx new file mode 100644 index 0000000..a639e40 --- /dev/null +++ b/src/pages/admin/setup/index.tsx @@ -0,0 +1,23 @@ +import type { BunextPageModuleMeta } from "@moduletrace/bunext/types"; +import AdminHero from "@/src/components/general/admin-hero"; +import { SiteData } from "@/src/data/site-data"; +import Divider from "@/src/components/twui/layout/Divider"; +import Stack from "@/src/components/twui/layout/Stack"; + +export default function AdminWireguardSetupPage() { + return ( + <> + + + + + ); +} + +export const meta: BunextPageModuleMeta = { + title: `Admin Wireguard Setup | ${SiteData["SiteName"]}`, + description: `Setup wireguard and wg-ui. Check if dependencies are installed. Update wg-ui and related packages. Etc.`, +}; diff --git a/src/pages/api/admin/add-host.ts b/src/pages/api/admin/add-host.ts index 476a7c4..724be60 100644 --- a/src/pages/api/admin/add-host.ts +++ b/src/pages/api/admin/add-host.ts @@ -47,6 +47,7 @@ export const handler: BunextAPIRouteHandler = async ( short_description: body?.short_description, listen_port: body?.listen_port, user, + is_main_host: body.is_main_host || undefined, }); } catch (error: any) { return { @@ -54,4 +55,4 @@ export const handler: BunextAPIRouteHandler = async ( msg: error.message, }; } -}; \ No newline at end of file +}; diff --git a/src/pages/api/admin/delete-host.ts b/src/pages/api/admin/delete-host.ts new file mode 100644 index 0000000..83aac8e --- /dev/null +++ b/src/pages/api/admin/delete-host.ts @@ -0,0 +1,60 @@ +import checkUserAccess from "@/src/functions/backend/auth/check-user-access"; +import userAuth from "@/src/functions/backend/auth/user-auth"; +import deleteWireguardHost from "@/src/functions/backend/setup/delete-wireguard-host"; +import type { ApiReqParams } from "@/src/types"; +import type { + APIResponseObject, + BunextAPIRouteHandler, +} from "@moduletrace/bunext/types"; + +export const handler: BunextAPIRouteHandler = async ( + params, +) => { + const req = params.req; + const body = params.body as ApiReqParams; + + if (req.method !== "DELETE") { + return { + success: false, + }; + } + + const { user, user_types } = await userAuth({ req }); + + if (!user?.logged_in_status) { + return { + success: false, + msg: `Unauthorized`, + logoutUser: true, + }; + } + + try { + const is_super_admin = checkUserAccess({ user_types }); + + if (!is_super_admin.success) { + return { + success: false, + msg: `Unauthorized`, + }; + } + + const host_id = body?.host_id; + + if (typeof host_id !== "number" && typeof host_id !== "string") { + throw new Error(`Please pass host ID to be deleted!`); + } + + const delete_host_res = await deleteWireguardHost({ + host_id: Number(host_id), + user, + }); + + return delete_host_res; + } catch (error: any) { + return { + success: false, + msg: error.message, + }; + } +}; diff --git a/src/pages/api/admin/setup-main-host.ts b/src/pages/api/admin/setup-main-host.ts index 4e8e84c..377a524 100644 --- a/src/pages/api/admin/setup-main-host.ts +++ b/src/pages/api/admin/setup-main-host.ts @@ -1,12 +1,11 @@ import checkUserAccess from "@/src/functions/backend/auth/check-user-access"; import userAuth from "@/src/functions/backend/auth/user-auth"; -import setupWireguardHost from "@/src/functions/backend/setup/setup-wireguard-host"; +import createWireguardHost from "@/src/functions/backend/setup/create-wireguard-host"; import type { ApiReqParams } from "@/src/types"; import type { APIResponseObject, BunextAPIRouteHandler, } from "@moduletrace/bunext/types"; -import _ from "lodash"; export const handler: BunextAPIRouteHandler = async ( params, @@ -40,11 +39,12 @@ export const handler: BunextAPIRouteHandler = async ( }; } - return await setupWireguardHost({ - host: { - wg_ip_address: body.ip_address, - }, + return await createWireguardHost({ + wg_ip_address: body.ip_address, + interface: body.interface, + name: "Main", user, + is_main_host: true, }); } catch (error: any) { return { diff --git a/src/types/index.ts b/src/types/index.ts index 40d1e52..414712d 100755 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -67,6 +67,9 @@ export type PagePropsType = { main_host_dir_names?: ReturnType | null; network_interfaces?: string[] | null; next_listen_port?: number | null; + is_main_host?: boolean | null; + main_host?: BUN_SQLITE_WGUI_HOSTS | null; + next_available_client_ip?: string | null; }; export type AppContextObject = { @@ -262,6 +265,7 @@ export type ApiReqParams< ip_address?: string; wg_ip_address?: string | null; + is_main_host?: boolean | null; }; export type UserAuthReturn = {