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

This commit is contained in:
Isaac Connor 2021-10-29 18:54:47 -04:00
commit 3f0bdf6332
7 changed files with 132 additions and 129 deletions

View File

@ -5,6 +5,12 @@ set +e
create_db () {
echo "Checking for db"
mysqladmin --defaults-file=/etc/mysql/debian.cnf -f reload
if [ $? -ne 0 ]; then
echo "Cannot talk to database. You will have to create the db manually with something like:";
echo "cat /usr/share/zoneminder/db/zm_create.sql | mysql -u root";
return;
fi
# test if database if already present...
if ! $(echo quit | mysql --defaults-file=/etc/mysql/debian.cnf zm > /dev/null 2> /dev/null) ; then
echo "Creating zm db"

View File

@ -720,7 +720,7 @@ sub CopyTo {
} # end foreach file.
} # end if ! moved
return $error if $error;
return $error;
} # end sub CopyTo
sub MoveTo {
@ -744,11 +744,11 @@ sub MoveTo {
$$self{StorageId} = $$NewStorage{Id};
$self->Storage($NewStorage);
$error .= $self->save();
if ($error) {
$ZoneMinder::Database::dbh->commit() if !$was_in_transaction;
return $error;
}
# Going to leave it to upper layer as to whether we rollback or not
$ZoneMinder::Database::dbh->commit() if !$was_in_transaction;
return $error if $error;
$self->delete_files($OldStorage);
return $error;
} # end sub MoveTo

View File

@ -663,6 +663,7 @@ bool EventStream::checkEventLoaded() {
else
curr_frame_id = 1;
Debug(2, "New frame id = %ld", curr_frame_id);
start = std::chrono::system_clock::now();
return true;
} else {
Debug(2, "No next event loaded using %s. Pausing", sql.c_str());
@ -957,18 +958,20 @@ void EventStream::runStream() {
static_cast<int64>(std::chrono::duration_cast<Microseconds>(delta).count()));
// if effective > base we should speed up frame delivery
delta = std::chrono::duration_cast<Microseconds>((delta * base_fps) / effective_fps);
Debug(3, "delta %" PRIi64 " us = base_fps (%f) / effective_fps (%f)",
if (base_fps < effective_fps) {
delta = std::chrono::duration_cast<Microseconds>((delta * base_fps) / effective_fps);
Debug(3, "delta %" PRIi64 " us = base_fps (%f) / effective_fps (%f)",
static_cast<int64>(std::chrono::duration_cast<Microseconds>(delta).count()),
base_fps,
effective_fps);
// but must not exceed maxfps
delta = std::max(delta, Microseconds(lround(Microseconds::period::den / maxfps)));
Debug(3, "delta %" PRIi64 " us = base_fps (%f) /effective_fps (%f) from 30fps",
// but must not exceed maxfps
delta = std::max(delta, Microseconds(lround(Microseconds::period::den / maxfps)));
Debug(3, "delta %" PRIi64 " us = base_fps (%f) / effective_fps (%f) from 30fps",
static_cast<int64>(std::chrono::duration_cast<Microseconds>(delta).count()),
base_fps,
effective_fps);
}
// +/- 1? What if we are skipping frames?
curr_frame_id += (replay_rate>0) ? frame_mod : -1*frame_mod;

View File

@ -1,7 +1,6 @@
<?php
if ( empty($_REQUEST['eid']) ) ajaxError('Event Id Not Provided');
if ( empty($_REQUEST['fid']) ) ajaxError('Frame Id Not Provided');
if (empty($_REQUEST['eid'])) ajaxError('Event Id Not Provided');
if (empty($_REQUEST['fid'])) ajaxError('Frame Id Not Provided');
$eid = $_REQUEST['eid'];
$fid = $_REQUEST['fid'];
@ -9,32 +8,26 @@ $row = ( isset($_REQUEST['row']) ) ? $_REQUEST['row'] : '';
$raw = isset($_REQUEST['raw']);
$data = array();
// Not sure if this is required
if ( ZM_OPT_USE_AUTH && (ZM_AUTH_RELAY == 'hashed') ) {
$auth_hash = generateAuthHash(ZM_AUTH_HASH_IPS);
if ( isset($_REQUEST['auth']) and ($_REQUEST['auth'] != $auth_hash) ) {
$data['auth'] = $auth_hash;
}
}
if ( $raw ) {
$sql = 'SELECT S.*,E.*,Z.Name AS ZoneName,Z.Units,Z.Area,M.Name AS MonitorName FROM Stats AS S LEFT JOIN Events AS E ON S.EventId = E.Id LEFT JOIN Zones AS Z ON S.ZoneId = Z.Id LEFT JOIN Monitors AS M ON E.MonitorId = M.Id WHERE S.EventId = ? AND S.FrameId = ? ORDER BY S.ZoneId';
$stat = dbFetchOne( $sql, NULL, array( $eid, $fid ) );
if ( $stat ) {
if ($raw) {
$sql = 'SELECT S.*,E.*,Z.Name AS ZoneName,Z.Units,Z.Area,M.Name AS MonitorName
FROM Stats AS S LEFT JOIN Events AS E ON S.EventId = E.Id LEFT JOIN Zones AS Z ON S.ZoneId = Z.Id LEFT JOIN Monitors AS M ON E.MonitorId = M.Id
WHERE S.EventId = ? AND S.FrameId = ? ORDER BY S.ZoneId';
$stats = dbFetchAll($sql, NULL, array($eid, $fid));
foreach ($stats as $stat) {
$stat['ZoneName'] = validHtmlStr($stat['ZoneName']);
$stat['PixelDiff'] = validHtmlStr($stat['PixelDiff']);
$stat['AlarmPixels'] = sprintf( "%d (%d%%)", $stat['AlarmPixels'], (100*$stat['AlarmPixels']/$stat['Area']) );
$stat['FilterPixels'] = sprintf( "%d (%d%%)", $stat['FilterPixels'], (100*$stat['FilterPixels']/$stat['Area']) );
$stat['BlobPixels'] = sprintf( "%d (%d%%)", $stat['BlobPixels'], (100*$stat['BlobPixels']/$stat['Area']) );
$stat['AlarmPixels'] = sprintf('%d (%d%%)', $stat['AlarmPixels'], (100*$stat['AlarmPixels']/$stat['Area']));
$stat['FilterPixels'] = sprintf('%d (%d%%)', $stat['FilterPixels'], (100*$stat['FilterPixels']/$stat['Area']));
$stat['BlobPixels'] = sprintf('%d (%d%%)', $stat['BlobPixels'], (100*$stat['BlobPixels']/$stat['Area']));
$stat['Blobs'] = validHtmlStr($stat['Blobs']);
if ( $stat['Blobs'] > 1 ) {
$stat['BlobSizes'] = sprintf( "%d-%d (%d%%-%d%%)", $stat['MinBlobSize'], $stat['MaxBlobSize'], (100*$stat['MinBlobSize']/$stat['Area']), (100*$stat['MaxBlobSize']/$stat['Area']) );
if ($stat['Blobs'] > 1) {
$stat['BlobSizes'] = sprintf('%d-%d (%d%%-%d%%)', $stat['MinBlobSize'], $stat['MaxBlobSize'], (100*$stat['MinBlobSize']/$stat['Area']), (100*$stat['MaxBlobSize']/$stat['Area']));
} else {
$stat['BlobSizes'] = sprintf( "%d (%d%%)", $stat['MinBlobSize'], 100*$stat['MinBlobSize']/$stat['Area'] );
$stat['BlobSizes'] = sprintf('%d (%d%%)', $stat['MinBlobSize'], 100*$stat['MinBlobSize']/$stat['Area']);
}
$stat['AlarmLimits'] = validHtmlStr($stat['MinX'].",".$stat['MinY']."-".$stat['MaxX'].",".$stat['MaxY']);
}
$data['raw'] = $stat;
$stat['AlarmLimits'] = validHtmlStr($stat['MinX'].','.$stat['MinY'].'-'.$stat['MaxX'].','.$stat['MaxY']);
$data['raw'][] = $stat;
} # end foreach stat/zone
} else {
$data['html'] = getStatsTableHTML($eid, $fid, $row);
$data['id'] = '#contentStatsTable' .$row;

View File

@ -18,30 +18,28 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
if ( !canView('Events') ) {
$view = 'error';
return;
}
require_once('includes/Frame.php');
$eid = validInt($_REQUEST['eid']);
$fid = empty($_REQUEST['fid']) ? 0 : validInt($_REQUEST['fid']);
$Event = new ZM\Event($eid);
if (!$Event->canView()) {
$view = 'error';
return;
}
$Monitor = $Event->Monitor();
# This is kinda weird.. so if we pass fid=0 or some other non-integer, then it loads max score
# perhaps we should consider being explicit, like fid = maxscore
if ( !empty($fid) ) {
$sql = 'SELECT * FROM Frames WHERE EventId = ? AND FrameId = ?';
if ( !($frame = dbFetchOne($sql, NULL, array($eid, $fid))) )
if (!empty($fid)) {
$sql = 'SELECT * FROM Frames WHERE EventId=? AND FrameId=?';
if (!($frame = dbFetchOne($sql, NULL, array($eid, $fid))))
$frame = array('EventId'=>$eid, 'FrameId'=>$fid, 'Type'=>'Normal', 'Score'=>0);
} else {
$frame = dbFetchOne('SELECT * FROM Frames WHERE EventId = ? AND Score = ?', NULL, array($eid, $Event->MaxScore()));
$frame = dbFetchOne('SELECT * FROM Frames WHERE EventId=? AND Score=?', NULL, array($eid, $Event->MaxScore()));
}
$Frame = new ZM\Frame($frame);
$maxFid = $Event->Frames();
$firstFid = 1;
@ -51,11 +49,11 @@ $lastFid = $maxFid;
$alarmFrame = ( $Frame->Type() == 'Alarm' ) ? 1 : 0;
if ( isset($_REQUEST['scale']) ) {
if (isset($_REQUEST['scale'])) {
$scale = validNum($_REQUEST['scale']);
} else if ( isset($_COOKIE['zmWatchScale'.$Monitor->Id()]) ) {
} else if (isset($_COOKIE['zmWatchScale'.$Monitor->Id()])) {
$scale = validNum($_COOKIE['zmWatchScale'.$Monitor->Id()]);
} else if ( isset($_COOKIE['zmWatchScale']) ) {
} else if (isset($_COOKIE['zmWatchScale'])) {
$scale = validNum($_COOKIE['zmWatchScale']);
} else {
$scale = max(reScale(SCALE_BASE, $Monitor->DefaultScale(), ZM_WEB_DEFAULT_SCALE), SCALE_BASE);
@ -63,7 +61,7 @@ if ( isset($_REQUEST['scale']) ) {
$scale = $scale ? $scale : 0;
$imageData = $Event->getImageSrc($frame, $scale, 0);
if ( !$imageData ) {
if (!$imageData) {
ZM\Error("No data found for Event $eid frame $fid");
$imageData = array();
}
@ -92,78 +90,80 @@ xhtmlHeaders(__FILE__, translate('Frame').' - '.$Event->Id().' - '.$Frame->Frame
<div id="page p-0">
<div class="d-flex flex-row justify-content-between px-3 pt-1">
<div id="toolbar" >
<button id="backBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Back') ?>" disabled><i class="fa fa-arrow-left"></i></button>
<button id="refreshBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Refresh') ?>" ><i class="fa fa-refresh"></i></button>
<button id="statsBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Stats') ?>" ><i class="fa fa-info"></i></button>
<button id="statsViewBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Stats').' '.translate('View') ?>" ><i class="fa fa-table"></i></button>
<button type="button" id="backBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Back') ?>" disabled><i class="fa fa-arrow-left"></i></button>
<button type="button" id="refreshBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Refresh') ?>" ><i class="fa fa-refresh"></i></button>
<button type="button" id="statsBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Stats') ?>" ><i class="fa fa-info"></i></button>
<button type="button" id="statsViewBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Stats').' '.translate('View') ?>" ><i class="fa fa-table"></i></button>
</div>
<h2><?php echo translate('Frame') ?> <?php echo $Event->Id().'-'.$Frame->FrameId().' ('.$Frame->Score().')' ?></h2>
<form>
<div id="scaleControl"><label for="scale"><?php echo translate('Scale') ?></label><?php echo htmlSelect('scale', $scales, $scale, array('data-on-change'=>'changeScale','id'=>'scale')); ?></div>
<div id="scaleControl">
<label for="scale"><?php echo translate('Scale') ?></label>
<?php echo htmlSelect('scale', $scales, $scale, array('data-on-change'=>'changeScale','id'=>'scale')); ?>
</div>
<input type="hidden" name="base_width" id="base_width" value="<?php echo $Event->Width(); ?>"/>
<input type="hidden" name="base_height" id="base_height" value="<?php echo $Event->Height(); ?>"/>
</form>
</div>
<div id="content" class="d-flex flex-row justify-content-center">
<table id="frameStatsTable" class="table-sm table-borderless pr-3">
<!-- FRAME STATISTICS POPULATED BY AJAX -->
</table>
<div>
<p id="image">
<?php if ( $imageData['hasAnalImage'] ) {
echo sprintf('<a href="?view=frame&amp;eid=%d&amp;fid=%d&scale=%d&amp;show=%s">', $Event->Id(), $Frame->FrameId(), $scale, ( $show=='anal'?'capt':'anal' ) );
} ?>
<div id="content" class="d-flex flex-row justify-content-center">
<table id="frameStatsTable" class="table-sm table-borderless pr-3">
<!-- FRAME STATISTICS POPULATED BY AJAX -->
</table>
<div>
<p id="image">
<?php
if ( $imageData['hasAnalImage'] ) {
echo sprintf('<a href="?view=frame&amp;eid=%d&amp;fid=%d&scale=%d&amp;show=%s">', $Event->Id(), $Frame->FrameId(), $scale, ( $show=='anal'?'capt':'anal' ) );
}
?>
<img id="frameImg"
src="<?php echo validHtmlStr($Frame->getImageSrc($show=='anal'?'analyse':'capture')) ?>"
width="<?php echo reScale($Event->Width(), $Monitor->DefaultScale(), $scale) ?>"
height="<?php echo reScale( $Event->Height(), $Monitor->DefaultScale(), $scale ) ?>"
height="<?php echo reScale($Event->Height(), $Monitor->DefaultScale(), $scale) ?>"
alt="<?php echo $Frame->EventId().'-'.$Frame->FrameId() ?>"
class="<?php echo $imageData['imageClass'] ?>"
/>
<?php if ( $imageData['hasAnalImage'] ) { ?></a><?php } ?>
</p>
<?php
if ($imageData['hasAnalImage']) { ?></a><?php } ?>
</p>
<?php
$frame_url_base = '?view=frame&amp;eid='.$Event->Id().'&amp;scale='.$scale.'&amp;show='.$show.'&amp;fid=';
?>
<p id="controls">
<a id="firstLink" <?php echo (( $Frame->FrameId() > 1 ) ? 'href="'.$frame_url_base.$firstFid.'" class="btn-primary"' : 'class="btn-primary disabled"') ?>><?php echo translate('First') ?></a>
<a id="prevLink" <?php echo ( $Frame->FrameId() > 1 ) ? 'href="'.$frame_url_base.$prevFid.'" class="btn-primary"' : 'class="btn-primary disabled"' ?>><?php echo translate('Prev') ?></a>
<a id="nextLink" <?php echo ( $Frame->FrameId() < $maxFid ) ? 'href="'.$frame_url_base.$nextFid.'" class="btn-primary"' : 'class="btn-primary disabled"' ?>><?php echo translate('Next') ?></a>
<a id="lastLink" <?php echo ( $Frame->FrameId() < $maxFid ) ? 'href="'.$frame_url_base.$lastFid .'" class="btn-primary"' : 'class="btn-primary disabled"' ?>><?php echo translate('Last') ?></a>
</p>
<p id="controls">
<a id="firstLink" <?php echo (( $Frame->FrameId() > 1 ) ? 'href="'.$frame_url_base.$firstFid.'" class="btn-primary"' : 'class="btn-primary disabled"') ?>><?php echo translate('First') ?></a>
<a id="prevLink" <?php echo ( $Frame->FrameId() > 1 ) ? 'href="'.$frame_url_base.$prevFid.'" class="btn-primary"' : 'class="btn-primary disabled"' ?>><?php echo translate('Prev') ?></a>
<a id="nextLink" <?php echo ( $Frame->FrameId() < $maxFid ) ? 'href="'.$frame_url_base.$nextFid.'" class="btn-primary"' : 'class="btn-primary disabled"' ?>><?php echo translate('Next') ?></a>
<a id="lastLink" <?php echo ( $Frame->FrameId() < $maxFid ) ? 'href="'.$frame_url_base.$lastFid .'" class="btn-primary"' : 'class="btn-primary disabled"' ?>><?php echo translate('Last') ?></a>
</p>
<?php
if ( file_exists($dImagePath) ) {
if (file_exists($dImagePath)) {
?>
<p id="diagImagePath"><?php echo $dImagePath ?></p>
<p id="diagImage">
<img
src="<?php echo viewImagePath($dImagePath) ?>"
width="<?php echo reScale($Event->Width(), $Monitor->DefaultScale(), $scale) ?>"
height="<?php echo reScale($Event->Height(), $Monitor->DefaultScale(), $scale) ?>"
class="<?php echo $imageData['imageClass'] ?>"
/>
</p>
<p id="diagImagePath"><?php echo $dImagePath ?></p>
<p id="diagImage">
<img
src="<?php echo viewImagePath($dImagePath) ?>"
width="<?php echo reScale($Event->Width(), $Monitor->DefaultScale(), $scale) ?>"
height="<?php echo reScale($Event->Height(), $Monitor->DefaultScale(), $scale) ?>"
class="<?php echo $imageData['imageClass'] ?>"
/>
</p>
<?php
}
if ( file_exists($rImagePath) ) {
if (file_exists($rImagePath)) {
?>
<p id="refImagePath"><?php echo $rImagePath ?></p>
<p id="refImage">
<img
src="<?php echo viewImagePath($rImagePath) ?>"
width="<?php echo reScale($Event->Width(), $Monitor->DefaultScale(), $scale) ?>"
height="<?php echo reScale($Event->Height(), $Monitor->DefaultScale(), $scale) ?>"
class="<?php echo $imageData['imageClass'] ?>"
/>
</p>
</div>
<p id="refImagePath"><?php echo $rImagePath ?></p>
<p id="refImage">
<img
src="<?php echo viewImagePath($rImagePath) ?>"
width="<?php echo reScale($Event->Width(), $Monitor->DefaultScale(), $scale) ?>"
height="<?php echo reScale($Event->Height(), $Monitor->DefaultScale(), $scale) ?>"
class="<?php echo $imageData['imageClass'] ?>"
/>
</p>
</div>
<?php } ?>
</div>
</div>

View File

@ -167,7 +167,6 @@ function submitToExport(element) {
}
function submitAction(button) {
console.log(button.value);
var form = button.form;
form.elements['action'].value = button.value;
form.submit();
@ -175,7 +174,6 @@ function submitAction(button) {
function deleteFilter(element) {
var form = element.form;
console.log(form);
if (confirm(deleteSavedFilterString+" '"+form.elements['filter[Name]'].value+"'?")) {
form.elements['action'].value = 'delete';
form.submit();
@ -384,7 +382,6 @@ function debugFilter() {
}
function manageModalBtns(id) {
console.log(id);
// Manage the CANCEL modal button
var cancelBtn = document.getElementById(id+"CancelBtn");
if ( cancelBtn ) {

View File

@ -12,10 +12,10 @@ function changeScale() {
last: $j('#lastLink')
};
if ( img ) {
if (img) {
var baseWidth = $j('#base_width').val();
var baseHeight = $j('#base_height').val();
if ( ! parseInt(scale) ) {
if (!parseInt(scale)) {
var newSize = scaleToFit(baseWidth, baseHeight, img, $j('#controls'));
newWidth = newSize.width;
newHeight = newSize.height;
@ -30,7 +30,7 @@ function changeScale() {
}
setCookie('zmWatchScale', scale, 3600);
$j.each(controlsLinks, function(k, anchor) { //Make frames respect scale choices
if ( anchor ) {
if (anchor) {
anchor.prop('href', anchor.prop('href').replace(/scale=.*&/, 'scale=' + scale + '&'));
}
});
@ -39,11 +39,11 @@ function changeScale() {
onStatsResize(newWidth);
}
function getFrmStatsCookie() {
function getFrameStatsCookie() {
var cookie = 'zmFrameStats';
var stats = getCookie(cookie);
if ( !stats ) {
if (!stats) {
stats = 'on';
setCookie(cookie, stats, 10*365);
}
@ -53,29 +53,33 @@ function getFrmStatsCookie() {
function getStat(params) {
$j.getJSON(thisUrl + '?view=request&request=stats&raw=true', params)
.done(function(data) {
var stat = data.raw;
var stats = data.raw;
$j('#frameStatsTable').empty().append('<tbody>');
$j.each( statHeaderStrings, function( key ) {
var th = $j('<th>').addClass('text-right').text(statHeaderStrings[key]);
var tdString;
for (const stat of stats) {
$j.each(statHeaderStrings, function(key) {
var th = $j('<th>').addClass('text-right').text(statHeaderStrings[key]);
var tdString;
switch (stat ? key : 'n/a') {
case 'FrameId':
tdString = '<a href="?view=stats&amp;eid=' + params.eid + '&amp;fid=' + params.fid + '">' + stat[key] + '</a>';
break;
case 'n/a':
tdString = 'n/a';
break;
default:
tdString = stat[key];
}
switch (stat ? key : 'n/a') {
case 'FrameId':
case 'EventId':
//tdString = '<a href="?view=stats&amp;eid=' + params.eid + '&amp;fid=' + params.fid + '">' + stat[key] + '</a>';
break;
case 'n/a':
tdString = 'n/a';
break;
default:
tdString = stat[key];
}
var td = $j('<td>').html(tdString);
var row = $j('<tr>').append(th, td);
var td = $j('<td>').html(tdString);
var row = $j('<tr>').append(th, td);
$j('#frameStatsTable tbody').append(row);
});
$j('#frameStatsTable tbody').append(row);
});
} // end foreach stat
})
.fail(logAjaxFail);
}
@ -85,16 +89,16 @@ function onStatsResize(vidwidth) {
var width = $j(window).width() - vidwidth;
// Hide the stats table if we have run out of room to show it properly
if ( width < minWidth ) {
if (width < minWidth) {
statsBtn.prop('disabled', true);
if ( table.is(':visible') ) {
if (table.is(':visible')) {
table.toggle(false);
wasHidden = true;
}
// Show the stats table if we hid it previously and sufficient room becomes available
} else if ( width >= minWidth ) {
} else if (width >= minWidth) {
statsBtn.prop('disabled', false);
if ( !table.is(':visible') && wasHidden ) {
if (!table.is(':visible') && wasHidden) {
table.toggle(true);
wasHidden = false;
}
@ -102,7 +106,7 @@ function onStatsResize(vidwidth) {
}
function initPage() {
if ( scale == '0' || scale == 'auto' ) changeScale();
if (scale == '0' || scale == 'auto') changeScale();
// Don't enable the back button if there is no previous zm page to go back to
backBtn.prop('disabled', !document.referrer.length);
@ -125,7 +129,7 @@ function initPage() {
var cookie = 'zmFrameStats';
// Toggle the visiblity of the stats table and write an appropriate cookie
if ( table.is(':visible') ) {
if (table.is(':visible')) {
setCookie(cookie, 'off', 10*365);
table.toggle(false);
} else {
@ -143,7 +147,7 @@ function initPage() {
// Load the frame stats
getStat({eid: eid, fid: fid});
if ( getFrmStatsCookie() != 'on' ) {
if (getFrameStatsCookie() != 'on') {
table.toggle(false);
} else {
onStatsResize($j('#base_width').val() * scale / SCALE_BASE);