diff --git a/distros/debian/control b/distros/debian/control index 3b11f37b8..ebb59b3ab 100644 --- a/distros/debian/control +++ b/distros/debian/control @@ -17,6 +17,14 @@ Build-Depends: debhelper (>= 9), cmake , libvlccore-dev, libvlc-dev , libcurl4-gnutls-dev | libcurl4-nss-dev | libcurl4-openssl-dev , libgcrypt11-dev, libpolkit-gobject-1-dev + , libphp-serialization-perl + , libdate-manip-perl, libmime-lite-perl, libmime-tools-perl, libdbd-mysql-perl + , libwww-perl, libarchive-tar-perl, libarchive-zip-perl, libdevice-serialport-perl + , libmodule-load-perl, libsys-mmap-perl, libjson-any-perl + , libnet-sftp-foreign-perl, libio-pty-perl, libexpect-perl + , libdata-dump-perl, libclass-std-fast-perl, libsoap-wsdl-perl, libio-socket-multicast-perl, libdigest-sha-perl + , libsys-cpu-perl, libsys-meminfo-perl + , libdata-uuid-perl Standards-Version: 3.9.4 Package: zoneminder @@ -32,6 +40,7 @@ Depends: ${shlibs:Depends}, ${misc:Depends}, ${perl:Depends} , libnet-sftp-foreign-perl, libio-pty-perl, libexpect-perl , libdata-dump-perl, libclass-std-fast-perl, libsoap-wsdl-perl, libio-socket-multicast-perl, libdigest-sha-perl , libsys-cpu-perl, libsys-meminfo-perl + , libdata-uuid-perl , libpcre3 , libav-tools, libavdevice53 , rsyslog | system-log-daemon diff --git a/distros/ubuntu1204/control b/distros/ubuntu1204/control index 0791622ed..d7c2232cf 100644 --- a/distros/ubuntu1204/control +++ b/distros/ubuntu1204/control @@ -21,6 +21,7 @@ Build-Depends: debhelper (>= 9), python-sphinx | python3-sphinx, apache2-dev, dh ,libphp-serialization-perl ,libsys-mmap-perl [!hurd-any] ,libwww-perl + ,libdata-uuid-perl # Unbundled (dh_linktree): ,libjs-jquery ,libjs-mootools @@ -42,14 +43,15 @@ Depends: ${shlibs:Depends}, ${misc:Depends}, ${perl:Depends} ,libmodule-load-conditional-perl ,libnet-sftp-foreign-perl # ,libzoneminder-perl (= ${source:Version}) - ,libarchive-zip-perl - ,libdbd-mysql-perl - ,libdevice-serialport-perl - ,libimage-info-perl - ,libjson-any-perl - ,libsys-mmap-perl [!hurd-any] - ,liburi-encode-perl - ,libwww-perl + ,libarchive-zip-perl + ,libdbd-mysql-perl + ,libdevice-serialport-perl + ,libimage-info-perl + ,libjson-any-perl + ,libsys-mmap-perl [!hurd-any] + ,liburi-encode-perl + ,libwww-perl + ,libdata-uuid-perl ,mysql-client | virtual-mysql-client ,perl-modules ,php5-mysql, php5-gd diff --git a/distros/ubuntu1604/control b/distros/ubuntu1604/control index 92698abb5..42075fa70 100644 --- a/distros/ubuntu1604/control +++ b/distros/ubuntu1604/control @@ -22,6 +22,7 @@ Build-Depends: debhelper (>= 9), dh-systemd, python-sphinx | python3-sphinx, apa ,libphp-serialization-perl ,libsys-mmap-perl [!hurd-any] ,libwww-perl + ,libdata-uuid-perl # Unbundled (dh_linktree): ,libjs-jquery ,libjs-mootools @@ -40,20 +41,21 @@ Depends: ${shlibs:Depends}, ${misc:Depends}, ${perl:Depends} ,libphp-serialization-perl ,libmodule-load-conditional-perl ,libnet-sftp-foreign-perl - ,libarchive-zip-perl - ,libdbd-mysql-perl - ,libdevice-serialport-perl - ,libimage-info-perl - ,libjson-any-perl - ,libsys-mmap-perl [!hurd-any] - ,liburi-encode-perl - ,libwww-perl - ,libdata-dump-perl - ,libclass-std-fast-perl - ,libsoap-wsdl-perl - ,libio-socket-multicast-perl - ,libdigest-sha-perl - ,libsys-cpu-perl, libsys-meminfo-perl + ,libarchive-zip-perl + ,libdbd-mysql-perl + ,libdevice-serialport-perl + ,libimage-info-perl + ,libjson-any-perl + ,libsys-mmap-perl [!hurd-any] + ,liburi-encode-perl + ,libwww-perl + ,libdata-dump-perl + ,libclass-std-fast-perl + ,libsoap-wsdl-perl + ,libio-socket-multicast-perl + ,libdigest-sha-perl + ,libsys-cpu-perl, libsys-meminfo-perl + ,libdata-uuid-perl ,mysql-client | virtual-mysql-client ,perl-modules ,php5-mysql | php-mysql, php5-gd | php-gd diff --git a/onvif/modules/lib/WSDiscovery/TransportUDP.pm b/onvif/modules/lib/WSDiscovery/TransportUDP.pm index 375f9628d..edc837da6 100644 --- a/onvif/modules/lib/WSDiscovery/TransportUDP.pm +++ b/onvif/modules/lib/WSDiscovery/TransportUDP.pm @@ -61,16 +61,19 @@ sub _notify_response } sub send_multi() { - my ($self, $address, $port, $data) = @_; + my ($self, $address, $port, $utf8_string) = @_; my $destination = $address . ':' . $port; my $socket = IO::Socket::Multicast->new(PROTO => 'udp', LocalPort=>$port, PeerAddr=>$destination, ReuseAddr=>1) or die 'Cannot open multicast socket to ' . ${address} . ':' . ${port}; + + my $bytes = $utf8_string; + utf8::encode($bytes); $socket->mcast_ttl(1); - $socket->send($data); + $socket->send($bytes); } sub receive_multi() { diff --git a/onvif/proxy/lib/WSDiscovery10/Elements/Header.pm b/onvif/proxy/lib/WSDiscovery10/Elements/Header.pm new file mode 100644 index 000000000..df2d7f389 --- /dev/null +++ b/onvif/proxy/lib/WSDiscovery10/Elements/Header.pm @@ -0,0 +1,55 @@ + +package WSDiscovery10::Elements::Header; +use strict; +use warnings; + + +__PACKAGE__->_set_element_form_qualified(0); + +sub get_xmlns { 'http://schemas.xmlsoap.org/soap/envelope/' }; + +our $XML_ATTRIBUTE_CLASS; +undef $XML_ATTRIBUTE_CLASS; + +sub __get_attr_class { + return $XML_ATTRIBUTE_CLASS; +} + +use Class::Std::Fast::Storable constructor => 'none'; +use base qw(SOAP::WSDL::XSD::Typelib::ComplexType); + +Class::Std::initialize(); + +{ # BLOCK to scope variables + +my %Action_of :ATTR(:get); +my %MessageID_of :ATTR(:get); +my %ReplyTo_of :ATTR(:get); +my %To_of :ATTR(:get); + +__PACKAGE__->_factory( + [ qw( Action MessageID ReplyTo To ) ], + { + 'Action' => \%Action_of, + 'MessageID' => \%MessageID_of, + 'ReplyTo' => \%ReplyTo_of, + 'To' => \%To_of, + }, + { + 'Action' => 'WSDiscovery10::Elements::Action', + 'MessageID' => 'WSDiscovery10::Elements::MessageID', + 'ReplyTo' => 'WSDiscovery10::Elements::ReplyTo', + 'To' => 'WSDiscovery10::Elements::To', + }, + { + 'Action' => '', + 'MessageID' => '', + 'ReplyTo' => '', + 'To' => '', + } +); + +} # end BLOCK + + +1; diff --git a/onvif/proxy/lib/WSDiscovery10/Interfaces/WSDiscovery/WSDiscoveryPort.pm b/onvif/proxy/lib/WSDiscovery10/Interfaces/WSDiscovery/WSDiscoveryPort.pm index d194bbc87..f1b6446a5 100644 --- a/onvif/proxy/lib/WSDiscovery10/Interfaces/WSDiscovery/WSDiscoveryPort.pm +++ b/onvif/proxy/lib/WSDiscovery10/Interfaces/WSDiscovery/WSDiscoveryPort.pm @@ -34,7 +34,11 @@ sub ProbeOp { }, header => { - + 'use' => 'literal', + namespace => 'http://schemas.xmlsoap.org/ws/2004/08/addressing', + encodingStyle => '', + parts => [qw( WSDiscovery10::Elements::Header )], + }, headerfault => { diff --git a/onvif/proxy/lib/WSDiscovery10/Typemaps/WSDiscovery.pm b/onvif/proxy/lib/WSDiscovery10/Typemaps/WSDiscovery.pm index 635a19393..c19a7c647 100644 --- a/onvif/proxy/lib/WSDiscovery10/Typemaps/WSDiscovery.pm +++ b/onvif/proxy/lib/WSDiscovery10/Typemaps/WSDiscovery.pm @@ -23,7 +23,12 @@ our $typemap_1 = { 'ProbeMatches/ProbeMatch/Types' => 'WSDiscovery10::Types::QNameListType', 'ProbeMatches/ProbeMatch/EndpointReference' => 'WSDiscovery10::Types::EndpointReferenceType', 'ProbeMatches/ProbeMatch/EndpointReference/ReferenceProperties' => 'WSDiscovery10::Types::ReferencePropertiesType', - 'ProbeMatches/ProbeMatch/EndpointReference/PortType' => 'WSDiscovery10::Types::AttributedQName' + 'ProbeMatches/ProbeMatch/EndpointReference/PortType' => 'WSDiscovery10::Types::AttributedQName', + 'MessageID' => '__SKIP__', + 'RelatesTo' => '__SKIP__', + 'To' => '__SKIP__', + 'Action' => '__SKIP__', + 'AppSequence' => '__SKIP__', }; ; diff --git a/onvif/proxy/lib/WSDiscovery10/Types/ProbeType.pm b/onvif/proxy/lib/WSDiscovery10/Types/ProbeType.pm index 10c290e8e..8d7e9e7ca 100644 --- a/onvif/proxy/lib/WSDiscovery10/Types/ProbeType.pm +++ b/onvif/proxy/lib/WSDiscovery10/Types/ProbeType.pm @@ -7,8 +7,10 @@ __PACKAGE__->_set_element_form_qualified(0); sub get_xmlns { 'http://schemas.xmlsoap.org/ws/2005/04/discovery' }; -our $XML_ATTRIBUTE_CLASS; -undef $XML_ATTRIBUTE_CLASS; +our $XML_ATTRIBUTE_CLASS = 'WSDiscovery10::Types::ProbeType::_ProbeType::XmlAttr'; + +#our $XML_ATTRIBUTE_CLASS; +#undef $XML_ATTRIBUTE_CLASS; sub __get_attr_class { return $XML_ATTRIBUTE_CLASS; @@ -49,11 +51,55 @@ __PACKAGE__->_factory( } # end BLOCK +package WSDiscovery10::Types::ProbeType::_ProbeType::XmlAttr; +#use base qw(SOAP::WSDL::XSD::Typelib::ComplexType); +use Class::Std::Fast::Storable constructor => 'none', cache => 1; +use base qw(SOAP::WSDL::XSD::Typelib::Builtin::anySimpleType); +{ # BLOCK to scope variables +my %Attribs_of :ATTR(:get); +sub new +{ + my $self = pop @{ Class::Std::Fast::OBJECT_CACHE_REF()->{ $_[0] } }; + $self = bless \(my $o = Class::Std::Fast::ID()), $_[0] + if not defined $self; + + $self->BUILD(${$self}, $_[1]); + return $self; +} + +sub BUILD +{ + my ($self, $ident, $arg_ref) = @_; + + $Attribs_of{$ident} = $arg_ref; +} + +# without this no attributes are serialized +# SOAP::WSDL::XSD::Typelib::CompexType sub serialize_attr() + +sub as_bool :BOOLIFY { 1 } + +sub serialize() +{ + my $ident = ${ $_[0] }; + my $option_ref = $_[1]; + my $attr_str = ""; + + foreach my $attr (keys %{$Attribs_of{$ident}}) + { + my $value = %{$Attribs_of{$ident}}{$attr}; + $attr_str .= " $attr=\"$value\""; + } + + return $attr_str; +} + +} # end BLOCK 1; diff --git a/onvif/scripts/zmonvif-probe.pl b/onvif/scripts/zmonvif-probe.pl index 93c12959f..10aa26a08 100755 --- a/onvif/scripts/zmonvif-probe.pl +++ b/onvif/scripts/zmonvif-probe.pl @@ -25,13 +25,14 @@ # 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 WSDiscovery10::Elements::To; require WSDiscovery::TransportUDP; @@ -169,6 +170,8 @@ sub discover ## try both soap versions my %services; + my $uuid_gen = Data::UUID->new(); + if($verbose) { print "Probing for SOAP 1.1\n" } @@ -177,12 +180,18 @@ sub discover }); $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::To->new({ value => 'urn:schemas-xmlsoap-org:ws:2005:04:discovery' }) + 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"; @@ -197,12 +206,22 @@ sub discover }); $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(); + $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 + 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::To->new({ value => 'urn:schemas-xmlsoap-org:ws:2005:04:discovery' }) + 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"; diff --git a/web/ajax/alarm.php b/web/ajax/alarm.php index b1f5f1496..2d4690866 100644 --- a/web/ajax/alarm.php +++ b/web/ajax/alarm.php @@ -1,5 +1,4 @@ diff --git a/web/includes/functions.php b/web/includes/functions.php index aa248314f..4808d61ef 100644 --- a/web/includes/functions.php +++ b/web/includes/functions.php @@ -108,31 +108,25 @@ function CORSHeaders() { } function getAuthUser( $auth ) { - if ( ZM_OPT_USE_AUTH && ZM_AUTH_RELAY == "hashed" && !empty($auth) ) - { + if ( ZM_OPT_USE_AUTH && ZM_AUTH_RELAY == "hashed" && !empty($auth) ) { $remoteAddr = ""; - if ( ZM_AUTH_HASH_IPS ) - { + if ( ZM_AUTH_HASH_IPS ) { $remoteAddr = $_SERVER['REMOTE_ADDR']; - if ( !$remoteAddr ) - { + if ( !$remoteAddr ) { Error( "Can't determine remote address for authentication, using empty string" ); $remoteAddr = ""; } } $sql = "select Username, Password, Enabled, Stream+0, Events+0, Control+0, Monitors+0, System+0, MonitorIds from Users where Enabled = 1"; - foreach ( dbFetchAll( $sql ) as $user ) - { + foreach ( dbFetchAll( $sql ) as $user ) { $now = time(); - for ( $i = 0; $i < 2; $i++, $now -= (60*60) ) // Try for last two hours - { + for ( $i = 0; $i < 2; $i++, $now -= (60*60) ) { // Try for last two hours $time = localtime( $now ); $authKey = ZM_AUTH_HASH_SECRET.$user['Username'].$user['Password'].$remoteAddr.$time[2].$time[3].$time[4].$time[5]; $authHash = md5( $authKey ); - if ( $auth == $authHash ) - { + if ( $auth == $authHash ) { return( $user ); } } @@ -142,73 +136,52 @@ function getAuthUser( $auth ) { return( false ); } -function generateAuthHash( $useRemoteAddr ) -{ - if ( ZM_OPT_USE_AUTH && ZM_AUTH_RELAY == "hashed" ) - { +function generateAuthHash( $useRemoteAddr ) { + if ( ZM_OPT_USE_AUTH && ZM_AUTH_RELAY == "hashed" ) { $time = localtime(); - if ( $useRemoteAddr ) - { + if ( $useRemoteAddr ) { $authKey = ZM_AUTH_HASH_SECRET.$_SESSION['username'].$_SESSION['passwordHash'].$_SESSION['remoteAddr'].$time[2].$time[3].$time[4].$time[5]; - } - else - { + } else { $authKey = ZM_AUTH_HASH_SECRET.$_SESSION['username'].$_SESSION['passwordHash'].$time[2].$time[3].$time[4].$time[5]; } $auth = md5( $authKey ); - } - else - { + } else { $auth = ""; } return( $auth ); } -function getStreamSrc( $args, $querySep='&' ) -{ +function getStreamSrc( $args, $querySep='&' ) { $streamSrc = ZM_BASE_URL.ZM_PATH_ZMS; - if ( ZM_OPT_USE_AUTH ) - { - if ( ZM_AUTH_RELAY == "hashed" ) - { + if ( ZM_OPT_USE_AUTH ) { + if ( ZM_AUTH_RELAY == "hashed" ) { $args[] = "auth=".generateAuthHash( ZM_AUTH_HASH_IPS ); - } - elseif ( ZM_AUTH_RELAY == "plain" ) - { + } elseif ( ZM_AUTH_RELAY == "plain" ) { $args[] = "user=".$_SESSION['username']; $args[] = "pass=".$_SESSION['password']; - } - elseif ( ZM_AUTH_RELAY == "none" ) - { + } elseif ( ZM_AUTH_RELAY == "none" ) { $args[] = "user=".$_SESSION['username']; } } - if ( !in_array( "mode=single", $args ) && !empty($GLOBALS['connkey']) ) - { + if ( !in_array( "mode=single", $args ) && !empty($GLOBALS['connkey']) ) { $args[] = "connkey=".$GLOBALS['connkey']; } - if ( ZM_RAND_STREAM ) - { + if ( ZM_RAND_STREAM ) { $args[] = "rand=".time(); } - if ( count($args) ) - { + if ( count($args) ) { $streamSrc .= "?".join( $querySep, $args ); } return( $streamSrc ); } -function getMimeType( $file ) -{ - if ( function_exists('mime_content_type') ) - { +function getMimeType( $file ) { + if ( function_exists('mime_content_type') ) { return( mime_content_type( $file ) ); - } - elseif ( function_exists('finfo_file') ) - { + } elseif ( function_exists('finfo_file') ) { $finfo = finfo_open( FILEINFO_MIME ); $mimeType = finfo_file( $finfo, $file ); finfo_close($finfo); @@ -350,42 +323,27 @@ function getImageStream( $id, $src, $width, $height, $title="" ) { } } -function outputControlStream( $src, $width, $height, $monitor, $scale, $target ) -{ - ?> -
+function outputControlStream( $src, $width, $height, $monitor, $scale, $target ) { +?> + - - - + + + - + - + -
- + +function outputHelperStream( $id, $src, $width, $height, $title="" ) { +?> - - + + - - + @@ -439,8 +392,7 @@ function outputControlStill( $src, $width, $height, $monitor, $scale, $target ) } // Incoming args are shell-escaped. This function must escape any further arguments it cannot guarantee. -function getZmuCommand( $args ) -{ +function getZmuCommand( $args ) { $zmuCommand = ZMU_PATH; if ( ZM_OPT_USE_AUTH ) @@ -464,30 +416,25 @@ function getZmuCommand( $args ) return( $zmuCommand ); } -function visibleMonitor( $mid ) -{ +function visibleMonitor( $mid ) { global $user; return( empty($user['MonitorIds']) || in_array( $mid, explode( ',', $user['MonitorIds'] ) ) ); } -function canView( $area, $mid=false ) -{ +function canView( $area, $mid=false ) { global $user; return( ($user[$area] == 'View' || $user[$area] == 'Edit') && ( !$mid || visibleMonitor( $mid ) ) ); } -function canEdit( $area, $mid=false ) -{ +function canEdit( $area, $mid=false ) { global $user; return( $user[$area] == 'Edit' && ( !$mid || visibleMonitor( $mid ) ) ); } -function getEventPath( $event ) -{ - +function getEventPath( $event ) { if ( ZM_USE_DEEP_STORAGE ) $eventPath = $event['MonitorId'].'/'.strftime( "%y/%m/%d/%H/%M/%S", strtotime($event['StartTime']) ); else @@ -501,14 +448,10 @@ function getEventDefaultVideoPath( $event ) { //$Event->Path().'/'.$event['DefaultVideo']; } -function deletePath( $path ) -{ - if ( is_dir( $path ) ) - { +function deletePath( $path ) { + if ( is_dir( $path ) ) { system( escapeshellcmd( "rm -rf ".$path ) ); - } - else - { + } else { unlink( $path ); } } @@ -532,26 +475,21 @@ function deleteEvent( $event ) { } # CAN EDIT } -function makeLink( $url, $label, $condition=1, $options="" ) -{ +function makeLink( $url, $label, $condition=1, $options="" ) { $string = ""; - if ( $condition ) - { + if ( $condition ) { $string .= ''; } $string .= $label; - if ( $condition ) - { + if ( $condition ) { $string .= ''; } return( $string ); } -function makePopupLink( $url, $winName, $winSize, $label, $condition=1, $options="" ) -{ +function makePopupLink( $url, $winName, $winSize, $label, $condition=1, $options="" ) { $string = ""; - if ( $condition ) - { + if ( $condition ) { if ( is_array( $winSize ) ) $popupParms = "'".$url."', '".$winName."', '".$winSize[0]."', ".$winSize[1].", ".$winSize[2]; else @@ -560,15 +498,13 @@ function makePopupLink( $url, $winName, $winSize, $label, $condition=1, $options $string .= ''; } $string .= $label; - if ( $condition ) - { + if ( $condition ) { $string .= ''; } return( $string ); } -function makePopupButton( $url, $winName, $winSize, $buttonValue, $condition=1, $options="" ) -{ +function makePopupButton( $url, $winName, $winSize, $buttonValue, $condition=1, $options="" ) { if ( is_array( $winSize ) ) $popupParms = "'".$url."', '".$winName."', '".$winSize[0]."', ".$winSize[1].", ".$winSize[2]; else @@ -577,8 +513,7 @@ function makePopupButton( $url, $winName, $winSize, $buttonValue, $condition=1, return( $string ); } -function truncText( $text, $length, $deslash=1 ) -{ +function truncText( $text, $length, $deslash=1 ) { return( preg_replace( "/^(.{".$length.",}?)\b.*$/", "\\1…", ($deslash?stripslashes($text):$text) ) ); } @@ -607,25 +542,20 @@ function htmlSelect( $name, $contents, $values, $behaviours=false ) { function buildSelect( $name, $contents, $behaviours=false ) { $value = ""; - if ( preg_match( "/^\s*(\w+)\s*(\[.*\])?\s*$/", $name, $matches ) && count($matches) > 2 ) - { + if ( preg_match( "/^\s*(\w+)\s*(\[.*\])?\s*$/", $name, $matches ) && count($matches) > 2 ) { $arr = $matches[1]; if ( isset($GLOBALS[$arr]) ) $value = $GLOBALS[$arr]; elseif ( isset($_REQUEST[$arr]) ) $value = $_REQUEST[$arr]; - if ( !preg_match_all( "/\[\s*['\"]?(\w+)[\"']?\s*\]/", $matches[2], $matches ) ) - { + if ( !preg_match_all( "/\[\s*['\"]?(\w+)[\"']?\s*\]/", $matches[2], $matches ) ) { Fatal( "Can't parse selector '$name'" ); } - for ( $i = 0; $i < count($matches[1]); $i++ ) - { + for ( $i = 0; $i < count($matches[1]); $i++ ) { $idx = $matches[1][$i]; $value = isset($value[$idx])?$value[$idx]:false; } - } - else - { + } else { if ( isset($GLOBALS[$name]) ) $value = $GLOBALS[$name]; elseif ( isset($_REQUEST[$name]) ) @@ -633,72 +563,58 @@ function buildSelect( $name, $contents, $behaviours=false ) } ob_start(); $behaviourText = ""; - if ( !empty($behaviours) ) - { - if ( is_array($behaviours) ) - { - foreach ( $behaviours as $event=>$action ) - { + if ( !empty($behaviours) ) { + if ( is_array($behaviours) ) { + foreach ( $behaviours as $event=>$action ) { $behaviourText .= ' '.$event.'="'.$action.'"'; } - } - else - { + } else { $behaviourText = ' onchange="'.$behaviours.'"'; } } ?> - - " selected="selected"> + + + $value ) - { + foreach( $newValues as $key=>$value ) { if ( $columns && !$columns[$key] ) continue; if ( !isset($types[$key]) ) $types[$key] = false; - switch( $types[$key] ) - { + switch( $types[$key] ) { case 'set' : { - if ( is_array( $newValues[$key] ) ) - { - if ( join(',',$newValues[$key]) != $values[$key] ) - { + if ( is_array( $newValues[$key] ) ) { + if ( join(',',$newValues[$key]) != $values[$key] ) { $changes[$key] = "$key = ".dbEscape(join(',',$newValues[$key])); } - } - elseif ( $values[$key] ) - { + } elseif ( $values[$key] ) { $changes[$key] = "$key = ''"; } break; } case 'image' : { - if ( is_array( $newValues[$key] ) ) - { + if ( is_array( $newValues[$key] ) ) { $imageData = getimagesize( $newValues[$key]['tmp_name'] ); $changes[$key.'Width'] = $key."Width = ".$imageData[0]; $changes[$key.'Height'] = $key."Height = ".$imageData[1]; @@ -708,17 +624,14 @@ function getFormChanges( $values, $newValues, $types=false, $columns=false ) readfile( $newValues[$key]['tmp_name'] ); $changes[$key] = $key." = ".dbEscape( ob_get_contents() ); ob_end_clean(); - } - else - { + } else { $changes[$key] = "$key = ".dbEscape($value); } break; } case 'document' : { - if ( is_array( $newValues[$key] ) ) - { + if ( is_array( $newValues[$key] ) ) { $imageData = getimagesize( $newValues[$key]['tmp_name'] ); $changes[$key.'Type'] = $key."Type = '".$newValues[$key]['type']."'"; $changes[$key.'Size'] = $key."Size = ".$newValues[$key]['size']; @@ -726,9 +639,7 @@ function getFormChanges( $values, $newValues, $types=false, $columns=false ) readfile( $newValues[$key]['tmp_name'] ); $changes[$key] = $key." = ".dbEscape( ob_get_contents() ); ob_end_clean(); - } - else - { + } else { $changes[$key] = "$key = ".dbEscape($value); } break; @@ -745,16 +656,14 @@ function getFormChanges( $values, $newValues, $types=false, $columns=false ) } case 'raw' : { - if ( $values[$key] != $value ) - { + if ( $values[$key] != $value ) { $changes[$key] = "$key = ".dbEscape($value); } break; } default : { - if ( !isset($values[$key]) || ($values[$key] != $value) ) - { + if ( !isset($values[$key]) || ($values[$key] != $value) ) { if ( ! isset($value) || $value == '' ) { $changes[$key] = "$key = NULL"; } else { @@ -765,16 +674,11 @@ function getFormChanges( $values, $newValues, $types=false, $columns=false ) } } } - foreach( $values as $key=>$value ) - { - if ( !empty($columns[$key]) ) - { - if ( !empty($types[$key]) ) - { - if ( $types[$key] == 'toggle' ) - { - if ( !isset($newValues[$key]) && !empty($value) ) - { + foreach( $values as $key=>$value ) { + if ( !empty($columns[$key]) ) { + if ( !empty($types[$key]) ) { + if ( $types[$key] == 'toggle' ) { + if ( !isset($newValues[$key]) && !empty($value) ) { $changes[$key] = "$key = 0"; } } @@ -788,55 +692,35 @@ function getFormChanges( $values, $newValues, $types=false, $columns=false ) return( $changes ); } -function getBrowser( &$browser, &$version ) -{ - if ( isset($_SESSION['browser']) ) - { +function getBrowser( &$browser, &$version ) { + if ( isset($_SESSION['browser']) ) { $browser = $_SESSION['browser']; $version = $_SESSION['version']; - } - else - { - if (( preg_match( '/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $logVersion)) || (preg_match( '/.*Trident.*rv:(.*?)(;|\))/', $_SERVER['HTTP_USER_AGENT'], $logVersion))) - { + } else { + if (( preg_match( '/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $logVersion)) || (preg_match( '/.*Trident.*rv:(.*?)(;|\))/', $_SERVER['HTTP_USER_AGENT'], $logVersion))) { $version = $logVersion[1]; $browser = 'ie'; - } - elseif ( preg_match( '/Chrome\/([0-9.]+)/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) - { + } elseif ( preg_match( '/Chrome\/([0-9.]+)/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) { $version = $logVersion[1]; // Check for old version of Chrome with bug 5876 - if ( $version < 7 ) - { + if ( $version < 7 ) { $browser = 'oldchrome'; - } - else - { + } else { $browser = 'chrome'; } - } - elseif ( preg_match( '/Safari\/([0-9.]+)/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) - { + } elseif ( preg_match( '/Safari\/([0-9.]+)/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) { $version = $logVersion[1]; $browser = 'safari'; - } - elseif ( preg_match( '/Opera[ \/]([0-9].[0-9]{1,2})/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) - { + } elseif ( preg_match( '/Opera[ \/]([0-9].[0-9]{1,2})/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) { $version = $logVersion[1]; $browser = 'opera'; - } - elseif ( preg_match( '/Konqueror\/([0-9.]+)/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) - { + } elseif ( preg_match( '/Konqueror\/([0-9.]+)/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) { $version = $logVersion[1]; $browser = 'konqueror'; - } - elseif ( preg_match( '/Mozilla\/([0-9].[0-9]{1,2})/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) - { + } elseif ( preg_match( '/Mozilla\/([0-9].[0-9]{1,2})/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) { $version = $logVersion[1]; $browser = 'mozilla'; - } - else - { + } else { $version = 0; $browser = 'unknown'; } @@ -845,101 +729,84 @@ function getBrowser( &$browser, &$version ) } } -function isMozilla() -{ +function isMozilla() { getBrowser( $browser, $version ); return( $browser == "mozilla" ); } -function isKonqueror() -{ +function isKonqueror() { getBrowser( $browser, $version ); return( $browser == "konqueror" ); } -function isInternetExplorer() -{ +function isInternetExplorer() { getBrowser( $browser, $version ); return( $browser == "ie" ); } -function isOldChrome() -{ +function isOldChrome() { getBrowser( $browser, $version ); return( $browser == "oldchrome" ); } -function isChrome() -{ +function isChrome() { getBrowser( $browser, $version ); return( $browser == "chrome" ); } -function isOpera() -{ +function isOpera() { getBrowser( $browser, $version ); return( $browser == "opera" ); } -function isSafari() -{ +function isSafari() { getBrowser( $browser, $version ); return( $browser == "safari" ); } -function isWindows() -{ +function isWindows() { return ( preg_match( '/Win/', $_SERVER['HTTP_USER_AGENT'] ) ); } -function canStreamIframe() -{ +function canStreamIframe() { return( isKonqueror() ); } -function canStreamNative() -{ +function canStreamNative() { // Old versions of Chrome can display the stream, but then it blocks everything else (Chrome bug 5876) return( ZM_WEB_CAN_STREAM == "yes" || ( ZM_WEB_CAN_STREAM == "auto" && (!isInternetExplorer() && !isOldChrome()) ) ); } -function canStreamApplet() -{ - if ( (ZM_OPT_CAMBOZOLA && !file_exists( ZM_PATH_WEB.'/'.ZM_PATH_CAMBOZOLA )) ) - { +function canStreamApplet() { + if ( (ZM_OPT_CAMBOZOLA && !file_exists( ZM_PATH_WEB.'/'.ZM_PATH_CAMBOZOLA )) ) { Warning ( "ZM_OPT_CAMBOZOLA is enabled, but the system cannot find ".ZM_PATH_WEB."/".ZM_PATH_CAMBOZOLA ); } return( (ZM_OPT_CAMBOZOLA && file_exists( ZM_PATH_WEB.'/'.ZM_PATH_CAMBOZOLA )) ); } -function canStream() -{ +function canStream() { return( canStreamNative() | canStreamApplet() ); } -function packageControl( $command ) -{ +function packageControl( $command ) { $string = ZM_PATH_BIN.'/zmpkg.pl '.escapeshellarg( $command ); $string .= " 2>/dev/null >&- <&- >/dev/null"; exec( $string ); } -function daemonControl( $command, $daemon=false, $args=false ) -{ +function daemonControl( $command, $daemon=false, $args=false ) { $string = ZM_PATH_BIN."/zmdc.pl $command"; - if ( $daemon ) - { + if ( $daemon ) { $string .= " $daemon"; - if ( $args ) - { + if ( $args ) { $string .= " $args"; } } @@ -947,30 +814,22 @@ function daemonControl( $command, $daemon=false, $args=false ) exec( $string ); } -function zmcControl( $monitor, $mode=false ) -{ +function zmcControl( $monitor, $mode=false ) { if ( (!defined('ZM_SERVER_ID')) or ( ZM_SERVER_ID==$monitor['ServerId'] ) ) { - $row = NULL; - if ( $monitor['Type'] == "Local" ) - { + $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']; - } - else - { + } else { $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" ) - { + if ( !$activeCount || $mode == "stop" ) { daemonControl( "stop", "zmc", $zmcArgs ); - } - else - { - if ( $mode == "restart" ) - { + } else { + if ( $mode == "restart" ) { daemonControl( "stop", "zmc", $zmcArgs ); } daemonControl( "start", "zmc", $zmcArgs ); @@ -978,76 +837,57 @@ function zmcControl( $monitor, $mode=false ) } } -function zmaControl( $monitor, $mode=false ) -{ +function zmaControl( $monitor, $mode=false ) { if ( (!defined('ZM_SERVER_ID')) or ( ZM_SERVER_ID==$monitor['ServerId'] ) ) { - if ( !is_array( $monitor ) ) - { + if ( !is_array( $monitor ) ) { $monitor = dbFetchOne( "select C.*, M.* from Monitors as M left join Controls as C on (M.ControlId = C.Id ) where M.Id=?", NULL, array($monitor) ); } - if ( !$monitor || $monitor['Function'] == 'None' || $monitor['Function'] == 'Monitor' || $mode == "stop" ) - { - if ( ZM_OPT_CONTROL ) - { + if ( !$monitor || $monitor['Function'] == 'None' || $monitor['Function'] == 'Monitor' || $mode == "stop" ) { + if ( ZM_OPT_CONTROL ) { daemonControl( "stop", "zmtrack.pl", "-m ".$monitor['Id'] ); } daemonControl( "stop", "zma", "-m ".$monitor['Id'] ); - if ( ZM_OPT_FRAME_SERVER ) - { + if ( ZM_OPT_FRAME_SERVER ) { daemonControl( "stop", "zmf", "-m ".$monitor['Id'] ); } - } - else - { - if ( $mode == "restart" ) - { - if ( ZM_OPT_CONTROL ) - { + } else { + if ( $mode == "restart" ) { + if ( ZM_OPT_CONTROL ) { daemonControl( "stop", "zmtrack.pl", "-m ".$monitor['Id'] ); } daemonControl( "stop", "zma", "-m ".$monitor['Id'] ); - if ( ZM_OPT_FRAME_SERVER ) - { + if ( ZM_OPT_FRAME_SERVER ) { daemonControl( "stop", "zmf", "-m ".$monitor['Id'] ); } } - if ( ZM_OPT_FRAME_SERVER ) - { + if ( ZM_OPT_FRAME_SERVER ) { daemonControl( "start", "zmf", "-m ".$monitor['Id'] ); } daemonControl( "start", "zma", "-m ".$monitor['Id'] ); - if ( ZM_OPT_CONTROL && $monitor['Controllable'] && $monitor['TrackMotion'] && ( $monitor['Function'] == 'Modect' || $monitor['Function'] == 'Mocord' ) ) - { + if ( ZM_OPT_CONTROL && $monitor['Controllable'] && $monitor['TrackMotion'] && ( $monitor['Function'] == 'Modect' || $monitor['Function'] == 'Mocord' ) ) { daemonControl( "start", "zmtrack.pl", "-m ".$monitor['Id'] ); } - if ( $mode == "reload" ) - { + if ( $mode == "reload" ) { daemonControl( "reload", "zma", "-m ".$monitor['Id'] ); } } } } -function initDaemonStatus() -{ +function initDaemonStatus() { global $daemon_status; - if ( !isset($daemon_status) ) - { - if ( daemonCheck() ) - { + if ( !isset($daemon_status) ) { + if ( daemonCheck() ) { $string = ZM_PATH_BIN."/zmdc.pl status"; $daemon_status = shell_exec( $string ); - } - else - { + } else { $daemon_status = ""; } } } -function daemonStatus( $daemon, $args=false ) -{ +function daemonStatus( $daemon, $args=false ) { global $daemon_status; initDaemonStatus(); @@ -1058,33 +898,25 @@ function daemonStatus( $daemon, $args=false ) return( strpos( $daemon_status, "'$string' running" ) !== false ); } -function zmcStatus( $monitor ) -{ - if ( $monitor['Type'] == 'Local' ) - { +function zmcStatus( $monitor ) { + if ( $monitor['Type'] == 'Local' ) { $zmcArgs = "-d ".$monitor['Device']; - } - else - { + } else { $zmcArgs = "-m ".$monitor['Id']; } return( daemonStatus( "zmc", $zmcArgs ) ); } -function zmaStatus( $monitor ) -{ - if ( is_array( $monitor ) ) - { +function zmaStatus( $monitor ) { + if ( is_array( $monitor ) ) { $monitor = $monitor['Id']; } return( daemonStatus( "zma", "-m $monitor" ) ); } -function daemonCheck( $daemon=false, $args=false ) -{ +function daemonCheck( $daemon=false, $args=false ) { $string = ZM_PATH_BIN."/zmdc.pl check"; - if ( $daemon ) - { + if ( $daemon ) { $string .= " $daemon"; if ( $args ) $string .= " $args"; @@ -1093,23 +925,17 @@ function daemonCheck( $daemon=false, $args=false ) return( preg_match( '/running/', $result ) ); } -function zmcCheck( $monitor ) -{ - if ( $monitor['Type'] == 'Local' ) - { +function zmcCheck( $monitor ) { + if ( $monitor['Type'] == 'Local' ) { $zmcArgs = "-d ".$monitor['Device']; - } - else - { + } else { $zmcArgs = "-m ".$monitor['Id']; } return( daemonCheck( "zmc", $zmcArgs ) ); } -function zmaCheck( $monitor ) -{ - if ( is_array( $monitor ) ) - { +function zmaCheck( $monitor ) { + if ( is_array( $monitor ) ) { $monitor = $monitor['Id']; } return( daemonCheck( "zma", "-m $monitor" ) ); @@ -1218,42 +1044,32 @@ function getImageSrc( $event, $frame, $scale=SCALE_BASE, $captureOnly=false, $ov return( $imageData ); } -function viewImagePath( $path, $querySep='&' ) -{ - if ( strncmp( $path, ZM_DIR_IMAGES, strlen(ZM_DIR_IMAGES) ) == 0 ) - { +function viewImagePath( $path, $querySep='&' ) { + if ( strncmp( $path, ZM_DIR_IMAGES, strlen(ZM_DIR_IMAGES) ) == 0 ) { // Thumbnails return( $path ); - } - elseif ( strpos( ZM_DIR_EVENTS, '/' ) === 0 ) - { + } elseif ( strpos( ZM_DIR_EVENTS, '/' ) === 0 ) { return( '?view=image'.$querySep.'path='.$path ); } return( ZM_DIR_EVENTS.'/'.$path ); } -function createListThumbnail( $event, $overwrite=false ) -{ +function createListThumbnail( $event, $overwrite=false ) { # Load the frame with the highest score to use as a thumbnail if ( !($frame = dbFetchOne( "SELECT * FROM Frames WHERE EventId=? AND Score=? ORDER BY FrameId LIMIT 1", NULL, array( $event['Id'], $event['MaxScore'] ) )) ) return( false ); $frameId = $frame['FrameId']; - if ( ZM_WEB_LIST_THUMB_WIDTH ) - { + if ( ZM_WEB_LIST_THUMB_WIDTH ) { $thumbWidth = ZM_WEB_LIST_THUMB_WIDTH; $scale = (SCALE_BASE*ZM_WEB_LIST_THUMB_WIDTH)/$event['Width']; $thumbHeight = reScale( $event['Height'], $scale ); - } - elseif ( ZM_WEB_LIST_THUMB_HEIGHT ) - { + } elseif ( ZM_WEB_LIST_THUMB_HEIGHT ) { $thumbHeight = ZM_WEB_LIST_THUMB_HEIGHT; $scale = (SCALE_BASE*ZM_WEB_LIST_THUMB_HEIGHT)/$event['Height']; $thumbWidth = reScale( $event['Width'], $scale ); - } - else - { + } else { Fatal( "No thumbnail width or height specified, please check in Options->Web" ); } @@ -1269,8 +1085,7 @@ function createListThumbnail( $event, $overwrite=false ) return( $thumbData ); } -function createVideo( $event, $format, $rate, $scale, $overwrite=false ) -{ +function createVideo( $event, $format, $rate, $scale, $overwrite=false ) { $command = ZM_PATH_BIN."/zmvideo.pl -e ".$event['Id']." -f ".$format." -r ".sprintf( "%.2F", ($rate/RATE_BASE) ); if ( preg_match( '/\d+x\d+/', $scale ) ) $command .= " -S ".$scale; @@ -1285,8 +1100,7 @@ function createVideo( $event, $format, $rate, $scale, $overwrite=false ) return( $status?"":rtrim($result) ); } -function executeFilter( $filter ) -{ +function executeFilter( $filter ) { $command = ZM_PATH_BIN."/zmfilter.pl --filter ".escapeshellarg($filter); $result = exec( $command, $output, $status ); dbQuery( "delete from Filters where Name like '_TempFilter%'" ); @@ -1295,11 +1109,9 @@ function executeFilter( $filter ) # This takes more than one scale amount, so it runs through each and alters dimension. # I can't imagine why you would want to do that. -function reScale( $dimension, $dummy ) -{ +function reScale( $dimension, $dummy ) { $new_dimension = $dimension; - for ( $i = 1; $i < func_num_args(); $i++ ) - { + for ( $i = 1; $i < func_num_args(); $i++ ) { $scale = func_get_arg( $i ); if ( !empty($scale) && $scale != SCALE_BASE ) $new_dimension = (int)(($new_dimension*$scale)/SCALE_BASE); @@ -1307,11 +1119,9 @@ function reScale( $dimension, $dummy ) return( $new_dimension ); } -function deScale( $dimension, $dummy ) -{ +function deScale( $dimension, $dummy ) { $new_dimension = $dimension; - for ( $i = 1; $i < func_num_args(); $i++ ) - { + for ( $i = 1; $i < func_num_args(); $i++ ) { $scale = func_get_arg( $i ); if ( !empty($scale) && $scale != SCALE_BASE ) $new_dimension = (int)(($new_dimension*SCALE_BASE)/$scale); @@ -1319,8 +1129,7 @@ function deScale( $dimension, $dummy ) return( $new_dimension ); } -function monitorLimitSql() -{ +function monitorLimitSql() { global $user; if ( !empty($user['MonitorIds']) ) $midSql = " and MonitorId in (".join( ",", preg_split( '/["\'\s]*,["\'\s]*/', $user['MonitorIds'] ) ).")"; @@ -1329,17 +1138,14 @@ function monitorLimitSql() return( $midSql ); } -function parseSort( $saveToSession=false, $querySep='&' ) -{ +function parseSort( $saveToSession=false, $querySep='&' ) { global $sortQuery, $sortColumn, $sortOrder; // Outputs - if ( empty($_REQUEST['sort_field']) ) - { + if ( empty($_REQUEST['sort_field']) ) { $_REQUEST['sort_field'] = ZM_WEB_EVENT_SORT_FIELD; $_REQUEST['sort_asc'] = (ZM_WEB_EVENT_SORT_ORDER == "asc"); } - switch( $_REQUEST['sort_field'] ) - { + switch( $_REQUEST['sort_field'] ) { case 'Id' : $sortColumn = "E.Id"; break; @@ -1385,41 +1191,33 @@ function parseSort( $saveToSession=false, $querySep='&' ) $sortQuery = $querySep."sort_field=".validHtmlStr($_REQUEST['sort_field']).$querySep."sort_asc=".validHtmlStr($_REQUEST['sort_asc']); if ( !isset($_REQUEST['limit']) ) $_REQUEST['limit'] = ""; - if ( $saveToSession ) - { + if ( $saveToSession ) { $_SESSION['sort_field'] = validHtmlStr($_REQUEST['sort_field']); $_SESSION['sort_asc'] = validHtmlStr($_REQUEST['sort_asc']); } } -function parseFilter( &$filter, $saveToSession=false, $querySep='&' ) -{ +function parseFilter( &$filter, $saveToSession=false, $querySep='&' ) { $filter['query'] = ''; $filter['sql'] = ''; $filter['fields'] = ''; - if ( isset($filter['terms']) && count($filter['terms']) ) - { - for ( $i = 0; $i < count($filter['terms']); $i++ ) - { - if ( isset($filter['terms'][$i]['cnj']) ) - { + if ( isset($filter['terms']) && count($filter['terms']) ) { + for ( $i = 0; $i < count($filter['terms']); $i++ ) { + if ( isset($filter['terms'][$i]['cnj']) ) { $filter['query'] .= $querySep."filter[terms][$i][cnj]=".urlencode($filter['terms'][$i]['cnj']); $filter['sql'] .= " ".$filter['terms'][$i]['cnj']." "; $filter['fields'] .= "\n"; } - if ( isset($filter['terms'][$i]['obr']) ) - { + if ( isset($filter['terms'][$i]['obr']) ) { $filter['query'] .= $querySep."filter[terms][$i][obr]=".urlencode($filter['terms'][$i]['obr']); $filter['sql'] .= " ".str_repeat( "(", $filter['terms'][$i]['obr'] )." "; $filter['fields'] .= "\n"; } - if ( isset($filter['terms'][$i]['attr']) ) - { + if ( isset($filter['terms'][$i]['attr']) ) { $filter['query'] .= $querySep."filter[terms][$i][attr]=".urlencode($filter['terms'][$i]['attr']); $filter['fields'] .= "\n"; - switch ( $filter['terms'][$i]['attr'] ) - { + switch ( $filter['terms'][$i]['attr'] ) { case 'MonitorName': $filter['sql'] .= 'M.'.preg_replace( '/^Monitor/', '', $filter['terms'][$i]['attr'] ); break; @@ -1464,10 +1262,8 @@ function parseFilter( &$filter, $saveToSession=false, $querySep='&' ) break; } $valueList = array(); - foreach ( preg_split( '/["\'\s]*?,["\'\s]*?/', preg_replace( '/^["\']+?(.+)["\']+?$/', '$1', $filter['terms'][$i]['val'] ) ) as $value ) - { - switch ( $filter['terms'][$i]['attr'] ) - { + foreach ( preg_split( '/["\'\s]*?,["\'\s]*?/', preg_replace( '/^["\']+?(.+)["\']+?$/', '$1', $filter['terms'][$i]['val'] ) ) as $value ) { + switch ( $filter['terms'][$i]['attr'] ) { case 'MonitorName': case 'Name': case 'Cause': @@ -1496,8 +1292,7 @@ function parseFilter( &$filter, $saveToSession=false, $querySep='&' ) $valueList[] = $value; } - switch ( $filter['terms'][$i]['op'] ) - { + switch ( $filter['terms'][$i]['op'] ) { case '=' : case '!=' : case '>=' : @@ -1525,8 +1320,7 @@ function parseFilter( &$filter, $saveToSession=false, $querySep='&' ) $filter['query'] .= $querySep."filter[terms][$i][val]=".urlencode($filter['terms'][$i]['val']); $filter['fields'] .= "\n"; } - if ( isset($filter['terms'][$i]['cbr']) ) - { + if ( isset($filter['terms'][$i]['cbr']) ) { $filter['query'] .= $querySep."filter[terms][$i][cbr]=".urlencode($filter['terms'][$i]['cbr']); $filter['sql'] .= " ".str_repeat( ")", $filter['terms'][$i]['cbr'] )." "; $filter['fields'] .= "\n"; @@ -1534,15 +1328,13 @@ function parseFilter( &$filter, $saveToSession=false, $querySep='&' ) } if ( $filter['sql'] ) $filter['sql'] = " and ( ".$filter['sql']." )"; - if ( $saveToSession ) - { + if ( $saveToSession ) { $_SESSION['filter'] = $filter; } } } -function addFilterTerm( $filter, $position, $term=false ) -{ +function addFilterTerm( $filter, $position, $term=false ) { if ( $position < 0 ) $position = 0; elseif( $position > count($filter['terms']) ) @@ -1554,8 +1346,7 @@ function addFilterTerm( $filter, $position, $term=false ) return( $filter ); } -function delFilterTerm( $filter, $position ) -{ +function delFilterTerm( $filter, $position ) { if ( $position < 0 ) $position = 0; elseif( $position >= count($filter['terms']) ) @@ -1565,24 +1356,19 @@ function delFilterTerm( $filter, $position ) return( $filter ); } -function getPagination( $pages, $page, $maxShortcuts, $query, $querySep='&' ) -{ +function getPagination( $pages, $page, $maxShortcuts, $query, $querySep='&' ) { global $view; $pageText = ""; - if ( $pages > 1 ) - { - if ( $page ) - { + if ( $pages > 1 ) { + if ( $page ) { if ( $page < 0 ) $page = 1; if ( $page > $pages ) $page = $pages; - if ( $page > 1 ) - { - if ( false && $page > 2 ) - { + if ( $page > 1 ) { + if ( false && $page > 2 ) { $pageText .= '<<'; } $pageText .= '<'; @@ -1590,8 +1376,7 @@ function getPagination( $pages, $page, $maxShortcuts, $query, $querySep='&' $newPages = array(); $pagesUsed = array(); $lo_exp = max(2,log($page-1)/log($maxShortcuts)); - for ( $i = 0; $i < $maxShortcuts; $i++ ) - { + for ( $i = 0; $i < $maxShortcuts; $i++ ) { $newPage = round($page-pow($lo_exp,$i)); if ( isset($pagesUsed[$newPage]) ) continue; @@ -1603,20 +1388,17 @@ function getPagination( $pages, $page, $maxShortcuts, $query, $querySep='&' if ( !isset($pagesUsed[1]) ) array_unshift( $newPages, 1 ); - foreach ( $newPages as $newPage ) - { + foreach ( $newPages as $newPage ) { $pageText .= ''.$newPage.' '; } } $pageText .= '- '.$page.' -'; - if ( $page < $pages ) - { + if ( $page < $pages ) { $newPages = array(); $pagesUsed = array(); $hi_exp = max(2,log($pages-$page)/log($maxShortcuts)); - for ( $i = 0; $i < $maxShortcuts; $i++ ) - { + for ( $i = 0; $i < $maxShortcuts; $i++ ) { $newPage = round($page+pow($hi_exp,$i)); if ( isset($pagesUsed[$newPage]) ) continue; @@ -1628,13 +1410,11 @@ function getPagination( $pages, $page, $maxShortcuts, $query, $querySep='&' if ( !isset($pagesUsed[$pages]) ) array_push( $newPages, $pages ); - foreach ( $newPages as $newPage ) - { + foreach ( $newPages as $newPage ) { $pageText .= ' '.$newPage.''; } $pageText .= '>'; - if ( false && $page < ($pages-1) ) - { + if ( false && $page < ($pages-1) ) { $pageText .= '>>'; } } @@ -1643,14 +1423,12 @@ function getPagination( $pages, $page, $maxShortcuts, $query, $querySep='&' return( $pageText ); } -function sortHeader( $field, $querySep='&' ) -{ +function sortHeader( $field, $querySep='&' ) { global $view; return( '?view='.$view.$querySep.'page=1'.$_REQUEST['filter']['query'].$querySep.'sort_field='.$field.$querySep.'sort_asc='.($_REQUEST['sort_field'] == $field?!$_REQUEST['sort_asc']:0).$querySep.'limit='.$_REQUEST['limit'] ); } -function sortTag( $field ) -{ +function sortTag( $field ) { if ( $_REQUEST['sort_field'] == $field ) if ( $_REQUEST['sort_asc'] ) return( "(^)" ); @@ -1659,29 +1437,26 @@ function sortTag( $field ) return( false ); } -function getLoad() -{ +function getLoad() { $load = sys_getloadavg(); return( $load[0] ); } -function getDiskPercent() -{ +function getDiskPercent() { $total = disk_total_space(ZM_DIR_EVENTS); if ( ! $total ) { Error("disk_total_space returned false for " . ZM_DIR_EVENTS ); return 0; } - $free = disk_free_space(ZM_DIR_EVENTS); - if ( ! $free ) { - Error("disk_free_space returned false for " . ZM_DIR_EVENTS ); - } - $space = round(($total - $free) / $total * 100); + $free = disk_free_space(ZM_DIR_EVENTS); + if ( ! $free ) { + Error("disk_free_space returned false for " . ZM_DIR_EVENTS ); + } + $space = round(($total - $free) / $total * 100); return( $space ); } -function getDiskBlocks() -{ +function getDiskBlocks() { $df = shell_exec( 'df '.ZM_DIR_EVENTS ); $space = -1; if ( preg_match( '/\s(\d+)\s+\d+\s+\d+%/ms', $df, $matches ) ) @@ -1692,32 +1467,26 @@ function getDiskBlocks() // Function to fix a problem whereby the built in PHP session handling // features want to put the sid as a hidden field after the form or // fieldset tag, neither of which will work with strict XHTML Basic. -function sidField() -{ - if ( SID ) - { +function sidField() { + if ( SID ) { list( $sessname, $sessid ) = explode( "=", SID ); - ?> - - + +"; return( false ); } @@ -1773,93 +1535,63 @@ function linesIntersect( $line1, $line2 ) $dx2 = $line2[1]['x'] - $line2[0]['x']; $dy2 = $line2[1]['y'] - $line2[0]['y']; - if ( $dx1 ) - { + if ( $dx1 ) { $m1 = $dy1/$dx1; $b1 = $line1[0]['y'] - ($m1 * $line1[0]['x']); - } - else - { + } else { $b1 = $line1[0]['y']; } - if ( $dx2 ) - { + if ( $dx2 ) { $m2 = $dy2/$dx2; $b2 = $line2[0]['y'] - ($m2 * $line2[0]['x']); - } - else - { + } else { $b2 = $line2[0]['y']; } - if ( $dx1 && $dx2 ) // Both not vertical - { - if ( $m1 != $m2 ) // Not parallel or colinear - { + if ( $dx1 && $dx2 ) { // Both not vertical + if ( $m1 != $m2 ) { // Not parallel or colinear $x = ( $b2 - $b1 ) / ( $m1 - $m2 ); - if ( $x >= $min_x1 && $x <= $max_x1 && $x >= $min_x2 && $x <= $max_x2 ) - { + if ( $x >= $min_x1 && $x <= $max_x1 && $x >= $min_x2 && $x <= $max_x2 ) { if ( $debug ) echo "Intersecting, at x $x
"; return( true ); - } - else - { + } else { if ( $debug ) echo "Not intersecting, out of range at x $x
"; return( false ); } - } - elseif ( $b1 == $b2 ) - { + } elseif ( $b1 == $b2 ) { // Colinear, must overlap due to box check, intersect? if ( $debug ) echo "Intersecting, colinear
"; return( true ); - } - else - { + } else { // Parallel if ( $debug ) echo "Not intersecting, parallel
"; return( false ); } - } - elseif ( !$dx1 ) // Line 1 is vertical - { + } elseif ( !$dx1 ) { // Line 1 is vertical $y = ( $m2 * $line1[0]['x'] ) * $b2; - if ( $y >= $min_y1 && $y <= $max_y1 ) - { + if ( $y >= $min_y1 && $y <= $max_y1 ) { if ( $debug ) echo "Intersecting, at y $y
"; return( true ); - } - else - { + } else { if ( $debug ) echo "Not intersecting, out of range at y $y
"; return( false ); } - } - elseif ( !$dx2 ) // Line 2 is vertical - { + } elseif ( !$dx2 ) { // Line 2 is vertical $y = ( $m1 * $line2[0]['x'] ) * $b1; - if ( $y >= $min_y2 && $y <= $max_y2 ) - { + if ( $y >= $min_y2 && $y <= $max_y2 ) { if ( $debug ) echo "Intersecting, at y $y
"; return( true ); - } - else - { + } else { if ( $debug ) echo "Not intersecting, out of range at y $y
"; return( false ); } - } - else // Both lines are vertical - { - if ( $line1[0]['x'] == $line2[0]['x'] ) - { + } else { // Both lines are vertical + if ( $line1[0]['x'] == $line2[0]['x'] ) { // Colinear, must overlap due to box check, intersect? if ( $debug ) echo "Intersecting, vertical, colinear
"; return( true ); - } - else - { + } else { // Parallel if ( $debug ) echo "Not intersecting, vertical, parallel
"; return( false ); @@ -1869,24 +1601,19 @@ function linesIntersect( $line1, $line2 ) return( false ); } -function isSelfIntersecting( $points ) -{ +function isSelfIntersecting( $points ) { global $debug; $n_coords = count($points); $edges = array(); - for ( $j = 0, $i = $n_coords-1; $j < $n_coords; $i = $j++ ) - { + for ( $j = 0, $i = $n_coords-1; $j < $n_coords; $i = $j++ ) { $edges[] = array( $points[$i], $points[$j] ); } - for ( $i = 0; $i <= ($n_coords-2); $i++ ) - { - for ( $j = $i+2; $j < $n_coords+min(0,$i-1); $j++ ) - { + for ( $i = 0; $i <= ($n_coords-2); $i++ ) { + for ( $j = $i+2; $j < $n_coords+min(0,$i-1); $j++ ) { if ( $debug ) echo "Checking $i and $j
"; - if ( linesIntersect( $edges[$i], $edges[$j] ) ) - { + if ( linesIntersect( $edges[$i], $edges[$j] ) ) { if ( $debug ) echo "Lines $i and $j intersect
"; return( true ); } @@ -1895,14 +1622,12 @@ function isSelfIntersecting( $points ) return( false ); } -function getPolyCentre( $points, $area=0 ) -{ +function getPolyCentre( $points, $area=0 ) { $cx = 0.0; $cy = 0.0; if ( !$area ) $area = getPolyArea( $points ); - for ( $i = 0, $j = count($points)-1; $i < count($points); $j = $i++ ) - { + for ( $i = 0, $j = count($points)-1; $i < count($points); $j = $i++ ) { $ct = ($points[$i]['x'] * $points[$j]['y']) - ($points[$j]['x'] * $points[$i]['y']); $cx += ($points[$i]['x'] + $points[$j]['x']) * ct; $cy += ($points[$i]['y'] + $points[$j]['y']) * ct; @@ -1913,27 +1638,23 @@ function getPolyCentre( $points, $area=0 ) return( array( 'x'=>$cx, 'y'=>$cy ) ); } -function _CompareXY( $a, $b ) -{ +function _CompareXY( $a, $b ) { if ( $a['min_y'] == $b['min_y'] ) return( intval($a['min_x'] - $b['min_x']) ); else return( intval($a['min_y'] - $b['min_y']) ); } -function _CompareX( $a, $b ) -{ +function _CompareX( $a, $b ) { return( intval($a['min_x'] - $b['min_x']) ); } -function getPolyArea( $points ) -{ +function getPolyArea( $points ) { global $debug; $n_coords = count($points); $global_edges = array(); - for ( $j = 0, $i = $n_coords-1; $j < $n_coords; $i = $j++ ) - { + for ( $j = 0, $i = $n_coords-1; $j < $n_coords; $i = $j++ ) { $x1 = $points[$i]['x']; $x2 = $points[$j]['x']; $y1 = $points[$i]['y']; @@ -1956,10 +1677,8 @@ function getPolyArea( $points ) usort( $global_edges, "_CompareXY" ); - if ( $debug ) - { - for ( $i = 0; $i < count($global_edges); $i++ ) - { + if ( $debug ) { + for ( $i = 0; $i < count($global_edges); $i++ ) { printf( "%d: min_y: %d, max_y:%d, min_x:%.2f, 1/m:%.2f
", $i, $global_edges[$i]['min_y'], $global_edges[$i]['max_y'], $global_edges[$i]['min_x'], $global_edges[$i]['_1_m'] ); } } @@ -1967,38 +1686,29 @@ function getPolyArea( $points ) $area = 0.0; $active_edges = array(); $y = $global_edges[0]['min_y']; - do - { - for ( $i = 0; $i < count($global_edges); $i++ ) - { - if ( $global_edges[$i]['min_y'] == $y ) - { + do { + for ( $i = 0; $i < count($global_edges); $i++ ) { + if ( $global_edges[$i]['min_y'] == $y ) { if ( $debug ) printf( "Moving global edge
" ); $active_edges[] = $global_edges[$i]; array_splice( $global_edges, $i, 1 ); $i--; - } - else - { + } else { break; } } usort( $active_edges, "_CompareX" ); - if ( $debug ) - { - for ( $i = 0; $i < count($active_edges); $i++ ) - { + if ( $debug ) { + for ( $i = 0; $i < count($active_edges); $i++ ) { printf( "%d - %d: min_y: %d, max_y:%d, min_x:%.2f, 1/m:%.2f
", $y, $i, $active_edges[$i]['min_y'], $active_edges[$i]['max_y'], $active_edges[$i]['min_x'], $active_edges[$i]['_1_m'] ); } } $last_x = 0; $row_area = 0; $parity = false; - for ( $i = 0; $i < count($active_edges); $i++ ) - { + for ( $i = 0; $i < count($active_edges); $i++ ) { $x = intval(round($active_edges[$i]['min_x'])); - if ( $parity ) - { + if ( $parity ) { $row_area += ($x - $last_x)+1; $area += $row_area; } @@ -2008,16 +1718,12 @@ function getPolyArea( $points ) } if ( $debug ) printf( "%d: Area:%d
", $y, $row_area ); $y++; - for ( $i = 0; $i < count($active_edges); $i++ ) - { - if ( $y >= $active_edges[$i]['max_y'] ) // Or >= as per sheets - { + for ( $i = 0; $i < count($active_edges); $i++ ) { + if ( $y >= $active_edges[$i]['max_y'] ) { // Or >= as per sheets if ( $debug ) printf( "Deleting active_edge
" ); array_splice( $active_edges, $i, 1 ); $i--; - } - else - { + } else { $active_edges[$i]['min_x'] += $active_edges[$i]['_1_m']; } } @@ -2026,12 +1732,10 @@ function getPolyArea( $points ) return( $area ); } -function getPolyAreaOld( $points ) -{ +function getPolyAreaOld( $points ) { $area = 0.0; $edge = 0.0; - for ( $i = 0, $j = count($points)-1; $i < count($points); $j = $i++ ) - { + for ( $i = 0, $j = count($points)-1; $i < count($points); $j = $i++ ) { $x_diff = ($points[$i]['x'] - $points[$j]['x']); $y_diff = ($points[$i]['y'] - $points[$j]['y']); $y_sum = ($points[$i]['y'] + $points[$j]['y']); @@ -2048,76 +1752,57 @@ function getPolyAreaOld( $points ) return( $area ); } -function mapCoords( $a ) -{ +function mapCoords( $a ) { return( $a['x'].",".$a['y'] ); } -function pointsToCoords( $points ) -{ +function pointsToCoords( $points ) { return( join( " ", array_map( "mapCoords", $points ) ) ); } -function coordsToPoints( $coords ) -{ +function coordsToPoints( $coords ) { $points = array(); - if ( preg_match_all( '/(\d+,\d+)+/', $coords, $matches ) ) - { - for ( $i = 0; $i < count($matches[1]); $i++ ) - { - if ( preg_match( '/(\d+),(\d+)/', $matches[1][$i], $cmatches ) ) - { + if ( preg_match_all( '/(\d+,\d+)+/', $coords, $matches ) ) { + for ( $i = 0; $i < count($matches[1]); $i++ ) { + if ( preg_match( '/(\d+),(\d+)/', $matches[1][$i], $cmatches ) ) { $points[] = array( 'x'=>$cmatches[1], 'y'=>$cmatches[2] ); - } - else - { + } else { echo( "Bogus coordinates '".$matches[$i]."'" ); return( false ); } } - } - else - { + } else { echo( "Bogus coordinate string '$coords'" ); return( false ); } return( $points ); } -function getLanguages() -{ +function getLanguages() { $langs = array(); - foreach ( glob("lang/*_*.php") as $file ) - { + foreach ( glob("lang/*_*.php") as $file ) { preg_match( '/([^\/]+_.+)\.php/', $file, $matches ); $langs[$matches[1]] = $matches[1]; } return( $langs ); } -function trimString( $string, $length ) -{ +function trimString( $string, $length ) { return( preg_replace( '/^(.{'.$length.',}?)\b.*$/', '\\1…', $string ) ); } -function monitorIdsToNames( $ids ) -{ +function monitorIdsToNames( $ids ) { global $mITN_monitors; - if ( !$mITN_monitors ) - { + if ( !$mITN_monitors ) { $sql = "select Id, Name from Monitors"; - foreach( dbFetchAll( $sql ) as $monitor ) - { + foreach( dbFetchAll( $sql ) as $monitor ) { $mITN_monitors[$monitor['Id']] = $monitor; } } $names = array(); - foreach ( preg_split( '/\s*,\s*/', $ids ) as $id ) - { - if ( visibleMonitor( $id ) ) - { - if ( isset($mITN_monitors[$id]) ) - { + foreach ( preg_split( '/\s*,\s*/', $ids ) as $id ) { + if ( visibleMonitor( $id ) ) { + if ( isset($mITN_monitors[$id]) ) { $names[] = $mITN_monitors[$id]['Name']; } } @@ -2126,53 +1811,42 @@ function monitorIdsToNames( $ids ) return( $name_string ); } -function initX10Status() -{ +function initX10Status() { global $x10_status; - if ( !isset($x10_status) ) - { + if ( !isset($x10_status) ) { $socket = socket_create( AF_UNIX, SOCK_STREAM, 0 ); - if ( $socket < 0 ) - { + if ( $socket < 0 ) { Fatal( "socket_create() failed: ".socket_strerror($socket) ); } $sock_file = ZM_PATH_SOCKS.'/zmx10.sock'; - if ( @socket_connect( $socket, $sock_file ) ) - { + if ( @socket_connect( $socket, $sock_file ) ) { $command = "status"; - if ( !socket_write( $socket, $command ) ) - { + if ( !socket_write( $socket, $command ) ) { Fatal( "Can't write to control socket: ".socket_strerror(socket_last_error($socket)) ); } socket_shutdown( $socket, 1 ); $x10Output = ""; - while ( $x10Response = socket_read( $socket, 256 ) ) - { + while ( $x10Response = socket_read( $socket, 256 ) ) { $x10Output .= $x10Response; } socket_close( $socket ); - } - else - { + } else { // Can't connect so use script $command = ZM_PATH_BIN."/zmx10.pl --command status"; //$command .= " 2>/dev/null >&- <&- >/dev/null"; $x10Output = exec( escapeshellcmd( $command ) ); } - foreach ( explode( "\n", $x10Output ) as $x10Response ) - { - if ( preg_match( "/^(\d+)\s+(.+)$/", $x10Response, $matches ) ) - { + foreach ( explode( "\n", $x10Output ) as $x10Response ) { + if ( preg_match( "/^(\d+)\s+(.+)$/", $x10Response, $matches ) ) { $x10_status[$matches[1]] = $matches[2]; } } } } -function getDeviceStatusX10( $key ) -{ +function getDeviceStatusX10( $key ) { global $x10_status; initX10Status(); @@ -2182,27 +1856,21 @@ function getDeviceStatusX10( $key ) return( $status ); } -function setDeviceStatusX10( $key, $status ) -{ +function setDeviceStatusX10( $key, $status ) { $socket = socket_create( AF_UNIX, SOCK_STREAM, 0 ); - if ( $socket < 0 ) - { + if ( $socket < 0 ) { Fatal( "socket_create() failed: ".socket_strerror($socket) ); } $sock_file = ZM_PATH_SOCKS.'/zmx10.sock'; - if ( @socket_connect( $socket, $sock_file ) ) - { + if ( @socket_connect( $socket, $sock_file ) ) { $command = "$status;$key"; - if ( !socket_write( $socket, $command ) ) - { + if ( !socket_write( $socket, $command ) ) { Fatal( "Can't write to control socket: ".socket_strerror(socket_last_error($socket)) ); } socket_shutdown( $socket, 1 ); $x10Response = socket_read( $socket, 256 ); socket_close( $socket ); - } - else - { + } else { // Can't connect so use script $command = ZM_PATH_BIN.'/zmx10.pl --command '.escapeshellarg( $status ); $command .= ' --unit-code '.escapeshellarg( $key ); @@ -2216,8 +1884,7 @@ function setDeviceStatusX10( $key, $status ) return( $status ); } -function logState() -{ +function logState() { $state = 'ok'; $levelCounts = array( @@ -2229,33 +1896,26 @@ function logState() $sql = "select Level, count(Level) as LevelCount from Logs where Level < ".Logger::INFO." and TimeKey > unix_timestamp(now() - interval ".ZM_LOG_CHECK_PERIOD." second) group by Level order by Level asc"; $counts = dbFetchAll( $sql ); - foreach ( $counts as $count ) - { + foreach ( $counts as $count ) { if ( $count['Level'] <= Logger::PANIC ) $count['Level'] = Logger::FATAL; - if ( !($levelCount = $levelCounts[$count['Level']]) ) - { + if ( !($levelCount = $levelCounts[$count['Level']]) ) { Error( "Unexpected Log level ".$count['Level'] ); next; } - if ( $levelCount[1] && $count['LevelCount'] >= $levelCount[1] ) - { + if ( $levelCount[1] && $count['LevelCount'] >= $levelCount[1] ) { $state = 'alarm'; break; - } - elseif ( $levelCount[0] && $count['LevelCount'] >= $levelCount[0] ) - { + } elseif ( $levelCount[0] && $count['LevelCount'] >= $levelCount[0] ) { $state = 'alert'; } } return( $state ); } -function isVector ( &$array ) -{ +function isVector ( &$array ) { $next_key = 0; - foreach ( array_keys($array) as $key ) - { + foreach ( array_keys($array) as $key ) { if ( !is_int( $key ) ) return( false ); if ( $key != $next_key++ ) @@ -2264,13 +1924,10 @@ function isVector ( &$array ) return( true ); } -function checkJsonError($value) -{ - if ( function_exists('json_last_error') ) - { +function checkJsonError($value) { + if ( function_exists('json_last_error') ) { $value = var_export($value,true); - switch( json_last_error() ) - { + switch( json_last_error() ) { case JSON_ERROR_DEPTH : Fatal( "Unable to decode JSON string '$value', maximum stack depth exceeded" ); case JSON_ERROR_CTRL_CHAR : @@ -2287,17 +1944,14 @@ function checkJsonError($value) } } -function jsonEncode( &$value ) -{ - if ( function_exists('json_encode') ) - { +function jsonEncode( &$value ) { + if ( function_exists('json_encode') ) { $string = json_encode( $value ); checkJsonError($value); return( $string ); } - switch ( gettype($value) ) - { + switch ( gettype($value) ) { case 'double': case 'integer': return( $value ); @@ -2312,11 +1966,9 @@ function jsonEncode( &$value ) case 'array': if ( isVector( $value ) ) return( '['.join( ',', array_map( 'jsonEncode', $value) ).']' ); - else - { + else { $result = '{'; - foreach ($value as $subkey => $subvalue ) - { + foreach ($value as $subkey => $subvalue ) { if ( $result != '{' ) $result .= ','; $result .= '"'.$subkey.'":'.jsonEncode( $subvalue ); @@ -2328,10 +1980,8 @@ function jsonEncode( &$value ) } } -function jsonDecode( $value ) -{ - if ( function_exists('json_decode') ) - { +function jsonDecode( $value ) { + if ( function_exists('json_decode') ) { $object = json_decode( $value, true ); checkJsonError($value); return( $object ); @@ -2340,35 +1990,31 @@ function jsonDecode( $value ) $comment = false; $unescape = false; $out = '$result='; - for ( $i = 0; $i < strlen($value); $i++ ) - { - if ( !$comment ) - { - if ( ($value[$i] == '{') || ($value[$i] == '[') ) + for ( $i = 0; $i < strlen($value); $i++ ) { + if ( !$comment ) { + if ( ($value[$i] == '{') || ($value[$i] == '[') ) { $out .= ' array('; - else if ( ($value[$i] == '}') || ($value[$i] == ']') ) - $out .= ')'; - else if ( $value[$i] == ':' ) - $out .= '=>'; - else - $out .= $value[$i]; - } - else if ( !$unescape ) - { - if ( $value[$i] == '\\' ) - $unescape = true; - else - $out .= $value[$i]; - } - else - { - if ( $value[$i] != '/' ) - $out .= '\\'; - $out .= $value[$i]; - $unescape = false; - } - if ( $value[$i] == '"' ) - $comment = !$comment; + } else if ( ($value[$i] == '}') || ($value[$i] == ']') ) { + $out .= ')'; + } else if ( $value[$i] == ':' ) { + $out .= '=>'; + } else { + $out .= $value[$i]; + } + } else if ( !$unescape ) { + if ( $value[$i] == '\\' ) + $unescape = true; + else + $out .= $value[$i]; + } else { + if ( $value[$i] != '/' ) + $out .= '\\'; + $out .= $value[$i]; + $unescape = false; + } + if ( $value[$i] == '"' ) { + $comment = !$comment; + } } eval( $out.';' ); return( $result ); @@ -2378,13 +2024,11 @@ define( 'HTTP_STATUS_OK', 200 ); define( 'HTTP_STATUS_BAD_REQUEST', 400 ); define( 'HTTP_STATUS_FORBIDDEN', 403 ); -function ajaxError( $message, $code=HTTP_STATUS_OK ) -{ +function ajaxError( $message, $code=HTTP_STATUS_OK ) { Error( $message ); if ( function_exists( 'ajaxCleanup' ) ) ajaxCleanup(); - if ( $code == HTTP_STATUS_OK ) - { + if ( $code == HTTP_STATUS_OK ) { $response = array( 'result'=>'Error', 'message'=>$message ); header( "Content-type: text/plain" ); exit( jsonEncode( $response ) ); @@ -2393,8 +2037,7 @@ function ajaxError( $message, $code=HTTP_STATUS_OK ) exit(); } -function ajaxResponse( $result=false ) -{ +function ajaxResponse( $result=false ) { if ( function_exists( 'ajaxCleanup' ) ) ajaxCleanup(); $response = array( 'result'=>'Ok' ); @@ -2406,25 +2049,21 @@ function ajaxResponse( $result=false ) exit( jsonEncode( $response ) ); } -function generateConnKey() -{ +function generateConnKey() { return( rand( 1, 999999 ) ); } -function detaintPath( $path ) -{ +function detaintPath( $path ) { // Remove any absolute paths, or relative ones that want to go up $path = preg_replace( '/\.(?:\.+[\\/][\\/]*)+/', '', $path ); $path = preg_replace( '/^[\\/]+/', '', $path ); return( $path ); } -function getSkinFile( $file ) -{ +function getSkinFile( $file ) { global $skinBase; $skinFile = false; - foreach ( $skinBase as $skin ) - { + foreach ( $skinBase as $skin ) { $tempSkinFile = detaintPath( 'skins'.'/'.$skin.'/'.$file ); if ( file_exists( $tempSkinFile ) ) $skinFile = $tempSkinFile; @@ -2436,22 +2075,18 @@ function getSkinIncludes( $file, $includeBase=false, $asOverride=false ) { global $skinBase; $skinFile = false; - foreach ( $skinBase as $skin ) - { + foreach ( $skinBase as $skin ) { $tempSkinFile = detaintPath( 'skins'.'/'.$skin.'/'.$file ); if ( file_exists( $tempSkinFile ) ) $skinFile = $tempSkinFile; } $includeFiles = array(); - if ( $asOverride ) - { + if ( $asOverride ) { if ( $skinFile ) $includeFiles[] = $skinFile; else if ( $includeBase ) $includeFiles[] = $file; - } - else - { + } else { if ( $includeBase ) $includeFiles[] = $file; if ( $skinFile ) @@ -2460,56 +2095,50 @@ function getSkinIncludes( $file, $includeBase=false, $asOverride=false ) return( $includeFiles ); } -function requestVar( $name, $default="" ) -{ +function requestVar( $name, $default="" ) { return( isset($_REQUEST[$name])?validHtmlStr($_REQUEST[$name]):$default ); } // For numbers etc in javascript or tags etc -function validInt( $input ) -{ +function validInt( $input ) { return( preg_replace( '/\D/', '', $input ) ); } -function validNum( $input ) -{ +function validNum( $input ) { return( preg_replace( '/[^\d.-]/', '', $input ) ); } // For general strings -function validStr( $input ) -{ +function validStr( $input ) { return( strip_tags( $input ) ); } // For strings in javascript or tags etc, expected to be in quotes so further quotes escaped rather than converted -function validJsStr( $input ) -{ +function validJsStr( $input ) { return( strip_tags( addslashes( $input ) ) ); } // For general text in pages outside of tags or quotes so quotes converted to entities -function validHtmlStr( $input ) -{ +function validHtmlStr( $input ) { return( htmlspecialchars( $input, ENT_QUOTES ) ); } function getStreamHTML( $monitor, $scale=100 ) { -//FIXME, the width and height of the image need to be scaled. - if ( ZM_WEB_STREAM_METHOD == 'mpeg' && ZM_MPEG_LIVE_FORMAT ) { - $streamSrc = $monitor->getStreamSrc( array( "mode=mpeg", "scale=".$scale, "bitrate=".ZM_WEB_VIDEO_BITRATE, "maxfps=".ZM_WEB_VIDEO_MAXFPS, "format=".ZM_MPEG_LIVE_FORMAT ) ); - return getVideoStream( "liveStream", $streamSrc, reScale( $monitor->Width(), $scale ), reScale( $monitor->Height(), $scale ), ZM_MPEG_LIVE_FORMAT, $monitor->Name() ); - } else if ( canStream() ) { - $streamSrc = $monitor->getStreamSrc( array( 'mode=jpeg', 'scale='.$scale, 'maxfps='.ZM_WEB_VIDEO_MAXFPS, 'buffer='.$monitor->StreamReplayBuffer() ) ); - if ( canStreamNative() ) - return getImageStream( "liveStream", $streamSrc, reScale( $monitor->Width(), $scale ), reScale( $monitor->Height(), $scale ), $monitor->Name() ); - elseif ( canStreamApplet() ) - outputHelperStream( "liveStream", $streamSrc, reScale( $monitor->Width(), $scale ), reScale( $monitor->Height(), $scale ), $monitor->Name() ); - } else { - $streamSrc = $monitor->getStreamSrc( array( 'mode=single', "scale=".$scale ) ); - outputImageStill( "liveStream", $streamSrc, reScale( $monitor->Width(), $scale ), reScale( $monitor->Height(), $scale ), $monitor->Name() ); - Info( "The system has fallen back to single jpeg mode for streaming. Consider enabling Cambozola or upgrading the client browser."); - } + //FIXME, the width and height of the image need to be scaled. + if ( ZM_WEB_STREAM_METHOD == 'mpeg' && ZM_MPEG_LIVE_FORMAT ) { + $streamSrc = $monitor->getStreamSrc( array( "mode=mpeg", "scale=".$scale, "bitrate=".ZM_WEB_VIDEO_BITRATE, "maxfps=".ZM_WEB_VIDEO_MAXFPS, "format=".ZM_MPEG_LIVE_FORMAT ) ); + return getVideoStream( "liveStream", $streamSrc, reScale( $monitor->Width(), $scale ), reScale( $monitor->Height(), $scale ), ZM_MPEG_LIVE_FORMAT, $monitor->Name() ); + } else if ( canStream() ) { + $streamSrc = $monitor->getStreamSrc( array( 'mode=jpeg', 'scale='.$scale, 'maxfps='.ZM_WEB_VIDEO_MAXFPS, 'buffer='.$monitor->StreamReplayBuffer() ) ); + if ( canStreamNative() ) + return getImageStream( "liveStream", $streamSrc, reScale( $monitor->Width(), $scale ), reScale( $monitor->Height(), $scale ), $monitor->Name() ); + elseif ( canStreamApplet() ) + outputHelperStream( "liveStream", $streamSrc, reScale( $monitor->Width(), $scale ), reScale( $monitor->Height(), $scale ), $monitor->Name() ); + } else { + $streamSrc = $monitor->getStreamSrc( array( 'mode=single', "scale=".$scale ) ); + outputImageStill( "liveStream", $streamSrc, reScale( $monitor->Width(), $scale ), reScale( $monitor->Height(), $scale ), $monitor->Name() ); + Info( "The system has fallen back to single jpeg mode for streaming. Consider enabling Cambozola or upgrading the client browser."); + } } // end function getStreamHTML ?>