示例#1
0
 /**
  * Add a mount point to the filesystem
  * @param string Mount point
  * @param string Backend class
  * @param array Backend parameters for the class
  * @param string MOUNT_TYPE_GROUP | MOUNT_TYPE_USER
  * @param string User or group to apply mount to
  * @param bool Personal or system mount point i.e. is this being called from the personal or admin page
  * @return bool
  */
 public static function addMountPoint($mountPoint, $class, $classOptions, $mountType, $applicable, $isPersonal = false)
 {
     $backends = self::getBackends();
     $mountPoint = OC\Files\Filesystem::normalizePath($mountPoint);
     if ($mountPoint === '' || $mountPoint === '/' || $mountPoint == '/Shared') {
         // can't mount at root or "Shared" folder
         return false;
     }
     if (!isset($backends[$class])) {
         // invalid backend
         return false;
     }
     if ($isPersonal) {
         // Verify that the mount point applies for the current user
         // Prevent non-admin users from mounting local storage
         if ($applicable !== OCP\User::getUser() || strtolower($class) === '\\oc\\files\\storage\\local') {
             return false;
         }
         $mountPoint = '/' . $applicable . '/files/' . ltrim($mountPoint, '/');
     } else {
         $mountPoint = '/$user/files/' . ltrim($mountPoint, '/');
     }
     $mount = array($applicable => array($mountPoint => array('class' => $class, 'options' => self::encryptPasswords($classOptions))));
     $mountPoints = self::readData($isPersonal ? OCP\User::getUser() : NULL);
     // Merge the new mount point into the current mount points
     if (isset($mountPoints[$mountType])) {
         if (isset($mountPoints[$mountType][$applicable])) {
             $mountPoints[$mountType][$applicable] = array_merge($mountPoints[$mountType][$applicable], $mount[$applicable]);
         } else {
             $mountPoints[$mountType] = array_merge($mountPoints[$mountType], $mount);
         }
     } else {
         $mountPoints[$mountType] = $mount;
     }
     self::writeData($isPersonal ? OCP\User::getUser() : NULL, $mountPoints);
     return self::getBackendStatus($class, $classOptions);
 }
示例#2
0
文件: config.php 项目: Romua1d/core
 /**
  * Add a mount point to the filesystem
  * @param string $mountPoint Mount point
  * @param string $class Backend class
  * @param array $classOptions Backend parameters for the class
  * @param string $mountType MOUNT_TYPE_GROUP | MOUNT_TYPE_USER
  * @param string $applicable User or group to apply mount to
  * @param bool $isPersonal Personal or system mount point i.e. is this being called from the personal or admin page
  * @param int|null $priority Mount point priority, null for default
  * @return boolean
  */
 public static function addMountPoint($mountPoint, $class, $classOptions, $mountType, $applicable, $isPersonal = false, $priority = null)
 {
     $backends = self::getBackends();
     $mountPoint = OC\Files\Filesystem::normalizePath($mountPoint);
     $relMountPoint = $mountPoint;
     if ($mountPoint === '' || $mountPoint === '/') {
         // can't mount at root folder
         return false;
     }
     if (!isset($backends[$class])) {
         // invalid backend
         return false;
     }
     if ($isPersonal) {
         // Verify that the mount point applies for the current user
         // Prevent non-admin users from mounting local storage and other disabled backends
         $allowed_backends = self::getPersonalBackends();
         if ($applicable != OCP\User::getUser() || !isset($allowed_backends[$class])) {
             return false;
         }
         $mountPoint = '/' . $applicable . '/files/' . ltrim($mountPoint, '/');
     } else {
         $mountPoint = '/$user/files/' . ltrim($mountPoint, '/');
     }
     $mount = array($applicable => array($mountPoint => array('class' => $class, 'options' => self::encryptPasswords($classOptions))));
     if (!$isPersonal && !is_null($priority)) {
         $mount[$applicable][$mountPoint]['priority'] = $priority;
     }
     $mountPoints = self::readData($isPersonal ? OCP\User::getUser() : NULL);
     // who else loves multi-dimensional array ?
     $isNew = !isset($mountPoints[$mountType]) || !isset($mountPoints[$mountType][$applicable]) || !isset($mountPoints[$mountType][$applicable][$mountPoint]);
     $mountPoints = self::mergeMountPoints($mountPoints, $mount, $mountType);
     // Set default priority if none set
     if (!isset($mountPoints[$mountType][$applicable][$mountPoint]['priority'])) {
         if (isset($backends[$class]['priority'])) {
             $mountPoints[$mountType][$applicable][$mountPoint]['priority'] = $backends[$class]['priority'];
         } else {
             $mountPoints[$mountType][$applicable][$mountPoint]['priority'] = 100;
         }
     }
     self::writeData($isPersonal ? OCP\User::getUser() : NULL, $mountPoints);
     $result = self::getBackendStatus($class, $classOptions, $isPersonal);
     if ($result && $isNew) {
         \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_create_mount, array(\OC\Files\Filesystem::signal_param_path => $relMountPoint, \OC\Files\Filesystem::signal_param_mount_type => $mountType, \OC\Files\Filesystem::signal_param_users => $applicable));
     }
     return $result;
 }
