mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-23 18:00:27 +08:00
IP名单新增IPv6和所有IP两种类型
This commit is contained in:
@@ -37,8 +37,11 @@ func (this *UpdateIPPopupAction) RunGet(params struct {
|
||||
"ipTo": item.IpTo,
|
||||
"expiredAt": item.ExpiredAt,
|
||||
"reason": item.Reason,
|
||||
"type": item.Type,
|
||||
}
|
||||
|
||||
this.Data["type"] = item.Type
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
@@ -50,6 +53,7 @@ func (this *UpdateIPPopupAction) RunPost(params struct {
|
||||
IpTo string
|
||||
ExpiredAt int64
|
||||
Reason string
|
||||
Type string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
@@ -59,27 +63,39 @@ func (this *UpdateIPPopupAction) RunPost(params struct {
|
||||
|
||||
// TODO 校验ItemId所属用户
|
||||
|
||||
params.Must.
|
||||
Field("ipFrom", params.IpFrom).
|
||||
Require("请输入开始IP")
|
||||
switch params.Type {
|
||||
case "ipv4":
|
||||
params.Must.
|
||||
Field("ipFrom", params.IpFrom).
|
||||
Require("请输入开始IP")
|
||||
|
||||
// 校验IP格式(ipFrom/ipTo)
|
||||
ipFromLong := utils.IP2Long(params.IpFrom)
|
||||
if len(params.IpFrom) > 0 {
|
||||
if ipFromLong == 0 {
|
||||
// 校验IP格式(ipFrom/ipTo)
|
||||
var ipFromLong uint64
|
||||
if !utils.IsIPv4(params.IpFrom) {
|
||||
this.Fail("请输入正确的开始IP")
|
||||
}
|
||||
}
|
||||
ipFromLong = utils.IP2Long(params.IpFrom)
|
||||
|
||||
ipToLong := utils.IP2Long(params.IpTo)
|
||||
if len(params.IpTo) > 0 {
|
||||
if ipToLong == 0 {
|
||||
var ipToLong uint64
|
||||
if len(params.IpTo) > 0 && !utils.IsIPv4(params.IpTo) {
|
||||
ipToLong = utils.IP2Long(params.IpTo)
|
||||
this.Fail("请输入正确的结束IP")
|
||||
}
|
||||
}
|
||||
|
||||
if ipFromLong > 0 && ipToLong > 0 && ipFromLong > ipToLong {
|
||||
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
|
||||
if ipFromLong > 0 && ipToLong > 0 && ipFromLong > ipToLong {
|
||||
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
|
||||
}
|
||||
case "ipv6":
|
||||
params.Must.
|
||||
Field("ipFrom", params.IpFrom).
|
||||
Require("请输入IP")
|
||||
|
||||
// 校验IP格式(ipFrom)
|
||||
if !utils.IsIPv6(params.IpFrom) {
|
||||
this.Fail("请输入正确的IPv6地址")
|
||||
}
|
||||
case "all":
|
||||
params.IpFrom = "0.0.0.0"
|
||||
}
|
||||
|
||||
_, err := this.RPC().IPItemRPC().UpdateIPItem(this.AdminContext(), &pb.UpdateIPItemRequest{
|
||||
@@ -88,6 +104,7 @@ func (this *UpdateIPPopupAction) RunPost(params struct {
|
||||
IpTo: params.IpTo,
|
||||
ExpiredAt: params.ExpiredAt,
|
||||
Reason: params.Reason,
|
||||
Type: params.Type,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
|
||||
Reference in New Issue
Block a user