From 86671c721193b5bc4e202e3ae5d49937a724ed32 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Mon, 11 Dec 2023 11:36:34 +0100 Subject: [PATCH 1/3] #12350 added agent name editing --- .../godmode/agentes/agent_manager.php | 69 ++++++++++++++++++- .../godmode/agentes/configurar_agente.php | 18 ++++- 2 files changed, 83 insertions(+), 4 deletions(-) diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 26bae75929..a6e0d7e987 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -357,7 +357,18 @@ if ($new_agent === false) { $tableAgent->data['caption_name'][0] = __('Agent name'); $tableAgent->rowclass['name'] = 'w540px'; $tableAgent->cellstyle['name'][0] = 'width: 100%;'; - $tableAgent->data['name'][0] = html_print_input_text('agente', $nombre_agente, '', 76, 100, true, false, false, '', 'w100p'); + $tableAgent->data['name'][0] = html_print_input_text( + 'agente', + $nombre_agente, + '', + 76, + 100, + true, + true, + false, + '', + 'w100p' + ); $tableAgent->data['name'][0] .= html_print_div( [ 'class' => 'moduleIdBox', @@ -365,6 +376,28 @@ if ($new_agent === false) { ], true ); + + // Other than Linux, Solaris, AIX, BSD, HPUX, MacOs, and Windows. + if ($id_os !== '1' && $id_os !== '2' && $id_os !== '3' && $id_os !== '4' + && $id_os !== '5' && $id_os !== '7' && $id_os !== '8' + ) { + $tableAgent->data['name'][0] .= html_print_anchor( + [ + 'content' => html_print_image( + 'images/edit.svg', + true, + [ + 'border' => 0, + 'title' => __('Edit agent name'), + 'class' => 'main_menu_icon invert_filter after_input_icon forced_title clickable', + 'onclick' => 'editAgent()', + ] + ), + ], + true + ); + } + // Agent options for QR code. $agent_options_update = 'agent_options_update'; } @@ -1429,7 +1462,6 @@ ui_require_jquery_file('bgiframe'); 128 ); } - $("#text-agente").prop('readonly', true); // Disable fixed ip button if empty. @@ -1458,4 +1490,37 @@ ui_require_jquery_file('bgiframe'); $('#basic_options').addClass('invisible'); } } + + function editAgent() { + $(`#text-agente`).attr(`readonly`, false); + const title = ''; + const text = ''; + const id = uniqId(); + $("body").append('
'); + $("#" + id).empty(); + $("#" + id).append(text); + $("#" + id).dialog({ + height: 150, + width: 528, + opacity: 1, + modal: true, + position: { + my: "center", + at: "center", + of: window, + collision: "fit" + }, + title: title, + closeOnEscape: true, + buttons: [{ + text: "OK", + click: function() { + $(this).dialog("close"); + } + }], + open: function(event, ui) { + $(".ui-dialog-titlebar-close").hide(); + }, + }).show(); + } diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index b4abfa1ad7..673919908e 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -956,6 +956,13 @@ if ($update_agent) { $mssg_warning = 0; $id_agente = (int) get_parameter_post('id_agente'); $nombre_agente = str_replace('`', '‘', (string) get_parameter_post('agente', '')); + $repeated_name = db_get_row_sql( + sprintf( + 'SELECT nombre FROM tagente WHERE id_agente <> %s AND nombre like "%s"', + $id_agente, + $nombre_agente + ) + ); $alias_safe_output = strip_tags(io_safe_output(get_parameter('alias', ''))); $alias = io_safe_input(trim(preg_replace('/[\/\\\|%#&$]/', '', $alias_safe_output))); $alias_as_name = (int) get_parameter_post('alias_as_name', 0); @@ -1084,14 +1091,17 @@ if ($update_agent) { } } + // Verify if there is another agent with the same name but different ID. + if (empty($repeated_name) === false) { + ui_print_error_message(__('Agent with repeated name')); + } + if ($mssg_warning) { ui_print_warning_message(__('The ip or dns name entered cannot be resolved')); } - // Verify if there is another agent with the same name but different ID. if ($alias == '') { ui_print_error_message(__('No agent alias specified')); - // If there is an agent with the same name, but a different ID. } if ($direccion_agente !== $address_list && (bool) $unique_ip === true && $direccion_agente != '') { @@ -1152,6 +1162,10 @@ if ($update_agent) { 'vul_scan_enabled' => $vul_scan_enabled, ]; + if (empty($repeated_name) === true) { + $values['nombre'] = $nombre_agente; + } + if ($config['metaconsole_agent_cache'] == 1) { $values['update_module_count'] = 1; // Force an update of the agent cache. From 151808b6bfdc95369b827acdefebb1748ba2d228 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Thu, 15 Feb 2024 17:00:55 +0100 Subject: [PATCH 2/3] #12350 added agent name editing 2 --- pandora_console/godmode/agentes/configurar_agente.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 2331bb24db..6a0f0306b0 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -1158,8 +1158,7 @@ if ($update_agent) { // Force an update of the agent cache. } - $result = db_process_sql_update('tagente', $values, ['id_agente' => $id_agente]); - + $result = (bool) db_process_sql_update('tagente', $values, ['id_agente' => $id_agente]); if ($result === false && $update_custom_result == false) { ui_print_error_message( __('There was a problem updating the agent') From 12eca2dbd4329c3ad6deb29eeb5c174328412dde Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Fri, 16 Feb 2024 09:14:34 +0100 Subject: [PATCH 3/3] #12350 added agent name editing 3 --- pandora_console/godmode/agentes/agent_manager.php | 5 +++-- pandora_console/include/constants.php | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 3afd44477a..12807e144c 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -378,8 +378,9 @@ if ($new_agent === false) { ); // Other than Linux, Solaris, AIX, BSD, HPUX, MacOs, and Windows. - if ($id_os !== '1' && $id_os !== '2' && $id_os !== '3' && $id_os !== '4' - && $id_os !== '5' && $id_os !== '7' && $id_os !== '8' + if ($id_os !== LINUX && $id_os !== SOLARIS && $id_os !== AIX + && $id_os !== BSD && $id_os !== HPUX && $id_os !== MACOS + && $id_os !== WINDOWS ) { $tableAgent->data['name'][0] .= html_print_anchor( [ diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index d68bba9c22..721712c4cf 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -907,3 +907,13 @@ define('DEMO_SERVICE', 6); define('DEMO_DASHBOARD', 7); define('DEMO_VISUAL_CONSOLE', 8); define('DEMO_PLUGIN', 9); + +// OS. +define('LINUX', '1'); +define('SOLARIS', '2'); +define('AIX', '3'); +define('BSD', '4'); +define('HPUX', '5'); +define('CISCO', '7'); +define('MACOS', '8'); +define('WINDOWS', '9');