Ejemplo n.º 1
0
 public static function setupFS($user = '')
 {
     // configure the initial filesystem based on the configuration
     if (self::$fsSetup) {
         //setting up the filesystem twice can only lead to trouble
         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) {
         OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => $CONFIG_DATADIRECTORY), '/');
         self::$rootMounted = true;
     }
     if ($user != "") {
         //if we aren't logged in, there is no use to set up the filesystem
         $user_dir = '/' . $user . '/files';
         $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);
         // Load personal mount config
         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);
                 }
             }
             $mtime = filemtime($user_root . '/mount.php');
             $previousMTime = OC_Preferences::getValue($user, 'files', 'mountconfigmtime', 0);
             if ($mtime > $previousMTime) {
                 //mount config has changed, filecache needs to be updated
                 OC_FileCache::triggerUpdate($user);
                 OC_Preferences::setValue($user, 'files', 'mountconfigmtime', $mtime);
             }
         }
         OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $user_dir));
     }
 }
Ejemplo n.º 2
0
 public static function setupFS($user = "", $root = "files")
 {
     // configure the initial filesystem based on the configuration
     if (self::$fsSetup) {
         //setting up the filesystem twice can only lead to trouble
         return false;
     }
     $CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
     $CONFIG_BACKUPDIRECTORY = OC_Config::getValue("backupdirectory", OC::$SERVERROOT . "/backup");
     // Check if config folder is writable.
     if (!is_writable(OC::$SERVERROOT . "/config/")) {
         $tmpl = new OC_Template('', 'error', 'guest');
         $tmpl->assign('errors', array(1 => array('error' => "Can't write into config directory 'config'", 'hint' => "You can usually fix this by giving the webserver user write access to the config directory in owncloud")));
         $tmpl->printPage();
         exit;
     }
     // Check if apps folder is writable.
     if (!is_writable(OC::$SERVERROOT . "/apps/")) {
         $tmpl = new OC_Template('', 'error', 'guest');
         $tmpl->assign('errors', array(1 => array('error' => "Can't write into apps directory 'apps'", 'hint' => "You can usually fix this by giving the webserver user write access to the config directory in owncloud")));
         $tmpl->printPage();
         exit;
     }
     // Create root dir.
     if (!is_dir($CONFIG_DATADIRECTORY_ROOT)) {
         $success = @mkdir($CONFIG_DATADIRECTORY_ROOT);
         if (!$success) {
             $tmpl = new OC_Template('', 'error', 'guest');
             $tmpl->assign('errors', array(1 => array('error' => "Can't create data directory (" . $CONFIG_DATADIRECTORY_ROOT . ")", 'hint' => "You can usually fix this by giving the webserver write access to the ownCloud directory '" . OC::$SERVERROOT . "' (in a terminal, use the command 'chown -R www-data:www-data /path/to/your/owncloud/install/data' ")));
             $tmpl->printPage();
             exit;
         }
     }
     // 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();
     }
     //first set up the local "root" storage
     if (!self::$rootMounted) {
         OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => $CONFIG_DATADIRECTORY_ROOT), '/');
         self::$rootMounted = true;
     }
     if ($user != "") {
         //if we aren't logged in, there is no use to set up the filesystem
         OC::$CONFIG_DATADIRECTORY = $CONFIG_DATADIRECTORY_ROOT . "/{$user}/{$root}";
         if (!is_dir(OC::$CONFIG_DATADIRECTORY)) {
             mkdir(OC::$CONFIG_DATADIRECTORY, 0755, true);
         }
         //jail the user into his "home" directory
         OC_Filesystem::init('/' . $user . '/' . $root);
         $quotaProxy = new OC_FileProxy_Quota();
         OC_FileProxy::register($quotaProxy);
         self::$fsSetup = true;
     }
 }
Ejemplo n.º 3
0
 public function setUp()
 {
     //set testing key
     $_SESSION['enckey'] = md5(time());
     //clear all proxies and hooks so we can do clean testing
     OC_FileProxy::clearProxies();
     OC_Hook::clear('OC_Filesystem');
     //enable only the encryption hook
     OC_FileProxy::register(new OC_FileProxy_Encryption());
     //set up temporary storage
     OC_Filesystem::clearMounts();
     OC_Filesystem::mount('OC_Filestorage_Temporary', array(), '/');
     //set up the users home folder in the temp storage
     $rootView = new OC_FilesystemView('');
     $rootView->mkdir('/' . OC_User::getUser());
     $rootView->mkdir('/' . OC_User::getUser() . '/files');
 }
