Files
EdgeAdmin/internal/web/actions/default/servers/iplists/createPopup.go

87 lines
2.0 KiB
Go
Raw Normal View History

2021-06-23 13:12:33 +08:00
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package iplists
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
2024-05-05 14:08:32 +08:00
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/iplists/iplistutils"
2023-06-30 18:08:30 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
2021-06-23 13:12:33 +08:00
"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 {
Type string
}) {
this.Data["type"] = params.Type
this.Show()
}
func (this *CreatePopupAction) RunPost(params struct {
Name string
2024-05-05 14:08:32 +08:00
Code string
2021-06-23 13:12:33 +08:00
Type string
Description string
IsGlobal bool
2021-06-23 13:12:33 +08:00
Must *actions.Must
CSRF *actionutils.CSRF
}) {
var listId int64 = 0
defer func() {
2023-06-30 18:08:30 +08:00
defer this.CreateLogInfo(codes.IPList_LogCreateIPList, listId)
2021-06-23 13:12:33 +08:00
}()
params.Must.
Field("name", params.Name).
Require("请输入名称")
2024-05-05 14:08:32 +08:00
if len(params.Code) > 0 {
if !iplistutils.ValidateIPListCode(params.Code) {
this.FailField("code", "代号格式错误,只能是英文字母、数字、中划线、下划线的组合")
return
}
listIdResp, err := this.RPC().IPListRPC().FindIPListIdWithCode(this.AdminContext(), &pb.FindIPListIdWithCodeRequest{Code: params.Code})
if err != nil {
this.ErrorPage(err)
return
}
if listIdResp.IpListId > 0 {
this.FailField("code", "代号'"+params.Code+"'已经被别的名单占用,请更换一个")
return
}
}
2021-06-23 13:12:33 +08:00
createResp, err := this.RPC().IPListRPC().CreateIPList(this.AdminContext(), &pb.CreateIPListRequest{
Type: params.Type,
Name: params.Name,
2024-05-05 14:08:32 +08:00
Code: params.Code,
2021-06-23 13:12:33 +08:00
TimeoutJSON: nil,
IsPublic: true,
Description: params.Description,
IsGlobal: params.IsGlobal,
2021-06-23 13:12:33 +08:00
})
if err != nil {
this.ErrorPage(err)
return
}
listId = createResp.IpListId
this.Data["list"] = maps.Map{
"type": params.Type,
}
this.Success()
}