Merge branch 'master' of https://github.com/ZoneMinder/ZoneMinder into plugin_support_list

Conflicts:
	scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in
This commit is contained in:
Emmanuel Papin 2015-05-14 11:12:38 +02:00
commit 6b2c435460
46 changed files with 5720 additions and 3192 deletions

View File

@ -107,6 +107,8 @@ if [ $1 -eq 0 ] ; then
# Package removal, not upgrade
/bin/systemctl --no-reload disable zoneminder.service > /dev/null 2>&1 || :
/bin/systemctl stop zoneminder.service > /dev/null 2>&1 || :
echo -e "\nRemoving ZoneMinder SELinux policy module. Please wait.\n"
/usr/sbin/semodule -r local_zoneminder.pp
fi
%postun
@ -128,7 +130,8 @@ fi
%files
%defattr(-,root,root,-)
%doc AUTHORS COPYING README.md distros/redhat/README.Centos7 distros/redhat/jscalendar-doc
%doc AUTHORS BUGS ChangeLog COPYING LICENSE NEWS README.md distros/redhat/README.Centos7 distros/redhat/jscalendar-doc
%doc distros/redhat/cambozola-doc distros/redhat/local_zoneminder.te
%config %attr(640,root,%{zmgid_final}) /etc/zm/zm.conf
%config(noreplace) %attr(644,root,root) /etc/httpd/conf.d/zoneminder.conf
%config(noreplace) /etc/tmpfiles.d/zoneminder.conf
@ -156,7 +159,8 @@ fi
%{_bindir}/zmx10.pl
%{perl_vendorlib}/ZoneMinder*
%{perl_vendorlib}/%{_arch}-linux-thread-multi/auto/ZoneMinder*
%{perl_vendorarch}/auto/ZoneMinder/.packlist
#%{perl_vendorlib}/%{_arch}-linux-thread-multi/auto/ZoneMinder*
#%{perl_archlib}/ZoneMinder*
%{_mandir}/man*/*
%dir %{_libexecdir}/zoneminder

View File

@ -36,34 +36,42 @@ use ZoneMinder::General qw(:all);
use ZoneMinder::Database qw(:all);
use ZoneMinder::Memory qw(:all);
our @ISA = qw(Exporter ZoneMinder::Base ZoneMinder::Config ZoneMinder::Logger ZoneMinder::General ZoneMinder::Database ZoneMinder::Memory);
our @ISA = qw(
Exporter
ZoneMinder::Base
ZoneMinder::Config
ZoneMinder::Logger
ZoneMinder::General
ZoneMinder::Database
ZoneMinder::Memory
);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
# This allows declaration use ZoneMinder ':all';
# This allows declaration use ZoneMinder ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
our %EXPORT_TAGS = (
'base' => [
@ZoneMinder::Base::EXPORT_OK
],
'config' => [
@ZoneMinder::Config::EXPORT_OK
],
'debug' => [
@ZoneMinder::Logger::EXPORT_OK
],
'general' => [
@ZoneMinder::General::EXPORT_OK
],
'database' => [
@ZoneMinder::Database::EXPORT_OK
],
'memory' => [
@ZoneMinder::Memory::EXPORT_OK
],
'base' => [
@ZoneMinder::Base::EXPORT_OK
],
'config' => [
@ZoneMinder::Config::EXPORT_OK
],
'debug' => [
@ZoneMinder::Logger::EXPORT_OK
],
'general' => [
@ZoneMinder::General::EXPORT_OK
],
'database' => [
@ZoneMinder::Database::EXPORT_OK
],
'memory' => [
@ZoneMinder::Memory::EXPORT_OK
],
);
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;

View File

@ -19,7 +19,7 @@
#
# ==========================================================================
#
# This module contains the common definitions and functions used by the rest
# This module contains the common definitions and functions used by the rest
# of the ZoneMinder scripts
#
package ZoneMinder::Base;
@ -38,7 +38,7 @@ use constant ZM_VERSION => "@VERSION@";
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
# This allows declaration use ZoneMinder ':all';
# This allows declaration use ZoneMinder ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
our %EXPORT_TAGS = ( 'all' => [ qw(ZM_VERSION) ] );
@ -62,7 +62,11 @@ ZoneMinder::Base - Base perl module for ZoneMinder
=head1 DESCRIPTION
This module is the base module for the rest of the ZoneMinder modules. It is included by each of the other modules but serves no purpose other than to propagate the perl module version amongst the other modules. You will never need to use this module directly but if you write new ZoneMinder modules they should include it.
This module is the base module for the rest of the ZoneMinder modules. It
is included by each of the other modules but serves no purpose other than
to propagate the perl module version amongst the other modules. You will
never need to use this module directly but if you write new ZoneMinder
modules they should include it.
=head2 EXPORT

View File

@ -19,7 +19,7 @@
#
# ==========================================================================
#
# This module contains the common definitions and functions used by the rest
# This module contains the common definitions and functions used by the rest
# of the ZoneMinder scripts
#
package ZoneMinder::Config;
@ -38,15 +38,15 @@ use vars qw( %Config );
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
# This allows declaration use ZoneMinder ':all';
# This allows declaration use ZoneMinder ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
our @EXPORT_CONFIG = qw( %Config ); # Get populated by BEGIN
our %EXPORT_TAGS = (
'constants' => [ qw(
ZM_PID
) ]
'constants' => [ qw(
ZM_PID
) ]
);
push( @{$EXPORT_TAGS{config}}, @EXPORT_CONFIG );
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
@ -65,39 +65,43 @@ use Carp;
# Load the config from the database into the symbol table
BEGIN
{
my $config_file = ZM_CONFIG;
( my $local_config_file = $config_file ) =~ s|^.*/|./|;
if ( -s $local_config_file and -r $local_config_file )
{
print( STDERR "Warning, overriding installed $local_config_file file with local copy\n" );
$config_file = $local_config_file;
}
open( my $CONFIG, "<", $config_file )
my $config_file = ZM_CONFIG;
( my $local_config_file = $config_file ) =~ s|^.*/|./|;
if ( -s $local_config_file and -r $local_config_file )
{
print( STDERR "Warning, overriding installed $local_config_file file with local copy\n" );
$config_file = $local_config_file;
}
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*#/ );
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 );
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 $dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME}.";host=".$Config{ZM_DB_HOST}, $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();
use DBI;
my $dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME}
.";host=".$Config{ZM_DB_HOST}
, $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();
}
1;
@ -113,9 +117,16 @@ ZoneMinder::Config - ZoneMinder configuration module.
=head1 DESCRIPTION
The ZoneMinder::Config module is used to import the ZoneMinder configuration from the database. It will do this at compile time in a BEGIN block and require access to the zm.conf file either in the current directory or in its defined location in order to determine database access details, configuration from this file will also be included. If the :all or :config tags are used then this configuration is exported into the namespace of the calling program or module.
The ZoneMinder::Config module is used to import the ZoneMinder
configuration from the database. It will do this at compile time in a BEGIN
block and require access to the zm.conf file either in the current
directory or in its defined location in order to determine database access
details, configuration from this file will also be included. If the :all or
:config tags are used then this configuration is exported into the
namespace of the calling program or module.
Once the configuration has been imported then configuration variables are defined as constants and can be accessed directory by name, e.g.
Once the configuration has been imported then configuration variables are
defined as constants and can be accessed directory by name, e.g.
$lang = $Config{ZM_LANG_DEFAULT};

View File

@ -19,7 +19,7 @@
#
# ==========================================================================
#
# This module contains the debug definitions and functions used by the rest
# This module contains the debug definitions and functions used by the rest
# of the ZoneMinder scripts
#
package ZoneMinder::ConfigAdmin;
@ -37,14 +37,14 @@ our @ISA = qw(Exporter ZoneMinder::Base);
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
# This allows declaration use ZoneMinder ':all';
# This allows declaration use ZoneMinder ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
our %EXPORT_TAGS = (
'functions' => [ qw(
loadConfigFromDB
saveConfigToDB
) ]
'functions' => [ qw(
loadConfigFromDB
saveConfigToDB
) ]
);
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
@ -67,99 +67,138 @@ use Carp;
sub loadConfigFromDB
{
print( "Loading config from DB\n" );
my $dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME}.";host=".$Config{ZM_DB_HOST}, $Config{ZM_DB_USER}, $Config{ZM_DB_PASS} );
if ( !$dbh )
{
print( "Error: unable to load options from database: $DBI::errstr\n" );
return( 0 );
}
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() );
my $option_count = 0;
while( my $config = $sth->fetchrow_hashref() )
{
my ( $name, $value ) = ( $config->{Name}, $config->{Value} );
#print( "Name = '$name'\n" );
my $option = $options_hash{$name};
if ( !$option )
{
warn( "No option '$name' found, removing" );
next;
}
#next if ( $option->{category} eq 'hidden' );
if ( defined($value) )
{
if ( $option->{type} == $types{boolean} )
{
$option->{value} = $value?"yes":"no";
}
else
{
$option->{value} = $value;
}
}
$option_count++;;
}
$sth->finish();
$dbh->disconnect();
return( $option_count );
print( "Loading config from DB\n" );
my $dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME}
.";host=".$Config{ZM_DB_HOST}
,$Config{ZM_DB_USER}
,$Config{ZM_DB_PASS}
);
if ( !$dbh )
{
print( "Error: unable to load options from database: $DBI::errstr\n" );
return( 0 );
}
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() );
my $option_count = 0;
while( my $config = $sth->fetchrow_hashref() )
{
my ( $name, $value ) = ( $config->{Name}, $config->{Value} );
#print( "Name = '$name'\n" );
my $option = $options_hash{$name};
if ( !$option )
{
warn( "No option '$name' found, removing" );
next;
}
#next if ( $option->{category} eq 'hidden' );
if ( defined($value) )
{
if ( $option->{type} == $types{boolean} )
{
$option->{value} = $value?"yes":"no";
}
else
{
$option->{value} = $value;
}
}
$option_count++;;
}
$sth->finish();
$dbh->disconnect();
return( $option_count );
}
sub saveConfigToDB
{
print( "Saving config to DB\n" );
my $dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME}.";host=".$Config{ZM_DB_HOST}, $Config{ZM_DB_USER}, $Config{ZM_DB_PASS} );
print( "Saving config to DB\n" );
my $dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME}
.";host=".$Config{ZM_DB_HOST}
,$Config{ZM_DB_USER}
,$Config{ZM_DB_PASS}
);
if ( !$dbh )
{
print( "Error: unable to save options to database: $DBI::errstr\n" );
return( 0 );
}
if ( !$dbh )
{
print( "Error: unable to save options to database: $DBI::errstr\n" );
return( 0 );
}
my $ac = $dbh->{AutoCommit};
$dbh->{AutoCommit} = 0;
$dbh->do('LOCK TABLE Config WRITE') or croak( "Can't lock Config table: " . $dbh->errstr() );
$dbh->do('LOCK TABLE Config WRITE')
or croak( "Can't lock Config table: " . $dbh->errstr() );
my $sql = "delete from Config";
my $res = $dbh->do( $sql ) or croak( "Can't do '$sql': ".$dbh->errstr() );
my $sql = "delete from Config";
my $res = $dbh->do( $sql )
or croak( "Can't do '$sql': ".$dbh->errstr() );
$sql = "replace into Config set Id = ?, Name = ?, Value = ?, Type = ?, DefaultValue = ?, Hint = ?, Pattern = ?, Format = ?, Prompt = ?, Help = ?, Category = ?, Readonly = ?, Requires = ?";
my $sth = $dbh->prepare_cached( $sql ) or croak( "Can't prepare '$sql': ".$dbh->errstr() );
foreach my $option ( @options )
{
#next if ( $option->{category} eq 'hidden' );
#print( $option->{name}."\n" ) if ( !$option->{category} );
$option->{db_type} = $option->{type}->{db_type};
$option->{db_hint} = $option->{type}->{hint};
$option->{db_pattern} = $option->{type}->{pattern};
$option->{db_format} = $option->{type}->{format};
if ( $option->{db_type} eq "boolean" )
{
$option->{db_value} = ($option->{value} eq "yes")?"1":"0";
}
else
{
$option->{db_value} = $option->{value};
}
if ( my $requires = $option->{requires} )
{
$option->{db_requires} = join( ";", map { my $value = $_->{value}; $value = ($value eq "yes")?1:0 if ( $options_hash{$_->{name}}->{db_type} eq "boolean" ); ( "$_->{name}=$value" ) } @$requires );
}
else
{
}
my $res = $sth->execute( $option->{id}, $option->{name}, $option->{db_value}, $option->{db_type}, $option->{default}, $option->{db_hint}, $option->{db_pattern}, $option->{db_format}, $option->{description}, $option->{help}, $option->{category}, $option->{readonly}?1:0, $option->{db_requires} ) or croak( "Can't execute: ".$sth->errstr() );
}
$sth->finish();
$sql = "replace into Config set Id = ?, Name = ?, Value = ?, Type = ?, DefaultValue = ?, Hint = ?, Pattern = ?, Format = ?, Prompt = ?, Help = ?, Category = ?, Readonly = ?, Requires = ?";
my $sth = $dbh->prepare_cached( $sql )
or croak( "Can't prepare '$sql': ".$dbh->errstr() );
foreach my $option ( @options )
{
#next if ( $option->{category} eq 'hidden' );
#print( $option->{name}."\n" ) if ( !$option->{category} );
$option->{db_type} = $option->{type}->{db_type};
$option->{db_hint} = $option->{type}->{hint};
$option->{db_pattern} = $option->{type}->{pattern};
$option->{db_format} = $option->{type}->{format};
if ( $option->{db_type} eq "boolean" )
{
$option->{db_value} = ($option->{value} eq "yes")
? "1"
: "0"
;
}
else
{
$option->{db_value} = $option->{value};
}
if ( my $requires = $option->{requires} )
{
$option->{db_requires} = join( ";",
map {
my $value = $_->{value};
$value = ($value eq "yes")
? 1
: 0
if ( $options_hash{$_->{name}}->{db_type} eq "boolean" )
; ( "$_->{name}=$value" )
} @$requires
);
}
else
{
}
my $res = $sth->execute(
$option->{id},
$option->{name},
$option->{db_value},
$option->{db_type},
$option->{default},
$option->{db_hint},
$option->{db_pattern},
$option->{db_format},
$option->{description},
$option->{help},
$option->{category},
$option->{readonly} ? 1 : 0,
$option->{db_requires}
) or croak( "Can't execute: ".$sth->errstr() );
}
$sth->finish();
$dbh->do('UNLOCK TABLES');
$dbh->{AutoCommit} = $ac;
$dbh->disconnect();
$dbh->disconnect();
}
1;
@ -179,9 +218,15 @@ ZoneMinder::ConfigAdmin - ZoneMinder Configuration Administration module
=head1 DESCRIPTION
The ZoneMinder:ConfigAdmin module contains the master definition of the ZoneMinder configuration options as well as helper methods. This module is intended for specialist confguration management and would not normally be used by end users.
The ZoneMinder:ConfigAdmin module contains the master definition of the
ZoneMinder configuration options as well as helper methods. This module is
intended for specialist confguration management and would not normally be
used by end users.
The configuration held in this module, which was previously in zmconfig.pl, includes the name, default value, description, help text, type and category for each option, as well as a number of additional fields in a small number of cases.
The configuration held in this module, which was previously in zmconfig.pl,
includes the name, default value, description, help text, type and category
for each option, as well as a number of additional fields in a small number
of cases.
=head1 METHODS
@ -189,11 +234,17 @@ The configuration held in this module, which was previously in zmconfig.pl, incl
=item loadConfigFromDB ();
Loads existing configuration from the database (if any) and merges it with the definitions held in this module. This results in the merging of any new configuration and the removal of any deprecated configuration while preserving the existing values of every else.
Loads existing configuration from the database (if any) and merges it with
the definitions held in this module. This results in the merging of any new
configuration and the removal of any deprecated configuration while
preserving the existing values of every else.
=item saveConfigToDB ();
Saves configuration held in memory to the database. The act of loading and saving configuration is a convenient way to ensure that the configuration held in the database corresponds with the most recent definitions and that all components are using the same set of configuration.
Saves configuration held in memory to the database. The act of loading and
saving configuration is a convenient way to ensure that the configuration
held in the database corresponds with the most recent definitions and that
all components are using the same set of configuration.
=back

