-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcachemgr-txt.js
58 lines (50 loc) · 2.16 KB
/
cachemgr-txt.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
/*
cachemgr.js for Squid HTTP Caching Proxy
Copyright (C) 2016-2017 Amos Jeffries
based on work by Francesco Chemolli
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
Use cachmgr.CGI logic for interpreting Squid manager reports
sent in text/plain format:
- any given line can be part of three constructions:
table header, table data, or pre-formatted text
- lines beginning with multiple whitespace are equivalent to a tab (\t).
- lines containing a tab (\t) are table rows in TSV format.
*/
function render_contents_txt(data) {
var datalines=data.split("\n");
var status='text'; //one of 'text','table', 'theader'
for (var lineno in datalines) {
l=quoteEntities(datalines[lineno]);
l=l.replace(/ {2} */g,"\t"); //multiple spaces = tab
switch(status) {
case 'text':
if (l.indexOf("\t")==-1) { //no \t found
datalines[lineno]=l+"<br />"; //quoted
} else { //let's begin a table
status='table';
datalines[lineno]='<table><tbody><tr><td>'+l.replace(/\t/g,"</td><td>")+"</tr>";
}
break;
case 'table':
if (l.indexOf("\t")==-1) {
status='text';
datalines[lineno]='</tbody></table>'+l;
} else {
datalines[lineno]='<tr><td>'+l.replace(/\t/g,"</td><td>")+"</tr>";
}
}
}
return datalines.join("");
}