Exemplo n.º 1
0
 /**
  * check if server2server share is enabled
  *
  * @param int $shareType
  * @return boolean
  */
 public function isShareTypeAllowed($shareType)
 {
     if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
         return $this->federatedShareProvider->isOutgoingServer2serverShareEnabled();
     }
     return true;
 }
Exemplo n.º 2
0
 /**
  * check if server-to-server sharing is enabled
  *
  * @param bool $incoming
  * @return bool
  */
 private function isS2SEnabled($incoming = false)
 {
     $result = \OCP\App::isEnabled('files_sharing');
     if ($incoming) {
         $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled();
     } else {
         $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled();
     }
     return $result;
 }
Exemplo n.º 3
0
 /**
  * @dataProvider dataDeleteUser
  *
  * @param string $owner The owner of the share (uid)
  * @param string $initiator The initiator of the share (uid)
  * @param string $recipient The recipient of the share (uid/gid/pass)
  * @param string $deletedUser The user that is deleted
  * @param bool $rowDeleted Is the row deleted in this setup
  */
 public function testDeleteUser($owner, $initiator, $recipient, $deletedUser, $rowDeleted)
 {
     $qb = $this->connection->getQueryBuilder();
     $qb->insert('share')->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE))->setValue('uid_owner', $qb->createNamedParameter($owner))->setValue('uid_initiator', $qb->createNamedParameter($initiator))->setValue('share_with', $qb->createNamedParameter($recipient))->setValue('item_type', $qb->createNamedParameter('file'))->setValue('item_source', $qb->createNamedParameter(42))->setValue('file_source', $qb->createNamedParameter(42))->execute();
     $id = $qb->getLastInsertId();
     $this->provider->userDeleted($deletedUser, \OCP\Share::SHARE_TYPE_REMOTE);
     $qb = $this->connection->getQueryBuilder();
     $qb->select('*')->from('share')->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
     $cursor = $qb->execute();
     $data = $cursor->fetchAll();
     $cursor->closeCursor();
     $this->assertCount($rowDeleted ? 0 : 1, $data);
 }
Exemplo n.º 4
0
 public function testGetSharedByWithLimit()
 {
     $node = $this->getMock('\\OCP\\Files\\File');
     $node->method('getId')->willReturn(42);
     $node->method('getName')->willReturn('myFile');
     $this->tokenHandler->method('generateToken')->willReturn('token');
     $this->notifications->method('sendRemoteShare')->willReturn(true);
     $this->rootFolder->expects($this->never())->method($this->anything());
     $share = $this->shareManager->newShare();
     $share->setSharedWith('*****@*****.**')->setSharedBy('sharedBy')->setShareOwner('shareOwner')->setPermissions(19)->setNode($node);
     $this->provider->create($share);
     $share2 = $this->shareManager->newShare();
     $share2->setSharedWith('*****@*****.**')->setSharedBy('sharedBy')->setShareOwner('shareOwner')->setPermissions(19)->setNode($node);
     $this->provider->create($share2);
     $shares = $this->provider->getSharesBy('shareOwner', \OCP\Share::SHARE_TYPE_REMOTE, null, true, 1, 1);
     $this->assertCount(1, $shares);
     $this->assertEquals('*****@*****.**', $shares[0]->getSharedWith());
 }
Exemplo n.º 5
0
 /**
  * update share information to keep federated re-shares in sync
  *
  * @param array $params
  * @return \OC_OCS_Result
  */
 public function updatePermissions($params)
 {
     $id = (int) $params['id'];
     $token = $this->request->getParam('token', null);
     $permissions = $this->request->getParam('permissions', null);
     try {
         $share = $this->federatedShareProvider->getShareById($id);
     } catch (Share\Exceptions\ShareNotFound $e) {
         return new \OC_OCS_Result(null, Http::STATUS_BAD_REQUEST);
     }
     $validPermission = ctype_digit($permissions);
     $validToken = $this->verifyShare($share, $token);
     if ($validPermission && $validToken) {
         $this->updatePermissionsInDatabase($share, (int) $permissions);
     } else {
         return new \OC_OCS_Result(null, Http::STATUS_BAD_REQUEST);
     }
     return new \OC_OCS_Result();
 }
 /**
  * @dataProvider dataTestFederatedSharingSettings
  *
  * @param string $isEnabled
  * @param bool $expected
  */
 public function testIsIncomingServer2serverShareEnabled($isEnabled, $expected)
 {
     $this->config->expects($this->once())->method('getAppValue')->with('files_sharing', 'incoming_server2server_share_enabled', 'yes')->willReturn($isEnabled);
     $this->assertSame($expected, $this->provider->isIncomingServer2serverShareEnabled());
 }
