From 9f13f8322973b500a1d2326e2ae6b676e30145ef Mon Sep 17 00:00:00 2001 From: m1ndst0rm Date: Sat, 29 Jun 2024 15:13:28 +0000 Subject: [PATCH 1/3] Adding feature change and update AllowedIPS :3 --- docs/changelog.json | 1 + src/lib/Server.js | 8 ++++++ src/lib/WireGuard.js | 13 ++++++++- src/www/css/app.css | 4 +++ src/www/index.html | 63 +++++++++++++++++++++++++++++++++++--------- src/www/js/api.js | 9 +++++++ src/www/js/app.js | 7 +++++ 7 files changed, 92 insertions(+), 13 deletions(-) diff --git a/docs/changelog.json b/docs/changelog.json index 49fc7d853..b5257be43 100644 --- a/docs/changelog.json +++ b/docs/changelog.json @@ -1,3 +1,4 @@ { + "1.1": "Adding change allowedIPS :)", "1": "Initial version. Enjoy!" } 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..24b5f7731 100644 --- a/src/www/js/app.js +++ b/src/www/js/app.js @@ -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'; From e9e79554b5d9f50260ec5b14b8df60d115e34203 Mon Sep 17 00:00:00 2001 From: m1ndst0rm Date: Sat, 29 Jun 2024 15:56:50 +0000 Subject: [PATCH 2/3] update url for updates :) --- src/www/js/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/www/js/app.js b/src/www/js/app.js index 24b5f7731..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; From c56a60d371ca5c8a01c4f3e31d01b951b6b3d3a7 Mon Sep 17 00:00:00 2001 From: Kostya Popov <36366626+mindst0rm@users.noreply.github.com> Date: Sun, 30 Jun 2024 13:50:26 +0500 Subject: [PATCH 3/3] Up version 1.1 --- docs/changelog.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/changelog.json b/docs/changelog.json index b5257be43..7de643c99 100644 --- a/docs/changelog.json +++ b/docs/changelog.json @@ -1,4 +1,3 @@ { - "1.1": "Adding change allowedIPS :)", - "1": "Initial version. Enjoy!" + "1.1": "Adding change allowedIPS :)" }