Merge branch 'master' of github.com:ZoneMinder/ZoneMinder

pull/1932/head
Isaac Connor 2017-06-23 10:11:52 -04:00
commit 52f1e2d235
8 changed files with 163 additions and 159 deletions

View File

@ -33,8 +33,11 @@ FOREACH(PERLSCRIPT ${perlscripts})
ENDFOREACH(PERLSCRIPT ${perlscripts})
# Install the perl scripts
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/zmaudit.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmcontrol.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmdc.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmfilter.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmpkg.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmtrack.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmtrigger.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmupdate.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmvideo.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmwatch.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmcamtool.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmsystemctl.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmtelemetry.pl" DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}" PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/zmaudit.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmcontrol.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmdc.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmfilter.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmpkg.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmtrack.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmtrigger.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmupdate.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmvideo.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmwatch.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmcamtool.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmtelemetry.pl" DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}" PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
if(NOT ZM_NO_X10)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/zmx10.pl" DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}" PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
endif(NOT ZM_NO_X10)
if(WITH_SYSTEMD)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/zmsystemctl.pl" DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}" PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
endif(WITH_SYSTEMD)

View File

@ -41,7 +41,7 @@ our @ISA = qw(Exporter ZoneMinder::Base);
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
our %EXPORT_TAGS = (
'constants' => [ qw(
constants => [ qw(
DEBUG
INFO
WARNING
@ -50,7 +50,7 @@ our %EXPORT_TAGS = (
PANIC
NOLOG
) ],
'functions' => [ qw(
functions => [ qw(
logInit
logReinit
logTerm
@ -72,13 +72,14 @@ our %EXPORT_TAGS = (
Panic
) ]
);
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
our @EXPORT = qw();
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our $VERSION = $ZoneMinder::Base::VERSION;
our @EXPORT = qw();
our $VERSION = $ZoneMinder::Base::VERSION;
# ==========================================================================
#
@ -86,43 +87,43 @@ our %EXPORT_TAGS = (
#
# ==========================================================================
use ZoneMinder::Config qw(:all);
use ZoneMinder::Config qw(:all);
use DBI;
use Carp;
use POSIX;
use IO::Handle;
use Data::Dumper;
use Time::HiRes qw/gettimeofday/;
use Sys::Syslog;
use DBI;
use Carp;
use POSIX;
use IO::Handle;
use Data::Dumper;
use Time::HiRes qw/gettimeofday/;
use Sys::Syslog;
use constant {
DEBUG => 1,
INFO => 0,
WARNING => -1,
ERROR => -2,
FATAL => -3,
PANIC => -4,
NOLOG => -5
};
use constant {
DEBUG => 1,
INFO => 0,
WARNING => -1,
ERROR => -2,
FATAL => -3,
PANIC => -4,
NOLOG => -5
};
our %codes = (
&DEBUG => "DBG",
&INFO => "INF",
&WARNING => "WAR",
&ERROR => "ERR",
&FATAL => "FAT",
&PANIC => "PNC",
&NOLOG => "OFF"
&DEBUG => 'DBG',
&INFO => 'INF',
&WARNING => 'WAR',
&ERROR => 'ERR',
&FATAL => 'FAT',
&PANIC => 'PNC',
&NOLOG => 'OFF'
);
our %priorities = (
&DEBUG => "debug",
&INFO => "info",
&WARNING => "warning",
&ERROR => "err",
&FATAL => "err",
&PANIC => "err"
&DEBUG => 'debug',
&INFO => 'info',
&WARNING => 'warning',
&ERROR => 'err',
&FATAL => 'err',
&PANIC => 'err'
);
our $logger;
@ -134,10 +135,10 @@ sub new {
$this->{initialised} = undef;
#$this->{id} = "zmundef";
#$this->{id} = 'zmundef';
( $this->{id} ) = $0 =~ m|^(?:.*/)?([^/]+?)(?:\.[^/.]+)?$|;
$this->{idRoot} = $this->{id};
$this->{idArgs} = "";
$this->{idArgs} = '';
$this->{level} = INFO;
$this->{termLevel} = NOLOG;
@ -151,7 +152,7 @@ sub new {
( $this->{fileName} = $0 ) =~ s|^.*/||;
$this->{logPath} = $Config{ZM_PATH_LOGS};
$this->{logFile} = $this->{logPath}."/".$this->{id}.".log";
$this->{logFile} = $this->{logPath}.'/'.$this->{id}.".log";
$this->{trace} = 0;
@ -196,7 +197,7 @@ sub initialise( @ ) {
$this->{logPath} = $options{logPath} if ( defined($options{logPath}) );
my $tempLogFile;
$tempLogFile = $this->{logPath}."/".$this->{id}.".log";
$tempLogFile = $this->{logPath}.'/'.$this->{id}.".log";
$tempLogFile = $options{logFile} if ( defined($options{logFile}) );
if ( my $logFile = $this->getTargettedEnv('LOG_FILE') ) {
$tempLogFile = $logFile;
@ -231,7 +232,6 @@ sub initialise( @ ) {
my $level;
$tempLevel = $level if ( defined($level = $this->getTargettedEnv('LOG_LEVEL')) );
$tempTermLevel = $level if ( defined($level = $this->getTargettedEnv('LOG_LEVEL_TERM')) );
$tempDatabaseLevel = $level if ( defined($level = $this->getTargettedEnv('LOG_LEVEL_DATABASE')) );
$tempFileLevel = $level if ( defined($level = $this->getTargettedEnv('LOG_LEVEL_FILE')) );
@ -240,9 +240,9 @@ sub initialise( @ ) {
if ( $Config{ZM_LOG_DEBUG} ) {
foreach my $target ( split( /\|/, $Config{ZM_LOG_DEBUG_TARGET} ) ) {
if ( $target eq $this->{id}
|| $target eq "_".$this->{id}
|| $target eq '_'.$this->{id}
|| $target eq $this->{idRoot}
|| $target eq "_".$this->{idRoot}
|| $target eq '_'.$this->{idRoot}
|| $target eq ""
) {
if ( $Config{ZM_LOG_DEBUG_LEVEL} > NOLOG ) {
@ -271,13 +271,13 @@ sub initialise( @ ) {
$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}}
);
}
@ -322,11 +322,11 @@ sub limit {
sub getTargettedEnv {
my $this = shift;
my $name = shift;
my $envName = $name."_".$this->{id};
my $envName = $name.'_'.$this->{id};
my $value;
$value = $ENV{$envName} if ( defined($ENV{$envName}) );
if ( !defined($value) && $this->{id} ne $this->{idRoot} ) {
$envName = $name."_".$this->{idRoot};
$envName = $name.'_'.$this->{idRoot};
$value = $ENV{$envName} if ( defined($ENV{$envName}) );
}
if ( !defined($value) ) {
@ -490,7 +490,7 @@ sub syslogLevel {
sub openSyslog {
my $this = shift;
openlog( $this->{id}, "pid", "local1" );
openlog( $this->{id}, 'pid', "local1" );
}
sub closeSyslog {
@ -523,6 +523,7 @@ sub openFile {
}
} else {
$this->fileLevel( NOLOG );
$this->termLevel( INFO );
Error( "Can't open log file '".$this->{logFile}."': $!" );
}
}
@ -544,10 +545,8 @@ sub logPrint {
my ($seconds, $microseconds) = gettimeofday();
my $message = sprintf(
"%s.%06d %s[%d].%s [%s]"
, strftime( "%x %H:%M:%S"
,localtime( $seconds )
)
'%s.%06d %s[%d].%s [%s]'
, strftime( '%x %H:%M:%S' ,localtime( $seconds ) )
, $microseconds
, $this->{id}
, $$
@ -564,7 +563,7 @@ sub logPrint {
}
print( $LOGFILE $message ) if ( $level <= $this->{fileLevel} );
if ( $level <= $this->{databaseLevel} ) {
my $sql = "insert into Logs ( TimeKey, Component, Pid, Level, Code, Message, File, Line ) values ( ?, ?, ?, ?, ?, ?, ?, NULL )";
my $sql = 'insert into Logs ( TimeKey, Component, Pid, Level, Code, Message, File, Line ) values ( ?, ?, ?, ?, ?, ?, ?, NULL )';
$this->{sth} = $this->{dbh}->prepare_cached( $sql );
if ( !$this->{sth} ) {
$this->{databaseLevel} = NOLOG;
@ -589,7 +588,7 @@ sub logPrint {
sub logInit( ;@ ) {
my %options = @_ ? @_ : ();
$logger = ZoneMinder::Logger->new() if ( !$logger );
$logger = ZoneMinder::Logger->new() if !$logger;
$logger->initialise( %options );
}
@ -646,14 +645,14 @@ sub logSyslogLevel {
sub Mark {
my $level = shift;
$level = DEBUG unless( defined($level) );
my $tag = "Mark";
my $tag = 'Mark';
fetch()->logPrint( $level, $tag );
}
sub Dump {
my $var = shift;
my $label = shift;
$label = "VAR" unless( defined($label) );
$label = 'VAR' unless( defined($label) );
fetch()->logPrint( DEBUG, Data::Dumper->Dump( [ $var ], [ $label ] ) );
}
@ -695,10 +694,10 @@ ZoneMinder::Logger - ZoneMinder Logger module
use ZoneMinder::Logger;
use ZoneMinder::Logger qw(:all);
logInit( "myproc", DEBUG );
logInit( 'myproc', DEBUG );
Debug( "This is what is happening" );
Info( "Something interesting is happening" );
Debug( 'This is what is happening' );
Info( 'Something interesting is happening' );
Warning( "Something might be going wrong." );
Error( "Something has gone wrong!!" );
Fatal( "Something has gone badly wrong, gotta stop!!" );

View File

@ -94,20 +94,11 @@ my $size = '';
my $overwrite = 0;
my $version = 0;
my @formats = split( /\s+/, $Config{ZM_FFMPEG_FORMATS} );
for ( my $i = 0; $i < @formats; $i++ )
{
if ( $i =~ /^(.+)\*$/ )
{
$format = $formats[$i] = $1;
}
}
GetOptions(
'concat|c:s' =>\$concat_name,
'concat|c:s' =>\$concat_name,
'event|e=i' =>\$event_id,
'filter_name=s' =>\$filter_name,
'filter_id=i' =>\$filter_id,
'filter_id=i' =>\$filter_id,
'format|f=s' =>\$format,
'rate|r=f' =>\$rate,
'scale|s=f' =>\$scale,
@ -115,51 +106,51 @@ GetOptions(
'size|S=s' =>\$size,
'overwrite' =>\$overwrite,
'version' =>\$version
) or pod2usage(-exitstatus => -1);
) or pod2usage(-exitstatus => -1);
if ( $version ) {
print ZoneMinder::Base::ZM_VERSION . "\n";
exit(0);
print ZoneMinder::Base::ZM_VERSION . "\n";
exit(0);
}
if ( !( $filter_id or $filter_name or $event_id ) || $event_id < 0 )
{
print( STDERR "Please give a valid event id or filter name\n" );
pod2usage(-exitstatus => -1);
if ( !( $filter_id or $filter_name or $event_id ) || ($event_id and ( $event_id < 0 ) ) ) {
print( STDERR "Please give a valid event id or filter name\n" );
pod2usage(-exitstatus => -1);
}
if ( ! $Config{ZM_OPT_FFMPEG} )
{
print( STDERR "Mpeg encoding is not currently enabled\n" );
exit(-1);
if ( ! $Config{ZM_OPT_FFMPEG} ) {
print( STDERR "Mpeg encoding is not currently enabled\n" );
exit(-1);
}
if ( !$rate && !$fps )
{
$rate = 1;
my @formats = split( /\s+/, $Config{ZM_FFMPEG_FORMATS} );
for ( my $i = 0; $i < @formats; $i++ ) {
if ( $i =~ /^(.+)\*$/ ) {
$format = $formats[$i] = $1;
}
}
if ( !$scale && !$size )
{
$scale = 1;
if ( !$rate && !$fps ) {
$rate = 1;
}
if ( $rate && ($rate < 0.25 || $rate > 100) )
{
print( STDERR "Rate is out of range, 0.25 >= rate <= 100\n" );
pod2usage(-exitstatus => -1);
if ( !$scale && !$size ) {
$scale = 1;
}
if ( $scale && ($scale < 0.25 || $scale > 4) )
{
print( STDERR "Scale is out of range, 0.25 >= scale <= 4\n" );
pod2usage(-exitstatus => -1);
if ( $rate && ($rate < 0.25 || $rate > 100) ) {
print( STDERR "Rate is out of range, 0.25 >= rate <= 100\n" );
pod2usage(-exitstatus => -1);
}
if ( $fps && ($fps > 30) )
{
print( STDERR "FPS is out of range, <= 30\n" );
pod2usage(-exitstatus => -1);
if ( $scale && ($scale < 0.25 || $scale > 4) ) {
print( STDERR "Scale is out of range, 0.25 >= scale <= 4\n" );
pod2usage(-exitstatus => -1);
}
if ( $fps && ($fps > 30) ) {
print( STDERR "FPS is out of range, <= 30\n" );
pod2usage(-exitstatus => -1);
}
my ( $detaint_format ) = $format =~ /^(\w+)$/;
@ -181,19 +172,25 @@ my $cwd = getcwd;
my $video_name;
my @event_ids;
if ( $event_id ) {
@event_ids = ( $event_id );
@event_ids = ( $event_id );
} elsif ( $filter_name or $filter_id ) {
my $Filter = ZoneMinder::Filter->find_one(
($filter_name ? ( Name => $filter_name ) : () ),
($filter_id ? ( Id => $filter_name ) : () ),
);
if ( ! $Filter ) {
Fatal("Filter $filter_name $filter_id not found.");
}
@event_ids = map { $_->{Id} }$Filter->Execute();
Fatal( "No events found for $filter_name") if ! @event_ids;
$concat_name = $filter_name if $concat_name eq '';
my $Filter = ZoneMinder::Filter->find_one(
($filter_name ? ( Name => $filter_name ) : () ),
($filter_id ? ( Id => $filter_name ) : () ),
);
if ( ! $Filter ) {
Fatal("Filter $filter_name $filter_id not found.");
}
@event_ids = map { $_->{Id} } $Filter->Execute();
if ( ! @event_ids ) {
Fatal( "No events found for $filter_name")
} else {
Debug(@event_ids . " events found for $filter_name");
}
$concat_name = $filter_name if $concat_name eq '';
} else {
Warning("Nothing to do");
}
my $sql = " SELECT max(F.Delta)-min(F.Delta) as FullLength,
@ -207,53 +204,54 @@ my $sql = " SELECT max(F.Delta)-min(F.Delta) as FullLength,
INNER JOIN Events as E on F.EventId = E.Id
INNER JOIN Monitors as M on E.MonitorId = M.Id
WHERE EventId = ?
GROUP BY F.EventId"
;
GROUP BY F.EventId";
my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() );
my @video_files;
foreach my $event_id ( @event_ids ) {
my $res = $sth->execute( $event_id )
or Fatal( "Can't execute: ".$sth->errstr() );
my $event = $sth->fetchrow_hashref();
my $res = $sth->execute( $event_id )
or Fatal( "Can't execute: ".$sth->errstr() );
my $event = $sth->fetchrow_hashref();
my $Event = new ZoneMinder::Event( $$event{Id}, $event );
my $video_file = $Event->GenerateVideo( $rate, $fps, $scale, $size, $overwrite, $format );
if ( $video_file ) {
push @video_files, $video_file;
print( STDOUT $video_file."\n" );
}
my $Event = new ZoneMinder::Event( $$event{Id}, $event );
my $video_file = $Event->GenerateVideo( $rate, $fps, $scale, $size, $overwrite, $format );
if ( $video_file ) {
push @video_files, $video_file;
print( STDOUT $video_file."\n" );
} else {
Warning("No video file generated for event $event_id");
}
} # end foreach event_id
if ( $concat_name ) {
($cwd) = $cwd =~ /(.*)/; # detaint
chdir( $cwd );
($concat_name ) = $concat_name =~ /([\-A-Za-z0-9_\.]*)/;
my $concat_list_file = "/tmp/$concat_name.concat.lst";
($cwd) = $cwd =~ /(.*)/; # detaint
chdir( $cwd );
($concat_name ) = $concat_name =~ /([\-A-Za-z0-9_\.]*)/;
my $concat_list_file = "/tmp/$concat_name.concat.lst";
my $video_file = $concat_name . '.'. $detaint_format;
my $video_file = $concat_name . '.'. $detaint_format;
open( my $fd, '>', $concat_list_file ) or die "Can't open $concat_list_file: $!";
foreach ( @video_files ) {
print $fd "file '$_'\n";
}
close $fd;
my $command = $Config{ZM_PATH_FFMPEG}
. " -f concat -i $concat_list_file -c copy "
." '$video_file' > ffmpeg.log 2>&1"
;
Debug( $command."\n" );
my $output = qx($command);
open( my $fd, '>', $concat_list_file ) or die "Can't open $concat_list_file: $!";
foreach ( @video_files ) {
print $fd "file '$_'\n";
}
close $fd;
my $command = $Config{ZM_PATH_FFMPEG}
. " -f concat -i $concat_list_file -c copy "
." '$video_file' > ffmpeg.log 2>&1"
;
Debug( $command."\n" );
my $output = qx($command);
my $status = $? >> 8;
my $status = $? >> 8;
unlink $concat_list_file;
if ( $status )
{
Error( "Unable to generate video, check /ffmpeg.log for details");
exit(-1);
}
print( STDOUT $video_file."\n" );
unlink $concat_list_file;
if ( $status ) {
Error( "Unable to generate video, check /ffmpeg.log for details");
exit(-1);
}
print( STDOUT $video_file."\n" );
}
exit( 0 );
__END__

View File

@ -32,8 +32,8 @@
#include <stdlib.h>
#include <limits.h>
/* Workaround for GNU/kFreeBSD */
#if defined(__FreeBSD_kernel__)
/* Workaround for GNU/kFreeBSD and FreeBSD */
#if defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
#ifndef ENODATA
#define ENODATA ENOATTR
#endif

View File

@ -24,6 +24,10 @@ extern "C" {
#include <libavformat/avformat.h>
}
#ifdef __FreeBSD__
#include <sys/time.h>
#endif // __FreeBSD__
class ZMPacket {
public:

View File

@ -63,13 +63,13 @@ RETSIGTYPE zm_die_handler(int signal)
ucontext_t *uc = (ucontext_t *) context;
cr2 = info->si_addr;
#if defined(__x86_64__)
#ifdef __FreeBSD_kernel__
#if defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
ip = (void *)(uc->uc_mcontext.mc_rip);
#else
ip = (void *)(uc->uc_mcontext.gregs[REG_RIP]);
#endif
#else
#ifdef __FreeBSD_kernel__
#if defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
ip = (void *)(uc->uc_mcontext.mc_eip);
#else
ip = (void *)(uc->uc_mcontext.gregs[REG_EIP]);

View File

@ -37,7 +37,7 @@ if [ "${TRAVIS_EVENT_TYPE}" == "cron" ]; then
# Don't keep packages older than 5 days
find ./zmrepo/$targetfolder/ -maxdepth 1 -type f -mtime +5 -delete
rsync -vzh --ignore-errors build/* zmrepo/$targetfolder/
rsync -vzlh --ignore-errors build/* zmrepo/$targetfolder/
fusermount -zu zmrepo
else
echo

View File

@ -176,8 +176,8 @@ if ( !empty($action) ) {
} else {
Error("No new Id despite new name");
}
$refreshParent = '/index.php?view=filter&Id='.$_REQUEST['Id'];
}
$refreshParent = '/index.php?view=filter&Id='.$_REQUEST['Id'];
}
} // end if canedit events
} // end if action == filter