mirror of
https://github.com/h44z/wg-portal
synced 2025-02-26 05:49:14 +00:00
Fix DNSStr validator
This commit is contained in:
parent
e6a8e2f2cf
commit
49c7109c61
1
go.mod
1
go.mod
@ -4,6 +4,7 @@ go 1.16
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
git.prolicht.digital/pub/healthcheck v1.0.1
|
git.prolicht.digital/pub/healthcheck v1.0.1
|
||||||
|
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
|
||||||
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5 // indirect
|
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5 // indirect
|
||||||
github.com/evanphx/json-patch v0.5.2
|
github.com/evanphx/json-patch v0.5.2
|
||||||
github.com/gin-contrib/sessions v0.0.5
|
github.com/gin-contrib/sessions v0.0.5
|
||||||
|
2
go.sum
2
go.sum
@ -9,6 +9,8 @@ github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbt
|
|||||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||||
github.com/agiledragon/gomonkey/v2 v2.3.1/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY=
|
github.com/agiledragon/gomonkey/v2 v2.3.1/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY=
|
||||||
github.com/antonlindstrom/pgstore v0.0.0-20200229204646-b08ebf1105e0/go.mod h1:2Ti6VUHVxpC0VSmTZzEvpzysnaGAfGBOoMIz5ykPyyw=
|
github.com/antonlindstrom/pgstore v0.0.0-20200229204646-b08ebf1105e0/go.mod h1:2Ti6VUHVxpC0VSmTZzEvpzysnaGAfGBOoMIz5ykPyyw=
|
||||||
|
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ=
|
||||||
|
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
|
||||||
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff/go.mod h1:+RTT1BOk5P97fT2CiHkbFQwkK3mjsFAP6zCYV2aXtjw=
|
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff/go.mod h1:+RTT1BOk5P97fT2CiHkbFQwkK3mjsFAP6zCYV2aXtjw=
|
||||||
github.com/bos-hieu/mongostore v0.0.2/go.mod h1:8AbbVmDEb0yqJsBrWxZIAZOxIfv/tsP8CDtdHduZHGg=
|
github.com/bos-hieu/mongostore v0.0.2/go.mod h1:8AbbVmDEb0yqJsBrWxZIAZOxIfv/tsP8CDtdHduZHGg=
|
||||||
github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60=
|
github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60=
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/asaskevich/govalidator"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/gin-gonic/gin/binding"
|
"github.com/gin-gonic/gin/binding"
|
||||||
"github.com/go-playground/validator/v10"
|
"github.com/go-playground/validator/v10"
|
||||||
@ -23,9 +24,7 @@ import (
|
|||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
//
|
|
||||||
// CUSTOM VALIDATORS ----------------------------------------------------------------------------
|
// CUSTOM VALIDATORS ----------------------------------------------------------------------------
|
||||||
//
|
|
||||||
var cidrList validator.Func = func(fl validator.FieldLevel) bool {
|
var cidrList validator.Func = func(fl validator.FieldLevel) bool {
|
||||||
cidrListStr := fl.Field().String()
|
cidrListStr := fl.Field().String()
|
||||||
|
|
||||||
@ -39,6 +38,18 @@ var cidrList validator.Func = func(fl validator.FieldLevel) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var dnsList validator.Func = func(fl validator.FieldLevel) bool {
|
||||||
|
dnsListStr := fl.Field().String()
|
||||||
|
dnsList := common.ParseStringList(dnsListStr)
|
||||||
|
for i := range dnsList {
|
||||||
|
ip := net.ParseIP(dnsList[i])
|
||||||
|
if ip == nil && !govalidator.IsDNSName(dnsList[i]) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
var ipList validator.Func = func(fl validator.FieldLevel) bool {
|
var ipList validator.Func = func(fl validator.FieldLevel) bool {
|
||||||
ipListStr := fl.Field().String()
|
ipListStr := fl.Field().String()
|
||||||
ipList := common.ParseStringList(ipListStr)
|
ipList := common.ParseStringList(ipListStr)
|
||||||
@ -55,6 +66,7 @@ func init() {
|
|||||||
if v, ok := binding.Validator.Engine().(*validator.Validate); ok {
|
if v, ok := binding.Validator.Engine().(*validator.Validate); ok {
|
||||||
_ = v.RegisterValidation("cidrlist", cidrList)
|
_ = v.RegisterValidation("cidrlist", cidrList)
|
||||||
_ = v.RegisterValidation("iplist", ipList)
|
_ = v.RegisterValidation("iplist", ipList)
|
||||||
|
_ = v.RegisterValidation("dnsList", dnsList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +101,7 @@ type Peer struct {
|
|||||||
// Misc. WireGuard Settings
|
// Misc. WireGuard Settings
|
||||||
PrivateKey string `form:"privkey" binding:"omitempty,base64"`
|
PrivateKey string `form:"privkey" binding:"omitempty,base64"`
|
||||||
IPsStr string `form:"ip" binding:"cidrlist,required_if=DeviceType server"` // a comma separated list of IPs of the client
|
IPsStr string `form:"ip" binding:"cidrlist,required_if=DeviceType server"` // a comma separated list of IPs of the client
|
||||||
DNSStr string `form:"dns" binding:"iplist"` // comma separated list of the DNS servers for the client
|
DNSStr string `form:"dns" binding:"dnsList"` // comma separated list of the DNS servers for the client
|
||||||
// Global Device Settings (can be ignored, only make sense if device is in server mode)
|
// Global Device Settings (can be ignored, only make sense if device is in server mode)
|
||||||
Mtu int `form:"mtu" binding:"gte=0,lte=1500"`
|
Mtu int `form:"mtu" binding:"gte=0,lte=1500"`
|
||||||
|
|
||||||
@ -255,7 +267,7 @@ type Device struct {
|
|||||||
PublicKey string `form:"pubkey" binding:"required,base64"`
|
PublicKey string `form:"pubkey" binding:"required,base64"`
|
||||||
Mtu int `form:"mtu" binding:"gte=0,lte=1500"` // the interface MTU, wg-quick addition
|
Mtu int `form:"mtu" binding:"gte=0,lte=1500"` // the interface MTU, wg-quick addition
|
||||||
IPsStr string `form:"ip" binding:"required,cidrlist"` // comma separated list of the IPs of the client, wg-quick addition
|
IPsStr string `form:"ip" binding:"required,cidrlist"` // comma separated list of the IPs of the client, wg-quick addition
|
||||||
DNSStr string `form:"dns" binding:"iplist"` // comma separated list of the DNS servers of the client, wg-quick addition
|
DNSStr string `form:"dns" binding:"dnsList"` // comma separated list of the DNS servers of the client, wg-quick addition
|
||||||
RoutingTable string `form:"routingtable"` // the routing table, wg-quick addition
|
RoutingTable string `form:"routingtable"` // the routing table, wg-quick addition
|
||||||
PreUp string `form:"preup"` // pre up script, wg-quick addition
|
PreUp string `form:"preup"` // pre up script, wg-quick addition
|
||||||
PostUp string `form:"postup"` // post up script, wg-quick addition
|
PostUp string `form:"postup"` // post up script, wg-quick addition
|
||||||
|
Loading…
Reference in New Issue
Block a user