From cfe10e6fa474e0c5d94d04d65663e774627d64a0 Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Wed, 19 Sep 2012 15:12:18 +0200
Subject: mod_admin_adhoc: Add commands for activating and deactivating hosts

---
 plugins/mod_admin_adhoc.lua | 63 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/plugins/mod_admin_adhoc.lua b/plugins/mod_admin_adhoc.lua
index a13c7312..aa1af3ff 100644
--- a/plugins/mod_admin_adhoc.lua
+++ b/plugins/mod_admin_adhoc.lua
@@ -17,6 +17,8 @@ local usermanager_create_user = require "core.usermanager".create_user;
 local usermanager_delete_user = require "core.usermanager".delete_user;
 local usermanager_get_password = require "core.usermanager".get_password;
 local usermanager_set_password = require "core.usermanager".set_password;
+local hostmanager_activate = require "core.hostmanager".activate;
+local hostmanager_deactivate = require "core.hostmanager".deactivate;
 local is_admin = require "core.usermanager".is_admin;
 local rm_load_roster = require "core.rostermanager".load_roster;
 local st, jid, uuid = require "util.stanza", require "util.jid", require "util.uuid";
@@ -606,6 +608,63 @@ function unload_modules_handler(self, data, state)
 	end
 end
 
+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
+
+
 local add_user_desc = adhoc_new("Add User", "http://jabber.org/protocol/admin#add-user", add_user_command_handler, "admin");
 local change_user_password_desc = adhoc_new("Change User Password", "http://jabber.org/protocol/admin#change-user-password", change_user_password_command_handler, "admin");
 local config_reload_desc = adhoc_new("Reload configuration", "http://prosody.im/protocol/config#reload", config_reload_handler, "global_admin");
