Browse Source

fixup: lint errors

pull/997/head
xwvike 3 years ago
committed by Julien COSMAO
parent
commit
cb916daaac
No known key found for this signature in database GPG Key ID: 69153421048939E2
  1. 18
      src/lib/WireGuard.js
  2. 2
      src/www/js/api.js
  3. 22
      src/www/js/app.js

18
src/lib/WireGuard.js

@ -111,12 +111,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;
}
@ -156,7 +156,7 @@ ${client.preSharedKey ? `PresharedKey = ${client.preSharedKey}\n` : ''
createdAt: new Date(client.createdAt),
updatedAt: new Date(client.updatedAt),
downloadableConfig: 'privateKey' in client,
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,
@ -281,7 +281,7 @@ Endpoint = ${WG_HOST}:${WG_CONFIG_PORT}`;
createdAt: new Date(),
updatedAt: new Date(),
allowedIPs: [{type:'ipv4', address, cidr: 32}],
allowedIPs: [{ type: 'ipv4', address, cidr: 32 }],
enabled: true,
};
@ -335,8 +335,7 @@ Endpoint = ${WG_HOST}:${WG_CONFIG_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;
@ -344,14 +343,15 @@ Endpoint = ${WG_HOST}:${WG_CONFIG_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();

2
src/www/js/api.js

@ -137,6 +137,7 @@ class API {
body: { address },
});
}
async updateClientAllowedIPs({ clientId, allowedIPs }) {
return this.call({
method: 'put',
@ -145,7 +146,6 @@ class API {
});
}
async restoreConfiguration(file) {
return this.call({
method: 'put',

22
src/www/js/app.js

@ -65,7 +65,7 @@ new Vue({
clientEditAddress: null,
clientEditAddressId: null,
clientEditAllowedIPs: null,
userInputIP:[0,0,0,0,0],
userInputIP: [0, 0, 0, 0, 0],
qrcode: null,
currentRelease: null,
@ -321,20 +321,20 @@ new Vue({
},
updateClientAllowedIPs(client) {
this.api.updateClientAllowedIPs({ clientId: client.id, allowedIPs: client.allowedIPs })
.catch((err) => alert(err.message || err.toString()))
.finally(() => this.refresh().catch(console.error));
.catch((err) => alert(err.message || err.toString()))
.finally(() => this.refresh().catch(console.error));
},
addNewIP(){
let address = this.userInputIP.slice(0,4).join('.');
let allowedIPs = this.clientEditAllowedIPs.allowedIPs;
let obj = {type:'ipv4', address, cidr: this.userInputIP[4]};
addNewIP() {
const address = this.userInputIP.slice(0, 4).join('.');
const allowedIPs = [...this.clientEditAllowedIPs.allowedIPs];
const obj = { type: 'ipv4', address, cidr: this.userInputIP[4] };
allowedIPs.push(obj);
this.clientEditAllowedIPs.allowedIPs = allowedIPs;
this.userInputIP = [0,0,0,0,0];
this.userInputIP = [0, 0, 0, 0, 0];
},
removeIP(index){
let allowedIPs = this.clientEditAllowedIPs.allowedIPs;
allowedIPs.splice(index,1);
removeIP(index) {
const allowedIPs = [...this.clientEditAllowedIPs.allowedIPs];
allowedIPs.splice(index, 1);
this.clientEditAllowedIPs.allowedIPs = allowedIPs;
},
toggleTheme() {

Loading…
Cancel
Save