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