open app thru index.php

This commit is contained in:
Georg Ehrke 2012-04-18 08:20:51 +02:00
parent 69ee0efc0b
commit 3e0e6e35f4
4 changed files with 45 additions and 14 deletions

View File

@ -57,7 +57,7 @@ elseif(OC_User::isLoggedIn()) {
exit(); exit();
} }
else { else {
OC_Util::redirectToDefaultPage(); OC::loadapp();
} }
} }

View File

@ -70,7 +70,14 @@ class OC{
* the root path of the apps folder for http requests (e.g. owncloud) * the root path of the apps folder for http requests (e.g. owncloud)
*/ */
public static $APPSWEBROOT = ''; public static $APPSWEBROOT = '';
/*
* requested app
*/
public static $REQUESTEDAPP = '';
/*
* requested file of app
*/
public static $REQUESTEDFILE = '';
/** /**
* SPL autoload * SPL autoload
*/ */
@ -161,12 +168,15 @@ class OC{
} }
// search the apps folder // search the apps folder
if(file_exists(OC::$SERVERROOT.'/apps')){ if(OC_Config::getValue('appsroot', '')<>''){
OC::$APPSROOT=OC_Config::getValue('appsroot', '');
OC::$APPSWEBROOT=OC_Config::getValue('appsurl', '');
}elseif(file_exists(OC::$SERVERROOT.'/apps')){
OC::$APPSROOT=OC::$SERVERROOT; OC::$APPSROOT=OC::$SERVERROOT;
OC::$APPSWEBROOT=OC::$WEBROOT; OC::$APPSWEBROOT=OC::$WEBROOT;
}elseif(file_exists(OC::$SERVERROOT.'/../apps')){ }elseif(file_exists(OC::$SERVERROOT.'/../apps')){
OC::$APPSWEBROOT=rtrim(dirname(OC::$WEBROOT), '/');
OC::$APPSROOT=rtrim(dirname(OC::$SERVERROOT), '/'); OC::$APPSROOT=rtrim(dirname(OC::$SERVERROOT), '/');
OC::$APPSWEBROOT=rtrim(dirname(OC::$WEBROOT), '/');
}else{ }else{
echo("apps directory not found! Please put the ownCloud apps folder in the ownCloud folder or the folder above. You can also configure the location in the config.php file."); echo("apps directory not found! Please put the ownCloud apps folder in the ownCloud folder or the folder above. You can also configure the location in the config.php file.");
exit; exit;
@ -262,6 +272,13 @@ class OC{
session_start(); session_start();
} }
public static function loadapp(){
if(file_exists(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP)){
OC_App::loadApps();
require_once(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/index.php');
}
}
public static function init(){ public static function init(){
// register autoloader // register autoloader
spl_autoload_register(array('OC','autoload')); spl_autoload_register(array('OC','autoload'));
@ -371,6 +388,9 @@ class OC{
//make sure temporary files are cleaned up //make sure temporary files are cleaned up
register_shutdown_function(array('OC_Helper','cleanTmp')); register_shutdown_function(array('OC_Helper','cleanTmp'));
self::$REQUESTEDAPP = (isset($_GET['app'])?strip_tags($_GET['app']):'files');
self::$REQUESTEDFILE = (isset($_GET['file'])?(OC_Helper::issubdirectory(OC::$APPSROOT . '/' . self::$REQUESTEDAPP . '/' . $_GET['file'], OC::$APPSROOT . '/' . self::$REQUESTEDAPP)?$_GET['file']:null):null);
} }
} }

View File

@ -520,4 +520,15 @@ class OC_Helper {
return $newname; return $newname;
} }
/*
* checks if $sub is a subdirectory of $parent
*
* @param $sub
* @param $parent
* @return bool
*/
public static function issubdirectory($sub, $parent){
return (substr(realpath($sub), 0, strlen(realpath($parent))) == realpath($parent))?true:false;
}
} }

View File

@ -292,7 +292,7 @@ class OC_Util {
if(isset($_REQUEST['redirect_url'])) { if(isset($_REQUEST['redirect_url'])) {
header( 'Location: '.$_REQUEST['redirect_url']); header( 'Location: '.$_REQUEST['redirect_url']);
} else { } else {
header( 'Location: '.OC::$WEBROOT.'/'.OC_Appconfig::getValue('core', 'defaultpage', 'files/index.php')); header( 'Location: '.OC::$WEBROOT.'/'.OC_Appconfig::getValue('core', 'defaultpage', '?app=files'));
} }
exit(); exit();
} }