Annotate

mod_server_contact_info/mod_server_contact_info.lua @ 2898:9fd61234b6f0

mod_firewall/definitions: Comments on LIST backends
author Kim Alvefur <zash@zash.se>
date Tue, 06 Mar 2018 18:24:34 +0100
parent 2772:2c59f2f0c37d
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
2697
d18a91c030df mod_server_contact_info: Bump log message to info level
Kim Alvefur <zash@zash.se>
parents: 2320
diff changeset
29 module:log("info", "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" });
2772
2c59f2f0c37d mod_server_contact_info: Correctly pass the list of addresses to util.dataforms
Matthew Wild <mwild1@gmail.com>
parents: 2697
diff changeset
45 form_values[t .. "-addresses"] = addresses;
414
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 end
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
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
49 module:add_extension(df_new(form_layout):form(form_values, "result"));