|
@@ -23,11 +23,11 @@ type WafFormatterService interface {
|
|
|
ConvertToWildcardDomain(ctx context.Context,domain string) (string, error)
|
|
|
AppendWafIp(ctx context.Context, req []string,returnSourceIp string) ([]v1.IpInfo, error)
|
|
|
WashIps(ctx context.Context, req []string) ([]string, error)
|
|
|
- PublishIpWhitelistTask(ips []string, action string,returnSourceIp string)
|
|
|
+ PublishIpWhitelistTask(ips []string, action string,returnSourceIp string, color string)
|
|
|
PublishDomainWhitelistTask(domain, ip, action string)
|
|
|
findIpDifferences(oldIps, newIps []string) ([]string, []string)
|
|
|
WashDeleteWafIp(ctx context.Context, backendList []string,allowIpList []string) ([]string, error)
|
|
|
- WashEditWafIp(ctx context.Context, newBackendList []string,newAllowIpList []string,oldBackendList []string,oldAllowIpList []string) ([]string, []string, []string, []string, error)
|
|
|
+ WashEditWafIp(ctx context.Context, newBackendList []string,newAllowIpList []string, newDenyIpList []string,oldBackendList []string,oldAllowIpList []string,oldDenyIpList []string) ([]string, []string, []string, []string, []string,[]string, error)
|
|
|
//cdn添加网站
|
|
|
AddOrigin(ctx context.Context, req v1.WebJson) (int64, error)
|
|
|
}
|
|
@@ -263,23 +263,25 @@ func (s *wafFormatterService) PublishDomainWhitelistTask(domain, ip, action stri
|
|
|
}
|
|
|
|
|
|
|
|
|
-func (s *wafFormatterService) PublishIpWhitelistTask(ips []string, action string, returnSourceIp string) {
|
|
|
+func (s *wafFormatterService) PublishIpWhitelistTask(ips []string, action string, returnSourceIp string,color string) {
|
|
|
// Define message payload, including the action
|
|
|
type ipTaskPayload struct {
|
|
|
Ips []string `json:"ips"`
|
|
|
Action string `json:"action"`
|
|
|
ReturnSourceIp string `json:"return_source_ip"`
|
|
|
+ Color string `json:"color"`
|
|
|
}
|
|
|
payload := ipTaskPayload{
|
|
|
Ips: ips,
|
|
|
Action: action,
|
|
|
ReturnSourceIp: returnSourceIp,
|
|
|
+ Color: color,
|
|
|
}
|
|
|
|
|
|
// Serialize the message
|
|
|
msgBody, err := json.Marshal(payload)
|
|
|
if err != nil {
|
|
|
- s.logger.Error("序列化 IP 白名单任务消息失败", zap.Error(err), zap.Any("IPs", ips), zap.String("action", action))
|
|
|
+ s.logger.Error("序列化 IP 白名单任务消息失败", zap.Error(err), zap.Any("IPs", ips), zap.String("action", action),zap.String("color", color))
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -303,9 +305,9 @@ func (s *wafFormatterService) PublishIpWhitelistTask(ips []string, action string
|
|
|
// Publish the message
|
|
|
err = s.mq.PublishWithCh(taskCfg.Exchange, routingKey, publishingMsg)
|
|
|
if err != nil {
|
|
|
- s.logger.Error("发布 IP 白名单任务到 MQ 失败", zap.Error(err), zap.String("action", action))
|
|
|
+ s.logger.Error("发布 IP 白名单任务到 MQ 失败", zap.Error(err), zap.String("action", action),zap.String("color", color))
|
|
|
} else {
|
|
|
- s.logger.Info("成功将 IP 白名单任务发布到 MQ", zap.String("action", action))
|
|
|
+ s.logger.Info("成功将 IP 白名单任务发布到 MQ", zap.String("action", action),zap.String("color", color))
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -354,15 +356,17 @@ func (s *wafFormatterService) WashDeleteWafIp(ctx context.Context, backendList [
|
|
|
return res, nil
|
|
|
}
|
|
|
|
|
|
-func (s *wafFormatterService) WashEditWafIp(ctx context.Context, newBackendList []string,newAllowIpList []string,oldBackendList []string,oldAllowIpList []string) ([]string, []string, []string, []string, error) {
|
|
|
+func (s *wafFormatterService) WashEditWafIp(ctx context.Context, newBackendList []string,newAllowIpList []string, newDenyIpList []string,oldBackendList []string,oldAllowIpList []string,oldDenyIpList []string) ([]string, []string, []string, []string, []string,[]string,error) {
|
|
|
var oldIps []string
|
|
|
var newIps []string
|
|
|
var oldAllowIps []string
|
|
|
var newAllowIps []string
|
|
|
+ var oldDenyIps []string
|
|
|
+ var newDenyIps []string
|
|
|
for _, v := range oldBackendList {
|
|
|
ip, _, err := net.SplitHostPort(v)
|
|
|
if err != nil {
|
|
|
- return nil, nil, nil, nil, err
|
|
|
+ return nil, nil, nil, nil,nil, nil, err
|
|
|
}
|
|
|
oldIps = append(oldIps, ip)
|
|
|
}
|
|
@@ -370,7 +374,7 @@ func (s *wafFormatterService) WashEditWafIp(ctx context.Context, newBackendList
|
|
|
for _, v := range newBackendList {
|
|
|
ip, _, err := net.SplitHostPort(v)
|
|
|
if err != nil {
|
|
|
- return nil, nil, nil, nil, err
|
|
|
+ return nil, nil, nil, nil,nil, nil, err
|
|
|
}
|
|
|
newIps = append(newIps, ip)
|
|
|
}
|
|
@@ -385,9 +389,16 @@ func (s *wafFormatterService) WashEditWafIp(ctx context.Context, newBackendList
|
|
|
}
|
|
|
addedAllowIps, removedAllowIps := s.findIpDifferences(oldAllowIps, newAllowIps)
|
|
|
|
|
|
+ if oldDenyIpList != nil {
|
|
|
+ oldDenyIps = append(oldDenyIps, oldDenyIpList...)
|
|
|
+ }
|
|
|
+ if newDenyIpList != nil {
|
|
|
+ newDenyIps = append(newDenyIps, newDenyIpList...)
|
|
|
+ }
|
|
|
+ addedDenyIps, removedDenyIps := s.findIpDifferences(oldDenyIps, newDenyIps)
|
|
|
|
|
|
|
|
|
- return addedIps, removedIps ,addedAllowIps, removedAllowIps, nil
|
|
|
+ return addedIps, removedIps ,addedAllowIps, removedAllowIps, addedDenyIps, removedDenyIps, nil
|
|
|
}
|
|
|
|
|
|
|