Comparison

plugins/mod_admin_adhoc.lua @ 5076:88fb94df9b18

mod_admin_adhoc, mod_announce: Explicitly specify possible actions for ad-hoc commands
author Florian Zeitz <florob@babelmonkeys.de>
date Thu, 02 Aug 2012 21:42:00 +0200
parent 5013:ab693eea0869
child 5100:65207b768f60
comparison
equal deleted inserted replaced
5075:4d939d2b1574 5076:88fb94df9b18
73 else 73 else
74 module:log("debug", "Invalid data, password mismatch or empty username while creating account for %s", fields.accountjid or "<nil>"); 74 module:log("debug", "Invalid data, password mismatch or empty username while creating account for %s", fields.accountjid or "<nil>");
75 return { status = "completed", error = { message = "Invalid data.\nPassword mismatch, or empty username" } }; 75 return { status = "completed", error = { message = "Invalid data.\nPassword mismatch, or empty username" } };
76 end 76 end
77 else 77 else
78 return { status = "executing", form = add_user_layout }, "executing"; 78 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = add_user_layout }, "executing";
79 end 79 end
80 end 80 end
81 81
82 function change_user_password_command_handler(self, data, state) 82 function change_user_password_command_handler(self, data, state)
83 local change_user_password_layout = dataforms_new{ 83 local change_user_password_layout = dataforms_new{
105 return { status = "completed", info = "Password successfully changed" }; 105 return { status = "completed", info = "Password successfully changed" };
106 else 106 else
107 return { status = "completed", error = { message = "User does not exist" } }; 107 return { status = "completed", error = { message = "User does not exist" } };
108 end 108 end
109 else 109 else
110 return { status = "executing", form = change_user_password_layout }, "executing"; 110 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = change_user_password_layout }, "executing";
111 end 111 end
112 end 112 end
113 113
114 function config_reload_handler(self, data, state) 114 function config_reload_handler(self, data, state)
115 local ok, err = prosody.reload_config(); 115 local ok, err = prosody.reload_config();
153 return {status = "completed", info = (#succeeded ~= 0 and 153 return {status = "completed", info = (#succeeded ~= 0 and
154 "The following accounts were successfully deleted:\n"..t_concat(succeeded, "\n").."\n" or "").. 154 "The following accounts were successfully deleted:\n"..t_concat(succeeded, "\n").."\n" or "")..
155 (#failed ~= 0 and 155 (#failed ~= 0 and
156 "The following accounts could not be deleted:\n"..t_concat(failed, "\n") or "") }; 156 "The following accounts could not be deleted:\n"..t_concat(failed, "\n") or "") };
157 else 157 else
158 return { status = "executing", form = delete_user_layout }, "executing"; 158 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = delete_user_layout }, "executing";
159 end 159 end
160 end 160 end
161 161
162 function disconnect_user(match_jid) 162 function disconnect_user(match_jid)
163 local node, hostname, givenResource = jid.split(match_jid); 163 local node, hostname, givenResource = jid.split(match_jid);
203 return {status = "completed", info = (#succeeded ~= 0 and 203 return {status = "completed", info = (#succeeded ~= 0 and
204 "The following accounts were successfully disconnected:\n"..t_concat(succeeded, "\n").."\n" or "").. 204 "The following accounts were successfully disconnected:\n"..t_concat(succeeded, "\n").."\n" or "")..
205 (#failed ~= 0 and 205 (#failed ~= 0 and
206 "The following accounts could not be disconnected:\n"..t_concat(failed, "\n") or "") }; 206 "The following accounts could not be disconnected:\n"..t_concat(failed, "\n") or "") };
207 else 207 else
208 return { status = "executing", form = end_user_session_layout }, "executing"; 208 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = end_user_session_layout }, "executing";
209 end 209 end
210 end 210 end
211 211
212 local end_user_session_layout = dataforms_new{ 212 local end_user_session_layout = dataforms_new{
213 title = "Ending a User Session"; 213 title = "Ending a User Session";
252 else 252 else
253 return { status = "completed", error = { message = "User does not exist" } }; 253 return { status = "completed", error = { message = "User does not exist" } };
254 end 254 end
255 return { status = "completed", result = { layout = get_user_password_result_layout, values = {accountjid = accountjid, password = password} } }; 255 return { status = "completed", result = { layout = get_user_password_result_layout, values = {accountjid = accountjid, password = password} } };
256 else 256 else
257 return { status = "executing", form = get_user_password_layout }, "executing"; 257 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = get_user_password_layout }, "executing";
258 end 258 end
259 end 259 end
260 260
261 function get_user_roster_handler(self, data, state) 261 function get_user_roster_handler(self, data, state)
262 local get_user_roster_layout = dataforms_new{ 262 local get_user_roster_layout = dataforms_new{
310 310
311 local result = get_user_roster_result_layout:form({ accountjid = user.."@"..host, roster = query_text }, "result"); 311 local result = get_user_roster_result_layout:form({ accountjid = user.."@"..host, roster = query_text }, "result");
312 result:add_child(query); 312 result:add_child(query);
313 return { status = "completed", other = result }; 313 return { status = "completed", other = result };
314 else 314 else
315 return { status = "executing", form = get_user_roster_layout }, "executing"; 315 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = get_user_roster_layout }, "executing";
316 end 316 end
317 end 317 end
318 318
319 function get_user_stats_handler(self, data, state) 319 function get_user_stats_handler(self, data, state)
320 local get_user_stats_layout = dataforms_new{ 320 local get_user_stats_layout = dataforms_new{
363 IPs = IPs .. "\n" .. session.ip; 363 IPs = IPs .. "\n" .. session.ip;
364 end 364 end
365 return { status = "completed", result = {layout = get_user_stats_result_layout, values = {ipaddresses = IPs, rostersize = tostring(rostersize), 365 return { status = "completed", result = {layout = get_user_stats_result_layout, values = {ipaddresses = IPs, rostersize = tostring(rostersize),
366 onlineresources = resources}} }; 366 onlineresources = resources}} };
367 else 367 else
368 return { status = "executing", form = get_user_stats_layout }, "executing"; 368 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = get_user_stats_layout }, "executing";
369 end 369 end
370 end 370 end
371 371
372 function get_online_users_command_handler(self, data, state) 372 function get_online_users_command_handler(self, data, state)
373 local get_online_users_layout = dataforms_new{ 373 local get_online_users_layout = dataforms_new{
423 end 423 end
424 end 424 end
425 end 425 end
426 return { status = "completed", result = {layout = get_online_users_result_layout, values = {onlineuserjids=t_concat(users, "\n")}} }; 426 return { status = "completed", result = {layout = get_online_users_result_layout, values = {onlineuserjids=t_concat(users, "\n")}} };
427 else 427 else
428 return { status = "executing", form = get_online_users_layout }, "executing"; 428 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = get_online_users_layout }, "executing";
429 end 429 end
430 end 430 end
431 431
432 function list_modules_handler(self, data, state) 432 function list_modules_handler(self, data, state)
433 local result = dataforms_new { 433 local result = dataforms_new {
467 else 467 else
468 return { status = "completed", error = { message = 'Failed to load module "'..fields.module..'" on host "'..data.to.. 468 return { status = "completed", error = { message = 'Failed to load module "'..fields.module..'" on host "'..data.to..
469 '". Error was: "'..tostring(err or "<unspecified>")..'"' } }; 469 '". Error was: "'..tostring(err or "<unspecified>")..'"' } };
470 end 470 end
471 else 471 else
472 return { status = "executing", form = layout }, "executing"; 472 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = layout }, "executing";
473 end 473 end
474 end 474 end
475 475
476 function reload_modules_handler(self, data, state) 476 function reload_modules_handler(self, data, state)
477 local layout = dataforms_new { 477 local layout = dataforms_new {
501 local info = (#ok_list > 0 and ("The following modules were successfully reloaded on host "..data.to..":\n"..t_concat(ok_list, "\n")) or "").. 501 local info = (#ok_list > 0 and ("The following modules were successfully reloaded on host "..data.to..":\n"..t_concat(ok_list, "\n")) or "")..
502 (#err_list > 0 and ("Failed to reload the following modules on host "..data.to..":\n"..t_concat(err_list, "\n")) or ""); 502 (#err_list > 0 and ("Failed to reload the following modules on host "..data.to..":\n"..t_concat(err_list, "\n")) or "");
503 return { status = "completed", info = info }; 503 return { status = "completed", info = info };
504 else 504 else
505 local modules = array.collect(keys(hosts[data.to].modules)):sort(); 505 local modules = array.collect(keys(hosts[data.to].modules)):sort();
506 return { status = "executing", form = { layout = layout; values = { modules = modules } } }, "executing"; 506 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = { layout = layout; values = { modules = modules } } }, "executing";
507 end 507 end
508 end 508 end
509 509
510 function send_to_online(message, server) 510 function send_to_online(message, server)
511 if server then 511 if server then
565 565
566 timer_add_task(tonumber(fields.delay or "5"), prosody.shutdown); 566 timer_add_task(tonumber(fields.delay or "5"), prosody.shutdown);
567 567
568 return { status = "completed", info = "Server is about to shut down" }; 568 return { status = "completed", info = "Server is about to shut down" };
569 else 569 else
570 return { status = "executing", form = shut_down_service_layout }, "executing"; 570 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = shut_down_service_layout }, "executing";
571 end 571 end
572 end 572 end
573 573
574 function unload_modules_handler(self, data, state) 574 function unload_modules_handler(self, data, state)
575 local layout = dataforms_new { 575 local layout = dataforms_new {
599 local info = (#ok_list > 0 and ("The following modules were successfully unloaded on host "..data.to..":\n"..t_concat(ok_list, "\n")) or "").. 599 local info = (#ok_list > 0 and ("The following modules were successfully unloaded on host "..data.to..":\n"..t_concat(ok_list, "\n")) or "")..
600 (#err_list > 0 and ("Failed to unload the following modules on host "..data.to..":\n"..t_concat(err_list, "\n")) or ""); 600 (#err_list > 0 and ("Failed to unload the following modules on host "..data.to..":\n"..t_concat(err_list, "\n")) or "");
601 return { status = "completed", info = info }; 601 return { status = "completed", info = info };
602 else 602 else
603 local modules = array.collect(keys(hosts[data.to].modules)):sort(); 603 local modules = array.collect(keys(hosts[data.to].modules)):sort();
604 return { status = "executing", form = { layout = layout; values = { modules = modules } } }, "executing"; 604 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = { layout = layout; values = { modules = modules } } }, "executing";
605 end 605 end
606 end 606 end
607 607
608 local add_user_desc = adhoc_new("Add User", "http://jabber.org/protocol/admin#add-user", add_user_command_handler, "admin"); 608 local add_user_desc = adhoc_new("Add User", "http://jabber.org/protocol/admin#add-user", add_user_command_handler, "admin");
609 local change_user_password_desc = adhoc_new("Change User Password", "http://jabber.org/protocol/admin#change-user-password", change_user_password_command_handler, "admin"); 609 local change_user_password_desc = adhoc_new("Change User Password", "http://jabber.org/protocol/admin#change-user-password", change_user_password_command_handler, "admin");