Merge pull request #1666 from connortechnology/fix_whitespace

tabs to spaces
This commit is contained in:
Kyle Johnson 2016-11-04 12:55:14 -06:00 committed by GitHub
commit ae0afaed0c
11 changed files with 6175 additions and 6175 deletions

View File

@ -58,7 +58,7 @@ ZoneMinder::Base - Base perl module for ZoneMinder
=head1 SYNOPSIS
use ZoneMinder::Base;
use ZoneMinder::Base;
=head1 DESCRIPTION

View File

@ -46,14 +46,14 @@ our @EXPORT_CONFIG = qw( %Config ); # Get populated by BEGIN
our %EXPORT_TAGS = (
functions => [ qw(
zmConfigLoad
loadConfigFromDB
saveConfigToDB
) ],
zmConfigLoad
loadConfigFromDB
saveConfigToDB
) ],
constants => [ qw(
ZM_PID
) ]
);
ZM_PID
) ]
);
push( @{$EXPORT_TAGS{config}}, @EXPORT_CONFIG );
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
@ -71,69 +71,69 @@ use Carp;
# Load the config from the database into the symbol table
BEGIN
{
my $config_file = ZM_CONFIG;
open( my $CONFIG, "<", $config_file )
or croak( "Can't open config file '$config_file': $!" );
foreach my $str ( <$CONFIG> )
{
next if ( $str =~ /^\s*$/ );
next if ( $str =~ /^\s*#/ );
my ( $name, $value ) = $str =~ /^\s*([^=\s]+)\s*=\s*(.*?)\s*$/;
if ( ! $name ) {
print( STDERR "Warning, bad line in $config_file: $str\n" );
next;
} # end if
$name =~ tr/a-z/A-Z/;
$Config{$name} = $value;
}
close( $CONFIG );
my $config_file = ZM_CONFIG;
open( my $CONFIG, "<", $config_file )
or croak( "Can't open config file '$config_file': $!" );
foreach my $str ( <$CONFIG> )
{
next if ( $str =~ /^\s*$/ );
next if ( $str =~ /^\s*#/ );
my ( $name, $value ) = $str =~ /^\s*([^=\s]+)\s*=\s*(.*?)\s*$/;
if ( ! $name ) {
print( STDERR "Warning, bad line in $config_file: $str\n" );
next;
} # end if
$name =~ tr/a-z/A-Z/;
$Config{$name} = $value;
}
close( $CONFIG );
use DBI;
my $socket;
my ( $host, $portOrSocket ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ );
use DBI;
my $socket;
my ( $host, $portOrSocket ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ );
if ( defined($portOrSocket) )
if ( defined($portOrSocket) )
{
if ( $portOrSocket =~ /^\// )
{
if ( $portOrSocket =~ /^\// )
{
$socket = ";mysql_socket=".$portOrSocket;
}
else
{
$socket = ";host=".$host.";port=".$portOrSocket;
}
$socket = ";mysql_socket=".$portOrSocket;
}
else
{
$socket = ";host=".$Config{ZM_DB_HOST};
$socket = ";host=".$host.";port=".$portOrSocket;
}
my $dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME}
.$socket
, $Config{ZM_DB_USER}
, $Config{ZM_DB_PASS}
) or croak( "Can't connect to db" );
my $sql = 'select * from Config';
my $sth = $dbh->prepare_cached( $sql ) or croak( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute() or croak( "Can't execute: ".$sth->errstr() );
while( my $config = $sth->fetchrow_hashref() ) {
$Config{$config->{Name}} = $config->{Value};
}
else
{
$socket = ";host=".$Config{ZM_DB_HOST};
}
my $dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME}
.$socket
, $Config{ZM_DB_USER}
, $Config{ZM_DB_PASS}
) or croak( "Can't connect to db" );
my $sql = 'select * from Config';
my $sth = $dbh->prepare_cached( $sql ) or croak( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute() or croak( "Can't execute: ".$sth->errstr() );
while( my $config = $sth->fetchrow_hashref() ) {
$Config{$config->{Name}} = $config->{Value};
}
$sth->finish();
#$dbh->disconnect();
if ( ! exists $Config{ZM_SERVER_ID} ) {
$Config{ZM_SERVER_ID} = undef;
$sth = $dbh->prepare_cached( 'SELECT * FROM Servers WHERE Name=?' );
if ( $Config{ZM_SERVER_NAME} ) {
$res = $sth->execute( $Config{ZM_SERVER_NAME} );
my $result = $sth->fetchrow_hashref();
$Config{ZM_SERVER_ID} = $$result{Id};
} elsif ( $Config{ZM_SERVER_HOST} ) {
$res = $sth->execute( $Config{ZM_SERVER_HOST} );
my $result = $sth->fetchrow_hashref();
$Config{ZM_SERVER_ID} = $$result{Id};
}
$sth->finish();
#$dbh->disconnect();
if ( ! exists $Config{ZM_SERVER_ID} ) {
$Config{ZM_SERVER_ID} = undef;
$sth = $dbh->prepare_cached( 'SELECT * FROM Servers WHERE Name=?' );
if ( $Config{ZM_SERVER_NAME} ) {
$res = $sth->execute( $Config{ZM_SERVER_NAME} );
my $result = $sth->fetchrow_hashref();
$Config{ZM_SERVER_ID} = $$result{Id};
} elsif ( $Config{ZM_SERVER_HOST} ) {
$res = $sth->execute( $Config{ZM_SERVER_HOST} );
my $result = $sth->fetchrow_hashref();
$Config{ZM_SERVER_ID} = $$result{Id};
}
$sth->finish();
}
}
}
sub loadConfigFromDB {
@ -315,7 +315,7 @@ Copyright (C) 2001-2008 Philip Coombes
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.3 or,
at your option, any later version of Perl 5 you may have available.
at your option, any later version of Perl 5 you may have available.
=cut
=cut

File diff suppressed because it is too large Load Diff

View File

@ -45,17 +45,17 @@ our $AUTOLOAD;
sub new
{
my $class = shift;
my $id = shift;
my $self = {};
$self->{name} = "PelcoD";
if ( !defined($id) )
{
Fatal( "No monitor defined when invoking protocol ".$self->{name} );
}
$self->{id} = $id;
bless( $self, $class );
return $self;
my $class = shift;
my $id = shift;
my $self = {};
$self->{name} = "PelcoD";
if ( !defined($id) )
{
Fatal( "No monitor defined when invoking protocol ".$self->{name} );
}
$self->{id} = $id;
bless( $self, $class );
return $self;
}
sub DESTROY
@ -64,91 +64,91 @@ sub DESTROY
sub AUTOLOAD
{
my $self = shift;
my $class = ref($self) || croak( "$self not object" );
my $name = $AUTOLOAD;
$name =~ s/.*://;
if ( exists($self->{$name}) )
{
return( $self->{$name} );
}
croak( "Can't access $name member of object of class $class" );
my $self = shift;
my $class = ref($self) || croak( "$self not object" );
my $name = $AUTOLOAD;
$name =~ s/.*://;
if ( exists($self->{$name}) )
{
return( $self->{$name} );
}
croak( "Can't access $name member of object of class $class" );
}
sub getKey
{
my $self = shift;
return( $self->{id} );
my $self = shift;
return( $self->{id} );
}
sub open
{
my $self = shift;
Fatal( "No open method defined for protocol ".$self->{name} );
my $self = shift;
Fatal( "No open method defined for protocol ".$self->{name} );
}
sub close
{
my $self = shift;
Fatal( "No close method defined for protocol ".$self->{name} );
my $self = shift;
Fatal( "No close method defined for protocol ".$self->{name} );
}
sub loadMonitor
{
my $self = shift;
if ( !$self->{Monitor} )
my $self = shift;
if ( !$self->{Monitor} )
{
if ( !($self->{Monitor} = zmDbGetMonitor( $self->{id} )) )
{
if ( !($self->{Monitor} = zmDbGetMonitor( $self->{id} )) )
{
Fatal( "Monitor id ".$self->{id}." not found or not controllable" );
}
if ( defined($self->{Monitor}->{AutoStopTimeout}) )
{
# Convert to microseconds.
$self->{Monitor}->{AutoStopTimeout} = int(1000000*$self->{Monitor}->{AutoStopTimeout});
}
Fatal( "Monitor id ".$self->{id}." not found or not controllable" );
}
if ( defined($self->{Monitor}->{AutoStopTimeout}) )
{
# Convert to microseconds.
$self->{Monitor}->{AutoStopTimeout} = int(1000000*$self->{Monitor}->{AutoStopTimeout});
}
}
}
sub getParam
{
my $self = shift;
my $params = shift;
my $name = shift;
my $default = shift;
my $self = shift;
my $params = shift;
my $name = shift;
my $default = shift;
if ( defined($params->{$name}) )
{
return( $params->{$name} );
}
elsif ( defined($default) )
{
return( $default );
}
Fatal( "Missing mandatory parameter '$name'" );
if ( defined($params->{$name}) )
{
return( $params->{$name} );
}
elsif ( defined($default) )
{
return( $default );
}
Fatal( "Missing mandatory parameter '$name'" );
}
sub executeCommand
{
my $self = shift;
my $params = shift;
my $self = shift;
my $params = shift;
$self->loadMonitor();
$self->loadMonitor();
my $command = $params->{command};
delete $params->{command};
my $command = $params->{command};
delete $params->{command};
#if ( !defined($self->{$command}) )
#{
#Fatal( "Unsupported command '$command'" );
#}
&{$self->{$command}}( $self, $params );
#if ( !defined($self->{$command}) )
#{
#Fatal( "Unsupported command '$command'" );
#}
&{$self->{$command}}( $self, $params );
}
sub printMsg
{
my $self = shift;
Fatal( "No printMsg method defined for protocol ".$self->{name} );
my $self = shift;
Fatal( "No printMsg method defined for protocol ".$self->{name} );
}
1;
@ -161,8 +161,8 @@ ZoneMinder::Database - Perl extension for blah blah blah
=head1 SYNOPSIS
use ZoneMinder::Database;
blah blah blah
use ZoneMinder::Database;
blah blah blah
=head1 DESCRIPTION

View File

@ -42,13 +42,13 @@ our @ISA = qw(Exporter ZoneMinder::Base);
# will save memory.
our %EXPORT_TAGS = (
'functions' => [ qw(
zmDbConnect
zmDbDisconnect
zmDbGetMonitors
zmDbGetMonitor
zmDbGetMonitorAndControl
) ]
);
zmDbConnect
zmDbDisconnect
zmDbGetMonitors
zmDbGetMonitor
zmDbGetMonitorAndControl
) ]
);
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
@ -72,48 +72,48 @@ our $dbh = undef;
sub zmDbConnect
{
my $force = shift;
if ( $force )
{
zmDbDisconnect();
}
if ( !defined( $dbh ) )
{
my $socket;
my ( $host, $portOrSocket ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ );
my $force = shift;
if ( $force )
{
zmDbDisconnect();
}
if ( !defined( $dbh ) )
{
my $socket;
my ( $host, $portOrSocket ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ );
if ( defined($portOrSocket) )
{
if ( $portOrSocket =~ /^\// )
{
$socket = ";mysql_socket=".$portOrSocket;
}
else
{
$socket = ";host=".$host.";port=".$portOrSocket;
}
}
else
{
$socket = ";host=".$Config{ZM_DB_HOST};
}
$dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME}
.$socket
, $Config{ZM_DB_USER}
, $Config{ZM_DB_PASS}
);
$dbh->trace( 0 );
if ( defined($portOrSocket) )
{
if ( $portOrSocket =~ /^\// )
{
$socket = ";mysql_socket=".$portOrSocket;
}
else
{
$socket = ";host=".$host.";port=".$portOrSocket;
}
}
return( $dbh );
else
{
$socket = ";host=".$Config{ZM_DB_HOST};
}
$dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME}
.$socket
, $Config{ZM_DB_USER}
, $Config{ZM_DB_PASS}
);
$dbh->trace( 0 );
}
return( $dbh );
}
sub zmDbDisconnect
{
if ( defined( $dbh ) )
{
$dbh->disconnect();
$dbh = undef;
}
if ( defined( $dbh ) )
{
$dbh->disconnect();
$dbh = undef;
}
}
use constant DB_MON_ALL => 0; # All monitors
@ -125,86 +125,86 @@ use constant DB_MON_PASSIVE => 5; # All monitors that are in nodect state
sub zmDbGetMonitors
{
zmDbConnect();
zmDbConnect();
my $function = shift || DB_MON_ALL;
my $sql = "select * from Monitors";
my $function = shift || DB_MON_ALL;
my $sql = "select * from Monitors";
if ( $function )
if ( $function )
{
if ( $function == DB_MON_CAPT )
{
if ( $function == DB_MON_CAPT )
{
$sql .= " where Function >= 'Monitor'";
}
elsif ( $function == DB_MON_ACTIVE )
{
$sql .= " where Function > 'Monitor'";
}
elsif ( $function == DB_MON_MOTION )
{
$sql .= " where Function = 'Modect' or Function = 'Mocord'";
}
elsif ( $function == DB_MON_RECORD )
{
$sql .= " where Function = 'Record' or Function = 'Mocord'";
}
elsif ( $function == DB_MON_PASSIVE )
{
$sql .= " where Function = 'Nodect'";
}
$sql .= " where Function >= 'Monitor'";
}
my $sth = $dbh->prepare_cached( $sql )
or croak( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute()
or croak( "Can't execute '$sql': ".$sth->errstr() );
my @monitors;
while( my $monitor = $sth->fetchrow_hashref() )
elsif ( $function == DB_MON_ACTIVE )
{
push( @monitors, $monitor );
$sql .= " where Function > 'Monitor'";
}
$sth->finish();
return( \@monitors );
elsif ( $function == DB_MON_MOTION )
{
$sql .= " where Function = 'Modect' or Function = 'Mocord'";
}
elsif ( $function == DB_MON_RECORD )
{
$sql .= " where Function = 'Record' or Function = 'Mocord'";
}
elsif ( $function == DB_MON_PASSIVE )
{
$sql .= " where Function = 'Nodect'";
}
}
my $sth = $dbh->prepare_cached( $sql )
or croak( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute()
or croak( "Can't execute '$sql': ".$sth->errstr() );
my @monitors;
while( my $monitor = $sth->fetchrow_hashref() )
{
push( @monitors, $monitor );
}
$sth->finish();
return( \@monitors );
}
sub zmDbGetMonitor
{
zmDbConnect();
zmDbConnect();
my $id = shift;
my $id = shift;
return( undef ) if ( !defined($id) );
return( undef ) if ( !defined($id) );
my $sql = "select * from Monitors where Id = ?";
my $sth = $dbh->prepare_cached( $sql )
or croak( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute( $id )
or croak( "Can't execute '$sql': ".$sth->errstr() );
my $monitor = $sth->fetchrow_hashref();
my $sql = "select * from Monitors where Id = ?";
my $sth = $dbh->prepare_cached( $sql )
or croak( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute( $id )
or croak( "Can't execute '$sql': ".$sth->errstr() );
my $monitor = $sth->fetchrow_hashref();
return( $monitor );
return( $monitor );
}
sub zmDbGetMonitorAndControl
{
zmDbConnect();
zmDbConnect();
my $id = shift;
my $id = shift;
return( undef ) if ( !defined($id) );
return( undef ) if ( !defined($id) );
my $sql = "SELECT C.*,M.*,C.Protocol
FROM Monitors as M
INNER JOIN Controls as C on (M.ControlId = C.Id)
WHERE M.Id = ?"
my $sql = "SELECT C.*,M.*,C.Protocol
FROM Monitors as M
INNER JOIN Controls as C on (M.ControlId = C.Id)
WHERE M.Id = ?"
;
my $sth = $dbh->prepare_cached( $sql )
or Fatal( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute( $id )
or Fatal( "Can't execute '$sql': ".$sth->errstr() );
my $monitor = $sth->fetchrow_hashref();
my $sth = $dbh->prepare_cached( $sql )
or Fatal( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute( $id )
or Fatal( "Can't execute '$sql': ".$sth->errstr() );
my $monitor = $sth->fetchrow_hashref();
return( $monitor );
return( $monitor );
}
1;
@ -217,8 +217,8 @@ ZoneMinder::Database - Perl extension for blah blah blah
=head1 SYNOPSIS
use ZoneMinder::Database;
blah blah blah
use ZoneMinder::Database;
blah blah blah
=head1 DESCRIPTION

View File

@ -43,8 +43,8 @@ our @ISA = qw(Exporter ZoneMinder::Base);
# will save memory.
our %EXPORT_TAGS = (
'functions' => [ qw(
) ]
);
) ]
);
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
@ -66,214 +66,214 @@ use ZoneMinder::Database qw(:all);
use POSIX;
sub new {
my ( $parent, $id, $data ) = @_;
my ( $parent, $id, $data ) = @_;
my $self = {};
bless $self, $parent;
$$self{dbh} = $ZoneMinder::Database::dbh;
my $self = {};
bless $self, $parent;
$$self{dbh} = $ZoneMinder::Database::dbh;
#zmDbConnect();
if ( ( $$self{Id} = $id ) or $data ) {
if ( ( $$self{Id} = $id ) or $data ) {
#$log->debug("loading $parent $id") if $debug or DEBUG_ALL;
$self->load( $data );
}
return $self;
$self->load( $data );
}
return $self;
} # end sub new
sub load {
my ( $self, $data ) = @_;
my $type = ref $self;
if ( ! $data ) {
my ( $self, $data ) = @_;
my $type = ref $self;
if ( ! $data ) {
#$log->debug("Object::load Loading from db $type");
$data = $$self{dbh}->selectrow_hashref( 'SELECT * FROM Events WHERE Id=?', {}, $$self{Id} );
if ( ! $data ) {
Error( "Failure to load Event record for $$self{Id}: Reason: " . $$self{dbh}->errstr );
} else {
Debug( 3, "Loaded Event $$self{Id}" );
} # end if
} # end if ! $data
if ( $data and %$data ) {
@$self{keys %$data} = values %$data;
} # end if
$data = $$self{dbh}->selectrow_hashref( 'SELECT * FROM Events WHERE Id=?', {}, $$self{Id} );
if ( ! $data ) {
Error( "Failure to load Event record for $$self{Id}: Reason: " . $$self{dbh}->errstr );
} else {
Debug( 3, "Loaded Event $$self{Id}" );
} # end if
} # end if ! $data
if ( $data and %$data ) {
@$self{keys %$data} = values %$data;
} # end if
} # end sub load
sub Name {
if ( @_ > 1 ) {
$_[0]{Name} = $_[1];
}
return $_[0]{Name};
if ( @_ > 1 ) {
$_[0]{Name} = $_[1];
}
return $_[0]{Name};
} # end sub Path
sub find {
shift if $_[0] eq 'ZoneMinder::Event';
my %sql_filters = @_;
shift if $_[0] eq 'ZoneMinder::Event';
my %sql_filters = @_;
my $sql = 'SELECT * FROM Events';
my @sql_filters;
my @sql_values;
my $sql = 'SELECT * FROM Events';
my @sql_filters;
my @sql_values;
if ( exists $sql_filters{Name} ) {
push @sql_filters , ' Name = ? ';
push @sql_values, $sql_filters{Name};
}
if ( exists $sql_filters{Name} ) {
push @sql_filters , ' Name = ? ';
push @sql_values, $sql_filters{Name};
}
$sql .= ' WHERE ' . join(' AND ', @sql_filters ) if @sql_filters;
$sql .= ' LIMIT ' . $sql_filters{limit} if $sql_filters{limit};
$sql .= ' WHERE ' . join(' AND ', @sql_filters ) if @sql_filters;
$sql .= ' LIMIT ' . $sql_filters{limit} if $sql_filters{limit};
my $sth = $ZoneMinder::Database::dbh->prepare_cached( $sql )
or Fatal( "Can't prepare '$sql': ".$ZoneMinder::Database::dbh->errstr() );
my $res = $sth->execute( @sql_values )
or Fatal( "Can't execute '$sql': ".$sth->errstr() );
my $sth = $ZoneMinder::Database::dbh->prepare_cached( $sql )
or Fatal( "Can't prepare '$sql': ".$ZoneMinder::Database::dbh->errstr() );
my $res = $sth->execute( @sql_values )
or Fatal( "Can't execute '$sql': ".$sth->errstr() );
my @results;
my @results;
while( my $db_filter = $sth->fetchrow_hashref() ) {
my $filter = new ZoneMinder::Event( $$db_filter{Id}, $db_filter );
push @results, $filter;
} # end while
return @results;
while( my $db_filter = $sth->fetchrow_hashref() ) {
my $filter = new ZoneMinder::Event( $$db_filter{Id}, $db_filter );
push @results, $filter;
} # end while
return @results;
}
sub find_one {
my @results = find(@_);
return $results[0] if @results;
my @results = find(@_);
return $results[0] if @results;
}
sub getEventPath
{
my $event = shift;
my $event = shift;
my $event_path = "";
if ( $Config{ZM_USE_DEEP_STORAGE} )
{
$event_path = $Config{ZM_DIR_EVENTS}
.'/'.$event->{MonitorId}
.'/'.strftime( "%y/%m/%d/%H/%M/%S",
localtime($event->{Time})
)
;
}
else
{
$event_path = $Config{ZM_DIR_EVENTS}
.'/'.$event->{MonitorId}
.'/'.$event->{Id}
;
}
my $event_path = "";
if ( $Config{ZM_USE_DEEP_STORAGE} )
{
$event_path = $Config{ZM_DIR_EVENTS}
.'/'.$event->{MonitorId}
.'/'.strftime( "%y/%m/%d/%H/%M/%S",
localtime($event->{Time})
)
;
}
else
{
$event_path = $Config{ZM_DIR_EVENTS}
.'/'.$event->{MonitorId}
.'/'.$event->{Id}
;
}
if ( index($Config{ZM_DIR_EVENTS},'/') != 0 ){
$event_path = $Config{ZM_PATH_WEB}
.'/'.$event_path
;
}
return( $event_path );
if ( index($Config{ZM_DIR_EVENTS},'/') != 0 ){
$event_path = $Config{ZM_PATH_WEB}
.'/'.$event_path
;
}
return( $event_path );
}
sub GenerateVideo {
my ( $self, $rate, $fps, $scale, $size, $overwrite, $format ) = @_;
my ( $self, $rate, $fps, $scale, $size, $overwrite, $format ) = @_;
my $event_path = getEventPath( $self );
chdir( $event_path );
( my $video_name = $self->{Name} ) =~ s/\s/_/g;
my $event_path = getEventPath( $self );
chdir( $event_path );
( my $video_name = $self->{Name} ) =~ s/\s/_/g;
my @file_parts;
if ( $rate )
{
my $file_rate = $rate;
$file_rate =~ s/\./_/;
$file_rate =~ s/_00//;
$file_rate =~ s/(_\d+)0+$/$1/;
$file_rate = 'r'.$file_rate;
push( @file_parts, $file_rate );
}
elsif ( $fps )
{
my $file_fps = $fps;
$file_fps =~ s/\./_/;
$file_fps =~ s/_00//;
$file_fps =~ s/(_\d+)0+$/$1/;
$file_fps = 'R'.$file_fps;
push( @file_parts, $file_fps );
}
my @file_parts;
if ( $rate )
{
my $file_rate = $rate;
$file_rate =~ s/\./_/;
$file_rate =~ s/_00//;
$file_rate =~ s/(_\d+)0+$/$1/;
$file_rate = 'r'.$file_rate;
push( @file_parts, $file_rate );
}
elsif ( $fps )
{
my $file_fps = $fps;
$file_fps =~ s/\./_/;
$file_fps =~ s/_00//;
$file_fps =~ s/(_\d+)0+$/$1/;
$file_fps = 'R'.$file_fps;
push( @file_parts, $file_fps );
}
if ( $scale )
{
my $file_scale = $scale;
$file_scale =~ s/\./_/;
$file_scale =~ s/_00//;
$file_scale =~ s/(_\d+)0+$/$1/;
$file_scale = 's'.$file_scale;
push( @file_parts, $file_scale );
}
elsif ( $size )
{
my $file_size = 'S'.$size;
push( @file_parts, $file_size );
}
my $video_file = "$video_name-".$file_parts[0]."-".$file_parts[1].".$format";
if ( $overwrite || !-s $video_file )
{
Info( "Creating video file $video_file for event $self->{Id}\n" );
if ( $scale )
{
my $file_scale = $scale;
$file_scale =~ s/\./_/;
$file_scale =~ s/_00//;
$file_scale =~ s/(_\d+)0+$/$1/;
$file_scale = 's'.$file_scale;
push( @file_parts, $file_scale );
}
elsif ( $size )
{
my $file_size = 'S'.$size;
push( @file_parts, $file_size );
}
my $video_file = "$video_name-".$file_parts[0]."-".$file_parts[1].".$format";
if ( $overwrite || !-s $video_file )
{
Info( "Creating video file $video_file for event $self->{Id}\n" );
my $frame_rate = sprintf( "%.2f", $self->{Frames}/$self->{FullLength} );
if ( $rate )
{
if ( $rate != 1.0 )
{
$frame_rate *= $rate;
}
}
elsif ( $fps )
{
$frame_rate = $fps;
}
my $frame_rate = sprintf( "%.2f", $self->{Frames}/$self->{FullLength} );
if ( $rate )
{
if ( $rate != 1.0 )
{
$frame_rate *= $rate;
}
}
elsif ( $fps )
{
$frame_rate = $fps;
}
my $width = $self->{MonitorWidth};
my $height = $self->{MonitorHeight};
my $video_size = " ${width}x${height}";
my $width = $self->{MonitorWidth};
my $height = $self->{MonitorHeight};
my $video_size = " ${width}x${height}";
if ( $scale )
{
if ( $scale != 1.0 )
{
$width = int($width*$scale);
$height = int($height*$scale);
$video_size = " ${width}x${height}";
}
}
elsif ( $size )
{
$video_size = $size;
}
my $command = $Config{ZM_PATH_FFMPEG}
." -y -r $frame_rate "
.$Config{ZM_FFMPEG_INPUT_OPTIONS}
." -i %0"
.$Config{ZM_EVENT_IMAGE_DIGITS}
."d-capture.jpg -s $video_size "
if ( $scale )
{
if ( $scale != 1.0 )
{
$width = int($width*$scale);
$height = int($height*$scale);
$video_size = " ${width}x${height}";
}
}
elsif ( $size )
{
$video_size = $size;
}
my $command = $Config{ZM_PATH_FFMPEG}
." -y -r $frame_rate "
.$Config{ZM_FFMPEG_INPUT_OPTIONS}
." -i %0"
.$Config{ZM_EVENT_IMAGE_DIGITS}
."d-capture.jpg -s $video_size "
#. " -f concat -i /tmp/event_files.txt"
." -s $video_size "
.$Config{ZM_FFMPEG_OUTPUT_OPTIONS}
." '$video_file' > ffmpeg.log 2>&1"
;
Debug( $command."\n" );
my $output = qx($command);
." -s $video_size "
.$Config{ZM_FFMPEG_OUTPUT_OPTIONS}
." '$video_file' > ffmpeg.log 2>&1"
;
Debug( $command."\n" );
my $output = qx($command);
my $status = $? >> 8;
if ( $status )
{
Error( "Unable to generate video, check "
.$event_path."/ffmpeg.log for details"
);
return;
}
my $status = $? >> 8;
if ( $status )
{
Error( "Unable to generate video, check "
.$event_path."/ffmpeg.log for details"
);
return;
}
Info( "Finished $video_file\n" );
return $event_path.'/'.$video_file;
} else {
Info( "Video file $video_file already exists for event $self->{Id}\n" );
return $event_path.'/'.$video_file;
}
return;
Info( "Finished $video_file\n" );
return $event_path.'/'.$video_file;
} else {
Info( "Video file $video_file already exists for event $self->{Id}\n" );
return $event_path.'/'.$video_file;
}
return;
} # end sub GenerateVideo
1;
@ -286,8 +286,8 @@ ZoneMinder::Database - Perl extension for blah blah blah
=head1 SYNOPSIS
use ZoneMinder::Event;
blah blah blah
use ZoneMinder::Event;
blah blah blah
=head1 DESCRIPTION

View File

@ -66,378 +66,378 @@ use ZoneMinder::Database qw(:all);
use POSIX;
sub new {
my ( $parent, $id, $data ) = @_;
my ( $parent, $id, $data ) = @_;
my $self = {};
bless $self, $parent;
$$self{dbh} = $ZoneMinder::Database::dbh;
my $self = {};
bless $self, $parent;
$$self{dbh} = $ZoneMinder::Database::dbh;
#zmDbConnect();
if ( ( $$self{Id} = $id ) or $data ) {
if ( ( $$self{Id} = $id ) or $data ) {
#$log->debug("loading $parent $id") if $debug or DEBUG_ALL;
$self->load( $data );
}
return $self;
$self->load( $data );
}
return $self;
} # end sub new
sub load {
my ( $self, $data ) = @_;
my $type = ref $self;
if ( ! $data ) {
my ( $self, $data ) = @_;
my $type = ref $self;
if ( ! $data ) {
#$log->debug("Object::load Loading from db $type");
$data = $$self{dbh}->selectrow_hashref( 'SELECT * FROM Filter WHERE Id=?', {}, $$self{Id} );
if ( ! $data ) {
Error( "Failure to load Filter record for $$self{Id}: Reason: " . $$self{dbh}->errstr );
} else {
Debug( 3, "Loaded Filter $$self{Id}" );
} # end if
} # end if ! $data
if ( $data and %$data ) {
@$self{keys %$data} = values %$data;
} # end if
$data = $$self{dbh}->selectrow_hashref( 'SELECT * FROM Filter WHERE Id=?', {}, $$self{Id} );
if ( ! $data ) {
Error( "Failure to load Filter record for $$self{Id}: Reason: " . $$self{dbh}->errstr );
} else {
Debug( 3, "Loaded Filter $$self{Id}" );
} # end if
} # end if ! $data
if ( $data and %$data ) {
@$self{keys %$data} = values %$data;
} # end if
} # end sub load
sub Name {
if ( @_ > 1 ) {
$_[0]{Name} = $_[1];
}
return $_[0]{Name};
if ( @_ > 1 ) {
$_[0]{Name} = $_[1];
}
return $_[0]{Name};
} # end sub Path
sub find {
shift if $_[0] eq 'ZoneMinder::Filter';
my %sql_filters = @_;
shift if $_[0] eq 'ZoneMinder::Filter';
my %sql_filters = @_;
my $sql = 'SELECT * FROM Filters';
my @sql_filters;
my @sql_values;
my $sql = 'SELECT * FROM Filters';
my @sql_filters;
my @sql_values;
if ( exists $sql_filters{Name} ) {
push @sql_filters , ' Name = ? ';
push @sql_values, $sql_filters{Name};
}
if ( exists $sql_filters{Name} ) {
push @sql_filters , ' Name = ? ';
push @sql_values, $sql_filters{Name};
}
$sql .= ' WHERE ' . join(' AND ', @sql_filters ) if @sql_filters;
$sql .= ' LIMIT ' . $sql_filters{limit} if $sql_filters{limit};
$sql .= ' WHERE ' . join(' AND ', @sql_filters ) if @sql_filters;
$sql .= ' LIMIT ' . $sql_filters{limit} if $sql_filters{limit};
my $sth = $ZoneMinder::Database::dbh->prepare_cached( $sql )
or Fatal( "Can't prepare '$sql': ".$ZoneMinder::Database::dbh->errstr() );
my $res = $sth->execute( @sql_values )
or Fatal( "Can't execute '$sql': ".$sth->errstr() );
my $sth = $ZoneMinder::Database::dbh->prepare_cached( $sql )
or Fatal( "Can't prepare '$sql': ".$ZoneMinder::Database::dbh->errstr() );
my $res = $sth->execute( @sql_values )
or Fatal( "Can't execute '$sql': ".$sth->errstr() );
my @results;
my @results;
while( my $db_filter = $sth->fetchrow_hashref() ) {
my $filter = new ZoneMinder::Filter( $$db_filter{Id}, $db_filter );
push @results, $filter;
} # end while
return @results;
while( my $db_filter = $sth->fetchrow_hashref() ) {
my $filter = new ZoneMinder::Filter( $$db_filter{Id}, $db_filter );
push @results, $filter;
} # end while
return @results;
}
sub find_one {
my @results = find(@_);
return $results[0] if @results;
my @results = find(@_);
return $results[0] if @results;
}
sub Execute {
my $self = $_[0];
my $self = $_[0];
my $sql = $self->Sql();
my $sql = $self->Sql();
if ( $self->{HasDiskPercent} )
{
my $disk_percent = getDiskPercent();
$sql =~ s/zmDiskPercent/$disk_percent/g;
}
if ( $self->{HasDiskBlocks} )
{
my $disk_blocks = getDiskBlocks();
$sql =~ s/zmDiskBlocks/$disk_blocks/g;
}
if ( $self->{HasSystemLoad} )
{
my $load = getLoad();
$sql =~ s/zmSystemLoad/$load/g;
}
if ( $self->{HasDiskPercent} )
{
my $disk_percent = getDiskPercent();
$sql =~ s/zmDiskPercent/$disk_percent/g;
}
if ( $self->{HasDiskBlocks} )
{
my $disk_blocks = getDiskBlocks();
$sql =~ s/zmDiskBlocks/$disk_blocks/g;
}
if ( $self->{HasSystemLoad} )
{
my $load = getLoad();
$sql =~ s/zmSystemLoad/$load/g;
}
my $sth = $$self{dbh}->prepare_cached( $sql )
or Fatal( "Can't prepare '$sql': ".$$self{dbh}->errstr() );
my $res = $sth->execute();
if ( !$res )
{
Error( "Can't execute filter '$sql', ignoring: ".$sth->errstr() );
return;
}
my @results;
my $sth = $$self{dbh}->prepare_cached( $sql )
or Fatal( "Can't prepare '$sql': ".$$self{dbh}->errstr() );
my $res = $sth->execute();
if ( !$res )
{
Error( "Can't execute filter '$sql', ignoring: ".$sth->errstr() );
return;
}
my @results;
while( my $event = $sth->fetchrow_hashref() ) {
push @results, $event;
}
$sth->finish();
return @results;
while( my $event = $sth->fetchrow_hashref() ) {
push @results, $event;
}
$sth->finish();
return @results;
}
sub Sql {
my $self = $_[0];
if ( ! $$self{Sql} ) {
my $filter_expr = ZoneMinder::General::jsonDecode( $self->{Query} );
my $sql = "SELECT E.Id,
E.MonitorId,
M.Name as MonitorName,
M.DefaultRate,
M.DefaultScale,
E.Name,
E.Cause,
E.Notes,
E.StartTime,
unix_timestamp(E.StartTime) as Time,
E.Length,
E.Frames,
E.AlarmFrames,
E.TotScore,
E.AvgScore,
E.MaxScore,
E.Archived,
E.Videoed,
E.Uploaded,
E.Emailed,
E.Messaged,
E.Executed
FROM Events as E
INNER JOIN Monitors as M on M.Id = E.MonitorId
";
$self->{Sql} = '';
my $self = $_[0];
if ( ! $$self{Sql} ) {
my $filter_expr = ZoneMinder::General::jsonDecode( $self->{Query} );
my $sql = "SELECT E.Id,
E.MonitorId,
M.Name as MonitorName,
M.DefaultRate,
M.DefaultScale,
E.Name,
E.Cause,
E.Notes,
E.StartTime,
unix_timestamp(E.StartTime) as Time,
E.Length,
E.Frames,
E.AlarmFrames,
E.TotScore,
E.AvgScore,
E.MaxScore,
E.Archived,
E.Videoed,
E.Uploaded,
E.Emailed,
E.Messaged,
E.Executed
FROM Events as E
INNER JOIN Monitors as M on M.Id = E.MonitorId
";
$self->{Sql} = '';
if ( $filter_expr->{terms} ) {
for ( my $i = 0; $i < @{$filter_expr->{terms}}; $i++ ) {
if ( exists($filter_expr->{terms}[$i]->{cnj}) ) {
$self->{Sql} .= " ".$filter_expr->{terms}[$i]->{cnj}." ";
}
if ( exists($filter_expr->{terms}[$i]->{obr}) ) {
$self->{Sql} .= " ".str_repeat( "(", $filter_expr->{terms}[$i]->{obr} )." ";
}
my $value = $filter_expr->{terms}[$i]->{val};
my @value_list;
if ( $filter_expr->{terms}[$i]->{attr} ) {
if ( $filter_expr->{terms}[$i]->{attr} =~ /^Monitor/ ) {
my ( $temp_attr_name ) = $filter_expr->{terms}[$i]->{attr} =~ /^Monitor(.+)$/;
$self->{Sql} .= "M.".$temp_attr_name;
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'DateTime' ) {
$self->{Sql} .= "E.StartTime";
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Date' ) {
$self->{Sql} .= "to_days( E.StartTime )";
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Time' ) {
$self->{Sql} .= "extract( hour_second from E.StartTime )";
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Weekday' ) {
$self->{Sql} .= "weekday( E.StartTime )";
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'DiskPercent' ) {
$self->{Sql} .= "zmDiskPercent";
$self->{HasDiskPercent} = !undef;
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'DiskBlocks' ) {
$self->{Sql} .= "zmDiskBlocks";
$self->{HasDiskBlocks} = !undef;
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'SystemLoad' ) {
$self->{Sql} .= "zmSystemLoad";
$self->{HasSystemLoad} = !undef;
} else {
$self->{Sql} .= "E.".$filter_expr->{terms}[$i]->{attr};
}
if ( $filter_expr->{terms} ) {
for ( my $i = 0; $i < @{$filter_expr->{terms}}; $i++ ) {
if ( exists($filter_expr->{terms}[$i]->{cnj}) ) {
$self->{Sql} .= " ".$filter_expr->{terms}[$i]->{cnj}." ";
}
if ( exists($filter_expr->{terms}[$i]->{obr}) ) {
$self->{Sql} .= " ".str_repeat( "(", $filter_expr->{terms}[$i]->{obr} )." ";
}
my $value = $filter_expr->{terms}[$i]->{val};
my @value_list;
if ( $filter_expr->{terms}[$i]->{attr} ) {
if ( $filter_expr->{terms}[$i]->{attr} =~ /^Monitor/ ) {
my ( $temp_attr_name ) = $filter_expr->{terms}[$i]->{attr} =~ /^Monitor(.+)$/;
$self->{Sql} .= "M.".$temp_attr_name;
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'DateTime' ) {
$self->{Sql} .= "E.StartTime";
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Date' ) {
$self->{Sql} .= "to_days( E.StartTime )";
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Time' ) {
$self->{Sql} .= "extract( hour_second from E.StartTime )";
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Weekday' ) {
$self->{Sql} .= "weekday( E.StartTime )";
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'DiskPercent' ) {
$self->{Sql} .= "zmDiskPercent";
$self->{HasDiskPercent} = !undef;
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'DiskBlocks' ) {
$self->{Sql} .= "zmDiskBlocks";
$self->{HasDiskBlocks} = !undef;
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'SystemLoad' ) {
$self->{Sql} .= "zmSystemLoad";
$self->{HasSystemLoad} = !undef;
} else {
$self->{Sql} .= "E.".$filter_expr->{terms}[$i]->{attr};
}
( my $stripped_value = $value ) =~ s/^["\']+?(.+)["\']+?$/$1/;
foreach my $temp_value ( split( /["'\s]*?,["'\s]*?/, $stripped_value ) ) {
if ( $filter_expr->{terms}[$i]->{attr} =~ /^Monitor/ ) {
$value = "'$temp_value'";
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Name'
|| $filter_expr->{terms}[$i]->{attr} eq 'Cause'
|| $filter_expr->{terms}[$i]->{attr} eq 'Notes'
) {
$value = "'$temp_value'";
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'DateTime' ) {
$value = DateTimeToSQL( $temp_value );
if ( !$value ) {
Error( "Error parsing date/time '$temp_value', "
."skipping filter '$self->{Name}'\n" );
return;
}
$value = "'$value'";
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Date' ) {
$value = DateTimeToSQL( $temp_value );
if ( !$value ) {
Error( "Error parsing date/time '$temp_value', "
."skipping filter '$self->{Name}'\n" );
return;
}
$value = "to_days( '$value' )";
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Time' ) {
$value = DateTimeToSQL( $temp_value );
if ( !$value ) {
Error( "Error parsing date/time '$temp_value', "
."skipping filter '$self->{Name}'\n" );
return;
}
$value = "extract( hour_second from '$value' )";
} else {
$value = $temp_value;
}
push( @value_list, $value );
} # end foreach temp_value
} # end if has an attr
if ( $filter_expr->{terms}[$i]->{op} ) {
if ( $filter_expr->{terms}[$i]->{op} eq '=~' ) {
$self->{Sql} .= " regexp $value";
} elsif ( $filter_expr->{terms}[$i]->{op} eq '!~' ) {
$self->{Sql} .= " not regexp $value";
} elsif ( $filter_expr->{terms}[$i]->{op} eq '=[]' ) {
$self->{Sql} .= " in (".join( ",", @value_list ).")";
} elsif ( $filter_expr->{terms}[$i]->{op} eq '!~' ) {
$self->{Sql} .= " not in (".join( ",", @value_list ).")";
} else {
$self->{Sql} .= " ".$filter_expr->{terms}[$i]->{op}." $value";
}
} # end if has an operator
if ( exists($filter_expr->{terms}[$i]->{cbr}) ) {
$self->{Sql} .= " ".str_repeat( ")", $filter_expr->{terms}[$i]->{cbr} )." ";
}
} # end foreach term
} # end if terms
if ( $self->{Sql} )
{
if ( $self->{AutoMessage} )
{
# Include all events, including events that are still ongoing
# and have no EndTime yet
$sql .= " and ( ".$self->{Sql}." )";
}
else
{
# Only include closed events (events with valid EndTime)
$sql .= " where not isnull(E.EndTime) and ( ".$self->{Sql}." )";
( my $stripped_value = $value ) =~ s/^["\']+?(.+)["\']+?$/$1/;
foreach my $temp_value ( split( /["'\s]*?,["'\s]*?/, $stripped_value ) ) {
if ( $filter_expr->{terms}[$i]->{attr} =~ /^Monitor/ ) {
$value = "'$temp_value'";
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Name'
|| $filter_expr->{terms}[$i]->{attr} eq 'Cause'
|| $filter_expr->{terms}[$i]->{attr} eq 'Notes'
) {
$value = "'$temp_value'";
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'DateTime' ) {
$value = DateTimeToSQL( $temp_value );
if ( !$value ) {
Error( "Error parsing date/time '$temp_value', "
."skipping filter '$self->{Name}'\n" );
return;
}
$value = "'$value'";
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Date' ) {
$value = DateTimeToSQL( $temp_value );
if ( !$value ) {
Error( "Error parsing date/time '$temp_value', "
."skipping filter '$self->{Name}'\n" );
return;
}
$value = "to_days( '$value' )";
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Time' ) {
$value = DateTimeToSQL( $temp_value );
if ( !$value ) {
Error( "Error parsing date/time '$temp_value', "
."skipping filter '$self->{Name}'\n" );
return;
}
$value = "extract( hour_second from '$value' )";
} else {
$value = $temp_value;
}
push( @value_list, $value );
} # end foreach temp_value
} # end if has an attr
if ( $filter_expr->{terms}[$i]->{op} ) {
if ( $filter_expr->{terms}[$i]->{op} eq '=~' ) {
$self->{Sql} .= " regexp $value";
} elsif ( $filter_expr->{terms}[$i]->{op} eq '!~' ) {
$self->{Sql} .= " not regexp $value";
} elsif ( $filter_expr->{terms}[$i]->{op} eq '=[]' ) {
$self->{Sql} .= " in (".join( ",", @value_list ).")";
} elsif ( $filter_expr->{terms}[$i]->{op} eq '!~' ) {
$self->{Sql} .= " not in (".join( ",", @value_list ).")";
} else {
$self->{Sql} .= " ".$filter_expr->{terms}[$i]->{op}." $value";
}
} # end if has an operator
if ( exists($filter_expr->{terms}[$i]->{cbr}) ) {
$self->{Sql} .= " ".str_repeat( ")", $filter_expr->{terms}[$i]->{cbr} )." ";
}
my @auto_terms;
if ( $self->{AutoArchive} )
{
push( @auto_terms, "E.Archived = 0" )
}
if ( $self->{AutoVideo} )
{
push( @auto_terms, "E.Videoed = 0" )
}
if ( $self->{AutoUpload} )
{
push( @auto_terms, "E.Uploaded = 0" )
}
if ( $self->{AutoEmail} )
{
push( @auto_terms, "E.Emailed = 0" )
}
if ( $self->{AutoMessage} )
{
push( @auto_terms, "E.Messaged = 0" )
}
if ( $self->{AutoExecute} )
{
push( @auto_terms, "E.Executed = 0" )
}
if ( @auto_terms )
{
$sql .= " and ( ".join( " or ", @auto_terms )." )";
}
if ( !$filter_expr->{sort_field} )
{
$filter_expr->{sort_field} = 'StartTime';
$filter_expr->{sort_asc} = 0;
}
my $sort_column = '';
if ( $filter_expr->{sort_field} eq 'Id' )
{
$sort_column = "E.Id";
}
elsif ( $filter_expr->{sort_field} eq 'MonitorName' )
{
$sort_column = "M.Name";
}
elsif ( $filter_expr->{sort_field} eq 'Name' )
{
$sort_column = "E.Name";
}
elsif ( $filter_expr->{sort_field} eq 'StartTime' )
{
$sort_column = "E.StartTime";
}
elsif ( $filter_expr->{sort_field} eq 'Secs' )
{
$sort_column = "E.Length";
}
elsif ( $filter_expr->{sort_field} eq 'Frames' )
{
$sort_column = "E.Frames";
}
elsif ( $filter_expr->{sort_field} eq 'AlarmFrames' )
{
$sort_column = "E.AlarmFrames";
}
elsif ( $filter_expr->{sort_field} eq 'TotScore' )
{
$sort_column = "E.TotScore";
}
elsif ( $filter_expr->{sort_field} eq 'AvgScore' )
{
$sort_column = "E.AvgScore";
}
elsif ( $filter_expr->{sort_field} eq 'MaxScore' )
{
$sort_column = "E.MaxScore";
}
else
{
$sort_column = "E.StartTime";
}
my $sort_order = $filter_expr->{sort_asc}?"asc":"desc";
$sql .= " order by ".$sort_column." ".$sort_order;
if ( $filter_expr->{limit} )
{
$sql .= " limit 0,".$filter_expr->{limit};
}
Debug( "SQL:$sql\n" );
$self->{Sql} = $sql;
} # end if has Sql
return $self->{Sql};
} # end foreach term
} # end if terms
if ( $self->{Sql} )
{
if ( $self->{AutoMessage} )
{
# Include all events, including events that are still ongoing
# and have no EndTime yet
$sql .= " and ( ".$self->{Sql}." )";
}
else
{
# Only include closed events (events with valid EndTime)
$sql .= " where not isnull(E.EndTime) and ( ".$self->{Sql}." )";
}
}
my @auto_terms;
if ( $self->{AutoArchive} )
{
push( @auto_terms, "E.Archived = 0" )
}
if ( $self->{AutoVideo} )
{
push( @auto_terms, "E.Videoed = 0" )
}
if ( $self->{AutoUpload} )
{
push( @auto_terms, "E.Uploaded = 0" )
}
if ( $self->{AutoEmail} )
{
push( @auto_terms, "E.Emailed = 0" )
}
if ( $self->{AutoMessage} )
{
push( @auto_terms, "E.Messaged = 0" )
}
if ( $self->{AutoExecute} )
{
push( @auto_terms, "E.Executed = 0" )
}
if ( @auto_terms )
{
$sql .= " and ( ".join( " or ", @auto_terms )." )";
}
if ( !$filter_expr->{sort_field} )
{
$filter_expr->{sort_field} = 'StartTime';
$filter_expr->{sort_asc} = 0;
}
my $sort_column = '';
if ( $filter_expr->{sort_field} eq 'Id' )
{
$sort_column = "E.Id";
}
elsif ( $filter_expr->{sort_field} eq 'MonitorName' )
{
$sort_column = "M.Name";
}
elsif ( $filter_expr->{sort_field} eq 'Name' )
{
$sort_column = "E.Name";
}
elsif ( $filter_expr->{sort_field} eq 'StartTime' )
{
$sort_column = "E.StartTime";
}
elsif ( $filter_expr->{sort_field} eq 'Secs' )
{
$sort_column = "E.Length";
}
elsif ( $filter_expr->{sort_field} eq 'Frames' )
{
$sort_column = "E.Frames";
}
elsif ( $filter_expr->{sort_field} eq 'AlarmFrames' )
{
$sort_column = "E.AlarmFrames";
}
elsif ( $filter_expr->{sort_field} eq 'TotScore' )
{
$sort_column = "E.TotScore";
}
elsif ( $filter_expr->{sort_field} eq 'AvgScore' )
{
$sort_column = "E.AvgScore";
}
elsif ( $filter_expr->{sort_field} eq 'MaxScore' )
{
$sort_column = "E.MaxScore";
}
else
{
$sort_column = "E.StartTime";
}
my $sort_order = $filter_expr->{sort_asc}?"asc":"desc";
$sql .= " order by ".$sort_column." ".$sort_order;
if ( $filter_expr->{limit} )
{
$sql .= " limit 0,".$filter_expr->{limit};
}
Debug( "SQL:$sql\n" );
$self->{Sql} = $sql;
} # end if has Sql
return $self->{Sql};
} # end sub Sql
sub getDiskPercent
{
my $command = "df .";
my $df = qx( $command );
my $space = -1;
if ( $df =~ /\s(\d+)%/ms )
{
$space = $1;
}
return( $space );
my $command = "df .";
my $df = qx( $command );
my $space = -1;
if ( $df =~ /\s(\d+)%/ms )
{
$space = $1;
}
return( $space );
}
sub getDiskBlocks
{
my $command = "df .";
my $df = qx( $command );
my $space = -1;
if ( $df =~ /\s(\d+)\s+\d+\s+\d+%/ms )
{
$space = $1;
}
return( $space );
my $command = "df .";
my $df = qx( $command );
my $space = -1;
if ( $df =~ /\s(\d+)\s+\d+\s+\d+%/ms )
{
$space = $1;
}
return( $space );
}
sub getLoad
{
my $command = "uptime .";
my $uptime = qx( $command );
my $load = -1;
if ( $uptime =~ /load average:\s+([\d.]+)/ms )
{
$load = $1;
Info( "Load: $load" );
}
return( $load );
my $command = "uptime .";
my $uptime = qx( $command );
my $load = -1;
if ( $uptime =~ /load average:\s+([\d.]+)/ms )
{
$load = $1;
Info( "Load: $load" );
}
return( $load );
}
#
@ -445,8 +445,8 @@ sub getLoad
#
sub strtotime
{
my $dt_str = shift;
return( Date::Manip::UnixDate( $dt_str, '%s' ) );
my $dt_str = shift;
return( Date::Manip::UnixDate( $dt_str, '%s' ) );
}
#
@ -454,22 +454,22 @@ sub strtotime
#
sub str_repeat
{
my $string = shift;
my $count = shift;
return( ${string}x${count} );
my $string = shift;
my $count = shift;
return( ${string}x${count} );
}
# Formats a date into MySQL format
sub DateTimeToSQL
{
my $dt_str = shift;
my $dt_val = strtotime( $dt_str );
if ( !$dt_val )
{
Error( "Unable to parse date string '$dt_str'\n" );
return( undef );
}
return( strftime( "%Y-%m-%d %H:%M:%S", localtime( $dt_val ) ) );
my $dt_str = shift;
my $dt_val = strtotime( $dt_str );
if ( !$dt_val )
{
Error( "Unable to parse date string '$dt_str'\n" );
return( undef );
}
return( strftime( "%Y-%m-%d %H:%M:%S", localtime( $dt_val ) ) );
}
1;
@ -482,8 +482,8 @@ ZoneMinder::Database - Perl extension for blah blah blah
=head1 SYNOPSIS
use ZoneMinder::Filter;
blah blah blah
use ZoneMinder::Filter;
blah blah blah
=head1 DESCRIPTION

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -42,8 +42,8 @@ our @ISA = qw(Exporter ZoneMinder::Base);
# will save memory.
our %EXPORT_TAGS = (
'functions' => [ qw(
) ]
);
) ]
);
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
@ -65,46 +65,46 @@ use ZoneMinder::Database qw(:all);
use POSIX;
sub new {
my ( $parent, $id, $data ) = @_;
my ( $parent, $id, $data ) = @_;
my $self = {};
bless $self, $parent;
if ( ( $$self{Id} = $id ) or $data ) {
my $self = {};
bless $self, $parent;
if ( ( $$self{Id} = $id ) or $data ) {
#$log->debug("loading $parent $id") if $debug or DEBUG_ALL;
$self->load( $data );
}
return $self;
$self->load( $data );
}
return $self;
} # end sub new
sub load {
my ( $self, $data ) = @_;
my $type = ref $self;
if ( ! $data ) {
my ( $self, $data ) = @_;
my $type = ref $self;
if ( ! $data ) {
#$log->debug("Object::load Loading from db $type");
$data = $ZoneMinder::Database::dbh->selectrow_hashref( 'SELECT * FROM Servers WHERE Id=?', {}, $$self{Id} );
if ( ! $data ) {
if ( $ZoneMinder::Database::dbh->errstr ) {
Error( "Failure to load Server record for $$self{id}: Reason: " . $ZoneMinder::Database::dbh->errstr );
} # end if
} # end if
} # end if ! $data
if ( $data and %$data ) {
@$self{keys %$data} = values %$data;
} # end if
$data = $ZoneMinder::Database::dbh->selectrow_hashref( 'SELECT * FROM Servers WHERE Id=?', {}, $$self{Id} );
if ( ! $data ) {
if ( $ZoneMinder::Database::dbh->errstr ) {
Error( "Failure to load Server record for $$self{id}: Reason: " . $ZoneMinder::Database::dbh->errstr );
} # end if
} # end if
} # end if ! $data
if ( $data and %$data ) {
@$self{keys %$data} = values %$data;
} # end if
} # end sub load
sub Name {
if ( @_ > 1 ) {
$_[0]{Name} = $_[1];
}
return $_[0]{Name};
if ( @_ > 1 ) {
$_[0]{Name} = $_[1];
}
return $_[0]{Name};
} # end sub Name
sub Hostname {
if ( @_ > 1 ) {
$_[0]{Hostname} = $_[1];
}
return $_[0]{Hostname};
if ( @_ > 1 ) {
$_[0]{Hostname} = $_[1];
}
return $_[0]{Hostname};
} # end sub Hostname
1;
@ -117,8 +117,8 @@ ZoneMinder::Database - Perl extension for blah blah blah
=head1 SYNOPSIS
use ZoneMinder::Server;
blah blah blah
use ZoneMinder::Server;
blah blah blah
=head1 DESCRIPTION