annotate mod_server_contact_info/mod_server_contact_info.lua @ 435:b6abe463b4fc

mod_stanza_counter: "*" doesn't handle stanzas.
author Marco Cirillo <maranda@lightwitch.org>
date Tue, 20 Sep 2011 22:42:03 +0000
parents 074237d7820b
children 4fdcb5c35021
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
414
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 -- This plugin implements http://xmpp.org/extensions/xep-0157.html
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local t_insert = table.insert;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local df_new = require "util.dataforms".new;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 local x_contact_info;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 -- Source: http://xmpp.org/registrar/formtypes.html#http:--jabber.org-network-serverinfo
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 local valid_types = {
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 abuse = true;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 admin = true;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 feedback = true;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 sales = true;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 security = true;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 support = true;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 }
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 local function update_form_data()
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 if x_contact_info then
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 module:remove_item("extension", x_contact_info);
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 end
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 x_contact_info = nil;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 local contact_config = module:get_option("contact_info");
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 if not contact_config then -- we'll use admins from the config as default
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 contact_config = { admin = {}; };
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 local admins = module:get_option("admins");
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 if not admins or #admins == 0 then
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 module:log("debug", "No contact_info or admins in config");
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 return -- Nothing to attach, so we'll just skip it.
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 end
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 module:log("debug", "No contact_info in config, using admins as fallback");
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 --TODO fetch global admins too?
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 for i = 1,#admins do
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 t_insert(contact_config.admin, "xmpp:" .. admins[i])
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 module:log("debug", "Added %s to admin-addresses", admins[i]);
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 end
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 end
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 if not next(contact_config) then
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 module:log("debug", "No contacts, skipping");
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 return -- No use in serving an empty form.
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 end
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 local form_layout = {
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 { value = "http://jabber.org/network/serverinfo"; type = "hidden"; name = "FORM_TYPE"; };
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 };
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 local form_values = {};
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 for t,a in pairs(contact_config) do
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 if valid_types[t] and a then
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 t_insert(form_layout, { name = t .. "-addresses", type = "list-multi" });
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 form_values[t .. "-addresses"] = type(a) == "table" and a or {a};
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50 end
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 end
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53 x_contact_info = df_new(form_layout):form(form_values, "result");
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
54 module:add_extension(x_contact_info);
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55 end
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57 module:hook_global("config-reloaded", update_form_data);
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 update_form_data();