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.

dcc.lua 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. --[[
  2. Copyright (c) 2016, Steve Freegard <steve.freegard@fsl.com>
  3. Copyright (c) 2016, Vsevolod Stakhov
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. ]]--
  14. -- Check messages for 'bulkiness' using DCC
  15. local N = 'dcc'
  16. local symbol_bulk = "DCC_BULK"
  17. local symbol = "DCC_REJECT"
  18. local opts = rspamd_config:get_all_opt(N)
  19. local lua_util = require "lua_util"
  20. local rspamd_logger = require "rspamd_logger"
  21. local dcc = require("lua_scanners").filter('dcc').dcc
  22. if confighelp then
  23. rspamd_config:add_example(nil, 'dcc',
  24. "Check messages for 'bulkiness' using DCC",
  25. [[
  26. dcc {
  27. socket = "/var/dcc/dccifd"; # Unix socket
  28. servers = "127.0.0.1:10045" # OR TCP upstreams
  29. timeout = 2s; # Timeout to wait for checks
  30. body_max = 999999; # Bulkness threshold for body
  31. fuz1_max = 999999; # Bulkness threshold for fuz1
  32. fuz2_max = 999999; # Bulkness threshold for fuz2
  33. }
  34. ]])
  35. return
  36. end
  37. local rule
  38. local function check_dcc (task)
  39. dcc.check(task, task:get_content(), nil, rule)
  40. end
  41. -- Configuration
  42. -- WORKAROUND for deprecated host and port settings
  43. if opts['host'] ~= nil and opts['port'] ~= nil then
  44. opts['servers'] = opts['host'] .. ':' .. opts['port']
  45. rspamd_logger.warnx(rspamd_config, 'Using host and port parameters is deprecated. ' ..
  46. 'Please use servers = "%s:%s"; instead', opts['host'], opts['port'])
  47. end
  48. if opts['host'] ~= nil and not opts['port'] then
  49. opts['socket'] = opts['host']
  50. rspamd_logger.warnx(rspamd_config, 'Using host parameters is deprecated. ' ..
  51. 'Please use socket = "%s"; instead', opts['host'])
  52. end
  53. -- WORKAROUND for deprecated host and port settings
  54. if not opts.symbol_bulk then
  55. opts.symbol_bulk = symbol_bulk
  56. end
  57. if not opts.symbol then
  58. opts.symbol = symbol
  59. end
  60. rule = dcc.configure(opts)
  61. if rule then
  62. local id = rspamd_config:register_symbol({
  63. name = 'DCC_CHECK',
  64. callback = check_dcc,
  65. type = 'callback',
  66. })
  67. rspamd_config:register_symbol {
  68. type = 'virtual',
  69. parent = id,
  70. name = opts.symbol
  71. }
  72. rspamd_config:register_symbol {
  73. type = 'virtual',
  74. parent = id,
  75. name = opts.symbol_bulk
  76. }
  77. rspamd_config:register_symbol {
  78. type = 'virtual',
  79. parent = id,
  80. name = 'DCC_FAIL'
  81. }
  82. rspamd_config:set_metric_symbol({
  83. group = N,
  84. score = 1.0,
  85. description = 'Detected as bulk mail by DCC',
  86. one_shot = true,
  87. name = opts.symbol_bulk,
  88. })
  89. rspamd_config:set_metric_symbol({
  90. group = N,
  91. score = 2.0,
  92. description = 'Rejected by DCC',
  93. one_shot = true,
  94. name = opts.symbol,
  95. })
  96. rspamd_config:set_metric_symbol({
  97. group = N,
  98. score = 0.0,
  99. description = 'DCC failure',
  100. one_shot = true,
  101. name = 'DCC_FAIL',
  102. })
  103. else
  104. lua_util.disable_module(N, "config")
  105. rspamd_logger.infox('DCC module not configured');
  106. end