Mercurial > prosody-modules
comparison mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua @ 242:161067865850
mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
| author | Florian Zeitz <florob@babelmonkeys.de> |
|---|---|
| date | Thu, 12 Aug 2010 23:07:14 +0200 |
| parents | 648c24de9040 |
| children | db1b4c6089b6 |
comparison
equal
deleted
inserted
replaced
| 241:665552d75ee2 | 242:161067865850 |
|---|---|
| 64 local get_user_password_layout = dataforms_new{ | 64 local get_user_password_layout = dataforms_new{ |
| 65 title = "Getting User's Password"; | 65 title = "Getting User's Password"; |
| 66 instructions = "Fill out this form to get a user's password."; | 66 instructions = "Fill out this form to get a user's password."; |
| 67 | 67 |
| 68 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; | 68 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; |
| 69 { name = "accountjid", type = "jid-single", label = "The Jabber ID for which to retrieve the password" }; | 69 { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for which to retrieve the password" }; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 local get_user_password_result_layout = dataforms_new{ | 72 local get_user_password_result_layout = dataforms_new{ |
| 73 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; | 73 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; |
| 74 { name = "accountjid", type = "jid-single", label = "JID" }; | 74 { name = "accountjid", type = "jid-single", label = "JID" }; |
| 75 { name = "password", type = "text-single", label = "Password" }; | 75 { name = "password", type = "text-single", label = "Password" }; |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 local get_user_roster_layout = dataforms_new{ | 78 local get_user_roster_layout = dataforms_new{ |
| 79 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; | 79 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; |
| 80 { name = "accountjid", type = "jid-single", label = "The Jabber ID for which to retrieve the roster" }; | 80 { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for which to retrieve the roster" }; |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 local get_user_roster_result_layout = dataforms_new{ | 83 local get_user_roster_result_layout = dataforms_new{ |
| 84 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; | 84 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; |
| 85 { name = "accountjid", type = "jid-single", label = "This is the roster for" }; | 85 { name = "accountjid", type = "jid-single", label = "This is the roster for" }; |
| 89 local get_user_stats_layout = dataforms_new{ | 89 local get_user_stats_layout = dataforms_new{ |
| 90 title = "Get User Statistics"; | 90 title = "Get User Statistics"; |
| 91 instructions = "Fill out this form to gather user statistics."; | 91 instructions = "Fill out this form to gather user statistics."; |
| 92 | 92 |
| 93 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; | 93 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; |
| 94 { name = "accountjid", type = "jid-single", label = "The Jabber ID for statistics" }; | 94 { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for statistics" }; |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 local get_user_stats_result_layout = dataforms_new{ | 97 local get_user_stats_result_layout = dataforms_new{ |
| 98 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; | 98 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; |
| 99 { name = "ipaddresses", type = "text-multi", label = "IP Addresses" }; | 99 { name = "ipaddresses", type = "text-multi", label = "IP Addresses" }; |
| 147 if state then | 147 if state then |
| 148 if data.action == "cancel" then | 148 if data.action == "cancel" then |
| 149 return { status = "canceled" }; | 149 return { status = "canceled" }; |
| 150 end | 150 end |
| 151 local fields = add_user_layout:data(data.form); | 151 local fields = add_user_layout:data(data.form); |
| 152 if not fields.accountjid then | |
| 153 return { status = "completed", error = { message = "You need to specify a JID." } }; | |
| 154 end | |
| 152 local username, host, resource = jid.split(fields.accountjid); | 155 local username, host, resource = jid.split(fields.accountjid); |
| 153 if data.to ~= host then | 156 if data.to ~= host then |
| 154 return { status = "completed", error = { message = "Trying to add a user on " .. host .. " but command was sent to " .. data.to}}; | 157 return { status = "completed", error = { message = "Trying to add a user on " .. host .. " but command was sent to " .. data.to}}; |
| 155 end | 158 end |
| 156 if (fields["password"] == fields["password-verify"]) and username and host then | 159 if (fields["password"] == fields["password-verify"]) and username and host then |
| 178 if state then | 181 if state then |
| 179 if data.action == "cancel" then | 182 if data.action == "cancel" then |
| 180 return { status = "canceled" }; | 183 return { status = "canceled" }; |
| 181 end | 184 end |
| 182 local fields = change_user_password_layout:data(data.form); | 185 local fields = change_user_password_layout:data(data.form); |
| 186 if not fields.accountjid or fields.accountjid == "" or not fields.password then | |
| 187 return { status = "completed", error = { message = "Please specify username and password" } }; | |
| 188 end | |
| 183 local username, host, resource = jid.split(fields.accountjid); | 189 local username, host, resource = jid.split(fields.accountjid); |
| 184 if data.to ~= host then | 190 if data.to ~= host then |
| 185 return { status = "completed", error = { message = "Trying to change the password of a user on " .. host .. " but command was sent to " .. data.to}}; | 191 return { status = "completed", error = { message = "Trying to change the password of a user on " .. host .. " but command was sent to " .. data.to}}; |
| 186 end | 192 end |
| 187 if usermanager_user_exists(username, host) and usermanager_set_password(username, fields.password, host) then | 193 if usermanager_user_exists(username, host) and usermanager_set_password(username, fields.password, host) then |
| 264 if state then | 270 if state then |
| 265 if data.action == "cancel" then | 271 if data.action == "cancel" then |
| 266 return { status = "canceled" }; | 272 return { status = "canceled" }; |
| 267 end | 273 end |
| 268 local fields = get_user_password_layout:data(data.form); | 274 local fields = get_user_password_layout:data(data.form); |
| 275 if not fields.accountjid then | |
| 276 return { status = "completed", error = { message = "Please specify a JID." } }; | |
| 277 end | |
| 269 local user, host, resource = jid.split(fields.accountjid); | 278 local user, host, resource = jid.split(fields.accountjid); |
| 270 local accountjid = ""; | 279 local accountjid = ""; |
| 271 local password = ""; | 280 local password = ""; |
| 272 if host ~= data.to then | 281 if host ~= data.to then |
| 273 return { status = "completed", error = { message = "Tried to get password for a user on " .. host .. " but command was sent to " .. data.to } }; | 282 return { status = "completed", error = { message = "Tried to get password for a user on " .. host .. " but command was sent to " .. data.to } }; |
| 288 if data.action == "cancel" then | 297 if data.action == "cancel" then |
| 289 return { status = "canceled" }; | 298 return { status = "canceled" }; |
| 290 end | 299 end |
| 291 | 300 |
| 292 local fields = add_user_layout:data(data.form); | 301 local fields = add_user_layout:data(data.form); |
| 302 | |
| 303 if not fields.accountjid then | |
| 304 return { status = "completed", error = { message = "Please specify a JID" } }; | |
| 305 end | |
| 293 | 306 |
| 294 local user, host, resource = jid.split(fields.accountjid); | 307 local user, host, resource = jid.split(fields.accountjid); |
| 295 if host ~= data.to then | 308 if host ~= data.to then |
| 296 return { status = "completed", error = { message = "Tried to get roster for a user on " .. host .. " but command was sent to " .. data.to } }; | 309 return { status = "completed", error = { message = "Tried to get roster for a user on " .. host .. " but command was sent to " .. data.to } }; |
| 297 elseif not usermanager_user_exists(user, host) then | 310 elseif not usermanager_user_exists(user, host) then |
| 331 if data.action == "cancel" then | 344 if data.action == "cancel" then |
| 332 return { status = "canceled" }; | 345 return { status = "canceled" }; |
| 333 end | 346 end |
| 334 | 347 |
| 335 local fields = get_user_stats_layout:data(data.form); | 348 local fields = get_user_stats_layout:data(data.form); |
| 349 | |
| 350 if not fields.accountjid then | |
| 351 return { status = "completed", error = { message = "Please specify a JID." } }; | |
| 352 end | |
| 336 | 353 |
| 337 local user, host, resource = jid.split(fields.accountjid); | 354 local user, host, resource = jid.split(fields.accountjid); |
| 338 if host ~= data.to then | 355 if host ~= data.to then |
| 339 return { status = "completed", error = { message = "Tried to get stats for a user on " .. host .. " but command was sent to " .. data.to } }; | 356 return { status = "completed", error = { message = "Tried to get stats for a user on " .. host .. " but command was sent to " .. data.to } }; |
| 340 elseif not usermanager_user_exists(user, host) then | 357 elseif not usermanager_user_exists(user, host) then |
| 427 return { status = "canceled" }; | 444 return { status = "canceled" }; |
| 428 end | 445 end |
| 429 | 446 |
| 430 local fields = announce_layout:data(data.form); | 447 local fields = announce_layout:data(data.form); |
| 431 | 448 |
| 449 if #fields.announcement == 0 then | |
| 450 return { status = "completed", error = { message = "Please specify some announcement text." } }; | |
| 451 end | |
| 452 | |
| 432 module:log("info", "Sending server announcement to all online users"); | 453 module:log("info", "Sending server announcement to all online users"); |
| 433 local message = st.message({type = "headline"}, fields.announcement):up() | 454 local message = st.message({type = "headline"}, fields.announcement):up() |
| 434 :tag("subject"):text(fields.subject or "Announcement"); | 455 :tag("subject"):text(fields.subject or "Announcement"); |
| 435 | 456 |
| 436 local count = send_to_online(message, data.to); | 457 local count = send_to_online(message, data.to); |
| 450 return { status = "canceled" }; | 471 return { status = "canceled" }; |
| 451 end | 472 end |
| 452 | 473 |
| 453 local fields = shut_down_service_layout:data(data.form); | 474 local fields = shut_down_service_layout:data(data.form); |
| 454 | 475 |
| 455 if fields.announcement then | 476 if #fields.announcement > 0 then |
| 456 local message = st.message({type = "headline"}, fields.announcement):up() | 477 local message = st.message({type = "headline"}, fields.announcement):up() |
| 457 :tag("subject"):text("Server is shutting down"); | 478 :tag("subject"):text("Server is shutting down"); |
| 458 send_to_online(message); | 479 send_to_online(message); |
| 459 end | 480 end |
| 460 | 481 |
