/usr/share/zabbix/js/class.bbcode.js is in zabbix-frontend-php 1:2.4.7+dfsg-2ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /*
** Zabbix
** Copyright (C) 2001-2015 Zabbix SIA
**
** 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.
**/
var BBCode = {
opentags: null, // open tag stack
crlf2br: null, // convert CRLF to <br>?
noparse: null, // ignore BBCode tags?
urlstart: null, // beginning of the URL if zero or greater (ignored if -1)
RE: {
'bbcode': /^\/?(?:b|i|u|pre|code|color|size|noparse|url)$/, // BBcode tags
'color': /^(:?#(?:[0-9a-f]{3})?[0-9a-f]{3})$/i, // color names or hex color
'uri': /^[-;\/\?:@&=\+\$,_\.!~\*'\(\)%0-9a-z]{1,512}$/i, // reserved, unreserved, escaped and alpha-numeric [RFC2396]
'format': /([\r\n])|(?:\[([a-z]{1,16})(?:=([^\x00-\x1F''\(\)<>\[\]]{1,256}))?\])|(?:\[\/([a-z]{1,16})\])/ig // main regular expression: CRLF, [tag=option], [tag] or [/tag]
},
// post must be HTML-encoded
Parse: function(post) {
this.crlf2br = false;
this.noparse = false;
this.urlstart = -1;
this.opentags = [];
var result = post.replace(this.RE.format, this.toHtml.bind(this));
if (this.opentags.length) {
var endtags = '';
if (this.opentags[this.opentags.length-1].bbtag == 'url') {
this.opentags.pop();
endtags += '\'>' + post.substr(this.urlstart, post.length-this.urlstart) + '</a>';
}
while (this.opentags.length) {
endtags += this.opentags.pop().etag;
}
}
return endtags ? result + endtags : result;
},
// check if it's a valid BBCode tag
isValidTag: function(str) {
if (empty(str)) {
return false;
}
return this.RE.bbcode.test(str);
},
toHtml: function(mstr, crlf, tag, option, tagEnd, offset, string) {
if (!empty(crlf)) {
if (!this.crlf2br) {
return mstr;
}
if (crlf == '\r') {
return '';
}
else if (crlf == '\n') {
return '<br />';
}
}
// handle start tags
if (this.isValidTag(tag)) {
if (this.noparse) {
return '[' + tag + ']';
}
if (!empty(this.opentags) && this.opentags[this.opentags.length - 1].bbtag == 'url' && this.urlstart >= 0) {
return '[' + tag + ']';
}
switch (tag) {
case 'noparse':
this.noparse = true;
return '';
case 'url':
this.opentags.push({'bbtag' : tag, 'etag' : '</a>'});
if (option && this.RE.uri.test(option)) {
this.urlstart = -1;
return '<a href="' + option + '">';
}
this.urlstart = mstr.length + offset;
return '<a href="';
case 'code':
this.opentags.push({'bbtag' : tag, 'etag' : '</code></pre>'});
this.noparse = false;
return '<pre><code>';
case 'pre':
this.opentags.push({'bbtag' : tag, 'etag' : '</pre>'});
this.noparse = false;
return '<pre>';
case 'color':
if (!option || !this.RE.color.test(option)) {
option = 'inherit';
}
this.opentags.push({'bbtag' : tag, 'etag' : '</span>'});
return '<span style="color: ' + option + '">';
case 'size':
option = option || '7';
this.opentags.push({'bbtag' : tag, 'etag' : '</span>'});
return '<span style="font-size: ' + parseInt(option, 10) + 'pt">';
default:
this.opentags.push({'bbtag' : tag, 'etag' : '</' + tag + '>'});
return '<' + tag + '>';
}
}
// process end tags
if (this.isValidTag(tagEnd)) {
if (this.noparse) {
if (tagEnd == 'noparse') {
this.noparse = false;
return '';
}
return '[/' + tagEnd + ']';
}
if (!this.opentags.length || this.opentags[this.opentags.length - 1].bbtag != tagEnd) {
return '<span style="color: red">[/' + tagEnd + ']</span>';
}
if (tagEnd == 'url') {
if (this.urlstart > 0) {
return '">' + string.substr(this.urlstart, offset - this.urlstart) + this.opentags.pop().etag;
}
return this.opentags.pop().etag;
}
else if (tagEnd == 'code' || tagEnd == 'pre') {
this.crlf2br = true;
}
return this.opentags.pop().etag;
}
return mstr;
}
};
|