6 Commits

Author SHA1 Message Date
bjdgyc
7342f1f1a9 修改版本 v0.1.8 2021-03-17 14:14:45 +08:00
bjdgyc
7a2d8a3ad0 修改日志默认为标准输出 2021-03-17 14:04:07 +08:00
bjdgyc
b5927a11d3 Merge pull request #8 from xbclub/main
fix systemd
2021-03-17 13:06:57 +08:00
yii
273b3ee1eb fix systemd 2021-03-17 11:37:34 +08:00
bjdgyc
016a43b792 完善测试文件 2021-03-10 17:00:16 +08:00
bjdgyc
ddba116fbf 修复登陆密码判断bug 2021-03-02 15:28:08 +08:00
10 changed files with 111 additions and 12 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,5 @@
# Binaries for programs and plugins # Binaries for programs and plugins
.idea/ .idea/
anylink-deploy anylink-deploy
ui

View File

@@ -34,7 +34,7 @@ AnyLink 服务端仅在CentOS 7、Ubuntu 18.04测试通过,如需要安装在
git clone https://github.com/bjdgyc/anylink.git git clone https://github.com/bjdgyc/anylink.git
cd anylink cd anylink
sh build.sh sh -x build.sh
# 注意使用root权限运行 # 注意使用root权限运行
cd anylink-deploy cd anylink-deploy
@@ -42,6 +42,8 @@ sudo ./anylink -conf="conf/server.toml"
# 默认管理后台访问地址 # 默认管理后台访问地址
# http://host:8800 # http://host:8800
# 默认日志文件
# log/anylink.log
``` ```
## Feature ## Feature
@@ -76,6 +78,22 @@ sudo ./anylink -conf="conf/server.toml"
[conf/server.toml](server/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 ## Setting
网络模式选择,需要配置 `link_mode` 参数,如 `link_mode="tun"`,`link_mode="tap"` 两种参数。 不同的参数需要对服务器做相应的设置。 网络模式选择,需要配置 `link_mode` 参数,如 `link_mode="tun"`,`link_mode="tap"` 两种参数。 不同的参数需要对服务器做相应的设置。

View File

@@ -2,5 +2,5 @@ package base
const ( const (
APP_NAME = "AnyLink" APP_NAME = "AnyLink"
APP_VER = "0.1.6" APP_VER = "0.1.8"
) )

View File

@@ -11,7 +11,8 @@ cert_key = "./vpn_cert.key"
ui_path = "../ui" ui_path = "../ui"
files_path = "../files" files_path = "../files"
#日志目录,为空写入标准输出 #日志目录,为空写入标准输出
log_path = "../log" #log_path = "../log"
log_path = ""
log_level = "info" log_level = "info"
#系统名称 #系统名称

View File

@@ -22,12 +22,13 @@ func closeIpdata() {
} }
func TestDb(t *testing.T) { func TestDb(t *testing.T) {
assert := assert.New(t) ast := assert.New(t)
preIpData() preIpData()
defer closeIpdata() defer closeIpdata()
u := User{Username: "a"} u := User{Username: "a"}
_ = Save(&u) err := Save(&u)
ast.Nil(err)
assert.Equal(u.Id, 1) ast.Equal(u.Id, 1)
} }

View 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))
}
}

View File

@@ -35,7 +35,7 @@ func SetUser(v *User) error {
planPass := v.PinCode planPass := v.PinCode
// 自动生成密码 // 自动生成密码
if len(planPass) < 6 { if len(planPass) < 6 {
planPass = utils.RandomNum(8) planPass = utils.RandomRunes(8)
} }
v.PinCode = planPass v.PinCode = planPass
@@ -82,12 +82,13 @@ func CheckUser(name, pwd, group string) error {
groupData := &Group{} groupData := &Group{}
err = One("Name", group, groupData) err = One("Name", group, groupData)
if err != nil || groupData.Status != 1 { if err != nil || groupData.Status != 1 {
return fmt.Errorf("%s %s", name, "用户组错误") return fmt.Errorf("%s - %s", name, "用户组错误")
} }
// 判断otp信息 // 判断otp信息
pinCode := pwd
if !v.DisableOtp { if !v.DisableOtp {
pwd = pwd[:pl-6] pinCode = pwd[:pl-6]
otp := pwd[pl-6:] otp := pwd[pl-6:]
if !checkOtp(name, otp, v.OtpSecret) { if !checkOtp(name, otp, v.OtpSecret) {
return fmt.Errorf("%s %s", name, "动态码错误") 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, "密码错误") return fmt.Errorf("%s %s", name, "密码错误")
} }

View 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)
}

View File

@@ -61,7 +61,7 @@ func HumanByte(bf interface{}) string {
return hb return hb
} }
func RandomNum(length int) string { func RandomRunes(length int) string {
letterRunes := []rune("abcdefghijklmnpqrstuvwxy1234567890") letterRunes := []rune("abcdefghijklmnpqrstuvwxy1234567890")
bytes := make([]rune, length) bytes := make([]rune, length)

View File

@@ -8,6 +8,6 @@ User=root
WorkingDirectory= /usr/local/anylink-deploy WorkingDirectory= /usr/local/anylink-deploy
Restart=on-failure Restart=on-failure
RestartSec=5s RestartSec=5s
ExecStart=/usr/local/anylink-deploy/anylink -conf="conf/server.toml" ExecStart=/usr/local/anylink-deploy/anylink -conf=conf/server.toml
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target