mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-04-26 07:05:19 +08:00
IPBox把IP加入黑名单可以选择过期时间/可以从已经添加的名单中删除/已经添加的名单中显示过期时间
This commit is contained in:
@@ -14,19 +14,30 @@ type AddIPAction struct {
|
||||
}
|
||||
|
||||
func (this *AddIPAction) RunPost(params struct {
|
||||
ListId int64
|
||||
Ip string
|
||||
ListId int64
|
||||
Ip string
|
||||
ExpiredAt int64
|
||||
}) {
|
||||
var itemId int64 = 0
|
||||
|
||||
defer func() {
|
||||
this.CreateLogInfo("在名单 %d 中创建IP %d", params.ListId, itemId)
|
||||
}()
|
||||
|
||||
var ipType = "ipv4"
|
||||
if strings.Contains(params.Ip, ":") {
|
||||
ipType = "ipv6"
|
||||
}
|
||||
|
||||
_, err := this.RPC().IPItemRPC().CreateIPItem(this.AdminContext(), &pb.CreateIPItemRequest{
|
||||
if params.ExpiredAt <= 0 {
|
||||
params.ExpiredAt = time.Now().Unix() + 86400
|
||||
}
|
||||
|
||||
createResp, err := this.RPC().IPItemRPC().CreateIPItem(this.AdminContext(), &pb.CreateIPItemRequest{
|
||||
IpListId: params.ListId,
|
||||
IpFrom: params.Ip,
|
||||
IpTo: "",
|
||||
ExpiredAt: time.Now().Unix() + 86400, // TODO 可以自定义时间
|
||||
ExpiredAt: params.ExpiredAt,
|
||||
Reason: "从IPBox中加入名单",
|
||||
Type: ipType,
|
||||
EventLevel: "critical",
|
||||
@@ -36,5 +47,7 @@ func (this *AddIPAction) RunPost(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
itemId = createResp.IpItemId
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
27
internal/web/actions/default/servers/ipbox/deleteFromList.go
Normal file
27
internal/web/actions/default/servers/ipbox/deleteFromList.go
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package ipbox
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type DeleteFromListAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteFromListAction) RunPost(params struct {
|
||||
ListId int64
|
||||
ItemId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo("从IP名单 %d 中删除IP %d", params.ListId, params.ItemId)
|
||||
|
||||
_, err := this.RPC().IPItemRPC().DeleteIPItem(this.AdminContext(), &pb.DeleteIPItemRequest{IpItemId: params.ItemId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -37,17 +37,44 @@ func (this *IndexAction) RunGet(params struct {
|
||||
this.Data["isp"] = regionResp.IpRegion.Isp
|
||||
|
||||
// IP列表
|
||||
ipListResp, err := this.RPC().IPListRPC().FindEnabledIPListContainsIP(this.AdminContext(), &pb.FindEnabledIPListContainsIPRequest{Ip: params.Ip})
|
||||
ipListResp, err := this.RPC().IPListRPC().FindEnabledIPListContainsIP(this.AdminContext(), &pb.FindEnabledIPListContainsIPRequest{
|
||||
Ip: params.Ip,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var ipListMaps = []maps.Map{}
|
||||
for _, ipList := range ipListResp.IpLists {
|
||||
itemsResp, err := this.RPC().IPItemRPC().ListIPItemsWithListId(this.AdminContext(), &pb.ListIPItemsWithListIdRequest{
|
||||
IpListId: ipList.Id,
|
||||
Keyword: "",
|
||||
IpFrom: params.Ip,
|
||||
IpTo: "",
|
||||
Offset: 0,
|
||||
Size: 1,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var items = itemsResp.IpItems
|
||||
if len(items) == 0 {
|
||||
continue
|
||||
}
|
||||
var item = items[0]
|
||||
|
||||
var expiredTime = ""
|
||||
if item.ExpiredAt > 0 {
|
||||
expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt)
|
||||
}
|
||||
|
||||
ipListMaps = append(ipListMaps, maps.Map{
|
||||
"id": ipList.Id,
|
||||
"name": ipList.Name,
|
||||
"type": ipList.Type,
|
||||
"id": ipList.Id,
|
||||
"name": ipList.Name,
|
||||
"type": ipList.Type,
|
||||
"itemExpiredTime": expiredTime,
|
||||
"itemId": item.Id,
|
||||
})
|
||||
}
|
||||
this.Data["ipLists"] = ipListMaps
|
||||
@@ -58,7 +85,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
IsPublic: true,
|
||||
Keyword: "",
|
||||
Offset: 0,
|
||||
Size: 10, // TODO 将来考虑到支持更多的黑名单
|
||||
Size: 20, // TODO 将来考虑到支持更多的黑名单
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
|
||||
@@ -15,6 +15,7 @@ func init() {
|
||||
Prefix("/servers/ipbox").
|
||||
Get("", new(IndexAction)).
|
||||
Post("/addIP", new(AddIPAction)).
|
||||
Post("/deleteFromList", new(DeleteFromListAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user