Exemplo n.º 1
0
 /**
  * @param String $shareId
  * @param array $shareMeta
  * @param AJXP_Node $node
  * @throws Exception
  * @return array|bool
  */
 public function shareToJson($shareId, $shareMeta, $node = null)
 {
     $messages = ConfService::getMessages();
     $jsonData = array();
     $elementWatch = false;
     if ($shareMeta["type"] == "file") {
         require_once "class.LegacyPubliclet.php";
         $jsonData = LegacyPubliclet::publicletToJson($shareId, $shareMeta, $this->getShareStore(), $this->getPublicAccessManager(), $this->watcher, $node);
     } else {
         if ($shareMeta["type"] == "minisite" || $shareMeta["type"] == "repository") {
             $repoId = $shareId;
             if (strpos($repoId, "repo-") === 0) {
                 // Legacy
                 $repoId = str_replace("repo-", "", $repoId);
                 $shareMeta["type"] = "repository";
             }
             $minisite = $shareMeta["type"] == "minisite";
             if ($minisite) {
                 $shareLink = $this->getShareStore()->loadShareObject($shareId);
                 $repoId = $shareLink->getRepositoryId();
             }
             $notExistsData = array("error" => true, "repositoryId" => $repoId, "users_number" => 0, "label" => "Error - Cannot find shared data", "description" => "Cannot find repository", "entries" => array(), "element_watch" => false, "repository_url" => "");
             $repo = ConfService::getRepositoryById($repoId);
             if ($repoId == null || $repo == null && $node != null) {
                 if ($minisite) {
                     $this->getShareStore()->getMetaManager()->removeShareFromMeta($node, $shareId);
                 }
                 return $notExistsData;
             }
             try {
                 $this->getShareStore()->testUserCanEditShare($repo->getOwner(), $repo->options);
             } catch (Exception $e) {
                 $notExistsData["label"] = $e->getMessage();
                 return $notExistsData;
             }
             if ($this->watcher != false && $node != null) {
                 $elementWatch = $this->watcher->hasWatchOnNode(new AJXP_Node("pydio://" . $repoId . "/"), AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_NAMESPACE);
             }
             if ($node != null) {
                 $sharedEntries = $this->getRightsManager()->computeSharedRepositoryAccessRights($repoId, true, new AJXP_Node("pydio://" . $repoId . "/"));
             } else {
                 $sharedEntries = $this->getRightsManager()->computeSharedRepositoryAccessRights($repoId, true, null);
             }
             if (empty($sharedEntries) && $minisite) {
                 $this->getShareStore()->getMetaManager()->removeShareFromMeta($node, $shareId);
                 return $notExistsData;
             }
             $cFilter = $repo->getContentFilter();
             if (!empty($cFilter)) {
                 $cFilter = $cFilter->toArray();
             }
             $jsonData = array("repositoryId" => $repoId, "users_number" => AuthService::countUsersForRepository($repoId), "label" => $repo->getDisplay(), "description" => $repo->getDescription(), "entries" => $sharedEntries, "element_watch" => $elementWatch, "repository_url" => AJXP_Utils::getWorkspaceShortcutURL($repo) . "/", "content_filter" => $cFilter, "share_owner" => $repo->getOwner(), "share_scope" => isset($repo->options["SHARE_ACCESS"]) ? $repo->options["SHARE_ACCESS"] : "private");
             if ($minisite && isset($shareLink)) {
                 $shareLink->setAdditionalMeta($shareMeta);
                 $jsonData["minisite"] = $shareLink->getJsonData($this->getPublicAccessManager(), $messages);
             }
         }
     }
     return $jsonData;
 }
