diff --git a/docs/changelog.json b/docs/changelog.json index 49fc7d853..7de643c99 100644 --- a/docs/changelog.json +++ b/docs/changelog.json @@ -1,3 +1,3 @@ { - "1": "Initial version. Enjoy!" + "1.1": "Adding change allowedIPS :)" } diff --git a/src/lib/Server.js b/src/lib/Server.js index eaf34cfba..a9b3047db 100644 --- a/src/lib/Server.js +++ b/src/lib/Server.js @@ -171,6 +171,14 @@ module.exports = class Server { const { address } = req.body; return WireGuard.updateClientAddress({ clientId, address }); })) + .put('/api/wireguard/client/:clientId/allowedips', Util.promisify(async (req, res) => { + const { clientId } = req.params; + if (clientId === '__proto__' || clientId === 'constructor' || clientId === 'prototype') { + res.end(403); + } + const { ips } = req.body; + return WireGuard.updateClientAllowedIPS({ clientId, ips }); + })) .listen(PORT, WEBUI_HOST, () => { debug(`Listening on http://${WEBUI_HOST}:${PORT}`); diff --git a/src/lib/WireGuard.js b/src/lib/WireGuard.js index 267a16d6e..95305e498 100644 --- a/src/lib/WireGuard.js +++ b/src/lib/WireGuard.js @@ -143,13 +143,14 @@ H4 = ${config.server.h4} for (const [clientId, client] of Object.entries(config.clients)) { if (!client.enabled) continue; + let allowedips_adding = client.allowedIPs ? ',' + client.allowedIPs : ''; result += ` # Client: ${client.name} (${clientId}) [Peer] PublicKey = ${client.publicKey} PresharedKey = ${client.preSharedKey} -AllowedIPs = ${client.address}/32`; +AllowedIPs = ${client.address}/32 ${allowedips_adding}`; } debug('Config saving...'); @@ -214,6 +215,7 @@ AllowedIPs = ${client.address}/32`; : new Date(Number(`${latestHandshakeAt}000`)); client.transferRx = Number(transferRx); client.transferTx = Number(transferTx); + client.allowedIPs = allowedIps; client.persistentKeepalive = persistentKeepalive; }); @@ -365,4 +367,13 @@ Endpoint = ${WG_HOST}:${WG_PORT}`; await this.saveConfig(); } + async updateClientAllowedIPS({ clientId, ips }) { + const client = await this.getClient({ clientId }); + + client.allowedIPs = ips; + client.updatedAt = new Date(); + + await this.saveConfig(); + } + }; diff --git a/src/www/css/app.css b/src/www/css/app.css index 2bd442619..779f21bd0 100644 --- a/src/www/css/app.css +++ b/src/www/css/app.css @@ -826,6 +826,10 @@ video { width: 5rem; } +.w-40 { + width: 10rem; +} + .w-4 { width: 1rem; } diff --git a/src/www/index.html b/src/www/index.html index e9d419d73..2913e214c 100644 --- a/src/www/index.html +++ b/src/www/index.html @@ -2,12 +2,13 @@
-