mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-16 05:30:27 +08:00
找不到匹配的域名时可以指定默认域名、指定不匹配时的处理动作
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -45,6 +46,14 @@ func (this *IndexAction) RunGet(params struct{}) {
|
||||
func (this *IndexAction) RunPost(params struct {
|
||||
GlobalConfigJSON []byte
|
||||
Must *actions.Must
|
||||
|
||||
// 不匹配域名相关
|
||||
AllowMismatchDomains []string
|
||||
DomainMismatchAction string
|
||||
DomainMismatchActionPageStatusCode int
|
||||
DomainMismatchActionPageContentHTML string
|
||||
|
||||
DefaultDomain string
|
||||
}) {
|
||||
// 创建日志
|
||||
this.CreateLog(oplogs.LevelInfo, "保存代理服务全局配置")
|
||||
@@ -59,10 +68,44 @@ func (this *IndexAction) RunPost(params struct {
|
||||
this.Fail("配置校验失败:" + err.Error())
|
||||
}
|
||||
|
||||
// 允许不匹配的域名
|
||||
allowMismatchDomains := []string{}
|
||||
for _, domain := range params.AllowMismatchDomains {
|
||||
if len(domain) > 0 {
|
||||
allowMismatchDomains = append(allowMismatchDomains, domain)
|
||||
}
|
||||
}
|
||||
globalConfig.HTTPAll.AllowMismatchDomains = allowMismatchDomains
|
||||
|
||||
// 不匹配域名的动作
|
||||
switch params.DomainMismatchAction {
|
||||
case "close":
|
||||
globalConfig.HTTPAll.DomainMismatchAction = &serverconfigs.DomainMismatchAction{
|
||||
Code: "close",
|
||||
Options: nil,
|
||||
}
|
||||
case "page":
|
||||
if params.DomainMismatchActionPageStatusCode <= 0 {
|
||||
params.DomainMismatchActionPageStatusCode = 404
|
||||
}
|
||||
globalConfig.HTTPAll.DomainMismatchAction = &serverconfigs.DomainMismatchAction{
|
||||
Code: "page",
|
||||
Options: maps.Map{
|
||||
"statusCode": params.DomainMismatchActionPageStatusCode,
|
||||
"contentHTML": params.DomainMismatchActionPageContentHTML,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// 修改配置
|
||||
globalConfigJSON, err := json.Marshal(globalConfig)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
|
||||
Code: SettingCodeServerGlobalConfig,
|
||||
ValueJSON: params.GlobalConfigJSON,
|
||||
ValueJSON: globalConfigJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Vue.component("values-box", {
|
||||
props: ["values", "size", "maxlength", "name"],
|
||||
props: ["values", "size", "maxlength", "name", "placeholder"],
|
||||
data: function () {
|
||||
let values = this.values;
|
||||
if (values == null) {
|
||||
@@ -32,6 +32,10 @@ Vue.component("values-box", {
|
||||
}, 200);
|
||||
},
|
||||
confirm: function () {
|
||||
if (this.value.length == 0) {
|
||||
return
|
||||
}
|
||||
|
||||
if (this.isUpdating) {
|
||||
Vue.set(this.vValues, this.index, this.value);
|
||||
} else {
|
||||
@@ -50,30 +54,31 @@ Vue.component("values-box", {
|
||||
this.value = "";
|
||||
}
|
||||
},
|
||||
template: '<div>\
|
||||
<div style="margin-bottom: 1em" v-if="vValues.length > 0">\
|
||||
<div class="ui label tiny" v-for="(value, index) in vValues" style="margin-top:0.4em;margin-bottom:0.4em">{{value}}\
|
||||
<input type="hidden" :name="name" :value="value"/>\
|
||||
<a href="" @click.prevent="update(index)" title="修改"><i class="icon pencil small" ></i></a> \
|
||||
<a href="" @click.prevent="remove(index)" title="删除"><i class="icon remove"></i></a> \
|
||||
</div> \
|
||||
</div> \
|
||||
template: `<div>
|
||||
<div style="margin-bottom: 1em" v-if="vValues.length > 0">
|
||||
<div class="ui label tiny" v-for="(value, index) in vValues" style="margin-top:0.4em;margin-bottom:0.4em">{{value}}
|
||||
<input type="hidden" :name="name" :value="value"/>
|
||||
<a href="" @click.prevent="update(index)" title="修改"><i class="icon pencil small" ></i></a>
|
||||
<a href="" @click.prevent="remove(index)" title="删除"><i class="icon remove"></i></a>
|
||||
</div>
|
||||
<div class="ui divider"></div>
|
||||
</div>
|
||||
<!-- 添加|修改 -->\
|
||||
<div v-if="isAdding || isUpdating">\
|
||||
<div class="ui fields inline">\
|
||||
<div class="ui field">\
|
||||
<input type="text" :size="size" :maxlength="maxlength" v-model="value" ref="value" @keyup.enter="confirm()" @keypress.enter.prevent="1"/>\
|
||||
</div> \
|
||||
<div class="ui field">\
|
||||
<button class="ui button small" type="button" @click.prevent="confirm()">确定</button> \
|
||||
</div>\
|
||||
<div class="ui field">\
|
||||
<a href="" @click.prevent="cancel()">取消</a> \
|
||||
</div> \
|
||||
</div> \
|
||||
</div> \
|
||||
<div v-if="!isAdding && !isUpdating">\
|
||||
<button class="ui button small" type="button" @click.prevent="create()">+</button> \
|
||||
</div>\
|
||||
</div>'
|
||||
<div v-if="isAdding || isUpdating">
|
||||
<div class="ui fields inline">
|
||||
<div class="ui field">
|
||||
<input type="text" :size="size" :maxlength="maxlength" :placeholder="placeholder" v-model="value" ref="value" @keyup.enter="confirm()" @keypress.enter.prevent="1"/>
|
||||
</div>
|
||||
<div class="ui field">
|
||||
<button class="ui button small" type="button" @click.prevent="confirm()">确定</button>
|
||||
</div>
|
||||
<div class="ui field">
|
||||
<a href="" @click.prevent="cancel()">取消</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!isAdding && !isUpdating">
|
||||
<button class="ui button small" type="button" @click.prevent="create()">+</button>
|
||||
</div>
|
||||
</div>`
|
||||
});
|
||||
@@ -28,4 +28,7 @@ table th.width10 {
|
||||
table th.width5 {
|
||||
width: 5em;
|
||||
}
|
||||
textarea::-webkit-scrollbar {
|
||||
width: 6px !important;
|
||||
}
|
||||
/*# sourceMappingURL=@layout_override.css.map */
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"sources":["@layout_override.less"],"names":[],"mappings":"AACA,GAAG,OAAO,SAAU,MAAK,MAAM,QAAS,OAAM;AAAS,GAAG,OAAO,SAAU,MAAK,MAAM,QAAS,QAAO;EACrG,oCAAA;;AAGD,GAAG,OAAO,SAAU,MAAK,QAAS,OAAM;AAAS,GAAG,OAAO,SAAU,MAAK,QAAS,QAAO;EACzF,oCAAA;;AAGD,GAAG,MAAM;EACR,kCAAA;;AAID,IACC;EACC,2BAAA;;AAKF,KAAK;EACJ,sBAAA;;AAGD,KAAK,KAAK;EACT,yBAAA;;AAID,KACC,GAAE;AADH,KACY,GAAE;EACZ,6BAAA;;AAFF,KAKC,GAAE;EACD,WAAA;;AANF,KASC,GAAE;EACD,UAAA","file":"@layout_override.css"}
|
||||
{"version":3,"sources":["@layout_override.less"],"names":[],"mappings":"AACA,GAAG,OAAO,SAAU,MAAK,MAAM,QAAS,OAAM;AAAS,GAAG,OAAO,SAAU,MAAK,MAAM,QAAS,QAAO;EACrG,oCAAA;;AAGD,GAAG,OAAO,SAAU,MAAK,QAAS,OAAM;AAAS,GAAG,OAAO,SAAU,MAAK,QAAS,QAAO;EACzF,oCAAA;;AAGD,GAAG,MAAM;EACR,kCAAA;;AAID,IACC;EACC,2BAAA;;AAKF,KAAK;EACJ,sBAAA;;AAGD,KAAK,KAAK;EACT,yBAAA;;AAID,KACC,GAAE;AADH,KACY,GAAE;EACZ,6BAAA;;AAFF,KAKC,GAAE;EACD,WAAA;;AANF,KASC,GAAE;EACD,UAAA;;AAKF,QAAQ;EACP,qBAAA","file":"@layout_override.css"}
|
||||
@@ -41,3 +41,8 @@ table {
|
||||
width: 5em;
|
||||
}
|
||||
}
|
||||
|
||||
// textarea
|
||||
textarea::-webkit-scrollbar {
|
||||
width: 6px !important;
|
||||
}
|
||||
|
||||
@@ -9,13 +9,55 @@
|
||||
<td colspan="2">HTTP/HTTPS通用设置</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="title">是否严格匹配域名</td>
|
||||
<td class="title color-border">是否严格匹配域名</td>
|
||||
<td>
|
||||
<div class="ui checkbox">
|
||||
<input type="checkbox" name="matchDomainStrictly" value="1" v-model="globalConfig.httpAll.matchDomainStrictly"/>
|
||||
<label></label>
|
||||
</div>
|
||||
<p class="comment">如果选择了严格匹配域名,则没有在Edge里绑定过的域名访问时都会返回404。</p>
|
||||
<p class="comment">如果选择了严格匹配域名,找不到匹配的域名时会采取对应的动作。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="color-border">默认域名</td>
|
||||
<td>
|
||||
<input type="text" name="defaultDomain" v-model="globalConfig.httpAll.defaultDomain" maxlength="100"/>
|
||||
<p class="comment">当找不到匹配的域名时,自动使用此域名。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="color-border">允许不匹配的域名</td>
|
||||
<td>
|
||||
<values-box :name="'allowMismatchDomains'" :values="globalConfig.httpAll.allowMismatchDomains" :size="40" :maxlength="100" :placeholder="'域名'"></values-box>
|
||||
<p class="comment">允许这些域名即时不匹配也可以访问。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="color-border">域名不匹配时的动作</td>
|
||||
<td>
|
||||
<div class="ui checkbox radio">
|
||||
<input type="radio" name="domainMismatchAction" value="close" v-model="domainMismatchAction"/>
|
||||
<label>断开连接</label>
|
||||
</div>
|
||||
|
||||
<div class="ui checkbox radio">
|
||||
<input type="radio" name="domainMismatchAction" value="page" v-model="domainMismatchAction"/>
|
||||
<label>显示提示页面</label>
|
||||
</div>
|
||||
<p class="comment" v-if="domainMismatchAction == 'close'">当找不到要访问的域名时关闭客户端连接。</p>
|
||||
<p class="comment" v-if="domainMismatchAction == 'page'">当找不到访问的域名时显示一个提示页面。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="domainMismatchAction == 'page'">
|
||||
<td class="color-border">响应代码</td>
|
||||
<td>
|
||||
<input type="text" name="domainMismatchActionPageStatusCode" v-model="domainMismatchActionPageOptions.statusCode" style="width:4em" maxlength="3"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="domainMismatchAction == 'page'">
|
||||
<td class="color-border">域名不匹配时的动作页面</td>
|
||||
<td>
|
||||
<textarea name="domainMismatchActionPageContentHTML" v-model="domainMismatchActionPageOptions.contentHTML" rows="3"></textarea>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@@ -1,3 +1,32 @@
|
||||
Tea.context(function () {
|
||||
this.success = NotifyReloadSuccess("保存成功")
|
||||
|
||||
/**
|
||||
* 域名不匹配动作
|
||||
*/
|
||||
this.domainMismatchAction = "page"
|
||||
|
||||
this.domainMismatchActionPageOptions = {
|
||||
statusCode: 404,
|
||||
contentHTML: `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<title>404 not found</title>
|
||||
</head>
|
||||
<body>
|
||||
<h4>找不到您要访问的页面.</h4>
|
||||
<h4>Sorry, page not found.</h4>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
}
|
||||
if (this.globalConfig.httpAll.domainMismatchAction != null) {
|
||||
this.domainMismatchAction = this.globalConfig.httpAll.domainMismatchAction.code
|
||||
|
||||
if (this.domainMismatchAction == "page") {
|
||||
this.domainMismatchActionPageOptions = this.globalConfig.httpAll.domainMismatchAction.options;
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user