集群设置--网站设置中“处理未绑定域名方式”支持跳转到网址

This commit is contained in:
刘祥超
2024-03-16 08:59:24 +08:00
parent 996adc37ff
commit c9d5e38db2
2 changed files with 41 additions and 3 deletions

View File

@@ -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 = `<!DOCTYPE html>
@@ -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
},
}

View File

@@ -27,8 +27,11 @@
<td class="color-border">处理未绑定域名方式</td>
<td>
<radio name="httpAllDomainMismatchActionCode" :v-value="'page'" v-model="httpAllDomainMismatchActionCode">显示提示页面</radio> &nbsp;
&nbsp; <radio name="httpAllDomainMismatchActionCode" :v-value="'close'" v-model="httpAllDomainMismatchActionCode">关闭连接</radio>
&nbsp; <radio name="httpAllDomainMismatchActionCode" :v-value="'redirect'" v-model="httpAllDomainMismatchActionCode">跳转到网址</radio> &nbsp;
<radio name="httpAllDomainMismatchActionCode" :v-value="'close'" v-model="httpAllDomainMismatchActionCode">关闭连接</radio>
<p class="comment" v-if="httpAllDomainMismatchActionCode == 'page'">显示提示内容。</p>
<p class="comment" v-if="httpAllDomainMismatchActionCode == 'redirect'">跳转到一个特定URL。</p>
<p class="comment" v-if="httpAllDomainMismatchActionCode == 'close'">直接关闭网络连接,不提示任何内容。</p>
</td>
</tr>
@@ -48,6 +51,14 @@
</td>
</tr>
<tr v-show="config.httpAll.matchDomainStrictly && httpAllDomainMismatchActionCode == 'redirect'">
<td class="color-border">跳转目标网址URL *</td>
<td>
<input type="text" placeholder="https://..." name="httpAllDomainMismatchActionRedirectURL" v-model="httpAllDomainMismatchActionRedirectURL"/>
<p class="comment">必须以http://或者https://开头,支持使用变量。</p>
</td>
</tr>
<tr v-show="config.httpAll.matchDomainStrictly">
<td>允许例外的域名</td>
<td>