1.4.5.2
This commit is contained in:
172
EdgeAdmin/internal/web/actions/default/ns/test/nodeOptions.go
Normal file
172
EdgeAdmin/internal/web/actions/default/ns/test/nodeOptions.go
Normal file
@@ -0,0 +1,172 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build plus
|
||||
|
||||
package test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type NodeOptionsAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *NodeOptionsAction) RunPost(params struct {
|
||||
ClusterId int64
|
||||
}) {
|
||||
clusterResp, err := this.RPC().NSClusterRPC().FindNSCluster(this.AdminContext(), &pb.FindNSClusterRequest{NsClusterId: params.ClusterId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var cluster = clusterResp.NsCluster
|
||||
if cluster == nil {
|
||||
this.NotFound("nsCluster", params.ClusterId)
|
||||
return
|
||||
}
|
||||
|
||||
nodesResp, err := this.RPC().NSNodeRPC().FindAllNSNodesWithNSClusterId(this.AdminContext(), &pb.FindAllNSNodesWithNSClusterIdRequest{NsClusterId: params.ClusterId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var nodeMaps = []maps.Map{}
|
||||
for _, node := range nodesResp.NsNodes {
|
||||
if !node.IsOn {
|
||||
continue
|
||||
}
|
||||
|
||||
addressesResp, err := this.RPC().NodeIPAddressRPC().FindAllEnabledNodeIPAddressesWithNodeId(this.AdminContext(), &pb.FindAllEnabledNodeIPAddressesWithNodeIdRequest{
|
||||
NodeId: node.Id,
|
||||
Role: nodeconfigs.NodeRoleDNS,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var addresses = addressesResp.NodeIPAddresses
|
||||
if len(addresses) == 0 {
|
||||
continue
|
||||
}
|
||||
var addrs = []string{}
|
||||
for _, addr := range addresses {
|
||||
if addr.CanAccess {
|
||||
addrs = append(addrs, addr.Ip)
|
||||
}
|
||||
}
|
||||
|
||||
nodeMaps = append(nodeMaps, maps.Map{
|
||||
"id": node.Id,
|
||||
"name": node.Name,
|
||||
"addrs": addrs,
|
||||
})
|
||||
}
|
||||
this.Data["nodes"] = nodeMaps
|
||||
|
||||
// 端口配置
|
||||
var portMaps = []maps.Map{}
|
||||
|
||||
if len(cluster.UdpJSON) > 0 {
|
||||
var config = &serverconfigs.TCPProtocolConfig{}
|
||||
err = json.Unmarshal(cluster.UdpJSON, config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
err = config.Init()
|
||||
if err == nil && config.IsOn {
|
||||
for _, listen := range config.Listen {
|
||||
for port := listen.MinPort; port <= listen.MaxPort; port++ {
|
||||
portMaps = append(portMaps, maps.Map{
|
||||
"port": port,
|
||||
"protocol": "udp",
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(cluster.TcpJSON) > 0 {
|
||||
var config = &serverconfigs.TCPProtocolConfig{}
|
||||
err = json.Unmarshal(cluster.TcpJSON, config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
err = config.Init()
|
||||
if err == nil && config.IsOn {
|
||||
for _, listen := range config.Listen {
|
||||
for port := listen.MinPort; port <= listen.MaxPort; port++ {
|
||||
portMaps = append(portMaps, maps.Map{
|
||||
"port": port,
|
||||
"protocol": "tcp",
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(cluster.TlsJSON) > 0 {
|
||||
var config = &serverconfigs.TCPProtocolConfig{}
|
||||
err = json.Unmarshal(cluster.TlsJSON, config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
err = config.Init()
|
||||
if err == nil && config.IsOn {
|
||||
for _, listen := range config.Listen {
|
||||
for port := listen.MinPort; port <= listen.MaxPort; port++ {
|
||||
portMaps = append(portMaps, maps.Map{
|
||||
"port": port,
|
||||
"protocol": "tls",
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(cluster.DohJSON) > 0 {
|
||||
var config = dnsconfigs.NewNSDoHConfig()
|
||||
err = json.Unmarshal(cluster.DohJSON, config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
err = config.Init()
|
||||
if err == nil && config.IsOn {
|
||||
for _, listen := range config.Listen {
|
||||
for port := listen.MinPort; port <= listen.MaxPort; port++ {
|
||||
portMaps = append(portMaps, maps.Map{
|
||||
"port": port,
|
||||
"protocol": "doh",
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(portMaps) == 0 {
|
||||
portMaps = []maps.Map{
|
||||
{
|
||||
"port": 53,
|
||||
"protocol": "udp",
|
||||
},
|
||||
{
|
||||
"port": 53,
|
||||
"protocol": "tcp",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["ports"] = portMaps
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user