mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-03 20:40:26 +08:00
自定义页面增加例外URL和限制URL设置
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
@@ -29,12 +30,18 @@ func (this *UpdatePopupAction) RunGet(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
pageConfig := &serverconfigs.HTTPPageConfig{}
|
||||
var pageConfig = &serverconfigs.HTTPPageConfig{}
|
||||
err = json.Unmarshal(configResp.PageJSON, pageConfig)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if pageConfig.ExceptURLPatterns == nil {
|
||||
pageConfig.ExceptURLPatterns = []*shared.URLPattern{}
|
||||
}
|
||||
if pageConfig.OnlyURLPatterns == nil {
|
||||
pageConfig.OnlyURLPatterns = []*shared.URLPattern{}
|
||||
}
|
||||
this.Data["pageConfig"] = pageConfig
|
||||
|
||||
this.Show()
|
||||
@@ -49,6 +56,9 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
URL string `alias:"url"`
|
||||
Body string
|
||||
|
||||
ExceptURLPatternsJSON []byte
|
||||
OnlyURLPatternsJSON []byte
|
||||
|
||||
NewStatus int
|
||||
|
||||
Must *actions.Must
|
||||
@@ -60,6 +70,11 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
Field("status", params.Status).
|
||||
Require("请输入响应状态码")
|
||||
|
||||
if len(params.Status) != 3 {
|
||||
this.FailField("status", "状态码长度必须为3位")
|
||||
return
|
||||
}
|
||||
|
||||
switch params.BodyType {
|
||||
case serverconfigs.HTTPPageBodyTypeURL:
|
||||
params.Must.
|
||||
@@ -82,13 +97,33 @@ func (this *UpdatePopupAction) 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
|
||||
}
|
||||
}
|
||||
|
||||
_, err := this.RPC().HTTPPageRPC().UpdateHTTPPage(this.AdminContext(), &pb.UpdateHTTPPageRequest{
|
||||
HttpPageId: params.PageId,
|
||||
StatusList: []string{params.Status},
|
||||
BodyType: params.BodyType,
|
||||
Url: params.URL,
|
||||
Body: params.Body,
|
||||
NewStatus: types.Int32(params.NewStatus),
|
||||
HttpPageId: params.PageId,
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user