From 33aba0793dd99210574fa3a709c378d70ee3d0d8 Mon Sep 17 00:00:00 2001 From: Joel Heaps <13434824+joelheaps@users.noreply.github.com> Date: Fri, 28 Jan 2022 16:01:01 -0600 Subject: [PATCH] Eliminate redundant config in src/config.js Co-authored-by: crazyracer98 <8631139+crazyracer98@users.noreply.github.com> --- src/config.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/config.js b/src/config.js index 379333aa..404e9d26 100644 --- a/src/config.js +++ b/src/config.js @@ -26,24 +26,22 @@ const modules = childProcess.execSync('lsmod', { shell: 'bash', }) -if (modules.includes("ip6table_nat")) { - 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; - ip6tables -t nat -A POSTROUTING -s ${module.exports.WG_DEFAULT_ADDRESS6.replace('x', '0')}/64 -o eth0 -j MASQUERADE; + 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; - `.split('\n').join(' '); -} else { - module.exports.WG_POST_UP = process.env.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; - `.split('\n').join(' '); + ip6tables -A FORWARD -o wg0 -j ACCEPT;` + } + + module.exports.WG_POST_UP = module.exports.WG_POST_UP.split('\n').join(' '); }