|
@@ -2,6 +2,7 @@ package service
|
|
|
|
|
|
import (
|
|
import (
|
|
"context"
|
|
"context"
|
|
|
|
+ "encoding/json"
|
|
"fmt"
|
|
"fmt"
|
|
v1 "github.com/go-nunu/nunu-layout-advanced/api/v1"
|
|
v1 "github.com/go-nunu/nunu-layout-advanced/api/v1"
|
|
"github.com/go-nunu/nunu-layout-advanced/internal/model"
|
|
"github.com/go-nunu/nunu-layout-advanced/internal/model"
|
|
@@ -10,7 +11,6 @@ import (
|
|
"net"
|
|
"net"
|
|
"sort"
|
|
"sort"
|
|
"strconv"
|
|
"strconv"
|
|
- "strings"
|
|
|
|
)
|
|
)
|
|
|
|
|
|
type TcpforwardingService interface {
|
|
type TcpforwardingService interface {
|
|
@@ -30,6 +30,7 @@ func NewTcpforwardingService(
|
|
globalRep repository.GlobalLimitRepository,
|
|
globalRep repository.GlobalLimitRepository,
|
|
hostRep repository.HostRepository,
|
|
hostRep repository.HostRepository,
|
|
wafformatter WafFormatterService,
|
|
wafformatter WafFormatterService,
|
|
|
|
+ cdn CdnService,
|
|
) TcpforwardingService {
|
|
) TcpforwardingService {
|
|
return &tcpforwardingService{
|
|
return &tcpforwardingService{
|
|
Service: service,
|
|
Service: service,
|
|
@@ -40,6 +41,7 @@ func NewTcpforwardingService(
|
|
globalRep: globalRep,
|
|
globalRep: globalRep,
|
|
hostRep: hostRep,
|
|
hostRep: hostRep,
|
|
wafformatter: wafformatter,
|
|
wafformatter: wafformatter,
|
|
|
|
+ cdn: cdn,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -52,6 +54,7 @@ type tcpforwardingService struct {
|
|
globalRep repository.GlobalLimitRepository
|
|
globalRep repository.GlobalLimitRepository
|
|
hostRep repository.HostRepository
|
|
hostRep repository.HostRepository
|
|
wafformatter WafFormatterService
|
|
wafformatter WafFormatterService
|
|
|
|
+ cdn CdnService
|
|
}
|
|
}
|
|
|
|
|
|
func (s *tcpforwardingService) GetTcpforwarding(ctx context.Context, req v1.GetForwardingRequest) (v1.TcpForwardingDataRequest, error) {
|
|
func (s *tcpforwardingService) GetTcpforwarding(ctx context.Context, req v1.GetForwardingRequest) (v1.TcpForwardingDataRequest, error) {
|
|
@@ -87,18 +90,9 @@ func (s *tcpforwardingService) GetTcpforwarding(ctx context.Context, req v1.GetF
|
|
|
|
|
|
return v1.TcpForwardingDataRequest{
|
|
return v1.TcpForwardingDataRequest{
|
|
Id: tcpForwarding.Id,
|
|
Id: tcpForwarding.Id,
|
|
- WafTcpId: tcpForwarding.WafTcpId,
|
|
|
|
- Tag: tcpForwarding.Tag,
|
|
|
|
|
|
+ CdnWebId: tcpForwarding.CdnWebId,
|
|
Port: tcpForwarding.Port,
|
|
Port: tcpForwarding.Port,
|
|
Comment: tcpForwarding.Comment,
|
|
Comment: tcpForwarding.Comment,
|
|
- WafGatewayGroupId: tcpForwarding.WafGatewayGroupId,
|
|
|
|
- WafTcpLimitRuleId: tcpForwarding.TcpLimitRuleId,
|
|
|
|
- CcCount: tcpForwarding.CcCount,
|
|
|
|
- CcDuration: tcpForwarding.CcDuration,
|
|
|
|
- CcBlockCount: tcpForwarding.CcBlockCount,
|
|
|
|
- CcBlockDuration: tcpForwarding.CcBlockDuration,
|
|
|
|
- BackendProtocol: tcpForwarding.BackendProtocol,
|
|
|
|
- BackendTimeout: tcpForwarding.BackendTimeout,
|
|
|
|
BackendList: backend.BackendList,
|
|
BackendList: backend.BackendList,
|
|
AllowIpList: backend.AllowIpList,
|
|
AllowIpList: backend.AllowIpList,
|
|
DenyIpList: backend.DenyIpList,
|
|
DenyIpList: backend.DenyIpList,
|
|
@@ -106,58 +100,22 @@ func (s *tcpforwardingService) GetTcpforwarding(ctx context.Context, req v1.GetF
|
|
}, nil
|
|
}, nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *tcpforwardingService) require(ctx context.Context,req v1.GlobalRequire) (v1.GlobalRequire, error) {
|
|
|
|
- res, err := s.wafformatter.require(ctx, req, "tcp")
|
|
|
|
- if err != nil {
|
|
|
|
- return v1.GlobalRequire{}, err
|
|
|
|
- }
|
|
|
|
- return res, nil
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (s *tcpforwardingService) buildWafFormData(req *v1.TcpForwardingDataSend, require v1.GlobalRequire) map[string]interface{} {
|
|
|
|
- return map[string]interface{}{
|
|
|
|
- "waf_tcp_id": req.WafTcpId,
|
|
|
|
- "tag": require.Tag,
|
|
|
|
- "port": req.Port,
|
|
|
|
- "waf_gateway_group_id": require.WafGatewayGroupId,
|
|
|
|
- "waf_tcp_limit_id": require.LimitRuleId,
|
|
|
|
- "cc_count": req.CcCount,
|
|
|
|
- "cc_duration": req.CcDuration,
|
|
|
|
- "cc_block_count": req.CcBlockCount,
|
|
|
|
- "cc_block_duration": req.CcBlockDuration,
|
|
|
|
- "backend_protocol": req.BackendProtocol,
|
|
|
|
- "backend_timeout": req.BackendTimeout,
|
|
|
|
- "comment": req.Comment,
|
|
|
|
- "backend_list": req.BackendList,
|
|
|
|
- "allow_ip_list": req.AllowIpList,
|
|
|
|
- "deny_ip_list": req.DenyIpList,
|
|
|
|
- "access_rule": req.AccessRule,
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
|
|
-func (s *tcpforwardingService) buildTcpForwardingModel(req *v1.TcpForwardingDataRequest, ruleId int, require v1.GlobalRequire) *model.Tcpforwarding {
|
|
|
|
|
|
+func (s *tcpforwardingService) buildTcpForwardingModel(req *v1.TcpForwardingDataRequest, ruleId int, require RequireResponse) *model.Tcpforwarding {
|
|
return &model.Tcpforwarding{
|
|
return &model.Tcpforwarding{
|
|
HostId: require.HostId,
|
|
HostId: require.HostId,
|
|
- WafTcpId: ruleId,
|
|
|
|
|
|
+ CdnWebId: ruleId,
|
|
Port: req.Port,
|
|
Port: req.Port,
|
|
- Tag: require.Tag,
|
|
|
|
Comment: req.Comment,
|
|
Comment: req.Comment,
|
|
- TcpLimitRuleId: require.LimitRuleId,
|
|
|
|
- WafGatewayGroupId: require.WafGatewayGroupId,
|
|
|
|
- CcCount: req.CcCount,
|
|
|
|
- CcDuration: req.CcDuration,
|
|
|
|
- CcBlockCount: req.CcBlockCount,
|
|
|
|
- CcBlockDuration: req.CcBlockDuration,
|
|
|
|
- BackendProtocol: req.BackendProtocol,
|
|
|
|
- BackendTimeout: req.BackendTimeout,
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *tcpforwardingService) buildTcpRuleModel(reqData *v1.TcpForwardingDataRequest, require v1.GlobalRequire, localDbId int) *model.TcpForwardingRule {
|
|
|
|
|
|
+func (s *tcpforwardingService) buildTcpRuleModel(reqData *v1.TcpForwardingDataRequest, require RequireResponse, localDbId int, cdnOriginIds map[string]int64) *model.TcpForwardingRule {
|
|
return &model.TcpForwardingRule{
|
|
return &model.TcpForwardingRule{
|
|
Uid: require.Uid,
|
|
Uid: require.Uid,
|
|
HostId: require.HostId,
|
|
HostId: require.HostId,
|
|
TcpId: localDbId, // 关联到本地数据库的主记录 ID
|
|
TcpId: localDbId, // 关联到本地数据库的主记录 ID
|
|
|
|
+ CdnOriginIds: cdnOriginIds,
|
|
BackendList: reqData.BackendList,
|
|
BackendList: reqData.BackendList,
|
|
AllowIpList: reqData.AllowIpList,
|
|
AllowIpList: reqData.AllowIpList,
|
|
DenyIpList: reqData.DenyIpList,
|
|
DenyIpList: reqData.DenyIpList,
|
|
@@ -165,50 +123,73 @@ func (s *tcpforwardingService) buildTcpRuleModel(reqData *v1.TcpForwardingDataRe
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *tcpforwardingService) prepareWafData(ctx context.Context, req *v1.TcpForwardingRequest) (v1.GlobalRequire, map[string]interface{}, error) {
|
|
|
|
|
|
+func (s *tcpforwardingService) prepareWafData(ctx context.Context, req *v1.TcpForwardingRequest) (RequireResponse, v1.Website, error) {
|
|
// 1. 获取必要的全局信息
|
|
// 1. 获取必要的全局信息
|
|
- require, err := s.require(ctx, v1.GlobalRequire{
|
|
|
|
|
|
+ require, err := s.wafformatter.Require(ctx, v1.GlobalRequire{
|
|
HostId: req.HostId,
|
|
HostId: req.HostId,
|
|
Uid: req.Uid,
|
|
Uid: req.Uid,
|
|
Comment: req.TcpForwardingData.Comment,
|
|
Comment: req.TcpForwardingData.Comment,
|
|
})
|
|
})
|
|
if err != nil {
|
|
if err != nil {
|
|
- return v1.GlobalRequire{}, nil, err
|
|
|
|
- }
|
|
|
|
- if require.WafGatewayGroupId == 0 || require.LimitRuleId == 0 {
|
|
|
|
- return v1.GlobalRequire{}, nil, fmt.Errorf("请先配置实例")
|
|
|
|
- }
|
|
|
|
- // 2. 将字符串切片拼接成字符串,用于 WAF API
|
|
|
|
- backendListStr := strings.Join(req.TcpForwardingData.BackendList, "\n")
|
|
|
|
- allowIpListStr := strings.Join(req.TcpForwardingData.AllowIpList, "\n")
|
|
|
|
- denyIpListStr := strings.Join(req.TcpForwardingData.DenyIpList, "\n")
|
|
|
|
-
|
|
|
|
- // 3. 创建用于构建 WAF 表单的数据结构
|
|
|
|
- formDataBase := v1.TcpForwardingDataSend{
|
|
|
|
- Tag: require.Tag,
|
|
|
|
- WafTcpId: req.TcpForwardingData.WafTcpId,
|
|
|
|
- WafGatewayGroupId: require.WafGatewayGroupId,
|
|
|
|
- WafTcpLimitRuleId: require.LimitRuleId,
|
|
|
|
- Port: req.TcpForwardingData.Port,
|
|
|
|
- CcCount: req.TcpForwardingData.CcCount,
|
|
|
|
- CcDuration: req.TcpForwardingData.CcDuration,
|
|
|
|
- CcBlockCount: req.TcpForwardingData.CcBlockCount,
|
|
|
|
- CcBlockDuration: req.TcpForwardingData.CcBlockDuration,
|
|
|
|
- BackendProtocol: req.TcpForwardingData.BackendProtocol,
|
|
|
|
- BackendTimeout: req.TcpForwardingData.BackendTimeout,
|
|
|
|
- BackendList: backendListStr,
|
|
|
|
- AllowIpList: allowIpListStr,
|
|
|
|
- DenyIpList: denyIpListStr,
|
|
|
|
- AccessRule: req.TcpForwardingData.AccessRule,
|
|
|
|
- Comment: req.TcpForwardingData.Comment,
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 4. 构建 WAF 表单数据映射
|
|
|
|
- formData := s.buildWafFormData(&formDataBase, require)
|
|
|
|
|
|
+ return RequireResponse{}, v1.Website{}, err
|
|
|
|
+ }
|
|
|
|
+ if require.GatewayGroupId == 0 || require.Uid == 0 {
|
|
|
|
+ return RequireResponse{}, v1.Website{}, fmt.Errorf("请先配置实例")
|
|
|
|
+ }
|
|
|
|
+ var jsonData v1.TypeJSON
|
|
|
|
+ jsonData.IsOn = true
|
|
|
|
+ for _, v := range require.GatewayIps {
|
|
|
|
+ jsonData.Listen = append(jsonData.Listen, v1.Listen{
|
|
|
|
+ Protocol: "tcp",
|
|
|
|
+ Host: v,
|
|
|
|
+ Port: req.TcpForwardingData.Port,
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ byteData, err := json.Marshal(jsonData)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return RequireResponse{}, v1.Website{}, err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ formData := v1.Website{
|
|
|
|
+ UserId: int64(require.CdnUid),
|
|
|
|
+ Type: "tcpProxy",
|
|
|
|
+ Name: require.Tag,
|
|
|
|
+ Description: req.TcpForwardingData.Comment,
|
|
|
|
+ TcpJSON: byteData,
|
|
|
|
+ ServerGroupIds: []int64{int64(require.GroupId)},
|
|
|
|
+ UserPlanId: int64(require.RuleId),
|
|
|
|
+ NodeClusterId: 1,
|
|
|
|
+ }
|
|
return require, formData, nil
|
|
return require, formData, nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (s *tcpforwardingService) AddOrigin(ctx context.Context, req v1.TcpForwardingRequest) (map[string]int64, error) {
|
|
|
|
+ res := make(map[string]int64)
|
|
|
|
+ for _, v := range req.TcpForwardingData.BackendList {
|
|
|
|
+ ip, port, err := net.SplitHostPort(v)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+ addr := v1.Addr{
|
|
|
|
+ Protocol: "tcp",
|
|
|
|
+ Host: ip,
|
|
|
|
+ Port: port,
|
|
|
|
+ }
|
|
|
|
+ id, err := s.cdn.CreateOrigin(ctx, v1.Origin{
|
|
|
|
+ Addr: addr,
|
|
|
|
+ Weight: 10,
|
|
|
|
+ Description: req.TcpForwardingData.Comment,
|
|
|
|
+ IsOn: true,
|
|
|
|
+ TlsSecurityVerifyMode: "auto",
|
|
|
|
+ })
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+ res[v] = id
|
|
|
|
+ }
|
|
|
|
+ return res, nil
|
|
|
|
+}
|
|
func (s *tcpforwardingService) AddTcpForwarding(ctx context.Context, req *v1.TcpForwardingRequest) error {
|
|
func (s *tcpforwardingService) AddTcpForwarding(ctx context.Context, req *v1.TcpForwardingRequest) error {
|
|
require, formData, err := s.prepareWafData(ctx, req)
|
|
require, formData, err := s.prepareWafData(ctx, req)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -218,15 +199,26 @@ func (s *tcpforwardingService) AddTcpForwarding(ctx context.Context, req *v1.Tcp
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- wafTcpId, err := s.wafformatter.sendFormData(ctx, "admin/info/waf_tcp/new", "admin/new/waf_tcp", formData)
|
|
|
|
|
|
+
|
|
|
|
+ tcpId, err := s.cdn.CreateWebsite(ctx, formData)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
- gatewayIps, _, err := s.wafformatter.GetIp(ctx, require.WafGatewayGroupId)
|
|
|
|
|
|
+ // 添加源站
|
|
|
|
+ cdnOriginIds, err := s.AddOrigin(ctx, *req)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
+ // 添加源站到网站
|
|
|
|
+ for _, v := range cdnOriginIds {
|
|
|
|
+ err = s.cdn.AddServerOrigin(ctx, tcpId, v)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
// 异步任务:将IP添加到白名单
|
|
// 异步任务:将IP添加到白名单
|
|
var ips []string
|
|
var ips []string
|
|
if req.TcpForwardingData.BackendList != nil {
|
|
if req.TcpForwardingData.BackendList != nil {
|
|
@@ -241,7 +233,7 @@ func (s *tcpforwardingService) AddTcpForwarding(ctx context.Context, req *v1.Tcp
|
|
}
|
|
}
|
|
var accessRuleIps []string
|
|
var accessRuleIps []string
|
|
if req.TcpForwardingData.AllowIpList != nil {
|
|
if req.TcpForwardingData.AllowIpList != nil {
|
|
- for _, v := range gatewayIps {
|
|
|
|
|
|
+ for _, v := range require.GatewayIps {
|
|
for _, ip := range req.TcpForwardingData.AllowIpList {
|
|
for _, ip := range req.TcpForwardingData.AllowIpList {
|
|
if net.ParseIP(ip) != nil{
|
|
if net.ParseIP(ip) != nil{
|
|
accessRuleIps = append(accessRuleIps, ip)
|
|
accessRuleIps = append(accessRuleIps, ip)
|
|
@@ -252,13 +244,15 @@ func (s *tcpforwardingService) AddTcpForwarding(ctx context.Context, req *v1.Tcp
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- tcpModel := s.buildTcpForwardingModel(&req.TcpForwardingData, wafTcpId, require)
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ tcpModel := s.buildTcpForwardingModel(&req.TcpForwardingData, int(tcpId), require)
|
|
|
|
|
|
id, err := s.tcpforwardingRepository.AddTcpforwarding(ctx, tcpModel)
|
|
id, err := s.tcpforwardingRepository.AddTcpforwarding(ctx, tcpModel)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- TcpRuleModel := s.buildTcpRuleModel(&req.TcpForwardingData, require, id)
|
|
|
|
|
|
+ TcpRuleModel := s.buildTcpRuleModel(&req.TcpForwardingData, require, id, cdnOriginIds)
|
|
if _, err = s.tcpforwardingRepository.AddTcpforwardingIps(ctx, *TcpRuleModel); err != nil {
|
|
if _, err = s.tcpforwardingRepository.AddTcpforwardingIps(ctx, *TcpRuleModel); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
@@ -266,23 +260,25 @@ func (s *tcpforwardingService) AddTcpForwarding(ctx context.Context, req *v1.Tcp
|
|
}
|
|
}
|
|
|
|
|
|
func (s *tcpforwardingService) EditTcpForwarding(ctx context.Context, req *v1.TcpForwardingRequest) error {
|
|
func (s *tcpforwardingService) EditTcpForwarding(ctx context.Context, req *v1.TcpForwardingRequest) error {
|
|
- WafTcpId, err := s.tcpforwardingRepository.GetTcpforwardingWafTcpIdById(ctx, req.TcpForwardingData.Id)
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- req.TcpForwardingData.WafTcpId = WafTcpId
|
|
|
|
require, formData, err := s.prepareWafData(ctx, req)
|
|
require, formData, err := s.prepareWafData(ctx, req)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- _, err = s.wafformatter.sendFormData(ctx, "admin/info/waf_tcp/edit?&__goadmin_edit_pk="+strconv.Itoa(req.TcpForwardingData.WafTcpId), "admin/edit/waf_tcp", formData)
|
|
|
|
|
|
+ oldData, err := s.tcpforwardingRepository.GetTcpforwarding(ctx, int64(req.TcpForwardingData.Id))
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- gatewayIps, _, err := s.wafformatter.GetIp(ctx, require.WafGatewayGroupId)
|
|
|
|
|
|
+
|
|
|
|
+ //修改网站
|
|
|
|
+ editData := v1.EditWebsite{
|
|
|
|
+ Id: int64(oldData.CdnWebId),
|
|
|
|
+ TypeJSON: formData.TcpJSON,
|
|
|
|
+ }
|
|
|
|
+ err = s.cdn.EditServerType(ctx, editData,"tcp")
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
+
|
|
// 异步任务:将IP添加到白名单
|
|
// 异步任务:将IP添加到白名单
|
|
ipData, err := s.tcpforwardingRepository.GetTcpForwardingIpsByID(ctx, req.TcpForwardingData.Id)
|
|
ipData, err := s.tcpforwardingRepository.GetTcpForwardingIpsByID(ctx, req.TcpForwardingData.Id)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -300,20 +296,19 @@ func (s *tcpforwardingService) EditTcpForwarding(ctx context.Context, req *v1.Tc
|
|
}
|
|
}
|
|
|
|
|
|
if len(addedAllowIps) > 0 {
|
|
if len(addedAllowIps) > 0 {
|
|
- for _, v := range gatewayIps {
|
|
|
|
|
|
+ for _, v := range require.GatewayIps {
|
|
go s.wafformatter.PublishIpWhitelistTask(addedAllowIps, "add",v)
|
|
go s.wafformatter.PublishIpWhitelistTask(addedAllowIps, "add",v)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if len(removedAllowIps) > 0 {
|
|
if len(removedAllowIps) > 0 {
|
|
- for _, v := range gatewayIps {
|
|
|
|
|
|
+ for _, v := range require.GatewayIps {
|
|
go s.wafformatter.PublishIpWhitelistTask(removedAllowIps, "del",v)
|
|
go s.wafformatter.PublishIpWhitelistTask(removedAllowIps, "del",v)
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
tcpModel := s.buildTcpForwardingModel(&req.TcpForwardingData, req.TcpForwardingData.WafTcpId, require)
|
|
tcpModel := s.buildTcpForwardingModel(&req.TcpForwardingData, req.TcpForwardingData.WafTcpId, require)
|
|
tcpModel.Id = req.TcpForwardingData.Id
|
|
tcpModel.Id = req.TcpForwardingData.Id
|
|
- if err = s.tcpforwardingRepository.EditTcpforwarding(ctx, tcpModel); err != nil {
|
|
|
|
|
|
+ if err = s.tcpforwardingRepository.EditTcpforwarding(ctx, tcpModel); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
TcpRuleModel := s.buildTcpRuleModel(&req.TcpForwardingData, require, req.TcpForwardingData.Id)
|
|
TcpRuleModel := s.buildTcpRuleModel(&req.TcpForwardingData, require, req.TcpForwardingData.Id)
|
|
@@ -407,34 +402,34 @@ func (s *tcpforwardingService) GetTcpForwardingAllIpsByHostId(ctx context.Contex
|
|
return nil, groupErr
|
|
return nil, groupErr
|
|
}
|
|
}
|
|
res := make([]v1.TcpForwardingDataRequest, 0, len(ids))
|
|
res := make([]v1.TcpForwardingDataRequest, 0, len(ids))
|
|
- for r := range resChan {
|
|
|
|
- if r.Err != nil {
|
|
|
|
- return nil, fmt.Errorf("received error from goroutine for ID %d: %w", r.Id, r.Err)
|
|
|
|
- }
|
|
|
|
- if r.Forwarding == nil {
|
|
|
|
- return nil,fmt.Errorf("received nil forwarding from goroutine for ID %d", r.Id)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- dataReq := v1.TcpForwardingDataRequest{
|
|
|
|
- Id: r.Forwarding.Id,
|
|
|
|
- Port: r.Forwarding.Port,
|
|
|
|
- CcCount: r.Forwarding.CcCount,
|
|
|
|
- CcDuration: r.Forwarding.CcDuration,
|
|
|
|
- CcBlockCount: r.Forwarding.CcBlockCount,
|
|
|
|
- CcBlockDuration: r.Forwarding.CcBlockDuration,
|
|
|
|
- BackendProtocol: r.Forwarding.BackendProtocol,
|
|
|
|
- BackendTimeout: r.Forwarding.BackendTimeout,
|
|
|
|
- Comment: r.Forwarding.Comment,
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- if r.BackendRule != nil {
|
|
|
|
- dataReq.BackendList = r.BackendRule.BackendList
|
|
|
|
- dataReq.AllowIpList = r.BackendRule.AllowIpList
|
|
|
|
- dataReq.DenyIpList = r.BackendRule.DenyIpList
|
|
|
|
- dataReq.AccessRule = r.BackendRule.AccessRule
|
|
|
|
- }
|
|
|
|
- res = append(res, dataReq)
|
|
|
|
- }
|
|
|
|
|
|
+ //for r := range resChan {
|
|
|
|
+ // if r.Err != nil {
|
|
|
|
+ // return nil, fmt.Errorf("received error from goroutine for ID %d: %w", r.Id, r.Err)
|
|
|
|
+ // }
|
|
|
|
+ // if r.Forwarding == nil {
|
|
|
|
+ // return nil,fmt.Errorf("received nil forwarding from goroutine for ID %d", r.Id)
|
|
|
|
+ // }
|
|
|
|
+ //
|
|
|
|
+ // dataReq := v1.TcpForwardingDataRequest{
|
|
|
|
+ // Id: r.Forwarding.Id,
|
|
|
|
+ // Port: r.Forwarding.Port,
|
|
|
|
+ // CcCount: r.Forwarding.CcCount,
|
|
|
|
+ // CcDuration: r.Forwarding.CcDuration,
|
|
|
|
+ // CcBlockCount: r.Forwarding.CcBlockCount,
|
|
|
|
+ // CcBlockDuration: r.Forwarding.CcBlockDuration,
|
|
|
|
+ // BackendProtocol: r.Forwarding.BackendProtocol,
|
|
|
|
+ // BackendTimeout: r.Forwarding.BackendTimeout,
|
|
|
|
+ // Comment: r.Forwarding.Comment,
|
|
|
|
+ //
|
|
|
|
+ // }
|
|
|
|
+ // if r.BackendRule != nil {
|
|
|
|
+ // dataReq.BackendList = r.BackendRule.BackendList
|
|
|
|
+ // dataReq.AllowIpList = r.BackendRule.AllowIpList
|
|
|
|
+ // dataReq.DenyIpList = r.BackendRule.DenyIpList
|
|
|
|
+ // dataReq.AccessRule = r.BackendRule.AccessRule
|
|
|
|
+ // }
|
|
|
|
+ // res = append(res, dataReq)
|
|
|
|
+ //}
|
|
|
|
|
|
sort.Slice(res, func(i, j int) bool {
|
|
sort.Slice(res, func(i, j int) bool {
|
|
return res[i].Id > res[j].Id
|
|
return res[i].Id > res[j].Id
|