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.

init.lua 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. -- Controller endpoints
  14. local local_conf = rspamd_paths['LOCAL_CONFDIR']
  15. local local_rules = rspamd_paths['RULESDIR']
  16. local rspamd_util = require "rspamd_util"
  17. local lua_util = require "lua_util"
  18. local rspamd_logger = require "rspamd_logger"
  19. -- Define default controller paths, could be overridden in local.d/controller.lua
  20. local controller_plugin_paths = {
  21. maps = dofile(local_rules .. "/controller/maps.lua"),
  22. neural = dofile(local_rules .. "/controller/neural.lua"),
  23. selectors = dofile(local_rules .. "/controller/selectors.lua"),
  24. fuzzy = dofile(local_rules .. "/controller/fuzzy.lua"),
  25. }
  26. if rspamd_util.file_exists(local_conf .. '/controller.lua') then
  27. local controller_overrides = dofile(local_conf .. '/controller.lua')
  28. if controller_overrides and type(controller_overrides) == 'table' then
  29. controller_plugin_paths = lua_util.override_defaults(controller_plugin_paths, controller_overrides)
  30. end
  31. end
  32. for plug, paths in pairs(controller_plugin_paths) do
  33. if not rspamd_plugins[plug] then
  34. rspamd_plugins[plug] = {}
  35. end
  36. if not rspamd_plugins[plug].webui then
  37. rspamd_plugins[plug].webui = {}
  38. end
  39. local webui = rspamd_plugins[plug].webui
  40. for path, attrs in pairs(paths) do
  41. if type(attrs) == 'table' then
  42. if type(attrs.handler) ~= 'function' then
  43. rspamd_logger.infox(rspamd_config, 'controller plugin %s; webui path %s has invalid handler: %s; ignore it',
  44. plug, path, type(attrs.handler))
  45. else
  46. webui[path] = lua_util.shallowcopy(attrs)
  47. rspamd_logger.infox(rspamd_config, 'controller plugin %s; register webui path %s',
  48. plug, path)
  49. end
  50. else
  51. rspamd_logger.infox(rspamd_config, 'controller plugin %s; webui path %s has invalid type: %s; ignore it',
  52. plug, path, type(attrs))
  53. end
  54. end
  55. end