From 81a2967683693d8e6cd28e4988ea16851a271b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Wed, 15 Jun 2022 16:32:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=B8=8D=E5=BF=85=E8=A6=81?= =?UTF-8?q?=E7=9A=84=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/ns/clusters/cluster/node/index.go | 182 -------------- .../ns/clusters/cluster/node/install.go | 117 --------- .../default/ns/clusters/cluster/node/logs.go | 75 ------ .../default/ns/clusters/cluster/node/start.go | 30 --- .../ns/clusters/cluster/node/status.go | 46 ---- .../default/ns/clusters/cluster/node/stop.go | 30 --- .../ns/clusters/cluster/node/update.go | 233 ------------------ .../cluster/node/updateInstallStatus.go | 30 --- .../cluster/settings/accessLog/index.go | 73 ------ .../ns/clusters/cluster/settings/index.go | 69 ------ .../cluster/settings/recursion/index.go | 68 ----- .../web/actions/default/ns/domains/create.go | 73 ------ .../web/actions/default/ns/domains/delete.go | 26 -- .../web/actions/default/ns/domains/domain.go | 72 ------ .../default/ns/domains/domainutils/utils.go | 55 ----- .../web/actions/default/ns/domains/index.go | 96 -------- .../default/ns/domains/keys/createPopup.go | 86 ------- .../actions/default/ns/domains/keys/delete.go | 26 -- .../default/ns/domains/keys/generateSecret.go | 29 --- .../actions/default/ns/domains/keys/index.go | 68 ----- .../default/ns/domains/keys/updatePopup.go | 100 -------- .../default/ns/domains/records/createPopup.go | 94 ------- .../default/ns/domains/records/delete.go | 26 -- .../default/ns/domains/records/index.go | 93 ------- .../default/ns/domains/records/updatePopup.go | 115 --------- .../web/actions/default/ns/domains/tsig.go | 80 ------ .../web/actions/default/ns/domains/update.go | 96 -------- .../actions/default/ns/routes/createPopup.go | 63 ----- .../web/actions/default/ns/routes/delete.go | 26 -- .../web/actions/default/ns/routes/index.go | 41 --- .../web/actions/default/ns/routes/options.go | 86 ------- .../web/actions/default/ns/routes/route.go | 17 -- .../web/actions/default/ns/routes/sort.go | 26 -- .../actions/default/ns/routes/updatePopup.go | 78 ------ .../default/ns/settings/accesslogs/index.go | 77 ------ .../web/actions/default/ns/settings/index.go | 17 -- .../ns/settings/settingutils/helper.go | 28 --- 37 files changed, 2547 deletions(-) delete mode 100644 internal/web/actions/default/ns/clusters/cluster/node/index.go delete mode 100644 internal/web/actions/default/ns/clusters/cluster/node/install.go delete mode 100644 internal/web/actions/default/ns/clusters/cluster/node/logs.go delete mode 100644 internal/web/actions/default/ns/clusters/cluster/node/start.go delete mode 100644 internal/web/actions/default/ns/clusters/cluster/node/status.go delete mode 100644 internal/web/actions/default/ns/clusters/cluster/node/stop.go delete mode 100644 internal/web/actions/default/ns/clusters/cluster/node/update.go delete mode 100644 internal/web/actions/default/ns/clusters/cluster/node/updateInstallStatus.go delete mode 100644 internal/web/actions/default/ns/clusters/cluster/settings/accessLog/index.go delete mode 100644 internal/web/actions/default/ns/clusters/cluster/settings/index.go delete mode 100644 internal/web/actions/default/ns/clusters/cluster/settings/recursion/index.go delete mode 100644 internal/web/actions/default/ns/domains/create.go delete mode 100644 internal/web/actions/default/ns/domains/delete.go delete mode 100644 internal/web/actions/default/ns/domains/domain.go delete mode 100644 internal/web/actions/default/ns/domains/domainutils/utils.go delete mode 100644 internal/web/actions/default/ns/domains/index.go delete mode 100644 internal/web/actions/default/ns/domains/keys/createPopup.go delete mode 100644 internal/web/actions/default/ns/domains/keys/delete.go delete mode 100644 internal/web/actions/default/ns/domains/keys/generateSecret.go delete mode 100644 internal/web/actions/default/ns/domains/keys/index.go delete mode 100644 internal/web/actions/default/ns/domains/keys/updatePopup.go delete mode 100644 internal/web/actions/default/ns/domains/records/createPopup.go delete mode 100644 internal/web/actions/default/ns/domains/records/delete.go delete mode 100644 internal/web/actions/default/ns/domains/records/index.go delete mode 100644 internal/web/actions/default/ns/domains/records/updatePopup.go delete mode 100644 internal/web/actions/default/ns/domains/tsig.go delete mode 100644 internal/web/actions/default/ns/domains/update.go delete mode 100644 internal/web/actions/default/ns/routes/createPopup.go delete mode 100644 internal/web/actions/default/ns/routes/delete.go delete mode 100644 internal/web/actions/default/ns/routes/index.go delete mode 100644 internal/web/actions/default/ns/routes/options.go delete mode 100644 internal/web/actions/default/ns/routes/route.go delete mode 100644 internal/web/actions/default/ns/routes/sort.go delete mode 100644 internal/web/actions/default/ns/routes/updatePopup.go delete mode 100644 internal/web/actions/default/ns/settings/accesslogs/index.go delete mode 100644 internal/web/actions/default/ns/settings/index.go delete mode 100644 internal/web/actions/default/ns/settings/settingutils/helper.go diff --git a/internal/web/actions/default/ns/clusters/cluster/node/index.go b/internal/web/actions/default/ns/clusters/cluster/node/index.go deleted file mode 100644 index 8637e049..00000000 --- a/internal/web/actions/default/ns/clusters/cluster/node/index.go +++ /dev/null @@ -1,182 +0,0 @@ -package node - -import ( - "encoding/json" - "fmt" - "github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils" - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils" - "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" - "github.com/iwind/TeaGo/maps" - "time" -) - -type IndexAction struct { - actionutils.ParentAction -} - -func (this *IndexAction) Init() { - this.Nav("", "node", "node") - this.SecondMenu("nodes") -} - -func (this *IndexAction) RunGet(params struct { - NodeId int64 -}) { - this.Data["nodeId"] = params.NodeId - - nodeResp, err := this.RPC().NSNodeRPC().FindEnabledNSNode(this.AdminContext(), &pb.FindEnabledNSNodeRequest{NsNodeId: params.NodeId}) - if err != nil { - this.ErrorPage(err) - return - } - node := nodeResp.NsNode - if node == nil { - this.WriteString("找不到要操作的节点") - return - } - - var clusterMap maps.Map = nil - if node.NsCluster != nil { - clusterId := node.NsCluster.Id - clusterResp, err := this.RPC().NSClusterRPC().FindEnabledNSCluster(this.AdminContext(), &pb.FindEnabledNSClusterRequest{NsClusterId: clusterId}) - if err != nil { - this.ErrorPage(err) - return - } - cluster := clusterResp.NsCluster - if cluster != nil { - clusterMap = maps.Map{ - "id": cluster.Id, - "name": cluster.Name, - "installDir": cluster.InstallDir, - } - } - } - - // IP地址 - ipAddressesResp, err := this.RPC().NodeIPAddressRPC().FindAllEnabledNodeIPAddressesWithNodeId(this.AdminContext(), &pb.FindAllEnabledNodeIPAddressesWithNodeIdRequest{ - NodeId: params.NodeId, - Role: nodeconfigs.NodeRoleDNS, - }) - if err != nil { - this.ErrorPage(err) - return - } - ipAddressMaps := []maps.Map{} - for _, addr := range ipAddressesResp.NodeIPAddresses { - ipAddressMaps = append(ipAddressMaps, maps.Map{ - "id": addr.Id, - "name": addr.Name, - "ip": addr.Ip, - "canAccess": addr.CanAccess, - "isOn": addr.IsOn, - "isUp": addr.IsUp, - }) - } - - // 运行状态 - status := &nodeconfigs.NodeStatus{} - if len(node.StatusJSON) > 0 { - err = json.Unmarshal(node.StatusJSON, &status) - if err != nil { - this.ErrorPage(err) - return - } - status.IsActive = status.IsActive && time.Now().Unix()-status.UpdatedAt <= 60 // N秒之内认为活跃 - } - - // 检查是否有新版本 - if len(status.OS) > 0 { - checkVersionResp, err := this.RPC().NSNodeRPC().CheckNSNodeLatestVersion(this.AdminContext(), &pb.CheckNSNodeLatestVersionRequest{ - Os: status.OS, - Arch: status.Arch, - CurrentVersion: status.BuildVersion, - }) - if err != nil { - this.ErrorPage(err) - return - } - this.Data["shouldUpgrade"] = checkVersionResp.HasNewVersion - this.Data["newVersion"] = checkVersionResp.NewVersion - } else { - this.Data["shouldUpgrade"] = false - this.Data["newVersion"] = "" - } - - // 登录信息 - var loginMap maps.Map = nil - if node.NodeLogin != nil { - loginParams := maps.Map{} - if len(node.NodeLogin.Params) > 0 { - err = json.Unmarshal(node.NodeLogin.Params, &loginParams) - if err != nil { - this.ErrorPage(err) - return - } - } - - grantMap := maps.Map{} - grantId := loginParams.GetInt64("grantId") - if grantId > 0 { - grantResp, err := this.RPC().NodeGrantRPC().FindEnabledNodeGrant(this.AdminContext(), &pb.FindEnabledNodeGrantRequest{NodeGrantId: grantId}) - if err != nil { - this.ErrorPage(err) - return - } - 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), - "username": grantResp.NodeGrant.Username, - } - } - } - - loginMap = maps.Map{ - "id": node.NodeLogin.Id, - "name": node.NodeLogin.Name, - "type": node.NodeLogin.Type, - "params": loginParams, - "grant": grantMap, - } - } - - this.Data["node"] = maps.Map{ - "id": node.Id, - "name": node.Name, - "ipAddresses": ipAddressMaps, - "cluster": clusterMap, - "installDir": node.InstallDir, - "isInstalled": node.IsInstalled, - "uniqueId": node.UniqueId, - "secret": node.Secret, - "isOn": node.IsOn, - - "status": maps.Map{ - "isActive": node.IsActive && status.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), - "connectionCount": status.ConnectionCount, - "buildVersion": status.BuildVersion, - "cpuPhysicalCount": status.CPUPhysicalCount, - "cpuLogicalCount": status.CPULogicalCount, - "load1m": fmt.Sprintf("%.2f", status.Load1m), - "load5m": fmt.Sprintf("%.2f", status.Load5m), - "load15m": fmt.Sprintf("%.2f", status.Load15m), - "cacheTotalDiskSize": numberutils.FormatBytes(status.CacheTotalDiskSize), - "cacheTotalMemorySize": numberutils.FormatBytes(status.CacheTotalMemorySize), - }, - - "login": loginMap, - } - - this.Show() -} diff --git a/internal/web/actions/default/ns/clusters/cluster/node/install.go b/internal/web/actions/default/ns/clusters/cluster/node/install.go deleted file mode 100644 index 6d437f03..00000000 --- a/internal/web/actions/default/ns/clusters/cluster/node/install.go +++ /dev/null @@ -1,117 +0,0 @@ -package node - -import ( - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" - "github.com/iwind/TeaGo/actions" - "github.com/iwind/TeaGo/maps" - "strings" -) - -// InstallAction 安装节点 -type InstallAction struct { - actionutils.ParentAction -} - -func (this *InstallAction) Init() { - this.Nav("", "node", "install") - this.SecondMenu("nodes") -} - -func (this *InstallAction) RunGet(params struct { - NodeId int64 -}) { - this.Data["nodeId"] = params.NodeId - - // 节点 - nodeResp, err := this.RPC().NSNodeRPC().FindEnabledNSNode(this.AdminContext(), &pb.FindEnabledNSNodeRequest{NsNodeId: params.NodeId}) - if err != nil { - this.ErrorPage(err) - return - } - node := nodeResp.NsNode - if node == nil { - this.WriteString("找不到要操作的节点") - return - } - - // 安装信息 - if node.InstallStatus != nil { - this.Data["installStatus"] = maps.Map{ - "isRunning": node.InstallStatus.IsRunning, - "isFinished": node.InstallStatus.IsFinished, - "isOk": node.InstallStatus.IsOk, - "updatedAt": node.InstallStatus.UpdatedAt, - "error": node.InstallStatus.Error, - } - } else { - this.Data["installStatus"] = nil - } - - // 集群 - var clusterMap maps.Map = nil - if node.NsCluster != nil { - clusterId := node.NsCluster.Id - clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{NodeClusterId: clusterId}) - if err != nil { - this.ErrorPage(err) - return - } - cluster := clusterResp.NodeCluster - if cluster != nil { - clusterMap = maps.Map{ - "id": cluster.Id, - "name": cluster.Name, - "installDir": cluster.InstallDir, - } - } - } - - // API节点列表 - apiNodesResp, err := this.RPC().APINodeRPC().FindAllEnabledAPINodes(this.AdminContext(), &pb.FindAllEnabledAPINodesRequest{}) - if err != nil { - this.ErrorPage(err) - return - } - apiNodes := apiNodesResp.ApiNodes - apiEndpoints := []string{} - for _, apiNode := range apiNodes { - if !apiNode.IsOn { - continue - } - apiEndpoints = append(apiEndpoints, apiNode.AccessAddrs...) - } - this.Data["apiEndpoints"] = "\"" + strings.Join(apiEndpoints, "\", \"") + "\"" - - this.Data["node"] = maps.Map{ - "id": node.Id, - "name": node.Name, - "installDir": node.InstallDir, - "isInstalled": node.IsInstalled, - "uniqueId": node.UniqueId, - "secret": node.Secret, - "cluster": clusterMap, - } - - this.Show() -} - -// RunPost 开始安装 -func (this *InstallAction) RunPost(params struct { - NodeId int64 - - Must *actions.Must -}) { - // 创建日志 - defer this.CreateLogInfo("安装节点 %d", params.NodeId) - - _, err := this.RPC().NSNodeRPC().InstallNSNode(this.AdminContext(), &pb.InstallNSNodeRequest{ - NsNodeId: params.NodeId, - }) - if err != nil { - this.ErrorPage(err) - return - } - - this.Success() -} diff --git a/internal/web/actions/default/ns/clusters/cluster/node/logs.go b/internal/web/actions/default/ns/clusters/cluster/node/logs.go deleted file mode 100644 index ddf0e9cb..00000000 --- a/internal/web/actions/default/ns/clusters/cluster/node/logs.go +++ /dev/null @@ -1,75 +0,0 @@ -package node - -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 LogsAction struct { - actionutils.ParentAction -} - -func (this *LogsAction) Init() { - this.Nav("", "node", "log") - this.SecondMenu("nodes") -} - -func (this *LogsAction) RunGet(params struct { - NodeId int64 - DayFrom string - DayTo string - Keyword string - Level string -}) { - this.Data["nodeId"] = params.NodeId - 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{ - Role: nodeconfigs.NodeRoleDNS, - NodeId: params.NodeId, - 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, 20) - - logsResp, err := this.RPC().NodeLogRPC().ListNodeLogs(this.AdminContext(), &pb.ListNodeLogsRequest{ - NodeId: params.NodeId, - 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 { - 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, - }) - } - this.Data["logs"] = logs - - this.Data["page"] = page.AsHTML() - - this.Show() -} diff --git a/internal/web/actions/default/ns/clusters/cluster/node/start.go b/internal/web/actions/default/ns/clusters/cluster/node/start.go deleted file mode 100644 index 658232b6..00000000 --- a/internal/web/actions/default/ns/clusters/cluster/node/start.go +++ /dev/null @@ -1,30 +0,0 @@ -package node - -import ( - "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" -) - -type StartAction struct { - actionutils.ParentAction -} - -func (this *StartAction) RunPost(params struct { - NodeId int64 -}) { - resp, err := this.RPC().NSNodeRPC().StartNSNode(this.AdminContext(), &pb.StartNSNodeRequest{NsNodeId: params.NodeId}) - if err != nil { - this.ErrorPage(err) - return - } - - // 创建日志 - defer this.CreateLog(oplogs.LevelInfo, "远程启动节点 %d", params.NodeId) - - if resp.IsOk { - this.Success() - } - - this.Fail("启动失败:" + resp.Error) -} diff --git a/internal/web/actions/default/ns/clusters/cluster/node/status.go b/internal/web/actions/default/ns/clusters/cluster/node/status.go deleted file mode 100644 index 869e5d2d..00000000 --- a/internal/web/actions/default/ns/clusters/cluster/node/status.go +++ /dev/null @@ -1,46 +0,0 @@ -package node - -import ( - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" - "github.com/iwind/TeaGo/maps" -) - -// StatusAction 节点状态 -type StatusAction struct { - actionutils.ParentAction -} - -func (this *StatusAction) RunPost(params struct { - NodeId int64 -}) { - // 节点 - nodeResp, err := this.RPC().NSNodeRPC().FindEnabledNSNode(this.AdminContext(), &pb.FindEnabledNSNodeRequest{NsNodeId: params.NodeId}) - if err != nil { - this.ErrorPage(err) - return - } - node := nodeResp.NsNode - if node == nil { - this.WriteString("找不到要操作的节点") - return - } - - // 安装信息 - if node.InstallStatus != nil { - this.Data["installStatus"] = maps.Map{ - "isRunning": node.InstallStatus.IsRunning, - "isFinished": node.InstallStatus.IsFinished, - "isOk": node.InstallStatus.IsOk, - "updatedAt": node.InstallStatus.UpdatedAt, - "error": node.InstallStatus.Error, - "errorCode": node.InstallStatus.ErrorCode, - } - } else { - this.Data["installStatus"] = nil - } - - this.Data["isInstalled"] = node.IsInstalled - - this.Success() -} diff --git a/internal/web/actions/default/ns/clusters/cluster/node/stop.go b/internal/web/actions/default/ns/clusters/cluster/node/stop.go deleted file mode 100644 index 30bfcf6c..00000000 --- a/internal/web/actions/default/ns/clusters/cluster/node/stop.go +++ /dev/null @@ -1,30 +0,0 @@ -package node - -import ( - "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" -) - -type StopAction struct { - actionutils.ParentAction -} - -func (this *StopAction) RunPost(params struct { - NodeId int64 -}) { - resp, err := this.RPC().NSNodeRPC().StopNSNode(this.AdminContext(), &pb.StopNSNodeRequest{NsNodeId: params.NodeId}) - if err != nil { - this.ErrorPage(err) - return - } - - // 创建日志 - defer this.CreateLog(oplogs.LevelInfo, "远程停止节点 %d", params.NodeId) - - if resp.IsOk { - this.Success() - } - - this.Fail("执行失败:" + resp.Error) -} diff --git a/internal/web/actions/default/ns/clusters/cluster/node/update.go b/internal/web/actions/default/ns/clusters/cluster/node/update.go deleted file mode 100644 index 6589cc92..00000000 --- a/internal/web/actions/default/ns/clusters/cluster/node/update.go +++ /dev/null @@ -1,233 +0,0 @@ -package node - -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/EdgeAdmin/internal/web/actions/default/nodes/ipAddresses/ipaddressutils" - "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" - "github.com/iwind/TeaGo/actions" - "github.com/iwind/TeaGo/maps" -) - -type UpdateAction struct { - actionutils.ParentAction -} - -func (this *UpdateAction) Init() { - this.Nav("", "node", "update") - this.SecondMenu("nodes") -} - -func (this *UpdateAction) RunGet(params struct { - NodeId int64 -}) { - this.Data["nodeId"] = params.NodeId - - nodeResp, err := this.RPC().NSNodeRPC().FindEnabledNSNode(this.AdminContext(), &pb.FindEnabledNSNodeRequest{NsNodeId: params.NodeId}) - if err != nil { - this.ErrorPage(err) - return - } - node := nodeResp.NsNode - if node == nil { - this.WriteString("找不到要操作的节点") - return - } - - var clusterMap maps.Map = nil - if node.NsCluster != nil { - clusterMap = maps.Map{ - "id": node.NsCluster.Id, - "name": node.NsCluster.Name, - } - } - - // IP地址 - ipAddressesResp, err := this.RPC().NodeIPAddressRPC().FindAllEnabledNodeIPAddressesWithNodeId(this.AdminContext(), &pb.FindAllEnabledNodeIPAddressesWithNodeIdRequest{ - NodeId: params.NodeId, - Role: nodeconfigs.NodeRoleDNS, - }) - if err != nil { - this.ErrorPage(err) - return - } - ipAddressMaps := []maps.Map{} - for _, addr := range ipAddressesResp.NodeIPAddresses { - ipAddressMaps = append(ipAddressMaps, maps.Map{ - "id": addr.Id, - "name": addr.Name, - "ip": addr.Ip, - "canAccess": addr.CanAccess, - "isOn": addr.IsOn, - "isUp": addr.IsUp, - }) - } - - // 登录信息 - var loginMap maps.Map = nil - if node.NodeLogin != nil { - loginParams := maps.Map{} - if len(node.NodeLogin.Params) > 0 { - err = json.Unmarshal(node.NodeLogin.Params, &loginParams) - if err != nil { - this.ErrorPage(err) - return - } - } - - grantMap := maps.Map{} - grantId := loginParams.GetInt64("grantId") - if grantId > 0 { - grantResp, err := this.RPC().NodeGrantRPC().FindEnabledNodeGrant(this.AdminContext(), &pb.FindEnabledNodeGrantRequest{NodeGrantId: grantId}) - if err != nil { - this.ErrorPage(err) - return - } - 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), - "username": grantResp.NodeGrant.Username, - } - } - } - - loginMap = maps.Map{ - "id": node.NodeLogin.Id, - "name": node.NodeLogin.Name, - "type": node.NodeLogin.Type, - "params": loginParams, - "grant": grantMap, - } - } - - this.Data["node"] = maps.Map{ - "id": node.Id, - "name": node.Name, - "ipAddresses": ipAddressMaps, - "cluster": clusterMap, - "isOn": node.IsOn, - "login": loginMap, - } - - // 所有集群 - resp, err := this.RPC().NSClusterRPC().FindAllEnabledNSClusters(this.AdminContext(), &pb.FindAllEnabledNSClustersRequest{}) - if err != nil { - this.ErrorPage(err) - } - if err != nil { - this.ErrorPage(err) - return - } - clusterMaps := []maps.Map{} - for _, cluster := range resp.NsClusters { - clusterMaps = append(clusterMaps, maps.Map{ - "id": cluster.Id, - "name": cluster.Name, - }) - } - this.Data["clusters"] = clusterMaps - - this.Show() -} - -func (this *UpdateAction) RunPost(params struct { - LoginId int64 - GrantId int64 - SshHost string - SshPort int - - NodeId int64 - Name string - IPAddressesJSON []byte `alias:"ipAddressesJSON"` - ClusterId int64 - IsOn bool - - Must *actions.Must -}) { - // 创建日志 - defer this.CreateLog(oplogs.LevelInfo, "修改节点 %d", params.NodeId) - - if params.NodeId <= 0 { - this.Fail("要操作的节点不存在") - } - - params.Must. - Field("name", params.Name). - Require("请输入节点名称") - - // 检查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地址") - } - - // TODO 检查登录授权 - loginInfo := &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().UpdateNSNode(this.AdminContext(), &pb.UpdateNSNodeRequest{ - NsNodeId: params.NodeId, - Name: params.Name, - NsClusterId: params.ClusterId, - IsOn: params.IsOn, - NodeLogin: loginInfo, - }) - if err != nil { - this.ErrorPage(err) - return - } - - // 禁用老的IP地址 - _, err = this.RPC().NodeIPAddressRPC().DisableAllNodeIPAddressesWithNodeId(this.AdminContext(), &pb.DisableAllNodeIPAddressesWithNodeIdRequest{ - NodeId: params.NodeId, - Role: nodeconfigs.NodeRoleDNS, - }) - if err != nil { - this.ErrorPage(err) - return - } - - // 添加新的IP地址 - err = ipaddressutils.UpdateNodeIPAddresses(this.Parent(), params.NodeId, nodeconfigs.NodeRoleDNS, params.IPAddressesJSON) - if err != nil { - this.ErrorPage(err) - return - } - - this.Success() -} diff --git a/internal/web/actions/default/ns/clusters/cluster/node/updateInstallStatus.go b/internal/web/actions/default/ns/clusters/cluster/node/updateInstallStatus.go deleted file mode 100644 index 27850d00..00000000 --- a/internal/web/actions/default/ns/clusters/cluster/node/updateInstallStatus.go +++ /dev/null @@ -1,30 +0,0 @@ -package node - -import ( - "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" -) - -type UpdateInstallStatusAction struct { - actionutils.ParentAction -} - -func (this *UpdateInstallStatusAction) RunPost(params struct { - NodeId int64 - IsInstalled bool -}) { - // 创建日志 - defer this.CreateLog(oplogs.LevelInfo, "修改节点安装状态 %d", params.NodeId) - - _, err := this.RPC().NSNodeRPC().UpdateNSNodeIsInstalled(this.AdminContext(), &pb.UpdateNSNodeIsInstalledRequest{ - NsNodeId: params.NodeId, - IsInstalled: params.IsInstalled, - }) - if err != nil { - this.ErrorPage(err) - return - } - - this.Success() -} diff --git a/internal/web/actions/default/ns/clusters/cluster/settings/accessLog/index.go b/internal/web/actions/default/ns/clusters/cluster/settings/accessLog/index.go deleted file mode 100644 index a8651841..00000000 --- a/internal/web/actions/default/ns/clusters/cluster/settings/accessLog/index.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package accessLog - -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 IndexAction struct { - actionutils.ParentAction -} - -func (this *IndexAction) Init() { - this.Nav("", "setting", "") - this.SecondMenu("accessLog") -} - -func (this *IndexAction) RunGet(params struct { - ClusterId int64 -}) { - accessLogResp, err := this.RPC().NSClusterRPC().FindNSClusterAccessLog(this.AdminContext(), &pb.FindNSClusterAccessLogRequest{NsClusterId: params.ClusterId}) - if err != nil { - this.ErrorPage(err) - return - } - - accessLogRef := &dnsconfigs.NSAccessLogRef{} - if len(accessLogResp.AccessLogJSON) > 0 { - err = json.Unmarshal(accessLogResp.AccessLogJSON, accessLogRef) - if err != nil { - this.ErrorPage(err) - return - } - } - this.Data["accessLogRef"] = accessLogRef - - this.Show() -} - -func (this *IndexAction) RunPost(params struct { - ClusterId int64 - AccessLogJSON []byte - - Must *actions.Must - CSRF *actionutils.CSRF -}) { - defer this.CreateLogInfo("修改域名服务集群 %d 访问日志配置", params.ClusterId) - - 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()) - } - - _, err = this.RPC().NSClusterRPC().UpdateNSClusterAccessLog(this.AdminContext(), &pb.UpdateNSClusterAccessLogRequest{ - NsClusterId: params.ClusterId, - AccessLogJSON: params.AccessLogJSON, - }) - if err != nil { - this.ErrorPage(err) - return - } - - this.Success() -} diff --git a/internal/web/actions/default/ns/clusters/cluster/settings/index.go b/internal/web/actions/default/ns/clusters/cluster/settings/index.go deleted file mode 100644 index 9dfa36c6..00000000 --- a/internal/web/actions/default/ns/clusters/cluster/settings/index.go +++ /dev/null @@ -1,69 +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" - "github.com/iwind/TeaGo/actions" - "github.com/iwind/TeaGo/maps" -) - -type IndexAction struct { - actionutils.ParentAction -} - -func (this *IndexAction) Init() { - this.Nav("", "setting", "") - this.SecondMenu("basic") -} - -func (this *IndexAction) RunGet(params struct { - ClusterId int64 -}) { - clusterResp, err := this.RPC().NSClusterRPC().FindEnabledNSCluster(this.AdminContext(), &pb.FindEnabledNSClusterRequest{NsClusterId: params.ClusterId}) - if err != nil { - this.ErrorPage(err) - return - } - cluster := clusterResp.NsCluster - if cluster == nil { - this.NotFound("nsCluster", params.ClusterId) - return - } - - this.Data["cluster"] = maps.Map{ - "id": cluster.Id, - "name": cluster.Name, - "isOn": cluster.IsOn, - } - - this.Show() -} - -func (this *IndexAction) RunPost(params struct { - ClusterId int64 - Name string - IsOn bool - - Must *actions.Must - CSRF *actionutils.CSRF -}) { - defer this.CreateLogInfo("修改域名服务集群基本信息 %d", params.ClusterId) - - params.Must. - Field("name", params.Name). - Require("请输入集群名称") - - _, err := this.RPC().NSClusterRPC().UpdateNSCluster(this.AdminContext(), &pb.UpdateNSClusterRequest{ - NsClusterId: params.ClusterId, - Name: params.Name, - IsOn: params.IsOn, - }) - if err != nil { - this.ErrorPage(err) - return - } - - this.Success() -} diff --git a/internal/web/actions/default/ns/clusters/cluster/settings/recursion/index.go b/internal/web/actions/default/ns/clusters/cluster/settings/recursion/index.go deleted file mode 100644 index 845d565b..00000000 --- a/internal/web/actions/default/ns/clusters/cluster/settings/recursion/index.go +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package recursion - -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 IndexAction struct { - actionutils.ParentAction -} - -func (this *IndexAction) Init() { - this.Nav("", "setting", "") - this.SecondMenu("recursion") -} - -func (this *IndexAction) RunGet(params struct { - ClusterId int64 -}) { - this.Data["clusterId"] = params.ClusterId - - resp, err := this.RPC().NSClusterRPC().FindNSClusterRecursionConfig(this.AdminContext(), &pb.FindNSClusterRecursionConfigRequest{NsClusterId: params.ClusterId}) - if err != nil { - this.ErrorPage(err) - return - } - - var config = &dnsconfigs.RecursionConfig{} - if len(resp.RecursionJSON) > 0 { - err = json.Unmarshal(resp.RecursionJSON, config) - if err != nil { - this.ErrorPage(err) - return - } - } else { - config.UseLocalHosts = true - } - this.Data["config"] = config - - this.Show() -} - -func (this *IndexAction) RunPost(params struct { - ClusterId int64 - RecursionJSON []byte - - Must *actions.Must - CSRF *actionutils.CSRF -}) { - defer this.CreateLogInfo("修改DNS集群 %d 的递归DNS设置", params.ClusterId) - - // TODO 校验域名 - - _, err := this.RPC().NSClusterRPC().UpdateNSClusterRecursionConfig(this.AdminContext(), &pb.UpdateNSClusterRecursionConfigRequest{ - NsClusterId: params.ClusterId, - RecursionJSON: params.RecursionJSON, - }) - if err != nil { - this.ErrorPage(err) - return - } - this.Success() -} diff --git a/internal/web/actions/default/ns/domains/create.go b/internal/web/actions/default/ns/domains/create.go deleted file mode 100644 index b24b4811..00000000 --- a/internal/web/actions/default/ns/domains/create.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package domains - -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/rpc/pb" - "github.com/iwind/TeaGo/actions" - "strings" -) - -type CreateAction struct { - actionutils.ParentAction -} - -func (this *CreateAction) Init() { - this.Nav("", "", "create") -} - -func (this *CreateAction) RunGet(params struct{}) { - // 集群数量 - countClustersResp, err := this.RPC().NSClusterRPC().CountAllEnabledNSClusters(this.AdminContext(), &pb.CountAllEnabledNSClustersRequest{}) - if err != nil { - this.ErrorPage(err) - return - } - this.Data["countClusters"] = countClustersResp.Count - - this.Show() -} - -func (this *CreateAction) RunPost(params struct { - Name string - ClusterId int64 - UserId int64 - - Must *actions.Must - CSRF *actionutils.CSRF -}) { - var domainId int64 - defer func() { - this.CreateLogInfo("创建域名 %d", domainId) - }() - - params.Name = strings.ToLower(params.Name) - - params.Must. - Field("name", params.Name). - Require("请输入域名"). - Expect(func() (message string, success bool) { - success = domainutils.ValidateDomainFormat(params.Name) - if !success { - message = "请输入正确的域名" - } - return - }). - Field("clusterId", params.ClusterId). - Gt(0, "请选择所属集群") - - createResp, err := this.RPC().NSDomainRPC().CreateNSDomain(this.AdminContext(), &pb.CreateNSDomainRequest{ - NsClusterId: params.ClusterId, - UserId: params.UserId, - Name: params.Name, - }) - if err != nil { - this.ErrorPage(err) - return - } - domainId = createResp.NsDomainId - - this.Success() -} diff --git a/internal/web/actions/default/ns/domains/delete.go b/internal/web/actions/default/ns/domains/delete.go deleted file mode 100644 index 0999d275..00000000 --- a/internal/web/actions/default/ns/domains/delete.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package domains - -import ( - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" -) - -type DeleteAction struct { - actionutils.ParentAction -} - -func (this *DeleteAction) RunPost(params struct { - DomainId int64 -}) { - defer this.CreateLogInfo("删除域名 %d", params.DomainId) - - _, err := this.RPC().NSDomainRPC().DeleteNSDomain(this.AdminContext(), &pb.DeleteNSDomainRequest{NsDomainId: params.DomainId}) - if err != nil { - this.ErrorPage(err) - return - } - - this.Success() -} diff --git a/internal/web/actions/default/ns/domains/domain.go b/internal/web/actions/default/ns/domains/domain.go deleted file mode 100644 index d8361271..00000000 --- a/internal/web/actions/default/ns/domains/domain.go +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package domains - -import ( - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/domains/domainutils" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" - "github.com/iwind/TeaGo/maps" -) - -type DomainAction struct { - actionutils.ParentAction -} - -func (this *DomainAction) Init() { - this.Nav("", "", "index") -} - -func (this *DomainAction) RunGet(params struct { - DomainId int64 -}) { - err := domainutils.InitDomain(this.Parent(), params.DomainId) - if err != nil { - this.ErrorPage(err) - return - } - var countRecords = this.Data.GetMap("domain").GetInt64("countRecords") - var countKeys = this.Data.GetMap("domain").GetInt64("countKeys") - - // 域名信息 - domainResp, err := this.RPC().NSDomainRPC().FindEnabledNSDomain(this.AdminContext(), &pb.FindEnabledNSDomainRequest{NsDomainId: params.DomainId}) - if err != nil { - this.ErrorPage(err) - return - } - domain := domainResp.NsDomain - if domain == nil { - this.NotFound("nsDomain", params.DomainId) - return - } - - var clusterMap maps.Map - if domain.NsCluster != nil { - clusterMap = maps.Map{ - "id": domain.NsCluster.Id, - "name": domain.NsCluster.Name, - } - } - - // 用户信息 - var userMap maps.Map - if domain.User != nil { - userMap = maps.Map{ - "id": domain.User.Id, - "username": domain.User.Username, - "fullname": domain.User.Fullname, - } - } - - this.Data["domain"] = maps.Map{ - "id": domain.Id, - "name": domain.Name, - "isOn": domain.IsOn, - "cluster": clusterMap, - "user": userMap, - "countRecords": countRecords, - "countKeys": countKeys, - } - - this.Show() -} diff --git a/internal/web/actions/default/ns/domains/domainutils/utils.go b/internal/web/actions/default/ns/domains/domainutils/utils.go deleted file mode 100644 index 10285832..00000000 --- a/internal/web/actions/default/ns/domains/domainutils/utils.go +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package domainutils - -import ( - "errors" - "github.com/TeaOSLab/EdgeAdmin/internal/rpc" - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" - "github.com/iwind/TeaGo/maps" - "github.com/iwind/TeaGo/types" -) - -// InitDomain 初始化域名信息 -func InitDomain(parent *actionutils.ParentAction, domainId int64) error { - rpcClient, err := rpc.SharedRPC() - if err != nil { - return err - } - domainResp, err := rpcClient.NSDomainRPC().FindEnabledNSDomain(parent.AdminContext(), &pb.FindEnabledNSDomainRequest{NsDomainId: domainId}) - if err != nil { - return err - } - var domain = domainResp.NsDomain - if domain == nil { - return errors.New("InitDomain: can not find domain with id '" + types.String(domainId) + "'") - } - - // 记录数量 - countRecordsResp, err := rpcClient.NSRecordRPC().CountAllEnabledNSRecords(parent.AdminContext(), &pb.CountAllEnabledNSRecordsRequest{ - NsDomainId: domainId, - }) - if err != nil { - return err - } - var countRecords = countRecordsResp.Count - - // Key数量 - countKeysResp, err := rpcClient.NSKeyRPC().CountAllEnabledNSKeys(parent.AdminContext(), &pb.CountAllEnabledNSKeysRequest{ - NsDomainId: domainId, - }) - if err != nil { - return err - } - var countKeys = countKeysResp.Count - - parent.Data["domain"] = maps.Map{ - "id": domain.Id, - "name": domain.Name, - "countRecords": countRecords, - "countKeys": countKeys, - } - - return nil -} diff --git a/internal/web/actions/default/ns/domains/index.go b/internal/web/actions/default/ns/domains/index.go deleted file mode 100644 index 7af9a89c..00000000 --- a/internal/web/actions/default/ns/domains/index.go +++ /dev/null @@ -1,96 +0,0 @@ -package domains - -import ( - teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const" - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" - "github.com/iwind/TeaGo/maps" -) - -type IndexAction struct { - actionutils.ParentAction -} - -func (this *IndexAction) Init() { - this.Nav("", "", "index") -} - -func (this *IndexAction) RunGet(params struct { - ClusterId int64 - UserId int64 - Keyword string -}) { - if !teaconst.IsPlus { - this.RedirectURL("/") - return - } - - this.Data["clusterId"] = params.ClusterId - this.Data["userId"] = params.UserId - this.Data["keyword"] = params.Keyword - - // 集群数量 - countClustersResp, err := this.RPC().NSClusterRPC().CountAllEnabledNSClusters(this.AdminContext(), &pb.CountAllEnabledNSClustersRequest{}) - if err != nil { - this.ErrorPage(err) - return - } - this.Data["countClusters"] = countClustersResp.Count - - // 分页 - countResp, err := this.RPC().NSDomainRPC().CountAllEnabledNSDomains(this.AdminContext(), &pb.CountAllEnabledNSDomainsRequest{ - UserId: params.UserId, - NsClusterId: params.ClusterId, - Keyword: params.Keyword, - }) - if err != nil { - this.ErrorPage(err) - return - } - page := this.NewPage(countResp.Count) - - // 列表 - domainsResp, err := this.RPC().NSDomainRPC().ListEnabledNSDomains(this.AdminContext(), &pb.ListEnabledNSDomainsRequest{ - UserId: params.UserId, - NsClusterId: params.ClusterId, - Keyword: params.Keyword, - Offset: page.Offset, - Size: page.Size, - }) - if err != nil { - this.ErrorPage(err) - return - } - domainMaps := []maps.Map{} - for _, domain := range domainsResp.NsDomains { - // 集群信息 - var clusterMap maps.Map - if domain.NsCluster != nil { - clusterMap = maps.Map{ - "id": domain.NsCluster.Id, - "name": domain.NsCluster.Name, - } - } - - // 用户信息 - var userMap maps.Map - if domain.User != nil { - userMap = maps.Map{ - "id": domain.User.Id, - "username": domain.User.Username, - "fullname": domain.User.Fullname, - } - } - - domainMaps = append(domainMaps, maps.Map{ - "id": domain.Id, - "name": domain.Name, - "isOn": domain.IsOn, - "cluster": clusterMap, - "user": userMap, - }) - } - this.Data["domains"] = domainMaps - - this.Show() -} diff --git a/internal/web/actions/default/ns/domains/keys/createPopup.go b/internal/web/actions/default/ns/domains/keys/createPopup.go deleted file mode 100644 index d1d77212..00000000 --- a/internal/web/actions/default/ns/domains/keys/createPopup.go +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package keys - -import ( - "encoding/base64" - "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" - "github.com/iwind/TeaGo/maps" -) - -type CreatePopupAction struct { - actionutils.ParentAction -} - -func (this *CreatePopupAction) Init() { - this.Nav("", "", "") -} - -func (this *CreatePopupAction) RunGet(params struct { - DomainId int64 -}) { - this.Data["domainId"] = params.DomainId - - // 所有算法 - var algorithmMaps = []maps.Map{} - for _, algo := range dnsconfigs.FindAllKeyAlgorithmTypes() { - algorithmMaps = append(algorithmMaps, maps.Map{ - "name": algo.Name, - "code": algo.Code, - }) - } - this.Data["algorithms"] = algorithmMaps - - this.Show() -} - -func (this *CreatePopupAction) RunPost(params struct { - DomainId int64 - Name string - Algo string - Secret string - SecretType string - - Must *actions.Must - CSRF *actionutils.CSRF -}) { - var keyId int64 = 0 - defer func() { - this.CreateLogInfo("创建DNS密钥 %d", keyId) - }() - - params.Must. - Field("name", params.Name). - Require("请输入密钥名称"). - Field("algo", params.Algo). - Require("请选择算法"). - Field("secret", params.Secret). - Require("请输入密码") - - // 校验密码 - if params.SecretType == dnsconfigs.NSKeySecretTypeBase64 { - _, err := base64.StdEncoding.DecodeString(params.Secret) - if err != nil { - this.FailField("secret", "请输入BASE64格式的密码或者选择明文") - } - } - - createResp, err := this.RPC().NSKeyRPC().CreateNSKey(this.AdminContext(), &pb.CreateNSKeyRequest{ - NsDomainId: params.DomainId, - NsZoneId: 0, - Name: params.Name, - Algo: params.Algo, - Secret: params.Secret, - SecretType: params.SecretType, - }) - if err != nil { - this.ErrorPage(err) - return - } - keyId = createResp.NsKeyId - - this.Success() -} diff --git a/internal/web/actions/default/ns/domains/keys/delete.go b/internal/web/actions/default/ns/domains/keys/delete.go deleted file mode 100644 index d76f63a5..00000000 --- a/internal/web/actions/default/ns/domains/keys/delete.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package keys - -import ( - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" -) - -type DeleteAction struct { - actionutils.ParentAction -} - -func (this *DeleteAction) RunPost(params struct { - KeyId int64 -}) { - defer this.CreateLogInfo("删除DNS密钥 %d", params.KeyId) - - _, err := this.RPC().NSKeyRPC().DeleteNSKey(this.AdminContext(), &pb.DeleteNSKeyRequest{NsKeyId: params.KeyId}) - if err != nil { - this.ErrorPage(err) - return - } - - this.Success() -} diff --git a/internal/web/actions/default/ns/domains/keys/generateSecret.go b/internal/web/actions/default/ns/domains/keys/generateSecret.go deleted file mode 100644 index 972c6c52..00000000 --- a/internal/web/actions/default/ns/domains/keys/generateSecret.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package keys - -import ( - "encoding/base64" - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs" - "github.com/iwind/TeaGo/rands" -) - -type GenerateSecretAction struct { - actionutils.ParentAction -} - -func (this *GenerateSecretAction) RunPost(params struct { - SecretType string -}) { - switch params.SecretType { - case dnsconfigs.NSKeySecretTypeClear: - this.Data["secret"] = rands.HexString(128) - case dnsconfigs.NSKeySecretTypeBase64: - this.Data["secret"] = base64.StdEncoding.EncodeToString([]byte(rands.HexString(128))) - default: - this.Data["secret"] = rands.HexString(128) - } - - this.Success() -} diff --git a/internal/web/actions/default/ns/domains/keys/index.go b/internal/web/actions/default/ns/domains/keys/index.go deleted file mode 100644 index 40695051..00000000 --- a/internal/web/actions/default/ns/domains/keys/index.go +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package keys - -import ( - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/domains/domainutils" - "github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" - "github.com/iwind/TeaGo/maps" -) - -type IndexAction struct { - actionutils.ParentAction -} - -func (this *IndexAction) Init() { - this.Nav("", "", "key") -} - -func (this *IndexAction) RunGet(params struct { - DomainId int64 -}) { - // 初始化域名信息 - err := domainutils.InitDomain(this.Parent(), params.DomainId) - if err != nil { - this.ErrorPage(err) - return - } - - // 数量 - countResp, err := this.RPC().NSKeyRPC().CountAllEnabledNSKeys(this.AdminContext(), &pb.CountAllEnabledNSKeysRequest{ - NsDomainId: params.DomainId, - NsZoneId: 0, - }) - if err != nil { - this.ErrorPage(err) - return - } - var page = this.NewPage(countResp.Count) - this.Data["page"] = page.AsHTML() - - // 列表 - keysResp, err := this.RPC().NSKeyRPC().ListEnabledNSKeys(this.AdminContext(), &pb.ListEnabledNSKeysRequest{ - NsDomainId: params.DomainId, - NsZoneId: 0, - Offset: page.Offset, - Size: page.Size, - }) - if err != nil { - this.ErrorPage(err) - return - } - var keyMaps = []maps.Map{} - for _, key := range keysResp.NsKeys { - keyMaps = append(keyMaps, maps.Map{ - "id": key.Id, - "name": key.Name, - "secret": key.Secret, - "secretTypeName": dnsconfigs.FindKeySecretTypeName(key.SecretType), - "algoName": dnsconfigs.FindKeyAlgorithmTypeName(key.Algo), - "isOn": key.IsOn, - }) - } - this.Data["keys"] = keyMaps - - this.Show() -} diff --git a/internal/web/actions/default/ns/domains/keys/updatePopup.go b/internal/web/actions/default/ns/domains/keys/updatePopup.go deleted file mode 100644 index ef48e8d7..00000000 --- a/internal/web/actions/default/ns/domains/keys/updatePopup.go +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package keys - -import ( - "encoding/base64" - "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" - "github.com/iwind/TeaGo/maps" -) - -type UpdatePopupAction struct { - actionutils.ParentAction -} - -func (this *UpdatePopupAction) Init() { - this.Nav("", "", "") -} - -func (this *UpdatePopupAction) RunGet(params struct { - KeyId int64 -}) { - keyResp, err := this.RPC().NSKeyRPC().FindEnabledNSKey(this.AdminContext(), &pb.FindEnabledNSKeyRequest{NsKeyId: params.KeyId}) - if err != nil { - this.ErrorPage(err) - return - } - var key = keyResp.NsKey - if key == nil { - return - } - - this.Data["key"] = maps.Map{ - "id": key.Id, - "name": key.Name, - "algo": key.Algo, - "secret": key.Secret, - "secretType": key.SecretType, - "isOn": key.IsOn, - } - - // 所有算法 - var algorithmMaps = []maps.Map{} - for _, algo := range dnsconfigs.FindAllKeyAlgorithmTypes() { - algorithmMaps = append(algorithmMaps, maps.Map{ - "name": algo.Name, - "code": algo.Code, - }) - } - this.Data["algorithms"] = algorithmMaps - - this.Show() -} - -func (this *UpdatePopupAction) RunPost(params struct { - KeyId int64 - Name string - Algo string - Secret string - SecretType string - IsOn bool - - Must *actions.Must - CSRF *actionutils.CSRF -}) { - this.CreateLogInfo("修改DNS密钥 %d", params.KeyId) - - params.Must. - Field("name", params.Name). - Require("请输入密钥名称"). - Field("algo", params.Algo). - Require("请选择算法"). - Field("secret", params.Secret). - Require("请输入密码") - - // 校验密码 - if params.SecretType == dnsconfigs.NSKeySecretTypeBase64 { - _, err := base64.StdEncoding.DecodeString(params.Secret) - if err != nil { - this.FailField("secret", "请输入BASE64格式的密码或者选择明文") - } - } - - _, err := this.RPC().NSKeyRPC().UpdateNSKey(this.AdminContext(), &pb.UpdateNSKeyRequest{ - NsKeyId: params.KeyId, - Name: params.Name, - Algo: params.Algo, - Secret: params.Secret, - SecretType: params.SecretType, - IsOn: params.IsOn, - }) - if err != nil { - this.ErrorPage(err) - return - } - - this.Success() -} diff --git a/internal/web/actions/default/ns/domains/records/createPopup.go b/internal/web/actions/default/ns/domains/records/createPopup.go deleted file mode 100644 index 6cbf599b..00000000 --- a/internal/web/actions/default/ns/domains/records/createPopup.go +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package records - -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" -) - -type CreatePopupAction struct { - actionutils.ParentAction -} - -func (this *CreatePopupAction) Init() { - this.Nav("", "", "") -} - -func (this *CreatePopupAction) RunGet(params struct { - DomainId int64 -}) { - // 域名信息 - domainResp, err := this.RPC().NSDomainRPC().FindEnabledNSDomain(this.AdminContext(), &pb.FindEnabledNSDomainRequest{NsDomainId: params.DomainId}) - if err != nil { - this.ErrorPage(err) - return - } - domain := domainResp.NsDomain - if domain == nil { - this.NotFound("nsDomain", params.DomainId) - return - } - this.Data["domain"] = maps.Map{ - "id": domain.Id, - "name": domain.Name, - } - - // 类型 - this.Data["types"] = dnsconfigs.FindAllRecordTypeDefinitions() - - // TTL - this.Data["ttlValues"] = dnsconfigs.FindAllRecordTTL() - - this.Show() -} - -func (this *CreatePopupAction) RunPost(params struct { - DomainId int64 - Name string - Type string - Value string - Ttl int32 - Description string - RouteCodes []string - - Must *actions.Must - CSRF *actionutils.CSRF -}) { - var recordId int64 - defer func() { - this.CreateLogInfo("创建域名记录 %d", recordId) - }() - - // 校验记录名 - if !domainutils.ValidateRecordName(params.Name) { - this.FailField("name", "请输入正确的记录名") - } - - // 校验记录值 - message, ok := domainutils.ValidateRecordValue(params.Type, params.Value) - if !ok { - this.FailField("value", "记录值错误:"+message) - } - - createResp, err := this.RPC().NSRecordRPC().CreateNSRecord(this.AdminContext(), &pb.CreateNSRecordRequest{ - NsDomainId: params.DomainId, - Description: params.Description, - Name: params.Name, - Type: params.Type, - Value: params.Value, - Ttl: params.Ttl, - NsRouteCodes: params.RouteCodes, - }) - if err != nil { - this.ErrorPage(err) - return - } - recordId = createResp.NsRecordId - - this.Success() -} diff --git a/internal/web/actions/default/ns/domains/records/delete.go b/internal/web/actions/default/ns/domains/records/delete.go deleted file mode 100644 index f640e556..00000000 --- a/internal/web/actions/default/ns/domains/records/delete.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package records - -import ( - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" -) - -type DeleteAction struct { - actionutils.ParentAction -} - -func (this *DeleteAction) RunPost(params struct { - RecordId int64 -}) { - defer this.CreateLogInfo("删除域名记录 %d", params.RecordId) - - _, err := this.RPC().NSRecordRPC().DeleteNSRecord(this.AdminContext(), &pb.DeleteNSRecordRequest{NsRecordId: params.RecordId}) - if err != nil { - this.ErrorPage(err) - return - } - - this.Success() -} diff --git a/internal/web/actions/default/ns/domains/records/index.go b/internal/web/actions/default/ns/domains/records/index.go deleted file mode 100644 index b1f896e8..00000000 --- a/internal/web/actions/default/ns/domains/records/index.go +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package records - -import ( - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/domains/domainutils" - "github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" - "github.com/iwind/TeaGo/maps" -) - -type IndexAction struct { - actionutils.ParentAction -} - -func (this *IndexAction) Init() { - this.Nav("", "", "record") -} - -func (this *IndexAction) RunGet(params struct { - DomainId int64 - Type string - Keyword string - RouteCode string -}) { - // 初始化域名信息 - err := domainutils.InitDomain(this.Parent(), params.DomainId) - if err != nil { - this.ErrorPage(err) - return - } - - this.Data["type"] = params.Type - this.Data["keyword"] = params.Keyword - this.Data["routeCode"] = params.RouteCode - - // 记录 - countResp, err := this.RPC().NSRecordRPC().CountAllEnabledNSRecords(this.AdminContext(), &pb.CountAllEnabledNSRecordsRequest{ - NsDomainId: params.DomainId, - Type: params.Type, - NsRouteCode: params.RouteCode, - Keyword: params.Keyword, - }) - if err != nil { - this.ErrorPage(err) - return - } - count := countResp.Count - page := this.NewPage(count) - this.Data["page"] = page.AsHTML() - - recordsResp, err := this.RPC().NSRecordRPC().ListEnabledNSRecords(this.AdminContext(), &pb.ListEnabledNSRecordsRequest{ - NsDomainId: params.DomainId, - Type: params.Type, - NsRouteCode: params.RouteCode, - Keyword: params.Keyword, - Offset: page.Offset, - Size: page.Size, - }) - if err != nil { - this.ErrorPage(err) - return - } - var recordMaps = []maps.Map{} - for _, record := range recordsResp.NsRecords { - routeMaps := []maps.Map{} - for _, route := range record.NsRoutes { - routeMaps = append(routeMaps, maps.Map{ - "id": route.Id, - "name": route.Name, - }) - } - - recordMaps = append(recordMaps, maps.Map{ - "id": record.Id, - "name": record.Name, - "type": record.Type, - "value": record.Value, - "ttl": record.Ttl, - "weight": record.Weight, - "description": record.Description, - "isOn": record.IsOn, - "routes": routeMaps, - }) - } - this.Data["records"] = recordMaps - - // 所有记录类型 - this.Data["types"] = dnsconfigs.FindAllRecordTypeDefinitions() - - this.Show() -} diff --git a/internal/web/actions/default/ns/domains/records/updatePopup.go b/internal/web/actions/default/ns/domains/records/updatePopup.go deleted file mode 100644 index aa36c9a0..00000000 --- a/internal/web/actions/default/ns/domains/records/updatePopup.go +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package records - -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" -) - -type UpdatePopupAction struct { - actionutils.ParentAction -} - -func (this *UpdatePopupAction) Init() { - this.Nav("", "", "") -} - -func (this *UpdatePopupAction) RunGet(params struct { - RecordId int64 -}) { - recordResp, err := this.RPC().NSRecordRPC().FindEnabledNSRecord(this.AdminContext(), &pb.FindEnabledNSRecordRequest{NsRecordId: params.RecordId}) - if err != nil { - this.ErrorPage(err) - return - } - record := recordResp.NsRecord - if record == nil { - this.NotFound("nsRecord", params.RecordId) - return - } - - this.Data["record"] = maps.Map{ - "id": record.Id, - "name": record.Name, - "type": record.Type, - "value": record.Value, - "ttl": record.Ttl, - "weight": record.Weight, - "description": record.Description, - "isOn": record.IsOn, - "routes": record.NsRoutes, - } - - // 域名信息 - domainResp, err := this.RPC().NSDomainRPC().FindEnabledNSDomain(this.AdminContext(), &pb.FindEnabledNSDomainRequest{NsDomainId: record.NsDomain.Id}) - if err != nil { - this.ErrorPage(err) - return - } - domain := domainResp.NsDomain - if domain == nil { - this.NotFound("nsDomain", record.NsDomain.Id) - return - } - this.Data["domain"] = maps.Map{ - "id": domain.Id, - "name": domain.Name, - } - - // 类型 - this.Data["types"] = dnsconfigs.FindAllRecordTypeDefinitions() - - // TTL - this.Data["ttlValues"] = dnsconfigs.FindAllRecordTTL() - - this.Show() -} - -func (this *UpdatePopupAction) RunPost(params struct { - RecordId int64 - Name string - Type string - Value string - Ttl int32 - Description string - IsOn bool - RouteCodes []string - - Must *actions.Must - CSRF *actionutils.CSRF -}) { - this.CreateLogInfo("修改域名记录 %d", params.RecordId) - - // 校验记录名 - if !domainutils.ValidateRecordName(params.Name) { - this.FailField("name", "请输入正确的记录名") - } - - // 校验记录值 - message, ok := domainutils.ValidateRecordValue(params.Type, params.Value) - if !ok { - this.FailField("value", "记录值错误:"+message) - } - - _, err := this.RPC().NSRecordRPC().UpdateNSRecord(this.AdminContext(), &pb.UpdateNSRecordRequest{ - NsRecordId: params.RecordId, - Description: params.Description, - Name: params.Name, - Type: params.Type, - Value: params.Value, - Ttl: params.Ttl, - IsOn: params.IsOn, - NsRouteCodes: params.RouteCodes, - }) - if err != nil { - this.ErrorPage(err) - return - } - - this.Success() -} diff --git a/internal/web/actions/default/ns/domains/tsig.go b/internal/web/actions/default/ns/domains/tsig.go deleted file mode 100644 index 0b767dc6..00000000 --- a/internal/web/actions/default/ns/domains/tsig.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package domains - -import ( - "encoding/json" - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/domains/domainutils" - "github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" - "github.com/iwind/TeaGo/actions" - "github.com/iwind/TeaGo/logs" -) - -type TsigAction struct { - actionutils.ParentAction -} - -func (this *TsigAction) Init() { - this.Nav("", "", "tsig") -} - -func (this *TsigAction) RunGet(params struct { - DomainId int64 -}) { - // 初始化域名信息 - err := domainutils.InitDomain(this.Parent(), params.DomainId) - if err != nil { - this.ErrorPage(err) - return - } - - // TSIG信息 - tsigResp, err := this.RPC().NSDomainRPC().FindEnabledNSDomainTSIG(this.AdminContext(), &pb.FindEnabledNSDomainTSIGRequest{NsDomainId: params.DomainId}) - if err != nil { - this.ErrorPage(err) - return - } - var tsigJSON = tsigResp.TsigJSON - - var tsigConfig = &dnsconfigs.TSIGConfig{} - if len(tsigJSON) > 0 { - err = json.Unmarshal(tsigJSON, tsigConfig) - if err != nil { - // 只是提示错误,仍然允许用户修改 - logs.Error(err) - } - } - this.Data["tsig"] = tsigConfig - - this.Show() -} - -func (this *TsigAction) RunPost(params struct { - DomainId int64 - IsOn bool - - Must *actions.Must - CSRF *actionutils.CSRF -}) { - defer this.CreateLogInfo("修改DNS域名 %d 的TSIG配置", params.DomainId) - - var tsigConfig = &dnsconfigs.TSIGConfig{ - IsOn: params.IsOn, - } - tsigJSON, err := json.Marshal(tsigConfig) - if err != nil { - this.ErrorPage(err) - return - } - _, err = this.RPC().NSDomainRPC().UpdateNSDomainTSIG(this.AdminContext(), &pb.UpdateNSDomainTSIGRequest{ - NsDomainId: params.DomainId, - TsigJSON: tsigJSON, - }) - if err != nil { - this.ErrorPage(err) - return - } - this.Success() -} diff --git a/internal/web/actions/default/ns/domains/update.go b/internal/web/actions/default/ns/domains/update.go deleted file mode 100644 index 44c307e5..00000000 --- a/internal/web/actions/default/ns/domains/update.go +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package domains - -import ( - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/domains/domainutils" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" - "github.com/iwind/TeaGo/actions" - "github.com/iwind/TeaGo/maps" -) - -type UpdateAction struct { - actionutils.ParentAction -} - -func (this *UpdateAction) Init() { - this.Nav("", "", "update") -} - -func (this *UpdateAction) RunGet(params struct { - DomainId int64 -}) { - // 初始化域名信息 - err := domainutils.InitDomain(this.Parent(), params.DomainId) - if err != nil { - this.ErrorPage(err) - return - } - var countRecords = this.Data.GetMap("domain").GetInt64("countRecords") - var countKeys = this.Data.GetMap("domain").GetInt64("countKeys") - - // 域名信息 - domainResp, err := this.RPC().NSDomainRPC().FindEnabledNSDomain(this.AdminContext(), &pb.FindEnabledNSDomainRequest{NsDomainId: params.DomainId}) - if err != nil { - this.ErrorPage(err) - return - } - domain := domainResp.NsDomain - if domain == nil { - this.NotFound("nsDomain", params.DomainId) - return - } - - var clusterId = int64(0) - if domain.NsCluster != nil { - clusterId = domain.NsCluster.Id - } - - // 用户信息 - var userId = int64(0) - if domain.User != nil { - userId = domain.User.Id - } - - this.Data["domain"] = maps.Map{ - "id": domain.Id, - "name": domain.Name, - "isOn": domain.IsOn, - "clusterId": clusterId, - "userId": userId, - "countRecords": countRecords, - "countKeys": countKeys, - } - - this.Show() -} - -func (this *UpdateAction) RunPost(params struct { - DomainId int64 - ClusterId int64 - UserId int64 - IsOn bool - - Must *actions.Must - CSRF *actionutils.CSRF -}) { - this.CreateLogInfo("修改域名 %d", params.DomainId) - - params.Must. - Field("clusterId", params.ClusterId). - Gt(0, "请选择所属集群") - - _, err := this.RPC().NSDomainRPC().UpdateNSDomain(this.AdminContext(), &pb.UpdateNSDomainRequest{ - NsDomainId: params.DomainId, - NsClusterId: params.ClusterId, - UserId: params.UserId, - IsOn: params.IsOn, - }) - if err != nil { - this.ErrorPage(err) - return - } - - this.Success() -} diff --git a/internal/web/actions/default/ns/routes/createPopup.go b/internal/web/actions/default/ns/routes/createPopup.go deleted file mode 100644 index 27b45808..00000000 --- a/internal/web/actions/default/ns/routes/createPopup.go +++ /dev/null @@ -1,63 +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/rpc/pb" - "github.com/iwind/TeaGo/actions" -) - -type CreatePopupAction struct { - actionutils.ParentAction -} - -func (this *CreatePopupAction) Init() { -} - -func (this *CreatePopupAction) RunGet(params struct { - ClusterId int64 - DomainId int64 - UserId int64 -}) { - this.Data["clusterId"] = params.ClusterId - this.Data["domainId"] = params.DomainId - this.Data["userId"] = params.UserId - - this.Show() -} - -func (this *CreatePopupAction) RunPost(params struct { - ClusterId int64 - DomainId int64 - UserId int64 - - Name string - RangesJSON []byte - - Must *actions.Must - CSRF *actionutils.CSRF -}) { - var routeId = int64(0) - defer func() { - this.CreateLogInfo("创建域名服务线路 %d", routeId) - }() - - params.Must.Field("name", params.Name). - Require("请输入线路名称") - - createResp, err := this.RPC().NSRouteRPC().CreateNSRoute(this.AdminContext(), &pb.CreateNSRouteRequest{ - NsClusterId: params.ClusterId, - NsDomainId: params.DomainId, - UserId: params.UserId, - Name: params.Name, - RangesJSON: params.RangesJSON, - }) - if err != nil { - this.ErrorPage(err) - return - } - routeId = createResp.NsRouteId - - this.Success() -} diff --git a/internal/web/actions/default/ns/routes/delete.go b/internal/web/actions/default/ns/routes/delete.go deleted file mode 100644 index 839ad131..00000000 --- a/internal/web/actions/default/ns/routes/delete.go +++ /dev/null @@ -1,26 +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/rpc/pb" -) - -type DeleteAction struct { - actionutils.ParentAction -} - -func (this *DeleteAction) RunPost(params struct { - RouteId int64 -}) { - defer this.CreateLogInfo("删除域名服务线路 %d", params.RouteId) - - _, err := this.RPC().NSRouteRPC().DeleteNSRoute(this.AdminContext(), &pb.DeleteNSRouteRequest{NsRouteId: params.RouteId}) - if err != nil { - this.ErrorPage(err) - return - } - - this.Success() -} diff --git a/internal/web/actions/default/ns/routes/index.go b/internal/web/actions/default/ns/routes/index.go deleted file mode 100644 index a7a055e4..00000000 --- a/internal/web/actions/default/ns/routes/index.go +++ /dev/null @@ -1,41 +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/rpc/pb" - "github.com/iwind/TeaGo/maps" -) - -type IndexAction struct { - actionutils.ParentAction -} - -func (this *IndexAction) Init() { - this.Nav("", "", "index") -} - -func (this *IndexAction) RunGet(params struct{}) { - routesResp, err := this.RPC().NSRouteRPC().FindAllEnabledNSRoutes(this.AdminContext(), &pb.FindAllEnabledNSRoutesRequest{ - NsClusterId: 0, - NsDomainId: 0, - UserId: 0, - }) - if err != nil { - this.ErrorPage(err) - return - } - - routeMaps := []maps.Map{} - for _, route := range routesResp.NsRoutes { - routeMaps = append(routeMaps, maps.Map{ - "id": route.Id, - "name": route.Name, - "isOn": route.IsOn, - }) - } - this.Data["routes"] = routeMaps - - this.Show() -} diff --git a/internal/web/actions/default/ns/routes/options.go b/internal/web/actions/default/ns/routes/options.go deleted file mode 100644 index f6142781..00000000 --- a/internal/web/actions/default/ns/routes/options.go +++ /dev/null @@ -1,86 +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/dnsconfigs" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" - "github.com/iwind/TeaGo/maps" - "github.com/iwind/TeaGo/types" -) - -type OptionsAction struct { - actionutils.ParentAction -} - -func (this *OptionsAction) RunPost(params struct { - ClusterId int64 - DomainId int64 - UserId int64 -}) { - var routeMaps = []maps.Map{} - - // 默认线路 - for _, route := range dnsconfigs.AllDefaultRoutes { - routeMaps = append(routeMaps, maps.Map{ - "name": route.Name, - "code": route.Code, - "type": "default", - }) - } - - // 自定义 - routesResp, err := this.RPC().NSRouteRPC().FindAllEnabledNSRoutes(this.AdminContext(), &pb.FindAllEnabledNSRoutesRequest{ - NsClusterId: params.ClusterId, - NsDomainId: params.DomainId, - UserId: params.UserId, - }) - if err != nil { - this.ErrorPage(err) - return - } - - for _, route := range routesResp.NsRoutes { - if len(route.Code) == 0 { - route.Code = "id:" + types.String(route.Id) - } - - routeMaps = append(routeMaps, maps.Map{ - "name": route.Name, - "code": route.Code, - "type": "user", - }) - } - - // 运营商 - for _, route := range dnsconfigs.AllDefaultISPRoutes { - routeMaps = append(routeMaps, maps.Map{ - "name": route.Name, - "code": route.Code, - "type": "isp", - }) - } - - // 中国 - for _, route := range dnsconfigs.AllDefaultChinaProvinceRoutes { - routeMaps = append(routeMaps, maps.Map{ - "name": route.Name, - "code": route.Code, - "type": "china", - }) - } - - // 全球 - for _, route := range dnsconfigs.AllDefaultWorldRegionRoutes { - routeMaps = append(routeMaps, maps.Map{ - "name": route.Name, - "code": route.Code, - "type": "world", - }) - } - - this.Data["routes"] = routeMaps - - this.Success() -} diff --git a/internal/web/actions/default/ns/routes/route.go b/internal/web/actions/default/ns/routes/route.go deleted file mode 100644 index 03cc8a6c..00000000 --- a/internal/web/actions/default/ns/routes/route.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package clusters - -import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - -type RouteAction struct { - actionutils.ParentAction -} - -func (this *RouteAction) Init() { - this.Nav("", "", "") -} - -func (this *RouteAction) RunGet(params struct{}) { - this.Show() -} diff --git a/internal/web/actions/default/ns/routes/sort.go b/internal/web/actions/default/ns/routes/sort.go deleted file mode 100644 index 6ca0338c..00000000 --- a/internal/web/actions/default/ns/routes/sort.go +++ /dev/null @@ -1,26 +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/rpc/pb" -) - -type SortAction struct { - actionutils.ParentAction -} - -func (this *SortAction) RunPost(params struct { - RouteIds []int64 -}) { - defer this.CreateLogInfo("对线路进行排序") - - _, err := this.RPC().NSRouteRPC().UpdateNSRouteOrders(this.AdminContext(), &pb.UpdateNSRouteOrdersRequest{NsRouteIds: params.RouteIds}) - if err != nil { - this.ErrorPage(err) - return - } - - this.Success() -} diff --git a/internal/web/actions/default/ns/routes/updatePopup.go b/internal/web/actions/default/ns/routes/updatePopup.go deleted file mode 100644 index 760809e9..00000000 --- a/internal/web/actions/default/ns/routes/updatePopup.go +++ /dev/null @@ -1,78 +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/rpc/pb" - "github.com/iwind/TeaGo/actions" - "github.com/iwind/TeaGo/maps" -) - -type UpdatePopupAction struct { - actionutils.ParentAction -} - -func (this *UpdatePopupAction) Init() { - this.Nav("", "", "") -} - -func (this *UpdatePopupAction) RunGet(params struct { - RouteId int64 -}) { - routeResp, err := this.RPC().NSRouteRPC().FindEnabledNSRoute(this.AdminContext(), &pb.FindEnabledNSRouteRequest{NsRouteId: params.RouteId}) - if err != nil { - this.ErrorPage(err) - return - } - route := routeResp.NsRoute - if route == nil { - this.NotFound("nsRoute", params.RouteId) - return - } - - rangeMaps := []maps.Map{} - if len(route.RangesJSON) > 0 { - err = json.Unmarshal([]byte(route.RangesJSON), &rangeMaps) - if err != nil { - this.ErrorPage(err) - return - } - } - - this.Data["route"] = maps.Map{ - "id": route.Id, - "name": route.Name, - "isOn": route.IsOn, - "ranges": rangeMaps, - } - - this.Show() -} - -func (this *UpdatePopupAction) RunPost(params struct { - RouteId int64 - Name string - RangesJSON []byte - - Must *actions.Must - CSRF *actionutils.CSRF -}) { - defer this.CreateLogInfo("修改域名线路 %d", params.RouteId) - - params.Must.Field("name", params.Name). - Require("请输入线路名称") - - _, err := this.RPC().NSRouteRPC().UpdateNSRoute(this.AdminContext(), &pb.UpdateNSRouteRequest{ - NsRouteId: params.RouteId, - Name: params.Name, - RangesJSON: params.RangesJSON, - }) - if err != nil { - this.ErrorPage(err) - return - } - - this.Success() -} diff --git a/internal/web/actions/default/ns/settings/accesslogs/index.go b/internal/web/actions/default/ns/settings/accesslogs/index.go deleted file mode 100644 index b6a25cf1..00000000 --- a/internal/web/actions/default/ns/settings/accesslogs/index.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package accesslogs - -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/TeaOSLab/EdgeCommon/pkg/systemconfigs" - "github.com/iwind/TeaGo/actions" -) - -type IndexAction struct { - actionutils.ParentAction -} - -func (this *IndexAction) Init() { - this.Nav("", "", "") - this.SecondMenu("accessLog") -} - -func (this *IndexAction) RunGet(params struct{}) { - resp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{ - Code: systemconfigs.SettingCodeNSAccessLogSetting, - }) - if err != nil { - this.ErrorPage(err) - return - } - - var config = &dnsconfigs.NSAccessLogRef{} - if len(resp.ValueJSON) > 0 { - err = json.Unmarshal(resp.ValueJSON, config) - if err != nil { - this.ErrorPage(err) - return - } - } else { - config.IsOn = true - config.LogMissingDomains = true - } - - this.Data["config"] = config - - this.Show() -} - -func (this *IndexAction) RunPost(params struct { - AccessLogJSON []byte - - Must *actions.Must - CSRF *actionutils.CSRF -}) { - // 校验配置 - var config = &dnsconfigs.NSAccessLogRef{} - err := json.Unmarshal(params.AccessLogJSON, config) - if err != nil { - this.Fail("配置解析失败:" + err.Error()) - } - - err = config.Init() - if err != nil { - this.Fail("配置校验失败:" + err.Error()) - } - - _, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{ - Code: systemconfigs.SettingCodeNSAccessLogSetting, - ValueJSON: params.AccessLogJSON, - }) - if err != nil { - this.ErrorPage(err) - return - } - - this.Success() -} diff --git a/internal/web/actions/default/ns/settings/index.go b/internal/web/actions/default/ns/settings/index.go deleted file mode 100644 index c231be1c..00000000 --- a/internal/web/actions/default/ns/settings/index.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package settings - -import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - -type IndexAction struct { - actionutils.ParentAction -} - -func (this *IndexAction) Init() { - this.Nav("", "", "") -} - -func (this *IndexAction) RunGet(params struct{}) { - this.RedirectURL("/ns/settings/accesslogs") -} diff --git a/internal/web/actions/default/ns/settings/settingutils/helper.go b/internal/web/actions/default/ns/settings/settingutils/helper.go deleted file mode 100644 index fce9930c..00000000 --- a/internal/web/actions/default/ns/settings/settingutils/helper.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package settingutils - -import ( - "github.com/iwind/TeaGo/actions" - "github.com/iwind/TeaGo/maps" -) - -type Helper struct { -} - -func (this *Helper) BeforeAction(actionPtr actions.ActionWrapper) (goNext bool) { - var action = actionPtr.Object() - secondMenuItem := action.Data.GetString("secondMenuItem") - action.Data["leftMenuItems"] = this.createSettingMenu(secondMenuItem) - return true -} - -func (this *Helper) createSettingMenu(selectedItem string) (items []maps.Map) { - return []maps.Map{ - { - "name": "访问日志", - "url": "/ns/settings/accesslogs", - "isActive": selectedItem == "accessLog", - }, - } -}