|
@@ -44,14 +44,14 @@ func NewWebForwardingService(
|
|
|
wafformatter: wafformatter,
|
|
|
aoDun: aoDun,
|
|
|
mq: mq,
|
|
|
- gatewayGroupIpRep: gatewayGroupIpRep,
|
|
|
- gatewayGroupRep: gatewayGroupRep,
|
|
|
+ gatewayGroupIpRep: gatewayGroupIpRep,
|
|
|
+ gatewayGroupRep: gatewayGroupRep,
|
|
|
cdn: cdn,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
const (
|
|
|
- isHttps = 1
|
|
|
+ isHttps = 1
|
|
|
protocolHttps = "https"
|
|
|
protocolHttp = "http"
|
|
|
defaultNodeClusterId = 1
|
|
@@ -66,15 +66,12 @@ type webForwardingService struct {
|
|
|
wafformatter WafFormatterService
|
|
|
aoDun AoDunService
|
|
|
mq *rabbitmq.RabbitMQ
|
|
|
- gatewayGroupIpRep repository.GateWayGroupIpRepository
|
|
|
- gatewayGroupRep repository.GatewayGroupRepository
|
|
|
+ gatewayGroupIpRep repository.GateWayGroupIpRepository
|
|
|
+ gatewayGroupRep repository.GatewayGroupRepository
|
|
|
cdn CdnService
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-func (s *webForwardingService) require(ctx context.Context,req v1.GlobalRequire) (v1.GlobalRequire, error) {
|
|
|
+func (s *webForwardingService) require(ctx context.Context, req v1.GlobalRequire) (v1.GlobalRequire, error) {
|
|
|
var err error
|
|
|
var res v1.GlobalRequire
|
|
|
g, gCtx := errgroup.WithContext(ctx)
|
|
@@ -95,7 +92,7 @@ func (s *webForwardingService) require(ctx context.Context,req v1.GlobalRequire)
|
|
|
}
|
|
|
return nil
|
|
|
})
|
|
|
- if err = g.Wait(); err != nil {
|
|
|
+ if err = g.Wait(); err != nil {
|
|
|
return v1.GlobalRequire{}, err
|
|
|
}
|
|
|
return res, nil
|
|
@@ -133,48 +130,43 @@ func (s *webForwardingService) GetWebForwarding(ctx context.Context, req v1.GetF
|
|
|
}
|
|
|
|
|
|
return v1.WebForwardingDataRequest{
|
|
|
- Id: webForwarding.Id,
|
|
|
- Port: webForwarding.Port,
|
|
|
- Domain: webForwarding.Domain,
|
|
|
- IsHttps: webForwarding.IsHttps,
|
|
|
- Comment: webForwarding.Comment,
|
|
|
- BackendList: backend.BackendList,
|
|
|
- HttpsKey: webForwarding.HttpsKey,
|
|
|
- HttpsCert: webForwarding.HttpsCert,
|
|
|
+ Id: webForwarding.Id,
|
|
|
+ Port: webForwarding.Port,
|
|
|
+ Domain: webForwarding.Domain,
|
|
|
+ IsHttps: webForwarding.IsHttps,
|
|
|
+ Comment: webForwarding.Comment,
|
|
|
+ BackendList: backend.BackendList,
|
|
|
+ HttpsKey: webForwarding.HttpsKey,
|
|
|
+ HttpsCert: webForwarding.HttpsCert,
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// buildWebForwardingModel 辅助函数,用于构建通用的 WebForwarding 模型
|
|
|
// ruleId 是从 WAF 系统获取的 ID
|
|
|
-func (s *webForwardingService) buildWebForwardingModel(req *v1.WebForwardingDataRequest,ruleId int, require RequireResponse) *model.WebForwarding {
|
|
|
+func (s *webForwardingService) buildWebForwardingModel(req *v1.WebForwardingDataRequest, ruleId int, require RequireResponse) *model.WebForwarding {
|
|
|
return &model.WebForwarding{
|
|
|
- HostId: require.HostId,
|
|
|
- CdnWebId: ruleId,
|
|
|
- Port: req.Port,
|
|
|
- Domain: req.Domain,
|
|
|
- IsHttps: req.IsHttps,
|
|
|
- Comment: req.Comment,
|
|
|
- HttpsCert: req.HttpsCert,
|
|
|
- HttpsKey: req.HttpsKey,
|
|
|
+ HostId: require.HostId,
|
|
|
+ CdnWebId: ruleId,
|
|
|
+ Port: req.Port,
|
|
|
+ Domain: req.Domain,
|
|
|
+ IsHttps: req.IsHttps,
|
|
|
+ Comment: req.Comment,
|
|
|
+ HttpsCert: req.HttpsCert,
|
|
|
+ HttpsKey: req.HttpsKey,
|
|
|
SslCertId: int(req.SslCertId),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (s *webForwardingService) buildWebRuleModel(reqData *v1.WebForwardingDataRequest, require RequireResponse, localDbId int, cdnOriginIds map[string]int64) *model.WebForwardingRule {
|
|
|
return &model.WebForwardingRule{
|
|
|
- Uid: require.Uid,
|
|
|
- HostId: require.HostId,
|
|
|
- WebId: localDbId,
|
|
|
+ Uid: require.Uid,
|
|
|
+ HostId: require.HostId,
|
|
|
+ WebId: localDbId,
|
|
|
CdnOriginIds: cdnOriginIds,
|
|
|
- BackendList: reqData.BackendList,
|
|
|
+ BackendList: reqData.BackendList,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
// =================================================================
|
|
|
// 主函数:prepareWafData
|
|
|
// 职责:协调整个流程,负责获取前置配置和组装最终的 formData。
|
|
@@ -201,14 +193,14 @@ func (s *webForwardingService) prepareWafData(ctx context.Context, req *v1.WebFo
|
|
|
|
|
|
type serverNames struct {
|
|
|
ServerNames string `json:"name" form:"name"`
|
|
|
- Type string `json:"type" form:"type"`
|
|
|
+ Type string `json:"type" form:"type"`
|
|
|
}
|
|
|
var serverName []serverNames
|
|
|
var serverJson []byte
|
|
|
if req.WebForwardingData.Domain != "" {
|
|
|
serverName = append(serverName, serverNames{
|
|
|
ServerNames: req.WebForwardingData.Domain,
|
|
|
- Type: "full",
|
|
|
+ Type: "full",
|
|
|
})
|
|
|
serverJson, err = json.Marshal(serverName)
|
|
|
if err != nil {
|
|
@@ -218,14 +210,14 @@ func (s *webForwardingService) prepareWafData(ctx context.Context, req *v1.WebFo
|
|
|
|
|
|
// 3. 组装最终的 WAF 表单数据
|
|
|
formData := v1.Website{
|
|
|
- UserId: int64(require.CdnUid),
|
|
|
- Type: "httpProxy",
|
|
|
- Name: require.Tag,
|
|
|
- ServerNamesJSON : serverJson,
|
|
|
- Description: req.WebForwardingData.Comment,
|
|
|
- ServerGroupIds: []int64{int64(require.GroupId)},
|
|
|
- UserPlanId: int64(require.RuleId),
|
|
|
- NodeClusterId: defaultNodeClusterId,
|
|
|
+ UserId: int64(require.CdnUid),
|
|
|
+ Type: "httpProxy",
|
|
|
+ Name: require.Tag,
|
|
|
+ ServerNamesJSON: serverJson,
|
|
|
+ Description: req.WebForwardingData.Comment,
|
|
|
+ ServerGroupIds: []int64{int64(require.GroupId)},
|
|
|
+ UserPlanId: int64(require.RuleId),
|
|
|
+ NodeClusterId: defaultNodeClusterId,
|
|
|
}
|
|
|
|
|
|
var noSslByteData, _ = json.Marshal(v1.TypeJSON{IsOn: false})
|
|
@@ -242,7 +234,6 @@ func (s *webForwardingService) prepareWafData(ctx context.Context, req *v1.WebFo
|
|
|
return require, formData, nil
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// =================================================================
|
|
|
// 辅助函数:buildProxyJSONConfig
|
|
|
// 职责:专门负责处理 HTTP/HTTPS 的差异,并生成对应的 JSON 配置。
|
|
@@ -258,8 +249,8 @@ func (s *webForwardingService) buildProxyJSONConfig(ctx context.Context, req *v1
|
|
|
// 判断协议类型,并处理 HTTPS 的特殊逻辑(证书)
|
|
|
if req.WebForwardingData.IsHttps == isHttps {
|
|
|
apiType = protocolHttps
|
|
|
-
|
|
|
- req.WebForwardingData.SslCertId, err = s.cdn.AddSSLCert(ctx, v1.SSlCert{
|
|
|
+ // 添加 SSL 证书
|
|
|
+ sslCertId, err := s.cdn.AddSSLCert(ctx, v1.SSlCert{
|
|
|
UserId: int64(require.CdnUid),
|
|
|
Name: req.WebForwardingData.Domain,
|
|
|
Description: req.WebForwardingData.Comment,
|
|
@@ -268,10 +259,36 @@ func (s *webForwardingService) buildProxyJSONConfig(ctx context.Context, req *v1
|
|
|
IsSelfSigned: false,
|
|
|
})
|
|
|
if err != nil {
|
|
|
- return nil, fmt.Errorf("添加SSL证书失败: %w", err)
|
|
|
+ return nil, fmt.Errorf("添加SSL证书失败: %w", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加 SSL 策略
|
|
|
+ if sslCertId != 0 {
|
|
|
+ type sslCerts struct {
|
|
|
+ IsOn bool `json:"isOn" form:"isOn"`
|
|
|
+ CertId int64 `json:"certId" form:"certId"`
|
|
|
+ }
|
|
|
+ var sslCertsSlice []sslCerts
|
|
|
+ sslCertsSlice = append(sslCertsSlice, sslCerts{
|
|
|
+ IsOn: true,
|
|
|
+ CertId: sslCertId,
|
|
|
+ })
|
|
|
+ sslCertsJson, err := json.Marshal(sslCertsSlice)
|
|
|
+ if err != nil {
|
|
|
+ return nil, fmt.Errorf("序列化SSL证书失败: %w", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ sslPolicyId, err := s.cdn.AddSSLPolicy(ctx, v1.AddSSLPolicy{
|
|
|
+ Http2Enabled: true,
|
|
|
+ SslCertsJSON: sslCertsJson,
|
|
|
+ MinVersion: "TLS 1.1",
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return nil, fmt.Errorf("添加SSL策略失败: %w", err)
|
|
|
+ }
|
|
|
+ jsonData.SslPolicyRef.SslPolicyId = sslPolicyId
|
|
|
}
|
|
|
jsonData.SslPolicyRef.IsOn = true
|
|
|
- jsonData.SslPolicyRef.SslPolicyId = req.WebForwardingData.SslCertId
|
|
|
} else {
|
|
|
apiType = protocolHttp
|
|
|
}
|
|
@@ -291,11 +308,11 @@ func (s *webForwardingService) buildProxyJSONConfig(ctx context.Context, req *v1
|
|
|
return nil, fmt.Errorf("序列化WAF配置失败: %w", err)
|
|
|
}
|
|
|
|
|
|
- return byteData, nil
|
|
|
+ return byteData, nil
|
|
|
}
|
|
|
|
|
|
// 查找两个列表的差异
|
|
|
-func (s webForwardingService) FindDifferenceList (oldList, newList []v1.BackendList) (added, removed []v1.BackendList) {
|
|
|
+func (s webForwardingService) FindDifferenceList(oldList, newList []v1.BackendList) (added, removed []v1.BackendList) {
|
|
|
diff := make(map[v1.BackendList]int)
|
|
|
|
|
|
// 1. 遍历旧列表,为每个元素计数 +1
|
|
@@ -323,8 +340,6 @@ func (s webForwardingService) FindDifferenceList (oldList, newList []v1.BackendL
|
|
|
return added, removed
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
func (s *webForwardingService) AddWebForwarding(ctx context.Context, req *v1.WebForwardingRequest) error {
|
|
|
require, formData, err := s.prepareWafData(ctx, req)
|
|
|
if err != nil {
|
|
@@ -340,7 +355,7 @@ func (s *webForwardingService) AddWebForwarding(ctx context.Context, req *v1.Web
|
|
|
return err
|
|
|
}
|
|
|
backendList := make(map[string]string)
|
|
|
- for _,k := range req.WebForwardingData.BackendList {
|
|
|
+ for _, k := range req.WebForwardingData.BackendList {
|
|
|
backendList[k.Addr] = k.CustomHost
|
|
|
}
|
|
|
// 添加源站
|
|
@@ -367,7 +382,7 @@ func (s *webForwardingService) AddWebForwarding(ctx context.Context, req *v1.Web
|
|
|
}
|
|
|
|
|
|
id, err := s.wafformatter.AddOrigin(ctx, v1.WebJson{
|
|
|
- ApiType: apiType,
|
|
|
+ ApiType: apiType,
|
|
|
BackendList: addrPunyPort,
|
|
|
Host: v.CustomHost,
|
|
|
Comment: req.WebForwardingData.Comment,
|
|
@@ -392,14 +407,11 @@ func (s *webForwardingService) AddWebForwarding(ctx context.Context, req *v1.Web
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- webRuleModel := s.buildWebRuleModel(&req.WebForwardingData,require, id, cdnOriginIds)
|
|
|
+ webRuleModel := s.buildWebRuleModel(&req.WebForwardingData, require, id, cdnOriginIds)
|
|
|
if _, err = s.webForwardingRepository.AddWebForwardingIps(ctx, *webRuleModel); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
if req.WebForwardingData.Domain != "" {
|
|
|
// 异步任务:将域名添加到白名单
|
|
|
doMain, err := s.wafformatter.ConvertToWildcardDomain(ctx, req.WebForwardingData.Domain)
|
|
@@ -409,7 +421,7 @@ func (s *webForwardingService) AddWebForwarding(ctx context.Context, req *v1.Web
|
|
|
if len(require.GatewayIps) == 0 {
|
|
|
return fmt.Errorf("网关组不存在")
|
|
|
}
|
|
|
- firstIp,err := s.GetGatewayFirstIp(ctx, require.HostId)
|
|
|
+ firstIp, err := s.GetGatewayFirstIp(ctx, require.HostId)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -425,15 +437,11 @@ func (s *webForwardingService) AddWebForwarding(ctx context.Context, req *v1.Web
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- ips = append(ips,ip)
|
|
|
+ ips = append(ips, ip)
|
|
|
}
|
|
|
- go s.wafformatter.PublishIpWhitelistTask(ips, "add","","white")
|
|
|
+ go s.wafformatter.PublishIpWhitelistTask(ips, "add", "", "white")
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
return nil
|
|
|
}
|
|
|
|
|
@@ -441,7 +449,7 @@ func (s *webForwardingService) EditWebForwarding(ctx context.Context, req *v1.We
|
|
|
|
|
|
require, formData, err := s.prepareWafData(ctx, req)
|
|
|
if err != nil {
|
|
|
- return err
|
|
|
+ return err
|
|
|
}
|
|
|
|
|
|
oldData, err := s.webForwardingRepository.GetWebForwarding(ctx, int64(req.WebForwardingData.Id))
|
|
@@ -456,7 +464,7 @@ func (s *webForwardingService) EditWebForwarding(ctx context.Context, req *v1.We
|
|
|
if req.WebForwardingData.IsHttps == isHttps {
|
|
|
typeJson = formData.HttpsJSON
|
|
|
apiType = protocolHttps
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
typeJson = formData.HttpJSON
|
|
|
apiType = protocolHttp
|
|
|
}
|
|
@@ -471,7 +479,7 @@ func (s *webForwardingService) EditWebForwarding(ctx context.Context, req *v1.We
|
|
|
|
|
|
//修改网站域名
|
|
|
if oldData.Domain != req.WebForwardingData.Domain {
|
|
|
- type serverName struct{
|
|
|
+ type serverName struct {
|
|
|
Name string `json:"name" form:"name"`
|
|
|
Type string `json:"type" form:"type"`
|
|
|
}
|
|
@@ -486,7 +494,7 @@ func (s *webForwardingService) EditWebForwarding(ctx context.Context, req *v1.We
|
|
|
return err
|
|
|
}
|
|
|
err = s.cdn.EditServerName(ctx, v1.EditServerNames{
|
|
|
- ServerId: int64(oldData.CdnWebId),
|
|
|
+ ServerId: int64(oldData.CdnWebId),
|
|
|
ServerNamesJSON: serverJson,
|
|
|
})
|
|
|
if err != nil {
|
|
@@ -502,9 +510,6 @@ func (s *webForwardingService) EditWebForwarding(ctx context.Context, req *v1.We
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
// 将域名添加到白名单
|
|
|
webData, err := s.webForwardingRepository.GetWebForwarding(ctx, int64(req.WebForwardingData.Id))
|
|
|
if err != nil {
|
|
@@ -513,7 +518,7 @@ func (s *webForwardingService) EditWebForwarding(ctx context.Context, req *v1.We
|
|
|
|
|
|
// 异步任务:将域名添加到白名单
|
|
|
if webData.Domain != req.WebForwardingData.Domain {
|
|
|
- firstIp,err := s.GetGatewayFirstIp(ctx, req.HostId)
|
|
|
+ firstIp, err := s.GetGatewayFirstIp(ctx, req.HostId)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -565,7 +570,7 @@ func (s *webForwardingService) EditWebForwarding(ctx context.Context, req *v1.We
|
|
|
}
|
|
|
addedIps, removedIps := s.wafformatter.findIpDifferences(oldIps, newIps)
|
|
|
if len(addedIps) > 0 {
|
|
|
- go s.wafformatter.PublishIpWhitelistTask(addedIps, "add","","white")
|
|
|
+ go s.wafformatter.PublishIpWhitelistTask(addedIps, "add", "", "white")
|
|
|
}
|
|
|
|
|
|
// IP过白
|
|
@@ -582,8 +587,6 @@ func (s *webForwardingService) EditWebForwarding(ctx context.Context, req *v1.We
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
//修改源站
|
|
|
addOrigins, delOrigins := s.FindDifferenceList(ipData.BackendList, req.WebForwardingData.BackendList)
|
|
|
addedIds := make(map[string]int64)
|
|
@@ -591,14 +594,14 @@ func (s *webForwardingService) EditWebForwarding(ctx context.Context, req *v1.We
|
|
|
var apiType string
|
|
|
if v.IsHttps == isHttps {
|
|
|
apiType = protocolHttps
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
apiType = protocolHttp
|
|
|
}
|
|
|
- id, err := s.wafformatter.AddOrigin(ctx,v1.WebJson{
|
|
|
- ApiType: apiType,
|
|
|
+ id, err := s.wafformatter.AddOrigin(ctx, v1.WebJson{
|
|
|
+ ApiType: apiType,
|
|
|
BackendList: v.Addr,
|
|
|
- Host: v.CustomHost,
|
|
|
- Comment: req.WebForwardingData.Comment,
|
|
|
+ Host: v.CustomHost,
|
|
|
+ Comment: req.WebForwardingData.Comment,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return err
|
|
@@ -612,7 +615,6 @@ func (s *webForwardingService) EditWebForwarding(ctx context.Context, req *v1.We
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
for k, v := range ipData.CdnOriginIds {
|
|
|
for _, ip := range delOrigins {
|
|
|
if k == ip.Addr {
|
|
@@ -632,7 +634,7 @@ func (s *webForwardingService) EditWebForwarding(ctx context.Context, req *v1.We
|
|
|
if err = s.webForwardingRepository.EditWebForwarding(ctx, webModel); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- webRuleModel := s.buildWebRuleModel(&req.WebForwardingData, require, req.WebForwardingData.Id,ipData.CdnOriginIds)
|
|
|
+ webRuleModel := s.buildWebRuleModel(&req.WebForwardingData, require, req.WebForwardingData.Id, ipData.CdnOriginIds)
|
|
|
if err = s.webForwardingRepository.EditWebForwardingIps(ctx, *webRuleModel); err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -651,12 +653,8 @@ func (s *webForwardingService) DeleteWebForwarding(ctx context.Context, Ids []in
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
// 异步任务:将域名添加到白名单
|
|
|
- firstIp,err := s.GetGatewayFirstIp(ctx, oldData.HostId)
|
|
|
+ firstIp, err := s.GetGatewayFirstIp(ctx, oldData.HostId)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -666,7 +664,7 @@ func (s *webForwardingService) DeleteWebForwarding(ctx context.Context, Ids []in
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- go s.wafformatter.PublishDomainWhitelistTask(doMain,firstIp, "del")
|
|
|
+ go s.wafformatter.PublishDomainWhitelistTask(doMain, firstIp, "del")
|
|
|
}
|
|
|
// IP过白
|
|
|
ipData, err := s.webForwardingRepository.GetWebForwardingIpsByID(ctx, Id)
|
|
@@ -695,10 +693,6 @@ func (s *webForwardingService) DeleteWebForwarding(ctx context.Context, Ids []in
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
if err = s.webForwardingRepository.DeleteWebForwarding(ctx, int64(Id)); err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -752,7 +746,6 @@ func (s *webForwardingService) GetWebForwardingWafWebAllIps(ctx context.Context,
|
|
|
return localErr
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// 2. 获取 Backend IP 信息
|
|
|
// 注意:这里我们允许 GetWebForwardingIpsByID 可能返回 nil 数据(例如没有规则)而不是错误
|
|
|
// 如果它也可能返回错误,则处理方式与上面类似
|
|
@@ -807,15 +800,14 @@ func (s *webForwardingService) GetWebForwardingWafWebAllIps(ctx context.Context,
|
|
|
return nil, fmt.Errorf("received nil forwarding from goroutine for ID %d", res.Id)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
dataReq := v1.WebForwardingDataRequest{
|
|
|
- Id: res.Forwarding.Id,
|
|
|
- Port: res.Forwarding.Port,
|
|
|
- Domain: res.Forwarding.Domain,
|
|
|
- IsHttps: res.Forwarding.IsHttps,
|
|
|
- Comment: res.Forwarding.Comment,
|
|
|
- HttpsKey: res.Forwarding.HttpsKey,
|
|
|
- HttpsCert: res.Forwarding.HttpsCert,
|
|
|
+ Id: res.Forwarding.Id,
|
|
|
+ Port: res.Forwarding.Port,
|
|
|
+ Domain: res.Forwarding.Domain,
|
|
|
+ IsHttps: res.Forwarding.IsHttps,
|
|
|
+ Comment: res.Forwarding.Comment,
|
|
|
+ HttpsKey: res.Forwarding.HttpsKey,
|
|
|
+ HttpsCert: res.Forwarding.HttpsCert,
|
|
|
}
|
|
|
|
|
|
if res.BackendRule != nil { // 只有当 BackendRule 存在时才填充相关字段
|
|
@@ -836,37 +828,36 @@ func (s *webForwardingService) GetGatewayFirstIp(ctx context.Context, hostId int
|
|
|
return "", err
|
|
|
}
|
|
|
if gateWayGroup == nil {
|
|
|
- return "",fmt.Errorf("网关组不存在")
|
|
|
+ return "", fmt.Errorf("网关组不存在")
|
|
|
}
|
|
|
gateWayIps, err := s.gatewayGroupIpRep.GetGateWayGroupFirstIpByGatewayGroupId(ctx, gateWayGroup.Id)
|
|
|
if err != nil {
|
|
|
return "", err
|
|
|
}
|
|
|
if len(gateWayIps) == 0 {
|
|
|
- return "",fmt.Errorf("网关组IP为空")
|
|
|
+ return "", fmt.Errorf("网关组IP为空")
|
|
|
}
|
|
|
return gateWayIps, nil
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// 清洗IP
|
|
|
-func (s *webForwardingService) WashDifferentIp(newIpList []string, oldIpList []string) (addedDenyIps []string,removedDenyIps []string) {
|
|
|
+func (s *webForwardingService) WashDifferentIp(newIpList []string, oldIpList []string) (addedDenyIps []string, removedDenyIps []string) {
|
|
|
var newAllowIps []string
|
|
|
var oldAllowIps []string
|
|
|
if len(oldIpList) > 0 {
|
|
|
for _, v := range oldIpList {
|
|
|
- if net.ParseIP(v) != nil{
|
|
|
+ if net.ParseIP(v) != nil {
|
|
|
oldAllowIps = append(oldAllowIps, v)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if len(newIpList) > 0 {
|
|
|
for _, v := range newIpList {
|
|
|
- if net.ParseIP(v) != nil{
|
|
|
+ if net.ParseIP(v) != nil {
|
|
|
newAllowIps = append(newAllowIps, v)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
addedDenyIps, removedDenyIps = s.wafformatter.findIpDifferences(oldAllowIps, newAllowIps)
|
|
|
return addedDenyIps, removedDenyIps
|
|
|
-}
|
|
|
+}
|