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[] = ' …'; 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[] = (new CLink($host['name'], 'hosts.php?form=update&hostid='.$host['hostid']))->addClass($style); 110 } 111 112 $name = new CLink($proxy['host'], 'zabbix.php?action=proxy.edit&proxyid='.$proxy['proxyid']); 113 114 // encryption 115 $in_encryption = ''; 116 $out_encryption = ''; 117 118 if ($proxy['status'] == HOST_STATUS_PROXY_PASSIVE) { 119 // input encryption 120 if ($proxy['tls_connect'] == HOST_ENCRYPTION_NONE) { 121 $in_encryption = (new CSpan(_('None')))->addClass(ZBX_STYLE_STATUS_GREEN); 122 } 123 elseif ($proxy['tls_connect'] == HOST_ENCRYPTION_PSK) { 124 $in_encryption = (new CSpan(_('PSK')))->addClass(ZBX_STYLE_STATUS_GREEN); 125 } 126 else { 127 $in_encryption = (new CSpan(_('CERT')))->addClass(ZBX_STYLE_STATUS_GREEN); 128 } 129 } 130 else { 131 // output encryption 132 $out_encryption_array = []; 133 if (($proxy['tls_accept'] & HOST_ENCRYPTION_NONE) == HOST_ENCRYPTION_NONE) { 134 $out_encryption_array[] = (new CSpan(_('None')))->addClass(ZBX_STYLE_STATUS_GREEN); 135 } 136 if (($proxy['tls_accept'] & HOST_ENCRYPTION_PSK) == HOST_ENCRYPTION_PSK) { 137 $out_encryption_array[] = (new CSpan(_('PSK')))->addClass(ZBX_STYLE_STATUS_GREEN); 138 } 139 if (($proxy['tls_accept'] & HOST_ENCRYPTION_CERTIFICATE) == HOST_ENCRYPTION_CERTIFICATE) { 140 $out_encryption_array[] = (new CSpan(_('CERT')))->addClass(ZBX_STYLE_STATUS_GREEN); 141 } 142 143 $out_encryption = (new CDiv($out_encryption_array))->addClass(ZBX_STYLE_STATUS_CONTAINER); 144 } 145 146 $proxyTable->addRow([ 147 new CCheckBox('proxyids['.$proxy['proxyid'].']', $proxy['proxyid']), 148 (new CCol($name))->addClass(ZBX_STYLE_NOWRAP), 149 $proxy['status'] == HOST_STATUS_PROXY_ACTIVE ? _('Active') : _('Passive'), 150 $proxy['status'] == HOST_STATUS_PROXY_ACTIVE ? $out_encryption : $in_encryption, 151 ($proxy['auto_compress'] == HOST_COMPRESSION_ON) 152 ? (new CSpan(_('On')))->addClass(ZBX_STYLE_STATUS_GREEN) 153 : (new CSpan(_('Off')))->addClass(ZBX_STYLE_STATUS_GREY), 154 ($proxy['lastaccess'] == 0) 155 ? (new CSpan(_('Never')))->addClass(ZBX_STYLE_RED) 156 : zbx_date2age($proxy['lastaccess']), 157 array_key_exists('host_count', $proxy) ? $proxy['host_count'] : '', 158 array_key_exists('item_count', $proxy) ? $proxy['item_count'] : '', 159 array_key_exists('vps_total', $proxy) ? $proxy['vps_total'] : '', 160 $hosts ? $hosts : '' 161 ]); 162} 163 164// append table to form 165$proxyForm->addItem([ 166 $proxyTable, 167 $data['paging'], 168 new CActionButtonList('action', 'proxyids', [ 169 'proxy.hostenable' => ['name' => _('Enable hosts'), 170 'confirm' => _('Enable hosts monitored by selected proxies?') 171 ], 172 'proxy.hostdisable' => ['name' => _('Disable hosts'), 173 'confirm' => _('Disable hosts monitored by selected proxies?') 174 ], 175 'proxy.delete' => ['name' => _('Delete'), 'confirm' => _('Delete selected proxies?')] 176 ], 'proxy') 177]); 178 179// append form to widget 180$widget->addItem($proxyForm)->show(); 181