Annotate

mod_muc_log/mod_muc_log.lua @ 54:f15108153710

Fix some muclogging -> muc_log issues I brought back in the merge
author Matthew Wild <mwild1@gmail.com>
date Sun, 18 Oct 2009 23:26:15 +0100
parent 53:5c4dd39a1e99
child 55:d9749ed44f6e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
1 -- Copyright (C) 2009 Thilo Cestonaro
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
2 --
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
3 -- This project is MIT/X11 licensed. Please see the
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
4 -- COPYING file in the source package for more information.
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
5 --
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
6 local prosody = prosody;
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
7 local splitJid = require "util.jid".split;
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
8 local bareJid = require "util.jid".bare;
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
9 local config_get = require "core.configmanager".get;
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
10 local httpserver = require "net.httpserver";
51
6a40e44a2b8a mod_muclogging: removed devel debug message stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 50
diff changeset
11 -- local dump = require "util.logger".dump;
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
12 local config = {};
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
13
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
14 --[[ LuaFileSystem
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
15 * URL: http://www.keplerproject.org/luafilesystem/index.html
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
16 * Install: luarocks install luafilesystem
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
17 * ]]
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
18 local lfs = require "lfs";
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
19
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
20 local lom = require "lxp.lom";
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
21
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
22 function validateLogFolder()
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
23 module:log("debug", "validateLogFolder; Folder: %s", tostring(config.folder));
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
24 if config.folder == nil then
52
11d1d4ff8037 mod_muclogging: renamed to mod_muc_log; s/muclogging/muc_log/
Thilo Cestonaro <thilo@cestona.ro>
parents: 51
diff changeset
25 module:log("warn", "muc_log folder isn't configured. configure it please!");
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
26 return false;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
27 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
28
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
29 -- check existance
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
30 local attributes = lfs.attributes(config.folder);
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
31 if attributes == nil then
52
11d1d4ff8037 mod_muclogging: renamed to mod_muc_log; s/muclogging/muc_log/
Thilo Cestonaro <thilo@cestona.ro>
parents: 51
diff changeset
32 module:log("warn", "muc_log folder doesn't exist. create it please!");
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
33 return false;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
34 elseif attributes.mode ~= "directory" then
52
11d1d4ff8037 mod_muclogging: renamed to mod_muc_log; s/muclogging/muc_log/
Thilo Cestonaro <thilo@cestona.ro>
parents: 51
diff changeset
35 module:log("warn", "muc_log folder isn't a folder, it's a %s. change this please!", attributes.mode);
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
36 return false;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
37 end --TODO: check for write rights!
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
38
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
39 module:log("debug", "Folder is validated and correct.")
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
40 return true;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
41 end
47
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
42
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
43 function logIfNeeded(e)
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
44 local stanza, origin = e.stanza, e.origin;
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
45 if validateLogFolder() == false then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
46 return;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
47 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
48
47
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
49 if (stanza.name == "presence") or
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
50 (stanza.name == "message" and tostring(stanza.attr.type) == "groupchat")
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
51 then
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
52 local node, host, resource = splitJid(stanza.attr.to);
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
53 if node ~= nil and host ~= nil then
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
54 local bare = node .. "@" .. host;
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
55 if prosody.hosts[host] ~= nil and prosody.hosts[host].muc ~= nil and prosody.hosts[host].muc.rooms[bare] ~= nil then
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
56 local room = prosody.hosts[host].muc.rooms[bare]
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
57 local logging = config_get(host, "core", "logging");
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
58 if logging == true then
47
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
59 local today = os.date("%y%m%d");
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
60 local now = os.date("%X")
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
61 local fn = config.folder .. "/" .. today .. "_" .. bare .. ".log";
47
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
62 local mucFrom = nil;
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
63
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
64 if stanza.name == "presence" and stanza.attr.type == nil then
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
65 mucFrom = stanza.attr.to;
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
66 else
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
67 for jid, nick in pairs(room._jid_nick) do
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
68 if jid == stanza.attr.from then
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
69 mucFrom = nick;
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
70 end
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
71 end
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
72 end
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
73
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
74 if mucFrom ~= nil then
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
75 module:log("debug", "try to open room log: %s", fn);
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
76 local f = assert(io.open(fn, "a"));
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
77 local realFrom = stanza.attr.from;
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
78 local realTo = stanza.attr.to;
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
79 stanza.attr.from = mucFrom;
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
80 stanza.attr.to = nil;
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
81 f:write("<stanza time=\"".. now .. "\">" .. tostring(stanza) .. "</stanza>\n");
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
82 stanza.attr.from = realFrom;
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
83 stanza.attr.to = realTo;
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
84 f:close()
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
85 end
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
86 end
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
87 end
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
88 end
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
89 end
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
90 return;
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
91 end
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
92
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
93 function createDoc(body)
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
94 return [[<html>
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
95 <head>
52
11d1d4ff8037 mod_muclogging: renamed to mod_muc_log; s/muclogging/muc_log/
Thilo Cestonaro <thilo@cestona.ro>
parents: 51
diff changeset
96 <title>muc_log</title>
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
97 </head>
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
98 <style type="text/css">
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
99 <!--
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
100 .timestuff {color: #AAAAAA; text-decoration: none;}
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
101 .muc_join {color: #009900; font-style: italic;}
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
102 .muc_leave {color: #009900; font-style: italic;}
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
103 .muc_kick {color: #009900; font-style: italic;}
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
104 .muc_bann {color: #009900; font-style: italic;}
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
105 .muc_name {color: #0000AA;}
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
106 //-->
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
107 </style>
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
108 <body>
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
109 ]] .. tostring(body) .. [[
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
110 </body>
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
111 </html>]];
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
112 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
113
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
114 function splitQuery(query)
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
115 local ret = {};
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
116 if query == nil then return ret; end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
117 local last = 1;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
118 local idx = query:find("&", last);
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
119 while idx ~= nil do
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
120 ret[#ret + 1] = query:sub(last, idx - 1);
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
121 last = idx + 1;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
122 idx = query:find("&", last);
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
123 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
124 ret[#ret + 1] = query:sub(last);
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
125 return ret;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
126 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
127
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
128 function grepRoomJid(url)
52
11d1d4ff8037 mod_muclogging: renamed to mod_muc_log; s/muclogging/muc_log/
Thilo Cestonaro <thilo@cestona.ro>
parents: 51
diff changeset
129 local tmp = url:sub(string.len("/muc_log/") + 1);
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
130 local node = nil;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
131 local host = nil;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
132 local at = nil;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
133 local slash = nil;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
134
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
135 at = tmp:find("@");
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
136 slash = tmp:find("/");
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
137 if slash ~= nil then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
138 slash = slash - 1;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
139 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
140
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
141 if at ~= nil then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
142 node = tmp:sub(1, at - 1);
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
143 host = tmp:sub(at + 1, slash);
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
144 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
145 return node, host;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
146 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
147
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
148 local function generateRoomListSiteContent()
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
149 local ret = "<h2>Rooms hosted on this server:</h2><hr /><p>";
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
150 for host, config in pairs(prosody.hosts) do
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
151 if prosody.hosts[host].muc ~= nil then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
152 local logging = config_get(host, "core", "logging");
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
153 if logging then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
154 for jid, room in pairs(prosody.hosts[host].muc.rooms) do
52
11d1d4ff8037 mod_muclogging: renamed to mod_muc_log; s/muclogging/muc_log/
Thilo Cestonaro <thilo@cestona.ro>
parents: 51
diff changeset
155 ret = ret .. "<a href=\"/muc_log/" .. jid .. "/\">" .. jid .."</a><br />\n";
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
156 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
157 else
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
158 module:log("debug", "logging not enabled for muc component: %s", tostring(host));
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
159 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
160 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
161 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
162 return ret .. "</p><hr />";
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
163 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
164
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
165 local function generateDayListSiteContentByRoom(bareRoomJid)
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
166 local ret = "";
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
167
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
168 for file in lfs.dir(config.folder) do
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
169 local year, month, day = file:match("^(%d%d)(%d%d)(%d%d)_" .. bareRoomJid .. ".log");
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
170 module:log("debug", "year: %s, month: %s, day: %s", year, month, day);
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
171 if year ~= nil and month ~= nil and day ~= nil and
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
172 year ~= "" and month ~= "" and day ~= ""
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
173 then
52
11d1d4ff8037 mod_muclogging: renamed to mod_muc_log; s/muclogging/muc_log/
Thilo Cestonaro <thilo@cestona.ro>
parents: 51
diff changeset
174 ret = "<a href=\"/muc_log/" .. bareRoomJid .. "/?year=" .. year .. "&month=" .. month .. "&day=" .. day .. "\">20" .. year .. "/" .. month .. "/" .. day .. "</a><br />\n" .. ret;
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
175 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
176 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
177 if ret ~= "" then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
178 return "<h2>available logged days of room: " .. bareRoomJid .. "</h2><hr /><p>" .. ret .. "</p><hr />";
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
179 else
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
180 return generateRoomListSiteContent(); -- fallback
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
181 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
182 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
183
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
184 local function parseDay(bareRoomJid, query)
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
185 local ret = "";
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
186 local year;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
187 local month;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
188 local day;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
189
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
190 for _,str in ipairs(query) do
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
191 local name, value;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
192 name, value = str:match("^(%a+)=(%d+)$");
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
193 if name == "year" then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
194 year = value;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
195 elseif name == "month" then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
196 month = value;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
197 elseif name == "day" then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
198 day = value;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
199 else
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
200 log("warn", "unknown query value");
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
201 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
202 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
203
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
204 if year ~= nil and month ~= nil and day ~= nil then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
205 local file = config.folder .. "/" .. year .. month .. day .. "_" .. bareRoomJid .. ".log";
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
206 local f, err = io.open(file, "r");
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
207 if f ~= nil then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
208 local content = f:read("*a");
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
209 local parsed = lom.parse("<xml>" .. content .. "</xml>");
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
210 if parsed ~= nil then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
211 for _,stanza in ipairs(parsed) do
51
6a40e44a2b8a mod_muclogging: removed devel debug message stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 50
diff changeset
212 -- module:log("debug", "dump of stanza: \n%s", dump(stanza))
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
213 if stanza.attr ~= nil and stanza.attr.time ~= nil then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
214 ret = ret .. "<a name=\"" .. stanza.attr.time .. "\" href=\"#" .. stanza.attr.time .. "\" class=\"timestuff\">[" .. stanza.attr.time .. "]</a> ";
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
215 if stanza[1] ~= nil then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
216 local nick;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
217 if stanza[1].attr.from ~= nil then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
218 nick = stanza[1].attr.from:match("/(.+)$");
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
219 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
220 if stanza[1].tag == "presence" and nick ~= nil then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
221 if stanza[1].attr.type == nil then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
222 ret = ret .. "<font class=\"muc_join\"> *** " .. nick .. " joins the room</font><br />\n";
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
223 elseif stanza[1].attr.type ~= nil and stanza[1].attr.type == "unavailable" then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
224 ret = ret .. "<font class=\"muc_leave\"> *** " .. nick .. " leaves the room</font><br />\n";
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
225 else
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
226 ret = ret .. "<font class=\"muc_leave\"> *** " .. nick .. " changed his/her status to: " .. stanza[1].attr.type .. "</font><br />\n";
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
227 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
228 elseif stanza[1].tag == "message" then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
229 local body;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
230 for _,tag in ipairs(stanza[1]) do
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
231 if tag.tag == "body" then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
232 body = tag[1]:gsub("\n", "<br />\n");
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
233 if nick ~= nil then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
234 break;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
235 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
236 elseif tag.tag == "nick" and nick == nil then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
237 nick = tag[1];
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
238 if body ~= nil then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
239 break;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
240 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
241 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
242 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
243 if nick ~= nil and body ~= nil then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
244 ret = ret .. "<font class=\"muc_name\">&lt;" .. nick .. "&gt;</font> " .. body .. "<br />\n";
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
245 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
246 else
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
247 module:log("info", "unknown stanza subtag in log found. room: %s; day: %s", bareRoomJid, year .. "/" .. month .. "/" .. day);
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
248 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
249 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
250 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
251 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
252 else
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
253 module:log("warn", "could not parse room log. room: %s; day: %s", bareRoomJid, year .. "/" .. month .. "/" .. day);
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
254 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
255 f:close();
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
256 else
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
257 ret = err;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
258 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
259 return "<h2>room " .. bareRoomJid .. " logging of 20" .. year .. "/" .. month .. "/" .. day .. "</h2><hr /><p>" .. ret .. "</p><hr />";
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
260 else
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
261 return generateDayListSiteContentByRoom(bareRoomJid); -- fallback
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
262 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
263 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
264
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
265 function handle_request(method, body, request)
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
266 module:log("debug", "method: %s, body: %s, request: %s", tostring(method), tostring(body), tostring(request));
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
267 -- module:log("debug", "dump of request:\n%s\n", dump(request));
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
268 local query = splitQuery(request.url.query);
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
269 local node, host = grepRoomJid(request.url.path);
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
270
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
271 if validateLogFolder() == false then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
272 return createDoc([[
54
f15108153710 Fix some muclogging -> muc_log issues I brought back in the merge
Matthew Wild <mwild1@gmail.com>
parents: 53
diff changeset
273 MUC logging is not configured correctly. Add a section to Host * "muc_log" and configure the value for the logging "folder".<br />
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
274 Like:<br />
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
275 Host "*"<br />
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
276 ....<br />
52
11d1d4ff8037 mod_muclogging: renamed to mod_muc_log; s/muclogging/muc_log/
Thilo Cestonaro <thilo@cestona.ro>
parents: 51
diff changeset
277 &nbsp;&nbsp;&nbsp;&nbsp;muc_log = {<br />
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
278 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;folder = "/opt/local/var/log/prosody/rooms";<br />
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
279 &nbsp;&nbsp;&nbsp;&nbsp;}<br />
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
280 ]]);
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
281 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
282 if node ~= nil and host ~= nil then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
283 local bare = node .. "@" .. host;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
284 if prosody.hosts[host] ~= nil and prosody.hosts[host].muc ~= nil and prosody.hosts[host].muc.rooms[bare] ~= nil then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
285 local room = prosody.hosts[host].muc.rooms[bare];
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
286 local logging = config_get(host, "core", "logging");
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
287 if logging == true then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
288 if request.url.query == nil then
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
289 return createDoc(generateDayListSiteContentByRoom(bare));
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
290 else
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
291 return createDoc(parseDay(bare, query));
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
292 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
293 else
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
294 module:log("debug", "logging not enabled for this room: %s", bare);
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
295 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
296 else
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
297 module:log("debug", "room instance not found. bare room jid: %s", tostring(bare));
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
298 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
299 else
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
300 return createDoc(generateRoomListSiteContent());
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
301 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
302 return;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
303 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
304
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
305 function module.load()
54
f15108153710 Fix some muclogging -> muc_log issues I brought back in the merge
Matthew Wild <mwild1@gmail.com>
parents: 53
diff changeset
306 config = config_get("*", "core", "muc_log");
f15108153710 Fix some muclogging -> muc_log issues I brought back in the merge
Matthew Wild <mwild1@gmail.com>
parents: 53
diff changeset
307 -- module:log("debug", "muc_log config: \n%s", dump(config));
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
308
53
5c4dd39a1e99 mod_muc_log: Use new httpserver.new_from_config syntax
Matthew Wild <mwild1@gmail.com>
parents: 52
diff changeset
309 httpserver.new_from_config({ config.http_port or true }, handle_request, { base = "muc_log" });
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
310 return validateLogFolder();
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
311 end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
312
47
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
313 module:hook("pre-message/bare", logIfNeeded, 500);
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
314 module:hook("pre-presence/full", logIfNeeded, 500);