2008-07-14 21:54:50 +08:00
|
|
|
<?php
|
|
|
|
//
|
|
|
|
// ZoneMinder main web interface 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
|
|
|
//
|
|
|
|
|
2018-08-31 22:37:11 +08:00
|
|
|
error_reporting(E_ALL);
|
2008-07-14 21:54:50 +08:00
|
|
|
|
|
|
|
$debug = false;
|
2016-10-20 23:51:42 +08:00
|
|
|
if ( $debug ) {
|
|
|
|
// Use these for debugging, though not both at once!
|
2018-08-31 22:37:11 +08:00
|
|
|
phpinfo(INFO_VARIABLES);
|
2016-10-20 23:51:42 +08:00
|
|
|
//error_reporting( E_ALL );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Use new style autoglobals where possible
|
2018-08-31 22:37:11 +08:00
|
|
|
if ( version_compare(phpversion(), '4.1.0', '<') ) {
|
2016-10-20 23:51:42 +08:00
|
|
|
$_SESSION = &$HTTP_SESSION_VARS;
|
|
|
|
$_SERVER = &$HTTP_SERVER_VARS;
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Useful debugging lines for mobile devices
|
2017-11-25 04:38:07 +08:00
|
|
|
if ( false ) {
|
2016-10-20 23:51:42 +08:00
|
|
|
ob_start();
|
2018-08-31 22:37:11 +08:00
|
|
|
phpinfo(INFO_VARIABLES);
|
|
|
|
$fp = fopen('/tmp/env.html', 'w');
|
|
|
|
fwrite($fp, ob_get_contents());
|
|
|
|
fclose($fp);
|
2016-10-20 23:51:42 +08:00
|
|
|
ob_end_clean();
|
2017-11-25 04:38:07 +08:00
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2018-08-31 22:37:11 +08:00
|
|
|
require_once('includes/config.php');
|
|
|
|
require_once('includes/logger.php');
|
|
|
|
require_once('includes/Server.php');
|
|
|
|
require_once('includes/Storage.php');
|
|
|
|
require_once('includes/Event.php');
|
|
|
|
require_once('includes/Group.php');
|
|
|
|
require_once('includes/Monitor.php');
|
2015-01-05 00:50:24 +08:00
|
|
|
|
2018-07-12 10:01:37 +08:00
|
|
|
|
2018-07-12 23:38:58 +08:00
|
|
|
if (
|
|
|
|
(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
|
|
|
|
or
|
2018-07-13 03:04:54 +08:00
|
|
|
(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'))
|
2018-07-12 23:38:58 +08:00
|
|
|
) {
|
2016-10-20 23:51:42 +08:00
|
|
|
$protocol = 'https';
|
|
|
|
} else {
|
|
|
|
$protocol = 'http';
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
2018-08-31 22:37:11 +08:00
|
|
|
define('ZM_BASE_PROTOCOL', $protocol);
|
2015-10-25 02:04:54 +08:00
|
|
|
|
|
|
|
// Absolute URL's are unnecessary and break compatibility with reverse proxies
|
|
|
|
// define( "ZM_BASE_URL", $protocol.'://'.$_SERVER['HTTP_HOST'] );
|
|
|
|
|
|
|
|
// Use relative URL's instead
|
2018-08-31 22:37:11 +08:00
|
|
|
define('ZM_BASE_URL', '');
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2015-10-13 03:43:24 +08:00
|
|
|
// Check time zone is set
|
|
|
|
if (!ini_get('date.timezone') || !date_default_timezone_set(ini_get('date.timezone'))) {
|
2016-10-20 23:51:42 +08:00
|
|
|
date_default_timezone_set('UTC');
|
|
|
|
Fatal( "ZoneMinder is not installed properly: php's date.timezone is not set to a valid timezone" );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( isset($_GET['skin']) ) {
|
|
|
|
$skin = $_GET['skin'];
|
|
|
|
} else if ( isset($_COOKIE['zmSkin']) ) {
|
|
|
|
$skin = $_COOKIE['zmSkin'];
|
|
|
|
} else if ( defined('ZM_SKIN_DEFAULT') ) {
|
|
|
|
$skin = ZM_SKIN_DEFAULT;
|
|
|
|
} else {
|
|
|
|
$skin = 'classic';
|
2015-10-13 03:43:24 +08:00
|
|
|
}
|
|
|
|
|
2018-08-31 22:37:11 +08:00
|
|
|
$skins = array_map('basename', glob('skins/*', GLOB_ONLYDIR));
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2018-08-31 22:37:11 +08:00
|
|
|
if ( ! in_array($skin, $skins) ) {
|
|
|
|
Error("Invalid skin '$skin' setting to " . $skins[0]);
|
2016-10-20 23:51:42 +08:00
|
|
|
$skin = $skins[0];
|
2015-02-20 03:17:33 +08:00
|
|
|
}
|
|
|
|
|
2016-10-20 23:51:42 +08:00
|
|
|
if ( isset($_GET['css']) ) {
|
|
|
|
$css = $_GET['css'];
|
|
|
|
} elseif ( isset($_COOKIE['zmCSS']) ) {
|
|
|
|
$css = $_COOKIE['zmCSS'];
|
2018-08-31 22:37:11 +08:00
|
|
|
} elseif ( defined('ZM_CSS_DEFAULT') ) {
|
2016-10-20 23:51:42 +08:00
|
|
|
$css = ZM_CSS_DEFAULT;
|
|
|
|
} else {
|
|
|
|
$css = 'classic';
|
|
|
|
}
|
2014-11-27 00:26:29 +08:00
|
|
|
|
2018-08-31 22:37:11 +08:00
|
|
|
$css_skins = array_map('basename', glob('skins/'.$skin.'/css/*',GLOB_ONLYDIR));
|
|
|
|
if ( !in_array($css, $css_skins) ) {
|
|
|
|
Error("Invalid skin css '$css' setting to " . $css_skins[0]);
|
2016-10-20 23:51:42 +08:00
|
|
|
$css = $css_skins[0];
|
2015-02-20 03:17:33 +08:00
|
|
|
}
|
|
|
|
|
2018-08-31 22:37:11 +08:00
|
|
|
define('ZM_BASE_PATH', dirname($_SERVER['REQUEST_URI']));
|
|
|
|
define('ZM_SKIN_PATH', "skins/$skin");
|
|
|
|
define('ZM_SKIN_NAME', $skin);
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2008-07-23 17:57:11 +08:00
|
|
|
$skinBase = array(); // To allow for inheritance of skins
|
2018-08-31 22:37:11 +08:00
|
|
|
if ( !file_exists(ZM_SKIN_PATH) )
|
|
|
|
Fatal("Invalid skin '$skin'");
|
2008-07-23 17:57:11 +08:00
|
|
|
$skinBase[] = $skin;
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2016-12-09 03:25:29 +08:00
|
|
|
$currentCookieParams = session_get_cookie_params();
|
2017-10-30 22:37:08 +08:00
|
|
|
//Logger::Debug('Setting cookie parameters to lifetime('.$currentCookieParams['lifetime'].') path('.$currentCookieParams['path'].') domain ('.$currentCookieParams['domain'].') secure('.$currentCookieParams['secure'].') httpOnly(1)');
|
2016-12-09 03:25:29 +08:00
|
|
|
session_set_cookie_params(
|
2017-06-27 02:29:45 +08:00
|
|
|
$currentCookieParams['lifetime'],
|
|
|
|
$currentCookieParams['path'],
|
|
|
|
$currentCookieParams['domain'],
|
|
|
|
$currentCookieParams['secure'],
|
2016-12-09 04:20:43 +08:00
|
|
|
true
|
2016-12-09 03:25:29 +08:00
|
|
|
);
|
|
|
|
|
2018-08-31 22:37:11 +08:00
|
|
|
ini_set('session.name', 'ZMSESSID');
|
2008-07-14 21:54:50 +08:00
|
|
|
|
|
|
|
session_start();
|
|
|
|
|
2016-10-20 23:51:42 +08:00
|
|
|
if ( !isset($_SESSION['skin']) || isset($_REQUEST['skin']) || !isset($_COOKIE['zmSkin']) || $_COOKIE['zmSkin'] != $skin ) {
|
|
|
|
$_SESSION['skin'] = $skin;
|
2018-08-31 22:37:11 +08:00
|
|
|
setcookie('zmSkin', $skin, time()+3600*24*30*12*10);
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2015-05-12 04:22:14 +08:00
|
|
|
if ( !isset($_SESSION['css']) || isset($_REQUEST['css']) || !isset($_COOKIE['zmCSS']) || $_COOKIE['zmCSS'] != $css ) {
|
2016-10-20 23:51:42 +08:00
|
|
|
$_SESSION['css'] = $css;
|
2018-08-31 22:37:11 +08:00
|
|
|
setcookie('zmCSS', $css, time()+3600*24*30*12*10);
|
2014-11-27 00:26:29 +08:00
|
|
|
}
|
|
|
|
|
2016-10-20 23:51:42 +08:00
|
|
|
if ( ZM_OPT_USE_AUTH ) {
|
2018-08-31 22:37:11 +08:00
|
|
|
if ( isset($_SESSION['user']) ) {
|
2016-10-20 23:51:42 +08:00
|
|
|
$user = $_SESSION['user'];
|
|
|
|
} else {
|
2018-08-31 22:37:11 +08:00
|
|
|
unset($user);
|
2016-10-20 23:51:42 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$user = $defaultUser;
|
|
|
|
}
|
2018-04-15 10:26:47 +08:00
|
|
|
# Only one request can open the session file at a time, so let's close the session here to improve concurrency.
|
|
|
|
# Any file/page that sets session variables must re-open it.
|
|
|
|
session_write_close();
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2018-08-31 22:37:11 +08:00
|
|
|
require_once('includes/lang.php');
|
|
|
|
require_once('includes/functions.php');
|
|
|
|
require_once('includes/auth.php');
|
2016-10-21 01:38:12 +08:00
|
|
|
|
|
|
|
# Running is global but only do the daemonCheck if it is actually needed
|
|
|
|
$running = null;
|
2008-09-26 17:47:20 +08:00
|
|
|
|
2015-12-02 23:05:27 +08:00
|
|
|
# Add Cross domain access headers
|
|
|
|
CORSHeaders();
|
|
|
|
|
2015-10-13 04:16:22 +08:00
|
|
|
// Check for valid content dirs
|
2016-10-20 23:51:42 +08:00
|
|
|
if ( !is_writable(ZM_DIR_EVENTS) || !is_writable(ZM_DIR_IMAGES) ) {
|
2018-04-15 10:26:47 +08:00
|
|
|
Warning("Cannot write to content dirs('".ZM_DIR_EVENTS."','".ZM_DIR_IMAGES."'). Check that these exist and are owned by the web account user");
|
2015-10-13 04:16:22 +08:00
|
|
|
}
|
|
|
|
|
2017-04-05 22:05:21 +08:00
|
|
|
# Globals
|
|
|
|
$redirect = null;
|
|
|
|
$view = null;
|
2008-09-26 17:47:20 +08:00
|
|
|
if ( isset($_REQUEST['view']) )
|
2016-10-21 01:16:50 +08:00
|
|
|
$view = detaintPath($_REQUEST['view']);
|
2011-07-22 16:37:01 +08:00
|
|
|
|
2017-04-05 22:05:21 +08:00
|
|
|
$request = null;
|
2011-07-22 16:37:01 +08:00
|
|
|
if ( isset($_REQUEST['request']) )
|
2016-10-21 01:16:50 +08:00
|
|
|
$request = detaintPath($_REQUEST['request']);
|
2008-09-26 17:47:20 +08:00
|
|
|
|
2018-08-31 22:37:11 +08:00
|
|
|
foreach ( getSkinIncludes('skin.php') as $includeFile )
|
2016-10-20 23:51:42 +08:00
|
|
|
require_once $includeFile;
|
2014-01-04 07:33:01 +08:00
|
|
|
|
2018-02-01 03:58:01 +08:00
|
|
|
if ( ZM_OPT_USE_AUTH ) {
|
|
|
|
if ( ZM_AUTH_HASH_LOGINS ) {
|
|
|
|
if ( empty($user) && ! empty($_REQUEST['auth']) ) {
|
2018-08-31 22:37:11 +08:00
|
|
|
if ( $authUser = getAuthUser($_REQUEST['auth']) ) {
|
|
|
|
userLogin($authUser['Username'], $authUser['Password'], true);
|
2018-02-01 03:58:01 +08:00
|
|
|
}
|
|
|
|
}
|
2018-10-03 04:59:05 +08:00
|
|
|
} else if ( isset($_REQUEST['username']) and isset($_REQUEST['password']) ) {
|
|
|
|
userLogin($_REQUEST['username'], $_REQUEST['password'], false);
|
2018-02-01 03:58:01 +08:00
|
|
|
}
|
2018-08-31 22:37:11 +08:00
|
|
|
if ( !empty($user) ) {
|
2016-10-20 23:51:42 +08:00
|
|
|
// generate it once here, while session is open. Value will be cached in session and return when called later on
|
2018-08-31 22:37:11 +08:00
|
|
|
generateAuthHash(ZM_AUTH_HASH_IPS);
|
2016-10-20 23:51:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( isset($_REQUEST['action']) ) {
|
|
|
|
$action = detaintPath($_REQUEST['action']);
|
2014-12-12 22:38:54 +08:00
|
|
|
}
|
|
|
|
|
2017-03-29 06:52:31 +08:00
|
|
|
# The only variable we really need to set is action. The others are informal.
|
|
|
|
isset($view) || $view = NULL;
|
|
|
|
isset($request) || $request = NULL;
|
|
|
|
isset($action) || $action = NULL;
|
|
|
|
|
2018-08-31 22:37:11 +08:00
|
|
|
Logger::Debug("View: $view Request: $request Action: $action");
|
|
|
|
if (
|
|
|
|
ZM_ENABLE_CSRF_MAGIC &&
|
|
|
|
( $action != 'login' ) &&
|
|
|
|
( $view != 'view_video' ) &&
|
2018-08-31 23:58:17 +08:00
|
|
|
( $view != 'image' ) &&
|
2018-08-31 22:37:11 +08:00
|
|
|
( $request != 'control' ) &&
|
|
|
|
( $view != 'frames' ) &&
|
|
|
|
( $view != 'archive' )
|
|
|
|
) {
|
2017-06-20 22:52:16 +08:00
|
|
|
require_once( 'includes/csrf/csrf-magic.php' );
|
2017-11-29 03:50:21 +08:00
|
|
|
#Logger::Debug("Calling csrf_check with the following values: \$request = \"$request\", \$view = \"$view\", \$action = \"$action\"");
|
2017-06-20 22:52:16 +08:00
|
|
|
csrf_check();
|
2017-03-29 06:29:36 +08:00
|
|
|
}
|
|
|
|
|
2017-03-29 22:19:00 +08:00
|
|
|
# Need to include actions because it does auth
|
2018-08-31 22:37:11 +08:00
|
|
|
require_once('includes/actions.php');
|
2017-03-29 22:19:00 +08:00
|
|
|
|
|
|
|
# If I put this here, it protects all views and popups, but it has to go after actions.php because actions.php does the actual logging in.
|
2018-08-31 22:37:11 +08:00
|
|
|
if ( ZM_OPT_USE_AUTH and !isset($user) ) {
|
|
|
|
Logger::Debug('Redirecting to login');
|
2017-03-29 22:19:00 +08:00
|
|
|
$view = 'login';
|
2017-06-20 22:52:16 +08:00
|
|
|
$request = null;
|
2018-08-31 22:37:11 +08:00
|
|
|
} else if ( ZM_SHOW_PRIVACY && ($action != 'privacy') && ($view !='options') && (!$request) && canEdit('System') ) {
|
|
|
|
Logger::Debug('Redirecting to privacy');
|
2018-08-31 01:25:02 +08:00
|
|
|
$view = 'privacy';
|
|
|
|
$request = null;
|
|
|
|
}
|
2015-04-21 01:06:34 +08:00
|
|
|
|
2017-04-05 22:05:21 +08:00
|
|
|
if ( $redirect ) {
|
2018-01-29 06:31:00 +08:00
|
|
|
header('Location: '.$redirect);
|
2017-04-05 22:05:21 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-27 01:56:38 +08:00
|
|
|
if ( $request ) {
|
2018-08-31 22:37:11 +08:00
|
|
|
foreach ( getSkinIncludes('ajax/'.$request.'.php', true, true) as $includeFile ) {
|
|
|
|
if ( !file_exists($includeFile) )
|
|
|
|
Fatal("Request '$request' does not exist");
|
2016-10-20 23:51:42 +08:00
|
|
|
require_once $includeFile;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else {
|
2018-08-31 22:37:11 +08:00
|
|
|
if ( $includeFiles = getSkinIncludes('views/'.$view.'.php', true, true) ) {
|
2016-10-20 23:51:42 +08:00
|
|
|
foreach ( $includeFiles as $includeFile ) {
|
2018-08-31 22:37:11 +08:00
|
|
|
if ( !file_exists($includeFile) )
|
|
|
|
Fatal("View '$view' does not exist");
|
2016-10-20 23:51:42 +08:00
|
|
|
require_once $includeFile;
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
2016-10-20 23:51:42 +08:00
|
|
|
// If the view overrides $view to 'error', and the user is not logged in, then the
|
|
|
|
// issue is probably resolvable by logging in, so provide the opportunity to do so.
|
|
|
|
// The login view should handle redirecting to the correct location afterward.
|
|
|
|
if ( $view == 'error' && !isset($user) ) {
|
|
|
|
$view = 'login';
|
2018-08-31 22:37:11 +08:00
|
|
|
foreach ( getSkinIncludes('views/login.php', true, true) as $includeFile )
|
2016-10-20 23:51:42 +08:00
|
|
|
require_once $includeFile;
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
2016-10-20 23:51:42 +08:00
|
|
|
}
|
|
|
|
// If the view is missing or the view still returned error with the user logged in,
|
|
|
|
// then it is not recoverable.
|
|
|
|
if ( !$includeFiles || $view == 'error' ) {
|
2018-08-31 22:37:11 +08:00
|
|
|
foreach ( getSkinIncludes('views/error.php', true, true) as $includeFile )
|
2016-10-20 23:51:42 +08:00
|
|
|
require_once $includeFile;
|
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
?>
|