+function activate_host_handler(self, data, state)
+ local layout = dataforms_new {
+ title = "Activate host";
+ instructions = "";
+
+ { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/hosts#activate" };
+ { name = "host", type = "text-single", required = true, label = "Host:"};
+ };
+ if state then
+ if data.action == "cancel" then
+ return { status = "canceled" };
+ end
+ local fields, err = layout:data(data.form);
+ if err then
+ return generate_error_message(err);
+ end
+ local ok, err = hostmanager_activate(fields.host);
+
+ if ok then
+ return { status = "completed", info = fields.host .. " activated" };
+ else
+ return { status = "canceled", error = err }
+ end
+ else
+ return { status = "executing", actions = {"next", "complete", default = "complete"}, form = { layout = layout } }, "executing";
+ end
+end
+
+function deactivate_host_handler(self, data, state)
+ local layout = dataforms_new {
+ title = "Deactivate host";
+ instructions = "";
+
+ { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/hosts#activate" };
+ { name = "host", type = "text-single", required = true, label = "Host:"};
+ };
+ if state then
+ if data.action == "cancel" then
+ return { status = "canceled" };
+ end
+ local fields, err = layout:data(data.form);
+ if err then
+ return generate_error_message(err);
+ end
+ local ok, err = hostmanager_deactivate(fields.host);
+
+ if ok then
+ return { status = "completed", info = fields.host .. " deactivated" };
+ else
+ return { status = "canceled", error = err }
+ end
+ else
+ return { status = "executing", actions = {"next", "complete", default = "complete"}, form = { layout = layout } }, "executing";
+ end
+end
+
+