From 329f790b2a0f84a2af3734a31c205e04932cc876 Mon Sep 17 00:00:00 2001 From: ramonn Date: Fri, 22 Feb 2013 13:11:47 +0000 Subject: [PATCH] 2013-02-22 Ramon Novoa * godmode/agentes/module_manager_editor_network.php, include/functions_snmp_browser.php, include/javascript/pandora_modules.js, operation/snmpconsole/snmp_browser.php: Integrated the SNMP browser into the SNMP module editor. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7703 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 8 + .../agentes/module_manager_editor_network.php | 64 ++- .../include/functions_snmp_browser.php | 103 ++++- .../include/javascript/pandora_modules.js | 112 ----- .../operation/snmpconsole/snmp_browser.php | 386 +----------------- 5 files changed, 172 insertions(+), 501 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 0c1ef097af..35055ebd01 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2013-02-22 Ramon Novoa + + * godmode/agentes/module_manager_editor_network.php, + include/functions_snmp_browser.php, + include/javascript/pandora_modules.js, + operation/snmpconsole/snmp_browser.php: Integrated the SNMP browser into + the SNMP module editor. + 2013-02-22 Miguel de Dios * godmode/alerts/alert_list.php, diff --git a/pandora_console/godmode/agentes/module_manager_editor_network.php b/pandora_console/godmode/agentes/module_manager_editor_network.php index 4198389255..3c3c0d41bd 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_network.php +++ b/pandora_console/godmode/agentes/module_manager_editor_network.php @@ -13,6 +13,17 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. +global $config; +require_once($config['homedir'] . "/include/functions_snmp_browser.php"); +ui_require_javascript_file ('pandora_snmp_browser'); + +// Save some variables for javascript functions +html_print_input_hidden ('ajax_url', ui_get_full_url("ajax.php"), false); +html_print_input_hidden ('search_matches_translation', __("Search matches"), false); + +// Define a custom action to save the OID selected in the SNMP browser to the form +html_print_input_hidden ('custom_action', urlencode (base64_encode('')), false); + $isFunctionPolicies = enterprise_include_once('include/functions_policies.php'); $disabledBecauseInPolicy = false; @@ -87,10 +98,7 @@ $data[1] .= ''; -$data[1] .= ''; -$data[1] .= ' '; +$data[1] .= ''; if ($disabledBecauseInPolicy) $disableButton = true; else @@ -99,7 +107,7 @@ else else $disableButton = false; -$data[1] .= html_print_button (__('SNMP walk'), 'snmp_walk', $disableButton, '', +$data[1] .= html_print_button (__('SNMP walk'), 'snmp_walk', $disableButton, 'snmpBrowserWindow()', 'class="sub next"', true); $data[1] .= ui_print_help_icon ('snmpwalk', true); $data[1] .= ''; @@ -184,6 +192,8 @@ $data[3] = html_print_select(array('noAuthNoPriv' => __('Not auth and not privac if ($snmp_version != 3) $table_simple->rowstyle['field_snmpv3_row3'] = 'display: none;'; push_table_simple($data, 'field_snmpv3_row3'); +snmp_browser_print_container (false, '100%', '60%', 'none'); + ?> \ No newline at end of file + +// Show the SNMP browser window +function snmpBrowserWindow () { + + // Keep elements in the form and the SNMP browser synced + $('#text-target_ip').val($('#text-ip_target').val()); + $('#text-community').val($('#text-snmp_community').val()); + + $("#snmp_browser_container").show().dialog ({ + title: '', + resizable: true, + draggable: true, + modal: true, + overlay: { + opacity: 0.5, + background: "black" + }, + width: 700, + height: 400 + }); +} + +// Set the form OID to the value selected in the SNMP browser +function setOID () { + $('#text-snmp_oid').val($('#snmp_selected_oid').text()); +} + + diff --git a/pandora_console/include/functions_snmp_browser.php b/pandora_console/include/functions_snmp_browser.php index ae4be3105c..f54a679592 100644 --- a/pandora_console/include/functions_snmp_browser.php +++ b/pandora_console/include/functions_snmp_browser.php @@ -282,11 +282,14 @@ function snmp_browser_get_oid ($target_ip, $community, $target_oid) { /** * Print the given OID data. * - * @param $oid array OID data. + * @param oid array OID data. + * @param custom_action string A custom action added to next to the close button. + * @param bool return The result is printed if set to true or returned if set to false. * + * @return string The OID data. */ -function snmp_browser_print_oid ($oid = array()) { - +function snmp_browser_print_oid ($oid = array(), $custom_action = '', $return = false) { + // OID information table $table->width = '100%'; $table->size = array (); @@ -301,7 +304,7 @@ function snmp_browser_print_oid ($oid = array()) { $table->data[0][0] = ''.__('OID').''; $table->data[0][1] = $oid['oid']; $table->data[1][0] = ''.__('Numeric OID').''; - $table->data[1][1] = $oid['numeric_oid']; + $table->data[1][1] = '' . $oid['numeric_oid'] . ''; $table->data[2][0] = ''.__('Value').''; $table->data[2][1] = $oid['value']; $i = 3; @@ -336,9 +339,91 @@ function snmp_browser_print_oid ($oid = array()) { $i++; } - echo ''; - html_print_image ("images/cancel.png", false, array ("style" => 'vertical-align: middle;'), false); - echo ''; - html_print_table($table, false); + $output = ''; + $output .= html_print_image ("images/cancel.png", true, array ("title" => __('Close'), "style" => 'vertical-align: middle;'), false); + $output .= ''; + + // Add a span for custom actions + if ($custom_action != '') { + $output .= '' . $custom_action . ''; + } + + $output .= html_print_table($table, true); + + if ($return) { + return $output; + } + + echo $output; } -?> \ No newline at end of file + +/** + * Print the div that contains the SNMP browser. + * + * @param bool return The result is printed if set to true or returned if set to false. + * @param string width Width of the SNMP browser. Units must be specified. + * @param string height Height of the SNMP browser. Units must be specified. + * @param string display CSS display value for the container div. Set to none to hide the div. + * + * @return string The container div. + * + */ +function snmp_browser_print_container ($return = false, $width = '95%', $height = '500px', $display = '') { + + // Target selection + $table->width = '100%'; + $table->size = array (); + $table->data = array (); + + // String search_string + $table->data[0][0] = ''.__('Target IP').''; + $table->data[0][1] = html_print_input_text ('target_ip', '', '', 25, 0, true); + $table->data[0][2] = ''.__('Community').''; + $table->data[0][3] = html_print_input_text ('community', '', '', 25, 0, true); + $table->data[0][4] = '' . html_print_image ("images/fullscreen.png", true, array ('title' => __('Expand the tree') . ' (' . __('can be slow') . ')', 'style' => 'vertical-align: middle;', 'onclick' => 'expandAll();')) . ''; + $table->data[0][4] .= ' ' . '' . html_print_image ("images/normalscreen.png", true, array ('title' => __('Collapse the tree'), 'style' => 'vertical-align: middle;', 'onclick' => 'collapseAll();')) . ''; + $table->data[1][0] = ''.__('Starting OID').''; + $table->data[1][1] = html_print_input_text ('starting_oid', '', '', 25, 0, true); + $table->data[1][2] = ''.__('Search text').''; + $table->data[1][3] = html_print_input_text ('search_text', '', '', 25, 0, true); + $table->data[1][4] = '' . html_print_image ("images/lupa.png", true, array ('title' => __('Search'), 'style' => 'vertical-align: middle;', 'onclick' => 'searchText();')) . ''; + $table->data[1][4] .= ' ' . '' . html_print_image ("images/go_first.png", true, array ('title' => __('First match'), 'style' => 'vertical-align: middle;', 'onclick' => 'searchFirstMatch();')) . ''; + $table->data[1][4] .= ' ' . '' . html_print_image ("images/go_previous.png", true, array ('title' => __('Previous match'), 'style' => 'vertical-align: middle;', 'onclick' => 'searchPrevMatch();')) . ''; + $table->data[1][4] .= ' ' . '' . html_print_image ("images/go_next.png", true, array ('title' => __('Next match'), 'style' => 'vertical-align: middle;', 'onclick' => 'searchNextMatch();')) . ''; + $table->data[1][4] .= ' ' . '' . html_print_image ("images/go_last.png", true, array ('title' => __('Last match'), 'style' => 'vertical-align: middle;', 'onclick' => 'searchLastMatch();')) . ''; + + // This extra div that can be handled by jquery's dialog + $output = '
'; + $output .= '
'; + $output .= '
'; + $output .= html_print_table($table, true); + $output .= '
'; + $output .= '
'; + $output .= html_print_button(__('Browse'), 'browse', false, 'snmpBrowse()', 'class="sub upd"', true); + $output .= '
'; + + // SNMP tree container + $output .= '
'; + $output .= html_print_input_hidden ('search_count', 0, true); + $output .= html_print_input_hidden ('search_index', -1, true); + + // Save some variables for javascript functions + $output .= html_print_input_hidden ('ajax_url', ui_get_full_url("ajax.php"), true); + $output .= html_print_input_hidden ('search_matches_translation', __("Search matches"), true); + + $output .= ''; + $output .= ''; + $output .= '
'; + $output .= ''; + $output .= '
'; + $output .= '
'; + $output .= '
'; + + if ($return) { + return $output; + } + + echo $output; +} + +?> diff --git a/pandora_console/include/javascript/pandora_modules.js b/pandora_console/include/javascript/pandora_modules.js index 1293bc6b13..919916cf59 100644 --- a/pandora_console/include/javascript/pandora_modules.js +++ b/pandora_console/include/javascript/pandora_modules.js @@ -378,118 +378,6 @@ function configure_modules_form () { ); }); - $("#text-ip_target").keyup (function () { - if (this.value != '') { - $("#button-snmp_walk").enable (); - } - else { - $("#button-snmp_walk").disable (); - } - }); - - $("#text-tcp_port").keyup (function () { - if (this.value != '') { - $("#button-snmp_walk").enable (); - } - else { - $("#button-snmp_walk").disable (); - } - }); - - $("#text-snmp_community").keyup (function () { - if (this.value != '') { - $("#button-snmp_walk").enable (); - } - else { - $("#button-snmp_walk").disable (); - } - }); - - $("#snmp_version").change(function () { - $("#button-snmp_walk").enable (); - }); - - $("#text-snmp3_auth_user").keyup (function () { - if (this.value != '') { - $("#button-snmp_walk").enable (); - } - else { - $("#button-snmp_walk").disable (); - } - }); - - $("#text-snmp3_auth_pass").keyup (function () { - if (this.value != '') { - $("#button-snmp_walk").enable (); - } - else { - $("#button-snmp_walk").disable (); - } - }); - - $("#snmp3_privacy_method").change(function () { - $("#button-snmp_walk").enable (); - }); - - $("#text-snmp3_privacy_pass").keyup (function () { - if (this.value != '') { - $("#button-snmp_walk").enable (); - } - else { - $("#button-snmp_walk").disable (); - } - }); - - $("#snmp3_auth_method").change(function () { - $("#button-snmp_walk").enable (); - }); - - $("#snmp3_security_level").change(function () { - $("#button-snmp_walk").enable (); - }); - - $("#button-snmp_walk").click (function () { - $(this).disable (); - $("#oid_loading").show (); - $("span.error").hide (); - $("#select_snmp_oid").empty ().hide (); - $("#text-snmp_oid").hide ().attr ("value", ""); - $("span#oid").show (); - jQuery.post ("ajax.php", - {"page" : "godmode/agentes/module_manager_editor", - "snmp_walk" : 1, - "ip_target" : $("#text-ip_target").fieldValue (), - "snmp_community" : $("#text-snmp_community").fieldValue (), - "snmp_port" : $("#text-tcp_port").val(), - "snmp_version": $('#snmp_version').val(), - "snmp3_auth_user": $('input[name=snmp3_auth_user]').val(), - "snmp3_security_level": $('#snmp3_security_level').val(), - "snmp3_auth_method": $('#snmp3_auth_method').val(), - "snmp3_auth_pass": $('input[name=snmp3_auth_pass]').val(), - "snmp3_privacy_method": $('#snmp3_privacy_method').val(), - "snmp3_privacy_pass": $('input[name=snmp3_privacy_pass]').val() - }, - function (data, status) { - if (data == false) { - $("span#no_snmp").show (); - $("#oid_loading").hide (); - $("#edit_oid").hide (); - $("#button-snmp_walk").enable (); - return false; - } - jQuery.each (data, function (id, value) { - opt = $("").attr ("value", id).html (value); - $("#select_snmp_oid").append (opt); - }); - $("#select_snmp_oid").show (); - $("#oid_loading").hide (); - $("#edit_oid").show (); - $("#button-snmp_walk").enable (); - }, - "json" - ); - }); - $("img#edit_oid").click (function () { $("#oid").hide (); $("#text-snmp_oid").show () diff --git a/pandora_console/operation/snmpconsole/snmp_browser.php b/pandora_console/operation/snmpconsole/snmp_browser.php index 60ab6ee2a3..2e69f7bc9c 100644 --- a/pandora_console/operation/snmpconsole/snmp_browser.php +++ b/pandora_console/operation/snmpconsole/snmp_browser.php @@ -17,6 +17,7 @@ // Load global vars global $config; require_once($config['homedir'] . "/include/functions_snmp_browser.php"); +ui_require_javascript_file ('pandora_snmp_browser'); // AJAX call if (is_ajax()) { @@ -25,11 +26,11 @@ if (is_ajax()) { $action = (string) get_parameter ("action", ""); $target_ip = (string) get_parameter ("target_ip", ''); $community = (string) get_parameter ("community", ''); - $starting_oid = (string) get_parameter ("starting_oid", '.'); - $target_oid = htmlspecialchars_decode (get_parameter ("oid", "")); - + // SNMP browser if ($action == "snmptree") { + $starting_oid = (string) get_parameter ("starting_oid", '.'); + $snmp_tree = snmp_browser_get_tree ($target_ip, $community, $starting_oid); if (! is_array ($snmp_tree)) { echo $snmp_tree; @@ -40,8 +41,14 @@ if (is_ajax()) { } // SNMP get else if ($action == "snmpget") { + $target_oid = htmlspecialchars_decode (get_parameter ("oid", "")); + $custom_action = get_parameter ("custom_action", ""); + if ($custom_action != "") { + $custom_action = urldecode (base64_decode ($custom_action)); + } + $oid = snmp_browser_get_oid ($target_ip, $community, $target_oid); - snmp_browser_print_oid ($oid); + snmp_browser_print_oid ($oid, $custom_action); return; } @@ -57,10 +64,6 @@ if (! check_acl ($config['id_user'], 0, "AR")) { exit; } -// Read parameters -//$target_ip = (string) get_parameter ("target_ip", ''); -//$community = (string) get_parameter ("community", ''); - // Header $url = 'index.php?sec=estado&sec2=operation/snmpconsole/snmp_browser&refr=' . $config["refr"] . '&pure=' . $config["pure"]; if ($config["pure"]) { @@ -72,370 +75,7 @@ if ($config["pure"]) { } ui_print_page_header (__("SNMP Browser"), "images/computer_error.png", false, "", false, $link); -// Target selection -$table->width = '100%'; -$table->size = array (); -$table->data = array (); - -// String search_string -$table->data[0][0] = ''.__('Target IP').''; -$table->data[0][1] = html_print_input_text ('target_ip', '', '', 25, 0, true); -$table->data[0][2] = ''.__('Community').''; -$table->data[0][3] = html_print_input_text ('community', '', '', 25, 0, true); -$table->data[0][4] = html_print_image ("images/fullscreen.png", true, array ('title' => __('Expand the tree') . ' (' . __('can be slow') . ')', 'style' => 'vertical-align: middle;', 'onclick' => 'expandAll();')); -$table->data[0][4] .= ' ' . html_print_image ("images/normalscreen.png", true, array ('title' => __('Collapse the tree'), 'style' => 'vertical-align: middle;', 'onclick' => 'collapseAll();')); -$table->data[1][0] = ''.__('Starting OID').''; -$table->data[1][1] = html_print_input_text ('starting_oid', '', '', 25, 0, true); -$table->data[1][2] = ''.__('Search text').''; -$table->data[1][3] = html_print_input_text ('search_text', '', '', 25, 0, true); -$table->data[1][4] = html_print_image ("images/lupa.png", true, array ('title' => __('Search'), 'style' => 'vertical-align: middle;', 'onclick' => 'searchText();')); -$table->data[1][4] .= ' ' . html_print_image ("images/go_first.png", true, array ('title' => __('First match'), 'style' => 'vertical-align: middle;', 'onclick' => 'searchFirstMatch();')); -$table->data[1][4] .= ' ' . html_print_image ("images/go_previous.png", true, array ('title' => __('Previous match'), 'style' => 'vertical-align: middle;', 'onclick' => 'searchPrevMatch();')); -$table->data[1][4] .= ' ' . html_print_image ("images/go_next.png", true, array ('title' => __('Next match'), 'style' => 'vertical-align: middle;', 'onclick' => 'searchNextMatch();')); -$table->data[1][4] .= ' ' . html_print_image ("images/go_last.png", true, array ('title' => __('Last match'), 'style' => 'vertical-align: middle;', 'onclick' => 'searchLastMatch();')); - -echo '
'; -echo html_print_table($table, true); -html_print_input_hidden ('search_count', 0, false); -html_print_input_hidden ('search_index', -1, false); -echo '
'; -echo html_print_button(__('Browse'), 'browse', false, 'snmpBrowse()', 'class="sub upd"', true); -echo '
'; -echo '
'; - -// SNMP tree -echo '
'; -echo ''; -echo ''; -echo '
'; -echo '
'; -echo '
'; +// SNMP tree container +snmp_browser_print_container (); ?> - -