Comparison

plugins/mod_announce.lua @ 1396:ce3eb5f71899

mod_announce: Use usermanager.is_admin to verify admin status
author Waqas Hussain <waqas20@gmail.com>
date Tue, 23 Jun 2009 23:55:56 +0500
parent 1385:8999dd4253f9
child 1397:4c7b8b8ab569
comparison
equal deleted inserted replaced
1395:1c547fb4e570 1396:ce3eb5f71899
1 local st, jid, set = require "util.stanza", require "util.jid", require "util.set"; 1 local st, jid, set = require "util.stanza", require "util.jid", require "util.set";
2 2
3 local is_admin = require "core.usermanager".is_admin;
3 local admins = set.new(config.get(module:get_host(), "core", "admins")); 4 local admins = set.new(config.get(module:get_host(), "core", "admins"));
4 5
5 function handle_announcement(data) 6 function handle_announcement(data)
6 local origin, stanza = data.origin, data.stanza; 7 local origin, stanza = data.origin, data.stanza;
7 local host, resource = select(2, jid.split(stanza.attr.to)); 8 local host, resource = select(2, jid.split(stanza.attr.to));
8 9
9 if resource ~= "announce/online" then 10 if resource ~= "announce/online" then
10 return; -- Not an announcement 11 return; -- Not an announcement
11 end 12 end
12 13
13 if not admins:contains(jid.bare(origin.full_jid)) then 14 if not is_admin(origin.full_jid) then
14 -- Not an admin? Not allowed! 15 -- Not an admin? Not allowed!
15 module:log("warn", "Non-admin %s tried to send server announcement", tostring(jid.bare(origin.full_jid))); 16 module:log("warn", "Non-admin %s tried to send server announcement", tostring(jid.bare(origin.full_jid)));
16 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); 17 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
17 return; 18 return;
18 end 19 end