mirror of
https://github.com/bjdgyc/anylink.git
synced 2025-08-06 19:43:25 +08:00
新增域名动态拆分隧道(域名路由功能)
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/bjdgyc/anylink/base"
|
||||
"github.com/bjdgyc/anylink/dbdata"
|
||||
@@ -118,7 +119,6 @@ func LinkTunnel(w http.ResponseWriter, r *http.Request) {
|
||||
for _, v := range cSess.Group.RouteExclude {
|
||||
HttpAddHeader(w, "X-CSTP-Split-Exclude", v.IpMask)
|
||||
}
|
||||
|
||||
HttpSetHeader(w, "X-CSTP-Lease-Duration", fmt.Sprintf("%d", base.Cfg.IpLease)) // ip地址租期
|
||||
HttpSetHeader(w, "X-CSTP-Session-Timeout", "none")
|
||||
HttpSetHeader(w, "X-CSTP-Session-Timeout-Alert-Interval", "60")
|
||||
@@ -153,7 +153,11 @@ func LinkTunnel(w http.ResponseWriter, r *http.Request) {
|
||||
HttpSetHeader(w, "X-CSTP-Disable-Always-On-VPN", "false")
|
||||
HttpSetHeader(w, "X-CSTP-Client-Bypass-Protocol", "false")
|
||||
HttpSetHeader(w, "X-CSTP-TCP-Keepalive", "false")
|
||||
// HttpSetHeader(w, "X-CSTP-Post-Auth-XML", ``)
|
||||
// 设置域名拆分隧道(移动端不支持)
|
||||
if mobile != "mobile" {
|
||||
SetPostAuthXml(cSess.Group, w)
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
hClone := w.Header().Clone()
|
||||
@@ -187,3 +191,42 @@ func LinkTunnel(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
go LinkCstp(conn, bufRW, cSess)
|
||||
}
|
||||
|
||||
// 设置域名拆分隧道
|
||||
func SetPostAuthXml(g *dbdata.Group, w http.ResponseWriter) error {
|
||||
if g.DsExcludeDomains == "" && g.DsIncludeDomains == "" {
|
||||
return nil
|
||||
}
|
||||
tmpl, err := template.New("post_auth_xml").Parse(ds_domains_xml)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var result bytes.Buffer
|
||||
_ = tmpl.Execute(&result, g)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if result.String() != "" {
|
||||
HttpSetHeader(w, "X-CSTP-Post-Auth-XML", result.String())
|
||||
base.Info(result.String())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var ds_domains_xml = `
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<config-auth client="vpn" type="complete" aggregate-auth-version="2">
|
||||
<config client="vpn" type="private">
|
||||
<opaque is-for="vpn-client">
|
||||
<custom-attr>
|
||||
{{if .DsExcludeDomains}}
|
||||
<dynamic-split-exclude-domains><![CDATA[{{.DsExcludeDomains}},]]></dynamic-split-exclude-domains>
|
||||
{{end}}
|
||||
{{if .DsIncludeDomains}}
|
||||
<dynamic-split-include-domains><![CDATA[{{.DsIncludeDomains}}]]></dynamic-split-include-domains>
|
||||
{{end}}
|
||||
</custom-attr>
|
||||
</opaque>
|
||||
</config>
|
||||
</config-auth>
|
||||
`
|
Reference in New Issue
Block a user