mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-29 14:26:34 +08:00
IP名单批量导入IP支持CIDR
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"encoding/csv"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
@@ -201,6 +202,19 @@ func (this *ImportAction) createItemFromValues(values []string, countIgnore *int
|
||||
item.Reason = values[5]
|
||||
}
|
||||
|
||||
// CIDR
|
||||
if strings.Contains(item.IpFrom, "/") {
|
||||
ipFrom, ipTo, err := configutils.ParseCIDR(item.IpFrom)
|
||||
if err == nil {
|
||||
item.IpFrom = ipFrom
|
||||
item.IpTo = ipTo
|
||||
}
|
||||
}
|
||||
|
||||
if len(item.EventLevel) == 0 {
|
||||
item.EventLevel = "critical"
|
||||
}
|
||||
|
||||
if net.ParseIP(item.IpFrom) == nil {
|
||||
*countIgnore++
|
||||
return nil
|
||||
@@ -209,5 +223,6 @@ func (this *ImportAction) createItemFromValues(values []string, countIgnore *int
|
||||
*countIgnore++
|
||||
return nil
|
||||
}
|
||||
|
||||
return item
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user