This commit is contained in:
=bhagwanSingh 2025-12-15 18:58:56 +05:30
parent 67af7df83c
commit e79383c1cf
1 changed files with 32 additions and 13 deletions

View File

@ -39,24 +39,43 @@ function generateKeyPair() {
return { privateKey, publicKey }; 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) { function addPeerToServer(publicKey, ip) {
const ipLast = ip.split(".")[3]; // const peerEntry = `
// [Peer]
// PublicKey = ${publicKey}
// AllowedIPs = ${ip}/32
// `;
const peerEntry = ` // fs.appendFileSync(WG_CONF, 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`);
// 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) { function generateClientConf(privateKey, ip) {
return ` return `
[Interface] [Interface]