rspamd.local.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.ADD_DELIMITER_TAG = {
  23. callback = function(task)
  24. tag = nil
  25. local tag_env = nil
  26. local tag_to = nil
  27. local util = require("rspamd_util")
  28. local rspamd_logger = require "rspamd_logger"
  29. local user_env_tagged = task:get_recipients(1)[1]['user']
  30. local user_to_tagged = task:get_recipients(2)[1]['user']
  31. local domain = task:get_recipients(1)[1]['domain']
  32. local user_env, tag_env = user_env_tagged:match("([^+]+)+(.*)")
  33. local user_to, tag_to = user_to_tagged:match("([^+]+)+(.*)")
  34. local authdomain = auth_domain_map:get_key(domain)
  35. if tag_env then
  36. tag = tag_env
  37. user = user_env
  38. elseif tag_to then
  39. tag = tag_to
  40. user = user_env
  41. end
  42. if tag and authdomain then
  43. rspamd_logger.infox("Domain %s is part of mailcow, start reading tag settings", domain)
  44. local user_untagged = user .. '@' .. domain
  45. rspamd_logger.infox("Querying tag settings for user %1", user_untagged)
  46. if modify_subject_map:get_key(user_untagged) then
  47. rspamd_logger.infox("User wants subject modified for tagged mail")
  48. local sbj = task:get_header('Subject')
  49. if tag then
  50. rspamd_logger.infox("Found tag %1, will modify subject header", tag)
  51. new_sbj = '=?UTF-8?B?' .. tostring(util.encode_base64('[' .. tag .. '] ' .. sbj)) .. '?='
  52. task:set_rmilter_reply({
  53. remove_headers = {['Subject'] = 1},
  54. add_headers = {['Subject'] = new_sbj}
  55. })
  56. end
  57. else
  58. rspamd_logger.infox("Add X-Moo-Tag header")
  59. task:set_rmilter_reply({
  60. add_headers = {['X-Moo-Tag'] = 'YES'}
  61. })
  62. end
  63. else
  64. rspamd_logger.infox("Skip delimiter handling for untagged message or authenticated user")
  65. end
  66. return false
  67. end
  68. }
  69. rspamd_config.MRAPTOR = {
  70. callback = function(task)
  71. local parts = task:get_parts()
  72. local rspamd_logger = require "rspamd_logger"
  73. local rspamd_regexp = require "rspamd_regexp"
  74. if parts then
  75. for _,p in ipairs(parts) do
  76. local mtype,subtype = p:get_type()
  77. local re = rspamd_regexp.create_cached('/(office|word|excel)/i')
  78. if re:match(subtype) then
  79. local content = tostring(p:get_content())
  80. local filename = p:get_filename()
  81. local file = os.tmpname()
  82. f = io.open(file, "a+")
  83. f:write(content)
  84. f:close()
  85. local scan = assert(io.popen('PATH=/usr/bin:/usr/local/bin mraptor ' .. file .. '> /dev/null 2>&1; echo $?', 'r'))
  86. local result = scan:read('*all')
  87. local exit_code = string.match(result, "%d+")
  88. rspamd_logger.infox(exit_code)
  89. scan:close()
  90. if exit_code == "20" then
  91. rspamd_logger.infox("Reject dangerous macro in office file " .. filename)
  92. task:set_pre_result(rspamd_actions['reject'], 'Dangerous macro in office file ' .. filename)
  93. end
  94. end
  95. end
  96. end
  97. end
  98. }