Software /
code /
prosody
Comparison
plugins/mod_admin_adhoc.lua @ 5135:52eafe0e9772
mod_admin_adhoc: Add commands for activating and deactivating hosts
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 19 Sep 2012 15:12:18 +0200 |
parent | 5100:65207b768f60 |
child | 5202:ff0d0cd07c43 |
comparison
equal
deleted
inserted
replaced
5134:43c5227fdd3b | 5135:52eafe0e9772 |
---|---|
15 local usermanager_user_exists = require "core.usermanager".user_exists; | 15 local usermanager_user_exists = require "core.usermanager".user_exists; |
16 local usermanager_create_user = require "core.usermanager".create_user; | 16 local usermanager_create_user = require "core.usermanager".create_user; |
17 local usermanager_delete_user = require "core.usermanager".delete_user; | 17 local usermanager_delete_user = require "core.usermanager".delete_user; |
18 local usermanager_get_password = require "core.usermanager".get_password; | 18 local usermanager_get_password = require "core.usermanager".get_password; |
19 local usermanager_set_password = require "core.usermanager".set_password; | 19 local usermanager_set_password = require "core.usermanager".set_password; |
20 local hostmanager_activate = require "core.hostmanager".activate; | |
21 local hostmanager_deactivate = require "core.hostmanager".deactivate; | |
20 local is_admin = require "core.usermanager".is_admin; | 22 local is_admin = require "core.usermanager".is_admin; |
21 local rm_load_roster = require "core.rostermanager".load_roster; | 23 local rm_load_roster = require "core.rostermanager".load_roster; |
22 local st, jid, uuid = require "util.stanza", require "util.jid", require "util.uuid"; | 24 local st, jid, uuid = require "util.stanza", require "util.jid", require "util.uuid"; |
23 local timer_add_task = require "util.timer".add_task; | 25 local timer_add_task = require "util.timer".add_task; |
24 local dataforms_new = require "util.dataforms".new; | 26 local dataforms_new = require "util.dataforms".new; |
604 local modules = array.collect(keys(hosts[data.to].modules)):sort(); | 606 local modules = array.collect(keys(hosts[data.to].modules)):sort(); |
605 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = { layout = layout; values = { modules = modules } } }, "executing"; | 607 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = { layout = layout; values = { modules = modules } } }, "executing"; |
606 end | 608 end |
607 end | 609 end |
608 | 610 |
611 function activate_host_handler(self, data, state) | |
612 local layout = dataforms_new { | |
613 title = "Activate host"; | |
614 instructions = ""; | |
615 | |
616 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/hosts#activate" }; | |
617 { name = "host", type = "text-single", required = true, label = "Host:"}; | |
618 }; | |
619 if state then | |
620 if data.action == "cancel" then | |
621 return { status = "canceled" }; | |
622 end | |
623 local fields, err = layout:data(data.form); | |
624 if err then | |
625 return generate_error_message(err); | |
626 end | |
627 local ok, err = hostmanager_activate(fields.host); | |
628 | |
629 if ok then | |
630 return { status = "completed", info = fields.host .. " activated" }; | |
631 else | |
632 return { status = "canceled", error = err } | |
633 end | |
634 else | |
635 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = { layout = layout } }, "executing"; | |
636 end | |
637 end | |
638 | |
639 function deactivate_host_handler(self, data, state) | |
640 local layout = dataforms_new { | |
641 title = "Deactivate host"; | |
642 instructions = ""; | |
643 | |
644 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/hosts#activate" }; | |
645 { name = "host", type = "text-single", required = true, label = "Host:"}; | |
646 }; | |
647 if state then | |
648 if data.action == "cancel" then | |
649 return { status = "canceled" }; | |
650 end | |
651 local fields, err = layout:data(data.form); | |
652 if err then | |
653 return generate_error_message(err); | |
654 end | |
655 local ok, err = hostmanager_deactivate(fields.host); | |
656 | |
657 if ok then | |
658 return { status = "completed", info = fields.host .. " deactivated" }; | |
659 else | |
660 return { status = "canceled", error = err } | |
661 end | |
662 else | |
663 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = { layout = layout } }, "executing"; | |
664 end | |
665 end | |
666 | |
667 | |
609 local add_user_desc = adhoc_new("Add User", "http://jabber.org/protocol/admin#add-user", add_user_command_handler, "admin"); | 668 local add_user_desc = adhoc_new("Add User", "http://jabber.org/protocol/admin#add-user", add_user_command_handler, "admin"); |
610 local change_user_password_desc = adhoc_new("Change User Password", "http://jabber.org/protocol/admin#change-user-password", change_user_password_command_handler, "admin"); | 669 local change_user_password_desc = adhoc_new("Change User Password", "http://jabber.org/protocol/admin#change-user-password", change_user_password_command_handler, "admin"); |
611 local config_reload_desc = adhoc_new("Reload configuration", "http://prosody.im/protocol/config#reload", config_reload_handler, "global_admin"); | 670 local config_reload_desc = adhoc_new("Reload configuration", "http://prosody.im/protocol/config#reload", config_reload_handler, "global_admin"); |
612 local delete_user_desc = adhoc_new("Delete User", "http://jabber.org/protocol/admin#delete-user", delete_user_command_handler, "admin"); | 671 local delete_user_desc = adhoc_new("Delete User", "http://jabber.org/protocol/admin#delete-user", delete_user_command_handler, "admin"); |
613 local end_user_session_desc = adhoc_new("End User Session", "http://jabber.org/protocol/admin#end-user-session", end_user_session_handler, "admin"); | 672 local end_user_session_desc = adhoc_new("End User Session", "http://jabber.org/protocol/admin#end-user-session", end_user_session_handler, "admin"); |
618 local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/protocol/modules#list", list_modules_handler, "admin"); | 677 local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/protocol/modules#list", list_modules_handler, "admin"); |
619 local load_module_desc = adhoc_new("Load module", "http://prosody.im/protocol/modules#load", load_module_handler, "admin"); | 678 local load_module_desc = adhoc_new("Load module", "http://prosody.im/protocol/modules#load", load_module_handler, "admin"); |
620 local reload_modules_desc = adhoc_new("Reload modules", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin"); | 679 local reload_modules_desc = adhoc_new("Reload modules", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin"); |
621 local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "global_admin"); | 680 local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "global_admin"); |
622 local unload_modules_desc = adhoc_new("Unload modules", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin"); | 681 local unload_modules_desc = adhoc_new("Unload modules", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin"); |
682 local activate_host_desc = adhoc_new("Activate host", "http://prosody.im/protocol/hosts#activate", activate_host_handler, "global_admin"); | |
683 local deactivate_host_desc = adhoc_new("Deactivate host", "http://prosody.im/protocol/hosts#deactivate", deactivate_host_handler, "global_admin"); | |
623 | 684 |
624 module:provides("adhoc", add_user_desc); | 685 module:provides("adhoc", add_user_desc); |
625 module:provides("adhoc", change_user_password_desc); | 686 module:provides("adhoc", change_user_password_desc); |
626 module:provides("adhoc", config_reload_desc); | 687 module:provides("adhoc", config_reload_desc); |
627 module:provides("adhoc", delete_user_desc); | 688 module:provides("adhoc", delete_user_desc); |
633 module:provides("adhoc", list_modules_desc); | 694 module:provides("adhoc", list_modules_desc); |
634 module:provides("adhoc", load_module_desc); | 695 module:provides("adhoc", load_module_desc); |
635 module:provides("adhoc", reload_modules_desc); | 696 module:provides("adhoc", reload_modules_desc); |
636 module:provides("adhoc", shut_down_service_desc); | 697 module:provides("adhoc", shut_down_service_desc); |
637 module:provides("adhoc", unload_modules_desc); | 698 module:provides("adhoc", unload_modules_desc); |
699 module:provides("adhoc", activate_host_desc); | |
700 module:provides("adhoc", deactivate_host_desc); |