From e79383c1cf0c14f25c9a153fa16c47ff22e3993c Mon Sep 17 00:00:00 2001 From: =bhagwanSingh Date: Mon, 15 Dec 2025 18:58:56 +0530 Subject: [PATCH] Update --- src/vpnHandler/vpn.js | 45 ++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/src/vpnHandler/vpn.js b/src/vpnHandler/vpn.js index 6bf6d80..de18998 100644 --- a/src/vpnHandler/vpn.js +++ b/src/vpnHandler/vpn.js @@ -39,24 +39,43 @@ function generateKeyPair() { return { privateKey, publicKey }; } +// function addPeerToServer(publicKey, ip) { +// const ipLast = ip.split(".")[3]; + +// const peerEntry = ` +// [Peer] +// PublicKey = ${publicKey} +// AllowedIPs = 10.0.0.${ipLast}/32 +// `; + +// fs.appendFileSync(WG_CONF, peerEntry); + +// // apply config instantly +// // execSync(`wg syncconf wg0 <(wg-quick strip wg0)`, { shell: "/bin/bash" }); +// execSync(`wg-quick strip wg0 > /tmp/wg0.tmp`); +// execSync(`wg syncconf wg0 /tmp/wg0.tmp`); + +// } + function addPeerToServer(publicKey, ip) { - const ipLast = ip.split(".")[3]; + // const peerEntry = ` + // [Peer] + // PublicKey = ${publicKey} + // AllowedIPs = ${ip}/32 + // `; - const peerEntry = ` -[Peer] -PublicKey = ${publicKey} -AllowedIPs = 10.0.0.${ipLast}/32 -`; - - fs.appendFileSync(WG_CONF, peerEntry); - - // apply config instantly - // execSync(`wg syncconf wg0 <(wg-quick strip wg0)`, { shell: "/bin/bash" }); - execSync(`wg-quick strip wg0 > /tmp/wg0.tmp`); - execSync(`wg syncconf wg0 /tmp/wg0.tmp`); + // 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( + `wg set wg0 peer ${publicKey} allowed-ips ${ip}/32`, + { stdio: "inherit" } + ); } + function generateClientConf(privateKey, ip) { return ` [Interface]