From c20db85ada9fa3c0080ddf7f765d5909b89ac249 Mon Sep 17 00:00:00 2001 From: =bhagwanSingh Date: Tue, 16 Dec 2025 14:21:00 +0530 Subject: [PATCH] a --- src/server.js | 2 +- src/vpnHandler/vpn.js | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/server.js b/src/server.js index 9327f59..4388ed2 100644 --- a/src/server.js +++ b/src/server.js @@ -521,7 +521,7 @@ app.use((req, res) => { }); }); -server.listen(PORT, () => { +server.listen(PORT, "0.0.0.0", () => { mongoose .connect( process.env.MONGO_URI, diff --git a/src/vpnHandler/vpn.js b/src/vpnHandler/vpn.js index 6e8015d..4ecb311 100644 --- a/src/vpnHandler/vpn.js +++ b/src/vpnHandler/vpn.js @@ -34,8 +34,8 @@ function allocateIp(db) { } function generateKeyPair() { - const privateKey = execSync("wg genkey").toString().trim(); - const publicKey = execSync(`echo ${privateKey} | wg pubkey`).toString().trim(); + const privateKey = execSync("sudo wg genkey").toString().trim(); + const publicKey = execSync(`sudo echo ${privateKey} | wg pubkey`).toString().trim(); return { privateKey, publicKey }; } @@ -66,12 +66,12 @@ function addPeerToServer(publicKey, ip) { fs.appendFileSync(WG_CONF, peerEntry); - execSync("wg-quick strip wg0 > /tmp/wg0.tmp"); - execSync("wg syncconf wg0 /tmp/wg0.tmp"); - execSync("rm -f /tmp/wg0.tmp"); + execSync("sudo wg-quick strip wg0 > /tmp/wg0.tmp"); + execSync("sudo wg syncconf wg0 /tmp/wg0.tmp"); + execSync("sudo rm -f /tmp/wg0.tmp"); execSync( - `wg set wg0 peer ${publicKey} allowed-ips ${ip}/32`, + `sudo wg set wg0 peer ${publicKey} allowed-ips ${ip}/32`, { stdio: "inherit" } ); } @@ -135,9 +135,9 @@ const removePeerFromConf = (publicKey) => { } function syncWireGuard() { - execSync("wg-quick strip wg0 > /tmp/wg0.tmp"); - execSync("wg syncconf wg0 /tmp/wg0.tmp"); - execSync("rm -f /tmp/wg0.tmp"); + execSync("sudo wg-quick strip wg0 > /tmp/wg0.tmp"); + execSync("sudo wg syncconf wg0 /tmp/wg0.tmp"); + execSync("sudo rm -f /tmp/wg0.tmp"); } export function disconnectWireGuardConnection(ip) { @@ -149,7 +149,7 @@ export function disconnectWireGuardConnection(ip) { } // 1️⃣ Remove peer from live kernel - execSync(`wg set wg0 peer ${publicKey} remove`); + execSync(`sudo wg set wg0 peer ${publicKey} remove`); // 2️⃣ Remove from config file removePeerFromConf(publicKey);