Просмотр исходного кода

feat(tcp): 重构 TCP转发功能

- 移除了与 WAF 相关的冗余代码
- 重构了 TCP 转发的添加和编辑逻辑
- 新增了创建网站和添加源站的功能
-优化了数据结构和接口设计
fusu 1 месяц назад
Родитель
Сommit
d786723398

+ 23 - 12
api/v1/cdn.go

@@ -44,14 +44,14 @@ type Website struct {
 	Type string `json:"type" form:"type"` // 类型:httpProxy(HTTP反向代理,一般CDN服务都选这个)、httpWeb(静态文件服务,只会从服务器上读取文件内容,不会转发到源站)、tcpProxy(TCP反向代理)、udpProxy(UDP反向代理)
 	Name string `json:"name" form:"name"` // 网站名称
 	Description string `json:"description" form:"description"` // 可选项,网站描述
-	ServerNamesJSON byte `json:"serverNamesJSON" form:"serverNamesJSON"` // 域名列表 json:server_names
-	HttpJSON byte `json:"httpJSON" form:"httpJSON"` // HTTP协议设置,当type为httpProxy或者httpWeb时填写 json:http_protocol
-	HttpsJSON byte `json:"httpsJSON" form:"httpsJSON"` // HTTPS协议设置,当type为httpProxy或者httpWeb时填写 json:https_protocol
-	TcpJSON byte `json:"tcpJSON" form:"tcpJSON"` // TCP协议设置,当type为tcpProxy时填写 json:tcp_protocol
-	TlsJSON byte `json:"tlsJSON" form:"tlsJSON"` // TLS协议设置,当type为tcpProxy时填写 json:tls_protocol
-	UdpJSON byte `json:"udpJSON" form:"udpJSON"` // UDP协议设置,当type为udpProxy时填写 json:udp_protocol
+	ServerNamesJSON []byte `json:"serverNamesJSON,omitempty" form:"serverNamesJSON"` // 域名列表 json:server_names
+	HttpJSON []byte `json:"httpJSON,omitempty" form:"httpJSON"` // HTTP协议设置,当type为httpProxy或者httpWeb时填写 json:http_protocol
+	HttpsJSON []byte `json:"httpsJSON,omitempty" form:"httpsJSON"` // HTTPS协议设置,当type为httpProxy或者httpWeb时填写 json:https_protocol
+	TcpJSON []byte `json:"tcpJSON,omitempty" form:"tcpJSON"` // TCP协议设置,当type为tcpProxy时填写 json:tcp_protocol
+	TlsJSON []byte `json:"tlsJSON,omitempty" form:"tlsJSON"` // TLS协议设置,当type为tcpProxy时填写 json:tls_protocol
+	UdpJSON []byte `json:"udpJSON,omitempty" form:"udpJSON"` // UDP协议设置,当type为udpProxy时填写 json:udp_protocol
 	WebId int64 `json:"webId" form:"webId"` // 可选项,Web配置ID,当type为httpProxy或者httpWeb时填写,可以通过 /HTTPWebService/createHTTPWeb 接口创建;如果你需要配置缓存等信息时需要在 HTTPWebService 接口操作=
-	ReverseProxyJSON byte `json:"reverseProxyJSON" form:"reverseProxyJSON"` // 反向代理(包含源站)配置引用,此项可以在创建网站后再设置 json:reverse_proxy_ref
+	ReverseProxyJSON []byte `json:"reverseProxyJSON,omitempty" form:"reverseProxyJSON"` // 反向代理(包含源站)配置引用,此项可以在创建网站后再设置 json:reverse_proxy_ref
 	ServerGroupIds []int64 `json:"serverGroupIds" form:"serverGroupIds"` // 可选项,所属网站分组ID列表
 	UserPlanId int64 `json:"userPlanId" form:"userPlanId"` // 可选项,套餐ID
 	NodeClusterId int64 `json:"nodeClusterId" form:"nodeClusterId"` // 所部署的集群ID
@@ -67,7 +67,12 @@ type TypeJSON struct {
 type Listen struct {
 	Protocol string `json:"protocol" form:"protocol"` // 协议类型:tcp、udp
 	Host string `json:"host" form:"host"` // 监听地址
-	Port int64 `json:"port" form:"port"` // 端口
+	Port string `json:"portRange" form:"portRange"` // 端口
+}
+
+type EditWebsite struct {
+	Id int64 `json:"id" form:"id"`
+	TypeJSON []byte `json:"typeJSON" form:"typeJSON"`
 }
 
 type ProxyJson struct {
@@ -78,15 +83,21 @@ type ProxyJson struct {
 type Origin struct {
 	OriginId int64 `json:"originId" form:"originId"`
 	Name string `json:"name" form:"name"` // 源站名称
-	Addr string `json:"addr" form:"addr"` // 源站地址
-	OssJSON byte `json:"ossJSON" form:"ossJSON"` // Oss配置 json:oss_config
+	Addr Addr `json:"addr" form:"addr"` // 源站地址
+	OssJSON []byte `json:"ossJSON" form:"ossJSON"` // Oss配置 json:oss_config
 	Description string `json:"description" form:"description"` // 备注
 	Weight int64 `json:"weight" form:"weight"` // 权重
 	IsOn bool `json:"isOn" form:"isOn"` // 是否开启
 	Domains []string `json:"domains" form:"domains"` // 域名
-	CertRefJSON byte `json:"certRefJSON" form:"certRefJSON"` // 证书引用,可选项
+	CertRefJSON []byte `json:"certRefJSON" form:"certRefJSON"` // 证书引用,可选项
 	Host string `json:"host" form:"host"` // 回源主机域名,可选项
 	FollowPort bool `json:"followPort" form:"followPort"` // 是否跟随端口,可选项
 	Http2Enabled bool `json:"http2Enabled" form:"http2Enabled"` //可选项,是否支持HTTP/2,只在HTTPS源站时生效
 	TlsSecurityVerifyMode string `json:"tlsSecurityVerifyMode" form:"tlsSecurityVerifyMode"` // // 安全校验模式:auto系统默认,force强校验,skip不校验
-}
+}
+
+type Addr struct {
+	Protocol string `json:"protocol" form:"protocol"` // 协议类型:tcp、udp
+	Host string `json:"host" form:"host"` // 监听地址
+	Port string `json:"portRange" form:"portRange"` // 端口
+}

+ 7 - 33
api/v1/tcpForwarding.go

@@ -1,42 +1,16 @@
 package v1
 
-type TcpForwardingDataSend struct {
-	WafTcpId          int    `form:"waf_tcp_id" json:"waf_tcp_id"`
-	Tag               string `form:"tag" json:"tag"`
-	Port              string    `form:"port" json:"port" binding:"required"`
-	WafGatewayGroupId int    `form:"waf_gateway_group_id" json:"waf_gateway_group_id"`
-	WafTcpLimitRuleId int    `form:"waf_tcp_limit_id" json:"waf_tcp_limit_id"`
-	CcCount           int    `form:"cc_count" json:"cc_count" default:"0"`
-	CcDuration        string `form:"cc_duration" json:"cc_duration" default:"0s"`
-	CcBlockCount      int    `form:"cc_block_count" json:"cc_block_count" default:"0"`
-	CcBlockDuration   string `form:"cc_block_duration" json:"cc_block_duration" default:"0s"`
-	BackendProtocol   string `form:"backend_protocol" json:"backend_protocol" default:"tcp"`
-	BackendTimeout    string `form:"backend_timeout" json:"backend_timeout" default:"5s"`
-	BackendList       string `form:"backend_list" json:"backend_list"`
-	AllowIpList       string `form:"allow_ip_list" json:"allow_ip_list"`
-	DenyIpList        string `form:"deny_ip_list" json:"deny_ip_list"`
-	AccessRule        string `form:"access_rule" json:"access_rule"`
-	Comment           string `form:"comment" json:"comment"`
-}
 
 
 type TcpForwardingDataRequest struct {
 	Id                int    `form:"id" json:"id"`
-	WafTcpId          int    `form:"waf_tcp_id" json:"waf_tcp_id"`
-	Tag               string `form:"tag" json:"tag"`
+	CdnWebId          int    `form:"cdnWebId" json:"cdnWebId"`
 	Port              string    `form:"port" json:"port" binding:"required"`
-	WafGatewayGroupId int    `form:"waf_gateway_group_id" json:"waf_gateway_group_id"`
-	WafTcpLimitRuleId int    `form:"waf_tcp_limit_id" json:"waf_tcp_limit_id"`
-	CcCount           int    `form:"cc_count" json:"cc_count" default:"0"`
-	CcDuration        string `form:"cc_duration" json:"cc_duration" default:"0s"`
-	CcBlockCount      int    `form:"cc_block_count" json:"cc_block_count" default:"0"`
-	CcBlockDuration   string `form:"cc_block_duration" json:"cc_block_duration" default:"0s"`
-	BackendProtocol   string `form:"backend_protocol" json:"backend_protocol" default:"tcp"`
-	BackendTimeout    string `form:"backend_timeout" json:"backend_timeout" default:"5s"`
-	BackendList       []string `form:"backend_list" json:"backend_list"`
-	AllowIpList       []string `form:"allow_ip_list" json:"allow_ip_list"`
-	DenyIpList        []string `form:"deny_ip_list" json:"deny_ip_list"`
-	AccessRule        string `form:"access_rule" json:"access_rule"`
+	GatewayGroupId 	  int    `form:"gatewayGroupId" json:"gatewayGroupId"`
+	BackendList       []string `form:"backendList" json:"backendList"`
+	AllowIpList       []string `form:"allowIpList" json:"allowIpList"`
+	DenyIpList        []string `form:"denyIpList" json:"denyIpList"`
+	AccessRule        string `form:"accessRule" json:"accessRule"`
 	Comment           string `form:"comment" json:"comment"`
 }
 
@@ -47,7 +21,7 @@ type DeleteTcpForwardingRequest struct {
 }
 
 type TcpForwardingRequest struct {
-	HostId            int `form:"host_id" json:"host_id" binding:"required"`
+	HostId            int `form:"hostId" json:"hostId" binding:"required"`
 	Uid               int `form:"uid" json:"uid" binding:"required"`
 	TcpForwardingData TcpForwardingDataRequest `form:"data" json:"data"`
 }

+ 0 - 3
api/v1/wafformatter.go

@@ -4,10 +4,7 @@ type GlobalRequire struct {
 	HostId            int    `form:"host_id" json:"host_id" binding:"required"`
 	Uid               int    `form:"uid" json:"uid" binding:"required"`
 	Comment           string `form:"comment" json:"comment" binding:"required"`
-	WafGatewayGroupId int    `form:"waf_gateway_group_id" json:"waf_gateway_group_id"`
-	LimitRuleId       int    `form:"limit_id" json:"limit_id"`
 	Domain            string `form:"domain" json:"domain"`
-	Tag               string `form:"tag" json:"tag" binding:"required"`
 }
 
 type GetForwardingRequest struct {

+ 4 - 4
cmd/server/wire/wire_gen.go

@@ -73,7 +73,10 @@ func NewWire(viperViper *viper.Viper, logger *log.Logger) (*app.App, func(), err
 	webLimitRepository := repository.NewWebLimitRepository(repositoryRepository)
 	webLimitService := service.NewWebLimitService(serviceService, webLimitRepository, requiredService, parserService, crawlerService, hostService)
 	webLimitHandler := handler.NewWebLimitHandler(handlerHandler, webLimitService)
-	tcpforwardingService := service.NewTcpforwardingService(serviceService, tcpforwardingRepository, parserService, requiredService, crawlerService, globalLimitRepository, hostRepository, wafFormatterService)
+	requestService := service.NewRequestService(serviceService)
+	cdnRepository := repository.NewCdnRepository(repositoryRepository)
+	cdnService := service.NewCdnService(serviceService, viperViper, requestService, cdnRepository)
+	tcpforwardingService := service.NewTcpforwardingService(serviceService, tcpforwardingRepository, parserService, requiredService, crawlerService, globalLimitRepository, hostRepository, wafFormatterService, cdnService)
 	tcpforwardingHandler := handler.NewTcpforwardingHandler(handlerHandler, tcpforwardingService)
 	udpForWardingService := service.NewUdpForWardingService(serviceService, udpForWardingRepository, requiredService, parserService, crawlerService, globalLimitRepository, hostRepository, wafFormatterService)
 	udpForWardingHandler := handler.NewUdpForWardingHandler(handlerHandler, udpForWardingService)
@@ -83,10 +86,7 @@ func NewWire(viperViper *viper.Viper, logger *log.Logger) (*app.App, func(), err
 	udpLimitRepository := repository.NewUdpLimitRepository(repositoryRepository)
 	udpLimitService := service.NewUdpLimitService(serviceService, udpLimitRepository, requiredService, crawlerService, parserService, hostService)
 	udpLimitHandler := handler.NewUdpLimitHandler(handlerHandler, udpLimitService)
-	requestService := service.NewRequestService(serviceService)
 	gatewayGroupService := service.NewGatewayGroupService(serviceService, gatewayGroupRepository, requiredService, parserService, requestService)
-	cdnRepository := repository.NewCdnRepository(repositoryRepository)
-	cdnService := service.NewCdnService(serviceService, viperViper, requestService, cdnRepository)
 	globalLimitService := service.NewGlobalLimitService(serviceService, globalLimitRepository, duedateService, crawlerService, viperViper, requiredService, parserService, hostService, tcpLimitService, udpLimitService, webLimitService, gatewayGroupService, hostRepository, gatewayGroupRepository, cdnService, cdnRepository)
 	globalLimitHandler := handler.NewGlobalLimitHandler(handlerHandler, globalLimitService)
 	adminRepository := repository.NewAdminRepository(repositoryRepository)

+ 3 - 10
internal/model/tcpforwarding.go

@@ -8,17 +8,8 @@ import (
 type Tcpforwarding struct {
 	Id                   int `gorm:"primary"`
 	HostId               int `gorm:"not null"`
-	WafTcpId            int `gorm:"not null"`
-	Tag                  string `gorm:"null"`
+	CdnWebId            int `gorm:"not null"`
 	Port                 string `gorm:"not null"`
-	WafGatewayGroupId    int `gorm:"null"`
-	TcpLimitRuleId       int `gorm:"not null"`
-	CcCount              int `gorm:"default:0"`
-	CcDuration           string `gorm:"default:0s"`
-	CcBlockCount         int `gorm:"default:0"`
-	CcBlockDuration      string `gorm:"null"`
-	BackendProtocol      string `gorm:"default:tcp"`
-	BackendTimeout       string `gorm:"null"`
 	Comment              string `gorm:"null"`
 	CreatedAt            time.Time
 	UpdatedAt            time.Time
@@ -34,6 +25,7 @@ type TcpForwardingRule struct {
 	Uid         int                `bson:"uid" json:"uid"`
 	HostId      int                `bson:"host_id" json:"host_id"`
 	TcpId       int                `bson:"tcp_id" json:"tcp_id"`
+	CdnOriginIds map[string]int64       	`bson:"cdn_origin_ids" json:"cdn_origin_ids"`
 	BackendList []string           `bson:"backend_list" json:"backend_list"`
 	AllowIpList []string           `bson:"allow_ip_list" json:"allow_ip_list"`
 	DenyIpList  []string           `bson:"deny_ip_list" json:"deny_ip_list"`
@@ -42,6 +34,7 @@ type TcpForwardingRule struct {
 	UpdatedAt   time.Time          `bson:"updated_at" json:"updated_at"`
 }
 
+
 func (m *TcpForwardingRule) CollectionName() string {
 	return "tcp_forwarding_rules"
 }

+ 51 - 5
internal/service/cdn.go

@@ -7,6 +7,7 @@ import (
 	v1 "github.com/go-nunu/nunu-layout-advanced/api/v1"
 	"github.com/go-nunu/nunu-layout-advanced/internal/repository"
 	"github.com/spf13/viper"
+	"strings"
 )
 
 type CdnService interface {
@@ -16,9 +17,11 @@ type CdnService interface {
 	BindPlan(ctx context.Context, req v1.Plan) (int64, error)
 	RenewPlan(ctx context.Context, req v1.RenewalPlan) error
 	CreateWebsite(ctx context.Context, req v1.Website) (int64, error)
+	EditServerType(ctx context.Context, req v1.EditWebsite,apiType string) error
 	EditProtocol(ctx context.Context, req v1.ProxyJson, action string) error
 	CreateOrigin(ctx context.Context, req v1.Origin) (int64, error)
 	EditOrigin(ctx context.Context, req v1.Origin) error
+	AddServerOrigin(ctx context.Context, serverId int64, originId int64) error
 }
 
 func NewCdnService(
@@ -306,19 +309,19 @@ func (s *cdnService) CreateWebsite(ctx context.Context, req v1.Website) (int64,
 		return 0, err
 	}
 	type DataStr struct {
-		WebsiteId int64 `json:"websiteId" form:"websiteId"`
+		ServerId int64 `json:"serverId" form:"serverId"`
 	}
 	var res v1.GeneralResponse[DataStr]
 	if err := json.Unmarshal(resBody, &res); err != nil {
 		return 0, fmt.Errorf("反序列化响应 JSON 失败 (内容: %s): %w", string(resBody), err)
 	}
 	if res.Code != 200 {
-		return 0, fmt.Errorf("API 错误: code %d, msg '%s'", res.Code, res.Message)
+		return 0, fmt.Errorf("创建网站API 错误: code %d, msg '%s'", res.Code, res.Message)
 	}
-	if res.Data.WebsiteId == 0 {
+	if res.Data.ServerId == 0 {
 		return 0, fmt.Errorf("创建网站失败")
 	}
-	return res.Data.WebsiteId, nil
+	return res.Data.ServerId, nil
 }
 
 func (s *cdnService) EditProtocol(ctx context.Context, req v1.ProxyJson, action string) error {
@@ -387,7 +390,7 @@ func (s *cdnService) CreateOrigin(ctx context.Context, req v1.Origin) (int64, er
 		return 0, fmt.Errorf("反序列化响应 JSON 失败 (内容: %s): %w", string(resBody), err)
 	}
 	if res.Code != 200 {
-		return 0, fmt.Errorf("API 错误: code %d, msg '%s'", res.Code, res.Message)
+		return 0, fmt.Errorf("添加源站API 错误: code %d, msg '%s'", res.Code, res.Message)
 	}
 	if res.Data.OriginId == 0 {
 		return 0, fmt.Errorf("创建源站失败")
@@ -395,6 +398,28 @@ func (s *cdnService) CreateOrigin(ctx context.Context, req v1.Origin) (int64, er
 	return res.Data.OriginId, nil
 }
 
+func (s *cdnService) EditServerType(ctx context.Context, req v1.EditWebsite,apiType string) error {
+	typeName := apiType + "JSON"
+	formData := map[string]interface{}{
+		"serverId": req.Id,
+		typeName: req.TypeJSON,
+	}
+	apiUrl := s.Url + "ServerService/updateServer" + strings.ToUpper(apiType)
+	resBody, err := s.sendDataWithTokenRetry(ctx, formData, apiUrl)
+	if err != nil {
+		return err
+	}
+	var res v1.GeneralResponse[any]
+	if err := json.Unmarshal(resBody, &res); err != nil {
+		return fmt.Errorf("反序列化响应 JSON 失败 (内容: %s): %w", string(resBody), err)
+	}
+	if res.Code != 200 {
+		return fmt.Errorf("API 错误: code %d, msg '%s'", res.Code, res.Message)
+	}
+	return nil
+
+}
+
 func (s *cdnService) EditOrigin(ctx context.Context, req v1.Origin) error {
 	formData := map[string]interface{}{
 		"originId":                req.OriginId,
@@ -424,4 +449,25 @@ func (s *cdnService) EditOrigin(ctx context.Context, req v1.Origin) error {
 		return fmt.Errorf("API 错误: code %d, msg '%s'", res.Code, res.Message)
 	}
 	return nil
+}
+
+func (s *cdnService) AddServerOrigin(ctx context.Context, serverId int64, originId int64) error  {
+	formData := map[string]interface{}{
+		"serverId": serverId,
+		"originId": originId,
+		"isPrimary": true,
+	}
+	apiUrl := s.Url + "ServerService/addServerOrigin"
+	resBody, err := s.sendDataWithTokenRetry(ctx, formData, apiUrl) // 使用封装后的方法
+	if err != nil {
+		return err
+	}
+	var res v1.GeneralResponse[any]
+	if err := json.Unmarshal(resBody, &res); err != nil {
+		return fmt.Errorf("反序列化响应 JSON 失败 (内容: %s): %w", string(resBody), err)
+	}
+	if res.Code != 200 {
+		return fmt.Errorf("API 错误: code %d, msg '%s'", res.Code, res.Message)
+	}
+	return nil
 }

+ 124 - 129
internal/service/tcpforwarding.go

@@ -2,6 +2,7 @@ package service
 
 import (
 	"context"
+	"encoding/json"
 	"fmt"
 	v1 "github.com/go-nunu/nunu-layout-advanced/api/v1"
 	"github.com/go-nunu/nunu-layout-advanced/internal/model"
@@ -10,7 +11,6 @@ import (
 	"net"
 	"sort"
 	"strconv"
-	"strings"
 )
 
 type TcpforwardingService interface {
@@ -30,6 +30,7 @@ func NewTcpforwardingService(
 	globalRep repository.GlobalLimitRepository,
 	hostRep repository.HostRepository,
 	wafformatter WafFormatterService,
+	cdn CdnService,
 ) TcpforwardingService {
 	return &tcpforwardingService{
 		Service:                 service,
@@ -40,6 +41,7 @@ func NewTcpforwardingService(
 		globalRep:               globalRep,
 		hostRep:                 hostRep,
 		wafformatter:            wafformatter,
+		cdn:                     cdn,
 	}
 }
 
@@ -52,6 +54,7 @@ type tcpforwardingService struct {
 	globalRep               repository.GlobalLimitRepository
 	hostRep      repository.HostRepository
 	wafformatter WafFormatterService
+	cdn CdnService
 }
 
 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{
 		Id:               tcpForwarding.Id,
-		WafTcpId:         tcpForwarding.WafTcpId,
-		Tag:              tcpForwarding.Tag,
+		CdnWebId:         	  tcpForwarding.CdnWebId,
 		Port:             tcpForwarding.Port,
 		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,
 		AllowIpList:       backend.AllowIpList,
 		DenyIpList:        backend.DenyIpList,
@@ -106,58 +100,22 @@ func (s *tcpforwardingService) GetTcpforwarding(ctx context.Context, req v1.GetF
 	}, 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{
 		HostId:  require.HostId,
-		WafTcpId: ruleId,
+		CdnWebId: ruleId,
 		Port:    req.Port,
-		Tag:     require.Tag,
 		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{
 		Uid:         require.Uid,
 		HostId:      require.HostId,
 		TcpId:       localDbId, // 关联到本地数据库的主记录 ID
+		CdnOriginIds: cdnOriginIds,
 		BackendList: reqData.BackendList,
 		AllowIpList: reqData.AllowIpList,
 		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. 获取必要的全局信息
-	require, err := s.require(ctx, v1.GlobalRequire{
+	require, err := s.wafformatter.Require(ctx, v1.GlobalRequire{
 		HostId:  req.HostId,
 		Uid:     req.Uid,
 		Comment: req.TcpForwardingData.Comment,
 	})
 	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
 }
 
+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 {
 	require, formData, err := s.prepareWafData(ctx, req)
 	if err != nil {
@@ -218,15 +199,26 @@ func (s *tcpforwardingService) AddTcpForwarding(ctx context.Context, req *v1.Tcp
 	if err != nil {
 		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 {
 		return err
 	}
 
-	gatewayIps, _, err := s.wafformatter.GetIp(ctx, require.WafGatewayGroupId)
+	// 添加源站
+	cdnOriginIds, err := s.AddOrigin(ctx, *req)
 	if err != nil {
 		return err
 	}
+	// 添加源站到网站
+	for _, v := range cdnOriginIds {
+		err = s.cdn.AddServerOrigin(ctx, tcpId, v)
+		if err != nil {
+			return err
+		}
+	}
+
+
 	// 异步任务:将IP添加到白名单
 	var ips []string
 	if req.TcpForwardingData.BackendList != nil {
@@ -241,7 +233,7 @@ func (s *tcpforwardingService) AddTcpForwarding(ctx context.Context, req *v1.Tcp
 	}
 	var accessRuleIps []string
 	if req.TcpForwardingData.AllowIpList != nil {
-		for _, v := range gatewayIps {
+		for _, v := range require.GatewayIps {
 			for _, ip := range req.TcpForwardingData.AllowIpList {
 				if net.ParseIP(ip) != nil{
 					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)
 	if err != nil {
 		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 {
 		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 {
-	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)
 	if err != nil {
 		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 {
 		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 {
 		return err
 	}
+
 	// 异步任务:将IP添加到白名单
 	ipData, err := s.tcpforwardingRepository.GetTcpForwardingIpsByID(ctx, req.TcpForwardingData.Id)
 	if err != nil {
@@ -300,20 +296,19 @@ func (s *tcpforwardingService) EditTcpForwarding(ctx context.Context, req *v1.Tc
 	}
 
 	if len(addedAllowIps) > 0 {
-		for _, v := range gatewayIps {
+		for _, v := range require.GatewayIps {
 			go s.wafformatter.PublishIpWhitelistTask(addedAllowIps, "add",v)
 		}
 	}
 	if len(removedAllowIps) > 0 {
-		for _, v := range gatewayIps {
+		for _, v := range require.GatewayIps {
 			go s.wafformatter.PublishIpWhitelistTask(removedAllowIps, "del",v)
 		}
-
 	}
 
 	tcpModel := s.buildTcpForwardingModel(&req.TcpForwardingData, req.TcpForwardingData.WafTcpId, require)
 	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
 	}
 	TcpRuleModel := s.buildTcpRuleModel(&req.TcpForwardingData, require, req.TcpForwardingData.Id)
@@ -407,34 +402,34 @@ func (s *tcpforwardingService) GetTcpForwardingAllIpsByHostId(ctx context.Contex
 		return nil, groupErr
 	}
 	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 {
 		return res[i].Id > res[j].Id

+ 154 - 174
internal/service/udpforwarding.go

@@ -7,10 +7,7 @@ import (
 	"github.com/go-nunu/nunu-layout-advanced/internal/model"
 	"github.com/go-nunu/nunu-layout-advanced/internal/repository"
 	"golang.org/x/sync/errgroup"
-	"net"
 	"sort"
-	"strconv"
-	"strings"
 )
 
 type UdpForWardingService interface {
@@ -55,13 +52,6 @@ type udpForWardingService struct {
 }
 
 
-func (s *udpForWardingService) require(ctx context.Context,req v1.GlobalRequire) (v1.GlobalRequire, error) {
-	res, err := s.wafformatter.require(ctx, req, "udp")
-	if err != nil {
-		return v1.GlobalRequire{}, err
-	}
-	return res, nil
-}
 func (s *udpForWardingService) GetUdpForWarding(ctx context.Context,req v1.GetForwardingRequest) (v1.UdpForwardingDataRequest, error) {
 	var udpForWarding model.UdpForWarding
 	var backend model.UdpForwardingRule
@@ -119,10 +109,7 @@ func (s *udpForWardingService) GetUdpForWarding(ctx context.Context,req v1.GetFo
 func (s *udpForWardingService) buildWafFormData(req *v1.UdpForwardingDataSend, require v1.GlobalRequire) map[string]interface{} {
 	return map[string]interface{}{
 		"waf_udp_id":           req.WafUdpId,
-		"tag":                  require.Tag,
 		"port":                 req.Port,
-		"waf_gateway_group_id": require.WafGatewayGroupId,
-		"waf_udp_limit_id":     require.LimitRuleId,
 		"cc_packet_count":      req.CcPacketCount,
 		"cc_packet_duration":   req.CcPacketDuration,
 		"cc_packet_block_count": req.CcBlockCount,
@@ -144,10 +131,7 @@ func (s *udpForWardingService) buildUdpForwardingModel(req *v1.UdpForwardingData
 	return &model.UdpForWarding{
 		HostId: 			  require.HostId,
 		WafUdpId:             ruleId,
-		Tag:                  require.Tag,
 		Port:                 req.Port,
-		WafGatewayGroupId:    require.WafGatewayGroupId,
-		UdpLimitRuleId:       require.LimitRuleId,
 		CcPacketCount:        req.CcPacketCount,
 		CcPacketDuration:     req.CcPacketDuration,
 		CcPacketBlockCount:   req.CcBlockCount,
@@ -175,171 +159,167 @@ func (s *udpForWardingService) buildUdpRuleModel(reqData *v1.UdpForwardingDataRe
 
 func (s *udpForWardingService) prepareWafData(ctx context.Context, req *v1.UdpForwardingRequest) (v1.GlobalRequire, map[string]interface{}, error) {
 	// 1. 获取必要的全局信息
-	require, err := s.require(ctx, v1.GlobalRequire{
-		HostId:  req.HostId,
-		Uid:     req.Uid,
-		Comment: req.UdpForwardingData.Comment,
-	})
-	if err != nil {
-		return v1.GlobalRequire{}, nil, err
-	}
-
-	if require.LimitRuleId == 0 || require.WafGatewayGroupId == 0 {
-		return v1.GlobalRequire{}, nil, fmt.Errorf("请先配置实例")
-	}
-
-	// 2. 将字符串切片拼接成字符串,用于 WAF API
-	backendListStr := strings.Join(req.UdpForwardingData.BackendList, "\n")
-	allowIpListStr := strings.Join(req.UdpForwardingData.AllowIpList, "\n")
-	denyIpListStr := strings.Join(req.UdpForwardingData.DenyIpList, "\n")
-
-	PortInt, err := strconv.Atoi(req.UdpForwardingData.Port)
-	if err != nil {
-		return v1.GlobalRequire{}, nil, err
-	}
-
-	// 3. 创建用于构建 WAF 表单的数据结构
-	formDataBase := v1.UdpForwardingDataSend{
-		Tag:               require.Tag,
-		WafUdpId:          req.UdpForwardingData.WafUdpId,
-		WafGatewayGroupId: require.WafGatewayGroupId,
-		WafUdpLimitId: require.LimitRuleId,
-		Port:              PortInt,
-		CcPacketCount:     req.UdpForwardingData.CcPacketCount,
-		CcPacketDuration:  req.UdpForwardingData.CcPacketDuration,
-		CcPacketBlockCount: req.UdpForwardingData.CcBlockCount,
-		CcPacketBlockDuration: req.UdpForwardingData.CcBlockDuration,
-		CcCount:           req.UdpForwardingData.CcCount,
-		CcDuration:        req.UdpForwardingData.CcDuration,
-		CcBlockCount:      req.UdpForwardingData.CcBlockCount,
-		CcBlockDuration:   req.UdpForwardingData.CcBlockDuration,
-		SessionTimeout:    req.UdpForwardingData.SessionTimeout,
-		BackendList:       backendListStr,
-		AllowIpList:       allowIpListStr,
-		DenyIpList:        denyIpListStr,
-		AccessRule:        req.UdpForwardingData.AccessRule,
-		Comment:           req.UdpForwardingData.Comment,
-	}
-
-	// 4. 构建 WAF 表单数据映射
-	formData := s.buildWafFormData(&formDataBase, require)
-
-	return require, formData, nil
+	//require, err := s.require(ctx, v1.GlobalRequire{
+	//	HostId:  req.HostId,
+	//	Uid:     req.Uid,
+	//	Comment: req.UdpForwardingData.Comment,
+	//})
+	//if err != nil {
+	//	return v1.GlobalRequire{}, nil, err
+	//}
+	//
+	//if require.LimitRuleId == 0 || require.WafGatewayGroupId == 0 {
+	//	return v1.GlobalRequire{}, nil, fmt.Errorf("请先配置实例")
+	//}
+	//
+	//// 2. 将字符串切片拼接成字符串,用于 WAF API
+	//backendListStr := strings.Join(req.UdpForwardingData.BackendList, "\n")
+	//allowIpListStr := strings.Join(req.UdpForwardingData.AllowIpList, "\n")
+	//denyIpListStr := strings.Join(req.UdpForwardingData.DenyIpList, "\n")
+	//
+	//PortInt, err := strconv.Atoi(req.UdpForwardingData.Port)
+	//if err != nil {
+	//	return v1.GlobalRequire{}, nil, err
+	//}
+	//
+	//// 3. 创建用于构建 WAF 表单的数据结构
+	//formDataBase := v1.UdpForwardingDataSend{
+	//	Tag:               require.Tag,
+	//	WafUdpId:          req.UdpForwardingData.WafUdpId,
+	//	WafGatewayGroupId: require.WafGatewayGroupId,
+	//	WafUdpLimitId: require.LimitRuleId,
+	//	Port:              PortInt,
+	//	CcPacketCount:     req.UdpForwardingData.CcPacketCount,
+	//	CcPacketDuration:  req.UdpForwardingData.CcPacketDuration,
+	//	CcPacketBlockCount: req.UdpForwardingData.CcBlockCount,
+	//	CcPacketBlockDuration: req.UdpForwardingData.CcBlockDuration,
+	//	CcCount:           req.UdpForwardingData.CcCount,
+	//	CcDuration:        req.UdpForwardingData.CcDuration,
+	//	CcBlockCount:      req.UdpForwardingData.CcBlockCount,
+	//	CcBlockDuration:   req.UdpForwardingData.CcBlockDuration,
+	//	SessionTimeout:    req.UdpForwardingData.SessionTimeout,
+	//	BackendList:       backendListStr,
+	//	AllowIpList:       allowIpListStr,
+	//	DenyIpList:        denyIpListStr,
+	//	AccessRule:        req.UdpForwardingData.AccessRule,
+	//	Comment:           req.UdpForwardingData.Comment,
+	//}
+	//
+	//// 4. 构建 WAF 表单数据映射
+	//formData := s.buildWafFormData(&formDataBase, require)
+
+	return v1.GlobalRequire{}, nil, nil
 }
 
 func (s *udpForWardingService) AddUdpForwarding(ctx context.Context, req *v1.UdpForwardingRequest) error {
-	require, formData, err := s.prepareWafData(ctx, req)
-	if err != nil {
-		return err
-	}
-	err = s.wafformatter.validateWafPortCount(ctx, require.HostId)
-	if err != nil {
-		return err
-	}
-	wafUdpId, err := s.wafformatter.sendFormData(ctx, "admin/info/waf_udp/new", "admin/new/waf_udp", formData)
-	if err != nil {
-		return err
-	}
-
-	gatewayIps, _, err := s.wafformatter.GetIp(ctx, require.WafGatewayGroupId)
-	if err != nil {
-		return err
-	}
-	// 异步任务:将IP添加到白名单
-	var ips []string
-	if req.UdpForwardingData.BackendList != nil {
-		for _, v := range req.UdpForwardingData.BackendList {
-			ip, _, err := net.SplitHostPort(v)
-			if err != nil {
-				return err
-			}
-			ips = append(ips, ip)
-		}
-		go s.wafformatter.PublishIpWhitelistTask(ips, "add","")
-	}
-	var accessRuleIps []string
-	if req.UdpForwardingData.AllowIpList != nil {
-		for _, v := range gatewayIps {
-			for _, ip := range req.UdpForwardingData.AllowIpList {
-				if net.ParseIP(ip) != nil {
-					accessRuleIps = append(accessRuleIps, ip)
-				}
-			}
-			go s.wafformatter.PublishIpWhitelistTask(accessRuleIps, "add",v)
-		}
-	}
-
-
-	udpModel := s.buildUdpForwardingModel(&req.UdpForwardingData, wafUdpId, require)
-
-	id, err := s.udpForWardingRepository.AddUdpForwarding(ctx, udpModel)
-	if err != nil {
-		return err
-	}
-	udpRuleModel := s.buildUdpRuleModel(&req.UdpForwardingData, require, id)
-	if _, err = s.udpForWardingRepository.AddUdpForwardingIps(ctx, *udpRuleModel); err != nil {
-		return err
-	}
+	//require, formData, err := s.prepareWafData(ctx, req)
+	//if err != nil {
+	//	return err
+	//}
+	//err = s.wafformatter.validateWafPortCount(ctx, require.HostId)
+	//if err != nil {
+	//	return err
+	//}
+	//
+	//gatewayIps, _, err := s.wafformatter.GetIp(ctx, require.WafGatewayGroupId)
+	//if err != nil {
+	//	return err
+	//}
+	//// 异步任务:将IP添加到白名单
+	//var ips []string
+	//if req.UdpForwardingData.BackendList != nil {
+	//	for _, v := range req.UdpForwardingData.BackendList {
+	//		ip, _, err := net.SplitHostPort(v)
+	//		if err != nil {
+	//			return err
+	//		}
+	//		ips = append(ips, ip)
+	//	}
+	//	go s.wafformatter.PublishIpWhitelistTask(ips, "add","")
+	//}
+	//var accessRuleIps []string
+	//if req.UdpForwardingData.AllowIpList != nil {
+	//	for _, v := range gatewayIps {
+	//		for _, ip := range req.UdpForwardingData.AllowIpList {
+	//			if net.ParseIP(ip) != nil {
+	//				accessRuleIps = append(accessRuleIps, ip)
+	//			}
+	//		}
+	//		go s.wafformatter.PublishIpWhitelistTask(accessRuleIps, "add",v)
+	//	}
+	//}
+	//
+	//
+	//udpModel := s.buildUdpForwardingModel(&req.UdpForwardingData, wafUdpId, require)
+	//
+	//id, err := s.udpForWardingRepository.AddUdpForwarding(ctx, udpModel)
+	//if err != nil {
+	//	return err
+	//}
+	//udpRuleModel := s.buildUdpRuleModel(&req.UdpForwardingData, require, id)
+	//if _, err = s.udpForWardingRepository.AddUdpForwardingIps(ctx, *udpRuleModel); err != nil {
+	//	return err
+	//}
 	return nil
 }
 
 func (s *udpForWardingService) EditUdpForwarding(ctx context.Context, req *v1.UdpForwardingRequest) error {
-	WafUdpId, err := s.udpForWardingRepository.GetUdpForwardingWafUdpIdById(ctx, req.UdpForwardingData.Id)
-	if err != nil {
-		return err
-	}
-	req.UdpForwardingData.WafUdpId = WafUdpId
-	require, formData, err := s.prepareWafData(ctx, req)
-	if err != nil {
-		return err
-	}
-	_, err = s.wafformatter.sendFormData(ctx, "admin/info/waf_udp/edit?&__goadmin_edit_pk="+strconv.Itoa(req.UdpForwardingData.WafUdpId), "admin/edit/waf_udp", formData)
-	if err != nil {
-		return err
-	}
-
-	// 异步任务:将IP添加到白名单
-	gatewayIps, _, err := s.wafformatter.GetIp(ctx, require.WafGatewayGroupId)
-	if err != nil {
-		return err
-	}
-	ipData, err := s.udpForWardingRepository.GetUdpForwardingIpsByID(ctx, req.UdpForwardingData.Id)
-	if err != nil {
-		return err
-	}
-	addedIps, removedIps, addedAllowIps, removedAllowIps, err := s.wafformatter.WashEditWafIp(ctx,req.UdpForwardingData.BackendList,req.UdpForwardingData.AllowIpList,ipData.BackendList,ipData.AllowIpList)
-	if err != nil {
-		return err
-	}
-	if len(addedIps) > 0 {
-		go s.wafformatter.PublishIpWhitelistTask(addedIps, "add","")
-	}
-	if len(removedIps) > 0 {
-		go s.wafformatter.PublishIpWhitelistTask(removedIps, "del","")
-	}
-
-	if len(addedAllowIps) > 0 {
-		for _, v := range gatewayIps {
-			go s.wafformatter.PublishIpWhitelistTask(addedAllowIps, "add",v)
-		}
-	}
-	if len(removedAllowIps) > 0 {
-		for _, v := range gatewayIps {
-			go s.wafformatter.PublishIpWhitelistTask(removedAllowIps, "del",v)
-		}
-
-	}
-
-
-	udpModel := s.buildUdpForwardingModel(&req.UdpForwardingData, req.UdpForwardingData.WafUdpId, require)
-	udpModel.Id = req.UdpForwardingData.Id
-	if err = s.udpForWardingRepository.EditUdpForwarding(ctx, udpModel); err != nil {
-		return err
-	}
-	udpRuleModel := s.buildUdpRuleModel(&req.UdpForwardingData, require, req.UdpForwardingData.Id)
-	if err = s.udpForWardingRepository.EditUdpForwardingIps(ctx, *udpRuleModel); err != nil {
-		return err
-	}
+	//WafUdpId, err := s.udpForWardingRepository.GetUdpForwardingWafUdpIdById(ctx, req.UdpForwardingData.Id)
+	//if err != nil {
+	//	return err
+	//}
+	//req.UdpForwardingData.WafUdpId = WafUdpId
+	//require, formData, err := s.prepareWafData(ctx, req)
+	//if err != nil {
+	//	return err
+	//}
+	//_, err = s.wafformatter.sendFormData(ctx, "admin/info/waf_udp/edit?&__goadmin_edit_pk="+strconv.Itoa(req.UdpForwardingData.WafUdpId), "admin/edit/waf_udp", formData)
+	//if err != nil {
+	//	return err
+	//}
+	//
+	//// 异步任务:将IP添加到白名单
+	//gatewayIps, _, err := s.wafformatter.GetIp(ctx, require.WafGatewayGroupId)
+	//if err != nil {
+	//	return err
+	//}
+	//ipData, err := s.udpForWardingRepository.GetUdpForwardingIpsByID(ctx, req.UdpForwardingData.Id)
+	//if err != nil {
+	//	return err
+	//}
+	//addedIps, removedIps, addedAllowIps, removedAllowIps, err := s.wafformatter.WashEditWafIp(ctx,req.UdpForwardingData.BackendList,req.UdpForwardingData.AllowIpList,ipData.BackendList,ipData.AllowIpList)
+	//if err != nil {
+	//	return err
+	//}
+	//if len(addedIps) > 0 {
+	//	go s.wafformatter.PublishIpWhitelistTask(addedIps, "add","")
+	//}
+	//if len(removedIps) > 0 {
+	//	go s.wafformatter.PublishIpWhitelistTask(removedIps, "del","")
+	//}
+	//
+	//if len(addedAllowIps) > 0 {
+	//	for _, v := range gatewayIps {
+	//		go s.wafformatter.PublishIpWhitelistTask(addedAllowIps, "add",v)
+	//	}
+	//}
+	//if len(removedAllowIps) > 0 {
+	//	for _, v := range gatewayIps {
+	//		go s.wafformatter.PublishIpWhitelistTask(removedAllowIps, "del",v)
+	//	}
+	//
+	//}
+	//
+	//
+	//udpModel := s.buildUdpForwardingModel(&req.UdpForwardingData, req.UdpForwardingData.WafUdpId, require)
+	//udpModel.Id = req.UdpForwardingData.Id
+	//if err = s.udpForWardingRepository.EditUdpForwarding(ctx, udpModel); err != nil {
+	//	return err
+	//}
+	//udpRuleModel := s.buildUdpRuleModel(&req.UdpForwardingData, require, req.UdpForwardingData.Id)
+	//if err = s.udpForWardingRepository.EditUdpForwardingIps(ctx, *udpRuleModel); err != nil {
+	//	return err
+	//}
 	return nil
 }
 

+ 19 - 31
internal/service/wafformatter.go

@@ -5,10 +5,10 @@ import (
 	"encoding/json"
 	"fmt"
 	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/repository"
 	"github.com/go-nunu/nunu-layout-advanced/pkg/rabbitmq"
 	amqp "github.com/rabbitmq/amqp091-go"
-	"github.com/spf13/cast"
 	"go.uber.org/zap"
 	"golang.org/x/net/publicsuffix"
 	"net"
@@ -17,8 +17,7 @@ import (
 )
 
 type WafFormatterService interface {
-	require(ctx context.Context, req v1.GlobalRequire, category string) (v1.GlobalRequire, error)
-	sendFormData(ctx context.Context,addTokenUrl string,addSendUrl string,formData map[string]interface{}) (int, error)
+	Require(ctx context.Context, req v1.GlobalRequire) (RequireResponse, error)
 	validateWafPortCount(ctx context.Context, hostId int) error
 	validateWafDomainCount(ctx context.Context, req v1.GlobalRequire) error
 	ConvertToWildcardDomain(ctx context.Context,domain string) (string, error)
@@ -76,45 +75,34 @@ type wafFormatterService struct {
 	gatewayGroupIpRep repository.GateWayGroupIpRepository
 }
 
-
-func (s *wafFormatterService) require(ctx context.Context,req v1.GlobalRequire,category string) (v1.GlobalRequire, error) {
-	RuleIds, err := s.globalRep.GetGlobalLimitByHostId(ctx, int64(req.HostId))
-	if err != nil {
-		return v1.GlobalRequire{}, err
-	}
-	req.WafGatewayGroupId = RuleIds.GatewayGroupId
-	domain, err := s.hostRep.GetDomainById(ctx, req.HostId)
-	if err != nil {
-		return v1.GlobalRequire{}, err
-	}
-	req.Tag = strconv.Itoa(req.Uid) + "_" + strconv.Itoa(req.HostId) + "_" + domain + "_" + req.Comment
-	return req, nil
+type RequireResponse struct {
+	model.GlobalLimit `json:"globalLimit" form:"globalLimit"`
+	GatewayIps []string `json:"ips" form:"ips"`
+	Tag string `json:"tag" form:"tag"`
 }
 
-func (s *wafFormatterService) sendFormData(ctx context.Context,addTokenUrl string,addSendUrl string,formData map[string]interface{}) (int, error) {
-	respBody, err := s.required.SendForm(ctx, addTokenUrl, addSendUrl, formData)
+func (s *wafFormatterService) Require(ctx context.Context,req v1.GlobalRequire) (RequireResponse, error)  {
+	var res RequireResponse
+	globalLimit, err := s.globalRep.GetGlobalLimitByHostId(ctx, int64(req.HostId))
 	if err != nil {
-		return 0, err
+		return RequireResponse{}, err
 	}
-	// 解析响应内容中的 alert 消息
-	res, err := s.parser.ParseAlert(string(respBody))
-	if err != nil {
-		return 0,err
-	}
-	if res != "" {
-		return 0,fmt.Errorf(res)
+	if globalLimit != nil {
+		res.GlobalLimit = *globalLimit
 	}
-	ruleIdStr, err := s.parser.GetRuleIdByColumnName(ctx, respBody,formData["tag"].(string))
+	domain, err := s.hostRep.GetDomainById(ctx, req.HostId)
 	if err != nil {
-		return 0, err
+		return RequireResponse{}, err
 	}
-	ruleId, err := cast.ToIntE(ruleIdStr)
+	res.Tag = strconv.Itoa(req.Uid) + "_" + strconv.Itoa(req.HostId) + "_" + domain + "_" + req.Comment
+	res.GatewayIps, err = s.gatewayGroupIpRep.GetGateWayGroupAllIpByGatewayGroupId(ctx, res.GatewayGroupId)
 	if err != nil {
-		return 0,err
+		return RequireResponse{}, err
 	}
-	return ruleId, nil
+	return res, nil
 }
 
+
 func (s *wafFormatterService) validateWafPortCount(ctx context.Context, hostId int) error {
 	congfig, err := s.host.GetGlobalLimitConfig(ctx, hostId)
 	if err != nil {

+ 180 - 194
internal/service/webforwarding.go

@@ -67,14 +67,14 @@ func (s *webForwardingService) require(ctx context.Context,req v1.GlobalRequire)
 	var res v1.GlobalRequire
 	g, gCtx := errgroup.WithContext(ctx)
 
-	g.Go(func() error {
-		result, e := s.wafformatter.require(gCtx, req, "web")
-		if e != nil {
-			return e
-		}
-		res = result
-		return nil
-	})
+	//g.Go(func() error {
+	//	result, e := s.wafformatter.require(gCtx, req, "web")
+	//	if e != nil {
+	//		return e
+	//	}
+	//	res = result
+	//	return nil
+	//})
 
 	g.Go(func() error {
 		e := s.wafformatter.validateWafDomainCount(gCtx, req)
@@ -167,12 +167,9 @@ func (s *webForwardingService) buildWafFormData(req *v1.WebForwardingDataSend, r
 
 	return map[string]interface{}{
 		"waf_web_id":            req.WafWebId,
-		"tag":                   require.Tag,
 		"port":                  req.Port,
 		"domain":                req.Domain,
 		"custom_host":           req.CustomHost,
-		"waf_gateway_group_id":  require.WafGatewayGroupId,
-		"waf_web_limit_id":      require.LimitRuleId,
 		"cc_count":              req.CcCount,
 		"cc_duration":           req.CcDuration,
 		"cc_block_count":        req.CcBlockCount,
@@ -202,12 +199,9 @@ func (s *webForwardingService) buildWebForwardingModel(req *v1.WebForwardingData
 	return &model.WebForwarding{
 		HostId: 			require.HostId,
 		WafWebId:           ruleId,
-		Tag:                require.Tag,
 		Port:               req.Port,
 		Domain:             req.Domain,
 		CustomHost:         req.CustomHost,
-		WafGatewayGroupId:  require.WafGatewayGroupId,
-		WebLimitRuleId:     require.LimitRuleId,
 		CcCount:            req.CcCount,
 		CcDuration:         req.CcDuration,
 		CcBlockCount:       req.CcBlockCount,
@@ -250,9 +244,7 @@ func (s *webForwardingService) prepareWafData(ctx context.Context, req *v1.WebFo
 	if err != nil {
 		return v1.GlobalRequire{}, nil, err
 	}
-	if require.WafGatewayGroupId == 0 || require.LimitRuleId == 0 {
-		return v1.GlobalRequire{}, nil, fmt.Errorf("请先配置实例")
-	}
+
 
 	// 2. 将字符串切片拼接成字符串,用于 WAF API
 	allowIpListStr := strings.Join(req.WebForwardingData.AllowIpList, "\n")
@@ -264,10 +256,7 @@ func (s *webForwardingService) prepareWafData(ctx context.Context, req *v1.WebFo
 	}
 	// 3. 创建用于构建 WAF 表单的数据结构
 	formDataBase := v1.WebForwardingDataSend{
-		Tag:                 require.Tag,
 		WafWebId:            req.WebForwardingData.WafWebId,
-		WafGatewayGroupId:   require.WafGatewayGroupId,
-		WafWebLimitId:   require.LimitRuleId,
 		Port:                PortInt,
 		Domain:              req.WebForwardingData.Domain,
 		CustomHost:          req.WebForwardingData.CustomHost,
@@ -302,184 +291,181 @@ func (s *webForwardingService) prepareWafData(ctx context.Context, req *v1.WebFo
 
 
 func (s *webForwardingService) AddWebForwarding(ctx context.Context, req *v1.WebForwardingRequest) error {
-	require, formData, err := s.prepareWafData(ctx, req)
-	if err != nil {
-		return err
-	}
-	err = s.wafformatter.validateWafPortCount(ctx, require.HostId)
-	if err != nil {
-		return err
-	}
-	wafWebId, err := s.wafformatter.sendFormData(ctx, "admin/info/waf_web/new", "admin/new/waf_web", formData)
-	if err != nil {
-		return err
-	}
-
-	gatewayIps, firstIp, err := s.wafformatter.GetIp(ctx, require.WafGatewayGroupId)
-	if err != nil {
-		return err
-	}
-	if req.WebForwardingData.Domain != "" {
-		// 异步任务:将域名添加到白名单
-		doMain, err := s.wafformatter.ConvertToWildcardDomain(ctx, req.WebForwardingData.Domain)
-		if err != nil {
-			return err
-		}
-		go s.wafformatter.PublishDomainWhitelistTask(doMain,firstIp, "add")
-
-	}
-
-	// IP过白
-	var ips []string
-	if req.WebForwardingData.BackendList != nil {
-		for _, v := range req.WebForwardingData.BackendList {
-			ip, _, err := net.SplitHostPort(v.Addr)
-			if err != nil {
-				return err
-			}
-			ips = append(ips,ip)
-		}
-		go s.wafformatter.PublishIpWhitelistTask(ips, "add","")
-	}
-	var accessRuleIps []string
-	if len(req.WebForwardingData.AllowIpList) > 0 {
-		for _, v := range gatewayIps {
-			for _, ip := range req.WebForwardingData.AllowIpList {
-				if net.ParseIP(ip) != nil{
-					accessRuleIps = append(accessRuleIps, ip)
-				}
-			}
-			go s.wafformatter.PublishIpWhitelistTask(accessRuleIps, "add",v)
-		}
-	}
-
-
-
-	webModel := s.buildWebForwardingModel(&req.WebForwardingData, wafWebId, require)
-
-	id, err := s.webForwardingRepository.AddWebForwarding(ctx, webModel)
-	if err != nil {
-		return err
-	}
-	webRuleModel := s.buildWebRuleModel(&req.WebForwardingData, require, id)
-
-
-	if _, err = s.webForwardingRepository.AddWebForwardingIps(ctx, *webRuleModel); err != nil {
-		return err
-	}
+	//require, formData, err := s.prepareWafData(ctx, req)
+	//if err != nil {
+	//	return err
+	//}
+	//err = s.wafformatter.validateWafPortCount(ctx, require.HostId)
+	//if err != nil {
+	//	return err
+	//}
+	//
+	//
+	//gatewayIps, firstIp, err := s.wafformatter.GetIp(ctx, require.WafGatewayGroupId)
+	//if err != nil {
+	//	return err
+	//}
+	//if req.WebForwardingData.Domain != "" {
+	//	// 异步任务:将域名添加到白名单
+	//	doMain, err := s.wafformatter.ConvertToWildcardDomain(ctx, req.WebForwardingData.Domain)
+	//	if err != nil {
+	//		return err
+	//	}
+	//	go s.wafformatter.PublishDomainWhitelistTask(doMain,firstIp, "add")
+	//
+	//}
+	//
+	//// IP过白
+	//var ips []string
+	//if req.WebForwardingData.BackendList != nil {
+	//	for _, v := range req.WebForwardingData.BackendList {
+	//		ip, _, err := net.SplitHostPort(v.Addr)
+	//		if err != nil {
+	//			return err
+	//		}
+	//		ips = append(ips,ip)
+	//	}
+	//	go s.wafformatter.PublishIpWhitelistTask(ips, "add","")
+	//}
+	//var accessRuleIps []string
+	//if len(req.WebForwardingData.AllowIpList) > 0 {
+	//	for _, v := range gatewayIps {
+	//		for _, ip := range req.WebForwardingData.AllowIpList {
+	//			if net.ParseIP(ip) != nil{
+	//				accessRuleIps = append(accessRuleIps, ip)
+	//			}
+	//		}
+	//		go s.wafformatter.PublishIpWhitelistTask(accessRuleIps, "add",v)
+	//	}
+	//}
+	//
+	//
+	//
+	//webModel := s.buildWebForwardingModel(&req.WebForwardingData, wafWebId, require)
+	//
+	//id, err := s.webForwardingRepository.AddWebForwarding(ctx, webModel)
+	//if err != nil {
+	//	return err
+	//}
+	//webRuleModel := s.buildWebRuleModel(&req.WebForwardingData, require, id)
+	//
+	//
+	//if _, err = s.webForwardingRepository.AddWebForwardingIps(ctx, *webRuleModel); err != nil {
+	//	return err
+	//}
 	return nil
 }
 
 func (s *webForwardingService) EditWebForwarding(ctx context.Context, req *v1.WebForwardingRequest) error {
-	WafWebId, err := s.webForwardingRepository.GetWebForwardingWafWebIdById(ctx, req.WebForwardingData.Id)
-	if err != nil {
-		return err
-	}
-	req.WebForwardingData.WafWebId = WafWebId
-	require, formData, err := s.prepareWafData(ctx, req)
-	if err != nil {
-		return err
-	}
-	_, err = s.wafformatter.sendFormData(ctx, "admin/info/waf_web/edit?&__goadmin_edit_pk="+strconv.Itoa(req.WebForwardingData.WafWebId), "admin/edit/waf_web", formData)
-	if err != nil {
-		return err
-	}
-
-	// 将域名添加到白名单
-	webData, err := s.webForwardingRepository.GetWebForwarding(ctx, int64(req.WebForwardingData.Id))
-	if err != nil {
-		return err
-	}
-	gatewayIps, firstIp, err := s.wafformatter.GetIp(ctx, webData.WafGatewayGroupId)
-	if err != nil {
-		return err
-	}
-	// 异步任务:将域名添加到白名单
-	if webData.Domain != req.WebForwardingData.Domain {
-
-		doMain, err := s.wafformatter.ConvertToWildcardDomain(ctx, req.WebForwardingData.Domain)
-		if err != nil {
-			return err
-		}
-		oldDomain, err := s.wafformatter.ConvertToWildcardDomain(ctx, webData.Domain)
-		if err != nil {
-			return err
-		}
-		go s.wafformatter.PublishDomainWhitelistTask(oldDomain, firstIp, "del")
-		go s.wafformatter.PublishDomainWhitelistTask(doMain, firstIp, "add")
-	}
-
-	// IP过白
-	ipData, err := s.webForwardingRepository.GetWebForwardingIpsByID(ctx, req.WebForwardingData.Id)
-	if err != nil {
-		return err
-	}
-	var oldIps []string
-	var oldAllowIps []string
-	var newIps []string
-	var newAllowIps []string
-	for _, v := range ipData.BackendList {
-		ip, _, err := net.SplitHostPort(v.Addr)
-		if err != nil {
-			return err
-		}
-		oldIps = append(oldIps, ip)
-
-	}
-	for _, v := range req.WebForwardingData.BackendList {
-		ip, _, err := net.SplitHostPort(v.Addr)
-		if err != nil {
-			return err
-		}
-		newIps = append(newIps, ip)
-	}
-	addedIps, removedIps := s.wafformatter.findIpDifferences(oldIps, newIps)
-	if len(addedIps) > 0 {
-		go s.wafformatter.PublishIpWhitelistTask(addedIps, "add","")
-	}
-	if len(removedIps) > 0 {
-		go s.wafformatter.PublishIpWhitelistTask(removedIps, "del","")
-	}
-	if len(ipData.AllowIpList) > 0 {
-		for _, v := range ipData.AllowIpList {
-			if net.ParseIP(v) != nil{
-				oldAllowIps = append(oldAllowIps, v)
-			}
-		}
-	}
-
-	if len(req.WebForwardingData.AllowIpList) > 0 {
-		for _, v := range req.WebForwardingData.AllowIpList {
-			if net.ParseIP(v) != nil{
-				newAllowIps = append(newAllowIps, v)
-			}
-		}
-	}
-	addedAllowIps, removedAllowIps := s.wafformatter.findIpDifferences(oldAllowIps, newAllowIps)
-	for _, v := range gatewayIps {
-		if len(addedAllowIps) > 0 {
-			go s.wafformatter.PublishIpWhitelistTask(addedAllowIps, "add",v)
-		}
-		if len(removedAllowIps) > 0 {
-			go s.wafformatter.PublishIpWhitelistTask(removedAllowIps, "del",v)
-		}
-	}
-
-
-
-
-
-
-
-	webModel := s.buildWebForwardingModel(&req.WebForwardingData, req.WebForwardingData.WafWebId, require)
-	webModel.Id = req.WebForwardingData.Id
-	if err = s.webForwardingRepository.EditWebForwarding(ctx, webModel); err != nil {
-		return err
-	}
-	webRuleModel := s.buildWebRuleModel(&req.WebForwardingData, require, req.WebForwardingData.Id)
-	if err = s.webForwardingRepository.EditWebForwardingIps(ctx, *webRuleModel); err != nil {
-		return err
-	}
+	//WafWebId, err := s.webForwardingRepository.GetWebForwardingWafWebIdById(ctx, req.WebForwardingData.Id)
+	//if err != nil {
+	//	return err
+	//}
+	//req.WebForwardingData.WafWebId = WafWebId
+	//require, formData, err := s.prepareWafData(ctx, req)
+	//if err != nil {
+	//	return err
+	//}
+	//_, err = s.wafformatter.sendFormData(ctx, "admin/info/waf_web/edit?&__goadmin_edit_pk="+strconv.Itoa(req.WebForwardingData.WafWebId), "admin/edit/waf_web", formData)
+	//if err != nil {
+	//	return err
+	//}
+	//
+	//// 将域名添加到白名单
+	//webData, err := s.webForwardingRepository.GetWebForwarding(ctx, int64(req.WebForwardingData.Id))
+	//if err != nil {
+	//	return err
+	//}
+	//gatewayIps, firstIp, err := s.wafformatter.GetIp(ctx, webData.WafGatewayGroupId)
+	//if err != nil {
+	//	return err
+	//}
+	//// 异步任务:将域名添加到白名单
+	//if webData.Domain != req.WebForwardingData.Domain {
+	//
+	//	doMain, err := s.wafformatter.ConvertToWildcardDomain(ctx, req.WebForwardingData.Domain)
+	//	if err != nil {
+	//		return err
+	//	}
+	//	oldDomain, err := s.wafformatter.ConvertToWildcardDomain(ctx, webData.Domain)
+	//	if err != nil {
+	//		return err
+	//	}
+	//	go s.wafformatter.PublishDomainWhitelistTask(oldDomain, firstIp, "del")
+	//	go s.wafformatter.PublishDomainWhitelistTask(doMain, firstIp, "add")
+	//}
+	//
+	//// IP过白
+	//ipData, err := s.webForwardingRepository.GetWebForwardingIpsByID(ctx, req.WebForwardingData.Id)
+	//if err != nil {
+	//	return err
+	//}
+	//var oldIps []string
+	//var oldAllowIps []string
+	//var newIps []string
+	//var newAllowIps []string
+	//for _, v := range ipData.BackendList {
+	//	ip, _, err := net.SplitHostPort(v.Addr)
+	//	if err != nil {
+	//		return err
+	//	}
+	//	oldIps = append(oldIps, ip)
+	//
+	//}
+	//for _, v := range req.WebForwardingData.BackendList {
+	//	ip, _, err := net.SplitHostPort(v.Addr)
+	//	if err != nil {
+	//		return err
+	//	}
+	//	newIps = append(newIps, ip)
+	//}
+	//addedIps, removedIps := s.wafformatter.findIpDifferences(oldIps, newIps)
+	//if len(addedIps) > 0 {
+	//	go s.wafformatter.PublishIpWhitelistTask(addedIps, "add","")
+	//}
+	//if len(removedIps) > 0 {
+	//	go s.wafformatter.PublishIpWhitelistTask(removedIps, "del","")
+	//}
+	//if len(ipData.AllowIpList) > 0 {
+	//	for _, v := range ipData.AllowIpList {
+	//		if net.ParseIP(v) != nil{
+	//			oldAllowIps = append(oldAllowIps, v)
+	//		}
+	//	}
+	//}
+	//
+	//if len(req.WebForwardingData.AllowIpList) > 0 {
+	//	for _, v := range req.WebForwardingData.AllowIpList {
+	//		if net.ParseIP(v) != nil{
+	//			newAllowIps = append(newAllowIps, v)
+	//		}
+	//	}
+	//}
+	//addedAllowIps, removedAllowIps := s.wafformatter.findIpDifferences(oldAllowIps, newAllowIps)
+	//for _, v := range gatewayIps {
+	//	if len(addedAllowIps) > 0 {
+	//		go s.wafformatter.PublishIpWhitelistTask(addedAllowIps, "add",v)
+	//	}
+	//	if len(removedAllowIps) > 0 {
+	//		go s.wafformatter.PublishIpWhitelistTask(removedAllowIps, "del",v)
+	//	}
+	//}
+	//
+	//
+	//
+	//
+	//
+	//
+	//
+	//webModel := s.buildWebForwardingModel(&req.WebForwardingData, req.WebForwardingData.WafWebId, require)
+	//webModel.Id = req.WebForwardingData.Id
+	//if err = s.webForwardingRepository.EditWebForwarding(ctx, webModel); err != nil {
+	//	return err
+	//}
+	//webRuleModel := s.buildWebRuleModel(&req.WebForwardingData, require, req.WebForwardingData.Id)
+	//if err = s.webForwardingRepository.EditWebForwardingIps(ctx, *webRuleModel); err != nil {
+	//	return err
+	//}
 	return nil
 }