From c503836634e995f7337db335fbe3c47c82604fe3 Mon Sep 17 00:00:00 2001 From: Pablo Aragon Date: Thu, 12 Jan 2023 12:28:40 +0100 Subject: [PATCH 1/3] Restrict access to collections with nms license --- .../godmode/agentes/configurar_agente.php | 8 +++++--- pandora_console/godmode/menu.php | 3 ++- pandora_console/include/constants.php | 1 + pandora_console/include/functions.php | 16 ++++++++++++++++ pandora_console/include/functions_api.php | 10 ++++++++++ pandora_console/operation/agentes/ver_agente.php | 8 +++++--- 6 files changed, 39 insertions(+), 7 deletions(-) diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 4432fef1cd..62807fa7c9 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -485,10 +485,12 @@ if ($id_agente) { } // Collection. - $collectiontab = enterprise_hook('collection_tab'); + if ($config['license_nms'] !== 1) { + $collectiontab = enterprise_hook('collection_tab'); - if ($collectiontab == -1) { - $collectiontab = ''; + if ($collectiontab == -1) { + $collectiontab = ''; + } } // NetworkConfigManager tab. diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index fef71922e3..7e9a7964a3 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -26,7 +26,8 @@ * GNU General Public License for more details. * ============================================================================ */ - +$config['license_nms'] = 1; +// ! Eliminar! // Begin. require_once 'include/config.php'; require_once 'include/functions_menu.php'; diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index 96fb1c216b..18b32b6de4 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -805,6 +805,7 @@ define('AUDIT_LOG_DASHBOARD_MANAGEMENT', 'Dashboard management'); define('AUDIT_LOG_SERVICE_MANAGEMENT', 'Service management'); define('AUDIT_LOG_INCIDENT_MANAGEMENT', 'Incident management'); define('AUDIT_LOG_UMC', 'Warp Manager'); +define('AUDIT_LOG_NMS_VIOLATION', 'NMS Violation'); // MIMEs. define( diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 7c2df5603b..a333006da8 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -6342,3 +6342,19 @@ function setDownloadCookieToken() ); } } + + +/** + * Check nms license on api. + * + * @return boolean + */ +function nms_check_api() +{ + global $config; + + if ($config['license_nms'] === 1) { + returnError('license_error'); + return true; + } +} diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index db79ed3c86..f322f5c2de 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -198,6 +198,16 @@ function returnError($typeError, $returnType='string') ); break; + case 'license_error': + returnData( + $returnType, + [ + 'type' => 'string', + 'data' => __('License not allowed for this operation.'), + ] + ); + break; + default: returnData( $returnType, diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index 2ee6781f00..89c7c70d8e 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -1461,9 +1461,11 @@ if ($inventorytab == -1 || $inventoryCount === 0) { } // Collection. -$collectiontab = enterprise_hook('collection_tab'); -if ($collectiontab == -1) { - $collectiontab = ''; +if ($config['license_nms'] !== 1) { + $collectiontab = enterprise_hook('collection_tab'); + if ($collectiontab == -1) { + $collectiontab = ''; + } } From 4392bd7fa8b7f96ff74aa5e1f84cefd1b94d30d7 Mon Sep 17 00:00:00 2001 From: Pablo Aragon Date: Fri, 13 Jan 2023 12:09:15 +0100 Subject: [PATCH 2/3] 9220 Restrict access to collections with nms license --- pandora_console/godmode/menu.php | 3 +-- pandora_console/godmode/servers/modificar_server.php | 10 ++++++---- .../include/class/SatelliteCollection.class.php | 9 +++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index 7e9a7964a3..fef71922e3 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -26,8 +26,7 @@ * GNU General Public License for more details. * ============================================================================ */ -$config['license_nms'] = 1; -// ! Eliminar! + // Begin. require_once 'include/config.php'; require_once 'include/functions_menu.php'; diff --git a/pandora_console/godmode/servers/modificar_server.php b/pandora_console/godmode/servers/modificar_server.php index 17f2020d13..748c707227 100644 --- a/pandora_console/godmode/servers/modificar_server.php +++ b/pandora_console/godmode/servers/modificar_server.php @@ -141,11 +141,13 @@ if (isset($_GET['server'])) { ]; - $buttons['collections'] = [ - 'active' => false, - 'text' => ''.html_print_image('images/collection.png', true, ['title' => __('Collections')]).'', + if ($config['license_nms'] !== 1) { + $buttons['collections'] = [ + 'active' => false, + 'text' => ''.html_print_image('images/collection.png', true, ['title' => __('Collections')]).'', - ]; + ]; + } } $buttons[$tab]['active'] = true; diff --git a/pandora_console/include/class/SatelliteCollection.class.php b/pandora_console/include/class/SatelliteCollection.class.php index 34348fdc7a..b8535f5cc6 100644 --- a/pandora_console/include/class/SatelliteCollection.class.php +++ b/pandora_console/include/class/SatelliteCollection.class.php @@ -84,6 +84,15 @@ class SatelliteCollection extends HTML return; } + if ($config['license_nms'] === 1) { + db_pandora_audit( + AUDIT_LOG_NMS_VIOLATION, + 'Trying to access satellite collections' + ); + include $config['homedir'].'/general/noaccess.php'; + return; + } + // Set the ajax controller. $this->ajaxController = $ajaxController; // Capture all parameters before start. From 0ec58067abf3291f421f278978e1aad728e19278 Mon Sep 17 00:00:00 2001 From: Pablo Aragon Date: Tue, 24 Jan 2023 14:45:42 +0100 Subject: [PATCH 3/3] 9220 Cast config['license_nms'] --- pandora_console/godmode/agentes/configurar_agente.php | 2 +- pandora_console/godmode/servers/modificar_server.php | 2 +- pandora_console/include/class/SatelliteCollection.class.php | 2 +- pandora_console/include/functions.php | 2 +- pandora_console/operation/agentes/ver_agente.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 36b1d5302a..6503a0fb0b 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -498,7 +498,7 @@ if ($id_agente) { } // Collection. - if ($config['license_nms'] !== 1) { + if ((int) $config['license_nms'] !== 1) { $collectiontab = enterprise_hook('collection_tab'); if ($collectiontab == -1) { diff --git a/pandora_console/godmode/servers/modificar_server.php b/pandora_console/godmode/servers/modificar_server.php index 748c707227..b7541586b3 100644 --- a/pandora_console/godmode/servers/modificar_server.php +++ b/pandora_console/godmode/servers/modificar_server.php @@ -141,7 +141,7 @@ if (isset($_GET['server'])) { ]; - if ($config['license_nms'] !== 1) { + if ((int) $config['license_nms'] !== 1) { $buttons['collections'] = [ 'active' => false, 'text' => ''.html_print_image('images/collection.png', true, ['title' => __('Collections')]).'', diff --git a/pandora_console/include/class/SatelliteCollection.class.php b/pandora_console/include/class/SatelliteCollection.class.php index b8535f5cc6..769ec5c6f4 100644 --- a/pandora_console/include/class/SatelliteCollection.class.php +++ b/pandora_console/include/class/SatelliteCollection.class.php @@ -84,7 +84,7 @@ class SatelliteCollection extends HTML return; } - if ($config['license_nms'] === 1) { + if ((int) $config['license_nms'] === 0) { db_pandora_audit( AUDIT_LOG_NMS_VIOLATION, 'Trying to access satellite collections' diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 8940dc08ae..c6e8812100 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -6398,7 +6398,7 @@ function nms_check_api() { global $config; - if ($config['license_nms'] === 1) { + if ((int) $config['license_nms'] === 1) { returnError('license_error'); return true; } diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index 6112ecbb52..c1bf5c27d7 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -1473,7 +1473,7 @@ if ($tab == 'inventory') { } // Collection. -if ($config['license_nms'] !== 1) { +if ((int) $config['license_nms'] !== 1) { $collectiontab = enterprise_hook('collection_tab'); if ($collectiontab == -1) { $collectiontab = '';