Пример #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;
 }
Пример #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;
 }
 /**
  * @dataProvider dataTestFederatedSharingSettings
  *
  * @param string $isEnabled
  * @param bool $expected
  */
 public function testIsOutgoingServer2serverShareEnabled($isEnabled, $expected)
 {
     $this->config->expects($this->once())->method('getAppValue')->with('files_sharing', 'outgoing_server2server_share_enabled', 'yes')->willReturn($isEnabled);
     $this->assertSame($expected, $this->provider->isOutgoingServer2serverShareEnabled());
 }
Пример #4
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;
 }