Merge branch 'storageareas' of github.com:ConnorTechnology/ZoneMinder into storageareas

This commit is contained in:
Isaac Connor 2017-04-09 15:41:40 -04:00
commit 58a0c82015
54 changed files with 2153 additions and 1793 deletions

View File

@ -66,12 +66,23 @@ set(CMAKE_CXX_FLAGS_DEBUG "-Wall -D__STDC_CONSTANT_MACROS -g")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
IF(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
add_definitions (-mfpu=neon)
ELSE(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
ENDIF(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
# GCC below 6.0 doesn't support __target__("fpu=neon") attribute, required for compiling ARM Neon code, otherwise compilation fails.
# Must use -mfpu=neon compiler flag instead, but only do that for processors that support neon, otherwise strip the neon code alltogether,
# because passing -fmpu=neon is unsafe to processors that don't support neon
IF(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm" AND CMAKE_SYSTEM_NAME MATCHES "Linux")
IF(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
EXEC_PROGRAM(grep ARGS " neon " "/proc/cpuinfo" OUTPUT_VARIABLE neonoutput RETURN_VALUE neonresult)
IF(neonresult EQUAL 0)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -mfpu=neon")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mfpu=neon")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -mfpu=neon")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -mfpu=neon")
ELSE(neonresult EQUAL 0)
add_definitions(-DZM_STRIP_NEON=1)
message(STATUS "ARM Neon is not available on this processor. Neon functions will be absent")
ENDIF(neonresult EQUAL 0)
ENDIF(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
ENDIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm" AND CMAKE_SYSTEM_NAME MATCHES "Linux")
# Modules that we need:
include (GNUInstallDirs)

View File

@ -1,2 +1,7 @@
D @ZM_TMPDIR@ 0755 @WEB_USER@ @WEB_GROUP@
D @ZM_TMPDIR@/logs 0755 @WEB_USER@ @WEB_GROUP@
D @ZM_TMPDIR@/cache 0755 @WEB_USER@ @WEB_GROUP@
D @ZM_TMPDIR@/cache/models 0755 @WEB_USER@ @WEB_GROUP@
D @ZM_TMPDIR@/cache/persistent 0755 @WEB_USER@ @WEB_GROUP@
D @ZM_TMPDIR@/cache/views 0755 @WEB_USER@ @WEB_GROUP@
D @ZM_SOCKDIR@ 0755 @WEB_USER@ @WEB_GROUP@

View File

@ -29,7 +29,7 @@
Name: zoneminder
Version: 1.30.2
Release: 1%{?dist}
Release: 2%{?dist}
Summary: A camera monitoring and analysis tool
Group: System Environment/Daemons
# jscalendar is LGPL (any version): http://www.dynarch.com/projects/calendar/
@ -39,7 +39,7 @@ Group: System Environment/Daemons
License: GPLv2+ and LGPLv2+ and MIT
URL: http://www.zoneminder.com/
Source0: https://github.com/ZoneMinder/ZoneMinder/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
Source0: https://github.com/ZoneMinder/ZoneMinder/archive/%{version}.tar.gz#/zoneminder-%{version}.tar.gz
Source1: https://github.com/FriendsOfCake/crud/archive/v%{crud_version}.tar.gz#/crud-%{crud_version}.tar.gz
%{?with_init_systemd:BuildRequires: systemd-devel}
@ -130,8 +130,8 @@ designed to support as many cameras as you can attach to your computer without
too much degradation of performance.
%prep
%autosetup
%autosetup -a 1
%autosetup -n ZoneMinder-%{version}
%autosetup -a 1 -n ZoneMinder-%{version}
rmdir ./web/api/app/Plugin/Crud
mv -f crud-%{crud_version} ./web/api/app/Plugin/Crud
@ -336,8 +336,11 @@ rm -rf %{_docdir}/%{name}-%{version}
%dir %attr(755,%{zmuid_final},%{zmgid_final}) %ghost %{_localstatedir}/run/zoneminder
%changelog
* Thu Mar 30 2017 Andrew Bauer <zonexpertconsulting@outlook.com> - 1.30.2-2
- 1.30.2 release
* Wed Feb 08 2017 Andrew Bauer <zonexpertconsulting@outlook.com> - 1.30.2-1
- Bump version for 1.30.2 release
- Bump version for 1.30.2 release candidate 1
* Wed Dec 28 2016 Andrew Bauer <zonexpertconsulting@outlook.com> - 1.30.1-2
- Changes from rpmfusion #4393

View File

@ -37,7 +37,7 @@ Package: zoneminder
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, ${perl:Depends}
,javascript-common
,libmp4v2-2, libx264-142|libx264-148, libswscale-ffmpeg3|libswscale4
,libmp4v2-2, libx264-142|libx264-148, libswscale-ffmpeg3|libswscale4|libswscale3
,ffmpeg | libav-tools
,libdate-manip-perl, libmime-lite-perl, libmime-tools-perl
,libdbd-mysql-perl

View File

@ -1,3 +1,4 @@
/var/cache/zoneminder/events /usr/share/zoneminder/www/events
/var/cache/zoneminder/images /usr/share/zoneminder/www/images
/var/cache/zoneminder/temp /usr/share/zoneminder/www/temp
/var/tmp /usr/share/zoneminder/www/api/app/tmp

View File

@ -1,2 +1,6 @@
d /var/run/zm 0755 www-data www-data
d /tmp/zm 0755 www-data www-data
d /var/run/zm 0755 www-data www-data
d /tmp/zm 0755 www-data www-data
d /var/tmp/zm 0755 www-data www-data
d /var/tmp/cache 0755 www-data www-data
d /var/tmp/cache/models 0755 www-data www-data
d /var/tmp/cache/persistent 0755 www-data www-data

View File

@ -12,7 +12,7 @@ Type=forking
ExecStart=@BINDIR@/zmpkg.pl start
ExecReload=@BINDIR@/zmpkg.pl restart
ExecStop=@BINDIR@/zmpkg.pl stop
PIDFile="@ZM_RUNDIR@/zm.pid"
PIDFile=@ZM_RUNDIR@/zm.pid
Environment=TZ=:/etc/localtime
[Install]

View File

@ -354,6 +354,26 @@ our @options = (
type => $types{boolean},
category => 'system',
},
{
name => 'ZM_ENABLE_CSRF_MAGIC',
default => 'no',
description => 'Enable csrf-magic library',
help => q`
CSRF stands for Cross-Site Request Forgery which, under specific
circumstances, can allow an attacker to perform any task your
ZoneMinder user account has permission to perform. To accomplish
this, the attacker must write a very specific web page and get
you to navigate to it, while you are logged into the ZoneMinder
web console at the same time. Enabling ZM_ENABLE_CSRF_MAGIC will
help mitigate these kinds of attackes. Be warned this feature
is experimental and may cause problems, particularly with the API.
If you find a false positive and can document how to reproduce it,
then please report it. This feature defaults to OFF currently due to
its experimental nature.
`,
type => $types{boolean},
category => 'system',
},
{
name => 'ZM_OPT_USE_API',
default => 'yes',

View File

@ -241,6 +241,7 @@ sub GenerateVideo {
sub delete {
my $event = $_[0];
Info( "Deleting event $event->{Id} from Monitor $event->{MonitorId} $event->{StartTime}\n" );
$ZoneMinder::Database::dbh->ping();
# Do it individually to avoid locking up the table for new events
my $sql = 'delete from Events where Id = ?';
my $sth = $ZoneMinder::Database::dbh->prepare_cached( $sql )
@ -331,12 +332,15 @@ sub delete_files {
sub Storage {
return new ZoneMinder::Storage( $_[0]{StorageId} );
}
sub check_for_in_filesystem {
my $path = $_[0]->Path();
if ( $path ) {
my @files = glob( $path . '/*' );
Debug("Checking for files for event $_[0]{Id} at $path using glob $path/* found " . scalar @files . " files");
return 1 if @files;
}
Debug("Checking for files for event $_[0]{Id} at $path using glob $path/* found no files");
return 0;
}

View File

@ -254,14 +254,14 @@ sub Sql {
} # end if terms
if ( $self->{Sql} ) {
if ( $self->{AutoMessage} ) {
#if ( $self->{AutoMessage} ) {
# Include all events, including events that are still ongoing
# and have no EndTime yet
$sql .= " and ( ".$self->{Sql}." )";
} else {
#} else {
# Only include closed events (events with valid EndTime)
$sql .= " where not isnull(E.EndTime) and ( ".$self->{Sql}." )";
}
#$sql .= " where not isnull(E.EndTime) and ( ".$self->{Sql}." )";
#}
}
my @auto_terms;
if ( $self->{AutoArchive} ) {

View File

@ -179,7 +179,7 @@ sub runCommand {
sub getEventPath {
my $event = shift;
my $Storage = new ZoneMinder::Storage( $$event{Id} );
my $Storage = new ZoneMinder::Storage( $$event{StorageId} );
my $event_path = join( '/',
$Storage->Path(),
$event->{MonitorId},

View File

@ -0,0 +1,358 @@
# ==========================================================================
#
# ZoneMinder ONVIF Module, $Date$, $Revision$
# Copyright (C) 2001-2008 Philip Coombes
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# ==========================================================================
#
# This module contains the common definitions and functions used by the rest
# of the ZoneMinder scripts
#
package ZoneMinder::ONVIF;
use 5.006;
use strict;
use warnings;
require Exporter;
require ZoneMinder::Base;
our @ISA = qw(Exporter);
our %EXPORT_TAGS = (
functions => [ qw(
) ]
);
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw();
our $VERSION = $ZoneMinder::Base::VERSION;
use Getopt::Std;
use Data::UUID;
require ONVIF::Client;
require WSDiscovery10::Interfaces::WSDiscovery::WSDiscoveryPort;
require WSDiscovery10::Elements::Header;
require WSDiscovery10::Elements::Types;
require WSDiscovery10::Elements::Scopes;
require WSDiscovery::TransportUDP;
sub deserialize_message {
my ($wsdl_client, $response) = @_;
# copied and adapted from SOAP::WSDL::Client
# get deserializer
my $deserializer = $wsdl_client->get_deserializer();
if(! $deserializer) {
$deserializer = SOAP::WSDL::Factory::Deserializer->get_deserializer({
soap_version => $wsdl_client->get_soap_version(),
%{ $wsdl_client->get_deserializer_args() },
});
}
# set class resolver if serializer supports it
$deserializer->set_class_resolver( $wsdl_client->get_class_resolver() )
if ( $deserializer->can('set_class_resolver') );
# Try deserializing response - there may be some,
# even if transport did not succeed (got a 500 response)
if ( $response ) {
# as our faults are false, returning a success marker is the only
# reliable way of determining whether the deserializer succeeded.
# Custom deserializers may return an empty list, or undef,
# and $@ is not guaranteed to be undefined.
my ($success, $result_body, $result_header) = eval {
(1, $deserializer->deserialize( $response ));
};
if (defined $success) {
return wantarray
? ($result_body, $result_header)
: $result_body;
}
elsif (blessed $@) { #}&& $@->isa('SOAP::WSDL::SOAP::Typelib::Fault11')) {
return $@;
}
else {
return $deserializer->generate_fault({
code => 'soap:Server',
role => 'urn:localhost',
message => "Error deserializing message: $@. \n"
. "Message was: \n$response"
});
}
};
}
ub interpret_messages {
my ($svc_discover, $services, @responses ) = @_;
my @results;
foreach my $response ( @responses ) {
if($verbose) {
print "Received message:\n" . $response . "\n";
}
my $result = deserialize_message($svc_discover, $response);
if(not $result) {
print "Error deserializing message. No message returned from deserializer.\n" if $verbose;
next;
}
my $xaddr;
foreach my $l_xaddr (split ' ', $result->get_ProbeMatch()->get_XAddrs()) {
# find IPv4 address
print "l_xaddr = $l_xaddr\n" if $verbose;
if($l_xaddr =~ m|//[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+[:/]|) {
$xaddr = $l_xaddr;
last;
} else {
print STDERR "Unable to find IPv4 address from xaddr $l_xaddr\n";
}
}
# No usable address found
next if not $xaddr;
# ignore multiple responses from one service
next if defined $services->{$xaddr};
$services->{$xaddr} = 1;
print "$xaddr, " . $svc_discover->get_soap_version() . ", ";
print "(";
my $scopes = $result->get_ProbeMatch()->get_Scopes();
my $count = 0;
my %scopes;
foreach my $scope(split ' ', $scopes) {
if($scope =~ m|onvif://www\.onvif\.org/(.+)/(.*)|) {
my ($attr, $value) = ($1,$2);
if( 0 < $count ++) {
print ", ";
}
print $attr . "=\'" . $value . "\'";
$scopes{$attr} = $value;
}
}
print ")\n";
push @results, { xaddr=>$xaddr,
soap_version => $svc_discover->get_soap_version(),
scopes => \%scopes,
};
}
return @results;
} # end sub interpret_messages
# functions
sub discover {
my @results;
## collect all responses
my @responses = ();
no warnings 'redefine';
*WSDiscovery::TransportUDP::_notify_response = sub {
my ($transport, $response) = @_;
push @responses, $response;
};
## try both soap versions
my %services;
my $uuid_gen = Data::UUID->new();
if ( ( ! $soap_version ) or ( $soap_version eq '1.1' ) ) {
if($verbose) {
print "Probing for SOAP 1.1\n"
}
my $svc_discover = WSDiscovery10::Interfaces::WSDiscovery::WSDiscoveryPort->new({
# no_dispatch => '1',
});
$svc_discover->set_soap_version('1.1');
my $uuid = $uuid_gen->create_str();
my $result = $svc_discover->ProbeOp(
{ # WSDiscovery::Types::ProbeType
Types => 'http://www.onvif.org/ver10/network/wsdl:NetworkVideoTransmitter http://www.onvif.org/ver10/device/wsdl:Device', # QNameListType
Scopes => { value => '' },
},
WSDiscovery10::Elements::Header->new({
Action => { value => 'http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe' },
MessageID => { value => "urn:uuid:$uuid" },
To => { value => 'urn:schemas-xmlsoap-org:ws:2005:04:discovery' },
})
);
print $result . "\n" if $verbose;
push @results, interpret_messages($svc_discover, \%services, @responses);
@responses = ();
} # end if doing soap 1.1
if ( ( ! $soap_version ) or ( $soap_version eq '1.2' ) ) {
if($verbose) {
print "Probing for SOAP 1.2\n"
}
my $svc_discover = WSDiscovery10::Interfaces::WSDiscovery::WSDiscoveryPort->new({
# no_dispatch => '1',
});
$svc_discover->set_soap_version('1.2');
# copies of the same Probe message must have the same MessageID.
# This is not a copy. So we generate a new uuid.
my $uuid = $uuid_gen->create_str();
# Everyone else, like the nodejs onvif code and odm only ask for NetworkVideoTransmitter
my $result = $svc_discover->ProbeOp(
{ # WSDiscovery::Types::ProbeType
xmlattr => { 'xmlns:dn' => 'http://www.onvif.org/ver10/network/wsdl', },
Types => 'dn:NetworkVideoTransmitter', # QNameListType
Scopes => { value => '' },
},
WSDiscovery10::Elements::Header->new({
Action => { value => 'http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe' },
MessageID => { value => "urn:uuid:$uuid" },
To => { value => 'urn:schemas-xmlsoap-org:ws:2005:04:discovery' },
})
);
print $result . "\n" if $verbose;
push @results, interpret_messages($svc_discover, \%services, @responses);
} # end if doing soap 1.2
return @results;
}
sub profiles {
my $result = $client->get_endpoint('media')->GetProfiles( { } ,, );
die $result if not $result;
if($verbose) {
print "Received message:\n" . $result . "\n";
}
my $profiles = $result->get_Profiles();
foreach my $profile ( @{ $profiles } ) {
my $token = $profile->attr()->get_token() ;
print $token . ", " .
$profile->get_Name() . ", " .
$profile->get_VideoEncoderConfiguration()->get_Encoding() . ", " .
$profile->get_VideoEncoderConfiguration()->get_Resolution()->get_Width() . ", " .
$profile->get_VideoEncoderConfiguration()->get_Resolution()->get_Height() . ", " .
$profile->get_VideoEncoderConfiguration()->get_RateControl()->get_FrameRateLimit() .
", ";
# Specification gives conflicting values for unicast stream types, try both.
# http://www.onvif.org/onvif/ver10/media/wsdl/media.wsdl#op.GetStreamUri
foreach my $streamtype ( 'RTP_unicast', 'RTP-Unicast' ) {
$result = $client->get_endpoint('media')->GetStreamUri( {
StreamSetup => { # ONVIF::Media::Types::StreamSetup
Stream => $streamtype, # StreamType
Transport => { # ONVIF::Media::Types::Transport
Protocol => 'RTSP', # TransportProtocol
},
},
ProfileToken => $token, # ReferenceToken
} ,, );
last if $result;
}
die $result if not $result;
# print $result . "\n";
print $result->get_MediaUri()->get_Uri() .
"\n";
} # end foreach profile
#
# use message parser without schema validation ???
#
}
sub move {
my ($dir) = @_;
my $result = $client->get_endpoint('ptz')->GetNodes( { } ,, );
die $result if not $result;
print $result . "\n";
} # end sub move
sub metadata {
my $result = $client->get_endpoint('media')->GetMetadataConfigurations( { } ,, );
die $result if not $result;
print $result . "\n";
$result = $client->get_endpoint('media')->GetVideoAnalyticsConfigurations( { } ,, );
die $result if not $result;
print $result . "\n";
# $result = $client->get_endpoint('analytics')->GetServiceCapabilities( { } ,, );
# die $result if not $result;
# print $result . "\n";
}
1;
__END__
=head1 NAME
ZoneMinder::ONVIF - perl module to access onvif functions for ZoneMinder
=head1 SYNOPSIS
use ZoneMinder::ONVIF;
=head1 DESCRIPTION
This is a module to contain useful functions and import all the other modules
required for ONVIF to work.
=head2 EXPORT
None by default.
=head1 SEE ALSO
http://www.zoneminder.com
=head1 AUTHOR
Philip Coombes, E<lt>philip.coombes@zoneminder.comE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2001-2008 Philip Coombes
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.3 or,
at your option, any later version of Perl 5 you may have available.
=cut

View File

@ -45,70 +45,69 @@ use ZoneMinder::Database qw(:all);
use vars qw/ $AUTOLOAD /;
sub new {
my ( $parent, $id, $data ) = @_;
my ( $parent, $id, $data ) = @_;
my $self = {};
bless $self, $parent;
no strict 'refs';
my $primary_key = ${$parent.'::primary_key'};
if ( ! $primary_key ) {
Error( 'NO primary_key for type ' . $parent );
return;
} # end if
if ( ( $$self{$primary_key} = $id ) or $data ) {
my $self = {};
bless $self, $parent;
no strict 'refs';
my $primary_key = ${$parent.'::primary_key'};
if ( ! $primary_key ) {
Error( 'NO primary_key for type ' . $parent );
return;
} # end if
if ( ( $$self{$primary_key} = $id ) or $data ) {
#$log->debug("loading $parent $id") if $debug or DEBUG_ALL;
$self->load( $data );
}
return $self;
$self->load( $data );
}
return $self;
} # end sub new
sub load {
my ( $self, $data ) = @_;
my $type = ref $self;
if ( ! $data ) {
no strict 'refs';
my $table = ${$type.'::table'};
if ( ! $table ) {
Error( 'NO table for type ' . $type );
return;
} # end if
my $primary_key = ${$type.'::primary_key'};
if ( ! $primary_key ) {
Error( 'NO primary_key for type ' . $type );
return;
} # end if
my ( $self, $data ) = @_;
my $type = ref $self;
if ( ! $data ) {
no strict 'refs';
my $table = ${$type.'::table'};
if ( ! $table ) {
Error( 'NO table for type ' . $type );
return;
} # end if
my $primary_key = ${$type.'::primary_key'};
if ( ! $primary_key ) {
Error( 'NO primary_key for type ' . $type );
return;
} # end if
if ( ! $$self{$primary_key} ) {
my ( $caller, undef, $line ) = caller;
Error( (ref $self) . "::load called without $primary_key from $caller:$line");
} else {
#$log->debug("Object::load Loading from db $type");
Debug("Loading $type from $table WHERE $primary_key = $$self{$primary_key}");
$data = $ZoneMinder::Database::dbh->selectrow_hashref( "SELECT * FROM $table WHERE $primary_key=?", {}, $$self{$primary_key} );
if ( ! $data ) {
if ( $ZoneMinder::Database::dbh->errstr ) {
Error( "Failure to load Object record for $$self{$primary_key}: Reason: " . $ZoneMinder::Database::dbh->errstr );
} else {
Debug("No Results Loading $type from $table WHERE $primary_key = $$self{$primary_key}");
} # end if
} # end if
} # end if
} # end if ! $data
if ( $data and %$data ) {
@$self{keys %$data} = values %$data;
} # end if
if ( ! $$self{$primary_key} ) {
my ( $caller, undef, $line ) = caller;
Error( (ref $self) . "::load called without $primary_key from $caller:$line");
} else {
#$log->debug("Object::load Loading from db $type");
Debug("Loading $type from $table WHERE $primary_key = $$self{$primary_key}");
$data = $ZoneMinder::Database::dbh->selectrow_hashref( "SELECT * FROM $table WHERE $primary_key=?", {}, $$self{$primary_key} );
if ( ! $data ) {
if ( $ZoneMinder::Database::dbh->errstr ) {
Error( "Failure to load Object record for $$self{$primary_key}: Reason: " . $ZoneMinder::Database::dbh->errstr );
} else {
Debug("No Results Loading $type from $table WHERE $primary_key = $$self{$primary_key}");
} # end if
} # end if
} # end if
} # end if ! $data
if ( $data and %$data ) {
@$self{keys %$data} = values %$data;
} # end if
} # end sub load
sub AUTOLOAD {
my ( $self, $newvalue ) = @_;
my $type = ref($_[0]);
my $name = $AUTOLOAD;
$name =~ s/.*://;
if ( @_ > 1 ) {
return $_[0]{$name} = $_[1];
}
return $_[0]{$name};
my ( $self, $newvalue ) = @_;
my $type = ref($_[0]);
my $name = $AUTOLOAD;
$name =~ s/.*://;
if ( @_ > 1 ) {
return $_[0]{$name} = $_[1];
}
return $_[0]{$name};
}

View File

@ -271,7 +271,7 @@ MAIN: while( $loop ) {
} # if USE_DEEP_STORAGE
Debug( 'Got '.int(keys(%$fs_events))." events for monitor $monitor_dir\n" );
delete_empty_directories( $monitor_dir );
#delete_empty_directories( $monitor_dir );
} # end foreach monitor
redo MAIN if ( $cleaned );
@ -338,7 +338,10 @@ MAIN: while( $loop ) {
my $deleteStatsSth = $dbh->prepare_cached( $deleteStatsSql )
or Fatal( "Can't prepare '$deleteStatsSql': ".$dbh->errstr() );
# Foreach database monitor and it's list of events.
while ( my ( $db_monitor, $db_events ) = each(%$db_monitors) ) {
# If we found the monitor in the file system
if ( my $fs_events = $fs_monitors->{$db_monitor} ) {
next if ! $db_events;
@ -355,7 +358,7 @@ Debug("Event $db_event is not in fs.");
next;
}
if ( $Event->check_for_in_filesystem() ) {
Debug('Database events apparent exists at ' . $Event->Path() );
Debug('Database events apparently exists at ' . $Event->Path() );
} else {
if ( $age > $Config{ZM_AUDIT_MIN_AGE} ) {
aud_print( "Database event '$db_monitor/$db_event' does not exist at " . $Event->Path().' in filesystem' );
@ -657,6 +660,7 @@ sub deleteSwapImage {
sub delete_empty_directories {
my $DIR;
Debug("delete_empty_directories $_[0]");
if ( ! opendir( $DIR, $_[0] ) ) {
Error( "delete_empty_directories: Can't open directory '".getcwd()."/$_[0]': $!" );
return;

View File

@ -209,6 +209,7 @@ use ZoneMinder;
use POSIX;
use Socket;
use IO::Handle;
use Time::HiRes qw(usleep);
#use Data::Dumper;
our %cmd_hash;
@ -456,20 +457,25 @@ sub send_stop {
} # end sub send_stop
sub kill_until_dead {
my ( $process ) = @_;
# Now check it has actually gone away, if not kill -9 it
my $count = 0;
while( $process and $$process{pid} and kill( 0, $$process{pid} ) ) {
if ( $count++ > 5 ) {
dPrint( ZoneMinder::Logger::WARNING, "'$$process{command}' has not stopped at "
.strftime( '%y/%m/%d %H:%M:%S', localtime() )
.". Sending KILL to pid $$process{pid}\n"
);
kill( 'KILL', $$process{pid} );
}
sleep( 1 );
my ( $process ) = @_;
# Now check it has actually gone away, if not kill -9 it
my $count = 0;
my $sigset = POSIX::SigSet->new;
my $blockset = POSIX::SigSet->new(SIGCHLD);
sigprocmask(SIG_BLOCK, $blockset, $sigset ) or die "dying at block...\n";
while( $process and $$process{pid} and kill( 0, $$process{pid} ) ) {
if ( $count++ > 50 ) {
dPrint( ZoneMinder::Logger::WARNING, "'$$process{command}' has not stopped at "
.strftime( '%y/%m/%d %H:%M:%S', localtime() )
.". Sending KILL to pid $$process{pid}\n"
);
kill( 'KILL', $$process{pid} );
}
sigprocmask(SIG_UNBLOCK, $blockset) or die "dying at unblock...\n";
usleep( 100 );
sigprocmask(SIG_BLOCK, $blockset, $sigset ) or die "dying at block...\n";
}
}
sub _stop {

View File

@ -42,8 +42,7 @@ FfmpegCamera::FfmpegCamera( int p_id, const std::string &p_path, const std::stri
mMethod( p_method ),
mOptions( p_options )
{
if ( capture )
{
if ( capture ) {
Initialise();
}
@ -83,20 +82,19 @@ FfmpegCamera::FfmpegCamera( int p_id, const std::string &p_path, const std::stri
}
FfmpegCamera::~FfmpegCamera()
{
FfmpegCamera::~FfmpegCamera() {
if ( videoStore ) {
delete videoStore;
}
CloseFfmpeg();
if ( capture )
{
if ( capture ) {
Terminate();
}
}
void FfmpegCamera::Initialise()
{
void FfmpegCamera::Initialise() {
if ( logDebugging() )
av_log_set_level( AV_LOG_DEBUG );
else
@ -106,12 +104,10 @@ void FfmpegCamera::Initialise()
avformat_network_init();
}
void FfmpegCamera::Terminate()
{
void FfmpegCamera::Terminate() {
}
int FfmpegCamera::PrimeCapture()
{
int FfmpegCamera::PrimeCapture() {
mVideoStreamId = -1;
mAudioStreamId = -1;
Info( "Priming capture from %s", mPath.c_str() );
@ -434,6 +430,10 @@ int FfmpegCamera::OpenFfmpeg() {
Fatal( "You must compile ffmpeg with the --enable-swscale option to use ffmpeg cameras" );
#endif // HAVE_LIBSWSCALE
if ( mVideoCodecContext->width != width || mVideoCodecContext->height != height ) {
Warning( "Monitor dimensions are %dx%d but camera is sending %dx%d", width, height, mVideoCodecContext->width, mVideoCodecContext->height );
}
mCanCapture = true;
return 0;
@ -675,16 +675,22 @@ Debug(5, "After av_read_frame (%d)", ret );
videoStore = NULL;
}
//Buffer video packets, since we are not recording. All audio packets are keyframes, so only if it's a video keyframe
// Buffer video packets, since we are not recording.
// All audio packets are keyframes, so only if it's a video keyframe
if ( packet.stream_index == mVideoStreamId) {
if ( key_frame ) {
Debug(3, "Clearing queue");
packetqueue.clearQueue();
}
if ( packet.pts && video_last_pts > packet.pts ) {
Warning( "Clearing queue due to out of order pts");
}
#if 0
// Not sure this is valid. While a camera will PROBABLY always have an increasing pts... it doesn't have to.
// Also, I think there are integer wrap-around issues.
else if ( packet.pts && video_last_pts > packet.pts ) {
Warning( "Clearing queue due to out of order pts packet.pts(%d) < video_last_pts(%d)");
packetqueue.clearQueue();
}
#endif
}
if (

File diff suppressed because it is too large Load Diff

View File

@ -299,6 +299,9 @@ void std_convert_argb_gray8(const uint8_t* col1, uint8_t* result, unsigned long
void std_convert_abgr_gray8(const uint8_t* col1, uint8_t* result, unsigned long count);
void std_convert_yuyv_gray8(const uint8_t* col1, uint8_t* result, unsigned long count);
void ssse3_convert_rgba_gray8(const uint8_t* col1, uint8_t* result, unsigned long count);
void ssse3_convert_bgra_gray8(const uint8_t* col1, uint8_t* result, unsigned long count);
void ssse3_convert_argb_gray8(const uint8_t* col1, uint8_t* result, unsigned long count);
void ssse3_convert_abgr_gray8(const uint8_t* col1, uint8_t* result, unsigned long count);
void ssse3_convert_yuyv_gray8(const uint8_t* col1, uint8_t* result, unsigned long count);
void zm_convert_yuyv_rgb(const uint8_t* col1, uint8_t* result, unsigned long count);
void zm_convert_yuyv_rgba(const uint8_t* col1, uint8_t* result, unsigned long count);
@ -315,8 +318,3 @@ void std_deinterlace_4field_rgba(uint8_t* col1, uint8_t* col2, unsigned int thre
void std_deinterlace_4field_bgra(uint8_t* col1, uint8_t* col2, unsigned int threshold, unsigned int width, unsigned int height);
void std_deinterlace_4field_argb(uint8_t* col1, uint8_t* col2, unsigned int threshold, unsigned int width, unsigned int height);
void std_deinterlace_4field_abgr(uint8_t* col1, uint8_t* col2, unsigned int threshold, unsigned int width, unsigned int height);
void ssse3_deinterlace_4field_gray8(uint8_t* col1, uint8_t* col2, unsigned int threshold, unsigned int width, unsigned int height);
void ssse3_deinterlace_4field_rgba(uint8_t* col1, uint8_t* col2, unsigned int threshold, unsigned int width, unsigned int height);
void ssse3_deinterlace_4field_bgra(uint8_t* col1, uint8_t* col2, unsigned int threshold, unsigned int width, unsigned int height);
void ssse3_deinterlace_4field_argb(uint8_t* col1, uint8_t* col2, unsigned int threshold, unsigned int width, unsigned int height);
void ssse3_deinterlace_4field_abgr(uint8_t* col1, uint8_t* col2, unsigned int threshold, unsigned int width, unsigned int height);

View File

@ -638,6 +638,7 @@ Monitor::~Monitor() {
close( map_fd );
if ( purpose == CAPTURE ) {
// How about we store this in the object on instantiation so that we don't have to do this again.
char mmap_path[PATH_MAX] = "";
snprintf( mmap_path, sizeof(mmap_path), "%s/zm.mmap.%d", config.path_map, id );
@ -1379,7 +1380,8 @@ bool Monitor::Analyse() {
}
}
} // end if section_length
if ( !event ) {
if ( ! event ) {
// Create event
event = new Event( this, *timestamp, "Continuous", noteSetMap, videoRecording );
@ -1442,7 +1444,7 @@ bool Monitor::Analyse() {
}
event->AddFrames( pre_event_images, images, timestamps );
}
}
} // end if false or config.overlap_timed_events
} // end if ! event
}
if ( score ) {
@ -1618,7 +1620,8 @@ bool Monitor::Analyse() {
}
shared_data->state = state = IDLE;
last_section_mod = 0;
}
} // end if ( trigger_data->trigger_state != TRIGGER_OFF )
if ( (!signal_change && signal) && (function == MODECT || function == MOCORD) ) {
if ( state == ALARM ) {
ref_image.Blend( *snap_image, alarm_ref_blend_perc );
@ -1627,9 +1630,9 @@ bool Monitor::Analyse() {
}
}
last_signal = signal;
}
} // end if Enabled()
shared_data->last_read_index = index%image_buffer_count;
shared_data->last_read_index = index % image_buffer_count;
//shared_data->last_read_time = image_buffer[index].timestamp->tv_sec;
shared_data->last_read_time = now.tv_sec;
@ -3584,7 +3587,7 @@ bool MonitorStream::sendFrame( const char *filepath, struct timeval *timestamp )
fprintf( stdout, "Content-Length: %d\r\n", img_buffer_size );
fprintf( stdout, "Content-Type: image/jpeg\r\n\r\n" );
if ( fwrite( img_buffer, img_buffer_size, 1, stdout ) != 1 ) {
if ( !zm_terminate )
if ( ! zm_terminate )
Error( "Unable to send stream frame: %s", strerror(errno) );
return( false );
}
@ -3678,7 +3681,7 @@ bool MonitorStream::sendFrame( Image *image, struct timeval *timestamp ) {
}
last_frame_sent = TV_2_FLOAT( now );
return( true );
}
} // end bool MonitorStream::sendFrame( Image *image, struct timeval *timestamp )
void MonitorStream::runStream() {
if ( type == STREAM_SINGLE ) {
@ -3804,7 +3807,7 @@ void MonitorStream::runStream() {
if ( temp_index%frame_mod == 0 ) {
Debug( 2, "Sending delayed frame %d", temp_index );
// Send the next frame
if ( !sendFrame( temp_image_buffer[temp_index].file_name, &temp_image_buffer[temp_index].timestamp ) )
if ( ! sendFrame( temp_image_buffer[temp_index].file_name, &temp_image_buffer[temp_index].timestamp ) )
zm_terminate = true;
memcpy( &last_frame_timestamp, &(swap_image->timestamp), sizeof(last_frame_timestamp) );
//frame_sent = true;

View File

@ -267,7 +267,7 @@ int RemoteCameraHttp::ReadData( Buffer &buffer, unsigned int bytes_expected ) {
Debug( 2, "Socket closed" );
//Disconnect(); // Disconnect is done outside of ReadData now.
return( -1 );
} else if ( bytes_read < total_bytes_to_read ) {
} else if ( (unsigned int)bytes_read < total_bytes_to_read ) {
Error( "Incomplete read, expected %d, got %d", total_bytes_to_read, bytes_read );
return( -1 );
}

View File

@ -250,30 +250,50 @@ void hwcaps_detect() {
/* x86 or x86-64 processor */
uint32_t r_edx, r_ecx, r_ebx;
#ifdef __x86_64__
__asm__ __volatile__(
"push %%rbx\n\t"
"mov $0x0,%%ecx\n\t"
"mov $0x7,%%eax\n\t"
"cpuid\n\t"
#ifdef __x86_64__
"push %%rbx\n\t"
#else
"push %%ebx\n\t"
#endif
"mov $0x1,%%eax\n\t"
"cpuid\n\t"
#ifdef __x86_64__
"pop %%rax\n\t"
"pop %%rbx\n\t"
#else
"pop %%ebx\n\t"
#endif
: "=d" (r_edx), "=c" (r_ecx), "=b" (r_ebx)
: "=d" (r_edx), "=c" (r_ecx), "=a" (r_ebx)
:
:
: "%eax"
);
#else
__asm__ __volatile__(
"push %%ebx\n\t"
"mov $0x0,%%ecx\n\t"
"mov $0x7,%%eax\n\t"
"cpuid\n\t"
"push %%ebx\n\t"
"mov $0x1,%%eax\n\t"
"cpuid\n\t"
"pop %%eax\n\t"
"pop %%ebx\n\t"
: "=d" (r_edx), "=c" (r_ecx), "=a" (r_ebx)
:
:
);
#endif
if (r_ebx & 0x00000020) {
sseversion = 52; /* AVX2 */
Debug(1,"Detected a x86\\x86-64 processor with AVX2");
} else if (r_ecx & 0x10000000) {
sseversion = 51; /* AVX */
Debug(1,"Detected a x86\\x86-64 processor with AVX");
} else if (r_ecx & 0x00100000) {
sseversion = 42; /* SSE4.2 */
Debug(1,"Detected a x86\\x86-64 processor with SSE4.2");
} else if (r_ecx & 0x00080000) {
sseversion = 41; /* SSE4.1 */
Debug(1,"Detected a x86\\x86-64 processor with SSE4.1");
} else if (r_ecx & 0x00000200) {
sseversion = 35; /* SSSE3 */
Debug(1,"Detected a x86\\x86-64 processor with SSSE3");

View File

@ -444,11 +444,12 @@ if ( audio_output_stream ) {
av_make_error_string(ret).c_str());
}
prevDts = 0;
video_start_pts = 0;
video_start_dts = 0;
audio_start_pts = 0;
audio_start_dts = 0;
video_last_pts = 0;
video_last_dts = 0;
audio_last_pts = 0;
audio_last_dts = 0;
previous_pts = 0;
previous_dts = 0;
filter_in_rescale_delta_last = AV_NOPTS_VALUE;
@ -551,45 +552,63 @@ void VideoStore::dumpPacket( AVPacket *pkt ){
}
int VideoStore::writeVideoFramePacket( AVPacket *ipkt ) {
Debug(4, "writeVideoFrame init_packet");
av_init_packet(&opkt);
if ( 1 ) {
//Scale the PTS of the outgoing packet to be the correct time base
if (ipkt->pts != AV_NOPTS_VALUE) {
if ( (!video_start_pts) || (video_start_pts > ipkt->pts) ) {
Debug(1, "Resetting video_start_pts from (%d) to (%d)", video_start_pts, ipkt->pts );
//never gets set, so the first packet can set it.
video_start_pts = ipkt->pts;
if ( ! video_last_pts ) {
// This is the first packet.
opkt.pts = 0;
Debug(2, "Starting video video_last_pts will become (%d)", ipkt->pts );
} else {
if ( ipkt->pts < video_last_pts ) {
Debug(1, "Resetting video_last_pts from (%d) to (%d)", video_last_pts, ipkt->pts );
// wrap around, need to figure out the distance FIXME having this wrong should cause a jump, but then play ok?
opkt.pts = previous_pts + av_rescale_q( ipkt->pts, video_input_stream->time_base, video_output_stream->time_base);
} else {
opkt.pts = previous_pts + av_rescale_q( ipkt->pts - video_last_pts, video_input_stream->time_base, video_output_stream->time_base);
}
}
opkt.pts = av_rescale_q(ipkt->pts - video_start_pts, video_input_stream->time_base, video_output_stream->time_base);
//- ost_tb_start_time;
Debug(3, "opkt.pts = %d from ipkt->pts(%d) - startPts(%d)", opkt.pts, ipkt->pts, video_start_pts );
Debug(3, "opkt.pts = %d from ipkt->pts(%d) - last_pts(%d)", opkt.pts, ipkt->pts, video_last_pts );
video_last_pts = ipkt->pts;
} else {
Debug(3, "opkt.pts = undef");
opkt.pts = AV_NOPTS_VALUE;
}
//Scale the DTS of the outgoing packet to be the correct time base
if(ipkt->dts == AV_NOPTS_VALUE) {
// why are we using cur_dts instead of packet.dts?
if ( (!video_start_dts) || (video_start_dts > video_input_stream->cur_dts) ) {
Debug(1, "Resetting video_start_dts from (%d) to (%d) p.dts was (%d)", video_start_dts, video_input_stream->cur_dts, ipkt->dts );
video_start_dts = video_input_stream->cur_dts;
}
opkt.dts = av_rescale_q(video_input_stream->cur_dts - video_start_dts, AV_TIME_BASE_Q, video_output_stream->time_base);
Debug(3, "opkt.dts = %d from video_input_stream->cur_dts(%d) - startDts(%d)",
opkt.dts, video_input_stream->cur_dts, video_start_dts
);
// Just because the input stream wraps, doesn't mean the output needs to. Really, if we are limiting ourselves to 10min segments I can't imagine every wrapping in the output. So need to handle input wrap, without causing output wrap.
if ( ! video_last_dts ) {
// This is the first packet.
opkt.dts = 0;
Debug(1, "Starting video video_last_pts will become (%d)", ipkt->dts );
} else {
if ( (!video_start_dts) || (video_start_dts > ipkt->dts) ) {
Debug(1, "Resetting video_start_dts from (%d) to (%d)", video_start_dts, ipkt->dts );
video_start_dts = ipkt->dts;
if ( ipkt->dts == AV_NOPTS_VALUE ) {
// why are we using cur_dts instead of packet.dts? I think cur_dts is in AV_TIME_BASE_Q, but ipkt.dts is in video_input_stream->time_base
if ( video_input_stream->cur_dts < video_last_dts ) {
Debug(1, "Resetting video_last_dts from (%d) to (%d) p.dts was (%d)", video_last_dts, video_input_stream->cur_dts, ipkt->dts );
opkt.dts = previous_dts + av_rescale_q(video_input_stream->cur_dts, AV_TIME_BASE_Q, video_output_stream->time_base);
} else {
opkt.dts = previous_dts + av_rescale_q(video_input_stream->cur_dts - video_last_dts, AV_TIME_BASE_Q, video_output_stream->time_base);
}
Debug(3, "opkt.dts = %d from video_input_stream->cur_dts(%d) - previus_dts(%d)",
opkt.dts, video_input_stream->cur_dts, video_last_dts
);
video_last_dts = video_input_stream->cur_dts;
} else {
if ( ipkt->dts < video_last_dts ) {
Debug(1, "Resetting video_last_dts from (%d) to (%d)", video_last_dts, ipkt->dts );
opkt.dts = previous_dts + av_rescale_q( ipkt->dts, video_input_stream->time_base, video_output_stream->time_base);
} else {
opkt.dts = previous_dts + av_rescale_q( ipkt->dts - video_last_dts, video_input_stream->time_base, video_output_stream->time_base);
}
Debug(3, "opkt.dts = %d from ipkt.dts(%d) - previus_dts(%d)",
opkt.dts, ipkt->dts, video_last_dts
);
video_last_dts = ipkt->dts;
}
opkt.dts = av_rescale_q(ipkt->dts - video_start_dts, video_input_stream->time_base, video_output_stream->time_base);
Debug(3, "opkt.dts = %d from ipkt->dts(%d) - startDts(%d)", opkt.dts, ipkt->dts, video_start_dts );
}
if ( opkt.dts > opkt.pts ) {
Debug( 1, "opkt.dts(%d) must be <= opkt.pts(%d). Decompression must happen before presentation.", opkt.dts, opkt.pts );
@ -597,20 +616,6 @@ if ( 1 ) {
}
opkt.duration = av_rescale_q(ipkt->duration, video_input_stream->time_base, video_output_stream->time_base);
} else {
// Using this results in super fast video output, might be because it should be using the codec time base instead of stream tb
//av_packet_rescale_ts( &opkt, video_input_stream->time_base, video_output_stream->time_base );
}
if ( opkt.dts != AV_NOPTS_VALUE ) {
int64_t max = video_output_stream->cur_dts + !(oc->oformat->flags & AVFMT_TS_NONSTRICT);
if ( video_output_stream->cur_dts && ( video_output_stream->cur_dts != AV_NOPTS_VALUE ) && ( max > opkt.dts ) ) {
Warning("st:%d PTS: %" PRId64 " DTS: %" PRId64 " < %" PRId64 " invalid, clipping", opkt.stream_index, opkt.pts, opkt.dts, max);
if( opkt.pts >= opkt.dts)
opkt.pts = FFMAX(opkt.pts, max);
opkt.dts = max;
}
}
opkt.flags = ipkt->flags;
opkt.pos=-1;
@ -650,14 +655,15 @@ Debug(4, "Not video and RAWPICTURE");
dumpPacket( ipkt);
dumpPacket(&opkt);
} else if ((prevDts > 0) && (prevDts > opkt.dts)) {
Warning("%s:%d: DTS out of order: %lld \u226E %lld; discarding frame", __FILE__, __LINE__, prevDts, opkt.dts);
prevDts = opkt.dts;
} else if ((previous_dts > 0) && (previous_dts > opkt.dts)) {
Warning("%s:%d: DTS out of order: %lld \u226E %lld; discarding frame", __FILE__, __LINE__, previous_dts, opkt.dts);
previous_dts = opkt.dts;
dumpPacket(&opkt);
} else {
prevDts = opkt.dts; // Unsure if av_interleaved_write_frame() clobbers opkt.dts when out of order, so storing in advance
previous_dts = opkt.dts; // Unsure if av_interleaved_write_frame() clobbers opkt.dts when out of order, so storing in advance
previous_pts = opkt.pts;
ret = av_interleaved_write_frame(oc, &opkt);
if(ret<0){
// There's nothing we can really do if the frame is rejected, just drop it and get on with the next
@ -689,34 +695,45 @@ int VideoStore::writeAudioFramePacket( AVPacket *ipkt ) {
#if 1
//Scale the PTS of the outgoing packet to be the correct time base
if ( ipkt->pts != AV_NOPTS_VALUE ) {
if ( (!audio_start_pts) || ( audio_start_pts > ipkt->pts ) ) {
Debug(1, "Resetting audeo_start_pts from (%d) to (%d)", audio_start_pts, ipkt->pts );
//never gets set, so the first packet can set it.
audio_start_pts = ipkt->pts;
if ( !audio_last_pts ) {
opkt.pts = 0;
} else {
if ( audio_last_pts > ipkt->pts ) {
Debug(1, "Resetting audeo_start_pts from (%d) to (%d)", audio_last_pts, ipkt->pts );
}
opkt.pts = previous_pts + av_rescale_q(ipkt->pts - audio_last_pts, audio_input_stream->time_base, audio_output_stream->time_base);
Debug(2, "opkt.pts = %d from ipkt->pts(%d) - last_pts(%d)", opkt.pts, ipkt->pts, audio_last_pts );
}
opkt.pts = av_rescale_q(ipkt->pts - audio_start_pts, audio_input_stream->time_base, audio_output_stream->time_base);
Debug(2, "opkt.pts = %d from ipkt->pts(%d) - startPts(%d)", opkt.pts, ipkt->pts, audio_start_pts );
audio_last_pts = ipkt->pts;
} else {
Debug(2, "opkt.pts = undef");
opkt.pts = AV_NOPTS_VALUE;
}
//Scale the DTS of the outgoing packet to be the correct time base
if(ipkt->dts == AV_NOPTS_VALUE) {
if ( (!audio_start_dts) || (audio_start_dts > audio_input_stream->cur_dts ) ) {
Debug(1, "Resetting audio_start_pts from (%d) to cur_dts (%d)", audio_start_dts, audio_input_stream->cur_dts );
audio_start_dts = audio_input_stream->cur_dts;
}
opkt.dts = av_rescale_q(audio_input_stream->cur_dts - audio_start_dts, AV_TIME_BASE_Q, audio_output_stream->time_base);
Debug(2, "opkt.dts = %d from video_input_stream->cur_dts(%d) - startDts(%d)",
opkt.dts, audio_input_stream->cur_dts, audio_start_dts
);
if ( ! audio_last_dts ) {
opkt.dts = 0;
} else {
if ( ( ! audio_start_dts ) || ( audio_start_dts > ipkt->dts ) ) {
Debug(1, "Resetting audeo_start_dts from (%d) to (%d)", audio_start_dts, ipkt->dts );
audio_start_dts = ipkt->dts;
if( ipkt->dts == AV_NOPTS_VALUE ) {
// So if the input has no dts assigned... still need an output dts... so we use cur_dts?
if ( audio_last_dts > audio_input_stream->cur_dts ) {
Debug(1, "Resetting audio_last_pts from (%d) to cur_dts (%d)", audio_last_dts, audio_input_stream->cur_dts );
opkt.dts = previous_dts + av_rescale_q( audio_input_stream->cur_dts, AV_TIME_BASE_Q, audio_output_stream->time_base);
} else {
opkt.dts = previous_dts + av_rescale_q( audio_input_stream->cur_dts - audio_last_dts, AV_TIME_BASE_Q, audio_output_stream->time_base);
}
audio_last_dts = audio_input_stream->cur_dts;
Debug(2, "opkt.dts = %d from video_input_stream->cur_dts(%d) - last_dts(%d)", opkt.dts, audio_input_stream->cur_dts, audio_last_dts );
} else {
if ( audio_last_dts > ipkt->dts ) {
Debug(1, "Resetting audio_last_dts from (%d) to (%d)", audio_last_dts, ipkt->dts );
opkt.dts = previous_dts + av_rescale_q(ipkt->dts, audio_input_stream->time_base, audio_output_stream->time_base);
} else {
opkt.dts = previous_dts + av_rescale_q(ipkt->dts - audio_last_dts, audio_input_stream->time_base, audio_output_stream->time_base);
}
Debug(2, "opkt.dts = %d from ipkt->dts(%d) - last_dts(%d)", opkt.dts, ipkt->dts, audio_last_dts );
}
opkt.dts = av_rescale_q(ipkt->dts - audio_start_dts, audio_input_stream->time_base, audio_output_stream->time_base);
Debug(2, "opkt.dts = %d from ipkt->dts(%d) - startDts(%d)", opkt.dts, ipkt->dts, audio_start_dts );
}
if ( opkt.dts > opkt.pts ) {
Debug(1,"opkt.dts(%d) must be <= opkt.pts(%d). Decompression must happen before presentation.", opkt.dts, opkt.pts );
@ -725,6 +742,7 @@ int VideoStore::writeAudioFramePacket( AVPacket *ipkt ) {
//opkt.pts = AV_NOPTS_VALUE;
//opkt.dts = AV_NOPTS_VALUE;
// I wonder if we could just use duration instead of all the hoop jumping above?
opkt.duration = av_rescale_q(ipkt->duration, audio_input_stream->time_base, audio_output_stream->time_base);
#else
#endif

View File

@ -54,15 +54,16 @@ private:
bool keyframeMessage;
int keyframeSkipNumber;
int64_t video_start_pts;
int64_t video_start_dts;
int64_t audio_start_pts;
int64_t audio_start_dts;
// These are for input
int64_t video_last_pts;
int64_t video_last_dts;
int64_t audio_last_pts;
int64_t audio_last_dts;
int64_t start_pts;
int64_t start_dts;
// These are for output, should start at zero. We assume they do not wrap because we just aren't going to save files that big.
int64_t previous_pts;
int64_t previous_dts;
int64_t prevDts;
int64_t filter_in_rescale_delta_last;
public:

View File

@ -73,8 +73,7 @@ possible, this should run at more or less constant speed.
#include "zm_signal.h"
#include "zm_monitor.h"
void Usage()
{
void Usage() {
fprintf( stderr, "zmc -d <device_path> or -r <proto> -H <host> -P <port> -p <path> or -f <file_path> or -m <monitor_id>\n" );
fprintf( stderr, "Options:\n" );
@ -91,8 +90,7 @@ void Usage()
exit( 0 );
}
int main( int argc, char *argv[] )
{
int main( int argc, char *argv[] ) {
self = argv[0];
srand( getpid() * time( 0 ) );
@ -110,21 +108,19 @@ int main( int argc, char *argv[] )
{"protocol", 1, 0, 'r'},
{"host", 1, 0, 'H'},
{"port", 1, 0, 'P'},
{"path", 1, 0, 'p'},
{"file", 1, 0, 'f'},
{"path", 1, 0, 'p'},
{"file", 1, 0, 'f'},
{"monitor", 1, 0, 'm'},
{"help", 0, 0, 'h'},
{"version", 0, 0, 'v'},
{0, 0, 0, 0}
};
while (1)
{
while (1) {
int option_index = 0;
int c = getopt_long (argc, argv, "d:H:P:p:f:m:h:v", long_options, &option_index);
if (c == -1)
{
if (c == -1) {
break;
}
@ -161,8 +157,7 @@ int main( int argc, char *argv[] )
}
}
if (optind < argc)
{
if (optind < argc) {
fprintf( stderr, "Extraneous options, " );
while (optind < argc)
printf ("%s ", argv[optind++]);
@ -171,37 +166,28 @@ int main( int argc, char *argv[] )
}
int modes = ( device[0]?1:0 + host[0]?1:0 + file[0]?1:0 + (monitor_id>0?1:0) );
if ( modes > 1 )
{
if ( modes > 1 ) {
fprintf( stderr, "Only one of device, host/port/path, file or monitor id allowed\n" );
Usage();
exit( 0 );
}
if ( modes < 1 )
{
if ( modes < 1 ) {
fprintf( stderr, "One of device, host/port/path, file or monitor id must be specified\n" );
Usage();
exit( 0 );
}
char log_id_string[32] = "";
if ( device[0] )
{
if ( device[0] ) {
const char *slash_ptr = strrchr( device, '/' );
snprintf( log_id_string, sizeof(log_id_string), "zmc_d%s", slash_ptr?slash_ptr+1:device );
}
else if ( host[0] )
{
} else if ( host[0] ) {
snprintf( log_id_string, sizeof(log_id_string), "zmc_h%s", host );
}
else if ( file[0] )
{
} else if ( file[0] ) {
const char *slash_ptr = strrchr( file, '/' );
snprintf( log_id_string, sizeof(log_id_string), "zmc_f%s", slash_ptr?slash_ptr+1:file );
}
else
{
} else {
snprintf( log_id_string, sizeof(log_id_string), "zmc_m%d", monitor_id );
}
@ -214,35 +200,26 @@ int main( int argc, char *argv[] )
Monitor **monitors = 0;
int n_monitors = 0;
#if ZM_HAS_V4L
if ( device[0] )
{
if ( device[0] ) {
n_monitors = Monitor::LoadLocalMonitors( device, monitors, Monitor::CAPTURE );
}
else
} else
#endif // ZM_HAS_V4L
if ( host[0] )
{
if ( host[0] ) {
if ( !port )
port = "80";
n_monitors = Monitor::LoadRemoteMonitors( protocol, host, port, path, monitors, Monitor::CAPTURE );
}
else if ( file[0] )
{
} else if ( file[0] ) {
n_monitors = Monitor::LoadFileMonitors( file, monitors, Monitor::CAPTURE );
}
else
{
} else {
Monitor *monitor = Monitor::Load( monitor_id, true, Monitor::CAPTURE );
if ( monitor )
{
if ( monitor ) {
monitors = new Monitor *[1];
monitors[0] = monitor;
n_monitors = 1;
}
}
if ( !n_monitors )
{
if ( !n_monitors ) {
Error( "No monitors found" );
exit ( -1 );
}
@ -259,8 +236,7 @@ int main( int argc, char *argv[] )
sigaddset( &block_set, SIGUSR2 );
monitors[0]->setStartupTime( (time_t)time(NULL) );
if ( monitors[0]->PrimeCapture() < 0 )
{
if ( monitors[0]->PrimeCapture() < 0 ) {
Error( "Failed to prime capture of initial monitor" );
exit( -1 );
}
@ -269,8 +245,7 @@ int main( int argc, char *argv[] )
long *alarm_capture_delays = new long[n_monitors];
long *next_delays = new long[n_monitors];
struct timeval * last_capture_times = new struct timeval[n_monitors];
for ( int i = 0; i < n_monitors; i++ )
{
for ( int i = 0; i < n_monitors; i++ ) {
last_capture_times[i].tv_sec = last_capture_times[i].tv_usec = 0;
capture_delays[i] = monitors[i]->GetCaptureDelay();
alarm_capture_delays[i] = monitors[i]->GetAlarmCaptureDelay();
@ -279,18 +254,14 @@ int main( int argc, char *argv[] )
int result = 0;
struct timeval now;
struct DeltaTimeval delta_time;
while( !zm_terminate )
{
while( !zm_terminate ) {
sigprocmask( SIG_BLOCK, &block_set, 0 );
for ( int i = 0; i < n_monitors; i++ )
{
for ( int i = 0; i < n_monitors; i++ ) {
long min_delay = MAXINT;
gettimeofday( &now, NULL );
for ( int j = 0; j < n_monitors; j++ )
{
if ( last_capture_times[j].tv_sec )
{
for ( int j = 0; j < n_monitors; j++ ) {
if ( last_capture_times[j].tv_sec ) {
DELTA_TIMEVAL( delta_time, now, last_capture_times[j], DT_PREC_3 );
if ( monitors[i]->GetState() == Monitor::ALARM )
next_delays[j] = alarm_capture_delays[j]-delta_time.delta;
@ -298,48 +269,39 @@ int main( int argc, char *argv[] )
next_delays[j] = capture_delays[j]-delta_time.delta;
if ( next_delays[j] < 0 )
next_delays[j] = 0;
}
else
{
} else {
next_delays[j] = 0;
}
if ( next_delays[j] <= min_delay )
{
if ( next_delays[j] <= min_delay ) {
min_delay = next_delays[j];
}
}
if ( next_delays[i] <= min_delay || next_delays[i] <= 0 )
{
if ( monitors[i]->PreCapture() < 0 )
{
if ( next_delays[i] <= min_delay || next_delays[i] <= 0 ) {
if ( monitors[i]->PreCapture() < 0 ) {
Error( "Failed to pre-capture monitor %d %d (%d/%d)", monitors[i]->Id(), monitors[i]->Name(), i+1, n_monitors );
zm_terminate = true;
result = -1;
break;
}
if ( monitors[i]->Capture() < 0 )
{
if ( monitors[i]->Capture() < 0 ) {
Error( "Failed to capture image from monitor %d %s (%d/%d)", monitors[i]->Id(), monitors[i]->Name(), i+1, n_monitors );
zm_terminate = true;
result = -1;
break;
}
if ( monitors[i]->PostCapture() < 0 )
{
if ( monitors[i]->PostCapture() < 0 ) {
Error( "Failed to post-capture monitor %d %s (%d/%d)", monitors[i]->Id(), monitors[i]->Name(), i+1, n_monitors );
zm_terminate = true;
result = -1;
break;
}
if ( next_delays[i] > 0 )
{
if ( next_delays[i] > 0 ) {
gettimeofday( &now, NULL );
DELTA_TIMEVAL( delta_time, now, last_capture_times[i], DT_PREC_3 );
long sleep_time = next_delays[i]-delta_time.delta;
if ( sleep_time > 0 )
{
if ( sleep_time > 0 ) {
usleep( sleep_time*(DT_MAXGRAN/DT_PREC_3) );
}
}
@ -349,8 +311,7 @@ int main( int argc, char *argv[] )
} // end foreach n_monitors
sigprocmask( SIG_UNBLOCK, &block_set, 0 );
} // end while ! zm_terminate
for ( int i = 0; i < n_monitors; i++ )
{
for ( int i = 0; i < n_monitors; i++ ) {
delete monitors[i];
}
delete [] monitors;

View File

@ -161,9 +161,11 @@ int main( int argc, const char *argv[] )
{
if ( !strcmp( name, "user" ) ) {
username = UriDecode( value );
Debug( 1, "Have %s for username", username.c_str() );
}
if ( !strcmp( name, "pass" ) ) {
password = UriDecode( password );
password = UriDecode( value );
Debug( 1, "Have %s for password", password.c_str() );
}
}
}
@ -183,12 +185,16 @@ int main( int argc, const char *argv[] )
{
if ( *auth ) {
user = zmLoadAuthUser( auth, config.auth_hash_ips );
} else {
Debug( 1, "Need both username and password" );
}
}
//else if ( strcmp( config.auth_relay, "plain" ) == 0 )
{
if ( username.length() && password.length() ) {
user = zmLoadUser( username.c_str(), password.c_str() );
} else {
Debug( 1, "Need both username and password" );
}
}
} // auth is none or something else

View File

@ -103,6 +103,7 @@ if ( !empty($action) ) {
userLogin( $username, $password );
$refreshParent = true;
$view = 'console';
$redirect = true;
} else if ( $action == 'logout' ) {
userLogout();
$refreshParent = true;
@ -133,37 +134,50 @@ if ( !empty($action) ) {
$filterName = $_REQUEST['newFilterName'];
}
if ( $filterName ) {
$sql = "REPLACE INTO Filters SET Name = ".dbEscape($filterName).",";
# Replace will teplace any filter with the same Id
# Since we aren't specifying the Id , this is effectively an insert
$sql = 'REPLACE INTO Filters SET Name = '.dbEscape($filterName).',';
} else {
$sql = 'UPDATE Filters SET';
$endSql = "where Id = ".$_REQUEST['Id'];
$endSql = 'WHERE Id = '.$_REQUEST['Id'];
}
# endSql is only set if ! filterName... so... woulnd't this always be true
if ( !empty($filterName) || $endSql ) {
$_REQUEST['filter']['sort_field'] = validStr($_REQUEST['sort_field']);
$_REQUEST['filter']['sort_asc'] = validStr($_REQUEST['sort_asc']);
$_REQUEST['filter']['limit'] = validInt($_REQUEST['limit']);
$sql .= " Query = ".dbEscape(jsonEncode($_REQUEST['filter']));
$sql .= ' Query = '.dbEscape(jsonEncode($_REQUEST['filter']));
if ( !empty($_REQUEST['AutoArchive']) )
$sql .= ", AutoArchive = ".dbEscape($_REQUEST['AutoArchive']);
$sql .= ', AutoArchive = '.dbEscape($_REQUEST['AutoArchive']);
if ( !empty($_REQUEST['AutoVideo']) )
$sql .= ", AutoVideo = ".dbEscape($_REQUEST['AutoVideo']);
$sql .= ', AutoVideo = '.dbEscape($_REQUEST['AutoVideo']);
if ( !empty($_REQUEST['AutoUpload']) )
$sql .= ", AutoUpload = ".dbEscape($_REQUEST['AutoUpload']);
$sql .= ', AutoUpload = '.dbEscape($_REQUEST['AutoUpload']);
if ( !empty($_REQUEST['AutoEmail']) )
$sql .= ", AutoEmail = ".dbEscape($_REQUEST['AutoEmail']);
$sql .= ', AutoEmail = '.dbEscape($_REQUEST['AutoEmail']);
if ( !empty($_REQUEST['AutoMessage']) )
$sql .= ", AutoMessage = ".dbEscape($_REQUEST['AutoMessage']);
$sql .= ', AutoMessage = '.dbEscape($_REQUEST['AutoMessage']);
if ( !empty($_REQUEST['AutoExecute']) && !empty($_REQUEST['AutoExecuteCmd']) )
$sql .= ", AutoExecute = ".dbEscape($_REQUEST['AutoExecute']).", AutoExecuteCmd = ".dbEscape($_REQUEST['AutoExecuteCmd']);
$sql .= ', AutoExecute = '.dbEscape($_REQUEST['AutoExecute']).", AutoExecuteCmd = ".dbEscape($_REQUEST['AutoExecuteCmd']);
if ( !empty($_REQUEST['AutoDelete']) )
$sql .= ", AutoDelete = ".dbEscape($_REQUEST['AutoDelete']);
$sql .= ', AutoDelete = '.dbEscape($_REQUEST['AutoDelete']);
if ( !empty($_REQUEST['background']) )
$sql .= ", Background = ".dbEscape($_REQUEST['background']);
$sql .= ', Background = '.dbEscape($_REQUEST['background']);
if ( !empty($_REQUEST['concurrent']) )
$sql .= ", Concurrent = ".dbEscape($_REQUEST['concurrent']);
$sql .= ', Concurrent = '.dbEscape($_REQUEST['concurrent']);
$sql .= $endSql;
dbQuery( $sql );
$refreshParent = true;
if ( $filterName ) {
$filter = dbFetchOne( 'SELECT * FROM Filters WHERE Name=?', NULL, array($filterName) );
if ( $filter ) {
# This won't work yet because refreshparent refreshes the old filter. Need to do a redirect instead of a refresh.
$_REQUEST['Id'] = $filter['Id'];
} else {
Error("No new Id despite new name");
}
}
$refreshParent = '/index.php?view=filter&Id='.$_REQUEST['Id'];
}
} // end if canedit events
} // end if action == filter
@ -512,7 +526,7 @@ if ( !empty($action) ) {
dbQuery( "update TriggersX10 set ".implode( ", ", $x10Changes )." where MonitorId=?", array($mid) );
} elseif ( !$user['MonitorIds'] ) {
if ( !$x10Monitor ) {
dbQuery( "insert into TriggersX10 set MonitorId = ?".implode( ", ", $x10Changes ), array( $mid ) );
dbQuery( "insert into TriggersX10 set MonitorId = ?, ".implode( ", ", $x10Changes ), array( $mid ) );
} else {
dbQuery( "delete from TriggersX10 where MonitorId = ?", array($mid) );
}
@ -822,12 +836,13 @@ if ( !empty($action) ) {
if ( count( $changes ) ) {
if ( !empty($_REQUEST['uid']) ) {
dbQuery( "update Users set ".implode( ", ", $changes )." where Id = ?", array($_REQUEST['uid']) );
# If we are updating the logged in user, then update our session user data.
if ( $user and ( $dbUser['Username'] == $user['Username'] ) )
userLogin( $dbUser['Username'], $dbUser['Password'] );
} else {
dbQuery( "insert into Users set ".implode( ", ", $changes ) );
}
$refreshParent = true;
if ( $dbUser['Username'] == $user['Username'] )
userLogin( $dbUser['Username'], $dbUser['Password'] );
}
$view = 'none';
} elseif ( $action == 'state' ) {

View File

@ -0,0 +1,9 @@
Copyright (c) 2008-2013, Edward Z. Yang
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,69 @@
[[ news ]]
1.0.4 released 2013-07-17
[SECURITY FIXES]
- When secret key was not explicitly set, it was not being used
by the csrf_hash() function. Thanks sparticvs for reporting.
[FEATURES]
- The default 'CSRF check failed' page now offers a handy 'Try
again' button, which resubmits the form.
[BUG FIXES]
- The fix for 1.0.3 inadvertantly turned off XMLHttpRequest
overloading for all browsers; it has now been fixed to only
apply to IE.
1.0.3 released 2012-01-31
[BUG FIXES]
- Internet Explorer 8 adds support for XMLHttpRequest.prototype,
but this support is broken for method overloading. We
explicitly disable JavaScript overloading for Internet Explorer.
Thanks Kelly Lu for reporting. <lubird@gmail.com>
- A global declaration was omitted, resulting in a variable
not being properly introduced in PHP 5.3. Thanks Whitney Beck for
reporting. <whitney.a.beck@gmail.com>
1.0.2 released 2009-03-08
[SECURITY FIXES]
- Due to a typo, csrf-magic accidentally treated the secret key
as always present. This means that there was a possible CSRF
attack against users without any cookies. No attacks in the
wild were known at the time of this release. Thanks Jakub
Vrána for reporting.
1.0.1 released 2008-11-02
[NEW FEATURES]
- Support for composite tokens; this also fixes a bug with using
IP-based tokens for users with cookies disabled.
- Native support cookie tokens; use csrf_conf('cookie', $name) to
specify the name of a cookie that the CSRF token should be
placed in. This is useful if you have a Squid cache, and need
to configure it to ignore this token.
- Tips/tricks section in README.txt.
- There is now a two hour expiration time on all tokens. This
can be modified using csrf_conf('expires', $seconds).
- ClickJacking protection using an iframe breaker. Disable with
csrf_conf('frame-breaker', false).
[BUG FIXES]
- CsrfMagic.send() incorrectly submitted GET requests twice,
once without the magic token and once with the token. Reported
by Kelly Lu <lubird@gmail.com>.

View File

@ -0,0 +1,160 @@
[[ csrf-magic ]]
Add the following line to the top of all web-accessible PHP pages. If you have
a common file included by everything, put it there.
include_once '/path/to/csrf-magic.php';
Do it, test it, then forget about it. csrf-magic is protecting you if nothing
bad happens. Read on if you run into problems.
TABLE OF CONTENTS
+ ------------------- +
1. TIPS AND TRICKS
2. AJAX
3. CONFIGURE
4. THANKS
5. FOOTNOTES
+ ------------------- +
1. TIPS AND TRICKS
* If your JavaScript and AJAX is persistently getting errors, check the
AJAX section below on how to fix.
* The CSS overlay protection makes it impossible to display your website
in frame/iframe elements. You can disable it with
csrf_conf('frame-breaker', false) in your csrf_startup() function.
* csrf-magic will start a session. To disable, use csrf_conf('auto-session',
false) in your csrf_startup() function.
* The default error message is a little user unfriendly. Write your own
function which outputs an error message and set csrf_conf('callback',
'myCallbackFunction') in your csrf_startup() function.
* Make sure csrf_conf('secret', 'ABCDEFG') has something random in it. If
the directory csrf-magic.php is in is writable, csrf-magic will generate
a secret key for you in the csrf-secret.php file.
* Remember you can use auto_prepend to include csrf-magic.php on all your
pages. You may want to create a stub file which you can include that
includes csrf-magic.php as well as performs configuration.
* The default expiration time for tokens is two hours. If you expect your
users to need longer to fill out forms, be sure to enable double
submission when the token is invalid.
2. AJAX
csrf-magic has the ability to dynamically rewrite AJAX requests which use
XMLHttpRequest. However, due to the invasiveness of this procedure, it is
not enabled by default. You can enable it by adding this code before you
include csrf-magic.php.
function csrf_startup() {
csrf_conf('rewrite-js', '/web/path/to/csrf-magic.js');
}
// include_once '/path/to/csrf-magic.php';
(Be sure to place csrf-magic.js somewhere web accessible).
The default method CSRF Magic uses to rewrite AJAX requests will
only work for browsers with support for XmlHttpRequest.prototype (this excludes
all versions of Internet Explorer). See this page for more information:
http://stackoverflow.com/questions/664315/internet-explorer-8-prototypes-and-xmlhttprequest
However, csrf-magic.js will
automatically detect and play nice with the following JavaScript frameworks:
* jQuery
* Prototype
* MooTools
* Ext
* Dojo
(Note 2013-07-16: It has been a long time since this manual support has
been updated, and some JavaScript libraries have placed their copies of XHR
in local variables in closures, which makes it difficult for us to monkey-patch
it in automatically.)
To rewrite your own JavaScript library to use csrf-magic.js, you should modify
your function that generates XMLHttpRequest to have this at the end:
return new CsrfMagic(xhrObject);
With whatever xhrObject may be. If you have literal instances of XMLHttpRequest
in your code, find and replace ''new XMLHttpRequest'' with ''new CsrfMagic''
(CsrfMagic will automatically instantiate an XMLHttpRequest object in a
cross-platform manner as necessary).
If you don't want csrf-magic monkeying around with your XMLHttpRequest object,
you can manually rewrite your AJAX code to include the variable. The important
information is stored in the global variables csrfMagicName and csrfMagicToken.
CsrfMagic.process may also be of interest, as it takes one parameter, a
querystring, and prepends the CSRF token to the value.
3. CONFIGURE
csrf-magic has some configuration options that you can set inside the
csrf_startup() function. They are described in csrf-magic.php, and you can
set them using the convenience function csrf_conf($name, $value).
For example, this is a recommended configuration:
/**
* This is a function that gets called if a csrf check fails. csrf-magic will
* then exit afterwards.
*/
function my_csrf_callback() {
echo "You're doing bad things young man!";
}
function csrf_startup() {
// While csrf-magic has a handy little heuristic for determining whether
// or not the content in the buffer is HTML or not, you should really
// give it a nudge and turn rewriting *off* when the content is
// not HTML. Implementation details will vary.
if (isset($_POST['ajax'])) csrf_conf('rewrite', false);
// This is a secret value that must be set in order to enable username
// and IP based checks. Don't show this to anyone. A secret id will
// automatically be generated for you if the directory csrf-magic.php
// is placed in is writable.
csrf_conf('secret', 'ABCDEFG123456');
// This enables JavaScript rewriting and will ensure your AJAX calls
// don't stop working.
csrf_conf('rewrite-js', '/csrf-magic.js');
// This makes csrf-magic call my_csrf_callback() before exiting when
// there is a bad csrf token. This lets me customize the error page.
csrf_conf('callback', 'my_csrf_callback');
// While this is enabled by default to boost backwards compatibility,
// for security purposes it should ideally be off. Some users can be
// NATted or have dialup addresses which rotate frequently. Cookies
// are much more reliable.
csrf_conf('allow-ip', false);
}
// Finally, include the library
include_once '/path/to/csrf-magic.php';
Configuration gets stored in the $GLOBALS['csrf'] array.
4. THANKS
My thanks to Chris Shiflett, for unintentionally inspiring the idea, as well
as telling me the original variant of the Bob and Mallory story,
and the Django CSRF Middleware authors, who thought up of this before me.
Gareth Heyes suggested using the frame-breaker option to protect against
CSS overlay attacks.

View File

@ -0,0 +1,191 @@
/**
* @file
*
* Rewrites XMLHttpRequest to automatically send CSRF token with it. In theory
* plays nice with other JavaScript libraries, needs testing though.
*/
// Here are the basic overloaded method definitions
// The wrapper must be set BEFORE onreadystatechange is written to, since
// a bug in ActiveXObject prevents us from properly testing for it.
CsrfMagic = function(real) {
// try to make it ourselves, if you didn't pass it
if (!real) try { real = new XMLHttpRequest; } catch (e) {;}
if (!real) try { real = new ActiveXObject('Msxml2.XMLHTTP'); } catch (e) {;}
if (!real) try { real = new ActiveXObject('Microsoft.XMLHTTP'); } catch (e) {;}
if (!real) try { real = new ActiveXObject('Msxml2.XMLHTTP.4.0'); } catch (e) {;}
this.csrf = real;
// properties
var csrfMagic = this;
real.onreadystatechange = function() {
csrfMagic._updateProps();
return csrfMagic.onreadystatechange ? csrfMagic.onreadystatechange() : null;
};
csrfMagic._updateProps();
}
CsrfMagic.prototype = {
open: function(method, url, async, username, password) {
if (method == 'POST') this.csrf_isPost = true;
// deal with Opera bug, thanks jQuery
if (username) return this.csrf_open(method, url, async, username, password);
else return this.csrf_open(method, url, async);
},
csrf_open: function(method, url, async, username, password) {
if (username) return this.csrf.open(method, url, async, username, password);
else return this.csrf.open(method, url, async);
},
send: function(data) {
if (!this.csrf_isPost) return this.csrf_send(data);
prepend = csrfMagicName + '=' + csrfMagicToken + '&';
// XXX: Removed to eliminate 'Refused to set unsafe header "Content-length" ' errors in modern browsers
// if (this.csrf_purportedLength === undefined) {
// this.csrf_setRequestHeader("Content-length", this.csrf_purportedLength + prepend.length);
// delete this.csrf_purportedLength;
// }
delete this.csrf_isPost;
return this.csrf_send(prepend + data);
},
csrf_send: function(data) {
return this.csrf.send(data);
},
setRequestHeader: function(header, value) {
// We have to auto-set this at the end, since we don't know how long the
// nonce is when added to the data.
if (this.csrf_isPost && header == "Content-length") {
this.csrf_purportedLength = value;
return;
}
return this.csrf_setRequestHeader(header, value);
},
csrf_setRequestHeader: function(header, value) {
return this.csrf.setRequestHeader(header, value);
},
abort: function() {
return this.csrf.abort();
},
getAllResponseHeaders: function() {
return this.csrf.getAllResponseHeaders();
},
getResponseHeader: function(header) {
return this.csrf.getResponseHeader(header);
} // ,
}
// proprietary
CsrfMagic.prototype._updateProps = function() {
this.readyState = this.csrf.readyState;
if (this.readyState == 4) {
this.responseText = this.csrf.responseText;
this.responseXML = this.csrf.responseXML;
this.status = this.csrf.status;
this.statusText = this.csrf.statusText;
}
}
CsrfMagic.process = function(base) {
if(typeof base == 'object') {
base[csrfMagicName] = csrfMagicToken;
return base;
}
var prepend = csrfMagicName + '=' + csrfMagicToken;
if (base) return prepend + '&' + base;
return prepend;
}
// callback function for when everything on the page has loaded
CsrfMagic.end = function() {
// This rewrites forms AGAIN, so in case buffering didn't work this
// certainly will.
forms = document.getElementsByTagName('form');
for (var i = 0; i < forms.length; i++) {
form = forms[i];
if (form.method.toUpperCase() !== 'POST') continue;
if (form.elements[csrfMagicName]) continue;
var input = document.createElement('input');
input.setAttribute('name', csrfMagicName);
input.setAttribute('value', csrfMagicToken);
input.setAttribute('type', 'hidden');
form.appendChild(input);
}
}
// Sets things up for Mozilla/Opera/nice browsers
// We very specifically match against Internet Explorer, since they haven't
// implemented prototypes correctly yet.
if (window.XMLHttpRequest && window.XMLHttpRequest.prototype && '\v' != 'v') {
var x = XMLHttpRequest.prototype;
var c = CsrfMagic.prototype;
// Save the original functions
x.csrf_open = x.open;
x.csrf_send = x.send;
x.csrf_setRequestHeader = x.setRequestHeader;
// Notice that CsrfMagic is itself an instantiatable object, but only
// open, send and setRequestHeader are necessary as decorators.
x.open = c.open;
x.send = c.send;
x.setRequestHeader = c.setRequestHeader;
} else {
// The only way we can do this is by modifying a library you have been
// using. We support YUI, script.aculo.us, prototype, MooTools,
// jQuery, Ext and Dojo.
if (window.jQuery) {
// jQuery didn't implement a new XMLHttpRequest function, so we have
// to do this the hard way.
jQuery.csrf_ajax = jQuery.ajax;
jQuery.ajax = function( s ) {
if (s.type && s.type.toUpperCase() == 'POST') {
s = jQuery.extend(true, s, jQuery.extend(true, {}, jQuery.ajaxSettings, s));
if ( s.data && s.processData && typeof s.data != "string" ) {
s.data = jQuery.param(s.data);
}
s.data = CsrfMagic.process(s.data);
}
return jQuery.csrf_ajax( s );
}
}
if (window.Prototype) {
// This works for script.aculo.us too
Ajax.csrf_getTransport = Ajax.getTransport;
Ajax.getTransport = function() {
return new CsrfMagic(Ajax.csrf_getTransport());
}
}
if (window.MooTools) {
Browser.csrf_Request = Browser.Request;
Browser.Request = function () {
return new CsrfMagic(Browser.csrf_Request());
}
}
if (window.YAHOO) {
// old YUI API
YAHOO.util.Connect.csrf_createXhrObject = YAHOO.util.Connect.createXhrObject;
YAHOO.util.Connect.createXhrObject = function (transaction) {
obj = YAHOO.util.Connect.csrf_createXhrObject(transaction);
obj.conn = new CsrfMagic(obj.conn);
return obj;
}
}
if (window.Ext) {
// Ext can use other js libraries as loaders, so it has to come last
// Ext's implementation is pretty identical to Yahoo's, but we duplicate
// it for comprehensiveness's sake.
Ext.lib.Ajax.csrf_createXhrObject = Ext.lib.Ajax.createXhrObject;
Ext.lib.Ajax.createXhrObject = function (transaction) {
obj = Ext.lib.Ajax.csrf_createXhrObject(transaction);
obj.conn = new CsrfMagic(obj.conn);
return obj;
}
}
if (window.dojo) {
// NOTE: this doesn't work with latest dojo
dojo.csrf__xhrObj = dojo._xhrObj;
dojo._xhrObj = function () {
return new CsrfMagic(dojo.csrf__xhrObj());
}
}
}

View File

@ -0,0 +1,405 @@
<?php
/**
* @file
*
* csrf-magic is a PHP library that makes adding CSRF-protection to your
* web applications a snap. No need to modify every form or create a database
* of valid nonces; just include this file at the top of every
* web-accessible page (or even better, your common include file included
* in every page), and forget about it! (There are, of course, configuration
* options for advanced users).
*
* This library is PHP4 and PHP5 compatible.
*/
// CONFIGURATION:
/**
* By default, when you include this file csrf-magic will automatically check
* and exit if the CSRF token is invalid. This will defer executing
* csrf_check() until you're ready. You can also pass false as a parameter to
* that function, in which case the function will not exit but instead return
* a boolean false if the CSRF check failed. This allows for tighter integration
* with your system.
*/
$GLOBALS['csrf']['defer'] = true;
/**
* This is the amount of seconds you wish to allow before any token becomes
* invalid; the default is two hours, which should be more than enough for
* most websites.
*/
$GLOBALS['csrf']['expires'] = 7200;
/**
* Callback function to execute when there's the CSRF check fails and
* $fatal == true (see csrf_check). This will usually output an error message
* about the failure.
*/
$GLOBALS['csrf']['callback'] = 'csrf_callback';
/**
* Whether or not to include our JavaScript library which also rewrites
* AJAX requests on this domain. Set this to the web path. This setting only works
* with supported JavaScript libraries in Internet Explorer; see README.txt for
* a list of supported libraries.
*/
$GLOBALS['csrf']['rewrite-js'] = false;
/**
* A secret key used when hashing items. Please generate a random string and
* place it here. If you change this value, all previously generated tokens
* will become invalid.
*/
$GLOBALS['csrf']['secret'] = '';
// nota bene: library code should use csrf_get_secret() and not access
// this global directly
/**
* Set this to false to disable csrf-magic's output handler, and therefore,
* its rewriting capabilities. If you're serving non HTML content, you should
* definitely set this false.
*/
$GLOBALS['csrf']['rewrite'] = true;
/**
* Whether or not to use IP addresses when binding a user to a token. This is
* less reliable and less secure than sessions, but is useful when you need
* to give facilities to anonymous users and do not wish to maintain a database
* of valid keys.
*/
$GLOBALS['csrf']['allow-ip'] = true;
/**
* If this information is available, use the cookie by this name to determine
* whether or not to allow the request. This is a shortcut implementation
* very similar to 'key', but we randomly set the cookie ourselves.
*/
$GLOBALS['csrf']['cookie'] = '__csrf_cookie';
/**
* If this information is available, set this to a unique identifier (it
* can be an integer or a unique username) for the current "user" of this
* application. The token will then be globally valid for all of that user's
* operations, but no one else. This requires that 'secret' be set.
*/
$GLOBALS['csrf']['user'] = false;
/**
* This is an arbitrary secret value associated with the user's session. This
* will most probably be the contents of a cookie, as an attacker cannot easily
* determine this information. Warning: If the attacker knows this value, they
* can easily spoof a token. This is a generic implementation; sessions should
* work in most cases.
*
* Why would you want to use this? Lets suppose you have a squid cache for your
* website, and the presence of a session cookie bypasses it. Let's also say
* you allow anonymous users to interact with the website; submitting forms
* and AJAX. Previously, you didn't have any CSRF protection for anonymous users
* and so they never got sessions; you don't want to start using sessions either,
* otherwise you'll bypass the Squid cache. Setup a different cookie for CSRF
* tokens, and have Squid ignore that cookie for get requests, for anonymous
* users. (If you haven't guessed, this scheme was(?) used for MediaWiki).
*/
$GLOBALS['csrf']['key'] = false;
/**
* The name of the magic CSRF token that will be placed in all forms, i.e.
* the contents of <input type="hidden" name="$name" value="CSRF-TOKEN" />
*/
$GLOBALS['csrf']['input-name'] = '__csrf_magic';
/**
* Set this to false if your site must work inside of frame/iframe elements,
* but do so at your own risk: this configuration protects you against CSS
* overlay attacks that defeat tokens.
*/
$GLOBALS['csrf']['frame-breaker'] = true;
/**
* Whether or not CSRF Magic should be allowed to start a new session in order
* to determine the key.
*/
$GLOBALS['csrf']['auto-session'] = true;
/**
* Whether or not csrf-magic should produce XHTML style tags.
*/
$GLOBALS['csrf']['xhtml'] = true;
// FUNCTIONS:
// Don't edit this!
$GLOBALS['csrf']['version'] = '1.0.4';
/**
* Rewrites <form> on the fly to add CSRF tokens to them. This can also
* inject our JavaScript library.
*/
function csrf_ob_handler($buffer, $flags) {
// Even though the user told us to rewrite, we should do a quick heuristic
// to check if the page is *actually* HTML. We don't begin rewriting until
// we hit the first <html tag.
static $is_html = false;
if (!$is_html) {
// not HTML until proven otherwise
if (stripos($buffer, '<html') !== false) {
$is_html = true;
} else {
return $buffer;
}
}
$tokens = csrf_get_tokens();
$name = $GLOBALS['csrf']['input-name'];
$endslash = $GLOBALS['csrf']['xhtml'] ? ' /' : '';
$input = "<input type='hidden' name='$name' value=\"$tokens\"$endslash>";
$buffer = preg_replace('#(<form[^>]*method\s*=\s*["\']post["\'][^>]*>)#i', '$1' . $input, $buffer);
if ($GLOBALS['csrf']['frame-breaker']) {
$buffer = str_ireplace('</head>', '<script type="text/javascript">if (top != self) {top.location.href = self.location.href;}</script></head>', $buffer);
}
if ($js = $GLOBALS['csrf']['rewrite-js']) {
$buffer = str_ireplace(
'</head>',
'<script type="text/javascript">'.
'var csrfMagicToken = "'.$tokens.'";'.
'var csrfMagicName = "'.$name.'";</script>'.
'<script src="'.$js.'" type="text/javascript"></script></head>',
$buffer
);
$script = '<script type="text/javascript">CsrfMagic.end();</script>';
$buffer = str_ireplace('</body>', $script . '</body>', $buffer, $count);
if (!$count) {
$buffer .= $script;
}
}
return $buffer;
}
/**
* Checks if this is a post request, and if it is, checks if the nonce is valid.
* @param bool $fatal Whether or not to fatally error out if there is a problem.
* @return True if check passes or is not necessary, false if failure.
*/
function csrf_check($fatal = true) {
if ($_SERVER['REQUEST_METHOD'] !== 'POST') return true;
csrf_start();
$name = $GLOBALS['csrf']['input-name'];
$ok = false;
$tokens = '';
do {
if (!isset($_POST[$name])) break;
// we don't regenerate a token and check it because some token creation
// schemes are volatile.
$tokens = $_POST[$name];
if (!csrf_check_tokens($tokens)) break;
$ok = true;
} while (false);
if ($fatal && !$ok) {
$callback = $GLOBALS['csrf']['callback'];
if (trim($tokens, 'A..Za..z0..9:;,') !== '') $tokens = 'hidden';
$callback($tokens);
exit;
}
return $ok;
}
/**
* Retrieves a valid token(s) for a particular context. Tokens are separated
* by semicolons.
*/
function csrf_get_tokens() {
$has_cookies = !empty($_COOKIE);
// $ip implements a composite key, which is sent if the user hasn't sent
// any cookies. It may or may not be used, depending on whether or not
// the cookies "stick"
$secret = csrf_get_secret();
if (!$has_cookies && $secret) {
// :TODO: Harden this against proxy-spoofing attacks
$IP_ADDRESS = (isset($_SERVER['IP_ADDRESS']) ? $_SERVER['IP_ADDRESS'] : $_SERVER['REMOTE_ADDR']);
$ip = ';ip:' . csrf_hash($IP_ADDRESS);
} else {
$ip = '';
}
csrf_start();
// These are "strong" algorithms that don't require per se a secret
if (session_id()) return 'sid:' . csrf_hash(session_id()) . $ip;
if ($GLOBALS['csrf']['cookie']) {
$val = csrf_generate_secret();
setcookie($GLOBALS['csrf']['cookie'], $val);
return 'cookie:' . csrf_hash($val) . $ip;
}
if ($GLOBALS['csrf']['key']) return 'key:' . csrf_hash($GLOBALS['csrf']['key']) . $ip;
// These further algorithms require a server-side secret
if (!$secret) return 'invalid';
if ($GLOBALS['csrf']['user'] !== false) {
return 'user:' . csrf_hash($GLOBALS['csrf']['user']);
}
if ($GLOBALS['csrf']['allow-ip']) {
return ltrim($ip, ';');
}
return 'invalid';
}
function csrf_flattenpost($data) {
$ret = array();
foreach($data as $n => $v) {
$ret = array_merge($ret, csrf_flattenpost2(1, $n, $v));
}
return $ret;
}
function csrf_flattenpost2($level, $key, $data) {
if(!is_array($data)) return array($key => $data);
$ret = array();
foreach($data as $n => $v) {
$nk = $level >= 1 ? $key."[$n]" : "[$n]";
$ret = array_merge($ret, csrf_flattenpost2($level+1, $nk, $v));
}
return $ret;
}
/**
* @param $tokens is safe for HTML consumption
*/
function csrf_callback($tokens) {
// (yes, $tokens is safe to echo without escaping)
header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
$data = '';
foreach (csrf_flattenpost($_POST) as $key => $value) {
if ($key == $GLOBALS['csrf']['input-name']) continue;
$data .= '<input type="hidden" name="'.htmlspecialchars($key).'" value="'.htmlspecialchars($value).'" />';
}
echo "<html><head><title>CSRF check failed</title></head>
<body>
<p>CSRF check failed. Your form session may have expired, or you may not have
cookies enabled.</p>
<form method='post' action=''>$data<input type='submit' value='Try again' /></form>
<p>Debug: $tokens</p></body></html>
";
}
/**
* Checks if a composite token is valid. Outward facing code should use this
* instead of csrf_check_token()
*/
function csrf_check_tokens($tokens) {
if (is_string($tokens)) $tokens = explode(';', $tokens);
foreach ($tokens as $token) {
if (csrf_check_token($token)) return true;
}
return false;
}
/**
* Checks if a token is valid.
*/
function csrf_check_token($token) {
if (strpos($token, ':') === false) return false;
list($type, $value) = explode(':', $token, 2);
if (strpos($value, ',') === false) return false;
list($x, $time) = explode(',', $token, 2);
if ($GLOBALS['csrf']['expires']) {
if (time() > $time + $GLOBALS['csrf']['expires']) return false;
}
switch ($type) {
case 'sid':
return $value === csrf_hash(session_id(), $time);
case 'cookie':
$n = $GLOBALS['csrf']['cookie'];
if (!$n) return false;
if (!isset($_COOKIE[$n])) return false;
return $value === csrf_hash($_COOKIE[$n], $time);
case 'key':
if (!$GLOBALS['csrf']['key']) return false;
return $value === csrf_hash($GLOBALS['csrf']['key'], $time);
// We could disable these 'weaker' checks if 'key' was set, but
// that doesn't make me feel good then about the cookie-based
// implementation.
case 'user':
if (!csrf_get_secret()) return false;
if ($GLOBALS['csrf']['user'] === false) return false;
return $value === csrf_hash($GLOBALS['csrf']['user'], $time);
case 'ip':
if (!csrf_get_secret()) return false;
// do not allow IP-based checks if the username is set, or if
// the browser sent cookies
if ($GLOBALS['csrf']['user'] !== false) return false;
if (!empty($_COOKIE)) return false;
if (!$GLOBALS['csrf']['allow-ip']) return false;
$IP_ADDRESS = (isset($_SERVER['IP_ADDRESS']) ? $_SERVER['IP_ADDRESS'] : $_SERVER['REMOTE_ADDR']);
return $value === csrf_hash($IP_ADDRESS, $time);
}
return false;
}
/**
* Sets a configuration value.
*/
function csrf_conf($key, $val) {
if (!isset($GLOBALS['csrf'][$key])) {
trigger_error('No such configuration ' . $key, E_USER_WARNING);
return;
}
$GLOBALS['csrf'][$key] = $val;
}
/**
* Starts a session if we're allowed to.
*/
function csrf_start() {
if ($GLOBALS['csrf']['auto-session'] && !session_id()) {
session_start();
}
}
/**
* Retrieves the secret, and generates one if necessary.
*/
function csrf_get_secret() {
if ($GLOBALS['csrf']['secret']) return $GLOBALS['csrf']['secret'];
$dir = dirname(__FILE__);
$file = $dir . '/csrf-secret.php';
$secret = '';
if (file_exists($file)) {
include $file;
return $secret;
}
if (is_writable($dir)) {
$secret = csrf_generate_secret();
$fh = fopen($file, 'w');
fwrite($fh, '<?php $secret = "'.$secret.'";' . PHP_EOL);
fclose($fh);
return $secret;
}
return '';
}
/**
* Generates a random string as the hash of time, microtime, and mt_rand.
*/
function csrf_generate_secret($len = 32) {
$r = '';
for ($i = 0; $i < $len; $i++) {
$r .= chr(mt_rand(0, 255));
}
$r .= time() . microtime();
return sha1($r);
}
/**
* Generates a hash/expiry double. If time isn't set it will be calculated
* from the current time.
*/
function csrf_hash($value, $time = null) {
if (!$time) $time = time();
return sha1(csrf_get_secret() . $value . $time) . ',' . $time;
}
// Load user configuration
if (function_exists('csrf_startup')) csrf_startup();
// Initialize our handler
if ($GLOBALS['csrf']['rewrite']) ob_start('csrf_ob_handler');
// Perform check
if (!$GLOBALS['csrf']['defer']) csrf_check();

View File

@ -19,7 +19,7 @@
//
// Compatibility functions
if ( version_compare( phpversion(), "4.3.0", "<") ) {
if ( version_compare( phpversion(), '4.3.0', '<') ) {
function ob_get_clean() {
$buffer = ob_get_contents();
ob_end_clean();
@ -27,24 +27,24 @@ if ( version_compare( phpversion(), "4.3.0", "<") ) {
}
}
function userLogin( $username, $password="", $passwordHashed=false ) {
function userLogin( $username, $password='', $passwordHashed=false ) {
global $user, $cookies;
$sql = "select * from Users where Enabled = 1";
$sql = 'SELECT * FROM Users WHERE Enabled = 1';
$sql_values = NULL;
if ( ZM_AUTH_TYPE == "builtin" ) {
if ( ZM_AUTH_TYPE == 'builtin' ) {
if ( $passwordHashed ) {
$sql .= " AND Username=? AND Password=?";
$sql .= ' AND Username=? AND Password=?';
} else {
$sql .= " AND Username=? AND Password=password(?)";
$sql .= ' AND Username=? AND Password=password(?)';
}
$sql_values = array( $username, $password );
} else {
$sql .= " AND Username = ?";
$sql .= ' AND Username = ?';
$sql_values = array( $username );
}
$_SESSION['username'] = $username;
if ( ZM_AUTH_RELAY == "plain" ) {
if ( ZM_AUTH_RELAY == 'plain' ) {
// Need to save this in session
$_SESSION['password'] = $password;
}
@ -829,36 +829,38 @@ function packageControl( $command ) {
}
function daemonControl( $command, $daemon=false, $args=false ) {
$string = ZM_PATH_BIN."/zmdc.pl $command";
$string = escapeshellcmd(ZM_PATH_BIN).'/zmdc.pl '.$command;
if ( $daemon ) {
$string .= escapeshellarg(" $daemon");
#$string .= ' ' . $daemon;
$string .= ' ' . $daemon;
if ( $args ) {
$string .= escapeshellarg(" $args");
$string .= ' ' . $args;
#$string .= ' ' . $args;
}
}
$string .= " 2>/dev/null >&- <&- >/dev/null";
$string .= ' 2>/dev/null >&- <&- >/dev/null';
Debug("exec $string");
exec( $string );
}
function zmcControl( $monitor, $mode=false ) {
if ( (!defined('ZM_SERVER_ID')) or ( ZM_SERVER_ID==$monitor['ServerId'] ) ) {
$row = NULL;
if ( $monitor['Type'] == "Local" ) {
$row = dbFetchOne( "select count(if(Function!='None',1,NULL)) as ActiveCount from Monitors where Device = ?", NULL, array($monitor['Device']) );
$zmcArgs = "-d ".$monitor['Device'];
if ( $monitor['Type'] == 'Local' ) {
$row = dbFetchOne( "SELECT count(if(Function!='None',1,NULL)) AS ActiveCount FROM Monitors WHERE Device = ?", NULL, array($monitor['Device']) );
$zmcArgs = '-d '.escapeshellarg( $monitor['Device'] );
} else {
$row = dbFetchOne( "select count(if(Function!='None',1,NULL)) as ActiveCount from Monitors where Id = ?", NULL, array($monitor['Id']) );
$zmcArgs = "-m ".$monitor['Id'];
$row = dbFetchOne( "SELECT count(if(Function!='None',1,NULL)) AS ActiveCount FROM Monitors WHERE Id = ?", NULL, array($monitor['Id']) );
$zmcArgs = '-m '.$monitor['Id'];
}
$activeCount = $row['ActiveCount'];
if ( !$activeCount || $mode == "stop" ) {
daemonControl( "stop", "zmc", $zmcArgs );
if ( (!$activeCount) || ($mode == 'stop') ) {
daemonControl( 'stop', 'zmc', $zmcArgs );
} else {
if ( $mode == "restart" ) {
daemonControl( "stop", "zmc", $zmcArgs );
if ( $mode == 'restart' ) {
daemonControl( 'stop', 'zmc', $zmcArgs );
}
daemonControl( "start", "zmc", $zmcArgs );
daemonControl( 'start', 'zmc', $zmcArgs );
}
} else {
$Server = new Server( $monitor['ServerId'] );
@ -878,7 +880,6 @@ function zmcControl( $monitor, $mode=false ) {
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }
}
}
@ -937,34 +938,34 @@ function daemonStatus( $daemon, $args=false ) {
initDaemonStatus();
$string = "$daemon";
$string = $daemon;
if ( $args )
$string .= " $args";
$string .= ' ' . $args;
return( strpos( $daemon_status, "'$string' running" ) !== false );
}
function zmcStatus( $monitor ) {
if ( $monitor['Type'] == 'Local' ) {
$zmcArgs = "-d ".$monitor['Device'];
$zmcArgs = '-d '.$monitor['Device'];
} else {
$zmcArgs = "-m ".$monitor['Id'];
$zmcArgs = '-m '.$monitor['Id'];
}
return( daemonStatus( "zmc", $zmcArgs ) );
return( daemonStatus( 'zmc', $zmcArgs ) );
}
function zmaStatus( $monitor ) {
if ( is_array( $monitor ) ) {
$monitor = $monitor['Id'];
}
return( daemonStatus( "zma", "-m $monitor" ) );
return( daemonStatus( 'zma', "-m $monitor" ) );
}
function daemonCheck( $daemon=false, $args=false ) {
$string = ZM_PATH_BIN."/zmdc.pl check";
if ( $daemon ) {
$string .= escapeshellarg(" $daemon");
$string .= ' ' . escapeshellarg( $daemon );
if ( $args )
$string .= escapeshellarg(" $args");
$string .= ' ' . escapeshellarg( $args );
}
$result = exec( $string );
return( preg_match( '/running/', $result ) );
@ -972,18 +973,18 @@ function daemonCheck( $daemon=false, $args=false ) {
function zmcCheck( $monitor ) {
if ( $monitor['Type'] == 'Local' ) {
$zmcArgs = "-d ".$monitor['Device'];
$zmcArgs = '-d '.$monitor['Device'];
} else {
$zmcArgs = "-m ".$monitor['Id'];
$zmcArgs = '-m '.$monitor['Id'];
}
return( daemonCheck( "zmc", $zmcArgs ) );
return( daemonCheck( 'zmc', $zmcArgs ) );
}
function zmaCheck( $monitor ) {
if ( is_array( $monitor ) ) {
$monitor = $monitor['Id'];
}
return( daemonCheck( "zma", "-m $monitor" ) );
return( daemonCheck( 'zma', "-m $monitor" ) );
}
function getImageSrc( $event, $frame, $scale=SCALE_BASE, $captureOnly=false, $overwrite=false ) {
@ -1404,9 +1405,9 @@ function sortHeader( $field, $querySep='&amp;' ) {
function sortTag( $field ) {
if ( $_REQUEST['sort_field'] == $field )
if ( $_REQUEST['sort_asc'] )
return( "(^)" );
return( '(^)' );
else
return( "(v)" );
return( '(v)' );
return( false );
}
@ -1418,15 +1419,15 @@ function getLoad() {
function getDiskPercent($path = ZM_DIR_EVENTS) {
$total = disk_total_space($path);
if ( $total === false ) {
Error("disk_total_space returned false. Verify the web account user has access to " . $path );
Error('disk_total_space returned false. Verify the web account user has access to ' . $path );
return 0;
} elseif ( $total == 0 ) {
Error("disk_total_space indicates the following path has a filesystem size of zero bytes" . $path );
Error('disk_total_space indicates the following path has a filesystem size of zero bytes' . $path );
return 100;
}
$free = disk_free_space($path);
if ( $free === false ) {
Error("disk_free_space returned false. Verify the web account user has access to " . $path );
Error('disk_free_space returned false. Verify the web account user has access to ' . $path );
}
$space = round((($total - $free) / $total) * 100);
return( $space );
@ -2173,4 +2174,8 @@ function human_filesize($bytes, $decimals = 2) {
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
}
function csrf_startup() {
csrf_conf('rewrite-js', 'includes/csrf/csrf-magic.js');
}
?>

View File

@ -146,19 +146,10 @@ if ( ZM_OPT_USE_AUTH ) {
require_once( 'includes/lang.php' );
require_once( 'includes/functions.php' );
require_once( 'includes/csrf/csrf-magic.php' );
# Running is global but only do the daemonCheck if it is actually needed
$running = null;
#= daemonCheck();
#$states = dbFetchAll( 'SELECT * FROM States' );
#foreach ( $states as $state ) {
#if ( $state['IsActive'] == 1 ) {
#$run_state = $state['Name'];
#break;
#}
#}
#$status = $running?translate('Running'):translate('Stopped');
#$run_state = dbFetchOne('SELECT Name FROM States WHERE IsActive = 1', 'Name' );
# Add Cross domain access headers
CORSHeaders();
@ -168,9 +159,13 @@ if ( !is_writable(ZM_DIR_EVENTS) || !is_writable(ZM_DIR_IMAGES) ) {
Error( "Cannot write to content dirs('".ZM_DIR_EVENTS."','".ZM_DIR_IMAGES."'). Check that these exist and are owned by the web account user");
}
# Globals
$redirect = null;
$view = null;
if ( isset($_REQUEST['view']) )
$view = detaintPath($_REQUEST['view']);
$request = null;
if ( isset($_REQUEST['request']) )
$request = detaintPath($_REQUEST['request']);
@ -191,11 +186,25 @@ if ( ZM_OPT_USE_AUTH && ZM_AUTH_HASH_LOGINS ) {
if ( isset($_REQUEST['action']) ) {
$action = detaintPath($_REQUEST['action']);
}
# The only variable we really need to set is action. The others are informal.
isset($view) || $view = NULL;
isset($request) || $request = NULL;
isset($action) || $action = NULL;
if ( ZM_ENABLE_CSRF_MAGIC && $action != 'login' ) {
Debug("Calling csrf_check with the following values: \$request = \"$request\", \$view = \"$view\", \$action = \"$action\"");
if ( ! csrf_check() ) {
Warning( "Failed csrf_check()" );
return;
}
}
# Need to include actions because it does auth
require_once( 'includes/actions.php' );
# If I put this here, it protects all views and popups, but it has to go after actions.php because actions.php does the actual logging in.
if ( ZM_OPT_USE_AUTH && ! isset($user) && $view != 'login' ) {
if ( ZM_OPT_USE_AUTH && ! isset($user) ) {
$view = 'login';
}
@ -203,6 +212,11 @@ if ( ZM_OPT_USE_AUTH && ! isset($user) && $view != 'login' ) {
# Any file/page that sets session variables must re-open it.
session_write_close();
if ( $redirect ) {
header('Location: /index.php?view='.$view);
return;
}
if ( isset( $_REQUEST['request'] ) ) {
foreach ( getSkinIncludes( 'ajax/'.$request.'.php', true, true ) as $includeFile ) {
if ( !file_exists( $includeFile ) )

View File

@ -0,0 +1,35 @@
#ScaleDiv,
#SpeedDiv{
vertical-align: top;
display: inline-flex;
border: 1px solid black;
width: 25%;
padding: 9px;
}
#ScaleDiv label,
#SpeedDiv label {
margin: 0;
}
#scaleslideroutput,
#speedslideroutput {
min-width: 75px;
display: block;
}
#timelinediv {
margin: 2px auto;
position:relative;
width:93%;
}
#timeline {
border:1px solid;
}
#monitors {
position:relative;
background-color:black;
width:100%;
height:100%;
}

View File

@ -0,0 +1,35 @@
#ScaleDiv,
#SpeedDiv{
vertical-align: top;
display: inline-flex;
border: 1px solid black;
width: 25%;
padding: 9px;
}
#ScaleDiv label,
#SpeedDiv label {
margin: 0;
}
#scaleslideroutput,
#speedslideroutput {
min-width: 75px;
display: block;
}
#timelinediv {
margin: 2px auto;
position:relative;
width:93%;
}
#timeline {
border:1px solid;
}
#monitors {
position:relative;
background-color:black;
width:100%;
height:100%;
}

View File

@ -0,0 +1,35 @@
#ScaleDiv,
#SpeedDiv{
vertical-align: top;
display: inline-flex;
border: 1px solid black;
width: 25%;
padding: 9px;
}
#ScaleDiv label,
#SpeedDiv label {
margin: 0;
}
#scaleslideroutput,
#speedslideroutput {
min-width: 75px;
display: block;
}
#timelinediv {
margin: 2px auto;
position:relative;
width:93%;
}
#timeline {
border:1px solid;
}
#monitors {
position:relative;
background-color:black;
width:100%;
height:100%;
}

View File

@ -66,6 +66,6 @@ var popupSizes = {
'video': { 'width': 420, 'height': 360 },
'videoview': { 'addWidth': 48, 'addHeight': 80 },
'watch': { 'addWidth': 96, 'minWidth': 420, 'addHeight': 384 },
'zone': { 'addWidth': 450, 'addHeight': 200, 'minHeight': 450 },
'zone': { 'addWidth': 520, 'addHeight': 260, 'minHeight': 600 },
'zones': { 'addWidth': 72, 'addHeight': 232 }
};

View File

@ -66,6 +66,6 @@ var popupSizes = {
'video': { 'width': 420, 'height': 360 },
'videoview': { 'addWidth': 48, 'addHeight': 80 },
'watch': { 'addWidth': 96, 'minWidth': 420, 'addHeight': 384 },
'zone': { 'addWidth': 520, 'addHeight': 240, 'minHeight': 600 },
'zone': { 'addWidth': 520, 'addHeight': 260, 'minHeight': 600 },
'zones': { 'addWidth': 72, 'addHeight': 232 }
};

View File

@ -186,10 +186,13 @@ function refreshWindow()
window.location.reload( true );
}
function refreshParentWindow()
{
if ( window.opener )
window.opener.location.reload( true );
function refreshParentWindow() {
if ( window.opener ) {
if ( refreshParent == true )
window.opener.location.reload( true );
else
window.opener.location.href = refreshParent;
}
}
//Shows a message if there is an error in the streamObj or the stream doesn't exist. Returns true if error, false otherwise.
@ -270,20 +273,18 @@ function configureDeleteButton( element )
form.deleteBtn.disabled = !checked;
}
function confirmDelete( message )
{
function confirmDelete( message ) {
return( confirm( message?message:'Are you sure you wish to delete?' ) );
}
if ( refreshParent )
{
if ( refreshParent ) {
refreshParentWindow();
}
if ( focusWindow )
{
if ( focusWindow ) {
windowToFront();
}
window.addEvent( 'domready', checkSize);
function convertLabelFormat(LabelFormat, monitorName){

View File

@ -35,7 +35,18 @@ var canViewSystem = <?php echo canView('System' )?'true':'false' ?>;
var canEditGroups = <?php echo canEdit('Groups' )?'true':'false' ?>;
var refreshParent = <?php echo !empty($refreshParent)?'true':'false' ?>;
var refreshParent = <?php
if ( ! empty($refreshParent) ) {
if ( $refreshParent == true ) {
echo 'true';
return;
} else if ( $refreshParent ) {
echo "'$refreshParent'";
return;
}
}
echo 'false';
?>;
var focusWindow = <?php echo !empty($focusWindow)?'true':'false' ?>;

View File

@ -146,7 +146,7 @@ xhtmlHeaders( __FILE__, translate('Console') );
<?php for ( $i = 0; $i < count($eventCounts); $i++ ) { ?>
<th class="colEvents"><?php echo $eventCounts[$i]['title'] ?></th>
<?php } ?>
<th class="colZones"><?php echo translate('Zones') ?></th>
<th class="colZones"><a href="<?php echo $_SERVER['PHP_SELF'] ?>?view=zones_overview"><?php echo translate('Zones') ?></a></th>
<?php if ( canEdit('Monitors') ) { ?>
<th class="colMark"><?php echo translate('Mark') ?></th>
<?php } ?>

View File

@ -26,13 +26,13 @@ $selectName = 'Id';
$filterNames = array( ''=>translate('ChooseFilter') );
$dbFilter = NULL;
foreach ( dbFetchAll( "select * from Filters order by Name" ) as $row ) {
foreach ( dbFetchAll( 'SELECT * FROM Filters ORDER BY Name' ) as $row ) {
$filterNames[$row['Id']] = $row['Name'];
if ( $row['Background'] )
$filterNames[$row['Id']] .= "*";
$filterNames[$row['Id']] .= '*';
if ( $row['Concurrent'] )
$filterNames[$row['Id']] .= "&";
if ( !empty($_REQUEST['reload']) && isset($_REQUEST['Id']) && $_REQUEST['Id'] == $row['Id'] ) {
$filterNames[$row['Id']] .= '&';
if ( isset($_REQUEST['Id']) && $_REQUEST['Id'] == $row['Id'] ) {
$dbFilter = $row;
}
}
@ -41,10 +41,12 @@ $backgroundStr = '';
if ( $dbFilter ) {
if ( $dbFilter['Background'] )
$backgroundStr = '['.strtolower(translate('Background')).']';
if ( $dbFilter['Concurrent'] )
$backgroundStr .= '['.strtolower(translate('Concurrent')).']';
$_REQUEST['filter'] = jsonDecode( $dbFilter['Query'] );
$_REQUEST['sort_field'] = isset($_REQUEST['filter']['sort_field'])?$_REQUEST['filter']['sort_field']:"DateTime";
$_REQUEST['sort_asc'] = isset($_REQUEST['filter']['sort_asc'])?$_REQUEST['filter']['sort_asc']:"1";
$_REQUEST['limit'] = isset($_REQUEST['filter']['limit'])?$_REQUEST['filter']['limit']:"";
$_REQUEST['sort_field'] = isset($_REQUEST['filter']['sort_field'])?$_REQUEST['filter']['sort_field']:'DateTime';
$_REQUEST['sort_asc'] = isset($_REQUEST['filter']['sort_asc'])?$_REQUEST['filter']['sort_asc']:'1';
$_REQUEST['limit'] = isset($_REQUEST['filter']['limit'])?$_REQUEST['filter']['limit']:'';
unset( $_REQUEST['filter']['sort_field'] );
unset( $_REQUEST['filter']['sort_asc'] );
unset( $_REQUEST['filter']['limit'] );
@ -71,8 +73,8 @@ $obracketTypes = array();
$cbracketTypes = array();
if ( isset($_REQUEST['filter']['terms']) ) {
for ( $i = 0; $i <= count($_REQUEST['filter']['terms'])-2; $i++ ) {
$obracketTypes[$i] = str_repeat( "(", $i );
$cbracketTypes[$i] = str_repeat( ")", $i );
$obracketTypes[$i] = str_repeat( '(', $i );
$cbracketTypes[$i] = str_repeat( ')', $i );
}
}

View File

@ -18,21 +18,18 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
if ( !canEdit( 'Events' ) )
{
$view = "error";
if ( !canEdit( 'Events' ) ) {
$view = 'error';
return;
}
$selectName = "Id";
$newSelectName = "newFilterName";
foreach ( dbFetchAll( "select * from Filters order by Name" ) as $row )
{
$filterNames[$row['Id']] = $row['Name'];
if ( $_REQUEST['Id'] == $row['Id'] )
{
$filterData = $row;
}
$selectName = 'Id';
$newSelectName = 'newFilterName';
foreach ( dbFetchAll( 'SELECT * FROM Filters ORDER BY Name' ) as $row ) {
$filterNames[$row['Id']] = $row['Name'];
if ( $_REQUEST['Id'] == $row['Id'] ) {
$filterData = $row;
}
}
$focusWindow = true;
@ -64,13 +61,14 @@ xhtmlHeaders(__FILE__, translate('SaveFilter') );
<input type="hidden" name="AutoExecute" value="<?php echo requestVar( 'AutoExecute' ) ?>"/>
<input type="hidden" name="AutoExecuteCmd" value="<?php echo requestVar( 'AutoExecuteCmd' ) ?>"/>
<input type="hidden" name="AutoDelete" value="<?php echo requestVar( 'AutoDelete' ) ?>"/>
<input type="hidden" name="Id" value="<?php echo $filterData['Id'] ?>"/>
<?php if ( count($filterNames) ) { ?>
<p>
<label for="<?php echo $selectName ?>"><?php echo translate('SaveAs') ?></label><?php echo buildSelect( $selectName, $filterNames ); ?><label for="<?php echo $newSelectName ?>"><?php echo translate('OrEnterNewName') ?></label><input type="text" size="32" id="<?php echo $newSelectName ?>" name="<?php echo $newSelectName ?>" value="<?php echo requestVar('filterName') ?>"/>
</p>
<?php } else { ?>
<p>
<label for="<?php echo $newSelectName ?>"><?php echo translate('EnterNewFilterName') ?></label><input type="text" size="32" id="<?php echo $newSelectName ?>" name="<?php echo $newSelectName ?>" value="">
<label for="<?php echo $newSelectName ?>"><?php echo translate('EnterNewFilterName') ?></label><input type="text" id="<?php echo $newSelectName ?>" name="<?php echo $newSelectName ?>" />
</p>
<?php } ?>
<p>

View File

@ -85,7 +85,7 @@ function deleteFilter( element, id, name )
{
var form = element.form;
form.action.value = 'delete';
submitToFilter( element, 1 );
submitToFilter( element, 0 );
}
}

View File

@ -111,7 +111,7 @@ function previewEvent( eventId, frameId )
if ( event['frames'][frameId] )
{
showEventDetail( event['frames'][frameId]['html'] );
var imagePath = event.frames[frameId].Image.imagePath;
var imagePath = '/index.php?view=image&eid='+eventId+'&fid='+frameId;
var videoName = event.DefaultVideo;
loadEventImage( imagePath, eventId, frameId, event.Width, event.Height, event.Frames/event.Length, videoName, event.Length, event.StartTime, monitors[event.MonitorId]);
return;
@ -125,11 +125,10 @@ function loadEventImage( imagePath, eid, fid, width, height, fps, videoName, dur
{
var vid= $('preview');
var imageSrc = $('imageSrc');
if(videoName)
{
if ( videoName && vid ) {
vid.show();
imageSrc.hide();
var newsource=imagePrefix+imagePath.slice(0,imagePath.lastIndexOf('/'))+"/"+videoName;
var newsource=imagePath.slice(0,imagePath.lastIndexOf('/'))+"/"+videoName;
//console.log(newsource);
//console.log(sources[0].src.slice(-newsource.length));
if(newsource!=vid.currentSrc.slice(-newsource.length) || vid.readyState==0)
@ -154,9 +153,9 @@ function loadEventImage( imagePath, eid, fid, width, height, fps, videoName, dur
}
else
{
vid.hide();
if ( vid ) vid.hide();
imageSrc.show();
imageSrc.setProperty( 'src', imagePrefix+imagePath );
imageSrc.setProperty( 'src', imagePath );
imageSrc.removeEvent( 'click' );
imageSrc.addEvent( 'click', showEvent.pass( [ eid, fid, width, height ] ) );
}

View File

@ -1,89 +1,60 @@
function validateForm( form )
{
function validateForm( form ) {
var errors = new Array();
if ( selfIntersecting )
{
if ( selfIntersecting ) {
errors[errors.length] = selfIntersectingString;
}
if ( form.elements['newZone[Type]'].value != 'Inactive' && form.elements['newZone[Type]'].value != 'Privacy' )
{
if ( !form.newAlarmRgbR.value || !form.newAlarmRgbG.value || !form.newAlarmRgbB.value )
{
if ( form.elements['newZone[Type]'].value != 'Inactive' && form.elements['newZone[Type]'].value != 'Privacy' ) {
if ( !form.newAlarmRgbR.value || !form.newAlarmRgbG.value || !form.newAlarmRgbB.value ) {
errors[errors.length] = alarmRGBUnsetString;
}
form.elements['newZone[AlarmRGB]'].value = (form.newAlarmRgbR.value<<16)|(form.newAlarmRgbG.value<<8)|form.newAlarmRgbB.value;
if ( !form.elements['newZone[MinPixelThreshold]'].value || (parseInt(form.elements['newZone[MinPixelThreshold]'].value) <= 0 ) )
{
if ( !form.elements['newZone[MinPixelThreshold]'].value || (parseInt(form.elements['newZone[MinPixelThreshold]'].value) <= 0 ) ) {
errors[errors.length] = minPixelThresUnsetString;
}
else if ( (parseInt(form.elements['newZone[MinPixelThreshold]'].value) >= parseInt(form.elements['newZone[MaxPixelThreshold]'].value)) && (parseInt(form.elements['newZone[MaxPixelThreshold]'].value) > 0) )
{
} else if ( (parseInt(form.elements['newZone[MinPixelThreshold]'].value) >= parseInt(form.elements['newZone[MaxPixelThreshold]'].value)) && (parseInt(form.elements['newZone[MaxPixelThreshold]'].value) > 0) ) {
errors[errors.length] = minPixelThresLtMaxString;
}
if ( form.elements['newZone[CheckMethod]'].value == 'FilteredPixels' || form.elements['newZone[CheckMethod]'].value == 'Blobs' )
{
if ( !form.elements['newZone[FilterX]'].value || !form.elements['newZone[FilterY]'].value )
{
if ( form.elements['newZone[CheckMethod]'].value == 'FilteredPixels' || form.elements['newZone[CheckMethod]'].value == 'Blobs' ) {
if ( !form.elements['newZone[FilterX]'].value || !form.elements['newZone[FilterY]'].value ) {
errors[errors.length] = filterUnsetString;
}
}
if ( !form.elements['newZone[MinAlarmPixels]'].value || (parseFloat(form.elements['newZone[MinAlarmPixels]'].value) <= 0 ) )
{
if ( !form.elements['newZone[MinAlarmPixels]'].value || (parseFloat(form.elements['newZone[MinAlarmPixels]'].value) <= 0 ) ) {
errors[errors.length] = minAlarmAreaUnsetString;
}
else if ( (parseFloat(form.elements['newZone[MinAlarmPixels]'].value) >= parseFloat(form.elements['newZone[MaxAlarmPixels]'].value)) && (parseFloat(form.elements['newZone[MaxAlarmPixels]'].value) > 0) )
{
} else if ( (parseFloat(form.elements['newZone[MinAlarmPixels]'].value) >= parseFloat(form.elements['newZone[MaxAlarmPixels]'].value)) && (parseFloat(form.elements['newZone[MaxAlarmPixels]'].value) > 0) ) {
errors[errors.length] = minAlarmAreaLtMaxString;
}
if ( form.elements['newZone[CheckMethod]'].value == 'FilteredPixels' || form.elements['newZone[CheckMethod]'].value == 'Blobs' )
{
if ( !form.elements['newZone[MinFilterPixels]'].value || (parseFloat(form.elements['newZone[MinFilterPixels]'].value) <= 0 ) )
{
if ( form.elements['newZone[CheckMethod]'].value == 'FilteredPixels' || form.elements['newZone[CheckMethod]'].value == 'Blobs' ) {
if ( !form.elements['newZone[MinFilterPixels]'].value || (parseFloat(form.elements['newZone[MinFilterPixels]'].value) <= 0 ) ) {
errors[errors.length] = minFilterAreaUnsetString;
}
else if ( (parseFloat(form.elements['newZone[MinFilterPixels]'].value) >= parseFloat(form.elements['newZone[MaxFilterPixels]'].value)) && (parseFloat(form.elements['newZone[MaxFilterPixels]'].value) > 0) )
{
} else if ( (parseFloat(form.elements['newZone[MinFilterPixels]'].value) >= parseFloat(form.elements['newZone[MaxFilterPixels]'].value)) && (parseFloat(form.elements['newZone[MaxFilterPixels]'].value) > 0) ) {
errors[errors.length] = minFilterAreaLtMaxString;
}
else if ( parseFloat(form.elements['newZone[MinAlarmPixels]'].value) < parseFloat(form.elements['newZone[MinFilterPixels]'].value) )
{
} else if ( parseFloat(form.elements['newZone[MinAlarmPixels]'].value) < parseFloat(form.elements['newZone[MinFilterPixels]'].value) ) {
errors[errors.length] = minFilterLtMinAlarmString;
}
if ( form.elements['newZone[CheckMethod]'].value == 'Blobs' )
{
if ( !form.elements['newZone[MinBlobPixels]'].value || (parseFloat(form.elements['newZone[MinBlobPixels]'].value) <= 0 ) )
{
if ( form.elements['newZone[CheckMethod]'].value == 'Blobs' ) {
if ( !form.elements['newZone[MinBlobPixels]'].value || (parseFloat(form.elements['newZone[MinBlobPixels]'].value) <= 0 ) ) {
errors[errors.length] = minBlobAreaUnsetString;
}
else if ( (parseFloat(form.elements['newZone[MinBlobPixels]'].value) >= parseFloat(form.elements['newZone[MaxBlobPixels]'].value)) && (parseFloat(form.elements['newZone[MaxBlobPixels]'].value) > 0) )
{
} else if ( (parseFloat(form.elements['newZone[MinBlobPixels]'].value) >= parseFloat(form.elements['newZone[MaxBlobPixels]'].value)) && (parseFloat(form.elements['newZone[MaxBlobPixels]'].value) > 0) ) {
errors[errors.length] = minBlobAreaLtMaxString;
}
else if ( parseFloat(form.elements['newZone[MinFilterPixels]'].value) < parseFloat(form.elements['newZone[MinBlobPixels]'].value) )
{
} else if ( parseFloat(form.elements['newZone[MinFilterPixels]'].value) < parseFloat(form.elements['newZone[MinBlobPixels]'].value) ) {
errors[errors.length] = minBlobLtMinFilterString;
}
if ( !form.elements['newZone[MinBlobs]'].value || (parseInt(form.elements['newZone[MinBlobs]'].value) <= 0 ) )
{
if ( !form.elements['newZone[MinBlobs]'].value || (parseInt(form.elements['newZone[MinBlobs]'].value) <= 0 ) ) {
errors[errors.length] = minBlobsUnsetString;
}
else if ( (parseInt(form.elements['newZone[MinBlobs]'].value) >= parseInt(form.elements['newZone[MaxBlobs]'].value)) && (parseInt(form.elements['newZone[MaxBlobs]'].value) > 0) )
{
} else if ( (parseInt(form.elements['newZone[MinBlobs]'].value) >= parseInt(form.elements['newZone[MaxBlobs]'].value)) && (parseInt(form.elements['newZone[MaxBlobs]'].value) > 0) ) {
errors[errors.length] = minBlobsLtMaxString;
}
}
}
}
if ( errors.length )
{
if ( errors.length ) {
alert( errors.join( "\n" ) );
return( false );
}
return( true );
}
function submitForm( form )
{
function submitForm( form ) {
form.elements['newZone[AlarmRGB]'].value = (form.newAlarmRgbR.value<<16)|(form.newAlarmRgbG.value<<8)|form.newAlarmRgbB.value;
form.elements['newZone[NumCoords]'].value = zone['Points'].length;
form.elements['newZone[Coords]'].value = getCoordString();
@ -92,11 +63,9 @@ function submitForm( form )
form.submit();
}
function applyZoneType()
{
function applyZoneType() {
var form = document.zoneForm;
if ( form.elements['newZone[Type]'].value == 'Inactive' || form.elements['newZone[Type]'].value == 'Privacy' )
{
if ( form.elements['newZone[Type]'].value == 'Inactive' || form.elements['newZone[Type]'].value == 'Privacy' ) {
form.presetSelector.disabled = true;
form.newAlarmRgbR.disabled = true;
form.newAlarmRgbG.disabled = true;
@ -116,9 +85,7 @@ function applyZoneType()
form.elements['newZone[MaxBlobs]'].disabled = true;
form.elements['newZone[OverloadFrames]'].disabled = true;
form.elements['newZone[ExtendAlarmFrames]'].disabled = true;
}
else if ( form.elements['newZone[Type]'].value == 'Preclusive' )
{
} else if ( form.elements['newZone[Type]'].value == 'Preclusive' ) {
form.presetSelector.disabled = false;
form.newAlarmRgbR.disabled = true;
form.newAlarmRgbG.disabled = true;
@ -131,9 +98,7 @@ function applyZoneType()
form.elements['newZone[OverloadFrames]'].disabled = false;
form.elements['newZone[ExtendAlarmFrames]'].disabled = false;
applyCheckMethod();
}
else
{
} else {
form.presetSelector.disabled = false;
form.newAlarmRgbR.disabled = false;
form.newAlarmRgbG.disabled = false;
@ -149,11 +114,9 @@ function applyZoneType()
}
}
function applyCheckMethod()
{
function applyCheckMethod() {
var form = document.zoneForm;
if ( form.elements['newZone[CheckMethod]'].value == 'AlarmedPixels' )
{
if ( form.elements['newZone[CheckMethod]'].value == 'AlarmedPixels' ) {
form.elements['newZone[FilterX]'].disabled = true;
form.elements['newZone[FilterY]'].disabled = true;
form.elements['newZone[MinFilterPixels]'].disabled = true;
@ -162,9 +125,7 @@ function applyCheckMethod()
form.elements['newZone[MaxBlobPixels]'].disabled = true;
form.elements['newZone[MinBlobs]'].disabled = true;
form.elements['newZone[MaxBlobs]'].disabled = true;
}
else if ( form.elements['newZone[CheckMethod]'].value == 'FilteredPixels' )
{
} else if ( form.elements['newZone[CheckMethod]'].value == 'FilteredPixels' ) {
form.elements['newZone[FilterX]'].disabled = false;
form.elements['newZone[FilterY]'].disabled = false;
form.elements['newZone[MinFilterPixels]'].disabled = false;
@ -173,9 +134,7 @@ function applyCheckMethod()
form.elements['newZone[MaxBlobPixels]'].disabled = true;
form.elements['newZone[MinBlobs]'].disabled = true;
form.elements['newZone[MaxBlobs]'].disabled = true;
}
else
{
} else {
form.elements['newZone[FilterX]'].disabled = false;
form.elements['newZone[FilterY]'].disabled = false;
form.elements['newZone[MinFilterPixels]'].disabled = false;
@ -187,13 +146,11 @@ function applyCheckMethod()
}
}
function applyPreset()
{
function applyPreset() {
var form = document.zoneForm;
var presetId = $('presetSelector').get('value');
if ( presets[presetId] )
{
if ( presets[presetId] ) {
var preset = presets[presetId];
form.elements['newZone[Units]'].selectedIndex = preset['UnitsIndex'];
@ -218,25 +175,21 @@ function applyPreset()
}
}
function toPixels( field, maxValue )
{
function toPixels( field, maxValue ) {
if ( field.value != '' )
field.value = Math.round((field.value*maxValue)/100);
}
function toPercent( field, maxValue )
{
function toPercent( field, maxValue ) {
if ( field.value != '' )
field.value = Math.round((100*100*field.value)/maxValue)/100;
}
function applyZoneUnits()
{
function applyZoneUnits() {
var area = zone.Area;
var form = document.zoneForm;
if ( form.elements['newZone[Units]'].value == 'Pixels' )
{
if ( form.elements['newZone[Units]'].value == 'Pixels' ) {
form.elements['newZone[TempArea]'].value = area;
toPixels( form.elements['newZone[MinAlarmPixels]'], area );
toPixels( form.elements['newZone[MaxAlarmPixels]'], area );
@ -244,9 +197,7 @@ function applyZoneUnits()
toPixels( form.elements['newZone[MaxFilterPixels]'], area );
toPixels( form.elements['newZone[MinBlobPixels]'], area );
toPixels( form.elements['newZone[MaxBlobPixels]'], area );
}
else
{
} else {
form.elements['newZone[TempArea]'].value = Math.round( area/monitorArea * 100 );
toPercent( form.elements['newZone[MinAlarmPixels]'], area );
toPercent( form.elements['newZone[MaxAlarmPixels]'], area );
@ -257,63 +208,54 @@ function applyZoneUnits()
}
}
function limitRange( field, minValue, maxValue )
{
field.value = constrainValue( parseInt(field.value), parseInt(minValue), parseInt(maxValue) );
function limitRange( field, minValue, maxValue ) {
if ( field.value != '' )
field.value = constrainValue( parseInt(field.value), parseInt(minValue), parseInt(maxValue) );
}
function limitFilter( field )
{
function limitFilter( field ) {
field.value = (Math.floor((field.value-1)/2)*2) + 1;
field.value = constrainValue(parseInt(field.value), 3, 15);
}
function limitArea( field )
{
function limitArea( field ) {
var minValue = 0;
var maxValue = zone.Area;
if ( document.zoneForm.elements['newZone[Units]'].value == "Percent" )
{
if ( document.zoneForm.elements['newZone[Units]'].value == "Percent" ) {
maxValue = 100;
}
limitRange( field, minValue, maxValue );
}
function highlightOn( index )
{
function highlightOn( index ) {
$('row'+index).addClass( 'highlight' );
$('point'+index).addClass( 'highlight' );
}
function highlightOff( index )
{
function highlightOff( index ) {
$('row'+index).removeClass( 'highlight' );
$('point'+index).removeClass( 'highlight' );
}
function setActivePoint( index )
{
function setActivePoint( index ) {
highlightOff( index );
$('row'+index).addClass( 'active' );
$('point'+index).addClass( 'active' );
}
function unsetActivePoint( index )
{
function unsetActivePoint( index ) {
$('row'+index).removeClass( 'active' );
$('point'+index).removeClass( 'active' );
}
function getCoordString()
{
function getCoordString() {
var coords = new Array();
for ( var i = 0; i < zone['Points'].length; i++ )
coords[coords.length] = zone['Points'][i].x+','+zone['Points'][i].y;
return( coords.join( " " ) );
}
function updateZoneImage()
{
function updateZoneImage() {
var SVG = $('zoneSVG');
var Poly = $('zonePoly');
Poly.points.clear();
@ -325,15 +267,13 @@ function updateZoneImage()
}
}
function fixActivePoint( index )
{
function fixActivePoint( index ) {
updateActivePoint( index );
unsetActivePoint( index );
updateZoneImage();
}
function constrainValue( value, loVal, hiVal )
{
function constrainValue( value, loVal, hiVal ) {
if ( value < loVal ) {
return loVal;
}
@ -343,8 +283,7 @@ function constrainValue( value, loVal, hiVal )
return value;
}
function updateActivePoint( index )
{
function updateActivePoint( index ) {
var point = $('point'+index);
var x = constrainValue( point.getStyle( 'left' ).toInt(), 0, maxX );
var y = constrainValue( point.getStyle( 'top' ).toInt(), 0, maxY );
@ -359,8 +298,7 @@ function updateActivePoint( index )
updateArea();
}
function addPoint( index )
{
function addPoint( index ) {
var nextIndex = index+1;
if ( index >= (zone['Points'].length-1) )
nextIndex = 0;
@ -376,15 +314,13 @@ function addPoint( index )
//setActivePoint( nextIndex );
}
function delPoint( index )
{
function delPoint( index ) {
zone['Points'].splice( index, 1 );
drawZonePoints();
}
function limitPointValue( point, loVal, hiVal )
{
point.value = constrainValue(point.value, loVal, hiVal)
function limitPointValue( point, loVal, hiVal ) {
point.value = constrainValue(point.value, loVal, hiVal);
}
function updateArea( ) {
@ -402,8 +338,7 @@ function updateArea( ) {
}
}
function updateX( index )
{
function updateX( index ) {
limitPointValue( $('newZone[Points]['+index+'][x]'), 0, maxX );
var point = $('point'+index);
@ -415,8 +350,7 @@ function updateX( index )
Point.x = x;
}
function updateY( index )
{
function updateY( index ) {
limitPointValue( $('newZone[Points]['+index+'][y]'), 0, maxY );
var point = $('point'+index);
@ -428,14 +362,11 @@ function updateY( index )
Point.y = y;
}
function saveChanges( element )
{
function saveChanges( element ) {
var form = element.form;
if ( validateForm( form ) )
{
if ( validateForm( form ) ) {
submitForm( form );
if ( form.elements['newZone[Type]'].value == 'Privacy' )
{
if ( form.elements['newZone[Type]'].value == 'Privacy' ) {
alert( 'Capture process for this monitor will be restarted for the Privacy zone changes to take effect.' );
}
return( true );
@ -443,22 +374,24 @@ function saveChanges( element )
return( false );
}
function drawZonePoints()
{
function drawZonePoints() {
$('imageFrame').getElements( 'div.zonePoint' ).each( function( element ) { element.destroy(); } );
for ( var i = 0; i < zone['Points'].length; i++ )
{
for ( var i = 0; i < zone['Points'].length; i++ ) {
var div = new Element( 'div', { 'id': 'point'+i, 'class': 'zonePoint', 'title': 'Point '+(i+1), 'styles': { 'left': zone['Points'][i].x, 'top': zone['Points'][i].y } } );
div.addEvent( 'mouseover', highlightOn.pass( i ) );
div.addEvent( 'mouseout', highlightOff.pass( i ) );
div.inject( $('imageFrame') );
div.makeDraggable( { 'container': $('imageFrame'), 'onStart': setActivePoint.pass( i ), 'onComplete': fixActivePoint.pass( i ), 'onDrag': updateActivePoint.pass( i ) } );
div.makeDraggable( {
'container': $('imageFrame'),
'onStart': setActivePoint.pass( i ),
'onComplete': fixActivePoint.pass( i ),
'onDrag': updateActivePoint.pass( i )
} );
}
var tables = $('zonePoints').getElements( 'table' );
tables.each( function( table ) { table.getElement( 'tbody' ).empty(); } );
for ( var i = 0; i < zone['Points'].length; i++ )
{
for ( var i = 0; i < zone['Points'].length; i++ ) {
var row = new Element( 'tr', { 'id': 'row'+i } );
row.addEvents( { 'mouseover': highlightOn.pass( i ), 'mouseout': highlightOff.pass( i ) } );
var cell = new Element( 'td' );
@ -647,17 +580,14 @@ function fetchImage( streamImage ) {
}
function appletRefresh() {
if ( streamStatus && (!streamStatus.paused && !streamStatus.delayed) )
{
if ( streamStatus && (!streamStatus.paused && !streamStatus.delayed) ) {
var streamImg = $('liveStream');
var parent = streamImg.getParent();
streamImg.dispose();
streamImg.inject( parent );
if ( appletRefreshTime )
appletRefresh.delay( appletRefreshTime*1000 );
}
else
{
} else {
appletRefresh.delay( 15*1000 ); //if we are paused or delayed check every 15 seconds if we are live yet...
}
}

View File

@ -768,22 +768,22 @@ switch ( $tab )
<tr><td><?php echo translate('Triggers') ?></td><td>
<?php
$optTriggers = getSetValues( 'Monitors', 'Triggers' );
$breakCount = (int)(ceil(count($optTriggers)));
$breakCount = min( 3, $breakCount );
$optCount = 0;
foreach( $optTriggers as $optTrigger )
{
if ( !ZM_OPT_X10 && $optTrigger == 'X10' )
continue;
if ( $optCount && ($optCount%$breakCount == 0) )
echo "</br>";
?>
<input type="checkbox" name="newMonitor[Triggers][]" value="<?php echo $optTrigger ?>"<?php if ( isset($monitor->Triggers) && in_array( $optTrigger, $monitor->Triggers ) ) { ?> checked="checked"<?php } ?>/>&nbsp;<?php echo $optTrigger ?>
<?php
$breakCount = (int)(ceil(count($optTriggers)));
$breakCount = min( 3, $breakCount );
$optCount = 0;
foreach( $optTriggers as $optTrigger ) {
if ( ( ! ZM_OPT_X10 ) && ( $optTrigger == 'X10' ) )
continue;
if ( $optCount && ($optCount%$breakCount == 0) )
echo '</br>';
echo '<input type="checkbox" name="newMonitor[Triggers][]" value="'. $optTrigger .'"';
if ( isset($monitor->Triggers) && is_array( $monitor->Triggers ) and in_array( $optTrigger, $monitor->Triggers ) ) {
echo ' checked="checked"';
}
echo '/>&nbsp;'. $optTrigger ;
$optCount ++;
}
if ( !$optCount )
{
if ( !$optCount ) {
?>
<em><?php echo translate('NoneAvailable') ?></em>
<?php

View File

@ -27,10 +27,10 @@ require_once( 'includes/Monitor.php' );
$groupSql = '';
if ( !empty($_REQUEST['group']) ) {
$row = dbFetchOne( 'select * from Groups where Id = ?', NULL, array($_REQUEST['group']) );
$sql = "select * from Monitors where Function != 'None' and find_in_set( Id, '".$row['MonitorIds']."' ) order by Sequence";
$row = dbFetchOne( 'SELECT * FROM Groups WHERE Id = ?', NULL, array($_REQUEST['group']) );
$sql = "SELECT * FROM Monitors WHERE Function != 'None' AND find_in_set( Id, '".$row['MonitorIds']."' ) ORDER BY Sequence";
} else {
$sql = "select * from Monitors where Function != 'None' order by Sequence";
$sql = "SELECT * FROM Monitors WHERE Function != 'None' ORDER BY Sequence";
}
$showControl = false;
@ -66,7 +66,7 @@ foreach( dbFetchAll( $sql ) as $row ) {
$row['Scale'] = $scale;
$row['PopupScale'] = reScale( SCALE_BASE, $row['DefaultScale'], ZM_WEB_DEFAULT_SCALE );
if ( ZM_OPT_CONTROL && $row['ControlId'] )
if ( ZM_OPT_CONTROL && $row['ControlId'] && $row['Controllable'] )
$showControl = true;
$row['connKey'] = generateConnKey();
$monitors[] = new Monitor( $row );

View File

@ -95,34 +95,35 @@
//
if ( !canView( 'Events' ) ) {
$view = "error";
$view = 'error';
return;
}
require_once( 'includes/Monitor.php' );
# FIXME THere is no way to select group at this time.
if ( !empty($_REQUEST['group']) ) {
$group = $_REQUEST['group'];
$row = dbFetchOne( 'select * from Groups where Id = ?', NULL, array($_REQUEST['group']) );
$monitorsSql = "select * from Monitors where Function != 'None' and find_in_set( Id, '".$row['MonitorIds']."' ) ";
$row = dbFetchOne( 'SELECT * FROM Groups WHERE Id = ?', NULL, array($_REQUEST['group']) );
$monitorsSql = "SELECT * FROM Monitors WHERE Function != 'None' AND find_in_set( Id, '".$row['MonitorIds']."' ) ";
} else {
$monitorsSql = "select * from Monitors ";
$group = "";
$monitorsSql = "SELECT * FROM Monitors WHERE 1>0";
$group = '';
}
// Note that this finds incomplete events as well, and any frame records written, but still cannot "see" to the end frame
// if the bulk record has not been written - to be able to include more current frames reduce bulk frame sizes (event size can be large)
// Note we round up just a bit on the end time as otherwise you get gaps, like 59.78 to 00 in the next second, which can give blank frames when moved through slowly.
$eventsSql = "
select E.Id,E.Name,E.StorageId,UNIX_TIMESTAMP(E.StartTime) as StartTimeSecs,
case when E.EndTime is null then (Select UNIX_TIMESTAMP(DATE_ADD(E.StartTime, Interval max(Delta)+0.5 Second)) from Frames F where F.EventId=E.Id)
else UNIX_TIMESTAMP(E.EndTime)
end as CalcEndTimeSecs, E.Length,
case when E.Frames is null then (Select count(*) from Frames F where F.EventId=E.Id) else E.Frames end as Frames,E.MaxScore,E.Cause,E.Notes,E.Archived,E.MonitorId
from Events as E
inner join Monitors as M on (E.MonitorId = M.Id)
where not isnull(E.Frames) and not isnull(StartTime) ";
$eventsSql = '
SELECT E.Id,E.Name,E.StorageId,UNIX_TIMESTAMP(E.StartTime) AS StartTimeSecs,
CASE WHEN E.EndTime IS NULL THEN (SELECT UNIX_TIMESTAMP(DATE_ADD(E.StartTime, Interval max(Delta)+0.5 Second)) FROM Frames F WHERE F.EventId=E.Id)
ELSE UNIX_TIMESTAMP(E.EndTime)
END AS CalcEndTimeSecs, E.Length,
CASE WHEN E.Frames IS NULL THEN (Select count(*) FROM Frames F WHERE F.EventId=E.Id) ELSE E.Frames END AS Frames,E.MaxScore,E.Cause,E.Notes,E.Archived,E.MonitorId
FROM Events AS E
INNER JOIN Monitors AS M ON (E.MonitorId = M.Id)
WHERE NOT isnull(E.Frames) AND NOT isnull(StartTime)';
@ -133,20 +134,19 @@ $eventsSql = "
// where not isnull(E.Frames) and not isnull(StartTime) ";
// Note that the delta value seems more accurate than the time stamp for some reason.
$frameSql = "
select E.Id as eId, E.MonitorId, UNIX_TIMESTAMP(DATE_ADD(E.StartTime, Interval Delta Second)) as TimeStampSecs, max(F.Score) as Score
from Events as E
inner join Frames as F on (F.EventId = E.Id)
where not isnull(StartTime) and F.Score>0 ";
$frameSql = '
SELECT E.Id AS eId, E.MonitorId, UNIX_TIMESTAMP(DATE_ADD(E.StartTime, Interval Delta Second)) AS TimeStampSecs, max(F.Score) AS Score
FROM Events AS E
INNER JOIN Frames AS F ON (F.EventId = E.Id)
WHERE NOT isnull(StartTime) AND F.Score>0';
// This program only calls itself with the time range involved -- it does all monitors (the user can see, in the called group) all the time
if ( !empty($user['MonitorIds']) )
{
if ( ! empty( $user['MonitorIds'] ) ) {
$monFilterSql = ' AND M.Id IN ('.$user['MonitorIds'].')';
$eventsSql .= $monFilterSql;
$monitorsSQL .= $monFilterSql;
$monitorsSql .= ' AND Id IN ('.$user['MonitorIds'].')';
$frameSql .= ' AND E.MonitorId IN ('.$user['MonitorIds'].')';
}
@ -156,87 +156,82 @@ if ( !empty($user['MonitorIds']) )
// The default (nothing at all specified) is for 1 hour so we do not read the whole database
if ( !isset($_REQUEST['minTime']) && !isset($_REQUEST['maxTime']) )
{
$maxTime=strftime("%c",time());
$minTime=strftime("%c",time() - 3600);
if ( !isset($_REQUEST['minTime']) && !isset($_REQUEST['maxTime']) ) {
$maxTime = strftime("%c",time());
$minTime = strftime("%c",time() - 3600);
}
if ( isset($_REQUEST['minTime']) )
$minTime = validHtmlStr($_REQUEST['minTime']);
$minTime = validHtmlStr($_REQUEST['minTime']);
if ( isset($_REQUEST['maxTime']) )
$maxTime = validHtmlStr($_REQUEST['maxTime']);
$maxTime = validHtmlStr($_REQUEST['maxTime']);
// AS a special case a "all" is passed in as an exterme interval - if so , clear them here and let the database query find them
if ( (strtotime($maxTime) - strtotime($minTime))/(365*24*3600) > 30 ) // test years
{
$minTime=null;
$maxTime=null;
if ( (strtotime($maxTime) - strtotime($minTime))/(365*24*3600) > 30 ) {
// test years
$minTime = null;
$maxTime = null;
}
$fitMode=1;
if (isset($_REQUEST['fit']) && $_REQUEST['fit']=='0' )
$fitMode=0;
$fitMode = 0;
if ( isset($_REQUEST['scale']) )
$defaultScale=validHtmlStr($_REQUEST['scale']);
$defaultScale = validHtmlStr($_REQUEST['scale']);
else
$defaultScale=1;
$defaultScale = 1;
$speeds=[0, 0.1, 0.25, 0.5, 0.75, 1.0, 1.5, 2, 3, 5, 10, 20, 50];
if (isset($_REQUEST['speed']) )
$defaultSpeed=validHtmlStr($_REQUEST['speed']);
$defaultSpeed = validHtmlStr($_REQUEST['speed']);
else
$defaultSpeed=1;
$defaultSpeed = 1;
$speedIndex=5; // default to 1x
for ($i=0; $i<count($speeds); $i++)
if($speeds[$i]==$defaultSpeed)
{
$speedIndex=$i;
break;
}
for ($i=0; $i<count($speeds); $i++) {
if($speeds[$i]==$defaultSpeed) {
$speedIndex=$i;
break;
}
}
if (isset($_REQUEST['current']) )
$defaultCurrentTime=validHtmlStr($_REQUEST['current']);
$defaultCurrentTime=validHtmlStr($_REQUEST['current']);
$initialModeIsLive=1;
if(isset($_REQUEST['live']) && $_REQUEST['live']=='0' )
$initialModeIsLive=0;
$initialModeIsLive=0;
$initialDisplayInterval=1000;
if(isset($_REQUEST['displayinterval']))
$initialDisplayInterval=validHtmlStr($_REQUEST['displayinterval']);
$initialDisplayInterval=validHtmlStr($_REQUEST['displayinterval']);
$eventsSql .= "group by E.Id,E.Name,E.StartTime,E.Length,E.Frames,E.MaxScore,E.Cause,E.Notes,E.Archived,E.MonitorId ";
$eventsSql .= ' GROUP BY E.Id,E.Name,E.StartTime,E.Length,E.Frames,E.MaxScore,E.Cause,E.Notes,E.Archived,E.MonitorId';
if( isset($minTime) && isset($maxTime) )
{
$minTimeSecs = strtotime($minTime);
$maxTimeSecs = strtotime($maxTime);
$eventsSql .= "having CalcEndTimeSecs > '" . $minTimeSecs . "' and StartTimeSecs < '" . $maxTimeSecs . "'";
$frameSql .= "and TimeStamp > '" . $minTime . "' and TimeStamp < '" . $maxTime . "'";
if( isset($minTime) && isset($maxTime) ) {
$minTimeSecs = strtotime($minTime);
$maxTimeSecs = strtotime($maxTime);
$eventsSql .= " HAVING CalcEndTimeSecs > '" . $minTimeSecs . "' AND StartTimeSecs < '" . $maxTimeSecs . "'";
$frameSql .= " AND TimeStamp > '" . $minTime . "' AND TimeStamp < '" . $maxTime . "'";
}
$frameSql .= "group by E.Id, E.MonitorId, F.TimeStamp, F.Delta order by E.MonitorId, F.TimeStamp asc";
$frameSql .= ' GROUP BY E.Id, E.MonitorId, F.TimeStamp, F.Delta ORDER BY E.MonitorId, F.TimeStamp ASC';
// This loads all monitors the user can see - even if we don't have data for one we still show all for switch to live.
$monitors = array();
$monitorsSql .= ' ORDER BY Sequence ASC ';
$monitorsSql .= ' ORDER BY Sequence ASC';
$index=0;
foreach( dbFetchAll( $monitorsSql ) as $row )
{
$monitors[$index] = $row;
$index = $index + 1;
foreach( dbFetchAll( $monitorsSql ) as $row ) {
$monitors[$index] = $row;
$index = $index + 1;
}
// These are zoom ranges per visible monitor
xhtmlHeaders(__FILE__, translate('MontageReview') );
?>
<style>
@ -252,29 +247,29 @@ input[type=range]::-ms-tooltip {
</div>
<h2><?php echo translate('MontageReview') ?></h2>
</div>
<div id="ScaleDiv" style="display: inline-flex; border: 1px solid black;">
<label style="margin:5px;" for="scaleslider"><?php echo translate('Scale')?></label>
<input id=scaleslider type=range min=0.1 max=1.0 value=<?php echo $defaultScale ?> step=0.10 width=20% onchange='setScale(this.value)' oninput='showScale(this.value)'/>
<span style='margin:5px;' id=scaleslideroutput><?php echo number_format((float)$defaultScale,2,'.','')?> x</span>
<div id="ScaleDiv">
<label for="scaleslider"><?php echo translate('Scale')?></label>
<input id="scaleslider" type="range" min="0.1" max="1.0" value="<?php echo $defaultScale ?>" step="0.10" onchange="setScale(this.value);" oninput="showScale(this.value);"/>
<span id="scaleslideroutput"><?php echo number_format((float)$defaultScale,2,'.','')?> x</span>
</div>
<div id="SpeedDiv" style='display: inline-flex; border: 1px solid black;'>
<label style='margin:5px;' for=speedslider><?php echo translate('Speed') ?></label>
<input id=speedslider type=range min=0 max=<?php echo count($speeds)-1?> value=<?php echo $speedIndex ?> step=1 wdth=20% onchange='setSpeed(this.value)' oninput='showSpeed(this.value)'/>
<span style='margin:5px;' id=speedslideroutput><?php echo $speeds[$speedIndex] ?> fps</span>
<div id="SpeedDiv">
<label for="speedslider"><?php echo translate('Speed') ?></label>
<input id="speedslider" type="range" min="0" max="<?php echo count($speeds)-1?>" value="<?php echo $speedIndex ?>" step="1" onchange="setSpeed(this.value);" oninput="showSpeed(this.value);"/>
<span id="speedslideroutput"><?php echo $speeds[$speedIndex] ?> fps</span>
</div>
<div style='display: inline-flex; border: 1px solid black; flex-flow: row wrap;'>
<button type="button" id=panleft onclick='panleft() '>&lt; <?php echo translate('Pan') ?></button>
<button type="button" id=zoomin onclick='zoomin() '><?php echo translate('In +') ?></button>
<button type="button" id=zoomout onclick='zoomout() '><?php echo translate('Out -') ?></button>
<button type="button" id=lasteight onclick='lastEight() '><?php echo translate('8 Hour') ?></button>
<button type="button" id=lasthour onclick='lastHour() '><?php echo translate('1 Hour') ?></button>
<button type="button" id=allof onclick='allof() '><?php echo translate('All Events') ?></button>
<button type="button" id=live onclick='setLive(1-liveMode)'><?php echo translate('Live') ?></button>
<button type="button" id=fit onclick='setFit(1-fitMode) '><?php echo translate('Fit') ?></button>
<button type="button" id=panright onclick='panright() '><?php echo translate('Pan') ?> &gt;</button>
<div style="display: inline-flex; border: 1px solid black; flex-flow: row wrap;">
<button type="button" id="panleft" onclick="panleft();" >&lt; <?php echo translate('Pan') ?></button>
<button type="button" id="zoomin" onclick="zoomin();" ><?php echo translate('In +') ?></button>
<button type="button" id="zoomout" onclick="zoomout();" ><?php echo translate('Out -') ?></button>
<button type="button" id="lasteight" onclick="lastEight();" ><?php echo translate('8 Hour') ?></button>
<button type="button" id="lasthour" onclick="lastHour();" ><?php echo translate('1 Hour') ?></button>
<button type="button" id="allof" onclick="allof();" ><?php echo translate('All Events') ?></button>
<button type="button" id="live" onclick="setLive(1-liveMode);"><?php echo translate('Live') ?></button>
<button type="button" id="fit" onclick="setFit(1-fitMode);" ><?php echo translate('Fit') ?></button>
<button type="button" id="panright" onclick="panright();" ><?php echo translate('Pan') ?> &gt;</button>
</div>
<div id="timelinediv" style="position:relative; width:93%;">
<canvas id="timeline" style="border:1px solid;" onmousemove="mmove(event);" ontouchmove="tmove(event);" onmousedown="mdown(event);" onmouseup="mup(event);" onmouseout="mout(event);"></canvas>
<div id="timelinediv">
<canvas id="timeline" onmousemove="mmove(event);" ontouchmove="tmove(event);" onmousedown="mdown(event);" onmouseup="mup(event);" onmouseout="mout(event);"></canvas>
<span id="scrubleft"></span>
<span id="scrubright"></span>
<span id="scruboutput"></span>
@ -282,14 +277,13 @@ input[type=range]::-ms-tooltip {
<?php
// Monitor images - these had to be loaded after the monitors used were determined (after loading events)
echo "<div id='monitors' style='position:relative; background-color:black;' width='100%' height='100%'>\n";
echo '<div id="monitors">';
foreach ($monitors as $m) {
echo "<canvas width='" . $m['Width'] * $defaultScale . "px' height='" . $m['Height'] * $defaultScale . "px' id='Monitor" . $m['Id'] . "' style='border:3px solid " . $m['WebColour'] . "' onclick='clickMonitor(event," . $m['Id'] . ")'>No Canvas Support!!</canvas>\n";
echo '<canvas width="' . $m['Width'] * $defaultScale . 'px" height="' . $m['Height'] * $defaultScale . 'px" id="Monitor' . $m['Id'] . '" style="border:3px solid ' . $m['WebColour'] . '" onclick="clickMonitor(event,' . $m['Id'] . ')">No Canvas Support!!</canvas>';
}
echo "</div>\n";
echo "<p id='fps'>evaluating fps</p>\n";
echo "<script>\n";
echo "<p id=\"fps\">evaluating fps</p>\n";
echo "<script type=\"text/javascript\">\n";
?>
var currentScale=<?php echo $defaultScale?>;
@ -325,19 +319,22 @@ $index=0;
$anyAlarms=false;
foreach( dbFetchAll( $eventsSql ) as $event ) {
if( $minTimeSecs > $event['StartTimeSecs']) $minTimeSecs=$event['StartTimeSecs'];
if( $maxTimeSecs < $event['CalcEndTimeSecs']) $maxTimeSecs=$event['CalcEndTimeSecs'];
echo "eMonId[$index]=" . $event['MonitorId'] . "; eId[$index]=" . $event['Id'] . "; ";
echo "eStartSecs[$index]=" . $event['StartTimeSecs'] . "; eEndSecs[$index]=" . $event['CalcEndTimeSecs'] . "; ";
echo "eventFrames[$index]=" . $event['Frames'] . "; ";
if( $minTimeSecs > $event['StartTimeSecs']) $minTimeSecs = $event['StartTimeSecs'];
if( $maxTimeSecs < $event['CalcEndTimeSecs']) $maxTimeSecs = $event['CalcEndTimeSecs'];
echo "eMonId[$index]=" . $event['MonitorId'] . ";
eId[$index]=" . $event['Id'] . ";
eStartSecs[$index]=" . $event['StartTimeSecs'] . ";
eEndSecs[$index]=" . $event['CalcEndTimeSecs'] . ";
eventFrames[$index]=" . $event['Frames'] . "; ";
// NO GOOD, need to use view=image
if ( ZM_USE_DEEP_STORAGE )
echo "ePath[$index] = \"events/" . $event['MonitorId'] . "/" . strftime("%y/%m/%d/%H/%M/%S", $event['StartTimeSecs']) . "/\";" ;
else
echo "ePath[$index] = \"events/" . $event['MonitorId'] . "/" . $event['Id'] . "/\";" ;
$index=$index+1;
$index = $index + 1;
if($event['MaxScore']>0)
$anyAlarms=true;
$anyAlarms = true;
echo "\n";
}
@ -463,13 +460,13 @@ echo "var minTimeSecs=" . $minTimeSecs . ";\n";
echo "var maxTimeSecs=" . $maxTimeSecs . ";\n";
echo "var rangeTimeSecs=" . ( $maxTimeSecs - $minTimeSecs + 1) . ";\n";
if(isset($defaultCurrentTime))
echo "var currentTimeSecs=" . strtotime($defaultCurrentTime) . ";\n";
echo "var currentTimeSecs=" . strtotime($defaultCurrentTime) . ";\n";
else
echo "var currentTimeSecs=" . ($minTimeSecs + $maxTimeSecs)/2 . ";\n";
echo "var currentTimeSecs=" . ($minTimeSecs + $maxTimeSecs)/2 . ";\n";
echo "var speeds=[";
for ($i=0; $i<count($speeds); $i++)
echo (($i>0)?", ":"") . $speeds[$i];
echo (($i>0)?", ":"") . $speeds[$i];
echo "];\n";
?>
@ -481,24 +478,23 @@ var ctx=canvas.getContext('2d');
var underSlider; // use this to hold what is hidden by the slider
var underSliderX; // Where the above was taken from (left side, Y is zero)
function evaluateLoadTimes()
{ // Only consider it a completed event if we load ALL monitors, then zero all and start again
function evaluateLoadTimes() {
// Only consider it a completed event if we load ALL monitors, then zero all and start again
var start=0;
var end=0;
if(liveMode!=1 && currentSpeed==0) return; // don't evaluate when we are not moving as we can do nothing really fast.
for(var i=0; i<monitorIndex.length; i++)
if( monitorName[i]>"")
{
for(var i=0; i<monitorIndex.length; i++) {
if( monitorName[i]>"") {
if( monitorLoadEndTimems[i]==0) return; // if we have a monitor with no time yet just wait
if( start == 0 || start > monitorLoadStartTimems[i] ) start = monitorLoadStartTimems[i];
if( end == 0 || end < monitorLoadEndTimems[i] ) end = monitorLoadEndTimems[i];
}
}
if(start==0 || end==0) return; // we really should not get here
for(var i=0; i<numMonitors; i++)
{
monitorLoadStartTimems[monitorPtr[i]]=0;
monitorLoadEndTimems[monitorPtr[i]]=0;
}
for(var i=0; i<numMonitors; i++) {
monitorLoadStartTimems[monitorPtr[i]]=0;
monitorLoadEndTimems[monitorPtr[i]]=0;
}
freeTimeLastIntervals[imageLoadTimesEvaluated++] = 1 - ((end - start)/currentDisplayInterval);
if( imageLoadTimesEvaluated < imageLoadTimesNeeded ) return;
var avgFrac=0;

View File

@ -18,7 +18,7 @@
//
if ( !canView( 'Events' ) ) {
$view = "error";
$view = 'error';
return;
}
@ -33,8 +33,8 @@ foreach ( getSkinIncludes( 'includes/timeline_functions.php' ) as $includeFile )
//
// When the chart range is years
define( "STRF_TL_AXIS_RANGE_YEAR1", "%b %Y" );
define( "STRF_TL_AXIS_RANGE_YEAR2", STRF_TL_AXIS_RANGE_YEAR1 );
define( 'STRF_TL_AXIS_RANGE_YEAR1', '%b %Y' );
define( 'STRF_TL_AXIS_RANGE_YEAR2', STRF_TL_AXIS_RANGE_YEAR1 );
// When the chart range is months
define( "STRF_TL_AXIS_RANGE_MONTH1", "%b" );
@ -140,8 +140,8 @@ foreach( dbFetchAll( $monitorsSql ) as $row ) {
$monitors[$row['Id']] = $row;
}
$rangeSql = "select min(E.StartTime) as MinTime, max(E.EndTime) as MaxTime from Events as E inner join Monitors as M on (E.MonitorId = M.Id) where not isnull(E.StartTime) and not isnull(E.EndTime)";
$eventsSql = "select E.Id,E.Name,E.StartTime,E.EndTime,E.Length,E.Frames,E.MaxScore,E.Cause,E.Notes,E.Archived,E.MonitorId from Events as E inner join Monitors as M on (E.MonitorId = M.Id) where not isnull(StartTime)";
$rangeSql = 'select min(E.StartTime) as MinTime, max(E.EndTime) as MaxTime from Events as E inner join Monitors as M on (E.MonitorId = M.Id) where not isnull(E.StartTime) and not isnull(E.EndTime)';
$eventsSql = 'select E.* from Events as E inner join Monitors as M on (E.MonitorId = M.Id) where not isnull(StartTime)';
if ( !empty($user['MonitorIds']) ) {
$monFilterSql = ' AND M.Id IN ('.$user['MonitorIds'].')';
@ -706,10 +706,12 @@ xhtmlHeaders(__FILE__, translate('Timeline') );
//due to chrome bug, has to enable https://code.google.com/p/chromium/issues/detail?id=472300
//crossorigin has to be added below to make caption work in chrome
?>
<!--
<video id="preview" width="100%" controls crossorigin="anonymous">
<source src="" type="video/mp4">
Your browser does not support the video tag.
</video>
o-->
</div>
</div>

View File

@ -162,7 +162,13 @@ xhtmlHeaders(__FILE__, translate('Zone') );
</tr>
<tr>
<th scope="row"><?php echo translate('ZoneAlarmColour') ?></th>
<td colspan="2"><input type="text" name="newAlarmRgbR" value="<?php echo ($newZone['AlarmRGB']>>16)&0xff ?>" size="3" onchange="limitRange( this, 0, 255 )"/>&nbsp;/&nbsp;<input type="text" name="newAlarmRgbG" value="<?php echo ($newZone['AlarmRGB']>>8)&0xff ?>" size="3" onchange="limitRange( this, 0, 255 )"/>&nbsp;/&nbsp;<input type="text" name="newAlarmRgbB" value="<?php echo $newZone['AlarmRGB']&0xff ?>" size="3" onchange="limitRange( this, 0, 255 )"/></td>
<td colspan="2">
<input type="text" name="newAlarmRgbR" value="<?php echo ($newZone['AlarmRGB']>>16)&0xff ?>" size="3" onchange="limitRange( this, 0, 255 )"/>
/
<input type="text" name="newAlarmRgbG" value="<?php echo ($newZone['AlarmRGB']>>8)&0xff ?>" size="3" onchange="limitRange( this, 0, 255 )"/>
/
<input type="text" name="newAlarmRgbB" value="<?php echo $newZone['AlarmRGB']&0xff ?>" size="3" onchange="limitRange( this, 0, 255 )"/>
</td>
</tr>
<tr>
<th scope="row"><?php echo translate('CheckMethod') ?></th>

View File

@ -56,6 +56,7 @@ $errorText = false;
$filename = '';
$Frame = null;
$Event = null;
$path = null;
if ( empty($_REQUEST['path']) ) {
if ( ! empty($_REQUEST['fid']) ) {
@ -75,7 +76,9 @@ if ( empty($_REQUEST['path']) ) {
$path = $Event->Path().'/'.sprintf('%0'.ZM_EVENT_IMAGE_DIGITS.'d',$Frame->FrameId()).'-'.$show.'.jpg';
} else {
$errorText = 'No image path';
Fatal("No Frame ID specified");
header("HTTP/1.0 404 Not Found");
return;
}
if ( ! file_exists( $path ) ) {

View File

@ -26,7 +26,7 @@
//
if ( !canView( 'Events' ) ) {
$view = "error";
$view = 'error';
return;
}
@ -45,7 +45,7 @@ if ( ! empty($_REQUEST['eid'] ) ) {
if ( $errorText ) {
Error( $errorText );
header ("HTTP/1.0 404 Not Found");
header ('HTTP/1.0 404 Not Found');
die();
}
@ -99,7 +99,8 @@ while( $length && ( ! feof( $fh ) ) && ( connection_status() == 0 ) ) {
print fread( $fh, $amount );
$length -= $amount;
usleep(100);
usleep(10);
flush();
}
fclose( $fh );

View File

@ -54,7 +54,7 @@
#cmakedefine HAVE_LIBSWSCALE 1
#cmakedefine HAVE_LIBSWSCALE_SWSCALE_H 1
#cmakedefine HAVE_LIBSWRESAMPLE 1
#cmakedefine HAVE_LIBSWRESMAPLE_SWSCALE_H 1
#cmakedefine HAVE_LIBSWRESAMPLE_SWRESAMPLE_H 1
#cmakedefine HAVE_LIBVLC 1
#cmakedefine HAVE_VLC_VLC_H 1
#cmakedefine HAVE_LIBX264 1