2014-07-15 02:59:36 +08:00
|
|
|
<?php
|
|
|
|
//
|
|
|
|
// ZoneMinder web ONVIF probe view file, $Date: 2014-07-05 $, $Revision: 1 $
|
|
|
|
// Copyright (C) Jan M. Hochstein
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 2
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
2016-12-26 23:23:16 +08:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2014-07-15 02:59:36 +08:00
|
|
|
//
|
|
|
|
|
2018-10-24 21:49:56 +08:00
|
|
|
if ( !canEdit('Monitors') ) {
|
2017-07-13 22:26:09 +08:00
|
|
|
$view = 'error';
|
|
|
|
return;
|
2014-07-15 02:59:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$cameras = array();
|
2015-05-10 21:10:30 +08:00
|
|
|
$cameras[0] = translate('ChooseDetectedCamera');
|
2014-07-15 02:59:36 +08:00
|
|
|
|
2016-10-05 02:33:51 +08:00
|
|
|
$profiles = array();
|
|
|
|
$profiles[0] = translate('ChooseDetectedProfile');
|
2014-07-15 02:59:36 +08:00
|
|
|
|
2016-10-04 22:29:37 +08:00
|
|
|
function execONVIF( $cmd ) {
|
|
|
|
$shell_command = escapeshellcmd(ZM_PATH_BIN . "/zmonvif-probe.pl $cmd");
|
|
|
|
|
|
|
|
exec( $shell_command, $output, $status );
|
|
|
|
|
|
|
|
if ( $status ) {
|
|
|
|
$html_output = implode( '<br/>', $output );
|
2019-02-22 22:19:07 +08:00
|
|
|
ZM\Fatal( "Unable to probe network cameras, status is '$status'. Output was:<br/><br/>
|
2016-10-04 22:29:37 +08:00
|
|
|
$html_output<br/><br/>
|
|
|
|
Please the following command from a command line for more information:<br/><br/>$shell_command"
|
|
|
|
);
|
2017-07-13 22:26:09 +08:00
|
|
|
} else {
|
2019-02-22 22:19:07 +08:00
|
|
|
ZM\Logger::Debug( "Results from probe: " . implode( '<br/>', $output ) );
|
2016-10-04 22:29:37 +08:00
|
|
|
}
|
2014-07-15 02:59:36 +08:00
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2017-07-13 22:26:09 +08:00
|
|
|
function probeCameras( $localIp ) {
|
|
|
|
$cameras = array();
|
|
|
|
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];
|
|
|
|
} else {
|
2019-02-22 22:19:07 +08:00
|
|
|
ZM\Logger::Debug('Unknown token ' . $tokens[1]);
|
2014-07-15 02:59:36 +08:00
|
|
|
}
|
2017-07-13 22:26:09 +08:00
|
|
|
}
|
|
|
|
} // end foreach token
|
|
|
|
$cameras[] = $camera;
|
|
|
|
}
|
|
|
|
} // end foreach line
|
2018-10-24 21:49:56 +08:00
|
|
|
} // end if results from execOnvif
|
|
|
|
return $cameras;
|
|
|
|
} // end function probeCameras
|
2014-07-15 02:59:36 +08:00
|
|
|
|
2017-07-13 22:26:09 +08:00
|
|
|
function probeProfiles( $device_ep, $soapversion, $username, $password ) {
|
|
|
|
$profiles = array();
|
2019-06-22 00:42:26 +08:00
|
|
|
if ( $lines = @execONVIF("profiles $device_ep $soapversion $username $password") ) {
|
2017-07-13 22:26:09 +08:00
|
|
|
foreach ( $lines as $line ) {
|
|
|
|
$line = rtrim( $line );
|
2018-10-24 21:49:56 +08:00
|
|
|
if ( preg_match('|^(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+)\s*$|', $line, $matches) ) {
|
2017-07-13 22:26:09 +08:00
|
|
|
$stream_uri = $matches[7];
|
|
|
|
// add user@pass to URI
|
2018-10-24 21:49:56 +08:00
|
|
|
if ( preg_match('|^(\S+://)(.+)$|', $stream_uri, $tokens) ) {
|
2017-07-13 22:26:09 +08:00
|
|
|
$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[] = $profile;
|
|
|
|
} else {
|
2019-02-22 22:19:07 +08:00
|
|
|
ZM\Logger::Debug("Line did not match preg: $line");
|
2017-07-13 22:26:09 +08:00
|
|
|
}
|
2018-10-24 21:49:56 +08:00
|
|
|
} // end foreach line
|
|
|
|
} // end if results from execONVIF
|
|
|
|
return $profiles;
|
|
|
|
} // end function probeProfiles
|
2014-07-15 02:59:36 +08:00
|
|
|
|
|
|
|
//==== STEP 1 ============================================================
|
|
|
|
|
|
|
|
$focusWindow = true;
|
|
|
|
|
2015-05-10 21:10:30 +08:00
|
|
|
xhtmlHeaders(__FILE__, translate('MonitorProbe') );
|
2014-07-15 02:59:36 +08:00
|
|
|
|
2018-10-24 21:49:56 +08:00
|
|
|
if ( !isset($_REQUEST['step']) || ($_REQUEST['step'] == '1') ) {
|
2014-07-15 02:59:36 +08:00
|
|
|
|
|
|
|
$monitors = array();
|
2018-10-24 21:49:56 +08:00
|
|
|
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])."<br/>";
|
|
|
|
$monitors[gethostbyname($matches[2])] = $monitor;
|
|
|
|
} else {
|
|
|
|
//echo "2: ".$monitor['Host']." = ".gethostbyname($monitor['Host'])."<br/>";
|
|
|
|
$monitors[gethostbyname($monitor['Host'])] = $monitor;
|
|
|
|
}
|
2014-07-15 02:59:36 +08:00
|
|
|
}
|
|
|
|
|
2018-10-24 21:49:56 +08:00
|
|
|
$detcameras = probeCameras('');
|
2017-07-13 22:26:09 +08:00
|
|
|
foreach ( $detcameras as $camera ) {
|
|
|
|
if ( preg_match( '|([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)|', $camera['monitor']['Host'], $matches ) ) {
|
2014-07-15 02:59:36 +08:00
|
|
|
$ip = $matches[1];
|
|
|
|
}
|
|
|
|
$host = $ip;
|
|
|
|
/*
|
|
|
|
if ( isset($monitors[$ip]) )
|
|
|
|
{
|
|
|
|
$monitor = $monitors[$ip];
|
|
|
|
$sourceString .= " (".$monitor['Name'].")";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-10 21:10:30 +08:00
|
|
|
$sourceString .= " - ".translate('Available');
|
2014-07-15 02:59:36 +08:00
|
|
|
}
|
|
|
|
$cameras[$sourceDesc] = $sourceString;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
// $sourceDesc = htmlspecialchars(serialize($camera['monitor']));
|
2018-10-24 21:49:56 +08:00
|
|
|
$sourceDesc = base64_encode(json_encode($camera['monitor']));
|
|
|
|
$sourceString = $camera['model'].' @ '.$host . ' using version ' . $camera['monitor']['SOAP'] ;
|
|
|
|
$cameras[$sourceDesc] = $sourceString;
|
2014-07-15 02:59:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( count($cameras) <= 0 )
|
2018-10-24 21:49:56 +08:00
|
|
|
$cameras[0] = translate('NoDetectedCameras');
|
2014-07-15 02:59:36 +08:00
|
|
|
|
|
|
|
?>
|
|
|
|
<body>
|
|
|
|
<div id="page">
|
|
|
|
<div id="header">
|
2015-05-10 21:10:30 +08:00
|
|
|
<h2><?php echo translate('MonitorProbe') ?></h2>
|
2014-07-15 02:59:36 +08:00
|
|
|
</div>
|
|
|
|
<div id="content">
|
2019-02-10 13:39:19 +08:00
|
|
|
<form name="contentForm" id="contentForm" method="post" action="?">
|
2014-07-15 02:59:36 +08:00
|
|
|
<input type="hidden" name="view" value="none"/>
|
2015-04-08 18:13:27 +08:00
|
|
|
<input type="hidden" name="mid" value="<?php echo validNum($_REQUEST['mid']) ?>"/>
|
2014-07-15 02:59:36 +08:00
|
|
|
<input type="hidden" name="step" value=""/>
|
|
|
|
<p>
|
2015-05-10 21:10:30 +08:00
|
|
|
<?php echo translate('OnvifProbeIntro') ?>
|
2014-07-15 02:59:36 +08:00
|
|
|
</p>
|
|
|
|
<p>
|
2018-10-24 21:49:56 +08:00
|
|
|
<label for="probe"><?php echo translate('DetectedCameras') ?></label>
|
|
|
|
<?php echo htmlSelect('probe', $cameras, null, array('onchange'=>'configureButtons(this)')); ?>
|
2014-07-15 02:59:36 +08:00
|
|
|
</p>
|
|
|
|
<p>
|
2015-05-10 21:10:30 +08:00
|
|
|
<?php echo translate('OnvifCredentialsIntro') ?>
|
2014-07-15 02:59:36 +08:00
|
|
|
</p>
|
|
|
|
<p>
|
2015-05-10 21:10:30 +08:00
|
|
|
<label for="username"><?php echo translate('Username') ?></label>
|
2018-10-24 21:49:56 +08:00
|
|
|
<input type="text" name="username" value="" onChange="configureButtons(this)"/>
|
2014-07-15 02:59:36 +08:00
|
|
|
</p>
|
|
|
|
<p>
|
2015-05-10 21:10:30 +08:00
|
|
|
<label for="password"><?php echo translate('Password') ?></label>
|
2019-02-22 22:19:07 +08:00
|
|
|
<input type="password" name="password" value="" onChange="configureButtons(this)"/>
|
2014-07-15 02:59:36 +08:00
|
|
|
</p>
|
|
|
|
<div id="contentButtons">
|
2019-01-16 22:59:58 +08:00
|
|
|
<input type="button" value="<?php echo translate('Cancel') ?>" data-on-click="closeWindow"/>
|
|
|
|
<input type="submit" name="nextBtn" value="<?php echo translate('Next') ?>" data-on-click-this="gotoStep2" disabled="disabled"/>
|
2014-07-15 02:59:36 +08:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
<?php
|
|
|
|
|
|
|
|
//==== STEP 2 ============================================================
|
2018-10-24 21:49:56 +08:00
|
|
|
} else if($_REQUEST['step'] == '2') {
|
2016-10-05 02:09:32 +08:00
|
|
|
if ( empty($_REQUEST['probe']) )
|
2019-02-22 22:19:07 +08:00
|
|
|
ZM\Fatal('No probe passed in request. Please go back and try again.');
|
2016-10-05 02:09:32 +08:00
|
|
|
#|| empty($_REQUEST['username']) ||
|
|
|
|
#empty($_REQUEST['password']) )
|
2014-07-15 02:59:36 +08:00
|
|
|
|
2018-10-24 21:49:56 +08:00
|
|
|
$probe = json_decode(base64_decode($_REQUEST['probe']));
|
2019-02-22 22:19:07 +08:00
|
|
|
ZM\Logger::Debug(print_r($probe,true));
|
2017-07-13 22:26:09 +08:00
|
|
|
foreach ( $probe as $name=>$value ) {
|
2018-10-24 21:49:56 +08:00
|
|
|
if ( isset($value) ) {
|
|
|
|
$monitor[$name] = $value;
|
|
|
|
}
|
2014-07-15 02:59:36 +08:00
|
|
|
}
|
|
|
|
$camera['monitor'] = $monitor;
|
|
|
|
|
|
|
|
//print $monitor['Host'].", ".$_REQUEST['username'].", ".$_REQUEST['password']."<br/>";
|
|
|
|
|
2018-10-24 21:49:56 +08:00
|
|
|
$detprofiles = probeProfiles($monitor['Host'], $monitor['SOAP'], $_REQUEST['username'], $_REQUEST['password']);
|
2017-07-13 22:26:09 +08:00
|
|
|
foreach ( $detprofiles as $profile ) {
|
2018-10-24 21:49:56 +08:00
|
|
|
$monitor = $camera['monitor'];
|
|
|
|
|
|
|
|
$sourceString = "${profile['Name']} : ${profile['Encoding']}" .
|
|
|
|
" (${profile['Width']}x${profile['Height']} @ ${profile['MaxFPS']}fps)";
|
|
|
|
// copy technical details
|
|
|
|
$monitor['Width'] = $profile['Width'];
|
|
|
|
$monitor['Height'] = $profile['Height'];
|
|
|
|
// The maxfps fields do not work for ip streams. Can re-enable if that is fixed.
|
|
|
|
// $monitor['MaxFPS'] = $profile['MaxFPS'];
|
|
|
|
// $monitor['AlarmMaxFPS'] = $profile['AlarmMaxFPS'];
|
|
|
|
$monitor['Path'] = $profile['Path'];
|
2019-06-22 00:42:26 +08:00
|
|
|
$monitor['ControlDevice'] = $profile['Profile']; # Netcat needs this for ProfileToken
|
2018-10-24 21:49:56 +08:00
|
|
|
$sourceDesc = base64_encode(json_encode($monitor));
|
|
|
|
$profiles[$sourceDesc] = $sourceString;
|
2014-07-15 02:59:36 +08:00
|
|
|
}
|
|
|
|
|
2016-10-05 02:33:51 +08:00
|
|
|
if ( count($profiles) <= 0 )
|
2018-10-24 21:49:56 +08:00
|
|
|
$profiles[0] = translate('NoDetectedProfiles');
|
2014-07-15 02:59:36 +08:00
|
|
|
|
|
|
|
?>
|
|
|
|
<body>
|
|
|
|
<div id="page">
|
|
|
|
<div id="header">
|
2015-05-10 21:10:30 +08:00
|
|
|
<h2><?php echo translate('ProfileProbe') ?></h2>
|
2014-07-15 02:59:36 +08:00
|
|
|
</div>
|
|
|
|
<div id="content">
|
2019-02-10 13:39:19 +08:00
|
|
|
<form name="contentForm" id="contentForm" method="post" action="?">
|
2014-07-15 02:59:36 +08:00
|
|
|
<input type="hidden" name="view" value="none"/>
|
2015-04-08 18:13:27 +08:00
|
|
|
<input type="hidden" name="mid" value="<?php echo validNum($_REQUEST['mid']) ?>"/>
|
2018-10-24 21:49:56 +08:00
|
|
|
<input type="hidden" name="step"/>
|
2014-07-15 02:59:36 +08:00
|
|
|
<p>
|
2015-05-10 21:10:30 +08:00
|
|
|
<?php echo translate('ProfileProbeIntro') ?>
|
2014-07-15 02:59:36 +08:00
|
|
|
</p>
|
|
|
|
<p>
|
2018-10-24 21:49:56 +08:00
|
|
|
<label for="probe"><?php echo translate('DetectedProfiles') ?></label>
|
|
|
|
<?php echo htmlSelect('probe', $profiles, null, array('onchange'=>'configureButtons(this)')); ?>
|
2014-07-15 02:59:36 +08:00
|
|
|
</p>
|
|
|
|
<div id="contentButtons">
|
2019-01-16 22:59:58 +08:00
|
|
|
<input type="button" name="prevBtn" value="<?php echo translate('Prev') ?>" data-on-click-this="gotoStep1"/>
|
|
|
|
<input type="button" value="<?php echo translate('Cancel') ?>" data-on-click="closeWindow"/>
|
|
|
|
<input type="submit" name="saveBtn" value="<?php echo translate('Save') ?>" data-on-click-this="submitCamera" disabled="disabled"/>
|
2014-07-15 02:59:36 +08:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
<?php
|
2018-10-24 21:49:56 +08:00
|
|
|
} // end if step 1 or 2
|
2014-07-15 02:59:36 +08:00
|
|
|
?>
|