管理端全部功能跑通

This commit is contained in:
robin
2026-02-27 10:35:22 +08:00
parent 4d275c921d
commit 150799f41d
263 changed files with 22664 additions and 4053 deletions

View File

@@ -5,6 +5,8 @@ import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/httpdns/httpdnsutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type IndexAction struct {
@@ -40,120 +42,88 @@ func (this *IndexAction) RunGet(params struct {
this.Data["status"] = params.Status
this.Data["keyword"] = params.Keyword
clusters := []map[string]interface{}{
{"id": int64(1), "name": "gateway-cn-hz"},
{"id": int64(2), "name": "gateway-cn-bj"},
clusterResp, err := this.RPC().HTTPDNSClusterRPC().FindAllHTTPDNSClusters(this.AdminContext(), &pb.FindAllHTTPDNSClustersRequest{})
if err != nil {
this.ErrorPage(err)
return
}
nodes := []map[string]interface{}{
{"id": int64(101), "clusterId": int64(1), "name": "hz-node-01"},
{"id": int64(102), "clusterId": int64(1), "name": "hz-node-02"},
{"id": int64(201), "clusterId": int64(2), "name": "bj-node-01"},
clusters := make([]map[string]interface{}, 0, len(clusterResp.GetClusters()))
nodes := make([]map[string]interface{}, 0)
for _, cluster := range clusterResp.GetClusters() {
clusters = append(clusters, map[string]interface{}{
"id": cluster.GetId(),
"name": cluster.GetName(),
})
nodeResp, err := this.RPC().HTTPDNSNodeRPC().ListHTTPDNSNodes(this.AdminContext(), &pb.ListHTTPDNSNodesRequest{
ClusterId: cluster.GetId(),
})
if err != nil {
this.ErrorPage(err)
return
}
for _, node := range nodeResp.GetNodes() {
nodes = append(nodes, map[string]interface{}{
"id": node.GetId(),
"clusterId": node.GetClusterId(),
"name": node.GetName(),
})
}
}
this.Data["clusters"] = clusters
this.Data["nodes"] = nodes
allLogs := []map[string]interface{}{
{
"time": "2026-02-23 10:21:51",
"clusterId": int64(1),
"clusterName": "gateway-cn-hz",
"nodeId": int64(101),
"nodeName": "hz-node-01",
"appName": "\u4e3b\u7ad9\u79fb\u52a8\u4e1a\u52a1",
"appId": "ab12xc34s2",
"domain": "api.business.com",
"query": "A",
"clientIp": "203.0.113.25",
"os": "Android",
"sdkVersion": "2.4.1",
"ips": "198.51.100.10,198.51.100.11",
"status": "success",
"errorCode": "none",
"costMs": 37,
"pinningMode": "report",
"pinningResult": "warn",
"sanMode": "strict",
"sanResult": "pass",
},
{
"time": "2026-02-23 10:18:02",
"clusterId": int64(2),
"clusterName": "gateway-cn-bj",
"nodeId": int64(201),
"nodeName": "bj-node-01",
"appName": "\u652f\u4ed8\u7f51\u5173\u4e1a\u52a1",
"appId": "vd8992ksm1",
"domain": "payment.business.com",
"query": "A",
"clientIp": "198.51.100.67",
"os": "iOS",
"sdkVersion": "2.3.9",
"ips": "198.51.100.22",
"status": "failed",
"errorCode": "40301",
"costMs": 52,
"pinningMode": "enforce",
"pinningResult": "fail",
"sanMode": "strict",
"sanResult": "fail",
},
{
"time": "2026-02-23 10:12:44",
"clusterId": int64(1),
"clusterName": "gateway-cn-hz",
"nodeId": int64(102),
"nodeName": "hz-node-02",
"appName": "\u4e3b\u7ad9\u79fb\u52a8\u4e1a\u52a1",
"appId": "ab12xc34s2",
"domain": "www.aliyun.com",
"query": "A",
"clientIp": "106.11.63.180",
"os": "Unknown",
"sdkVersion": "none",
"ips": "3.33.120.190,15.197.120.33",
"status": "success",
"errorCode": "none",
"costMs": 41,
"pinningMode": "off",
"pinningResult": "na",
"sanMode": "report",
"sanResult": "warn",
},
logResp, err := this.RPC().HTTPDNSAccessLogRPC().ListHTTPDNSAccessLogs(this.AdminContext(), &pb.ListHTTPDNSAccessLogsRequest{
Day: "",
ClusterId: params.ClusterId,
NodeId: params.NodeId,
AppId: strings.TrimSpace(params.AppId),
Domain: strings.TrimSpace(params.Domain),
Status: strings.TrimSpace(params.Status),
Keyword: strings.TrimSpace(params.Keyword),
Offset: 0,
Size: 100,
})
if err != nil {
this.ErrorPage(err)
return
}
status := strings.TrimSpace(strings.ToLower(params.Status))
appID := strings.TrimSpace(strings.ToLower(params.AppId))
domain := strings.TrimSpace(strings.ToLower(params.Domain))
keyword := strings.TrimSpace(strings.ToLower(params.Keyword))
logs := make([]map[string]interface{}, 0, len(logResp.GetLogs()))
for _, item := range logResp.GetLogs() {
createdTime := ""
if item.GetCreatedAt() > 0 {
createdTime = timeutil.FormatTime("Y-m-d H:i:s", item.GetCreatedAt())
}
status := item.GetStatus()
if len(status) == 0 {
status = "failed"
}
errorCode := item.GetErrorCode()
if len(errorCode) == 0 {
errorCode = "none"
}
filtered := make([]map[string]interface{}, 0)
for _, log := range allLogs {
if params.ClusterId > 0 && log["clusterId"].(int64) != params.ClusterId {
continue
}
if params.NodeId > 0 && log["nodeId"].(int64) != params.NodeId {
continue
}
if len(status) > 0 && log["status"].(string) != status {
continue
}
if len(appID) > 0 && !strings.Contains(strings.ToLower(log["appId"].(string)), appID) {
continue
}
if len(domain) > 0 && !strings.Contains(strings.ToLower(log["domain"].(string)), domain) {
continue
}
if len(keyword) > 0 {
if !strings.Contains(strings.ToLower(log["appName"].(string)), keyword) &&
!strings.Contains(strings.ToLower(log["domain"].(string)), keyword) &&
!strings.Contains(strings.ToLower(log["clientIp"].(string)), keyword) &&
!strings.Contains(strings.ToLower(log["ips"].(string)), keyword) {
continue
}
}
filtered = append(filtered, log)
logs = append(logs, map[string]interface{}{
"time": createdTime,
"clusterId": item.GetClusterId(),
"clusterName": item.GetClusterName(),
"nodeId": item.GetNodeId(),
"nodeName": item.GetNodeName(),
"appName": item.GetAppName(),
"appId": item.GetAppId(),
"domain": item.GetDomain(),
"query": item.GetQtype(),
"clientIp": item.GetClientIP(),
"os": item.GetOs(),
"sdkVersion": item.GetSdkVersion(),
"ips": item.GetResultIPs(),
"status": status,
"errorCode": errorCode,
"costMs": item.GetCostMs(),
})
}
this.Data["resolveLogs"] = filtered
this.Data["resolveLogs"] = logs
this.Show()
}