This commit is contained in:
unknown
2026-02-04 20:27:13 +08:00
commit 3b042d1dad
9410 changed files with 1488147 additions and 0 deletions

View File

@@ -0,0 +1,140 @@
package waf
import (
"encoding/json"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "")
}
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
if !this.ValidateFeature(userconfigs.UserFeatureCodeServerWAF, params.ServerId) {
return
}
this.Data["serverId"] = params.ServerId
this.Data["path"] = this.Request.URL.Path
// 所有的服务列表
serversResp, err := this.RPC().ServerRPC().ListEnabledServersMatch(this.UserContext(), &pb.ListEnabledServersMatchRequest{
Offset: 0,
Size: 100, // 我们这里最多显示前100个
ServerGroupId: 0,
Keyword: "",
ProtocolFamily: "http",
UserId: this.UserId(),
IgnoreSSLCerts: true,
})
if err != nil {
this.ErrorPage(err)
return
}
serverMaps := []maps.Map{}
for _, server := range serversResp.Servers {
if !server.IsOn {
continue
}
// 域名列表
serverNames := []*serverconfigs.ServerNameConfig{}
if server.IsAuditing || (server.AuditingResult != nil && !server.AuditingResult.IsOk) {
server.ServerNamesJSON = server.AuditingServerNamesJSON
}
if len(server.ServerNamesJSON) > 0 {
err = json.Unmarshal(server.ServerNamesJSON, &serverNames)
if err != nil {
this.ErrorPage(err)
return
}
}
if len(serverNames) == 0 {
continue
}
serverName := server.Name
if len(serverNames) > 0 {
if len(serverNames[0].SubNames) == 0 {
serverName = serverNames[0].Name
} else {
serverName = serverNames[0].SubNames[0]
}
}
serverMaps = append(serverMaps, maps.Map{
"id": server.Id,
"serverName": serverName,
})
}
this.Data["servers"] = serverMaps
// 统计数据
resp, err := this.RPC().ServerHTTPFirewallDailyStatRPC().ComposeServerHTTPFirewallDashboard(this.UserContext(), &pb.ComposeServerHTTPFirewallDashboardRequest{
Day: timeutil.Format("Ymd"),
UserId: this.UserId(),
ServerId: params.ServerId,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["countDailyLog"] = resp.CountDailyLog
this.Data["countDailyBlock"] = resp.CountDailyBlock
this.Data["countDailyCaptcha"] = resp.CountDailyCaptcha
this.Data["countWeeklyBlock"] = resp.CountWeeklyBlock
this.Data["countMonthlyBlock"] = resp.CountMonthlyBlock
// 分组
groupStatMaps := []maps.Map{}
for _, group := range resp.HttpFirewallRuleGroups {
groupStatMaps = append(groupStatMaps, maps.Map{
"group": maps.Map{
"id": group.HttpFirewallRuleGroup.Id,
"name": group.HttpFirewallRuleGroup.Name,
},
"count": group.Count,
})
}
this.Data["groupStats"] = groupStatMaps
// 每日趋势
logStatMaps := []maps.Map{}
blockStatMaps := []maps.Map{}
captchaStatMaps := []maps.Map{}
for _, stat := range resp.LogDailyStats {
logStatMaps = append(logStatMaps, maps.Map{
"day": stat.Day,
"count": stat.Count,
})
}
for _, stat := range resp.BlockDailyStats {
blockStatMaps = append(blockStatMaps, maps.Map{
"day": stat.Day,
"count": stat.Count,
})
}
for _, stat := range resp.CaptchaDailyStats {
captchaStatMaps = append(captchaStatMaps, maps.Map{
"day": stat.Day,
"count": stat.Count,
})
}
this.Data["logDailyStats"] = logStatMaps
this.Data["blockDailyStats"] = blockStatMaps
this.Data["captchaDailyStats"] = captchaStatMaps
this.Show()
}

View File

@@ -0,0 +1,17 @@
package waf
import (
"github.com/TeaOSLab/EdgeUser/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth("")).
Data("teaMenu", "waf").
Prefix("/waf").
Get("", new(IndexAction)).
EndAll()
})
}

View File

