예제 #1
0
 public function setUp()
 {
     // remember files_encryption state
     $this->stateFilesEncryption = \OC_App::isEnabled('files_encryption');
     // we want to tests with the encryption app disabled
     \OC_App::disable('files_encryption');
     $this->storage = new \OC\Files\Storage\Temporary(array());
     $textData = "dummy file data\n";
     $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
     $this->storage->mkdir('folder');
     $this->storage->file_put_contents('foo.txt', $textData);
     $this->storage->file_put_contents('foo.png', $imgData);
     $this->storage->file_put_contents('folder/bar.txt', $textData);
     $this->storage->file_put_contents('folder/bar2.txt', $textData);
     $this->scanner = $this->storage->getScanner();
     $this->scanner->scan('');
     $this->cache = $this->storage->getCache();
     \OC\Files\Filesystem::tearDown();
     if (!self::$user) {
         self::$user = uniqid();
     }
     \OC_User::createUser(self::$user, 'password');
     \OC_User::setUserId(self::$user);
     \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files');
     Filesystem::clearMounts();
     Filesystem::mount($this->storage, array(), '/' . self::$user . '/files');
     \OC_Hook::clear('OC_Filesystem');
 }
예제 #2
0
	protected function setUp() {
		parent::setUp();

		$this->storage = new \OC\Files\Storage\Temporary(array());
		$textData = "dummy file data\n";
		$imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
		$this->storage->mkdir('folder');
		$this->storage->file_put_contents('foo.txt', $textData);
		$this->storage->file_put_contents('foo.png', $imgData);
		$this->storage->file_put_contents('folder/bar.txt', $textData);
		$this->storage->file_put_contents('folder/bar2.txt', $textData);

		$this->scanner = $this->storage->getScanner();
		$this->scanner->scan('');
		$this->cache = $this->storage->getCache();

		if (!self::$user) {
			self::$user = $this->getUniqueID();
		}

		\OC_User::createUser(self::$user, 'password');
		$this->loginAsUser(self::$user);

		Filesystem::init(self::$user, '/' . self::$user . '/files');

		Filesystem::clearMounts();
		Filesystem::mount($this->storage, array(), '/' . self::$user . '/files');

		\OC_Hook::clear('OC_Filesystem');
	}
예제 #3
0
 /**
  * @brief Can be set up
  * @param string $user
  * @return boolean
  * @description configure the initial filesystem based on the configuration
  */
 public static function setupFS($user = '')
 {
     //setting up the filesystem twice can only lead to trouble
     if (self::$fsSetup) {
         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();
     }
     // load all filesystem apps before, so no setup-hook gets lost
     if (!isset($RUNTIME_NOAPPS) || !$RUNTIME_NOAPPS) {
         OC_App::loadApps(array('filesystem'));
     }
     // 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;
     }
     $configDataDirectory = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
     //first set up the local "root" storage
     \OC\Files\Filesystem::initMounts();
     if (!self::$rootMounted) {
         \OC\Files\Filesystem::mount('\\OC\\Files\\Storage\\Local', array('datadir' => $configDataDirectory), '/');
         self::$rootMounted = true;
     }
     //if we aren't logged in, there is no use to set up the filesystem
     if ($user != "") {
         \OC\Files\Filesystem::addStorageWrapper(function ($mountPoint, $storage) {
             // set up quota for home storages, even for other users
             // which can happen when using sharing
             if ($storage instanceof \OC\Files\Storage\Home) {
                 $user = $storage->getUser()->getUID();
                 $quota = OC_Util::getUserQuota($user);
                 if ($quota !== \OC\Files\SPACE_UNLIMITED) {
                     return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota));
                 }
             }
             return $storage;
         });
         $userDir = '/' . $user . '/files';
         $userRoot = OC_User::getHome($user);
         $userDirectory = $userRoot . '/files';
         if (!is_dir($userDirectory)) {
             mkdir($userDirectory, 0755, true);
             OC_Util::copySkeleton($userDirectory);
         }
         //jail the user into his "home" directory
         \OC\Files\Filesystem::init($user, $userDir);
         $fileOperationProxy = new OC_FileProxy_FileOperations();
         OC_FileProxy::register($fileOperationProxy);
         OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir));
     }
     return true;
 }
