Initialize client forms

This commit is contained in:
2026-09-17 07:22:20 +01:00
parent e0d105beb9
commit 90ee3debf0
28 changed files with 584 additions and 145 deletions
@@ -2,16 +2,12 @@ import { AppData } from "@/src/data/app-data";
import deriveWireguardInterfaceName from "@/src/utils/derive-wireguard-interface-name";
import type {
BUN_SQLITE_WGUI_CLIENTS,
BUN_SQLITE_WGUI_HOSTS,
BUN_SQLITE_WGUI_VARIABLES,
} from "@/db/types/db";
const LISTEN_PORT = 51820;
const IP_TABLES_DIR = `/var/lib/wgui/iptables`;
const HOSTS_CONFIG_DIR = `/var/lib/wgui/hosts`;
import type { BUN_SQLITE_WGUI_HOSTS_JOIN } from "@/src/types/sql-joins";
type Params = {
host?: BUN_SQLITE_WGUI_HOSTS;
host?: BUN_SQLITE_WGUI_HOSTS_JOIN;
variables?: BUN_SQLITE_WGUI_VARIABLES[];
clients?: BUN_SQLITE_WGUI_CLIENTS[];
};
@@ -23,18 +19,42 @@ export default function deriveHostConfig({ host, variables, clients }: Params) {
host?.wg_ip_address ||
variables?.find((v) => v.key == "main_host_wg_ip_address")?.value;
const public_key =
host?.public_key ||
variables?.find((v) => v.key == "main_host_wg_public_key")?.value;
const interface_name = deriveWireguardInterfaceName({ host_id });
// const HOST_CONFIG_DIR = path.join(
// WGUI_LIB_HOSTS_CONFIGS_DIR,
// String(host_id),
// );
// const HOST_CLIENTS_DIR = path.join(
// HOST_CONFIG_DIR,
// WGUI_LIB_HOST_CLIENTS_DIR_NAME,
// );
// const HOST_IPTABLES_DIR = path.join(
// HOST_CONFIG_DIR,
// WGUI_LIB_HOST_IPTABLES_DIR_NAME,
// );
// const HOST_CONFIG_FILE = path.join(
// HOST_CONFIG_DIR,
// `${interface_name}.conf`,
// );
return {
host_id,
interface_name,
config_path: `${HOSTS_CONFIG_DIR}/${interface_name}.conf`,
config_path: host?.dir_names?.HOST_CONFIG_FILE,
address: wg_ip_address ? `${wg_ip_address}/24` : undefined,
listen_port: LISTEN_PORT,
post_up: `${IP_TABLES_DIR}/${host_id}-up.sh`,
post_down: `${IP_TABLES_DIR}/${host_id}-down.sh`,
public_key: host?.public_key,
listen_port: AppData["DefaultWGListenPort"],
post_up: host?.dir_names?.POST_UP_PATH,
post_down: host?.dir_names?.POST_DOWN_PATH,
public_key: public_key,
client_count:
clients?.filter((client) => (client.host_id || 0) == host_id)
.length || 0,