', $output );
Fatal( "Unable to probe network cameras, status is '$status'. Output was:
$html_output
Please the following command from a command line for more information:
".
ZM_PATH_BIN . "/zmonvif-probe.pl $cmd" );
return $output;
}
function probeCameras( $localIp )
{
$cameras = array();
$count = 0;
if ( $lines = @execONVIF( "probe" ) )
{
foreach ( $lines as $line )
{
$line = rtrim( $line );
if ( preg_match( '|^(.+),(.+),\s\((.*)\)$|', $line, $matches ) )
{
$device_ep = $matches[1];
$soapversion = $matches[2];
$camera = array(
'model' => "Unknown ONVIF Camera",
'monitor' => array(
'Function' => "Monitor",
'Type' => 'Ffmpeg',
'Host' => $device_ep,
'SOAP' => $soapversion,
),
);
foreach ( preg_split('|,\s*|', $matches[3]) as $attr_val ) {
if( preg_match( '|(.+)=\'(.*)\'|', $attr_val, $tokens ) )
{
if($tokens[1] == "hardware") {
$camera['model'] = $tokens[2];
}
elseif($tokens[1] == "name") {
$camera['monitor']['Name'] = $tokens[2];
}
elseif($tokens[1] == "location") {
// $camera['location'] = $tokens[2];
}
}
}
$cameras[$count ++] = $camera;
}
}
}
return( $cameras );
}
function probeProfiles( $device_ep, $soapversion, $username, $password )
{
$profiles = array();
$count = 0;
if ( $lines = @execONVIF( "profiles $device_ep $soapversion $username $password" ) )
{
foreach ( $lines as $line )
{
$line = rtrim( $line );
if ( preg_match( '|^(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+)\s*$|', $line, $matches ) )
{
$stream_uri = $matches[7];
// add user@pass to URI
if( preg_match( '|^(\S+://)(.+)$|', $stream_uri, $tokens ) )
{
$stream_uri = $tokens[1].$username.':'.$password.'@'.$tokens[2];
}
$profile = array( # 'monitor' part of camera
'Type' => 'Ffmpeg',
'Width' => $matches[4],
'Height' => $matches[5],
'MaxFPS' => $matches[6],
'Path' => $stream_uri,
// local-only:
'Profile' => $matches[1],
'Name' => $matches[2],
'Encoding' => $matches[3],
);
$profiles[$count ++] = $profile;
}
}
}
return( $profiles );
}
//==== STEP 1 ============================================================
$focusWindow = true;
xhtmlHeaders(__FILE__, translate('MonitorProbe') );
if( !isset($_REQUEST['step']) || ($_REQUEST['step'] == "1")) {
$monitors = array();
foreach ( dbFetchAll( "select Id, Name, Host from Monitors where Type = 'Remote' order by Host" ) as $monitor )
{
if ( preg_match( '/^(.+)@(.+)$/', $monitor['Host'], $matches ) )
{
//echo "1: ".$matches[2]." = ".gethostbyname($matches[2])."
";
$monitors[gethostbyname($matches[2])] = $monitor;
}
else
{
//echo "2: ".$monitor['Host']." = ".gethostbyname($monitor['Host'])."
";
$monitors[gethostbyname($monitor['Host'])] = $monitor;
}
}
$detcameras = probeCameras( '' );
foreach ( $detcameras as $camera )
{
if ( preg_match( '|([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)|', $camera['monitor']['Host'], $matches ) )
{
$ip = $matches[1];
}
$host = $ip;
/*
if ( isset($monitors[$ip]) )
{
$monitor = $monitors[$ip];
$sourceString .= " (".$monitor['Name'].")";
}
else
{
$sourceString .= " - ".translate('Available');
}
$cameras[$sourceDesc] = $sourceString;
}
*/
// $sourceDesc = htmlspecialchars(serialize($camera['monitor']));
$sourceDesc = base64_encode(serialize($camera['monitor']));
$sourceString = $camera['model'].' @ '.$host;
$cameras[$sourceDesc] = $sourceString;
}
if ( count($cameras) <= 0 )
$cameras[0] = translate('NoDetectedCameras');
?>