예제 #4
0
 public function setUp()
 {
     $this->user = '******' . uniqid();
     \OC_User::createUser($this->user, $this->user);
     \OC\Files\Filesystem::tearDown();
     \OC_User::setUserId($this->user);
     \OC\Files\Filesystem::init($this->user, '/' . $this->user . '/files');
     \OC\Files\Filesystem::clearMounts();
     $this->storageMock = null;
 }
예제 #5
0
 protected function setUp()
 {
     parent::setUp();
     $this->user = $this->getUniqueID('user_');
     \OC::$server->getUserManager()->createUser($this->user, $this->user);
     $this->storage = \OC\Files\Filesystem::getStorage('/');
     \OC\Files\Filesystem::tearDown();
     \OC_User::setUserId($this->user);
     \OC\Files\Filesystem::init($this->user, '/' . $this->user . '/files');
     \OC\Files\Filesystem::clearMounts();
     $this->storageMock = null;
 }
예제 #6
0
 protected function setUp()
 {
     parent::setUp();
     $this->originalStorage = \OC\Files\Filesystem::getStorage('/');
     // create a new user with his own filesystem view
     // this gets called by each test in this test class
     $this->user = $this->getUniqueID();
     \OC_User::setUserId($this->user);
     \OC\Files\Filesystem::init($this->user, '/' . $this->user . '/files');
     \OC\Files\Filesystem::mount('OC\\Files\\Storage\\Temporary', array(), '/');
     $this->rootView = new \OC\Files\View('');
     $this->rootView->mkdir('/' . $this->user);
     $this->rootView->mkdir('/' . $this->user . '/files');
 }
예제 #7
0
 public function setUp()
 {
     parent::setUp();
     \OC_User::clearBackends();
     \OC_User::useBackend(new \OC_User_Dummy());
     \OC\Files\Filesystem::clearMounts();
     //login
     \OC_User::createUser('test', 'test');
     \OC::$server->getSession()->set('user_id', 'test');
     $this->storage = new \OC\Files\Storage\Temporary(array());
     \OC\Files\Filesystem::init('test', '');
     \OC\Files\Filesystem::clearMounts();
     \OC\Files\Filesystem::mount($this->storage, array(), '/');
     \OC\Files\Filesystem::file_put_contents('file1', self::CONTENT);
     $this->config->method('getAvChunkSize')->willReturn('1024');
 }
예제 #8
0
 function setUp()
 {
     // mock OC_L10n
     if (!self::$user) {
         self::$user = uniqid();
     }
     \OC_User::createUser(self::$user, 'password');
     \OC_User::setUserId(self::$user);
     \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files');
     $l10nMock = $this->getMock('\\OC_L10N', array('t'), array(), '', false);
     $l10nMock->expects($this->any())->method('t')->will($this->returnArgument(0));
     $viewMock = $this->getMock('\\OC\\Files\\View', array('rename', 'normalizePath', 'getFileInfo', 'file_exists'), array(), '', false);
     $viewMock->expects($this->any())->method('normalizePath')->will($this->returnArgument(0));
     $viewMock->expects($this->any())->method('rename')->will($this->returnValue(true));
     $this->viewMock = $viewMock;
     $this->files = new \OCA\Files\App($viewMock, $l10nMock);
 }
예제 #9
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();
     }
     // load all filesystem apps before, so no setup-hook gets lost
     if (!isset($RUNTIME_NOAPPS) || !$RUNTIME_NOAPPS) {
         OC_App::loadApps(array('filesystem'));
     }
     // 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\Files\Filesystem::mount('\\OC\\Files\\Storage\\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\Files\Filesystem::init($user, $user_dir);
         $quotaProxy = new OC_FileProxy_Quota();
         $fileOperationProxy = new OC_FileProxy_FileOperations();
         OC_FileProxy::register($quotaProxy);
         OC_FileProxy::register($fileOperationProxy);
         OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $user_dir));
     }
     return true;
 }
