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
scripts/ZoneMinder/lib/ZoneMinder
web

View File

@ -348,7 +348,12 @@ Debug("Checking for files for event $_[0]{Id} at $path using glob $path/* found
sub 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};
}

View File

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

View File

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

View File

@ -283,7 +283,9 @@ for ( $i = 0; $i < $pointCols; $i++ )
</tr>
</tbody>
</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>
</form>
</div>

View File

@ -26,10 +26,10 @@ if ( !canView( 'Monitors' ) ) {
$mid = validInt($_REQUEST['mid']);
$monitor = new Monitor( $mid );
# Width() and Height() are already rotated
$minX = 0;
$maxX = $monitor->Width()-1;
$minY = 0;
$maxY = $monitor->Height()-1;
$minX = 0;
$maxX = $monitor->Width()-1;
$minY = 0;
$maxY = $monitor->Height()-1;
$zones = array();
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>
<tbody>
<?php
foreach( $zones as $zone )
{
foreach( $zones as $zone ) {
?>
<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>
@ -86,12 +85,12 @@ foreach( $zones as $zone )
</tbody>
</table>
<div class="ZonesImage" style="position:relative; clear:both;">
<?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;">
<?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;">
<?php
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
} // end foreach zone
?>