Add host setup functions and client components
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { AppData } from "@/src/data/app-data";
|
||||
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`;
|
||||
|
||||
type Params = {
|
||||
host?: BUN_SQLITE_WGUI_HOSTS;
|
||||
variables?: BUN_SQLITE_WGUI_VARIABLES[];
|
||||
clients?: BUN_SQLITE_WGUI_CLIENTS[];
|
||||
};
|
||||
|
||||
export default function deriveHostConfig({
|
||||
host,
|
||||
variables,
|
||||
clients,
|
||||
}: Params) {
|
||||
const host_id = host?.id || AppData["WireguardHostID"];
|
||||
|
||||
const wg_ip_address =
|
||||
host?.wg_ip_address ||
|
||||
variables?.find((v) => v.key == "main_host_wg_ip_address")?.value;
|
||||
|
||||
return {
|
||||
host_id,
|
||||
interface_name: `wg${host_id}`,
|
||||
config_path: `/etc/wireguard/wg${host_id}.conf`,
|
||||
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`,
|
||||
private_key: host?.private_key,
|
||||
public_key: host?.public_key,
|
||||
client_count: clients?.filter(
|
||||
(client) => (client.host_id || 0) == host_id,
|
||||
).length || 0,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user