local st = require "util.stanza"; local datetime = require"util.datetime"; local jid_split = require"util.jid".split; local nodeprep = require"util.encodings".stringprep.nodeprep; local uuid = require"util.uuid".generate; local it = require"util.iterators"; local gettime = require"socket".gettime; local archive = module:open_store("archive2", "archive"); -- Support both old and new MUC code local mod_muc = module:depends"muc"; local rooms = rawget(mod_muc, "rooms"); local each_room = rawget(mod_muc, "each_room") or function() return it.values(rooms); end; local new_muc = not rooms; if new_muc then rooms = module:shared"muc/rooms"; end local get_room_from_jid = rawget(mod_muc, "get_room_from_jid") or function (jid) return rooms[jid]; end local function get_room(name) local jid = name .. '@' .. module.host; return get_room_from_jid(jid); end module:depends"http"; local function template(data) --[[ DOC Like util.template, but deals with plain text Returns a closure that is called with a table of values {name} is substituted for values["name"] and is XML escaped {name!} is substituted without XML escaping {name?} is optional and is replaced with an empty string if no value exists ]] return function(values) return (data:gsub("{([^!}]-)(%p?)}", function (name, opt) local value = values[name]; if value then if opt ~= "!" then return st.xml_escape(value); end return value; elseif opt == "?" then return ""; end end)); end end -- TODO Move templates into files local base = template(template[[ {title}

{title}

{header!}

{body!}

]] { prosody_version = prosody.version }); local dates_template = template(base{ title = "Logs for room {room}"; header = [[ ]]; body = [[ ]]; footer = ""; }) local date_line_template = template[[
  • {date}
  • ]]; local page_template = template(base{ title = "Logs for room {room} on {date}"; header = [[ ]]; body = [[
      {logs!}
    ]]; footer = [[ ]]; }); local line_template = template[[
  • {nick} {verb?} {body?}
  • ]]; local room_list_template = template(base{ title = "Rooms on {host}"; header = ""; body = [[
    {rooms!}
    ]]; footer = ""; }); local room_item_template = template[[
    {name}
    {description?}
    ]]; local function public_room(room) if type(room) == "string" then room = get_room(room); end return room and not room:get_hidden() and not room:get_members_only() and room._data.logging ~= false; end -- FIXME Invent some more efficient API for this local function dates_page(event, path) local request, response = event.request, event.response; local room = nodeprep(path:match("^(.*)/$")); if not room or not public_room(room) then return end local dates, i = {}, 1; module:log("debug", "Find all dates with messages"); local next_day; repeat local iter = archive:find(room, { ["start"] = next_day; limit = 1; with = "message