From 924841ae719a7fd90e714178f28498ea9d107a34 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 17 Apr 2020 10:26:03 -0400 Subject: [PATCH 01/10] Merge pull request #2913 from connortechnology/fix_monitor_loading Fix monitor loading --- src/zm_monitor.cpp | 46 ++++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 2f0e4826b..2a4c46724 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -1815,7 +1815,7 @@ void Monitor::Reload() { "`AlarmFrameCount`, `SectionLength`, `MinSectionLength`, `FrameSkip`, " "`MotionFrameSkip`, `AnalysisFPSLimit`, `AnalysisUpdateDelay`, `MaxFPS`, `AlarmMaxFPS`, " "`FPSReportInterval`, `RefBlendPerc`, `AlarmRefBlendPerc`, `TrackMotion`, " - "`SignalCheckColour` FROM `Monitors` WHERE `Id` = '%d'", id); + "`SignalCheckPoints`, `SignalCheckColour` FROM `Monitors` WHERE `Id` = '%d'", id); zmDbRow *row = zmDbFetchOne(sql); if ( !row ) { @@ -1861,13 +1861,8 @@ void Monitor::Reload() { alarm_ref_blend_perc = atoi(dbrow[index++]); track_motion = atoi(dbrow[index++]); - signal_check_points = dbrow[index]?atoi(dbrow[index]):0;index++; - - if ( dbrow[index][0] == '#' ) - signal_check_colour = strtol(dbrow[index]+1,0,16); - else - signal_check_colour = strtol(dbrow[index],0,16); - index++; + signal_check_points = dbrow[index]?atoi(dbrow[index]):0; index++; + signal_check_colour = strtol(dbrow[index][0]=='#'?dbrow[index]+1:dbrow[index], 0, 16); index++; shared_data->state = state = IDLE; shared_data->alarm_x = shared_data->alarm_y = -1; @@ -1880,7 +1875,7 @@ void Monitor::Reload() { } // end if row ReloadZones(); -} // end void Monitor::Reload() +} // end void Monitor::Reload() void Monitor::ReloadZones() { Debug(1, "Reloading zones for monitor %s", name); @@ -2059,20 +2054,21 @@ int Monitor::LoadFfmpegMonitors(const char *file, Monitor **&monitors, Purpose p } // end int Monitor::LoadFfmpegMonitors #endif // HAVE_LIBAVFORMAT -/* - std::string load_monitor_sql = - "SELECT Id, Name, ServerId, StorageId, Type, Function+0, Enabled, LinkedMonitors, " - "AnalysisFPSLimit, AnalysisUpdateDelay, MaxFPS, AlarmMaxFPS," - "Device, Channel, Format, V4LMultiBuffer, V4LCapturesPerFrame, " // V4L Settings - "Protocol, Method, Options, User, Pass, Host, Port, Path, Width, Height, Colours, Palette, Orientation+0, Deinterlacing, RTSPDescribe, " - "SaveJPEGs, VideoWriter, EncoderParameters, -"OutputCodec, Encoder, OutputContainer," -" RecordAudio, " - "Brightness, Contrast, Hue, Colour, " - "EventPrefix, LabelFormat, LabelX, LabelY, LabelSize," - "ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, StreamReplayBuffer, AlarmFrameCount, " - "SectionLength, MinSectionLength, FrameSkip, MotionFrameSkip, " - "FPSReportInterval, RefBlendPerc, AlarmRefBlendPerc, TrackMotion, Exif, SignalCheckColour FROM Monitors"; +/* For reference +std::string load_monitor_sql = +"SELECT `Id`, `Name`, `ServerId`, `StorageId`, `Type`, `Function`+0, `Enabled`, `LinkedMonitors`, " +"`AnalysisFPSLimit`, `AnalysisUpdateDelay`, `MaxFPS`, `AlarmMaxFPS`," +"`Device`, `Channel`, `Format`, `V4LMultiBuffer`, `V4LCapturesPerFrame`, " // V4L Settings +"`Protocol`, `Method`, `Options`, `User`, `Pass`, `Host`, `Port`, `Path`, `Width`, `Height`, `Colours`, `Palette`, `Orientation`+0, `Deinterlacing`, " +"`DecoderHWAccelName`, `DecoderHWAccelDevice`, `RTSPDescribe`, " +"`SaveJPEGs`, `VideoWriter`, `EncoderParameters`, " +//" OutputCodec, Encoder, OutputContainer, " +"`RecordAudio`, " +"`Brightness`, `Contrast`, `Hue`, `Colour`, " +"`EventPrefix`, `LabelFormat`, `LabelX`, `LabelY`, `LabelSize`," +"`ImageBufferCount`, `WarmupCount`, `PreEventCount`, `PostEventCount`, `StreamReplayBuffer`, `AlarmFrameCount`, " +"`SectionLength`, `MinSectionLength`, `FrameSkip`, `MotionFrameSkip`, " +"`FPSReportInterval`, `RefBlendPerc`, `AlarmRefBlendPerc`, `TrackMotion`, `Exif`, `SignalCheckPoints`, `SignalCheckColour` FROM `Monitors`"; */ Monitor *Monitor::Load(MYSQL_ROW dbrow, bool load_zones, Purpose purpose) { @@ -2092,8 +2088,6 @@ Monitor *Monitor::Load(MYSQL_ROW dbrow, bool load_zones, Purpose purpose) { double capture_max_fps = dbrow[col] ? atof(dbrow[col]) : 0.0; col++; double capture_delay = ( capture_max_fps > 0.0 ) ? int(DT_PREC_3/capture_max_fps) : 0; - - Debug(1,"Capture Delay!? %.3f", capture_delay); unsigned int alarm_capture_delay = (dbrow[col]&&atof(dbrow[col])>0.0)?int(DT_PREC_3/atof(dbrow[col])):0; col++; const char *device = dbrow[col]; col++; @@ -2166,9 +2160,9 @@ Monitor *Monitor::Load(MYSQL_ROW dbrow, bool load_zones, Purpose purpose) { int ref_blend_perc = atoi(dbrow[col]); col++; int alarm_ref_blend_perc = atoi(dbrow[col]); col++; int track_motion = atoi(dbrow[col]); col++; + bool embed_exif = (*dbrow[col] != '0'); col++; int signal_check_points = dbrow[col] ? atoi(dbrow[col]) : 0;col++; int signal_check_color = strtol(dbrow[col][0] == '#' ? dbrow[col]+1 : dbrow[col], 0, 16); col++; - bool embed_exif = (*dbrow[col] != '0'); col++; Camera *camera = 0; if ( type == "Local" ) { From ac017a5c7292dfc161349fbe1d050daa34d89aec Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 17 Apr 2020 09:44:07 -0400 Subject: [PATCH 02/10] Add support for strftimes' %r when converting to moment.js formatting --- web/skins/classic/js/skin.js | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/web/skins/classic/js/skin.js b/web/skins/classic/js/skin.js index 6db2a7a4e..aa04bd4df 100644 --- a/web/skins/classic/js/skin.js +++ b/web/skins/classic/js/skin.js @@ -453,10 +453,37 @@ function convertLabelFormat(LabelFormat, monitorName) { //convert label format from strftime to moment's format (modified from //https://raw.githubusercontent.com/benjaminoakes/moment-strftime/master/lib/moment-strftime.js //added %f and %N below (TODO: add %Q) - var replacements = {"a": 'ddd', "A": 'dddd', "b": 'MMM', "B": 'MMMM', "d": 'DD', "e": 'D', "F": 'YYYY-MM-DD', "H": 'HH', "I": 'hh', "j": 'DDDD', "k": 'H', "l": 'h', "m": 'MM', "M": 'mm', "p": 'A', "S": 'ss', "u": 'E', "w": 'd', "W": 'WW', "y": 'YY', "Y": 'YYYY', "z": 'ZZ', "Z": 'z', 'f': 'SS', 'N': "["+monitorName+"]", '%': '%'}; + var replacements = { + 'a': 'ddd', + 'A': 'dddd', + 'b': 'MMM', + 'B': 'MMMM', + 'd': 'DD', + 'e': 'D', + 'F': 'YYYY-MM-DD', + 'H': 'HH', + 'I': 'hh', + 'j': 'DDDD', + 'k': 'H', + 'l': 'h', + 'm': 'MM', + 'M': 'mm', + 'p': 'A', + 'r': 'hh:mm:ss A', + 'S': 'ss', + 'u': 'E', + 'w': 'd', + 'W': 'WW', + 'y': 'YY', + 'Y': 'YYYY', + 'z': 'ZZ', + 'Z': 'z', + 'f': 'SS', + 'N': '['+monitorName+']', + '%': '%'}; var momentLabelFormat = Object.keys(replacements).reduce(function(momentFormat, key) { var value = replacements[key]; - return momentFormat.replace("%" + key, value); + return momentFormat.replace('%' + key, value); }, LabelFormat); return momentLabelFormat; } @@ -467,7 +494,7 @@ function addVideoTimingTrack(video, LabelFormat, monitorName, duration, startTim var labelFormat = convertLabelFormat(LabelFormat, monitorName); startTime = moment(startTime); - for (var i = 0; i <= duration; i++) { + for ( var i = 0; i <= duration; i++ ) { cues[i] = {id: i, index: i, startTime: i, endTime: i+1, text: startTime.format(labelFormat)}; startTime.add(1, 's'); } From 8fd32b8f1d98934771fa1f0881e1bdbdf0f2495f Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 24 Feb 2020 21:04:40 -0700 Subject: [PATCH 03/10] add area definition to zone creation via API --- docs/api.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/api.rst b/docs/api.rst index 76eadcaa3..23effc0b7 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -482,6 +482,7 @@ Create a Zone &Zone[Units]=Percent\ &Zone[NumCoords]=4\ &Zone[Coords]=0,0 639,0 639,479 0,479\ + &Zone[Area]=307200\ &Zone[AlarmRGB]=16711680\ &Zone[CheckMethod]=Blobs\ &Zone[MinPixelThreshold]=25\ From 3e8de7dd6c9ccfb730fae0f14d552481dce86f5b Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 21 Apr 2020 08:30:42 -0400 Subject: [PATCH 04/10] Move the script include for recaptcha into the view instead of the xhtmlHeaders function. Fixes #2918 --- web/skins/classic/includes/functions.php | 8 ++------ web/skins/classic/views/login.php | 1 + 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/web/skins/classic/includes/functions.php b/web/skins/classic/includes/functions.php index 3042a5488..05c746691 100644 --- a/web/skins/classic/includes/functions.php +++ b/web/skins/classic/includes/functions.php @@ -1,6 +1,6 @@ - - diff --git a/web/skins/classic/views/login.php b/web/skins/classic/views/login.php index 76ebeafd8..3b1a9d690 100644 --- a/web/skins/classic/views/login.php +++ b/web/skins/classic/views/login.php @@ -30,6 +30,7 @@ xhtmlHeaders(__FILE__, translate('Login')); && ZM_OPT_USE_GOOG_RECAPTCHA && ZM_OPT_GOOG_RECAPTCHA_SITEKEY && ZM_OPT_GOOG_RECAPTCHA_SECRETKEY) { echo '
'; + echo ''; } ?> From d0e83fcfcbf0a0d0349c8892c8e55715b5aa5d55 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 21 Apr 2020 09:19:29 -0400 Subject: [PATCH 05/10] handle case where g-recaptcha-response is not in the request, due to failure to render the recaptcha --- web/includes/actions/login.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/web/includes/actions/login.php b/web/includes/actions/login.php index 68ca4e604..da1b60ed2 100644 --- a/web/includes/actions/login.php +++ b/web/includes/actions/login.php @@ -29,8 +29,13 @@ if ( ('login' == $action) && isset($_REQUEST['username']) && ( ZM_AUTH_TYPE == ' && defined('ZM_OPT_GOOG_RECAPTCHA_SITEKEY') && ZM_OPT_USE_GOOG_RECAPTCHA && ZM_OPT_GOOG_RECAPTCHA_SECRETKEY - && ZM_OPT_GOOG_RECAPTCHA_SITEKEY ) - { + && ZM_OPT_GOOG_RECAPTCHA_SITEKEY + ) { + if ( !isset($_REQUEST['g-recaptcha-response']) ) { + ZM\Error('reCaptcha authentication failed. No g-recpatcha-response in REQUEST: '); + unset($user); // unset should be ok here because we aren't in a function + return; + } $url = 'https://www.google.com/recaptcha/api/siteverify'; $fields = array ( 'secret' => ZM_OPT_GOOG_RECAPTCHA_SECRETKEY, From 543628d0ee84f903337d9bdcb3b47eacb785501e Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 21 Apr 2020 09:20:04 -0400 Subject: [PATCH 06/10] cleanup, and add missing in the navbar when not logged in which seems to be causing the recaptcha render to fail --- web/skins/classic/includes/functions.php | 34 +++++++++++++----------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/web/skins/classic/includes/functions.php b/web/skins/classic/includes/functions.php index 05c746691..a5e000d3d 100644 --- a/web/skins/classic/includes/functions.php +++ b/web/skins/classic/includes/functions.php @@ -337,33 +337,35 @@ if ( $user and $user['Username'] ) {
  • >
  • >
  • keyboard_arrow_
  • - + + From b384d233ae7287eb98383d9b22dd65bf191579ae Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 21 Apr 2020 09:20:33 -0400 Subject: [PATCH 07/10] add async and defer to recaptcha load --- web/skins/classic/views/login.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/web/skins/classic/views/login.php b/web/skins/classic/views/login.php index 3b1a9d690..296a54887 100644 --- a/web/skins/classic/views/login.php +++ b/web/skins/classic/views/login.php @@ -22,19 +22,17 @@ xhtmlHeaders(__FILE__, translate('Login')); - - '; - echo ''; - } ?> - + + '; +} ?> - From 264ba6525b937cea90f8b8ba0ed5304c8113acd0 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 21 Apr 2020 12:19:18 -0400 Subject: [PATCH 08/10] Remove debug --- web/skins/classic/views/js/monitor.js.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/web/skins/classic/views/js/monitor.js.php b/web/skins/classic/views/js/monitor.js.php index 04fa06dcb..6a6db3ce9 100644 --- a/web/skins/classic/views/js/monitor.js.php +++ b/web/skins/classic/views/js/monitor.js.php @@ -138,11 +138,7 @@ function validateForm( form ) { if ( (form.elements['newMonitor[SaveJPEGs]'].value == '0') && (form.elements['newMonitor[VideoWriter]'].value == '0') ) { warnings[warnings.length] = ""; } -console.log(form.elements['newMonitor[SaveJPEGs]'].value); -console.log(form.elements['newMonitor[VideoWriter]'].value); - } -console.log(warnings); if ( warnings.length ) { if ( !confirm(warnings.join("\n")) ) { return false; From 10d89ed82e0c88e9aad3300a955ce7946f9c575d Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 23 Apr 2020 10:00:11 -0400 Subject: [PATCH 09/10] Spacing, quotes, improve debug messages. --- .../ZoneMinder/lib/ZoneMinder/Memory.pm.in | 10 ++++------ .../lib/ZoneMinder/Memory/Mapped.pm | 20 ++++++++++++------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Memory.pm.in b/scripts/ZoneMinder/lib/ZoneMinder/Memory.pm.in index 53da1659b..13cae4d4b 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Memory.pm.in +++ b/scripts/ZoneMinder/lib/ZoneMinder/Memory.pm.in @@ -301,7 +301,7 @@ sub zmMemVerify { } return !undef; -} +} # end sub zmMemVerify sub zmMemRead { my $monitor = shift; @@ -375,10 +375,8 @@ sub zmMemInvalidate { my $mem_key = zmMemKey($monitor); if ( $mem_key ) { zmMemDetach($monitor); - } else { - Warning('no memkey in zmMemInvalidate'); } -} +} # end sub zmMemInvalidate sub zmMemTidy { zmMemClean(); @@ -504,10 +502,10 @@ sub zmHasAlarmed { my $last_event_id = shift; my ( $state, $last_event ) = zmMemRead($monitor, - ['shared_data:state' ,'shared_data:last_event'] + ['shared_data:state', 'shared_data:last_event'] ); - if ( $state == STATE_ALARM || $state == STATE_ALERT ) { + if ( $state == STATE_ALARM or $state == STATE_ALERT ) { return $last_event; } elsif( $last_event != $last_event_id ) { return $last_event; diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Memory/Mapped.pm b/scripts/ZoneMinder/lib/ZoneMinder/Memory/Mapped.pm index b9a8b6a1c..cb7920913 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Memory/Mapped.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Memory/Mapped.pm @@ -51,7 +51,7 @@ our %EXPORT_TAGS = ( ); push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS; -our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); +our @EXPORT_OK = ( @{ $EXPORT_TAGS{all} } ); our @EXPORT = @EXPORT_OK; @@ -77,17 +77,17 @@ sub zmMemAttach { my ( $monitor, $size ) = @_; if ( !$size ) { - Error("No size passed to zmMemAttach for monitor $$monitor{Id}"); + Error('No size passed to zmMemAttach for monitor '.$$monitor{Id}); return undef; } if ( defined($monitor->{MMapAddr}) ) { - Debug("zmMemAttach already attached at $monitor->{MMapAddr}"); + Debug("zmMemAttach already attached at $monitor->{MMapAddr} for $$monitor{Id}"); return !undef; } my $mmap_file = $Config{ZM_PATH_MAP}.'/zm.mmap.'.$monitor->{Id}; if ( ! -e $mmap_file ) { - Error("Memory map file '$mmap_file' does not exist. zmc might not be running."); + Error("Memory map file '$mmap_file' does not exist in zmMemAttach. zmc might not be running."); return undef; } my $mmap_file_size = -s $mmap_file; @@ -119,18 +119,24 @@ sub zmMemDetach { if ( $monitor->{MMap} ) { if ( ! munmap(${$monitor->{MMap}}) ) { - Warn( "Unable to munmap for monitor $$monitor{Id}\n"); + Warn("Unable to munmap for monitor $$monitor{Id}"); } delete $monitor->{MMap}; + } else { + Warn("No MMap for $$monitor{Id}"); } if ( $monitor->{MMapAddr} ) { delete $monitor->{MMapAddr}; + } else { + Warn("No MMapAddr in $$monitor{Id}"); } if ( $monitor->{MMapHandle} ) { close($monitor->{MMapHandle}); delete $monitor->{MMapHandle}; + } else { + Warn("No MMapHandle in $$monitor{Id}"); } -} +} # end sub zmMemDetach sub zmMemGet { my $monitor = shift; @@ -162,7 +168,7 @@ sub zmMemPut { } sub zmMemClean { - Debug("Removing memory map files"); + Debug('Removing memory map files'); my $mapPath = $Config{ZM_PATH_MAP}.'/zm.mmap.*'; foreach my $mapFile( glob( $mapPath ) ) { ( $mapFile ) = $mapFile =~ /^(.+)$/; From 055c20c3cc9070db5779d2245a561ce9e84dbacb Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 23 Apr 2020 10:23:46 -0400 Subject: [PATCH 10/10] fix eslint --- web/skins/classic/js/skin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/skins/classic/js/skin.js b/web/skins/classic/js/skin.js index aa04bd4df..2c21c0503 100644 --- a/web/skins/classic/js/skin.js +++ b/web/skins/classic/js/skin.js @@ -454,7 +454,7 @@ function convertLabelFormat(LabelFormat, monitorName) { //https://raw.githubusercontent.com/benjaminoakes/moment-strftime/master/lib/moment-strftime.js //added %f and %N below (TODO: add %Q) var replacements = { - 'a': 'ddd', + 'a': 'ddd', 'A': 'dddd', 'b': 'MMM', 'B': 'MMMM',