mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-28 13:36:37 +08:00
实现对ACME用户的增删改
This commit is contained in:
15
internal/web/actions/default/servers/certs/acme/create.go
Normal file
15
internal/web/actions/default/servers/certs/acme/create.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package acme
|
||||
|
||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
|
||||
type CreateAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreateAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *CreateAction) RunGet(params struct{}) {
|
||||
this.Show()
|
||||
}
|
||||
15
internal/web/actions/default/servers/certs/acme/index.go
Normal file
15
internal/web/actions/default/servers/certs/acme/index.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package acme
|
||||
|
||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "cert")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package users
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
type CreatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct{}) {
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
Email string
|
||||
Description string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
params.Must.
|
||||
Field("email", params.Email).
|
||||
Require("请输入邮箱").
|
||||
Email("请输入正确的邮箱格式")
|
||||
|
||||
createResp, err := this.RPC().ACMEUserRPC().CreateACMEUser(this.AdminContext(), &pb.CreateACMEUserRequest{
|
||||
Email: params.Email,
|
||||
Description: params.Description,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 日志
|
||||
defer this.CreateLogInfo("创建ACME用户 %d", createResp.AcmeUserId)
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package users
|
||||
|
||||
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 {
|
||||
UserId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo("删除ACME用户 %d", params.UserId)
|
||||
|
||||
countResp, err := this.RPC().SSLCertRPC().CountSSLCertsWithACMEUserId(this.AdminContext(), &pb.CountSSLCertsWithACMEUserIdRequest{AcmeUserId: params.UserId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if countResp.Count > 0 {
|
||||
this.Fail("有证书正在和这个用户关联,所以不能删除")
|
||||
}
|
||||
|
||||
_, err = this.RPC().ACMEUserRPC().DeleteACMEUser(this.AdminContext(), &pb.DeleteACMEUserRequest{AcmeUserId: params.UserId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package users
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "user")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
countResp, err := this.RPC().ACMEUserRPC().CountACMEUsers(this.AdminContext(), &pb.CountAcmeUsersRequest{
|
||||
AdminId: this.AdminId(),
|
||||
UserId: 0,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
count := countResp.Count
|
||||
page := this.NewPage(count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
usersResp, err := this.RPC().ACMEUserRPC().ListACMEUsers(this.AdminContext(), &pb.ListACMEUsersRequest{
|
||||
AdminId: this.AdminId(),
|
||||
UserId: 0,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
userMaps := []maps.Map{}
|
||||
for _, user := range usersResp.AcmeUsers {
|
||||
userMaps = append(userMaps, maps.Map{
|
||||
"id": user.Id,
|
||||
"email": user.Email,
|
||||
"description": user.Description,
|
||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", user.CreatedAt),
|
||||
})
|
||||
}
|
||||
this.Data["users"] = userMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package users
|
||||
|
||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
|
||||
type SelectPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *SelectPopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *SelectPopupAction) RunGet(params struct{}) {
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package users
|
||||
|
||||
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 {
|
||||
UserId int64
|
||||
}) {
|
||||
userResp, err := this.RPC().ACMEUserRPC().FindEnabledACMEUser(this.AdminContext(), &pb.FindEnabledACMEUserRequest{AcmeUserId: params.UserId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
user := userResp.AcmeUser
|
||||
if user == nil {
|
||||
this.NotFound("acmeUser", params.UserId)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["user"] = maps.Map{
|
||||
"id": user.Id,
|
||||
"email": user.Email,
|
||||
"description": user.Description,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunPost(params struct {
|
||||
UserId int64
|
||||
Description string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo("修改ACME用户 %d", params.UserId)
|
||||
|
||||
_, err := this.RPC().ACMEUserRPC().UpdateACMEUser(this.AdminContext(), &pb.UpdateACMEUserRequest{
|
||||
AcmeUserId: params.UserId,
|
||||
Description: params.Description,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package ssl
|
||||
package certs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -1,4 +1,4 @@
|
||||
package ssl
|
||||
package certs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -1,4 +1,4 @@
|
||||
package ssl
|
||||
package certs
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
||||
@@ -1,4 +1,4 @@
|
||||
package ssl
|
||||
package certs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -1,4 +1,4 @@
|
||||
package ssl
|
||||
package certs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -1,4 +1,4 @@
|
||||
package ssl
|
||||
package certs
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
35
internal/web/actions/default/servers/certs/helper.go
Normal file
35
internal/web/actions/default/servers/certs/helper.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package certs
|
||||
|
||||
import (
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Helper struct {
|
||||
}
|
||||
|
||||
func NewHelper() *Helper {
|
||||
return &Helper{}
|
||||
}
|
||||
|
||||
func (this *Helper) BeforeAction(action *actions.ActionObject) {
|
||||
if action.Request.Method != http.MethodGet {
|
||||
return
|
||||
}
|
||||
|
||||
action.Data["teaMenu"] = "servers"
|
||||
|
||||
action.Data["leftMenuItems"] = []maps.Map{
|
||||
{
|
||||
"name": "证书",
|
||||
"url": "/servers/certs",
|
||||
"isActive": action.Data.GetString("leftMenuItem") == "cert",
|
||||
},
|
||||
{
|
||||
"name": "免费证书",
|
||||
"url": "/servers/certs/acme",
|
||||
"isActive": action.Data.GetString("leftMenuItem") == "acme",
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package ssl
|
||||
package certs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -1,7 +1,8 @@
|
||||
package ssl
|
||||
package certs
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/componentutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/certs/acme"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/certs/acme/users"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
@@ -11,8 +12,11 @@ func init() {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth()).
|
||||
Helper(NewHelper()).
|
||||
Helper(componentutils.NewComponentHelper()).
|
||||
Prefix("/servers/components/ssl").
|
||||
|
||||
Data("teaSubMenu", "cert").
|
||||
|
||||
Prefix("/servers/certs").
|
||||
Data("leftMenuItem", "cert").
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/uploadPopup", new(UploadPopupAction)).
|
||||
Post("/delete", new(DeleteAction)).
|
||||
@@ -25,6 +29,20 @@ func init() {
|
||||
Get("/downloadZip", new(DownloadZipAction)).
|
||||
Get("/selectPopup", new(SelectPopupAction)).
|
||||
Get("/datajs", new(DatajsAction)).
|
||||
|
||||
// ACME
|
||||
Prefix("/servers/certs/acme").
|
||||
Data("leftMenuItem", "acme").
|
||||
Get("", new(acme.IndexAction)).
|
||||
GetPost("/create", new(acme.CreateAction)).
|
||||
|
||||
Prefix("/servers/certs/acme/users").
|
||||
Get("", new(users.IndexAction)).
|
||||
GetPost("/createPopup", new(users.CreatePopupAction)).
|
||||
GetPost("/updatePopup", new(users.UpdatePopupAction)).
|
||||
Post("/delete", new(users.DeleteAction)).
|
||||
GetPost("/selectPopup", new(users.SelectPopupAction)).
|
||||
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package ssl
|
||||
package certs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -1,4 +1,4 @@
|
||||
package ssl
|
||||
package certs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -1,4 +1,4 @@
|
||||
package ssl
|
||||
package certs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -1,4 +1,4 @@
|
||||
package ssl
|
||||
package certs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -1,4 +1,4 @@
|
||||
package ssl
|
||||
package certs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -52,11 +52,6 @@ func (this *ComponentHelper) createLeftMenus(secondMenuItem string) (items []map
|
||||
"url": "/servers/components/log",
|
||||
"isActive": secondMenuItem == "log",
|
||||
})
|
||||
items = append(items, maps.Map{
|
||||
"name": "SSL证书管理",
|
||||
"url": "/servers/components/ssl",
|
||||
"isActive": secondMenuItem == "ssl",
|
||||
})
|
||||
items = append(items, maps.Map{
|
||||
"name": "IP库",
|
||||
"url": "/servers/components/ip-library",
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package ssl
|
||||
|
||||
import (
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Helper struct {
|
||||
}
|
||||
|
||||
func NewHelper() *Helper {
|
||||
return &Helper{}
|
||||
}
|
||||
|
||||
func (this *Helper) BeforeAction(action *actions.ActionObject) {
|
||||
if action.Request.Method != http.MethodGet {
|
||||
return
|
||||
}
|
||||
|
||||
action.Data["mainTab"] = "component"
|
||||
action.Data["secondMenuItem"] = "ssl"
|
||||
}
|
||||
Reference in New Issue
Block a user