Skip to content

Commit

Permalink
* Attempt to fix perara#66 with new IP-address check.
Browse files Browse the repository at this point in the history
  • Loading branch information
perara committed Jan 22, 2021
1 parent e959cd1 commit 02a9639
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions wg_dashboard_frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"file-saver": "2.0.5",
"hammerjs": "2.0.8",
"install": "0.13.0",
"ip-address": "^7.1.0",
"ip-cidr": "2.1.1",
"js-file-download": "0.4.12",
"jszip": "3.5.0",
Expand Down
18 changes: 14 additions & 4 deletions wg_dashboard_frontend/src/app/validators/ip-address.validator.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import { AbstractControl, ValidationErrors } from '@angular/forms';
import * as IPCIDR from 'ip-cidr';
import {Address4, Address6} from 'ip-address'

export class IPValidator {

static isIPAddress(control: AbstractControl): ValidationErrors | null {
if (!control.value || !(new IPCIDR(control.value).isValid())) {
return { validIP: true };
}
return null;

try {
new Address4(control.value)
return null
} catch (e) {}
try{
new Address6(control.value)
return null
} catch (e) {}
return { validIP: true };
}



}

0 comments on commit 02a9639

Please sign in to comment.