source: binary-improvements/webserver_legacy/js/log.js@ 461

Last change on this file since 461 was 320, checked in by alloc, 6 years ago

Fixed #152: XSS attacks

File size: 2.4 KB
Line 
1var lastLogLine = -1;
2
3function StartLogModule () {
4 var maxLinesPerRequest = 50;
5
6 var timeout = null;
7 var table = $("#tab_log > table");
8 var lastRead = -1;
9
10
11 var updateEvent = function() {
12 $.getJSON( "../api/getlog?firstLine=" + (lastLogLine + 1) + "&lastLine=" + (lastLogLine + maxLinesPerRequest) )
13 .done(function(data) {
14 if (data.firstLine - lastLogLine - 1 > 0) {
15 var row = $("<tr></tr>").appendTo (table);
16 $('<td colspan="4">Missed ' + (data.firstLine - lastLogLine - 1) + ' log entries</td>').addClass ("logcol_missed").appendTo (row);
17 }
18 for (var i = 0; i < data.entries.length; i++) {
19 var row = $("<tr></tr>").addClass (data.entries [i].type).attr ("id", "line" + (data.firstLine + i)).appendTo (table);
20 $("<td>" + data.entries [i].date + " " + data.entries [i].time + "</td>").addClass ("logcol_datetime").appendTo (row);
21 $("<td>" + data.entries [i].uptime + "</td>").addClass ("logcol_uptime").appendTo (row);
22 $("<td>" + data.entries [i].type + "</td>").addClass ("logcol_type").appendTo (row);
23 var msg = $("<td></td>").text(data.entries [i].msg).addClass ("logcol_msg").appendTo (row);
24 if (data.entries [i].trace.length > 0) {
25 msg.append ('<br><div class="trace"><span>' + data.entries [i].trace.replace (/\n/g, "</span><span>") + '</span></div><a class="tracebtn"></a>');
26 }
27 }
28
29 if (data.entries.length > 0) {
30 lastLogLine = data.lastLine;
31 }
32 })
33 .fail(function(jqxhr, textStatus, error) {
34 console.log("Error fetching log lines");
35 })
36 .always(function() {
37 });
38 timeout = window.setTimeout(updateEvent, 2000);
39 };
40
41 var markAsRead = function() {
42 lastRead = lastLogLine;
43 table.find (".readmark").removeClass ("readmark");
44 table.find ("#line" + (lastRead)).addClass ("readmark");
45 };
46
47 table.on ("click.action", ".tracebtn", function (event) {
48 $(this).toggleClass ("visible");
49 $(this).prev ().toggleClass ("visible");
50 });
51
52 $(".adminlog #markasread").on ("click.action", null, function (event) {
53 markAsRead ();
54 });
55
56
57 tabs.on ("tabbedcontenttabopened", function (event, data) {
58 if (data.newTab === "#tab_log") {
59 updateEvent ();
60
61 markAsRead ();
62 var markedrow = $(".adminlog .readmark");
63 if (markedrow.length > 0) {
64 window.setTimeout (function () {
65 $('html, body').scrollTop (markedrow.offset ().top);
66 }, 20);
67 }
68 } else {
69 window.clearTimeout (timeout);
70 }
71 });
72
73 if (tabs.tabbedContent ("isTabOpen", "tab_log")) {
74 updateEvent ();
75 }
76
77}
78
79
Note: See TracBrowser for help on using the repository browser.