Mercurial > prosody-modules
comparison mod_muc_log/mod_muc_log.lua @ 85:83494de806a4
mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
author | Thilo Cestonaro <thilo@cestona.ro> |
---|---|
date | Sun, 08 Nov 2009 18:35:53 +0100 |
parents | 9ceeab822e40 |
children | fc7055efd568 |
comparison
equal
deleted
inserted
replaced
84:b47216512a1d | 85:83494de806a4 |
---|---|
10 local httpserver = require "net.httpserver"; | 10 local httpserver = require "net.httpserver"; |
11 local serialize = require "util.serialization".serialize; | 11 local serialize = require "util.serialization".serialize; |
12 local datamanager = require "util.datamanager"; | 12 local datamanager = require "util.datamanager"; |
13 local data_load, data_store, data_getpath = datamanager.load, datamanager.store, datamanager.getpath; | 13 local data_load, data_store, data_getpath = datamanager.load, datamanager.store, datamanager.getpath; |
14 local datastore = "muc_log"; | 14 local datastore = "muc_log"; |
15 local muc_host = module:get_host(); | |
15 local config = {}; | 16 local config = {}; |
16 | 17 |
17 | 18 |
18 --[[ LuaFileSystem | 19 --[[ LuaFileSystem |
19 * URL: http://www.keplerproject.org/luafilesystem/index.html | 20 * URL: http://www.keplerproject.org/luafilesystem/index.html |
98 local function ensureDatastorePathExists(node, host, today) | 99 local function ensureDatastorePathExists(node, host, today) |
99 local path = data_getpath(node, host, datastore, "dat", true); | 100 local path = data_getpath(node, host, datastore, "dat", true); |
100 path = path:gsub("/[^/]*$", ""); | 101 path = path:gsub("/[^/]*$", ""); |
101 | 102 |
102 -- check existance | 103 -- check existance |
103 local attributes = lfs.attributes(path); | 104 local attributes, err = lfs.attributes(path); |
104 if attributes.mode ~= "directory" then | 105 if attributes == nil or attributes.mode ~= "directory" then |
105 module:log("warn", "muc_log folder isn't a folder: %s", path); | 106 module:log("warn", "muc_log folder isn't a folder: %s", path); |
106 return false; | 107 return false; |
107 end | 108 end |
108 | 109 |
109 attributes = lfs.attributes(path .. "/" .. today); | 110 attributes, err = lfs.attributes(path .. "/" .. today); |
110 if attributes == nil then | 111 if attributes == nil then |
111 return lfs.mkdir(path .. "/" .. today); | 112 return lfs.mkdir(path .. "/" .. today); |
112 elseif attributes.mode == "directory" then | 113 elseif attributes.mode == "directory" then |
113 return true; | 114 return true; |
114 end | 115 end |
123 (stanza.name == "message" and tostring(stanza.attr.type) == "groupchat") | 124 (stanza.name == "message" and tostring(stanza.attr.type) == "groupchat") |
124 then | 125 then |
125 local node, host, resource = splitJid(stanza.attr.to); | 126 local node, host, resource = splitJid(stanza.attr.to); |
126 if node ~= nil and host ~= nil then | 127 if node ~= nil and host ~= nil then |
127 local bare = node .. "@" .. host; | 128 local bare = node .. "@" .. host; |
128 if prosody.hosts[host] ~= nil and prosody.hosts[host].muc ~= nil and prosody.hosts[host].muc.rooms[bare] ~= nil then | 129 if host == muc_host and prosody.hosts[host] ~= nil and prosody.hosts[host].muc ~= nil and prosody.hosts[host].muc.rooms[bare] ~= nil then |
129 local room = prosody.hosts[host].muc.rooms[bare] | 130 local room = prosody.hosts[host].muc.rooms[bare] |
130 local today = os.date("%y%m%d"); | 131 local today = os.date("%y%m%d"); |
131 local now = os.date("%X") | 132 local now = os.date("%X") |
132 local mucTo = nil | 133 local mucTo = nil |
133 local mucFrom = nil; | 134 local mucFrom = nil; |
134 local alreadyJoined = false; | 135 local alreadyJoined = false; |
135 | 136 |
137 if room._data.hidden then -- do not log any data of private rooms | |
138 return; | |
139 end | |
140 | |
136 if stanza.name == "presence" and stanza.attr.type == nil then | 141 if stanza.name == "presence" and stanza.attr.type == nil then |
137 mucFrom = stanza.attr.to; | 142 mucFrom = stanza.attr.to; |
138 if room._occupants ~= nil and room._occupants[stanza.attr.to] ~= nil then -- if true, the user has already joined the room | 143 if room._occupants ~= nil and room._occupants[stanza.attr.to] ~= nil then -- if true, the user has already joined the room |
139 alreadyJoined = true; | 144 alreadyJoined = true; |
140 stanza:tag("alreadyJoined"):text("true"); -- we need to log the information that the user has already joined, so add this and remove after logging | 145 stanza:tag("alreadyJoined"):text("true"); -- we need to log the information that the user has already joined, so add this and remove after logging |
246 end | 251 end |
247 | 252 |
248 local function generateRoomListSiteContent() | 253 local function generateRoomListSiteContent() |
249 local rooms = ""; | 254 local rooms = ""; |
250 for host, config in pairs(prosody.hosts) do | 255 for host, config in pairs(prosody.hosts) do |
251 if prosody.hosts[host].muc ~= nil then | 256 if host == muc_host and prosody.hosts[host].muc ~= nil then |
252 for jid, room in pairs(prosody.hosts[host].muc.rooms) do | 257 for jid, room in pairs(prosody.hosts[host].muc.rooms) do |
253 rooms = rooms .. html.hosts.bit:gsub("###JID###", jid); | 258 if not room._data.hidden then |
259 rooms = rooms .. html.hosts.bit:gsub("###JID###", jid); | |
260 end | |
254 end | 261 end |
255 end | 262 end |
256 end | 263 end |
257 | 264 |
258 return html.hosts.body:gsub("###HOSTS_STUFF###", rooms); | 265 return html.hosts.body:gsub("###HOSTS_STUFF###", rooms); |
261 local function generateDayListSiteContentByRoom(bareRoomJid) | 268 local function generateDayListSiteContentByRoom(bareRoomJid) |
262 local days = ""; | 269 local days = ""; |
263 local tmp; | 270 local tmp; |
264 local node, host, resource = splitJid(bareRoomJid); | 271 local node, host, resource = splitJid(bareRoomJid); |
265 local path = data_getpath(node, host, datastore); | 272 local path = data_getpath(node, host, datastore); |
273 local room = nil; | |
274 local attributes = nil; | |
275 | |
266 path = path:gsub("/[^/]*$", ""); | 276 path = path:gsub("/[^/]*$", ""); |
267 for file in lfs.dir(path) do | 277 attributes = lfs.attributes(path); |
268 local year, month, day = file:match("^(%d%d)(%d%d)(%d%d)"); | 278 if host == muc_host and prosody.hosts[host] ~= nil and prosody.hosts[host].muc ~= nil and prosody.hosts[host].muc.rooms[bareRoomJid] ~= nil then |
269 if year ~= nil and month ~= nil and day ~= nil and | 279 room = prosody.hosts[host].muc.rooms[bareRoomJid]; |
270 year ~= "" and month ~= "" and day ~= "" | 280 if room._data.hidden then |
271 then | 281 room = nil |
272 tmp = html.days.bit; | 282 end |
273 tmp = tmp:gsub("###JID###", bareRoomJid); | 283 end |
274 tmp = tmp:gsub("###YEAR###", year):gsub("###MONTH###", month):gsub("###DAY###", day); | 284 if attributes ~= nil and room ~= nil then |
275 days = tmp .. days; | 285 for file in lfs.dir(path) do |
286 local year, month, day = file:match("^(%d%d)(%d%d)(%d%d)"); | |
287 if year ~= nil and month ~= nil and day ~= nil and | |
288 year ~= "" and month ~= "" and day ~= "" | |
289 then | |
290 tmp = html.days.bit; | |
291 tmp = tmp:gsub("###JID###", bareRoomJid); | |
292 tmp = tmp:gsub("###YEAR###", year):gsub("###MONTH###", month):gsub("###DAY###", day); | |
293 days = tmp .. days; | |
294 end | |
276 end | 295 end |
277 end | 296 end |
278 if days ~= "" then | 297 if days ~= "" then |
279 tmp = html.days.body:gsub("###DAYS_STUFF###", days); | 298 tmp = html.days.body:gsub("###DAYS_STUFF###", days); |
280 return tmp:gsub("###JID###", bareRoomJid); | 299 return tmp:gsub("###JID###", bareRoomJid); |