diff --git a/onvif/modules/lib/ONVIF/Client.pm b/onvif/modules/lib/ONVIF/Client.pm
index eaf78747d..c835caca9 100644
--- a/onvif/modules/lib/ONVIF/Client.pm
+++ b/onvif/modules/lib/ONVIF/Client.pm
@@ -77,6 +77,8 @@ my %soap_version_of :ATTR(:default<('1.1')>);
sub service
{
my ($self, $serviceName, $attr) = @_;
+#print "service: " . $services_of{${$self}}{$serviceName}{$attr} . "\n";
+# Please note that the Std::Class::Fast docs say not to use ident.
$services_of{ident $self}{$serviceName}{$attr};
}
@@ -113,27 +115,59 @@ sub set_soap_version
delete $serializer_of{ ident $self };
}
-sub get_service_urls
-{
+sub get_service_urls {
my ($self) = @_;
my $result = $self->service('device', 'ep')->GetServices( {
IncludeCapability => 'true', # boolean
},,
);
-
- die $result if not $result;
-# print $result . "\n";
-
- foreach my $svc ( @{ $result->get_Service() } ) {
- my $short_name = $namespace_map{$svc->get_Namespace()};
- my $url_svc = $svc->get_XAddr()->get_value();
- if(defined $short_name && defined $url_svc) {
+ if ( $result ) {
+ foreach my $svc ( @{ $result->get_Service() } ) {
+ my $short_name = $namespace_map{$svc->get_Namespace()};
+ my $url_svc = $svc->get_XAddr()->get_value();
+ if(defined $short_name && defined $url_svc) {
# print "Got $short_name service\n";
- $self->set_service($short_name, 'url', $url_svc);
+ $self->set_service($short_name, 'url', $url_svc);
+ }
}
+ # } else {
+ #print "No results from GetServices: $result\n";
}
-}
+
+ # Some devices do not support getServices, so we have to try getCapabilities
+
+ $result = $self->service('device', 'ep')->GetCapabilities( {}, , );
+ if ( ! $result ) {
+ print "No results from GetCapabilities: $result\n";
+ return;
+ }
+ # Result is a GetCapabilitiesResponse
+ foreach my $capabilities ( @{ $result->get_Capabilities() } ) {
+ foreach my $capability ( 'PTZ', 'Media', 'Imaging', 'Events', 'Device' ) {
+ if ( my $function = $capabilities->can( "get_$capability" ) ) {
+ my $Services = $function->( $capabilities );
+ if ( ! $Services ) {
+ print "Nothing returned ffrom get_$capability\n";
+ } else {
+ foreach my $svc ( @{ $Services } ) {
+ # The capability versions don't have a namespace, so just lowercase them.
+ my $short_name = lc $capability;
+ my $url_svc = $svc->get_XAddr()->get_value();
+ if( defined $url_svc) {
+# print "Got $short_name service\n";
+ $self->set_service($short_name, 'url', $url_svc);
+ }
+ } # end foreach svr
+ }
+ } else {
+ print "No $capability function\n";
+
+ } # end if has a get_ function
+ } # end foreach capability
+ } # end foreach capabilities
+
+} # end sub get_service_urls
sub http_digest {
my ($service, $username, $password) = @_;
diff --git a/onvif/modules/lib/ONVIF/Deserializer/MessageParser.pm b/onvif/modules/lib/ONVIF/Deserializer/MessageParser.pm
index b0ce6f0fd..0e4b6dcfb 100644
--- a/onvif/modules/lib/ONVIF/Deserializer/MessageParser.pm
+++ b/onvif/modules/lib/ONVIF/Deserializer/MessageParser.pm
@@ -272,7 +272,11 @@ sub _initialize {
#
$_method =~s{\.}{__}xg;
$_method =~s{\-}{_}xg;
- $list->[-1]->$_method( $current );
+ if ( $list->[-1]->can( $_method ) ) {
+ $list->[-1]->$_method( $current );
+ } else {
+ print ( "ERror " . $list->[-1] . " cannot $_method\n" );
+ }
$current = pop @$list; # step up in object hierarchy
diff --git a/onvif/modules/lib/WSDiscovery/TransportUDP.pm b/onvif/modules/lib/WSDiscovery/TransportUDP.pm
index 007fcf053..911146f4d 100644
--- a/onvif/modules/lib/WSDiscovery/TransportUDP.pm
+++ b/onvif/modules/lib/WSDiscovery/TransportUDP.pm
@@ -120,8 +120,8 @@ sub send_receive {
my ($address,$port) = ($endpoint =~ /([^:\/]+):([0-9]+)/);
-# warn "address = ${address}";
-# warn "port = ${port}";
+ #warn "address = ${address}";
+ #warn "port = ${port}";
$self->send_multi($address, $port, $envelope);
diff --git a/onvif/proxy/lib/WSDiscovery10/Elements/Probe.pm b/onvif/proxy/lib/WSDiscovery10/Elements/Probe.pm
index e07ec2510..33e3c5f96 100644
--- a/onvif/proxy/lib/WSDiscovery10/Elements/Probe.pm
+++ b/onvif/proxy/lib/WSDiscovery10/Elements/Probe.pm
@@ -15,6 +15,7 @@ __PACKAGE__->__set_ref();
use base qw(
SOAP::WSDL::XSD::Typelib::Element
WSDiscovery10::Types::ProbeType
+ WSDiscovery10::Types::ProbeMatchesType
);
}
diff --git a/onvif/scripts/zmonvif-probe.pl b/onvif/scripts/zmonvif-probe.pl
index 10aa26a08..a5aee9574 100755
--- a/onvif/scripts/zmonvif-probe.pl
+++ b/onvif/scripts/zmonvif-probe.pl
@@ -1,4 +1,5 @@
#!/usr/bin/perl -w
+use strict;
#
# ==========================================================================
#
@@ -41,6 +42,7 @@ require WSDiscovery::TransportUDP;
# Globals
my $verbose = 0;
+my $soap_version = undef;
my $client;
# =========================================================================
@@ -171,61 +173,66 @@ sub discover
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({
+ 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');
+ });
+ $svc_discover->set_soap_version('1.1');
- my $uuid = $uuid_gen->create_str();
+ 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";
+ 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;
- interpret_messages($svc_discover, \%services, @responses);
- @responses = ();
+ interpret_messages($svc_discover, \%services, @responses);
+ @responses = ();
+ } # end if doing soap 1.1
- if($verbose) {
- print "Probing for SOAP 1.2\n"
- }
- $svc_discover = WSDiscovery10::Interfaces::WSDiscovery::WSDiscoveryPort->new({
+ 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');
+ });
+ $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.
- $uuid = $uuid_gen->create_str();
+# 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();
- $result = $svc_discover->ProbeOp(
- { # WSDiscovery::Types::ProbeType
- xmlattr => { 'xmlns:dn' => 'http://www.onvif.org/ver10/network/wsdl',
- 'xmlns:tds' => 'http://www.onvif.org/ver10/device/wsdl', },
- Types => 'dn:NetworkVideoTransmitter tds: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";
+# 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;
+ interpret_messages($svc_discover, \%services, @responses);
+ } # end if doing soap 1.2
- interpret_messages($svc_discover, \%services, @responses);
}
@@ -321,7 +328,7 @@ my $OPTIONS = "v";
sub HELP_MESSAGE
{
my ($fh, $pkg, $ver, $opts) = @_;
- print $fh "Usage: " . __FILE__ . " [-v] probe \n";
+ print $fh "Usage: " . __FILE__ . " [-v] probe \n";
print $fh " " . __FILE__ . " [-v] \n";
print $fh <new( {
'url_svc_device' => $url_svc_device,
diff --git a/src/zm_image.cpp b/src/zm_image.cpp
index e73b20bcc..e3147a998 100644
--- a/src/zm_image.cpp
+++ b/src/zm_image.cpp
@@ -152,11 +152,13 @@ Image::Image( const Image &p_image )
strncpy( text, p_image.text, sizeof(text) );
}
-Image::~Image()
-{
+Image::~Image() {
DumpImgBuffer();
- if ( initialised )
- {
+}
+
+/* Should be called as part of program shutdown to free everything */
+void Image::Deinitialise() {
+ if ( initialised ) {
/*
delete[] y_table;
delete[] uv_table;
@@ -166,30 +168,25 @@ Image::~Image()
delete[] b_u_table;
*/
initialised = false;
- }
- if ( readjpg_dcinfo )
- {
- jpeg_destroy_decompress( readjpg_dcinfo );
- delete readjpg_dcinfo;
- readjpg_dcinfo = 0;
- }
- if ( decodejpg_dcinfo )
- {
- jpeg_destroy_decompress( decodejpg_dcinfo );
- delete decodejpg_dcinfo;
- decodejpg_dcinfo = 0;
- }
-#if 0
-+// This creates a memleak because it isn't de-allocating the structures and it's doing it on every Image construct/destruct.
-+// We need to refactor this code big time.
-
- for ( unsigned int quality=0; quality <= 100; quality += 1 ) {
- if ( writejpg_ccinfo[quality] ) {
- delete writejpg_ccinfo[quality];
- writejpg_ccinfo[quality] = NULL;
+ if ( readjpg_dcinfo ) {
+ jpeg_destroy_decompress( readjpg_dcinfo );
+ delete readjpg_dcinfo;
+ readjpg_dcinfo = 0;
}
- } // end foreach quality
-#endif
+ if ( decodejpg_dcinfo )
+ {
+ jpeg_destroy_decompress( decodejpg_dcinfo );
+ delete decodejpg_dcinfo;
+ decodejpg_dcinfo = 0;
+ }
+ for ( unsigned int quality=0; quality <= 100; quality += 1 ) {
+ if ( writejpg_ccinfo[quality] ) {
+ jpeg_destroy_compress( writejpg_ccinfo[quality] );
+ delete writejpg_ccinfo[quality];
+ writejpg_ccinfo[quality] = NULL;
+ }
+ } // end foreach quality
+ }
}
void Image::Initialise()
diff --git a/src/zm_image.h b/src/zm_image.h
index b63157c03..7afa84d5e 100644
--- a/src/zm_image.h
+++ b/src/zm_image.h
@@ -137,7 +137,6 @@ protected:
static jpeg_decompress_struct *decodejpg_dcinfo;
static struct zm_error_mgr jpg_err;
-protected:
unsigned int width;
unsigned int height;
unsigned int pixels;
@@ -150,8 +149,6 @@ protected:
int holdbuffer; /* Hold the buffer instead of replacing it with new one */
char text[1024];
-protected:
- static void Initialise();
public:
Image();
@@ -159,6 +156,8 @@ public:
Image( int p_width, int p_height, int p_colours, int p_subpixelorder, uint8_t *p_buffer=0);
Image( const Image &p_image );
~Image();
+ static void Initialise();
+ static void Deinitialise();
inline unsigned int Width() const { return( width ); }
inline unsigned int Height() const { return( height ); }
diff --git a/src/zma.cpp b/src/zma.cpp
index 03ffe1726..b9483d7c9 100644
--- a/src/zma.cpp
+++ b/src/zma.cpp
@@ -198,6 +198,7 @@ int main( int argc, char *argv[] )
{
fprintf( stderr, "Can't find monitor with id of %d\n", id );
}
+ Image::Deinitialise();
logTerm();
zmDbClose();
return( 0 );
diff --git a/src/zmc.cpp b/src/zmc.cpp
index 76b16e6d0..0cef211a0 100644
--- a/src/zmc.cpp
+++ b/src/zmc.cpp
@@ -358,6 +358,7 @@ int main( int argc, char *argv[] )
delete [] next_delays;
delete [] last_capture_times;
+ Image::Deinitialise();
logTerm();
zmDbClose();
diff --git a/web/includes/actions.php b/web/includes/actions.php
index 710221e45..8cf17ff6e 100644
--- a/web/includes/actions.php
+++ b/web/includes/actions.php
@@ -44,7 +44,7 @@ function do_post_request($url, $data, $optional_headers = null) {
}
function getAffectedIds( $name ) {
- $names = $name."s";
+ $names = $name.'s';
$ids = array();
if ( isset($_REQUEST[$names]) || isset($_REQUEST[$name]) ) {
if ( isset($_REQUEST[$names]) )
@@ -67,10 +67,10 @@ if ( ZM_OPT_USE_AUTH && ZM_AUTH_HASH_LOGINS ) {
}
if ( !empty($action) ) {
- if ( $action == "login" && isset($_REQUEST['username']) && ( ZM_AUTH_TYPE == "remote" || isset($_REQUEST['password']) ) ) {
+ if ( $action == 'login' && isset($_REQUEST['username']) && ( ZM_AUTH_TYPE == 'remote' || isset($_REQUEST['password']) ) ) {
// if true, a popup will display after login
// PP - lets validate reCaptcha if it exists
- if ( defined('ZM_OPT_USE_GOOG_RECAPTCHA')
+ if ( defined('ZM_OPT_USE_GOOG_RECAPTCHA')
&& defined('ZM_OPT_GOOG_RECAPTCHA_SECRETKEY')
&& defined('ZM_OPT_GOOG_RECAPTCHA_SITEKEY')
&& ZM_OPT_USE_GOOG_RECAPTCHA && ZM_OPT_GOOG_RECAPTCHA_SECRETKEY
@@ -94,7 +94,7 @@ if ( !empty($action) ) {
// as it produces the same error as when you don't answer a recaptcha
if (isset($responseData['error-codes']) && is_array($responseData['error-codes'])) {
if (!in_array('invalid-input-secret',$responseData['error-codes'])) {
- Error ("reCaptcha authentication failed");
+ Error ('reCaptcha authentication failed');
userLogout();
$view='login';
$refreshParent = true;
@@ -107,24 +107,19 @@ if ( !empty($action) ) {
} // end if success==false
} // end if using reCaptcha
- }
- // General scope actions
- if ( $action == "login" && isset($_REQUEST['username']) && ( ZM_AUTH_TYPE == "remote" || isset($_REQUEST['password']) ) ) {
$username = validStr( $_REQUEST['username'] );
$password = isset($_REQUEST['password'])?validStr($_REQUEST['password']):'';
userLogin( $username, $password );
$refreshParent = true;
$view = 'console';
- } elseif ( $action == "logout" ) {
+ } else if ( $action == 'logout' ) {
userLogout();
$refreshParent = true;
$view = 'none';
- }
- elseif ( $action == "bandwidth" && isset($_REQUEST['newBandwidth']) )
- {
+ } else if ( $action == 'bandwidth' && isset($_REQUEST['newBandwidth']) ) {
$_COOKIE['zmBandwidth'] = validStr($_REQUEST['newBandwidth']);
- setcookie( "zmBandwidth", validStr($_REQUEST['newBandwidth']), time()+3600*24*30*12*10 );
+ setcookie( 'zmBandwidth', validStr($_REQUEST['newBandwidth']), time()+3600*24*30*12*10 );
$refreshParent = true;
}
@@ -133,9 +128,9 @@ if ( !empty($action) ) {
if ( $action == 'filter' ) {
if ( !empty($_REQUEST['subaction']) ) {
- if ( $_REQUEST['subaction'] == "addterm" )
+ if ( $_REQUEST['subaction'] == 'addterm' )
$_REQUEST['filter'] = addFilterTerm( $_REQUEST['filter'], $_REQUEST['line'] );
- elseif ( $_REQUEST['subaction'] == "delterm" )
+ elseif ( $_REQUEST['subaction'] == 'delterm' )
$_REQUEST['filter'] = delFilterTerm( $_REQUEST['filter'], $_REQUEST['line'] );
} elseif ( canEdit( 'Events' ) ) {
$sql = '';
@@ -143,7 +138,7 @@ if ( !empty($action) ) {
$filterName = '';
if ( !empty($_REQUEST['execute']) ) {
// TempFilterName is used in event listing later on
- $tempFilterName = $filterName = "_TempFilter".time();
+ $tempFilterName = $filterName = '_TempFilter'.time();
} elseif ( !empty($_REQUEST['newFilterName']) ) {
$filterName = $_REQUEST['newFilterName'];
}
@@ -185,48 +180,31 @@ if ( !empty($action) ) {
} // end if canview events
// Event scope actions, edit permissions required
- if ( canEdit( 'Events' ) )
- {
- if ( $action == "rename" && isset($_REQUEST['eventName']) && !empty($_REQUEST['eid']) )
- {
+ if ( canEdit( 'Events' ) ) {
+ if ( $action == 'rename' && isset($_REQUEST['eventName']) && !empty($_REQUEST['eid']) ) {
dbQuery( 'UPDATE Events SET Name=? WHERE Id=?', array( $_REQUEST['eventName'], $_REQUEST['eid'] ) );
- }
- else if ( $action == "eventdetail" )
- {
- if ( !empty($_REQUEST['eid']) )
- {
+ } else if ( $action == 'eventdetail' ) {
+ if ( !empty($_REQUEST['eid']) ) {
dbQuery( 'UPDATE Events SET Cause=?, Notes=? WHERE Id=?', array( $_REQUEST['newEvent']['Cause'], $_REQUEST['newEvent']['Notes'], $_REQUEST['eid'] ) );
$refreshParent = true;
- }
- else
- {
- foreach( getAffectedIds( 'markEid' ) as $markEid )
- {
+ } else {
+ foreach( getAffectedIds( 'markEid' ) as $markEid ) {
dbQuery( 'UPDATE Events SET Cause=?, Notes=? WHERE Id=?', array( $_REQUEST['newEvent']['Cause'], $_REQUEST['newEvent']['Notes'], $markEid ) );
$refreshParent = true;
}
}
- }
- elseif ( $action == "archive" || $action == "unarchive" )
- {
- $archiveVal = ($action == "archive")?1:0;
- if ( !empty($_REQUEST['eid']) )
- {
+ } elseif ( $action == 'archive' || $action == 'unarchive' ) {
+ $archiveVal = ($action == 'archive')?1:0;
+ if ( !empty($_REQUEST['eid']) ) {
dbQuery( 'UPDATE Events SET Archived=? WHERE Id=?', array( $archiveVal, $_REQUEST['eid']) );
- }
- else
- {
- foreach( getAffectedIds( 'markEid' ) as $markEid )
- {
+ } else {
+ foreach( getAffectedIds( 'markEid' ) as $markEid ) {
dbQuery( 'UPDATE Events SET Archived=? WHERE Id=?', array( $archiveVal, $markEid ) );
$refreshParent = true;
}
}
- }
- elseif ( $action == 'delete' )
- {
- foreach( getAffectedIds( 'markEid' ) as $markEid )
- {
+ } elseif ( $action == 'delete' ) {
+ foreach( getAffectedIds( 'markEid' ) as $markEid ) {
deleteEvent( $markEid );
$refreshParent = true;
}
@@ -240,20 +218,16 @@ if ( !empty($action) ) {
}
// Monitor control actions, require a monitor id and control view permissions for that monitor
- if ( !empty($_REQUEST['mid']) && canView( 'Control', $_REQUEST['mid'] ) )
- {
+ if ( !empty($_REQUEST['mid']) && canView( 'Control', $_REQUEST['mid'] ) ) {
require_once( 'control_functions.php' );
require_once( 'Monitor.php' );
$mid = validInt($_REQUEST['mid']);
- if ( $action == "control" )
- {
+ if ( $action == 'control' ) {
$monitor = new Monitor( $mid );
$ctrlCommand = buildControlCommand( $monitor );
sendControlCommand( $monitor->Id(), $ctrlCommand );
- }
- elseif ( $action == "settings" )
- {
+ } elseif ( $action == 'settings' ) {
$args = " -m " . escapeshellarg($mid);
$args .= " -B" . escapeshellarg($_REQUEST['newBrightness']);
$args .= " -C" . escapeshellarg($_REQUEST['newContrast']);
@@ -264,21 +238,16 @@ if ( !empty($action) ) {
$zmuOutput = exec( $zmuCommand );
list( $brightness, $contrast, $hue, $colour ) = explode( ' ', $zmuOutput );
- dbQuery( "update Monitors set Brightness = ?, Contrast = ?, Hue = ?, Colour = ? where Id = ?", array($brightness, $contrast, $hue, $colour, $mid));
+ dbQuery( 'UPDATE Monitors SET Brightness = ?, Contrast = ?, Hue = ?, Colour = ? WHERE Id = ?', array($brightness, $contrast, $hue, $colour, $mid));
}
}
// Control capability actions, require control edit permissions
- if ( canEdit( 'Control' ) )
- {
- if ( $action == "controlcap" )
- {
- if ( !empty($_REQUEST['cid']) )
- {
- $control = dbFetchOne( "select * from Controls where Id = ?", NULL, array($_REQUEST['cid']) );
- }
- else
- {
+ if ( canEdit( 'Control' ) ) {
+ if ( $action == 'controlcap' ) {
+ if ( !empty($_REQUEST['cid']) ) {
+ $control = dbFetchOne( 'SELECT * FROM Controls WHERE Id = ?', NULL, array($_REQUEST['cid']) );
+ } else {
$control = array();
}
@@ -288,36 +257,26 @@ if ( !empty($action) ) {
);
$columns = getTableColumns( 'Controls' );
- foreach ( $columns as $name=>$type )
- {
- if ( preg_match( '/^(Can|Has)/', $name ) )
- {
+ foreach ( $columns as $name=>$type ) {
+ if ( preg_match( '/^(Can|Has)/', $name ) ) {
$types[$name] = 'toggle';
}
}
$changes = getFormChanges( $control, $_REQUEST['newControl'], $types, $columns );
- if ( count( $changes ) )
- {
- if ( !empty($_REQUEST['cid']) )
- {
+ if ( count( $changes ) ) {
+ if ( !empty($_REQUEST['cid']) ) {
dbQuery( "update Controls set ".implode( ", ", $changes )." where Id = ?", array($_REQUEST['cid']) );
- }
- else
- {
+ } else {
dbQuery( "insert into Controls set ".implode( ", ", $changes ) );
//$_REQUEST['cid'] = dbInsertId();
}
$refreshParent = true;
}
$view = 'none';
- }
- elseif ( $action == "delete" )
- {
- if ( isset($_REQUEST['markCids']) )
- {
- foreach( $_REQUEST['markCids'] as $markCid )
- {
+ } elseif ( $action == 'delete' ) {
+ if ( isset($_REQUEST['markCids']) ) {
+ foreach( $_REQUEST['markCids'] as $markCid ) {
dbQuery( "delete from Controls where Id = ?", array($markCid) );
dbQuery( "update Monitors set Controllable = 0, ControlId = 0 where ControlId = ?", array($markCid) );
$refreshParent = true;
@@ -327,50 +286,40 @@ if ( !empty($action) ) {
}
// Monitor edit actions, require a monitor id and edit permissions for that monitor
- if ( !empty($_REQUEST['mid']) && canEdit( 'Monitors', $_REQUEST['mid'] ) )
- {
+ if ( !empty($_REQUEST['mid']) && canEdit( 'Monitors', $_REQUEST['mid'] ) ) {
$mid = validInt($_REQUEST['mid']);
- if ( $action == "function" )
- {
+ if ( $action == 'function' ) {
$monitor = dbFetchOne( "SELECT * FROM Monitors WHERE Id=?", NULL, array($mid) );
$newFunction = validStr($_REQUEST['newFunction']);
- $newEnabled = isset( $_REQUEST['newEnabled'] ) and $_REQUEST['newEnabled'] != "1" ? "0" : "1";
+ $newEnabled = isset( $_REQUEST['newEnabled'] ) and $_REQUEST['newEnabled'] != '1' ? '0' : '1';
$oldFunction = $monitor['Function'];
$oldEnabled = $monitor['Enabled'];
- if ( $newFunction != $oldFunction || $newEnabled != $oldEnabled )
- {
+ if ( $newFunction != $oldFunction || $newEnabled != $oldEnabled ) {
dbQuery( "update Monitors set Function=?, Enabled=? where Id=?", array( $newFunction, $newEnabled, $mid ) );
$monitor['Function'] = $newFunction;
$monitor['Enabled'] = $newEnabled;
//if ( $cookies ) session_write_close();
- if ( daemonCheck() )
- {
+ if ( daemonCheck() ) {
$restart = ($oldFunction == 'None') || ($newFunction == 'None') || ($newEnabled != $oldEnabled);
- zmaControl( $monitor, "stop" );
- zmcControl( $monitor, $restart?"restart":"" );
- zmaControl( $monitor, "start" );
+ zmaControl( $monitor, 'stop' );
+ zmcControl( $monitor, $restart?'restart':'' );
+ zmaControl( $monitor, 'start' );
}
$refreshParent = true;
}
- }
- elseif ( $action == "zone" && isset( $_REQUEST['zid'] ) )
- {
+ } elseif ( $action == 'zone' && isset( $_REQUEST['zid'] ) ) {
$zid = validInt($_REQUEST['zid']);
- $monitor = dbFetchOne( "SELECT * FROM Monitors WHERE Id=?", NULL, array($mid) );
+ $monitor = dbFetchOne( 'SELECT * FROM Monitors WHERE Id=?', NULL, array($mid) );
- if ( !empty($zid) )
- {
- $zone = dbFetchOne( "SELECT * FROM Zones WHERE MonitorId=? AND Id=?", NULL, array( $mid, $zid ) );
- }
- else
- {
+ if ( !empty($zid) ) {
+ $zone = dbFetchOne( 'SELECT * FROM Zones WHERE MonitorId=? AND Id=?', NULL, array( $mid, $zid ) );
+ } else {
$zone = array();
}
- if ( $_REQUEST['newZone']['Units'] == 'Percent' )
- {
+ if ( $_REQUEST['newZone']['Units'] == 'Percent' ) {
$_REQUEST['newZone']['MinAlarmPixels'] = intval(($_REQUEST['newZone']['MinAlarmPixels']*$_REQUEST['newZone']['Area'])/100);
$_REQUEST['newZone']['MaxAlarmPixels'] = intval(($_REQUEST['newZone']['MaxAlarmPixels']*$_REQUEST['newZone']['Area'])/100);
if ( isset($_REQUEST['newZone']['MinFilterPixels']) )
@@ -387,28 +336,20 @@ if ( !empty($action) ) {
$types = array();
$changes = getFormChanges( $zone, $_REQUEST['newZone'], $types );
- if ( count( $changes ) )
- {
- if ( $zid > 0 )
- {
+ if ( count( $changes ) ) {
+ if ( $zid > 0 ) {
dbQuery( "UPDATE Zones SET ".implode( ", ", $changes )." WHERE MonitorId=? AND Id=?", array( $mid, $zid) );
- }
- else
- {
+ } else {
dbQuery( "INSERT INTO Zones SET MonitorId=?, ".implode( ", ", $changes ), array( $mid ) );
}
//if ( $cookies ) session_write_close();
- if ( daemonCheck() )
- {
- if ( $_REQUEST['newZone']['Type'] == 'Privacy' )
- {
- zmaControl( $monitor, "stop" );
- zmcControl( $monitor, "restart" );
- zmaControl( $monitor, "start" );
- }
- else
- {
- zmaControl( $mid, "restart" );
+ if ( daemonCheck() ) {
+ if ( $_REQUEST['newZone']['Type'] == 'Privacy' ) {
+ zmaControl( $monitor, 'stop' );
+ zmcControl( $monitor, 'restart' );
+ zmaControl( $monitor, 'start' );
+ } else {
+ zmaControl( $mid, 'restart' );
}
}
if ( $_REQUEST['newZone']['Type'] == 'Privacy' && $monitor['Controllable'] ) {
@@ -418,97 +359,76 @@ if ( !empty($action) ) {
$refreshParent = true;
}
$view = 'none';
- }
- elseif ( $action == "plugin" && isset($_REQUEST['pl']))
- {
- $sql="SELECT * FROM PluginsConfig WHERE MonitorId=? AND ZoneId=? AND pluginName=?";
+ } elseif ( $action == 'plugin' && isset($_REQUEST['pl'])) {
+ $sql='SELECT * FROM PluginsConfig WHERE MonitorId=? AND ZoneId=? AND pluginName=?';
$pconfs=dbFetchAll( $sql, NULL, array( $mid, $_REQUEST['zid'], $_REQUEST['pl'] ) );
$changes=0;
- foreach( $pconfs as $pconf )
- {
+ foreach( $pconfs as $pconf ) {
$value=$_REQUEST['pluginOpt'][$pconf['Name']];
- if(array_key_exists($pconf['Name'], $_REQUEST['pluginOpt']) && ($pconf['Value']!=$value))
- {
+ if(array_key_exists($pconf['Name'], $_REQUEST['pluginOpt']) && ($pconf['Value']!=$value)) {
dbQuery("UPDATE PluginsConfig SET Value=? WHERE id=?", array( $value, $pconf['Id'] ) );
$changes++;
}
}
- if($changes>0)
- {
- if ( daemonCheck() )
- {
- zmaControl( $mid, "restart" );
+ if($changes>0) {
+ if ( daemonCheck() ) {
+ zmaControl( $mid, 'restart' );
}
$refreshParent = true;
}
$view = 'none';
- }
- elseif ( $action == "sequence" && isset($_REQUEST['smid']) )
- {
+ } elseif ( $action == 'sequence' && isset($_REQUEST['smid']) ) {
$smid = validInt($_REQUEST['smid']);
- $monitor = dbFetchOne( "select * from Monitors where Id = ?", NULL, array($mid) );
- $smonitor = dbFetchOne( "select * from Monitors where Id = ?", NULL, array($smid) );
+ $monitor = dbFetchOne( 'select * from Monitors where Id = ?', NULL, array($mid) );
+ $smonitor = dbFetchOne( 'select * from Monitors where Id = ?', NULL, array($smid) );
- dbQuery( "update Monitors set Sequence=? where Id=?", array( $smonitor['Sequence'], $monitor['Id'] ) );
- dbQuery( "update Monitors set Sequence=? WHERE Id=?", array( $monitor['Sequence'], $smonitor['Id'] ) );
+ dbQuery( 'update Monitors set Sequence=? where Id=?', array( $smonitor['Sequence'], $monitor['Id'] ) );
+ dbQuery( 'update Monitors set Sequence=? WHERE Id=?', array( $monitor['Sequence'], $smonitor['Id'] ) );
$refreshParent = true;
fixSequences();
}
- if ( $action == "delete" )
- {
- if ( isset($_REQUEST['markZids']) )
- {
+ if ( $action == 'delete' ) {
+ if ( isset($_REQUEST['markZids']) ) {
$deletedZid = 0;
- foreach( $_REQUEST['markZids'] as $markZid )
- {
- $zone = dbFetchOne( "select * from Zones where Id=?", NULL, array($markZid) );
- dbQuery( "delete from Zones WHERE MonitorId=? AND Id=?", array( $mid, $markZid) );
+ foreach( $_REQUEST['markZids'] as $markZid ) {
+ $zone = dbFetchOne( 'select * from Zones where Id=?', NULL, array($markZid) );
+ dbQuery( 'delete from Zones WHERE MonitorId=? AND Id=?', array( $mid, $markZid) );
$deletedZid = 1;
}
- if ( $deletedZid )
- {
+ if ( $deletedZid ) {
//if ( $cookies )
//session_write_close();
- if ( daemonCheck() )
- if ( $zone['Type'] == 'Privacy' )
- {
- zmaControl( $mid, "stop" );
- zmcControl( $mid, "restart" );
- zmaControl( $mid, "start" );
- }
- else
- {
- zmaControl( $mid, "restart" );
+ if ( daemonCheck() ) {
+ if ( $zone['Type'] == 'Privacy' ) {
+ zmaControl( $mid, 'stop' );
+ zmcControl( $mid, 'restart' );
+ zmaControl( $mid, 'start' );
+ } else {
+ zmaControl( $mid, 'restart' );
}
+ } // end if daemonCheck()
$refreshParent = true;
- }
- }
- }
+ } // end if deletedzid
+ } // end if isset($_REQUEST['markZids'])
+ } // end if action == delete
}
// Monitor edit actions, monitor id derived, require edit permissions for that monitor
- if ( canEdit( 'Monitors' ) )
- {
- if ( $action == "monitor" )
- {
- if ( !empty($_REQUEST['mid']) )
- {
+ if ( canEdit( 'Monitors' ) ) {
+ if ( $action == 'monitor' ) {
+ if ( !empty($_REQUEST['mid']) ) {
$mid = validInt($_REQUEST['mid']);
- $monitor = dbFetchOne( "select * from Monitors where Id = ?", NULL, array($mid) );
+ $monitor = dbFetchOne( 'SELECT * FROM Monitors WHERE Id = ?', NULL, array($mid) );
- if ( ZM_OPT_X10 )
- {
- $x10Monitor = dbFetchOne( "select * from TriggersX10 where MonitorId=?", NULL, array($mid) );
+ if ( ZM_OPT_X10 ) {
+ $x10Monitor = dbFetchOne( 'SELECT * FROM TriggersX10 WHERE MonitorId=?', NULL, array($mid) );
if ( !$x10Monitor )
$x10Monitor = array();
}
- }
- else
- {
+ } else {
$monitor = array();
- if ( ZM_OPT_X10 )
- {
+ if ( ZM_OPT_X10 ) {
$x10Monitor = array();
}
}
@@ -528,20 +448,16 @@ if ( !empty($action) ) {
$columns = getTableColumns( 'Monitors' );
$changes = getFormChanges( $monitor, $_REQUEST['newMonitor'], $types, $columns );
- if ( count( $changes ) )
- {
- if ( !empty($_REQUEST['mid']) )
- {
+ if ( count( $changes ) ) {
+ if ( !empty($_REQUEST['mid']) ) {
$mid = validInt($_REQUEST['mid']);
dbQuery( "update Monitors set ".implode( ", ", $changes )." where Id =?", array($mid) );
- if ( isset($changes['Name']) )
- {
+ if ( isset($changes['Name']) ) {
$saferOldName = basename( $monitor['Name'] );
$saferNewName = basename( $_REQUEST['newMonitor']['Name'] );
rename( ZM_DIR_EVENTS."/".$saferOldName, ZM_DIR_EVENTS."/".$saferNewName);
}
- if ( isset($changes['Width']) || isset($changes['Height']) )
- {
+ if ( isset($changes['Width']) || isset($changes['Height']) ) {
$newW = $_REQUEST['newMonitor']['Width'];
$newH = $_REQUEST['newMonitor']['Height'];
$newA = $newW * $newH;
@@ -549,13 +465,11 @@ if ( !empty($action) ) {
$oldH = $monitor['Height'];
$oldA = $oldW * $oldH;
- $zones = dbFetchAll( "select * from Zones where MonitorId=?", NULL, array($mid) );
- foreach ( $zones as $zone )
- {
+ $zones = dbFetchAll( 'SELECT * FROM Zones WHERE MonitorId=?', NULL, array($mid) );
+ foreach ( $zones as $zone ) {
$newZone = $zone;
$points = coordsToPoints( $zone['Coords'] );
- for ( $i = 0; $i < count($points); $i++ )
- {
+ for ( $i = 0; $i < count($points); $i++ ) {
$points[$i]['x'] = intval(($points[$i]['x']*($newW-1))/($oldW-1));
$points[$i]['y'] = intval(($points[$i]['y']*($newH-1))/($oldH-1));
}
@@ -570,18 +484,15 @@ if ( !empty($action) ) {
$changes = getFormChanges( $zone, $newZone, $types );
- if ( count( $changes ) )
- {
+ if ( count( $changes ) ) {
dbQuery( "update Zones set ".implode( ", ", $changes )." WHERE MonitorId=? AND Id=?", array( $mid, $zone['Id'] ) );
}
}
}
- }
- elseif ( !$user['MonitorIds'] )
- {
+ } elseif ( !$user['MonitorIds'] ) {
# FIXME This is actually a race condition. Should lock the table.
- $maxSeq = dbFetchOne( "select max(Sequence) as MaxSequence from Monitors", "MaxSequence" );
- $changes[] = "Sequence = ".($maxSeq+1);
+ $maxSeq = dbFetchOne( 'SELECT max(Sequence) AS MaxSequence FROM Monitors', 'MaxSequence' );
+ $changes[] = 'Sequence = '.($maxSeq+1);
dbQuery( "insert into Monitors set ".implode( ", ", $changes ) );
$mid = dbInsertId();
@@ -591,32 +502,23 @@ if ( !empty($action) ) {
mkdir( ZM_DIR_EVENTS.'/'.$mid, 0755 );
$saferName = basename($_REQUEST['newMonitor']['Name']);
symlink( $mid, ZM_DIR_EVENTS.'/'.$saferName );
- if ( isset($_COOKIE['zmGroup']) )
- {
+ if ( isset($_COOKIE['zmGroup']) ) {
dbQuery( "UPDATE Groups SET MonitorIds = concat(MonitorIds,',".$mid."') WHERE Id=?", array($_COOKIE['zmGroup']) );
}
}
$restart = true;
}
- if ( ZM_OPT_X10 )
- {
+ if ( ZM_OPT_X10 ) {
$x10Changes = getFormChanges( $x10Monitor, $_REQUEST['newX10Monitor'] );
- if ( count( $x10Changes ) )
- {
- if ( $x10Monitor && isset($_REQUEST['newX10Monitor']) )
- {
+ if ( count( $x10Changes ) ) {
+ if ( $x10Monitor && isset($_REQUEST['newX10Monitor']) ) {
dbQuery( "update TriggersX10 set ".implode( ", ", $x10Changes )." where MonitorId=?", array($mid) );
- }
- elseif ( !$user['MonitorIds'] )
- {
- if ( !$x10Monitor )
- {
+ } elseif ( !$user['MonitorIds'] ) {
+ if ( !$x10Monitor ) {
dbQuery( "insert into TriggersX10 set MonitorId = ?".implode( ", ", $x10Changes ), array( $mid ) );
- }
- else
- {
+ } else {
dbQuery( "delete from TriggersX10 where MonitorId = ?", array($mid) );
}
}
@@ -624,17 +526,15 @@ if ( !empty($action) ) {
}
}
- if ( $restart )
- {
- $monitor = dbFetchOne( "select * from Monitors where Id = ?", NULL, array($mid) );
+ if ( $restart ) {
+ $monitor = dbFetchOne( 'SELECT * FROM Monitors WHERE Id = ?', NULL, array($mid) );
//fixDevices();
//if ( $cookies )
//session_write_close();
- if ( daemonCheck() )
- {
- zmaControl( $monitor, "stop" );
- zmcControl( $monitor, "restart" );
- zmaControl( $monitor, "start" );
+ if ( daemonCheck() ) {
+ zmaControl( $monitor, 'stop' );
+ zmcControl( $monitor, 'restart' );
+ zmaControl( $monitor, 'start' );
}
if ( $monitor['Controllable'] ) {
require_once( 'control_functions.php' );
@@ -642,45 +542,38 @@ if ( !empty($action) ) {
}
//daemonControl( 'restart', 'zmwatch.pl' );
$refreshParent = true;
- }
+ } // end if restart
$view = 'none';
}
- if ( $action == "delete" )
- {
- if ( isset($_REQUEST['markMids']) && !$user['MonitorIds'] )
- {
- foreach( $_REQUEST['markMids'] as $markMid )
- {
- if ( canEdit( 'Monitors', $markMid ) )
- {
- if ( $monitor = dbFetchOne( "select * from Monitors where Id = ?", NULL, array($markMid) ) )
- {
- if ( daemonCheck() )
- {
- zmaControl( $monitor, "stop" );
- zmcControl( $monitor, "stop" );
+ if ( $action == 'delete' ) {
+ if ( isset($_REQUEST['markMids']) && !$user['MonitorIds'] ) {
+ foreach( $_REQUEST['markMids'] as $markMid ) {
+ if ( canEdit( 'Monitors', $markMid ) ) {
+ if ( $monitor = dbFetchOne( 'SELECT * FROM Monitors WHERE Id = ?', NULL, array($markMid) ) ) {
+ if ( daemonCheck() ) {
+ zmaControl( $monitor, 'stop' );
+ zmcControl( $monitor, 'stop' );
}
// This is the important stuff
- dbQuery( "delete from Monitors where Id = ?", array($markMid) );
- dbQuery( "delete from Zones where MonitorId = ?", array($markMid) );
+ dbQuery( 'DELETE FROM Monitors WHERE Id = ?', array($markMid) );
+ dbQuery( 'DELETE FROM Zones WHERE MonitorId = ?', array($markMid) );
if ( ZM_OPT_X10 )
- dbQuery( "delete from TriggersX10 where MonitorId=?", array($markMid) );
+ dbQuery( 'DELETE FROM TriggersX10 WHERE MonitorId=?', array($markMid) );
fixSequences();
// If fast deletes are on, then zmaudit will clean everything else up later
// If fast deletes are off and there are lots of events then this step may
// well time out before completing, in which case zmaudit will still tidy up
- if ( !ZM_OPT_FAST_DELETE )
- {
+ if ( !ZM_OPT_FAST_DELETE ) {
// Slight hack, we maybe should load *, but we happen to know that the deleteEvent function uses Id and StartTime.
- $markEids = dbFetchAll( "SELECT Id,StartTime FROM Events WHERE MonitorId=?", NULL, array($markMid) );
+ $markEids = dbFetchAll( 'SELECT Id,StartTime FROM Events WHERE MonitorId=?', NULL, array($markMid) );
foreach( $markEids as $markEid )
deleteEvent( $markEid, $markMid );
- deletePath( ZM_DIR_EVENTS."/".basename($monitor['Name']) );
- deletePath( ZM_DIR_EVENTS."/".$monitor['Id'] ); // I'm trusting the Id.
+ deletePath( ZM_DIR_EVENTS.'/'.basename($monitor['Name']) );
+ deletePath( ZM_DIR_EVENTS.'/'.$monitor['Id'] ); // I'm trusting the Id.
}
}
}
@@ -690,54 +583,42 @@ if ( !empty($action) ) {
}
// Device view actions
- if ( canEdit( 'Devices' ) )
- {
- if ( $action == "device" )
- {
- if ( !empty($_REQUEST['command']) )
- {
+ if ( canEdit( 'Devices' ) ) {
+ if ( $action == 'device' ) {
+ if ( !empty($_REQUEST['command']) ) {
setDeviceStatusX10( $_REQUEST['key'], $_REQUEST['command'] );
- }
- elseif ( isset( $_REQUEST['newDevice'] ) )
- {
- if ( isset($_REQUEST['did']) )
- {
+ } elseif ( isset( $_REQUEST['newDevice'] ) ) {
+ if ( isset($_REQUEST['did']) ) {
dbQuery( "update Devices set Name=?, KeyString=? where Id=?", array($_REQUEST['newDevice']['Name'], $_REQUEST['newDevice']['KeyString'], $_REQUEST['did']) );
- }
- else
- {
+ } else {
dbQuery( "insert into Devices set Name=?, KeyString=?", array( $_REQUEST['newDevice']['Name'], $_REQUEST['newDevice']['KeyString'] ) );
}
$refreshParent = true;
$view = 'none';
}
- }
- elseif ( $action == "delete" )
- {
- if ( isset($_REQUEST['markDids']) )
- {
- foreach( $_REQUEST['markDids'] as $markDid )
- {
+ } elseif ( $action == 'delete' ) {
+ if ( isset($_REQUEST['markDids']) ) {
+ foreach( $_REQUEST['markDids'] as $markDid ) {
dbQuery( "delete from Devices where Id=?", array($markDid) );
$refreshParent = true;
}
}
- }
- }
+ } // end if action
+ } // end if canedit devices
// Group view actions
- if ( canView( 'Groups' ) && $action == "setgroup" ) {
+ if ( canView( 'Groups' ) && $action == 'setgroup' ) {
if ( !empty($_REQUEST['gid']) ) {
- setcookie( "zmGroup", validInt($_REQUEST['gid']), time()+3600*24*30*12*10 );
+ setcookie( 'zmGroup', validInt($_REQUEST['gid']), time()+3600*24*30*12*10 );
} else {
- setcookie( "zmGroup", "", time()-3600*24*2 );
+ setcookie( 'zmGroup', '', time()-3600*24*2 );
}
$refreshParent = true;
}
// Group edit actions
if ( canEdit( 'Groups' ) ) {
- if ( $action == "group" ) {
+ if ( $action == 'group' ) {
# Should probably verfy that each monitor id is a valid monitor, that we have access to. HOwever at the moment, you have to have System permissions to do this
$monitors = empty( $_POST['newGroup']['MonitorIds'] ) ? NULL : implode(',', $_POST['newGroup']['MonitorIds']);
if ( !empty($_POST['gid']) ) {
@@ -747,30 +628,27 @@ if ( !empty($action) ) {
}
$view = 'none';
}
- if ( !empty($_REQUEST['gid']) && $action == "delete" ) {
- dbQuery( "delete from Groups where Id = ?", array($_REQUEST['gid']) );
- if ( isset($_COOKIE['zmGroup']) )
- {
- if ( $_REQUEST['gid'] == $_COOKIE['zmGroup'] )
- {
+ if ( !empty($_REQUEST['gid']) && $action == 'delete' ) {
+ dbQuery( 'DELETE FROM Groups WHERE Id = ?', array($_REQUEST['gid']) );
+ if ( isset($_COOKIE['zmGroup']) ) {
+ if ( $_REQUEST['gid'] == $_COOKIE['zmGroup'] ) {
unset( $_COOKIE['zmGroup'] );
- setcookie( "zmGroup", "", time()-3600*24*2 );
+ setcookie( 'zmGroup', '', time()-3600*24*2 );
$refreshParent = true;
}
}
}
$refreshParent = true;
- }
+ } // end if can edit groups
// System edit actions
- if ( canEdit( 'System' ) )
- {
+ if ( canEdit( 'System' ) ) {
if ( isset( $_REQUEST['object'] ) ) {
if ( $_REQUEST['object'] == 'server' ) {
- if ( $action == "Save" ) {
+ if ( $action == 'Save' ) {
if ( !empty($_REQUEST['id']) )
- $dbServer = dbFetchOne( "SELECT * FROM Servers WHERE Id=?", NULL, array($_REQUEST['id']) );
+ $dbServer = dbFetchOne( 'SELECT * FROM Servers WHERE Id=?', NULL, array($_REQUEST['id']) );
else
$dbServer = array();
@@ -796,9 +674,9 @@ if ( !empty($action) ) {
Error( "Unknown action $action in saving Server" );
}
} else if ( $_REQUEST['object'] == 'storage' ) {
- if ( $action == "Save" ) {
+ if ( $action == 'Save' ) {
if ( !empty($_REQUEST['id']) )
- $dbStorage = dbFetchOne( "SELECT * FROM Storage WHERE Id=?", NULL, array($_REQUEST['id']) );
+ $dbStorage = dbFetchOne( 'SELECT * FROM Storage WHERE Id=?', NULL, array($_REQUEST['id']) );
else
$dbStorage = array();
@@ -817,7 +695,7 @@ if ( !empty($action) ) {
} else if ( $action == 'delete' ) {
if ( !empty($_REQUEST['markIds']) ) {
foreach( $_REQUEST['markIds'] as $Id )
- dbQuery( "DELETE FROM Storage WHERE Id=?", array($Id) );
+ dbQuery( 'DELETE FROM Storage WHERE Id=?', array($Id) );
}
$refreshParent = true;
} else {
@@ -825,11 +703,9 @@ if ( !empty($action) ) {
}
} # end if isset($_REQUEST['object'] )
- } else if ( $action == "version" && isset($_REQUEST['option']) )
- {
+ } else if ( $action == 'version' && isset($_REQUEST['option']) ) {
$option = $_REQUEST['option'];
- switch( $option )
- {
+ switch( $option ) {
case 'go' :
{
// Ignore this, the caller will open the page itself
@@ -845,16 +721,11 @@ if ( !empty($action) ) {
case 'week' :
{
$nextReminder = time();
- if ( $option == 'hour' )
- {
+ if ( $option == 'hour' ) {
$nextReminder += 60*60;
- }
- elseif ( $option == 'day' )
- {
+ } elseif ( $option == 'day' ) {
$nextReminder += 24*60*60;
- }
- elseif ( $option == 'week' )
- {
+ } elseif ( $option == 'week' ) {
$nextReminder += 7*24*60*60;
}
dbQuery( "update Config set Value = '".$nextReminder."' where Name = 'ZM_DYN_NEXT_REMINDER'" );
@@ -867,11 +738,9 @@ if ( !empty($action) ) {
}
}
}
- if ( $action == "donate" && isset($_REQUEST['option']) )
- {
+ if ( $action == 'donate' && isset($_REQUEST['option']) ) {
$option = $_REQUEST['option'];
- switch( $option )
- {
+ switch( $option ) {
case 'go' :
{
// Ignore this, the caller will open the page itself
@@ -883,20 +752,13 @@ if ( !empty($action) ) {
case 'month' :
{
$nextReminder = time();
- if ( $option == 'hour' )
- {
+ if ( $option == 'hour' ) {
$nextReminder += 60*60;
- }
- elseif ( $option == 'day' )
- {
+ } elseif ( $option == 'day' ) {
$nextReminder += 24*60*60;
- }
- elseif ( $option == 'week' )
- {
+ } elseif ( $option == 'week' ) {
$nextReminder += 7*24*60*60;
- }
- elseif ( $option == 'month' )
- {
+ } elseif ( $option == 'month' ) {
$nextReminder += 30*24*60*60;
}
dbQuery( "update Config set Value = '".$nextReminder."' where Name = 'ZM_DYN_DONATE_REMINDER_TIME'" );
@@ -908,54 +770,47 @@ if ( !empty($action) ) {
dbQuery( "update Config set Value = '0' where Name = 'ZM_DYN_SHOW_DONATE_REMINDER'" );
break;
}
- }
+ } // end switch option
}
- if ( $action == "options" && isset($_REQUEST['tab']) )
- {
+ if ( $action == 'options' && isset($_REQUEST['tab']) ) {
$configCat = $configCats[$_REQUEST['tab']];
$changed = false;
- foreach ( $configCat as $name=>$value )
- {
+ foreach ( $configCat as $name=>$value ) {
unset( $newValue );
- if ( $value['Type'] == "boolean" && empty($_REQUEST['newConfig'][$name]) )
+ if ( $value['Type'] == 'boolean' && empty($_REQUEST['newConfig'][$name]) )
$newValue = 0;
elseif ( isset($_REQUEST['newConfig'][$name]) )
$newValue = preg_replace( "/\r\n/", "\n", stripslashes( $_REQUEST['newConfig'][$name] ) );
- if ( isset($newValue) && ($newValue != $value['Value']) )
- {
+ if ( isset($newValue) && ($newValue != $value['Value']) ) {
dbQuery( 'UPDATE Config SET Value=? WHERE Name=?', array( $newValue, $name ) );
$changed = true;
}
}
- if ( $changed )
- {
- switch( $_REQUEST['tab'] )
- {
- case "system" :
- case "config" :
- case "paths" :
+ if ( $changed ) {
+ switch( $_REQUEST['tab'] ) {
+ case 'system' :
+ case 'config' :
+ case 'paths' :
$restartWarning = true;
break;
- case "web" :
- case "tools" :
+ case 'web' :
+ case 'tools' :
break;
- case "logging" :
- case "network" :
- case "mail" :
- case "upload" :
+ case 'logging' :
+ case 'network' :
+ case 'mail' :
+ case 'upload' :
$restartWarning = true;
break;
- case "highband" :
- case "medband" :
- case "lowband" :
+ case 'highband' :
+ case 'medband' :
+ case 'lowband' :
break;
}
}
loadConfig( false );
- }
- elseif ( $action == "user" )
- {
+ } elseif ( $action == 'user' ) {
if ( !empty($_REQUEST['uid']) )
$dbUser = dbFetchOne( "SELECT * FROM Users WHERE Id=?", NULL, array($_REQUEST['uid']) );
else
@@ -969,14 +824,10 @@ if ( !empty($action) ) {
else
unset( $changes['Password'] );
- if ( count( $changes ) )
- {
- if ( !empty($_REQUEST['uid']) )
- {
+ if ( count( $changes ) ) {
+ if ( !empty($_REQUEST['uid']) ) {
dbQuery( "update Users set ".implode( ", ", $changes )." where Id = ?", array($_REQUEST['uid']) );
- }
- else
- {
+ } else {
dbQuery( "insert into Users set ".implode( ", ", $changes ) );
}
$refreshParent = true;
@@ -984,21 +835,15 @@ if ( !empty($action) ) {
userLogin( $dbUser['Username'], $dbUser['Password'] );
}
$view = 'none';
- }
- elseif ( $action == "state" )
- {
- if ( !empty($_REQUEST['runState']) )
- {
+ } elseif ( $action == 'state' ) {
+ if ( !empty($_REQUEST['runState']) ) {
//if ( $cookies ) session_write_close();
packageControl( $_REQUEST['runState'] );
$refreshParent = true;
}
- }
- elseif ( $action == "save" )
- {
- if ( !empty($_REQUEST['runState']) || !empty($_REQUEST['newState']) )
- {
- $sql = "select Id,Function,Enabled from Monitors order by Id";
+ } elseif ( $action == 'save' ) {
+ if ( !empty($_REQUEST['runState']) || !empty($_REQUEST['newState']) ) {
+ $sql = 'SELECT Id,Function,Enabled FROM Monitors ORDER BY Id';
$definitions = array();
foreach( dbFetchAll( $sql ) as $monitor )
{
@@ -1009,28 +854,22 @@ if ( !empty($action) ) {
$_REQUEST['runState'] = $_REQUEST['newState'];
dbQuery( "replace into States set Name=?, Definition=?", array( $_REQUEST['runState'],$definition) );
}
- }
- elseif ( $action == "delete" )
- {
+ } elseif ( $action == 'delete' ) {
if ( isset($_REQUEST['runState']) )
dbQuery( "delete from States where Name=?", array($_REQUEST['runState']) );
- if ( isset($_REQUEST['markUids']) )
- {
+ if ( isset($_REQUEST['markUids']) ) {
foreach( $_REQUEST['markUids'] as $markUid )
dbQuery( "delete from Users where Id = ?", array($markUid) );
if ( $markUid == $user['Id'] )
userLogout();
}
}
- }
- else
- {
- if ( ZM_USER_SELF_EDIT && $action == "user" )
- {
+ } else {
+ if ( ZM_USER_SELF_EDIT && $action == 'user' ) {
$uid = $user['Id'];
- $dbUser = dbFetchOne( "select Id, Password, Language from Users where Id = ?", NULL, array($uid) );
+ $dbUser = dbFetchOne( 'SELECT Id, Password, Language FROM Users WHERE Id = ?', NULL, array($uid) );
$types = array();
$changes = getFormChanges( $dbUser, $_REQUEST['newUser'], $types );
@@ -1039,8 +878,7 @@ if ( !empty($action) ) {
$changes['Password'] = "Password = password(".dbEscape($_REQUEST['newUser']['Password']).")";
else
unset( $changes['Password'] );
- if ( count( $changes ) )
- {
+ if ( count( $changes ) ) {
dbQuery( "update Users set ".implode( ", ", $changes )." where Id=?", array($uid) );
$refreshParent = true;
}
@@ -1048,10 +886,9 @@ if ( !empty($action) ) {
}
}
- if ( $action == "reset" )
- {
+ if ( $action == 'reset' ) {
$_SESSION['zmEventResetTime'] = strftime( STRF_FMT_DATETIME_DB );
- setcookie( "zmEventResetTime", $_SESSION['zmEventResetTime'], time()+3600*24*30*12*10 );
+ setcookie( 'zmEventResetTime', $_SESSION['zmEventResetTime'], time()+3600*24*30*12*10 );
//if ( $cookies ) session_write_close();
}
}
diff --git a/web/includes/functions.php b/web/includes/functions.php
index 471224905..f912e6eec 100644
--- a/web/includes/functions.php
+++ b/web/includes/functions.php
@@ -141,32 +141,30 @@ function getAuthUser( $auth ) {
}
function generateAuthHash( $useRemoteAddr ) {
- if ( ZM_OPT_USE_AUTH && ZM_AUTH_RELAY == 'hashed' ) {
+ if ( ZM_OPT_USE_AUTH and ZM_AUTH_RELAY == 'hashed' and $_SESSION['username'] and $_SESSION['passwordHash'] ) {
# regenerate a hash at half the liftetime of a hash, an hour is 3600 so half is 1800
if ( ( $_SESSION['AuthHashGeneratedAt'] < time() - ( ZM_AUTH_HASH_TTL * 1800 ) ) or ! isset($_SESSION['AuthHash']) ) {
- if ( ! ( $_SESSION['username'] and $_SESSION['passwordHash'] ) ) {
- Warning("Can't generate auth hash until we are logged in");
+ # Don't both regenerating Auth Hash if an hour hasn't gone by yet
+ $time = localtime();
+ $authKey = '';
+ if ( $useRemoteAddr ) {
+ $authKey = ZM_AUTH_HASH_SECRET.$_SESSION['username'].$_SESSION['passwordHash'].$_SESSION['remoteAddr'].$time[2].$time[3].$time[4].$time[5];
} else {
- $time = localtime();
- if ( $useRemoteAddr ) {
- $authKey = ZM_AUTH_HASH_SECRET.$_SESSION['username'].$_SESSION['passwordHash'].$_SESSION['remoteAddr'].$time[2].$time[3].$time[4].$time[5];
- } else {
- $authKey = ZM_AUTH_HASH_SECRET.$_SESSION['username'].$_SESSION['passwordHash'].$time[2].$time[3].$time[4].$time[5];
- }
- $auth = md5( $authKey );
- if ( session_status() == PHP_SESSION_NONE ) {
- Warning("Session is not active. AuthHash will not be cached.");
- }
- $_SESSION['AuthHash'] = $auth;
- $_SESSION['AuthHashGeneratedAt'] = time();
- Debug("Generating new auth $auth at " . $_SESSION['AuthHashGeneratedAt']. " using $authKey" );
+ $authKey = ZM_AUTH_HASH_SECRET.$_SESSION['username'].$_SESSION['passwordHash'].$time[2].$time[3].$time[4].$time[5];
}
+ $auth = md5( $authKey );
+ if ( session_status() == PHP_SESSION_NONE ) {
+ Warning("Session is not active. AuthHash will not be cached.");
+ }
+ $_SESSION['AuthHash'] = $auth;
+ $_SESSION['AuthHashGeneratedAt'] = time();
+ Debug("Generated new auth $auth at " . $_SESSION['AuthHashGeneratedAt']. " using $authKey" );
} else {
- Debug("Using auth " . $_SESSION['AuthHash'] );
+ Debug( "Using cached auth " . $_SESSION['AuthHash'] );
} # end if AuthHash is not cached
return $_SESSION['AuthHash'];
} else {
- $auth = "";
+ $auth = '';
}
return( $auth );
}
diff --git a/web/lang/en_gb.php b/web/lang/en_gb.php
index ac2657cc8..9064dbf88 100644
--- a/web/lang/en_gb.php
+++ b/web/lang/en_gb.php
@@ -520,6 +520,7 @@ $SLANG = array(
'NewUser' => 'New User',
'Next' => 'Next',
'NoDetectedCameras' => 'No Detected Cameras',
+ 'NoDetectedProfiles' => 'No Detected Profiles',
'NoFramesRecorded' => 'There are no frames recorded for this event',
'NoGroup' => 'No Group',
'NoneAvailable' => 'None available',
diff --git a/web/skins/classic/views/onvifprobe.php b/web/skins/classic/views/onvifprobe.php
index 10ac580b7..991ba6267 100644
--- a/web/skins/classic/views/onvifprobe.php
+++ b/web/skins/classic/views/onvifprobe.php
@@ -18,41 +18,40 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
-if ( !canEdit( 'Monitors' ) )
-{
- $view = "error";
+if ( !canEdit( 'Monitors' ) ) {
+ $view = 'error';
return;
}
$cameras = array();
$cameras[0] = translate('ChooseDetectedCamera');
+$profiles = array();
+$profiles[0] = translate('ChooseDetectedProfile');
-function execONVIF( $cmd )
-{
- exec( escapeshellcmd(ZM_PATH_BIN . "/zmonvif-probe.pl $cmd"), $output, $status );
-
- if ( $status )
+function execONVIF( $cmd ) {
+ $shell_command = escapeshellcmd(ZM_PATH_BIN . "/zmonvif-probe.pl $cmd");
+
+ exec( $shell_command, $output, $status );
+
+ if ( $status ) {
$html_output = implode( '
', $output );
Fatal( "Unable to probe network cameras, status is '$status'. Output was:
$html_output
- Please the following command from a command line for more information:
".
- ZM_PATH_BIN . "/zmonvif-probe.pl $cmd" );
+ Please the following command from a command line for more information:
$shell_command"
+ );
+ }
return $output;
}
-function probeCameras( $localIp )
-{
+function probeCameras( $localIp ) {
$cameras = array();
$count = 0;
- if ( $lines = @execONVIF( "probe" ) )
- {
- foreach ( $lines as $line )
- {
+ if ( $lines = @execONVIF( 'probe' ) ) {
+ foreach ( $lines as $line ) {
$line = rtrim( $line );
- if ( preg_match( '|^(.+),(.+),\s\((.*)\)$|', $line, $matches ) )
- {
+ if ( preg_match( '|^(.+),(.+),\s\((.*)\)$|', $line, $matches ) ) {
$device_ep = $matches[1];
$soapversion = $matches[2];
$camera = array(
@@ -65,15 +64,12 @@ function probeCameras( $localIp )
),
);
foreach ( preg_split('|,\s*|', $matches[3]) as $attr_val ) {
- if( preg_match( '|(.+)=\'(.*)\'|', $attr_val, $tokens ) )
- {
+ if( preg_match( '|(.+)=\'(.*)\'|', $attr_val, $tokens ) ) {
if($tokens[1] == "hardware") {
$camera['model'] = $tokens[2];
- }
- elseif($tokens[1] == "name") {
+ } elseif($tokens[1] == "name") {
$camera['monitor']['Name'] = $tokens[2];
- }
- elseif($tokens[1] == "location") {
+ } elseif($tokens[1] == "location") {
// $camera['location'] = $tokens[2];
}
@@ -86,21 +82,16 @@ function probeCameras( $localIp )
return( $cameras );
}
-function probeProfiles( $device_ep, $soapversion, $username, $password )
-{
+function probeProfiles( $device_ep, $soapversion, $username, $password ) {
$profiles = array();
$count = 0;
- if ( $lines = @execONVIF( "profiles $device_ep $soapversion $username $password" ) )
- {
- foreach ( $lines as $line )
- {
+ if ( $lines = @execONVIF( "profiles $device_ep $soapversion $username $password" ) ) {
+ foreach ( $lines as $line ) {
$line = rtrim( $line );
- if ( preg_match( '|^(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+)\s*$|', $line, $matches ) )
- {
+ if ( preg_match( '|^(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+)\s*$|', $line, $matches ) ) {
$stream_uri = $matches[7];
// add user@pass to URI
- if( preg_match( '|^(\S+://)(.+)$|', $stream_uri, $tokens ) )
- {
+ if( preg_match( '|^(\S+://)(.+)$|', $stream_uri, $tokens ) ) {
$stream_uri = $tokens[1].$username.':'.$password.'@'.$tokens[2];
}
@@ -133,25 +124,19 @@ xhtmlHeaders(__FILE__, translate('MonitorProbe') );
if( !isset($_REQUEST['step']) || ($_REQUEST['step'] == "1")) {
$monitors = array();
- foreach ( dbFetchAll( "select Id, Name, Host from Monitors where Type = 'Remote' order by Host" ) as $monitor )
- {
- if ( preg_match( '/^(.+)@(.+)$/', $monitor['Host'], $matches ) )
- {
+ foreach ( dbFetchAll( "select Id, Name, Host from Monitors where Type = 'Remote' order by Host" ) as $monitor ) {
+ if ( preg_match( '/^(.+)@(.+)$/', $monitor['Host'], $matches ) ) {
//echo "1: ".$matches[2]." = ".gethostbyname($matches[2])."
";
$monitors[gethostbyname($matches[2])] = $monitor;
- }
- else
- {
+ } else {
//echo "2: ".$monitor['Host']." = ".gethostbyname($monitor['Host'])."
";
$monitors[gethostbyname($monitor['Host'])] = $monitor;
}
}
$detcameras = probeCameras( '' );
- foreach ( $detcameras as $camera )
- {
- if ( preg_match( '|([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)|', $camera['monitor']['Host'], $matches ) )
- {
+ foreach ( $detcameras as $camera ) {
+ if ( preg_match( '|([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)|', $camera['monitor']['Host'], $matches ) ) {
$ip = $matches[1];
}
$host = $ip;
@@ -220,15 +205,14 @@ if( !isset($_REQUEST['step']) || ($_REQUEST['step'] == "1")) {
}
else if($_REQUEST['step'] == "2")
{
- if ( empty($_REQUEST['probe']) || empty($_REQUEST['username']) ||
- empty($_REQUEST['password']) )
- Fatal("Internal error. Please re-open this page.");
+ if ( empty($_REQUEST['probe']) )
+ Fatal("No probe passed in request. Please go back and try again.");
+#|| empty($_REQUEST['username']) ||
+ #empty($_REQUEST['password']) )
$probe = unserialize(base64_decode($_REQUEST['probe']));
- foreach ( $probe as $name=>$value )
- {
- if ( isset($value) )
- {
+ foreach ( $probe as $name=>$value ) {
+ if ( isset($value) ) {
$monitor[$name] = $value;
}
}
@@ -237,8 +221,7 @@ else if($_REQUEST['step'] == "2")
//print $monitor['Host'].", ".$_REQUEST['username'].", ".$_REQUEST['password']."
";
$detprofiles = probeProfiles( $monitor['Host'], $monitor['SOAP'], $_REQUEST['username'], $_REQUEST['password']);
- foreach ( $detprofiles as $profile )
- {
+ foreach ( $detprofiles as $profile ) {
$monitor = $camera['monitor'];
$sourceString = "${profile['Name']} : ${profile['Encoding']}" .
@@ -252,11 +235,11 @@ else if($_REQUEST['step'] == "2")
$monitor['Path'] = $profile['Path'];
// $sourceDesc = htmlspecialchars(serialize($monitor));
$sourceDesc = base64_encode(serialize($monitor));
- $cameras[$sourceDesc] = $sourceString;
+ $profiles[$sourceDesc] = $sourceString;
}
- if ( count($cameras) <= 0 )
- $cameras[0] = translate('NoDetectedCameras');
+ if ( count($profiles) <= 0 )
+ $profiles[0] = translate('NoDetectedProfiles');
?>
@@ -273,7 +256,7 @@ else if($_REQUEST['step'] == "2")
-
+