Merge pull request #290 from bjdgyc/dev

添加github action编译
This commit is contained in:
bjdgyc 2024-01-29 00:15:27 +08:00 committed by GitHub
commit 9d5f5719d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
44 changed files with 890 additions and 1367 deletions

View File

@ -1,5 +1,7 @@
ignore: ignore:
- "screenshot" - "^doc"
- "web" - "^home"
- "server/conf" - "^web"
- "server/files" - "^server/conf"
- "^server/files"

View File

@ -12,13 +12,14 @@
name: "CodeQL" name: "CodeQL"
on: on:
push: workflow_dispatch:
branches: [ "main", "dev" ]
pull_request: # push:
# The branches below must be a subset of the branches above # branches: [ "main", "dev" ]
branches: [ "main", "dev" ] # pull_request:
schedule: # branches: [ "main", "dev" ]
- cron: '32 12 * * 5' # schedule:
# - cron: '32 12 * * 5'
jobs: jobs:
analyze: analyze:
@ -39,7 +40,7 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v4
# Initializes the CodeQL tools for scanning. # Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL - name: Initialize CodeQL

48
.github/workflows/go-update.yml vendored Normal file
View File

@ -0,0 +1,48 @@
name: go-update
on:
workflow_dispatch:
# schedule:
# - cron: "1 2 * * 5"
jobs:
go:
runs-on: ubuntu-latest
steps:
- name: Setup Go 1.x.y
uses: actions/setup-go@main
with:
go-version: '1.20'
stable: true
- name: Checkout codebase
uses: actions/checkout@main
- name: go
run: |
cd ./server
go mod tidy -compat=1.20
#gofmt -w -r 'interface{} -> any' .
go get -u
go mod download
go get -u
go mod download
- name: Git push
run: |
git init
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git remote rm origin
git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUBTOKEN }}@github.com/${{ github.repository }}"
git gc --aggressive
git add --all
git commit -m "update go.mod $(date +%Y.%m.%d.%H.%M)"
#git push -f -u origin _autoaction
git push -u origin _autoaction
# 删除无用 workflow runs;
- name: Delete workflow runs
uses: GitRML/delete-workflow-runs@main
with:
retain_days: 0.1
keep_minimum_runs: 1

View File

