From ad1808d43bcd131774470b81e8fbc208db0f7c95 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 3 Oct 2017 13:25:05 -0400 Subject: [PATCH 1/4] warn when path doesn't exist in event::age --- scripts/ZoneMinder/lib/ZoneMinder/Event.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Event.pm b/scripts/ZoneMinder/lib/ZoneMinder/Event.pm index 32d4fba85..4f7ce0ca5 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Event.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Event.pm @@ -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}; } From 995809ccb75df02964b8bbc568531877ed08cc45 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 4 Oct 2017 10:48:14 -0400 Subject: [PATCH 2/4] fix play/pause while editing zone --- web/skins/classic/views/js/zone.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/web/skins/classic/views/js/zone.js b/web/skins/classic/views/js/zone.js index e24cc87dd..023671588 100644 --- a/web/skins/classic/views/js/zone.js +++ b/web/skins/classic/views/js/zone.js @@ -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() { From 8f8d66189cce00b3b81979cfdf0f04ef51b6eb41 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 4 Oct 2017 10:48:24 -0400 Subject: [PATCH 3/4] Google code style --- web/ajax/stream.php | 218 +++++++++++++++++++++----------------------- 1 file changed, 102 insertions(+), 116 deletions(-) diff --git a/web/ajax/stream.php b/web/ajax/stream.php index bf964e687..7f050bda8 100644 --- a/web/ajax/stream.php +++ b/web/ajax/stream.php @@ -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 ); } ?> From 54949db0b5ea0ee5d4f58d445e55a7b7aaf99b18 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 4 Oct 2017 10:48:37 -0400 Subject: [PATCH 4/4] spacing/google code style --- web/skins/classic/views/js/zones.js | 4 ++-- web/skins/classic/views/zone.php | 4 +++- web/skins/classic/views/zones.php | 17 ++++++++--------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/web/skins/classic/views/js/zones.js b/web/skins/classic/views/js/zones.js index b453ab4f5..a01f8b56f 100644 --- a/web/skins/classic/views/js/zones.js +++ b/web/skins/classic/views/js/zones.js @@ -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 ); } diff --git a/web/skins/classic/views/zone.php b/web/skins/classic/views/zone.php index ba0cb7328..f6a763c19 100644 --- a/web/skins/classic/views/zone.php +++ b/web/skins/classic/views/zone.php @@ -283,7 +283,9 @@ for ( $i = 0; $i < $pointCols; $i++ ) - disabled="disabled"/> + + disabled="disabled"/> + diff --git a/web/skins/classic/views/zones.php b/web/skins/classic/views/zones.php index c153d69c2..e9e5f292c 100644 --- a/web/skins/classic/views/zones.php +++ b/web/skins/classic/views/zones.php @@ -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') ); @@ -86,12 +85,12 @@ foreach( $zones as $zone )
- - + + - +