From 4e5fdd7e0ad0da160084eb0ec889805b857edf60 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Fri, 24 May 2013 09:58:44 +0000 Subject: [PATCH] 2013-05-24 Ramon Novoa * include/functions.php: Merged from 4.0 branch. Removed calls to PHP's SNMP functions. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8205 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 5 +++ pandora_console/include/functions.php | 45 ++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index b6ef0080c0..a8c0fcdecc 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,8 @@ +2013-05-24 Ramon Novoa + + * include/functions.php: Merged from 4.0 branch. Removed calls + to PHP's SNMP functions. + 2013-05-23 Miguel de Dios * include/javascript/pandora_visual_console.js, diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 30ec9a73a4..81d4732cb0 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -1271,29 +1271,58 @@ function get_snmpwalk($ip_target, $snmp_version, $snmp_community = '', $snmp3_au $snmp3_security_level = '', $snmp3_auth_method = '', $snmp3_auth_pass = '', $snmp3_privacy_method = '', $snmp3_privacy_pass = '', $quick_print = 0, $base_oid = "", $snmp_port = '') { - snmp_set_quick_print ($quick_print); + // Note: quick_print is ignored // Fix for snmp port if (!empty($snmp_port)){ $ip_target = $ip_target.':'.$snmp_port; } + // Escape the base OID + if ($base_oid != "") { + $base_oid = escapeshellarg ($base_oid); + } + + if ($config['snmpwalk'] == '') { + switch (PHP_OS) { + case "FreeBSD": + $snmpwalk_bin = '/usr/local/bin/snmpwalk'; + break; + case "NetBSD": + $snmpwalk_bin = '/usr/pkg/bin/snmpwalk'; + break; + default: + $snmpwalk_bin = 'snmpwalk'; + break; + } + } + else { + $snmpwalk_bin = $config['snmpwalk']; + } + $output = array(); + $rc = 0; switch ($snmp_version) { case '3': - $snmpwalk = @snmp3_real_walk ($ip_target, $snmp3_auth_user, - $snmp3_security_level, $snmp3_auth_method, $snmp3_auth_pass, - $snmp3_privacy_method, $snmp3_privacy_pass, $base_oid); + exec ($snmpwalk_bin . ' -m ALL -v 3 -u ' . escapeshellarg($snmp3_auth_user) . ' -A ' . escapeshellarg($snmp3_auth_pass) . ' -l ' . escapeshellarg($snmp3_security_level) . ' -a ' . escapeshellarg($snmp3_auth_method) . ' -x ' . escapeshellarg($snmp3_privacy_method) . ' -X ' . escapeshellarg($snmp3_privacy_pass) . ' ' . escapeshellarg($ip_target) . ' ' . $base_oid . ' 2>/dev/null', $output, $rc); break; case '2': case '2c': - $snmpwalk = @snmp2_real_walk ($ip_target, $snmp_community, $base_oid); - break; case '1': default: - $snmpwalk = @snmprealwalk($ip_target, $snmp_community, $base_oid); + exec ($snmpwalk_bin . ' -m ALL -v ' . escapeshellarg($snmp_version) . ' -c ' . escapeshellarg($snmp_community) . ' ' . escapeshellarg($ip_target) . ' ' . $base_oid . ' 2>/dev/null', $output, $rc); break; } - + + // Parse the output of snmpwalk + foreach ($output as $line) { + + // Separate the OID from the value + $full_oid = explode (' = ', $line); + if (isset ($full_oid[1])) { + $snmpwalk[$full_oid[0]] = $full_oid[1]; + }ge + } + return $snmpwalk; }