Ejemplo n.º 1
0
 public function switchActions($actionName, $httpVars, $fileVars)
 {
     switch ($actionName) {
         case "accept_invitation":
             $remoteShareId = \AJXP_Utils::sanitize($httpVars["remote_share_id"], AJXP_SANITIZE_ALPHANUM);
             $store = new SQLStore();
             $remoteShare = $store->remoteShareById($remoteShareId);
             if ($remoteShare !== null) {
                 $client = new OCSClient();
                 $client->acceptInvitation($remoteShare);
                 $remoteShare->setStatus(OCS_INVITATION_STATUS_ACCEPTED);
                 $store->storeRemoteShare($remoteShare);
             }
             break;
         case "reject_invitation":
             $remoteShareId = \AJXP_Utils::sanitize($httpVars["remote_share_id"], AJXP_SANITIZE_ALPHANUM);
             $store = new SQLStore();
             $remoteShare = $store->remoteShareById($remoteShareId);
             if ($remoteShare !== null) {
                 $client = new OCSClient();
                 $client->declineInvitation($remoteShare);
                 $store->deleteRemoteShare($remoteShare);
                 \ConfService::getInstance()->invalidateLoadedRepositories();
             }
             break;
         default:
             break;
     }
     return null;
 }
Ejemplo n.º 2
0
 protected function actionReceive($parameters)
 {
     $targetUser = \AJXP_Utils::sanitize($parameters["shareWith"], AJXP_SANITIZE_EMAILCHARS);
     if (!\AuthService::userExists($targetUser)) {
         throw new UserNotFoundException();
     }
     $token = \AJXP_Utils::sanitize($parameters["token"], AJXP_SANITIZE_ALPHANUM);
     $remoteId = \AJXP_Utils::sanitize($parameters["remoteId"], AJXP_SANITIZE_ALPHANUM);
     $documentName = \AJXP_Utils::sanitize($parameters["name"], AJXP_SANITIZE_FILENAME);
     $sender = \AJXP_Utils::sanitize($parameters["owner"], AJXP_SANITIZE_EMAILCHARS);
     $remote = $parameters["remote"];
     $testParts = parse_url($remote);
     if (!is_array($testParts) || empty($testParts["scheme"]) || empty($testParts["host"])) {
         throw new InvalidArgumentsException();
     }
     $endpoints = OCSClient::findEndpointsForURL($remote);
     $share = new RemoteShare();
     $share->setUser($targetUser);
     $share->setOcsRemoteId($remoteId);
     $share->setOcsToken($token);
     $share->setDocumentName($documentName);
     $share->setSender($sender);
     $share->setReceptionDate(time());
     $share->setStatus(OCS_INVITATION_STATUS_PENDING);
     $share->setHost(rtrim($remote, '/'));
     $share->setOcsServiceUrl(rtrim($remote, '/') . $endpoints['share']);
     $share->setOcsDavUrl(rtrim($remote, '/') . $endpoints['webdav']);
     $share->pingRemoteDAVPoint();
     $store = new SQLStore();
     $newShare = $store->storeRemoteShare($share);
     $response = $this->buildResponse("ok", 200, "Successfully received share, waiting for user response.", array("id" => $newShare->getId()));
     $this->sendResponse($response, $this->getFormat($parameters));
     $userRole = \AuthService::getRole("AJXP_USR_/" . $targetUser);
     if ($userRole !== false) {
         // Artificially "touch" user role
         // to force repositories reload if he is logged in
         \AuthService::updateRole($userRole);
     }
 }