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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. }
  25. if rspamd_util.file_exists(local_conf .. '/controller.lua') then
  26. local controller_overrides = dofile(local_conf .. '/controller.lua')
  27. if controller_overrides and type(controller_overrides) == 'table' then
  28. controller_plugin_paths = lua_util.override_defaults(controller_plugin_paths, controller_overrides)
  29. end
  30. end
  31. for plug,paths in pairs(controller_plugin_paths) do
  32. if not rspamd_plugins[plug] then
  33. rspamd_plugins[plug] = {}
  34. end
  35. if not rspamd_plugins[plug].webui then
  36. rspamd_plugins[plug].webui = {}
  37. end
  38. local webui = rspamd_plugins[plug].webui
  39. for path,attrs in pairs(paths) do
  40. if type(attrs) == 'table' then
  41. if type(attrs.handler) ~= 'function' then
  42. rspamd_logger.infox(rspamd_config, 'controller plugin %s; webui path %s has invalid handler: %s; ignore it',
  43. plug, path, type(attrs.handler))
  44. else
  45. webui[path] = lua_util.shallowcopy(attrs)
  46. rspamd_logger.infox(rspamd_config, 'controller plugin %s; register webui path %s',
  47. plug, path)
  48. end
  49. else
  50. rspamd_logger.infox(rspamd_config, 'controller plugin %s; webui path %s has invalid type: %s; ignore it',
  51. plug, path, type(attrs))
  52. end
  53. end
  54. end