2020-11-07 19:40:18 +08:00
|
|
|
|
package ipadmin
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
2020-11-17 15:41:43 +08:00
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
2020-11-07 19:40:18 +08:00
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
2020-11-10 09:22:58 +08:00
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/waf/ipadmin/ipadminutils"
|
2020-11-07 19:40:18 +08:00
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/models"
|
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
|
|
|
|
"github.com/iwind/TeaGo/actions"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type CreateIPPopupAction struct {
|
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *CreateIPPopupAction) Init() {
|
|
|
|
|
|
this.Nav("", "", "")
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *CreateIPPopupAction) RunGet(params struct {
|
|
|
|
|
|
FirewallPolicyId int64
|
|
|
|
|
|
Type string
|
|
|
|
|
|
}) {
|
|
|
|
|
|
this.Data["type"] = params.Type
|
|
|
|
|
|
|
|
|
|
|
|
listId, err := models.SharedHTTPFirewallPolicyDAO.FindEnabledPolicyIPListIdWithType(this.AdminContext(), params.FirewallPolicyId, params.Type)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
this.Data["listId"] = listId
|
|
|
|
|
|
|
|
|
|
|
|
this.Show()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *CreateIPPopupAction) RunPost(params struct {
|
2020-11-10 09:22:58 +08:00
|
|
|
|
FirewallPolicyId int64
|
|
|
|
|
|
ListId int64
|
|
|
|
|
|
IpFrom string
|
|
|
|
|
|
IpTo string
|
|
|
|
|
|
ExpiredAt int64
|
|
|
|
|
|
Reason string
|
2020-11-07 19:40:18 +08:00
|
|
|
|
|
|
|
|
|
|
Must *actions.Must
|
|
|
|
|
|
CSRF *actionutils.CSRF
|
|
|
|
|
|
}) {
|
|
|
|
|
|
// TODO 校验ListId所属用户
|
|
|
|
|
|
// TODO 校验IP格式(ipFrom/ipTo)
|
|
|
|
|
|
|
|
|
|
|
|
params.Must.
|
|
|
|
|
|
Field("ipFrom", params.IpFrom).
|
|
|
|
|
|
Require("请输入开始IP")
|
|
|
|
|
|
|
2020-11-17 15:41:43 +08:00
|
|
|
|
createResp, err := this.RPC().IPItemRPC().CreateIPItem(this.AdminContext(), &pb.CreateIPItemRequest{
|
2020-11-07 19:40:18 +08:00
|
|
|
|
IpListId: params.ListId,
|
|
|
|
|
|
IpFrom: params.IpFrom,
|
|
|
|
|
|
IpTo: params.IpTo,
|
|
|
|
|
|
ExpiredAt: params.ExpiredAt,
|
|
|
|
|
|
Reason: params.Reason,
|
|
|
|
|
|
})
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2020-11-17 15:41:43 +08:00
|
|
|
|
itemId := createResp.IpItemId
|
2020-11-07 19:40:18 +08:00
|
|
|
|
|
2020-11-10 09:22:58 +08:00
|
|
|
|
// 发送通知
|
|
|
|
|
|
err = ipadminutils.NotifyUpdateToClustersWithFirewallPolicyId(this.AdminContext(), params.FirewallPolicyId)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-11-17 15:41:43 +08:00
|
|
|
|
// 日志
|
2020-11-20 15:32:42 +08:00
|
|
|
|
defer this.CreateLog(oplogs.LevelInfo, "在WAF策略 %d 名单中添加IP %d", params.FirewallPolicyId, itemId)
|
2020-11-17 15:41:43 +08:00
|
|
|
|
|
2020-11-07 19:40:18 +08:00
|
|
|
|
this.Success()
|
|
|
|
|
|
}
|