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. local 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. local 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.ADD_DELIMITER_TAG = {
  23. callback = function(task)
  24. tag = nil
  25. local util = require("rspamd_util")
  26. local rspamd_logger = require "rspamd_logger"
  27. local user_env_tagged = task:get_recipients(1)[1]['user']
  28. local user_to_tagged = task:get_recipients(2)[1]['user']
  29. local domain = task:get_recipients(1)[1]['domain']
  30. local user_env, tag_env = user_env_tagged:match("([^+]+)+(.*)")
  31. local user_to, tag_to = user_to_tagged:match("([^+]+)+(.*)")
  32. local authdomain = auth_domain_map:get_key(domain)
  33. if tag_env then
  34. tag = tag_env
  35. user = user_env
  36. elseif tag_to then
  37. tag = tag_to
  38. user = user_env
  39. end
  40. if tag and authdomain then
  41. rspamd_logger.infox("Domain %s is part of mailcow, start reading tag settings", domain)
  42. local user_untagged = user .. '@' .. domain
  43. rspamd_logger.infox("Querying tag settings for user %1", user_untagged)
  44. if modify_subject_map:get_key(user_untagged) then
  45. rspamd_logger.infox("User wants subject modified for tagged mail")
  46. local sbj = task:get_header('Subject')
  47. if tag then
  48. rspamd_logger.infox("Found tag %1, will modify subject header", tag)
  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. end
  55. else
  56. rspamd_logger.infox("Add X-Moo-Tag header")
  57. task:set_rmilter_reply({
  58. add_headers = {['X-Moo-Tag'] = 'YES'}
  59. })
  60. end
  61. else
  62. rspamd_logger.infox("Skip delimiter handling for untagged message or authenticated user")
  63. end
  64. return false
  65. end
  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. }