From b8f0f4c618333013b5678c9196f7fa59ddbf648f Mon Sep 17 00:00:00 2001 From: lanrenwo Date: Thu, 13 Oct 2022 10:43:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9F=9F=E5=90=8D=E6=8B=86?= =?UTF-8?q?=E5=88=86=E9=9A=A7=E9=81=93=E7=9A=84=E6=95=B0=E6=8D=AE=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/dbdata/group.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/server/dbdata/group.go b/server/dbdata/group.go index 97fa740..ee66ac0 100644 --- a/server/dbdata/group.go +++ b/server/dbdata/group.go @@ -9,6 +9,8 @@ import ( "time" "github.com/bjdgyc/anylink/base" + "golang.org/x/text/language" + "golang.org/x/text/message" ) const ( @@ -17,6 +19,9 @@ const ( All = "all" ) +// 域名分流最大字符2万 +const DsMaxLen = 20000 + type GroupLinkAcl struct { // 自上而下匹配 默认 allow * * Action string `json:"action"` // allow、deny @@ -145,10 +150,10 @@ func SetGroup(g *Group) error { clientDns = append(clientDns, v) } } - if len(routeInclude) == 0 || (len(routeInclude) == 1 && routeInclude[0].Val == "all") { - if len(clientDns) == 0 { - return errors.New("默认路由,必须设置一个DNS") - } + // 是否默认路由 + isDefRoute := len(routeInclude) == 0 || (len(routeInclude) == 1 && routeInclude[0].Val == "all") + if isDefRoute && len(clientDns) == 0 { + return errors.New("默认路由,必须设置一个DNS") } g.ClientDns = clientDns // 域名拆分隧道,不能同时填写 @@ -167,6 +172,9 @@ func SetGroup(g *Group) error { if err != nil { return errors.New("排除域名有误:" + err.Error()) } + if isDefRoute && g.DsIncludeDomains != "" { + return errors.New("默认路由, 不允许设置\"包含域名\", 请重新配置") + } // 处理登入方式的逻辑 defAuth := map[string]interface{}{ "type": "local", @@ -219,6 +227,7 @@ func CheckDomainNames(domains string) error { if domains == "" { return nil } + strLen := 0 str_slice := strings.Split(domains, ",") for _, val := range str_slice { if val == "" { @@ -227,6 +236,11 @@ func CheckDomainNames(domains string) error { if !ValidateDomainName(val) { return errors.New(val + " 域名有误") } + strLen += len(val) + } + if strLen > DsMaxLen { + p := message.NewPrinter(language.English) + return fmt.Errorf("字符长度超出限制,最大%s个(不包含逗号), 请删减一些域名", p.Sprintf("%d", DsMaxLen)) } return nil }