diff options
author | Bart Visscher <bartv@thisnet.nl> | 2012-08-30 21:49:28 +0200 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2012-08-30 21:49:28 +0200 |
commit | b483f2aab856e3324026588a9702043072fd7ad2 (patch) | |
tree | 9a5696d43ae53160bee592e1b6874185cbd98ad4 /lib | |
parent | cbaf858dea0f2094805edb6aa223bdd6877fff5b (diff) | |
parent | 598815b21e94219eb66684c64802e165a35180ad (diff) | |
download | nextcloud-server-b483f2aab856e3324026588a9702043072fd7ad2.tar.gz nextcloud-server-b483f2aab856e3324026588a9702043072fd7ad2.zip |
Merge branch 'master' into routing
Conflicts:
apps/contacts/js/contacts.js
apps/contacts/lib/search.php
apps/files_archive/js/archive.js
apps/gallery/lib/tiles.php
apps/gallery/templates/index.php
lib/ocs.php
Diffstat (limited to 'lib')
71 files changed, 662 insertions, 448 deletions
diff --git a/lib/MDB2/Driver/Datatype/sqlite3.php b/lib/MDB2/Driver/Datatype/sqlite3.php index d74badbe4f1..66c68b93778 100644 --- a/lib/MDB2/Driver/Datatype/sqlite3.php +++ b/lib/MDB2/Driver/Datatype/sqlite3.php @@ -383,5 +383,3 @@ class MDB2_Driver_Datatype_sqlite3 extends MDB2_Driver_Datatype_Common // }}} } - -?>
\ No newline at end of file diff --git a/lib/MDB2/Driver/Function/sqlite3.php b/lib/MDB2/Driver/Function/sqlite3.php index 1af262fd7a7..790bd0e747b 100644 --- a/lib/MDB2/Driver/Function/sqlite3.php +++ b/lib/MDB2/Driver/Function/sqlite3.php @@ -55,12 +55,12 @@ class MDB2_Driver_Function_sqlite3 extends MDB2_Driver_Function_Common { switch ($type) { case 'time': - return 'time(\'now\')'; + return 'CURRENT_TIME'; case 'date': - return 'date(\'now\')'; + return 'CURRENT_DATE'; case 'timestamp': default: - return 'datetime(\'now\')'; + return 'CURRENT_TIMESTAMP'; } } diff --git a/lib/MDB2/Driver/Native/sqlite3.php b/lib/MDB2/Driver/Native/sqlite3.php index de650107238..344d523bdf3 100644 --- a/lib/MDB2/Driver/Native/sqlite3.php +++ b/lib/MDB2/Driver/Native/sqlite3.php @@ -31,4 +31,3 @@ require_once 'MDB2/Driver/Native/Common.php'; class MDB2_Driver_Native_sqlite extends MDB2_Driver_Native_Common { } -?>
\ No newline at end of file diff --git a/lib/MDB2/Driver/Reverse/sqlite3.php b/lib/MDB2/Driver/Reverse/sqlite3.php index 33e5b590268..e5c758e3503 100644 --- a/lib/MDB2/Driver/Reverse/sqlite3.php +++ b/lib/MDB2/Driver/Reverse/sqlite3.php @@ -584,5 +584,3 @@ class MDB2_Driver_Reverse_sqlite3 extends MDB2_Driver_Reverse_Common 'This DBMS can not obtain tableInfo from result sets', __FUNCTION__); } } - -?>
\ No newline at end of file diff --git a/lib/app.php b/lib/app.php index 74315903467..5c0ec2f01ef 100755 --- a/lib/app.php +++ b/lib/app.php @@ -286,7 +286,7 @@ class OC_App{ if(OC_Config::getValue('knowledgebaseenabled', true)==true){ $settings = array( array( "id" => "help", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "help.php" ), "name" => $l->t("Help"), "icon" => OC_Helper::imagePath( "settings", "help.svg" )) - ); + ); } // if the user is logged-in @@ -313,7 +313,7 @@ class OC_App{ $settings[]=array( "id" => "admin", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "admin.php" ), "name" => $l->t("Admin"), "icon" => OC_Helper::imagePath( "settings", "admin.svg" )); } - } + } $navigation = self::proceedNavigation($settings); return $navigation; @@ -571,7 +571,7 @@ class OC_App{ // check if the app is compatible with this version of ownCloud $info = OC_App::getAppInfo($app); if(!isset($info['require']) or ($version[0]>$info['require'])){ - OC_Log::write('core','App "'.$info['name'].'" can\'t be used because it is not compatible with this version of ownCloud',OC_Log::ERROR); + OC_Log::write('core','App "'.$info['name'].'" ('.$app.') can\'t be used because it is not compatible with this version of ownCloud',OC_Log::ERROR); OC_App::disable( $app ); } } diff --git a/lib/appconfig.php b/lib/appconfig.php index 372cded9a5f..0e608b540bd 100644 --- a/lib/appconfig.php +++ b/lib/appconfig.php @@ -100,7 +100,7 @@ class OC_Appconfig{ return $default; } } - + /** * @brief check if a key is set in the appconfig * @param string $app @@ -111,7 +111,7 @@ class OC_Appconfig{ $exists = self::getKeys( $app ); return in_array( $key, $exists ); } - + /** * @brief sets a value in the appconfig * @param $app app @@ -163,7 +163,7 @@ class OC_Appconfig{ return true; } - + /** * get multiply values, either the app or key can be used as wildcard by setting it to false * @param app diff --git a/lib/archive.php b/lib/archive.php index fabd7cc7a51..5ac4edbfd1e 100644 --- a/lib/archive.php +++ b/lib/archive.php @@ -28,7 +28,7 @@ abstract class OC_Archive{ return new OC_Archive_TAR($path); } } - + abstract function __construct($source); /** * add an empty folder to the archive diff --git a/lib/archive/tar.php b/lib/archive/tar.php index f6efd6d0ecc..095362d0cd6 100644 --- a/lib/archive/tar.php +++ b/lib/archive/tar.php @@ -14,7 +14,7 @@ class OC_Archive_TAR extends OC_Archive{ const BZIP=2; private $fileList; - + /** * @var Archive_Tar tar */ @@ -127,7 +127,7 @@ class OC_Archive_TAR extends OC_Archive{ } return null; } - + /** * get the uncompressed size of a file in the archive * @param string path @@ -254,7 +254,7 @@ class OC_Archive_TAR extends OC_Archive{ return false; } } - + /** * remove a file or folder from the archive * @param string path diff --git a/lib/archive/zip.php b/lib/archive/zip.php index c1a5c35738b..396b1f6c054 100644 --- a/lib/archive/zip.php +++ b/lib/archive/zip.php @@ -12,7 +12,7 @@ class OC_Archive_ZIP extends OC_Archive{ */ private $zip=null; private $path; - + function __construct($source){ $this->path=$source; $this->zip=new ZipArchive(); diff --git a/lib/backgroundjob/worker.php b/lib/backgroundjob/worker.php index b4f0429b319..8684e0df117 100644 --- a/lib/backgroundjob/worker.php +++ b/lib/backgroundjob/worker.php @@ -22,7 +22,7 @@ /** * This class does the dirty work. - * + * * TODO: locking in doAllSteps */ class OC_BackgroundJob_Worker{ @@ -56,7 +56,7 @@ class OC_BackgroundJob_Worker{ OC_BackgroundJob_QueuedTask::delete( $task['id'] ); call_user_func( array( $task['klass'], $task['method'] ), $task['parameters'] ); } - + return true; } @@ -70,7 +70,7 @@ class OC_BackgroundJob_Worker{ */ public static function doNextStep(){ $laststep = OC_Appconfig::getValue( 'core', 'backgroundjobs_step', 'regular_tasks' ); - + if( $laststep == 'regular_tasks' ){ // get last app $lasttask = OC_Appconfig::getValue( 'core', 'backgroundjobs_task', '' ); @@ -79,7 +79,7 @@ class OC_BackgroundJob_Worker{ $regular_tasks = OC_BackgroundJob_RegularTask::all(); ksort( $regular_tasks ); $done = false; - + // search for next background job foreach( $regular_tasks as $key => $value ){ if( strcmp( $key, $lasttask ) > 0 ){ @@ -112,7 +112,7 @@ class OC_BackgroundJob_Worker{ OC_Appconfig::setValue( 'core', 'backgroundjobs_task', '' ); } } - + return true; } } diff --git a/lib/base.php b/lib/base.php index fb49e9e6706..237b6ab7081 100644 --- a/lib/base.php +++ b/lib/base.php @@ -246,7 +246,7 @@ class OC{ OC_Util::addScript( 'backgroundjobs' ); } } - + OC_Util::addStyle( "styles" ); OC_Util::addStyle( "multiselect" ); OC_Util::addStyle( "jquery-ui-1.8.16.custom" ); @@ -362,6 +362,10 @@ class OC{ } } + // register cache cleanup jobs + OC_BackgroundJob_RegularTask::register('OC_Cache_FileGlobal', 'gc'); + OC_Hook::connect('OC_User', 'post_login', 'OC_Cache_File', 'loginListener'); + // Check for blacklisted files OC_Hook::connect('OC_Filesystem','write','OC_Filesystem','isBlacklisted'); OC_Hook::connect('OC_Filesystem', 'rename', 'OC_Filesystem', 'isBlacklisted'); @@ -498,7 +502,7 @@ class OC{ // Someone wants to log in : } elseif (OC::tryFormLogin()) { $error = true; - + // The user is already authenticated using Apaches AuthType Basic... very usable in combination with LDAP } elseif (OC::tryBasicAuthLogin()) { $error = true; @@ -558,7 +562,7 @@ class OC{ protected static function tryBasicAuthLogin() { if (!isset($_SERVER["PHP_AUTH_USER"]) || !isset($_SERVER["PHP_AUTH_PW"])){ - return false; + return false; } OC_App::loadApps(array('authentication')); if (OC_User::login($_SERVER["PHP_AUTH_USER"],$_SERVER["PHP_AUTH_PW"])) { diff --git a/lib/cache.php b/lib/cache.php index 55f189a5da8..fed990b5b34 100644 --- a/lib/cache.php +++ b/lib/cache.php @@ -38,7 +38,7 @@ class OC_Cache { if (!self::$global_cache_fast && function_exists('apc_store')) { self::$global_cache_fast = new OC_Cache_APC(true); } - + self::$global_cache = new OC_Cache_FileGlobal(); if (self::$global_cache_fast) { self::$global_cache = new OC_Cache_Broker(self::$global_cache_fast, self::$global_cache); @@ -67,7 +67,7 @@ class OC_Cache { if (!self::$user_cache_fast && function_exists('apc_store')) { self::$user_cache_fast = new OC_Cache_APC(); } - + self::$user_cache = new OC_Cache_File(); if (self::$user_cache_fast) { self::$user_cache = new OC_Cache_Broker(self::$user_cache_fast, self::$user_cache); diff --git a/lib/cache/file.php b/lib/cache/file.php index 562c3d17167..b9073dee09a 100644 --- a/lib/cache/file.php +++ b/lib/cache/file.php @@ -8,14 +8,19 @@ class OC_Cache_File{ + protected $storage; protected function getStorage() { + if (isset($this->storage)) { + return $this->storage; + } if(OC_User::isLoggedIn()){ $subdir = 'cache'; $view = new OC_FilesystemView('/'.OC_User::getUser()); if(!$view->file_exists($subdir)) { $view->mkdir($subdir); } - return new OC_FilesystemView('/'.OC_User::getUser().'/'.$subdir); + $this->storage = new OC_FilesystemView('/'.OC_User::getUser().'/'.$subdir); + return $this->storage; }else{ OC_Log::write('core','Can\'t get cache storage, user not logged in', OC_Log::ERROR); return false; @@ -74,4 +79,25 @@ class OC_Cache_File{ } return true; } + + public function gc() { + $storage = $this->getStorage(); + if($storage and $storage->is_dir('/')) { + $now = time(); + $dh=$storage->opendir('/'); + while($file=readdir($dh)) { + if($file!='.' and $file!='..') { + $mtime = $storage->filemtime('/'.$file); + if ($mtime < $now) { + $storage->unlink('/'.$file); + } + } + } + } + } + + public static function loginListener() { + $c = new self(); + $c->gc(); + } } diff --git a/lib/cache/fileglobal.php b/lib/cache/fileglobal.php index 1c2c9bdc82d..d4336553c38 100644 --- a/lib/cache/fileglobal.php +++ b/lib/cache/fileglobal.php @@ -8,7 +8,7 @@ class OC_Cache_FileGlobal{ - protected function getCacheDir() { + static protected function getCacheDir() { $cache_dir = get_temp_dir().'/owncloud-'.OC_Util::getInstanceId().'/'; if (!is_dir($cache_dir)) { mkdir($cache_dir); @@ -23,7 +23,7 @@ class OC_Cache_FileGlobal{ public function get($key) { $key = $this->fixKey($key); if ($this->hasKey($key)) { - $cache_dir = $this->getCacheDir(); + $cache_dir = self::getCacheDir(); return file_get_contents($cache_dir.$key); } return null; @@ -31,7 +31,7 @@ class OC_Cache_FileGlobal{ public function set($key, $value, $ttl=0) { $key = $this->fixKey($key); - $cache_dir = $this->getCacheDir(); + $cache_dir = self::getCacheDir(); if ($cache_dir and file_put_contents($cache_dir.$key, $value)) { if ($ttl === 0) { $ttl = 86400; // 60*60*24 @@ -43,7 +43,7 @@ class OC_Cache_FileGlobal{ public function hasKey($key) { $key = $this->fixKey($key); - $cache_dir = $this->getCacheDir(); + $cache_dir = self::getCacheDir(); if ($cache_dir && is_file($cache_dir.$key)) { $mtime = filemtime($cache_dir.$key); if ($mtime < time()) { @@ -56,7 +56,7 @@ class OC_Cache_FileGlobal{ } public function remove($key) { - $cache_dir = $this->getCacheDir(); + $cache_dir = self::getCacheDir(); if(!$cache_dir){ return false; } @@ -65,7 +65,7 @@ class OC_Cache_FileGlobal{ } public function clear(){ - $cache_dir = $this->getCacheDir(); + $cache_dir = self::getCacheDir(); if($cache_dir and is_dir($cache_dir)){ $dh=opendir($cache_dir); while($file=readdir($dh)){ @@ -75,4 +75,26 @@ class OC_Cache_FileGlobal{ } } } + + static public function gc() { + $last_run = OC_AppConfig::getValue('core', 'global_cache_gc_lastrun', 0); + $now = time(); + if (($now - $last_run) < 300) { + // only do cleanup every 5 minutes + return; + } + OC_AppConfig::setValue('core', 'global_cache_gc_lastrun', $now); + $cache_dir = self::getCacheDir(); + if($cache_dir and is_dir($cache_dir)) { + $dh=opendir($cache_dir); + while($file=readdir($dh)) { + if($file!='.' and $file!='..') { + $mtime = filemtime($cache_dir.$file); + if ($mtime < $now) { + unlink($cache_dir.$file); + } + } + } + } + } } diff --git a/lib/connector/sabre/auth.php b/lib/connector/sabre/auth.php index 99f696e3a07..8197571e949 100644 --- a/lib/connector/sabre/auth.php +++ b/lib/connector/sabre/auth.php @@ -45,4 +45,4 @@ class OC_Connector_Sabre_Auth extends Sabre_DAV_Auth_Backend_AbstractBasic { } } } -} +} diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index cd3ed60292c..a7502446152 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -203,4 +203,3 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa return $props; } } - diff --git a/lib/connector/sabre/file.php b/lib/connector/sabre/file.php index 9d571fceb0d..5bd38240d44 100644 --- a/lib/connector/sabre/file.php +++ b/lib/connector/sabre/file.php @@ -126,4 +126,3 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D } } - diff --git a/lib/connector/sabre/locks.php b/lib/connector/sabre/locks.php index 0ddc8b18d2f..a01653d960a 100644 --- a/lib/connector/sabre/locks.php +++ b/lib/connector/sabre/locks.php @@ -42,7 +42,7 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract { // pure sql. MySQL's non-standard string concatination prevents us // from doing this though. // NOTE: SQLite requires time() to be inserted directly. That's ugly - // but otherwise reading locks from SQLite Databases will return + // but otherwise reading locks from SQLite Databases will return // nothing $query = 'SELECT * FROM `*PREFIX*locks` WHERE `userid` = ? AND (`created` + `timeout`) > '.time().' AND (( `uri` = ?)'; $params = array(OC_User::getUser(),$uri); @@ -75,7 +75,7 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract { $stmt = OC_DB::prepare( $query ); $result = $stmt->execute( $params ); - + $lockList = array(); while( $row = $result->fetchRow()){ @@ -114,7 +114,7 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract { foreach($locks as $lock) { if ($lock->token == $lockInfo->token) $exists = true; } - + if ($exists) { $query = OC_DB::prepare( 'UPDATE `*PREFIX*locks` SET `owner` = ?, `timeout` = ?, `scope` = ?, `depth` = ?, `uri` = ?, `created` = ? WHERE `userid` = ? AND `token` = ?' ); $result = $query->execute( array($lockInfo->owner,$lockInfo->timeout,$lockInfo->scope,$lockInfo->depth,$uri,$lockInfo->created,OC_User::getUser(),$lockInfo->token)); diff --git a/lib/connector/sabre/node.php b/lib/connector/sabre/node.php index b9bf474a041..afcabe7bef6 100644 --- a/lib/connector/sabre/node.php +++ b/lib/connector/sabre/node.php @@ -80,9 +80,9 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr $oldPath = $this->path; OC_Filesystem::rename($this->path,$newPath); - + $this->path = $newPath; - + $query = OC_DB::prepare( 'UPDATE `*PREFIX*properties` SET `propertypath` = ? WHERE `userid` = ? AND `propertypath` = ?' ); $query->execute( array( $newPath,OC_User::getUser(), $oldPath )); @@ -123,8 +123,8 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr } - /** - * sets the last modification time of the file (mtime) to the value given + /** + * sets the last modification time of the file (mtime) to the value given * in the second parameter or to now if the second param is empty. * Even if the modification time is set to a custom value the access time is set to now. */ @@ -195,7 +195,7 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr if(count($properties) == 0){ return $this->property_cache; } - + $props = array(); foreach($properties as $property) { if (isset($this->property_cache[$property])) $props[$property] = $this->property_cache[$property]; diff --git a/lib/db.php b/lib/db.php index 5ef67202a10..de72dee2554 100644 --- a/lib/db.php +++ b/lib/db.php @@ -27,7 +27,7 @@ class OC_DB { const BACKEND_PDO=0; const BACKEND_MDB2=1; - + static private $connection; //the prefered connection to use, either PDO or MDB2 static private $backend=null; static private $MDB2=false; @@ -55,7 +55,7 @@ class OC_DB { } return self::BACKEND_MDB2; } - + /** * @brief connects to the database * @returns true if connection can be established or nothing (die()) @@ -104,7 +104,7 @@ class OC_DB { } $opts = array(); $datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT.'/data' ); - + // do nothing if the connection already has been established if(!self::$PDO){ // Add the dsn according to the database type @@ -158,7 +158,7 @@ class OC_DB { } return true; } - + /** * connect to the database using mdb2 */ @@ -234,10 +234,10 @@ class OC_DB { } break; } - + // Try to establish connection self::$MDB2 = MDB2::factory( $dsn, $options ); - + // Die if we could not connect if( PEAR::isError( self::$MDB2 )){ echo( '<b>can not connect to database, using '.$type.'. ('.self::$MDB2->getUserInfo().')</center>'); @@ -245,11 +245,11 @@ class OC_DB { OC_Log::write('core',self::$MDB2->getMessage(),OC_Log::FATAL); die( $error ); } - + // We always, really always want associative arrays self::$MDB2->setFetchMode(MDB2_FETCHMODE_ASSOC); } - + // we are done. great! return true; } @@ -262,7 +262,7 @@ class OC_DB { * SQL query via MDB2 prepare(), needs to be execute()'d! */ static public function prepare( $query , $limit=null, $offset=null ){ - + if (!is_null($limit) && $limit != -1) { if (self::$backend == self::BACKEND_MDB2) { //MDB2 uses or emulates limits & offset internally @@ -394,7 +394,7 @@ class OC_DB { // read file $content = file_get_contents( $file ); - + // Make changes and save them to an in-memory file $file2 = 'static://db_scheme'; $content = str_replace( '*dbname*', $CONFIG_DBNAME, $content ); @@ -414,7 +414,7 @@ class OC_DB { // Try to create tables $definition = self::$schema->parseDatabaseDefinitionFile( $file2 ); - + //clean up memory unlink( $file2 ); @@ -427,7 +427,7 @@ class OC_DB { $oldname = $definition['name']; $definition['name']=OC_Config::getValue( "dbuser", $oldname ); } - + $ret=self::$schema->createDatabase( $definition ); // Die in case something went wrong @@ -438,7 +438,7 @@ class OC_DB { return true; } - + /** * @brief update the database scheme * @param $file file to read structure from @@ -451,7 +451,7 @@ class OC_DB { // read file $content = file_get_contents( $file ); - + $previousSchema = self::$schema->getDefinitionFromDatabase(); if (PEAR::isError($previousSchema)) { $error = $previousSchema->getMessage(); @@ -475,10 +475,10 @@ class OC_DB { */ file_put_contents( $file2, $content ); $op = self::$schema->updateDatabase($file2, $previousSchema, array(), false); - + //clean up memory unlink( $file2 ); - + if (PEAR::isError($op)) { $error = $op->getMessage(); $detail = $op->getDebugInfo(); @@ -528,16 +528,15 @@ class OC_DB { self::$prefix=OC_Config::getValue( "dbtableprefix", "oc_" ); } $prefix = self::$prefix; - + // differences in escaping of table names ('`' for mysql) and getting the current timestamp if( $type == 'sqlite' || $type == 'sqlite3' ){ $query = str_replace( '`', '"', $query ); $query = str_replace( 'NOW()', 'datetime(\'now\')', $query ); $query = str_replace( 'now()', 'datetime(\'now\')', $query ); - }elseif( $type == 'mysql' ){ - $query = str_replace( 'NOW()', 'CURRENT_TIMESTAMP', $query ); - $query = str_replace( 'now()', 'CURRENT_TIMESTAMP', $query ); - }elseif( $type == 'pgsql' || $type == 'oci' ){ + }elseif( $type == 'pgsql' ){ + $query = str_replace( '`', '"', $query ); + }elseif( $type == 'oci' ){ $query = str_replace( '`', '"', $query ); $query = str_replace( 'NOW()', 'CURRENT_TIMESTAMP', $query ); $query = str_replace( 'now()', 'CURRENT_TIMESTAMP', $query ); @@ -548,7 +547,7 @@ class OC_DB { return $query; } - + /** * @brief drop a table * @param string $tableNamme the table to drop @@ -558,7 +557,7 @@ class OC_DB { self::$MDB2->loadModule('Manager'); self::$MDB2->dropTable($tableName); } - + /** * remove all tables defined in a database structure xml file * @param string $file the xml file describing the tables @@ -579,7 +578,7 @@ class OC_DB { // get the tables $definition = self::$schema->parseDatabaseDefinitionFile( $file2 ); - + // Delete our temporary file unlink( $file2 ); $tables=array_keys($definition['tables']); @@ -587,30 +586,30 @@ class OC_DB { self::dropTable($table); } } - + /** * @brief replaces the owncloud tables with a new set * @param $file string path to the MDB2 xml db export file */ public static function replaceDB( $file ){ - $apps = OC_App::getAllApps(); - self::beginTransaction(); - // Delete the old tables - self::removeDBStructure( OC::$SERVERROOT . '/db_structure.xml' ); - - foreach($apps as $app){ - $path = OC_App::getAppPath($app).'/appinfo/database.xml'; - if(file_exists($path)){ - self::removeDBStructure( $path ); - } - } - - // Create new tables - self::createDBFromStructure( $file ); - self::commit(); - + $apps = OC_App::getAllApps(); + self::beginTransaction(); + // Delete the old tables + self::removeDBStructure( OC::$SERVERROOT . '/db_structure.xml' ); + + foreach($apps as $app){ + $path = OC_App::getAppPath($app).'/appinfo/database.xml'; + if(file_exists($path)){ + self::removeDBStructure( $path ); + } + } + + // Create new tables + self::createDBFromStructure( $file ); + self::commit(); + } - + /** * Start a transaction */ @@ -661,7 +660,7 @@ class PDOStatementWrapper{ public function __construct($statement){ $this->statement=$statement; } - + /** * make execute return the result instead of a bool */ @@ -678,7 +677,7 @@ class PDOStatementWrapper{ return false; } } - + /** * provide numRows */ @@ -691,21 +690,21 @@ class PDOStatementWrapper{ return $this->statement->rowCount(); } } - + /** * provide an alias for fetch */ public function fetchRow(){ return $this->statement->fetch(); } - + /** * pass all other function directly to the PDOStatement */ public function __call($name,$arguments){ return call_user_func_array(array($this->statement,$name),$arguments); } - + /** * Provide a simple fetchOne. * fetch single column from the next row @@ -715,4 +714,3 @@ class PDOStatementWrapper{ return $this->statement->fetchColumn($colnum); } } - diff --git a/lib/eventsource.php b/lib/eventsource.php index 95af2e471bc..45a20806b6e 100644 --- a/lib/eventsource.php +++ b/lib/eventsource.php @@ -30,7 +30,7 @@ class OC_EventSource{ private $fallback; private $fallBackId=0; - + public function __construct(){ @ob_end_clean(); header('Cache-Control: no-cache'); diff --git a/lib/filecache.php b/lib/filecache.php index e85d6747f90..364b908bcfa 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -76,14 +76,14 @@ class OC_FileCache{ 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[$fullpath]=$data; return; @@ -136,7 +136,7 @@ class OC_FileCache{ $queryParts[]='`mimepart`=?'; } $arguments[]=$id; - + $sql = 'UPDATE `*PREFIX*fscache` SET '.implode(' , ',$queryParts).' WHERE `id`=?'; $query=OC_DB::prepare($sql); $result=$query->execute($arguments); @@ -192,14 +192,14 @@ class OC_FileCache{ } $query=OC_DB::prepare('DELETE FROM `*PREFIX*fscache` WHERE `path_hash`=?'); $query->execute(array(md5($root.$path))); - + //delete everything inside the folder $query=OC_DB::prepare('DELETE FROM `*PREFIX*fscache` WHERE `path` LIKE ?'); $query->execute(array($root.$path.'/%')); OC_Cache::remove('fileid/'.$root.$path); } - + /** * return array of filenames matching the querty * @param string $query @@ -277,14 +277,14 @@ class OC_FileCache{ if(($cache=OC_Cache::getUserCache(true)) && $cache->hasKey('fileid/'.$fullPath)){ return $cache->get('fileid/'.$fullPath); } - + $query=OC_DB::prepare('SELECT `id` FROM `*PREFIX*fscache` WHERE `path_hash`=?'); $result=$query->execute(array(md5($fullPath))); if(OC_DB::isError($result)){ OC_Log::write('files','error while getting file id of '.$path,OC_Log::ERROR); return -1; } - + $result=$result->fetchRow(); if(is_array($result)){ $id=$result['id']; @@ -294,10 +294,10 @@ class OC_FileCache{ if($cache=OC_Cache::getUserCache(true)){ $cache->set('fileid/'.$fullPath,$id); } - + return $id; } - + /** * get the file path from the id, relative to the home folder of the user * @param int id @@ -331,7 +331,7 @@ class OC_FileCache{ return self::getId(dirname($path),''); } } - + /** * adjust the size of the parent folders * @param string $path @@ -390,7 +390,7 @@ class OC_FileCache{ } } } - + OC_FileCache_Update::cleanFolder($path,$root); self::increaseSize($path,$totalSize,$root); } diff --git a/lib/filecache/cached.php b/lib/filecache/cached.php index 95cc0ac300e..505f1a5e2a0 100644 --- a/lib/filecache/cached.php +++ b/lib/filecache/cached.php @@ -12,7 +12,7 @@ */ class OC_FileCache_Cached{ public static $savedData=array(); - + public static function get($path,$root=false){ if($root===false){ $root=OC_Filesystem::getRoot(); diff --git a/lib/filecache/update.php b/lib/filecache/update.php index 0b5ff8e2446..7b5f18fe5c1 100644 --- a/lib/filecache/update.php +++ b/lib/filecache/update.php @@ -42,7 +42,7 @@ class OC_FileCache_Update{ return true; } } - + /** * delete non existing files from the cache */ @@ -148,7 +148,7 @@ class OC_FileCache_Update{ } $mimetype=$view->getMimeType($path); - + $size=0; $cached=OC_FileCache_Cached::get($path,$root); $cachedSize=isset($cached['size'])?$cached['size']:0; diff --git a/lib/fileproxy.php b/lib/fileproxy.php index ec04faa9bc5..a1c79874bf7 100644 --- a/lib/fileproxy.php +++ b/lib/fileproxy.php @@ -43,7 +43,7 @@ class OC_FileProxy{ private static $proxies=array(); public static $enabled=true; - + /** * fallback function when a proxy operation is not implemented * @param string $function the name of the proxy operation @@ -58,7 +58,7 @@ class OC_FileProxy{ return $arguments[1]; } } - + /** * register a proxy to be used * @param OC_FileProxy $proxy @@ -66,7 +66,7 @@ class OC_FileProxy{ public static function register($proxy){ self::$proxies[]=$proxy; } - + public static function getProxies($operation){ $proxies=array(); foreach(self::$proxies as $proxy){ diff --git a/lib/fileproxy/quota.php b/lib/fileproxy/quota.php index 7316224cc61..4c6261fc514 100644 --- a/lib/fileproxy/quota.php +++ b/lib/fileproxy/quota.php @@ -27,7 +27,7 @@ class OC_FileProxy_Quota extends OC_FileProxy{ private $userQuota=-1; - + /** * get the quota for the current user * @return int @@ -46,9 +46,9 @@ class OC_FileProxy_Quota extends OC_FileProxy{ $this->userQuota=OC_Helper::computerFileSize($userQuota); } return $this->userQuota; - + } - + /** * get the free space in the users home folder * @return int @@ -69,7 +69,7 @@ class OC_FileProxy_Quota extends OC_FileProxy{ } return $totalSpace-$usedSpace; } - + public function postFree_space($path,$space){ $free=$this->getFreeSpace(); if($free==0){ diff --git a/lib/files.php b/lib/files.php index 1a1fffa0a50..0c71f6e5e42 100644 --- a/lib/files.php +++ b/lib/files.php @@ -406,9 +406,9 @@ class OC_Files { //check for write permissions if(is_writable(OC::$SERVERROOT.'/.htaccess')) { file_put_contents(OC::$SERVERROOT.'/.htaccess', $htaccess); - return OC_Helper::computerFileSize($size); + return OC_Helper::computerFileSize($size); } else { OC_Log::write('files','Can\'t write upload limit to '.OC::$SERVERROOT.'/.htaccess. Please check the file permissions',OC_Log::WARN); } - + return false; } diff --git a/lib/filestorage/common.php b/lib/filestorage/common.php index c829be62f74..e2828e56170 100644 --- a/lib/filestorage/common.php +++ b/lib/filestorage/common.php @@ -21,11 +21,11 @@ */ /** - * Storage backend class for providing common filesystem operation methods + * Storage backend class for providing common filesystem operation methods * which are not storage-backend specific. * * OC_Filestorage_Common is never used directly; it is extended by all other - * storage backends, where its methods may be overridden, and additional + * storage backends, where its methods may be overridden, and additional * (backend-specific) methods are defined. * * Some OC_Filestorage_Common methods call functions which are first defined @@ -115,71 +115,71 @@ abstract class OC_Filestorage_Common extends OC_Filestorage { * @param $empty Flag indicating whether directory will be emptied * @returns true/false * - * @note By default the directory specified by $directory will be + * @note By default the directory specified by $directory will be * deleted together with its contents. To avoid this set $empty to true */ public function deleteAll( $directory, $empty = false ) { - + // strip leading slash if( substr( $directory, 0, 1 ) == "/" ) { - + $directory = substr( $directory, 1 ); - + } - + // strip trailing slash if( substr( $directory, -1) == "/" ) { - + $directory = substr( $directory, 0, -1 ); - + } - + if ( !$this->file_exists( \OCP\USER::getUser() . '/' . $directory ) || !$this->is_dir( \OCP\USER::getUser() . '/' . $directory ) ) { - + return false; - + } elseif( !$this->is_readable( \OCP\USER::getUser() . '/' . $directory ) ) { - + return false; - + } else { - + $directoryHandle = $this->opendir( \OCP\USER::getUser() . '/' . $directory ); - + while ( $contents = readdir( $directoryHandle ) ) { - + if ( $contents != '.' && $contents != '..') { - + $path = $directory . "/" . $contents; - + if ( $this->is_dir( $path ) ) { - + deleteAll( $path ); - + } else { - + $this->unlink( \OCP\USER::getUser() .'/' . $path ); // TODO: make unlink use same system path as is_dir - + } } - + } - + //$this->closedir( $directoryHandle ); // TODO: implement closedir in OC_FSV if ( $empty == false ) { - + if ( !$this->rmdir( $directory ) ) { - + return false; - + } - + } - + return true; } - + } public function getMimeType($path){ if(!$this->file_exists($path)){ diff --git a/lib/filestorage/commontest.php b/lib/filestorage/commontest.php index b5126a407b3..4d06e4fa321 100644 --- a/lib/filestorage/commontest.php +++ b/lib/filestorage/commontest.php @@ -31,11 +31,11 @@ class OC_Filestorage_CommonTest extends OC_Filestorage_Common{ * @var OC_FileStorage_Local */ private $storage; - + public function __construct($params){ $this->storage=new OC_Filestorage_Local($params); } - + public function mkdir($path){ return $this->storage->mkdir($path); } diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php index 22d17469df3..b19205f45b1 100644 --- a/lib/filestorage/local.php +++ b/lib/filestorage/local.php @@ -61,7 +61,7 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{ return filemtime($this->datadir.$path); } public function touch($path, $mtime=null){ - // sets the modification time of the file to the given value. + // sets the modification time of the file to the given value. // If mtime is nil the current time is set. // note that the access time of the file always changes to the current time. if(!is_null($mtime)){ @@ -72,7 +72,7 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{ if( $result ) { clearstatcache( true, $this->datadir.$path ); } - + return $result; } public function file_get_contents($path){ diff --git a/lib/filesystem.php b/lib/filesystem.php index 82fbf11afdf..327329f9d91 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -3,22 +3,22 @@ /** * ownCloud * -* @author Frank Karlitschek -* @copyright 2012 Frank Karlitschek frank@owncloud.org -* +* @author Frank Karlitschek +* @copyright 2012 Frank Karlitschek frank@owncloud.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 +* 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 +* +* 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/>. -* +* */ @@ -193,7 +193,7 @@ class OC_Filesystem{ return OC_Filesystem::$storages[$mountpoint]; } } - + static public function init($root){ if(self::$defaultInstance){ return false; @@ -237,7 +237,7 @@ class OC_Filesystem{ } } } - + self::$loaded=true; } @@ -257,14 +257,14 @@ class OC_Filesystem{ static public function getView(){ return self::$defaultInstance; } - + /** * tear down the filesystem, removing all storage providers */ static public function tearDown(){ self::$storages=array(); } - + /** * create a new storage of a specific type * @param string type @@ -284,7 +284,7 @@ class OC_Filesystem{ return false; } } - + /** * change the root to a fake root * @param string fakeRoot @@ -326,7 +326,7 @@ class OC_Filesystem{ } self::$mounts[$mountpoint]=array('class'=>$class,'arguments'=>$arguments); } - + /** * return the path to a local version of the file * we need this because we can't know if a file is stored local or not from outside the filestorage and for some purposes a local file is needed @@ -343,21 +343,21 @@ class OC_Filesystem{ static public function getLocalFolder($path){ return self::$defaultInstance->getLocalFolder($path); } - + /** * return path to file which reflects one visible in browser * @param string path * @return string */ static public function getLocalPath($path) { - $datadir = \OCP\Config::getSystemValue('datadirectory').'/'.\OC_User::getUser().'/files'; + $datadir = OC_User::getHome($user).'/files'; $newpath = $path; if (strncmp($newpath, $datadir, strlen($datadir)) == 0) { $newpath = substr($path, strlen($datadir)); } return $newpath; } - + /** * check if the requested path is valid * @param string path @@ -372,7 +372,7 @@ class OC_Filesystem{ } return true; } - + /** * checks if a file is blacklsited for storage in the filesystem * Listens to write and rename hooks @@ -392,7 +392,7 @@ class OC_Filesystem{ } } } - + /** * following functions are equivilent to their php buildin equivilents for arguments/return values. */ @@ -496,11 +496,11 @@ class OC_Filesystem{ static public function hash($type,$path, $raw = false){ return self::$defaultInstance->hash($type,$path, $raw); } - + static public function free_space($path='/'){ return self::$defaultInstance->free_space($path); } - + static public function search($query){ return OC_FileCache::search($query); } diff --git a/lib/filesystemview.php b/lib/filesystemview.php index a888e5340ea..461a0262560 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -56,7 +56,7 @@ class OC_FilesystemView { } return $this->fakeRoot.$path; } - + /** * change the root to a fake toor * @param string fakeRoot @@ -325,7 +325,7 @@ class OC_FilesystemView { if(OC_FileProxy::runPreProxies('rename', $absolutePath1, $absolutePath2) and OC_Filesystem::isValidPath($path2)) { $path1 = $this->getRelativePath($absolutePath1); $path2 = $this->getRelativePath($absolutePath2); - + if($path1 == null or $path2 == null) { return false; } @@ -352,7 +352,7 @@ class OC_FilesystemView { $storage1 = $this->getStorage($path1); $storage1->unlink($this->getInternalPath($path1.$postFix1)); $result = $count>0; - } + } OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_rename, @@ -373,7 +373,7 @@ class OC_FilesystemView { if(OC_FileProxy::runPreProxies('copy', $absolutePath1, $absolutePath2) and OC_Filesystem::isValidPath($path2)) { $path1 = $this->getRelativePath($absolutePath1); $path2 = $this->getRelativePath($absolutePath2); - + if($path1 == null or $path2 == null) { return false; } diff --git a/lib/geo.php b/lib/geo.php index a967ab28a96..964605b1c1c 100644 --- a/lib/geo.php +++ b/lib/geo.php @@ -12,7 +12,7 @@ class OC_Geo{ * @param (string) $longitude - Longitude * @return (string) $timezone - closest timezone */ - public static function timezone($latitude, $longitude){ + public static function timezone($latitude, $longitude){ $alltimezones = DateTimeZone::listIdentifiers(); $variances = array(); //calculate for all timezones the system know diff --git a/lib/group.php b/lib/group.php index 72cf5dc89af..dd70a94eb0d 100644 --- a/lib/group.php +++ b/lib/group.php @@ -271,7 +271,7 @@ class OC_Group { } return $users; } - + /** * @brief get a list of all users in several groups * @param array $gids diff --git a/lib/helper.php b/lib/helper.php index 3cdb3e53c22..69856085dbe 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -101,6 +101,17 @@ class OC_Helper { } /** + * @brief Creates an absolute url for public use + * @param $service id + * @returns the url + * + * Returns a absolute url to the given service. + */ + public static function linkToPublic($service, $add_slash = false) { + return self::linkToAbsolute( '', 'public.php') . '?service=' . $service . (($add_slash && $service[strlen($service)-1]!='/')?'/':''); + } + + /** * @brief Creates path to an image * @param $app app * @param $image image name diff --git a/lib/hook.php b/lib/hook.php index b53755310e0..ee390d6cd5a 100644 --- a/lib/hook.php +++ b/lib/hook.php @@ -83,4 +83,3 @@ class OC_Hook{ } } } - diff --git a/lib/image.php b/lib/image.php index 90c64320a7c..e87cf9e16d9 100644 --- a/lib/image.php +++ b/lib/image.php @@ -383,7 +383,7 @@ class OC_Image { /** * @brief Loads an image from an open file handle. * It is the responsibility of the caller to position the pointer at the correct place and to close the handle again. - * @param $handle + * @param $handle * @returns An image resource or false on error */ public function loadFromFileHandle($handle) { @@ -468,7 +468,7 @@ class OC_Image { break; */ default: - + // this is mostly file created from encrypted file $this->resource = imagecreatefromstring(\OC_Filesystem::file_get_contents(\OC_Filesystem::getLocalPath($imagepath))); $itype = IMAGETYPE_PNG; @@ -534,7 +534,7 @@ class OC_Image { $width_orig=imageSX($this->resource); $height_orig=imageSY($this->resource); $ratio_orig = $width_orig/$height_orig; - + if ($ratio_orig > 1) { $new_height = round($maxsize/$ratio_orig); $new_width = $maxsize; @@ -564,7 +564,7 @@ class OC_Image { public function preciseResize($width, $height) { if (!$this->valid()) { OC_Log::write('core',__METHOD__.'(): No image loaded', OC_Log::ERROR); - return false; + return false; } $width_orig=imageSX($this->resource); $height_orig=imageSY($this->resource); diff --git a/lib/json.php b/lib/json.php index 3d9d5c96fa3..32ae734e4a5 100644 --- a/lib/json.php +++ b/lib/json.php @@ -52,7 +52,7 @@ class OC_JSON{ exit(); } } - + /** * Check if the user is a admin, send json error msg if not */ @@ -64,7 +64,7 @@ class OC_JSON{ exit(); } } - + /** * Check if the user is a subadmin, send json error msg if not */ diff --git a/lib/l10n.php b/lib/l10n.php index e7f5ffea0e4..cfa0e26486b 100644 --- a/lib/l10n.php +++ b/lib/l10n.php @@ -28,17 +28,17 @@ class OC_L10N{ * cached instances */ protected static $instances=array(); - + /** * cache */ protected static $cache = array(); - + /** * The best language */ protected static $language = ''; - + /** * App of this object */ @@ -53,7 +53,7 @@ class OC_L10N{ * Translations */ private $translations = array(); - + /** * Localization */ @@ -61,7 +61,7 @@ class OC_L10N{ 'date' => 'd.m.Y', 'datetime' => 'd.m.Y H:i:s', 'time' => 'H:i:s'); - + /** * get an L10N instance * @return OC_L10N @@ -76,7 +76,7 @@ class OC_L10N{ return new OC_L10N($app,$lang); } } - + /** * @brief The constructor * @param $app the app requesting l10n @@ -90,7 +90,7 @@ class OC_L10N{ $this->app = $app; $this->lang = $lang; } - + protected function init(){ if ($this->app === true) { return; @@ -119,7 +119,7 @@ class OC_L10N{ if(isset($TRANSLATIONS) && is_array($TRANSLATIONS)){ $this->translations = $TRANSLATIONS; } - } + } if(file_exists(OC::$SERVERROOT.'/core/l10n/l10n-'.$lang.'.php')){ // Include the file, save the data from $CONFIG @@ -188,7 +188,7 @@ class OC_L10N{ * @returns String or false * * Returns the localized data. - * + * * Implemented types: * - date * - Creates a date @@ -241,7 +241,7 @@ class OC_L10N{ * @returns language * * If $app is an array, ownCloud assumes that these are the available - * languages. Otherwise ownCloud tries to find the files in the l10n + * languages. Otherwise ownCloud tries to find the files in the l10n * folder. * * If nothing works it returns 'en' diff --git a/lib/l10n/nb_NO.php b/lib/l10n/nb_NO.php index af9503b7bf4..f751a41d5eb 100644 --- a/lib/l10n/nb_NO.php +++ b/lib/l10n/nb_NO.php @@ -11,6 +11,7 @@ "Selected files too large to generate zip file." => "De valgte filene er for store til å kunne generere ZIP-fil", "Application is not enabled" => "Applikasjon er ikke påslått", "Authentication error" => "Autentiseringsfeil", +"Token expired. Please reload page." => "Symbol utløpt. Vennligst last inn siden på nytt.", "seconds ago" => "sekunder siden", "1 minute ago" => "1 minuitt siden", "%d minutes ago" => "%d minutter siden", diff --git a/lib/mail.php b/lib/mail.php index 0ac9a97c1bf..acdadeffd33 100644 --- a/lib/mail.php +++ b/lib/mail.php @@ -17,7 +17,7 @@ require_once('class.phpmailer.php'); class OC_Mail { /** - * send an email + * send an email * * @param string $toaddress * @param string $toname @@ -31,9 +31,9 @@ class OC_Mail { $SMTPMODE = OC_Config::getValue( 'mail_smtpmode', 'sendmail' ); $SMTPHOST = OC_Config::getValue( 'mail_smtphost', '127.0.0.1' ); - $SMTPAUTH = OC_Config::getValue( 'mail_smtpauth', false ); - $SMTPUSERNAME = OC_Config::getValue( 'mail_smtpname', '' ); - $SMTPPASSWORD = OC_Config::getValue( 'mail_smtppassword', '' ); + $SMTPAUTH = OC_Config::getValue( 'mail_smtpauth', false ); + $SMTPUSERNAME = OC_Config::getValue( 'mail_smtpname', '' ); + $SMTPPASSWORD = OC_Config::getValue( 'mail_smtppassword', '' ); $mailo = new PHPMailer(true); diff --git a/lib/migrate.php b/lib/migrate.php index 917d77eaca0..7d7169c4e46 100644 --- a/lib/migrate.php +++ b/lib/migrate.php @@ -141,7 +141,7 @@ class OC_Migrate{ // Export the app info $exportdata = self::exportAppData(); // Add the data dir to the zip - self::$content->addDir( $datadir . '/' . self::$uid, true, '/' ); + self::$content->addDir(OC_User::getHome(self::$uid), true, '/' ); break; case 'instance': self::$content = new OC_Migration_Content( self::$zip ); @@ -159,14 +159,14 @@ class OC_Migrate{ self::$content->addFromString( $dbexport, "dbexport.xml" ); // Add user data foreach(OC_User::getUsers() as $user){ - self::$content->addDir( $datadir . '/' . $user . '/', true, "/userdata/" ); + self::$content->addDir(OC_User::getHome($user), true, "/userdata/" ); } break; case 'userfiles': self::$content = new OC_Migration_Content( self::$zip ); // Creates a zip with all of the users files foreach(OC_User::getUsers() as $user){ - self::$content->addDir( $datadir . '/' . $user . '/', true, "/" ); + self::$content->addDir(OC_User::getHome($user), true, "/" ); } break; case 'system': @@ -196,7 +196,7 @@ class OC_Migrate{ * @param optional $uid userid of new user */ public static function import( $path, $type='user', $uid=null ){ - + $datadir = OC_Config::getValue( 'datadirectory' ); // Extract the zip if( !$extractpath = self::extractZip( $path ) ){ @@ -222,13 +222,13 @@ class OC_Migrate{ if( self::$exporttype == 'user' ){ 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 ) ); + return json_encode( array( 'success' => false ) ); } } @@ -411,7 +411,7 @@ class OC_Migrate{ $success = false; } } - + // Run the export function? if( $success ){ // Set the provider properties @@ -421,7 +421,7 @@ class OC_Migrate{ $return['apps'][$provider->getID()]['success'] = false; $return['apps'][$provider->getID()]['message'] = 'failed to create the app tables'; } - + // Now add some app info the the return array $appinfo = OC_App::getAppInfo( $provider->getID() ); $return['apps'][$provider->getID()]['version'] = OC_App::getAppVersion($provider->getID()); diff --git a/lib/migration/content.php b/lib/migration/content.php index 5c89e6bacd6..e04ac224f79 100644 --- a/lib/migration/content.php +++ b/lib/migration/content.php @@ -25,13 +25,13 @@ * provides methods to add and access data from the migration */ class OC_Migration_Content{ - + private $zip=false; // Holds the MDB2 object private $db=null; // Holds an array of tmpfiles to delete after zip creation private $tmpfiles=false; - + /** * @brief sets up the * @param $zip ZipArchive object @@ -42,25 +42,25 @@ class OC_Migration_Content{ $this->zip = $zip; $this->db = $db; - + if( !is_null( $db ) ){ // Get db path $db = $this->db->getDatabase(); $this->tmpfiles[] = $db; } - + } - + // @brief prepares the db // @param $query the sql query to prepare public function prepare( $query ){ - + // Optimize the query $query = $this->processQuery( $query ); - + // Optimize the query $query = $this->db->prepare( $query ); - + // Die if we have an error (error means: bad query, not 0 results!) if( PEAR::isError( $query ) ) { $entry = 'DB Error: "'.$result->getMessage().'"<br />'; @@ -68,11 +68,11 @@ class OC_Migration_Content{ OC_Log::write( 'migration', $entry, OC_Log::FATAL ); return false; } else { - return $query; + return $query; } - + } - + /** * @brief processes the db query * @param $query the query to process @@ -86,7 +86,7 @@ class OC_Migration_Content{ $query = str_replace( '*PREFIX*', '', $query ); return $query; } - + /** * @brief copys rows to migration.db from the main database * @param $options array of options. @@ -94,19 +94,19 @@ class OC_Migration_Content{ */ public function copyRows( $options ){ if( !array_key_exists( 'table', $options ) ){ - return false; + return false; } - + $return = array(); - + // Need to include 'where' in the query? if( array_key_exists( 'matchval', $options ) && array_key_exists( 'matchcol', $options ) ){ - + // If only one matchval, create an array if(!is_array($options['matchval'])){ - $options['matchval'] = array( $options['matchval'] ); + $options['matchval'] = array( $options['matchval'] ); } - + foreach( $options['matchval'] as $matchval ){ // Run the query for this match value (where x = y value) $sql = 'SELECT * FROM `*PREFIX*' . $options['table'] . '` WHERE `' . $options['matchcol'] . '` LIKE ?'; @@ -122,13 +122,13 @@ class OC_Migration_Content{ $query = OC_DB::prepare( $sql ); $results = $query->execute(); $return = $this->insertData( $results, $options ); - + } - + return $return; - + } - + /** * @brief saves a sql data set into migration.db * @param $data a sql data set returned from self::prepare()->query() @@ -144,7 +144,7 @@ class OC_Migration_Content{ $fields[] = $field; $values[] = $value; } - + // Generate some sql $sql = "INSERT INTO `" . $options['table'] . '` ( `'; $fieldssql = implode( '`, `', $fields ); @@ -154,7 +154,7 @@ class OC_Migration_Content{ // Make the query $query = $this->prepare( $sql ); if( !$query ){ - OC_Log::write( 'migration', 'Invalid sql produced: '.$sql, OC_Log::FATAL ); + OC_Log::write( 'migration', 'Invalid sql produced: '.$sql, OC_Log::FATAL ); return false; exit(); } else { @@ -162,10 +162,10 @@ class OC_Migration_Content{ // Do we need to return some values? if( array_key_exists( 'idcol', $options ) ){ // Yes we do - $return[] = $row[$options['idcol']]; + $return[] = $row[$options['idcol']]; } else { // Take a guess and return the first field :) - $return[] = reset($row); + $return[] = reset($row); } } $fields = ''; @@ -173,11 +173,11 @@ class OC_Migration_Content{ } return $return; } - + /** * @brief adds a directory to the zip object * @param $dir string path of the directory to add - * @param $recursive bool + * @param $recursive bool * @param $internaldir string path of folder to add dir to in zip * @return bool */ @@ -186,13 +186,13 @@ class OC_Migration_Content{ $this->zip->addEmptyDir($internaldir . $dirname); $internaldir.=$dirname.='/'; if( !file_exists( $dir ) ){ - return false; + return false; } if ($dirhandle = opendir($dir)) { while (false !== ( $file = readdir($dirhandle))) { - + if (( $file != '.' ) && ( $file != '..' )) { - + if (is_dir($dir . '/' . $file) && $recursive) { $this->addDir($dir . '/' . $file, $recursive, $internaldir); } elseif (is_file($dir . '/' . $file)) { @@ -207,7 +207,7 @@ class OC_Migration_Content{ } return true; } - + /** * @brief adds a file to the zip from a given string * @param $data string of data to add @@ -220,13 +220,13 @@ class OC_Migration_Content{ $this->tmpfiles[] = $file; if( !file_put_contents( $file, $data ) ){ OC_Log::write( 'migation', 'Failed to save data to a temporary file', OC_Log::ERROR ); - return false; + return false; } // Add file to the zip $this->zip->addFile( $file, $path ); return true; } - + /** * @brief closes the zip, removes temp files * @return bool @@ -234,19 +234,19 @@ class OC_Migration_Content{ public function finish(){ if( !$this->zip->close() ){ OC_Log::write( 'migration', 'Failed to write the zip file with error: '.$this->zip->getStatusString(), OC_Log::ERROR ); - return false; + return false; } $this->cleanup(); - return true; - } - + return true; + } + /** * @brief cleans up after the zip */ private function cleanup(){ // Delete tmp files foreach($this->tmpfiles as $i){ - unlink( $i ); - } + unlink( $i ); + } } } diff --git a/lib/migration/provider.php b/lib/migration/provider.php index 91336f3019d..259b1fe7ae6 100644 --- a/lib/migration/provider.php +++ b/lib/migration/provider.php @@ -3,37 +3,37 @@ * provides search functionalty */ abstract class OC_Migration_Provider{ - + protected $id=false; - protected $content=false; + protected $content=false; protected $uid=false; protected $olduid=false; protected $appinfo=false; - + public function __construct( $appid ){ // Set the id $this->id = $appid; OC_Migrate::registerProvider( $this ); } - + /** * @brief exports data for apps * @return array appdata to be exported */ abstract function export( ); - + /** * @brief imports data for the app * @return void */ abstract function import( ); - + /** * @brief sets the OC_Migration_Content object to $this->content * @param $content a OC_Migration_Content object */ public function setData( $uid, $content, $info=null ){ - $this->content = $content; + $this->content = $content; $this->uid = $uid; $id = $this->id; if( !is_null( $info ) ){ @@ -41,12 +41,12 @@ abstract class OC_Migration_Provider{ $this->appinfo = $info->apps->$id; } } - + /** * @brief returns the appid of the provider * @return string */ public function getID(){ - return $this->id; + return $this->id; } } diff --git a/lib/ocs.php b/lib/ocs.php index 1df08df9fa1..64e89648e1b 100644 --- a/lib/ocs.php +++ b/lib/ocs.php @@ -177,7 +177,7 @@ class OC_OCS { ->requirements(array('format'=>'xml|json')); // CLOUD - // systemWebApps + // systemWebApps $router->create('system_webapps', '/cloud/system/webapps.{format}') ->defaults(array('format' => $format)) @@ -187,7 +187,7 @@ class OC_OCS { }) ->requirements(array('format'=>'xml|json')); - // quotaget + // quotaget $router->create('quota_get', '/cloud/user/{user}.{format}') ->defaults(array('format' => $format)) @@ -197,7 +197,7 @@ class OC_OCS { OC_OCS::quotaGet($format, $user); }) ->requirements(array('format'=>'xml|json')); - // quotaset + // quotaset $router->create('quota_set', '/cloud/user/{user}.{format}') ->post() @@ -210,7 +210,7 @@ class OC_OCS { }) ->requirements(array('format'=>'xml|json')); - // keygetpublic + // keygetpublic $router->create('keygetpublic', '/cloud/user/{user}/publickey.{format}') ->defaults(array('format' => $format)) @@ -221,7 +221,7 @@ class OC_OCS { }) ->requirements(array('format'=>'xml|json')); - // keygetprivate + // keygetprivate $router->create('keygetpublic', '/cloud/user/{user}/privatekey.{format}') ->defaults(array('format' => $format)) @@ -557,7 +557,7 @@ class OC_OCS { echo(OC_OCS::generatexml($format,'ok',100,'')); } } - + /** * get private data * @param string $user diff --git a/lib/ocsclient.php b/lib/ocsclient.php index ae35470cff6..f05a9af31c2 100644 --- a/lib/ocsclient.php +++ b/lib/ocsclient.php @@ -29,7 +29,7 @@ class OC_OCSClient{ /** - * @brief Get the url of the OCS AppStore server. + * @brief Get the url of the OCS AppStore server. * @returns string of the AppStore server * * This function returns the url of the OCS AppStore server. It´s possible to set it in the config file or it will fallback to the default @@ -40,7 +40,7 @@ class OC_OCSClient{ } /** - * @brief Get the url of the OCS KB server. + * @brief Get the url of the OCS KB server. * @returns string of the KB server * This function returns the url of the OCS knowledge base server. It´s possible to set it in the config file or it will fallback to the default */ @@ -61,13 +61,13 @@ class OC_OCSClient{ return NULL; } $url=OC_OCSClient::getAppStoreURL().'/content/categories'; - + $xml=@file_get_contents($url); if($xml==FALSE){ return NULL; } $data=simplexml_load_string($xml); - + $tmp=$data->data; $cats=array(); @@ -119,9 +119,9 @@ class OC_OCSClient{ $app['preview']=(string)$tmp[$i]->smallpreviewpic1; $app['changed']=strtotime($tmp[$i]->changed); $app['description']=(string)$tmp[$i]->description; - + $apps[]=$app; - } + } return $apps; } @@ -184,10 +184,10 @@ class OC_OCSClient{ $tmp=$data->data->content; $app=array(); - if(isset($tmp->downloadlink)) { + if(isset($tmp->downloadlink)) { $app['downloadlink']=$tmp->downloadlink; }else{ - $app['downloadlink']=''; + $app['downloadlink']=''; } return $app; } @@ -199,7 +199,7 @@ class OC_OCSClient{ * * This function returns a list of all the knowledgebase entries from the OCS server */ - public static function getKnownledgebaseEntries($page,$pagesize,$search=''){ + public static function getKnownledgebaseEntries($page,$pagesize,$search=''){ if(OC_Config::getValue('knowledgebaseenabled', true)==false){ $kbe=array(); $kbe['totalitems']=0; diff --git a/lib/preferences.php b/lib/preferences.php index b6c4c3a163f..de5747fcccc 100644 --- a/lib/preferences.php +++ b/lib/preferences.php @@ -116,7 +116,7 @@ class OC_Preferences{ // Try to fetch the value, return default if not exists. $query = OC_DB::prepare( 'SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?' ); $result = $query->execute( array( $user, $app, $key )); - + $row = $result->fetchRow(); if($row){ return $row["configvalue"]; diff --git a/lib/public/app.php b/lib/public/app.php index e74f1550740..be38bbff98a 100644 --- a/lib/public/app.php +++ b/lib/public/app.php @@ -26,7 +26,7 @@ * */ -// use OCP namespace for all classes that are considered public. +// use OCP namespace for all classes that are considered public. // This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; @@ -130,7 +130,7 @@ class App { /** - * @brief Check if the app is enabled, redirects to home if not + * @brief Check if the app is enabled, redirects to home if not * @param $app app * @returns true/false */ @@ -140,7 +140,7 @@ class App { /** - * @brief Get the last version of the app, either from appinfo/version or from appinfo/info.xml + * @brief Get the last version of the app, either from appinfo/version or from appinfo/info.xml * @param $app app * @returns true/false */ diff --git a/lib/public/backgroundjob.php b/lib/public/backgroundjob.php index 834bebb5c3c..2962346dbc9 100644 --- a/lib/public/backgroundjob.php +++ b/lib/public/backgroundjob.php @@ -24,7 +24,7 @@ * Public interface of ownCloud forbackground jobs. */ -// use OCP namespace for all classes that are considered public. +// use OCP namespace for all classes that are considered public. // This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; @@ -42,7 +42,7 @@ namespace OCP; * An example of the queued task would be the creation of the thumbnail. As * soon as the user uploads a picture the gallery app registers the queued * task "create thumbnail" and saves the path in the parameter instead of doing - * the work right away. This makes the app more responsive. As soon as the task + * the work right away. This makes the app more responsive. As soon as the task * is done it will be deleted from the list. */ class BackgroundJob { diff --git a/lib/public/config.php b/lib/public/config.php index ab01902ffe6..f3120b9aaa2 100644 --- a/lib/public/config.php +++ b/lib/public/config.php @@ -27,7 +27,7 @@ */ /** - * @brief use OCP namespace for all classes that are considered public. + * @brief use OCP namespace for all classes that are considered public. * * Classes that use this namespace are for use by apps, and not for use by internal * OC classes diff --git a/lib/public/db.php b/lib/public/db.php index 23c670cf442..e1da62e2d27 100644 --- a/lib/public/db.php +++ b/lib/public/db.php @@ -26,7 +26,7 @@ * */ -// use OCP namespace for all classes that are considered public. +// use OCP namespace for all classes that are considered public. // This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; diff --git a/lib/public/files.php b/lib/public/files.php index 32b3f036744..be5952d362a 100644 --- a/lib/public/files.php +++ b/lib/public/files.php @@ -26,7 +26,7 @@ * */ -// use OCP namespace for all classes that are considered public. +// use OCP namespace for all classes that are considered public. // This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; diff --git a/lib/public/json.php b/lib/public/json.php index 99df79173eb..c37b42c3f74 100644 --- a/lib/public/json.php +++ b/lib/public/json.php @@ -26,7 +26,7 @@ * */ -// use OCP namespace for all classes that are considered public. +// use OCP namespace for all classes that are considered public. // This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; @@ -47,17 +47,17 @@ class JSON { /** * Check if the user is logged in, send json error msg if not. - * + * * This method checks if a user is logged in. If not, a json error * response will be return and the method will exit from execution * of the script. * The returned json will be in the format: - * + * * {"status":"error","data":{"message":"Authentication error."}} - * + * * Add this call to the start of all ajax method files that requires * an authenticated user. - * + * * @return string json formatted error string if not authenticated. */ public static function checkLoggedIn(){ @@ -66,22 +66,22 @@ class JSON { /** * Check an ajax get/post call if the request token is valid. - * + * * This method checks for a valid variable 'requesttoken' in $_GET, * $_POST and $_SERVER. If a valid token is not found, a json error * response will be return and the method will exit from execution * of the script. * The returned json will be in the format: - * + * * {"status":"error","data":{"message":"Token expired. Please reload page."}} - * - * Add this call to the start of all ajax method files that creates, + * + * Add this call to the start of all ajax method files that creates, * updates or deletes anything. * In cases where you e.g. use an ajax call to load a dialog containing * a submittable form, you will need to add the requesttoken first as a * parameter to the ajax call, then assign it to the template and finally * add a hidden input field also named 'requesttoken' containing the value. - * + * * @return string json formatted error string if not valid. */ public static function callCheck(){ @@ -90,10 +90,10 @@ class JSON { /** * Send json success msg - * + * * Return a json success message with optional extra data. - * @see OCP\JSON::error() for the format to use. - * + * @see OCP\JSON::error() for the format to use. + * * @param array $data The data to use * @return string json formatted string. */ @@ -103,19 +103,19 @@ class JSON { /** * Send json error msg - * - * Return a json error message with optional extra data for + * + * Return a json error message with optional extra data for * error message or app specific data. - * + * * Example use: - * + * * $id = [some value] * OCP\JSON::error(array('data':array('message':'An error happened', 'id': $id))); - * + * * Will return the json formatted string: - * + * * {"status":"error","data":{"message":"An error happened", "id":[some value]}} - * + * * @param array $data The data to use * @return string json formatted error string. */ @@ -134,17 +134,17 @@ class JSON { /** * Check if the App is enabled and send JSON error message instead - * + * * This method checks if a specific app is enabled. If not, a json error * response will be return and the method will exit from execution * of the script. * The returned json will be in the format: - * + * * {"status":"error","data":{"message":"Application is not enabled."}} - * + * * Add this call to the start of all ajax method files that requires * a specific app to be enabled. - * + * * @param string $app The app to check * @return string json formatted string if not enabled. */ @@ -154,17 +154,17 @@ class JSON { /** * Check if the user is a admin, send json error msg if not - * + * * This method checks if the current user has admin rights. If not, a json error * response will be return and the method will exit from execution * of the script. * The returned json will be in the format: - * + * * {"status":"error","data":{"message":"Authentication error."}} - * + * * Add this call to the start of all ajax method files that requires * administrative rights. - * + * * @return string json formatted string if not admin user. */ public static function checkAdminUser(){ diff --git a/lib/public/response.php b/lib/public/response.php index 8dff3bcd354..febb3f14361 100644 --- a/lib/public/response.php +++ b/lib/public/response.php @@ -26,7 +26,7 @@ * */ -// use OCP namespace for all classes that are considered public. +// use OCP namespace for all classes that are considered public. // This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; diff --git a/lib/public/share.php b/lib/public/share.php index 93820760d15..9ad0f0f68f6 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -32,7 +32,7 @@ class Share { const SHARE_TYPE_USER = 0; const SHARE_TYPE_GROUP = 1; - const SHARE_TYPE_PRIVATE_LINK = 3; + const SHARE_TYPE_LINK = 3; const SHARE_TYPE_EMAIL = 4; const SHARE_TYPE_CONTACT = 5; const SHARE_TYPE_REMOTE = 6; @@ -67,15 +67,31 @@ class Share { * @return Returns true if backend is registered or false if error */ public static function registerBackend($itemType, $class, $collectionOf = null, $supportedFileExtensions = null) { - if (!isset(self::$backendTypes[$itemType])) { - self::$backendTypes[$itemType] = array('class' => $class, 'collectionOf' => $collectionOf, 'supportedFileExtensions' => $supportedFileExtensions); - if(count(self::$backendTypes) === 1) { - \OC_Util::addScript('core', 'share'); - \OC_Util::addStyle('core', 'share'); + if (self::isEnabled()) { + if (!isset(self::$backendTypes[$itemType])) { + self::$backendTypes[$itemType] = array('class' => $class, 'collectionOf' => $collectionOf, 'supportedFileExtensions' => $supportedFileExtensions); + if(count(self::$backendTypes) === 1) { + \OC_Util::addScript('core', 'share'); + \OC_Util::addStyle('core', 'share'); + } + return true; } + \OC_Log::write('OCP\Share', 'Sharing backend '.$class.' not registered, '.self::$backendTypes[$itemType]['class'].' is already registered for '.$itemType, \OC_Log::WARN); + } + return false; + } + + /** + * @brief Check if the Share API is enabled + * @return Returns true if enabled or false + * + * The Share API is enabled by default if not configured + * + */ + public static function isEnabled() { + if (\OC_Appconfig::getValue('core', 'shareapi_enabled', 'yes') == 'yes') { return true; } - \OC_Log::write('OCP\Share', 'Sharing backend '.$class.' not registered, '.self::$backendTypes[$itemType]['class'].' is already registered for '.$itemType, \OC_Log::WARN); return false; } @@ -113,6 +129,17 @@ class Share { } /** + * @brief Get the item of item type shared by a link + * @param string Item type + * @param string Item source + * @param string Owner of link + * @return Item + */ + public static function getItemSharedWithByLink($itemType, $itemSource, $uidOwner) { + return self::getItems($itemType, $itemSource, self::SHARE_TYPE_LINK, null, $uidOwner, self::FORMAT_NONE, null, 1); + } + + /** * @brief Get the shared items of item type owned by the current user * @param string Item type * @param int Format (optional) Format type must be defined by the backend @@ -138,7 +165,7 @@ class Share { * @brief Share an item with a user, group, or via private link * @param string Item type * @param string Item source - * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_PRIVATE_LINK + * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK * @param string User or group the item is being shared with * @param int CRUDS permissions * @return bool Returns true on success or false on failure @@ -157,11 +184,13 @@ class Share { \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } - $inGroup = array_intersect(\OC_Group::getUserGroups($uidOwner), \OC_Group::getUserGroups($shareWith)); - if (empty($inGroup)) { - $message = 'Sharing '.$itemSource.' failed, because the user '.$shareWith.' is not a member of any groups that '.$uidOwner.' is a member of'; - \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); - throw new \Exception($message); + if (\OC_Appconfig::getValue('core', 'shareapi_share_policy', 'global') == 'groups_only') { + $inGroup = array_intersect(\OC_Group::getUserGroups($uidOwner), \OC_Group::getUserGroups($shareWith)); + if (empty($inGroup)) { + $message = 'Sharing '.$itemSource.' failed, because the user '.$shareWith.' is not a member of any groups that '.$uidOwner.' is a member of'; + \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); + throw new \Exception($message); + } } // Check if the item source is already shared with the user, either from the same owner or a different user if ($checkExists = self::getItems($itemType, $itemSource, self::$shareTypeUserAndGroups, $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) { @@ -198,9 +227,30 @@ class Share { $shareWith = array(); $shareWith['group'] = $group; $shareWith['users'] = array_diff(\OC_Group::usersInGroup($group), array($uidOwner)); - } else if ($shareType === self::SHARE_TYPE_PRIVATE_LINK) { - $shareWith = md5(uniqid($itemSource, true)); + } else if ($shareType === self::SHARE_TYPE_LINK) { + if (\OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes') == 'yes') { + if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_LINK, null, $uidOwner, self::FORMAT_NONE, null, 1)) { + // If password is set delete the old link + if (isset($shareWith)) { + self::delete($checkExists['id']); + } else { + $message = 'Sharing '.$itemSource.' failed, because this item is already shared with a link'; + \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); + throw new \Exception($message); + } + } + // Generate hash of password - same method as user passwords + if (isset($shareWith)) { + $forcePortable = (CRYPT_BLOWFISH != 1); + $hasher = new \PasswordHash(8, $forcePortable); + $shareWith = $hasher->HashPassword($shareWith.\OC_Config::getValue('passwordsalt', '')); + } return self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions); + } + $message = 'Sharing '.$itemSource.' failed, because sharing with links is not allowed'; + \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); + throw new \Exception($message); + return false; } else if ($shareType === self::SHARE_TYPE_CONTACT) { if (!\OC_App::isEnabled('contacts')) { $message = 'Sharing '.$itemSource.' failed, because the contacts app is not enabled'; @@ -262,7 +312,7 @@ class Share { * @brief Unshare an item from a user, group, or delete a private link * @param string Item type * @param string Item source - * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_PRIVATE_LINK + * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK * @param string User or group the item is being shared with * @return Returns true on success or false on failure */ @@ -298,7 +348,7 @@ class Share { * @brief Set the permissions of an item for a specific user or group * @param string Item type * @param string Item source - * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_PRIVATE_LINK + * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK * @param string User or group the item is being shared with * @param int CRUDS permissions * @return Returns true on success or false on failure @@ -407,7 +457,7 @@ class Share { * @brief Get shared items from the database * @param string Item type * @param string Item source or target (optional) - * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, SHARE_TYPE_PRIVATE_LINK, $shareTypeUserAndGroups, or $shareTypeGroupUserUnique + * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, SHARE_TYPE_LINK, $shareTypeUserAndGroups, or $shareTypeGroupUserUnique * @param string User or group the item is being shared with * @param string User that is the owner of shared items (optional) * @param int Format to convert items to with formatItems() @@ -420,6 +470,13 @@ class Share { * */ private static function getItems($itemType, $item = null, $shareType = null, $shareWith = null, $uidOwner = null, $format = self::FORMAT_NONE, $parameters = null, $limit = -1, $includeCollections = false, $itemShareWithBySource = false) { + if (!self::isEnabled()) { + if ($limit == 1 || (isset($uidOwner) && isset($item))) { + return false; + } else { + return array(); + } + } $backend = self::getBackend($itemType); // Get filesystem root to add it to the file target and remove from the file source, match file_source with the file cache if ($itemType == 'file' || $itemType == 'folder') { @@ -444,9 +501,9 @@ class Share { $queryArgs = array($itemType); } } - if (isset($shareType) && isset($shareWith)) { + if (isset($shareType)) { // Include all user and group items - if ($shareType == self::$shareTypeUserAndGroups) { + if ($shareType == self::$shareTypeUserAndGroups && isset($shareWith)) { $where .= ' AND `share_type` IN (?,?,?)'; $queryArgs[] = self::SHARE_TYPE_USER; $queryArgs[] = self::SHARE_TYPE_GROUP; @@ -459,9 +516,12 @@ class Share { $where .= ' AND `uid_owner` != ?'; $queryArgs[] = $shareWith; } else { - $where .= ' AND `share_type` = ? AND `share_with` = ?'; + $where .= ' AND `share_type` = ?'; $queryArgs[] = $shareType; - $queryArgs[] = $shareWith; + if (isset($shareWith)) { + $where .= ' AND `share_with` = ?'; + $queryArgs[] = $shareWith; + } } } if (isset($uidOwner)) { @@ -485,29 +545,33 @@ class Share { } } if (isset($item)) { + if ($includeCollections && $collectionTypes = self::getCollectionItemTypes($itemType)) { + $where .= ' AND ('; + } else { + $where .= ' AND'; + } // If looking for own shared items, check item_source else check item_target if (isset($uidOwner) || $itemShareWithBySource) { // If item type is a file, file source needs to be checked in case the item was converted if ($itemType == 'file' || $itemType == 'folder') { - $where .= ' AND `file_source` = ?'; + $where .= ' `file_source` = ?'; $column = 'file_source'; } else { - $where .= ' AND `item_source` = ?'; + $where .= ' `item_source` = ?'; $column = 'item_source'; } } else { if ($itemType == 'file' || $itemType == 'folder') { - $where .= ' AND `file_target` = ?'; + $where .= ' `file_target` = ?'; } else { - $where .= ' AND `item_target` = ?'; + $where .= ' `item_target` = ?'; } } $queryArgs[] = $item; if ($includeCollections && $collectionTypes = self::getCollectionItemTypes($itemType)) { - // TODO Bart - this doesn't work with only one argument -// $placeholders = join(',', array_fill(0, count($collectionTypes), '?')); -// $where .= " OR item_type IN ('".$placeholders."')"; -// $queryArgs = array_merge($queryArgs, $collectionTypes); + $placeholders = join(',', array_fill(0, count($collectionTypes), '?')); + $where .= ' OR item_type IN ('.$placeholders.'))'; + $queryArgs = array_merge($queryArgs, $collectionTypes); } } if ($limit != -1 && !$includeCollections) { @@ -518,8 +582,12 @@ class Share { } // The limit must be at least 3, because filtering needs to be done if ($limit < 3) { - $limit = 3; + $queryLimit = 3; + } else { + $queryLimit = $limit; } + } else { + $queryLimit = null; } // TODO Optimize selects if ($format == self::FORMAT_STATUSES) { @@ -548,7 +616,7 @@ class Share { } } $root = strlen($root); - $query = \OC_DB::prepare('SELECT '.$select.' FROM `*PREFIX*share` '.$where, $limit); + $query = \OC_DB::prepare('SELECT '.$select.' FROM `*PREFIX*share` '.$where, $queryLimit); $result = $query->execute($queryArgs); $items = array(); $targets = array(); @@ -606,28 +674,30 @@ class Share { } } // Check if this is a collection of the requested item type - if ($includeCollections && $row['item_type'] != $itemType && ($collectionBackend = self::getBackend($row['item_type'])) && $collectionBackend instanceof Share_Backend_Collection) { - $row['collection'] = array('item_type' => $itemType, $column => $row[$column]); - // Fetch all of the children sources - $children = $collectionBackend->getChildren($row[$column]); - foreach ($children as $child) { - $childItem = $row; - $childItem['item_source'] = $child; -// $childItem['item_target'] = $child['target']; TODO - if (isset($item)) { - if ($childItem[$column] == $item) { - // Return only the item instead of a 2-dimensional array - if ($limit == 1 && $format == self::FORMAT_NONE) { - return $childItem; - } else { - // Unset the items array and break out of both loops - $items = array(); - $items[] = $childItem; - break 2; + if ($includeCollections && $row['item_type'] != $itemType) { + if (($collectionBackend = self::getBackend($row['item_type'])) && $collectionBackend instanceof Share_Backend_Collection) { + $row['collection'] = array('item_type' => $itemType, $column => $row[$column]); + // Fetch all of the children sources + $children = $collectionBackend->getChildren($row[$column]); + foreach ($children as $child) { + $childItem = $row; + $childItem['item_source'] = $child; + // $childItem['item_target'] = $child['target']; TODO + if (isset($item)) { + if ($childItem[$column] == $item) { + // Return only the item instead of a 2-dimensional array + if ($limit == 1 && $format == self::FORMAT_NONE) { + return $childItem; + } else { + // Unset the items array and break out of both loops + $items = array(); + $items[] = $childItem; + break 2; + } } + } else { + $collectionItems[] = $childItem; } - } else { - $collectionItems[] = $childItem; } } // Remove collection item @@ -646,7 +716,7 @@ class Share { $column = 'path'; } foreach ($items as $item) { - if ($item['share_type'] == self::SHARE_TYPE_PRIVATE_LINK) { + if ($item['share_type'] == self::SHARE_TYPE_LINK) { $statuses[$item[$column]] = true; } else if (!isset($statuses[$item[$column]])) { $statuses[$item[$column]] = false; @@ -666,7 +736,7 @@ class Share { * @brief Put shared item into the database * @param string Item type * @param string Item source - * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_PRIVATE_LINK + * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK * @param string User or group the item is being shared with * @param int CRUDS permissions * @param bool|array Parent folder target (optional) @@ -823,7 +893,7 @@ class Share { * @brief Generate a unique target for the item * @param string Item type * @param string Item source - * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_PRIVATE_LINK + * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK * @param string User or group the item is being shared with * @return string Item target * @@ -832,7 +902,7 @@ class Share { */ private static function generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner) { $backend = self::getBackend($itemType); - if ($shareType == self::SHARE_TYPE_PRIVATE_LINK) { + if ($shareType == self::SHARE_TYPE_LINK) { return $backend->generateTarget($itemSource, false); } else { if ($itemType == 'file' || $itemType == 'folder') { @@ -1049,5 +1119,3 @@ interface Share_Backend_Collection extends Share_Backend { public function getChildren($itemSource); } - -?> diff --git a/lib/public/template.php b/lib/public/template.php index a0ed618cb2c..11c740d13ac 100644 --- a/lib/public/template.php +++ b/lib/public/template.php @@ -26,7 +26,7 @@ * */ -// use OCP namespace for all classes that are considered public. +// use OCP namespace for all classes that are considered public. // This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; @@ -88,13 +88,13 @@ function simple_file_size($bytes) { /** * @brief Generate html code for an options block. - * @param $options the options - * @param $selected which one is selected? - * @param $params the parameters + * @param $options the options + * @param $selected which one is selected? + * @param $params the parameters * @returns html options */ function html_select_options($options, $selected, $params=array()) { - return(\html_select_options($options, $selected, $params)); + return(\html_select_options($options, $selected, $params)); } diff --git a/lib/public/user.php b/lib/public/user.php index 2fa599488a7..6228268d75b 100644 --- a/lib/public/user.php +++ b/lib/public/user.php @@ -26,7 +26,7 @@ * */ -// use OCP namespace for all classes that are considered public. +// use OCP namespace for all classes that are considered public. // This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; diff --git a/lib/public/util.php b/lib/public/util.php index 9f6f6f32e1e..6ad578441e2 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -144,6 +144,17 @@ class Util { return(\OC_Helper::linkToRemote( $service )); } + /** + * @brief Creates an absolute url for public use + * @param $service id + * @returns the url + * + * Returns a absolute url to the given app and file. + */ + public static function linkToPublic($service) { + return \OC_Helper::linkToPublic($service); + } + /** * @brief Creates an url @@ -249,7 +260,7 @@ class Util { /** - * Register an get/post call. This is important to prevent CSRF attacks + * Register an get/post call. This is important to prevent CSRF attacks * TODO: write example */ public static function callRegister(){ diff --git a/lib/search.php b/lib/search.php index f8a4b8e96eb..9dfd0cf69ef 100644 --- a/lib/search.php +++ b/lib/search.php @@ -27,7 +27,7 @@ class OC_Search{ static private $providers=array(); static private $registeredProviders=array(); - + /** * remove all registered search providers */ @@ -35,7 +35,7 @@ class OC_Search{ self::$providers=array(); self::$registeredProviders=array(); } - + /** * register a new search provider to be used * @param string $provider class name of a OC_Search_Provider @@ -43,7 +43,7 @@ class OC_Search{ public static function registerProvider($class,$options=array()){ self::$registeredProviders[]=array('class'=>$class,'options'=>$options); } - + /** * search all provider for $query * @param string query @@ -57,7 +57,7 @@ class OC_Search{ } return $results; } - + /** * create instances of all the registered search providers */ diff --git a/lib/search/provider.php b/lib/search/provider.php index b3ee79b4770..b83c5aa61b6 100644 --- a/lib/search/provider.php +++ b/lib/search/provider.php @@ -4,11 +4,11 @@ */ abstract class OC_Search_Provider { private $options; - + public function __construct($options){ $this->options=$options; } - + /** * search for $query * @param string $query diff --git a/lib/setup.php b/lib/setup.php index f7e8c6950ce..271fe55fd70 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -18,7 +18,7 @@ if(isset($_POST['install']) AND $_POST['install']=='true') { // We have to launch the installation process : $e = OC_Setup::install($_POST); $errors = array('errors' => $e); - + if(count($e) > 0) { //OC_Template::printGuestPage("", "error", array("errors" => $errors)); $options = array_merge($_POST, $opts, $errors); @@ -37,7 +37,7 @@ class OC_Setup { public static function install($options) { $error = array(); $dbtype = $options['dbtype']; - + if(empty($options['adminlogin'])) { $error[] = 'Set an admin username.'; } @@ -72,7 +72,7 @@ class OC_Setup { $username = htmlspecialchars_decode($options['adminlogin']); $password = htmlspecialchars_decode($options['adminpass']); $datadir = htmlspecialchars_decode($options['directory']); - + //use sqlite3 when available, otherise sqlite2 will be used. if($dbtype=='sqlite' and class_exists('SQLite3')){ $dbtype='sqlite3'; @@ -84,8 +84,8 @@ class OC_Setup { //write the config file OC_Config::setValue('datadirectory', $datadir); - OC_Config::setValue('dbtype', $dbtype); - OC_Config::setValue('version',implode('.',OC_Util::getVersion())); + OC_Config::setValue('dbtype', $dbtype); + OC_Config::setValue('version',implode('.',OC_Util::getVersion())); if($dbtype == 'mysql') { $dbuser = $options['dbuser']; $dbpass = $options['dbpass']; @@ -107,7 +107,7 @@ class OC_Setup { } else { $oldUser=OC_Config::getValue('dbuser', false); - + $query="SELECT user FROM mysql.user WHERE user='$dbuser'"; //this should be enough to check for admin rights in mysql if(mysql_query($query, $connection)) { //use the admin login data for the new database user @@ -184,9 +184,9 @@ class OC_Setup { $dbusername='oc_'.$username; //create a new password so we don't need to store the admin config in the config file $dbpassword=md5(time()); - + self::pg_createDBUser($dbusername, $dbpassword, $connection); - + OC_CONFIG::setValue('dbuser', $dbusername); OC_CONFIG::setValue('dbpassword', $dbpassword); @@ -257,7 +257,7 @@ class OC_Setup { ); return $error; } else { - //check for roles creation rights in oracle + //check for roles creation rights in oracle $query="SELECT count(*) FROM user_role_privs, role_sys_privs WHERE user_role_privs.granted_role = role_sys_privs.role AND privilege = 'CREATE ROLE'"; $stmt = oci_parse($connection, $query); @@ -342,7 +342,7 @@ class OC_Setup { } } } - } + } else { //delete the old sqlite database first, might cause infinte loops otherwise if(file_exists("$datadir/owncloud.db")){ @@ -428,7 +428,7 @@ class OC_Setup { } } $query = "REVOKE ALL PRIVILEGES ON DATABASE \"$e_name\" FROM PUBLIC"; - $result = pg_query($connection, $query); + $result = pg_query($connection, $query); } private static function pg_createDBUser($name,$password,$connection) { @@ -463,7 +463,7 @@ class OC_Setup { } } /** - * + * * @param String $name * @param String $password * @param String $tablespace @@ -552,7 +552,7 @@ class OC_Setup { $content.= "</IfModule>\n"; $content.= "<IfModule mod_rewrite.c>\n"; $content.= "RewriteEngine on\n"; - $content.= "RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]\n"; + $content.= "RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]\n"; $content.= "RewriteRule ^.well-known/host-meta /public.php?service=host-meta [QSA,L]\n"; $content.= "RewriteRule ^.well-known/carddav /remote.php/carddav/ [R]\n"; $content.= "RewriteRule ^.well-known/caldav /remote.php/caldav/ [R]\n"; diff --git a/lib/subadmin.php b/lib/subadmin.php index 8d4f413b104..4752492df30 100644 --- a/lib/subadmin.php +++ b/lib/subadmin.php @@ -3,7 +3,7 @@ * ownCloud * * @author Georg Ehrke - * @copyright 2012 Georg Ehrke + * @copyright 2012 Georg Ehrke * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE @@ -85,7 +85,7 @@ class OC_SubAdmin{ } return $uids; } - + /** * @brief get all SubAdmins * @return array @@ -99,7 +99,7 @@ class OC_SubAdmin{ } return $subadmins; } - + /** * @brief checks if a user is a SubAdmin of a group * @param $uid uid of the subadmin @@ -115,7 +115,7 @@ class OC_SubAdmin{ } return false; } - + /** * @brief checks if a user is a SubAdmin * @param $uid uid of the subadmin @@ -130,7 +130,7 @@ class OC_SubAdmin{ } return false; } - + /** * @brief checks if a user is a accessible by a subadmin * @param $subadmin uid of the subadmin @@ -141,6 +141,9 @@ class OC_SubAdmin{ if(!self::isSubAdmin($subadmin)){ return false; } + if(OC_Group::inGroup($user, 'admin')){ + return false; + } $accessiblegroups = self::getSubAdminsGroups($subadmin); foreach($accessiblegroups as $accessiblegroup){ if(OC_Group::inGroup($user, $accessiblegroup)){ @@ -149,7 +152,7 @@ class OC_SubAdmin{ } return false; } - + /* * @brief alias for self::isSubAdminofGroup() */ @@ -159,7 +162,7 @@ class OC_SubAdmin{ /** * @brief delete all SubAdmins by uid - * @param $parameters + * @param $parameters * @return boolean */ public static function post_deleteUser($parameters){ diff --git a/lib/template.php b/lib/template.php index a10ddcd5c33..fe8a3c79943 100644 --- a/lib/template.php +++ b/lib/template.php @@ -161,7 +161,7 @@ class OC_Template{ header('X-Frame-Options: Sameorigin'); header('X-XSS-Protection: 1; mode=block'); header('X-Content-Type-Options: nosniff'); - + $this->findTemplate($name); } @@ -171,8 +171,8 @@ class OC_Template{ * mobile -> interface for smartphones * tablet -> interface for tablets * standalone -> the default interface but without header, footer and - * sidebar, just the application. Useful to use just a specific - * app on the desktop in a standalone window. + * sidebar, just the application. Useful to use just a specific + * app on the desktop in a standalone window. */ public static function detectFormfactor(){ // please add more useragent strings for other devices @@ -208,13 +208,13 @@ class OC_Template{ $_SESSION['formfactor']=$_GET['formfactor']; } $formfactor=$_SESSION['formfactor']; - if($formfactor=='default') { + if($formfactor=='default') { $fext=''; - }elseif($formfactor=='mobile') { + }elseif($formfactor=='mobile') { $fext='.mobile'; - }elseif($formfactor=='tablet') { + }elseif($formfactor=='tablet') { $fext='.tablet'; - }elseif($formfactor=='standalone') { + }elseif($formfactor=='standalone') { $fext='.standalone'; }else{ $fext=''; diff --git a/lib/templatelayout.php b/lib/templatelayout.php index 588a7845997..18fd23aac95 100644 --- a/lib/templatelayout.php +++ b/lib/templatelayout.php @@ -29,14 +29,16 @@ class OC_TemplateLayout extends OC_Template { break; } } - }else{ - parent::__construct( 'core', 'layout.guest' ); + } else if ($renderas == 'guest') { + parent::__construct('core', 'layout.guest'); + } else { + parent::__construct('core', 'layout.base'); } $apps_paths = array(); foreach(OC_App::getEnabledApps() as $app){ $apps_paths[$app] = OC_App::getAppWebPath($app); - } + } $this->assign( 'apps_paths', str_replace('\\/', '/',json_encode($apps_paths)),false ); // Ugly unescape slashes waiting for better solution // Add the js files @@ -63,7 +65,7 @@ class OC_TemplateLayout extends OC_Template { foreach(OC::$APPSROOTS as $app_root) { if($root == $app_root['path']) { $in_root = true; - break; + break; } } diff --git a/lib/user.php b/lib/user.php index 06a56b7f4a6..c432f6074a6 100644 --- a/lib/user.php +++ b/lib/user.php @@ -333,6 +333,27 @@ class OC_User { } /** + * @brief Check if the password is correct + * @param $uid The username + * @param $password The password + * @returns string + * + * Check if the password is correct without logging in the user + * returns the user id or false + */ + public static function getHome($uid){ + foreach(self::$_usedBackends as $backend){ + if($backend->implementsActions(OC_USER_BACKEND_GET_HOME)){ + $result=$backend->getHome($uid); + if($result){ + return $result; + } + } + } + return OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ) . '/' . $uid; + } + + /** * @brief Get a list of all users * @returns array with all uids * @@ -364,7 +385,7 @@ class OC_User { } return false; } - + /** * disables a user * @param string $userid the user to disable @@ -374,7 +395,7 @@ class OC_User { $query = OC_DB::prepare($query); $query->execute(array($userid, 'core', 'enabled', 'false')); } - + /** * enable a user * @param string $userid @@ -384,7 +405,7 @@ class OC_User { $query = OC_DB::prepare($query); $query->execute(array($userid, 'core', 'enabled', 'false')); } - + /** * checks if a user is enabled * @param string $userid diff --git a/lib/user/backend.php b/lib/user/backend.php index f67908cdac0..36e4bd9f761 100644 --- a/lib/user/backend.php +++ b/lib/user/backend.php @@ -34,6 +34,7 @@ define('OC_USER_BACKEND_NOT_IMPLEMENTED', -501); define('OC_USER_BACKEND_CREATE_USER', 0x000001); define('OC_USER_BACKEND_SET_PASSWORD', 0x000010); define('OC_USER_BACKEND_CHECK_PASSWORD', 0x000100); +define('OC_USER_BACKEND_GET_HOME', 0x001000); /** @@ -48,6 +49,7 @@ abstract class OC_User_Backend implements OC_User_Interface { OC_USER_BACKEND_CREATE_USER => 'createUser', OC_USER_BACKEND_SET_PASSWORD => 'setPassword', OC_USER_BACKEND_CHECK_PASSWORD => 'checkPassword', + OC_USER_BACKEND_GET_HOME => 'getHome', ); /** @@ -109,4 +111,13 @@ abstract class OC_User_Backend implements OC_User_Interface { public function userExists($uid){ return false; } + + /** + * @brief get the user's home directory + * @param string $uid the username + * @return boolean + */ + public function getHome($uid){ + return false; + } } diff --git a/lib/user/database.php b/lib/user/database.php index dff4d145fc7..52f3b35fa5c 100644 --- a/lib/user/database.php +++ b/lib/user/database.php @@ -43,7 +43,7 @@ class OC_User_Database extends OC_User_Backend { * @var PasswordHash */ static private $hasher=null; - + private function getHasher(){ if(!self::$hasher){ //we don't want to use DES based crypt(), since it doesn't return a has with a recognisable prefix @@ -53,7 +53,7 @@ class OC_User_Database extends OC_User_Backend { return self::$hasher; } - + /** * @brief Create a new user * @param $uid The username of the user to create @@ -121,7 +121,7 @@ class OC_User_Database extends OC_User_Backend { * returns the user id or false */ public function checkPassword( $uid, $password ){ - $query = OC_DB::prepare( 'SELECT `uid`, `password` FROM `*PREFIX*users` WHERE `uid` = ?' ); + $query = OC_DB::prepare( 'SELECT `uid`, `password` FROM `*PREFIX*users` WHERE LOWER(`uid`) = LOWER(?)' ); $result = $query->execute( array( $uid)); $row=$result->fetchRow(); @@ -170,9 +170,22 @@ class OC_User_Database extends OC_User_Backend { * @return boolean */ public function userExists($uid){ - $query = OC_DB::prepare( 'SELECT * FROM `*PREFIX*users` WHERE `uid` = ?' ); + $query = OC_DB::prepare( 'SELECT * FROM `*PREFIX*users` WHERE LOWER(`uid`) = LOWER(?)' ); $result = $query->execute( array( $uid )); - + return $result->numRows() > 0; } + + /** + * @brief get the user's home directory + * @param string $uid the username + * @return boolean + */ + public function getHome($uid){ + if($this->userExists($uid)){ + return OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ) . '/' . $uid; + }else{ + return false; + } + } } diff --git a/lib/user/example.php b/lib/user/example.php index 77246d8136c..b2d0dc25410 100644 --- a/lib/user/example.php +++ b/lib/user/example.php @@ -57,4 +57,14 @@ abstract class OC_User_Example extends OC_User_Backend { * returns the user id or false */ abstract public function checkPassword($uid, $password); + + /** + * @brief get the user's home directory + * @param $uid The username + * @returns string + * + * get the user's home directory + * returns the path or false + */ + abstract public function getHome($uid); } diff --git a/lib/user/http.php b/lib/user/http.php index 009aa30c6f5..5149678e4ed 100644 --- a/lib/user/http.php +++ b/lib/user/http.php @@ -41,9 +41,9 @@ class OC_User_HTTP extends OC_User_Backend { $url.='?'.$parts['query']; } return array($parts['user'],$url); - + } - + /** * check if an url is a valid login * @param string url @@ -52,7 +52,7 @@ class OC_User_HTTP extends OC_User_Backend { private function matchUrl($url){ return ! is_null(parse_url($url,PHP_URL_USER)); } - + /** * @brief Check if the password is correct * @param $uid The username @@ -67,7 +67,7 @@ class OC_User_HTTP extends OC_User_Backend { return false; } list($user,$url)=$this->parseUrl($uid); - + $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERPWD, $user.':'.$password); @@ -76,7 +76,7 @@ class OC_User_HTTP extends OC_User_Backend { curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); - + curl_close($ch); return $status==200; @@ -90,4 +90,17 @@ class OC_User_HTTP extends OC_User_Backend { public function userExists($uid){ return $this->matchUrl($uid); } + + /** + * @brief get the user's home directory + * @param string $uid the username + * @return boolean + */ + public function getHome($uid){ + if($this->userExists($uid)){ + return OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ) . '/' . $uid; + }else{ + return false; + } + } }
\ No newline at end of file diff --git a/lib/util.php b/lib/util.php index e63eb5b24c9..10b88b24438 100755 --- a/lib/util.php +++ b/lib/util.php @@ -19,6 +19,18 @@ class OC_Util { return false; } + // If we are not forced to load a specific user we load the one that is logged in + if( $user == "" && OC_User::isLoggedIn()){ + $user = OC_User::getUser(); + } + + // the filesystem will finish when $user is not empty, + // mark fs setup here to avoid doing the setup from loading + // OC_Filesystem + if ($user != '') { + self::$fsSetup=true; + } + $CONFIG_DATADIRECTORY = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ); //first set up the local "root" storage if(!self::$rootMounted){ @@ -26,26 +38,21 @@ class OC_Util { self::$rootMounted=true; } - // If we are not forced to load a specific user we load the one that is logged in - if( $user == "" && OC_User::isLoggedIn()){ - $user = OC_User::getUser(); - } - if( $user != "" ){ //if we aren't logged in, there is no use to set up the filesystem $user_dir = '/'.$user.'/files'; - $userdirectory = $CONFIG_DATADIRECTORY.$user_dir; + $user_root = OC_User::getHome($user); + $userdirectory = $user_root . '/files'; if( !is_dir( $userdirectory )){ mkdir( $userdirectory, 0755, true ); } - //jail the user into his "home" directory + OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => $user_root), $user); OC_Filesystem::init($user_dir); $quotaProxy=new OC_FileProxy_Quota(); OC_FileProxy::register($quotaProxy); - self::$fsSetup=true; // Load personal mount config - if (is_file($CONFIG_DATADIRECTORY.'/'.$user.'/mount.php')) { - $mountConfig = include($CONFIG_DATADIRECTORY.'/'.$user.'/mount.php'); + if (is_file($user_root.'/mount.php')) { + $mountConfig = include($user_root.'/mount.php'); if (isset($mountConfig['user'][$user])) { foreach ($mountConfig['user'][$user] as $mountPoint => $options) { OC_Filesystem::mount($options['class'], $options['options'], $mountPoint); @@ -66,7 +73,8 @@ class OC_Util { * @return array */ public static function getVersion(){ - return array(4,82,4); + // hint: We only can count up. So the internal version number of ownCloud 4.5 will be 4,9,0. This is not visible to the user + return array(4,83,5); } /** @@ -74,7 +82,7 @@ class OC_Util { * @return string */ public static function getVersionString(){ - return '5 pre alpha 1'; + return '4.5 beta 1'; } /** @@ -201,7 +209,7 @@ class OC_Util { // Check if there is a writable install folder. if(OC_Config::getValue('appstoreenabled', true)) { if( OC_App::getInstallPath() === null || !is_writable(OC_App::getInstallPath())) { - $errors[]=array('error'=>"Can't write into apps directory",'hint'=>"You can usually fix this by giving the webserver user write access to the apps directory + $errors[]=array('error'=>"Can't write into apps directory",'hint'=>"You can usually fix this by giving the webserver user write access to the apps directory in owncloud or disabling the appstore in the config file."); } } @@ -209,7 +217,7 @@ class OC_Util { $CONFIG_DATADIRECTORY = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ); //check for correct file permissions if(!stristr(PHP_OS, 'WIN')){ - $permissionsModHint="Please change the permissions to 0770 so that the directory cannot be listed by other users."; + $permissionsModHint="Please change the permissions to 0770 so that the directory cannot be listed by other users."; $prems=substr(decoct(@fileperms($CONFIG_DATADIRECTORY)),-3); if(substr($prems,-1)!='0'){ OC_Helper::chmodr($CONFIG_DATADIRECTORY,0770); @@ -400,15 +408,15 @@ class OC_Util { // cleanup old tokens garbage collector // only run every 20th time so we don't waste cpu cycles - if(rand(0,20)==0) { + if(rand(0,20)==0) { foreach($_SESSION as $key=>$value) { // search all tokens in the session if(substr($key,0,12)=='requesttoken') { if($value+$maxtime<time()){ // remove outdated tokens - unset($_SESSION[$key]); + unset($_SESSION[$key]); } - } + } } } // return the token @@ -455,13 +463,13 @@ class OC_Util { exit; } } - + /** * @brief Public function to sanitize HTML * * This function is used to sanitize HTML and should be applied on any * string or array of strings before displaying it on a web page. - * + * * @param string or array of strings * @return array with sanitized strings or a single sanitized string, depends on the input parameter. */ diff --git a/lib/vcategories.php b/lib/vcategories.php index 20d9e3b5d61..05dfe18db6f 100644 --- a/lib/vcategories.php +++ b/lib/vcategories.php @@ -129,7 +129,7 @@ class OC_VCategories { * $objects[] = $row['carddata']; * } * } - * $categories->rescan($objects); + * $categories->rescan($objects); */ public function rescan($objects, $sync=true, $reset=true) { if($reset === true) { @@ -219,7 +219,7 @@ class OC_VCategories { if(!is_array($haystack)) { return false; } - return array_search(strtolower($needle),array_map('strtolower',$haystack)); + return array_search(strtolower($needle),array_map('strtolower',$haystack)); } } |