/** * get list of users with access to the file * * @param string $path to the file * @return array */ public function getAccessList($path) { // Make sure that a share key is generated for the owner too list($owner, $ownerPath) = $this->util->getUidAndFilename($path); // always add owner to the list of users with access to the file $userIds = array($owner); if (!$this->util->isFile($ownerPath)) { return array('users' => $userIds, 'public' => false); } $ownerPath = substr($ownerPath, strlen('/files')); $ownerPath = $this->util->stripPartialFileExtension($ownerPath); // Find out who, if anyone, is sharing the file $result = \OCP\Share::getUsersSharingFile($ownerPath, $owner); $userIds = \array_merge($userIds, $result['users']); $public = $result['public'] || $result['remote']; // check if it is a group mount if (\OCP\App::isEnabled("files_external")) { $mounts = \OC_Mount_Config::getSystemMountPoints(); foreach ($mounts as $mount) { if ($mount['mountpoint'] == substr($ownerPath, 1, strlen($mount['mountpoint']))) { $mountedFor = $this->util->getUserWithAccessToMountPoint($mount['applicable']['users'], $mount['applicable']['groups']); $userIds = array_merge($userIds, $mountedFor); } } } // Remove duplicate UIDs $uniqueUserIds = array_unique($userIds); return array('users' => $uniqueUserIds, 'public' => $public); }
/** * check if the file is stored on a system wide mount point * @param string $path relative to /data/user with leading '/' * @return boolean */ public function isSystemWideMountPoint($path) { $normalizedPath = ltrim($path, '/'); if (\OCP\App::isEnabled("files_external")) { $mounts = \OC_Mount_Config::getSystemMountPoints(); foreach ($mounts as $mount) { if ($mount['mountpoint'] == substr($normalizedPath, 0, strlen($mount['mountpoint']))) { if ($this->isMountPointApplicableToUser($mount)) { return true; } } } } return false; }
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU Affero General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. */ OC_Util::checkAdminUser(); OCP\Util::addScript('files_external', 'settings'); OCP\Util::addscript('3rdparty', 'chosen/chosen.jquery.min'); OCP\Util::addStyle('files_external', 'settings'); OCP\Util::addStyle('3rdparty', 'chosen/chosen'); $backends = OC_Mount_Config::getBackends(); $personal_backends = array(); $enabled_backends = explode(',', OCP\Config::getAppValue('files_external', 'user_mounting_backends', '')); foreach ($backends as $class => $backend) { if ($class != '\\OC\\Files\\Storage\\Local') { $personal_backends[$class] = array('backend' => $backend['backend'], 'enabled' => in_array($class, $enabled_backends)); } } $tmpl = new OCP\Template('files_external', 'settings'); $tmpl->assign('isAdminPage', true); $tmpl->assign('mounts', OC_Mount_Config::getSystemMountPoints()); $tmpl->assign('backends', $backends); $tmpl->assign('personal_backends', $personal_backends); $tmpl->assign('groups', OC_Group::getGroups()); $tmpl->assign('users', OCP\User::getUsers()); $tmpl->assign('userDisplayNames', OC_User::getDisplayNames()); $tmpl->assign('dependencies', OC_Mount_Config::checkDependencies()); $tmpl->assign('allowUserMounting', OCP\Config::getAppValue('files_external', 'allow_user_mounting', 'yes')); return $tmpl->fetchPage();
/** * check if the file is stored on a system wide mount point * @param string $path relative to /data/user with leading '/' * @param string $uid * @return boolean */ public function isSystemWideMountPoint($path, $uid) { if (\OCP\App::isEnabled("files_external")) { $mounts = \OC_Mount_Config::getSystemMountPoints(); foreach ($mounts as $mount) { if (strpos($path, '/files/' . $mount['mountpoint']) === 0) { if ($this->isMountPointApplicableToUser($mount, $uid)) { return true; } } } } return false; }
/** * Create then re-read mount points configs where the mount points * have the same path, the config must NOT be merged. */ public function testRereadMountpointWithSamePath() { $mountType = OC_Mount_Config::MOUNT_TYPE_USER; $isPersonal = false; $options1 = array('host' => 'smbhost', 'user' => 'smbuser', 'password' => 'smbpassword', 'share' => 'smbshare', 'root' => 'smbroot'); // write config $this->assertTrue(OC_Mount_Config::addMountPoint('/ext', '\\OC\\Files\\Storage\\SMB', $options1, $mountType, self::TEST_USER1, $isPersonal)); $options2 = array('host' => 'anothersmbhost', 'user' => 'anothersmbuser', 'password' => 'anothersmbpassword', 'share' => 'anothersmbshare', 'root' => 'anothersmbroot'); $this->assertTrue(OC_Mount_Config::addMountPoint('/ext', '\\OC\\Files\\Storage\\SMB', $options2, $mountType, self::TEST_USER2, $isPersonal)); // re-read config $config = OC_Mount_Config::getSystemMountPoints(); $this->assertEquals(2, count($config)); $this->assertEquals('\\OC\\Files\\Storage\\SMB', $config[0]['class']); $this->assertEquals('ext', $config[0]['mountpoint']); $this->assertEquals($options1, $config[0]['options']); $this->assertEquals('\\OC\\Files\\Storage\\SMB', $config[1]['class']); $this->assertEquals('ext', $config[1]['mountpoint']); $this->assertEquals($options2, $config[1]['options']); }
/** * get system mount points * wrap static method so that it can be mocked for testing * * @return array */ protected function getSystemMountPoints() { return \OC_Mount_Config::getSystemMountPoints(); }
/** * Test reading and writing global config */ public function testReadWriteGlobalConfig() { $mountType = OC_Mount_Config::MOUNT_TYPE_USER; $applicable = 'all'; $isPersonal = false; $mountConfig = array('host' => 'smbhost', 'user' => 'smbuser', 'password' => 'smbpassword', 'share' => 'smbshare', 'root' => 'smbroot'); // write config $this->assertTrue(OC_Mount_Config::addMountPoint('/ext', '\\OC\\Files\\Storage\\SMB', $mountConfig, $mountType, $applicable, $isPersonal)); // re-read config $config = OC_Mount_Config::getSystemMountPoints(); $this->assertEquals(1, count($config)); $this->assertTrue(isset($config['ext'])); $this->assertEquals('\\OC\\Files\\Storage\\SMB', $config['ext']['class']); $savedMountConfig = $config['ext']['configuration']; $this->assertEquals($mountConfig, $savedMountConfig); // key order needs to be preserved for the UI... $this->assertEquals(array_keys($mountConfig), array_keys($savedMountConfig)); }
if ($class != '\\OC\\Files\\Storage\\Local') { $personal_backends[$class] = array('backend' => $backend['backend'], 'enabled' => in_array($class, $enabled_backends)); } } $mounts = OC_Mount_Config::getSystemMountPoints(); $hasId = true; foreach ($mounts as $mount) { if (!isset($mount['id'])) { // some mount points are missing ids $hasId = false; break; } } if (!$hasId) { $service = new \OCA\Files_external\Service\GlobalStoragesService(); // this will trigger the new storage code which will automatically // generate storage config ids $service->getAllStorages(); // re-read updated config $mounts = OC_Mount_Config::getSystemMountPoints(); // TODO: use the new storage config format in the template } $tmpl = new OCP\Template('files_external', 'settings'); $tmpl->assign('encryptionEnabled', \OC::$server->getEncryptionManager()->isEnabled()); $tmpl->assign('isAdminPage', true); $tmpl->assign('mounts', $mounts); $tmpl->assign('backends', $backends); $tmpl->assign('personal_backends', $personal_backends); $tmpl->assign('dependencies', OC_Mount_Config::checkDependencies()); $tmpl->assign('allowUserMounting', OCP\Config::getAppValue('files_external', 'allow_user_mounting', 'yes')); return $tmpl->fetchPage();
public function testAllowWritingIncompleteConfigIfStorageContructorFails() { $storageClass = 'Test_Mount_Config_Dummy_Storage'; $mountType = 'user'; $applicable = 'all'; $isPersonal = false; $this->assertEquals(0, OC_Mount_Config::addMountPoint('/ext', $storageClass, array('simulateFail' => true), $mountType, $applicable, $isPersonal)); // config can be retrieved afterwards $mounts = OC_Mount_Config::getSystemMountPoints(); $this->assertEquals(1, count($mounts)); // no storage id was set $this->assertFalse(isset($mounts[0]['storage_id'])); }
/** * @brief check if the file is stored on a system wide mount point * @param $path relative to /data/user with leading '/' * @return boolean */ public function isSystemWideMountPoint($path) { if (\OCP\App::isEnabled("files_external")) { $mount = \OC_Mount_Config::getSystemMountPoints(); foreach ($mount as $mountPoint => $data) { if ($mountPoint == substr($path, 1, strlen($mountPoint))) { return true; } } } return false; }