Files
EdgeAdmin/internal/web/actions/default/servers/index.go

113 lines
2.8 KiB
Go
Raw Normal View History

2020-07-22 22:19:39 +08:00
package servers
2020-07-29 19:34:54 +08:00
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
2020-09-15 14:44:52 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
2020-09-13 20:37:07 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
2020-07-29 19:34:54 +08:00
"github.com/iwind/TeaGo/maps"
)
2020-07-22 22:19:39 +08:00
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
2020-08-21 12:32:16 +08:00
this.Nav("", "server", "index")
2020-07-22 22:19:39 +08:00
}
func (this *IndexAction) RunGet(params struct{}) {
2020-07-29 19:34:54 +08:00
countResp, err := this.RPC().ServerRPC().CountAllEnabledServers(this.AdminContext(), &pb.CountAllEnabledServersRequest{})
if err != nil {
this.ErrorPage(err)
return
}
count := countResp.Count
page := this.NewPage(count)
this.Data["page"] = page.AsHTML()
// 服务列表
serversResp, err := this.RPC().ServerRPC().ListEnabledServers(this.AdminContext(), &pb.ListEnabledServersRequest{
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
serverMaps := []maps.Map{}
for _, server := range serversResp.Servers {
2020-09-15 14:44:52 +08:00
config := &serverconfigs.ServerConfig{}
err = json.Unmarshal(server.Config, config)
2020-07-29 19:34:54 +08:00
if err != nil {
this.ErrorPage(err)
return
}
2020-08-21 12:32:16 +08:00
// 端口列表
portMaps := []maps.Map{}
2020-09-15 14:44:52 +08:00
if len(server.HttpJSON) > 0 && config.HTTP.IsOn {
for _, listen := range config.HTTP.Listen {
2020-08-21 12:32:16 +08:00
portMaps = append(portMaps, maps.Map{
"protocol": listen.Protocol,
"portRange": listen.PortRange,
})
}
}
2020-09-15 14:44:52 +08:00
if config.HTTPS != nil && config.HTTPS.IsOn {
for _, listen := range config.HTTPS.Listen {
2020-08-21 12:32:16 +08:00
portMaps = append(portMaps, maps.Map{
"protocol": listen.Protocol,
"portRange": listen.PortRange,
})
}
}
2020-09-15 14:44:52 +08:00
if config.TCP != nil && config.TCP.IsOn {
for _, listen := range config.TCP.Listen {
2020-08-21 12:32:16 +08:00
portMaps = append(portMaps, maps.Map{
"protocol": listen.Protocol,
"portRange": listen.PortRange,
})
}
}
2020-09-15 14:44:52 +08:00
if config.TLS != nil && config.TLS.IsOn {
for _, listen := range config.TLS.Listen {
2020-08-21 12:32:16 +08:00
portMaps = append(portMaps, maps.Map{
"protocol": listen.Protocol,
"portRange": listen.PortRange,
})
}
}
2020-09-15 14:44:52 +08:00
if config.Unix != nil && config.Unix.IsOn {
for _, listen := range config.Unix.Listen {
2020-08-21 12:32:16 +08:00
portMaps = append(portMaps, maps.Map{
"protocol": listen.Protocol,
"portRange": listen.Host,
})
}
}
2020-09-15 14:44:52 +08:00
if config.UDP != nil && config.UDP.IsOn {
for _, listen := range config.UDP.Listen {
2020-08-21 12:32:16 +08:00
portMaps = append(portMaps, maps.Map{
"protocol": listen.Protocol,
"portRange": listen.PortRange,
})
}
}
2020-07-29 19:34:54 +08:00
serverMaps = append(serverMaps, maps.Map{
"id": server.Id,
2020-09-13 20:37:07 +08:00
"name": server.Name,
2020-07-29 19:34:54 +08:00
"cluster": maps.Map{
"id": server.Cluster.Id,
"name": server.Cluster.Name,
},
2020-08-21 12:32:16 +08:00
"ports": portMaps,
2020-09-15 14:44:52 +08:00
"serverTypeName": serverconfigs.FindServerType(server.Type).GetString("name"),
2020-07-29 19:34:54 +08:00
})
}
this.Data["servers"] = serverMaps
2020-07-22 22:19:39 +08:00
this.Show()
}