예제 #10
0
 protected function setUp()
 {
     parent::setUp();
     // FIXME: use proper tearDown with $this->loginAsUser() and $this->logout()
     // (would currently break the tests for some reason)
     $this->originalStorage = \OC\Files\Filesystem::getStorage('/');
     // create a new user with his own filesystem view
     // this gets called by each test in this test class
     $backend = new \OC_User_Dummy();
     \OC_User::useBackend($backend);
     $backend->createUser(self::TEST_PREVIEW_USER1, self::TEST_PREVIEW_USER1);
     $user = \OC::$server->getUserManager()->get(self::TEST_PREVIEW_USER1);
     \OC::$server->getUserSession()->setUser($user);
     \OC\Files\Filesystem::init(self::TEST_PREVIEW_USER1, '/' . self::TEST_PREVIEW_USER1 . '/files');
     \OC\Files\Filesystem::mount('OC\\Files\\Storage\\Temporary', array(), '/');
     $this->rootView = new \OC\Files\View('');
     $this->rootView->mkdir('/' . self::TEST_PREVIEW_USER1);
     $this->rootView->mkdir('/' . self::TEST_PREVIEW_USER1 . '/files');
 }
예제 #11
0
 public function setUp()
 {
     \OC\Files\Filesystem::init('', '');
     \OC\Files\Filesystem::clearMounts();
     $manager = \OC\Files\Filesystem::getMountManager();
     \OC_Hook::clear('OC_Filesystem');
     \OC_Hook::connect('OC_Filesystem', 'post_write', '\\OC\\Files\\Cache\\Updater', 'writeHook');
     \OC_Hook::connect('OC_Filesystem', 'post_delete', '\\OC\\Files\\Cache\\Updater', 'deleteHook');
     \OC_Hook::connect('OC_Filesystem', 'post_rename', '\\OC\\Files\\Cache\\Updater', 'renameHook');
     \OC_Hook::connect('OC_Filesystem', 'post_touch', '\\OC\\Files\\Cache\\Updater', 'touchHook');
     $user = new User(uniqid('user'), new \OC_User_Dummy());
     \OC_User::setUserId($user->getUID());
     $this->view = new View();
     $this->root = new Root($manager, $this->view, $user);
     $storage = new Temporary(array());
     $subStorage = new Temporary(array());
     $this->storages[] = $storage;
     $this->storages[] = $subStorage;
     $this->root->mount($storage, '/');
     $this->root->mount($subStorage, '/substorage/');
 }
예제 #12
0
 public function testHooks()
 {
     if (\OC\Files\Filesystem::getView()) {
         $user = \OC_User::getUser();
     } else {
         $user = $this->getUniqueID();
         \OC\Files\Filesystem::init($user, '/' . $user . '/files');
     }
     \OC_Hook::clear('OC_Filesystem');
     \OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
     \OC\Files\Filesystem::mount('OC\\Files\\Storage\\Temporary', array(), '/');
     $rootView = new \OC\Files\View('');
     $rootView->mkdir('/' . $user);
     $rootView->mkdir('/' . $user . '/files');
     //		\OC\Files\Filesystem::file_put_contents('/foo', 'foo');
     \OC\Files\Filesystem::mkdir('/bar');
     //		\OC\Files\Filesystem::file_put_contents('/bar//foo', 'foo');
     $tmpFile = \OC_Helper::tmpFile();
     file_put_contents($tmpFile, 'foo');
     $fh = fopen($tmpFile, 'r');
     //		\OC\Files\Filesystem::file_put_contents('/bar//foo', $fh);
 }
