2012-06-21 Hirofumi Kosaka <kosaka@rworks.jp>

* extensions/net_tools.php: Use 'whereis' to get command path
	to execute, regardless $PATH environment.
	Merged from 4.0.2


git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6642 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
hkosaka 2012-06-21 09:04:59 +00:00
parent 0a2c98835b
commit 4f782d0b7a
2 changed files with 72 additions and 70 deletions

View File

@ -1,3 +1,9 @@
2012-06-21 Hirofumi Kosaka <kosaka@rworks.jp>
* 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 <juanmanuel.ramon@artica.es> 2012-06-20 Juan Manuel Ramon <juanmanuel.ramon@artica.es>
* include/styles/pandora_black.css: Autocomplete text is visible in * include/styles/pandora_black.css: Autocomplete text is visible in

View File

@ -16,6 +16,27 @@
extensions_add_opemode_tab_agent ('network_tools','Network Tools','extensions/net_tools/nettool.png',"main_net_tools"); 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 () { function main_net_tools () {
@ -53,70 +74,50 @@ function main_net_tools () {
switch($operation) { switch($operation) {
case 1: case 1:
ob_start(); $traceroute = whereis_the_command ('traceroute');
system('which traceroute'); if (empty($traceroute)) {
$output = ob_get_clean();
$result = explode(':', $output);
$result = trim($result[1]);
if (! empty($result)) {
echo "<h3>".__("Traceroute to "). $ip. "</h3>";
echo "<pre>";
echo system ("traceroute $ip");
echo "</pre>";
}
elseif (file_exists('/usr/sbin/traceroute')) {
echo "<h3>".__("Traceroute to "). $ip. "</h3>";
echo "<pre>";
echo system ("/usr/sbin/traceroute $ip");
echo "</pre>";
}
else {
ui_print_error_message(__('Traceroute executable does not exist.')); ui_print_error_message(__('Traceroute executable does not exist.'));
} }
else {
echo "<h3>".__("Traceroute to "). $ip. "</h3>";
echo "<pre>";
echo system ("$traceroute $ip");
echo "</pre>";
}
break; break;
case 2: case 2:
ob_start(); $ping = whereis_the_command ('ping');
system('which ping'); if (empty($ping)) {
$output = ob_get_clean();
$result = explode(':', $output);
$result = trim($result[1]);
if (empty($result)) {
ui_print_error_message(__('Ping executable does not exist.')); ui_print_error_message(__('Ping executable does not exist.'));
} }
else { else {
echo "<h3>".__("Ping to "). $ip. "</h3>"; echo "<h3>".__("Ping to "). $ip. "</h3>";
echo "<pre>"; echo "<pre>";
echo system ("ping -c 5 $ip"); echo system ("$ping -c 5 $ip");
echo "</pre>"; echo "</pre>";
} }
break; break;
case 4: case 4:
ob_start(); $nmap = whereis_the_command ('nmap');
system('which nmap'); if (empty($nmap)) {
$output = ob_get_clean();
$result = explode(':', $output);
$result = trim($result[1]);
if (empty($result)) {
ui_print_error_message(__('Nmap executable does not exist.')); ui_print_error_message(__('Nmap executable does not exist.'));
} }
else { else {
echo "<h3>".__("Basic TCP Scan on "). $ip. "</h3>"; echo "<h3>".__("Basic TCP Scan on "). $ip. "</h3>";
echo "<pre>"; echo "<pre>";
echo system ("nmap -F $ip"); echo system ("$nmap -F $ip");
echo "</pre>"; echo "</pre>";
} }
break; break;
case 5: case 5:
echo "<h3>".__("Domain and IP information for "). $ip. "</h3>"; echo "<h3>".__("Domain and IP information for "). $ip. "</h3>";
ob_start();
system('which dig'); $dig = whereis_the_command ('dig');
$output = ob_get_clean(); if (empty($dig)) {
$result = explode(':', $output);
$result = trim($result[1]);
if (empty($result)) {
ui_print_error_message(__('Dig executable does not exist.')); ui_print_error_message(__('Dig executable does not exist.'));
} }
else { else {
@ -124,39 +125,34 @@ function main_net_tools () {
echo system ("dig $ip"); echo system ("dig $ip");
echo "</pre>"; echo "</pre>";
} }
ob_start();
system('which whois'); $whois = whereis_the_command ('whois');
$output = ob_get_clean(); if (empty($whois)) {
$result = explode(':', $output);
$result = trim($result[1]);
if (empty($result)) {
ui_print_error_message(__('Whois executable does not exist.')); ui_print_error_message(__('Whois executable does not exist.'));
} }
else { else {
echo "<pre>"; echo "<pre>";
echo system ("whois $ip"); echo system ("whois $ip");
echo "</pre>"; echo "</pre>";
} }
break; break;
case 3: echo "<h3>".__("SNMP information for "). $ip. "</h3>";
ob_start(); case 3:
system('which snmpget'); echo "<h3>".__("SNMP information for "). $ip. "</h3>";
$output = ob_get_clean();
$result = explode(':', $output); $snmpget = whereis_the_command ('snmpget');
$result = trim($result[1]); if (empty($snmpget)) {
if (empty($result)) {
ui_print_error_message(__('SNMPget executable does not exist.')); ui_print_error_message(__('SNMPget executable does not exist.'));
} }
else { else {
echo "<h4>Uptime</h4>"; echo "<h4>Uptime</h4>";
echo "<pre>"; echo "<pre>";
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 "</pre>"; echo "</pre>";
echo "<h4>Device info</h4>"; echo "<h4>Device info</h4>";
echo "<pre>"; echo "<pre>";
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 "</pre>"; echo "</pre>";
echo "<h4>Interface Information</h4>"; echo "<h4>Interface Information</h4>";
@ -164,11 +160,11 @@ function main_net_tools () {
echo "<tr><th>".__("Interface"); echo "<tr><th>".__("Interface");
echo "<th>".__("Status"); echo "<th>".__("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++){ 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 "); $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 "); $estado = exec ("$snmpget -Oqunv -v1 -c $community $ip .1.3.6.1.2.1.2.2.1.8.$ax ");
echo "<tr><td>$interface<td>$estado"; echo "<tr><td>$interface<td>$estado";
} }
echo "</table>"; echo "</table>";