Mercurial > prosody-modules
comparison mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua @ 44:00f96207693a
mod_adhoc_cmd_admin: Possibility to limit number of received answers
| author | Florian Zeitz <florob@babelmonkeys.de> |
|---|---|
| date | Fri, 16 Oct 2009 01:37:10 +0200 |
| parents | adc9eff8adb2 |
| children | 7fbaf590dc12 |
comparison
equal
deleted
inserted
replaced
| 43:adc9eff8adb2 | 44:00f96207693a |
|---|---|
| 25 | 25 |
| 26 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; | 26 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; |
| 27 { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for the account to be added" }; | 27 { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for the account to be added" }; |
| 28 { name = "password", type = "text-private", label = "The password for this account" }; | 28 { name = "password", type = "text-private", label = "The password for this account" }; |
| 29 { name = "password-verify", type = "text-private", label = "Retype password" }; | 29 { name = "password-verify", type = "text-private", label = "Retype password" }; |
| 30 }; | |
| 31 | |
| 32 local get_online_users_layout = dataforms_new{ | |
| 33 title = "Getting List of Online Users"; | |
| 34 instructions = "How many users should be returned at most?"; | |
| 35 | |
| 36 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; | |
| 37 { name = "max_items", type = "list-single", label = "Maximum number of users", | |
| 38 value = { "25", "50", "75", "100", "150", "200", "all" } }; | |
| 30 }; | 39 }; |
| 31 | 40 |
| 32 function add_user_command_handler(item, origin, stanza) | 41 function add_user_command_handler(item, origin, stanza) |
| 33 if not is_admin(stanza.attr.from) then | 42 if not is_admin(stanza.attr.from) then |
| 34 module:log("warn", "Non-admin %s tried to add a user", tostring(jid.bare(stanza.attr.from))); | 43 module:log("warn", "Non-admin %s tried to add a user", tostring(jid.bare(stanza.attr.from))); |
| 91 origin.send(st.error_reply(stanza, "auth", "forbidden", "You don't have permission to request a list of online users"):up() | 100 origin.send(st.error_reply(stanza, "auth", "forbidden", "You don't have permission to request a list of online users"):up() |
| 92 :add_child(item:cmdtag("canceled") | 101 :add_child(item:cmdtag("canceled") |
| 93 :tag("note", {type="error"}):text("You don't have permission to request a list of online users"))); | 102 :tag("note", {type="error"}):text("You don't have permission to request a list of online users"))); |
| 94 return true; | 103 return true; |
| 95 end | 104 end |
| 96 local field = st.stanza("field", {label="The list of all online users", var="onlineuserjids", type="text-multi"}); | 105 if stanza.tags[1].attr.sessionid and sessions[stanza.tags[1].attr.sessionid] then |
| 97 for username, user in pairs(hosts[stanza.attr.to].sessions or {}) do | 106 if stanza.tags[1].attr.action == "cancel" then |
| 98 field:tag("value"):text(username.."@"..stanza.attr.to):up(); | 107 origin.send(st.reply(stanza):add_child(item:cmdtag("canceled", stanza.tags[1].attr.sessionid))); |
| 108 sessions[stanza.tags[1].attr.sessionid] = nil; | |
| 109 return true; | |
| 110 end | |
| 111 | |
| 112 form = stanza.tags[1]:child_with_ns("jabber:x:data"); | |
| 113 local fields = add_user_layout:data(form); | |
| 114 | |
| 115 local max_items = nil | |
| 116 if fields.max_items ~= "all" then | |
| 117 max_items = tonumber(fields.max_items); | |
| 118 end | |
| 119 local count = 0; | |
| 120 local field = st.stanza("field", {label="The list of all online users", var="onlineuserjids", type="text-multi"}); | |
| 121 for username, user in pairs(hosts[stanza.attr.to].sessions or {}) do | |
| 122 if (max_items ~= nil) and (count >= max_items) then | |
| 123 break; | |
| 124 end | |
| 125 field:tag("value"):text(username.."@"..stanza.attr.to):up(); | |
| 126 count = count + 1; | |
| 127 end | |
| 128 origin.send(st.reply(stanza):add_child(item:cmdtag("completed", stanza.tags[1].attr.sessionid) | |
| 129 :tag("x", {xmlns="jabber:x:data", type="result"}) | |
| 130 :tag("field", {type="hidden", var="FORM_TYPE"}) | |
| 131 :tag("value"):text("http://jabber.org/protocol/admin"):up():up() | |
| 132 :add_child(field))); | |
| 133 else | |
| 134 local sessionid=uuid.generate(); | |
| 135 sessions[sessionid] = "executing"; | |
| 136 origin.send(st.reply(stanza):add_child(item:cmdtag("executing", sessionid):add_child(get_online_users_layout:form()))); | |
| 99 end | 137 end |
| 100 origin.send(st.reply(stanza):add_child(item:cmdtag("completed", uuid:generate()) | |
| 101 :tag("x", {xmlns="jabber:x:data", type="result"}) | |
| 102 :tag("field", {type="hidden", var="FORM_TYPE"}) | |
| 103 :tag("value"):text("http://jabber.org/protocol/admin"):up():up() | |
| 104 :add_child(field))); | |
| 105 | 138 |
| 106 return true; | 139 return true; |
| 107 end | 140 end |
| 108 | 141 |
| 109 local add_user_desc = adhoc_new("Add User", "http://jabber.org/protocol/admin#add-user", add_user_command_handler, "admin"); | 142 local add_user_desc = adhoc_new("Add User", "http://jabber.org/protocol/admin#add-user", add_user_command_handler, "admin"); |
