Browse Source

Fix importing of IPv6 addresses

pull/106/head
slokhorst 4 years ago
parent
commit
f231126a50
  1. 16
      wg_dashboard_frontend/src/app/page/dashboard/add-server/add-server.component.ts
  2. 14
      wg_dashboard_frontend/src/app/validators/ip-address.validator.ts

16
wg_dashboard_frontend/src/app/page/dashboard/add-server/add-server.component.ts

@ -11,6 +11,7 @@ import {forkJoin, from} from "rxjs";
import {map, mergeMap} from "rxjs/operators"; import {map, mergeMap} from "rxjs/operators";
import {NotifierService} from "angular-notifier"; import {NotifierService} from "angular-notifier";
import {MatCheckboxChange} from "@angular/material/checkbox"; import {MatCheckboxChange} from "@angular/material/checkbox";
import {Address4, Address6} from 'ip-address'
@Component({ @Component({
selector: 'app-add-server', selector: 'app-add-server',
templateUrl: './add-server.component.html', templateUrl: './add-server.component.html',
@ -174,8 +175,19 @@ export class AddServerComponent implements OnInit {
return false; return false;
} }
iFace.nodes["subnet"] = iFace.nodes["address"].split("/")[1]; iFace.nodes["address"]
iFace.nodes["address"] = iFace.nodes["address"].split("/")[0]; .split(",")
.map(x => x.trim())
.forEach(cidr => {
const [address, subnet] = cidr.split("/");
if (Address4.isValid(address)) {
iFace.nodes["address"] = address;
iFace.nodes["subnet"] = subnet;
} else if (Address6.isValid(address)) {
iFace.nodes["v6_address"] = address;
iFace.nodes["v6_subnet"] = subnet;
}
})
iFace.nodes["peers"] = sPeers iFace.nodes["peers"] = sPeers
.map( x => x.nodes) .map( x => x.nodes)

14
wg_dashboard_frontend/src/app/validators/ip-address.validator.ts

@ -5,16 +5,10 @@ import {Address4, Address6} from 'ip-address'
export class IPValidator { export class IPValidator {
static isIPAddress(control: AbstractControl): ValidationErrors | null { static isIPAddress(control: AbstractControl): ValidationErrors | null {
if (Address4.isValid(control.value) || Address6.isValid(control.value))
try { return null;
new Address4(control.value) else
return null return { validIP: true };
} catch (e) {}
try{
new Address6(control.value)
return null
} catch (e) {}
return { validIP: true };
} }

Loading…
Cancel
Save