protected function doAction() { $sortField = $this->getInput('sort', CProfile::get('web.media_types.php.sort', 'description')); $sortOrder = $this->getInput('sortorder', CProfile::get('web.media_types.php.sortorder', ZBX_SORT_UP)); CProfile::update('web.media_type.php.sort', $sortField, PROFILE_TYPE_STR); CProfile::update('web.media_types.php.sortorder', $sortOrder, PROFILE_TYPE_STR); $config = select_config(); $data = ['uncheck' => $this->hasInput('uncheck'), 'sort' => $sortField, 'sortorder' => $sortOrder]; // get media types $data['mediatypes'] = API::Mediatype()->get(['output' => ['mediatypeid', 'description', 'type', 'smtp_server', 'smtp_helo', 'smtp_email', 'exec_path', 'gsm_modem', 'username', 'status'], 'limit' => $config['search_limit'] + 1, 'editable' => true, 'preservekeys' => true]); if ($data['mediatypes']) { // get media types used in actions $actions = API::Action()->get(['output' => ['actionid', 'name'], 'selectOperations' => ['operationtype', 'opmessage'], 'mediatypeids' => array_keys($data['mediatypes'])]); foreach ($data['mediatypes'] as &$mediaType) { $mediaType['typeid'] = $mediaType['type']; $mediaType['type'] = media_type2str($mediaType['type']); $mediaType['listOfActions'] = []; foreach ($actions as $action) { foreach ($action['operations'] as $operation) { if ($operation['operationtype'] == OPERATION_TYPE_MESSAGE && $operation['opmessage']['mediatypeid'] == $mediaType['mediatypeid']) { $mediaType['listOfActions'][$action['actionid']] = ['actionid' => $action['actionid'], 'name' => $action['name']]; } } } order_result($mediaType['listOfActions'], 'name'); } unset($mediaType); order_result($data['mediatypes'], $sortField, $sortOrder); } $url = (new CUrl('zabbix.php'))->setArgument('action', 'mediatype.list'); $data['paging'] = getPagingLine($data['mediatypes'], $sortOrder, $url); $response = new CControllerResponseData($data); $response->setTitle(_('Configuration of media types')); $this->setResponse($response); }
protected function checkInput() { $fields = ['mediatypeid' => 'db media_type.mediatypeid', 'type' => 'db media_type.type|in ' . implode(',', array_keys(media_type2str())), 'description' => 'db media_type.description', 'smtp_server' => 'db media_type.smtp_server', 'smtp_port' => 'db media_type.smtp_port', 'smtp_helo' => 'db media_type.smtp_helo', 'smtp_email' => 'db media_type.smtp_email', 'smtp_security' => 'db media_type.smtp_security|in ' . SMTP_CONNECTION_SECURITY_NONE . ',' . SMTP_CONNECTION_SECURITY_STARTTLS . ',' . SMTP_CONNECTION_SECURITY_SSL_TLS, 'smtp_verify_peer' => 'db media_type.smtp_verify_peer|in 0,1', 'smtp_verify_host' => 'db media_type.smtp_verify_host|in 0,1', 'smtp_authentication' => 'db media_type.smtp_authentication|in ' . SMTP_AUTHENTICATION_NONE . ',' . SMTP_AUTHENTICATION_NORMAL, 'exec_path' => 'db media_type.exec_path', 'eztext_limit' => 'in ' . EZ_TEXTING_LIMIT_USA . ',' . EZ_TEXTING_LIMIT_CANADA, 'exec_params' => 'array media_type.exec_params', 'exec_params_count' => 'int32', 'gsm_modem' => 'db media_type.gsm_modem', 'jabber_username' => 'db media_type.username', 'eztext_username' => 'db media_type.username', 'smtp_username' => 'db media_type.username', 'passwd' => 'db media_type.passwd', 'status' => 'db media_type.status|in ' . MEDIA_TYPE_STATUS_ACTIVE . ',' . MEDIA_TYPE_STATUS_DISABLED]; $ret = $this->validateInput($fields); if (!$ret) { $this->setResponse(new CControllerResponseFatal()); } return $ret; }
protected function checkInput() { $fields = ['type' => 'required|db media_type.type|in ' . implode(',', array_keys(media_type2str())), 'description' => 'db media_type.description|not_empty', 'smtp_server' => 'db media_type.smtp_server', 'smtp_port' => 'db media_type.smtp_port', 'smtp_helo' => 'db media_type.smtp_helo', 'smtp_email' => 'db media_type.smtp_email', 'smtp_security' => 'db media_type.smtp_security|in ' . SMTP_CONNECTION_SECURITY_NONE . ',' . SMTP_CONNECTION_SECURITY_STARTTLS . ',' . SMTP_CONNECTION_SECURITY_SSL_TLS, 'smtp_verify_peer' => 'db media_type.smtp_verify_peer|in 0,1', 'smtp_verify_host' => 'db media_type.smtp_verify_host|in 0,1', 'smtp_authentication' => 'db media_type.smtp_authentication|in ' . SMTP_AUTHENTICATION_NONE . ',' . SMTP_AUTHENTICATION_NORMAL, 'exec_path' => 'db media_type.exec_path', 'eztext_limit' => 'in ' . EZ_TEXTING_LIMIT_USA . ',' . EZ_TEXTING_LIMIT_CANADA, 'exec_params' => 'array media_type.exec_params', 'exec_params_count' => 'int32', 'gsm_modem' => 'db media_type.gsm_modem', 'jabber_username' => 'db media_type.username', 'eztext_username' => 'db media_type.username', 'smtp_username' => 'db media_type.username', 'passwd' => 'db media_type.passwd', 'status' => 'db media_type.status|in ' . MEDIA_TYPE_STATUS_ACTIVE . ',' . MEDIA_TYPE_STATUS_DISABLED]; $ret = $this->validateInput($fields); if (!$ret) { switch ($this->GetValidationError()) { case self::VALIDATION_ERROR: $response = new CControllerResponseRedirect('zabbix.php?action=mediatype.edit'); $response->setFormData($this->getInputAll()); $response->setMessageError(_('Cannot add media type')); $this->setResponse($response); break; case self::VALIDATION_FATAL_ERROR: $this->setResponse(new CControllerResponseFatal()); break; } } return $ret; }
$actionLinks = array(); if (!empty($mediaType['listOfActions'])) { foreach ($mediaType['listOfActions'] as $action) { $actionLinks[] = new CLink($action['name'], 'actionconf.php?form=update&actionid=' . $action['actionid']); $actionLinks[] = ', '; } array_pop($actionLinks); } else { $actionLinks = '-'; } $actionColumn = new CCol($actionLinks); $actionColumn->setAttribute('style', 'white-space: normal;'); $statusLink = 'media_types.php?go=' . ($mediaType['status'] == MEDIA_TYPE_STATUS_DISABLED ? 'activate' : 'disable') . '&mediatypeids' . SQUAREBRACKETS . '=' . $mediaType['mediatypeid']; $status = MEDIA_TYPE_STATUS_ACTIVE == $mediaType['status'] ? new CLink(_('Enabled'), $statusLink, 'enabled') : new CLink(_('Disabled'), $statusLink, 'disabled'); // append row $mediaTypeTable->addRow(array(new CCheckBox('mediatypeids[' . $mediaType['mediatypeid'] . ']', null, null, $mediaType['mediatypeid']), $this->data['displayNodes'] ? $mediaType['nodename'] : null, new CLink($mediaType['description'], '?form=edit&mediatypeid=' . $mediaType['mediatypeid']), media_type2str($mediaType['typeid']), $status, $actionColumn, $details)); } // create go button $goComboBox = new CComboBox('go'); $goOption = new CComboItem('activate', _('Enable selected')); $goOption->setAttribute('confirm', _('Enable selected media types?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('disable', _('Disable selected')); $goOption->setAttribute('confirm', _('Disable selected media types?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('delete', _('Delete selected')); $goOption->setAttribute('confirm', _('Delete selected media types?')); $goComboBox->addItem($goOption); $goButton = new CSubmit('goButton', _('Go') . ' (0)'); $goButton->setAttribute('id', 'goButton'); zbx_add_post_js('chkbxRange.pageGoName = "mediatypeids";');
} else { $table = new CTableInfo(S_NO_MEDIA_TYPES_DEFINED); $table->setHeader(array(make_sorting_link(S_TYPE, 'mt.type'), make_sorting_link(S_DESCRIPTION, 'mt.description'), S_DETAILS)); $result = DBselect('SELECT mt.* ' . ' FROM media_type mt' . ' WHERE ' . DBin_node('mt.mediatypeid') . order_by('mt.type,mt.description')); while ($row = DBfetch($result)) { switch ($row['type']) { case MEDIA_TYPE_EMAIL: $details = S_SMTP_SERVER . ": '" . $row['smtp_server'] . "', " . S_SMTP_HELO . ": '" . $row['smtp_helo'] . "', " . S_SMTP_EMAIL . ": '" . $row['smtp_email'] . "'"; break; case MEDIA_TYPE_EXEC: $details = S_SCRIPT_NAME . ": '" . $row['exec_path'] . "'"; break; case MEDIA_TYPE_SMS: $details = S_GSM_MODEM . ": '" . $row['gsm_modem'] . "'"; break; case MEDIA_TYPE_JABBER: $details = S_JABBER_IDENTIFIER . ": '" . $row['username'] . "'"; break; default: $details = ''; } $table->addRow(array(media_type2str($row['type']), new CLink($row["description"], "?&form=update&mediatypeid=" . $row["mediatypeid"], 'action'), $details)); $row_count++; } $table->show(); } zbx_add_post_js('insert_in_element("numrows","' . $row_count . '");'); ?> <?php include_once "include/page_footer.php";
$mediaTypeView->render(); $mediaTypeView->show(); } else { $sortField = getRequest('sort', CProfile::get('web.' . $page['file'] . '.sort', 'description')); $sortOrder = getRequest('sortorder', CProfile::get('web.' . $page['file'] . '.sortorder', ZBX_SORT_UP)); CProfile::update('web.' . $page['file'] . '.sort', $sortField, PROFILE_TYPE_STR); CProfile::update('web.' . $page['file'] . '.sortorder', $sortOrder, PROFILE_TYPE_STR); $data = array('sort' => $sortField, 'sortorder' => $sortOrder); // get media types $data['mediatypes'] = API::Mediatype()->get(array('output' => API_OUTPUT_EXTEND, 'preservekeys' => true, 'editable' => true, 'limit' => $config['search_limit'] + 1)); if ($data['mediatypes']) { // get media types used in actions $actions = API::Action()->get(array('mediatypeids' => zbx_objectValues($data['mediatypes'], 'mediatypeid'), 'output' => array('actionid', 'name'), 'selectOperations' => array('operationtype', 'opmessage'), 'preservekeys' => true)); foreach ($data['mediatypes'] as $key => $mediaType) { $data['mediatypes'][$key]['typeid'] = $data['mediatypes'][$key]['type']; $data['mediatypes'][$key]['type'] = media_type2str($data['mediatypes'][$key]['type']); $data['mediatypes'][$key]['listOfActions'] = array(); if ($actions) { foreach ($actions as $actionId => $action) { foreach ($action['operations'] as $operation) { if ($operation['operationtype'] == OPERATION_TYPE_MESSAGE && $operation['opmessage']['mediatypeid'] == $mediaType['mediatypeid']) { $data['mediatypes'][$key]['listOfActions'][$actionId] = array('actionid' => $actionId, 'name' => $action['name']); } } } order_result($data['mediatypes'][$key]['listOfActions'], 'name'); } } order_result($data['mediatypes'], $sortField, $sortOrder); $data['paging'] = getPagingLine($data['mediatypes'], $sortOrder); } else {
$actionLinks = array(); if (!empty($mediaType['listOfActions'])) { foreach ($mediaType['listOfActions'] as $action) { $actionLinks[] = new CLink($action['name'], 'actionconf.php?form=update&actionid=' . $action['actionid']); $actionLinks[] = ', '; } array_pop($actionLinks); } else { $actionLinks = '-'; } $actionColumn = new CCol($actionLinks); $actionColumn->setAttribute('style', 'white-space: normal;'); $statusLink = 'media_types.php' . '?action=' . ($mediaType['status'] == MEDIA_TYPE_STATUS_DISABLED ? 'mediatype.massenable' : 'mediatype.massdisable') . '&mediatypeids[]=' . $mediaType['mediatypeid']; $status = MEDIA_TYPE_STATUS_ACTIVE == $mediaType['status'] ? new CLink(_('Enabled'), $statusLink, 'enabled') : new CLink(_('Disabled'), $statusLink, 'disabled'); // append row $mediaTypeTable->addRow(array(new CCheckBox('mediatypeids[' . $mediaType['mediatypeid'] . ']', null, null, $mediaType['mediatypeid']), new CLink($mediaType['description'], '?form=edit&mediatypeid=' . $mediaType['mediatypeid']), media_type2str($mediaType['typeid']), $status, $actionColumn, $details)); } // create go button $goComboBox = new CComboBox('action'); $goOption = new CComboItem('mediatype.massenable', _('Enable selected')); $goOption->setAttribute('confirm', _('Enable selected media types?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('mediatype.massdisable', _('Disable selected')); $goOption->setAttribute('confirm', _('Disable selected media types?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('mediatype.massdelete', _('Delete selected')); $goOption->setAttribute('confirm', _('Delete selected media types?')); $goComboBox->addItem($goOption); $goButton = new CSubmit('goButton', _('Go') . ' (0)'); $goButton->setAttribute('id', 'goButton'); zbx_add_post_js('chkbxRange.pageGoName = "mediatypeids";');
// get media types $options = array('output' => API_OUTPUT_EXTEND, 'preservekeys' => 1, 'editable' => true, 'limit' => $config['search_limit'] + 1); $data['mediatypes'] = API::Mediatype()->get($options); // get media types used in actions $options = array('mediatypeids' => zbx_objectValues($data['mediatypes'], 'mediatypeid'), 'output' => array('actionid', 'name'), 'preservekeys' => 1); $actions = API::Action()->get($options); foreach ($data['mediatypes'] as $number => $mediatype) { $data['mediatypes'][$number]['listOfActions'] = array(); foreach ($actions as $actionid => $action) { if (!empty($action['mediatypeids'])) { foreach ($action['mediatypeids'] as $actionMediaTypeId) { if ($mediatype['mediatypeid'] == $actionMediaTypeId) { $data['mediatypes'][$number]['listOfActions'][$actionid] = array('actionid' => $actionid, 'name' => $action['name']); } } } } $data['mediatypes'][$number]['usedInActions'] = !isset($mediatype['listOfActions']); // allow sort by mediatype name $data['mediatypes'][$number]['typeid'] = $data['mediatypes'][$number]['type']; $data['mediatypes'][$number]['type'] = media_type2str($data['mediatypes'][$number]['type']); } // sort data order_result($data['mediatypes'], getPageSortField('description'), getPageSortOrder()); $data['paging'] = getPagingLine($data['mediatypes']); // render view $mediaTypeView = new CView('administration.mediatypes.list', $data); $mediaTypeView->render(); $mediaTypeView->show(); } require_once dirname(__FILE__) . '/include/page_footer.php';
break; case MEDIA_TYPE_EZ_TEXTING: $details = _('Username') . NAME_DELIMITER . '"' . $mediaType['username'] . '"'; break; default: $details = ''; break; } // action list $actionLinks = []; if (!empty($mediaType['listOfActions'])) { foreach ($mediaType['listOfActions'] as $action) { $actionLinks[] = new CLink($action['name'], 'actionconf.php?form=update&actionid=' . $action['actionid']); $actionLinks[] = ', '; } array_pop($actionLinks); } else { $actionLinks = ''; } $actionColumn = new CCol($actionLinks); $actionColumn->setAttribute('style', 'white-space: normal;'); $statusLink = 'zabbix.php' . '?action=' . ($mediaType['status'] == MEDIA_TYPE_STATUS_DISABLED ? 'mediatype.enable' : 'mediatype.disable') . '&mediatypeids[]=' . $mediaType['mediatypeid']; $status = MEDIA_TYPE_STATUS_ACTIVE == $mediaType['status'] ? (new CLink(_('Enabled'), $statusLink))->addClass(ZBX_STYLE_LINK_ACTION)->addClass(ZBX_STYLE_GREEN)->addSID() : (new CLink(_('Disabled'), $statusLink))->addClass(ZBX_STYLE_LINK_ACTION)->addClass(ZBX_STYLE_RED)->addSID(); $name = new CLink($mediaType['description'], '?action=mediatype.edit&mediatypeid=' . $mediaType['mediatypeid']); // append row $mediaTypeTable->addRow([new CCheckBox('mediatypeids[' . $mediaType['mediatypeid'] . ']', $mediaType['mediatypeid']), (new CCol($name))->addClass(ZBX_STYLE_NOWRAP), media_type2str($mediaType['typeid']), $status, $actionColumn, $details]); } // append table to form $mediaTypeForm->addItem([$mediaTypeTable, $data['paging'], new CActionButtonList('action', 'mediatypeids', ['mediatype.enable' => ['name' => _('Enable'), 'confirm' => _('Enable selected media types?')], 'mediatype.disable' => ['name' => _('Disable'), 'confirm' => _('Disable selected media types?')], 'mediatype.delete' => ['name' => _('Delete'), 'confirm' => _('Delete selected media types?')]])]); // append form to widget $widget->addItem($mediaTypeForm)->show();
/** * Check required fields by type. Values for fields must not be empty. * * @param array $mediatype An array of media type data. * @param string $mediatype['description'] Name of the media type. * @param string $mediatype['type'] E-mail, Script, SMS, Jabber and Ez Texting. * * @throws APIException if the input is invalid. */ protected function checkRequiredFieldsByType(array $mediatype) { $type_validator = new CLimitedSetValidator(['values' => array_keys(media_type2str())]); if (!$type_validator->validate($mediatype['type'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect value "%1$s" in field "%2$s" for media type "%3$s".', $mediatype['type'], 'type', $mediatype['description'])); } $required_fields_by_type = [MEDIA_TYPE_EMAIL => ['smtp_server', 'smtp_helo', 'smtp_email'], MEDIA_TYPE_EXEC => ['exec_path'], MEDIA_TYPE_SMS => ['gsm_modem'], MEDIA_TYPE_JABBER => ['username'], MEDIA_TYPE_EZ_TEXTING => ['exec_path', 'username']]; foreach ($required_fields_by_type[$mediatype['type']] as $field) { // Check if fields set on Create method. For update method they are checked when type is changed. if (!array_key_exists($field, $mediatype)) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Field "%1$s" is required for media type "%2$s".', $field, $mediatype['description'])); } elseif (array_key_exists($field, $mediatype) && ($mediatype[$field] === '' || $mediatype[$field] === null)) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Field "%1$s" is missing a value for media type "%2$s".', $field, $mediatype['description'])); } } }
case MEDIA_TYPE_EMAIL: $details = S_SMTP_SERVER . ": '" . $row['smtp_server'] . "', " . S_SMTP_HELO . ": '" . $row['smtp_helo'] . "', " . S_SMTP_EMAIL . ": '" . $row['smtp_email'] . "'"; break; case MEDIA_TYPE_EXEC: $details = S_SCRIPT_NAME . ": '" . $row['exec_path'] . "'"; break; case MEDIA_TYPE_SMS: $details = S_GSM_MODEM . ": '" . $row['gsm_modem'] . "'"; break; case MEDIA_TYPE_JABBER: $details = S_JABBER_IDENTIFIER . ": '" . $row['username'] . "'"; break; default: $details = ''; } $table->addRow(array(new CCheckBox('media_types[' . $row['mediatypeid'] . ']', NULL, NULL, $row['mediatypeid']), media_type2str($row['type']), new CLink($row["description"], "?&form=update&mediatypeid=" . $row["mediatypeid"], 'action'), $details)); } //----- GO ------ $goBox = new CComboBox('go'); $goBox->addItem('delete', S_DELETE_SELECTED); // goButton name is necessary!!! $goButton = new CButton('goButton', S_GO . ' (0)'); $goButton->setAttribute('id', 'goButton'); zbx_add_post_js('chkbxRange.pageGoName = "media_types";'); $table->setFooter(new CCol(array($goBox, $goButton))); $form->addItem($table); $form->show(); zbx_add_post_js('insert_in_element("numrows","' . $table->getNumRows() . '");'); } ?>
case MEDIA_TYPE_EXEC: $details = S_SCRIPT_NAME . ': "' . $mediatype['exec_path'] . '"'; break; case MEDIA_TYPE_SMS: $details = S_GSM_MODEM . ': "' . $mediatype['gsm_modem'] . '"'; break; case MEDIA_TYPE_JABBER: $details = S_JABBER_IDENTIFIER . ': "' . $mediatype['username'] . '"'; break; case MEDIA_TYPE_EZ_TEXTING: $details = S_USERNAME . ': "' . $mediatype['username'] . '"'; break; default: $details = ''; } $table->addRow(array(new CCheckBox('media_types[' . $mediatype['mediatypeid'] . ']', NULL, NULL, $mediatype['mediatypeid']), new CLink($mediatype['description'], '?form=update&mediatypeid=' . $mediatype['mediatypeid']), media_type2str($mediatype['type']), $details)); } //----- GO ------ $goBox = new CComboBox('go'); $goOption = new CComboItem('delete', S_DELETE_SELECTED); $goOption->setAttribute('confirm', S_DELETE_SELECTED_MEDIATYPES_Q); $goBox->addItem($goOption); // goButton name is necessary!!! $goButton = new CButton('goButton', S_GO . ' (0)'); $goButton->setAttribute('id', 'goButton'); zbx_add_post_js('chkbxRange.pageGoName = "media_types";'); $footer = get_table_header(array($goBox, $goButton)); $form->addItem(array($paging, $table, $paging, $footer)); $medias_wdgt->addItem($form); } $medias_wdgt->show();