Merge branch 'storageareas' of github.com:connortechnology/ZoneMinder into storageareas

pull/2077/head
Isaac Connor 2017-10-04 21:51:38 -04:00
commit 91c2e07e64
6 changed files with 139 additions and 141 deletions

View File

@ -348,7 +348,12 @@ Debug("Checking for files for event $_[0]{Id} at $path using glob $path/* found
sub age { sub age {
if ( ! $_[0]{age} ) { if ( ! $_[0]{age} ) {
$_[0]{age} = (time() - ($^T - ((-M $_[0]->Path() ) * 24*60*60))); if ( -e $_[0]->Path() ) {
# $^T is the time the program began running. -M is program start time - file modification time in days
$_[0]{age} = (time() - ($^T - ((-M $_[0]->Path() ) * 24*60*60)));
} else {
Warning($_[0]->Path() . ' does not appear to exist.');
}
} }
return $_[0]{age}; return $_[0]{age};
} }

View File

@ -3,46 +3,42 @@
define( "MSG_TIMEOUT", ZM_WEB_AJAX_TIMEOUT ); define( "MSG_TIMEOUT", ZM_WEB_AJAX_TIMEOUT );
define( "MSG_DATA_SIZE", 4+256 ); define( "MSG_DATA_SIZE", 4+256 );
if ( !($_REQUEST['connkey'] && $_REQUEST['command']) ) if ( !($_REQUEST['connkey'] && $_REQUEST['command']) ) {
{ ajaxError( "Unexpected received message type '$type'" );
ajaxError( "Unexpected received message type '$type'" );
} }
if ( !($socket = @socket_create( AF_UNIX, SOCK_DGRAM, 0 )) ) if ( !($socket = @socket_create( AF_UNIX, SOCK_DGRAM, 0 )) ) {
{ ajaxError( "socket_create() failed: ".socket_strerror(socket_last_error()) );
ajaxError( "socket_create() failed: ".socket_strerror(socket_last_error()) );
} }
$locSockFile = ZM_PATH_SOCKS.'/zms-'.sprintf("%06d",$_REQUEST['connkey']).'w.sock'; $locSockFile = ZM_PATH_SOCKS.'/zms-'.sprintf("%06d",$_REQUEST['connkey']).'w.sock';
if ( !@socket_bind( $socket, $locSockFile ) ) if ( !@socket_bind( $socket, $locSockFile ) ) {
{ ajaxError( "socket_bind( $locSockFile ) failed: ".socket_strerror(socket_last_error()) );
ajaxError( "socket_bind( $locSockFile ) failed: ".socket_strerror(socket_last_error()) );
} }
switch ( $_REQUEST['command'] ) switch ( $_REQUEST['command'] ) {
{ case CMD_VARPLAY :
case CMD_VARPLAY : Logger::Debug( "Varplaying to ".$_REQUEST['rate'] );
Logger::Debug( "Varplaying to ".$_REQUEST['rate'] ); $msg = pack( "lcn", MSG_CMD, $_REQUEST['command'], $_REQUEST['rate']+32768 );
$msg = pack( "lcn", MSG_CMD, $_REQUEST['command'], $_REQUEST['rate']+32768 ); break;
break; case CMD_ZOOMIN :
case CMD_ZOOMIN : Logger::Debug( "Zooming to ".$_REQUEST['x'].",".$_REQUEST['y'] );
Logger::Debug( "Zooming to ".$_REQUEST['x'].",".$_REQUEST['y'] ); $msg = pack( "lcnn", MSG_CMD, $_REQUEST['command'], $_REQUEST['x'], $_REQUEST['y'] );
$msg = pack( "lcnn", MSG_CMD, $_REQUEST['command'], $_REQUEST['x'], $_REQUEST['y'] ); break;
break; case CMD_PAN :
case CMD_PAN : Logger::Debug( "Panning to ".$_REQUEST['x'].",".$_REQUEST['y'] );
Logger::Debug( "Panning to ".$_REQUEST['x'].",".$_REQUEST['y'] ); $msg = pack( "lcnn", MSG_CMD, $_REQUEST['command'], $_REQUEST['x'], $_REQUEST['y'] );
$msg = pack( "lcnn", MSG_CMD, $_REQUEST['command'], $_REQUEST['x'], $_REQUEST['y'] ); break;
break; case CMD_SCALE :
case CMD_SCALE : Logger::Debug( "Scaling to ".$_REQUEST['scale'] );
Logger::Debug( "Scaling to ".$_REQUEST['scale'] ); $msg = pack( "lcn", MSG_CMD, $_REQUEST['command'], $_REQUEST['scale'] );
$msg = pack( "lcn", MSG_CMD, $_REQUEST['command'], $_REQUEST['scale'] ); break;
break; case CMD_SEEK :
case CMD_SEEK : Logger::Debug( "Seeking to ".$_REQUEST['offset'] );
Logger::Debug( "Seeking to ".$_REQUEST['offset'] ); $msg = pack( "lcN", MSG_CMD, $_REQUEST['command'], $_REQUEST['offset'] );
$msg = pack( "lcN", MSG_CMD, $_REQUEST['command'], $_REQUEST['offset'] ); break;
break; default :
default : $msg = pack( "lc", MSG_CMD, $_REQUEST['command'] );
$msg = pack( "lc", MSG_CMD, $_REQUEST['command'] ); break;
break;
} }
$remSockFile = ZM_PATH_SOCKS.'/zms-'.sprintf("%06d",$_REQUEST['connkey']).'s.sock'; $remSockFile = ZM_PATH_SOCKS.'/zms-'.sprintf("%06d",$_REQUEST['connkey']).'s.sock';
@ -64,98 +60,88 @@ $wSockets = NULL;
$eSockets = NULL; $eSockets = NULL;
$numSockets = @socket_select( $rSockets, $wSockets, $eSockets, intval(MSG_TIMEOUT/1000), (MSG_TIMEOUT%1000)*1000 ); $numSockets = @socket_select( $rSockets, $wSockets, $eSockets, intval(MSG_TIMEOUT/1000), (MSG_TIMEOUT%1000)*1000 );
if ( $numSockets === false ) if ( $numSockets === false ) {
{ ajaxError( "socket_select failed: ".socket_strerror(socket_last_error()) );
ajaxError( "socket_select failed: ".socket_strerror(socket_last_error()) ); } else if ( $numSockets < 0 ) {
} ajaxError( "Socket closed $remSockFile" );
else if ( $numSockets < 0 ) } else if ( $numSockets == 0 ) {
{ ajaxError( "Timed out waiting for msg $remSockFile" );
ajaxError( "Socket closed $remSockFile" ); } else if ( $numSockets > 0 ) {
} if ( count($rSockets) != 1 )
else if ( $numSockets == 0 ) ajaxError( "Bogus return from select, ".count($rSockets)." sockets available" );
{
ajaxError( "Timed out waiting for msg $remSockFile" );
}
else if ( $numSockets > 0 )
{
if ( count($rSockets) != 1 )
ajaxError( "Bogus return from select, ".count($rSockets)." sockets available" );
} }
switch( $nbytes = @socket_recvfrom( $socket, $msg, MSG_DATA_SIZE, 0, $remSockFile ) ) switch( $nbytes = @socket_recvfrom( $socket, $msg, MSG_DATA_SIZE, 0, $remSockFile ) ) {
{ case -1 :
case -1 : {
{ ajaxError( "socket_recvfrom( $remSockFile ) failed: ".socket_strerror(socket_last_error()) );
ajaxError( "socket_recvfrom( $remSockFile ) failed: ".socket_strerror(socket_last_error()) ); break;
break; }
} case 0 :
case 0 : {
{ ajaxError( "No data to read from socket" );
ajaxError( "No data to read from socket" ); break;
break; }
} default :
default : {
{ if ( $nbytes != MSG_DATA_SIZE )
if ( $nbytes != MSG_DATA_SIZE ) ajaxError( "Got unexpected message size, got $nbytes, expected ".MSG_DATA_SIZE );
ajaxError( "Got unexpected message size, got $nbytes, expected ".MSG_DATA_SIZE ); break;
break; }
}
} }
$data = unpack( "ltype", $msg ); $data = unpack( "ltype", $msg );
switch ( $data['type'] ) switch ( $data['type'] ) {
{ case MSG_DATA_WATCH :
case MSG_DATA_WATCH : {
{ $data = unpack( "ltype/imonitor/istate/dfps/ilevel/irate/ddelay/izoom/Cdelayed/Cpaused/Cenabled/Cforced", $msg );
$data = unpack( "ltype/imonitor/istate/dfps/ilevel/irate/ddelay/izoom/Cdelayed/Cpaused/Cenabled/Cforced", $msg ); $data['fps'] = round( $data['fps'], 2 );
$data['fps'] = round( $data['fps'], 2 ); $data['rate'] /= RATE_BASE;
$data['rate'] /= RATE_BASE; $data['delay'] = round( $data['delay'], 2 );
$data['delay'] = round( $data['delay'], 2 ); $data['zoom'] = round( $data['zoom']/SCALE_BASE, 1 );
$data['zoom'] = round( $data['zoom']/SCALE_BASE, 1 ); if ( ZM_OPT_USE_AUTH && ZM_AUTH_RELAY == "hashed" ) {
if ( ZM_OPT_USE_AUTH && ZM_AUTH_RELAY == "hashed" ) { session_start();
session_start(); $time = time();
$time = time(); // Regenerate auth hash after half the lifetime of the hash
// Regenerate auth hash after half the lifetime of the hash if ( (!isset($_SESSION['AuthHashGeneratedAt'])) or ( $_SESSION['AuthHashGeneratedAt'] < $time - (ZM_AUTH_HASH_TTL * 1800) ) ) {
if ( (!isset($_SESSION['AuthHashGeneratedAt'])) or ( $_SESSION['AuthHashGeneratedAt'] < $time - (ZM_AUTH_HASH_TTL * 1800) ) ) { $data['auth'] = generateAuthHash( ZM_AUTH_HASH_IPS );
$data['auth'] = generateAuthHash( ZM_AUTH_HASH_IPS ); }
} session_write_close();
session_write_close();
}
ajaxResponse( array( 'status'=>$data ) );
break;
} }
case MSG_DATA_EVENT : ajaxResponse( array( 'status'=>$data ) );
{ break;
$data = unpack( "ltype/ievent/iprogress/irate/izoom/Cpaused", $msg ); }
//$data['progress'] = sprintf( "%.2f", $data['progress'] ); case MSG_DATA_EVENT :
$data['rate'] /= RATE_BASE; {
$data['zoom'] = round( $data['zoom']/SCALE_BASE, 1 ); $data = unpack( "ltype/ievent/iprogress/irate/izoom/Cpaused", $msg );
if ( ZM_OPT_USE_AUTH && ZM_AUTH_RELAY == "hashed" ) { //$data['progress'] = sprintf( "%.2f", $data['progress'] );
session_start(); $data['rate'] /= RATE_BASE;
$time = time(); $data['zoom'] = round( $data['zoom']/SCALE_BASE, 1 );
// Regenerate auth hash after half the lifetime of the hash if ( ZM_OPT_USE_AUTH && ZM_AUTH_RELAY == "hashed" ) {
if ( (!isset($_SESSION['AuthHashGeneratedAt'])) or ( $_SESSION['AuthHashGeneratedAt'] < $time - (ZM_AUTH_HASH_TTL * 1800) ) ) { session_start();
$data['auth'] = generateAuthHash( ZM_AUTH_HASH_IPS ); $time = time();
} // Regenerate auth hash after half the lifetime of the hash
session_write_close(); if ( (!isset($_SESSION['AuthHashGeneratedAt'])) or ( $_SESSION['AuthHashGeneratedAt'] < $time - (ZM_AUTH_HASH_TTL * 1800) ) ) {
} $data['auth'] = generateAuthHash( ZM_AUTH_HASH_IPS );
ajaxResponse( array( 'status'=>$data ) ); }
break; session_write_close();
}
default :
{
ajaxError( "Unexpected received message type '$type'" );
} }
ajaxResponse( array( 'status'=>$data ) );
break;
}
default :
{
ajaxError( "Unexpected received message type '$type'" );
}
} }
ajaxError( 'Unrecognised action or insufficient permissions' ); ajaxError( 'Unrecognised action or insufficient permissions' );
function ajaxCleanup() function ajaxCleanup() {
{ global $socket, $locSockFile;
global $socket, $locSockFile; if ( !empty( $socket ) )
if ( !empty( $socket ) ) @socket_close( $socket );
@socket_close( $socket ); if ( !empty( $locSockFile ) )
if ( !empty( $locSockFile ) ) @unlink( $locSockFile );
@unlink( $locSockFile );
} }
?> ?>

