|
@@ -418,18 +418,21 @@ func (s *webForwardingService) AddWebForwarding(ctx context.Context, req *v1.Web
|
|
|
}
|
|
|
|
|
|
// 开启访问日志
|
|
|
- if webId != 0 {
|
|
|
- webConfigId, err := s.webForwardingRepository.GetWebConfigId(ctx, webId)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- err = s.EditLog(ctx, webConfigId)
|
|
|
+ err = s.EditLog(ctx, webId)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ // 开启CC
|
|
|
+ if req.WebForwardingData.CcConfig.IsOn {
|
|
|
+ err = s.EditCcConfig(ctx, webId, req.WebForwardingData.CcConfig)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
webModel := s.buildWebForwardingModel(&req.WebForwardingData, int(webId), require)
|
|
|
|
|
|
id, err := s.webForwardingRepository.AddWebForwarding(ctx, webModel)
|
|
@@ -567,6 +570,18 @@ func (s *webForwardingService) EditWebForwarding(ctx context.Context, req *v1.We
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ err = s.EditCcConfig(ctx, int64(oldData.CdnWebId), v1.CcConfigRequest{
|
|
|
+ IsOn: req.WebForwardingData.CcConfig.IsOn,
|
|
|
+ Level: req.WebForwardingData.CcConfig.Level,
|
|
|
+ Limit5s: req.WebForwardingData.CcConfig.Limit5s,
|
|
|
+ Limit60s: req.WebForwardingData.CcConfig.Limit60s,
|
|
|
+ Limit300s: req.WebForwardingData.CcConfig.Limit300s,
|
|
|
+ ThresholdMethod: req.WebForwardingData.CcConfig.ThresholdMethod,
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
// 将域名添加到白名单
|
|
|
webData, err := s.webForwardingRepository.GetWebForwarding(ctx, int64(req.WebForwardingData.Id))
|
|
|
if err != nil {
|
|
@@ -939,7 +954,11 @@ func (s *webForwardingService) WashDifferentIp(newIpList []string, oldIpList []s
|
|
|
return addedDenyIps, removedDenyIps
|
|
|
}
|
|
|
|
|
|
-func (s *webForwardingService) EditLog(ctx context.Context,webConfigId int64) error {
|
|
|
+func (s *webForwardingService) EditLog(ctx context.Context,webId int64) error {
|
|
|
+ webConfigId, err := s.webForwardingRepository.GetWebConfigId(ctx, webId)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
|
|
|
if err := s.cdn.EditWebLog(ctx, webConfigId,v1.WebLog{
|
|
|
IsPrior: false,
|
|
@@ -956,4 +975,33 @@ func (s *webForwardingService) EditLog(ctx context.Context,webConfigId int64) er
|
|
|
return err
|
|
|
}
|
|
|
return nil
|
|
|
+}
|
|
|
+
|
|
|
+func (s *webForwardingService) EditCcConfig(ctx context.Context,webId int64, req v1.CcConfigRequest) error {
|
|
|
+ webConfigId, err := s.webForwardingRepository.GetWebConfigId(ctx, webId)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ configThreshold := []struct{
|
|
|
+ MaxRequests int `json:"maxRequests"`
|
|
|
+ BlockSeconds int `json:"blockSeconds"`
|
|
|
+ PeriodSeconds int `json:"periodSeconds"`
|
|
|
+ }{
|
|
|
+ {MaxRequests: req.Limit5s},
|
|
|
+ {MaxRequests: req.Limit60s},
|
|
|
+ {MaxRequests: req.Limit300s},
|
|
|
+ }
|
|
|
+
|
|
|
+ if err := s.cdn.EditCcConfig(ctx, webConfigId, v1.CcConfig{
|
|
|
+ IsOn: req.IsOn,
|
|
|
+ ThresholdMethod: req.ThresholdMethod,
|
|
|
+ Thresholds: configThreshold,
|
|
|
+ Level: req.Level,
|
|
|
+ UseDefaultThresholds : true,
|
|
|
+ }); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
}
|