Ejemplo n.º 1
0
 /**
  * Returns the mount points visible for this user.
  *
  * @param array $params
  * @return \OC_OCS_Result share information
  */
 public static function getUserMounts($params)
 {
     $entries = array();
     $user = \OC_User::getUser();
     $mounts = \OC_Mount_Config::getAbsoluteMountPoints($user);
     foreach ($mounts as $mountPoint => $mount) {
         $entries[] = self::formatMount($mountPoint, $mount);
     }
     return new \OC_OCS_Result($entries);
 }
Ejemplo n.º 2
0
 /**
  * Intercepts the user credentials on login and stores them
  * encrypted inside the session if SMB_OC storage is enabled.
  * @param array $params
  */
 public static function login($params)
 {
     $mountpoints = \OC_Mount_Config::getAbsoluteMountPoints($params['uid']);
     $mountpointClasses = array();
     foreach ($mountpoints as $mountpoint) {
         $mountpointClasses[$mountpoint['class']] = true;
     }
     if (isset($mountpointClasses['\\OC\\Files\\Storage\\SMB_OC'])) {
         \OC::$server->getSession()->set('smb-credentials', \OC::$server->getCrypto()->encrypt(json_encode($params)));
     }
 }
Ejemplo n.º 3
0
 /**
  * Get all mountpoints applicable for the user
  *
  * @param \OCP\IUser $user
  * @param \OCP\Files\Storage\IStorageFactory $loader
  * @return \OCP\Files\Mount\IMountPoint[]
  */
 public function getMountsForUser(IUser $user, IStorageFactory $loader)
 {
     $mountPoints = \OC_Mount_Config::getAbsoluteMountPoints($user->getUID());
     $mounts = array();
     foreach ($mountPoints as $mountPoint => $options) {
         if (isset($options['options']['objectstore'])) {
             $objectClass = $options['options']['objectstore']['class'];
             $options['options']['objectstore'] = new $objectClass($options['options']['objectstore']);
         }
         $mountOptions = isset($options['mountOptions']) ? $options['mountOptions'] : [];
         if (isset($options['personal']) && $options['personal']) {
             $mounts[] = new PersonalMount($options['class'], $mountPoint, $options['options'], $loader, $mountOptions);
         } else {
             $mounts[] = new MountPoint($options['class'], $mountPoint, $options['options'], $loader, $mountOptions);
         }
     }
     return $mounts;
 }
Ejemplo n.º 4
0
 /**
  * saves mount configuration
  */
 private function saveConfig()
 {
     // we read all mountpoints
     $mountPoints = \OC_Mount_Config::getAbsoluteMountPoints(\OCP\User::getUser());
     // we use the refresh token as unique ID
     $new_refresh_token = json_decode($this->params['hubic_token'], TRUE)['refresh_token'];
     foreach ($mountPoints as $mountPoint => $options) {
         if ($options['class'] == '\\OC\\Files\\Storage\\Hubic' && json_decode($options['options']['hubic_token'], TRUE)['refresh_token'] == $new_refresh_token) {
             $shortMountPoint = end(explode('/', $mountPoint, 4));
             if ($options['personal']) {
                 $mountType = \OC_Mount_Config::MOUNT_TYPE_USER;
                 $applicable = \OCP\User::getUser();
             } else {
                 $mountType = $options['priority_type'];
                 $applicable = $options['applicable'];
             }
             \OC_Mount_Config::addMountPoint($shortMountPoint, $options['class'], $this->params, $mountType, $applicable, $options['personal'], $options['priority']);
             break;
         }
     }
 }
Ejemplo n.º 5
0
 public function testMultiUserPersonalConfigLoading()
 {
     $mountConfig = array('host' => 'somehost', 'user' => 'someuser', 'password' => 'somepassword', 'root' => 'someroot');
     // Create personal mount point
     $this->assertTrue(OC_Mount_Config::addMountPoint('/ext', '\\OC\\Files\\Storage\\SMB', $mountConfig, OC_Mount_Config::MOUNT_TYPE_USER, self::TEST_USER1, true));
     // Ensure other user can read mount points
     \OC_User::setUserId(self::TEST_USER2);
     $mountPointsMe = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER2);
     $mountPointsOther = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER1);
     $this->assertEquals(0, count($mountPointsMe));
     $this->assertEquals(1, count($mountPointsOther));
     $this->assertTrue(isset($mountPointsOther['/' . self::TEST_USER1 . '/files/ext']));
     $this->assertEquals('\\OC\\Files\\Storage\\SMB', $mountPointsOther['/' . self::TEST_USER1 . '/files/ext']['class']);
     $this->assertEquals($mountConfig, $mountPointsOther['/' . self::TEST_USER1 . '/files/ext']['options']);
 }