Ejemplo n.º 4
0
 public function setUp()
 {
     $this->oldConfig = OCP\Config::getAppValue('files_encryption', 'enable_encryption', 'true');
     OCP\Config::setAppValue('files_encryption', 'enable_encryption', 'true');
     $this->oldKey = isset($_SESSION['enckey']) ? $_SESSION['enckey'] : null;
     //set testing key
     $_SESSION['enckey'] = md5(time());
     //clear all proxies and hooks so we can do clean testing
     OC_FileProxy::clearProxies();
     OC_Hook::clear('OC_Filesystem');
     //enable only the encryption hook
     OC_FileProxy::register(new OC_FileProxy_Encryption());
     //set up temporary storage
     OC_Filesystem::clearMounts();
     OC_Filesystem::mount('OC_Filestorage_Temporary', array(), '/');
     //set up the users home folder in the temp storage
     $rootView = new OC_FilesystemView('');
     $rootView->mkdir('/' . OC_User::getUser());
     $rootView->mkdir('/' . OC_User::getUser() . '/files');
 }
Ejemplo n.º 5
0
 public static function loadUserMountPoints($user)
 {
     $user_dir = '/' . $user . '/files';
     $user_root = OC_User::getHome($user);
     $userdirectory = $user_root . '/files';
     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);
             }
         }
         $mtime = filemtime($user_root . '/mount.php');
         $previousMTime = OC_Preferences::getValue($user, 'files', 'mountconfigmtime', 0);
         if ($mtime > $previousMTime) {
             //mount config has changed, filecache needs to be updated
             OC_FileCache::triggerUpdate($user);
             OC_Preferences::setValue($user, 'files', 'mountconfigmtime', $mtime);
         }
     }
 }
Ejemplo n.º 6
0
 public function setUp()
 {
     //clear all proxies and hooks so we can do clean testing
     OC_FileProxy::clearProxies();
     OC_Hook::clear('OC_Filesystem');
     //enable only the encryption hook if needed
     if (OC_App::isEnabled('files_encryption')) {
         OC_FileProxy::register(new OC_FileProxy_Encryption());
     }
     //set up temporary storage
     OC_Filesystem::clearMounts();
     OC_Filesystem::mount('OC_Filestorage_Temporary', array(), '/');
     OC_User::clearBackends();
     OC_User::useBackend(new OC_User_Dummy());
     //login
     OC_User::createUser('test', 'test');
     $this->user = OC_User::getUser();
     OC_User::setUserId('test');
     //set up the users dir
     $rootView = new OC_FilesystemView('');
     $rootView->mkdir('/test');
     $this->instance = new OC_Cache_File();
 }
