diff --git a/internal/web/actions/default/servers/server/settings/locations/locationutils/location_helper.go b/internal/web/actions/default/servers/server/settings/locations/locationutils/location_helper.go index 5978fa52..5be22dce 100644 --- a/internal/web/actions/default/servers/server/settings/locations/locationutils/location_helper.go +++ b/internal/web/actions/default/servers/server/settings/locations/locationutils/location_helper.go @@ -179,6 +179,13 @@ func (this *LocationHelper) createMenus(serverIdString string, locationIdString "isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.RemoteAddr != nil && locationConfig.Web.RemoteAddr.IsOn, }) + menuItems = append(menuItems, maps.Map{ + "name": "请求限制", + "url": "/servers/server/settings/locations/requestLimit?serverId=" + serverIdString + "&locationId=" + locationIdString, + "isActive": secondMenuItem == "requestLimit", + "isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.RequestLimit != nil && locationConfig.Web.RequestLimit.IsOn, + }) + return menuItems } @@ -187,12 +194,12 @@ func (this *LocationHelper) hasHTTPHeaders(web *serverconfigs.HTTPWebConfig) boo if web == nil { return false } - if web.RequestHeaderPolicyRef != nil { + if web.RequestHeaderPolicyRef != nil && web.RequestHeaderPolicyRef.IsPrior { if web.RequestHeaderPolicyRef.IsOn && web.RequestHeaderPolicy != nil && !web.RequestHeaderPolicy.IsEmpty() { return true } } - if web.ResponseHeaderPolicyRef != nil { + if web.ResponseHeaderPolicyRef != nil && web.ResponseHeaderPolicyRef.IsPrior { if web.ResponseHeaderPolicyRef.IsOn && web.ResponseHeaderPolicy != nil && !web.ResponseHeaderPolicy.IsEmpty() { return true } diff --git a/internal/web/actions/default/servers/server/settings/locations/requestLimit/index.go b/internal/web/actions/default/servers/server/settings/locations/requestLimit/index.go new file mode 100644 index 00000000..af47ce3d --- /dev/null +++ b/internal/web/actions/default/servers/server/settings/locations/requestLimit/index.go @@ -0,0 +1,55 @@ +// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package requestlimit + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/actions" +) + +type IndexAction struct { + actionutils.ParentAction +} + +func (this *IndexAction) Init() { + +} + +func (this *IndexAction) RunGet(params struct { + ServerId int64 + LocationId int64 +}) { + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithLocationId(this.AdminContext(), params.LocationId) + if err != nil { + this.ErrorPage(err) + return + } + + this.Data["webId"] = webConfig.Id + this.Data["requestLimitConfig"] = webConfig.RequestLimit + + this.Show() +} + +func (this *IndexAction) RunPost(params struct { + WebId int64 + RequestLimitJSON []byte + + Must *actions.Must + CSRF *actionutils.CSRF +}) { + defer this.CreateLogInfo("修改Web %d 请求限制", params.WebId) + + _, err := this.RPC().HTTPWebRPC().UpdateHTTPWebRequestLimit(this.AdminContext(), &pb.UpdateHTTPWebRequestLimitRequest{ + HttpWebId: params.WebId, + RequestLimitJSON: params.RequestLimitJSON, + }) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/servers/server/settings/locations/requestLimit/init.go b/internal/web/actions/default/servers/server/settings/locations/requestLimit/init.go new file mode 100644 index 00000000..85fe5ae0 --- /dev/null +++ b/internal/web/actions/default/servers/server/settings/locations/requestLimit/init.go @@ -0,0 +1,22 @@ +package requestlimit + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/configloaders" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/locationutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/serverutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/helpers" + "github.com/iwind/TeaGo" +) + +func init() { + TeaGo.BeforeStart(func(server *TeaGo.Server) { + server. + Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)). + Helper(locationutils.NewLocationHelper()). + Helper(serverutils.NewServerHelper()). + Data("tinyMenuItem", "requestLimit"). + Prefix("/servers/server/settings/locations/requestLimit"). + GetPost("", new(IndexAction)). + EndAll() + }) +} diff --git a/internal/web/import.go b/internal/web/import.go index 7ceb2989..feac3df2 100644 --- a/internal/web/import.go +++ b/internal/web/import.go @@ -80,6 +80,7 @@ import ( _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/location" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/pages" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/remoteAddr" + _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/requestLimit" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/reverseProxy" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/rewrite" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/stat" diff --git a/web/views/@default/servers/server/settings/locations/requestLimit/index.html b/web/views/@default/servers/server/settings/locations/requestLimit/index.html new file mode 100644 index 00000000..8291f557 --- /dev/null +++ b/web/views/@default/servers/server/settings/locations/requestLimit/index.html @@ -0,0 +1,18 @@ +{$layout} +{$template "/left_menu"} + +
+ {$template "../location_menu"} + {$template "../left_menu"} + +
+
+ + + + + + +
+
+
\ No newline at end of file diff --git a/web/views/@default/servers/server/settings/locations/requestLimit/index.js b/web/views/@default/servers/server/settings/locations/requestLimit/index.js new file mode 100644 index 00000000..295a9aaf --- /dev/null +++ b/web/views/@default/servers/server/settings/locations/requestLimit/index.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyReloadSuccess("保存成功") +}) \ No newline at end of file