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
22/**
23 * @var CView $this
24 */
25
26if ($data['uncheck']) {
27	uncheckTableRows('proxy');
28}
29
30$widget = (new CWidget())
31	->setTitle(_('Proxies'))
32	->setControls((new CTag('nav', true,
33		(new CList())
34			->addItem(new CRedirectButton(_('Create proxy'), 'zabbix.php?action=proxy.edit'))
35		))
36			->setAttribute('aria-label', _('Content controls'))
37	)
38	->addItem((new CFilter((new CUrl('zabbix.php'))->setArgument('action', 'proxy.list')))
39		->setProfile($data['profileIdx'])
40		->setActiveTab($data['active_tab'])
41		->addFilterTab(_('Filter'), [
42			(new CFormList())->addRow(_('Name'),
43				(new CTextBox('filter_name', $data['filter']['name']))
44					->setWidth(ZBX_TEXTAREA_FILTER_SMALL_WIDTH)
45					->setAttribute('autofocus', 'autofocus')
46			),
47			(new CFormList())->addRow(_('Mode'),
48				(new CRadioButtonList('filter_status', (int) $data['filter']['status']))
49					->addValue(_('Any'), -1)
50					->addValue(_('Active'), HOST_STATUS_PROXY_ACTIVE)
51					->addValue(_('Passive'), HOST_STATUS_PROXY_PASSIVE)
52					->setModern(true)
53			)
54		])
55		->addVar('action', 'proxy.list')
56	);
57
58// create form
59$proxyForm = (new CForm('get'))->setName('proxyForm');
60
61// create table
62$proxyTable = (new CTableInfo())
63	->setHeader([
64		(new CColHeader(
65			(new CCheckBox('all_hosts'))
66				->onClick("checkAll('".$proxyForm->getName()."', 'all_hosts', 'proxyids');")
67		))->addClass(ZBX_STYLE_CELL_WIDTH),
68		make_sorting_header(_('Name'), 'host', $data['sort'], $data['sortorder'],
69			(new CUrl('zabbix.php'))
70				->setArgument('action', 'proxy.list')
71				->getUrl()
72		),
73		_('Mode'),
74		_('Encryption'),
75		_('Compression'),
76		_('Last seen (age)'),
77		_('Host count'),
78		_('Item count'),
79		_('Required performance (vps)'),
80		_('Hosts')
81	]);
82
83foreach ($data['proxies'] as $proxy) {
84	$hosts = [];
85	$i = 0;
86
87	foreach ($proxy['hosts'] as $host) {
88		if (++$i > $data['config']['max_in_table']) {
89			$hosts[] = ' &hellip;';
90
91			break;
92		}
93
94		switch ($host['status']) {
95			case HOST_STATUS_MONITORED:
96				$style = null;
97				break;
98			case HOST_STATUS_TEMPLATE:
99				$style = ZBX_STYLE_GREY;
100				break;
101			default:
102				$style = ZBX_STYLE_RED;
103		}
104
105		if ($hosts) {
106			$hosts[] = ', ';
107		}
108
109		$hosts[] = $data['allowed_ui_conf_hosts']
110			? (new CLink($host['name'], 'hosts.php?form=update&hostid='.$host['hostid']))->addClass($style)
111			: (new CSpan($host['name']))->addClass($style);
112	}
113
114	$name = new CLink($proxy['host'], 'zabbix.php?action=proxy.edit&proxyid='.$proxy['proxyid']);
115
116	// encryption
117	$in_encryption = '';
118	$out_encryption = '';
119
120	if ($proxy['status'] == HOST_STATUS_PROXY_PASSIVE) {
121		// input encryption
122		if ($proxy['tls_connect'] == HOST_ENCRYPTION_NONE) {
123			$in_encryption = (new CSpan(_('None')))->addClass(ZBX_STYLE_STATUS_GREEN);
124		}
125		elseif ($proxy['tls_connect'] == HOST_ENCRYPTION_PSK) {
126			$in_encryption = (new CSpan(_('PSK')))->addClass(ZBX_STYLE_STATUS_GREEN);
127		}
128		else {
129			$in_encryption = (new CSpan(_('CERT')))->addClass(ZBX_STYLE_STATUS_GREEN);
130		}
131	}
132	else {
133		// output encryption
134		$out_encryption_array = [];
135		if (($proxy['tls_accept'] & HOST_ENCRYPTION_NONE) == HOST_ENCRYPTION_NONE) {
136			$out_encryption_array[] = (new CSpan(_('None')))->addClass(ZBX_STYLE_STATUS_GREEN);
137		}
138		if (($proxy['tls_accept'] & HOST_ENCRYPTION_PSK) == HOST_ENCRYPTION_PSK) {
139			$out_encryption_array[] = (new CSpan(_('PSK')))->addClass(ZBX_STYLE_STATUS_GREEN);
140		}
141		if (($proxy['tls_accept'] & HOST_ENCRYPTION_CERTIFICATE) == HOST_ENCRYPTION_CERTIFICATE) {
142			$out_encryption_array[] = (new CSpan(_('CERT')))->addClass(ZBX_STYLE_STATUS_GREEN);
143		}
144
145		$out_encryption = (new CDiv($out_encryption_array))->addClass(ZBX_STYLE_STATUS_CONTAINER);
146	}
147
148	$proxyTable->addRow([
149		new CCheckBox('proxyids['.$proxy['proxyid'].']', $proxy['proxyid']),
150		(new CCol($name))->addClass(ZBX_STYLE_NOWRAP),
151		$proxy['status'] == HOST_STATUS_PROXY_ACTIVE ? _('Active') : _('Passive'),
152		$proxy['status'] == HOST_STATUS_PROXY_ACTIVE ? $out_encryption : $in_encryption,
153		($proxy['auto_compress'] == HOST_COMPRESSION_ON)
154			? (new CSpan(_('On')))->addClass(ZBX_STYLE_STATUS_GREEN)
155			: (new CSpan(_('Off')))->addClass(ZBX_STYLE_STATUS_GREY),
156		($proxy['lastaccess'] == 0)
157			? (new CSpan(_('Never')))->addClass(ZBX_STYLE_RED)
158			: zbx_date2age($proxy['lastaccess']),
159		array_key_exists('host_count', $proxy) ? $proxy['host_count'] : '',
160		array_key_exists('item_count', $proxy) ? $proxy['item_count'] : '',
161		array_key_exists('vps_total', $proxy) ? $proxy['vps_total'] : '',
162		$hosts ? $hosts : ''
163	]);
164}
165
166// append table to form
167$proxyForm->addItem([
168	$proxyTable,
169	$data['paging'],
170	new CActionButtonList('action', 'proxyids', [
171		'proxy.hostenable' => ['name' => _('Enable hosts'),
172			'confirm' => _('Enable hosts monitored by selected proxies?')
173		],
174		'proxy.hostdisable' => ['name' => _('Disable hosts'),
175			'confirm' => _('Disable hosts monitored by selected proxies?')
176		],
177		'proxy.delete' => ['name' => _('Delete'), 'confirm' => _('Delete selected proxies?')]
178	], 'proxy')
179]);
180
181// append form to widget
182$widget->addItem($proxyForm)->show();
183