From 7ecf7b08b1af22904ce05900411ce929f2b3376d Mon Sep 17 00:00:00 2001 From: Philip H <47042125+pheiduck@users.noreply.github.com> Date: Fri, 5 Jul 2024 22:42:38 +0200 Subject: [PATCH 01/29] fixup: typos --- How_to_generate_an_bcrypt_hash.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/How_to_generate_an_bcrypt_hash.md b/How_to_generate_an_bcrypt_hash.md index d2b69f59..bdd8de7b 100644 --- a/How_to_generate_an_bcrypt_hash.md +++ b/How_to_generate_an_bcrypt_hash.md @@ -31,9 +31,9 @@ pip3 install bcrypt --break-system-packages ```bash sudo dnf update sudo dnf install python3 python3-pip -# If you use have install python using apt +# If you use have install python using dnf sudo dnf install python3-bcrypt -# If don't install python using apt +# If don't install python using dnf pip3 install bcrypt # If you got externally-managed-environment error pip3 install bcrypt --break-system-packages @@ -43,9 +43,9 @@ pip3 install bcrypt --break-system-packages ```bash sudo pacman -Syy sudo pacman -S python python-pip -# If you use have install python using apt +# If you use have install python using pacman sudo pacman -S python-bcrypt -# If don't install python using apt +# If don't install python using pacman pip3 install bcrypt # If you got externally-managed-environment error pip3 install bcrypt --break-system-packages @@ -98,4 +98,4 @@ The hashed password for an docker env is: $$2b$$12$$NRiL4Kw4dKid.ix2WvZltOmaQBZj The docker line ``PASSWORD_HASH`` will be: ```txt PASSWORD_HASH=$$2b$$12$$NRiL4Kw4dKid.ix2WvZltOmaQBZjoX30shjHJXRVdEGshAxYWXXMe -``` \ No newline at end of file +``` From 378464a424c5109eb49ac17d3a8bce9c4a22c7d0 Mon Sep 17 00:00:00 2001 From: Philip H <47042125+pheiduck@users.noreply.github.com> Date: Sun, 7 Jul 2024 19:13:03 +0200 Subject: [PATCH 02/29] How_to_generate_an_bcrypt_hash.md: macos guide --- How_to_generate_an_bcrypt_hash.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/How_to_generate_an_bcrypt_hash.md b/How_to_generate_an_bcrypt_hash.md index bdd8de7b..acca38fe 100644 --- a/How_to_generate_an_bcrypt_hash.md +++ b/How_to_generate_an_bcrypt_hash.md @@ -51,6 +51,13 @@ pip3 install bcrypt pip3 install bcrypt --break-system-packages ``` +### macOS +```bash +pip3 install bcrypt +# If you got externally-managed-environment error +pip3 install bcrypt --break-system-packages +``` + ## Generating bcrypt hash from the command line You can use the following one-liner command to generate a bcrypt hash directly in the cmd/ terminal: ```bash From 6a588ee3facd141ab5e2d6f20447836bfd758c70 Mon Sep 17 00:00:00 2001 From: NPM Update Bot Date: Sun, 7 Jul 2024 17:13:42 +0000 Subject: [PATCH 03/29] npm: package updates --- src/package-lock.json | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/package-lock.json b/src/package-lock.json index 86c3e277..c12f06bd 100644 --- a/src/package-lock.json +++ b/src/package-lock.json @@ -2827,15 +2827,15 @@ "dev": true }, "node_modules/jackspeak": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.4.0.tgz", - "integrity": "sha512-JVYhQnN59LVPFCEcVa2C3CrEKYacvjRfqIQl+h8oi91aLYQVWRYbxjPcv1bUiUy/kLmQaANrYfNMCO3kuEDHfw==", + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.4.1.tgz", + "integrity": "sha512-U23pQPDnmYybVkYjObcuYMk43VRlMLLqLI+RdZy8s8WV8WsxO9SnqSroKaluuvcNOdCAlauKszDwd+umbot5Mg==", "dev": true, "dependencies": { "@isaacs/cliui": "^8.0.2" }, "engines": { - "node": ">=14" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -2972,12 +2972,12 @@ "peer": true }, "node_modules/lru-cache": { - "version": "10.3.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.3.0.tgz", - "integrity": "sha512-CQl19J/g+Hbjbv4Y3mFNNXFEL/5t/KCg8POCuUqd4rMKjGG+j1ybER83hxV58zL+dFI1PTkt3GNFSHRt+d8qEQ==", + "version": "10.3.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.3.1.tgz", + "integrity": "sha512-9/8QXrtbGeMB6LxwQd4x1tIMnsmUxMvIH/qWGsccz6bt9Uln3S+sgAaqfQNhbGA8ufzs2fHuP/yqapGgP9Hh2g==", "dev": true, "engines": { - "node": "14 || >=16.14" + "node": ">=18" } }, "node_modules/merge2": { @@ -4239,9 +4239,9 @@ } }, "node_modules/sucrase/node_modules/glob": { - "version": "10.4.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.2.tgz", - "integrity": "sha512-GwMlUF6PkPo3Gk21UxkCohOv0PLcIXVtKyLlpEI28R/cO/4eNOdmLk3CMW1wROV/WR/EsZOWAfBbBOqYvs88/w==", + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.3.tgz", + "integrity": "sha512-Q38SGlYRpVtDBPSWEylRyctn7uDeTp4NQERTLiCT1FqA9JXPYWqAVmQU6qh4r/zMM5ehxTcbaO8EjhWnvEhmyg==", "dev": true, "dependencies": { "foreground-child": "^3.1.0", @@ -4255,7 +4255,7 @@ "glob": "dist/esm/bin.mjs" }, "engines": { - "node": ">=16 || 14 >=14.18" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/isaacs" From a2c758dbcb2d883ef64eb70638ed220bad668218 Mon Sep 17 00:00:00 2001 From: Philip H <47042125+pheiduck@users.noreply.github.com> Date: Sun, 7 Jul 2024 19:15:57 +0200 Subject: [PATCH 04/29] How_to_generate_an_bcrypt_hash.md: macos homebrew --- How_to_generate_an_bcrypt_hash.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/How_to_generate_an_bcrypt_hash.md b/How_to_generate_an_bcrypt_hash.md index acca38fe..3da616c0 100644 --- a/How_to_generate_an_bcrypt_hash.md +++ b/How_to_generate_an_bcrypt_hash.md @@ -53,6 +53,8 @@ pip3 install bcrypt --break-system-packages ### macOS ```bash +brew install bcrypt +# If don't install bcrypt using homebrew pip3 install bcrypt # If you got externally-managed-environment error pip3 install bcrypt --break-system-packages From 438fc7ccf9aae0310640f1d30c63fcd4f2a01a81 Mon Sep 17 00:00:00 2001 From: Stevie Galluscio Date: Sun, 7 Jul 2024 11:57:04 -0500 Subject: [PATCH 05/29] Fix bcrypt hash one-liner --- How_to_generate_an_bcrypt_hash.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/How_to_generate_an_bcrypt_hash.md b/How_to_generate_an_bcrypt_hash.md index 3da616c0..46cb2275 100644 --- a/How_to_generate_an_bcrypt_hash.md +++ b/How_to_generate_an_bcrypt_hash.md @@ -63,7 +63,7 @@ pip3 install bcrypt --break-system-packages ## Generating bcrypt hash from the command line You can use the following one-liner command to generate a bcrypt hash directly in the cmd/ terminal: ```bash -python3 -c "import bcrypt; password = b'your_password_here'; assert len(password) < 72, 'Password must be less than 72 bytes due to bcrypt limitation'; hashed = bcrypt.hashpw(password, bcrypt.gensalt()); print(f'The hashed password is: {hashed.decode()}'); docker_interpolation = hashed.decode().replace('$', '$$'); print(f'The hashed password for a Docker env is: {docker_interpolation}')" # or python if you run this on Windows. CHANGE your_password_here BY YOUR PASSWORD +python3 -c "import bcrypt; password = b'your_password_here'; assert len(password) < 72, 'Password must be less than 72 bytes due to bcrypt limitation'; hashed = bcrypt.hashpw(password, bcrypt.gensalt()); print(f'The hashed password is: {hashed.decode()}'); docker_interpolation = hashed.decode().replace('$', '$'*2); print(f'The hashed password for a Docker env is: {docker_interpolation}')" # or python if you run this on Windows. CHANGE your_password_here BY YOUR PASSWORD ``` Please change ``your_password_here`` in the line by your own password. From c73c6c72911ff4da18b00aa4227fda64cb22cd75 Mon Sep 17 00:00:00 2001 From: NPM Update Bot Date: Mon, 8 Jul 2024 08:42:56 +0000 Subject: [PATCH 06/29] npm: package updates --- src/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/package-lock.json b/src/package-lock.json index c12f06bd..4ac3c884 100644 --- a/src/package-lock.json +++ b/src/package-lock.json @@ -2972,9 +2972,9 @@ "peer": true }, "node_modules/lru-cache": { - "version": "10.3.1", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.3.1.tgz", - "integrity": "sha512-9/8QXrtbGeMB6LxwQd4x1tIMnsmUxMvIH/qWGsccz6bt9Uln3S+sgAaqfQNhbGA8ufzs2fHuP/yqapGgP9Hh2g==", + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.0.tgz", + "integrity": "sha512-bfJaPTuEiTYBu+ulDaeQ0F+uLmlfFkMgXj4cbwfuMSjgObGMzb55FMMbDvbRU0fAHZ4sLGkz2mKwcMg8Dvm8Ww==", "dev": true, "engines": { "node": ">=18" From a0c495ddad0ad7e5662ac3bbb72a868047d4dfc8 Mon Sep 17 00:00:00 2001 From: "Elian (ThreadR) Freyermuth" Date: Tue, 9 Jul 2024 14:11:07 +0200 Subject: [PATCH 07/29] Fix a small typo in README.md Changed from "Home Assistent" to "Home Assistant" --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 921c1d6c..81d531a7 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ These options can be configured by setting environment variables using `-e KEY=" | `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 listen on that (othwise default) inside the Docker container. | -| `WG_CONFIG_PORT`| `51820` | `12345` | The UDP port used on [Home Assistent Plugin](https://github.com/adriy-be/homeassistant-addons-jdeath/tree/main/wgeasy) +| `WG_CONFIG_PORT`| `51820` | `12345` | The UDP port used on [Home Assistant Plugin](https://github.com/adriy-be/homeassistant-addons-jdeath/tree/main/wgeasy) | `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 IP address range. | From 94d87681c384689cb4aa371d9d9c3a924f40ce5f Mon Sep 17 00:00:00 2001 From: NPM Update Bot Date: Tue, 9 Jul 2024 15:01:53 +0000 Subject: [PATCH 08/29] npm: package updates --- src/package-lock.json | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/package-lock.json b/src/package-lock.json index 4ac3c884..95700cd3 100644 --- a/src/package-lock.json +++ b/src/package-lock.json @@ -1917,9 +1917,9 @@ } }, "node_modules/esquery": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.5.0.tgz", - "integrity": "sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.6.0.tgz", + "integrity": "sha512-ca9pw9fomFcKPvFLXhBKUK90ZvGibiGOvRJNbjljY7s7uq/5YO4BOzcYtJqExdx99rF6aAcnRxHmcUHcz6sQsg==", "dev": true, "peer": true, "dependencies": { @@ -2827,15 +2827,15 @@ "dev": true }, "node_modules/jackspeak": { - "version": "3.4.1", - "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.4.1.tgz", - "integrity": "sha512-U23pQPDnmYybVkYjObcuYMk43VRlMLLqLI+RdZy8s8WV8WsxO9SnqSroKaluuvcNOdCAlauKszDwd+umbot5Mg==", + "version": "3.4.2", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.4.2.tgz", + "integrity": "sha512-qH3nOSj8q/8+Eg8LUPOq3C+6HWkpUioIjDsq1+D4zY91oZvpPttw8GwtF1nReRYKXl+1AORyFqtm2f5Q1SB6/Q==", "dev": true, "dependencies": { "@isaacs/cliui": "^8.0.2" }, "engines": { - "node": ">=18" + "node": "14 >=14.21 || 16 >=16.20 || >=18" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -2972,12 +2972,12 @@ "peer": true }, "node_modules/lru-cache": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.0.tgz", - "integrity": "sha512-bfJaPTuEiTYBu+ulDaeQ0F+uLmlfFkMgXj4cbwfuMSjgObGMzb55FMMbDvbRU0fAHZ4sLGkz2mKwcMg8Dvm8Ww==", + "version": "10.4.2", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.2.tgz", + "integrity": "sha512-voV4dDrdVZVNz84n39LFKDaRzfwhdzJ7akpyXfTMxCgRUp07U3lcJUXRlhTKP17rgt09sUzLi5iCitpEAr+6ug==", "dev": true, "engines": { - "node": ">=18" + "node": "14 || 16 || 18 || 20 || >=22" } }, "node_modules/merge2": { @@ -4239,9 +4239,9 @@ } }, "node_modules/sucrase/node_modules/glob": { - "version": "10.4.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.3.tgz", - "integrity": "sha512-Q38SGlYRpVtDBPSWEylRyctn7uDeTp4NQERTLiCT1FqA9JXPYWqAVmQU6qh4r/zMM5ehxTcbaO8EjhWnvEhmyg==", + "version": "10.4.5", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.5.tgz", + "integrity": "sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==", "dev": true, "dependencies": { "foreground-child": "^3.1.0", @@ -4254,9 +4254,6 @@ "bin": { "glob": "dist/esm/bin.mjs" }, - "engines": { - "node": ">=18" - }, "funding": { "url": "https://github.com/sponsors/isaacs" } From 72ba79b5f2a636adab77ee116e0d11620c344bf3 Mon Sep 17 00:00:00 2001 From: tetuaoro Date: Tue, 9 Jul 2024 17:06:12 +0200 Subject: [PATCH 09/29] feat: load configuration from file * import json config file & update the config (restore) * export the config and save it to json file (backup) --- src/lib/Server.js | 19 +++++++- src/lib/WireGuard.js | 15 +++++- src/www/index.html | 106 ++++++++++++++++++++++++++++--------------- src/www/js/api.js | 15 ++++++ src/www/js/app.js | 16 +++++++ src/www/js/i18n.js | 2 + 6 files changed, 134 insertions(+), 39 deletions(-) diff --git a/src/lib/Server.js b/src/lib/Server.js index 40341ee5..2c046d99 100644 --- a/src/lib/Server.js +++ b/src/lib/Server.js @@ -265,6 +265,23 @@ module.exports = class Server { }); }; + // import_export + const router3 = createRouter(); + app.use(router3); + + router3 + .get('/api/wireguard/dl', defineEventHandler((event) => { + const config = WireGuard.downloadConfiguration(); + setHeader(event, 'Content-Disposition', 'attachment; filename="wg0.json"'); + setHeader(event, 'Content-Type', 'text/json'); + return config; + })) + .put('/api/wireguard/upload', defineEventHandler(async (event) => { + const { file } = await readBody(event); + await WireGuard.uploadConfiguration(file); + return { success: true } + })); + // Static assets const publicDir = '/app/www'; app.use( @@ -276,7 +293,7 @@ module.exports = class Server { getMeta: async (id) => { const filePath = safePathJoin(publicDir, id); - const stats = await stat(filePath).catch(() => {}); + const stats = await stat(filePath).catch(() => { }); if (!stats || !stats.isFile()) { return; } diff --git a/src/lib/WireGuard.js b/src/lib/WireGuard.js index d4f32c5f..ba4a224d 100644 --- a/src/lib/WireGuard.js +++ b/src/lib/WireGuard.js @@ -111,7 +111,7 @@ PostDown = ${WG_POST_DOWN} [Peer] PublicKey = ${client.publicKey} ${client.preSharedKey ? `PresharedKey = ${client.preSharedKey}\n` : '' -}AllowedIPs = ${client.address}/32`; + }AllowedIPs = ${client.address}/32`; } debug('Config saving...'); @@ -206,7 +206,7 @@ ${WG_MTU ? `MTU = ${WG_MTU}\n` : ''}\ [Peer] PublicKey = ${config.server.publicKey} ${client.preSharedKey ? `PresharedKey = ${client.preSharedKey}\n` : '' -}AllowedIPs = ${WG_ALLOWED_IPS} + }AllowedIPs = ${WG_ALLOWED_IPS} PersistentKeepalive = ${WG_PERSISTENT_KEEPALIVE} Endpoint = ${WG_HOST}:${WG_CONFIG_PORT}`; } @@ -319,6 +319,17 @@ Endpoint = ${WG_HOST}:${WG_CONFIG_PORT}`; await this.saveConfig(); } + async uploadConfiguration(config) { + const _config = JSON.parse(config); + await this.__saveConfig(_config); + await this.__syncConfig(); + } + + async downloadConfiguration() { + const config = await this.getConfig(); + return JSON.stringify(config, null, 2); + } + // Shutdown wireguard async Shutdown() { await Util.exec('wg-quick down wg0').catch(() => { }); diff --git a/src/www/index.html b/src/www/index.html index 72044728..2fe8800f 100644 --- a/src/www/index.html +++ b/src/www/index.html @@ -3,7 +3,7 @@ WireGuard - + @@ -23,45 +23,50 @@

