|
|
|
@ -105,12 +105,12 @@ PostDown = ${WG_POST_DOWN} |
|
|
|
for (const [clientId, client] of Object.entries(config.clients)) { |
|
|
|
if (!client.enabled) continue; |
|
|
|
let allowedIPs = ''; |
|
|
|
if(client?.allowedIPs){ |
|
|
|
if (client?.allowedIPs) { |
|
|
|
for (const allowedIP of client.allowedIPs) { |
|
|
|
allowedIPs += `,${allowedIP.address}/${allowedIP.cidr}`; |
|
|
|
} |
|
|
|
allowedIPs = allowedIPs.substring(1); |
|
|
|
}else { |
|
|
|
} else { |
|
|
|
allowedIPs = client.address; |
|
|
|
} |
|
|
|
|
|
|
|
@ -149,7 +149,7 @@ AllowedIPs = ${allowedIPs}`; |
|
|
|
publicKey: client.publicKey, |
|
|
|
createdAt: new Date(client.createdAt), |
|
|
|
updatedAt: new Date(client.updatedAt), |
|
|
|
allowedIPs: client?.allowedIPs?client.allowedIPs:[{type:'ipv4', address:client.address, cidr: 32}], |
|
|
|
allowedIPs: client?.allowedIPs ? client.allowedIPs : [{ type: 'ipv4', address: client.address, cidr: 32 }], |
|
|
|
|
|
|
|
persistentKeepalive: null, |
|
|
|
latestHandshakeAt: null, |
|
|
|
@ -272,7 +272,7 @@ Endpoint = ${WG_HOST}:${WG_PORT}`; |
|
|
|
|
|
|
|
createdAt: new Date(), |
|
|
|
updatedAt: new Date(), |
|
|
|
allowedIPs: [{type:'ipv4', address, cidr: 32}], |
|
|
|
allowedIPs: [{ type: 'ipv4', address, cidr: 32 }], |
|
|
|
|
|
|
|
enabled: true, |
|
|
|
}; |
|
|
|
@ -326,8 +326,7 @@ Endpoint = ${WG_HOST}:${WG_PORT}`; |
|
|
|
if (!Util.isValidIPv4(address)) { |
|
|
|
throw new ServerError(`Invalid Address: ${address}`, 400); |
|
|
|
} |
|
|
|
if(client?.allowedIPs){ |
|
|
|
let allowedIPs = client.allowedIPs |
|
|
|
if (client?.allowedIPs) { |
|
|
|
client.allowedIPs[0].address = address; |
|
|
|
} |
|
|
|
client.address = address; |
|
|
|
@ -335,14 +334,15 @@ Endpoint = ${WG_HOST}:${WG_PORT}`; |
|
|
|
|
|
|
|
await this.saveConfig(); |
|
|
|
} |
|
|
|
|
|
|
|
async updateClientAllowedIPs({ clientId, allowedIPs }) { |
|
|
|
const client = await this.getClient({ clientId }); |
|
|
|
let ips = allowedIPs.map(item=>item.address) |
|
|
|
ips.forEach(ip=>{ |
|
|
|
const ips = allowedIPs.map((item) => item.address); |
|
|
|
ips.forEach((ip) => { |
|
|
|
if (!Util.isValidIPv4(ip)) { |
|
|
|
throw new ServerError(`Invalid Address: ${ip}`, 400); |
|
|
|
} |
|
|
|
}) |
|
|
|
}); |
|
|
|
client.allowedIPs = allowedIPs; |
|
|
|
client.updatedAt = new Date(); |
|
|
|
|
|
|
|
|