Mercurial > prosody-hg
comparison plugins/mod_server_contact_info.lua @ 8257:c24837f57259
mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 23 Sep 2017 13:35:33 +0100 |
| parents | |
| children | fd704adc62e1 |
comparison
equal
deleted
inserted
replaced
| 8256:cdffe33efae4 | 8257:c24837f57259 |
|---|---|
| 1 -- XEP-0157: Contact Addresses for XMPP Services for Prosody | |
| 2 -- | |
| 3 -- Copyright (C) 2011-2016 Kim Alvefur | |
| 4 -- | |
| 5 -- This file is MIT/X11 licensed. | |
| 6 -- | |
| 7 | |
| 8 local t_insert = table.insert; | |
| 9 local array = require "util.array"; | |
| 10 local df_new = require "util.dataforms".new; | |
| 11 | |
| 12 -- Source: http://xmpp.org/registrar/formtypes.html#http:--jabber.org-network-serverinfo | |
| 13 local valid_types = { | |
| 14 abuse = true; | |
| 15 admin = true; | |
| 16 feedback = true; | |
| 17 sales = true; | |
| 18 security = true; | |
| 19 support = true; | |
| 20 } | |
| 21 | |
| 22 local contact_config = module:get_option("contact_info"); | |
| 23 if not contact_config or not next(contact_config) then -- we'll use admins from the config as default | |
| 24 local admins = module:get_option_inherited_set("admins", {}); | |
| 25 if admins:empty() then | |
| 26 module:log("error", "No contact_info or admins set in config"); | |
| 27 return -- Nothing to attach, so we'll just skip it. | |
| 28 end | |
| 29 module:log("info", "No contact_info in config, using admins as fallback"); | |
| 30 contact_config = { | |
| 31 admin = array.collect( admins / function(admin) return "xmpp:" .. admin; end); | |
| 32 }; | |
| 33 end | |
| 34 | |
| 35 local form_layout = { | |
| 36 { value = "http://jabber.org/network/serverinfo"; type = "hidden"; name = "FORM_TYPE"; }; | |
| 37 }; | |
| 38 | |
| 39 local form_values = {}; | |
| 40 | |
| 41 for t in pairs(valid_types) do | |
| 42 local addresses = contact_config[t]; | |
| 43 if addresses then | |
| 44 t_insert(form_layout, { name = t .. "-addresses", type = "list-multi" }); | |
| 45 form_values[t .. "-addresses"] = addresses; | |
| 46 end | |
| 47 end | |
| 48 | |
| 49 module:add_extension(df_new(form_layout):form(form_values, "result")); |
