Merge branch 'master' into oc_error

This commit is contained in:
Georg Ehrke 2012-06-16 09:35:57 +02:00
commit 14f6d4dcba
25 changed files with 246 additions and 283 deletions

View file

@ -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 <element>
*

View file

@ -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.
*

View file

@ -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()

View file

@ -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()

View file

@ -11,6 +11,7 @@ require_once('when/When.php');
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('calendar');
session_write_close();
// Look for the calendar id
$calendar_id = null;

View file

@ -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('')){

View file

@ -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");
}
}

View file

@ -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;
}

View file

@ -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),'');
}
}
}

Binary file not shown.

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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']){

View file

@ -1,87 +0,0 @@
<?php
/**
* ownCloud - user_migrate
*
* @author Tom Needham
* @copyright 2012 Tom Needham tom@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/>.
*
*/
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();
}

View file

@ -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();
$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();
}

View file

@ -1,13 +0,0 @@
<form id="import" action="#" method="post" enctype="multipart/form-data">
<fieldset class="personalblock">
<?php if(isset($_['error'])){ ?>
<h3><?php echo $_['error']['error']; ?></h3>
<p><?php echo $_['error']['hint']; ?></p>
<?php } ?>
<legend><strong><?php echo $l->t('Import user account');?></strong></legend>
</p>
<p><input type="file" id="owncloud_import" name="owncloud_import" style="width:180px;"><label for="owncloud_import"> <?php echo $l->t('ownCloud User Zip');?></label>
</p>
<input type="submit" name="user_import" value="<?php echo $l->t('Import'); ?>" />
</fieldset>
</form>

View file

@ -4,3 +4,16 @@
</p>
<button id="exportbtn">Export<img style="display: none;" class="loading" src="<?php echo OCP\Util::linkTo('core', 'img/loading.gif'); ?>" /></button>
</fieldset>
<form id="import" action="#" method="post" enctype="multipart/form-data">
<fieldset class="personalblock">
<?php if(isset($_['error'])){ ?>
<h3><?php echo $_['error']['error']; ?></h3>
<p><?php echo $_['error']['hint']; ?></p>
<?php } ?>
<legend><strong><?php echo $l->t('Import user account');?></strong></legend>
</p>
<p><input type="file" id="owncloud_import" name="owncloud_import" style="width:180px;"><label for="owncloud_import"> <?php echo $l->t('ownCloud User Zip');?></label>
</p>
<input type="submit" name="user_import" value="<?php echo $l->t('Import'); ?>" />
</fieldset>
</form>

View file

@ -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 = '';

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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

View file

@ -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

View file

@ -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);