From 54b8cce5e4c3f793caa77905f30e21236cab2ab9 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 11 Sep 2017 16:57:51 -0400 Subject: [PATCH 01/98] fix tabs to spaces --- web/skins/classic/views/monitor.php | 139 ++++++++++++++-------------- 1 file changed, 69 insertions(+), 70 deletions(-) diff --git a/web/skins/classic/views/monitor.php b/web/skins/classic/views/monitor.php index fae0f4a68..35faa3fce 100644 --- a/web/skins/classic/views/monitor.php +++ b/web/skins/classic/views/monitor.php @@ -153,14 +153,14 @@ function fourcc( $a, $b, $c, $d ) { } if ( isset( $_REQUEST['newMonitor'] ) ) { - # Update the monitor object with whatever has been set so far. + # Update the monitor object with whatever has been set so far. $monitor->set( $_REQUEST['newMonitor'] ); if ( ZM_OPT_X10 ) $newX10Monitor = $_REQUEST['newX10Monitor']; } else { - # FIXME: Triggers in the db is a comma separated string. Needs to be an array. - #$monitor->Triggers()= explode( ',', isset($monitor->Triggers())?$monitor->Triggers:"" ); + # FIXME: Triggers in the db is a comma separated string. Needs to be an array. + #$monitor->Triggers()= explode( ',', isset($monitor->Triggers())?$monitor->Triggers:"" ); if ( ZM_OPT_X10 ) $newX10Monitor = $x10Monitor; } @@ -176,9 +176,9 @@ if ( $monitor->AlarmMaxFPS() == '0.00' ) if ( !empty($_REQUEST['preset']) ) { $preset = dbFetchOne( 'SELECT Type, Device, Channel, Format, Protocol, Method, Host, Port, Path, Width, Height, Palette, MaxFPS, Controllable, ControlId, ControlDevice, ControlAddress, DefaultRate, DefaultScale FROM MonitorPresets WHERE Id = ?', NULL, array($_REQUEST['preset']) ); foreach ( $preset as $name=>$value ) { - # Does isset handle NULL's? I don't think this code is correct. + # Does isset handle NULL's? I don't think this code is correct. if ( isset($value) ) { - $monitor->$name = $value; + $monitor->$name = $value; } } } @@ -186,17 +186,17 @@ if ( !empty($_REQUEST['probe']) ) { $probe = unserialize(base64_decode($_REQUEST['probe'])); foreach ( $probe as $name=>$value ) { if ( isset($value) ) { - # Does isset handle NULL's? I don't think this code is correct. - $monitor->$name = $value; + # Does isset handle NULL's? I don't think this code is correct. + $monitor->$name = $value; } } - if ( ZM_HAS_V4L && $monitor->Type() == 'Local' ) { - $monitor->Palette( fourCC( substr($monitor->Palette,0,1), substr($monitor->Palette,1,1), substr($monitor->Palette,2,1), substr($monitor->Palette,3,1) ) ); - if ( $monitor->Format() == 'PAL' ) - $monitor->Format( 0x000000ff ); - elseif ( $monitor->Format() == 'NTSC' ) - $monitor->Format( 0x0000b000 ); - } + if ( ZM_HAS_V4L && $monitor->Type() == 'Local' ) { + $monitor->Palette( fourCC( substr($monitor->Palette,0,1), substr($monitor->Palette,1,1), substr($monitor->Palette,2,1), substr($monitor->Palette,3,1) ) ); + if ( $monitor->Format() == 'PAL' ) + $monitor->Format( 0x000000ff ); + elseif ( $monitor->Format() == 'NTSC' ) + $monitor->Format( 0x0000b000 ); + } } $sourceTypes = array( @@ -681,7 +681,7 @@ switch ( $tab ) { Type() ); ?> Enabled() ) { ?> checked="checked"/> - - - LinkedMonitors() ) - $monitorIds = array_flip( explode( ',', $monitor->LinkedMonitors()) ); - else - $monitorIds = array(); - foreach ( $monitors as $linked_monitor ) { - if ( (!$monitor->Id() || ($monitor->Id()!= $linked_monitor['Id'])) && visibleMonitor( $linked_monitor['Id'] ) ) { + $monitors = dbFetchAll( 'select Id,Name from Monitors order by Sequence asc' ); + if ( $monitor->LinkedMonitors() ) + $monitorIds = array_flip( explode( ',', $monitor->LinkedMonitors()) ); + else + $monitorIds = array(); + foreach ( $monitors as $linked_monitor ) { + if ( (!$monitor->Id() || ($monitor->Id()!= $linked_monitor['Id'])) && visibleMonitor( $linked_monitor['Id'] ) ) { ?> - + - - + + Method() == 'v4l1' ) { ?> - - - + + + - - - + + + - V4LMultiBuffer() == 1 ? 'checked="checked"' : '' ) ?>/> - - V4LMultiBuffer() == 0 ? 'checked="checked"' : '' ) ?>/> - - V4LMultiBuffer() ? 'checked="checked"' : '' ) ?>/> - + V4LMultiBuffer() == 1 ? 'checked="checked"' : '' ) ?>/> + + V4LMultiBuffer() == 0 ? 'checked="checked"' : '' ) ?>/> + + V4LMultiBuffer() ? 'checked="checked"' : '' ) ?>/> + Protocol(), "updateMethods( this );if(this.value=='rtsp'){\$('RTSPDescribe').setStyle('display','table-row');}else{\$('RTSPDescribe').hide();}" ); ?> Protocol() || $monitor->Protocol() == 'http' ) { + if ( !$monitor->Protocol() || $monitor->Protocol() == 'http' ) { ?> - Method() ); ?> + Method() ); ?> @@ -856,7 +856,7 @@ switch ( $tab ) { - + @@ -940,41 +940,41 @@ switch ( $tab ) { + DefaultRate() ); ?> DefaultScale() ); ?> Type() == 'Local' ) { + if ( ZM_HAS_V4L && $monitor->Type() == 'Local' ) { ?> - - - - -      - - + + + + +      + + - - - -      - - + + + +      + + -  () - Exif() ) { ?> checked="checked"/> - +  () + Exif() ) { ?> checked="checked"/> + " disabled="disabled"/> - From 104bf07c5a47056c027503892604f63228414752 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 11 Sep 2017 21:52:22 -0400 Subject: [PATCH 02/98] fix pod docs --- scripts/zmpkg.pl.in | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/zmpkg.pl.in b/scripts/zmpkg.pl.in index 597d7ac1a..3313d29a3 100644 --- a/scripts/zmpkg.pl.in +++ b/scripts/zmpkg.pl.in @@ -35,6 +35,7 @@ This script is used to start and stop the ZoneMinder package primarily to allow command line control for automatic restart on reboot (see zm script) =cut + use strict; use bytes; From 5516a62a0e36b6f89ebe41aa62f7216fb8fd66ab Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 11 Sep 2017 22:12:10 -0400 Subject: [PATCH 03/98] google code style, switch quotes --- scripts/zmpkg.pl.in | 563 ++++++++++++++++++++------------------------ 1 file changed, 257 insertions(+), 306 deletions(-) diff --git a/scripts/zmpkg.pl.in b/scripts/zmpkg.pl.in index 3313d29a3..bc57430f4 100644 --- a/scripts/zmpkg.pl.in +++ b/scripts/zmpkg.pl.in @@ -21,21 +21,6 @@ # # ========================================================================== -=head1 NAME - -zmpkg.pl - ZoneMinder Package Control Script - -=head1 SYNOPSIS - - zmpkg.pl {start|stop|restart|status|logrot|'state'|version} - -=head1 DESCRIPTION - -This script is used to start and stop the ZoneMinder package primarily to -allow command line control for automatic restart on reboot (see zm script) - -=cut - use strict; use bytes; @@ -62,48 +47,41 @@ logInit(); my $command = $ARGV[0]||''; if ( $command eq 'version' ) { - print ZoneMinder::Base::ZM_VERSION . "\n"; - exit(0); + print ZoneMinder::Base::ZM_VERSION . "\n"; + exit(0); } my $state; my $dbh; -if ( !$command || $command !~ /^(?:start|stop|restart|status|logrot|version)$/ ) -{ - if ( $command ) - { - $dbh = zmDbConnect(); - # Check to see if it's a valid run state - my $sql = 'select * from States where Name = ?'; - my $sth = $dbh->prepare_cached( $sql ) - or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res = $sth->execute( $command ) - or Fatal( "Can't execute: ".$sth->errstr() ); - if ( $state = $sth->fetchrow_hashref() ) - { - $state->{Name} = $command; - $state->{Definitions} = []; - foreach( split( /,/, $state->{Definition} ) ) - { - my ( $id, $function, $enabled ) = split( /:/, $_ ); - push( @{$state->{Definitions}}, - { Id=>$id, Function=>$function, Enabled=>$enabled } - ); - } - $store_state=$command; # PP - Remember the name that was passed to search in DB - $command = 'state'; - } - else - { - $command = undef; - } - } - if ( !$command ) - { - pod2usage(-exitstatus => -1); +if ( !$command || $command !~ /^(?:start|stop|restart|status|logrot|version)$/ ) { + if ( $command ) { + $dbh = zmDbConnect(); +# Check to see if it's a valid run state + my $sql = 'SELECT * FROM States WHERE Name=?'; + my $sth = $dbh->prepare_cached( $sql ) + or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); + my $res = $sth->execute( $command ) + or Fatal( "Can't execute: ".$sth->errstr() ); + if ( $state = $sth->fetchrow_hashref() ) { + $state->{Name} = $command; + $state->{Definitions} = []; + foreach( split( /,/, $state->{Definition} ) ) { + my ( $id, $function, $enabled ) = split( /:/, $_ ); + push( @{$state->{Definitions}}, + { Id=>$id, Function=>$function, Enabled=>$enabled } + ); + } + $store_state=$command; # PP - Remember the name that was passed to search in DB + $command = 'state'; + } else { + $command = undef; } + } + if ( !$command ) { + pod2usage(-exitstatus => -1); + } } $dbh = zmDbConnect() if ! $dbh; # PP - Sane state check @@ -111,324 +89,297 @@ isActiveSanityCheck(); # Move to the right place chdir( $Config{ZM_PATH_WEB} ) - or Fatal( "Can't chdir to '".$Config{ZM_PATH_WEB}."': $!" ); + or Fatal( "Can't chdir to '".$Config{ZM_PATH_WEB}."': $!" ); -my $dbg_id = ""; + my $dbg_id = ''; -Info( "Command: $command\n" ); + Info( "Command: $command\n" ); -my $retval = 0; + my $retval = 0; -if ( $command eq "state" ) -{ + if ( $command eq 'state' ) { Info( "Updating DB: $state->{Name}\n" ); my $sql = $Config{ZM_SERVER_ID} ? 'SELECT * FROM Monitors WHERE ServerId=? ORDER BY Id ASC' : 'SELECT * FROM Monitors ORDER BY Id ASC'; my $sth = $dbh->prepare_cached( $sql ) - or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); + or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); my $res = $sth->execute( $Config{ZM_SERVER_ID} ? $Config{ZM_SERVER_ID}: () ) - or Fatal( "Can't execute: ".$sth->errstr() ); - while( my $monitor = $sth->fetchrow_hashref() ) - { - foreach my $definition ( @{$state->{Definitions}} ) - { - if ( $monitor->{Id} =~ /^$definition->{Id}$/ ) - { - $monitor->{NewFunction} = $definition->{Function}; - $monitor->{NewEnabled} = $definition->{Enabled}; - } - } - #next if ( !$monitor->{NewFunction} ); - $monitor->{NewFunction} = 'None' - if ( !$monitor->{NewFunction} ); - $monitor->{NewEnabled} = 0 - if ( !$monitor->{NewEnabled} ); - if ( $monitor->{Function} ne $monitor->{NewFunction} - || $monitor->{Enabled} ne $monitor->{NewEnabled} - ) - { - my $sql = "update Monitors set Function = ?, Enabled = ? where Id = ?"; - my $sth = $dbh->prepare_cached( $sql ) - or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res = $sth->execute( $monitor->{NewFunction}, $monitor->{NewEnabled}, $monitor->{Id} ) - or Fatal( "Can't execute: ".$sth->errstr() ); + or Fatal( "Can't execute: ".$sth->errstr() ); + while( my $monitor = $sth->fetchrow_hashref() ) { + foreach my $definition ( @{$state->{Definitions}} ) { + if ( $monitor->{Id} =~ /^$definition->{Id}$/ ) { + $monitor->{NewFunction} = $definition->{Function}; + $monitor->{NewEnabled} = $definition->{Enabled}; } + } +#next if ( !$monitor->{NewFunction} ); + $monitor->{NewFunction} = 'None' + if ( !$monitor->{NewFunction} ); + $monitor->{NewEnabled} = 0 + if ( !$monitor->{NewEnabled} ); + if ( $monitor->{Function} ne $monitor->{NewFunction} + || $monitor->{Enabled} ne $monitor->{NewEnabled} + ) { + my $sql = 'UPDATE Monitors SET Function=?, Enabled=? WHERE Id=?'; + my $sth = $dbh->prepare_cached( $sql ) + or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); + my $res = $sth->execute( $monitor->{NewFunction}, $monitor->{NewEnabled}, $monitor->{Id} ) + or Fatal( "Can't execute: ".$sth->errstr() ); + } } $sth->finish(); - - # PP - Now mark a specific state as active + +# PP - Now mark a specific state as active resetStates(); Info ("Marking $store_state as Enabled"); - $sql = "update States set IsActive = '1' where Name = ?"; + $sql = "UPDATE States SET IsActive = '1' WHERE Name = ?"; $sth = $dbh->prepare_cached( $sql ) - or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); + or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); $res = $sth->execute( $store_state ) - or Fatal( "Can't execute: ".$sth->errstr() ); + or Fatal( "Can't execute: ".$sth->errstr() ); - # PP - zero out other states isActive - $command = "restart"; -} +# PP - zero out other states isActive + $command = 'restart'; + } # Check if we are running systemd and if we have been called by the system -if ( $command =~ /^(start|stop|restart)$/ ) -{ - # We have to detaint to keep perl from complaining - $command = $1; +if ( $command =~ /^(start|stop|restart)$/ ) { +# We have to detaint to keep perl from complaining + $command = $1; - - if ( systemdRunning() && !calledBysystem() ) { - qx(@BINDIR@/zmsystemctl.pl $command); - $command = ""; - } + if ( systemdRunning() && !calledBysystem() ) { + qx(@BINDIR@/zmsystemctl.pl $command); + $command = ''; + } } -if ( $command =~ /^(?:stop|restart)$/ ) -{ - my $status = runCommand( "zmdc.pl check" ); +if ( $command =~ /^(?:stop|restart)$/ ) { + my $status = runCommand('zmdc.pl check'); - if ( $status eq "running" ) - { - runCommand( "zmdc.pl shutdown" ); - zmMemTidy(); - } - else - { - $retval = 1; - } + if ( $status eq 'running' ) { + runCommand('zmdc.pl shutdown'); + zmMemTidy(); + } else { + $retval = 1; + } } #runCommand( "zmupdate.pl -f" ); -if ( $command =~ /^(?:start|restart)$/ ) -{ - my $status = runCommand( "zmdc.pl check" ); +if ( $command =~ /^(?:start|restart)$/ ) { + my $status = runCommand('zmdc.pl check'); - if ( $status eq "stopped" ) - { - if ( $Config{ZM_DYN_DB_VERSION} - and ( $Config{ZM_DYN_DB_VERSION} ne ZM_VERSION ) - ) - { - Fatal( "Version mismatch, system is version ".ZM_VERSION - .", database is ".$Config{ZM_DYN_DB_VERSION} - .", please run zmupdate.pl to update." - ); - exit( -1 ); - } + if ( $status eq 'stopped' ) { + if ( $Config{ZM_DYN_DB_VERSION} + and ( $Config{ZM_DYN_DB_VERSION} ne ZM_VERSION ) + ) { + Fatal( 'Version mismatch, system is version '.ZM_VERSION + .', database is '.$Config{ZM_DYN_DB_VERSION} + .', please run zmupdate.pl to update.' + ); + exit( -1 ); + } - # Recreate the temporary directory if it's been wiped - verifyFolder("@ZM_TMPDIR@"); +# Recreate the temporary directory if it's been wiped + verifyFolder('@ZM_TMPDIR@'); - # Recreate the run directory if it's been wiped - verifyFolder("@ZM_RUNDIR@"); +# Recreate the run directory if it's been wiped + verifyFolder('@ZM_RUNDIR@'); - # Recreate the sock directory if it's been wiped - verifyFolder("@ZM_SOCKDIR@"); +# Recreate the sock directory if it's been wiped + verifyFolder('@ZM_SOCKDIR@'); - zmMemTidy(); - runCommand( "zmdc.pl startup" ); + zmMemTidy(); + runCommand('zmdc.pl startup'); - if ( $Config{ZM_SERVER_ID} ) { - Info( "Multi-server configuration detected. Starting up services for server $Config{ZM_SERVER_ID}\n"); + if ( $Config{ZM_SERVER_ID} ) { + Info("Multi-server configuration detected. Starting up services for server $Config{ZM_SERVER_ID}\n"); + } else { + Info('Single server configuration detected. Starting up services.'); + } + + my $sql = $Config{ZM_SERVER_ID} ? 'SELECT * FROM Monitors WHERE ServerId=?' : 'SELECT * FROM Monitors'; + my $sth = $dbh->prepare_cached( $sql ) + or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); + my $res = $sth->execute( $Config{ZM_SERVER_ID} ? $Config{ZM_SERVER_ID} : () ) + or Fatal( "Can't execute: ".$sth->errstr() ); + while( my $monitor = $sth->fetchrow_hashref() ) { + if ( $monitor->{Function} ne 'None' ) { + if ( $monitor->{Type} eq 'Local' ) { + runCommand( "zmdc.pl start zmc -d $monitor->{Device}" ); } else { - Info( "Single server configuration detected. Starting up services." ); + runCommand( "zmdc.pl start zmc -m $monitor->{Id}" ); } - - my $sql = $Config{ZM_SERVER_ID} ? 'SELECT * FROM Monitors WHERE ServerId=?' : 'SELECT * FROM Monitors'; - my $sth = $dbh->prepare_cached( $sql ) - or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res = $sth->execute( $Config{ZM_SERVER_ID} ? $Config{ZM_SERVER_ID} : () ) - or Fatal( "Can't execute: ".$sth->errstr() ); - while( my $monitor = $sth->fetchrow_hashref() ) - { - if ( $monitor->{Function} ne 'None' ) - { - if ( $monitor->{Type} eq 'Local' ) - { - runCommand( "zmdc.pl start zmc -d $monitor->{Device}" ); - } - else - { - runCommand( "zmdc.pl start zmc -m $monitor->{Id}" ); - } - if ( $monitor->{Function} ne 'Monitor' ) - { - runCommand( "zmdc.pl start zma -m $monitor->{Id}" ); - } - if ( $Config{ZM_OPT_CONTROL} ) - { - if ( $monitor->{Function} eq 'Modect' || $monitor->{Function} eq 'Mocord' ) - { - if ( $monitor->{Controllable} && $monitor->{TrackMotion} ) - { - runCommand( "zmdc.pl start zmtrack.pl -m $monitor->{Id}" ); - } - } - } + if ( $monitor->{Function} ne 'Monitor' ) { + runCommand( "zmdc.pl start zma -m $monitor->{Id}" ); + } + if ( $Config{ZM_OPT_CONTROL} ) { + if ( $monitor->{Function} eq 'Modect' || $monitor->{Function} eq 'Mocord' ) { + if ( $monitor->{Controllable} && $monitor->{TrackMotion} ) { + runCommand( "zmdc.pl start zmtrack.pl -m $monitor->{Id}" ); } + } } - $sth->finish(); + } + } + $sth->finish(); - # This is now started unconditionally - runCommand( "zmdc.pl start zmfilter.pl" ); - if ( $Config{ZM_RUN_AUDIT} ) - { - runCommand( "zmdc.pl start zmaudit.pl -c" ); - } - if ( $Config{ZM_OPT_TRIGGERS} ) - { - runCommand( "zmdc.pl start zmtrigger.pl" ); - } - if ( $Config{ZM_OPT_X10} ) - { - runCommand( "zmdc.pl start zmx10.pl -c start" ); - } - runCommand( "zmdc.pl start zmwatch.pl" ); - if ( $Config{ZM_CHECK_FOR_UPDATES} ) - { - runCommand( "zmdc.pl start zmupdate.pl -c" ); - } - if ( $Config{ZM_TELEMETRY_DATA} ) - { - runCommand( "zmdc.pl start zmtelemetry.pl" ); - } +# This is now started unconditionally + runCommand('zmdc.pl start zmfilter.pl'); + if ( $Config{ZM_RUN_AUDIT} ) { + runCommand('zmdc.pl start zmaudit.pl -c'); } - else - { - $retval = 1; + if ( $Config{ZM_OPT_TRIGGERS} ) { + runCommand('zmdc.pl start zmtrigger.pl'); } + if ( $Config{ZM_OPT_X10} ) { + runCommand('zmdc.pl start zmx10.pl -c start'); + } + runCommand('zmdc.pl start zmwatch.pl'); + if ( $Config{ZM_CHECK_FOR_UPDATES} ) { + runCommand('zmdc.pl start zmupdate.pl -c'); + } + if ( $Config{ZM_TELEMETRY_DATA} ) { + runCommand('zmdc.pl start zmtelemetry.pl'); + } + } else { + $retval = 1; + } } -if ( $command eq "status" ) -{ - my $status = runCommand( "zmdc.pl check" ); +if ( $command eq 'status' ) { + my $status = runCommand('zmdc.pl check'); - print( STDOUT $status."\n" ); -} - -if ( $command eq "logrot" ) -{ - runCommand( "zmdc.pl logrot" ); + print( STDOUT $status."\n" ); +} elsif ( $command eq 'logrot' ) { + runCommand('zmdc.pl logrot'); } exit( $retval ); # PP - Make sure isActive is on and only one -sub isActiveSanityCheck -{ +sub isActiveSanityCheck { - Info ("Sanity checking States table..."); - $dbh = zmDbConnect() if ! $dbh; - - # PP - First, make sure default exists and there is only one - my $sql = "select Name from States where Name = 'default'"; - my $sth = $dbh->prepare_cached( $sql ) - or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res = $sth->execute() - or Fatal( "Can't execute: ".$sth->errstr() ); + Info ('Sanity checking States table...'); + $dbh = zmDbConnect() if ! $dbh; - if ($sth->rows != 1) # PP - no row, or too many rows. Either case is an error - { - Info( "Fixing States table - either no default state or duplicate default states" ); - $sql = "delete from States where Name = 'default'"; - $sth = $dbh->prepare_cached( $sql ) - or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - $res = $sth->execute() - or Fatal( "Can't execute: ".$sth->errstr() ); - $sql = "insert into States (Name,Definition,IsActive) VALUES ('default','','1');"; - $sth = $dbh->prepare_cached( $sql ) - or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - $res = $sth->execute() - or Fatal( "Can't execute: ".$sth->errstr() ); - } +# PP - First, make sure default exists and there is only one + my $sql = "SELECT Name FROM States WHERE Name='default'"; + my $sth = $dbh->prepare_cached( $sql ) + or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); + my $res = $sth->execute() + or Fatal( "Can't execute: ".$sth->errstr() ); + + if ($sth->rows != 1) { +# PP - no row, or too many rows. Either case is an error + Info( 'Fixing States table - either no default state or duplicate default states' ); + $sql = "DELETE FROM States WHERE Name='default'"; + $sth = $dbh->prepare_cached( $sql ) + or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); + $res = $sth->execute() + or Fatal( "Can't execute: ".$sth->errstr() ); + $sql = "INSERT INTO States (Name,Definition,IsActive) VALUES ('default','','1');"; + $sth = $dbh->prepare_cached( $sql ) + or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); + $res = $sth->execute() + or Fatal( "Can't execute: ".$sth->errstr() ); + } - # PP - Now make sure no two states have IsActive=1 - $sql = "select Name from States where IsActive = '1'"; - $sth = $dbh->prepare_cached( $sql ) - or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - $res = $sth->execute() - or Fatal( "Can't execute: ".$sth->errstr() ); +# PP - Now make sure no two states have IsActive=1 + $sql = "SELECT Name FROM States WHERE IsActive = '1'"; + $sth = $dbh->prepare_cached( $sql ) + or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); + $res = $sth->execute() + or Fatal( "Can't execute: ".$sth->errstr() ); - if ( $sth->rows != 1 ) - { - Info( "Fixing States table so only one run state is active" ); - resetStates(); - $sql = "update States set IsActive='1' WHERE Name='default'"; - $sth = $dbh->prepare_cached( $sql ) - or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - $res = $sth->execute() - or Fatal( "Can't execute: ".$sth->errstr() ); - - - } + if ( $sth->rows != 1 ) { + Info( 'Fixing States table so only one run state is active' ); + resetStates(); + $sql = "UPDATE States SET IsActive='1' WHERE Name='default'"; + $sth = $dbh->prepare_cached( $sql ) + or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); + $res = $sth->execute() + or Fatal( "Can't execute: ".$sth->errstr() ); + } } # PP - zeroes out isActive for all states -sub resetStates -{ - $dbh = zmDbConnect() if ! $dbh; - my $sql = "update States set IsActive = '0'"; - my $sth = $dbh->prepare_cached( $sql ) - or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res = $sth->execute() - or Fatal( "Can't execute: ".$sth->errstr() ); +sub resetStates { + $dbh = zmDbConnect() if ! $dbh; + my $sql = "UPDATE States SET IsActive='0'"; + my $sth = $dbh->prepare_cached( $sql ) + or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); + my $res = $sth->execute() + or Fatal( "Can't execute: ".$sth->errstr() ); } -sub systemdRunning -{ - my $result = 0; +sub systemdRunning { + my $result = 0; - my $output = qx(ps -o comm="" -p 1); - chomp( $output ); + my $output = qx(ps -o comm="" -p 1); + chomp( $output ); - if ($output =~ /systemd/) { - $result = 1; + if ( $output =~ /systemd/ ) { + $result = 1; + } + + return $result; +} + +sub calledBysystem { + my $result = 0; + my $ppid = getppid(); + + my $output = qx(ps -o comm="" -p $ppid); + chomp( $output ); + + if ($output =~ /^(?:systemd|init)$/) { + $result = 1; + } + + return $result; +} + +sub verifyFolder { + my $folder = shift; + + # Recreate the temporary directory if it's been wiped + if ( !-e $folder ) { + Debug( "Recreating directory '$folder'" ); + mkdir( $folder, 0774 ) + or Fatal( "Can't create missing temporary directory '$folder': $!" ); + my ( $runName ) = getpwuid( $> ); + if ( $runName ne $Config{ZM_WEB_USER} ) { + # Not running as web user, so should be root in which case + # chown the directory + my ( $webName, $webPass, $webUid, $webGid ) = getpwnam( $Config{ZM_WEB_USER} ) + or Fatal( "Can't get user details for web user '" + .$Config{ZM_WEB_USER}."': $!" + ); + chown( $webUid, $webGid, "$folder" ) + or Fatal( "Can't change ownership of directory '$folder' to '" + .$Config{ZM_WEB_USER}.":".$Config{ZM_WEB_GROUP}."': $!" + ); } - - return $result; + } } -sub calledBysystem -{ - my $result = 0; - my $ppid = getppid(); - - my $output = qx(ps -o comm="" -p $ppid); - chomp( $output ); - - if ($output =~ /^(?:systemd|init)$/) { - $result = 1; - } - - return $result; -} - -sub verifyFolder -{ - my $folder = shift; - - # Recreate the temporary directory if it's been wiped - if ( !-e $folder ) - { - Debug( "Recreating directory '$folder'" ); - mkdir( "$folder", 0774 ) - or Fatal( "Can't create missing temporary directory '$folder': $!" ); - my ( $runName ) = getpwuid( $> ); - if ( $runName ne $Config{ZM_WEB_USER} ) - { - # Not running as web user, so should be root in which case - # chown the directory - my ( $webName, $webPass, $webUid, $webGid ) = getpwnam( $Config{ZM_WEB_USER} ) - or Fatal( "Can't get user details for web user '" - .$Config{ZM_WEB_USER}."': $!" - ); - chown( $webUid, $webGid, "$folder" ) - or Fatal( "Can't change ownership of directory '$folder' to '" - .$Config{ZM_WEB_USER}.":".$Config{ZM_WEB_GROUP}."': $!" - ); - } - } -} +1; __END__ + +=head1 NAME + +zmpkg.pl - ZoneMinder Package Control Script + +=head1 SYNOPSIS + +zmpkg.pl {start|stop|restart|status|logrot|'state'|version} + +=head1 DESCRIPTION + + This script is used to start and stop the ZoneMinder package primarily to +allow command line control for automatic restart on reboot (see zm script) + +=cut From 9ad29f4baf5b1ed147e6f45b4cfe3d53c7dc7d40 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 11 Sep 2017 22:19:49 -0400 Subject: [PATCH 04/98] fix and move pod to bottom --- scripts/zmaudit.pl.in | 53 ++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/scripts/zmaudit.pl.in b/scripts/zmaudit.pl.in index 6cf2af2e3..367511a44 100644 --- a/scripts/zmaudit.pl.in +++ b/scripts/zmaudit.pl.in @@ -21,32 +21,6 @@ # # ========================================================================== -=head1 NAME - -zmaudit.pl - ZoneMinder event file system and database consistency checker - -=head1 SYNOPSIS - - zmaudit.pl [-r,-report|-i,-interactive] - -=head1 DESCRIPTION - -This script checks for consistency between the event filesystem and -the database. If events are found in one and not the other they are -deleted (optionally). Additionally any monitor event directories that -do not correspond to a database monitor are similarly disposed of. -However monitors in the database that don't have a directory are left -alone as this is valid if they are newly created and have no events -yet. - -=head1 OPTIONS - - -c, --continuous - Run continuously - -i, --interactive - Ask before applying any changes - -r, --report - Just report don't actually do anything - -v, --version - Print the installed version of ZoneMinder - -=cut use strict; use bytes; @@ -562,3 +536,30 @@ sub deleteSwapImage { 1; __END__ + +=head1 NAME + +zmaudit.pl - ZoneMinder event file system and database consistency checker + +=head1 SYNOPSIS + + zmaudit.pl [-r,-report|-i,-interactive] + +=head1 DESCRIPTION + +This script checks for consistency between the event filesystem and +the database. If events are found in one and not the other they are +deleted (optionally). Additionally any monitor event directories that +do not correspond to a database monitor are similarly disposed of. +However monitors in the database that don't have a directory are left +alone as this is valid if they are newly created and have no events +yet. + +=head1 OPTIONS + + -c, --continuous - Run continuously + -i, --interactive - Ask before applying any changes + -r, --report - Just report don't actually do anything + -v, --version - Print the installed version of ZoneMinder + +=cut From 6cbab6e68bfb9de5d266c04f1fae56d31cd41821 Mon Sep 17 00:00:00 2001 From: DeathByKorea Date: Sat, 23 Sep 2017 18:46:40 +0100 Subject: [PATCH 05/98] Added Arch AUR package (#1986) Package is well maintained, [Arch Wiki page](https://wiki.archlinux.org/index.php/ZoneMinder) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4c318b659..75561bbcd 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ This is the recommended method to install ZoneMinder onto your system. ZoneMinde - Fedora via [RPM Fusion](http://rpmfusion.org) - OpenSuse via [third party repository](http://www.zoneminder.com/wiki/index.php/Installing_using_ZoneMinder_RPMs_for_SuSE) - Mageia from their default repository +- Arch via the [AUR](https://aur.archlinux.org/packages/zoneminder/) If a repository that hosts ZoneMinder packages is not available for your distro, then you are encouraged to build your own package, rather than build from source. While each distro is different in ways that set it apart from all the others, they are often similar enough to allow you to adapt another distro's package building instructions to your own. From d83b9ce622948050b60cbbf41781d2fe28817016 Mon Sep 17 00:00:00 2001 From: Steve Gilvarry Date: Fri, 29 Sep 2017 08:03:39 +1000 Subject: [PATCH 06/98] Fixes #1983 (#1989) Fair point here we put a command it should run, but I have added assistance with this part of the install is not zoneminder specific --- docs/installationguide/ubuntu.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/installationguide/ubuntu.rst b/docs/installationguide/ubuntu.rst index e561e7477..fe95754d1 100644 --- a/docs/installationguide/ubuntu.rst +++ b/docs/installationguide/ubuntu.rst @@ -15,9 +15,11 @@ achieve the same result by running: :: - tasksel install lamp-server + sudo tasksel install lamp-server During installation it will ask you to set up a master/root password for the MySQL. +Installing LAMP is not ZoneMinder specific so you will find plenty of resources to +guide you with a quick search. **Step 1:** Either run commands in this install using sudo or use the below to become root :: From 9c40f65757e7f41dcd1521b7528c28ee13c78801 Mon Sep 17 00:00:00 2001 From: Steve Gilvarry Date: Fri, 29 Sep 2017 11:20:20 +1000 Subject: [PATCH 07/98] Fix user language setting never being used https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=858675 pointed here https://forums.zoneminder.com/viewtopic.php?t=19403 Checked and sure enough was still there not pointing to the lang folder. --- web/includes/lang.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/includes/lang.php b/web/includes/lang.php index b5dbda09d..0cab566b7 100644 --- a/web/includes/lang.php +++ b/web/includes/lang.php @@ -37,7 +37,7 @@ function loadLanguage( $prefix="" ) $fallbackLangFile = $prefix.'lang/en_gb.php'; $systemLangFile = $prefix.'lang/'.ZM_LANG_DEFAULT.'.php'; if ( isset($user['Language']) ) - $userLangFile = $prefix.$user['Language'].'.php'; + $userLangFile = $prefix.'lang/'.$user['Language'].'.php'; if ( isset($userLangFile) && file_exists( $userLangFile ) ) return( $userLangFile ); From de6f8de3f8cfd9aebd2556454de21a6fc4862563 Mon Sep 17 00:00:00 2001 From: MalakymR Date: Wed, 4 Oct 2017 12:41:44 +0100 Subject: [PATCH 08/98] Include Gentoo ebuild (#1993) package: https://packages.gentoo.org/packages/www-misc/zoneminder wiki: https://wiki.gentoo.org/wiki/ZoneMinder Currently at 1.30.2, PR pending for .4 Will be a -9999 ebuild to track git soon as well. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 75561bbcd..1d43ff560 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ This is the recommended method to install ZoneMinder onto your system. ZoneMinde - OpenSuse via [third party repository](http://www.zoneminder.com/wiki/index.php/Installing_using_ZoneMinder_RPMs_for_SuSE) - Mageia from their default repository - Arch via the [AUR](https://aur.archlinux.org/packages/zoneminder/) +- Gentoo from their [default repository](https://packages.gentoo.org/packages/www-misc/zoneminder) If a repository that hosts ZoneMinder packages is not available for your distro, then you are encouraged to build your own package, rather than build from source. While each distro is different in ways that set it apart from all the others, they are often similar enough to allow you to adapt another distro's package building instructions to your own. From a8fc83248197f4669a263415660eabab8dface2b Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Sat, 7 Oct 2017 09:55:14 -0400 Subject: [PATCH 09/98] fix for monitor API edit perm (#1995) --- web/api/app/Controller/MonitorsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/api/app/Controller/MonitorsController.php b/web/api/app/Controller/MonitorsController.php index a0a4c8c6b..7f6e24854 100644 --- a/web/api/app/Controller/MonitorsController.php +++ b/web/api/app/Controller/MonitorsController.php @@ -122,7 +122,7 @@ public function beforeFilter() { if (!$this->Monitor->exists($id)) { throw new NotFoundException(__('Invalid monitor')); } - if ($this->Session->Read('systemPermission') != 'Edit') + if ($this->Session->Read('monitorPermission') != 'Edit') { throw new UnauthorizedException(__('Insufficient privileges')); return; From e825e5d61e4291c8dac5317da59280db02c4a5c0 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Sat, 7 Oct 2017 17:42:39 -0500 Subject: [PATCH 10/98] initial commit to change color of web console systemstats (#1981) * initial commit to change color of web console systemstats * use css classes --- web/includes/functions.php | 60 +++++++++++++++++++ .../classic/css/classic/views/console.css | 13 ++++ web/skins/classic/css/dark/views/console.css | 13 ++++ web/skins/classic/css/flat/views/console.css | 13 ++++ web/skins/classic/views/console.php | 2 +- 5 files changed, 100 insertions(+), 1 deletion(-) diff --git a/web/includes/functions.php b/web/includes/functions.php index b85624335..2ead3d64e 100644 --- a/web/includes/functions.php +++ b/web/includes/functions.php @@ -1504,6 +1504,66 @@ function getDiskBlocks() { return( $space ); } +function systemStats() { + + $load = getLoad(); + $diskPercent = getDiskPercent(); + $pathMapPercent = getDiskPercent(ZM_PATH_MAP); + $cpus = getcpus(); + + $normalized_load = $load / $cpus; + + # Colorize the system load stat + if ( $normalized_load <= 0.75 ) { + $htmlLoad=$load; + } elseif ( $normalized_load <= 0.9 ) { + $htmlLoad="$load"; + } elseif ( $normalized_load <= 1.1 ) { + $htmlLoad="$load"; + } else { + $htmlLoad="$load"; + } + + # Colorize the disk space stat + if ( $diskPercent < 98 ) { + $htmlDiskPercent="$diskPercent%"; + } elseif ( $diskPercent <= 99 ) { + $htmlDiskPercent="$diskPercent%"; + } else { + $htmlDiskPercent="$diskPercent%"; + } + + # Colorize the PATH_MAP (usually /dev/shm) stat + if ( $pathMapPercent < 90 ) { + if ( disk_free_space(ZM_PATH_MAP) > 209715200 ) { # have to always have at least 200MiB free + $htmlPathMapPercent="$pathMapPercent%"; + } else { + $htmlPathMapPercent="$pathMapPercent%"; + } + } elseif ( $pathMapPercent < 100 ) { + $htmlPathMapPercent="$pathMapPercent%"; + } else { + $htmlPathMapPercent="$pathMapPercent%"; + } + + $htmlString = translate('Load').": $htmlLoad - ".translate('Disk').": $htmlDiskPercent - ".ZM_PATH_MAP.": $htmlPathMapPercent"; + + return( $htmlString ); +} + +function getcpus() { + + if (is_readable("/proc/cpuinfo") ) { # Works on Linux + preg_match_all('/^processor/m', file_get_contents('/proc/cpuinfo'), $matches); + $num_cpus = count($matches[0]); + } else { # Works on BSD + $matches = explode(":", shell_exec("sysctl hw.ncpu")); + $num_cpus = trim($matches[1]); + } + + return( $num_cpus ); +} + // Function to fix a problem whereby the built in PHP session handling // features want to put the sid as a hidden field after the form or // fieldset tag, neither of which will work with strict XHTML Basic. diff --git a/web/skins/classic/css/classic/views/console.css b/web/skins/classic/css/classic/views/console.css index 481a14944..fdf1cfb63 100644 --- a/web/skins/classic/css/classic/views/console.css +++ b/web/skins/classic/css/classic/views/console.css @@ -12,6 +12,19 @@ float: right; } +#systemStats .warning { + color: orange; +} + +#systemStats .error { + color: red; +} + +#systemStats .critical { + color: red; + text-decoration: blink; +} + #monitorSummary { float: left; text-align: left; diff --git a/web/skins/classic/css/dark/views/console.css b/web/skins/classic/css/dark/views/console.css index 9de9128b5..e28a15b79 100644 --- a/web/skins/classic/css/dark/views/console.css +++ b/web/skins/classic/css/dark/views/console.css @@ -12,6 +12,19 @@ float: right; } +#systemStats .warning { + color: orange; +} + +#systemStats .error { + color: red; +} + +#systemStats .critical { + color: red; + text-decoration: blink; +} + #monitorSummary { float: left; text-align: left; diff --git a/web/skins/classic/css/flat/views/console.css b/web/skins/classic/css/flat/views/console.css index 481a14944..fdf1cfb63 100644 --- a/web/skins/classic/css/flat/views/console.css +++ b/web/skins/classic/css/flat/views/console.css @@ -12,6 +12,19 @@ float: right; } +#systemStats .warning { + color: orange; +} + +#systemStats .error { + color: red; +} + +#systemStats .critical { + color: red; + text-decoration: blink; +} + #monitorSummary { float: left; text-align: left; diff --git a/web/skins/classic/views/console.php b/web/skins/classic/views/console.php index c5a3c9784..ccb845df3 100644 --- a/web/skins/classic/views/console.php +++ b/web/skins/classic/views/console.php @@ -154,7 +154,7 @@ xhtmlHeaders( __FILE__, translate('Console') );