@@ -0,0 +1,28 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package iplists
import (
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
)
type DeleteAction struct {
actionutils.ParentAction
}
func (this *DeleteAction) RunPost(params struct {
ListId int64
}) {
defer this.CreateLogInfo(codes.IPList_LogDeleteIPList, params.ListId)
// 删除
_, err := this.RPC().IPListRPC().DeleteIPList(this.UserContext(), &pb.DeleteIPListRequest{IpListId: params.ListId})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,26 @@
package iplists
import (
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
)
type DeleteIPAction struct {
actionutils.ParentAction
}
func (this *DeleteIPAction) RunPost(params struct {
ItemId int64
}) {
// 日志
defer this.CreateLogInfo(codes.IPItem_LogDeleteIPItem, 0, params.ItemId)
_, err := this.RPC().IPItemRPC().DeleteIPItem(this.UserContext(), &pb.DeleteIPItemRequest{IpItemId: params.ItemId})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,38 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package iplists
import (
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/types"
"strings"
)
type DeleteItemsAction struct {
actionutils.ParentAction
}
func (this *DeleteItemsAction) RunPost(params struct {
ItemIds []int64
}) {
if len(params.ItemIds) == 0 {
this.Success()
}
var itemIdStrings = []string{}
for _, itemId := range params.ItemIds {
itemIdStrings = append(itemIdStrings, types.String(itemId))
}
defer this.CreateLogInfo(codes.IPList_LogDeleteIPBatch, strings.Join(itemIdStrings, ", "))
_, err := this.RPC().IPItemRPC().DeleteIPItems(this.UserContext(), &pb.DeleteIPItemsRequest{IpItemIds: params.ItemIds})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,198 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package iplists
import (
"github.com/TeaOSLab/EdgeCommon/pkg/iplibrary"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
"time"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "index")
}
func (this *IndexAction) RunGet(params struct {
Keyword string
GlobalOnly bool
Unread bool
EventLevel string
ListType string
}) {
this.Data["type"] = ""
this.Data["keyword"] = params.Keyword
this.Data["globalOnly"] = params.GlobalOnly
this.Data["unread"] = params.Unread
this.Data["eventLevel"] = params.EventLevel
this.Data["listType"] = params.ListType
countUnreadResp, err := this.RPC().IPItemRPC().CountAllEnabledIPItems(this.UserContext(), &pb.CountAllEnabledIPItemsRequest{
Keyword: params.Keyword,
GlobalOnly: params.GlobalOnly,
Unread: true,
EventLevel: params.EventLevel,
ListType: params.ListType,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["countUnread"] = countUnreadResp.Count
countResp, err := this.RPC().IPItemRPC().CountAllEnabledIPItems(this.UserContext(), &pb.CountAllEnabledIPItemsRequest{
Keyword: params.Keyword,
GlobalOnly: params.GlobalOnly,
Unread: params.Unread,
EventLevel: params.EventLevel,
ListType: params.ListType,
})
if err != nil {
this.ErrorPage(err)
return
}
var count = countResp.Count
var page = this.NewPage(count)
this.Data["page"] = page.AsHTML()
itemsResp, err := this.RPC().IPItemRPC().ListAllEnabledIPItems(this.UserContext(), &pb.ListAllEnabledIPItemsRequest{
Keyword: params.Keyword,
GlobalOnly: params.GlobalOnly,
Unread: params.Unread,
EventLevel: params.EventLevel,
ListType: params.ListType,
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
var itemMaps = []maps.Map{}
for _, result := range itemsResp.Results {
var item = result.IpItem
expiredTime := ""
if item.ExpiredAt > 0 {
expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt)
}
// policy
var sourcePolicyMap = maps.Map{"id": 0}
if item.SourceHTTPFirewallPolicy != nil {
sourcePolicyMap = maps.Map{
"id": item.SourceHTTPFirewallPolicy.Id,
"name": item.SourceHTTPFirewallPolicy.Name,
"serverId": item.SourceHTTPFirewallPolicy.ServerId,
}
}
// group
var sourceGroupMap = maps.Map{"id": 0}
if item.SourceHTTPFirewallRuleGroup != nil {
sourceGroupMap = maps.Map{
"id": item.SourceHTTPFirewallRuleGroup.Id,
"name": item.SourceHTTPFirewallRuleGroup.Name,
}
}
// set
var sourceSetMap = maps.Map{"id": 0}
if item.SourceHTTPFirewallRuleSet != nil {
sourceSetMap = maps.Map{
"id": item.SourceHTTPFirewallRuleSet.Id,
"name": item.SourceHTTPFirewallRuleSet.Name,
}
}
// server
var sourceServerMap = maps.Map{"id": 0}
if item.SourceServer != nil {
sourceServerMap = maps.Map{
"id": item.SourceServer.Id,
"name": item.SourceServer.Name,
}
}
// IP名单
var listMap = maps.Map{"id": 0}
if result.IpList != nil {
listMap = maps.Map{
"id": result.IpList.Id,
"name": result.IpList.Name,
"type": result.IpList.Type,
}
}
// policy
var policyMap = maps.Map{"id": 0}
if result.HttpFirewallPolicy != nil {
policyMap = maps.Map{
"id": result.HttpFirewallPolicy.Id,
"name": result.HttpFirewallPolicy.Name,
}
if result.Server != nil {
policyMap["server"] = maps.Map{"id": result.Server.Id, "name": result.Server.Name}
}
}
// node
var sourceNodeMap = maps.Map{"id": 0}
if item.SourceNode != nil && item.SourceNode.NodeCluster != nil {
sourceNodeMap = maps.Map{
"id": item.SourceNode.Id,
"name": item.SourceNode.Name,
"clusterId": item.SourceNode.NodeCluster.Id,
}
}
// 区域 & ISP
var region = ""
var isp = ""
if len(item.IpFrom) > 0 && len(item.IpTo) == 0 {
var ipRegion = iplibrary.LookupIP(item.IpFrom)
if ipRegion != nil && ipRegion.IsOk() {
region = ipRegion.RegionSummary()
isp = ipRegion.ProviderName()
}
}
itemMaps = append(itemMaps, maps.Map{
"id": item.Id,
"value": item.Value,
"ipFrom": item.IpFrom,
"ipTo": item.IpTo,
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),
"isExpired": item.ExpiredAt < time.Now().Unix(),
"expiredTime": expiredTime,
"reason": item.Reason,
"type": item.Type,
"isRead": item.IsRead,
"lifeSeconds": item.ExpiredAt - time.Now().Unix(),
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(item.EventLevel),
"sourcePolicy": sourcePolicyMap,
"sourceGroup": sourceGroupMap,
"sourceSet": sourceSetMap,
"sourceServer": sourceServerMap,
"sourceNode": sourceNodeMap,
"list": listMap,
"policy": policyMap,
"region": region,
"isp": isp,
})
}
this.Data["items"] = itemMaps
// 所有级别
this.Data["eventLevels"] = firewallconfigs.FindAllFirewallEventLevels()
this.Show()
}

View File

@@ -0,0 +1,45 @@
package iplists
import (
"github.com/TeaOSLab/EdgeUser/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth("")).
Data("teaMenu", "waf").
Data("teaSubMenu", "iplist").
Prefix("/waf/iplists").
Get("", new(IndexAction)).
//Get("/lists", new(ListsAction)).
//GetPost("/createPopup", new(CreatePopupAction)).
Get("/list", new(ListAction)).
//GetPost("/import", new(ImportAction)).
//GetPost("/export", new(ExportAction)).
//Get("/exportData", new(ExportDataAction)).
Post("/delete", new(DeleteAction)).
Post("/deleteItems", new(DeleteItemsAction)).
//GetPost("/test", new(TestAction)).
//GetPost("/update", new(UpdateAction)).
Get("/items", new(ItemsAction)).
//Get("/selectPopup", new(SelectPopupAction)).
// IP相关
//GetPost("/createIPPopup", new(CreateIPPopupAction)).
//GetPost("/updateIPPopup", new(UpdateIPPopupAction)).
Post("/deleteIP", new(DeleteIPAction)).
//Get("/accessLogsPopup", new(AccessLogsPopupAction)).
Post("/readAll", new(ReadAllAction)).
// 防火墙
//GetPost("/bindHTTPFirewallPopup", new(BindHTTPFirewallPopupAction)).
//Post("/unbindHTTPFirewall", new(UnbindHTTPFirewallAction)).
//Post("/httpFirewall", new(HttpFirewallAction)).
// 选项数据
Post("/levelOptions", new(LevelOptionsAction)).
EndAll()
})
}

View File

@@ -0,0 +1,144 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package iplists
import (
"github.com/TeaOSLab/EdgeCommon/pkg/iplibrary"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
"time"
)
type ItemsAction struct {
actionutils.ParentAction
}
func (this *ItemsAction) Init() {
this.Nav("", "", "item")
}
func (this *ItemsAction) RunGet(params struct {
ListId int64
Keyword string
EventLevel string
}) {
this.Data["keyword"] = params.Keyword
this.Data["eventLevel"] = params.EventLevel
err := InitIPList(this.Parent(), params.ListId)
if err != nil {
this.ErrorPage(err)
return
}
// 数量
var listId = params.ListId
countResp, err := this.RPC().IPItemRPC().CountIPItemsWithListId(this.UserContext(), &pb.CountIPItemsWithListIdRequest{
IpListId: listId,
Keyword: params.Keyword,
EventLevel: params.EventLevel,
})
if err != nil {
this.ErrorPage(err)
return
}
count := countResp.Count
page := this.NewPage(count)
this.Data["page"] = page.AsHTML()
// 列表
itemsResp, err := this.RPC().IPItemRPC().ListIPItemsWithListId(this.UserContext(), &pb.ListIPItemsWithListIdRequest{
IpListId: listId,
Keyword: params.Keyword,
EventLevel: params.EventLevel,
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
itemMaps := []maps.Map{}
for _, item := range itemsResp.IpItems {
expiredTime := ""
if item.ExpiredAt > 0 {
expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt)
}
// policy
var sourcePolicyMap = maps.Map{"id": 0}
if item.SourceHTTPFirewallPolicy != nil {
sourcePolicyMap = maps.Map{
"id": item.SourceHTTPFirewallPolicy.Id,
"name": item.SourceHTTPFirewallPolicy.Name,
"serverId": item.SourceHTTPFirewallPolicy.ServerId,
}
}
// group
var sourceGroupMap = maps.Map{"id": 0}
if item.SourceHTTPFirewallRuleGroup != nil {
sourceGroupMap = maps.Map{
"id": item.SourceHTTPFirewallRuleGroup.Id,
"name": item.SourceHTTPFirewallRuleGroup.Name,
}
}
// set
var sourceSetMap = maps.Map{"id": 0}
if item.SourceHTTPFirewallRuleSet != nil {
sourceSetMap = maps.Map{
"id": item.SourceHTTPFirewallRuleSet.Id,
"name": item.SourceHTTPFirewallRuleSet.Name,
}
}
// server
var sourceServerMap = maps.Map{"id": 0}
if item.SourceServer != nil {
sourceServerMap = maps.Map{
"id": item.SourceServer.Id,
"name": item.SourceServer.Name,
}
}
// 区域 & ISP
var region = ""
var isp = ""
if len(item.IpFrom) > 0 && len(item.IpTo) == 0 {
var ipRegion = iplibrary.LookupIP(item.IpFrom)
if ipRegion != nil && ipRegion.IsOk() {
region = ipRegion.RegionSummary()
isp = ipRegion.ProviderName()
}
}
itemMaps = append(itemMaps, maps.Map{
"id": item.Id,
"value": item.Value,
"ipFrom": item.IpFrom,
"ipTo": item.IpTo,
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),
"expiredTime": expiredTime,
"reason": item.Reason,
"type": item.Type,
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(item.EventLevel),
"sourcePolicy": sourcePolicyMap,
"sourceGroup": sourceGroupMap,
"sourceSet": sourceSetMap,
"sourceServer": sourceServerMap,
"lifeSeconds": item.ExpiredAt - time.Now().Unix(),
"region": region,
"isp": isp,
})
}
this.Data["items"] = itemMaps
// 所有级别
this.Data["eventLevels"] = firewallconfigs.FindAllFirewallEventLevels()
this.Show()
}

View File

@@ -0,0 +1,18 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package iplists
import (
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
)
type LevelOptionsAction struct {
actionutils.ParentAction
}
func (this *LevelOptionsAction) RunPost(params struct{}) {
this.Data["levels"] = firewallconfigs.FindAllFirewallEventLevels()
this.Success()
}

View File

@@ -0,0 +1,25 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package iplists
import "github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
type ListAction struct {
actionutils.ParentAction
}
func (this *ListAction) Init() {
this.Nav("", "", "list")
}
func (this *ListAction) RunGet(params struct {
ListId int64
}) {
err := InitIPList(this.Parent(), params.ListId)
if err != nil {
this.ErrorPage(err)
return
}
this.Show()
}

View File

@@ -0,0 +1,25 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package iplists
import (
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
)
type ReadAllAction struct {
actionutils.ParentAction
}
func (this *ReadAllAction) RunPost(params struct{}) {
defer this.CreateLogInfo(codes.IPItem_LogReadAllIPItems)
_, err := this.RPC().IPItemRPC().UpdateIPItemsRead(this.UserContext(), &pb.UpdateIPItemsReadRequest{})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,56 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package iplists
import (
"errors"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ipconfigs"
"github.com/TeaOSLab/EdgeUser/internal/rpc"
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
"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.UserContext(), &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 ipconfigs.IPListTypeBlack:
typeName = "黑名单"
case ipconfigs.IPListTypeWhite:
typeName = "白名单"
case ipconfigs.IPListTypeGrey:
typeName = "灰名单"
}
// IP数量
countItemsResp, err := client.IPItemRPC().CountIPItemsWithListId(action.UserContext(), &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,
"isGlobal": list.IsGlobal,
}
return nil
}

View File

@@ -0,0 +1,166 @@
package logs
import (
"encoding/json"
"github.com/TeaOSLab/EdgeCommon/pkg/iplibrary"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
"regexp"
"strings"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "")
}
func (this *IndexAction) RunGet(params struct {
Day string
RequestId string
FirewallPolicyId int64
GroupId int64
ServerId int64
Partition int32 `default:"-1"`
}) {
if len(params.Day) == 0 {
params.Day = timeutil.Format("Y-m-d")
}
this.Data["path"] = this.Request.URL.Path
this.Data["day"] = params.Day
this.Data["groupId"] = params.GroupId
this.Data["accessLogs"] = []interface{}{}
this.Data["serverId"] = params.ServerId
// 所有的服务列表
serversResp, err := this.RPC().ServerRPC().ListEnabledServersMatch(this.UserContext(), &pb.ListEnabledServersMatchRequest{
Offset: 0,
Size: 100, // 我们这里最多显示前100个
ServerGroupId: 0,
Keyword: "",
ProtocolFamily: "http",
UserId: this.UserId(),
IgnoreSSLCerts: true,
})
if err != nil {
this.ErrorPage(err)
return
}
serverMaps := []maps.Map{}
for _, server := range serversResp.Servers {
if !server.IsOn {
continue
}
// 域名列表
serverNames := []*serverconfigs.ServerNameConfig{}
if server.IsAuditing || (server.AuditingResult != nil && !server.AuditingResult.IsOk) {
server.ServerNamesJSON = server.AuditingServerNamesJSON
}
if len(server.ServerNamesJSON) > 0 {
err = json.Unmarshal(server.ServerNamesJSON, &serverNames)
if err != nil {
this.ErrorPage(err)
return
}
}
if len(serverNames) == 0 {
continue
}
serverName := server.Name
if len(serverNames) > 0 {
if len(serverNames[0].SubNames) == 0 {
serverName = serverNames[0].Name
} else {
serverName = serverNames[0].SubNames[0]
}
}
serverMaps = append(serverMaps, maps.Map{
"id": server.Id,
"serverName": serverName,
})
}
this.Data["servers"] = serverMaps
// 查询
day := params.Day
ipList := []string{}
if len(day) > 0 && regexp.MustCompile(`\d{4}-\d{2}-\d{2}`).MatchString(day) {
day = strings.ReplaceAll(day, "-", "")
size := int64(20)
resp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.UserContext(), &pb.ListHTTPAccessLogsRequest{
Partition: params.Partition,
RequestId: params.RequestId,
UserId: this.UserId(),
ServerId: params.ServerId,
FirewallPolicyId: params.FirewallPolicyId,
FirewallRuleGroupId: params.GroupId,
HasFirewallPolicy: true,
Day: day,
Size: size,
Reverse: false,
})
if err != nil {
this.ErrorPage(err)
return
}
if len(resp.HttpAccessLogs) == 0 {
this.Data["accessLogs"] = []interface{}{}
} else {
this.Data["accessLogs"] = resp.HttpAccessLogs
for _, accessLog := range resp.HttpAccessLogs {
if len(accessLog.RemoteAddr) > 0 {
if !lists.ContainsString(ipList, accessLog.RemoteAddr) {
ipList = append(ipList, accessLog.RemoteAddr)
}
}
}
}
this.Data["hasMore"] = resp.HasMore
this.Data["nextRequestId"] = resp.RequestId
// 上一个requestId
this.Data["hasPrev"] = false
this.Data["lastRequestId"] = ""
if len(params.RequestId) > 0 {
this.Data["hasPrev"] = true
prevResp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.UserContext(), &pb.ListHTTPAccessLogsRequest{
Partition: params.Partition,
UserId: this.UserId(),
ServerId: params.ServerId,
RequestId: params.RequestId,
FirewallPolicyId: params.FirewallPolicyId,
FirewallRuleGroupId: params.GroupId,
HasFirewallPolicy: true,
Day: day,
Size: size,
Reverse: true,
})
if err != nil {
this.ErrorPage(err)
return
}
if int64(len(prevResp.HttpAccessLogs)) == size {
this.Data["lastRequestId"] = prevResp.RequestId
}
}
}
// 根据IP查询区域
this.Data["regions"] = iplibrary.LookupIPSummaries(ipList)
this.Show()
}

View File

@@ -0,0 +1,18 @@
package logs
import (
"github.com/TeaOSLab/EdgeUser/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth("")).
Data("teaMenu", "waf").
Data("teaSubMenu", "wafLogs").
Prefix("/waf/logs").
Get("", new(IndexAction)).
EndAll()
})
}