mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-03 20:40:26 +08:00
缓存设置中可以设置缓存主域名,用来复用多域名下的缓存
This commit is contained in:
@@ -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())
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user