Software /
code /
prosody-modules
Annotate
mod_muc_log/mod_muc_log.lua @ 80:bed9a6b40fae
mod_proxy65: basic white list - access control list
author | Thilo Cestonaro <thilo@cestona.ro> |
---|---|
date | Sun, 01 Nov 2009 16:42:04 +0100 |
parent | 62:0dfd65bfedb0 |
child | 81:9ceeab822e40 |
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"; |
56
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
11 local serialize = require "util.serialization".serialize; |
62
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
12 local datamanager = require "util.datamanager"; |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
13 local data_load, data_store, data_getpath = datamanager.load, datamanager.store, datamanager.getpath; |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
14 local datastore = "muc_log"; |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
15 local config = {}; |
80
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
62
diff
changeset
|
16 local verifyAuthRequest = module:require "verifyhttpauth".verifyHttpAuthRequest; |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
62
diff
changeset
|
17 |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
18 |
56
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
19 |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
20 --[[ LuaFileSystem |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
21 * 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
|
22 * Install: luarocks install luafilesystem |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
23 * ]] |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
24 local lfs = require "lfs"; |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
25 |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
26 local lom = require "lxp.lom"; |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
27 |
56
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
28 |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
29 --[[ |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
30 * Default templates for the html output. |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
31 ]]-- |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
32 local html = {}; |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
33 html.doc = [[<html> |
57
cddcea7c091a
mod_muc_log: set content-type header; escape some html stuff in messages (>, <, \n, http://....)
Thilo Cestonaro <thilo@cestona.ro>
parents:
56
diff
changeset
|
34 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" > |
56
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
35 <head> |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
36 <title>muc_log</title> |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
37 </head> |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
38 <style type="text/css"> |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
39 <!-- |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
40 .timestuff {color: #AAAAAA; text-decoration: none;} |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
41 .muc_join {color: #009900; font-style: italic;} |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
42 .muc_leave {color: #009900; font-style: italic;} |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
43 .muc_statusChange {color: #009900; font-style: italic;} |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
44 .muc_title {color: #BBBBBB; font-size: 32px;} |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
45 .muc_titleChange {color: #009900; font-style: italic;} |
56
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
46 .muc_kick {color: #009900; font-style: italic;} |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
47 .muc_bann {color: #009900; font-style: italic;} |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
48 .muc_msg_nick {color: #0000AA;} |
56
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
49 //--> |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
50 </style> |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
51 <body> |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
52 ###BODY_STUFF### |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
53 </body> |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
54 </html>]]; |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
55 |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
56 html.hosts = {}; |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
57 html.hosts.bit = [[<a href="/muc_log/###JID###">###JID###</a><br />]] |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
58 html.hosts.body = [[<h2>Rooms hosted on this server:</h2><hr /><p> |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
59 ###HOSTS_STUFF### |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
60 </p><hr />]]; |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
61 |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
62 html.days = {}; |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
63 html.days.bit = [[<a href="/muc_log/###JID###/?year=###YEAR###&month=###MONTH###&day=###DAY###">20###YEAR###/###MONTH###/###DAY###</a><br />]]; |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
64 html.days.body = [[<h2>available logged days of room: ###JID###</h2><hr /><p> |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
65 ###DAYS_STUFF### |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
66 </p><hr />]]; |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
67 |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
68 html.day = {}; |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
69 html.day.title = [[Subject: <font class="muc_title">###TITLE###</font>]]; |
56
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
70 html.day.time = [[<a name="###TIME###" href="####TIME###" class="timestuff">[###TIME###]</a> ]]; -- the one ####TIME### need to stay! it will evaluate to e.g. #09:10:56 which is an anker then |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
71 html.day.presence = {}; |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
72 html.day.presence.join = [[###TIME_STUFF###<font class="muc_join"> *** ###NICK### joins the room</font><br />]]; |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
73 html.day.presence.leave = [[###TIME_STUFF###<font class="muc_leave"> *** ###NICK### leaves the room</font><br />]]; |
59
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
74 html.day.presence.statusText = [[ and his status message is "###STATUS###"]]; |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
75 html.day.presence.statusChange = [[###TIME_STUFF###<font class="muc_statusChange"> *** ###NICK### shows now as "###SHOW###"###STATUS_STUFF###</font><br />]]; |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
76 html.day.message = [[###TIME_STUFF###<font class="muc_msg_nick"><###NICK###></font> ###MSG###<br />]]; |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
77 html.day.titleChange = [[###TIME_STUFF###<font class="muc_titleChange"> *** ###NICK### changed the title to "###TITLE###"</font><br />]]; |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
78 html.day.reason = [[, the reason was "###REASON###"]] |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
79 html.day.kick = [[###TIME_STUFF###<font class="muc_kick"> *** ###VICTIM### got kicked###REASON_STUFF###</font><br />]]; |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
80 html.day.bann = [[###TIME_STUFF###<font class="muc_bann"> *** ###VICTIM### got banned###REASON_STUFF###</font><br />]]; |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
81 html.day.body = [[<h2>room ###JID### logging of 20###YEAR###/###MONTH###/###DAY###</h2> |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
82 <p>###TITLE_STUFF###</p> |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
83 <hr /><p> |
56
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
84 ###DAY_STUFF### |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
85 </p><hr />]]; |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
86 |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
87 html.help = [[ |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
88 MUC logging is not configured correctly.<br /> |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
89 Here is a example config:<br /> |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
90 Component "rooms.example.com" "muc"<br /> |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
91 modules_enabled = {<br /> |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
92 "muc_log";<br /> |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
93 }<br /> |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
94 muc_log = {<br /> |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
95 folder = "/opt/local/var/log/prosody/rooms";<br /> |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
96 http_port = "/opt/local/var/log/prosody/rooms";<br /> |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
97 }<br /> |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
98 ]]; |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
99 |
62
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
100 local function ensureDatastorePathExists(node, host, today) |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
101 local path = data_getpath(node, host, datastore, "dat", true); |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
102 path = path:gsub("/[^/]*$", ""); |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
103 |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
104 -- check existance |
62
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
105 local attributes = lfs.attributes(path); |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
106 if attributes.mode ~= "directory" then |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
107 module:log("warn", "muc_log folder isn't a folder: %s", path); |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
108 return false; |
62
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
109 end |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
110 |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
111 attributes = lfs.attributes(path .. "/" .. today); |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
112 if attributes == nil then |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
113 return lfs.mkdir(path .. "/" .. today); |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
114 elseif attributes.mode == "directory" then |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
115 return true; |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
116 end |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
117 return false; |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
118 end |
47
99ff520519fe
mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
119 |
99ff520519fe
mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
120 function logIfNeeded(e) |
99ff520519fe
mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
121 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
|
122 |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
123 if (stanza.name == "presence") or |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
124 (stanza.name == "iq") or |
55
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
125 (stanza.name == "message" and tostring(stanza.attr.type) == "groupchat") |
47
99ff520519fe
mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
126 then |
99ff520519fe
mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
127 local node, host, resource = splitJid(stanza.attr.to); |
99ff520519fe
mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
128 if node ~= nil and host ~= nil then |
99ff520519fe
mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
129 local bare = node .. "@" .. host; |
99ff520519fe
mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
130 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
|
131 local room = prosody.hosts[host].muc.rooms[bare] |
55
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
132 local today = os.date("%y%m%d"); |
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
133 local now = os.date("%X") |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
134 local mucTo = nil |
55
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
135 local mucFrom = nil; |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
136 local alreadyJoined = false; |
55
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
137 |
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
138 if stanza.name == "presence" and stanza.attr.type == nil then |
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
139 mucFrom = stanza.attr.to; |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
140 if room._occupants ~= nil and room._occupants[stanza.attr.to] ~= nil then -- if true, the user has already joined the room |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
141 alreadyJoined = true; |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
142 stanza:tag("alreadyJoined"):text("true"); -- we need to log the information that the user has already joined, so add this and remove after logging |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
143 end |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
144 elseif stanza.name == "iq" and stanza.attr.type == "set" then -- kick, to is the room, from is the admin, nick who is kicked is attr of iq->query->item |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
145 if stanza.tags[1] ~= nil and stanza.tags[1].name == "query" then |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
146 local tmp = stanza.tags[1]; |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
147 if tmp.tags[1] ~= nil and tmp.tags[1].name == "item" and tmp.tags[1].attr.nick ~= nil then |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
148 tmp = tmp.tags[1]; |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
149 for jid, nick in pairs(room._jid_nick) do |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
150 if nick == stanza.attr.to .. "/" .. tmp.attr.nick then |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
151 mucTo = nick; |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
152 break; |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
153 end |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
154 end |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
155 end |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
156 end |
55
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
157 else |
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
158 for jid, nick in pairs(room._jid_nick) do |
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
159 if jid == stanza.attr.from then |
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
160 mucFrom = nick; |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
161 break; |
47
99ff520519fe
mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
162 end |
99ff520519fe
mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
163 end |
55
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
164 end |
47
99ff520519fe
mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
165 |
62
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
166 if (mucFrom ~= nil or mucTo ~= nil) and ensureDatastorePathExists(node, host, today) then |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
167 local data = data_load(node, host, datastore .. "/" .. today); |
55
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
168 local realFrom = stanza.attr.from; |
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
169 local realTo = stanza.attr.to; |
62
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
170 |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
171 if data == nil then |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
172 data = {}; |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
173 end |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
174 |
55
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
175 stanza.attr.from = mucFrom; |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
176 stanza.attr.to = mucTo; |
62
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
177 data[#data + 1] = "<stanza time=\"".. now .. "\">" .. tostring(stanza) .. "</stanza>\n"; |
55
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
178 stanza.attr.from = realFrom; |
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
179 stanza.attr.to = realTo; |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
180 if alreadyJoined == true then |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
181 if stanza[#stanza].name == "alreadyJoined" then -- normaly the faked element should be the last, remove it when it is the last |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
182 stanza[#stanza] = nil; |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
183 else |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
184 for i = 1, #stanza, 1 do |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
185 if stanza[i].name == "alreadyJoined" then -- remove the faked element |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
186 stanza[i] = nil; |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
187 break; |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
188 end |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
189 end |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
190 end |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
191 end |
62
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
192 data_store(node, host, datastore .. "/" .. today, data); |
47
99ff520519fe
mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
193 end |
99ff520519fe
mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
194 end |
99ff520519fe
mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
195 end |
99ff520519fe
mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
196 end |
99ff520519fe
mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
197 return; |
99ff520519fe
mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
198 end |
99ff520519fe
mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
199 |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
200 function createDoc(body) |
56
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
201 return html.doc:gsub("###BODY_STUFF###", body); |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
202 end |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
203 |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
204 local function htmlEscape(t) |
57
cddcea7c091a
mod_muc_log: set content-type header; escape some html stuff in messages (>, <, \n, http://....)
Thilo Cestonaro <thilo@cestona.ro>
parents:
56
diff
changeset
|
205 t = t:gsub("<", "<"); |
cddcea7c091a
mod_muc_log: set content-type header; escape some html stuff in messages (>, <, \n, http://....)
Thilo Cestonaro <thilo@cestona.ro>
parents:
56
diff
changeset
|
206 t = t:gsub(">", ">"); |
cddcea7c091a
mod_muc_log: set content-type header; escape some html stuff in messages (>, <, \n, http://....)
Thilo Cestonaro <thilo@cestona.ro>
parents:
56
diff
changeset
|
207 t = t:gsub("(http://[%a%d@%.:/&%?=%-_#]+)", [[<a href="%1">%1</a>]]); |
56
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
208 t = t:gsub("\n", "<br />"); |
57
cddcea7c091a
mod_muc_log: set content-type header; escape some html stuff in messages (>, <, \n, http://....)
Thilo Cestonaro <thilo@cestona.ro>
parents:
56
diff
changeset
|
209 -- TODO do any html escaping stuff ... |
56
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
210 return t; |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
211 end |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
212 |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
213 function splitQuery(query) |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
214 local ret = {}; |
59
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
215 local name, value = nil, nil; |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
216 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
|
217 local last = 1; |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
218 local idx = query:find("&", last); |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
219 while idx ~= nil do |
59
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
220 name, value = query:sub(last, idx - 1):match("^(%a+)=(%d+)$"); |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
221 ret[name] = value; |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
222 last = idx + 1; |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
223 idx = query:find("&", last); |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
224 end |
59
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
225 name, value = query:sub(last):match("^(%a+)=(%d+)$"); |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
226 ret[name] = value; |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
227 return ret; |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
228 end |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
229 |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
230 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
|
231 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
|
232 local node = nil; |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
233 local host = nil; |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
234 local at = nil; |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
235 local slash = nil; |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
236 |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
237 at = tmp:find("@"); |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
238 slash = tmp:find("/"); |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
239 if slash ~= nil then |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
240 slash = slash - 1; |
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 |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
243 if at ~= nil then |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
244 node = tmp:sub(1, at - 1); |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
245 host = tmp:sub(at + 1, slash); |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
246 end |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
247 return node, host; |
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 |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
250 local function generateRoomListSiteContent() |
56
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
251 local rooms = ""; |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
252 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
|
253 if prosody.hosts[host].muc ~= nil then |
55
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
254 for jid, room in pairs(prosody.hosts[host].muc.rooms) do |
56
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
255 rooms = rooms .. html.hosts.bit:gsub("###JID###", jid); |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
256 end |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
257 end |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
258 end |
56
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
259 |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
260 return html.hosts.body:gsub("###HOSTS_STUFF###", rooms); |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
261 end |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
262 |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
263 local function generateDayListSiteContentByRoom(bareRoomJid) |
56
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
264 local days = ""; |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
265 local tmp; |
62
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
266 local node, host, resource = splitJid(bareRoomJid); |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
267 local path = data_getpath(node, host, datastore); |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
268 path = path:gsub("/[^/]*$", ""); |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
269 for file in lfs.dir(path) do |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
270 local year, month, day = file:match("^(%d%d)(%d%d)(%d%d)"); |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
271 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
|
272 year ~= "" and month ~= "" and day ~= "" |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
273 then |
56
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
274 tmp = html.days.bit; |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
275 tmp = tmp:gsub("###JID###", bareRoomJid); |
59
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
276 tmp = tmp:gsub("###YEAR###", year):gsub("###MONTH###", month):gsub("###DAY###", day); |
56
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
277 days = tmp .. days; |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
278 end |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
279 end |
56
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
280 if days ~= "" then |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
281 tmp = html.days.body:gsub("###DAYS_STUFF###", days); |
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
282 return tmp:gsub("###JID###", bareRoomJid); |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
283 else |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
284 return generateRoomListSiteContent(); -- fallback |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
285 end |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
286 end |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
287 |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
288 local function parseIqStanza(stanza, timeStuff, nick) |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
289 local text = nil; |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
290 for _,tag in ipairs(stanza) do |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
291 if tag.tag == "query" then |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
292 for _,item in ipairs(tag) do |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
293 if item.tag == "item" then |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
294 for _,reason in ipairs(item) do |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
295 if reason.tag == "reason" then |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
296 text = reason[1]; |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
297 break; |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
298 end |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
299 end |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
300 break; |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
301 end |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
302 end |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
303 break; |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
304 end |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
305 end |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
306 |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
307 if text ~= nil then |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
308 text = html.day.reason:gsub("###REASON###", htmlEscape(text)); |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
309 else |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
310 text = ""; |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
311 end |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
312 return html.day.kick:gsub("###TIME_STUFF###", timeStuff):gsub("###VICTIM###", nick):gsub("###REASON_STUFF###", text); |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
313 end |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
314 |
59
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
315 local function parsePresenceStanza(stanza, timeStuff, nick) |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
316 local ret = ""; |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
317 if stanza.attr.type == nil then |
59
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
318 local show, status = nil, ""; |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
319 local alreadyJoined = false; |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
320 for _, tag in ipairs(stanza) do |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
321 if tag.tag == "alreadyJoined" then |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
322 alreadyJoined = true; |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
323 elseif tag.tag == "show" then |
59
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
324 show = tag[1]; |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
325 elseif tag.tag == "status" then |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
326 status = tag[1]; |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
327 end |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
328 end |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
329 if alreadyJoined == true then |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
330 if show == nil then |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
331 show = "online"; |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
332 end |
59
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
333 ret = html.day.presence.statusChange:gsub("###TIME_STUFF###", timeStuff); |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
334 if status ~= "" then |
60
5cca708c9f11
mod_muc_log: escape nicknames and status messages too. (thx waqas for finding it; Hope you had fun :P )
Thilo Cestonaro <thilo@cestona.ro>
parents:
59
diff
changeset
|
335 status = html.day.presence.statusText:gsub("###STATUS###", htmlEscape(status)); |
59
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
336 end |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
337 ret = ret:gsub("###SHOW###", show):gsub("###NICK###", nick):gsub("###STATUS_STUFF###", status); |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
338 else |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
339 ret = html.day.presence.join:gsub("###TIME_STUFF###", timeStuff):gsub("###NICK###", nick); |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
340 end |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
341 elseif stanza.attr.type ~= nil and stanza.attr.type == "unavailable" then |
59
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
342 ret = html.day.presence.leave:gsub("###TIME_STUFF###", timeStuff):gsub("###NICK###", nick); |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
343 end |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
344 return ret; |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
345 end |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
346 |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
347 local function parseMessageStanza(stanza, timeStuff, nick) |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
348 local body, title, ret = nil, nil, ""; |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
349 |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
350 for _,tag in ipairs(stanza) do |
59
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
351 if tag.tag == "body" then |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
352 body = tag[1]; |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
353 if nick ~= nil then |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
354 break; |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
355 end |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
356 elseif tag.tag == "nick" and nick == nil then |
60
5cca708c9f11
mod_muc_log: escape nicknames and status messages too. (thx waqas for finding it; Hope you had fun :P )
Thilo Cestonaro <thilo@cestona.ro>
parents:
59
diff
changeset
|
357 nick = htmlEscape(tag[1]); |
59
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
358 if body ~= nil or title ~= nil then |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
359 break; |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
360 end |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
361 elseif tag.tag == "subject" then |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
362 title = tag[1]; |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
363 if nick ~= nil then |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
364 break; |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
365 end |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
366 end |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
367 end |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
368 if nick ~= nil and body ~= nil then |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
369 body = htmlEscape(body); |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
370 ret = html.day.message:gsub("###TIME_STUFF###", timeStuff):gsub("###NICK###", nick):gsub("###MSG###", body); |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
371 elseif nick ~= nil and title ~= nil then |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
372 title = htmlEscape(title); |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
373 ret = html.day.titleChange:gsub("###TIME_STUFF###", timeStuff):gsub("###NICK###", nick):gsub("###TITLE###", title); |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
374 end |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
375 return ret; |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
376 end |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
377 |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
378 local function parseDay(bareRoomJid, roomSubject, query) |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
379 local ret = ""; |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
380 local year; |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
381 local month; |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
382 local day; |
56
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
383 local tmp; |
62
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
384 local node, host, resource = splitJid(bareRoomJid); |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
385 |
59
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
386 if query.year ~= nil and query.month ~= nil and query.day ~= nil then |
62
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
387 local data = data_load(node, host, datastore .. "/" .. query.year .. query.month .. query.day); |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
388 if data ~= nil then |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
389 for i=1, #data, 1 do |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
390 local stanza = lom.parse(data[i]); |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
391 if stanza ~= nil and stanza.attr ~= nil and stanza.attr.time ~= nil then |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
392 local timeStuff = html.day.time:gsub("###TIME###", stanza.attr.time); |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
393 if stanza[1] ~= nil then |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
394 local nick; |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
395 |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
396 -- grep nick from "from" resource |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
397 if stanza[1].attr.from ~= nil then -- presence and messages |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
398 nick = htmlEscape(stanza[1].attr.from:match("/(.+)$")); |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
399 elseif stanza[1].attr.to ~= nil then -- iq |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
400 nick = htmlEscape(stanza[1].attr.to:match("/(.+)$")); |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
401 end |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
402 |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
403 if stanza[1].tag == "presence" and nick ~= nil then |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
404 ret = ret .. parsePresenceStanza(stanza[1], timeStuff, nick); |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
405 elseif stanza[1].tag == "message" then |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
406 ret = ret .. parseMessageStanza(stanza[1], timeStuff, nick); |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
407 elseif stanza[1].tag == "iq" then |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
408 ret = ret .. parseIqStanza(stanza[1], timeStuff, nick); |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
409 else |
0dfd65bfedb0
mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents:
61
diff
changeset
|
410 module:log("info", "unknown stanza subtag in log found. room: %s; day: %s", bareRoomJid, query.year .. "/" .. query.month .. "/" .. query.day); |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
411 end |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
412 end |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
413 end |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
414 end |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
415 else |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
416 return generateDayListSiteContentByRoom(bareRoomJid); -- fallback |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
417 end |
59
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
418 tmp = html.day.body:gsub("###DAY_STUFF###", ret):gsub("###JID###", bareRoomJid); |
50e3d5b87119
mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents:
57
diff
changeset
|
419 tmp = tmp:gsub("###YEAR###", query.year):gsub("###MONTH###", query.month):gsub("###DAY###", query.day); |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
420 tmp = tmp:gsub("###TITLE_STUFF###", html.day.title:gsub("###TITLE###", roomSubject)); |
56
e9de45beaf5e
mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
55
diff
changeset
|
421 return tmp; |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
422 else |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
423 return generateDayListSiteContentByRoom(bareRoomJid); -- fallback |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
424 end |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
425 end |
80
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
62
diff
changeset
|
426 local requests = {}; |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
427 function handle_request(method, body, request) |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
428 local query = splitQuery(request.url.query); |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
429 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
|
430 |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
431 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
|
432 local bare = node .. "@" .. host; |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
433 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
|
434 local room = prosody.hosts[host].muc.rooms[bare]; |
55
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
435 if request.url.query == nil then |
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
436 return createDoc(generateDayListSiteContentByRoom(bare)); |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
437 else |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
438 local subject = "" |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
439 if room._data ~= nil and room._data.subject ~= nil then |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
440 subject = room._data.subject; |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
441 end |
80
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
62
diff
changeset
|
442 local doc = createDoc(parseDay(bare, subject, query)); |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
62
diff
changeset
|
443 local id = "thisIsTheId"; |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
62
diff
changeset
|
444 requests[id] = request; |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
62
diff
changeset
|
445 requests[id].doc = doc; |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
62
diff
changeset
|
446 |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
62
diff
changeset
|
447 verifyAuthRequest(request.url.path .. "?" .. request.url.query, "thilo@cestona.ro", id, function (id, confirmed) |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
62
diff
changeset
|
448 if confirmed and requests[id] then |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
62
diff
changeset
|
449 requests[id].send(requests[id].doc); |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
62
diff
changeset
|
450 end |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
62
diff
changeset
|
451 end) |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
62
diff
changeset
|
452 return true; |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
453 end |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
454 else |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
455 return createDoc(generateRoomListSiteContent()); |
50
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
456 end |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
457 else |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
458 return createDoc(generateRoomListSiteContent()); |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
459 end |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
460 return; |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
461 end |
a96d3f37d845
mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents:
47
diff
changeset
|
462 |
80
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
62
diff
changeset
|
463 config = config_get(module:get_host(), "core", "muc_log") or {}; |
55
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
464 |
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
465 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
|
466 |
55
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
467 module:hook("message/bare", logIfNeeded, 500); |
47
99ff520519fe
mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
468 module:hook("pre-message/bare", logIfNeeded, 500); |
61
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
469 module:hook("iq/bare", logIfNeeded, 500); |
e609da067e9f
mod_muc_log: display room's current title; show kicked messages with and without reason
Thilo Cestonaro <thilo@cestona.ro>
parents:
60
diff
changeset
|
470 module:hook("pre-iq/bare", logIfNeeded, 500); |
55
d9749ed44f6e
mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents:
54
diff
changeset
|
471 module:hook("presence/full", logIfNeeded, 500); |
47
99ff520519fe
mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
472 module:hook("pre-presence/full", logIfNeeded, 500); |