Skip to content

Commit 7329603

Browse files
authored
Merge pull request #314 from bjdgyc/dev
支持分割DNS功能
2 parents 2828d10 + a7c6791 commit 7329603

File tree

7 files changed

+472
-375
lines changed

7 files changed

+472
-375
lines changed

server/admin/api_group.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ func GroupDetail(w http.ResponseWriter, r *http.Request) {
7575
if len(data.Auth) == 0 {
7676
data.Auth["type"] = "local"
7777
}
78+
// 兼容旧数据
79+
if data.SplitDns == nil {
80+
data.SplitDns = []dbdata.ValData{}
81+
}
7882
RespSucess(w, data)
7983
}
8084

server/conf/profile.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<RestrictTunnelProtocols>IPSec</RestrictTunnelProtocols>
1010
<BypassDownloader>true</BypassDownloader>
1111
<AutoUpdate UserControllable="false">false</AutoUpdate>
12+
<LocalLanAccess UserControllable="true">true</LocalLanAccess>
1213
<WindowsVPNEstablishment>AllowRemoteUsers</WindowsVPNEstablishment>
1314
<LinuxVPNEstablishment>AllowRemoteUsers</LinuxVPNEstablishment>
1415
<CertEnrollmentPin>pinAllowed</CertEnrollmentPin>

server/dbdata/group.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ func SetGroup(g *Group) error {
215215
// DNS 判断
216216
clientDns := []ValData{}
217217
for _, v := range g.ClientDns {
218+
v.Val = strings.TrimSpace(v.Val)
218219
if v.Val != "" {
219220
ip := net.ParseIP(v.Val)
220221
if ip.String() != v.Val {
@@ -229,6 +230,20 @@ func SetGroup(g *Group) error {
229230
return errors.New("默认路由,必须设置一个DNS")
230231
}
231232
g.ClientDns = clientDns
233+
234+
splitDns := []ValData{}
235+
for _, v := range g.SplitDns {
236+
v.Val = strings.TrimSpace(v.Val)
237+
if v.Val != "" {
238+
ValidateDomainName(v.Val)
239+
if !ValidateDomainName(v.Val) {
240+
return errors.New("域名 错误")
241+
}
242+
splitDns = append(splitDns, v)
243+
}
244+
}
245+
g.SplitDns = splitDns
246+
232247
// 域名拆分隧道,不能同时填写
233248
g.DsIncludeDomains = strings.TrimSpace(g.DsIncludeDomains)
234249
g.DsExcludeDomains = strings.TrimSpace(g.DsExcludeDomains)

server/dbdata/tables.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type Group struct {
1111
Note string `json:"note" xorm:"varchar(255)"`
1212
AllowLan bool `json:"allow_lan" xorm:"Bool"`
1313
ClientDns []ValData `json:"client_dns" xorm:"Text"`
14+
SplitDns []ValData `json:"split_dns" xorm:"Text"`
1415
RouteInclude []ValData `json:"route_include" xorm:"Text"`
1516
RouteExclude []ValData `json:"route_exclude" xorm:"Text"`
1617
DsExcludeDomains string `json:"ds_exclude_domains" xorm:"Text"`

server/handler/link_tunnel.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func LinkTunnel(w http.ResponseWriter, r *http.Request) {
8686
}
8787
cSess.CstpDpd = cstpDpd
8888

89-
dtlsPort := "4433"
89+
dtlsPort := "443"
9090
if strings.Contains(base.Cfg.ServerDTLSAddr, ":") {
9191
ss := strings.Split(base.Cfg.ServerDTLSAddr, ":")
9292
dtlsPort = ss[1]
@@ -131,6 +131,11 @@ func LinkTunnel(w http.ResponseWriter, r *http.Request) {
131131
for _, v := range cSess.Group.ClientDns {
132132
HttpAddHeader(w, "X-CSTP-DNS", v.Val)
133133
}
134+
// 分割dns
135+
for _, v := range cSess.Group.SplitDns {
136+
HttpAddHeader(w, "X-CSTP-Split-DNS", v.Val)
137+
}
138+
134139
// 允许的路由
135140
for _, v := range cSess.Group.RouteInclude {
136141
if strings.ToLower(v.Val) == dbdata.All {
@@ -156,9 +161,9 @@ func LinkTunnel(w http.ResponseWriter, r *http.Request) {
156161
HttpSetHeader(w, "X-CSTP-Keep", "true")
157162
HttpSetHeader(w, "X-CSTP-Tunnel-All-DNS", "false")
158163

159-
HttpSetHeader(w, "X-CSTP-Rekey-Time", "43200") // 172800
164+
HttpSetHeader(w, "X-CSTP-Rekey-Time", "86400") // 172800
160165
HttpSetHeader(w, "X-CSTP-Rekey-Method", "new-tunnel")
161-
HttpSetHeader(w, "X-DTLS-Rekey-Time", "43200")
166+
HttpSetHeader(w, "X-DTLS-Rekey-Time", "86400")
162167
HttpSetHeader(w, "X-DTLS-Rekey-Method", "new-tunnel")
163168

164169
HttpSetHeader(w, "X-CSTP-DPD", fmt.Sprintf("%d", cstpDpd))
@@ -180,7 +185,7 @@ func LinkTunnel(w http.ResponseWriter, r *http.Request) {
180185
HttpSetHeader(w, "X-CSTP-Routing-Filtering-Ignore", "false")
181186
HttpSetHeader(w, "X-CSTP-Quarantine", "false")
182187
HttpSetHeader(w, "X-CSTP-Disable-Always-On-VPN", "false")
183-
HttpSetHeader(w, "X-CSTP-Client-Bypass-Protocol", "false")
188+
HttpSetHeader(w, "X-CSTP-Client-Bypass-Protocol", "true")
184189
HttpSetHeader(w, "X-CSTP-TCP-Keepalive", "false")
185190
// 设置域名拆分隧道(移动端不支持)
186191
if mobile != "mobile" {

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.11.4
1+
0.12.1

0 commit comments

Comments
 (0)