From 85794418e24fca2e113e3427137c1150e03bcc86 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Tue, 27 Feb 2024 09:11:28 +0100 Subject: [PATCH] disallow editing module type --- .../godmode/agentes/configurar_agente.php | 16 +++++++++++++++- pandora_server/lib/PandoraFMS/DataServer.pm | 7 +------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 6a1084e605..5f0bbc0730 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -1499,6 +1499,7 @@ if ($update_module === true || $create_module === true) { $old_configuration_data = (string) get_parameter('old_configuration_data'); $new_configuration_data = ''; + $custom_string_1_default = ''; $custom_string_2_default = ''; $custom_string_3_default = ''; @@ -1964,6 +1965,19 @@ if ($update_module) { } } + $def_msg = __('There was a problem updating module. Processing error'); + + if (preg_match('/module_type\s+([^\\n]+)/', io_safe_output($configuration_data), $matches)) { + $config_module_type = $matches[1]; + + $type_id = (int) db_get_value('id_tipo', 'ttipo_modulo', 'nombre', $config_module_type); + + if ($type_id !== $id_module_type) { + $def_msg = __('There was a problem updating module: module type cannot be edited'); + $result = ERR_GENERIC; + } + } + if (is_error($result) === true) { switch ($result) { case ERR_EXIST: @@ -1981,7 +1995,7 @@ if ($update_module) { case ERR_DB: case ERR_GENERIC: default: - $msg = __('There was a problem updating module. Processing error'); + $msg = $def_msg; break; } diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index 9ca6812e54..b8dc319c45 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -657,12 +657,7 @@ sub process_xml_data ($$$$$) { # Unnamed module next if ($module_name eq ''); - # Read module type from db when module exists within it (skip XML read). - my $module_type = get_db_value ($dbh, 'SELECT ttm.nombre FROM ttipo_modulo ttm INNER JOIN tagente_modulo tam ON tam.id_tipo_modulo = ttm.id_tipo WHERE tam.id_agente = ' . $agent_id . ' AND tam.nombre' . ' = '. $RDBMS_QUOTE_STRING . safe_input($module_name) . $RDBMS_QUOTE_STRING); - - if (!defined($module_type)) { - $module_type = get_tag_value ($module_data, 'type', 'generic_data'); - } + my $module_type = get_tag_value ($module_data, 'type', 'generic_data'); # Apply timezone offset to module if timestamp is set. if (defined($module_data->{'timestamp'} && $module_data->{'timestamp'} ne '')) {