This file is indexed.

/usr/share/zabbix/tr_testexpr.php 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
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
<?php
/*
** 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; ifnot, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/


require_once dirname(__FILE__).'/include/config.inc.php';
require_once dirname(__FILE__).'/include/triggers.inc.php';

$page['title'] = _('Test');
$page['file'] = 'tr_testexpr.php';

define('ZBX_PAGE_NO_MENU', 1);
define('COMBO_PATTERN', 'str_in_array({},array(');
define('COMBO_PATTERN_LENGTH', strlen(COMBO_PATTERN));

$definedErrorPhrases = array(
	EXPRESSION_HOST_UNKNOWN => _('Unknown host, no such host present in system'),
	EXPRESSION_HOST_ITEM_UNKNOWN => _('Unknown host item, no such item in selected host'),
	EXPRESSION_NOT_A_MACRO_ERROR => _('Given expression is not a macro'),
	EXPRESSION_FUNCTION_UNKNOWN => _('Incorrect function is used')
);

require_once dirname(__FILE__).'/include/page_header.php';

// expression analyze
$expression = getRequest('expression', '');

define('NO_LINK_IN_TESTING', true);
list($outline, $eHTMLTree) = analyzeExpression($expression);

// test data (create table, create check fields)
$dataTable = new CTable(null, 'tableinfo');
$dataTable->setAttribute('id', 'data_list');
$dataTable->setHeader(array(_('Expression Variable Elements'), _('Result type'), _('Value')));

$datas = array();
$fields = array();
$rplcts = array();
$allowedTesting = true;

$expressionData = new CTriggerExpression();
$result = $expressionData->parse($expression);
if ($result) {
	$macrosData = array();

	$supportedTokenTypes = array(
		CTriggerExpressionParserResult::TOKEN_TYPE_FUNCTION_MACRO => 1,
		CTriggerExpressionParserResult::TOKEN_TYPE_MACRO => 1,
		CTriggerExpressionParserResult::TOKEN_TYPE_USER_MACRO => 1,
		CTriggerExpressionParserResult::TOKEN_TYPE_LLD_MACRO => 1
	);
	foreach ($result->getTokens() as $token) {
		if (!isset($supportedTokenTypes[$token['type']]) || isset($macrosData[$token['value']])) {
			continue;
		}

		$fname = 'test_data_'.md5($token['value']);
		$macrosData[$token['value']] = getRequest($fname, '');

		$info = get_item_function_info($token['value']);

		if (!is_array($info) && isset($definedErrorPhrases[$info])) {
			$allowedTesting = false;
			$control = new CTextBox($fname, $macrosData[$token['value']], 30);
			$control->setAttribute('disabled', 'disabled');
		}
		else {
			$validation = $info['validation'];

			if (substr($validation, 0, COMBO_PATTERN_LENGTH) == COMBO_PATTERN) {
				$end = strlen($validation) - COMBO_PATTERN_LENGTH - 4;
				$vals = explode(',', substr($validation, COMBO_PATTERN_LENGTH, $end));
				$control = new CComboBox($fname, $macrosData[$token['value']]);

				foreach ($vals as $v) {
					$control->addItem($v, $v);
				}
			}
			else {
				$control = new CTextBox($fname, $macrosData[$token['value']], 30);
			}

			$fields[$fname] = array($info['type'], O_OPT, null, $validation, 'isset({test_expression})',
				$token['value']
			);
		}

		$resultType = (is_array($info) || !isset($definedErrorPhrases[$info]))
			? $info['value_type']
			: new CCol($definedErrorPhrases[$info], 'disaster');

		$dataTable->addRow(new CRow(array($token['value'], $resultType, $control)));
	}
}

// checks
$fields['test_expression'] = array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null);
if (!check_fields($fields)) {
	$test = false;
}

// actions
if (isset($_REQUEST['test_expression'])) {
	show_messages();
	$test = true;
}
else {
	$test = false;
}

// form
$testForm = new CFormTable(_('Test'), 'tr_testexpr.php');
$testForm->addHelpIcon();
$testForm->setTableClass('formlongtable formtable');
$testForm->addVar('expression', $expression);
$testForm->addRow(_('Test data'), $dataTable);

$resultTable = new CTable(null, 'tableinfo');
$resultTable->setAttribute('id', 'result_list');
$resultTable->setOddRowClass('even_row');
$resultTable->setEvenRowClass('even_row');
$resultTable->setHeader(array(_('Expression'), _('Result')));

ksort($rplcts, SORT_NUMERIC);

foreach ($eHTMLTree as $e) {
	$result = '-';
	$style = 'text-align: center;';

	if ($allowedTesting && $test && isset($e['expression'])) {
		if (evalExpressionData($e['expression']['value'], $macrosData)) {
			$result = 'TRUE';
			$style = 'background-color: #ccf; color: #00f;';
		}
		else {
			$result = 'FALSE';
			$style = 'background-color: #fcc; color: #f00;';
		}
	}

	$col = new CCol($result);
	$col->setAttribute('style', $style);

	$resultTable->addRow(new CRow(array($e['list'], $col)));
}

$result = '-';
$style = 'text-align: center;';

if ($allowedTesting && $test) {
	if (evalExpressionData($expression, $macrosData)) {
		$result = 'TRUE';
		$style = 'background-color: #ccf; color: #00f;';
	}
	else {
		$result = 'FALSE';
		$style = 'background-color: #fcc; color: #f00;';
	}
}

$col = new CCol($result);
$col->setAttribute('style', $style);

$resultTable->setFooter(array($outline, $col), $resultTable->headerClass);

$testForm->addRow(_('Result'), $resultTable);

// action buttons
$testButton = new CSubmit('test_expression', _('Test'));
if (!$allowedTesting) {
	$testButton->setAttribute('disabled', 'disabled');
}

$testForm->addItemToBottomRow($testButton);
$testForm->addItemToBottomRow(SPACE);
$testForm->addItemToBottomRow(new CButton('close', _('Close'), 'javascript: self.close();'));
$testForm->show();

require_once dirname(__FILE__).'/include/page_footer.php';