(actionConfig *CaptchaAction, policyId int64, groupId int64, setId int64, originURL string, req requests.Request, writer http.ResponseWriter, useLocalFirewall bool)
| 511 | } |
| 512 | |
| 513 | func (this *CaptchaValidator) validateOneClickForm(actionConfig *CaptchaAction, policyId int64, groupId int64, setId int64, originURL string, req requests.Request, writer http.ResponseWriter, useLocalFirewall bool) (allow bool) { |
| 514 | var captchaId = req.WAFRaw().FormValue(captchaIdName) |
| 515 | var nonce = req.WAFRaw().FormValue("nonce") |
| 516 | if len(captchaId) > 0 { |
| 517 | var key = "WAF_CAPTCHA:" + captchaId |
| 518 | var cacheItem = ttlcache.SharedInt64Cache.Read(key) |
| 519 | ttlcache.SharedInt64Cache.Delete(key) |
| 520 | if cacheItem != nil { |
| 521 | // 清除计数 |
| 522 | CaptchaDeleteCacheKey(req) |
| 523 | |
| 524 | if cacheItem.Value == types.Int64(nonce) { |
| 525 | var life = CaptchaSeconds |
| 526 | if actionConfig.Life > 0 { |
| 527 | life = types.Int(actionConfig.Life) |
| 528 | } |
| 529 | |
| 530 | // 加入到白名单 |
| 531 | SharedIPWhiteList.RecordIP(wafutils.ComposeIPType(setId, req), actionConfig.Scope, req.WAFServerId(), req.WAFRemoteIP(), time.Now().Unix()+int64(life), policyId, false, groupId, setId, "") |
| 532 | |
| 533 | req.ProcessResponseHeaders(writer.Header(), http.StatusSeeOther) |
| 534 | |
| 535 | // 记录到Cookie |
| 536 | this.setCookie(writer, setId, life) |
| 537 | |
| 538 | http.Redirect(writer, req.WAFRaw(), originURL, http.StatusSeeOther) |
| 539 | |
| 540 | return false |
| 541 | } |
| 542 | } else { |
| 543 | // 增加计数 |
| 544 | if !CaptchaIncreaseFails(req, actionConfig, policyId, groupId, setId, CaptchaPageCodeSubmit, useLocalFirewall) { |
| 545 | return false |
| 546 | } |
| 547 | |
| 548 | req.ProcessResponseHeaders(writer.Header(), http.StatusSeeOther) |
| 549 | http.Redirect(writer, req.WAFRaw(), req.WAFRaw().URL.String(), http.StatusSeeOther) |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | return true |
| 554 | } |
| 555 | |
| 556 | func (this *CaptchaValidator) showSlideForm(actionConfig *CaptchaAction, req requests.Request, writer http.ResponseWriter) { |
| 557 | var lang = actionConfig.Lang |
no test coverage detected