mod_server_contact_info/mod_server_contact_info.lua
author Kim Alvefur <zash@zash.se>
Sat, 01 Oct 2016 17:13:57 +0200
changeset 2321 465b34fdeb60
parent 942 4fdcb5c35021
child 2322 3e5828e3f17f
permissions -rw-r--r--
mod_server_contact_info: Include both global and local admins in fallback mode
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
2321
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");
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
    17
if not contact_config then -- we'll use admins from the config as default
2321
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
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
    20
		module:log("debug", "No contact_info or admins in config");
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");
2321
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
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
    28
if not next(contact_config) then
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
    29
	module:log("debug", "No contacts, skipping");
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
    30
	return -- No use in serving an empty form.
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
    31
end
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
    32
local form_layout = {
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
    33
	{ 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
    34
};
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
    35
local form_values = {};
414
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    36
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
    37
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
    38
	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
    39
		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
    40
		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
    41
	end
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    42
end
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    43
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
    44
module:add_extension(df_new(form_layout):form(form_values, "result"));