Fix host private key read and peer AllowedIPs in wireguard host setup

This commit is contained in:
2026-09-13 07:26:33 +01:00
parent 94dfcf6e43
commit 0ecac621c5
@@ -58,25 +58,31 @@ export default async function setupWireguardHost({
};
}
try {
const HOST_PUBLIC_KEY = host?.id
? host.public_key
: execSync(
`cat ${path.join(WIREGUARD_HOST_CONFIG_DIR, WIREGUARD_PUBLIC_KEY_FILE_NAME)}`,
);
const HOST_PRIVATE_KEY = host?.id
? host.public_key
const HOST_PRIVATE_KEY = host?.private_key
? host.private_key
: execSync(
`cat ${path.join(WIREGUARD_HOST_CONFIG_DIR, WIREGUARD_PRIVATE_KEY_FILE_NAME)}`,
);
let sh = ``;
const POST_UP_PATH = path.join(WGUI_LIB_IP_TABLES_DIR, `${host_id}-up.sh`);
const POST_UP_PATH = path.join(
WGUI_LIB_IP_TABLES_DIR,
`${host_id}-up.sh`,
);
const POST_DOWN_PATH = path.join(
WGUI_LIB_IP_TABLES_DIR,
`${host_id}-down.sh`,
);
sh += `cd ${WIREGUARD_HOST_CONFIG_DIR}\n`;
sh += `cat > ${POST_UP_PATH} << EOF\n`;
sh += `#!/bin/bash\n\n`;
sh += `# Allow WireGuard traffic to/from the server itself\n`;
@@ -119,11 +125,11 @@ export default async function setupWireguardHost({
if (clients[0]) {
for (let i = 0; i < clients.length; i++) {
const client = clients[i];
if (!client?.id || !client.public_key || !client.private_key)
continue;
if (!client?.id || !client.public_key) continue;
sh += `[Peer]\n`;
sh += `PublicKey = ${client.public_key}\n`;
sh += `AllowedIPs = ${client.allowed_ips}\n`;
sh += `\n`;
}
}
@@ -132,7 +138,6 @@ export default async function setupWireguardHost({
sh += `\n`;
try {
const exec = execSync(sh, { encoding: "utf-8" });
} catch (error: any) {
return {