Ejemplo n.º 7
0
 public static function setup($options)
 {
     $user_dir = $options['user_dir'];
     OC_Filesystem::mount('OC_Filestorage_Shared', array('sharedFolder' => '/Shared'), $user_dir . '/Shared/');
 }
 public static function setupFS($user = "", $root = "files")
 {
     // configure the initial filesystem based on the configuration
     if (self::$fsSetup) {
         //setting up the filesystem twice can only lead to trouble
         return false;
     }
     $CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
     $CONFIG_BACKUPDIRECTORY = OC_Config::getValue("backupdirectory", OC::$SERVERROOT . "/backup");
     // Create root dir
     if (!is_dir($CONFIG_DATADIRECTORY_ROOT)) {
         $success = @mkdir($CONFIG_DATADIRECTORY_ROOT);
         if (!$success) {
             $tmpl = new OC_Template('', 'error', 'guest');
             $tmpl->assign('errors', array(1 => array('error' => "Can't create data directory (" . $CONFIG_DATADIRECTORY_ROOT . ")", 'hint' => "You can usually fix this by setting the owner of '" . OC::$SERVERROOT . "' to the user that the web server uses (" . OC_Util::checkWebserverUser() . ")")));
             $tmpl->printPage();
             exit;
         }
     }
     // 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
         //first set up the local "root" storage and the backupstorage if needed
         $rootStorage = OC_Filesystem::createStorage('local', array('datadir' => $CONFIG_DATADIRECTORY_ROOT));
         // 			if( OC_Config::getValue( "enablebackup", false )){
         // 				// This creates the Directorys recursively
         // 				if(!is_dir( "$CONFIG_BACKUPDIRECTORY/$user/$root" )){
         // 					mkdir( "$CONFIG_BACKUPDIRECTORY/$user/$root", 0755, true );
         // 				}
         // 				$backupStorage=OC_Filesystem::createStorage('local',array('datadir'=>$CONFIG_BACKUPDIRECTORY));
         // 				$backup=new OC_FILEOBSERVER_BACKUP(array('storage'=>$backupStorage));
         // 				$rootStorage->addObserver($backup);
         // 			}
         OC_Filesystem::mount($rootStorage, '/');
         // TODO add this storage provider in a proper way
         $sharedStorage = OC_Filesystem::createStorage('shared', array('datadir' => '/' . OC_User::getUser() . '/files/Shared'));
         OC_Filesystem::mount($sharedStorage, '/' . OC_User::getUser() . '/files/Shared/');
         OC::$CONFIG_DATADIRECTORY = $CONFIG_DATADIRECTORY_ROOT . "/{$user}/{$root}";
         if (!is_dir(OC::$CONFIG_DATADIRECTORY)) {
             mkdir(OC::$CONFIG_DATADIRECTORY, 0755, true);
         }
         // TODO: find a cool way for doing this
         // 			//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("/{$user}/{$root}");
         $quotaProxy = new OC_FileProxy_Quota();
         OC_FileProxy::register($quotaProxy);
         self::$fsSetup = true;
     }
 }
Ejemplo n.º 9
0
 public function testHooks()
 {
     if (OC_Filesystem::getView()) {
         $user = OC_User::getUser();
     } else {
         $user = uniqid();
         OC_Filesystem::init('/' . $user . '/files');
     }
     OC_Hook::clear('OC_Filesystem');
     OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
     OC_Filesystem::mount('OC_Filestorage_Temporary', array(), '/');
     $rootView = new OC_FilesystemView('');
     $rootView->mkdir('/' . $user);
     $rootView->mkdir('/' . $user . '/files');
     OC_Filesystem::file_put_contents('/foo', 'foo');
     OC_Filesystem::mkdir('/bar');
     OC_Filesystem::file_put_contents('/bar//foo', 'foo');
     $tmpFile = OC_Helper::tmpFile();
     file_put_contents($tmpFile, 'foo');
     $fh = fopen($tmpFile, 'r');
     OC_Filesystem::file_put_contents('/bar//foo', $fh);
 }
Ejemplo n.º 10
0
 /**
  * automount paths from file hooks
  * @param aray params
  */
 public static function autoMount($params)
 {
     if (!self::$enableAutomount) {
         return;
     }
     $path = $params['path'];
     if (!self::$rootView) {
         self::$rootView = new OC_FilesystemView('');
     }
     self::$enableAutomount = false;
     //prevent recursion
     $supported = array('zip', 'tar.gz', 'tar.bz2', 'tgz');
     foreach ($supported as $type) {
         $ext = '.' . $type . '/';
         if (($pos = strpos(strtolower($path), $ext)) !== false) {
             $archive = substr($path, 0, $pos + strlen($ext) - 1);
             if (self::$rootView->file_exists($archive) and array_search($archive, self::$mounted) === false) {
                 $localArchive = self::$rootView->getLocalFile($archive);
                 OC_Filesystem::mount('OC_Filestorage_Archive', array('archive' => $localArchive), $archive . '/');
                 self::$mounted[] = $archive;
             }
         }
     }
     self::$enableAutomount = true;
 }
 public static function setup()
 {
     OC_Filesystem::mount('OC_Filestorage_Shared', array('datadir' => '/' . OCP\USER::getUser() . '/files/Shared'), '/' . OCP\USER::getUser() . '/files/Shared/');
 }