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 @@ - WireGuard + AmneziaWG by M1NDST0RM + - - + +
@@ -36,7 +37,7 @@

- AmneziaWG + AmneziaWG by M1NDST0RM

@@ -92,8 +93,8 @@

- + @@ -163,6 +164,31 @@

+
+ + + + + + AllowedIPS: {{client.allowedIPs}} + + + + + + + + @@ -318,8 +344,8 @@

- + @@ -429,15 +455,15 @@

- AmneziaWG + AmneziaWG by M1NDST0RM

- +
@@ -477,6 +503,19 @@

+

+ Разработка от     + +     + M1NDST0RM +

+

@@ -491,4 +530,4 @@

- + \ No newline at end of file diff --git a/src/www/js/api.js b/src/www/js/api.js index bb244e072..1dbcef7c5 100644 --- a/src/www/js/api.js +++ b/src/www/js/api.js @@ -131,4 +131,13 @@ class API { }); } + async updateClientAllowedIPS({ clientId, ips }) { + return this.call({ + method: 'put', + // path: `/wireguard/client/${clientId}/address/`, + path: `/wireguard/client/${clientId}/allowedips/`, + body: { ips }, + }); + } + } diff --git a/src/www/js/app.js b/src/www/js/app.js index 47e824180..20d9f030a 100644 --- a/src/www/js/app.js +++ b/src/www/js/app.js @@ -5,7 +5,7 @@ 'use strict'; -const CHANGELOG_URL = 'https://raw.githubusercontent.com/spcfox/amnezia-wg-easy/production/docs/changelog.json'; +const CHANGELOG_URL = 'https://raw.githubusercontent.com/mindst0rm/amneziawg-web-ui/master/docs/changelog.json'; function bytes(bytes, decimals, kib, maxunit) { kib = kib || false; @@ -49,6 +49,8 @@ new Vue({ clientEditNameId: null, clientEditAddress: null, clientEditAddressId: null, + clientEditAllowedIPS: null, + clientEditAllowedIPSId: null, qrcode: null, currentRelease: null, @@ -250,6 +252,11 @@ new Vue({ .catch((err) => alert(err.message || err.toString())) .finally(() => this.refresh().catch(console.error)); }, + updateClientAllowedIPS(client, ips) { + this.api.updateClientAllowedIPS({ clientId: client.id, ips }) + .catch((err) => alert(err.message || err.toString())) + .finally(() => this.refresh().catch(console.error)); + }, toggleTheme() { if (this.isDark) { localStorage.theme = 'light';