1<?php
2/*
3** Zabbix
4** Copyright (C) 2001-2021 Zabbix SIA
5**
6** This program is free software; you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation; either version 2 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program; if not, write to the Free Software
18** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19**/
20
21
22if ($data['uncheck']) {
23	uncheckTableRows();
24}
25
26$widget = (new CWidget())
27	->setTitle(_('Proxies'))
28	->setControls((new CForm())
29		->cleanItems()
30		->addItem((new CList())->addItem(new CRedirectButton(_('Create proxy'), 'zabbix.php?action=proxy.edit')))
31	);
32
33// create form
34$proxyForm = (new CForm('get'))->setName('proxyForm');
35
36// create table
37$proxyTable = (new CTableInfo())
38	->setHeader([
39		(new CColHeader(
40			(new CCheckBox('all_hosts'))
41				->onClick("checkAll('".$proxyForm->getName()."', 'all_hosts', 'proxyids');")
42		))->addClass(ZBX_STYLE_CELL_WIDTH),
43		make_sorting_header(_('Name'), 'host', $data['sort'], $data['sortorder']),
44		_('Mode'),
45		_('Encryption'),
46		_('Last seen (age)'),
47		_('Host count'),
48		_('Item count'),
49		_('Required performance (vps)'),
50		_('Hosts')
51	]);
52
53foreach ($data['proxies'] as $proxy) {
54	$hosts = [];
55	$i = 0;
56
57	foreach ($proxy['hosts'] as $host) {
58		if (++$i > $data['config']['max_in_table']) {
59			$hosts[] = ' &hellip;';
60
61			break;
62		}
63
64		switch ($host['status']) {
65			case HOST_STATUS_MONITORED:
66				$style = null;
67				break;
68			case HOST_STATUS_TEMPLATE:
69				$style = ZBX_STYLE_GREY;
70				break;
71			default:
72				$style = ZBX_STYLE_RED;
73		}
74
75		if ($hosts) {
76			$hosts[] = ', ';
77		}
78
79		$hosts[] = (new CLink($host['name'], 'hosts.php?form=update&hostid='.$host['hostid']))->addClass($style);
80	}
81
82	$name = new CLink($proxy['host'], 'zabbix.php?action=proxy.edit&proxyid='.$proxy['proxyid']);
83
84	// encryption
85	$in_encryption = '';
86	$out_encryption = '';
87
88	if ($proxy['status'] == HOST_STATUS_PROXY_PASSIVE) {
89		// input encryption
90		if ($proxy['tls_connect'] == HOST_ENCRYPTION_NONE) {
91			$in_encryption = (new CSpan(_('None')))->addClass(ZBX_STYLE_STATUS_GREEN);
92		}
93		elseif ($proxy['tls_connect'] == HOST_ENCRYPTION_PSK) {
94			$in_encryption = (new CSpan(_('PSK')))->addClass(ZBX_STYLE_STATUS_GREEN);
95		}
96		else {
97			$in_encryption = (new CSpan(_('CERT')))->addClass(ZBX_STYLE_STATUS_GREEN);
98		}
99	}
100	else {
101		// output encryption
102		$out_encryption_array = [];
103		if (($proxy['tls_accept'] & HOST_ENCRYPTION_NONE) == HOST_ENCRYPTION_NONE) {
104			$out_encryption_array[] = (new CSpan(_('None')))->addClass(ZBX_STYLE_STATUS_GREEN);
105		}
106		if (($proxy['tls_accept'] & HOST_ENCRYPTION_PSK) == HOST_ENCRYPTION_PSK) {
107			$out_encryption_array[] = (new CSpan(_('PSK')))->addClass(ZBX_STYLE_STATUS_GREEN);
108		}
109		if (($proxy['tls_accept'] & HOST_ENCRYPTION_CERTIFICATE) == HOST_ENCRYPTION_CERTIFICATE) {
110			$out_encryption_array[] = (new CSpan(_('CERT')))->addClass(ZBX_STYLE_STATUS_GREEN);
111		}
112
113		$out_encryption = (new CDiv($out_encryption_array))->addClass(ZBX_STYLE_STATUS_CONTAINER);
114	}
115
116	$proxyTable->addRow([
117		new CCheckBox('proxyids['.$proxy['proxyid'].']', $proxy['proxyid']),
118		(new CCol($name))->addClass(ZBX_STYLE_NOWRAP),
119		$proxy['status'] == HOST_STATUS_PROXY_ACTIVE ? _('Active') : _('Passive'),
120		$proxy['status'] == HOST_STATUS_PROXY_ACTIVE ? $out_encryption : $in_encryption,
121		$proxy['lastaccess'] == 0
122			? (new CSpan(_('Never')))->addClass(ZBX_STYLE_RED)
123			: zbx_date2age($proxy['lastaccess']),
124		count($proxy['hosts']),
125		array_key_exists('item_count', $proxy) ? $proxy['item_count'] : 0,
126		array_key_exists('perf', $proxy) ? $proxy['perf'] : '',
127		$hosts ? $hosts : ''
128	]);
129}
130
131// append table to form
132$proxyForm->addItem([
133	$proxyTable,
134	$data['paging'],
135	new CActionButtonList('action', 'proxyids', [
136		'proxy.hostenable' => ['name' => _('Enable hosts'),
137			'confirm' => _('Enable hosts monitored by selected proxies?')
138		],
139		'proxy.hostdisable' => ['name' => _('Disable hosts'),
140			'confirm' => _('Disable hosts monitored by selected proxies?')
141		],
142		'proxy.delete' => ['name' => _('Delete'), 'confirm' => _('Delete selected proxies?')]
143	])
144]);
145
146// append form to widget
147$widget->addItem($proxyForm)->show();
148