Skip to content

Commit c9d5e38

Browse files
committed
集群设置--网站设置中“处理未绑定域名方式”支持跳转到网址
1 parent 996adc3 commit c9d5e38

File tree

2 files changed

+41
-3
lines changed
  • internal/web/actions/default/clusters/cluster/settings/global-server-config
  • web/views/@default/clusters/cluster/settings/global-server-config

2 files changed

+41
-3
lines changed

internal/web/actions/default/clusters/cluster/settings/global-server-config/index.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ func (this *IndexAction) RunGet(params struct {
4646
var httpAllDomainMismatchActionCode = serverconfigs.DomainMismatchActionPage
4747
var httpAllDomainMismatchActionContentHTML string
4848
var httpAllDomainMismatchActionStatusCode = "404"
49+
50+
var httpAllDomainMismatchActionRedirectURL = ""
51+
4952
if config.HTTPAll.DomainMismatchAction != nil {
5053
httpAllDomainMismatchActionCode = config.HTTPAll.DomainMismatchAction.Code
5154

@@ -56,6 +59,10 @@ func (this *IndexAction) RunGet(params struct {
5659
if statusCode > 0 {
5760
httpAllDomainMismatchActionStatusCode = types.String(statusCode)
5861
}
62+
63+
if config.HTTPAll.DomainMismatchAction.Code == serverconfigs.DomainMismatchActionRedirect {
64+
httpAllDomainMismatchActionRedirectURL = config.HTTPAll.DomainMismatchAction.Options.GetString("url")
65+
}
5966
}
6067
} else {
6168
httpAllDomainMismatchActionContentHTML = `<!DOCTYPE html>
@@ -83,6 +90,8 @@ p { color: grey; }
8390
this.Data["httpAllDomainMismatchActionContentHTML"] = httpAllDomainMismatchActionContentHTML
8491
this.Data["httpAllDomainMismatchActionStatusCode"] = httpAllDomainMismatchActionStatusCode
8592

93+
this.Data["httpAllDomainMismatchActionRedirectURL"] = httpAllDomainMismatchActionRedirectURL
94+
8695
this.Show()
8796
}
8897

@@ -93,6 +102,7 @@ func (this *IndexAction) RunPost(params struct {
93102
HttpAllDomainMismatchActionCode string
94103
HttpAllDomainMismatchActionContentHTML string
95104
HttpAllDomainMismatchActionStatusCode string
105+
HttpAllDomainMismatchActionRedirectURL string
96106
HttpAllAllowMismatchDomainsJSON []byte
97107
HttpAllAllowNodeIP bool
98108
HttpAllDefaultDomain string
@@ -156,11 +166,28 @@ func (this *IndexAction) RunPost(params struct {
156166
var domainMisMatchStatusCode = types.Int(domainMisMatchStatusCodeString)
157167

158168
config.HTTPAll.MatchDomainStrictly = params.HttpAllMatchDomainStrictly
169+
170+
// validate
171+
if config.HTTPAll.MatchDomainStrictly {
172+
// validate redirect
173+
if params.HttpAllDomainMismatchActionCode == serverconfigs.DomainMismatchActionRedirect {
174+
if len(params.HttpAllDomainMismatchActionRedirectURL) == 0 {
175+
this.FailField("httpAllDomainMismatchActionRedirectURL", "请输入跳转目标网址URL")
176+
return
177+
}
178+
if !regexp.MustCompile(`(?i)(http|https)://`).MatchString(params.HttpAllDomainMismatchActionRedirectURL) {
179+
this.FailField("httpAllDomainMismatchActionRedirectURL", "目标网址URL必须以http://或https://开头")
180+
return
181+
}
182+
}
183+
}
184+
159185
config.HTTPAll.DomainMismatchAction = &serverconfigs.DomainMismatchAction{
160186
Code: params.HttpAllDomainMismatchActionCode,
161187
Options: maps.Map{
162-
"statusCode": domainMisMatchStatusCode,
163-
"contentHTML": params.HttpAllDomainMismatchActionContentHTML,
188+
"statusCode": domainMisMatchStatusCode, // page
189+
"contentHTML": params.HttpAllDomainMismatchActionContentHTML, // page
190+
"url": params.HttpAllDomainMismatchActionRedirectURL, // redirect
164191
},
165192
}
166193

web/views/@default/clusters/cluster/settings/global-server-config/index.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ <h4 id="title-server-name-bind">域名绑定</h4>
2727
<td class="color-border">处理未绑定域名方式</td>
2828
<td>
2929
<radio name="httpAllDomainMismatchActionCode" :v-value="'page'" v-model="httpAllDomainMismatchActionCode">显示提示页面</radio> &nbsp;
30-
&nbsp; <radio name="httpAllDomainMismatchActionCode" :v-value="'close'" v-model="httpAllDomainMismatchActionCode">关闭连接</radio>
30+
&nbsp; <radio name="httpAllDomainMismatchActionCode" :v-value="'redirect'" v-model="httpAllDomainMismatchActionCode">跳转到网址</radio> &nbsp;
31+
<radio name="httpAllDomainMismatchActionCode" :v-value="'close'" v-model="httpAllDomainMismatchActionCode">关闭连接</radio>
32+
3133
<p class="comment" v-if="httpAllDomainMismatchActionCode == 'page'">显示提示内容。</p>
34+
<p class="comment" v-if="httpAllDomainMismatchActionCode == 'redirect'">跳转到一个特定URL。</p>
3235
<p class="comment" v-if="httpAllDomainMismatchActionCode == 'close'">直接关闭网络连接,不提示任何内容。</p>
3336
</td>
3437
</tr>
@@ -48,6 +51,14 @@ <h4 id="title-server-name-bind">域名绑定</h4>
4851
</td>
4952
</tr>
5053

54+
<tr v-show="config.httpAll.matchDomainStrictly && httpAllDomainMismatchActionCode == 'redirect'">
55+
<td class="color-border">跳转目标网址URL *</td>
56+
<td>
57+
<input type="text" placeholder="https://..." name="httpAllDomainMismatchActionRedirectURL" v-model="httpAllDomainMismatchActionRedirectURL"/>
58+
<p class="comment">必须以http://或者https://开头,支持使用变量。</p>
59+
</td>
60+
</tr>
61+
5162
<tr v-show="config.httpAll.matchDomainStrictly">
5263
<td>允许例外的域名</td>
5364
<td>

0 commit comments

Comments
 (0)