From 82db353dd14309dca3af98c1bb332161e506fb3f Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Fri, 5 May 2023 14:10:41 +0200 Subject: [PATCH] #11098 The operation of the create module button from the SNPM Walk modal is adjusted --- .../agentes/module_manager_editor_network.php | 2 +- .../include/functions_snmp_browser.php | 8 + .../javascript/pandora_snmp_browser.js | 4 +- .../operation/snmpconsole/snmp_browser.php | 211 +++++++++++------- 4 files changed, 145 insertions(+), 80 deletions(-) diff --git a/pandora_console/godmode/agentes/module_manager_editor_network.php b/pandora_console/godmode/agentes/module_manager_editor_network.php index b1a120d4da..d6a76f3cba 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_network.php +++ b/pandora_console/godmode/agentes/module_manager_editor_network.php @@ -311,7 +311,7 @@ $data[2] .= html_print_button( __('SNMP Walk'), 'snmp_walk', false, - 'snmpBrowserWindow()', + 'snmpBrowserWindow('.$id_agente.')', [ 'mode' => 'link' ], true ); diff --git a/pandora_console/include/functions_snmp_browser.php b/pandora_console/include/functions_snmp_browser.php index 091793f940..1634bf7a9b 100644 --- a/pandora_console/include/functions_snmp_browser.php +++ b/pandora_console/include/functions_snmp_browser.php @@ -1126,6 +1126,14 @@ function snmp_browser_print_container( $output .= '
'; $output .= '
'; $output .= '
'; + $output .= html_print_input_hidden( + 'id_agent_module', + 0, + true, + false, + false, + 'id_agent_module' + ); $output .= html_print_table($table, true); $output .= html_print_div( [ diff --git a/pandora_console/include/javascript/pandora_snmp_browser.js b/pandora_console/include/javascript/pandora_snmp_browser.js index c8dc331ff4..58a1972c40 100644 --- a/pandora_console/include/javascript/pandora_snmp_browser.js +++ b/pandora_console/include/javascript/pandora_snmp_browser.js @@ -533,7 +533,7 @@ function checkSNMPVersion() { } // Show the SNMP browser window -function snmpBrowserWindow() { +function snmpBrowserWindow(id_agente = 0) { // Keep elements in the form and the SNMP browser synced $("#text-target_ip").val($("#text-ip_target").val()); $("#target_port").val($("#text-tcp_port").val()); @@ -549,6 +549,8 @@ function snmpBrowserWindow() { $("#password-snmp3_browser_privacy_pass").val( $("#password-snmp3_privacy_pass").val() ); + // Realation agente module. + $("#id_agent_module").val(id_agente); checkSNMPVersion(); diff --git a/pandora_console/operation/snmpconsole/snmp_browser.php b/pandora_console/operation/snmpconsole/snmp_browser.php index cb5306f291..e8b8ed71ac 100644 --- a/pandora_console/operation/snmpconsole/snmp_browser.php +++ b/pandora_console/operation/snmpconsole/snmp_browser.php @@ -609,87 +609,142 @@ function show_add_module() { var id_agent = 0; var id_module = 0; + var id_agent_module = $("#id_agent_module").val(); + + if (id_agent_module) { + // Get SNMP target. + confirmDialog({ + title: '', + message: ' ', + ok: '', + cancel: '', + onAccept: function() { + + // Get SNMP target. + var snmp_target = { + target_ip : $('#text-target_ip').val(), + community : $('#text-community').val(), + snmp_version : $('#snmp_browser_version').val(), + snmp3_auth_user : $('#text-snmp3_browser_auth_user').val(), + snmp3_security_level : $('#snmp3_browser_security_level').val(), + snmp3_auth_method : $('#snmp3_browser_auth_method').val(), + snmp3_auth_pass : $('#password-snmp3_browser_auth_pass').val(), + snmp3_privacy_method : $('#snmp3_browser_privacy_method').val(), + snmp3_privacy_pass : $('#password-snmp3_browser_privacy_pass').val(), + tcp_port : $('#target_port').val(), + }; + + // Append values to form. + var input = ""; + + $.each( snmp_target, function( key, val ) { + input = $("") + .attr("type", "hidden") + .attr("name", key).val(val); + + $("#snmp_create_module").append(input); + }); + + //Submit form to agent module url. + $("#snmp_create_module").attr( + "action", + "index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&id_agente=" + +id_agent_module+ + "&tab=module&edit_module=1" + ); + + $('#snmp_create_module').submit(); - $("#dialog_create_module").dialog({ - resizable: true, - draggable: true, - modal: true, - width: '300', - height:'auto', - overlay: { - opacity: 0.5, - background: "black" - }, - buttons: - [ - { - class: "ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-cancel", - text: '', - click: function() { - $(this).dialog("close"); - } }, - - { - class: "ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next", - text: '', - click: function(e) { - - confirmDialog({ - title: '', - message: ' ', - ok: '', - cancel: '', - onAccept: function() { - - // Get id agent and add it to form. - id_agent = $('#hidden-id_agent').val(); - - // Get SNMP target. - var snmp_target = { - - target_ip : $('#text-target_ip').val(), - community : $('#text-community').val(), - snmp_version : $('#snmp_browser_version').val(), - snmp3_auth_user : $('#text-snmp3_browser_auth_user').val(), - snmp3_security_level : $('#snmp3_browser_security_level').val(), - snmp3_auth_method : $('#snmp3_browser_auth_method').val(), - snmp3_auth_pass : $('#password-snmp3_browser_auth_pass').val(), - snmp3_privacy_method : $('#snmp3_browser_privacy_method').val(), - snmp3_privacy_pass : $('#password-snmp3_browser_privacy_pass').val(), - tcp_port : $('#target_port').val(), - }; - - // Append values to form. - var input = ""; - - $.each( snmp_target, function( key, val ) { - input = $("") - .attr("type", "hidden") - .attr("name", key).val(val); - - $("#snmp_create_module").append(input); - }); -console.log(input); - //Submit form to agent module url. - $("#snmp_create_module").attr( - "action", - "index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&id_agente=" - +id_agent+ - "&tab=module&edit_module=1" - ); - - $('#snmp_create_module').submit(); - }, - onDeny: function () { - $("#dialog_create_module").dialog("close"); - return false; - } - }); - } + onDeny: function () { + $("#dialog_create_module").dialog("close"); + return false; } - ], - }); + }); + + } else { + + $("#dialog_create_module").dialog({ + resizable: true, + draggable: true, + modal: true, + width: '300', + height:'auto', + overlay: { + opacity: 0.5, + background: "black" + }, + buttons: + [ + { + class: "ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-cancel", + text: '', + click: function() { + $(this).dialog("close"); + } + }, + + { + class: "ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next", + text: '', + click: function(e) { + + confirmDialog({ + title: '', + message: ' ', + ok: '', + cancel: '', + onAccept: function() { + + // Get id agent and add it to form. + id_agent = $('#hidden-id_agent').val(); + + // Get SNMP target. + var snmp_target = { + + target_ip : $('#text-target_ip').val(), + community : $('#text-community').val(), + snmp_version : $('#snmp_browser_version').val(), + snmp3_auth_user : $('#text-snmp3_browser_auth_user').val(), + snmp3_security_level : $('#snmp3_browser_security_level').val(), + snmp3_auth_method : $('#snmp3_browser_auth_method').val(), + snmp3_auth_pass : $('#password-snmp3_browser_auth_pass').val(), + snmp3_privacy_method : $('#snmp3_browser_privacy_method').val(), + snmp3_privacy_pass : $('#password-snmp3_browser_privacy_pass').val(), + tcp_port : $('#target_port').val(), + }; + + // Append values to form. + var input = ""; + + $.each( snmp_target, function( key, val ) { + input = $("") + .attr("type", "hidden") + .attr("name", key).val(val); + + $("#snmp_create_module").append(input); + }); + + //Submit form to agent module url. + $("#snmp_create_module").attr( + "action", + "index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&id_agente=" + +id_agent+ + "&tab=module&edit_module=1" + ); + + $('#snmp_create_module').submit(); + }, + onDeny: function () { + $("#dialog_create_module").dialog("close"); + return false; + } + }); + } + } + ], + }); + } }