mirror of
https://github.com/bjdgyc/anylink.git
synced 2025-09-29 00:19:36 +08:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
7342f1f1a9 | ||
|
7a2d8a3ad0 | ||
|
b5927a11d3 | ||
|
273b3ee1eb | ||
|
016a43b792 | ||
|
ddba116fbf |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
# Binaries for programs and plugins
|
||||
.idea/
|
||||
anylink-deploy
|
||||
ui
|
||||
|
||||
|
20
README.md
20
README.md
@@ -34,7 +34,7 @@ AnyLink 服务端仅在CentOS 7、Ubuntu 18.04测试通过,如需要安装在
|
||||
git clone https://github.com/bjdgyc/anylink.git
|
||||
|
||||
cd anylink
|
||||
sh build.sh
|
||||
sh -x build.sh
|
||||
|
||||
# 注意使用root权限运行
|
||||
cd anylink-deploy
|
||||
@@ -42,6 +42,8 @@ sudo ./anylink -conf="conf/server.toml"
|
||||
|
||||
# 默认管理后台访问地址
|
||||
# http://host:8800
|
||||
# 默认日志文件
|
||||
# log/anylink.log
|
||||
```
|
||||
|
||||
## Feature
|
||||
@@ -76,6 +78,22 @@ sudo ./anylink -conf="conf/server.toml"
|
||||
|
||||
[conf/server.toml](server/conf/server.toml)
|
||||
|
||||
## systemd
|
||||
|
||||
添加 systemd脚本
|
||||
* anylink 程序目录放入 `/usr/local/anylink-deploy`
|
||||
|
||||
systemd 脚本放入:
|
||||
* centos: `/usr/lib/systemd/system/`
|
||||
* ubuntu: `/lib/systemd/system/`
|
||||
|
||||
操作命令:
|
||||
* 启动: `systemctl start anylink`
|
||||
* 停止: `systemctl stop anylink`
|
||||
* 开机自启: `systemctl enable anylink`
|
||||
|
||||
|
||||
|
||||
## Setting
|
||||
|
||||
网络模式选择,需要配置 `link_mode` 参数,如 `link_mode="tun"`,`link_mode="tap"` 两种参数。 不同的参数需要对服务器做相应的设置。
|
||||
|
@@ -2,5 +2,5 @@ package base
|
||||
|
||||
const (
|
||||
APP_NAME = "AnyLink"
|
||||
APP_VER = "0.1.6"
|
||||
APP_VER = "0.1.8"
|
||||
)
|
||||
|
@@ -11,7 +11,8 @@ cert_key = "./vpn_cert.key"
|
||||
ui_path = "../ui"
|
||||
files_path = "../files"
|
||||
#日志目录,为空写入标准输出
|
||||
log_path = "../log"
|
||||
#log_path = "../log"
|
||||
log_path = ""
|
||||
log_level = "info"
|
||||
|
||||
#系统名称
|
||||
|
@@ -22,12 +22,13 @@ func closeIpdata() {
|
||||
}
|
||||
|
||||
func TestDb(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
ast := assert.New(t)
|
||||
preIpData()
|
||||
defer closeIpdata()
|
||||
|
||||
u := User{Username: "a"}
|
||||
_ = Save(&u)
|
||||
err := Save(&u)
|
||||
ast.Nil(err)
|
||||
|
||||
assert.Equal(u.Id, 1)
|
||||
ast.Equal(u.Id, 1)
|
||||
}
|
||||
|
33
server/dbdata/group_test.go
Normal file
33
server/dbdata/group_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package dbdata
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/bjdgyc/anylink/pkg/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetGroupNames(t *testing.T) {
|
||||
ast := assert.New(t)
|
||||
|
||||
preIpData()
|
||||
defer closeIpdata()
|
||||
|
||||
// 添加 group
|
||||
g1 := Group{Name: "g1", ClientDns: []ValData{{Val: "114.114.114.114"}}}
|
||||
err := SetGroup(&g1)
|
||||
ast.Nil(err)
|
||||
g2 := Group{Name: "g2", ClientDns: []ValData{{Val: "114.114.114.114"}}}
|
||||
err = SetGroup(&g2)
|
||||
ast.Nil(err)
|
||||
g3 := Group{Name: "g3", ClientDns: []ValData{{Val: "114.114.114.114"}}}
|
||||
err = SetGroup(&g3)
|
||||
ast.Nil(err)
|
||||
|
||||
// 判断所有数据
|
||||
gAll := []string{"g1", "g2", "g3"}
|
||||
gs := GetGroupNames()
|
||||
for _, v := range gs {
|
||||
ast.Equal(true, utils.InArrStr(gAll, v))
|
||||
}
|
||||
}
|
@@ -35,7 +35,7 @@ func SetUser(v *User) error {
|
||||
planPass := v.PinCode
|
||||
// 自动生成密码
|
||||
if len(planPass) < 6 {
|
||||
planPass = utils.RandomNum(8)
|
||||
planPass = utils.RandomRunes(8)
|
||||
}
|
||||
v.PinCode = planPass
|
||||
|
||||
@@ -82,12 +82,13 @@ func CheckUser(name, pwd, group string) error {
|
||||
groupData := &Group{}
|
||||
err = One("Name", group, groupData)
|
||||
if err != nil || groupData.Status != 1 {
|
||||
return fmt.Errorf("%s %s", name, "用户组错误")
|
||||
return fmt.Errorf("%s - %s", name, "用户组错误")
|
||||
}
|
||||
|
||||
// 判断otp信息
|
||||
pinCode := pwd
|
||||
if !v.DisableOtp {
|
||||
pwd = pwd[:pl-6]
|
||||
pinCode = pwd[:pl-6]
|
||||
otp := pwd[pl-6:]
|
||||
if !checkOtp(name, otp, v.OtpSecret) {
|
||||
return fmt.Errorf("%s %s", name, "动态码错误")
|
||||
@@ -95,7 +96,7 @@ func CheckUser(name, pwd, group string) error {
|
||||
}
|
||||
|
||||
// 判断用户密码
|
||||
if pwd != v.PinCode {
|
||||
if pinCode != v.PinCode {
|
||||
return fmt.Errorf("%s %s", name, "密码错误")
|
||||
}
|
||||
|
||||
|
43
server/dbdata/user_test.go
Normal file
43
server/dbdata/user_test.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package dbdata
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/xlzd/gotp"
|
||||
)
|
||||
|
||||
func TestCheckUser(t *testing.T) {
|
||||
ast := assert.New(t)
|
||||
|
||||
preIpData()
|
||||
defer closeIpdata()
|
||||
|
||||
group := "group1"
|
||||
|
||||
// 添加一个组
|
||||
dns := []ValData{{Val: "114.114.114.114"}}
|
||||
route := []ValData{{Val: "192.168.1.1/24"}}
|
||||
g := Group{Name: group, Status: 1, ClientDns: dns, RouteInclude: route}
|
||||
err := SetGroup(&g)
|
||||
ast.Nil(err)
|
||||
// 判断 IpMask
|
||||
ast.Equal(g.RouteInclude[0].IpMask, "192.168.1.1/255.255.255.0")
|
||||
|
||||
// 添加一个用户
|
||||
u := User{Username: "aaa", Groups: []string{group}, Status: 1}
|
||||
err = SetUser(&u)
|
||||
ast.Nil(err)
|
||||
|
||||
// 验证 PinCode + OtpSecret
|
||||
totp := gotp.NewDefaultTOTP(u.OtpSecret)
|
||||
secret := totp.Now()
|
||||
err = CheckUser("aaa", u.PinCode+secret, group)
|
||||
ast.Nil(err)
|
||||
|
||||
// 单独验证密码
|
||||
u.DisableOtp = true
|
||||
_ = SetUser(&u)
|
||||
err = CheckUser("aaa", u.PinCode, group)
|
||||
ast.Nil(err)
|
||||
}
|
@@ -61,7 +61,7 @@ func HumanByte(bf interface{}) string {
|
||||
return hb
|
||||
}
|
||||
|
||||
func RandomNum(length int) string {
|
||||
func RandomRunes(length int) string {
|
||||
letterRunes := []rune("abcdefghijklmnpqrstuvwxy1234567890")
|
||||
|
||||
bytes := make([]rune, length)
|
||||
|
@@ -8,6 +8,6 @@ User=root
|
||||
WorkingDirectory= /usr/local/anylink-deploy
|
||||
Restart=on-failure
|
||||
RestartSec=5s
|
||||
ExecStart=/usr/local/anylink-deploy/anylink -conf="conf/server.toml"
|
||||
ExecStart=/usr/local/anylink-deploy/anylink -conf=conf/server.toml
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
Reference in New Issue
Block a user