Files
EdgeAdmin/internal/web/actions/default/servers/iplists/test.go

78 lines
1.8 KiB
Go
Raw Normal View History

2021-06-23 13:12:33 +08:00
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package iplists
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type TestAction struct {
actionutils.ParentAction
}
func (this *TestAction) Init() {
this.Nav("", "", "test")
}
func (this *TestAction) RunGet(params struct {
ListId int64
}) {
err := InitIPList(this.Parent(), params.ListId)
if err != nil {
this.ErrorPage(err)
return
}
this.Show()
}
func (this *TestAction) RunPost(params struct {
ListId int64
Ip string
Must *actions.Must
CSRF *actionutils.CSRF
}) {
resp, err := this.RPC().IPItemRPC().CheckIPItemStatus(this.AdminContext(), &pb.CheckIPItemStatusRequest{
IpListId: params.ListId,
Ip: params.Ip,
})
if err != nil {
this.ErrorPage(err)
return
}
2024-05-05 20:20:43 +08:00
var resultMap = maps.Map{
2021-06-23 13:12:33 +08:00
"isDone": true,
"isFound": resp.IsFound,
"isOk": resp.IsOk,
"error": resp.Error,
"isAllowed": resp.IsAllowed,
}
if resp.IpItem != nil {
resultMap["item"] = maps.Map{
"id": resp.IpItem.Id,
"value": resp.IpItem.Value,
2021-06-23 13:12:33 +08:00
"ipFrom": resp.IpItem.IpFrom,
"ipTo": resp.IpItem.IpTo,
"reason": resp.IpItem.Reason,
"expiredAt": resp.IpItem.ExpiredAt,
"createdTime": timeutil.FormatTime("Y-m-d", resp.IpItem.CreatedAt),
2021-06-23 13:12:33 +08:00
"expiredTime": timeutil.FormatTime("Y-m-d H:i:s", resp.IpItem.ExpiredAt),
"type": resp.IpItem.Type,
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(resp.IpItem.EventLevel),
2024-05-05 20:20:43 +08:00
"listType": resp.IpItem.ListType,
2021-06-23 13:12:33 +08:00
}
}
this.Data["result"] = resultMap
this.Success()
}