Update
This commit is contained in:
parent
67af7df83c
commit
e79383c1cf
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Reference in New Issue