1.4.5.2
This commit is contained in:
255
EdgeAdmin/internal/web/actions/default/users/user/servers.go
Normal file
255
EdgeAdmin/internal/web/actions/default/users/user/servers.go
Normal file
@@ -0,0 +1,255 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/users/userutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
)
|
||||
|
||||
type ServersAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ServersAction) Init() {
|
||||
this.Nav("", "", "server")
|
||||
}
|
||||
|
||||
func (this *ServersAction) RunGet(params struct {
|
||||
UserId int64
|
||||
|
||||
ClusterId int64
|
||||
GroupId int64
|
||||
Keyword string
|
||||
AuditingFlag int32
|
||||
CheckDNS bool
|
||||
|
||||
TrafficOutOrder string
|
||||
}) {
|
||||
err := userutils.InitUser(this.Parent(), params.UserId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["clusterId"] = params.ClusterId
|
||||
this.Data["groupId"] = params.GroupId
|
||||
this.Data["keyword"] = params.Keyword
|
||||
this.Data["auditingFlag"] = params.AuditingFlag
|
||||
this.Data["checkDNS"] = params.CheckDNS
|
||||
this.Data["hasOrder"] = len(params.TrafficOutOrder) > 0
|
||||
this.Data["userId"] = params.UserId
|
||||
|
||||
dashboardResp, err := this.RPC().UserRPC().ComposeUserDashboard(this.AdminContext(), &pb.ComposeUserDashboardRequest{UserId: params.UserId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 单位
|
||||
userUIConfig, err := configloaders.LoadUserUIConfig()
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["uiConfig"] = maps.Map{
|
||||
"showTrafficCharts": true,
|
||||
"showBandwidthCharts": true,
|
||||
"bandwidthUnit": systemconfigs.BandwidthUnitBit,
|
||||
}
|
||||
|
||||
if userUIConfig != nil {
|
||||
this.Data["uiConfig"] = maps.Map{
|
||||
"showTrafficCharts": userUIConfig.ShowTrafficCharts,
|
||||
"showBandwidthCharts": userUIConfig.ShowBandwidthCharts,
|
||||
"bandwidthUnit": systemconfigs.BandwidthUnitBit, // 强制使用比特单位
|
||||
}
|
||||
}
|
||||
|
||||
// 整体带宽统计
|
||||
var monthlyPeekBandwidthBytes = dashboardResp.MonthlyPeekBandwidthBytes
|
||||
var dailyPeekBandwidthBytes = dashboardResp.DailyPeekBandwidthBytes
|
||||
monthlyPeekBandwidthBytes *= 8
|
||||
dailyPeekBandwidthBytes *= 8
|
||||
this.Data["dashboard"] = maps.Map{
|
||||
"countServers": dashboardResp.CountServers,
|
||||
"monthlyTrafficBytes": dashboardResp.MonthlyTrafficBytes,
|
||||
"monthlyPeekBandwidthBits": monthlyPeekBandwidthBytes,
|
||||
"dailyTrafficBytes": dashboardResp.DailyTrafficBytes,
|
||||
"dailyPeekBandwidthBits": dailyPeekBandwidthBytes,
|
||||
}
|
||||
|
||||
// 服务列表
|
||||
countServersResp, err := this.RPC().ServerRPC().CountAllEnabledServersMatch(this.AdminContext(), &pb.CountAllEnabledServersMatchRequest{
|
||||
UserId: params.UserId,
|
||||
NodeClusterId: params.ClusterId,
|
||||
ServerGroupId: params.GroupId,
|
||||
Keyword: params.Keyword,
|
||||
AuditingFlag: params.AuditingFlag,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var count = countServersResp.Count
|
||||
var page = this.NewPage(count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
serversResp, err := this.RPC().ServerRPC().ListEnabledServersMatch(this.AdminContext(), &pb.ListEnabledServersMatchRequest{
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
UserId: params.UserId,
|
||||
NodeClusterId: params.ClusterId,
|
||||
ServerGroupId: params.GroupId,
|
||||
Keyword: params.Keyword,
|
||||
AuditingFlag: params.AuditingFlag,
|
||||
TrafficOutDesc: params.TrafficOutOrder == "desc",
|
||||
TrafficOutAsc: params.TrafficOutOrder == "asc",
|
||||
IgnoreServerNames: true,
|
||||
IgnoreSSLCerts: true,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var serverMaps = []maps.Map{}
|
||||
for _, server := range serversResp.Servers {
|
||||
var config = &serverconfigs.ServerConfig{}
|
||||
err = json.Unmarshal(server.Config, config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 端口列表
|
||||
var portMaps = []maps.Map{}
|
||||
if config.HTTP != nil && config.HTTP.IsOn {
|
||||
for _, listen := range config.HTTP.Listen {
|
||||
portMaps = append(portMaps, maps.Map{
|
||||
"protocol": listen.Protocol,
|
||||
"portRange": listen.PortRange,
|
||||
})
|
||||
}
|
||||
}
|
||||
if config.HTTPS != nil && config.HTTPS.IsOn {
|
||||
for _, listen := range config.HTTPS.Listen {
|
||||
portMaps = append(portMaps, maps.Map{
|
||||
"protocol": listen.Protocol,
|
||||
"portRange": listen.PortRange,
|
||||
})
|
||||
}
|
||||
}
|
||||
if config.TCP != nil && config.TCP.IsOn {
|
||||
for _, listen := range config.TCP.Listen {
|
||||
portMaps = append(portMaps, maps.Map{
|
||||
"protocol": listen.Protocol,
|
||||
"portRange": listen.PortRange,
|
||||
})
|
||||
}
|
||||
}
|
||||
if config.TLS != nil && config.TLS.IsOn {
|
||||
for _, listen := range config.TLS.Listen {
|
||||
portMaps = append(portMaps, maps.Map{
|
||||
"protocol": listen.Protocol,
|
||||
"portRange": listen.PortRange,
|
||||
})
|
||||
}
|
||||
}
|
||||
if config.UDP != nil && config.UDP.IsOn {
|
||||
for _, listen := range config.UDP.Listen {
|
||||
portMaps = append(portMaps, maps.Map{
|
||||
"protocol": listen.Protocol,
|
||||
"portRange": listen.PortRange,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 分组
|
||||
var groupMaps = []maps.Map{}
|
||||
if len(server.ServerGroups) > 0 {
|
||||
for _, group := range server.ServerGroups {
|
||||
groupMaps = append(groupMaps, maps.Map{
|
||||
"id": group.Id,
|
||||
"name": group.Name,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 域名列表
|
||||
// 域名列表
|
||||
if server.IsAuditing || (server.AuditingResult != nil && !server.AuditingResult.IsOk) {
|
||||
server.ServerNamesJSON = server.AuditingServerNamesJSON
|
||||
|
||||
if len(config.ServerNames) == 0 {
|
||||
// 审核中的域名
|
||||
if len(server.ServerNamesJSON) > 0 {
|
||||
var serverNames = []*serverconfigs.ServerNameConfig{}
|
||||
err = json.Unmarshal(server.ServerNamesJSON, &serverNames)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
config.ServerNames = serverNames
|
||||
}
|
||||
}
|
||||
}
|
||||
var auditingIsOk = true
|
||||
if !server.IsAuditing && server.AuditingResult != nil && !server.AuditingResult.IsOk {
|
||||
auditingIsOk = false
|
||||
}
|
||||
var firstServerName = ""
|
||||
for _, serverNameConfig := range config.ServerNames {
|
||||
if len(serverNameConfig.Name) > 0 {
|
||||
firstServerName = serverNameConfig.Name
|
||||
break
|
||||
}
|
||||
if len(serverNameConfig.SubNames) > 0 {
|
||||
firstServerName = serverNameConfig.SubNames[0]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// 提交审核时间
|
||||
var auditingTime = ""
|
||||
if server.AuditingAt > 0 {
|
||||
auditingTime = timeutil.FormatTime("Y-m-d", server.AuditingAt)
|
||||
}
|
||||
|
||||
// 统计数据
|
||||
var bandwidthBits int64 = 0
|
||||
if server.BandwidthBytes > 0 {
|
||||
bandwidthBits = server.BandwidthBytes * 8
|
||||
}
|
||||
|
||||
serverMaps = append(serverMaps, maps.Map{
|
||||
"id": server.Id,
|
||||
"isOn": server.IsOn,
|
||||
"name": server.Name,
|
||||
"cluster": maps.Map{
|
||||
"id": server.NodeCluster.Id,
|
||||
"name": server.NodeCluster.Name,
|
||||
},
|
||||
"ports": portMaps,
|
||||
"serverTypeName": serverconfigs.FindServerType(server.Type).GetString("name"),
|
||||
"groups": groupMaps,
|
||||
"firstServerName": firstServerName,
|
||||
"countServerNames": server.CountServerNames,
|
||||
"isAuditing": server.IsAuditing,
|
||||
"auditingIsOk": auditingIsOk,
|
||||
"auditingTime": auditingTime,
|
||||
"bandwidthBits": bandwidthBits,
|
||||
})
|
||||
}
|
||||
this.Data["servers"] = serverMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
Reference in New Issue
Block a user