annotate mod_server_contact_info/mod_server_contact_info.lua @ 2318:3e5828e3f17f

mod_server_contact_info: Log error when no addresses or admins are set
author Kim Alvefur <zash@zash.se>
date Sat, 01 Oct 2016 17:15:03 +0200
parents 465b34fdeb60
children 86128b948fed
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
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
34 for t,a in pairs(contact_config) do
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
35 if valid_types[t] and a then
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
36 t_insert(form_layout, { name = t .. "-addresses", type = "list-multi" });
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
37 form_values[t .. "-addresses"] = type(a) == "table" and a or {a};
414
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 end
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 end
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
41 module:add_extension(df_new(form_layout):form(form_values, "result"));