5 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
9 changed files with 103 additions and 9 deletions

View File

@@ -78,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"` 两种参数。 不同的参数需要对服务器做相应的设置。

View File

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

View File

@@ -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"
#系统名称

View File

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

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
// 自动生成密码
if len(planPass) < 6 {
planPass = utils.RandomNum(8)
planPass = utils.RandomRunes(8)
}
v.PinCode = planPass
@@ -82,7 +82,7 @@ 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信息

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
}
func RandomNum(length int) string {
func RandomRunes(length int) string {
letterRunes := []rune("abcdefghijklmnpqrstuvwxy1234567890")
bytes := make([]rune, length)

View File

@@ -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