Browse Source

* Attempt to fix #66 with new IP-address check.

pull/78/head
Per-Arne Andersen 4 years ago
parent
commit
22d7b9a04d
  1. 1
      wg_dashboard_frontend/package.json
  2. 18
      wg_dashboard_frontend/src/app/validators/ip-address.validator.ts

1
wg_dashboard_frontend/package.json

@ -51,6 +51,7 @@
"file-saver": "2.0.5", "file-saver": "2.0.5",
"hammerjs": "2.0.8", "hammerjs": "2.0.8",
"install": "0.13.0", "install": "0.13.0",
"ip-address": "^7.1.0",
"ip-cidr": "2.1.1", "ip-cidr": "2.1.1",
"js-file-download": "0.4.12", "js-file-download": "0.4.12",
"jszip": "3.5.0", "jszip": "3.5.0",

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

@ -1,12 +1,22 @@
import { AbstractControl, ValidationErrors } from '@angular/forms'; import { AbstractControl, ValidationErrors } from '@angular/forms';
import * as IPCIDR from 'ip-cidr'; import * as IPCIDR from 'ip-cidr';
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 (!control.value || !(new IPCIDR(control.value).isValid())) {
return { validIP: true }; try {
} new Address4(control.value)
return null; return null
} catch (e) {}
try{
new Address6(control.value)
return null
} catch (e) {}
return { validIP: true };
} }
} }

Loading…
Cancel
Save