简化IP名单中创建IP操作/支持IP以CIDR方式显示

This commit is contained in:
GoEdgeLab
2024-04-13 16:45:32 +08:00
parent 34bd39100b
commit e33eeb9018
30 changed files with 229 additions and 537 deletions

View File

@@ -3,11 +3,66 @@ package utils
import ( import (
"bytes" "bytes"
"errors" "errors"
"github.com/TeaOSLab/EdgeCommon/pkg/iputils"
"github.com/iwind/TeaGo/types" "github.com/iwind/TeaGo/types"
"net" "net"
"strings" "strings"
) )
// ParseIPValue 解析IP值
func ParseIPValue(value string) (newValue string, ipFrom string, ipTo string, ok bool) {
if len(value) == 0 {
return
}
newValue = value
// ip1-ip2
if strings.Contains(value, "-") {
var pieces = strings.Split(value, "-")
if len(pieces) != 2 {
return
}
ipFrom = strings.TrimSpace(pieces[0])
ipTo = strings.TrimSpace(pieces[1])
if !iputils.IsValid(ipFrom) || !iputils.IsValid(ipTo) {
return
}
if !iputils.IsSameVersion(ipFrom, ipTo) {
return
}
if iputils.CompareIP(ipFrom, ipTo) > 0 {
ipFrom, ipTo = ipTo, ipFrom
newValue = ipFrom + "-" + ipTo
}
ok = true
return
}
// ip/mask
if strings.Contains(value, "/") {
cidr, err := iputils.ParseCIDR(value)
if err != nil {
return
}
return newValue, cidr.From().String(), cidr.To().String(), true
}
// single value
if iputils.IsValid(value) {
ipFrom = value
ok = true
return
}
return
}
// ExtractIP 分解IP // ExtractIP 分解IP
// 只支持D段掩码的CIDR // 只支持D段掩码的CIDR
// 最多只记录255个值 // 最多只记录255个值

View File

