From 2ab79820a19e3342202d5c315eff92c795636153 Mon Sep 17 00:00:00 2001 From: josh4trunks Date: Sun, 22 May 2016 08:08:12 -0700 Subject: [PATCH 01/16] Add back changes --- src/zm_db.cpp | 28 ++++++++++++++++++++-------- src/zm_logger.cpp | 27 +++++++++++++++++++-------- web/includes/database.php | 14 +++++++++++++- 3 files changed, 52 insertions(+), 17 deletions(-) diff --git a/src/zm_db.cpp b/src/zm_db.cpp index 8f2527fc2..430f4553b 100644 --- a/src/zm_db.cpp +++ b/src/zm_db.cpp @@ -37,12 +37,10 @@ void zmDbConnect() my_bool reconnect = 1; if ( mysql_options( &dbconn, MYSQL_OPT_RECONNECT, &reconnect ) ) Fatal( "Can't set database auto reconnect option: %s", mysql_error( &dbconn ) ); - std::string::size_type colonIndex = staticConfig.DB_HOST.find( ":/" ); - if ( colonIndex != std::string::npos ) + std::string::size_type colonIndex = staticConfig.DB_HOST.find( ":" ); + if ( colonIndex == std::string::npos ) { - std::string dbHost = staticConfig.DB_HOST.substr( 0, colonIndex ); - std::string dbPort = staticConfig.DB_HOST.substr( colonIndex+1 ); - if ( !mysql_real_connect( &dbconn, dbHost.c_str(), staticConfig.DB_USER.c_str(), staticConfig.DB_PASS.c_str(), 0, atoi(dbPort.c_str()), 0, 0 ) ) + if ( !mysql_real_connect( &dbconn, staticConfig.DB_HOST.c_str(), staticConfig.DB_USER.c_str(), staticConfig.DB_PASS.c_str(), NULL, 0, NULL, 0 ) ) { Error( "Can't connect to server: %s", mysql_error( &dbconn ) ); exit( mysql_errno( &dbconn ) ); @@ -50,10 +48,24 @@ void zmDbConnect() } else { - if ( !mysql_real_connect( &dbconn, staticConfig.DB_HOST.c_str(), staticConfig.DB_USER.c_str(), staticConfig.DB_PASS.c_str(), 0, 0, 0, 0 ) ) + std::string dbHost = staticConfig.DB_HOST.substr( 0, colonIndex ); + std::string dbPortOrSocket = staticConfig.DB_HOST.substr( colonIndex+1 ); + if ( dbPortOrSocket[0] == '/' ) { - Error( "Can't connect to server: %s", mysql_error( &dbconn ) ); - exit( mysql_errno( &dbconn ) ); + if ( !mysql_real_connect( &dbconn, NULL, staticConfig.DB_USER.c_str(), staticConfig.DB_PASS.c_str(), NULL, 0, dbPortOrSocket.c_str(), 0 ) ) + { + Error( "Can't connect to server: %s", mysql_error( &dbconn ) ); + exit( mysql_errno( &dbconn ) ); + } + + } + else + { + if ( !mysql_real_connect( &dbconn, dbHost.c_str(), staticConfig.DB_USER.c_str(), staticConfig.DB_PASS.c_str(), NULL, atoi(dbPortOrSocket.c_str()), NULL, 0 ) ) + { + Error( "Can't connect to server: %s", mysql_error( &dbconn ) ); + exit( mysql_errno( &dbconn ) ); + } } } if ( mysql_select_db( &dbconn, staticConfig.DB_NAME.c_str() ) ) diff --git a/src/zm_logger.cpp b/src/zm_logger.cpp index 4d66deee2..9e28135ba 100644 --- a/src/zm_logger.cpp +++ b/src/zm_logger.cpp @@ -367,12 +367,10 @@ Logger::Level Logger::databaseLevel( Logger::Level databaseLevel ) my_bool reconnect = 1; if ( mysql_options( &mDbConnection, MYSQL_OPT_RECONNECT, &reconnect ) ) Fatal( "Can't set database auto reconnect option: %s", mysql_error( &mDbConnection ) ); - std::string::size_type colonIndex = staticConfig.DB_HOST.find( ":/" ); - if ( colonIndex != std::string::npos ) + std::string::size_type colonIndex = staticConfig.DB_HOST.find( ":" ); + if ( colonIndex == std::string::npos ) { - std::string dbHost = staticConfig.DB_HOST.substr( 0, colonIndex ); - std::string dbPort = staticConfig.DB_HOST.substr( colonIndex+1 ); - if ( !mysql_real_connect( &mDbConnection, dbHost.c_str(), staticConfig.DB_USER.c_str(), staticConfig.DB_PASS.c_str(), 0, atoi(dbPort.c_str()), 0, 0 ) ) + if ( !mysql_real_connect( &mDbConnection, staticConfig.DB_HOST.c_str(), staticConfig.DB_USER.c_str(), staticConfig.DB_PASS.c_str(), NULL, 0, NULL, 0 ) ) { Fatal( "Can't connect to database: %s", mysql_error( &mDbConnection ) ); exit( mysql_errno( &mDbConnection ) ); @@ -380,10 +378,23 @@ Logger::Level Logger::databaseLevel( Logger::Level databaseLevel ) } else { - if ( !mysql_real_connect( &mDbConnection, staticConfig.DB_HOST.c_str(), staticConfig.DB_USER.c_str(), staticConfig.DB_PASS.c_str(), 0, 0, 0, 0 ) ) + std::string dbHost = staticConfig.DB_HOST.substr( 0, colonIndex ); + std::string dbPortOrSocket = staticConfig.DB_HOST.substr( colonIndex+1 ); + if ( dbPortOrSocket[0] == '/' ) { - Fatal( "Can't connect to database: %s", mysql_error( &mDbConnection ) ); - exit( mysql_errno( &mDbConnection ) ); + if ( !mysql_real_connect( &mDbConnection, NULL, staticConfig.DB_USER.c_str(), staticConfig.DB_PASS.c_str(), NULL, 0, dbPortOrSocket.c_str(), 0 ) ) + { + Fatal( "Can't connect to database: %s", mysql_error( &mDbConnection ) ); + exit( mysql_errno( &mDbConnection ) ); + } + } + else + { + if ( !mysql_real_connect( &mDbConnection, dbHost.c_str(), staticConfig.DB_USER.c_str(), staticConfig.DB_PASS.c_str(), NULL, atoi(dbPortOrSocket.c_str()), NULL, 0 ) ) + { + Fatal( "Can't connect to database: %s", mysql_error( &mDbConnection ) ); + exit( mysql_errno( &mDbConnection ) ); + } } } unsigned long mysqlVersion = mysql_get_server_version( &mDbConnection ); diff --git a/web/includes/database.php b/web/includes/database.php index 809145032..f9071026e 100644 --- a/web/includes/database.php +++ b/web/includes/database.php @@ -30,8 +30,20 @@ function dbConnect() { global $dbConn; + if (strpos(ZM_DB_HOST, ':')) { + // Host variable may carry a port or socket. + list($host, $portOrSocket) = explode(':', ZM_DB_HOST, 2); + if (is_numeric($portOrSocket)) { + $socket = ':host='.$host . ';port='.$portOrSocket; + } else { + $socket = ':unix_socket='.$portOrSocket; + } + } else { + $socket = ':host='.ZM_DB_HOST; + } + try { - $dbConn = new PDO( ZM_DB_TYPE . ':host=' . ZM_DB_HOST . ';dbname='.ZM_DB_NAME, ZM_DB_USER, ZM_DB_PASS ); + $dbConn = new PDO( ZM_DB_TYPE . $socket . ';dbname='.ZM_DB_NAME, ZM_DB_USER, ZM_DB_PASS ); $dbConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $ex ) { echo "Unable to connect to ZM db." . $ex->getMessage(); From 38e1cc909cb16ca38ce2b406481265643bfb45da Mon Sep 17 00:00:00 2001 From: josh4trunks Date: Sun, 22 May 2016 08:19:18 -0700 Subject: [PATCH 02/16] Reapply changes to Database.pm --- scripts/ZoneMinder/lib/ZoneMinder/Database.pm | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Database.pm b/scripts/ZoneMinder/lib/ZoneMinder/Database.pm index 7dfe0654b..fbbe0a027 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Database.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Database.pm @@ -79,25 +79,29 @@ sub zmDbConnect } if ( !defined( $dbh ) ) { - my ( $host, $port ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ ); + my $socket; + my ( $host, $portOrSocket ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ ); - if ( defined($port) ) + if ( defined($portOrSocket) ) { - $dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME} - .";host=".$host - .";port=".$port - , $Config{ZM_DB_USER} - , $Config{ZM_DB_PASS} - ); + if ( $portOrSocket =~ /^\// ) + { + $socket = ";mysql_socket=".$portOrSocket; + } + else + { + $socket = ";host=".$host.";port=".$portOrSocket; + } } else { - $dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME} - .";host=".$Config{ZM_DB_HOST} - , $Config{ZM_DB_USER} - , $Config{ZM_DB_PASS} - ); + $socket = ";host=".$Config{ZM_DB_HOST}; } + $dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME} + .$socket + , $Config{ZM_DB_USER} + , $Config{ZM_DB_PASS} + ); $dbh->trace( 0 ); } return( $dbh ); From a3fe6ea1819113fe9696a43e4eb9f28cf943b38e Mon Sep 17 00:00:00 2001 From: josh4trunks Date: Sun, 22 May 2016 08:28:23 -0700 Subject: [PATCH 03/16] Apply changes to Logger.pm --- scripts/ZoneMinder/lib/ZoneMinder/Logger.pm | 30 ++++++++++++--------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm b/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm index a6a82db87..d17f9683a 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm @@ -460,25 +460,29 @@ sub databaseLevel { if ( !$this->{dbh} ) { - my ( $host, $port ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ ); + my $socket; + my ( $host, $portOrSocket ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ ); - if ( defined($port) ) + if ( defined($portOrSocket) ) { - $this->{dbh} = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME} - .";host=".$host - .";port=".$port - , $Config{ZM_DB_USER} - , $Config{ZM_DB_PASS} - ); + if ( $portOrSocket =~ /^\// ) + { + $socket = ";mysql_socket=".$portOrSocket; + } + else + { + $socket = ";host=".$host.";port=".$portOrSocket; + } } else { - $this->{dbh} = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME} - .";host=".$Config{ZM_DB_HOST} - , $Config{ZM_DB_USER} - , $Config{ZM_DB_PASS} - ); + $socket = ";host=".$Config{ZM_DB_HOST}; } + $this->{dbh} = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME} + .$socket + , $Config{ZM_DB_USER} + , $Config{ZM_DB_PASS} + ); if ( !$this->{dbh} ) { $databaseLevel = NOLOG; From 57a25373fab44ba0e9630bbbfc8fed054a5c06cc Mon Sep 17 00:00:00 2001 From: josh4trunks Date: Sun, 22 May 2016 08:53:30 -0700 Subject: [PATCH 04/16] Add logic to Config.pm --- .../ZoneMinder/lib/ZoneMinder/Config.pm.in | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Config.pm.in b/scripts/ZoneMinder/lib/ZoneMinder/Config.pm.in index 0cc8081d2..251d6c1ba 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Config.pm.in +++ b/scripts/ZoneMinder/lib/ZoneMinder/Config.pm.in @@ -89,8 +89,26 @@ BEGIN close( $CONFIG ); use DBI; + my $socket; + my ( $host, $portOrSocket ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ ); + + if ( defined($portOrSocket) ) + { + if ( $portOrSocket =~ /^\// ) + { + $socket = ";mysql_socket=".$portOrSocket; + } + else + { + $socket = ";host=".$host.";port=".$portOrSocket; + } + } + else + { + $socket = ";host=".$Config{ZM_DB_HOST}; + } my $dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME} - .";host=".$Config{ZM_DB_HOST} + .$socket , $Config{ZM_DB_USER} , $Config{ZM_DB_PASS} ) or croak( "Can't connect to db" ); From f969186abb2ba4197004eaef91a50802b1734ea7 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 26 May 2016 11:15:13 -0400 Subject: [PATCH 05/16] add the ZM_WEB_ID_ON_CONSOLE option and use it to show the ID column on the console --- scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in | 10 ++++++++++ web/skins/classic/views/console.php | 11 ++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in index 610d2432d..16a618827 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in +++ b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in @@ -1564,6 +1564,16 @@ our @options = type => $types{boolean}, category => "web", }, + { + name => "ZM_WEB_ID_ON_CONSOLE", + default => "no", + description => "Should the console list the monitor id", + help => qqq("Some find it useful to have the id always visible + on the console. This option will add a column listing it. + "), + type => $types{boolean}, + category => "web", + }, { name => "ZM_WEB_POPUP_ON_ALARM", default => "yes", diff --git a/web/skins/classic/views/console.php b/web/skins/classic/views/console.php index dbf0ea2f4..1aa2c101d 100644 --- a/web/skins/classic/views/console.php +++ b/web/skins/classic/views/console.php @@ -182,6 +182,9 @@ $seqDownFile = getSkinFile( 'graphics/seq-d.gif' ); $versionClass = (ZM_DYN_DB_VERSION&&(ZM_DYN_DB_VERSION!=ZM_VERSION))?'errorText':''; +$left_columns = 3; +if ( count($servers) ) $left_columns += 1; +if ( ZM_WEB_ID_ON_CONSOLE ) ) $left_columns += 1; xhtmlHeaders( __FILE__, translate('Console') ); ?> @@ -241,6 +244,9 @@ else + + + @@ -269,7 +275,7 @@ if ( canEdit('Monitors') ) - + From f461bc1e80b6441058961792a1c2564120e5b5ae Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 26 May 2016 12:18:58 -0400 Subject: [PATCH 06/16] get rid of extra ) --- web/skins/classic/views/console.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/skins/classic/views/console.php b/web/skins/classic/views/console.php index 1aa2c101d..b1f437c56 100644 --- a/web/skins/classic/views/console.php +++ b/web/skins/classic/views/console.php @@ -184,7 +184,7 @@ $versionClass = (ZM_DYN_DB_VERSION&&(ZM_DYN_DB_VERSION!=ZM_VERSION))?'errorText' $left_columns = 3; if ( count($servers) ) $left_columns += 1; -if ( ZM_WEB_ID_ON_CONSOLE ) ) $left_columns += 1; +if ( ZM_WEB_ID_ON_CONSOLE ) $left_columns += 1; xhtmlHeaders( __FILE__, translate('Console') ); ?> From 1f53377d8ae3c8e45ce8de5c012b1398f107457d Mon Sep 17 00:00:00 2001 From: Steve Gilvarry Date: Tue, 5 Jul 2016 07:28:52 +1000 Subject: [PATCH 07/16] Implement suggested wait for MySQL start --- distros/ubuntu1204/zoneminder.init | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/distros/ubuntu1204/zoneminder.init b/distros/ubuntu1204/zoneminder.init index 5cdf62165..0474672b2 100644 --- a/distros/ubuntu1204/zoneminder.init +++ b/distros/ubuntu1204/zoneminder.init @@ -23,6 +23,13 @@ command="$ZM_PATH_BIN/zmpkg.pl" start() { echo -n "Starting $prog: " + # ATB - wait for mysqld to start. Continue if it takes too long. + count=0 + while [ ! -e /var/run/mysqld/mysqld.sock ] && [ $count -lt 60 ] + do + sleep 1 + count=$((count+1)) + done export TZ=:/etc/localtime mkdir -p "$RUNDIR" && chown www-data:www-data "$RUNDIR" mkdir -p "$TMPDIR" && chown www-data:www-data "$TMPDIR" From 1f060f193883fc4bd932b109d974cd86b0ed6faa Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Tue, 5 Jul 2016 11:35:08 -0500 Subject: [PATCH 08/16] Update zoneminder.init Remove my initials --- distros/ubuntu1204/zoneminder.init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distros/ubuntu1204/zoneminder.init b/distros/ubuntu1204/zoneminder.init index 0474672b2..de552848b 100644 --- a/distros/ubuntu1204/zoneminder.init +++ b/distros/ubuntu1204/zoneminder.init @@ -23,7 +23,7 @@ command="$ZM_PATH_BIN/zmpkg.pl" start() { echo -n "Starting $prog: " - # ATB - wait for mysqld to start. Continue if it takes too long. + # Wait for mysqld to start. Continue if it takes too long. count=0 while [ ! -e /var/run/mysqld/mysqld.sock ] && [ $count -lt 60 ] do From 19265b631abe64306507982234769dbc14d41366 Mon Sep 17 00:00:00 2001 From: Andy Bauer Date: Sat, 9 Jul 2016 13:11:30 -0500 Subject: [PATCH 09/16] custom banner text on web console --- scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in | 14 ++++++++++++++ web/skins/classic/views/console.php | 1 + 2 files changed, 15 insertions(+) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in index 610d2432d..d23186c23 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in +++ b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in @@ -1548,6 +1548,20 @@ our @options = type => $types{string}, category => "web", }, + { + name => "ZM_WEB_CONSOLE_BANNER", + default => "", + description => "Arbitrary text message near the top of the console", + help => qqq(" + Allows the administrator to place an arbitrary text message + near the top of the web console. This is useful for the developers + to display a message which indicates the running instance of + ZoneMinder is a development snapshot, but it can also be used for + any other purpose as well. + "), + type => $types{string}, + category => "web", + }, { name => "ZM_WEB_RESIZE_CONSOLE", default => "yes", diff --git a/web/skins/classic/views/console.php b/web/skins/classic/views/console.php index 8f0f3c198..e6f3ccf6a 100644 --- a/web/skins/classic/views/console.php +++ b/web/skins/classic/views/console.php @@ -195,6 +195,7 @@ xhtmlHeaders( __FILE__, translate('Console') );

: / : %

ZoneMinder - - v'.ZM_VERSION.'', canEdit( 'System' ) ) ?>

+

Date: Mon, 25 Jul 2016 11:20:49 +0100 Subject: [PATCH 10/16] Control script for Keekoon cameras. Tested with KK002. --- db/zm_create.sql.in | 1 + .../lib/ZoneMinder/Control/Keekoon.pm | 297 ++++++++++++++++++ 2 files changed, 298 insertions(+) create mode 100644 scripts/ZoneMinder/lib/ZoneMinder/Control/Keekoon.pm diff --git a/db/zm_create.sql.in b/db/zm_create.sql.in index 029f20989..0d6c853c9 100644 --- a/db/zm_create.sql.in +++ b/db/zm_create.sql.in @@ -594,6 +594,7 @@ INSERT INTO `Controls` VALUES (NULL,'Wanscam HW0025','Libvlc','WanscamHW0025', 1 INSERT INTO `Controls` VALUES (NULL,'IPCC 7210W','Libvlc','IPCC7210W', 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 16, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 350, 0, 0, 1, 0, 10, 0, 0, 1, 0, 0, 0, 0, 1, 0, 10, 0, 0, 0, 0); INSERT INTO `Controls` VALUES (NULL,'Vivotek ePTZ','Remote','Vivotek_ePTZ',0,0,1,1,0,0,0,1,0,0,0,0,1,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,0,0,0,0,1,0,5,0,0,1,0,0,0,0,1,0,5,0,0,0,0); INSERT INTO `Controls` VALUES (NULL,'Netcat ONVIF','Ffmpeg','Netcat',0,0,1,1,0,0,0,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,100,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,100,5,5,0,0,0,1,255,1,1,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0); +INSERT INTO `Controls` VALUES (NULL,'Keekoon','Remote','Keekoon', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); -- -- Add some monitor preset values diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Control/Keekoon.pm b/scripts/ZoneMinder/lib/ZoneMinder/Control/Keekoon.pm new file mode 100644 index 000000000..09edb7d47 --- /dev/null +++ b/scripts/ZoneMinder/lib/ZoneMinder/Control/Keekoon.pm @@ -0,0 +1,297 @@ +# ========================================================================== +# +# ZoneMinder Keekoon Control Protocol Module +# This code was mostly derived from other ZM Control modules +# +# ========================================================================== +# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# ========================================================================== +# +# Tested: KK002 (22 July 2016) +# +# Usage: +# ====== +# +# Copy this file to say /usr/share/perl5/ZoneMinder/Control (Debian/Ubuntu) +# +# Create a new Control Capabilities: +# Main: Name Keekoon, Type = Remote, Protocol = Keekoon +# Move: Can Move, Can Move Diagonally, Can Move Continous +# Pan: Can Pan +# Tilt: Can Tilt +# Presets: Has Presets, Num Presets = 6, Can Set Presets +# +# Set the ControlAddress in the camera definition, use the format: +# http(s)://username:password@address:port +# +# eg : http://admin:adminpass@10.10.10.1:80 +# or : https://admin:password@mycamera.example.co.uk:80 +# +# Return Location to Preset 1 +# Auto Stop Timeout = 0.5 is a good starting point +# +# =========================================================================== +# Problems: Enable debug and watch /tmp/zm_debug.log. The +# correct debug log can be found by date stamp. +# Enable/disable the Source for the camera in the web GUI +# each time you edit this script. If the pid doesn't +# change then you have not restarted it. +# Errors like this: +# [Error in response to Request:'400 URL must be absolute'] +# means that you have not specified all the parts in ControlAddress or the +# Regex has failed to parse it correctly +# +# ========================================================================= +# Notes: +# Example command from docs, at http://www.keekoonvision.com/for-developers-a: +# Up: http://camera_ip:web_port/decoder_control.cgi?command=0&user=username&pwd=password +# However the camera actually uses basic auth and not user= etc +# +# Test URLs with something like this +# curl -XGET -u user:pass "http://cam.example.co.uk:80/decoder_control.cgi?command=1 +# +# These cameras have a default admin user but can have six more defined +# with membership of three groups +# https is not directly supported but could be via say HA Proxy, so that +# is included rather than hardstrapping http:// +# ========================================================================== + +package ZoneMinder::Control::Keekoon; + +use 5.006; +use strict; +use warnings; + +require ZoneMinder::Control; + +our @ISA = qw(ZoneMinder::Control); + +use ZoneMinder::Logger qw(:all); +use ZoneMinder::Config qw(:all); +use Time::HiRes qw( usleep ); + +sub new +{ + + my $class = shift; + my $id = shift; + my $self = ZoneMinder::Control->new( $id ); + my $logindetails = ""; + bless( $self, $class ); + srand( time() ); + return $self; +} + +our $AUTOLOAD; + +sub AUTOLOAD +{ + my $self = shift; + my $class = ref( ) || croak( "$self not object" ); + my $name = $AUTOLOAD; + $name =~ s/.*://; + if ( exists($self->{$name}) ) + { + return( $self->{$name} ); + } + Fatal( "Can't access $name member of object of class $class" ); +} + +sub open +{ + my $self = shift; + + $self->loadMonitor(); + + use LWP::UserAgent; + + $self->{ua} = LWP::UserAgent->new; + $self->{ua}->agent( "ZoneMinder Control Agent/".ZoneMinder::Base::ZM_VERSION ); + + $self->{state} = 'open'; + + Info( "Open" ); + +} + +sub close +{ + my $self = shift; + $self->{state} = 'closed'; +} + +sub printMsg +{ + my $self = shift; + my $msg = shift; + my $msg_len = length($msg); + + Debug( $msg."[".$msg_len."]" ); +} + +sub sendCmd +{ + my $self = shift; + my $cmd = shift; + my $result = undef; + + my ( $PROTOCOL, $USER, $PASS, $ADDR, $PORT ) + = $self->{Monitor}->{ControlAddress} =~ /^(https?):\/\/(.*):(.*)@(.*):(\d+)$/; + my $URL = $PROTOCOL."://".$ADDR.":".$PORT."/decoder_control.cgi?command=".$cmd; + + Debug( "ControlAddress from camera Control setting:".$self->{Monitor}->{ControlAddress} ); + Debug( "URL parsed from ControlAddress:".$URL); + + my $req = HTTP::Request->new( GET=>$URL ); + + # Do Basic Auth + $req->authorization_basic($USER, $PASS); + + my $res = $self->{ua}->request($req); + + if ( $res->is_success ) + { + $result = !undef; + } + else + { + Error( "Error in response to Request:'".$res->status_line()."'" ); + } + + return( $result ); +} + +# Set autoStop timeout on the Control tab for the camera +sub autoStop +{ + my $self = shift; + my $stop_command = shift; + my $autostop = shift; + + if( $stop_command && $autostop) + { + Debug( "Auto Stop" ); + usleep( $autostop ); + my $cmd = $stop_command; + $self->sendCmd( $cmd ); + } +} + +sub moveConUp +{ + my $self = shift; + my $cmd = "0"; + my $stop_command = "1"; + Debug( "Move Up" ); + $self->sendCmd( $cmd ); + $self->autoStop( $stop_command, $self->{Monitor}->{AutoStopTimeout} ); +} + +sub moveConDown +{ + my $self = shift; + my $cmd = "2"; + my $stop_command = "3"; + Debug( "Move Down" ); + $self->sendCmd( $cmd ); + $self->autoStop( $stop_command, $self->{Monitor}->{AutoStopTimeout} ); +} + +sub moveConLeft +{ + my $self = shift; + my $cmd = "4"; + my $stop_command = "5"; + Debug( "Move Left" ); + $self->sendCmd( $cmd ); + $self->autoStop( $stop_command, $self->{Monitor}->{AutoStopTimeout} ); +} + +sub moveConRight +{ + my $self = shift; + my $cmd = "6"; + my $stop_command = "7"; + Debug( "Move Right" ); + $self->sendCmd( $cmd ); + $self->autoStop( $stop_command, $self->{Monitor}->{AutoStopTimeout} ); +} + +sub moveConUpRight +{ + my $self = shift; + Debug( "Move Diagonally Up Right" ); + $self->moveConUp( ); + $self->moveConRight( ); +} + +sub moveConDownRight +{ + my $self = shift; + Debug( "Move Diagonally Down Right" ); + $self->moveConDown( ); + $self->moveConRight( ); +} + +sub moveConUpLeft +{ + my $self = shift; + Debug( "Move Diagonally Up Left" ); + $self->moveConUp( ); + $self->moveConLeft( ); +} + +sub moveConDownLeft +{ + my $self = shift; + Debug( "Move Diagonally Down Left" ); + $self->moveConDown( ); + $self->moveConLeft( ); +} + +# SET: 30,32,34,36,38,40 for presets 1-6 +sub presetSet +{ + my $self = shift; + my $params = shift; + my $preset = $self->getParam( $params, 'preset' ); + + Debug( "Set Preset No: " . $preset ); + + if (( $preset >= 1 ) && ( $preset <= 6 )) { + my $cmd = (($preset*2) + 28); + $self->sendCmd( $cmd ); + Debug( "Set preset cmd: " . $cmd ); + } + +} + +# GOTO: 31,33,35,37,39,41 for presets 1-6 +sub presetGoto +{ + my $self = shift; + my $params = shift; + my $preset = $self->getParam( $params, 'preset' ); + Debug( "Goto Preset No: " . $preset ); + + if (( $preset >= 1 ) && ( $preset <= 6 )) { + my $cmd = (($preset*2) + 29); + $self->sendCmd( $cmd ); + Debug( "Goto Preset cmd: " . $cmd ); + } + +} + +1; From 71e3789bd0af68465474fa6f5a8e4321d6662ace Mon Sep 17 00:00:00 2001 From: Steve Gilvarry Date: Thu, 28 Jul 2016 23:15:01 +1000 Subject: [PATCH 11/16] Use av_dict_parse_string to split ffmpeg options, and remove creating strings to split them in next step for rtsp_transport --- src/zm_ffmpeg_camera.cpp | 51 +++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index 12456a560..3b1adaa02 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -226,9 +226,12 @@ int FfmpegCamera::OpenFfmpeg() { Debug ( 2, "OpenFfmpeg called." ); + int ret; + mOpenStart = time(NULL); mIsOpening = true; + // Open the input, not necessarily a file #if !LIBAVFORMAT_VERSION_CHECK(53, 2, 0, 4, 0) Debug ( 1, "Calling av_open_input_file" ); @@ -236,37 +239,25 @@ int FfmpegCamera::OpenFfmpeg() { #else // Handle options AVDictionary *opts = 0; - StringVector opVect = split(Options(), ","); - + ret = av_dict_parse_string(&opts, Options().c_str(), "=", ",", 0); + if (ret < 0) { + Warning("Could not parse format options list '%s'\n", Options().c_str()); + } + + // Set transport method as specified by method field, rtpUni is default - if ( Method() == "rtpMulti" ) - opVect.push_back("rtsp_transport=udp_multicast"); - else if ( Method() == "rtpRtsp" ) - opVect.push_back("rtsp_transport=tcp"); - else if ( Method() == "rtpRtspHttp" ) - opVect.push_back("rtsp_transport=http"); - - Debug(2, "Number of Options: %d",opVect.size()); - for (size_t i=0; i 1) { - parts[0] = trimSpaces(parts[0]); - parts[1] = trimSpaces(parts[1]); - if ( av_dict_set(&opts, parts[0].c_str(), parts[1].c_str(), 0) == 0 ) { - Debug(2, "set option %d '%s' to '%s'", i, parts[0].c_str(), parts[1].c_str()); - } - else - { - Warning( "Error trying to set option %d '%s' to '%s'", i, parts[0].c_str(), parts[1].c_str() ); - } - - } - else - { - Warning( "Unable to parse ffmpeg option %d '%s', expecting key=value", i, opVect[i].c_str() ); - } - } + if (Method() == "rtpMulti") { + ret = av_dict_set(&opts, "rtsp_transport", "udp_multicast", 0); + } else if (Method() == "rtpRtsp") { + ret = av_dict_set(&opts, "rtsp_transport", "tcp", 0); + } else if (Method() == "rtpRtspHttp") { + ret = av_dict_set(&opts, "rtsp_transport", "http", 0); + } + + if (ret < 0) { + Warning("Could not set rtsp_transport method '%s'\n", Method().c_str()); + } + Debug ( 1, "Calling avformat_open_input" ); mFormatContext = avformat_alloc_context( ); From 1a684b7709e8afc4ca438b934e4d2bd28cd8029e Mon Sep 17 00:00:00 2001 From: Steve Gilvarry Date: Thu, 28 Jul 2016 23:22:34 +1000 Subject: [PATCH 12/16] Remove whitespace --- src/zm_ffmpeg_camera.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index 3b1adaa02..533b69b2c 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -231,7 +231,6 @@ int FfmpegCamera::OpenFfmpeg() { mOpenStart = time(NULL); mIsOpening = true; - // Open the input, not necessarily a file #if !LIBAVFORMAT_VERSION_CHECK(53, 2, 0, 4, 0) Debug ( 1, "Calling av_open_input_file" ); @@ -241,10 +240,9 @@ int FfmpegCamera::OpenFfmpeg() { AVDictionary *opts = 0; ret = av_dict_parse_string(&opts, Options().c_str(), "=", ",", 0); if (ret < 0) { - Warning("Could not parse format options list '%s'\n", Options().c_str()); + Warning("Could not parse ffmpeg input options list '%s'\n", Options().c_str()); } - // Set transport method as specified by method field, rtpUni is default if (Method() == "rtpMulti") { ret = av_dict_set(&opts, "rtsp_transport", "udp_multicast", 0); From 25d58f51923735764f6cb1a72314105a44fd2ee0 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 2 Aug 2016 13:22:44 -0400 Subject: [PATCH 13/16] quote the password --- scripts/zmupdate.pl.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/zmupdate.pl.in b/scripts/zmupdate.pl.in index c0dcd3868..462cb1d18 100644 --- a/scripts/zmupdate.pl.in +++ b/scripts/zmupdate.pl.in @@ -460,7 +460,7 @@ if ( $version ) $command .= " -u".$dbUser; if ( $dbPass ) { - $command .= " -p".$dbPass; + $command .= ' -p"'.$dbPass.'"'; } } $command .= " ".$Config{ZM_DB_NAME}." < "; From 3a804a0d0c4ae4e5b63f1769336431528593317e Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Sat, 6 Aug 2016 16:34:00 -0500 Subject: [PATCH 14/16] Update definemonitor.rst --- docs/userguide/definemonitor.rst | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/userguide/definemonitor.rst b/docs/userguide/definemonitor.rst index d69b44425..c7c13d5a3 100644 --- a/docs/userguide/definemonitor.rst +++ b/docs/userguide/definemonitor.rst @@ -46,10 +46,19 @@ Linked Monitors This field allows you to select other monitors on your system that act as triggers for this monitor. So if you have a camera covering one aspect of your property you can force all cameras to record while that camera detects motion or other events. You can either directly enter a comma separated list of monitor ids or click on ‘Select’ to choose a selection. Be very careful not to create circular dependencies with this feature however you will have infinitely persisting alarms which is almost certainly not what you want! To unlink monitors you can ctrl-click. Maximum FPS - On some occasions you may have one or more cameras capable of high capture rates but find that you generally do not require this performance at all times and would prefer to lighten the load on your server. This option permits you to limit the maximum capture rate to a specified value. This may allow you to have more cameras supported on your system by reducing the CPU load or to allocate video bandwidth unevenly between cameras sharing the same video device. This value is only a rough guide and the lower the value you set the less close the actual FPS may approach it especially on shared devices where it can be difficult to synchronise two or more different capture rates precisely. This option controls the maximum FPS in the circumstance where no alarm is occurring only. (Note for IP cameras: ZoneMinder has no way to set or limit the mjpeg stream the camera passes, some cams you can set this through the url string, others do not. So if you're using mjpeg feeds you must NOT throttle here at the server end, only the cam end. If you want to use this feature, the server to throttle, then you MUST use jpeg instead of mjpeg method to get picture from the camera) - + On some occasions you may have one or more cameras capable of high capture rates but find that you generally do not require this performance at all times and would prefer to lighten the load on your server. This option permits you to limit the maximum capture rate to a specified value. This may allow you to have more cameras supported on your system by reducing the CPU load or to allocate video bandwidth unevenly between cameras sharing the same video device. This value is only a rough guide and the lower the value you set the less close the actual FPS may approach it especially on shared devices where it can be difficult to synchronise two or more different capture rates precisely. This option controls the maximum FPS in the circumstance where no alarm is occurring only. + + This feature is limited and will only work under the following conditions: + + #. Local cameras + #. Remote (IP) cameras in snapshot or jpeg mode **only** + + Using this field for video streams from IP cameras will cause undesirable results when the value is equal to or less than the frame rate from the camera. Note that placing a value higher than the camera's frame rate is allowed and can help prevent cpu spikes when communication from the camera is lost. + Alarm Maximum FPS If you have specified a Maximum FPS it may be that you don’t want this limitation to apply when your monitor is recording motion or other event. This setting allows you to override the Maximum FPS value if this circumstance occurs. As with the Maximum FPS setting leaving this blank implies no limit so if you have set a maximum fps in the previous option then when an alarm occurs this limit would be ignored and ZoneMinder would capture as fast as possible for the duration of the alarm, returning to the limited value after the alarm has concluded. Equally you could set this to the same, or higher (or even lower) value than Maximum FPS for more precise control over the capture rate in the event of an alarm. + + **IMPORTANT:** This field is subject to the same limitations as the Maxium FPS field. Ignoring these limitations will produce undesriable results. Reference Image Blend %ge Each analysed image in ZoneMinder is a composite of previous images and is formed by applying the current image as a certain percentage of the previous reference image. Thus, if we entered the value of 10 here, each image’s part in the reference image will diminish by a factor of 0.9 each time round. So a typical reference image will be 10% the previous image, 9% the one before that and then 8.1%, 7.2%, 6.5% and so on of the rest of the way. An image will effectively vanish around 25 images later than when it was added. This blend value is what is specified here and if higher will make slower progressing events less detectable as the reference image would change more quickly. Similarly events will be deemed to be over much sooner as the reference image adapts to the new images more quickly. In signal processing terms the higher this value the steeper the event attack and decay of the signal. It depends on your particular requirements what the appropriate value would be for you but start with 10 here and adjust it (usually down) later if necessary. From fbc0086fcceb3c2a955a74a6efcaae388b6334eb Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 8 Aug 2016 16:52:09 -0400 Subject: [PATCH 15/16] get the other dbPass use and quote it. Slight visual code style cleanup. --- scripts/zmupdate.pl.in | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/scripts/zmupdate.pl.in b/scripts/zmupdate.pl.in index 462cb1d18..7497309c3 100644 --- a/scripts/zmupdate.pl.in +++ b/scripts/zmupdate.pl.in @@ -412,15 +412,12 @@ if ( $version ) { my ( $host, $port ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ ); my $command = "mysqldump"; - $command .= " -h".$host if defined($host); + $command .= " -h".$host if defined($host); $command .= " -P".$port if defined($port); if ( $dbUser ) { - $command .= " -u".$dbUser; - if ( $dbPass ) - { - $command .= " -p".$dbPass; - } + $command .= ' -u'.$dbUser; + $command .= ' -p"'.$dbPass.'"' if $dbPass; } my $backup = "@ZM_TMPDIR@/".$Config{ZM_DB_NAME}."-".$version.".dump"; $command .= " --add-drop-table --databases ".$Config{ZM_DB_NAME}." > ".$backup; @@ -458,10 +455,7 @@ if ( $version ) if ( $dbUser ) { $command .= " -u".$dbUser; - if ( $dbPass ) - { - $command .= ' -p"'.$dbPass.'"'; - } + $command .= ' -p"'.$dbPass.'"' if $dbPass; } $command .= " ".$Config{ZM_DB_NAME}." < "; if ( $updateDir ) From 6b70ff964b67a6415485e2b4845352d371e46415 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 10 Aug 2016 09:06:15 -0400 Subject: [PATCH 16/16] fix path in cake api cleanup rules --- distros/debian/rules | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/distros/debian/rules b/distros/debian/rules index 4bdc7cb0c..473871a49 100755 --- a/distros/debian/rules +++ b/distros/debian/rules @@ -27,9 +27,9 @@ override_dh_auto_configure: override_dh_auto_install: dh_auto_install --buildsystem=cmake install -D -m 0644 debian/apache.conf $(INSTDIR)/etc/zm/apache.conf - rm $(INSTDIR)/usr/share/zoneminder/api/lib/Cake/LICENSE.txt - rm $(INSTDIR)/usr/share/zoneminder/api/.gitignore - rm -r $(INSTDIR)/usr/share/zoneminder/api/lib/Cake/Test + rm $(INSTDIR)/usr/share/zoneminder/www/api/lib/Cake/LICENSE.txt + rm $(INSTDIR)/usr/share/zoneminder/www/api/.gitignore + rm -r $(INSTDIR)/usr/share/zoneminder/www/api/lib/Cake/Test override_dh_auto_test: # do not run tests...
+ @@ -315,6 +321,9 @@ foreach( $displayMonitors as $monitor ) $fclass .= " disabledText"; $scale = max( reScale( SCALE_BASE, $monitor['DefaultScale'], ZM_WEB_DEFAULT_SCALE ), SCALE_BASE ); ?> + + '.translate('Fn'.$monitor['Function']).( empty($monitor['Enabled']) ? ', disabled' : '' ) .'', canEdit( 'Monitors' ) ) ?>