예제 #13
0
파일: util.php 프로젝트: pinoniq/core
 /**
  * Can be set up
  *
  * @param string $user
  * @return boolean
  * @description configure the initial filesystem based on the configuration
  */
 public static function setupFS($user = '')
 {
     //setting up the filesystem twice can only lead to trouble
     if (self::$fsSetup) {
         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();
     }
     // load all filesystem apps before, so no setup-hook gets lost
     OC_App::loadApps(array('filesystem'));
     // 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;
     }
     //check if we are using an object storage
     $objectStore = OC_Config::getValue('objectstore');
     if (isset($objectStore)) {
         self::initObjectStoreRootFS($objectStore);
     } else {
         self::initLocalStorageRootFS();
     }
     if ($user != '' && !OCP\User::userExists($user)) {
         return false;
     }
     //if we aren't logged in, there is no use to set up the filesystem
     if ($user != "") {
         \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) {
             // set up quota for home storages, even for other users
             // which can happen when using sharing
             /**
              * @var \OC\Files\Storage\Storage $storage
              */
             if ($storage->instanceOfStorage('\\OC\\Files\\Storage\\Home') || $storage->instanceOfStorage('\\OC\\Files\\ObjectStore\\HomeObjectStoreStorage')) {
                 if (is_object($storage->getUser())) {
                     $user = $storage->getUser()->getUID();
                     $quota = OC_Util::getUserQuota($user);
                     if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
                         return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files'));
                     }
                 }
             }
             return $storage;
         });
         // copy skeleton for local storage only
         if (!isset($objectStore)) {
             $userRoot = OC_User::getHome($user);
             $userDirectory = $userRoot . '/files';
             if (!is_dir($userDirectory)) {
                 mkdir($userDirectory, 0755, true);
                 OC_Util::copySkeleton($userDirectory);
             }
         }
         $userDir = '/' . $user . '/files';
         //jail the user into his "home" directory
         \OC\Files\Filesystem::init($user, $userDir);
         $fileOperationProxy = new OC_FileProxy_FileOperations();
         OC_FileProxy::register($fileOperationProxy);
         OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir));
     }
     return true;
 }
