選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

mod_muc_allowners.lua 2.7KB

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