Fix host private key read and peer AllowedIPs in wireguard host setup
This commit is contained in:
@@ -58,25 +58,31 @@ export default async function setupWireguardHost({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const HOST_PUBLIC_KEY = host?.id
|
const HOST_PUBLIC_KEY = host?.id
|
||||||
? host.public_key
|
? host.public_key
|
||||||
: execSync(
|
: execSync(
|
||||||
`cat ${path.join(WIREGUARD_HOST_CONFIG_DIR, WIREGUARD_PUBLIC_KEY_FILE_NAME)}`,
|
`cat ${path.join(WIREGUARD_HOST_CONFIG_DIR, WIREGUARD_PUBLIC_KEY_FILE_NAME)}`,
|
||||||
);
|
);
|
||||||
const HOST_PRIVATE_KEY = host?.id
|
const HOST_PRIVATE_KEY = host?.private_key
|
||||||
? host.public_key
|
? host.private_key
|
||||||
: execSync(
|
: execSync(
|
||||||
`cat ${path.join(WIREGUARD_HOST_CONFIG_DIR, WIREGUARD_PRIVATE_KEY_FILE_NAME)}`,
|
`cat ${path.join(WIREGUARD_HOST_CONFIG_DIR, WIREGUARD_PRIVATE_KEY_FILE_NAME)}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
let sh = ``;
|
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(
|
const POST_DOWN_PATH = path.join(
|
||||||
WGUI_LIB_IP_TABLES_DIR,
|
WGUI_LIB_IP_TABLES_DIR,
|
||||||
`${host_id}-down.sh`,
|
`${host_id}-down.sh`,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
sh += `cd ${WIREGUARD_HOST_CONFIG_DIR}\n`;
|
||||||
|
|
||||||
sh += `cat > ${POST_UP_PATH} << EOF\n`;
|
sh += `cat > ${POST_UP_PATH} << EOF\n`;
|
||||||
sh += `#!/bin/bash\n\n`;
|
sh += `#!/bin/bash\n\n`;
|
||||||
sh += `# Allow WireGuard traffic to/from the server itself\n`;
|
sh += `# Allow WireGuard traffic to/from the server itself\n`;
|
||||||
@@ -119,11 +125,11 @@ export default async function setupWireguardHost({
|
|||||||
if (clients[0]) {
|
if (clients[0]) {
|
||||||
for (let i = 0; i < clients.length; i++) {
|
for (let i = 0; i < clients.length; i++) {
|
||||||
const client = clients[i];
|
const client = clients[i];
|
||||||
if (!client?.id || !client.public_key || !client.private_key)
|
if (!client?.id || !client.public_key) continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
sh += `[Peer]\n`;
|
sh += `[Peer]\n`;
|
||||||
sh += `PublicKey = ${client.public_key}\n`;
|
sh += `PublicKey = ${client.public_key}\n`;
|
||||||
|
sh += `AllowedIPs = ${client.allowed_ips}\n`;
|
||||||
sh += `\n`;
|
sh += `\n`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,7 +138,6 @@ export default async function setupWireguardHost({
|
|||||||
|
|
||||||
sh += `\n`;
|
sh += `\n`;
|
||||||
|
|
||||||
try {
|
|
||||||
const exec = execSync(sh, { encoding: "utf-8" });
|
const exec = execSync(sh, { encoding: "utf-8" });
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user