diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index cb0cc8850a..7bc0911f36 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,9 @@ +2012-06-21 Hirofumi Kosaka + + * extensions/net_tools.php: Use 'whereis' to get command path + to execute, regardless $PATH environment. + Merged from 4.0.2 + 2012-06-20 Juan Manuel Ramon * include/styles/pandora_black.css: Autocomplete text is visible in diff --git a/pandora_console/extensions/net_tools.php b/pandora_console/extensions/net_tools.php index 523ac4cdc2..27ad50f92a 100644 --- a/pandora_console/extensions/net_tools.php +++ b/pandora_console/extensions/net_tools.php @@ -16,6 +16,27 @@ extensions_add_opemode_tab_agent ('network_tools','Network Tools','extensions/net_tools/nettool.png',"main_net_tools"); +function whereis_the_command ($command) { + + ob_start(); + system('whereis '. $command); + $output = ob_get_clean(); + $result = explode(':', $output); + $result = trim($result[1]); + + if ( empty($result)) { + return NULL; + } + + $result = explode(' ', $result); + $fullpath = trim($result[0]); + + if (! file_exists($fullpath)) { + return NULL; + } + + return $fullpath; +} function main_net_tools () { @@ -46,117 +67,92 @@ function main_net_tools () { echo ""; echo ""; echo ""; - - + + $operation = get_parameter ("operation",0); $community = get_parameter ("community","public"); - + switch($operation) { case 1: - ob_start(); - system('which traceroute'); - $output = ob_get_clean(); - $result = explode(':', $output); - $result = trim($result[1]); - if (! empty($result)) { - echo "

".__("Traceroute to "). $ip. "

"; - echo "
";
-                                echo system ("traceroute $ip");
-                                echo "
"; - } - elseif (file_exists('/usr/sbin/traceroute')) { - echo "

".__("Traceroute to "). $ip. "

"; - echo "
";
-                                echo system ("/usr/sbin/traceroute $ip");
-                                echo "
"; - } - else { - ui_print_error_message(__('Traceroute executable does not exist.')); - } + $traceroute = whereis_the_command ('traceroute'); + if (empty($traceroute)) { + ui_print_error_message(__('Traceroute executable does not exist.')); + } + else { + echo "

".__("Traceroute to "). $ip. "

"; + echo "
";
+				echo system ("$traceroute $ip");
+				echo "
"; + } + break; - case 2: - ob_start(); - system('which ping'); - $output = ob_get_clean(); - $result = explode(':', $output); - $result = trim($result[1]); - if (empty($result)) { + case 2: + $ping = whereis_the_command ('ping'); + if (empty($ping)) { ui_print_error_message(__('Ping executable does not exist.')); } else { echo "

".__("Ping to "). $ip. "

"; - echo "
";
-	                echo system ("ping -c 5 $ip");
-	                echo "
"; + echo "
";
+				echo system ("$ping -c 5 $ip");
+				echo "
"; } break; case 4: - ob_start(); - system('which nmap'); - $output = ob_get_clean(); - $result = explode(':', $output); - $result = trim($result[1]); - if (empty($result)) { + $nmap = whereis_the_command ('nmap'); + if (empty($nmap)) { ui_print_error_message(__('Nmap executable does not exist.')); } else { echo "

".__("Basic TCP Scan on "). $ip. "

"; echo "
";
-                	echo system ("nmap -F $ip");
+                	echo system ("$nmap -F $ip");
                 	echo "
"; } break; - + case 5: echo "

".__("Domain and IP information for "). $ip. "

"; - ob_start(); - system('which dig'); - $output = ob_get_clean(); - $result = explode(':', $output); - $result = trim($result[1]); - if (empty($result)) { + + $dig = whereis_the_command ('dig'); + if (empty($dig)) { ui_print_error_message(__('Dig executable does not exist.')); } else { echo "
";
-                	echo system ("dig $ip");
-                	echo "
"; + echo system ("dig $ip"); + echo ""; } - ob_start(); - system('which whois'); - $output = ob_get_clean(); - $result = explode(':', $output); - $result = trim($result[1]); - if (empty($result)) { + + $whois = whereis_the_command ('whois'); + if (empty($whois)) { ui_print_error_message(__('Whois executable does not exist.')); } else { echo "
";
-                	echo system ("whois $ip");
-                	echo "
"; - + echo system ("whois $ip"); + echo ""; } break; - case 3: echo "

".__("SNMP information for "). $ip. "

"; - ob_start(); - system('which snmpget'); - $output = ob_get_clean(); - $result = explode(':', $output); - $result = trim($result[1]); - if (empty($result)) { + + case 3: + echo "

".__("SNMP information for "). $ip. "

"; + + $snmpget = whereis_the_command ('snmpget'); + if (empty($snmpget)) { ui_print_error_message(__('SNMPget executable does not exist.')); } else { echo "

Uptime

"; echo "
";
-                	echo exec ("snmpget -Ounv -v1 -c $community $ip .1.3.6.1.2.1.1.3.0 ");
+                	echo exec ("$snmpget -Ounv -v1 -c $community $ip .1.3.6.1.2.1.1.3.0 ");
                 	echo "
"; echo "

Device info

"; echo "
";
 	
-	                echo system ("snmpget -Ounv -v1 -c $community $ip .1.3.6.1.2.1.1.1.0 ");
+	                echo system ("$snmpget -Ounv -v1 -c $community $ip .1.3.6.1.2.1.1.1.0 ");
 	                echo "
"; echo "

Interface Information

"; @@ -164,11 +160,11 @@ function main_net_tools () { echo "".__("Interface"); echo "".__("Status"); - $int_max = exec ("snmpget -Oqunv -v1 -c $community $ip .1.3.6.1.2.1.2.1.0 "); + $int_max = exec ("$snmpget -Oqunv -v1 -c $community $ip .1.3.6.1.2.1.2.1.0 "); for ($ax=0; $ax < $int_max; $ax++){ - $interface = exec ("snmpget -Oqunv -v1 -c $community $ip .1.3.6.1.2.1.2.2.1.2.$ax "); - $estado = exec ("snmpget -Oqunv -v1 -c $community $ip .1.3.6.1.2.1.2.2.1.8.$ax "); + $interface = exec ("$snmpget -Oqunv -v1 -c $community $ip .1.3.6.1.2.1.2.2.1.2.$ax "); + $estado = exec ("$snmpget -Oqunv -v1 -c $community $ip .1.3.6.1.2.1.2.2.1.8.$ax "); echo "$interface$estado"; } echo "";