summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php4
-rw-r--r--lib/connector/sabre/auth.php1
-rw-r--r--lib/crypt.php165
-rw-r--r--lib/fakedirstream.php45
-rw-r--r--lib/filecache.php43
-rw-r--r--lib/fileproxy.php17
-rw-r--r--lib/filestorage.php2
-rw-r--r--lib/filestorage/local.php71
-rw-r--r--lib/filesystemview.php97
-rw-r--r--lib/helper.php58
-rw-r--r--lib/streamwrappers.php223
-rw-r--r--lib/user.php6
-rw-r--r--lib/util.php8
13 files changed, 412 insertions, 328 deletions
diff --git a/lib/base.php b/lib/base.php
index 342bdc6768e..85afaa62258 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -303,13 +303,15 @@ if(!function_exists('get_temp_dir')) {
unlink($temp);
return dirname($temp);
}
+ if( $temp=sys_get_temp_dir()) return $temp;
+
return null;
}
}
OC::init();
-require_once('fakedirstream.php');
+require_once('streamwrappers.php');
diff --git a/lib/connector/sabre/auth.php b/lib/connector/sabre/auth.php
index 1e87c7cee08..8964ef7d0de 100644
--- a/lib/connector/sabre/auth.php
+++ b/lib/connector/sabre/auth.php
@@ -23,6 +23,7 @@ class OC_Connector_Sabre_Auth extends Sabre_DAV_Auth_Backend_AbstractBasic {
* @return bool
*/
protected function validateUserPass($username, $password){
+ OC_Util::setUpFS();//login hooks may need early access to the filesystem
if(OC_User::login($username,$password)){
OC_Util::setUpFS();
return true;
diff --git a/lib/crypt.php b/lib/crypt.php
deleted file mode 100644
index 60020679480..00000000000
--- a/lib/crypt.php
+++ /dev/null
@@ -1,165 +0,0 @@
-<?php
-/**
- * ownCloud
- *
- * @author Frank Karlitschek
- * @copyright 2010 Frank Karlitschek karlitschek@kde.org
- *
- * 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/>.
- *
- */
-
-
-
-// Todo:
-// - Crypt/decrypt button in the userinterface
-// - Setting if crypto should be on by default
-// - Add a setting "DonĀ“t encrypt files larger than xx because of performance reasons"
-// - Transparent decrypt/encrpt in filesystem.php. Autodetect if a file is encrypted (.encrypted extensio)
-// - Don't use a password directly as encryption key. but a key which is stored on the server and encrypted with the user password. -> password change faster
-// - IMPORTANT! Check if the block lenght of the encrypted data stays the same
-
-
-require_once('Crypt_Blowfish/Blowfish.php');
-
-/**
- * This class is for crypting and decrypting
- */
-class OC_Crypt {
-
- static $encription_extension='.encrypted';
-
- public static function init($login,$password) {
- $_SESSION['user_password'] = $password; // save the password as passcode for the encryption
- if(OC_User::isLoggedIn()){
- // does key exist?
- if(!file_exists(OC_Config::getValue( "datadirectory").'/'.$login.'/encryption.key')){
- OC_Crypt::createkey($_SESSION['user_password']);
- }
- }
- }
-
-
-
- public static function createkey($passcode) {
- if(OC_User::isLoggedIn()){
- // generate a random key
- $key=mt_rand(10000,99999).mt_rand(10000,99999).mt_rand(10000,99999).mt_rand(10000,99999);
-
- // encrypt the key with the passcode of the user
- $enckey=OC_Crypt::encrypt($key,$passcode);
-
- // Write the file
- $username=OC_USER::getUser();
- @file_put_contents(OC_Config::getValue( "datadirectory").'/'.$username.'/encryption.key', $enckey );
- }
- }
-
- public static function changekeypasscode( $newpasscode) {
- if(OC_User::isLoggedIn()){
- $username=OC_USER::getUser();
-
- // read old key
- $key=file_get_contents(OC_Config::getValue( "datadirectory").'/'.$username.'/encryption.key');
-
- // decrypt key with old passcode
- $key=OC_Crypt::decrypt($key, $_SESSION['user_password']);
-
- // encrypt again with new passcode
- $key=OC_Crypt::encrypt($key,$newpassword);
-
- // store the new key
- file_put_contents(OC_Config::getValue( "datadirectory").'/'.$username.'/encryption.key', $key );
-
- $_SESSION['user_password']=$newpasscode;
- }
- }
-
- /**
- * @brief encrypts an content
- * @param $content the cleartext message you want to encrypt
- * @param $key the encryption key
- * @returns encrypted content
- *
- * This function encrypts an content
- */
- public static function encrypt( $content, $key) {
- $bf = new Crypt_Blowfish($key);
- return($bf->encrypt($content));
- }
-
-
- /**
- * @brief decryption of an content
- * @param $content the cleartext message you want to decrypt
- * @param $key the encryption key
- * @returns cleartext content
- *
- * This function decrypts an content
- */
- public static function decrypt( $content, $key) {
- $bf = new Crypt_Blowfish($key);
- return($bf->encrypt($contents));
- }
-
-
- /**
- * @brief encryption of a file
- * @param $filename
- * @param $key the encryption key
- *
- * This function encrypts a file
- */
- public static function encryptfile( $filename, $key) {
- $handleread = fopen($filename, "rb");
- if($handleread<>FALSE) {
- $handlewrite = fopen($filename.OC_Crypt::$encription_extension, "wb");
- while (!feof($handleread)) {
- $content = fread($handleread, 8192);
- $enccontent=OC_CRYPT::encrypt( $content, $key);
- fwrite($handlewrite, $enccontent);
- }
- fclose($handlewrite);
- unlink($filename);
- }
- fclose($handleread);
- }
-
-
- /**
- * @brief decryption of a file
- * @param $filename
- * @param $key the decryption key
- *
- * This function decrypts a file
- */
- public static function decryptfile( $filename, $key) {
- $handleread = fopen($filename.OC_Crypt::$encription_extension, "rb");
- if($handleread<>FALSE) {
- $handlewrite = fopen($filename, "wb");
- while (!feof($handleread)) {
- $content = fread($handleread, 8192);
- $enccontent=OC_CRYPT::decrypt( $content, $key);
- fwrite($handlewrite, $enccontent);
- }
- fclose($handlewrite);
- unlink($filename.OC_Crypt::$encription_extension);
- }
- fclose($handleread);
- }
-
-
-
-
-}
diff --git a/lib/fakedirstream.php b/lib/fakedirstream.php
deleted file mode 100644
index fa3e64da62c..00000000000
--- a/lib/fakedirstream.php
+++ /dev/null
@@ -1,45 +0,0 @@
-<?php
-global $FAKEDIRS;
-$FAKEDIRS=array();
-
-class fakeDirStream{
- private $name;
- private $data;
- private $index;
-
- public function dir_opendir($path,$options){
- global $FAKEDIRS;
- $url=parse_url($path);
- $this->name=substr($path,strlen('fakedir://'));
- $this->index=0;
- if(isset($FAKEDIRS[$this->name])){
- $this->data=$FAKEDIRS[$this->name];
- }else{
- $this->data=array();
- }
- return true;
- }
-
- public function dir_readdir(){
- if($this->index>=count($this->data)){
- return false;
- }
- $filename=$this->data[$this->index];
- $this->index++;
- return $filename;
- }
-
- public function dir_closedir() {
- $this->data=false;
- $this->name='';
- return true;
- }
-
- public function dir_rewinddir() {
- $this->index=0;
- return true;
- }
-}
-
-stream_wrapper_register("fakedir", "fakeDirStream");
-
diff --git a/lib/filecache.php b/lib/filecache.php
index faadddfb37e..6ccb0d90ef1 100644
--- a/lib/filecache.php
+++ b/lib/filecache.php
@@ -28,6 +28,8 @@
* It will try to keep the data up to date but changes from outside ownCloud can invalidate the cache
*/
class OC_FileCache{
+ private static $savedData=array();
+
/**
* get the filesystem info from the cache
* @param string path
@@ -93,6 +95,14 @@ class OC_FileCache{
self::update($id,$data);
return;
}
+ if(isset(self::$savedData[$path])){
+ $data=array_merge($data,self::$savedData[$path]);
+ unset(self::$savedData[$path]);
+ }
+ if(!isset($data['size']) or !isset($data['mtime'])){//save incomplete data for the next time we write it
+ self::$savedData[$path]=$data;
+ return;
+ }
if(!isset($data['encrypted'])){
$data['encrypted']=false;
}
@@ -101,9 +111,8 @@ class OC_FileCache{
}
$mimePart=dirname($data['mimetype']);
$user=OC_User::getUser();
- $query=OC_DB::prepare('INSERT INTO *PREFIX*fscache(parent, name, path, size, mtime, ctime, mimetype, mimepart,user,writable) VALUES(?,?,?,?,?,?,?,?,?,?)');
- $query->execute(array($parent,basename($path),$path,$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart,$user,$data['writable']));
-
+ $query=OC_DB::prepare('INSERT INTO *PREFIX*fscache(parent, name, path, size, mtime, ctime, mimetype, mimepart,user,writable,encrypted,versioned) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)');
+ $query->execute(array($parent,basename($path),$path,$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart,$user,$data['writable'],$data['encrypted'],$data['versioned']));
}
/**
@@ -323,7 +332,29 @@ class OC_FileCache{
}
self::increaseSize(dirname($fullPath),$size-$cachedSize);
}
-
+
+ public static function getCached($path,$root=''){
+ if(!$root){
+ $root=OC_Filesystem::getRoot();
+ }else{
+ if($root=='/'){
+ $root='';
+ }
+ }
+ $path=$root.$path;
+ $query=OC_DB::prepare('SELECT ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE path=?');
+ $result=$query->execute(array($path))->fetchRow();
+ if(is_array($result)){
+ if(isset(self::$savedData[$path])){
+ $result=array_merge($result,self::$savedData[$path]);
+ }
+ return $result;
+ }else{
+ OC_Log::write('get(): file not found in cache ('.$path.')','core',OC_Log::DEBUG);
+ return false;
+ }
+ }
+
private static function getCachedSize($path,$root){
if(!$root){
$root=OC_Filesystem::getRoot();
@@ -332,6 +363,7 @@ class OC_FileCache{
$root='';
}
}
+ $path=$root.$path;
$query=OC_DB::prepare('SELECT size FROM *PREFIX*fscache WHERE path=?');
$result=$query->execute(array($path));
if($row=$result->fetchRow()){
@@ -515,6 +547,9 @@ class OC_FileCache{
}
$view=new OC_FilesystemView($root);
}
+ if(!$view->file_exists($path)){
+ return false;
+ }
$mtime=$view->filemtime($path);
$isDir=$view->is_dir($path);
$path=$root.$path;
diff --git a/lib/fileproxy.php b/lib/fileproxy.php
index 235fc8bf284..46fc2f49c50 100644
--- a/lib/fileproxy.php
+++ b/lib/fileproxy.php
@@ -34,11 +34,12 @@
* A post-proxy recieves 2 arguments, the filepath and the result of the operation.
* The return calue of the post-proxy will be used as the new result of the operation
* The operations that have a post-proxy are
- * file_get_contents, is_file, is_dir, file_exists, stat, is_readable, is_writable, filemtime, filectime, file_get_contents, getMimeType, hash, free_space and search
+ * file_get_contents, is_file, is_dir, file_exists, stat, is_readable, is_writable, fileatime, filemtime, filectime, file_get_contents, getMimeType, hash, fopen, free_space and search
*/
class OC_FileProxy{
private static $proxies=array();
+ public static $enabled=true;
/**
* check if this proxy implments a specific proxy operation
@@ -83,16 +84,19 @@ class OC_FileProxy{
return $proxies;
}
- public static function runPreProxies($operation,$filepath,$filepath2=null){
+ public static function runPreProxies($operation,&$filepath,&$filepath2=null){
+ if(!self::$enabled){
+ return true;
+ }
$proxies=self::getProxies($operation,false);
$operation='pre'.$operation;
foreach($proxies as $proxy){
- if($filepath2){
- if(!$proxy->$operation($filepath,$filepath2)){
+ if(!is_null($filepath2)){
+ if($proxy->$operation($filepath,$filepath2)===false){
return false;
}
}else{
- if(!$proxy->$operation($filepath)){
+ if($proxy->$operation($filepath)===false){
return false;
}
}
@@ -101,6 +105,9 @@ class OC_FileProxy{
}
public static function runPostProxies($operation,$path,$result){
+ if(!self::$enabled){
+ return $result;
+ }
$proxies=self::getProxies($operation,true);
$operation='post'.$operation;
foreach($proxies as $proxy){
diff --git a/lib/filestorage.php b/lib/filestorage.php
index 4523144f6f4..d420427225b 100644
--- a/lib/filestorage.php
+++ b/lib/filestorage.php
@@ -45,8 +45,6 @@ class OC_Filestorage{
public function rename($path1,$path2){}
public function copy($path1,$path2){}
public function fopen($path,$mode){}
- public function toTmpFile($path){}//copy the file to a temporary file, used for cross-storage file actions
- public function fromTmpFile($tmpPath,$path){}//copy a file from a temporary file, used for cross-storage file actions
public function getMimeType($path){}
public function hash($type,$path,$raw){}
public function free_space($path){}
diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php
index dcb516a3afb..6f4f68c503d 100644
--- a/lib/filestorage/local.php
+++ b/lib/filestorage/local.php
@@ -74,7 +74,7 @@ class OC_Filestorage_Local extends OC_Filestorage{
public function file_get_contents($path){
return file_get_contents($this->datadir.$path);
}
- public function file_put_contents($path,$data){
+ public function file_put_contents($path,$data=null){
if($return=file_put_contents($this->datadir.$path,$data)){
}
}
@@ -122,72 +122,9 @@ class OC_Filestorage_Local extends OC_Filestorage{
return $return;
}
- public function getMimeType($fspath){
- if($this->is_readable($fspath)){
- $mimeType='application/octet-stream';
- if ($mimeType=='application/octet-stream') {
- self::$mimetypes = include('mimetypes.fixlist.php');
- $extention=strtolower(strrchr(basename($fspath), "."));
- $extention=substr($extention,1);//remove leading .
- $mimeType=(isset(self::$mimetypes[$extention]))?self::$mimetypes[$extention]:'application/octet-stream';
-
- }
- if (@is_dir($this->datadir.$fspath)) {
- // directories are easy
- return "httpd/unix-directory";
- }
- if($mimeType=='application/octet-stream' and function_exists('finfo_open') and function_exists('finfo_file') and $finfo=finfo_open(FILEINFO_MIME)){
- $mimeType =strtolower(finfo_file($finfo,$this->datadir.$fspath));
- $mimeType=substr($mimeType,0,strpos($mimeType,';'));
- finfo_close($finfo);
- }
- if ($mimeType=='application/octet-stream' && function_exists("mime_content_type")) {
- // use mime magic extension if available
- $mimeType = mime_content_type($this->datadir.$fspath);
- }
- if ($mimeType=='application/octet-stream' && OC_Helper::canExecute("file")) {
- // it looks like we have a 'file' command,
- // lets see it it does have mime support
- $fspath=str_replace("'","\'",$fspath);
- $fp = popen("file -i -b '{$this->datadir}$fspath' 2>/dev/null", "r");
- $reply = fgets($fp);
- pclose($fp);
-
- //trim the character set from the end of the response
- $mimeType=substr($reply,0,strrpos($reply,' '));
- }
- if ($mimeType=='application/octet-stream') {
- // Fallback solution: (try to guess the type by the file extension
- if(!self::$mimetypes || self::$mimetypes != include('mimetypes.list.php')){
- self::$mimetypes=include('mimetypes.list.php');
- }
- $extention=strtolower(strrchr(basename($fspath), "."));
- $extention=substr($extention,1);//remove leading .
- $mimeType=(isset(self::$mimetypes[$extention]))?self::$mimetypes[$extention]:'application/octet-stream';
- }
- return $mimeType;
- }else{
- return false;
- }
- }
-
- public function toTmpFile($path){
- $tmpFolder=get_temp_dir();
- $filename=tempnam($tmpFolder,'OC_TEMP_FILE_'.substr($path,strrpos($path,'.')));
- $fileStats = stat($this->datadir.$path);
- if(copy($this->datadir.$path,$filename)){
- touch($filename, $fileStats['mtime'], $fileStats['atime']);
- return $filename;
- }else{
- return false;
- }
- }
-
- public function fromTmpFile($tmpFile,$path){
- $fileStats = stat($tmpFile);
- if(rename($tmpFile,$this->datadir.$path)){
- touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']);
- return true;
+ public function getMimeType($path){
+ if($this->is_readable($path)){
+ return OC_Helper::getMimeType($this->datadir.$path);
}else{
return false;
}
diff --git a/lib/filesystemview.php b/lib/filesystemview.php
index 91c6cd17720..c4d5ff35142 100644
--- a/lib/filesystemview.php
+++ b/lib/filesystemview.php
@@ -163,7 +163,22 @@ class OC_FilesystemView {
return $this->basicOperation('file_get_contents',$path,array('read'));
}
public function file_put_contents($path,$data){
- return $this->basicOperation('file_put_contents',$path,array('create','write'),$data);
+ if(is_resource($data)){//not having to deal with streams in file_put_contents makes life easier
+ $target=$this->fopen($path,'w');
+ if($target){
+ while(!feof($data)){
+ fwrite($target,fread($data,8192));
+ }
+ fclose($target);
+ fclose($data);
+ OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, array( OC_Filesystem::signal_param_path => $path));
+ return true;
+ }else{
+ return false;
+ }
+ }else{
+ return $this->basicOperation('file_put_contents',$path,array('create','write'),$data);
+ }
}
public function unlink($path){
return $this->basicOperation('unlink',$path,array('delete'));
@@ -179,9 +194,13 @@ class OC_FilesystemView {
if($storage=$this->getStorage($path1)){
$result=$storage->rename($this->getInternalPath($path1),$this->getInternalPath($path2));
}
- }elseif($storage1=$this->getStorage($path1) and $storage2=$this->getStorage($path2)){
- $tmpFile=$storage1->toTmpFile($this->getInternalPath($path1));
- $result=$storage2->fromTmpFile($tmpFile,$this->getInternalPath($path2));
+ }else{
+ $source=$this->fopen($path1,'r');
+ $target=$this->fopen($path2,'w');
+ while (!feof($source)){
+ fwrite($target,fread($source,8192));
+ }
+ $storage1=$this->getStorage($path1);
$storage1->unlink($this->getInternalPath($path1));
}
OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_rename, array( OC_Filesystem::signal_param_oldpath => $path1, OC_Filesystem::signal_param_newpath=>$path2));
@@ -207,9 +226,14 @@ class OC_FilesystemView {
if($storage=$this->getStorage($path1)){
$result=$storage->copy($this->getInternalPath($path1),$this->getInternalPath($path2));
}
- }elseif($storage1=$this->getStorage($path1) and $storage2=$this->getStorage($path2)){
- $tmpFile=$storage1->toTmpFile($this->getInternalPath($path1));
- $result=$storage2->fromTmpFile($tmpFile,$this->getInternalPath($path2));
+ }else{
+ $source=$this->fopen($path1,'r');
+ $target=$this->fopen($path2,'w');
+ if($target and $source){
+ while (!feof($source)){
+ fwrite($target,fread($source,8192));
+ }
+ }
}
OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_copy, array( OC_Filesystem::signal_param_oldpath => $path1 , OC_Filesystem::signal_param_newpath=>$path2));
if(!$exists){
@@ -245,29 +269,28 @@ class OC_FilesystemView {
return $this->basicOperation('fopen',$path,$hooks,$mode);
}
public function toTmpFile($path){
- if(OC_FileProxy::runPreProxies('toTmpFile',$path) and OC_Filesystem::isValidPath($path) and $storage=$this->getStorage($path)){
- OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_read, array( OC_Filesystem::signal_param_path => $path));
- return $storage->toTmpFile($this->getInternalPath($path));
+ if(OC_Filesystem::isValidPath($path)){
+ $source=$this->fopen($path,'r');
+ $tmpFile=tempnam(get_temp_dir(),'OC_TMP_').substr($path,strrpos($path,'.'));
+ if($source){
+ return file_put_contents($tmpFile,$source);
+ }
}
}
public function fromTmpFile($tmpFile,$path){
- if(OC_FileProxy::runPreProxies('copy',$tmpFile,$path) and OC_Filesystem::isValidPath($path) and $storage=$this->getStorage($path)){
- $run=true;
- $exists=$this->file_exists($path);
- if(!$exists){
- OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_create, array( OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run));
- }
- if($run){
- OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_write, array( OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run));
+ if(OC_Filesystem::isValidPath($path)){
+ if(!$tmpFile){
+ debug_print_backtrace();
}
- if($run){
- $result=$storage->fromTmpFile($tmpFile,$this->getInternalPath($path));
- if(!$exists){
- OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_create, array( OC_Filesystem::signal_param_path => $path));
- }
- OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, array( OC_Filesystem::signal_param_path => $path));
- return $result;
+ $source=fopen($tmpFile,'r');
+ if($source){
+ $this->file_put_contents($path,$source);
+ unlink($tmpFile);
+ return true;
+ }else{
}
+ }else{
+ return false;
}
}
@@ -294,23 +317,29 @@ class OC_FilesystemView {
if(OC_FileProxy::runPreProxies($operation,$path, $extraParam) and OC_Filesystem::isValidPath($path) and $storage=$this->getStorage($path)){
$interalPath=$this->getInternalPath($path);
$run=true;
- foreach($hooks as $hook){
- if($hook!='read'){
- OC_Hook::emit( OC_Filesystem::CLASSNAME, $hook, array( OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run));
- }else{
- OC_Hook::emit( OC_Filesystem::CLASSNAME, $hook, array( OC_Filesystem::signal_param_path => $path));
+ if(OC_Filesystem::$loaded and $this->fakeRoot==OC_Filesystem::getRoot()){
+ foreach($hooks as $hook){
+ if($hook!='read'){
+ OC_Hook::emit( OC_Filesystem::CLASSNAME, $hook, array( OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run));
+ }else{
+ OC_Hook::emit( OC_Filesystem::CLASSNAME, $hook, array( OC_Filesystem::signal_param_path => $path));
+ }
}
}
if($run){
- if($extraParam){
+ if(!is_null($extraParam)){
$result=$storage->$operation($interalPath,$extraParam);
}else{
$result=$storage->$operation($interalPath);
}
$result=OC_FileProxy::runPostProxies($operation,$path,$result);
- foreach($hooks as $hook){
- if($hook!='read'){
- OC_Hook::emit( OC_Filesystem::CLASSNAME, 'post_'.$hook, array( OC_Filesystem::signal_param_path => $path));
+ if(OC_Filesystem::$loaded and $this->fakeRoot==OC_Filesystem::getRoot()){
+ if($operation!='fopen'){//no post hooks for fopen, the file stream is still open
+ foreach($hooks as $hook){
+ if($hook!='read'){
+ OC_Hook::emit( OC_Filesystem::CLASSNAME, 'post_'.$hook, array( OC_Filesystem::signal_param_path => $path));
+ }
+ }
}
}
return $result;
diff --git a/lib/helper.php b/lib/helper.php
index 2f71bdad2dc..6dea4a6a8cd 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -25,6 +25,8 @@
* Collection of useful functions
*/
class OC_Helper {
+ private static $mimetypes=array();
+
/**
* @brief Creates an url
* @param $app app
@@ -267,6 +269,62 @@ class OC_Helper {
unlink($dir);
}
}
+
+ /**
+ * get the mimetype form a local file
+ * @param string path
+ * @return string
+ * does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead
+ */
+ static function getMimeType($path){
+ $isWrapped=(strpos($path,'://')!==false) and (substr($path,0,7)=='file://');
+ $mimeType='application/octet-stream';
+ if ($mimeType=='application/octet-stream') {
+ if(count(self::$mimetypes)>0){
+ self::$mimetypes = include('mimetypes.fixlist.php');
+ }
+ $extention=strtolower(strrchr(basename($path), "."));
+ $extention=substr($extention,1);//remove leading .
+ $mimeType=(isset(self::$mimetypes[$extention]))?self::$mimetypes[$extention]:'application/octet-stream';
+
+ }
+ if (@is_dir($path)) {
+ // directories are easy
+ return "httpd/unix-directory";
+ }
+ if($mimeType=='application/octet-stream' and function_exists('finfo_open') and function_exists('finfo_file') and $finfo=finfo_open(FILEINFO_MIME)){
+ $info = @strtolower(finfo_file($finfo,$path));
+ if($info){
+ $mimeType=substr($info,0,strpos($info,';'));
+ }
+ finfo_close($finfo);
+ }
+ if (!$isWrapped and $mimeType=='application/octet-stream' && function_exists("mime_content_type")) {
+ // use mime magic extension if available
+ $mimeType = mime_content_type($path);
+ }
+ if (!$isWrapped and $mimeType=='application/octet-stream' && OC_Helper::canExecute("file")) {
+ // it looks like we have a 'file' command,
+ // lets see it it does have mime support
+ $path=str_replace("'","\'",$path);
+ $fp = popen("file -i -b '$path' 2>/dev/null", "r");
+ $reply = fgets($fp);
+ pclose($fp);
+
+ //trim the character set from the end of the response
+ $mimeType=substr($reply,0,strrpos($reply,' '));
+ }
+ if ($mimeType=='application/octet-stream') {
+ // Fallback solution: (try to guess the type by the file extension
+ if(!self::$mimetypes || self::$mimetypes != include('mimetypes.list.php')){
+ self::$mimetypes=include('mimetypes.list.php');
+ }
+ $extention=strtolower(strrchr(basename($path), "."));
+ $extention=substr($extention,1);//remove leading .
+ $mimeType=(isset(self::$mimetypes[$extention]))?self::$mimetypes[$extention]:'application/octet-stream';
+ }
+ return $mimeType;
+ }
/**
* @brief Checks $_REQUEST contains a var for the $s key. If so, returns the html-escaped value of this var; otherwise returns the default value provided by $d.
diff --git a/lib/streamwrappers.php b/lib/streamwrappers.php
new file mode 100644
index 00000000000..1454a99e8d5
--- /dev/null
+++ b/lib/streamwrappers.php
@@ -0,0 +1,223 @@
+<?php
+global $FAKEDIRS;
+$FAKEDIRS=array();
+
+class OC_FakeDirStream{
+ public static $dirs=array();
+ private $name;
+ private $index;
+
+ public function dir_opendir($path,$options){
+ global $FAKEDIRS;
+ $url=parse_url($path);
+ $this->name=substr($path,strlen('fakedir://'));
+ $this->index=0;
+ if(!isset(self::$dirs[$this->name])){
+ self::$dirs[$this->name]=array();
+ }
+ return true;
+ }
+
+ public function dir_readdir(){
+ if($this->index>=count(self::$dirs[$this->name])){
+ return false;
+ }
+ $filename=self::$dirs[$this->name][$this->index];
+ $this->index++;
+ return $filename;
+ }
+
+ public function dir_closedir() {
+ $this->name='';
+ return true;
+ }
+
+ public function dir_rewinddir() {
+ $this->index=0;
+ return true;
+ }
+}
+
+class OC_StaticStreamWrapper {
+ public $context;
+ protected static $data = array();
+
+ protected $path = '';
+ protected $pointer = 0;
+ protected $writable = false;
+
+ public function stream_close() {}
+
+ public function stream_eof() {
+ return $this->pointer >= strlen(self::$data[$this->path]);
+ }
+
+ public function stream_flush() {}
+
+ public function stream_open($path, $mode, $options, &$opened_path) {
+ switch ($mode[0]) {
+ case 'r':
+ if (!isset(self::$data[$path])) return false;
+ $this->path = $path;
+ $this->writable = isset($mode[1]) && $mode[1] == '+';
+ break;
+ case 'w':
+ self::$data[$path] = '';
+ $this->path = $path;
+ $this->writable = true;
+ break;
+ case 'a':
+ if (!isset(self::$data[$path])) self::$data[$path] = '';
+ $this->path = $path;
+ $this->writable = true;
+ $this->pointer = strlen(self::$data[$path]);
+ break;
+ case 'x':
+ if (isset(self::$data[$path])) return false;
+ $this->path = $path;
+ $this->writable = true;
+ break;
+ case 'c':
+ if (!isset(self::$data[$path])) self::$data[$path] = '';
+ $this->path = $path;
+ $this->writable = true;
+ break;
+ default:
+ return false;
+ }
+ $opened_path = $this->path;
+ return true;
+ }
+
+ public function stream_read($count) {
+ $bytes = min(strlen(self::$data[$this->path]) - $this->pointer, $count);
+ $data = substr(self::$data[$this->path], $this->pointer, $bytes);
+ $this->pointer += $bytes;
+ return $data;
+ }
+
+ public function stream_seek($offset, $whence = SEEK_SET) {
+ $len = strlen(self::$data[$this->path]);
+ switch ($whence) {
+ case SEEK_SET:
+ if ($offset <= $len) {
+ $this->pointer = $offset;
+ return true;
+ }
+ break;
+ case SEEK_CUR:
+ if ($this->pointer + $offset <= $len) {
+ $this->pointer += $offset;
+ return true;
+ }
+ break;
+ case SEEK_END:
+ if ($len + $offset <= $len) {
+ $this->pointer = $len + $offset;
+ return true;
+ }
+ break;
+ }
+ return false;
+ }
+
+ public function stream_stat() {
+ $size = strlen(self::$data[$this->path]);
+ $time = time();
+ return array(
+ 0 => 0,
+ 'dev' => 0,
+ 1 => 0,
+ 'ino' => 0,
+ 2 => 0777,
+ 'mode' => 0777,
+ 3 => 1,
+ 'nlink' => 1,
+ 4 => 0,
+ 'uid' => 0,
+ 5 => 0,
+ 'gid' => 0,
+ 6 => '',
+ 'rdev' => '',
+ 7 => $size,
+ 'size' => $size,
+ 8 => $time,
+ 'atime' => $time,
+ 9 => $time,
+ 'mtime' => $time,
+ 10 => $time,
+ 'ctime' => $time,
+ 11 => -1,
+ 'blksize' => -1,
+ 12 => -1,
+ 'blocks' => -1,
+ );
+ }
+
+ public function stream_tell() {
+ return $this->pointer;
+ }
+
+ public function stream_write($data) {
+ if (!$this->writable) return 0;
+ $size = strlen($data);
+ $len = strlen(self::$data[$this->path]);
+ if ($this->stream_eof()) {
+ self::$data[$this->path] .= $data;
+ } else {
+ self::$data[$this->path] = substr_replace(
+ self::$data[$this->path],
+ $data,
+ $this->pointer
+ );
+ }
+ $this->pointer += $size;
+ return $size;
+ }
+
+ public function unlink($path) {
+ if (isset(self::$data[$path])) {
+ unset(self::$data[$path]);
+ }
+ return true;
+ }
+
+ public function url_stat($path) {
+ if (isset(self::$data[$path])) {
+ $size = strlen(self::$data[$path]);
+ $time = time();
+ return array(
+ 0 => 0,
+ 'dev' => 0,
+ 1 => 0,
+ 'ino' => 0,
+ 2 => 0777,
+ 'mode' => 0777,
+ 3 => 1,
+ 'nlink' => 1,
+ 4 => 0,
+ 'uid' => 0,
+ 5 => 0,
+ 'gid' => 0,
+ 6 => '',
+ 'rdev' => '',
+ 7 => $size,
+ 'size' => $size,
+ 8 => $time,
+ 'atime' => $time,
+ 9 => $time,
+ 'mtime' => $time,
+ 10 => $time,
+ 'ctime' => $time,
+ 11 => -1,
+ 'blksize' => -1,
+ 12 => -1,
+ 'blocks' => -1,
+ );
+ }
+ return false;
+ }
+}
+
+stream_wrapper_register("fakedir", "OC_FakeDirStream");
+stream_wrapper_register('static', 'OC_StaticStreamWrapper');
diff --git a/lib/user.php b/lib/user.php
index 0746fcc6eb4..fda19a33154 100644
--- a/lib/user.php
+++ b/lib/user.php
@@ -195,8 +195,9 @@ class OC_User {
if( $run ){
$uid=self::checkPassword( $uid, $password );
if($uid){
- OC_Crypt::init($uid,$password);
- return self::setUserId($uid);
+ self::setUserId($uid);
+ OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid, 'password'=>$password ));
+ return true;
}
}
return false;
@@ -209,7 +210,6 @@ class OC_User {
*/
public static function setUserId($uid) {
$_SESSION['user_id'] = $uid;
- OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid ));
return true;
}
diff --git a/lib/util.php b/lib/util.php
index 05caeca0e3e..2fd1dd543d6 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -8,6 +8,7 @@ class OC_Util {
public static $scripts=array();
public static $styles=array();
public static $headers=array();
+ private static $rootMounted=false;
private static $fsSetup=false;
// Can be set up
@@ -35,9 +36,12 @@ class OC_Util {
$user = OC_User::getUser();
}
- if( $user != "" ){ //if we aren't logged in, there is no use to set up the filesystem
- //first set up the local "root" storage
+ //first set up the local "root" storage
+ if(!self::$rootMounted){
OC_Filesystem::mount('OC_Filestorage_Local',array('datadir'=>$CONFIG_DATADIRECTORY_ROOT),'/');
+ self::$rootMounted=true;
+ }
+ if( $user != "" ){ //if we aren't logged in, there is no use to set up the filesystem
OC::$CONFIG_DATADIRECTORY = $CONFIG_DATADIRECTORY_ROOT."/$user/$root";
if( !is_dir( OC::$CONFIG_DATADIRECTORY )){