You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. --[[
  2. Copyright (c) 2023, Vsevolod Stakhov <vsevolod@rspamd.com>
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ]]--
  13. local function handle_gen_fuzzy(task, conn, req_params)
  14. if type(rspamd_plugins.fuzzy_check) == 'table' then
  15. local ret, hashes
  16. task:process_message()
  17. if req_params.rule then
  18. ret, hashes = pcall(rspamd_plugins.fuzzy_check.hex_hashes, task, req_params.rule)
  19. elseif req_params.flag then
  20. ret, hashes = pcall(rspamd_plugins.fuzzy_check.hex_hashes, task, tonumber(req_params.flag))
  21. else
  22. conn:send_error(404, 'missing rule or flag')
  23. return
  24. end
  25. if ret then
  26. conn:send_ucl({ success = true, hashes = hashes })
  27. else
  28. conn:send_error(500, 'cannot generate hashes')
  29. end
  30. else
  31. conn:send_error(404, 'fuzzy_check is not enabled')
  32. end
  33. end
  34. return {
  35. hashes = {
  36. handler = handle_gen_fuzzy,
  37. need_task = true,
  38. enable = false
  39. },
  40. }