安装过程中节点主机地址允许填写域名

This commit is contained in:
GoEdgeLab
2023-03-10 17:00:53 +08:00
parent 8106c48342
commit e5b840a492
2 changed files with 20 additions and 2 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
"net"
"regexp"
"strings"
)
@@ -61,7 +62,24 @@ func (this *ValidateApiAction) RunPost(params struct {
}
if net.ParseIP(params.NewHost) == nil {
this.FailField("newHost", "请输入正确的API节点主机地址")
// 检查是否为域名
var domainReg = regexp.MustCompile(`^[\w-]+$`) // 这里暂不支持 unicode 域名
var digitReg = regexp.MustCompile(`^\d+$`)
var isIP = true
for _, piece := range strings.Split(params.NewHost, ".") {
if !domainReg.MatchString(piece) {
this.FailField("newHost", "请输入正确的API节点主机地址")
return
}
if !digitReg.MatchString(piece) {
isIP = false
}
}
if isIP {
this.FailField("newHost", "请输入正确的API节点主机地址")
return
}
}
params.Must.