2008-07-14 21:54:50 +08:00
< ? php
//
// ZoneMinder web configuration file, $Date$, $Revision$
2008-07-25 17:48:16 +08:00
// Copyright (C) 2001-2008 Philip Coombes
2008-07-14 21:54:50 +08:00
//
// 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
2016-12-26 23:23:16 +08:00
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2008-07-14 21:54:50 +08:00
//
//
// This section contains options substituted by the zmconfig.pl utility, do not edit these directly
//
2017-12-20 23:19:24 +08:00
define ( 'ZM_CONFIG' , '@ZM_CONFIG@' ); // Path to config file
define ( 'ZM_CONFIG_SUBDIR' , '@ZM_CONFIG_SUBDIR@' ); // Path to config subfolder
2013-11-01 21:47:28 +08:00
// Define, and override any given in config file
2017-12-20 23:19:24 +08:00
define ( 'ZM_VERSION' , '@VERSION@' ); // Version
define ( 'ZM_DIR_TEMP' , '@ZM_TMPDIR@' );
2018-04-20 03:01:46 +08:00
define ( 'ZM_DIR_CACHE' , '@ZM_CACHEDIR@' );
2018-04-07 02:52:39 +08:00
global $configvals ;
2008-07-14 21:54:50 +08:00
2011-06-21 17:19:10 +08:00
$configFile = ZM_CONFIG ;
$localConfigFile = basename ( $configFile );
2017-08-14 23:38:21 +08:00
if ( file_exists ( $localConfigFile ) && filesize ( $localConfigFile ) > 0 ) {
if ( php_sapi_name () == 'cli' && empty ( $_SERVER [ 'REMOTE_ADDR' ]) )
2019-12-14 06:46:56 +08:00
print ( " Warning, overriding installed $localConfigFile file with local copy \n " );
2017-08-14 23:38:21 +08:00
else
2019-12-14 06:46:56 +08:00
error_log ( " Warning, overriding installed $localConfigFile file with local copy " );
2017-08-14 23:38:21 +08:00
$configFile = $localConfigFile ;
2011-06-21 17:19:10 +08:00
}
2017-06-06 04:39:19 +08:00
# Process name, value pairs from the main config file first
$configvals = process_configfile ( $configFile );
# Search for user created config files. If one or more are found then
# update our config value array with those values
$configSubFolder = ZM_CONFIG_SUBDIR ;
if ( is_dir ( $configSubFolder ) ) {
2017-08-14 23:38:21 +08:00
if ( is_readable ( $configSubFolder ) ) {
foreach ( glob ( " $configSubFolder /*.conf " ) as $filename ) {
2017-10-07 23:31:48 +08:00
//error_log("processing $filename");
2019-12-14 06:46:56 +08:00
$configvals = array_replace ( $configvals , process_configfile ( $filename ));
2017-06-06 04:39:19 +08:00
}
2017-08-14 23:38:21 +08:00
} else {
2019-12-14 06:46:56 +08:00
error_log ( " WARNING: ZoneMinder configuration subfolder found but is not readable. Check folder permissions on $configSubFolder . " );
2017-08-14 23:38:21 +08:00
}
2017-09-27 04:13:51 +08:00
} else {
2019-12-14 06:46:56 +08:00
error_log ( " WARNING: ZoneMinder configuration subfolder found but is not a directory. Check $configSubFolder . " );
2017-06-06 04:39:19 +08:00
}
# Now that our array our finalized, define each key => value
# pair in the array as a constant
2019-12-14 06:46:56 +08:00
foreach ( $configvals as $key => $value ) {
define ( $key , $value );
2008-07-14 21:54:50 +08:00
}
//
// This section is options normally derived from other options or configuration
//
2017-12-20 23:19:24 +08:00
define ( 'ZMU_PATH' , ZM_PATH_BIN . '/zmu' ); // Local path to the ZoneMinder Utility
2008-07-14 21:54:50 +08:00
2008-10-28 22:25:12 +08:00
//
2011-02-16 05:59:06 +08:00
// If setup supports Video 4 Linux v2 and/or v1
2008-10-28 22:25:12 +08:00
//
2017-12-20 23:19:24 +08:00
define ( 'ZM_HAS_V4L2' , '@ZM_HAS_V4L2@' ); // V4L2 support enabled
define ( 'ZM_HAS_V4L1' , '@ZM_HAS_V4L1@' ); // V4L1 support enabled
define ( 'ZM_HAS_V4L' , '@ZM_HAS_V4L@' ); // V4L support enabled
2008-10-28 22:25:12 +08:00
2015-02-22 01:12:07 +08:00
//
// If ONVIF support has been built in
//
2017-12-20 23:19:24 +08:00
define ( 'ZM_HAS_ONVIF' , '@ZM_HAS_ONVIF@' ); // ONVIF support enabled
2015-02-22 01:12:07 +08:00
2008-12-06 02:41:14 +08:00
//
// If PCRE dev libraries are installed
//
2017-12-20 23:19:24 +08:00
define ( 'ZM_PCRE' , '@ZM_PCRE@' ); // PCRE support enabled
2008-12-06 02:41:14 +08:00
2008-07-14 21:54:50 +08:00
//
// Alarm states
//
2017-12-20 23:19:24 +08:00
define ( 'STATE_IDLE' , 0 );
define ( 'STATE_PREALARM' , 1 );
define ( 'STATE_ALARM' , 2 );
define ( 'STATE_ALERT' , 3 );
define ( 'STATE_TAPE' , 4 );
2008-07-14 21:54:50 +08:00
//
// DVR Control Commands
//
2017-12-20 23:19:24 +08:00
define ( 'MSG_CMD' , 1 );
define ( 'MSG_DATA_WATCH' , 2 );
define ( 'MSG_DATA_EVENT' , 3 );
define ( 'CMD_NONE' , 0 );
define ( 'CMD_PAUSE' , 1 );
define ( 'CMD_PLAY' , 2 );
define ( 'CMD_STOP' , 3 );
define ( 'CMD_FASTFWD' , 4 );
define ( 'CMD_SLOWFWD' , 5 );
define ( 'CMD_SLOWREV' , 6 );
define ( 'CMD_FASTREV' , 7 );
define ( 'CMD_ZOOMIN' , 8 );
define ( 'CMD_ZOOMOUT' , 9 );
define ( 'CMD_PAN' , 10 );
define ( 'CMD_SCALE' , 11 );
define ( 'CMD_PREV' , 12 );
define ( 'CMD_NEXT' , 13 );
define ( 'CMD_SEEK' , 14 );
define ( 'CMD_VARPLAY' , 15 );
define ( 'CMD_QUIT' , 17 );
define ( 'CMD_QUERY' , 99 );
2008-07-14 21:54:50 +08:00
//
// These are miscellaneous options you won't normally need to change
//
2017-12-20 23:19:24 +08:00
define ( 'MAX_EVENTS' , 10 ); // The maximum number of events to show in the monitor event listing
define ( 'RATE_BASE' , 100 ); // The additional scaling factor used to help get fractional rates in integer format
define ( 'SCALE_BASE' , 100 ); // The additional scaling factor used to help get fractional scales in integer format
2008-07-14 21:54:50 +08:00
//
2014-02-26 23:14:04 +08:00
// Date and time formats, not to be modified by language files
2008-07-14 21:54:50 +08:00
//
2017-12-20 23:19:24 +08:00
define ( 'STRF_FMT_DATETIME_DB' , '%Y-%m-%d %H:%M:%S' ); // Strftime format for database queries, don't change
define ( 'MYSQL_FMT_DATETIME_SHORT' , '%y/%m/%d %H:%i:%S' ); // MySQL date_format shorter format for dates with time
2008-07-14 21:54:50 +08:00
2019-12-14 06:46:56 +08:00
require_once ( 'database.php' );
require_once ( 'logger.php' );
2008-07-14 21:54:50 +08:00
loadConfig ();
2019-02-22 22:19:07 +08:00
ZM\Logger :: fetch () -> initialise ();
2008-07-14 21:54:50 +08:00
$GLOBALS [ 'defaultUser' ] = array (
2017-12-20 23:19:24 +08:00
'Username' => 'admin' ,
'Password' => '' ,
'Language' => '' ,
2017-12-05 00:05:50 +08:00
'Enabled' => 1 ,
'Stream' => 'View' ,
'Events' => 'Edit' ,
'Control' => 'Edit' ,
'Monitors' => 'Edit' ,
'Groups' => 'Edit' ,
'Devices' => 'Edit' ,
'System' => 'Edit' ,
'MaxBandwidth' => '' ,
'MonitorIds' => false
2008-07-14 21:54:50 +08:00
);
2017-08-14 23:38:21 +08:00
function loadConfig ( $defineConsts = true ) {
global $config ;
global $dbConn ;
$config = array ();
2018-10-20 03:00:30 +08:00
$result = $dbConn -> query ( 'SELECT Name,Value FROM Config' );
2017-08-14 23:38:21 +08:00
if ( ! $result )
echo mysql_error ();
2019-12-14 06:46:56 +08:00
while ( $row = dbFetchNext ( $result ) ) {
2017-08-14 23:38:21 +08:00
if ( $defineConsts )
2019-12-14 06:46:56 +08:00
define ( $row [ 'Name' ], $row [ 'Value' ]);
2017-08-14 23:38:21 +08:00
$config [ $row [ 'Name' ]] = $row ;
}
2018-10-20 03:00:30 +08:00
} # end function loadConfig
2008-07-14 21:54:50 +08:00
2017-12-05 04:52:16 +08:00
// For Human-readability, use ZM_SERVER_HOST or ZM_SERVER_NAME in zm.conf, and convert it here to a ZM_SERVER_ID
2015-07-17 22:12:44 +08:00
if ( ! defined ( 'ZM_SERVER_ID' ) ) {
2019-12-14 06:46:56 +08:00
require_once ( 'Server.php' );
2017-08-14 23:38:21 +08:00
if ( defined ( 'ZM_SERVER_NAME' ) and ZM_SERVER_NAME ) {
2019-12-14 06:46:56 +08:00
# Use Server lookup so that it caches
$Server = ZM\Server :: find_one ( array ( 'Name' => ZM_SERVER_NAME ));
if ( ! $Server ) {
2020-01-03 05:54:50 +08:00
ZM\Error ( 'Invalid Multi-Server configration detected. ZM_SERVER_NAME set to ' . ZM_SERVER_NAME . ' in zm.conf, but no corresponding entry found in Servers table.' );
2017-08-14 23:38:21 +08:00
} else {
2019-12-14 06:46:56 +08:00
define ( 'ZM_SERVER_ID' , $Server -> Id ());
2017-08-14 23:38:21 +08:00
}
} else if ( defined ( 'ZM_SERVER_HOST' ) and ZM_SERVER_HOST ) {
2019-12-14 06:46:56 +08:00
$Server = ZM\Server :: find_one ( array ( 'Name' => ZM_SERVER_HOST ));
if ( ! $Server ) {
2020-01-03 05:54:50 +08:00
ZM\Error ( 'Invalid Multi-Server configration detected. ZM_SERVER_HOST set to ' . ZM_SERVER_HOST . ' in zm.conf, but no corresponding entry found in Servers table.' );
2017-08-14 23:38:21 +08:00
} else {
2019-12-14 06:46:56 +08:00
define ( 'ZM_SERVER_ID' , $Server -> Id ());
2017-08-14 23:38:21 +08:00
}
}
2015-07-09 23:45:19 +08:00
}
2020-04-03 02:00:36 +08:00
if ( defined ( 'ZM_TIMEZONE' ) and ZM_TIMEZONE )
2020-02-12 02:21:28 +08:00
ini_set ( 'date.timezone' , ZM_TIMEZONE );
2019-10-19 02:37:09 +08:00
2017-06-06 04:39:19 +08:00
function process_configfile ( $configFile ) {
2017-08-14 23:38:21 +08:00
if ( is_readable ( $configFile ) ) {
$configvals = array ();
2020-01-03 05:54:50 +08:00
$cfg = fopen ( $configFile , 'r' ) or ZM\Error ( " Could not open config file: $configFile . " );
2017-08-14 23:38:21 +08:00
while ( ! feof ( $cfg ) ) {
2019-12-14 06:46:56 +08:00
$str = fgets ( $cfg , 256 );
if ( preg_match ( '/^\s*(#.*)?$/' , $str ) ) {
2017-08-14 23:38:21 +08:00
continue ;
2019-12-14 06:46:56 +08:00
} else if ( preg_match ( '/^\s*([^=\s]+)\s*=\s*[\'"]*(.*?)[\'"]*\s*$/' , $str , $matches )) {
2017-08-14 23:38:21 +08:00
$configvals [ $matches [ 1 ]] = $matches [ 2 ];
2019-12-14 06:46:56 +08:00
} else {
2020-01-03 05:54:50 +08:00
ZM\Error ( " Malformed line in config $configFile\n $str " );
2019-12-14 06:46:56 +08:00
}
2017-06-06 04:39:19 +08:00
}
2019-12-14 06:46:56 +08:00
fclose ( $cfg );
return $configvals ;
2017-08-14 23:38:21 +08:00
} else {
2019-12-14 06:46:56 +08:00
error_log ( " WARNING: ZoneMinder configuration file found but is not readable. Check file permissions on $configFile . " );
return false ;
2017-08-14 23:38:21 +08:00
}
2017-06-06 04:39:19 +08:00
}
2015-07-09 23:45:19 +08:00
2008-07-14 21:54:50 +08:00
?>