mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-04-24 13:55:18 +08:00
ACME证书增加ZeroSSL支持
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package accounts
|
||||
|
||||
import (
|
||||
"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 {
|
||||
ProviderCode string
|
||||
}) {
|
||||
this.Data["providerCode"] = params.ProviderCode
|
||||
|
||||
// 服务商列表
|
||||
providersResp, err := this.RPC().ACMEProviderRPC().FindAllACMEProviders(this.AdminContext(), &pb.FindAllACMEProvidersRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var providerMaps = []maps.Map{}
|
||||
for _, provider := range providersResp.AcmeProviders {
|
||||
providerMaps = append(providerMaps, maps.Map{
|
||||
"name": provider.Name,
|
||||
"code": provider.Code,
|
||||
"description": provider.Description,
|
||||
"requireEAB": provider.RequireEAB,
|
||||
"eabDescription": provider.EabDescription,
|
||||
})
|
||||
}
|
||||
|
||||
this.Data["providers"] = providerMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
Name string
|
||||
ProviderCode string
|
||||
EabKid string
|
||||
EabKey string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
var accountId int64
|
||||
defer func() {
|
||||
this.CreateLogInfo("创建ACME服务商账号 %d", accountId)
|
||||
}()
|
||||
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入账号名称").
|
||||
Field("providerCode", params.ProviderCode).
|
||||
Require("请选择服务商")
|
||||
|
||||
providerResp, err := this.RPC().ACMEProviderRPC().FindACMEProviderWithCode(this.AdminContext(), &pb.FindACMEProviderWithCodeRequest{AcmeProviderCode: params.ProviderCode})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var provider = providerResp.AcmeProvider
|
||||
if provider == nil {
|
||||
this.Fail("请选择服务商")
|
||||
}
|
||||
|
||||
if provider.RequireEAB {
|
||||
params.Must.
|
||||
Field("eabKid", params.EabKid).
|
||||
Require("请输入EAB Kid").
|
||||
Field("eabKey", params.EabKey).
|
||||
Require("请输入EAB HMAC Key")
|
||||
}
|
||||
|
||||
createResp, err := this.RPC().ACMEProviderAccountRPC().CreateACMEProviderAccount(this.AdminContext(), &pb.CreateACMEProviderAccountRequest{
|
||||
Name: params.Name,
|
||||
ProviderCode: params.ProviderCode,
|
||||
EabKid: params.EabKid,
|
||||
EabKey: params.EabKey,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
accountId = createResp.AcmeProviderAccountId
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package accounts
|
||||
|
||||
import (
|
||||
"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 {
|
||||
AccountId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo("删除ACME服务商账号 %d", params.AccountId)
|
||||
|
||||
_, err := this.RPC().ACMEProviderAccountRPC().DeleteACMEProviderAccount(this.AdminContext(), &pb.DeleteACMEProviderAccountRequest{AcmeProviderAccountId: params.AccountId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package accounts
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "account")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
countResp, err := this.RPC().ACMEProviderAccountRPC().CountAllEnabledACMEProviderAccounts(this.AdminContext(), &pb.CountAllEnabledACMEProviderAccountsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var count = countResp.Count
|
||||
var page = this.NewPage(count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
accountsResp, err := this.RPC().ACMEProviderAccountRPC().ListEnabledACMEProviderAccounts(this.AdminContext(), &pb.ListEnabledACMEProviderAccountsRequest{
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var accountMaps = []maps.Map{}
|
||||
for _, account := range accountsResp.AcmeProviderAccounts {
|
||||
var providerMap maps.Map
|
||||
if account.AcmeProvider != nil {
|
||||
providerMap = maps.Map{
|
||||
"name": account.AcmeProvider.Name,
|
||||
"code": account.AcmeProvider.Code,
|
||||
"requireEAB": account.AcmeProvider.RequireEAB,
|
||||
}
|
||||
}
|
||||
|
||||
accountMaps = append(accountMaps, maps.Map{
|
||||
"id": account.Id,
|
||||
"isOn": account.IsOn,
|
||||
"name": account.Name,
|
||||
"eabKid": account.EabKid,
|
||||
"eabKey": account.EabKey,
|
||||
"provider": providerMap,
|
||||
})
|
||||
}
|
||||
this.Data["accounts"] = accountMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package accounts
|
||||
|
||||
import (
|
||||
"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 {
|
||||
AccountId int64
|
||||
}) {
|
||||
// 账号信息
|
||||
accountResp, err := this.RPC().ACMEProviderAccountRPC().FindEnabledACMEProviderAccount(this.AdminContext(), &pb.FindEnabledACMEProviderAccountRequest{AcmeProviderAccountId: params.AccountId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var account = accountResp.AcmeProviderAccount
|
||||
if account == nil {
|
||||
this.NotFound("ACMEProviderAccount", params.AccountId)
|
||||
return
|
||||
}
|
||||
|
||||
var providerMap maps.Map
|
||||
if account.AcmeProvider != nil {
|
||||
providerMap = maps.Map{
|
||||
"name": account.AcmeProvider.Name,
|
||||
"code": account.AcmeProvider.Code,
|
||||
"description": account.AcmeProvider.Description,
|
||||
"eabDescription": account.AcmeProvider.EabDescription,
|
||||
"requireEAB": account.AcmeProvider.RequireEAB,
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["account"] = maps.Map{
|
||||
"id": account.Id,
|
||||
"name": account.Name,
|
||||
"isOn": account.IsOn,
|
||||
"providerCode": account.ProviderCode,
|
||||
"eabKid": account.EabKid,
|
||||
"eabKey": account.EabKey,
|
||||
"provider": providerMap,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunPost(params struct {
|
||||
AccountId int64
|
||||
Name string
|
||||
ProviderCode string
|
||||
EabKid string
|
||||
EabKey string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo("修改ACME服务商账号 %d", params.AccountId)
|
||||
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入账号名称").
|
||||
Field("providerCode", params.ProviderCode).
|
||||
Require("请选择服务商")
|
||||
|
||||
providerResp, err := this.RPC().ACMEProviderRPC().FindACMEProviderWithCode(this.AdminContext(), &pb.FindACMEProviderWithCodeRequest{AcmeProviderCode: params.ProviderCode})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var provider = providerResp.AcmeProvider
|
||||
if provider == nil {
|
||||
this.Fail("请选择服务商")
|
||||
}
|
||||
|
||||
if provider.RequireEAB {
|
||||
params.Must.
|
||||
Field("eabKid", params.EabKid).
|
||||
Require("请输入EAB Kid").
|
||||
Field("eabKey", params.EabKey).
|
||||
Require("请输入EAB HMAC Key")
|
||||
}
|
||||
|
||||
_, err = this.RPC().ACMEProviderAccountRPC().UpdateACMEProviderAccount(this.AdminContext(), &pb.UpdateACMEProviderAccountRequest{
|
||||
AcmeProviderAccountId: params.AccountId,
|
||||
Name: params.Name,
|
||||
EabKid: params.EabKid,
|
||||
EabKey: params.EabKey,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user