annotate mod_server_contact_info/mod_server_contact_info.lua @ 2638:33f7ca7bdc86

mod_list_active: Add README
author Kim Alvefur <zash@zash.se>
date Wed, 22 Mar 2017 14:55:41 +0100
parents d6a3362ca256
children d18a91c030df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2320
d6a3362ca256 mod_server_contact_info: Add copyright header
Kim Alvefur <zash@zash.se>
parents: 2319
diff changeset
1 -- XEP-0157: Contact Addresses for XMPP Services for Prosody
d6a3362ca256 mod_server_contact_info: Add copyright header
Kim Alvefur <zash@zash.se>
parents: 2319
diff changeset
2 --
d6a3362ca256 mod_server_contact_info: Add copyright header
Kim Alvefur <zash@zash.se>
parents: 2319
diff changeset
3 -- Copyright (C) 2011-2016 Kim Alvefur
d6a3362ca256 mod_server_contact_info: Add copyright header
Kim Alvefur <zash@zash.se>
parents: 2319
diff changeset
4 --
d6a3362ca256 mod_server_contact_info: Add copyright header
Kim Alvefur <zash@zash.se>
parents: 2319
diff changeset
5 -- This file is MIT/X11 licensed.
d6a3362ca256 mod_server_contact_info: Add copyright header
Kim Alvefur <zash@zash.se>
parents: 2319
diff changeset
6 --
d6a3362ca256 mod_server_contact_info: Add copyright header
Kim Alvefur <zash@zash.se>
parents: 2319
diff changeset
7
414
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 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
9 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
10 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
11
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 -- 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
13 local valid_types = {
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 abuse = true;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 admin = true;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 feedback = true;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 sales = true;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 security = true;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 support = true;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 }
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
22 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
23 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
24 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
25 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
26 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
27 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
28 end
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
29 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
30 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
31 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
32 };
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
33 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
34
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
35 local form_layout = {
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
36 { 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
37 };
2320
d6a3362ca256 mod_server_contact_info: Add copyright header
Kim Alvefur <zash@zash.se>
parents: 2319
diff changeset
38
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
39 local form_values = {};
414
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40
2319
86128b948fed mod_server_contact_info: Use more explicit value data format for dataform
Kim Alvefur <zash@zash.se>
parents: 2318
diff changeset
41 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
42 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
43 if addresses then
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
44 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
45 local values = {};
86128b948fed mod_server_contact_info: Use more explicit value data format for dataform
Kim Alvefur <zash@zash.se>
parents: 2318
diff changeset
46 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
47 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
48 else
86128b948fed mod_server_contact_info: Use more explicit value data format for dataform
Kim Alvefur <zash@zash.se>
parents: 2318
diff changeset
49 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
50 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
51 end
86128b948fed mod_server_contact_info: Use more explicit value data format for dataform
Kim Alvefur <zash@zash.se>
parents: 2318
diff changeset
52 end
86128b948fed mod_server_contact_info: Use more explicit value data format for dataform
Kim Alvefur <zash@zash.se>
parents: 2318
diff changeset
53 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
54 end
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
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
57 module:add_extension(df_new(form_layout):form(form_values, "result"));