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,172 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package setting
import (
"encoding/json"
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/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/maps"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "index")
}
func (this *IndexAction) RunGet(params struct{}) {
if !teaconst.IsPlus {
this.RedirectURL("/users")
return
}
// 当前配置
resp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: systemconfigs.SettingCodeUserRegisterConfig})
if err != nil {
this.ErrorPage(err)
return
}
var config = userconfigs.DefaultUserRegisterConfig()
if len(resp.ValueJSON) > 0 {
err = json.Unmarshal(resp.ValueJSON, config)
if err != nil {
this.ErrorPage(err)
return
}
}
this.Data["config"] = config
// 功能列表
var featureMaps = []maps.Map{}
for _, feature := range userconfigs.FindAllUserFeatures() {
featureMaps = append(featureMaps, maps.Map{
"name": feature.Name,
"description": feature.Description,
"code": feature.Code,
"isChecked": lists.ContainsString(config.Features, feature.Code),
})
}
this.Data["features"] = featureMaps
// 当前高防
this.Data["adIsVisible"] = plus.AllowComponent(plus.ComponentCodeAntiDDoS)
// 当前默认的智能DNS设置
this.Data["nsIsVisible"] = plus.AllowComponent(plus.ComponentCodeNS)
this.Show()
}
func (this *IndexAction) RunPost(params struct {
IsOn bool
ComplexPassword bool
RequireVerification bool
RequireIdentity bool
CheckClientRegion bool
EmailVerificationIsOn bool
EmailVerificationShowNotice bool
EmailVerificationCanLogin bool
EmailVerificationSubject string
EmailVerificationBody string
EmailResetPasswordIsOn bool
EmailResetPasswordSubject string
EmailResetPasswordBody string
MobileVerificationIsOn bool
MobileVerificationShowNotice bool
MobileVerificationCanLogin bool
MobileVerificationForce bool
MobileVerificationBody string
CdnIsOn bool
ClusterId int64
Features []string
FeatureOp string
AdIsOn bool
NsIsOn bool
Must *actions.Must
CSRF *actionutils.CSRF
}) {
defer this.CreateLogInfo(codes.User_LogUpdateUserGlobalSettings)
params.Must.
Field("clusterId", params.ClusterId).
Gt(0, "请选择一个集群")
var config = userconfigs.DefaultUserRegisterConfig()
config.IsOn = params.IsOn
config.ComplexPassword = params.ComplexPassword
config.RequireVerification = params.RequireVerification
config.RequireIdentity = params.RequireIdentity
config.CheckClientRegion = params.CheckClientRegion
config.EmailVerification.IsOn = params.EmailVerificationIsOn
config.EmailVerification.CanLogin = params.EmailVerificationCanLogin
config.EmailVerification.Subject = params.EmailVerificationSubject
config.EmailVerification.Body = params.EmailVerificationBody
config.EmailVerification.ShowNotice = params.EmailVerificationShowNotice
config.MobileVerification.IsOn = params.MobileVerificationIsOn
config.MobileVerification.CanLogin = params.MobileVerificationCanLogin
config.MobileVerification.Force = params.MobileVerificationForce
config.MobileVerification.Body = params.MobileVerificationBody
config.MobileVerification.ShowNotice = params.MobileVerificationShowNotice
config.EmailResetPassword.IsOn = params.EmailResetPasswordIsOn
config.EmailResetPassword.Subject = params.EmailResetPasswordSubject
config.EmailResetPassword.Body = params.EmailResetPasswordBody
config.CDNIsOn = params.CdnIsOn
config.ClusterId = params.ClusterId
config.Features = params.Features
config.ADIsOn = params.AdIsOn
config.NSIsOn = params.NsIsOn
configJSON, err := json.Marshal(config)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
Code: systemconfigs.SettingCodeUserRegisterConfig,
ValueJSON: configJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
if params.FeatureOp != "keep" {
_, err = this.RPC().UserRPC().UpdateAllUsersFeatures(this.AdminContext(), &pb.UpdateAllUsersFeaturesRequest{
FeatureCodes: params.Features,
Overwrite: params.FeatureOp == "overwrite",
})
if err != nil {
this.ErrorPage(err)
return
}
}
this.Success()
}