集群可以设置默认的WAF策略、缓存策略

This commit is contained in:
GoEdgeLab
2020-12-17 15:50:44 +08:00
parent ee549b945d
commit 41ac159e23
100 changed files with 1172 additions and 488 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)
}

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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()
}

View File

@@ -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 {

View File

@@ -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())
}

View File

@@ -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)

View File

@@ -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)).

View File

@@ -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()
}

View File

@@ -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

View File

@@ -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,

View File

@@ -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()
}

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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("找不到要操作的缓存策略")
}

View File

@@ -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()
}

View File

@@ -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()
}

View File

@@ -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

View File

@@ -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

View File

@@ -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()
})
}

View File

@@ -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()
}

View File

@@ -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("找不到要操作的缓存策略")
}

View File

@@ -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("找不到要操作的缓存策略")
}

View File

@@ -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()
}

View File

@@ -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("找不到要操作的缓存策略")
}

View File

@@ -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("找不到要操作的缓存策略")
}

View File

@@ -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("找不到要操作的缓存策略")
}

View File

@@ -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,

View File

@@ -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()
}

View File

@@ -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)

View File

@@ -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()
}

View File

@@ -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()
}

View File

@@ -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)

View File

@@ -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

View File

@@ -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())

View File

@@ -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,
})
}

View File

@@ -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)).

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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)

View File

@@ -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

View File

@@ -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()
}

View File

@@ -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()
}

View File

@@ -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)

View File

@@ -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)

View File

@@ -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,

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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()
}

View File

@@ -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)

View File

@@ -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()
}

View File

@@ -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()
}

View File

@@ -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()
}

View File

@@ -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)

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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
}

View File

@@ -0,0 +1,7 @@
package models
var SharedServerDAO = new(ServerDAO)
type ServerDAO struct {
BaseDAO
}

View File

@@ -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", {
<table class="ui table definition selectable">
<prior-checkbox :v-config="cacheConfig" v-if="vIsLocation"></prior-checkbox>
<tbody v-show="!vIsLocation || cacheConfig.isPrior">
<tr>
<td>缓存策略</td>
<td>
<div v-if="vCachePolicy != null">{{vCachePolicy.name}}
<p class="comment">使用当前服务所在集群的设置。</p>
</div>
<span v-else class="red">当前集群没有设置缓存策略,当前配置无法生效。</span>
</td>
</tr>
<tr>
<td class="title">是否开启缓存</td>
<td>
@@ -102,13 +111,11 @@ Vue.component("http-cache-config-box", {
<table class="ui table selectable" v-show="cacheConfig.cacheRefs.length > 0">
<thead>
<tr>
<th>缓存策略</th>
<th>条件</th>
<th>缓存时间</th>
<th class="two op">操作</th>
</tr>
<tr v-for="(cacheRef, index) in cacheConfig.cacheRefs">
<td><a :href="'/servers/components/cache/policy?cachePolicyId=' + cacheRef.cachePolicyId">{{cacheRef.cachePolicy.name}}</a></td>
<td>
<http-request-conds-view :v-conds="cacheRef.conds"></http-request-conds-view>
</td>

View File

@@ -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: `<div>
<div v-if="cachePolicy != null" class="ui label basic">
<input type="hidden" name="cachePolicyId" :value="cachePolicy.id"/>
{{cachePolicy.name}} &nbsp; <a :href="'/servers/components/cache/policy?cachePolicyId=' + cachePolicy.id" target="_blank"><i class="icon pencil small"></i></a>&nbsp; <a href="" @click.prevent="remove()"><i class="icon remove small"></i></a>
</div>
<div v-if="cachePolicy == null">
<span v-if="count > 0"><a href="" @click.prevent="select">[选择已有策略]</a> &nbsp; &nbsp; </span><a href="" @click.prevent="create">[创建新策略]</a>
</div>
</div>`
})

View File

