diff --git a/internal/web/actions/default/servers/components/waf/update.go b/internal/web/actions/default/servers/components/waf/update.go index 6f0b56f9..9ab50b31 100644 --- a/internal/web/actions/default/servers/components/waf/update.go +++ b/internal/web/actions/default/servers/components/waf/update.go @@ -1,6 +1,7 @@ package waf import ( + "encoding/json" "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" @@ -37,6 +38,7 @@ func (this *UpdateAction) RunGet(params struct { StatusCode: http.StatusForbidden, Body: "Blocked By WAF", URL: "", + Timeout: 60, } } @@ -87,7 +89,14 @@ func (this *UpdateAction) RunPost(params struct { Field("name", params.Name). Require("请输入策略名称") - _, err := this.RPC().HTTPFirewallPolicyRPC().UpdateHTTPFirewallPolicy(this.AdminContext(), &pb.UpdateHTTPFirewallPolicyRequest{ + // 校验JSON + var blockOptions = &firewallconfigs.HTTPFirewallBlockAction{} + err := json.Unmarshal(params.BlockOptionsJSON, blockOptions) + if err != nil { + this.Fail("拦截动作参数校验失败:" + err.Error()) + } + + _, err = this.RPC().HTTPFirewallPolicyRPC().UpdateHTTPFirewallPolicy(this.AdminContext(), &pb.UpdateHTTPFirewallPolicyRequest{ HttpFirewallPolicyId: params.FirewallPolicyId, IsOn: params.IsOn, Name: params.Name, diff --git a/internal/web/actions/default/servers/server/settings/compression/index.go b/internal/web/actions/default/servers/server/settings/compression/index.go new file mode 100644 index 00000000..1319e4fe --- /dev/null +++ b/internal/web/actions/default/servers/server/settings/compression/index.go @@ -0,0 +1,71 @@ +// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package compression + +import ( + "encoding/json" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" + "github.com/iwind/TeaGo/actions" +) + +type IndexAction struct { + actionutils.ParentAction +} + +func (this *IndexAction) Init() { + this.Nav("", "setting", "index") + this.SecondMenu("compression") +} + +func (this *IndexAction) RunGet(params struct { + ServerId int64 +}) { + // WebId + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) + if err != nil { + this.ErrorPage(err) + return + } + + this.Data["webId"] = webConfig.Id + + this.Data["compressionConfig"] = webConfig.Compression + + this.Show() +} + +func (this *IndexAction) RunPost(params struct { + WebId int64 + CompressionJSON []byte + + Must *actions.Must + CSRF *actionutils.CSRF +}) { + defer this.CreateLogInfo("修改Web %d 的压缩设置", params.WebId) + + // 校验配置 + var compressionConfig = &serverconfigs.HTTPCompressionConfig{} + err := json.Unmarshal(params.CompressionJSON, compressionConfig) + if err != nil { + this.Fail("配置校验失败:" + err.Error()) + } + + err = compressionConfig.Init() + if err != nil { + this.Fail("配置校验失败:" + err.Error()) + } + + _, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCompression(this.AdminContext(), &pb.UpdateHTTPWebCompressionRequest{ + WebId: params.WebId, + CompressionJSON: params.CompressionJSON, + }) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/servers/server/settings/gzip/init.go b/internal/web/actions/default/servers/server/settings/compression/init.go similarity index 86% rename from internal/web/actions/default/servers/server/settings/gzip/init.go rename to internal/web/actions/default/servers/server/settings/compression/init.go index 6963e58f..7ca465d2 100644 --- a/internal/web/actions/default/servers/server/settings/gzip/init.go +++ b/internal/web/actions/default/servers/server/settings/compression/init.go @@ -1,4 +1,4 @@ -package gzip +package compression import ( "github.com/TeaOSLab/EdgeAdmin/internal/configloaders" @@ -12,7 +12,7 @@ func init() { server. Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)). Helper(serverutils.NewServerHelper()). - Prefix("/servers/server/settings/gzip"). + Prefix("/servers/server/settings/compression"). GetPost("", new(IndexAction)). EndAll() }) diff --git a/internal/web/actions/default/servers/server/settings/gzip/index.go b/internal/web/actions/default/servers/server/settings/gzip/index.go deleted file mode 100644 index b159f800..00000000 --- a/internal/web/actions/default/servers/server/settings/gzip/index.go +++ /dev/null @@ -1,153 +0,0 @@ -package gzip - -import ( - "encoding/json" - "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" - "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" - "github.com/iwind/TeaGo/actions" - "github.com/iwind/TeaGo/types" -) - -type IndexAction struct { - actionutils.ParentAction -} - -func (this *IndexAction) Init() { - this.Nav("", "setting", "index") - this.SecondMenu("gzip") -} - -func (this *IndexAction) RunGet(params struct { - ServerId int64 -}) { - webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) - if err != nil { - this.ErrorPage(err) - return - } - - this.Data["webId"] = webConfig.Id - - gzipId := int64(0) - if webConfig.GzipRef != nil { - gzipId = webConfig.GzipRef.GzipId - } - gzipConfig := &serverconfigs.HTTPGzipConfig{ - Id: 0, - IsOn: true, - } - if gzipId > 0 { - resp, err := this.RPC().HTTPGzipRPC().FindEnabledHTTPGzipConfig(this.AdminContext(), &pb.FindEnabledGzipConfigRequest{HttpGzipId: gzipId}) - if err != nil { - this.ErrorPage(err) - return - } - err = json.Unmarshal(resp.HttpGzipJSON, gzipConfig) - if err != nil { - this.ErrorPage(err) - return - } - } - - this.Data["gzipConfig"] = gzipConfig - - if webConfig.GzipRef == nil { - webConfig.GzipRef = &serverconfigs.HTTPGzipRef{ - IsPrior: false, - IsOn: false, - GzipId: 0, - } - } - this.Data["gzipRef"] = webConfig.GzipRef - - this.Show() -} - -func (this *IndexAction) RunPost(params struct { - WebId int64 - GzipId int64 - Level int - MinLength string - MaxLength string - CondsJSON []byte - GzipRefJSON []byte - - Must *actions.Must -}) { - // 日志 - defer this.CreateLog(oplogs.LevelInfo, "修改Web %d 的GZip配置", params.WebId) - - if params.Level < 0 || params.Level > 9 { - this.Fail("请选择正确的压缩级别") - } - - minLength := &pb.SizeCapacity{Count: -1} - if len(params.MinLength) > 0 { - err := json.Unmarshal([]byte(params.MinLength), minLength) - if err != nil { - this.ErrorPage(err) - return - } - } - - maxLength := &pb.SizeCapacity{Count: -1} - if len(params.MaxLength) > 0 { - err := json.Unmarshal([]byte(params.MaxLength), maxLength) - if err != nil { - this.ErrorPage(err) - return - } - } - - gzipRef := &serverconfigs.HTTPGzipRef{} - err := json.Unmarshal(params.GzipRefJSON, gzipRef) - if err != nil { - this.ErrorPage(err) - return - } - - if params.GzipId > 0 { - _, err := this.RPC().HTTPGzipRPC().UpdateHTTPGzip(this.AdminContext(), &pb.UpdateHTTPGzipRequest{ - HttpGzipId: params.GzipId, - Level: types.Int32(params.Level), - MinLength: minLength, - MaxLength: maxLength, - CondsJSON: params.CondsJSON, - }) - if err != nil { - this.ErrorPage(err) - return - } - } else { - resp, err := this.RPC().HTTPGzipRPC().CreateHTTPGzip(this.AdminContext(), &pb.CreateHTTPGzipRequest{ - Level: types.Int32(params.Level), - MinLength: minLength, - MaxLength: maxLength, - CondsJSON: params.CondsJSON, - }) - if err != nil { - this.ErrorPage(err) - return - } - gzipRef.GzipId = resp.HttpGzipId - } - - gzipRefJSON, err := json.Marshal(gzipRef) - if err != nil { - this.ErrorPage(err) - return - } - - _, err = this.RPC().HTTPWebRPC().UpdateHTTPWebGzip(this.AdminContext(), &pb.UpdateHTTPWebGzipRequest{ - WebId: params.WebId, - GzipJSON: gzipRefJSON, - }) - if err != nil { - this.ErrorPage(err) - } - - this.Success() -} diff --git a/internal/web/actions/default/servers/server/settings/locations/compression/index.go b/internal/web/actions/default/servers/server/settings/locations/compression/index.go new file mode 100644 index 00000000..80a0e4f1 --- /dev/null +++ b/internal/web/actions/default/servers/server/settings/locations/compression/index.go @@ -0,0 +1,69 @@ +// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package compression + +import ( + "encoding/json" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" + "github.com/iwind/TeaGo/actions" +) + +type IndexAction struct { + actionutils.ParentAction +} + +func (this *IndexAction) Init() { + this.Nav("", "", "") +} + +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["compressionConfig"] = webConfig.Compression + + this.Show() +} + +func (this *IndexAction) RunPost(params struct { + WebId int64 + CompressionJSON []byte + + Must *actions.Must + CSRF *actionutils.CSRF +}) { + defer this.CreateLogInfo("修改Web %d 的压缩设置", params.WebId) + + // 校验配置 + var compressionConfig = &serverconfigs.HTTPCompressionConfig{} + err := json.Unmarshal(params.CompressionJSON, compressionConfig) + if err != nil { + this.Fail("配置校验失败:" + err.Error()) + } + + err = compressionConfig.Init() + if err != nil { + this.Fail("配置校验失败:" + err.Error()) + } + + _, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCompression(this.AdminContext(), &pb.UpdateHTTPWebCompressionRequest{ + WebId: params.WebId, + CompressionJSON: params.CompressionJSON, + }) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/servers/server/settings/locations/gzip/init.go b/internal/web/actions/default/servers/server/settings/locations/compression/init.go similarity index 83% rename from internal/web/actions/default/servers/server/settings/locations/gzip/init.go rename to internal/web/actions/default/servers/server/settings/locations/compression/init.go index f95b7437..9d369b9f 100644 --- a/internal/web/actions/default/servers/server/settings/locations/gzip/init.go +++ b/internal/web/actions/default/servers/server/settings/locations/compression/init.go @@ -1,4 +1,4 @@ -package gzip +package compression import ( "github.com/TeaOSLab/EdgeAdmin/internal/configloaders" @@ -14,8 +14,8 @@ func init() { Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)). Helper(locationutils.NewLocationHelper()). Helper(serverutils.NewServerHelper()). - Data("tinyMenuItem", "gzip"). - Prefix("/servers/server/settings/locations/gzip"). + Data("tinyMenuItem", "compression"). + Prefix("/servers/server/settings/locations/compression"). GetPost("", new(IndexAction)). EndAll() }) diff --git a/internal/web/actions/default/servers/server/settings/locations/gzip/index.go b/internal/web/actions/default/servers/server/settings/locations/gzip/index.go deleted file mode 100644 index 4d148f92..00000000 --- a/internal/web/actions/default/servers/server/settings/locations/gzip/index.go +++ /dev/null @@ -1,150 +0,0 @@ -package gzip - -import ( - "encoding/json" - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" - "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" - "github.com/iwind/TeaGo/actions" - "github.com/iwind/TeaGo/types" -) - -type IndexAction struct { - actionutils.ParentAction -} - -func (this *IndexAction) Init() { - this.Nav("", "setting", "index") - this.SecondMenu("gzip") -} - -func (this *IndexAction) RunGet(params struct { - LocationId int64 -}) { - webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithLocationId(this.AdminContext(), params.LocationId) - if err != nil { - this.ErrorPage(err) - return - } - - this.Data["webId"] = webConfig.Id - - gzipId := int64(0) - if webConfig.GzipRef != nil { - gzipId = webConfig.GzipRef.GzipId - } - gzipConfig := &serverconfigs.HTTPGzipConfig{ - Id: 0, - IsOn: true, - } - if gzipId > 0 { - resp, err := this.RPC().HTTPGzipRPC().FindEnabledHTTPGzipConfig(this.AdminContext(), &pb.FindEnabledGzipConfigRequest{HttpGzipId: gzipId}) - if err != nil { - this.ErrorPage(err) - return - } - err = json.Unmarshal(resp.HttpGzipJSON, gzipConfig) - if err != nil { - this.ErrorPage(err) - return - } - } - - this.Data["gzipConfig"] = gzipConfig - - if webConfig.GzipRef == nil { - webConfig.GzipRef = &serverconfigs.HTTPGzipRef{ - IsPrior: false, - IsOn: false, - GzipId: 0, - } - } - this.Data["gzipRef"] = webConfig.GzipRef - - this.Show() -} - -func (this *IndexAction) RunPost(params struct { - WebId int64 - GzipRefJSON []byte - GzipId int64 - Level int - MinLength string - MaxLength string - - Must *actions.Must -}) { - defer this.CreateLogInfo("修改Web %d 的Gzip设置", params.WebId) - - if params.Level < 0 || params.Level > 9 { - this.Fail("请选择正确的压缩级别") - } - - minLength := &pb.SizeCapacity{Count: -1} - if len(params.MinLength) > 0 { - err := json.Unmarshal([]byte(params.MinLength), minLength) - if err != nil { - this.ErrorPage(err) - return - } - } - - maxLength := &pb.SizeCapacity{Count: -1} - if len(params.MaxLength) > 0 { - err := json.Unmarshal([]byte(params.MaxLength), maxLength) - if err != nil { - this.ErrorPage(err) - return - } - } - - gzipRef := &serverconfigs.HTTPGzipRef{} - err := json.Unmarshal(params.GzipRefJSON, gzipRef) - if err != nil { - this.ErrorPage(err) - return - } - gzipRef.GzipId = params.GzipId - - if params.GzipId > 0 { - _, err := this.RPC().HTTPGzipRPC().UpdateHTTPGzip(this.AdminContext(), &pb.UpdateHTTPGzipRequest{ - HttpGzipId: params.GzipId, - Level: types.Int32(params.Level), - MinLength: minLength, - MaxLength: maxLength, - }) - if err != nil { - this.ErrorPage(err) - return - } - } else { - resp, err := this.RPC().HTTPGzipRPC().CreateHTTPGzip(this.AdminContext(), &pb.CreateHTTPGzipRequest{ - Level: types.Int32(params.Level), - MinLength: minLength, - MaxLength: maxLength, - }) - if err != nil { - this.ErrorPage(err) - return - } - gzipId := resp.HttpGzipId - gzipRef.GzipId = gzipId - } - - gzipRefJSON, err := json.Marshal(gzipRef) - if err != nil { - this.ErrorPage(err) - return - } - - _, err = this.RPC().HTTPWebRPC().UpdateHTTPWebGzip(this.AdminContext(), &pb.UpdateHTTPWebGzipRequest{ - WebId: params.WebId, - GzipJSON: gzipRefJSON, - }) - if err != nil { - this.ErrorPage(err) - } - - this.Success() -} 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 0c7737f7..47ae5122 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 @@ -127,10 +127,10 @@ func (this *LocationHelper) createMenus(serverIdString string, locationIdString "isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.StatRef != nil && locationConfig.Web.StatRef.IsPrior, }) menuItems = append(menuItems, maps.Map{ - "name": "Gzip压缩", - "url": "/servers/server/settings/locations/gzip?serverId=" + serverIdString + "&locationId=" + locationIdString, - "isActive": secondMenuItem == "gzip", - "isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.GzipRef != nil && locationConfig.Web.GzipRef.IsPrior, + "name": "内容压缩", + "url": "/servers/server/settings/locations/compression?serverId=" + serverIdString + "&locationId=" + locationIdString, + "isActive": secondMenuItem == "compression", + "isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.Compression != nil && locationConfig.Web.Compression.IsPrior, }) menuItems = append(menuItems, maps.Map{ "name": "特殊页面", diff --git a/internal/web/actions/default/servers/serverutils/server_helper.go b/internal/web/actions/default/servers/serverutils/server_helper.go index 540ee389..e76140ca 100644 --- a/internal/web/actions/default/servers/serverutils/server_helper.go +++ b/internal/web/actions/default/servers/serverutils/server_helper.go @@ -299,10 +299,10 @@ func (this *ServerHelper) createSettingsMenu(secondMenuItem string, serverIdStri "isOn": serverConfig.Web != nil && serverConfig.Web.StatRef != nil && serverConfig.Web.StatRef.IsOn, }) menuItems = append(menuItems, maps.Map{ - "name": "Gzip压缩", - "url": "/servers/server/settings/gzip?serverId=" + serverIdString, - "isActive": secondMenuItem == "gzip", - "isOn": serverConfig.Web != nil && serverConfig.Web.GzipRef != nil && serverConfig.Web.GzipRef.IsOn, + "name": "内容压缩", + "url": "/servers/server/settings/compression?serverId=" + serverIdString, + "isActive": secondMenuItem == "compression", + "isOn": serverConfig.Web != nil && serverConfig.Web.Compression != nil && serverConfig.Web.Compression.IsOn, }) menuItems = append(menuItems, maps.Map{ "name": "特殊页面", diff --git a/internal/web/import.go b/internal/web/import.go index db4877e3..06b44459 100644 --- a/internal/web/import.go +++ b/internal/web/import.go @@ -59,10 +59,10 @@ import ( _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/accessLog" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/cache" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/charset" + _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/compression" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/conds" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/dns" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/fastcgi" - _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/gzip" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/headers" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/http" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/https" @@ -71,8 +71,8 @@ import ( _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/accessLog" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/cache" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/charset" + _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/compression" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/fastcgi" - _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/gzip" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/headers" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/http" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/location" diff --git a/web/public/js/components/common/sortable.js b/web/public/js/components/common/sortable.js index fa431779..8b4f7909 100644 --- a/web/public/js/components/common/sortable.js +++ b/web/public/js/components/common/sortable.js @@ -25,4 +25,15 @@ function sortTable(callback) { }) }) document.head.appendChild(jsFile) -} \ No newline at end of file +} + +function sortLoad(callback) { + let jsFile = document.createElement("script") + jsFile.setAttribute("src", "/js/sortable.min.js") + jsFile.addEventListener("load", function () { + if (typeof (callback) == "function") { + callback() + } + }) + document.head.appendChild(jsFile) +} diff --git a/web/public/js/components/common/values-box.js b/web/public/js/components/common/values-box.js index 8814fb2b..1168cb0b 100644 --- a/web/public/js/components/common/values-box.js +++ b/web/public/js/components/common/values-box.js @@ -10,7 +10,8 @@ Vue.component("values-box", { "isUpdating": false, "isAdding": false, "index": 0, - "value": "" + "value": "", + isEditing: false } }, methods: { @@ -58,9 +59,18 @@ Vue.component("values-box", { }, addValue: function (v) { this.vValues.push(v) + }, + + startEditing: function () { + this.isEditing = !this.isEditing } }, template: `
+
+
{{value}}
+ [修改] +
+
{{value}} @@ -86,5 +96,6 @@ Vue.component("values-box", {
+
` }); \ No newline at end of file diff --git a/web/public/js/components/server/http-compression-config-box.js b/web/public/js/components/server/http-compression-config-box.js new file mode 100644 index 00000000..7b8ff836 --- /dev/null +++ b/web/public/js/components/server/http-compression-config-box.js @@ -0,0 +1,231 @@ +// 压缩配置 +Vue.component("http-compression-config-box", { + props: ["v-compression-config", "v-is-location"], + mounted: function () { + let that = this + sortLoad(function () { + that.initSortableTypes() + }) + }, + data: function () { + let config = this.vCompressionConfig + if (config == null) { + config = { + isPrior: false, + isOn: false, + useDefaultTypes: true, + types: ["gzip", "deflate", "brotli"], + level: 5, + gzipRef: null, + deflateRef: null, + brotliRef: null, + minLength: {count: 0, "unit": "kb"}, + maxLength: {count: 0, "unit": "kb"}, + mimeTypes: ["text/*", "application/*", "font/*"], + extensions: [".js", ".json", ".html", ".htm", ".xml", ".css", ".woff2", ".txt"], + conds: null + } + } + + if (config.types == null) { + config.types = [] + } + if (config.mimeTypes == null) { + config.mimeTypes = [] + } + if (config.extensions == null) { + config.extensions = [] + } + + let allTypes = [ + { + name: "Gzip", + code: "gzip", + isOn: true + }, + { + name: "Deflate", + code: "deflate", + isOn: true + }, + { + name: "Brotli", + code: "brotli", + isOn: true + } + ] + + let configTypes = [] + config.types.forEach(function (typeCode) { + allTypes.forEach(function (t) { + if (typeCode == t.code) { + t.isOn = true + configTypes.push(t) + } + }) + }) + allTypes.forEach(function (t) { + if (!config.types.$contains(t.code)) { + t.isOn = false + configTypes.push(t) + } + }) + + return { + config: config, + moreOptionsVisible: false, + allTypes: configTypes + } + }, + watch: { + "config.level": function (v) { + let level = parseInt(v) + if (isNaN(level)) { + level = 1 + } else if (level < 1) { + level = 1 + } else if (level > 10) { + level = 10 + } + this.config.level = level + } + }, + methods: { + isOn: function () { + return (!this.vIsLocation || this.config.isPrior) && this.config.isOn + }, + changeExtensions: function (values) { + values.forEach(function (v, k) { + if (v.length > 0 && v[0] != ".") { + values[k] = "." + v + } + }) + this.config.extensions = values + }, + changeMimeTypes: function (values) { + this.config.mimeTypes = values + }, + changeAdvancedVisible: function () { + this.moreOptionsVisible = !this.moreOptionsVisible + }, + changeConds: function (conds) { + this.config.conds = conds + }, + changeType: function () { + this.config.types = [] + let that = this + this.allTypes.forEach(function (v) { + if (v.isOn) { + that.config.types.push(v.code) + } + }) + }, + initSortableTypes: function () { + let box = document.querySelector("#compression-types-box") + let that = this + Sortable.create(box, { + draggable: ".checkbox", + handle: ".icon.handle", + onStart: function () { + + }, + onUpdate: function (event) { + let checkboxes = box.querySelectorAll(".checkbox") + let codes = [] + checkboxes.forEach(function (checkbox) { + let code = checkbox.getAttribute("data-code") + codes.push(code) + }) + that.config.types = codes + } + }) + } + }, + template: `
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
是否启用 +
+ + +
+
压缩级别 + +

级别越高,压缩比例越大。

+
支持的扩展名 + +

含有这些扩展名的URL将会被压缩,不区分大小写。

+
支持的MimeType + +

响应的Content-Type里包含这些MimeType的内容将会被压缩。

+
压缩算法 +
+ + + +
+
+
+
+
+ + +
+
+
+ +

选择支持的压缩算法和优先顺序,拖动图表排序。

+
内容最小长度 + +

0表示不限制,内容长度从文件尺寸或Content-Length中获取。

+
内容最大长度 + +

0表示不限制,内容长度从文件尺寸或Content-Length中获取。

+
匹配条件 + +
+
+
` +}) \ No newline at end of file diff --git a/web/public/js/components/server/http-firewall-block-options.js b/web/public/js/components/server/http-firewall-block-options.js index 7341108b..6198cba4 100644 --- a/web/public/js/components/server/http-firewall-block-options.js +++ b/web/public/js/components/server/http-firewall-block-options.js @@ -3,7 +3,8 @@ Vue.component("http-firewall-block-options", { data: function () { return { blockOptions: this.vBlockOptions, - statusCode: this.vBlockOptions.statusCode + statusCode: this.vBlockOptions.statusCode, + timeout: this.vBlockOptions.timeout } }, watch: { @@ -14,6 +15,14 @@ Vue.component("http-firewall-block-options", { } else { this.blockOptions.statusCode = statusCode } + }, + timeout: function (v) { + let timeout = parseInt(v) + if (isNaN(timeout)) { + this.blockOptions.timeout = 0 + } else { + this.blockOptions.timeout = timeout + } } }, template: `
@@ -31,6 +40,16 @@ Vue.component("http-firewall-block-options", { + + 超时时间 + +
+ + +
+

触发阻止动作时,封锁客户端IP的时间。

+ +
` diff --git a/web/views/@default/servers/components/waf/policy.html b/web/views/@default/servers/components/waf/policy.html index da4265c9..81b9291a 100644 --- a/web/views/@default/servers/components/waf/policy.html +++ b/web/views/@default/servers/components/waf/policy.html @@ -32,6 +32,13 @@ 提示内容 {{firewallPolicy.blockOptions.body}} + + 超时时间 + + 使用默认时间。 + {{firewallPolicy.blockOptions.timeout}}秒 + +
diff --git a/web/views/@default/servers/server/settings/gzip/index.html b/web/views/@default/servers/server/settings/compression/gzip/index.html similarity index 100% rename from web/views/@default/servers/server/settings/gzip/index.html rename to web/views/@default/servers/server/settings/compression/gzip/index.html diff --git a/web/views/@default/servers/server/settings/gzip/index.js b/web/views/@default/servers/server/settings/compression/gzip/index.js similarity index 100% rename from web/views/@default/servers/server/settings/gzip/index.js rename to web/views/@default/servers/server/settings/compression/gzip/index.js diff --git a/web/views/@default/servers/server/settings/compression/index.html b/web/views/@default/servers/server/settings/compression/index.html new file mode 100644 index 00000000..d87bedbc --- /dev/null +++ b/web/views/@default/servers/server/settings/compression/index.html @@ -0,0 +1,12 @@ +{$layout} +{$template "/left_menu"} + +
+
+ + + + + +
+
\ No newline at end of file diff --git a/web/views/@default/servers/server/settings/locations/gzip/index.js b/web/views/@default/servers/server/settings/compression/index.js similarity index 100% rename from web/views/@default/servers/server/settings/locations/gzip/index.js rename to web/views/@default/servers/server/settings/compression/index.js diff --git a/web/views/@default/servers/server/settings/locations/gzip/index.html b/web/views/@default/servers/server/settings/locations/compression/gzip/index.html similarity index 100% rename from web/views/@default/servers/server/settings/locations/gzip/index.html rename to web/views/@default/servers/server/settings/locations/compression/gzip/index.html diff --git a/web/views/@default/servers/server/settings/locations/compression/gzip/index.js b/web/views/@default/servers/server/settings/locations/compression/gzip/index.js new file mode 100644 index 00000000..295a9aaf --- /dev/null +++ b/web/views/@default/servers/server/settings/locations/compression/gzip/index.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyReloadSuccess("保存成功") +}) \ No newline at end of file diff --git a/web/views/@default/servers/server/settings/locations/compression/index.html b/web/views/@default/servers/server/settings/locations/compression/index.html new file mode 100644 index 00000000..3bb36ba2 --- /dev/null +++ b/web/views/@default/servers/server/settings/locations/compression/index.html @@ -0,0 +1,21 @@ +{$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/compression/index.js b/web/views/@default/servers/server/settings/locations/compression/index.js new file mode 100644 index 00000000..295a9aaf --- /dev/null +++ b/web/views/@default/servers/server/settings/locations/compression/index.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyReloadSuccess("保存成功") +}) \ No newline at end of file