comparison mod_muc_log/mod_muc_log.lua @ 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.
author Thilo Cestonaro <thilo@cestona.ro>
date Mon, 09 Nov 2009 18:15:59 +0100
parents fc7055efd568
children d8cdbebb58f2
comparison
equal deleted inserted replaced
86:fc7055efd568 87:0e639d081ba7
32 html.doc = [[<html> 32 html.doc = [[<html>
33 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" > 33 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
34 <head> 34 <head>
35 <title>muc_log</title> 35 <title>muc_log</title>
36 </head> 36 </head>
37 <script type="text/javascript"><!--
38 function showHide(name) {
39 var eles = document.getElementsByName(name);
40 for (var i = 0; i < eles.length; i++) {
41 eles[i].style.display = eles[i].style.display != "none" ? "none" : "";
42 }
43
44 }
45 --></script>
37 <style type="text/css"> 46 <style type="text/css">
38 <!-- 47 <!--
39 .timestuff {color: #AAAAAA; text-decoration: none;} 48 .timestuff {color: #AAAAAA; text-decoration: none;}
40 .muc_join {color: #009900; font-style: italic;} 49 .muc_join {color: #009900; font-style: italic;}
41 .muc_leave {color: #009900; font-style: italic;} 50 .muc_leave {color: #009900; font-style: italic;}
66 75
67 html.day = {}; 76 html.day = {};
68 html.day.title = [[Subject: <font class="muc_title">###TITLE###</font>]]; 77 html.day.title = [[Subject: <font class="muc_title">###TITLE###</font>]];
69 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 78 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
70 html.day.presence = {}; 79 html.day.presence = {};
71 html.day.presence.join = [[###TIME_STUFF###<font class="muc_join"> *** ###NICK### joins the room</font><br />]]; 80 html.day.presence.join = [[<div name="joinLeave" style="display: ###SHOWHIDE###;">###TIME_STUFF###<font class="muc_join"> *** ###NICK### joins the room</font><br /></div>]];
72 html.day.presence.leave = [[###TIME_STUFF###<font class="muc_leave"> *** ###NICK### leaves the room</font><br />]]; 81 html.day.presence.leave = [[<div name="joinLeave" style="display: ###SHOWHIDE###;">###TIME_STUFF###<font class="muc_leave"> *** ###NICK### leaves the room</font><br /></div>]];
73 html.day.presence.statusText = [[ and his status message is "###STATUS###"]]; 82 html.day.presence.statusText = [[ and his status message is "###STATUS###"]];
74 html.day.presence.statusChange = [[###TIME_STUFF###<font class="muc_statusChange"> *** ###NICK### shows now as "###SHOW###"###STATUS_STUFF###</font><br />]]; 83 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>]];
75 html.day.message = [[###TIME_STUFF###<font class="muc_msg_nick">&lt;###NICK###&gt;</font> ###MSG###<br />]]; 84 html.day.message = [[###TIME_STUFF###<font class="muc_msg_nick">&lt;###NICK###&gt;</font> ###MSG###<br />]];
76 html.day.titleChange = [[###TIME_STUFF###<font class="muc_titleChange"> *** ###NICK### changed the title to "###TITLE###"</font><br />]]; 85 html.day.titleChange = [[###TIME_STUFF###<font class="muc_titleChange"> *** ###NICK### changed the title to "###TITLE###"</font><br />]];
77 html.day.reason = [[, the reason was "###REASON###"]] 86 html.day.reason = [[, the reason was "###REASON###"]]
78 html.day.kick = [[###TIME_STUFF###<font class="muc_kick"> *** ###VICTIM### got kicked###REASON_STUFF###</font><br />]]; 87 html.day.kick = [[###TIME_STUFF###<font class="muc_kick"> *** ###VICTIM### got kicked###REASON_STUFF###</font><br />]];
79 html.day.bann = [[###TIME_STUFF###<font class="muc_bann"> *** ###VICTIM### got banned###REASON_STUFF###</font><br />]]; 88 html.day.bann = [[###TIME_STUFF###<font class="muc_bann"> *** ###VICTIM### got banned###REASON_STUFF###</font><br />]];
80 html.day.body = [[<h2>room ###JID### logging of 20###YEAR###/###MONTH###/###DAY###</h2> 89 html.day.body = [[<h2>room ###JID### logging of 20###YEAR###/###MONTH###/###DAY###</h2>
81 <p>###TITLE_STUFF###</p> 90 <p>###TITLE_STUFF###</p>
82 <hr /><p> 91 <input type="checkbox" onclick="showHide('joinLeave')" ###JOIN_CHECKED###/>show/hide joins and Leaves</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
92 <input type="checkbox" onclick="showHide('status')" ###STATUS_CHECKED###/>show/hide status changes</button>
93 <hr /><div id="main" style="overflow: scroll;">
83 ###DAY_STUFF### 94 ###DAY_STUFF###
84 </p><hr />]]; 95 </div><hr />
96 <script><!--
97 document.getElementById("main").style.height = screen.availHeight - 300;
98 --></script>]];
85 99
86 html.help = [[ 100 html.help = [[
87 MUC logging is not configured correctly.<br /> 101 MUC logging is not configured correctly.<br />
88 Here is a example config:<br /> 102 Here is a example config:<br />
89 Component "rooms.example.com" "muc"<br /> 103 Component "rooms.example.com" "muc"<br />
335 return; 349 return;
336 end 350 end
337 351
338 local function parsePresenceStanza(stanza, timeStuff, nick) 352 local function parsePresenceStanza(stanza, timeStuff, nick)
339 local ret = ""; 353 local ret = "";
354 local showJoin = "block"
355 if not config.showJoin then
356 showJoin = "none";
357 end
358
340 if stanza.attr.type == nil then 359 if stanza.attr.type == nil then
360 local showStatus = "block"
361 if not config.showStatus then
362 showStatus = "none";
363 end
341 local show, status = nil, ""; 364 local show, status = nil, "";
342 local alreadyJoined = false; 365 local alreadyJoined = false;
343 for _, tag in ipairs(stanza) do 366 for _, tag in ipairs(stanza) do
344 if tag.tag == "alreadyJoined" then 367 if tag.tag == "alreadyJoined" then
345 alreadyJoined = true; 368 alreadyJoined = true;
355 end 378 end
356 ret = html.day.presence.statusChange:gsub("###TIME_STUFF###", timeStuff); 379 ret = html.day.presence.statusChange:gsub("###TIME_STUFF###", timeStuff);
357 if status ~= "" then 380 if status ~= "" then
358 status = html.day.presence.statusText:gsub("###STATUS###", htmlEscape(status)); 381 status = html.day.presence.statusText:gsub("###STATUS###", htmlEscape(status));
359 end 382 end
360 ret = ret:gsub("###SHOW###", show):gsub("###NICK###", nick):gsub("###STATUS_STUFF###", status); 383 ret = ret:gsub("###SHOW###", show):gsub("###NICK###", nick):gsub("###SHOWHIDE###", showStatus):gsub("###STATUS_STUFF###", status);
361 else 384 else
362 ret = html.day.presence.join:gsub("###TIME_STUFF###", timeStuff):gsub("###NICK###", nick); 385 ret = html.day.presence.join:gsub("###TIME_STUFF###", timeStuff):gsub("###SHOWHIDE###", showJoin):gsub("###NICK###", nick);
363 end 386 end
364 elseif stanza.attr.type ~= nil and stanza.attr.type == "unavailable" then 387 elseif stanza.attr.type ~= nil and stanza.attr.type == "unavailable" then
365 ret = html.day.presence.leave:gsub("###TIME_STUFF###", timeStuff):gsub("###NICK###", nick); 388
389 ret = html.day.presence.leave:gsub("###TIME_STUFF###", timeStuff):gsub("###SHOWHIDE###", showJoin):gsub("###NICK###", nick);
366 end 390 end
367 return ret; 391 return ret;
368 end 392 end
369 393
370 local function parseMessageStanza(stanza, timeStuff, nick) 394 local function parseMessageStanza(stanza, timeStuff, nick)
444 return generateDayListSiteContentByRoom(bareRoomJid); -- fallback 468 return generateDayListSiteContentByRoom(bareRoomJid); -- fallback
445 end 469 end
446 tmp = html.day.body:gsub("###DAY_STUFF###", ret):gsub("###JID###", bareRoomJid); 470 tmp = html.day.body:gsub("###DAY_STUFF###", ret):gsub("###JID###", bareRoomJid);
447 tmp = tmp:gsub("###YEAR###", query.year):gsub("###MONTH###", query.month):gsub("###DAY###", query.day); 471 tmp = tmp:gsub("###YEAR###", query.year):gsub("###MONTH###", query.month):gsub("###DAY###", query.day);
448 tmp = tmp:gsub("###TITLE_STUFF###", html.day.title:gsub("###TITLE###", roomSubject)); 472 tmp = tmp:gsub("###TITLE_STUFF###", html.day.title:gsub("###TITLE###", roomSubject));
473 tmp = tmp:gsub("###STATUS_CHECKED###", config.showStatus and "checked='checked'" or "");
474 tmp = tmp:gsub("###JOIN_CHECKED###", config.showJoin and "checked='checked'" or "");
449 return tmp; 475 return tmp;
450 else 476 else
451 return generateDayListSiteContentByRoom(bareRoomJid); -- fallback 477 return generateDayListSiteContentByRoom(bareRoomJid); -- fallback
452 end 478 end
453 end 479 end
477 end 503 end
478 return; 504 return;
479 end 505 end
480 506
481 config = config_get(module:get_host(), "core", "muc_log"); 507 config = config_get(module:get_host(), "core", "muc_log");
508 config.showStatus = config.showStatus or true;
509 config.showJoin = config.showJoin or true;
482 510
483 httpserver.new_from_config({ config.http_port or true }, handle_request, { base = "muc_log" }); 511 httpserver.new_from_config({ config.http_port or true }, handle_request, { base = "muc_log" });
484 512
485 module:hook("message/bare", logIfNeeded, 500); 513 module:hook("message/bare", logIfNeeded, 500);
486 module:hook("pre-message/bare", logIfNeeded, 500); 514 module:hook("pre-message/bare", logIfNeeded, 500);