Files
EdgeAdmin/web/public/js/components/server/http-firewall-rules-box.js

100 lines
3.5 KiB
JavaScript
Raw Normal View History

2020-10-08 11:11:37 +08:00
Vue.component("http-firewall-rules-box", {
props: ["v-rules", "v-type"],
data: function () {
let rules = this.vRules
if (rules == null) {
rules = []
}
return {
rules: rules
}
},
methods: {
addRule: function () {
window.UPDATING_RULE = null
let that = this
teaweb.popup("/servers/components/waf/createRulePopup?type=" + this.vType, {
2022-11-16 15:43:08 +08:00
height: "30em",
2020-10-08 11:11:37 +08:00
callback: function (resp) {
that.rules.push(resp.data.rule)
}
})
},
updateRule: function (index, rule) {
window.UPDATING_RULE = teaweb.clone(rule)
2020-10-08 11:11:37 +08:00
let that = this
teaweb.popup("/servers/components/waf/createRulePopup?type=" + this.vType, {
2022-11-16 15:43:08 +08:00
height: "30em",
2020-10-08 11:11:37 +08:00
callback: function (resp) {
Vue.set(that.rules, index, resp.data.rule)
}
})
},
removeRule: function (index) {
let that = this
teaweb.confirm("确定要删除此规则吗?", function () {
that.rules.$remove(index)
})
2023-01-06 19:12:53 +08:00
},
operatorName: function (operatorCode) {
let operatorName = operatorCode
2023-01-06 19:12:53 +08:00
if (typeof (window.WAF_RULE_OPERATORS) != null) {
window.WAF_RULE_OPERATORS.forEach(function (v) {
if (v.code == operatorCode) {
operatorName = v.name
}
})
}
return operatorName
},
operatorDataType: function (operatorCode) {
let operatorDataType = "none"
if (typeof (window.WAF_RULE_OPERATORS) != null) {
window.WAF_RULE_OPERATORS.forEach(function (v) {
if (v.code == operatorCode) {
operatorDataType = v.dataType
}
})
}
return operatorDataType
},
isEmptyString: function (v) {
return typeof v == "string" && v.length == 0
2020-10-08 11:11:37 +08:00
}
},
template: `<div>
<input type="hidden" name="rulesJSON" :value="JSON.stringify(rules)"/>
<div v-if="rules.length > 0">
2023-01-06 19:12:53 +08:00
<div v-for="(rule, index) in rules" class="ui label small basic" style="margin-bottom: 0.5em; line-height: 1.5">
2021-07-19 10:48:53 +08:00
{{rule.name}}[{{rule.param}}]
<!-- cc2 -->
<span v-if="rule.param == '\${cc2}'">
2023-05-02 17:04:40 +08:00
{{rule.checkpointOptions.period}}秒内请求数
2021-07-19 10:48:53 +08:00
</span>
2021-10-19 11:38:56 +08:00
<!-- refererBlock -->
<span v-if="rule.param == '\${refererBlock}'">
<span v-if="rule.checkpointOptions.allowDomains != null && rule.checkpointOptions.allowDomains.length > 0">允许{{rule.checkpointOptions.allowDomains}}</span>
<span v-if="rule.checkpointOptions.denyDomains != null && rule.checkpointOptions.denyDomains.length > 0">禁止{{rule.checkpointOptions.denyDomains}}</span>
2021-10-19 11:38:56 +08:00
</span>
2021-07-19 10:48:53 +08:00
<span v-else>
2023-02-02 16:14:07 +08:00
<span v-if="rule.paramFilters != null && rule.paramFilters.length > 0" v-for="paramFilter in rule.paramFilters"> | {{paramFilter.code}}</span> <span :class="{dash:(!rule.isComposed && rule.isCaseInsensitive)}" :title="(!rule.isComposed && rule.isCaseInsensitive) ? '':''">{{operatorName(rule.operator)}}</span>
<span v-if="!isEmptyString(rule.value)">{{rule.value}}</span>
<span v-else-if="operatorDataType(rule.operator) != 'none'" class="disabled" style="font-weight: normal" title="空字符串">[]</span>
2021-07-19 10:48:53 +08:00
</span>
<!-- description -->
<span v-if="rule.description != null && rule.description.length > 0" class="grey small">{{rule.description}}</span>
2020-10-08 11:11:37 +08:00
<a href="" title="修改" @click.prevent="updateRule(index, rule)"><i class="icon pencil small"></i></a>
<a href="" title="删除" @click.prevent="removeRule(index)"><i class="icon remove"></i></a>
</div>
<div class="ui divider"></div>
</div>
<button class="ui button tiny" type="button" @click.prevent="addRule()">+</button>
</div>`
})