예제 #14
0
파일: hooks.php 프로젝트: AARNet/user_saml
 public static function post_login($parameters)
 {
     // Do nothing if we're sharding and not on the master
     if (OCP\App::isEnabled('files_sharding') && !OCA\FilesSharding\Lib::isMaster()) {
         return true;
     }
     $uid = '';
     $userid = $parameters['uid'];
     $samlBackend = new OC_USER_SAML();
     $ocUserDatabase = new OC_User_Database();
     // Redirect regardless of whether the user has authenticated with SAML or not.
     // Since this is a post_login hook, he will have authenticated in some way and have a valid session.
     if ($ocUserDatabase->userExists($userid)) {
         // Set user attributes for sharding
         $display_name = \OCP\User::getDisplayName($userid);
         $email = \OCP\Config::getUserValue($userid, 'settings', 'email');
         $groups = \OC_Group::getUserGroups($userid);
         $quota = \OC_Preferences::getValue($userid, 'files', 'quota');
         OC_Util::teardownFS($userid);
         OC_Util::setupFS($userid);
         OC_Log::write('saml', 'Setting user attributes: ' . $userid . ":" . $display_name . ":" . $email . ":" . join($groups) . ":" . $quota, OC_Log::INFO);
         self::setAttributes($userid, $display_name, $email, $groups, $quota);
         self::user_redirect($userid);
     }
     if (!$samlBackend->auth->isAuthenticated()) {
         return false;
     }
     $attributes = $samlBackend->auth->getAttributes();
     //$email = "<pre>" . print_r($attributes, 1) . "</pre>";
     //$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
     //error_log($email, 1, '*****@*****.**', $headers);
     $usernameFound = false;
     foreach ($samlBackend->usernameMapping as $usernameMapping) {
         if (array_key_exists($usernameMapping, $attributes) && !empty($attributes[$usernameMapping][0])) {
             $usernameFound = true;
             $uid = $attributes[$usernameMapping][0];
             OC_Log::write('saml', 'Authenticated user ' . $uid, OC_Log::INFO);
             break;
         }
     }
     if (!$usernameFound || $uid !== $userid) {
         return false;
     }
     $attrs = self::get_user_attributes($uid, $samlBackend);
     if (!$ocUserDatabase->userExists($uid)) {
         // If autocreate is not enabled - back off
         if (!$samlBackend->autocreate) {
             return false;
         }
         // Apparently it is necessary to clear the uid first, to be able to create the user in the DB
         $userManager = \OC_User::getManager();
         $userManager->delete($uid);
         // Reject invalid user names
         if (preg_match('/[^a-zA-Z0-9 _\\.@\\-]/', $uid)) {
             OC_Log::write('saml', 'Invalid username "' . $uid . '", allowed chars "a-zA-Z0-9" and "_.@-" ', OC_Log::DEBUG);
             return false;
         }
         $cookiedomain = OCP\App::isEnabled('files_sharding') ? OCA\FilesSharding\Lib::getCookieDomain() : null;
         // Reject users we don't allow to autocreate an account
         if (isset($uid) && trim($uid) != '' && !OC_User::userExists($uid) && !self::check_user_attributes($attributes)) {
             $failCookieName = 'saml_auth_fail';
             $userCookieName = 'saml_auth_fail_user';
             $expire = 0;
             //time()+60*60*24*30;
             $expired = time() - 3600;
             $path = '/';
             setcookie($failCookieName, "notallowed:" . $uid, $expire, $path, $cookiedomain, false, false);
             setcookie($userCookieName, $uid, $expire, $path, $cookiedomain, false, false);
             $spSource = 'default-sp';
             $auth = new SimpleSAML_Auth_Simple($spSource);
             OC_Log::write('saml', 'Rejected user "' . $uid, OC_Log::ERROR);
             if (OCP\App::isEnabled('files_sharding') && !OCA\FilesSharding\Lib::isMaster()) {
                 $auth->logout(!OCA\FilesSharding\Lib::getMasterURL());
             } else {
                 $auth->logout();
             }
             return false;
         }
         // Create new user
         $random_password = OC_Util::generateRandomBytes(20);
         OC_Log::write('saml', 'Creating new user: '******'/' . $uid . '/files';
             \OC\Files\Filesystem::init($uid, $userDir);
             if ($samlBackend->updateUserData) {
                 self::update_user_data($uid, $samlBackend, $attrs, true);
                 if (OCP\App::isEnabled('files_sharding') && OCA\FilesSharding\Lib::isMaster()) {
                     $master_site = OCA\FilesSharding\Lib::dbGetSite(null);
                     $server_id = OCA\FilesSharding\Lib::dbChooseServerForUser($uid, $master_site, 0, null);
                     OC_Log::write('saml', 'Setting server for new user: '******'display_name'], $attrs['email'], $attrs['groups'], $attrs['quota']);
         }
     } else {
         if ($samlBackend->updateUserData) {
             self::update_user_data($uid, $samlBackend, $attrs, false);
         }
     }
     self::user_redirect($userid);
     return true;
 }
예제 #15
0
파일: preview.php 프로젝트: Romua1d/core
 private function initFS()
 {
     // create a new user with his own filesystem view
     // this gets called by each test in this test class
     $user = uniqid();
     \OC_User::setUserId($user);
     \OC\Files\Filesystem::init($user, '/' . $user . '/files');
     \OC\Files\Filesystem::mount('OC\\Files\\Storage\\Temporary', array(), '/');
     return $user;
 }
예제 #16
0
파일: util.php 프로젝트: reverserob/core
 /**
  * Can be set up
  *
  * @param string $user
  * @return boolean
  * @description configure the initial filesystem based on the configuration
  */
 public static function setupFS($user = '')
 {
     //setting up the filesystem twice can only lead to trouble
     if (self::$fsSetup) {
         return false;
     }
     \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem');
     // 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();
     }
     // load all filesystem apps before, so no setup-hook gets lost
     OC_App::loadApps(array('filesystem'));
     // 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;
     }
     \OC\Files\Filesystem::initMountManager();
     \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) {
         if ($storage->instanceOfStorage('\\OC\\Files\\Storage\\Common')) {
             /** @var \OC\Files\Storage\Common $storage */
             $storage->setMountOptions($mount->getOptions());
         }
         return $storage;
     });
     // install storage availability wrapper, before most other wrappers
     \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, $storage) {
         if (!$storage->isLocal()) {
             return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]);
         }
         return $storage;
     });
     \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) {
         // set up quota for home storages, even for other users
         // which can happen when using sharing
         /**
          * @var \OC\Files\Storage\Storage $storage
          */
         if ($storage->instanceOfStorage('\\OC\\Files\\Storage\\Home') || $storage->instanceOfStorage('\\OC\\Files\\ObjectStore\\HomeObjectStoreStorage')) {
             /** @var \OC\Files\Storage\Home $storage */
             if (is_object($storage->getUser())) {
                 $user = $storage->getUser()->getUID();
                 $quota = OC_Util::getUserQuota($user);
                 if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
                     return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files'));
                 }
             }
         }
         return $storage;
     });
     OC_Hook::emit('OC_Filesystem', 'preSetup', array('user' => $user));
     //check if we are using an object storage
     $objectStore = OC_Config::getValue('objectstore');
     if (isset($objectStore)) {
         self::initObjectStoreRootFS($objectStore);
     } else {
         self::initLocalStorageRootFS();
     }
     if ($user != '' && !OCP\User::userExists($user)) {
         \OC::$server->getEventLogger()->end('setup_fs');
         return false;
     }
     //if we aren't logged in, there is no use to set up the filesystem
     if ($user != "") {
         $userDir = '/' . $user . '/files';
         //jail the user into his "home" directory
         \OC\Files\Filesystem::init($user, $userDir);
         OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir));
     }
     \OC::$server->getEventLogger()->end('setup_fs');
     return true;
 }
