优化自定义页面设置,页面URL不再支持填写本地文件

This commit is contained in:
GoEdgeLab
2023-07-07 11:48:36 +08:00
parent e27c0280ff
commit 5f69761ac4
6 changed files with 89 additions and 24 deletions

View File

@@ -45,7 +45,8 @@ func (this *CreatePopupAction) RunPost(params struct {
case shared.BodyTypeURL:
params.Must.
Field("url", params.URL).
Require("请输入要显示的URL")
Require("请输入要显示的URL").
Match( `^(?i)(http|https)://`, "请输入正确的URL")
case shared.BodyTypeHTML:
params.Must.
Field("body", params.Body).

View File

@@ -1,11 +1,16 @@
package pages
import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/types"
"regexp"
)
type IndexAction struct {
@@ -46,18 +51,75 @@ func (this *IndexAction) RunGet(params struct {
func (this *IndexAction) RunPost(params struct {
WebId int64
PagesJSON string
ShutdownJSON string
PagesJSON []byte
ShutdownJSON []byte
Must *actions.Must
}) {
// 日志
defer this.CreateLogInfo(codes.ServerPage_LogUpdatePages, params.WebId)
// TODO 检查配置
// 检查配置
var urlReg = regexp.MustCompile(`^(?i)(http|https)://`)
// validate pages
if len(params.PagesJSON) > 0 {
var pages = []*serverconfigs.HTTPPageConfig{}
err := json.Unmarshal(params.PagesJSON, &pages)
if err != nil {
this.ErrorPage(err)
return
}
for _, page := range pages {
err = page.Init()
if err != nil {
this.Fail("配置校验失败:" + err.Error())
return
}
// check url
if page.BodyType == shared.BodyTypeURL && !urlReg.MatchString(page.URL) {
this.Fail("自定义页面中 '" + page.URL + "' 不是一个正确的URL请进行修改")
return
}
}
}
// validate shutdown page
if len(params.ShutdownJSON) > 0 {
var shutdownConfig = &serverconfigs.HTTPShutdownConfig{}
err := json.Unmarshal(params.ShutdownJSON, shutdownConfig)
if err != nil {
this.ErrorPage(err)
return
}
err = shutdownConfig.Init()
if err != nil {
this.Fail("配置校验失败:" + err.Error())
return
}
if shutdownConfig.BodyType == shared.BodyTypeURL {
if len(shutdownConfig.URL) > 512 {
this.Fail("临时关闭页面中URL过长不能超过512字节")
return
}
if !urlReg.MatchString(shutdownConfig.URL) {
this.Fail("临时关闭页面中 '" + shutdownConfig.URL + "' 不是一个正确的URL请进行修改")
return
}
} else if shutdownConfig.Body == shared.BodyTypeHTML {
if len(shutdownConfig.Body) > 32*1024 {
this.Fail("临时关闭页面中HTML内容长度不能超过32K")
return
}
}
}
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebPages(this.AdminContext(), &pb.UpdateHTTPWebPagesRequest{
HttpWebId: params.WebId,
PagesJSON: []byte(params.PagesJSON),
PagesJSON: params.PagesJSON,
})
if err != nil {
this.ErrorPage(err)
@@ -66,7 +128,7 @@ func (this *IndexAction) RunPost(params struct {
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebShutdown(this.AdminContext(), &pb.UpdateHTTPWebShutdownRequest{
HttpWebId: params.WebId,
ShutdownJSON: []byte(params.ShutdownJSON),
ShutdownJSON: params.ShutdownJSON,
})
if err != nil {
this.ErrorPage(err)

View File

@@ -65,7 +65,8 @@ func (this *UpdatePopupAction) RunPost(params struct {
case shared.BodyTypeURL:
params.Must.
Field("url", params.URL).
Require("请输入要显示的URL")
Require("请输入要显示的URL").
Match( `^(?i)(http|https)://`, "请输入正确的URL")
case shared.BodyTypeHTML:
params.Must.
Field("body", params.Body).