Browse Source

Merge branch of upstream

pull/708/head
Astound 3 years ago
parent
commit
5848cb219c
No known key found for this signature in database GPG Key ID: 97504AF0027B1A56
  1. 1
      .gitignore
  2. 3
      README.md
  3. 1
      docker-compose.yml
  4. 9
      src/config.js
  5. 15
      src/lib/WireGuard.js
  6. 1061
      src/package-lock.json
  7. 1
      src/package.json

1
.gitignore

@ -1,3 +1,4 @@
/config
/wg0.conf
/wg0.json
.DS_Store

3
README.md

@ -88,7 +88,8 @@ These options can be configured by setting environment variables using `-e KEY="
| `PASSWORD` | - | `foobar123` | When set, requires a password when logging in to the Web UI. |
| `WG_HOST` | - | `vpn.myserver.com` | The public hostname of your VPN server. |
| `WG_DEVICE` | `eth0` | `ens6f0` | Ethernet device the wireguard traffic should be forwarded through. |
| `WG_PORT` | `51820` | `12345` | The public UDP port of your VPN server. WireGuard will always listen on `51820` inside the Docker container. |
| `WG_PORT` | `51820` | `12345` | The public UDP port of your VPN server. This will also change the port wireguard will listen to. |
| `WG_INTERFACE` | `wg0` | `wg1` | The interface wireguard will use in the container. (Only needed if `network_mode: host` or `--net=host` is used) |
| `WG_MTU` | `null` | `1420` | The MTU the clients will use. Server uses default WG MTU. |
| `WG_PERSISTENT_KEEPALIVE` | `0` | `25` | Value in seconds to keep the "connection" open. If this value is 0, then connections won't be kept alive. |
| `WG_DEFAULT_ADDRESS` | `10.8.0.x` | `10.6.0.x` | Clients IPv4 address range. |

1
docker-compose.yml

@ -12,6 +12,7 @@ services:
# Optional:
# - PASSWORD=foobar123
# - WG_PORT=51820
# - WG_INTERFACE=wg0
# - WG_DEFAULT_ADDRESS=10.8.0.x
# - WG_DEFAULT_ADDRESS6=fd42:42:42::x
# - WG_DEFAULT_DNS=1.1.1.1

9
src/config.js

@ -8,6 +8,7 @@ module.exports.WEBUI_HOST = process.env.WEBUI_HOST || '0.0.0.0';
module.exports.PASSWORD = process.env.PASSWORD;
module.exports.WG_PATH = process.env.WG_PATH || '/etc/wireguard/';
module.exports.WG_DEVICE = process.env.WG_DEVICE || 'eth0';
module.exports.WG_INTERFACE = process.env.WG_INTERFACE || 'wg0';
module.exports.WG_HOST = process.env.WG_HOST;
module.exports.WG_PORT = process.env.WG_PORT || 51820;
module.exports.WG_MTU = process.env.WG_MTU || null;
@ -26,12 +27,12 @@ module.exports.WG_PRE_UP = process.env.WG_PRE_UP || '';
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 ${module.exports.WG_DEVICE} -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;
iptables -A FORWARD -i ${module.exports.WG_INTERFACE} -j ACCEPT;
iptables -A FORWARD -o ${module.exports.WG_INTERFACE} -j ACCEPT;
ip6tables -t nat -A POSTROUTING -s ${module.exports.WG_DEFAULT_ADDRESS6.replace('x', '0')}/64 -o ${module.exports.WG_DEVICE} -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 -i ${module.exports.WG_INTERFACE} -j ACCEPT;
ip6tables -A FORWARD -o ${module.exports.WG_INTERFACE} -j ACCEPT;
`.split('\n').join(' ');
module.exports.WG_PRE_DOWN = process.env.WG_PRE_DOWN || '';

15
src/lib/WireGuard.js

@ -25,6 +25,7 @@ const {
WG_POST_UP,
WG_PRE_DOWN,
WG_POST_DOWN,
WG_INTERFACE,
} = require('../config');
module.exports = class WireGuard {
@ -63,10 +64,10 @@ module.exports = class WireGuard {
}
await this.__saveConfig(config);
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!');
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!`);
}
throw err;
@ -118,7 +119,7 @@ AllowedIPs = ${client.address}/32, ${client.address6}/128`;
await fs.writeFile(path.join(WG_PATH, 'wg0.json'), JSON.stringify(config, false, 2), {
mode: 0o660,
});
await fs.writeFile(path.join(WG_PATH, 'wg0.conf'), result, {
await fs.writeFile(path.join(WG_PATH, `${WG_INTERFACE}.conf`), result, {
mode: 0o600,
});
debug('Config saved.');
@ -126,7 +127,7 @@ AllowedIPs = ${client.address}/32, ${client.address6}/128`;
async __syncConfig() {
debug('Config syncing...');
await Util.exec('wg syncconf wg0 <(wg-quick strip wg0)');
await Util.exec(`wg syncconf ${WG_INTERFACE} <(wg-quick strip ${WG_INTERFACE})`);
debug('Config synced.');
}
@ -150,7 +151,7 @@ AllowedIPs = ${client.address}/32, ${client.address6}/128`;
}));
// Loop WireGuard status
const dump = await Util.exec('wg show wg0 dump', {
const dump = await Util.exec(`wg show ${WG_INTERFACE} dump`, {
log: false,
});
dump

1061
src/package-lock.json

File diff suppressed because it is too large

1
src/package.json

@ -21,7 +21,6 @@
"uuid": "^9.0.1"
},
"devDependencies": {
"eslint": "^8.56.0",
"eslint-config-athom": "^3.1.3",
"tailwindcss": "^3.4.0"
},

Loading…
Cancel
Save