This commit is contained in:
=bhagwanSingh 2025-12-16 14:21:00 +05:30
parent 0e8ce1f850
commit c20db85ada
2 changed files with 11 additions and 11 deletions

View File

@ -521,7 +521,7 @@ app.use((req, res) => {
});
});
server.listen(PORT, () => {
server.listen(PORT, "0.0.0.0", () => {
mongoose
.connect(
process.env.MONGO_URI,

View File

@ -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);