2013-02-14 Ramon Novoa <rnovoa@artica.es>
* godmode/setup/setup_netflow.php, include/functions_config.php: Added the deletion of old netflow and log data. * include/functions_snmp_browser.php: Added to repository. SNMP browser specific functions. * operation/menu.php, operation/snmpconsole/snmp_browser.php: Added search capabilities to the SNMP browser and other small improvements. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7656 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
7872a82a35
commit
79806e27cb
|
@ -1,3 +1,16 @@
|
|||
2013-02-14 Ramon Novoa <rnovoa@artica.es>
|
||||
|
||||
* godmode/setup/setup_netflow.php,
|
||||
include/functions_config.php: Added the deletion of old netflow and
|
||||
log data.
|
||||
|
||||
* include/functions_snmp_browser.php: Added to repository. SNMP browser
|
||||
specific functions.
|
||||
|
||||
* operation/menu.php,
|
||||
operation/snmpconsole/snmp_browser.php: Added search capabilities to
|
||||
the SNMP browser and other small improvements.
|
||||
|
||||
2013-02-14 Miguel de Dios <miguel.dedios@artica.es>
|
||||
|
||||
* include/styles/pandora_legacy.css: cleaned source code.
|
||||
|
|
|
@ -37,7 +37,6 @@ $table->border = 0;
|
|||
$table->cellspacing = 3;
|
||||
$table->cellpadding = 5;
|
||||
$table->class = "databox_color";
|
||||
$table->style[0] = 'vertical-align: top;';
|
||||
|
||||
$table->data = array ();
|
||||
|
||||
|
@ -49,12 +48,16 @@ $table->data[2][0] = '<b>'.__('Daemon binary path').'</b>';
|
|||
$table->data[2][1] = html_print_input_text ('netflow_daemon', $config['netflow_daemon'], false, 50, 200, true);
|
||||
$table->data[3][0] = '<b>'.__('Nfdump binary path').'</b>';
|
||||
$table->data[3][1] = html_print_input_text ('netflow_nfdump', $config['netflow_nfdump'], false, 50, 200, true);
|
||||
$table->data[4][0] = '<b>'.__('Maximum chart resolution').'</b>' . ui_print_help_tip (__("Maximum number of points that a netflow area chart will display. The higher the resolution the performance. Values between 50 and 100 are recommended."), true);
|
||||
$table->data[4][1] = html_print_input_text ('netflow_max_resolution', $config['netflow_max_resolution'], false, 50, 200, true);
|
||||
$table->data[5][0] = '<b>'.__('Disable custom live view filters').'</b>' . ui_print_help_tip (__("Disable the definition of custom filters in the live view. Only existing filters can be used."), true);
|
||||
$table->data[5][1] = __('Yes').' '.html_print_radio_button ('netflow_disable_custom_lvfilters', 1, '', $config["netflow_disable_custom_lvfilters"], true).' ';
|
||||
$table->data[5][1] .= __('No').' '.html_print_radio_button ('netflow_disable_custom_lvfilters', 0, '', $config["netflow_disable_custom_lvfilters"], true).' ';
|
||||
|
||||
$table->data[4][0] = '<b>'.__('Nfexpire binary path').'</b>';
|
||||
$table->data[4][1] = html_print_input_text ('netflow_nfexpire', $config['netflow_nfexpire'], false, 50, 200, true);
|
||||
$table->data[5][0] = '<b>'.__('Maximum chart resolution').'</b>' . ui_print_help_tip (__("Maximum number of points that a netflow area chart will display. The higher the resolution the performance. Values between 50 and 100 are recommended."), true);
|
||||
$table->data[5][1] = html_print_input_text ('netflow_max_resolution', $config['netflow_max_resolution'], false, 50, 200, true);
|
||||
$table->data[6][0] = '<b>'.__('Disable custom live view filters').'</b>' . ui_print_help_tip (__("Disable the definition of custom filters in the live view. Only existing filters can be used."), true);
|
||||
$table->data[6][1] = __('Yes').' '.html_print_radio_button ('netflow_disable_custom_lvfilters', 1, '', $config["netflow_disable_custom_lvfilters"], true).' ';
|
||||
$table->data[6][1] .= __('No').' '.html_print_radio_button ('netflow_disable_custom_lvfilters', 0, '', $config["netflow_disable_custom_lvfilters"], true).' ';
|
||||
$table->data[7][0] = '<b>'.__('Netflow max lifetime').'</b>'.ui_print_help_tip (__("Sets the maximum lifetime for netflow data in days."), true);
|
||||
$table->data[7][1] = html_print_input_text ('netflow_max_lifetime', $config['netflow_max_lifetime'], false, 50, 200, true);
|
||||
|
||||
echo '<form id="netflow_setup" method="post">';
|
||||
|
||||
html_print_table ($table);
|
||||
|
|
|
@ -302,14 +302,17 @@ function config_update_config () {
|
|||
break;
|
||||
case 'net':
|
||||
config_update_value ('netflow_path', get_parameter ('netflow_path'));
|
||||
config_update_value ('netflow_interval', get_parameter ('netflow_interval'));
|
||||
config_update_value ('netflow_interval', (int)get_parameter ('netflow_interval'));
|
||||
config_update_value ('netflow_daemon', get_parameter ('netflow_daemon'));
|
||||
config_update_value ('netflow_nfdump', get_parameter ('netflow_nfdump'));
|
||||
config_update_value ('netflow_max_resolution', get_parameter ('netflow_max_resolution'));
|
||||
config_update_value ('netflow_nfexpire', get_parameter ('netflow_nfexpire'));
|
||||
config_update_value ('netflow_max_resolution', (int)get_parameter ('netflow_max_resolution'));
|
||||
config_update_value ('netflow_disable_custom_lvfilters', get_parameter ('netflow_disable_custom_lvfilters'));
|
||||
config_update_value ('netflow_max_lifetime', (int) get_parameter ('netflow_max_lifetime'));
|
||||
break;
|
||||
case 'log':
|
||||
config_update_value ('log_dir', (string)get_parameter('log_dir'));
|
||||
config_update_value ('log_dir', get_parameter('log_dir'));
|
||||
config_update_value ('log_max_lifetime', (int)get_parameter('log_max_lifetime'));
|
||||
break;
|
||||
|
||||
}
|
||||
|
@ -499,6 +502,10 @@ function config_process_config () {
|
|||
config_update_value ('log_dir', '/var/spool/pandora/data_in/log');
|
||||
}
|
||||
|
||||
if (!isset ($config["log_max_lifetime"])) {
|
||||
config_update_value ('log_max_lifetime', 15);
|
||||
}
|
||||
|
||||
if (!isset ($config["font_size"])) {
|
||||
config_update_value ('font_size', 6);
|
||||
}
|
||||
|
@ -609,7 +616,11 @@ function config_process_config () {
|
|||
if (!isset ($config['netflow_nfdump'])) {
|
||||
config_update_value ( 'netflow_nfdump', '/usr/bin/nfdump');
|
||||
}
|
||||
|
||||
|
||||
if (!isset ($config['netflow_nfexpire'])) {
|
||||
config_update_value ( 'netflow_nfexpire', '/usr/bin/nfexpire');
|
||||
}
|
||||
|
||||
if (!isset ($config['netflow_max_resolution'])) {
|
||||
config_update_value ( 'netflow_max_resolution', '50');
|
||||
}
|
||||
|
@ -622,6 +633,10 @@ function config_process_config () {
|
|||
config_update_value ( 'netflow_disable_custom_lvfilters', 0);
|
||||
}
|
||||
|
||||
if (!isset ($config['netflow_max_lifetime'])) {
|
||||
config_update_value ( 'netflow_max_lifetime', '5');
|
||||
}
|
||||
|
||||
if (!isset ($config['auth'])) {
|
||||
config_update_value ( 'auth', 'mysql');
|
||||
}
|
||||
|
|
|
@ -0,0 +1,327 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2013 Artica Soluciones Tecnologicas
|
||||
// Please see http://pandorafms.org for full contribution list
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public License
|
||||
// as published by the Free Software Foundation; version 2
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
|
||||
include_once($config['homedir'] . "/include/functions_config.php");
|
||||
enterprise_include_once ($config['homedir'] . '/enterprise/include/pdf_translator.php');
|
||||
enterprise_include_once ($config['homedir'] . '/enterprise/include/functions_metaconsole.php');
|
||||
|
||||
// Date format for nfdump
|
||||
global $nfdump_date_format;
|
||||
$nfdump_date_format = 'Y/m/d.H:i:s';
|
||||
|
||||
/**
|
||||
* Selects all netflow filters (array (id_name => id_name)) or filters filtered
|
||||
*
|
||||
* @param tree string SNMP tree returned by snmp_broser_get_tree.
|
||||
* @param id string Level ID. Do not set, used for recursion.
|
||||
* @param depth string Branch depth. Do not set, used for recursion.
|
||||
*
|
||||
*/
|
||||
function snmp_browser_print_tree ($tree, $id = 0, $depth = 0, $last = 0, $last_array = array()) {
|
||||
|
||||
// Leaf
|
||||
if (empty ($tree['__LEAVES__'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
$total = sizeof (array_keys ($tree['__LEAVES__'])) - 1;
|
||||
$last_array[$depth] = $last;
|
||||
|
||||
if ($depth > 0) {
|
||||
echo "<ul id='ul_$id' style='margin: 0; padding: 0; display: none'>\n";
|
||||
} else {
|
||||
echo "<ul id='ul_$id' style='margin: 0; padding: 0;'>\n";
|
||||
}
|
||||
foreach ($tree['__LEAVES__'] as $level => $sub_level) {
|
||||
|
||||
// Id used to expand leafs
|
||||
$sub_id = time() . rand(0, getrandmax());
|
||||
|
||||
// Display the branch
|
||||
echo "<li id='li_$sub_id' style='margin: 0; padding: 0;'>";
|
||||
|
||||
// Indent sub branches
|
||||
for ($i = 1; $i <= $depth; $i++) {
|
||||
if ($last_array[$i] == 1) {
|
||||
html_print_image ("operation/tree/no_branch.png", false, array ("style" => 'vertical-align: middle;'));
|
||||
} else {
|
||||
html_print_image ("operation/tree/branch.png", false, array ("style" => 'vertical-align: middle;'));
|
||||
}
|
||||
}
|
||||
|
||||
// Branch
|
||||
if (! empty ($sub_level['__LEAVES__'])) {
|
||||
echo "<a id='anchor_$sub_id' onfocus='javascript: this.blur();' href='javascript: toggleTreeNode(\"$sub_id\", \"$id\");'>";
|
||||
if ($depth == 0 && $count == 0) {
|
||||
if ($count == $total) {
|
||||
html_print_image ("operation/tree/one_closed.png", false, array ("style" => 'vertical-align: middle;'));
|
||||
} else {
|
||||
html_print_image ("operation/tree/first_closed.png", false, array ("style" => 'vertical-align: middle;'));
|
||||
}
|
||||
} else if ($count == $total) {
|
||||
html_print_image ("operation/tree/last_closed.png", false, array ("style" => 'vertical-align: middle;'));
|
||||
} else {
|
||||
html_print_image ("operation/tree/closed.png", false, array ("style" => 'vertical-align: middle;'));
|
||||
}
|
||||
echo "</a>";
|
||||
}
|
||||
// Leave
|
||||
else {
|
||||
if ($depth == 0 && $count == 0) {
|
||||
if ($count == $total) {
|
||||
html_print_image ("operation/tree/no_branch.png", false, array ("style" => 'vertical-align: middle;'));
|
||||
} else {
|
||||
html_print_image ("operation/tree/first_leaf.png", false, array ("style" => 'vertical-align: middle;'));
|
||||
}
|
||||
} else if ($count == $total) {
|
||||
html_print_image ("operation/tree/last_leaf.png", false, array ("style" => 'vertical-align: middle;'));
|
||||
} else {
|
||||
html_print_image ("operation/tree/leaf.png", false, array ("style" => 'vertical-align: middle;'));
|
||||
}
|
||||
}
|
||||
|
||||
// Branch or leave with branches!
|
||||
if (isset ($sub_level['__OID__'])) {
|
||||
echo "<a onfocus='javascript: this.blur();' href='javascript: snmpGet(\"" . addslashes($sub_level['__OID__']) . "\");'>";
|
||||
html_print_image ("images/computer_error.png", false, array ("style" => 'vertical-align: middle;'));
|
||||
echo "</a>";
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
echo '<span>' . $level . '</span>';
|
||||
if (isset ($sub_level['__VALUE__'])) {
|
||||
echo '<span class="value" style="display: none;"> = ' . $sub_level['__VALUE__'] . '</span>';
|
||||
}
|
||||
echo "</li>";
|
||||
|
||||
// Recursively print sub levels
|
||||
snmp_browser_print_tree ($sub_level, $sub_id, $depth + 1, ($count == $total ? 1 : 0), $last_array);
|
||||
|
||||
$count++;
|
||||
}
|
||||
echo "</ul>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the SNMP tree for the given SNMP agent.
|
||||
*
|
||||
* @param target_ip string IP of the SNMP agent.
|
||||
* @param community string SNMP community to use.
|
||||
*
|
||||
* @return array The SNMP tree.
|
||||
*/
|
||||
function snmp_browser_get_tree ($target_ip, $community, $starting_oid = '.') {
|
||||
global $config;
|
||||
|
||||
if ($target_ip == '') {
|
||||
return __('Target IP cannot be blank.');
|
||||
}
|
||||
|
||||
// Call snmpwalk
|
||||
$oid_tree = array('__LEAVES__' => array());
|
||||
exec ('snmpwalk -m ALL -M +' . escapeshellarg($config['homedir'] . '/attachment/mibs') . ' -Cc -c ' . escapeshellarg($community) . ' -v 1 ' . escapeshellarg($target_ip) . ' ' . escapeshellarg($starting_oid), $output, $rc);
|
||||
|
||||
//if ($rc != 0) {
|
||||
// return __('No data');
|
||||
//}
|
||||
foreach ($output as $line) {
|
||||
|
||||
// Separate the OID from the value
|
||||
$full_oid = explode ('=', $line);
|
||||
if (! isset ($full_oid[1])) {
|
||||
continue;
|
||||
}
|
||||
$oid = trim($full_oid[0]);
|
||||
$value = trim ($full_oid[1]);
|
||||
|
||||
// Parse the OID
|
||||
$group = 0;
|
||||
$sub_oid = "";
|
||||
$ptr = &$oid_tree['__LEAVES__'];
|
||||
|
||||
for ($i = 0; $i < strlen ($oid); $i++) {
|
||||
|
||||
// "X.Y.Z"
|
||||
if ($oid[$i] == '"') {
|
||||
$group = $group ^ 1;
|
||||
}
|
||||
|
||||
// Move to the next element of the OID
|
||||
if ($group == 0 && $oid[$i] == '.') {
|
||||
|
||||
// Starting dot
|
||||
if ($sub_oid == '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! isset ($ptr[$sub_oid]) || ! isset ($ptr[$sub_oid]['__LEAVES__'])) {
|
||||
$ptr[$sub_oid]['__LEAVES__'] = array();
|
||||
}
|
||||
|
||||
$ptr = &$ptr[$sub_oid]['__LEAVES__'];
|
||||
$sub_oid = '';
|
||||
} else {
|
||||
if ($oid[$i] != '"') {
|
||||
$sub_oid .= $oid[$i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The last element will contain the full OID
|
||||
$ptr[$sub_oid] = array('__OID__' => $oid, '__VALUE__' => $value);
|
||||
$ptr = &$ptr[$sub_oid];
|
||||
$sub_oid = "";
|
||||
}
|
||||
|
||||
return$oid_tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve data for the specified OID.
|
||||
*
|
||||
* @param target_ip string IP of the SNMP agent.
|
||||
* @param community string SNMP community to use.
|
||||
* @param target_oid SNMP OID to query.
|
||||
*
|
||||
* @return array OID data.
|
||||
*
|
||||
*/
|
||||
function snmp_browser_get_oid ($target_ip, $community, $target_oid) {
|
||||
global $config;
|
||||
|
||||
if ($target_oid == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$oid_data['oid'] = $target_oid;
|
||||
exec ('snmpget -m ALL -M +' . escapeshellarg($config['homedir'] . '/attachment/mibs') . ' -On -v1 -c ' . escapeshellarg($community) . " " . escapeshellarg($target_ip) . ' ' . escapeshellarg($target_oid), $output, $rc);
|
||||
if ($rc != 0) {
|
||||
return $oid_data;
|
||||
}
|
||||
|
||||
foreach ($output as $line) {
|
||||
|
||||
// Separate the OID from the value
|
||||
$full_oid = explode ('=', $line);
|
||||
if (! isset ($full_oid[1])) {
|
||||
break;
|
||||
}
|
||||
|
||||
$oid = trim($full_oid[0]);
|
||||
$oid_data['numeric_oid'] = $oid;
|
||||
|
||||
// Translate the OID
|
||||
exec ("snmptranslate -Td " . escapeshellarg($oid), $translate_output);
|
||||
foreach ($translate_output as $line) {
|
||||
if (preg_match ('/SYNTAX\s+(.*)/', $line, $matches) == 1) {
|
||||
$oid_data['syntax'] = $matches[1];
|
||||
}
|
||||
else if (preg_match ('/MAX-ACCESS\s+(.*)/', $line, $matches) == 1) {
|
||||
$oid_data['max_access'] = $matches[1];
|
||||
}
|
||||
else if (preg_match ('/STATUS\s+(.*)/', $line, $matches) == 1) {
|
||||
$oid_data['status'] = $matches[1];
|
||||
}
|
||||
else if (preg_match ('/DISPLAY\-HINT\s+(.*)/', $line, $matches) == 1) {
|
||||
$oid_data['display_hint'] = $matches[1];
|
||||
}
|
||||
}
|
||||
|
||||
// Parse the description
|
||||
$translate_output = implode ('', $translate_output);
|
||||
if (preg_match ('/DESCRIPTION\s+\"(.*)\"/', $translate_output, $matches) == 1) {
|
||||
$oid_data['description'] = $matches[1];
|
||||
}
|
||||
|
||||
$full_value = explode (':', trim ($full_oid[1]));
|
||||
if (! isset ($full_value[1])) {
|
||||
$oid_data['value'] = trim ($full_oid[1]);
|
||||
} else {
|
||||
$oid_data['type'] = trim($full_value[0]);
|
||||
$oid_data['value'] = trim($full_value[1]);
|
||||
}
|
||||
|
||||
return $oid_data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the given OID data.
|
||||
*
|
||||
* @param $oid array OID data.
|
||||
*
|
||||
*/
|
||||
function snmp_browser_print_oid ($oid = array()) {
|
||||
|
||||
// OID information table
|
||||
$table->width = '100%';
|
||||
$table->size = array ();
|
||||
$table->data = array ();
|
||||
|
||||
foreach (array('oid', 'numeric_oid', 'value') as $key) {
|
||||
if (! isset ($oid[$key])) {
|
||||
$oid[$key] = '';
|
||||
}
|
||||
}
|
||||
|
||||
$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[2][0] = '<strong>'.__('Value').'</strong>';
|
||||
$table->data[2][1] = $oid['value'];
|
||||
$i = 3;
|
||||
if (isset ($oid['type'])) {
|
||||
$table->data[$i][0] = '<strong>'.__('Type').'</strong>';
|
||||
$table->data[$i][1] = $oid['type'];
|
||||
$i++;
|
||||
}
|
||||
if (isset ($oid['description'])) {
|
||||
$table->data[$i][0] = '<strong>'.__('Description').'</strong>';
|
||||
$table->data[$i][1] = $oid['description'];
|
||||
$i++;
|
||||
}
|
||||
if (isset ($oid['syntax'])) {
|
||||
$table->data[$i][0] = '<strong>'.__('Syntax').'</strong>';
|
||||
$table->data[$i][1] = $oid['syntax'];
|
||||
$i++;
|
||||
}
|
||||
if (isset ($oid['display_hint'])) {
|
||||
$table->data[$i][0] = '<strong>'.__('Display hint').'</strong>';
|
||||
$table->data[$i][1] = $oid['display_hint'];
|
||||
$i++;
|
||||
}
|
||||
if (isset ($oid['max_access'])) {
|
||||
$table->data[$i][0] = '<strong>'.__('Max access').'</strong>';
|
||||
$table->data[$i][1] = $oid['max_access'];
|
||||
$i++;
|
||||
}
|
||||
if (isset ($oid['status'])) {
|
||||
$table->data[$i][0] = '<strong>'.__('Status').'</strong>';
|
||||
$table->data[$i][1] = $oid['status'];
|
||||
$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);
|
||||
}
|
||||
|
||||
?>
|
|
@ -333,7 +333,7 @@ if (check_acl ($config['id_user'], 0, "IR")) {
|
|||
if (check_acl ($config['id_user'], 0, "AR")) {
|
||||
|
||||
//SNMP Console
|
||||
$menu_operation["snmpconsole"]["text"] = __('SNMP console');
|
||||
$menu_operation["snmpconsole"]["text"] = __('SNMP');
|
||||
$menu_operation["snmpconsole"]["refr"] = 0;
|
||||
$menu_operation["snmpconsole"]["sec2"] = "operation/snmpconsole/snmp_view";
|
||||
$menu_operation["snmpconsole"]["id"] = "oper-snmpc";
|
||||
|
|
|
@ -73,7 +73,7 @@ if ($config["pure"]) {
|
|||
ui_print_page_header (__("SNMP Browser"), "images/computer_error.png", false, "", false, $link);
|
||||
|
||||
// Target selection
|
||||
$table->width = '90%';
|
||||
$table->width = '100%';
|
||||
$table->size = array ();
|
||||
$table->data = array ();
|
||||
|
||||
|
@ -82,31 +82,38 @@ $table->data[0][0] = '<strong>'.__('Target IP').'</strong>';
|
|||
$table->data[0][1] = html_print_input_text ('target_ip', '', '', 50, 0, true);
|
||||
$table->data[0][2] = '<strong>'.__('Community').'</strong>';
|
||||
$table->data[0][3] = html_print_input_text ('community', '', '', 50, 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] = '<strong>'.__('Starting OID').'</strong>';
|
||||
$table->data[1][1] = html_print_input_text ('starting_oid', '', '', 50, 0, true);
|
||||
$table->data[1][2] = '<strong>'.__('Search text').'</strong>';
|
||||
$table->data[1][3] = html_print_input_text ('search_text', '', '', 50, 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 '<div>';
|
||||
echo '<div style="width: 95%">';
|
||||
echo html_print_table($table, true);
|
||||
echo '</div>';
|
||||
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
|
||||
$table->width = '100%';
|
||||
$table->size = array ();
|
||||
$table->data = array ();
|
||||
$table->data[0][0] = '<div style="height: 500px; position: relative">';
|
||||
$table->data[0][0] .= '<div id="spinner" style="display:none;">' . html_print_image ("images/spinner.gif", true, array ("style" => 'vertical-align: middle;'), false) . '</div>';
|
||||
$table->data[0][0] .= '<div id="snmp_browser" style="height: 500px; overflow: auto;"></div>';
|
||||
$table->data[0][0] .= '<div id="snmp_data" style="width: 40%; position: absolute; top:0; right:20px"></div>';
|
||||
$table->data[0][0] .= '</div>';
|
||||
html_print_table($table, false);
|
||||
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>';
|
||||
|
||||
?>
|
||||
|
||||
<script language="JavaScript" type="text/javascript">
|
||||
<!--
|
||||
|
||||
// Load the SNMP tree via AJAX
|
||||
function snmpBrowse () {
|
||||
|
@ -152,10 +159,10 @@ function snmpBrowse () {
|
|||
});
|
||||
}
|
||||
|
||||
// Expand an SNMP tree node
|
||||
function expandTreeNode(node) {
|
||||
// Expand or collapse an SNMP tree node
|
||||
function toggleTreeNode(node) {
|
||||
|
||||
var display = $("#" + node).css('display');
|
||||
var display = $("#ul_" + node).css('display');
|
||||
var src = $("#anchor_" + node).children("img").attr('src');
|
||||
|
||||
// Show the expanded or collapsed square
|
||||
|
@ -167,7 +174,57 @@ function expandTreeNode(node) {
|
|||
$("#anchor_" + node).children("img").attr('src', src);
|
||||
|
||||
// Hide or show leaves
|
||||
$("#" + node).toggle();
|
||||
$("#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
|
||||
|
@ -215,5 +272,170 @@ 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>
|
||||
|
|
Loading…
Reference in New Issue