You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mod_s2s_whitelist.lua 968B

1234567891011121314151617181920212223242526
  1. -- Using as a base version https://hg.prosody.im/prosody-modules/file/c1a8ce147885/mod_s2s_whitelist/mod_s2s_whitelist.lua
  2. local st = require "util.stanza";
  3. local whitelist = module:get_option_inherited_set("s2s_whitelist", {});
  4. module:hook("route/remote", function (event)
  5. if not whitelist:contains(event.to_host) then
  6. -- make sure we do not send error replies for errors
  7. if event.stanza.attr.type == 'error' then
  8. module:log('debug', 'Not whitelisted destination domain for an error: %s', event.stanza);
  9. return true;
  10. end
  11. module:send(st.error_reply(event.stanza, "cancel", "not-allowed", "Communication with this domain is restricted"));
  12. return true;
  13. end
  14. end, 100);
  15. module:hook("s2s-stream-features", function (event)
  16. if not whitelist:contains(event.origin.from_host) then
  17. event.origin:close({
  18. condition = "policy-violation";
  19. text = "Communication with this domain is restricted";
  20. });
  21. end
  22. end, 1000);