diff --git a/3rdparty/MDB2/Schema/Parser.php b/3rdparty/MDB2/Schema/Parser.php index cfd0c37d8a..3c4345661b 100644 --- a/3rdparty/MDB2/Schema/Parser.php +++ b/3rdparty/MDB2/Schema/Parser.php @@ -146,33 +146,6 @@ class MDB2_Schema_Parser extends XML_Parser ); } - /** - * PHP 4 compatible constructor - * - * @param array $variables mixed array with user defined schema - * variables - * @param bool $fail_on_invalid_names array with reserved words per RDBMS - * @param array $structure multi dimensional array with - * database schema and data - * @param array $valid_types information of all valid fields - * types - * @param bool $force_defaults if true sets a default value to - * field when not explicit - * @param int $max_identifiers_length maximum allowed size for entities - * name - * - * @return void - * - * @access public - * @static - */ - function MDB2_Schema_Parser($variables, $fail_on_invalid_names = true, - $structure = false, $valid_types = array(), $force_defaults = true, - $max_identifiers_length = null - ) { - $this->__construct($variables, $fail_on_invalid_names, $structure, $valid_types, $force_defaults); - } - /** * Triggered when reading a XML open tag * diff --git a/3rdparty/MDB2/Schema/Parser2.php b/3rdparty/MDB2/Schema/Parser2.php index b415b4a336..f27dffbabf 100644 --- a/3rdparty/MDB2/Schema/Parser2.php +++ b/3rdparty/MDB2/Schema/Parser2.php @@ -143,33 +143,6 @@ class MDB2_Schema_Parser2 extends XML_Unserializer parent::XML_Unserializer($this->options); } - /** - * PHP 4 compatible constructor - * - * @param array $variables mixed array with user defined schema - * variables - * @param bool $fail_on_invalid_names array with reserved words per RDBMS - * @param array $structure multi dimensional array with - * database schema and data - * @param array $valid_types information of all valid fields - * types - * @param bool $force_defaults if true sets a default value to - * field when not explicit - * @param int $max_identifiers_length maximum allowed size for entities - * name - * - * @return void - * - * @access public - * @static - */ - function MDB2_Schema_Parser2($variables, $fail_on_invalid_names = true, - $structure = false, $valid_types = array(), $force_defaults = true, - $max_identifiers_length = null - ) { - $this->__construct($variables, $fail_on_invalid_names, $structure, $valid_types, $force_defaults); - } - /** * Main method. Parses XML Schema File. * diff --git a/3rdparty/MDB2/Schema/Validate.php b/3rdparty/MDB2/Schema/Validate.php index 4cff175576..4a8e0d27ba 100644 --- a/3rdparty/MDB2/Schema/Validate.php +++ b/3rdparty/MDB2/Schema/Validate.php @@ -108,28 +108,6 @@ class MDB2_Schema_Validate $this->max_identifiers_length = $max_identifiers_length; } - /** - * PHP 4 compatible constructor - * - * @param bool $fail_on_invalid_names array with reserved words per RDBMS - * @param array $valid_types information of all valid fields - * types - * @param bool $force_defaults if true sets a default value to - * field when not explicit - * @param int $max_identifiers_length maximum allowed size for entities - * name - * - * @return void - * - * @access public - * @static - */ - function MDB2_Schema_Validate($fail_on_invalid_names = true, $valid_types = array(), - $force_defaults = true, $max_identifiers_length = null - ) { - $this->__construct($fail_on_invalid_names, $valid_types, $force_defaults); - } - // }}} // {{{ raiseError() diff --git a/3rdparty/MDB2/Schema/Writer.php b/3rdparty/MDB2/Schema/Writer.php index 70a03168de..96dd2bed0f 100644 --- a/3rdparty/MDB2/Schema/Writer.php +++ b/3rdparty/MDB2/Schema/Writer.php @@ -80,23 +80,6 @@ class MDB2_Schema_Writer function __construct($valid_types = array()) { $this->valid_types = $valid_types; - } - - /** - * PHP 4 compatible constructor - * - * @param array $valid_types information of all valid fields - * types - * - * @return void - * - * @access public - * @static - */ - function MDB2_Schema_Writer($valid_types = array()) - { - $this->__construct($valid_types); - } // }}} // {{{ raiseError() diff --git a/apps/calendar/ajax/events.php b/apps/calendar/ajax/events.php index ccf6102ab4..6ea89e3e5b 100644 --- a/apps/calendar/ajax/events.php +++ b/apps/calendar/ajax/events.php @@ -7,6 +7,7 @@ */ OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('calendar'); +session_write_close(); // Look for the calendar id $calendar_id = null; diff --git a/apps/files/ajax/scan.php b/apps/files/ajax/scan.php index d695ce8161..6fcf97688c 100644 --- a/apps/files/ajax/scan.php +++ b/apps/files/ajax/scan.php @@ -10,6 +10,7 @@ if(!$checkOnly){ $eventSource=new OC_EventSource(); } +session_write_close(); //create the file cache if necesary if($force or !OC_FileCache::inCache('')){ diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php index d2b8ad145a..4c0ffa978e 100644 --- a/apps/files_encryption/lib/crypt.php +++ b/apps/files_encryption/lib/crypt.php @@ -43,22 +43,22 @@ class OC_Crypt { self::init($params['uid'],$params['password']); } - public static function init($login,$password) { - $view1=new OC_FilesystemView('/'); - if(!$view1->file_exists('/'.$login)){ - $view1->mkdir('/'.$login); - } + public static function init($login,$password) { + $view1=new OC_FilesystemView('/'); + if(!$view1->file_exists('/'.$login)){ + $view1->mkdir('/'.$login); + } - $view=new OC_FilesystemView('/'.$login); - - OC_FileProxy::$enabled=false; - if(!$view->file_exists('/encryption.key')){// does key exist? - OC_Crypt::createkey($login,$password); - } - $key=$view->file_get_contents('/encryption.key'); - OC_FileProxy::$enabled=true; - $_SESSION['enckey']=OC_Crypt::decrypt($key, $password); - } + $view=new OC_FilesystemView('/'.$login); + + OC_FileProxy::$enabled=false; + if(!$view->file_exists('/encryption.key')){// does key exist? + OC_Crypt::createkey($login,$password); + } + $key=$view->file_get_contents('/encryption.key'); + OC_FileProxy::$enabled=true; + $_SESSION['enckey']=OC_Crypt::decrypt($key, $password); + } /** @@ -140,7 +140,7 @@ class OC_Crypt { public static function decrypt( $content, $key='') { $bf = self::getBlowfish($key); $data=$bf->decrypt($content); - return rtrim($data, "\0"); + return $data; } /** @@ -181,6 +181,9 @@ class OC_Crypt { while (!feof($handleread)) { $content = fread($handleread, 8192); $enccontent=OC_CRYPT::decrypt( $content, $key); + if(feof($handleread)){ + $enccontent=rtrim($enccontent, "\0"); + } fwrite($handlewrite, $enccontent); } fclose($handlewrite); @@ -209,6 +212,6 @@ class OC_Crypt { $result.=self::decrypt(substr($data,0,8192),$key); $data=substr($data,8192); } - return $result; + return rtrim($result, "\0"); } } diff --git a/apps/files_encryption/lib/cryptstream.php b/apps/files_encryption/lib/cryptstream.php index a698ee0033..56331cbf60 100644 --- a/apps/files_encryption/lib/cryptstream.php +++ b/apps/files_encryption/lib/cryptstream.php @@ -47,7 +47,6 @@ class OC_CryptStream{ $this->path=self::$sourceStreams[basename($path)]['path']; }else{ $this->path=$path; - OCP\Util::writeLog('files_encryption','open encrypted '.$path. ' in '.$mode,OCP\Util::DEBUG); OC_FileProxy::$enabled=false;//disable fileproxies so we can open the source file $this->source=self::$rootView->fopen($path,$mode); OC_FileProxy::$enabled=true; @@ -84,6 +83,9 @@ class OC_CryptStream{ }else{ $result=''; } + if($this->stream_eof()){ + $result=rtrim($result, "\0"); + } return $result; } diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index ad9bcf55f2..b9e719448a 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -67,7 +67,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{ if(self::shouldEncrypt($path)){ if (!is_resource($data)) {//stream put contents should have been converter to fopen $data=OC_Crypt::blockEncrypt($data); - OC_FileCache::put($path,array('encrypted'=>true)); + OC_FileCache::put($path,array('encrypted'=>true),''); } } } diff --git a/apps/files_encryption/tests/binary b/apps/files_encryption/tests/binary new file mode 100644 index 0000000000..79bc99479d Binary files /dev/null and b/apps/files_encryption/tests/binary differ diff --git a/apps/files_encryption/tests/encryption.php b/apps/files_encryption/tests/encryption.php index cf24a225d2..70aa1daf4c 100644 --- a/apps/files_encryption/tests/encryption.php +++ b/apps/files_encryption/tests/encryption.php @@ -13,6 +13,7 @@ class Test_Encryption extends UnitTestCase { $source=file_get_contents($file); //nice large text file $encrypted=OC_Crypt::encrypt($source,$key); $decrypted=OC_Crypt::decrypt($encrypted,$key); + $decrypted=rtrim($decrypted, "\0"); $this->assertNotEqual($encrypted,$source); $this->assertEqual($decrypted,$source); @@ -20,6 +21,7 @@ class Test_Encryption extends UnitTestCase { $encrypted=OC_Crypt::encrypt($chunk,$key); $this->assertEqual(strlen($chunk),strlen($encrypted)); $decrypted=OC_Crypt::decrypt($encrypted,$key); + $decrypted=rtrim($decrypted, "\0"); $this->assertEqual($decrypted,$chunk); $encrypted=OC_Crypt::blockEncrypt($source,$key); @@ -43,6 +45,7 @@ class Test_Encryption extends UnitTestCase { $source=file_get_contents($file); //binary file $encrypted=OC_Crypt::encrypt($source,$key); $decrypted=OC_Crypt::decrypt($encrypted,$key); + $decrypted=rtrim($decrypted, "\0"); $this->assertEqual($decrypted,$source); $encrypted=OC_Crypt::blockEncrypt($source,$key); @@ -50,4 +53,20 @@ class Test_Encryption extends UnitTestCase { $this->assertEqual($decrypted,$source); } + + function testBinary(){ + $key=uniqid(); + + $file=__DIR__.'/binary'; + $source=file_get_contents($file); //binary file + $encrypted=OC_Crypt::encrypt($source,$key); + $decrypted=OC_Crypt::decrypt($encrypted,$key); + + $decrypted=rtrim($decrypted, "\0"); + $this->assertEqual($decrypted,$source); + + $encrypted=OC_Crypt::blockEncrypt($source,$key); + $decrypted=OC_Crypt::blockDecrypt($encrypted,$key); + $this->assertEqual($decrypted,$source); + } } diff --git a/apps/files_encryption/tests/proxy.php b/apps/files_encryption/tests/proxy.php index f36b219343..5616e2091a 100644 --- a/apps/files_encryption/tests/proxy.php +++ b/apps/files_encryption/tests/proxy.php @@ -7,8 +7,13 @@ */ class Test_CryptProxy extends UnitTestCase { + private $oldConfig; public function setUp(){ + $this->oldConfig=OCP\Config::getAppValue('files_encryption','enable_encryption','true'); + OCP\Config::setAppValue('files_encryption','enable_encryption','true'); + + //set testing key $_SESSION['enckey']=md5(time()); @@ -29,10 +34,11 @@ class Test_CryptProxy extends UnitTestCase { $rootView->mkdir('/'.OC_User::getUser().'/files'); } + public function tearDown(){ + OCP\Config::setAppValue('files_encryption','enable_encryption',$this->oldConfig); + } + public function testSimple(){ - $oldConfig=OCP\Config::getAppValue('files_encryption','enable_encryption','true'); - OCP\Config::setAppValue('files_encryption','enable_encryption','true'); - $file=OC::$SERVERROOT.'/3rdparty/MDB2.php'; $original=file_get_contents($file); @@ -46,16 +52,42 @@ class Test_CryptProxy extends UnitTestCase { $this->assertNotEqual($original,$stored); $this->assertEqual($original,$fromFile); + } + + public function testView(){ + $file=OC::$SERVERROOT.'/3rdparty/MDB2.php'; + $original=file_get_contents($file); + $rootView=new OC_FilesystemView(''); $view=new OC_FilesystemView('/'.OC_User::getUser()); $userDir='/'.OC_User::getUser().'/files'; + $rootView->file_put_contents($userDir.'/file',$original); + + OC_FileProxy::$enabled=false; + $stored=$rootView->file_get_contents($userDir.'/file'); + OC_FileProxy::$enabled=true; + + $this->assertNotEqual($original,$stored); $fromFile=$rootView->file_get_contents($userDir.'/file'); $this->assertEqual($original,$fromFile); $fromFile=$view->file_get_contents('files/file'); $this->assertEqual($original,$fromFile); + } - OCP\Config::setAppValue('files_encryption','enable_encryption',$oldConfig); + public function testBinary(){ + $file=__DIR__.'/binary'; + $original=file_get_contents($file); + + OC_Filesystem::file_put_contents('/file',$original); + + OC_FileProxy::$enabled=false; + $stored=OC_Filesystem::file_get_contents('/file'); + OC_FileProxy::$enabled=true; + + $fromFile=OC_Filesystem::file_get_contents('/file'); + $this->assertNotEqual($original,$stored); + $this->assertEqual($original,$fromFile); } } diff --git a/apps/files_encryption/tests/stream.php b/apps/files_encryption/tests/stream.php index b23805d60b..4ffeb6210a 100644 --- a/apps/files_encryption/tests/stream.php +++ b/apps/files_encryption/tests/stream.php @@ -50,7 +50,22 @@ class Test_CryptStream extends UnitTestCase { $file=$this->tmpFiles[$id]; } $stream=fopen($file,$mode); - OC_CryptStream::$sourceStreams[$id]=array('path'=>'dummy','stream'=>$stream); + OC_CryptStream::$sourceStreams[$id]=array('path'=>'dummy'.$id,'stream'=>$stream); return fopen('crypt://streams/'.$id,$mode); } + + function testBinary(){ + $file=__DIR__.'/binary'; + $source=file_get_contents($file); + + $stream=$this->getStream('test','w'); + fwrite($stream,$source); + fclose($stream); + + $stream=$this->getStream('test','r'); + $data=stream_get_contents($stream); + fclose($stream); + $this->assertEqual(strlen($data),strlen($source)); + $this->assertEqual($source,$data); + } } diff --git a/apps/media/ajax/api.php b/apps/media/ajax/api.php index a229c17e80..23abc57927 100644 --- a/apps/media/ajax/api.php +++ b/apps/media/ajax/api.php @@ -46,6 +46,9 @@ if(!isset($arguments['album'])){ if(!isset($arguments['search'])){ $arguments['search']=''; } + +session_write_close(); + OC_MEDIA_COLLECTION::$uid=OCP\USER::getUser(); if($arguments['action']){ switch($arguments['action']){ diff --git a/apps/user_migrate/admin.php b/apps/user_migrate/admin.php deleted file mode 100644 index df8bff01c8..0000000000 --- a/apps/user_migrate/admin.php +++ /dev/null @@ -1,87 +0,0 @@ -. - * - */ -OCP\User::checkAdminUser(); -OCP\App::checkAppEnabled('user_migrate'); - -// Import? -if (isset($_POST['user_import'])) { - - $root = OC::$SERVERROOT . "/"; - $importname = "owncloud_import_" . date("y-m-d_H-i-s"); - - // Save data dir for later - $datadir = OCP\Config::getSystemValue( 'datadirectory' ); - - // Copy the uploaded file - $from = $_FILES['owncloud_import']['tmp_name']; - $to = get_temp_dir().'/'.$importname.'.zip'; - if( !move_uploaded_file( $from, $to ) ){ - $error = array('error'=>'Failed to move the uploaded file','hint'=>'Try checking the permissions of the '.get_temp_dir().' dir.'); - OCP\Util::writeLog( 'user_migrate', "Failed to copy the uploaded file", OCP\Util::ERROR ); - $tmpl = new OCP\Template('user_migrate', 'admin'); - $tmpl->assign('error',$error); - return $tmpl->fetchPage(); - } - $response = json_decode( OC_Migrate::import( $to, 'user' ) ); - if( !$response->success ){ - $error = array('error'=>'There was an error while importing the user!','hint'=>'Please check the logs for a more detailed explaination'); - $tmpl = new OCP\Template('user_migrate', 'admin'); - $tmpl->assign('error',$error); - return $tmpl->fetchPage(); - } else { - // Check import status - foreach( $response->data as $app => $status ){ - if( $status != 'true' ){ - // It failed for some reason - if( $status == 'notsupported' ){ - $notsupported[] = $app; - } else if( !$status ){ - $failed[] = $app; - } - } - } - // Any problems? - if( isset( $notsupported ) || isset( $failed ) ){ - if( count( $failed ) > 0 ){ - $error = array('error'=>'Some app data failed to import','hint'=>'App data for: '.implode(', ', $failed).' failed to import.'); - $tmpl = new OCP\Template('user_migrate', 'admin'); - $tmpl->assign('error',$error); - return $tmpl->fetchPage(); - } else if( count( $notsupported ) > 0 ){ - $error = array('error'=>'Some app data could not be imported, as the apps are not installed on this instance','hint'=>'App data for: '.implode(', ', $notsupported).' failed to import as they were not found. Please install the apps and try again'); - $tmpl = new OCP\Template('user_migrate', 'admin'); - $tmpl->assign('error',$error); - return $tmpl->fetchPage(); - } - } else { - // Went swimmingly! - $tmpl = new OCP\Template('user_migrate', 'admin'); - return $tmpl->fetchPage(); - } - } - -} else { -// fill template - $tmpl = new OCP\Template('user_migrate', 'admin'); - return $tmpl->fetchPage(); -} diff --git a/apps/user_migrate/settings.php b/apps/user_migrate/settings.php index 8edd035338..098927fa17 100644 --- a/apps/user_migrate/settings.php +++ b/apps/user_migrate/settings.php @@ -23,7 +23,67 @@ * */ OCP\App::checkAppEnabled('user_migrate'); +if (isset($_POST['user_import'])) { + $root = OC::$SERVERROOT . "/"; + $importname = "owncloud_import_" . date("y-m-d_H-i-s"); + + // Save data dir for later + $datadir = OCP\Config::getSystemValue( 'datadirectory' ); + + // Copy the uploaded file + $from = $_FILES['owncloud_import']['tmp_name']; + $to = get_temp_dir().'/'.$importname.'.zip'; + if( !move_uploaded_file( $from, $to ) ){ -// fill template -$tmpl = new OCP\Template('user_migrate', 'settings'); -return $tmpl->fetchPage(); \ No newline at end of file + $error = array('error'=>'Failed to move the uploaded file','hint'=>'Try checking the permissions of the '.get_temp_dir().' dir.'); + OCP\Util::writeLog( 'user_migrate', "Failed to copy the uploaded file", OCP\Util::ERROR ); + $tmpl = new OCP\Template('user_migrate', 'settings'); + $tmpl->assign('error',$error); + //return $tmpl->fetchPage(); + } + + + $response = json_decode( OC_Migrate::import( $to, 'user' ) ); + if( !$response->success ){ + $error = array('error'=>'There was an error while importing the user!','hint'=>'Please check the logs for a more detailed explaination'); + $tmpl = new OCP\Template('user_migrate', 'settings'); + $tmpl->assign('error',$error); + //return $tmpl->fetchPage(); + } else { + // Check import status + foreach( $response->data as $app => $status ){ + if( $status != 'true' ){ + // It failed for some reason + if( $status == 'notsupported' ){ + $notsupported[] = $app; + } else if( !$status ){ + $failed[] = $app; + } + } + } + // Any problems? + if( isset( $notsupported ) || isset( $failed ) ){ + if( count( $failed ) > 0 ){ + $error = array('error'=>'Some app data failed to import','hint'=>'App data for: '.implode(', ', $failed).' failed to import.'); + $tmpl = new OCP\Template('user_migrate', 'settings'); + $tmpl->assign('error',$error); + //return $tmpl->fetchPage(); + } else if( count( $notsupported ) > 0 ){ + $error = array('error'=>'Some app data could not be imported, as the apps are not installed on this instance','hint'=>'App data for: '.implode(', ', $notsupported).' failed to import as they were not found. Please install the apps and try again'); + $tmpl = new OCP\Template('user_migrate', 'settings'); + $tmpl->assign('error',$error); + //return $tmpl->fetchPage(); + } + } else { + // Went swimmingly! + $tmpl = new OCP\Template('user_migrate', 'settings'); + //return $tmpl->fetchPage(); + } + + } + +} else { + // fill template + $tmpl = new OCP\Template('user_migrate', 'settings'); + return $tmpl->fetchPage(); +} \ No newline at end of file diff --git a/apps/user_migrate/templates/admin.php b/apps/user_migrate/templates/admin.php deleted file mode 100644 index ff51f43ffd..0000000000 --- a/apps/user_migrate/templates/admin.php +++ /dev/null @@ -1,13 +0,0 @@ -
-
- -

