Mercurial > prosody-modules
annotate mod_support_contact/mod_support_contact.lua @ 5406:b86d80e21c60
mod_http_oauth2: Validate consistency of response and grant types
Ensure that these correlated fields make sense per RFC 7591 ยง 2.1, even
though we currently only check the response type during authorization.
This could probably all be deleted if (when!) we remove the implicit
grant, since then these things don't make any sense anymore.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 02 May 2023 16:34:31 +0200 |
parents | 7dbde05b48a9 |
children |
rev | line source |
---|---|
1
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 -- mod_support_contact.lua |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 -- |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 -- Config options: |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 -- support_contact = "support@hostname"; -- a JID |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 -- support_contact_nick = "Support!"; -- roster nick |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 -- support_contact_group = "Users being supported!"; -- the roster group in the support contact's roster |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 local host = module:get_host(); |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 |
986
8b1250df82e8
mod_support_contact: Use module:get_option_string()
Kim Alvefur <zash@zash.se>
parents:
777
diff
changeset
|
10 local support_contact = module:get_option_string("support_contact", "support@"..host); |
8b1250df82e8
mod_support_contact: Use module:get_option_string()
Kim Alvefur <zash@zash.se>
parents:
777
diff
changeset
|
11 local support_contact_nick = module:get_option_string("support_contact_nick", "Support"); |
8b1250df82e8
mod_support_contact: Use module:get_option_string()
Kim Alvefur <zash@zash.se>
parents:
777
diff
changeset
|
12 local support_contact_group = module:get_option_string("support_contact_group", "Users"); |
1
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 if not(support_contact and support_contact_nick) then return; end |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 local rostermanager = require "core.rostermanager"; |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 local jid_split = require "util.jid".split; |
100
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
18 local st = require "util.stanza"; |
1
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 module:hook("user-registered", function(event) |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 module:log("debug", "Adding support contact"); |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 local groups = support_contact_group and {[support_contact_group] = true;} or {}; |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 local node, host = event.username, event.host; |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 local jid = node and (node..'@'..host) or host; |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 local roster; |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 |
100
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
29 roster = rostermanager.load_roster(node, host); |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
30 if hosts[host] then |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
31 roster[support_contact] = {subscription = "both", name = support_contact_nick, groups = {}}; |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
32 else |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
33 roster[support_contact] = {subscription = "from", ask = "subscribe", name = support_contact_nick, groups = {}}; |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
34 end |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
35 rostermanager.save_roster(node, host, roster); |
1
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 node, host = jid_split(support_contact); |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
986
diff
changeset
|
38 |
100
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
39 if hosts[host] then |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
40 roster = rostermanager.load_roster(node, host); |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
41 roster[jid] = {subscription = "both", groups = groups}; |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
42 rostermanager.save_roster(node, host, roster); |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
43 rostermanager.roster_push(node, host, jid); |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
44 else |
777
e5413b66aeec
mod_support_contact: Use module:send()
Matthew Wild <mwild1@gmail.com>
parents:
100
diff
changeset
|
45 module:send(st.presence({from=jid, to=support_contact, type="subscribe"})); |
100
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
46 end |
1
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
47 end); |