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 22require_once dirname(__FILE__).'/js/configuration.host.edit.js.php'; 23 24$widget = (new CWidget()) 25 ->setTitle(_('Hosts')) 26 ->addItem(get_header_host_table('', $data['hostid'])); 27 28$divTabs = new CTabView(); 29if (!hasRequest('form_refresh')) { 30 $divTabs->setSelected(0); 31} 32 33$frmHost = (new CForm()) 34 ->setName('hostsForm') 35 ->addVar('form', $data['form']) 36 ->addVar('clear_templates', $data['clear_templates']) 37 ->addVar('flags', $data['flags']) 38 ->addVar('tls_connect', $data['tls_connect']) 39 ->addVar('tls_accept', $data['tls_accept']) 40 ->setAttribute('id', 'hostForm'); 41 42if ($data['hostid'] != 0) { 43 $frmHost->addVar('hostid', $data['hostid']); 44} 45if ($data['clone_hostid'] != 0) { 46 $frmHost->addVar('clone_hostid', $data['clone_hostid']); 47} 48if ($data['groupid'] != 0) { 49 $frmHost->addVar('groupid', $data['groupid']); 50} 51 52$hostList = new CFormList('hostlist'); 53 54// LLD rule link 55if ($data['flags'] == ZBX_FLAG_DISCOVERY_CREATED) { 56 $hostList->addRow(_('Discovered by'), 57 new CLink($data['discoveryRule']['name'], 58 'host_prototypes.php?parent_discoveryid='.$data['discoveryRule']['itemid'] 59 ) 60 ); 61} 62 63$hostList->addRow(_('Host name'), 64 (new CTextBox('host', $data['host'], ($data['flags'] == ZBX_FLAG_DISCOVERY_CREATED), 128)) 65 ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 66 ->setAttribute('autofocus', 'autofocus') 67); 68 69$hostList->addRow(_('Visible name'), 70 (new CTextBox('visiblename', $data['visiblename'], ($data['flags'] == ZBX_FLAG_DISCOVERY_CREATED), 128)) 71 ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 72); 73 74if ($data['flags'] != ZBX_FLAG_DISCOVERY_CREATED) { 75 // groups for normal hosts 76 $groupsTB = new CTweenBox($frmHost, 'groups', $data['groups'], 10); 77 78 foreach ($data['groupsAll'] as $group) { 79 if (in_array($group['groupid'], $data['groups'])) { 80 $groupsTB->addItem($group['groupid'], $group['name'], null, 81 array_key_exists($group['groupid'], $data['groupsAllowed']) 82 ); 83 } 84 elseif (array_key_exists($group['groupid'], $data['groupsAllowed'])) { 85 $groupsTB->addItem($group['groupid'], $group['name']); 86 } 87 } 88 89 $hostList->addRow(_('Groups'), $groupsTB->get(_('In groups'), _('Other groups'))); 90 91 $new_group = (new CTextBox('newgroup', $data['newgroup'])) 92 ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 93 ->setAttribute('maxlength', 64); 94 $new_group_label = _('New group'); 95 if (CWebUser::$data['type'] != USER_TYPE_SUPER_ADMIN) { 96 $new_group_label .= ' '._('(Only super admins can create groups)'); 97 $new_group->setReadonly(true); 98 } 99 $hostList->addRow(new CLabel($new_group_label, 'newgroup'), 100 (new CSpan($new_group))->addClass(ZBX_STYLE_FORM_NEW_GROUP) 101 ); 102} 103else { 104 // groups for discovered hosts 105 $groupBox = new CListBox(null, null, 10); 106 $groupBox->setEnabled(false); 107 foreach ($data['groupsAll'] as $group) { 108 if (in_array($group['groupid'], $data['groups'])) { 109 $groupBox->addItem($group['groupid'], $group['name'], null, 110 array_key_exists($group['groupid'], $data['groupsAllowed']) 111 ); 112 } 113 } 114 $hostList->addRow(_('Groups'), $groupBox); 115 $hostList->addVar('groups', $data['groups']); 116} 117 118// interfaces for normal hosts 119if ($data['flags'] != ZBX_FLAG_DISCOVERY_CREATED) { 120 zbx_add_post_js($data['interfaces'] 121 ? 'hostInterfacesManager.add('.CJs::encodeJson($data['interfaces']).');' 122 : 'hostInterfacesManager.addNew("agent");'); 123 124 // Zabbix agent interfaces 125 $ifTab = (new CTable()) 126 ->setId('agentInterfaces') 127 ->setHeader([ 128 new CColHeader(), 129 new CColHeader(_('IP address')), 130 new CColHeader(_('DNS name')), 131 new CColHeader(_('Connect to')), 132 new CColHeader(_('Port')), 133 (new CColHeader(_('Default')))->setColSpan(2) 134 ]) 135 ->addRow((new CRow([ 136 (new CCol( 137 (new CButton('addAgentInterface', _('Add')))->addClass(ZBX_STYLE_BTN_LINK) 138 ))->setColSpan(7) 139 ]))->setId('agentInterfacesFooter')); 140 141 $hostList->addRow(_('Agent interfaces'), 142 (new CDiv($ifTab)) 143 ->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR) 144 ->setAttribute('data-type', 'agent') 145 ->setWidth(ZBX_HOST_INTERFACE_WIDTH) 146 ); 147 148 // SNMP interfaces 149 $ifTab = (new CTable()) 150 ->setId('SNMPInterfaces') 151 ->addRow((new CRow([ 152 (new CCol( 153 (new CButton('addSNMPInterface', _('Add')))->addClass(ZBX_STYLE_BTN_LINK) 154 ))->setColSpan(7) 155 ]))->setId('SNMPInterfacesFooter')); 156 157 $hostList->addRow(_('SNMP interfaces'), 158 (new CDiv($ifTab)) 159 ->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR) 160 ->setAttribute('data-type', 'snmp') 161 ->setWidth(ZBX_HOST_INTERFACE_WIDTH) 162 ); 163 164 // JMX interfaces 165 $ifTab = (new CTable()) 166 ->setId('JMXInterfaces') 167 ->addRow((new CRow([ 168 (new CCol( 169 (new CButton('addJMXInterface', _('Add')))->addClass(ZBX_STYLE_BTN_LINK) 170 ))->setColSpan(7) 171 ]))->setId('JMXInterfacesFooter')); 172 173 $hostList->addRow(_('JMX interfaces'), 174 (new CDiv($ifTab)) 175 ->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR) 176 ->setAttribute('data-type', 'jmx') 177 ->setWidth(ZBX_HOST_INTERFACE_WIDTH) 178 ); 179 180 // IPMI interfaces 181 $ifTab = (new CTable()) 182 ->setId('IPMIInterfaces') 183 ->addRow((new CRow([ 184 (new CCol( 185 (new CButton('addIPMIInterface', _('Add')))->addClass(ZBX_STYLE_BTN_LINK) 186 ))->setColSpan(7) 187 ]))->setId('IPMIInterfacesFooter')); 188 189 $hostList->addRow(_('IPMI interfaces'), 190 (new CDiv($ifTab)) 191 ->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR) 192 ->setAttribute('data-type', 'ipmi') 193 ->setWidth(ZBX_HOST_INTERFACE_WIDTH) 194 ); 195} 196// interfaces for discovered hosts 197else { 198 $existingInterfaceTypes = []; 199 foreach ($data['interfaces'] as $interface) { 200 $existingInterfaceTypes[$interface['type']] = true; 201 } 202 zbx_add_post_js('hostInterfacesManager.add('.CJs::encodeJson($data['interfaces']).');'); 203 zbx_add_post_js('hostInterfacesManager.disable();'); 204 205 $hostList->addVar('interfaces', $data['interfaces']); 206 207 // Zabbix agent interfaces 208 $ifTab = (new CTable()) 209 ->setId('agentInterfaces') 210 ->setHeader([ 211 new CColHeader(), 212 new CColHeader(_('IP address')), 213 new CColHeader(_('DNS name')), 214 new CColHeader(_('Connect to')), 215 new CColHeader(_('Port')), 216 (new CColHeader(_('Default')))->setColSpan(2) 217 ]); 218 219 $row = (new CRow())->setId('agentInterfacesFooter'); 220 if (!array_key_exists(INTERFACE_TYPE_AGENT, $existingInterfaceTypes)) { 221 $row->addItem(new CCol()); 222 $row->addItem((new CCol(_('No agent interfaces found.')))->setColSpan(6)); 223 } 224 $ifTab->addRow($row); 225 226 $hostList->addRow(_('Agent interfaces'), 227 (new CDiv($ifTab)) 228 ->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR) 229 ->setAttribute('data-type', 'agent') 230 ->setWidth(ZBX_HOST_INTERFACE_WIDTH) 231 ); 232 233 // SNMP interfaces 234 $ifTab = (new CTable())->setId('SNMPInterfaces'); 235 236 $row = (new CRow())->setId('SNMPInterfacesFooter'); 237 if (!array_key_exists(INTERFACE_TYPE_SNMP, $existingInterfaceTypes)) { 238 $row->addItem(new CCol()); 239 $row->addItem((new CCol(_('No SNMP interfaces found.')))->setColSpan(6)); 240 } 241 $ifTab->addRow($row); 242 243 $hostList->addRow(_('SNMP interfaces'), 244 (new CDiv($ifTab)) 245 ->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR) 246 ->setAttribute('data-type', 'snmp') 247 ->setWidth(ZBX_HOST_INTERFACE_WIDTH) 248 ); 249 250 // JMX interfaces 251 $ifTab = (new CTable())->setId('JMXInterfaces'); 252 253 $row = (new CRow())->setId('JMXInterfacesFooter'); 254 if (!array_key_exists(INTERFACE_TYPE_JMX, $existingInterfaceTypes)) { 255 $row->addItem(new CCol()); 256 $row->addItem((new CCol(_('No JMX interfaces found.')))->setColSpan(6)); 257 } 258 $ifTab->addRow($row); 259 260 $hostList->addRow(_('JMX interfaces'), 261 (new CDiv($ifTab)) 262 ->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR) 263 ->setAttribute('data-type', 'jmx') 264 ->setWidth(ZBX_HOST_INTERFACE_WIDTH) 265 ); 266 267 // IPMI interfaces 268 $ifTab = (new CTable())->setId('IPMIInterfaces'); 269 270 $row = (new CRow())->setId('IPMIInterfacesFooter'); 271 if (!array_key_exists(INTERFACE_TYPE_IPMI, $existingInterfaceTypes)) { 272 $row->addItem(new CCol()); 273 $row->addItem((new CCol(_('No IPMI interfaces found.')))->setColSpan(6)); 274 } 275 $ifTab->addRow($row); 276 277 $hostList->addRow(_('IPMI interfaces'), 278 (new CDiv($ifTab)) 279 ->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR) 280 ->setAttribute('data-type', 'ipmi') 281 ->setWidth(ZBX_HOST_INTERFACE_WIDTH) 282 ); 283} 284 285$hostList->addRow(_('Description'), 286 (new CTextArea('description', $data['description']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 287); 288 289// Proxy 290if ($data['flags'] != ZBX_FLAG_DISCOVERY_CREATED) { 291 $proxy = new CComboBox('proxy_hostid', $data['proxy_hostid'], null, [0 => _('(no proxy)')] + $data['proxies']); 292 $proxy->setEnabled($data['flags'] != ZBX_FLAG_DISCOVERY_CREATED); 293} 294else { 295 $proxy = (new CTextBox(null, $data['proxy_hostid'] != 0 ? $data['proxies'][$data['proxy_hostid']] : _('(no proxy)'), true)) 296 ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH); 297 $hostList->addVar('proxy_hostid', $data['proxy_hostid']); 298} 299$hostList->addRow(_('Monitored by proxy'), $proxy); 300 301$hostList->addRow(_('Enabled'), 302 (new CCheckBox('status', HOST_STATUS_MONITORED))->setChecked($data['status'] == HOST_STATUS_MONITORED) 303); 304 305if ($data['clone_hostid'] != 0) { 306 // host applications 307 $hostApps = API::Application()->get([ 308 'output' => ['name'], 309 'hostids' => [$data['clone_hostid']], 310 'inherited' => false, 311 'preservekeys' => true, 312 'filter' => ['flags' => ZBX_FLAG_DISCOVERY_NORMAL] 313 ]); 314 315 if ($hostApps) { 316 $applicationsList = []; 317 foreach ($hostApps as $hostAppId => $hostApp) { 318 $applicationsList[$hostAppId] = $hostApp['name']; 319 } 320 order_result($applicationsList); 321 322 $listBox = new CListBox('applications', null, 8); 323 $listBox->setAttribute('disabled', 'disabled'); 324 $listBox->addItems($applicationsList); 325 $hostList->addRow(_('Applications'), $listBox); 326 } 327 328 // host items 329 $hostItems = API::Item()->get([ 330 'output' => ['itemid', 'hostid', 'key_', 'name'], 331 'hostids' => [$data['clone_hostid']], 332 'inherited' => false, 333 'filter' => ['flags' => ZBX_FLAG_DISCOVERY_NORMAL] 334 ]); 335 336 if ($hostItems) { 337 $hostItems = CMacrosResolverHelper::resolveItemNames($hostItems); 338 339 $itemsList = []; 340 foreach ($hostItems as $hostItem) { 341 $itemsList[$hostItem['itemid']] = $hostItem['name_expanded']; 342 } 343 order_result($itemsList); 344 345 $listBox = new CListBox('items', null, 8); 346 $listBox->setAttribute('disabled', 'disabled'); 347 $listBox->addItems($itemsList); 348 $hostList->addRow(_('Items'), $listBox); 349 } 350 351 // host triggers 352 $hostTriggers = API::Trigger()->get([ 353 'output' => ['triggerid', 'description'], 354 'selectItems' => ['type'], 355 'hostids' => [$data['clone_hostid']], 356 'inherited' => false, 357 'filter' => ['flags' => [ZBX_FLAG_DISCOVERY_NORMAL]] 358 ]); 359 360 if ($hostTriggers) { 361 $triggersList = []; 362 363 foreach ($hostTriggers as $hostTrigger) { 364 if (httpItemExists($hostTrigger['items'])) { 365 continue; 366 } 367 $triggersList[$hostTrigger['triggerid']] = $hostTrigger['description']; 368 } 369 370 if ($triggersList) { 371 order_result($triggersList); 372 373 $listBox = new CListBox('triggers', null, 8); 374 $listBox->setAttribute('disabled', 'disabled'); 375 $listBox->addItems($triggersList); 376 $hostList->addRow(_('Triggers'), $listBox); 377 } 378 } 379 380 // host graphs 381 $hostGraphs = API::Graph()->get([ 382 'output' => ['graphid', 'name'], 383 'selectHosts' => ['hostid'], 384 'selectItems' => ['type'], 385 'hostids' => [$data['clone_hostid']], 386 'inherited' => false, 387 'filter' => ['flags' => [ZBX_FLAG_DISCOVERY_NORMAL]] 388 ]); 389 390 if ($hostGraphs) { 391 $graphsList = []; 392 foreach ($hostGraphs as $hostGraph) { 393 if (count($hostGraph['hosts']) > 1) { 394 continue; 395 } 396 if (httpItemExists($hostGraph['items'])) { 397 continue; 398 } 399 $graphsList[$hostGraph['graphid']] = $hostGraph['name']; 400 } 401 402 if ($graphsList) { 403 order_result($graphsList); 404 405 $listBox = new CListBox('graphs', null, 8); 406 $listBox->setAttribute('disabled', 'disabled'); 407 $listBox->addItems($graphsList); 408 $hostList->addRow(_('Graphs'), $listBox); 409 } 410 } 411 412 // discovery rules 413 $hostDiscoveryRuleIds = []; 414 415 $hostDiscoveryRules = API::DiscoveryRule()->get([ 416 'output' => ['itemid', 'hostid', 'key_', 'name'], 417 'hostids' => [$data['clone_hostid']], 418 'inherited' => false 419 ]); 420 421 if ($hostDiscoveryRules) { 422 $hostDiscoveryRules = CMacrosResolverHelper::resolveItemNames($hostDiscoveryRules); 423 424 $discoveryRuleList = []; 425 foreach ($hostDiscoveryRules as $discoveryRule) { 426 $discoveryRuleList[$discoveryRule['itemid']] = $discoveryRule['name_expanded']; 427 } 428 order_result($discoveryRuleList); 429 $hostDiscoveryRuleIds = array_keys($discoveryRuleList); 430 431 $listBox = new CListBox('discoveryRules', null, 8); 432 $listBox->setAttribute('disabled', 'disabled'); 433 $listBox->addItems($discoveryRuleList); 434 $hostList->addRow(_('Discovery rules'), $listBox); 435 } 436 437 // item prototypes 438 $hostItemPrototypes = API::ItemPrototype()->get([ 439 'output' => ['itemid', 'hostid', 'key_', 'name'], 440 'hostids' => [$data['clone_hostid']], 441 'discoveryids' => $hostDiscoveryRuleIds, 442 'inherited' => false 443 ]); 444 445 if ($hostItemPrototypes) { 446 $hostItemPrototypes = CMacrosResolverHelper::resolveItemNames($hostItemPrototypes); 447 448 $prototypeList = []; 449 foreach ($hostItemPrototypes as $itemPrototype) { 450 $prototypeList[$itemPrototype['itemid']] = $itemPrototype['name_expanded']; 451 } 452 order_result($prototypeList); 453 454 $listBox = new CListBox('itemsPrototypes', null, 8); 455 $listBox->setAttribute('disabled', 'disabled'); 456 $listBox->addItems($prototypeList); 457 $hostList->addRow(_('Item prototypes'), $listBox); 458 } 459 460 // Trigger prototypes 461 $hostTriggerPrototypes = API::TriggerPrototype()->get([ 462 'output' => ['triggerid', 'description'], 463 'selectItems' => ['type'], 464 'hostids' => [$data['clone_hostid']], 465 'discoveryids' => $hostDiscoveryRuleIds, 466 'inherited' => false 467 ]); 468 469 if ($hostTriggerPrototypes) { 470 $prototypeList = []; 471 foreach ($hostTriggerPrototypes as $triggerPrototype) { 472 // skip trigger prototypes with web items 473 if (httpItemExists($triggerPrototype['items'])) { 474 continue; 475 } 476 $prototypeList[$triggerPrototype['triggerid']] = $triggerPrototype['description']; 477 } 478 479 if ($prototypeList) { 480 order_result($prototypeList); 481 482 $listBox = new CListBox('triggerprototypes', null, 8); 483 $listBox->setAttribute('disabled', 'disabled'); 484 $listBox->addItems($prototypeList); 485 $hostList->addRow(_('Trigger prototypes'), $listBox); 486 } 487 } 488 489 // Graph prototypes 490 $hostGraphPrototypes = API::GraphPrototype()->get([ 491 'output' => ['graphid', 'name'], 492 'selectHosts' => ['hostid'], 493 'hostids' => [$data['clone_hostid']], 494 'discoveryids' => $hostDiscoveryRuleIds, 495 'inherited' => false 496 ]); 497 498 if ($hostGraphPrototypes) { 499 $prototypeList = []; 500 foreach ($hostGraphPrototypes as $graphPrototype) { 501 if (count($graphPrototype['hosts']) == 1) { 502 $prototypeList[$graphPrototype['graphid']] = $graphPrototype['name']; 503 } 504 } 505 order_result($prototypeList); 506 507 $listBox = new CListBox('graphPrototypes', null, 8); 508 $listBox->setAttribute('disabled', 'disabled'); 509 $listBox->addItems($prototypeList); 510 $hostList->addRow(_('Graph prototypes'), $listBox); 511 } 512 513 // host prototypes 514 $hostPrototypes = API::HostPrototype()->get([ 515 'output' => ['hostid', 'name'], 516 'discoveryids' => $hostDiscoveryRuleIds, 517 'inherited' => false 518 ]); 519 520 if ($hostPrototypes) { 521 $prototypeList = []; 522 foreach ($hostPrototypes as $hostPrototype) { 523 $prototypeList[$hostPrototype['hostid']] = $hostPrototype['name']; 524 } 525 order_result($prototypeList); 526 527 $listBox = new CListBox('hostPrototypes', null, 8); 528 $listBox->setAttribute('disabled', 'disabled'); 529 $listBox->addItems($prototypeList); 530 $hostList->addRow(_('Host prototypes'), $listBox); 531 } 532 533 // web scenarios 534 $httpTests = API::HttpTest()->get([ 535 'output' => ['httptestid', 'name'], 536 'hostids' => [$data['clone_hostid']], 537 'inherited' => false 538 ]); 539 540 if ($httpTests) { 541 $httpTestList = []; 542 543 foreach ($httpTests as $httpTest) { 544 $httpTestList[$httpTest['httptestid']] = $httpTest['name']; 545 } 546 547 order_result($httpTestList); 548 549 $listBox = new CListBox('httpTests', null, 8); 550 $listBox->setAttribute('disabled', 'disabled'); 551 $listBox->addItems($httpTestList); 552 $hostList->addRow(_('Web scenarios'), $listBox); 553 } 554} 555 556$divTabs->addTab('hostTab', _('Host'), $hostList); 557 558// templates 559$tmplList = new CFormList(); 560 561// templates for normal hosts 562if ($data['flags'] != ZBX_FLAG_DISCOVERY_CREATED) { 563 $ignoredTemplates = []; 564 565 $linkedTemplateTable = (new CTable()) 566 ->setAttribute('style', 'width: 100%;') 567 ->setHeader([_('Name'), _('Action')]); 568 569 foreach ($data['linked_templates'] as $template) { 570 $tmplList->addVar('templates[]', $template['templateid']); 571 572 if (array_key_exists($template['templateid'], $data['writable_templates'])) { 573 $template_link = (new CLink($template['name'], 574 'templates.php?form=update&templateid='.$template['templateid'] 575 ))->setTarget('_blank'); 576 } 577 else { 578 $template_link = new CSpan($template['name']); 579 } 580 581 $linkedTemplateTable->addRow([ 582 $template_link, 583 (new CCol( 584 new CHorList([ 585 (new CSimpleButton(_('Unlink'))) 586 ->onClick('javascript: submitFormWithParam('. 587 '"'.$frmHost->getName().'", "unlink['.$template['templateid'].']", "1"'. 588 ');') 589 ->addClass(ZBX_STYLE_BTN_LINK), 590 array_key_exists($template['templateid'], $data['original_templates']) 591 ? (new CSimpleButton(_('Unlink and clear'))) 592 ->onClick('javascript: submitFormWithParam('. 593 '"'.$frmHost->getName().'", "unlink_and_clear['.$template['templateid'].']", "1"'. 594 ');') 595 ->addClass(ZBX_STYLE_BTN_LINK) 596 : null 597 ]) 598 ))->addClass(ZBX_STYLE_NOWRAP) 599 ], null, 'conditions_'.$template['templateid']); 600 601 $ignoredTemplates[$template['templateid']] = $template['name']; 602 } 603 604 $tmplList->addRow(_('Linked templates'), 605 (new CDiv($linkedTemplateTable)) 606 ->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR) 607 ->setAttribute('style', 'min-width: '.ZBX_TEXTAREA_BIG_WIDTH.'px;') 608 ); 609 610 // create new linked template table 611 $newTemplateTable = (new CTable()) 612 ->addRow([ 613 (new CMultiSelect([ 614 'name' => 'add_templates[]', 615 'objectName' => 'templates', 616 'ignored' => $ignoredTemplates, 617 'popup' => [ 618 'parameters' => 'srctbl=templates&srcfld1=hostid&srcfld2=host&dstfrm='.$frmHost->getName(). 619 '&dstfld1=add_templates_&templated_hosts=1&multiselect=1' 620 ] 621 ]))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 622 ]) 623 ->addRow([ 624 (new CSimpleButton(_('Add'))) 625 ->onClick('javascript: submitFormWithParam("'.$frmHost->getName().'", "add_template", "1");') 626 ->addClass(ZBX_STYLE_BTN_LINK) 627 ]); 628 629 $tmplList->addRow(_('Link new templates'), 630 (new CDiv($newTemplateTable)) 631 ->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR) 632 ->setAttribute('style', 'min-width: '.ZBX_TEXTAREA_BIG_WIDTH.'px;') 633 ); 634} 635// templates for discovered hosts 636else { 637 $linkedTemplateTable = (new CTable()) 638 ->setAttribute('style', 'width: 100%;') 639 ->setHeader([_('Name')]); 640 641 foreach ($data['linked_templates'] as $template) { 642 $tmplList->addVar('templates[]', $template['templateid']); 643 $template_link = (new CLink($template['name'], 'templates.php?form=update&templateid='.$template['templateid'])) 644 ->setTarget('_blank'); 645 646 $linkedTemplateTable->addRow($template_link, null, 'conditions_'.$template['templateid']); 647 } 648 649 $tmplList->addRow(_('Linked templates'), 650 (new CDiv($linkedTemplateTable)) 651 ->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR) 652 ->setAttribute('style', 'min-width: '.ZBX_TEXTAREA_BIG_WIDTH.'px;') 653 ); 654} 655 656$divTabs->addTab('templateTab', _('Templates'), $tmplList); 657 658/* 659 * IPMI 660 */ 661if ($data['flags'] != ZBX_FLAG_DISCOVERY_CREATED) { 662 $cmbIPMIAuthtype = new CListBox('ipmi_authtype', $data['ipmi_authtype'], 7, null, ipmiAuthTypes()); 663 $cmbIPMIPrivilege = new CListBox('ipmi_privilege', $data['ipmi_privilege'], 5, null, ipmiPrivileges()); 664} 665else { 666 $cmbIPMIAuthtype = [ 667 (new CTextBox('ipmi_authtype_name', ipmiAuthTypes($data['ipmi_authtype']), true)) 668 ->setWidth(ZBX_TEXTAREA_SMALL_WIDTH), 669 new CVar('ipmi_authtype', $data['ipmi_authtype']) 670 ]; 671 $cmbIPMIPrivilege = [ 672 (new CTextBox('ipmi_privilege_name', ipmiPrivileges($data['ipmi_privilege']), true)) 673 ->setWidth(ZBX_TEXTAREA_SMALL_WIDTH), 674 new CVar('ipmi_privilege', $data['ipmi_privilege']) 675 ]; 676} 677 678$divTabs->addTab('ipmiTab', _('IPMI'), 679 (new CFormList()) 680 ->addRow(_('Authentication algorithm'), $cmbIPMIAuthtype) 681 ->addRow(_('Privilege level'), $cmbIPMIPrivilege) 682 ->addRow(_('Username'), 683 (new CTextBox('ipmi_username', $data['ipmi_username'], ($data['flags'] == ZBX_FLAG_DISCOVERY_CREATED))) 684 ->setWidth(ZBX_TEXTAREA_SMALL_WIDTH) 685 ) 686 ->addRow(_('Password'), 687 (new CTextBox('ipmi_password', $data['ipmi_password'], ($data['flags'] == ZBX_FLAG_DISCOVERY_CREATED))) 688 ->setWidth(ZBX_TEXTAREA_SMALL_WIDTH) 689 ) 690); 691 692/* 693 * Macros 694 */ 695$macrosView = new CView('hostmacros', [ 696 'macros' => $data['macros'], 697 'show_inherited_macros' => $data['show_inherited_macros'], 698 'is_template' => false, 699 'readonly' => ($data['flags'] == ZBX_FLAG_DISCOVERY_CREATED) 700]); 701$divTabs->addTab('macroTab', _('Macros'), $macrosView->render()); 702 703$inventoryFormList = new CFormList('inventorylist'); 704 705$inventoryFormList->addRow(null, 706 (new CRadioButtonList('inventory_mode', (int) $data['inventory_mode'])) 707 ->addValue(_('Disabled'), HOST_INVENTORY_DISABLED) 708 ->addValue(_('Manual'), HOST_INVENTORY_MANUAL) 709 ->addValue(_('Automatic'), HOST_INVENTORY_AUTOMATIC) 710 ->setEnabled($data['flags'] != ZBX_FLAG_DISCOVERY_CREATED) 711 ->setModern(true) 712); 713if ($data['flags'] == ZBX_FLAG_DISCOVERY_CREATED) { 714 $inventoryFormList->addVar('inventory_mode', $data['inventory_mode']); 715} 716 717$hostInventoryTable = DB::getSchema('host_inventory'); 718$hostInventoryFields = getHostInventories(); 719 720foreach ($hostInventoryFields as $inventoryNo => $inventoryInfo) { 721 $field_name = $inventoryInfo['db_field']; 722 723 if (!array_key_exists($field_name, $data['host_inventory'])) { 724 $data['host_inventory'][$field_name] = ''; 725 } 726 727 if ($hostInventoryTable['fields'][$field_name]['type'] == DB::FIELD_TYPE_TEXT) { 728 $input = (new CTextArea('host_inventory['.$field_name.']', $data['host_inventory'][$field_name])) 729 ->setWidth(ZBX_TEXTAREA_BIG_WIDTH); 730 } 731 else { 732 $field_length = $hostInventoryTable['fields'][$field_name]['length']; 733 734 $input = (new CTextBox('host_inventory['.$field_name.']', $data['host_inventory'][$field_name])) 735 ->setWidth(($field_length < 39) ? ZBX_TEXTAREA_SMALL_WIDTH : ZBX_TEXTAREA_BIG_WIDTH) 736 ->setAttribute('maxlength', $field_length); 737 } 738 739 if ($data['inventory_mode'] == HOST_INVENTORY_DISABLED) { 740 $input->setAttribute('disabled', 'disabled'); 741 } 742 743 // link to populating item at the right side (if any) 744 if (array_key_exists($inventoryNo, $data['inventory_items'])) { 745 $name = $data['inventory_items'][$inventoryNo]['name_expanded']; 746 747 $link = (new CLink($name, 'items.php?form=update&itemid='.$data['inventory_items'][$inventoryNo]['itemid'])) 748 ->setAttribute('title', _s('This field is automatically populated by item "%s".', $name)); 749 750 $inventory_item = (new CSpan([' ← ', $link]))->addClass('populating_item'); 751 if ($data['inventory_mode'] != HOST_INVENTORY_AUTOMATIC) { 752 // those links are visible only in automatic mode 753 $inventory_item->addStyle('display: none'); 754 } 755 756 // this will be used for disabling fields via jquery 757 $input->addClass('linked_to_item'); 758 if ($data['inventory_mode'] == HOST_INVENTORY_AUTOMATIC) { 759 $input->setAttribute('disabled', 'disabled'); 760 } 761 } 762 else { 763 $inventory_item = null; 764 } 765 766 $inventoryFormList->addRow($inventoryInfo['title'], [$input, $inventory_item]); 767} 768 769$divTabs->addTab('inventoryTab', _('Host inventory'), $inventoryFormList); 770 771// Encryption form list. 772$encryption_form_list = (new CFormList('encryption')) 773 ->addRow(_('Connections to host'), 774 (new CRadioButtonList('tls_connect', (int) $data['tls_connect'])) 775 ->addValue(_('No encryption'), HOST_ENCRYPTION_NONE) 776 ->addValue(_('PSK'), HOST_ENCRYPTION_PSK) 777 ->addValue(_('Certificate'), HOST_ENCRYPTION_CERTIFICATE) 778 ->setModern(true) 779 ->setEnabled($data['flags'] != ZBX_FLAG_DISCOVERY_CREATED) 780 ) 781 ->addRow(_('Connections from host'), [ 782 new CLabel([(new CCheckBox('tls_in_none'))->setEnabled($data['flags'] != ZBX_FLAG_DISCOVERY_CREATED), 783 _('No encryption') 784 ]), 785 BR(), 786 new CLabel([(new CCheckBox('tls_in_psk'))->setEnabled($data['flags'] != ZBX_FLAG_DISCOVERY_CREATED), _('PSK')]), 787 BR(), 788 new CLabel([(new CCheckBox('tls_in_cert'))->setEnabled($data['flags'] != ZBX_FLAG_DISCOVERY_CREATED), 789 _('Certificate') 790 ]) 791 ]) 792 ->addRow(_('PSK identity'), 793 (new CTextBox('tls_psk_identity', $data['tls_psk_identity'], $data['flags'] == ZBX_FLAG_DISCOVERY_CREATED, 128)) 794 ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 795 ) 796 ->addRow(_('PSK'), 797 (new CTextBox('tls_psk', $data['tls_psk'], $data['flags'] == ZBX_FLAG_DISCOVERY_CREATED, 512)) 798 ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 799 ) 800 ->addRow(_('Issuer'), 801 (new CTextBox('tls_issuer', $data['tls_issuer'], $data['flags'] == ZBX_FLAG_DISCOVERY_CREATED, 1024)) 802 ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 803 ) 804 ->addRow(_x('Subject', 'encryption certificate'), 805 (new CTextBox('tls_subject', $data['tls_subject'], $data['flags'] == ZBX_FLAG_DISCOVERY_CREATED, 1024)) 806 ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 807 ); 808 809$divTabs->addTab('encryptionTab', _('Encryption'), $encryption_form_list); 810 811/* 812 * footer 813 */ 814// Do not display the clone and delete buttons for clone forms and new host forms. 815if ($data['hostid'] != 0) { 816 $divTabs->setFooter(makeFormFooter( 817 new CSubmit('update', _('Update')), 818 [ 819 new CSubmit('clone', _('Clone')), 820 new CSubmit('full_clone', _('Full clone')), 821 new CButtonDelete(_('Delete selected host?'), url_param('form').url_param('hostid').url_param('groupid')), 822 new CButtonCancel(url_param('groupid')) 823 ] 824 )); 825} 826else { 827 $divTabs->setFooter(makeFormFooter( 828 new CSubmit('add', _('Add')), 829 [new CButtonCancel(url_param('groupid'))] 830 )); 831} 832 833$frmHost->addItem($divTabs); 834 835$widget->addItem($frmHost); 836 837return $widget; 838