From 426aeea95b5d3b4ab3932bcc81a5efadf84cd8fe Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 7 Sep 2018 16:29:23 -0400 Subject: [PATCH 1/7] add db reconnects to zmwatch. --- scripts/zmwatch.pl.in | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/scripts/zmwatch.pl.in b/scripts/zmwatch.pl.in index b98b9d22a..e48b8d9d3 100644 --- a/scripts/zmwatch.pl.in +++ b/scripts/zmwatch.pl.in @@ -78,6 +78,11 @@ my $sth = $dbh->prepare_cached($sql) or Fatal("Can't prepare '$sql': ".$dbh->errstr()); while( 1 ) { + while ( ! ( $dbh and $dbh->ping() ) ) { + if ( ! ( $dbh = zmDbConnect() ) ) { + sleep($Config{ZM_WATCH_CHECK_INTERVAL}); + } + } my $res = $sth->execute( $Config{ZM_SERVER_ID} ? $Config{ZM_SERVER_ID} : () ) or Fatal('Can\'t execute: '.$sth->errstr()); @@ -98,7 +103,7 @@ while( 1 ) { Debug("Monitor $$monitor{Id} LastWriteTime is $capture_time."); if ( !$capture_time ) { my $startup_time = zmGetStartupTime($monitor); - if ( $now - $startup_time > $Config{ZM_WATCH_MAX_DELAY} ) { + if ( ( $now - $startup_time ) > $Config{ZM_WATCH_MAX_DELAY} ) { Info( "Restarting capture daemon for $$monitor{Name}, no image since startup. ". "Startup time was $startup_time - now $now > $Config{ZM_WATCH_MAX_DELAY}" @@ -111,11 +116,12 @@ while( 1 ) { } } if ( ! $restart ) { - my $max_image_delay = ( $monitor->{MaxFPS} - &&($monitor->{MaxFPS}>0) - &&($monitor->{MaxFPS}<1) - ) ? (3/$monitor->{MaxFPS}) - : $Config{ZM_WATCH_MAX_DELAY} + my $max_image_delay = ( + $monitor->{MaxFPS} + &&($monitor->{MaxFPS}>0) + &&($monitor->{MaxFPS}<1) + ) ? (3/$monitor->{MaxFPS}) + : $Config{ZM_WATCH_MAX_DELAY} ; my $image_delay = $now-$capture_time; Debug("Monitor $monitor->{Id} last captured $image_delay seconds ago, max is $max_image_delay"); From def72b8e66b98704507afedbd4848a71e2edfba1 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 7 Sep 2018 16:29:59 -0400 Subject: [PATCH 2/7] tidy up license --- scripts/ZoneMinder/lib/ZoneMinder/Base.pm.in | 39 ++++++-------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Base.pm.in b/scripts/ZoneMinder/lib/ZoneMinder/Base.pm.in index d80add206..2607aadf4 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Base.pm.in +++ b/scripts/ZoneMinder/lib/ZoneMinder/Base.pm.in @@ -1,27 +1,3 @@ -# ========================================================================== -# -# ZoneMinder Base Module, $Date$, $Revision$ -# Copyright (C) 2001-2008 Philip Coombes -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# -# ========================================================================== -# -# This module contains the common definitions and functions used by the rest -# of the ZoneMinder scripts -# package ZoneMinder::Base; use 5.006; @@ -82,11 +58,18 @@ Philip Coombes, Ephilip.coombes@zoneminder.comE =head1 COPYRIGHT AND LICENSE -Copyright (C) 2001-2008 Philip Coombes +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself, either Perl version 5.8.3 or, -at your option, any later version of Perl 5 you may have available. +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. =cut From b7aa11f10924e63312385e09d37c76ed75a111f8 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 7 Sep 2018 16:30:24 -0400 Subject: [PATCH 3/7] Fix infinite loop reconnecting to db in Logging --- scripts/ZoneMinder/lib/ZoneMinder/Logger.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm b/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm index bac118a13..48e39e70e 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm @@ -440,7 +440,7 @@ sub databaseLevel { if ( defined($databaseLevel) ) { $databaseLevel = $this->limit($databaseLevel); if ( $this->{databaseLevel} != $databaseLevel ) { - if ( $databaseLevel > NOLOG and $this->{databaseLevel} <= NOLOG ) { + if ( ( $databaseLevel > NOLOG ) and ( $this->{databaseLevel} <= NOLOG ) ) { if ( !$this->{dbh} ) { $this->{dbh} = ZoneMinder::Database::zmDbConnect(); } @@ -560,11 +560,14 @@ sub logPrint { if ( $level <= $this->{databaseLevel} ) { if ( ! ( $this->{dbh} and $this->{dbh}->ping() ) ) { $this->{sth} = undef; + # Turn this off because zDbConnect will do logging calls. + my $oldlevel = $this->{databaseLevel}; + $this->{databaseLevel} = NOLOG; if ( ! ( $this->{dbh} = ZoneMinder::Database::zmDbConnect() ) ) { #print(STDERR "Can't log to database: "); - $this->{databaseLevel} = NOLOG; return; } + $this->{databaseLevel} = $oldlevel; } my $sql = 'INSERT INTO Logs ( TimeKey, Component, Pid, Level, Code, Message, File, Line ) VALUES ( ?, ?, ?, ?, ?, ?, ?, NULL )'; From fa690826a33a9c9f0599eee8f1e976d72af66082 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 7 Sep 2018 16:30:47 -0400 Subject: [PATCH 4/7] clean up zmstats, add db reconnect --- scripts/zmstats.pl.in | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/scripts/zmstats.pl.in b/scripts/zmstats.pl.in index 888a18351..25bccfebc 100644 --- a/scripts/zmstats.pl.in +++ b/scripts/zmstats.pl.in @@ -53,7 +53,6 @@ use constant START_DELAY => 30; # To give everything else time to start @EXTRA_PERL_LIB@ use ZoneMinder; -use ZoneMinder::Storage; use POSIX; use DBI; use autouse 'Data::Dumper'=>qw(Dumper); @@ -72,15 +71,13 @@ sleep( START_DELAY ); my $dbh = zmDbConnect(); -my $sql = $Config{ZM_SERVER_ID} ? 'SELECT * FROM Monitors WHERE ServerId=?' : 'SELECT * FROM Monitors'; -my $sth = $dbh->prepare_cached( $sql ) - or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - - while( 1 ) { while ( ! ( $dbh and $dbh->ping() ) ) { Info("Reconnecting to db"); - $dbh = zmDbConnect(); + if ( ! ( $dbh = zmDbConnect() ) ) { + #What we do here is not that important, so just skip this interval + sleep($Config{ZM_STATS_UPDATE_INTERVAL}); + } } $dbh->do('DELETE FROM Events_Hour WHERE StartTime < DATE_SUB(NOW(), INTERVAL 1 hour)') or Error($dbh->errstr()); @@ -88,7 +85,7 @@ while( 1 ) { $dbh->do('DELETE FROM Events_Week WHERE StartTime < DATE_SUB(NOW(), INTERVAL 1 week)') or Error($dbh->errstr()); $dbh->do('DELETE FROM Events_Month WHERE StartTime < DATE_SUB(NOW(), INTERVAL 1 month)') or Error($dbh->errstr()); - sleep( $Config{ZM_STATS_UPDATE_INTERVAL} ); + sleep($Config{ZM_STATS_UPDATE_INTERVAL}); } # end while (1) Info( "Stats Daemon exiting\n" ); From dfdac2ed705cbceabc1c4c6a5e8616102fb4fb03 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 7 Sep 2018 16:31:11 -0400 Subject: [PATCH 5/7] make find and find_one functions consistent across Objects --- web/ajax/add_monitors.php | 4 +- web/ajax/log.php | 4 +- web/includes/Control.php | 33 ++++-- web/includes/Event.php | 21 +++- web/includes/Filter.php | 68 ++++++++++--- web/includes/Group.php | 71 ++++++++----- web/includes/Monitor.php | 43 ++++++-- web/includes/Server.php | 102 ++++++++----------- web/includes/Storage.php | 64 +++++++----- web/skins/classic/includes/functions.php | 4 +- web/skins/classic/views/_monitor_filters.php | 28 ++--- web/skins/classic/views/add_monitors.php | 14 +-- web/skins/classic/views/events.php | 78 ++++++++------ web/skins/classic/views/group.php | 27 ++--- web/skins/classic/views/groups.php | 20 ++-- web/skins/classic/views/monitors.php | 45 ++++---- web/skins/classic/views/options.php | 46 ++++----- 17 files changed, 402 insertions(+), 270 deletions(-) diff --git a/web/ajax/add_monitors.php b/web/ajax/add_monitors.php index c5664f06b..69ce0332f 100644 --- a/web/ajax/add_monitors.php +++ b/web/ajax/add_monitors.php @@ -93,7 +93,7 @@ Info("Testing connection to " . $url_bits['host'].':'.$port); foreach ( $available_streams as &$stream ) { # check for existence in db. $stream['url'] = unparse_url( $stream, array('path'=>'/','query'=>'action=stream') ); - $monitors = Monitor::find_all( array('Path'=>$stream['url']) ); + $monitors = Monitor::find( array('Path'=>$stream['url']) ); if ( count($monitors) ) { Info("Found monitors matching " . $stream['url'] ); $stream['Monitor'] = $monitors[0]; @@ -135,7 +135,7 @@ if ( canEdit( 'Monitors' ) ) { if ( 0 ) { // Shortcut test - $monitors = Monitor::find_all( array( 'Path'=>$_REQUEST['url'] ) ); + $monitors = Monitor::find( array('Path'=>$_REQUEST['url']) ); if ( count( $monitors ) ) { Info("Monitor found for " . $_REQUEST['url']); $url_bits['url'] = $_REQUEST['url']; diff --git a/web/ajax/log.php b/web/ajax/log.php index 375b53a05..59595d216 100644 --- a/web/ajax/log.php +++ b/web/ajax/log.php @@ -33,7 +33,7 @@ switch ( $_REQUEST['task'] ) { if ( !canView('System') ) ajaxError('Insufficient permissions to view log entries'); - $servers = Server::find_all(); + $servers = Server::find(); $servers_by_Id = array(); # There is probably a better way to do this. foreach ( $servers as $server ) { @@ -153,7 +153,7 @@ switch ( $_REQUEST['task'] ) { } $sortOrder = (isset($_POST['sortOrder']) and $_POST['sortOrder']) == 'asc' ? 'asc':'desc'; - $servers = Server::find_all(); + $servers = Server::find(); $servers_by_Id = array(); # There is probably a better way to do this. foreach ( $servers as $server ) { diff --git a/web/includes/Control.php b/web/includes/Control.php index 74beeca05..fcb35ac63 100644 --- a/web/includes/Control.php +++ b/web/includes/Control.php @@ -166,8 +166,7 @@ private $defaults = array( } } } - public static function find_all( $parameters = null, $options = null ) { - $filters = array(); + public static function find( $parameters = null, $options = null ) { $sql = 'SELECT * FROM Controls '; $values = array(); @@ -189,15 +188,37 @@ private $defaults = array( } $sql .= implode(' AND ', $fields ); } - if ( $options and isset($options['order']) ) { - $sql .= ' ORDER BY ' . $options['order']; + if ( $options ) { + if ( isset($options['order']) ) { + $sql .= ' ORDER BY ' . $options['order']; + } + if ( isset($options['limit']) ) { + if ( is_integer($options['limit']) or ctype_digit($options['limit']) ) { + $sql .= ' LIMIT ' . $limit; + } else { + $backTrace = debug_backtrace(); + $file = $backTrace[1]['file']; + $line = $backTrace[1]['line']; + Error("Invalid value for limit($limit) passed to Control::find from $file:$line"); + return; + } + } } + $controls = array(); $result = dbQuery($sql, $values); $results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Control'); foreach ( $results as $row => $obj ) { - $filters[] = $obj; + $controls[] = $obj; } - return $filters; + return $controls; + } + + public static function find_one( $parameters = array() ) { + $results = Control::find( $parameters, array('limit'=>1) ); + if ( ! sizeof($results) ) { + return; + } + return $results[0]; } public function save( $new_values = null ) { diff --git a/web/includes/Event.php b/web/includes/Event.php index d7ce25dc4..2bb05bf5d 100644 --- a/web/includes/Event.php +++ b/web/includes/Event.php @@ -486,7 +486,7 @@ class Event { isset($event_cache[$parameters['Id']]) ) { return $event_cache[$parameters['Id']]; } - $results = Event::find_all( $parameters, $options ); + $results = Event::find( $parameters, $options ); if ( count($results) > 1 ) { Error("Event Returned more than 1"); return $results[0]; @@ -497,7 +497,7 @@ class Event { } } - public static function find_all( $parameters = null, $options = null ) { + public static function find( $parameters = null, $options = null ) { $filters = array(); $sql = 'SELECT * FROM Events '; $values = array(); @@ -520,8 +520,21 @@ class Event { } $sql .= implode(' AND ', $fields ); } - if ( $options and isset($options['order']) ) { - $sql .= ' ORDER BY ' . $options['order']; + if ( $options ) { + if ( isset($options['order']) ) { + $sql .= ' ORDER BY ' . $options['order']; + } + if ( isset($options['limit']) ) { + if ( is_integer($options['limit']) or ctype_digit($options['limit']) ) { + $sql .= ' LIMIT ' . $limit; + } else { + $backTrace = debug_backtrace(); + $file = $backTrace[1]['file']; + $line = $backTrace[1]['line']; + Error("Invalid value for limit($limit) passed to Event::find from $file:$line"); + return; + } + } } $result = dbQuery($sql, $values); $results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Event'); diff --git a/web/includes/Filter.php b/web/includes/Filter.php index 721302edb..f65399320 100644 --- a/web/includes/Filter.php +++ b/web/includes/Filter.php @@ -26,12 +26,12 @@ public $defaults = array( public function __construct( $IdOrRow=NULL ) { $row = NULL; if ( $IdOrRow ) { - if ( is_integer( $IdOrRow ) or is_numeric( $IdOrRow ) ) { - $row = dbFetchOne( 'SELECT * FROM Filters WHERE Id=?', NULL, array( $IdOrRow ) ); + if ( is_integer($IdOrRow) or is_numeric($IdOrRow) ) { + $row = dbFetchOne('SELECT * FROM Filters WHERE Id=?', NULL, array($IdOrRow)); if ( ! $row ) { - Error('Unable to load Filter record for Id=' . $IdOrRow ); + Error('Unable to load Filter record for Id=' . $IdOrRow); } - } elseif ( is_array( $IdOrRow ) ) { + } elseif ( is_array($IdOrRow) ) { $row = $IdOrRow; } else { $backTrace = debug_backtrace(); @@ -47,8 +47,8 @@ public $defaults = array( foreach ($row as $k => $v) { $this->{$k} = $v; } - if ( array_key_exists( 'Query', $this ) and $this->{'Query'} ) { - $this->{'Query'} = jsonDecode( $this->{'Query'} ); + if ( array_key_exists('Query', $this) and $this->{'Query'} ) { + $this->{'Query'} = jsonDecode($this->{'Query'}); } else { $this->{'Query'} = array(); } @@ -111,18 +111,62 @@ public $defaults = array( return $this->defaults{'limit'}; } - public static function find_all() { + public static function find( $parameters = null, $options = null ) { $filters = array(); - $result = dbQuery( 'SELECT * FROM Filters ORDER BY Name'); - $results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Filter' ); + $sql = 'SELECT * FROM Filters '; + $values = array(); + + if ( $parameters ) { + $fields = array(); + $sql .= 'WHERE '; + foreach ( $parameters as $field => $value ) { + if ( $value == null ) { + $fields[] = $field.' IS NULL'; + } else if ( is_array( $value ) ) { + $func = function(){return '?';}; + $fields[] = $field.' IN ('.implode(',', array_map($func, $value)). ')'; + $values += $value; + } else { + $fields[] = $field.'=?'; + $values[] = $value; + } + } + $sql .= implode(' AND ', $fields); + } + if ( $options ) { + if ( isset($options['order']) ) { + $sql .= ' ORDER BY ' . $options['order']; + } + if ( isset($options['limit']) ) { + if ( is_integer($options['limit']) or ctype_digit($options['limit']) ) { + $sql .= ' LIMIT ' . $limit; + } else { + $backTrace = debug_backtrace(); + $file = $backTrace[1]['file']; + $line = $backTrace[1]['line']; + Error("Invalid value for limit($limit) passed to Filter::find from $file:$line"); + return; + } + } + } + $result = dbQuery($sql, $values); + $results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Filter'); foreach ( $results as $row => $obj ) { $filters[] = $obj; } return $filters; - } + } # end find() + + public static function find_one( $parameters = array() ) { + $results = Filter::find($parameters, array('limit'=>1)); + if ( ! sizeof($results) ) { + return; + } + return $results[0]; + } # end find_one() public function delete() { - dbQuery( 'DELETE FROM Filters WHERE Id = ?', array($this->{'Id'}) ); + dbQuery('DELETE FROM Filters WHERE Id = ?', array($this->{'Id'})); } # end function delete() public function set( $data ) { @@ -141,8 +185,6 @@ public $defaults = array( } } } - - } # end class ?> diff --git a/web/includes/Group.php b/web/includes/Group.php index 441eff70e..4cbdaa83b 100644 --- a/web/includes/Group.php +++ b/web/includes/Group.php @@ -58,27 +58,7 @@ class Group { } } - public static function find_one($parameters = null, $options = null) { - global $group_cache; - if ( - ( count($parameters) == 1 ) and - isset($parameters['Id']) and - isset($group_cache[$parameters['Id']]) ) { - return $group_cache[$parameters['Id']]; - } - $results = Group::find_all($parameters, $options); - if ( count($results) > 1 ) { - Error("Group::find_one Returned more than 1"); - return $results[0]; - } else if ( count($results) ) { - return $results[0]; - } else { - return null; - } - } - - public static function find_all( $parameters = null ) { - $filters = array(); + public static function find( $parameters = null, $options = null ) { $sql = 'SELECT * FROM Groups '; $values = array(); @@ -90,22 +70,57 @@ class Group { $fields[] = $field.' IS NULL'; } else if ( is_array( $value ) ) { $func = function(){return '?';}; - $fields[] = $field.' IN ('.implode(',', array_map( $func, $value ) ). ')'; + $fields[] = $field.' IN ('.implode(',', array_map($func, $value)). ')'; $values += $value; } else { $fields[] = $field.'=?'; $values[] = $value; } } - $sql .= implode(' AND ', $fields ); - } - $sql .= ' ORDER BY Name'; + $sql .= implode(' AND ', $fields); + } # end if parameters + if ( $options ) { + if ( isset($options['order']) ) { + $sql .= ' ORDER BY ' . $options['order']; + } + if ( isset($options['limit']) ) { + if ( is_integer($options['limit']) or ctype_digit($options['limit']) ) { + $sql .= ' LIMIT ' . $limit; + } else { + $backTrace = debug_backtrace(); + $file = $backTrace[1]['file']; + $line = $backTrace[1]['line']; + Error("Invalid value for limit($limit) passed to Group::find from $file:$line"); + return; + } + } + } # end if options + $groups = array(); $result = dbQuery($sql, $values); $results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Group'); foreach ( $results as $row => $obj ) { - $filters[] = $obj; + $groups[] = $obj; + } + return $groups; + } # end find() + + public static function find_one($parameters = null, $options = null) { + global $group_cache; + if ( + ( count($parameters) == 1 ) and + isset($parameters['Id']) and + isset($group_cache[$parameters['Id']]) ) { + return $group_cache[$parameters['Id']]; + } + $results = Group::find($parameters, $options); + if ( count($results) > 1 ) { + Error("Group::find_one Returned more than 1"); + return $results[0]; + } else if ( count($results) ) { + return $results[0]; + } else { + return null; } - return $filters; } public function delete() { @@ -182,7 +197,7 @@ class Group { public static function get_dropdown_options() { $Groups = array(); - foreach ( Group::find_all( ) as $Group ) { + foreach ( Group::find( ) as $Group ) { $Groups[$Group->Id()] = $Group; } diff --git a/web/includes/Monitor.php b/web/includes/Monitor.php index efa530c0a..19aaf920b 100644 --- a/web/includes/Monitor.php +++ b/web/includes/Monitor.php @@ -278,8 +278,7 @@ private $control_fields = array( } # end if method_exists } # end foreach $data as $k=>$v } - public static function find_all( $parameters = null, $options = null ) { - $filters = array(); + public static function find( $parameters = null, $options = null ) { $sql = 'SELECT * FROM Monitors '; $values = array(); @@ -289,9 +288,9 @@ private $control_fields = array( foreach ( $parameters as $field => $value ) { if ( $value == null ) { $fields[] = $field.' IS NULL'; - } else if ( is_array( $value ) ) { + } else if ( is_array($value) ) { $func = function(){return '?';}; - $fields[] = $field.' IN ('.implode(',', array_map( $func, $value ) ). ')'; + $fields[] = $field.' IN ('.implode(',', array_map($func, $value)). ')'; $values += $value; } else { @@ -299,18 +298,40 @@ private $control_fields = array( $values[] = $value; } } - $sql .= implode(' AND ', $fields ); + $sql .= implode(' AND ', $fields); } - if ( $options and isset($options['order']) ) { - $sql .= ' ORDER BY ' . $options['order']; + if ( $options ) { + if ( isset($options['order']) ) { + $sql .= ' ORDER BY ' . $options['order']; + } + if ( isset($options['limit']) ) { + if ( is_integer($options['limit']) or ctype_digit($options['limit']) ) { + $sql .= ' LIMIT ' . $limit; + } else { + $backTrace = debug_backtrace(); + $file = $backTrace[1]['file']; + $line = $backTrace[1]['line']; + Error("Invalid value for limit($limit) passed to Control::find from $file:$line"); + return; + } + } } + $monitors = array(); $result = dbQuery($sql, $values); $results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Monitor'); foreach ( $results as $row => $obj ) { - $filters[] = $obj; + $monitors[] = $obj; } - return $filters; - } + return $monitors; + } # end find + + public static function find_one( $parameters = array() ) { + $results = Monitor::find( $parameters, array('limit'=>1) ); + if ( ! sizeof($results) ) { + return; + } + return $results[0]; + } # end find_one public function save($new_values = null) { @@ -509,5 +530,7 @@ private $control_fields = array( } return $source; } // end function Source + + } // end class Monitor ?> diff --git a/web/includes/Server.php b/web/includes/Server.php index 591563b52..f9a82c9bb 100644 --- a/web/includes/Server.php +++ b/web/includes/Server.php @@ -13,12 +13,12 @@ class Server { public function __construct( $IdOrRow = NULL ) { $row = NULL; if ( $IdOrRow ) { - if ( is_integer( $IdOrRow ) or ctype_digit( $IdOrRow ) ) { - $row = dbFetchOne( 'SELECT * FROM Servers WHERE Id=?', NULL, array( $IdOrRow ) ); - if ( ! $row ) { - Error("Unable to load Server record for Id=" . $IdOrRow ); + if ( is_integer($IdOrRow) or ctype_digit($IdOrRow) ) { + $row = dbFetchOne('SELECT * FROM Servers WHERE Id=?', NULL, array($IdOrRow)); + if ( !$row ) { + Error("Unable to load Server record for Id=" . $IdOrRow); } - } elseif ( is_array( $IdOrRow ) ) { + } elseif ( is_array($IdOrRow) ) { $row = $IdOrRow; } } # end if isset($IdOrRow) @@ -31,39 +31,6 @@ class Server { $this->{'Hostname'} = ''; } } - public static function find_all( $parameters = null, $options = null ) { - $filters = array(); - $sql = 'SELECT * FROM Servers '; - $values = array(); - - if ( $parameters ) { - $fields = array(); - $sql .= 'WHERE '; - foreach ( $parameters as $field => $value ) { - if ( $value == null ) { - $fields[] = $field.' IS NULL'; - } else if ( is_array( $value ) ) { - $func = function(){return '?';}; - $fields[] = $field.' IN ('.implode(',', array_map( $func, $value ) ). ')'; - $values += $value; - - } else { - $fields[] = $field.'=?'; - $values[] = $value; - } - } - $sql .= implode(' AND ', $fields ); - } - if ( $options and isset($options['order']) ) { - $sql .= ' ORDER BY ' . $options['order']; - } - $result = dbQuery($sql, $values); - $results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Server'); - foreach ( $results as $row => $obj ) { - $filters[] = $obj; - } - return $filters; - } public function Url() { if ( $this->Id() ) { @@ -96,26 +63,45 @@ class Server { } } } - - public static function find( $parameters = array(), $limit = NULL ) { - $sql = 'SELECT * FROM Servers'; + public static function find( $parameters = null, $options = null ) { + $filters = array(); + $sql = 'SELECT * FROM Servers '; $values = array(); - if ( sizeof($parameters) ) { - $sql .= ' WHERE ' . implode( ' AND ', array_map( - function($v){ return $v.'=?'; }, - array_keys( $parameters ) - ) ); - $values = array_values( $parameters ); + + if ( $parameters ) { + $fields = array(); + $sql .= 'WHERE '; + foreach ( $parameters as $field => $value ) { + if ( $value == null ) { + $fields[] = $field.' IS NULL'; + } else if ( is_array( $value ) ) { + $func = function(){return '?';}; + $fields[] = $field.' IN ('.implode(',', array_map( $func, $value ) ). ')'; + $values += $value; + + } else { + $fields[] = $field.'=?'; + $values[] = $value; + } + } + $sql .= implode(' AND ', $fields ); + } + if ( $options ) { + if ( isset($options['order']) ) { + $sql .= ' ORDER BY ' . $options['order']; + } + if ( isset($options['limit']) ) { + if ( is_integer($options['limit']) or ctype_digit($options['limit']) ) { + $sql .= ' LIMIT ' . $limit; + } else { + $backTrace = debug_backtrace(); + $file = $backTrace[1]['file']; + $line = $backTrace[1]['line']; + Error("Invalid value for limit($limit) passed to Server::find from $file:$line"); + return; + } + } } - if ( is_integer( $limit ) or ctype_digit( $limit ) ) { - $sql .= ' LIMIT ' . $limit; - } else { - $backTrace = debug_backtrace(); - $file = $backTrace[1]['file']; - $line = $backTrace[1]['line']; - Error("Invalid value for limit($limit) passed to Server::find from $file:$line"); - return; - } $results = dbFetchAll( $sql, NULL, $values ); if ( $results ) { return array_map( function($id){ return new Server($id); }, $results ); @@ -123,8 +109,8 @@ class Server { } public static function find_one( $parameters = array() ) { - $results = Server::find( $parameters, 1 ); - if ( ! sizeof( $results ) ) { + $results = Server::find( $parameters, array('limit'=>1) ); + if ( ! sizeof($results) ) { return; } return $results[0]; diff --git a/web/includes/Storage.php b/web/includes/Storage.php index 70f2f831d..bdd4bdf26 100644 --- a/web/includes/Storage.php +++ b/web/includes/Storage.php @@ -40,7 +40,6 @@ class Storage { $this->{'Path'} = ZM_DIR_EVENTS; } return $this->{'Path'}; - } return $this->{'Name'}; } @@ -53,19 +52,19 @@ class Storage { return $this->{'Name'}; } - public function __call( $fn, array $args= NULL){ - if ( count( $args ) ) { + public function __call( $fn, array $args= NULL ) { + if ( count($args) ) { $this->{$fn} = $args[0]; } - if ( array_key_exists( $fn, $this ) ) { + if ( array_key_exists($fn, $this) ) return $this->{$fn}; - $backTrace = debug_backtrace(); - $file = $backTrace[1]['file']; - $line = $backTrace[1]['line']; - Warning( "Unknown function call Storage->$fn from $file:$line" ); - } + $backTrace = debug_backtrace(); + $file = $backTrace[1]['file']; + $line = $backTrace[1]['line']; + Warning("Unknown function call Storage->$fn from $file:$line"); } + public static function find_one( $parameters = null, $options = null ) { global $storage_cache; if ( @@ -74,7 +73,7 @@ class Storage { isset($storage_cache[$parameters['Id']]) ) { return $storage_cache[$parameters['Id']]; } - $results = Storage::find_all( $parameters, $options ); + $results = Storage::find($parameters, $options); if ( count($results) > 1 ) { Error("Storage Returned more than 1"); return $results[0]; @@ -84,8 +83,7 @@ class Storage { return null; } } - public static function find_all( $parameters = null, $options = null ) { - $filters = array(); + public static function find( $parameters = null, $options = null ) { $sql = 'SELECT * FROM Storage '; $values = array(); @@ -95,7 +93,7 @@ class Storage { foreach ( $parameters as $field => $value ) { if ( $value == null ) { $fields[] = $field.' IS NULL'; - } else if ( is_array( $value ) ) { + } else if ( is_array($value) ) { $func = function(){return '?';}; $fields[] = $field.' IN ('.implode(',', array_map($func, $value)). ')'; $values += $value; @@ -106,32 +104,47 @@ class Storage { } } $sql .= implode(' AND ', $fields); - } - if ( $options and isset($options['order']) ) { - $sql .= ' ORDER BY ' . $options['order']; - } + } # end if parameters + if ( $options ) { + if ( isset($options['order']) ) { + $sql .= ' ORDER BY ' . $options['order']; + } # end if options + if ( isset($options['limit']) ) { + if ( is_integer($options['limit']) or ctype_digit($options['limit']) ) { + $sql .= ' LIMIT ' . $limit; + } else { + $backTrace = debug_backtrace(); + $file = $backTrace[1]['file']; + $line = $backTrace[1]['line']; + Error("Invalid value for limit($limit) passed to Control::find from $file:$line"); + return; + } + } # end if limit + } # end if options + $storage_areas = array(); $result = dbQuery($sql, $values); if ( $result ) { $results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Storage'); foreach ( $results as $row => $obj ) { - $filters[] = $obj; + $storage_areas[] = $obj; } } - return $filters; - } + return $storage_areas; + } # end find() + public function disk_usage_percent() { $path = $this->Path(); if ( ! $path ) { - Warning("Storage::disk_usage_percent: path is empty"); + Warning('Storage::disk_usage_percent: path is empty'); return 0; - } else if ( ! file_exists( $path ) ) { + } else if ( ! file_exists($path) ) { Warning("Storage::disk_usage_percent: path $path does not exist"); return 0; } $total = $this->disk_total_space(); if ( ! $total ) { - Error("disk_total_space returned false for " . $path ); + Error('disk_total_space returned false for ' . $path ); return 0; } $used = $this->disk_used_space(); @@ -139,6 +152,7 @@ class Storage { //Logger::Debug("Used $usage = round( ( $used / $total ) * 100 )"); return $usage; } + public function disk_total_space() { if ( !array_key_exists('disk_total_space', $this) ) { $path = $this->Path(); @@ -175,8 +189,8 @@ class Storage { if ( (! array_key_exists('DiskSpace', $this)) or (!$this->{'DiskSpace'}) ) { $used = dbFetchOne('SELECT SUM(DiskSpace) AS DiskSpace FROM Events WHERE StorageId=? AND DiskSpace IS NOT NULL', 'DiskSpace', array($this->Id()) ); - foreach ( Event::find_all( array('StorageId'=>$this->Id(), 'DiskSpace'=>null) ) as $Event ) { - $Event->Storage( $this ); // Prevent further db hit + foreach ( Event::find(array('StorageId'=>$this->Id(), 'DiskSpace'=>null)) as $Event ) { + $Event->Storage($this); // Prevent further db hit $used += $Event->DiskSpace(); } $this->{'DiskSpace'} = $used; diff --git a/web/skins/classic/includes/functions.php b/web/skins/classic/includes/functions.php index 66243daf3..f85d863c9 100644 --- a/web/skins/classic/includes/functions.php +++ b/web/skins/classic/includes/functions.php @@ -329,7 +329,7 @@ if ($reload == 'reload') ob_start(); ?>
  • : Path()] = $area; @@ -350,7 +350,7 @@ if ($reload == 'reload') ob_start(); return ''.$S->Name() . ': ' . $S->disk_usage_percent().'%' . ''; }; #$func = function($S){ return ''.$S->Name() . ': ' . $S->disk_usage_percent().'%' . ''; }; if ( count($storage_areas) >= 4 ) - $storage_areas = Storage::find_all( array('ServerId'=>null) ); + $storage_areas = Storage::find( array('ServerId'=>null) ); if ( count($storage_areas) < 4 ) echo implode( ', ', array_map ( $func, $storage_areas ) ); echo ' ' . ZM_PATH_MAP .': '. getDiskPercent(ZM_PATH_MAP).'%'; diff --git a/web/skins/classic/views/_monitor_filters.php b/web/skins/classic/views/_monitor_filters.php index c0c6021d2..357c6e7d1 100644 --- a/web/skins/classic/views/_monitor_filters.php +++ b/web/skins/classic/views/_monitor_filters.php @@ -18,26 +18,26 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // -$servers = Server::find_all(null, array('order'=>'lower(Name)')); +$servers = Server::find(null, array('order'=>'lower(Name)')); $ServersById = array(); foreach ( $servers as $S ) { $ServersById[$S->Id()] = $S; } session_start(); foreach ( array('Group','Function','ServerId','StorageId','Status','MonitorId','MonitorName','Source') as $var ) { - if ( isset( $_REQUEST[$var] ) ) { + if ( isset($_REQUEST[$var]) ) { if ( $_REQUEST[$var] != '' ) { $_SESSION[$var] = $_REQUEST[$var]; } else { - unset( $_SESSION[$var] ); + unset($_SESSION[$var]); } - } else if ( isset( $_REQUEST['filtering'] ) ) { - unset( $_SESSION[$var] ); + } else if ( isset($_REQUEST['filtering']) ) { + unset($_SESSION[$var]); } } session_write_close(); -$storage_areas = Storage::find_all(); +$storage_areas = Storage::find(); $StorageById = array(); foreach ( $storage_areas as $S ) { $StorageById[$S->Id()] = $S; @@ -50,7 +50,7 @@ $html = '; $GroupsById = array(); -foreach ( Group::find_all() as $G ) { +foreach ( Group::find() as $G ) { $GroupsById[$G->Id()] = $G; } @@ -78,17 +78,17 @@ if ( $groupSql ) foreach ( array('ServerId','StorageId','Status','Function') as $filter ) { if ( isset($_SESSION[$filter]) ) { if ( is_array($_SESSION[$filter]) ) { - $conditions[] = $filter . ' IN ('.implode(',', array_map(function(){return '?';}, $_SESSION[$filter] ) ). ')'; - $values = array_merge( $values, $_SESSION[$filter] ); + $conditions[] = $filter . ' IN ('.implode(',', array_map(function(){return '?';}, $_SESSION[$filter])). ')'; + $values = array_merge($values, $_SESSION[$filter]); } else { $conditions[] = $filter . '=?'; $values[] = $_SESSION[$filter]; } } } # end foreach filter -if ( ! empty( $user['MonitorIds'] ) ) { - $ids = explode(',', $user['MonitorIds'] ); - $conditions[] = 'M.Id IN ('.implode(',',array_map( function(){return '?';}, $ids) ).')'; +if ( ! empty($user['MonitorIds']) ) { + $ids = explode(',', $user['MonitorIds']); + $conditions[] = 'M.Id IN ('.implode(',',array_map(function(){return '?';}, $ids)).')'; $values += $ids; } @@ -115,7 +115,7 @@ $html .= ''; if ( count($ServersById) > 1 ) { $html .= ''; - $html .= htmlSelect( 'ServerId[]', $ServersById, + $html .= htmlSelect('ServerId[]', $ServersById, (isset($_SESSION['ServerId'])?$_SESSION['ServerId']:''), array( 'onchange'=>'this.form.submit();', @@ -129,7 +129,7 @@ if ( count($ServersById) > 1 ) { if ( count($StorageById) > 1 ) { $html .= ''; - $html .= htmlSelect( 'StorageId[]',$StorageById, + $html .= htmlSelect('StorageId[]', $StorageById, (isset($_SESSION['StorageId'])?$_SESSION['StorageId']:''), array( 'onchange'=>'this.form.submit();', diff --git a/web/skins/classic/views/add_monitors.php b/web/skins/classic/views/add_monitors.php index f73a22864..98eb87b16 100644 --- a/web/skins/classic/views/add_monitors.php +++ b/web/skins/classic/views/add_monitors.php @@ -44,11 +44,11 @@ xhtmlHeaders(__FILE__, translate('AddMonitors'));
    Enter by IP or URL -

    -Simply enter the ip address or full url to the stream. -It will be probed for available streams, or checked to see if it has already been entered. -If streams are found, they will be listed in the results column. Click Add to add them. -

    +

    + Simply enter the ip address or full url to the stream. + It will be probed for available streams, or checked to see if it has already been entered. + If streams are found, they will be listed in the results column. Click Add to add them. +

    @@ -80,7 +80,7 @@ If streams are found, they will be listed in the results column. Click Add to ad ?> Id()] = $S; @@ -92,7 +92,7 @@ If streams are found, they will be listed in the results column. Click Add to ad Id()] = $S; diff --git a/web/skins/classic/views/events.php b/web/skins/classic/views/events.php index eb5ccb14d..50409cf16 100644 --- a/web/skins/classic/views/events.php +++ b/web/skins/classic/views/events.php @@ -83,7 +83,7 @@ if ( $_POST ) { exit(); } -$storage_areas = Storage::find_all(); +$storage_areas = Storage::find(); $StorageById = array(); foreach ( $storage_areas as $S ) { $StorageById[$S->Id()] = $S; @@ -94,7 +94,7 @@ xhtmlHeaders(__FILE__, translate('Events') ); ?>
    - + diff --git a/web/skins/classic/views/group.php b/web/skins/classic/views/group.php index 5a4446544..d765e445f 100644 --- a/web/skins/classic/views/group.php +++ b/web/skins/classic/views/group.php @@ -18,18 +18,18 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // -if ( !canEdit( 'Groups' ) ) { +if ( !canEdit('Groups') ) { $view = 'error'; return; } if ( !empty($_REQUEST['gid']) ) { - $newGroup = new Group( $_REQUEST['gid'] ); + $newGroup = new Group($_REQUEST['gid']); } else { $newGroup = new Group(); } -xhtmlHeaders( __FILE__, translate('Group').' - '.$newGroup->Name() ); +xhtmlHeaders(__FILE__, translate('Group').' - '.$newGroup->Name()); ?>
    @@ -52,7 +52,7 @@ xhtmlHeaders( __FILE__, translate('Group').' - '.$newGroup->Name() ); Id()] = $Group; } @@ -76,7 +76,7 @@ function get_children($Group) { $kids = array(); if ( isset( $children[$Group->Id()] ) ) { - $kids += array_map( 'get_Id', $children[$Group->Id()] ); + $kids += array_map('get_Id', $children[$Group->Id()]); foreach ( $children[$Group->Id()] as $G ) { foreach ( get_children($G) as $id ) { $kids[] = $id; @@ -89,13 +89,12 @@ function get_children($Group) { $kids = get_children($newGroup); if ( $newGroup->Id() ) $kids[] = $newGroup->Id(); -$sql = 'SELECT Id,Name from Groups'.(count($kids)?' WHERE Id NOT IN ('.implode(',',array_map(function(){return '?';}, $kids )).')' : '').' ORDER BY Name'; +$sql = 'SELECT Id,Name from Groups'.(count($kids)?' WHERE Id NOT IN ('.implode(',',array_map(function(){return '?';}, $kids)).')' : '').' ORDER BY Name'; $options = array(''=>'None'); -foreach ( dbFetchAll( $sql, null, $kids ) as $option ) { - - $options[$option['Id']] = str_repeat('  ', $Groups[$option['Id']]->depth() ) . $option['Name']; +foreach ( dbFetchAll($sql, null, $kids) as $option ) { + $options[$option['Id']] = str_repeat('  ', $Groups[$option['Id']]->depth()) . $option['Name']; } -echo htmlSelect( 'newGroup[ParentId]', $options, $newGroup->ParentId(), array('onchange'=>'configureButtons(this);' )); +echo htmlSelect('newGroup[ParentId]', $options, $newGroup->ParentId(), array('onchange'=>'configureButtons(this);')); ?> @@ -104,10 +103,10 @@ echo htmlSelect( 'newGroup[ParentId]', $options, $newGroup->ParentId(), array('o Id() ? '' : ' disabled="disabled"'?>/> +
    diff --git a/web/skins/classic/views/groups.php b/web/skins/classic/views/groups.php index ecf85b3c1..fb383026d 100644 --- a/web/skins/classic/views/groups.php +++ b/web/skins/classic/views/groups.php @@ -28,7 +28,7 @@ $group_id = 0; $max_depth = 0; $Groups = array(); -foreach ( Group::find_all( ) as $Group ) { +foreach ( Group::find( ) as $Group ) { $Groups[$Group->Id()] = $Group; } @@ -41,7 +41,7 @@ foreach ( $Groups as $id=>$Group ) { if ( $max_depth < $Group->depth() ) $max_depth = $Group->depth(); } -xhtmlHeaders(__FILE__, translate('Groups') ); +xhtmlHeaders(__FILE__, translate('Groups')); ?>
    @@ -64,33 +64,37 @@ function group_line( $Group ) { global $children; global $max_depth; $html = ''; - $html .= str_repeat( ' ', $Group->depth() ); + $html .= str_repeat(' ', $Group->depth()); $html .= ''; if ( canEdit('Groups') ) { $html .= ''. validHtmlStr($Group->Id() . ' ' . $Group->Name()).''; } else { $html .= validHtmlStr($Group->Name()); } - $html .= ''. monitorIdsToNames( $Group->MonitorIds(), 30 ).' + $html .= ''. monitorIdsToNames($Group->MonitorIds(), 30).' '; if ( isset( $children[$Group->Id()] ) ) { foreach ( $children[$Group->Id()] as $G ) { - $html .= group_line( $G ); + $html .= group_line($G); } } return $html; } if ( isset( $children[null] ) ) foreach ( $children[null] as $Group ) - echo group_line( $Group ); + echo group_line($Group); ?>
    - /> - + +
    diff --git a/web/skins/classic/views/monitors.php b/web/skins/classic/views/monitors.php index 4c35a0f8f..ff57a4edf 100644 --- a/web/skins/classic/views/monitors.php +++ b/web/skins/classic/views/monitors.php @@ -18,25 +18,24 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // -if ( !canEdit( 'Monitors' ) ) { +if ( !canEdit('Monitors') ) { $view = 'error'; return; } -$monitors = Monitor::find_all( array('Id' => $_REQUEST['mids'] ) ); +$monitors = Monitor::find(array('Id' => $_REQUEST['mids'])); $monitor = $monitors[0]; -$servers = Server::find_all(); +$servers = Server::find(); $ServersById = array(); foreach ( $servers as $S ) { $ServersById[$S->Id()] = $S; } -$storage_areas = Storage::find_all(); +$storage_areas = Storage::find(); $StorageById = array(); foreach ( $storage_areas as $S ) { $StorageById[$S->Id()] = $S; } - $focusWindow = true; xhtmlHeaders(__FILE__, translate('Function')); @@ -48,7 +47,7 @@ xhtmlHeaders(__FILE__, translate('Function'));
    The following monitors will have these settings update when you click Save:

    - ', array_map( function($m){return $m->Id().' ' .$m->Name();}, $monitors ) ); ?> + ', array_map(function($m){return $m->Id().' ' .$m->Name();}, $monitors)); ?>
    @@ -56,31 +55,31 @@ The following monitors will have these settings update when you click Save:
    Id().'"/>'; - }, $monitors ) + }, $monitors) ); if ( count($ServersById) > 0 ) { ?> -

    -'None')+$ServersById, $monitor->ServerId() ); ?> -

    +

    + 'None')+$ServersById, $monitor->ServerId()); ?> +

    0 ) { + } + if ( count($StorageById) > 0 ) { ?> -

    -'All')+$StorageById, $monitor->StorageId() ); ?> -

    +

    + 'All')+$StorageById, $monitor->StorageId()); ?> +

    Function() ); + $options = array(); + foreach ( getEnumValues('Monitors', 'Function') as $opt ) { + $options[$opt] = translate('Fn'.$opt); + } + echo htmlSelect('newMonitor[Function]', $options, $monitor->Function()); ?>

    @@ -89,7 +88,7 @@ echo htmlSelect( 'newMonitor[Function]', $options, $monitor->Function() );

    - +
    diff --git a/web/skins/classic/views/options.php b/web/skins/classic/views/options.php index 2a17cf0b9..37d7c75c4 100644 --- a/web/skins/classic/views/options.php +++ b/web/skins/classic/views/options.php @@ -18,12 +18,12 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // -if ( !canView( 'System' ) ) { +if ( !canView('System') ) { $view = 'error'; return; } -$canEdit = canEdit( 'System' ); +$canEdit = canEdit('System'); $tabs = array(); $tabs['skins'] = translate('Display'); @@ -50,10 +50,10 @@ else $focusWindow = true; -xhtmlHeaders( __FILE__, translate('Options') ); +xhtmlHeaders(__FILE__, translate('Options')); # Have to do this stuff up here before including header.php because fof the cookie setting -$skin_options = array_map( 'basename', glob('skins/*',GLOB_ONLYDIR) ); +$skin_options = array_map('basename', glob('skins/*',GLOB_ONLYDIR)); if ( $tab == 'skins' ) { $current_skin = $_COOKIE['zmSkin']; $reload = false; @@ -75,7 +75,7 @@ if ( $tab == 'skins' ) { ?> - +
    -
    +
    '.$dir.''; } ?> @@ -136,7 +136,7 @@ foreach( array_map( 'basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDI - +
    @@ -155,17 +155,17 @@ foreach( array_map( 'basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDI "/> -
    +
    @@ -270,15 +270,15 @@ foreach( array_map( 'basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDI -'lower(Name)') ) as $Storage ) { ?> +'lower(Name)') ) as $Storage ) { ?> - - - - + + + + + echo makePopupLink('?view=storage&id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Name()), $canEdit ) ?> @@ -400,6 +400,4 @@ foreach( array_map( 'basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDI - - - + From b778fd782c264534cc33bba2cf90962331c6b504 Mon Sep 17 00:00:00 2001 From: Vitaly Saversky <33189579+larandvit@users.noreply.github.com> Date: Sun, 9 Sep 2018 09:39:30 -0400 Subject: [PATCH 6/7] Misspelling - non-recordable (#2200) --- docs/userguide/definemonitor.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/userguide/definemonitor.rst b/docs/userguide/definemonitor.rst index 8f85feb98..bf12a1bc5 100644 --- a/docs/userguide/definemonitor.rst +++ b/docs/userguide/definemonitor.rst @@ -150,7 +150,7 @@ Orientation WebSite ^^^^^^^ -This Source Type allows one to configure an arbitrary website as a non-reocrdable, fully interactive, monitor in ZoneMinder. Note that sites with self-signed certificates will not display until the end user first manually navigates to the site and accpets the unsigned certificate. Also note that some sites will set an X-Frame option in the header, which discourages their site from being displayed within a frame. ZoneMinder will detect this condition and present a warning in the log. When this occurs, the end user can choose to install a browser plugin or extension to workaround this issue. +This Source Type allows one to configure an arbitrary website as a non-recordable, fully interactive, monitor in ZoneMinder. Note that sites with self-signed certificates will not display until the end user first manually navigates to the site and accpets the unsigned certificate. Also note that some sites will set an X-Frame option in the header, which discourages their site from being displayed within a frame. ZoneMinder will detect this condition and present a warning in the log. When this occurs, the end user can choose to install a browser plugin or extension to workaround this issue. Website URL Enter the full http or https url to the desired website. From d945e2ba543b03a1af68defc05fa0bc0611eb2b8 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sun, 9 Sep 2018 11:34:12 -0400 Subject: [PATCH 7/7] Fix context allocation on ffmpeg 2.8. Fixes #41 on connorTechnology fork. --- src/zm_videostore.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/zm_videostore.cpp b/src/zm_videostore.cpp index 7d5d2de59..1c3f34cf5 100644 --- a/src/zm_videostore.cpp +++ b/src/zm_videostore.cpp @@ -336,14 +336,14 @@ bool VideoStore::open() { } else if (av_dict_count(opts) != 0) { Warning("some options not set\n"); } + if (opts) av_dict_free(&opts); if (ret < 0) { Error("Error occurred when writing out file header to %s: %s\n", filename, av_make_error_string(ret).c_str()); return false; } - if (opts) av_dict_free(&opts); return true; -} +} // end VideoStore::open() VideoStore::~VideoStore() { @@ -398,12 +398,14 @@ VideoStore::~VideoStore() { pkt.stream_index = audio_out_stream->index; av_interleaved_write_frame(oc, &pkt); zm_av_packet_unref(&pkt); - } // while have buffered frames - } // end if audio_out_codec + } // while have buffered frames + } // end if audio_out_codec // Flush Queues + Debug(1,"Flushing interleaved queues"); av_interleaved_write_frame(oc, NULL); + Debug(1,"Writing trailer"); /* Write the trailer before close */ if (int rc = av_write_trailer(oc)) { Error("Error writing trailer %s", av_err2str(rc)); @@ -411,7 +413,7 @@ VideoStore::~VideoStore() { Debug(3, "Sucess Writing trailer"); } - // WHen will be not using a file ? + // When will we not be using a file ? if ( !(out_format->flags & AVFMT_NOFILE) ) { /* Close the out file. */ Debug(2, "Closing"); @@ -507,6 +509,7 @@ bool VideoStore::setup_resampler() { } Debug(2, "Have audio out codec"); +#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) // audio_out_ctx = audio_out_stream->codec; audio_out_ctx = avcodec_alloc_context3(audio_out_codec); @@ -517,6 +520,12 @@ bool VideoStore::setup_resampler() { } Debug(2, "Have audio_out_ctx"); + // Now copy them to the out stream + audio_out_stream = avformat_new_stream(oc, NULL); +#else + audio_out_stream = avformat_new_stream(oc, NULL); + audio_out_ctx = audio_out_stream->codec; +#endif /* put sample parameters */ audio_out_ctx->bit_rate = audio_in_ctx->bit_rate; @@ -556,8 +565,6 @@ bool VideoStore::setup_resampler() { audio_out_ctx->time_base = (AVRational){1, audio_out_ctx->sample_rate}; - // Now copy them to the out stream - audio_out_stream = avformat_new_stream(oc, audio_out_codec); #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) ret = avcodec_parameters_from_context(audio_out_stream->codecpar,
    Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Id()), $canEdit ) ?>Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Name()), $canEdit ) ?>Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Path()), $canEdit ) ?>Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Type()), $canEdit ) ?>Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Scheme()), $canEdit ) ?>Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Name()), $canEdit ) ?>Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Path()), $canEdit ) ?>Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Type()), $canEdit ) ?>Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Scheme()), $canEdit ) ?> Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Name()), $canEdit ) ?> disk_used_space()) . ' of ' . human_filesize($Storage->disk_total_space()) ?> disabled="disabled"/>