aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMichael Gapczynski <mtgap@owncloud.com>2012-08-09 11:38:22 -0400
committerMichael Gapczynski <mtgap@owncloud.com>2012-08-09 11:38:22 -0400
commit78cd1153f012f871935130325167759898f030ab (patch)
tree685a5fe56663e6b6087aa4f28c8f09daf1e80546 /lib
parentb830b3e24b281204344e9162352c7034f0a67187 (diff)
parentf9cec1426fe639a5683e36b5fbdeb9149feacb19 (diff)
downloadnextcloud-server-78cd1153f012f871935130325167759898f030ab.tar.gz
nextcloud-server-78cd1153f012f871935130325167759898f030ab.zip
Merge branch 'master' into share_api
Conflicts: apps/contacts/lib/vcard.php apps/files_sharing/sharedstorage.php
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php121
-rw-r--r--lib/exception.php93
-rw-r--r--lib/filecache.php30
-rw-r--r--lib/filecache/update.php4
-rw-r--r--lib/helper.php61
-rw-r--r--lib/public/util.php4
-rw-r--r--lib/request.php77
-rwxr-xr-xlib/util.php4
8 files changed, 230 insertions, 164 deletions
diff --git a/lib/base.php b/lib/base.php
index 888dc265d64..6514a0c0b0c 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -185,8 +185,8 @@ class OC{
// redirect to https site if configured
if( OC_Config::getValue( "forcessl", false )){
ini_set("session.cookie_secure", "on");
- if(OC_Helper::serverProtocol()<>'https' and !OC::$CLI) {
- $url = "https://". OC_Helper::serverHost() . $_SERVER['REQUEST_URI'];
+ if(OC_Request::serverProtocol()<>'https' and !OC::$CLI) {
+ $url = "https://". OC_Request::serverHost() . $_SERVER['REQUEST_URI'];
header("Location: $url");
exit();
}
@@ -373,7 +373,7 @@ class OC{
self::$REQUESTEDAPP = (isset($_GET['app']) && trim($_GET['app']) != '' && !is_null($_GET['app'])?str_replace(array('\0', '/', '\\', '..'), '', strip_tags($_GET['app'])):OC_Config::getValue('defaultapp', 'files'));
if(substr_count(self::$REQUESTEDAPP, '?') != 0){
$app = substr(self::$REQUESTEDAPP, 0, strpos(self::$REQUESTEDAPP, '?'));
- $param = substr(self::$REQUESTEDAPP, strpos(self::$REQUESTEDAPP, '?') + 1);
+ $param = substr($_GET['app'], strpos($_GET['app'], '?') + 1);
parse_str($param, $get);
$_GET = array_merge($_GET, $get);
self::$REQUESTEDAPP = $app;
@@ -398,12 +398,121 @@ class OC{
}
}
}
+
+ /**
+ * @brief Try to handle request
+ * @return true when the request is handled here
+ */
+ public static function handleRequest() {
+ if (!OC_Config::getValue('installed', false)) {
+ // Check for autosetup:
+ $autosetup_file = OC::$SERVERROOT."/config/autoconfig.php";
+ if( file_exists( $autosetup_file )){
+ OC_Log::write('core','Autoconfig file found, setting up owncloud...',OC_Log::INFO);
+ include( $autosetup_file );
+ $_POST['install'] = 'true';
+ $_POST = array_merge ($_POST, $AUTOCONFIG);
+ unlink($autosetup_file);
+ }
+ OC_Util::addScript('setup');
+ require_once('setup.php');
+ exit();
+ }
+ // Handle WebDAV
+ if($_SERVER['REQUEST_METHOD']=='PROPFIND'){
+ header('location: '.OC_Helper::linkToRemote('webdav'));
+ return true;
+ }
+ if(!OC_User::isLoggedIn() && substr(OC::$REQUESTEDFILE,-3) == 'css') {
+ OC_App::loadApps();
+ OC::loadfile();
+ return true;
+ }
+ // Someone is logged in :
+ if(OC_User::isLoggedIn()) {
+ OC_App::loadApps();
+ if(isset($_GET["logout"]) and ($_GET["logout"])) {
+ OC_User::logout();
+ header("Location: ".OC::$WEBROOT.'/');
+ }else{
+ if(is_null(OC::$REQUESTEDFILE)) {
+ OC::loadapp();
+ }else{
+ OC::loadfile();
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ public 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'));
+ if(defined("DEBUG") && DEBUG) {
+ OC_Log::write('core','Trying to login from cookie',OC_Log::DEBUG);
+ }
+ // confirm credentials in cookie
+ if(isset($_COOKIE['oc_token']) && OC_User::userExists($_COOKIE['oc_username']) &&
+ OC_Preferences::getValue($_COOKIE['oc_username'], "login", "token") == $_COOKIE['oc_token']) {
+ OC_User::setUserId($_COOKIE['oc_username']);
+ OC_Util::redirectToDefaultPage();
+ }
+ else {
+ OC_User::unsetMagicInCookie();
+ }
+ return true;
+ }
+
+ public static function tryFormLogin() {
+ if(!isset($_POST["user"])
+ || !isset($_POST['password'])
+ || !isset($_SESSION['sectoken'])
+ || !isset($_POST['sectoken'])
+ || ($_SESSION['sectoken']!=$_POST['sectoken']) ) {
+ return false;
+ }
+ OC_App::loadApps();
+ if(OC_User::login($_POST["user"], $_POST["password"])) {
+ if(!empty($_POST["remember_login"])){
+ if(defined("DEBUG") && DEBUG) {
+ OC_Log::write('core','Setting remember login to cookie', OC_Log::DEBUG);
+ }
+ $token = md5($_POST["user"].time().$_POST['password']);
+ OC_Preferences::setValue($_POST['user'], 'login', 'token', $token);
+ OC_User::setMagicInCookie($_POST["user"], $token);
+ }
+ else {
+ OC_User::unsetMagicInCookie();
+ }
+ OC_Util::redirectToDefaultPage();
+ }
+ return true;
+ }
+
+ public static function tryBasicAuthLogin() {
+ if (!isset($_SERVER["PHP_AUTH_USER"])
+ || !isset($_SERVER["PHP_AUTH_PW"])){
+ return false;
+ }
+ OC_App::loadApps(array('authentication'));
+ if (OC_User::login($_SERVER["PHP_AUTH_USER"],$_SERVER["PHP_AUTH_PW"])) {
+ //OC_Log::write('core',"Logged in with HTTP Authentication",OC_Log::DEBUG);
+ OC_User::unsetMagicInCookie();
+ $_REQUEST['redirect_url'] = (isset($_SERVER['REQUEST_URI'])?$_SERVER['REQUEST_URI']:'');
+ OC_Util::redirectToDefaultPage();
+ }
+ return true;
+ }
+
}
// define runtime variables - unless this already has been done
-if( !isset( $RUNTIME_NOSETUPFS )){
- $RUNTIME_NOSETUPFS = false;
-}
if( !isset( $RUNTIME_NOAPPS )){
$RUNTIME_NOAPPS = false;
}
diff --git a/lib/exception.php b/lib/exception.php
deleted file mode 100644
index db516fc12d2..00000000000
--- a/lib/exception.php
+++ /dev/null
@@ -1,93 +0,0 @@
-<?php
-/**
- * ownCloud
- *
- * @author Georg Ehrke
- * @copyright 2012 georg@owncloud.com
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library 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 AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-class OC_Exception extends Exception{
-
- function __construct($message = null, $code = 0, $file = null, $line = null){
- parent::__construct($message, $code);
- if(!is_null($file)){
- $this->file = $file;
- }
- if(!is_null($line)){
- $this->line = $line;
- }
- $this->writelog();
- }
-
- private function writelog(){
- @OC_Log::write(OC_App::getCurrentApp(), $this->getMessage() . '-' . $this->getFile() . '-' . $this->getLine(), OC_Log::FATAL);
- }
-
- private function generatesysinfo(){
- return array('phpversion' => PHP_VERSION,
- 'os' => php_uname('s'),
- 'osrelease' => php_uname('r'),
- 'osarchitecture' => php_uname('m'),
- 'phpserverinterface' => php_sapi_name(),
- 'serverprotocol' => $_SERVER['SERVER_PROTOCOL'],
- 'requestmethod' => $_SERVER['REQUEST_METHOD'],
- 'https' => ($_SERVER['HTTPS']==''?'false':'true'),
- 'database'=>(@OC_Config::getValue('dbtype')!=''?@OC_Config::getValue('dbtype'):'')
- );
- }
-
- function __toString(){
- $tmpl = new OC_Template('core', 'exception', 'guest');
- $tmpl->assign('showsysinfo', true);
- $tmpl->assign('message', $this->getMessage());
- $tmpl->assign('code', $this->getCode());
- $tmpl->assign('file', $this->getFile());
- $tmpl->assign('line', $this->getLine());
- $tmpl->assign('sysinfo', $this->generatesysinfo());
- $tmpl->printPage();
- }
-}
-
-function oc_exceptionhandler($exception){
- switch($exception->getCode()){
- case E_NOTICE:
- case E_DEPRECATED:
- case E_USER_NOTICE:
- case E_USER_DEPRECATED:
- break;
- default:
- throw new OC_Exception($exception->getMessage(), $exception->getCode(), $exception->getFile(), $exception->getLine());
- break;
- }
- return true;
-}
-
-function oc_errorhandler($errno , $errstr , $errfile , $errline){
- switch($errno){
- case E_NOTICE:
- case E_DEPRECATED:
- case E_USER_NOTICE:
- case E_USER_DEPRECATED:
- break;
- default:
- throw new OC_Exception($errstr, $errno, $errfile, $errline);
- break;
- }
- return true;
-}
-set_exception_handler('oc_exceptionhandler');
-set_error_handler('oc_errorhandler');
-error_reporting(E_ERROR | E_WARNING | E_PARSE); \ No newline at end of file
diff --git a/lib/filecache.php b/lib/filecache.php
index 8211637d141..352fc695f30 100644
--- a/lib/filecache.php
+++ b/lib/filecache.php
@@ -65,19 +65,27 @@ class OC_FileCache{
if($root===false){
$root=OC_Filesystem::getRoot();
}
- $path=$root.$path;
- $parent=self::getParentId($path);
- $id=self::getId($path,'');
- if(isset(OC_FileCache_Cached::$savedData[$path])){
- $data=array_merge(OC_FileCache_Cached::$savedData[$path],$data);
- unset(OC_FileCache_Cached::$savedData[$path]);
+ $fullpath=$root.$path;
+ $parent=self::getParentId($fullpath);
+ $id=self::getId($fullpath,'');
+ if(isset(OC_FileCache_Cached::$savedData[$fullpath])){
+ $data=array_merge(OC_FileCache_Cached::$savedData[$fullpath],$data);
+ unset(OC_FileCache_Cached::$savedData[$fullpath]);
}
if($id!=-1){
self::update($id,$data);
return;
}
+
+ // add parent directory to the file cache if it does not exist yet.
+ if ($parent == -1 && $fullpath != $root) {
+ $parentDir = substr(dirname($path), 0, strrpos(dirname($path), DIRECTORY_SEPARATOR));
+ self::scanFile($parentDir);
+ $parent = self::getParentId($fullpath);
+ }
+
if(!isset($data['size']) or !isset($data['mtime'])){//save incomplete data for the next time we write it
- OC_FileCache_Cached::$savedData[$path]=$data;
+ OC_FileCache_Cached::$savedData[$fullpath]=$data;
return;
}
if(!isset($data['encrypted'])){
@@ -94,13 +102,13 @@ class OC_FileCache{
$data['versioned']=(int)$data['versioned'];
$user=OC_User::getUser();
$query=OC_DB::prepare('INSERT INTO *PREFIX*fscache(parent, name, path, path_hash, size, mtime, ctime, mimetype, mimepart,`user`,writable,encrypted,versioned) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)');
- $result=$query->execute(array($parent,basename($path),$path,md5($path),$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart,$user,$data['writable'],$data['encrypted'],$data['versioned']));
+ $result=$query->execute(array($parent,basename($fullpath),$fullpath,md5($fullpath),$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart,$user,$data['writable'],$data['encrypted'],$data['versioned']));
if(OC_DB::isError($result)){
- OC_Log::write('files','error while writing file('.$path.') to cache',OC_Log::ERROR);
+ OC_Log::write('files','error while writing file('.$fullpath.') to cache',OC_Log::ERROR);
}
if($cache=OC_Cache::getUserCache(true)){
- $cache->remove('fileid/'.$path);//ensure we don't have -1 cached
+ $cache->remove('fileid/'.$fullpath);//ensure we don't have -1 cached
}
}
@@ -343,7 +351,7 @@ class OC_FileCache{
* @param string $path
* @param OC_EventSource $enventSource (optional)
* @param int count (optional)
- * @param string root (optionak)
+ * @param string root (optional)
*/
public static function scan($path,$eventSource=false,&$count=0,$root=false){
if($eventSource){
diff --git a/lib/filecache/update.php b/lib/filecache/update.php
index 93b632acb4e..0b5ff8e2446 100644
--- a/lib/filecache/update.php
+++ b/lib/filecache/update.php
@@ -152,8 +152,8 @@ class OC_FileCache_Update{
$size=0;
$cached=OC_FileCache_Cached::get($path,$root);
$cachedSize=isset($cached['size'])?$cached['size']:0;
-
- if($mimetype=='httpd/unix-directory'){
+
+ if($view->is_dir($path.'/')){
if(OC_FileCache::inCache($path,$root)){
$cachedContent=OC_FileCache_Cached::getFolderContent($path,$root);
foreach($cachedContent as $file){
diff --git a/lib/helper.php b/lib/helper.php
index 666bc6badfc..8c362747a27 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -65,52 +65,6 @@ class OC_Helper {
}
/**
- * @brief Returns the server host
- * @returns the server host
- *
- * Returns the server host, even if the website uses one or more
- * reverse proxies
- */
- public static function serverHost() {
- if(OC::$CLI){
- return 'localhost';
- }
- if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
- if (strpos($_SERVER['HTTP_X_FORWARDED_HOST'], ",") !== false) {
- $host = trim(array_pop(explode(",", $_SERVER['HTTP_X_FORWARDED_HOST'])));
- }
- else{
- $host=$_SERVER['HTTP_X_FORWARDED_HOST'];
- }
- }
- else{
- $host = $_SERVER['HTTP_HOST'];
- }
- return $host;
- }
-
-
- /**
- * @brief Returns the server protocol
- * @returns the server protocol
- *
- * Returns the server protocol. It respects reverse proxy servers and load balancers
- */
- public static function serverProtocol() {
- if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
- $proto = strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']);
- }else{
- if(isset($_SERVER['HTTPS']) and !empty($_SERVER['HTTPS']) and ($_SERVER['HTTPS']!='off')) {
- $proto = 'https';
- }else{
- $proto = 'http';
- }
- }
- return($proto);
- }
-
-
- /**
* @brief Creates an absolute url
* @param $app app
* @param $file file
@@ -120,8 +74,19 @@ class OC_Helper {
*/
public static function linkToAbsolute( $app, $file ) {
$urlLinkTo = self::linkTo( $app, $file );
- $urlLinkTo = self::serverProtocol(). '://' . self::serverHost() . $urlLinkTo;
- return $urlLinkTo;
+ return self::makeURLAbsolute($urlLinkTo);
+ }
+
+ /**
+ * @brief Makes an $url absolute
+ * @param $url the url
+ * @returns the absolute url
+ *
+ * Returns a absolute url to the given app and file.
+ */
+ public static function makeURLAbsolute( $url )
+ {
+ return OC_Request::serverProtocol(). '://' . OC_Request::serverHost() . $url;
}
/**
diff --git a/lib/public/util.php b/lib/public/util.php
index 75ca29f7129..9f6f6f32e1e 100644
--- a/lib/public/util.php
+++ b/lib/public/util.php
@@ -165,7 +165,7 @@ class Util {
* reverse proxies
*/
public static function getServerHost() {
- return(\OC_Helper::serverHost());
+ return(\OC_Request::serverHost());
}
/**
@@ -175,7 +175,7 @@ class Util {
* Returns the server protocol. It respects reverse proxy servers and load balancers
*/
public static function getServerProtocol() {
- return(\OC_Helper::serverProtocol());
+ return(\OC_Request::serverProtocol());
}
/**
diff --git a/lib/request.php b/lib/request.php
index 0b5aaf8ef30..3fe61fbddcd 100644
--- a/lib/request.php
+++ b/lib/request.php
@@ -7,6 +7,79 @@
*/
class OC_Request {
+ /**
+ * @brief Returns the server host
+ * @returns the server host
+ *
+ * Returns the server host, even if the website uses one or more
+ * reverse proxies
+ */
+ public static function serverHost() {
+ if(OC::$CLI){
+ return 'localhost';
+ }
+ if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
+ if (strpos($_SERVER['HTTP_X_FORWARDED_HOST'], ",") !== false) {
+ $host = trim(array_pop(explode(",", $_SERVER['HTTP_X_FORWARDED_HOST'])));
+ }
+ else{
+ $host=$_SERVER['HTTP_X_FORWARDED_HOST'];
+ }
+ }
+ else{
+ $host = $_SERVER['HTTP_HOST'];
+ }
+ return $host;
+ }
+
+
+ /**
+ * @brief Returns the server protocol
+ * @returns the server protocol
+ *
+ * Returns the server protocol. It respects reverse proxy servers and load balancers
+ */
+ public static function serverProtocol() {
+ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
+ $proto = strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']);
+ }else{
+ if(isset($_SERVER['HTTPS']) and !empty($_SERVER['HTTPS']) and ($_SERVER['HTTPS']!='off')) {
+ $proto = 'https';
+ }else{
+ $proto = 'http';
+ }
+ }
+ return($proto);
+ }
+
+ /**
+ * @brief get Path info from request
+ * @returns string Path info or false when not found
+ */
+ public static function getPathInfo() {
+ if (array_key_exists('PATH_INFO', $_SERVER)){
+ $path_info = $_SERVER['PATH_INFO'];
+ }else{
+ $path_info = substr($_SERVER['REQUEST_URI'], strlen($_SERVER['SCRIPT_NAME']));
+ // following is taken from Sabre_DAV_URLUtil::decodePathSegment
+ $path_info = rawurldecode($path_info);
+ $encoding = mb_detect_encoding($path_info, array('UTF-8','ISO-8859-1'));
+
+ switch($encoding) {
+
+ case 'ISO-8859-1' :
+ $path_info = utf8_encode($path_info);
+
+ }
+ // end copy
+ }
+ return $path_info;
+ }
+
+ /**
+ * @brief Check if this is a no-cache request
+ * @returns true for no-cache
+ */
static public function isNoCache() {
if (!isset($_SERVER['HTTP_CACHE_CONTROL'])) {
return false;
@@ -14,6 +87,10 @@ class OC_Request {
return $_SERVER['HTTP_CACHE_CONTROL'] == 'no-cache';
}
+ /**
+ * @brief Check if the requestor understands gzip
+ * @returns true for gzip encoding supported
+ */
static public function acceptGZip() {
if (!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
return false;
diff --git a/lib/util.php b/lib/util.php
index f26fa63e446..4c5d416f9f2 100755
--- a/lib/util.php
+++ b/lib/util.php
@@ -348,7 +348,7 @@ class OC_Util {
else {
$defaultpage = OC_Appconfig::getValue('core', 'defaultpage');
if ($defaultpage) {
- $location = OC_Helper::serverProtocol().'://'.OC_Helper::serverHost().OC::$WEBROOT.'/'.$defaultpage;
+ $location = OC_Helper::makeURLAbsolute(OC::$WEBROOT.'/'.$defaultpage);
}
else {
$location = OC_Helper::linkToAbsolute( 'files', 'index.php' );
@@ -476,7 +476,7 @@ class OC_Util {
@fclose($fp);
// accessing the file via http
- $url = OC_Helper::serverProtocol(). '://' . OC_Helper::serverHost() . OC::$WEBROOT.'/data'.$filename;
+ $url = OC_Helper::makeURLAbsolute(OC::$WEBROOT.'/data'.$filename);
$fp = @fopen($url, 'r');
$content=@fread($fp, 2048);
@fclose($fp);