2008-07-14 13:54:50 +00:00
|
|
|
<?php
|
|
|
|
//
|
|
|
|
// ZoneMinder main web interface file, $Date$, $Revision$
|
2008-07-25 09:48:16 +00:00
|
|
|
// Copyright (C) 2001-2008 Philip Coombes
|
2008-07-14 13:54:50 +00: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 15:23:16 +00:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2008-07-14 13:54:50 +00:00
|
|
|
//
|
|
|
|
|
2022-10-17 21:43:09 +00:00
|
|
|
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
|
2008-07-14 13:54:50 +00:00
|
|
|
|
|
|
|
$debug = false;
|
2016-10-20 15:51:42 +00:00
|
|
|
if ( $debug ) {
|
|
|
|
// Use these for debugging, though not both at once!
|
2018-08-31 14:37:11 +00:00
|
|
|
phpinfo(INFO_VARIABLES);
|
2008-07-14 13:54:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Use new style autoglobals where possible
|
2018-08-31 14:37:11 +00:00
|
|
|
if ( version_compare(phpversion(), '4.1.0', '<') ) {
|
2016-10-20 15:51:42 +00:00
|
|
|
$_SESSION = &$HTTP_SESSION_VARS;
|
|
|
|
$_SERVER = &$HTTP_SERVER_VARS;
|
2008-07-14 13:54:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Useful debugging lines for mobile devices
|
2020-05-01 17:17:39 +00:00
|
|
|
if ( false ) {
|
2016-10-20 15:51:42 +00:00
|
|
|
ob_start();
|
2018-08-31 14:37:11 +00:00
|
|
|
phpinfo(INFO_VARIABLES);
|
2019-03-01 22:27:08 +00:00
|
|
|
$fp = fopen('/tmp/env.html', 'w+');
|
2018-08-31 14:37:11 +00:00
|
|
|
fwrite($fp, ob_get_contents());
|
|
|
|
fclose($fp);
|
2016-10-20 15:51:42 +00:00
|
|
|
ob_end_clean();
|
2017-11-24 20:38:07 +00:00
|
|
|
}
|
2008-07-14 13:54:50 +00:00
|
|
|
|
2018-08-31 14:37:11 +00:00
|
|
|
require_once('includes/config.php');
|
2019-01-30 16:05:36 +00:00
|
|
|
require_once('includes/session.php');
|
2018-08-31 14:37:11 +00:00
|
|
|
require_once('includes/logger.php');
|
|
|
|
require_once('includes/Server.php');
|
2015-01-04 16:50:24 +00:00
|
|
|
|
2020-06-24 02:20:07 +00:00
|
|
|
// Useful debugging lines for mobile devices
|
2020-08-17 22:30:44 +00:00
|
|
|
if ( 0 and ZM\Logger::fetch()->debugOn() ) {
|
2020-06-24 02:20:07 +00:00
|
|
|
ob_start();
|
|
|
|
phpinfo(INFO_VARIABLES);
|
2020-10-14 14:39:25 +00:00
|
|
|
ZM\Debug(ob_get_contents());
|
2020-06-24 02:20:07 +00:00
|
|
|
ob_end_clean();
|
|
|
|
}
|
|
|
|
|
2020-04-10 15:14:09 +00:00
|
|
|
global $Servers;
|
2020-03-04 16:03:30 +00:00
|
|
|
$Servers = ZM\Server::find();
|
|
|
|
|
2018-07-12 15:38:58 +00:00
|
|
|
if (
|
|
|
|
(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
|
|
|
|
or
|
2018-07-12 19:04:54 +00:00
|
|
|
(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'))
|
2018-07-12 15:38:58 +00:00
|
|
|
) {
|
2016-10-20 15:51:42 +00:00
|
|
|
$protocol = 'https';
|
|
|
|
} else {
|
|
|
|
$protocol = 'http';
|
2008-07-14 13:54:50 +00:00
|
|
|
}
|
2018-08-31 14:37:11 +00:00
|
|
|
define('ZM_BASE_PROTOCOL', $protocol);
|
2015-10-24 18:04:54 +00: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 14:37:11 +00:00
|
|
|
define('ZM_BASE_URL', '');
|
2008-07-14 13:54:50 +00:00
|
|
|
|
2019-01-15 14:05:11 +00:00
|
|
|
require_once('includes/functions.php');
|
2019-03-01 22:27:08 +00:00
|
|
|
if ( $_SERVER['REQUEST_METHOD'] == 'OPTIONS' ) {
|
2020-10-14 14:39:25 +00:00
|
|
|
ZM\Debug('OPTIONS Method, only doing CORS');
|
2019-03-01 22:27:08 +00:00
|
|
|
# Add Cross domain access headers
|
|
|
|
CORSHeaders();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-20 15:51:42 +00:00
|
|
|
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-12 19:43:24 +00:00
|
|
|
}
|
|
|
|
|
2021-03-21 13:19:21 +00:00
|
|
|
if (!is_dir('skins/'.$skin) ) {
|
2019-09-17 16:07:10 +00:00
|
|
|
$skins = array_map('basename', glob('skins/*', GLOB_ONLYDIR));
|
2008-07-14 13:54:50 +00:00
|
|
|
|
2019-09-17 16:07:10 +00:00
|
|
|
if ( !in_array($skin, $skins) ) {
|
|
|
|
ZM\Error("Invalid skin '$skin' setting to ".$skins[0]);
|
|
|
|
$skin = $skins[0];
|
|
|
|
}
|
2015-02-19 19:17:33 +00:00
|
|
|
}
|
2020-08-17 00:08:14 +00:00
|
|
|
global $css;
|
2016-10-20 15:51:42 +00:00
|
|
|
if ( isset($_GET['css']) ) {
|
|
|
|
$css = $_GET['css'];
|
2019-09-17 16:07:10 +00:00
|
|
|
} else if ( isset($_COOKIE['zmCSS']) ) {
|
2016-10-20 15:51:42 +00:00
|
|
|
$css = $_COOKIE['zmCSS'];
|
2019-09-17 16:07:10 +00:00
|
|
|
} else if ( defined('ZM_CSS_DEFAULT') ) {
|
2016-10-20 15:51:42 +00:00
|
|
|
$css = ZM_CSS_DEFAULT;
|
|
|
|
} else {
|
|
|
|
$css = 'classic';
|
|
|
|
}
|
2014-11-26 16:26:29 +00:00
|
|
|
|
2021-03-21 13:19:21 +00:00
|
|
|
if (!is_dir("skins/$skin/css/$css")) {
|
2019-09-17 16:07:10 +00:00
|
|
|
$css_skins = array_map('basename', glob('skins/'.$skin.'/css/*', GLOB_ONLYDIR));
|
2021-03-21 13:19:21 +00:00
|
|
|
if (count($css_skins)) {
|
|
|
|
if (!in_array($css, $css_skins)) {
|
2019-09-17 16:07:10 +00:00
|
|
|
ZM\Error("Invalid skin css '$css' setting to " . $css_skins[0]);
|
|
|
|
$css = $css_skins[0];
|
|
|
|
} else {
|
|
|
|
$css = '';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ZM\Error("No css options found at skins/$skin/css");
|
|
|
|
$css = '';
|
|
|
|
}
|
2015-02-19 19:17:33 +00:00
|
|
|
}
|
|
|
|
|
2018-08-31 14:37:11 +00:00
|
|
|
define('ZM_BASE_PATH', dirname($_SERVER['REQUEST_URI']));
|
|
|
|
define('ZM_SKIN_PATH', "skins/$skin");
|
|
|
|
define('ZM_SKIN_NAME', $skin);
|
2008-07-14 13:54:50 +00:00
|
|
|
|
2008-07-23 09:57:11 +00:00
|
|
|
$skinBase = array(); // To allow for inheritance of skins
|
2021-03-21 13:19:21 +00:00
|
|
|
if (!file_exists(ZM_SKIN_PATH))
|
2019-09-17 16:07:10 +00:00
|
|
|
ZM\Fatal("Invalid skin '$skin'");
|
2008-07-23 09:57:11 +00:00
|
|
|
$skinBase[] = $skin;
|
2008-07-14 13:54:50 +00:00
|
|
|
|
2019-01-30 16:05:36 +00:00
|
|
|
zm_session_start();
|
2019-02-05 16:45:58 +00:00
|
|
|
if (
|
|
|
|
!isset($_SESSION['skin']) ||
|
|
|
|
isset($_REQUEST['skin']) ||
|
|
|
|
!isset($_COOKIE['zmSkin']) ||
|
2019-09-17 16:07:10 +00:00
|
|
|
($_COOKIE['zmSkin'] != $skin)
|
2019-02-05 16:45:58 +00:00
|
|
|
) {
|
2016-10-20 15:51:42 +00:00
|
|
|
$_SESSION['skin'] = $skin;
|
2022-01-20 14:46:38 +00:00
|
|
|
zm_setcookie('zmSkin', $skin);
|
2008-07-14 13:54:50 +00:00
|
|
|
}
|
|
|
|
|
2019-02-05 16:45:58 +00:00
|
|
|
if (
|
|
|
|
!isset($_SESSION['css']) ||
|
|
|
|
isset($_REQUEST['css']) ||
|
|
|
|
!isset($_COOKIE['zmCSS']) ||
|
2019-09-17 16:07:10 +00:00
|
|
|
($_COOKIE['zmCSS'] != $css)
|
2019-02-05 16:45:58 +00:00
|
|
|
) {
|
2016-10-20 15:51:42 +00:00
|
|
|
$_SESSION['css'] = $css;
|
2022-01-20 14:46:38 +00:00
|
|
|
zm_setcookie('zmCSS', $css);
|
2014-11-26 16:26:29 +00:00
|
|
|
}
|
|
|
|
|
2015-12-02 15:05:27 +00:00
|
|
|
# Add Cross domain access headers
|
|
|
|
CORSHeaders();
|
|
|
|
|
2015-10-12 20:16:22 +00:00
|
|
|
// Check for valid content dirs
|
2018-12-29 14:52:58 +00:00
|
|
|
if ( !is_writable(ZM_DIR_EVENTS) ) {
|
2019-03-19 13:13:56 +00:00
|
|
|
ZM\Warning("Cannot write to event folder ".ZM_DIR_EVENTS.". Check that it exists and is owned by the web account user.");
|
2015-10-12 20:16:22 +00:00
|
|
|
}
|
|
|
|
|
2017-04-05 14:05:21 +00:00
|
|
|
# Globals
|
2022-10-17 16:35:00 +00:00
|
|
|
# Running is global but only do the daemonCheck if it is actually needed
|
|
|
|
$running = null;
|
2019-01-23 16:18:30 +00:00
|
|
|
$action = null;
|
2018-11-07 17:33:54 +00:00
|
|
|
$error_message = null;
|
2017-04-05 14:05:21 +00:00
|
|
|
$redirect = null;
|
2022-10-17 16:35:00 +00:00
|
|
|
$view = isset($_REQUEST['view']) ? detaintPath($_REQUEST['view']) : null;
|
2019-08-20 13:46:53 +00:00
|
|
|
$user = null;
|
2022-10-17 16:35:00 +00:00
|
|
|
$request = isset($_REQUEST['request']) ? detaintPath($_REQUEST['request']) : null;
|
2008-09-26 09:47:20 +00:00
|
|
|
|
2018-10-09 14:05:50 +00:00
|
|
|
require_once('includes/auth.php');
|
2020-02-27 22:42:02 +00:00
|
|
|
|
2020-01-20 16:02:43 +00: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.
|
2019-09-04 21:53:59 +00:00
|
|
|
session_write_close();
|
2016-10-20 15:51:42 +00:00
|
|
|
|
2021-04-12 17:42:24 +00:00
|
|
|
require_once('includes/Storage.php');
|
|
|
|
require_once('includes/Event.php');
|
|
|
|
require_once('includes/Group.php');
|
|
|
|
require_once('includes/Monitor.php');
|
|
|
|
|
2020-02-27 22:42:02 +00:00
|
|
|
// lang references $user[Language] so must come after auth
|
|
|
|
require_once('includes/lang.php');
|
|
|
|
|
2019-02-05 17:32:24 +00:00
|
|
|
foreach ( getSkinIncludes('skin.php') as $includeFile ) {
|
|
|
|
require_once $includeFile;
|
|
|
|
}
|
|
|
|
|
2022-10-03 19:49:48 +00:00
|
|
|
if (isset($_POST['action'])) {
|
|
|
|
# Actions can only be performed on POST because we don't check csrf on GETs.
|
|
|
|
$action = detaintPath($_POST['action']);
|
|
|
|
} else if (isset($_REQUEST['action'])) {
|
|
|
|
ZM\Error('actions can no longer be performed without POST.');
|
|
|
|
}
|
2019-01-23 16:18:30 +00:00
|
|
|
|
2017-03-28 22:52:31 +00: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;
|
|
|
|
|
2019-08-15 19:16:20 +00:00
|
|
|
if ( (!$view and !$request) or ($view == 'console') ) {
|
|
|
|
check_timezone();
|
|
|
|
}
|
|
|
|
|
2020-10-14 14:39:25 +00:00
|
|
|
ZM\Debug("View: $view Request: $request Action: $action User: " . ( isset($user) ? $user['Username'] : 'none' ));
|
2018-08-31 14:37:11 +00:00
|
|
|
if (
|
|
|
|
ZM_ENABLE_CSRF_MAGIC &&
|
|
|
|
( $action != 'login' ) &&
|
2020-09-02 22:11:53 +00:00
|
|
|
( $view != 'view_video' ) && // only video no html
|
|
|
|
( $view != 'image' ) && // view=image doesn't return html, just image data.
|
2018-08-31 14:37:11 +00:00
|
|
|
( $request != 'control' ) &&
|
2020-09-02 22:11:53 +00:00
|
|
|
//( $view != 'frames' ) && // big html can overflow ob
|
|
|
|
( $view != 'archive' ) // returns data
|
2021-01-11 22:08:44 +00:00
|
|
|
&& ( (!isset($_SERVER['CONTENT_TYPE']) or ($_SERVER['CONTENT_TYPE'] != 'application/csp-report')) )
|
2018-08-31 14:37:11 +00:00
|
|
|
) {
|
2019-08-20 13:46:53 +00:00
|
|
|
require_once('includes/csrf/csrf-magic.php');
|
2020-10-14 14:39:25 +00:00
|
|
|
#ZM\Debug("Calling csrf_check with the following values: \$request = \"$request\", \$view = \"$view\", \$action = \"$action\"");
|
2017-06-20 14:52:16 +00:00
|
|
|
csrf_check();
|
2017-03-28 22:29:36 +00:00
|
|
|
}
|
|
|
|
|
2017-03-29 14:19:00 +00:00
|
|
|
# Need to include actions because it does auth
|
2022-09-27 14:49:50 +00:00
|
|
|
if ( $action and $view and !$request ) {
|
2019-01-04 14:26:34 +00:00
|
|
|
if ( file_exists('includes/actions/'.$view.'.php') ) {
|
|
|
|
require_once('includes/actions/'.$view.'.php');
|
|
|
|
} else {
|
2019-03-18 15:24:28 +00:00
|
|
|
ZM\Warning("No includes/actions/$view.php for action $action");
|
2019-01-04 14:26:34 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-29 14:19:00 +00: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.
|
2019-08-20 13:46:53 +00:00
|
|
|
if ( ZM_OPT_USE_AUTH and (!isset($user)) and ($view != 'login') and ($view != 'none') ) {
|
2021-03-13 17:11:55 +00:00
|
|
|
if ($request) {
|
|
|
|
# requests only return json
|
2019-03-01 22:27:08 +00:00
|
|
|
header('HTTP/1.1 401 Unauthorized');
|
|
|
|
exit;
|
|
|
|
}
|
2019-02-05 17:32:24 +00:00
|
|
|
$view = 'none';
|
|
|
|
$redirect = ZM_BASE_URL.$_SERVER['PHP_SELF'].'?view=login';
|
2021-03-13 17:11:55 +00:00
|
|
|
zm_session_start();
|
|
|
|
$_SESSION['postLoginQuery'] = $_SERVER['QUERY_STRING'];
|
|
|
|
session_write_close();
|
2019-02-08 14:55:32 +00:00
|
|
|
} else if ( ZM_SHOW_PRIVACY && ($view != 'privacy') && ($view != 'options') && (!$request) && canEdit('System') ) {
|
2019-02-05 17:32:24 +00:00
|
|
|
$view = 'none';
|
|
|
|
$redirect = ZM_BASE_URL.$_SERVER['PHP_SELF'].'?view=privacy';
|
2018-08-30 17:25:02 +00:00
|
|
|
$request = null;
|
|
|
|
}
|
2015-04-20 17:06:34 +00:00
|
|
|
|
2022-10-17 16:35:00 +00:00
|
|
|
if ( isset($_REQUEST['redirect']) ) {
|
2021-03-21 13:19:21 +00:00
|
|
|
$redirect = '?view='.detaintPath($_REQUEST['redirect']);
|
2022-10-17 16:35:00 +00:00
|
|
|
}
|
2019-01-18 14:51:06 +00:00
|
|
|
|
2022-10-17 16:35:00 +00:00
|
|
|
if ($redirect) {
|
2020-10-14 14:39:25 +00:00
|
|
|
ZM\Debug("Redirecting to $redirect");
|
2018-01-28 22:31:00 +00:00
|
|
|
header('Location: '.$redirect);
|
2017-04-05 14:05:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-26 17:56:38 +00:00
|
|
|
if ( $request ) {
|
2018-08-31 14:37:11 +00:00
|
|
|
foreach ( getSkinIncludes('ajax/'.$request.'.php', true, true) as $includeFile ) {
|
|
|
|
if ( !file_exists($includeFile) )
|
2019-03-18 15:24:28 +00:00
|
|
|
ZM\Fatal("Request '$request' does not exist");
|
2016-10-20 15:51:42 +00:00
|
|
|
require_once $includeFile;
|
|
|
|
}
|
|
|
|
return;
|
2019-01-23 16:18:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-18 14:52:45 +00:00
|
|
|
# Add CSP Headers
|
|
|
|
$cspNonce = bin2hex(zm_random_bytes(16));
|
2019-01-23 16:18:30 +00:00
|
|
|
if ( $includeFiles = getSkinIncludes('views/'.$view.'.php', true, true) ) {
|
2020-09-02 17:58:24 +00:00
|
|
|
ob_start();
|
2021-08-18 14:52:45 +00:00
|
|
|
CSPHeaders($view, $cspNonce);
|
2019-01-23 16:18:30 +00:00
|
|
|
foreach ( $includeFiles as $includeFile ) {
|
2022-10-17 16:35:00 +00:00
|
|
|
if (!file_exists($includeFile))
|
2019-03-18 15:24:28 +00:00
|
|
|
ZM\Fatal("View '$view' does not exist");
|
2019-01-23 16:18:30 +00:00
|
|
|
require_once $includeFile;
|
2016-10-20 15:51:42 +00:00
|
|
|
}
|
2019-01-23 16:18:30 +00: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';
|
|
|
|
foreach ( getSkinIncludes('views/login.php', true, true) as $includeFile )
|
2016-10-20 15:51:42 +00:00
|
|
|
require_once $includeFile;
|
|
|
|
}
|
2021-08-18 14:52:45 +00:00
|
|
|
while (ob_get_level() > 0) ob_end_flush();
|
2022-10-17 16:35:00 +00:00
|
|
|
} # end if include files for view
|
2019-01-23 16:18:30 +00: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' ) {
|
|
|
|
foreach ( getSkinIncludes('views/error.php', true, true) as $includeFile )
|
|
|
|
require_once $includeFile;
|
|
|
|
}
|
2008-07-14 13:54:50 +00:00
|
|
|
?>
|