示例#3
0
 /**
  * Add a mount point to the filesystem
  *
  * @param string $mountPoint Mount point
  * @param string $class Backend class
  * @param array $classOptions Backend parameters for the class
  * @param string $mountType MOUNT_TYPE_GROUP | MOUNT_TYPE_USER
  * @param string $applicable User or group to apply mount to
  * @param bool $isPersonal Personal or system mount point i.e. is this being called from the personal or admin page
  * @param int|null $priority Mount point priority, null for default
  * @return boolean
  */
 public static function addMountPoint($mountPoint, $class, $classOptions, $mountType, $applicable, $isPersonal = false, $priority = null)
 {
     $backends = self::getBackends();
     $mountPoint = OC\Files\Filesystem::normalizePath($mountPoint);
     $relMountPoint = $mountPoint;
     if ($mountPoint === '' || $mountPoint === '/') {
         // can't mount at root folder
         return false;
     }
     if (!isset($backends[$class])) {
         // invalid backend
         return false;
     }
     if ($isPersonal) {
         // Verify that the mount point applies for the current user
         // Prevent non-admin users from mounting local storage and other disabled backends
         $allowed_backends = self::getPersonalBackends();
         if ($applicable != OCP\User::getUser() || !isset($allowed_backends[$class])) {
             return false;
         }
         $mountPoint = '/' . $applicable . '/files/' . ltrim($mountPoint, '/');
     } else {
         $mountPoint = '/$user/files/' . ltrim($mountPoint, '/');
         //��moutPoint����Ҫ�����
     }
     //$mount数组,用于存到数据库
     $mount = array($applicable => array($mountPoint => array('class' => $class, 'options' => self::encryptPasswords($classOptions), 'priority' => 100)));
     //给$mount赋值storage_id
     self::addStorageId($mount[$applicable][$mountPoint]);
     //获取mount的数据库对象
     $mountdatabase = new \OC\Files\Mount\MountDatabase();
     $res = $mountdatabase->getMountPointByUserAndStorage($applicable, $mountPoint);
     //判断是否数据库已经存在,存在则返回true
     if (!empty($res)) {
         return '已经存在改数据!';
     } else {
         //不存在则添加后返回true
         $flag = $mountdatabase->insertMountPoint($mount);
         /*if (!$isPersonal && !is_null($priority)) {
                         $mount[$applicable][$mountPoint]['priority'] = $priority;
                     }
         
                     $mountPoints = self::readData($isPersonal ? OCP\User::getUser() : null);
                     // who else loves multi-dimensional array ?
                     $isNew = !isset($mountPoints[$mountType]) ||
                         !isset($mountPoints[$mountType][$applicable]) ||
                         !isset($mountPoints[$mountType][$applicable][$mountPoint]);
                     $mountPoints = self::mergeMountPoints($mountPoints, $mount, $mountType);
         
                     // Set default priority if none set
                     if (!isset($mountPoints[$mountType][$applicable][$mountPoint]['priority'])) {
                         if (isset($backends[$class]['priority'])) {
                             $mountPoints[$mountType][$applicable][$mountPoint]['priority']
                                 = $backends[$class]['priority'];
                         } else {
                             $mountPoints[$mountType][$applicable][$mountPoint]['priority']
                                 = 100;
                         }
                     }
         
                     self::writeData($isPersonal ? OCP\User::getUser() : null, $mountPoints);*/
         $result = self::getBackendStatus($class, $classOptions, $isPersonal);
         if ($result && $flag) {
             \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_create_mount, array(\OC\Files\Filesystem::signal_param_path => $relMountPoint, \OC\Files\Filesystem::signal_param_mount_type => $mountType, \OC\Files\Filesystem::signal_param_users => $applicable));
         }
         //return $result;
         return '新增数据成功!';
     }
 }