File diff suppressed because it is too large Load Diff

View File

@ -19,7 +19,7 @@
#
# ==========================================================================
#
# This module contains the base class definitions for the camera control
# This module contains the base class definitions for the camera control
# protocol implementations
#
package ZoneMinder::Control;
@ -45,17 +45,17 @@ our $AUTOLOAD;
sub new
{
my $class = shift;
my $id = shift;
my $self = {};
$self->{name} = "PelcoD";
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;
$self->{id} = $id;
bless( $self, $class );
return $self;
}
sub DESTROY
@ -64,32 +64,32 @@ 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;
my $self = shift;
return( $self->{id} );
}
sub open
{
my $self = shift;
my $self = shift;
Fatal( "No open method defined for protocol ".$self->{name} );
}
sub close
{
my $self = shift;
my $self = shift;
Fatal( "No close method defined for protocol ".$self->{name} );
}
@ -147,7 +147,7 @@ sub executeCommand
sub printMsg
{
my $self = shift;
my $self = shift;
Fatal( "No printMsg method defined for protocol ".$self->{name} );
}

View File

@ -21,10 +21,10 @@
#
# This module contains the implementation of the 3S camera control
# protocol
#Model: N5071
#Hardware Version: 00
#Firmware Version: V1.03_STD-1
#Firmware Build Time: Jun 19 2012 15:28:17
#Model: N5071
#Hardware Version: 00
#Firmware Version: V1.03_STD-1
#Firmware Build Time: Jun 19 2012 15:28:17
package ZoneMinder::Control::3S;

View File

@ -53,7 +53,7 @@ our @ISA = qw(ZoneMinder::Control);
# of the position of your mouse on the arrow.
# Extremity of arrow equal to fastest speed of movement
# Close the base of arrow to lowest speed of movement
# for diagonaly you can click before the begining of the arrow for low speed
# for diagonaly you can click before the beginning of the arrow for low speed
# In round center equal to stop to move and switch of latest OSD
# -You can clic directly on the image that equal to click on arrow (for the left there is a bug in zoneminder speed is inverted)
# -Zoom Tele switch ON InfraRed LED and stay to manual IR MODE
@ -63,7 +63,7 @@ our @ISA = qw(ZoneMinder::Control);
# -8 Preset PTZ are implemented and functionnal
# -This Script use for login "admin" this hardcoded and your password must setup in "Control Device" section
# -This script is compatible with the basic authentification method used by mostly new camera based with hi3510 chipset
# -AutoStop function is active and you must set up value (in sec exemple 0.7) under AutoStop section
# -AutoStop function is active and you must set up value (in sec example 0.7) under AutoStop section
# or you can set up to 0 for disable it (in this case you need to click to the circle center for stop)
# -"White In" to control Brightness, "auto" for restore the original value of Brightness
# -"White Out" to control Contrast, "man" for restore the original value of Contrast
@ -129,7 +129,7 @@ sub printMsg
}
sub sendCmd
{
{
my $self = shift;
my $cmd = shift;
my $result = undef;
@ -211,7 +211,7 @@ sub moveConUp
if ( $tiltspeed < 10 ) {
$tiltspeed = 1;
}
Debug( "Move Up" );
Debug( "Move Up" );
if ( $osd eq "on" )
{
my $cmd = "param.cgi?cmd=setoverlayattr&-region=1&-show=1&-name=Move Up $tiltspeed";

View File

@ -57,7 +57,7 @@ our @ISA = qw(ZoneMinder::Control);
# of the position of your mouse on the arrow.
# Extremity of arrow equal to fastest speed of movement
# Close the base of arrow to lowest speed of movement
# for diagonaly you can click before the begining of the arrow for low speed
# for diagonaly you can click before the beginning of the arrow for low speed
# In round center equal to stop to move
# -You can clic directly on the image that equal to click on arrow (for the left there is a bug in zoneminder speed is inverted)
# -Zoom Tele/Wide with time control to simulate speed because speed value do not work (buggy firmware or not implemented on this cam)
@ -67,7 +67,7 @@ our @ISA = qw(ZoneMinder::Control);
# You Need to configure ZoneMinder PANSPEED & TILTSEPPED & ZOOMSPEED 1 to 63 by 1 step
# -This Script use for login "admin" this hardcoded and your password must setup in "Control Device" section
# -This script is compatible with the basic authentification method used by mostly new camera
# -AutoStop function is active and you must set up value (in sec exemple 0.5) under AutoStop section
# -AutoStop function is active and you must set up value (in sec example 0.5) under AutoStop section
# or you can set up to 0 for disable it but the camera never stop to move and trust me, she can move all the night...
# (you need to click to the center arrow for stop)
# -"White In" to control Brightness, "auto" for restore the original value of Brightness

View File

@ -43,176 +43,176 @@ use ZoneMinder::Config qw(:all);
use Time::HiRes qw( usleep );
sub new
{
my $class = shift;
my $id = shift;
my $self = ZoneMinder::Control->new( $id );
bless( $self, $class );
srand( time() );
return $self;
{
my $class = shift;
my $id = shift;
my $self = ZoneMinder::Control->new( $id );
bless( $self, $class );
srand( time() );
return $self;
}
our $AUTOLOAD;
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} );
}
Fatal( "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} );
}
Fatal( "Can't access $name member of object of class $class" );
}
sub open
{
my $self = shift;
my $self = shift;
$self->loadMonitor();
$self->loadMonitor();
use LWP::UserAgent;
$self->{ua} = LWP::UserAgent->new;
$self->{ua}->agent( "ZoneMinder Control Agent/".ZoneMinder::Base::ZM_VERSION );
use LWP::UserAgent;
$self->{ua} = LWP::UserAgent->new;
$self->{ua}->agent( "ZoneMinder Control Agent/".ZoneMinder::Base::ZM_VERSION );
$self->{state} = 'open';
$self->{state} = 'open';
}
sub close
{
my $self = shift;
$self->{state} = 'closed';
my $self = shift;
$self->{state} = 'closed';
}
sub printMsg
{
my $self = shift;
my $msg = shift;
my $msg_len = length($msg);
my $self = shift;
my $msg = shift;
my $msg_len = length($msg);
Debug( $msg."[".$msg_len."]" );
Debug( $msg."[".$msg_len."]" );
}
sub sendCmd
{
my $self = shift;
my $cmd = shift;
my $result = undef;
my $self = shift;
my $cmd = shift;
my $result = undef;
my ($user, $password) = split /:/, $self->{Monitor}->{ControlDevice};
my ($user, $password) = split /:/, $self->{Monitor}->{ControlDevice};
if ( !defined $password ) {
# If value of "Control device" does not consist of two parts, then only password is given and we fallback to default user:
$password = $user;
$user = 'admin';
}
if ( !defined $password ) {
# If value of "Control device" does not consist of two parts, then only password is given and we fallback to default user:
$password = $user;
$user = 'admin';
}
$cmd .= "user=$user&pwd=$password";
$cmd .= "user=$user&pwd=$password";
printMsg( $cmd, "Tx" );
printMsg( $cmd, "Tx" );
my $req = HTTP::Request->new( GET=>"http://".$self->{Monitor}->{ControlAddress}."/$cmd" );
my $res = $self->{ua}->request($req);
my $req = HTTP::Request->new( GET=>"http://".$self->{Monitor}->{ControlAddress}."/$cmd" );
my $res = $self->{ua}->request($req);
if ( $res->is_success )
{
$result = !undef;
}
else
{
Error( "Error check failed: '".$res->status_line()."' for URL ".$req->uri() );
}
if ( $res->is_success )
{
$result = !undef;
}
else
{
Error( "Error check failed: '".$res->status_line()."' for URL ".$req->uri() );
}
return( $result );
return( $result );
}
sub reset
{
my $self = shift;
Debug( "Camera Reset" );
$self->sendCmd( 'reboot.cgi?' );
my $self = shift;
Debug( "Camera Reset" );
$self->sendCmd( 'reboot.cgi?' );
}
#Up Arrow
sub moveConUp
{
my $self = shift;
Debug( "Move Up" );
$self->sendCmd( 'decoder_control.cgi?command=0&' );
my $self = shift;
Debug( "Move Up" );
$self->sendCmd( 'decoder_control.cgi?command=0&' );
}
#Down Arrow
sub moveConDown
{
my $self = shift;
Debug( "Move Down" );
$self->sendCmd( 'decoder_control.cgi?command=2&' );
my $self = shift;
Debug( "Move Down" );
$self->sendCmd( 'decoder_control.cgi?command=2&' );
}
#Left Arrow
sub moveConLeft
{
my $self = shift;
Debug( "Move Left" );
$self->sendCmd( 'decoder_control.cgi?command=6&' );
my $self = shift;
Debug( "Move Left" );
$self->sendCmd( 'decoder_control.cgi?command=6&' );
}
#Right Arrow
sub moveConRight
{
my $self = shift;
Debug( "Move Right" );
$self->sendCmd( 'decoder_control.cgi?command=4&' );
my $self = shift;
Debug( "Move Right" );
$self->sendCmd( 'decoder_control.cgi?command=4&' );
}
#Diagonally Up Right Arrow
sub moveConUpRight
{
my $self = shift;
Debug( "Move Diagonally Up Right" );
$self->sendCmd( 'decoder_control.cgi?command=90&' );
my $self = shift;
Debug( "Move Diagonally Up Right" );
$self->sendCmd( 'decoder_control.cgi?command=90&' );
}
#Diagonally Down Right Arrow
sub moveConDownRight
{
my $self = shift;
Debug( "Move Diagonally Down Right" );
$self->sendCmd( 'decoder_control.cgi?command=92&' );
my $self = shift;
Debug( "Move Diagonally Down Right" );
$self->sendCmd( 'decoder_control.cgi?command=92&' );
}
#Diagonally Up Left Arrow
sub moveConUpLeft
{
my $self = shift;
Debug( "Move Diagonally Up Left" );
$self->sendCmd( 'decoder_control.cgi?command=91&' );
my $self = shift;
Debug( "Move Diagonally Up Left" );
$self->sendCmd( 'decoder_control.cgi?command=91&' );
}
#Diagonally Down Left Arrow
sub moveConDownLeft
{
my $self = shift;
Debug( "Move Diagonally Down Left" );
$self->sendCmd( 'decoder_control.cgi?command=93&' );
my $self = shift;
Debug( "Move Diagonally Down Left" );
$self->sendCmd( 'decoder_control.cgi?command=93&' );
}
#Stop
sub moveStop
{
my $self = shift;
Debug( "Move Stop" );
$self->sendCmd( 'decoder_control.cgi?command=1&' );
my $self = shift;
Debug( "Move Stop" );
$self->sendCmd( 'decoder_control.cgi?command=1&' );
}
#Move Camera to Home Position
sub presetHome
{
my $self = shift;
Debug( "Home Preset" );
$self->sendCmd( 'decoder_control.cgi?command=25&' );
my $self = shift;
Debug( "Home Preset" );
$self->sendCmd( 'decoder_control.cgi?command=25&' );
}
1;
@ -226,10 +226,11 @@ ZoneMinder::Control::FI8908W - Foscam FI8908W camera control
=head1 DESCRIPTION
This module contains the implementation of the Foscam FI8908W / FI8918W IP camera control
protocol.
This module contains the implementation of the Foscam FI8908W / FI8918W IP
camera control protocol.
The module uses "Control Device" value to retrieve user and password. User
and password should be separated by colon, e.g. user:password. If colon is
not provided, then "admin" is used as a fallback value for the user.
The module uses "Control Device" value to retrieve user and password. User and password should
be separated by colon, e.g. user:password. If colon is not provided, then "admin" is used
as a fallback value for the user.
=cut

