annotate mod_server_contact_info/mod_server_contact_info.lua @ 2319:86128b948fed

mod_server_contact_info: Use more explicit value data format for dataform
author Kim Alvefur <zash@zash.se>
date Sat, 01 Oct 2016 17:16:23 +0200
parents 3e5828e3f17f
children d6a3362ca256
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;
2317
465b34fdeb60 mod_server_contact_info: Include both global and local admins in fallback mode
Kim Alvefur <zash@zash.se>
parents: 942
diff changeset
3 local array = require "util.array";
414
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 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
5
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
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
16 local contact_config = module:get_option("contact_info");
2318
3e5828e3f17f mod_server_contact_info: Log error when no addresses or admins are set
Kim Alvefur <zash@zash.se>
parents: 2317
diff changeset
17 if not contact_config or not next(contact_config) then -- we'll use admins from the config as default
2317
465b34fdeb60 mod_server_contact_info: Include both global and local admins in fallback mode
Kim Alvefur <zash@zash.se>
parents: 942
diff changeset
18 local admins = module:get_option_inherited_set("admins", {});
465b34fdeb60 mod_server_contact_info: Include both global and local admins in fallback mode
Kim Alvefur <zash@zash.se>
parents: 942
diff changeset
19 if admins:empty() then
2318
3e5828e3f17f mod_server_contact_info: Log error when no addresses or admins are set
Kim Alvefur <zash@zash.se>
parents: 2317
diff changeset
20 module:log("error", "No contact_info or admins set in config");
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
21 return -- Nothing to attach, so we'll just skip it.
414
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 end
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
23 module:log("debug", "No contact_info in config, using admins as fallback");
2317
465b34fdeb60 mod_server_contact_info: Include both global and local admins in fallback mode
Kim Alvefur <zash@zash.se>
parents: 942
diff changeset
24 contact_config = {
465b34fdeb60 mod_server_contact_info: Include both global and local admins in fallback mode
Kim Alvefur <zash@zash.se>
parents: 942
diff changeset
25 admin = array.collect( admins / function(admin) return "xmpp:" .. admin; end);
465b34fdeb60 mod_server_contact_info: Include both global and local admins in fallback mode
Kim Alvefur <zash@zash.se>
parents: 942
diff changeset
26 };
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
27 end
2318
3e5828e3f17f mod_server_contact_info: Log error when no addresses or admins are set
Kim Alvefur <zash@zash.se>
parents: 2317
diff changeset
28
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
29 local form_layout = {
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
30 { value = "http://jabber.org/network/serverinfo"; type = "hidden"; name = "FORM_TYPE"; };
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
31 };
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
32 local form_values = {};
414
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33
2319
86128b948fed mod_server_contact_info: Use more explicit value data format for dataform
Kim Alvefur <zash@zash.se>
parents: 2318
diff changeset
34 for t in pairs(valid_types) do
86128b948fed mod_server_contact_info: Use more explicit value data format for dataform
Kim Alvefur <zash@zash.se>
parents: 2318
diff changeset
35 local addresses = contact_config[t];
86128b948fed mod_server_contact_info: Use more explicit value data format for dataform
Kim Alvefur <zash@zash.se>
parents: 2318
diff changeset
36 if addresses then
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
37 t_insert(form_layout, { name = t .. "-addresses", type = "list-multi" });
2319
86128b948fed mod_server_contact_info: Use more explicit value data format for dataform
Kim Alvefur <zash@zash.se>
parents: 2318
diff changeset
38 local values = {};
86128b948fed mod_server_contact_info: Use more explicit value data format for dataform
Kim Alvefur <zash@zash.se>
parents: 2318
diff changeset
39 if type(addresses) ~= "table" then
86128b948fed mod_server_contact_info: Use more explicit value data format for dataform
Kim Alvefur <zash@zash.se>
parents: 2318
diff changeset
40 values[1] = { value = addresses };
86128b948fed mod_server_contact_info: Use more explicit value data format for dataform
Kim Alvefur <zash@zash.se>
parents: 2318
diff changeset
41 else
86128b948fed mod_server_contact_info: Use more explicit value data format for dataform
Kim Alvefur <zash@zash.se>
parents: 2318
diff changeset
42 for i, address in ipairs(addresses) do
86128b948fed mod_server_contact_info: Use more explicit value data format for dataform
Kim Alvefur <zash@zash.se>
parents: 2318
diff changeset
43 values[i] = { value = address };
86128b948fed mod_server_contact_info: Use more explicit value data format for dataform
Kim Alvefur <zash@zash.se>
parents: 2318
diff changeset
44 end
86128b948fed mod_server_contact_info: Use more explicit value data format for dataform
Kim Alvefur <zash@zash.se>
parents: 2318
diff changeset
45 end
86128b948fed mod_server_contact_info: Use more explicit value data format for dataform
Kim Alvefur <zash@zash.se>
parents: 2318
diff changeset
46 form_values[t .. "-addresses"] = values;
414
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 end
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 end
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
50 module:add_extension(df_new(form_layout):form(form_values, "result"));