Mercurial > prosody-modules
annotate mod_server_contact_info/mod_server_contact_info.lua @ 5920:254a21a104aa
mod_server_contact_info: Backport from prosody trunk
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 07 Jun 2024 16:14:58 +0100 |
parents | |
children |
rev | line source |
---|---|
5920
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 -- XEP-0157: Contact Addresses for XMPP Services for Prosody |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 -- |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 -- Copyright (C) 2011-2018 Kim Alvefur |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 -- |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 -- This project is MIT/X11 licensed. Please see the |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 -- COPYING file in the source package for more information. |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 -- |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 -- This module is backported from Prosody trunk for the benefit of |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 -- Prosody 0.12 deployments. The following line will ensure that it won't be |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 -- loaded in Prosody versions with built-in support for mod_server_info - |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 -- thus preferring the mod_server_contact_info shipped with Prosody instead. |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 --% conflicts: mod_server_info |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 local array = require "util.array"; |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 local it = require "util.iterators"; |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 local jid = require "util.jid"; |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 local url = require "socket.url"; |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 module:depends("server_info"); |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 -- Source: http://xmpp.org/registrar/formtypes.html#http:--jabber.org-network-serverinfo |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 local address_types = { |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 abuse = "abuse-addresses"; |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 admin = "admin-addresses"; |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 feedback = "feedback-addresses"; |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 sales = "sales-addresses"; |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 security = "security-addresses"; |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 status = "status-addresses"; |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 support = "support-addresses"; |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 }; |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 -- JIDs of configured service admins are used as fallback |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 local admins = module:get_option_inherited_set("admins", {}); |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 local contact_config = module:get_option("contact_info", { |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 admin = array.collect(admins / jid.prep / function(admin) return url.build({scheme = "xmpp"; path = admin}); end); |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 }); |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 local fields = {}; |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 for key, field_var in it.sorted_pairs(address_types) do |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 if contact_config[key] then |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 table.insert(fields, { |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 type = "list-multi"; |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 name = key; |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 var = field_var; |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 value = contact_config[key]; |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 }); |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 end |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 end |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 |
254a21a104aa
mod_server_contact_info: Backport from prosody trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 module:add_item("server-info-fields", fields); |