mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-05 22:30:28 +08:00
删除不必要的文件
This commit is contained in:
@@ -1,173 +0,0 @@
|
|||||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
||||||
|
|
||||||
package logs
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/lists"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
|
||||||
"net"
|
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type IndexAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) Init() {
|
|
||||||
this.Nav("", "", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) RunGet(params struct {
|
|
||||||
RequestId string
|
|
||||||
Keyword string
|
|
||||||
Day string
|
|
||||||
}) {
|
|
||||||
day := strings.ReplaceAll(params.Day, "-", "")
|
|
||||||
if !regexp.MustCompile(`^\d{8}$`).MatchString(day) {
|
|
||||||
day = timeutil.Format("Ymd")
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Data["keyword"] = params.Keyword
|
|
||||||
this.Data["day"] = day[:4] + "-" + day[4:6] + "-" + day[6:]
|
|
||||||
this.Data["path"] = this.Request.URL.Path
|
|
||||||
|
|
||||||
var size = int64(10)
|
|
||||||
|
|
||||||
resp, err := this.RPC().NSAccessLogRPC().ListNSAccessLogs(this.AdminContext(), &pb.ListNSAccessLogsRequest{
|
|
||||||
RequestId: params.RequestId,
|
|
||||||
NsNodeId: 0,
|
|
||||||
NsDomainId: 0,
|
|
||||||
NsRecordId: 0,
|
|
||||||
Size: size,
|
|
||||||
Day: day,
|
|
||||||
Keyword: params.Keyword,
|
|
||||||
Reverse: false,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ipList := []string{}
|
|
||||||
nodeIds := []int64{}
|
|
||||||
domainIds := []int64{}
|
|
||||||
if len(resp.NsAccessLogs) == 0 {
|
|
||||||
this.Data["accessLogs"] = []interface{}{}
|
|
||||||
} else {
|
|
||||||
this.Data["accessLogs"] = resp.NsAccessLogs
|
|
||||||
for _, accessLog := range resp.NsAccessLogs {
|
|
||||||
// IP
|
|
||||||
if len(accessLog.RemoteAddr) > 0 {
|
|
||||||
// 去掉端口
|
|
||||||
ip, _, err := net.SplitHostPort(accessLog.RemoteAddr)
|
|
||||||
if err == nil {
|
|
||||||
accessLog.RemoteAddr = ip
|
|
||||||
if !lists.ContainsString(ipList, ip) {
|
|
||||||
ipList = append(ipList, ip)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 节点
|
|
||||||
if !lists.ContainsInt64(nodeIds, accessLog.NsNodeId) {
|
|
||||||
nodeIds = append(nodeIds, accessLog.NsNodeId)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 域名
|
|
||||||
if !lists.ContainsInt64(domainIds, accessLog.NsDomainId) {
|
|
||||||
domainIds = append(domainIds, accessLog.NsDomainId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.Data["hasMore"] = resp.HasMore
|
|
||||||
this.Data["nextRequestId"] = resp.RequestId
|
|
||||||
|
|
||||||
// 上一个requestId
|
|
||||||
this.Data["hasPrev"] = false
|
|
||||||
this.Data["lastRequestId"] = ""
|
|
||||||
if len(params.RequestId) > 0 {
|
|
||||||
this.Data["hasPrev"] = true
|
|
||||||
prevResp, err := this.RPC().NSAccessLogRPC().ListNSAccessLogs(this.AdminContext(), &pb.ListNSAccessLogsRequest{
|
|
||||||
RequestId: params.RequestId,
|
|
||||||
NsNodeId: 0,
|
|
||||||
NsDomainId: 0,
|
|
||||||
NsRecordId: 0,
|
|
||||||
Day: day,
|
|
||||||
Keyword: params.Keyword,
|
|
||||||
Size: size,
|
|
||||||
Reverse: true,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if int64(len(prevResp.NsAccessLogs)) == size {
|
|
||||||
this.Data["lastRequestId"] = prevResp.RequestId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据IP查询区域
|
|
||||||
regionMap := map[string]string{} // ip => region
|
|
||||||
if len(ipList) > 0 {
|
|
||||||
resp, err := this.RPC().IPLibraryRPC().LookupIPRegions(this.AdminContext(), &pb.LookupIPRegionsRequest{IpList: ipList})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if resp.IpRegionMap != nil {
|
|
||||||
for ip, region := range resp.IpRegionMap {
|
|
||||||
if len(region.Isp) > 0 {
|
|
||||||
region.Summary += " | " + region.Isp
|
|
||||||
}
|
|
||||||
regionMap[ip] = region.Summary
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.Data["regions"] = regionMap
|
|
||||||
|
|
||||||
// 节点信息
|
|
||||||
nodeMap := map[int64]interface{}{} // node id => { ... }
|
|
||||||
for _, nodeId := range nodeIds {
|
|
||||||
nodeResp, err := this.RPC().NSNodeRPC().FindEnabledNSNode(this.AdminContext(), &pb.FindEnabledNSNodeRequest{NsNodeId: nodeId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
node := nodeResp.NsNode
|
|
||||||
if node != nil {
|
|
||||||
nodeMap[node.Id] = maps.Map{
|
|
||||||
"id": node.Id,
|
|
||||||
"name": node.Name,
|
|
||||||
"cluster": maps.Map{
|
|
||||||
"id": node.NsCluster.Id,
|
|
||||||
"name": node.NsCluster.Name,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.Data["nodes"] = nodeMap
|
|
||||||
|
|
||||||
// 域名信息
|
|
||||||
domainMap := map[int64]interface{}{} // domain id => { ... }
|
|
||||||
for _, domainId := range domainIds {
|
|
||||||
domainResp, err := this.RPC().NSDomainRPC().FindEnabledNSDomain(this.AdminContext(), &pb.FindEnabledNSDomainRequest{NsDomainId: domainId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
domain := domainResp.NsDomain
|
|
||||||
if domain != nil {
|
|
||||||
domainMap[domain.Id] = maps.Map{
|
|
||||||
"id": domain.Id,
|
|
||||||
"name": domain.Name,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.Data["domains"] = domainMap
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
package cluster
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/actions"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
)
|
|
||||||
|
|
||||||
// CreateNodeAction 创建节点
|
|
||||||
type CreateNodeAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *CreateNodeAction) Init() {
|
|
||||||
this.Nav("", "node", "create")
|
|
||||||
this.SecondMenu("nodes")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *CreateNodeAction) RunGet(params struct {
|
|
||||||
ClusterId int64
|
|
||||||
}) {
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *CreateNodeAction) RunPost(params struct {
|
|
||||||
Name string
|
|
||||||
IpAddressesJSON []byte
|
|
||||||
ClusterId int64
|
|
||||||
|
|
||||||
Must *actions.Must
|
|
||||||
}) {
|
|
||||||
params.Must.
|
|
||||||
Field("name", params.Name).
|
|
||||||
Require("请输入节点名称")
|
|
||||||
|
|
||||||
if len(params.IpAddressesJSON) == 0 {
|
|
||||||
this.Fail("请至少添加一个IP地址")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查cluster
|
|
||||||
if params.ClusterId <= 0 {
|
|
||||||
this.Fail("请选择所在集群")
|
|
||||||
}
|
|
||||||
clusterResp, err := this.RPC().NSClusterRPC().FindEnabledNSCluster(this.AdminContext(), &pb.FindEnabledNSClusterRequest{NsClusterId: params.ClusterId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if clusterResp.NsCluster == nil {
|
|
||||||
this.Fail("选择的集群不存在")
|
|
||||||
}
|
|
||||||
|
|
||||||
// IP地址
|
|
||||||
ipAddresses := []maps.Map{}
|
|
||||||
if len(params.IpAddressesJSON) > 0 {
|
|
||||||
err := json.Unmarshal(params.IpAddressesJSON, &ipAddresses)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(ipAddresses) == 0 {
|
|
||||||
this.Fail("请至少输入一个IP地址")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 保存
|
|
||||||
createResp, err := this.RPC().NSNodeRPC().CreateNSNode(this.AdminContext(), &pb.CreateNSNodeRequest{
|
|
||||||
Name: params.Name,
|
|
||||||
NodeClusterId: params.ClusterId,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
nodeId := createResp.NsNodeId
|
|
||||||
|
|
||||||
// IP地址
|
|
||||||
for _, addrMap := range ipAddresses {
|
|
||||||
addressId := addrMap.GetInt64("id")
|
|
||||||
if addressId > 0 {
|
|
||||||
_, err = this.RPC().NodeIPAddressRPC().UpdateNodeIPAddressNodeId(this.AdminContext(), &pb.UpdateNodeIPAddressNodeIdRequest{
|
|
||||||
NodeIPAddressId: addressId,
|
|
||||||
NodeId: nodeId,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
var ipStrings = addrMap.GetString("ip")
|
|
||||||
result, _ := utils.ExtractIP(ipStrings)
|
|
||||||
|
|
||||||
if len(result) == 1 {
|
|
||||||
// 单个创建
|
|
||||||
_, err = this.RPC().NodeIPAddressRPC().CreateNodeIPAddress(this.AdminContext(), &pb.CreateNodeIPAddressRequest{
|
|
||||||
NodeId: nodeId,
|
|
||||||
Role: nodeconfigs.NodeRoleDNS,
|
|
||||||
Name: addrMap.GetString("name"),
|
|
||||||
Ip: result[0],
|
|
||||||
CanAccess: addrMap.GetBool("canAccess"),
|
|
||||||
IsUp: addrMap.GetBool("isUp"),
|
|
||||||
})
|
|
||||||
} else if len(result) > 1 {
|
|
||||||
// 批量创建
|
|
||||||
_, err = this.RPC().NodeIPAddressRPC().CreateNodeIPAddresses(this.AdminContext(), &pb.CreateNodeIPAddressesRequest{
|
|
||||||
NodeId: nodeId,
|
|
||||||
Role: nodeconfigs.NodeRoleDNS,
|
|
||||||
Name: addrMap.GetString("name"),
|
|
||||||
IpList: result,
|
|
||||||
CanAccess: addrMap.GetBool("canAccess"),
|
|
||||||
IsUp: addrMap.GetBool("isUp"),
|
|
||||||
GroupValue: ipStrings,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建日志
|
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "创建域名服务节点 %d", nodeId)
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
package cluster
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
)
|
|
||||||
|
|
||||||
type DeleteAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *DeleteAction) Init() {
|
|
||||||
this.Nav("", "delete", "index")
|
|
||||||
this.SecondMenu("nodes")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *DeleteAction) RunGet(params struct{}) {
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *DeleteAction) RunPost(params struct {
|
|
||||||
ClusterId int64
|
|
||||||
}) {
|
|
||||||
// 创建日志
|
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "删除域名服务集群 %d", params.ClusterId)
|
|
||||||
|
|
||||||
// TODO 如果有用户在使用此集群,就不能删除
|
|
||||||
|
|
||||||
// 删除
|
|
||||||
_, err := this.RPC().NSClusterRPC().DeleteNSCluster(this.AdminContext(), &pb.DeleteNSCluster{NsClusterId: params.ClusterId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
||||||
|
|
||||||
package cluster
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
)
|
|
||||||
|
|
||||||
type DeleteNodeAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *DeleteNodeAction) RunPost(params struct {
|
|
||||||
NodeId int64
|
|
||||||
}) {
|
|
||||||
defer this.CreateLogInfo("删除域名服务节点 %d", params.NodeId)
|
|
||||||
|
|
||||||
_, err := this.RPC().NSNodeRPC().DeleteNSNode(this.AdminContext(), &pb.DeleteNSNodeRequest{NsNodeId: params.NodeId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
||||||
|
|
||||||
package cluster
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/logs"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
"github.com/iwind/TeaGo/types"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type IndexAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) Init() {
|
|
||||||
this.Nav("", "node", "index")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) RunGet(params struct {
|
|
||||||
ClusterId int64
|
|
||||||
InstalledState int
|
|
||||||
ActiveState int
|
|
||||||
Keyword string
|
|
||||||
}) {
|
|
||||||
this.Data["installState"] = params.InstalledState
|
|
||||||
this.Data["activeState"] = params.ActiveState
|
|
||||||
this.Data["keyword"] = params.Keyword
|
|
||||||
|
|
||||||
countAllResp, err := this.RPC().NSNodeRPC().CountAllEnabledNSNodesMatch(this.AdminContext(), &pb.CountAllEnabledNSNodesMatchRequest{
|
|
||||||
NsClusterId: params.ClusterId,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.Data["countAll"] = countAllResp.Count
|
|
||||||
|
|
||||||
countResp, err := this.RPC().NSNodeRPC().CountAllEnabledNSNodesMatch(this.AdminContext(), &pb.CountAllEnabledNSNodesMatchRequest{
|
|
||||||
NsClusterId: params.ClusterId,
|
|
||||||
InstallState: types.Int32(params.InstalledState),
|
|
||||||
ActiveState: types.Int32(params.ActiveState),
|
|
||||||
Keyword: params.Keyword,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
page := this.NewPage(countResp.Count)
|
|
||||||
this.Data["page"] = page.AsHTML()
|
|
||||||
|
|
||||||
nodesResp, err := this.RPC().NSNodeRPC().ListEnabledNSNodesMatch(this.AdminContext(), &pb.ListEnabledNSNodesMatchRequest{
|
|
||||||
Offset: page.Offset,
|
|
||||||
Size: page.Size,
|
|
||||||
NsClusterId: params.ClusterId,
|
|
||||||
InstallState: types.Int32(params.InstalledState),
|
|
||||||
ActiveState: types.Int32(params.ActiveState),
|
|
||||||
Keyword: params.Keyword,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
nodeMaps := []maps.Map{}
|
|
||||||
for _, node := range nodesResp.NsNodes {
|
|
||||||
// 状态
|
|
||||||
status := &nodeconfigs.NodeStatus{}
|
|
||||||
if len(node.StatusJSON) > 0 {
|
|
||||||
err = json.Unmarshal(node.StatusJSON, &status)
|
|
||||||
if err != nil {
|
|
||||||
logs.Error(err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
status.IsActive = status.IsActive && time.Now().Unix()-status.UpdatedAt <= 60 // N秒之内认为活跃
|
|
||||||
}
|
|
||||||
|
|
||||||
// IP
|
|
||||||
ipAddressesResp, err := this.RPC().NodeIPAddressRPC().FindAllEnabledNodeIPAddressesWithNodeId(this.AdminContext(), &pb.FindAllEnabledNodeIPAddressesWithNodeIdRequest{
|
|
||||||
NodeId: node.Id,
|
|
||||||
Role: nodeconfigs.NodeRoleDNS,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ipAddresses := []maps.Map{}
|
|
||||||
for _, addr := range ipAddressesResp.NodeIPAddresses {
|
|
||||||
ipAddresses = append(ipAddresses, maps.Map{
|
|
||||||
"id": addr.Id,
|
|
||||||
"name": addr.Name,
|
|
||||||
"ip": addr.Ip,
|
|
||||||
"canAccess": addr.CanAccess,
|
|
||||||
"isOn": addr.IsOn,
|
|
||||||
"isUp": addr.IsUp,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
nodeMaps = append(nodeMaps, maps.Map{
|
|
||||||
"id": node.Id,
|
|
||||||
"name": node.Name,
|
|
||||||
"isInstalled": node.IsInstalled,
|
|
||||||
"isOn": node.IsOn,
|
|
||||||
"isUp": node.IsUp,
|
|
||||||
"installStatus": maps.Map{
|
|
||||||
"isRunning": node.InstallStatus.IsRunning,
|
|
||||||
"isFinished": node.InstallStatus.IsFinished,
|
|
||||||
"isOk": node.InstallStatus.IsOk,
|
|
||||||
"error": node.InstallStatus.Error,
|
|
||||||
},
|
|
||||||
"status": maps.Map{
|
|
||||||
"isActive": node.IsActive,
|
|
||||||
"updatedAt": status.UpdatedAt,
|
|
||||||
"hostname": status.Hostname,
|
|
||||||
"cpuUsage": status.CPUUsage,
|
|
||||||
"cpuUsageText": fmt.Sprintf("%.2f%%", status.CPUUsage*100),
|
|
||||||
"memUsage": status.MemoryUsage,
|
|
||||||
"memUsageText": fmt.Sprintf("%.2f%%", status.MemoryUsage*100),
|
|
||||||
},
|
|
||||||
"ipAddresses": ipAddresses,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
this.Data["nodes"] = nodeMaps
|
|
||||||
|
|
||||||
// 记录最近访问
|
|
||||||
_, err = this.RPC().LatestItemRPC().IncreaseLatestItem(this.AdminContext(), &pb.IncreaseLatestItemRequest{
|
|
||||||
ItemType: "nsCluster",
|
|
||||||
ItemId: params.ClusterId,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
package cluster
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/actions"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
)
|
|
||||||
|
|
||||||
type UpdateNodeSSHAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *UpdateNodeSSHAction) Init() {
|
|
||||||
this.Nav("", "", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *UpdateNodeSSHAction) RunGet(params struct {
|
|
||||||
NodeId int64
|
|
||||||
}) {
|
|
||||||
nodeResp, err := this.RPC().NSNodeRPC().FindEnabledNSNode(this.AdminContext(), &pb.FindEnabledNSNodeRequest{NsNodeId: params.NodeId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if nodeResp.NsNode == nil {
|
|
||||||
this.NotFound("node", params.NodeId)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
node := nodeResp.NsNode
|
|
||||||
this.Data["node"] = maps.Map{
|
|
||||||
"id": node.Id,
|
|
||||||
"name": node.Name,
|
|
||||||
}
|
|
||||||
|
|
||||||
if nodeResp.NsNode.NsCluster != nil {
|
|
||||||
this.Data["clusterId"] = nodeResp.NsNode.NsCluster.Id
|
|
||||||
} else {
|
|
||||||
this.Data["clusterId"] = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// SSH
|
|
||||||
loginParams := maps.Map{
|
|
||||||
"host": "",
|
|
||||||
"port": "",
|
|
||||||
"grantId": 0,
|
|
||||||
}
|
|
||||||
this.Data["loginId"] = 0
|
|
||||||
if node.NodeLogin != nil {
|
|
||||||
this.Data["loginId"] = node.NodeLogin.Id
|
|
||||||
if len(node.NodeLogin.Params) > 0 {
|
|
||||||
err = json.Unmarshal(node.NodeLogin.Params, &loginParams)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.Data["params"] = loginParams
|
|
||||||
|
|
||||||
// 认证信息
|
|
||||||
grantId := loginParams.GetInt64("grantId")
|
|
||||||
grantResp, err := this.RPC().NodeGrantRPC().FindEnabledNodeGrant(this.AdminContext(), &pb.FindEnabledNodeGrantRequest{NodeGrantId: grantId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
}
|
|
||||||
var grantMap maps.Map = nil
|
|
||||||
if grantResp.NodeGrant != nil {
|
|
||||||
grantMap = maps.Map{
|
|
||||||
"id": grantResp.NodeGrant.Id,
|
|
||||||
"name": grantResp.NodeGrant.Name,
|
|
||||||
"method": grantResp.NodeGrant.Method,
|
|
||||||
"methodName": grantutils.FindGrantMethodName(grantResp.NodeGrant.Method),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.Data["grant"] = grantMap
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *UpdateNodeSSHAction) RunPost(params struct {
|
|
||||||
NodeId int64
|
|
||||||
LoginId int64
|
|
||||||
SshHost string
|
|
||||||
SshPort int
|
|
||||||
GrantId int64
|
|
||||||
|
|
||||||
Must *actions.Must
|
|
||||||
}) {
|
|
||||||
params.Must.
|
|
||||||
Field("sshHost", params.SshHost).
|
|
||||||
Require("请输入SSH主机地址").
|
|
||||||
Field("sshPort", params.SshPort).
|
|
||||||
Gt(0, "SSH主机端口需要大于0").
|
|
||||||
Lt(65535, "SSH主机端口需要小于65535")
|
|
||||||
|
|
||||||
if params.GrantId <= 0 {
|
|
||||||
this.Fail("需要选择或填写至少一个认证信息")
|
|
||||||
}
|
|
||||||
|
|
||||||
login := &pb.NodeLogin{
|
|
||||||
Id: params.LoginId,
|
|
||||||
Name: "SSH",
|
|
||||||
Type: "ssh",
|
|
||||||
Params: maps.Map{
|
|
||||||
"grantId": params.GrantId,
|
|
||||||
"host": params.SshHost,
|
|
||||||
"port": params.SshPort,
|
|
||||||
}.AsJSON(),
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := this.RPC().NSNodeRPC().UpdateNSNodeLogin(this.AdminContext(), &pb.UpdateNSNodeLoginRequest{
|
|
||||||
NsNodeId: params.NodeId,
|
|
||||||
NodeLogin: login,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建日志
|
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "修改节点 %d 配置", params.NodeId)
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
||||||
|
|
||||||
package cluster
|
|
||||||
|
|
||||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
|
|
||||||
type UpgradeRemoteAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *UpgradeRemoteAction) Init() {
|
|
||||||
this.Nav("", "", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *UpgradeRemoteAction) RunGet(params struct{}) {
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
package clusterutils
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/actions"
|
|
||||||
"github.com/iwind/TeaGo/logs"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ClusterHelper 单个集群的帮助
|
|
||||||
type ClusterHelper struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewClusterHelper() *ClusterHelper {
|
|
||||||
return &ClusterHelper{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *ClusterHelper) BeforeAction(actionPtr actions.ActionWrapper) (goNext bool) {
|
|
||||||
action := actionPtr.Object()
|
|
||||||
if action.Request.Method != http.MethodGet {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
action.Data["teaMenu"] = "ns"
|
|
||||||
|
|
||||||
selectedTabbar := action.Data.GetString("mainTab")
|
|
||||||
clusterId := action.ParamInt64("clusterId")
|
|
||||||
clusterIdString := strconv.FormatInt(clusterId, 10)
|
|
||||||
action.Data["clusterId"] = clusterId
|
|
||||||
|
|
||||||
if clusterId > 0 {
|
|
||||||
rpcClient, err := rpc.SharedRPC()
|
|
||||||
if err != nil {
|
|
||||||
logs.Error(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
clusterResp, err := rpcClient.NSClusterRPC().FindEnabledNSCluster(actionPtr.(actionutils.ActionInterface).AdminContext(), &pb.FindEnabledNSClusterRequest{
|
|
||||||
NsClusterId: clusterId,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
logs.Error(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cluster := clusterResp.NsCluster
|
|
||||||
if cluster == nil {
|
|
||||||
action.WriteString("can not find ns cluster")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tabbar := actionutils.NewTabbar()
|
|
||||||
tabbar.Add("集群列表", "", "/ns/clusters", "", false)
|
|
||||||
tabbar.Add("集群节点", "", "/ns/clusters/cluster?clusterId="+clusterIdString, "server", selectedTabbar == "node")
|
|
||||||
tabbar.Add("集群设置", "", "/ns/clusters/cluster/settings?clusterId="+clusterIdString, "setting", selectedTabbar == "setting")
|
|
||||||
tabbar.Add("删除集群", "", "/ns/clusters/cluster/delete?clusterId="+clusterIdString, "trash", selectedTabbar == "delete")
|
|
||||||
|
|
||||||
{
|
|
||||||
m := tabbar.Add("当前集群:"+cluster.Name, "", "/ns/clusters/cluster?clusterId="+clusterIdString, "", false)
|
|
||||||
m["right"] = true
|
|
||||||
}
|
|
||||||
actionutils.SetTabbar(action, tabbar)
|
|
||||||
|
|
||||||
// 左侧菜单
|
|
||||||
secondMenuItem := action.Data.GetString("secondMenuItem")
|
|
||||||
switch selectedTabbar {
|
|
||||||
case "setting":
|
|
||||||
action.Data["leftMenuItems"] = this.createSettingMenu(cluster, secondMenuItem)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置菜单
|
|
||||||
func (this *ClusterHelper) createSettingMenu(cluster *pb.NSCluster, selectedItem string) (items []maps.Map) {
|
|
||||||
clusterId := numberutils.FormatInt64(cluster.Id)
|
|
||||||
return []maps.Map{
|
|
||||||
{
|
|
||||||
"name": "基础设置",
|
|
||||||
"url": "/ns/clusters/cluster/settings?clusterId=" + clusterId,
|
|
||||||
"isActive": selectedItem == "basic",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "访问日志",
|
|
||||||
"url": "/ns/clusters/cluster/settings/accessLog?clusterId=" + clusterId,
|
|
||||||
"isActive": selectedItem == "accessLog",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "递归DNS",
|
|
||||||
"url": "/ns/clusters/cluster/settings/recursion?clusterId=" + clusterId,
|
|
||||||
"isActive": selectedItem == "recursion",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
||||||
|
|
||||||
package clusters
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/actions"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CreateAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *CreateAction) Init() {
|
|
||||||
this.Nav("", "", "create")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *CreateAction) RunGet(params struct{}) {
|
|
||||||
// 默认的访问日志设置
|
|
||||||
this.Data["accessLogRef"] = &dnsconfigs.NSAccessLogRef{
|
|
||||||
IsOn: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *CreateAction) RunPost(params struct {
|
|
||||||
Name string
|
|
||||||
AccessLogJSON []byte
|
|
||||||
|
|
||||||
Must *actions.Must
|
|
||||||
CSRF *actionutils.CSRF
|
|
||||||
}) {
|
|
||||||
var clusterId int64
|
|
||||||
defer func() {
|
|
||||||
this.CreateLogInfo("创建域名服务集群 %d", clusterId)
|
|
||||||
}()
|
|
||||||
|
|
||||||
params.Must.
|
|
||||||
Field("name", params.Name).
|
|
||||||
Require("请输入集群名称")
|
|
||||||
|
|
||||||
// 校验访问日志设置
|
|
||||||
ref := &dnsconfigs.NSAccessLogRef{}
|
|
||||||
err := json.Unmarshal(params.AccessLogJSON, ref)
|
|
||||||
if err != nil {
|
|
||||||
this.Fail("数据格式错误:" + err.Error())
|
|
||||||
}
|
|
||||||
err = ref.Init()
|
|
||||||
if err != nil {
|
|
||||||
this.Fail("数据格式错误:" + err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := this.RPC().NSClusterRPC().CreateNSCluster(this.AdminContext(), &pb.CreateNSClusterRequest{
|
|
||||||
Name: params.Name,
|
|
||||||
AccessLogJSON: params.AccessLogJSON,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
clusterId = resp.NsClusterId
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
||||||
|
|
||||||
package clusters
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
"github.com/iwind/TeaGo/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type IndexAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) Init() {
|
|
||||||
this.Nav("", "", "index")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) RunGet(params struct{}) {
|
|
||||||
countResp, err := this.RPC().NSClusterRPC().CountAllEnabledNSClusters(this.AdminContext(), &pb.CountAllEnabledNSClustersRequest{})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
count := countResp.Count
|
|
||||||
page := this.NewPage(count)
|
|
||||||
this.Data["page"] = page.AsHTML()
|
|
||||||
|
|
||||||
clustersResp, err := this.RPC().NSClusterRPC().ListEnabledNSClusters(this.AdminContext(), &pb.ListEnabledNSClustersRequest{
|
|
||||||
Offset: page.Offset,
|
|
||||||
Size: page.Size,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
clusterMaps := []maps.Map{}
|
|
||||||
for _, cluster := range clustersResp.NsClusters {
|
|
||||||
// 全部节点数量
|
|
||||||
countNodesResp, err := this.RPC().NSNodeRPC().CountAllEnabledNSNodesMatch(this.AdminContext(), &pb.CountAllEnabledNSNodesMatchRequest{NsClusterId: cluster.Id})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 在线节点
|
|
||||||
countActiveNodesResp, err := this.RPC().NSNodeRPC().CountAllEnabledNSNodesMatch(this.AdminContext(), &pb.CountAllEnabledNSNodesMatchRequest{
|
|
||||||
NsClusterId: cluster.Id,
|
|
||||||
ActiveState: types.Int32(configutils.BoolStateYes),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 需要升级的节点
|
|
||||||
countUpgradeNodesResp, err := this.RPC().NSNodeRPC().CountAllUpgradeNSNodesWithNSClusterId(this.AdminContext(), &pb.CountAllUpgradeNSNodesWithNSClusterIdRequest{NsClusterId: cluster.Id})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
clusterMaps = append(clusterMaps, maps.Map{
|
|
||||||
"id": cluster.Id,
|
|
||||||
"name": cluster.Name,
|
|
||||||
"isOn": cluster.IsOn,
|
|
||||||
"countAllNodes": countNodesResp.Count,
|
|
||||||
"countActiveNodes": countActiveNodesResp.Count,
|
|
||||||
"countUpgradeNodes": countUpgradeNodesResp.Count,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
this.Data["clusters"] = clusterMaps
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
package logs
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type IndexAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) Init() {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) RunGet(params struct {
|
|
||||||
DayFrom string
|
|
||||||
DayTo string
|
|
||||||
Keyword string
|
|
||||||
Level string
|
|
||||||
}) {
|
|
||||||
this.Data["dayFrom"] = params.DayFrom
|
|
||||||
this.Data["dayTo"] = params.DayTo
|
|
||||||
this.Data["keyword"] = params.Keyword
|
|
||||||
this.Data["level"] = params.Level
|
|
||||||
|
|
||||||
countResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{
|
|
||||||
NodeId: 0,
|
|
||||||
Role: nodeconfigs.NodeRoleDNS,
|
|
||||||
DayFrom: params.DayFrom,
|
|
||||||
DayTo: params.DayTo,
|
|
||||||
Keyword: params.Keyword,
|
|
||||||
Level: params.Level,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
count := countResp.Count
|
|
||||||
page := this.NewPage(count)
|
|
||||||
this.Data["page"] = page.AsHTML()
|
|
||||||
|
|
||||||
logsResp, err := this.RPC().NodeLogRPC().ListNodeLogs(this.AdminContext(), &pb.ListNodeLogsRequest{
|
|
||||||
NodeId: 0,
|
|
||||||
Role: nodeconfigs.NodeRoleDNS,
|
|
||||||
DayFrom: params.DayFrom,
|
|
||||||
DayTo: params.DayTo,
|
|
||||||
Keyword: params.Keyword,
|
|
||||||
Level: params.Level,
|
|
||||||
Offset: page.Offset,
|
|
||||||
Size: page.Size,
|
|
||||||
})
|
|
||||||
|
|
||||||
logs := []maps.Map{}
|
|
||||||
for _, log := range logsResp.NodeLogs {
|
|
||||||
// 节点信息
|
|
||||||
nodeResp, err := this.RPC().NSNodeRPC().FindEnabledNSNode(this.AdminContext(), &pb.FindEnabledNSNodeRequest{NsNodeId: log.NodeId})
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
node := nodeResp.NsNode
|
|
||||||
if node == nil || node.NsCluster == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
logs = append(logs, maps.Map{
|
|
||||||
"tag": log.Tag,
|
|
||||||
"description": log.Description,
|
|
||||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),
|
|
||||||
"level": log.Level,
|
|
||||||
"isToday": timeutil.FormatTime("Y-m-d", log.CreatedAt) == timeutil.Format("Y-m-d"),
|
|
||||||
"count": log.Count,
|
|
||||||
"node": maps.Map{
|
|
||||||
"id": node.Id,
|
|
||||||
"cluster": maps.Map{
|
|
||||||
"id": node.NsCluster.Id,
|
|
||||||
"name": node.NsCluster.Name,
|
|
||||||
},
|
|
||||||
"name": node.Name,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
this.Data["logs"] = logs
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package clusters
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
)
|
|
||||||
|
|
||||||
type OptionsAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *OptionsAction) RunPost(params struct{}) {
|
|
||||||
clustersResp, err := this.RPC().NSClusterRPC().FindAllEnabledNSClusters(this.AdminContext(), &pb.FindAllEnabledNSClustersRequest{})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
clusterMaps := []maps.Map{}
|
|
||||||
for _, cluster := range clustersResp.NsClusters {
|
|
||||||
clusterMaps = append(clusterMaps, maps.Map{
|
|
||||||
"id": cluster.Id,
|
|
||||||
"name": cluster.Name,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
this.Data["clusters"] = clusterMaps
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -1,156 +0,0 @@
|
|||||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
||||||
|
|
||||||
package test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dns/domains/domainutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/actions"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
"github.com/iwind/TeaGo/types"
|
|
||||||
"github.com/miekg/dns"
|
|
||||||
"net"
|
|
||||||
"regexp"
|
|
||||||
)
|
|
||||||
|
|
||||||
type IndexAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) Init() {
|
|
||||||
this.Nav("", "", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) RunGet(params struct{}) {
|
|
||||||
// 集群列表
|
|
||||||
clustersResp, err := this.RPC().NSClusterRPC().FindAllEnabledNSClusters(this.AdminContext(), &pb.FindAllEnabledNSClustersRequest{})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var clusterMaps = []maps.Map{}
|
|
||||||
for _, cluster := range clustersResp.NsClusters {
|
|
||||||
if !cluster.IsOn {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
countNodesResp, err := this.RPC().NSNodeRPC().CountAllEnabledNSNodesMatch(this.AdminContext(), &pb.CountAllEnabledNSNodesMatchRequest{
|
|
||||||
NsClusterId: cluster.Id,
|
|
||||||
InstallState: 0,
|
|
||||||
ActiveState: 0,
|
|
||||||
Keyword: "",
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var countNodes = countNodesResp.Count
|
|
||||||
if countNodes <= 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
clusterMaps = append(clusterMaps, maps.Map{
|
|
||||||
"id": cluster.Id,
|
|
||||||
"name": cluster.Name,
|
|
||||||
"countNodes": countNodes,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
this.Data["clusters"] = clusterMaps
|
|
||||||
|
|
||||||
// 记录类型
|
|
||||||
this.Data["recordTypes"] = dnsconfigs.FindAllRecordTypeDefinitions()
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) RunPost(params struct {
|
|
||||||
NodeId int64
|
|
||||||
Domain string
|
|
||||||
Type string
|
|
||||||
Ip string
|
|
||||||
ClientIP string
|
|
||||||
|
|
||||||
Must *actions.Must
|
|
||||||
}) {
|
|
||||||
nodeResp, err := this.RPC().NSNodeRPC().FindEnabledNSNode(this.AdminContext(), &pb.FindEnabledNSNodeRequest{NsNodeId: params.NodeId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var node = nodeResp.NsNode
|
|
||||||
if node == nil {
|
|
||||||
this.Fail("找不到要测试的节点")
|
|
||||||
}
|
|
||||||
|
|
||||||
var isOk = false
|
|
||||||
var errMsg string
|
|
||||||
var isNetError = false
|
|
||||||
var result string
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
this.Data["isOk"] = isOk
|
|
||||||
this.Data["err"] = errMsg
|
|
||||||
this.Data["isNetErr"] = isNetError
|
|
||||||
this.Data["result"] = result
|
|
||||||
this.Success()
|
|
||||||
}()
|
|
||||||
|
|
||||||
if !domainutils.ValidateDomainFormat(params.Domain) {
|
|
||||||
errMsg = "域名格式错误"
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
recordType, ok := dns.StringToType[params.Type]
|
|
||||||
if !ok {
|
|
||||||
errMsg = "不支持此记录类型"
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(params.ClientIP) > 0 && net.ParseIP(params.ClientIP) == nil {
|
|
||||||
errMsg = "客户端IP格式不正确"
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var optionId int64
|
|
||||||
if len(params.ClientIP) > 0 {
|
|
||||||
optionResp, err := this.RPC().NSQuestionOptionRPC().CreateNSQuestionOption(this.AdminContext(), &pb.CreateNSQuestionOptionRequest{
|
|
||||||
Name: "setRemoteAddr",
|
|
||||||
ValuesJSON: maps.Map{"ip": params.ClientIP}.AsJSON(),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
optionId = optionResp.NsQuestionOptionId
|
|
||||||
defer func() {
|
|
||||||
_, err = this.RPC().NSQuestionOptionRPC().DeleteNSQuestionOption(this.AdminContext(), &pb.DeleteNSQuestionOptionRequest{NsQuestionOptionId: optionId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
c := new(dns.Client)
|
|
||||||
m := new(dns.Msg)
|
|
||||||
var domain = params.Domain + "."
|
|
||||||
if optionId > 0 {
|
|
||||||
domain = "$" + types.String(optionId) + "-" + domain
|
|
||||||
}
|
|
||||||
m.SetQuestion(domain, recordType)
|
|
||||||
r, _, err := c.Exchange(m, params.Ip+":53")
|
|
||||||
if err != nil {
|
|
||||||
errMsg = "解析过程中出错:" + err.Error()
|
|
||||||
|
|
||||||
// 是否为网络错误
|
|
||||||
if regexp.MustCompile(`timeout|connect`).MatchString(err.Error()) {
|
|
||||||
isNetError = true
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
result = r.String()
|
|
||||||
result = regexp.MustCompile(`\$\d+-`).ReplaceAllString(result, "")
|
|
||||||
isOk = true
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
||||||
|
|
||||||
package test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
)
|
|
||||||
|
|
||||||
type NodeOptionsAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *NodeOptionsAction) RunPost(params struct {
|
|
||||||
ClusterId int64
|
|
||||||
}) {
|
|
||||||
nodesResp, err := this.RPC().NSNodeRPC().FindAllEnabledNSNodesWithNSClusterId(this.AdminContext(), &pb.FindAllEnabledNSNodesWithNSClusterIdRequest{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
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
package users
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
)
|
|
||||||
|
|
||||||
type OptionsAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *OptionsAction) RunPost(params struct{}) {
|
|
||||||
usersResp, err := this.RPC().UserRPC().ListEnabledUsers(this.AdminContext(), &pb.ListEnabledUsersRequest{
|
|
||||||
Offset: 0,
|
|
||||||
Size: 10000, // TODO 改进 <ns-user-selector> 组件
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
userMaps := []maps.Map{}
|
|
||||||
for _, user := range usersResp.Users {
|
|
||||||
userMaps = append(userMaps, maps.Map{
|
|
||||||
"id": user.Id,
|
|
||||||
"fullname": user.Fullname,
|
|
||||||
"username": user.Username,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
this.Data["users"] = userMaps
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user