内容压缩支持brotli和deflate

This commit is contained in:
GoEdgeLab
2021-09-29 20:12:27 +08:00
parent 84dd0d662b
commit 2a8846b4be
23 changed files with 486 additions and 322 deletions

View File

@@ -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,

View File

@@ -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()
}

View File

@@ -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()
})

View File

@@ -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()
}

View File

@@ -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()
}

View File

@@ -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()
})

View File

@@ -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()
}

View File

@@ -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": "特殊页面",

View File

@@ -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": "特殊页面",

View File

@@ -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"

View File

@@ -25,4 +25,15 @@ function sortTable(callback) {
})
})
document.head.appendChild(jsFile)
}
}
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)
}

View File

@@ -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: `<div>
<div v-show="!isEditing">
<div class="ui label tiny basic" v-for="(value, index) in vValues" style="margin-top:0.4em;margin-bottom:0.4em">{{value}}</div>
<a href="" @click.prevent="startEditing" style="font-size: 0.8em; margin-left: 0.2em">[修改]</a>
</div>
<div v-show="isEditing">
<div style="margin-bottom: 1em" v-if="vValues.length > 0">
<div class="ui label tiny basic" v-for="(value, index) in vValues" style="margin-top:0.4em;margin-bottom:0.4em">{{value}}
<input type="hidden" :name="name" :value="value"/>
@@ -86,5 +96,6 @@ Vue.component("values-box", {
<div v-if="!isAdding && !isUpdating">
<button class="ui button tiny" type="button" @click.prevent="create()">+</button>
</div>
</div>
</div>`
});

View File

@@ -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: `<div>
<input type="hidden" name="compressionJSON" :value="JSON.stringify(config)"/>
<table class="ui table definition selectable">
<prior-checkbox :v-config="config" v-if="vIsLocation"></prior-checkbox>
<tbody v-show="!vIsLocation || config.isPrior">
<tr>
<td class="title">是否启用</td>
<td>
<div class="ui checkbox">
<input type="checkbox" value="1" v-model="config.isOn"/>
<label></label>
</div>
</td>
</tr>
</tbody>
<tbody v-show="isOn()">
<tr>
<td>压缩级别</td>
<td>
<select class="ui dropdown auto-width" v-model="config.level">
<option v-for="i in 10" :value="i">{{i}}</option>
</select>
<p class="comment">级别越高,压缩比例越大。</p>
</td>
</tr>
<tr>
<td>支持的扩展名</td>
<td>
<values-box :values="config.extensions" @change="changeExtensions" placeholder="比如 .html"></values-box>
<p class="comment">含有这些扩展名的URL将会被压缩不区分大小写。</p>
</td>
</tr>
<tr>
<td>支持的MimeType</td>
<td>
<values-box :values="config.mimeTypes" @change="changeMimeTypes" placeholder="比如 text/*"></values-box>
<p class="comment">响应的Content-Type里包含这些MimeType的内容将会被压缩。</p>
</td>
</tr>
</tbody>
<more-options-tbody @change="changeAdvancedVisible" v-if="isOn()"></more-options-tbody>
<tbody v-show="isOn() && moreOptionsVisible">
<tr>
<td>压缩算法</td>
<td>
<div class="ui checkbox">
<input type="checkbox" v-model="config.useDefaultTypes" id="compression-use-default"/>
<label v-if="config.useDefaultTypes" for="compression-use-default">使用默认顺序<span class="grey small">gzip、deflate、brotli</span></label>
<label v-if="!config.useDefaultTypes" for="compression-use-default">使用默认顺序</label>
</div>
<div v-show="!config.useDefaultTypes">
<div class="ui divider"></div>
<div id="compression-types-box">
<div class="ui checkbox" v-for="t in allTypes" style="margin-right: 2em" :data-code="t.code">
<input type="checkbox" v-model="t.isOn" :id="'compression-type-' + t.code" @change="changeType"/>
<label :for="'compression-type-' + t.code">{{t.name}} &nbsp; <i class="icon list small grey handle"></i></label>
</div>
</div>
</div>
<p class="comment">选择支持的压缩算法和优先顺序,拖动<i class="icon list small grey"></i>图表排序。</p>
</td>
</tr>
<tr>
<td>内容最小长度</td>
<td>
<size-capacity-box :v-name="'minLength'" :v-value="config.minLength" :v-unit="'kb'"></size-capacity-box>
<p class="comment">0表示不限制内容长度从文件尺寸或Content-Length中获取。</p>
</td>
</tr>
<tr>
<td>内容最大长度</td>
<td>
<size-capacity-box :v-name="'maxLength'" :v-value="config.maxLength" :v-unit="'mb'"></size-capacity-box>
<p class="comment">0表示不限制内容长度从文件尺寸或Content-Length中获取。</p>
</td>
</tr>
<tr>
<td>匹配条件</td>
<td>
<http-request-conds-box :v-conds="config.conds" @change="changeConds"></http-request-conds-box>
</td>
</tr>
</tbody>
</table>
<div class="margin"></div>
</div>`
})

View File

@@ -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: `<div>
@@ -31,6 +40,16 @@ Vue.component("http-firewall-block-options", {
<textarea rows="3" v-model="blockOptions.body"></textarea>
</td>
</tr>
<tr>
<td>超时时间</td>
<td>
<div class="ui input right labeled">
<input type="text" v-model="timeout" style="width: 5em" maxlength="6"/>
<span class="ui label">秒</span>
</div>
<p class="comment">触发阻止动作时封锁客户端IP的时间。</p>
</td>
</tr>
</table>
</div>
`

View File

@@ -32,6 +32,13 @@
<td>提示内容</td>
<td>{{firewallPolicy.blockOptions.body}}</td>
</tr>
<tr>
<td>超时时间</td>
<td>
<span v-if="firewallPolicy.blockOptions.timeout <= 0" class="disabled">使用默认时间。</span>
<span v-else>{{firewallPolicy.blockOptions.timeout}}秒</span>
</td>
</tr>
</table>
</div>
</td>

View File

@@ -0,0 +1,12 @@
{$layout}
{$template "/left_menu"}
<div class="right-box">
<form class="ui form" data-tea-action="$" data-tea-success="success">
<csrf-token></csrf-token>
<input type="hidden" name="webId" :value="webId"/>
<http-compression-config-box :v-compression-config="compressionConfig"></http-compression-config-box>
<submit-btn></submit-btn>
</form>
</div>

View File

@@ -0,0 +1,3 @@
Tea.context(function () {
this.success = NotifyReloadSuccess("保存成功")
})

View File

@@ -0,0 +1,21 @@
{$layout}
{$template "/left_menu"}
<div class="right-box">
{$template "../location_menu"}
{$template "../left_menu"}
<div class="right-box tiny">
<div class="margin"></div>
<form method="post" class="ui form" data-tea-success="success" data-tea-action="$">
<csrf-token></csrf-token>
<input type="hidden" name="webId" :value="webId"/>
<http-compression-config-box :v-compression-config="compressionConfig" :v-is-location="true"></http-compression-config-box>
<div class="margin"></div>
<submit-btn></submit-btn>
</form>
</div>
</div>

View File

@@ -0,0 +1,3 @@
Tea.context(function () {
this.success = NotifyReloadSuccess("保存成功")
})