@ -1,10 +1,12 @@
name: Go name: Go
on: on:
push: workflow_dispatch:
branches: [ "main", "dev" ]
pull_request: # push:
branches: [ "main", "dev" ] # branches: [ "main", "dev" ]
# pull_request:
# branches: [ "main", "dev" ]
jobs: jobs:
@ -12,15 +14,15 @@ jobs:
name: Build name: Build
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
- name: Set up Go 1.x - name: Set up Go 1.x
uses: actions/setup-go@v2 uses: actions/setup-go@v4
with: with:
go-version: 1.18 go-version: '1.20'
id: go go-version-file: 'server/go.mod'
cache-dependency-path: 'server/go.sum'
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Get dependencies - name: Get dependencies
run: | run: |
@ -32,7 +34,7 @@ jobs:
cd server cd server
mkdir ui mkdir ui
touch ui/index.html touch ui/index.html
go build -v -o anylink -ldflags "-X main.CommitId=`git rev-parse HEAD`" go build -v -o anylink -trimpath -ldflags "-X main.CommitId=`git rev-parse HEAD`"
./anylink tool -v ./anylink tool -v
- name: Test coverage - name: Test coverage
@ -40,7 +42,7 @@ jobs:
cd server cd server
go test -race -coverprofile=coverage.txt -covermode=atomic -v ./... go test -race -coverprofile=coverage.txt -covermode=atomic -v ./...
- name: Upload coverage to Codecov - name: Upload coverage reports to Codecov
run: | uses: codecov/codecov-action@v3
cd server env:
bash <(curl -s https://codecov.io/bash) CODECOV_TOKEN: 28d52fb0-8fc9-460f-95b9-fb84f9138e58

View File

@ -0,0 +1,47 @@
name: release-tag-version
on:
workflow_dispatch:
push:
tags:
- "v0.*"
jobs:
Build:
name: build-binary
runs-on: ubuntu-latest
env:
TZ: Asia/Shanghai
steps:
- name: Hello world
run: |
uname -a
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.20'
cache-dependency-path: 'server/go.sum'
- uses: actions/setup-node@v4
with:
node-version: '16'
cache: 'yarn'
cache-dependency-path: 'web/yarn.lock'
- # https://github.com/docker/setup-qemu-action
name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: build
run: |
mkdir server/ui
touch server/ui/index.html
sudo apt-get install -y -q gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
aarch64-linux-gnu-gcc -v
aarch64-linux-gnu-g++ -v
bash build.sh github_action
# Docker:
# name: build-docker

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
anylink-deploy anylink-deploy
anylink-deploy.tar.gz anylink-deploy.tar.gz
dist

104
.goreleaser.yaml Normal file
View File

@ -0,0 +1,104 @@
#https://goreleaser.com/static/schema.json
# release --skip=publish
# goreleaser build --skip=validate --clean --debug
# GOPROXY=https://goproxy.cn
# docker run -it --rm -v $PWD:/app -v /go:/go -w /app --platform=linux/arm64
# docker run -it --rm -v $PWD:/app -v /go:/go -w /app goreleaser/goreleaser-cross build --skip=validate --clean --debug
# docker run -it --rm -v $PWD:/app -v /go:/go -w /app bjdgyc/dcross goreleaser build --skip=validate --clean --debug
version: 1
dist: dist
before:
hooks:
- pwd
# - cmd: go mod tidy
# dir:
# "{{ dir .Dist}}"
# output: true
# - cmd: go generate
# dir:
# "{{ dir .Dist}}"
# output: true
builds:
- id: "build"
#main: .
dir: ./server
hooks:
pre:
- cmd: go mod tidy
dir: ./server
output: true
- cmd: go generate
dir: ./server
output: true
# {{- if eq .Arch "amd64" }}CC=x86_64-linux-gnu-gcc CXX=x86_64-linux-gnu-g++{{- end }}
env:
- CGO_ENABLED=1
- >-
{{- if eq .Os "linux" }}
{{- if eq .Arch "amd64" }}CC=x86_64-linux-musl-gcc{{- end }}
{{- if eq .Arch "arm64" }}CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++{{- end }}
{{- end }}
{{- if eq .Os "darwin" }}
{{- if eq .Arch "amd64"}}CC=o64-clang{{- end }}
{{- if eq .Arch "arm64"}}CC=oa64-clang{{- end }}
{{- end }}
{{- if eq .Os "windows" }}
{{- if eq .Arch "amd64"}}CC=x86_64-w64-mingw32-gcc{{- end }}
{{- if eq .Arch "arm64"}}CC=aarch64-linux-gnu-gcc{{- end }}
{{- end }}
goos:
- linux
#- darwin
#- windows
goarch:
- amd64
#- arm64
# https://go.dev/wiki/MinimumRequirements
goamd64:
- v1
command: build
flags:
- -trimpath
- -tags osusergo,netgo,sqlite_omit_load_extension
ldflags:
# go tool link -help
# go tool compile -help
# -linkmode external
# -extld=$CC
# -fpic 作为动态链接库的时候 需要添加
- -s -w -extldflags '-static' -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=dcross
archives:
- id: "archive1"
format: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"

View File

@ -3,9 +3,10 @@
[![Go](https://github.com/bjdgyc/anylink/workflows/Go/badge.svg?branch=main)](https://github.com/bjdgyc/anylink/actions) [![Go](https://github.com/bjdgyc/anylink/workflows/Go/badge.svg?branch=main)](https://github.com/bjdgyc/anylink/actions)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/bjdgyc/anylink)](https://pkg.go.dev/github.com/bjdgyc/anylink) [![PkgGoDev](https://pkg.go.dev/badge/github.com/bjdgyc/anylink)](https://pkg.go.dev/github.com/bjdgyc/anylink)
[![Go Report Card](https://goreportcard.com/badge/github.com/bjdgyc/anylink)](https://goreportcard.com/report/github.com/bjdgyc/anylink) [![Go Report Card](https://goreportcard.com/badge/github.com/bjdgyc/anylink)](https://goreportcard.com/report/github.com/bjdgyc/anylink)
[![codecov](https://codecov.io/gh/bjdgyc/anylink/branch/master/graph/badge.svg?token=JTFLIIIBQ0)](https://codecov.io/gh/bjdgyc/anylink) [![codecov](https://codecov.io/gh/bjdgyc/anylink/graph/badge.svg?token=JTFLIIIBQ0)](https://codecov.io/gh/bjdgyc/anylink)
![GitHub release](https://img.shields.io/github/v/release/bjdgyc/anylink) ![GitHub release](https://img.shields.io/github/v/release/bjdgyc/anylink)
![GitHub downloads)](https://img.shields.io/github/downloads/bjdgyc/anylink/total) ![GitHub downloads total)](https://img.shields.io/github/downloads/bjdgyc/anylink/total)
![GitHub Downloads (all assets, latest release)](https://img.shields.io/github/downloads/bjdgyc/anylink/latest/total)
[![Docker pulls)](https://img.shields.io/docker/pulls/bjdgyc/anylink.svg)](https://hub.docker.com/r/bjdgyc/anylink) [![Docker pulls)](https://img.shields.io/docker/pulls/bjdgyc/anylink.svg)](https://hub.docker.com/r/bjdgyc/anylink)
![LICENSE](https://img.shields.io/github/license/bjdgyc/anylink) ![LICENSE](https://img.shields.io/github/license/bjdgyc/anylink)
@ -59,11 +60,13 @@ AnyLink 服务端仅在 CentOS 7、CentOS 8、Ubuntu 18.04、Ubuntu 20.04 测试
> >
> 其他问题 [前往查看](doc/question.md) > 其他问题 [前往查看](doc/question.md)
> >
> 首次使用,请在浏览器访问 https://域名:443浏览器提示安全后在客户端输入 【域名:443】 即可 > 默认管理后台访问地址 https://host:8800 默认账号密码 admin 123456
>
> 首次使用,请在浏览器访问 https://域名:443 浏览器提示安全后,在客户端输入 【域名:443】 即可
### 自行编译安装 ### 自行编译安装
> 需要提前安装好 golang >= 1.19 和 nodejs >= 16.x 和 yarn >= v1.22.x > 需要提前安装好 golang >= 1.20 和 nodejs >= 16.x 和 yarn >= v1.22.x
```shell ```shell
git clone https://github.com/bjdgyc/anylink.git git clone https://github.com/bjdgyc/anylink.git
@ -308,7 +311,7 @@ ipv4_end = "10.1.2.200"
## Discussion ## Discussion
添加QQ群(1): 567510628 添加QQ群(1)(已满): 567510628
添加QQ群(2): 739072205 添加QQ群(2): 739072205
@ -320,6 +323,13 @@ ipv4_end = "10.1.2.200"
![contact_me_qr](doc/screenshot/contact_me_qr.png) ![contact_me_qr](doc/screenshot/contact_me_qr.png)
--> -->
## Support Client
- [AnyConnect Secure Client](https://www.cisco.com/) (可通过群文件下载: Windows/macOS/Linux/Android/iOS)
- [OpenConnect](https://gitlab.com/openconnect/openconnect) (Windows/macOS/Linux)
- [AnyLink Secure Client](https://github.com/tlslink/anylink-client) (Windows/macOS/Linux)
## Contribution ## Contribution
欢迎提交 PR、Issues感谢为 AnyLink 做出贡献。 欢迎提交 PR、Issues感谢为 AnyLink 做出贡献。

View File

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
github_action=$1
set -x set -x
function RETVAL() { function RETVAL() {
rt=$1 rt=$1
@ -12,20 +14,21 @@ function RETVAL() {
#当前目录 #当前目录
cpath=$(pwd) cpath=$(pwd)
ver=`cat server/base/app_ver.go | grep APP_VER | awk '{print $3}' | sed 's/"//g'` #ver=`cat server/base/app_ver.go | grep APP_VER | awk '{print $3}' | sed 's/"//g'`
ver=$(cat version)
echo "当前版本 $ver" echo "当前版本 $ver"
echo "编译前端项目" echo "编译前端项目"
cd $cpath/web cd $cpath/web
#国内可替换源加快速度 #国内可替换源加快速度
#npx browserslist@latest --update-db #npx browserslist@latest --update-db
#npm install --registry=https://registry.npm.taobao.org if [ "$github_action" == "github_action" ]; then
#npm install
#npm run build
yarn install --registry=https://registry.npmmirror.com yarn install --registry=https://registry.npmmirror.com
yarn run build else
yarn install
fi
yarn run build
RETVAL $? RETVAL $?
@ -33,11 +36,31 @@ echo "编译二进制文件"
cd $cpath/server cd $cpath/server
rm -rf ui rm -rf ui
cp -rf $cpath/web/ui . cp -rf $cpath/web/ui .
flags="-v -trimpath -extldflags '-static' -tags osusergo,netgo,sqlite_omit_load_extension"
ldflags="-s -w -X main.appVer=$ver -X main.commitId=$(git rev-parse HEAD) -X main.date=$(date --iso-8601=seconds)"
if [ "$github_action" == "github_action" ]; then
echo "github_action"
else
#国内可替换源加快速度 #国内可替换源加快速度
export GOPROXY=https://goproxy.io export GOPROXY=https://goproxy.io
go mod tidy go mod tidy
go build -v -o anylink -ldflags "-s -w -X main.CommitId=$(git rev-parse HEAD)" go build -o anylink "$flags" -ldflags "$ldflags"
RETVAL $? exit 0
fi
#github action
go mod tidy
go build -o anylink_amd64 "$flags" -ldflags "$ldflags"
#arm64交叉编译
CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ go build -o anylink_arm64 "$flags" -ldflags "$ldflags"
./anylink_amd64 -v
./anylink_arm64 -v
exit 0
cd $cpath cd $cpath
@ -45,9 +68,10 @@ echo "整理部署文件"
deploy="anylink-deploy" deploy="anylink-deploy"
rm -rf $deploy ${deploy}.tar.gz rm -rf $deploy ${deploy}.tar.gz
mkdir $deploy mkdir $deploy
mkdir $deploy/log
cp -r server/anylink $deploy cp -r server/anylink $deploy
#cp -r server/bridge-init.sh $deploy cp -r server/bridge-init.sh $deploy
cp -r server/conf $deploy cp -r server/conf $deploy
cp -r systemd $deploy cp -r systemd $deploy

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
ver=`cat server/base/app_ver.go | grep APP_VER | awk '{print $3}' | sed 's/"//g'` ver=`cat server/base/app_ver.go | grep "APP_VER" | awk '{print $3}' | sed 's/"//g'`
echo $ver echo $ver
#docker login -u bjdgyc #docker login -u bjdgyc

View File

@ -12,7 +12,7 @@
> >
> 需要展示主页的同学可以在QQ群 直接联系我添加。 > 需要展示主页的同学可以在QQ群 直接联系我添加。
| 昵称 | 主页 / 留言 | | 昵称 | 主页 / 联系方式 |
|-----------|------------------------------| |-----------|------------------------------|
| 代码 oo8 | | | 代码 oo8 | |
| 甘磊 | https://github.com/ganlei333 | | 甘磊 | https://github.com/ganlei333 |
@ -40,9 +40,10 @@
| 悲鸣 | | | 悲鸣 | |
| 谢谢 | | | 谢谢 | |
| 云思科技 | | | 云思科技 | |
| 哆啦A伟(张佳伟) | 嘿嘿 | | 哆啦A伟(张佳伟) | |
| 人类的悲欢并不相通 | 开源不易,感谢分享 | | 人类的悲欢并不相通 | |
| 做人要低调 | | | 做人要低调 | |
| 洛洛 | |

View File

@ -27,7 +27,7 @@ COPY --from=builder_node /web/ui /anylink/ui
#TODO 本地打包时使用镜像 #TODO 本地打包时使用镜像
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
RUN apk add gcc musl-dev RUN apk add gcc musl-dev
RUN cd /anylink;go mod tidy;go build -o anylink -ldflags "-s -w -X main.CommitId=${GitCommitId}" \ RUN cd /anylink;go mod tidy;go build -o anylink -trimpath -ldflags "-s -w -X main.CommitId=${GitCommitId}" \
&& /anylink/anylink tool -v && /anylink/anylink tool -v
@ -47,7 +47,7 @@ COPY ./home /app/home
#TODO 本地打包时使用镜像 #TODO 本地打包时使用镜像
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
RUN apk add --no-cache bash iptables \ RUN apk add --no-cache bash iptables iproute2\
&& chmod +x /app/docker_entrypoint.sh \ && chmod +x /app/docker_entrypoint.sh \
&& ls /app && ls /app

View File

@ -36,7 +36,7 @@ func Login(w http.ResponseWriter, r *http.Request) {
totp := gotp.NewDefaultTOTP(base.Cfg.AdminOtp) totp := gotp.NewDefaultTOTP(base.Cfg.AdminOtp)
unix := time.Now().Unix() unix := time.Now().Unix()
verify := totp.Verify(otp, int(unix)) verify := totp.Verify(otp, unix)
if !verify { if !verify {
RespError(w, RespUserOrPassErr) RespError(w, RespUserOrPassErr)

View File

@ -22,6 +22,7 @@ import (
func UserList(w http.ResponseWriter, r *http.Request) { func UserList(w http.ResponseWriter, r *http.Request) {
_ = r.ParseForm() _ = r.ParseForm()
prefix := r.FormValue("prefix") prefix := r.FormValue("prefix")
prefix = strings.TrimSpace(prefix)
pageS := r.FormValue("page") pageS := r.FormValue("page")
page, _ := strconv.Atoi(pageS) page, _ := strconv.Atoi(pageS)
if page < 1 { if page < 1 {
@ -37,8 +38,11 @@ func UserList(w http.ResponseWriter, r *http.Request) {
// 查询前缀匹配 // 查询前缀匹配
if len(prefix) > 0 { if len(prefix) > 0 {
count = dbdata.CountPrefix("username", prefix, &dbdata.User{}) fuzzy := "%" + prefix + "%"
err = dbdata.Prefix("username", prefix, &datas, pageSize, 1) where := "username LIKE ? OR nickname LIKE ? OR email LIKE ?"
count = dbdata.FindWhereCount(&dbdata.User{}, where, fuzzy, fuzzy, fuzzy)
err = dbdata.FindWhere(&datas, pageSize, page, where, fuzzy, fuzzy, fuzzy)
} else { } else {
count = dbdata.CountAll(&dbdata.User{}) count = dbdata.CountAll(&dbdata.User{})
err = dbdata.Find(&datas, pageSize, page) err = dbdata.Find(&datas, pageSize, page)

View File

@ -25,6 +25,7 @@ func StartAdmin() {
r.Use(func(next http.Handler) http.Handler { r.Use(func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
utils.SetSecureHeader(w) utils.SetSecureHeader(w)
w.Header().Set("Server", "AnyLinkAdminOpenSource")
next.ServeHTTP(w, req) next.ServeHTTP(w, req)
}) })
}) })
@ -96,8 +97,9 @@ func StartAdmin() {
r.HandleFunc("/debug/pprof", location("/debug/pprof/")).Name("debug") r.HandleFunc("/debug/pprof", location("/debug/pprof/")).Name("debug")
r.PathPrefix("/debug/pprof/").HandlerFunc(pprof.Index).Name("debug") r.PathPrefix("/debug/pprof/").HandlerFunc(pprof.Index).Name("debug")
// statsviz // statsviz
r.Path("/debug/statsviz/ws").Name("debug").HandlerFunc(statsviz.Ws) srv, _ := statsviz.NewServer() // Create server or handle error
r.PathPrefix("/debug/statsviz/").Name("debug").Handler(statsviz.Index) r.Path("/debug/statsviz/ws").Name("debug").HandlerFunc(srv.Ws())
r.PathPrefix("/debug/statsviz/").Name("debug").Handler(srv.Index())
} }
base.Info("Listen admin", base.Cfg.AdminAddr) base.Info("Listen admin", base.Cfg.AdminAddr)
@ -128,6 +130,7 @@ func StartAdmin() {
Addr: base.Cfg.AdminAddr, Addr: base.Cfg.AdminAddr,
Handler: r, Handler: r,
TLSConfig: tlsConfig, TLSConfig: tlsConfig,
ErrorLog: base.GetServerLog(),
} }
err := srv.ListenAndServeTLS("", "") err := srv.ListenAndServeTLS("", "")
if err != nil { if err != nil {

View File

@ -2,6 +2,12 @@ package base
const ( const (
APP_NAME = "AnyLink" APP_NAME = "AnyLink"
// app版本号 )
APP_VER = "0.10.1"
var (
// APP_VER app版本号
APP_VER = "0.0.1"
// 提交id
CommitId string
Date string
) )

View File

@ -45,6 +45,7 @@ type ServerConfig struct {
FilesPath string `json:"files_path"` FilesPath string `json:"files_path"`
LogPath string `json:"log_path"` LogPath string `json:"log_path"`
LogLevel string `json:"log_level"` LogLevel string `json:"log_level"`
HttpServerLog bool `json:"http_server_log"`
Pprof bool `json:"pprof"` Pprof bool `json:"pprof"`
Issuer string `json:"issuer"` Issuer string `json:"issuer"`
AdminUser string `json:"admin_user"` AdminUser string `json:"admin_user"`
@ -70,6 +71,7 @@ type ServerConfig struct {
Mtu int `json:"mtu"` Mtu int `json:"mtu"`
DefaultDomain string `json:"default_domain"` DefaultDomain string `json:"default_domain"`
IdleTimeout int `json:"idle_timeout"` // in seconds
SessionTimeout int `json:"session_timeout"` // in seconds SessionTimeout int `json:"session_timeout"` // in seconds
// AuthTimeout int `json:"auth_timeout"` // in seconds // AuthTimeout int `json:"auth_timeout"` // in seconds
AuditInterval int `json:"audit_interval"` // in seconds AuditInterval int `json:"audit_interval"` // in seconds

View File

@ -1,7 +1,6 @@
package base package base
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -17,8 +16,6 @@ import (
) )
var ( var (
// 提交id
CommitId string
// pass明文 // pass明文
passwd string passwd string
// 生成otp // 生成otp
@ -60,6 +57,15 @@ func execute() {
envs[rr.Key().String()] = rr.Value().Index(0).String() envs[rr.Key().String()] = rr.Value().Index(0).String()
} }
//移动配置解析代码
conf := linkViper.GetString("conf")
linkViper.SetConfigFile(conf)
err = linkViper.ReadInConfig()
if err != nil {
// 没有配置文件,直接报错
panic("config file err:" + err.Error())
}
if !runSrv { if !runSrv {
os.Exit(0) os.Exit(0)
} }
@ -106,19 +112,28 @@ func initCmd() {
cobra.OnInitialize(func() { cobra.OnInitialize(func() {
linkViper.AutomaticEnv() linkViper.AutomaticEnv()
conf := linkViper.GetString("conf")
_, err := os.Stat(conf) //ver := linkViper.GetBool("version")
if errors.Is(err, os.ErrNotExist) { //if ver {
// 没有配置文件,不做处理 // printVersion()
panic(err) // os.Exit(0)
} //}
//
linkViper.SetConfigFile(conf) //return
err = linkViper.ReadInConfig() //
if err != nil { //conf := linkViper.GetString("conf")
panic("config file err:" + err.Error()) //_, err := os.Stat(conf)
} //if errors.Is(err, os.ErrNotExist) {
// // 没有配置文件,不做处理
// panic("conf stat err:" + err.Error())
//}
//
//
//linkViper.SetConfigFile(conf)
//err = linkViper.ReadInConfig()
//if err != nil {
// panic("config file err:" + err.Error())
//}
}) })
} }
@ -164,6 +179,6 @@ func initToolCmd() *cobra.Command {
} }
func printVersion() { func printVersion() {
fmt.Printf("%s v%s build on %s [%s, %s] commit_id(%s) \n", fmt.Printf("%s v%s build on %s [%s, %s] %s commit_id(%s)\n",
APP_NAME, APP_VER, runtime.Version(), runtime.GOOS, runtime.GOARCH, CommitId) APP_NAME, APP_VER, runtime.Version(), runtime.GOOS, runtime.GOARCH, Date, CommitId)
} }

View File

@ -22,9 +22,9 @@ type config struct {
var configs = []config{ var configs = []config{
{Typ: cfgStr, Name: "conf", Usage: "config file", ValStr: "./conf/server.toml", Short: "c"}, {Typ: cfgStr, Name: "conf", Usage: "config file", ValStr: "./conf/server.toml", Short: "c"},
{Typ: cfgStr, Name: "profile", Usage: "profile.xml file", ValStr: "./conf/profile.xml"}, {Typ: cfgStr, Name: "profile", Usage: "profile.xml file", ValStr: "./conf/profile.xml"},
{Typ: cfgStr, Name: "server_addr", Usage: "服务监听地址", ValStr: ":443"}, {Typ: cfgStr, Name: "server_addr", Usage: "TCP服务监听地址(任意端口)", ValStr: ":443"},
{Typ: cfgBool, Name: "server_dtls", Usage: "开启DTLS", ValBool: false}, {Typ: cfgBool, Name: "server_dtls", Usage: "开启DTLS", ValBool: false},
{Typ: cfgStr, Name: "server_dtls_addr", Usage: "DTLS监听地址", ValStr: ":443"}, {Typ: cfgStr, Name: "server_dtls_addr", Usage: "DTLS监听地址(任意端口)", ValStr: ":443"},
{Typ: cfgStr, Name: "admin_addr", Usage: "后台服务监听地址", ValStr: ":8800"}, {Typ: cfgStr, Name: "admin_addr", Usage: "后台服务监听地址", ValStr: ":8800"},
{Typ: cfgBool, Name: "proxy_protocol", Usage: "TCP代理协议", ValBool: false}, {Typ: cfgBool, Name: "proxy_protocol", Usage: "TCP代理协议", ValBool: false},
{Typ: cfgStr, Name: "db_type", Usage: "数据库类型 [sqlite3 mysql postgres]", ValStr: "sqlite3"}, {Typ: cfgStr, Name: "db_type", Usage: "数据库类型 [sqlite3 mysql postgres]", ValStr: "sqlite3"},
@ -34,6 +34,7 @@ var configs = []config{
{Typ: cfgStr, Name: "files_path", Usage: "外部下载文件路径", ValStr: "./conf/files"}, {Typ: cfgStr, Name: "files_path", Usage: "外部下载文件路径", ValStr: "./conf/files"},
{Typ: cfgStr, Name: "log_path", Usage: "日志文件路径,默认标准输出", ValStr: ""}, {Typ: cfgStr, Name: "log_path", Usage: "日志文件路径,默认标准输出", ValStr: ""},
{Typ: cfgStr, Name: "log_level", Usage: "日志等级 [debug info warn error]", ValStr: "debug"}, {Typ: cfgStr, Name: "log_level", Usage: "日志等级 [debug info warn error]", ValStr: "debug"},
{Typ: cfgBool, Name: "http_server_log", Usage: "开启go标准库http.Server的日志", ValBool: false},
{Typ: cfgBool, Name: "pprof", Usage: "开启pprof", ValBool: false}, {Typ: cfgBool, Name: "pprof", Usage: "开启pprof", ValBool: false},
{Typ: cfgStr, Name: "issuer", Usage: "系统名称", ValStr: "XX公司VPN"}, {Typ: cfgStr, Name: "issuer", Usage: "系统名称", ValStr: "XX公司VPN"},
{Typ: cfgStr, Name: "admin_user", Usage: "管理用户名", ValStr: "admin"}, {Typ: cfgStr, Name: "admin_user", Usage: "管理用户名", ValStr: "admin"},
@ -52,14 +53,15 @@ var configs = []config{
{Typ: cfgInt, Name: "ip_lease", Usage: "IP租期(秒)", ValInt: 86400}, {Typ: cfgInt, Name: "ip_lease", Usage: "IP租期(秒)", ValInt: 86400},
{Typ: cfgInt, Name: "max_client", Usage: "最大用户连接", ValInt: 200}, {Typ: cfgInt, Name: "max_client", Usage: "最大用户连接", ValInt: 200},
{Typ: cfgInt, Name: "max_user_client", Usage: "最大单用户连接", ValInt: 3}, {Typ: cfgInt, Name: "max_user_client", Usage: "最大单用户连接", ValInt: 3},
{Typ: cfgInt, Name: "cstp_keepalive", Usage: "keepalive时间(秒)", ValInt: 4}, {Typ: cfgInt, Name: "cstp_keepalive", Usage: "keepalive时间(秒)", ValInt: 5},
{Typ: cfgInt, Name: "cstp_dpd", Usage: "死链接检测时间(秒)", ValInt: 9}, {Typ: cfgInt, Name: "cstp_dpd", Usage: "死链接检测时间(秒)", ValInt: 12},
{Typ: cfgInt, Name: "mobile_keepalive", Usage: "移动端keepalive接检测时间(秒)", ValInt: 7}, {Typ: cfgInt, Name: "mobile_keepalive", Usage: "移动端keepalive接检测时间(秒)", ValInt: 10},
{Typ: cfgInt, Name: "mobile_dpd", Usage: "移动端死链接检测时间(秒)", ValInt: 15}, {Typ: cfgInt, Name: "mobile_dpd", Usage: "移动端死链接检测时间(秒)", ValInt: 22},
{Typ: cfgInt, Name: "mtu", Usage: "最大传输单元MTU", ValInt: 1460}, {Typ: cfgInt, Name: "mtu", Usage: "最大传输单元MTU", ValInt: 1460},
{Typ: cfgInt, Name: "idle_timeout", Usage: "空闲链接超时时间(秒)-超时后断开链接0关闭此功能", ValInt: 7200},
{Typ: cfgInt, Name: "session_timeout", Usage: "session过期时间(秒)-用于断线重连0永不过期", ValInt: 3600}, {Typ: cfgInt, Name: "session_timeout", Usage: "session过期时间(秒)-用于断线重连0永不过期", ValInt: 3600},
// {Typ: cfgInt, Name: "auth_timeout", Usage: "auth_timeout", ValInt: 0}, // {Typ: cfgInt, Name: "auth_timeout", Usage: "auth_timeout", ValInt: 0},
{Typ: cfgInt, Name: "audit_interval", Usage: "审计去重间隔(秒),-1关闭", ValInt: -1}, {Typ: cfgInt, Name: "audit_interval", Usage: "审计去重间隔(秒),-1关闭", ValInt: 600},
{Typ: cfgBool, Name: "show_sql", Usage: "显示sql语句用于调试", ValBool: false}, {Typ: cfgBool, Name: "show_sql", Usage: "显示sql语句用于调试", ValBool: false},
{Typ: cfgBool, Name: "iptables_nat", Usage: "是否自动添加NAT", ValBool: true}, {Typ: cfgBool, Name: "iptables_nat", Usage: "是否自动添加NAT", ValBool: true},

View File

@ -28,6 +28,10 @@ var (
logName = "anylink.log" logName = "anylink.log"
) )
func init() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
}
// 实现 os.Writer 接口 // 实现 os.Writer 接口
type logWriter struct { type logWriter struct {
UseStdout bool UseStdout bool
@ -77,15 +81,28 @@ func initLog() {
baseLw.newFile() baseLw.newFile()
baseLevel = logLevel2Int(Cfg.LogLevel) baseLevel = logLevel2Int(Cfg.LogLevel)
baseLog = log.New(baseLw, "", log.LstdFlags|log.Lshortfile) baseLog = log.New(baseLw, "", log.LstdFlags|log.Lshortfile)
serverLog = log.New(&sLogWriter{}, "[http_server]", log.LstdFlags|log.Lshortfile)
} }
func GetBaseLw() *logWriter { func GetBaseLw() *logWriter {
return baseLw return baseLw
} }
var serverLog *log.Logger
type sLogWriter struct{}
func (w *sLogWriter) Write(p []byte) (n int, err error) {
if Cfg.HttpServerLog {
return os.Stderr.Write(p)
}
return 0, nil
}
// 获取 log.Logger // 获取 log.Logger
func GetBaseLog() *log.Logger { func GetServerLog() *log.Logger {
return baseLog return serverLog
} }
func GetLogLevel() int { func GetLogLevel() int {

View File

@ -50,20 +50,25 @@ func CheckModOrLoad(mod string) {
return return
} }
var err error
if mod == "tun" || mod == "tap" { if mod == "tun" || mod == "tap" {
_, err := os.Stat(tunPath) _, err = os.Stat(tunPath)
if err == nil { if err == nil {
// 文件存在 // 文件存在
return return
} }
panic("Linux tunFile is null " + tunPath) err = fmt.Errorf("[error] Linux tunFile is null %s", tunPath)
log.Println(err)
return
// panic(err)
} }
if InContainer { if InContainer {
err := fmt.Errorf("Linux module %s is not loaded, please run `modprobe %s`", mod, mod) err = fmt.Errorf("[error] Linux module %s is not loaded, please run `modprobe %s`", mod, mod)
// log.Println(err) log.Println(err)
// return return
panic(err) // panic(err)
} }
cmdstr := fmt.Sprintln("modprobe", mod) cmdstr := fmt.Sprintln("modprobe", mod)

View File

@ -29,10 +29,11 @@ admin_otp = ""
jwt_secret = "abcdef.0123456789.abcdef" jwt_secret = "abcdef.0123456789.abcdef"
#服务监听地址 #TCP服务监听地址(任意端口)
server_addr = ":443" server_addr = ":443"
#开启 DTLS, 默认关闭 #开启 DTLS, 默认关闭
server_dtls = false server_dtls = false
#UDP监听地址(任意端口)
server_dtls_addr = ":443" server_dtls_addr = ":443"
#后台服务监听地址 #后台服务监听地址
admin_addr = ":8800" admin_addr = ":8800"
@ -49,7 +50,7 @@ ipv4_start = "192.168.90.100"
ipv4_end = "192.168.90.200" ipv4_end = "192.168.90.200"
#最大客户端数量 #最大客户端数量
max_client = 100 max_client = 200
#单个用户同时在线数量 #单个用户同时在线数量
max_user_client = 3 max_user_client = 3
#IP租期(秒) #IP租期(秒)
@ -59,10 +60,10 @@ ip_lease = 86400
default_group = "one" default_group = "one"
#客户端失效检测时间(秒) dpd > keepalive #客户端失效检测时间(秒) dpd > keepalive
cstp_keepalive = 6 cstp_keepalive = 5
cstp_dpd = 10 cstp_dpd = 12
mobile_keepalive = 15 mobile_keepalive = 10
mobile_dpd = 20 mobile_dpd = 22
#设置最大传输单元 #设置最大传输单元
mtu = 1460 mtu = 1460
@ -71,10 +72,11 @@ mtu = 1460
default_domain = "example.com" default_domain = "example.com"
#default_domain = "example.com abc.example.com" #default_domain = "example.com abc.example.com"
idle_timeout = 7200
#session过期时间用于断线重连0永不过期 #session过期时间用于断线重连0永不过期
session_timeout = 3600 session_timeout = 3600
auth_timeout = 0 auth_timeout = 0
audit_interval = -1 audit_interval = 600
show_sql = false show_sql = false

View File

@ -23,7 +23,7 @@ admin_pass = "$2a$10$UQ7C.EoPifDeJh6d8.31TeSPQU7hM/NOM2nixmBucJpAuXDQNqNke"
admin_otp = "" admin_otp = ""
jwt_secret = "abcdef.0123456789.abcdef" jwt_secret = "abcdef.0123456789.abcdef"
#服务监听地址 #TCP服务监听地址(任意端口)
server_addr = ":443" server_addr = ":443"
#后台服务监听地址 #后台服务监听地址
admin_addr = ":8800" admin_addr = ":8800"

View File

@ -1,61 +1,67 @@
-----BEGIN CERTIFICATE----- -----BEGIN CERTIFICATE-----
MIIF9jCCBN6gAwIBAgIQAuUy6Rv6Bo3nDXn5FackbDANBgkqhkiG9w0BAQsFADBu MIIGbTCCBNWgAwIBAgIQIodwqN03+Y3aYpdvfq2qKTANBgkqhkiG9w0BAQwFADBZ
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 MQswCQYDVQQGEwJDTjElMCMGA1UEChMcVHJ1c3RBc2lhIFRlY2hub2xvZ2llcywg
d3cuZGlnaWNlcnQuY29tMS0wKwYDVQQDEyRFbmNyeXB0aW9uIEV2ZXJ5d2hlcmUg SW5jLjEjMCEGA1UEAxMaVHJ1c3RBc2lhIFJTQSBEViBUTFMgQ0EgRzIwHhcNMjQw
RFYgVExTIENBIC0gRzEwHhcNMjMwMTAzMDAwMDAwWhcNM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EHbH3uhdVwcEQHvDzaOEEJc9Ilz6pdYsrv+trOmeR5PeIxv S5kYCoEudbDWT89U+tHMOxzUKkb3nDA0WvJEN52CAanYO3blihnX3eX7enQMGtsM
t1jQacSwN1z6z0N4CRjBpePV/9nwETkEaKjQuXSoYlN+pczK/4nX2W9+E/OnwtZs gfDrArcQyS+WMKUkyOlNysqGtj3XWYKssBPrX/0GqMimoeYkg+B4daBTbOVB6sKs
ScyFffPtTLHf1u4eSYuBT/AdwaKHXetxWzh98GP9LRfQhm63Gs+/WcloYl489dG/ +USnmhI2MF3QUxn0+fC207HbSDj7s4a6npjg5KsL0zUsFrNZlMH30Tx2L0WuI1T7
FOFjch2TdmrPcUwxxGEbbPt3zXRxSVlzvIaf4gTUl2+PsKwbKy/w4OLS 65lKHaKt8CyuL/YTjD5lAGYtJ+K9ypl5sBUFCXeW1lazTocjDa2CKv3WV+kVBhyO
2nA2Lo4e643YXwXw98+ufU2U9yUjn1OrhsUXo3qaxETGVMumRwubtX4O2dUKnYGF
xBxfHzXJKhZjX+U2ENIwsrm7pp3dcpIZqKxPCeowU5Ma9tvYpM7kgDhploMfsVic
H7pWcFY99X5nMwJoDDBYomY=
-----END CERTIFICATE----- -----END CERTIFICATE-----
-----BEGIN CERTIFICATE----- -----BEGIN CERTIFICATE-----
MIIEqjCCA5KgAwIBAgIQAnmsRYvBskWr+YBTzSybsTANBgkqhkiG9w0BAQsFADBh MIIFBzCCA++gAwIBAgIRALIM7VUuMaC/NDp1KHQ76aswDQYJKoZIhvcNAQELBQAw
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 ezELMAkGA1UEBhMCR0IxGzAZBgNVBAgMEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G
d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD A1UEBwwHU2FsZm9yZDEaMBgGA1UECgwRQ29tb2RvIENBI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OCAQEAK3Gp6/aGq7aBZsxf/oQ+TD/B dHRwOi8vY3JsLmNvbW9kb2NhLmNvbS9BQUFDZXJ0aWZpY2F0ZVNlcnZpY2VzLmNy
SwW3AU4ETK+GQf2kFzYZkby5SFrHdPomunx2HBzViUchGoofGgg7gHW0W3MlQAXW bDA0BggrBgEFBQcBAQQoMCYwJAYIKwYBBQUHMAGGGGh0dHA6Ly9vY3NwLmNvbW9k
M0r5LUvStcr82QDWYNPaUy4taCQmyaJ+VB+6wxHstSigOlSNF2a6vg4rgexixeiV b2NhLmNvbTANBgkqhkiG9w0BAQsFAAOCAQEAHMUom5cxIje2IiFU7mOCsBr2F6CY
4YSB03Yqp2t3TeZHM9ESfkus74nQyW7pRGezj+TC44xCagCQQOzzNmzEAP2SnCrJ eU5cyfQ/Aep9kAXYUDuWsaT85721JxeXFYkf4D/cgNd9+hxT8ZeDOJrn+ysqR7NO
sNE2DpRVMnL8J6xBRdjmOsC3N6cQuKuRXbzByVBjCqAA8t1L0I+9wXJerLPyErjy 2K9AdqTdIY2uZPKmvgHOkvH2gQD6jc05eSPOwdY/10IPvmpgUKaGOa/tyygL8Og4
rMKWaBFLmfK/AHNF4ZihwPGOc7w6UHczBZXH5RFzJNnww+WnKuTPI0HfnVH8lg== 3tYyoHipMMnS4OiYKakDJny0XVuchIP7ZMKiP07Q3FIuSS4omzR77kmc75/6Q9dP
v4wa90UCOn1j6r7WhMmX3eT3Gsdj3WMe9bYD0AFuqa6MDyjIeXq08mVGraXiw73s
Zale8OMckn/BU3O/3aFNLHLfET2H2hT6Wb3nwxjpLIfXmSVcVd8A58XH0g==
-----END CERTIFICATE----- -----END CERTIFICATE-----

View File

@ -1,27 +1,28 @@
-----BEGIN RSA PRIVATE KEY----- -----BEGIN PRIVATE KEY-----
MIIEpQIBAAKCAQEA0kAk9gG84//u/xKAwiRUsi6U3/OI8Au8VwTBWdAMiZQiTLzi MIIEuwIBADANBgkqhkiG9w0BAQEFAASCBKUwggShAgEAAoIBAQD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UxYlt7ke9wWUfuCinSDplj/A/2rdzSqxmOtZNU5AjIlZ0urfXlp
VyOU9Vro9N9P9o3MktlDsndFulrtYmmLN2YJ9GYpVD43rQA9WPE7uxI784hwLvP3 aNjlo9E6q2dEokuxLn3AqMSs1s/XcOtDlg+RjtLZR9YpJpg0pf6xaF06r7KwDYdz
4+00JXwW8b5lY76y+ZUe2RUCgYEAt6BQN/YgPCH4JmHKIWp64If2HbQntlWQJwRN pJIllVDIT9T9WzwDRwPNhMVhUTpaN8cW+NUlWCENUiu68cQGGk/cfQKBgEmvRk+I
b/qcBIT3EQu1iwSll85jxtSqu4YjwHOgoGAGI5PIYTsSApFY8AyhAUoI2OTdtSXS 4PjZPl6CC7VOOiyVYO46E7RzdwlGuin7SupPQmctL6LaY8TAxPGW7LrjujiCoDLj
+prg6dvmNhTPICk6n73seE5bLOR9NfdsEdk5ijhnlW09OyMb2S2VzR+UYIEbRvnq PU6G08BZdqI/0FIMX54xiBbXJ+dSiqkJWARfotE6zi12uLrc1YTlTEU/U+0/VhGG
THeMqR0CgYEAwQ9aAIGD4t4DXjHHtz6Wqpbq6jj6mmYBsL9jqRgu8ASj1/THgWWn jt42xm4WocrbWM4fnARXIpSq3QyNsHd2F8NxAoGBAMEcT0mFQ0J7HCQ+zL36ogGv
iUrlCbFIXWu2vnP1h0SBV56GA7MSTqAt0ZdTzpI1PRkMOIO9z1dN4Q2R1SEya1eF Bc/N6WR0xSEBQVG9D4iysxX4XyJukCuUCvMIbsBj5IVAVBlMNxfDtL/kD6tgy0L7
7/LPLqJIoLbILGvy6U3DLYdMckPZaoTPf5BNKD52paZcNbjkXTlVLSY= tdN7nOaYgnqTyZfQItz92cQ6oiIqW7GPJA5ATJe1fxXINjcP6EkRDAfACBW7/l85
-----END RSA PRIVATE KEY----- Cd/yRpaOSMPbqKO1OOSn
-----END PRIVATE KEY-----

View File

@ -75,6 +75,11 @@ func Find(data interface{}, limit, page int) error {
return xdb.Limit(limit, start).Find(data) return xdb.Limit(limit, start).Find(data)
} }
func FindWhereCount(data interface{}, where string, args ...interface{}) int {
n, _ := xdb.Where(where, args...).Count(data)
return int(n)
}
func FindWhere(data interface{}, limit int, page int, where string, args ...interface{}) error { func FindWhere(data interface{}, limit int, page int, where string, args ...interface{}) error {
if limit == 0 { if limit == 0 {
return xdb.Where(where, args...).Find(data) return xdb.Where(where, args...).Find(data)

View File

@ -62,7 +62,7 @@ func SettingSet(data interface{}) error {
func SettingGet(data interface{}) error { func SettingGet(data interface{}) error {
name := StructName(data) name := StructName(data)
s := &Setting{Name: name} s := &Setting{}
err := One("name", name, s) err := One("name", name, s)
if err != nil { if err != nil {
return err return err

View File

@ -186,7 +186,7 @@ func checkOtp(name, otp, secret string) bool {
totp := gotp.NewDefaultTOTP(secret) totp := gotp.NewDefaultTOTP(secret)
unix := time.Now().Unix() unix := time.Now().Unix()
verify := totp.Verify(otp, int(unix)) verify := totp.Verify(otp, unix)
return verify return verify
} }

View File

@ -22,6 +22,7 @@ const (
UserLogoutTimeout = 3 // 用户超时登出 UserLogoutTimeout = 3 // 用户超时登出
UserLogoutAdmin = 4 // 账号被管理员踢下线 UserLogoutAdmin = 4 // 账号被管理员踢下线
UserLogoutExpire = 5 // 账号过期被踢下线 UserLogoutExpire = 5 // 账号过期被踢下线
UserIdleTimeout = 6 // 用户空闲链接超时
) )
type UserActLogProcess struct { type UserActLogProcess struct {
@ -62,6 +63,7 @@ var (
UserLogoutTimeout: "Session过期被踢下线", UserLogoutTimeout: "Session过期被踢下线",
UserLogoutAdmin: "账号被管理员踢下线", UserLogoutAdmin: "账号被管理员踢下线",
UserLogoutExpire: "账号过期被踢下线", UserLogoutExpire: "账号过期被踢下线",
UserIdleTimeout: "用户空闲链接超时",
}, },
} }
) )

View File

@ -1,103 +1,107 @@
module github.com/bjdgyc/anylink module github.com/bjdgyc/anylink
go 1.19 go 1.20
require ( require (
github.com/arl/statsviz v0.5.1 github.com/arl/statsviz v0.6.0
github.com/deckarep/golang-set v1.8.0 github.com/deckarep/golang-set v1.8.0
github.com/go-acme/lego/v4 v4.10.2 github.com/go-acme/lego/v4 v4.14.2
github.com/go-co-op/gocron v1.17.0 github.com/go-co-op/gocron v1.37.0
github.com/go-ldap/ldap v3.0.3+incompatible github.com/go-ldap/ldap v3.0.3+incompatible
github.com/go-sql-driver/mysql v1.6.0 github.com/go-sql-driver/mysql v1.7.1
github.com/gocarina/gocsv v0.0.0-20220712153207-8b2118da4570 github.com/gocarina/gocsv v0.0.0-20231116093920-b87c2d0e983a
github.com/golang-jwt/jwt/v4 v4.2.0 github.com/golang-jwt/jwt/v4 v4.5.0
github.com/google/gopacket v1.1.19 github.com/google/gopacket v1.1.19
github.com/gorilla/handlers v1.5.1 github.com/gorilla/handlers v1.5.2
github.com/gorilla/mux v1.8.0 github.com/gorilla/mux v1.8.1
github.com/ivpusic/grpool v1.0.0 github.com/ivpusic/grpool v1.0.0
github.com/lanrenwo/lzsgo v0.0.2 github.com/lanrenwo/lzsgo v0.0.2
github.com/lib/pq v1.10.2 github.com/lib/pq v1.10.9
github.com/mattn/go-sqlite3 v1.14.9 github.com/mattn/go-sqlite3 v1.14.19
github.com/orcaman/concurrent-map v1.0.0 github.com/orcaman/concurrent-map v1.0.0
github.com/pion/dtls/v2 v2.2.7 github.com/pion/dtls/v2 v2.2.9
github.com/pion/logging v0.2.2 github.com/pion/logging v0.2.2
github.com/pires/go-proxyproto v0.6.2 github.com/pires/go-proxyproto v0.7.0
github.com/shirou/gopsutil v3.21.7+incompatible github.com/shirou/gopsutil v3.21.11+incompatible
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/songgao/packets v0.0.0-20160404182456-549a10cd4091 github.com/songgao/packets v0.0.0-20160404182456-549a10cd4091
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8 github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
github.com/spf13/cast v1.3.1 github.com/spf13/cast v1.6.0
github.com/spf13/cobra v1.2.1 github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.8.1 github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.8.3 github.com/stretchr/testify v1.8.4
github.com/xhit/go-simple-mail/v2 v2.10.0 github.com/xhit/go-simple-mail/v2 v2.16.0
github.com/xlzd/gotp v0.0.0-20181030022105-c8557ba2c119 github.com/xlzd/gotp v0.1.0
github.com/xuri/excelize/v2 v2.6.1 github.com/xuri/excelize/v2 v2.8.0
go.uber.org/atomic v1.10.0 go.uber.org/atomic v1.11.0
golang.org/x/crypto v0.8.0 golang.org/x/crypto v0.18.0
golang.org/x/net v0.9.0 golang.org/x/net v0.20.0
golang.org/x/text v0.9.0 golang.org/x/text v0.14.0
golang.org/x/time v0.3.0 golang.org/x/time v0.5.0
layeh.com/radius v0.0.0-20210819152912-ad72663a72ab layeh.com/radius v0.0.0-20231213012653-1006025d24f8
xorm.io/xorm v1.3.2 xorm.io/xorm v1.3.7
) )
require ( require (
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1755 // indirect github.com/aliyun/alibaba-cloud-sdk-go v1.62.664 // indirect
github.com/cenkalti/backoff/v4 v4.2.0 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cloudflare/cloudflare-go v0.49.0 // indirect github.com/cloudflare/cloudflare-go v0.86.0 // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-jose/go-jose/v3 v3.0.0 // indirect github.com/go-jose/go-jose/v3 v3.0.1 // indirect
github.com/go-test/deep v1.1.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.1 // indirect github.com/hashicorp/go-retryablehttp v0.7.5 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/kr/text v0.2.0 // indirect github.com/miekg/dns v1.1.58 // indirect
github.com/miekg/dns v1.1.50 // indirect github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
github.com/pion/transport/v2 v2.2.1 // indirect github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/pkg/errors v0.9.1 // indirect github.com/pion/transport/v2 v2.2.4 // indirect
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.490 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.490 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect
golang.org/x/mod v0.8.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect
golang.org/x/tools v0.6.0 // indirect github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.846 // indirect
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.846 // indirect
github.com/toorop/go-dkim v0.0.0-20240103092955-90b7d1423f92 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/tools v0.17.0 // indirect
) )
require ( require (
github.com/StackExchange/wmi v1.2.1 // indirect github.com/coreos/go-iptables v0.7.0
github.com/coreos/go-iptables v0.6.0 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/davecgh/go-spew v1.1.1 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-ole/go-ole v1.2.5 // indirect github.com/goccy/go-json v0.10.2 // indirect
github.com/goccy/go-json v0.8.1 // indirect
github.com/golang/snappy v0.0.4 // indirect github.com/golang/snappy v0.0.4 // indirect
github.com/gorilla/websocket v1.4.2 // indirect github.com/gorilla/websocket v1.5.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect github.com/json-iterator/go v1.1.12 // indirect
github.com/magiconair/properties v1.8.5 // indirect github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/pelletier/go-toml v1.9.3 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/richardlehane/mscfb v1.0.4 // indirect github.com/richardlehane/mscfb v1.0.4 // indirect
github.com/richardlehane/msoleps v1.0.3 // indirect github.com/richardlehane/msoleps v1.0.3 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/spf13/afero v1.6.0 // indirect github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect
github.com/syndtr/goleveldb v1.0.0 // indirect github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/tklauser/go-sysconf v0.3.7 // indirect github.com/tklauser/go-sysconf v0.3.13 // indirect
github.com/tklauser/numcpus v0.2.3 // indirect github.com/tklauser/numcpus v0.7.0 // indirect
github.com/xuri/efp v0.0.0-20220603152613-6918739fd470 // indirect github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53 // indirect
github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22 // indirect github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05 // indirect
golang.org/x/sync v0.1.0 // indirect golang.org/x/sys v0.16.0 // indirect
golang.org/x/sys v0.7.0 // indirect
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect
gopkg.in/ini.v1 v1.66.6 // indirect gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect xorm.io/builder v0.3.13 // indirect
) )

File diff suppressed because it is too large Load Diff

View File

@ -157,7 +157,7 @@ func tplRequest(typ int, w io.Writer, data RequestData) {
if data.Banner != "" { if data.Banner != "" {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
xml.EscapeText(buf, []byte(data.Banner)) _ = xml.EscapeText(buf, []byte(data.Banner))
data.Banner = buf.String() data.Banner = buf.String()
} }

View File

@ -24,7 +24,10 @@ func LinkCstp(conn net.Conn, bufRW *bufio.ReadWriter, cSess *sessdata.ConnSessio
err error err error
n int n int
dataLen uint16 dataLen uint16
dead = time.Duration(cSess.CstpDpd+5) * time.Second dead = time.Second * time.Duration(cSess.CstpDpd+5)
idle = time.Second * time.Duration(base.Cfg.IdleTimeout)
checkIdle = base.Cfg.IdleTimeout > 0
lastTime time.Time
) )
go cstpWrite(conn, bufRW, cSess) go cstpWrite(conn, bufRW, cSess)
@ -55,13 +58,24 @@ func LinkCstp(conn net.Conn, bufRW *bufio.ReadWriter, cSess *sessdata.ConnSessio
case 0x07: // KEEPALIVE case 0x07: // KEEPALIVE
// do nothing // do nothing
// base.Debug("recv keepalive", cSess.IpAddr) // base.Debug("recv keepalive", cSess.IpAddr)
// 判断超时时间
if checkIdle {
lastTime = cSess.LastDataTime.Load()
if lastTime.Before(utils.NowSec().Add(-idle)) {
base.Warn("IdleTimeout", cSess.Username, cSess.IpAddr, "lastTime", lastTime)
sessdata.CloseSess(cSess.Sess.Token, dbdata.UserIdleTimeout)
return
}
}
case 0x05: // DISCONNECT case 0x05: // DISCONNECT
cSess.UserLogoutCode = dbdata.UserLogoutClient cSess.UserLogoutCode = dbdata.UserLogoutClient
base.Debug("DISCONNECT", cSess.Username, cSess.IpAddr) base.Debug("DISCONNECT", cSess.Username, cSess.IpAddr)
sessdata.CloseSess(cSess.Sess.Token, dbdata.UserLogoutClient)
return return
case 0x03: // DPD-REQ case 0x03: // DPD-REQ
// base.Debug("recv DPD-REQ", cSess.IpAddr) // base.Debug("recv DPD-REQ", cSess.IpAddr)
pl.PType = 0x04 pl.PType = 0x04
pl.Data = pl.Data[:n]
if payloadOutCstp(cSess, pl) { if payloadOutCstp(cSess, pl) {
return return
} }
@ -98,6 +112,8 @@ func LinkCstp(conn net.Conn, bufRW *bufio.ReadWriter, cSess *sessdata.ConnSessio
if payloadIn(cSess, pl) { if payloadIn(cSess, pl) {
return return
} }
// 只记录返回正确的数据时间
cSess.LastDataTime.Store(utils.NowSec())
} }
} }
} }
@ -153,7 +169,7 @@ func cstpWrite(conn net.Conn, bufRW *bufio.ReadWriter, cSess *sessdata.ConnSessi
binary.BigEndian.PutUint16(pl.Data[4:6], uint16(l)) binary.BigEndian.PutUint16(pl.Data[4:6], uint16(l))
} }
} else { } else {
pl.Data = append(pl.Data[:0], plHeader...) // pl.Data = append(pl.Data[:0], plHeader...)
// 设置头类型 // 设置头类型
pl.Data[6] = pl.PType pl.Data[6] = pl.PType
} }

View File

@ -64,6 +64,7 @@ func LinkDtls(conn net.Conn, cSess *sessdata.ConnSession) {
case 0x03: // DPD-REQ case 0x03: // DPD-REQ
// base.Debug("recv DPD-REQ", cSess.IpAddr) // base.Debug("recv DPD-REQ", cSess.IpAddr)
pl.PType = 0x04 pl.PType = 0x04
pl.Data = pl.Data[:n]
if payloadOutDtls(cSess, dSess, pl) { if payloadOutDtls(cSess, dSess, pl) {
return return
} }
@ -93,6 +94,8 @@ func LinkDtls(conn net.Conn, cSess *sessdata.ConnSession) {
if payloadIn(cSess, pl) { if payloadIn(cSess, pl) {
return return
} }
// 只记录返回正确的数据时间
cSess.LastDataTime.Store(utils.NowSec())
} }
} }
@ -147,7 +150,8 @@ func dtlsWrite(conn net.Conn, dSess *sessdata.DtlsSession, cSess *sessdata.ConnS
} }
} else { } else {
// 设置头类型 // 设置头类型
pl.Data = append(pl.Data[:0], pl.PType) // pl.Data = append(pl.Data[:0], pl.PType)
pl.Data[0] = pl.PType
} }
n, err := conn.Write(pl.Data) n, err := conn.Write(pl.Data)
if err != nil { if err != nil {

View File

@ -14,6 +14,8 @@ func LinkHome(w http.ResponseWriter, r *http.Request) {
// hu, _ := httputil.DumpRequest(r, true) // hu, _ := httputil.DumpRequest(r, true)
// fmt.Println("DumpHome: ", string(hu)) // fmt.Println("DumpHome: ", string(hu))
w.Header().Set("Content-Type", "text/html; charset=utf-8") w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Header().Del("X-Aggregate-Auth")
connection := strings.ToLower(r.Header.Get("Connection")) connection := strings.ToLower(r.Header.Get("Connection"))
userAgent := strings.ToLower(r.UserAgent()) userAgent := strings.ToLower(r.UserAgent())
if connection == "close" && (strings.Contains(userAgent, "anyconnect") || strings.Contains(userAgent, "openconnect")) { if connection == "close" && (strings.Contains(userAgent, "anyconnect") || strings.Contains(userAgent, "openconnect")) {
@ -33,6 +35,8 @@ func LinkHome(w http.ResponseWriter, r *http.Request) {
} }
func LinkOtpQr(w http.ResponseWriter, r *http.Request) { func LinkOtpQr(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cross-Origin-Resource-Policy", "cross-origin")
_ = r.ParseForm() _ = r.ParseForm()
idS := r.FormValue("id") idS := r.FormValue("id")
jwtToken := r.FormValue("jwt") jwtToken := r.FormValue("jwt")

View File

@ -74,11 +74,7 @@ func LinkTun(cSess *sessdata.ConnSession) error {
// 通过 ip link show 查看 alias 信息 // 通过 ip link show 查看 alias 信息
cmdstr1 := fmt.Sprintf("ip link set dev %s up mtu %d multicast off", ifce.Name(), cSess.Mtu) cmdstr1 := fmt.Sprintf("ip link set dev %s up mtu %d multicast off alias %s.%s", ifce.Name(), cSess.Mtu, cSess.Group.Name, cSess.Username)
if !base.InContainer {
// 容器默认 iproute 不支持 alias
cmdstr1 += fmt.Sprintf(" alias %s.%s", cSess.Group.Name, cSess.Username)
}
cmdstr2 := fmt.Sprintf("ip addr add dev %s local %s peer %s/32", cmdstr2 := fmt.Sprintf("ip addr add dev %s local %s peer %s/32",
ifce.Name(), base.Cfg.Ipv4Gateway, cSess.IpAddr) ifce.Name(), base.Cfg.Ipv4Gateway, cSess.IpAddr)
err = execCmd([]string{cmdstr1, cmdstr2}) err = execCmd([]string{cmdstr1, cmdstr2})

View File

@ -136,7 +136,7 @@ func LinkTunnel(w http.ResponseWriter, r *http.Request) {
} }
HttpAddHeader(w, "X-CSTP-Split-Include", v.IpMask) HttpAddHeader(w, "X-CSTP-Split-Include", v.IpMask)
} }
// 不允许的路由 // 不允许的路由 X-Cstp-Remote-Address-Ip4:
for _, v := range cSess.Group.RouteExclude { for _, v := range cSess.Group.RouteExclude {
HttpAddHeader(w, "X-CSTP-Split-Exclude", v.IpMask) HttpAddHeader(w, "X-CSTP-Split-Exclude", v.IpMask)
} }
@ -184,10 +184,9 @@ func LinkTunnel(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
hClone := w.Header().Clone() hClone := w.Header().Clone()
headers := make([]byte, 0) buf := &bytes.Buffer{}
buf := bytes.NewBuffer(headers)
_ = hClone.Write(buf) _ = hClone.Write(buf)
base.Debug(buf.String()) base.Trace("LinkTunnel Response Header:", buf.String())
hj := w.(http.Hijacker) hj := w.(http.Hijacker)
conn, bufRW, err := hj.Hijack() conn, bufRW, err := hj.Hijack()

View File

@ -55,11 +55,9 @@ func LinkMacvtap(cSess *sessdata.ConnSession) error {
cSess.SetIfName(ifName) cSess.SetIfName(ifName)
cmdstr1 := fmt.Sprintf("ip link add link %s name %s type macvtap mode bridge", base.Cfg.Ipv4Master, ifName) cmdstr1 := fmt.Sprintf("ip link add link %s name %s type macvtap mode bridge", base.Cfg.Ipv4Master, ifName)
cmdstr2 := fmt.Sprintf("ip link set dev %s up mtu %d address %s", ifName, cSess.Mtu, cSess.MacHw) cmdstr2 := fmt.Sprintf("ip link set dev %s up mtu %d address %s alias %s.%s", ifName, cSess.Mtu,
if !base.InContainer { cSess.MacHw, cSess.Group.Name, cSess.Username)
// 容器默认 iproute 不支持 alias
cmdstr2 += fmt.Sprintf(" alias %s.%s", cSess.Group.Name, cSess.Username)
}
err := execCmd([]string{cmdstr1, cmdstr2}) err := execCmd([]string{cmdstr1, cmdstr2})
if err != nil { if err != nil {
base.Error(err) base.Error(err)

View File

@ -59,9 +59,9 @@ func startTls() {
Addr: addr, Addr: addr,
Handler: initRoute(), Handler: initRoute(),
TLSConfig: tlsConfig, TLSConfig: tlsConfig,
ErrorLog: base.GetBaseLog(), ErrorLog: base.GetServerLog(),
ReadTimeout: 60 * time.Second, ReadTimeout: 100 * time.Second,
WriteTimeout: 60 * time.Second, WriteTimeout: 100 * time.Second,
} }
ln, err = net.Listen("tcp", addr) ln, err = net.Listen("tcp", addr)

View File

@ -20,14 +20,21 @@ import (
var uiData embed.FS var uiData embed.FS
// 程序版本 // 程序版本
var CommitId string var (
appVer string
commitId string
date string
)
func main() { func main() {
base.CommitId = CommitId
admin.UiData = uiData admin.UiData = uiData
base.APP_VER = appVer
base.CommitId = commitId
base.Date = date
base.Start() base.Start()
handler.Start() handler.Start()
signalWatch() signalWatch()
} }
@ -35,7 +42,7 @@ func signalWatch() {
base.Info("Server pid: ", os.Getpid()) base.Info("Server pid: ", os.Getpid())
sigs := make(chan os.Signal, 1) sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGALRM) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGALRM, syscall.SIGUSR2)
for { for {
sig := <-sigs sig := <-sigs
base.Info("Get signal:", sig) base.Info("Get signal:", sig)

View File

@ -89,10 +89,13 @@ func initIpPool() {
// } // }
// AcquireIp 获取动态ip // AcquireIp 获取动态ip
func AcquireIp(username, macAddr string, uniqueMac bool) net.IP { func AcquireIp(username, macAddr string, uniqueMac bool) (newIp net.IP) {
base.Trace("AcquireIp:", username, macAddr, uniqueMac) base.Trace("AcquireIp start:", username, macAddr, uniqueMac)
ipPoolMux.Lock() ipPoolMux.Lock()
defer ipPoolMux.Unlock() defer func() {
ipPoolMux.Unlock()
base.Trace("AcquireIp end:", username, macAddr, uniqueMac, newIp)
}()
var ( var (
err error err error

View File

@ -49,6 +49,7 @@ type ConnSession struct {
BandwidthDownAll atomic2.Uint64 // 使用下行带宽总量 BandwidthDownAll atomic2.Uint64 // 使用下行带宽总量
closeOnce sync.Once closeOnce sync.Once
CloseChan chan struct{} CloseChan chan struct{}
LastDataTime atomic2.Time // 最后数据传输时间
PayloadIn chan *Payload PayloadIn chan *Payload
PayloadOutCstp chan *Payload // Cstp的数据 PayloadOutCstp chan *Payload // Cstp的数据
PayloadOutDtls chan *Payload // Dtls的数据 PayloadOutDtls chan *Payload // Dtls的数据
@ -219,6 +220,7 @@ func (s *Session) NewConn() *ConnSession {
PayloadOutDtls: make(chan *Payload, 64), PayloadOutDtls: make(chan *Payload, 64),
dSess: &atomic.Value{}, dSess: &atomic.Value{},
} }
cSess.LastDataTime.Store(time.Now())
dSess := &DtlsSession{ dSess := &DtlsSession{
isActive: -1, isActive: -1,

1
version Normal file
View File

@ -0,0 +1 @@
0.10.3

View File

@ -23,13 +23,16 @@
</el-upload> </el-upload>
<el-dropdown-menu slot="dropdown"> <el-dropdown-menu slot="dropdown">
<el-dropdown-item> <el-dropdown-item>
<el-link style="font-size:12px;" type="success" href="批量添加用户模版.xlsx"><i class="el-icon-download"></i>下载模版</el-link> <el-link style="font-size:12px;" type="success" href="批量添加用户模版.xlsx"><i
class="el-icon-download"></i>下载模版
</el-link>
</el-dropdown-item> </el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
</el-dropdown> </el-dropdown>
</el-form-item> </el-form-item>
<el-form-item label="用户名:"> <el-form-item label="用户名或姓名或邮箱:">
<el-input size="small" v-model="searchData" placeholder="请输入内容" @keydown.enter.native="searchEnterFun"></el-input> <el-input size="small" v-model="searchData" placeholder="请输入内容"
@keydown.enter.native="searchEnterFun"></el-input>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>