Merge branch 'master' of github.com:ZoneMinder/zoneminder

This commit is contained in:
Isaac Connor 2019-08-14 16:18:31 -04:00
commit 81dadc17dc
2 changed files with 30 additions and 29 deletions

View File

@ -562,8 +562,8 @@ sub CopyTo {
return 'Old Storage path changed, Event has moved somewhere else.'; return 'Old Storage path changed, Event has moved somewhere else.';
} }
$$self{Storage} = $NewStorage; $NewPath .= $self->Relative_Path();
( $NewPath ) = ( $self->Path(undef) =~ /^(.*)$/ ); # De-taint $NewPath = ( $NewPath =~ /^(.*)$/ ); # De-taint
if ( $NewPath eq $OldPath ) { if ( $NewPath eq $OldPath ) {
$ZoneMinder::Database::dbh->commit(); $ZoneMinder::Database::dbh->commit();
return "New path and old path are the same! $NewPath"; return "New path and old path are the same! $NewPath";
@ -685,7 +685,7 @@ sub MoveTo {
# Succeeded in copying all files, so we may now update the Event. # Succeeded in copying all files, so we may now update the Event.
$$self{StorageId} = $$NewStorage{Id}; $$self{StorageId} = $$NewStorage{Id};
$$self{Storage} = $NewStorage; $self->Storage($NewStorage);
$error .= $self->save(); $error .= $self->save();
if ( $error ) { if ( $error ) {
$ZoneMinder::Database::dbh->commit(); $ZoneMinder::Database::dbh->commit();

View File

@ -21,38 +21,38 @@ if ( sem_acquire($semaphore,1) !== false ) {
} }
$localSocketFile = ZM_PATH_SOCKS.'/zms-'.sprintf('%06d',$_REQUEST['connkey']).'w.sock'; $localSocketFile = ZM_PATH_SOCKS.'/zms-'.sprintf('%06d',$_REQUEST['connkey']).'w.sock';
if ( file_exists( $localSocketFile ) ) { if ( file_exists($localSocketFile) ) {
ZM\Warning("sock file $localSocketFile already exists?! Is someone else talking to zms?"); ZM\Warning("sock file $localSocketFile already exists?! Is someone else talking to zms?");
// They could be. We can maybe have concurrent requests from a browser. // They could be. We can maybe have concurrent requests from a browser.
} }
if ( !socket_bind( $socket, $localSocketFile ) ) { if ( !socket_bind($socket, $localSocketFile) ) {
ajaxError("socket_bind( $localSocketFile ) failed: ".socket_strerror(socket_last_error()) ); ajaxError("socket_bind( $localSocketFile ) failed: ".socket_strerror(socket_last_error()));
} }
switch ( $_REQUEST['command'] ) { switch ( $_REQUEST['command'] ) {
case CMD_VARPLAY : case CMD_VARPLAY :
ZM\Logger::Debug( 'Varplaying to '.$_REQUEST['rate'] ); ZM\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 :
ZM\Logger::Debug( 'Zooming to '.$_REQUEST['x'].','.$_REQUEST['y'] ); ZM\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 :
ZM\Logger::Debug( 'Panning to '.$_REQUEST['x'].','.$_REQUEST['y'] ); ZM\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 :
ZM\Logger::Debug( 'Scaling to '.$_REQUEST['scale'] ); ZM\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 :
ZM\Logger::Debug( 'Seeking to '.$_REQUEST['offset'] ); ZM\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 :
ZM\Logger::Debug('Sending command ' . $_REQUEST['command']); ZM\Logger::Debug('Sending command ' . $_REQUEST['command']);
$msg = pack( 'lc', MSG_CMD, $_REQUEST['command'] ); $msg = pack('lc', MSG_CMD, $_REQUEST['command']);
break; break;
} }
@ -60,7 +60,8 @@ if ( sem_acquire($semaphore,1) !== false ) {
// Pi can take up to 3 seconds for zms to start up. // Pi can take up to 3 seconds for zms to start up.
$max_socket_tries = 1000; $max_socket_tries = 1000;
// FIXME This should not exceed web_ajax_timeout // FIXME This should not exceed web_ajax_timeout
while ( !file_exists($remSockFile) && $max_socket_tries-- ) { //sometimes we are too fast for our own good, if it hasn't been setup yet give it a second. while ( !file_exists($remSockFile) && $max_socket_tries-- ) {
//sometimes we are too fast for our own good, if it hasn't been setup yet give it a second.
// WHY? We will just send another one... // WHY? We will just send another one...
// ANSWER: Because otherwise we get a log of errors logged // ANSWER: Because otherwise we get a log of errors logged
@ -71,27 +72,27 @@ if ( sem_acquire($semaphore,1) !== false ) {
if ( !file_exists($remSockFile) ) { if ( !file_exists($remSockFile) ) {
ajaxError("Socket $remSockFile does not exist. This file is created by zms, and since it does not exist, either zms did not run, or zms exited early. Please check your zms logs and ensure that CGI is enabled in apache and check that the PATH_ZMS is set correctly. Make sure that ZM is actually recording. If you are trying to view a live stream and the capture process (zmc) is not running then zms will exit. Please go to http://zoneminder.readthedocs.io/en/latest/faq.html#why-can-t-i-see-streamed-images-when-i-can-see-stills-in-the-zone-window-etc for more information."); ajaxError("Socket $remSockFile does not exist. This file is created by zms, and since it does not exist, either zms did not run, or zms exited early. Please check your zms logs and ensure that CGI is enabled in apache and check that the PATH_ZMS is set correctly. Make sure that ZM is actually recording. If you are trying to view a live stream and the capture process (zmc) is not running then zms will exit. Please go to http://zoneminder.readthedocs.io/en/latest/faq.html#why-can-t-i-see-streamed-images-when-i-can-see-stills-in-the-zone-window-etc for more information.");
} else { } else {
if ( !@socket_sendto( $socket, $msg, strlen($msg), 0, $remSockFile ) ) { if ( !@socket_sendto($socket, $msg, strlen($msg), 0, $remSockFile) ) {
ajaxError( "socket_sendto( $remSockFile ) failed: ".socket_strerror(socket_last_error()) ); ajaxError("socket_sendto( $remSockFile ) failed: ".socket_strerror(socket_last_error()));
} }
} }
$rSockets = array( $socket ); $rSockets = array($socket);
$wSockets = NULL; $wSockets = NULL;
$eSockets = NULL; $eSockets = NULL;
$timeout = MSG_TIMEOUT - ( time() - $start_time ); $timeout = MSG_TIMEOUT - ( time() - $start_time );
$numSockets = socket_select( $rSockets, $wSockets, $eSockets, intval($timeout/1000), ($timeout%1000)*1000 ); $numSockets = socket_select($rSockets, $wSockets, $eSockets, intval($timeout/1000), ($timeout%1000)*1000);
if ( $numSockets === false ) { if ( $numSockets === false ) {
ZM\Error('socket_select failed: ' . socket_strerror(socket_last_error()) ); ZM\Error('socket_select failed: ' . socket_strerror(socket_last_error()));
ajaxError( 'socket_select failed: '.socket_strerror(socket_last_error()) ); ajaxError('socket_select failed: '.socket_strerror(socket_last_error()));
} else if ( $numSockets < 0 ) { } else if ( $numSockets < 0 ) {
ZM\Error( "Socket closed $remSockFile" ); ZM\Error("Socket closed $remSockFile");
ajaxError( "Socket closed $remSockFile" ); ajaxError("Socket closed $remSockFile");
} else if ( $numSockets == 0 ) { } else if ( $numSockets == 0 ) {
ZM\Error( "Timed out waiting for msg $remSockFile" ); ZM\Error("Timed out waiting for msg $remSockFile");
socket_set_nonblock($socket); socket_set_nonblock($socket);
#ajaxError("Timed out waiting for msg $remSockFile"); #ajaxError("Timed out waiting for msg $remSockFile");
} else if ( $numSockets > 0 ) { } else if ( $numSockets > 0 ) {
@ -101,7 +102,7 @@ if ( sem_acquire($semaphore,1) !== false ) {
} }
} }
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;
@ -157,7 +158,7 @@ if ( sem_acquire($semaphore,1) !== false ) {
} }
sem_release($semaphore); sem_release($semaphore);
} else { } else {
ZM\Logger::Debug("Couldn't get semaphore"); ZM\Logger::Debug('Couldn\'t get semaphore');
ajaxResponse(array()); ajaxResponse(array());
} }