Exemplo n.º 2
0
 /**
  * @param String $repoId
  * @param $mixUsersAndGroups
  * @param $currentFileUrl
  * @return array
  */
 public function computeSharedRepositoryAccessRights($repoId, $mixUsersAndGroups, $currentFileUrl)
 {
     $loggedUser = AuthService::getLoggedUser();
     $users = AuthService::getUsersForRepository($repoId);
     $baseGroup = "/";
     $groups = AuthService::listChildrenGroups($baseGroup);
     $mess = ConfService::getMessages();
     $groups[$baseGroup] = $mess["447"];
     $sharedEntries = array();
     if (!$mixUsersAndGroups) {
         $sharedGroups = array();
     }
     foreach ($groups as $gId => $gLabel) {
         $r = AuthService::getRole("AJXP_GRP_" . AuthService::filterBaseGroup($gId));
         if ($r != null) {
             $right = $r->getAcl($repoId);
             if (!empty($right)) {
                 $entry = array("ID" => $gId, "TYPE" => "group", "LABEL" => $gLabel, "RIGHT" => $right);
                 if (!$mixUsersAndGroups) {
                     $sharedGroups[$gId] = $entry;
                 } else {
                     $sharedEntries[] = $entry;
                 }
             }
         }
     }
     foreach ($users as $userId => $userObject) {
         if ($userObject->getId() == $loggedUser->getId()) {
             continue;
         }
         $ri = $userObject->personalRole->getAcl($repoId);
         $uLabel = $userObject->personalRole->filterParameterValue("core.conf", "USER_DISPLAY_NAME", AJXP_REPO_SCOPE_ALL, "");
         if (empty($uLabel)) {
             $uLabel = $userId;
         }
         if (!empty($ri)) {
             $entry = array("ID" => $userId, "TYPE" => $userObject->hasParent() ? "tmp_user" : "user", "LABEL" => $uLabel, "RIGHT" => $userObject->personalRole->getAcl($repoId));
             if ($this->watcher !== false) {
                 $entry["WATCH"] = $this->watcher->hasWatchOnNode(new AJXP_Node($currentFileUrl), $userId, MetaWatchRegister::$META_WATCH_USERS_NAMESPACE);
             }
             if (!$mixUsersAndGroups) {
                 $sharedEntries[$userId] = $entry;
             } else {
                 $sharedEntries[] = $entry;
             }
         }
     }
     if (!$mixUsersAndGroups) {
         return array("USERS" => $sharedEntries, "GROUPS" => $sharedGroups);
     }
     return $sharedEntries;
 }
Exemplo n.º 3
0
 /**
  * @param string $shareId
  * @param ShareStore $shareStore
  * @param PublicAccessManager $publicAccessManager
  * @param MetaWatchRegister|null $watcher
  * @return array|false
  * @throws Exception
  */
 public static function publicletToJson($shareId, $shareMeta, $shareStore, $publicAccessManager, $watcher, $node)
 {
     $messages = ConfService::getMessages();
     $elementWatch = false;
     $pData = $shareStore->loadShare($shareId);
     if (!count($pData)) {
         return false;
     }
     foreach ($shareStore->modifiableShareKeys as $key) {
         if (isset($pData[$key])) {
             $shareMeta[$key] = $pData[$key];
         }
     }
     if ($pData["OWNER_ID"] != AuthService::getLoggedUser()->getId() && !AuthService::getLoggedUser()->isAdmin()) {
         throw new Exception($messages["share_center.48"]);
     }
     if (isset($shareMeta["short_form_url"])) {
         $link = $shareMeta["short_form_url"];
     } else {
         $link = $publicAccessManager->buildPublicLink($shareId);
     }
     if ($watcher != false && $node != null) {
         $result = array();
         $elementWatch = $watcher->hasWatchOnNode($node, AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_USERS_NAMESPACE, $result);
         if ($elementWatch && !in_array($shareId, $result)) {
             $elementWatch = false;
         }
     }
     $jsonData = array_merge(array("element_id" => $shareId, "publiclet_link" => $link, "download_counter" => $shareStore->getCurrentDownloadCounter($shareId), "download_limit" => $pData["DOWNLOAD_LIMIT"], "expire_time" => $pData["EXPIRE_TIME"] != 0 ? date($messages["date_format"], $pData["EXPIRE_TIME"]) : 0, "has_password" => !empty($pData["PASSWORD"]), "element_watch" => $elementWatch, "is_expired" => $shareStore->isShareExpired($shareId, $pData)), $shareMeta);
     return $jsonData;
 }
