/** * Extend parent * @param DOMNode $contribNode */ protected function parseSpecificContributions(&$contribNode) { parent::parseSpecificContributions($contribNode); $disableSharing = false; $downloadFolder = ConfService::getCoreConf("PUBLIC_DOWNLOAD_FOLDER"); if (empty($downloadFolder) || (!is_dir($downloadFolder) || !is_writable($downloadFolder))) { $this->logError("Warning on public links, {$downloadFolder} is not writeable!", array("folder" => $downloadFolder, "is_dir" => is_dir($downloadFolder), "is_writeable" => is_writable($downloadFolder))); } $xpathesToRemove = array(); if (strpos(ConfService::getRepository()->getAccessType(), "ajxp_") === 0) { $xpathesToRemove[] = 'action[@name="share-file-minisite"]'; $xpathesToRemove[] = 'action[@name="share-folder-minisite-public"]'; $xpathesToRemove[] = 'action[@name="share-edit-shared"]'; } else { if (AuthService::usersEnabled()) { $loggedUser = AuthService::getLoggedUser(); if ($loggedUser != null && AuthService::isReservedUserId($loggedUser->getId())) { $disableSharing = true; } } else { $disableSharing = true; } } if ($disableSharing) { // All share- actions $xpathesToRemove[] = 'action[contains(@name, "share-")]'; } else { $folderSharingAllowed = $this->getAuthorization("folder", "any"); $fileSharingAllowed = $this->getAuthorization("file", "any"); if ($fileSharingAllowed === false) { // Share file button $xpathesToRemove[] = 'action[@name="share-file-minisite"]'; } if (!$folderSharingAllowed) { // Share folder button $xpathesToRemove[] = 'action[@name="share-folder-minisite-public"]'; } } foreach ($xpathesToRemove as $xpath) { $actionXpath = new DOMXPath($contribNode->ownerDocument); $nodeList = $actionXpath->query($xpath, $contribNode); foreach ($nodeList as $shareActionNode) { $contribNode->removeChild($shareActionNode); } } }
public function switchAction($action, $httpVars, $fileVars) { if (!isset($this->actions[$action])) { return; } parent::accessPreprocess($action, $httpVars, $fileVars); $loggedUser = AuthService::getLoggedUser(); if (AuthService::usersEnabled() && !$loggedUser->isAdmin()) { return; } if (AuthService::usersEnabled()) { $currentBookmarks = AuthService::getLoggedUser()->getBookmarks(); // FLATTEN foreach ($currentBookmarks as $bm) { $this->currentBookmarks[] = $bm["PATH"]; } } if ($action == "edit") { if (isset($httpVars["sub_action"])) { $action = $httpVars["sub_action"]; } } $mess = ConfService::getMessages(); $currentUserIsGroupAdmin = AuthService::getLoggedUser() != null && AuthService::getLoggedUser()->getGroupPath() != "/"; if ($currentUserIsGroupAdmin && ConfService::getAuthDriverImpl()->isAjxpAdmin(AuthService::getLoggedUser()->getId())) { $currentUserIsGroupAdmin = false; } switch ($action) { //------------------------------------ // BASIC LISTING //------------------------------------ case "ls": $rootNodes = array("data" => array("LABEL" => $mess["ajxp_conf.110"], "ICON" => "user.png", "DESCRIPTION" => $mess["ajxp_conf.137"], "CHILDREN" => array("repositories" => array("AJXP_MIME" => "workspaces_zone", "LABEL" => $mess["ajxp_conf.3"], "DESCRIPTION" => $mess["ajxp_conf.138"], "ICON" => "hdd_external_unmount.png", "LIST" => "listRepositories"), "users" => array("AJXP_MIME" => "users_zone", "LABEL" => $mess["ajxp_conf.2"], "DESCRIPTION" => $mess["ajxp_conf.139"], "ICON" => "users-folder.png", "LIST" => "listUsers"), "roles" => array("AJXP_MIME" => "roles_zone", "LABEL" => $mess["ajxp_conf.69"], "DESCRIPTION" => $mess["ajxp_conf.140"], "ICON" => "user-acl.png", "LIST" => "listRoles"))), "config" => array("AJXP_MIME" => "plugins_zone", "LABEL" => $mess["ajxp_conf.109"], "ICON" => "preferences_desktop.png", "DESCRIPTION" => $mess["ajxp_conf.136"], "CHILDREN" => array("core" => array("AJXP_MIME" => "plugins_zone", "LABEL" => $mess["ajxp_conf.98"], "DESCRIPTION" => $mess["ajxp_conf.133"], "ICON" => "preferences_desktop.png", "LIST" => "listPlugins"), "plugins" => array("AJXP_MIME" => "plugins_zone", "LABEL" => $mess["ajxp_conf.99"], "DESCRIPTION" => $mess["ajxp_conf.134"], "ICON" => "folder_development.png", "LIST" => "listPlugins"), "core_plugins" => array("AJXP_MIME" => "plugins_zone", "LABEL" => $mess["ajxp_conf.123"], "DESCRIPTION" => $mess["ajxp_conf.135"], "ICON" => "folder_development.png", "LIST" => "listPlugins"))), "admin" => array("LABEL" => $mess["ajxp_conf.111"], "ICON" => "toggle_log.png", "DESCRIPTION" => $mess["ajxp_conf.141"], "CHILDREN" => array("logs" => array("LABEL" => $mess["ajxp_conf.4"], "DESCRIPTION" => $mess["ajxp_conf.142"], "ICON" => "toggle_log.png", "LIST" => "listLogFiles"), "diagnostic" => array("LABEL" => $mess["ajxp_conf.5"], "DESCRIPTION" => $mess["ajxp_conf.143"], "ICON" => "susehelpcenter.png", "LIST" => "printDiagnostic"))), "developer" => array("LABEL" => $mess["ajxp_conf.144"], "ICON" => "applications_engineering.png", "DESCRIPTION" => $mess["ajxp_conf.145"], "CHILDREN" => array("actions" => array("LABEL" => $mess["ajxp_conf.146"], "DESCRIPTION" => $mess["ajxp_conf.147"], "ICON" => "book.png", "LIST" => "listActions"), "hooks" => array("LABEL" => $mess["ajxp_conf.148"], "DESCRIPTION" => $mess["ajxp_conf.149"], "ICON" => "book.png", "LIST" => "listHooks")))); if ($currentUserIsGroupAdmin) { unset($rootNodes["config"]); unset($rootNodes["admin"]); unset($rootNodes["developer"]); } AJXP_Controller::applyHook("ajxp_conf.list_config_nodes", array(&$rootNodes)); $parentName = ""; $dir = trim(AJXP_Utils::decodeSecureMagic(isset($httpVars["dir"]) ? $httpVars["dir"] : ""), " /"); if ($dir != "") { $hash = null; if (strstr(urldecode($dir), "#") !== false) { list($dir, $hash) = explode("#", urldecode($dir)); } $splits = explode("/", $dir); $root = array_shift($splits); if (count($splits)) { $returnNodes = false; if (isset($httpVars["file"])) { $returnNodes = true; } $child = $splits[0]; if (isset($rootNodes[$root]["CHILDREN"][$child])) { $atts = array(); if ($child == "users") { $atts["remote_indexation"] = "admin_search"; } $callback = $rootNodes[$root]["CHILDREN"][$child]["LIST"]; if (is_string($callback) && method_exists($this, $callback)) { if (!$returnNodes) { AJXP_XMLWriter::header("tree", $atts); } $res = call_user_func(array($this, $callback), implode("/", $splits), $root, $hash, $returnNodes, isset($httpVars["file"]) ? $httpVars["file"] : ''); if (!$returnNodes) { AJXP_XMLWriter::close(); } } else { if (is_array($callback)) { $res = call_user_func($callback, implode("/", $splits), $root, $hash, $returnNodes, isset($httpVars["file"]) ? $httpVars["file"] : ''); } } if ($returnNodes) { AJXP_XMLWriter::header("tree", $atts); if (isset($res["/" . $dir . "/" . $httpVars["file"]])) { print $res["/" . $dir . "/" . $httpVars["file"]]; } AJXP_XMLWriter::close(); } return; } } else { $parentName = "/" . $root . "/"; $nodes = $rootNodes[$root]["CHILDREN"]; } } else { $parentName = "/"; $nodes = $rootNodes; } if (isset($httpVars["file"])) { $parentName = $httpVars["dir"] . "/"; $nodes = array(basename($httpVars["file"]) => array("LABEL" => basename($httpVars["file"]))); } if (isset($nodes)) { AJXP_XMLWriter::header(); if (!isset($httpVars["file"])) { AJXP_XMLWriter::sendFilesListComponentConfig('<columns switchDisplayMode="detail"><column messageId="ajxp_conf.1" attributeName="ajxp_label" sortType="String"/><column messageId="ajxp_conf.102" attributeName="description" sortType="String"/></columns>'); } foreach ($nodes as $key => $data) { $bmString = ''; if (in_array($parentName . $key, $this->currentBookmarks)) { $bmString = ' ajxp_bookmarked="true" overlay_icon="bookmark.png" '; } if ($key == "users") { $bmString .= ' remote_indexation="admin_search"'; } if (isset($data["AJXP_MIME"])) { $bmString .= ' ajxp_mime="' . $data["AJXP_MIME"] . '"'; } if (empty($data["CHILDREN"])) { print '<tree text="' . AJXP_Utils::xmlEntities($data["LABEL"]) . '" description="' . AJXP_Utils::xmlEntities($data["DESCRIPTION"]) . '" icon="' . $data["ICON"] . '" filename="' . $parentName . $key . '" ' . $bmString . '/>'; } else { print '<tree text="' . AJXP_Utils::xmlEntities($data["LABEL"]) . '" description="' . AJXP_Utils::xmlEntities($data["DESCRIPTION"]) . '" icon="' . $data["ICON"] . '" filename="' . $parentName . $key . '" ' . $bmString . '>'; foreach ($data["CHILDREN"] as $cKey => $cData) { $bmString = ''; if (in_array($parentName . $key . "/" . $cKey, $this->currentBookmarks)) { $bmString = ' ajxp_bookmarked="true" overlay_icon="bookmark.png" '; } if ($cKey == "users") { $bmString .= ' remote_indexation="admin_search"'; } if (isset($cData["AJXP_MIME"])) { $bmString .= ' ajxp_mime="' . $cData["AJXP_MIME"] . '"'; } print '<tree text="' . AJXP_Utils::xmlEntities($cData["LABEL"]) . '" description="' . AJXP_Utils::xmlEntities($cData["DESCRIPTION"]) . '" icon="' . $cData["ICON"] . '" filename="' . $parentName . $key . '/' . $cKey . '" ' . $bmString . '/>'; } print '</tree>'; } } AJXP_XMLWriter::close(); } break; case "stat": header("Content-type:application/json"); print '{"mode":true}'; return; break; case "clear_plugins_cache": AJXP_XMLWriter::header(); // Clear plugins cache if they exist AJXP_PluginsService::clearPluginsCache(); ConfService::clearMessagesCache(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf." . (AJXP_SKIP_CACHE ? "132" : "131")], null); AJXP_XMLWriter::reloadDataNode(); AJXP_XMLWriter::close(); break; case "create_group": if (isset($httpVars["group_path"])) { $basePath = AJXP_Utils::forwardSlashDirname($httpVars["group_path"]); if (empty($basePath)) { $basePath = "/"; } $gName = AJXP_Utils::sanitize(AJXP_Utils::decodeSecureMagic(basename($httpVars["group_path"])), AJXP_SANITIZE_ALPHANUM); } else { $basePath = substr($httpVars["dir"], strlen("/data/users")); $gName = AJXP_Utils::sanitize(SystemTextEncoding::magicDequote($httpVars["group_name"]), AJXP_SANITIZE_ALPHANUM); } $gLabel = AJXP_Utils::decodeSecureMagic($httpVars["group_label"]); AuthService::createGroup($basePath, $gName, $gLabel); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.124"], null); AJXP_XMLWriter::reloadDataNode(); AJXP_XMLWriter::close(); break; case "create_role": $roleId = AJXP_Utils::sanitize(SystemTextEncoding::magicDequote($httpVars["role_id"]), AJXP_SANITIZE_HTML_STRICT); if (!strlen($roleId)) { throw new Exception($mess[349]); } if (AuthService::getRole($roleId) !== false) { throw new Exception($mess["ajxp_conf.65"]); } $r = new AJXP_Role($roleId); if (AuthService::getLoggedUser() != null && AuthService::getLoggedUser()->getGroupPath() != null) { $r->setGroupPath(AuthService::getLoggedUser()->getGroupPath()); } AuthService::updateRole($r); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.66"], null); AJXP_XMLWriter::reloadDataNode("", $httpVars["role_id"]); AJXP_XMLWriter::close(); break; case "edit_role": $roleId = SystemTextEncoding::magicDequote($httpVars["role_id"]); $roleGroup = false; $userObject = null; $groupLabel = null; if (strpos($roleId, "AJXP_GRP_") === 0) { $groupPath = substr($roleId, strlen("AJXP_GRP_")); $filteredGroupPath = AuthService::filterBaseGroup($groupPath); $groups = AuthService::listChildrenGroups(AJXP_Utils::forwardSlashDirname($groupPath)); $key = "/" . basename($groupPath); if (!array_key_exists($key, $groups)) { throw new Exception("Cannot find group with this id!"); } $roleId = "AJXP_GRP_" . $filteredGroupPath; $groupLabel = $groups[$key]; $roleGroup = true; } if (strpos($roleId, "AJXP_USR_") === 0) { $usrId = str_replace("AJXP_USR_/", "", $roleId); $userObject = ConfService::getConfStorageImpl()->createUserObject($usrId); if (!AuthService::canAdministrate($userObject)) { throw new Exception("Cant find user!"); } $role = $userObject->personalRole; } else { $role = AuthService::getRole($roleId, $roleGroup); } if ($role === false) { throw new Exception("Cant find role! "); } if (isset($httpVars["format"]) && $httpVars["format"] == "json") { HTMLWriter::charsetHeader("application/json"); $roleData = $role->getDataArray(true); $allReps = ConfService::getRepositoriesList("all", false); $repos = array(); if (!empty($userObject)) { // USER foreach ($allReps as $repositoryId => $repositoryObject) { if (!AuthService::canAssign($repositoryObject, $userObject) || $repositoryObject->isTemplate || $repositoryObject->getAccessType() == "ajxp_conf" && !$userObject->isAdmin() || $repositoryObject->getUniqueUser() != null && $repositoryObject->getUniqueUser() != $userObject->getId()) { continue; } $repos[$repositoryId] = SystemTextEncoding::toUTF8($repositoryObject->getDisplay()); } } else { foreach ($allReps as $repositoryId => $repositoryObject) { if (!AuthService::canAdministrate($repositoryObject)) { continue; } $repos[$repositoryId] = SystemTextEncoding::toUTF8($repositoryObject->getDisplay()); } } // Make sure it's utf8 $data = array("ROLE" => $roleData, "ALL" => array("REPOSITORIES" => $repos)); if (isset($userObject)) { $data["USER"] = array(); $data["USER"]["LOCK"] = $userObject->getLock(); $data["USER"]["PROFILE"] = $userObject->getProfile(); $data["ALL"]["PROFILES"] = array("standard|Standard", "admin|Administrator", "shared|Shared", "guest|Guest"); $data["USER"]["ROLES"] = array_keys($userObject->getRoles()); $data["ALL"]["ROLES"] = array_keys(AuthService::getRolesList(array(), true)); if (isset($userObject->parentRole)) { $data["PARENT_ROLE"] = $userObject->parentRole->getDataArray(); } } else { if (isset($groupPath)) { $data["GROUP"] = array("PATH" => $groupPath, "LABEL" => $groupLabel); } } $scope = "role"; if ($roleGroup) { $scope = "group"; } else { if (isset($userObject)) { $scope = "user"; } } $data["SCOPE_PARAMS"] = array(); $nodes = AJXP_PluginsService::getInstance()->searchAllManifests("//param[contains(@scope,'" . $scope . "')]|//global_param[contains(@scope,'" . $scope . "')]", "node", false, true, true); foreach ($nodes as $node) { $pId = $node->parentNode->parentNode->attributes->getNamedItem("id")->nodeValue; $origName = $node->attributes->getNamedItem("name")->nodeValue; $node->attributes->getNamedItem("name")->nodeValue = "AJXP_REPO_SCOPE_ALL/" . $pId . "/" . $origName; $nArr = array(); foreach ($node->attributes as $attrib) { $nArr[$attrib->nodeName] = AJXP_XMLWriter::replaceAjxpXmlKeywords($attrib->nodeValue); } $data["SCOPE_PARAMS"][] = $nArr; } echo json_encode($data); } break; case "post_json_role": $roleId = SystemTextEncoding::magicDequote($httpVars["role_id"]); $roleGroup = false; $userObject = $usrId = $filteredGroupPath = null; if (strpos($roleId, "AJXP_GRP_") === 0) { $groupPath = substr($roleId, strlen("AJXP_GRP_")); $filteredGroupPath = AuthService::filterBaseGroup($groupPath); $roleId = "AJXP_GRP_" . $filteredGroupPath; $groups = AuthService::listChildrenGroups(AJXP_Utils::forwardSlashDirname($groupPath)); $key = "/" . basename($groupPath); if (!array_key_exists($key, $groups)) { throw new Exception("Cannot find group with this id!"); } $groupLabel = $groups[$key]; $roleGroup = true; } if (strpos($roleId, "AJXP_USR_") === 0) { $usrId = str_replace("AJXP_USR_/", "", $roleId); $userObject = ConfService::getConfStorageImpl()->createUserObject($usrId); if (!AuthService::canAdministrate($userObject)) { throw new Exception("Cannot post role for user " . $usrId); } $originalRole = $userObject->personalRole; } else { // second param = create if not exists. $originalRole = AuthService::getRole($roleId, $roleGroup); } if ($originalRole === false) { throw new Exception("Cant find role! "); } $jsonData = SystemTextEncoding::magicDequote($httpVars["json_data"]); $data = json_decode($jsonData, true); $roleData = $data["ROLE"]; $forms = $data["FORMS"]; $binariesContext = array(); if (isset($userObject)) { $binariesContext = array("USER" => $userObject->getId()); } foreach ($forms as $repoScope => $plugData) { foreach ($plugData as $plugId => $formsData) { $parsed = array(); AJXP_Utils::parseStandardFormParameters($formsData, $parsed, $userObject != null ? $usrId : null, "ROLE_PARAM_", $binariesContext, AJXP_Role::$cypheredPassPrefix); $roleData["PARAMETERS"][$repoScope][$plugId] = $parsed; } } $existingParameters = $originalRole->listParameters(true); $this->mergeExistingParameters($roleData["PARAMETERS"], $existingParameters); if (isset($userObject) && isset($data["USER"]) && isset($data["USER"]["PROFILE"])) { $userObject->setAdmin($data["USER"]["PROFILE"] == "admin"); $userObject->setProfile($data["USER"]["PROFILE"]); } if (isset($data["GROUP_LABEL"]) && isset($groupLabel) && $groupLabel != $data["GROUP_LABEL"]) { ConfService::getConfStorageImpl()->relabelGroup($filteredGroupPath, $data["GROUP_LABEL"]); } if ($currentUserIsGroupAdmin) { // FILTER DATA FOR GROUP ADMINS $params = $this->getEditableParameters(false); foreach ($roleData["PARAMETERS"] as $scope => &$plugsParameters) { foreach ($plugsParameters as $paramPlugin => &$parameters) { foreach ($parameters as $pName => $pValue) { if (!isset($params[$paramPlugin]) || !in_array($pName, $params[$paramPlugin])) { unset($parameters[$pName]); } } if (!count($parameters)) { unset($plugsParameters[$paramPlugin]); } } if (!count($plugsParameters)) { unset($roleData["PARAMETERS"][$scope]); } } // Remerge from parent $roleData["PARAMETERS"] = $originalRole->array_merge_recursive2($originalRole->listParameters(), $roleData["PARAMETERS"]); // Changing Actions is not allowed $roleData["ACTIONS"] = $originalRole->listActionsStates(); } try { $originalRole->bunchUpdate($roleData); if (isset($userObject)) { $userObject->personalRole = $originalRole; $userObject->save("superuser"); } else { AuthService::updateRole($originalRole); } $output = array("ROLE" => $originalRole->getDataArray(true), "SUCCESS" => true); } catch (Exception $e) { $output = array("ERROR" => $e->getMessage()); } HTMLWriter::charsetHeader("application/json"); echo json_encode($output); break; case "user_set_lock": $userId = AJXP_Utils::decodeSecureMagic($httpVars["user_id"]); $lock = $httpVars["lock"] == "true" ? true : false; $lockType = $httpVars["lock_type"]; if (AuthService::userExists($userId)) { $userObject = ConfService::getConfStorageImpl()->createUserObject($userId); if (!AuthService::canAdministrate($userObject)) { throw new Exception("Cannot update user data for " . $userId); } if ($lock) { $userObject->setLock($lockType); } else { $userObject->removeLock(); } $userObject->save("superuser"); } break; case "create_user": if (!isset($httpVars["new_user_login"]) || $httpVars["new_user_login"] == "" || !isset($httpVars["new_user_pwd"]) || $httpVars["new_user_pwd"] == "") { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]); AJXP_XMLWriter::close(); return; } $original_login = SystemTextEncoding::magicDequote($httpVars["new_user_login"]); $new_user_login = AJXP_Utils::sanitize($original_login, AJXP_SANITIZE_EMAILCHARS); if ($original_login != $new_user_login) { throw new Exception(str_replace("%s", $new_user_login, $mess["ajxp_conf.127"])); } if (AuthService::userExists($new_user_login, "w") || AuthService::isReservedUserId($new_user_login)) { throw new Exception($mess["ajxp_conf.43"]); } AuthService::createUser($new_user_login, $httpVars["new_user_pwd"]); $confStorage = ConfService::getConfStorageImpl(); $newUser = $confStorage->createUserObject($new_user_login); $basePath = AuthService::getLoggedUser()->getGroupPath(); if (empty($basePath)) { $basePath = "/"; } if (!empty($httpVars["group_path"])) { $newUser->setGroupPath(rtrim($basePath, "/") . "/" . ltrim($httpVars["group_path"], "/")); } else { $newUser->setGroupPath($basePath); } $newUser->save("superuser"); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.44"], null); AJXP_XMLWriter::reloadDataNode("", $new_user_login); AJXP_XMLWriter::close(); break; case "change_admin_right": $userId = $httpVars["user_id"]; if (!AuthService::userExists($userId)) { throw new Exception("Invalid user id!"); } $confStorage = ConfService::getConfStorageImpl(); $user = $confStorage->createUserObject($userId); if (!AuthService::canAdministrate($user)) { throw new Exception("Cannot update user with id " . $userId); } $user->setAdmin($httpVars["right_value"] == "1" ? true : false); $user->save("superuser"); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.45"] . $httpVars["user_id"], null); AJXP_XMLWriter::reloadDataNode(); AJXP_XMLWriter::close(); break; case "role_update_right": if (!isset($httpVars["role_id"]) || !isset($httpVars["repository_id"]) || !isset($httpVars["right"])) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]); AJXP_XMLWriter::close(); break; } $rId = AJXP_Utils::sanitize($httpVars["role_id"]); $role = AuthService::getRole($rId); if ($role === false) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"] . "(" . $rId . ")"); AJXP_XMLWriter::close(); break; } $role->setAcl(AJXP_Utils::sanitize($httpVars["repository_id"], AJXP_SANITIZE_ALPHANUM), AJXP_Utils::sanitize($httpVars["right"], AJXP_SANITIZE_ALPHANUM)); AuthService::updateRole($role); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.46"] . $httpVars["role_id"], null); AJXP_XMLWriter::close(); break; case "user_update_right": if (!isset($httpVars["user_id"]) || !isset($httpVars["repository_id"]) || !isset($httpVars["right"]) || !AuthService::userExists($httpVars["user_id"])) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]); print "<update_checkboxes user_id=\"" . $httpVars["user_id"] . "\" repository_id=\"" . $httpVars["repository_id"] . "\" read=\"old\" write=\"old\"/>"; AJXP_XMLWriter::close(); return; } $confStorage = ConfService::getConfStorageImpl(); $userId = AJXP_Utils::sanitize($httpVars["user_id"], AJXP_SANITIZE_EMAILCHARS); $user = $confStorage->createUserObject($userId); if (!AuthService::canAdministrate($user)) { throw new Exception("Cannot update user with id " . $userId); } $user->personalRole->setAcl(AJXP_Utils::sanitize($httpVars["repository_id"], AJXP_SANITIZE_ALPHANUM), AJXP_Utils::sanitize($httpVars["right"], AJXP_SANITIZE_ALPHANUM)); $user->save(); $loggedUser = AuthService::getLoggedUser(); if ($loggedUser->getId() == $user->getId()) { AuthService::updateUser($user); } AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.46"] . $httpVars["user_id"], null); print "<update_checkboxes user_id=\"" . $httpVars["user_id"] . "\" repository_id=\"" . $httpVars["repository_id"] . "\" read=\"" . $user->canRead($httpVars["repository_id"]) . "\" write=\"" . $user->canWrite($httpVars["repository_id"]) . "\"/>"; AJXP_XMLWriter::reloadRepositoryList(); AJXP_XMLWriter::close(); return; break; case "user_update_group": $userSelection = new UserSelection(); $userSelection->initFromHttpVars($httpVars); $dir = $httpVars["dir"]; $dest = $httpVars["dest"]; if (isset($httpVars["group_path"])) { // API Case $groupPath = $httpVars["group_path"]; } else { if (strpos($dir, "/data/users", 0) !== 0 || strpos($dest, "/data/users", 0) !== 0) { break; } $groupPath = substr($dest, strlen("/data/users")); } $confStorage = ConfService::getConfStorageImpl(); $userId = null; $usersMoved = array(); $basePath = AuthService::getLoggedUser() != null ? AuthService::getLoggedUser()->getGroupPath() : "/"; if (empty($basePath)) { $basePath = "/"; } if (!empty($groupPath)) { $targetPath = rtrim($basePath, "/") . "/" . ltrim($groupPath, "/"); } else { $targetPath = $basePath; } foreach ($userSelection->getFiles() as $selectedUser) { $userId = basename($selectedUser); if (!AuthService::userExists($userId)) { continue; } $user = $confStorage->createUserObject($userId); if (!AuthService::canAdministrate($user)) { continue; } $user->setGroupPath($targetPath, true); $user->save("superuser"); $usersMoved[] = $user->getId(); } AJXP_XMLWriter::header(); if (count($usersMoved)) { AJXP_XMLWriter::sendMessage(count($usersMoved) . " user(s) successfully moved to " . $targetPath, null); AJXP_XMLWriter::reloadDataNode($dest, $userId); AJXP_XMLWriter::reloadDataNode(); } else { AJXP_XMLWriter::sendMessage(null, "No users moved, there must have been something wrong."); } AJXP_XMLWriter::close(); break; case "user_add_role": case "user_delete_role": if (!isset($httpVars["user_id"]) || !isset($httpVars["role_id"]) || !AuthService::userExists($httpVars["user_id"]) || !AuthService::getRole($httpVars["role_id"])) { throw new Exception($mess["ajxp_conf.61"]); } if ($action == "user_add_role") { $act = "add"; $messId = "73"; } else { $act = "remove"; $messId = "74"; } $this->updateUserRole(AJXP_Utils::sanitize($httpVars["user_id"], AJXP_SANITIZE_EMAILCHARS), $httpVars["role_id"], $act); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf." . $messId] . $httpVars["user_id"], null); AJXP_XMLWriter::close(); return; break; case "user_update_role": $confStorage = ConfService::getConfStorageImpl(); $selection = new UserSelection(); $selection->initFromHttpVars($httpVars); $files = $selection->getFiles(); $detectedRoles = array(); $roleId = null; if (isset($httpVars["role_id"]) && isset($httpVars["update_role_action"])) { $update = $httpVars["update_role_action"]; $roleId = $httpVars["role_id"]; if (AuthService::getRole($roleId) === false) { throw new Exception("Invalid role id"); } } foreach ($files as $index => $file) { $userId = basename($file); if (isset($update)) { $userObject = $this->updateUserRole($userId, $roleId, $update); } else { $userObject = $confStorage->createUserObject($userId); if (!AuthService::canAdministrate($userObject)) { continue; } } if ($userObject->hasParent()) { unset($files[$index]); continue; } $userRoles = $userObject->getRoles(); foreach ($userRoles as $roleIndex => $bool) { if (!isset($detectedRoles[$roleIndex])) { $detectedRoles[$roleIndex] = 0; } if ($bool === true) { $detectedRoles[$roleIndex]++; } } } $count = count($files); AJXP_XMLWriter::header("admin_data"); print "<user><ajxp_roles>"; foreach ($detectedRoles as $roleId => $roleCount) { if ($roleCount < $count) { continue; } print "<role id=\"{$roleId}\"/>"; } print "</ajxp_roles></user>"; print "<ajxp_roles>"; foreach (AuthService::getRolesList(array(), !$this->listSpecialRoles) as $roleId => $roleObject) { print "<role id=\"{$roleId}\"/>"; } print "</ajxp_roles>"; AJXP_XMLWriter::close("admin_data"); break; case "save_custom_user_params": $userId = AJXP_Utils::sanitize($httpVars["user_id"], AJXP_SANITIZE_EMAILCHARS); if ($userId == $loggedUser->getId()) { $user = $loggedUser; } else { $confStorage = ConfService::getConfStorageImpl(); $user = $confStorage->createUserObject($userId); } if (!AuthService::canAdministrate($user)) { throw new Exception("Cannot update user with id " . $userId); } $custom = $user->getPref("CUSTOM_PARAMS"); if (!is_array($custom)) { $custom = array(); } $options = $custom; $this->parseParameters($httpVars, $options, $userId, false, $custom); $custom = $options; $user->setPref("CUSTOM_PARAMS", $custom); $user->save(); if ($loggedUser->getId() == $user->getId()) { AuthService::updateUser($user); } AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.47"] . $httpVars["user_id"], null); AJXP_XMLWriter::close(); break; case "save_repository_user_params": $userId = AJXP_Utils::sanitize($httpVars["user_id"], AJXP_SANITIZE_EMAILCHARS); if ($userId == $loggedUser->getId()) { $user = $loggedUser; } else { $confStorage = ConfService::getConfStorageImpl(); $user = $confStorage->createUserObject($userId); } if (!AuthService::canAdministrate($user)) { throw new Exception("Cannot update user with id " . $userId); } $wallet = $user->getPref("AJXP_WALLET"); if (!is_array($wallet)) { $wallet = array(); } $repoID = $httpVars["repository_id"]; if (!array_key_exists($repoID, $wallet)) { $wallet[$repoID] = array(); } $options = $wallet[$repoID]; $existing = $options; $this->parseParameters($httpVars, $options, $userId, false, $existing); $wallet[$repoID] = $options; $user->setPref("AJXP_WALLET", $wallet); $user->save(); if ($loggedUser->getId() == $user->getId()) { AuthService::updateUser($user); } AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.47"] . $httpVars["user_id"], null); AJXP_XMLWriter::close(); break; case "update_user_pwd": if (!isset($httpVars["user_id"]) || !isset($httpVars["user_pwd"]) || !AuthService::userExists($httpVars["user_id"]) || trim($httpVars["user_pwd"]) == "") { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]); AJXP_XMLWriter::close(); return; } $userId = AJXP_Utils::sanitize($httpVars["user_id"], AJXP_SANITIZE_EMAILCHARS); $user = ConfService::getConfStorageImpl()->createUserObject($userId); if (!AuthService::canAdministrate($user)) { throw new Exception("Cannot update user data for " . $userId); } $res = AuthService::updatePassword($userId, $httpVars["user_pwd"]); AJXP_XMLWriter::header(); if ($res === true) { AJXP_XMLWriter::sendMessage($mess["ajxp_conf.48"] . $userId, null); } else { AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.49"] . " : {$res}"); } AJXP_XMLWriter::close(); break; case "save_user_preference": if (!isset($httpVars["user_id"]) || !AuthService::userExists($httpVars["user_id"])) { throw new Exception($mess["ajxp_conf.61"]); } $userId = AJXP_Utils::sanitize($httpVars["user_id"], AJXP_SANITIZE_EMAILCHARS); if ($userId == $loggedUser->getId()) { $userObject = $loggedUser; } else { $confStorage = ConfService::getConfStorageImpl(); $userObject = $confStorage->createUserObject($userId); } if (!AuthService::canAdministrate($userObject)) { throw new Exception("Cannot update user data for " . $userId); } $i = 0; while (isset($httpVars["pref_name_" . $i]) && isset($httpVars["pref_value_" . $i])) { $prefName = AJXP_Utils::sanitize($httpVars["pref_name_" . $i], AJXP_SANITIZE_ALPHANUM); $prefValue = AJXP_Utils::sanitize(SystemTextEncoding::magicDequote($httpVars["pref_value_" . $i])); if ($prefName == "password") { continue; } if ($prefName != "pending_folder" && $userObject == null) { $i++; continue; } $userObject->setPref($prefName, $prefValue); $userObject->save("user"); $i++; } AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage("Succesfully saved user preference", null); AJXP_XMLWriter::close(); break; case "get_drivers_definition": AJXP_XMLWriter::header("drivers", array("allowed" => $currentUserIsGroupAdmin ? "false" : "true")); print AJXP_XMLWriter::replaceAjxpXmlKeywords(ConfService::availableDriversToXML("param", "", true)); AJXP_XMLWriter::close("drivers"); break; case "get_templates_definition": AJXP_XMLWriter::header("repository_templates"); $count = 0; $repositories = ConfService::listRepositoriesWithCriteria(array("isTemplate" => '1'), $count); foreach ($repositories as $repo) { if (!$repo->isTemplate) { continue; } $repoId = $repo->getUniqueId(); $repoLabel = SystemTextEncoding::toUTF8($repo->getDisplay()); $repoType = $repo->getAccessType(); print "<template repository_id=\"{$repoId}\" repository_label=\"{$repoLabel}\" repository_type=\"{$repoType}\">"; foreach ($repo->getOptionsDefined() as $optionName) { print "<option name=\"{$optionName}\"/>"; } print "</template>"; } AJXP_XMLWriter::close("repository_templates"); break; case "create_repository": $repDef = $httpVars; $isTemplate = isset($httpVars["sf_checkboxes_active"]); unset($repDef["get_action"]); unset($repDef["sf_checkboxes_active"]); if (isset($httpVars["json_data"])) { $repDef = json_decode(SystemTextEncoding::magicDequote($httpVars["json_data"]), true); $options = $repDef["DRIVER_OPTIONS"]; } else { $options = array(); $this->parseParameters($repDef, $options, null, true); } if (count($options)) { $repDef["DRIVER_OPTIONS"] = $options; unset($repDef["DRIVER_OPTIONS"]["AJXP_GROUP_PATH_PARAMETER"]); } if (strstr($repDef["DRIVER"], "ajxp_template_") !== false) { $templateId = substr($repDef["DRIVER"], 14); $templateRepo = ConfService::getRepositoryById($templateId); $newRep = $templateRepo->createTemplateChild($repDef["DISPLAY"], $repDef["DRIVER_OPTIONS"]); if (isset($repDef["AJXP_SLUG"])) { $newRep->setSlug($repDef["AJXP_SLUG"]); } } else { if ($currentUserIsGroupAdmin) { throw new Exception("You are not allowed to create a workspace from a driver. Use a template instead."); } $pServ = AJXP_PluginsService::getInstance(); $driver = $pServ->getPluginByTypeName("access", $repDef["DRIVER"]); $newRep = ConfService::createRepositoryFromArray(0, $repDef); $testFile = $driver->getBaseDir() . "/test." . $newRep->getAccessType() . "Access.php"; if (!$isTemplate && is_file($testFile)) { //chdir(AJXP_TESTS_FOLDER."/plugins"); $className = $newRep->getAccessType() . "AccessTest"; if (!class_exists($className)) { include $testFile; } $class = new $className(); $result = $class->doRepositoryTest($newRep); if (!$result) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $class->failedInfo); AJXP_XMLWriter::close(); return; } } // Apply default metasource if any if ($driver != null && $driver->getConfigs() != null) { $confs = $driver->getConfigs(); if (!empty($confs["DEFAULT_METASOURCES"])) { $metaIds = AJXP_Utils::parseCSL($confs["DEFAULT_METASOURCES"]); $metaSourceOptions = array(); foreach ($metaIds as $metaID) { $metaPlug = $pServ->getPluginById($metaID); if ($metaPlug == null) { continue; } $pNodes = $metaPlug->getManifestRawContent("//param[@default]", "nodes"); $defaultParams = array(); foreach ($pNodes as $domNode) { $defaultParams[$domNode->getAttribute("name")] = $domNode->getAttribute("default"); } $metaSourceOptions[$metaID] = $defaultParams; } $newRep->addOption("META_SOURCES", $metaSourceOptions); } } } if ($this->repositoryExists($newRep->getDisplay())) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.50"]); AJXP_XMLWriter::close(); return; } if ($isTemplate) { $newRep->isTemplate = true; } if ($currentUserIsGroupAdmin) { $newRep->setGroupPath(AuthService::getLoggedUser()->getGroupPath()); } else { if (!empty($options["AJXP_GROUP_PATH_PARAMETER"])) { $basePath = "/"; if (AuthService::getLoggedUser() != null && AuthService::getLoggedUser()->getGroupPath() != null) { $basePath = AuthService::getLoggedUser()->getGroupPath(); } $value = AJXP_Utils::securePath(rtrim($basePath, "/") . "/" . ltrim($options["AJXP_GROUP_PATH_PARAMETER"], "/")); $newRep->setGroupPath($value); } } $res = ConfService::addRepository($newRep); AJXP_XMLWriter::header(); if ($res == -1) { AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.51"]); } else { $loggedUser = AuthService::getLoggedUser(); $loggedUser->personalRole->setAcl($newRep->getUniqueId(), "rw"); $loggedUser->recomputeMergedRole(); $loggedUser->save("superuser"); AuthService::updateUser($loggedUser); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.52"], null); AJXP_XMLWriter::reloadDataNode("", $newRep->getUniqueId()); AJXP_XMLWriter::reloadRepositoryList(); } AJXP_XMLWriter::close(); break; case "edit_repository": $repId = $httpVars["repository_id"]; $repository = ConfService::getRepositoryById($repId); if ($repository == null) { throw new Exception("Cannot find workspace with id {$repId}"); } if (!AuthService::canAdministrate($repository)) { throw new Exception("You are not allowed to edit this workspace!"); } $pServ = AJXP_PluginsService::getInstance(); $plug = $pServ->getPluginById("access." . $repository->accessType); if ($plug == null) { throw new Exception("Cannot find access driver (" . $repository->accessType . ") for workspace!"); } AJXP_XMLWriter::header("admin_data"); $slug = $repository->getSlug(); if ($slug == "" && $repository->isWriteable()) { $repository->setSlug(); ConfService::replaceRepository($repId, $repository); } if (AuthService::getLoggedUser() != null && AuthService::getLoggedUser()->getGroupPath() != null) { $rgp = $repository->getGroupPath(); if ($rgp == null) { $rgp = "/"; } if (strlen($rgp) < strlen(AuthService::getLoggedUser()->getGroupPath())) { $repository->setWriteable(false); } } $nested = array(); $definitions = $plug->getConfigsDefinitions(); print "<repository index=\"{$repId}\""; foreach ($repository as $name => $option) { if (strstr($name, " ") > -1) { continue; } if (!is_array($option)) { if (is_bool($option)) { $option = $option ? "true" : "false"; } print " {$name}=\"" . SystemTextEncoding::toUTF8(AJXP_Utils::xmlEntities($option)) . "\" "; } else { if (is_array($option)) { $nested[] = $option; } } } if (count($nested)) { print ">"; foreach ($nested as $option) { foreach ($option as $key => $optValue) { if (is_array($optValue) && count($optValue)) { print "<param name=\"{$key}\"><![CDATA[" . json_encode($optValue) . "]]></param>"; } else { if (is_object($optValue)) { print "<param name=\"{$key}\"><![CDATA[" . json_encode($optValue) . "]]></param>"; } else { if (is_bool($optValue)) { $optValue = $optValue ? "true" : "false"; } else { if (isset($definitions[$key]) && $definitions[$key]["type"] == "password" && !empty($optValue)) { $optValue = "__AJXP_VALUE_SET__"; } } $optValue = AJXP_Utils::xmlEntities($optValue, true); print "<param name=\"{$key}\" value=\"{$optValue}\"/>"; } } } } // Add SLUG if (!$repository->isTemplate) { print "<param name=\"AJXP_SLUG\" value=\"" . $repository->getSlug() . "\"/>"; } if ($repository->getGroupPath() != null) { $basePath = "/"; if (AuthService::getLoggedUser() != null && AuthService::getLoggedUser()->getGroupPath() != null) { $basePath = AuthService::getLoggedUser()->getGroupPath(); } $groupPath = $repository->getGroupPath(); if ($basePath != "/") { $groupPath = substr($repository->getGroupPath(), strlen($basePath)); } print "<param name=\"AJXP_GROUP_PATH_PARAMETER\" value=\"" . $groupPath . "\"/>"; } print "</repository>"; } else { print "/>"; } if ($repository->hasParent()) { $parent = ConfService::getRepositoryById($repository->getParentId()); if (isset($parent) && $parent->isTemplate) { $parentLabel = $parent->getDisplay(); $parentType = $parent->getAccessType(); print "<template repository_id=\"" . $repository->getParentId() . "\" repository_label=\"{$parentLabel}\" repository_type=\"{$parentType}\">"; foreach ($parent->getOptionsDefined() as $parentOptionName) { print "<option name=\"{$parentOptionName}\"/>"; } print "</template>"; } } $manifest = $plug->getManifestRawContent("server_settings/param"); $manifest = AJXP_XMLWriter::replaceAjxpXmlKeywords($manifest); print "<ajxpdriver name=\"" . $repository->accessType . "\">{$manifest}</ajxpdriver>"; print "<metasources>"; $metas = $pServ->getPluginsByType("metastore"); $metas = array_merge($metas, $pServ->getPluginsByType("meta")); $metas = array_merge($metas, $pServ->getPluginsByType("index")); foreach ($metas as $metaPlug) { print "<meta id=\"" . $metaPlug->getId() . "\" label=\"" . AJXP_Utils::xmlEntities($metaPlug->getManifestLabel()) . "\">"; $manifest = $metaPlug->getManifestRawContent("server_settings/param"); $manifest = AJXP_XMLWriter::replaceAjxpXmlKeywords($manifest); print $manifest; print "</meta>"; } print "</metasources>"; AJXP_XMLWriter::close("admin_data"); return; break; case "edit_repository_label": case "edit_repository_data": $repId = $httpVars["repository_id"]; $repo = ConfService::getRepositoryById($repId); if (!$repo->isWriteable()) { throw new Exception("This workspace is not writeable. Please edit directly the conf/bootstrap_repositories.php file."); } $res = 0; if (isset($httpVars["newLabel"])) { $newLabel = AJXP_Utils::sanitize(AJXP_Utils::securePath($httpVars["newLabel"]), AJXP_SANITIZE_HTML); if ($this->repositoryExists($newLabel)) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.50"]); AJXP_XMLWriter::close(); return; } $repo->setDisplay($newLabel); $res = ConfService::replaceRepository($repId, $repo); } else { $options = array(); $existing = $repo->getOptionsDefined(); $existingValues = array(); foreach ($existing as $exK) { $existingValues[$exK] = $repo->getOption($exK, true); } $this->parseParameters($httpVars, $options, null, true, $existingValues); if (count($options)) { foreach ($options as $key => $value) { if ($key == "AJXP_SLUG") { $repo->setSlug($value); continue; } elseif ($key == "AJXP_GROUP_PATH_PARAMETER") { $basePath = "/"; if (AuthService::getLoggedUser() != null && AuthService::getLoggedUser()->getGroupPath() != null) { $basePath = AuthService::getLoggedUser()->getGroupPath(); } $value = AJXP_Utils::securePath(rtrim($basePath, "/") . "/" . ltrim($value, "/")); $repo->setGroupPath($value); continue; } $repo->addOption($key, $value); } } if ($repo->getOption("DEFAULT_RIGHTS")) { $gp = $repo->getGroupPath(); if (empty($gp) || $gp == "/") { $defRole = AuthService::getRole("ROOT_ROLE"); } else { $defRole = AuthService::getRole("AJXP_GRP_" . $gp, true); } if ($defRole !== false) { $defRole->setAcl($repId, $repo->getOption("DEFAULT_RIGHTS")); AuthService::updateRole($defRole); } } if (is_file(AJXP_TESTS_FOLDER . "/plugins/test.ajxp_" . $repo->getAccessType() . ".php")) { chdir(AJXP_TESTS_FOLDER . "/plugins"); include AJXP_TESTS_FOLDER . "/plugins/test.ajxp_" . $repo->getAccessType() . ".php"; $className = "ajxp_" . $repo->getAccessType(); $class = new $className(); $result = $class->doRepositoryTest($repo); if (!$result) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $class->failedInfo); AJXP_XMLWriter::close(); return; } } ConfService::replaceRepository($repId, $repo); } AJXP_XMLWriter::header(); if ($res == -1) { AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.53"]); } else { AJXP_XMLWriter::sendMessage($mess["ajxp_conf.54"], null); if (isset($httpVars["newLabel"])) { AJXP_XMLWriter::reloadDataNode("", $repId); } AJXP_XMLWriter::reloadRepositoryList(); } AJXP_XMLWriter::close(); break; case "meta_source_add": $repId = $httpVars["repository_id"]; $repo = ConfService::getRepositoryById($repId); if (!is_object($repo)) { throw new Exception("Invalid workspace id! {$repId}"); } $metaSourceType = AJXP_Utils::sanitize($httpVars["new_meta_source"], AJXP_SANITIZE_ALPHANUM); if (isset($httpVars["json_data"])) { $options = json_decode(SystemTextEncoding::magicDequote($httpVars["json_data"]), true); } else { $options = array(); $this->parseParameters($httpVars, $options, null, true); } $repoOptions = $repo->getOption("META_SOURCES"); if (is_array($repoOptions) && isset($repoOptions[$metaSourceType])) { throw new Exception($mess["ajxp_conf.55"]); } if (!is_array($repoOptions)) { $repoOptions = array(); } $repoOptions[$metaSourceType] = $options; uksort($repoOptions, array($this, "metaSourceOrderingFunction")); $repo->addOption("META_SOURCES", $repoOptions); ConfService::replaceRepository($repId, $repo); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.56"], null); AJXP_XMLWriter::close(); break; case "meta_source_delete": $repId = $httpVars["repository_id"]; $repo = ConfService::getRepositoryById($repId); if (!is_object($repo)) { throw new Exception("Invalid workspace id! {$repId}"); } $metaSourceId = $httpVars["plugId"]; $repoOptions = $repo->getOption("META_SOURCES"); if (is_array($repoOptions) && array_key_exists($metaSourceId, $repoOptions)) { unset($repoOptions[$metaSourceId]); uksort($repoOptions, array($this, "metaSourceOrderingFunction")); $repo->addOption("META_SOURCES", $repoOptions); ConfService::replaceRepository($repId, $repo); } else { throw new Exception("Cannot find meta source " . $metaSourceId); } AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.57"], null); AJXP_XMLWriter::close(); break; case "meta_source_edit": $repId = $httpVars["repository_id"]; $repo = ConfService::getRepositoryById($repId); if (!is_object($repo)) { throw new Exception("Invalid workspace id! {$repId}"); } $metaSourceId = $httpVars["plugId"]; $repoOptions = $repo->getOption("META_SOURCES"); if (!is_array($repoOptions)) { $repoOptions = array(); } if (isset($httpVars["json_data"])) { $options = json_decode(SystemTextEncoding::magicDequote($httpVars["json_data"]), true); } else { $options = array(); $this->parseParameters($httpVars, $options, null, true); } if (isset($repoOptions[$metaSourceId])) { $this->mergeExistingParameters($options, $repoOptions[$metaSourceId]); } $repoOptions[$metaSourceId] = $options; uksort($repoOptions, array($this, "metaSourceOrderingFunction")); $repo->addOption("META_SOURCES", $repoOptions); ConfService::replaceRepository($repId, $repo); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.58"], null); AJXP_XMLWriter::close(); break; case "delete": // REST API mapping if (isset($httpVars["data_type"])) { switch ($httpVars["data_type"]) { case "repository": $httpVars["repository_id"] = basename($httpVars["data_id"]); break; case "role": $httpVars["role_id"] = basename($httpVars["data_id"]); break; case "user": $httpVars["user_id"] = basename($httpVars["data_id"]); break; case "group": $httpVars["group"] = "/data/users" . $httpVars["data_id"]; break; default: break; } unset($httpVars["data_type"]); unset($httpVars["data_id"]); } if (isset($httpVars["repository_id"])) { $repId = $httpVars["repository_id"]; $repo = ConfService::getRepositoryById($repId); if (!is_object($repo)) { $res = -1; } else { $res = ConfService::deleteRepository($repId); } AJXP_XMLWriter::header(); if ($res == -1) { AJXP_XMLWriter::sendMessage(null, $mess[427]); } else { AJXP_XMLWriter::sendMessage($mess["ajxp_conf.59"], null); AJXP_XMLWriter::reloadDataNode(); AJXP_XMLWriter::reloadRepositoryList(); } AJXP_XMLWriter::close(); return; } else { if (isset($httpVars["role_id"])) { $roleId = $httpVars["role_id"]; if (AuthService::getRole($roleId) === false) { throw new Exception($mess["ajxp_conf.67"]); } AuthService::deleteRole($roleId); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.68"], null); AJXP_XMLWriter::reloadDataNode(); AJXP_XMLWriter::close(); } else { if (isset($httpVars["group"])) { $groupPath = $httpVars["group"]; $basePath = substr(AJXP_Utils::forwardSlashDirname($groupPath), strlen("/data/users")); $gName = basename($groupPath); AuthService::deleteGroup($basePath, $gName); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.128"], null); AJXP_XMLWriter::reloadDataNode(); AJXP_XMLWriter::close(); } else { if (!isset($httpVars["user_id"]) || $httpVars["user_id"] == "" || AuthService::isReservedUserId($httpVars["user_id"]) || $loggedUser->getId() == $httpVars["user_id"]) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]); AJXP_XMLWriter::close(); } AuthService::deleteUser($httpVars["user_id"]); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.60"], null); AJXP_XMLWriter::reloadDataNode(); AJXP_XMLWriter::close(); } } } break; case "get_plugin_manifest": $ajxpPlugin = AJXP_PluginsService::getInstance()->getPluginById($httpVars["plugin_id"]); AJXP_XMLWriter::header("admin_data"); $fullManifest = $ajxpPlugin->getManifestRawContent("", "xml"); $xPath = new DOMXPath($fullManifest->ownerDocument); $addParams = ""; $instancesDefinitions = array(); $pInstNodes = $xPath->query("server_settings/global_param[contains(@type, 'plugin_instance:')]"); foreach ($pInstNodes as $pInstNode) { $type = $pInstNode->getAttribute("type"); $instType = str_replace("plugin_instance:", "", $type); $fieldName = $pInstNode->getAttribute("name"); $pInstNode->setAttribute("type", "group_switch:" . $fieldName); $typePlugs = AJXP_PluginsService::getInstance()->getPluginsByType($instType); foreach ($typePlugs as $typePlug) { if ($typePlug->getId() == "auth.multi") { continue; } $checkErrorMessage = ""; try { $typePlug->performChecks(); } catch (Exception $e) { $checkErrorMessage = " (Warning : " . $e->getMessage() . ")"; } $tParams = AJXP_XMLWriter::replaceAjxpXmlKeywords($typePlug->getManifestRawContent("server_settings/param[not(@group_switch_name)]")); $addParams .= '<global_param group_switch_name="' . $fieldName . '" name="instance_name" group_switch_label="' . $typePlug->getManifestLabel() . $checkErrorMessage . '" group_switch_value="' . $typePlug->getId() . '" default="' . $typePlug->getId() . '" type="hidden"/>'; $addParams .= str_replace("<param", "<global_param group_switch_name=\"{$fieldName}\" group_switch_label=\"" . $typePlug->getManifestLabel() . $checkErrorMessage . "\" group_switch_value=\"" . $typePlug->getId() . "\" ", $tParams); $addParams .= str_replace("<param", "<global_param", AJXP_XMLWriter::replaceAjxpXmlKeywords($typePlug->getManifestRawContent("server_settings/param[@group_switch_name]"))); $addParams .= AJXP_XMLWriter::replaceAjxpXmlKeywords($typePlug->getManifestRawContent("server_settings/global_param")); $instancesDefs = $typePlug->getConfigsDefinitions(); if (!empty($instancesDefs) && is_array($instancesDefs)) { foreach ($instancesDefs as $defKey => $defData) { $instancesDefinitions[$fieldName . "/" . $defKey] = $defData; } } } } $allParams = AJXP_XMLWriter::replaceAjxpXmlKeywords($fullManifest->ownerDocument->saveXML($fullManifest)); $allParams = str_replace('type="plugin_instance:', 'type="group_switch:', $allParams); $allParams = str_replace("</server_settings>", $addParams . "</server_settings>", $allParams); echo $allParams; $definitions = $instancesDefinitions; $configsDefs = $ajxpPlugin->getConfigsDefinitions(); if (is_array($configsDefs)) { $definitions = array_merge($configsDefs, $instancesDefinitions); } $values = $ajxpPlugin->getConfigs(); if (!is_array($values)) { $values = array(); } echo "<plugin_settings_values>"; // First flatten keys $flattenedKeys = array(); foreach ($values as $key => $value) { $type = $definitions[$key]["type"]; if ((strpos($type, "group_switch:") === 0 || strpos($type, "plugin_instance:") === 0) && is_array($value)) { $res = array(); $this->flattenKeyValues($res, $definitions, $value, $key); $flattenedKeys += $res; // Replace parent key by new flat value $values[$key] = $flattenedKeys[$key]; } } $values += $flattenedKeys; foreach ($values as $key => $value) { $attribute = true; $type = $definitions[$key]["type"]; if ($type == "array" && is_array($value)) { $value = implode(",", $value); } else { if ($type == "boolean") { $value = $value === true || $value === "true" || $value == 1 ? "true" : "false"; } else { if ($type == "textarea") { $attribute = false; } else { if ($type == "password" && !empty($value)) { $value = "__AJXP_VALUE_SET__"; } } } } if ($attribute) { echo "<param name=\"{$key}\" value=\"" . AJXP_Utils::xmlEntities($value) . "\"/>"; } else { echo "<param name=\"{$key}\" cdatavalue=\"true\"><![CDATA[" . $value . "]]></param>"; } } if ($ajxpPlugin->getType() != "core") { echo "<param name=\"AJXP_PLUGIN_ENABLED\" value=\"" . ($ajxpPlugin->isEnabled() ? "true" : "false") . "\"/>"; } echo "</plugin_settings_values>"; echo "<plugin_doc><![CDATA[<p>" . $ajxpPlugin->getPluginInformationHTML("Charles du Jeu", "http://pyd.io/plugins/") . "</p>"; if (file_exists($ajxpPlugin->getBaseDir() . "/plugin_doc.html")) { echo file_get_contents($ajxpPlugin->getBaseDir() . "/plugin_doc.html"); } echo "]]></plugin_doc>"; AJXP_XMLWriter::close("admin_data"); break; case "run_plugin_action": $options = array(); $this->parseParameters($httpVars, $options, null, true); $pluginId = $httpVars["action_plugin_id"]; if (isset($httpVars["button_key"])) { $options = $options[$httpVars["button_key"]]; } $plugin = AJXP_PluginsService::getInstance()->softLoad($pluginId, $options); if (method_exists($plugin, $httpVars["action_plugin_method"])) { try { $res = call_user_func(array($plugin, $httpVars["action_plugin_method"]), $options); } catch (Exception $e) { echo "ERROR:" . $e->getMessage(); break; } echo $res; } else { echo 'ERROR: Plugin ' . $httpVars["action_plugin_id"] . ' does not implement ' . $httpVars["action_plugin_method"] . ' method!'; } break; case "edit_plugin_options": $options = array(); $this->parseParameters($httpVars, $options, null, true); $confStorage = ConfService::getConfStorageImpl(); list($pType, $pName) = explode(".", $httpVars["plugin_id"]); $existing = $confStorage->loadPluginConfig($pType, $pName); $this->mergeExistingParameters($options, $existing); $confStorage->savePluginConfig($httpVars["plugin_id"], $options); AJXP_PluginsService::clearPluginsCache(); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.97"], null); AJXP_XMLWriter::close(); break; case "generate_api_docs": PydioSdkGenerator::analyzeRegistry(isset($httpVars["version"]) ? $httpVars["version"] : AJXP_VERSION); break; // Action for update all Pydio's user from ldap in CLI mode // Action for update all Pydio's user from ldap in CLI mode case "cli_update_user_list": if (php_sapi_name() == "cli") { $progressBar = new AJXP_ProgressBarCLI(); $countCallback = array($progressBar, "init"); $loopCallback = array($progressBar, "update"); AuthService::listUsers("/", null, -1, -1, true, true, $countCallback, $loopCallback); } break; default: break; } return; }
/** * @param Array $httpVars * @param Repository $repository * @param AbstractAccessDriver $accessDriver * @param null $uniqueUser * @throws Exception * @return int|Repository */ public function createSharedRepository($httpVars, $repository, $accessDriver, $uniqueUser = null) { // ERRORS // 100 : missing args // 101 : repository label already exists // 102 : user already exists // 103 : current user is not allowed to share // SUCCESS // 200 if (!isset($httpVars["repo_label"]) || $httpVars["repo_label"] == "") { return 100; } $foldersharing = $this->getFilteredOption("ENABLE_FOLDER_SHARING", $this->repository->getId()); if (isset($foldersharing) && $foldersharing === false) { return 103; } $loggedUser = AuthService::getLoggedUser(); $actRights = $loggedUser->mergedRole->listActionsStatesFor($repository); if (isset($actRights["share"]) && $actRights["share"] === false) { return 103; } $users = array(); $uRights = array(); $uPasses = array(); $groups = array(); $index = 0; $prefix = $this->getFilteredOption("SHARED_USERS_TMP_PREFIX", $this->repository->getId()); while (isset($httpVars["user_" . $index])) { $eType = $httpVars["entry_type_" . $index]; $rightString = ($httpVars["right_read_" . $index] == "true" ? "r" : "") . ($httpVars["right_write_" . $index] == "true" ? "w" : ""); if ($this->watcher !== false) { $uWatch = $httpVars["right_watch_" . $index] == "true" ? true : false; } if (empty($rightString)) { $index++; continue; } if ($eType == "user") { $u = AJXP_Utils::decodeSecureMagic($httpVars["user_" . $index], AJXP_SANITIZE_EMAILCHARS); if (!AuthService::userExists($u) && !isset($httpVars["user_pass_" . $index])) { $index++; continue; } else { if (AuthService::userExists($u) && isset($httpVars["user_pass_" . $index])) { throw new Exception("User {$u} already exists, please choose another name."); } } if (!AuthService::userExists($u, "r") && !empty($prefix) && strpos($u, $prefix) !== 0) { $u = $prefix . $u; } $users[] = $u; } else { $u = AJXP_Utils::decodeSecureMagic($httpVars["user_" . $index]); if (strpos($u, "/AJXP_TEAM/") === 0) { $confDriver = ConfService::getConfStorageImpl(); if (method_exists($confDriver, "teamIdToUsers")) { $teamUsers = $confDriver->teamIdToUsers(str_replace("/AJXP_TEAM/", "", $u)); foreach ($teamUsers as $userId) { $users[] = $userId; $uRights[$userId] = $rightString; if ($this->watcher !== false) { $uWatches[$userId] = $uWatch; } } } $index++; continue; } else { $groups[] = $u; } } $uRights[$u] = $rightString; $uPasses[$u] = isset($httpVars["user_pass_" . $index]) ? $httpVars["user_pass_" . $index] : ""; if ($this->watcher !== false) { $uWatches[$u] = $uWatch; } $index++; } $label = AJXP_Utils::decodeSecureMagic($httpVars["repo_label"]); $description = AJXP_Utils::decodeSecureMagic($httpVars["repo_description"]); if (isset($httpVars["repository_id"])) { $editingRepo = ConfService::getRepositoryById($httpVars["repository_id"]); } // CHECK USER & REPO DOES NOT ALREADY EXISTS if ($this->getFilteredOption("AVOID_SHARED_FOLDER_SAME_LABEL", $this->repository->getId()) == true) { $repos = ConfService::getRepositoriesList(); foreach ($repos as $obj) { if ($obj->getDisplay() == $label && (!isset($editingRepo) || $editingRepo != $obj)) { return 101; } } } $confDriver = ConfService::getConfStorageImpl(); foreach ($users as $userName) { if (AuthService::userExists($userName)) { // check that it's a child user $userObject = $confDriver->createUserObject($userName); if (ConfService::getCoreConf("ALLOW_CROSSUSERS_SHARING", "conf") != true && (!$userObject->hasParent() || $userObject->getParent() != $loggedUser->id)) { return 102; } } else { if ($httpVars["create_guest_user"] != "true" && !ConfService::getCoreConf("USER_CREATE_USERS", "conf") || AuthService::isReservedUserId($userName)) { return 102; } if (!isset($httpVars["shared_pass"]) || $httpVars["shared_pass"] == "") { return 100; } } } // CREATE SHARED OPTIONS $options = $accessDriver->makeSharedRepositoryOptions($httpVars, $repository); $customData = array(); foreach ($httpVars as $key => $value) { if (substr($key, 0, strlen("PLUGINS_DATA_")) == "PLUGINS_DATA_") { $customData[substr($key, strlen("PLUGINS_DATA_"))] = $value; } } if (count($customData)) { $options["PLUGINS_DATA"] = $customData; } if (isset($editingRepo)) { $newRepo = $editingRepo; if ($editingRepo->getDisplay() != $label) { $newRepo->setDisplay($label); ConfService::replaceRepository($httpVars["repository_id"], $newRepo); } $editingRepo->setDescription($description); } else { if ($repository->getOption("META_SOURCES")) { $options["META_SOURCES"] = $repository->getOption("META_SOURCES"); foreach ($options["META_SOURCES"] as $index => $data) { if (isset($data["USE_SESSION_CREDENTIALS"]) && $data["USE_SESSION_CREDENTIALS"] === true) { $options["META_SOURCES"][$index]["ENCODED_CREDENTIALS"] = AJXP_Safe::getEncodedCredentialString(); } } } $newRepo = $repository->createSharedChild($label, $options, $repository->id, $loggedUser->id, null); $gPath = $loggedUser->getGroupPath(); if (!empty($gPath) && !ConfService::getCoreConf("CROSSUSERS_ALLGROUPS", "conf")) { $newRepo->setGroupPath($gPath); } $newRepo->setDescription($description); ConfService::addRepository($newRepo); } $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]); if (isset($editingRepo)) { $currentRights = $this->computeSharedRepositoryAccessRights($httpVars["repository_id"], false, $this->urlBase . $file); $originalUsers = array_keys($currentRights["USERS"]); $removeUsers = array_diff($originalUsers, $users); if (count($removeUsers)) { foreach ($removeUsers as $user) { if (AuthService::userExists($user)) { $userObject = $confDriver->createUserObject($user); $userObject->personalRole->setAcl($newRepo->getUniqueId(), ""); $userObject->save("superuser"); } } } $originalGroups = array_keys($currentRights["GROUPS"]); $removeGroups = array_diff($originalGroups, $groups); if (count($removeGroups)) { foreach ($removeGroups as $groupId) { $role = AuthService::getRole("AJXP_GRP_" . AuthService::filterBaseGroup($groupId)); if ($role !== false) { $role->setAcl($newRepo->getUniqueId(), ""); AuthService::updateRole($role); } } } } foreach ($users as $userName) { if (AuthService::userExists($userName, "r")) { // check that it's a child user $userObject = $confDriver->createUserObject($userName); } else { if (ConfService::getAuthDriverImpl()->getOption("TRANSMIT_CLEAR_PASS")) { $pass = $uPasses[$userName]; } else { $pass = md5($uPasses[$userName]); } $limit = $loggedUser->personalRole->filterParameterValue("core.conf", "USER_SHARED_USERS_LIMIT", AJXP_REPO_SCOPE_ALL, ""); if (!empty($limit) && intval($limit) > 0) { $count = count(ConfService::getConfStorageImpl()->getUserChildren($loggedUser->getId())); if ($count >= $limit) { $mess = ConfService::getMessages(); throw new Exception($mess['483']); } } AuthService::createUser($userName, $pass); $userObject = $confDriver->createUserObject($userName); $userObject->personalRole->clearAcls(); $userObject->setParent($loggedUser->id); $userObject->setGroupPath($loggedUser->getGroupPath()); $userObject->setProfile("shared"); if (isset($httpVars["minisite"])) { $mess = ConfService::getMessages(); $userObject->personalRole->setParameterValue("core.conf", "USER_DISPLAY_NAME", "[" . $mess["share_center.109"] . "] " . $newRepo->getDisplay()); } AJXP_Controller::applyHook("user.after_create", array($userObject)); } // CREATE USER WITH NEW REPO RIGHTS $userObject->personalRole->setAcl($newRepo->getUniqueId(), $uRights[$userName]); if (isset($httpVars["minisite"])) { $newRole = new AJXP_Role("AJXP_SHARED-" . $newRepo->getUniqueId()); $r = AuthService::getRole("MINISITE"); if (is_a($r, "AJXP_Role")) { if ($httpVars["disable_download"]) { $f = AuthService::getRole("MINISITE_NODOWNLOAD"); if (is_a($f, "AJXP_Role")) { $r = $f->override($r); } } $allData = $r->getDataArray(); $newData = $newRole->getDataArray(); if (isset($allData["ACTIONS"][AJXP_REPO_SCOPE_SHARED])) { $newData["ACTIONS"][$newRepo->getUniqueId()] = $allData["ACTIONS"][AJXP_REPO_SCOPE_SHARED]; } if (isset($allData["PARAMETERS"][AJXP_REPO_SCOPE_SHARED])) { $newData["PARAMETERS"][$newRepo->getUniqueId()] = $allData["PARAMETERS"][AJXP_REPO_SCOPE_SHARED]; } $newRole->bunchUpdate($newData); AuthService::updateRole($newRole); $userObject->addRole($newRole); } } $userObject->save("superuser"); if ($this->watcher !== false) { // Register a watch on the current folder for shared user if ($uWatches[$userName] == "true") { $this->watcher->setWatchOnFolder(new AJXP_Node($this->urlBase . $file), $userName, MetaWatchRegister::$META_WATCH_USERS_CHANGE, array(AuthService::getLoggedUser()->getId())); } else { $this->watcher->removeWatchFromFolder(new AJXP_Node($this->urlBase . $file), $userName, true); } } } if ($this->watcher !== false) { // Register a watch on the new repository root for current user if ($httpVars["self_watch_folder"] == "true") { $this->watcher->setWatchOnFolder(new AJXP_Node($this->baseProtocol . "://" . $newRepo->getUniqueId() . "/"), AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_BOTH); } else { $this->watcher->removeWatchFromFolder(new AJXP_Node($this->baseProtocol . "://" . $newRepo->getUniqueId() . "/"), AuthService::getLoggedUser()->getId()); } } foreach ($groups as $group) { $grRole = AuthService::getRole("AJXP_GRP_" . AuthService::filterBaseGroup($group), true); $grRole->setAcl($newRepo->getUniqueId(), $uRights[$group]); AuthService::updateRole($grRole); } if (array_key_exists("minisite", $httpVars) && $httpVars["minisite"] != true) { AJXP_Controller::applyHook("node.share.create", array('type' => 'repository', 'repository' => &$repository, 'accessDriver' => &$accessDriver, 'new_repository' => &$newRepo)); } return $newRepo; }
function switchAction($action, $httpVars, $fileVars) { if (!isset($this->actions[$action])) { return; } parent::accessPreprocess($action, $httpVars, $fileVars); $loggedUser = AuthService::getLoggedUser(); if (AuthService::usersEnabled() && !$loggedUser->isAdmin()) { return; } if ($action == "edit") { if (isset($httpVars["sub_action"])) { $action = $httpVars["sub_action"]; } } $mess = ConfService::getMessages(); switch ($action) { //------------------------------------ // BASIC LISTING //------------------------------------ case "ls": $rootNodes = array("data" => array("LABEL" => $mess["ajxp_conf.110"], "ICON" => "user.png", "CHILDREN" => array("repositories" => array("LABEL" => $mess["ajxp_conf.3"], "ICON" => "hdd_external_unmount.png", "LIST" => "listRepositories"), "users" => array("LABEL" => $mess["ajxp_conf.2"], "ICON" => "user.png", "LIST" => "listUsers"), "roles" => array("LABEL" => $mess["ajxp_conf.69"], "ICON" => "yast_kuser.png", "LIST" => "listRoles"))), "config" => array("LABEL" => $mess["ajxp_conf.109"], "ICON" => "preferences_desktop.png", "CHILDREN" => array("core" => array("LABEL" => $mess["ajxp_conf.98"], "ICON" => "preferences_desktop.png", "LIST" => "listPlugins"), "plugins" => array("LABEL" => $mess["ajxp_conf.99"], "ICON" => "folder_development.png", "LIST" => "listPlugins"))), "admin" => array("LABEL" => $mess["ajxp_conf.111"], "ICON" => "toggle_log.png", "CHILDREN" => array("logs" => array("LABEL" => $mess["ajxp_conf.4"], "ICON" => "toggle_log.png", "LIST" => "listLogFiles"), "files" => array("LABEL" => $mess["ajxp_shared.3"], "ICON" => "html.png", "LIST" => "listSharedFiles"), "diagnostic" => array("LABEL" => $mess["ajxp_conf.5"], "ICON" => "susehelpcenter.png", "LIST" => "printDiagnostic")))); AJXP_Controller::applyHook("ajxp_conf.list_config_nodes", array(&$rootNodes)); $dir = trim(AJXP_Utils::decodeSecureMagic(isset($httpVars["dir"]) ? $httpVars["dir"] : ""), " /"); if ($dir != "") { $splits = explode("/", $dir); $root = array_shift($splits); if (count($splits)) { $child = $splits[0]; if (strstr(urldecode($child), "#") !== false) { list($child, $hash) = explode("#", urldecode($child)); } if (isset($rootNodes[$root]["CHILDREN"][$child])) { $callback = $rootNodes[$root]["CHILDREN"][$child]["LIST"]; if (is_string($callback) && method_exists($this, $callback)) { AJXP_XMLWriter::header(); call_user_func(array($this, $callback), implode("/", $splits), $root, $hash); AJXP_XMLWriter::close(); } else { if (is_array($callback)) { call_user_func($callback, implode("/", $splits), $root, $hash); } } return; } } else { $parentName = "/" . $root . "/"; $nodes = $rootNodes[$root]["CHILDREN"]; } } else { $parentName = "/"; $nodes = $rootNodes; } if (isset($nodes)) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendFilesListComponentConfig('<columns switchGridMode="filelist"><column messageId="ajxp_conf.1" attributeName="ajxp_label" sortType="String"/></columns>'); foreach ($nodes as $key => $data) { print '<tree text="' . AJXP_Utils::xmlEntities($data["LABEL"]) . '" icon="' . $data["ICON"] . '" filename="' . $parentName . $key . '"/>'; } AJXP_XMLWriter::close(); } break; case "stat": header("Content-type:application/json"); print '{"mode":true}'; return; break; case "create_role": $roleId = AJXP_Utils::sanitize(SystemTextEncoding::magicDequote($httpVars["role_id"]), AJXP_SANITIZE_HTML_STRICT); if (!strlen($roleId)) { throw new Exception($mess[349]); } if (AuthService::getRole($roleId) !== false) { throw new Exception($mess["ajxp_conf.65"]); } AuthService::updateRole(new AjxpRole($roleId)); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.66"], null); AJXP_XMLWriter::reloadDataNode("", $httpVars["role_id"]); AJXP_XMLWriter::close(); break; case "edit_role": $roleId = SystemTextEncoding::magicDequote($httpVars["role_id"]); $role = AuthService::getRole($roleId); if ($role === false) { throw new Exception("Cant find role! "); } AJXP_XMLWriter::header("admin_data"); print AJXP_XMLWriter::writeRoleRepositoriesData($role); AJXP_XMLWriter::close("admin_data"); break; case "update_role_right": if (!isset($httpVars["role_id"]) || !isset($httpVars["repository_id"]) || !isset($httpVars["right"])) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]); print "<update_checkboxes user_id=\"" . $httpVars["role_id"] . "\" repository_id=\"" . $httpVars["repository_id"] . "\" read=\"old\" write=\"old\"/>"; AJXP_XMLWriter::close(); return; } $role = AuthService::getRole($httpVars["role_id"]); if ($role === false) { throw new Exception("Cant find role!"); } $role->setRight($httpVars["repository_id"], $httpVars["right"]); AuthService::updateRole($role); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.64"] . $httpVars["role_id"], null); print "<update_checkboxes user_id=\"" . $httpVars["role_id"] . "\" repository_id=\"" . $httpVars["repository_id"] . "\" read=\"" . $role->canRead($httpVars["repository_id"]) . "\" write=\"" . $role->canWrite($httpVars["repository_id"]) . "\"/>"; //AJXP_XMLWriter::reloadRepositoryList(); AJXP_XMLWriter::close(); break; case "update_role_actions": if (!isset($httpVars["role_id"]) || !isset($httpVars["disabled_actions"])) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]); AJXP_XMLWriter::close(); return; } $role = AuthService::getRole($httpVars["role_id"]); if ($role === false) { throw new Exception("Cant find role!"); } $actions = explode(",", $httpVars["disabled_actions"]); // Clear and reload actions foreach ($role->getSpecificActionsRights("ajxp.all") as $actName => $actValue) { $role->setSpecificActionRight("ajxp.all", $actName, true); } foreach ($actions as $action) { if (($action = AJXP_Utils::sanitize($action, AJXP_SANITIZE_ALPHANUM)) == "") { continue; } $role->setSpecificActionRight("ajxp.all", $action, false); } AuthService::updateRole($role); AJXP_XMLWriter::header("admin_data"); print AJXP_XMLWriter::writeRoleRepositoriesData($role); AJXP_XMLWriter::close("admin_data"); break; case "update_role_default": if (!isset($httpVars["role_id"]) || !isset($httpVars["default_value"])) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]); AJXP_XMLWriter::close(); return; } $role = AuthService::getRole($httpVars["role_id"]); if ($role === false) { throw new Exception("Cannot find role!"); } $role->setDefault($httpVars["default_value"] == "true"); AuthService::updateRole($role); AJXP_XMLWriter::header("admin_data"); print AJXP_XMLWriter::writeRoleRepositoriesData($role); AJXP_XMLWriter::close("admin_data"); break; case "get_custom_params": $confStorage = ConfService::getConfStorageImpl(); AJXP_XMLWriter::header("admin_data"); $confDriver = ConfService::getConfStorageImpl(); $customData = $confDriver->options['CUSTOM_DATA']; if (is_array($customData) && count($customData) > 0) { print "<custom_data>"; foreach ($customData as $custName => $custValue) { print "<param name=\"{$custName}\" type=\"string\" label=\"{$custValue}\" description=\"\" value=\"\"/>"; } print "</custom_data>"; } AJXP_XMLWriter::close("admin_data"); break; case "edit_user": $confStorage = ConfService::getConfStorageImpl(); $userId = $httpVars["user_id"]; if (!AuthService::userExists($userId)) { throw new Exception("Invalid user id!"); } $userObject = $confStorage->createUserObject($userId); //print_r($userObject); AJXP_XMLWriter::header("admin_data"); AJXP_XMLWriter::sendUserData($userObject, true); // Add CUSTOM USER DATA $confDriver = ConfService::getConfStorageImpl(); $customData = $confDriver->options['CUSTOM_DATA']; if (is_array($customData) && count($customData) > 0) { $userCustom = $userObject->getPref("CUSTOM_PARAMS"); print "<custom_data>"; foreach ($customData as $custName => $custValue) { $value = isset($userCustom[$custName]) ? $userCustom[$custName] : ''; print "<param name=\"{$custName}\" type=\"string\" label=\"{$custValue}\" description=\"\" value=\"{$value}\"/>"; } print "</custom_data>"; } // Add WALLET DATA : DEFINITIONS AND VALUES print "<drivers>"; print AJXP_XMLWriter::replaceAjxpXmlKeywords(ConfService::availableDriversToXML("user_param")); print "</drivers>"; $wallet = $userObject->getPref("AJXP_WALLET"); if (is_array($wallet) && count($wallet) > 0) { print "<user_wallet>"; foreach ($wallet as $repoId => $options) { foreach ($options as $optName => $optValue) { print "<wallet_data repo_id=\"{$repoId}\" option_name=\"{$optName}\" option_value=\"{$optValue}\"/>"; } } print "</user_wallet>"; } $editPass = $userId != "guest" ? "1" : "0"; $authDriver = ConfService::getAuthDriverImpl(); if (!$authDriver->passwordsEditable()) { $editPass = "******"; } print "<edit_options edit_pass=\"" . $editPass . "\" edit_admin_right=\"" . ($userId != "guest" && $userId != $loggedUser->getId() ? "1" : "0") . "\" edit_delete=\"" . ($userId != "guest" && $userId != $loggedUser->getId() && $authDriver->usersEditable() ? "1" : "0") . "\"/>"; print "<ajxp_roles>"; foreach (AuthService::getRolesList() as $roleId => $roleObject) { print "<role id=\"" . AJXP_Utils::xmlEntities($roleId) . "\"/>"; } print "</ajxp_roles>"; AJXP_XMLWriter::close("admin_data"); break; case "create_user": if (!isset($httpVars["new_user_login"]) || $httpVars["new_user_login"] == "" || !isset($httpVars["new_user_pwd"]) || $httpVars["new_user_pwd"] == "") { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]); AJXP_XMLWriter::close(); return; } $new_user_login = AJXP_Utils::sanitize(SystemTextEncoding::magicDequote($httpVars["new_user_login"]), AJXP_SANITIZE_EMAILCHARS); if (AuthService::userExists($new_user_login) || AuthService::isReservedUserId($new_user_login)) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.43"]); AJXP_XMLWriter::close(); return; } $confStorage = ConfService::getConfStorageImpl(); $newUser = $confStorage->createUserObject($new_user_login); $customData = array(); $this->parseParameters($httpVars, $customData); if (is_array($customData) && count($customData) > 0) { $newUser->setPref("CUSTOM_PARAMS", $customData); } $newUser->save("superuser"); AuthService::createUser($new_user_login, $httpVars["new_user_pwd"]); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.44"], null); AJXP_XMLWriter::reloadDataNode("", $new_user_login); AJXP_XMLWriter::close(); break; case "change_admin_right": $userId = $httpVars["user_id"]; if (!AuthService::userExists($userId)) { throw new Exception("Invalid user id!"); } $confStorage = ConfService::getConfStorageImpl(); $user = $confStorage->createUserObject($userId); $user->setAdmin($httpVars["right_value"] == "1" ? true : false); $user->save("superuser"); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.45"] . $httpVars["user_id"], null); AJXP_XMLWriter::reloadDataNode(); AJXP_XMLWriter::close(); break; case "update_user_right": if (!isset($httpVars["user_id"]) || !isset($httpVars["repository_id"]) || !isset($httpVars["right"]) || !AuthService::userExists($httpVars["user_id"])) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]); print "<update_checkboxes user_id=\"" . $httpVars["user_id"] . "\" repository_id=\"" . $httpVars["repository_id"] . "\" read=\"old\" write=\"old\"/>"; AJXP_XMLWriter::close(); return; } $confStorage = ConfService::getConfStorageImpl(); $user = $confStorage->createUserObject($httpVars["user_id"]); $user->setRight(AJXP_Utils::sanitize($httpVars["repository_id"], AJXP_SANITIZE_ALPHANUM), AJXP_Utils::sanitize($httpVars["right"], AJXP_SANITIZE_ALPHANUM)); $user->save(); $loggedUser = AuthService::getLoggedUser(); if ($loggedUser->getId() == $user->getId()) { AuthService::updateUser($user); } AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.46"] . $httpVars["user_id"], null); print "<update_checkboxes user_id=\"" . $httpVars["user_id"] . "\" repository_id=\"" . $httpVars["repository_id"] . "\" read=\"" . $user->canRead($httpVars["repository_id"]) . "\" write=\"" . $user->canWrite($httpVars["repository_id"]) . "\"/>"; AJXP_XMLWriter::reloadRepositoryList(); AJXP_XMLWriter::close(); return; break; case "user_add_role": case "user_delete_role": if (!isset($httpVars["user_id"]) || !isset($httpVars["role_id"]) || !AuthService::userExists($httpVars["user_id"]) || !AuthService::getRole($httpVars["role_id"])) { throw new Exception($mess["ajxp_conf.61"]); } if ($action == "user_add_role") { $act = "add"; $messId = "73"; } else { $act = "remove"; $messId = "74"; } $this->updateUserRole($httpVars["user_id"], $httpVars["role_id"], $act); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf." . $messId] . $httpVars["user_id"], null); AJXP_XMLWriter::close(); return; break; case "batch_users_roles": $confStorage = ConfService::getConfStorageImpl(); $selection = new UserSelection(); $selection->initFromHttpVars($httpVars); $files = $selection->getFiles(); $detectedRoles = array(); if (isset($httpVars["role_id"]) && isset($httpVars["update_role_action"])) { $update = $httpVars["update_role_action"]; $roleId = $httpVars["role_id"]; if (AuthService::getRole($roleId) === false) { throw new Exception("Invalid role id"); } } foreach ($files as $index => $file) { $userId = basename($file); if (isset($update)) { $userObject = $this->updateUserRole($userId, $roleId, $update); } else { $userObject = $confStorage->createUserObject($userId); } if ($userObject->hasParent()) { unset($files[$index]); continue; } $userRoles = $userObject->getRoles(); foreach ($userRoles as $roleIndex => $bool) { if (!isset($detectedRoles[$roleIndex])) { $detectedRoles[$roleIndex] = 0; } if ($bool === true) { $detectedRoles[$roleIndex]++; } } } $count = count($files); AJXP_XMLWriter::header("admin_data"); print "<user><ajxp_roles>"; foreach ($detectedRoles as $roleId => $roleCount) { if ($roleCount < $count) { continue; } print "<role id=\"{$roleId}\"/>"; } print "</ajxp_roles></user>"; print "<ajxp_roles>"; foreach (AuthService::getRolesList() as $roleId => $roleObject) { print "<role id=\"{$roleId}\"/>"; } print "</ajxp_roles>"; AJXP_XMLWriter::close("admin_data"); break; case "save_custom_user_params": $userId = $httpVars["user_id"]; if ($userId == $loggedUser->getId()) { $user = $loggedUser; } else { $confStorage = ConfService::getConfStorageImpl(); $user = $confStorage->createUserObject($userId); } $custom = $user->getPref("CUSTOM_PARAMS"); if (!is_array($custom)) { $custom = array(); } $options = $custom; $this->parseParameters($httpVars, $options, $userId); $custom = $options; $user->setPref("CUSTOM_PARAMS", $custom); $user->save(); if ($loggedUser->getId() == $user->getId()) { AuthService::updateUser($user); } AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.47"] . $httpVars["user_id"], null); AJXP_XMLWriter::close(); break; case "save_repository_user_params": $userId = $httpVars["user_id"]; if ($userId == $loggedUser->getId()) { $user = $loggedUser; } else { $confStorage = ConfService::getConfStorageImpl(); $user = $confStorage->createUserObject($userId); } $wallet = $user->getPref("AJXP_WALLET"); if (!is_array($wallet)) { $wallet = array(); } $repoID = $httpVars["repository_id"]; if (!array_key_exists($repoID, $wallet)) { $wallet[$repoID] = array(); } $options = $wallet[$repoID]; $this->parseParameters($httpVars, $options, $userId); $wallet[$repoID] = $options; $user->setPref("AJXP_WALLET", $wallet); $user->save(); if ($loggedUser->getId() == $user->getId()) { AuthService::updateUser($user); } AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.47"] . $httpVars["user_id"], null); AJXP_XMLWriter::close(); break; case "update_user_pwd": if (!isset($httpVars["user_id"]) || !isset($httpVars["user_pwd"]) || !AuthService::userExists($httpVars["user_id"]) || trim($httpVars["user_pwd"]) == "") { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]); AJXP_XMLWriter::close(); return; } $res = AuthService::updatePassword($httpVars["user_id"], $httpVars["user_pwd"]); AJXP_XMLWriter::header(); if ($res === true) { AJXP_XMLWriter::sendMessage($mess["ajxp_conf.48"] . $httpVars["user_id"], null); } else { AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.49"] . " : {$res}"); } AJXP_XMLWriter::close(); break; case "save_user_preference": if (!isset($httpVars["user_id"]) || !AuthService::userExists($httpVars["user_id"])) { throw new Exception($mess["ajxp_conf.61"]); } $userId = $httpVars["user_id"]; if ($userId == $loggedUser->getId()) { $userObject = $loggedUser; } else { $confStorage = ConfService::getConfStorageImpl(); $userObject = $confStorage->createUserObject($userId); } $i = 0; while (isset($httpVars["pref_name_" . $i]) && isset($httpVars["pref_value_" . $i])) { $prefName = AJXP_Utils::sanitize($httpVars["pref_name_" . $i], AJXP_SANITIZE_ALPHANUM); $prefValue = AJXP_Utils::sanitize(SystemTextEncoding::magicDequote($httpVars["pref_value_" . $i])); if ($prefName == "password") { continue; } if ($prefName != "pending_folder" && $userObject == null) { $i++; continue; } $userObject->setPref($prefName, $prefValue); $userObject->save("user"); $i++; } AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage("Succesfully saved user preference", null); AJXP_XMLWriter::close(); break; case "get_drivers_definition": AJXP_XMLWriter::header("drivers"); print AJXP_XMLWriter::replaceAjxpXmlKeywords(ConfService::availableDriversToXML("param", "", true)); AJXP_XMLWriter::close("drivers"); break; case "get_templates_definition": AJXP_XMLWriter::header("repository_templates"); $repositories = ConfService::getRepositoriesList(); foreach ($repositories as $repo) { if (!$repo->isTemplate) { continue; } $repoId = $repo->getUniqueId(); $repoLabel = $repo->getDisplay(); $repoType = $repo->getAccessType(); print "<template repository_id=\"{$repoId}\" repository_label=\"{$repoLabel}\" repository_type=\"{$repoType}\">"; foreach ($repo->getOptionsDefined() as $optionName) { print "<option name=\"{$optionName}\"/>"; } print "</template>"; } AJXP_XMLWriter::close("repository_templates"); break; case "create_repository": $options = array(); $repDef = $httpVars; $isTemplate = isset($httpVars["sf_checkboxes_active"]); unset($repDef["get_action"]); unset($repDef["sf_checkboxes_active"]); $this->parseParameters($repDef, $options); if (count($options)) { $repDef["DRIVER_OPTIONS"] = $options; } if (strstr($repDef["DRIVER"], "ajxp_template_") !== false) { $templateId = substr($repDef["DRIVER"], 14); $templateRepo = ConfService::getRepositoryById($templateId); $newRep = $templateRepo->createTemplateChild($repDef["DISPLAY"], $repDef["DRIVER_OPTIONS"]); } else { $pServ = AJXP_PluginsService::getInstance(); $driver = $pServ->getPluginByTypeName("access", $repDef["DRIVER"]); $newRep = ConfService::createRepositoryFromArray(0, $repDef); $testFile = $driver->getBaseDir() . "/test." . $newRep->getAccessType() . "Access.php"; if (!$isTemplate && is_file($testFile)) { //chdir(AJXP_TESTS_FOLDER."/plugins"); include $testFile; $className = $newRep->getAccessType() . "AccessTest"; $class = new $className(); $result = $class->doRepositoryTest($newRep); if (!$result) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $class->failedInfo); AJXP_XMLWriter::close(); return; } } // Apply default metasource if any if ($driver != null && $driver->getConfigs() != null) { $confs = $driver->getConfigs(); if (!empty($confs["DEFAULT_METASOURCES"])) { $metaIds = AJXP_Utils::parseCSL($confs["DEFAULT_METASOURCES"]); $metaSourceOptions = array(); foreach ($metaIds as $metaID) { $metaPlug = $pServ->getPluginById($metaID); if ($metaPlug == null) { continue; } $pNodes = $metaPlug->getManifestRawContent("//param[@default]", "nodes"); $defaultParams = array(); foreach ($pNodes as $domNode) { $defaultParams[$domNode->getAttribute("name")] = $domNode->getAttribute("default"); } $metaSourceOptions[$metaID] = $defaultParams; } $newRep->addOption("META_SOURCES", $metaSourceOptions); } } } if ($this->repositoryExists($newRep->getDisplay())) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.50"]); AJXP_XMLWriter::close(); return; } if ($isTemplate) { $newRep->isTemplate = true; } $res = ConfService::addRepository($newRep); AJXP_XMLWriter::header(); if ($res == -1) { AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.51"]); } else { $loggedUser = AuthService::getLoggedUser(); $loggedUser->setRight($newRep->getUniqueId(), "rw"); $loggedUser->save("superuser"); AuthService::updateUser($loggedUser); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.52"], null); AJXP_XMLWriter::reloadDataNode("", $newRep->getUniqueId()); AJXP_XMLWriter::reloadRepositoryList(); } AJXP_XMLWriter::close(); break; case "edit_repository": $repId = $httpVars["repository_id"]; $repList = ConfService::getRootDirsList(); //print_r($repList); if (!isset($repList[$repId])) { throw new Exception("Cannot find repository with id {$repId}"); } $repository = $repList[$repId]; $pServ = AJXP_PluginsService::getInstance(); $plug = $pServ->getPluginById("access." . $repository->accessType); if ($plug == null) { throw new Exception("Cannot find access driver (" . $repository->accessType . ") for repository!"); } AJXP_XMLWriter::header("admin_data"); $slug = $repository->getSlug(); if ($slug == "" && $repository->isWriteable()) { $repository->setSlug(); ConfService::replaceRepository($repId, $repository); } $nested = array(); print "<repository index=\"{$repId}\""; foreach ($repository as $name => $option) { if (strstr($name, " ") > -1) { continue; } if (!is_array($option)) { if (is_bool($option)) { $option = $option ? "true" : "false"; } print " {$name}=\"" . SystemTextEncoding::toUTF8(AJXP_Utils::xmlEntities($option)) . "\" "; } else { if (is_array($option)) { $nested[] = $option; } } } if (count($nested)) { print ">"; foreach ($nested as $option) { foreach ($option as $key => $optValue) { if (is_array($optValue) && count($optValue)) { print "<param name=\"{$key}\"><![CDATA[" . json_encode($optValue) . "]]></param>"; } else { if (is_bool($optValue)) { $optValue = $optValue ? "true" : "false"; } print "<param name=\"{$key}\" value=\"{$optValue}\"/>"; } } } // Add SLUG if (!$repository->isTemplate) { print "<param name=\"AJXP_SLUG\" value=\"" . $repository->getSlug() . "\"/>"; } print "</repository>"; } else { print "/>"; } if ($repository->hasParent()) { $parent = ConfService::getRepositoryById($repository->getParentId()); if (isset($parent) && $parent->isTemplate) { $parentLabel = $parent->getDisplay(); $parentType = $parent->getAccessType(); print "<template repository_id=\"" . $repository->getParentId() . "\" repository_label=\"{$parentLabel}\" repository_type=\"{$parentType}\">"; foreach ($parent->getOptionsDefined() as $parentOptionName) { print "<option name=\"{$parentOptionName}\"/>"; } print "</template>"; } } $manifest = $plug->getManifestRawContent("server_settings/param"); $manifest = AJXP_XMLWriter::replaceAjxpXmlKeywords($manifest); print "<ajxpdriver name=\"" . $repository->accessType . "\">{$manifest}</ajxpdriver>"; print "<metasources>"; $metas = $pServ->getPluginsByType("metastore"); $metas = array_merge($metas, $pServ->getPluginsByType("meta")); $metas = array_merge($metas, $pServ->getPluginsByType("index")); foreach ($metas as $metaPlug) { print "<meta id=\"" . $metaPlug->getId() . "\" label=\"" . AJXP_Utils::xmlEntities($metaPlug->getManifestLabel()) . "\">"; $manifest = $metaPlug->getManifestRawContent("server_settings/param"); $manifest = AJXP_XMLWriter::replaceAjxpXmlKeywords($manifest); print $manifest; print "</meta>"; } print "</metasources>"; AJXP_XMLWriter::close("admin_data"); return; break; case "edit_repository_label": case "edit_repository_data": $repId = $httpVars["repository_id"]; $repo = ConfService::getRepositoryById($repId); $res = 0; if (isset($httpVars["newLabel"])) { $newLabel = AJXP_Utils::decodeSecureMagic($httpVars["newLabel"]); if ($this->repositoryExists($newLabel)) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.50"]); AJXP_XMLWriter::close(); return; } $repo->setDisplay($newLabel); $res = ConfService::replaceRepository($repId, $repo); } else { $options = array(); $this->parseParameters($httpVars, $options); if (count($options)) { foreach ($options as $key => $value) { if ($key == "AJXP_SLUG") { $repo->setSlug($value); continue; } $repo->addOption($key, $value); } } if (is_file(AJXP_TESTS_FOLDER . "/plugins/test.ajxp_" . $repo->getAccessType() . ".php")) { chdir(AJXP_TESTS_FOLDER . "/plugins"); include AJXP_TESTS_FOLDER . "/plugins/test.ajxp_" . $repo->getAccessType() . ".php"; $className = "ajxp_" . $repo->getAccessType(); $class = new $className(); $result = $class->doRepositoryTest($repo); if (!$result) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $class->failedInfo); AJXP_XMLWriter::close(); return; } } ConfService::replaceRepository($repId, $repo); } AJXP_XMLWriter::header(); if ($res == -1) { AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.53"]); } else { AJXP_XMLWriter::sendMessage($mess["ajxp_conf.54"], null); AJXP_XMLWriter::reloadDataNode("", isset($httpVars["newLabel"]) ? $repId : false); AJXP_XMLWriter::reloadRepositoryList(); } AJXP_XMLWriter::close(); break; case "add_meta_source": $repId = $httpVars["repository_id"]; $repo = ConfService::getRepositoryById($repId); if (!is_object($repo)) { throw new Exception("Invalid repository id! {$repId}"); } $metaSourceType = AJXP_Utils::sanitize($httpVars["new_meta_source"], AJXP_SANITIZE_ALPHANUM); $options = array(); $this->parseParameters($httpVars, $options); $repoOptions = $repo->getOption("META_SOURCES"); if (is_array($repoOptions) && isset($repoOptions[$metaSourceType])) { throw new Exception($mess["ajxp_conf.55"]); } if (!is_array($repoOptions)) { $repoOptions = array(); } $repoOptions[$metaSourceType] = $options; uksort($repoOptions, array($this, "metaSourceOrderingFunction")); $repo->addOption("META_SOURCES", $repoOptions); ConfService::replaceRepository($repId, $repo); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.56"], null); AJXP_XMLWriter::close(); break; case "delete_meta_source": $repId = $httpVars["repository_id"]; $repo = ConfService::getRepositoryById($repId); if (!is_object($repo)) { throw new Exception("Invalid repository id! {$repId}"); } $metaSourceId = $httpVars["plugId"]; $repoOptions = $repo->getOption("META_SOURCES"); if (is_array($repoOptions) && array_key_exists($metaSourceId, $repoOptions)) { unset($repoOptions[$metaSourceId]); uksort($repoOptions, array($this, "metaSourceOrderingFunction")); $repo->addOption("META_SOURCES", $repoOptions); ConfService::replaceRepository($repId, $repo); } AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.57"], null); AJXP_XMLWriter::close(); break; case "edit_meta_source": $repId = $httpVars["repository_id"]; $repo = ConfService::getRepositoryById($repId); if (!is_object($repo)) { throw new Exception("Invalid repository id! {$repId}"); } $metaSourceId = $httpVars["plugId"]; $options = array(); $this->parseParameters($httpVars, $options); $repoOptions = $repo->getOption("META_SOURCES"); if (!is_array($repoOptions)) { $repoOptions = array(); } $repoOptions[$metaSourceId] = $options; uksort($repoOptions, array($this, "metaSourceOrderingFunction")); $repo->addOption("META_SOURCES", $repoOptions); ConfService::replaceRepository($repId, $repo); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.58"], null); AJXP_XMLWriter::close(); break; case "delete": if (isset($httpVars["repository_id"])) { $repId = $httpVars["repository_id"]; $res = ConfService::deleteRepository($repId); AJXP_XMLWriter::header(); if ($res == -1) { AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.51"]); } else { AJXP_XMLWriter::sendMessage($mess["ajxp_conf.59"], null); AJXP_XMLWriter::reloadDataNode(); AJXP_XMLWriter::reloadRepositoryList(); } AJXP_XMLWriter::close(); return; } else { if (isset($httpVars["shared_file"])) { AJXP_XMLWriter::header(); $element = basename($httpVars["shared_file"]); $dlFolder = ConfService::getCoreConf("PUBLIC_DOWNLOAD_FOLDER"); $publicletData = $this->loadPublicletData($dlFolder . "/" . $element . ".php"); unlink($dlFolder . "/" . $element . ".php"); AJXP_XMLWriter::sendMessage($mess["ajxp_shared.13"], null); AJXP_XMLWriter::reloadDataNode(); AJXP_XMLWriter::close(); } else { if (isset($httpVars["role_id"])) { $roleId = $httpVars["role_id"]; if (AuthService::getRole($roleId) === false) { throw new Exception($mess["ajxp_conf.67"]); } AuthService::deleteRole($roleId); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.66"], null); AJXP_XMLWriter::reloadDataNode(); AJXP_XMLWriter::close(); } else { if (!isset($httpVars["user_id"]) || $httpVars["user_id"] == "" || AuthService::isReservedUserId($httpVars["user_id"]) || $loggedUser->getId() == $httpVars["user_id"]) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]); AJXP_XMLWriter::close(); } $res = AuthService::deleteUser($httpVars["user_id"]); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.60"], null); AJXP_XMLWriter::reloadDataNode(); AJXP_XMLWriter::close(); } } } break; case "clear_expired": $deleted = $this->clearExpiredFiles(); AJXP_XMLWriter::header(); if (count($deleted)) { AJXP_XMLWriter::sendMessage(sprintf($mess["ajxp_shared.23"], count($deleted) . ""), null); AJXP_XMLWriter::reloadDataNode(); } else { AJXP_XMLWriter::sendMessage($mess["ajxp_shared.24"], null); } AJXP_XMLWriter::close(); break; case "get_plugin_manifest": $ajxpPlugin = AJXP_PluginsService::getInstance()->getPluginById($httpVars["plugin_id"]); AJXP_XMLWriter::header("admin_data"); echo AJXP_XMLWriter::replaceAjxpXmlKeywords($ajxpPlugin->getManifestRawContent()); $definitions = $ajxpPlugin->getConfigsDefinitions(); $values = $ajxpPlugin->getConfigs(); if (!is_array($values)) { $values = array(); } echo "<plugin_settings_values>"; foreach ($values as $key => $value) { if ($definitions[$key]["type"] == "array" && is_array($value)) { $value = implode(",", $value); } else { if ($definitions[$key]["type"] == "boolean") { $value = $value === true || $value === "true" || $value == 1 ? "true" : "false"; } else { if ($definitions[$key]["type"] == "textarea") { //$value = str_replace("\\n", "\n", $value); } } } echo "<param name=\"{$key}\" value=\"" . AJXP_Utils::xmlEntities($value) . "\"/>"; } if ($ajxpPlugin->getType() != "core") { echo "<param name=\"AJXP_PLUGIN_ENABLED\" value=\"" . ($ajxpPlugin->isEnabled() ? "true" : "false") . "\"/>"; } echo "</plugin_settings_values>"; echo "<plugin_doc><![CDATA[<p>" . $ajxpPlugin->getPluginInformationHTML("Charles du Jeu", "http://ajaxplorer.info/plugins/") . "</p>"; if (file_exists($ajxpPlugin->getBaseDir() . "/plugin_doc.html")) { echo file_get_contents($ajxpPlugin->getBaseDir() . "/plugin_doc.html"); } echo "]]></plugin_doc>"; AJXP_XMLWriter::close("admin_data"); break; case "edit_plugin_options": $options = array(); $this->parseParameters($httpVars, $options); $confStorage = ConfService::getConfStorageImpl(); $confStorage->savePluginConfig($httpVars["plugin_id"], $options); @unlink(AJXP_PLUGINS_CACHE_FILE); @unlink(AJXP_PLUGINS_REQUIRES_FILE); @unlink(AJXP_PLUGINS_MESSAGES_FILE); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.97"], null); AJXP_XMLWriter::reloadDataNode(); AJXP_XMLWriter::close(); break; default: break; } return; }
function createSharedRepository($httpVars, $repository, $accessDriver) { // ERRORS // 100 : missing args // 101 : repository label already exists // 102 : user already exists // 103 : current user is not allowed to share // SUCCESS // 200 if (!isset($httpVars["repo_label"]) || $httpVars["repo_label"] == "" || !isset($httpVars["repo_rights"]) || $httpVars["repo_rights"] == "") { return 100; } $loggedUser = AuthService::getLoggedUser(); $actRights = $loggedUser->getSpecificActionsRights($repository->id); if (isset($actRights["share"]) && $actRights["share"] === false) { return 103; } $users = array(); if (isset($httpVars["shared_user"]) && !empty($httpVars["shared_user"])) { $users = array_filter(array_map("trim", explode(",", str_replace("\n", ",", $httpVars["shared_user"]))), array("AuthService", "userExists")); } if (isset($httpVars["new_shared_user"]) && !empty($httpVars["new_shared_user"])) { $newshareduser = AJXP_Utils::decodeSecureMagic($httpVars["new_shared_user"], AJXP_SANITIZE_ALPHANUM); if (!empty($this->pluginConf["SHARED_USERS_TMP_PREFIX"]) && strpos($newshareduser, $this->pluginConf["SHARED_USERS_TMP_PREFIX"]) !== 0) { $newshareduser = $this->pluginConf["SHARED_USERS_TMP_PREFIX"] . $newshareduser; } if (!AuthService::userExists($newshareduser)) { array_push($users, $newshareduser); } else { throw new Exception("User already exists, please choose another name."); } } //$userName = AJXP_Utils::decodeSecureMagic($httpVars["shared_user"], AJXP_SANITIZE_ALPHANUM); $label = AJXP_Utils::decodeSecureMagic($httpVars["repo_label"]); $rights = $httpVars["repo_rights"]; if ($rights != "r" && $rights != "w" && $rights != "rw") { return 100; } if (isset($httpVars["repository_id"])) { $editingRepo = ConfService::getRepositoryById($httpVars["repository_id"]); } // CHECK USER & REPO DOES NOT ALREADY EXISTS $repos = ConfService::getRepositoriesList(); foreach ($repos as $obj) { if ($obj->getDisplay() == $label && (!isset($editingRepo) || $editingRepo != $obj)) { return 101; } } $confDriver = ConfService::getConfStorageImpl(); foreach ($users as $userName) { if (AuthService::userExists($userName)) { // check that it's a child user $userObject = $confDriver->createUserObject($userName); if (ConfService::getCoreConf("ALLOW_CROSSUSERS_SHARING") != true && (!$userObject->hasParent() || $userObject->getParent() != $loggedUser->id)) { return 102; } } else { if (AuthService::isReservedUserId($userName)) { return 102; } if (!isset($httpVars["shared_pass"]) || $httpVars["shared_pass"] == "") { return 100; } } } // CREATE SHARED OPTIONS $options = $accessDriver->makeSharedRepositoryOptions($httpVars, $repository); $customData = array(); foreach ($httpVars as $key => $value) { if (substr($key, 0, strlen("PLUGINS_DATA_")) == "PLUGINS_DATA_") { $customData[substr($key, strlen("PLUGINS_DATA_"))] = $value; } } if (count($customData)) { $options["PLUGINS_DATA"] = $customData; } if (isset($editingRepo)) { $newRepo = $editingRepo; $newRepo->setDisplay($label); $newRepo->options = array_merge($newRepo->options, $options); ConfService::replaceRepository($httpVars["repository_id"], $newRepo); } else { if ($repository->getOption("META_SOURCES")) { $options["META_SOURCES"] = $repository->getOption("META_SOURCES"); foreach ($options["META_SOURCES"] as $index => $data) { if (isset($data["USE_SESSION_CREDENTIALS"]) && $data["USE_SESSION_CREDENTIALS"] === true) { $options["META_SOURCES"][$index]["ENCODED_CREDENTIALS"] = AJXP_Safe::getEncodedCredentialString(); } } } $newRepo = $repository->createSharedChild($label, $options, $repository->id, $loggedUser->id, null); ConfService::addRepository($newRepo); } if (isset($httpVars["original_users"])) { $originalUsers = explode(",", $httpVars["original_users"]); $removeUsers = array_diff($originalUsers, $users); if (count($removeUsers)) { foreach ($removeUsers as $user) { if (AuthService::userExists($user)) { $userObject = $confDriver->createUserObject($user); $userObject->removeRights($newRepo->getUniqueId()); $userObject->save("superuser"); } } } } foreach ($users as $userName) { if (AuthService::userExists($userName)) { // check that it's a child user $userObject = $confDriver->createUserObject($userName); } else { if (ConfService::getAuthDriverImpl()->getOption("TRANSMIT_CLEAR_PASS")) { $pass = $httpVars["shared_pass"]; } else { $pass = md5($httpVars["shared_pass"]); } AuthService::createUser($userName, $pass); $userObject = $confDriver->createUserObject($userName); $userObject->clearRights(); $userObject->setParent($loggedUser->id); } // CREATE USER WITH NEW REPO RIGHTS $userObject->setRight($newRepo->getUniqueId(), $rights); $userObject->setSpecificActionRight($newRepo->getUniqueId(), "share", false); $userObject->save("superuser"); } // METADATA if (!isset($editingRepo) && $this->metaStore != null) { $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]); $this->metaStore->setMetadata(new AJXP_Node($this->urlBase . $file), "ajxp_shared", array("element" => $newRepo->getUniqueId()), true, AJXP_METADATA_SCOPE_REPOSITORY); } return 200; }
/** * @param Array $httpVars * @param Repository $repository * @param AbstractAccessDriver $accessDriver * @param null $uniqueUser * @throws Exception * @return int|Repository */ public function createSharedRepository($httpVars, $repository, $accessDriver, $uniqueUser = null) { // ERRORS // 100 : missing args // 101 : repository label already exists // 102 : user already exists // 103 : current user is not allowed to share // SUCCESS // 200 if (!isset($httpVars["repo_label"]) || $httpVars["repo_label"] == "") { return 100; } /* // FILE IS ALWAYS THE PARENT FOLDER SO WE NOW CHECK FOLDER_SHARING AT A HIGHER LEVEL $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]); $foldersharing = $this->getFilteredOption("ENABLE_FOLDER_SHARING", $this->repository->getId()); $foldersharingDisabled = isset($foldersharing) && ($foldersharing === false || (is_string($foldersharing) && $foldersharing == "disable")); if (is_dir($this->urlBase.$file) && $foldersharingDisabled) { return 103; } */ $loggedUser = AuthService::getLoggedUser(); $actRights = $loggedUser->mergedRole->listActionsStatesFor($repository); if (isset($actRights["share"]) && $actRights["share"] === false) { return 103; } $users = array(); $uRights = array(); $uPasses = array(); $groups = array(); $uWatches = array(); $index = 0; $prefix = $this->getFilteredOption("SHARED_USERS_TMP_PREFIX", $this->repository->getId()); while (isset($httpVars["user_" . $index])) { $eType = $httpVars["entry_type_" . $index]; $uWatch = false; $rightString = ($httpVars["right_read_" . $index] == "true" ? "r" : "") . ($httpVars["right_write_" . $index] == "true" ? "w" : ""); if ($this->watcher !== false) { $uWatch = $httpVars["right_watch_" . $index] == "true" ? true : false; } if (empty($rightString)) { $index++; continue; } if ($eType == "user") { $u = AJXP_Utils::decodeSecureMagic($httpVars["user_" . $index], AJXP_SANITIZE_EMAILCHARS); if (!AuthService::userExists($u) && !isset($httpVars["user_pass_" . $index])) { $index++; continue; } else { if (AuthService::userExists($u, "w") && isset($httpVars["user_pass_" . $index])) { throw new Exception("User {$u} already exists, please choose another name."); } } if (!AuthService::userExists($u, "r") && !empty($prefix) && strpos($u, $prefix) !== 0) { $u = $prefix . $u; } $users[] = $u; } else { $u = AJXP_Utils::decodeSecureMagic($httpVars["user_" . $index]); if (strpos($u, "/AJXP_TEAM/") === 0) { $confDriver = ConfService::getConfStorageImpl(); if (method_exists($confDriver, "teamIdToUsers")) { $teamUsers = $confDriver->teamIdToUsers(str_replace("/AJXP_TEAM/", "", $u)); foreach ($teamUsers as $userId) { $users[] = $userId; $uRights[$userId] = $rightString; if ($this->watcher !== false) { $uWatches[$userId] = $uWatch; } } } $index++; continue; } else { $groups[] = $u; } } $uRights[$u] = $rightString; $uPasses[$u] = isset($httpVars["user_pass_" . $index]) ? $httpVars["user_pass_" . $index] : ""; if ($this->watcher !== false) { $uWatches[$u] = $uWatch; } $index++; } $label = AJXP_Utils::sanitize(AJXP_Utils::securePath($httpVars["repo_label"]), AJXP_SANITIZE_HTML); $description = AJXP_Utils::sanitize(AJXP_Utils::securePath($httpVars["repo_description"]), AJXP_SANITIZE_HTML); if (isset($httpVars["repository_id"])) { $editingRepo = ConfService::getRepositoryById($httpVars["repository_id"]); } // CHECK USER & REPO DOES NOT ALREADY EXISTS if ($this->getFilteredOption("AVOID_SHARED_FOLDER_SAME_LABEL", $this->repository->getId()) == true) { $count = 0; $similarLabelRepos = ConfService::listRepositoriesWithCriteria(array("display" => $label), $count); if ($count && !isset($editingRepo)) { return 101; } if ($count && isset($editingRepo)) { foreach ($similarLabelRepos as $slr) { if ($slr->getUniqueId() != $editingRepo->getUniqueId()) { return 101; } } } /* $repos = ConfService::getRepositoriesList(); foreach ($repos as $obj) { if ($obj->getDisplay() == $label && (!isSet($editingRepo) || $editingRepo != $obj)) { } } */ } $confDriver = ConfService::getConfStorageImpl(); foreach ($users as $userName) { if (AuthService::userExists($userName)) { // check that it's a child user $userObject = $confDriver->createUserObject($userName); if (ConfService::getCoreConf("ALLOW_CROSSUSERS_SHARING", "conf") != true && (!$userObject->hasParent() || $userObject->getParent() != $loggedUser->id)) { return 102; } } else { if ($httpVars["create_guest_user"] != "true" && !ConfService::getCoreConf("USER_CREATE_USERS", "conf") || AuthService::isReservedUserId($userName)) { return 102; } if (!isset($httpVars["shared_pass"]) || $httpVars["shared_pass"] == "") { return 100; } } } // CREATE SHARED OPTIONS $options = $accessDriver->makeSharedRepositoryOptions($httpVars, $repository); $customData = array(); foreach ($httpVars as $key => $value) { if (substr($key, 0, strlen("PLUGINS_DATA_")) == "PLUGINS_DATA_") { $customData[substr($key, strlen("PLUGINS_DATA_"))] = $value; } } if (count($customData)) { $options["PLUGINS_DATA"] = $customData; } if (isset($editingRepo)) { $this->getShareStore()->testUserCanEditShare($editingRepo->getOwner()); $newRepo = $editingRepo; $replace = false; if ($editingRepo->getDisplay() != $label) { $newRepo->setDisplay($label); $replace = true; } if ($editingRepo->getDescription() != $description) { $newRepo->setDescription($description); $replace = true; } if ($replace) { ConfService::replaceRepository($httpVars["repository_id"], $newRepo); } } else { if ($repository->getOption("META_SOURCES")) { $options["META_SOURCES"] = $repository->getOption("META_SOURCES"); foreach ($options["META_SOURCES"] as $index => &$data) { if (isset($data["USE_SESSION_CREDENTIALS"]) && $data["USE_SESSION_CREDENTIALS"] === true) { $options["META_SOURCES"][$index]["ENCODED_CREDENTIALS"] = AJXP_Safe::getEncodedCredentialString(); } if ($index == "meta.syncable" && (!isset($data["REPO_SYNCABLE"]) || $data["REPO_SYNCABLE"] === true)) { $data["REQUIRES_INDEXATION"] = true; } } } $newRepo = $repository->createSharedChild($label, $options, $repository->id, $loggedUser->id, null); $gPath = $loggedUser->getGroupPath(); if (!empty($gPath) && !ConfService::getCoreConf("CROSSUSERS_ALLGROUPS", "conf")) { $newRepo->setGroupPath($gPath); } $newRepo->setDescription($description); $newRepo->options["PATH"] = SystemTextEncoding::fromStorageEncoding($newRepo->options["PATH"]); if (isset($httpVars["filter_nodes"])) { $newRepo->setContentFilter(new ContentFilter($httpVars["filter_nodes"])); } ConfService::addRepository($newRepo); if (!isset($httpVars["minisite"])) { $this->getShareStore()->storeShare($repository->getId(), array("REPOSITORY" => $newRepo->getUniqueId(), "OWNER_ID" => $loggedUser->getId()), "repository"); } } $sel = new UserSelection($this->repository, $httpVars); $file = $sel->getUniqueFile(); $newRepoUniqueId = $newRepo->getUniqueId(); if (isset($editingRepo)) { $currentRights = $this->computeSharedRepositoryAccessRights($httpVars["repository_id"], false, $this->urlBase . $file); $originalUsers = array_keys($currentRights["USERS"]); $removeUsers = array_diff($originalUsers, $users); if (count($removeUsers)) { foreach ($removeUsers as $user) { if (AuthService::userExists($user)) { $userObject = $confDriver->createUserObject($user); $userObject->personalRole->setAcl($newRepoUniqueId, ""); $userObject->save("superuser"); } if ($this->watcher !== false) { $this->watcher->removeWatchFromFolder(new AJXP_Node($this->urlBase . $file), $user, true); } } } $originalGroups = array_keys($currentRights["GROUPS"]); $removeGroups = array_diff($originalGroups, $groups); if (count($removeGroups)) { foreach ($removeGroups as $groupId) { $role = AuthService::getRole($groupId); if ($role !== false) { $role->setAcl($newRepoUniqueId, ""); AuthService::updateRole($role); } } } } foreach ($users as $userName) { if (AuthService::userExists($userName, "r")) { // check that it's a child user $userObject = $confDriver->createUserObject($userName); } else { if (ConfService::getAuthDriverImpl()->getOptionAsBool("TRANSMIT_CLEAR_PASS")) { $pass = $uPasses[$userName]; } else { $pass = md5($uPasses[$userName]); } if (!isset($httpVars["minisite"])) { // This is an explicit user creation - check possible limits AJXP_Controller::applyHook("user.before_create", array($userName, null, false, false)); $limit = $loggedUser->personalRole->filterParameterValue("core.conf", "USER_SHARED_USERS_LIMIT", AJXP_REPO_SCOPE_ALL, ""); if (!empty($limit) && intval($limit) > 0) { $count = count(ConfService::getConfStorageImpl()->getUserChildren($loggedUser->getId())); if ($count >= $limit) { $mess = ConfService::getMessages(); throw new Exception($mess['483']); } } } AuthService::createUser($userName, $pass, false, isset($httpVars["minisite"])); $userObject = $confDriver->createUserObject($userName); $userObject->personalRole->clearAcls(); $userObject->setParent($loggedUser->id); $userObject->setGroupPath($loggedUser->getGroupPath()); $userObject->setProfile("shared"); if (isset($httpVars["minisite"])) { $mess = ConfService::getMessages(); $userObject->setHidden(true); $userObject->personalRole->setParameterValue("core.conf", "USER_DISPLAY_NAME", "[" . $mess["share_center.109"] . "] " . AJXP_Utils::sanitize($newRepo->getDisplay(), AJXP_SANITIZE_EMAILCHARS)); } AJXP_Controller::applyHook("user.after_create", array($userObject)); } // CREATE USER WITH NEW REPO RIGHTS $userObject->personalRole->setAcl($newRepoUniqueId, $uRights[$userName]); // FORK MASK IF THERE IS ANY if ($file != "/" && $loggedUser->mergedRole->hasMask($repository->getId())) { $parentTree = $loggedUser->mergedRole->getMask($repository->getId())->getTree(); // Try to find a branch on the current selection $parts = explode("/", trim($file, "/")); while (($next = array_shift($parts)) !== null) { if (isset($parentTree[$next])) { $parentTree = $parentTree[$next]; } else { $parentTree = null; break; } } if ($parentTree != null) { $newMask = new AJXP_PermissionMask(); $newMask->updateTree($parentTree); } if (isset($newMask)) { $userObject->personalRole->setMask($newRepoUniqueId, $newMask); } } if (isset($httpVars["minisite"])) { if (isset($editingRepo)) { try { AuthService::deleteRole("AJXP_SHARED-" . $newRepoUniqueId); } catch (Exception $e) { } } $newRole = new AJXP_Role("AJXP_SHARED-" . $newRepoUniqueId); $r = AuthService::getRole("MINISITE"); if (is_a($r, "AJXP_Role")) { if ($httpVars["disable_download"]) { $f = AuthService::getRole("MINISITE_NODOWNLOAD"); if (is_a($f, "AJXP_Role")) { $r = $f->override($r); } } $allData = $r->getDataArray(); $newData = $newRole->getDataArray(); if (isset($allData["ACTIONS"][AJXP_REPO_SCOPE_SHARED])) { $newData["ACTIONS"][$newRepoUniqueId] = $allData["ACTIONS"][AJXP_REPO_SCOPE_SHARED]; } if (isset($allData["PARAMETERS"][AJXP_REPO_SCOPE_SHARED])) { $newData["PARAMETERS"][$newRepoUniqueId] = $allData["PARAMETERS"][AJXP_REPO_SCOPE_SHARED]; } $newRole->bunchUpdate($newData); AuthService::updateRole($newRole); $userObject->addRole($newRole); } } $userObject->save("superuser"); if ($this->watcher !== false) { // Register a watch on the current folder for shared user if ($uWatches[$userName]) { $this->watcher->setWatchOnFolder(new AJXP_Node("pydio://" . $newRepoUniqueId . "/"), $userName, MetaWatchRegister::$META_WATCH_USERS_CHANGE, array(AuthService::getLoggedUser()->getId())); } else { $this->watcher->removeWatchFromFolder(new AJXP_Node("pydio://" . $newRepoUniqueId . "/"), $userName, true); } } } if ($this->watcher !== false) { // Register a watch on the new repository root for current user if ($httpVars["self_watch_folder"] == "true") { $this->watcher->setWatchOnFolder(new AJXP_Node("pydio://" . $newRepoUniqueId . "/"), AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_BOTH); } else { $this->watcher->removeWatchFromFolder(new AJXP_Node("pydio://" . $newRepoUniqueId . "/"), AuthService::getLoggedUser()->getId()); } } foreach ($groups as $group) { $r = $uRights[$group]; /*if($group == "AJXP_GRP_/") { $group = "ROOT_ROLE"; }*/ $grRole = AuthService::getRole($group, true); $grRole->setAcl($newRepoUniqueId, $r); AuthService::updateRole($grRole); } if (array_key_exists("minisite", $httpVars) && $httpVars["minisite"] != true) { AJXP_Controller::applyHook(isset($editingRepo) ? "node.share.update" : "node.share.create", array('type' => 'repository', 'repository' => &$repository, 'accessDriver' => &$accessDriver, 'new_repository' => &$newRepo)); } return $newRepo; }
/** * @param $httpVars * @param array $users * @param array $groups * @throws Exception */ public function createUsersFromParameters($httpVars, &$users = array(), &$groups = array()) { $index = 0; $allowCrossUserSharing = ConfService::getCoreConf("ALLOW_CROSSUSERS_SHARING", "conf"); $allowSharedUsersCreation = ConfService::getCoreConf("USER_CREATE_USERS", "conf"); $loggedUser = AuthService::getLoggedUser(); $confDriver = ConfService::getConfStorageImpl(); $mess = ConfService::getMessages(); while (isset($httpVars[PARAM_USER_LOGIN_PREFIX . $index])) { $eType = $httpVars[PARAM_USER_ENTRY_TYPE . $index]; $rightString = ($httpVars[PARAM_USER_RIGHT_READ_PREFIX . $index] == "true" ? "r" : "") . ($httpVars[PARAM_USER_RIGHT_WRITE_PREFIX . $index] == "true" ? "w" : ""); $uWatch = false; if ($this->watcher !== false) { $uWatch = $httpVars[PARAM_USER_RIGHT_WATCH_PREFIX . $index] == "true" ? true : false; } if (empty($rightString)) { $index++; continue; } if ($eType == "user") { $u = AJXP_Utils::decodeSecureMagic($httpVars[PARAM_USER_LOGIN_PREFIX . $index], AJXP_SANITIZE_EMAILCHARS); $userExistsRead = AuthService::userExists($u); if (!$userExistsRead && !isset($httpVars[PARAM_USER_PASS_PREFIX . $index])) { $index++; continue; } else { if (AuthService::userExists($u, "w") && isset($httpVars[PARAM_USER_PASS_PREFIX . $index])) { throw new Exception(str_replace("%s", $u, $mess["share_center.222"])); } } if ($userExistsRead) { $userObject = $confDriver->createUserObject($u); if ($allowCrossUserSharing != true && (!$userObject->hasParent() || $userObject->getParent() != $loggedUser->getId())) { throw new Exception($mess["share_center.221"]); } } else { if (!$allowSharedUsersCreation || AuthService::isReservedUserId($u)) { throw new Exception($mess["share_center.220"]); } if (!empty($this->options["SHARED_USERS_TMP_PREFIX"]) && strpos($u, $this->options["SHARED_USERS_TMP_PREFIX"]) !== 0) { $u = $this->options["SHARED_USERS_TMP_PREFIX"] . $u; } } $entry = array("ID" => $u, "TYPE" => "user"); } else { $u = AJXP_Utils::decodeSecureMagic($httpVars[PARAM_USER_LOGIN_PREFIX . $index]); if (strpos($u, "/AJXP_TEAM/") === 0) { if (method_exists($confDriver, "teamIdToUsers")) { $teamUsers = $confDriver->teamIdToUsers(str_replace("/AJXP_TEAM/", "", $u)); foreach ($teamUsers as $userId) { $users[$userId] = array("ID" => $userId, "TYPE" => "user", "RIGHT" => $rightString); if ($this->watcher !== false) { $users[$userId]["WATCH"] = $uWatch; } } } $index++; continue; } $entry = array("ID" => $u, "TYPE" => "group"); } $entry["RIGHT"] = $rightString; $entry["PASSWORD"] = isset($httpVars[PARAM_USER_PASS_PREFIX . $index]) ? $httpVars[PARAM_USER_PASS_PREFIX . $index] : ""; if ($this->watcher !== false) { $entry["WATCH"] = $uWatch; } if ($entry["TYPE"] == "user") { $users[$entry["ID"]] = $entry; } else { if ($entry["ID"] == "AJXP_GRP_/") { $entry["ID"] = "AJXP_GRP_" . AuthService::filterBaseGroup("/"); } $groups[$entry["ID"]] = $entry; } $index++; } }