mirror of
				https://github.com/bjdgyc/anylink.git
				synced 2025-11-04 11:06:22 +08:00 
			
		
		
		
	优化域名拆分隧道的数据校验
This commit is contained in:
		@@ -9,6 +9,8 @@ import (
 | 
				
			|||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/bjdgyc/anylink/base"
 | 
						"github.com/bjdgyc/anylink/base"
 | 
				
			||||||
 | 
						"golang.org/x/text/language"
 | 
				
			||||||
 | 
						"golang.org/x/text/message"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
@@ -17,6 +19,9 @@ const (
 | 
				
			|||||||
	All   = "all"
 | 
						All   = "all"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 域名分流最大字符2万
 | 
				
			||||||
 | 
					const DsMaxLen = 20000
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type GroupLinkAcl struct {
 | 
					type GroupLinkAcl struct {
 | 
				
			||||||
	// 自上而下匹配 默认 allow * *
 | 
						// 自上而下匹配 默认 allow * *
 | 
				
			||||||
	Action string     `json:"action"` // allow、deny
 | 
						Action string     `json:"action"` // allow、deny
 | 
				
			||||||
@@ -145,11 +150,11 @@ func SetGroup(g *Group) error {
 | 
				
			|||||||
			clientDns = append(clientDns, v)
 | 
								clientDns = append(clientDns, v)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if len(routeInclude) == 0 || (len(routeInclude) == 1 && routeInclude[0].Val == "all") {
 | 
						// 是否默认路由
 | 
				
			||||||
		if len(clientDns) == 0 {
 | 
						isDefRoute := len(routeInclude) == 0 || (len(routeInclude) == 1 && routeInclude[0].Val == "all")
 | 
				
			||||||
 | 
						if isDefRoute && len(clientDns) == 0 {
 | 
				
			||||||
		return errors.New("默认路由,必须设置一个DNS")
 | 
							return errors.New("默认路由,必须设置一个DNS")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	g.ClientDns = clientDns
 | 
						g.ClientDns = clientDns
 | 
				
			||||||
	// 域名拆分隧道,不能同时填写
 | 
						// 域名拆分隧道,不能同时填写
 | 
				
			||||||
	g.DsIncludeDomains = strings.TrimSpace(g.DsIncludeDomains)
 | 
						g.DsIncludeDomains = strings.TrimSpace(g.DsIncludeDomains)
 | 
				
			||||||
@@ -167,6 +172,9 @@ func SetGroup(g *Group) error {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return errors.New("排除域名有误:" + err.Error())
 | 
							return errors.New("排除域名有误:" + err.Error())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if isDefRoute && g.DsIncludeDomains != "" {
 | 
				
			||||||
 | 
							return errors.New("默认路由, 不允许设置\"包含域名\", 请重新配置")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	// 处理登入方式的逻辑
 | 
						// 处理登入方式的逻辑
 | 
				
			||||||
	defAuth := map[string]interface{}{
 | 
						defAuth := map[string]interface{}{
 | 
				
			||||||
		"type": "local",
 | 
							"type": "local",
 | 
				
			||||||
@@ -219,6 +227,7 @@ func CheckDomainNames(domains string) error {
 | 
				
			|||||||
	if domains == "" {
 | 
						if domains == "" {
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						strLen := 0
 | 
				
			||||||
	str_slice := strings.Split(domains, ",")
 | 
						str_slice := strings.Split(domains, ",")
 | 
				
			||||||
	for _, val := range str_slice {
 | 
						for _, val := range str_slice {
 | 
				
			||||||
		if val == "" {
 | 
							if val == "" {
 | 
				
			||||||
@@ -227,6 +236,11 @@ func CheckDomainNames(domains string) error {
 | 
				
			|||||||
		if !ValidateDomainName(val) {
 | 
							if !ValidateDomainName(val) {
 | 
				
			||||||
			return errors.New(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
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user