- WireGuard + WireGuard

-
+ + + + + + + + {{$t("download")}} + + -
- - - - - - - - - {{$t("backup")}} - - - -
+
-
+
@@ -225,24 +220,20 @@ - + · - + {{client.transferTxCurrent | bytes}}/s - + - + · - + @@ -250,8 +241,7 @@ {{client.transferRxCurrent | bytes}}/s - {{!uiTrafficStats ? " · " : ""}}{{new Date(client.latestHandshakeAt) | timeago}} @@ -327,7 +317,8 @@ :class="{ 'hover:bg-red-800 dark:hover:bg-red-800 hover:text-white dark:hover:text-white': client.downloadableConfig, 'is-disabled': !client.downloadableConfig - }" :title="!client.downloadableConfig ? $t('noPrivKey') : $t('showQR')" + }" + :title="!client.downloadableConfig ? $t('noPrivKey') : $t('showQR')" @click="qrcode = `./api/wireguard/client/${client.id}/qrcode.svg`"> @@ -344,7 +335,8 @@ :class="{ 'hover:bg-red-800 dark:hover:bg-red-800 hover:text-white dark:hover:text-white': client.downloadableConfig, 'is-disabled': !client.downloadableConfig - }" :title="!client.downloadableConfig ? $t('noPrivKey') : $t('downloadConfig')" + }" + :title="!client.downloadableConfig ? $t('noPrivKey') : $t('downloadConfig')" @click="if(!client.downloadableConfig) { $event.preventDefault(); }"> @@ -448,8 +440,8 @@
- + @@ -566,8 +558,8 @@ class="shadow rounded-md bg-white dark:bg-neutral-700 mx-auto w-64 p-5 overflow-hidden mt-10">
- +
@@ -608,10 +600,9 @@
-

