diff --git a/wg_dashboard_frontend/package.json b/wg_dashboard_frontend/package.json index 8c20eb7..a1b73c2 100644 --- a/wg_dashboard_frontend/package.json +++ b/wg_dashboard_frontend/package.json @@ -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", diff --git a/wg_dashboard_frontend/src/app/validators/ip-address.validator.ts b/wg_dashboard_frontend/src/app/validators/ip-address.validator.ts index b29c386..29770bf 100644 --- a/wg_dashboard_frontend/src/app/validators/ip-address.validator.ts +++ b/wg_dashboard_frontend/src/app/validators/ip-address.validator.ts @@ -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 }; } + + + }