Initial commit (code only without large binaries)
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type ClusterHostsAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ClusterHostsAction) RunPost(params struct {
|
||||
ClusterId int64
|
||||
}) {
|
||||
hostsResp, err := this.RPC().NSClusterRPC().FindNSClusterHosts(this.AdminContext(), &pb.FindNSClusterHostsRequest{
|
||||
NsClusterId: params.ClusterId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var hosts = hostsResp.Hosts
|
||||
if hosts == nil {
|
||||
hosts = []string{}
|
||||
}
|
||||
this.Data["hosts"] = hosts
|
||||
|
||||
this.Success()
|
||||
}
|
||||
170
EdgeAdmin/internal/web/actions/default/ns/settings/user/index.go
Normal file
170
EdgeAdmin/internal/web/actions/default/ns/settings/user/index.go
Normal file
@@ -0,0 +1,170 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
this.SecondMenu("user")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
resp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{
|
||||
Code: systemconfigs.SettingCodeNSUserConfig,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var config = dnsconfigs.NewNSUserConfig()
|
||||
if len(resp.ValueJSON) > 0 {
|
||||
err = json.Unmarshal(resp.ValueJSON, config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
if config.DefaultPlanConfig == nil {
|
||||
config.DefaultPlanConfig = dnsconfigs.DefaultNSUserPlanConfig()
|
||||
}
|
||||
}
|
||||
if config.DomainValidation == nil {
|
||||
config.DomainValidation = dnsconfigs.NewNSDomainValidationConfig()
|
||||
}
|
||||
|
||||
// 当前集群主机地址
|
||||
var clusterHosts = []string{}
|
||||
if config.DefaultClusterId > 0 {
|
||||
hostsResp, err := this.RPC().NSClusterRPC().FindNSClusterHosts(this.AdminContext(), &pb.FindNSClusterHostsRequest{
|
||||
NsClusterId: config.DefaultClusterId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if len(hostsResp.Hosts) > 0 {
|
||||
clusterHosts = hostsResp.Hosts
|
||||
}
|
||||
}
|
||||
this.Data["clusterHosts"] = clusterHosts
|
||||
|
||||
this.Data["config"] = config
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunPost(params struct {
|
||||
DefaultClusterId int64
|
||||
|
||||
DomainValidationIsOn bool
|
||||
DomainValidationResolversJSON []byte
|
||||
|
||||
SupportCountryRoutes bool
|
||||
SupportChinaProvinceRoutes bool
|
||||
SupportISPRoutes bool
|
||||
SupportAgentRoutes bool
|
||||
SupportPublicRoutes bool
|
||||
|
||||
SupportHealthCheck bool
|
||||
|
||||
MinTTL int32
|
||||
MaxDomains int32
|
||||
MaxRecordsPerDomain int32
|
||||
MaxLoadBalanceRecordsPerRecord int32
|
||||
MaxCustomRoutes int32
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.NS_LogUpdateNSUserConfig)
|
||||
|
||||
if params.DefaultClusterId <= 0 {
|
||||
this.Fail("选择默认部署集群")
|
||||
}
|
||||
|
||||
resp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{
|
||||
Code: systemconfigs.SettingCodeNSUserConfig,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var config = dnsconfigs.NewNSUserConfig()
|
||||
if len(resp.ValueJSON) > 0 {
|
||||
err = json.Unmarshal(resp.ValueJSON, config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 默认集群
|
||||
config.DefaultClusterId = params.DefaultClusterId
|
||||
|
||||
// 域名验证
|
||||
if config.DomainValidation == nil {
|
||||
config.DomainValidation = dnsconfigs.NewNSDomainValidationConfig()
|
||||
}
|
||||
config.DomainValidation.IsOn = params.DomainValidationIsOn
|
||||
config.DomainValidation.Resolvers = []*dnsconfigs.DNSResolver{}
|
||||
err = json.Unmarshal(params.DomainValidationResolversJSON, &config.DomainValidation.Resolvers)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 基础功能
|
||||
var planConfig = dnsconfigs.DefaultNSPlanConfig()
|
||||
planConfig.SupportCountryRoutes = params.SupportCountryRoutes
|
||||
planConfig.SupportChinaProvinceRoutes = params.SupportChinaProvinceRoutes
|
||||
planConfig.SupportISPRoutes = params.SupportISPRoutes
|
||||
planConfig.SupportAgentRoutes = params.SupportAgentRoutes
|
||||
planConfig.SupportPublicRoutes = params.SupportPublicRoutes
|
||||
|
||||
planConfig.SupportHealthCheck = params.SupportHealthCheck
|
||||
|
||||
planConfig.MinTTL = params.MinTTL
|
||||
planConfig.MaxDomains = params.MaxDomains
|
||||
planConfig.MaxRecordsPerDomain = params.MaxRecordsPerDomain
|
||||
planConfig.MaxLoadBalanceRecordsPerRecord = params.MaxLoadBalanceRecordsPerRecord
|
||||
planConfig.MaxCustomRoutes = params.MaxCustomRoutes
|
||||
err = planConfig.Init()
|
||||
if err != nil {
|
||||
this.Fail("默认功能配置校验失败:" + err.Error())
|
||||
}
|
||||
config.DefaultPlanConfig = planConfig
|
||||
|
||||
// 保存
|
||||
configJSON, err := json.Marshal(config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
|
||||
Code: systemconfigs.SettingCodeNSUserConfig,
|
||||
ValueJSON: configJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build plus
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/plus"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/settings/settingutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(plus.NewHelper(plus.ComponentCodeNS)).
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNS)).
|
||||
Helper(new(settingutils.Helper)).
|
||||
Data("teaMenu", "ns").
|
||||
Data("teaSubMenu", "setting").
|
||||
Prefix("/ns/settings/user").
|
||||
GetPost("", new(IndexAction)).
|
||||
Post("/clusterHosts", new(ClusterHostsAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user