Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorRobin Appelman <icewind1991@gmail.com>2010-09-06 22:02:17 +0400
committerRobin Appelman <icewind1991@gmail.com>2010-09-06 22:02:17 +0400
commit5162809c8afd722a00de90390f94e173cac8431a (patch)
tree10831f5d104831dd236d9e0094fca07af8bb9a23 /inc
parentb479f9d570054bc5630a600d9321444216e2e4a2 (diff)
make the filesystem configurable (no gui yet)
Diffstat (limited to 'inc')
-rw-r--r--inc/lib_base.php27
-rw-r--r--inc/lib_filestorage.php2
-rw-r--r--inc/lib_filesystem.php47
3 files changed, 73 insertions, 3 deletions
diff --git a/inc/lib_base.php b/inc/lib_base.php
index f989bc4dbdf..0f355eb3487 100644
--- a/inc/lib_base.php
+++ b/inc/lib_base.php
@@ -111,17 +111,23 @@ $loginresult=OC_USER::loginlisener();
*/
class OC_UTIL {
public static $scripts=array();
+ private static $fsSetup=false;
public static function setupFS(){// configure the initial filesystem based on the configuration
+ if(self::$fsSetup){//setting up the filesystem twice can only lead to trouble
+ return false;
+ }
global $CONFIG_DATADIRECTORY_ROOT;
global $CONFIG_DATADIRECTORY;
global $CONFIG_BACKUPDIRECTORY;
global $CONFIG_ENABLEBACKUP;
+ global $CONFIG_FILESYSTEM;
if(!is_dir($CONFIG_DATADIRECTORY_ROOT)){
@mkdir($CONFIG_DATADIRECTORY_ROOT) or die("Can't create data directory ($CONFIG_DATADIRECTORY_ROOT), you can usually fix this by setting the owner of '$SERVERROOT' to the user that the web server uses (www-data for debian/ubuntu)");
}
- if(OC_USER::isLoggedIn()){
- $rootStorage=new OC_FILESTORAGE_LOCAL(array('datadir'=>$CONFIG_DATADIRECTORY));
+ if(OC_USER::isLoggedIn()){ //if we aren't logged in, there is no use to set up the filesystem
+ //first set up the local "root" storage and the backupstorage if needed
+ $rootStorage=OC_FILESYSTEM::createStorage('local',array('datadir'=>$CONFIG_DATADIRECTORY));
if($CONFIG_ENABLEBACKUP){
if(!is_dir($CONFIG_BACKUPDIRECTORY)){
mkdir($CONFIG_BACKUPDIRECTORY);
@@ -129,7 +135,7 @@ class OC_UTIL {
if(!is_dir($CONFIG_BACKUPDIRECTORY.'/'.$_SESSION['username_clean'])){
mkdir($CONFIG_BACKUPDIRECTORY.'/'.$_SESSION['username_clean']);
}
- $backupStorage=new OC_FILESTORAGE_LOCAL(array('datadir'=>$CONFIG_BACKUPDIRECTORY));
+ $backupStorage=OC_FILESYSTEM::createStorage('local',array('datadir'=>$CONFIG_BACKUPDIRECTORY));
$backup=new OC_FILEOBSERVER_BACKUP(array('storage'=>$backupStorage));
$rootStorage->addObserver($backup);
}
@@ -140,7 +146,22 @@ class OC_UTIL {
mkdir($CONFIG_DATADIRECTORY);
}
+ //set up the other storages according to the system settings
+ foreach($CONFIG_FILESYSTEM as $storageConfig){
+ if(OC_FILESYSTEM::hasStorageType($storageConfig['type'])){
+ $arguments=$storageConfig;
+ unset($arguments['type']);
+ unset($arguments['mountpoint']);
+ $storage=OC_FILESYSTEM::createStorage($storageConfig['type'],$arguments);
+ if($storage){
+ OC_FILESYSTEM::mount($storage,$storageConfig['mountpoint']);
+ }
+ }
+ }
+
+ //jail the user into his "home" directory
OC_FILESYSTEM::chroot('/'.$_SESSION['username_clean']);
+ self::$fsSetup=true;
}
}
diff --git a/inc/lib_filestorage.php b/inc/lib_filestorage.php
index b63dd200b36..62532916ca5 100644
--- a/inc/lib_filestorage.php
+++ b/inc/lib_filestorage.php
@@ -75,6 +75,8 @@ class OC_FILESTORAGE{
public function getTree($path){}
}
+
+OC_FILESYSTEM::registerStorageType('local','OC_FILESTORAGE_LOCAL',array('datadir'=>'string'));
/**
* for local filestore, we only have to map the paths
*/
diff --git a/inc/lib_filesystem.php b/inc/lib_filesystem.php
index 3a2373f166b..263b1d7a419 100644
--- a/inc/lib_filesystem.php
+++ b/inc/lib_filesystem.php
@@ -30,6 +30,53 @@
class OC_FILESYSTEM{
static private $storages=array();
static private $fakeRoot='';
+ static private $storageTypes=array();
+
+
+ /**
+ * register a storage type
+ * @param string type
+ * @param string classname
+ * @param array arguments an associative array in the form of name=>type (eg array('datadir'=>'string'))
+ */
+ static public function registerStorageType($type,$classname,$arguments){
+ self::$storageTypes[$type]=array('type'=>$type,'classname'=>$classname,'arguments'=>$arguments);
+ }
+
+ /**
+ * check if the filesystem supports a specific storagetype
+ * @param string type
+ * @return bool
+ */
+ static public function hasStorageType($type){
+ return isset(self::$storageTypes[$type]);
+ }
+
+ /**
+ * get the list of names of storagetypes that the filesystem supports
+ * @return array
+ */
+ static public function getStorageTypeNames(){
+ return array_keys(self::$storageTypes);
+ }
+
+ /**
+ * create a new storage of a specific type
+ * @param string type
+ * @param array arguments
+ * @return OC_FILESTORAGE
+ */
+ static public function createStorage($type,$arguments){
+ if(!self::hasStorageType($type)){
+ return false;
+ }
+ $className=self::$storageTypes[$type]['classname'];
+ if(class_exists($className)){
+ return new $className($arguments);
+ }else{
+ return false;
+ }
+ }
/**
* change the root to a fake toor