mirror of
https://github.com/bjdgyc/anylink.git
synced 2025-08-07 23:04:17 +08:00
新增域名动态拆分隧道(域名路由功能)
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/bjdgyc/anylink/base"
|
||||
@@ -127,6 +129,20 @@ func SetGroup(g *Group) error {
|
||||
}
|
||||
}
|
||||
g.ClientDns = clientDns
|
||||
// 域名拆分隧道,不能同时填写
|
||||
if g.DsIncludeDomains != "" && g.DsExcludeDomains != "" {
|
||||
return errors.New("包含/排除域名不能同时填写")
|
||||
}
|
||||
// 校验包含域名的格式
|
||||
err = CheckDomainNames(g.DsIncludeDomains)
|
||||
if err != nil {
|
||||
return errors.New("包含域名有误:" + err.Error())
|
||||
}
|
||||
// 校验排除域名的格式
|
||||
err = CheckDomainNames(g.DsExcludeDomains)
|
||||
if err != nil {
|
||||
return errors.New("排除域名有误:" + err.Error())
|
||||
}
|
||||
|
||||
g.UpdatedAt = time.Now()
|
||||
if g.Id > 0 {
|
||||
@@ -149,3 +165,27 @@ func parseIpNet(s string) (string, *net.IPNet, error) {
|
||||
|
||||
return ipMask, ipNet, nil
|
||||
}
|
||||
func CheckDomainNames(domains string) error {
|
||||
if domains == "" {
|
||||
return nil
|
||||
}
|
||||
str_slice := strings.Split(domains, ",")
|
||||
for _, val := range str_slice {
|
||||
if val == "" {
|
||||
return errors.New(val + " 请以逗号分隔域名")
|
||||
}
|
||||
if !ValidateDomainName(val) {
|
||||
return errors.New(val + " 域名有误")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ValidateDomainName(domain string) bool {
|
||||
pos := strings.LastIndex(domain, ".")
|
||||
if pos != -1 && len(domain[pos+1:]) < 2 {
|
||||
return false
|
||||
}
|
||||
RegExp := regexp.MustCompile(`^[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$`)
|
||||
return RegExp.MatchString(domain)
|
||||
}
|
||||
|
@@ -6,18 +6,20 @@ import (
|
||||
)
|
||||
|
||||
type Group struct {
|
||||
Id int `json:"id" xorm:"pk autoincr not null"`
|
||||
Name string `json:"name" xorm:"varchar(60) not null unique"`
|
||||
Note string `json:"note" xorm:"varchar(255)"`
|
||||
AllowLan bool `json:"allow_lan" xorm:"Bool"`
|
||||
ClientDns []ValData `json:"client_dns" xorm:"Text"`
|
||||
RouteInclude []ValData `json:"route_include" xorm:"Text"`
|
||||
RouteExclude []ValData `json:"route_exclude" xorm:"Text"`
|
||||
LinkAcl []GroupLinkAcl `json:"link_acl" xorm:"Text"`
|
||||
Bandwidth int `json:"bandwidth" xorm:"Int"` // 带宽限制
|
||||
Status int8 `json:"status" xorm:"Int"` // 1正常
|
||||
CreatedAt time.Time `json:"created_at" xorm:"DateTime created"`
|
||||
UpdatedAt time.Time `json:"updated_at" xorm:"DateTime updated"`
|
||||
Id int `json:"id" xorm:"pk autoincr not null"`
|
||||
Name string `json:"name" xorm:"varchar(60) not null unique"`
|
||||
Note string `json:"note" xorm:"varchar(255)"`
|
||||
AllowLan bool `json:"allow_lan" xorm:"Bool"`
|
||||
ClientDns []ValData `json:"client_dns" xorm:"Text"`
|
||||
RouteInclude []ValData `json:"route_include" xorm:"Text"`
|
||||
RouteExclude []ValData `json:"route_exclude" xorm:"Text"`
|
||||
DsExcludeDomains string `json:"ds_exclude_domains" xorm:"Text"`
|
||||
DsIncludeDomains string `json:"ds_include_domains" xorm:"Text"`
|
||||
LinkAcl []GroupLinkAcl `json:"link_acl" xorm:"Text"`
|
||||
Bandwidth int `json:"bandwidth" xorm:"Int"` // 带宽限制
|
||||
Status int8 `json:"status" xorm:"Int"` // 1正常
|
||||
CreatedAt time.Time `json:"created_at" xorm:"DateTime created"`
|
||||
UpdatedAt time.Time `json:"updated_at" xorm:"DateTime updated"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
|
Reference in New Issue
Block a user