Added port, limited base OID (default) removed timeout (browser) capturing error to message
This commit is contained in:
parent
67c51b0e96
commit
e711239c69
|
@ -25,6 +25,7 @@ if (is_ajax()) {
|
||||||
$method = (string) get_parameter('method', '');
|
$method = (string) get_parameter('method', '');
|
||||||
$action = (string) get_parameter('action', '');
|
$action = (string) get_parameter('action', '');
|
||||||
$target_ip = (string) get_parameter('target_ip', '');
|
$target_ip = (string) get_parameter('target_ip', '');
|
||||||
|
$target_port = (string) get_parameter('target_port', '');
|
||||||
$community = (string) io_safe_output((get_parameter('community', '')));
|
$community = (string) io_safe_output((get_parameter('community', '')));
|
||||||
$snmp_version = (string) get_parameter('snmp_browser_version', '');
|
$snmp_version = (string) get_parameter('snmp_browser_version', '');
|
||||||
$snmp3_auth_user = io_safe_output(get_parameter('snmp3_browser_auth_user'));
|
$snmp3_auth_user = io_safe_output(get_parameter('snmp3_browser_auth_user'));
|
||||||
|
@ -63,7 +64,8 @@ if (is_ajax()) {
|
||||||
$snmp3_privacy_method,
|
$snmp3_privacy_method,
|
||||||
$snmp3_privacy_pass,
|
$snmp3_privacy_pass,
|
||||||
'null',
|
'null',
|
||||||
$server_to_exec
|
$server_to_exec,
|
||||||
|
$target_port
|
||||||
);
|
);
|
||||||
if (! is_array($snmp_tree)) {
|
if (! is_array($snmp_tree)) {
|
||||||
echo $snmp_tree;
|
echo $snmp_tree;
|
||||||
|
|
|
@ -2001,6 +2001,10 @@ function get_snmpwalk(
|
||||||
) {
|
) {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
|
if (empty($ip_target) === true) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
// Note: quick_print is ignored
|
// Note: quick_print is ignored
|
||||||
// Fix for snmp port
|
// Fix for snmp port
|
||||||
if (!empty($snmp_port)) {
|
if (!empty($snmp_port)) {
|
||||||
|
|
|
@ -265,94 +265,43 @@ function snmp_browser_get_tree(
|
||||||
$snmp3_privacy_method='',
|
$snmp3_privacy_method='',
|
||||||
$snmp3_privacy_pass='',
|
$snmp3_privacy_pass='',
|
||||||
$snmp3_context_engine_id=null,
|
$snmp3_context_engine_id=null,
|
||||||
$server_to_exec=0
|
$server_to_exec=0,
|
||||||
|
$target_port=''
|
||||||
) {
|
) {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
if ($server_to_exec != 0) {
|
|
||||||
$output = get_snmpwalk(
|
$output = get_snmpwalk(
|
||||||
|
// Ip_target.
|
||||||
$target_ip,
|
$target_ip,
|
||||||
|
// Snmp_version.
|
||||||
$version,
|
$version,
|
||||||
|
// Snmp_community.
|
||||||
$community,
|
$community,
|
||||||
|
// Snmp3_auth_user.
|
||||||
$snmp3_auth_user,
|
$snmp3_auth_user,
|
||||||
|
// Snmp3_security_level.
|
||||||
$snmp3_security_level,
|
$snmp3_security_level,
|
||||||
|
// Snmp3_auth_method.
|
||||||
$snmp3_auth_method,
|
$snmp3_auth_method,
|
||||||
|
// Snmp3_auth_pass.
|
||||||
$snmp3_auth_pass,
|
$snmp3_auth_pass,
|
||||||
|
// Snmp3_privacy_method.
|
||||||
$snmp3_privacy_method,
|
$snmp3_privacy_method,
|
||||||
|
// Snmp3_privacy_pass.
|
||||||
$snmp3_privacy_pass,
|
$snmp3_privacy_pass,
|
||||||
|
// Quick_print.
|
||||||
0,
|
0,
|
||||||
|
// Base_oid.
|
||||||
$starting_oid,
|
$starting_oid,
|
||||||
'',
|
// Snmp_port.
|
||||||
|
$target_port,
|
||||||
|
// Server_to_exec.
|
||||||
$server_to_exec,
|
$server_to_exec,
|
||||||
|
// Extra_arguments.
|
||||||
'',
|
'',
|
||||||
|
// Format.
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
switch ($version) {
|
|
||||||
case '1':
|
|
||||||
$snmp_version = SNMP::VERSION_1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '2':
|
|
||||||
$snmp_version = SNMP::VERSION_2C;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '2c':
|
|
||||||
$snmp_version = SNMP::VERSION_2C;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '3':
|
|
||||||
$snmp_version = SNMP::VERSION_3;
|
|
||||||
$community = $snmp3_auth_user;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
$snmp_version = SNMP::VERSION_2C;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$snmp_session = new SNMP($snmp_version, $target_ip, $community);
|
|
||||||
$snmp_session->oid_output_format = SNMP_OID_OUTPUT_MODULE;
|
|
||||||
|
|
||||||
// Set security if SNMP Version is 3.
|
|
||||||
if ($snmp_version == SNMP::VERSION_3) {
|
|
||||||
$snmp_session->setSecurity(
|
|
||||||
$snmp3_security_level,
|
|
||||||
$snmp3_auth_method,
|
|
||||||
$snmp3_auth_pass,
|
|
||||||
$snmp3_privacy_method,
|
|
||||||
$snmp3_privacy_pass,
|
|
||||||
'',
|
|
||||||
$snmp3_context_engine_id
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$mibs_dir = $config['homedir'].'/attachment/mibs';
|
|
||||||
$_dir = opendir($mibs_dir);
|
|
||||||
|
|
||||||
// Future. Recomemended: Use a global config limit of MIBs loaded.
|
|
||||||
while (($mib_file = readdir($_dir)) !== false) {
|
|
||||||
if ($mib_file == '..' || $mib_file == '.') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$rs = snmp_read_mib($mibs_dir.'/'.$mib_file);
|
|
||||||
if ($rs !== true) {
|
|
||||||
error_log('Failed while reading MIB file: '.$mib_file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
closedir($_dir);
|
|
||||||
|
|
||||||
$output = $snmp_session->walk($starting_oid);
|
|
||||||
if ($output == false) {
|
|
||||||
$output = $snmp_session->getError();
|
|
||||||
$snmp_session->close();
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
|
|
||||||
$snmp_session->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build the tree if output comes filled.
|
// Build the tree if output comes filled.
|
||||||
if (empty($output) === false) {
|
if (empty($output) === false) {
|
||||||
|
@ -575,6 +524,7 @@ function snmp_browser_print_oid(
|
||||||
$output = '';
|
$output = '';
|
||||||
|
|
||||||
// OID information table
|
// OID information table
|
||||||
|
$table = new StdClass();
|
||||||
$table->width = '100%';
|
$table->width = '100%';
|
||||||
$table->size = [];
|
$table->size = [];
|
||||||
$table->data = [];
|
$table->data = [];
|
||||||
|
@ -725,15 +675,33 @@ function snmp_browser_print_container(
|
||||||
$table->size = [];
|
$table->size = [];
|
||||||
$table->data = [];
|
$table->data = [];
|
||||||
|
|
||||||
$table->data[0][0] = '<strong>'.__('Target IP').'</strong> ';
|
$table->size[0] = '30%';
|
||||||
$table->data[0][0] .= html_print_input_text(
|
|
||||||
'target_ip',
|
$table->data[0][0] = '<div class="mw500px"><strong>'.__('Target IP').'</strong> ';
|
||||||
get_parameter('target_ip', ''),
|
$table->data[0][0] .= html_print_input(
|
||||||
'',
|
[
|
||||||
25,
|
'type' => 'text',
|
||||||
0,
|
'name' => 'target_ip',
|
||||||
true
|
'value' => get_parameter('target_ip', ''),
|
||||||
|
'required' => true,
|
||||||
|
'size' => 25,
|
||||||
|
'maxlength' => 0,
|
||||||
|
'return' => true,
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
$table->data[0][0] .= '  <strong>'.__('Port').'</strong> ';
|
||||||
|
$table->data[0][0] .= html_print_input(
|
||||||
|
[
|
||||||
|
'type' => 'number',
|
||||||
|
'name' => 'target_port',
|
||||||
|
'id' => 'target_port',
|
||||||
|
'value' => get_parameter('target_port', 161),
|
||||||
|
'required' => true,
|
||||||
|
'return' => true,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$table->data[0][0] .= '</div>';
|
||||||
|
|
||||||
$table->data[0][1] = '<strong>'.__('Community').'</strong> ';
|
$table->data[0][1] = '<strong>'.__('Community').'</strong> ';
|
||||||
$table->data[0][1] .= html_print_input_text(
|
$table->data[0][1] .= html_print_input_text(
|
||||||
'community',
|
'community',
|
||||||
|
@ -746,7 +714,7 @@ function snmp_browser_print_container(
|
||||||
$table->data[0][2] = '<strong>'.__('Starting OID').'</strong> ';
|
$table->data[0][2] = '<strong>'.__('Starting OID').'</strong> ';
|
||||||
$table->data[0][2] .= html_print_input_text(
|
$table->data[0][2] .= html_print_input_text(
|
||||||
'starting_oid',
|
'starting_oid',
|
||||||
get_parameter('starting_oid', '.1.3.6.1.2'),
|
get_parameter('starting_oid', '.1.3.6.1.2.1.2.2'),
|
||||||
'',
|
'',
|
||||||
25,
|
25,
|
||||||
0,
|
0,
|
||||||
|
@ -805,13 +773,16 @@ function snmp_browser_print_container(
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
$table->data[1][2] = html_print_button(
|
$table->data[1][2] = html_print_input(
|
||||||
__('Browse'),
|
[
|
||||||
'browse',
|
'type' => 'submit',
|
||||||
false,
|
'label' => __('Browse'),
|
||||||
'snmpBrowse()',
|
'name' => 'browse',
|
||||||
'class="sub search" style="margin-top:0px;"',
|
'disabled' => false,
|
||||||
true
|
'script' => 'snmpBrowse()',
|
||||||
|
'attributes' => 'class="sub search" style="margin-top:0px;"',
|
||||||
|
'return' => true,
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
// SNMP v3 options.
|
// SNMP v3 options.
|
||||||
|
@ -1013,8 +984,9 @@ function snmp_browser_print_container(
|
||||||
$output = '<div id="snmp_browser_container" style="'.$display.'">';
|
$output = '<div id="snmp_browser_container" style="'.$display.'">';
|
||||||
$output .= '<div style="text-align: left; width: '.$width.'; height: '.$height.';">';
|
$output .= '<div style="text-align: left; width: '.$width.'; height: '.$height.';">';
|
||||||
$output .= '<div style="width: 100%">';
|
$output .= '<div style="width: 100%">';
|
||||||
|
$output .= '<form onsubmit="snmpBrowse(); return false;">';
|
||||||
$output .= html_print_table($table, true);
|
$output .= html_print_table($table, true);
|
||||||
$output .= '</div>';
|
$output .= '</form></div>';
|
||||||
|
|
||||||
if (isset($snmp_version) === false) {
|
if (isset($snmp_version) === false) {
|
||||||
$snmp_version = null;
|
$snmp_version = null;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* globals $,jQuery */
|
||||||
// Load the SNMP tree via AJAX
|
// Load the SNMP tree via AJAX
|
||||||
function snmpBrowse() {
|
function snmpBrowse() {
|
||||||
// Empty the SNMP tree
|
// Empty the SNMP tree
|
||||||
|
@ -15,6 +16,7 @@ function snmpBrowse() {
|
||||||
|
|
||||||
// Read the target IP and community
|
// Read the target IP and community
|
||||||
var target_ip = $("#text-target_ip").val();
|
var target_ip = $("#text-target_ip").val();
|
||||||
|
var target_port = $("#target_port").val();
|
||||||
var community = $("#text-community").val();
|
var community = $("#text-community").val();
|
||||||
var starting_oid = $("#text-starting_oid").val();
|
var starting_oid = $("#text-starting_oid").val();
|
||||||
var snmp_version = $("#snmp_browser_version").val();
|
var snmp_version = $("#snmp_browser_version").val();
|
||||||
|
@ -25,13 +27,13 @@ function snmpBrowse() {
|
||||||
var snmp3_auth_pass = $("#password-snmp3_browser_auth_pass").val();
|
var snmp3_auth_pass = $("#password-snmp3_browser_auth_pass").val();
|
||||||
var snmp3_privacy_method = $("#snmp3_browser_privacy_method").val();
|
var snmp3_privacy_method = $("#snmp3_browser_privacy_method").val();
|
||||||
var snmp3_privacy_pass = $("#password-snmp3_browser_privacy_pass").val();
|
var snmp3_privacy_pass = $("#password-snmp3_browser_privacy_pass").val();
|
||||||
var server_to_exec = $("#server_to_exec").val();
|
|
||||||
var ajax_url = $("#hidden-ajax_url").val();
|
var ajax_url = $("#hidden-ajax_url").val();
|
||||||
|
|
||||||
// Prepare the AJAX call
|
// Prepare the AJAX call
|
||||||
|
|
||||||
var params = {};
|
var params = {};
|
||||||
params["target_ip"] = target_ip;
|
params["target_ip"] = target_ip;
|
||||||
|
params["target_port"] = target_port;
|
||||||
params["community"] = community;
|
params["community"] = community;
|
||||||
params["starting_oid"] = starting_oid;
|
params["starting_oid"] = starting_oid;
|
||||||
params["snmp_browser_version"] = snmp_version;
|
params["snmp_browser_version"] = snmp_version;
|
||||||
|
@ -52,7 +54,6 @@ function snmpBrowse() {
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: (action = ajax_url),
|
url: (action = ajax_url),
|
||||||
async: true,
|
async: true,
|
||||||
timeout: 120000,
|
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
// Hide the spinner
|
// Hide the spinner
|
||||||
$("#spinner").css("display", "none");
|
$("#spinner").css("display", "none");
|
||||||
|
@ -62,6 +63,9 @@ function snmpBrowse() {
|
||||||
|
|
||||||
// Manage click and select events.
|
// Manage click and select events.
|
||||||
snmp_browser_events_manage();
|
snmp_browser_events_manage();
|
||||||
|
},
|
||||||
|
error: function(e) {
|
||||||
|
$("#snmp_browser").html(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -499,6 +503,7 @@ function checkSNMPVersion() {
|
||||||
function snmpBrowserWindow() {
|
function snmpBrowserWindow() {
|
||||||
// Keep elements in the form and the SNMP browser synced
|
// Keep elements in the form and the SNMP browser synced
|
||||||
$("#text-target_ip").val($("#text-ip_target").val());
|
$("#text-target_ip").val($("#text-ip_target").val());
|
||||||
|
$("#target_port").val($("#text-tcp_port").val());
|
||||||
$("#text-community").val($("#text-snmp_community").val());
|
$("#text-community").val($("#text-snmp_community").val());
|
||||||
$("#snmp_browser_version").val($("#snmp_version").val());
|
$("#snmp_browser_version").val($("#snmp_version").val());
|
||||||
$("#text-snmp3_browser_auth_user").val($("#text-snmp3_auth_user").val());
|
$("#text-snmp3_browser_auth_user").val($("#text-snmp3_auth_user").val());
|
||||||
|
@ -525,7 +530,7 @@ function snmpBrowserWindow() {
|
||||||
opacity: 0.5,
|
opacity: 0.5,
|
||||||
background: "black"
|
background: "black"
|
||||||
},
|
},
|
||||||
width: 920,
|
width: 1000,
|
||||||
height: 500
|
height: 500
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue