disableCsrfValidation(); } protected function checkInput() { $fields = [ 'action' => 'required|string', 'backurl' => 'required|string', 'valuemapids' => 'not_empty|array_db valuemaps.valuemapid', 'hostids' => 'not_empty|array_db hosts.hostid', 'mediatypeids' => 'not_empty|array_db media_type.mediatypeid', 'maps' => 'not_empty|array_db sysmaps.sysmapid', 'templates' => 'not_empty|array_db hosts.hostid', 'format' => 'in '.implode(',', [CExportWriterFactory::YAML, CExportWriterFactory::XML, CExportWriterFactory::JSON]) ]; $ret = $this->validateInput($fields); if (!$ret) { $this->setResponse(new CControllerResponseFatal()); } return $ret; } protected function checkPermissions() { switch ($this->getInput('action')) { case 'export.mediatypes': return $this->checkAccess(CRoleHelper::UI_ADMINISTRATION_MEDIA_TYPES); case 'export.valuemaps': return $this->checkAccess(CRoleHelper::UI_ADMINISTRATION_GENERAL); case 'export.hosts': return $this->checkAccess(CRoleHelper::UI_CONFIGURATION_HOSTS); case 'export.templates': return $this->checkAccess(CRoleHelper::UI_CONFIGURATION_TEMPLATES); case 'export.sysmaps': return $this->checkAccess(CRoleHelper::UI_MONITORING_MAPS); default: return false; } } protected function doAction() { $action = $this->getInput('action'); $params = [ 'format' => $this->getInput('format', CExportWriterFactory::YAML), 'prettyprint' => true, 'options' => [] ]; switch ($action) { case 'export.valuemaps': $params['options']['valueMaps'] = $this->getInput('valuemapids', []); break; case 'export.hosts': $params['options']['hosts'] = $this->getInput('hostids', []); break; case 'export.mediatypes': $params['options']['mediaTypes'] = $this->getInput('mediatypeids', []); break; case 'export.sysmaps': $params['options']['maps'] = $this->getInput('maps', []); break; case 'export.templates': $params['options']['templates'] = $this->getInput('templates', []); break; default: $this->setResponse(new CControllerResponseFatal()); return; } $result = API::Configuration()->export($params); if ($result) { $response = new CControllerResponseData([ 'main_block' => $result, 'mime_type' => CExportWriterFactory::getMimeType($params['format']), 'page' => ['file' => 'zbx_export_'.substr($action, 7).'.'.$params['format']] ]); } else { $response = new CControllerResponseRedirect($this->getInput('backurl', 'zabbix.php?action=dashboard.view')); CMessageHelper::setErrorTitle(_('Export failed')); } $this->setResponse($response); } }