-

- - t('Import user account');?> -

-

-

- -
-
diff --git a/apps/user_migrate/templates/settings.php b/apps/user_migrate/templates/settings.php index 8f1fe41df0..1718abe9e0 100644 --- a/apps/user_migrate/templates/settings.php +++ b/apps/user_migrate/templates/settings.php @@ -4,3 +4,16 @@

+
+
+ +

+

+ + t('Import user account');?> +

+

+

+ +
+
diff --git a/apps/user_webfinger/webfinger.php b/apps/user_webfinger/webfinger.php index e75c546c2c..39ab4ba6ba 100644 --- a/apps/user_webfinger/webfinger.php +++ b/apps/user_webfinger/webfinger.php @@ -17,13 +17,6 @@ header("Content-Type: application/xrd+json"); * '* but can also use complex database queries to generate the webfinger result **/ -// calculate the documentroot -// modified version of the one in lib/base.php that takes the .well-known symlink into account -/*$DOCUMENTROOT=realpath($_SERVER['DOCUMENT_ROOT']); -$SERVERROOT=str_replace("\\",'/',dirname(dirname(dirname(dirname(__FILE__))))); -$SUBURI=substr(realpath($_SERVER["SCRIPT_FILENAME"]),strlen($SERVERROOT)); -$WEBROOT=substr($SUBURI,0,-34); -*/ $userName = ''; $hostName = ''; diff --git a/lib/base.php b/lib/base.php index f85710ddfc..fedc123885 100644 --- a/lib/base.php +++ b/lib/base.php @@ -121,8 +121,7 @@ class OC{ } public static function initPaths(){ - // calculate the documentroot - $DOCUMENTROOT=realpath($_SERVER['DOCUMENT_ROOT']); + // calculate the root directories OC::$SERVERROOT=str_replace("\\",'/',substr(__FILE__,0,-13)); OC::$SUBURI= str_replace("\\","/",substr(realpath($_SERVER["SCRIPT_FILENAME"]),strlen(OC::$SERVERROOT))); $scriptName=$_SERVER["SCRIPT_NAME"]; @@ -137,9 +136,6 @@ class OC{ } } OC::$WEBROOT=substr($scriptName,0,strlen($scriptName)-strlen(OC::$SUBURI)); - // try a new way to detect the WEBROOT which is simpler and also works with the app directory outside the owncloud folder. let´s see if this works for everybody -// OC::$WEBROOT=substr(OC::$SERVERROOT,strlen($DOCUMENTROOT)); - if(OC::$WEBROOT!='' and OC::$WEBROOT[0]!=='/'){ OC::$WEBROOT='/'.OC::$WEBROOT; diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index 5aa70392d7..9832449af3 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -69,15 +69,13 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa if (!$info) throw new Sabre_DAV_Exception_NotFound('File with name ' . $path . ' could not be located'); if ($info['mimetype'] == 'httpd/unix-directory') { - - return new OC_Connector_Sabre_Directory($path, $info); - + $node = new OC_Connector_Sabre_Directory($path); } else { - - return new OC_Connector_Sabre_File($path, $info); - + $node = new OC_Connector_Sabre_File($path); } + $node->setFileinfoCache($info); + return $node; } /** @@ -87,10 +85,28 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa */ public function getChildren() { - $nodes = array(); $folder_content = OC_FileCache::getFolderContent($this->path); + $paths = array(); foreach($folder_content as $info) { - $nodes[] = $this->getChild($info['name'], $info); + $paths[] = $this->path.'/'.$info['name']; + } + $placeholders = join(',', array_fill(0, count($paths), '?')); + $query = OC_DB::prepare( 'SELECT * FROM *PREFIX*properties WHERE userid = ?' . ' AND propertypath IN ('.$placeholders.')' ); + array_unshift($paths, OC_User::getUser()); // prepend userid + $result = $query->execute( $paths ); + $properties = array_fill_keys($paths, array()); + while($row = $result->fetchRow()) { + $propertypath = $row['propertypath']; + $propertyname = $row['propertyname']; + $propertyvalue = $row['propertyvalue']; + $properties[$propertypath][$propertyname] = $propertyvalue; + } + + $nodes = array(); + foreach($folder_content as $info) { + $node = $this->getChild($info['name'], $info); + $node->setPropertyCache($properties[$this->path.'/'.$info['name']]); + $nodes[] = $node; } return $nodes; } diff --git a/lib/connector/sabre/node.php b/lib/connector/sabre/node.php index e5c059f0c8..be315a0ffd 100644 --- a/lib/connector/sabre/node.php +++ b/lib/connector/sabre/node.php @@ -30,10 +30,15 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr */ protected $path; /** - * file stat cache + * node fileinfo cache * @var array */ protected $fileinfo_cache; + /** + * node properties cache + * @var array + */ + protected $property_cache = null; /** * Sets up the node, expects a full path name @@ -41,11 +46,8 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr * @param string $path * @return void */ - public function __construct($path, $fileinfo_cache = null) { + public function __construct($path) { $this->path = $path; - if ($fileinfo_cache) { - $this->fileinfo_cache = $fileinfo_cache; - } } @@ -85,8 +87,13 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr } + public function setFileinfoCache($fileinfo_cache) + { + $this->fileinfo_cache = $fileinfo_cache; + } + /** - * Set the stat cache + * Make sure the fileinfo cache is filled. Uses OC_FileCache or a direct stat */ protected function getFileinfoCache() { if (!isset($this->fileinfo_cache)) { @@ -99,6 +106,11 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr } } + public function setPropertyCache($property_cache) + { + $this->property_cache = $property_cache; + } + /** * Returns the last modification time, as a unix timestamp * @@ -137,7 +149,7 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr } } else { - if( strcmp( $propertyName, "lastmodified")) { + if( strcmp( $propertyName, "lastmodified") === 0) { $this->touch($propertyValue); } else { if(!array_key_exists( $propertyName, $existing )){ @@ -151,6 +163,7 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr } } + $this->setPropertyCache(null); return true; } @@ -166,23 +179,24 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr * @return void */ function getProperties($properties) { - // At least some magic in here :-) - $query = OC_DB::prepare( 'SELECT * FROM *PREFIX*properties WHERE userid = ? AND propertypath = ?' ); - $result = $query->execute( array( OC_User::getUser(), $this->path )); + if (is_null($this->property_cache)) { + $query = OC_DB::prepare( 'SELECT * FROM *PREFIX*properties WHERE userid = ? AND propertypath = ?' ); + $result = $query->execute( array( OC_User::getUser(), $this->path )); - $existing = array(); - while( $row = $result->fetchRow()){ - $existing[$row['propertyname']] = $row['propertyvalue']; + $this->property_cache = array(); + while( $row = $result->fetchRow()){ + $this->property_cache[$row['propertyname']] = $row['propertyvalue']; + } } // if the array was empty, we need to return everything if(count($properties) == 0){ - return $existing; + return $this->property_cache; } $props = array(); foreach($properties as $property) { - if (isset($existing[$property])) $props[$property] = $existing[$property]; + if (isset($this->property_cache[$property])) $props[$property] = $this->property_cache[$property]; } return $props; } diff --git a/lib/filecache.php b/lib/filecache.php index 7c9c4dc41f..32c6929ff6 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -34,7 +34,7 @@ class OC_FileCache{ * @param string root (optional) * @return array * - * returns an assiciative array with the following keys: + * returns an associative array with the following keys: * - size * - mtime * - ctime diff --git a/lib/migrate.php b/lib/migrate.php index f9cab915d0..5939ba32e5 100644 --- a/lib/migrate.php +++ b/lib/migrate.php @@ -196,7 +196,7 @@ class OC_Migrate{ * @param optional $uid userid of new user */ public static function import( $path, $type='user', $uid=null ){ - OC_Util::checkAdminUser(); + $datadir = OC_Config::getValue( 'datadirectory' ); // Extract the zip if( !$extractpath = self::extractZip( $path ) ){ @@ -216,12 +216,19 @@ class OC_Migrate{ } self::$exporttype = $type; + $currentuser = OC_User::getUser(); + // Have we got a user if type is user if( self::$exporttype == 'user' ){ - if( !$uid ){ - self::$uid = $json->exporteduser; - } else { - self::$uid = $uid; + self::$uid = !is_null($uid) ? $uid : $currentuser; + } + + // We need to be an admin if we are not importing our own data + if(($type == 'user' && self::$uid != $currentuser) || $type != 'user' ){ + if( !OC_Group::inGroup( OC_User::getUser(), 'admin' )){ + // Naughty. + OC_Log::write( 'migration', 'Import not permitted.', OC_Log::ERROR ); + return json_encode( array( 'success' => false ) ); } } @@ -229,27 +236,8 @@ class OC_Migrate{ switch( self::$exporttype ){ case 'user': // Check user availability - if( OC_User::userExists( self::$uid ) ){ - OC_Log::write( 'migration', 'User already exists', OC_Log::ERROR ); - return json_encode( array( 'success' => false ) ); - } - $run = true; - OC_Hook::emit( "OC_User", "pre_createUser", array( "run" => &$run, "uid" => self::$uid, "password" => $json->hash )); - if( !$run ){ - // Something stopped the user creation - OC_Log::write( 'migration', 'User creation failed', OC_Log::ERROR ); - return json_encode( array( 'success' => false ) ); - } - // Create the user - if( !self::createUser( self::$uid, $json->hash ) ){ - return json_encode( array( 'success' => false ) ); - } - // Emit the post_createUser hook (password is already hashed, will cause problems - OC_Hook::emit( "OC_User", "post_createUser", array( "uid" => self::$uid, "password" => $json->hash )); - // Make the new users data dir - $path = $datadir . '/' . self::$uid; - if( !mkdir( $path, 0755, true ) ){ - OC_Log::write( 'migration', 'Failed to create users data dir: '.$path, OC_Log::ERROR ); + if( !OC_User::userExists( self::$uid ) ){ + OC_Log::write( 'migration', 'User doesn\'t exist', OC_Log::ERROR ); return json_encode( array( 'success' => false ) ); } // Copy data diff --git a/remote.php b/remote.php index b1be50f36a..0c5804221b 100644 --- a/remote.php +++ b/remote.php @@ -5,7 +5,7 @@ require_once('lib/base.php'); if (array_key_exists('PATH_INFO', $_SERVER)){ $path_info = $_SERVER['PATH_INFO']; }else{ - $path_info = substr($_SERVER['PHP_SELF'], strpos($_SERVER['PHP_SELF'], basename(__FILE__)) + strlen(basename(__FILE__))); + $path_info = substr($_SERVER['REQUEST_URI'], strlen($_SERVER['SCRIPT_NAME'])); } if ($path_info === false) { OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);