This commit is contained in:
parent
c20db85ada
commit
15bbbd8a98
|
|
@ -34,8 +34,8 @@ function allocateIp(db) {
|
|||
}
|
||||
|
||||
function generateKeyPair() {
|
||||
const privateKey = execSync("sudo wg genkey").toString().trim();
|
||||
const publicKey = execSync(`sudo echo ${privateKey} | wg pubkey`).toString().trim();
|
||||
const privateKey = execSync("wg genkey").toString().trim();
|
||||
const publicKey = execSync(`echo ${privateKey} | wg pubkey`).toString().trim();
|
||||
return { privateKey, publicKey };
|
||||
}
|
||||
|
||||
|
|
@ -66,12 +66,12 @@ function addPeerToServer(publicKey, ip) {
|
|||
|
||||
fs.appendFileSync(WG_CONF, peerEntry);
|
||||
|
||||
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-quick strip wg0 > /tmp/wg0.tmp");
|
||||
execSync("wg syncconf wg0 /tmp/wg0.tmp");
|
||||
execSync("rm -f /tmp/wg0.tmp");
|
||||
|
||||
execSync(
|
||||
`sudo wg set wg0 peer ${publicKey} allowed-ips ${ip}/32`,
|
||||
`wg set wg0 peer ${publicKey} allowed-ips ${ip}/32`,
|
||||
{ stdio: "inherit" }
|
||||
);
|
||||
}
|
||||
|
|
@ -135,9 +135,9 @@ const removePeerFromConf = (publicKey) => {
|
|||
}
|
||||
|
||||
function syncWireGuard() {
|
||||
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-quick strip wg0 > /tmp/wg0.tmp");
|
||||
execSync("wg syncconf wg0 /tmp/wg0.tmp");
|
||||
execSync("rm -f /tmp/wg0.tmp");
|
||||
}
|
||||
|
||||
export function disconnectWireGuardConnection(ip) {
|
||||
|
|
@ -149,7 +149,7 @@ export function disconnectWireGuardConnection(ip) {
|
|||
}
|
||||
|
||||
// 1️⃣ Remove peer from live kernel
|
||||
execSync(`sudo wg set wg0 peer ${publicKey} remove`);
|
||||
execSync(`wg set wg0 peer ${publicKey} remove`);
|
||||
|
||||
// 2️⃣ Remove from config file
|
||||
removePeerFromConf(publicKey);
|
||||
|
|
|
|||
Loading…
Reference in New Issue