mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-04 05:00:25 +08:00
实现公用的IP名单
This commit is contained in:
52
internal/web/actions/default/servers/iplists/utils.go
Normal file
52
internal/web/actions/default/servers/iplists/utils.go
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package iplists
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
func InitIPList(action *actionutils.ParentAction, listId int64) error {
|
||||
client, err := rpc.SharedRPC()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
listResp, err := client.IPListRPC().FindEnabledIPList(action.AdminContext(), &pb.FindEnabledIPListRequest{IpListId: listId})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
list := listResp.IpList
|
||||
if list == nil {
|
||||
return errors.New("not found")
|
||||
}
|
||||
|
||||
var typeName = ""
|
||||
switch list.Type {
|
||||
case "black":
|
||||
typeName = "黑名单"
|
||||
case "white":
|
||||
typeName = "白名单"
|
||||
}
|
||||
|
||||
// IP数量
|
||||
countItemsResp, err := client.IPItemRPC().CountIPItemsWithListId(action.AdminContext(), &pb.CountIPItemsWithListIdRequest{IpListId: listId})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
countItems := countItemsResp.Count
|
||||
|
||||
action.Data["list"] = maps.Map{
|
||||
"id": list.Id,
|
||||
"name": list.Name,
|
||||
"type": list.Type,
|
||||
"typeName": typeName,
|
||||
"description": list.Description,
|
||||
"isOn": list.IsOn,
|
||||
"countItems": countItems,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user