2013-02-22 Ramon Novoa <rnovoa@artica.es>

* 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
This commit is contained in:
ramonn 2013-02-22 13:11:47 +00:00
parent 3fa698bcf6
commit 329f790b2a
5 changed files with 172 additions and 501 deletions

View File

@ -1,3 +1,11 @@
2013-02-22 Ramon Novoa <rnovoa@artica.es>
* 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 <miguel.dedios@artica.es>
* godmode/alerts/alert_list.php,

View File

@ -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('<a href="javascript:setOID()"><img src="' . ui_get_full_url("images") . '/hand_point.png" title="' . __("Use this OID") . '" style="vertical-align: middle;"></img></a>')), false);
$isFunctionPolicies = enterprise_include_once('include/functions_policies.php');
$disabledBecauseInPolicy = false;
@ -87,10 +98,7 @@ $data[1] .= '<span class="invisible" id="oid">';
$data[1] .= html_print_select (array (), 'select_snmp_oid', $snmp_oid, '', '', 0, true, false, false, '', $disabledBecauseInPolicy);
$data[1] .= html_print_image("images/edit.png", true, array("class" => "invisible clickable", "id" => "edit_oid"));
$data[1] .= '</span>';
$data[1] .= '<span id="no_snmp" class="error invisible">'.__('Unable to do SNMP walk').'</span>';
$data[1] .= '</span> <span class="right" style="width: 50%; text-align: right"><span id="oid_loading" class="invisible">';
$data[1] .= html_print_image('images/spinner.gif', true);
$data[1] .= '</span>';
$data[1] .= '</span><span class="right" style="width: 50%; text-align: right">';
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] .= '</span>';
@ -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');
?>
<script type="text/javascript">
$(document).ready (function () {
@ -223,6 +233,46 @@ $(document).ready (function () {
$("#id_module_type").blur (function () {
$(this).css ("width", "180px");
});
// Keep elements in the form and the SNMP browser synced
$('#text-ip_target').keyup(function() {
$('#text-target_ip').val($(this).val());
});
$('#text-target_ip').keyup(function() {
$('#text-ip_target').val($(this).val());
});
$('#text-community').keyup(function() {
$('#text-snmp_community').val($(this).val());
});
$('#text-snmp_community').keyup(function() {
$('#text-community').val($(this).val());
});
});
</script>
// 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());
}
</script>

View File

@ -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] = '<strong>'.__('OID').'</strong>';
$table->data[0][1] = $oid['oid'];
$table->data[1][0] = '<strong>'.__('Numeric OID').'</strong>';
$table->data[1][1] = $oid['numeric_oid'];
$table->data[1][1] = '<span id="snmp_selected_oid">' . $oid['numeric_oid'] . '</span>';
$table->data[2][0] = '<strong>'.__('Value').'</strong>';
$table->data[2][1] = $oid['value'];
$i = 3;
@ -336,9 +339,91 @@ function snmp_browser_print_oid ($oid = array()) {
$i++;
}
echo '<a href="#" onClick="hideOIDData();">';
html_print_image ("images/cancel.png", false, array ("style" => 'vertical-align: middle;'), false);
echo '</a>';
html_print_table($table, false);
$output = '<a href="javascript:" onClick="hideOIDData();">';
$output .= html_print_image ("images/cancel.png", true, array ("title" => __('Close'), "style" => 'vertical-align: middle;'), false);
$output .= '</a>';
// Add a span for custom actions
if ($custom_action != '') {
$output .= '<span id="snmp_custom_action">' . $custom_action . '</span>';
}
$output .= html_print_table($table, true);
if ($return) {
return $output;
}
echo $output;
}
?>
/**
* 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] = '<strong>'.__('Target IP').'</strong>';
$table->data[0][1] = html_print_input_text ('target_ip', '', '', 25, 0, true);
$table->data[0][2] = '<strong>'.__('Community').'</strong>';
$table->data[0][3] = html_print_input_text ('community', '', '', 25, 0, true);
$table->data[0][4] = '<a href="javascript:">' . html_print_image ("images/fullscreen.png", true, array ('title' => __('Expand the tree') . ' (' . __('can be slow') . ')', 'style' => 'vertical-align: middle;', 'onclick' => 'expandAll();')) . '</a>';
$table->data[0][4] .= '&nbsp;' . '<a href="javascript:">' . html_print_image ("images/normalscreen.png", true, array ('title' => __('Collapse the tree'), 'style' => 'vertical-align: middle;', 'onclick' => 'collapseAll();')) . '</a>';
$table->data[1][0] = '<strong>'.__('Starting OID').'</strong>';
$table->data[1][1] = html_print_input_text ('starting_oid', '', '', 25, 0, true);
$table->data[1][2] = '<strong>'.__('Search text').'</strong>';
$table->data[1][3] = html_print_input_text ('search_text', '', '', 25, 0, true);
$table->data[1][4] = '<a href="javascript:">' . html_print_image ("images/lupa.png", true, array ('title' => __('Search'), 'style' => 'vertical-align: middle;', 'onclick' => 'searchText();')) . '</a>';
$table->data[1][4] .= '&nbsp;' . '<a href="javascript:">' . html_print_image ("images/go_first.png", true, array ('title' => __('First match'), 'style' => 'vertical-align: middle;', 'onclick' => 'searchFirstMatch();')) . '</a>';
$table->data[1][4] .= '&nbsp;' . '<a href="javascript:">' . html_print_image ("images/go_previous.png", true, array ('title' => __('Previous match'), 'style' => 'vertical-align: middle;', 'onclick' => 'searchPrevMatch();')) . '</a>';
$table->data[1][4] .= '&nbsp;' . '<a href="javascript:">' . html_print_image ("images/go_next.png", true, array ('title' => __('Next match'), 'style' => 'vertical-align: middle;', 'onclick' => 'searchNextMatch();')) . '</a>';
$table->data[1][4] .= '&nbsp;' . '<a href="javascript:">' . html_print_image ("images/go_last.png", true, array ('title' => __('Last match'), 'style' => 'vertical-align: middle;', 'onclick' => 'searchLastMatch();')) . '</a>';
// This extra div that can be handled by jquery's dialog
$output = '<div id="snmp_browser_container" style="display:' . $display . '">';
$output .= '<div style="text-align: left; width: ' . $width . '; height: ' . $height . ';">';
$output .= '<div style="width: 100%">';
$output .= html_print_table($table, true);
$output .= '</div>';
$output .= '<div>';
$output .= html_print_button(__('Browse'), 'browse', false, 'snmpBrowse()', 'class="sub upd"', true);
$output .= '</div>';
// SNMP tree container
$output .= '<div style="width: 100%; height: 100%; margin-top: 5px; position: relative;">';
$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 .= '<div id="search_results" style="display: none; padding: 5px; background-color: #EAEAEA; border: 1px solid #E2E2E2; border-radius: 4px;"></div>';
$output .= '<div id="spinner" style="position: absolute; top:0; left:0px; display:none;">' . html_print_image ("images/spinner.gif", true) . '</div>';
$output .= '<div id="snmp_browser" style="height: 100%; overflow: auto; background-color: #F4F5F4; border: 1px solid #E2E2E2; border-radius: 4px; "></div>';
$output .= '<div id="snmp_data" style="display: none; width: 40%; position: absolute; top:0; right:20px"></div>';
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
if ($return) {
return $output;
}
echo $output;
}
?>

View File

@ -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 = $("<option></option>").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 ()

View File

@ -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] = '<strong>'.__('Target IP').'</strong>';
$table->data[0][1] = html_print_input_text ('target_ip', '', '', 25, 0, true);
$table->data[0][2] = '<strong>'.__('Community').'</strong>';
$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] .= '&nbsp;' . html_print_image ("images/normalscreen.png", true, array ('title' => __('Collapse the tree'), 'style' => 'vertical-align: middle;', 'onclick' => 'collapseAll();'));
$table->data[1][0] = '<strong>'.__('Starting OID').'</strong>';
$table->data[1][1] = html_print_input_text ('starting_oid', '', '', 25, 0, true);
$table->data[1][2] = '<strong>'.__('Search text').'</strong>';
$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] .= '&nbsp;' . html_print_image ("images/go_first.png", true, array ('title' => __('First match'), 'style' => 'vertical-align: middle;', 'onclick' => 'searchFirstMatch();'));
$table->data[1][4] .= '&nbsp;' . html_print_image ("images/go_previous.png", true, array ('title' => __('Previous match'), 'style' => 'vertical-align: middle;', 'onclick' => 'searchPrevMatch();'));
$table->data[1][4] .= '&nbsp;' . html_print_image ("images/go_next.png", true, array ('title' => __('Next match'), 'style' => 'vertical-align: middle;', 'onclick' => 'searchNextMatch();'));
$table->data[1][4] .= '&nbsp;' . html_print_image ("images/go_last.png", true, array ('title' => __('Last match'), 'style' => 'vertical-align: middle;', 'onclick' => 'searchLastMatch();'));
echo '<div style="width: 95%">';
echo html_print_table($table, true);
html_print_input_hidden ('search_count', 0, false);
html_print_input_hidden ('search_index', -1, false);
echo '<div>';
echo html_print_button(__('Browse'), 'browse', false, 'snmpBrowse()', 'class="sub upd"', true);
echo '</div>';
echo '</div>';
// SNMP tree
echo '<div style="width: 95%; margin-top: 5px; background-color: #F4F5F4; border: 1px solid #E2E2E2; border-radius: 4px; position: relative">';
echo '<div id="search_results" style="display:none; padding: 5px; background-color: #EAEAEA;"></div>';
echo '<div id="spinner" style="position: absolute; top:0; left:0px; display:none;">' . html_print_image ("images/spinner.gif", true) . '</div>';
echo '<div id="snmp_browser" style="height: 600px; overflow: auto;"></div>';
echo '<div id="snmp_data" style="width: 40%; position: absolute; top:0; right:20px"></div>';
echo '</div>';
// SNMP tree container
snmp_browser_print_container ();
?>
<script language="JavaScript" type="text/javascript">
// Load the SNMP tree via AJAX
function snmpBrowse () {
// Empty the SNMP tree
$("#snmp_browser").html('');
// Hide the data div
hideOIDData();
// Show the spinner
$("#spinner").css('display', '');
// Read the target IP and community
var target_ip = $('#text-target_ip').val();
var community = $('#text-community').val();
var starting_oid = $('#text-starting_oid').val();
// Prepare the AJAX call
var params = [
"target_ip=" + target_ip,
"community=" + community,
"starting_oid=" + starting_oid,
"action=" + "snmptree",
"page=operation/snmpconsole/snmp_browser"
];
// Browse!
jQuery.ajax ({
data: params.join ("&"),
type: 'POST',
url: action="<?php echo ui_get_full_url("ajax.php", false, false, false); ?>",
async: true,
timeout: 120000,
success: function (data) {
// Hide the spinner
$("#spinner").css('display', 'none');
// Load the SNMP tree
$("#snmp_browser").html(data);
}
});
}
// Expand or collapse an SNMP tree node
function toggleTreeNode(node) {
var display = $("#ul_" + node).css('display');
var src = $("#anchor_" + node).children("img").attr('src');
// Show the expanded or collapsed square
if (display == "none") {
src = src.replace("closed", "expanded");
} else {
src = src.replace("expanded", "closed");
}
$("#anchor_" + node).children("img").attr('src', src);
// Hide or show leaves
$("#ul_" + node).toggle();
}
// Expand an SNMP tree node
function expandTreeNode(node) {
if (node == 0) {
return;
}
// Show the expanded square
var src = $("#anchor_" + node).children("img").attr('src');
src = src.replace("closed", "expanded");
$("#anchor_" + node).children("img").attr('src', src);
// Show leaves
$("#ul_" + node).css('display', '');
}
// Expand an SNMP tree node
function collapseTreeNode(node) {
if (node == 0) {
return;
}
// Show the collapsed square
var src = $("#anchor_" + node).children("img").attr('src');
src = src.replace("expanded", "closed");
$("#anchor_" + node).children("img").attr('src', src);
// Hide leaves
$("#ul_" + node).css('display', 'none');
}
// Expand all tree nodes
function expandAll(node) {
$('#snmp_browser').find('ul').each ( function () {
var id = $(this).attr('id').substr(3);
expandTreeNode (id);
});
}
// Collapse all tree nodes
function collapseAll(node) {
$('#snmp_browser').find('ul').each ( function () {
var id = $(this).attr('id').substr(3);
collapseTreeNode (id);
});
}
// Perform an SNMP get request via AJAX
function snmpGet (oid) {
// Empty previous OID data
$("#snmp_data").html()
// Read the target IP and community
var target_ip = $('#text-target_ip').val();
var community = $('#text-community').val();
// Prepare the AJAX call
var params = [
"target_ip=" + target_ip,
"community=" + community,
"oid=" + oid,
"action=" + "snmpget",
"page=operation/snmpconsole/snmp_browser"
];
// SNMP get!
jQuery.ajax ({
data: params.join ("&"),
type: 'POST',
url: action="<?php echo ui_get_full_url("ajax.php", false, false, false); ?>",
async: true,
timeout: 60000,
success: function (data) {
$("#snmp_data").html(data);
}
});
// Show the data div
showOIDData();
}
// Show the div that displays OID data
function showOIDData() {
$("#snmp_data").css('display', '');
}
// Hide the div that displays OID data
function hideOIDData() {
$("#snmp_data").css('display', 'none');
}
// Search the SNMP tree for a matching string
function searchText() {
var text = $('#text-search_text').val();
var regexp = new RegExp(text);
// Hide previous search result count
$("#search_results").css('display', '');
// Show the spinner
$("#spinner").css('display', '');
// Collapse previously searched nodes
$('.expanded').each( function () {
$(this).removeClass('expanded');
// Remove the leading ul_
var node_id = $(this).attr('id').substr(3);
collapseTreeNode(node_id);
});
// Un-highlight previously searched nodes
$('match').removeClass('match');
$('span').removeClass('group_view_warn');
// Hide values
$('span.value').css('display', 'none');
// Disable empty searches
var count = 0;
if (text != '') {
count = searchTreeNode($('#snmp_browser'), regexp);
}
// Hide the spinner
$("#spinner").css('display', 'none');
// Show and save the search result count
$("#hidden-search_count").val(count);
$("#search_results").text("<?php echo __("Search matches"); ?>" + ': ' + count);
$("#search_results").css('display', '');
// Reset the search index
$("#hidden-search_index").val(-1);
// Focus the first match
searchNextMatch ();
}
// Recursively search an SNMP tree node trying to match the given regexp
function searchTreeNode(obj, regexp) {
// For each node tree
var count = 0;
$(obj).children("ul").each( function () {
var ul_node = this;
// Expand if regexp matches one of its children
$(ul_node).addClass('expand')
// Search children for matches
$(ul_node).children("li").each( function () {
var li_node = this;
var text = $(li_node).text();
// Match!
if (regexp.test(text) == true) {
count++;
// Highlight in yellow
$(li_node).children('span').addClass('group_view_warn');
$(li_node).addClass('match');
// Show the value
$(li_node).children('span.value').css('display', '');
// Expand all nodes that lead to this one
$('.expand').each( function () {
$(this).addClass('expanded');
// Remove the leading ul_
var node_id = $(this).attr('id').substr(3);
expandTreeNode(node_id);
});
}
});
// Search sub nodes
count += searchTreeNode(ul_node, regexp);
// Do not expand this node if it has not been expanded already
$(ul_node).removeClass('expand');
});
return count;
}
// Focus the next search match
function searchNextMatch () {
var search_index = $("#hidden-search_index").val();
var search_count = $("#hidden-search_count").val();
// Update the search index
search_index++;
if (search_index >= search_count) {
search_index = 0;
}
// Get the id of the next element
var id = $('.match:eq(' + search_index + ')').attr('id');
// Scroll
$('#snmp_browser').animate({
scrollTop: $('#snmp_browser').scrollTop() + $('#' + id).offset().top - $('#snmp_browser').offset().top
}, 1000);
// Save the search index
$("#hidden-search_index").val(search_index);
}
// Focus the previous search match
function searchPrevMatch () {
var search_index = $("#hidden-search_index").val();
var search_count = $("#hidden-search_count").val();
// Update the search index
search_index--;
if (search_index < 0) {
search_index = search_count - 1;
}
// Get the id of the next element
var id = $('.match:eq(' + search_index + ')').attr('id');
// Scroll
$('#snmp_browser').animate({
scrollTop: $('#snmp_browser').scrollTop() + $('#' + id).offset().top - $('#snmp_browser').offset().top
}, 1000);
// Save the search index
$("#hidden-search_index").val(search_index);
}
// Focus the first search match
function searchFirstMatch () {
// Reset the search index
$("#hidden-search_index").val(-1);
// Focus the first match
searchNextMatch();
}
// Focus the last search match
function searchLastMatch () {
// Reset the search index
$("#hidden-search_index").val(-1);
// Focus the last match
searchPrevMatch();
}
</script>