View File

@ -102,7 +102,6 @@ sub close
sub printMsg
{
my $self = shift;
my $msg = shift;
my $msg_len = length($msg);
Debug( $msg."[".$msg_len."]" );
@ -113,9 +112,28 @@ sub sendCmd
my $self = shift;
my $cmd = shift;
my $result = undef;
my ($user, $password) = split /:/, $self->{Monitor}->{ControlDevice};
if ( ! $password ) {
$password = $user;
$user = 'admin';
}
$user = 'admin' if ! $user;
$password = 'pwd' if ! $password;
$cmd .= "&usr=$user&pwd=$password";
printMsg( $cmd, "Tx" );
my $temps = time();
my $req = HTTP::Request->new( GET=>"http://".$self->{Monitor}->{ControlAddress}."/cgi-bin/CGIProxy.fcgi?usr%3Dadmin%26pwd%3D".$self->{Monitor}->{ControlDevice}."%26cmd%3D".$cmd."%26".$temps );
my $url;
if ( $self->{Monitor}->{ControlAddress} =~ /^http/ ) {
$url = $self->{Monitor}->{ControlAddress};
} else {
$url = "http://".$self->{Monitor}->{ControlAddress};
}
$url .= "/cgi-bin/CGIProxy.fcgi?cmd=$cmd%26".time;
printMsg( $url, "Tx" );
my $req = HTTP::Request->new( GET=>$url );
my $res = $self->{ua}->request($req);
if ( $res->is_success )
{
@ -134,7 +152,7 @@ sub reset
# Setup OSD
my $cmd = "setOSDSetting%26isEnableTimeStamp%3D0%26isEnableDevName%3D1%26dispPos%3D0%26isEnabledOSDMask%3D0";
$self->sendCmd( $cmd );
# Setup For Stream=0 Resolution=720p Bandwith=4M FPS=30 KeyFrameInterval/GOP=100 VBR=ON
# Setup For Stream=0 Resolution=720p Bandwidth=4M FPS=30 KeyFrameInterval/GOP=100 VBR=ON
$cmd = "setVideoStreamParam%26streamType%3D0%26resolution%3D0%26bitRate%3D4194304%26frameRate%3D30%26GOP%3D100%26isVBR%3D1";
$self->sendCmd( $cmd );
# Setup For Infrared AUTO

View File

@ -107,14 +107,18 @@ sub sendCmd {
printMsg( $cmd, "Tx" );
#print( "http://$address/$cmd\n" );
#my $req = HTTP::Request->new( GET=>"http://".$self->{Monitor}->{ControlAddress}."/$cmd" );
my $url;
if ( $self->{Monitor}->{ControlAddress} =~ /^http/ ) {
$url = $self->{Monitor}->{ControlAddress}.'/cgi-bin/setGPIO.cgi?preventCache='.time;
} else {
$url = 'http://'.$self->{Monitor}->{ControlAddress}.'/cgi-bin/setGPIO.cgi?preventCache='.time;
} # en dif
Error("Url: $url $cmd");
my $url;
if ( $self->{Monitor}->{ControlAddress} =~ /^http/ ) {
$url = $self->{Monitor}->{ControlAddress}
.'/cgi-bin/setGPIO.cgi?preventCache='.time
;
} else {
$url = 'http://'.$self->{Monitor}->{ControlAddress}
.'/cgi-bin/setGPIO.cgi?preventCache='.time
;
} # en dif
Error("Url: $url $cmd");
my $uri = URI::Encode->new( { encode_reserved => 0 } );
my $encoded = $uri->encode( $cmd );
my $res = $self->{ua}->post( $url, Content=>"data=$encoded" );
@ -203,7 +207,11 @@ sub moveMap
my $xcoord = $self->getParam( $params, 'xcoord' );
my $ycoord = $self->getParam( $params, 'ycoord' );
Debug( "Move Map to $xcoord,$ycoord" );
my $cmd = "/axis-cgi/com/ptz.cgi?center=$xcoord,$ycoord&imagewidth=".$self->{Monitor}->{Width}."&imageheight=".$self->{Monitor}->{Height};
my $cmd = "/axis-cgi/com/ptz.cgi?center=$xcoord,$ycoord&imagewidth="
.$self->{Monitor}->{Width}
."&imageheight="
.$self->{Monitor}->{Height}
;
$self->sendCmd( $cmd );
}

View File

@ -60,16 +60,16 @@ our @ISA = qw(ZoneMinder::Control);
#
# ******** YOU MUST CHANGE THE FOLLOWING LINES TO MATCH YOUR CAMERA! **********
#
#
# I assume that "TV-IP672WI" would work for the TV-IP672WI, but can't test since I don't own one.
#
#
# TV-IP672PI works for the PI version, of course.
#
# Finally, the username is the username you'd like to authenticate as.
#
our $REALM = 'TV-IP862IC';
our $USERNAME = 'admin';
our $PASSWORD = '';
our $PASSWORD = '';
our $ADDRESS = '';
# ==========================================================================
@ -111,26 +111,32 @@ sub open
my $self = shift;
$self->loadMonitor();
my ( $protocol, $username, $password, $address ) = $self->{Monitor}->{ControlAddress} =~ /^(https?:\/\/)?([^:]+):([^\/@]+)@(.*)$/;
if ( $username ) {
$USERNAME = $username;
$PASSWORD = $password;
$ADDRESS = $address;
} else {
Error( "Failed to parse auth from address");
$ADDRESS = $self->{Monitor}->{ControlAddress};
}
if ( ! $ADDRESS =~ /:/ ) {
Error( "You generally need to also specify the port. I will append :80" );
$ADDRESS .= ':80';
}
my ( $protocol, $username, $password, $address )
= $self->{Monitor}->{ControlAddress} =~ /^(https?:\/\/)?([^:]+):([^\/@]+)@(.*)$/;
if ( $username ) {
$USERNAME = $username;
$PASSWORD = $password;
$ADDRESS = $address;
} else {
Error( "Failed to parse auth from address");
$ADDRESS = $self->{Monitor}->{ControlAddress};
}
if ( ! $ADDRESS =~ /:/ ) {
Error( "You generally need to also specify the port. I will append :80" );
$ADDRESS .= ':80';
}
use LWP::UserAgent;
$self->{ua} = LWP::UserAgent->new;
$self->{ua}->agent( "ZoneMinder Control Agent/".$ZoneMinder::Base::ZM_VERSION );
$self->{state} = 'open';
# credentials: ("ip:port" (no prefix!), realm (string), username (string), password (string)
Debug ( "sendCmd credentials control address:'".$ADDRESS."' realm:'" . $REALM . "' username:'" . $USERNAME . "' password:'".$PASSWORD."'");
# credentials: ("ip:port" (no prefix!), realm (string), username (string), password (string)
Debug ( "sendCmd credentials control address:'".$ADDRESS
."' realm:'" . $REALM
. "' username:'" . $USERNAME
. "' password:'".$PASSWORD
."'"
);
$self->{ua}->credentials($ADDRESS,$REALM,$USERNAME,$PASSWORD);
}
@ -159,29 +165,29 @@ sub sendCmd
my $result = undef;
my $url = "http://".$ADDRESS."/cgi/ptdc.cgi?command=".$cmd;
my $url = "http://".$ADDRESS."/cgi/ptdc.cgi?command=".$cmd;
my $req = HTTP::Request->new( GET=>$url );
Debug ("sendCmd command: " . $url );
my $res = $self->{ua}->request($req);
if ( $res->is_success ) {
$result = !undef;
} else {
if ( $res->status_line() eq '401 Unauthorized' ) {
Error( "Error check failed, trying again: USERNAME: $USERNAME realm: $REALM password: " . $PASSWORD );
Error("Content was " . $res->content() );
my $res = $self->{ua}->request($req);
if ( $res->is_success ) {
$result = !undef;
} else {
Error("Content was " . $res->content() );
}
}
if ( ! $result ) {
Error( "Error check failed: '".$res->status_line()."' cmd:'".$cmd."'" );
}
if ( $res->status_line() eq '401 Unauthorized' ) {
Error( "Error check failed, trying again: USERNAME: $USERNAME realm: $REALM password: " . $PASSWORD );
Error("Content was " . $res->content() );
my $res = $self->{ua}->request($req);
if ( $res->is_success ) {
$result = !undef;
} else {
Error("Content was " . $res->content() );
}
}
if ( ! $result ) {
Error( "Error check failed: '".$res->status_line()."' cmd:'".$cmd."'" );
}
}
return( $result );
@ -203,10 +209,10 @@ sub sendCmdPost
my $result = undef;
if ($url eq undef)
{
Error ("url passed to sendCmdPost is undefined.");
return(-1);
}
{
Error ("url passed to sendCmdPost is undefined.");
return(-1);
}
Debug ("sendCmdPost url: " . $url . " cmd: " . $cmd);
@ -215,7 +221,7 @@ sub sendCmdPost
$req->content($cmd);
Debug ( "sendCmdPost credentials control address:'".$ADDRESS."' realm:'" . $REALM . "' username:'" . $USERNAME . "' password:'".$PASSWORD."'");
my $res = $self->{ua}->request($req);
if ( $res->is_success )
@ -225,11 +231,11 @@ sub sendCmdPost
else
{
Error( "sendCmdPost Error check failed: '".$res->status_line()."' cmd:'".$cmd."'" );
if ( $res->status_line() eq '401 Unauthorized' ) {
Error( "sendCmdPost Error check failed: USERNAME: $USERNAME realm: $REALM password: " . $PASSWORD );
} else {
Error( "sendCmdPost Error check failed: USERNAME: $USERNAME realm: $REALM password: " . $PASSWORD );
} # endif
if ( $res->status_line() eq '401 Unauthorized' ) {
Error( "sendCmdPost Error check failed: USERNAME: $USERNAME realm: $REALM password: " . $PASSWORD );
} else {
Error( "sendCmdPost Error check failed: USERNAME: $USERNAME realm: $REALM password: " . $PASSWORD );
} # endif
}
return( $result );

View File

@ -16,8 +16,8 @@
# Rename to Wanscam
# Pan Left/Right switched
# IR On/Off switched
# Brightness Increase/Decrease in 16 steps
#
# Brightness Increase/Decrease in 16 steps
#
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View File

@ -126,32 +126,32 @@ sub sendCmd
sub Up
{
my $self = shift;
$self->moveConUp();
$self->moveConUp();
}
sub Down
{
my $self = shift;
$self->moveConDown();
$self->moveConDown();
}
sub Left
{
my $self = shift;
$self->moveConLeft();
$self->moveConLeft();
}
sub Right
{
my $self = shift;
$self->moveConRight();
$self->moveConRight();
}
sub reset
{
my $self = shift;
$self->cameraReset();
$self->cameraReset();
}

View File

@ -36,7 +36,7 @@ our %CamParams = ();
# ==========================================================================
#
# ONVIF Control Protocol
#
#
# On ControlAddress use the format :
# USERNAME:PASSWORD@ADDRESS:PORT
# eg : admin:@10.1.2.1:80
@ -50,7 +50,7 @@ use ZoneMinder::Config qw(:all);
use Time::HiRes qw( usleep );
sub new
{
{
my $class = shift;
my $id = shift;
@ -90,7 +90,7 @@ sub open
}
sub close
{
{
my $self = shift;
$self->{state} = 'closed';
}
@ -133,7 +133,7 @@ sub getCamParams
my $req = HTTP::Request->new( GET=>"http://".$self->{Monitor}->{ControlAddress}."/get_camera_params.cgi" );
my $res = $self->{ua}->request($req);
if ( $res->is_success )
if ( $res->is_success )
{
# Parse results setting values in %FCParams
my $content = $res->decoded_content;
@ -141,7 +141,7 @@ sub getCamParams
while ($content =~ s/var\s+([^=]+)=([^;]+);//ms) {
$CamParams{$1} = $2;
}
}
}
else
{
Error( "Error check failed:'".$res->status_line()."'" );

View File

@ -19,7 +19,7 @@
#
# ==========================================================================
#
# This module contains the common definitions and functions used by the rest
# This module contains the common definitions and functions used by the rest
# of the ZoneMinder scripts
#
package ZoneMinder::Database;
@ -37,17 +37,17 @@ our @ISA = qw(Exporter ZoneMinder::Base);
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
# This allows declaration use ZoneMinder ':all';
# This allows declaration use ZoneMinder ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# 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;
@ -72,35 +72,44 @@ our $dbh = undef;
sub zmDbConnect
{
my $force = shift;
if ( $force )
{
zmDbDisconnect();
}
if ( !defined( $dbh ) )
{
my $force = shift;
if ( $force )
{
zmDbDisconnect();
}
if ( !defined( $dbh ) )
{
my ( $host, $port ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ );
if ( defined($port) )
{
$dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME}.";host=".$host.";port=".$port, $Config{ZM_DB_USER}, $Config{ZM_DB_PASS} );
$dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME}
.";host=".$host
.";port=".$port
, $Config{ZM_DB_USER}
, $Config{ZM_DB_PASS}
);
}
else
{
$dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME}.";host=".$Config{ZM_DB_HOST}, $Config{ZM_DB_USER}, $Config{ZM_DB_PASS} );
$dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME}
.";host=".$Config{ZM_DB_HOST}
, $Config{ZM_DB_USER}
, $Config{ZM_DB_PASS}
);
}
$dbh->trace( 0 );
}
return( $dbh );
}
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
@ -112,76 +121,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 == 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'";
}
}
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() );
if ( $function )
{
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'";
}
}
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;
my @monitors;
while( my $monitor = $sth->fetchrow_hashref() )
{
push( @monitors, $monitor );
}
$sth->finish();
return( \@monitors );
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 $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 $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 $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();
return( $monitor );
return( $monitor );
}
1;

