(req requests.Request, writer http.ResponseWriter, defaultCaptchaType firewallconfigs.ServerCaptchaType)
| 39 | } |
| 40 | |
| 41 | func (this *CaptchaValidator) Run(req requests.Request, writer http.ResponseWriter, defaultCaptchaType firewallconfigs.ServerCaptchaType) { |
| 42 | var realURL string |
| 43 | var urlObj = req.WAFRaw().URL |
| 44 | if urlObj != nil { |
| 45 | realURL = urlObj.Query().Get("from") |
| 46 | } |
| 47 | |
| 48 | var info = req.WAFRaw().URL.Query().Get("info") |
| 49 | if len(info) == 0 { |
| 50 | if len(realURL) > 0 { |
| 51 | req.ProcessResponseHeaders(writer.Header(), http.StatusTemporaryRedirect) |
| 52 | http.Redirect(writer, req.WAFRaw(), realURL, http.StatusTemporaryRedirect) |
| 53 | } else { |
| 54 | req.ProcessResponseHeaders(writer.Header(), http.StatusBadRequest) |
| 55 | writer.WriteHeader(http.StatusBadRequest) |
| 56 | _, _ = writer.Write([]byte("invalid request (001)")) |
| 57 | } |
| 58 | return |
| 59 | } |
| 60 | |
| 61 | var success bool |
| 62 | var actionId int64 |
| 63 | var setId int64 |
| 64 | var originURL string |
| 65 | var policyId int64 |
| 66 | var groupId int64 |
| 67 | var useLocalFirewall bool |
| 68 | var timestamp int64 |
| 69 | |
| 70 | var infoArg = &InfoArg{} |
| 71 | decodeErr := infoArg.Decode(info) |
| 72 | if decodeErr == nil && infoArg.IsValid() { |
| 73 | success = true |
| 74 | |
| 75 | actionId = infoArg.ActionId |
| 76 | setId = infoArg.SetId |
| 77 | originURL = infoArg.URL |
| 78 | policyId = infoArg.PolicyId |
| 79 | groupId = infoArg.GroupId |
| 80 | useLocalFirewall = infoArg.UseLocalFirewall |
| 81 | timestamp = infoArg.Timestamp |
| 82 | } else { |
| 83 | // 兼容老版本 |
| 84 | m, decodeMapErr := utils.SimpleDecryptMap(info) |
| 85 | if decodeMapErr == nil { |
| 86 | success = true |
| 87 | |
| 88 | actionId = m.GetInt64("actionId") |
| 89 | setId = m.GetInt64("setId") |
| 90 | originURL = m.GetString("url") |
| 91 | policyId = m.GetInt64("policyId") |
| 92 | groupId = m.GetInt64("groupId") |
| 93 | useLocalFirewall = m.GetBool("useLocalFirewall") |
| 94 | timestamp = m.GetInt64("timestamp") |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | if !success { |
nothing calls this directly
no test coverage detected