Exemplo n.º 7
0
 /**
  * @PublicPage
  * @NoCSRFRequired
  *
  * @param string $token
  * @param string $path
  * @return TemplateResponse|RedirectResponse
  * @throws NotFoundException
  */
 public function showShare($token, $path = '')
 {
     \OC_User::setIncognitoMode(true);
     // Check whether share exists
     try {
         $share = $this->shareManager->getShareByToken($token);
     } catch (ShareNotFound $e) {
         $this->emitAccessShareHook($token, 404, 'Share not found');
         return new NotFoundResponse();
     }
     // Share is password protected - check whether the user is permitted to access the share
     if ($share->getPassword() !== null && !$this->linkShareAuth($share)) {
         return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate', array('token' => $token)));
     }
     if (!$this->validateShare($share)) {
         throw new NotFoundException();
     }
     // We can't get the path of a file share
     try {
         if ($share->getNode() instanceof \OCP\Files\File && $path !== '') {
             $this->emitAccessShareHook($share, 404, 'Share not found');
             throw new NotFoundException();
         }
     } catch (\Exception $e) {
         $this->emitAccessShareHook($share, 404, 'Share not found');
         throw $e;
     }
     $rootFolder = null;
     if ($share->getNode() instanceof \OCP\Files\Folder) {
         /** @var \OCP\Files\Folder $rootFolder */
         $rootFolder = $share->getNode();
         try {
             $path = $rootFolder->get($path);
         } catch (\OCP\Files\NotFoundException $e) {
             $this->emitAccessShareHook($share, 404, 'Share not found');
             throw new NotFoundException();
         }
     }
     $shareTmpl = [];
     $shareTmpl['displayName'] = $this->userManager->get($share->getShareOwner())->getDisplayName();
     $shareTmpl['owner'] = $share->getShareOwner();
     $shareTmpl['filename'] = $share->getNode()->getName();
     $shareTmpl['directory_path'] = $share->getTarget();
     $shareTmpl['mimetype'] = $share->getNode()->getMimetype();
     $shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($share->getNode()->getMimetype());
     $shareTmpl['dirToken'] = $token;
     $shareTmpl['sharingToken'] = $token;
     $shareTmpl['server2serversharing'] = $this->federatedShareProvider->isOutgoingServer2serverShareEnabled();
     $shareTmpl['protected'] = $share->getPassword() !== null ? 'true' : 'false';
     $shareTmpl['dir'] = '';
     $shareTmpl['nonHumanFileSize'] = $share->getNode()->getSize();
     $shareTmpl['fileSize'] = \OCP\Util::humanFileSize($share->getNode()->getSize());
     // Show file list
     if ($share->getNode() instanceof \OCP\Files\Folder) {
         $shareTmpl['dir'] = $rootFolder->getRelativePath($path->getPath());
         /*
          * The OC_Util methods require a view. This just uses the node API
          */
         $freeSpace = $share->getNode()->getStorage()->free_space($share->getNode()->getInternalPath());
         if ($freeSpace < \OCP\Files\FileInfo::SPACE_UNLIMITED) {
             $freeSpace = max($freeSpace, 0);
         } else {
             $freeSpace = INF > 0 ? INF : PHP_INT_MAX;
             // work around https://bugs.php.net/bug.php?id=69188
         }
         $uploadLimit = Util::uploadLimit();
         $maxUploadFilesize = min($freeSpace, $uploadLimit);
         $folder = new Template('files', 'list', '');
         $folder->assign('dir', $rootFolder->getRelativePath($path->getPath()));
         $folder->assign('dirToken', $token);
         $folder->assign('permissions', \OCP\Constants::PERMISSION_READ);
         $folder->assign('isPublic', true);
         $folder->assign('publicUploadEnabled', 'no');
         $folder->assign('uploadMaxFilesize', $maxUploadFilesize);
         $folder->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
         $folder->assign('freeSpace', $freeSpace);
         $folder->assign('uploadLimit', $uploadLimit);
         // PHP upload limit
         $folder->assign('usedSpacePercent', 0);
         $folder->assign('trash', false);
         $shareTmpl['folder'] = $folder->fetchPage();
     }
     $shareTmpl['downloadURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.downloadShare', array('token' => $token));
     $shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
     $shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true);
     $shareTmpl['previewMaxX'] = $this->config->getSystemValue('preview_max_x', 1024);
     $shareTmpl['previewMaxY'] = $this->config->getSystemValue('preview_max_y', 1024);
     $csp = new OCP\AppFramework\Http\ContentSecurityPolicy();
     $csp->addAllowedFrameDomain('\'self\'');
     $response = new TemplateResponse($this->appName, 'public', $shareTmpl, 'base');
     $response->setContentSecurityPolicy($csp);
     $this->emitAccessShareHook($share);
     return $response;
 }