Initial commit (code only without large binaries)

This commit is contained in:
robin
2026-02-15 18:58:44 +08:00
commit 35df75498f
9442 changed files with 1495866 additions and 0 deletions

View File

@@ -0,0 +1,95 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package authority
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/plus"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
plusutils "github.com/TeaOSLab/EdgePlus/pkg/utils"
"github.com/iwind/TeaGo/actions"
)
type ActivateAction struct {
actionutils.ParentAction
}
func (this *ActivateAction) Init() {
this.Nav("", "", "activate")
}
func (this *ActivateAction) RunGet(params struct{}) {
// 选中左侧菜单
this.Data["teaSubMenu"] = "authority"
this.Show()
}
func (this *ActivateAction) RunPost(params struct {
Key string
Must *actions.Must
CSRF *actionutils.CSRF
}) {
requestCode, err := plusutils.GenerateRequestCode()
if err != nil {
this.ErrorPage(err)
return
}
if len(params.Key) == 0 {
this.FailField("key", "请输入注册码")
}
// 本地检查
key, err := plusutils.DecodeKey([]byte(params.Key))
if err != nil {
this.Fail("请输入正确的注册码")
return
}
if key.Method != plusutils.MethodRemote {
if len(key.RequestCode) > 0 { // 使用注册码激活
ok, errorCode := plusutils.ValidateRequestCode(key.RequestCode)
if !ok {
this.Fail("无法在当前服务器上使用此注册码,请联系软件开发者,错误代号:" + errorCode)
return
}
} else if len(key.MacAddresses) > 0 { // 使用MAC地址激活
for _, address := range key.MacAddresses {
if !plus.ValidateMac(address) {
this.Fail("无法在当前服务器上使用此注册码,请联系软件开发者")
return
}
}
}
}
resp, err := this.RPC().AuthorityKeyRPC().ValidateAuthorityKey(this.AdminContext(), &pb.ValidateAuthorityKeyRequest{
Key: params.Key,
RequestCode: requestCode,
})
if err != nil {
this.ErrorPage(err)
return
}
if resp.IsOk {
_, err := this.RPC().AuthorityKeyRPC().UpdateAuthorityKey(this.AdminContext(), &pb.UpdateAuthorityKeyRequest{
Value: params.Key,
RequestCode: requestCode,
})
if err != nil {
this.ErrorPage(err)
return
}
// 显示菜单
_ = configloaders.ReloadAdminUIConfig()
this.Success()
} else {
this.FailField("key", "无法激活:"+resp.Error)
}
}

View File

@@ -0,0 +1,31 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package authority
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
plusutils "github.com/TeaOSLab/EdgePlus/pkg/utils"
)
type ApplyAction struct {
actionutils.ParentAction
}
func (this *ApplyAction) Init() {
this.Nav("", "", "apply")
}
func (this *ApplyAction) RunGet(params struct{}) {
// 选中左侧菜单
this.Data["teaSubMenu"] = "authority"
requestCode, err := plusutils.GenerateRequestCode()
if err != nil {
this.ErrorPage(err)
return
}
this.Data["requestCode"] = requestCode
this.Show()
}

View File

@@ -0,0 +1,118 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package authority
import (
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
"github.com/TeaOSLab/EdgeAdmin/internal/plus"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
plusutils "github.com/TeaOSLab/EdgePlus/pkg/utils"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
"time"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("authority", "", "index")
}
func (this *IndexAction) RunGet(params struct{}) {
// 选中左侧菜单
this.Data["teaSubMenu"] = "authority"
this.Data["key"] = nil
this.Data["plusErr"] = ""
keyResp, err := this.RPC().AuthorityKeyRPC().ReadAuthorityKey(this.AdminContext(), &pb.ReadAuthorityKeyRequest{})
if err != nil {
this.Data["plusErr"] = err.Error()
this.Show()
return
}
var keyMap maps.Map = nil
teaconst.IsPlus = false
plus.UpdateComponents("", []string{})
plus.ErrString = ""
var key = keyResp.AuthorityKey
if key != nil {
if len(key.MacAddresses) == 0 {
key.MacAddresses = []string{}
}
if len(key.Components) == 0 {
key.Components = []string{}
}
var isActive = len(key.DayTo) > 0 && key.DayTo >= timeutil.Format("Y-m-d")
var method = ""
if isActive {
nativeKey, err := plusutils.DecodeKey([]byte(key.Value))
var isOk = true
if err != nil {
teaconst.IsPlus = false
} else if len(nativeKey.RequestCode) > 0 { // 使用申请码
method = nativeKey.Method
isOk, _ = plusutils.ValidateRequestCode(nativeKey.RequestCode)
} else if len(nativeKey.MacAddresses) > 0 { // MAC地址
for _, address := range nativeKey.MacAddresses {
if !plus.ValidateMac(address) {
isOk = false
break
}
}
}
if isOk {
teaconst.IsPlus = true
plus.UpdateComponents(key.Edition, key.Components)
} else {
teaconst.IsPlus = false
plus.UpdateComponents("", []string{})
plus.ErrString = "当前管理平台所在服务器环境与商业版认证分发时发生了变化,因此无法使用商业版功能。如果你正在迁移管理平台,请联系开发者重新申请新的注册码。"
}
}
var isExpiring = isActive && key.DayTo < timeutil.Format("Y-m-d", time.Now().AddDate(0, 0, 7))
// 终身授权
var dayTo = key.DayTo
if dayTo >= "2050-01-01" {
dayTo = "终身授权"
}
keyMap = maps.Map{
"dayFrom": key.DayFrom,
"dayTo": dayTo,
"hostname": key.Hostname,
"company": key.Company,
"nodes": key.Nodes,
"components": key.Components,
"editionName": plusutils.EditionName(key.Edition),
"isExpired": !isActive,
"isExpiring": isExpiring,
"updatedTime": timeutil.FormatTime("Y-m-d H:i:s", keyResp.AuthorityKey.UpdatedAt),
"method": method,
}
}
this.Data["key"] = keyMap
this.Data["plusErr"] = plus.ErrString
// 配额
quotaResp, err := this.RPC().AuthorityKeyRPC().FindAuthorityQuota(this.AdminContext(), &pb.FindAuthorityQuotaRequest{})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["quota"] = maps.Map{
"maxNodes": quotaResp.MaxNodes,
"countNodes": quotaResp.CountNodes,
}
this.Show()
}

View File

@@ -0,0 +1,23 @@
//go:build plus
package authority
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/settingutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeSetting)).
Helper(settingutils.NewAdvancedHelper("authority")).
Prefix("/settings/authority").
Get("", new(IndexAction)).
Get("/apply", new(ApplyAction)).
GetPost("/activate", new(ActivateAction)).
EndAll()
})
}