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"
|
2021-01-03 20:25:15 +08:00
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
2020-11-07 19:40:18 +08:00
|
|
|
|
"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 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{
|
|
|
|
|
|
"id": item.Id,
|
|
|
|
|
|
"ipFrom": item.IpFrom,
|
|
|
|
|
|
"ipTo": item.IpTo,
|
|
|
|
|
|
"expiredAt": item.ExpiredAt,
|
|
|
|
|
|
"reason": item.Reason,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.Show()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *UpdateIPPopupAction) RunPost(params struct {
|
2020-11-10 09:22:58 +08:00
|
|
|
|
FirewallPolicyId int64
|
|
|
|
|
|
ItemId int64
|
2020-11-07 19:40:18 +08:00
|
|
|
|
|
|
|
|
|
|
IpFrom string
|
|
|
|
|
|
IpTo string
|
|
|
|
|
|
ExpiredAt int64
|
|
|
|
|
|
Reason string
|
|
|
|
|
|
|
|
|
|
|
|
Must *actions.Must
|
|
|
|
|
|
CSRF *actionutils.CSRF
|
|
|
|
|
|
}) {
|
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, params.ItemId)
|
2020-11-17 15:41:43 +08:00
|
|
|
|
|
2020-11-07 19:40:18 +08:00
|
|
|
|
// TODO 校验ItemId所属用户
|
|
|
|
|
|
|
|
|
|
|
|
params.Must.
|
|
|
|
|
|
Field("ipFrom", params.IpFrom).
|
|
|
|
|
|
Require("请输入开始IP")
|
|
|
|
|
|
|
2021-01-03 20:25:15 +08:00
|
|
|
|
// 校验IP格式(ipFrom/ipTo)
|
|
|
|
|
|
ipFromLong := utils.IP2Long(params.IpFrom)
|
|
|
|
|
|
if len(params.IpFrom) > 0 {
|
|
|
|
|
|
if ipFromLong == 0 {
|
|
|
|
|
|
this.Fail("请输入正确的开始IP")
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ipToLong := utils.IP2Long(params.IpTo)
|
|
|
|
|
|
if len(params.IpTo) > 0 {
|
|
|
|
|
|
if ipToLong == 0 {
|
|
|
|
|
|
this.Fail("请输入正确的结束IP")
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ipFromLong > 0 && ipToLong > 0 && ipFromLong > ipToLong {
|
|
|
|
|
|
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-11-07 19:40:18 +08:00
|
|
|
|
_, err := this.RPC().IPItemRPC().UpdateIPItem(this.AdminContext(), &pb.UpdateIPItemRequest{
|
|
|
|
|
|
IpItemId: params.ItemId,
|
|
|
|
|
|
IpFrom: params.IpFrom,
|
|
|
|
|
|
IpTo: params.IpTo,
|
|
|
|
|
|
ExpiredAt: params.ExpiredAt,
|
|
|
|
|
|
Reason: params.Reason,
|
|
|
|
|
|
})
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.Success()
|
|
|
|
|
|
}
|