Merge pull request #1384 from owncloud/upgrade_fix

Check for upgrade/maintance mode before trying to load an app
This commit is contained in:
Bart Visscher 2013-02-01 07:12:06 -08:00
commit 2488a495c6
1 changed files with 53 additions and 70 deletions

View File

@ -27,8 +27,7 @@ require_once 'public/constants.php';
* No, we can not put this class in its own file because it is used by * No, we can not put this class in its own file because it is used by
* OC_autoload! * OC_autoload!
*/ */
class OC class OC {
{
/** /**
* Associative array for autoloading. classname => filename * Associative array for autoloading. classname => filename
*/ */
@ -78,13 +77,12 @@ class OC
/** /**
* SPL autoload * SPL autoload
*/ */
public static function autoload($className) public static function autoload($className) {
{
if (array_key_exists($className, OC::$CLASSPATH)) { if (array_key_exists($className, OC::$CLASSPATH)) {
$path = OC::$CLASSPATH[$className]; $path = OC::$CLASSPATH[$className];
/** @TODO: Remove this when necessary /** @TODO: Remove this when necessary
Remove "apps/" from inclusion path for smooth migration to mutli app dir Remove "apps/" from inclusion path for smooth migration to mutli app dir
*/ */
if (strpos($path, 'apps/') === 0) { if (strpos($path, 'apps/') === 0) {
OC_Log::write('core', 'include path for class "' . $className . '" starts with "apps/"', OC_Log::DEBUG); OC_Log::write('core', 'include path for class "' . $className . '" starts with "apps/"', OC_Log::DEBUG);
$path = str_replace('apps/', '', $path); $path = str_replace('apps/', '', $path);
@ -96,7 +94,7 @@ class OC
} elseif (strpos($className, 'OCP\\') === 0) { } elseif (strpos($className, 'OCP\\') === 0) {
$path = 'public/' . strtolower(str_replace('\\', '/', substr($className, 3)) . '.php'); $path = 'public/' . strtolower(str_replace('\\', '/', substr($className, 3)) . '.php');
} elseif (strpos($className, 'OCA\\') === 0) { } elseif (strpos($className, 'OCA\\') === 0) {
foreach(self::$APPSROOTS as $appDir) { foreach (self::$APPSROOTS as $appDir) {
$path = $appDir['path'] . '/' . strtolower(str_replace('\\', '/', substr($className, 3)) . '.php'); $path = $appDir['path'] . '/' . strtolower(str_replace('\\', '/', substr($className, 3)) . '.php');
$fullPath = stream_resolve_include_path($path); $fullPath = stream_resolve_include_path($path);
if (file_exists($fullPath)) { if (file_exists($fullPath)) {
@ -124,8 +122,7 @@ class OC
return false; return false;
} }
public static function initPaths() public static function initPaths() {
{
// calculate the root directories // calculate the root directories
OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4));
OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT)));
@ -150,7 +147,7 @@ class OC
// ensure we can find OC_Config // ensure we can find OC_Config
set_include_path( set_include_path(
OC::$SERVERROOT . '/lib' . PATH_SEPARATOR . OC::$SERVERROOT . '/lib' . PATH_SEPARATOR .
get_include_path() get_include_path()
); );
// search the 3rdparty folder // search the 3rdparty folder
@ -188,17 +185,18 @@ class OC
exit; exit;
} }
$paths = array(); $paths = array();
foreach (OC::$APPSROOTS as $path) foreach (OC::$APPSROOTS as $path) {
$paths[] = $path['path']; $paths[] = $path['path'];
}
// set the right include path // set the right include path
set_include_path( set_include_path(
OC::$SERVERROOT . '/lib' . PATH_SEPARATOR . OC::$SERVERROOT . '/lib' . PATH_SEPARATOR .
OC::$SERVERROOT . '/config' . PATH_SEPARATOR . OC::$SERVERROOT . '/config' . PATH_SEPARATOR .
OC::$THIRDPARTYROOT . '/3rdparty' . PATH_SEPARATOR . OC::$THIRDPARTYROOT . '/3rdparty' . PATH_SEPARATOR .
implode($paths, PATH_SEPARATOR) . PATH_SEPARATOR . implode($paths, PATH_SEPARATOR) . PATH_SEPARATOR .
get_include_path() . PATH_SEPARATOR . get_include_path() . PATH_SEPARATOR .
OC::$SERVERROOT OC::$SERVERROOT
); );
} }
@ -211,8 +209,7 @@ class OC
} }
} }
public static function checkInstalled() public static function checkInstalled() {
{
// Redirect to installer if not installed // Redirect to installer if not installed
if (!OC_Config::getValue('installed', false) && OC::$SUBURI != '/index.php') { if (!OC_Config::getValue('installed', false) && OC::$SUBURI != '/index.php') {
if (!OC::$CLI) { if (!OC::$CLI) {
@ -223,8 +220,7 @@ class OC
} }
} }
public static function checkSSL() public static function checkSSL() {
{
// redirect to https site if configured // redirect to https site if configured
if (OC_Config::getValue("forcessl", false)) { if (OC_Config::getValue("forcessl", false)) {
header('Strict-Transport-Security: max-age=31536000'); header('Strict-Transport-Security: max-age=31536000');
@ -274,8 +270,7 @@ class OC
} }
} }
public static function initTemplateEngine() public static function initTemplateEngine() {
{
// Add the stuff we need always // Add the stuff we need always
OC_Util::addScript("jquery-1.7.2.min"); OC_Util::addScript("jquery-1.7.2.min");
OC_Util::addScript("jquery-ui-1.10.0.custom"); OC_Util::addScript("jquery-ui-1.10.0.custom");
@ -297,8 +292,7 @@ class OC
OC_Util::addScript("oc-requesttoken"); OC_Util::addScript("oc-requesttoken");
} }
public static function initSession() public static function initSession() {
{
// prevents javascript from accessing php session cookies // prevents javascript from accessing php session cookies
ini_set('session.cookie_httponly', '1;'); ini_set('session.cookie_httponly', '1;');
@ -328,8 +322,7 @@ class OC
$_SESSION['LAST_ACTIVITY'] = time(); $_SESSION['LAST_ACTIVITY'] = time();
} }
public static function getRouter() public static function getRouter() {
{
if (!isset(OC::$router)) { if (!isset(OC::$router)) {
OC::$router = new OC_Router(); OC::$router = new OC_Router();
OC::$router->loadRoutes(); OC::$router->loadRoutes();
@ -339,19 +332,17 @@ class OC
} }
public static function loadAppClassPaths() public static function loadAppClassPaths() {
{ foreach (OC_APP::getEnabledApps() as $app) {
foreach(OC_APP::getEnabledApps() as $app) { $file = OC_App::getAppPath($app) . '/appinfo/classpath.php';
$file = OC_App::getAppPath($app).'/appinfo/classpath.php'; if (file_exists($file)) {
if(file_exists($file)) {
require_once $file; require_once $file;
} }
} }
} }
public static function init() public static function init() {
{
// register autoloader // register autoloader
spl_autoload_register(array('OC', 'autoload')); spl_autoload_register(array('OC', 'autoload'));
setlocale(LC_ALL, 'en_US.UTF-8'); setlocale(LC_ALL, 'en_US.UTF-8');
@ -516,8 +507,7 @@ class OC
/** /**
* register hooks for the cache * register hooks for the cache
*/ */
public static function registerCacheHooks() public static function registerCacheHooks() {
{
// register cache cleanup jobs // register cache cleanup jobs
OC_BackgroundJob_RegularTask::register('OC_Cache_FileGlobal', 'gc'); OC_BackgroundJob_RegularTask::register('OC_Cache_FileGlobal', 'gc');
OC_Hook::connect('OC_User', 'post_login', 'OC_Cache_File', 'loginListener'); OC_Hook::connect('OC_User', 'post_login', 'OC_Cache_File', 'loginListener');
@ -526,8 +516,7 @@ class OC
/** /**
* register hooks for the filesystem * register hooks for the filesystem
*/ */
public static function registerFilesystemHooks() public static function registerFilesystemHooks() {
{
// Check for blacklisted files // Check for blacklisted files
OC_Hook::connect('OC_Filesystem', 'write', 'OC_Filesystem', 'isBlacklisted'); OC_Hook::connect('OC_Filesystem', 'write', 'OC_Filesystem', 'isBlacklisted');
OC_Hook::connect('OC_Filesystem', 'rename', 'OC_Filesystem', 'isBlacklisted'); OC_Hook::connect('OC_Filesystem', 'rename', 'OC_Filesystem', 'isBlacklisted');
@ -536,8 +525,7 @@ class OC
/** /**
* register hooks for sharing * register hooks for sharing
*/ */
public static function registerShareHooks() public static function registerShareHooks() {
{
OC_Hook::connect('OC_User', 'post_deleteUser', 'OCP\Share', 'post_deleteUser'); OC_Hook::connect('OC_User', 'post_deleteUser', 'OCP\Share', 'post_deleteUser');
OC_Hook::connect('OC_User', 'post_addToGroup', 'OCP\Share', 'post_addToGroup'); OC_Hook::connect('OC_User', 'post_addToGroup', 'OCP\Share', 'post_addToGroup');
OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OCP\Share', 'post_removeFromGroup'); OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OCP\Share', 'post_removeFromGroup');
@ -547,12 +535,22 @@ class OC
/** /**
* @brief Handle the request * @brief Handle the request
*/ */
public static function handleRequest() public static function handleRequest() {
{
// load all the classpaths from the enabled apps so they are available // load all the classpaths from the enabled apps so they are available
// in the routing files of each app // in the routing files of each app
OC::loadAppClassPaths(); OC::loadAppClassPaths();
// Check if ownCloud is installed or in maintenance (update) mode
if (!OC_Config::getValue('installed', false)) {
require_once 'core/setup.php';
exit();
}
$request = OC_Request::getPathInfo();
if(substr($request, -3) !== '.js'){// we need these files during the upgrade
self::checkMaintenanceMode();
self::checkUpgrade();
}
try { try {
OC::getRouter()->match(OC_Request::getPathInfo()); OC::getRouter()->match(OC_Request::getPathInfo());
return; return;
@ -562,6 +560,7 @@ class OC
OC_Response::setStatus(405); OC_Response::setStatus(405);
return; return;
} }
$app = OC::$REQUESTEDAPP; $app = OC::$REQUESTEDAPP;
$file = OC::$REQUESTEDFILE; $file = OC::$REQUESTEDFILE;
$param = array('app' => $app, 'file' => $file); $param = array('app' => $app, 'file' => $file);
@ -571,14 +570,6 @@ class OC
return; return;
} }
// Check if ownCloud is installed or in maintenance (update) mode
if (!OC_Config::getValue('installed', false)) {
require_once 'core/setup.php';
exit();
}
self::checkMaintenanceMode();
self::checkUpgrade();
// Handle redirect URL for logged in users // Handle redirect URL for logged in users
if (isset($_REQUEST['redirect_url']) && OC_User::isLoggedIn()) { if (isset($_REQUEST['redirect_url']) && OC_User::isLoggedIn()) {
$location = OC_Helper::makeURLAbsolute(urldecode($_REQUEST['redirect_url'])); $location = OC_Helper::makeURLAbsolute(urldecode($_REQUEST['redirect_url']));
@ -608,7 +599,7 @@ class OC
$file_ext = substr($param['file'], -3); $file_ext = substr($param['file'], -3);
if ($file_ext != 'php' if ($file_ext != 'php'
|| !self::loadAppScriptFile($param) || !self::loadAppScriptFile($param)
) { ) {
header('HTTP/1.0 404 Not Found'); header('HTTP/1.0 404 Not Found');
} }
} }
@ -618,8 +609,7 @@ class OC
self::handleLogin(); self::handleLogin();
} }
public static function loadAppScriptFile($param) public static function loadAppScriptFile($param) {
{
OC_App::loadApps(); OC_App::loadApps();
$app = $param['app']; $app = $param['app'];
$file = $param['file']; $file = $param['file'];
@ -633,8 +623,7 @@ class OC
return false; return false;
} }
public static function loadCSSFile($param) public static function loadCSSFile($param) {
{
$app = $param['app']; $app = $param['app'];
$file = $param['file']; $file = $param['file'];
$app_path = OC_App::getAppPath($app); $app_path = OC_App::getAppPath($app);
@ -647,27 +636,25 @@ class OC
} }
} }
protected static function handleLogin() protected static function handleLogin() {
{
OC_App::loadApps(array('prelogin')); OC_App::loadApps(array('prelogin'));
$error = array(); $error = array();
// remember was checked after last login // remember was checked after last login
if (OC::tryRememberLogin()) { if (OC::tryRememberLogin()) {
$error[] = 'invalidcookie'; $error[] = 'invalidcookie';
// Someone wants to log in : // Someone wants to log in :
} elseif (OC::tryFormLogin()) { } elseif (OC::tryFormLogin()) {
$error[] = 'invalidpassword'; $error[] = 'invalidpassword';
// The user is already authenticated using Apaches AuthType Basic... very usable in combination with LDAP // The user is already authenticated using Apaches AuthType Basic... very usable in combination with LDAP
} elseif (OC::tryBasicAuthLogin()) { } elseif (OC::tryBasicAuthLogin()) {
$error[] = 'invalidpassword'; $error[] = 'invalidpassword';
} }
OC_Util::displayLoginPage(array_unique($error)); OC_Util::displayLoginPage(array_unique($error));
} }
protected static function cleanupLoginTokens($user) protected static function cleanupLoginTokens($user) {
{
$cutoff = time() - OC_Config::getValue('remember_login_cookie_lifetime', 60 * 60 * 24 * 15); $cutoff = time() - OC_Config::getValue('remember_login_cookie_lifetime', 60 * 60 * 24 * 15);
$tokens = OC_Preferences::getKeys($user, 'login_token'); $tokens = OC_Preferences::getKeys($user, 'login_token');
foreach ($tokens as $token) { foreach ($tokens as $token) {
@ -678,13 +665,12 @@ class OC
} }
} }
protected static function tryRememberLogin() protected static function tryRememberLogin() {
{
if (!isset($_COOKIE["oc_remember_login"]) if (!isset($_COOKIE["oc_remember_login"])
|| !isset($_COOKIE["oc_token"]) || !isset($_COOKIE["oc_token"])
|| !isset($_COOKIE["oc_username"]) || !isset($_COOKIE["oc_username"])
|| !$_COOKIE["oc_remember_login"] || !$_COOKIE["oc_remember_login"]
) { ) {
return false; return false;
} }
OC_App::loadApps(array('authentication')); OC_App::loadApps(array('authentication'));
@ -719,8 +705,7 @@ class OC
return true; return true;
} }
protected static function tryFormLogin() protected static function tryFormLogin() {
{
if (!isset($_POST["user"]) || !isset($_POST['password'])) { if (!isset($_POST["user"]) || !isset($_POST['password'])) {
return false; return false;
} }
@ -753,11 +738,10 @@ class OC
return true; return true;
} }
protected static function tryBasicAuthLogin() protected static function tryBasicAuthLogin() {
{
if (!isset($_SERVER["PHP_AUTH_USER"]) if (!isset($_SERVER["PHP_AUTH_USER"])
|| !isset($_SERVER["PHP_AUTH_PW"]) || !isset($_SERVER["PHP_AUTH_PW"])
) { ) {
return false; return false;
} }
OC_App::loadApps(array('authentication')); OC_App::loadApps(array('authentication'));
@ -778,8 +762,7 @@ if (!isset($RUNTIME_NOAPPS)) {
} }
if (!function_exists('get_temp_dir')) { if (!function_exists('get_temp_dir')) {
function get_temp_dir() function get_temp_dir() {
{
if ($temp = ini_get('upload_tmp_dir')) return $temp; if ($temp = ini_get('upload_tmp_dir')) return $temp;
if ($temp = getenv('TMP')) return $temp; if ($temp = getenv('TMP')) return $temp;
if ($temp = getenv('TEMP')) return $temp; if ($temp = getenv('TEMP')) return $temp;