mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-06-06 00:37:24 +03:00
Validate AllowedIPs from user input
This commit is contained in:
parent
fe57993240
commit
7ae4dd12dd
5 changed files with 55 additions and 14 deletions
20
util/util.go
20
util/util.go
|
@ -2,6 +2,7 @@ package util
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/ngoduykhanh/wireguard-ui/model"
|
||||
|
@ -38,3 +39,22 @@ func BuildClientConfig(client model.Client) string {
|
|||
|
||||
return strConfig
|
||||
}
|
||||
|
||||
// ValidateCIDR to validate an network CIDR
|
||||
func ValidateCIDR(cidr string) bool {
|
||||
_, _, err := net.ParseCIDR(cidr)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ValidateAllowedIPs to validate allowed ip addresses in CIDR format.
|
||||
func ValidateAllowedIPs(cidrs []string) bool {
|
||||
for _, cidr := range cidrs {
|
||||
if ValidateCIDR(cidr) == false {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue