From 79fa76e039efcd606687a15aba96ab0600eb87ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Wed, 13 Dec 2023 18:33:48 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=93=E5=AD=98=E8=AE=BE=E7=BD=AE=E4=B8=AD?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E8=AE=BE=E7=BD=AE=E7=BC=93=E5=AD=98=E4=B8=BB?= =?UTF-8?q?=E5=9F=9F=E5=90=8D=EF=BC=8C=E7=94=A8=E6=9D=A5=E5=A4=8D=E7=94=A8?= =?UTF-8?q?=E5=A4=9A=E5=9F=9F=E5=90=8D=E4=B8=8B=E7=9A=84=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../groups/group/settings/cache/index.go | 6 +- .../servers/server/settings/cache/index.go | 44 ++++++++++++++ .../server/settings/locations/cache/index.go | 47 ++++++++++++++- .../server/http-cache-config-box.js | 59 ++++++++++++++++++- 4 files changed, 152 insertions(+), 4 deletions(-) diff --git a/internal/web/actions/default/servers/groups/group/settings/cache/index.go b/internal/web/actions/default/servers/groups/group/settings/cache/index.go index af697b3d..6aa233a8 100644 --- a/internal/web/actions/default/servers/groups/group/settings/cache/index.go +++ b/internal/web/actions/default/servers/groups/group/settings/cache/index.go @@ -53,12 +53,16 @@ func (this *IndexAction) RunPost(params struct { defer this.CreateLogInfo(codes.ServerCache_LogUpdateCacheSettings, params.WebId) // 校验配置 - cacheConfig := &serverconfigs.HTTPCacheConfig{} + var cacheConfig = &serverconfigs.HTTPCacheConfig{} err := json.Unmarshal(params.CacheJSON, cacheConfig) if err != nil { this.ErrorPage(err) return } + + // 分组不支持主域名 + cacheConfig.Key = nil + err = cacheConfig.Init() if err != nil { this.Fail("检查配置失败:" + err.Error()) diff --git a/internal/web/actions/default/servers/server/settings/cache/index.go b/internal/web/actions/default/servers/server/settings/cache/index.go index 2fa314a7..9e30e6e9 100644 --- a/internal/web/actions/default/servers/server/settings/cache/index.go +++ b/internal/web/actions/default/servers/server/settings/cache/index.go @@ -4,6 +4,7 @@ import ( "encoding/json" "github.com/TeaOSLab/EdgeAdmin/internal/utils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dns/domains/domainutils" "github.com/TeaOSLab/EdgeCommon/pkg/langs/codes" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" @@ -12,6 +13,7 @@ import ( "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/types" + "strings" ) type IndexAction struct { @@ -92,6 +94,48 @@ func (this *IndexAction) RunPost(params struct { return } + // 检查Key + if cacheConfig.Key != nil && cacheConfig.Key.IsOn { + if cacheConfig.Key.Scheme != "http" && cacheConfig.Key.Scheme != "https" { + this.Fail("缓存主域名协议只能是http或者https") + return + } + if len(cacheConfig.Key.Host) == 0 { + this.Fail("请输入缓存主域名") + return + } + cacheConfig.Key.Host = strings.ToLower(strings.TrimSuffix(cacheConfig.Key.Host, "/")) + if !domainutils.ValidateDomainFormat(cacheConfig.Key.Host) { + this.Fail("请输入正确的缓存主域名") + return + } + + // 检查域名所属 + serverIdResp, err := this.RPC().HTTPWebRPC().FindServerIdWithHTTPWebId(this.AdminContext(), &pb.FindServerIdWithHTTPWebIdRequest{HttpWebId: params.WebId}) + if err != nil { + this.ErrorPage(err) + return + } + var serverId = serverIdResp.ServerId + if serverId <= 0 { + this.Fail("找不到要操作的网站") + return + } + + existServerNameResp, err := this.RPC().ServerRPC().CheckServerNameInServer(this.AdminContext(), &pb.CheckServerNameInServerRequest{ + ServerId: serverId, + ServerName: cacheConfig.Key.Host, + }) + if err != nil { + this.ErrorPage(err) + return + } + if !existServerNameResp.Exists { + this.Fail("域名 '" + cacheConfig.Key.Host + "' 在当前网站中并未绑定,不能作为缓存主域名") + return + } + } + err = cacheConfig.Init() if err != nil { this.Fail("检查配置失败:" + err.Error()) diff --git a/internal/web/actions/default/servers/server/settings/locations/cache/index.go b/internal/web/actions/default/servers/server/settings/locations/cache/index.go index faaff31a..86a9954c 100644 --- a/internal/web/actions/default/servers/server/settings/locations/cache/index.go +++ b/internal/web/actions/default/servers/server/settings/locations/cache/index.go @@ -4,6 +4,7 @@ import ( "encoding/json" "github.com/TeaOSLab/EdgeAdmin/internal/utils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dns/domains/domainutils" "github.com/TeaOSLab/EdgeCommon/pkg/langs/codes" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" @@ -11,6 +12,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/maps" + "strings" ) type IndexAction struct { @@ -71,12 +73,55 @@ func (this *IndexAction) RunPost(params struct { defer this.CreateLogInfo(codes.ServerCache_LogUpdateCacheSettings, params.WebId) // 校验配置 - cacheConfig := &serverconfigs.HTTPCacheConfig{} + var cacheConfig = &serverconfigs.HTTPCacheConfig{} err := json.Unmarshal(params.CacheJSON, cacheConfig) if err != nil { this.ErrorPage(err) return } + + // 检查Key + if cacheConfig.Key != nil && cacheConfig.Key.IsOn { + if cacheConfig.Key.Scheme != "http" && cacheConfig.Key.Scheme != "https" { + this.Fail("缓存主域名协议只能是http或者https") + return + } + if len(cacheConfig.Key.Host) == 0 { + this.Fail("请输入缓存主域名") + return + } + cacheConfig.Key.Host = strings.ToLower(strings.TrimSuffix(cacheConfig.Key.Host, "/")) + if !domainutils.ValidateDomainFormat(cacheConfig.Key.Host) { + this.Fail("请输入正确的缓存主域名") + return + } + + // 检查域名所属 + serverIdResp, err := this.RPC().HTTPWebRPC().FindServerIdWithHTTPWebId(this.AdminContext(), &pb.FindServerIdWithHTTPWebIdRequest{HttpWebId: params.WebId}) + if err != nil { + this.ErrorPage(err) + return + } + var serverId = serverIdResp.ServerId + if serverId <= 0 { + this.Fail("找不到要操作的网站") + return + } + + existServerNameResp, err := this.RPC().ServerRPC().CheckServerNameInServer(this.AdminContext(), &pb.CheckServerNameInServerRequest{ + ServerId: serverId, + ServerName: cacheConfig.Key.Host, + }) + if err != nil { + this.ErrorPage(err) + return + } + if !existServerNameResp.Exists { + this.Fail("域名 '" + cacheConfig.Key.Host + "' 在当前网站中并未绑定,不能作为缓存主域名") + return + } + } + err = cacheConfig.Init() if err != nil { this.Fail("检查配置失败:" + err.Error()) diff --git a/web/public/js/components/server/http-cache-config-box.js b/web/public/js/components/server/http-cache-config-box.js index 7d4a4884..9b4752ee 100644 --- a/web/public/js/components/server/http-cache-config-box.js +++ b/web/public/js/components/server/http-cache-config-box.js @@ -19,11 +19,21 @@ Vue.component("http-cache-config-box", { cacheConfig.cacheRefs = [] } - var maxBytes = null + let maxBytes = null if (this.vCachePolicy != null && this.vCachePolicy.maxBytes != null) { maxBytes = this.vCachePolicy.maxBytes } + // key + if (cacheConfig.key == null) { + // use Vue.set to activate vue events + Vue.set(cacheConfig, "key", { + isOn: false, + scheme: "https", + host: "" + }) + } + return { cacheConfig: cacheConfig, moreOptionsVisible: false, @@ -31,7 +41,9 @@ Vue.component("http-cache-config-box", { maxBytes: maxBytes, searchBoxVisible: false, - searchKeyword: "" + searchKeyword: "", + + keyOptionsVisible: false } }, watch: { @@ -106,6 +118,44 @@ Vue.component("http-cache-config-box", { + + + 缓存主域名 + +
默认   [修改]
+
使用主域名:{{cacheConfig.key.scheme}}://{{cacheConfig.key.host}}   [修改]
+
+
+ + + + + + + + + +
启用主域名 +

启用主域名后,所有缓存键值中的协议和域名部分都会修改为主域名,用来实现缓存不区分域名。

+
主域名 * +
+
+ +
+
+ +
+
+

此域名必须是当前网站已绑定域名,在刷新缓存时也需要使用此域名。

+
+ +
+ + + @@ -164,6 +214,11 @@ Vue.component("http-cache-config-box", { +
+ +
+
+

缓存条件   [添加]   [搜索]