rspamd.local.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. end
  42. if authdomain then
  43. rspamd_logger.infox("found mailcow domain %s", domain)
  44. rspamd_logger.infox("querying tag settings for user %s", rcpt)
  45. if modify_subject_map:get_key(rcpt) then
  46. rspamd_logger.infox("user wants subject modified for tagged mail")
  47. local sbj = task:get_header('Subject')
  48. new_sbj = '=?UTF-8?B?' .. tostring(util.encode_base64('[' .. tag .. '] ' .. sbj)) .. '?='
  49. task:set_rmilter_reply({
  50. remove_headers = {['Subject'] = 1},
  51. add_headers = {['Subject'] = new_sbj}
  52. })
  53. else
  54. rspamd_logger.infox("Add X-Moo-Tag header")
  55. task:set_rmilter_reply({
  56. add_headers = {['X-Moo-Tag'] = 'YES'}
  57. })
  58. end
  59. else
  60. rspamd_logger.infox("skip delimiter handling for unknown domain")
  61. end
  62. return false
  63. end
  64. end,
  65. priority = 10
  66. })
  67. rspamd_config.MRAPTOR = {
  68. callback = function(task)
  69. local parts = task:get_parts()
  70. local rspamd_logger = require "rspamd_logger"
  71. local rspamd_regexp = require "rspamd_regexp"
  72. if parts then
  73. for _,p in ipairs(parts) do
  74. local mtype,subtype = p:get_type()
  75. local re = rspamd_regexp.create_cached('/(office|word|excel)/i')
  76. if re:match(subtype) then
  77. local content = tostring(p:get_content())
  78. local filename = p:get_filename()
  79. local file = os.tmpname()
  80. f = io.open(file, "a+")
  81. f:write(content)
  82. f:close()
  83. local scan = assert(io.popen('PATH=/usr/bin:/usr/local/bin mraptor ' .. file .. '> /dev/null 2>&1; echo $?', 'r'))
  84. local result = scan:read('*all')
  85. local exit_code = string.match(result, "%d+")
  86. rspamd_logger.infox(exit_code)
  87. scan:close()
  88. if exit_code == "20" then
  89. rspamd_logger.infox("Reject dangerous macro in office file " .. filename)
  90. task:set_pre_result(rspamd_actions['reject'], 'Dangerous macro in office file ' .. filename)
  91. end
  92. end
  93. end
  94. end
  95. end
  96. }