rspamd.local.lua 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. local tag = nil
  25. local util = require("rspamd_util")
  26. local rspamd_logger = require "rspamd_logger"
  27. local user_tagged = task:get_recipients(2)[1]['user']
  28. local domain = task:get_recipients(1)[1]['domain']
  29. local user, tag = user_tagged:match("([^+]+)+(.*)")
  30. local authdomain = auth_domain_map:get_key(domain)
  31. if tag and authdomain then
  32. rspamd_logger.infox("domain: %1, tag: %2", domain, tag)
  33. local user_untagged = user .. '@' .. domain
  34. rspamd_logger.infox("querying tag settings for user %1", user_untagged)
  35. if modify_subject_map:get_key(user_untagged) then
  36. rspamd_logger.infox("found user in map for subject rewrite")
  37. local sbj = task:get_header('Subject')
  38. new_sbj = '=?UTF-8?B?' .. tostring(util.encode_base64('[' .. tag .. '] ' .. sbj)) .. '?='
  39. task:set_rmilter_reply({
  40. remove_headers = {['Subject'] = 1},
  41. add_headers = {['Subject'] = new_sbj}
  42. })
  43. else
  44. rspamd_logger.infox("add X-Moo-Tag header")
  45. task:set_rmilter_reply({
  46. add_headers = {['X-Moo-Tag'] = 'YES'}
  47. })
  48. end
  49. else
  50. rspamd_logger.infox("skip delimiter handling for untagged message or authenticated user")
  51. end
  52. return false
  53. end
  54. }
  55. rspamd_config.MRAPTOR = {
  56. callback = function(task)
  57. local parts = task:get_parts()
  58. local rspamd_logger = require "rspamd_logger"
  59. local rspamd_regexp = require "rspamd_regexp"
  60. if parts then
  61. for _,p in ipairs(parts) do
  62. local mtype,subtype = p:get_type()
  63. local re = rspamd_regexp.create_cached('/(office|word|excel)/i')
  64. if re:match(subtype) then
  65. local content = tostring(p:get_content())
  66. local filename = p:get_filename()
  67. local file = os.tmpname()
  68. f = io.open(file, "a+")
  69. f:write(content)
  70. f:close()
  71. local scan = assert(io.popen('PATH=/usr/bin:/usr/local/bin mraptor ' .. file .. '> /dev/null 2>&1; echo $?', 'r'))
  72. local result = scan:read('*all')
  73. local exit_code = string.match(result, "%d+")
  74. rspamd_logger.infox(exit_code)
  75. scan:close()
  76. if exit_code == "20" then
  77. rspamd_logger.infox("Reject dangerous macro in office file " .. filename)
  78. task:set_pre_result(rspamd_actions['reject'], 'Dangerous macro in office file ' .. filename)
  79. end
  80. end
  81. end
  82. end
  83. end
  84. }