From cc4c68ad000499aeb1b0f2c153f3fffbefb766c3 Mon Sep 17 00:00:00 2001 From: tm-sanjay Date: Fri, 6 Jan 2023 14:12:43 +0530 Subject: [PATCH] localIp added to QR code --- src/config.js | 2 +- src/lib/WireGuard.js | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/config.js b/src/config.js index e62df350..7d7fbc1e 100644 --- a/src/config.js +++ b/src/config.js @@ -9,7 +9,7 @@ module.exports.WG_PATH = process.env.WG_PATH || '/etc/wireguard/'; module.exports.WG_HOST = process.env.WG_HOST || '0.0.0.0'; module.exports.WG_PORT = process.env.WG_PORT || 51820; module.exports.WG_MTU = process.env.WG_MTU || null; -module.exports.WG_PERSISTENT_KEEPALIVE = process.env.WG_PERSISTENT_KEEPALIVE || 0; +module.exports.WG_PERSISTENT_KEEPALIVE = process.env.WG_PERSISTENT_KEEPALIVE || 25; module.exports.WG_DEFAULT_ADDRESS = process.env.WG_DEFAULT_ADDRESS || '10.8.0.x'; module.exports.WG_DEFAULT_DNS = typeof process.env.WG_DEFAULT_DNS === 'string' ? process.env.WG_DEFAULT_DNS diff --git a/src/lib/WireGuard.js b/src/lib/WireGuard.js index 704ff622..237496d5 100644 --- a/src/lib/WireGuard.js +++ b/src/lib/WireGuard.js @@ -191,9 +191,16 @@ AllowedIPs = ${client.address}/32`; return client; } + //get local ip + static async getLocalIP() { + var ip = await Util.exec('hostname -I'); + return ip.split(' ')[0]; + } + async getClientConfiguration({ clientId }) { const config = await this.getConfig(); const client = await this.getClient({ clientId }); + const localIP = await WireGuard.getLocalIP(); return ` [Interface] @@ -206,7 +213,7 @@ ${WG_MTU ? `MTU = ${WG_MTU}` : ''} PublicKey = ${config.server.publicKey} AllowedIPs = ${WG_ALLOWED_IPS} PersistentKeepalive = ${WG_PERSISTENT_KEEPALIVE} -Endpoint = ${WG_HOST}:${WG_PORT}`; +Endpoint = ${localIP}:${WG_PORT}`; } async getClientQRCodeSVG({ clientId }) {