Beispiel #1
0
 /**
  * send server-to-server unshare to remote server
  *
  * @param string $remote url
  * @param int $id share id
  * @param string $token
  * @return bool
  */
 public function sendRemoteUnShare($remote, $id, $token)
 {
     $url = rtrim($remote, '/');
     $fields = array('token' => $token, 'format' => 'json');
     $url = $this->addressHandler->removeProtocolFromUrl($url);
     $result = $this->tryHttpPostToShareEndpoint($url, '/' . $id . '/unshare', $fields);
     $status = json_decode($result['result'], true);
     return $result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200);
 }
Beispiel #2
0
 /**
  * send server-to-server unshare to remote server
  *
  * @param string $remote url
  * @param int $id share id
  * @param string $token
  * @return bool
  */
 public function sendRemoteUnShare($remote, $id, $token)
 {
     $url = rtrim($remote, '/') . self::BASE_PATH_TO_SHARE_API . '/' . $id . '/unshare?format=' . self::RESPONSE_FORMAT;
     $fields = array('token' => $token, 'format' => 'json');
     $url = $this->addressHandler->removeProtocolFromUrl($url);
     $result = $this->tryHttpPost($url, $fields);
     $status = json_decode($result['result'], true);
     return $result['success'] && $status['ocs']['meta']['statuscode'] === 100;
 }
 /**
  * Delete a share
  *
  * @param IShare $share
  */
 public function delete(IShare $share)
 {
     $qb = $this->dbConnection->getQueryBuilder();
     $qb->delete('share')->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())));
     $qb->execute();
     list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedWith());
     $this->notifications->sendRemoteUnShare($remote, $share->getId(), $share->getToken());
 }
 /**
  * in case of a re-share we need to send the other use (initiator or owner)
  * a message that the file was unshared
  *
  * @param IShare $share
  * @param bool $isOwner the user can either be the owner or the user who re-sahred it
  * @throws ShareNotFound
  * @throws \OC\HintException
  */
 protected function revokeShare($share, $isOwner)
 {
     // also send a unShare request to the initiator, if this is a different user than the owner
     if ($share->getShareOwner() !== $share->getSharedBy()) {
         if ($isOwner) {
             list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());
         } else {
             list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner());
         }
         $remoteId = $this->getRemoteId($share);
         $this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken());
     }
 }
Beispiel #5
0
 /**
  * send server-to-server unshare to remote server
  *
  * @param string $remote url
  * @param int $id share id
  * @param string $token
  * @param int $try how often did we already tried to send the un-share request
  * @return bool
  */
 public function sendRemoteUnShare($remote, $id, $token, $try = 0)
 {
     $url = rtrim($remote, '/');
     $fields = array('token' => $token, 'format' => 'json');
     $url = $this->addressHandler->removeProtocolFromUrl($url);
     $result = $this->tryHttpPostToShareEndpoint($url, '/' . $id . '/unshare', $fields);
     $status = json_decode($result['result'], true);
     if ($result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200)) {
         return true;
     } elseif ($try === 0) {
         // only add new job on first try
         $this->jobList->add('OCA\\FederatedFileSharing\\BackgroundJob\\UnShare', ['remote' => $remote, 'id' => $id, 'token' => $token, 'try' => $try, 'lastRun' => $this->getTimestamp()]);
     }
     return false;
 }
 /**
  * inform remote server whether server-to-server share was accepted/declined
  *
  * @param string $remote
  * @param string $token
  * @param int $remoteId Share id on the remote host
  * @param string $action possible actions: accept, decline, unshare, revoke, permissions
  * @param array $data
  * @param int $try
  * @return boolean
  */
 public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0)
 {
     $fields = array('token' => $token);
     foreach ($data as $key => $value) {
         $fields[$key] = $value;
     }
     $url = $this->addressHandler->removeProtocolFromUrl($remote);
     $result = $this->tryHttpPostToShareEndpoint(rtrim($url, '/'), '/' . $remoteId . '/' . $action, $fields);
     $status = json_decode($result['result'], true);
     if ($result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200)) {
         return true;
     } elseif ($try === 0) {
         // only add new job on first try
         $this->jobList->add('OCA\\FederatedFileSharing\\BackgroundJob\\RetryJob', ['remote' => $remote, 'remoteId' => $remoteId, 'token' => $token, 'action' => $action, 'data' => json_encode($data), 'try' => $try, 'lastRun' => $this->getTimestamp()]);
     }
     return false;
 }
 /**
  * decline server-to-server share
  *
  * @param array $params
  * @return \OC_OCS_Result
  */
 public function declineShare($params)
 {
     if (!$this->isS2SEnabled()) {
         return new \OC_OCS_Result(null, 503, 'Server does not support federated cloud sharing');
     }
     $id = (int) $params['id'];
     $token = isset($_POST['token']) ? $_POST['token'] : null;
     try {
         $share = $this->federatedShareProvider->getShareById($id);
     } catch (Share\Exceptions\ShareNotFound $e) {
         return new \OC_OCS_Result();
     }
     if ($this->verifyShare($share, $token)) {
         if ($share->getShareOwner() !== $share->getSharedBy()) {
             list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());
             $remoteId = $this->federatedShareProvider->getRemoteId($share);
             $this->notifications->sendDeclineShare($remote, $remoteId, $share->getToken());
         }
         $this->executeDeclineShare($share);
     }
     return new \OC_OCS_Result();
 }
 /**
  * @dataProvider dataTestRemoveProtocolFromUrl
  *
  * @param string $url
  * @param string $expectedResult
  */
 public function testRemoveProtocolFromUrl($url, $expectedResult)
 {
     $result = $this->addressHandler->removeProtocolFromUrl($url);
     $this->assertSame($expectedResult, $result);
 }