Mercurial > prosody-modules
changeset 1452:097c6af98d0a
Merge
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 25 Jun 2014 20:46:35 +0200 |
parents | 843769eb40c3 (current diff) d31ace5b1175 (diff) |
children | 7b53cfc6ba8d |
files | |
diffstat | 3 files changed, 98 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_muc_log/mod_muc_log.lua Wed Jun 25 20:45:01 2014 +0200 +++ b/mod_muc_log/mod_muc_log.lua Wed Jun 25 20:46:35 2014 +0200 @@ -16,21 +16,39 @@ -- Module Definitions +local function get_room_from_jid(jid) + local node, host = split_jid(jid); + local component = hosts[host]; + if component then + local muc = component.modules.muc + if muc and rawget(muc,"rooms") then + -- We're running 0.9.x or 0.10 (old MUC API) + return muc.rooms[jid]; + elseif muc and rawget(muc,"get_room_from_jid") then + -- We're running >0.10 (new MUC API) + return muc.get_room_from_jid(jid); + else + return + end + end +end + function log_if_needed(event) local stanza = event.stanza; - if (stanza.name == "presence") or + if (stanza.name == "presence") or (stanza.name == "iq") or - (stanza.name == "message" and tostring(stanza.attr.type) == "groupchat") + (stanza.name == "message" and tostring(stanza.attr.type) == "groupchat") then local node, host = split_jid(stanza.attr.to); - local muc = hosts[host].muc; if node and host then local bare = node .. "@" .. host; - if muc and muc.rooms[bare] then - local room = muc.rooms[bare] - local today = os.date("%y%m%d"); - local now = os.date("%X") + if get_room_from_jid(bare) then + local room = get_room_from_jid(bare) + + local today = os.date("!%y%m%d"); + local now = os.date("!%X") + local muc_to = nil local muc_from = nil; local already_joined = false;
--- a/mod_muc_log_http/muc_log_http/mod_muc_log_http.lua Wed Jun 25 20:45:01 2014 +0200 +++ b/mod_muc_log_http/muc_log_http/mod_muc_log_http.lua Wed Jun 25 20:46:35 2014 +0200 @@ -66,18 +66,57 @@ return s and (s:gsub("[^a-zA-Z0-9.~_-]", function (c) return ("%%%02x"):format(c:byte()); end)); end -local function generate_room_list(component) - local rooms = ""; - local component_host = hosts[component]; - if component_host and component_host.muc ~= nil then - for jid, room in pairs(component_host.muc.rooms) do +local function get_room_from_jid(jid) + local node, host = split_jid(jid); + local component = hosts[host]; + if component then + local muc = component.modules.muc + if muc and rawget(muc,"rooms") then + -- We're running 0.9.x or 0.10 (old MUC API) + return muc.rooms[jid]; + elseif muc and rawget(muc,"get_room_from_jid") then + -- We're running >0.10 (new MUC API) + return muc.get_room_from_jid(jid); + else + return + end + end +end + +local function get_room_list(host) + local component = hosts[host]; + local list = {}; + if component then + local muc = component.modules.muc + if muc and rawget(muc,"rooms") then + -- We're running 0.9.x or 0.10 (old MUC API) + for _, room in pairs(muc.rooms) do + list[room.jid] = room; + end + return list; + elseif muc and rawget(muc,"each_room") then + -- We're running >0.10 (new MUC API) + for room, _ in muc.each_room() do + list[room.jid] = room; + end + return list; + end + end +end + +local function generate_room_list(host) + local rooms; + + for jid, room in pairs(get_room_list(host)) do local node = split_jid(jid); if not room._data.hidden and room._data.logging and node then - rooms = rooms .. html.rooms.bit:gsub("###ROOM###", urlencode(node)):gsub("###COMPONENT###", component); + rooms = (rooms or "") .. html.rooms.bit:gsub("###ROOM###", urlencode(node)):gsub("###COMPONENT###", host); end end - return html.rooms.body:gsub("###ROOMS_STUFF###", rooms):gsub("###COMPONENT###", component), "Chatroom logs for "..component; - end + + if rooms then + return html.rooms.body:gsub("###ROOMS_STUFF###", rooms):gsub("###COMPONENT###", host), "Chatroom logs for "..host; + end end -- Calendar stuff @@ -224,7 +263,7 @@ local topic = ""; local component = hosts[host]; - if not(component and component.muc and component.muc.rooms[bare_room_jid]) then + if not(get_room_from_jid(bare_room_jid)) then return; end @@ -232,7 +271,8 @@ attributes = lfs.attributes(path); do local found = 0; - for jid, room in pairs(component.muc.rooms) do + module:log("debug", generate_room_list(host)); + for jid, room in pairs(get_room_list(host)) do local node = split_jid(jid) if not room._data.hidden and room._data.logging and node then if found == 0 then @@ -249,7 +289,7 @@ end end - room = component.muc.rooms[bare_room_jid]; + room = get_room_from_jid(bare_room_jid); if room._data.hidden or not room._data.logging then room = nil; end @@ -611,6 +651,7 @@ local room; local node, day, more = request.url.path:match("^/"..url_base.."/+([^/]*)/*([^/]*)/*(.*)$"); + if more ~= "" then response.status_code = 404; return response:send(handle_error(response.status_code, "Unknown URL.")); @@ -625,8 +666,7 @@ return response:send(handle_error(response.status_code, "Muc Theme is not loaded.")); end - - if node then room = hosts[my_host].modules.muc.rooms[node.."@"..my_host]; end + if node then room = get_room_from_jid(node.."@"..my_host); end if node and not room then response.status_code = 404; return response:send(handle_error(response.status_code, "Room doesn't exist.")); @@ -636,7 +676,6 @@ return response:send(handle_error(response.status_code, "There're no logs for this room.")); end - if not node then -- room list for component return response:send(create_doc(generate_room_list(my_host))); elseif not day then -- room's listing
--- a/mod_statsd/mod_statsd.lua Wed Jun 25 20:45:01 2014 +0200 +++ b/mod_statsd/mod_statsd.lua Wed Jun 25 20:46:35 2014 +0200 @@ -15,22 +15,25 @@ sock:setpeername(options.hostname or "127.0.0.1", options.port or 8125) -- Metrics are namespaced by ".", and seperated by newline -function clean(s) return (s:gsub("[%.\n]", "_")) end +function clean(s) return (s:gsub("[%.:\n]", "_")) end -- A 'safer' send function to expose function send(s) return sock:send(s) end -- prefix should end in "." -local prefix = (options.prefix or ("prosody." .. clean(module.host))) .. "." +local prefix = (options.prefix or "prosody") .. "." +if not options.no_host then + prefix = prefix .. clean(module.host) .. "." +end -- Track users as they bind/unbind -- count bare sessions every time, as we have no way to tell if it's a new bare session or not module:hook("resource-bind", function(event) - send(prefix.."bare_sessions:"..iterators.count(bare_sessions).."|g") + send(prefix.."bare_sessions:"..iterators.count(pairs(bare_sessions)).."|g") send(prefix.."full_sessions:+1|g") end, 1) module:hook("resource-unbind", function(event) - send(prefix.."bare_sessions:"..iterators.count(bare_sessions).."|g") + send(prefix.."bare_sessions:"..iterators.count(pairs(bare_sessions)).."|g") send(prefix.."full_sessions:-1|g") end, 1) @@ -53,9 +56,20 @@ send(prefix..clean(room_node)..".broadcast-message:1|c") end) module:hook("muc-invite", function(event) + -- Total count send(prefix.."invite:1|c") local room_node = jid.split(event.room.jid) + -- Counts per room send(prefix..clean(room_node)..".invite:1|c") - local to_node, to_host, to_resource = jid.split(event.stanza.attr.to) - send(prefix..clean(to_node)..".invites:1|c") + -- Counts per recipient + send(prefix..clean(event.stanza.attr.to)..".invited:1|c") end) +module:hook("muc-decline", function(event) + -- Total count + send(prefix.."decline:1|c") + local room_node = jid.split(event.room.jid) + -- Counts per room + send(prefix..clean(room_node)..".decline:1|c") + -- Counts per sender + send(prefix..clean(event.incoming.attr.from)..".declined:1|c") +end)