From 8bcb5d06cadc1030f4f9763388eb37a46a523f9d Mon Sep 17 00:00:00 2001 From: "Philip H." <47042125+pheiduck@users.noreply.github.com> Date: Sun, 21 Jan 2024 13:31:17 +0000 Subject: [PATCH] fixup: lint errors --- src/config.js | 16 ++++++++-------- src/lib/Server.js | 2 +- src/lib/Util.js | 2 +- src/lib/WireGuard.js | 12 ++++++------ src/www/js/api.js | 1 + src/www/js/app.js | 2 +- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/config.js b/src/config.js index 31def814..30644513 100644 --- a/src/config.js +++ b/src/config.js @@ -1,7 +1,7 @@ 'use strict'; -const { release } = require('./package.json'); const childProcess = require('child_process'); +const { release } = require('./package.json'); module.exports.RELEASE = release; module.exports.PORT = process.env.PORT || 51821; @@ -26,22 +26,22 @@ module.exports.WG_ALLOWED_IPS = process.env.WG_ALLOWED_IPS || '0.0.0.0/0, ::/0'; // Set WG_POST_UP to allow IPv6 NAT and forwarding only if the required kernel module is available const modules = childProcess.execSync('lsmod', { shell: 'bash', -}) -module.exports.WG_POST_UP = process.env.WG_POST_UP +}); +module.exports.WG_POST_UP = process.env.WG_POST_UP; if (!process.env.WG_POST_UP) { module.exports.WG_POST_UP = ` iptables -t nat -A POSTROUTING -s ${module.exports.WG_DEFAULT_ADDRESS.replace('x', '0')}/24 -o eth0 -j MASQUERADE; iptables -A INPUT -p udp -m udp --dport 51820 -j ACCEPT; iptables -A FORWARD -i wg0 -j ACCEPT; - iptables -A FORWARD -o wg0 -j ACCEPT;` - - if (modules.includes("ip6table_nat")) { + iptables -A FORWARD -o wg0 -j ACCEPT;`; + + if (modules.includes('ip6table_nat')) { module.exports.WG_POST_UP += `ip6tables -t nat -A POSTROUTING -s ${module.exports.WG_DEFAULT_ADDRESS6.replace('x', '0')}/64 -o eth0 -j MASQUERADE; ip6tables -A INPUT -p udp -m udp --dport 51820 -j ACCEPT; ip6tables -A FORWARD -i wg0 -j ACCEPT; - ip6tables -A FORWARD -o wg0 -j ACCEPT;` + ip6tables -A FORWARD -o wg0 -j ACCEPT;`; } - + module.exports.WG_POST_UP = module.exports.WG_POST_UP.split('\n').join(' '); } diff --git a/src/lib/Server.js b/src/lib/Server.js index 459d55c9..94fbc98a 100644 --- a/src/lib/Server.js +++ b/src/lib/Server.js @@ -158,7 +158,7 @@ module.exports = class Server { const { name } = req.body; return WireGuard.updateClientName({ clientId, name }); })) - .put('/api/wireguard/client/:clientId/address6', Util.promisify(async req => { + .put('/api/wireguard/client/:clientId/address6', Util.promisify(async (req) => { const { clientId } = req.params; const { address6 } = req.body; return WireGuard.updateClientAddress6({ clientId, address6 }); diff --git a/src/lib/Util.js b/src/lib/Util.js index 28084637..d63ef641 100644 --- a/src/lib/Util.js +++ b/src/lib/Util.js @@ -19,7 +19,7 @@ module.exports = class Util { static isValidIPv6(str) { // Regex source : https://stackoverflow.com/a/17871737 - const regex = new RegExp('^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$'); + const regex = new RegExp('^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$'); const matches = str.match(regex); return !!matches; } diff --git a/src/lib/WireGuard.js b/src/lib/WireGuard.js index 560d027c..099bc5bf 100644 --- a/src/lib/WireGuard.js +++ b/src/lib/WireGuard.js @@ -48,14 +48,14 @@ module.exports = class WireGuard { log: 'echo ***hidden*** | wg pubkey', }); const address = WG_DEFAULT_ADDRESS.replace('x', '1'); - const address6 = WG_DEFAULT_ADDRESS6.replace('x', '1'); + const address6 = WG_DEFAULT_ADDRESS6.replace('x', '1'); config = { server: { privateKey, publicKey, address, - address6, + address6, }, clients: {}, }; @@ -79,7 +79,7 @@ module.exports = class WireGuard { // await Util.exec('ip6tables -A INPUT -p udp -m udp --dport 51820 -j ACCEPT'); // await Util.exec('ip6tables -A FORWARD -i wg0 -j ACCEPT'); // await Util.exec('ip6tables -A FORWARD -o wg0 -j ACCEPT'); - await this.__syncConfig(); + await this.__syncConfig(); return config; }); @@ -119,7 +119,7 @@ PostDown = ${WG_POST_DOWN} [Peer] PublicKey = ${client.publicKey} PresharedKey = ${client.preSharedKey} -AllowedIPs = ${client.address}/32, ${client.address6}/128`; +AllowedIPs = ${client.address}/32, ${client.address6}/128`; } debug('Config saving...'); @@ -205,7 +205,7 @@ AllowedIPs = ${client.address}/32, ${client.address6}/128`; const config = await this.getConfig(); const client = await this.getClient({ clientId }); const isDnsSet = WG_DEFAULT_DNS || WG_DEFAULT_DNS6; - const dnsServers = [WG_DEFAULT_DNS, WG_DEFAULT_DNS6].filter(item => !!item).join(', ') + const dnsServers = [WG_DEFAULT_DNS, WG_DEFAULT_DNS6].filter((item) => !!item).join(', '); return ` [Interface] @@ -260,7 +260,7 @@ Endpoint = ${WG_HOST}:${WG_PORT}`; let address6; for (let i = 2; i < 255; i++) { - const client = Object.values(config.clients).find(client => { + const client = Object.values(config.clients).find((client) => { return client.address6 === WG_DEFAULT_ADDRESS6.replace('x', i.toString(16)); }); diff --git a/src/www/js/api.js b/src/www/js/api.js index 40dfbaf3..a226172e 100644 --- a/src/www/js/api.js +++ b/src/www/js/api.js @@ -131,4 +131,5 @@ class API { body: { address6 }, }); } + } diff --git a/src/www/js/app.js b/src/www/js/app.js index de739ca8..eedc72ce 100644 --- a/src/www/js/app.js +++ b/src/www/js/app.js @@ -252,7 +252,7 @@ new Vue({ }, updateClientAddress6(client, address6) { this.api.updateClientAddress6({ clientId: client.id, address6 }) - .catch(err => alert(err.message || err.toString())) + .catch((err) => alert(err.message || err.toString())) .finally(() => this.refresh().catch(console.error)); }, toggleTheme() {