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

This commit is contained in:
Isaac Connor 2021-12-15 12:43:03 -05:00
commit d41d2ff03d
10 changed files with 141 additions and 132 deletions

View File

@ -51,11 +51,21 @@ sub open {
my $self = shift; my $self = shift;
$self->loadMonitor(); $self->loadMonitor();
if ($self->{Monitor}->{ControlAddress} and ($self->{Monitor}->{ControlAddress} ne 'user:pass@ip')) {
Debug("Getting connection details from Control Address " . $self->{Monitor}->{ControlAddress});
if ( $self->{Monitor}->{ControlAddress} !~ /^\w+:\/\// ) { if ( $self->{Monitor}->{ControlAddress} !~ /^\w+:\/\// ) {
# Has no scheme at the beginning, so won't parse as a URI # Has no scheme at the beginning, so won't parse as a URI
$self->{Monitor}->{ControlAddress} = 'http://'.$self->{Monitor}->{ControlAddress}; $self->{Monitor}->{ControlAddress} = 'http://'.$self->{Monitor}->{ControlAddress};
} }
$uri = URI->new($self->{Monitor}->{ControlAddress}); $uri = URI->new($self->{Monitor}->{ControlAddress});
} elsif ($self->{Monitor}->{Path}) {
Debug("Getting connection details from Path " . $self->{Monitor}->{Path});
$uri = URI->new($self->{Monitor}->{Path});
$uri->scheme('http');
$uri->port(80);
$uri->path('');
}
use LWP::UserAgent; use LWP::UserAgent;
$self->{ua} = LWP::UserAgent->new; $self->{ua} = LWP::UserAgent->new;
@ -64,6 +74,7 @@ sub open {
$self->{state} = 'closed'; $self->{state} = 'closed';
my ( $username, $password, $host ) = ( $uri->authority() =~ /^([^:]+):([^@]*)@(.+)$/ ); my ( $username, $password, $host ) = ( $uri->authority() =~ /^([^:]+):([^@]*)@(.+)$/ );
Debug("Have username: $username password: $password host: $host from authority:" . $uri->authority());
$uri->userinfo(undef); $uri->userinfo(undef);
@ -82,16 +93,22 @@ sub open {
$self->{state} = 'open'; $self->{state} = 'open';
return; return;
} }
if ($res->status_line() eq '404 Not Found') {
#older style
$url = 'axis-cgi/com/ptz.cgi';
$res = $self->{ua}->get($uri->canonical().$url);
Debug("Result from getting ".$uri->canonical().$url . ':' . $res->status_line());
}
if ($res->status_line() eq '401 Unauthorized') { if ($res->status_line() eq '401 Unauthorized') {
my $headers = $res->headers(); my $headers = $res->headers();
foreach my $k ( keys %$headers ) { foreach my $k ( keys %$headers ) {
Debug("Initial Header $k => $$headers{$k}"); Debug("Initial Header $k => $$headers{$k}");
} }
if ( $$headers{'www-authenticate'} ) { if ( $$headers{'www-authenticate'} ) {
my ( $auth, $tokens ) = $$headers{'www-authenticate'} =~ /^(\w+)\s+(.*)$/; foreach my $auth_header ( ref $$headers{'www-authenticate'} eq 'ARRAY' ? @{$$headers{'www-authenticate'}} : ($$headers{'www-authenticate'})) {
my ( $auth, $tokens ) = $auth_header =~ /^(\w+)\s+(.*)$/;
if ( $tokens =~ /\w+="([^"]+)"/i ) { if ( $tokens =~ /\w+="([^"]+)"/i ) {
if ( $realm ne $1 ) { if ( $realm ne $1 ) {
$realm = $1; $realm = $1;
@ -109,6 +126,7 @@ sub open {
} else { } else {
Error('Failed to match realm in tokens'); Error('Failed to match realm in tokens');
} # end if } # end if
} # end foreach auth header
} else { } else {
Debug('No headers line'); Debug('No headers line');
} # end if headers } # end if headers

View File

@ -413,13 +413,11 @@ sub Sql {
$sql .= ' LIMIT 0,'.$filter_expr->{limit}; $sql .= ' LIMIT 0,'.$filter_expr->{limit};
} }
if ($$self{LockRows}) { if ($$self{LockRows}) {
$sql .= ' FOR UPDATE OF E' $sql .= ' FOR UPDATE';
} else {
$sql .= ' FOR SHARE OF E'
}
if ($filter_expr->{skip_locked}) { if ($filter_expr->{skip_locked}) {
$sql .= ' SKIP LOCKED'; $sql .= ' SKIP LOCKED';
} }
}
$self->{Sql} = $sql; $self->{Sql} = $sql;
} # end if has Sql } # end if has Sql
return $self->{Sql}; return $self->{Sql};

View File

@ -243,18 +243,24 @@ sub control {
if ($command eq 'stop' or $command eq 'restart') { if ($command eq 'stop' or $command eq 'restart') {
if ($process) { if ($process) {
`/usr/bin/zmdc.pl stop $process -m $$monitor{Id}`; ZoneMinder::General::runCommand("zmdc.pl stop $process -m $$monitor{Id}");
} else { } else {
`/usr/bin/zmdc.pl stop zma -m $$monitor{Id}`; if ($monitor->{Type} eq 'Local') {
`/usr/bin/zmdc.pl stop zmc -m $$monitor{Id}`; ZoneMinder::General::runCommand('zmdc.pl stop zmc -d '.$monitor->{Device});
} else {
ZoneMinder::General::runCommand('zmdc.pl stop zmc -m '.$monitor->{Id});
}
} }
} }
if ( $command eq 'start' or $command eq 'restart' ) { if ( $command eq 'start' or $command eq 'restart' ) {
if ( $process ) { if ( $process ) {
`/usr/bin/zmdc.pl start $process -m $$monitor{Id}`; ZoneMinder::General::runCommand("zmdc.pl start $process -m $$monitor{Id}");
} else { } else {
`/usr/bin/zmdc.pl start zmc -m $$monitor{Id}`; if ($monitor->{Type} eq 'Local') {
`/usr/bin/zmdc.pl start zma -m $$monitor{Id}`; ZoneMinder::General::runCommand('zmdc.pl start zmc -d '.$monitor->{Device});
} else {
ZoneMinder::General::runCommand('zmdc.pl start zmc -m '.$monitor->{Id});
}
} # end if } # end if
} }
} # end sub control } # end sub control

View File

@ -1048,7 +1048,7 @@ sub executeCommand {
Error("Command '$command' exited with status: $status"); Error("Command '$command' exited with status: $status");
return 0; return 0;
} else { } else {
zmSQLExecute('UPDATE `Events` SET `Executed` = 1 WHERE `Id` = ?', $Event->{Id}); ZoneMinder::Database::zmSQLExecute('UPDATE `Events` SET `Executed` = 1 WHERE `Id` = ?', $Event->{Id});
} }
return 1; return 1;
} }

View File

@ -56,6 +56,7 @@ use constant START_DELAY => 30; # To give everything else time to start
@EXTRA_PERL_LIB@ @EXTRA_PERL_LIB@
use ZoneMinder; use ZoneMinder;
use ZoneMinder::Storage; use ZoneMinder::Storage;
use ZoneMinder::Monitor;
use POSIX; use POSIX;
use DBI; use DBI;
use autouse 'Data::Dumper'=>qw(Dumper); use autouse 'Data::Dumper'=>qw(Dumper);
@ -80,9 +81,6 @@ Info('Watchdog starting, pausing for '.START_DELAY.' seconds');
sleep(START_DELAY); sleep(START_DELAY);
my $dbh = zmDbConnect(); my $dbh = zmDbConnect();
my $sql = $Config{ZM_SERVER_ID} ? 'SELECT * FROM Monitors WHERE ServerId=?' : 'SELECT * FROM Monitors';
my $sth = $dbh->prepare_cached($sql)
or Fatal("Can't prepare '$sql': ".$dbh->errstr());
while (!$zm_terminate) { while (!$zm_terminate) {
while (!($dbh and $dbh->ping())) { while (!($dbh and $dbh->ping())) {
@ -91,38 +89,40 @@ while (!$zm_terminate) {
} }
} }
my $res = $sth->execute( $Config{ZM_SERVER_ID} ? $Config{ZM_SERVER_ID} : () ) foreach my $monitor (ZoneMinder::Monitor->find($Config{ZM_SERVER_ID} ? (ServerId=>$Config{ZM_SERVER_ID}) : ())) {
or Fatal('Can\'t execute: '.$sth->errstr());
while( my $monitor = $sth->fetchrow_hashref() ) {
next if $monitor->{Function} eq 'None'; next if $monitor->{Function} eq 'None';
next if $monitor->{Type} eq 'WebSite'; next if $monitor->{Type} eq 'WebSite';
my $now = time(); my $now = time();
my $restart = 0; my $restart = 0;
if (zmMemVerify($monitor)) {
zmMemInvalidate($monitor);
if (!zmMemVerify($monitor)) {
Info("Restarting capture daemon for $monitor->{Name}, shared data not valid");
$monitor->control('restart');
next;
}
# Check we have got an image recently # Check we have got an image recently
my $capture_time = zmGetLastWriteTime($monitor); my $capture_time = zmGetLastWriteTime($monitor);
if (!defined($capture_time)) { if (!defined($capture_time)) {
# Can't read from shared data # Can't read from shared data
Debug('LastWriteTime is not defined.'); Warning('LastWriteTime is not defined.');
zmMemInvalidate($monitor);
next; next;
} }
Debug("Monitor $$monitor{Id} LastWriteTime is $capture_time."); Debug("Monitor $$monitor{Id} LastWriteTime is $capture_time.");
if (!$capture_time) { if (!$capture_time) {
# We can't get the last capture time so can't be sure it's died, it might just be starting up.
my $startup_time = zmGetStartupTime($monitor); my $startup_time = zmGetStartupTime($monitor);
if (($now - $startup_time) > $Config{ZM_WATCH_MAX_DELAY}) { if (($now - $startup_time) > $Config{ZM_WATCH_MAX_DELAY}) {
Warning( Warning(
"Restarting capture daemon for $$monitor{Name}, no image since startup. ". "Restarting capture daemon for $$monitor{Name}, no image since startup. ".
"Startup time was $startup_time - now $now > $Config{ZM_WATCH_MAX_DELAY}" "Startup time was $startup_time - now $now > $Config{ZM_WATCH_MAX_DELAY}"
); );
$restart = 1; $monitor->control('restart');
} else { }
# We can't get the last capture time so can't be sure it's died, it might just be starting up.
zmMemInvalidate($monitor);
next; next;
} }
}
if (!$restart) {
my $max_image_delay = ( my $max_image_delay = (
$monitor->{MaxFPS} $monitor->{MaxFPS}
&&($monitor->{MaxFPS}>0) &&($monitor->{MaxFPS}>0)
@ -133,38 +133,23 @@ while (!$zm_terminate) {
my $image_delay = $now - $capture_time; my $image_delay = $now - $capture_time;
Debug("Monitor $monitor->{Id} last captured $image_delay seconds ago, max is $max_image_delay"); Debug("Monitor $monitor->{Id} last captured $image_delay seconds ago, max is $max_image_delay");
if ($image_delay > $max_image_delay) { if ($image_delay > $max_image_delay) {
Warning("Restarting capture daemon for " Warning('Restarting capture daemon for '.$monitor->{Name}.
.$monitor->{Name}.", time since last capture $image_delay seconds ($now-$capture_time)" ", time since last capture $image_delay seconds ($now-$capture_time)");
); $monitor->control('restart');
$restart = 1; next;
}
} # end if ! restart
} else {
Info("Restarting capture daemon for $monitor->{Name}, shared data not valid");
$restart = 1;
} }
if ($restart) { if ($monitor->{Function} ne 'Monitor') {
my $command; # Now check analysis thread
if ($monitor->{Type} eq 'Local') {
$command = 'zmdc.pl restart zmc -d '.$monitor->{Device};
} else {
$command = 'zmdc.pl restart zmc -m '.$monitor->{Id};
}
runCommand($command);
} elsif ($monitor->{Function} ne 'Monitor') {
# Now check analysis daemon
$restart = 0;
# Check we have got an image recently # Check we have got an image recently
my $image_time = zmGetLastReadTime($monitor); my $image_time = zmGetLastReadTime($monitor);
if (!defined($image_time)) { if (!defined($image_time)) {
# Can't read from shared data # Can't read from shared data
$restart = 1;
Error("Error reading shared data for $$monitor{Id} $$monitor{Name}"); Error("Error reading shared data for $$monitor{Id} $$monitor{Name}");
$monitor->control('restart');
next;
} elsif (!$image_time) { } elsif (!$image_time) {
# We can't get the last capture time so can't be sure it's died. Debug("Last analyse time for $$monitor{Id} $$monitor{Name} was zero.");
#$restart = 1;
Error("Last analyse time for $$monitor{Id} $$monitor{Name} was zero.");
} else { } else {
my $max_image_delay = ( $monitor->{MaxFPS} my $max_image_delay = ( $monitor->{MaxFPS}
&&($monitor->{MaxFPS}>0) &&($monitor->{MaxFPS}>0)
@ -176,25 +161,14 @@ while (!$zm_terminate) {
Debug("Monitor $monitor->{Id} last analysed $image_delay seconds ago, max is $max_image_delay"); Debug("Monitor $monitor->{Id} last analysed $image_delay seconds ago, max is $max_image_delay");
if ($image_delay > $max_image_delay) { if ($image_delay > $max_image_delay) {
Warning("Analysis daemon for $$monitor{Id} $$monitor{Name} needs restarting," Warning("Analysis daemon for $$monitor{Id} $$monitor{Name} needs restarting,"
." time since last analysis $image_delay seconds ($now-$image_time)" ." time since last analysis $image_delay seconds ($now-$image_time)");
); $monitor->control('restart');
$restart = 1; next;
} }
} }
if ($restart) {
Info("Restarting analysis daemon for $$monitor{Id} $$monitor{Name}");
my $command;
if ( $monitor->{Type} eq 'Local' ) {
$command = 'zmdc.pl restart zmc -d '.$monitor->{Device};
} else {
$command = 'zmdc.pl restart zmc -m '.$monitor->{Id};
}
runCommand($command);
} # end if restart
} # end if check analysis daemon } # end if check analysis daemon
# Prevent open handles building up if we have connect to shared memory
zmMemInvalidate($monitor); # Close our file handle to the zmc process we are about to end
} # end foreach monitor } # end foreach monitor
sleep($Config{ZM_WATCH_CHECK_INTERVAL}); sleep($Config{ZM_WATCH_CHECK_INTERVAL});

View File

@ -128,10 +128,10 @@ bool StreamBase::checkCommandQueue() {
return true; return true;
} }
} else if ( connkey ) { } else if ( connkey ) {
Warning("No sd in checkCommandQueue, comms not open?"); Warning("No sd in checkCommandQueue, comms not open for connkey %06d?", connkey);
} else { } else {
// Perfectly valid if only getting a snapshot // Perfectly valid if only getting a snapshot
Debug(1, "No sd in checkCommandQueue, comms not open?"); Debug(1, "No sd in checkCommandQueue, comms not open.");
} }
return false; return false;
} // end bool StreamBase::checkCommandQueue() } // end bool StreamBase::checkCommandQueue()
@ -387,8 +387,8 @@ void StreamBase::openComms() {
rem_addr.sun_family = AF_UNIX; rem_addr.sun_family = AF_UNIX;
last_comm_update = std::chrono::system_clock::now(); last_comm_update = std::chrono::system_clock::now();
} // end if connKey > 0
Debug(3, "comms open at %s", loc_sock_path); Debug(3, "comms open at %s", loc_sock_path);
} // end if connKey > 0
} // end void StreamBase::openComms() } // end void StreamBase::openComms()
void StreamBase::closeComms() { void StreamBase::closeComms() {

View File

@ -482,7 +482,7 @@ int main(int argc, char *argv[]) {
exit_zmu(-1); exit_zmu(-1);
} }
if ( !ValidateAccess(user, mon_id, function) ) { if ( !ValidateAccess(user, mon_id, function) ) {
Error("Insufficient privileges for requested action"); Error("Insufficient privileges for user %s for requested function %x", username, function);
exit_zmu(-1); exit_zmu(-1);
} }
} // end if auth } // end if auth
@ -497,6 +497,16 @@ int main(int argc, char *argv[]) {
if ( verbose ) { if ( verbose ) {
printf("Monitor %u(%s)\n", monitor->Id(), monitor->Name()); printf("Monitor %u(%s)\n", monitor->Id(), monitor->Name());
} }
if (monitor->GetFunction() == Monitor::NONE) {
if (verbose) {
printf("Current state: None\n");
} else {
printf("%d", Monitor::UNKNOWN);
}
exit_zmu(-1);
}
if ( !monitor->connect() ) { if ( !monitor->connect() ) {
Error("Can't connect to capture daemon: %d %s", monitor->Id(), monitor->Name()); Error("Can't connect to capture daemon: %d %s", monitor->Id(), monitor->Name());
exit_zmu(-1); exit_zmu(-1);

View File

@ -446,8 +446,10 @@ function streamFastRev(action) {
function streamPrev(action) { function streamPrev(action) {
if (action) { if (action) {
$j(".vjsMessage").remove(); $j(".vjsMessage").remove();
if (prevEventId != 0) {
location.replace(thisUrl + '?view=event&eid=' + prevEventId + filterQuery + sortQuery); location.replace(thisUrl + '?view=event&eid=' + prevEventId + filterQuery + sortQuery);
return; return;
}
/* Ideally I'd like to get back to this style /* Ideally I'd like to get back to this style
if ( vid && PrevEventDefVideoPath.indexOf("view_video") > 0 ) { if ( vid && PrevEventDefVideoPath.indexOf("view_video") > 0 ) {
@ -619,8 +621,8 @@ function getNearEventsResponse(respObj, respText) {
if (checkStreamForErrors('getNearEventsResponse', respObj)) { if (checkStreamForErrors('getNearEventsResponse', respObj)) {
return; return;
} }
prevEventId = respObj.nearevents.PrevEventId; prevEventId = parseInt(respObj.nearevents.PrevEventId);
nextEventId = respObj.nearevents.NextEventId; nextEventId = parseInt(respObj.nearevents.NextEventId);
prevEventStartTime = Date.parse(respObj.nearevents.PrevEventStartTime); prevEventStartTime = Date.parse(respObj.nearevents.PrevEventStartTime);
nextEventStartTime = Date.parse(respObj.nearevents.NextEventStartTime); nextEventStartTime = Date.parse(respObj.nearevents.NextEventStartTime);
PrevEventDefVideoPath = respObj.nearevents.PrevEventDefVideoPath; PrevEventDefVideoPath = respObj.nearevents.PrevEventDefVideoPath;

View File

@ -904,9 +904,10 @@ function initPage() {
if (monitorType != 'WebSite') { if (monitorType != 'WebSite') {
if (streamMode == 'single') { if (streamMode == 'single') {
statusCmdTimer = setTimeout(statusCmdQuery, (Math.random()+0.1)*statusRefreshTimeout); statusCmdTimer = setTimeout(statusCmdQuery, 100);
setInterval(watchdogCheck, statusRefreshTimeout*2, 'status'); setInterval(watchdogCheck, statusRefreshTimeout*2, 'status');
} else { } else {
streamCmdTimer = setTimeout(streamCmdQuery, 100);
setInterval(watchdogCheck, statusRefreshTimeout*2, 'stream'); setInterval(watchdogCheck, statusRefreshTimeout*2, 'stream');
} }

View File

@ -1,5 +1,5 @@
<?php <?php
global $monIdx; global $monitor_index;
global $nextMid; global $nextMid;
global $options; global $options;
global $monitors; global $monitors;
@ -53,7 +53,7 @@ var monitorRefresh = '<?php echo $monitor->Refresh() ?>';
var monitorStreamReplayBuffer = <?php echo $monitor->StreamReplayBuffer() ?>; var monitorStreamReplayBuffer = <?php echo $monitor->StreamReplayBuffer() ?>;
var monitorControllable = <?php echo $monitor->Controllable()?'true':'false' ?>; var monitorControllable = <?php echo $monitor->Controllable()?'true':'false' ?>;
var monIdx = '<?php echo $monIdx; ?>'; var monIdx = <?php echo $monitor_index; ?>;
var nextMid = "<?php echo isset($nextMid)?$nextMid:'' ?>"; var nextMid = "<?php echo isset($nextMid)?$nextMid:'' ?>";
var mode = "<?php echo $options['mode'] ?>"; var mode = "<?php echo $options['mode'] ?>";