Files
EdgeAdmin/internal/web/actions/default/servers/components/waf/ipadmin/updateIPPopup.go

97 lines
2.1 KiB
Go
Raw Normal View History

2020-11-07 19:40:18 +08:00
package ipadmin
2024-04-06 14:55:29 +08:00
import (
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
2020-11-07 19:40:18 +08:00
"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-07 19:40:18 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
type UpdateIPPopupAction struct {
actionutils.ParentAction
}
func (this *UpdateIPPopupAction) Init() {
this.Nav("", "", "")
}
func (this *UpdateIPPopupAction) RunGet(params struct {
ItemId int64
}) {
itemResp, err := this.RPC().IPItemRPC().FindEnabledIPItem(this.AdminContext(), &pb.FindEnabledIPItemRequest{IpItemId: params.ItemId})
if err != nil {
this.ErrorPage(err)
return
}
item := itemResp.IpItem
if item == nil {
this.NotFound("ipItem", params.ItemId)
return
}
this.Data["item"] = maps.Map{
2021-02-06 17:37:09 +08:00
"id": item.Id,
"value": item.Value,
2021-02-06 17:37:09 +08:00
"ipFrom": item.IpFrom,
"ipTo": item.IpTo,
"expiredAt": item.ExpiredAt,
"reason": item.Reason,
"type": item.Type,
"eventLevel": item.EventLevel,
2020-11-07 19:40:18 +08:00
}
this.Data["type"] = item.Type
2020-11-07 19:40:18 +08:00
this.Show()
}
func (this *UpdateIPPopupAction) RunPost(params struct {
FirewallPolicyId int64
ItemId int64
2020-11-07 19:40:18 +08:00
Value string
2021-02-06 17:37:09 +08:00
ExpiredAt int64
Reason string
Type string
EventLevel string
2020-11-07 19:40:18 +08:00
Must *actions.Must
CSRF *actionutils.CSRF
}) {
// 日志
2023-06-30 18:08:30 +08:00
defer this.CreateLogInfo(codes.WAF_LogUpdateIPFromWAFPolicy, params.FirewallPolicyId, params.ItemId)
switch params.Type {
case "ip":
// 校验IP格式
params.Must.
Field("value", params.Value).
Require("请输入IP或IP段")
2024-04-06 14:55:29 +08:00
_, _, _, ok := utils.ParseIPValue(params.Value)
if !ok {
this.FailField("value", "请输入正确的IP格式")
return
}
case "all":
params.Value = "0.0.0.0"
2021-01-03 20:25:15 +08:00
}
2020-11-07 19:40:18 +08:00
_, err := this.RPC().IPItemRPC().UpdateIPItem(this.AdminContext(), &pb.UpdateIPItemRequest{
2021-02-06 17:37:09 +08:00
IpItemId: params.ItemId,
Value: params.Value,
2021-02-06 17:37:09 +08:00
ExpiredAt: params.ExpiredAt,
Reason: params.Reason,
Type: params.Type,
EventLevel: params.EventLevel,
2020-11-07 19:40:18 +08:00
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}