@@ -43,7 +43,7 @@ Vue.component("http-cache-ref-box", {
},
template: `<tbody>
<tr>
<td>匹配条件 *</td>
<td class="title">匹配条件 *</td>
<td>
<http-request-conds-box :v-conds="ref.conds" @change="changeConds"></http-request-conds-box>

View File

@@ -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: `<div>
@@ -34,6 +19,15 @@ Vue.component("http-firewall-config-box", {
<table class="ui table selectable definition">
<prior-checkbox :v-config="firewall" v-if="vIsLocation"></prior-checkbox>
<tbody v-show="!vIsLocation || firewall.isPrior">
<tr>
<td>WAF策略</td>
<td>
<div v-if="vFirewallPolicy != null">{{vFirewallPolicy.name}}
<p class="comment">使用当前服务所在集群的设置。</p>
</div>
<span v-else class="red">当前集群没有设置WAF策略当前配置无法生效。</span>
</td>
</tr>
<tr>
<td class="title">是否启用Web防火墙</td>
<td>
@@ -44,21 +38,6 @@ Vue.component("http-firewall-config-box", {
</td>
</tr>
</tbody>
<tbody v-show="(!vIsLocation || firewall.isPrior) && firewall.isOn">
<tr>
<td>选择Web防火墙策略</td>
<td>
<span class="disabled" v-if="vFirewallPolicies.length == 0">暂时还没有防火墙策略</span>
<div v-if="vFirewallPolicies.length > 0">
<select class="ui dropdown auto-width" v-model="firewall.firewallPolicyId" @change="changePolicyId">
<option value="0">[请选择]</option>
<option v-for="policy in vFirewallPolicies" :value="policy.id">{{policy.name}}</option>
</select>
<p class="comment" v-if="selectedPolicy != null"><span v-if="!selectedPolicy.isOn" class="red">[正在停用的策略]</span>{{selectedPolicy.description}} &nbsp; <a :href="'/servers/components/waf/policy?firewallPolicyId=' + selectedPolicy.id">详情&raquo;</a> </p>
</div>
</td>
</tr>
</tbody>
</table>
<div class="margin"></div>
</div>`

View File

@@ -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: `<div>
<div v-if="firewallPolicy != null" class="ui label basic">
<input type="hidden" name="httpFirewallPolicyId" :value="firewallPolicy.id"/>
{{firewallPolicy.name}} &nbsp; <a :href="'/servers/components/waf/policy?firewallPolicyId=' + firewallPolicy.id" target="_blank"><i class="icon pencil small"></i></a>&nbsp; <a href="" @click.prevent="remove()"><i class="icon remove small"></i></a>
</div>
<div v-if="firewallPolicy == null">
<span v-if="count > 0"><a href="" @click.prevent="select">[选择已有策略]</a> &nbsp; &nbsp; </span><a href="" @click.prevent="create">[创建新策略]</a>
</div>
</div>`
})

View File

@@ -0,0 +1,19 @@
{$layout}
{$template "/left_menu"}
<div class="right-box">
<form class="ui form" method="post" data-tea-action="$" data-tea-success="success">
<csrf-token></csrf-token>
<input type="hidden" name="clusterId" :value="clusterId"/>
<table class="ui table definition selectable">
<tr>
<td class="title">选择缓存策略 *</td>
<td>
<http-cache-policy-selector :v-cache-policy="cachePolicy"></http-cache-policy-selector>
<p class="comment">部署在当前集群上的所有服务都会自动使用此策略,只是服务可以自定义是否开启。</p>
</td>
</tr>
</table>
<submit-btn></submit-btn>
</form>
</div>

View File

@@ -0,0 +1,3 @@
Tea.context(function () {
this.success = NotifyReloadSuccess("保存成功")
})

View File

@@ -0,0 +1,19 @@
{$layout}
{$template "/left_menu"}
<div class="right-box">
<form class="ui form" method="post" data-tea-action="$" data-tea-success="success">
<csrf-token></csrf-token>
<input type="hidden" name="clusterId" :value="clusterId"/>
<table class="ui table definition selectable">
<tr>
<td class="title">选择WAF策略 *</td>
<td>
<http-firewall-policy-selector :v-http-firewall-policy="firewallPolicy"></http-firewall-policy-selector>
<p class="comment">部署在当前集群上的所有服务都会自动使用此策略,只是服务可以自定义是否开启。</p>
</td>
</tr>
</table>
<submit-btn></submit-btn>
</form>
</div>

View File

@@ -0,0 +1,3 @@
Tea.context(function () {
this.success = NotifyReloadSuccess("保存成功")
})

View File

@@ -9,6 +9,18 @@
<td class="title">集群名称 *</td>
<td><input type="text" name="name" maxlength="50" ref="focus"/></td>
</tr>
<tr>
<td>默认缓存设置 *</td>
<td>
<http-cache-policy-selector></http-cache-policy-selector>
</td>
</tr>
<tr>
<td>默认WAF设置 *</td>
<td>
<http-firewall-policy-selector></http-firewall-policy-selector>
</td>
</tr>
</table>
<h4>节点安装选项</h4>

View File

@@ -2,18 +2,12 @@
<h3>选择认证</h3>
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<input type="hidden" name="grantId" :value="grantId"/>
<table class="ui table selectable definition">
<tr>
<td class="title">选择认证</td>
<td>
<span v-if="grants.length == 0">暂时还没有可用的认证。</span>
<a class="ui label small basic" v-for="grant in grants" :class="{blue:grantId == grant.id}" @click.prevent="selectGrant(grant)" style="margin-bottom:0.5em">{{grant.name}} <span class="small">{{grant.methodName}}</span></a>
<p class="comment">请点击选中某个认证。</p>
</td>
</tr>
</table>
<submit-btn>确定</submit-btn>
</form>
<table class="ui table definition">
<tr>
<td>
<span v-if="grants.length == 0">暂时还没有可用的认证。</span>
<a class="ui label small basic" v-for="grant in grants" :class="{blue:grantId == grant.id}" @click.prevent="selectGrant(grant)" style="margin-bottom:0.5em">{{grant.name}} <span class="small">{{grant.methodName}}</span></a>
<p class="comment">请点击选中某个认证。</p>
</td>
</tr>
</table>

View File

@@ -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;
});

View File

@@ -13,7 +13,7 @@
<th>策略名称</th>
<th>策略类型</th>
<th>容量</th>
<th class="center">引用服务</th>
<th class="center">集群数</th>
<th class="center">状态</th>
<th class="two op">操作</th>
</tr>
@@ -25,7 +25,7 @@
<span v-if="policy.capacity != null && policy.capacity.count > 0">{{policy.capacity.count}}{{policy.capacity.unit.toUpperCase()}}</span>
<span v-else class="disabled">不限</span>
</td>
<td class="center">{{infos[index].countServers}}</td>
<td class="center">{{infos[index].countClusters}}</td>
<td class="center"><label-on :v-is-on="policy.isOn"></label-on></td>
<td>
<a :href="'/servers/components/cache/policy?cachePolicyId=' + policy.id">详情</a> &nbsp; <a href="" @click.prevent="deletePolicy(policy.id)">删除</a>

View File

@@ -1,67 +1,74 @@
{$layout}
{$template "policy_menu"}
{$template "policy_menu"}
<table class="ui table definition selectable">
<tr>
<td class="title">策略名称</td>
<td>{{cachePolicy.name}}</td>
</tr>
<tr>
<td>状态</td>
<td><label-on :v-is-on="cachePolicy.isOn"></label-on></td>
</tr>
<tr>
<td class="color-border">缓存类型</td>
<td>
{{typeName}}<span class="small">{{cachePolicy.type}}</span>
</td>
</tr>
<table class="ui table definition selectable">
<tr>
<td class="title">策略名称</td>
<td>{{cachePolicy.name}}</td>
</tr>
<tr>
<td>状态</td>
<td><label-on :v-is-on="cachePolicy.isOn"></label-on></td>
</tr>
<tr>
<td class="color-border">缓存类型</td>
<td>
{{typeName}}<span class="small">{{cachePolicy.type}}</span>
</td>
</tr>
<!-- 文件缓存选项 -->
<tbody v-if="cachePolicy.type == 'file'">
<tr>
<td class="color-border">缓存目录</td>
<td>
{{cachePolicy.options.dir}}
<p class="comment">存放文件缓存的目录,通常填写绝对路径。</p>
</td>
</tr>
</tbody>
<!-- 文件缓存选项 -->
<tbody v-if="cachePolicy.type == 'file'">
<tr>
<td class="color-border">缓存目录</td>
<td>
{{cachePolicy.options.dir}}
<p class="comment">存放文件缓存的目录,通常填写绝对路径。</p>
</td>
</tr>
</tbody>
<tr>
<td>缓存最大容量</td>
<td>
<size-capacity-view :v-value="cachePolicy.capacity" :v-default-text="'不限'"></size-capacity-view>
<p class="comment">允许缓存的最大内容长度如果为0表示没有限制。</p>
</td>
</tr>
<tr>
<td colspan="2"><more-options-indicator></more-options-indicator></td>
</tr>
<tbody v-show="moreOptionsVisible">
<tr>
<td>最大内容长度</td>
<td>
<size-capacity-view :v-value="cachePolicy.maxSize" :v-default-text="'不限'"></size-capacity-view>
<p class="comment">允许缓存的最大内容长度如果为0表示没有限制。</p>
</td>
</tr>
<tr>
<td>容纳Key数量</td>
<td>
<span v-if="cachePolicy.maxKeys > 0">{{cachePolicy.maxKeys}}</span>
<span v-else>不限</span>
<p class="comment">可以容纳多少数量的Key0表示不限制。</p>
</td>
</tr>
<tr>
<td>描述</td>
<td>
<span v-if="cachePolicy.description.length > 0">{{cachePolicy.description}}</span>
<span v-else class="disabled">暂时还没有描述。</span>
</td>
</tr>
</tbody>
</table>
<tr>
<td>缓存最大容量</td>
<td>
<size-capacity-view :v-value="cachePolicy.capacity" :v-default-text="'不限'"></size-capacity-view>
<p class="comment">允许缓存的最大内容长度如果为0表示没有限制。</p>
</td>
</tr>
<tr>
<td colspan="2"><more-options-indicator></more-options-indicator></td>
</tr>
<tbody v-show="moreOptionsVisible">
<tr>
<td>最大内容长度</td>
<td>
<size-capacity-view :v-value="cachePolicy.maxSize" :v-default-text="'不限'"></size-capacity-view>
<p class="comment">允许缓存的最大内容长度如果为0表示没有限制。</p>
</td>
</tr>
<tr>
<td>容纳Key数量</td>
<td>
<span v-if="cachePolicy.maxKeys > 0">{{cachePolicy.maxKeys}}</span>
<span v-else>不限</span>
<p class="comment">可以容纳多少数量的Key0表示不限制。</p>
</td>
</tr>
<tr>
<td>描述</td>
<td>
<span v-if="cachePolicy.description.length > 0">{{cachePolicy.description}}</span>
<span v-else class="disabled">暂时还没有描述。</span>
</td>
</tr>
</tbody>
</table>
<h4>使用此策略的集群</h4>
<p class="comment" v-if="clusters.length == 0">暂时还没有集群使用此策略。</p>
<table class="ui table selectable" v-if="clusters.length > 0">
<tr v-for="cluster in clusters">
<td>{{cluster.name}}<link-icon :href="'/clusters/cluster?clusterId=' + cluster.id"></link-icon></td>
</tr>
</table>

View File

@@ -0,0 +1,24 @@
{$layout "layout_popup"}
<h3>选择缓存策略</h3>
<table class="ui table selectable">
<thead>
<tr>
<th>策略名称</th>
<th style="width: 7em">状态</th>
<th class="two op">操作</th>
</tr>
</thead>
<tr v-for="cachePolicy in cachePolicies">
<td>{{cachePolicy.name}}</td>
<td>
<label-on :v-is-on="cachePolicy.isOn"></label-on>
</td>
<td>
<span v-if="cachePolicy.isOn">
<a href="" @click.prevent="selectPolicy(cachePolicy)">选择</a>
</span>
</td>
</tr>
</table>
<div class="page" v-html="page"></div>

View File

@@ -0,0 +1,11 @@
Tea.context(function () {
this.selectPolicy = function (cachePolicy) {
NotifyPopup({
code: 200,
data: {
cachePolicy: cachePolicy
},
message: ""
})
}
})

View File

@@ -14,7 +14,7 @@
<th>策略名称</th>
<th class="center">入站规则分组</th>
<th class="center">出站规则分组</th>
<th class="center">引用服务</th>
<th class="center">集群数</th>
<th class="two wide center">状态</th>
<th class="two op">操作</th>
</tr>
@@ -23,7 +23,7 @@
<td>{{policy.name}}</td>
<td class="center">{{policy.countInbound}}</td>
<td class="center">{{policy.countOutbound}}</td>
<td class="center">{{policy.countServers}}</td>
<td class="center">{{policy.countClusters}}</td>
<td class="center"><label-on :v-is-on="policy.isOn"></label-on></td>
<td>
<a :href="'/servers/components/waf/policy?firewallPolicyId=' + policy.id">详情</a> &nbsp;

View File

@@ -1,55 +1,54 @@
{$layout}
{$template "waf_menu"}
{$template "waf_menu"}
<table class="ui table definition selectable">
<tr>
<td class="title">策略名称</td>
<td>{{firewallPolicy.name}}</td>
</tr>
<tr>
<td>是否启用</td>
<td>
<label-on :v-is-on="firewallPolicy.isOn"></label-on>
</td>
</tr>
<tr>
<td>预置的规则分组</td>
<td>
<span class="ui label tiny basic" v-for="group in firewallPolicy.groups" style="margin-bottom:0.5em" :class="{disabled:!group.isOn}">{{group.name}}</span>
</td>
</tr>
<tr>
<td>阻止动作设置</td>
<td>
<span v-if="firewallPolicy.blockOptions == null" class="disabled">还没有设置。</span>
<div v-else>
<table class="ui table">
<tr>
<td class="title">状态码</td>
<td>{{firewallPolicy.blockOptions.statusCode}}</td>
</tr>
<tr>
<td>提示内容</td>
<td>{{firewallPolicy.blockOptions.body}}</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td>描述</td>
<td>
<span v-if="firewallPolicy.description.length > 0">{{firewallPolicy.description}}</span>
<span v-else class="disabled">暂时还没有描述。</span>
</td>
</tr>
</table>
<table class="ui table definition selectable">
<tr>
<td class="title">策略名称</td>
<td>{{firewallPolicy.name}}</td>
</tr>
<tr>
<td>是否启用</td>
<td>
<label-on :v-is-on="firewallPolicy.isOn"></label-on>
</td>
</tr>
<tr>
<td>预置的规则分组</td>
<td>
<span class="ui label tiny basic" v-for="group in firewallPolicy.groups" style="margin-bottom:0.5em" :class="{disabled:!group.isOn}">{{group.name}}</span>
</td>
</tr>
<tr>
<td>阻止动作设置</td>
<td>
<span v-if="firewallPolicy.blockOptions == null" class="disabled">还没有设置。</span>
<div v-else>
<table class="ui table">
<tr>
<td class="title">状态码</td>
<td>{{firewallPolicy.blockOptions.statusCode}}</td>
</tr>
<tr>
<td>提示内容</td>
<td>{{firewallPolicy.blockOptions.body}}</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td>描述</td>
<td>
<span v-if="firewallPolicy.description.length > 0">{{firewallPolicy.description}}</span>
<span v-else class="disabled">暂时还没有描述。</span>
</td>
</tr>
</table>
<h4>使用此策略的服务</h4>
<p class="comment" v-if="servers.length == 0">暂时还没有代理服务使用此策略。</p>
<table class="ui table selectable" v-if="servers.length > 0">
<tr v-for="server in servers">
<td>{{server.name}}<link-icon :href="'/servers/server?serverId=' + server.id"></link-icon></td>
</tr>
</table>
<h4>使用此策略的集群</h4>
<p class="comment" v-if="clusters.length == 0">暂时还没有集群使用此策略。</p>
<table class="ui table selectable" v-if="clusters.length > 0">
<tr v-for="cluster in clusters">
<td>{{cluster.name}}<link-icon :href="'/clusters/cluster?clusterId=' + cluster.id"></link-icon></td>
</tr>
</table>

View File

@@ -0,0 +1,24 @@
{$layout "layout_popup"}
<h3>选择WAF策略</h3>
<table class="ui table selectable">
<thead>
<tr>
<th>策略名称</th>
<th style="width: 7em">状态</th>
<th class="two op">操作</th>
</tr>
</thead>
<tr v-for="policy in policies">
<td>{{policy.name}}</td>
<td>
<label-on :v-is-on="policy.isOn"></label-on>
</td>
<td>
<span v-if="policy.isOn">
<a href="" @click.prevent="selectPolicy(policy)">选择</a>
</span>
</td>
</tr>
</table>
<div class="page" v-html="page"></div>

View File

@@ -0,0 +1,11 @@
Tea.context(function () {
this.selectPolicy = function (firewallPolicy) {
NotifyPopup({
code: 200,
data: {
firewallPolicy: firewallPolicy
},
message: ""
})
}
})

View File

@@ -4,14 +4,6 @@
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<table class="ui table definition selectable">
<tr>
<td class="title">缓存策略 *</td>
<td>
<select class="ui dropdown auto-width" name="cachePolicyId" v-model="cachePolicyId">
<option v-for="cachePolicy in cachePolicies" :value="cachePolicy.id">{{cachePolicy.name}}</option>
</select>
</td>
</tr>
<tbody is="http-cache-ref-box" :v-cache-ref="cacheRef"></tbody>
</table>
<submit-btn></submit-btn>

View File

@@ -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
})

View File

@@ -5,7 +5,7 @@
<div class="right-box">
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<input type="hidden" name="webId" :value="webId"/>
<http-cache-config-box :v-cache-config="cacheConfig"></http-cache-config-box>
<http-cache-config-box :v-cache-config="cacheConfig" :v-cache-policy="cachePolicy"></http-cache-config-box>
<submit-btn></submit-btn>
</form>
</div>

View File

@@ -9,7 +9,7 @@
<div class="right-box tiny">
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<input type="hidden" name="webId" :value="webId"/>
<http-cache-config-box :v-cache-config="cacheConfig" :v-is-location="true"></http-cache-config-box>
<http-cache-config-box :v-cache-config="cacheConfig" :v-cache-policy="cachePolicy" :v-is-location="true"></http-cache-config-box>
<submit-btn></submit-btn>
</form>
</div>

View File

@@ -8,7 +8,7 @@
<div class="right-box tiny">
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<input type="hidden" name="webId" :value="webId"/>
<http-firewall-config-box :v-firewall-config="firewallConfig" :v-firewall-policies="firewallPolicies" :v-is-location="true"></http-firewall-config-box>
<http-firewall-config-box :v-firewall-config="firewallConfig" :v-firewall-policy="firewallPolicy" :v-is-location="true"></http-firewall-config-box>
<submit-btn></submit-btn>
</form>
</div>

View File

@@ -2,9 +2,9 @@
{$template "/left_menu"}
<div class="right-box">
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<input type="hidden" name="webId" :value="webId"/>
<http-firewall-config-box :v-firewall-config="firewallConfig" :v-firewall-policies="firewallPolicies"></http-firewall-config-box>
<submit-btn></submit-btn>
</form>
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<input type="hidden" name="webId" :value="webId"/>
<http-firewall-config-box :v-firewall-config="firewallConfig" :v-firewall-policy="firewallPolicy"></http-firewall-config-box>
<submit-btn></submit-btn>
</form>
</div>