2020-11-12 14:41:34 +08:00
|
|
|
package providers
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"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 ProviderAction struct {
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *ProviderAction) Init() {
|
|
|
|
|
this.Nav("", "", "")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *ProviderAction) 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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-02 18:14:00 +08:00
|
|
|
// 本地EdgeDNS相关
|
2022-08-05 14:38:56 +08:00
|
|
|
localEdgeDNSMap, err := this.readEdgeDNS(provider, apiParams)
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
2021-06-02 18:14:00 +08:00
|
|
|
}
|
|
|
|
|
|
2020-11-12 14:41:34 +08:00
|
|
|
this.Data["provider"] = maps.Map{
|
2021-06-02 18:14:00 +08:00
|
|
|
"id": provider.Id,
|
|
|
|
|
"name": provider.Name,
|
|
|
|
|
"type": provider.Type,
|
|
|
|
|
"typeName": provider.TypeName,
|
|
|
|
|
"apiParams": apiParams,
|
|
|
|
|
"localEdgeDNS": localEdgeDNSMap,
|
2020-11-12 14:41:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 域名
|
|
|
|
|
domainsResp, err := this.RPC().DNSDomainRPC().FindAllEnabledDNSDomainsWithDNSProviderId(this.AdminContext(), &pb.FindAllEnabledDNSDomainsWithDNSProviderIdRequest{DnsProviderId: provider.Id})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
domainMaps := []maps.Map{}
|
|
|
|
|
for _, domain := range domainsResp.DnsDomains {
|
|
|
|
|
dataUpdatedTime := ""
|
|
|
|
|
if domain.DataUpdatedAt > 0 {
|
|
|
|
|
dataUpdatedTime = timeutil.FormatTime("Y-m-d H:i:s", domain.DataUpdatedAt)
|
|
|
|
|
}
|
|
|
|
|
domainMaps = append(domainMaps, maps.Map{
|
2020-11-14 21:28:14 +08:00
|
|
|
"id": domain.Id,
|
|
|
|
|
"name": domain.Name,
|
|
|
|
|
"isOn": domain.IsOn,
|
2021-08-19 14:26:25 +08:00
|
|
|
"isUp": domain.IsUp,
|
2021-11-06 16:23:38 +08:00
|
|
|
"isDeleted": domain.IsDeleted,
|
2020-11-14 21:28:14 +08:00
|
|
|
"dataUpdatedTime": dataUpdatedTime,
|
|
|
|
|
"countRoutes": len(domain.Routes),
|
|
|
|
|
"countServerRecords": domain.CountServerRecords,
|
|
|
|
|
"serversChanged": domain.ServersChanged,
|
|
|
|
|
"countNodeRecords": domain.CountNodeRecords,
|
|
|
|
|
"nodesChanged": domain.NodesChanged,
|
2020-12-23 16:49:53 +08:00
|
|
|
"countClusters": domain.CountNodeClusters,
|
|
|
|
|
"countAllNodes": domain.CountAllNodes,
|
|
|
|
|
"countAllServers": domain.CountAllServers,
|
2020-11-12 14:41:34 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
this.Data["domains"] = domainMaps
|
|
|
|
|
|
|
|
|
|
this.Show()
|
|
|
|
|
}
|