优化细节

This commit is contained in:
bjdgyc
2021-12-31 21:37:21 +08:00
parent 85e2ba0b0f
commit 684fea69d0
5 changed files with 56 additions and 31 deletions

View File

@@ -10,6 +10,7 @@ db_source = "./conf/anylink.db"
cert_file = "./conf/vpn_cert.crt"
cert_key = "./conf/vpn_cert.key"
files_path = "./conf/files"
log_level = "debug"
#系统名称
issuer = "XX公司VPN"

View File

@@ -102,7 +102,23 @@ func addInitData() error {
return err
}
return sess.Commit()
err = sess.Commit()
if err != nil {
return err
}
g1 := Group{
Name: "ops",
AllowLan: true,
ClientDns: []ValData{{Val: "114.114.114.114"}},
RouteInclude: []ValData{{Val: All}},
}
err = SetGroup(&g1)
if err != nil {
return err
}
return nil
}
func CheckErrNotFound(err error) bool {

View File

@@ -12,6 +12,7 @@ import (
const (
Allow = "allow"
Deny = "deny"
All = "all"
)
type GroupLinkAcl struct {
@@ -65,25 +66,10 @@ func SetGroup(g *Group) error {
}
// 判断数据
clientDns := []ValData{}
for _, v := range g.ClientDns {
if v.Val != "" {
ip := net.ParseIP(v.Val)
if ip.String() != v.Val {
return errors.New("DNS IP 错误")
}
clientDns = append(clientDns, v)
}
}
if len(clientDns) == 0 {
return errors.New("必须设置一个DNS")
}
g.ClientDns = clientDns
routeInclude := []ValData{}
for _, v := range g.RouteInclude {
if v.Val != "" {
if v.Val == "all" {
if v.Val == All {
routeInclude = append(routeInclude, v)
continue
}
@@ -124,6 +110,24 @@ func SetGroup(g *Group) error {
}
g.LinkAcl = linkAcl
// DNS 判断
clientDns := []ValData{}
for _, v := range g.ClientDns {
if v.Val != "" {
ip := net.ParseIP(v.Val)
if ip.String() != v.Val {
return errors.New("DNS IP 错误")
}
clientDns = append(clientDns, v)
}
}
if len(routeInclude) == 0 || (len(routeInclude) == 1 && routeInclude[0].Val == "all") {
if len(clientDns) == 0 {
return errors.New("默认路由必须设置一个DNS")
}
}
g.ClientDns = clientDns
g.UpdatedAt = time.Now()
if g.Id > 0 {
err = Set(g)

View File

@@ -10,6 +10,7 @@ import (
"strings"
"github.com/bjdgyc/anylink/base"
"github.com/bjdgyc/anylink/dbdata"
"github.com/bjdgyc/anylink/sessdata"
)
@@ -23,11 +24,11 @@ func init() {
}
func HttpSetHeader(w http.ResponseWriter, key string, value string) {
w.Header()[key] = []string{value}
w.Header()[key] = []string{value}
}
func HttpAddHeader(w http.ResponseWriter, key string, value string) {
w.Header()[key] = append(w.Header()[key], value)
w.Header()[key] = append(w.Header()[key], value)
}
func LinkTunnel(w http.ResponseWriter, r *http.Request) {
@@ -95,7 +96,7 @@ func LinkTunnel(w http.ResponseWriter, r *http.Request) {
HttpSetHeader(w, "X-CSTP-Address", cSess.IpAddr.String()) // 分配的ip地址
HttpSetHeader(w, "X-CSTP-Netmask", sessdata.IpPool.Ipv4Mask.String()) // 子网掩码
HttpSetHeader(w, "X-CSTP-Hostname", hn) // 机器名称
//HttpSetHeader(w, "X-CSTP-Default-Domain", cSess.LocalIp)
//HttpSetHeader(w, "X-CSTP-Default-Domain", cSess.LocalIp)
HttpSetHeader(w, "X-CSTP-Base-MTU", cstpBaseMtu)
// 允许本地LAN访问vpn网络必须放在路由的第一个
@@ -108,7 +109,7 @@ func LinkTunnel(w http.ResponseWriter, r *http.Request) {
}
// 允许的路由
for _, v := range cSess.Group.RouteInclude {
if v.Val == "all" {
if v.Val == dbdata.All {
continue
}
HttpAddHeader(w, "X-CSTP-Split-Include", v.IpMask)