mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-08 06:00:24 +08:00
waf/ip名单有变更立即发送通知
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user