View File

@ -496,16 +496,20 @@ function getStreamCmdResponse( respObj, respText ) {
} }
} else { } else {
checkStreamForErrors("getStreamCmdResponse", respObj);//log them checkStreamForErrors("getStreamCmdResponse", respObj);//log them
// Try to reload the image stream. if ( ! streamPause ) {
var streamImg = document.getElementById('liveStream'); // Try to reload the image stream.
if ( streamImg ) var streamImg = $('liveStream'+monitorId);
streamImg.src = streamImg.src.replace(/rand=\d+/i, 'rand='+Math.floor((Math.random() * 1000000) )); if ( streamImg )
streamImg.src = streamImg.src.replace(/rand=\d+/i, 'rand='+Math.floor((Math.random() * 1000000) ));
}
} }
var streamCmdTimeout = statusRefreshTimeout; if ( ! streamPause ) {
if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT ) var streamCmdTimeout = statusRefreshTimeout;
streamCmdTimeout = streamCmdTimeout/5; if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT )
streamCmdTimer = streamCmdQuery.delay( streamCmdTimeout ); streamCmdTimeout = streamCmdTimeout/5;
streamCmdTimer = streamCmdQuery.delay( streamCmdTimeout );
}
} }
var streamPause = false; var streamPause = false;
@ -556,10 +560,12 @@ function getStatusCmdResponse( respObj, respText ) {
} else } else
checkStreamForErrors("getStatusCmdResponse", respObj); checkStreamForErrors("getStatusCmdResponse", respObj);
var statusCmdTimeout = statusRefreshTimeout; if ( ! streamPause ) {
if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT ) var statusCmdTimeout = statusRefreshTimeout;
statusCmdTimeout = statusCmdTimeout/5; if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT )
statusCmdTimer = statusCmdQuery.delay( statusCmdTimeout ); statusCmdTimeout = statusCmdTimeout/5;
statusCmdTimer = statusCmdQuery.delay( statusCmdTimeout );
}
} }
function statusCmdQuery() { function statusCmdQuery() {

View File

@ -2,7 +2,7 @@ var streamCmdParms = "view=request&request=stream&connkey="+connKey;
var streamCmdReq = new Request.JSON( { url: monitorUrl+thisUrl, method: 'post', timeout: AJAX_TIMEOUT, link: 'cancel' } ); var streamCmdReq = new Request.JSON( { url: monitorUrl+thisUrl, method: 'post', timeout: AJAX_TIMEOUT, link: 'cancel' } );
function streamCmdQuit( action ) { function streamCmdQuit( action ) {
if ( action ) if ( action )
streamCmdReq.send( streamCmdParms+"&command="+CMD_QUIT ); streamCmdReq.send( streamCmdParms+"&command="+CMD_QUIT );
} }

View File

@ -283,7 +283,9 @@ for ( $i = 0; $i < $pointCols; $i++ )
</tr> </tr>
</tbody> </tbody>
</table> </table>
<input id="pauseBtn" type="button" value="<?php echo translate('Pause') ?>" onclick="streamCmdPauseToggle()"/><input type="submit" id="submitBtn" name="submitBtn" value="<?php echo translate('Save') ?>" onclick="return saveChanges( this )"<?php if (!canEdit( 'Monitors' ) || (false && $selfIntersecting)) { ?> disabled="disabled"<?php } ?>/><input type="button" value="<?php echo translate('Cancel') ?>" onclick="refreshParentWindow(); closeWindow();"/> <input id="pauseBtn" type="button" value="<?php echo translate('Pause') ?>" onclick="streamCmdPauseToggle()"/>
<input type="submit" id="submitBtn" name="submitBtn" value="<?php echo translate('Save') ?>" onclick="return saveChanges( this )"<?php if (!canEdit( 'Monitors' ) || (false && $selfIntersecting)) { ?> disabled="disabled"<?php } ?>/>
<input type="button" value="<?php echo translate('Cancel') ?>" onclick="refreshParentWindow(); closeWindow();"/>
</div> </div>
</form> </form>
</div> </div>

View File

@ -26,10 +26,10 @@ if ( !canView( 'Monitors' ) ) {
$mid = validInt($_REQUEST['mid']); $mid = validInt($_REQUEST['mid']);
$monitor = new Monitor( $mid ); $monitor = new Monitor( $mid );
# Width() and Height() are already rotated # Width() and Height() are already rotated
$minX = 0; $minX = 0;
$maxX = $monitor->Width()-1; $maxX = $monitor->Width()-1;
$minY = 0; $minY = 0;
$maxY = $monitor->Height()-1; $maxY = $monitor->Height()-1;
$zones = array(); $zones = array();
foreach( dbFetchAll( 'SELECT * FROM Zones WHERE MonitorId=? ORDER BY Area DESC', NULL, array($mid) ) as $row ) { foreach( dbFetchAll( 'SELECT * FROM Zones WHERE MonitorId=? ORDER BY Area DESC', NULL, array($mid) ) as $row ) {
@ -71,8 +71,7 @@ xhtmlHeaders(__FILE__, translate('Zones') );
</thead> </thead>
<tbody> <tbody>
<?php <?php
foreach( $zones as $zone ) foreach( $zones as $zone ) {
{
?> ?>
<tr> <tr>
<td class="colName"><a href="#" onclick="streamCmdQuit( true ); createPopup( '?view=zone&amp;mid=<?php echo $mid ?>&amp;zid=<?php echo $zone['Id'] ?>', 'zmZone', 'zone', <?php echo $monitor->Width() ?>, <?php echo $monitor->Height() ?> ); return( false );"><?php echo $zone['Name'] ?></a></td> <td class="colName"><a href="#" onclick="streamCmdQuit( true ); createPopup( '?view=zone&amp;mid=<?php echo $mid ?>&amp;zid=<?php echo $zone['Id'] ?>', 'zmZone', 'zone', <?php echo $monitor->Width() ?>, <?php echo $monitor->Height() ?> ); return( false );"><?php echo $zone['Name'] ?></a></td>
@ -86,12 +85,12 @@ foreach( $zones as $zone )
</tbody> </tbody>
</table> </table>
<div class="ZonesImage" style="position:relative; clear:both;"> <div class="ZonesImage" style="position:relative; clear:both;">
<?php echo getStreamHTML( $monitor ); ?> <?php echo getStreamHTML( $monitor ); ?>
<svg class="zones" width="<?php echo $monitor->Width() ?>" height="<?php echo $monitor->Height() ?>" style="position:absolute; top: 0; left: 0; background: none;"> <svg class="zones" width="<?php echo $monitor->Width() ?>" height="<?php echo $monitor->Height() ?>" style="position:absolute; top: 0; left: 0; background: none;">
<?php <?php
foreach( array_reverse($zones) as $zone ) { foreach( array_reverse($zones) as $zone ) {
?> ?>
<polygon points="<?php echo $zone['AreaCoords'] ?>" class="<?php echo $zone['Type']?>" onclick="streamCmdQuit( true ); createPopup( '?view=zone&amp;mid=<?php echo $mid ?>&amp;zid=<?php echo $zone['Id'] ?>', 'zmZone', 'zone', <?php echo $monitor->Width ?>, <?php echo $monitor->Height ?> ); return( false );"/> <polygon points="<?php echo $zone['AreaCoords'] ?>" class="<?php echo $zone['Type']?>" onclick="streamCmdQuit( true ); createPopup( '?view=zone&amp;mid=<?php echo $mid ?>&amp;zid=<?php echo $zone['Id'] ?>', 'zmZone', 'zone', <?php echo $monitor->Width ?>, <?php echo $monitor->Height ?> ); return( false );"/>
<?php <?php
} // end foreach zone } // end foreach zone
?> ?>