增加商业版激活功能

This commit is contained in:
GoEdgeLab
2021-09-16 10:32:58 +08:00
parent f4f268d9b7
commit 35fd437aaa
8 changed files with 100 additions and 15 deletions

View File

@@ -0,0 +1,52 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package server
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
)
type ActivateAction struct {
actionutils.ParentAction
}
func (this *ActivateAction) Init() {
this.Nav("", "", "activate")
}
func (this *ActivateAction) RunGet(params struct{}) {
this.Show()
}
func (this *ActivateAction) RunPost(params struct {
Key string
Must *actions.Must
CSRF *actionutils.CSRF
}) {
if len(params.Key) == 0 {
this.FailField("key", "请输入激活码")
}
resp, err := this.RPC().AuthorityKeyRPC().ValidateAuthorityKey(this.AdminContext(), &pb.ValidateAuthorityKeyRequest{Key: params.Key})
if err != nil {
this.ErrorPage(err)
return
}
if resp.IsOk {
_, err := this.RPC().AuthorityKeyRPC().UpdateAuthorityKey(this.AdminContext(), &pb.UpdateAuthorityKeyRequest{
Value: params.Key,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
} else {
this.FailField("key", "无法激活:"+resp.Error)
}
}

View File

@@ -8,6 +8,7 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
"time"
)
type IndexAction struct {
@@ -26,24 +27,28 @@ func (this *IndexAction) RunGet(params struct{}) {
}
var keyMap maps.Map = nil
teaconst.IsPlus = false
if keyResp.AuthorityKey != nil {
if len(keyResp.AuthorityKey.MacAddresses) == 0 {
keyResp.AuthorityKey.MacAddresses = []string{}
var key = keyResp.AuthorityKey
if key != nil {
if len(key.MacAddresses) == 0 {
key.MacAddresses = []string{}
}
isActive := len(keyResp.AuthorityKey.DayTo) > 0 && keyResp.AuthorityKey.DayTo >= timeutil.Format("Y-m-d")
isActive := len(key.DayTo) > 0 && key.DayTo >= timeutil.Format("Y-m-d")
if isActive {
teaconst.IsPlus = true
}
isExpiring := isActive && key.DayTo < timeutil.Format("Y-m-d", time.Now().AddDate(0, 0, 7))
keyMap = maps.Map{
"dayFrom": keyResp.AuthorityKey.DayFrom,
"dayTo": keyResp.AuthorityKey.DayTo,
"macAddresses": keyResp.AuthorityKey.MacAddresses,
"hostname": keyResp.AuthorityKey.Hostname,
"company": keyResp.AuthorityKey.Company,
"nodes": keyResp.AuthorityKey.Nodes,
"dayFrom": key.DayFrom,
"dayTo": key.DayTo,
"macAddresses": key.MacAddresses,
"hostname": key.Hostname,
"company": key.Company,
"nodes": key.Nodes,
"isExpired": !isActive,
"isExpiring": isExpiring,
"updatedTime": timeutil.FormatTime("Y-m-d H:i:s", keyResp.AuthorityKey.UpdatedAt),
}
}

View File

@@ -14,6 +14,7 @@ func init() {
Helper(settingutils.NewAdvancedHelper("authority")).
Prefix("/settings/authority").
Get("", new(IndexAction)).
GetPost("/activate", new(ActivateAction)).
EndAll()
})
}

View File

@@ -39,7 +39,7 @@ func (this *AdvancedHelper) BeforeAction(actionPtr actions.ActionWrapper) (goNex
tabbar.Add("监控节点", "", "/settings/monitorNodes", "", this.tab == "monitorNodes")
}
if teaconst.BuildPlus {
tabbar.Add("业版认证", "", "/settings/authority", "", this.tab == "authority")
tabbar.Add("业版认证", "", "/settings/authority", "", this.tab == "authority")
}
//tabbar.Add("备份", "", "/settings/backup", "", this.tab == "backup")