revert: custom interface PR: #700

This commit is contained in:
Philip H. 2023-12-30 18:35:37 +00:00 committed by GitHub
parent 2eb276a836
commit e1dfc0ff19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 16 deletions

View file

@ -23,7 +23,6 @@ const {
WG_POST_UP,
WG_PRE_DOWN,
WG_POST_DOWN,
WG_INTERFACE,
} = require('../config');
module.exports = class WireGuard {
@ -60,18 +59,18 @@ module.exports = class WireGuard {
}
await this.__saveConfig(config);
await Util.exec(`wg-quick down ${WG_INTERFACE}`).catch(() => { });
await Util.exec(`wg-quick up ${WG_INTERFACE}`).catch((err) => {
if (err && err.message && err.message.includes(`Cannot find device ${WG_INTERFACE}`)) {
throw new Error(`WireGuard exited with the error: Cannot find device ${WG_INTERFACE}\nThis usually means that your host's kernel does not support WireGuard!`);
await Util.exec('wg-quick down wg0').catch(() => { });
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!');
}
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 -t nat -A POSTROUTING -s ${WG_DEFAULT_ADDRESS.replace('x', '0')}/24 -o eth0 -j MASQUERADE`);
// await Util.exec('iptables -A INPUT -p udp -m udp --dport 51820 -j ACCEPT');
// await Util.exec('iptables -A FORWARD -i ' + WG_INTERFACE + ' -j ACCEPT');
// await Util.exec('iptables -A FORWARD -o ' + WG_INTERFACE + ' -j ACCEPT');
// await Util.exec('iptables -A FORWARD -i wg0 -j ACCEPT');
// await Util.exec('iptables -A FORWARD -o wg0 -j ACCEPT');
await this.__syncConfig();
return config;
@ -119,7 +118,7 @@ AllowedIPs = ${client.address}/32`;
await fs.writeFile(path.join(WG_PATH, 'wg0.json'), JSON.stringify(config, false, 2), {
mode: 0o660,
});
await fs.writeFile(path.join(WG_PATH, `${WG_INTERFACE}.conf`), result, {
await fs.writeFile(path.join(WG_PATH, 'wg0.conf'), result, {
mode: 0o600,
});
debug('Config saved.');
@ -127,7 +126,7 @@ AllowedIPs = ${client.address}/32`;
async __syncConfig() {
debug('Config syncing...');
await Util.exec(`wg syncconf ${WG_INTERFACE} <(wg-quick strip ${WG_INTERFACE})`);
await Util.exec('wg syncconf wg0 <(wg-quick strip wg0)');
debug('Config synced.');
}
@ -150,7 +149,7 @@ AllowedIPs = ${client.address}/32`;
}));
// Loop WireGuard status
const dump = await Util.exec(`wg show ${WG_INTERFACE} dump`, {
const dump = await Util.exec('wg show wg0 dump', {
log: false,
});
dump