aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2009-10-21 12:02:30 +0500
committerWaqas Hussain <waqas20@gmail.com>2009-10-21 12:02:30 +0500
commitfe9ea9641ba0ac94afe943d47b44cb3305356a95 (patch)
tree539c0318c44f84cc9808840daff3cde0264e81fa
parent1d89d7c92ca542ea063033148d25c25409f31a80 (diff)
parent27298d7e5b5d1c40e378f7169e1c96293791c021 (diff)
downloadprosody-fe9ea9641ba0ac94afe943d47b44cb3305356a95.tar.gz
prosody-fe9ea9641ba0ac94afe943d47b44cb3305356a95.zip
Merged with trunk.
-rw-r--r--core/usermanager.lua15
-rw-r--r--plugins/mod_lastactivity.lua2
-rw-r--r--plugins/muc/mod_muc.lua31
3 files changed, 32 insertions, 16 deletions
diff --git a/core/usermanager.lua b/core/usermanager.lua
index 6c36fa29..925ac774 100644
--- a/core/usermanager.lua
+++ b/core/usermanager.lua
@@ -6,10 +6,7 @@
-- COPYING file in the source package for more information.
--
-
-
-require "util.datamanager"
-local datamanager = datamanager;
+local datamanager = require "util.datamanager";
local log = require "util.logger".init("usermanager");
local type = type;
local error = error;
@@ -66,14 +63,18 @@ function get_supported_methods(host)
return {["PLAIN"] = true, ["DIGEST-MD5"] = true}; -- TODO this should be taken from the config
end
-function is_admin(jid)
- local admins = config.get("*", "core", "admins");
+function is_admin(jid, host)
+ host = host or "*";
+ local admins = config.get(host, "core", "admins");
+ if host ~= "*" and admins == config.get("*", "core", "admins") then
+ return nil;
+ end
if type(admins) == "table" then
jid = jid_bare(jid);
for _,admin in ipairs(admins) do
if admin == jid then return true; end
end
- else log("debug", "Option core.admins is not a table"); end
+ elseif admins then log("warn", "Option 'admins' for host '%s' is not a table", host); end
return nil;
end
diff --git a/plugins/mod_lastactivity.lua b/plugins/mod_lastactivity.lua
index cb914fe3..a0da9829 100644
--- a/plugins/mod_lastactivity.lua
+++ b/plugins/mod_lastactivity.lua
@@ -23,7 +23,7 @@ module:hook("pre-presence/bare", function(event)
s = s and #s.tags == 0 and s[1] or "";
map[event.origin.username] = {s = s, t = t};
end
-end);
+end, 10);
module:hook("iq/bare/jabber:iq:last:query", function(event)
local origin, stanza = event.origin, event.stanza;
diff --git a/plugins/muc/mod_muc.lua b/plugins/muc/mod_muc.lua
index 3e6fafb8..856f3cba 100644
--- a/plugins/muc/mod_muc.lua
+++ b/plugins/muc/mod_muc.lua
@@ -12,21 +12,30 @@ if module:get_host_type() ~= "component" then
end
local muc_host = module:get_host();
-local muc_name = "Chatrooms";
+local muc_name = module:get_option("name");
+if type(muc_name) ~= "string" then muc_name = "Prosody Chatrooms"; end
+local restrict_room_creation = module:get_option("restrict_room_creation");
+if restrict_room_creation and restrict_room_creation ~= true then restrict_room_creation = nil; end
local history_length = 20;
local muc_new_room = module:require "muc".new_room;
local register_component = require "core.componentmanager".register_component;
local deregister_component = require "core.componentmanager".deregister_component;
local jid_split = require "util.jid".split;
+local jid_bare = require "util.jid".bare;
local st = require "util.stanza";
local uuid_gen = require "util.uuid".generate;
local datamanager = require "util.datamanager";
+local um_is_admin = require "core.usermanager".is_admin;
local rooms = {};
local persistent_rooms = datamanager.load(nil, muc_host, "persistent") or {};
local component;
+local function is_admin(jid)
+ return um_is_admin(jid) or um_is_admin(jid, module.host);
+end
+
local function room_route_stanza(room, stanza) core_post_stanza(component, stanza); end
local function room_save(room, forced)
local node = jid_split(room.jid);
@@ -104,14 +113,20 @@ component = register_component(muc_host, function(origin, stanza)
if to_host == muc_host or bare == muc_host then
local room = rooms[bare];
if not room then
- room = muc_new_room(bare);
- room.route_stanza = room_route_stanza;
- room.save = room_save;
- rooms[bare] = room;
+ if not(restrict_room_creation) or is_admin(stanza.attr.from) then
+ room = muc_new_room(bare);
+ room.route_stanza = room_route_stanza;
+ room.save = room_save;
+ rooms[bare] = room;
+ end
end
- room:handle_stanza(origin, stanza);
- if not next(room._occupants) and not persistent_rooms[room.jid] then -- empty, non-persistent room
- rooms[bare] = nil; -- discard room
+ if room then
+ room:handle_stanza(origin, stanza);
+ if not next(room._occupants) and not persistent_rooms[room.jid] then -- empty, non-persistent room
+ rooms[bare] = nil; -- discard room
+ end
+ else
+ origin.send(st.error_reply(stanza, "cancel", "not-allowed"));
end
else --[[not for us?]] end
return;