Merge pull request #1666 from connortechnology/fix_whitespace
tabs to spaces
This commit is contained in:
commit
ae0afaed0c
|
@ -58,7 +58,7 @@ ZoneMinder::Base - Base perl module for ZoneMinder
|
||||||
|
|
||||||
=head1 SYNOPSIS
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
use ZoneMinder::Base;
|
use ZoneMinder::Base;
|
||||||
|
|
||||||
=head1 DESCRIPTION
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
|
|
@ -46,14 +46,14 @@ our @EXPORT_CONFIG = qw( %Config ); # Get populated by BEGIN
|
||||||
|
|
||||||
our %EXPORT_TAGS = (
|
our %EXPORT_TAGS = (
|
||||||
functions => [ qw(
|
functions => [ qw(
|
||||||
zmConfigLoad
|
zmConfigLoad
|
||||||
loadConfigFromDB
|
loadConfigFromDB
|
||||||
saveConfigToDB
|
saveConfigToDB
|
||||||
) ],
|
) ],
|
||||||
constants => [ qw(
|
constants => [ qw(
|
||||||
ZM_PID
|
ZM_PID
|
||||||
) ]
|
) ]
|
||||||
);
|
);
|
||||||
push( @{$EXPORT_TAGS{config}}, @EXPORT_CONFIG );
|
push( @{$EXPORT_TAGS{config}}, @EXPORT_CONFIG );
|
||||||
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
|
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
|
# Load the config from the database into the symbol table
|
||||||
BEGIN
|
BEGIN
|
||||||
{
|
{
|
||||||
my $config_file = ZM_CONFIG;
|
my $config_file = ZM_CONFIG;
|
||||||
open( my $CONFIG, "<", $config_file )
|
open( my $CONFIG, "<", $config_file )
|
||||||
or croak( "Can't open config file '$config_file': $!" );
|
or croak( "Can't open config file '$config_file': $!" );
|
||||||
foreach my $str ( <$CONFIG> )
|
foreach my $str ( <$CONFIG> )
|
||||||
{
|
{
|
||||||
next if ( $str =~ /^\s*$/ );
|
next if ( $str =~ /^\s*$/ );
|
||||||
next if ( $str =~ /^\s*#/ );
|
next if ( $str =~ /^\s*#/ );
|
||||||
my ( $name, $value ) = $str =~ /^\s*([^=\s]+)\s*=\s*(.*?)\s*$/;
|
my ( $name, $value ) = $str =~ /^\s*([^=\s]+)\s*=\s*(.*?)\s*$/;
|
||||||
if ( ! $name ) {
|
if ( ! $name ) {
|
||||||
print( STDERR "Warning, bad line in $config_file: $str\n" );
|
print( STDERR "Warning, bad line in $config_file: $str\n" );
|
||||||
next;
|
next;
|
||||||
} # end if
|
} # end if
|
||||||
$name =~ tr/a-z/A-Z/;
|
$name =~ tr/a-z/A-Z/;
|
||||||
$Config{$name} = $value;
|
$Config{$name} = $value;
|
||||||
}
|
}
|
||||||
close( $CONFIG );
|
close( $CONFIG );
|
||||||
|
|
||||||
use DBI;
|
use DBI;
|
||||||
my $socket;
|
my $socket;
|
||||||
my ( $host, $portOrSocket ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ );
|
my ( $host, $portOrSocket ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ );
|
||||||
|
|
||||||
if ( defined($portOrSocket) )
|
if ( defined($portOrSocket) )
|
||||||
|
{
|
||||||
|
if ( $portOrSocket =~ /^\// )
|
||||||
{
|
{
|
||||||
if ( $portOrSocket =~ /^\// )
|
$socket = ";mysql_socket=".$portOrSocket;
|
||||||
{
|
|
||||||
$socket = ";mysql_socket=".$portOrSocket;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$socket = ";host=".$host.";port=".$portOrSocket;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$socket = ";host=".$Config{ZM_DB_HOST};
|
$socket = ";host=".$host.";port=".$portOrSocket;
|
||||||
}
|
}
|
||||||
my $dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME}
|
}
|
||||||
.$socket
|
else
|
||||||
, $Config{ZM_DB_USER}
|
{
|
||||||
, $Config{ZM_DB_PASS}
|
$socket = ";host=".$Config{ZM_DB_HOST};
|
||||||
) or croak( "Can't connect to db" );
|
}
|
||||||
my $sql = 'select * from Config';
|
my $dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME}
|
||||||
my $sth = $dbh->prepare_cached( $sql ) or croak( "Can't prepare '$sql': ".$dbh->errstr() );
|
.$socket
|
||||||
my $res = $sth->execute() or croak( "Can't execute: ".$sth->errstr() );
|
, $Config{ZM_DB_USER}
|
||||||
while( my $config = $sth->fetchrow_hashref() ) {
|
, $Config{ZM_DB_PASS}
|
||||||
$Config{$config->{Name}} = $config->{Value};
|
) 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();
|
$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 {
|
sub loadConfigFromDB {
|
||||||
|
@ -315,7 +315,7 @@ Copyright (C) 2001-2008 Philip Coombes
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or modify
|
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,
|
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
|
@ -45,17 +45,17 @@ our $AUTOLOAD;
|
||||||
|
|
||||||
sub new
|
sub new
|
||||||
{
|
{
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
my $id = shift;
|
my $id = shift;
|
||||||
my $self = {};
|
my $self = {};
|
||||||
$self->{name} = "PelcoD";
|
$self->{name} = "PelcoD";
|
||||||
if ( !defined($id) )
|
if ( !defined($id) )
|
||||||
{
|
{
|
||||||
Fatal( "No monitor defined when invoking protocol ".$self->{name} );
|
Fatal( "No monitor defined when invoking protocol ".$self->{name} );
|
||||||
}
|
}
|
||||||
$self->{id} = $id;
|
$self->{id} = $id;
|
||||||
bless( $self, $class );
|
bless( $self, $class );
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub DESTROY
|
sub DESTROY
|
||||||
|
@ -64,91 +64,91 @@ sub DESTROY
|
||||||
|
|
||||||
sub AUTOLOAD
|
sub AUTOLOAD
|
||||||
{
|
{
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $class = ref($self) || croak( "$self not object" );
|
my $class = ref($self) || croak( "$self not object" );
|
||||||
my $name = $AUTOLOAD;
|
my $name = $AUTOLOAD;
|
||||||
$name =~ s/.*://;
|
$name =~ s/.*://;
|
||||||
if ( exists($self->{$name}) )
|
if ( exists($self->{$name}) )
|
||||||
{
|
{
|
||||||
return( $self->{$name} );
|
return( $self->{$name} );
|
||||||
}
|
}
|
||||||
croak( "Can't access $name member of object of class $class" );
|
croak( "Can't access $name member of object of class $class" );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub getKey
|
sub getKey
|
||||||
{
|
{
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return( $self->{id} );
|
return( $self->{id} );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub open
|
sub open
|
||||||
{
|
{
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
Fatal( "No open method defined for protocol ".$self->{name} );
|
Fatal( "No open method defined for protocol ".$self->{name} );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub close
|
sub close
|
||||||
{
|
{
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
Fatal( "No close method defined for protocol ".$self->{name} );
|
Fatal( "No close method defined for protocol ".$self->{name} );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub loadMonitor
|
sub loadMonitor
|
||||||
{
|
{
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
if ( !$self->{Monitor} )
|
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" );
|
||||||
{
|
|
||||||
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});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if ( defined($self->{Monitor}->{AutoStopTimeout}) )
|
||||||
|
{
|
||||||
|
# Convert to microseconds.
|
||||||
|
$self->{Monitor}->{AutoStopTimeout} = int(1000000*$self->{Monitor}->{AutoStopTimeout});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub getParam
|
sub getParam
|
||||||
{
|
{
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $params = shift;
|
my $params = shift;
|
||||||
my $name = shift;
|
my $name = shift;
|
||||||
my $default = shift;
|
my $default = shift;
|
||||||
|
|
||||||
if ( defined($params->{$name}) )
|
if ( defined($params->{$name}) )
|
||||||
{
|
{
|
||||||
return( $params->{$name} );
|
return( $params->{$name} );
|
||||||
}
|
}
|
||||||
elsif ( defined($default) )
|
elsif ( defined($default) )
|
||||||
{
|
{
|
||||||
return( $default );
|
return( $default );
|
||||||
}
|
}
|
||||||
Fatal( "Missing mandatory parameter '$name'" );
|
Fatal( "Missing mandatory parameter '$name'" );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub executeCommand
|
sub executeCommand
|
||||||
{
|
{
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $params = shift;
|
my $params = shift;
|
||||||
|
|
||||||
$self->loadMonitor();
|
$self->loadMonitor();
|
||||||
|
|
||||||
my $command = $params->{command};
|
my $command = $params->{command};
|
||||||
delete $params->{command};
|
delete $params->{command};
|
||||||
|
|
||||||
#if ( !defined($self->{$command}) )
|
#if ( !defined($self->{$command}) )
|
||||||
#{
|
#{
|
||||||
#Fatal( "Unsupported command '$command'" );
|
#Fatal( "Unsupported command '$command'" );
|
||||||
#}
|
#}
|
||||||
&{$self->{$command}}( $self, $params );
|
&{$self->{$command}}( $self, $params );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub printMsg
|
sub printMsg
|
||||||
{
|
{
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
Fatal( "No printMsg method defined for protocol ".$self->{name} );
|
Fatal( "No printMsg method defined for protocol ".$self->{name} );
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -161,8 +161,8 @@ ZoneMinder::Database - Perl extension for blah blah blah
|
||||||
|
|
||||||
=head1 SYNOPSIS
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
use ZoneMinder::Database;
|
use ZoneMinder::Database;
|
||||||
blah blah blah
|
blah blah blah
|
||||||
|
|
||||||
=head1 DESCRIPTION
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
|
|
@ -42,13 +42,13 @@ our @ISA = qw(Exporter ZoneMinder::Base);
|
||||||
# will save memory.
|
# will save memory.
|
||||||
our %EXPORT_TAGS = (
|
our %EXPORT_TAGS = (
|
||||||
'functions' => [ qw(
|
'functions' => [ qw(
|
||||||
zmDbConnect
|
zmDbConnect
|
||||||
zmDbDisconnect
|
zmDbDisconnect
|
||||||
zmDbGetMonitors
|
zmDbGetMonitors
|
||||||
zmDbGetMonitor
|
zmDbGetMonitor
|
||||||
zmDbGetMonitorAndControl
|
zmDbGetMonitorAndControl
|
||||||
) ]
|
) ]
|
||||||
);
|
);
|
||||||
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
|
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
|
||||||
|
|
||||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||||
|
@ -72,48 +72,48 @@ our $dbh = undef;
|
||||||
|
|
||||||
sub zmDbConnect
|
sub zmDbConnect
|
||||||
{
|
{
|
||||||
my $force = shift;
|
my $force = shift;
|
||||||
if ( $force )
|
if ( $force )
|
||||||
{
|
{
|
||||||
zmDbDisconnect();
|
zmDbDisconnect();
|
||||||
}
|
}
|
||||||
if ( !defined( $dbh ) )
|
if ( !defined( $dbh ) )
|
||||||
{
|
{
|
||||||
my $socket;
|
my $socket;
|
||||||
my ( $host, $portOrSocket ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ );
|
my ( $host, $portOrSocket ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ );
|
||||||
|
|
||||||
if ( defined($portOrSocket) )
|
if ( defined($portOrSocket) )
|
||||||
{
|
{
|
||||||
if ( $portOrSocket =~ /^\// )
|
if ( $portOrSocket =~ /^\// )
|
||||||
{
|
{
|
||||||
$socket = ";mysql_socket=".$portOrSocket;
|
$socket = ";mysql_socket=".$portOrSocket;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$socket = ";host=".$host.";port=".$portOrSocket;
|
$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 );
|
|
||||||
}
|
}
|
||||||
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
|
sub zmDbDisconnect
|
||||||
{
|
{
|
||||||
if ( defined( $dbh ) )
|
if ( defined( $dbh ) )
|
||||||
{
|
{
|
||||||
$dbh->disconnect();
|
$dbh->disconnect();
|
||||||
$dbh = undef;
|
$dbh = undef;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use constant DB_MON_ALL => 0; # All monitors
|
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
|
sub zmDbGetMonitors
|
||||||
{
|
{
|
||||||
zmDbConnect();
|
zmDbConnect();
|
||||||
|
|
||||||
my $function = shift || DB_MON_ALL;
|
my $function = shift || DB_MON_ALL;
|
||||||
my $sql = "select * from Monitors";
|
my $sql = "select * from Monitors";
|
||||||
|
|
||||||
if ( $function )
|
if ( $function )
|
||||||
|
{
|
||||||
|
if ( $function == DB_MON_CAPT )
|
||||||
{
|
{
|
||||||
if ( $function == DB_MON_CAPT )
|
$sql .= " where Function >= 'Monitor'";
|
||||||
{
|
|
||||||
$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'";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
my $sth = $dbh->prepare_cached( $sql )
|
elsif ( $function == DB_MON_ACTIVE )
|
||||||
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 );
|
$sql .= " where Function > 'Monitor'";
|
||||||
}
|
}
|
||||||
$sth->finish();
|
elsif ( $function == DB_MON_MOTION )
|
||||||
return( \@monitors );
|
{
|
||||||
|
$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
|
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 $sql = "select * from Monitors where Id = ?";
|
||||||
my $sth = $dbh->prepare_cached( $sql )
|
my $sth = $dbh->prepare_cached( $sql )
|
||||||
or croak( "Can't prepare '$sql': ".$dbh->errstr() );
|
or croak( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
my $res = $sth->execute( $id )
|
my $res = $sth->execute( $id )
|
||||||
or croak( "Can't execute '$sql': ".$sth->errstr() );
|
or croak( "Can't execute '$sql': ".$sth->errstr() );
|
||||||
my $monitor = $sth->fetchrow_hashref();
|
my $monitor = $sth->fetchrow_hashref();
|
||||||
|
|
||||||
return( $monitor );
|
return( $monitor );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub zmDbGetMonitorAndControl
|
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
|
my $sql = "SELECT C.*,M.*,C.Protocol
|
||||||
FROM Monitors as M
|
FROM Monitors as M
|
||||||
INNER JOIN Controls as C on (M.ControlId = C.Id)
|
INNER JOIN Controls as C on (M.ControlId = C.Id)
|
||||||
WHERE M.Id = ?"
|
WHERE M.Id = ?"
|
||||||
;
|
;
|
||||||
my $sth = $dbh->prepare_cached( $sql )
|
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( $id )
|
my $res = $sth->execute( $id )
|
||||||
or Fatal( "Can't execute '$sql': ".$sth->errstr() );
|
or Fatal( "Can't execute '$sql': ".$sth->errstr() );
|
||||||
my $monitor = $sth->fetchrow_hashref();
|
my $monitor = $sth->fetchrow_hashref();
|
||||||
|
|
||||||
return( $monitor );
|
return( $monitor );
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -217,8 +217,8 @@ ZoneMinder::Database - Perl extension for blah blah blah
|
||||||
|
|
||||||
=head1 SYNOPSIS
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
use ZoneMinder::Database;
|
use ZoneMinder::Database;
|
||||||
blah blah blah
|
blah blah blah
|
||||||
|
|
||||||
=head1 DESCRIPTION
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,8 @@ our @ISA = qw(Exporter ZoneMinder::Base);
|
||||||
# will save memory.
|
# will save memory.
|
||||||
our %EXPORT_TAGS = (
|
our %EXPORT_TAGS = (
|
||||||
'functions' => [ qw(
|
'functions' => [ qw(
|
||||||
) ]
|
) ]
|
||||||
);
|
);
|
||||||
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
|
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
|
||||||
|
|
||||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||||
|
@ -66,214 +66,214 @@ use ZoneMinder::Database qw(:all);
|
||||||
use POSIX;
|
use POSIX;
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ( $parent, $id, $data ) = @_;
|
my ( $parent, $id, $data ) = @_;
|
||||||
|
|
||||||
my $self = {};
|
my $self = {};
|
||||||
bless $self, $parent;
|
bless $self, $parent;
|
||||||
$$self{dbh} = $ZoneMinder::Database::dbh;
|
$$self{dbh} = $ZoneMinder::Database::dbh;
|
||||||
#zmDbConnect();
|
#zmDbConnect();
|
||||||
if ( ( $$self{Id} = $id ) or $data ) {
|
if ( ( $$self{Id} = $id ) or $data ) {
|
||||||
#$log->debug("loading $parent $id") if $debug or DEBUG_ALL;
|
#$log->debug("loading $parent $id") if $debug or DEBUG_ALL;
|
||||||
$self->load( $data );
|
$self->load( $data );
|
||||||
}
|
}
|
||||||
return $self;
|
return $self;
|
||||||
} # end sub new
|
} # end sub new
|
||||||
|
|
||||||
sub load {
|
sub load {
|
||||||
my ( $self, $data ) = @_;
|
my ( $self, $data ) = @_;
|
||||||
my $type = ref $self;
|
my $type = ref $self;
|
||||||
if ( ! $data ) {
|
if ( ! $data ) {
|
||||||
#$log->debug("Object::load Loading from db $type");
|
#$log->debug("Object::load Loading from db $type");
|
||||||
$data = $$self{dbh}->selectrow_hashref( 'SELECT * FROM Events WHERE Id=?', {}, $$self{Id} );
|
$data = $$self{dbh}->selectrow_hashref( 'SELECT * FROM Events WHERE Id=?', {}, $$self{Id} );
|
||||||
if ( ! $data ) {
|
if ( ! $data ) {
|
||||||
Error( "Failure to load Event record for $$self{Id}: Reason: " . $$self{dbh}->errstr );
|
Error( "Failure to load Event record for $$self{Id}: Reason: " . $$self{dbh}->errstr );
|
||||||
} else {
|
} else {
|
||||||
Debug( 3, "Loaded Event $$self{Id}" );
|
Debug( 3, "Loaded Event $$self{Id}" );
|
||||||
} # end if
|
} # end if
|
||||||
} # end if ! $data
|
} # end if ! $data
|
||||||
if ( $data and %$data ) {
|
if ( $data and %$data ) {
|
||||||
@$self{keys %$data} = values %$data;
|
@$self{keys %$data} = values %$data;
|
||||||
} # end if
|
} # end if
|
||||||
} # end sub load
|
} # end sub load
|
||||||
|
|
||||||
sub Name {
|
sub Name {
|
||||||
if ( @_ > 1 ) {
|
if ( @_ > 1 ) {
|
||||||
$_[0]{Name} = $_[1];
|
$_[0]{Name} = $_[1];
|
||||||
}
|
}
|
||||||
return $_[0]{Name};
|
return $_[0]{Name};
|
||||||
} # end sub Path
|
} # end sub Path
|
||||||
|
|
||||||
sub find {
|
sub find {
|
||||||
shift if $_[0] eq 'ZoneMinder::Event';
|
shift if $_[0] eq 'ZoneMinder::Event';
|
||||||
my %sql_filters = @_;
|
my %sql_filters = @_;
|
||||||
|
|
||||||
my $sql = 'SELECT * FROM Events';
|
my $sql = 'SELECT * FROM Events';
|
||||||
my @sql_filters;
|
my @sql_filters;
|
||||||
my @sql_values;
|
my @sql_values;
|
||||||
|
|
||||||
if ( exists $sql_filters{Name} ) {
|
if ( exists $sql_filters{Name} ) {
|
||||||
push @sql_filters , ' Name = ? ';
|
push @sql_filters , ' Name = ? ';
|
||||||
push @sql_values, $sql_filters{Name};
|
push @sql_values, $sql_filters{Name};
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= ' WHERE ' . join(' AND ', @sql_filters ) if @sql_filters;
|
$sql .= ' WHERE ' . join(' AND ', @sql_filters ) if @sql_filters;
|
||||||
$sql .= ' LIMIT ' . $sql_filters{limit} if $sql_filters{limit};
|
$sql .= ' LIMIT ' . $sql_filters{limit} if $sql_filters{limit};
|
||||||
|
|
||||||
my $sth = $ZoneMinder::Database::dbh->prepare_cached( $sql )
|
my $sth = $ZoneMinder::Database::dbh->prepare_cached( $sql )
|
||||||
or Fatal( "Can't prepare '$sql': ".$ZoneMinder::Database::dbh->errstr() );
|
or Fatal( "Can't prepare '$sql': ".$ZoneMinder::Database::dbh->errstr() );
|
||||||
my $res = $sth->execute( @sql_values )
|
my $res = $sth->execute( @sql_values )
|
||||||
or Fatal( "Can't execute '$sql': ".$sth->errstr() );
|
or Fatal( "Can't execute '$sql': ".$sth->errstr() );
|
||||||
|
|
||||||
my @results;
|
my @results;
|
||||||
|
|
||||||
while( my $db_filter = $sth->fetchrow_hashref() ) {
|
while( my $db_filter = $sth->fetchrow_hashref() ) {
|
||||||
my $filter = new ZoneMinder::Event( $$db_filter{Id}, $db_filter );
|
my $filter = new ZoneMinder::Event( $$db_filter{Id}, $db_filter );
|
||||||
push @results, $filter;
|
push @results, $filter;
|
||||||
} # end while
|
} # end while
|
||||||
return @results;
|
return @results;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub find_one {
|
sub find_one {
|
||||||
my @results = find(@_);
|
my @results = find(@_);
|
||||||
return $results[0] if @results;
|
return $results[0] if @results;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub getEventPath
|
sub getEventPath
|
||||||
{
|
{
|
||||||
my $event = shift;
|
my $event = shift;
|
||||||
|
|
||||||
my $event_path = "";
|
my $event_path = "";
|
||||||
if ( $Config{ZM_USE_DEEP_STORAGE} )
|
if ( $Config{ZM_USE_DEEP_STORAGE} )
|
||||||
{
|
{
|
||||||
$event_path = $Config{ZM_DIR_EVENTS}
|
$event_path = $Config{ZM_DIR_EVENTS}
|
||||||
.'/'.$event->{MonitorId}
|
.'/'.$event->{MonitorId}
|
||||||
.'/'.strftime( "%y/%m/%d/%H/%M/%S",
|
.'/'.strftime( "%y/%m/%d/%H/%M/%S",
|
||||||
localtime($event->{Time})
|
localtime($event->{Time})
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$event_path = $Config{ZM_DIR_EVENTS}
|
$event_path = $Config{ZM_DIR_EVENTS}
|
||||||
.'/'.$event->{MonitorId}
|
.'/'.$event->{MonitorId}
|
||||||
.'/'.$event->{Id}
|
.'/'.$event->{Id}
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( index($Config{ZM_DIR_EVENTS},'/') != 0 ){
|
if ( index($Config{ZM_DIR_EVENTS},'/') != 0 ){
|
||||||
$event_path = $Config{ZM_PATH_WEB}
|
$event_path = $Config{ZM_PATH_WEB}
|
||||||
.'/'.$event_path
|
.'/'.$event_path
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
return( $event_path );
|
return( $event_path );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub GenerateVideo {
|
sub GenerateVideo {
|
||||||
my ( $self, $rate, $fps, $scale, $size, $overwrite, $format ) = @_;
|
my ( $self, $rate, $fps, $scale, $size, $overwrite, $format ) = @_;
|
||||||
|
|
||||||
my $event_path = getEventPath( $self );
|
my $event_path = getEventPath( $self );
|
||||||
chdir( $event_path );
|
chdir( $event_path );
|
||||||
( my $video_name = $self->{Name} ) =~ s/\s/_/g;
|
( my $video_name = $self->{Name} ) =~ s/\s/_/g;
|
||||||
|
|
||||||
my @file_parts;
|
my @file_parts;
|
||||||
if ( $rate )
|
if ( $rate )
|
||||||
{
|
{
|
||||||
my $file_rate = $rate;
|
my $file_rate = $rate;
|
||||||
$file_rate =~ s/\./_/;
|
$file_rate =~ s/\./_/;
|
||||||
$file_rate =~ s/_00//;
|
$file_rate =~ s/_00//;
|
||||||
$file_rate =~ s/(_\d+)0+$/$1/;
|
$file_rate =~ s/(_\d+)0+$/$1/;
|
||||||
$file_rate = 'r'.$file_rate;
|
$file_rate = 'r'.$file_rate;
|
||||||
push( @file_parts, $file_rate );
|
push( @file_parts, $file_rate );
|
||||||
}
|
}
|
||||||
elsif ( $fps )
|
elsif ( $fps )
|
||||||
{
|
{
|
||||||
my $file_fps = $fps;
|
my $file_fps = $fps;
|
||||||
$file_fps =~ s/\./_/;
|
$file_fps =~ s/\./_/;
|
||||||
$file_fps =~ s/_00//;
|
$file_fps =~ s/_00//;
|
||||||
$file_fps =~ s/(_\d+)0+$/$1/;
|
$file_fps =~ s/(_\d+)0+$/$1/;
|
||||||
$file_fps = 'R'.$file_fps;
|
$file_fps = 'R'.$file_fps;
|
||||||
push( @file_parts, $file_fps );
|
push( @file_parts, $file_fps );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $scale )
|
if ( $scale )
|
||||||
{
|
{
|
||||||
my $file_scale = $scale;
|
my $file_scale = $scale;
|
||||||
$file_scale =~ s/\./_/;
|
$file_scale =~ s/\./_/;
|
||||||
$file_scale =~ s/_00//;
|
$file_scale =~ s/_00//;
|
||||||
$file_scale =~ s/(_\d+)0+$/$1/;
|
$file_scale =~ s/(_\d+)0+$/$1/;
|
||||||
$file_scale = 's'.$file_scale;
|
$file_scale = 's'.$file_scale;
|
||||||
push( @file_parts, $file_scale );
|
push( @file_parts, $file_scale );
|
||||||
}
|
}
|
||||||
elsif ( $size )
|
elsif ( $size )
|
||||||
{
|
{
|
||||||
my $file_size = 'S'.$size;
|
my $file_size = 'S'.$size;
|
||||||
push( @file_parts, $file_size );
|
push( @file_parts, $file_size );
|
||||||
}
|
}
|
||||||
my $video_file = "$video_name-".$file_parts[0]."-".$file_parts[1].".$format";
|
my $video_file = "$video_name-".$file_parts[0]."-".$file_parts[1].".$format";
|
||||||
if ( $overwrite || !-s $video_file )
|
if ( $overwrite || !-s $video_file )
|
||||||
{
|
{
|
||||||
Info( "Creating video file $video_file for event $self->{Id}\n" );
|
Info( "Creating video file $video_file for event $self->{Id}\n" );
|
||||||
|
|
||||||
my $frame_rate = sprintf( "%.2f", $self->{Frames}/$self->{FullLength} );
|
my $frame_rate = sprintf( "%.2f", $self->{Frames}/$self->{FullLength} );
|
||||||
if ( $rate )
|
if ( $rate )
|
||||||
{
|
{
|
||||||
if ( $rate != 1.0 )
|
if ( $rate != 1.0 )
|
||||||
{
|
{
|
||||||
$frame_rate *= $rate;
|
$frame_rate *= $rate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ( $fps )
|
elsif ( $fps )
|
||||||
{
|
{
|
||||||
$frame_rate = $fps;
|
$frame_rate = $fps;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $width = $self->{MonitorWidth};
|
my $width = $self->{MonitorWidth};
|
||||||
my $height = $self->{MonitorHeight};
|
my $height = $self->{MonitorHeight};
|
||||||
my $video_size = " ${width}x${height}";
|
my $video_size = " ${width}x${height}";
|
||||||
|
|
||||||
if ( $scale )
|
if ( $scale )
|
||||||
{
|
{
|
||||||
if ( $scale != 1.0 )
|
if ( $scale != 1.0 )
|
||||||
{
|
{
|
||||||
$width = int($width*$scale);
|
$width = int($width*$scale);
|
||||||
$height = int($height*$scale);
|
$height = int($height*$scale);
|
||||||
$video_size = " ${width}x${height}";
|
$video_size = " ${width}x${height}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ( $size )
|
elsif ( $size )
|
||||||
{
|
{
|
||||||
$video_size = $size;
|
$video_size = $size;
|
||||||
}
|
}
|
||||||
my $command = $Config{ZM_PATH_FFMPEG}
|
my $command = $Config{ZM_PATH_FFMPEG}
|
||||||
." -y -r $frame_rate "
|
." -y -r $frame_rate "
|
||||||
.$Config{ZM_FFMPEG_INPUT_OPTIONS}
|
.$Config{ZM_FFMPEG_INPUT_OPTIONS}
|
||||||
." -i %0"
|
." -i %0"
|
||||||
.$Config{ZM_EVENT_IMAGE_DIGITS}
|
.$Config{ZM_EVENT_IMAGE_DIGITS}
|
||||||
."d-capture.jpg -s $video_size "
|
."d-capture.jpg -s $video_size "
|
||||||
#. " -f concat -i /tmp/event_files.txt"
|
#. " -f concat -i /tmp/event_files.txt"
|
||||||
." -s $video_size "
|
." -s $video_size "
|
||||||
.$Config{ZM_FFMPEG_OUTPUT_OPTIONS}
|
.$Config{ZM_FFMPEG_OUTPUT_OPTIONS}
|
||||||
." '$video_file' > ffmpeg.log 2>&1"
|
." '$video_file' > ffmpeg.log 2>&1"
|
||||||
;
|
;
|
||||||
Debug( $command."\n" );
|
Debug( $command."\n" );
|
||||||
my $output = qx($command);
|
my $output = qx($command);
|
||||||
|
|
||||||
my $status = $? >> 8;
|
my $status = $? >> 8;
|
||||||
if ( $status )
|
if ( $status )
|
||||||
{
|
{
|
||||||
Error( "Unable to generate video, check "
|
Error( "Unable to generate video, check "
|
||||||
.$event_path."/ffmpeg.log for details"
|
.$event_path."/ffmpeg.log for details"
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Info( "Finished $video_file\n" );
|
Info( "Finished $video_file\n" );
|
||||||
return $event_path.'/'.$video_file;
|
return $event_path.'/'.$video_file;
|
||||||
} else {
|
} else {
|
||||||
Info( "Video file $video_file already exists for event $self->{Id}\n" );
|
Info( "Video file $video_file already exists for event $self->{Id}\n" );
|
||||||
return $event_path.'/'.$video_file;
|
return $event_path.'/'.$video_file;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} # end sub GenerateVideo
|
} # end sub GenerateVideo
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -286,8 +286,8 @@ ZoneMinder::Database - Perl extension for blah blah blah
|
||||||
|
|
||||||
=head1 SYNOPSIS
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
use ZoneMinder::Event;
|
use ZoneMinder::Event;
|
||||||
blah blah blah
|
blah blah blah
|
||||||
|
|
||||||
=head1 DESCRIPTION
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
|
|
@ -66,378 +66,378 @@ use ZoneMinder::Database qw(:all);
|
||||||
use POSIX;
|
use POSIX;
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ( $parent, $id, $data ) = @_;
|
my ( $parent, $id, $data ) = @_;
|
||||||
|
|
||||||
my $self = {};
|
my $self = {};
|
||||||
bless $self, $parent;
|
bless $self, $parent;
|
||||||
$$self{dbh} = $ZoneMinder::Database::dbh;
|
$$self{dbh} = $ZoneMinder::Database::dbh;
|
||||||
#zmDbConnect();
|
#zmDbConnect();
|
||||||
if ( ( $$self{Id} = $id ) or $data ) {
|
if ( ( $$self{Id} = $id ) or $data ) {
|
||||||
#$log->debug("loading $parent $id") if $debug or DEBUG_ALL;
|
#$log->debug("loading $parent $id") if $debug or DEBUG_ALL;
|
||||||
$self->load( $data );
|
$self->load( $data );
|
||||||
}
|
}
|
||||||
return $self;
|
return $self;
|
||||||
} # end sub new
|
} # end sub new
|
||||||
|
|
||||||
sub load {
|
sub load {
|
||||||
my ( $self, $data ) = @_;
|
my ( $self, $data ) = @_;
|
||||||
my $type = ref $self;
|
my $type = ref $self;
|
||||||
if ( ! $data ) {
|
if ( ! $data ) {
|
||||||
#$log->debug("Object::load Loading from db $type");
|
#$log->debug("Object::load Loading from db $type");
|
||||||
$data = $$self{dbh}->selectrow_hashref( 'SELECT * FROM Filter WHERE Id=?', {}, $$self{Id} );
|
$data = $$self{dbh}->selectrow_hashref( 'SELECT * FROM Filter WHERE Id=?', {}, $$self{Id} );
|
||||||
if ( ! $data ) {
|
if ( ! $data ) {
|
||||||
Error( "Failure to load Filter record for $$self{Id}: Reason: " . $$self{dbh}->errstr );
|
Error( "Failure to load Filter record for $$self{Id}: Reason: " . $$self{dbh}->errstr );
|
||||||
} else {
|
} else {
|
||||||
Debug( 3, "Loaded Filter $$self{Id}" );
|
Debug( 3, "Loaded Filter $$self{Id}" );
|
||||||
} # end if
|
} # end if
|
||||||
} # end if ! $data
|
} # end if ! $data
|
||||||
if ( $data and %$data ) {
|
if ( $data and %$data ) {
|
||||||
@$self{keys %$data} = values %$data;
|
@$self{keys %$data} = values %$data;
|
||||||
} # end if
|
} # end if
|
||||||
} # end sub load
|
} # end sub load
|
||||||
|
|
||||||
sub Name {
|
sub Name {
|
||||||
if ( @_ > 1 ) {
|
if ( @_ > 1 ) {
|
||||||
$_[0]{Name} = $_[1];
|
$_[0]{Name} = $_[1];
|
||||||
}
|
}
|
||||||
return $_[0]{Name};
|
return $_[0]{Name};
|
||||||
} # end sub Path
|
} # end sub Path
|
||||||
|
|
||||||
sub find {
|
sub find {
|
||||||
shift if $_[0] eq 'ZoneMinder::Filter';
|
shift if $_[0] eq 'ZoneMinder::Filter';
|
||||||
my %sql_filters = @_;
|
my %sql_filters = @_;
|
||||||
|
|
||||||
my $sql = 'SELECT * FROM Filters';
|
my $sql = 'SELECT * FROM Filters';
|
||||||
my @sql_filters;
|
my @sql_filters;
|
||||||
my @sql_values;
|
my @sql_values;
|
||||||
|
|
||||||
if ( exists $sql_filters{Name} ) {
|
if ( exists $sql_filters{Name} ) {
|
||||||
push @sql_filters , ' Name = ? ';
|
push @sql_filters , ' Name = ? ';
|
||||||
push @sql_values, $sql_filters{Name};
|
push @sql_values, $sql_filters{Name};
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= ' WHERE ' . join(' AND ', @sql_filters ) if @sql_filters;
|
$sql .= ' WHERE ' . join(' AND ', @sql_filters ) if @sql_filters;
|
||||||
$sql .= ' LIMIT ' . $sql_filters{limit} if $sql_filters{limit};
|
$sql .= ' LIMIT ' . $sql_filters{limit} if $sql_filters{limit};
|
||||||
|
|
||||||
my $sth = $ZoneMinder::Database::dbh->prepare_cached( $sql )
|
my $sth = $ZoneMinder::Database::dbh->prepare_cached( $sql )
|
||||||
or Fatal( "Can't prepare '$sql': ".$ZoneMinder::Database::dbh->errstr() );
|
or Fatal( "Can't prepare '$sql': ".$ZoneMinder::Database::dbh->errstr() );
|
||||||
my $res = $sth->execute( @sql_values )
|
my $res = $sth->execute( @sql_values )
|
||||||
or Fatal( "Can't execute '$sql': ".$sth->errstr() );
|
or Fatal( "Can't execute '$sql': ".$sth->errstr() );
|
||||||
|
|
||||||
my @results;
|
my @results;
|
||||||
|
|
||||||
while( my $db_filter = $sth->fetchrow_hashref() ) {
|
while( my $db_filter = $sth->fetchrow_hashref() ) {
|
||||||
my $filter = new ZoneMinder::Filter( $$db_filter{Id}, $db_filter );
|
my $filter = new ZoneMinder::Filter( $$db_filter{Id}, $db_filter );
|
||||||
push @results, $filter;
|
push @results, $filter;
|
||||||
} # end while
|
} # end while
|
||||||
return @results;
|
return @results;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub find_one {
|
sub find_one {
|
||||||
my @results = find(@_);
|
my @results = find(@_);
|
||||||
return $results[0] if @results;
|
return $results[0] if @results;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub Execute {
|
sub Execute {
|
||||||
my $self = $_[0];
|
my $self = $_[0];
|
||||||
|
|
||||||
my $sql = $self->Sql();
|
my $sql = $self->Sql();
|
||||||
|
|
||||||
if ( $self->{HasDiskPercent} )
|
if ( $self->{HasDiskPercent} )
|
||||||
{
|
{
|
||||||
my $disk_percent = getDiskPercent();
|
my $disk_percent = getDiskPercent();
|
||||||
$sql =~ s/zmDiskPercent/$disk_percent/g;
|
$sql =~ s/zmDiskPercent/$disk_percent/g;
|
||||||
}
|
}
|
||||||
if ( $self->{HasDiskBlocks} )
|
if ( $self->{HasDiskBlocks} )
|
||||||
{
|
{
|
||||||
my $disk_blocks = getDiskBlocks();
|
my $disk_blocks = getDiskBlocks();
|
||||||
$sql =~ s/zmDiskBlocks/$disk_blocks/g;
|
$sql =~ s/zmDiskBlocks/$disk_blocks/g;
|
||||||
}
|
}
|
||||||
if ( $self->{HasSystemLoad} )
|
if ( $self->{HasSystemLoad} )
|
||||||
{
|
{
|
||||||
my $load = getLoad();
|
my $load = getLoad();
|
||||||
$sql =~ s/zmSystemLoad/$load/g;
|
$sql =~ s/zmSystemLoad/$load/g;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $sth = $$self{dbh}->prepare_cached( $sql )
|
my $sth = $$self{dbh}->prepare_cached( $sql )
|
||||||
or Fatal( "Can't prepare '$sql': ".$$self{dbh}->errstr() );
|
or Fatal( "Can't prepare '$sql': ".$$self{dbh}->errstr() );
|
||||||
my $res = $sth->execute();
|
my $res = $sth->execute();
|
||||||
if ( !$res )
|
if ( !$res )
|
||||||
{
|
{
|
||||||
Error( "Can't execute filter '$sql', ignoring: ".$sth->errstr() );
|
Error( "Can't execute filter '$sql', ignoring: ".$sth->errstr() );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
my @results;
|
my @results;
|
||||||
|
|
||||||
while( my $event = $sth->fetchrow_hashref() ) {
|
while( my $event = $sth->fetchrow_hashref() ) {
|
||||||
push @results, $event;
|
push @results, $event;
|
||||||
}
|
}
|
||||||
$sth->finish();
|
$sth->finish();
|
||||||
return @results;
|
return @results;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub Sql {
|
sub Sql {
|
||||||
my $self = $_[0];
|
my $self = $_[0];
|
||||||
if ( ! $$self{Sql} ) {
|
if ( ! $$self{Sql} ) {
|
||||||
my $filter_expr = ZoneMinder::General::jsonDecode( $self->{Query} );
|
my $filter_expr = ZoneMinder::General::jsonDecode( $self->{Query} );
|
||||||
my $sql = "SELECT E.Id,
|
my $sql = "SELECT E.Id,
|
||||||
E.MonitorId,
|
E.MonitorId,
|
||||||
M.Name as MonitorName,
|
M.Name as MonitorName,
|
||||||
M.DefaultRate,
|
M.DefaultRate,
|
||||||
M.DefaultScale,
|
M.DefaultScale,
|
||||||
E.Name,
|
E.Name,
|
||||||
E.Cause,
|
E.Cause,
|
||||||
E.Notes,
|
E.Notes,
|
||||||
E.StartTime,
|
E.StartTime,
|
||||||
unix_timestamp(E.StartTime) as Time,
|
unix_timestamp(E.StartTime) as Time,
|
||||||
E.Length,
|
E.Length,
|
||||||
E.Frames,
|
E.Frames,
|
||||||
E.AlarmFrames,
|
E.AlarmFrames,
|
||||||
E.TotScore,
|
E.TotScore,
|
||||||
E.AvgScore,
|
E.AvgScore,
|
||||||
E.MaxScore,
|
E.MaxScore,
|
||||||
E.Archived,
|
E.Archived,
|
||||||
E.Videoed,
|
E.Videoed,
|
||||||
E.Uploaded,
|
E.Uploaded,
|
||||||
E.Emailed,
|
E.Emailed,
|
||||||
E.Messaged,
|
E.Messaged,
|
||||||
E.Executed
|
E.Executed
|
||||||
FROM Events as E
|
FROM Events as E
|
||||||
INNER JOIN Monitors as M on M.Id = E.MonitorId
|
INNER JOIN Monitors as M on M.Id = E.MonitorId
|
||||||
";
|
";
|
||||||
$self->{Sql} = '';
|
$self->{Sql} = '';
|
||||||
|
|
||||||
if ( $filter_expr->{terms} ) {
|
if ( $filter_expr->{terms} ) {
|
||||||
for ( my $i = 0; $i < @{$filter_expr->{terms}}; $i++ ) {
|
for ( my $i = 0; $i < @{$filter_expr->{terms}}; $i++ ) {
|
||||||
if ( exists($filter_expr->{terms}[$i]->{cnj}) ) {
|
if ( exists($filter_expr->{terms}[$i]->{cnj}) ) {
|
||||||
$self->{Sql} .= " ".$filter_expr->{terms}[$i]->{cnj}." ";
|
$self->{Sql} .= " ".$filter_expr->{terms}[$i]->{cnj}." ";
|
||||||
}
|
}
|
||||||
if ( exists($filter_expr->{terms}[$i]->{obr}) ) {
|
if ( exists($filter_expr->{terms}[$i]->{obr}) ) {
|
||||||
$self->{Sql} .= " ".str_repeat( "(", $filter_expr->{terms}[$i]->{obr} )." ";
|
$self->{Sql} .= " ".str_repeat( "(", $filter_expr->{terms}[$i]->{obr} )." ";
|
||||||
}
|
}
|
||||||
my $value = $filter_expr->{terms}[$i]->{val};
|
my $value = $filter_expr->{terms}[$i]->{val};
|
||||||
my @value_list;
|
my @value_list;
|
||||||
if ( $filter_expr->{terms}[$i]->{attr} ) {
|
if ( $filter_expr->{terms}[$i]->{attr} ) {
|
||||||
if ( $filter_expr->{terms}[$i]->{attr} =~ /^Monitor/ ) {
|
if ( $filter_expr->{terms}[$i]->{attr} =~ /^Monitor/ ) {
|
||||||
my ( $temp_attr_name ) = $filter_expr->{terms}[$i]->{attr} =~ /^Monitor(.+)$/;
|
my ( $temp_attr_name ) = $filter_expr->{terms}[$i]->{attr} =~ /^Monitor(.+)$/;
|
||||||
$self->{Sql} .= "M.".$temp_attr_name;
|
$self->{Sql} .= "M.".$temp_attr_name;
|
||||||
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'DateTime' ) {
|
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'DateTime' ) {
|
||||||
$self->{Sql} .= "E.StartTime";
|
$self->{Sql} .= "E.StartTime";
|
||||||
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Date' ) {
|
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Date' ) {
|
||||||
$self->{Sql} .= "to_days( E.StartTime )";
|
$self->{Sql} .= "to_days( E.StartTime )";
|
||||||
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Time' ) {
|
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Time' ) {
|
||||||
$self->{Sql} .= "extract( hour_second from E.StartTime )";
|
$self->{Sql} .= "extract( hour_second from E.StartTime )";
|
||||||
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Weekday' ) {
|
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Weekday' ) {
|
||||||
$self->{Sql} .= "weekday( E.StartTime )";
|
$self->{Sql} .= "weekday( E.StartTime )";
|
||||||
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'DiskPercent' ) {
|
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'DiskPercent' ) {
|
||||||
$self->{Sql} .= "zmDiskPercent";
|
$self->{Sql} .= "zmDiskPercent";
|
||||||
$self->{HasDiskPercent} = !undef;
|
$self->{HasDiskPercent} = !undef;
|
||||||
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'DiskBlocks' ) {
|
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'DiskBlocks' ) {
|
||||||
$self->{Sql} .= "zmDiskBlocks";
|
$self->{Sql} .= "zmDiskBlocks";
|
||||||
$self->{HasDiskBlocks} = !undef;
|
$self->{HasDiskBlocks} = !undef;
|
||||||
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'SystemLoad' ) {
|
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'SystemLoad' ) {
|
||||||
$self->{Sql} .= "zmSystemLoad";
|
$self->{Sql} .= "zmSystemLoad";
|
||||||
$self->{HasSystemLoad} = !undef;
|
$self->{HasSystemLoad} = !undef;
|
||||||
} else {
|
} else {
|
||||||
$self->{Sql} .= "E.".$filter_expr->{terms}[$i]->{attr};
|
$self->{Sql} .= "E.".$filter_expr->{terms}[$i]->{attr};
|
||||||
}
|
}
|
||||||
|
|
||||||
( my $stripped_value = $value ) =~ s/^["\']+?(.+)["\']+?$/$1/;
|
( my $stripped_value = $value ) =~ s/^["\']+?(.+)["\']+?$/$1/;
|
||||||
foreach my $temp_value ( split( /["'\s]*?,["'\s]*?/, $stripped_value ) ) {
|
foreach my $temp_value ( split( /["'\s]*?,["'\s]*?/, $stripped_value ) ) {
|
||||||
if ( $filter_expr->{terms}[$i]->{attr} =~ /^Monitor/ ) {
|
if ( $filter_expr->{terms}[$i]->{attr} =~ /^Monitor/ ) {
|
||||||
$value = "'$temp_value'";
|
$value = "'$temp_value'";
|
||||||
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Name'
|
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Name'
|
||||||
|| $filter_expr->{terms}[$i]->{attr} eq 'Cause'
|
|| $filter_expr->{terms}[$i]->{attr} eq 'Cause'
|
||||||
|| $filter_expr->{terms}[$i]->{attr} eq 'Notes'
|
|| $filter_expr->{terms}[$i]->{attr} eq 'Notes'
|
||||||
) {
|
) {
|
||||||
$value = "'$temp_value'";
|
$value = "'$temp_value'";
|
||||||
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'DateTime' ) {
|
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'DateTime' ) {
|
||||||
$value = DateTimeToSQL( $temp_value );
|
$value = DateTimeToSQL( $temp_value );
|
||||||
if ( !$value ) {
|
if ( !$value ) {
|
||||||
Error( "Error parsing date/time '$temp_value', "
|
Error( "Error parsing date/time '$temp_value', "
|
||||||
."skipping filter '$self->{Name}'\n" );
|
."skipping filter '$self->{Name}'\n" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$value = "'$value'";
|
$value = "'$value'";
|
||||||
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Date' ) {
|
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Date' ) {
|
||||||
$value = DateTimeToSQL( $temp_value );
|
$value = DateTimeToSQL( $temp_value );
|
||||||
if ( !$value ) {
|
if ( !$value ) {
|
||||||
Error( "Error parsing date/time '$temp_value', "
|
Error( "Error parsing date/time '$temp_value', "
|
||||||
."skipping filter '$self->{Name}'\n" );
|
."skipping filter '$self->{Name}'\n" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$value = "to_days( '$value' )";
|
$value = "to_days( '$value' )";
|
||||||
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Time' ) {
|
} elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Time' ) {
|
||||||
$value = DateTimeToSQL( $temp_value );
|
$value = DateTimeToSQL( $temp_value );
|
||||||
if ( !$value ) {
|
if ( !$value ) {
|
||||||
Error( "Error parsing date/time '$temp_value', "
|
Error( "Error parsing date/time '$temp_value', "
|
||||||
."skipping filter '$self->{Name}'\n" );
|
."skipping filter '$self->{Name}'\n" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$value = "extract( hour_second from '$value' )";
|
$value = "extract( hour_second from '$value' )";
|
||||||
} else {
|
} else {
|
||||||
$value = $temp_value;
|
$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}." )";
|
|
||||||
}
|
}
|
||||||
|
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;
|
} # end foreach term
|
||||||
if ( $self->{AutoArchive} )
|
} # end if terms
|
||||||
{
|
|
||||||
push( @auto_terms, "E.Archived = 0" )
|
if ( $self->{Sql} )
|
||||||
}
|
{
|
||||||
if ( $self->{AutoVideo} )
|
if ( $self->{AutoMessage} )
|
||||||
{
|
{
|
||||||
push( @auto_terms, "E.Videoed = 0" )
|
# Include all events, including events that are still ongoing
|
||||||
}
|
# and have no EndTime yet
|
||||||
if ( $self->{AutoUpload} )
|
$sql .= " and ( ".$self->{Sql}." )";
|
||||||
{
|
}
|
||||||
push( @auto_terms, "E.Uploaded = 0" )
|
else
|
||||||
}
|
{
|
||||||
if ( $self->{AutoEmail} )
|
# Only include closed events (events with valid EndTime)
|
||||||
{
|
$sql .= " where not isnull(E.EndTime) and ( ".$self->{Sql}." )";
|
||||||
push( @auto_terms, "E.Emailed = 0" )
|
}
|
||||||
}
|
}
|
||||||
if ( $self->{AutoMessage} )
|
my @auto_terms;
|
||||||
{
|
if ( $self->{AutoArchive} )
|
||||||
push( @auto_terms, "E.Messaged = 0" )
|
{
|
||||||
}
|
push( @auto_terms, "E.Archived = 0" )
|
||||||
if ( $self->{AutoExecute} )
|
}
|
||||||
{
|
if ( $self->{AutoVideo} )
|
||||||
push( @auto_terms, "E.Executed = 0" )
|
{
|
||||||
}
|
push( @auto_terms, "E.Videoed = 0" )
|
||||||
if ( @auto_terms )
|
}
|
||||||
{
|
if ( $self->{AutoUpload} )
|
||||||
$sql .= " and ( ".join( " or ", @auto_terms )." )";
|
{
|
||||||
}
|
push( @auto_terms, "E.Uploaded = 0" )
|
||||||
if ( !$filter_expr->{sort_field} )
|
}
|
||||||
{
|
if ( $self->{AutoEmail} )
|
||||||
$filter_expr->{sort_field} = 'StartTime';
|
{
|
||||||
$filter_expr->{sort_asc} = 0;
|
push( @auto_terms, "E.Emailed = 0" )
|
||||||
}
|
}
|
||||||
my $sort_column = '';
|
if ( $self->{AutoMessage} )
|
||||||
if ( $filter_expr->{sort_field} eq 'Id' )
|
{
|
||||||
{
|
push( @auto_terms, "E.Messaged = 0" )
|
||||||
$sort_column = "E.Id";
|
}
|
||||||
}
|
if ( $self->{AutoExecute} )
|
||||||
elsif ( $filter_expr->{sort_field} eq 'MonitorName' )
|
{
|
||||||
{
|
push( @auto_terms, "E.Executed = 0" )
|
||||||
$sort_column = "M.Name";
|
}
|
||||||
}
|
if ( @auto_terms )
|
||||||
elsif ( $filter_expr->{sort_field} eq 'Name' )
|
{
|
||||||
{
|
$sql .= " and ( ".join( " or ", @auto_terms )." )";
|
||||||
$sort_column = "E.Name";
|
}
|
||||||
}
|
if ( !$filter_expr->{sort_field} )
|
||||||
elsif ( $filter_expr->{sort_field} eq 'StartTime' )
|
{
|
||||||
{
|
$filter_expr->{sort_field} = 'StartTime';
|
||||||
$sort_column = "E.StartTime";
|
$filter_expr->{sort_asc} = 0;
|
||||||
}
|
}
|
||||||
elsif ( $filter_expr->{sort_field} eq 'Secs' )
|
my $sort_column = '';
|
||||||
{
|
if ( $filter_expr->{sort_field} eq 'Id' )
|
||||||
$sort_column = "E.Length";
|
{
|
||||||
}
|
$sort_column = "E.Id";
|
||||||
elsif ( $filter_expr->{sort_field} eq 'Frames' )
|
}
|
||||||
{
|
elsif ( $filter_expr->{sort_field} eq 'MonitorName' )
|
||||||
$sort_column = "E.Frames";
|
{
|
||||||
}
|
$sort_column = "M.Name";
|
||||||
elsif ( $filter_expr->{sort_field} eq 'AlarmFrames' )
|
}
|
||||||
{
|
elsif ( $filter_expr->{sort_field} eq 'Name' )
|
||||||
$sort_column = "E.AlarmFrames";
|
{
|
||||||
}
|
$sort_column = "E.Name";
|
||||||
elsif ( $filter_expr->{sort_field} eq 'TotScore' )
|
}
|
||||||
{
|
elsif ( $filter_expr->{sort_field} eq 'StartTime' )
|
||||||
$sort_column = "E.TotScore";
|
{
|
||||||
}
|
$sort_column = "E.StartTime";
|
||||||
elsif ( $filter_expr->{sort_field} eq 'AvgScore' )
|
}
|
||||||
{
|
elsif ( $filter_expr->{sort_field} eq 'Secs' )
|
||||||
$sort_column = "E.AvgScore";
|
{
|
||||||
}
|
$sort_column = "E.Length";
|
||||||
elsif ( $filter_expr->{sort_field} eq 'MaxScore' )
|
}
|
||||||
{
|
elsif ( $filter_expr->{sort_field} eq 'Frames' )
|
||||||
$sort_column = "E.MaxScore";
|
{
|
||||||
}
|
$sort_column = "E.Frames";
|
||||||
else
|
}
|
||||||
{
|
elsif ( $filter_expr->{sort_field} eq 'AlarmFrames' )
|
||||||
$sort_column = "E.StartTime";
|
{
|
||||||
}
|
$sort_column = "E.AlarmFrames";
|
||||||
my $sort_order = $filter_expr->{sort_asc}?"asc":"desc";
|
}
|
||||||
$sql .= " order by ".$sort_column." ".$sort_order;
|
elsif ( $filter_expr->{sort_field} eq 'TotScore' )
|
||||||
if ( $filter_expr->{limit} )
|
{
|
||||||
{
|
$sort_column = "E.TotScore";
|
||||||
$sql .= " limit 0,".$filter_expr->{limit};
|
}
|
||||||
}
|
elsif ( $filter_expr->{sort_field} eq 'AvgScore' )
|
||||||
Debug( "SQL:$sql\n" );
|
{
|
||||||
$self->{Sql} = $sql;
|
$sort_column = "E.AvgScore";
|
||||||
} # end if has Sql
|
}
|
||||||
return $self->{Sql};
|
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
|
} # end sub Sql
|
||||||
|
|
||||||
sub getDiskPercent
|
sub getDiskPercent
|
||||||
{
|
{
|
||||||
my $command = "df .";
|
my $command = "df .";
|
||||||
my $df = qx( $command );
|
my $df = qx( $command );
|
||||||
my $space = -1;
|
my $space = -1;
|
||||||
if ( $df =~ /\s(\d+)%/ms )
|
if ( $df =~ /\s(\d+)%/ms )
|
||||||
{
|
{
|
||||||
$space = $1;
|
$space = $1;
|
||||||
}
|
}
|
||||||
return( $space );
|
return( $space );
|
||||||
}
|
}
|
||||||
sub getDiskBlocks
|
sub getDiskBlocks
|
||||||
{
|
{
|
||||||
my $command = "df .";
|
my $command = "df .";
|
||||||
my $df = qx( $command );
|
my $df = qx( $command );
|
||||||
my $space = -1;
|
my $space = -1;
|
||||||
if ( $df =~ /\s(\d+)\s+\d+\s+\d+%/ms )
|
if ( $df =~ /\s(\d+)\s+\d+\s+\d+%/ms )
|
||||||
{
|
{
|
||||||
$space = $1;
|
$space = $1;
|
||||||
}
|
}
|
||||||
return( $space );
|
return( $space );
|
||||||
}
|
}
|
||||||
sub getLoad
|
sub getLoad
|
||||||
{
|
{
|
||||||
my $command = "uptime .";
|
my $command = "uptime .";
|
||||||
my $uptime = qx( $command );
|
my $uptime = qx( $command );
|
||||||
my $load = -1;
|
my $load = -1;
|
||||||
if ( $uptime =~ /load average:\s+([\d.]+)/ms )
|
if ( $uptime =~ /load average:\s+([\d.]+)/ms )
|
||||||
{
|
{
|
||||||
$load = $1;
|
$load = $1;
|
||||||
Info( "Load: $load" );
|
Info( "Load: $load" );
|
||||||
}
|
}
|
||||||
return( $load );
|
return( $load );
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -445,8 +445,8 @@ sub getLoad
|
||||||
#
|
#
|
||||||
sub strtotime
|
sub strtotime
|
||||||
{
|
{
|
||||||
my $dt_str = shift;
|
my $dt_str = shift;
|
||||||
return( Date::Manip::UnixDate( $dt_str, '%s' ) );
|
return( Date::Manip::UnixDate( $dt_str, '%s' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -454,22 +454,22 @@ sub strtotime
|
||||||
#
|
#
|
||||||
sub str_repeat
|
sub str_repeat
|
||||||
{
|
{
|
||||||
my $string = shift;
|
my $string = shift;
|
||||||
my $count = shift;
|
my $count = shift;
|
||||||
return( ${string}x${count} );
|
return( ${string}x${count} );
|
||||||
}
|
}
|
||||||
|
|
||||||
# Formats a date into MySQL format
|
# Formats a date into MySQL format
|
||||||
sub DateTimeToSQL
|
sub DateTimeToSQL
|
||||||
{
|
{
|
||||||
my $dt_str = shift;
|
my $dt_str = shift;
|
||||||
my $dt_val = strtotime( $dt_str );
|
my $dt_val = strtotime( $dt_str );
|
||||||
if ( !$dt_val )
|
if ( !$dt_val )
|
||||||
{
|
{
|
||||||
Error( "Unable to parse date string '$dt_str'\n" );
|
Error( "Unable to parse date string '$dt_str'\n" );
|
||||||
return( undef );
|
return( undef );
|
||||||
}
|
}
|
||||||
return( strftime( "%Y-%m-%d %H:%M:%S", localtime( $dt_val ) ) );
|
return( strftime( "%Y-%m-%d %H:%M:%S", localtime( $dt_val ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -482,8 +482,8 @@ ZoneMinder::Database - Perl extension for blah blah blah
|
||||||
|
|
||||||
=head1 SYNOPSIS
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
use ZoneMinder::Filter;
|
use ZoneMinder::Filter;
|
||||||
blah blah blah
|
blah blah blah
|
||||||
|
|
||||||
=head1 DESCRIPTION
|
=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
|
@ -42,8 +42,8 @@ our @ISA = qw(Exporter ZoneMinder::Base);
|
||||||
# will save memory.
|
# will save memory.
|
||||||
our %EXPORT_TAGS = (
|
our %EXPORT_TAGS = (
|
||||||
'functions' => [ qw(
|
'functions' => [ qw(
|
||||||
) ]
|
) ]
|
||||||
);
|
);
|
||||||
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
|
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
|
||||||
|
|
||||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||||
|
@ -65,46 +65,46 @@ use ZoneMinder::Database qw(:all);
|
||||||
use POSIX;
|
use POSIX;
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ( $parent, $id, $data ) = @_;
|
my ( $parent, $id, $data ) = @_;
|
||||||
|
|
||||||
my $self = {};
|
my $self = {};
|
||||||
bless $self, $parent;
|
bless $self, $parent;
|
||||||
if ( ( $$self{Id} = $id ) or $data ) {
|
if ( ( $$self{Id} = $id ) or $data ) {
|
||||||
#$log->debug("loading $parent $id") if $debug or DEBUG_ALL;
|
#$log->debug("loading $parent $id") if $debug or DEBUG_ALL;
|
||||||
$self->load( $data );
|
$self->load( $data );
|
||||||
}
|
}
|
||||||
return $self;
|
return $self;
|
||||||
} # end sub new
|
} # end sub new
|
||||||
|
|
||||||
sub load {
|
sub load {
|
||||||
my ( $self, $data ) = @_;
|
my ( $self, $data ) = @_;
|
||||||
my $type = ref $self;
|
my $type = ref $self;
|
||||||
if ( ! $data ) {
|
if ( ! $data ) {
|
||||||
#$log->debug("Object::load Loading from db $type");
|
#$log->debug("Object::load Loading from db $type");
|
||||||
$data = $ZoneMinder::Database::dbh->selectrow_hashref( 'SELECT * FROM Servers WHERE Id=?', {}, $$self{Id} );
|
$data = $ZoneMinder::Database::dbh->selectrow_hashref( 'SELECT * FROM Servers WHERE Id=?', {}, $$self{Id} );
|
||||||
if ( ! $data ) {
|
if ( ! $data ) {
|
||||||
if ( $ZoneMinder::Database::dbh->errstr ) {
|
if ( $ZoneMinder::Database::dbh->errstr ) {
|
||||||
Error( "Failure to load Server record for $$self{id}: Reason: " . $ZoneMinder::Database::dbh->errstr );
|
Error( "Failure to load Server record for $$self{id}: Reason: " . $ZoneMinder::Database::dbh->errstr );
|
||||||
} # end if
|
} # end if
|
||||||
} # end if
|
} # end if
|
||||||
} # end if ! $data
|
} # end if ! $data
|
||||||
if ( $data and %$data ) {
|
if ( $data and %$data ) {
|
||||||
@$self{keys %$data} = values %$data;
|
@$self{keys %$data} = values %$data;
|
||||||
} # end if
|
} # end if
|
||||||
} # end sub load
|
} # end sub load
|
||||||
|
|
||||||
sub Name {
|
sub Name {
|
||||||
if ( @_ > 1 ) {
|
if ( @_ > 1 ) {
|
||||||
$_[0]{Name} = $_[1];
|
$_[0]{Name} = $_[1];
|
||||||
}
|
}
|
||||||
return $_[0]{Name};
|
return $_[0]{Name};
|
||||||
} # end sub Name
|
} # end sub Name
|
||||||
|
|
||||||
sub Hostname {
|
sub Hostname {
|
||||||
if ( @_ > 1 ) {
|
if ( @_ > 1 ) {
|
||||||
$_[0]{Hostname} = $_[1];
|
$_[0]{Hostname} = $_[1];
|
||||||
}
|
}
|
||||||
return $_[0]{Hostname};
|
return $_[0]{Hostname};
|
||||||
} # end sub Hostname
|
} # end sub Hostname
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -117,8 +117,8 @@ ZoneMinder::Database - Perl extension for blah blah blah
|
||||||
|
|
||||||
=head1 SYNOPSIS
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
use ZoneMinder::Server;
|
use ZoneMinder::Server;
|
||||||
blah blah blah
|
blah blah blah
|
||||||
|
|
||||||
=head1 DESCRIPTION
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue