This file is indexed.

/usr/share/zabbix/include/js.inc.php is in zabbix-frontend-php 1:3.0.12+dfsg-1.

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
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<?php
/*
** Zabbix
** Copyright (C) 2001-2017 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.
**/


/**
 * Convert PHP variable to string version of JavaScript style
 *
 * @deprecated use CJs::encodeJson() instead
 * @see CJs::encodeJson()
 *
 * @param mixed $value
 * @param bool  $as_object return string containing javascript object
 * @param bool  $addQuotes whether quotes should be added at the beginning and at the end of string
 *
 * @return string
 */
function zbx_jsvalue($value, $as_object = false, $addQuotes = true) {
	if (!is_array($value)) {
		if (is_object($value)) {
			return unpack_object($value);
		}
		elseif (is_string($value)) {
			$escaped = str_replace("\r", '', $value); // removing caret returns
			$escaped = str_replace("\\", "\\\\", $escaped); // escaping slashes: \ => \\
			$escaped = str_replace('"', '\"', $escaped); // escaping quotes: " => \"
			$escaped = str_replace("\n", '\n', $escaped); // changing LF to '\n' string
			$escaped = str_replace('\'', '\\\'', $escaped); // escaping single quotes: ' => \'
			$escaped = str_replace('/', '\/', $escaped); // escaping forward slash: / => \/
			if ($addQuotes) {
				$escaped = "'".$escaped."'";
			}
			return $escaped;
		}
		elseif (is_null($value)) {
			return 'null';
		}
		elseif (is_bool($value)) {
			return ($value) ? 'true' : 'false';
		}
		else {
			return strval($value);
		}
	}
	elseif (count($value) == 0) {
		return $as_object ? '{}' : '[]';
	}

	$is_object = $as_object;

	foreach ($value as $key => &$v) {
		$is_object |= is_string($key);
		$escaped_key = $is_object ? '"'.zbx_jsvalue($key, false, false).'":' : '';
		$v = $escaped_key.zbx_jsvalue($v, $as_object, $addQuotes);
	}
	unset($v);

	return $is_object ? '{'.implode(',', $value).'}' : '['.implode(',', $value).']';
}

function encodeValues(&$value, $encodeTwice = true) {
	if (is_string($value)) {
		$value = htmlentities($value, ENT_COMPAT, 'UTF-8');
		if ($encodeTwice) {
			$value = htmlentities($value, ENT_COMPAT, 'UTF-8');
		}
	}
	elseif (is_array(($value))) {
		foreach ($value as $key => $elem) {
			encodeValues($value[$key]);
		}
	}
	elseif (is_object(($value))) {
		foreach ($value->items as $key => $item) {
			encodeValues($value->items[$key], false);
		}
	}
}

function insert_show_color_picker_javascript() {
	global $SHOW_COLOR_PICKER_SCRIPT_INSERTED;

	if ($SHOW_COLOR_PICKER_SCRIPT_INSERTED) {
		return;
	}
	$SHOW_COLOR_PICKER_SCRIPT_INSERTED = true;
	$table = [];

	// gray colors
	$row = [];
	foreach (['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'] as $c) {
		$color = $c.$c.$c.$c.$c.$c;
		$row[] = (new CColorCell(null, $color))
			->setTitle('#'.$color)
			->onClick('set_color("'.$color.'");');
	}
	$table[] = (new CDiv($row))->addClass(ZBX_STYLE_COLOR_PICKER);

	// other colors
	$colors = [
		['r' => 0, 'g' => 0, 'b' => 1],
		['r' => 0, 'g' => 1, 'b' => 0],
		['r' => 1, 'g' => 0, 'b' => 0],
		['r' => 0, 'g' => 1, 'b' => 1],
		['r' => 1, 'g' => 0, 'b' => 1],
		['r' => 1, 'g' => 1, 'b' => 0]
	];

	$brigs = [
		[0 => '0', 1 => '3'],
		[0 => '0', 1 => '4'],
		[0 => '0', 1 => '5'],
		[0 => '0', 1 => '6'],
		[0 => '0', 1 => '7'],
		[0 => '0', 1 => '8'],
		[0 => '0', 1 => '9'],
		[0 => '0', 1 => 'A'],
		[0 => '0', 1 => 'B'],
		[0 => '0', 1 => 'C'],
		[0 => '0', 1 => 'D'],
		[0 => '0', 1 => 'E'],
		[0 => '3', 1 => 'F'],
		[0 => '6', 1 => 'F'],
		[0 => '9', 1 => 'F'],
		[0 => 'C', 1 => 'F']
	];

	foreach ($colors as $c) {
		$row = [];
		foreach ($brigs as $br) {
			$r = $br[$c['r']];
			$g = $br[$c['g']];
			$b = $br[$c['b']];

			$color = $r.$r.$g.$g.$b.$b;
			$row[] = (new CColorCell(null, $color))
				->setTitle('#'.$color)
				->onClick('set_color("'.$color.'");');
		}
		$table[] = (new CDiv($row))->addClass(ZBX_STYLE_COLOR_PICKER);
	}

	$cancel = (new CSimpleButton())
		->addClass(ZBX_STYLE_OVERLAY_CLOSE_BTN)
		->onClick('javascript: hide_color_picker();');

	$tmp = [$cancel, $table];
	insert_js('var color_picker = null,'."\n".
		'curr_lbl = null,'."\n".
		'curr_txt = null,'."\n".
		'color_table = '.zbx_jsvalue(unpack_object($tmp))."\n");
	zbx_add_post_js('create_color_picker();');
}

