Mercurial > prosody-modules
comparison mod_muc_access_control/mod_muc_access_control.lua @ 3024:f54c80404ad3
mod_muc_access_control: Multiple fixes to make the module work (fixes #1086)
| author | Frank Doepper <prosody@woffs.de> |
|---|---|
| date | Tue, 22 May 2018 16:13:03 +0100 |
| parents | 050cd7b6fa96 |
| children |
comparison
equal
deleted
inserted
replaced
| 3023:38365c1f1fe4 | 3024:f54c80404ad3 |
|---|---|
| 11 if not prepped_room_name then | 11 if not prepped_room_name then |
| 12 module:log("error", "Invalid room name: %s", unprepped_room_name); | 12 module:log("error", "Invalid room name: %s", unprepped_room_name); |
| 13 else | 13 else |
| 14 local prepped_list = {}; | 14 local prepped_list = {}; |
| 15 for _, unprepped_jid in ipairs(unprepped_list) do | 15 for _, unprepped_jid in ipairs(unprepped_list) do |
| 16 local prepped_jid = jid.prep(jid); | 16 local prepped_jid = jid.prep(unprepped_jid); |
| 17 if not prepped_jid then | 17 if not prepped_jid then |
| 18 module:log("error", "Invalid JID: %s", unprepped_jid); | 18 module:log("error", "Invalid JID: %s", unprepped_jid); |
| 19 else | 19 else |
| 20 table.insert(prepped_list, jid.pep(jid)); | 20 prepped_list[prepped_jid] = true; |
| 21 end | 21 end |
| 22 end | 22 end |
| 23 access_lists[prepped_room_name] = prepped_list; | |
| 23 end | 24 end |
| 24 end | 25 end |
| 25 | 26 |
| 26 local function is_restricted(room, who) | 27 local function is_restricted(room, who) |
| 27 local allowed = access_lists[room]; | 28 local allowed = access_lists[room]; |
| 32 | 33 |
| 33 return "forbidden"; | 34 return "forbidden"; |
| 34 end | 35 end |
| 35 | 36 |
| 36 module:hook("presence/full", function(event) | 37 module:hook("presence/full", function(event) |
| 37 local stanza = event.stanza; | 38 local stanza = event.stanza; |
| 38 | 39 |
| 39 if stanza.name == "presence" and stanza.attr.type == "unavailable" then -- Leaving events get discarded | 40 if stanza.name == "presence" and stanza.attr.type == "unavailable" then -- Leaving events get discarded |
| 40 return; | 41 return; |
| 41 end | 42 end |
| 42 | 43 |
| 43 -- Get the room | 44 -- Get the room |
| 44 local room = jid.split(stanza.attr.to); | 45 local room = jid.split(stanza.attr.to); |
| 45 if not room then return; end | 46 if not room then return; end |
| 46 | 47 |
| 47 -- Get who has tried to join it | 48 -- Get who has tried to join it |
| 48 local who = jid.bare(stanza.attr.from) | 49 local who = jid.bare(stanza.attr.from) |
| 49 | 50 |
| 50 -- Checking whether room is restricted | 51 -- Checking whether room is restricted |
| 51 local check_restricted = is_restricted(room, who) | 52 local check_restricted = is_restricted(room, who) |
| 52 if check_restricted ~= nil then | 53 if check_restricted ~= nil then |
| 53 event.allowed = false; | 54 event.allowed = false; |
| 54 event.stanza.attr.type = 'error'; | 55 event.stanza.attr.type = 'error'; |
| 55 return event.origin.send(st.error_reply(event.stanza, "cancel", "forbidden", "You're not allowed to enter this room: " .. check_restricted)); | 56 return event.origin.send(st.error_reply(event.stanza, "cancel", "forbidden", "You're not allowed to enter this room: " .. check_restricted)); |
| 56 end | 57 end |
| 57 end, 10); | 58 end, 10); |
