1.4.5.2
This commit is contained in:
103
EdgeAdmin/internal/web/actions/default/ns/domains/healthCheck.go
Normal file
103
EdgeAdmin/internal/web/actions/default/ns/domains/healthCheck.go
Normal file
@@ -0,0 +1,103 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package domains
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/domains/domainutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
type HealthCheckAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *HealthCheckAction) Init() {
|
||||
this.Nav("", "", "healthCheck")
|
||||
}
|
||||
|
||||
func (this *HealthCheckAction) RunGet(params struct {
|
||||
DomainId int64
|
||||
}) {
|
||||
err := domainutils.InitDomain(this.Parent(), params.DomainId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["domainId"] = params.DomainId
|
||||
|
||||
// 检查当前用户权限
|
||||
canUpdate, err := domainutils.CheckHealthCheckPermission(this.RPC(), this.AdminContext(), params.DomainId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["canUpdate"] = canUpdate
|
||||
|
||||
// 健康检查配置
|
||||
healthCheckResp, err := this.RPC().NSDomainRPC().FindNSDomainRecordsHealthCheck(this.AdminContext(), &pb.FindNSDomainRecordsHealthCheckRequest{NsDomainId: params.DomainId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var healthCheckConfig = dnsconfigs.NewNSRecordsHealthCheckConfig()
|
||||
if len(healthCheckResp.NsDomainRecordsHealthCheckJSON) > 0 {
|
||||
err = json.Unmarshal(healthCheckResp.NsDomainRecordsHealthCheckJSON, healthCheckConfig)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
this.Data["config"] = healthCheckConfig
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *HealthCheckAction) RunPost(params struct {
|
||||
DomainId int64
|
||||
RecordsHealthCheckJSON []byte
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.NSDomain_LogUpdateNSDomainHealthCheck, params.DomainId)
|
||||
|
||||
canUpdate, err := domainutils.CheckHealthCheckPermission(this.RPC(), this.AdminContext(), params.DomainId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if !canUpdate {
|
||||
this.Fail("当前用户没有权限修改健康检查设置")
|
||||
return
|
||||
}
|
||||
|
||||
var config = dnsconfigs.NewNSRecordsHealthCheckConfig()
|
||||
err = json.Unmarshal(params.RecordsHealthCheckJSON, config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
err = config.Init()
|
||||
if err != nil {
|
||||
this.Fail("校验配置失败:" + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
_, err = this.RPC().NSDomainRPC().UpdateNSDomainRecordsHealthCheck(this.AdminContext(), &pb.UpdateNSDomainRecordsHealthCheckRequest{
|
||||
NsDomainId: params.DomainId,
|
||||
NsDomainRecordsHealthCheckJSON: params.RecordsHealthCheckJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user