mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-05-23 00:15:19 +03:00
Allow passing extra allowed subnets (#114)
This commit is contained in:
parent
f3a788e3a4
commit
341f9b6a42
6 changed files with 97 additions and 21 deletions
26
util/util.go
26
util/util.go
|
@ -76,10 +76,18 @@ func ValidateCIDR(cidr string) bool {
|
|||
}
|
||||
|
||||
// ValidateCIDRList to validate a list of network CIDR
|
||||
func ValidateCIDRList(cidrs []string) bool {
|
||||
func ValidateCIDRList(cidrs []string, allowEmpty bool) bool {
|
||||
for _, cidr := range cidrs {
|
||||
if ValidateCIDR(cidr) == false {
|
||||
return false
|
||||
if allowEmpty {
|
||||
if len(cidr) > 0 {
|
||||
if ValidateCIDR(cidr) == false {
|
||||
return false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ValidateCIDR(cidr) == false {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
|
@ -87,7 +95,15 @@ func ValidateCIDRList(cidrs []string) bool {
|
|||
|
||||
// ValidateAllowedIPs to validate allowed ip addresses in CIDR format
|
||||
func ValidateAllowedIPs(cidrs []string) bool {
|
||||
if ValidateCIDRList(cidrs) == false {
|
||||
if ValidateCIDRList(cidrs, false) == false {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ValidateExtraAllowedIPs to validate extra Allowed ip addresses, allowing empty strings
|
||||
func ValidateExtraAllowedIPs(cidrs []string) bool {
|
||||
if ValidateCIDRList(cidrs, true) == false {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
@ -95,7 +111,7 @@ func ValidateAllowedIPs(cidrs []string) bool {
|
|||
|
||||
// ValidateServerAddresses to validate allowed ip addresses in CIDR format
|
||||
func ValidateServerAddresses(cidrs []string) bool {
|
||||
if ValidateCIDRList(cidrs) == false {
|
||||
if ValidateCIDRList(cidrs, false) == false {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue