-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_viewer.js
342 lines (296 loc) · 8.19 KB
/
log_viewer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/**
* The MIT License (http://www.opensource.org/licenses/mit-license.php)
*
* Copyright (c) 2010 Nexopia.com, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
**/
function adjust_date(date, adjustment)
{
adjusted = new Date(date);
timestamp = adjusted.getTime();
timestamp = timestamp + adjustment;
adjusted.setTime(timestamp);
return adjusted;
}
function add_filter(pattern, negate_filter, logic_filter)
{
var filter_list = document.getElementById('filter_list');
var filter_template = document.getElementById('filter_template');
if (filter_list && filter_template)
{
var new_filter = filter_template.cloneNode(true);
new_filter.id = '';
if (pattern != null)
{
for (var i = 0; i < new_filter.childNodes.length; i++)
{
if ((new_filter.childNodes[i].tagName == 'INPUT') && (new_filter.childNodes[i].name == 'filter[]'))
{
new_filter.childNodes[i].value = pattern;
}
}
}
if (negate_filter != null)
{
for (var i = 0; i < new_filter.childNodes.length; i++)
{
if ((new_filter.childNodes[i].tagName == 'SELECT') && (new_filter.childNodes[i].name == 'negate_filter[]'))
{
for (var j = 0; j < new_filter.childNodes[i].options.length; j++)
{
if (new_filter.childNodes[i].options[j].value == negate_filter)
{
new_filter.childNodes[i].options[j].selected = 1;
}
}
}
}
}
if (logic_filter != null)
{
for (var i = 0; i < new_filter.childNodes.length; i++)
{
if ((new_filter.childNodes[i].tagName == 'SELECT') && (new_filter.childNodes[i].name == 'logic_filter[]'))
{
for (var j = 0; j < new_filter.childNodes[i].options.length; j++)
{
if (new_filter.childNodes[i].options[j].value == logic_filter)
{
new_filter.childNodes[i].options[j].selected = 1;
}
}
}
}
}
filter_list.appendChild(new_filter);
return 1;
}
return 0;
}
function clear_selection(id)
{
var select = document.getElementById(id);
if (! select)
{
return 0;
}
for (var i = 0; i < select.options.length; i++)
{
select.options[i].selected = false;
}
}
function hide_selection(e)
{
var selected_text = '';
if (window.getSelection)
{
selected_text = window.getSelection().toString();
}
else if (document.getSelection)
{
selected_text = document.getSelection().toString();
}
else if (document.selection)
{
selected_text = document.selection.createRange().text;
}
selected_text = selected_text.replace(/^\s+|\s+$/g, '');
if (selected_text.length > 0)
{
add_filter(selected_text, 1, 'AND');
}
}
function highlight_named_anchor()
{
if (window.location.hash.match(/^#\d+.\d+$/))
{
var element = document.getElementById(window.location.hash.substr(1));
if (element && element.parentNode)
{
element.parentNode.style.fontWeight = "bold";
element.parentNode.style.background = "#222222";
element.parentNode.style.border = "2px dotted white";
}
}
}
function invert_selection(id)
{
var select = document.getElementById(id);
if (! select)
{
return 0;
}
for (var i = 0; i < select.options.length; i++)
{
if (select.options[i].selected)
{
select.options[i].selected = false;
}
else
{
select.options[i].selected = true;
}
}
}
function is_visible(id)
{
var element = document.getElementById(id);
if (! element)
{
return -1;
}
if (element.style.display == 'none')
{
return 0;
}
return 1;
}
function parse_token(token)
{
if (token == null)
{
token = prompt("Please enter a log token.\nLog tokens are expected to look like this example: '10:48:53:2009-03-08:req:19525:636'.\n", "HH:MM:SS:YYYY-MM-DD:<STRING>");
}
token = token.replace(/^\s+|\s+$/g, '');
if (! token.length)
{
return false;
}
// Token Regular Expression Map:
// 10:48:53:2009-03-08:<STRING>
// HH:MM:SS:YYYY-MM-DD:<STRING>
if (! token.match(/^\d{2}:\d{2}:\d{2}:\d{4}-\d{2}-\d{2}:/))
{
alert("The log token '" + token + "' is not valid.");
return false;
}
var hour = parseInt(token.substr(0,2), 10);
var minute = parseInt(token.substr(3,2), 10);
var second = parseInt(token.substr(6,2), 10);
var year = parseInt(token.substr(9,4), 10);
var month = parseInt(token.substr(14,2), 10);
var day = parseInt(token.substr(17,2), 10);
var string = token.substr(20);
var timestamp = new Date(year, month - 1, day, hour, minute, second);
if (! set_start_time_selections(adjust_date(timestamp, -1000)))
{
alert("The log token '" + token + "' is outside of the allowed timeframe.");
return false;
}
if (! set_end_time_selections(adjust_date(timestamp, 1000)))
{
alert("The log token '" + token + "' is outside of the allowed timeframe.");
return false;
}
// Remove all filters.
var filter_list = document.getElementById('filter_list');
if (filter_list)
{
while (filter_list.hasChildNodes())
{
filter_list.removeChild(filter_list.firstChild);
}
}
// Add a single filter that consists of the token string that we are
// looking for.
add_filter(string, 0, null);
refresh_view();
}
function refresh_view()
{
var form = document.getElementById('control_form');
if (form)
{
form.onsubmit();
form.submit();
}
}
function set_end_time_selections(timestamp)
{
var r = true;
r = r && set_selection(document.getElementsByName('end_year')[0], timestamp.getFullYear());
r = r && set_selection(document.getElementsByName('end_month')[0], timestamp.getMonth() + 1);
r = r && set_selection(document.getElementsByName('end_day')[0], timestamp.getDate());
r = r && set_selection(document.getElementsByName('end_hour')[0], timestamp.getHours());
r = r && set_selection(document.getElementsByName('end_minute')[0], timestamp.getMinutes());
r = r && set_selection(document.getElementsByName('end_second')[0], timestamp.getSeconds());
return r;
}
function set_selection(select, value)
{
for (var i = 0; i < select.options.length; i++)
{
if (typeof(value) == 'number')
{
if (parseInt(select.options[i].value, 10) == value)
{
select.selectedIndex = i;
return true;
}
}
else
{
if (select.options[i].value == value)
{
select.selectedIndex = i;
return true;
}
}
}
return false;
}
function set_start_time_selections(timestamp)
{
var r = true;
r = r && set_selection(document.getElementsByName('start_year')[0], timestamp.getFullYear());
r = r && set_selection(document.getElementsByName('start_month')[0], timestamp.getMonth() + 1);
r = r && set_selection(document.getElementsByName('start_day')[0], timestamp.getDate());
r = r && set_selection(document.getElementsByName('start_hour')[0], timestamp.getHours());
r = r && set_selection(document.getElementsByName('start_minute')[0], timestamp.getMinutes());
r = r && set_selection(document.getElementsByName('start_second')[0], timestamp.getSeconds());
return r;
}
function tail()
{
var form = document.getElementById('control_form');
var timestamp = new Date();
set_start_time_selections(adjust_date(timestamp, -60000));
set_end_time_selections(timestamp);
if (form)
{
form.action = form.action + '#tail';
}
refresh_view();
}
function toggle_display(id)
{
var element = document.getElementById(id);
if (! element)
{
return -1;
}
if (element.style.display == 'none')
{
element.style.display = '';
return 1;
}
element.style.display = 'none';
return 0;
}