annotate mod_http_admin_api/mod_http_admin_api.lua @ 4710:099dcdb732b1

mod_auth_cyrus: Import from Prosody rev 8f1e7fd55e7b
author Kim Alvefur <zash@zash.se>
date Sun, 17 Oct 2021 17:08:07 +0200
parents cade5dac1003
children bd83c9ada037
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4345
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
1 local usermanager = require "core.usermanager";
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
2
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local json = require "util.json";
4516
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
4 local st = require "util.stanza";
4517
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
5 local array = require "util.array";
4576
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
6 local statsmanager = require "core.statsmanager";
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 module:depends("http");
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9
4576
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
10 local announce = module:depends("announce");
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 local invites = module:depends("invites");
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local tokens = module:depends("tokenauth");
4345
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
13 local mod_pep = module:depends("pep");
4382
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
14 local mod_groups = module:depends("groups_internal");
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15
4363
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
16 local push_errors = module:shared("cloud_notify/push_errors");
4352
f6da234b21b8 mod_http_admin_api: Add groups property to users
Matthew Wild <mwild1@gmail.com>
parents: 4351
diff changeset
17
4371
3d01bc4547b2 mod_http_admin_api: Add /server/info endpoint for site_name and version
Matthew Wild <mwild1@gmail.com>
parents: 4369
diff changeset
18 local site_name = module:get_option_string("site_name", module.host);
3d01bc4547b2 mod_http_admin_api: Add /server/info endpoint for site_name and version
Matthew Wild <mwild1@gmail.com>
parents: 4369
diff changeset
19
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 local json_content_type = "application/json";
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 local www_authenticate_header = ("Bearer realm=%q"):format(module.host.."/"..module.name);
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23
4516
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
24 local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
25 local xmlns_nick = "http://jabber.org/protocol/nick";
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
26
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 local function check_credentials(request)
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 local auth_type, auth_data = string.match(request.headers.authorization or "", "^(%S+)%s(.+)$");
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 if not (auth_type and auth_data) then
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 return false;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 if auth_type == "Bearer" then
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 local token_info = tokens.get_token_info(auth_data);
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 if not token_info or not token_info.session then
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 return false;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 return token_info.session;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 return nil;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 function check_auth(routes)
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 local function check_request_auth(event)
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 local session = check_credentials(event.request);
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 if not session then
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 event.response.headers.authorization = www_authenticate_header;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 return false, 401;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 elseif session.auth_scope ~= "prosody:scope:admin" then
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 return false, 403;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 event.session = session;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 return true;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 for route, handler in pairs(routes) do
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 routes[route] = function (event, ...)
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 local permit, code = check_request_auth(event);
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 if not permit then
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 return code;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 return handler(event, ...);
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 end;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 return routes;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 local function token_info_to_invite_info(token_info)
4349
5ca36c36ab05 mod_http_admin_api: Expose new invite properties: groups, source and reusable
Matthew Wild <mwild1@gmail.com>
parents: 4345
diff changeset
69 local additional_data = token_info.additional_data;
5ca36c36ab05 mod_http_admin_api: Expose new invite properties: groups, source and reusable
Matthew Wild <mwild1@gmail.com>
parents: 4345
diff changeset
70 local groups = additional_data and additional_data.groups or nil;
5ca36c36ab05 mod_http_admin_api: Expose new invite properties: groups, source and reusable
Matthew Wild <mwild1@gmail.com>
parents: 4345
diff changeset
71 local source = additional_data and additional_data.source or nil;
4378
d4e0e4d22fc7 mod_http_admin_api: Add 'reset' property to returned invite objects
Matthew Wild <mwild1@gmail.com>
parents: 4375
diff changeset
72 local reset = not not (additional_data and additional_data.allow_reset or nil);
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 return {
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74 id = token_info.token;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 type = token_info.type;
4358
d3e0fe470877 mod_http_admin_api: Ensure 'reusable' flag is always present on an invite
Matthew Wild <mwild1@gmail.com>
parents: 4357
diff changeset
76 reusable = not not token_info.reusable;
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
77 inviter = token_info.inviter;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
78 jid = token_info.jid;
4354
d61d7d30f38d mod_http_admin_api: Add XMPP URI into invite objects
Matthew Wild <mwild1@gmail.com>
parents: 4353
diff changeset
79 uri = token_info.uri;
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
80 landing_page = token_info.landing_page;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
81 created_at = token_info.created_at;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
82 expires = token_info.expires;
4349
5ca36c36ab05 mod_http_admin_api: Expose new invite properties: groups, source and reusable
Matthew Wild <mwild1@gmail.com>
parents: 4345
diff changeset
83 groups = groups;
5ca36c36ab05 mod_http_admin_api: Expose new invite properties: groups, source and reusable
Matthew Wild <mwild1@gmail.com>
parents: 4345
diff changeset
84 source = source;
4378
d4e0e4d22fc7 mod_http_admin_api: Add 'reset' property to returned invite objects
Matthew Wild <mwild1@gmail.com>
parents: 4375
diff changeset
85 reset = reset;
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
86 };
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
87 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
88
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
89 function list_invites(event)
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
90 local invites_list = {};
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
91 for token, invite in invites.pending_account_invites() do --luacheck: ignore 213/token
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
92 table.insert(invites_list, token_info_to_invite_info(invite));
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94 table.sort(invites_list, function (a, b)
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 return a.created_at < b.created_at;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 end);
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
97
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98 event.response.headers["Content-Type"] = json_content_type;
4350
270025e76bf8 mod_http_admin_api: Use json.encode_array() when returning an array
Matthew Wild <mwild1@gmail.com>
parents: 4349
diff changeset
99 return json.encode_array(invites_list);
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
101
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
102 function get_invite_by_id(event, invite_id)
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
103 local invite = invites.get_account_invite_info(invite_id);
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
104 if not invite then
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
105 return 404;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
106 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
107
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
108 event.response.headers["Content-Type"] = json_content_type;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109 return json.encode(token_info_to_invite_info(invite));
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
110 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111
4374
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
112 function create_invite_type(event, invite_type)
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
113 local options;
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
114
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
115 local request = event.request;
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
116 if request.body and #request.body > 0 then
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
117 if request.headers.content_type ~= json_content_type then
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
118 module:log("warn", "Invalid content type");
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
119 return 400;
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
120 end
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
121 options = json.decode(event.request.body);
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
122 if not options then
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
123 module:log("warn", "Invalid JSON");
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
124 return 400;
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
125 end
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
126 else
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
127 options = {};
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
128 end
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
129
4396
de55e1475808 mod_http_admin_api: re-add information about invite creator
Jonas Schäfer <jonas@wielicki.name>
parents: 4393
diff changeset
130 local source = event.session.username .. "@" .. module.host .. "/admin_api";
de55e1475808 mod_http_admin_api: re-add information about invite creator
Jonas Schäfer <jonas@wielicki.name>
parents: 4393
diff changeset
131
4374
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
132 local invite;
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
133 if invite_type == "reset" then
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
134 if not options.username then
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
135 return 400;
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
136 end
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
137 invite = invites.create_account_reset(options.username, options.ttl);
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
138 elseif invite_type == "group" then
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
139 if not options.groups then
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
140 return 400;
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
141 end
4396
de55e1475808 mod_http_admin_api: re-add information about invite creator
Jonas Schäfer <jonas@wielicki.name>
parents: 4393
diff changeset
142 invite = invites.create_group(options.groups, {
de55e1475808 mod_http_admin_api: re-add information about invite creator
Jonas Schäfer <jonas@wielicki.name>
parents: 4393
diff changeset
143 source = source;
de55e1475808 mod_http_admin_api: re-add information about invite creator
Jonas Schäfer <jonas@wielicki.name>
parents: 4393
diff changeset
144 }, options.ttl);
4374
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
145 elseif invite_type == "account" then
4375
03cf0d41b272 mod_http_admin_api: Allow specifying groups in account invite
Matthew Wild <mwild1@gmail.com>
parents: 4374
diff changeset
146 invite = invites.create_account(options.username, {
4396
de55e1475808 mod_http_admin_api: re-add information about invite creator
Jonas Schäfer <jonas@wielicki.name>
parents: 4393
diff changeset
147 source = source;
4375
03cf0d41b272 mod_http_admin_api: Allow specifying groups in account invite
Matthew Wild <mwild1@gmail.com>
parents: 4374
diff changeset
148 groups = options.groups;
03cf0d41b272 mod_http_admin_api: Allow specifying groups in account invite
Matthew Wild <mwild1@gmail.com>
parents: 4374
diff changeset
149 }, options.ttl);
4374
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
150 else
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
151 return 400;
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
152 end
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
153 if not invite then
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
154 return 500;
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
155 end
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
156 event.response.headers["Content-Type"] = json_content_type;
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
157 return json.encode(token_info_to_invite_info(invite));
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
158 end
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
159
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
160 function delete_invite(event, invite_id) --luacheck: ignore 212/event
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
161 if not invites.delete_account_invite(invite_id) then
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
162 return 404;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
163 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
164 return 200;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
165 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
166
4345
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
167 local function get_user_info(username)
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
168 if not usermanager.user_exists(username, module.host) then
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
169 return nil;
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
170 end
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
171 local display_name;
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
172 do
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
173 local pep_service = mod_pep.get_pep_service(username);
4516
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
174 local ok, _, nick_item = pep_service:get_last_item(xmlns_nick, true);
4345
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
175 if ok and nick_item then
4516
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
176 display_name = nick_item:get_child_text("nick", xmlns_nick);
4345
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
177 end
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
178 end
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
179
4517
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
180 local roles = nil;
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
181 if usermanager.get_roles then
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
182 local roles_map = usermanager.get_roles(username.."@"..module.host, module.host)
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
183 roles = array()
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
184 if roles_map then
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
185 for role in pairs(roles_map) do
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
186 roles:push(role)
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
187 end
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
188 end
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
189 end
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
190
4362
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
191 return {
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
192 username = username;
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
193 display_name = display_name;
4517
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
194 roles = roles;
4362
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
195 };
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
196 end
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
197
4363
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
198 local function get_session_debug_info(session)
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
199 local info = {
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
200 full_jid = session.full_jid;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
201 ip = session.ip;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
202 since = math.floor(session.conntime);
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
203 status = {
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
204 connected = not not session.conn;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
205 hibernating = not not session.hibernating;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
206 };
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
207 features = {
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
208 carbons = not not session.want_carbons;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
209 encrypted = not not session.secure;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
210 acks = not not session.smacks;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
211 resumption = not not session.resumption_token;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
212 mobile_optimization = not not session.csi_counter;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
213 push_notifications = not not session.push_identifier;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
214 history = not not session.mam_requested;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
215 };
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
216 queues = {};
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
217 };
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
218 -- CSI
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
219 if session.state then
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
220 info.status.active = session.state == "active";
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
221 info.queues.held_stanzas = session.csi_counter or 0;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
222 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
223 -- Smacks queue
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
224 if session.last_requested_h and session.last_acknowledged_stanza then
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
225 info.queues.awaiting_acks = session.last_requested_h - session.last_acknowledged_stanza;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
226 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
227 if session.push_identifier then
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
228 info.push_info = {
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
229 id = session.push_identifier;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
230 wakeup_push_sent = session.first_hibernated_push;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
231 };
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
232 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
233 return info;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
234 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
235
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
236 local function get_user_omemo_info(username)
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
237 local everything_valid = true;
4366
83370df0ce4a mod_http_admin_api: do not report OMEMO as ok if no devices exist
Jonas Schäfer <jonas@wielicki.name>
parents: 4365
diff changeset
238 local any_device = false;
4363
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
239 local omemo_status = {};
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
240 local omemo_devices;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
241 local pep_service = mod_pep.get_pep_service(username);
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
242 if pep_service and pep_service.nodes then
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
243 local ok, _, device_list = pep_service:get_last_item("eu.siacs.conversations.axolotl.devicelist", true);
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
244 if ok and device_list then
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
245 device_list = device_list:get_child("list", "eu.siacs.conversations.axolotl");
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
246 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
247 if device_list then
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
248 omemo_devices = {};
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
249 for device_entry in device_list:childtags("device") do
4366
83370df0ce4a mod_http_admin_api: do not report OMEMO as ok if no devices exist
Jonas Schäfer <jonas@wielicki.name>
parents: 4365
diff changeset
250 any_device = true;
4363
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
251 local device_info = {};
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
252 local device_id = tonumber(device_entry.attr.id or "");
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
253 if device_id then
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
254 device_info.id = device_id;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
255 local bundle_id = ("eu.siacs.conversations.axolotl.bundles:%d"):format(device_id);
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
256 local have_bundle, _, bundle = pep_service:get_last_item(bundle_id, true);
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
257 if have_bundle and bundle and bundle:get_child("bundle", "eu.siacs.conversations.axolotl") then
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
258 device_info.have_bundle = true;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
259 local config_ok, bundle_config = pep_service:get_node_config(bundle_id, true);
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
260 if config_ok and bundle_config then
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
261 device_info.bundle_config = bundle_config;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
262 if bundle_config.max_items == 1
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
263 and bundle_config.access_model == "open"
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
264 and bundle_config.persist_items == true
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
265 and bundle_config.publish_model == "publishers" then
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
266 device_info.valid = true;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
267 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
268 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
269 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
270 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
271 if device_info.valid == nil then
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
272 device_info.valid = false;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
273 everything_valid = false;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
274 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
275 table.insert(omemo_devices, device_info);
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
276 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
277
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
278 local config_ok, list_config = pep_service:get_node_config("eu.siacs.conversations.axolotl.devicelist", true);
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
279 if config_ok and list_config then
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
280 omemo_status.config = list_config;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
281 if list_config.max_items == 1
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
282 and list_config.access_model == "open"
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
283 and list_config.persist_items == true
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
284 and list_config.publish_model == "publishers" then
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
285 omemo_status.config_valid = true;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
286 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
287 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
288 if omemo_status.config_valid == nil then
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
289 omemo_status.config_valid = false;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
290 everything_valid = false;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
291 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
292 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
293 end
4366
83370df0ce4a mod_http_admin_api: do not report OMEMO as ok if no devices exist
Jonas Schäfer <jonas@wielicki.name>
parents: 4365
diff changeset
294 omemo_status.valid = everything_valid and any_device;
4363
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
295 return {
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
296 status = omemo_status;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
297 devices = omemo_devices;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
298 };
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
299 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
300
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
301 local function get_user_debug_info(username)
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
302 local debug_info = {
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
303 time = os.time();
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
304 };
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
305 -- Online sessions
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
306 do
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
307 local user_sessions = hosts[module.host].sessions[username];
4365
f975a4d31f35 mod_http_admin_api: make the api a bit less untested
Jonas Schäfer <jonas@wielicki.name>
parents: 4364
diff changeset
308 if user_sessions then
f975a4d31f35 mod_http_admin_api: make the api a bit less untested
Jonas Schäfer <jonas@wielicki.name>
parents: 4364
diff changeset
309 user_sessions = user_sessions.sessions
f975a4d31f35 mod_http_admin_api: make the api a bit less untested
Jonas Schäfer <jonas@wielicki.name>
parents: 4364
diff changeset
310 end
4363
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
311 local sessions = {};
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
312 if user_sessions then
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
313 for _, session in pairs(user_sessions) do
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
314 table.insert(sessions, get_session_debug_info(session));
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
315 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
316 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
317 debug_info.sessions = sessions;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
318 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
319 -- Push registrations
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
320 do
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
321 local store = module:open_store("cloud_notify");
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
322 local services = store:get(username);
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
323 local push_registrations = {};
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
324 if services then
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
325 for identifier, push_info in pairs(services) do
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
326 push_registrations[identifier] = {
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
327 since = push_info.timestamp;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
328 service = push_info.jid;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
329 node = push_info.node;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
330 error_count = push_errors[identifier] or 0;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
331 };
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
332 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
333 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
334 debug_info.push_registrations = push_registrations;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
335 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
336 -- OMEMO
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
337 debug_info.omemo = get_user_omemo_info(username);
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
338
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
339 return debug_info;
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
340 end
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
341
4345
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
342 function list_users(event)
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
343 local user_list = {};
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
344 for username in usermanager.users(module.host) do
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
345 table.insert(user_list, get_user_info(username));
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
346 end
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
347
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
348 event.response.headers["Content-Type"] = json_content_type;
4350
270025e76bf8 mod_http_admin_api: Use json.encode_array() when returning an array
Matthew Wild <mwild1@gmail.com>
parents: 4349
diff changeset
349 return json.encode_array(user_list);
4345
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
350 end
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
351
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
352 function get_user_by_name(event, username)
4362
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
353 local property
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
354 do
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
355 local name, sub_path = username:match("^([^/]+)/(%w+)$");
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
356 if name then
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
357 username = name;
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
358 property = sub_path;
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
359 end
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
360 end
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
361
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
362 if property == "groups" then
4364
49cf9d188b26 mod_http_admin_api: set content-type for debug API
Jonas Schäfer <jonas@wielicki.name>
parents: 4363
diff changeset
363 event.response.headers["Content-Type"] = json_content_type;
4382
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
364 return json.encode(mod_groups.get_user_groups(username));
4363
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
365 elseif property == "debug" then
4364
49cf9d188b26 mod_http_admin_api: set content-type for debug API
Jonas Schäfer <jonas@wielicki.name>
parents: 4363
diff changeset
366 event.response.headers["Content-Type"] = json_content_type;
4363
636d56bbad97 mod_http_admin_api: 100% untested user debug info endpoint
Matthew Wild <mwild1@gmail.com>
parents: 4362
diff changeset
367 return json.encode(get_user_debug_info(username));
4362
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
368 end
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
369
4345
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
370 local user_info = get_user_info(username);
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
371 if not user_info then
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
372 return 404;
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
373 end
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
374
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
375 event.response.headers["Content-Type"] = json_content_type;
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
376 return json.encode(user_info);
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
377 end
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
378
4516
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
379 function update_user(event, username)
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
380 local current_user = get_user_info(username);
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
381
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
382 local request = event.request;
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
383 if request.headers.content_type ~= json_content_type
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
384 or (not request.body or #request.body == 0) then
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
385 return 400;
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
386 end
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
387 local new_user = json.decode(event.request.body);
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
388 if not new_user then
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
389 return 400;
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
390 end
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
391
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
392 if new_user.username and new_user.username ~= username then
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
393 return 400;
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
394 end
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
395
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
396 local final_user = {};
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
397
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
398 if new_user.display_name then
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
399 local pep_service = mod_pep.get_pep_service(username);
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
400 -- TODO: publish
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
401 local nick_item = st.stanza("item", { xmlns = xmlns_pubsub, id = "current" })
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
402 :text_tag("nick", new_user.display_name, { xmlns = xmlns_nick });
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
403 if pep_service:publish(xmlns_nick, true, "current", nick_item, {
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
404 access_model = "open";
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
405 _defaults_only = true;
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
406 }) then
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
407 final_user.display_name = new_user.display_name;
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
408 end
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
409 end
4517
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
410
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
411 if new_user.roles then
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
412 if not usermanager.set_roles then
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
413 return 500, "feature-not-implemented"
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
414 end
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
415
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
416 local backend_roles = {};
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
417 for _, role in ipairs(new_user.roles) do
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
418 backend_roles[role] = true;
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
419 end
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
420 local jid = username.."@"..module.host;
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
421 if not usermanager.set_roles(jid, module.host, backend_roles) then
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
422 module:log("error", "failed to set roles %q for %s", backend_roles, jid)
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
423 return 500
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
424 end
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
425 end
d6a3201a65c0 mod_http_admin_api: support for updating user roles via the API
Jonas Schäfer <jonas@wielicki.name>
parents: 4516
diff changeset
426
4516
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
427 return 200;
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
428 end
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
429
4345
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
430 function delete_user(event, username) --luacheck: ignore 212/event
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
431 if not usermanager.delete_user(username, module.host) then
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
432 return 404;
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
433 end
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
434 return 200;
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
435 end
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
436
4353
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
437 function list_groups(event)
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
438 local group_list = {};
4382
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
439 for group_id in mod_groups.groups() do
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
440 local group_info = mod_groups.get_info(group_id);
4353
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
441 table.insert(group_list, {
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
442 id = group_id;
4368
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
443 name = group_info.name;
4390
17d44ba8fde2 mod_http_admin_api: support for creating groups with MUCs
Jonas Schäfer <jonas@wielicki.name>
parents: 4382
diff changeset
444 muc_jid = group_info.muc_jid;
4382
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
445 members = mod_groups.get_members(group_id);
4353
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
446 });
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
447 end
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
448
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
449 event.response.headers["Content-Type"] = json_content_type;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
450 return json.encode_array(group_list);
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
451 end
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
452
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
453 function get_group_by_id(event, group_id)
4382
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
454 local group = mod_groups.get_info(group_id);
4353
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
455 if not group then
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
456 return 404;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
457 end
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
458
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
459 event.response.headers["Content-Type"] = json_content_type;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
460
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
461 return json.encode({
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
462 id = group_id;
4368
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
463 name = group.name;
4390
17d44ba8fde2 mod_http_admin_api: support for creating groups with MUCs
Jonas Schäfer <jonas@wielicki.name>
parents: 4382
diff changeset
464 muc_jid = group.muc_jid;
4382
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
465 members = mod_groups.get_members(group_id);
4353
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
466 });
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
467 end
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
468
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
469 function create_group(event)
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
470 local request = event.request;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
471 if request.headers.content_type ~= json_content_type
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
472 or (not request.body or #request.body == 0) then
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
473 return 400;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
474 end
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
475 local group = json.decode(event.request.body);
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
476 if not group then
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
477 return 400;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
478 end
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
479
4368
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
480 if not group.name then
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
481 module:log("warn", "Group missing name property");
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
482 return 400;
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
483 end
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
484
4390
17d44ba8fde2 mod_http_admin_api: support for creating groups with MUCs
Jonas Schäfer <jonas@wielicki.name>
parents: 4382
diff changeset
485 local create_muc = group.create_muc and true or false;
17d44ba8fde2 mod_http_admin_api: support for creating groups with MUCs
Jonas Schäfer <jonas@wielicki.name>
parents: 4382
diff changeset
486
17d44ba8fde2 mod_http_admin_api: support for creating groups with MUCs
Jonas Schäfer <jonas@wielicki.name>
parents: 4382
diff changeset
487 local group_id = mod_groups.create(
17d44ba8fde2 mod_http_admin_api: support for creating groups with MUCs
Jonas Schäfer <jonas@wielicki.name>
parents: 4382
diff changeset
488 {
17d44ba8fde2 mod_http_admin_api: support for creating groups with MUCs
Jonas Schäfer <jonas@wielicki.name>
parents: 4382
diff changeset
489 name = group.name;
17d44ba8fde2 mod_http_admin_api: support for creating groups with MUCs
Jonas Schäfer <jonas@wielicki.name>
parents: 4382
diff changeset
490 },
17d44ba8fde2 mod_http_admin_api: support for creating groups with MUCs
Jonas Schäfer <jonas@wielicki.name>
parents: 4382
diff changeset
491 create_muc
17d44ba8fde2 mod_http_admin_api: support for creating groups with MUCs
Jonas Schäfer <jonas@wielicki.name>
parents: 4382
diff changeset
492 );
4382
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
493 if not group_id then
4353
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
494 return 500;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
495 end
4361
7f1f3b79d991 mod_http_admin_api: Return new group object on successful creation
Matthew Wild <mwild1@gmail.com>
parents: 4360
diff changeset
496
7f1f3b79d991 mod_http_admin_api: Return new group object on successful creation
Matthew Wild <mwild1@gmail.com>
parents: 4360
diff changeset
497 event.response.headers["Content-Type"] = json_content_type;
4390
17d44ba8fde2 mod_http_admin_api: support for creating groups with MUCs
Jonas Schäfer <jonas@wielicki.name>
parents: 4382
diff changeset
498
17d44ba8fde2 mod_http_admin_api: support for creating groups with MUCs
Jonas Schäfer <jonas@wielicki.name>
parents: 4382
diff changeset
499 local info = mod_groups.get_info(group_id);
4361
7f1f3b79d991 mod_http_admin_api: Return new group object on successful creation
Matthew Wild <mwild1@gmail.com>
parents: 4360
diff changeset
500 return json.encode({
4368
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
501 id = group_id;
4390
17d44ba8fde2 mod_http_admin_api: support for creating groups with MUCs
Jonas Schäfer <jonas@wielicki.name>
parents: 4382
diff changeset
502 name = info.name;
17d44ba8fde2 mod_http_admin_api: support for creating groups with MUCs
Jonas Schäfer <jonas@wielicki.name>
parents: 4382
diff changeset
503 muc_jid = info.muc_jid or nil;
4368
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
504 members = {};
4361
7f1f3b79d991 mod_http_admin_api: Return new group object on successful creation
Matthew Wild <mwild1@gmail.com>
parents: 4360
diff changeset
505 });
4353
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
506 end
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
507
4368
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
508 function update_group(event, group) --luacheck: ignore 212/event
4382
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
509 -- Add member
4368
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
510 local group_id, member_name = group:match("^([^/]+)/members/([^/]+)$");
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
511 if group_id and member_name then
4382
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
512 if not mod_groups.add_member(group_id, member_name) then
4368
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
513 return 500;
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
514 end
4369
29b7f445aec5 mod_http_admin_api: add support for updating groups
Jonas Schäfer <jonas@wielicki.name>
parents: 4368
diff changeset
515 return 204;
29b7f445aec5 mod_http_admin_api: add support for updating groups
Jonas Schäfer <jonas@wielicki.name>
parents: 4368
diff changeset
516 end
29b7f445aec5 mod_http_admin_api: add support for updating groups
Jonas Schäfer <jonas@wielicki.name>
parents: 4368
diff changeset
517
29b7f445aec5 mod_http_admin_api: add support for updating groups
Jonas Schäfer <jonas@wielicki.name>
parents: 4368
diff changeset
518 local group_id = group:match("^([^/]+)$")
29b7f445aec5 mod_http_admin_api: add support for updating groups
Jonas Schäfer <jonas@wielicki.name>
parents: 4368
diff changeset
519 if group_id then
29b7f445aec5 mod_http_admin_api: add support for updating groups
Jonas Schäfer <jonas@wielicki.name>
parents: 4368
diff changeset
520 local request = event.request;
4382
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
521 if request.headers.content_type ~= json_content_type or (not request.body or #request.body == 0) then
4369
29b7f445aec5 mod_http_admin_api: add support for updating groups
Jonas Schäfer <jonas@wielicki.name>
parents: 4368
diff changeset
522 return 400;
29b7f445aec5 mod_http_admin_api: add support for updating groups
Jonas Schäfer <jonas@wielicki.name>
parents: 4368
diff changeset
523 end
29b7f445aec5 mod_http_admin_api: add support for updating groups
Jonas Schäfer <jonas@wielicki.name>
parents: 4368
diff changeset
524
29b7f445aec5 mod_http_admin_api: add support for updating groups
Jonas Schäfer <jonas@wielicki.name>
parents: 4368
diff changeset
525 local update = json.decode(event.request.body);
29b7f445aec5 mod_http_admin_api: add support for updating groups
Jonas Schäfer <jonas@wielicki.name>
parents: 4368
diff changeset
526 if not update then
29b7f445aec5 mod_http_admin_api: add support for updating groups
Jonas Schäfer <jonas@wielicki.name>
parents: 4368
diff changeset
527 return 400;
29b7f445aec5 mod_http_admin_api: add support for updating groups
Jonas Schäfer <jonas@wielicki.name>
parents: 4368
diff changeset
528 end
29b7f445aec5 mod_http_admin_api: add support for updating groups
Jonas Schäfer <jonas@wielicki.name>
parents: 4368
diff changeset
529
4382
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
530 local group_info = mod_groups.get_info(group_id);
4369
29b7f445aec5 mod_http_admin_api: add support for updating groups
Jonas Schäfer <jonas@wielicki.name>
parents: 4368
diff changeset
531 if not group_info then
29b7f445aec5 mod_http_admin_api: add support for updating groups
Jonas Schäfer <jonas@wielicki.name>
parents: 4368
diff changeset
532 return 404;
29b7f445aec5 mod_http_admin_api: add support for updating groups
Jonas Schäfer <jonas@wielicki.name>
parents: 4368
diff changeset
533 end
29b7f445aec5 mod_http_admin_api: add support for updating groups
Jonas Schäfer <jonas@wielicki.name>
parents: 4368
diff changeset
534
29b7f445aec5 mod_http_admin_api: add support for updating groups
Jonas Schäfer <jonas@wielicki.name>
parents: 4368
diff changeset
535 if update.name then
4382
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
536 group_info["name"] = update.name;
4369
29b7f445aec5 mod_http_admin_api: add support for updating groups
Jonas Schäfer <jonas@wielicki.name>
parents: 4368
diff changeset
537 end
4382
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
538 if mod_groups.set_info(group_id, group_info) then
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
539 return 204;
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
540 else
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
541 return 500;
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
542 end
4368
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
543 end
4382
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
544 return 404;
4368
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
545 end
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
546
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
547 function delete_group(event, subpath) --luacheck: ignore 212/event
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
548 -- Check if this is a membership deletion and handle it
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
549 local group_id, member_name = subpath:match("^([^/]+)/members/([^/]+)$");
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
550 if group_id and member_name then
4382
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
551 if mod_groups.remove_member(group_id, member_name) then
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
552 return 204;
4368
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
553 else
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
554 return 500;
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
555 end
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
556 else
4382
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
557 -- Action refers to the group
4368
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
558 group_id = subpath;
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
559 end
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
560
4353
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
561 if not group_id then
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
562 return 400;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
563 end
4368
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
564
4382
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
565 if not mod_groups.exists(group_id) then
4368
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
566 return 404;
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
567 end
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
568
4382
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
569 if not mod_groups.delete(group_id) then
4353
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
570 return 500;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
571 end
4382
0d6b69777bc1 mod_http_admin_api: port to use new mod_groups_internal module
Jonas Schäfer <jonas@wielicki.name>
parents: 4378
diff changeset
572 return 204;
4353
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
573 end
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
574
4371
3d01bc4547b2 mod_http_admin_api: Add /server/info endpoint for site_name and version
Matthew Wild <mwild1@gmail.com>
parents: 4369
diff changeset
575 local function get_server_info(event)
3d01bc4547b2 mod_http_admin_api: Add /server/info endpoint for site_name and version
Matthew Wild <mwild1@gmail.com>
parents: 4369
diff changeset
576 event.response.headers["Content-Type"] = json_content_type;
3d01bc4547b2 mod_http_admin_api: Add /server/info endpoint for site_name and version
Matthew Wild <mwild1@gmail.com>
parents: 4369
diff changeset
577 return json.encode({
3d01bc4547b2 mod_http_admin_api: Add /server/info endpoint for site_name and version
Matthew Wild <mwild1@gmail.com>
parents: 4369
diff changeset
578 site_name = site_name;
3d01bc4547b2 mod_http_admin_api: Add /server/info endpoint for site_name and version
Matthew Wild <mwild1@gmail.com>
parents: 4369
diff changeset
579 version = prosody.version;
3d01bc4547b2 mod_http_admin_api: Add /server/info endpoint for site_name and version
Matthew Wild <mwild1@gmail.com>
parents: 4369
diff changeset
580 });
3d01bc4547b2 mod_http_admin_api: Add /server/info endpoint for site_name and version
Matthew Wild <mwild1@gmail.com>
parents: 4369
diff changeset
581 end
3d01bc4547b2 mod_http_admin_api: Add /server/info endpoint for site_name and version
Matthew Wild <mwild1@gmail.com>
parents: 4369
diff changeset
582
4576
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
583 local function maybe_export_plain_gauge(mf)
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
584 if mf == nil then
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
585 return nil
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
586 end
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
587 return mf.data.value
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
588 end
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
589
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
590 local function maybe_export_plain_counter(mf)
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
591 if mf == nil then
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
592 return nil
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
593 end
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
594 return {
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
595 since = mf.data._created,
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
596 value = mf.data.value,
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
597 }
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
598 end
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
599
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
600 local function maybe_export_summed_gauge(mf)
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
601 if mf == nil then
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
602 return nil
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
603 end
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
604 local sum = 0;
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
605 for _, metric in mf:iter_metrics() do
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
606 sum = sum + metric.value;
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
607 end
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
608 return sum;
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
609 end
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
610
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
611 local function get_server_metrics(event)
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
612 event.response.headers["Content-Type"] = json_content_type;
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
613 local result = {};
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
614 local families = statsmanager.get_metric_registry():get_metric_families();
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
615 result.memory = maybe_export_plain_gauge(families.process_resident_memory_bytes);
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
616 result.cpu = maybe_export_plain_counter(families.process_cpu_seconds);
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
617 result.c2s = maybe_export_summed_gauge(families["prosody_mod_c2s/connections"])
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
618 return json.encode(result);
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
619 end
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
620
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
621 local function post_server_announcement(event)
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
622 local request = event.request;
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
623 if request.headers.content_type ~= json_content_type
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
624 or (not request.body or #request.body == 0) then
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
625 return 400;
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
626 end
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
627 local body = json.decode(event.request.body);
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
628 if not body then
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
629 return 400;
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
630 end
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
631
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
632 if type(body.recipients) ~= "table" and body.recipients ~= "online" and body.recipients ~= "all" then
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
633 return 400;
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
634 end
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
635
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
636 if not body.body or #body.body == 0 then
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
637 return 400;
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
638 end
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
639
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
640 local message = st.message():tag("body"):text(body.body):up();
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
641 local host = module.host
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
642 message.attr.from = host
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
643 if body.recipients == "online" then
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
644 announce.send_to_online(message, host);
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
645 elseif body.recipients == "all" then
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
646 for username in usermanager.users(host) do
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
647 message.attr.to = username .. "@" .. host
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
648 module:send(st.clone(message))
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
649 end
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
650 else
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
651 for _, addr in ipairs(body.recipients) do
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
652 message.attr.to = addr
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
653 module:send(message)
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
654 end
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
655 end
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
656
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
657 return 201;
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
658 end
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
659
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
660 module:provides("http", {
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
661 route = check_auth {
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
662 ["GET /invites"] = list_invites;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
663 ["GET /invites/*"] = get_invite_by_id;
4374
e707810a943e mod_http_admin_api: Improve invite API and support password resets
Matthew Wild <mwild1@gmail.com>
parents: 4371
diff changeset
664 ["POST /invites/*"] = create_invite_type;
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
665 ["DELETE /invites/*"] = delete_invite;
4345
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
666
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
667 ["GET /users"] = list_users;
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
668 ["GET /users/*"] = get_user_by_name;
4516
5bc706c2db8f mod_http_admin_api: allow updating the user nickname via API
Jonas Schäfer <jonas@wielicki.name>
parents: 4396
diff changeset
669 ["PUT /users/*"] = update_user;
4345
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
670 ["DELETE /users/*"] = delete_user;
4353
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
671
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
672 ["GET /groups"] = list_groups;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
673 ["GET /groups/*"] = get_group_by_id;
4360
76bec3f66b24 mod_http_admin_api: Switch PUT to POST where appropriate
Matthew Wild <mwild1@gmail.com>
parents: 4359
diff changeset
674 ["POST /groups"] = create_group;
4368
e0c8d866d58c mod_http_admin_api: Some fixes and improvements for the groups API
Matthew Wild <mwild1@gmail.com>
parents: 4366
diff changeset
675 ["PUT /groups/*"] = update_group;
4353
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
676 ["DELETE /groups/*"] = delete_group;
4371
3d01bc4547b2 mod_http_admin_api: Add /server/info endpoint for site_name and version
Matthew Wild <mwild1@gmail.com>
parents: 4369
diff changeset
677
3d01bc4547b2 mod_http_admin_api: Add /server/info endpoint for site_name and version
Matthew Wild <mwild1@gmail.com>
parents: 4369
diff changeset
678 ["GET /server/info"] = get_server_info;
4576
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
679
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
680 ["GET /server/metrics"] = get_server_metrics;
cade5dac1003 mod_http_admin_api: Add endpoints for server maintenance
Jonas Schäfer <jonas@wielicki.name>
parents: 4517
diff changeset
681 ["POST /server/announcement"] = post_server_announcement;
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
682 };
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
683 });