From 41ac159e231bd238ca745e60b96fe4823a28ceeb Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Thu, 17 Dec 2020 15:50:44 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9B=86=E7=BE=A4=E5=8F=AF=E4=BB=A5=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=BB=98=E8=AE=A4=E7=9A=84WAF=E7=AD=96=E7=95=A5?= =?UTF-8?q?=E3=80=81=E7=BC=93=E5=AD=98=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/tasks/task_sync_cluster.go | 2 +- .../default/clusters/cluster/createBatch.go | 10 +- .../default/clusters/cluster/createNode.go | 14 +- .../default/clusters/cluster/delete.go | 2 +- .../clusters/cluster/groups/createPopup.go | 4 +- .../default/clusters/cluster/groups/index.go | 2 +- .../clusters/cluster/groups/selectPopup.go | 2 +- .../actions/default/clusters/cluster/index.go | 30 ++-- .../default/clusters/cluster/installManual.go | 2 +- .../default/clusters/cluster/installNodes.go | 4 +- .../default/clusters/cluster/installRemote.go | 2 +- .../default/clusters/cluster/node/install.go | 2 +- .../default/clusters/cluster/node/node.go | 2 +- .../default/clusters/cluster/node/update.go | 20 +-- .../clusters/cluster/settings/cache/index.go | 75 ++++++++++ .../clusters/cluster/settings/health.go | 4 +- .../cluster/settings/healthRunPopup.go | 2 +- .../clusters/cluster/settings/index.go | 10 +- .../default/clusters/cluster/settings/init.go | 10 ++ .../clusters/cluster/settings/waf/index.go | 75 ++++++++++ .../default/clusters/cluster/upgradeRemote.go | 2 +- .../clusters/clusterutils/cluster_helper.go | 12 +- .../web/actions/default/clusters/create.go | 27 +++- .../web/actions/default/clusters/index.go | 8 +- internal/web/actions/default/clusters/sync.go | 2 +- .../actions/default/dns/clusters/cluster.go | 8 +- .../actions/default/nodes/nodeutils/utils.go | 2 +- .../components/cache/cacheutils/utils.go | 6 +- .../default/servers/components/cache/clean.go | 4 +- .../default/servers/components/cache/count.go | 22 +++ .../servers/components/cache/createPopup.go | 9 +- .../servers/components/cache/delete.go | 6 +- .../default/servers/components/cache/index.go | 10 +- .../default/servers/components/cache/init.go | 3 + .../servers/components/cache/policy.go | 17 +++ .../servers/components/cache/preheat.go | 4 +- .../default/servers/components/cache/purge.go | 4 +- .../servers/components/cache/selectPopup.go | 60 ++++++++ .../default/servers/components/cache/stat.go | 4 +- .../servers/components/cache/testRead.go | 4 +- .../servers/components/cache/testWrite.go | 4 +- .../servers/components/cache/update.go | 6 +- .../default/servers/components/waf/count.go | 21 +++ .../components/waf/createGroupPopup.go | 6 +- .../servers/components/waf/createPopup.go | 17 ++- .../default/servers/components/waf/delete.go | 8 +- .../servers/components/waf/deleteGroup.go | 6 +- .../default/servers/components/waf/helper.go | 2 +- .../default/servers/components/waf/import.go | 4 +- .../default/servers/components/waf/index.go | 12 +- .../default/servers/components/waf/init.go | 2 + .../servers/components/waf/ipadmin/index.go | 4 +- .../waf/ipadmin/ipadminutils/utils.go | 13 +- .../components/waf/ipadmin/provinces.go | 4 +- .../default/servers/components/waf/log.go | 6 +- .../default/servers/components/waf/policy.go | 16 +-- .../servers/components/waf/selectPopup.go | 73 ++++++++++ .../servers/components/waf/sortGroups.go | 6 +- .../default/servers/components/waf/update.go | 12 +- .../web/actions/default/servers/create.go | 2 +- .../default/servers/server/log/viewPopup.go | 8 +- .../server/settings/cache/createPopup.go | 39 +----- .../servers/server/settings/cache/index.go | 18 +++ .../default/servers/server/settings/index.go | 12 +- .../server/settings/locations/cache/index.go | 19 +++ .../server/settings/locations/waf/index.go | 23 +-- .../servers/server/settings/waf/index.go | 22 +-- .../web/actions/default/users/createPopup.go | 18 +-- internal/web/actions/default/users/update.go | 20 +-- internal/web/models/base_dao.go | 18 +++ internal/web/models/http_cache_policy_dao.go | 52 +++++-- .../web/models/http_firewall_policy_dao.go | 79 ++++++----- internal/web/models/node_cluster_dao.go | 21 +++ internal/web/models/server_dao.go | 7 + .../server/http-cache-config-box.js | 13 +- .../server/http-cache-policy-selector.js | 49 +++++++ .../components/server/http-cache-ref-box.js | 2 +- .../server/http-firewall-config-box.js | 43 ++---- .../server/http-firewall-policy-selector.js | 49 +++++++ .../cluster/settings/cache/index.html | 19 +++ .../clusters/cluster/settings/cache/index.js | 3 + .../clusters/cluster/settings/waf/index.html | 19 +++ .../clusters/cluster/settings/waf/index.js | 3 + web/views/@default/clusters/create.html | 12 ++ .../@default/clusters/grants/selectPopup.html | 24 ++-- .../@default/clusters/grants/selectPopup.js | 9 +- .../servers/components/cache/index.html | 4 +- .../servers/components/cache/policy.html | 131 +++++++++--------- .../servers/components/cache/selectPopup.html | 24 ++++ .../servers/components/cache/selectPopup.js | 11 ++ .../servers/components/waf/index.html | 4 +- .../servers/components/waf/policy.html | 103 +++++++------- .../servers/components/waf/selectPopup.html | 24 ++++ .../servers/components/waf/selectPopup.js | 11 ++ .../server/settings/cache/createPopup.html | 8 -- .../server/settings/cache/createPopup.js | 11 +- .../servers/server/settings/cache/index.html | 2 +- .../settings/locations/cache/index.html | 2 +- .../server/settings/locations/waf/index.html | 2 +- .../servers/server/settings/waf/index.html | 10 +- 100 files changed, 1172 insertions(+), 488 deletions(-) create mode 100644 internal/web/actions/default/clusters/cluster/settings/cache/index.go create mode 100644 internal/web/actions/default/clusters/cluster/settings/waf/index.go create mode 100644 internal/web/actions/default/servers/components/cache/count.go create mode 100644 internal/web/actions/default/servers/components/cache/selectPopup.go create mode 100644 internal/web/actions/default/servers/components/waf/count.go create mode 100644 internal/web/actions/default/servers/components/waf/selectPopup.go create mode 100644 internal/web/models/base_dao.go create mode 100644 internal/web/models/node_cluster_dao.go create mode 100644 internal/web/models/server_dao.go create mode 100644 web/public/js/components/server/http-cache-policy-selector.js create mode 100644 web/public/js/components/server/http-firewall-policy-selector.js create mode 100644 web/views/@default/clusters/cluster/settings/cache/index.html create mode 100644 web/views/@default/clusters/cluster/settings/cache/index.js create mode 100644 web/views/@default/clusters/cluster/settings/waf/index.html create mode 100644 web/views/@default/clusters/cluster/settings/waf/index.js create mode 100644 web/views/@default/servers/components/cache/selectPopup.html create mode 100644 web/views/@default/servers/components/cache/selectPopup.js create mode 100644 web/views/@default/servers/components/waf/selectPopup.html create mode 100644 web/views/@default/servers/components/waf/selectPopup.js diff --git a/internal/tasks/task_sync_cluster.go b/internal/tasks/task_sync_cluster.go index d2ac2ff5..6ada44fb 100644 --- a/internal/tasks/task_sync_cluster.go +++ b/internal/tasks/task_sync_cluster.go @@ -55,7 +55,7 @@ func (this *SyncClusterTask) loop() error { for _, cluster := range resp.Clusters { _, err := rpcClient.NodeRPC().SyncNodesVersionWithCluster(ctx, &pb.SyncNodesVersionWithClusterRequest{ - ClusterId: cluster.Id, + NodeClusterId: cluster.Id, }) if err != nil { return err diff --git a/internal/web/actions/default/clusters/cluster/createBatch.go b/internal/web/actions/default/clusters/cluster/createBatch.go index 6055d325..2d1aeff1 100644 --- a/internal/web/actions/default/clusters/cluster/createBatch.go +++ b/internal/web/actions/default/clusters/cluster/createBatch.go @@ -77,11 +77,11 @@ func (this *CreateBatchAction) RunPost(params struct { // 保存 for _, ip := range realIPList { resp, err := this.RPC().NodeRPC().CreateNode(this.AdminContext(), &pb.CreateNodeRequest{ - Name: ip, - ClusterId: params.ClusterId, - GroupId: params.GroupId, - RegionId: params.RegionId, - Login: nil, + Name: ip, + NodeClusterId: params.ClusterId, + GroupId: params.GroupId, + RegionId: params.RegionId, + Login: nil, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/clusters/cluster/createNode.go b/internal/web/actions/default/clusters/cluster/createNode.go index 36341283..97159e40 100644 --- a/internal/web/actions/default/clusters/cluster/createNode.go +++ b/internal/web/actions/default/clusters/cluster/createNode.go @@ -118,13 +118,13 @@ func (this *CreateNodeAction) RunPost(params struct { // 保存 createResp, err := this.RPC().NodeRPC().CreateNode(this.AdminContext(), &pb.CreateNodeRequest{ - Name: params.Name, - ClusterId: params.ClusterId, - GroupId: params.GroupId, - RegionId: params.RegionId, - Login: loginInfo, - DnsDomainId: params.DnsDomainId, - DnsRoutes: dnsRouteCodes, + Name: params.Name, + NodeClusterId: params.ClusterId, + GroupId: params.GroupId, + RegionId: params.RegionId, + Login: loginInfo, + DnsDomainId: params.DnsDomainId, + DnsRoutes: dnsRouteCodes, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/clusters/cluster/delete.go b/internal/web/actions/default/clusters/cluster/delete.go index 51428a52..0be65319 100644 --- a/internal/web/actions/default/clusters/cluster/delete.go +++ b/internal/web/actions/default/clusters/cluster/delete.go @@ -33,7 +33,7 @@ func (this *DeleteAction) RunPost(params struct { } // 删除 - _, err = this.RPC().NodeClusterRPC().DeleteNodeCluster(this.AdminContext(), &pb.DeleteNodeClusterRequest{ClusterId: params.ClusterId}) + _, err = this.RPC().NodeClusterRPC().DeleteNodeCluster(this.AdminContext(), &pb.DeleteNodeClusterRequest{NodeClusterId: params.ClusterId}) if err != nil { this.ErrorPage(err) return diff --git a/internal/web/actions/default/clusters/cluster/groups/createPopup.go b/internal/web/actions/default/clusters/cluster/groups/createPopup.go index 237b5b18..26d0be92 100644 --- a/internal/web/actions/default/clusters/cluster/groups/createPopup.go +++ b/internal/web/actions/default/clusters/cluster/groups/createPopup.go @@ -34,8 +34,8 @@ func (this *CreatePopupAction) RunPost(params struct { Field("name", params.Name). Require("请输入分组名称") createResp, err := this.RPC().NodeGroupRPC().CreateNodeGroup(this.AdminContext(), &pb.CreateNodeGroupRequest{ - ClusterId: params.ClusterId, - Name: params.Name, + NodeClusterId: params.ClusterId, + Name: params.Name, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/clusters/cluster/groups/index.go b/internal/web/actions/default/clusters/cluster/groups/index.go index f452aeb0..408ef63e 100644 --- a/internal/web/actions/default/clusters/cluster/groups/index.go +++ b/internal/web/actions/default/clusters/cluster/groups/index.go @@ -19,7 +19,7 @@ func (this *IndexAction) RunGet(params struct { ClusterId int64 }) { groupsResp, err := this.RPC().NodeGroupRPC().FindAllEnabledNodeGroupsWithClusterId(this.AdminContext(), &pb.FindAllEnabledNodeGroupsWithClusterIdRequest{ - ClusterId: params.ClusterId, + NodeClusterId: params.ClusterId, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/clusters/cluster/groups/selectPopup.go b/internal/web/actions/default/clusters/cluster/groups/selectPopup.go index 967ef772..7b3be452 100644 --- a/internal/web/actions/default/clusters/cluster/groups/selectPopup.go +++ b/internal/web/actions/default/clusters/cluster/groups/selectPopup.go @@ -18,7 +18,7 @@ func (this *SelectPopupAction) Init() { func (this *SelectPopupAction) RunGet(params struct { ClusterId int64 }) { - groupsResp, err := this.RPC().NodeGroupRPC().FindAllEnabledNodeGroupsWithClusterId(this.AdminContext(), &pb.FindAllEnabledNodeGroupsWithClusterIdRequest{ClusterId: params.ClusterId}) + groupsResp, err := this.RPC().NodeGroupRPC().FindAllEnabledNodeGroupsWithClusterId(this.AdminContext(), &pb.FindAllEnabledNodeGroupsWithClusterIdRequest{NodeClusterId: params.ClusterId}) if err != nil { this.ErrorPage(err) } diff --git a/internal/web/actions/default/clusters/cluster/index.go b/internal/web/actions/default/clusters/cluster/index.go index f73918d9..5004d9b2 100644 --- a/internal/web/actions/default/clusters/cluster/index.go +++ b/internal/web/actions/default/clusters/cluster/index.go @@ -37,12 +37,12 @@ func (this *IndexAction) RunGet(params struct { this.Data["keyword"] = params.Keyword countResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{ - ClusterId: params.ClusterId, - GroupId: params.GroupId, - RegionId: params.RegionId, - InstallState: types.Int32(params.InstalledState), - ActiveState: types.Int32(params.ActiveState), - Keyword: params.Keyword, + NodeClusterId: params.ClusterId, + GroupId: params.GroupId, + RegionId: params.RegionId, + InstallState: types.Int32(params.InstalledState), + ActiveState: types.Int32(params.ActiveState), + Keyword: params.Keyword, }) if err != nil { this.ErrorPage(err) @@ -53,14 +53,14 @@ func (this *IndexAction) RunGet(params struct { this.Data["page"] = page.AsHTML() nodesResp, err := this.RPC().NodeRPC().ListEnabledNodesMatch(this.AdminContext(), &pb.ListEnabledNodesMatchRequest{ - Offset: page.Offset, - Size: page.Size, - ClusterId: params.ClusterId, - GroupId: params.GroupId, - RegionId: params.RegionId, - InstallState: types.Int32(params.InstalledState), - ActiveState: types.Int32(params.ActiveState), - Keyword: params.Keyword, + Offset: page.Offset, + Size: page.Size, + NodeClusterId: params.ClusterId, + GroupId: params.GroupId, + RegionId: params.RegionId, + InstallState: types.Int32(params.InstalledState), + ActiveState: types.Int32(params.ActiveState), + Keyword: params.Keyword, }) nodeMaps := []maps.Map{} for _, node := range nodesResp.Nodes { @@ -154,7 +154,7 @@ func (this *IndexAction) RunGet(params struct { // 所有分组 groupMaps := []maps.Map{} groupsResp, err := this.RPC().NodeGroupRPC().FindAllEnabledNodeGroupsWithClusterId(this.AdminContext(), &pb.FindAllEnabledNodeGroupsWithClusterIdRequest{ - ClusterId: params.ClusterId, + NodeClusterId: params.ClusterId, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/clusters/cluster/installManual.go b/internal/web/actions/default/clusters/cluster/installManual.go index bbc29093..187a4401 100644 --- a/internal/web/actions/default/clusters/cluster/installManual.go +++ b/internal/web/actions/default/clusters/cluster/installManual.go @@ -21,7 +21,7 @@ func (this *InstallManualAction) RunGet(params struct { }) { this.Data["leftMenuItems"] = LeftMenuItemsForInstall(params.ClusterId, "manual") - nodesResp, err := this.RPC().NodeRPC().FindAllNotInstalledNodesWithClusterId(this.AdminContext(), &pb.FindAllNotInstalledNodesWithClusterIdRequest{ClusterId: params.ClusterId}) + nodesResp, err := this.RPC().NodeRPC().FindAllNotInstalledNodesWithClusterId(this.AdminContext(), &pb.FindAllNotInstalledNodesWithClusterIdRequest{NodeClusterId: params.ClusterId}) if err != nil { this.ErrorPage(err) return diff --git a/internal/web/actions/default/clusters/cluster/installNodes.go b/internal/web/actions/default/clusters/cluster/installNodes.go index 71c60af8..5e110819 100644 --- a/internal/web/actions/default/clusters/cluster/installNodes.go +++ b/internal/web/actions/default/clusters/cluster/installNodes.go @@ -21,7 +21,7 @@ func (this *InstallNodesAction) RunGet(params struct { }) { this.Data["leftMenuItems"] = LeftMenuItemsForInstall(params.ClusterId, "register") - clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{ClusterId: params.ClusterId}) + clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{NodeClusterId: params.ClusterId}) if err != nil { this.ErrorPage(err) return @@ -33,7 +33,7 @@ func (this *InstallNodesAction) RunGet(params struct { cluster := clusterResp.Cluster - clusterAPINodesResp, err := this.RPC().NodeClusterRPC().FindAPINodesWithNodeCluster(this.AdminContext(), &pb.FindAPINodesWithNodeClusterRequest{ClusterId: params.ClusterId}) + clusterAPINodesResp, err := this.RPC().NodeClusterRPC().FindAPINodesWithNodeCluster(this.AdminContext(), &pb.FindAPINodesWithNodeClusterRequest{NodeClusterId: params.ClusterId}) if err != nil { this.ErrorPage(err) return diff --git a/internal/web/actions/default/clusters/cluster/installRemote.go b/internal/web/actions/default/clusters/cluster/installRemote.go index a5ba4dee..46a1eebb 100644 --- a/internal/web/actions/default/clusters/cluster/installRemote.go +++ b/internal/web/actions/default/clusters/cluster/installRemote.go @@ -23,7 +23,7 @@ func (this *InstallRemoteAction) RunGet(params struct { }) { this.Data["leftMenuItems"] = LeftMenuItemsForInstall(params.ClusterId, "install") - nodesResp, err := this.RPC().NodeRPC().FindAllNotInstalledNodesWithClusterId(this.AdminContext(), &pb.FindAllNotInstalledNodesWithClusterIdRequest{ClusterId: params.ClusterId}) + nodesResp, err := this.RPC().NodeRPC().FindAllNotInstalledNodesWithClusterId(this.AdminContext(), &pb.FindAllNotInstalledNodesWithClusterIdRequest{NodeClusterId: params.ClusterId}) if err != nil { this.ErrorPage(err) return diff --git a/internal/web/actions/default/clusters/cluster/node/install.go b/internal/web/actions/default/clusters/cluster/node/install.go index 9f817eb5..45d80a7a 100644 --- a/internal/web/actions/default/clusters/cluster/node/install.go +++ b/internal/web/actions/default/clusters/cluster/node/install.go @@ -53,7 +53,7 @@ func (this *InstallAction) RunGet(params struct { var clusterMap maps.Map = nil if node.Cluster != nil { clusterId := node.Cluster.Id - clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{ClusterId: clusterId}) + clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{NodeClusterId: clusterId}) if err != nil { this.ErrorPage(err) return diff --git a/internal/web/actions/default/clusters/cluster/node/node.go b/internal/web/actions/default/clusters/cluster/node/node.go index 4f58ef93..a99ed1a7 100644 --- a/internal/web/actions/default/clusters/cluster/node/node.go +++ b/internal/web/actions/default/clusters/cluster/node/node.go @@ -39,7 +39,7 @@ func (this *NodeAction) RunGet(params struct { var clusterMap maps.Map = nil if node.Cluster != nil { clusterId := node.Cluster.Id - clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{ClusterId: clusterId}) + clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{NodeClusterId: clusterId}) if err != nil { this.ErrorPage(err) return diff --git a/internal/web/actions/default/clusters/cluster/node/update.go b/internal/web/actions/default/clusters/cluster/node/update.go index 9a7975a8..a7d0bf9d 100644 --- a/internal/web/actions/default/clusters/cluster/node/update.go +++ b/internal/web/actions/default/clusters/cluster/node/update.go @@ -247,16 +247,16 @@ func (this *UpdateAction) RunPost(params struct { // 保存 _, err := this.RPC().NodeRPC().UpdateNode(this.AdminContext(), &pb.UpdateNodeRequest{ - NodeId: params.NodeId, - GroupId: params.GroupId, - RegionId: params.RegionId, - Name: params.Name, - ClusterId: params.ClusterId, - Login: loginInfo, - MaxCPU: params.MaxCPU, - IsOn: params.IsOn, - DnsDomainId: params.DnsDomainId, - DnsRoutes: dnsRouteCodes, + NodeId: params.NodeId, + GroupId: params.GroupId, + RegionId: params.RegionId, + Name: params.Name, + NodeClusterId: params.ClusterId, + Login: loginInfo, + MaxCPU: params.MaxCPU, + IsOn: params.IsOn, + DnsDomainId: params.DnsDomainId, + DnsRoutes: dnsRouteCodes, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/clusters/cluster/settings/cache/index.go b/internal/web/actions/default/clusters/cluster/settings/cache/index.go new file mode 100644 index 00000000..2539a762 --- /dev/null +++ b/internal/web/actions/default/clusters/cluster/settings/cache/index.go @@ -0,0 +1,75 @@ +package cache + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/models" + "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("cache") +} + +func (this *IndexAction) RunGet(params struct { + ClusterId int64 +}) { + cluster, err := models.SharedNodeClusterDAO.FindEnabledNodeCluster(this.AdminContext(), params.ClusterId) + if err != nil { + this.ErrorPage(err) + return + } + if cluster == nil { + this.NotFound("nodeCluster", params.ClusterId) + return + } + + // 缓存设置 + this.Data["cachePolicy"] = nil + if cluster.HttpCachePolicyId > 0 { + cachePolicy, err := models.SharedHTTPCachePolicyDAO.FindEnabledHTTPCachePolicy(this.AdminContext(), cluster.HttpCachePolicyId) + if err != nil { + this.ErrorPage(err) + return + } + if cachePolicy != nil { + this.Data["cachePolicy"] = maps.Map{ + "id": cachePolicy.Id, + "name": cachePolicy.Name, + "isOn": cachePolicy.IsOn, + } + } + } + + this.Show() +} + +func (this *IndexAction) RunPost(params struct { + ClusterId int64 + CachePolicyId int64 + + Must *actions.Must + CSRF *actionutils.CSRF +}) { + defer this.CreateLogInfo("设置集群 %d 的缓存策略为 %d", params.ClusterId, params.CachePolicyId) + + if params.CachePolicyId <= 0 { + this.Fail("请选择缓存策略") + } + + _, err := this.RPC().NodeClusterRPC().UpdateNodeClusterHTTPCachePolicyId(this.AdminContext(), &pb.UpdateNodeClusterHTTPCachePolicyIdRequest{ + NodeClusterId: params.ClusterId, + HttpCachePolicyId: params.CachePolicyId, + }) + if err != nil { + this.ErrorPage(err) + return + } + this.Success() +} diff --git a/internal/web/actions/default/clusters/cluster/settings/health.go b/internal/web/actions/default/clusters/cluster/settings/health.go index 8b9df1ce..1bc3c411 100644 --- a/internal/web/actions/default/clusters/cluster/settings/health.go +++ b/internal/web/actions/default/clusters/cluster/settings/health.go @@ -21,7 +21,7 @@ func (this *HealthAction) Init() { func (this *HealthAction) RunGet(params struct { ClusterId int64 }) { - configResp, err := this.RPC().NodeClusterRPC().FindNodeClusterHealthCheckConfig(this.AdminContext(), &pb.FindNodeClusterHealthCheckConfigRequest{ClusterId: params.ClusterId}) + configResp, err := this.RPC().NodeClusterRPC().FindNodeClusterHealthCheckConfig(this.AdminContext(), &pb.FindNodeClusterHealthCheckConfigRequest{NodeClusterId: params.ClusterId}) if err != nil { this.ErrorPage(err) return @@ -56,7 +56,7 @@ func (this *HealthAction) RunPost(params struct { } _, err = this.RPC().NodeClusterRPC().UpdateNodeClusterHealthCheck(this.AdminContext(), &pb.UpdateNodeClusterHealthCheckRequest{ - ClusterId: params.ClusterId, + NodeClusterId: params.ClusterId, HealthCheckJSON: params.HealthCheckJSON, }) if err != nil { diff --git a/internal/web/actions/default/clusters/cluster/settings/healthRunPopup.go b/internal/web/actions/default/clusters/cluster/settings/healthRunPopup.go index 406b50b9..cb6a02f1 100644 --- a/internal/web/actions/default/clusters/cluster/settings/healthRunPopup.go +++ b/internal/web/actions/default/clusters/cluster/settings/healthRunPopup.go @@ -28,7 +28,7 @@ func (this *HealthRunPopupAction) RunPost(params struct { // 创建日志 defer this.CreateLog(oplogs.LevelInfo, "执行集群健康检查设置 %d", params.ClusterId) - resp, err := this.RPC().NodeClusterRPC().ExecuteNodeClusterHealthCheck(this.AdminContext(), &pb.ExecuteNodeClusterHealthCheckRequest{ClusterId: params.ClusterId}) + resp, err := this.RPC().NodeClusterRPC().ExecuteNodeClusterHealthCheck(this.AdminContext(), &pb.ExecuteNodeClusterHealthCheckRequest{NodeClusterId: params.ClusterId}) if err != nil { this.Fail(err.Error()) } diff --git a/internal/web/actions/default/clusters/cluster/settings/index.go b/internal/web/actions/default/clusters/cluster/settings/index.go index a8e37823..c940e187 100644 --- a/internal/web/actions/default/clusters/cluster/settings/index.go +++ b/internal/web/actions/default/clusters/cluster/settings/index.go @@ -21,7 +21,7 @@ func (this *IndexAction) Init() { func (this *IndexAction) RunGet(params struct { ClusterId int64 }) { - clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{ClusterId: params.ClusterId}) + clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{NodeClusterId: params.ClusterId}) if err != nil { this.ErrorPage(err) return @@ -79,10 +79,10 @@ func (this *IndexAction) RunPost(params struct { Require("请输入集群名称") _, err := this.RPC().NodeClusterRPC().UpdateNodeCluster(this.AdminContext(), &pb.UpdateNodeClusterRequest{ - ClusterId: params.ClusterId, - Name: params.Name, - GrantId: params.GrantId, - InstallDir: params.InstallDir, + NodeClusterId: params.ClusterId, + Name: params.Name, + GrantId: params.GrantId, + InstallDir: params.InstallDir, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/clusters/cluster/settings/init.go b/internal/web/actions/default/clusters/cluster/settings/init.go index be428aa2..f59cfe1b 100644 --- a/internal/web/actions/default/clusters/cluster/settings/init.go +++ b/internal/web/actions/default/clusters/cluster/settings/init.go @@ -2,8 +2,10 @@ package settings import ( "github.com/TeaOSLab/EdgeAdmin/internal/configloaders" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/cache" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/dns" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/toa" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/waf" clusters "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/clusterutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/helpers" "github.com/iwind/TeaGo" @@ -16,9 +18,17 @@ func init() { Helper(clusters.NewClusterHelper()). Prefix("/clusters/cluster/settings"). GetPost("", new(IndexAction)). + + // 健康检查 GetPost("/health", new(HealthAction)). GetPost("/healthRunPopup", new(HealthRunPopupAction)). + // 缓存 + GetPost("/cache", new(cache.IndexAction)). + + // WAF + GetPost("/waf", new(waf.IndexAction)). + // DNS Prefix("/clusters/cluster/settings/dns"). GetPost("", new(dns.IndexAction)). diff --git a/internal/web/actions/default/clusters/cluster/settings/waf/index.go b/internal/web/actions/default/clusters/cluster/settings/waf/index.go new file mode 100644 index 00000000..eeac4277 --- /dev/null +++ b/internal/web/actions/default/clusters/cluster/settings/waf/index.go @@ -0,0 +1,75 @@ +package waf + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/models" + "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("waf") +} + +func (this *IndexAction) RunGet(params struct { + ClusterId int64 +}) { + cluster, err := models.SharedNodeClusterDAO.FindEnabledNodeCluster(this.AdminContext(), params.ClusterId) + if err != nil { + this.ErrorPage(err) + return + } + if cluster == nil { + this.NotFound("nodeCluster", params.ClusterId) + return + } + + // WAF设置 + this.Data["firewallPolicy"] = nil + if cluster.HttpFirewallPolicyId > 0 { + firewallPolicy, err := models.SharedHTTPFirewallPolicyDAO.FindEnabledHTTPFirewallPolicy(this.AdminContext(), cluster.HttpFirewallPolicyId) + if err != nil { + this.ErrorPage(err) + return + } + if firewallPolicy != nil { + this.Data["firewallPolicy"] = maps.Map{ + "id": firewallPolicy.Id, + "name": firewallPolicy.Name, + "isOn": firewallPolicy.IsOn, + } + } + } + + this.Show() +} + +func (this *IndexAction) RunPost(params struct { + ClusterId int64 + HttpFirewallPolicyId int64 + + Must *actions.Must + CSRF *actionutils.CSRF +}) { + defer this.CreateLogInfo("设置集群 %d 的WAF策略为 %d", params.ClusterId, params.HttpFirewallPolicyId) + + if params.HttpFirewallPolicyId <= 0 { + this.Fail("请选择WAF策略") + } + + _, err := this.RPC().NodeClusterRPC().UpdateNodeClusterHTTPFirewallPolicyId(this.AdminContext(), &pb.UpdateNodeClusterHTTPFirewallPolicyIdRequest{ + NodeClusterId: params.ClusterId, + HttpFirewallPolicyId: params.HttpFirewallPolicyId, + }) + if err != nil { + this.ErrorPage(err) + return + } + this.Success() +} diff --git a/internal/web/actions/default/clusters/cluster/upgradeRemote.go b/internal/web/actions/default/clusters/cluster/upgradeRemote.go index 85c43a9e..9bb4abd0 100644 --- a/internal/web/actions/default/clusters/cluster/upgradeRemote.go +++ b/internal/web/actions/default/clusters/cluster/upgradeRemote.go @@ -24,7 +24,7 @@ func (this *UpgradeRemoteAction) RunGet(params struct { this.Data["leftMenuItems"] = LeftMenuItemsForInstall(params.ClusterId, "upgrade") nodes := []maps.Map{} - resp, err := this.RPC().NodeRPC().FindAllUpgradeNodesWithClusterId(this.AdminContext(), &pb.FindAllUpgradeNodesWithClusterIdRequest{ClusterId: params.ClusterId}) + resp, err := this.RPC().NodeRPC().FindAllUpgradeNodesWithClusterId(this.AdminContext(), &pb.FindAllUpgradeNodesWithClusterIdRequest{NodeClusterId: params.ClusterId}) if err != nil { this.ErrorPage(err) return diff --git a/internal/web/actions/default/clusters/clusterutils/cluster_helper.go b/internal/web/actions/default/clusters/clusterutils/cluster_helper.go index d946798e..c5016a6d 100644 --- a/internal/web/actions/default/clusters/clusterutils/cluster_helper.go +++ b/internal/web/actions/default/clusters/clusterutils/cluster_helper.go @@ -38,7 +38,7 @@ func (this *ClusterHelper) BeforeAction(action *actions.ActionObject) { } if clusterId > 0 { - clusterResp, err := rpcClient.NodeClusterRPC().FindEnabledNodeCluster(rpcClient.Context(action.Context.GetInt64("adminId")), &pb.FindEnabledNodeClusterRequest{ClusterId: clusterId}) + clusterResp, err := rpcClient.NodeClusterRPC().FindEnabledNodeCluster(rpcClient.Context(action.Context.GetInt64("adminId")), &pb.FindEnabledNodeClusterRequest{NodeClusterId: clusterId}) if err != nil { logs.Error(err) return @@ -77,6 +77,16 @@ func (this *ClusterHelper) createSettingMenu(clusterId string, selectedItem stri "url": "/clusters/cluster/settings?clusterId=" + clusterId, "isActive": selectedItem == "basic", }) + items = append(items, maps.Map{ + "name": "缓存设置", + "url": "/clusters/cluster/settings/cache?clusterId=" + clusterId, + "isActive": selectedItem == "cache", + }) + items = append(items, maps.Map{ + "name": "WAF设置", + "url": "/clusters/cluster/settings/waf?clusterId=" + clusterId, + "isActive": selectedItem == "waf", + }) items = append(items, maps.Map{ "name": "健康检查", "url": "/clusters/cluster/settings/health?clusterId=" + clusterId, diff --git a/internal/web/actions/default/clusters/create.go b/internal/web/actions/default/clusters/create.go index ccd82f8b..4ec83dea 100644 --- a/internal/web/actions/default/clusters/create.go +++ b/internal/web/actions/default/clusters/create.go @@ -30,6 +30,12 @@ func (this *CreateAction) RunGet(params struct{}) { func (this *CreateAction) RunPost(params struct { Name string + // 缓存策略 + CachePolicyId int64 + + // WAF策略 + HttpFirewallPolicyId int64 + // SSH相关 GrantId int64 InstallDir string @@ -44,6 +50,13 @@ func (this *CreateAction) RunPost(params struct { Field("name", params.Name). Require("请输入集群名称") + if params.CachePolicyId <= 0 { + this.Fail("请选择或者创建缓存策略") + } + if params.HttpFirewallPolicyId <= 0 { + this.Fail("请选择或者创建WAF策略") + } + // 检查DNS名称 if len(params.DnsName) > 0 { if !domainutils.ValidateDomainFormat(params.DnsName) { @@ -67,11 +80,13 @@ func (this *CreateAction) RunPost(params struct { // TODO 检查DnsDomainId的有效性 createResp, err := this.RPC().NodeClusterRPC().CreateNodeCluster(this.AdminContext(), &pb.CreateNodeClusterRequest{ - Name: params.Name, - GrantId: params.GrantId, - InstallDir: params.InstallDir, - DnsDomainId: params.DnsDomainId, - DnsName: params.DnsName, + Name: params.Name, + GrantId: params.GrantId, + InstallDir: params.InstallDir, + DnsDomainId: params.DnsDomainId, + DnsName: params.DnsName, + HttpCachePolicyId: params.CachePolicyId, + HttpFirewallPolicyId: params.HttpFirewallPolicyId, }) if err != nil { this.ErrorPage(err) @@ -79,7 +94,7 @@ func (this *CreateAction) RunPost(params struct { } // 创建日志 - defer this.CreateLog(oplogs.LevelInfo, "创建节点集群:%d", createResp.ClusterId) + defer this.CreateLog(oplogs.LevelInfo, "创建节点集群:%d", createResp.NodeClusterId) this.Success() } diff --git a/internal/web/actions/default/clusters/index.go b/internal/web/actions/default/clusters/index.go index f776e8c7..1118b7a3 100644 --- a/internal/web/actions/default/clusters/index.go +++ b/internal/web/actions/default/clusters/index.go @@ -38,7 +38,7 @@ func (this *IndexAction) RunGet(params struct{}) { } for _, cluster := range clustersResp.Clusters { // 全部节点数量 - countNodesResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{ClusterId: cluster.Id}) + countNodesResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{NodeClusterId: cluster.Id}) if err != nil { this.ErrorPage(err) return @@ -46,8 +46,8 @@ func (this *IndexAction) RunGet(params struct{}) { // 在线节点 countActiveNodesResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{ - ClusterId: cluster.Id, - ActiveState: types.Int32(configutils.BoolStateYes), + NodeClusterId: cluster.Id, + ActiveState: types.Int32(configutils.BoolStateYes), }) if err != nil { this.ErrorPage(err) @@ -55,7 +55,7 @@ func (this *IndexAction) RunGet(params struct{}) { } // 需要升级的节点 - countUpgradeNodesResp, err := this.RPC().NodeRPC().CountAllUpgradeNodesWithClusterId(this.AdminContext(), &pb.CountAllUpgradeNodesWithClusterIdRequest{ClusterId: cluster.Id}) + countUpgradeNodesResp, err := this.RPC().NodeRPC().CountAllUpgradeNodesWithClusterId(this.AdminContext(), &pb.CountAllUpgradeNodesWithClusterIdRequest{NodeClusterId: cluster.Id}) if err != nil { this.ErrorPage(err) return diff --git a/internal/web/actions/default/clusters/sync.go b/internal/web/actions/default/clusters/sync.go index bc41cd89..94bf10d5 100644 --- a/internal/web/actions/default/clusters/sync.go +++ b/internal/web/actions/default/clusters/sync.go @@ -25,7 +25,7 @@ func (this *SyncAction) RunPost(params struct{}) { for _, cluster := range clusters { _, err := this.RPC().NodeRPC().SyncNodesVersionWithCluster(this.AdminContext(), &pb.SyncNodesVersionWithClusterRequest{ - ClusterId: cluster.Id, + NodeClusterId: cluster.Id, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/dns/clusters/cluster.go b/internal/web/actions/default/dns/clusters/cluster.go index 4a0b3ada..9a7b55a1 100644 --- a/internal/web/actions/default/dns/clusters/cluster.go +++ b/internal/web/actions/default/dns/clusters/cluster.go @@ -18,7 +18,7 @@ func (this *ClusterAction) RunGet(params struct { ClusterId int64 }) { // 集群信息 - clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{ClusterId: params.ClusterId}) + clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{NodeClusterId: params.ClusterId}) if err != nil { this.ErrorPage(err) return @@ -77,7 +77,7 @@ func (this *ClusterAction) RunGet(params struct { "name": route.Name, "code": route.Code, }, - "clusterId": node.ClusterId, + "clusterId": node.NodeClusterId, }) } } else { @@ -89,14 +89,14 @@ func (this *ClusterAction) RunGet(params struct { "name": "", "code": "", }, - "clusterId": node.ClusterId, + "clusterId": node.NodeClusterId, }) } } this.Data["nodes"] = nodeMaps // 代理服务解析记录 - serversResp, err := this.RPC().ServerRPC().FindAllEnabledServersDNSWithClusterId(this.AdminContext(), &pb.FindAllEnabledServersDNSWithClusterIdRequest{ClusterId: params.ClusterId}) + serversResp, err := this.RPC().ServerRPC().FindAllEnabledServersDNSWithClusterId(this.AdminContext(), &pb.FindAllEnabledServersDNSWithClusterIdRequest{NodeClusterId: params.ClusterId}) if err != nil { this.ErrorPage(err) return diff --git a/internal/web/actions/default/nodes/nodeutils/utils.go b/internal/web/actions/default/nodes/nodeutils/utils.go index 18838168..c697e87c 100644 --- a/internal/web/actions/default/nodes/nodeutils/utils.go +++ b/internal/web/actions/default/nodes/nodeutils/utils.go @@ -32,7 +32,7 @@ func SendMessageToCluster(ctx context.Context, clusterId int64, code string, msg } // 获取所有节点 - nodesResp, err := defaultRPCClient.NodeRPC().FindAllEnabledNodesWithClusterId(ctx, &pb.FindAllEnabledNodesWithClusterIdRequest{ClusterId: clusterId}) + nodesResp, err := defaultRPCClient.NodeRPC().FindAllEnabledNodesWithClusterId(ctx, &pb.FindAllEnabledNodesWithClusterIdRequest{NodeClusterId: clusterId}) if err != nil { return results, err } diff --git a/internal/web/actions/default/servers/components/cache/cacheutils/utils.go b/internal/web/actions/default/servers/components/cache/cacheutils/utils.go index 6cdf130d..d3fb9ab8 100644 --- a/internal/web/actions/default/servers/components/cache/cacheutils/utils.go +++ b/internal/web/actions/default/servers/components/cache/cacheutils/utils.go @@ -22,15 +22,15 @@ func FindCachePolicyNameWithoutError(parent *actionutils.ParentAction, cachePoli // 查找缓存策略配置 func FindCachePolicy(parent *actionutils.ParentAction, cachePolicyId int64) (*serverconfigs.HTTPCachePolicy, error) { - resp, err := parent.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(parent.AdminContext(), &pb.FindEnabledHTTPCachePolicyConfigRequest{CachePolicyId: cachePolicyId}) + resp, err := parent.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(parent.AdminContext(), &pb.FindEnabledHTTPCachePolicyConfigRequest{HttpCachePolicyId: cachePolicyId}) if err != nil { return nil, err } - if len(resp.CachePolicyJSON) == 0 { + if len(resp.HttpCachePolicyJSON) == 0 { return nil, errors.New("cache policy not found") } config := &serverconfigs.HTTPCachePolicy{} - err = json.Unmarshal(resp.CachePolicyJSON, config) + err = json.Unmarshal(resp.HttpCachePolicyJSON, config) if err != nil { return nil, err } diff --git a/internal/web/actions/default/servers/components/cache/clean.go b/internal/web/actions/default/servers/components/cache/clean.go index d7f83f0a..89519640 100644 --- a/internal/web/actions/default/servers/components/cache/clean.go +++ b/internal/web/actions/default/servers/components/cache/clean.go @@ -58,12 +58,12 @@ func (this *CleanAction) RunPost(params struct { Value: strconv.FormatInt(params.ClusterId, 10), }) - cachePolicyResp, err := this.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPCachePolicyConfigRequest{CachePolicyId: params.CachePolicyId}) + cachePolicyResp, err := this.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPCachePolicyConfigRequest{HttpCachePolicyId: params.CachePolicyId}) if err != nil { this.ErrorPage(err) return } - cachePolicyJSON := cachePolicyResp.CachePolicyJSON + cachePolicyJSON := cachePolicyResp.HttpCachePolicyJSON if len(cachePolicyJSON) == 0 { this.Fail("找不到要操作的缓存策略") } diff --git a/internal/web/actions/default/servers/components/cache/count.go b/internal/web/actions/default/servers/components/cache/count.go new file mode 100644 index 00000000..596dfe2b --- /dev/null +++ b/internal/web/actions/default/servers/components/cache/count.go @@ -0,0 +1,22 @@ +package cache + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" +) + +// 计算可用缓存策略数量 +type CountAction struct { + actionutils.ParentAction +} + +func (this *CountAction) RunPost(params struct{}) { + countResp, err := this.RPC().HTTPCachePolicyRPC().CountAllEnabledHTTPCachePolicies(this.AdminContext(), &pb.CountAllEnabledHTTPCachePoliciesRequest{}) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["count"] = countResp.Count + + this.Success() +} diff --git a/internal/web/actions/default/servers/components/cache/createPopup.go b/internal/web/actions/default/servers/components/cache/createPopup.go index fbe7e826..85c558e9 100644 --- a/internal/web/actions/default/servers/components/cache/createPopup.go +++ b/internal/web/actions/default/servers/components/cache/createPopup.go @@ -7,6 +7,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/maps" ) type CreatePopupAction struct { @@ -79,8 +80,14 @@ func (this *CreatePopupAction) RunPost(params struct { return } + // 返回数据 + this.Data["cachePolicy"] = maps.Map{ + "id": createResp.HttpCachePolicyId, + "name": params.Name, + } + // 创建日志 - defer this.CreateLog(oplogs.LevelInfo, "创建缓存策略:%d", createResp.CachePolicyId) + defer this.CreateLog(oplogs.LevelInfo, "创建缓存策略:%d", createResp.HttpCachePolicyId) this.Success() } diff --git a/internal/web/actions/default/servers/components/cache/delete.go b/internal/web/actions/default/servers/components/cache/delete.go index af0c02df..3db023b3 100644 --- a/internal/web/actions/default/servers/components/cache/delete.go +++ b/internal/web/actions/default/servers/components/cache/delete.go @@ -14,16 +14,16 @@ func (this *DeleteAction) RunPost(params struct { CachePolicyId int64 }) { // 检查是否被引用 - countResp, err := this.RPC().ServerRPC().CountAllEnabledServersWithCachePolicyId(this.AdminContext(), &pb.CountAllEnabledServersWithCachePolicyIdRequest{CachePolicyId: params.CachePolicyId}) + countResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClustersWithHTTPCachePolicyId(this.AdminContext(), &pb.CountAllEnabledNodeClustersWithHTTPCachePolicyIdRequest{HttpCachePolicyId: params.CachePolicyId}) if err != nil { this.ErrorPage(err) return } if countResp.Count > 0 { - this.Fail("此缓存策略正在被有些服务引用,请修改后再删除。") + this.Fail("此缓存策略正在被有些集群引用,请修改后再删除。") } - _, err = this.RPC().HTTPCachePolicyRPC().DeleteHTTPCachePolicy(this.AdminContext(), &pb.DeleteHTTPCachePolicyRequest{CachePolicyId: params.CachePolicyId}) + _, err = this.RPC().HTTPCachePolicyRPC().DeleteHTTPCachePolicy(this.AdminContext(), &pb.DeleteHTTPCachePolicyRequest{HttpCachePolicyId: params.CachePolicyId}) if err != nil { this.ErrorPage(err) return diff --git a/internal/web/actions/default/servers/components/cache/index.go b/internal/web/actions/default/servers/components/cache/index.go index d1024627..d0480839 100644 --- a/internal/web/actions/default/servers/components/cache/index.go +++ b/internal/web/actions/default/servers/components/cache/index.go @@ -34,7 +34,7 @@ func (this *IndexAction) RunGet(params struct{}) { this.ErrorPage(err) return } - cachePoliciesJSON := listResp.CachePoliciesJSON + cachePoliciesJSON := listResp.HttpCachePoliciesJSON cachePolicies := []*serverconfigs.HTTPCachePolicy{} err = json.Unmarshal(cachePoliciesJSON, &cachePolicies) if err != nil { @@ -45,16 +45,16 @@ func (this *IndexAction) RunGet(params struct{}) { infos := []maps.Map{} for _, cachePolicy := range cachePolicies { - countServersResp, err := this.RPC().ServerRPC().CountAllEnabledServersWithCachePolicyId(this.AdminContext(), &pb.CountAllEnabledServersWithCachePolicyIdRequest{CachePolicyId: cachePolicy.Id}) + countClustersResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClustersWithHTTPCachePolicyId(this.AdminContext(), &pb.CountAllEnabledNodeClustersWithHTTPCachePolicyIdRequest{HttpCachePolicyId: cachePolicy.Id}) if err != nil { this.ErrorPage(err) return } - countServers := countServersResp.Count + countClusters := countClustersResp.Count infos = append(infos, maps.Map{ - "typeName": serverconfigs.FindCachePolicyStorageName(cachePolicy.Type), - "countServers": countServers, + "typeName": serverconfigs.FindCachePolicyStorageName(cachePolicy.Type), + "countClusters": countClusters, }) } this.Data["infos"] = infos diff --git a/internal/web/actions/default/servers/components/cache/init.go b/internal/web/actions/default/servers/components/cache/init.go index be5ae613..4326ef57 100644 --- a/internal/web/actions/default/servers/components/cache/init.go +++ b/internal/web/actions/default/servers/components/cache/init.go @@ -26,6 +26,9 @@ func init() { Post("/delete", new(DeleteAction)). Post("/testRead", new(TestReadAction)). Post("/testWrite", new(TestWriteAction)). + Get("/selectPopup", new(SelectPopupAction)). + Post("/count", new(CountAction)). + EndAll() }) } diff --git a/internal/web/actions/default/servers/components/cache/policy.go b/internal/web/actions/default/servers/components/cache/policy.go index 14a1ef20..60cc0f19 100644 --- a/internal/web/actions/default/servers/components/cache/policy.go +++ b/internal/web/actions/default/servers/components/cache/policy.go @@ -3,7 +3,9 @@ package cache import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/cache/cacheutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" + "github.com/iwind/TeaGo/maps" ) type PolicyAction struct { @@ -26,5 +28,20 @@ func (this *PolicyAction) RunGet(params struct { this.Data["typeName"] = serverconfigs.FindCachePolicyStorageName(cachePolicy.Type) + // 正在使用此策略的集群 + clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClustersWithHTTPCachePolicyId(this.AdminContext(), &pb.FindAllEnabledNodeClustersWithHTTPCachePolicyIdRequest{HttpCachePolicyId: params.CachePolicyId}) + if err != nil { + this.ErrorPage(err) + return + } + clusterMaps := []maps.Map{} + for _, cluster := range clustersResp.NodeClusters { + clusterMaps = append(clusterMaps, maps.Map{ + "id": cluster.Id, + "name": cluster.Name, + }) + } + this.Data["clusters"] = clusterMaps + this.Show() } diff --git a/internal/web/actions/default/servers/components/cache/preheat.go b/internal/web/actions/default/servers/components/cache/preheat.go index 636e2a1f..08543391 100644 --- a/internal/web/actions/default/servers/components/cache/preheat.go +++ b/internal/web/actions/default/servers/components/cache/preheat.go @@ -61,12 +61,12 @@ func (this *PreheatAction) RunPost(params struct { Value: strconv.FormatInt(params.ClusterId, 10), }) - cachePolicyResp, err := this.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPCachePolicyConfigRequest{CachePolicyId: params.CachePolicyId}) + cachePolicyResp, err := this.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPCachePolicyConfigRequest{HttpCachePolicyId: params.CachePolicyId}) if err != nil { this.ErrorPage(err) return } - cachePolicyJSON := cachePolicyResp.CachePolicyJSON + cachePolicyJSON := cachePolicyResp.HttpCachePolicyJSON if len(cachePolicyJSON) == 0 { this.Fail("找不到要操作的缓存策略") } diff --git a/internal/web/actions/default/servers/components/cache/purge.go b/internal/web/actions/default/servers/components/cache/purge.go index 672a43f4..51007545 100644 --- a/internal/web/actions/default/servers/components/cache/purge.go +++ b/internal/web/actions/default/servers/components/cache/purge.go @@ -60,12 +60,12 @@ func (this *PurgeAction) RunPost(params struct { Value: strconv.FormatInt(params.ClusterId, 10), }) - cachePolicyResp, err := this.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPCachePolicyConfigRequest{CachePolicyId: params.CachePolicyId}) + cachePolicyResp, err := this.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPCachePolicyConfigRequest{HttpCachePolicyId: params.CachePolicyId}) if err != nil { this.ErrorPage(err) return } - cachePolicyJSON := cachePolicyResp.CachePolicyJSON + cachePolicyJSON := cachePolicyResp.HttpCachePolicyJSON if len(cachePolicyJSON) == 0 { this.Fail("找不到要操作的缓存策略") } diff --git a/internal/web/actions/default/servers/components/cache/selectPopup.go b/internal/web/actions/default/servers/components/cache/selectPopup.go new file mode 100644 index 00000000..4a158cbf --- /dev/null +++ b/internal/web/actions/default/servers/components/cache/selectPopup.go @@ -0,0 +1,60 @@ +package cache + +import ( + "encoding/json" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" + "github.com/iwind/TeaGo/maps" +) + +type SelectPopupAction struct { + actionutils.ParentAction +} + +func (this *SelectPopupAction) Init() { + this.Nav("", "", "") +} + +func (this *SelectPopupAction) RunGet(params struct{}) { + countResp, err := this.RPC().HTTPCachePolicyRPC().CountAllEnabledHTTPCachePolicies(this.AdminContext(), &pb.CountAllEnabledHTTPCachePoliciesRequest{}) + if err != nil { + this.ErrorPage(err) + return + } + count := countResp.Count + page := this.NewPage(count) + + this.Data["page"] = page.AsHTML() + + cachePoliciesResp, err := this.RPC().HTTPCachePolicyRPC().ListEnabledHTTPCachePolicies(this.AdminContext(), &pb.ListEnabledHTTPCachePoliciesRequest{ + Offset: page.Offset, + Size: page.Size, + }) + if err != nil { + this.ErrorPage(err) + return + } + cachePolicies := []*serverconfigs.HTTPCachePolicy{} + if len(cachePoliciesResp.HttpCachePoliciesJSON) > 0 { + err = json.Unmarshal(cachePoliciesResp.HttpCachePoliciesJSON, &cachePolicies) + if err != nil { + this.ErrorPage(err) + return + } + } + + policyMaps := []maps.Map{} + for _, cachePolicy := range cachePolicies { + policyMaps = append(policyMaps, maps.Map{ + "id": cachePolicy.Id, + "name": cachePolicy.Name, + "description": cachePolicy.Description, + "isOn": cachePolicy.IsOn, + }) + } + + this.Data["cachePolicies"] = policyMaps + + this.Show() +} diff --git a/internal/web/actions/default/servers/components/cache/stat.go b/internal/web/actions/default/servers/components/cache/stat.go index 11633d13..639ff4e3 100644 --- a/internal/web/actions/default/servers/components/cache/stat.go +++ b/internal/web/actions/default/servers/components/cache/stat.go @@ -58,12 +58,12 @@ func (this *StatAction) RunPost(params struct { Value: strconv.FormatInt(params.ClusterId, 10), }) - cachePolicyResp, err := this.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPCachePolicyConfigRequest{CachePolicyId: params.CachePolicyId}) + cachePolicyResp, err := this.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPCachePolicyConfigRequest{HttpCachePolicyId: params.CachePolicyId}) if err != nil { this.ErrorPage(err) return } - cachePolicyJSON := cachePolicyResp.CachePolicyJSON + cachePolicyJSON := cachePolicyResp.HttpCachePolicyJSON if len(cachePolicyJSON) == 0 { this.Fail("找不到要操作的缓存策略") } diff --git a/internal/web/actions/default/servers/components/cache/testRead.go b/internal/web/actions/default/servers/components/cache/testRead.go index fe5293f5..840c842f 100644 --- a/internal/web/actions/default/servers/components/cache/testRead.go +++ b/internal/web/actions/default/servers/components/cache/testRead.go @@ -25,12 +25,12 @@ func (this *TestReadAction) RunPost(params struct { Value: strconv.FormatInt(params.ClusterId, 10), }) - cachePolicyResp, err := this.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPCachePolicyConfigRequest{CachePolicyId: params.CachePolicyId}) + cachePolicyResp, err := this.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPCachePolicyConfigRequest{HttpCachePolicyId: params.CachePolicyId}) if err != nil { this.ErrorPage(err) return } - cachePolicyJSON := cachePolicyResp.CachePolicyJSON + cachePolicyJSON := cachePolicyResp.HttpCachePolicyJSON if len(cachePolicyJSON) == 0 { this.Fail("找不到要操作的缓存策略") } diff --git a/internal/web/actions/default/servers/components/cache/testWrite.go b/internal/web/actions/default/servers/components/cache/testWrite.go index be1e3f40..70061e6a 100644 --- a/internal/web/actions/default/servers/components/cache/testWrite.go +++ b/internal/web/actions/default/servers/components/cache/testWrite.go @@ -26,12 +26,12 @@ func (this *TestWriteAction) RunPost(params struct { Value: strconv.FormatInt(params.ClusterId, 10), }) - cachePolicyResp, err := this.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPCachePolicyConfigRequest{CachePolicyId: params.CachePolicyId}) + cachePolicyResp, err := this.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPCachePolicyConfigRequest{HttpCachePolicyId: params.CachePolicyId}) if err != nil { this.ErrorPage(err) return } - cachePolicyJSON := cachePolicyResp.CachePolicyJSON + cachePolicyJSON := cachePolicyResp.HttpCachePolicyJSON if len(cachePolicyJSON) == 0 { this.Fail("找不到要操作的缓存策略") } diff --git a/internal/web/actions/default/servers/components/cache/update.go b/internal/web/actions/default/servers/components/cache/update.go index 14297e3e..3c2e8e17 100644 --- a/internal/web/actions/default/servers/components/cache/update.go +++ b/internal/web/actions/default/servers/components/cache/update.go @@ -20,12 +20,12 @@ func (this *UpdateAction) Init() { func (this *UpdateAction) RunGet(params struct { CachePolicyId int64 }) { - configResp, err := this.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPCachePolicyConfigRequest{CachePolicyId: params.CachePolicyId}) + configResp, err := this.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPCachePolicyConfigRequest{HttpCachePolicyId: params.CachePolicyId}) if err != nil { this.ErrorPage(err) return } - configJSON := configResp.CachePolicyJSON + configJSON := configResp.HttpCachePolicyJSON if len(configJSON) == 0 { this.NotFound("cachePolicy", params.CachePolicyId) return @@ -90,7 +90,7 @@ func (this *UpdateAction) RunPost(params struct { return } _, err = this.RPC().HTTPCachePolicyRPC().UpdateHTTPCachePolicy(this.AdminContext(), &pb.UpdateHTTPCachePolicyRequest{ - CachePolicyId: params.CachePolicyId, + HttpCachePolicyId: params.CachePolicyId, IsOn: params.IsOn, Name: params.Name, Description: params.Description, diff --git a/internal/web/actions/default/servers/components/waf/count.go b/internal/web/actions/default/servers/components/waf/count.go new file mode 100644 index 00000000..634f10fb --- /dev/null +++ b/internal/web/actions/default/servers/components/waf/count.go @@ -0,0 +1,21 @@ +package waf + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" +) + +type CountAction struct { + actionutils.ParentAction +} + +func (this *CountAction) RunPost(params struct{}) { + countResp, err := this.RPC().HTTPFirewallPolicyRPC().CountAllEnabledHTTPFirewallPolicies(this.AdminContext(), &pb.CountAllEnabledHTTPFirewallPoliciesRequest{}) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["count"] = countResp.Count + + this.Success() +} diff --git a/internal/web/actions/default/servers/components/waf/createGroupPopup.go b/internal/web/actions/default/servers/components/waf/createGroupPopup.go index ffa299dd..3e6d3003 100644 --- a/internal/web/actions/default/servers/components/waf/createGroupPopup.go +++ b/internal/web/actions/default/servers/components/waf/createGroupPopup.go @@ -86,9 +86,9 @@ func (this *CreateGroupPopupAction) RunPost(params struct { } _, err = this.RPC().HTTPFirewallPolicyRPC().UpdateHTTPFirewallPolicyGroups(this.AdminContext(), &pb.UpdateHTTPFirewallPolicyGroupsRequest{ - FirewallPolicyId: params.FirewallPolicyId, - InboundJSON: inboundJSON, - OutboundJSON: outboundJSON, + HttpFirewallPolicyId: params.FirewallPolicyId, + InboundJSON: inboundJSON, + OutboundJSON: outboundJSON, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/servers/components/waf/createPopup.go b/internal/web/actions/default/servers/components/waf/createPopup.go index f5231db7..bc917ad2 100644 --- a/internal/web/actions/default/servers/components/waf/createPopup.go +++ b/internal/web/actions/default/servers/components/waf/createPopup.go @@ -46,18 +46,25 @@ func (this *CreatePopupAction) RunPost(params struct { Require("请输入策略名称") createResp, err := this.RPC().HTTPFirewallPolicyRPC().CreateHTTPFirewallPolicy(this.AdminContext(), &pb.CreateHTTPFirewallPolicyRequest{ - IsOn: params.IsOn, - Name: params.Name, - Description: params.Description, - FirewallGroupCodes: params.GroupCodes, + IsOn: params.IsOn, + Name: params.Name, + Description: params.Description, + HttpFirewallGroupCodes: params.GroupCodes, }) if err != nil { this.ErrorPage(err) return } + // 返回数据 + this.Data["firewallPolicy"] = maps.Map{ + "id": createResp.HttpFirewallPolicyId, + "name": params.Name, + "description": params.Description, + } + // 日志 - defer this.CreateLog(oplogs.LevelInfo, "创建WAF策略 %d", createResp.FirewallPolicyId) + defer this.CreateLog(oplogs.LevelInfo, "创建WAF策略 %d", createResp.HttpFirewallPolicyId) this.Success() } diff --git a/internal/web/actions/default/servers/components/waf/delete.go b/internal/web/actions/default/servers/components/waf/delete.go index 6d25e2d6..fe502355 100644 --- a/internal/web/actions/default/servers/components/waf/delete.go +++ b/internal/web/actions/default/servers/components/waf/delete.go @@ -16,22 +16,20 @@ func (this *DeleteAction) RunPost(params struct { // 日志 defer this.CreateLog(oplogs.LevelInfo, "删除WAF策略 %d", params.FirewallPolicyId) - countResp, err := this.RPC().ServerRPC().CountAllEnabledServersWithHTTPFirewallPolicyId(this.AdminContext(), &pb.CountAllEnabledServersWithHTTPFirewallPolicyIdRequest{FirewallPolicyId: params.FirewallPolicyId}) + countResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClustersWithHTTPFirewallPolicyId(this.AdminContext(), &pb.CountAllEnabledNodeClustersWithHTTPFirewallPolicyIdRequest{HttpFirewallPolicyId: params.FirewallPolicyId}) if err != nil { this.ErrorPage(err) return } if countResp.Count > 0 { - this.Fail("此WAF策略正在被有些服务引用,请修改后再删除。") + this.Fail("此WAF策略正在被有些集群引用,请修改后再删除。") } - _, err = this.RPC().HTTPFirewallPolicyRPC().DeleteFirewallPolicy(this.AdminContext(), &pb.DeleteFirewallPolicyRequest{FirewallPolicyId: params.FirewallPolicyId}) + _, err = this.RPC().HTTPFirewallPolicyRPC().DeleteHTTPFirewallPolicy(this.AdminContext(), &pb.DeleteHTTPFirewallPolicyRequest{HttpFirewallPolicyId: params.FirewallPolicyId}) if err != nil { this.ErrorPage(err) return } - - this.Success() } diff --git a/internal/web/actions/default/servers/components/waf/deleteGroup.go b/internal/web/actions/default/servers/components/waf/deleteGroup.go index 88fdb9f8..a35d1fe1 100644 --- a/internal/web/actions/default/servers/components/waf/deleteGroup.go +++ b/internal/web/actions/default/servers/components/waf/deleteGroup.go @@ -43,9 +43,9 @@ func (this *DeleteGroupAction) RunPost(params struct { } _, err = this.RPC().HTTPFirewallPolicyRPC().UpdateHTTPFirewallPolicyGroups(this.AdminContext(), &pb.UpdateHTTPFirewallPolicyGroupsRequest{ - FirewallPolicyId: params.FirewallPolicyId, - InboundJSON: inboundJSON, - OutboundJSON: outboundJSON, + HttpFirewallPolicyId: params.FirewallPolicyId, + InboundJSON: inboundJSON, + OutboundJSON: outboundJSON, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/servers/components/waf/helper.go b/internal/web/actions/default/servers/components/waf/helper.go index 5aadff4f..f673be39 100644 --- a/internal/web/actions/default/servers/components/waf/helper.go +++ b/internal/web/actions/default/servers/components/waf/helper.go @@ -33,7 +33,7 @@ func (this *Helper) BeforeAction(actionPtr actions.ActionWrapper) (goNext bool) action.Data["countOutboundGroups"] = 0 parentAction := actionutils.FindParentAction(actionPtr) if parentAction != nil { - firewallPolicy, err := models.SharedHTTPFirewallPolicyDAO.FindEnabledPolicy(parentAction.AdminContext(), firewallPolicyId) + firewallPolicy, err := models.SharedHTTPFirewallPolicyDAO.FindEnabledHTTPFirewallPolicy(parentAction.AdminContext(), firewallPolicyId) if err != nil { parentAction.ErrorPage(err) return diff --git a/internal/web/actions/default/servers/components/waf/import.go b/internal/web/actions/default/servers/components/waf/import.go index 33cbe5b5..d2bc5aca 100644 --- a/internal/web/actions/default/servers/components/waf/import.go +++ b/internal/web/actions/default/servers/components/waf/import.go @@ -48,8 +48,8 @@ func (this *ImportAction) RunPost(params struct { } _, err = this.RPC().HTTPFirewallPolicyRPC().ImportHTTPFirewallPolicy(this.AdminContext(), &pb.ImportHTTPFirewallPolicyRequest{ - FirewallPolicyId: params.FirewallPolicyId, - FirewallPolicyJSON: data, + HttpFirewallPolicyId: params.FirewallPolicyId, + HttpFirewallPolicyJSON: data, }) if err != nil { this.Fail("导入失败:" + err.Error()) diff --git a/internal/web/actions/default/servers/components/waf/index.go b/internal/web/actions/default/servers/components/waf/index.go index 1243d1f5..58572781 100644 --- a/internal/web/actions/default/servers/components/waf/index.go +++ b/internal/web/actions/default/servers/components/waf/index.go @@ -17,7 +17,7 @@ func (this *IndexAction) Init() { } func (this *IndexAction) RunGet(params struct{}) { - countResp, err := this.RPC().HTTPFirewallPolicyRPC().CountAllEnabledFirewallPolicies(this.AdminContext(), &pb.CountAllEnabledFirewallPoliciesRequest{}) + countResp, err := this.RPC().HTTPFirewallPolicyRPC().CountAllEnabledHTTPFirewallPolicies(this.AdminContext(), &pb.CountAllEnabledHTTPFirewallPoliciesRequest{}) if err != nil { this.ErrorPage(err) return @@ -25,7 +25,7 @@ func (this *IndexAction) RunGet(params struct{}) { count := countResp.Count page := this.NewPage(count) - listResp, err := this.RPC().HTTPFirewallPolicyRPC().ListEnabledFirewallPolicies(this.AdminContext(), &pb.ListEnabledFirewallPoliciesRequest{ + listResp, err := this.RPC().HTTPFirewallPolicyRPC().ListEnabledHTTPFirewallPolicies(this.AdminContext(), &pb.ListEnabledHTTPFirewallPoliciesRequest{ Offset: page.Offset, Size: page.Size, }) @@ -34,7 +34,7 @@ func (this *IndexAction) RunGet(params struct{}) { return } policyMaps := []maps.Map{} - for _, policy := range listResp.FirewallPolicies { + for _, policy := range listResp.HttpFirewallPolicies { countInbound := 0 countOutbound := 0 if len(policy.InboundJSON) > 0 { @@ -56,12 +56,12 @@ func (this *IndexAction) RunGet(params struct{}) { countOutbound = len(outboundConfig.GroupRefs) } - countServersResp, err := this.RPC().ServerRPC().CountAllEnabledServersWithHTTPFirewallPolicyId(this.AdminContext(), &pb.CountAllEnabledServersWithHTTPFirewallPolicyIdRequest{FirewallPolicyId: policy.Id}) + countClustersResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClustersWithHTTPFirewallPolicyId(this.AdminContext(), &pb.CountAllEnabledNodeClustersWithHTTPFirewallPolicyIdRequest{HttpFirewallPolicyId: policy.Id}) if err != nil { this.ErrorPage(err) return } - countServers := countServersResp.Count + countClusters := countClustersResp.Count policyMaps = append(policyMaps, maps.Map{ "id": policy.Id, @@ -69,7 +69,7 @@ func (this *IndexAction) RunGet(params struct{}) { "name": policy.Name, "countInbound": countInbound, "countOutbound": countOutbound, - "countServers": countServers, + "countClusters": countClusters, }) } diff --git a/internal/web/actions/default/servers/components/waf/init.go b/internal/web/actions/default/servers/components/waf/init.go index bc2bc8b9..08d435d9 100644 --- a/internal/web/actions/default/servers/components/waf/init.go +++ b/internal/web/actions/default/servers/components/waf/init.go @@ -38,6 +38,8 @@ func init() { Post("/updateSetOn", new(UpdateSetOnAction)). Post("/deleteSet", new(DeleteSetAction)). GetPost("/updateSetPopup", new(UpdateSetPopupAction)). + Post("/count", new(CountAction)). + Get("/selectPopup", new(SelectPopupAction)). // IP管理 GetPost("/ipadmin", new(ipadmin.IndexAction)). diff --git a/internal/web/actions/default/servers/components/waf/ipadmin/index.go b/internal/web/actions/default/servers/components/waf/ipadmin/index.go index 5a7cee29..3f7f99d6 100644 --- a/internal/web/actions/default/servers/components/waf/ipadmin/index.go +++ b/internal/web/actions/default/servers/components/waf/ipadmin/index.go @@ -96,8 +96,8 @@ func (this *IndexAction) RunPost(params struct { } _, err = this.RPC().HTTPFirewallPolicyRPC().UpdateHTTPFirewallInboundConfig(this.AdminContext(), &pb.UpdateHTTPFirewallInboundConfigRequest{ - FirewallPolicyId: params.FirewallPolicyId, - InboundJSON: inboundJSON, + HttpFirewallPolicyId: params.FirewallPolicyId, + InboundJSON: inboundJSON, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/servers/components/waf/ipadmin/ipadminutils/utils.go b/internal/web/actions/default/servers/components/waf/ipadmin/ipadminutils/utils.go index 1f842055..a8d07dd1 100644 --- a/internal/web/actions/default/servers/components/waf/ipadmin/ipadminutils/utils.go +++ b/internal/web/actions/default/servers/components/waf/ipadmin/ipadminutils/utils.go @@ -6,7 +6,6 @@ import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/nodeutils" "github.com/TeaOSLab/EdgeCommon/pkg/messageconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" - "github.com/iwind/TeaGo/lists" ) // 通知使用此WAF策略的集群更新 @@ -15,18 +14,12 @@ func NotifyUpdateToClustersWithFirewallPolicyId(ctx context.Context, firewallPol if err != nil { return err } - resp, err := client.ServerRPC().FindAllEnabledServersWithHTTPFirewallPolicyId(ctx, &pb.FindAllEnabledServersWithHTTPFirewallPolicyIdRequest{FirewallPolicyId: firewallPolicyId}) + resp, err := client.NodeClusterRPC().FindAllEnabledNodeClustersWithHTTPFirewallPolicyId(ctx, &pb.FindAllEnabledNodeClustersWithHTTPFirewallPolicyIdRequest{HttpFirewallPolicyId: firewallPolicyId}) if err != nil { return err } - clusterIds := []int64{} - for _, server := range resp.Servers { - if !lists.ContainsInt64(clusterIds, server.Cluster.Id) { - clusterIds = append(clusterIds, server.Cluster.Id) - } - } - for _, clusterId := range clusterIds { - _, err = nodeutils.SendMessageToCluster(ctx, clusterId, messageconfigs.MessageCodeIPListChanged, &messageconfigs.IPListChangedMessage{}, 3) + for _, cluster := range resp.NodeClusters { + _, err = nodeutils.SendMessageToCluster(ctx, cluster.Id, messageconfigs.MessageCodeIPListChanged, &messageconfigs.IPListChangedMessage{}, 3) if err != nil { return err } diff --git a/internal/web/actions/default/servers/components/waf/ipadmin/provinces.go b/internal/web/actions/default/servers/components/waf/ipadmin/provinces.go index f957aeb8..355e767a 100644 --- a/internal/web/actions/default/servers/components/waf/ipadmin/provinces.go +++ b/internal/web/actions/default/servers/components/waf/ipadmin/provinces.go @@ -98,8 +98,8 @@ func (this *ProvincesAction) RunPost(params struct { } _, err = this.RPC().HTTPFirewallPolicyRPC().UpdateHTTPFirewallInboundConfig(this.AdminContext(), &pb.UpdateHTTPFirewallInboundConfigRequest{ - FirewallPolicyId: params.FirewallPolicyId, - InboundJSON: inboundJSON, + HttpFirewallPolicyId: params.FirewallPolicyId, + InboundJSON: inboundJSON, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/servers/components/waf/log.go b/internal/web/actions/default/servers/components/waf/log.go index 09be53fc..866824f9 100644 --- a/internal/web/actions/default/servers/components/waf/log.go +++ b/internal/web/actions/default/servers/components/waf/log.go @@ -83,15 +83,15 @@ func (this *LogAction) RunGet(params struct { } // 所有分组 - policyResp, err := this.RPC().HTTPFirewallPolicyRPC().FindEnabledFirewallPolicyConfig(this.AdminContext(), &pb.FindEnabledFirewallPolicyConfigRequest{ - FirewallPolicyId: params.FirewallPolicyId, + policyResp, err := this.RPC().HTTPFirewallPolicyRPC().FindEnabledHTTPFirewallPolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPFirewallPolicyConfigRequest{ + HttpFirewallPolicyId: params.FirewallPolicyId, }) if err != nil { this.ErrorPage(err) return } policyConfig := &firewallconfigs.HTTPFirewallPolicy{} - err = json.Unmarshal(policyResp.FirewallPolicyJSON, policyConfig) + err = json.Unmarshal(policyResp.HttpFirewallPolicyJSON, policyConfig) if err != nil { this.ErrorPage(err) return diff --git a/internal/web/actions/default/servers/components/waf/policy.go b/internal/web/actions/default/servers/components/waf/policy.go index 16719e6e..4ea9ed11 100644 --- a/internal/web/actions/default/servers/components/waf/policy.go +++ b/internal/web/actions/default/servers/components/waf/policy.go @@ -55,20 +55,20 @@ func (this *PolicyAction) RunGet(params struct { "blockOptions": firewallPolicy.BlockOptions, } - // 正在使用此策略的服务 - listServersResp, err := this.RPC().ServerRPC().FindAllEnabledServersWithHTTPFirewallPolicyId(this.AdminContext(), &pb.FindAllEnabledServersWithHTTPFirewallPolicyIdRequest{FirewallPolicyId: params.FirewallPolicyId}) + // 正在使用此策略的集群 + clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClustersWithHTTPFirewallPolicyId(this.AdminContext(), &pb.FindAllEnabledNodeClustersWithHTTPFirewallPolicyIdRequest{HttpFirewallPolicyId: params.FirewallPolicyId}) if err != nil { this.ErrorPage(err) return } - serverMaps := []maps.Map{} - for _, server := range listServersResp.Servers { - serverMaps = append(serverMaps, maps.Map{ - "id": server.Id, - "name": server.Name, + clusterMaps := []maps.Map{} + for _, cluster := range clustersResp.NodeClusters { + clusterMaps = append(clusterMaps, maps.Map{ + "id": cluster.Id, + "name": cluster.Name, }) } - this.Data["servers"] = serverMaps + this.Data["clusters"] = clusterMaps this.Show() } diff --git a/internal/web/actions/default/servers/components/waf/selectPopup.go b/internal/web/actions/default/servers/components/waf/selectPopup.go new file mode 100644 index 00000000..6c44ea88 --- /dev/null +++ b/internal/web/actions/default/servers/components/waf/selectPopup.go @@ -0,0 +1,73 @@ +package waf + +import ( + "encoding/json" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs" + "github.com/iwind/TeaGo/maps" +) + +type SelectPopupAction struct { + actionutils.ParentAction +} + +func (this *SelectPopupAction) Init() { + this.FirstMenu("index") +} + +func (this *SelectPopupAction) RunGet(params struct{}) { + countResp, err := this.RPC().HTTPFirewallPolicyRPC().CountAllEnabledHTTPFirewallPolicies(this.AdminContext(), &pb.CountAllEnabledHTTPFirewallPoliciesRequest{}) + if err != nil { + this.ErrorPage(err) + return + } + count := countResp.Count + page := this.NewPage(count) + + listResp, err := this.RPC().HTTPFirewallPolicyRPC().ListEnabledHTTPFirewallPolicies(this.AdminContext(), &pb.ListEnabledHTTPFirewallPoliciesRequest{ + Offset: page.Offset, + Size: page.Size, + }) + if err != nil { + this.ErrorPage(err) + return + } + policyMaps := []maps.Map{} + for _, policy := range listResp.HttpFirewallPolicies { + countInbound := 0 + countOutbound := 0 + if len(policy.InboundJSON) > 0 { + inboundConfig := &firewallconfigs.HTTPFirewallInboundConfig{} + err = json.Unmarshal(policy.InboundJSON, inboundConfig) + if err != nil { + this.ErrorPage(err) + return + } + countInbound = len(inboundConfig.GroupRefs) + } + if len(policy.OutboundJSON) > 0 { + outboundConfig := &firewallconfigs.HTTPFirewallInboundConfig{} + err = json.Unmarshal(policy.OutboundJSON, outboundConfig) + if err != nil { + this.ErrorPage(err) + return + } + countOutbound = len(outboundConfig.GroupRefs) + } + + policyMaps = append(policyMaps, maps.Map{ + "id": policy.Id, + "isOn": policy.IsOn, + "name": policy.Name, + "countInbound": countInbound, + "countOutbound": countOutbound, + }) + } + + this.Data["policies"] = policyMaps + + this.Data["page"] = page.AsHTML() + + this.Show() +} diff --git a/internal/web/actions/default/servers/components/waf/sortGroups.go b/internal/web/actions/default/servers/components/waf/sortGroups.go index 86c5f654..2d917650 100644 --- a/internal/web/actions/default/servers/components/waf/sortGroups.go +++ b/internal/web/actions/default/servers/components/waf/sortGroups.go @@ -73,9 +73,9 @@ func (this *SortGroupsAction) RunPost(params struct { } _, err = this.RPC().HTTPFirewallPolicyRPC().UpdateHTTPFirewallPolicyGroups(this.AdminContext(), &pb.UpdateHTTPFirewallPolicyGroupsRequest{ - FirewallPolicyId: params.FirewallPolicyId, - InboundJSON: inboundJSON, - OutboundJSON: outboundJSON, + HttpFirewallPolicyId: params.FirewallPolicyId, + InboundJSON: inboundJSON, + OutboundJSON: outboundJSON, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/servers/components/waf/update.go b/internal/web/actions/default/servers/components/waf/update.go index 9ec0f06f..7e619c76 100644 --- a/internal/web/actions/default/servers/components/waf/update.go +++ b/internal/web/actions/default/servers/components/waf/update.go @@ -88,12 +88,12 @@ func (this *UpdateAction) RunPost(params struct { Require("请输入策略名称") _, err := this.RPC().HTTPFirewallPolicyRPC().UpdateHTTPFirewallPolicy(this.AdminContext(), &pb.UpdateHTTPFirewallPolicyRequest{ - FirewallPolicyId: params.FirewallPolicyId, - IsOn: params.IsOn, - Name: params.Name, - Description: params.Description, - FirewallGroupCodes: params.GroupCodes, - BlockOptionsJSON: params.BlockOptionsJSON, + HttpFirewallPolicyId: params.FirewallPolicyId, + IsOn: params.IsOn, + Name: params.Name, + Description: params.Description, + FirewallGroupCodes: params.GroupCodes, + BlockOptionsJSON: params.BlockOptionsJSON, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/servers/create.go b/internal/web/actions/default/servers/create.go index f8e4c8f3..dfa889a0 100644 --- a/internal/web/actions/default/servers/create.go +++ b/internal/web/actions/default/servers/create.go @@ -256,7 +256,7 @@ func (this *CreateAction) RunPost(params struct { Name: params.Name, ServerNamesJON: []byte(params.ServerNames), Description: params.Description, - ClusterId: params.ClusterId, + NodeClusterId: params.ClusterId, IncludeNodesJSON: includeNodesJSON, ExcludeNodesJSON: excludeNodesJSON, WebId: webId, diff --git a/internal/web/actions/default/servers/server/log/viewPopup.go b/internal/web/actions/default/servers/server/log/viewPopup.go index 61073d96..714b22dc 100644 --- a/internal/web/actions/default/servers/server/log/viewPopup.go +++ b/internal/web/actions/default/servers/server/log/viewPopup.go @@ -40,16 +40,16 @@ func (this *ViewPopupAction) RunGet(params struct { // WAF相关 var wafMap maps.Map = nil if accessLog.FirewallPolicyId > 0 { - policyResp, err := this.RPC().HTTPFirewallPolicyRPC().FindEnabledFirewallPolicy(this.AdminContext(), &pb.FindEnabledFirewallPolicyRequest{FirewallPolicyId: accessLog.FirewallPolicyId}) + policyResp, err := this.RPC().HTTPFirewallPolicyRPC().FindEnabledHTTPFirewallPolicy(this.AdminContext(), &pb.FindEnabledHTTPFirewallPolicyRequest{HttpFirewallPolicyId: accessLog.FirewallPolicyId}) if err != nil { this.ErrorPage(err) return } - if policyResp.FirewallPolicy != nil { + if policyResp.HttpFirewallPolicy != nil { wafMap = maps.Map{ "policy": maps.Map{ - "id": policyResp.FirewallPolicy.Id, - "name": policyResp.FirewallPolicy.Name, + "id": policyResp.HttpFirewallPolicy.Id, + "name": policyResp.HttpFirewallPolicy.Name, }, } if accessLog.FirewallRuleGroupId > 0 { diff --git a/internal/web/actions/default/servers/server/settings/cache/createPopup.go b/internal/web/actions/default/servers/server/settings/cache/createPopup.go index 83333494..1ede0d45 100644 --- a/internal/web/actions/default/servers/server/settings/cache/createPopup.go +++ b/internal/web/actions/default/servers/server/settings/cache/createPopup.go @@ -3,11 +3,8 @@ package cache import ( "encoding/json" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeAdmin/internal/web/models" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/iwind/TeaGo/actions" - "github.com/iwind/TeaGo/maps" ) type CreatePopupAction struct { @@ -19,45 +16,16 @@ func (this *CreatePopupAction) Init() { } func (this *CreatePopupAction) RunGet(params struct{}) { - // 缓存策略列表 - cachePoliciesResp, err := this.RPC().HTTPCachePolicyRPC().FindAllEnabledHTTPCachePolicies(this.AdminContext(), &pb.FindAllEnabledHTTPCachePoliciesRequest{}) - if err != nil { - this.ErrorPage(err) - return - } - cachePolicyMaps := []maps.Map{} - for _, cachePolicy := range cachePoliciesResp.CachePolicies { - cachePolicyMaps = append(cachePolicyMaps, maps.Map{ - "id": cachePolicy.Id, - "name": cachePolicy.Name, - }) - } - this.Data["cachePolicies"] = cachePolicyMaps - this.Show() } func (this *CreatePopupAction) RunPost(params struct { - CachePolicyId int64 - CacheRefJSON []byte + CacheRefJSON []byte Must *actions.Must }) { - if params.CachePolicyId <= 0 { - this.Fail("请选择要使用的缓存策略") - } - - cachePolicy, err := models.SharedHTTPCachePolicyDAO.FindEnabledCachePolicyConfig(this.AdminContext(), params.CachePolicyId) - if err != nil { - this.ErrorPage(err) - return - } - if cachePolicy == nil { - this.Fail("找不到你要使用的缓存策略") - } - cacheRef := &serverconfigs.HTTPCacheRef{} - err = json.Unmarshal(params.CacheRefJSON, cacheRef) + err := json.Unmarshal(params.CacheRefJSON, cacheRef) if err != nil { this.ErrorPage(err) return @@ -66,9 +34,6 @@ func (this *CreatePopupAction) RunPost(params struct { this.Fail("请输入缓存Key") } - cacheRef.CachePolicyId = cachePolicy.Id - cacheRef.CachePolicy = cachePolicy - err = cacheRef.Init() if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/servers/server/settings/cache/index.go b/internal/web/actions/default/servers/server/settings/cache/index.go index d7df9d9a..69764a5b 100644 --- a/internal/web/actions/default/servers/server/settings/cache/index.go +++ b/internal/web/actions/default/servers/server/settings/cache/index.go @@ -5,9 +5,11 @@ import ( "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/webutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/models" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/maps" ) type IndexAction struct { @@ -31,6 +33,22 @@ func (this *IndexAction) RunGet(params struct { this.Data["webId"] = webConfig.Id this.Data["cacheConfig"] = webConfig.Cache + // 当前集群的缓存策略 + cachePolicy, err := models.SharedHTTPCachePolicyDAO.FindEnabledHTTPCachePolicyWithServerId(this.AdminContext(), params.ServerId) + if err != nil { + this.ErrorPage(err) + return + } + if cachePolicy != nil { + this.Data["cachePolicy"] = maps.Map{ + "id": cachePolicy.Id, + "name": cachePolicy.Name, + "isOn": cachePolicy.IsOn, + } + } else { + this.Data["cachePolicy"] = nil + } + this.Show() } diff --git a/internal/web/actions/default/servers/server/settings/index.go b/internal/web/actions/default/servers/server/settings/index.go index 9ea603cd..93ecf1b6 100644 --- a/internal/web/actions/default/servers/server/settings/index.go +++ b/internal/web/actions/default/servers/server/settings/index.go @@ -114,12 +114,12 @@ func (this *IndexAction) RunPost(params struct { } _, err := this.RPC().ServerRPC().UpdateServerBasic(this.AdminContext(), &pb.UpdateServerBasicRequest{ - ServerId: params.ServerId, - Name: params.Name, - Description: params.Description, - ClusterId: params.ClusterId, - IsOn: params.IsOn, - GroupIds: params.GroupIds, + ServerId: params.ServerId, + Name: params.Name, + Description: params.Description, + NodeClusterId: params.ClusterId, + IsOn: params.IsOn, + GroupIds: params.GroupIds, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/servers/server/settings/locations/cache/index.go b/internal/web/actions/default/servers/server/settings/locations/cache/index.go index f3cb7a16..c5c833bf 100644 --- a/internal/web/actions/default/servers/server/settings/locations/cache/index.go +++ b/internal/web/actions/default/servers/server/settings/locations/cache/index.go @@ -4,9 +4,11 @@ import ( "encoding/json" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/webutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/models" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/maps" ) type IndexAction struct { @@ -17,6 +19,7 @@ func (this *IndexAction) Init() { } func (this *IndexAction) RunGet(params struct { + ServerId int64 LocationId int64 }) { webConfig, err := webutils.FindWebConfigWithLocationId(this.Parent(), params.LocationId) @@ -28,6 +31,22 @@ func (this *IndexAction) RunGet(params struct { this.Data["webId"] = webConfig.Id this.Data["cacheConfig"] = webConfig.Cache + // 当前集群的缓存策略 + cachePolicy, err := models.SharedHTTPCachePolicyDAO.FindEnabledHTTPCachePolicyWithServerId(this.AdminContext(), params.ServerId) + if err != nil { + this.ErrorPage(err) + return + } + if cachePolicy != nil { + this.Data["cachePolicy"] = maps.Map{ + "id": cachePolicy.Id, + "name": cachePolicy.Name, + "isOn": cachePolicy.IsOn, + } + } else { + this.Data["cachePolicy"] = nil + } + this.Show() } diff --git a/internal/web/actions/default/servers/server/settings/locations/waf/index.go b/internal/web/actions/default/servers/server/settings/locations/waf/index.go index cf6bcef7..09207691 100644 --- a/internal/web/actions/default/servers/server/settings/locations/waf/index.go +++ b/internal/web/actions/default/servers/server/settings/locations/waf/index.go @@ -3,6 +3,7 @@ package waf import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/webutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/models" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/maps" @@ -16,6 +17,7 @@ func (this *IndexAction) Init() { } func (this *IndexAction) RunGet(params struct { + ServerId int64 LocationId int64 }) { webConfig, err := webutils.FindWebConfigWithLocationId(this.Parent(), params.LocationId) @@ -27,22 +29,21 @@ func (this *IndexAction) RunGet(params struct { this.Data["webId"] = webConfig.Id this.Data["firewallConfig"] = webConfig.FirewallRef - // 当前已有策略 - policiesResp, err := this.RPC().HTTPFirewallPolicyRPC().FindAllEnabledHTTPFirewallPolicies(this.AdminContext(), &pb.FindAllEnabledHTTPFirewallPoliciesRequest{}) + // 获取当前服务所在集群的WAF设置 + firewallPolicy, err := models.SharedHTTPFirewallPolicyDAO.FindEnabledHTTPFirewallPolicyWithServerId(this.AdminContext(), params.ServerId) if err != nil { this.ErrorPage(err) return } - policyMaps := []maps.Map{} - for _, p := range policiesResp.FirewallPolicies { - policyMaps = append(policyMaps, maps.Map{ - "id": p.Id, - "name": p.Name, - "isOn": p.IsOn, - "description": p.Description, - }) + if firewallPolicy != nil { + this.Data["firewallPolicy"] = maps.Map{ + "id": firewallPolicy.Id, + "name": firewallPolicy.Name, + "isOn": firewallPolicy.IsOn, + } + } else { + this.Data["firewallPolicy"] = nil } - this.Data["firewallPolicies"] = policyMaps this.Show() } diff --git a/internal/web/actions/default/servers/server/settings/waf/index.go b/internal/web/actions/default/servers/server/settings/waf/index.go index 4802cb1c..cd5f692c 100644 --- a/internal/web/actions/default/servers/server/settings/waf/index.go +++ b/internal/web/actions/default/servers/server/settings/waf/index.go @@ -3,6 +3,7 @@ package waf import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/webutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/models" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/maps" @@ -29,22 +30,21 @@ func (this *IndexAction) RunGet(params struct { this.Data["webId"] = webConfig.Id this.Data["firewallConfig"] = webConfig.FirewallRef - // 当前已有策略 - policiesResp, err := this.RPC().HTTPFirewallPolicyRPC().FindAllEnabledHTTPFirewallPolicies(this.AdminContext(), &pb.FindAllEnabledHTTPFirewallPoliciesRequest{}) + // 获取当前服务所在集群的WAF设置 + firewallPolicy, err := models.SharedHTTPFirewallPolicyDAO.FindEnabledHTTPFirewallPolicyWithServerId(this.AdminContext(), params.ServerId) if err != nil { this.ErrorPage(err) return } - policyMaps := []maps.Map{} - for _, p := range policiesResp.FirewallPolicies { - policyMaps = append(policyMaps, maps.Map{ - "id": p.Id, - "name": p.Name, - "isOn": p.IsOn, - "description": p.Description, - }) + if firewallPolicy != nil { + this.Data["firewallPolicy"] = maps.Map{ + "id": firewallPolicy.Id, + "name": firewallPolicy.Name, + "isOn": firewallPolicy.IsOn, + } + } else { + this.Data["firewallPolicy"] = nil } - this.Data["firewallPolicies"] = policyMaps this.Show() } diff --git a/internal/web/actions/default/users/createPopup.go b/internal/web/actions/default/users/createPopup.go index cad2c73d..0bf7a750 100644 --- a/internal/web/actions/default/users/createPopup.go +++ b/internal/web/actions/default/users/createPopup.go @@ -77,15 +77,15 @@ func (this *CreatePopupAction) RunPost(params struct { } createResp, err := this.RPC().UserRPC().CreateUser(this.AdminContext(), &pb.CreateUserRequest{ - Username: params.Username, - Password: params.Pass1, - Fullname: params.Fullname, - Mobile: params.Mobile, - Tel: params.Tel, - Email: params.Email, - Remark: params.Remark, - Source: "admin:" + numberutils.FormatInt64(this.AdminId()), - ClusterId: params.ClusterId, + Username: params.Username, + Password: params.Pass1, + Fullname: params.Fullname, + Mobile: params.Mobile, + Tel: params.Tel, + Email: params.Email, + Remark: params.Remark, + Source: "admin:" + numberutils.FormatInt64(this.AdminId()), + NodeClusterId: params.ClusterId, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/users/update.go b/internal/web/actions/default/users/update.go index 59a91fb3..ae3a589b 100644 --- a/internal/web/actions/default/users/update.go +++ b/internal/web/actions/default/users/update.go @@ -115,16 +115,16 @@ func (this *UpdateAction) RunPost(params struct { } _, err = this.RPC().UserRPC().UpdateUser(this.AdminContext(), &pb.UpdateUserRequest{ - UserId: params.UserId, - Username: params.Username, - Password: params.Pass1, - Fullname: params.Fullname, - Mobile: params.Mobile, - Tel: params.Tel, - Email: params.Email, - Remark: params.Remark, - IsOn: params.IsOn, - ClusterId: params.ClusterId, + UserId: params.UserId, + Username: params.Username, + Password: params.Pass1, + Fullname: params.Fullname, + Mobile: params.Mobile, + Tel: params.Tel, + Email: params.Email, + Remark: params.Remark, + IsOn: params.IsOn, + NodeClusterId: params.ClusterId, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/models/base_dao.go b/internal/web/models/base_dao.go new file mode 100644 index 00000000..209a9746 --- /dev/null +++ b/internal/web/models/base_dao.go @@ -0,0 +1,18 @@ +package models + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/rpc" + "github.com/iwind/TeaGo/logs" +) + +type BaseDAO struct { +} + +func (this *BaseDAO) RPC() *rpc.RPCClient { + client, err := rpc.SharedRPC() + if err != nil { + logs.Println("[MODEL]get shared rpc client failed: " + err.Error()) + return nil + } + return client +} diff --git a/internal/web/models/http_cache_policy_dao.go b/internal/web/models/http_cache_policy_dao.go index b2263409..5a2d8138 100644 --- a/internal/web/models/http_cache_policy_dao.go +++ b/internal/web/models/http_cache_policy_dao.go @@ -3,7 +3,6 @@ package models import ( "context" "encoding/json" - "github.com/TeaOSLab/EdgeAdmin/internal/rpc" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" ) @@ -11,25 +10,60 @@ import ( var SharedHTTPCachePolicyDAO = new(HTTPCachePolicyDAO) type HTTPCachePolicyDAO struct { + BaseDAO } // 查找缓存策略配置 -func (this *HTTPCachePolicyDAO) FindEnabledCachePolicyConfig(ctx context.Context, cachePolicyId int64) (*serverconfigs.HTTPCachePolicy, error) { - rpcClient, err := rpc.SharedRPC() +func (this *HTTPCachePolicyDAO) FindEnabledHTTPCachePolicyConfig(ctx context.Context, cachePolicyId int64) (*serverconfigs.HTTPCachePolicy, error) { + resp, err := this.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(ctx, &pb.FindEnabledHTTPCachePolicyConfigRequest{HttpCachePolicyId: cachePolicyId}) if err != nil { return nil, err } - resp, err := rpcClient.HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(ctx, &pb.FindEnabledHTTPCachePolicyConfigRequest{CachePolicyId: cachePolicyId}) - if err != nil { - return nil, err - } - if len(resp.CachePolicyJSON) == 0 { + if len(resp.HttpCachePolicyJSON) == 0 { return nil, nil } config := &serverconfigs.HTTPCachePolicy{} - err = json.Unmarshal(resp.CachePolicyJSON, config) + err = json.Unmarshal(resp.HttpCachePolicyJSON, config) if err != nil { return nil, err } return config, nil } + +// 查找缓存策略信息 +func (this *HTTPCachePolicyDAO) FindEnabledHTTPCachePolicy(ctx context.Context, cachePolicyId int64) (*pb.HTTPCachePolicy, error) { + resp, err := this.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicy(ctx, &pb.FindEnabledHTTPCachePolicyRequest{ + HttpCachePolicyId: cachePolicyId, + }) + if err != nil { + return nil, err + } + return resp.HttpCachePolicy, nil +} + +// 根据服务ID查找缓存策略 +func (this *HTTPCachePolicyDAO) FindEnabledHTTPCachePolicyWithServerId(ctx context.Context, serverId int64) (*pb.HTTPCachePolicy, error) { + serverResp, err := this.RPC().ServerRPC().FindEnabledServer(ctx, &pb.FindEnabledServerRequest{ServerId: serverId}) + if err != nil { + return nil, err + } + server := serverResp.Server + if server == nil { + return nil, nil + } + if server.Cluster == nil { + return nil, nil + } + clusterId := server.Cluster.Id + cluster, err := SharedNodeClusterDAO.FindEnabledNodeCluster(ctx, clusterId) + if err != nil { + return nil, err + } + if cluster == nil { + return nil, nil + } + if cluster.HttpCachePolicyId == 0 { + return nil, nil + } + return SharedHTTPCachePolicyDAO.FindEnabledHTTPCachePolicy(ctx, cluster.HttpCachePolicyId) +} diff --git a/internal/web/models/http_firewall_policy_dao.go b/internal/web/models/http_firewall_policy_dao.go index ec6ff02c..530ccf80 100644 --- a/internal/web/models/http_firewall_policy_dao.go +++ b/internal/web/models/http_firewall_policy_dao.go @@ -14,36 +14,20 @@ var SharedHTTPFirewallPolicyDAO = new(HTTPFirewallPolicyDAO) // WAF策略相关 type HTTPFirewallPolicyDAO struct { -} - -// 查找WAF策略基本信息 -func (this *HTTPFirewallPolicyDAO) FindEnabledPolicy(ctx context.Context, policyId int64) (*pb.HTTPFirewallPolicy, error) { - client, err := rpc.SharedRPC() - if err != nil { - return nil, err - } - resp, err := client.HTTPFirewallPolicyRPC().FindEnabledFirewallPolicy(ctx, &pb.FindEnabledFirewallPolicyRequest{FirewallPolicyId: policyId}) - if err != nil { - return nil, err - } - return resp.FirewallPolicy, nil + BaseDAO } // 查找WAF策略配置 func (this *HTTPFirewallPolicyDAO) FindEnabledPolicyConfig(ctx context.Context, policyId int64) (*firewallconfigs.HTTPFirewallPolicy, error) { - client, err := rpc.SharedRPC() + resp, err := this.RPC().HTTPFirewallPolicyRPC().FindEnabledHTTPFirewallPolicyConfig(ctx, &pb.FindEnabledHTTPFirewallPolicyConfigRequest{HttpFirewallPolicyId: policyId}) if err != nil { return nil, err } - resp, err := client.HTTPFirewallPolicyRPC().FindEnabledFirewallPolicyConfig(ctx, &pb.FindEnabledFirewallPolicyConfigRequest{FirewallPolicyId: policyId}) - if err != nil { - return nil, err - } - if len(resp.FirewallPolicyJSON) == 0 { + if len(resp.HttpFirewallPolicyJSON) == 0 { return nil, nil } firewallPolicy := &firewallconfigs.HTTPFirewallPolicy{} - err = json.Unmarshal(resp.FirewallPolicyJSON, firewallPolicy) + err = json.Unmarshal(resp.HttpFirewallPolicyJSON, firewallPolicy) if err != nil { return nil, err } @@ -111,8 +95,8 @@ func (this *HTTPFirewallPolicyDAO) FindEnabledPolicyWhiteIPListId(ctx context.Co return 0, err } _, err = client.HTTPFirewallPolicyRPC().UpdateHTTPFirewallInboundConfig(ctx, &pb.UpdateHTTPFirewallInboundConfigRequest{ - FirewallPolicyId: policyId, - InboundJSON: inboundJSON, + HttpFirewallPolicyId: policyId, + InboundJSON: inboundJSON, }) if err != nil { return 0, err @@ -125,11 +109,6 @@ func (this *HTTPFirewallPolicyDAO) FindEnabledPolicyWhiteIPListId(ctx context.Co // 查找WAF的黑名单 func (this *HTTPFirewallPolicyDAO) FindEnabledPolicyBlackIPListId(ctx context.Context, policyId int64) (int64, error) { - client, err := rpc.SharedRPC() - if err != nil { - return 0, err - } - config, err := this.FindEnabledPolicyConfig(ctx, policyId) if err != nil { return 0, err @@ -141,7 +120,7 @@ func (this *HTTPFirewallPolicyDAO) FindEnabledPolicyBlackIPListId(ctx context.Co config.Inbound = &firewallconfigs.HTTPFirewallInboundConfig{IsOn: true} } if config.Inbound.BlackListRef == nil || config.Inbound.BlackListRef.ListId == 0 { - createResp, err := client.IPListRPC().CreateIPList(ctx, &pb.CreateIPListRequest{ + createResp, err := this.RPC().IPListRPC().CreateIPList(ctx, &pb.CreateIPListRequest{ Type: "black", Name: "黑名单", Code: "black", @@ -159,9 +138,9 @@ func (this *HTTPFirewallPolicyDAO) FindEnabledPolicyBlackIPListId(ctx context.Co if err != nil { return 0, err } - _, err = client.HTTPFirewallPolicyRPC().UpdateHTTPFirewallInboundConfig(ctx, &pb.UpdateHTTPFirewallInboundConfigRequest{ - FirewallPolicyId: policyId, - InboundJSON: inboundJSON, + _, err = this.RPC().HTTPFirewallPolicyRPC().UpdateHTTPFirewallInboundConfig(ctx, &pb.UpdateHTTPFirewallInboundConfigRequest{ + HttpFirewallPolicyId: policyId, + InboundJSON: inboundJSON, }) if err != nil { return 0, err @@ -171,3 +150,41 @@ func (this *HTTPFirewallPolicyDAO) FindEnabledPolicyBlackIPListId(ctx context.Co return config.Inbound.BlackListRef.ListId, nil } + +// 查找WAF信息 +func (this *HTTPFirewallPolicyDAO) FindEnabledHTTPFirewallPolicy(ctx context.Context, firewallPolicyId int64) (*pb.HTTPFirewallPolicy, error) { + resp, err := this.RPC().HTTPFirewallPolicyRPC().FindEnabledHTTPFirewallPolicy(ctx, &pb.FindEnabledHTTPFirewallPolicyRequest{ + HttpFirewallPolicyId: firewallPolicyId, + }) + if err != nil { + return nil, err + } + return resp.HttpFirewallPolicy, nil +} + +// 根据服务Id查找WAF策略 +func (this *HTTPFirewallPolicyDAO) FindEnabledHTTPFirewallPolicyWithServerId(ctx context.Context, serverId int64) (*pb.HTTPFirewallPolicy, error) { + serverResp, err := this.RPC().ServerRPC().FindEnabledServer(ctx, &pb.FindEnabledServerRequest{ServerId: serverId}) + if err != nil { + return nil, err + } + server := serverResp.Server + if server == nil { + return nil, nil + } + if server.Cluster == nil { + return nil, nil + } + clusterId := server.Cluster.Id + cluster, err := SharedNodeClusterDAO.FindEnabledNodeCluster(ctx, clusterId) + if err != nil { + return nil, err + } + if cluster == nil { + return nil, nil + } + if cluster.HttpFirewallPolicyId == 0 { + return nil, nil + } + return SharedHTTPFirewallPolicyDAO.FindEnabledHTTPFirewallPolicy(ctx, cluster.HttpFirewallPolicyId) +} diff --git a/internal/web/models/node_cluster_dao.go b/internal/web/models/node_cluster_dao.go new file mode 100644 index 00000000..82c0fabf --- /dev/null +++ b/internal/web/models/node_cluster_dao.go @@ -0,0 +1,21 @@ +package models + +import ( + "context" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" +) + +var SharedNodeClusterDAO = new(NodeClusterDAO) + +type NodeClusterDAO struct { + BaseDAO +} + +// 查找集群 +func (this *NodeClusterDAO) FindEnabledNodeCluster(ctx context.Context, clusterId int64) (*pb.NodeCluster, error) { + clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(ctx, &pb.FindEnabledNodeClusterRequest{NodeClusterId: clusterId}) + if err != nil { + return nil, err + } + return clusterResp.Cluster, nil +} diff --git a/internal/web/models/server_dao.go b/internal/web/models/server_dao.go new file mode 100644 index 00000000..07dbfe91 --- /dev/null +++ b/internal/web/models/server_dao.go @@ -0,0 +1,7 @@ +package models + +var SharedServerDAO = new(ServerDAO) + +type ServerDAO struct { + BaseDAO +} diff --git a/web/public/js/components/server/http-cache-config-box.js b/web/public/js/components/server/http-cache-config-box.js index 263d72fb..de3250df 100644 --- a/web/public/js/components/server/http-cache-config-box.js +++ b/web/public/js/components/server/http-cache-config-box.js @@ -1,5 +1,5 @@ Vue.component("http-cache-config-box", { - props: ["v-cache-config", "v-cache-policies", "v-is-location"], + props: ["v-cache-config", "v-is-location", "v-cache-policy"], data: function () { let cacheConfig = this.vCacheConfig if (cacheConfig == null) { @@ -86,6 +86,15 @@ Vue.component("http-cache-config-box", { + + + + - + @@ -25,7 +25,7 @@ {{policy.capacity.count}}{{policy.capacity.unit.toUpperCase()}}不限 - + + + + + + + + + + + + + + + + + + + + + +
缓存策略 +
{{vCachePolicy.name}} +

使用当前服务所在集群的设置。

+
+ 当前集群没有设置缓存策略,当前配置无法生效。 +
是否开启缓存 @@ -102,13 +111,11 @@ Vue.component("http-cache-config-box", { - - diff --git a/web/public/js/components/server/http-cache-policy-selector.js b/web/public/js/components/server/http-cache-policy-selector.js new file mode 100644 index 00000000..053e9bc9 --- /dev/null +++ b/web/public/js/components/server/http-cache-policy-selector.js @@ -0,0 +1,49 @@ +Vue.component("http-cache-policy-selector", { + props: ["v-cache-policy"], + mounted: function () { + let that = this + Tea.action("/servers/components/cache/count") + .post() + .success(function (resp) { + that.count = resp.data.count + }) + }, + data: function () { + let cachePolicy = this.vCachePolicy + return { + count: 0, + cachePolicy: cachePolicy + } + }, + methods: { + remove: function () { + this.cachePolicy = null + }, + select: function () { + let that = this + teaweb.popup("/servers/components/cache/selectPopup", { + callback: function (resp) { + that.cachePolicy = resp.data.cachePolicy + } + }) + }, + create: function () { + let that = this + teaweb.popup("/servers/components/cache/createPopup", { + height: "26em", + callback: function (resp) { + that.cachePolicy = resp.data.cachePolicy + } + }) + } + }, + template: `
+
+ + {{cachePolicy.name}}     +
+ +
` +}) \ No newline at end of file diff --git a/web/public/js/components/server/http-cache-ref-box.js b/web/public/js/components/server/http-cache-ref-box.js index 2010c6c7..fa42e5cc 100644 --- a/web/public/js/components/server/http-cache-ref-box.js +++ b/web/public/js/components/server/http-cache-ref-box.js @@ -43,7 +43,7 @@ Vue.component("http-cache-ref-box", { }, template: ` - + + + + + + + + +
缓存策略 条件 缓存时间 操作
{{cacheRef.cachePolicy.name}}
匹配条件 *匹配条件 * diff --git a/web/public/js/components/server/http-firewall-config-box.js b/web/public/js/components/server/http-firewall-config-box.js index 4b1c1de2..3a3f7604 100644 --- a/web/public/js/components/server/http-firewall-config-box.js +++ b/web/public/js/components/server/http-firewall-config-box.js @@ -1,5 +1,5 @@ Vue.component("http-firewall-config-box", { - props: ["v-firewall-config", "v-firewall-policies", "v-is-location"], + props: ["v-firewall-config", "v-is-location", "v-firewall-policy"], data: function () { let firewall = this.vFirewallConfig if (firewall == null) { @@ -11,22 +11,7 @@ Vue.component("http-firewall-config-box", { } return { - firewall: firewall, - selectedPolicy: this.lookupPolicy(firewall.firewallPolicyId) - } - }, - methods: { - changePolicyId: function () { - this.firewall.firewallPolicyId = parseInt(this.firewall.firewallPolicyId) - this.selectedPolicy = this.lookupPolicy(this.firewall.firewallPolicyId) - }, - lookupPolicy: function (policyId) { - if (policyId <= 0) { - return null - } - return this.vFirewallPolicies.$find(function (k, v) { - return v.id == policyId - }) + firewall: firewall } }, template: `
@@ -34,6 +19,15 @@ Vue.component("http-firewall-config-box", { + + + + - - - - - -
WAF策略 +
{{vFirewallPolicy.name}} +

使用当前服务所在集群的设置。

+
+ 当前集群没有设置WAF策略,当前配置无法生效。 +
是否启用Web防火墙 @@ -44,21 +38,6 @@ Vue.component("http-firewall-config-box", {
选择Web防火墙策略 - 暂时还没有防火墙策略 -
- -

[正在停用的策略]{{selectedPolicy.description}}   详情»

-
-
` diff --git a/web/public/js/components/server/http-firewall-policy-selector.js b/web/public/js/components/server/http-firewall-policy-selector.js new file mode 100644 index 00000000..1a8b965a --- /dev/null +++ b/web/public/js/components/server/http-firewall-policy-selector.js @@ -0,0 +1,49 @@ +Vue.component("http-firewall-policy-selector", { + props: ["v-http-firewall-policy"], + mounted: function () { + let that = this + Tea.action("/servers/components/waf/count") + .post() + .success(function (resp) { + that.count = resp.data.count + }) + }, + data: function () { + let firewallPolicy = this.vHttpFirewallPolicy + return { + count: 0, + firewallPolicy: firewallPolicy + } + }, + methods: { + remove: function () { + this.firewallPolicy = null + }, + select: function () { + let that = this + teaweb.popup("/servers/components/waf/selectPopup", { + callback: function (resp) { + that.firewallPolicy = resp.data.firewallPolicy + } + }) + }, + create: function () { + let that = this + teaweb.popup("/servers/components/waf/createPopup", { + height: "26em", + callback: function (resp) { + that.firewallPolicy = resp.data.firewallPolicy + } + }) + } + }, + template: `
+
+ + {{firewallPolicy.name}}     +
+ +
` +}) \ No newline at end of file diff --git a/web/views/@default/clusters/cluster/settings/cache/index.html b/web/views/@default/clusters/cluster/settings/cache/index.html new file mode 100644 index 00000000..3abae661 --- /dev/null +++ b/web/views/@default/clusters/cluster/settings/cache/index.html @@ -0,0 +1,19 @@ +{$layout} +{$template "/left_menu"} + +
+
+ + + + + + + +
选择缓存策略 * + +

部署在当前集群上的所有服务都会自动使用此策略,只是服务可以自定义是否开启。

+
+ +
+
\ No newline at end of file diff --git a/web/views/@default/clusters/cluster/settings/cache/index.js b/web/views/@default/clusters/cluster/settings/cache/index.js new file mode 100644 index 00000000..295a9aaf --- /dev/null +++ b/web/views/@default/clusters/cluster/settings/cache/index.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyReloadSuccess("保存成功") +}) \ No newline at end of file diff --git a/web/views/@default/clusters/cluster/settings/waf/index.html b/web/views/@default/clusters/cluster/settings/waf/index.html new file mode 100644 index 00000000..4d77cfa9 --- /dev/null +++ b/web/views/@default/clusters/cluster/settings/waf/index.html @@ -0,0 +1,19 @@ +{$layout} +{$template "/left_menu"} + +
+
+ + + + + + + +
选择WAF策略 * + +

部署在当前集群上的所有服务都会自动使用此策略,只是服务可以自定义是否开启。

+
+ +
+
\ No newline at end of file diff --git a/web/views/@default/clusters/cluster/settings/waf/index.js b/web/views/@default/clusters/cluster/settings/waf/index.js new file mode 100644 index 00000000..295a9aaf --- /dev/null +++ b/web/views/@default/clusters/cluster/settings/waf/index.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyReloadSuccess("保存成功") +}) \ No newline at end of file diff --git a/web/views/@default/clusters/create.html b/web/views/@default/clusters/create.html index 237d8cbd..91e4c514 100644 --- a/web/views/@default/clusters/create.html +++ b/web/views/@default/clusters/create.html @@ -9,6 +9,18 @@
集群名称 *
默认缓存设置 * + +
默认WAF设置 * + +

节点安装选项

diff --git a/web/views/@default/clusters/grants/selectPopup.html b/web/views/@default/clusters/grants/selectPopup.html index 3aa7358d..dac31cee 100644 --- a/web/views/@default/clusters/grants/selectPopup.html +++ b/web/views/@default/clusters/grants/selectPopup.html @@ -2,18 +2,12 @@

选择认证

-
- - - - - - -
选择认证 - 暂时还没有可用的认证。 - {{grant.name}} ({{grant.methodName}}) -

请点击选中某个认证。

-
- - 确定 -
\ No newline at end of file + + + + +
+ 暂时还没有可用的认证。 + {{grant.name}} ({{grant.methodName}}) +

请点击选中某个认证。

+
\ No newline at end of file diff --git a/web/views/@default/clusters/grants/selectPopup.js b/web/views/@default/clusters/grants/selectPopup.js index b2a8d828..ce4aba25 100644 --- a/web/views/@default/clusters/grants/selectPopup.js +++ b/web/views/@default/clusters/grants/selectPopup.js @@ -2,8 +2,11 @@ Tea.context(function () { this.grantId = 0; this.selectGrant = function (grant) { - this.grantId = grant.id; + NotifyPopup({ + code: 200, + data: { + grant: grant + } + }) }; - - this.success = NotifyPopup; }); \ No newline at end of file diff --git a/web/views/@default/servers/components/cache/index.html b/web/views/@default/servers/components/cache/index.html index 664d2557..2e80202f 100644 --- a/web/views/@default/servers/components/cache/index.html +++ b/web/views/@default/servers/components/cache/index.html @@ -13,7 +13,7 @@
策略名称 策略类型 容量引用服务集群数 状态 操作
{{infos[index].countServers}}{{infos[index].countClusters}} 详情   删除 diff --git a/web/views/@default/servers/components/cache/policy.html b/web/views/@default/servers/components/cache/policy.html index 69a403b0..119ba1b1 100644 --- a/web/views/@default/servers/components/cache/policy.html +++ b/web/views/@default/servers/components/cache/policy.html @@ -1,67 +1,74 @@ {$layout} +{$template "policy_menu"} - {$template "policy_menu"} + + + + + + + + + + + + + -
策略名称{{cachePolicy.name}}
状态
缓存类型 + {{typeName}}({{cachePolicy.type}}) +
- - - - - - - - - - - - - - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - -
策略名称{{cachePolicy.name}}
状态
缓存类型 - {{typeName}}({{cachePolicy.type}}) -
缓存目录 - {{cachePolicy.options.dir}} -

存放文件缓存的目录,通常填写绝对路径。

-
缓存目录 + {{cachePolicy.options.dir}} +

存放文件缓存的目录,通常填写绝对路径。

+
缓存最大容量 - -

允许缓存的最大内容长度,如果为0表示没有限制。

-
最大内容长度 - -

允许缓存的最大内容长度,如果为0表示没有限制。

-
容纳Key数量 - {{cachePolicy.maxKeys}} - 不限 -

可以容纳多少数量的Key,0表示不限制。

-
描述 - {{cachePolicy.description}} - 暂时还没有描述。 -
\ No newline at end of file +
缓存最大容量 + +

允许缓存的最大内容长度,如果为0表示没有限制。

+
最大内容长度 + +

允许缓存的最大内容长度,如果为0表示没有限制。

+
容纳Key数量 + {{cachePolicy.maxKeys}} + 不限 +

可以容纳多少数量的Key,0表示不限制。

+
描述 + {{cachePolicy.description}} + 暂时还没有描述。 +
+ +

使用此策略的集群

+

暂时还没有集群使用此策略。

+ + + + +
{{cluster.name}}
\ No newline at end of file diff --git a/web/views/@default/servers/components/cache/selectPopup.html b/web/views/@default/servers/components/cache/selectPopup.html new file mode 100644 index 00000000..abb5b239 --- /dev/null +++ b/web/views/@default/servers/components/cache/selectPopup.html @@ -0,0 +1,24 @@ +{$layout "layout_popup"} + +

选择缓存策略

+ + + + + + + + + + + + + +
策略名称状态操作
{{cachePolicy.name}} + + + + 选择 + +
+
\ No newline at end of file diff --git a/web/views/@default/servers/components/cache/selectPopup.js b/web/views/@default/servers/components/cache/selectPopup.js new file mode 100644 index 00000000..e28bdfe8 --- /dev/null +++ b/web/views/@default/servers/components/cache/selectPopup.js @@ -0,0 +1,11 @@ +Tea.context(function () { + this.selectPolicy = function (cachePolicy) { + NotifyPopup({ + code: 200, + data: { + cachePolicy: cachePolicy + }, + message: "" + }) + } +}) \ No newline at end of file diff --git a/web/views/@default/servers/components/waf/index.html b/web/views/@default/servers/components/waf/index.html index da381f24..5c0b9fc9 100644 --- a/web/views/@default/servers/components/waf/index.html +++ b/web/views/@default/servers/components/waf/index.html @@ -14,7 +14,7 @@ 策略名称 入站规则分组 出站规则分组 - 引用服务 + 集群数 状态 操作 @@ -23,7 +23,7 @@ {{policy.name}} {{policy.countInbound}} {{policy.countOutbound}} - {{policy.countServers}} + {{policy.countClusters}} 详情   diff --git a/web/views/@default/servers/components/waf/policy.html b/web/views/@default/servers/components/waf/policy.html index 2fed1f46..da4265c9 100644 --- a/web/views/@default/servers/components/waf/policy.html +++ b/web/views/@default/servers/components/waf/policy.html @@ -1,55 +1,54 @@ {$layout} +{$template "waf_menu"} - {$template "waf_menu"} + + + + + + + + + + + + + + + + + + + + + +
策略名称{{firewallPolicy.name}}
是否启用 + +
预置的规则分组 + {{group.name}} +
阻止动作设置 + 还没有设置。 +
+ + + + + + + + + +
状态码{{firewallPolicy.blockOptions.statusCode}}
提示内容{{firewallPolicy.blockOptions.body}}
+
+
描述 + {{firewallPolicy.description}} + 暂时还没有描述。 +
- - - - - - - - - - - - - - - - - - - - - -
策略名称{{firewallPolicy.name}}
是否启用 - -
预置的规则分组 - {{group.name}} -
阻止动作设置 - 还没有设置。 -
- - - - - - - - - -
状态码{{firewallPolicy.blockOptions.statusCode}}
提示内容{{firewallPolicy.blockOptions.body}}
-
-
描述 - {{firewallPolicy.description}} - 暂时还没有描述。 -
- -

使用此策略的服务

-

暂时还没有代理服务使用此策略。

- - - - -
{{server.name}}
\ No newline at end of file +

使用此策略的集群

+

暂时还没有集群使用此策略。

+ + + + +
{{cluster.name}}
\ No newline at end of file diff --git a/web/views/@default/servers/components/waf/selectPopup.html b/web/views/@default/servers/components/waf/selectPopup.html new file mode 100644 index 00000000..5abeeaed --- /dev/null +++ b/web/views/@default/servers/components/waf/selectPopup.html @@ -0,0 +1,24 @@ +{$layout "layout_popup"} + +

选择WAF策略

+ + + + + + + + + + + + + +
策略名称状态操作
{{policy.name}} + + + + 选择 + +
+
\ No newline at end of file diff --git a/web/views/@default/servers/components/waf/selectPopup.js b/web/views/@default/servers/components/waf/selectPopup.js new file mode 100644 index 00000000..0bb96a2d --- /dev/null +++ b/web/views/@default/servers/components/waf/selectPopup.js @@ -0,0 +1,11 @@ +Tea.context(function () { + this.selectPolicy = function (firewallPolicy) { + NotifyPopup({ + code: 200, + data: { + firewallPolicy: firewallPolicy + }, + message: "" + }) + } +}) \ No newline at end of file diff --git a/web/views/@default/servers/server/settings/cache/createPopup.html b/web/views/@default/servers/server/settings/cache/createPopup.html index 76ad505d..7e546a1e 100644 --- a/web/views/@default/servers/server/settings/cache/createPopup.html +++ b/web/views/@default/servers/server/settings/cache/createPopup.html @@ -4,14 +4,6 @@
- - - -
缓存策略 * - -
diff --git a/web/views/@default/servers/server/settings/cache/createPopup.js b/web/views/@default/servers/server/settings/cache/createPopup.js index 8f26d615..b208fb78 100644 --- a/web/views/@default/servers/server/settings/cache/createPopup.js +++ b/web/views/@default/servers/server/settings/cache/createPopup.js @@ -2,16 +2,7 @@ Tea.context(function () { this.success = NotifyPopup this.cacheRef = null - let cachePolicyId = 0 - if (this.cachePolicies.length > 0) { - cachePolicyId = this.cachePolicies[0].id - } if (window.parent.UPDATING_CACHE_REF != null) { - let cacheRef = window.parent.UPDATING_CACHE_REF - this.cacheRef = cacheRef - if (cacheRef.cachePolicy != null) { - cachePolicyId = cacheRef.cachePolicy.id - } + this.cacheRef = window.parent.UPDATING_CACHE_REF } - this.cachePolicyId = cachePolicyId }) \ No newline at end of file diff --git a/web/views/@default/servers/server/settings/cache/index.html b/web/views/@default/servers/server/settings/cache/index.html index e2cbfd20..f6fa97a8 100644 --- a/web/views/@default/servers/server/settings/cache/index.html +++ b/web/views/@default/servers/server/settings/cache/index.html @@ -5,7 +5,7 @@
- +
\ No newline at end of file diff --git a/web/views/@default/servers/server/settings/locations/cache/index.html b/web/views/@default/servers/server/settings/locations/cache/index.html index 15e33075..9b6634b6 100644 --- a/web/views/@default/servers/server/settings/locations/cache/index.html +++ b/web/views/@default/servers/server/settings/locations/cache/index.html @@ -9,7 +9,7 @@
- +
diff --git a/web/views/@default/servers/server/settings/locations/waf/index.html b/web/views/@default/servers/server/settings/locations/waf/index.html index c1e4da70..f36dfdba 100644 --- a/web/views/@default/servers/server/settings/locations/waf/index.html +++ b/web/views/@default/servers/server/settings/locations/waf/index.html @@ -8,7 +8,7 @@
- +
diff --git a/web/views/@default/servers/server/settings/waf/index.html b/web/views/@default/servers/server/settings/waf/index.html index fee9741e..f8e7f889 100644 --- a/web/views/@default/servers/server/settings/waf/index.html +++ b/web/views/@default/servers/server/settings/waf/index.html @@ -2,9 +2,9 @@ {$template "/left_menu"}
-
- - - -
+
+ + + +
\ No newline at end of file