예제 #17
0
 public function testHooks()
 {
     if (\OC\Files\Filesystem::getView()) {
         $user = \OC_User::getUser();
     } else {
         $user = self::TEST_FILESYSTEM_USER1;
         $backend = new \Test\Util\User\Dummy();
         \OC_User::useBackend($backend);
         $backend->createUser($user, $user);
         $userObj = \OC::$server->getUserManager()->get($user);
         \OC::$server->getUserSession()->setUser($userObj);
         \OC\Files\Filesystem::init($user, '/' . $user . '/files');
     }
     \OC_Hook::clear('OC_Filesystem');
     \OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
     \OC\Files\Filesystem::mount('OC\\Files\\Storage\\Temporary', array(), '/');
     $rootView = new \OC\Files\View('');
     $rootView->mkdir('/' . $user);
     $rootView->mkdir('/' . $user . '/files');
     //		\OC\Files\Filesystem::file_put_contents('/foo', 'foo');
     \OC\Files\Filesystem::mkdir('/bar');
     //		\OC\Files\Filesystem::file_put_contents('/bar//foo', 'foo');
     $tmpFile = \OC::$server->getTempManager()->getTemporaryFile();
     file_put_contents($tmpFile, 'foo');
     $fh = fopen($tmpFile, 'r');
     //		\OC\Files\Filesystem::file_put_contents('/bar//foo', $fh);
 }
예제 #18
0
 /**
  * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  */
 public static function init($user, $root)
 {
     return \OC\Files\Filesystem::init($user, $root);
 }
예제 #19
0
파일: add.php 프로젝트: BacLuc/newGryfiPage
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $uid = $input->getArgument('uid');
     if ($this->userManager->userExists($uid)) {
         $output->writeln('<error>The user "' . $uid . '" already exists.</error>');
         return 1;
     }
     if ($input->getOption('password-from-env')) {
         $password = getenv('OC_PASS');
         if (!$password) {
             $output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>');
             return 1;
         }
     } elseif ($input->isInteractive()) {
         /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */
         $dialog = $this->getHelperSet()->get('dialog');
         $password = $dialog->askHiddenResponse($output, '<question>Enter password: </question>', false);
         $confirm = $dialog->askHiddenResponse($output, '<question>Confirm password: </question>', false);
         if ($password !== $confirm) {
             $output->writeln("<error>Passwords did not match!</error>");
             return 1;
         }
     } else {
         $output->writeln("<error>Interactive input or --password-from-env is needed for entering a password!</error>");
         return 1;
     }
     $user = $this->userManager->createUser($input->getArgument('uid'), $password);
     if ($user instanceof IUser) {
         $output->writeln('<info>The user "' . $user->getUID() . '" was created successfully</info>');
     } else {
         $output->writeln('<error>An error occurred while creating the user</error>');
         return 1;
     }
     if ($input->getOption('display-name')) {
         $user->setDisplayName($input->getOption('display-name'));
         $output->writeln('Display name set to "' . $user->getDisplayName() . '"');
     }
     $groups = $input->getOption('group');
     if (!empty($groups)) {
         // Make sure we init the Filesystem for the user, in case we need to
         // init some group shares.
         Filesystem::init($user->getUID(), '');
     }
     foreach ($groups as $groupName) {
         $group = $this->groupManager->get($groupName);
         if (!$group) {
             $this->groupManager->createGroup($groupName);
             $group = $this->groupManager->get($groupName);
             $output->writeln('Created group "' . $group->getGID() . '"');
         }
         $group->addUser($user);
         $output->writeln('User "' . $user->getUID() . '" added to group "' . $group->getGID() . '"');
     }
 }