Comparison

plugins/muc/mod_muc.lua @ 2033:38d32c154cec

MUC: Added config option 'restrict_room_creation' to allow restricting room creation to admins.
author Waqas Hussain <waqas20@gmail.com>
date Wed, 21 Oct 2009 11:58:33 +0500
parent 2028:4f33100195a0
child 2458:b4628c4d9ee2
child 2923:b7049746bd29
comparison
equal deleted inserted replaced
2032:2714ccde2569 2033:38d32c154cec
12 end 12 end
13 13
14 local muc_host = module:get_host(); 14 local muc_host = module:get_host();
15 local muc_name = module:get_option("name"); 15 local muc_name = module:get_option("name");
16 if type(muc_name) ~= "string" then muc_name = "Prosody Chatrooms"; end 16 if type(muc_name) ~= "string" then muc_name = "Prosody Chatrooms"; end
17 local restrict_room_creation = module:get_option("restrict_room_creation");
18 if restrict_room_creation and restrict_room_creation ~= true then restrict_room_creation = nil; end
17 local history_length = 20; 19 local history_length = 20;
18 20
19 local muc_new_room = module:require "muc".new_room; 21 local muc_new_room = module:require "muc".new_room;
20 local register_component = require "core.componentmanager".register_component; 22 local register_component = require "core.componentmanager".register_component;
21 local deregister_component = require "core.componentmanager".deregister_component; 23 local deregister_component = require "core.componentmanager".deregister_component;
22 local jid_split = require "util.jid".split; 24 local jid_split = require "util.jid".split;
25 local jid_bare = require "util.jid".bare;
23 local st = require "util.stanza"; 26 local st = require "util.stanza";
24 local uuid_gen = require "util.uuid".generate; 27 local uuid_gen = require "util.uuid".generate;
25 local datamanager = require "util.datamanager"; 28 local datamanager = require "util.datamanager";
29 local um_is_admin = require "core.usermanager".is_admin;
26 30
27 local rooms = {}; 31 local rooms = {};
28 local persistent_rooms = datamanager.load(nil, muc_host, "persistent") or {}; 32 local persistent_rooms = datamanager.load(nil, muc_host, "persistent") or {};
29 local component; 33 local component;
34
35 local function is_admin(jid)
36 return um_is_admin(jid) or um_is_admin(jid, module.host);
37 end
30 38
31 local function room_route_stanza(room, stanza) core_post_stanza(component, stanza); end 39 local function room_route_stanza(room, stanza) core_post_stanza(component, stanza); end
32 local function room_save(room, forced) 40 local function room_save(room, forced)
33 local node = jid_split(room.jid); 41 local node = jid_split(room.jid);
34 persistent_rooms[room.jid] = room._data.persistent; 42 persistent_rooms[room.jid] = room._data.persistent;
103 if to_node then 111 if to_node then
104 local bare = to_node.."@"..to_host; 112 local bare = to_node.."@"..to_host;
105 if to_host == muc_host or bare == muc_host then 113 if to_host == muc_host or bare == muc_host then
106 local room = rooms[bare]; 114 local room = rooms[bare];
107 if not room then 115 if not room then
108 room = muc_new_room(bare); 116 if not(restrict_room_creation) or is_admin(stanza.attr.from) then
109 room.route_stanza = room_route_stanza; 117 room = muc_new_room(bare);
110 room.save = room_save; 118 room.route_stanza = room_route_stanza;
111 rooms[bare] = room; 119 room.save = room_save;
120 rooms[bare] = room;
121 end
112 end 122 end
113 room:handle_stanza(origin, stanza); 123 if room then
114 if not next(room._occupants) and not persistent_rooms[room.jid] then -- empty, non-persistent room 124 room:handle_stanza(origin, stanza);
115 rooms[bare] = nil; -- discard room 125 if not next(room._occupants) and not persistent_rooms[room.jid] then -- empty, non-persistent room
126 rooms[bare] = nil; -- discard room
127 end
128 else
129 origin.send(st.error_reply(stanza, "cancel", "not-allowed"));
116 end 130 end
117 else --[[not for us?]] end 131 else --[[not for us?]] end
118 return; 132 return;
119 end 133 end
120 -- to the main muc domain 134 -- to the main muc domain