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(_('Scripts')) 28 ->setControls((new CForm()) 29 ->cleanItems() 30 ->addItem((new CList())->addItem(new CRedirectButton(_('Create script'), 'zabbix.php?action=script.edit'))) 31 ); 32 33$scriptsForm = (new CForm()) 34 ->setName('scriptsForm') 35 ->setId('scripts'); 36 37$scriptsTable = (new CTableInfo()) 38 ->setHeader([ 39 (new CColHeader( 40 (new CCheckBox('all_scripts'))->onClick("checkAll('".$scriptsForm->getName()."', 'all_scripts', 'scriptids');") 41 ))->addClass(ZBX_STYLE_CELL_WIDTH), 42 make_sorting_header(_('Name'), 'name', $data['sort'], $data['sortorder']), 43 _('Type'), 44 _('Execute on'), 45 make_sorting_header(_('Commands'), 'command', $data['sort'], $data['sortorder']), 46 _('User group'), 47 _('Host group'), 48 _('Host access') 49 ]); 50 51foreach ($data['scripts'] as $script) { 52 switch ($script['type']) { 53 case ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT: 54 $scriptType = _('Script'); 55 break; 56 case ZBX_SCRIPT_TYPE_IPMI: 57 $scriptType = _('IPMI'); 58 break; 59 } 60 61 if ($script['type'] == ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT) { 62 switch ($script['execute_on']) { 63 case ZBX_SCRIPT_EXECUTE_ON_AGENT: 64 $scriptExecuteOn = _('Agent'); 65 break; 66 case ZBX_SCRIPT_EXECUTE_ON_SERVER: 67 $scriptExecuteOn = _('Server'); 68 break; 69 } 70 } 71 else { 72 $scriptExecuteOn = ''; 73 } 74 75 $scriptsTable->addRow([ 76 new CCheckBox('scriptids['.$script['scriptid'].']', $script['scriptid']), 77 (new CCol( 78 new CLink($script['name'], 'zabbix.php?action=script.edit&scriptid='.$script['scriptid']) 79 ))->addClass(ZBX_STYLE_NOWRAP), 80 $scriptType, 81 $scriptExecuteOn, 82 zbx_nl2br(htmlspecialchars($script['command'], ENT_COMPAT, 'UTF-8')), 83 ($script['userGroupName'] === null) ? _('All') : $script['userGroupName'], 84 ($script['hostGroupName'] === null) ? _('All') : $script['hostGroupName'], 85 ($script['host_access'] == PERM_READ_WRITE) ? _('Write') : _('Read') 86 ]); 87} 88 89// append table to form 90$scriptsForm->addItem([ 91 $scriptsTable, 92 $data['paging'], 93 new CActionButtonList('action', 'scriptids', [ 94 'script.delete' => ['name' => _('Delete'), 'confirm' => _('Delete selected scripts?')] 95 ]) 96]); 97 98// append form to widget 99$widget->addItem($scriptsForm)->show(); 100