Merge branch 'master' of github.com:ZoneMinder/ZoneMinder
This commit is contained in:
commit
234a9ce236
|
@ -505,6 +505,20 @@ our @options = (
|
||||||
type => $types{directory},
|
type => $types{directory},
|
||||||
category => "paths",
|
category => "paths",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name => "ZM_DIR_EXPORTS",
|
||||||
|
default => "@ZM_TMPDIR@",
|
||||||
|
description => "Directory where exported archives are stored",
|
||||||
|
help => qqq("
|
||||||
|
This is the path to the exports directory where exported
|
||||||
|
tar.gz and zip archives are stored. By default this points to
|
||||||
|
ZoneMinder's temp folder, which often sits in ram. Since exported
|
||||||
|
archives can potentially become large, it is a good idea to move
|
||||||
|
this folder to some other location on machines with low memory.
|
||||||
|
"),
|
||||||
|
type => $types{directory},
|
||||||
|
category => "paths",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name => "ZM_PATH_ZMS",
|
name => "ZM_PATH_ZMS",
|
||||||
default => "/cgi-bin/nph-zms",
|
default => "/cgi-bin/nph-zms",
|
||||||
|
|
|
@ -106,8 +106,7 @@ if ( $version ) {
|
||||||
print( ZoneMinder::Base::ZM_VERSION . "\n");
|
print( ZoneMinder::Base::ZM_VERSION . "\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
if ( ($report + $interactive + $continuous) > 1 )
|
if ( ($report + $interactive + $continuous) > 1 ) {
|
||||||
{
|
|
||||||
print( STDERR "Error, only one option may be specified\n" );
|
print( STDERR "Error, only one option may be specified\n" );
|
||||||
pod2usage(-exitstatus => -1);
|
pod2usage(-exitstatus => -1);
|
||||||
}
|
}
|
||||||
|
@ -162,32 +161,27 @@ MAIN: while( $loop ) {
|
||||||
$cleaned = 0;
|
$cleaned = 0;
|
||||||
my $res = $monitorSelectSth->execute()
|
my $res = $monitorSelectSth->execute()
|
||||||
or Fatal( "Can't execute: ".$monitorSelectSth->errstr() );
|
or Fatal( "Can't execute: ".$monitorSelectSth->errstr() );
|
||||||
while( my $monitor = $monitorSelectSth->fetchrow_hashref() )
|
while( my $monitor = $monitorSelectSth->fetchrow_hashref() ) {
|
||||||
{
|
|
||||||
Debug( "Found database monitor '$monitor->{Id}'" );
|
Debug( "Found database monitor '$monitor->{Id}'" );
|
||||||
my $db_events = $db_monitors->{$monitor->{Id}} = {};
|
my $db_events = $db_monitors->{$monitor->{Id}} = {};
|
||||||
my $res = $eventSelectSth->execute( $monitor->{Id} )
|
my $res = $eventSelectSth->execute( $monitor->{Id} )
|
||||||
or Fatal( "Can't execute: ".$eventSelectSth->errstr() );
|
or Fatal( "Can't execute: ".$eventSelectSth->errstr() );
|
||||||
while ( my $event = $eventSelectSth->fetchrow_hashref() )
|
while ( my $event = $eventSelectSth->fetchrow_hashref() ) {
|
||||||
{
|
|
||||||
$db_events->{$event->{Id}} = $event->{Age};
|
$db_events->{$event->{Id}} = $event->{Age};
|
||||||
}
|
}
|
||||||
Debug( "Got ".int(keys(%$db_events))." events\n" );
|
Debug( "Got ".int(keys(%$db_events))." events\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
my $fs_monitors;
|
my $fs_monitors;
|
||||||
foreach my $monitor ( glob("[0-9]*") )
|
foreach my $monitor ( glob("[0-9]*") ) {
|
||||||
{
|
|
||||||
# Thie glob above gives all files starting with a digit. So a monitor with a name starting with a digit will be in this list.
|
# Thie glob above gives all files starting with a digit. So a monitor with a name starting with a digit will be in this list.
|
||||||
next if $monitor =~ /\D/;
|
next if $monitor =~ /\D/;
|
||||||
Debug( "Found filesystem monitor '$monitor'" );
|
Debug( "Found filesystem monitor '$monitor'" );
|
||||||
my $fs_events = $fs_monitors->{$monitor} = {};
|
my $fs_events = $fs_monitors->{$monitor} = {};
|
||||||
( my $monitor_dir ) = ( $monitor =~ /^(.*)$/ ); # De-taint
|
( my $monitor_dir ) = ( $monitor =~ /^(.*)$/ ); # De-taint
|
||||||
|
|
||||||
if ( $Config{ZM_USE_DEEP_STORAGE} )
|
if ( $Config{ZM_USE_DEEP_STORAGE} ) {
|
||||||
{
|
foreach my $day_dir ( glob("$monitor_dir/*/*/*") ) {
|
||||||
foreach my $day_dir ( glob("$monitor_dir/*/*/*") )
|
|
||||||
{
|
|
||||||
Debug( "Checking $day_dir" );
|
Debug( "Checking $day_dir" );
|
||||||
( $day_dir ) = ( $day_dir =~ /^(.*)$/ ); # De-taint
|
( $day_dir ) = ( $day_dir =~ /^(.*)$/ ); # De-taint
|
||||||
chdir( $day_dir );
|
chdir( $day_dir );
|
||||||
|
@ -196,86 +190,63 @@ MAIN: while( $loop ) {
|
||||||
my @event_links = sort { $b <=> $a } grep { -l $_ } readdir( DIR );
|
my @event_links = sort { $b <=> $a } grep { -l $_ } readdir( DIR );
|
||||||
closedir( DIR );
|
closedir( DIR );
|
||||||
my $count = 0;
|
my $count = 0;
|
||||||
foreach my $event_link ( @event_links )
|
foreach my $event_link ( @event_links ) {
|
||||||
{
|
|
||||||
Debug( "Checking link $event_link" );
|
Debug( "Checking link $event_link" );
|
||||||
( my $event = $event_link ) =~ s/^.*\.//;
|
( my $event = $event_link ) =~ s/^.*\.//;
|
||||||
my $event_path = readlink( $event_link );
|
my $event_path = readlink( $event_link );
|
||||||
if ( $count++ > MAX_AGED_DIRS )
|
if ( $count++ > MAX_AGED_DIRS ) {
|
||||||
{
|
|
||||||
$fs_events->{$event} = -1;
|
$fs_events->{$event} = -1;
|
||||||
}
|
} else {
|
||||||
else
|
if ( !-e $event_path ) {
|
||||||
{
|
|
||||||
if ( !-e $event_path )
|
|
||||||
{
|
|
||||||
aud_print( "Event link $day_dir/$event_link does not point to valid target" );
|
aud_print( "Event link $day_dir/$event_link does not point to valid target" );
|
||||||
if ( confirm() )
|
if ( confirm() ) {
|
||||||
{
|
|
||||||
( $event_link ) = ( $event_link =~ /^(.*)$/ ); # De-taint
|
( $event_link ) = ( $event_link =~ /^(.*)$/ ); # De-taint
|
||||||
unlink( $event_link );
|
unlink( $event_link );
|
||||||
$cleaned = 1;
|
$cleaned = 1;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$fs_events->{$event} = (time() - ($^T - ((-M $event_path) * 24*60*60)));
|
$fs_events->{$event} = (time() - ($^T - ((-M $event_path) * 24*60*60)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} # end foreach event_link
|
||||||
chdir( EVENT_PATH );
|
chdir( EVENT_PATH );
|
||||||
}
|
} # end foreach day_dir
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
chdir( $monitor_dir );
|
chdir( $monitor_dir );
|
||||||
opendir( DIR, "." ) or Fatal( "Can't open directory '$monitor_dir': $!" );
|
opendir( DIR, "." ) or Fatal( "Can't open directory '$monitor_dir': $!" );
|
||||||
my @temp_events = sort { $b <=> $a } grep { -d $_ && $_ =~ /^\d+$/ } readdir( DIR );
|
my @temp_events = sort { $b <=> $a } grep { -d $_ && $_ =~ /^\d+$/ } readdir( DIR );
|
||||||
closedir( DIR );
|
closedir( DIR );
|
||||||
my $count = 0;
|
my $count = 0;
|
||||||
foreach my $event ( @temp_events )
|
foreach my $event ( @temp_events ) {
|
||||||
{
|
if ( $count++ > MAX_AGED_DIRS ) {
|
||||||
if ( $count++ > MAX_AGED_DIRS )
|
|
||||||
{
|
|
||||||
$fs_events->{$event} = -1;
|
$fs_events->{$event} = -1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$fs_events->{$event} = (time() - ($^T - ((-M $event) * 24*60*60)));
|
$fs_events->{$event} = (time() - ($^T - ((-M $event) * 24*60*60)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
chdir( EVENT_PATH );
|
chdir( EVENT_PATH );
|
||||||
}
|
}
|
||||||
Debug( "Got ".int(keys(%$fs_events))." events\n" );
|
Debug( "Got ".int(keys(%$fs_events))." events\n" );
|
||||||
}
|
} # end foreach monitor Id
|
||||||
redo MAIN if ( $cleaned );
|
redo MAIN if ( $cleaned );
|
||||||
|
|
||||||
$cleaned = 0;
|
$cleaned = 0;
|
||||||
while ( my ( $fs_monitor, $fs_events ) = each(%$fs_monitors) )
|
while ( my ( $fs_monitor, $fs_events ) = each(%$fs_monitors) ) {
|
||||||
{
|
if ( my $db_events = $db_monitors->{$fs_monitor} ) {
|
||||||
if ( my $db_events = $db_monitors->{$fs_monitor} )
|
if ( $fs_events ) {
|
||||||
{
|
while ( my ( $fs_event, $age ) = each(%$fs_events ) ) {
|
||||||
if ( $fs_events )
|
if ( !defined($db_events->{$fs_event}) && ($age < 0 || ($age > $Config{ZM_AUDIT_MIN_AGE})) ) {
|
||||||
{
|
|
||||||
while ( my ( $fs_event, $age ) = each(%$fs_events ) )
|
|
||||||
{
|
|
||||||
if ( !defined($db_events->{$fs_event}) && ($age < 0 || ($age > $Config{ZM_AUDIT_MIN_AGE})) )
|
|
||||||
{
|
|
||||||
aud_print( "Filesystem event '$fs_monitor/$fs_event' does not exist in database" );
|
aud_print( "Filesystem event '$fs_monitor/$fs_event' does not exist in database" );
|
||||||
if ( confirm() )
|
if ( confirm() ) {
|
||||||
{
|
|
||||||
deleteEventFiles( $fs_event, $fs_monitor );
|
deleteEventFiles( $fs_event, $fs_monitor );
|
||||||
$cleaned = 1;
|
$cleaned = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
aud_print( "Filesystem monitor '$fs_monitor' does not exist in database" );
|
aud_print( "Filesystem monitor '$fs_monitor' does not exist in database" );
|
||||||
if ( confirm() )
|
if ( confirm() ) {
|
||||||
{
|
|
||||||
my $command = "rm -rf $fs_monitor";
|
my $command = "rm -rf $fs_monitor";
|
||||||
executeShellCommand( $command );
|
executeShellCommand( $command );
|
||||||
$cleaned = 1;
|
$cleaned = 1;
|
||||||
|
@ -284,14 +255,12 @@ 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 );
|
||||||
|
@ -313,14 +282,10 @@ MAIN: while( $loop ) {
|
||||||
my $deleteStatsSql = "delete low_priority from Stats where EventId = ?";
|
my $deleteStatsSql = "delete low_priority from Stats where EventId = ?";
|
||||||
my $deleteStatsSth = $dbh->prepare_cached( $deleteStatsSql )
|
my $deleteStatsSth = $dbh->prepare_cached( $deleteStatsSql )
|
||||||
or Fatal( "Can't prepare '$deleteStatsSql': ".$dbh->errstr() );
|
or Fatal( "Can't prepare '$deleteStatsSql': ".$dbh->errstr() );
|
||||||
while ( my ( $db_monitor, $db_events ) = each(%$db_monitors) )
|
while ( my ( $db_monitor, $db_events ) = each(%$db_monitors) ) {
|
||||||
{
|
if ( my $fs_events = $fs_monitors->{$db_monitor} ) {
|
||||||
if ( my $fs_events = $fs_monitors->{$db_monitor} )
|
if ( $db_events ) {
|
||||||
{
|
while ( my ( $db_event, $age ) = each(%$db_events ) ) {
|
||||||
if ( $db_events )
|
|
||||||
{
|
|
||||||
while ( my ( $db_event, $age ) = each(%$db_events ) )
|
|
||||||
{
|
|
||||||
if ( !defined($fs_events->{$db_event}) ) {
|
if ( !defined($fs_events->{$db_event}) ) {
|
||||||
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 in filesystem" );
|
aud_print( "Database event '$db_monitor/$db_event' does not exist in filesystem" );
|
||||||
|
@ -338,10 +303,8 @@ MAIN: while( $loop ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} # end if db_events
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
aud_print( "Database monitor '$db_monitor' does not exist in filesystem" );
|
aud_print( "Database monitor '$db_monitor' does not exist in filesystem" );
|
||||||
#if ( confirm() )
|
#if ( confirm() )
|
||||||
#{
|
#{
|
||||||
|
@ -351,7 +314,7 @@ MAIN: while( $loop ) {
|
||||||
#$cleaned = 1;
|
#$cleaned = 1;
|
||||||
#}
|
#}
|
||||||
}
|
}
|
||||||
}
|
} # end foreach db_monitor
|
||||||
redo MAIN if ( $cleaned );
|
redo MAIN if ( $cleaned );
|
||||||
|
|
||||||
# Remove orphaned events (with no monitor)
|
# Remove orphaned events (with no monitor)
|
||||||
|
@ -363,11 +326,9 @@ MAIN: while( $loop ) {
|
||||||
or Fatal( "Can't prepare '$selectOrphanedEventsSql': ".$dbh->errstr() );
|
or Fatal( "Can't prepare '$selectOrphanedEventsSql': ".$dbh->errstr() );
|
||||||
$res = $selectOrphanedEventsSth->execute()
|
$res = $selectOrphanedEventsSth->execute()
|
||||||
or Fatal( "Can't execute: ".$selectOrphanedEventsSth->errstr() );
|
or Fatal( "Can't execute: ".$selectOrphanedEventsSth->errstr() );
|
||||||
while( my $event = $selectOrphanedEventsSth->fetchrow_hashref() )
|
while( my $event = $selectOrphanedEventsSth->fetchrow_hashref() ) {
|
||||||
{
|
|
||||||
aud_print( "Found orphaned event with no monitor '$event->{Id}'" );
|
aud_print( "Found orphaned event with no monitor '$event->{Id}'" );
|
||||||
if ( confirm() )
|
if ( confirm() ) {
|
||||||
{
|
|
||||||
$res = $deleteEventSth->execute( $event->{Id} )
|
$res = $deleteEventSth->execute( $event->{Id} )
|
||||||
or Fatal( "Can't execute: ".$deleteEventSth->errstr() );
|
or Fatal( "Can't execute: ".$deleteEventSth->errstr() );
|
||||||
$cleaned = 1;
|
$cleaned = 1;
|
||||||
|
@ -383,11 +344,9 @@ MAIN: while( $loop ) {
|
||||||
or Fatal( "Can't prepare '$selectEmptyEventsSql': ".$dbh->errstr() );
|
or Fatal( "Can't prepare '$selectEmptyEventsSql': ".$dbh->errstr() );
|
||||||
$res = $selectEmptyEventsSth->execute()
|
$res = $selectEmptyEventsSth->execute()
|
||||||
or Fatal( "Can't execute: ".$selectEmptyEventsSth->errstr() );
|
or Fatal( "Can't execute: ".$selectEmptyEventsSth->errstr() );
|
||||||
while( my $event = $selectEmptyEventsSth->fetchrow_hashref() )
|
while( my $event = $selectEmptyEventsSth->fetchrow_hashref() ) {
|
||||||
{
|
|
||||||
aud_print( "Found empty event with no frame records '$event->{Id}'" );
|
aud_print( "Found empty event with no frame records '$event->{Id}'" );
|
||||||
if ( confirm() )
|
if ( confirm() ) {
|
||||||
{
|
|
||||||
$res = $deleteEventSth->execute( $event->{Id} )
|
$res = $deleteEventSth->execute( $event->{Id} )
|
||||||
or Fatal( "Can't execute: ".$deleteEventSth->errstr() );
|
or Fatal( "Can't execute: ".$deleteEventSth->errstr() );
|
||||||
$cleaned = 1;
|
$cleaned = 1;
|
||||||
|
@ -403,11 +362,9 @@ MAIN: while( $loop ) {
|
||||||
or Fatal( "Can't prepare '$selectOrphanedFramesSql': ".$dbh->errstr() );
|
or Fatal( "Can't prepare '$selectOrphanedFramesSql': ".$dbh->errstr() );
|
||||||
$res = $selectOrphanedFramesSth->execute()
|
$res = $selectOrphanedFramesSth->execute()
|
||||||
or Fatal( "Can't execute: ".$selectOrphanedFramesSth->errstr() );
|
or Fatal( "Can't execute: ".$selectOrphanedFramesSth->errstr() );
|
||||||
while( my $frame = $selectOrphanedFramesSth->fetchrow_hashref() )
|
while( my $frame = $selectOrphanedFramesSth->fetchrow_hashref() ) {
|
||||||
{
|
|
||||||
aud_print( "Found orphaned frame records for event '$frame->{EventId}'" );
|
aud_print( "Found orphaned frame records for event '$frame->{EventId}'" );
|
||||||
if ( confirm() )
|
if ( confirm() ) {
|
||||||
{
|
|
||||||
$res = $deleteFramesSth->execute( $frame->{EventId} )
|
$res = $deleteFramesSth->execute( $frame->{EventId} )
|
||||||
or Fatal( "Can't execute: ".$deleteFramesSth->errstr() );
|
or Fatal( "Can't execute: ".$deleteFramesSth->errstr() );
|
||||||
$cleaned = 1;
|
$cleaned = 1;
|
||||||
|
@ -423,11 +380,9 @@ MAIN: while( $loop ) {
|
||||||
or Fatal( "Can't prepare '$selectOrphanedStatsSql': ".$dbh->errstr() );
|
or Fatal( "Can't prepare '$selectOrphanedStatsSql': ".$dbh->errstr() );
|
||||||
$res = $selectOrphanedStatsSth->execute()
|
$res = $selectOrphanedStatsSth->execute()
|
||||||
or Fatal( "Can't execute: ".$selectOrphanedStatsSth->errstr() );
|
or Fatal( "Can't execute: ".$selectOrphanedStatsSth->errstr() );
|
||||||
while( my $stat = $selectOrphanedStatsSth->fetchrow_hashref() )
|
while( my $stat = $selectOrphanedStatsSth->fetchrow_hashref() ) {
|
||||||
{
|
|
||||||
aud_print( "Found orphaned statistic records for event '$stat->{EventId}'" );
|
aud_print( "Found orphaned statistic records for event '$stat->{EventId}'" );
|
||||||
if ( confirm() )
|
if ( confirm() ) {
|
||||||
{
|
|
||||||
$res = $deleteStatsSth->execute( $stat->{EventId} )
|
$res = $deleteStatsSth->execute( $stat->{EventId} )
|
||||||
or Fatal( "Can't execute: ".$deleteStatsSth->errstr() );
|
or Fatal( "Can't execute: ".$deleteStatsSth->errstr() );
|
||||||
$cleaned = 1;
|
$cleaned = 1;
|
||||||
|
@ -470,13 +425,10 @@ MAIN: while( $loop ) {
|
||||||
or Fatal( "Can't prepare '$updateUnclosedEventsSql': ".$dbh->errstr() );
|
or Fatal( "Can't prepare '$updateUnclosedEventsSql': ".$dbh->errstr() );
|
||||||
$res = $selectUnclosedEventsSth->execute()
|
$res = $selectUnclosedEventsSth->execute()
|
||||||
or Fatal( "Can't execute: ".$selectUnclosedEventsSth->errstr() );
|
or Fatal( "Can't execute: ".$selectUnclosedEventsSth->errstr() );
|
||||||
while( my $event = $selectUnclosedEventsSth->fetchrow_hashref() )
|
while( my $event = $selectUnclosedEventsSth->fetchrow_hashref() ) {
|
||||||
{
|
|
||||||
aud_print( "Found open event '$event->{Id}'" );
|
aud_print( "Found open event '$event->{Id}'" );
|
||||||
if ( confirm( 'close', 'closing' ) )
|
if ( confirm( 'close', 'closing' ) ) {
|
||||||
{
|
$res = $updateUnclosedEventsSth->execute(
|
||||||
$res = $updateUnclosedEventsSth->execute
|
|
||||||
(
|
|
||||||
sprintf("%s%d%s",
|
sprintf("%s%d%s",
|
||||||
$event->{Prefix},
|
$event->{Prefix},
|
||||||
$event->{Id},
|
$event->{Id},
|
||||||
|
@ -499,8 +451,8 @@ MAIN: while( $loop ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Now delete any old image files
|
# Now delete any old image files
|
||||||
if ( my @old_files = grep { -M > $max_image_age } <$image_path/*.{jpg,gif,wbmp}> )
|
my @old_files = grep { -M > $max_image_age } <$image_path/*.{jpg,gif,wbmp}>;
|
||||||
{
|
if ( @old_files ) {
|
||||||
aud_print( "Deleting ".int(@old_files)." old images\n" );
|
aud_print( "Deleting ".int(@old_files)." old images\n" );
|
||||||
my $untainted_old_files = join( ";", @old_files );
|
my $untainted_old_files = join( ";", @old_files );
|
||||||
( $untainted_old_files ) = ( $untainted_old_files =~ /^(.*)$/ );
|
( $untainted_old_files ) = ( $untainted_old_files =~ /^(.*)$/ );
|
||||||
|
@ -512,10 +464,8 @@ MAIN: while( $loop ) {
|
||||||
File::Find::find( { wanted=>\&deleteSwapImage, untaint=>1 }, $swap_image_root );
|
File::Find::find( { wanted=>\&deleteSwapImage, untaint=>1 }, $swap_image_root );
|
||||||
|
|
||||||
# Prune the Logs table if required
|
# Prune the Logs table if required
|
||||||
if ( $Config{ZM_LOG_DATABASE_LIMIT} )
|
if ( $Config{ZM_LOG_DATABASE_LIMIT} ) {
|
||||||
{
|
if ( $Config{ZM_LOG_DATABASE_LIMIT} =~ /^\d+$/ ) {
|
||||||
if ( $Config{ZM_LOG_DATABASE_LIMIT} =~ /^\d+$/ )
|
|
||||||
{
|
|
||||||
# Number of rows
|
# Number of rows
|
||||||
my $selectLogRowCountSql = "SELECT count(*) as Rows from Logs";
|
my $selectLogRowCountSql = "SELECT count(*) as Rows from Logs";
|
||||||
my $selectLogRowCountSth = $dbh->prepare_cached( $selectLogRowCountSql )
|
my $selectLogRowCountSth = $dbh->prepare_cached( $selectLogRowCountSql )
|
||||||
|
@ -524,23 +474,17 @@ MAIN: while( $loop ) {
|
||||||
or Fatal( "Can't execute: ".$selectLogRowCountSth->errstr() );
|
or Fatal( "Can't execute: ".$selectLogRowCountSth->errstr() );
|
||||||
my $row = $selectLogRowCountSth->fetchrow_hashref();
|
my $row = $selectLogRowCountSth->fetchrow_hashref();
|
||||||
my $logRows = $row->{Rows};
|
my $logRows = $row->{Rows};
|
||||||
if ( $logRows > $Config{ZM_LOG_DATABASE_LIMIT} )
|
if ( $logRows > $Config{ZM_LOG_DATABASE_LIMIT} ) {
|
||||||
{
|
|
||||||
my $deleteLogByRowsSql = "DELETE low_priority FROM Logs ORDER BY TimeKey ASC LIMIT ?";
|
my $deleteLogByRowsSql = "DELETE low_priority FROM Logs ORDER BY TimeKey ASC LIMIT ?";
|
||||||
my $deleteLogByRowsSth = $dbh->prepare_cached( $deleteLogByRowsSql )
|
my $deleteLogByRowsSth = $dbh->prepare_cached( $deleteLogByRowsSql )
|
||||||
or Fatal( "Can't prepare '$deleteLogByRowsSql': ".$dbh->errstr() );
|
or Fatal( "Can't prepare '$deleteLogByRowsSql': ".$dbh->errstr() );
|
||||||
$res = $deleteLogByRowsSth->execute( $logRows - $Config{ZM_LOG_DATABASE_LIMIT} )
|
$res = $deleteLogByRowsSth->execute( $logRows - $Config{ZM_LOG_DATABASE_LIMIT} )
|
||||||
or Fatal( "Can't execute: ".$deleteLogByRowsSth->errstr() );
|
or Fatal( "Can't execute: ".$deleteLogByRowsSth->errstr() );
|
||||||
if ( $deleteLogByRowsSth->rows() )
|
if ( $deleteLogByRowsSth->rows() ) {
|
||||||
{
|
aud_print( "Deleted ".$deleteLogByRowsSth->rows() ." log table entries by count\n" );
|
||||||
aud_print( "Deleted ".$deleteLogByRowsSth->rows()
|
|
||||||
." log table entries by count\n" )
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
# Time of record
|
# Time of record
|
||||||
my $deleteLogByTimeSql =
|
my $deleteLogByTimeSql =
|
||||||
"DELETE low_priority FROM Logs
|
"DELETE low_priority FROM Logs
|
||||||
|
@ -550,12 +494,10 @@ MAIN: while( $loop ) {
|
||||||
$res = $deleteLogByTimeSth->execute()
|
$res = $deleteLogByTimeSth->execute()
|
||||||
or Fatal( "Can't execute: ".$deleteLogByTimeSth->errstr() );
|
or Fatal( "Can't execute: ".$deleteLogByTimeSth->errstr() );
|
||||||
if ( $deleteLogByTimeSth->rows() ){
|
if ( $deleteLogByTimeSth->rows() ){
|
||||||
aud_print( "Deleted ".$deleteLogByTimeSth->rows()
|
aud_print( "Deleted ".$deleteLogByTimeSth->rows() ." log table entries by time\n" );
|
||||||
." log table entries by time\n" )
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} # end if ( $Config{ZM_LOG_DATABASE_LIMIT} )
|
||||||
$loop = $continuous;
|
$loop = $continuous;
|
||||||
|
|
||||||
sleep( $Config{ZM_AUDIT_CHECK_INTERVAL} ) if $continuous;
|
sleep( $Config{ZM_AUDIT_CHECK_INTERVAL} ) if $continuous;
|
||||||
|
@ -563,52 +505,37 @@ MAIN: while( $loop ) {
|
||||||
|
|
||||||
exit( 0 );
|
exit( 0 );
|
||||||
|
|
||||||
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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub confirm
|
sub confirm {
|
||||||
{
|
|
||||||
my $prompt = shift || "delete";
|
my $prompt = shift || "delete";
|
||||||
my $action = shift || "deleting";
|
my $action = shift || "deleting";
|
||||||
|
|
||||||
my $yesno = 0;
|
my $yesno = 0;
|
||||||
if ( $report )
|
if ( $report ) {
|
||||||
{
|
|
||||||
print( "\n" );
|
print( "\n" );
|
||||||
}
|
} elsif ( $interactive ) {
|
||||||
elsif ( $interactive )
|
|
||||||
{
|
|
||||||
print( ", $prompt y/n: " );
|
print( ", $prompt y/n: " );
|
||||||
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';
|
||||||
}
|
}
|
||||||
$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;
|
||||||
|
@ -616,24 +543,23 @@ sub confirm
|
||||||
return( $yesno );
|
return( $yesno );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub deleteSwapImage
|
sub deleteSwapImage {
|
||||||
{
|
|
||||||
my $file = $_;
|
my $file = $_;
|
||||||
|
|
||||||
if ( $file !~ /^zmswap-/ )
|
if ( $file !~ /^zmswap-/ ) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Ignore directories
|
# Ignore directories
|
||||||
if ( -d $file )
|
if ( -d $file ) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( -M $file > $max_swap_age )
|
if ( -M $file > $max_swap_age ) {
|
||||||
{
|
|
||||||
Debug( "Deleting $file" );
|
Debug( "Deleting $file" );
|
||||||
#unlink( $file );
|
#unlink( $file );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
__END__
|
||||||
|
|
|
@ -120,35 +120,28 @@ my $dbh = zmDbConnect();
|
||||||
$Config{ZM_DB_USER} = $dbUser;
|
$Config{ZM_DB_USER} = $dbUser;
|
||||||
$Config{ZM_DB_PASS} = $dbPass;
|
$Config{ZM_DB_PASS} = $dbPass;
|
||||||
|
|
||||||
if ( ! ($check || $freshen || $rename || $zoneFix || $migrateEvents || $version) )
|
if ( ! ($check || $freshen || $rename || $zoneFix || $migrateEvents || $version) ) {
|
||||||
{
|
if ( $Config{ZM_DYN_DB_VERSION} ) {
|
||||||
if ( $Config{ZM_DYN_DB_VERSION} )
|
|
||||||
{
|
|
||||||
$version = $Config{ZM_DYN_DB_VERSION};
|
$version = $Config{ZM_DYN_DB_VERSION};
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
print( STDERR "Please give a valid option\n" );
|
print( STDERR "Please give a valid option\n" );
|
||||||
pod2usage(-exitstatus => -1);
|
pod2usage(-exitstatus => -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ($check + $freshen + $rename + $zoneFix + $migrateEvents + ($version?1:0)) > 1 )
|
if ( ($check + $freshen + $rename + $zoneFix + $migrateEvents + ($version?1:0)) > 1 ) {
|
||||||
{
|
|
||||||
print( STDERR "Please give only one option\n" );
|
print( STDERR "Please give only one option\n" );
|
||||||
pod2usage(-exitstatus => -1);
|
pod2usage(-exitstatus => -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $check && $Config{ZM_CHECK_FOR_UPDATES} )
|
if ( $check && $Config{ZM_CHECK_FOR_UPDATES} ) {
|
||||||
{
|
|
||||||
print( "Update agent starting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" );
|
print( "Update agent starting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" );
|
||||||
|
|
||||||
my $currVersion = $Config{ZM_DYN_CURR_VERSION};
|
my $currVersion = $Config{ZM_DYN_CURR_VERSION};
|
||||||
my $lastVersion = $Config{ZM_DYN_LAST_VERSION};
|
my $lastVersion = $Config{ZM_DYN_LAST_VERSION};
|
||||||
my $lastCheck = $Config{ZM_DYN_LAST_CHECK};
|
my $lastCheck = $Config{ZM_DYN_LAST_CHECK};
|
||||||
|
|
||||||
if ( !$currVersion )
|
if ( !$currVersion ) {
|
||||||
{
|
|
||||||
$currVersion = $Config{ZM_VERSION};
|
$currVersion = $Config{ZM_VERSION};
|
||||||
|
|
||||||
my $sql = "update Config set Value = ? where Name = 'ZM_DYN_CURR_VERSION'";
|
my $sql = "update Config set Value = ? where Name = 'ZM_DYN_CURR_VERSION'";
|
||||||
|
@ -157,11 +150,9 @@ if ( $check && $Config{ZM_CHECK_FOR_UPDATES} )
|
||||||
$sth->finish();
|
$sth->finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
while( 1 )
|
while( 1 ) {
|
||||||
{
|
|
||||||
my $now = time();
|
my $now = time();
|
||||||
if ( !$lastVersion || !$lastCheck || (($now-$lastCheck) > CHECK_INTERVAL) )
|
if ( !$lastVersion || !$lastCheck || (($now-$lastCheck) > CHECK_INTERVAL) ) {
|
||||||
{
|
|
||||||
Info( "Checking for updates\n" );
|
Info( "Checking for updates\n" );
|
||||||
|
|
||||||
use LWP::UserAgent;
|
use LWP::UserAgent;
|
||||||
|
@ -173,8 +164,7 @@ if ( $check && $Config{ZM_CHECK_FOR_UPDATES} )
|
||||||
my $req = HTTP::Request->new( GET=>'https://update.zoneminder.com/version.txt' );
|
my $req = HTTP::Request->new( GET=>'https://update.zoneminder.com/version.txt' );
|
||||||
my $res = $ua->request($req);
|
my $res = $ua->request($req);
|
||||||
|
|
||||||
if ( $res->is_success )
|
if ( $res->is_success ) {
|
||||||
{
|
|
||||||
$lastVersion = $res->content;
|
$lastVersion = $res->content;
|
||||||
chomp($lastVersion);
|
chomp($lastVersion);
|
||||||
$lastCheck = $now;
|
$lastCheck = $now;
|
||||||
|
@ -190,9 +180,7 @@ if ( $check && $Config{ZM_CHECK_FOR_UPDATES} )
|
||||||
my $lc_sth = $dbh->prepare_cached( $lc_sql ) or die( "Can't prepare '$lc_sql': ".$dbh->errstr() );
|
my $lc_sth = $dbh->prepare_cached( $lc_sql ) or die( "Can't prepare '$lc_sql': ".$dbh->errstr() );
|
||||||
my $lc_res = $lc_sth->execute( $lastCheck ) or die( "Can't execute: ".$lc_sth->errstr() );
|
my $lc_res = $lc_sth->execute( $lastCheck ) or die( "Can't execute: ".$lc_sth->errstr() );
|
||||||
$lc_sth->finish();
|
$lc_sth->finish();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
Error( "Error check failed: '".$res->status_line()."'\n" );
|
Error( "Error check failed: '".$res->status_line()."'\n" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,24 +188,21 @@ if ( $check && $Config{ZM_CHECK_FOR_UPDATES} )
|
||||||
}
|
}
|
||||||
print( "Update agent exiting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" );
|
print( "Update agent exiting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" );
|
||||||
}
|
}
|
||||||
if ( $rename )
|
|
||||||
{
|
if ( $rename ) {
|
||||||
require File::Find;
|
require File::Find;
|
||||||
|
|
||||||
chdir( EVENT_PATH );
|
chdir( EVENT_PATH );
|
||||||
|
|
||||||
sub renameImage
|
sub renameImage {
|
||||||
{
|
|
||||||
my $file = $_;
|
my $file = $_;
|
||||||
|
|
||||||
# Ignore directories
|
# Ignore directories
|
||||||
if ( -d $file )
|
if ( -d $file ) {
|
||||||
{
|
|
||||||
print( "Checking directory '$file'\n" );
|
print( "Checking directory '$file'\n" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( $file !~ /(capture|analyse)-(\d+)(\.jpg)/ )
|
if ( $file !~ /(capture|analyse)-(\d+)(\.jpg)/ ) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
my $newFile = "$2-$1$3";
|
my $newFile = "$2-$1$3";
|
||||||
|
@ -228,23 +213,20 @@ if ( $rename )
|
||||||
|
|
||||||
File::Find::find( \&renameImage, '.' );
|
File::Find::find( \&renameImage, '.' );
|
||||||
}
|
}
|
||||||
if ( $zoneFix )
|
if ( $zoneFix ) {
|
||||||
{
|
|
||||||
|
|
||||||
my $sql = "select Z.*, M.Width as MonitorWidth, M.Height as MonitorHeight from Zones as Z inner join Monitors as M on Z.MonitorId = M.Id where Z.Units = 'Percent'";
|
my $sql = "select Z.*, M.Width as MonitorWidth, M.Height as MonitorHeight from Zones as Z inner join Monitors as M on Z.MonitorId = M.Id where Z.Units = 'Percent'";
|
||||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||||
my @zones;
|
my @zones;
|
||||||
while( my $zone = $sth->fetchrow_hashref() )
|
while( my $zone = $sth->fetchrow_hashref() ) {
|
||||||
{
|
|
||||||
push( @zones, $zone );
|
push( @zones, $zone );
|
||||||
}
|
}
|
||||||
$sth->finish();
|
$sth->finish();
|
||||||
|
|
||||||
$sql = "update Zones set MinAlarmPixels = ?, MaxAlarmPixels = ?, MinFilterPixels = ?, MaxFilterPixels = ?, MinBlobPixels = ?, MaxBlobPixels = ? where Id = ?";
|
$sql = "update Zones set MinAlarmPixels = ?, MaxAlarmPixels = ?, MinFilterPixels = ?, MaxFilterPixels = ?, MinBlobPixels = ?, MaxBlobPixels = ? where Id = ?";
|
||||||
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
foreach my $zone ( @zones )
|
foreach my $zone ( @zones ) {
|
||||||
{
|
|
||||||
my $zone_width = (($zone->{HiX}*$zone->{MonitorWidth})-($zone->{LoX}*$zone->{MonitorWidth}))/100;
|
my $zone_width = (($zone->{HiX}*$zone->{MonitorWidth})-($zone->{LoX}*$zone->{MonitorWidth}))/100;
|
||||||
my $zone_height = (($zone->{HiY}*$zone->{MonitorHeight})-($zone->{LoY}*$zone->{MonitorHeight}))/100;
|
my $zone_height = (($zone->{HiY}*$zone->{MonitorHeight})-($zone->{LoY}*$zone->{MonitorHeight}))/100;
|
||||||
my $zone_area = $zone_width * $zone_height;
|
my $zone_area = $zone_width * $zone_height;
|
||||||
|
@ -261,13 +243,11 @@ if ( $zoneFix )
|
||||||
}
|
}
|
||||||
$sth->finish();
|
$sth->finish();
|
||||||
}
|
}
|
||||||
if ( $migrateEvents )
|
if ( $migrateEvents ) {
|
||||||
{
|
|
||||||
my $webUid = (getpwnam( $Config{ZM_WEB_USER} ))[2];
|
my $webUid = (getpwnam( $Config{ZM_WEB_USER} ))[2];
|
||||||
my $webGid = (getgrnam( $Config{ZM_WEB_USER} ))[2];
|
my $webGid = (getgrnam( $Config{ZM_WEB_USER} ))[2];
|
||||||
|
|
||||||
if ( !(($> == 0) || ($> == $webUid)) )
|
if ( !(($> == 0) || ($> == $webUid)) ) {
|
||||||
{
|
|
||||||
print( "Error, migrating events can only be done as user root or ".$Config{ZM_WEB_USER}.".\n" );
|
print( "Error, migrating events can only be done as user root or ".$Config{ZM_WEB_USER}.".\n" );
|
||||||
exit( -1 );
|
exit( -1 );
|
||||||
}
|
}
|
||||||
|
@ -281,32 +261,27 @@ if ( $migrateEvents )
|
||||||
print( "\nAbout to convert saved events to deep storage, please ensure that ZoneMinder is fully stopped before proceeding.\nThis process is not easily reversible. Are you sure you wish to proceed?\n\nPress 'y' to continue or 'n' to abort : " );
|
print( "\nAbout to convert saved events to deep storage, please ensure that ZoneMinder is fully stopped before proceeding.\nThis process is not easily reversible. Are you sure you wish to proceed?\n\nPress 'y' to continue or 'n' to abort : " );
|
||||||
my $response = <STDIN>;
|
my $response = <STDIN>;
|
||||||
chomp( $response );
|
chomp( $response );
|
||||||
while ( $response !~ /^[yYnN]$/ )
|
while ( $response !~ /^[yYnN]$/ ) {
|
||||||
{
|
|
||||||
print( "Please press 'y' to continue or 'n' to abort only : " );
|
print( "Please press 'y' to continue or 'n' to abort only : " );
|
||||||
$response = <STDIN>;
|
$response = <STDIN>;
|
||||||
chomp( $response );
|
chomp( $response );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $response =~ /^[yY]$/ )
|
if ( $response =~ /^[yY]$/ ) {
|
||||||
{
|
|
||||||
print( "Converting all events to deep storage.\n" );
|
print( "Converting all events to deep storage.\n" );
|
||||||
|
|
||||||
chdir( $Config{ZM_PATH_WEB} );
|
chdir( $Config{ZM_PATH_WEB} );
|
||||||
my $sql = "select *, unix_timestamp(StartTime) as UnixStartTime from Events";
|
my $sql = "select *, unix_timestamp(StartTime) as UnixStartTime from Events";
|
||||||
my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
my $res = $sth->execute();
|
my $res = $sth->execute();
|
||||||
if ( !$res )
|
if ( !$res ) {
|
||||||
{
|
|
||||||
Fatal( "Can't fetch Events: ".$sth->errstr() );
|
Fatal( "Can't fetch Events: ".$sth->errstr() );
|
||||||
}
|
}
|
||||||
|
|
||||||
while( my $event = $sth->fetchrow_hashref() )
|
while( my $event = $sth->fetchrow_hashref() ) {
|
||||||
{
|
|
||||||
my $oldEventPath = $Config{ZM_DIR_EVENTS}.'/'.$event->{MonitorId}.'/'.$event->{Id};
|
my $oldEventPath = $Config{ZM_DIR_EVENTS}.'/'.$event->{MonitorId}.'/'.$event->{Id};
|
||||||
|
|
||||||
if ( !-d $oldEventPath )
|
if ( !-d $oldEventPath ) {
|
||||||
{
|
|
||||||
print( "Warning, can't find old event path '$oldEventPath', already converted?\n" );
|
print( "Warning, can't find old event path '$oldEventPath', already converted?\n" );
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
@ -330,14 +305,11 @@ if ( $migrateEvents )
|
||||||
$sth->finish();
|
$sth->finish();
|
||||||
|
|
||||||
print( "All events converted.\n\n" );
|
print( "All events converted.\n\n" );
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
print( "Aborting event conversion.\n\n" );
|
print( "Aborting event conversion.\n\n" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( $freshen )
|
if ( $freshen ) {
|
||||||
{
|
|
||||||
print( "\nFreshening configuration in database\n" );
|
print( "\nFreshening configuration in database\n" );
|
||||||
ZoneMinder::Config::loadConfigFromDB();
|
ZoneMinder::Config::loadConfigFromDB();
|
||||||
ZoneMinder::Config::saveConfigToDB();
|
ZoneMinder::Config::saveConfigToDB();
|
||||||
|
@ -375,22 +347,18 @@ if ( $interactive ) {
|
||||||
}
|
}
|
||||||
} # end if interactive
|
} # end if interactive
|
||||||
|
|
||||||
if ( $version )
|
if ( $version ) {
|
||||||
{
|
|
||||||
my ( $detaint_version ) = $version =~ /^([\w.]+)$/;
|
my ( $detaint_version ) = $version =~ /^([\w.]+)$/;
|
||||||
$version = $detaint_version;
|
$version = $detaint_version;
|
||||||
|
|
||||||
if ( ZM_VERSION eq $version )
|
if ( ZM_VERSION eq $version ) {
|
||||||
{
|
|
||||||
print( "\nDatabase already at version $version, update aborted.\n\n" );
|
print( "\nDatabase already at version $version, update aborted.\n\n" );
|
||||||
exit( 0 );
|
exit( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
print( "\nInitiating database upgrade to version ".ZM_VERSION." from version $version\n" );
|
print( "\nInitiating database upgrade to version ".ZM_VERSION." from version $version\n" );
|
||||||
if ( $interactive )
|
if ( $interactive ) {
|
||||||
{
|
if ( $Config{ZM_DYN_DB_VERSION} && $Config{ZM_DYN_DB_VERSION} ne $version ) {
|
||||||
if ( $Config{ZM_DYN_DB_VERSION} && $Config{ZM_DYN_DB_VERSION} ne $version )
|
|
||||||
{
|
|
||||||
print( "\nWARNING - You have specified an upgrade from version $version but the database version found is ".$Config{ZM_DYN_DB_VERSION}.". Is this correct?\nPress enter to continue or ctrl-C to abort : " );
|
print( "\nWARNING - You have specified an upgrade from version $version but the database version found is ".$Config{ZM_DYN_DB_VERSION}.". Is this correct?\nPress enter to continue or ctrl-C to abort : " );
|
||||||
my $response = <STDIN>;
|
my $response = <STDIN>;
|
||||||
}
|
}
|
||||||
|
@ -401,21 +369,25 @@ if ( $version )
|
||||||
print( "\nDo you wish to take a backup of your database prior to upgrading?\nThis may result in a large file in @ZM_TMPDIR@ if you have a lot of events.\nPress 'y' for a backup or 'n' to continue : " );
|
print( "\nDo you wish to take a backup of your database prior to upgrading?\nThis may result in a large file in @ZM_TMPDIR@ if you have a lot of events.\nPress 'y' for a backup or 'n' to continue : " );
|
||||||
$response = <STDIN>;
|
$response = <STDIN>;
|
||||||
chomp( $response );
|
chomp( $response );
|
||||||
while ( $response !~ /^[yYnN]$/ )
|
while ( $response !~ /^[yYnN]$/ ) {
|
||||||
{
|
|
||||||
print( "Please press 'y' for a backup or 'n' to continue only : " );
|
print( "Please press 'y' for a backup or 'n' to continue only : " );
|
||||||
$response = <STDIN>;
|
$response = <STDIN>;
|
||||||
chomp( $response );
|
chomp( $response );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $response =~ /^[yY]$/ )
|
if ( $response =~ /^[yY]$/ ) {
|
||||||
{
|
my ( $host, $portOrSocket ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ );
|
||||||
my ( $host, $port ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ );
|
|
||||||
my $command = "mysqldump";
|
my $command = "mysqldump";
|
||||||
$command .= " -h".$host if defined($host);
|
if ( defined($portOrSocket) ) {
|
||||||
$command .= " -P".$port if defined($port);
|
if ( $portOrSocket =~ /^\// ) {
|
||||||
if ( $dbUser )
|
$command .= " -S".$portOrSocket;
|
||||||
{
|
} else {
|
||||||
|
$command .= " -h".$host." -P".$portOrSocket;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$command .= " -h".$host;
|
||||||
|
}
|
||||||
|
if ( $dbUser ) {
|
||||||
$command .= ' -u'.$dbUser;
|
$command .= ' -u'.$dbUser;
|
||||||
$command .= ' -p"'.$dbPass.'"' if $dbPass;
|
$command .= ' -p"'.$dbPass.'"' if $dbPass;
|
||||||
}
|
}
|
||||||
|
@ -425,45 +397,42 @@ if ( $version )
|
||||||
print( "Executing '$command'\n" ) if ( logDebugging() );
|
print( "Executing '$command'\n" ) if ( logDebugging() );
|
||||||
my $output = qx($command);
|
my $output = qx($command);
|
||||||
my $status = $? >> 8;
|
my $status = $? >> 8;
|
||||||
if ( $status || logDebugging() )
|
if ( $status || logDebugging() ) {
|
||||||
{
|
|
||||||
chomp( $output );
|
chomp( $output );
|
||||||
print( "Output: $output\n" );
|
print( "Output: $output\n" );
|
||||||
}
|
}
|
||||||
if ( $status )
|
if ( $status ) {
|
||||||
{
|
|
||||||
die( "Command '$command' exited with status: $status\n" );
|
die( "Command '$command' exited with status: $status\n" );
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
print( "Database successfully backed up to $backup, proceeding to upgrade.\n" );
|
print( "Database successfully backed up to $backup, proceeding to upgrade.\n" );
|
||||||
}
|
}
|
||||||
}
|
} elsif ( $response !~ /^[nN]$/ ) {
|
||||||
elsif ( $response !~ /^[nN]$/ )
|
|
||||||
{
|
|
||||||
die( "Unexpected response '$response'" );
|
die( "Unexpected response '$response'" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sub patchDB
|
sub patchDB {
|
||||||
{
|
|
||||||
my $dbh = shift;
|
my $dbh = shift;
|
||||||
my $version = shift;
|
my $version = shift;
|
||||||
|
|
||||||
my ( $host, $port ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ );
|
my ( $host, $portOrSocket ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ );
|
||||||
my $command = "mysql -h".$host;
|
my $command = "mysql";
|
||||||
$command .= " -P".$port if defined($port);
|
if ( defined($portOrSocket) ) {
|
||||||
if ( $dbUser )
|
if ( $portOrSocket =~ /^\// ) {
|
||||||
{
|
$command .= " -S".$portOrSocket;
|
||||||
|
} else {
|
||||||
|
$command .= " -h".$host." -P".$portOrSocket;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$command .= " -h".$host;
|
||||||
|
}
|
||||||
|
if ( $dbUser ) {
|
||||||
$command .= " -u".$dbUser;
|
$command .= " -u".$dbUser;
|
||||||
$command .= ' -p"'.$dbPass.'"' if $dbPass;
|
$command .= ' -p"'.$dbPass.'"' if $dbPass;
|
||||||
}
|
}
|
||||||
$command .= " ".$Config{ZM_DB_NAME}." < ";
|
$command .= " ".$Config{ZM_DB_NAME}." < ";
|
||||||
if ( $updateDir )
|
if ( $updateDir ) {
|
||||||
{
|
|
||||||
$command .= $updateDir;
|
$command .= $updateDir;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$command .= $Config{ZM_PATH_DATA}."/db";
|
$command .= $Config{ZM_PATH_DATA}."/db";
|
||||||
}
|
}
|
||||||
$command .= "/zm_update-".$version.".sql";
|
$command .= "/zm_update-".$version.".sql";
|
||||||
|
@ -471,17 +440,13 @@ if ( $version )
|
||||||
print( "Executing '$command'\n" ) if ( logDebugging() );
|
print( "Executing '$command'\n" ) if ( logDebugging() );
|
||||||
my $output = qx($command);
|
my $output = qx($command);
|
||||||
my $status = $? >> 8;
|
my $status = $? >> 8;
|
||||||
if ( $status || logDebugging() )
|
if ( $status || logDebugging() ) {
|
||||||
{
|
|
||||||
chomp( $output );
|
chomp( $output );
|
||||||
print( "Output: $output\n" );
|
print( "Output: $output\n" );
|
||||||
}
|
}
|
||||||
if ( $status )
|
if ( $status ) {
|
||||||
{
|
|
||||||
die( "Command '$command' exited with status: $status\n" );
|
die( "Command '$command' exited with status: $status\n" );
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
print( "\nDatabase successfully upgraded to version $version.\n" );
|
print( "\nDatabase successfully upgraded to version $version.\n" );
|
||||||
my $sql = "update Config set Value = ? where Name = 'ZM_DYN_DB_VERSION'";
|
my $sql = "update Config set Value = ? where Name = 'ZM_DYN_DB_VERSION'";
|
||||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
|
@ -497,42 +462,35 @@ if ( $version )
|
||||||
ZoneMinder::Config::saveConfigToDB();
|
ZoneMinder::Config::saveConfigToDB();
|
||||||
|
|
||||||
my $cascade = undef;
|
my $cascade = undef;
|
||||||
if ( $cascade || $version eq "1.19.0" )
|
if ( $cascade || $version eq "1.19.0" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.19.0" );
|
patchDB( $dbh, "1.19.0" );
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.19.1" )
|
if ( $cascade || $version eq "1.19.1" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.19.1");
|
patchDB( $dbh, "1.19.1");
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.19.2" )
|
if ( $cascade || $version eq "1.19.2" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.19.2" );
|
patchDB( $dbh, "1.19.2" );
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.19.3" )
|
if ( $cascade || $version eq "1.19.3" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.19.3" );
|
patchDB( $dbh, "1.19.3" );
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.19.4" )
|
if ( $cascade || $version eq "1.19.4" ) {
|
||||||
{
|
|
||||||
# Rename the event directories and create a new symlink for the names
|
# Rename the event directories and create a new symlink for the names
|
||||||
chdir( EVENT_PATH );
|
chdir( EVENT_PATH );
|
||||||
|
|
||||||
my $sql = "select * from Monitors order by Id";
|
my $sql = "select * from Monitors order by Id";
|
||||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||||
while( my $monitor = $sth->fetchrow_hashref() )
|
while( my $monitor = $sth->fetchrow_hashref() ) {
|
||||||
{
|
if ( -d $monitor->{Name} ) {
|
||||||
if ( -d $monitor->{Name} )
|
|
||||||
{
|
|
||||||
rename( $monitor->{Name}, $monitor->{Id} ) or warn( "Can't rename existing monitor directory '$monitor->{Name}' to '$monitor->{Id}': $!" );
|
rename( $monitor->{Name}, $monitor->{Id} ) or warn( "Can't rename existing monitor directory '$monitor->{Name}' to '$monitor->{Id}': $!" );
|
||||||
symlink( $monitor->{Id}, $monitor->{Name} ) or warn( "Can't symlink monitor directory '$monitor->{Id}' to '$monitor->{Name}': $!" );
|
symlink( $monitor->{Id}, $monitor->{Name} ) or warn( "Can't symlink monitor directory '$monitor->{Id}' to '$monitor->{Name}': $!" );
|
||||||
}
|
}
|
||||||
|
@ -544,46 +502,39 @@ if ( $version )
|
||||||
|
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.19.5" )
|
if ( $cascade || $version eq "1.19.5" ) {
|
||||||
{
|
|
||||||
print( "\nThis version now only uses one database user.\nPlease ensure you have run zmconfig.pl and re-entered your database username and password prior to upgrading, or the upgrade will fail.\nPress enter to continue or ctrl-C to stop : " );
|
print( "\nThis version now only uses one database user.\nPlease ensure you have run zmconfig.pl and re-entered your database username and password prior to upgrading, or the upgrade will fail.\nPress enter to continue or ctrl-C to stop : " );
|
||||||
# Patch the database
|
# Patch the database
|
||||||
my $dummy = <STDIN>;
|
my $dummy = <STDIN>;
|
||||||
patchDB( $dbh, "1.19.5" );
|
patchDB( $dbh, "1.19.5" );
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.20.0" )
|
if ( $cascade || $version eq "1.20.0" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.20.0" );
|
patchDB( $dbh, "1.20.0" );
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.20.1" )
|
if ( $cascade || $version eq "1.20.1" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.20.1" );
|
patchDB( $dbh, "1.20.1" );
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.21.0" )
|
if ( $cascade || $version eq "1.21.0" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.21.0" );
|
patchDB( $dbh, "1.21.0" );
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.21.1" )
|
if ( $cascade || $version eq "1.21.1" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.21.1" );
|
patchDB( $dbh, "1.21.1" );
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.21.2" )
|
if ( $cascade || $version eq "1.21.2" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.21.2" );
|
patchDB( $dbh, "1.21.2" );
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.21.3" )
|
if ( $cascade || $version eq "1.21.3" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.21.3" );
|
patchDB( $dbh, "1.21.3" );
|
||||||
|
|
||||||
|
@ -593,8 +544,7 @@ if ( $version )
|
||||||
my $sql = "select * from Monitors order by Id";
|
my $sql = "select * from Monitors order by Id";
|
||||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||||
while( my $monitor = $sth->fetchrow_hashref() )
|
while( my $monitor = $sth->fetchrow_hashref() ) {
|
||||||
{
|
|
||||||
my $sql = "update Events set Width = ?, Height = ? where MonitorId = ?";
|
my $sql = "update Events set Width = ?, Height = ? where MonitorId = ?";
|
||||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
my $res = $sth->execute( $monitor->{Width}, $monitor->{Height}, $monitor->{Id} ) or die( "Can't execute: ".$sth->errstr() );
|
my $res = $sth->execute( $monitor->{Width}, $monitor->{Height}, $monitor->{Id} ) or die( "Can't execute: ".$sth->errstr() );
|
||||||
|
@ -609,8 +559,7 @@ if ( $version )
|
||||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||||
my $sequence = 1;
|
my $sequence = 1;
|
||||||
while( my $monitor = $sth->fetchrow_hashref() )
|
while( my $monitor = $sth->fetchrow_hashref() ) {
|
||||||
{
|
|
||||||
my $sql = "update Monitors set Sequence = ? where Id = ?";
|
my $sql = "update Monitors set Sequence = ? where Id = ?";
|
||||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
my $res = $sth->execute( $sequence++, $monitor->{Id} ) or die( "Can't execute: ".$sth->errstr() );
|
my $res = $sth->execute( $sequence++, $monitor->{Id} ) or die( "Can't execute: ".$sth->errstr() );
|
||||||
|
@ -625,17 +574,14 @@ if ( $version )
|
||||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||||
my @filters;
|
my @filters;
|
||||||
while( my $filter = $sth->fetchrow_hashref() )
|
while( my $filter = $sth->fetchrow_hashref() ) {
|
||||||
{
|
|
||||||
push( @filters, $filter );
|
push( @filters, $filter );
|
||||||
}
|
}
|
||||||
$sth->finish();
|
$sth->finish();
|
||||||
$sql = "update Filters set Query = ? where Name = ?";
|
$sql = "update Filters set Query = ? where Name = ?";
|
||||||
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
foreach my $filter ( @filters )
|
foreach my $filter ( @filters ) {
|
||||||
{
|
if ( $filter->{Query} =~ /op\d=&/ ) {
|
||||||
if ( $filter->{Query} =~ /op\d=&/ )
|
|
||||||
{
|
|
||||||
( my $newQuery = $filter->{Query} ) =~ s/(op\d=)&/$1=&/g;
|
( my $newQuery = $filter->{Query} ) =~ s/(op\d=)&/$1=&/g;
|
||||||
$res = $sth->execute( $newQuery, $filter->{Name} ) or die( "Can't execute: ".$sth->errstr() );
|
$res = $sth->execute( $newQuery, $filter->{Name} ) or die( "Can't execute: ".$sth->errstr() );
|
||||||
}
|
}
|
||||||
|
@ -644,8 +590,7 @@ if ( $version )
|
||||||
|
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.21.4" )
|
if ( $cascade || $version eq "1.21.4" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.21.4" );
|
patchDB( $dbh, "1.21.4" );
|
||||||
|
|
||||||
|
@ -658,24 +603,19 @@ if ( $version )
|
||||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||||
my @zones;
|
my @zones;
|
||||||
while( my $zone = $sth->fetchrow_hashref() )
|
while( my $zone = $sth->fetchrow_hashref() ) {
|
||||||
{
|
|
||||||
push( @zones, $zone );
|
push( @zones, $zone );
|
||||||
}
|
}
|
||||||
$sth->finish();
|
$sth->finish();
|
||||||
|
|
||||||
no strict 'refs';
|
no strict 'refs';
|
||||||
foreach my $zone ( @zones )
|
foreach my $zone ( @zones ) {
|
||||||
{
|
|
||||||
# Create the coordinate strings
|
# Create the coordinate strings
|
||||||
if ( $zone->{Units} eq "Pixels" )
|
if ( $zone->{Units} eq "Pixels" ) {
|
||||||
{
|
|
||||||
my $sql = "update Zones set NumCoords = 4, Coords = concat( LoX,',',LoY,' ',HiX,',',LoY,' ',HiX,',',HiY,' ',LoX,',',HiY ), Area = round( ((HiX-LoX)+1)*((HiY-LoY)+1) ) where Id = ?";
|
my $sql = "update Zones set NumCoords = 4, Coords = concat( LoX,',',LoY,' ',HiX,',',LoY,' ',HiX,',',HiY,' ',LoX,',',HiY ), Area = round( ((HiX-LoX)+1)*((HiY-LoY)+1) ) where Id = ?";
|
||||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
my $res = $sth->execute( $zone->{Id} ) or die( "Can't execute: ".$sth->errstr() );
|
my $res = $sth->execute( $zone->{Id} ) or die( "Can't execute: ".$sth->errstr() );
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
my $loX = ($zone->{LoX} * ($zone->{Width}-1) ) / 100;
|
my $loX = ($zone->{LoX} * ($zone->{Width}-1) ) / 100;
|
||||||
my $hiX = ($zone->{HiX} * ($zone->{Width}-1) ) / 100;
|
my $hiX = ($zone->{HiX} * ($zone->{Width}-1) ) / 100;
|
||||||
my $loY = ($zone->{LoY} * ($zone->{Height}-1) ) / 100;
|
my $loY = ($zone->{LoY} * ($zone->{Height}-1) ) / 100;
|
||||||
|
@ -696,17 +636,14 @@ if ( $version )
|
||||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||||
my @states;
|
my @states;
|
||||||
while( my $state = $sth->fetchrow_hashref() )
|
while( my $state = $sth->fetchrow_hashref() ) {
|
||||||
{
|
|
||||||
push( @states, $state );
|
push( @states, $state );
|
||||||
}
|
}
|
||||||
$sth->finish();
|
$sth->finish();
|
||||||
|
|
||||||
foreach my $state ( @states )
|
foreach my $state ( @states ) {
|
||||||
{
|
|
||||||
my @new_defns;
|
my @new_defns;
|
||||||
foreach my $defn ( split( /,/, $state->{Definition} ) )
|
foreach my $defn ( split( /,/, $state->{Definition} ) ) {
|
||||||
{
|
|
||||||
push( @new_defns, $defn.":1" );
|
push( @new_defns, $defn.":1" );
|
||||||
}
|
}
|
||||||
my $sql = "update States set Definition = ? where Name = ?";
|
my $sql = "update States set Definition = ? where Name = ?";
|
||||||
|
@ -717,23 +654,19 @@ if ( $version )
|
||||||
|
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.22.0" )
|
if ( $cascade || $version eq "1.22.0" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.22.0" );
|
patchDB( $dbh, "1.22.0" );
|
||||||
|
|
||||||
# Check for maximum FPS setting and update alarm max fps settings
|
# Check for maximum FPS setting and update alarm max fps settings
|
||||||
{
|
{
|
||||||
print( "Updating monitors. Please wait.\n" );
|
print( "Updating monitors. Please wait.\n" );
|
||||||
if ( defined(&ZM_NO_MAX_FPS_ON_ALARM) && &ZM_NO_MAX_FPS_ON_ALARM )
|
if ( defined(&ZM_NO_MAX_FPS_ON_ALARM) && &ZM_NO_MAX_FPS_ON_ALARM ) {
|
||||||
{
|
|
||||||
# Update the individual monitor settings to match the previous global one
|
# Update the individual monitor settings to match the previous global one
|
||||||
my $sql = "update Monitors set AlarmMaxFPS = NULL";
|
my $sql = "update Monitors set AlarmMaxFPS = NULL";
|
||||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
# Update the individual monitor settings to match the previous global one
|
# Update the individual monitor settings to match the previous global one
|
||||||
my $sql = "update Monitors set AlarmMaxFPS = MaxFPS";
|
my $sql = "update Monitors set AlarmMaxFPS = MaxFPS";
|
||||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
|
@ -743,8 +676,7 @@ if ( $version )
|
||||||
{
|
{
|
||||||
print( "Updating mail configuration. Please wait.\n" );
|
print( "Updating mail configuration. Please wait.\n" );
|
||||||
my ( $sql, $sth, $res );
|
my ( $sql, $sth, $res );
|
||||||
if ( defined(&ZM_EMAIL_TEXT) && &ZM_EMAIL_TEXT )
|
if ( defined(&ZM_EMAIL_TEXT) && &ZM_EMAIL_TEXT ) {
|
||||||
{
|
|
||||||
my ( $email_subject, $email_body ) = $Config{ZM_EMAIL_TEXT} =~ /subject\s*=\s*"([^\n]*)".*body\s*=\s*"(.*)"?$/ms;
|
my ( $email_subject, $email_body ) = $Config{ZM_EMAIL_TEXT} =~ /subject\s*=\s*"([^\n]*)".*body\s*=\s*"(.*)"?$/ms;
|
||||||
$sql = "replace into Config set Id = 0, Name = 'ZM_EMAIL_SUBJECT', Value = '".$email_subject."', Type = 'string', DefaultValue = 'ZoneMinder: Alarm - %MN%-%EI% (%ESM% - %ESA% %EFA%)', Hint = 'string', Pattern = '(?-xism:^(.+)\$)', Format = ' \$1 ', Prompt = 'The subject of the email used to send matching event details', Help = 'This option is used to define the subject of the email that is sent for any events that match the appropriate filters.', Category = 'mail', Readonly = '0', Requires = 'ZM_OPT_EMAIL=1'";
|
$sql = "replace into Config set Id = 0, Name = 'ZM_EMAIL_SUBJECT', Value = '".$email_subject."', Type = 'string', DefaultValue = 'ZoneMinder: Alarm - %MN%-%EI% (%ESM% - %ESA% %EFA%)', Hint = 'string', Pattern = '(?-xism:^(.+)\$)', Format = ' \$1 ', Prompt = 'The subject of the email used to send matching event details', Help = 'This option is used to define the subject of the email that is sent for any events that match the appropriate filters.', Category = 'mail', Readonly = '0', Requires = 'ZM_OPT_EMAIL=1'";
|
||||||
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
|
@ -753,8 +685,7 @@ if ( $version )
|
||||||
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
$res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
$res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||||
}
|
}
|
||||||
if ( defined(&ZM_MESSAGE_TEXT) && &ZM_MESSAGE_TEXT )
|
if ( defined(&ZM_MESSAGE_TEXT) && &ZM_MESSAGE_TEXT ) {
|
||||||
{
|
|
||||||
my ( $message_subject, $message_body ) = $Config{ZM_MESSAGE_TEXT} =~ /subject\s*=\s*"([^\n]*)".*body\s*=\s*"(.*)"?$/ms;
|
my ( $message_subject, $message_body ) = $Config{ZM_MESSAGE_TEXT} =~ /subject\s*=\s*"([^\n]*)".*body\s*=\s*"(.*)"?$/ms;
|
||||||
$sql = "replace into Config set Id = 0, Name = 'ZM_MESSAGE_SUBJECT', Value = '".$message_subject."', Type = 'string', DefaultValue = 'ZoneMinder: Alarm - %MN%-%EI%', Hint = 'string', Pattern = '(?-xism:^(.+)\$)', Format = ' \$1 ', Prompt = 'The subject of the message used to send matching event details', Help = 'This option is used to define the subject of the message that is sent for any events that match the appropriate filters.', Category = 'mail', Readonly = '0', Requires = 'ZM_OPT_MESSAGE=1'";
|
$sql = "replace into Config set Id = 0, Name = 'ZM_MESSAGE_SUBJECT', Value = '".$message_subject."', Type = 'string', DefaultValue = 'ZoneMinder: Alarm - %MN%-%EI%', Hint = 'string', Pattern = '(?-xism:^(.+)\$)', Format = ' \$1 ', Prompt = 'The subject of the message used to send matching event details', Help = 'This option is used to define the subject of the message that is sent for any events that match the appropriate filters.', Category = 'mail', Readonly = '0', Requires = 'ZM_OPT_MESSAGE=1'";
|
||||||
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
|
@ -766,20 +697,17 @@ if ( $version )
|
||||||
}
|
}
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.22.1" )
|
if ( $cascade || $version eq "1.22.1" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.22.1" );
|
patchDB( $dbh, "1.22.1" );
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.22.2" )
|
if ( $cascade || $version eq "1.22.2" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.22.2" );
|
patchDB( $dbh, "1.22.2" );
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.22.3" )
|
if ( $cascade || $version eq "1.22.3" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.22.3" );
|
patchDB( $dbh, "1.22.3" );
|
||||||
|
|
||||||
|
@ -789,15 +717,12 @@ if ( $version )
|
||||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||||
my @db_monitors;
|
my @db_monitors;
|
||||||
while( my $db_monitor = $sth->fetchrow_hashref() )
|
while( my $db_monitor = $sth->fetchrow_hashref() ) {
|
||||||
{
|
|
||||||
push( @db_monitors, $db_monitor );
|
push( @db_monitors, $db_monitor );
|
||||||
}
|
}
|
||||||
$sth->finish();
|
$sth->finish();
|
||||||
foreach my $db_monitor ( @db_monitors )
|
foreach my $db_monitor ( @db_monitors ) {
|
||||||
{
|
if ( $db_monitor->{LabelFormat} =~ /\%\%s/ ) {
|
||||||
if ( $db_monitor->{LabelFormat} =~ /\%\%s/ )
|
|
||||||
{
|
|
||||||
$db_monitor->{LabelFormat} =~ s/\%\%s/%N/;
|
$db_monitor->{LabelFormat} =~ s/\%\%s/%N/;
|
||||||
$db_monitor->{LabelFormat} =~ s/\%\%s/%Q/;
|
$db_monitor->{LabelFormat} =~ s/\%\%s/%Q/;
|
||||||
|
|
||||||
|
@ -814,25 +739,20 @@ if ( $version )
|
||||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||||
my @dbFilters;
|
my @dbFilters;
|
||||||
while( my $dbFilter = $sth->fetchrow_hashref() )
|
while( my $dbFilter = $sth->fetchrow_hashref() ) {
|
||||||
{
|
|
||||||
push( @dbFilters, $dbFilter );
|
push( @dbFilters, $dbFilter );
|
||||||
}
|
}
|
||||||
$sth->finish();
|
$sth->finish();
|
||||||
foreach my $dbFilter ( @dbFilters )
|
foreach my $dbFilter ( @dbFilters ) {
|
||||||
{
|
|
||||||
my %filter_terms;
|
my %filter_terms;
|
||||||
foreach my $filter_parm ( split( /&/, $dbFilter->{Query} ) )
|
foreach my $filter_parm ( split( /&/, $dbFilter->{Query} ) ) {
|
||||||
{
|
|
||||||
my( $key, $value ) = split( /=/, $filter_parm, 2 );
|
my( $key, $value ) = split( /=/, $filter_parm, 2 );
|
||||||
if ( $key )
|
if ( $key ) {
|
||||||
{
|
|
||||||
$filter_terms{$key} = $value;
|
$filter_terms{$key} = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
my $filter = { 'terms' => [] };
|
my $filter = { 'terms' => [] };
|
||||||
for ( my $i = 1; $i <= $filter_terms{trms}; $i++ )
|
for ( my $i = 1; $i <= $filter_terms{trms}; $i++ ) {
|
||||||
{
|
|
||||||
my $term = {};
|
my $term = {};
|
||||||
my $conjunction_name = "cnj$i";
|
my $conjunction_name = "cnj$i";
|
||||||
my $obracket_name = "obr$i";
|
my $obracket_name = "obr$i";
|
||||||
|
@ -855,11 +775,9 @@ if ( $version )
|
||||||
|
|
||||||
my $newQuery = 'a:'.int(keys(%$filter)).':{s:5:"terms";a:'.int(@{$filter->{terms}}).':{';
|
my $newQuery = 'a:'.int(keys(%$filter)).':{s:5:"terms";a:'.int(@{$filter->{terms}}).':{';
|
||||||
my $i = 0;
|
my $i = 0;
|
||||||
foreach my $term ( @{$filter->{terms}} )
|
foreach my $term ( @{$filter->{terms}} ) {
|
||||||
{
|
|
||||||
$newQuery .= 'i:'.$i.';a:'.int(keys(%$term)).':{';
|
$newQuery .= 'i:'.$i.';a:'.int(keys(%$term)).':{';
|
||||||
while ( my ( $key, $val ) = each( %$term ) )
|
while ( my ( $key, $val ) = each( %$term ) ) {
|
||||||
{
|
|
||||||
$newQuery .= 's:'.length($key).':"'.$key.'";';
|
$newQuery .= 's:'.length($key).':"'.$key.'";';
|
||||||
$newQuery .= 's:'.length($val).':"'.$val.'";';
|
$newQuery .= 's:'.length($val).':"'.$val.'";';
|
||||||
}
|
}
|
||||||
|
@ -867,10 +785,8 @@ if ( $version )
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
$newQuery .= '}';
|
$newQuery .= '}';
|
||||||
foreach my $field ( "sort_field", "sort_asc", "limit" )
|
foreach my $field ( "sort_field", "sort_asc", "limit" ) {
|
||||||
{
|
if ( defined($filter->{$field}) ) {
|
||||||
if ( defined($filter->{$field}) )
|
|
||||||
{
|
|
||||||
$newQuery .= 's:'.length($field).':"'.$field.'";';
|
$newQuery .= 's:'.length($field).':"'.$field.'";';
|
||||||
$newQuery .= 's:'.length($filter->{$field}).':"'.$filter->{$field}.'";';
|
$newQuery .= 's:'.length($filter->{$field}).':"'.$filter->{$field}.'";';
|
||||||
}
|
}
|
||||||
|
@ -893,52 +809,43 @@ if ( $version )
|
||||||
}
|
}
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.23.0" )
|
if ( $cascade || $version eq "1.23.0" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.23.0" );
|
patchDB( $dbh, "1.23.0" );
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.23.1" )
|
if ( $cascade || $version eq "1.23.1" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.23.1" );
|
patchDB( $dbh, "1.23.1" );
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.23.2" )
|
if ( $cascade || $version eq "1.23.2" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.23.2" );
|
patchDB( $dbh, "1.23.2" );
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.23.3" )
|
if ( $cascade || $version eq "1.23.3" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.23.3" );
|
patchDB( $dbh, "1.23.3" );
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.24.0" )
|
if ( $cascade || $version eq "1.24.0" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.24.0" );
|
patchDB( $dbh, "1.24.0" );
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.24.1" )
|
if ( $cascade || $version eq "1.24.1" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.24.1" );
|
patchDB( $dbh, "1.24.1" );
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.24.2" )
|
if ( $cascade || $version eq "1.24.2" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.24.2" );
|
patchDB( $dbh, "1.24.2" );
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.24.3" )
|
if ( $cascade || $version eq "1.24.3" ) {
|
||||||
{
|
my $result = eval {
|
||||||
my $result = eval
|
|
||||||
{
|
|
||||||
require PHP::Serialization;
|
require PHP::Serialization;
|
||||||
PHP::Serialization->import();
|
PHP::Serialization->import();
|
||||||
};
|
};
|
||||||
|
@ -954,13 +861,11 @@ if ( $version )
|
||||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||||
my @dbFilters;
|
my @dbFilters;
|
||||||
while( my $dbFilter = $sth->fetchrow_hashref() )
|
while( my $dbFilter = $sth->fetchrow_hashref() ) {
|
||||||
{
|
|
||||||
push( @dbFilters, $dbFilter );
|
push( @dbFilters, $dbFilter );
|
||||||
}
|
}
|
||||||
$sth->finish();
|
$sth->finish();
|
||||||
foreach my $dbFilter ( @dbFilters )
|
foreach my $dbFilter ( @dbFilters ) {
|
||||||
{
|
|
||||||
print( " ".$dbFilter->{Name} );
|
print( " ".$dbFilter->{Name} );
|
||||||
eval {
|
eval {
|
||||||
my $phpQuery = $dbFilter->{Query};
|
my $phpQuery = $dbFilter->{Query};
|
||||||
|
@ -970,13 +875,10 @@ if ( $version )
|
||||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
my $res = $sth->execute( $jsonQuery, $dbFilter->{Name} ) or die( "Can't execute: ".$sth->errstr() );
|
my $res = $sth->execute( $jsonQuery, $dbFilter->{Name} ) or die( "Can't execute: ".$sth->errstr() );
|
||||||
};
|
};
|
||||||
if ( $@ )
|
if ( $@ ) {
|
||||||
{
|
|
||||||
print( " - failed, please check or report. Query is '".$dbFilter->{Query}."'\n" );
|
print( " - failed, please check or report. Query is '".$dbFilter->{Query}."'\n" );
|
||||||
print( $@ );
|
print( $@ );
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
print( " - complete\n" );
|
print( " - complete\n" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -984,8 +886,7 @@ if ( $version )
|
||||||
}
|
}
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version eq "1.24.4" )
|
if ( $cascade || $version eq "1.24.4" ) {
|
||||||
{
|
|
||||||
# Patch the database
|
# Patch the database
|
||||||
patchDB( $dbh, "1.24.4" );
|
patchDB( $dbh, "1.24.4" );
|
||||||
|
|
||||||
|
@ -995,15 +896,13 @@ if ( $version )
|
||||||
my $updateSql = "update Config set Value = ? where Name = ?";
|
my $updateSql = "update Config set Value = ? where Name = ?";
|
||||||
my $updateSth = $dbh->prepare_cached( $updateSql ) or die( "Can't prepare '$updateSql': ".$dbh->errstr() );
|
my $updateSth = $dbh->prepare_cached( $updateSql ) or die( "Can't prepare '$updateSql': ".$dbh->errstr() );
|
||||||
my $fetchRes = $fetchSth->execute() or die( "Can't execute: ".$fetchSth->errstr() );
|
my $fetchRes = $fetchSth->execute() or die( "Can't execute: ".$fetchSth->errstr() );
|
||||||
while( my $config = $fetchSth->fetchrow_hashref() )
|
while( my $config = $fetchSth->fetchrow_hashref() ) {
|
||||||
{
|
|
||||||
( my $name = $config->{Name} ) =~ s/_FTP_/_/;
|
( my $name = $config->{Name} ) =~ s/_FTP_/_/;
|
||||||
my $updateRes = $updateSth->execute( $config->{Value}, $name ) or die( "Can't execute: ".$updateSth->errstr() );
|
my $updateRes = $updateSth->execute( $config->{Value}, $name ) or die( "Can't execute: ".$updateSth->errstr() );
|
||||||
}
|
}
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
}
|
}
|
||||||
if ( $cascade || $version lt "1.26.0" )
|
if ( $cascade || $version lt "1.26.0" ) {
|
||||||
{
|
|
||||||
my $sth = $dbh->prepare_cached( 'select * from Monitors LIMIT 0,1' );
|
my $sth = $dbh->prepare_cached( 'select * from Monitors LIMIT 0,1' );
|
||||||
die "Error: " . $dbh->errstr . "\n" unless ($sth);
|
die "Error: " . $dbh->errstr . "\n" unless ($sth);
|
||||||
die "Error: " . $sth->errstr . "\n" unless ($sth->execute);
|
die "Error: " . $sth->errstr . "\n" unless ($sth->execute);
|
||||||
|
@ -1017,7 +916,6 @@ if ( $version )
|
||||||
} # end if
|
} # end if
|
||||||
$sth->finish();
|
$sth->finish();
|
||||||
|
|
||||||
|
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
$version = '1.26.0';
|
$version = '1.26.0';
|
||||||
}
|
}
|
||||||
|
@ -1056,17 +954,14 @@ if ( $version )
|
||||||
$cascade = !undef;
|
$cascade = !undef;
|
||||||
} # end if
|
} # end if
|
||||||
|
|
||||||
if ( $cascade )
|
if ( $cascade ) {
|
||||||
{
|
|
||||||
my $installed_version = ZM_VERSION;
|
my $installed_version = ZM_VERSION;
|
||||||
my $sql = "update Config set Value = ? where Name = ?";
|
my $sql = "update Config set Value = ? where Name = ?";
|
||||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
my $res = $sth->execute( "$installed_version", "ZM_DYN_DB_VERSION" ) or die( "Can't execute: ".$sth->errstr() );
|
my $res = $sth->execute( "$installed_version", "ZM_DYN_DB_VERSION" ) or die( "Can't execute: ".$sth->errstr() );
|
||||||
$res = $sth->execute( "$installed_version", "ZM_DYN_CURR_VERSION" ) or die( "Can't execute: ".$sth->errstr() );
|
$res = $sth->execute( "$installed_version", "ZM_DYN_CURR_VERSION" ) or die( "Can't execute: ".$sth->errstr() );
|
||||||
$sth->finish();
|
$sth->finish();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
zmDbDisconnect();
|
zmDbDisconnect();
|
||||||
die( "Can't find upgrade from version '$version'" );
|
die( "Can't find upgrade from version '$version'" );
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
define( "ZM_CONFIG", "@ZM_CONFIG@" ); // Path to config file
|
define( "ZM_CONFIG", "@ZM_CONFIG@" ); // Path to config file
|
||||||
// Define, and override any given in config file
|
// Define, and override any given in config file
|
||||||
define( "ZM_VERSION", "@VERSION@" ); // Version
|
define( "ZM_VERSION", "@VERSION@" ); // Version
|
||||||
|
define( "ZM_DIR_TEMP", "@ZM_TMPDIR@" );
|
||||||
|
|
||||||
$configFile = ZM_CONFIG;
|
$configFile = ZM_CONFIG;
|
||||||
$localConfigFile = basename($configFile);
|
$localConfigFile = basename($configFile);
|
||||||
|
|
|
@ -890,7 +890,7 @@ function exportEvents( $eids, $exportDetail, $exportFrames, $exportImages, $expo
|
||||||
{
|
{
|
||||||
$eids = array($eids);
|
$eids = array($eids);
|
||||||
}
|
}
|
||||||
$monitorPath = 'events/';
|
$monitorPath = ZM_DIR_EVENTS."/";
|
||||||
$html_eventMaster = 'zmEventImagesMaster_'.date('Ymd_His'). '.html';
|
$html_eventMaster = 'zmEventImagesMaster_'.date('Ymd_His'). '.html';
|
||||||
if ( !($fp = fopen( $monitorPath."/".$html_eventMaster, "w" )) ) Fatal( "Can't open event images export file '$html_eventMaster'" );
|
if ( !($fp = fopen( $monitorPath."/".$html_eventMaster, "w" )) ) Fatal( "Can't open event images export file '$html_eventMaster'" );
|
||||||
fwrite( $fp, exportEventImagesMaster( $eids ) );
|
fwrite( $fp, exportEventImagesMaster( $eids ) );
|
||||||
|
@ -898,7 +898,7 @@ function exportEvents( $eids, $exportDetail, $exportFrames, $exportImages, $expo
|
||||||
$exportFileList[] = $monitorPath."/".$html_eventMaster;
|
$exportFileList[] = $monitorPath."/".$html_eventMaster;
|
||||||
}
|
}
|
||||||
|
|
||||||
$listFile = "temp/".$export_listFile;
|
$listFile = ZM_DIR_EXPORTS."/".$export_listFile;
|
||||||
if ( !($fp = fopen( $listFile, "w" )) )
|
if ( !($fp = fopen( $listFile, "w" )) )
|
||||||
{
|
{
|
||||||
Fatal( "Can't open event export list file '$listFile'" );
|
Fatal( "Can't open event export list file '$listFile'" );
|
||||||
|
@ -911,7 +911,7 @@ function exportEvents( $eids, $exportDetail, $exportFrames, $exportImages, $expo
|
||||||
$archive = "";
|
$archive = "";
|
||||||
if ( $exportFormat == "tar" )
|
if ( $exportFormat == "tar" )
|
||||||
{
|
{
|
||||||
$archive = "temp/".$export_root.".tar.gz";
|
$archive = ZM_DIR_EXPORTS."/".$export_root.".tar.gz";
|
||||||
@unlink( $archive );
|
@unlink( $archive );
|
||||||
$command = "tar --create --gzip --file=$archive --files-from=$listFile";
|
$command = "tar --create --gzip --file=$archive --files-from=$listFile";
|
||||||
exec( escapeshellcmd( $command ), $output, $status );
|
exec( escapeshellcmd( $command ), $output, $status );
|
||||||
|
@ -925,8 +925,7 @@ function exportEvents( $eids, $exportDetail, $exportFrames, $exportImages, $expo
|
||||||
}
|
}
|
||||||
elseif ( $exportFormat == "zip" )
|
elseif ( $exportFormat == "zip" )
|
||||||
{
|
{
|
||||||
$archive = "temp/zm_export.zip";
|
$archive = ZM_DIR_EXPORTS."/".$export_root.".zip";
|
||||||
$archive = "temp/".$export_root.".zip";
|
|
||||||
@unlink( $archive );
|
@unlink( $archive );
|
||||||
$command = "cat ".escapeshellarg($listFile)." | zip -q ".escapeshellarg($archive)." -@";
|
$command = "cat ".escapeshellarg($listFile)." | zip -q ".escapeshellarg($archive)." -@";
|
||||||
//cat zmFileList.txt | zip -q zm_export.zip -@
|
//cat zmFileList.txt | zip -q zm_export.zip -@
|
||||||
|
@ -948,7 +947,7 @@ function exportEvents( $eids, $exportDetail, $exportFrames, $exportImages, $expo
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return( $archive );
|
return( '?view=archive%26type='.$exportFormat );
|
||||||
}
|
}
|
||||||
function mygetEventPath( $event )
|
function mygetEventPath( $event )
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
<?php
|
||||||
|
//
|
||||||
|
// ZoneMinder file view file, $Date: 2008-09-29 14:15:13 +0100 (Mon, 29 Sep 2008) $, $Revision: 2640 $
|
||||||
|
// Copyright (C) 2001-2008 Philip Coombes
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU General Public License
|
||||||
|
// as published by the Free Software Foundation; either version 2
|
||||||
|
// of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
//
|
||||||
|
|
||||||
|
if ( !canView( 'Events' ) )
|
||||||
|
{
|
||||||
|
$view = "error";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$archivetype = $_REQUEST['type'];
|
||||||
|
|
||||||
|
if ( $archivetype ) {
|
||||||
|
switch ($archivetype) {
|
||||||
|
case "tar":
|
||||||
|
$mimetype = "gzip";
|
||||||
|
$file_ext = "tar.gz";
|
||||||
|
break;
|
||||||
|
case "zip":
|
||||||
|
$mimetype = "zip";
|
||||||
|
$file_ext = "zip";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$mimetype = NULL;
|
||||||
|
$file_ext = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $mimetype ) {
|
||||||
|
$filename = "zmExport.$file_ext";
|
||||||
|
$filename_path = ZM_DIR_TEMP."/".$filename;
|
||||||
|
if ( is_readable($filename_path) ) {
|
||||||
|
header( "Content-type: application/$mimetype" );
|
||||||
|
header( "Content-Disposition: attachment; filename=$filename");
|
||||||
|
readfile( $filename_path );
|
||||||
|
} else {
|
||||||
|
Error("$filename_path does not exist or is not readable.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Error("Unsupported archive type specified. Supported archives are tar and zip");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Error("No archive type given to archive.php. Please specify a tar or zip archive.");
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
Loading…
Reference in New Issue