function insert_javascript_for_visibilitybox() {
	if (defined('CVISIBILITYBOX_JAVASCRIPT_INSERTED')) {
		return null;
	}
	define('CVISIBILITYBOX_JAVASCRIPT_INSERTED', 1);

	$js = '
		function visibility_status_changeds(value, obj_name, replace_to) {
			var obj = document.getElementsByName(obj_name);
			if (obj.length <= 0) {
				obj = [document.getElementById(obj_name)];
			}
			if (obj.length <= 0 || is_null(obj[0])) {
				throw "'._('Cannot find objects with name').' [" + obj_name +"]";
			}

			for (i = obj.length - 1; i >= 0; i--) {
				if (replace_to && replace_to != "") {
					if (obj[i].originalObject) {
						var old_obj = obj[i].originalObject;
						old_obj.originalObject = obj[i];
						obj[i].parentNode.replaceChild(old_obj, obj[i]);
					}
					else if (!value) {
						try {
							var new_obj = document.createElement("a");
							new_obj.setAttribute("name", obj[i].name);
							new_obj.setAttribute("id", obj[i].id);
						}
						catch(e) {
							throw "'._('Cannot create new element').'";
						}
						new_obj.style.textDecoration = "none";
						new_obj.innerHTML = replace_to;
						new_obj.originalObject = obj[i];
						obj[i].parentNode.replaceChild(new_obj, obj[i]);
					}
					else {
						throw "Missing originalObject for restoring";
					}
				}
				else {
					value = value ? "visible" : "hidden";
					obj[i].style.visibility = value;
				}
			}
		}';
	insert_js($js);
}

function insert_js_function($fnct_name) {
	switch ($fnct_name) {
		case 'add_media':
			insert_js('
				function add_media(formname, media, mediatypeid, sendto, period, active, severity) {
					var form = window.opener.document.forms[formname];
					var media_name = (media > -1) ? "user_medias[" + media + "]" : "new_media";
					if (!form) {
						close_window();
						return false;
					}
					window.opener.create_var(form, media_name + "[mediatypeid]", mediatypeid);
					window.opener.create_var(form, media_name + "[sendto]", sendto);
					window.opener.create_var(form, media_name + "[period]", period);
					window.opener.create_var(form, media_name + "[active]", active);
					window.opener.create_var(form, media_name + "[severity]", severity);

					form.submit();
					close_window();
					return true;
				}');
			break;

		case 'addSelectedValues':
			insert_js('
				function addSelectedValues(form, object, parentId) {
					form = $(form);
					if (is_null(form)) {
						return close_window()
					};
					var parent = window.opener;
					if (!parent) {
						return close_window();
					}

					if (typeof parentId === "undefined") {
						var parentId = null;
					}

					var data = { object: object, values: [], parentId: parentId };
					var chkBoxes = form.getInputs("checkbox");
					for (var i = 0; i < chkBoxes.length; i++) {
						if (chkBoxes[i].checked && (chkBoxes[i].name.indexOf("all_") < 0)) {
							var value = {};
							if (isset(chkBoxes[i].value, popupReference)) {
								value = popupReference[chkBoxes[i].value];
							}
							else {
								value[object] = chkBoxes[i].value;
							}
							data["values"].push(value);
						}
					}
					close_window();

					parent.jQuery(parent.document).trigger("add.popup", data);
				}');
			break;

		case 'addValue':
			insert_js('
				function addValue(object, singleValue, parentId) {
					var parent = window.opener;
					if (!parent) {
						return close_window();
					}
					var value = {};
					if (isset(singleValue, popupReference)) {
						value = popupReference[singleValue];
					}
					else {
						value[object] = singleValue;
					}

					if (typeof parentId === "undefined") {
						var parentId = null;
					}
					var data = { object: object, values: [value], parentId: parentId };

					close_window();

					parent.jQuery(parent.document).trigger("add.popup", data);
				}');
			break;

		case 'addValues':
			insert_js('
				function addValues(frame, values, submitParent) {
					var parentDocument = window.opener.document;
					if (!parentDocument) {
						return close_window();
					}
					var parentDocumentForms = $(parentDocument.body).select("form[name=" + frame + "]");
					var submitParent = submitParent || false;
					var frmStorage = null;

					for (var key in values) {
						if (is_null(values[key])) {
							continue;
						}

						if (parentDocumentForms.length > 0) {
							frmStorage = jQuery(parentDocumentForms[0]).find("#" + key).get(0);
						}
						if (typeof frmStorage === "undefined" || is_null(frmStorage)) {
							frmStorage = parentDocument.getElementById(key);
						}

						if (jQuery(frmStorage).is("span")) {
							jQuery(frmStorage).html(values[key]);
						}
						else {
							frmStorage.value = values[key];
						}
					}
					if (!is_null(frmStorage) && submitParent) {
						frmStorage.form.submit();
					}
					close_window();
				}');
			break;
	}
};

function insert_js($script, $jQueryDocumentReady = false) {
	echo get_js($script, $jQueryDocumentReady);
}

function get_js($script, $jQueryDocumentReady = false) {
	return $jQueryDocumentReady
		? '<script type="text/javascript">'."\n".'jQuery(document).ready(function() { '.$script.' });'."\n".'</script>'
		: '<script type="text/javascript">'."\n".$script."\n".'</script>';
}

// add JavaScript for calling after page loading
function zbx_add_post_js($script) {
	global $ZBX_PAGE_POST_JS;

	if ($ZBX_PAGE_POST_JS === null) {
		$ZBX_PAGE_POST_JS = [];
	}

	if (!in_array($script, $ZBX_PAGE_POST_JS)) {
		$ZBX_PAGE_POST_JS[] = $script;
	}
}

function insertPagePostJs() {
	global $ZBX_PAGE_POST_JS;

	if ($ZBX_PAGE_POST_JS) {
		echo get_js(implode("\n", $ZBX_PAGE_POST_JS), true);
	}
}