Exemplo n.º 4
0
 /**
  * @param String $shareId
  * @param Array $shareData
  * @param AJXP_Node $node
  * @throws Exception
  * @return array|bool
  */
 public function shareToJson($shareId, $shareData, $node = null)
 {
     $messages = ConfService::getMessages();
     $jsonData = array();
     $elementWatch = false;
     if ($shareData["type"] == "file") {
         $pData = $this->getShareStore()->loadShare($shareId);
         if (!count($pData)) {
             return false;
         }
         foreach ($this->getShareStore()->modifiableShareKeys as $key) {
             if (isset($pData[$key])) {
                 $shareData[$key] = $pData[$key];
             }
         }
         if ($pData["OWNER_ID"] != AuthService::getLoggedUser()->getId() && !AuthService::getLoggedUser()->isAdmin()) {
             throw new Exception($messages["share_center.48"]);
         }
         if (isset($shareData["short_form_url"])) {
             $link = $shareData["short_form_url"];
         } else {
             $link = $this->buildPublicletLink($shareId);
         }
         if ($this->watcher != false && $node != null) {
             $result = array();
             $elementWatch = $this->watcher->hasWatchOnNode($node, AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_USERS_NAMESPACE, $result);
             if ($elementWatch && !in_array($shareId, $result)) {
                 $elementWatch = false;
             }
         }
         $jsonData = array_merge(array("element_id" => $shareId, "publiclet_link" => $link, "download_counter" => $this->getShareStore()->getCurrentDownloadCounter($shareId), "download_limit" => $pData["DOWNLOAD_LIMIT"], "expire_time" => $pData["EXPIRE_TIME"] != 0 ? date($messages["date_format"], $pData["EXPIRE_TIME"]) : 0, "has_password" => !empty($pData["PASSWORD"]), "element_watch" => $elementWatch, "is_expired" => $this->shareStore->isShareExpired($shareId, $pData)), $shareData);
     } else {
         if ($shareData["type"] == "minisite" || $shareData["type"] == "repository") {
             $repoId = $shareId;
             if (strpos($repoId, "repo-") === 0) {
                 // Legacy
                 $repoId = str_replace("repo-", "", $repoId);
                 $shareData["type"] = "repository";
             }
             $minisite = $shareData["type"] == "minisite";
             $minisiteIsPublic = false;
             $dlDisabled = false;
             $minisiteLink = '';
             if ($minisite) {
                 $minisiteData = $this->getShareStore()->loadShare($shareId);
                 $repoId = $minisiteData["REPOSITORY"];
                 $minisiteIsPublic = isset($minisiteData["PRELOG_USER"]);
                 $dlDisabled = isset($minisiteData["DOWNLOAD_DISABLED"]) && $minisiteData["DOWNLOAD_DISABLED"] === true;
                 if (isset($shareData["short_form_url"])) {
                     $minisiteLink = $shareData["short_form_url"];
                 } else {
                     $minisiteLink = $this->buildPublicletLink($shareId);
                 }
             }
             $notExistsData = array("error" => true, "repositoryId" => $repoId, "users_number" => 0, "label" => "Error - Cannot find shared data", "description" => "Cannot find repository", "entries" => array(), "element_watch" => false, "repository_url" => "");
             $repo = ConfService::getRepositoryById($repoId);
             if ($repoId == null || $repo == null && $node != null) {
                 if ($minisite) {
                     $this->removeShareFromMeta($node, $shareId);
                 }
                 return $notExistsData;
             } else {
                 if (!AuthService::getLoggedUser()->isAdmin() && $repo->getOwner() != AuthService::getLoggedUser()->getId()) {
                     return $notExistsData;
                 }
             }
             if ($this->watcher != false && $node != null) {
                 $elementWatch = $this->watcher->hasWatchOnNode(new AJXP_Node($this->baseProtocol . "://" . $repoId . "/"), AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_NAMESPACE);
             }
             if ($node != null) {
                 $sharedEntries = $this->computeSharedRepositoryAccessRights($repoId, true, $node->getUrl());
             } else {
                 $sharedEntries = $this->computeSharedRepositoryAccessRights($repoId, true, null);
             }
             $cFilter = $repo->getContentFilter();
             if (!empty($cFilter)) {
                 $cFilter = $cFilter->toArray();
             }
             $jsonData = array("repositoryId" => $repoId, "users_number" => AuthService::countUsersForRepository($repoId), "label" => $repo->getDisplay(), "description" => $repo->getDescription(), "entries" => $sharedEntries, "element_watch" => $elementWatch, "repository_url" => AJXP_Utils::detectServerURL(true) . "?goto=" . $repo->getSlug() . "/", "content_filter" => $cFilter);
             if (isset($minisiteData)) {
                 if (!empty($minisiteData["DOWNLOAD_LIMIT"]) && !$dlDisabled) {
                     $jsonData["download_counter"] = $this->getShareStore()->getCurrentDownloadCounter($shareId);
                     $jsonData["download_limit"] = $minisiteData["DOWNLOAD_LIMIT"];
                 }
                 if (!empty($minisiteData["EXPIRE_TIME"])) {
                     $delta = $minisiteData["EXPIRE_TIME"] - time();
                     $days = round($delta / (60 * 60 * 24));
                     $jsonData["expire_time"] = date($messages["date_format"], $minisiteData["EXPIRE_TIME"]);
                     $jsonData["expire_after"] = $days;
                 } else {
                     $jsonData["expire_after"] = 0;
                 }
                 $jsonData["is_expired"] = $this->shareStore->isShareExpired($shareId, $minisiteData);
                 if (isset($minisiteData["AJXP_TEMPLATE_NAME"])) {
                     $jsonData["minisite_layout"] = $minisiteData["AJXP_TEMPLATE_NAME"];
                 }
                 if (!$minisiteIsPublic) {
                     $jsonData["has_password"] = true;
                 }
                 $jsonData["minisite"] = array("public" => $minisiteIsPublic ? "true" : "false", "public_link" => $minisiteLink, "disable_download" => $dlDisabled, "hash" => $shareId, "hash_is_shorten" => isset($shareData["short_form_url"]));
                 foreach ($this->getShareStore()->modifiableShareKeys as $key) {
                     if (isset($minisiteData[$key])) {
                         $jsonData[$key] = $minisiteData[$key];
                     }
                 }
             }
         }
     }
     return $jsonData;
 }
