自定义页面增加例外URL和限制URL设置

This commit is contained in:
GoEdgeLab
2023-11-13 10:45:13 +08:00
parent 6126171ca8
commit 07ad183065
8 changed files with 192 additions and 49 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"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"
)
@@ -31,26 +32,32 @@ func (this *CreatePopupAction) RunPost(params struct {
URL string `alias:"url"`
Body string
ExceptURLPatternsJSON []byte
OnlyURLPatternsJSON []byte
NewStatus int
Must *actions.Must
}) {
// TODO 对状态码进行更多校验
params.Must.
Field("status", params.Status).
Require("请输入响应状态码")
if len(params.Status) != 3 {
this.FailField("status", "状态码长度必须为3位")
return
}
switch params.BodyType {
case serverconfigs.HTTPPageBodyTypeURL:
params.Must.
Field("url", params.URL).
Require("请输入要显示的URL").
Match( `^(?i)(http|https)://`, "请输入正确的URL")
Match(`^(?i)(http|https)://`, "请输入正确的URL")
case serverconfigs.HTTPPageBodyTypeRedirectURL:
params.Must.
Field("url", params.URL).
Require("请输入要跳转的URL").
Match( `^(?i)(http|https)://`, "请输入正确的URL")
Match(`^(?i)(http|https)://`, "请输入正确的URL")
case serverconfigs.HTTPPageBodyTypeHTML:
params.Must.
Field("body", params.Body).
@@ -62,12 +69,32 @@ func (this *CreatePopupAction) RunPost(params struct {
}
}
var exceptURLPatterns = []*shared.URLPattern{}
if len(params.ExceptURLPatternsJSON) > 0 {
err := json.Unmarshal(params.ExceptURLPatternsJSON, &exceptURLPatterns)
if err != nil {
this.ErrorPage(err)
return
}
}
var onlyURLPatterns = []*shared.URLPattern{}
if len(params.OnlyURLPatternsJSON) > 0 {
err := json.Unmarshal(params.OnlyURLPatternsJSON, &onlyURLPatterns)
if err != nil {
this.ErrorPage(err)
return
}
}
createResp, err := this.RPC().HTTPPageRPC().CreateHTTPPage(this.AdminContext(), &pb.CreateHTTPPageRequest{
StatusList: []string{params.Status},
BodyType: params.BodyType,
Url: params.URL,
Body: params.Body,
NewStatus: types.Int32(params.NewStatus),
StatusList: []string{params.Status},
BodyType: params.BodyType,
Url: params.URL,
Body: params.Body,
NewStatus: types.Int32(params.NewStatus),
ExceptURLPatternsJSON: params.ExceptURLPatternsJSON,
OnlyURLPatternsJSON: params.OnlyURLPatternsJSON,
})
if err != nil {
this.ErrorPage(err)