# HG changeset patch # User Florian Zeitz # Date 1281647234 -7200 # Node ID 161067865850f25be49fa89329addf3c42b7680b # Parent 665552d75ee28ae5ee07e97db7b06343430928df mod_adhoc_cmd_admin: Be more tollerant towards client/user errors. diff -r 665552d75ee2 -r 161067865850 mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua --- a/mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua Thu Aug 12 20:57:58 2010 +0200 +++ b/mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua Thu Aug 12 23:07:14 2010 +0200 @@ -66,7 +66,7 @@ instructions = "Fill out this form to get a user's password."; { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; - { name = "accountjid", type = "jid-single", label = "The Jabber ID for which to retrieve the password" }; + { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for which to retrieve the password" }; }; local get_user_password_result_layout = dataforms_new{ @@ -77,7 +77,7 @@ local get_user_roster_layout = dataforms_new{ { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; - { name = "accountjid", type = "jid-single", label = "The Jabber ID for which to retrieve the roster" }; + { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for which to retrieve the roster" }; }; local get_user_roster_result_layout = dataforms_new{ @@ -91,7 +91,7 @@ instructions = "Fill out this form to gather user statistics."; { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; - { name = "accountjid", type = "jid-single", label = "The Jabber ID for statistics" }; + { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for statistics" }; }; local get_user_stats_result_layout = dataforms_new{ @@ -149,6 +149,9 @@ return { status = "canceled" }; end local fields = add_user_layout:data(data.form); + if not fields.accountjid then + return { status = "completed", error = { message = "You need to specify a JID." } }; + end local username, host, resource = jid.split(fields.accountjid); if data.to ~= host then return { status = "completed", error = { message = "Trying to add a user on " .. host .. " but command was sent to " .. data.to}}; @@ -180,6 +183,9 @@ return { status = "canceled" }; end local fields = change_user_password_layout:data(data.form); + if not fields.accountjid or fields.accountjid == "" or not fields.password then + return { status = "completed", error = { message = "Please specify username and password" } }; + end local username, host, resource = jid.split(fields.accountjid); if data.to ~= host then return { status = "completed", error = { message = "Trying to change the password of a user on " .. host .. " but command was sent to " .. data.to}}; @@ -266,6 +272,9 @@ return { status = "canceled" }; end local fields = get_user_password_layout:data(data.form); + if not fields.accountjid then + return { status = "completed", error = { message = "Please specify a JID." } }; + end local user, host, resource = jid.split(fields.accountjid); local accountjid = ""; local password = ""; @@ -291,6 +300,10 @@ local fields = add_user_layout:data(data.form); + if not fields.accountjid then + return { status = "completed", error = { message = "Please specify a JID" } }; + end + local user, host, resource = jid.split(fields.accountjid); if host ~= data.to then return { status = "completed", error = { message = "Tried to get roster for a user on " .. host .. " but command was sent to " .. data.to } }; @@ -334,6 +347,10 @@ local fields = get_user_stats_layout:data(data.form); + if not fields.accountjid then + return { status = "completed", error = { message = "Please specify a JID." } }; + end + local user, host, resource = jid.split(fields.accountjid); if host ~= data.to then return { status = "completed", error = { message = "Tried to get stats for a user on " .. host .. " but command was sent to " .. data.to } }; @@ -429,6 +446,10 @@ local fields = announce_layout:data(data.form); + if #fields.announcement == 0 then + return { status = "completed", error = { message = "Please specify some announcement text." } }; + end + module:log("info", "Sending server announcement to all online users"); local message = st.message({type = "headline"}, fields.announcement):up() :tag("subject"):text(fields.subject or "Announcement"); @@ -452,7 +473,7 @@ local fields = shut_down_service_layout:data(data.form); - if fields.announcement then + if #fields.announcement > 0 then local message = st.message({type = "headline"}, fields.announcement):up() :tag("subject"):text("Server is shutting down"); send_to_online(message);