forked from perara/wg-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Attempt to fix perara#66 with new IP-address check.
- Loading branch information
Showing
2 changed files
with
15 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 14 additions & 4 deletions
18
wg_dashboard_frontend/src/app/validators/ip-address.validator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
} | ||
|
||
|
||
|
||
} |