Exemplo n.º 5
0
 /**
  * @param MetaWatchRegister|false $watcher
  * @param ShareRightsManager $rightsManager
  * @param PublicAccessManager $publicAccessManager
  * @param array $messages
  * @return array|false
  */
 public function toJson($watcher, $rightsManager, $publicAccessManager, $messages)
 {
     $repoRootNode = new AJXP_Node("pydio://" . $this->getRepositoryId() . "/");
     $elementWatch = false;
     if ($watcher != false) {
         $elementWatch = $watcher->hasWatchOnNode($repoRootNode, AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_NAMESPACE);
     }
     $sharedEntries = $rightsManager->computeSharedRepositoryAccessRights($this->getRepositoryId(), true, $repoRootNode);
     if (empty($sharedEntries)) {
         return false;
     }
     $cFilter = $this->getRepository()->getContentFilter();
     if (!empty($cFilter)) {
         $cFilter = $cFilter->toArray();
     }
     $jsonData = array("repositoryId" => $this->getRepositoryId(), "users_number" => AuthService::countUsersForRepository($this->getRepositoryId()), "label" => $this->getRepository()->getDisplay(), "description" => $this->getRepository()->getDescription(), "entries" => $sharedEntries, "element_watch" => $elementWatch, "repository_url" => AJXP_Utils::getWorkspaceShortcutURL($this->getRepository()) . "/", "content_filter" => $cFilter, "share_owner" => $this->getOwner(), "share_scope" => $this->getVisibilityScope());
     $jsonData["links"] = array();
     foreach ($this->shareLinks as $shareLink) {
         $uniqueUser = $shareLink->getUniqueUser();
         $found = false;
         foreach ($sharedEntries as $entry) {
             if ($entry["ID"] == $uniqueUser) {
                 $found = true;
             }
         }
         if (!$found) {
             // STRANGE, THE ASSOCIATED USER IS MISSING
             error_log("Found shareLink orphan with uniqueUser " . $uniqueUser);
             continue;
         }
         $jsonData["links"][$shareLink->getHash()] = $shareLink->getJsonData($publicAccessManager, $messages);
     }
     return $jsonData;
 }
 /**
  * @param String $repoId
  * @param bool $mixUsersAndGroups
  * @param AJXP_Node|null $watcherNode
  * @return array
  */
 public function computeSharedRepositoryAccessRights($repoId, $mixUsersAndGroups, $watcherNode = null)
 {
     $roles = AuthService::getRolesForRepository($repoId);
     $sharedEntries = $sharedGroups = array();
     $mess = ConfService::getMessages();
     foreach ($roles as $rId) {
         $role = AuthService::getRole($rId);
         if ($role == null) {
             continue;
         }
         $RIGHT = $role->getAcl($repoId);
         if (empty($RIGHT)) {
             continue;
         }
         $ID = $rId;
         $WATCH = false;
         $HIDDEN = false;
         $AVATAR = false;
         if (strpos($rId, "AJXP_USR_/") === 0) {
             $userId = substr($rId, strlen('AJXP_USR_/'));
             $role = AuthService::getRole($rId);
             $userObject = ConfService::getConfStorageImpl()->createUserObject($userId);
             $LABEL = $role->filterParameterValue("core.conf", "USER_DISPLAY_NAME", AJXP_REPO_SCOPE_ALL, "");
             $AVATAR = $role->filterParameterValue("core.conf", "avatar", AJXP_REPO_SCOPE_ALL, "");
             if (empty($LABEL)) {
                 $LABEL = $userId;
             }
             $TYPE = $userObject->hasParent() ? "tmp_user" : "user";
             $HIDDEN = $userObject->isHidden();
             if ($this->watcher !== false && $watcherNode != null) {
                 $WATCH = $this->watcher->hasWatchOnNode($watcherNode, $userId, MetaWatchRegister::$META_WATCH_USERS_NAMESPACE);
             }
             $ID = $userId;
         } else {
             if ($rId == "AJXP_GRP_" . AuthService::filterBaseGroup("/")) {
                 $TYPE = "group";
                 $LABEL = $mess["447"];
             } else {
                 if (strpos($rId, "AJXP_GRP_/") === 0) {
                     if (empty($loadedGroups)) {
                         $displayAll = ConfService::getCoreConf("CROSSUSERS_ALLGROUPS_DISPLAY", "conf");
                         if ($displayAll) {
                             AuthService::setGroupFiltering(false);
                         }
                         $loadedGroups = AuthService::listChildrenGroups();
                         if ($displayAll) {
                             AuthService::setGroupFiltering(true);
                         } else {
                             $baseGroup = AuthService::filterBaseGroup("/");
                             foreach ($loadedGroups as $loadedG => $loadedLabel) {
                                 unset($loadedGroups[$loadedG]);
                                 $loadedGroups[rtrim($baseGroup, "/") . "/" . ltrim($loadedG, "/")] = $loadedLabel;
                             }
                         }
                     }
                     $groupId = substr($rId, strlen('AJXP_GRP_'));
                     if (isset($loadedGroups[$groupId])) {
                         $LABEL = $loadedGroups[$groupId];
                     }
                     /*
                     if($groupId == AuthService::filterBaseGroup("/")){
                         $LABEL = $mess["447"];
                     }
                     */
                     if (empty($LABEL)) {
                         $LABEL = $groupId;
                     }
                     $TYPE = "group";
                 } else {
                     $role = AuthService::getRole($rId);
                     $LABEL = $role->getLabel();
                     $TYPE = 'group';
                 }
             }
         }
         if (empty($LABEL)) {
             $LABEL = $rId;
         }
         $entry = array("ID" => $ID, "TYPE" => $TYPE, "LABEL" => $LABEL, "RIGHT" => $RIGHT);
         if ($WATCH) {
             $entry["WATCH"] = $WATCH;
         }
         if ($HIDDEN) {
             $entry["HIDDEN"] = true;
         }
         if ($AVATAR !== false) {
             $entry["AVATAR"] = $AVATAR;
         }
         if ($TYPE == "group") {
             $sharedGroups[$entry["ID"]] = $entry;
         } else {
             $sharedEntries[$entry["ID"]] = $entry;
         }
     }
     if (!$mixUsersAndGroups) {
         return array("USERS" => $sharedEntries, "GROUPS" => $sharedGroups);
     } else {
         return array_merge(array_values($sharedGroups), array_values($sharedEntries));
     }
 }