|
@@ -33,9 +33,7 @@ func NewGlobalLimitService(
|
|
required RequiredService,
|
|
required RequiredService,
|
|
parser ParserService,
|
|
parser ParserService,
|
|
host HostService,
|
|
host HostService,
|
|
- gateWayGroup GatewayGroupService,
|
|
|
|
hostRep repository.HostRepository,
|
|
hostRep repository.HostRepository,
|
|
- gateWayGroupRep repository.GatewayGroupRepository,
|
|
|
|
cdnService CdnService,
|
|
cdnService CdnService,
|
|
cdnRep repository.CdnRepository,
|
|
cdnRep repository.CdnRepository,
|
|
tcpforwardingRep repository.TcpforwardingRepository,
|
|
tcpforwardingRep repository.TcpforwardingRepository,
|
|
@@ -46,6 +44,7 @@ func NewGlobalLimitService(
|
|
tcpforwarding TcpforwardingService,
|
|
tcpforwarding TcpforwardingService,
|
|
udpForWarding UdpForWardingService,
|
|
udpForWarding UdpForWardingService,
|
|
webForWarding WebForwardingService,
|
|
webForWarding WebForwardingService,
|
|
|
|
+ gatewayIpRep repository.GatewayipRepository,
|
|
) GlobalLimitService {
|
|
) GlobalLimitService {
|
|
return &globalLimitService{
|
|
return &globalLimitService{
|
|
Service: service,
|
|
Service: service,
|
|
@@ -56,9 +55,7 @@ func NewGlobalLimitService(
|
|
required: required,
|
|
required: required,
|
|
parser: parser,
|
|
parser: parser,
|
|
host: host,
|
|
host: host,
|
|
- gateWayGroup: gateWayGroup,
|
|
|
|
hostRep: hostRep,
|
|
hostRep: hostRep,
|
|
- gateWayGroupRep: gateWayGroupRep,
|
|
|
|
cdnService: cdnService,
|
|
cdnService: cdnService,
|
|
cdnRep: cdnRep,
|
|
cdnRep: cdnRep,
|
|
tcpforwardingRep: tcpforwardingRep,
|
|
tcpforwardingRep: tcpforwardingRep,
|
|
@@ -69,6 +66,7 @@ func NewGlobalLimitService(
|
|
tcpforwarding: tcpforwarding,
|
|
tcpforwarding: tcpforwarding,
|
|
udpForWarding: udpForWarding,
|
|
udpForWarding: udpForWarding,
|
|
webForWarding: webForWarding,
|
|
webForWarding: webForWarding,
|
|
|
|
+ gatewayIpRep: gatewayIpRep,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -81,9 +79,7 @@ type globalLimitService struct {
|
|
required RequiredService
|
|
required RequiredService
|
|
parser ParserService
|
|
parser ParserService
|
|
host HostService
|
|
host HostService
|
|
- gateWayGroup GatewayGroupService
|
|
|
|
hostRep repository.HostRepository
|
|
hostRep repository.HostRepository
|
|
- gateWayGroupRep repository.GatewayGroupRepository
|
|
|
|
cdnService CdnService
|
|
cdnService CdnService
|
|
cdnRep repository.CdnRepository
|
|
cdnRep repository.CdnRepository
|
|
tcpforwardingRep repository.TcpforwardingRepository
|
|
tcpforwardingRep repository.TcpforwardingRepository
|
|
@@ -94,6 +90,7 @@ type globalLimitService struct {
|
|
tcpforwarding TcpforwardingService
|
|
tcpforwarding TcpforwardingService
|
|
udpForWarding UdpForWardingService
|
|
udpForWarding UdpForWardingService
|
|
webForWarding WebForwardingService
|
|
webForWarding WebForwardingService
|
|
|
|
+ gatewayIpRep repository.GatewayipRepository
|
|
}
|
|
}
|
|
|
|
|
|
func (s *globalLimitService) GetCdnUserId(ctx context.Context, uid int64) (int64, error) {
|
|
func (s *globalLimitService) GetCdnUserId(ctx context.Context, uid int64) (int64, error) {
|
|
@@ -169,6 +166,8 @@ func (s *globalLimitService) GlobalLimitRequire(ctx context.Context, req v1.Glob
|
|
res.NodeArea = configCount.NodeArea
|
|
res.NodeArea = configCount.NodeArea
|
|
res.ConfigMaxProtection = configCount.ConfigMaxProtection
|
|
res.ConfigMaxProtection = configCount.ConfigMaxProtection
|
|
res.IsBanUdp = configCount.IsBanUdp
|
|
res.IsBanUdp = configCount.IsBanUdp
|
|
|
|
+ res.HostId = req.HostId
|
|
|
|
+
|
|
domain, err := s.hostRep.GetDomainById(ctx, req.HostId)
|
|
domain, err := s.hostRep.GetDomainById(ctx, req.HostId)
|
|
if err != nil {
|
|
if err != nil {
|
|
return v1.GlobalLimitRequireResponse{}, err
|
|
return v1.GlobalLimitRequireResponse{}, err
|
|
@@ -226,18 +225,13 @@ func (s *globalLimitService) AddGlobalLimit(ctx context.Context, req v1.GlobalLi
|
|
}
|
|
}
|
|
|
|
|
|
g, gCtx := errgroup.WithContext(ctx)
|
|
g, gCtx := errgroup.WithContext(ctx)
|
|
- var gatewayGroupId int
|
|
|
|
var userId int64
|
|
var userId int64
|
|
var groupId int64
|
|
var groupId int64
|
|
g.Go(func() error {
|
|
g.Go(func() error {
|
|
- res, e := s.gateWayGroupRep.GetGatewayGroupWhereHostIdNull(gCtx, require)
|
|
|
|
|
|
+ e := s.gatewayIpRep.GetIpWhereHostIdNull(gCtx, require)
|
|
if e != nil {
|
|
if e != nil {
|
|
return fmt.Errorf("获取网关组失败: %w", e)
|
|
return fmt.Errorf("获取网关组失败: %w", e)
|
|
}
|
|
}
|
|
- if res == 0 {
|
|
|
|
- return fmt.Errorf("获取网关组失败")
|
|
|
|
- }
|
|
|
|
- gatewayGroupId = res
|
|
|
|
return nil
|
|
return nil
|
|
})
|
|
})
|
|
|
|
|
|
@@ -326,14 +320,6 @@ func (s *globalLimitService) AddGlobalLimit(ctx context.Context, req v1.GlobalLi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- err = s.gateWayGroupRep.EditGatewayGroup(ctx, &model.GatewayGroup{
|
|
|
|
- Id: gatewayGroupId,
|
|
|
|
- HostId: req.HostId,
|
|
|
|
- })
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
expiredAt, err := s.ConversionTimeUnix(ctx, require.ExpiredAt)
|
|
expiredAt, err := s.ConversionTimeUnix(ctx, require.ExpiredAt)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -353,7 +339,6 @@ func (s *globalLimitService) AddGlobalLimit(ctx context.Context, req v1.GlobalLi
|
|
Name: require.GlobalLimitName,
|
|
Name: require.GlobalLimitName,
|
|
RuleId: int(ruleId),
|
|
RuleId: int(ruleId),
|
|
GroupId: int(groupId),
|
|
GroupId: int(groupId),
|
|
- GatewayGroupId: gatewayGroupId,
|
|
|
|
CdnUid: int(userId),
|
|
CdnUid: int(userId),
|
|
Comment: req.Comment,
|
|
Comment: req.Comment,
|
|
ExpiredAt: expiredAt,
|
|
ExpiredAt: expiredAt,
|
|
@@ -374,7 +359,6 @@ func (s *globalLimitService) AddGlobalLimit(ctx context.Context, req v1.GlobalLi
|
|
Name: require.GlobalLimitName,
|
|
Name: require.GlobalLimitName,
|
|
RuleId: int(ruleId),
|
|
RuleId: int(ruleId),
|
|
GroupId: int(groupId),
|
|
GroupId: int(groupId),
|
|
- GatewayGroupId: gatewayGroupId,
|
|
|
|
CdnUid: int(userId),
|
|
CdnUid: int(userId),
|
|
Comment: req.Comment,
|
|
Comment: req.Comment,
|
|
State: true,
|
|
State: true,
|
|
@@ -386,6 +370,7 @@ func (s *globalLimitService) AddGlobalLimit(ctx context.Context, req v1.GlobalLi
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
func (s *globalLimitService) EditGlobalLimit(ctx context.Context, req v1.GlobalLimitRequest) error {
|
|
func (s *globalLimitService) EditGlobalLimit(ctx context.Context, req v1.GlobalLimitRequest) error {
|
|
require, err := s.GlobalLimitRequire(ctx, req)
|
|
require, err := s.GlobalLimitRequire(ctx, req)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -396,17 +381,21 @@ func (s *globalLimitService) EditGlobalLimit(ctx context.Context, req v1.GlobalL
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
- if data.GatewayGroupId == 0 {
|
|
|
|
- gatewayGroupId, e := s.gateWayGroupRep.GetGatewayGroupWhereHostIdNull(ctx, require)
|
|
|
|
- if e != nil {
|
|
|
|
- return fmt.Errorf("获取网关组失败: %w", e)
|
|
|
|
- }
|
|
|
|
- if gatewayGroupId == 0 {
|
|
|
|
- return fmt.Errorf("获取网关组失败")
|
|
|
|
|
|
+ // 如果不存在实例,创建
|
|
|
|
+ gatewayIp, err := s.gatewayIpRep.GetGatewayipByHostIdAll(ctx, int64(req.HostId))
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ if gatewayIp != nil {
|
|
|
|
+ err = s.gatewayIpRep.GetIpWhereHostIdNull(ctx, require)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return fmt.Errorf("获取网关组失败: %w", err)
|
|
}
|
|
}
|
|
- data.GatewayGroupId = gatewayGroupId
|
|
|
|
|
|
+ return nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
outputTimeStr, err := s.ConversionTime(ctx, require.ExpiredAt)
|
|
outputTimeStr, err := s.ConversionTime(ctx, require.ExpiredAt)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -430,7 +419,6 @@ func (s *globalLimitService) EditGlobalLimit(ctx context.Context, req v1.GlobalL
|
|
if err := s.globalLimitRepository.UpdateGlobalLimitByHostId(ctx, &model.GlobalLimit{
|
|
if err := s.globalLimitRepository.UpdateGlobalLimitByHostId(ctx, &model.GlobalLimit{
|
|
HostId: req.HostId,
|
|
HostId: req.HostId,
|
|
Comment: req.Comment,
|
|
Comment: req.Comment,
|
|
- GatewayGroupId: data.GatewayGroupId,
|
|
|
|
ExpiredAt: expiredAt,
|
|
ExpiredAt: expiredAt,
|
|
}); err != nil {
|
|
}); err != nil {
|
|
return err
|
|
return err
|
|
@@ -470,6 +458,7 @@ func (s *globalLimitService) DeleteGlobalLimit(ctx context.Context, req v1.Globa
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 黑白IP
|
|
BwIds, err := s.allowAndDenyRep.GetIpCountListId(ctx, int64(req.HostId))
|
|
BwIds, err := s.allowAndDenyRep.GetIpCountListId(ctx, int64(req.HostId))
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -530,10 +519,7 @@ func (s *globalLimitService) DeleteGlobalLimit(ctx context.Context, req v1.Globa
|
|
if err := s.globalLimitRepository.EditHostState(ctx, int64(req.HostId), false); err != nil {
|
|
if err := s.globalLimitRepository.EditHostState(ctx, int64(req.HostId), false); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- if err := s.gateWayGroupRep.EditGatewayGroup(ctx,&model.GatewayGroup{
|
|
|
|
- Id: oldData.GatewayGroupId,
|
|
|
|
- HostId: 0,
|
|
|
|
- }); err != nil {
|
|
|
|
|
|
+ if err := s.gatewayIpRep.CleanIPByHostId(ctx, []int64{int64(req.HostId)}); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|