@@ -620,6 +679,8 @@ local load_module_desc = adhoc_new("Load module", "http://prosody.im/protocol/mo
 local reload_modules_desc = adhoc_new("Reload modules", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin");
 local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "global_admin");
 local unload_modules_desc = adhoc_new("Unload modules", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin");
+local activate_host_desc = adhoc_new("Activate host", "http://prosody.im/protocol/hosts#activate", activate_host_handler, "global_admin");
+local deactivate_host_desc = adhoc_new("Deactivate host", "http://prosody.im/protocol/hosts#deactivate", deactivate_host_handler, "global_admin");
 
 module:provides("adhoc", add_user_desc);
 module:provides("adhoc", change_user_password_desc);
@@ -635,3 +696,5 @@ module:provides("adhoc", load_module_desc);
 module:provides("adhoc", reload_modules_desc);
 module:provides("adhoc", shut_down_service_desc);
 module:provides("adhoc", unload_modules_desc);
+module:provides("adhoc", activate_host_desc);
+module:provides("adhoc", deactivate_host_desc);
-- 
cgit v1.2.3


From e0e7541f02faa5df74a151e3fe64d9323a12ebe7 Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Wed, 19 Sep 2012 16:39:19 +0200
Subject: storagemanager: Fix argument (Thanks Maranda)

---
 core/storagemanager.lua | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/core/storagemanager.lua b/core/storagemanager.lua
index d744700a..97ff084f 100644
--- a/core/storagemanager.lua
+++ b/core/storagemanager.lua
@@ -123,7 +123,7 @@ function datamanager.stores(username, host, typ)
 	return get_driver(host):stores(username, typ);
 end
 function datamanager.purge(username, host)
-	return purge(username);
+	return purge(username, host);
 end
 
 return _M;
-- 
cgit v1.2.3


From 93cde32b80d341ff10c2a1bae4344199486389bc Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Wed, 19 Sep 2012 16:40:38 +0200
Subject: storagemanager: Remove unused variable

---
 core/storagemanager.lua | 1 -
 1 file changed, 1 deletion(-)

diff --git a/core/storagemanager.lua b/core/storagemanager.lua
index 97ff084f..5a7bb7bd 100644
--- a/core/storagemanager.lua
+++ b/core/storagemanager.lua
@@ -96,7 +96,6 @@ end
 
 function purge(user, host)
 	local storage = config.get(host, "storage");
-	local driver_name;
 	if type(storage) == "table" then
 		-- multiple storage backends in use that we need to purge
 		local purged = {};
-- 
cgit v1.2.3


From 8d9a04088f11349c430002cf6f56ce2337228b20 Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Wed, 19 Sep 2012 23:24:40 +0200
Subject: prosodyctl: Set $HOME to data path. Fixes issue with openssl and
 random state (Thanks Florob)

---
 prosodyctl | 1 +
 1 file changed, 1 insertion(+)

diff --git a/prosodyctl b/prosodyctl
index d4aa6d5e..52b734f7 100755
--- a/prosodyctl
+++ b/prosodyctl
@@ -161,6 +161,7 @@ if ok and pposix then
 	
 	-- Set our umask to protect data files
 	pposix.umask(config.get("*", "core", "umask") or "027");
+	pposix.setenv("HOME", data_path);
 else
 	print("Error: Unable to load pposix module. Check that Prosody is installed correctly.")
 	print("For more help send the below error to us through http://prosody.im/discuss");
-- 
cgit v1.2.3


From eae1e0b03e4c3b9cabc93537f036121496d1e6a5 Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Wed, 19 Sep 2012 23:25:10 +0200
Subject: prosodyctl: Abort if unable to load util.pposix

---
 prosodyctl | 1 +
 1 file changed, 1 insertion(+)

diff --git a/prosodyctl b/prosodyctl
index 52b734f7..12117c0f 100755
--- a/prosodyctl
+++ b/prosodyctl
@@ -166,6 +166,7 @@ else
 	print("Error: Unable to load pposix module. Check that Prosody is installed correctly.")
 	print("For more help send the below error to us through http://prosody.im/discuss");
 	print(tostring(pposix))
+	os.exit(1);
 end
 
 local function test_writeable(filename)
-- 
cgit v1.2.3


From 4a423e63859ba5be2ff19dd5d5d17dd75ad19f59 Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Wed, 19 Sep 2012 23:26:38 +0200
Subject: prosodyctl: Set stricter umask while generating key (thanks darkrain)

---
 prosodyctl | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/prosodyctl b/prosodyctl
index 12117c0f..93eac3f2 100755
--- a/prosodyctl
+++ b/prosodyctl
@@ -686,11 +686,13 @@ function cert_commands.key(arg)
 		if ask_overwrite(key_filename) then
 			return nil, key_filename;
 		end
-		os.remove(key_filename); -- We chmod this file to not have write permissions
+		os.remove(key_filename); -- This file, if it exists is unlikely to have write permissions
 		local key_size = tonumber(arg[2] or show_prompt("Choose key size (2048):") or 2048);
+		local old_umask = pposix.umask("0377");
 		if openssl.genrsa{out=key_filename, key_size} then
 			os.execute(("chmod 400 '%s'"):format(key_filename));
 			show_message("Key written to ".. key_filename);
+			pposix.umask(old_umask);
 			return nil, key_filename;
 		end
 		show_message("There was a problem, see OpenSSL output");
-- 
cgit v1.2.3


From c586bcd596d47bf6cca6439d3eb96ba8d6a681f4 Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Wed, 19 Sep 2012 23:29:25 +0200
Subject: prosodyctl: Fix copypaste error

---
 prosodyctl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/prosodyctl b/prosodyctl
index 93eac3f2..e26339e2 100755
--- a/prosodyctl
+++ b/prosodyctl
@@ -724,7 +724,7 @@ function cert_commands.generate(arg)
 	if #arg >= 1 and arg[1] ~= "--help" then
 		local cert_filename = (CFG_DATADIR or ".") .. "/" .. arg[1] .. ".cert";
 		if ask_overwrite(cert_filename) then
-			return nil, conf_filename;
+			return nil, cert_filename;
 		end
 		local _, key_filename = cert_commands.key({arg[1]});
 		local _, conf_filename = cert_commands.config(arg);
-- 
cgit v1.2.3