mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-03 12:20:28 +08:00
WAF人机识别实现点击验证和滑动解锁验证/单个网站可以设置默认的人机识别方式
This commit is contained in:
@@ -63,7 +63,7 @@ func generateComponentsJSFile() error {
|
||||
} else {
|
||||
buffer.WriteString("window.REQUEST_COND_COMPONENTS = ")
|
||||
buffer.Write(typesJSON)
|
||||
buffer.Write([]byte{'\n', '\n'})
|
||||
buffer.Write([]byte{';', '\n', '\n'})
|
||||
}
|
||||
|
||||
// 条件操作符
|
||||
@@ -73,7 +73,7 @@ func generateComponentsJSFile() error {
|
||||
} else {
|
||||
buffer.WriteString("window.REQUEST_COND_OPERATORS = ")
|
||||
buffer.Write(requestOperatorsJSON)
|
||||
buffer.Write([]byte{'\n', '\n'})
|
||||
buffer.Write([]byte{';', '\n', '\n'})
|
||||
}
|
||||
|
||||
// 请求变量
|
||||
@@ -83,7 +83,7 @@ func generateComponentsJSFile() error {
|
||||
} else {
|
||||
buffer.WriteString("window.REQUEST_VARIABLES = ")
|
||||
buffer.Write(requestVariablesJSON)
|
||||
buffer.Write([]byte{'\n', '\n'})
|
||||
buffer.Write([]byte{';', '\n', '\n'})
|
||||
}
|
||||
|
||||
// 指标
|
||||
@@ -93,7 +93,7 @@ func generateComponentsJSFile() error {
|
||||
} else {
|
||||
buffer.WriteString("window.METRIC_HTTP_KEYS = ")
|
||||
buffer.Write(metricHTTPKeysJSON)
|
||||
buffer.Write([]byte{'\n', '\n'})
|
||||
buffer.Write([]byte{';', '\n', '\n'})
|
||||
}
|
||||
|
||||
// IP地址阈值项目
|
||||
@@ -103,7 +103,7 @@ func generateComponentsJSFile() error {
|
||||
} else {
|
||||
buffer.WriteString("window.IP_ADDR_THRESHOLD_ITEMS = ")
|
||||
buffer.Write(ipAddrThresholdItemsJSON)
|
||||
buffer.Write([]byte{'\n', '\n'})
|
||||
buffer.Write([]byte{';', '\n', '\n'})
|
||||
}
|
||||
|
||||
// IP地址阈值动作
|
||||
@@ -113,7 +113,7 @@ func generateComponentsJSFile() error {
|
||||
} else {
|
||||
buffer.WriteString("window.IP_ADDR_THRESHOLD_ACTIONS = ")
|
||||
buffer.Write(ipAddrThresholdActionsJSON)
|
||||
buffer.Write([]byte{'\n', '\n'})
|
||||
buffer.Write([]byte{';', '\n', '\n'})
|
||||
}
|
||||
|
||||
// WAF操作符
|
||||
@@ -123,7 +123,17 @@ func generateComponentsJSFile() error {
|
||||
} else {
|
||||
buffer.WriteString("window.WAF_RULE_OPERATORS = ")
|
||||
buffer.Write(wafOperatorsJSON)
|
||||
buffer.Write([]byte{'\n', '\n'})
|
||||
buffer.Write([]byte{';', '\n', '\n'})
|
||||
}
|
||||
|
||||
// WAF验证码类型
|
||||
captchaTypesJSON, err := json.Marshal(firewallconfigs.FindAllCaptchaTypes())
|
||||
if err != nil {
|
||||
logs.Println("ComponentsAction marshal captcha types failed: " + err.Error())
|
||||
} else {
|
||||
buffer.WriteString("window.WAF_CAPTCHA_TYPES = ")
|
||||
buffer.Write(captchaTypesJSON)
|
||||
buffer.Write([]byte{';', '\n', '\n'})
|
||||
}
|
||||
|
||||
fp, err := os.OpenFile(filepath.Clean(Tea.PublicFile("/js/components.src.js")), os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0777)
|
||||
|
||||
@@ -71,7 +71,7 @@ func (this *ComponentsAction) RunGet(params struct{}) {
|
||||
} else {
|
||||
buffer.WriteString("window.REQUEST_COND_COMPONENTS = ")
|
||||
buffer.Write(typesJSON)
|
||||
buffer.Write([]byte{'\n', '\n'})
|
||||
buffer.Write([]byte{';', '\n', '\n'})
|
||||
}
|
||||
|
||||
// 条件操作符
|
||||
@@ -81,7 +81,7 @@ func (this *ComponentsAction) RunGet(params struct{}) {
|
||||
} else {
|
||||
buffer.WriteString("window.REQUEST_COND_OPERATORS = ")
|
||||
buffer.Write(requestOperatorsJSON)
|
||||
buffer.Write([]byte{'\n', '\n'})
|
||||
buffer.Write([]byte{';', '\n', '\n'})
|
||||
}
|
||||
|
||||
// 请求变量
|
||||
@@ -91,7 +91,7 @@ func (this *ComponentsAction) RunGet(params struct{}) {
|
||||
} else {
|
||||
buffer.WriteString("window.REQUEST_VARIABLES = ")
|
||||
buffer.Write(requestVariablesJSON)
|
||||
buffer.Write([]byte{'\n', '\n'})
|
||||
buffer.Write([]byte{';', '\n', '\n'})
|
||||
}
|
||||
|
||||
// 指标
|
||||
@@ -101,7 +101,7 @@ func (this *ComponentsAction) RunGet(params struct{}) {
|
||||
} else {
|
||||
buffer.WriteString("window.METRIC_HTTP_KEYS = ")
|
||||
buffer.Write(metricHTTPKeysJSON)
|
||||
buffer.Write([]byte{'\n', '\n'})
|
||||
buffer.Write([]byte{';', '\n', '\n'})
|
||||
}
|
||||
|
||||
// IP地址阈值项目
|
||||
@@ -111,7 +111,7 @@ func (this *ComponentsAction) RunGet(params struct{}) {
|
||||
} else {
|
||||
buffer.WriteString("window.IP_ADDR_THRESHOLD_ITEMS = ")
|
||||
buffer.Write(ipAddrThresholdItemsJSON)
|
||||
buffer.Write([]byte{'\n', '\n'})
|
||||
buffer.Write([]byte{';', '\n', '\n'})
|
||||
}
|
||||
|
||||
// IP地址阈值动作
|
||||
@@ -121,7 +121,7 @@ func (this *ComponentsAction) RunGet(params struct{}) {
|
||||
} else {
|
||||
buffer.WriteString("window.IP_ADDR_THRESHOLD_ACTIONS = ")
|
||||
buffer.Write(ipAddrThresholdActionsJSON)
|
||||
buffer.Write([]byte{'\n', '\n'})
|
||||
buffer.Write([]byte{';', '\n', '\n'})
|
||||
}
|
||||
|
||||
// WAF操作符
|
||||
@@ -131,7 +131,17 @@ func (this *ComponentsAction) RunGet(params struct{}) {
|
||||
} else {
|
||||
buffer.WriteString("window.WAF_RULE_OPERATORS = ")
|
||||
buffer.Write(wafOperatorsJSON)
|
||||
buffer.Write([]byte{'\n', '\n'})
|
||||
buffer.Write([]byte{';', '\n', '\n'})
|
||||
}
|
||||
|
||||
// WAF验证码类型
|
||||
captchaTypesJSON, err := json.Marshal(firewallconfigs.FindAllCaptchaTypes())
|
||||
if err != nil {
|
||||
logs.Println("ComponentsAction marshal captcha types failed: " + err.Error())
|
||||
} else {
|
||||
buffer.WriteString("window.WAF_CAPTCHA_TYPES = ")
|
||||
buffer.Write(captchaTypesJSON)
|
||||
buffer.Write([]byte{';', '\n', '\n'})
|
||||
}
|
||||
|
||||
componentsData = buffer.Bytes()
|
||||
|
||||
@@ -25,7 +25,8 @@ Vue.component("http-firewall-captcha-options-viewer", {
|
||||
}
|
||||
return {
|
||||
options: options,
|
||||
summary: ""
|
||||
summary: "",
|
||||
captchaTypes: window.WAF_CAPTCHA_TYPES
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -43,8 +44,18 @@ Vue.component("http-firewall-captcha-options-viewer", {
|
||||
if (this.options.failBlockScopeAll) {
|
||||
summaryList.push("全局封禁")
|
||||
}
|
||||
if (this.options.uiIsOn) {
|
||||
summaryList.push("定制UI")
|
||||
let that = this
|
||||
let typeDef = this.captchaTypes.$find(function (k, v) {
|
||||
return v.code == that.options.captchaType
|
||||
})
|
||||
if (typeDef != null) {
|
||||
summaryList.push("默认验证方式:" + typeDef.name)
|
||||
}
|
||||
|
||||
if (this.options.captchaType == "default") {
|
||||
if (this.options.uiIsOn) {
|
||||
summaryList.push("定制UI")
|
||||
}
|
||||
}
|
||||
if (summaryList.length == 0) {
|
||||
this.summary = "默认配置"
|
||||
|
||||
@@ -7,6 +7,7 @@ Vue.component("http-firewall-captcha-options", {
|
||||
let options = this.vCaptchaOptions
|
||||
if (options == null) {
|
||||
options = {
|
||||
captchaType: "default",
|
||||
countLetters: 0,
|
||||
life: 0,
|
||||
maxFails: 0,
|
||||
@@ -27,11 +28,17 @@ Vue.component("http-firewall-captcha-options", {
|
||||
if (options.countLetters <= 0) {
|
||||
options.countLetters = 6
|
||||
}
|
||||
|
||||
if (options.captchaType == null || options.captchaType.length == 0) {
|
||||
options.captchaType = "default"
|
||||
}
|
||||
|
||||
return {
|
||||
options: options,
|
||||
isEditing: false,
|
||||
summary: "",
|
||||
uiBodyWarning: ""
|
||||
uiBodyWarning: "",
|
||||
captchaTypes: window.WAF_CAPTCHA_TYPES
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
@@ -73,6 +80,9 @@ Vue.component("http-firewall-captcha-options", {
|
||||
"options.failBlockScopeAll": function (v) {
|
||||
this.updateSummary()
|
||||
},
|
||||
"options.captchaType": function (v) {
|
||||
this.updateSummary()
|
||||
},
|
||||
"options.uiIsOn": function (v) {
|
||||
this.updateSummary()
|
||||
},
|
||||
@@ -102,9 +112,21 @@ Vue.component("http-firewall-captcha-options", {
|
||||
if (this.options.failBlockScopeAll) {
|
||||
summaryList.push("全局封禁")
|
||||
}
|
||||
if (this.options.uiIsOn) {
|
||||
summaryList.push("定制UI")
|
||||
|
||||
let that = this
|
||||
let typeDef = this.captchaTypes.$find(function (k, v) {
|
||||
return v.code == that.options.captchaType
|
||||
})
|
||||
if (typeDef != null) {
|
||||
summaryList.push("默认验证方式:" + typeDef.name)
|
||||
}
|
||||
|
||||
if (this.options.captchaType == "default") {
|
||||
if (this.options.uiIsOn) {
|
||||
summaryList.push("定制UI")
|
||||
}
|
||||
}
|
||||
|
||||
if (summaryList.length == 0) {
|
||||
this.summary = "默认配置"
|
||||
} else {
|
||||
@@ -121,6 +143,15 @@ Vue.component("http-firewall-captcha-options", {
|
||||
<div v-show="isEditing" style="margin-top: 0.5em">
|
||||
<table class="ui table definition selectable">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>默认验证方式</td>
|
||||
<td>
|
||||
<select class="ui dropdown auto-width" v-model="options.captchaType">
|
||||
<option v-for="captchaDef in captchaTypes" :value="captchaDef.code">{{captchaDef.name}}</option>
|
||||
</select>
|
||||
<p class="comment" v-for="captchaDef in captchaTypes" v-if="captchaDef.code == options.captchaType">{{captchaDef.description}}</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="title">有效时间</td>
|
||||
<td>
|
||||
@@ -158,7 +189,8 @@ Vue.component("http-firewall-captcha-options", {
|
||||
<p class="comment">是否在失败时全局封禁,默认为只封禁对单个网站的访问。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
||||
<tr v-show="options.captchaType == 'default'">
|
||||
<td>验证码中数字个数</td>
|
||||
<td>
|
||||
<select class="ui dropdown auto-width" v-model="options.countLetters">
|
||||
@@ -166,12 +198,13 @@ Vue.component("http-firewall-captcha-options", {
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr v-show="options.captchaType == 'default'">
|
||||
<td class="color-border">定制UI</td>
|
||||
<td><checkbox v-model="options.uiIsOn"></checkbox></td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
<tbody v-show="options.uiIsOn">
|
||||
<tbody v-show="options.uiIsOn && options.captchaType == 'default'">
|
||||
<tr>
|
||||
<td class="color-border">页面标题</td>
|
||||
<td>
|
||||
|
||||
@@ -7,14 +7,20 @@ Vue.component("http-firewall-config-box", {
|
||||
isPrior: false,
|
||||
isOn: false,
|
||||
firewallPolicyId: 0,
|
||||
ignoreGlobalRules: false
|
||||
ignoreGlobalRules: false,
|
||||
defaultCaptchaType: "none"
|
||||
}
|
||||
}
|
||||
|
||||
if (firewall.defaultCaptchaType == null || firewall.defaultCaptchaType.length == 0) {
|
||||
firewall.defaultCaptchaType = "none"
|
||||
}
|
||||
|
||||
return {
|
||||
firewall: firewall,
|
||||
moreOptionsVisible: false,
|
||||
execGlobalRules: !firewall.ignoreGlobalRules
|
||||
execGlobalRules: !firewall.ignoreGlobalRules,
|
||||
captchaTypes: window.WAF_CAPTCHA_TYPES
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
@@ -46,7 +52,7 @@ Vue.component("http-firewall-config-box", {
|
||||
<prior-checkbox :v-config="firewall" v-if="vIsLocation || vIsGroup"></prior-checkbox>
|
||||
<tbody v-show="(!vIsLocation && !vIsGroup) || firewall.isPrior">
|
||||
<tr>
|
||||
<td class="title">启用WAF</td>
|
||||
<td class="title">启用Web防火墙</td>
|
||||
<td>
|
||||
<checkbox v-model="firewall.isOn"></checkbox>
|
||||
<p class="comment">选中后,表示启用当前网站的WAF功能。</p>
|
||||
@@ -55,6 +61,15 @@ Vue.component("http-firewall-config-box", {
|
||||
</tbody>
|
||||
<more-options-tbody @change="changeOptionsVisible" v-show="firewall.isOn"></more-options-tbody>
|
||||
<tbody v-show="moreOptionsVisible">
|
||||
<tr>
|
||||
<td>人机识别验证方式</td>
|
||||
<td>
|
||||
<select class="ui dropdown auto-width" v-model="firewall.defaultCaptchaType">
|
||||
<option value="none">默认</option>
|
||||
<option v-for="captchaType in captchaTypes" :value="captchaType.code">{{captchaType.name}}</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>启用系统全局规则</td>
|
||||
<td>
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>验证码动作设置</td>
|
||||
<td>人机识别动作配置</td>
|
||||
<td>
|
||||
<http-firewall-captcha-options-viewer :v-captcha-options="firewallPolicy.captchaOptions"></http-firewall-captcha-options-viewer>
|
||||
</td>
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>验证码动作配置</td>
|
||||
<td>人机识别动作配置</td>
|
||||
<td>
|
||||
<http-firewall-captcha-options :v-captcha-options="firewallPolicy.captchaOptions"></http-firewall-captcha-options>
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user