2024-05-17 17:56:37 +08:00
|
|
|
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved.
|
2022-04-19 16:33:51 +08:00
|
|
|
|
|
|
|
|
//go:build !plus
|
|
|
|
|
|
2020-11-11 21:32:19 +08:00
|
|
|
package providers
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
2023-06-30 18:08:30 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
2020-11-11 21:32:19 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
|
|
|
"github.com/iwind/TeaGo/actions"
|
|
|
|
|
"github.com/iwind/TeaGo/maps"
|
2021-01-28 11:29:50 +08:00
|
|
|
"github.com/iwind/TeaGo/rands"
|
2020-11-11 21:32:19 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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{
|
2021-06-02 18:14:00 +08:00
|
|
|
"name": t.Name,
|
|
|
|
|
"code": t.Code,
|
|
|
|
|
"description": t.Description,
|
2020-11-11 21:32:19 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
this.Data["types"] = typeMaps
|
|
|
|
|
|
2021-01-28 11:29:50 +08:00
|
|
|
// 自动生成CustomHTTP私钥
|
|
|
|
|
this.Data["paramCustomHTTPSecret"] = rands.HexString(32)
|
|
|
|
|
|
2021-06-02 18:14:00 +08:00
|
|
|
// EdgeDNS集群列表
|
2022-08-05 14:38:56 +08:00
|
|
|
this.Data["nsClusters"] = []maps.Map{}
|
2021-06-02 18:14:00 +08:00
|
|
|
|
2020-11-11 21:32:19 +08:00
|
|
|
this.Show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *CreatePopupAction) RunPost(params struct {
|
|
|
|
|
Name string
|
|
|
|
|
Type string
|
|
|
|
|
|
2020-11-15 11:57:43 +08:00
|
|
|
// DNSPod
|
2023-11-23 15:14:34 +08:00
|
|
|
ParamDNSPodId string
|
|
|
|
|
ParamDNSPodToken string
|
|
|
|
|
ParamDNSPodRegion string
|
|
|
|
|
|
|
|
|
|
ParamDNSPodAPIType string
|
|
|
|
|
ParamDNSPodAccessKeyId string
|
|
|
|
|
ParamDNSPodAccessKeySecret string
|
2020-11-11 21:32:19 +08:00
|
|
|
|
2020-11-15 11:57:43 +08:00
|
|
|
// AliDNS
|
2022-05-07 20:59:38 +08:00
|
|
|
ParamAliDNSAccessKeyId string
|
|
|
|
|
ParamAliDNSAccessKeySecret string
|
|
|
|
|
ParamAliDNSRegionId string
|
2020-11-15 11:57:43 +08:00
|
|
|
|
2021-08-04 22:14:35 +08:00
|
|
|
// HuaweiDNS
|
|
|
|
|
ParamHuaweiAccessKeyId string
|
|
|
|
|
ParamHuaweiAccessKeySecret string
|
2023-01-01 18:28:37 +08:00
|
|
|
ParamHuaweiEndpoint string
|
2021-08-04 22:14:35 +08:00
|
|
|
|
2021-04-15 17:02:35 +08:00
|
|
|
// CloudFlare
|
2022-04-19 16:33:51 +08:00
|
|
|
ParamCloudFlareAPIKey string
|
|
|
|
|
ParamCloudFlareEmail string
|
2021-04-15 17:02:35 +08:00
|
|
|
|
2021-01-28 11:29:50 +08:00
|
|
|
// CustomHTTP
|
|
|
|
|
ParamCustomHTTPURL string
|
|
|
|
|
ParamCustomHTTPSecret string
|
|
|
|
|
|
2022-09-08 19:36:37 +08:00
|
|
|
// EdgeDNS API
|
|
|
|
|
ParamEdgeDNSAPIRole string
|
|
|
|
|
ParamEdgeDNSAPIHost string
|
|
|
|
|
ParamEdgeDNSAPIAccessKeyId string
|
|
|
|
|
ParamEdgeDNSAPIAccessKeySecret string
|
|
|
|
|
|
2024-05-12 09:33:30 +08:00
|
|
|
MinTTL int32
|
|
|
|
|
|
2020-11-11 21:32:19 +08:00
|
|
|
Must *actions.Must
|
|
|
|
|
CSRF *actionutils.CSRF
|
|
|
|
|
}) {
|
|
|
|
|
params.Must.
|
|
|
|
|
Field("name", params.Name).
|
|
|
|
|
Require("请输入账号说明").
|
|
|
|
|
Field("type", params.Type).
|
|
|
|
|
Require("请选择服务商厂家")
|
|
|
|
|
|
2023-11-23 15:14:34 +08:00
|
|
|
var apiParams = maps.Map{}
|
2020-11-11 21:32:19 +08:00
|
|
|
switch params.Type {
|
|
|
|
|
case "dnspod":
|
2023-11-23 15:14:34 +08:00
|
|
|
apiParams["apiType"] = params.ParamDNSPodAPIType
|
|
|
|
|
switch params.ParamDNSPodAPIType {
|
|
|
|
|
case "tencentDNS":
|
|
|
|
|
params.Must.
|
|
|
|
|
Field("paramDNSPodAccessKeyId", params.ParamDNSPodAccessKeyId).
|
|
|
|
|
Require("请输入SecretId").
|
|
|
|
|
Field("paramDNSPodAccessKeySecret", params.ParamDNSPodAccessKeySecret).
|
|
|
|
|
Require("请输入SecretKey")
|
|
|
|
|
apiParams["accessKeyId"] = params.ParamDNSPodAccessKeyId
|
|
|
|
|
apiParams["accessKeySecret"] = params.ParamDNSPodAccessKeySecret
|
|
|
|
|
apiParams["region"] = params.ParamDNSPodRegion
|
|
|
|
|
default:
|
|
|
|
|
params.Must.
|
|
|
|
|
Field("paramId", params.ParamDNSPodId).
|
|
|
|
|
Require("请输入密钥ID").
|
|
|
|
|
Field("paramToken", params.ParamDNSPodToken).
|
|
|
|
|
Require("请输入密钥Token")
|
|
|
|
|
|
|
|
|
|
apiParams["id"] = params.ParamDNSPodId
|
|
|
|
|
apiParams["token"] = params.ParamDNSPodToken
|
|
|
|
|
apiParams["region"] = params.ParamDNSPodRegion
|
|
|
|
|
}
|
2020-11-15 11:57:43 +08:00
|
|
|
case "alidns":
|
|
|
|
|
params.Must.
|
2022-05-07 20:59:38 +08:00
|
|
|
Field("paramAliDNSAccessKeyId", params.ParamAliDNSAccessKeyId).
|
2020-11-15 11:57:43 +08:00
|
|
|
Require("请输入AccessKeyId").
|
2022-05-07 20:59:38 +08:00
|
|
|
Field("paramAliDNSAccessKeySecret", params.ParamAliDNSAccessKeySecret).
|
2020-11-15 11:57:43 +08:00
|
|
|
Require("请输入AccessKeySecret")
|
|
|
|
|
|
2022-05-07 20:59:38 +08:00
|
|
|
apiParams["accessKeyId"] = params.ParamAliDNSAccessKeyId
|
|
|
|
|
apiParams["accessKeySecret"] = params.ParamAliDNSAccessKeySecret
|
|
|
|
|
apiParams["regionId"] = params.ParamAliDNSRegionId
|
2021-08-04 22:14:35 +08:00
|
|
|
case "huaweiDNS":
|
|
|
|
|
params.Must.
|
|
|
|
|
Field("paramHuaweiAccessKeyId", params.ParamHuaweiAccessKeyId).
|
|
|
|
|
Require("请输入AccessKeyId").
|
|
|
|
|
Field("paramHuaweiAccessKeySecret", params.ParamHuaweiAccessKeySecret).
|
|
|
|
|
Require("请输入AccessKeySecret")
|
|
|
|
|
|
|
|
|
|
apiParams["accessKeyId"] = params.ParamHuaweiAccessKeyId
|
|
|
|
|
apiParams["accessKeySecret"] = params.ParamHuaweiAccessKeySecret
|
2023-01-01 18:28:37 +08:00
|
|
|
apiParams["endpoint"] = params.ParamHuaweiEndpoint
|
2021-04-15 17:02:35 +08:00
|
|
|
case "cloudFlare":
|
|
|
|
|
params.Must.
|
2022-04-19 16:33:51 +08:00
|
|
|
Field("paramCloudFlareAPIKey", params.ParamCloudFlareAPIKey).
|
2021-04-15 17:02:35 +08:00
|
|
|
Require("请输入API密钥").
|
2022-04-19 16:33:51 +08:00
|
|
|
Field("paramCloudFlareEmail", params.ParamCloudFlareEmail).
|
2021-04-15 17:02:35 +08:00
|
|
|
Email("请输入正确格式的邮箱地址")
|
2022-04-19 16:33:51 +08:00
|
|
|
apiParams["apiKey"] = params.ParamCloudFlareAPIKey
|
|
|
|
|
apiParams["email"] = params.ParamCloudFlareEmail
|
2022-09-08 19:36:37 +08:00
|
|
|
case "edgeDNSAPI":
|
|
|
|
|
params.Must.
|
|
|
|
|
Field("paramEdgeDNSAPIHost", params.ParamEdgeDNSAPIHost).
|
|
|
|
|
Require("请输入API地址").
|
|
|
|
|
Field("paramEdgeDNSAPIRole", params.ParamEdgeDNSAPIRole).
|
|
|
|
|
Require("请选择AccessKey类型").
|
|
|
|
|
Field("paramEdgeDNSAPIAccessKeyId", params.ParamEdgeDNSAPIAccessKeyId).
|
|
|
|
|
Require("请输入AccessKey ID").
|
|
|
|
|
Field("paramEdgeDNSAPIAccessKeySecret", params.ParamEdgeDNSAPIAccessKeySecret).
|
|
|
|
|
Require("请输入AccessKey密钥")
|
|
|
|
|
apiParams["host"] = params.ParamEdgeDNSAPIHost
|
|
|
|
|
apiParams["role"] = params.ParamEdgeDNSAPIRole
|
|
|
|
|
apiParams["accessKeyId"] = params.ParamEdgeDNSAPIAccessKeyId
|
|
|
|
|
apiParams["accessKeySecret"] = params.ParamEdgeDNSAPIAccessKeySecret
|
2021-01-28 11:29:50 +08:00
|
|
|
case "customHTTP":
|
|
|
|
|
params.Must.
|
|
|
|
|
Field("paramCustomHTTPURL", params.ParamCustomHTTPURL).
|
|
|
|
|
Require("请输入HTTP URL").
|
|
|
|
|
Match("^(?i)(http|https):", "URL必须以http://或者https://开头").
|
|
|
|
|
Field("paramCustomHTTPSecret", params.ParamCustomHTTPSecret).
|
|
|
|
|
Require("请输入私钥")
|
|
|
|
|
apiParams["url"] = params.ParamCustomHTTPURL
|
|
|
|
|
apiParams["secret"] = params.ParamCustomHTTPSecret
|
2020-11-11 21:32:19 +08:00
|
|
|
default:
|
|
|
|
|
this.Fail("暂时不支持此服务商'" + params.Type + "'")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createResp, err := this.RPC().DNSProviderRPC().CreateDNSProvider(this.AdminContext(), &pb.CreateDNSProviderRequest{
|
|
|
|
|
Name: params.Name,
|
|
|
|
|
Type: params.Type,
|
|
|
|
|
ApiParamsJSON: apiParams.AsJSON(),
|
2024-05-12 09:33:30 +08:00
|
|
|
MinTTL: params.MinTTL,
|
2020-11-11 21:32:19 +08:00
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 18:08:30 +08:00
|
|
|
defer this.CreateLogInfo(codes.DNSProvider_LogCreateDNSProvider, createResp.DnsProviderId)
|
2020-11-11 21:32:19 +08:00
|
|
|
|
|
|
|
|
this.Success()
|
|
|
|
|
}
|