View File

@ -19,7 +19,7 @@
#
# ==========================================================================
#
# This module contains the common definitions and functions used by the rest
# This module contains the common definitions and functions used by the rest
# of the ZoneMinder scripts
#
package ZoneMinder::General;
@ -203,13 +203,26 @@ sub getEventPath
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}) );
$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};
$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
;
}
$event_path = $Config{ZM_PATH_WEB}.'/'.$event_path if ( index($Config{ZM_DIR_EVENTS},'/') != 0 );
return( $event_path );
}
@ -219,7 +232,9 @@ sub createEventPath
# WARNING assumes running from events directory
#
my $event = shift;
my $eventRootPath = ($Config{ZM_DIR_EVENTS}=~m|/|)?$Config{ZM_DIR_EVENTS}:($Config{ZM_PATH_WEB}.'/'.$Config{ZM_DIR_EVENTS});
my $eventRootPath = ($Config{ZM_DIR_EVENTS}=~m|/|)
? $Config{ZM_DIR_EVENTS}
: ($Config{ZM_PATH_WEB}.'/'.$Config{ZM_DIR_EVENTS});
my $eventPath = $eventRootPath.'/'.$event->{MonitorId};
if ( $Config{ZM_USE_DEEP_STORAGE} )
@ -242,7 +257,8 @@ sub createEventPath
# Create event id symlink
my $idFile = sprintf( "%s/.%d", $eventPath, $event->{Id} );
symlink( $timePath, $idFile ) or Fatal( "Can't symlink $idFile -> $eventPath: $!" );
symlink( $timePath, $idFile )
or Fatal( "Can't symlink $idFile -> $eventPath: $!" );
makePath( $timePath, $eventPath );
$eventPath .= '/'.$timePath;
@ -281,8 +297,13 @@ sub _checkProcessOwner
my ( $processOwner ) = getpwuid( $> );
if ( $processOwner ne $Config{ZM_WEB_USER} )
{
# Not running as web user, so should be root in whch case chown the temporary directory
( my $ownerName, my $ownerPass, $_ownerUid, $_ownerGid ) = getpwnam( $Config{ZM_WEB_USER} ) or Fatal( "Can't get user details for web user '".$Config{ZM_WEB_USER}."': $!" );
# Not running as web user, so should be root in which case chown
# the temporary directory
( my $ownerName, my $ownerPass, $_ownerUid, $_ownerGid )
= getpwnam( $Config{ZM_WEB_USER} )
or Fatal( "Can't get user details for web user '"
.$Config{ZM_WEB_USER}."': $!"
);
$_setFileOwner = 1;
}
else
@ -299,7 +320,10 @@ sub setFileOwner
if ( _checkProcessOwner() )
{
chown( $_ownerUid, $_ownerGid, $file ) or Fatal( "Can't change ownership of file '$file' to '".$Config{ZM_WEB_USER}.":".$Config{ZM_WEB_GROUP}."': $!" );
chown( $_ownerUid, $_ownerGid, $file )
or Fatal( "Can't change ownership of file '$file' to '"
.$Config{ZM_WEB_USER}.":".$Config{ZM_WEB_GROUP}."': $!"
);
}
}
@ -337,9 +361,14 @@ sub createEvent
elsif ( $event->{MonitorId} )
{
my $sql = "select * from Monitors where Id = ?";
my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare sql '$sql': ".$dbh->errstr() );
my $res = $sth->execute( $event->{MonitorId} ) or Fatal( "Can't execute sql '$sql': ".$sth->errstr() );
$event->{monitor} = $sth->fetchrow_hashref() or Fatal( "Unable to create event, can't load monitor with id '".$event->{MonitorId}."'" );
my $sth = $dbh->prepare_cached( $sql )
or Fatal( "Can't prepare sql '$sql': ".$dbh->errstr() );
my $res = $sth->execute( $event->{MonitorId} )
or Fatal( "Can't execute sql '$sql': ".$sth->errstr() );
$event->{monitor} = $sth->fetchrow_hashref()
or Fatal( "Unable to create event, can't load monitor with id '"
.$event->{MonitorId}."'"
);
$sth->finish();
}
else
@ -360,7 +389,9 @@ sub createEvent
my $imageInfo = Image::Info::image_info( $frame->{imagePath} );
if ( $imageInfo->{error} )
{
Error( "Unable to extract image info from '".$frame->{imagePath}."': ".$imageInfo->{error} );
Error( "Unable to extract image info from '"
.$frame->{imagePath}."': ".$imageInfo->{error}
);
}
else
{
@ -396,18 +427,25 @@ sub createEvent
push( @values, $event->{$field} );
}
my $sql = "insert into Events (".join(',',@fields).") values (".join(',',@formats).")";
my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare sql '$sql': ".$dbh->errstr() );
my $res = $sth->execute( @values ) or Fatal( "Can't execute sql '$sql': ".$sth->errstr() );
my $sql = "INSERT INTO Events (".join(',',@fields)
.") VALUES (".join(',',@formats).")"
;
my $sth = $dbh->prepare_cached( $sql )
or Fatal( "Can't prepare sql '$sql': ".$dbh->errstr() );
my $res = $sth->execute( @values )
or Fatal( "Can't execute sql '$sql': ".$sth->errstr() );
$event->{Id} = $dbh->{mysql_insertid};
Info( "Created event ".$event->{Id} );
if ( $event->{EndTime} )
{
$event->{Name} = $event->{monitor}->{EventPrefix}.$event->{Id} if ( $event->{Name} eq 'New Event' );
$event->{Name} = $event->{monitor}->{EventPrefix}.$event->{Id}
if ( $event->{Name} eq 'New Event' );
my $sql = "update Events set Name = ? where Id = ?";
my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare sql '$sql': ".$dbh->errstr() );
my $res = $sth->execute( $event->{Name}, $event->{Id} ) or Fatal( "Can't execute sql '$sql': ".$sth->errstr() );
my $sth = $dbh->prepare_cached( $sql )
or Fatal( "Can't prepare sql '$sql': ".$dbh->errstr() );
my $res = $sth->execute( $event->{Name}, $event->{Id} )
or Fatal( "Can't execute sql '$sql': ".$sth->errstr() );
}
my $eventPath = createEventPath( $event );
@ -430,19 +468,39 @@ sub createEvent
push( @values, $frame->{$field} );
}
my $sql = "insert into Frames (".join(',',@fields).") values (".join(',',@formats).")";
my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare sql '$sql': ".$dbh->errstr() );
my $res = $sth->execute( @values ) or Fatal( "Can't execute sql '$sql': ".$sth->errstr() );
my $sql = "insert into Frames (".join(',',@fields)
.") values (".join(',',@formats).")"
;
my $sth = $dbh->prepare_cached( $sql )
or Fatal( "Can't prepare sql '$sql': ".$dbh->errstr() );
my $res = $sth->execute( @values )
or Fatal( "Can't execute sql '$sql': ".$sth->errstr() );
#$frame->{FrameId} = $dbh->{mysql_insertid};
if ( $frame->{imagePath} )
{
$frame->{capturePath} = sprintf( "%s/%0".$Config{ZM_EVENT_IMAGE_DIGITS}."d-capture.jpg", $eventPath, $frame->{FrameId} );
rename( $frame->{imagePath}, $frame->{capturePath} ) or Fatal( "Can't copy ".$frame->{imagePath}." to ".$frame->{capturePath}.": $!" );
$frame->{capturePath} = sprintf(
"%s/%0".$Config{ZM_EVENT_IMAGE_DIGITS}
."d-capture.jpg"
, $eventPath
, $frame->{FrameId}
);
rename( $frame->{imagePath}, $frame->{capturePath} )
or Fatal( "Can't copy ".$frame->{imagePath}
." to ".$frame->{capturePath}.": $!"
);
setFileOwner( $frame->{capturePath} );
if ( 0 && $Config{ZM_CREATE_ANALYSIS_IMAGES} )
{
$frame->{analysePath} = sprintf( "%s/%0".$Config{ZM_EVENT_IMAGE_DIGITS}."d-analyse.jpg", $eventPath, $frame->{FrameId} );
link( $frame->{capturePath}, $frame->{analysePath} ) or Fatal( "Can't link ".$frame->{capturePath}." to ".$frame->{analysePath}.": $!" );
$frame->{analysePath} = sprintf(
"%s/%0".$Config{ZM_EVENT_IMAGE_DIGITS}
."d-analyse.jpg"
, $eventPath
, $frame->{FrameId}
);
link( $frame->{capturePath}, $frame->{analysePath} )
or Fatal( "Can't link ".$frame->{capturePath}
." to ".$frame->{analysePath}.": $!"
);
setFileOwner( $frame->{analysePath} );
}
}
@ -469,7 +527,8 @@ sub updateEvent
my $dbh = zmDbConnect();
$event->{Name} = $event->{monitor}->{EventPrefix}.$event->{Id} if ( $event->{Name} eq 'New Event' );
$event->{Name} = $event->{monitor}->{EventPrefix}.$event->{Id}
if ( $event->{Name} eq 'New Event' );
my %formats = (
StartTime => 'from_unixtime(?)',
@ -486,8 +545,10 @@ sub updateEvent
my $sql = "update Events set ".join(',',@sets)." where Id = ?";
push( @values, $event->{Id} );
my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare sql '$sql': ".$dbh->errstr() );
my $res = $sth->execute( @values ) or Fatal( "Can't execute sql '$sql': ".$sth->errstr() );
my $sth = $dbh->prepare_cached( $sql )
or Fatal( "Can't prepare sql '$sql': ".$dbh->errstr() );
my $res = $sth->execute( @values )
or Fatal( "Can't execute sql '$sql': ".$sth->errstr() );
}
sub deleteEventFiles

View File

