diff --git a/internal/web/actions/default/servers/server/settings/http/index.go b/internal/web/actions/default/servers/server/settings/http/index.go index 3e3c6e50..eacb4379 100644 --- a/internal/web/actions/default/servers/server/settings/http/index.go +++ b/internal/web/actions/default/servers/server/settings/http/index.go @@ -9,6 +9,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/types" "regexp" @@ -30,7 +31,7 @@ func (this *IndexAction) RunGet(params struct { if !isOk { return } - httpConfig := &serverconfigs.HTTPProtocolConfig{} + var httpConfig = &serverconfigs.HTTPProtocolConfig{} if len(server.HttpJSON) > 0 { err := json.Unmarshal(server.HttpJSON, httpConfig) if err != nil { @@ -40,6 +41,26 @@ func (this *IndexAction) RunGet(params struct { } else { httpConfig.IsOn = true } + _ = httpConfig.Init() + var httpPorts = httpConfig.AllPorts() + + // 检查http和https端口冲突 + var conflictingPorts = []int{} + if len(server.HttpsJSON) > 0 { + var httpsConfig = &serverconfigs.HTTPSProtocolConfig{} + err := json.Unmarshal(server.HttpsJSON, httpsConfig) + if err != nil { + this.ErrorPage(err) + return + } + _ = httpsConfig.Init() + for _, port := range httpsConfig.AllPorts() { + if lists.ContainsInt(httpPorts, port) { + conflictingPorts = append(conflictingPorts, port) + } + } + } + this.Data["conflictingPorts"] = conflictingPorts this.Data["serverType"] = server.Type this.Data["httpConfig"] = maps.Map{ diff --git a/internal/web/actions/default/servers/server/settings/https/index.go b/internal/web/actions/default/servers/server/settings/https/index.go index e3f6363d..d0faf86d 100644 --- a/internal/web/actions/default/servers/server/settings/https/index.go +++ b/internal/web/actions/default/servers/server/settings/https/index.go @@ -10,6 +10,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs" "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/types" "regexp" @@ -42,6 +43,27 @@ func (this *IndexAction) RunGet(params struct { httpsConfig.IsOn = true } + _ = httpsConfig.Init() + var httpsPorts = httpsConfig.AllPorts() + + // 检查http和https端口冲突 + var conflictingPorts = []int{} + if len(server.HttpJSON) > 0 { + var httpConfig = &serverconfigs.HTTPProtocolConfig{} + err := json.Unmarshal(server.HttpJSON, httpConfig) + if err != nil { + this.ErrorPage(err) + return + } + _ = httpConfig.Init() + for _, port := range httpConfig.AllPorts() { + if lists.ContainsInt(httpsPorts, port) { + conflictingPorts = append(conflictingPorts, port) + } + } + } + this.Data["conflictingPorts"] = conflictingPorts + var sslPolicy *sslconfigs.SSLPolicy if httpsConfig.SSLPolicyRef != nil && httpsConfig.SSLPolicyRef.SSLPolicyId > 0 { sslPolicyConfigResp, err := this.RPC().SSLPolicyRPC().FindEnabledSSLPolicyConfig(this.AdminContext(), &pb.FindEnabledSSLPolicyConfigRequest{ diff --git a/web/views/@default/servers/server/settings/http/index.html b/web/views/@default/servers/server/settings/http/index.html index bf0f1bd3..9e042f25 100644 --- a/web/views/@default/servers/server/settings/http/index.html +++ b/web/views/@default/servers/server/settings/http/index.html @@ -23,6 +23,7 @@ 还没有添加端口绑定,会导致HTTP服务无法访问。 +

配置错误:{{port}}端口同HTTPS设置的端口冲突,请删除HTTP或HTTPS中的相关端口。

diff --git a/web/views/@default/servers/server/settings/https/index.html b/web/views/@default/servers/server/settings/https/index.html index d7303e5e..0ab2afc3 100644 --- a/web/views/@default/servers/server/settings/https/index.html +++ b/web/views/@default/servers/server/settings/https/index.html @@ -29,6 +29,7 @@ 还没有添加端口绑定,会导致HTTPS服务无法访问。 +

配置错误:{{port}}端口同HTTP设置的端口冲突,请删除HTTP或HTTPS中的相关端口。