From 7ef503ff591a5fd15e23552dc83bc1cbcb51bcce Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Sat, 21 Feb 2015 13:08:04 -0600 Subject: [PATCH] User configurable arp tool --- .../lib/ZoneMinder/ConfigData.pm.in | 8 +++ web/skins/classic/views/monitorprobe.php | 49 ++++++++++--------- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in index 15c9e287f..46da03bf0 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in +++ b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in @@ -654,6 +654,14 @@ our @options = type => $types{abs_path}, category => "paths", }, + { + name => "ZM_PATH_ARP", + default => "", + description => "Path to a supported ARP tool", + help => "The camera probe function uses Address Resolution Protocol in order to find known devices on the network. Optionally supply the full path to \"ip neigh\", \"arp -a\", or any other tool on your system that returns ip/mac address pairs. If this field is left empty, ZoneMinder will search for the command \"arp\" and attempt to use that.", + type => $types{abs_path}, + category => "paths", + }, { name => "ZM_WEB_TITLE_PREFIX", default => "ZM", diff --git a/web/skins/classic/views/monitorprobe.php b/web/skins/classic/views/monitorprobe.php index f8e985543..8ae592440 100644 --- a/web/skins/classic/views/monitorprobe.php +++ b/web/skins/classic/views/monitorprobe.php @@ -290,37 +290,42 @@ unset($output); // Calling arp without the full path was reported to fail on some systems // Use the builtin unix command "type" to tell us where the command is $arp_command = ''; -$result = exec( 'type -p arp', $output, $status ); -if ( $status ) { - Warning( "Unable to determine path for arp command, type -p arp returned '$status' output is: " . implode( "\n", $output ) ); - unset($output); - $result = exec( 'which arp', $output, $status ); - if ( $status ) { - Warning( "Unable to determine path for arp command, which arp returned '$status'" ); - if ( file_exists( '/usr/sbin/arp' ) ) { - $arp_command = '/usr/sbin/arp'; - } - } else { - $arp_command = $output[0]; - } +$result = explode( " ", ZM_PATH_ARP ); +if ( !is_executable( $result[0] ) ) { + if ( ZM_PATH_ARP ) { + Warning( "User assigned ARP tool not found. Verify ZM_PATH_ARP points to a valid arp tool and is executable by the web user account." ); + } + $result = exec( 'type -p arp', $output, $status ); + if ( $status ) { + Warning( "Unable to determine path for arp command, type -p arp returned '$status' output is: " . implode( "\n", $output ) ); + unset($output); + $result = exec( 'which arp', $output, $status ); + if ( $status ) { + Warning( "Unable to determine path for arp command, which arp returned '$status'" ); + if ( file_exists( '/usr/sbin/arp' ) ) { + $arp_command = '/usr/sbin/arp -a'; + } + } else { + $arp_command = $output[0]." -a"; + } + } else { + $arp_command = $output[0]." -a"; + } } else { - $arp_command = $output[0]; + $arp_command = ZM_PATH_ARP; } // Now that we know where arp is, call it using the full path -$command = $arp_command." -a"; unset($output); -$result = exec( escapeshellcmd($command), $output, $status ); +$result = exec( escapeshellcmd($arp_command), $output, $status ); if ( $status ) Fatal( "Unable to probe network cameras, status is '$status'" ); foreach ( $output as $line ) { - if ( !preg_match( '/^(\S+) \(([\d.]+)\) at ([0-9a-f:]+)/', $line, $matches ) ) + if ( !preg_match( '/^.*([\d.]+).*([0-9a-f:]+).*/', $line, $matches ) ) continue; - $host = $matches[1]; - $ip = $matches[2]; - if ( !$host || $host == '?' ) - $host = $ip; - $mac = $matches[3]; + $ip = $matches[1]; + $host = $ip; + $mac = $matches[2]; //echo "I:$ip, H:$host, M:$mac
"; $macRoot = substr($mac,0,8); if ( isset($macBases[$macRoot]) )