|
@@ -34,6 +34,7 @@ func NewWebForwardingService(
|
|
|
aoDun AoDunService,
|
|
|
mq *rabbitmq.RabbitMQ,
|
|
|
gatewayGroupIpRep repository.GateWayGroupIpRepository,
|
|
|
+ gatewayGroupRep repository.GatewayGroupRepository,
|
|
|
) WebForwardingService {
|
|
|
return &webForwardingService{
|
|
|
Service: service,
|
|
@@ -45,6 +46,7 @@ func NewWebForwardingService(
|
|
|
aoDun: aoDun,
|
|
|
mq: mq,
|
|
|
gatewayGroupIpRep: gatewayGroupIpRep,
|
|
|
+ gatewayGroupRep: gatewayGroupRep,
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -58,6 +60,7 @@ type webForwardingService struct {
|
|
|
aoDun AoDunService
|
|
|
mq *rabbitmq.RabbitMQ
|
|
|
gatewayGroupIpRep repository.GateWayGroupIpRepository
|
|
|
+ gatewayGroupRep repository.GatewayGroupRepository
|
|
|
}
|
|
|
|
|
|
func (s *webForwardingService) require(ctx context.Context,req v1.GlobalRequire) (v1.GlobalRequire, error) {
|
|
@@ -297,6 +300,18 @@ func (s *webForwardingService) prepareWafData(ctx context.Context, req *v1.WebFo
|
|
|
return require, formData, nil
|
|
|
}
|
|
|
|
|
|
+func (s *webForwardingService) GetIp(ctx context.Context, gatewayGroupId int) (string, error) {
|
|
|
+ WafGatewayGroupRuleId, err := s.gatewayGroupRep.GetGatewayGroupByRuleId(ctx, int64(gatewayGroupId))
|
|
|
+ if err != nil {
|
|
|
+ return "", err
|
|
|
+ }
|
|
|
+ ip, err := s.gatewayGroupIpRep.GetGateWayGroupFirstIpByGatewayGroupId(ctx, WafGatewayGroupRuleId.Id)
|
|
|
+ if err != nil {
|
|
|
+ return "", err
|
|
|
+ }
|
|
|
+ return ip, nil
|
|
|
+}
|
|
|
+
|
|
|
func (s *webForwardingService) AddWebForwarding(ctx context.Context, req *v1.WebForwardingRequest) error {
|
|
|
require, formData, err := s.prepareWafData(ctx, req)
|
|
|
if err != nil {
|
|
@@ -311,15 +326,16 @@ func (s *webForwardingService) AddWebForwarding(ctx context.Context, req *v1.Web
|
|
|
return err
|
|
|
}
|
|
|
if req.WebForwardingData.Domain != "" {
|
|
|
- // 异步任务:将域名添加到白名单
|
|
|
- doMain, err := s.wafformatter.ConvertToWildcardDomain(ctx, req.WebForwardingData.Domain)
|
|
|
+ ip, err := s.GetIp(ctx, require.WafGatewayGroupId)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- ip, err := s.gatewayGroupIpRep.GetGateWayGroupFirstIpByGatewayGroupId(ctx, require.WafGatewayGroupId)
|
|
|
+ // 异步任务:将域名添加到白名单
|
|
|
+ doMain, err := s.wafformatter.ConvertToWildcardDomain(ctx, req.WebForwardingData.Domain)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
+
|
|
|
go s.publishDomainWhitelistTask(doMain,ip, "add")
|
|
|
}
|
|
|
|
|
@@ -368,8 +384,9 @@ func (s *webForwardingService) EditWebForwarding(ctx context.Context, req *v1.We
|
|
|
return err
|
|
|
}
|
|
|
if webData.Domain != req.WebForwardingData.Domain {
|
|
|
- Ip, err := s.gatewayGroupIpRep.GetGateWayGroupFirstIpByGatewayGroupId(ctx, webData.WafGatewayGroupId)
|
|
|
- if err != nil {
|
|
|
+ Ip, err := s.GetIp(ctx, webData.WafGatewayGroupId)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
}
|
|
|
// 异步任务:将域名添加到白名单
|
|
|
doMain, err := s.wafformatter.ConvertToWildcardDomain(ctx, req.WebForwardingData.Domain)
|