您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

mod_muc_allowners.lua 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. local jid = require "util.jid";
  2. local um_is_admin = require "core.usermanager".is_admin;
  3. local util = module:require "util";
  4. local is_healthcheck_room = util.is_healthcheck_room;
  5. local extract_subdomain = util.extract_subdomain;
  6. local moderated_subdomains;
  7. local moderated_rooms;
  8. local function load_config()
  9. moderated_subdomains = module:get_option_set("allowners_moderated_subdomains", {})
  10. moderated_rooms = module:get_option_set("allowners_moderated_rooms", {})
  11. end
  12. load_config();
  13. local function is_admin(jid)
  14. return um_is_admin(jid, module.host);
  15. end
  16. -- Checks whether the jid is moderated, the room name is in moderated_rooms
  17. -- or if the subdomain is in the moderated_subdomains
  18. -- @return returns on of the:
  19. -- -> false
  20. -- -> true, room_name, subdomain
  21. -- -> true, room_name, nil (if no subdomain is used for the room)
  22. local function is_moderated(room_jid)
  23. if moderated_subdomains:empty() and moderated_rooms:empty() then
  24. return false;
  25. end
  26. local room_node = jid.node(room_jid);
  27. -- parses bare room address, for multidomain expected format is:
  28. -- [subdomain]roomName@conference.domain
  29. local target_subdomain, target_room_name = extract_subdomain(room_node);
  30. if target_subdomain then
  31. if moderated_subdomains:contains(target_subdomain) then
  32. return true, target_room_name, target_subdomain;
  33. end
  34. elseif moderated_rooms:contains(room_node) then
  35. return true, room_node, nil;
  36. end
  37. return false;
  38. end
  39. module:hook("muc-occupant-joined", function (event)
  40. local room, occupant = event.room, event.occupant;
  41. if is_healthcheck_room(room.jid) or is_admin(occupant.jid) then
  42. return;
  43. end
  44. local moderated, room_name, subdomain = is_moderated(room.jid);
  45. if moderated then
  46. local session = event.origin;
  47. local token = session.auth_token;
  48. if not token then
  49. module:log('debug', 'skip allowners for non-auth user subdomain:%s room_name:%s', subdomain, room_name);
  50. return;
  51. end
  52. if not (room_name == session.jitsi_meet_room or session.jitsi_meet_room == '*') then
  53. module:log('debug', 'skip allowners for auth user and non matching room name: %s, jwt room name: %s', room_name, session.jitsi_meet_room);
  54. return;
  55. end
  56. if not (subdomain == session.jitsi_meet_context_group) then
  57. module:log('debug', 'skip allowners for auth user and non matching room subdomain: %s, jwt subdomain: %s', subdomain, session.jitsi_meet_context_group);
  58. return;
  59. end
  60. end
  61. room:set_affiliation(true, occupant.bare_jid, "owner");
  62. end, 2);
  63. module:hook("muc-occupant-left", function (event)
  64. local room, occupant = event.room, event.occupant;
  65. if is_healthcheck_room(room.jid) then
  66. return;
  67. end
  68. room:set_affiliation(true, occupant.bare_jid, nil);
  69. end, 2);
  70. module:hook_global('config-reloaded', load_config);