Merge branch 'storageareas' of github.com:connortechnology/ZoneMinder into storageareas

This commit is contained in:
Isaac Connor 2019-05-08 06:06:28 -04:00
commit 4c8a29e8d3
4 changed files with 54 additions and 49 deletions

View File

@ -488,21 +488,21 @@ MAIN: while( $loop ) {
my $monitor_links; my $monitor_links;
foreach my $link ( glob('*') ) { foreach my $link ( glob('*') ) {
next if ( !-l $link ); next if !-l $link;
next if ( -e $link ); next if -e $link;
aud_print( "Filesystem monitor link '$link' does not point to valid monitor directory" ); aud_print("Filesystem monitor link '$link' does not point to valid monitor directory");
if ( confirm() ) { if ( confirm() ) {
( $link ) = ( $link =~ /^(.*)$/ ); # De-taint ( $link ) = ( $link =~ /^(.*)$/ ); # De-taint
my $command = qq`rm "$link"`; my $command = qq`rm "$link"`;
executeShellCommand( $command ); executeShellCommand($command);
$cleaned = 1; $cleaned = 1;
} }
} } # end foreach monitor link
} # end foreach Storage Area } # end foreach Storage Area
if ( $cleaned ) { if ( $cleaned ) {
Debug("Events were deleted, starting again."); Debug('Events were deleted, starting again.');
redo MAIN; redo MAIN;
} }
@ -559,8 +559,8 @@ EVENT: while ( my ( $db_event, $age ) = each( %$db_events ) ) {
Warning("Event $$Event{Id} is Archived. Taking no further action on it."); Warning("Event $$Event{Id} is Archived. Taking no further action on it.");
next; next;
} }
if ( ! $Event->StartTime() ) { if ( !$Event->StartTime() ) {
Info("Event $$Event{Id} has no start time."); aud_print("Event $$Event{Id} has no start time.");
if ( confirm() ) { if ( confirm() ) {
$Event->delete(); $Event->delete();
$cleaned = 1; $cleaned = 1;
@ -569,7 +569,7 @@ EVENT: while ( my ( $db_event, $age ) = each( %$db_events ) ) {
} }
if ( ! $Event->EndTime() ) { if ( ! $Event->EndTime() ) {
if ( $age > $Config{ZM_AUDIT_MIN_AGE} ) { if ( $age > $Config{ZM_AUDIT_MIN_AGE} ) {
Info("Event $$Event{Id} has no end time and is $age seconds old. deleting it."); aud_print("Event $$Event{Id} has no end time and is $age seconds old. Deleting it.");
if ( confirm() ) { if ( confirm() ) {
$Event->delete(); $Event->delete();
$cleaned = 1; $cleaned = 1;
@ -578,7 +578,7 @@ EVENT: while ( my ( $db_event, $age ) = each( %$db_events ) ) {
} }
} }
if ( $Event->check_for_in_filesystem() ) { if ( $Event->check_for_in_filesystem() ) {
Debug("Database event $$Event{Id} apparently exists at " . $Event->Path() ); Debug("Database event $$Event{Id} apparently exists at " . $Event->Path());
} else { } else {
if ( $age > $Config{ZM_AUDIT_MIN_AGE} ) { if ( $age > $Config{ZM_AUDIT_MIN_AGE} ) {
aud_print("Database event '$db_monitor/$db_event' does not exist at " . $Event->Path().' in filesystem, deleting'); aud_print("Database event '$db_monitor/$db_event' does not exist at " . $Event->Path().' in filesystem, deleting');
@ -587,14 +587,14 @@ EVENT: while ( my ( $db_event, $age ) = each( %$db_events ) ) {
$cleaned = 1; $cleaned = 1;
} }
} else { } else {
aud_print( "Database event '".$Event->Path()." monitor:$db_monitor event:$db_event' does not exist in filesystem but too young to delete age: $age > MIN $Config{ZM_AUDIT_MIN_AGE}.\n" ); aud_print("Database event '".$Event->Path()." monitor:$db_monitor event:$db_event' does not exist in filesystem but too young to delete age: $age > MIN $Config{ZM_AUDIT_MIN_AGE}.");
} }
} # end if exists in filesystem } # end if exists in filesystem
} else { } else {
Debug("Found fs event for id $db_event, $age seconds old at " . $$fs_events{$db_event}->Path()); Debug("Found fs event for id $db_event, $age seconds old at " . $$fs_events{$db_event}->Path());
my $Event = ZoneMinder::Event->find_one( Id=>$db_event ); my $Event = ZoneMinder::Event->find_one( Id=>$db_event );
if ( $Event and ! $Event->check_for_in_filesystem() ) { if ( $Event and ! $Event->check_for_in_filesystem() ) {
Warning("Not found at " . $Event->Path() . ' was found at ' . $$fs_events{$db_event}->Path() ); Warning('Not found at ' . $Event->Path() . ' was found at ' . $$fs_events{$db_event}->Path());
Warning($Event->to_string()); Warning($Event->to_string());
Warning($$fs_events{$db_event}->to_string()); Warning($$fs_events{$db_event}->to_string());
$$Event{Scheme} = '' if ! defined $$Event{Scheme}; $$Event{Scheme} = '' if ! defined $$Event{Scheme};
@ -622,7 +622,7 @@ EVENT: while ( my ( $db_event, $age ) = each( %$db_events ) ) {
} # foreach db_event } # foreach db_event
} # end foreach db_monitor } # end foreach db_monitor
if ( $cleaned ) { if ( $cleaned ) {
Debug("Have done some cleaning, restarting."); Debug('Have done some cleaning, restarting.');
redo MAIN; redo MAIN;
} }
@ -904,25 +904,25 @@ FROM Frames WHERE EventId=?';
Monitors.MonthEvents = E.MonthEvents, Monitors.MonthEvents = E.MonthEvents,
Monitors.MonthEventDiskSpace = E.MonthEventDiskSpace Monitors.MonthEventDiskSpace = E.MonthEventDiskSpace
`; `;
my $eventcounts_hour_sth = $dbh->prepare_cached( $eventcounts_hour_sql ); my $eventcounts_hour_sth = $dbh->prepare_cached($eventcounts_hour_sql);
my $eventcounts_day_sth = $dbh->prepare_cached( $eventcounts_day_sql ); my $eventcounts_day_sth = $dbh->prepare_cached($eventcounts_day_sql);
my $eventcounts_week_sth = $dbh->prepare_cached( $eventcounts_week_sql ); my $eventcounts_week_sth = $dbh->prepare_cached($eventcounts_week_sql);
my $eventcounts_month_sth = $dbh->prepare_cached( $eventcounts_month_sql ); my $eventcounts_month_sth = $dbh->prepare_cached($eventcounts_month_sql);
$eventcounts_hour_sth->execute( ) or Error( "Can't execute: ".$eventcounts_sth->errstr() ); $eventcounts_hour_sth->execute() or Error("Can't execute: ".$eventcounts_sth->errstr());
$eventcounts_day_sth->execute( ) or Error( "Can't execute: ".$eventcounts_sth->errstr() ); $eventcounts_day_sth->execute() or Error("Can't execute: ".$eventcounts_sth->errstr());
$eventcounts_week_sth->execute( ) or Error( "Can't execute: ".$eventcounts_sth->errstr() ); $eventcounts_week_sth->execute() or Error("Can't execute: ".$eventcounts_sth->errstr());
$eventcounts_month_sth->execute( ) or Error( "Can't execute: ".$eventcounts_sth->errstr() ); $eventcounts_month_sth->execute() or Error("Can't execute: ".$eventcounts_sth->errstr());
sleep( $Config{ZM_AUDIT_CHECK_INTERVAL} ) if $continuous; sleep($Config{ZM_AUDIT_CHECK_INTERVAL}) if $continuous;
}; };
Term(); Term();
sub aud_print { sub aud_print {
my $string = shift; my $string = shift;
if ( ! $continuous ) { if ( !$continuous ) {
print( $string ); print($string);
} else { } else {
Info( $string ); Info($string);
} }
} }
@ -932,13 +932,13 @@ sub confirm {
my $yesno = 0; my $yesno = 0;
if ( $report ) { if ( $report ) {
print( "\n" ); print("\n");
} elsif ( $interactive ) { } elsif ( $interactive ) {
print( ", $prompt Y/n/q: " ); print(", $prompt Y/n/q: ");
my $char = <>; my $char = <>;
chomp( $char ); chomp($char);
if ( $char eq 'q' ) { if ( $char eq 'q' ) {
exit( 0 ); exit(0);
} }
if ( !$char ) { if ( !$char ) {
$char = 'y'; $char = 'y';
@ -946,13 +946,13 @@ sub confirm {
$yesno = ( $char =~ /[yY]/ ); $yesno = ( $char =~ /[yY]/ );
} else { } else {
if ( !$continuous ) { if ( !$continuous ) {
print( ", $action\n" ); print(", $action\n");
} else { } else {
Info( $action ); Info($action);
} }
$yesno = 1; $yesno = 1;
} }
return( $yesno ); return $yesno;
} }
sub deleteSwapImage { sub deleteSwapImage {

View File

@ -1729,6 +1729,11 @@ bool Monitor::Analyse() {
); );
closeEvent(); closeEvent();
event = new Event(this, *timestamp, cause, noteSetMap); event = new Event(this, *timestamp, cause, noteSetMap);
shared_data->last_event = event->Id();
//set up video store data
snprintf(video_store_data->event_file, sizeof(video_store_data->event_file), "%s", event->getEventFile());
video_store_data->recording = event->StartTime();
} }
} // end if event } // end if event

View File

@ -44,7 +44,7 @@ class Storage {
} }
public function Path() { public function Path() {
if ( isset( $this->{'Path'} ) and ( $this->{'Path'} != '' ) ) { if ( isset($this->{'Path'}) and ( $this->{'Path'} != '' ) ) {
return $this->{'Path'}; return $this->{'Path'};
} else if ( ! isset($this->{'Id'}) ) { } else if ( ! isset($this->{'Id'}) ) {
$path = ZM_DIR_EVENTS; $path = ZM_DIR_EVENTS;
@ -58,7 +58,7 @@ class Storage {
return $this->{'Name'}; return $this->{'Name'};
} }
public function Name() { public function Name() {
if ( isset( $this->{'Name'} ) and ( $this->{'Name'} != '' ) ) { if ( isset($this->{'Name'}) and ( $this->{'Name'} != '' ) ) {
return $this->{'Name'}; return $this->{'Name'};
} else if ( ! isset($this->{'Id'}) ) { } else if ( ! isset($this->{'Id'}) ) {
return 'Default'; return 'Default';
@ -73,7 +73,7 @@ class Storage {
if ( array_key_exists($fn, $this) ) if ( array_key_exists($fn, $this) )
return $this->{$fn}; return $this->{$fn};
if ( array_key_exists( $fn, $this->defaults ) ) if ( array_key_exists($fn, $this->defaults) )
return $this->defaults{$fn}; return $this->defaults{$fn};
$backTrace = debug_backtrace(); $backTrace = debug_backtrace();
@ -96,7 +96,7 @@ class Storage {
$results = Storage::find($parameters, $options); $results = Storage::find($parameters, $options);
if ( count($results) > 1 ) { if ( count($results) > 1 ) {
Error("Storage Returned more than 1"); Error('Storage Returned more than 1');
return $results[0]; return $results[0];
} else if ( count($results) ) { } else if ( count($results) ) {
return $results[0]; return $results[0];
@ -116,7 +116,7 @@ class Storage {
$fields[] = $field.' IS NULL'; $fields[] = $field.' IS NULL';
} else if ( is_array($value) ) { } else if ( is_array($value) ) {
$func = function(){return '?';}; $func = function(){return '?';};
$fields[] = $field.' IN ('.implode(',', array_map($func, $value)). ')'; $fields[] = $field.' IN ('.implode(',', array_map($func, $value)).')';
$values += $value; $values += $value;
} else { } else {
@ -165,11 +165,11 @@ class Storage {
$total = $this->disk_total_space(); $total = $this->disk_total_space();
if ( ! $total ) { if ( ! $total ) {
Error('disk_total_space returned false for ' . $path ); Error('disk_total_space returned false for ' . $path);
return 0; return 0;
} }
$used = $this->disk_used_space(); $used = $this->disk_used_space();
$usage = round( ($used / $total) * 100); $usage = round(($used / $total) * 100);
//Logger::Debug("Used $usage = round( ( $used / $total ) * 100 )"); //Logger::Debug("Used $usage = round( ( $used / $total ) * 100 )");
return $usage; return $usage;
} }
@ -208,7 +208,7 @@ class Storage {
public function event_disk_space() { public function event_disk_space() {
# This isn't a function like this in php, so we have to add up the space used in each event. # This isn't a function like this in php, so we have to add up the space used in each event.
if ( (! array_key_exists('DiskSpace', $this)) or (!$this->{'DiskSpace'}) ) { if ( (! array_key_exists('DiskSpace', $this)) or (!$this->{'DiskSpace'}) ) {
$used = dbFetchOne('SELECT SUM(DiskSpace) AS DiskSpace FROM Events WHERE StorageId=? AND DiskSpace IS NOT NULL', 'DiskSpace', array($this->Id()) ); $used = dbFetchOne('SELECT SUM(DiskSpace) AS DiskSpace FROM Events WHERE StorageId=? AND DiskSpace IS NOT NULL', 'DiskSpace', array($this->Id()));
foreach ( Event::find(array('StorageId'=>$this->Id(), 'DiskSpace'=>null)) as $Event ) { foreach ( Event::find(array('StorageId'=>$this->Id(), 'DiskSpace'=>null)) as $Event ) {
$Event->Storage($this); // Prevent further db hit $Event->Storage($this); // Prevent further db hit
@ -221,7 +221,7 @@ class Storage {
public function Server() { public function Server() {
if ( ! array_key_exists('Server',$this) ) { if ( ! array_key_exists('Server',$this) ) {
$this->{'Server'}= new Server( $this->{'ServerId'} ); $this->{'Server'}= new Server($this->{'ServerId'});
} }
return $this->{'Server'}; return $this->{'Server'};
} }
@ -239,5 +239,5 @@ class Storage {
} }
return json_encode($json); return json_encode($json);
} }
} } // end class Storage
?> ?>

View File

@ -353,18 +353,18 @@ foreach ( array_map('basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDI
<input type="checkbox" id="<?php echo $name ?>" name="newConfig[<?php echo $name ?>]" value="1"<?php if ( $value['Value'] ) { ?> checked="checked"<?php } ?><?php echo $canEdit?'':' disabled="disabled"' ?>/> <input type="checkbox" id="<?php echo $name ?>" name="newConfig[<?php echo $name ?>]" value="1"<?php if ( $value['Value'] ) { ?> checked="checked"<?php } ?><?php echo $canEdit?'':' disabled="disabled"' ?>/>
<?php <?php
} elseif ( is_array( $value['Hint'] ) ) { } elseif ( is_array( $value['Hint'] ) ) {
echo htmlSelect( "newConfig[$name]", $value['Hint'], $value['Value'] ); echo htmlSelect("newConfig[$name]", $value['Hint'], $value['Value']);
} elseif ( preg_match( '/\|/', $value['Hint'] ) ) { } elseif ( preg_match('/\|/', $value['Hint']) ) {
?> ?>
<?php <?php
$options = explode( '|', $value['Hint'] ); $options = explode('|', $value['Hint']);
if ( count( $options ) > 3 ) { if ( count($options) > 3 ) {
?> ?>
<select class="form-control" name="newConfig[<?php echo $name ?>]"<?php echo $canEdit?'':' disabled="disabled"' ?>> <select class="form-control" name="newConfig[<?php echo $name ?>]"<?php echo $canEdit?'':' disabled="disabled"' ?>>
<?php <?php
foreach ( $options as $option ) { foreach ( $options as $option ) {
if ( preg_match( '/^([^=]+)=(.+)$/', $option, $matches ) ) { if ( preg_match('/^([^=]+)=(.+)$/', $option, $matches) ) {
$optionLabel = $matches[1]; $optionLabel = $matches[1];
$optionValue = $matches[2]; $optionValue = $matches[2];
} else { } else {
@ -379,7 +379,7 @@ foreach ( array_map('basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDI
<?php <?php
} else { } else {
foreach ( $options as $option ) { foreach ( $options as $option ) {
if ( preg_match( '/^([^=]+)=(.+)$/', $option ) ) { if ( preg_match('/^([^=]+)=(.+)$/', $option) ) {
$optionLabel = $matches[1]; $optionLabel = $matches[1];
$optionValue = $matches[2]; $optionValue = $matches[2];
} else { } else {
@ -387,7 +387,7 @@ foreach ( array_map('basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDI
} }
?> ?>
<label> <label>
<input type="radio" id="<?php echo $name.'_'.preg_replace( '/[^a-zA-Z0-9]/', '', $optionValue ) ?>" name="newConfig[<?php echo $name ?>]" value="<?php echo $optionValue ?>"<?php if ( $value['Value'] == $optionValue ) { ?> checked="checked"<?php } ?><?php echo $canEdit?'':' disabled="disabled"' ?>/> <input type="radio" id="<?php echo $name.'_'.preg_replace('/[^a-zA-Z0-9]/', '', $optionValue) ?>" name="newConfig[<?php echo $name ?>]" value="<?php echo $optionValue ?>"<?php if ( $value['Value'] == $optionValue ) { ?> checked="checked"<?php } ?><?php echo $canEdit?'':' disabled="disabled"' ?>/>
<?php echo htmlspecialchars($optionLabel) ?> <?php echo htmlspecialchars($optionLabel) ?>
</label> </label>
<?php <?php