Ejemplo n.º 1
0
 /**
  * Update a share
  *
  * @param \OCP\Share\IShare $share
  * @return \OCP\Share\IShare The share object
  */
 public function update(\OCP\Share\IShare $share)
 {
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
         /*
          * We allow updating the recipient on user shares.
          */
         $qb = $this->dbConn->getQueryBuilder();
         $qb->update('share')->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))->set('share_with', $qb->createNamedParameter($share->getSharedWith()))->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))->set('permissions', $qb->createNamedParameter($share->getPermissions()))->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))->execute();
     } else {
         if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
             $qb = $this->dbConn->getQueryBuilder();
             $qb->update('share')->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))->set('permissions', $qb->createNamedParameter($share->getPermissions()))->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))->execute();
             /*
              * Update all user defined group shares
              */
             $qb = $this->dbConn->getQueryBuilder();
             $qb->update('share')->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))->execute();
             /*
              * Now update the permissions for all children that have not set it to 0
              */
             $qb = $this->dbConn->getQueryBuilder();
             $qb->update('share')->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0)))->set('permissions', $qb->createNamedParameter($share->getPermissions()))->execute();
         } else {
             if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
                 $qb = $this->dbConn->getQueryBuilder();
                 $qb->update('share')->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))->set('share_with', $qb->createNamedParameter($share->getPassword()))->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))->set('permissions', $qb->createNamedParameter($share->getPermissions()))->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))->set('token', $qb->createNamedParameter($share->getToken()))->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))->execute();
             }
         }
     }
     return $share;
 }
Ejemplo n.º 2
0
 /**
  * Verify the password of a public share
  *
  * @param \OCP\Share\IShare $share
  * @param string $password
  * @return bool
  */
 public function checkPassword(\OCP\Share\IShare $share, $password)
 {
     if ($share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK) {
         //TODO maybe exception?
         return false;
     }
     if ($password === null || $share->getPassword() === null) {
         return false;
     }
     $newHash = '';
     if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) {
         return false;
     }
     if (!empty($newHash)) {
         $share->setPassword($newHash);
         $provider = $this->factory->getProviderForType($share->getShareType());
         $provider->update($share);
     }
     return true;
 }
 /**
  * Checks if a password is required or if the one supplied is working
  *
  * @param IShare $share
  * @param string|null $password optional password
  *
  * @throws CheckException
  */
 private function checkAuthorisation($share, $password)
 {
     $passwordRequired = $share->getPassword();
     if (isset($passwordRequired)) {
         if ($password !== null) {
             $this->authenticate($share, $password);
         } else {
             $this->checkSession($share);
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Convert an IShare to an array for OCS output
  *
  * @param \OCP\Share\IShare $share
  * @return array
  * @throws NotFoundException In case the node can't be resolved.
  */
 protected function formatShare(\OCP\Share\IShare $share)
 {
     $sharedBy = $this->userManager->get($share->getSharedBy());
     $shareOwner = $this->userManager->get($share->getShareOwner());
     $result = ['id' => $share->getId(), 'share_type' => $share->getShareType(), 'uid_owner' => $share->getSharedBy(), 'displayname_owner' => $sharedBy !== null ? $sharedBy->getDisplayName() : $share->getSharedBy(), 'permissions' => $share->getPermissions(), 'stime' => $share->getShareTime()->getTimestamp(), 'parent' => null, 'expiration' => null, 'token' => null, 'uid_file_owner' => $share->getShareOwner(), 'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner()];
     $node = $share->getNode();
     $result['path'] = $this->rootFolder->getUserFolder($share->getShareOwner())->getRelativePath($node->getPath());
     if ($node instanceof \OCP\Files\Folder) {
         $result['item_type'] = 'folder';
     } else {
         $result['item_type'] = 'file';
     }
     $result['storage_id'] = $node->getStorage()->getId();
     $result['storage'] = $node->getStorage()->getCache()->getNumericStorageId();
     $result['item_source'] = $node->getId();
     $result['file_source'] = $node->getId();
     $result['file_parent'] = $node->getParent()->getId();
     $result['file_target'] = $share->getTarget();
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
         $sharedWith = $this->userManager->get($share->getSharedWith());
         $result['share_with'] = $share->getSharedWith();
         $result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith();
     } else {
         if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
             $result['share_with'] = $share->getSharedWith();
             $result['share_with_displayname'] = $share->getSharedWith();
         } else {
             if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
                 $result['share_with'] = $share->getPassword();
                 $result['share_with_displayname'] = $share->getPassword();
                 $result['token'] = $share->getToken();
                 $result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]);
                 $expiration = $share->getExpirationDate();
                 if ($expiration !== null) {
                     $result['expiration'] = $expiration->format('Y-m-d 00:00:00');
                 }
             } else {
                 if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) {
                     $result['share_with'] = $share->getSharedWith();
                     $result['share_with_displayname'] = $share->getSharedWith();
                     $result['token'] = $share->getToken();
                 }
             }
         }
     }
     $result['mail_send'] = $share->getMailSend() ? 1 : 0;
     return $result;
 }
Ejemplo n.º 5
0
 /**
  * Creates the environment based on the share the token links to
  *
  * @param IShare $share
  */
 public function setTokenBasedEnv($share)
 {
     $origShareOwnerId = $share->getShareOwner();
     $this->userFolder = $this->rootFolder->getUserFolder($origShareOwnerId);
     $this->sharedNodeId = $share->getNodeId();
     $this->sharedNode = $share->getNode();
     $this->fromRootToFolder = $this->buildFromRootToFolder($this->sharedNodeId);
     $this->folderName = $share->getTarget();
     $this->userId = $origShareOwnerId;
     $this->sharePassword = $share->getPassword();
 }