Software /
code /
prosody-modules
Annotate
mod_nodeinfo2/mod_nodeinfo2.lua @ 3707:3248295e1b16
mod_nodeinfo2: Retrieve message count from mod_measure_message_e2ee for localPosts and localComments.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 10 Oct 2019 17:59:32 +0200 |
parent | 3706:36b645e94325 |
child | 3708:0a800463bc08 |
rev | line source |
---|---|
3705
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 local json = require "util.json"; |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local array = require "util.array"; |
3707
3248295e1b16
mod_nodeinfo2: Retrieve message count from mod_measure_message_e2ee for localPosts and localComments.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3706
diff
changeset
|
3 local get_stats = require "core.statsmanager".get_stats; |
3705
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 module:depends("http"); |
3707
3248295e1b16
mod_nodeinfo2: Retrieve message count from mod_measure_message_e2ee for localPosts and localComments.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3706
diff
changeset
|
6 module:depends("measure_message_e2ee"); |
3705
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 local total_users = 0; |
3706 | 9 for _ in require "core.usermanager".users(module.host) do -- TODO refresh at some interval? |
3705
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 total_users = total_users + 1; |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 end |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 module:provides("http", { |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 default_path = "/.well-known/x-nodeinfo2"; |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 route = { |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 GET = function (event) |
3707
3248295e1b16
mod_nodeinfo2: Retrieve message count from mod_measure_message_e2ee for localPosts and localComments.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3706
diff
changeset
|
17 local stats, changed_only, extras = get_stats(); |
3248295e1b16
mod_nodeinfo2: Retrieve message count from mod_measure_message_e2ee for localPosts and localComments.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3706
diff
changeset
|
18 local message_count = nil; |
3248295e1b16
mod_nodeinfo2: Retrieve message count from mod_measure_message_e2ee for localPosts and localComments.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3706
diff
changeset
|
19 for stat, value in pairs(stats) do |
3248295e1b16
mod_nodeinfo2: Retrieve message count from mod_measure_message_e2ee for localPosts and localComments.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3706
diff
changeset
|
20 if stat == "/*/mod_measure_message_e2ee/message:rate" then |
3248295e1b16
mod_nodeinfo2: Retrieve message count from mod_measure_message_e2ee for localPosts and localComments.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3706
diff
changeset
|
21 message_count = extras[stat].total; |
3248295e1b16
mod_nodeinfo2: Retrieve message count from mod_measure_message_e2ee for localPosts and localComments.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3706
diff
changeset
|
22 end |
3248295e1b16
mod_nodeinfo2: Retrieve message count from mod_measure_message_e2ee for localPosts and localComments.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3706
diff
changeset
|
23 end |
3248295e1b16
mod_nodeinfo2: Retrieve message count from mod_measure_message_e2ee for localPosts and localComments.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3706
diff
changeset
|
24 |
3705
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 event.response.headers.content_type = "application/json"; |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 return json.encode({ |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 version = "1.0"; |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 server = { |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 baseUrl = module:http_url("","/"); |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 name = module.host; |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 software = "Prosody"; |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 version = prosody.version; |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 }; |
3706 | 34 --[[ TODO re-use data from mod_server_contact_info ? |
3705
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 organization = { |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 name = ""; |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 contact = ""; |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 account = ""; |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 }; |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 --]] |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 protocols = array { |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 "xmpp", |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 }; |
3706 | 44 --[[ TODO would be cool to identify local transports |
3705
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 services = { |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 inbound = array { |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 "irc"; |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 }; |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 outbound = array { |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
50 }; |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 }; |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 --]] |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 openRegistrations = module:get_option_boolean("allow_registration", false); |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 usage = { |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
55 users = { |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
56 total = total_users; |
3706 | 57 -- TODO how would one calculate these? |
3705
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
58 -- activeHalfyear = 1; |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
59 -- activeMonth = 1; |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
60 -- activeWeek = 1; |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
61 }; |
3707
3248295e1b16
mod_nodeinfo2: Retrieve message count from mod_measure_message_e2ee for localPosts and localComments.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3706
diff
changeset
|
62 localPosts = message_count; |
3248295e1b16
mod_nodeinfo2: Retrieve message count from mod_measure_message_e2ee for localPosts and localComments.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3706
diff
changeset
|
63 localComments = message_count; |
3705
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
64 }; |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
65 }); |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
66 end; |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
67 } |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
68 }); |
5d3d8b75dee9
mod_nodeinfo2: Expose service metadata per NodeInfo2
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
69 |