Ejemplo n.º 6
0
 }
 //组合获取的mimetype的ID
 $mimetypesid = "";
 foreach ($mimetypesrow as $val) {
     $mimetypesid = $mimetypesid . $val['id'] . ',';
 }
 $mimetypesid = substr($mimetypesid, 0, strrpos($mimetypesid, ','));
 try {
     //查询当前数据库中当前用的的本地存储信息
     $queryDelFast = \OC_DB::prepare('SELECT * FROM `*PREFIX*storages` WHERE `id` = ?');
     $result = $queryDelFast->execute(array("home::" . $_SESSION['user_id']));
     $row = $result->fetchRow();
     $stoarr[] = $row['numeric_id'];
     $locastorage = $row['numeric_id'];
     //查询出当前用户的mount信息
     $mounts = OC_Mount_Config::getAbsoluteMountPoints($_SESSION['user_id']);
     //将mount信息中的storage_id变为数组
     foreach ($mounts as $key => $val) {
         $stoarr[] = $val['storage_id'];
     }
     $storagestr = implode(',', $stoarr);
     //组合where条件
     $where = 'WHERE path NOT LIKE "%thumbnails%" AND storage IN (' . $storagestr . ') AND mimetype IN (' . $mimetypesid . ')';
     $queryAllFiles = \OC_DB::prepare('SELECT * FROM `*PREFIX*filecache`  ' . $where . ' order by  ' . $order);
     $result = $queryAllFiles->execute();
     $row = $result->fetchAll();
 } catch (\Exception $e) {
     \OCP\Util::writeLog('filefilter', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
     return false;
 }
 $files = $row;
Ejemplo n.º 7
0
 /**
  * Test mount points used at mount time, making sure
  * the configuration is prepared properly.
  *
  * @dataProvider mountDataProvider
  * @param bool $isPersonal true for personal mount point, false for system mount point
  * @param string $mountType mount type
  * @param string $applicable target user/group or "all"
  * @param string $testUser user for which to retrieve the mount points
  * @param bool $expectVisible whether to expect the mount point to be visible for $testUser
  */
 public function testMount($isPersonal, $mountType, $applicable, $testUser, $expectVisible)
 {
     $mountConfig = array('host' => 'someost', 'user' => 'someuser', 'password' => 'somepassword', 'root' => 'someroot');
     // add mount point as "test" user
     $this->assertTrue(OC_Mount_Config::addMountPoint('/ext', '\\OC\\Files\\Storage\\SMB', $mountConfig, $mountType, $applicable, $isPersonal));
     // check mount points in the perspective of user $testUser
     \OC_User::setUserId($testUser);
     $mountPoints = OC_Mount_Config::getAbsoluteMountPoints($testUser);
     if ($expectVisible) {
         $this->assertEquals(1, count($mountPoints));
         $this->assertTrue(isset($mountPoints['/' . self::TEST_USER1 . '/files/ext']));
         $this->assertEquals('\\OC\\Files\\Storage\\SMB', $mountPoints['/' . self::TEST_USER1 . '/files/ext']['class']);
         $this->assertEquals($mountConfig, $mountPoints['/' . self::TEST_USER1 . '/files/ext']['options']);
     } else {
         $this->assertEquals(0, count($mountPoints));
     }
 }
Ejemplo n.º 8
0
 /**
  * Test for persistence of priority when changing mount options
  */
 public function testPriorityPersistence()
 {
     $class = '\\OC\\Files\\Storage\\SMB';
     $priority = 123;
     $mountConfig = array('host' => 'somehost', 'user' => 'someuser', 'password' => 'somepassword', 'root' => 'someroot');
     $this->assertTrue(OC_Mount_Config::addMountPoint('/ext', $class, $mountConfig, OC_Mount_Config::MOUNT_TYPE_USER, self::TEST_USER1, false, $priority));
     // Check for correct priority
     $mountPoints = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER1);
     $this->assertEquals($priority, $mountPoints['/' . self::TEST_USER1 . '/files/ext']['priority']);
     // Simulate changed mount options (without priority set)
     $this->assertTrue(OC_Mount_Config::addMountPoint('/ext', $class, $mountConfig, OC_Mount_Config::MOUNT_TYPE_USER, self::TEST_USER1, false));
     // Check for correct priority
     $mountPoints = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER1);
     $this->assertEquals($priority, $mountPoints['/' . self::TEST_USER1 . '/files/ext']['priority']);
 }