Check for upgrade/maintance mode before trying to load an app

This commit is contained in:
Robin Appelman 2013-01-30 22:55:33 +01:00
parent 0cde86ac55
commit f452d2d0c4
1 changed files with 49 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
* OC_autoload!
*/
class OC
{
class OC {
/**
* Associative array for autoloading. classname => filename
*/
@ -78,13 +77,12 @@ class OC
/**
* SPL autoload
*/
public static function autoload($className)
{
public static function autoload($className) {
if (array_key_exists($className, OC::$CLASSPATH)) {
$path = OC::$CLASSPATH[$className];
/** @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) {
OC_Log::write('core', 'include path for class "' . $className . '" starts with "apps/"', OC_Log::DEBUG);
$path = str_replace('apps/', '', $path);
@ -96,7 +94,7 @@ class OC
} elseif (strpos($className, 'OCP\\') === 0) {
$path = 'public/' . strtolower(str_replace('\\', '/', substr($className, 3)) . '.php');
} 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');
$fullPath = stream_resolve_include_path($path);
if (file_exists($fullPath)) {
@ -124,8 +122,7 @@ class OC
return false;
}
public static function initPaths()
{
public static function initPaths() {
// calculate the root directories
OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4));
OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT)));
@ -150,7 +147,7 @@ class OC
// ensure we can find OC_Config
set_include_path(
OC::$SERVERROOT . '/lib' . PATH_SEPARATOR .
get_include_path()
get_include_path()
);
// search the 3rdparty folder
@ -188,17 +185,18 @@ class OC
exit;
}
$paths = array();
foreach (OC::$APPSROOTS as $path)
foreach (OC::$APPSROOTS as $path) {
$paths[] = $path['path'];
}
// set the right include path
set_include_path(
OC::$SERVERROOT . '/lib' . PATH_SEPARATOR .
OC::$SERVERROOT . '/config' . PATH_SEPARATOR .
OC::$THIRDPARTYROOT . '/3rdparty' . PATH_SEPARATOR .
implode($paths, PATH_SEPARATOR) . PATH_SEPARATOR .
get_include_path() . PATH_SEPARATOR .
OC::$SERVERROOT
OC::$SERVERROOT . '/config' . PATH_SEPARATOR .
OC::$THIRDPARTYROOT . '/3rdparty' . PATH_SEPARATOR .
implode($paths, PATH_SEPARATOR) . PATH_SEPARATOR .
get_include_path() . PATH_SEPARATOR .
OC::$SERVERROOT
);
}
@ -211,8 +209,7 @@ class OC
}
}
public static function checkInstalled()
{
public static function checkInstalled() {
// Redirect to installer if not installed
if (!OC_Config::getValue('installed', false) && OC::$SUBURI != '/index.php') {
if (!OC::$CLI) {
@ -223,8 +220,7 @@ class OC
}
}
public static function checkSSL()
{
public static function checkSSL() {
// redirect to https site if configured
if (OC_Config::getValue("forcessl", false)) {
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
OC_Util::addScript("jquery-1.7.2.min");
OC_Util::addScript("jquery-ui-1.10.0.custom");
@ -297,8 +292,7 @@ class OC
OC_Util::addScript("oc-requesttoken");
}
public static function initSession()
{
public static function initSession() {
// prevents javascript from accessing php session cookies
ini_set('session.cookie_httponly', '1;');
@ -328,8 +322,7 @@ class OC
$_SESSION['LAST_ACTIVITY'] = time();
}
public static function getRouter()
{
public static function getRouter() {
if (!isset(OC::$router)) {
OC::$router = new OC_Router();
OC::$router->loadRoutes();
@ -339,19 +332,17 @@ class OC
}
public static function loadAppClassPaths()
{
foreach(OC_APP::getEnabledApps() as $app) {
$file = OC_App::getAppPath($app).'/appinfo/classpath.php';
if(file_exists($file)) {
public static function loadAppClassPaths() {
foreach (OC_APP::getEnabledApps() as $app) {
$file = OC_App::getAppPath($app) . '/appinfo/classpath.php';
if (file_exists($file)) {
require_once $file;
}
}
}
public static function init()
{
public static function init() {
// register autoloader
spl_autoload_register(array('OC', 'autoload'));
setlocale(LC_ALL, 'en_US.UTF-8');
@ -516,8 +507,7 @@ class OC
/**
* register hooks for the cache
*/
public static function registerCacheHooks()
{
public static function registerCacheHooks() {
// register cache cleanup jobs
OC_BackgroundJob_RegularTask::register('OC_Cache_FileGlobal', 'gc');
OC_Hook::connect('OC_User', 'post_login', 'OC_Cache_File', 'loginListener');
@ -526,8 +516,7 @@ class OC
/**
* register hooks for the filesystem
*/
public static function registerFilesystemHooks()
{
public static function registerFilesystemHooks() {
// Check for blacklisted files
OC_Hook::connect('OC_Filesystem', 'write', 'OC_Filesystem', 'isBlacklisted');
OC_Hook::connect('OC_Filesystem', 'rename', 'OC_Filesystem', 'isBlacklisted');
@ -536,8 +525,7 @@ class OC
/**
* 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_addToGroup', 'OCP\Share', 'post_addToGroup');
OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OCP\Share', 'post_removeFromGroup');
@ -547,12 +535,19 @@ class OC
/**
* @brief Handle the request
*/
public static function handleRequest()
{
public static function handleRequest() {
// load all the classpaths from the enabled apps so they are available
// in the routing files of each app
OC::loadAppClassPaths();
// 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();
try {
OC::getRouter()->match(OC_Request::getPathInfo());
return;
@ -571,14 +566,6 @@ class OC
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
if (isset($_REQUEST['redirect_url']) && OC_User::isLoggedIn()) {
$location = OC_Helper::makeURLAbsolute(urldecode($_REQUEST['redirect_url']));
@ -608,7 +595,7 @@ class OC
$file_ext = substr($param['file'], -3);
if ($file_ext != 'php'
|| !self::loadAppScriptFile($param)
) {
) {
header('HTTP/1.0 404 Not Found');
}
}
@ -618,8 +605,7 @@ class OC
self::handleLogin();
}
public static function loadAppScriptFile($param)
{
public static function loadAppScriptFile($param) {
OC_App::loadApps();
$app = $param['app'];
$file = $param['file'];
@ -633,8 +619,7 @@ class OC
return false;
}
public static function loadCSSFile($param)
{
public static function loadCSSFile($param) {
$app = $param['app'];
$file = $param['file'];
$app_path = OC_App::getAppPath($app);
@ -647,27 +632,25 @@ class OC
}
}
protected static function handleLogin()
{
protected static function handleLogin() {
OC_App::loadApps(array('prelogin'));
$error = array();
// remember was checked after last login
if (OC::tryRememberLogin()) {
$error[] = 'invalidcookie';
// Someone wants to log in :
// Someone wants to log in :
} elseif (OC::tryFormLogin()) {
$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()) {
$error[] = 'invalidpassword';
}
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);
$tokens = OC_Preferences::getKeys($user, 'login_token');
foreach ($tokens as $token) {
@ -678,13 +661,12 @@ class OC
}
}
protected static function tryRememberLogin()
{
protected static function tryRememberLogin() {
if (!isset($_COOKIE["oc_remember_login"])
|| !isset($_COOKIE["oc_token"])
|| !isset($_COOKIE["oc_username"])
|| !$_COOKIE["oc_remember_login"]
) {
) {
return false;
}
OC_App::loadApps(array('authentication'));
@ -719,8 +701,7 @@ class OC
return true;
}
protected static function tryFormLogin()
{
protected static function tryFormLogin() {
if (!isset($_POST["user"]) || !isset($_POST['password'])) {
return false;
}
@ -753,11 +734,10 @@ class OC
return true;
}
protected static function tryBasicAuthLogin()
{
protected static function tryBasicAuthLogin() {
if (!isset($_SERVER["PHP_AUTH_USER"])
|| !isset($_SERVER["PHP_AUTH_PW"])
) {
) {
return false;
}
OC_App::loadApps(array('authentication'));
@ -778,8 +758,7 @@ if (!isset($RUNTIME_NOAPPS)) {
}
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 = getenv('TMP')) return $temp;
if ($temp = getenv('TEMP')) return $temp;