From c9d5e38db275b052944e5f9ea0e47c55a49e9c9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Sat, 16 Mar 2024 08:59:24 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9B=86=E7=BE=A4=E8=AE=BE=E7=BD=AE--=E7=BD=91?= =?UTF-8?q?=E7=AB=99=E8=AE=BE=E7=BD=AE=E4=B8=AD=E2=80=9C=E5=A4=84=E7=90=86?= =?UTF-8?q?=E6=9C=AA=E7=BB=91=E5=AE=9A=E5=9F=9F=E5=90=8D=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=E2=80=9D=E6=94=AF=E6=8C=81=E8=B7=B3=E8=BD=AC=E5=88=B0=E7=BD=91?= =?UTF-8?q?=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../settings/global-server-config/index.go | 31 +++++++++++++++++-- .../settings/global-server-config/index.html | 13 +++++++- 2 files changed, 41 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 16427821..faaa4dd2 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 @@ -46,6 +46,9 @@ func (this *IndexAction) RunGet(params struct { var httpAllDomainMismatchActionCode = serverconfigs.DomainMismatchActionPage var httpAllDomainMismatchActionContentHTML string var httpAllDomainMismatchActionStatusCode = "404" + + var httpAllDomainMismatchActionRedirectURL = "" + if config.HTTPAll.DomainMismatchAction != nil { httpAllDomainMismatchActionCode = config.HTTPAll.DomainMismatchAction.Code @@ -56,6 +59,10 @@ func (this *IndexAction) RunGet(params struct { if statusCode > 0 { httpAllDomainMismatchActionStatusCode = types.String(statusCode) } + + if config.HTTPAll.DomainMismatchAction.Code == serverconfigs.DomainMismatchActionRedirect { + httpAllDomainMismatchActionRedirectURL = config.HTTPAll.DomainMismatchAction.Options.GetString("url") + } } } else { httpAllDomainMismatchActionContentHTML = ` @@ -83,6 +90,8 @@ p { color: grey; } this.Data["httpAllDomainMismatchActionContentHTML"] = httpAllDomainMismatchActionContentHTML this.Data["httpAllDomainMismatchActionStatusCode"] = httpAllDomainMismatchActionStatusCode + this.Data["httpAllDomainMismatchActionRedirectURL"] = httpAllDomainMismatchActionRedirectURL + this.Show() } @@ -93,6 +102,7 @@ func (this *IndexAction) RunPost(params struct { HttpAllDomainMismatchActionCode string HttpAllDomainMismatchActionContentHTML string HttpAllDomainMismatchActionStatusCode string + HttpAllDomainMismatchActionRedirectURL string HttpAllAllowMismatchDomainsJSON []byte HttpAllAllowNodeIP bool HttpAllDefaultDomain string @@ -156,11 +166,28 @@ func (this *IndexAction) RunPost(params struct { var domainMisMatchStatusCode = types.Int(domainMisMatchStatusCodeString) config.HTTPAll.MatchDomainStrictly = params.HttpAllMatchDomainStrictly + + // validate + if config.HTTPAll.MatchDomainStrictly { + // validate redirect + if params.HttpAllDomainMismatchActionCode == serverconfigs.DomainMismatchActionRedirect { + if len(params.HttpAllDomainMismatchActionRedirectURL) == 0 { + this.FailField("httpAllDomainMismatchActionRedirectURL", "请输入跳转目标网址URL") + return + } + if !regexp.MustCompile(`(?i)(http|https)://`).MatchString(params.HttpAllDomainMismatchActionRedirectURL) { + this.FailField("httpAllDomainMismatchActionRedirectURL", "目标网址URL必须以http://或https://开头") + return + } + } + } + config.HTTPAll.DomainMismatchAction = &serverconfigs.DomainMismatchAction{ Code: params.HttpAllDomainMismatchActionCode, Options: maps.Map{ - "statusCode": domainMisMatchStatusCode, - "contentHTML": params.HttpAllDomainMismatchActionContentHTML, + "statusCode": domainMisMatchStatusCode, // page + "contentHTML": params.HttpAllDomainMismatchActionContentHTML, // page + "url": params.HttpAllDomainMismatchActionRedirectURL, // redirect }, } 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 bbf8eba6..b09fe1a2 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 @@ -27,8 +27,11 @@ 处理未绑定域名方式 显示提示页面   -   关闭连接 +   跳转到网址   + 关闭连接 +

显示提示内容。

+

跳转到一个特定URL。

直接关闭网络连接,不提示任何内容。

@@ -48,6 +51,14 @@ + + 跳转目标网址URL * + + +

必须以http://或者https://开头,支持使用变量。

+ + + 允许例外的域名