rspamd.local.lua 3.4 KB

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