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-11-02 09:37:20 +08:00
|
|
|
"strconv"
|
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
|
|
|
}
|
|
|
|
|
|
2020-10-31 15:21:24 +08:00
|
|
|
func (this *IndexAction) RunGet(params struct {
|
|
|
|
|
GroupId int64
|
|
|
|
|
Keyword string
|
|
|
|
|
}) {
|
|
|
|
|
this.Data["groupId"] = params.GroupId
|
|
|
|
|
this.Data["keyword"] = params.Keyword
|
|
|
|
|
|
|
|
|
|
countResp, err := this.RPC().ServerRPC().CountAllEnabledServersMatch(this.AdminContext(), &pb.CountAllEnabledServersMatchRequest{
|
|
|
|
|
GroupId: params.GroupId,
|
|
|
|
|
Keyword: params.Keyword,
|
|
|
|
|
})
|
2020-07-29 19:34:54 +08:00
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
count := countResp.Count
|
|
|
|
|
page := this.NewPage(count)
|
|
|
|
|
this.Data["page"] = page.AsHTML()
|
|
|
|
|
|
|
|
|
|
// 服务列表
|
2020-10-31 15:21:24 +08:00
|
|
|
serversResp, err := this.RPC().ServerRPC().ListEnabledServersMatch(this.AdminContext(), &pb.ListEnabledServersMatchRequest{
|
|
|
|
|
Offset: page.Offset,
|
|
|
|
|
Size: page.Size,
|
|
|
|
|
GroupId: params.GroupId,
|
|
|
|
|
Keyword: params.Keyword,
|
2020-07-29 19:34:54 +08:00
|
|
|
})
|
|
|
|
|
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
|
|
|
|
2020-10-29 21:37:48 +08:00
|
|
|
// 分组
|
|
|
|
|
groupMaps := []maps.Map{}
|
|
|
|
|
if len(server.Groups) > 0 {
|
|
|
|
|
for _, group := range server.Groups {
|
|
|
|
|
groupMaps = append(groupMaps, maps.Map{
|
|
|
|
|
"id": group.Id,
|
|
|
|
|
"name": group.Name,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-31 15:21:24 +08:00
|
|
|
// 域名列表
|
|
|
|
|
serverNames := []*serverconfigs.ServerNameConfig{}
|
2020-12-03 21:07:08 +08:00
|
|
|
if len(server.ServerNamesJSON) > 0 {
|
|
|
|
|
err = json.Unmarshal(server.ServerNamesJSON, &serverNames)
|
2020-10-31 15:21:24 +08:00
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-15 16:28:25 +08:00
|
|
|
countServerNames := 0
|
|
|
|
|
for _, serverName := range serverNames {
|
|
|
|
|
if len(serverName.SubNames) == 0 {
|
|
|
|
|
countServerNames++
|
|
|
|
|
} else {
|
|
|
|
|
countServerNames += len(serverName.SubNames)
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-31 15:21:24 +08:00
|
|
|
|
2020-07-29 19:34:54 +08:00
|
|
|
serverMaps = append(serverMaps, maps.Map{
|
|
|
|
|
"id": server.Id,
|
2020-10-09 12:03:32 +08:00
|
|
|
"isOn": server.IsOn,
|
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-11-15 16:28:25 +08:00
|
|
|
"ports": portMaps,
|
|
|
|
|
"serverTypeName": serverconfigs.FindServerType(server.Type).GetString("name"),
|
|
|
|
|
"groups": groupMaps,
|
|
|
|
|
"serverNames": serverNames,
|
|
|
|
|
"countServerNames": countServerNames,
|
2020-07-29 19:34:54 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
this.Data["servers"] = serverMaps
|
|
|
|
|
|
2020-10-31 15:21:24 +08:00
|
|
|
// 分组
|
|
|
|
|
groupsResp, err := this.RPC().ServerGroupRPC().FindAllEnabledServerGroups(this.AdminContext(), &pb.FindAllEnabledServerGroupsRequest{})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
groupMaps := []maps.Map{}
|
|
|
|
|
for _, group := range groupsResp.Groups {
|
2020-11-02 09:37:20 +08:00
|
|
|
countResp, err := this.RPC().ServerRPC().CountAllEnabledServersWithGroupId(this.AdminContext(), &pb.CountAllEnabledServersWithGroupIdRequest{GroupId: group.Id})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
groupName := group.Name
|
|
|
|
|
if countResp.Count > 0 {
|
|
|
|
|
groupName += "(" + strconv.FormatInt(countResp.Count, 10) + ")"
|
|
|
|
|
}
|
2020-10-31 15:21:24 +08:00
|
|
|
groupMaps = append(groupMaps, maps.Map{
|
|
|
|
|
"id": group.Id,
|
2020-11-02 09:37:20 +08:00
|
|
|
"name": groupName,
|
2020-10-31 15:21:24 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
this.Data["groups"] = groupMaps
|
|
|
|
|
|
2020-07-22 22:19:39 +08:00
|
|
|
this.Show()
|
|
|
|
|
}
|