From 3ed8f9ca55ab6802563b5b5a46c27e535b70dfea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Thu, 27 Jul 2023 11:23:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E4=BF=AE=E6=94=B9=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E6=9C=AA=E7=BB=91=E5=AE=9A=E5=9F=9F=E5=90=8D=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E6=8F=90=E7=A4=BA=E9=A1=B5=E9=9D=A2=E7=9A=84=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../settings/global-server-config/index.go | 20 +++++++++++++++++-- .../settings/global-server-config/index.html | 9 ++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/internal/web/actions/default/clusters/cluster/settings/global-server-config/index.go b/internal/web/actions/default/clusters/cluster/settings/global-server-config/index.go index 4b70695f..4a154f9e 100644 --- a/internal/web/actions/default/clusters/cluster/settings/global-server-config/index.go +++ b/internal/web/actions/default/clusters/cluster/settings/global-server-config/index.go @@ -10,6 +10,8 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/maps" + "github.com/iwind/TeaGo/types" + "regexp" ) type IndexAction struct { @@ -42,8 +44,13 @@ func (this *IndexAction) RunGet(params struct { this.Data["config"] = config var httpAllDomainMismatchActionContentHTML = "" - if config.HTTPAll.DomainMismatchAction != nil { + var httpAllDomainMismatchActionStatusCode = "404" + if config.HTTPAll.DomainMismatchAction != nil && config.HTTPAll.DomainMismatchAction.Options != nil { httpAllDomainMismatchActionContentHTML = config.HTTPAll.DomainMismatchAction.Options.GetString("contentHTML") + var statusCode = config.HTTPAll.DomainMismatchAction.Options.GetInt("statusCode") + if statusCode > 0 { + httpAllDomainMismatchActionStatusCode = types.String(statusCode) + } } else { httpAllDomainMismatchActionContentHTML = ` @@ -67,6 +74,7 @@ p { color: grey; } } this.Data["httpAllDomainMismatchActionContentHTML"] = httpAllDomainMismatchActionContentHTML + this.Data["httpAllDomainMismatchActionStatusCode"] = httpAllDomainMismatchActionStatusCode this.Show() } @@ -76,6 +84,7 @@ func (this *IndexAction) RunPost(params struct { HttpAllMatchDomainStrictly bool HttpAllDomainMismatchActionContentHTML string + HttpAllDomainMismatchActionStatusCode string HttpAllAllowMismatchDomainsJSON []byte HttpAllAllowNodeIP bool HttpAllDefaultDomain string @@ -121,11 +130,18 @@ func (this *IndexAction) RunPost(params struct { } } + var domainMisMatchStatusCodeString = params.HttpAllDomainMismatchActionStatusCode + if !regexp.MustCompile(`^\d{3}$`).MatchString(domainMisMatchStatusCodeString) { + this.FailField("httpAllDomainMismatchActionContentStatusCode", "请输入正确的状态码") + return + } + var domainMisMatchStatusCode = types.Int(domainMisMatchStatusCodeString) + config.HTTPAll.MatchDomainStrictly = params.HttpAllMatchDomainStrictly config.HTTPAll.DomainMismatchAction = &serverconfigs.DomainMismatchAction{ Code: serverconfigs.DomainMismatchActionPage, Options: maps.Map{ - "statusCode": 404, + "statusCode": domainMisMatchStatusCode, "contentHTML": params.HttpAllDomainMismatchActionContentHTML, }, } diff --git a/web/views/@default/clusters/cluster/settings/global-server-config/index.html b/web/views/@default/clusters/cluster/settings/global-server-config/index.html index eadb5d64..fa0b7b47 100644 --- a/web/views/@default/clusters/cluster/settings/global-server-config/index.html +++ b/web/views/@default/clusters/cluster/settings/global-server-config/index.html @@ -17,6 +17,13 @@

选中后,表示禁止未绑定的域名和IP访问。

+ + 提示页面状态码 + + +

默认404。

+ + 未绑定域名页面提示 @@ -35,7 +42,7 @@ 默认域名 -

例外域名或使用节点IP访问时使用的默认域名。

+

例外域名或使用节点IP访问时使用的默认域名;如果指定的域名在集群里已经绑定到某个网站,则相当于直接访问该网站。