diff --git a/README.md b/README.md index 1f3a2b8..95c890e 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,11 @@ This software is licensed under the GNU Lesser General Public License v3.0. ## Changelog +### Version 5.4.2 + +* Added support for Zabbix 5.0 and 5.2 +* Non-functional menu entry for non-superadmins is now hidden + ### Version 5.0.2 * Added support for templates @@ -24,7 +29,7 @@ This software is licensed under the GNU Lesser General Public License v3.0. ## Requirements -- Zabbix 5.4 +- Zabbix 5.0 to 5.4 - File write access to the Zabbix frontend server - Super admin permissions for the Zabbix users that want to use the frontend module @@ -63,5 +68,5 @@ Additional hints: * The columns must be in the first line of the CSV file. * The separator character must be ";". -The CSV file can then imported in the same menu entry. You get a chance to preview the host list before the actual import. +The CSV file can then be imported in the same menu entry. You get a chance to preview the host list before the actual import. diff --git a/modules/csv-host-importer/Module.php b/modules/csv-host-importer/Module.php index f441ea0..775b98c 100644 --- a/modules/csv-host-importer/Module.php +++ b/modules/csv-host-importer/Module.php @@ -2,7 +2,7 @@ /** * Zabbix CSV Import Frontend Module * - * @version 5.0.2 + * @version 5.0.0 * @author Wolfgang Alper * @copyright IntelliTrend GmbH, https://www.intellitrend.de * @license GNU Lesser General Public License v3.0 @@ -19,6 +19,7 @@ use APP; use CController as CAction; +use CWebUser; /** * Please see Core\CModule class for additional reference. @@ -29,6 +30,10 @@ class Module extends \Core\CModule { * Initialize module. */ public function init(): void { + // Only super admins should see the menu entry + if (CWebUser::getType() != USER_TYPE_SUPER_ADMIN) { + return; + } // Initialize main menu (CMenu class instance). APP::Component()->get('menu.main')->findOrAdd(_('Configuration'))->getSubmenu()->add((new \CMenuItem(_('Host CSV Importer')))->setAction('ichi.import')); } diff --git a/modules/csv-host-importer/actions/CsvHostImport.php b/modules/csv-host-importer/actions/CsvHostImport.php index c195c06..feddada 100644 --- a/modules/csv-host-importer/actions/CsvHostImport.php +++ b/modules/csv-host-importer/actions/CsvHostImport.php @@ -2,7 +2,7 @@ /** * Zabbix CSV Import Frontend Module * - * @version 5.0.2 + * @version 5.0.0 * @author Wolfgang Alper * @copyright IntelliTrend GmbH, https://www.intellitrend.de * @license GNU Lesser General Public License v3.0 @@ -23,6 +23,8 @@ use CRoleHelper; use CUploadFile; use API; +use CSession; // 5.0.0 +use CSessionHelper; // 5.2.0+ /** * Host CSV importer module action. @@ -61,6 +63,8 @@ class CsvHostImport extends CAction { 8 => 'A PHP extension stopped the file upload.', ]; + const HOSTLIST_KEY = 'ichi.hostlist'; + private $hostlist = []; private $step = 0; @@ -101,7 +105,11 @@ protected function checkInput(): bool { * @return bool */ protected function checkPermissions(): bool { - return $this->checkAccess(CRoleHelper::UI_ADMINISTRATION_GENERAL); + if (version_compare(ZABBIX_VERSION, '5.4.0', '>=')) { + return $this->checkAccess(CRoleHelper::UI_ADMINISTRATION_GENERAL); + } else { + return ($this->getUserType() == USER_TYPE_SUPER_ADMIN); + } } private function csvParse(): bool { @@ -261,6 +269,39 @@ private function importHosts(): bool { return true; } + private function loadSession() { + if (version_compare(ZABBIX_VERSION, '5.2.0', '>=')) { + if (!CSessionHelper::has(self::HOSTLIST_KEY)) { + return false; + } + $this->hostlist = CSessionHelper::get(self::HOSTLIST_KEY); + return true; + } else { + if (!CSession::keyExists(self::HOSTLIST_KEY)) { + return false; + } + $this->hostlist = CSession::getValue(self::HOSTLIST_KEY); + return true; + } + } + + private function saveSession() { + if (version_compare(ZABBIX_VERSION, '5.2.0', '>=')) { + CSessionHelper::set(self::HOSTLIST_KEY, $this->hostlist); + } else { + CSession::setValue(self::HOSTLIST_KEY, $this->hostlist); + } + } + + private function clearSession() { + if (version_compare(ZABBIX_VERSION, '5.2.0', '>=')) { + CSessionHelper::unset([self::HOSTLIST_KEY]); + } else { + CSession::unsetValue([self::HOSTLIST_KEY]); + } + } + + /** * Prepare the response object for the view. Method called by Zabbix core. * @@ -287,17 +328,16 @@ protected function doAction() { if (!$this->csvParse()) { $this->step = 0; } - $_SESSION['ichi.hostlist'] = $this->hostlist; + $this->saveSession(); break; case 2: // import - if (!isset($_SESSION['ichi.hostlist'])) { + if (!$this->loadSession()) { error(_('Missing host list in session.')); break; } - $this->hostlist = $_SESSION['ichi.hostlist']; if ($this->importHosts()) { - unset($_SESSION['ichi.hostlist']); + $this->clearSession(); } break; } diff --git a/modules/csv-host-importer/actions/CsvHostImportExample.php b/modules/csv-host-importer/actions/CsvHostImportExample.php index e56f277..75cd3d7 100644 --- a/modules/csv-host-importer/actions/CsvHostImportExample.php +++ b/modules/csv-host-importer/actions/CsvHostImportExample.php @@ -2,7 +2,7 @@ /** * Zabbix CSV Import Frontend Module * - * @version 5.0.2 + * @version 5.0.0 * @author Wolfgang Alper * @copyright IntelliTrend GmbH, https://www.intellitrend.de * @license GNU Lesser General Public License v3.0 @@ -56,7 +56,11 @@ protected function checkInput(): bool { * @return bool */ protected function checkPermissions(): bool { - return $this->checkAccess(CRoleHelper::UI_ADMINISTRATION_GENERAL); + if (version_compare(ZABBIX_VERSION, '5.4.0', '>=')) { + return $this->checkAccess(CRoleHelper::UI_ADMINISTRATION_GENERAL); + } else { + return ($this->getUserType() == USER_TYPE_SUPER_ADMIN); + } } /** diff --git a/modules/csv-host-importer/manifest.json b/modules/csv-host-importer/manifest.json index a9be441..72cf2c3 100644 --- a/modules/csv-host-importer/manifest.json +++ b/modules/csv-host-importer/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 1.0, "id": "intellitrend_csv_host_importer", "name": "CSV Host Importer", - "version": "5.0.2", + "version": "5.4.2", "namespace": "ichi", "author": "IntelliTrend GmbH", "url": "https://www.intellitrend.de/", diff --git a/modules/csv-host-importer/views/layout.ichi.example.php b/modules/csv-host-importer/views/layout.ichi.example.php index 5cf8531..2c9fa7b 100644 --- a/modules/csv-host-importer/views/layout.ichi.example.php +++ b/modules/csv-host-importer/views/layout.ichi.example.php @@ -2,7 +2,7 @@ /** * Zabbix CSV Import Frontend Module * - * @version 5.0.2 + * @version 5.0.0 * @author Wolfgang Alper * @copyright IntelliTrend GmbH, https://www.intellitrend.de * @license GNU Lesser General Public License v3.0 diff --git a/modules/csv-host-importer/views/module.ichi.import.php b/modules/csv-host-importer/views/module.ichi.import.php index 91aadac..c9053d6 100644 --- a/modules/csv-host-importer/views/module.ichi.import.php +++ b/modules/csv-host-importer/views/module.ichi.import.php @@ -2,7 +2,7 @@ /** * Zabbix CSV Import Frontend Module * - * @version 5.0.2 + * @version 5.0.0 * @author Wolfgang Alper * @copyright IntelliTrend GmbH, https://www.intellitrend.de * @license GNU Lesser General Public License v3.0 @@ -66,9 +66,10 @@ ); $hostlist = $data['hostlist']; - $table = (new CTable()) - ->setId('hostlist-table') - ->addClass(ZBX_STYLE_VALUEMAP_LIST_TABLE); + $table = (new CTable())->setId('hostlist-table'); + if (defined('ZBX_STYLE_VALUEMAP_LIST_TABLE')) { + $table->addClass(ZBX_STYLE_VALUEMAP_LIST_TABLE); + } $cols = []; @@ -99,9 +100,10 @@ // import $hostlist = $data['hostlist']; - $table = (new CTable()) - ->setId('hostlist-table') - ->addClass(ZBX_STYLE_VALUEMAP_LIST_TABLE); + $table = (new CTable())->setId('hostlist-table'); + if (defined('ZBX_STYLE_VALUEMAP_LIST_TABLE')) { + $table->addClass(ZBX_STYLE_VALUEMAP_LIST_TABLE); + } $table->setColumns([ (new CTableColumn(_('Name')))