WireGuard Easy © 2021-2024 by Emile Nijssen is - licensed under WireGuard Easy © 2021-2024 by Emile Nijssen is licensed under CC BY-NC-SA 4.0 · {{$t("donate")}}

From 39d32b0a1cb5990ff3a36ea64f7b639f970d121d Mon Sep 17 00:00:00 2001 From: tetuaoro Date: Wed, 10 Jul 2024 14:44:40 +0200 Subject: [PATCH 18/29] Revert "i18n.js: german translation" This reverts commit e4a7ff08c6c76bf9b1449d520d458be9f57102bc. --- src/www/js/i18n.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/www/js/i18n.js b/src/www/js/i18n.js index ec914b81..267f8c32 100644 --- a/src/www/js/i18n.js +++ b/src/www/js/i18n.js @@ -229,10 +229,6 @@ const messages = { // eslint-disable-line no-unused-vars downloadConfig: 'Konfiguration herunterladen', madeBy: 'Erstellt von', donate: 'Spenden', - restore: 'Wiederherstellen', - backup: 'Sichern', - titleRestoreConfig: 'Stelle deine Konfiguration wieder her', - titleBackupConfig: 'Sichere deine Konfiguraion', }, ca: { // github.com/guillembonet name: 'Nom', From 45087a9683cf43a6a76d77f637c1b19644da0ca1 Mon Sep 17 00:00:00 2001 From: tetuaoro Date: Wed, 10 Jul 2024 15:01:39 +0200 Subject: [PATCH 19/29] fix conficts --- src/lib/Server.js | 2 +- src/www/index.html | 81 +++++++++++++++++++++++++--------------------- 2 files changed, 46 insertions(+), 37 deletions(-) diff --git a/src/lib/Server.js b/src/lib/Server.js index d995bb69..12c42077 100644 --- a/src/lib/Server.js +++ b/src/lib/Server.js @@ -265,7 +265,7 @@ module.exports = class Server { }); }; - // backup_restore + // import_export const router3 = createRouter(); app.use(router3); diff --git a/src/www/index.html b/src/www/index.html index 927d2690..345ccb74 100644 --- a/src/www/index.html +++ b/src/www/index.html @@ -3,7 +3,7 @@ WireGuard - + @@ -23,45 +23,50 @@

- WireGuard + WireGuard

-