$frmHost = (new CForm())->setName('templatesForm')->addVar('form', $data['form'])->addVar('groupid', $data['groupId']);
if ($data['templateId'] != 0) {
    $frmHost->addVar('templateid', $data['templateId']);
}
if ($data['templateId'] != 0 && !hasRequest('form_refresh')) {
    $host = $this->data['dbTemplate']['host'];
    $visiblename = $this->data['dbTemplate']['name'];
    // display empty visible name if equal to host name
    if ($visiblename === $host) {
        $visiblename = '';
    }
    $macros = $this->data['dbTemplate']['macros'];
    $templateIds = $this->data['original_templates'];
}
if ($data['show_inherited_macros']) {
    $macros = mergeInheritedMacros($macros, getInheritedMacros($templateIds));
}
$macros = array_values(order_macros($macros, 'macro'));
$clear_templates = array_intersect($clear_templates, array_keys($this->data['original_templates']));
$clear_templates = array_diff($clear_templates, array_keys($templateIds));
natcasesort($templateIds);
$frmHost->addVar('clear_templates', $clear_templates);
// TEMPLATE WIDGET {
$templateList = (new CFormList('hostlist'))->addRow(_('Template name'), (new CTextBox('template_name', $host, false, 128))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)->setAttribute('autofocus', 'autofocus'))->addRow(_('Visible name'), (new CTextBox('visiblename', $visiblename, false, 128))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH));
$groupsTB = new CTweenBox($frmHost, 'groups', $data['groupIds'], 10);
if ($data['form'] === 'update') {
    // Add existing template groups to list and, depending on permissions show name as enabled or disabled.
    $groupsInList = [];
    foreach ($data['groupsAll'] as $group) {
        if (isset($data['groupIds'][$group['groupid']])) {
            $groupsTB->addItem($group['groupid'], $group['name'], true, isset($data['groupsAllowed'][$group['groupid']]));
Example #2
0
 if ($data['flags'] == ZBX_FLAG_DISCOVERY_CREATED) {
     if ($data['proxy_hostid'] != 0) {
         $data['proxies'] = API::Proxy()->get(['output' => ['host'], 'proxyids' => [$data['proxy_hostid']], 'preservekeys' => true]);
     } else {
         $data['proxies'] = [];
     }
 } else {
     $data['proxies'] = API::Proxy()->get(['output' => ['host'], 'preservekeys' => true]);
     order_result($data['proxies'], 'host');
 }
 foreach ($data['proxies'] as &$proxy) {
     $proxy = $proxy['host'];
 }
 unset($proxy);
 if ($data['show_inherited_macros']) {
     $data['macros'] = mergeInheritedMacros($data['macros'], getInheritedMacros($data['templates']));
 }
 $data['macros'] = array_values(order_macros($data['macros'], 'macro'));
 if (!$data['macros'] && $data['flags'] != ZBX_FLAG_DISCOVERY_CREATED) {
     $macro = ['macro' => '', 'value' => ''];
     if ($data['show_inherited_macros']) {
         $macro['type'] = MACRO_TYPE_HOSTMACRO;
     }
     $data['macros'][] = $macro;
 }
 // groups with RW permissions
 $data['groupsAllowed'] = API::HostGroup()->get(['output' => [], 'editable' => true, 'preservekeys' => true]);
 // all available groups
 $data['groupsAll'] = API::HostGroup()->get(['output' => ['groupid', 'name']]);
 CArrayHelper::sort($data['groupsAll'], ['name']);
 if ($data['templates']) {
    $tmplList->addRow(_('Link new templates'), (new CDiv($newTemplateTable))->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR)->setAttribute('style', 'min-width: ' . ZBX_TEXTAREA_BIG_WIDTH . 'px;'));
}
$divTabs->addTab('templateTab', _('Templates'), $tmplList);
// display inherited parameters only for hosts prototypes on hosts
if ($parentHost['status'] != HOST_STATUS_TEMPLATE) {
    // IPMI
    $ipmiList = new CFormList();
    $ipmiList->addRow(_('Authentication algorithm'), (new CTextBox('ipmi_authtype', ipmiAuthTypes($parentHost['ipmi_authtype']), true))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH));
    $ipmiList->addRow(_('Privilege level'), (new CTextBox('ipmi_privilege', ipmiPrivileges($parentHost['ipmi_privilege']), true))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH));
    $ipmiList->addRow(_('Username'), (new CTextBox('ipmi_username', $parentHost['ipmi_username'], true))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH));
    $ipmiList->addRow(_('Password'), (new CTextBox('ipmi_password', $parentHost['ipmi_password'], true))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH));
    $divTabs->addTab('ipmiTab', _('IPMI'), $ipmiList);
    // macros
    $macros = $parentHost['macros'];
    if ($data['show_inherited_macros']) {
        $macros = mergeInheritedMacros($macros, getInheritedMacros(zbx_objectValues($hostPrototype['templates'], 'templateid')));
    }
    $macros = array_values(order_macros($macros, 'macro'));
    $macrosView = new CView('hostmacros', ['macros' => $macros, 'show_inherited_macros' => $data['show_inherited_macros'], 'is_template' => false, 'readonly' => true]);
    $divTabs->addTab('macroTab', _('Macros'), $macrosView->render());
}
$inventoryFormList = (new CFormList('inventorylist'))->addRow(null, (new CRadioButtonList('inventory_mode', (int) $hostPrototype['inventory']['inventory_mode']))->addValue(_('Disabled'), HOST_INVENTORY_DISABLED)->addValue(_('Manual'), HOST_INVENTORY_MANUAL)->addValue(_('Automatic'), HOST_INVENTORY_AUTOMATIC)->setEnabled($hostPrototype['templateid'] == 0)->setModern(true));
$divTabs->addTab('inventoryTab', _('Host inventory'), $inventoryFormList);
// Encryption form list.
$encryption_form_list = (new CFormList('encryption'))->addRow(_('Connections to host'), (new CRadioButtonList('tls_connect', (int) $parentHost['tls_connect']))->addValue(_('No encryption'), HOST_ENCRYPTION_NONE)->addValue(_('PSK'), HOST_ENCRYPTION_PSK)->addValue(_('Certificate'), HOST_ENCRYPTION_CERTIFICATE)->setModern(true)->setEnabled(false))->addRow(_('Connections from host'), [new CLabel([(new CCheckBox('tls_in_none'))->setAttribute('disabled', 'disabled'), _('No encryption')]), BR(), new CLabel([(new CCheckBox('tls_in_psk'))->setAttribute('disabled', 'disabled'), _('PSK')]), BR(), new CLabel([(new CCheckBox('tls_in_cert'))->setAttribute('disabled', 'disabled'), _('Certificate')])])->addRow(_('PSK identity'), (new CTextBox('tls_psk_identity', $parentHost['tls_psk_identity'], false, 128))->setWidth(ZBX_TEXTAREA_BIG_WIDTH)->setAttribute('disabled', 'disabled'))->addRow(_('PSK'), (new CTextBox('tls_psk', $parentHost['tls_psk'], false, 512))->setWidth(ZBX_TEXTAREA_BIG_WIDTH)->setAttribute('disabled', 'disabled'))->addRow(_('Issuer'), (new CTextBox('tls_issuer', $parentHost['tls_issuer'], false, 1024))->setWidth(ZBX_TEXTAREA_BIG_WIDTH)->setAttribute('disabled', 'disabled'))->addRow(_x('Subject', 'encryption certificate'), (new CTextBox('tls_subject', $parentHost['tls_subject'], false, 1024))->setWidth(ZBX_TEXTAREA_BIG_WIDTH)->setAttribute('disabled', 'disabled'));
$divTabs->addTab('encryptionTab', _('Encryption'), $encryption_form_list);
/*
 * footer
 */
if (isset($hostPrototype['hostid'])) {
    $btnDelete = new CButtonDelete(_('Delete selected host prototype?'), url_param('form') . url_param('hostid') . url_param('parent_discoveryid'));