mod_muc_log/mod_muc_log.lua
author Thilo Cestonaro <thilo@cestona.ro>
Tue, 10 Nov 2009 22:53:12 +0100
changeset 90 d6521ebea967
parent 89 24c734c09982
child 94 941fd7d8b9b2
permissions -rw-r--r--
mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
     7
local tabSort = table.sort;
47
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
     8
local splitJid = require "util.jid".split;
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
     9
local bareJid = require "util.jid".bare;
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    10
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
    11
local httpserver = require "net.httpserver";
56
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
    12
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
    13
local datamanager = require "util.datamanager";
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
    14
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
    15
local datastore = "muc_log";
88
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
    16
local muc_hosts = {};
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
    17
local config = nil;
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>
87
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
    38
<script type="text/javascript"><!--
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
    39
function showHide(name) {
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
    40
	var eles = document.getElementsByName(name);
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
    41
	for (var i = 0; i < eles.length; i++) {
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
    42
		eles[i].style.display = eles[i].style.display != "none" ? "none" : "";
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
    43
	}
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
    44
	
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
    45
}
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
    46
--></script>
56
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
    47
<style type="text/css">
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
    48
<!--
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
    49
.timestuff {color: #AAAAAA; text-decoration: none;}
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
    50
.muc_join {color: #009900; font-style: italic;}
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
    51
.muc_leave {color: #009900; font-style: italic;}
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
    52
.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
    53
.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
    54
.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
    55
.muc_kick {color: #009900; font-style: italic;}
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
    56
.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
    57
.muc_msg_nick {color: #0000AA;}
56
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
    58
//-->
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
    59
</style>
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
    60
<body>
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
    61
###BODY_STUFF###
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
    62
</body>
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
    63
</html>]];
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
    64
88
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
    65
html.components = {};
89
24c734c09982 mod_muc_log: Changed absolute URL paths to be relative.
Waqas Hussain <waqas20@gmail.com>
parents: 88
diff changeset
    66
html.components.bit = [[<a href="###COMPONENT###/">###COMPONENT###</a><br />]]
88
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
    67
html.components.body = [[<h2>MUC hosts available on this server:</h2><hr /><p>
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
    68
###COMPONENTS_STUFF###
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
    69
</p><hr />]];
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
    70
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
    71
html.rooms = {};
89
24c734c09982 mod_muc_log: Changed absolute URL paths to be relative.
Waqas Hussain <waqas20@gmail.com>
parents: 88
diff changeset
    72
html.rooms.bit = [[<a href="###ROOM###/">###ROOM###</a><br />]]
88
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
    73
html.rooms.body = [[<h2>Rooms hosted on MUC host: ###COMPONENT###</h2><hr /><p>
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
    74
###ROOMS_STUFF###
56
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
    75
</p><hr />]];
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
    76
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
    77
html.days = {};
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
    78
html.days.bit = [[<a href="###BARE_DAY###/">20###YEAR###/###MONTH###/###DAY###</a><br />]];
56
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
    79
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
    80
###DAYS_STUFF###
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
    81
</p><hr />]];
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
    82
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
    83
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
    84
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
    85
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
    86
html.day.presence = {};
87
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
    87
html.day.presence.join = [[<div name="joinLeave" style="display: ###SHOWHIDE###;">###TIME_STUFF###<font class="muc_join"> *** ###NICK### joins the room</font><br /></div>]];
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
    88
html.day.presence.leave = [[<div name="joinLeave" style="display: ###SHOWHIDE###;">###TIME_STUFF###<font class="muc_leave"> *** ###NICK### leaves the room</font><br /></div>]];
59
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
    89
html.day.presence.statusText = [[ and his status message is "###STATUS###"]];
87
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
    90
html.day.presence.statusChange = [[<div name="status" style="display: ###SHOWHIDE###;">###TIME_STUFF###<font class="muc_statusChange"> *** ###NICK### shows now as "###SHOW###"###STATUS_STUFF###</font><br /></div>]];
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
    91
html.day.message = [[###TIME_STUFF###<font class="muc_msg_nick">&lt;###NICK###&gt;</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
    92
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
    93
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
    94
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
    95
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
    96
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
    97
<p>###TITLE_STUFF###</p>
87
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
    98
<input type="checkbox" onclick="showHide('joinLeave')" ###JOIN_CHECKED###/>show/hide joins and Leaves</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
    99
<input type="checkbox" onclick="showHide('status')" ###STATUS_CHECKED###/>show/hide status changes</button>
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
   100
<hr /><div id="main" style="overflow: scroll;">
56
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   101
###DAY_STUFF###
87
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
   102
</div><hr />
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
   103
<script><!--
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   104
var ele = document.getElementById("main");
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   105
ele.style.height = window.innerHeight - ele.offsetTop - 25;
87
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
   106
--></script>]];
56
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   107
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   108
html.help = [[
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   109
MUC logging is not configured correctly.<br />
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   110
Here is a example config:<br />
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   111
Component "rooms.example.com" "muc"<br />
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   112
&nbsp;&nbsp;modules_enabled = {<br />
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   113
&nbsp;&nbsp;&nbsp;&nbsp;"muc_log";<br />
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   114
&nbsp;&nbsp;}<br />
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   115
&nbsp;&nbsp;muc_log = {<br />
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   116
&nbsp;&nbsp;&nbsp;&nbsp;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
   117
&nbsp;&nbsp;&nbsp;&nbsp;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
   118
&nbsp;&nbsp;}<br />
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   119
]];
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   120
62
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   121
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
   122
	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
   123
	path = path:gsub("/[^/]*$", "");
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   124
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   125
	-- check existance
85
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   126
	local attributes, err = lfs.attributes(path);
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   127
	if attributes == nil or attributes.mode ~= "directory" then
62
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   128
		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
   129
		return false;
62
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   130
	end
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   131
	
85
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   132
	attributes, err = lfs.attributes(path .. "/" .. today);
62
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   133
	if attributes == nil then
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   134
		return lfs.mkdir(path .. "/" .. today);
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   135
	elseif attributes.mode == "directory" then
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   136
		return true;
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   137
	end
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   138
	return false;
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   139
end
47
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   140
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   141
function logIfNeeded(e)
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   142
	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
   143
	
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
   144
	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
   145
		(stanza.name == "iq") or
55
d9749ed44f6e mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents: 54
diff changeset
   146
	   	(stanza.name == "message" and tostring(stanza.attr.type) == "groupchat")
47
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   147
	then
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   148
		local node, host, resource = splitJid(stanza.attr.to);
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   149
		if node ~= nil and host ~= nil then
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   150
			local bare = node .. "@" .. host;
88
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   151
			if muc_hosts[host] and prosody.hosts[host] ~= nil and prosody.hosts[host].muc ~= nil and prosody.hosts[host].muc.rooms[bare] ~= nil then
47
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   152
				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
   153
				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
   154
				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
   155
				local mucTo = nil
55
d9749ed44f6e mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents: 54
diff changeset
   156
				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
   157
				local alreadyJoined = false;
85
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   158
				
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   159
				if room._data.hidden then -- do not log any data of private rooms
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   160
					return;
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   161
				end
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   162
				
55
d9749ed44f6e mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents: 54
diff changeset
   163
				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
   164
					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
   165
					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
   166
						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
   167
						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
   168
					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
   169
				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
   170
					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
   171
						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
   172
						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
   173
							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
   174
							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
   175
								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
   176
									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
   177
									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
   178
								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
   179
							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
   180
						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
   181
					end
55
d9749ed44f6e mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents: 54
diff changeset
   182
				else
d9749ed44f6e mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents: 54
diff changeset
   183
					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
   184
						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
   185
							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
   186
							break;
47
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   187
						end
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   188
					end
55
d9749ed44f6e mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents: 54
diff changeset
   189
				end
47
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   190
62
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   191
				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
   192
					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
   193
					local realFrom = stanza.attr.from;
d9749ed44f6e mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents: 54
diff changeset
   194
					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
   195
					
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   196
					if data == nil then
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   197
						data = {};
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   198
					end
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   199
					
55
d9749ed44f6e mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents: 54
diff changeset
   200
					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
   201
					stanza.attr.to = mucTo;
62
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   202
					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
   203
					stanza.attr.from = realFrom;
d9749ed44f6e mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents: 54
diff changeset
   204
					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
   205
					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
   206
						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
   207
							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
   208
						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
   209
							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
   210
								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
   211
									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
   212
									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
   213
								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
   214
							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
   215
						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
   216
					end
62
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   217
					data_store(node, host, datastore .. "/" .. today, data);
47
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   218
				end
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   219
			end
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   220
		end
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   221
	end
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   222
	return;
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   223
end
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   224
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   225
function createDoc(body)
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   226
	return html.doc:gsub("###BODY_STUFF###", body or "");
56
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   227
end
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   228
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   229
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
   230
	t = t:gsub("<", "&lt;");
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
   231
	t = t:gsub(">", "&gt;");
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
   232
	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
   233
	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
   234
	-- TODO do any html escaping stuff ... 
56
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   235
	return t;
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   236
end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   237
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   238
function splitUrl(url)
52
11d1d4ff8037 mod_muclogging: renamed to mod_muc_log; s/muclogging/muc_log/
Thilo Cestonaro <thilo@cestona.ro>
parents: 51
diff changeset
   239
	local tmp = url:sub(string.len("/muc_log/") + 1);
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   240
	local day = nil;
88
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   241
	local room = nil;
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   242
	local component = nil;
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   243
	local at = nil;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   244
	local slash = nil;
88
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   245
	local slash2 = nil;
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   246
	
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   247
	slash = tmp:find("/");
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   248
	if slash then
88
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   249
	 	component = tmp:sub(1, slash - 1);
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   250
		if tmp:len() > slash then
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   251
			room = tmp:sub(slash + 1);
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   252
			slash = room:find("/");
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   253
			if slash then
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   254
				tmp = room;
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   255
				room = tmp:sub(1, slash - 1);
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   256
				if tmp:len() > slash then
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   257
					day = tmp:sub(slash + 1);
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   258
					slash = day:find("/");
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   259
					if slash then
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   260
						day = day:sub(1, slash - 1);
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   261
					end
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   262
				end
88
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   263
			end
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   264
		end
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   265
	end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   266
	
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   267
	return room, component, day;
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   268
end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   269
88
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   270
local function generateComponentListSiteContent()
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   271
	local components = "";
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   272
	for component,muc_host in pairs(muc_hosts) do
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   273
		components = components .. html.components.bit:gsub("###COMPONENT###", component);
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   274
	end
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   275
	
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   276
	return html.components.body:gsub("###COMPONENTS_STUFF###", components);
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   277
end
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   278
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   279
local function generateRoomListSiteContent(component)
56
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   280
	local rooms = "";
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   281
	if prosody.hosts[component] and prosody.hosts[component].muc ~= nil then
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   282
		for jid, room in pairs(prosody.hosts[component].muc.rooms) do
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   283
			local node = splitJid(jid);
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   284
			if not room._data.hidden and node then
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   285
				rooms = rooms .. html.rooms.bit:gsub("###ROOM###", node):gsub("###COMPONENT###", component);
50
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
		end
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   288
		return html.rooms.body:gsub("###ROOMS_STUFF###", rooms):gsub("###COMPONENT###", component);
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   289
	end
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   290
	return generateComponentListSiteContent(); -- fallback
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   291
end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   292
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   293
local function generateDayListSiteContentByRoom(bareRoomJid)
56
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   294
	local days = "";
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   295
	local arrDays = {};
56
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   296
	local tmp;
62
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   297
	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
   298
	local path = data_getpath(node, host, datastore);
85
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   299
	local room = nil;
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   300
	local attributes = nil;
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   301
	
62
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   302
	path = path:gsub("/[^/]*$", "");
85
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   303
	attributes = lfs.attributes(path);
88
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   304
	if muc_hosts[host] and prosody.hosts[host] ~= nil and prosody.hosts[host].muc ~= nil and prosody.hosts[host].muc.rooms[bareRoomJid] ~= nil then
85
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   305
		room = prosody.hosts[host].muc.rooms[bareRoomJid];
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   306
		if room._data.hidden then
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   307
			room = nil
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   308
		end
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   309
	end
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   310
	if attributes ~= nil and room ~= nil then
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   311
		for file in lfs.dir(path) do
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   312
			local year, month, day = file:match("^(%d%d)(%d%d)(%d%d)");
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   313
			if	year ~= nil and month ~= nil and day ~= nil and
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   314
				year ~= ""  and month ~= ""  and day ~= ""
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   315
			then
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   316
					arrDays[#arrDays + 1] = {bare=file, year=year, month=month, day=day};
85
83494de806a4 mod_muc_log: Do not log other muc-component's rooms then the module was loaded for. Do neither log nor provide access to possible existing log if a room is private. (thx flo for spotting this)
Thilo Cestonaro <thilo@cestona.ro>
parents: 81
diff changeset
   317
			end
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   318
		end
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   319
		tabSort(arrDays, function(a,b) 
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   320
			return a.bare < b.bare;
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   321
		end);
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   322
		for _, date in pairs(arrDays) do
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   323
			tmp = html.days.bit;
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   324
			tmp = tmp:gsub("###ROOM###", node):gsub("###COMPONENT###", host);
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   325
			tmp = tmp:gsub("###BARE_DAY###", date.bare);
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   326
			tmp = tmp:gsub("###YEAR###", date.year):gsub("###MONTH###", date.month):gsub("###DAY###", date.day);
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   327
			days = tmp .. days;
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   328
		end
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   329
	end
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   330
	
56
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   331
	if days ~= "" then
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   332
		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
   333
		return tmp:gsub("###JID###", bareRoomJid);
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   334
	else
88
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   335
		return generateRoomListSiteContent(host); -- fallback
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   336
	end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   337
end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   338
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
   339
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
   340
	local text = nil;
86
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   341
	local victim = nil;
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   342
	if(stanza.attr.type == "set") then
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   343
		for _,tag in ipairs(stanza) do
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   344
			if tag.tag == "query" then
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   345
				for _,item in ipairs(tag) do
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   346
					if item.tag == "item" and item.attr.nick ~= nil and tostring(item.attr.role) == 'none' then
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   347
						victim = item.attr.nick;
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   348
						for _,reason in ipairs(item) do
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   349
							if reason.tag == "reason" then
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   350
								text = reason[1];
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   351
								break;
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   352
							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
   353
						end
86
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   354
						break;
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   355
					end 
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   356
				end
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   357
				break;
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
   358
			end
86
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   359
		end
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   360
		if victim ~= nil then
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   361
			if text ~= nil then	
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   362
				text = html.day.reason:gsub("###REASON###", htmlEscape(text));
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   363
			else
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   364
				text = "";
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   365
			end	
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   366
			return html.day.kick:gsub("###TIME_STUFF###", timeStuff):gsub("###VICTIM###", victim):gsub("###REASON_STUFF###", text);
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
   367
		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
   368
	end
86
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   369
	return;
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
   370
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
   371
59
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   372
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
   373
	local ret = "";
87
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
   374
	local showJoin = "block"
88
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   375
	
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   376
	if config and not config.showJoin then
87
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
   377
		showJoin = "none";
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
   378
	end
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
   379
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
   380
	if stanza.attr.type == nil then
87
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
   381
		local showStatus = "block"
88
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   382
		if config and not config.showStatus then
87
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
   383
			showStatus = "none";
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
   384
		end
59
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   385
		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
   386
		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
   387
		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
   388
			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
   389
				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
   390
			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
   391
				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
   392
			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
   393
				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
   394
			end
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   395
		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
   396
		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
   397
			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
   398
				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
   399
			end
59
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   400
			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
   401
			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
   402
				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
   403
			end
87
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
   404
			ret = ret:gsub("###SHOW###", show):gsub("###NICK###", nick):gsub("###SHOWHIDE###", showStatus):gsub("###STATUS_STUFF###", status);
59
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   405
		else
87
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
   406
			ret = html.day.presence.join:gsub("###TIME_STUFF###", timeStuff):gsub("###SHOWHIDE###", showJoin):gsub("###NICK###", nick);
59
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   407
		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
   408
	elseif stanza.attr.type ~= nil and stanza.attr.type == "unavailable" then
87
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
   409
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
   410
		ret = html.day.presence.leave:gsub("###TIME_STUFF###", timeStuff):gsub("###SHOWHIDE###", showJoin):gsub("###NICK###", nick);
59
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   411
	end
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   412
	return ret;
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   413
end
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   414
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   415
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
   416
	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
   417
	
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
   418
	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
   419
		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
   420
			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
   421
			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
   422
				break;
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   423
			end
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   424
		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
   425
			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
   426
			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
   427
				break;
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   428
			end
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   429
		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
   430
			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
   431
			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
   432
				break;
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   433
			end
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   434
		end
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   435
	end
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   436
	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
   437
		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
   438
		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
   439
	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
   440
		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
   441
		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
   442
	end
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   443
	return ret;
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   444
end
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   445
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   446
local function parseDay(bareRoomJid, roomSubject, bare_day)
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   447
	local ret = "";
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   448
	local year;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   449
	local month;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   450
	local day;
56
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   451
	local tmp;
62
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   452
	local node, host, resource = splitJid(bareRoomJid);
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   453
	local year, month, day = bare_day: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
   454
	
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   455
	if bare_day ~= nil then
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   456
		local data = data_load(node, host, datastore .. "/" .. bare_day);
62
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   457
		if data ~= nil then
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   458
			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
   459
				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
   460
				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
   461
					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
   462
					if stanza[1] ~= nil then
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   463
						local nick;
86
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   464
						local tmp;
62
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   465
						
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   466
						-- grep nick from "from" resource
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   467
						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
   468
							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
   469
						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
   470
							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
   471
						end
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   472
						
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   473
						if stanza[1].tag == "presence" and nick ~= nil then
86
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   474
							tmp = parsePresenceStanza(stanza[1], timeStuff, nick);
62
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   475
						elseif stanza[1].tag == "message" then
86
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   476
							tmp = parseMessageStanza(stanza[1], timeStuff, nick);
62
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   477
						elseif stanza[1].tag == "iq" then
86
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   478
							tmp = parseIqStanza(stanza[1], timeStuff, nick);
62
0dfd65bfedb0 mod_muc_log: using datamanager to store the logging.
Thilo Cestonaro <thilo@cestona.ro>
parents: 61
diff changeset
   479
						else
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   480
							module:log("info", "unknown stanza subtag in log found. room: %s; day: %s", bareRoomJid, year .. "/" .. month .. "/" .. day);
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   481
						end
86
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   482
						if tmp ~= nil then
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   483
							ret = ret .. tmp
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   484
							tmp = nil;
fc7055efd568 mod_muc_log: retrieving the room config, is not a kick of a person!! :) (thx again to flo spotting it!)
Thilo Cestonaro <thilo@cestona.ro>
parents: 85
diff changeset
   485
						end
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   486
					end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   487
				end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   488
			end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   489
		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
   490
			return generateDayListSiteContentByRoom(bareRoomJid); -- fallback
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   491
		end
59
50e3d5b87119 mod_muc_log: better presence and message parsing; react on subject changes
Thilo Cestonaro <thilo@cestona.ro>
parents: 57
diff changeset
   492
		tmp = html.day.body:gsub("###DAY_STUFF###", ret):gsub("###JID###", bareRoomJid);
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   493
		tmp = tmp:gsub("###YEAR###", year):gsub("###MONTH###", month):gsub("###DAY###", 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
   494
		tmp = tmp:gsub("###TITLE_STUFF###", html.day.title:gsub("###TITLE###", roomSubject));
87
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
   495
		tmp = tmp:gsub("###STATUS_CHECKED###", config.showStatus and "checked='checked'" or "");
0e639d081ba7 mod_muc_log: add show/hide join/leave and status changes checkboxes. Add two config values showJoin and showStatus as the default values.
Thilo Cestonaro <thilo@cestona.ro>
parents: 86
diff changeset
   496
		tmp = tmp:gsub("###JOIN_CHECKED###", config.showJoin and "checked='checked'" or "");
56
e9de45beaf5e mod_muc_log: templify the html stuff
Thilo Cestonaro <thilo@cestona.ro>
parents: 55
diff changeset
   497
		return tmp;
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   498
	else
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   499
		return generateDayListSiteContentByRoom(bareRoomJid); -- fallback
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   500
	end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   501
end
81
9ceeab822e40 mod_muc_log: revert changes of last commit (bed9a6b40f)
Thilo Cestonaro <thilo@cestona.ro>
parents: 80
diff changeset
   502
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   503
--[[
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   504
local function loggingMucComponents()
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   505
	local n = 0;
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   506
	for component,_ in pairs(muc_hosts) do
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   507
		n = n + 1;
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   508
	end
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   509
	return n;
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   510
end
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   511
]]--
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   512
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   513
function handle_request(method, body, request)
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   514
	-- local query = splitQuery(request.url.query);
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   515
	local node, host, day = splitUrl(request.url.path);
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   516
	--[[if host == nil and loggingMucComponents() == 1 then
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   517
		for component,_ in pairs(muc_hosts) do
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   518
			host = component;
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   519
			break;
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   520
		end
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   521
		module:log("debug", "host: %s", tostring(host));
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   522
	end]]--
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   523
	
88
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   524
	if node ~= nil and host ~= nil then
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   525
		local bare = node .. "@" .. host;
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   526
		if prosody.hosts[host] ~= nil and prosody.hosts[host].muc ~= nil then
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   527
			if prosody.hosts[host].muc.rooms[bare] ~= nil then
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   528
				local room = prosody.hosts[host].muc.rooms[bare];
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   529
				if day == nil then
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   530
					return createDoc(generateDayListSiteContentByRoom(bare));
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   531
				else
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   532
					local subject = ""
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   533
					if room._data ~= nil and room._data.subject ~= nil then
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   534
						subject = room._data.subject;
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   535
					end
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   536
					return createDoc(parseDay(bare, subject, day));
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   537
				end
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   538
			else
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   539
				return createDoc(generateRoomListSiteContent(host));
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   540
			end
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   541
		else
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   542
			return createDoc(generateComponentListSiteContent());
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   543
		end
88
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   544
	elseif host ~= nil then
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   545
		return createDoc(generateRoomListSiteContent(host));
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   546
	else
88
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   547
		return createDoc(generateComponentListSiteContent());
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   548
	end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   549
	return;
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   550
end
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   551
88
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   552
function module.load()
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   553
	config = config_get("*", "core", "muc_log") or {};
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   554
	if config.showStatus == nil then
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   555
		config.showStatus = true;
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   556
	end
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   557
	if config.showJoin == nil then
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   558
		config.showJoin = true;
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   559
	end
88
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   560
	httpserver.new_from_config({ config.http_port or true }, handle_request, { base = "muc_log" });
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   561
	
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   562
	for jid, host in pairs(prosody.hosts) do
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   563
		if host.muc then
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   564
			local logging = config_get(jid, "core", "logging");
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   565
			if logging then
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   566
				module:log("debug", "component: %s", tostring(jid));
88
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   567
				muc_hosts[jid] = true;
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   568
			end
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   569
		end
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   570
	end
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   571
end
55
d9749ed44f6e mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents: 54
diff changeset
   572
88
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   573
function module.unload()
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   574
	muc_hosts = nil;
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   575
end
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   576
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   577
module:add_event_hook("component-activated", function(component, config)
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   578
	if config.core.logging == true then
90
d6521ebea967 mod_muc_log: specified day is now part of the url not a query. days are sorted, newest top.
Thilo Cestonaro <thilo@cestona.ro>
parents: 89
diff changeset
   579
		module:log("debug", "component: %s", tostring(component));
88
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   580
		muc_hosts[component] = true;
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   581
	end
d8cdbebb58f2 mod_muc_log: can handle now more components and should be used as global module! HTTP Path changed to http://...../muc_log/<component>/<room>/
Thilo Cestonaro <thilo@cestona.ro>
parents: 87
diff changeset
   582
end);
50
a96d3f37d845 mod_muclogging: with http_server part for viewing
Thilo Cestonaro <thilo@cestona.ro>
parents: 47
diff changeset
   583
55
d9749ed44f6e mod_muc_log: make it recognize s2s messages/presences
Thilo Cestonaro <thilo@cestona.ro>
parents: 54
diff changeset
   584
module:hook("message/bare", logIfNeeded, 500);
47
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   585
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
   586
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
   587
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
   588
module:hook("presence/full", logIfNeeded, 500);
47
99ff520519fe mod_muclogging: initial checkin
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   589
module:hook("pre-presence/full", logIfNeeded, 500);