@ -19,7 +19,7 @@
#
# ==========================================================================
#
# This module contains the debug definitions and functions used by the rest
# This module contains the debug definitions and functions used by the rest
# of the ZoneMinder scripts
#
package ZoneMinder::Logger;
@ -258,7 +258,12 @@ sub initialise( @ )
{
foreach my $target ( split( /\|/, $Config{ZM_LOG_DEBUG_TARGET} ) )
{
if ( $target eq $this->{id} || $target eq "_".$this->{id} || $target eq $this->{idRoot} || $target eq "_".$this->{idRoot} || $target eq "" )
if ( $target eq $this->{id}
|| $target eq "_".$this->{id}
|| $target eq $this->{idRoot}
|| $target eq "_".$this->{idRoot}
|| $target eq ""
)
{
if ( $Config{ZM_LOG_DEBUG_LEVEL} > NOLOG )
{
@ -287,8 +292,15 @@ sub initialise( @ )
$this->{autoFlush} = $ENV{'LOG_FLUSH'}?1:0 if ( defined($ENV{'LOG_FLUSH'}) );
$this->{initialised} = !undef;
Debug( "LogOpts: level=".$codes{$this->{level}}."/".$codes{$this->{effectiveLevel}}.", screen=".$codes{$this->{termLevel}}.", database=".$codes{$this->{databaseLevel}}.", logfile=".$codes{$this->{fileLevel}}."->".$this->{logFile}.", syslog=".$codes{$this->{syslogLevel}} );
Debug( "LogOpts: level=".$codes{$this->{level}}
."/".$codes{$this->{effectiveLevel}}
.", screen=".$codes{$this->{termLevel}}
.", database=".$codes{$this->{databaseLevel}}
.", logfile=".$codes{$this->{fileLevel}}
."->".$this->{logFile}
.", syslog=".$codes{$this->{syslogLevel}}
);
}
sub terminate
@ -452,23 +464,39 @@ sub databaseLevel
if ( defined($port) )
{
$this->{dbh} = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME}.";host=".$host.";port=".$port, $Config{ZM_DB_USER}, $Config{ZM_DB_PASS} );
$this->{dbh} = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME}
.";host=".$host
.";port=".$port
, $Config{ZM_DB_USER}
, $Config{ZM_DB_PASS}
);
}
else
{
$this->{dbh} = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME}.";host=".$Config{ZM_DB_HOST}, $Config{ZM_DB_USER}, $Config{ZM_DB_PASS} );
$this->{dbh} = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME}
.";host=".$Config{ZM_DB_HOST}
, $Config{ZM_DB_USER}
, $Config{ZM_DB_PASS}
);
}
if ( !$this->{dbh} )
{
$databaseLevel = NOLOG;
Error( "Unable to write log entries to DB, can't connect to database '".$Config{ZM_DB_NAME}."' on host '".$Config{ZM_DB_HOST}."'" );
Error( "Unable to write log entries to DB, can't connect to database '"
.$Config{ZM_DB_NAME}
."' on host '"
.$Config{ZM_DB_HOST}
."'"
);
}
else
{
$this->{dbh}->{AutoCommit} = 1;
Fatal( "Can't set AutoCommit on in database connection" ) unless( $this->{dbh}->{AutoCommit} );
Fatal( "Can't set AutoCommit on in database connection" )
unless( $this->{dbh}->{AutoCommit} );
$this->{dbh}->{mysql_auto_reconnect} = 1;
Fatal( "Can't set mysql_auto_reconnect on in database connection" ) unless( $this->{dbh}->{mysql_auto_reconnect} );
Fatal( "Can't set mysql_auto_reconnect on in database connection" )
unless( $this->{dbh}->{mysql_auto_reconnect} );
$this->{dbh}->trace( 0 );
}
}
@ -559,7 +587,9 @@ sub openFile
if ( $> == 0 )
{
chown( $webUid, $webGid, $this->{logFile} )
or Fatal( "Can't change permissions on log file '".$this->{logFile}."': $!" )
or Fatal( "Can't change permissions on log file '"
.$this->{logFile}."': $!"
)
}
}
else
@ -588,7 +618,17 @@ sub logPrint
my $code = $codes{$level};
my ($seconds, $microseconds) = gettimeofday();
my $message = sprintf( "%s.%06d %s[%d].%s [%s]", strftime( "%x %H:%M:%S", localtime( $seconds ) ), $microseconds, $this->{id}, $$, $code, $string );
my $message = sprintf(
"%s.%06d %s[%d].%s [%s]"
, strftime( "%x %H:%M:%S"
,localtime( $seconds )
)
, $microseconds
, $this->{id}
, $$
, $code
, $string
);
if ( $this->{trace} )
{
$message = Carp::shortmess( $message );
@ -597,7 +637,8 @@ sub logPrint
{
$message = $message."\n";
}
syslog( $priorities{$level}, $code." [%s]", $string ) if ( $level <= $this->{syslogLevel} );
syslog( $priorities{$level}, $code." [%s]", $string )
if ( $level <= $this->{syslogLevel} );
print( $LOGFILE $message ) if ( $level <= $this->{fileLevel} );
if ( $level <= $this->{databaseLevel} )
{
@ -608,7 +649,14 @@ sub logPrint
$this->{databaseLevel} = NOLOG;
Fatal( "Can't prepare log entry '$sql': ".$this->{dbh}->errstr() );
}
my $res = $this->{sth}->execute( $seconds+($microseconds/1000000.0), $this->{id}, $$, $level, $code, $string, $this->{fileName} );
my $res = $this->{sth}->execute( $seconds+($microseconds/1000000.0)
, $this->{id}
, $$
, $level
, $code
, $string
, $this->{fileName}
);
if ( !$res )
{
$this->{databaseLevel} = NOLOG;
@ -758,11 +806,19 @@ ZoneMinder::Logger - ZoneMinder Logger module
=head1 DESCRIPTION
The ZoneMinder:Logger module contains the common debug and error reporting routines used by the ZoneMinder scripts.
The ZoneMinder:Logger module contains the common debug and error reporting
routines used by the ZoneMinder scripts.
To use debug in your scripts you need to include this module, and call logInit. Thereafter you can sprinkle Debug or Error calls etc throughout the code safe in the knowledge that they will be reported to your error log, and possibly the syslogger, in a meaningful and consistent format.
To use debug in your scripts you need to include this module, and call
logInit. Thereafter you can sprinkle Debug or Error calls etc throughout
the code safe in the knowledge that they will be reported to your error
log, and possibly the syslogger, in a meaningful and consistent format.
Debug is discussed in terms of levels where 1 and above (currently only 1 for scripts) is considered debug, 0 is considered as informational, -1 is a warning, -2 is an error and -3 is a fatal error or panic. Where levels are mentioned below as thresholds the value given and anything with a lower level (ie. more serious) will be included.
Debug is discussed in terms of levels where 1 and above (currently only 1
for scripts) is considered debug, 0 is considered as informational, -1 is a
warning, -2 is an error and -3 is a fatal error or panic. Where levels are
mentioned below as thresholds the value given and anything with a lower
level (ie. more serious) will be included.
=head1 METHODS
@ -770,7 +826,12 @@ Debug is discussed in terms of levels where 1 and above (currently only 1 for sc
=item logInit ( $id, %options );
Initialises the debug and prepares the logging for forthcoming operations. If not called explicitly it will be called by the first debug call in your script, but with default (and probably meaningless) options. The only compulsory arguments are $id which must be a string that will identify debug coming from this script in mixed logs. Other options may be provided as below,
Initialises the debug and prepares the logging for forthcoming operations.
If not called explicitly it will be called by the first debug call in your
script, but with default (and probably meaningless) options. The only
compulsory arguments are $id which must be a string that will identify
debug coming from this script in mixed logs. Other options may be provided
as below,
Option Default Description
--------- --------- -----------
@ -807,27 +868,39 @@ These methods can be used to get and set the current settings as defined in logI
=item Debug( $string );
This method will output a debug message if the current debug level permits it, otherwise does nothing. This message will be tagged with the DBG string in the logs.
This method will output a debug message if the current debug level permits
it, otherwise does nothing. This message will be tagged with the DBG string
in the logs.
=item Info( $string );
This method will output an informational message if the current debug level permits it, otherwise does nothing. This message will be tagged with the INF string in the logs.
This method will output an informational message if the current debug level
permits it, otherwise does nothing. This message will be tagged with the
INF string in the logs.
=item Warning( $string );
This method will output a warning message if the current debug level permits it, otherwise does nothing. This message will be tagged with the WAR string in the logs.
This method will output a warning message if the current debug level
permits it, otherwise does nothing. This message will be tagged with the
WAR string in the logs.
=item Error( $string );
This method will output an error message if the current debug level permits it, otherwise does nothing. This message will be tagged with the ERR string in the logs.
This method will output an error message if the current debug level permits
it, otherwise does nothing. This message will be tagged with the ERR string
in the logs.
=item Fatal( $string );
This method will output a fatal error message and then die if the current debug level permits it, otherwise does nothing. This message will be tagged with the FAT string in the logs.
This method will output a fatal error message and then die if the current
debug level permits it, otherwise does nothing. This message will be tagged
with the FAT string in the logs.
=item Panic( $string );
This method will output a panic error message and then die with a stack trace if the current debug level permits it, otherwise does nothing. This message will be tagged with the PNC string in the logs.
This method will output a panic error message and then die with a stack
trace if the current debug level permits it, otherwise does nothing. This
message will be tagged with the PNC string in the logs.
=back
@ -845,7 +918,8 @@ The :all tag will export all above symbols.
Carp
Sys::Syslog
The ZoneMinder README file Troubleshooting section for an extended discussion on the use and configuration of syslog with ZoneMinder.
The ZoneMinder README file Troubleshooting section for an extended
discussion on the use and configuration of syslog with ZoneMinder.
http://www.zoneminder.com

File diff suppressed because it is too large Load Diff

View File

@ -36,18 +36,18 @@ our @ISA = qw(Exporter ZoneMinder::Base);
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
# This allows declaration use ZoneMinder ':all';
# This allows declaration use ZoneMinder ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
our %EXPORT_TAGS = (
'functions' => [ qw(
zmMemKey
zmMemAttach
zmMemDetach
zmMemGet
zmMemPut
zmMemClean
) ],
'functions' => [ qw(
zmMemKey
zmMemAttach
zmMemDetach
zmMemGet
zmMemPut
zmMemClean
) ],
);
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
@ -70,115 +70,129 @@ use Sys::Mmap;
sub zmMemKey
{
my $monitor = shift;
my $monitor = shift;
return( defined($monitor->{MMapAddr})?$monitor->{MMapAddr}:undef );
}
sub zmMemAttach
{
my ( $monitor, $size ) = @_;
if ( ! $size ) {
Error( "No size passed to zmMemAttach for monitor $$monitor{Id}\n" );
return( undef );
}
if ( !defined($monitor->{MMapAddr}) )
{
my ( $monitor, $size ) = @_;
if ( ! $size ) {
Error( "No size passed to zmMemAttach for monitor $$monitor{Id}\n" );
return( undef );
}
if ( !defined($monitor->{MMapAddr}) )
{
my $mmap_file = $Config{ZM_PATH_MAP}."/zm.mmap.".$monitor->{Id};
if ( ! -e $mmap_file ) {
Error( sprintf( "Memory map file '%s' does not exist. zmc might not be running.", $mmap_file ) );
return ( undef );
}
if ( ! -e $mmap_file ) {
Error( sprintf( "Memory map file '%s' does not exist. zmc might not be running."
, $mmap_file
)
);
return ( undef );
}
my $mmap_file_size = -s $mmap_file;
my $mmap_file_size = -s $mmap_file;
if ( $mmap_file_size < $size ) {
Error( sprintf( "Memory map file '%s' should have been %d but was instead %d", $mmap_file, $size, $mmap_file_size ) );
return ( undef );
}
if ( $mmap_file_size < $size ) {
Error( sprintf( "Memory map file '%s' should have been %d but was instead %d"
, $mmap_file
, $size
, $mmap_file_size
)
);
return ( undef );
}
if ( !open( MMAP, "+<", $mmap_file ) )
{
Error( sprintf( "Can't open memory map file '%s': $!\n", $mmap_file ) );
return( undef );
Error( sprintf( "Can't open memory map file '%s': $!\n", $mmap_file ) );
return( undef );
}
my $mmap = undef;
my $mmap_addr = mmap( $mmap, $size, PROT_READ|PROT_WRITE, MAP_SHARED, \*MMAP );
if ( !$mmap_addr || !$mmap )
{
Error( sprintf( "Can't mmap to file '%s': $!\n", $mmap_file ) );
close( MMAP );
return( undef );
Error( sprintf( "Can't mmap to file '%s': $!\n", $mmap_file ) );
close( MMAP );
return( undef );
}
$monitor->{MMapHandle} = \*MMAP;
$monitor->{MMapAddr} = $mmap_addr;
$monitor->{MMap} = \$mmap;
}
return( !undef );
$monitor->{MMapHandle} = \*MMAP;
$monitor->{MMapAddr} = $mmap_addr;
$monitor->{MMap} = \$mmap;
}
return( !undef );
}
sub zmMemDetach
{
my $monitor = shift;
my $monitor = shift;
if ( $monitor->{MMap} )
{
if ( ! munmap( ${$monitor->{MMap}} ) ) {
Warn( "Unable to munmap for monitor $$monitor{Id}\n");
}
delete $monitor->{MMap};
Warn( "Unable to munmap for monitor $$monitor{Id}\n");
}
delete $monitor->{MMap};
}
if ( $monitor->{MMapAddr} )
{
delete $monitor->{MMapAddr};
delete $monitor->{MMapAddr};
}
if ( $monitor->{MMapHandle} )
{
close( $monitor->{MMapHandle} );
delete $monitor->{MMapHandle};
delete $monitor->{MMapHandle};
}
}
sub zmMemGet
{
my $monitor = shift;
my $offset = shift;
my $size = shift;
my $monitor = shift;
my $offset = shift;
my $size = shift;
my $mmap = $monitor->{MMap};
my $mmap = $monitor->{MMap};
if ( !$mmap || !$$mmap )
{
Error( sprintf( "Can't read from mapped memory for monitor '%d', gone away?", $monitor->{Id} ) );
Error( sprintf( "Can't read from mapped memory for monitor '%d', gone away?"
, $monitor->{Id}
)
);
return( undef );
}
my $data = substr( $$mmap, $offset, $size );
my $data = substr( $$mmap, $offset, $size );
return( $data );
}
sub zmMemPut
{
my $monitor = shift;
my $offset = shift;
my $size = shift;
my $data = shift;
my $monitor = shift;
my $offset = shift;
my $size = shift;
my $data = shift;
my $mmap = $monitor->{MMap};
my $mmap = $monitor->{MMap};
if ( !$mmap || !$$mmap )
{
Error( sprintf( "Can't write mapped memory for monitor '%d', gone away?", $monitor->{Id} ) );
Error( sprintf( "Can't write mapped memory for monitor '%d', gone away?"
, $monitor->{Id}
)
);
return( undef );
}
substr( $$mmap, $offset, $size ) = $data;
return( !undef );
substr( $$mmap, $offset, $size ) = $data;
return( !undef );
}
sub zmMemClean
{
Debug( "Removing memory map files\n" );
Debug( "Removing memory map files\n" );
my $mapPath = $Config{ZM_PATH_MAP}."/zm.mmap.*";
foreach my $mapFile( glob( $mapPath ) )
{
( $mapFile ) = $mapFile =~ /^(.+)$/;
Debug( "Removing memory map file '$mapFile'\n" );
Debug( "Removing memory map file '$mapFile'\n" );
unlink( $mapFile );
}
}

View File

@ -19,7 +19,7 @@
#
# ==========================================================================
#
# This module contains the common definitions and functions used by the rest
# This module contains the common definitions and functions used by the rest
# of the ZoneMinder scripts
#
package ZoneMinder::Memory::Shared;
@ -39,18 +39,18 @@ eval 'sub IPC_CREAT {0001000}' unless defined &IPC_CREAT;
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
# This allows declaration use ZoneMinder ':all';
# This allows declaration use ZoneMinder ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
our %EXPORT_TAGS = (
'functions' => [ qw(
'functions' => [ qw(
zmMemKey
zmMemAttach
zmMemDetach
zmMemGet
zmMemPut
zmMemClean
) ],
) ],
);
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
@ -71,77 +71,92 @@ use ZoneMinder::Logger qw(:all);
sub zmMemKey
{
my $monitor = shift;
return( defined($monitor->{ShmKey})?$monitor->{ShmKey}:undef );
my $monitor = shift;
return( defined($monitor->{ShmKey})?$monitor->{ShmKey}:undef );
}
sub zmMemAttach
{
my $monitor = shift;
my $size = shift;
if ( !defined($monitor->{ShmId}) )
{
my $shm_key = (hex($Config{ZM_SHM_KEY})&0xffff0000)|$monitor->{Id};
my $shm_id = shmget( $shm_key, $size, &IPC_CREAT | 0777 );
if ( !defined($shm_id) )
{
Error( sprintf( "Can't get shared memory id '%x', %d: $!\n", $shm_key, $monitor->{Id} ) );
return( undef );
}
$monitor->{ShmKey} = $shm_key;
$monitor->{ShmId} = $shm_id;
}
return( !undef );
my $monitor = shift;
my $size = shift;
if ( !defined($monitor->{ShmId}) )
{
my $shm_key = (hex($Config{ZM_SHM_KEY})&0xffff0000)|$monitor->{Id};
my $shm_id = shmget( $shm_key, $size, &IPC_CREAT | 0777 );
if ( !defined($shm_id) )
{
Error( sprintf( "Can't get shared memory id '%x', %d: $!\n"
, $shm_key
, $monitor->{Id}
)
);
return( undef );
}
$monitor->{ShmKey} = $shm_key;
$monitor->{ShmId} = $shm_id;
}
return( !undef );
}
sub zmMemDetach
{
my $monitor = shift;
my $monitor = shift;
delete $monitor->{ShmId};
delete $monitor->{ShmId};
}
sub zmMemGet
{
my $monitor = shift;
my $offset = shift;
my $size = shift;
my $monitor = shift;
my $offset = shift;
my $size = shift;
my $shm_key = $monitor->{ShmKey};
my $shm_id = $monitor->{ShmId};
my $shm_key = $monitor->{ShmKey};
my $shm_id = $monitor->{ShmId};
my $data;
if ( !shmread( $shm_id, $data, $offset, $size ) )
{
Error( sprintf( "Can't read from shared memory '%x/%d': $!", $shm_key, $shm_id ) );
Error( sprintf( "Can't read from shared memory '%x/%d': $!"
, $shm_key
, $shm_id
)
);
return( undef );
}
return( $data );
return( $data );
}
sub zmMemPut
{
my $monitor = shift;
my $offset = shift;
my $size = shift;
my $data = shift;
my $monitor = shift;
my $offset = shift;
my $size = shift;
my $data = shift;
my $shm_key = $monitor->{ShmKey};
my $shm_id = $monitor->{ShmId};
my $shm_key = $monitor->{ShmKey};
my $shm_id = $monitor->{ShmId};
if ( !shmwrite( $shm_id, $data, $offset, $size ) )
{
Error( sprintf( "Can't write to shared memory '%x/%d': $!", $shm_key, $shm_id ) );
Error( sprintf( "Can't write to shared memory '%x/%d': $!"
, $shm_key
, $shm_id
)
);
return( undef );
}
return( !undef );
return( !undef );
}
sub zmMemClean
{
Debug( "Removing shared memory\n" );
# Find ZoneMinder shared memory
my $command = "ipcs -m | grep '^".substr( sprintf( "0x%x", hex($Config{ZM_SHM_KEY}) ), 0, -2 )."'";
my $command = "ipcs -m | grep '^"
.substr( sprintf( "0x%x", hex($Config{ZM_SHM_KEY}) ), 0, -2 )
."'"
;
Debug( "Checking for shared memory with '$command'\n" );
open( my $CMD, '<', "$command |" )
or Fatal( "Can't execute '$command': $!" );

View File

@ -46,53 +46,53 @@ our $AUTOLOAD;
sub new
{
my $class = shift;
my $self = {};
$self->{readable} = !undef;
$self->{writeable} = !undef;
$self->{selectable} = undef;
$self->{state} = 'closed';
bless( $self, $class );
return $self;
my $class = shift;
my $self = {};
$self->{readable} = !undef;
$self->{writeable} = !undef;
$self->{selectable} = undef;
$self->{state} = 'closed';
bless( $self, $class );
return $self;
}
sub clone
{
my $self = shift;
my $clone = { %$self };
bless $clone, ref $self;
my $self = shift;
my $clone = { %$self };
bless $clone, ref $self;
}
sub open
{
my $self = shift;
my $class = ref($self) or croak( "Can't get class for non object $self" );
croak( "Abstract base class method called for object of class $class" );
my $self = shift;
my $class = ref($self) or croak( "Can't get class for non object $self" );
croak( "Abstract base class method called for object of class $class" );
}
sub close
{
my $self = shift;
my $class = ref($self) or croak( "Can't get class for non object $self" );
croak( "Abstract base class method called for object of class $class" );
my $self = shift;
my $class = ref($self) or croak( "Can't get class for non object $self" );
croak( "Abstract base class method called for object of class $class" );
}
sub getState
{
my $self = shift;
return( $self->{state} );
my $self = shift;
return( $self->{state} );
}
sub isOpen
{
my $self = shift;
return( $self->{state} eq "open" );
my $self = shift;
return( $self->{state} eq "open" );
}
sub isConnected
{
my $self = shift;
return( $self->{state} eq "connected" );
my $self = shift;
return( $self->{state} eq "connected" );
}
sub DESTROY
@ -101,15 +101,15 @@ sub DESTROY
sub AUTOLOAD
{
my $self = shift;
my $class = ref($self) || croak( "$self not object" );
my $name = $AUTOLOAD;
$name =~ s/.*://;
if ( !exists($self->{$name}) )
{
croak( "Can't access $name member of object of class $class" );
}
return( $self->{$name} );
my $self = shift;
my $class = ref($self) || croak( "$self not object" );
my $name = $AUTOLOAD;
$name =~ s/.*://;
if ( !exists($self->{$name}) )
{
croak( "Can't access $name member of object of class $class" );
}
return( $self->{$name} );
}
1;

View File

@ -48,23 +48,23 @@ use Fcntl;
sub new
{
my $class = shift;
my %params = @_;
my $self = ZoneMinder::Trigger::Channel::Handle->new;
$self->{path} = $params{path};
bless( $self, $class );
return $self;
my $class = shift;
my %params = @_;
my $self = ZoneMinder::Trigger::Channel::Handle->new;
$self->{path} = $params{path};
bless( $self, $class );
return $self;
}
sub open
{
my $self = shift;
local *sfh;
#sysopen( *sfh, $conn->{path}, O_NONBLOCK|O_RDONLY ) or croak( "Can't sysopen: $!" );
#open( *sfh, "<".$conn->{path} ) or croak( "Can't open: $!" );
open( *sfh, "+<", $self->{path} ) or croak( "Can't open: $!" );
$self->{state} = 'open';
$self->{handle} = *sfh;
my $self = shift;
local *sfh;
#sysopen( *sfh, $conn->{path}, O_NONBLOCK|O_RDONLY ) or croak( "Can't sysopen: $!" );
#open( *sfh, "<".$conn->{path} ) or croak( "Can't open: $!" );
open( *sfh, "+<", $self->{path} ) or croak( "Can't open: $!" );
$self->{state} = 'open';
$self->{handle} = *sfh;
}
1;

View File

@ -46,12 +46,12 @@ use POSIX;
sub new
{
my $class = shift;
my $port = shift;
my $self = ZoneMinder::Trigger::Channel->new();
$self->{handle} = undef;
bless( $self, $class );
return $self;
my $class = shift;
my $port = shift;
my $self = ZoneMinder::Trigger::Channel->new();
$self->{handle} = undef;
bless( $self, $class );
return $self;
}
sub spawns
@ -61,43 +61,49 @@ sub spawns
sub close
{
my $self = shift;
close( $self->{handle} );
$self->{state} = 'closed';
$self->{handle} = undef;
my $self = shift;
close( $self->{handle} );
$self->{state} = 'closed';
$self->{handle} = undef;
}
sub read
{
my $self = shift;
my $buffer;
my $nbytes = sysread( $self->{handle}, $buffer, POSIX::BUFSIZ );
if ( !$nbytes )
{
return( undef );
}
Debug( "Read '$buffer' ($nbytes bytes)\n" );
return( $buffer );
my $self = shift;
my $buffer;
my $nbytes = sysread( $self->{handle}, $buffer, POSIX::BUFSIZ );
if ( !$nbytes )
{
return( undef );
}
Debug( "Read '$buffer' ($nbytes bytes)\n" );
return( $buffer );
}
sub write
{
my $self = shift;
my $buffer = shift;
my $nbytes = syswrite( $self->{handle}, $buffer );
if ( !defined( $nbytes) || $nbytes < length($buffer) )
{
Error( "Unable to write buffer '".$buffer.", expected ".length($buffer)." bytes, sent ".($nbytes?$nbytes:'undefined').": $!\n" );
return( undef );
}
Debug( "Wrote '$buffer' ($nbytes bytes)\n" );
return( !undef );
my $self = shift;
my $buffer = shift;
my $nbytes = syswrite( $self->{handle}, $buffer );
if ( !defined( $nbytes) || $nbytes < length($buffer) )
{
Error( "Unable to write buffer '".$buffer
.", expected "
.length($buffer)
." bytes, sent "
.($nbytes?$nbytes:'undefined')
.": $!\n"
);
return( undef );
}
Debug( "Wrote '$buffer' ($nbytes bytes)\n" );
return( !undef );
}
sub fileno
{
my $self = shift;
return( defined($self->{handle})?fileno($self->{handle}):-1 );
my $self = shift;
return( defined($self->{handle})?fileno($self->{handle}):-1 );
}
1;

View File

@ -48,44 +48,45 @@ use Socket;
sub new
{
my $class = shift;
my %params = @_;
my $self = ZoneMinder::Trigger::Channel::Spawning->new();
$self->{selectable} = !undef;
$self->{port} = $params{port};
bless( $self, $class );
return $self;
my $class = shift;
my %params = @_;
my $self = ZoneMinder::Trigger::Channel::Spawning->new();
$self->{selectable} = !undef;
$self->{port} = $params{port};
bless( $self, $class );
return $self;
}
sub open
{
my $self = shift;
local *sfh;
my $saddr = sockaddr_in( $self->{port}, INADDR_ANY );
socket( *sfh, PF_INET, SOCK_STREAM, getprotobyname('tcp') ) or croak( "Can't open socket: $!" );
setsockopt( *sfh, SOL_SOCKET, SO_REUSEADDR, 1 );
bind( *sfh, $saddr ) or croak( "Can't bind: $!" );
listen( *sfh, SOMAXCONN ) or croak( "Can't listen: $!" );
$self->{state} = 'open';
$self->{handle} = *sfh;
my $self = shift;
local *sfh;
my $saddr = sockaddr_in( $self->{port}, INADDR_ANY );
socket( *sfh, PF_INET, SOCK_STREAM, getprotobyname('tcp') )
or croak( "Can't open socket: $!" );
setsockopt( *sfh, SOL_SOCKET, SO_REUSEADDR, 1 );
bind( *sfh, $saddr ) or croak( "Can't bind: $!" );
listen( *sfh, SOMAXCONN ) or croak( "Can't listen: $!" );
$self->{state} = 'open';
$self->{handle} = *sfh;
}
sub _spawn
{
my $self = shift;
my $new_handle = shift;
my $clone = $self->clone();
$clone->{handle} = $new_handle;
$clone->{state} = 'connected';
return( $clone );
my $self = shift;
my $new_handle = shift;
my $clone = $self->clone();
$clone->{handle} = $new_handle;
$clone->{state} = 'connected';
return( $clone );
}
sub accept
{
my $self = shift;
local *cfh;
my $paddr = accept( *cfh, $self->{handle} );
return( $self->_spawn( *cfh ) );
my $self = shift;
local *cfh;
my $paddr = accept( *cfh, $self->{handle} );
return( $self->_spawn( *cfh ) );
}
1;

View File

@ -46,64 +46,70 @@ use Device::SerialPort;
sub new
{
my $class = shift;
my %params = @_;
my $self = ZoneMinder::Trigger::Channel->new;
$self->{path} = $params{path};
bless( $self, $class );
return $self;
my $class = shift;
my %params = @_;
my $self = ZoneMinder::Trigger::Channel->new;
$self->{path} = $params{path};
bless( $self, $class );
return $self;
}
sub open
{
my $self = shift;
my $device = new Device::SerialPort( $self->{path} );
$device->baudrate(9600);
$device->databits(8);
$device->parity('none');
$device->stopbits(1);
$device->handshake('none');
my $self = shift;
my $device = new Device::SerialPort( $self->{path} );
$device->baudrate(9600);
$device->databits(8);
$device->parity('none');
$device->stopbits(1);
$device->handshake('none');
$device->read_const_time(50);
$device->read_char_time(10);
$device->read_const_time(50);
$device->read_char_time(10);
$self->{device} = $device;
$self->{state} = 'open';
$self->{state} = 'connected';
$self->{device} = $device;
$self->{state} = 'open';
$self->{state} = 'connected';
}
sub close
{
my $self = shift;
$self->{device}->close();
$self->{state} = 'closed';
my $self = shift;
$self->{device}->close();
$self->{state} = 'closed';
}
sub read
{
my $self = shift;
my $buffer = $self->{device}->lookfor();
if ( !$buffer || !length($buffer) )
{
return( undef );
}
Debug( "Read '$buffer' (".length($buffer)." bytes)\n" );
return( $buffer );
my $self = shift;
my $buffer = $self->{device}->lookfor();
if ( !$buffer || !length($buffer) )
{
return( undef );
}
Debug( "Read '$buffer' (".length($buffer)." bytes)\n" );
return( $buffer );
}
sub write
{
my $self = shift;
my $buffer = shift;
my $nbytes = $self->{device}->write( $buffer );
$self->{device}->write_drain();
if ( !defined( $nbytes) || $nbytes < length($buffer) )
{
Error( "Unable to write buffer '".$buffer.", expected ".length($buffer)." bytes, sent ".$nbytes.": $!\n" );
return( undef );
}
Debug( "Wrote '$buffer' ($nbytes bytes)\n" );
return( !undef );
my $self = shift;
my $buffer = shift;
my $nbytes = $self->{device}->write( $buffer );
$self->{device}->write_drain();
if ( !defined( $nbytes) || $nbytes < length($buffer) )
{
Error( "Unable to write buffer '".$buffer
.", expected "
.length($buffer)
." bytes, sent "
.$nbytes
.": $!\n"
);
return( undef );
}
Debug( "Wrote '$buffer' ($nbytes bytes)\n" );
return( !undef );
}
1;

View File

@ -45,12 +45,12 @@ use ZoneMinder::Logger qw(:all);
sub new
{
my $class = shift;
my $port = shift;
my $self = ZoneMinder::Trigger::Channel::Handle->new();
$self->{spawns} = !undef;
bless( $self, $class );
return $self;
my $class = shift;
my $port = shift;
my $self = ZoneMinder::Trigger::Channel::Handle->new();
$self->{spawns} = !undef;
bless( $self, $class );
return $self;
}
sub spawns

View File

@ -48,25 +48,25 @@ use Socket;
sub new
{
my $class = shift;
my %params = @_;
my $self = ZoneMinder::Trigger::Channel->new;
$self->{selectable} = !undef;
$self->{path} = $params{path};
bless( $self, $class );
return $self;
my $class = shift;
my %params = @_;
my $self = ZoneMinder::Trigger::Channel->new;
$self->{selectable} = !undef;
$self->{path} = $params{path};
bless( $self, $class );
return $self;
}
sub open
{
my $self = shift;
local *sfh;
unlink( $self->{path} );
my $saddr = sockaddr_un( $self->{path} );
socket( *sfh, PF_UNIX, SOCK_STREAM, 0 ) or croak( "Can't open socket: $!" );
bind( *sfh, $saddr ) or croak( "Can't bind: $!" );
listen( *sfh, SOMAXCONN ) or croak( "Can't listen: $!" );
$self->{handle} = *sfh;
my $self = shift;
local *sfh;
unlink( $self->{path} );
my $saddr = sockaddr_un( $self->{path} );
socket( *sfh, PF_UNIX, SOCK_STREAM, 0 ) or croak( "Can't open socket: $!" );
bind( *sfh, $saddr ) or croak( "Can't bind: $!" );
listen( *sfh, SOMAXCONN ) or croak( "Can't listen: $!" );
$self->{handle} = *sfh;
}
sub _spawn

View File

@ -46,115 +46,121 @@ our $AUTOLOAD;
sub new
{
my $class = shift;
my %params = @_;
my $self = {};
$self->{name} = $params{name};
$self->{channel} = $params{channel};
$self->{input} = $params{mode} =~ /r/i;
$self->{output} = $params{mode} =~ /w/i;
bless( $self, $class );
return $self;
my $class = shift;
my %params = @_;
my $self = {};
$self->{name} = $params{name};
$self->{channel} = $params{channel};
$self->{input} = $params{mode} =~ /r/i;
$self->{output} = $params{mode} =~ /w/i;
bless( $self, $class );
return $self;
}
sub clone
{
my $self = shift;
my $clone = { %$self };
bless $clone, ref $self;
return( $clone );
my $self = shift;
my $clone = { %$self };
bless $clone, ref $self;
return( $clone );
}
sub spawns
{
my $self = shift;
my $self = shift;
return( $self->{channel}->spawns() );
}
sub _spawn
{
my $self = shift;
my $new_channel = shift;
my $clone = $self->clone();
$clone->{channel} = $new_channel;
return( $clone );
my $self = shift;
my $new_channel = shift;
my $clone = $self->clone();
$clone->{channel} = $new_channel;
return( $clone );
}
sub accept
{
my $self = shift;
my $new_channel = $self->{channel}->accept();
return( $self->_spawn( $new_channel ) );
my $self = shift;
my $new_channel = $self->{channel}->accept();
return( $self->_spawn( $new_channel ) );
}
sub open
{
my $self = shift;
return( $self->{channel}->open() );
my $self = shift;
return( $self->{channel}->open() );
}
sub close
{
my $self = shift;
return( $self->{channel}->close() );
my $self = shift;
return( $self->{channel}->close() );
}
sub fileno
{
my $self = shift;
return( $self->{channel}->fileno() );
my $self = shift;
return( $self->{channel}->fileno() );
}
sub isOpen
{
my $self = shift;
return( $self->{channel}->isOpen() );
my $self = shift;
return( $self->{channel}->isOpen() );
}
sub isConnected
{
my $self = shift;
return( $self->{channel}->isConnected() );
my $self = shift;
return( $self->{channel}->isConnected() );
}
sub canRead
{
my $self = shift;
return( $self->{input} && $self->isConnected() );
my $self = shift;
return( $self->{input} && $self->isConnected() );
}
sub canWrite
{
my $self = shift;
return( $self->{output} && $self->isConnected() );
my $self = shift;
return( $self->{output} && $self->isConnected() );
}
sub getMessages
{
my $self = shift;
my $buffer = $self->{channel}->read();
my $self = shift;
my $buffer = $self->{channel}->read();
return( undef ) if ( !defined($buffer) );
return( undef ) if ( !defined($buffer) );
my @messages = split( /\r?\n/, $buffer );
return( \@messages );
my @messages = split( /\r?\n/, $buffer );
return( \@messages );
}
sub putMessages
{
my $self = shift;
my $messages = shift;
my $self = shift;
my $messages = shift;
if ( @$messages )
{
my $buffer = join( "\n", @$messages );
$buffer .= "\n";
if ( !$self->{channel}->write( $buffer ) )
{
Error( "Unable to write buffer '".$buffer." to connection ".$self->{name}." (".$self->fileno().")\n" );
}
}
return( undef );
if ( @$messages )
{
my $buffer = join( "\n", @$messages );
$buffer .= "\n";
if ( !$self->{channel}->write( $buffer ) )
{
Error( "Unable to write buffer '".$buffer
." to connection "
.$self->{name}
." ("
.$self->fileno()
.")\n"
);
}
}
return( undef );
}
sub timedActions
@ -167,22 +173,22 @@ 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} );
}
elsif ( defined($self->{channel}) )
{
if ( exists($self->{channel}->{$name}) )
{
return( $self->{channel}->{$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} );
}
elsif ( defined($self->{channel}) )
{
if ( exists($self->{channel}->{$name}) )
{
return( $self->{channel}->{$name} );
}
}
croak( "Can't access $name member of object of class $class" );
}
1;

