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 26$widget = (new CWidget())->setTitle(_('Web monitoring')); 27 28// append host summary to widget header 29if (!empty($this->data['hostid'])) { 30 $widget->addItem(get_header_host_table('web', $this->data['hostid'])); 31} 32 33// create form 34$http_form = (new CForm()) 35 ->setName('httpForm') 36 ->setId('httpForm') 37 ->setAttribute('aria-labeledby', ZBX_STYLE_PAGE_TITLE) 38 ->addVar('form', $this->data['form']) 39 ->addVar('hostid', $this->data['hostid']) 40 ->addVar('templated', $this->data['templated']); 41 42if (!empty($this->data['httptestid'])) { 43 $http_form->addVar('httptestid', $this->data['httptestid']); 44} 45 46/* 47 * Scenario tab 48 */ 49$http_form_list = new CFormList(); 50 51// Parent http tests 52if (!empty($this->data['templates'])) { 53 $http_form_list->addRow(_('Parent web scenarios'), $this->data['templates']); 54} 55 56// Name 57$name_text_box = (new CTextBox('name', $this->data['name'], $this->data['templated'], 64)) 58 ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 59 ->setAriaRequired(); 60if (!$this->data['templated']) { 61 $name_text_box->setAttribute('autofocus', 'autofocus'); 62} 63$http_form_list->addRow((new CLabel(_('Name'), 'name'))->setAsteriskMark(), $name_text_box); 64 65// Application 66if ($this->data['application_list']) { 67 $applications = zbx_array_merge([''], $this->data['application_list']); 68 $http_form_list->addRow(new CLabel(_('Application'), 'label-application'), 69 (new CSelect('applicationid')) 70 ->setFocusableElementId('label-application') 71 ->setValue($this->data['applicationid']) 72 ->addOptions(CSelect::createOptionsFromArray($applications)) 73 ); 74} 75else { 76 $http_form_list->addRow(_('Application'), new CSpan(_('No applications found.'))); 77} 78 79// New application 80$http_form_list 81 ->addRow(new CLabel(_('New application'), 'new_application'), 82 (new CSpan( 83 (new CTextBox('new_application', $this->data['new_application']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 84 ))->addClass(ZBX_STYLE_FORM_NEW_GROUP) 85 ) 86 ->addRow((new CLabel(_('Update interval'), 'delay'))->setAsteriskMark(), 87 (new CTextBox('delay', $data['delay'])) 88 ->setWidth(ZBX_TEXTAREA_SMALL_WIDTH) 89 ->setAriaRequired() 90 ) 91 ->addRow( 92 (new CLabel(_('Attempts'), 'retries'))->setAsteriskMark(), 93 (new CNumericBox('retries', $this->data['retries'], 2)) 94 ->setAriaRequired() 95 ->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH) 96 ); 97 98$agent_select = (new CSelect('agent')) 99 ->setId('agent') 100 ->setFocusableElementId('label-agent') 101 ->setValue($this->data['agent']); 102 103$user_agents_all = userAgents(); 104$user_agents_all[_('Others')][ZBX_AGENT_OTHER] = _('other').' ...'; 105 106foreach ($user_agents_all as $user_agent_group => $user_agents) { 107 $agent_select->addOptionGroup((new CSelectOptionGroup($user_agent_group)) 108 ->addOptions(CSelect::createOptionsFromArray($user_agents)) 109 ); 110} 111 112$http_form_list->addRow(new CLabel(_('Agent'), $agent_select->getFocusableElementId()), $agent_select); 113 114$http_form_list->addRow(_('User agent string'), 115 (new CTextBox('agent_other', $this->data['agent_other']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH), 116 'row_agent_other' 117); 118 119// append HTTP proxy to form list 120$http_form_list 121 ->addRow(_('HTTP proxy'), 122 (new CTextBox('http_proxy', $this->data['http_proxy'], false, 255)) 123 ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 124 ->setAttribute('placeholder', '[protocol://][user[:password]@]proxy.example.com[:port]') 125 ->disableAutocomplete() 126 ); 127 128$http_form_list->addRow(_('Variables'), (new CDiv( 129 (new CTable()) 130 ->addClass('httpconf-dynamic-row') 131 ->setAttribute('data-type', 'variables') 132 ->setAttribute('style', 'width: 100%;') 133 ->setHeader(['', _('Name'), '', _('Value'), '']) 134 ->addRow((new CRow([ 135 (new CCol( 136 (new CButton(null, _('Add'))) 137 ->addClass(ZBX_STYLE_BTN_LINK) 138 ->addClass('element-table-add') 139 ))->setColSpan(5) 140 ]))) 141)) 142 ->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR) 143 ->setAttribute('style', 'min-width: ' . ZBX_TEXTAREA_BIG_WIDTH . 'px;') 144); 145 146$http_form_list->addRow(_('Headers'), (new CDiv( 147 (new CTable()) 148 ->addClass('httpconf-dynamic-row') 149 ->setAttribute('data-type', 'headers') 150 ->setAttribute('style', 'width: 100%;') 151 ->setHeader(['', _('Name'), '', _('Value'), '']) 152 ->addRow((new CRow([ 153 (new CCol( 154 (new CButton(null, _('Add'))) 155 ->addClass(ZBX_STYLE_BTN_LINK) 156 ->addClass('element-table-add') 157 ))->setColSpan(5) 158 ]))) 159)) 160 ->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR) 161 ->setAttribute('style', 'min-width: ' . ZBX_TEXTAREA_BIG_WIDTH . 'px;') 162); 163 164$http_form_list->addRow(_('Enabled'), (new CCheckBox('status'))->setChecked(!$this->data['status'])); 165 166/* 167 * Authentication tab 168 */ 169$http_authentication_form_list = new CFormList(); 170 171// Authentication type 172$http_authentication_form_list->addRow(new CLabel(_('HTTP authentication'), 'label-authentication'), 173 (new CSelect('authentication')) 174 ->setId('authentication') 175 ->setFocusableElementId('label-authentication') 176 ->setValue($this->data['authentication']) 177 ->addOptions(CSelect::createOptionsFromArray(httptest_authentications())) 178); 179 180$http_authentication_form_list 181 ->addRow(new CLabel(_('User'), 'http_user'), 182 (new CTextBox('http_user', $this->data['http_user'], false, 64)) 183 ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 184 ->disableAutocomplete() 185 ) 186 ->addRow(new CLabel(_('Password'), 'http_password'), 187 (new CTextBox('http_password', $this->data['http_password'], false, 64)) 188 ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 189 ->disableAutocomplete() 190 ) 191 ->addRow(_('SSL verify peer'), 192 (new CCheckBox('verify_peer'))->setChecked($this->data['verify_peer'] == 1) 193 ) 194 ->addRow(_('SSL verify host'), 195 (new CCheckBox('verify_host'))->setChecked($this->data['verify_host'] == 1) 196 ) 197 ->addRow(_('SSL certificate file'), 198 (new CTextBox('ssl_cert_file', $this->data['ssl_cert_file'], false, 255))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 199 ) 200 ->addRow(_('SSL key file'), 201 (new CTextBox('ssl_key_file', $this->data['ssl_key_file'], false, 255))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 202 ) 203 ->addRow(_('SSL key password'), 204 (new CTextBox('ssl_key_password', $this->data['ssl_key_password'], false, 64)) 205 ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 206 ->disableAutocomplete() 207 ); 208 209/* 210 * Step tab 211 */ 212$http_step_form_list = new CFormList(); 213$steps_table = (new CTable()) 214 ->addClass('httpconf-steps-dynamic-row') 215 ->setHeader([ 216 (new CColHeader())->setWidth('15'), 217 (new CColHeader())->setWidth('15'), 218 (new CColHeader(_('Name')))->setWidth('150'), 219 (new CColHeader(_('Timeout')))->setWidth('50'), 220 (new CColHeader(_('URL')))->setWidth('200'), 221 (new CColHeader(_('Required')))->setWidth('75'), 222 (new CColHeader(_('Status codes'))) 223 ->addClass(ZBX_STYLE_NOWRAP) 224 ->setWidth('90'), 225 (new CColHeader(_('Action')))->setWidth('50') 226 ]); 227 228if (!$this->data['templated']) { 229 $steps_table->addRow( 230 (new CCol( 231 (new CButton(null, _('Add'))) 232 ->addClass('element-table-add') 233 ->addClass(ZBX_STYLE_BTN_LINK) 234 ))->setColSpan(8) 235 ); 236} 237else { 238 $steps_table->addRow( 239 (new CCol(null))->setColSpan(8)->addClass('element-table-add') 240 ); 241} 242 243$http_step_form_list->addRow((new CLabel(_('Steps'), $steps_table->getId()))->setAsteriskMark(), 244 (new CDiv($steps_table)) 245 ->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR) 246 ->setAriaRequired() 247); 248 249// append tabs to form 250$http_tab = (new CTabView()) 251 ->addTab('scenarioTab', _('Scenario'), $http_form_list) 252 ->addTab('stepTab', _('Steps'), $http_step_form_list) 253 ->addTab('authenticationTab', _('Authentication'), $http_authentication_form_list); 254if (!$this->data['form_refresh']) { 255 $http_tab->setSelected(0); 256} 257 258// append buttons to form 259if (!empty($this->data['httptestid'])) { 260 $buttons = [new CSubmit('clone', _('Clone'))]; 261 262 if ($this->data['host']['status'] == HOST_STATUS_MONITORED 263 || $this->data['host']['status'] == HOST_STATUS_NOT_MONITORED) { 264 265 $buttons[] = new CButtonQMessage( 266 'del_history', 267 _('Clear history and trends'), 268 _('History clearing can take a long time. Continue?') 269 ); 270 } 271 272 $buttons[] = (new CButtonDelete(_('Delete web scenario?'), url_params(['form', 'httptestid', 'hostid']))) 273 ->setEnabled(!$data['templated']); 274 $buttons[] = new CButtonCancel(); 275 276 $http_tab->setFooter(makeFormFooter(new CSubmit('update', _('Update')), $buttons)); 277} 278else { 279 $http_tab->setFooter(makeFormFooter( 280 new CSubmit('add', _('Add')), 281 [new CButtonCancel()] 282 )); 283} 284 285$http_form->addItem($http_tab); 286$widget->addItem($http_form); 287 288$this->data['scenario_tab_data'] = [ 289 'agent_visibility' => [], 290 'pairs' => [ 291 'variables' => [], 292 'headers' => [] 293 ] 294]; 295 296foreach ($data['pairs'] as $field) { 297 zbx_subarray_push($this->data['scenario_tab_data']['pairs'], $field['type'], $field); 298} 299 300zbx_subarray_push($this->data['scenario_tab_data']['agent_visibility'], ZBX_AGENT_OTHER, 'agent_other'); 301zbx_subarray_push($this->data['scenario_tab_data']['agent_visibility'], ZBX_AGENT_OTHER, 'row_agent_other'); 302 303require_once dirname(__FILE__).'/js/configuration.httpconf.edit.js.php'; 304 305$widget->show(); 306