diff --git a/internal/web/actions/default/servers/components/waf/ipadmin/createIPPopup.go b/internal/web/actions/default/servers/components/waf/ipadmin/createIPPopup.go index df78b125..44f0bd8f 100644 --- a/internal/web/actions/default/servers/components/waf/ipadmin/createIPPopup.go +++ b/internal/web/actions/default/servers/components/waf/ipadmin/createIPPopup.go @@ -2,6 +2,7 @@ package ipadmin import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/waf/ipadmin/ipadminutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/models" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" @@ -32,11 +33,12 @@ func (this *CreateIPPopupAction) RunGet(params struct { } func (this *CreateIPPopupAction) RunPost(params struct { - ListId int64 - IpFrom string - IpTo string - ExpiredAt int64 - Reason string + FirewallPolicyId int64 + ListId int64 + IpFrom string + IpTo string + ExpiredAt int64 + Reason string Must *actions.Must CSRF *actionutils.CSRF @@ -60,5 +62,12 @@ func (this *CreateIPPopupAction) RunPost(params struct { return } + // 发送通知 + err = ipadminutils.NotifyUpdateToClustersWithFirewallPolicyId(this.AdminContext(), params.FirewallPolicyId) + if err != nil { + this.ErrorPage(err) + return + } + this.Success() } diff --git a/internal/web/actions/default/servers/components/waf/ipadmin/deleteIP.go b/internal/web/actions/default/servers/components/waf/ipadmin/deleteIP.go index c11d3d8e..5a2c5a6a 100644 --- a/internal/web/actions/default/servers/components/waf/ipadmin/deleteIP.go +++ b/internal/web/actions/default/servers/components/waf/ipadmin/deleteIP.go @@ -2,6 +2,7 @@ package ipadmin import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/waf/ipadmin/ipadminutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" ) @@ -10,7 +11,8 @@ type DeleteIPAction struct { } func (this *DeleteIPAction) RunPost(params struct { - ItemId int64 + FirewallPolicyId int64 + ItemId int64 }) { // TODO 判断权限 @@ -20,5 +22,12 @@ func (this *DeleteIPAction) RunPost(params struct { return } + // 发送通知 + err = ipadminutils.NotifyUpdateToClustersWithFirewallPolicyId(this.AdminContext(), params.FirewallPolicyId) + if err != nil { + this.ErrorPage(err) + return + } + this.Success() } 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 new file mode 100644 index 00000000..1f842055 --- /dev/null +++ b/internal/web/actions/default/servers/components/waf/ipadmin/ipadminutils/utils.go @@ -0,0 +1,35 @@ +package ipadminutils + +import ( + "context" + "github.com/TeaOSLab/EdgeAdmin/internal/rpc" + "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策略的集群更新 +func NotifyUpdateToClustersWithFirewallPolicyId(ctx context.Context, firewallPolicyId int64) error { + client, err := rpc.SharedRPC() + if err != nil { + return err + } + resp, err := client.ServerRPC().FindAllEnabledServersWithHTTPFirewallPolicyId(ctx, &pb.FindAllEnabledServersWithHTTPFirewallPolicyIdRequest{FirewallPolicyId: 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) + if err != nil { + return err + } + } + return nil +} diff --git a/internal/web/actions/default/servers/components/waf/ipadmin/updateIPPopup.go b/internal/web/actions/default/servers/components/waf/ipadmin/updateIPPopup.go index bd020439..3af790c1 100644 --- a/internal/web/actions/default/servers/components/waf/ipadmin/updateIPPopup.go +++ b/internal/web/actions/default/servers/components/waf/ipadmin/updateIPPopup.go @@ -2,6 +2,7 @@ package ipadmin import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/waf/ipadmin/ipadminutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/maps" @@ -41,7 +42,8 @@ func (this *UpdateIPPopupAction) RunGet(params struct { } func (this *UpdateIPPopupAction) RunPost(params struct { - ItemId int64 + FirewallPolicyId int64 + ItemId int64 IpFrom string IpTo string @@ -70,5 +72,12 @@ func (this *UpdateIPPopupAction) RunPost(params struct { return } + // 发送通知 + err = ipadminutils.NotifyUpdateToClustersWithFirewallPolicyId(this.AdminContext(), params.FirewallPolicyId) + if err != nil { + this.ErrorPage(err) + return + } + this.Success() } diff --git a/internal/web/helpers/user_must_auth.go b/internal/web/helpers/user_must_auth.go index a9cf3890..52c6e682 100644 --- a/internal/web/helpers/user_must_auth.go +++ b/internal/web/helpers/user_must_auth.go @@ -114,6 +114,7 @@ func (this *UserMustAuth) BeforeAction(actionPtr actions.ActionWrapper, paramNam action.Data["teaTabbar"] = []map[string]interface{}{} action.Data["teaVersion"] = teaconst.Version action.Data["teaIsSuper"] = false + action.Data["teaDemoEnabled"] = teaconst.IsDemo // 菜单 action.Data["firstMenuItem"] = "" diff --git a/web/views/@default/@layout.js b/web/views/@default/@layout.js index 7cde84d9..b28cfbc2 100644 --- a/web/views/@default/@layout.js +++ b/web/views/@default/@layout.js @@ -2,7 +2,6 @@ Tea.context(function () { this.moreOptionsVisible = false this.globalChangedClusters = [] this.globalMessageBadge = 0 - this.teaDemoEnabled = false if (typeof this.leftMenuItemIsDisabled == "undefined") { this.leftMenuItemIsDisabled = false diff --git a/web/views/@default/servers/components/waf/ipadmin/createIPPopup.html b/web/views/@default/servers/components/waf/ipadmin/createIPPopup.html index 1ad0a64d..33880182 100644 --- a/web/views/@default/servers/components/waf/ipadmin/createIPPopup.html +++ b/web/views/@default/servers/components/waf/ipadmin/createIPPopup.html @@ -4,6 +4,7 @@

添加IP到黑名单

+ diff --git a/web/views/@default/servers/components/waf/ipadmin/lists.js b/web/views/@default/servers/components/waf/ipadmin/lists.js index b683f91c..5d566046 100644 --- a/web/views/@default/servers/components/waf/ipadmin/lists.js +++ b/web/views/@default/servers/components/waf/ipadmin/lists.js @@ -1,6 +1,6 @@ Tea.context(function () { this.updateItem = function (itemId) { - teaweb.popup(Tea.url(".updateIPPopup", {itemId: itemId}), { + teaweb.popup(Tea.url(".updateIPPopup?firewallPolicyId=" + this.firewallPolicyId, {itemId: itemId}), { height: "23em", callback: function () { teaweb.success("保存成功", function () { @@ -15,6 +15,7 @@ Tea.context(function () { teaweb.confirm("确定要删除这个IP吗?", function () { that.$post(".deleteIP") .params({ + "firewallPolicyId": this.firewallPolicyId, "itemId": itemId }) .refresh() diff --git a/web/views/@default/servers/components/waf/ipadmin/updateIPPopup.html b/web/views/@default/servers/components/waf/ipadmin/updateIPPopup.html index 5fee0fcb..0586e4aa 100644 --- a/web/views/@default/servers/components/waf/ipadmin/updateIPPopup.html +++ b/web/views/@default/servers/components/waf/ipadmin/updateIPPopup.html @@ -3,6 +3,7 @@

修改IP

+