@@ -99,6 +99,7 @@ func (this *ListsAction) RunGet(params struct {
itemMaps = append(itemMaps, maps.Map{ itemMaps = append(itemMaps, maps.Map{
"id": item.Id, "id": item.Id,
"value": item.Value,
"ipFrom": item.IpFrom, "ipFrom": item.IpFrom,
"ipTo": item.IpTo, "ipTo": item.IpTo,
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt), "createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),

View File

@@ -57,6 +57,7 @@ func (this *TestAction) RunPost(params struct {
if resp.IpItem != nil { if resp.IpItem != nil {
resultMap["item"] = maps.Map{ resultMap["item"] = maps.Map{
"id": resp.IpItem.Id, "id": resp.IpItem.Id,
"value": resp.IpItem.Value,
"ipFrom": resp.IpItem.IpFrom, "ipFrom": resp.IpItem.IpFrom,
"ipTo": resp.IpItem.IpTo, "ipTo": resp.IpItem.IpTo,
"reason": resp.IpItem.Reason, "reason": resp.IpItem.Reason,

View File

@@ -1,8 +1,8 @@
package ipadmin package ipadmin
import ( import (
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/iputils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes" "github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/actions"
@@ -33,6 +33,7 @@ func (this *UpdateIPPopupAction) RunGet(params struct {
this.Data["item"] = maps.Map{ this.Data["item"] = maps.Map{
"id": item.Id, "id": item.Id,
"value": item.Value,
"ipFrom": item.IpFrom, "ipFrom": item.IpFrom,
"ipTo": item.IpTo, "ipTo": item.IpTo,
"expiredAt": item.ExpiredAt, "expiredAt": item.ExpiredAt,
@@ -50,8 +51,7 @@ func (this *UpdateIPPopupAction) RunPost(params struct {
FirewallPolicyId int64 FirewallPolicyId int64
ItemId int64 ItemId int64
IpFrom string Value string
IpTo string
ExpiredAt int64 ExpiredAt int64
Reason string Reason string
Type string Type string
@@ -63,50 +63,25 @@ func (this *UpdateIPPopupAction) RunPost(params struct {
// 日志 // 日志
defer this.CreateLogInfo(codes.WAF_LogUpdateIPFromWAFPolicy, params.FirewallPolicyId, params.ItemId) defer this.CreateLogInfo(codes.WAF_LogUpdateIPFromWAFPolicy, params.FirewallPolicyId, params.ItemId)
// TODO 校验ItemId所属用户
switch params.Type { switch params.Type {
case "ipv4": case "ip":
// 校验IP格式
params.Must. params.Must.
Field("ipFrom", params.IpFrom). Field("value", params.Value).
Require("请输入开始IP") Require("请输入IP或IP段")
// 校验IP格式ipFrom/ipTo _, _, _, ok := utils.ParseIPValue(params.Value)
if !iputils.IsIPv4(params.IpFrom) { if !ok {
this.FailField("ipFrom", "请输入正确的开始IP") this.FailField("value", "请输入正确的IP格式")
} return
if len(params.IpTo) > 0 && !iputils.IsIPv4(params.IpTo) {
this.FailField("ipTo", "请输入正确的结束IP")
}
if len(params.IpTo) > 0 && iputils.CompareIP(params.IpFrom, params.IpTo) > 0 {
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
}
case "ipv6":
params.Must.
Field("ipFrom", params.IpFrom).
Require("请输入正确的开始IP")
if !iputils.IsIPv6(params.IpFrom) {
this.FailField("ipFrom", "请输入正确的IPv6地址")
}
if len(params.IpTo) > 0 && !iputils.IsIPv6(params.IpTo) {
this.FailField("ipTo", "请输入正确的IPv6地址")
}
if len(params.IpTo) > 0 && iputils.CompareIP(params.IpFrom, params.IpTo) > 0 {
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
} }
case "all": case "all":
params.IpFrom = "0.0.0.0" params.Value = "0.0.0.0"
} }
_, err := this.RPC().IPItemRPC().UpdateIPItem(this.AdminContext(), &pb.UpdateIPItemRequest{ _, err := this.RPC().IPItemRPC().UpdateIPItem(this.AdminContext(), &pb.UpdateIPItemRequest{
IpItemId: params.ItemId, IpItemId: params.ItemId,
IpFrom: params.IpFrom, Value: params.Value,
IpTo: params.IpTo,
ExpiredAt: params.ExpiredAt, ExpiredAt: params.ExpiredAt,
Reason: params.Reason, Reason: params.Reason,
Type: params.Type, Type: params.Type,

View File

@@ -109,6 +109,7 @@ func (this *AllowListAction) RunGet(params struct {
itemMaps = append(itemMaps, maps.Map{ itemMaps = append(itemMaps, maps.Map{
"id": item.Id, "id": item.Id,
"value": item.Value,
"ipFrom": item.IpFrom, "ipFrom": item.IpFrom,
"ipTo": item.IpTo, "ipTo": item.IpTo,
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt), "createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),

View File

@@ -109,6 +109,7 @@ func (this *DenyListAction) RunGet(params struct {
itemMaps = append(itemMaps, maps.Map{ itemMaps = append(itemMaps, maps.Map{
"id": item.Id, "id": item.Id,
"value": item.Value,
"ipFrom": item.IpFrom, "ipFrom": item.IpFrom,
"ipTo": item.IpTo, "ipTo": item.IpTo,
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt), "createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),

View File

@@ -70,6 +70,7 @@ func (this *TestAction) RunPost(params struct {
if resp.IpItem != nil { if resp.IpItem != nil {
resultMap["item"] = maps.Map{ resultMap["item"] = maps.Map{
"id": resp.IpItem.Id, "id": resp.IpItem.Id,
"value": resp.IpItem.Value,
"ipFrom": resp.IpItem.IpFrom, "ipFrom": resp.IpItem.IpFrom,
"ipTo": resp.IpItem.IpTo, "ipTo": resp.IpItem.IpTo,
"reason": resp.IpItem.Reason, "reason": resp.IpItem.Reason,

View File

@@ -1,8 +1,8 @@
package ipadmin package ipadmin
import ( import (
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/iputils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes" "github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/actions"
@@ -33,6 +33,7 @@ func (this *UpdateIPPopupAction) RunGet(params struct {
this.Data["item"] = maps.Map{ this.Data["item"] = maps.Map{
"id": item.Id, "id": item.Id,
"value": item.Value,
"ipFrom": item.IpFrom, "ipFrom": item.IpFrom,
"ipTo": item.IpTo, "ipTo": item.IpTo,
"expiredAt": item.ExpiredAt, "expiredAt": item.ExpiredAt,
@@ -49,8 +50,7 @@ func (this *UpdateIPPopupAction) RunGet(params struct {
func (this *UpdateIPPopupAction) RunPost(params struct { func (this *UpdateIPPopupAction) RunPost(params struct {
ItemId int64 ItemId int64
IpFrom string Value string
IpTo string
ExpiredAt int64 ExpiredAt int64
Reason string Reason string
Type string Type string
@@ -62,50 +62,25 @@ func (this *UpdateIPPopupAction) RunPost(params struct {
// 日志 // 日志
defer this.CreateLogInfo(codes.IPItem_LogUpdateIPItem, params.ItemId) defer this.CreateLogInfo(codes.IPItem_LogUpdateIPItem, params.ItemId)
// TODO 校验ItemId所属用户
switch params.Type { switch params.Type {
case "ipv4": case "ip":
// 校验IP格式
params.Must. params.Must.
Field("ipFrom", params.IpFrom). Field("value", params.Value).
Require("请输入开始IP") Require("请输入IP或IP段")
// 校验IP格式ipFrom/ipTo _, _, _, ok := utils.ParseIPValue(params.Value)
if !iputils.IsIPv4(params.IpFrom) { if !ok {
this.FailField("ipFrom", "请输入正确的开始IP") this.FailField("value", "请输入正确的IP格式")
} return
if len(params.IpTo) > 0 && !iputils.IsIPv4(params.IpTo) {
this.FailField("ipTo", "请输入正确的结束IP")
}
if len(params.IpTo) > 0 && iputils.CompareIP(params.IpFrom, params.IpTo) > 0 {
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
}
case "ipv6":
params.Must.
Field("ipFrom", params.IpFrom).
Require("请输入正确的开始IP")
if !iputils.IsIPv6(params.IpFrom) {
this.FailField("ipFrom", "请输入正确的IPv6地址")
}
if len(params.IpTo) > 0 && !iputils.IsIPv6(params.IpTo) {
this.FailField("ipTo", "请输入正确的IPv6地址")
}
if len(params.IpTo) > 0 && iputils.CompareIP(params.IpFrom, params.IpTo) > 0 {
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
} }
case "all": case "all":
params.IpFrom = "0.0.0.0" params.Value = "0.0.0.0"
} }
_, err := this.RPC().IPItemRPC().UpdateIPItem(this.AdminContext(), &pb.UpdateIPItemRequest{ _, err := this.RPC().IPItemRPC().UpdateIPItem(this.AdminContext(), &pb.UpdateIPItemRequest{
IpItemId: params.ItemId, IpItemId: params.ItemId,
IpFrom: params.IpFrom, Value: params.Value,
IpTo: params.IpTo,
ExpiredAt: params.ExpiredAt, ExpiredAt: params.ExpiredAt,
Reason: params.Reason, Reason: params.Reason,
Type: params.Type, Type: params.Type,

View File

@@ -1,16 +1,14 @@
package iplists package iplists
import ( import (
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
"github.com/TeaOSLab/EdgeCommon/pkg/iputils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes" "github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
"github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types" "github.com/iwind/TeaGo/types"
"net"
"strings" "strings"
) )
@@ -50,9 +48,7 @@ func (this *CreateIPPopupAction) RunPost(params struct {
ListId int64 ListId int64
Method string Method string
IpFrom string Value string
IpTo string
IpData string IpData string
ExpiredAt int64 ExpiredAt int64
@@ -76,29 +72,24 @@ func (this *CreateIPPopupAction) RunPost(params struct {
} }
type ipData struct { type ipData struct {
value string
ipFrom string ipFrom string
ipTo string ipTo string
} }
var batchIPs = []*ipData{} var batchIPs = []*ipData{}
switch params.Type { switch params.Type {
case "ipv4": case "ip":
if params.Method == "single" { if params.Method == "single" {
// 校验IP格式ipFrom/ipTo // 校验IP格式
params.Must. params.Must.
Field("ipFrom", params.IpFrom). Field("value", params.Value).
Require("请输入开始IP") Require("请输入IP或IP段")
if !iputils.IsIPv4(params.IpFrom) { _, _, _, ok := utils.ParseIPValue(params.Value)
this.FailField("ipFrom", "请输入正确的开始IP") if !ok {
} this.FailField("value", "请输入正确的IP格式")
return
if len(params.IpTo) > 0 && !iputils.IsIPv4(params.IpTo) {
this.FailField("ipTo", "请输入正确的结束IP")
}
if len(params.IpTo) != 0 && iputils.CompareIP(params.IpFrom, params.IpTo) > 0 {
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
} }
} else if params.Method == "batch" { } else if params.Method == "batch" {
if len(params.IpData) == 0 { if len(params.IpData) == 0 {
@@ -107,144 +98,30 @@ func (this *CreateIPPopupAction) RunPost(params struct {
var lines = strings.Split(params.IpData, "\n") var lines = strings.Split(params.IpData, "\n")
for index, line := range lines { for index, line := range lines {
line = strings.TrimSpace(line) line = strings.TrimSpace(line)
if strings.Contains(line, "/") { // CIDR if len(line) == 0 {
if strings.Contains(line, ":") { continue
this.FailField("ipData", "第"+types.String(index+1)+"行IP格式错误"+line)
}
ipFrom, ipTo, err := configutils.ParseCIDR(line)
if err != nil {
this.FailField("ipData", "第"+types.String(index+1)+"行IP格式错误"+line)
}
batchIPs = append(batchIPs, &ipData{
ipFrom: ipFrom,
ipTo: ipTo,
})
} else if strings.Contains(line, "-") { // IP Range
var pieces = strings.Split(line, "-")
var ipFrom = strings.TrimSpace(pieces[0])
var ipTo = strings.TrimSpace(pieces[1])
if net.ParseIP(ipFrom) == nil || net.ParseIP(ipTo) == nil || strings.Contains(ipFrom, ":") || strings.Contains(ipTo, ":") {
this.FailField("ipData", "第"+types.String(index+1)+"行IP格式错误"+line)
}
if len(ipTo) > 0 && iputils.CompareIP(ipFrom, ipTo) > 0 {
ipFrom, ipTo = ipTo, ipFrom
}
batchIPs = append(batchIPs, &ipData{
ipFrom: ipFrom,
ipTo: ipTo,
})
} else if strings.Contains(line, ",") { // IP Range
var pieces = strings.Split(line, ",")
var ipFrom = strings.TrimSpace(pieces[0])
var ipTo = strings.TrimSpace(pieces[1])
if net.ParseIP(ipFrom) == nil || net.ParseIP(ipTo) == nil || strings.Contains(ipFrom, ":") || strings.Contains(ipTo, ":") {
this.FailField("ipData", "第"+types.String(index+1)+"行IP格式错误"+line)
}
if len(ipTo) > 0 && iputils.CompareIP(ipFrom, ipTo) > 0 {
ipFrom, ipTo = ipTo, ipFrom
}
batchIPs = append(batchIPs, &ipData{
ipFrom: ipFrom,
ipTo: ipTo,
})
} else if len(line) > 0 {
var ipFrom = line
if net.ParseIP(ipFrom) == nil || strings.Contains(ipFrom, ":") {
this.FailField("ipData", "第"+types.String(index+1)+"行IP格式错误"+line)
}
batchIPs = append(batchIPs, &ipData{
ipFrom: ipFrom,
})
} }
} _, ipFrom, ipTo, ok := utils.ParseIPValue(line)
} if !ok {
case "ipv6": this.FailField("ipData", "第"+types.String(index+1)+"行IP格式错误"+line)
if params.Method == "single" { return
params.Must.
Field("ipFrom", params.IpFrom).
Require("请输入正确的开始IP")
if !iputils.IsIPv6(params.IpFrom) {
this.FailField("ipFrom", "请输入正确的IPv6地址")
}
if len(params.IpTo) > 0 && !iputils.IsIPv6(params.IpTo) {
this.FailField("ipTo", "请输入正确的IPv6地址")
}
if len(params.IpTo) > 0 && iputils.CompareIP(params.IpFrom, params.IpTo) > 0 {
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
}
} else if params.Method == "batch" {
if len(params.IpData) == 0 {
this.FailField("ipData", "请输入IP")
}
var lines = strings.Split(params.IpData, "\n")
for index, line := range lines {
line = strings.TrimSpace(line)
if strings.Contains(line, "/") { // CIDR
if !strings.Contains(line, ":") {
this.FailField("ipData", "第"+types.String(index+1)+"行IP格式错误"+line)
}
ipFrom, ipTo, err := configutils.ParseCIDR(line)
if err != nil {
this.FailField("ipData", "第"+types.String(index+1)+"行IP格式错误"+line)
}
batchIPs = append(batchIPs, &ipData{
ipFrom: ipFrom,
ipTo: ipTo,
})
} else if strings.Contains(line, "-") { // IP Range
var pieces = strings.Split(line, "-")
var ipFrom = strings.TrimSpace(pieces[0])
var ipTo = strings.TrimSpace(pieces[1])
if net.ParseIP(ipFrom) == nil || net.ParseIP(ipTo) == nil || !strings.Contains(ipFrom, ":") || !strings.Contains(ipTo, ":") {
this.FailField("ipData", "第"+types.String(index+1)+"行IP格式错误"+line)
}
if len(ipTo) > 0 && iputils.CompareIP(ipFrom, ipTo) > 0 {
ipFrom, ipTo = ipTo, ipFrom
}
batchIPs = append(batchIPs, &ipData{
ipFrom: ipFrom,
ipTo: ipTo,
})
} else if strings.Contains(line, ",") { // IP Range
var pieces = strings.Split(line, ",")
var ipFrom = strings.TrimSpace(pieces[0])
var ipTo = strings.TrimSpace(pieces[1])
if net.ParseIP(ipFrom) == nil || net.ParseIP(ipTo) == nil || !strings.Contains(ipFrom, ":") || !strings.Contains(ipTo, ":") {
this.FailField("ipData", "第"+types.String(index+1)+"行IP格式错误"+line)
}
if len(ipTo) > 0 && iputils.CompareIP(ipFrom, ipTo) > 0 {
ipFrom, ipTo = ipTo, ipFrom
}
batchIPs = append(batchIPs, &ipData{
ipFrom: ipFrom,
ipTo: ipTo,
})
} else if len(line) > 0 {
var ipFrom = line
if net.ParseIP(ipFrom) == nil || !strings.Contains(ipFrom, ":") {
this.FailField("ipData", "第"+types.String(index+1)+"行IP格式错误"+line)
}
batchIPs = append(batchIPs, &ipData{
ipFrom: ipFrom,
})
} }
batchIPs = append(batchIPs, &ipData{
value: line,
ipFrom: ipFrom,
ipTo: ipTo,
})
} }
} }
case "all": case "all":
params.IpFrom = "0.0.0.0" params.Value = "0.0.0.0"
} }
if len(batchIPs) > 0 { if len(batchIPs) > 0 {
for _, ip := range batchIPs { for _, ip := range batchIPs {
_, err := this.RPC().IPItemRPC().CreateIPItem(this.AdminContext(), &pb.CreateIPItemRequest{ _, err := this.RPC().IPItemRPC().CreateIPItem(this.AdminContext(), &pb.CreateIPItemRequest{
IpListId: params.ListId, IpListId: params.ListId,
Value: ip.value,
IpFrom: ip.ipFrom, IpFrom: ip.ipFrom,
IpTo: ip.ipTo, IpTo: ip.ipTo,
ExpiredAt: params.ExpiredAt, ExpiredAt: params.ExpiredAt,
@@ -263,8 +140,7 @@ func (this *CreateIPPopupAction) RunPost(params struct {
} else { } else {
createResp, err := this.RPC().IPItemRPC().CreateIPItem(this.AdminContext(), &pb.CreateIPItemRequest{ createResp, err := this.RPC().IPItemRPC().CreateIPItem(this.AdminContext(), &pb.CreateIPItemRequest{
IpListId: params.ListId, IpListId: params.ListId,
IpFrom: params.IpFrom, Value: params.Value,
IpTo: params.IpTo,
ExpiredAt: params.ExpiredAt, ExpiredAt: params.ExpiredAt,
Reason: params.Reason, Reason: params.Reason,
Type: params.Type, Type: params.Type,

View File

@@ -30,7 +30,6 @@ func (this *ExportDataAction) RunGet(params struct {
}) { }) {
defer this.CreateLogInfo(codes.IPList_LogExportIPList, params.ListId) defer this.CreateLogInfo(codes.IPList_LogExportIPList, params.ListId)
var err error
var ext string var ext string
var jsonMaps = []maps.Map{} var jsonMaps = []maps.Map{}
var xlsxFile *xlsx.File var xlsxFile *xlsx.File
@@ -44,20 +43,16 @@ func (this *ExportDataAction) RunGet(params struct {
case "xlsx": case "xlsx":
ext = ".xlsx" ext = ".xlsx"
xlsxFile = xlsx.NewFile() xlsxFile = xlsx.NewFile()
if err != nil { var err error
this.ErrorPage(err)
return
}
xlsxSheet, err = xlsxFile.AddSheet("IP名单") xlsxSheet, err = xlsxFile.AddSheet("IP名单")
if err != nil { if err != nil {
this.ErrorPage(err) this.ErrorPage(err)
return return
} }
row := xlsxSheet.AddRow() var row = xlsxSheet.AddRow()
row.SetHeight(26) row.SetHeight(26)
row.AddCell().SetValue("开始IP") row.AddCell().SetValue("IP/IP段")
row.AddCell().SetValue("结束IP")
row.AddCell().SetValue("过期时间戳") row.AddCell().SetValue("过期时间戳")
row.AddCell().SetValue("类型") row.AddCell().SetValue("类型")
row.AddCell().SetValue("级别") row.AddCell().SetValue("级别")
@@ -93,27 +88,25 @@ func (this *ExportDataAction) RunGet(params struct {
for _, item := range itemsResp.IpItems { for _, item := range itemsResp.IpItems {
switch params.Format { switch params.Format {
case "xlsx": case "xlsx":
row := xlsxSheet.AddRow() var row = xlsxSheet.AddRow()
row.SetHeight(26) row.SetHeight(26)
row.AddCell().SetValue(item.IpFrom) row.AddCell().SetValue(item.Value)
row.AddCell().SetValue(item.IpTo)
row.AddCell().SetValue(types.String(item.ExpiredAt)) row.AddCell().SetValue(types.String(item.ExpiredAt))
row.AddCell().SetValue(item.Type) row.AddCell().SetValue(item.Type)
row.AddCell().SetValue(item.EventLevel) row.AddCell().SetValue(item.EventLevel)
row.AddCell().SetValue(item.Reason) row.AddCell().SetValue(item.Reason)
case "csv": case "csv":
err = csvWriter.Write([]string{item.IpFrom, item.IpTo, types.String(item.ExpiredAt), item.Type, item.EventLevel, item.Reason}) err = csvWriter.Write([]string{item.Value, types.String(item.ExpiredAt), item.Type, item.EventLevel, item.Reason})
if err != nil { if err != nil {
this.ErrorPage(err) this.ErrorPage(err)
return return
} }
case "txt": case "txt":
data = append(data, item.IpFrom+","+item.IpTo+","+types.String(item.ExpiredAt)+","+item.Type+","+item.EventLevel+","+item.Reason...) data = append(data, item.Value+","+types.String(item.ExpiredAt)+","+item.Type+","+item.EventLevel+","+item.Reason...)
data = append(data, '\n') data = append(data, '\n')
case "json": case "json":
jsonMaps = append(jsonMaps, maps.Map{ jsonMaps = append(jsonMaps, maps.Map{
"ipFrom": item.IpFrom, "value": item.Value,
"ipTo": item.IpTo,
"expiredAt": item.ExpiredAt, "expiredAt": item.ExpiredAt,
"type": item.Type, "type": item.Type,
"eventLevel": item.EventLevel, "eventLevel": item.EventLevel,
@@ -127,7 +120,7 @@ func (this *ExportDataAction) RunGet(params struct {
switch params.Format { switch params.Format {
case "xlsx": case "xlsx":
var buf = &bytes.Buffer{} var buf = &bytes.Buffer{}
err = xlsxFile.Write(buf) err := xlsxFile.Write(buf)
if err != nil { if err != nil {
this.ErrorPage(err) this.ErrorPage(err)
return return
@@ -137,6 +130,7 @@ func (this *ExportDataAction) RunGet(params struct {
csvWriter.Flush() csvWriter.Flush()
data = csvBuffer.Bytes() data = csvBuffer.Bytes()
case "json": case "json":
var err error
data, err = json.Marshal(jsonMaps) data, err = json.Marshal(jsonMaps)
if err != nil { if err != nil {
this.ErrorPage(err) this.ErrorPage(err)

View File

@@ -6,8 +6,8 @@ import (
"bytes" "bytes"
"encoding/csv" "encoding/csv"
"encoding/json" "encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes" "github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/actions"
@@ -15,7 +15,6 @@ import (
"github.com/iwind/TeaGo/types" "github.com/iwind/TeaGo/types"
"github.com/tealeg/xlsx/v3" "github.com/tealeg/xlsx/v3"
"io" "io"
"net"
"regexp" "regexp"
"strings" "strings"
) )
@@ -79,9 +78,10 @@ func (this *ImportAction) RunPost(params struct {
var items = []*pb.IPItem{} var items = []*pb.IPItem{}
switch ext { switch ext {
case ".xlsx": case ".xlsx":
file, err := xlsx.OpenBinary(data) file, openErr := xlsx.OpenBinary(data)
if err != nil { if openErr != nil {
this.Fail("Excel读取错误" + err.Error()) this.Fail("Excel读取错误" + openErr.Error())
return
} }
if len(file.Sheets) > 0 { if len(file.Sheets) > 0 {
var sheet = file.Sheets[0] var sheet = file.Sheets[0]
@@ -136,7 +136,7 @@ func (this *ImportAction) RunPost(params struct {
if len(line) == 0 { if len(line) == 0 {
continue continue
} }
item := this.createItemFromValues(strings.SplitN(string(line), ",", 6), &countIgnore) item := this.createItemFromValues(strings.SplitN(string(line), ",", 5), &countIgnore)
if item != nil { if item != nil {
items = append(items, item) items = append(items, item)
} }
@@ -150,6 +150,7 @@ func (this *ImportAction) RunPost(params struct {
for _, item := range items { for _, item := range items {
_, err = this.RPC().IPItemRPC().CreateIPItem(this.AdminContext(), &pb.CreateIPItemRequest{ _, err = this.RPC().IPItemRPC().CreateIPItem(this.AdminContext(), &pb.CreateIPItemRequest{
IpListId: params.ListId, IpListId: params.ListId,
Value: item.Value,
IpFrom: item.IpFrom, IpFrom: item.IpFrom,
IpTo: item.IpTo, IpTo: item.IpTo,
ExpiredAt: item.ExpiredAt, ExpiredAt: item.ExpiredAt,
@@ -170,60 +171,45 @@ func (this *ImportAction) RunPost(params struct {
} }
func (this *ImportAction) createItemFromValues(values []string, countIgnore *int) *pb.IPItem { func (this *ImportAction) createItemFromValues(values []string, countIgnore *int) *pb.IPItem {
// ipFrom, ipTo, expiredAt, type, eventType, reason // value, expiredAt, type, eventType, reason
var item = &pb.IPItem{} var item = &pb.IPItem{}
switch len(values) { switch len(values) {
case 1: case 1:
item.IpFrom = values[0] item.Value = values[0]
case 2: case 2:
item.IpFrom = values[0] item.Value = values[0]
item.IpTo = values[1] item.ExpiredAt = types.Int64(values[1])
case 3: case 3:
item.IpFrom = values[0] item.Value = values[0]
item.IpTo = values[1] item.ExpiredAt = types.Int64(values[1])
item.ExpiredAt = types.Int64(values[2]) item.Type = values[2]
case 4: case 4:
item.IpFrom = values[0] item.Value = values[0]
item.IpTo = values[1] item.ExpiredAt = types.Int64(values[1])
item.ExpiredAt = types.Int64(values[2]) item.Type = values[2]
item.Type = values[3] item.EventLevel = values[3]
case 5: case 5:
item.IpFrom = values[0] item.Value = values[0]
item.IpTo = values[1] item.ExpiredAt = types.Int64(values[1])
item.ExpiredAt = types.Int64(values[2]) item.Type = values[2]
item.Type = values[3] item.EventLevel = values[3]
item.EventLevel = values[4] item.Reason = values[4]
case 6:
item.IpFrom = values[0]
item.IpTo = values[1]
item.ExpiredAt = types.Int64(values[2])
item.Type = values[3]
item.EventLevel = values[4]
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 { if len(item.EventLevel) == 0 {
item.EventLevel = "critical" item.EventLevel = "critical"
} }
if net.ParseIP(item.IpFrom) == nil { newValue, ipFrom, ipTo, ok := utils.ParseIPValue(item.Value)
*countIgnore++ if !ok {
return nil
}
if len(item.IpTo) > 0 && net.ParseIP(item.IpTo) == nil {
*countIgnore++ *countIgnore++
return nil return nil
} }
item.Value = newValue
item.IpFrom = ipFrom
item.IpTo = ipTo
return item return item
} }

View File

@@ -172,6 +172,7 @@ func (this *IndexAction) RunGet(params struct {
itemMaps = append(itemMaps, maps.Map{ itemMaps = append(itemMaps, maps.Map{
"id": item.Id, "id": item.Id,
"value": item.Value,
"ipFrom": item.IpFrom, "ipFrom": item.IpFrom,
"ipTo": item.IpTo, "ipTo": item.IpTo,
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt), "createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),

View File

@@ -118,6 +118,7 @@ func (this *ItemsAction) RunGet(params struct {
itemMaps = append(itemMaps, maps.Map{ itemMaps = append(itemMaps, maps.Map{
"id": item.Id, "id": item.Id,
"value": item.Value,
"ipFrom": item.IpFrom, "ipFrom": item.IpFrom,
"ipTo": item.IpTo, "ipTo": item.IpTo,
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt), "createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),

View File

@@ -58,6 +58,7 @@ func (this *TestAction) RunPost(params struct {
if resp.IpItem != nil { if resp.IpItem != nil {
resultMap["item"] = maps.Map{ resultMap["item"] = maps.Map{
"id": resp.IpItem.Id, "id": resp.IpItem.Id,
"value": resp.IpItem.Value,
"ipFrom": resp.IpItem.IpFrom, "ipFrom": resp.IpItem.IpFrom,
"ipTo": resp.IpItem.IpTo, "ipTo": resp.IpItem.IpTo,
"reason": resp.IpItem.Reason, "reason": resp.IpItem.Reason,

View File

@@ -1,8 +1,8 @@
package iplists package iplists
import ( import (
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/iputils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes" "github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/actions"
@@ -33,6 +33,7 @@ func (this *UpdateIPPopupAction) RunGet(params struct {
this.Data["item"] = maps.Map{ this.Data["item"] = maps.Map{
"id": item.Id, "id": item.Id,
"value": item.Value,
"ipFrom": item.IpFrom, "ipFrom": item.IpFrom,
"ipTo": item.IpTo, "ipTo": item.IpTo,
"expiredAt": item.ExpiredAt, "expiredAt": item.ExpiredAt,
@@ -49,8 +50,7 @@ func (this *UpdateIPPopupAction) RunGet(params struct {
func (this *UpdateIPPopupAction) RunPost(params struct { func (this *UpdateIPPopupAction) RunPost(params struct {
ItemId int64 ItemId int64
IpFrom string Value string
IpTo string
ExpiredAt int64 ExpiredAt int64
Reason string Reason string
Type string Type string
@@ -62,50 +62,25 @@ func (this *UpdateIPPopupAction) RunPost(params struct {
// 日志 // 日志
defer this.CreateLogInfo(codes.IPItem_LogUpdateIPItem, params.ItemId) defer this.CreateLogInfo(codes.IPItem_LogUpdateIPItem, params.ItemId)
// TODO 校验ItemId所属用户
switch params.Type { switch params.Type {
case "ipv4": case "ip":
// 校验IP格式
params.Must. params.Must.
Field("ipFrom", params.IpFrom). Field("value", params.Value).
Require("请输入开始IP") Require("请输入IP或IP段")
// 校验IP格式ipFrom/ipTo _, _, _, ok := utils.ParseIPValue(params.Value)
if !iputils.IsIPv4(params.IpFrom) { if !ok {
this.FailField("ipFrom", "请输入正确的开始IP") this.FailField("value", "请输入正确的IP格式")
} return
if len(params.IpTo) > 0 && !iputils.IsIPv4(params.IpTo) {
this.FailField("ipTo", "请输入正确的结束IP")
}
if len(params.IpTo) > 0 && iputils.CompareIP(params.IpFrom, params.IpTo) > 0 {
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
}
case "ipv6":
params.Must.
Field("ipFrom", params.IpFrom).
Require("请输入正确的开始IP")
if !iputils.IsIPv6(params.IpFrom) {
this.FailField("ipFrom", "请输入正确的IPv6地址")
}
if len(params.IpTo) > 0 && !iputils.IsIPv6(params.IpTo) {
this.FailField("ipTo", "请输入正确的IPv6地址")
}
if len(params.IpTo) > 0 && iputils.CompareIP(params.IpFrom, params.IpTo) > 0 {
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
} }
case "all": case "all":
params.IpFrom = "0.0.0.0" params.Value = "0.0.0.0"
} }
_, err := this.RPC().IPItemRPC().UpdateIPItem(this.AdminContext(), &pb.UpdateIPItemRequest{ _, err := this.RPC().IPItemRPC().UpdateIPItem(this.AdminContext(), &pb.UpdateIPItemRequest{
IpItemId: params.ItemId, IpItemId: params.ItemId,
IpFrom: params.IpFrom, Value: params.Value,
IpTo: params.IpTo,
ExpiredAt: params.ExpiredAt, ExpiredAt: params.ExpiredAt,
Reason: params.Reason, Reason: params.Reason,
Type: params.Type, Type: params.Type,

View File

@@ -109,6 +109,7 @@ func (this *AllowListAction) RunGet(params struct {
itemMaps = append(itemMaps, maps.Map{ itemMaps = append(itemMaps, maps.Map{
"id": item.Id, "id": item.Id,
"value": item.Value,
"ipFrom": item.IpFrom, "ipFrom": item.IpFrom,
"ipTo": item.IpTo, "ipTo": item.IpTo,
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt), "createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),

View File

@@ -109,6 +109,7 @@ func (this *DenyListAction) RunGet(params struct {
itemMaps = append(itemMaps, maps.Map{ itemMaps = append(itemMaps, maps.Map{
"id": item.Id, "id": item.Id,
"value": item.Value,
"ipFrom": item.IpFrom, "ipFrom": item.IpFrom,
"ipTo": item.IpTo, "ipTo": item.IpTo,
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt), "createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),

View File

@@ -70,6 +70,7 @@ func (this *TestAction) RunPost(params struct {
if resp.IpItem != nil { if resp.IpItem != nil {
resultMap["item"] = maps.Map{ resultMap["item"] = maps.Map{
"id": resp.IpItem.Id, "id": resp.IpItem.Id,
"value": resp.IpItem.Value,
"ipFrom": resp.IpItem.IpFrom, "ipFrom": resp.IpItem.IpFrom,
"ipTo": resp.IpItem.IpTo, "ipTo": resp.IpItem.IpTo,
"reason": resp.IpItem.Reason, "reason": resp.IpItem.Reason,

View File

@@ -1,8 +1,8 @@
package ipadmin package ipadmin
import ( import (
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/iputils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes" "github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/actions"
@@ -33,6 +33,7 @@ func (this *UpdateIPPopupAction) RunGet(params struct {
this.Data["item"] = maps.Map{ this.Data["item"] = maps.Map{
"id": item.Id, "id": item.Id,
"value": item.Value,
"ipFrom": item.IpFrom, "ipFrom": item.IpFrom,
"ipTo": item.IpTo, "ipTo": item.IpTo,
"expiredAt": item.ExpiredAt, "expiredAt": item.ExpiredAt,
@@ -49,8 +50,7 @@ func (this *UpdateIPPopupAction) RunGet(params struct {
func (this *UpdateIPPopupAction) RunPost(params struct { func (this *UpdateIPPopupAction) RunPost(params struct {
ItemId int64 ItemId int64
IpFrom string Value string
IpTo string
ExpiredAt int64 ExpiredAt int64
Reason string Reason string
Type string Type string
@@ -62,50 +62,25 @@ func (this *UpdateIPPopupAction) RunPost(params struct {
// 日志 // 日志
defer this.CreateLogInfo(codes.IPItem_LogUpdateIPItem, params.ItemId) defer this.CreateLogInfo(codes.IPItem_LogUpdateIPItem, params.ItemId)
// TODO 校验ItemId所属用户
switch params.Type { switch params.Type {
case "ipv4": case "ip":
// 校验IP格式
params.Must. params.Must.
Field("ipFrom", params.IpFrom). Field("value", params.Value).
Require("请输入开始IP") Require("请输入IP或IP段")
// 校验IP格式ipFrom/ipTo _, _, _, ok := utils.ParseIPValue(params.Value)
if !iputils.IsIPv4(params.IpFrom) { if !ok {
this.FailField("ipFrom", "请输入正确的开始IP") this.FailField("value", "请输入正确的IP格式")
} return
if len(params.IpTo) > 0 && !iputils.IsIPv4(params.IpTo) {
this.FailField("ipTo", "请输入正确的结束IP")
}
if len(params.IpTo) > 0 && iputils.CompareIP(params.IpFrom, params.IpTo) > 0 {
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
}
case "ipv6":
params.Must.
Field("ipFrom", params.IpFrom).
Require("请输入正确的开始IP")
if !iputils.IsIPv6(params.IpFrom) {
this.FailField("ipFrom", "请输入正确的IPv6地址")
}
if len(params.IpTo) > 0 && !iputils.IsIPv6(params.IpTo) {
this.FailField("ipTo", "请输入正确的IPv6地址")
}
if len(params.IpTo) > 0 && iputils.CompareIP(params.IpFrom, params.IpTo) > 0 {
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
} }
case "all": case "all":
params.IpFrom = "0.0.0.0" params.Value = "0.0.0.0"
} }
_, err := this.RPC().IPItemRPC().UpdateIPItem(this.AdminContext(), &pb.UpdateIPItemRequest{ _, err := this.RPC().IPItemRPC().UpdateIPItem(this.AdminContext(), &pb.UpdateIPItemRequest{
IpItemId: params.ItemId, IpItemId: params.ItemId,
IpFrom: params.IpFrom, Value: params.Value,
IpTo: params.IpTo,
ExpiredAt: params.ExpiredAt, ExpiredAt: params.ExpiredAt,
Reason: params.Reason, Reason: params.Reason,
Type: params.Type, Type: params.Type,

View File

@@ -140,6 +140,15 @@ Vue.component("datetime-input", {
resultTimestamp: function () { resultTimestamp: function () {
return this.timestamp return this.timestamp
}, },
nextYear: function () {
let date = new Date()
date.setFullYear(date.getFullYear()+1)
this.day = date.getFullYear() + "-" + this.leadingZero(date.getMonth() + 1, 2) + "-" + this.leadingZero(date.getDate(), 2)
this.hour = this.leadingZero(date.getHours(), 2)
this.minute = this.leadingZero(date.getMinutes(), 2)
this.second = this.leadingZero(date.getSeconds(), 2)
this.change()
},
nextDays: function (days) { nextDays: function (days) {
let date = new Date() let date = new Date()
date.setTime(date.getTime() + days * 86400 * 1000) date.setTime(date.getTime() + days * 86400 * 1000)
@@ -171,6 +180,6 @@ Vue.component("datetime-input", {
<div class="ui field">:</div> <div class="ui field">:</div>
<div class="ui field" :class="{error: hasSecondError}"><input type="text" v-model="second" maxlength="2" style="width:4em" placeholder="秒" @input="change"/></div> <div class="ui field" :class="{error: hasSecondError}"><input type="text" v-model="second" maxlength="2" style="width:4em" placeholder="秒" @input="change"/></div>
</div> </div>
<p class="comment">常用时间:<a href="" @click.prevent="nextHours(1)"> &nbsp;1小时&nbsp; </a> <span class="disabled">|</span> <a href="" @click.prevent="nextDays(1)"> &nbsp;1天&nbsp; </a> <span class="disabled">|</span> <a href="" @click.prevent="nextDays(3)"> &nbsp;3天&nbsp; </a> <span class="disabled">|</span> <a href="" @click.prevent="nextDays(7)"> &nbsp;1周&nbsp; </a> <span class="disabled">|</span> <a href="" @click.prevent="nextDays(30)"> &nbsp;30天&nbsp; </a> </p> <p class="comment">常用时间:<a href="" @click.prevent="nextHours(1)"> &nbsp;1小时&nbsp; </a> <span class="disabled">|</span> <a href="" @click.prevent="nextDays(1)"> &nbsp;1天&nbsp; </a> <span class="disabled">|</span> <a href="" @click.prevent="nextDays(3)"> &nbsp;3天&nbsp; </a> <span class="disabled">|</span> <a href="" @click.prevent="nextDays(7)"> &nbsp;1周&nbsp; </a> <span class="disabled">|</span> <a href="" @click.prevent="nextDays(30)"> &nbsp;30天&nbsp; </a> <span class="disabled">|</span> <a href="" @click.prevent="nextYear()"> &nbsp;1年&nbsp; </a> </p>
</div>` </div>`
}) })

View File

@@ -2,13 +2,13 @@ Vue.component("ip-item-text", {
props: ["v-item"], props: ["v-item"],
template: `<span> template: `<span>
<span v-if="vItem.type == 'all'">*</span> <span v-if="vItem.type == 'all'">*</span>
<span v-if="vItem.type == 'ipv4' || vItem.type.length == 0"> <span v-else>
{{vItem.ipFrom}} <span v-if="vItem.value != null && vItem.value.length > 0">{{vItem.value}}</span>
<span v-if="vItem.ipTo.length > 0">- {{vItem.ipTo}}</span> <span v-else>
</span> {{vItem.ipFrom}}
<span v-if="vItem.type == 'ipv6'">{{vItem.ipFrom}} <span v-if="vItem.ipTo != null &&vItem.ipTo.length > 0">- {{vItem.ipTo}}</span>
<span v-if="vItem.ipTo.length > 0">- {{vItem.ipTo}}</span> </span>
</span> </span>
<span v-if="vItem.eventLevelName != null && vItem.eventLevelName.length > 0">&nbsp; 级别:{{vItem.eventLevelName}}</span> <span v-if="vItem.eventLevelName != null && vItem.eventLevelName.length > 0">&nbsp; 级别:{{vItem.eventLevelName}}</span>
</span>` </span>`
}) })

View File

@@ -155,8 +155,12 @@ Vue.component("ip-list-table", {
</td> </td>
<td> <td>
<span v-if="item.type != 'all'" :class="{green: item.list != null && item.list.type == 'white'}"> <span v-if="item.type != 'all'" :class="{green: item.list != null && item.list.type == 'white'}">
<keyword :v-word="keyword">{{item.ipFrom}}</keyword> <span> <span class="small red" v-if="item.isRead != null && !item.isRead">&nbsp;New&nbsp;</span>&nbsp;<a :href="'/servers/iplists?ip=' + item.ipFrom" v-if="vShowSearchButton" title="搜索此IP"><span><i class="icon search small" style="color: #ccc"></i></span></a></span> <span v-if="item.value != null && item.value.length > 0"><keyword :v-word="keyword">{{item.value}}</keyword></span>
<span v-if="item.ipTo.length > 0"> - <keyword :v-word="keyword">{{item.ipTo}}</keyword></span></span> <span v-else>
<keyword :v-word="keyword">{{item.ipFrom}}</keyword> <span> <span class="small red" v-if="item.isRead != null && !item.isRead">&nbsp;New&nbsp;</span>&nbsp;<a :href="'/servers/iplists?ip=' + item.ipFrom" v-if="vShowSearchButton" title="搜索此IP"><span><i class="icon search small" style="color: #ccc"></i></span></a></span>
<span v-if="item.ipTo.length > 0"> - <keyword :v-word="keyword">{{item.ipTo}}</keyword></span>
</span>
</span>
<span v-else class="disabled">*</span> <span v-else class="disabled">*</span>
<div v-if="item.region != null && item.region.length > 0"> <div v-if="item.region != null && item.region.length > 0">

View File

@@ -22,38 +22,11 @@
</td> </td>
</tr> </tr>
<!-- IPv4 --> <tbody v-if="type != 'all'">
<tbody v-if="type == 'ipv4'">
<tr> <tr>
<td>开始IP *</td> <td>IP或IP段 *</td>
<td> <td>
<input type="text" name="ipFrom" maxlength="64" placeholder="x.x.x.x" ref="focus" v-model="item.ipFrom"/> <input type="text" name="value" maxlength="64" placeholder="x.x.x.x" ref="focus" v-model="item.value" style="width: 20em"/>
</td>
</tr>
<tr>
<td>结束IP</td>
<td>
<input type="text" name="ipTo" maxlength="64" placeholder="x.x.x.x" v-model="item.ipTo"/>
<p class="comment">只有表示IP段的时候才需要填写此项。</p>
</td>
</tr>
</tbody>
<!-- IPv6 -->
<tbody v-if="type == 'ipv6'">
<tr>
<td>开始IP *</td>
<td>
<input type="text" name="ipFrom" maxlength="64" placeholder="x:x:x:x:x:x:x:x" ref="focus" v-model="item.ipFrom"/>
<p class="comment">IPv6地址比如 1406:3c00:0:2409:13:58:103:15</p>
</td>
</tr>
<tr>
<td>结束IP</td>
<td>
<input type="text" name="ipTo" maxlength="64" placeholder="x:x:x:x:x:x:x:x" ref="focus" v-model="item.ipTo"/>
<p class="comment">只有表示IP段的时候才需要填写此项。</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>

View File

@@ -21,37 +21,11 @@
</td> </td>
</tr> </tr>
<!-- IPv4 --> <tbody v-if="type != 'all'">
<tbody v-if="type == 'ipv4'">
<tr> <tr>
<td>开始IP *</td> <td>IP或IP段 *</td>
<td> <td>
<input type="text" name="ipFrom" maxlength="64" placeholder="x.x.x.x" ref="focus" v-model="item.ipFrom"/> <input type="text" name="value" maxlength="64" placeholder="x.x.x.x" ref="focus" v-model="item.value" style="width: 20em"/>
</td>
</tr>
<tr>
<td>结束IP</td>
<td>
<input type="text" name="ipTo" maxlength="64" placeholder="x.x.x.x" v-model="item.ipTo"/>
<p class="comment">只有表示IP段的时候才需要填写此项。</p>
</td>
</tr>
</tbody>
<!-- IPv6 -->
<tbody v-if="type == 'ipv6'">
<tr>
<td>开始IP *</td>
<td>
<input type="text" name="ipFrom" maxlength="64" placeholder="x:x:x:x:x:x:x:x" ref="focus" v-model="item.ipFrom"/>
<p class="comment">IPv6地址比如 1406:3c00:0:2409:13:58:103:15</p>
</td>
</tr>
<tr>
<td>结束IP</td>
<td>
<input type="text" name="ipTo" maxlength="64" placeholder="x:x:x:x:x:x:x:x" ref="focus" v-model="item.ipTo"/>
<p class="comment">只有表示IP段的时候才需要填写此项。</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>

View File

@@ -11,12 +11,10 @@
<td class="title">类型 *</td> <td class="title">类型 *</td>
<td> <td>
<select class="ui dropdown auto-width" name="type" v-model="type"> <select class="ui dropdown auto-width" name="type" v-model="type">
<option value="ipv4">IPv4</option> <option value="ip">单IP或IP段</option>
<option value="ipv6">IPv6</option>
<option value="all">所有IP</option> <option value="all">所有IP</option>
</select> </select>
<p class="comment" v-if="type == 'ipv4'">单个IPv4或一个IPv4范围。</p> <p class="comment" v-if="type == 'ip'">单个IP或一个IP范围。</p>
<p class="comment" v-if="type == 'ipv6'">单个IPv6或一个IPv6范围。</p>
<p class="comment" v-if="type == 'all'">允许或禁用所有的IP。</p> <p class="comment" v-if="type == 'all'">允许或禁用所有的IP。</p>
</td> </td>
</tr> </tr>
@@ -30,60 +28,23 @@
</tr> </tr>
<!-- 单个添加 --> <!-- 单个添加 -->
<!-- IPv4 --> <tbody v-if="method == 'single' && type == 'ip'">
<tbody v-if="method == 'single' && type == 'ipv4'">
<tr> <tr>
<td>开始IP *</td> <td>IP或IP段 *</td>
<td> <td>
<input type="text" name="ipFrom" maxlength="64" placeholder="x.x.x.x" ref="focus" style="width: 10em"/> <input type="text" name="value" maxlength="64" placeholder="x.x.x.x" ref="focus" style="width: 20em"/>
</td> <p class="comment">支持IPv4和IPv6支持三种格式单个IP比如192.168.1.100、IP范围比如192.168.1.1-192.168.1.255、CIDR比如192.168.1.1/24</p>
</tr>
<tr>
<td>结束IP</td>
<td>
<input type="text" name="ipTo" maxlength="64" placeholder="x.x.x.x" style="width: 10em"/>
<p class="comment">只有表示IP段的时候才需要填写此项。</p>
</td>
</tr>
</tbody>
<!-- IPv6 -->
<tbody v-if="method == 'single' && type == 'ipv6'">
<tr>
<td>开始IP *</td>
<td>
<input type="text" name="ipFrom" maxlength="64" placeholder="x:x:x:x:x:x:x:x" ref="focus" style="width: 20em"/>
<p class="comment">IPv6地址比如 1406:3c00:0:2409:13:58:103:15</p>
</td>
</tr>
<tr>
<td>结束IP</td>
<td>
<input type="text" name="ipTo" maxlength="64" placeholder="x:x:x:x:x:x:x:x" ref="focus" style="width: 20em"/>
<p class="comment">只有表示IP段的时候才需要填写此项。</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
<!-- 批量添加 --> <!-- 批量添加 -->
<!-- IPv4 --> <tbody v-if="method == 'batch' && type == 'ip'">
<tbody v-if="method == 'batch' && type == 'ipv4'">
<tr> <tr>
<td>IP列表</td> <td>IP列表</td>
<td> <td>
<textarea name="ipData" style="width: 20em" :placeholder="'x.x.x.x' + '\n'+ 'x.x.x.x/24' + '\n' + 'x.x.x.x-y.y.y.y'" rows="3"></textarea> <textarea name="ipData" style="width: 20em" :placeholder="'x.x.x.x' + '\n' + 'x.x.x.x/24' + '\n' + 'x.x.x.x-y.y.y.y'" rows="3"></textarea>
<p class="comment">每行一个IP支持三种格式<code-label :class="'grey'">192.168.1.1</code-label><code-label :class="'grey'">192.168.1.1/24</code-label><code-label :class="'grey'">192.168.1.1-192.168.1.255</code-label></p> <p class="comment">每行一个IP支持三种格式<code-label :class="'grey'">192.168.1.100</code-label><code-label :class="'grey'">192.168.1.1-192.168.1.255</code-label><code-label :class="'grey'">192.168.1.1/24</code-label></p>
</td>
</tr>
</tbody>
<!-- IPv6 -->
<tbody v-if="method == 'batch' && type == 'ipv6'">
<tr>
<td>IP列表</td>
<td>
<textarea name="ipData" style="width: 20em" :placeholder="'x:x:x:x:x:x:x:x'" rows="3"></textarea>
<p class="comment">每行一个IP。</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>

View File

@@ -1,5 +1,5 @@
Tea.context(function () { Tea.context(function () {
this.type = "ipv4" this.type = "ip"
this.eventLevel = (this.listType == "white") ? "debug" : "critical" this.eventLevel = (this.listType == "white") ? "debug" : "critical"
this.method = "single" this.method = "single"
}) })

View File

@@ -7,7 +7,7 @@
<table class="ui table definition selectable"> <table class="ui table definition selectable">
<tr> <tr>
<td class="title">说明</td> <td class="title">说明</td>
<td>导出所有的IP</td> <td>导出所有的IP并以文件格式下载。注意v1.3.5版本及以后导出的数据不能在之前的版本中导入。</td>
</tr> </tr>
<tr> <tr>
<td>格式</td> <td>格式</td>

View File

@@ -21,7 +21,7 @@
<div v-if="result.isFound"> <div v-if="result.isFound">
<div v-if="result.item != null"> <div v-if="result.item != null">
<div v-if="result.isAllowed"> <div v-if="result.isAllowed">
<span class="green">在白名单中 <ip-item-text :v-item="result.item"></ip-item-text>&nbsp;<a href="" @click.prevent="updateItem(result.list.id, result.item.id)" title="查看和修改"><i class="icon pencil small"></i></a></span> <span class="green">在白名单中 <ip-item-text :v-item="result.item"></ip-item-text>&nbsp;<a href="" @click.prevent="updateItem(result.item.id)" title="查看和修改"><i class="icon pencil small"></i></a></span>
</div> </div>
<div v-else> <div v-else>
<span class="red">在黑名单中 <ip-item-text :v-item="result.item"></ip-item-text>&nbsp;<a href="" @click.prevent="updateItem(result.item.id)" title="查看和修改"><i class="icon pencil small"></i></a></span> <span class="red">在黑名单中 <ip-item-text :v-item="result.item"></ip-item-text>&nbsp;<a href="" @click.prevent="updateItem(result.item.id)" title="查看和修改"><i class="icon pencil small"></i></a></span>

View File

@@ -21,37 +21,11 @@
</td> </td>
</tr> </tr>
<!-- IPv4 --> <tbody v-if="type != 'all'">
<tbody v-if="type == 'ipv4'">
<tr> <tr>
<td>开始IP *</td> <td>IP或IP段 *</td>
<td> <td>
<input type="text" name="ipFrom" maxlength="64" placeholder="x.x.x.x" ref="focus" v-model="item.ipFrom"/> <input type="text" name="value" maxlength="64" placeholder="x.x.x.x" ref="focus" v-model="item.value" style="width: 20em"/>
</td>
</tr>
<tr>
<td>结束IP</td>
<td>
<input type="text" name="ipTo" maxlength="64" placeholder="x.x.x.x" v-model="item.ipTo"/>
<p class="comment">只有表示IP段的时候才需要填写此项。</p>
</td>
</tr>
</tbody>
<!-- IPv6 -->
<tbody v-if="type == 'ipv6'">
<tr>
<td>开始IP *</td>
<td>
<input type="text" name="ipFrom" maxlength="64" placeholder="x:x:x:x:x:x:x:x" ref="focus" v-model="item.ipFrom"/>
<p class="comment">IPv6地址比如 1406:3c00:0:2409:13:58:103:15</p>
</td>
</tr>
<tr>
<td>结束IP</td>
<td>
<input type="text" name="ipTo" maxlength="64" placeholder="x:x:x:x:x:x:x:x" ref="focus" v-model="item.ipTo"/>
<p class="comment">只有表示IP段的时候才需要填写此项。</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>

View File

@@ -22,36 +22,11 @@
</tr> </tr>
<!-- IPv4 --> <!-- IPv4 -->
<tbody v-if="type == 'ipv4'"> <tbody v-if="type != 'all'">
<tr> <tr>
<td>开始IP *</td> <td>IP或IP段 *</td>
<td> <td>
<input type="text" name="ipFrom" maxlength="64" placeholder="x.x.x.x" ref="focus" v-model="item.ipFrom"/> <input type="text" name="value" maxlength="64" placeholder="x.x.x.x" ref="focus" v-model="item.value" style="width: 20em"/>
</td>
</tr>
<tr>
<td>结束IP</td>
<td>
<input type="text" name="ipTo" maxlength="64" placeholder="x.x.x.x" v-model="item.ipTo"/>
<p class="comment">只有表示IP段的时候才需要填写此项。</p>
</td>
</tr>
</tbody>
<!-- IPv6 -->
<tbody v-if="type == 'ipv6'">
<tr>
<td>开始IP *</td>
<td>
<input type="text" name="ipFrom" maxlength="64" placeholder="x:x:x:x:x:x:x:x" ref="focus" v-model="item.ipFrom"/>
<p class="comment">IPv6地址比如 1406:3c00:0:2409:13:58:103:15</p>
</td>
</tr>
<tr>
<td>结束IP</td>
<td>
<input type="text" name="ipTo" maxlength="64" placeholder="x:x:x:x:x:x:x:x" ref="focus" v-model="item.ipTo"/>
<p class="comment">只有表示IP段的时候才需要填写此项。</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>