View File

@ -44,40 +44,40 @@ use ZoneMinder::Logger qw(:all);
sub new
{
my $class = shift;
my $path = shift;
my $self = ZoneMinder::Trigger::Connection->new( @_ );
bless( $self, $class );
return $self;
my $class = shift;
my $path = shift;
my $self = ZoneMinder::Trigger::Connection->new( @_ );
bless( $self, $class );
return $self;
}
sub getMessages
{
my $self = shift;
my $buffer = $self->{channel}->read();
my $self = shift;
my $buffer = $self->{channel}->read();
return( undef ) if ( !defined($buffer) );
return( undef ) if ( !defined($buffer) );
Debug( "Handling buffer '$buffer'\n" );
my @messages = grep { s/-/|/g; 1; } split( /\r?\n/, $buffer );
return( \@messages );
Debug( "Handling buffer '$buffer'\n" );
my @messages = grep { s/-/|/g; 1; } split( /\r?\n/, $buffer );
return( \@messages );
}
sub putMessages
{
my $self = shift;
my $messages = shift;
my $self = shift;
my $messages = shift;
if ( @$messages )
{
my $buffer = join( "\n", grep{ s/\|/-/; 1; } @$messages );
$buffer .= "\n";
if ( !$self->{channel}->write( $buffer ) )
{
Error( "Unable to write buffer '".$buffer." to connection ".$self->{name}." (".$self->fileno().")\n" );
}
}
return( undef );
if ( @$messages )
{
my $buffer = join( "\n", grep{ s/\|/-/; 1; } @$messages );
$buffer .= "\n";
if ( !$self->{channel}->write( $buffer ) )
{
Error( "Unable to write buffer '".$buffer." to connection ".$self->{name}." (".$self->fileno().")\n" );
}
}
return( undef );
}
1;

