zoneminder/web/includes/config.php.in

227 lines
7.7 KiB
PHP
Raw Permalink Normal View History

<?php
//
// ZoneMinder web configuration file, $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 section contains options substituted by the zmconfig.pl utility, do not edit these directly
//
define( 'ZM_CONFIG', '@ZM_CONFIG@' ); // Path to config file
define( 'ZM_CONFIG_SUBDIR', '@ZM_CONFIG_SUBDIR@' ); // Path to config subfolder
// Define, and override any given in config file
define( 'ZM_VERSION', '@VERSION@' ); // Version
define( 'ZM_DIR_TEMP', '@ZM_TMPDIR@' );
define( 'ZM_DIR_CACHE', '@ZM_CACHEDIR@' );
2018-04-07 02:52:39 +08:00
global $configvals;
$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']) )
print( "Warning, overriding installed $localConfigFile file with local copy\n" );
else
error_log( "Warning, overriding installed $localConfigFile file with local copy" );
$configFile = $localConfigFile;
}
# 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");
2017-08-14 23:38:21 +08:00
$configvals = array_replace($configvals, process_configfile($filename) );
}
2017-08-14 23:38:21 +08:00
} else {
error_log( "WARNING: ZoneMinder configuration subfolder found but is not readable. Check folder permissions on $configSubFolder." );
}
} else {
error_log( "WARNING: ZoneMinder configuration subfolder found but is not a directory. Check $configSubFolder." );
}
# Now that our array our finalized, define each key => value
# pair in the array as a constant
foreach( $configvals as $key => $value) {
2017-08-14 23:38:21 +08:00
define( $key, $value );
}
//
// This section is options normally derived from other options or configuration
//
define( 'ZMU_PATH', ZM_PATH_BIN.'/zmu' ); // Local path to the ZoneMinder Utility
//
// If setup supports Video 4 Linux v2 and/or v1
//
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
//
// If ONVIF support has been built in
//
define( 'ZM_HAS_ONVIF', '@ZM_HAS_ONVIF@' ); // ONVIF support enabled
//
// If PCRE dev libraries are installed
//
define( 'ZM_PCRE', '@ZM_PCRE@' ); // PCRE support enabled
//
// Alarm states
//
define( 'STATE_IDLE', 0 );
define( 'STATE_PREALARM', 1 );
define( 'STATE_ALARM', 2 );
define( 'STATE_ALERT', 3 );
define( 'STATE_TAPE', 4 );
//
// DVR Control Commands
//
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 );
//
// These are miscellaneous options you won't normally need to change
//
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
//
// Date and time formats, not to be modified by language files
//
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
require_once( 'database.php' );
require_once( 'logger.php' );
loadConfig();
Logger::fetch()->initialise();
$GLOBALS['defaultUser'] = array(
'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
);
2017-08-14 23:38:21 +08:00
function loadConfig( $defineConsts=true ) {
global $config;
global $configCats;
global $dbConn;
$config = array();
$configCat = array();
$result = $dbConn->query( 'select * from Config order by Id asc' );
if ( !$result )
echo mysql_error();
$monitors = array();
while( $row = dbFetchNext( $result ) ) {
if ( $defineConsts )
define( $row['Name'], $row['Value'] );
$config[$row['Name']] = $row;
if ( !($configCat = &$configCats[$row['Category']]) ) {
$configCats[$row['Category']] = array();
$configCat = &$configCats[$row['Category']];
}
2017-08-14 23:38:21 +08:00
$configCat[$row['Name']] = $row;
}
//print_r( $config );
//print_r( $configCats );
}
// For Human-readability, use ZM_SERVER_HOST or ZM_SERVER_NAME in zm.conf, and convert it here to a ZM_SERVER_ID
if ( ! defined('ZM_SERVER_ID') ) {
2017-08-14 23:38:21 +08:00
if ( defined('ZM_SERVER_NAME') and ZM_SERVER_NAME ) {
$server_id = dbFetchOne('SELECT Id FROM Servers WHERE Name=?', 'Id', array(ZM_SERVER_NAME));
if ( ! $server_id ) {
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 {
define( 'ZM_SERVER_ID', $server_id );
}
} else if ( defined('ZM_SERVER_HOST') and ZM_SERVER_HOST ) {
$server_id = dbFetchOne('SELECT Id FROM Servers WHERE Name=?', 'Id', array(ZM_SERVER_HOST));
if ( ! $server_id ) {
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 {
define( 'ZM_SERVER_ID', $server_id );
}
}
}
function process_configfile($configFile) {
2017-08-14 23:38:21 +08:00
if ( is_readable( $configFile ) ) {
$configvals = array();
$cfg = fopen( $configFile, 'r') or Error("Could not open config file: $configFile.");
2017-08-14 23:38:21 +08:00
while ( !feof($cfg) ) {
$str = fgets( $cfg, 256 );
if ( preg_match( '/^\s*$/', $str ))
continue;
elseif ( preg_match( '/^\s*#/', $str ))
continue;
elseif ( preg_match( '/^\s*([^=\s]+)\s*=\s*[\'"]*(.*?)[\'"]*\s*$/', $str, $matches ))
2017-08-14 23:38:21 +08:00
$configvals[$matches[1]] = $matches[2];
}
2017-08-14 23:38:21 +08:00
fclose( $cfg );
return( $configvals );
} else {
error_log( "WARNING: ZoneMinder configuration file found but is not readable. Check file permissions on $configFile." );
return( false );
}
}
?>