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.

selectors.lua 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. --[[
  2. Copyright (c) 2022, 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 lua_selectors = require "lua_selectors"
  14. -- Controller selectors plugin
  15. local function handle_list_transforms(_, conn)
  16. conn:send_ucl(lua_selectors.list_transforms())
  17. end
  18. local function handle_list_extractors(_, conn)
  19. conn:send_ucl(lua_selectors.list_extractors())
  20. end
  21. local function handle_check_selector(_, conn, req_params)
  22. if req_params.selector and req_params.selector ~= '' then
  23. local selector = lua_selectors.create_selector_closure(rspamd_config,
  24. req_params.selector, '', true)
  25. conn:send_ucl({success = selector and true})
  26. else
  27. conn:send_error(404, 'missing selector')
  28. end
  29. end
  30. local function handle_check_message(task, conn, req_params)
  31. if req_params.selector and req_params.selector ~= '' then
  32. local selector = lua_selectors.create_selector_closure(rspamd_config,
  33. req_params.selector, '', true)
  34. if not selector then
  35. conn:send_error(500, 'invalid selector')
  36. else
  37. task:process_message()
  38. local elts = selector(task)
  39. conn:send_ucl({success = true, data = elts})
  40. end
  41. else
  42. conn:send_error(404, 'missing selector')
  43. end
  44. end
  45. return {
  46. list_extractors = {
  47. handler = handle_list_extractors,
  48. enable = true,
  49. },
  50. list_transforms = {
  51. handler = handle_list_transforms,
  52. enable = true,
  53. },
  54. check_selector = {
  55. handler = handle_check_selector,
  56. enable = true,
  57. },
  58. check_message = {
  59. handler = handle_check_message,
  60. enable = true,
  61. need_task = true,
  62. }
  63. }