View File

@ -1554,8 +1554,10 @@ void EventStream::runStream()
if ( ((curr_frame_id-1)%frame_mod) == 0 )
{
delta_us = (unsigned int)(frame_data->delta * 1000000);
if ( effective_fps < base_fps )
delta_us = (unsigned int)((delta_us * base_fps)/effective_fps);
// if effective > base we should speed up frame delivery
delta_us = (unsigned int)((delta_us * base_fps)/effective_fps);
// but must not exceed maxfps
delta_us = max(delta_us, 1000000 / maxfps);
send_frame = true;
}
}

View File

@ -427,7 +427,7 @@ void *FfmpegCamera::ReopenFfmpegThreadCallback(void *ctx){
// Close current stream.
camera->CloseFfmpeg();
// Sleep if neccessary to not reconnect too fast.
// Sleep if necessary to not reconnect too fast.
int wait = config.ffmpeg_open_timeout - (time(NULL) - camera->mOpenStart);
wait = wait < 0 ? 0 : wait;
if (wait > 0){

View File

@ -305,7 +305,7 @@ void Image::Initialise()
initialised = true;
}
/* Requests a writeable buffer to the image. This is safer than buffer() because this way we can gurantee that a buffer of required size exists */
/* Requests a writeable buffer to the image. This is safer than buffer() because this way we can guarantee that a buffer of required size exists */
uint8_t* Image::WriteBuffer(const unsigned int p_width, const unsigned int p_height, const unsigned int p_colours, const unsigned int p_subpixelorder) {
unsigned int newsize;
@ -1593,7 +1593,7 @@ Image *Image::Highlight( unsigned int n_images, Image *images[], const Rgb thres
return( result );
}
/* New function to allow buffer re-using instead of allocationg memory for the delta image everytime */
/* New function to allow buffer re-using instead of allocationg memory for the delta image every time */
void Image::Delta( const Image &image, Image* targetimage) const
{
#ifdef ZM_IMAGE_PROFILING

View File

@ -32,6 +32,13 @@
#include <stdlib.h>
#include <limits.h>
/* Workaround for GNU/kFreeBSD */
#if defined(__FreeBSD_kernel__)
#ifndef ENODATA
#define ENODATA ENOATTR
#endif
#endif
static unsigned int BigEndian;
static int vidioctl( int fd, int request, void *arg )
@ -255,7 +262,7 @@ static PixelFormat getFfPixFormatFromV4lPalette( int v4l_version, int palette )
#if ZM_HAS_V4L2
static char palette_desc[32];
/* Automatic format selection prefered formats */
/* Automatic format selection preferred formats */
static const uint32_t prefered_rgb32_formats[] = {V4L2_PIX_FMT_BGR32, V4L2_PIX_FMT_RGB32, V4L2_PIX_FMT_BGR24, V4L2_PIX_FMT_RGB24, V4L2_PIX_FMT_YUYV, V4L2_PIX_FMT_UYVY, V4L2_PIX_FMT_JPEG, V4L2_PIX_FMT_MJPEG, V4L2_PIX_FMT_YUV422P, V4L2_PIX_FMT_YUV420};
static const uint32_t prefered_rgb24_formats[] = {V4L2_PIX_FMT_BGR24, V4L2_PIX_FMT_RGB24, V4L2_PIX_FMT_YUYV, V4L2_PIX_FMT_UYVY, V4L2_PIX_FMT_JPEG, V4L2_PIX_FMT_MJPEG, V4L2_PIX_FMT_YUV422P, V4L2_PIX_FMT_YUV420};
static const uint32_t prefered_gray8_formats[] = {V4L2_PIX_FMT_GREY, V4L2_PIX_FMT_YUYV, V4L2_PIX_FMT_UYVY, V4L2_PIX_FMT_JPEG, V4L2_PIX_FMT_MJPEG, V4L2_PIX_FMT_YUV422P, V4L2_PIX_FMT_YUV420};

View File

@ -535,7 +535,12 @@ void Logger::logPrint( bool hex, const char * const file, const int line, const
if (tid < 0 ) // Thread/Process id
#else
#ifdef HAVE_SYSCALL
#ifdef __FreeBSD_kernel__
if ( (syscall(SYS_thr_self, &tid)) < 0 ) // Thread/Process id
# else
if ( (tid = syscall(SYS_gettid)) < 0 ) // Thread/Process id
#endif
#endif // HAVE_SYSCALL
#endif
tid = getpid(); // Process id

View File

@ -470,7 +470,7 @@ Monitor::Monitor(
}
}
// Will this not happen everytime a monitor is instantiated? Seems like all the calls to the Monitor constructor pass a zero for n_zones, then load zones after..
// Will this not happen every time a monitor is instantiated? Seems like all the calls to the Monitor constructor pass a zero for n_zones, then load zones after..
if ( !n_zones ) {
Debug( 1, "Monitor %s has no zones, adding one.", name );
n_zones = 1;
@ -558,14 +558,18 @@ bool Monitor::connect() {
Error( "Got unexpected memory map file size %ld, expected %d", map_stat.st_size, mem_size );
return false;
} else {
#ifdef MAP_LOCKED
mem_ptr = (unsigned char *)mmap( NULL, mem_size, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_LOCKED, map_fd, 0 );
if ( mem_ptr == MAP_FAILED ) {
if ( errno == EAGAIN ) {
Debug( 1, "Unable to map file %s (%d bytes) to locked memory, trying unlocked", mem_file, mem_size );
#endif
mem_ptr = (unsigned char *)mmap( NULL, mem_size, PROT_READ|PROT_WRITE, MAP_SHARED, map_fd, 0 );
Debug( 1, "Mapped file %s (%d bytes) to locked memory, unlocked", mem_file, mem_size );
#ifdef MAP_LOCKED
}
}
#endif
if ( mem_ptr == MAP_FAILED )
Fatal( "Can't map file %s (%d bytes) to memory: %s(%d)", mem_file, mem_size, strerror(errno), errno );
}
@ -3150,7 +3154,7 @@ bool Monitor::closeEvent()
* comparing it with ZM_COLOUR_RGB24 or ZM_COLOUR_RGB32 is the way ), and then
* manage che check using RGB_VAL_RED() and so on macros instead of just RED().
*
* Be carefull that in 32 bit images we need to check also where the alpha channel is, so,
* Be careful that in 32 bit images we need to check also where the alpha channel is, so,
* (RGBA and BGRA) or (ABGR and ARGB) aren't the same!
*
* To check black pixels in 32 bit images i can do a more efficient way using

View File

@ -262,7 +262,7 @@ void VideoStream::SetupCodec( int colours, int subpixelorder, int width, int hei
/* emit one intra frame every second */
c->gop_size = frame_rate;
// some formats want stream headers to be seperate
// some formats want stream headers to be separate
if ( of->flags & AVFMT_GLOBALHEADER )
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
}

View File

@ -392,7 +392,7 @@ int RtspThread::run()
if ( ( lines[i].size() > 13 ) && ( lines[i].substr( 0, 13 ) == "Content-Base:" ) )
{
mUrl = trimSpaces( lines[i].substr( 13 ) );
Info("Recieved new Content-Base in DESCRIBE reponse header. Updated device Url to: '%s'", mUrl.c_str() );
Info("Received new Content-Base in DESCRIBE response header. Updated device Url to: '%s'", mUrl.c_str() );
break;
}
}

View File

@ -64,12 +64,19 @@ RETSIGTYPE zm_die_handler(int signal)
info->si_uid, info->si_status);
ucontext_t *uc = (ucontext_t *) context;
cr2 = info->si_addr;
#if defined(__x86_64__)
cr2 = info->si_addr;
#ifdef __FreeBSD_kernel__
ip = (void *)(uc->uc_mcontext.mc_rip);
#else
ip = (void *)(uc->uc_mcontext.gregs[REG_RIP]);
#endif
#else
cr2 = info->si_addr;
#ifdef __FreeBSD_kernel__
ip = (void *)(uc->uc_mcontext.mc_eip);
#else
ip = (void *)(uc->uc_mcontext.gregs[REG_EIP]);
#endif
#endif // defined(__x86_64__)
// Print the signal address and instruction pointer if available

View File

@ -36,15 +36,19 @@ class ThreadException : public Exception
{
private:
pid_t pid() {
pid_t tid;
pid_t tid;
#ifdef __FreeBSD__
long lwpid;
thr_self(&lwpid);
tid = lwpid;
long lwpid;
thr_self(&lwpid);
tid = lwpid;
#else
tid=syscall(SYS_gettid);
#ifdef __FreeBSD_kernel__
if ( (syscall(SYS_thr_self, &tid)) < 0 ) // Thread/Process id
# else
tid=syscall(SYS_gettid);
#endif
#endif
return tid;
return tid;
}
public:
ThreadException( const std::string &message ) : Exception( stringtf( "(%d) "+message, (long int)pid() ) ) {
@ -219,13 +223,18 @@ protected:
pid_t id() const
{
pid_t tid;
pid_t tid;
#ifdef __FreeBSD__
long lwpid;
thr_self(&lwpid);
tid = lwpid;
long lwpid;
thr_self(&lwpid);
tid = lwpid;
#else
tid=syscall(SYS_gettid);
#ifdef __FreeBSD_kernel__
if ( (syscall(SYS_thr_self, &tid)) < 0 ) // Thread/Process id
#else
tid=syscall(SYS_gettid);
#endif
#endif
return tid;
}

View File

@ -40,7 +40,11 @@ private:
thr_self(&lwpid);
tid = lwpid;
#else
#ifdef __FreeBSD_kernel__
if ( (syscall(SYS_thr_self, &tid)) < 0 ) // Thread/Process id
#else
tid=syscall(SYS_gettid);
#endif
#endif
return tid;
}

View File

@ -1,4 +1,6 @@
<?php
# We use session vars in here, so we need to restart the session because we stopped it in index.php to improve concurrency.
session_start();
if ( empty($_REQUEST['id']) && empty($_REQUEST['eids']) ) {
ajaxError( "No event id(s) supplied" );

View File

@ -63,30 +63,30 @@ if ( isset($_GET['skin']) )
$skin = $_GET['skin'];
elseif ( isset($_COOKIE['zmSkin']) )
$skin = $_COOKIE['zmSkin'];
elseif ( defined(ZM_SKIN_DEFAULT) )
elseif ( defined('ZM_SKIN_DEFAULT') )
$skin = ZM_SKIN_DEFAULT;
else
$skin = "classic";
$skins = array_map( 'basename', glob('skins/*',GLOB_ONLYDIR) );
if ( ! in_array( $skin, $skins ) ) {
Error( "Invalid skin '$skin'" );
$skin = 'classic';
Error( "Invalid skin '$skin' setting to " . $skins[0] );
$skin = $skins[0];
}
if ( isset($_GET['css']) )
$css = $_GET['css'];
elseif ( isset($_COOKIE['zmCSS']) )
$css = $_COOKIE['zmCSS'];
elseif (defined(ZM_CSS_DEFAULT))
elseif (defined('ZM_CSS_DEFAULT'))
$css = ZM_CSS_DEFAULT;
else
$css = "classic";
$css_skins = array_map( 'basename', glob('skins/'.$skin.'/css/*',GLOB_ONLYDIR) );
if ( ! in_array( $css, $css_skins ) ) {
Error( "Invalid skin css '$css'" );
$css = 'classic';
Error( "Invalid skin css '$css' setting to " . $css_skins[0] );
$css = $css_skins[0];
}
define( "ZM_BASE_PATH", dirname( $_SERVER['REQUEST_URI'] ) );
@ -102,13 +102,13 @@ ini_set( "session.name", "ZMSESSID" );
session_start();
if ( !isset($_SESSION['skin']) || isset($_REQUEST['skin']) )
if ( !isset($_SESSION['skin']) || isset($_REQUEST['skin']) || !isset($_COOKIE['zmSkin']) || $_COOKIE['zmSkin'] != $skin )
{
$_SESSION['skin'] = $skin;
setcookie( "zmSkin", $skin, time()+3600*24*30*12*10 );
}
if ( !isset($_SESSION['css']) || isset($_REQUEST['css']) ) {
if ( !isset($_SESSION['css']) || isset($_REQUEST['css']) || !isset($_COOKIE['zmCSS']) || $_COOKIE['zmCSS'] != $css ) {
$_SESSION['css'] = $css;
setcookie( "zmCSS", $css, time()+3600*24*30*12*10 );
}
@ -143,6 +143,10 @@ if ( ZM_OPT_USE_AUTH && ! isset($user) && $view != 'login' ) {
$view = 'login';
}
# Only one request can open the session file at a time, so let's close the session here to improve concurrency.
# Any file/page that uses the session must re-open it.
session_write_close();
if ( isset( $_REQUEST['request'] ) )
{
foreach ( getSkinIncludes( 'ajax/'.$request.'.php', true, true ) as $includeFile )

View File

@ -24,6 +24,9 @@ if ( !canView( 'Events' ) )
return;
}
# Must re-start session because we close it now in index.php to improve concurrency
session_start();
if ( isset($_SESSION['export']) )
{
if ( isset($_SESSION['export']['detail']) )