annotate mod_compat_muc_admin/mod_compat_muc_admin.lua @ 628:c72be31941fa

mod_compat_muc_admin: we shall make sure that only owners can destroy rooms and not everyone, isn't it?
author Marco Cirillo <maranda@lightwitch.org>
date Tue, 27 Mar 2012 16:07:52 +0000
parents a8ff69c9b498
children 7d4cde86b12e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
627
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
1 local st = require "util.stanza";
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
2 local jid_split = require "util.jid".split;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
3 local jid_bare = require "util.jid".bare;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
4 local jid_prep = require "util.jid".prep;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
5 local log = require "util.logger".init("mod_muc");
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
6 local muc_host = module:get_host();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
7
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
8 if not hosts[muc_host].modules.muc then -- Not a MUC host
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
9 module:log("error", "this module can only be used on muc hosts."); return false;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
10 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
11
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
12 local xmlns_ma, xmlns_mo = "http://jabber.org/protocol/muc#admin", "http://jabber.org/protocol/muc#owner";
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
13
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
14 -- COMPAT: iq condensed function
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
15 hosts[muc_host].modules.muc.stanza_handler.muc_new_room.room_mt["compat_iq"] = function (self, origin, stanza, xmlns)
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
16 local actor = stanza.attr.from;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
17 local affiliation = self:get_affiliation(actor);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
18 local current_nick = self._jid_nick[actor];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
19 local role = current_nick and self._occupants[current_nick].role or self:get_default_role(affiliation);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
20 local item = stanza.tags[1].tags[1];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
21 if item and item.name == "item" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
22 if stanza.attr.type == "set" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
23 local callback = function() origin.send(st.reply(stanza)); end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
24 if item.attr.jid then -- Validate provided JID
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
25 item.attr.jid = jid_prep(item.attr.jid);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
26 if not item.attr.jid then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
27 origin.send(st.error_reply(stanza, "modify", "jid-malformed"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
28 return;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
29 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
30 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
31 if not item.attr.jid and item.attr.nick then -- COMPAT Workaround for Miranda sending 'nick' instead of 'jid' when changing affiliation
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
32 local occupant = self._occupants[self.jid.."/"..item.attr.nick];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
33 if occupant then item.attr.jid = occupant.jid; end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
34 elseif not item.attr.nick and item.attr.jid then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
35 local nick = self._jid_nick[item.attr.jid];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
36 if nick then item.attr.nick = select(3, jid_split(nick)); end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
37 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
38 local reason = item.tags[1] and item.tags[1].name == "reason" and #item.tags[1] == 1 and item.tags[1][1];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
39 if item.attr.affiliation and item.attr.jid and not item.attr.role then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
40 local success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, callback, reason);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
41 if not success then origin.send(st.error_reply(stanza, errtype, err)); end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
42 elseif item.attr.role and item.attr.nick and not item.attr.affiliation then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
43 local success, errtype, err = self:set_role(actor, self.jid.."/"..item.attr.nick, item.attr.role, callback, reason);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
44 if not success then origin.send(st.error_reply(stanza, errtype, err)); end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
45 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
46 origin.send(st.error_reply(stanza, "cancel", "bad-request"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
47 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
48 elseif stanza.attr.type == "get" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
49 local _aff = item.attr.affiliation;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
50 local _rol = item.attr.role;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
51 if _aff and not _rol then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
52 if affiliation == "owner" or (affiliation == "admin" and _aff ~= "owner" and _aff ~= "admin") then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
53 local reply = st.reply(stanza):query(xmlns);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
54 for jid, affiliation in pairs(self._affiliations) do
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
55 if affiliation == _aff then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
56 reply:tag("item", {affiliation = _aff, jid = jid}):up();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
57 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
58 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
59 origin.send(reply);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
60 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
61 origin.send(st.error_reply(stanza, "auth", "forbidden"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
62 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
63 elseif _rol and not _aff then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
64 if role == "moderator" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
65 -- TODO allow admins and owners not in room? Provide read-only access to everyone who can see the participants anyway?
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
66 if _rol == "none" then _rol = nil; end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
67 local reply = st.reply(stanza):query(xmlns);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
68 for occupant_jid, occupant in pairs(self._occupants) do
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
69 if occupant.role == _rol then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
70 reply:tag("item", {
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
71 nick = select(3, jid_split(occupant_jid)),
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
72 role = _rol or "none",
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
73 affiliation = occupant.affiliation or "none",
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
74 jid = occupant.jid
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
75 }):up();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
76 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
77 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
78 origin.send(reply);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
79 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
80 origin.send(st.error_reply(stanza, "auth", "forbidden"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
81 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
82 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
83 origin.send(st.error_reply(stanza, "cancel", "bad-request"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
84 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
85 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
86 elseif stanza.attr.type == "set" or stanza.attr.type == "get" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
87 origin.send(st.error_reply(stanza, "cancel", "bad-request"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
88 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
89 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
90
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
91 -- COMPAT: reworked handle_to_room function
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
92 hosts[muc_host].modules.muc.stanza_handler.muc_new_room.room_mt["handle_to_room"] = function (self, origin, stanza)
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
93 local type = stanza.attr.type;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
94 local xmlns = stanza.tags[1] and stanza.tags[1].attr.xmlns;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
95 if stanza.name == "iq" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
96 if xmlns == "http://jabber.org/protocol/disco#info" and type == "get" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
97 origin.send(self:get_disco_info(stanza));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
98 elseif xmlns == "http://jabber.org/protocol/disco#items" and type == "get" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
99 origin.send(self:get_disco_items(stanza));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
100 elseif (xmlns == xmlns_ma or xmlns == xmlns_mo) then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
101 if xmlns == xmlns_ma then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
102 self:compat_iq(origin, stanza, xmlns);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
103 elseif xmlns == xmlns_mo and stanza.tags[1].name == "query" and #stanza.tags[1].tags == 0 and
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
104 stanza.attr.type == "get" then -- form request
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
105 if self:get_affiliation(stanza.attr.from) ~= "owner" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
106 origin.send(st.error_reply(stanza, "auth", "forbidden", "Only owners can configure rooms"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
107 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
108 self:send_form(origin, stanza);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
109 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
110 elseif xmlns == xmlns_mo and stanza.tags[1].name == "query" and stanza.tags[1]:get_child("x", "jabber:x:data") and
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
111 stanza.attr.type == "set" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
112 if self:get_affiliation(stanza.attr.from) ~= "owner" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
113 origin.send(st.error_reply(stanza, "auth", "forbidden", "Only owners can configure rooms"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
114 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
115 self:process_form(origin, stanza);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
116 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
117 elseif xmlns == xmlns_mo and stanza.tags[1].tags[1] then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
118 local child = stanza.tags[1].tags[1];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
119 if child.name == "destroy" then
628
c72be31941fa mod_compat_muc_admin: we shall make sure that only owners can destroy rooms and not everyone, isn't it?
Marco Cirillo <maranda@lightwitch.org>
parents: 627
diff changeset
120 if self:get_affiliation(stanza.attr.from) == "owner" then
c72be31941fa mod_compat_muc_admin: we shall make sure that only owners can destroy rooms and not everyone, isn't it?
Marco Cirillo <maranda@lightwitch.org>
parents: 627
diff changeset
121 local newjid = child.attr.jid;
c72be31941fa mod_compat_muc_admin: we shall make sure that only owners can destroy rooms and not everyone, isn't it?
Marco Cirillo <maranda@lightwitch.org>
parents: 627
diff changeset
122 local reason, password;
c72be31941fa mod_compat_muc_admin: we shall make sure that only owners can destroy rooms and not everyone, isn't it?
Marco Cirillo <maranda@lightwitch.org>
parents: 627
diff changeset
123 for _,tag in ipairs(child.tags) do
c72be31941fa mod_compat_muc_admin: we shall make sure that only owners can destroy rooms and not everyone, isn't it?
Marco Cirillo <maranda@lightwitch.org>
parents: 627
diff changeset
124 if tag.name == "reason" then
c72be31941fa mod_compat_muc_admin: we shall make sure that only owners can destroy rooms and not everyone, isn't it?
Marco Cirillo <maranda@lightwitch.org>
parents: 627
diff changeset
125 reason = #tag.tags == 0 and tag[1];
c72be31941fa mod_compat_muc_admin: we shall make sure that only owners can destroy rooms and not everyone, isn't it?
Marco Cirillo <maranda@lightwitch.org>
parents: 627
diff changeset
126 elseif tag.name == "password" then
c72be31941fa mod_compat_muc_admin: we shall make sure that only owners can destroy rooms and not everyone, isn't it?
Marco Cirillo <maranda@lightwitch.org>
parents: 627
diff changeset
127 password = #tag.tags == 0 and tag[1];
c72be31941fa mod_compat_muc_admin: we shall make sure that only owners can destroy rooms and not everyone, isn't it?
Marco Cirillo <maranda@lightwitch.org>
parents: 627
diff changeset
128 end
627
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
129 end
628
c72be31941fa mod_compat_muc_admin: we shall make sure that only owners can destroy rooms and not everyone, isn't it?
Marco Cirillo <maranda@lightwitch.org>
parents: 627
diff changeset
130 self:destroy(newjid, reason, password);
c72be31941fa mod_compat_muc_admin: we shall make sure that only owners can destroy rooms and not everyone, isn't it?
Marco Cirillo <maranda@lightwitch.org>
parents: 627
diff changeset
131 origin.send(st.reply(stanza));
c72be31941fa mod_compat_muc_admin: we shall make sure that only owners can destroy rooms and not everyone, isn't it?
Marco Cirillo <maranda@lightwitch.org>
parents: 627
diff changeset
132 else origin.send(st.error_reply(stanza, "auth", "forbidden", "Only owners can destroy rooms")); end
627
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
133 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
134 self:compat_iq(origin, stanza, xmlns);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
135 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
136 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
137 origin.send(st.error_reply(stanza, "modify", "bad-request"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
138 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
139 elseif type == "set" or type == "get" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
140 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
141 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
142 elseif stanza.name == "message" and type == "groupchat" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
143 local from, to = stanza.attr.from, stanza.attr.to;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
144 local room = jid_bare(to);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
145 local current_nick = self._jid_nick[from];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
146 local occupant = self._occupants[current_nick];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
147 if not occupant then -- not in room
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
148 origin.send(st.error_reply(stanza, "cancel", "not-acceptable"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
149 elseif occupant.role == "visitor" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
150 origin.send(st.error_reply(stanza, "cancel", "forbidden"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
151 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
152 local from = stanza.attr.from;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
153 stanza.attr.from = current_nick;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
154 local subject = getText(stanza, {"subject"});
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
155 if subject then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
156 if occupant.role == "moderator" or
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
157 ( self._data.changesubject and occupant.role == "participant" ) then -- and participant
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
158 self:set_subject(current_nick, subject); -- TODO use broadcast_message_stanza
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
159 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
160 stanza.attr.from = from;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
161 origin.send(st.error_reply(stanza, "cancel", "forbidden"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
162 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
163 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
164 self:broadcast_message(stanza, true);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
165 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
166 stanza.attr.from = from;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
167 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
168 elseif stanza.name == "message" and type == "error" and is_kickable_error(stanza) then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
169 local current_nick = self._jid_nick[stanza.attr.from];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
170 log("debug", "%s kicked from %s for sending an error message", current_nick, self.jid);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
171 self:handle_to_occupant(origin, build_unavailable_presence_from_error(stanza)); -- send unavailable
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
172 elseif stanza.name == "presence" then -- hack - some buggy clients send presence updates to the room rather than their nick
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
173 local to = stanza.attr.to;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
174 local current_nick = self._jid_nick[stanza.attr.from];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
175 if current_nick then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
176 stanza.attr.to = current_nick;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
177 self:handle_to_occupant(origin, stanza);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
178 stanza.attr.to = to;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
179 elseif type ~= "error" and type ~= "result" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
180 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
181 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
182 elseif stanza.name == "message" and not stanza.attr.type and #stanza.tags == 1 and self._jid_nick[stanza.attr.from]
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
183 and stanza.tags[1].name == "x" and stanza.tags[1].attr.xmlns == "http://jabber.org/protocol/muc#user" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
184 local x = stanza.tags[1];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
185 local payload = (#x.tags == 1 and x.tags[1]);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
186 if payload and payload.name == "invite" and payload.attr.to then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
187 local _from, _to = stanza.attr.from, stanza.attr.to;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
188 local _invitee = jid_prep(payload.attr.to);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
189 if _invitee then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
190 local _reason = payload.tags[1] and payload.tags[1].name == 'reason' and #payload.tags[1].tags == 0 and payload.tags[1][1];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
191 local invite = st.message({from = _to, to = _invitee, id = stanza.attr.id})
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
192 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'})
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
193 :tag('invite', {from=_from})
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
194 :tag('reason'):text(_reason or ""):up()
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
195 :up();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
196 if self:get_password() then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
197 invite:tag("password"):text(self:get_password()):up();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
198 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
199 invite:up()
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
200 :tag('x', {xmlns="jabber:x:conference", jid=_to}) -- COMPAT: Some older clients expect this
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
201 :text(_reason or "")
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
202 :up()
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
203 :tag('body') -- Add a plain message for clients which don't support invites
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
204 :text(_from..' invited you to the room '.._to..(_reason and (' ('.._reason..')') or ""))
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
205 :up();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
206 if self:is_members_only() and not self:get_affiliation(_invitee) then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
207 log("debug", "%s invited %s into members only room %s, granting membership", _from, _invitee, _to);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
208 self:set_affiliation(_from, _invitee, "member", nil, "Invited by " .. self._jid_nick[_from])
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
209 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
210 self:_route_stanza(invite);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
211 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
212 origin.send(st.error_reply(stanza, "cancel", "jid-malformed"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
213 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
214 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
215 origin.send(st.error_reply(stanza, "cancel", "bad-request"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
216 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
217 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
218 if type == "error" or type == "result" then return; end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
219 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
220 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
221 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
222
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
223