mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-30 23:16:35 +08:00
增加DNS服务商账号管理
This commit is contained in:
@@ -204,6 +204,10 @@ func (this *RPCClient) LogRPC() pb.LogServiceClient {
|
||||
return pb.NewLogServiceClient(this.pickConn())
|
||||
}
|
||||
|
||||
func (this *RPCClient) DNSProviderRPC() pb.DNSProviderServiceClient {
|
||||
return pb.NewDNSProviderServiceClient(this.pickConn())
|
||||
}
|
||||
|
||||
// 构造Admin上下文
|
||||
func (this *RPCClient) Context(adminId int64) context.Context {
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -17,6 +17,9 @@ func init() {
|
||||
Prefix("/dns/providers").
|
||||
Data("teaSubMenu", "provider").
|
||||
Get("", new(providers.IndexAction)).
|
||||
GetPost("/createPopup", new(providers.CreatePopupAction)).
|
||||
GetPost("/updatePopup", new(providers.UpdatePopupAction)).
|
||||
Post("/delete", new(providers.DeleteAction)).
|
||||
EndData().
|
||||
|
||||
EndAll()
|
||||
|
||||
84
internal/web/actions/default/dns/providers/createPopup.go
Normal file
84
internal/web/actions/default/dns/providers/createPopup.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package providers
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type CreatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct{}) {
|
||||
// 所有厂商
|
||||
typesResp, err := this.RPC().DNSProviderRPC().FindAllDNSProviderTypes(this.AdminContext(), &pb.FindAllDNSProviderTypesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
typeMaps := []maps.Map{}
|
||||
for _, t := range typesResp.ProviderTypes {
|
||||
typeMaps = append(typeMaps, maps.Map{
|
||||
"name": t.Name,
|
||||
"code": t.Code,
|
||||
})
|
||||
}
|
||||
this.Data["types"] = typeMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
Name string
|
||||
Type string
|
||||
|
||||
// dnspod
|
||||
ParamId string
|
||||
ParamToken string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入账号说明").
|
||||
Field("type", params.Type).
|
||||
Require("请选择服务商厂家")
|
||||
|
||||
apiParams := maps.Map{}
|
||||
switch params.Type {
|
||||
case "dnspod":
|
||||
params.Must.
|
||||
Field("paramId", params.ParamId).
|
||||
Require("请输入密钥ID").
|
||||
Field("paramToken", params.ParamToken).
|
||||
Require("请输入密钥Token")
|
||||
|
||||
apiParams["id"] = params.ParamId
|
||||
apiParams["token"] = params.ParamToken
|
||||
default:
|
||||
this.Fail("暂时不支持此服务商'" + params.Type + "'")
|
||||
}
|
||||
|
||||
createResp, err := this.RPC().DNSProviderRPC().CreateDNSProvider(this.AdminContext(), &pb.CreateDNSProviderRequest{
|
||||
Name: params.Name,
|
||||
Type: params.Type,
|
||||
ApiParamsJSON: apiParams.AsJSON(),
|
||||
RoutesJSON: nil,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.CreateLog(oplogs.LevelInfo, "创建DNS服务商 %d", createResp.DnsProviderId)
|
||||
|
||||
this.Success()
|
||||
}
|
||||
40
internal/web/actions/default/dns/providers/delete.go
Normal file
40
internal/web/actions/default/dns/providers/delete.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package providers
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type DeleteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteAction) RunPost(params struct {
|
||||
ProviderId int64
|
||||
}) {
|
||||
// TODO 检查权限
|
||||
|
||||
// 记录日志
|
||||
this.CreateLog(oplogs.LevelInfo, "删除DNS服务商 %d", params.ProviderId)
|
||||
|
||||
// 检查是否被使用
|
||||
countClustersResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClustersWithDNSProviderId(this.AdminContext(), &pb.CountAllEnabledNodeClustersWithDNSProviderIdRequest{DnsProviderId: params.ProviderId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if countClustersResp.Count > 0 {
|
||||
this.Fail("当前DNS服务商账号正在被" + numberutils.FormatInt64(countClustersResp.Count) + "个集群所使用,所以不能删除。请修改后再操作。")
|
||||
}
|
||||
|
||||
// 执行删除
|
||||
_, err = this.RPC().DNSProviderRPC().DeleteDNSProvider(this.AdminContext(), &pb.DeleteDNSProviderRequest{DnsProviderId: params.ProviderId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -1,6 +1,11 @@
|
||||
package providers
|
||||
|
||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
@@ -11,5 +16,39 @@ func (this *IndexAction) Init() {
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
countResp, err := this.RPC().DNSProviderRPC().CountAllEnabledDNSProviders(this.AdminContext(), &pb.CountAllEnabledDNSProvidersRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
count := countResp.Count
|
||||
page := this.NewPage(count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
providersResp, err := this.RPC().DNSProviderRPC().ListEnabledDNSProviders(this.AdminContext(), &pb.ListEnabledDNSProvidersRequest{
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
providerMaps := []maps.Map{}
|
||||
for _, provider := range providersResp.DnsProviders {
|
||||
dataUpdatedTime := ""
|
||||
if provider.DataUpdatedAt > 0 {
|
||||
dataUpdatedTime = timeutil.FormatTime("Y-m-d H:i:s", provider.DataUpdatedAt)
|
||||
}
|
||||
|
||||
providerMaps = append(providerMaps, maps.Map{
|
||||
"id": provider.Id,
|
||||
"name": provider.Name,
|
||||
"type": provider.Type,
|
||||
"typeName": provider.TypeName,
|
||||
"dataUpdatedTime": dataUpdatedTime,
|
||||
})
|
||||
}
|
||||
this.Data["providers"] = providerMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
118
internal/web/actions/default/dns/providers/updatePopup.go
Normal file
118
internal/web/actions/default/dns/providers/updatePopup.go
Normal file
@@ -0,0 +1,118 @@
|
||||
package providers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type UpdatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunGet(params struct {
|
||||
ProviderId int64
|
||||
}) {
|
||||
providerResp, err := this.RPC().DNSProviderRPC().FindEnabledDNSProvider(this.AdminContext(), &pb.FindEnabledDNSProviderRequest{DnsProviderId: params.ProviderId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
provider := providerResp.DnsProvider
|
||||
if provider == nil {
|
||||
this.NotFound("dnsProvider", params.ProviderId)
|
||||
return
|
||||
}
|
||||
|
||||
apiParams := maps.Map{}
|
||||
if len(provider.ApiParamsJSON) > 0 {
|
||||
err = json.Unmarshal(provider.ApiParamsJSON, &apiParams)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.Data["provider"] = maps.Map{
|
||||
"id": provider.Id,
|
||||
"name": provider.Name,
|
||||
"type": provider.Type,
|
||||
"typeName": provider.TypeName,
|
||||
"params": apiParams,
|
||||
}
|
||||
|
||||
// 所有厂商
|
||||
typesResp, err := this.RPC().DNSProviderRPC().FindAllDNSProviderTypes(this.AdminContext(), &pb.FindAllDNSProviderTypesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
typeMaps := []maps.Map{}
|
||||
for _, t := range typesResp.ProviderTypes {
|
||||
typeMaps = append(typeMaps, maps.Map{
|
||||
"name": t.Name,
|
||||
"code": t.Code,
|
||||
})
|
||||
}
|
||||
this.Data["types"] = typeMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunPost(params struct {
|
||||
ProviderId int64
|
||||
|
||||
Name string
|
||||
Type string
|
||||
|
||||
// dnspod
|
||||
ParamId string
|
||||
ParamToken string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
this.CreateLog(oplogs.LevelInfo, "修改DNS服务商 %d", params.ProviderId)
|
||||
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入账号说明").
|
||||
Field("type", params.Type).
|
||||
Require("请选择服务商厂家")
|
||||
|
||||
apiParams := maps.Map{}
|
||||
switch params.Type {
|
||||
case "dnspod":
|
||||
params.Must.
|
||||
Field("paramId", params.ParamId).
|
||||
Require("请输入密钥ID").
|
||||
Field("paramToken", params.ParamToken).
|
||||
Require("请输入密钥Token")
|
||||
|
||||
apiParams["id"] = params.ParamId
|
||||
apiParams["token"] = params.ParamToken
|
||||
default:
|
||||
this.Fail("暂时不支持此服务商'" + params.Type + "'")
|
||||
}
|
||||
|
||||
_, err := this.RPC().DNSProviderRPC().UpdateDNSProvider(this.AdminContext(), &pb.UpdateDNSProviderRequest{
|
||||
DnsProviderId: params.ProviderId,
|
||||
Name: params.Name,
|
||||
ApiParamsJSON: apiParams.AsJSON(),
|
||||
RoutesJSON: nil,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package settings
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
@@ -101,6 +102,9 @@ func (this *IndexAction) RunPost(params struct {
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
// 记录日志
|
||||
this.CreateLog(oplogs.LevelInfo, "修改代理服务 %d 基本信息", params.ServerId)
|
||||
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入服务名称")
|
||||
|
||||
@@ -2,6 +2,7 @@ package serverNames
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/serverutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
@@ -36,6 +37,9 @@ func (this *IndexAction) RunGet(params struct {
|
||||
}
|
||||
this.Data["serverNames"] = serverNamesConfig
|
||||
|
||||
// DNS
|
||||
this.Data["dnsName"] = server.DnsName
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
@@ -44,6 +48,9 @@ func (this *IndexAction) RunPost(params struct {
|
||||
ServerNames string
|
||||
Must *actions.Must
|
||||
}) {
|
||||
// 记录日志
|
||||
this.CreateLog(oplogs.LevelInfo, "修改代理服务 %d 域名", params.ServerId)
|
||||
|
||||
serverNames := []*serverconfigs.ServerNameConfig{}
|
||||
err := json.Unmarshal([]byte(params.ServerNames), &serverNames)
|
||||
if err != nil {
|
||||
|
||||
@@ -110,7 +110,7 @@ func (this *UserMustAuth) BeforeAction(actionPtr actions.ActionWrapper, paramNam
|
||||
"icon": "globe",
|
||||
"subItems": []maps.Map{
|
||||
{
|
||||
"name": "第三方DNS",
|
||||
"name": "DNS服务商",
|
||||
"url": "/dns/providers",
|
||||
"code": "provider",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user