From 001c07499e7d548fd2d6f91bbe55518c0afdcfde Mon Sep 17 00:00:00 2001 From: "Philip H." <47042125+pheiduck@users.noreply.github.com> Date: Mon, 25 Dec 2023 23:51:44 +0000 Subject: [PATCH] WireGuard.js: changes from https://github.com/wg-easy/wg-easy/pull/328 --- src/lib/WireGuard.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/lib/WireGuard.js b/src/lib/WireGuard.js index 96e628be..ef19cf27 100644 --- a/src/lib/WireGuard.js +++ b/src/lib/WireGuard.js @@ -60,12 +60,20 @@ module.exports = class WireGuard { await this.__saveConfig(config); await Util.exec('wg-quick down wg0').catch(() => { }); - await Util.exec('wireguard-go wg0').catch((err) => { + await Util.exec('wg-quick up wg0').catch((err) => { if (err && err.message && err.message.includes('Cannot find device "wg0"')) { - throw new Error('WireGuard exited with the error: Cannot find device "wg0"\nThis usually means that your host\'s kernel does not support WireGuard!'); + debug('WireGuard exited with the error: Cannot find device "wg0"\nThis usually means that your host\'s kernel does not support WireGuard! Trying to use wireguard-go implementation.'); + Util.exec('cp -f /wireguard-go/wg /wireguard-go/wg-quick /wireguard-go/wireguard-go /usr/bin/').catch(() => { }); + Util.exec('wg-quick up wg0').catch((err) => { + if (err && err.message && err.message.includes('Cannot find device "wg0"')) { + throw new Error('WireGuard exited with the error: Cannot find device "wg0"\nThis means, that even wireguard-go does not work!\nThis usually means that you didn\'t mounted /dev/net/tun to container properly!'); + } + + throw err; + }); + } else { + throw err; } - - throw err; }); // await Util.exec(`iptables -t nat -A POSTROUTING -s ${WG_DEFAULT_ADDRESS.replace('x', '0')}/24 -o ' + WG_DEVICE + ' -j MASQUERADE`); // await Util.exec('iptables -A INPUT -p udp -m udp --dport 51820 -j ACCEPT');