rspamd.local.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. rspamd_config.MAILCOW_AUTH = {
  2. callback = function(task)
  3. local uname = task:get_user()
  4. if uname then
  5. return 1
  6. end
  7. end
  8. }
  9. modify_subject_map = rspamd_config:add_map({
  10. url = 'http://172.22.1.251:8081/tags.php',
  11. type = 'map',
  12. description = 'Map of users to use subject tags for'
  13. })
  14. local redis_params
  15. redis_params = rspamd_parse_redis_server('tag_settings')
  16. if redis_params then
  17. rspamd_config:register_symbol({
  18. name = 'TAG_MOO',
  19. type = 'postfilter',
  20. callback = function(task)
  21. local util = require("rspamd_util")
  22. local rspamd_logger = require "rspamd_logger"
  23. local tagged_rcpt = task:get_symbol("TAGGED_RCPT")
  24. local mailcow_domain = task:get_symbol("RCPT_MAILCOW_DOMAIN")
  25. local user = task:get_recipients(0)[1]['user']
  26. local domain = task:get_recipients(0)[1]['domain']
  27. local rcpt = user .. '@' .. domain
  28. if tagged_rcpt and mailcow_domain then
  29. local tag = tagged_rcpt[1].options[1]
  30. rspamd_logger.infox("found tag: %s", tag)
  31. local action = task:get_metric_action('default')
  32. rspamd_logger.infox("metric action now: %s", action)
  33. if action ~= 'no action' and action ~= 'greylist' then
  34. rspamd_logger.infox("skipping tag handler for action: %s", action)
  35. task:set_metric_action('default', action)
  36. return true
  37. end
  38. local wants_subject_tag = task:get_symbol("RCPT_WANTS_SUBJECT_TAG")
  39. if wants_subject_tag then
  40. rspamd_logger.infox("user wants subject modified for tagged mail")
  41. local sbj = task:get_header('Subject')
  42. new_sbj = '=?UTF-8?B?' .. tostring(util.encode_base64('[' .. tag .. '] ' .. sbj)) .. '?='
  43. task:set_rmilter_reply({
  44. remove_headers = {['Subject'] = 1},
  45. add_headers = {['Subject'] = new_sbj}
  46. })
  47. else
  48. rspamd_logger.infox("Add X-Moo-Tag header")
  49. task:set_rmilter_reply({
  50. add_headers = {['X-Moo-Tag'] = 'YES'}
  51. })
  52. end
  53. end
  54. end,
  55. priority = 10
  56. })
  57. end
  58. rspamd_config.MRAPTOR = {
  59. callback = function(task)
  60. local parts = task:get_parts()
  61. local rspamd_logger = require "rspamd_logger"
  62. local rspamd_regexp = require "rspamd_regexp"
  63. if parts then
  64. for _,p in ipairs(parts) do
  65. local mtype,subtype = p:get_type()
  66. local re = rspamd_regexp.create_cached('/(office|word|excel)/i')
  67. if re:match(subtype) then
  68. local content = tostring(p:get_content())
  69. local filename = p:get_filename()
  70. local file = os.tmpname()
  71. f = io.open(file, "a+")
  72. f:write(content)
  73. f:close()
  74. local scan = assert(io.popen('PATH=/usr/bin:/usr/local/bin mraptor ' .. file .. '> /dev/null 2>&1; echo $?', 'r'))
  75. local result = scan:read('*all')
  76. local exit_code = string.match(result, "%d+")
  77. rspamd_logger.infox(exit_code)
  78. scan:close()
  79. if exit_code == "20" then
  80. rspamd_logger.infox("Reject dangerous macro in office file " .. filename)
  81. task:set_pre_result(rspamd_actions['reject'], 'Dangerous macro in office file ' .. filename)
  82. end
  83. end
  84. end
  85. end
  86. end
  87. }