Browse Source

Update WireGuard.js

pull/400/head
wingsman2 4 years ago
committed by GitHub
parent
commit
80c8007147
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      src/lib/WireGuard.js

22
src/lib/WireGuard.js

@ -104,14 +104,17 @@ PostDown = ${WG_POST_DOWN}
for (const [clientId, client] of Object.entries(config.clients)) {
if (!client.enabled) continue;
var checkallowed;
if(!client.allowedGWIPs){
checkallowed = client.address+"/32";
}else{checkallowed=client.address+"/32, "+client.allowedGWIPs}
result += `
# Client: ${client.name} (${clientId})
[Peer]
PublicKey = ${client.publicKey}
PresharedKey = ${client.preSharedKey}
AllowedIPs = ${client.address}/32`;
AllowedIPs = ${checkallowed}`;
}
debug('Config saving...');
@ -137,6 +140,7 @@ AllowedIPs = ${client.address}/32`;
name: client.name,
enabled: client.enabled,
address: client.address,
allowedGWIPs: client.allowedGWIPs,
publicKey: client.publicKey,
createdAt: new Date(client.createdAt),
updatedAt: new Date(client.updatedAt),
@ -219,10 +223,13 @@ Endpoint = ${WG_HOST}:${WG_PORT}`;
});
}
async createClient({ name }) {
async createClient({ name, allowedGWIPs }) {
if (!name) {
throw new Error('Missing: Name');
}
if (!allowedGWIPs) {
allowedGWIPs = "";
}
const config = await this.getConfig();
@ -252,6 +259,7 @@ Endpoint = ${WG_HOST}:${WG_PORT}`;
const client = {
name,
address,
allowedGWIPs,
privateKey,
publicKey,
preSharedKey,
@ -318,4 +326,12 @@ Endpoint = ${WG_HOST}:${WG_PORT}`;
await this.saveConfig();
}
async updateClientAllowIPS({ clientId, allowedGWIPs }) {
const client = await this.getClient({ clientId });
client.allowedGWIPs = allowedGWIPs;
client.updatedAt = new Date();
await this.saveConfig();
}
};

Loading…
Cancel
Save