comparison mod_readonly/mod_readonly.lua @ 750:8133dd5f266a

mod_readonly: Allow preventing direct modification of certain user data via XMPP
author Matthew Wild <mwild1@gmail.com>
date Fri, 27 Jul 2012 02:38:43 +0100
parents
children 7776c9dc5f37
comparison
equal deleted inserted replaced
749:1a7cdc874b8c 750:8133dd5f266a
1 local st = require "util.stanza";
2
3 local stores = module:get_option("readonly_stores", {
4 vcard = { "vcard-temp", "vCard" };
5 });
6
7 local namespaces = {};
8 for name, namespace in pairs(stores) do
9 namespaces[table.concat(namespace, ":")] = name;
10 end
11
12 function prevent_write(event)
13 local stanza = event.stanza;
14 if stanza.attr.type ~= "set" then return; end
15 local xmlns_and_tag = stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name;
16 local store_name = namespaces[xmlns_and_tag];
17 if store_name then
18 module:log("warn", "Preventing modification of %s store by %s", store_name, stanza.attr.from);
19 event.origin.send(st.error_reply(stanza, "cancel", "not-allowed", store_name.." data is read-only"));
20 return true; -- Block stanza
21 end
22 end
23
24 for namespace in pairs(namespaces) do
25 module:hook("iq/bare/"..namespace, prevent_write, 200);
26 end