换成单集群模式

This commit is contained in:
robin
2026-03-02 20:07:53 +08:00
parent 5d0b7c7e91
commit 2a76d1773d
432 changed files with 5681 additions and 5095 deletions

View File

@@ -10,6 +10,7 @@ import (
"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"
"github.com/xlzd/gotp"
)
@@ -23,6 +24,38 @@ func (this *CreatePopupAction) Init() {
}
func (this *CreatePopupAction) RunGet(params struct{}) {
// 检查是否启用了 HTTPDNS 功能(全局用户注册设置中)
var hasHTTPDNSFeature = false
var defaultHttpdnsClusterId int64 = 0
resp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: systemconfigs.SettingCodeUserRegisterConfig})
if err == nil && len(resp.ValueJSON) > 0 {
var config = userconfigs.DefaultUserRegisterConfig()
if json.Unmarshal(resp.ValueJSON, config) == nil {
hasHTTPDNSFeature = config.HTTPDNSIsOn
if len(config.HTTPDNSDefaultClusterIds) > 0 {
defaultHttpdnsClusterId = config.HTTPDNSDefaultClusterIds[0]
}
}
}
this.Data["hasHTTPDNSFeature"] = hasHTTPDNSFeature
this.Data["httpdnsClusterId"] = defaultHttpdnsClusterId
// 加载所有 HTTPDNS 集群
var httpdnsClusters = []maps.Map{}
if hasHTTPDNSFeature {
httpdnsClusterResp, err := this.RPC().HTTPDNSClusterRPC().FindAllHTTPDNSClusters(this.AdminContext(), &pb.FindAllHTTPDNSClustersRequest{})
if err == nil {
for _, c := range httpdnsClusterResp.GetClusters() {
httpdnsClusters = append(httpdnsClusters, maps.Map{
"id": c.GetId(),
"name": c.GetName(),
})
}
}
}
this.Data["httpdnsClusters"] = httpdnsClusters
this.Show()
}
@@ -35,8 +68,9 @@ func (this *CreatePopupAction) RunPost(params struct {
Tel string
Email string
Remark string
ClusterId int64
FeaturesType string
ClusterId int64
HttpdnsClusterId int64
FeaturesType string
// OTP
OtpOn bool
@@ -111,6 +145,28 @@ func (this *CreatePopupAction) RunPost(params struct {
userId = createResp.UserId
// 如果表单选择了 HTTPDNS 关联集群,在这里予以保存
if params.HttpdnsClusterId > 0 {
httpdnsJSON, _ := json.Marshal([]int64{params.HttpdnsClusterId})
_, err = this.RPC().UserRPC().UpdateUser(this.AdminContext(), &pb.UpdateUserRequest{
UserId: userId,
Username: params.Username,
Password: params.Pass1,
Fullname: params.Fullname,
Mobile: params.Mobile,
Tel: params.Tel,
Email: params.Email,
Remark: params.Remark,
IsOn: true,
NodeClusterId: params.ClusterId,
HttpdnsClusterIdsJSON: httpdnsJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
}
// 功能
if teaconst.IsPlus {
if params.FeaturesType == "default" {
@@ -127,14 +183,41 @@ func (this *CreatePopupAction) RunPost(params struct {
this.ErrorPage(err)
return
}
var featureCodes = config.Features
if config.HTTPDNSIsOn && !lists.ContainsString(featureCodes, userconfigs.UserFeatureCodeHTTPDNS) {
featureCodes = append(featureCodes, userconfigs.UserFeatureCodeHTTPDNS)
}
_, err = this.RPC().UserRPC().UpdateUserFeatures(this.AdminContext(), &pb.UpdateUserFeaturesRequest{
UserId: userId,
FeatureCodes: config.Features,
FeatureCodes: featureCodes,
})
if err != nil {
this.ErrorPage(err)
return
}
// 自动关联默认 HTTPDNS 集群 (如果没有在表单中选择的话)
if config.HTTPDNSIsOn && params.HttpdnsClusterId <= 0 && len(config.HTTPDNSDefaultClusterIds) > 0 {
httpdnsJSON, _ := json.Marshal(config.HTTPDNSDefaultClusterIds)
_, err = this.RPC().UserRPC().UpdateUser(this.AdminContext(), &pb.UpdateUserRequest{
UserId: userId,
Username: params.Username,
Password: params.Pass1,
Fullname: params.Fullname,
Mobile: params.Mobile,
Tel: params.Tel,
Email: params.Email,
Remark: params.Remark,
IsOn: true,
NodeClusterId: params.ClusterId,
HttpdnsClusterIdsJSON: httpdnsJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
}
}
} else if params.FeaturesType == "all" {
featuresResp, err := this.RPC().UserRPC().FindAllUserFeatureDefinitions(this.AdminContext(), &pb.FindAllUserFeatureDefinitionsRequest{})

View File

@@ -66,6 +66,28 @@ func (this *IndexAction) RunGet(params struct{}) {
// 当前默认的智能DNS设置
this.Data["nsIsVisible"] = plus.AllowComponent(plus.ComponentCodeNS)
// HTTPDNS 集群列表(用于默认集群多选)
httpdnsClusterResp, err := this.RPC().HTTPDNSClusterRPC().FindAllHTTPDNSClusters(this.AdminContext(), &pb.FindAllHTTPDNSClustersRequest{})
if err != nil {
this.ErrorPage(err)
return
}
httpdnsClusters := make([]maps.Map, 0, len(httpdnsClusterResp.GetClusters()))
for _, cluster := range httpdnsClusterResp.GetClusters() {
httpdnsClusters = append(httpdnsClusters, maps.Map{
"id": cluster.GetId(),
"name": cluster.GetName(),
})
}
this.Data["httpdnsClusters"] = httpdnsClusters
// 当前选中的默认集群(取数组第一个元素)
var httpdnsDefaultClusterId int64
if len(config.HTTPDNSDefaultClusterIds) > 0 {
httpdnsDefaultClusterId = config.HTTPDNSDefaultClusterIds[0]
}
this.Data["httpdnsDefaultClusterId"] = httpdnsDefaultClusterId
this.Show()
}
@@ -102,7 +124,8 @@ func (this *IndexAction) RunPost(params struct {
NsIsOn bool
HttpdnsIsOn bool
HttpdnsIsOn bool
HttpdnsDefaultClusterId int64
Must *actions.Must
CSRF *actionutils.CSRF
@@ -154,6 +177,11 @@ func (this *IndexAction) RunPost(params struct {
config.NSIsOn = params.NsIsOn
config.HTTPDNSIsOn = params.HttpdnsIsOn
if params.HttpdnsDefaultClusterId > 0 {
config.HTTPDNSDefaultClusterIds = []int64{params.HttpdnsDefaultClusterId}
} else {
config.HTTPDNSDefaultClusterIds = []int64{}
}
configJSON, err := json.Marshal(config)
if err != nil {

View File

@@ -1,6 +1,8 @@
package users
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/users/userutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
@@ -85,6 +87,46 @@ func (this *UpdateAction) RunGet(params struct {
this.Data["clusterId"] = user.NodeCluster.Id
}
// 检查用户是否开通了 HTTPDNS 功能
var hasHTTPDNSFeature = false
userFeaturesResp, err := this.RPC().UserRPC().FindUserFeatures(this.AdminContext(), &pb.FindUserFeaturesRequest{UserId: params.UserId})
if err != nil {
this.ErrorPage(err)
return
}
for _, f := range userFeaturesResp.Features {
if f.Code == "httpdns" {
hasHTTPDNSFeature = true
break
}
}
this.Data["hasHTTPDNSFeature"] = hasHTTPDNSFeature
// 读取用户已关联的 HTTPDNS 集群(取第一个作为下拉默认值)
var httpdnsClusterId int64
if len(user.HttpdnsClusterIdsJSON) > 0 {
var userHTTPDNSClusterIds []int64
if json.Unmarshal(user.HttpdnsClusterIdsJSON, &userHTTPDNSClusterIds) == nil && len(userHTTPDNSClusterIds) > 0 {
httpdnsClusterId = userHTTPDNSClusterIds[0]
}
}
this.Data["httpdnsClusterId"] = httpdnsClusterId
// 加载所有 HTTPDNS 集群
httpdnsClusterResp, err := this.RPC().HTTPDNSClusterRPC().FindAllHTTPDNSClusters(this.AdminContext(), &pb.FindAllHTTPDNSClustersRequest{})
if err != nil {
this.ErrorPage(err)
return
}
httpdnsClusters := make([]maps.Map, 0, len(httpdnsClusterResp.GetClusters()))
for _, c := range httpdnsClusterResp.GetClusters() {
httpdnsClusters = append(httpdnsClusters, maps.Map{
"id": c.GetId(),
"name": c.GetName(),
})
}
this.Data["httpdnsClusters"] = httpdnsClusters
this.Show()
}
@@ -99,8 +141,9 @@ func (this *UpdateAction) RunPost(params struct {
Email string
Remark string
IsOn bool
ClusterId int64
BandwidthAlgo string
ClusterId int64
HttpdnsClusterId int64
BandwidthAlgo string
// OTP
OtpOn bool
@@ -151,18 +194,25 @@ func (this *UpdateAction) RunPost(params struct {
Email("请输入正确的电子邮箱")
}
var httpdnsClusterIds []int64
if params.HttpdnsClusterId > 0 {
httpdnsClusterIds = []int64{params.HttpdnsClusterId}
}
httpdnsClusterIdsJSON, _ := json.Marshal(httpdnsClusterIds)
_, err = this.RPC().UserRPC().UpdateUser(this.AdminContext(), &pb.UpdateUserRequest{
UserId: params.UserId,
Username: params.Username,
Password: params.Pass1,
Fullname: params.Fullname,
Mobile: params.Mobile,
Tel: params.Tel,
Email: params.Email,
Remark: params.Remark,
IsOn: params.IsOn,
NodeClusterId: params.ClusterId,
BandwidthAlgo: params.BandwidthAlgo,
UserId: params.UserId,
Username: params.Username,
Password: params.Pass1,
Fullname: params.Fullname,
Mobile: params.Mobile,
Tel: params.Tel,
Email: params.Email,
Remark: params.Remark,
IsOn: params.IsOn,
NodeClusterId: params.ClusterId,
BandwidthAlgo: params.BandwidthAlgo,
HttpdnsClusterIdsJSON: httpdnsClusterIdsJSON,
})
if err != nil {
this.ErrorPage(err)

View File

@@ -6,6 +6,8 @@ import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/users/userutils"
"github.com/TeaOSLab/EdgeCommon/pkg/iplibrary"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
"github.com/iwind/TeaGo/maps"
)
@@ -89,6 +91,37 @@ func (this *UserAction) RunGet(params struct {
}
}
// 检查全局是否启用了 HTTPDNS 功能
var hasHTTPDNSFeature = false
sysResp, sysErr := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: systemconfigs.SettingCodeUserRegisterConfig})
if sysErr == nil && len(sysResp.ValueJSON) > 0 {
var config = userconfigs.DefaultUserRegisterConfig()
if json.Unmarshal(sysResp.ValueJSON, config) == nil {
hasHTTPDNSFeature = config.HTTPDNSIsOn
}
}
this.Data["hasHTTPDNSFeature"] = hasHTTPDNSFeature
// 读取用户关联的 HTTPDNS 集群
var httpdnsClusterMap maps.Map = nil
if hasHTTPDNSFeature && len(user.HttpdnsClusterIdsJSON) > 0 {
var httpdnsClusterIds []int64
if json.Unmarshal(user.HttpdnsClusterIdsJSON, &httpdnsClusterIds) == nil && len(httpdnsClusterIds) > 0 {
httpdnsClusterResp, httpdnsErr := this.RPC().HTTPDNSClusterRPC().FindAllHTTPDNSClusters(this.AdminContext(), &pb.FindAllHTTPDNSClustersRequest{})
if httpdnsErr == nil {
for _, c := range httpdnsClusterResp.GetClusters() {
if c.GetId() == httpdnsClusterIds[0] {
httpdnsClusterMap = maps.Map{
"id": c.GetId(),
"name": c.GetName(),
}
break
}
}
}
}
}
this.Data["user"] = maps.Map{
"id": user.Id,
"username": user.Username,
@@ -100,6 +133,7 @@ func (this *UserAction) RunGet(params struct {
"mobile": user.Mobile,
"isOn": user.IsOn,
"cluster": clusterMap,
"httpdnsCluster": httpdnsClusterMap,
"countAccessKeys": countAccessKeys,
"isRejected": user.IsRejected,
"rejectReason": user.RejectReason,