Skip to content

Commit bdc8e26

Browse files
authored
Merge pull request #304 from bjdgyc/dev
Dev
2 parents 8ea158a + 268e9c4 commit bdc8e26

File tree

10 files changed

+109
-79
lines changed

10 files changed

+109
-79
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,27 @@ sudo ./anylink
108108
- [x] 兼容 AnyConnect
109109
- [x] 兼容 OpenConnect
110110
- [x] 基于 tun 设备的 nat 访问模式
111-
- [x] 基于 tap 设备的桥接访问模式
111+
- [x] 基于 tun 设备的桥接访问模式
112112
- [x] 基于 macvtap 设备的桥接访问模式
113113
- [x] 支持 [proxy protocol v1&v2](http://www.haproxy.org/download/2.2/doc/proxy-protocol.txt) 协议
114114
- [x] 用户组支持
115+
- [x] 用户组策略支持
115116
- [x] 多用户支持
116117
- [x] 用户策略支持
117118
- [x] TOTP 令牌支持
118119
- [x] TOTP 令牌开关
119120
- [x] 流量速率限制
120121
- [x] 后台管理界面
121122
- [x] 访问权限管理
123+
- [x] 用户活动审计功能
122124
- [x] IP 访问审计功能
123125
- [x] 域名动态拆分隧道(域名路由功能)
124126
- [x] radius认证支持
125127
- [x] LDAP认证支持
128+
- [x] 空闲链接超时自动断开
129+
- [x] 流量压缩功能
130+
- [x] 出口 IP 自动放行
131+
- [x] 支持多服务的配置区分
126132
- [ ] 基于 ipvtap 设备的桥接访问模式
127133

128134
## Config

build.sh

Lines changed: 6 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,21 @@
11
#!/bin/bash
22

3-
#github action release.sh
4-
5-
set -x
6-
function RETVAL() {
7-
rt=$1
8-
if [ $rt != 0 ]; then
9-
echo $rt
10-
exit 1
11-
fi
12-
}
13-
143
#当前目录
154
cpath=$(pwd)
165

176
ver=$(cat version)
187
echo $ver
198

20-
echo "copy二进制文件"
21-
cd $cpath/server
22-
# -tags osusergo,netgo,sqlite_omit_load_extension
23-
flags="-trimpath"
24-
ldflags="-s -w -extldflags '-static' -X main.appVer=$ver -X main.commitId=$(git rev-parse HEAD) -X main.buildDate=$(date --iso-8601=seconds)"
25-
#github action
26-
gopath=/go
27-
28-
dockercmd=$(
29-
cat <<EOF
30-
sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
31-
apk add gcc g++ musl musl-dev tzdata
32-
export GOPROXY=https://goproxy.cn
33-
go mod tidy
34-
echo "build:"
35-
export CGO_ENABLED=1
36-
go build -v -o anylink_amd64 $flags -ldflags "$ldflags"
37-
./anylink_amd64 -v
38-
EOF
39-
)
9+
#前端编译 仅需要执行一次
10+
bash ./build_web.sh
4011

41-
#使用 musl-dev 编译
42-
docker run -q --rm -v $PWD:/app -v $gopath:/go -w /app --platform=linux/amd64 \
43-
golang:1.20-alpine3.19 sh -c "$dockercmd"
44-
45-
exit 0
46-
47-
#arm64编译
48-
docker run -q --rm -v $PWD:/app -v $gopath:/go -w /app --platform=linux/arm64 \
49-
golang:1.20-alpine3.19 go build -o anylink_arm64 $flags -ldflags "$ldflags"
50-
./anylink_arm64 -v
51-
52-
exit 0
12+
cd $cpath/server
5313

54-
cd $cpath
14+
go build -v -o anylink
5515

56-
echo "整理部署文件"
57-
deploy="anylink-deploy"
58-
rm -rf $deploy ${deploy}.tar.gz
59-
mkdir $deploy
60-
mkdir $deploy/log
16+
./anylink -v
6117

62-
cp -r server/anylink $deploy
63-
cp -r server/bridge-init.sh $deploy
64-
cp -r server/conf $deploy
6518

66-
cp -r systemd $deploy
67-
cp -r LICENSE $deploy
68-
cp -r home $deploy
19+
echo "anylink 编译完成,目录: $cpath/server/anylink"
6920

70-
tar zcvf ${deploy}.tar.gz $deploy
7121

72-
#注意使用root权限运行
73-
#cd anylink-deploy
74-
#sudo ./anylink --conf="conf/server.toml"

build_test.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
3+
#github action release.sh
4+
5+
set -x
6+
function RETVAL() {
7+
rt=$1
8+
if [ $rt != 0 ]; then
9+
echo $rt
10+
exit 1
11+
fi
12+
}
13+
14+
#当前目录
15+
cpath=$(pwd)
16+
17+
ver=$(cat version)
18+
echo $ver
19+
20+
#前端编译 仅需要执行一次
21+
#bash ./build_web.sh
22+
23+
echo "copy二进制文件"
24+
25+
# -tags osusergo,netgo,sqlite_omit_load_extension
26+
flags="-trimpath"
27+
ldflags="-s -w -extldflags '-static' -X main.appVer=$ver -X main.commitId=$(git rev-parse HEAD) -X main.buildDate=$(date --iso-8601=seconds)"
28+
#github action
29+
gopath=/go
30+
31+
dockercmd=$(
32+
cat <<EOF
33+
sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
34+
apk add gcc g++ musl musl-dev tzdata
35+
export GOPROXY=https://goproxy.cn
36+
go mod tidy
37+
echo "build:"
38+
rm anylink
39+
export CGO_ENABLED=1
40+
go build -v -o anylink $flags -ldflags "$ldflags"
41+
./anylink -v
42+
EOF
43+
)
44+
45+
#使用 musl-dev 编译
46+
docker run -q --rm -v $PWD/server:/app -v $gopath:/go -w /app --platform=linux/amd64 \
47+
golang:1.20-alpine3.19 sh -c "$dockercmd"
48+
49+
#arm64编译
50+
#docker run -q --rm -v $PWD/server:/app -v $gopath:/go -w /app --platform=linux/arm64 \
51+
# golang:1.20-alpine3.19 go build -o anylink_arm64 $flags -ldflags "$ldflags"
52+
#exit 0
53+
54+
#cd $cpath
55+
56+
echo "整理部署文件"
57+
rm -rf anylink-deploy anylink-deploy.tar.gz
58+
mkdir anylink-deploy
59+
mkdir anylink-deploy/log
60+
61+
cp -r server/anylink anylink-deploy
62+
cp -r server/conf anylink-deploy
63+
64+
cp -r index_template anylink-deploy
65+
cp -r deploy anylink-deploy
66+
cp -r LICENSE anylink-deploy
67+
68+
tar zcvf anylink-deploy.tar.gz anylink-deploy
69+
70+
#注意使用root权限运行
71+
#cd anylink-deploy
72+
#sudo ./anylink --conf="conf/server.toml"

server/base/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type config struct {
2222
var configs = []config{
2323
{Typ: cfgStr, Name: "conf", Usage: "config file", ValStr: "./conf/server.toml", Short: "c"},
2424
{Typ: cfgStr, Name: "profile", Usage: "profile.xml file", ValStr: "./conf/profile.xml"},
25-
{Typ: cfgStr, Name: "profile_name", Usage: "profile name(用于区分不同网站的配置)", ValStr: "anylink"},
25+
{Typ: cfgStr, Name: "profile_name", Usage: "profile name(用于区分不同服务端的配置)", ValStr: "anylink"},
2626
{Typ: cfgStr, Name: "server_addr", Usage: "TCP服务监听地址(任意端口)", ValStr: ":443"},
2727
{Typ: cfgBool, Name: "server_dtls", Usage: "开启DTLS", ValBool: false},
2828
{Typ: cfgStr, Name: "server_dtls_addr", Usage: "DTLS监听地址(任意端口)", ValStr: ":443"},
@@ -59,7 +59,7 @@ var configs = []config{
5959
{Typ: cfgInt, Name: "mobile_keepalive", Usage: "移动端keepalive接检测时间(秒)", ValInt: 40},
6060
{Typ: cfgInt, Name: "mobile_dpd", Usage: "移动端死链接检测时间(秒)", ValInt: 60},
6161
{Typ: cfgInt, Name: "mtu", Usage: "最大传输单元MTU", ValInt: 1460},
62-
{Typ: cfgInt, Name: "idle_timeout", Usage: "空闲链接超时时间(秒)-超时后断开链接,0关闭此功能", ValInt: 1800},
62+
{Typ: cfgInt, Name: "idle_timeout", Usage: "空闲链接超时时间(秒)-超时后断开链接,0关闭此功能", ValInt: 0},
6363
{Typ: cfgInt, Name: "session_timeout", Usage: "session过期时间(秒)-用于断线重连,0永不过期", ValInt: 3600},
6464
// {Typ: cfgInt, Name: "auth_timeout", Usage: "auth_timeout", ValInt: 0},
6565
{Typ: cfgInt, Name: "audit_interval", Usage: "审计去重间隔(秒),-1关闭", ValInt: 600},

server/conf/server-sample.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ cert_file = "./conf/vpn_cert.pem"
1111
cert_key = "./conf/vpn_cert.key"
1212
files_path = "./conf/files"
1313
profile = "./conf/profile.xml"
14-
#profile name(用于区分不同网站的配置)
14+
#profile name(用于区分不同服务端的配置)
1515
#客户端存放位置 C:\ProgramData\Cisco\Cisco Secure Client\VPN\Profile
1616
profile_name = "anylink"
1717
#日志目录,为空写入标准输出
@@ -82,10 +82,10 @@ default_domain = "example.com"
8282
#default_domain = "example.com abc.example.com"
8383

8484
#空闲链接超时时间(秒)-超时后断开链接,0关闭此功能
85-
idle_timeout = 1800
85+
idle_timeout = 0
8686
#session过期时间,用于断线重连,0永不过期
8787
session_timeout = 3600
88-
auth_timeout = 0
88+
#auth_timeout = 0
8989
audit_interval = 600
9090

9191
show_sql = false

server/handler/link_auth.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ func LinkAuth(w http.ResponseWriter, r *http.Request) {
4646
cr := ClientRequest{}
4747
err = xml.Unmarshal(body, &cr)
4848
if err != nil {
49+
base.Error(err)
4950
w.WriteHeader(http.StatusBadRequest)
5051
return
5152
}
52-
// fmt.Printf("%+v \n", cr)
53+
base.Trace(fmt.Sprintf("%+v \n", cr))
5354
// setCommonHeader(w)
5455
if cr.Type == "logout" {
5556
// 退出删除session信息
@@ -140,7 +141,7 @@ func LinkAuth(w http.ResponseWriter, r *http.Request) {
140141
Banner: other.Banner, ProfileName: base.Cfg.ProfileName, ProfileHash: profileHash}
141142
w.WriteHeader(http.StatusOK)
142143
tplRequest(tpl_complete, w, rd)
143-
base.Debug("login", cr.Auth.Username, userAgent)
144+
base.Info("login", cr.Auth.Username, userAgent)
144145
}
145146

146147
const (

server/handler/link_cstp.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ func LinkCstp(conn net.Conn, bufRW *bufio.ReadWriter, cSess *sessdata.ConnSessio
3737
// 设置超时限制
3838
err = conn.SetReadDeadline(utils.NowSec().Add(dead))
3939
if err != nil {
40-
base.Error("SetDeadline: ", cSess.Username, err)
40+
base.Error("SetDeadline: ", cSess.Username, cSess.IpAddr, err)
4141
return
4242
}
4343
// hdata := make([]byte, BufferSize)
4444
pl := getPayload()
4545
n, err = bufRW.Read(pl.Data)
4646
if err != nil {
47-
base.Error("read hdata: ", cSess.Username, err)
47+
base.Warn("read hdata: ", cSess.Username, cSess.IpAddr, err)
4848
return
4949
}
5050

@@ -69,7 +69,7 @@ func LinkCstp(conn net.Conn, bufRW *bufio.ReadWriter, cSess *sessdata.ConnSessio
6969
}
7070
case 0x05: // DISCONNECT
7171
cSess.UserLogoutCode = dbdata.UserLogoutClient
72-
base.Debug("DISCONNECT", cSess.Username, cSess.IpAddr, conn.RemoteAddr(), n, string(pl.Data[9:n]))
72+
base.Info("DISCONNECT", cSess.Username, cSess.IpAddr, conn.RemoteAddr(), n, string(pl.Data[9:n]))
7373
sessdata.CloseSess(cSess.Sess.Token, dbdata.UserLogoutClient)
7474
return
7575
case 0x03: // DPD-REQ
@@ -176,7 +176,7 @@ func cstpWrite(conn net.Conn, bufRW *bufio.ReadWriter, cSess *sessdata.ConnSessi
176176

177177
n, err = conn.Write(pl.Data)
178178
if err != nil {
179-
base.Error("write err", cSess.Username, err)
179+
base.Warn("write err", cSess.Username, cSess.IpAddr, err)
180180
return
181181
}
182182

server/handler/link_dtls.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ func LinkDtls(conn net.Conn, cSess *sessdata.ConnSession) {
3636
for {
3737
err = conn.SetReadDeadline(utils.NowSec().Add(dead))
3838
if err != nil {
39-
base.Error("SetDeadline: ", cSess.Username, err)
39+
base.Error("SetDeadline: ", cSess.Username, cSess.IpAddr, err)
4040
return
4141
}
4242

4343
pl := getPayload()
4444
n, err = conn.Read(pl.Data)
4545
if err != nil {
46-
base.Error("read hdata: ", cSess.Username, err)
46+
base.Warn("read hdata: ", cSess.Username, cSess.IpAddr, err)
4747
return
4848
}
4949

@@ -59,10 +59,10 @@ func LinkDtls(conn net.Conn, cSess *sessdata.ConnSession) {
5959
base.Trace("recv LinkDtls Keepalive", cSess.Username, cSess.IpAddr, conn.RemoteAddr())
6060
case 0x05: // DISCONNECT
6161
cSess.UserLogoutCode = dbdata.UserLogoutClient
62-
base.Debug("DISCONNECT DTLS", cSess.Username, cSess.IpAddr, conn.RemoteAddr())
62+
base.Info("DISCONNECT DTLS", cSess.Username, cSess.IpAddr, conn.RemoteAddr())
6363
return
6464
case 0x03: // DPD-REQ
65-
base.Trace("recv LinkDtls DPD-REQ", cSess.Username, cSess.IpAddr, conn.RemoteAddr(), n, pl.Data[:n])
65+
base.Trace("recv LinkDtls DPD-REQ", cSess.Username, cSess.IpAddr, conn.RemoteAddr(), n)
6666
pl.PType = 0x04
6767
// 从零开始 可以直接赋值
6868
pl.Data = pl.Data[:n]
@@ -151,12 +151,15 @@ func dtlsWrite(conn net.Conn, dSess *sessdata.DtlsSession, cSess *sessdata.ConnS
151151
}
152152
} else {
153153
// 设置头类型
154-
// pl.Data = append(pl.Data[:0], pl.PType)
155-
pl.Data[0] = pl.PType
154+
if pl.PType == 0x04 {
155+
pl.Data[0] = pl.PType
156+
} else {
157+
pl.Data = append(pl.Data[:0], pl.PType)
158+
}
156159
}
157160
n, err := conn.Write(pl.Data)
158161
if err != nil {
159-
base.Error("write err", cSess.Username, err)
162+
base.Warn("write err", cSess.Username, cSess.IpAddr, err)
160163
return
161164
}
162165

server/handler/link_tun.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func checkTun() {
4646
// 修复 rockyos nat 不生效
4747
base.CheckModOrLoad("iptable_filter")
4848
base.CheckModOrLoad("iptable_nat")
49+
// base.CheckModOrLoad("xt_comment")
4950

5051
// 添加注释
5152
natRule := []string{"-s", base.Cfg.Ipv4CIDR, "-o", base.Cfg.Ipv4Master, "-m", "comment",

server/handler/link_tunnel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func LinkTunnel(w http.ResponseWriter, r *http.Request) {
9292
dtlsPort = ss[1]
9393
}
9494

95-
base.Debug(cSess.IpAddr, cSess.MacHw, sess.Username, mobile)
95+
base.Info(sess.Username, cSess.IpAddr, cSess.MacHw, cSess.Client, mobile)
9696

9797
// 检测密码套件
9898
dtlsCiphersuite := checkDtls12Ciphersuite(r.Header.Get("X-Dtls12-Ciphersuite"))

0 commit comments

Comments
 (0)