2020-07-22 22:19:39 +08:00
|
|
|
package servers
|
|
|
|
|
|
2020-07-29 19:34:54 +08:00
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
2020-09-13 20:37:07 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
2020-07-29 19:34:54 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
2020-09-13 20:37:07 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
2020-08-21 12:32:16 +08:00
|
|
|
"github.com/iwind/TeaGo/logs"
|
2020-07-29 19:34:54 +08:00
|
|
|
"github.com/iwind/TeaGo/maps"
|
2020-08-21 12:32:16 +08:00
|
|
|
"strings"
|
2020-07-29 19:34:54 +08:00
|
|
|
)
|
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-08-21 12:32:16 +08:00
|
|
|
serverConfig := &serverconfigs.ServerConfig{}
|
2020-07-29 19:34:54 +08:00
|
|
|
err = json.Unmarshal(server.Config, &serverConfig)
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2020-08-21 12:32:16 +08:00
|
|
|
err = serverConfig.Init()
|
|
|
|
|
if err != nil {
|
|
|
|
|
logs.Println("init server '" + serverConfig.Name + "' error: " + err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serverTypeNames := []string{}
|
|
|
|
|
|
|
|
|
|
// 端口列表
|
|
|
|
|
portMaps := []maps.Map{}
|
|
|
|
|
if serverConfig.HTTP != nil && serverConfig.HTTP.IsOn {
|
|
|
|
|
serverTypeNames = append(serverTypeNames, "HTTP")
|
|
|
|
|
for _, listen := range serverConfig.HTTP.Listen {
|
|
|
|
|
portMaps = append(portMaps, maps.Map{
|
|
|
|
|
"protocol": listen.Protocol,
|
|
|
|
|
"portRange": listen.PortRange,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if serverConfig.HTTPS != nil && serverConfig.HTTPS.IsOn {
|
|
|
|
|
serverTypeNames = append(serverTypeNames, "HTTPS")
|
|
|
|
|
for _, listen := range serverConfig.HTTPS.Listen {
|
|
|
|
|
portMaps = append(portMaps, maps.Map{
|
|
|
|
|
"protocol": listen.Protocol,
|
|
|
|
|
"portRange": listen.PortRange,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if serverConfig.TCP != nil && serverConfig.TCP.IsOn {
|
|
|
|
|
serverTypeNames = append(serverTypeNames, "TCP")
|
|
|
|
|
for _, listen := range serverConfig.TCP.Listen {
|
|
|
|
|
portMaps = append(portMaps, maps.Map{
|
|
|
|
|
"protocol": listen.Protocol,
|
|
|
|
|
"portRange": listen.PortRange,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if serverConfig.TLS != nil && serverConfig.TLS.IsOn {
|
|
|
|
|
serverTypeNames = append(serverTypeNames, "TLS")
|
|
|
|
|
for _, listen := range serverConfig.TLS.Listen {
|
|
|
|
|
portMaps = append(portMaps, maps.Map{
|
|
|
|
|
"protocol": listen.Protocol,
|
|
|
|
|
"portRange": listen.PortRange,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if serverConfig.Unix != nil && serverConfig.Unix.IsOn {
|
|
|
|
|
serverTypeNames = append(serverTypeNames, "Unix")
|
|
|
|
|
for _, listen := range serverConfig.Unix.Listen {
|
|
|
|
|
portMaps = append(portMaps, maps.Map{
|
|
|
|
|
"protocol": listen.Protocol,
|
|
|
|
|
"portRange": listen.Host,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if serverConfig.UDP != nil && serverConfig.UDP.IsOn {
|
|
|
|
|
serverTypeNames = append(serverTypeNames, "UDP")
|
|
|
|
|
for _, listen := range serverConfig.UDP.Listen {
|
|
|
|
|
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,
|
|
|
|
|
"serverTypeName": strings.Join(serverTypeNames, "+"),
|
2020-07-29 19:34:54 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
this.Data["servers"] = serverMaps
|
|
|
|
|
|
2020-07-22 22:19:39 +08:00
|
|
|
this.Show()
|
|
|
|
|
}
|