make the filesystem configurable (no gui yet)
This commit is contained in:
parent
b479f9d570
commit
5162809c8a
|
@ -111,17 +111,23 @@ $loginresult=OC_USER::loginlisener();
|
||||||
*/
|
*/
|
||||||
class OC_UTIL {
|
class OC_UTIL {
|
||||||
public static $scripts=array();
|
public static $scripts=array();
|
||||||
|
private static $fsSetup=false;
|
||||||
|
|
||||||
public static function setupFS(){// configure the initial filesystem based on the configuration
|
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_ROOT;
|
||||||
global $CONFIG_DATADIRECTORY;
|
global $CONFIG_DATADIRECTORY;
|
||||||
global $CONFIG_BACKUPDIRECTORY;
|
global $CONFIG_BACKUPDIRECTORY;
|
||||||
global $CONFIG_ENABLEBACKUP;
|
global $CONFIG_ENABLEBACKUP;
|
||||||
|
global $CONFIG_FILESYSTEM;
|
||||||
if(!is_dir($CONFIG_DATADIRECTORY_ROOT)){
|
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)");
|
@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()){
|
if(OC_USER::isLoggedIn()){ //if we aren't logged in, there is no use to set up the filesystem
|
||||||
$rootStorage=new OC_FILESTORAGE_LOCAL(array('datadir'=>$CONFIG_DATADIRECTORY));
|
//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($CONFIG_ENABLEBACKUP){
|
||||||
if(!is_dir($CONFIG_BACKUPDIRECTORY)){
|
if(!is_dir($CONFIG_BACKUPDIRECTORY)){
|
||||||
mkdir($CONFIG_BACKUPDIRECTORY);
|
mkdir($CONFIG_BACKUPDIRECTORY);
|
||||||
|
@ -129,7 +135,7 @@ class OC_UTIL {
|
||||||
if(!is_dir($CONFIG_BACKUPDIRECTORY.'/'.$_SESSION['username_clean'])){
|
if(!is_dir($CONFIG_BACKUPDIRECTORY.'/'.$_SESSION['username_clean'])){
|
||||||
mkdir($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));
|
$backup=new OC_FILEOBSERVER_BACKUP(array('storage'=>$backupStorage));
|
||||||
$rootStorage->addObserver($backup);
|
$rootStorage->addObserver($backup);
|
||||||
}
|
}
|
||||||
|
@ -140,7 +146,22 @@ class OC_UTIL {
|
||||||
mkdir($CONFIG_DATADIRECTORY);
|
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']);
|
OC_FILESYSTEM::chroot('/'.$_SESSION['username_clean']);
|
||||||
|
self::$fsSetup=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,8 @@ class OC_FILESTORAGE{
|
||||||
public function getTree($path){}
|
public function getTree($path){}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
OC_FILESYSTEM::registerStorageType('local','OC_FILESTORAGE_LOCAL',array('datadir'=>'string'));
|
||||||
/**
|
/**
|
||||||
* for local filestore, we only have to map the paths
|
* for local filestore, we only have to map the paths
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -30,6 +30,53 @@
|
||||||
class OC_FILESYSTEM{
|
class OC_FILESYSTEM{
|
||||||
static private $storages=array();
|
static private $storages=array();
|
||||||
static private $fakeRoot='';
|
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
|
* change the root to a fake toor
|
||||||
|
|
|
@ -39,23 +39,7 @@ if(empty($_SERVER['PHP_AUTH_USER']) && empty($_SERVER['REDIRECT_REMOTE_USER']))
|
||||||
$user=$_SERVER['PHP_AUTH_USER'];
|
$user=$_SERVER['PHP_AUTH_USER'];
|
||||||
$passwd=$_SERVER['PHP_AUTH_PW'];
|
$passwd=$_SERVER['PHP_AUTH_PW'];
|
||||||
if(OC_USER::login($user,$passwd)){
|
if(OC_USER::login($user,$passwd)){
|
||||||
$CONFIG_DATADIRECTORY=$CONFIG_DATADIRECTORY_ROOT.'/'.$user;
|
OC_UTIL::setUpFS();
|
||||||
if(!is_dir($CONFIG_DATADIRECTORY)){
|
|
||||||
mkdir($CONFIG_DATADIRECTORY);
|
|
||||||
}
|
|
||||||
$rootStorage=new OC_FILESTORAGE_LOCAL(array('datadir'=>$CONFIG_DATADIRECTORY));
|
|
||||||
if($CONFIG_ENABLEBACKUP){
|
|
||||||
if(!is_dir($CONFIG_BACKUPDIRECTORY)){
|
|
||||||
mkdir($CONFIG_BACKUPDIRECTORY);
|
|
||||||
}
|
|
||||||
if(!is_dir($CONFIG_BACKUPDIRECTORY.'/'.$user)){
|
|
||||||
mkdir($CONFIG_BACKUPDIRECTORY.'/'.$user);
|
|
||||||
}
|
|
||||||
$backupStorage=new OC_FILESTORAGE_LOCAL(array('datadir'=>$CONFIG_BACKUPDIRECTORY.'/'.$user));
|
|
||||||
$backup=new OC_FILEOBSERVER_BACKUP(array('storage'=>$backupStorage));
|
|
||||||
$rootStorage->addObserver($backup);
|
|
||||||
}
|
|
||||||
OC_FILESYSTEM::mount($rootStorage,'/');
|
|
||||||
$server = new HTTP_WebDAV_Server_Filesystem();
|
$server = new HTTP_WebDAV_Server_Filesystem();
|
||||||
$server->db_name = $CONFIG_DBNAME;
|
$server->db_name = $CONFIG_DBNAME;
|
||||||
$server->ServeRequest($CONFIG_DATADIRECTORY);
|
$server->ServeRequest($CONFIG_DATADIRECTORY);
|
||||||
|
|
Loading…
Reference in New Issue