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