function ajxp_gluecode_updateRole($loginData, &$userObject) { $authPlug = ConfService::getAuthDriverImpl(); if (property_exists($authPlug, "drivers") && is_array($authPlug->drivers) && $authPlug->drivers["remote"]) { $authPlug = $authPlug->drivers["remote"]; } $rolesMap = $authPlug->getOption("ROLES_MAP"); if (!isset($rolesMap) || strlen($rolesMap) == 0) { return; } // String like {key:value,key2:value2,key3:value3} $rolesMap = explode(",", $rolesMap); $newMap = array(); foreach ($rolesMap as $value) { $parts = explode(":", trim($value)); $roleId = trim($parts[1]); $roleObject = AuthService::getRole($roleId); if ($roleObject != null) { $newMap[trim($parts[0])] = $roleObject; $userObject->removeRole($roleId); } } $rolesMap = $newMap; if (isset($loginData["roles"]) && is_array($loginData["roles"])) { foreach ($loginData["roles"] as $role) { if (isset($rolesMap[$role])) { $userObject->addRole($rolesMap[$role]); } } } }
function applyAction($actionName, $httpVars, $filesVar) { if ($actionName == "get_ajxp_actions") { AJXP_XMLWriter::header(); $this->sendActionsToClient(false, null, null); $authDriver = ConfService::getAuthDriverImpl(); $authDriver->sendActionsToClient(false, null, null); $confDriver = ConfService::getConfStorageImpl(); $confDriver->sendActionsToClient(false, null, null); AJXP_XMLWriter::close(); exit(1); } else { parent::applyAction($actionName, $httpVars, $filesVar); } }
function countAdminUsers() { $confDriver = ConfService::getConfStorageImpl(); $authDriver = ConfService::getAuthDriverImpl(); $count = 0; $users = $authDriver->listUsers(); foreach (array_keys($users) as $userId) { $userObject = $confDriver->createUserObject($userId); $userObject->load(); if ($userObject->isAdmin()) { $count++; } } return $count; }
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; } /* // 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; }
function switchAction($action, $httpVars, $fileVars) { if (!isset($this->actions[$action])) { return; } $loggedUser = AuthService::getLoggedUser(); if (ENABLE_USERS && !$loggedUser->isAdmin()) { return; } if ($action == "edit") { if (isset($httpVars["sub_action"])) { $action = $httpVars["sub_action"]; } } switch ($action) { //------------------------------------ // BASIC LISTING //------------------------------------ case "ls": $rootNodes = array("users" => array("LABEL" => "Users", "ICON" => "yast_kuser.png"), "repositories" => array("LABEL" => "Repositories", "ICON" => "folder_red.png"), "logs" => array("LABEL" => "Logs", "ICON" => "toggle_log.png"), "diagnostic" => array("LABEL" => "Diagnostic", "ICON" => "susehelpcenter.png")); $dir = isset($httpVars["dir"]) ? $httpVars["dir"] : ""; $splits = explode("/", $dir); if (count($splits)) { if ($splits[0] == "") { array_shift($splits); } if (count($splits)) { $strippedDir = strtolower(urldecode($splits[0])); } else { $strippedDir = ""; } } if (array_key_exists($strippedDir, $rootNodes)) { AJXP_XMLWriter::header(); if ($strippedDir == "users") { $this->listUsers(); } else { if ($strippedDir == "repositories") { $this->listRepositories(); } else { if ($strippedDir == "logs") { $this->listLogFiles($dir); } else { if ($strippedDir == "diagnostic") { $this->printDiagnostic(); } } } } AJXP_XMLWriter::close(); exit(1); } else { AJXP_XMLWriter::header(); print '<columns switchGridMode="filelist"><column messageString="Configuration Data" attributeName="ajxp_label" sortType="String"/></columns>'; foreach ($rootNodes as $key => $data) { $src = ''; if ($key == "logs") { $src = 'src="content.php?dir=' . $key . '"'; } print '<tree text="' . $data["LABEL"] . '" icon="' . $data["ICON"] . '" filename="/' . $key . '" parentname="/" ' . $src . ' />'; } AJXP_XMLWriter::close(); exit(1); } break; case "edit_user": $confStorage = ConfService::getConfStorageImpl(); $userId = $httpVars["user_id"]; $userObject = $confStorage->createUserObject($userId); //print_r($userObject); AJXP_XMLWriter::header("admin_data"); AJXP_XMLWriter::sendUserData($userObject, true); // Add WALLET DATA : DEFINITIONS AND VALUES print "<drivers>"; print 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") . "\"/>"; AJXP_XMLWriter::close("admin_data"); exit(1); break; case "create_user": if (!isset($_GET["new_user_login"]) || $_GET["new_user_login"] == "" || !isset($_GET["new_user_pwd"]) || $_GET["new_user_pwd"] == "") { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, "Wrong Arguments!"); AJXP_XMLWriter::close(); exit(1); } $forbidden = array("guest", "share"); if (AuthService::userExists($_GET["new_user_login"]) || in_array($_GET["new_user_login"], $forbidden)) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, "User already exists, please choose another login!"); AJXP_XMLWriter::close(); exit(1); } if (get_magic_quotes_gpc()) { $_GET["new_user_login"] = stripslashes($_GET["new_user_login"]); } $_GET["new_user_login"] = str_replace("'", "", $_GET["new_user_login"]); $confStorage = ConfService::getConfStorageImpl(); $newUser = $confStorage->createUserObject($_GET["new_user_login"]); $newUser->save(); AuthService::createUser($_GET["new_user_login"], $_GET["new_user_pwd"]); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage("User created successfully", null); AJXP_XMLWriter::reloadFileList($_GET["new_user_login"]); AJXP_XMLWriter::close(); exit(1); break; case "change_admin_right": $userId = $_GET["user_id"]; $confStorage = ConfService::getConfStorageImpl(); $user = $confStorage->createUserObject($userId); $user->setAdmin($_GET["right_value"] == "1" ? true : false); $user->save(); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage("Changed admin right for user " . $_GET["user_id"], null); AJXP_XMLWriter::reloadFileList(false); AJXP_XMLWriter::close(); exit(1); break; case "update_user_right": if (!isset($_GET["user_id"]) || !isset($_GET["repository_id"]) || !isset($_GET["right"]) || !AuthService::userExists($_GET["user_id"])) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, "Wrong arguments"); print "<update_checkboxes user_id=\"" . $_GET["user_id"] . "\" repository_id=\"" . $_GET["repository_id"] . "\" read=\"old\" write=\"old\"/>"; AJXP_XMLWriter::close(); exit(1); } $confStorage = ConfService::getConfStorageImpl(); $user = $confStorage->createUserObject($_GET["user_id"]); $user->setRight($_GET["repository_id"], $_GET["right"]); $user->save(); $loggedUser = AuthService::getLoggedUser(); if ($loggedUser->getId() == $user->getId()) { AuthService::updateUser($user); } AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage("Changed right for user " . $_GET["user_id"], null); print "<update_checkboxes user_id=\"" . $_GET["user_id"] . "\" repository_id=\"" . $_GET["repository_id"] . "\" read=\"" . $user->canRead($_GET["repository_id"]) . "\" write=\"" . $user->canWrite($_GET["repository_id"]) . "\"/>"; AJXP_XMLWriter::reloadRepositoryList(); AJXP_XMLWriter::close(); exit(1); break; case "save_repository_user_params": $userId = $_GET["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 = $_GET["repository_id"]; if (!array_key_exists($repoID, $wallet)) { $wallet[$repoID] = array(); } $options = $wallet[$repoID]; $this->parseParameters($_GET, $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("Saved data for user " . $_GET["user_id"], null); AJXP_XMLWriter::close(); exit(1); break; case "update_user_pwd": if (!isset($_GET["user_id"]) || !isset($_GET["user_pwd"]) || !AuthService::userExists($_GET["user_id"]) || trim($_GET["user_pwd"]) == "") { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, "Wrong Arguments!"); AJXP_XMLWriter::close(); exit(1); } $res = AuthService::updatePassword($_GET["user_id"], $_GET["user_pwd"]); AJXP_XMLWriter::header(); if ($res === true) { AJXP_XMLWriter::sendMessage("Password changed successfully for user " . $_GET["user_id"], null); } else { AJXP_XMLWriter::sendMessage(null, "Cannot update password : {$res}"); } AJXP_XMLWriter::close(); exit(1); break; case "get_drivers_definition": AJXP_XMLWriter::header("drivers"); print ConfService::availableDriversToXML("param"); AJXP_XMLWriter::close("drivers"); exit(1); break; case "create_repository": $options = array(); $repDef = $_GET; unset($repDef["get_action"]); $this->parseParameters($repDef, $options); if (count($options)) { $repDef["DRIVER_OPTIONS"] = $options; } // NOW SAVE THIS REPOSITORY! $newRep = ConfService::createRepositoryFromArray(0, $repDef); if (is_file(INSTALL_PATH . "/server/tests/plugins/test.ajxp_" . $newRep->getAccessType() . ".php")) { chdir(INSTALL_PATH . "/server/tests/plugins"); include INSTALL_PATH . "/server/tests/plugins/test.ajxp_" . $newRep->getAccessType() . ".php"; $className = "ajxp_" . $newRep->getAccessType(); $class = new $className(); $result = $class->doRepositoryTest($newRep); if (!$result) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $class->failedInfo); AJXP_XMLWriter::close(); exit(1); } } $res = ConfService::addRepository($newRep); AJXP_XMLWriter::header(); if ($res == -1) { AJXP_XMLWriter::sendMessage(null, "The conf directory is not writeable"); } else { AJXP_XMLWriter::sendMessage("Successfully created repository", null); AJXP_XMLWriter::reloadFileList($newRep->getDisplay()); AJXP_XMLWriter::reloadRepositoryList(); } AJXP_XMLWriter::close(); exit(1); break; case "edit_repository": $repId = $httpVars["repository_id"]; $repList = ConfService::getRootDirsList(); //print_r($repList); AJXP_XMLWriter::header("admin_data"); if (!isset($repList[$repId])) { AJXP_XMLWriter::close("admin_data"); exit(1); } $repository = $repList[$repId]; $nested = array(); print "<repository index=\"{$repId}\""; foreach ($repository as $name => $option) { if (!is_array($option)) { if (is_bool($option)) { $option = $option ? "true" : "false"; } print " {$name}=\"" . SystemTextEncoding::toUTF8(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_bool($optValue)) { $optValue = $optValue ? "true" : "false"; } print "<param name=\"{$key}\" value=\"{$optValue}\"/>"; } } print "</repository>"; } else { print "/>"; } print ConfService::availableDriversToXML("param", $repository->accessType); AJXP_XMLWriter::close("admin_data"); exit(1); break; case "edit_repository_label": case "edit_repository_data": $repId = $_GET["repository_id"]; $repo = ConfService::getRepositoryById($repId); $res = 0; if (isset($_GET["newLabel"])) { $repo->setDisplay(SystemTextEncoding::fromPostedFileName($_GET["newLabel"])); $res = ConfService::replaceRepository($repId, $repo); } else { $options = array(); $this->parseParameters($_GET, $options); if (count($options)) { foreach ($options as $key => $value) { $repo->addOption($key, $value); } } if (is_file(INSTALL_PATH . "/server/tests/plugins/test.ajxp_" . $repo->getAccessType() . ".php")) { chdir(INSTALL_PATH . "/server/tests/plugins"); include INSTALL_PATH . "/server/tests/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(); exit(1); } } ConfService::replaceRepository($repId, $repo); } AJXP_XMLWriter::header(); if ($res == -1) { AJXP_XMLWriter::sendMessage(null, "Error while trying to edit repository"); } else { AJXP_XMLWriter::sendMessage("Successfully edited repository", null); AJXP_XMLWriter::reloadFileList(isset($_GET["newLabel"]) ? SystemTextEncoding::fromPostedFileName($_GET["newLabel"]) : false); AJXP_XMLWriter::reloadRepositoryList(); } AJXP_XMLWriter::close(); exit(1); case "delete": if (isset($httpVars["repository_id"])) { $repId = $httpVars["repository_id"]; //if(get_magic_quotes_gpc()) $repLabel = stripslashes($repLabel); $res = ConfService::deleteRepository($repId); AJXP_XMLWriter::header(); if ($res == -1) { AJXP_XMLWriter::sendMessage(null, "The conf directory is not writeable"); } else { AJXP_XMLWriter::sendMessage("Successfully deleted repository", null); AJXP_XMLWriter::reloadFileList(false); AJXP_XMLWriter::reloadRepositoryList(); } AJXP_XMLWriter::close(); exit(1); } else { $forbidden = array("guest", "share"); if (!isset($httpVars["user_id"]) || $httpVars["user_id"] == "" || in_array($_GET["user_id"], $forbidden) || $loggedUser->getId() == $httpVars["user_id"]) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, "Wrong Arguments!"); AJXP_XMLWriter::close(); exit(1); } $res = AuthService::deleteUser($httpVars["user_id"]); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage("User successfully erased", null); AJXP_XMLWriter::reloadFileList($httpVars["user_id"]); AJXP_XMLWriter::close(); exit(1); } break; default: break; } return; }
/** * Dynamically replace XML keywords with their live values. * AJXP_SERVER_ACCESS, AJXP_MIMES_*,AJXP_ALL_MESSAGES, etc. * @static * @param string $xml * @param bool $stripSpaces * @return mixed */ public static function replaceAjxpXmlKeywords($xml, $stripSpaces = false) { $messages = ConfService::getMessages(); $confMessages = ConfService::getMessagesConf(); $matches = array(); if (isset($_SESSION["AJXP_SERVER_PREFIX_URI"])) { //$xml = str_replace("AJXP_THEME_FOLDER", $_SESSION["AJXP_SERVER_PREFIX_URI"].AJXP_THEME_FOLDER, $xml); $xml = str_replace("AJXP_SERVER_ACCESS", $_SESSION["AJXP_SERVER_PREFIX_URI"] . AJXP_SERVER_ACCESS, $xml); } else { //$xml = str_replace("AJXP_THEME_FOLDER", AJXP_THEME_FOLDER, $xml); $xml = str_replace("AJXP_SERVER_ACCESS", AJXP_SERVER_ACCESS, $xml); } $xml = str_replace("AJXP_APPLICATION_TITLE", ConfService::getCoreConf("APPLICATION_TITLE"), $xml); $xml = str_replace("AJXP_MIMES_EDITABLE", AJXP_Utils::getAjxpMimes("editable"), $xml); $xml = str_replace("AJXP_MIMES_IMAGE", AJXP_Utils::getAjxpMimes("image"), $xml); $xml = str_replace("AJXP_MIMES_AUDIO", AJXP_Utils::getAjxpMimes("audio"), $xml); $xml = str_replace("AJXP_MIMES_ZIP", AJXP_Utils::getAjxpMimes("zip"), $xml); $authDriver = ConfService::getAuthDriverImpl(); if ($authDriver != NULL) { $loginRedirect = $authDriver->getLoginRedirect(); $xml = str_replace("AJXP_LOGIN_REDIRECT", $loginRedirect !== false ? "'" . $loginRedirect . "'" : "false", $xml); } $xml = str_replace("AJXP_REMOTE_AUTH", "false", $xml); $xml = str_replace("AJXP_NOT_REMOTE_AUTH", "true", $xml); $xml = str_replace("AJXP_ALL_MESSAGES", "MessageHash=" . json_encode(ConfService::getMessages()) . ";", $xml); if (preg_match_all("/AJXP_MESSAGE(\\[.*?\\])/", $xml, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $messId = str_replace("]", "", str_replace("[", "", $match[1])); $xml = str_replace("AJXP_MESSAGE[{$messId}]", $messages[$messId], $xml); } } if (preg_match_all("/CONF_MESSAGE(\\[.*?\\])/", $xml, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $messId = str_replace(array("[", "]"), "", $match[1]); $message = $messId; if (array_key_exists($messId, $confMessages)) { $message = $confMessages[$messId]; } $xml = str_replace("CONF_MESSAGE[{$messId}]", AJXP_Utils::xmlEntities($message), $xml); } } if (preg_match_all("/MIXIN_MESSAGE(\\[.*?\\])/", $xml, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $messId = str_replace(array("[", "]"), "", $match[1]); $message = $messId; if (array_key_exists($messId, $confMessages)) { $message = $confMessages[$messId]; } $xml = str_replace("MIXIN_MESSAGE[{$messId}]", AJXP_Utils::xmlEntities($message), $xml); } } if ($stripSpaces) { $xml = preg_replace("/[\n\r]?/", "", $xml); $xml = preg_replace("/\t/", " ", $xml); } $xml = str_replace(array('xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"', 'xsi:noNamespaceSchemaLocation="file:../core.ajaxplorer/ajxp_registry.xsd"'), "", $xml); $tab = array(&$xml); AJXP_Controller::applyIncludeHook("xml.filter", $tab); return $xml; }
ConfService::setLanguage($_COOKIE["AJXP_lang"]); } } //------------------------------------------------------------ // SPECIAL HANDLING FOR FANCY UPLOADER RIGHTS FOR THIS ACTION //------------------------------------------------------------ if (AuthService::usersEnabled()) { $loggedUser = AuthService::getLoggedUser(); if ($action == "upload" && ($loggedUser == null || !$loggedUser->canWrite(ConfService::getCurrentRepositoryId() . "")) && isset($_FILES['Filedata'])) { header('HTTP/1.0 ' . '410 Not authorized'); die('Error 410 Not authorized!'); } } // THIS FIRST DRIVERS DO NOT NEED ID CHECK //$ajxpDriver = AJXP_PluginsService::findPlugin("gui", "ajax"); $authDriver = ConfService::getAuthDriverImpl(); // DRIVERS BELOW NEED IDENTIFICATION CHECK if (!AuthService::usersEnabled() || ConfService::getCoreConf("ALLOW_GUEST_BROWSING", "auth") || AuthService::getLoggedUser() != null) { $confDriver = ConfService::getConfStorageImpl(); $Driver = ConfService::loadRepositoryDriver(); } AJXP_PluginsService::getInstance()->initActivePlugins(); require_once AJXP_BIN_FOLDER . "/class.AJXP_Controller.php"; $xmlResult = AJXP_Controller::findActionAndApply($action, array_merge($_GET, $_POST), $_FILES); if ($xmlResult !== false && $xmlResult != "") { AJXP_XMLWriter::header(); print $xmlResult; AJXP_XMLWriter::close(); } else { if (isset($requireAuth) && AJXP_Controller::$lastActionNeedsAuth) { AJXP_XMLWriter::header();
} } if ($repository == null) { AJXP_Logger::debug("not found, dying {$repositoryId}"); die('You are not allowed to access this service'); } $rId = $repositoryId; $rootDir = new AJXP_Sabre_Collection("/", $repository, null); $server = new Sabre\DAV\Server($rootDir); $server->setBaseUri($baseURI . "/" . $pathBase); } else { $rootDir = new AJXP_Sabre_RootCollection("root"); $server = new Sabre\DAV\Server($rootDir); $server->setBaseUri($baseURI); } if ((AJXP_Sabre_AuthBackendBasic::detectBasicHeader() || ConfService::getCoreConf("WEBDAV_FORCE_BASIC")) && ConfService::getAuthDriverImpl()->getOption("TRANSMIT_CLEAR_PASS")) { $authBackend = new AJXP_Sabre_AuthBackendBasic($rId); } else { $authBackend = new AJXP_Sabre_AuthBackendDigest($rId); } $authPlugin = new Sabre\DAV\Auth\Plugin($authBackend, ConfService::getCoreConf("WEBDAV_DIGESTREALM")); $server->addPlugin($authPlugin); if (!is_dir(AJXP_DATA_PATH . "/plugins/server.sabredav")) { mkdir(AJXP_DATA_PATH . "/plugins/server.sabredav", 0755); $fp = fopen(AJXP_DATA_PATH . "/plugins/server.sabredav/locks", "w"); fwrite($fp, ""); fclose($fp); } $lockBackend = new Sabre\DAV\Locks\Backend\File(AJXP_DATA_PATH . "/plugins/server.sabredav/locks"); $lockPlugin = new Sabre\DAV\Locks\Plugin($lockBackend); $server->addPlugin($lockPlugin);
static function replaceAjxpXmlKeywords($xml, $stripSpaces = false) { $messages = ConfService::getMessages(); $matches = array(); $xml = str_replace("AJXP_CLIENT_RESOURCES_FOLDER", CLIENT_RESOURCES_FOLDER, $xml); if (isset($_SESSION["AJXP_SERVER_PREFIX_URI"])) { $xml = str_replace("AJXP_THEME_FOLDER", $_SESSION["AJXP_SERVER_PREFIX_URI"] . AJXP_THEME_FOLDER, $xml); $xml = str_replace("AJXP_SERVER_ACCESS", $_SESSION["AJXP_SERVER_PREFIX_URI"] . SERVER_ACCESS, $xml); } else { $xml = str_replace("AJXP_THEME_FOLDER", AJXP_THEME_FOLDER, $xml); $xml = str_replace("AJXP_SERVER_ACCESS", SERVER_ACCESS, $xml); } $xml = str_replace("AJXP_MIMES_EDITABLE", AJXP_Utils::getAjxpMimes("editable"), $xml); $xml = str_replace("AJXP_MIMES_IMAGE", AJXP_Utils::getAjxpMimes("image"), $xml); $xml = str_replace("AJXP_MIMES_AUDIO", AJXP_Utils::getAjxpMimes("audio"), $xml); $xml = str_replace("AJXP_MIMES_ZIP", AJXP_Utils::getAjxpMimes("zip"), $xml); $loginRedirect = ConfService::getAuthDriverImpl()->getLoginRedirect(); $xml = str_replace("AJXP_LOGIN_REDIRECT", $loginRedirect !== false ? "'" . $loginRedirect . "'" : "false", $xml); $xml = str_replace("AJXP_REMOTE_AUTH", "false", $xml); $xml = str_replace("AJXP_NOT_REMOTE_AUTH", "true", $xml); $xml = str_replace("AJXP_ALL_MESSAGES", "MessageHash=" . json_encode(ConfService::getMessages()) . ";", $xml); if (preg_match_all("/AJXP_MESSAGE(\\[.*?\\])/", $xml, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $messId = str_replace("]", "", str_replace("[", "", $match[1])); $xml = str_replace("AJXP_MESSAGE[{$messId}]", $messages[$messId], $xml); } } if ($stripSpaces) { $xml = preg_replace("/[\n\r]?/", "", $xml); $xml = preg_replace("/\t/", " ", $xml); } return $xml; }
function switchAction($action, $httpVars, $fileVars) { if (!isset($this->actions[$action])) { return; } parent::accessPreprocess($action, $httpVars, $fileVars); $loggedUser = AuthService::getLoggedUser(); if (ENABLE_USERS && !$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("repositories" => array("LABEL" => $mess["ajxp_conf.3"], "ICON" => "folder_red.png"), "users" => array("LABEL" => $mess["ajxp_conf.2"], "ICON" => "yast_kuser.png"), "roles" => array("LABEL" => $mess["ajxp_conf.69"], "ICON" => "user_group_new.png"), "files" => array("LABEL" => $mess["ajxp_shared.3"], "ICON" => "html.png"), "logs" => array("LABEL" => $mess["ajxp_conf.4"], "ICON" => "toggle_log.png"), "diagnostic" => array("LABEL" => $mess["ajxp_conf.5"], "ICON" => "susehelpcenter.png")); $dir = isset($httpVars["dir"]) ? $httpVars["dir"] : ""; $splits = explode("/", $dir); if (count($splits)) { if ($splits[0] == "") { array_shift($splits); } if (count($splits)) { $strippedDir = strtolower(urldecode($splits[0])); } else { $strippedDir = ""; } } if (array_key_exists($strippedDir, $rootNodes)) { AJXP_XMLWriter::header(); if ($strippedDir == "users") { $this->listUsers(); } else { if ($strippedDir == "roles") { $this->listRoles(); } else { if ($strippedDir == "repositories") { $this->listRepositories(); } else { if ($strippedDir == "logs") { $this->listLogFiles($dir); } else { if ($strippedDir == "diagnostic") { $this->printDiagnostic(); } else { if ($strippedDir == "files") { $this->listSharedFiles(); } } } } } } AJXP_XMLWriter::close(); exit(1); } else { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendFilesListComponentConfig('<columns switchGridMode="filelist"><column messageId="ajxp_conf.1" attributeName="ajxp_label" sortType="String"/></columns>'); foreach ($rootNodes as $key => $data) { $src = ''; if ($key == "logs") { $src = 'src="content.php?get_action=ls&dir=' . $key . '"'; } print '<tree text="' . $data["LABEL"] . '" icon="' . $data["ICON"] . '" filename="/' . $key . '" parentname="/" ' . $src . ' />'; } AJXP_XMLWriter::close(); exit(1); } break; case "stat": header("Content-type:application/json"); print '{"mode":true}'; exit(1); break; case "create_role": $roleId = $httpVars["role_id"]; 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 = $httpVars["role_id"]; $role = AuthService::getRole($roleId); 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; //exit(1); } $role = AuthService::getRole($httpVars["role_id"]); $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(); //exit(1); 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"]); $actions = array_map("trim", 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 == "") { 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 "edit_user": $confStorage = ConfService::getConfStorageImpl(); $userId = $httpVars["user_id"]; $userObject = $confStorage->createUserObject($userId); //print_r($userObject); AJXP_XMLWriter::header("admin_data"); AJXP_XMLWriter::sendUserData($userObject, true); // Add WALLET DATA : DEFINITIONS AND VALUES print "<drivers>"; print 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=\"{$roleId}\"/>"; } print "</ajxp_roles>"; AJXP_XMLWriter::close("admin_data"); exit(1); 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(); exit(1); } $forbidden = array("guest", "share"); if (AuthService::userExists($httpVars["new_user_login"]) || in_array($httpVars["new_user_login"], $forbidden)) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.43"]); AJXP_XMLWriter::close(); exit(1); } if (get_magic_quotes_gpc()) { $httpVars["new_user_login"] = stripslashes($httpVars["new_user_login"]); } $httpVars["new_user_login"] = str_replace("'", "", $httpVars["new_user_login"]); $confStorage = ConfService::getConfStorageImpl(); $newUser = $confStorage->createUserObject($httpVars["new_user_login"]); $newUser->save(); AuthService::createUser($httpVars["new_user_login"], $httpVars["new_user_pwd"]); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.44"], null); AJXP_XMLWriter::reloadFileList($httpVars["new_user_login"]); AJXP_XMLWriter::close(); exit(1); break; case "change_admin_right": $userId = $httpVars["user_id"]; $confStorage = ConfService::getConfStorageImpl(); $user = $confStorage->createUserObject($userId); $user->setAdmin($httpVars["right_value"] == "1" ? true : false); $user->save(); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.45"] . $httpVars["user_id"], null); AJXP_XMLWriter::reloadFileList(false); AJXP_XMLWriter::close(); exit(1); 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(); exit(1); } $confStorage = ConfService::getConfStorageImpl(); $user = $confStorage->createUserObject($httpVars["user_id"]); $user->setRight($httpVars["repository_id"], $httpVars["right"]); $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"])) { 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"]; } 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_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(); exit(1); 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(); exit(1); } $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(); exit(1); break; case "get_drivers_definition": AJXP_XMLWriter::header("drivers"); print ConfService::availableDriversToXML("param"); AJXP_XMLWriter::close("drivers"); exit(1); break; case "create_repository": $options = array(); $repDef = $httpVars; unset($repDef["get_action"]); $this->parseParameters($repDef, $options); if (count($options)) { $repDef["DRIVER_OPTIONS"] = $options; } // NOW SAVE THIS REPOSITORY! $newRep = ConfService::createRepositoryFromArray(0, $repDef); if (is_file(INSTALL_PATH . "/server/tests/plugins/test.ajxp_" . $newRep->getAccessType() . ".php")) { chdir(INSTALL_PATH . "/server/tests/plugins"); include INSTALL_PATH . "/server/tests/plugins/test.ajxp_" . $newRep->getAccessType() . ".php"; $className = "ajxp_" . $newRep->getAccessType(); $class = new $className(); $result = $class->doRepositoryTest($newRep); if (!$result) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $class->failedInfo); AJXP_XMLWriter::close(); exit(1); } } if ($this->repositoryExists($newRep->getDisplay())) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.50"]); AJXP_XMLWriter::close(); exit(1); } $res = ConfService::addRepository($newRep); AJXP_XMLWriter::header(); if ($res == -1) { AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.51"]); } else { $confStorage = ConfService::getConfStorageImpl(); $loggedUser = AuthService::getLoggedUser(); $loggedUser->setRight($newRep->getUniqueId(), "rw"); $loggedUser->save(); AuthService::updateUser($loggedUser); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.52"], null); AJXP_XMLWriter::reloadFileList($newRep->getDisplay()); AJXP_XMLWriter::reloadRepositoryList(); } AJXP_XMLWriter::close(); exit(1); break; case "edit_repository": $repId = $httpVars["repository_id"]; $repList = ConfService::getRootDirsList(); //print_r($repList); AJXP_XMLWriter::header("admin_data"); if (!isset($repList[$repId])) { AJXP_XMLWriter::close("admin_data"); exit(1); } $repository = $repList[$repId]; $nested = array(); print "<repository index=\"{$repId}\""; foreach ($repository as $name => $option) { 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}\"/>"; } } } print "</repository>"; } else { print "/>"; } $pServ = AJXP_PluginsService::getInstance(); $plug = $pServ->getPluginById("access." . $repository->accessType); $manifest = $plug->getManifestRawContent("server_settings/param"); print "<ajxpdriver name=\"" . $repository->accessType . "\">{$manifest}</ajxpdriver>"; print "<metasources>"; $metas = $pServ->getPluginsByType("meta"); foreach ($metas as $metaPlug) { print "<meta id=\"" . $metaPlug->getId() . "\">"; $manifest = $metaPlug->getManifestRawContent("server_settings/param"); print $manifest; print "</meta>"; } print "</metasources>"; AJXP_XMLWriter::close("admin_data"); exit(1); break; case "edit_repository_label": case "edit_repository_data": $repId = $httpVars["repository_id"]; $repo = ConfService::getRepositoryById($repId); $res = 0; if (isset($httpVars["newLabel"])) { $newLabel = SystemTextEncoding::fromPostedFileName($httpVars["newLabel"]); if ($this->repositoryExists($newLabel)) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.50"]); AJXP_XMLWriter::close(); exit(1); } $repo->setDisplay($newLabel); $res = ConfService::replaceRepository($repId, $repo); } else { $options = array(); $this->parseParameters($httpVars, $options); if (count($options)) { foreach ($options as $key => $value) { $repo->addOption($key, $value); } } if (is_file(INSTALL_PATH . "/server/tests/plugins/test.ajxp_" . $repo->getAccessType() . ".php")) { chdir(INSTALL_PATH . "/server/tests/plugins"); include INSTALL_PATH . "/server/tests/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(); exit(1); } } 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"]) ? SystemTextEncoding::fromPostedFileName($httpVars["newLabel"]) : false); AJXP_XMLWriter::reloadRepositoryList(); } AJXP_XMLWriter::close(); exit(1); case "add_meta_source": $repId = $httpVars["repository_id"]; $repo = ConfService::getRepositoryById($repId); $metaSourceType = $httpVars["new_meta_source"]; $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; $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); $metaSourceId = $httpVars["plugId"]; $repoOptions = $repo->getOption("META_SOURCES"); if (is_array($repoOptions) && array_key_exists($metaSourceId, $repoOptions)) { unset($repoOptions[$metaSourceId]); $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); $metaSourceId = $httpVars["plugId"]; $options = array(); $this->parseParameters($httpVars, $options); $repoOptions = $repo->getOption("META_SOURCES"); if (!is_array($repoOptions)) { $repoOptions = array(); } $repoOptions[$metaSourceId] = $options; $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"]; //if(get_magic_quotes_gpc()) $repLabel = stripslashes($repLabel); $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(); exit(1); } else { if (isset($httpVars["shared_file"])) { AJXP_XMLWriter::header(); $element = basename($httpVars["shared_file"]); $publicletData = $this->loadPublicletData(PUBLIC_DOWNLOAD_FOLDER . "/" . $element . ".php"); unlink(PUBLIC_DOWNLOAD_FOLDER . "/" . $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 { $forbidden = array("guest", "share"); if (!isset($httpVars["user_id"]) || $httpVars["user_id"] == "" || in_array($httpVars["user_id"], $forbidden) || $loggedUser->getId() == $httpVars["user_id"]) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]); AJXP_XMLWriter::close(); exit(1); } $res = AuthService::deleteUser($httpVars["user_id"]); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["ajxp_conf.60"], null); AJXP_XMLWriter::reloadDataNode(); AJXP_XMLWriter::close(); exit(1); } } } 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; 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; }
/** * Static function for deleting a user * * @param String $userId * @param Array $deletedSubUsers */ static function deleteUser($userId, &$deletedSubUsers) { $storage = ConfService::getConfStorageImpl(); $serialDir = AJXP_VarsFilter::filter($storage->getOption("USERS_DIRPATH")); $files = glob($serialDir . "/" . $userId . "/*.ser"); if (is_array($files) && count($files)) { foreach ($files as $file) { unlink($file); } } if (is_dir($serialDir . "/" . $userId)) { rmdir($serialDir . "/" . $userId); } $authDriver = ConfService::getAuthDriverImpl(); $confDriver = ConfService::getConfStorageImpl(); $users = $authDriver->listUsers(); foreach (array_keys($users) as $id) { $object = $confDriver->createUserObject($id); if ($object->hasParent() && $object->getParent() == $userId) { AJXP_User::deleteUser($id, $deletedSubUsers); $deletedSubUsers[] = $id; } } }
protected function listUsersIds($baseGroup = "/") { $authDriver = ConfService::getAuthDriverImpl(); $pairs = $authDriver->listUsers($baseGroup); return array_keys($pairs); }
public function computeBootConf() { if (isset($_GET["server_prefix_uri"])) { $_SESSION["AJXP_SERVER_PREFIX_URI"] = str_replace("_UP_", "..", $_GET["server_prefix_uri"]); } $currentIsMinisite = strpos(session_name(), "AjaXplorer_Shared") === 0; $config = array(); $config["ajxpResourcesFolder"] = "plugins/gui.ajax/res"; if ($currentIsMinisite) { $config["ajxpServerAccess"] = "index_shared.php"; } else { $config["ajxpServerAccess"] = AJXP_SERVER_ACCESS; } $config["zipEnabled"] = ConfService::zipBrowsingEnabled(); $config["multipleFilesDownloadEnabled"] = ConfService::zipCreationEnabled(); $customIcon = $this->getFilteredOption("CUSTOM_ICON"); self::filterXml($customIcon); $config["customWording"] = array("welcomeMessage" => $this->getFilteredOption("CUSTOM_WELCOME_MESSAGE"), "title" => ConfService::getCoreConf("APPLICATION_TITLE"), "icon" => $customIcon, "iconWidth" => $this->getFilteredOption("CUSTOM_ICON_WIDTH"), "iconHeight" => $this->getFilteredOption("CUSTOM_ICON_HEIGHT"), "iconOnly" => $this->getFilteredOption("CUSTOM_ICON_ONLY"), "titleFontSize" => $this->getFilteredOption("CUSTOM_FONT_SIZE")); $cIcBin = $this->getFilteredOption("CUSTOM_ICON_BINARY"); if (!empty($cIcBin)) { $config["customWording"]["icon_binary_url"] = "get_action=get_global_binary_param&binary_id=" . $cIcBin; } $config["usersEnabled"] = AuthService::usersEnabled(); $config["loggedUser"] = AuthService::getLoggedUser() != null; $config["currentLanguage"] = ConfService::getLanguage(); $config["session_timeout"] = intval(ini_get("session.gc_maxlifetime")); $timeoutTime = $this->getFilteredOption("CLIENT_TIMEOUT_TIME"); if (empty($timeoutTime)) { $to = $config["session_timeout"]; } else { $to = $timeoutTime; } if ($currentIsMinisite) { $to = -1; } $config["client_timeout"] = intval($to); $config["client_timeout_warning"] = floatval($this->getFilteredOption("CLIENT_TIMEOUT_WARN")); $config["availableLanguages"] = ConfService::getConf("AVAILABLE_LANG"); $config["usersEditable"] = ConfService::getAuthDriverImpl()->usersEditable(); $config["ajxpVersion"] = AJXP_VERSION; $config["ajxpVersionDate"] = AJXP_VERSION_DATE; $analytic = $this->getFilteredOption('GOOGLE_ANALYTICS_ID'); if (!empty($analytic)) { $config["googleAnalyticsData"] = array("id" => $analytic, "domain" => $this->getFilteredOption('GOOGLE_ANALYTICS_DOMAIN'), "event" => $this->getFilteredOption('GOOGLE_ANALYTICS_EVENT')); } $config["i18nMessages"] = ConfService::getMessages(); $config["SECURE_TOKEN"] = AuthService::generateSecureToken(); $config["streaming_supported"] = "true"; $config["theme"] = $this->pluginConf["GUI_THEME"]; return $config; }
static function driverSupportsAuthSchemes() { $authDriver = ConfService::getAuthDriverImpl(); return $authDriver->supportsAuthSchemes(); }
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; }
public function switchAction($action, $httpVars, $fileVars) { if (!isset($this->actions[$action])) { return; } $xmlBuffer = ""; foreach ($httpVars as $getName => $getValue) { ${$getName} = AJXP_Utils::securePath($getValue); } if (isset($dir) && $action != "upload") { $dir = SystemTextEncoding::fromUTF8($dir); } $mess = ConfService::getMessages(); switch ($action) { //------------------------------------ // SWITCH THE ROOT REPOSITORY //------------------------------------ case "switch_repository": if (!isset($repository_id)) { break; } $dirList = ConfService::getRepositoriesList(); /** @var $repository_id string */ if (!isset($dirList[$repository_id])) { $errorMessage = "Trying to switch to an unkown repository!"; break; } ConfService::switchRootDir($repository_id); // Load try to init the driver now, to trigger an exception // if it's not loading right. ConfService::loadRepositoryDriver(); if (AuthService::usersEnabled() && AuthService::getLoggedUser() != null) { $user = AuthService::getLoggedUser(); $activeRepId = ConfService::getCurrentRepositoryId(); $user->setArrayPref("history", "last_repository", $activeRepId); $user->save("user"); } //$logMessage = "Successfully Switched!"; $this->logInfo("Switch Repository", array("rep. id" => $repository_id)); break; //------------------------------------ // SEND XML REGISTRY //------------------------------------ //------------------------------------ // SEND XML REGISTRY //------------------------------------ case "get_xml_registry": case "state": $regDoc = AJXP_PluginsService::getXmlRegistry(); $changes = AJXP_Controller::filterRegistryFromRole($regDoc); if ($changes) { AJXP_PluginsService::updateXmlRegistry($regDoc); } $clone = $regDoc->cloneNode(true); $clonePath = new DOMXPath($clone); $serverCallbacks = $clonePath->query("//serverCallback|hooks"); foreach ($serverCallbacks as $callback) { $callback->parentNode->removeChild($callback); } $xPath = ''; if (isset($httpVars["xPath"])) { $xPath = ltrim(AJXP_Utils::securePath($httpVars["xPath"]), "/"); } if (!empty($xPath)) { $nodes = $clonePath->query($xPath); if ($httpVars["format"] == "json") { $data = AJXP_XMLWriter::xmlToArray($nodes->item(0)); HTMLWriter::charsetHeader("application/json"); echo json_encode($data); } else { AJXP_XMLWriter::header("ajxp_registry_part", array("xPath" => $xPath)); if ($nodes->length) { print AJXP_XMLWriter::replaceAjxpXmlKeywords($clone->saveXML($nodes->item(0))); } AJXP_XMLWriter::close("ajxp_registry_part"); } } else { AJXP_Utils::safeIniSet("zlib.output_compression", "4096"); if ($httpVars["format"] == "json") { $data = AJXP_XMLWriter::xmlToArray($clone); HTMLWriter::charsetHeader("application/json"); echo json_encode($data); } else { header('Content-Type: application/xml; charset=UTF-8'); print AJXP_XMLWriter::replaceAjxpXmlKeywords($clone->saveXML()); } } break; //------------------------------------ // BOOKMARK BAR //------------------------------------ //------------------------------------ // BOOKMARK BAR //------------------------------------ case "get_bookmarks": $bmUser = null; if (AuthService::usersEnabled() && AuthService::getLoggedUser() != null) { $bmUser = AuthService::getLoggedUser(); } else { if (!AuthService::usersEnabled()) { $confStorage = ConfService::getConfStorageImpl(); $bmUser = $confStorage->createUserObject("shared"); } } if ($bmUser == null) { AJXP_XMLWriter::header(); AJXP_XMLWriter::close(); } $driver = ConfService::loadRepositoryDriver(); if (!is_a($driver, "AjxpWrapperProvider")) { $driver = false; } if (isset($httpVars["bm_action"]) && isset($httpVars["bm_path"])) { $bmPath = AJXP_Utils::decodeSecureMagic($httpVars["bm_path"]); if ($httpVars["bm_action"] == "add_bookmark") { $title = ""; if (isset($httpVars["bm_title"])) { $title = AJXP_Utils::decodeSecureMagic($httpVars["bm_title"]); } if ($title == "" && $bmPath == "/") { $title = ConfService::getCurrentRootDirDisplay(); } $bmUser->addBookMark($bmPath, $title); if ($driver) { $node = new AJXP_Node($driver->getResourceUrl($bmPath)); $node->setMetadata("ajxp_bookmarked", array("ajxp_bookmarked" => "true"), true, AJXP_METADATA_SCOPE_REPOSITORY, true); } } else { if ($httpVars["bm_action"] == "delete_bookmark") { $bmUser->removeBookmark($bmPath); if ($driver) { $node = new AJXP_Node($driver->getResourceUrl($bmPath)); $node->removeMetadata("ajxp_bookmarked", true, AJXP_METADATA_SCOPE_REPOSITORY, true); } } else { if ($httpVars["bm_action"] == "rename_bookmark" && isset($httpVars["bm_title"])) { $title = AJXP_Utils::decodeSecureMagic($httpVars["bm_title"]); $bmUser->renameBookmark($bmPath, $title); } } } AJXP_Controller::applyHook("msg.instant", array("<reload_bookmarks/>", ConfService::getRepository()->getId())); if (AuthService::usersEnabled() && AuthService::getLoggedUser() != null) { $bmUser->save("user"); AuthService::updateUser($bmUser); } else { if (!AuthService::usersEnabled()) { $bmUser->save("user"); } } } AJXP_XMLWriter::header(); AJXP_XMLWriter::writeBookmarks($bmUser->getBookmarks(), true, isset($httpVars["format"]) ? $httpVars["format"] : "legacy"); AJXP_XMLWriter::close(); break; //------------------------------------ // SAVE USER PREFERENCE //------------------------------------ //------------------------------------ // SAVE USER PREFERENCE //------------------------------------ case "save_user_pref": $userObject = AuthService::getLoggedUser(); $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"); AuthService::updateUser($userObject); //setcookie("AJXP_$prefName", $prefValue); $i++; } header("Content-Type:text/plain"); print "SUCCESS"; break; //------------------------------------ // SAVE USER PREFERENCE //------------------------------------ //------------------------------------ // SAVE USER PREFERENCE //------------------------------------ case "custom_data_edit": case "user_create_user": $data = array(); if ($action == "user_create_user" && isset($httpVars["NEW_new_user_id"])) { $updating = false; AJXP_Utils::parseStandardFormParameters($httpVars, $data, null, "NEW_"); $original_id = AJXP_Utils::decodeSecureMagic($data["new_user_id"]); $data["new_user_id"] = AJXP_Utils::decodeSecureMagic($data["new_user_id"], AJXP_SANITIZE_EMAILCHARS); if ($original_id != $data["new_user_id"]) { throw new Exception(str_replace("%s", $data["new_user_id"], $mess["ajxp_conf.127"])); } if (AuthService::userExists($data["new_user_id"], "w")) { throw new Exception($mess["ajxp_conf.43"]); } $loggedUser = AuthService::getLoggedUser(); $limit = $loggedUser->personalRole->filterParameterValue("core.conf", "USER_SHARED_USERS_LIMIT", AJXP_REPO_SCOPE_ALL, ""); if (!empty($limit) && intval($limit) > 0) { $count = count($this->getUserChildren($loggedUser->getId())); if ($count >= $limit) { throw new Exception($mess['483']); } } AuthService::createUser($data["new_user_id"], $data["new_password"]); $userObject = ConfService::getConfStorageImpl()->createUserObject($data["new_user_id"]); $userObject->setParent($loggedUser->getId()); $userObject->save('superuser'); $userObject->personalRole->clearAcls(); $userObject->setGroupPath($loggedUser->getGroupPath()); $userObject->setProfile("shared"); } else { if ($action == "user_create_user" && isset($httpVars["NEW_existing_user_id"])) { $updating = true; AJXP_Utils::parseStandardFormParameters($httpVars, $data, null, "NEW_"); $userId = $data["existing_user_id"]; if (!AuthService::userExists($userId)) { throw new Exception("Cannot find user"); } $userObject = ConfService::getConfStorageImpl()->createUserObject($userId); if ($userObject->getParent() != AuthService::getLoggedUser()->getId()) { throw new Exception("Cannot find user"); } if (!empty($data["new_password"])) { AuthService::updatePassword($userId, $data["new_password"]); } } else { $updating = false; $userObject = AuthService::getLoggedUser(); AJXP_Utils::parseStandardFormParameters($httpVars, $data, null, "PREFERENCES_"); } } $paramNodes = AJXP_PluginsService::searchAllManifests("//server_settings/param[contains(@scope,'user') and @expose='true']", "node", false, false, true); $rChanges = false; if (is_array($paramNodes) && count($paramNodes)) { foreach ($paramNodes as $xmlNode) { if ($xmlNode->getAttribute("expose") == "true") { $parentNode = $xmlNode->parentNode->parentNode; $pluginId = $parentNode->getAttribute("id"); if (empty($pluginId)) { $pluginId = $parentNode->nodeName . "." . $parentNode->getAttribute("name"); } $name = $xmlNode->getAttribute("name"); if (isset($data[$name]) || $data[$name] === "") { if ($data[$name] == "__AJXP_VALUE_SET__") { continue; } if ($data[$name] === "" || $userObject->parentRole == null || $userObject->parentRole->filterParameterValue($pluginId, $name, AJXP_REPO_SCOPE_ALL, "") != $data[$name] || $userObject->personalRole->filterParameterValue($pluginId, $name, AJXP_REPO_SCOPE_ALL, "") != $data[$name]) { $userObject->personalRole->setParameterValue($pluginId, $name, $data[$name]); $rChanges = true; } } } } } if ($rChanges) { AuthService::updateRole($userObject->personalRole, $userObject); $userObject->recomputeMergedRole(); if ($action == "custom_data_edit") { AuthService::updateUser($userObject); } } if ($action == "user_create_user") { AJXP_Controller::applyHook($updating ? "user.after_update" : "user.after_create", array($userObject)); if (isset($data["send_email"]) && $data["send_email"] == true && !empty($data["email"])) { $mailer = AJXP_PluginsService::getInstance()->getUniqueActivePluginForType("mailer"); if ($mailer !== false) { $mess = ConfService::getMessages(); $link = AJXP_Utils::detectServerURL(); $apptitle = ConfService::getCoreConf("APPLICATION_TITLE"); $subject = str_replace("%s", $apptitle, $mess["507"]); $body = str_replace(array("%s", "%link", "%user", "%pass"), array($apptitle, $link, $data["new_user_id"], $data["new_password"]), $mess["508"]); $mailer->sendMail(array($data["email"]), $subject, $body); } } echo "SUCCESS"; } else { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($mess["241"], null); AJXP_XMLWriter::close(); } break; case "user_update_user": if (!isset($httpVars["user_id"])) { throw new Exception("invalid arguments"); } $userId = $httpVars["user_id"]; if (!AuthService::userExists($userId)) { throw new Exception("Cannot find user"); } $userObject = ConfService::getConfStorageImpl()->createUserObject($userId); if ($userObject->getParent() != AuthService::getLoggedUser()->getId()) { throw new Exception("Cannot find user"); } $paramsString = ConfService::getCoreConf("NEWUSERS_EDIT_PARAMETERS", "conf"); $result = array(); $params = explode(",", $paramsString); foreach ($params as $p) { $result[$p] = $userObject->personalRole->filterParameterValue("core.conf", $p, AJXP_REPO_SCOPE_ALL, ""); } HTMLWriter::charsetHeader("application/json"); echo json_encode($result); break; //------------------------------------ // WEBDAV PREFERENCES //------------------------------------ //------------------------------------ // WEBDAV PREFERENCES //------------------------------------ case "webdav_preferences": $userObject = AuthService::getLoggedUser(); $webdavActive = false; $passSet = false; $digestSet = false; // Detect http/https and host if (ConfService::getCoreConf("WEBDAV_BASEHOST") != "") { $baseURL = ConfService::getCoreConf("WEBDAV_BASEHOST"); } else { $baseURL = AJXP_Utils::detectServerURL(); } $webdavBaseUrl = $baseURL . ConfService::getCoreConf("WEBDAV_BASEURI") . "/"; $davData = $userObject->getPref("AJXP_WEBDAV_DATA"); $digestSet = isset($davData["HA1"]); if (isset($httpVars["activate"]) || isset($httpVars["webdav_pass"])) { if (!empty($httpVars["activate"])) { $activate = $httpVars["activate"] == "true" ? true : false; if (empty($davData)) { $davData = array(); } $davData["ACTIVE"] = $activate; } if (!empty($httpVars["webdav_pass"])) { $password = $httpVars["webdav_pass"]; if (function_exists('mcrypt_encrypt')) { $user = $userObject->getId(); $secret = defined("AJXP_SAFE_SECRET_KEY") ? AJXP_SAFE_SECRET_KEY : "CDAFx¨op#"; $password = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($user . $secret), $password, MCRYPT_MODE_ECB)); } $davData["PASS"] = $password; } $userObject->setPref("AJXP_WEBDAV_DATA", $davData); $userObject->save("user"); } if (!empty($davData)) { $webdavActive = isset($davData["ACTIVE"]) && $davData["ACTIVE"] === true; $passSet = isset($davData["PASS"]); } $repoList = ConfService::getRepositoriesList(); $davRepos = array(); $loggedUser = AuthService::getLoggedUser(); foreach ($repoList as $repoIndex => $repoObject) { $accessType = $repoObject->getAccessType(); $driver = AJXP_PluginsService::getInstance()->getPluginByTypeName("access", $accessType); if (is_a($driver, "AjxpWrapperProvider") && !$repoObject->getOption("AJXP_WEBDAV_DISABLED") && ($loggedUser->canRead($repoIndex) || $loggedUser->canWrite($repoIndex))) { $davRepos[$repoIndex] = $webdavBaseUrl . "" . ($repoObject->getSlug() == null ? $repoObject->getId() : $repoObject->getSlug()); } } $prefs = array("webdav_active" => $webdavActive, "password_set" => $passSet, "digest_set" => $digestSet, "webdav_force_basic" => ConfService::getCoreConf("WEBDAV_FORCE_BASIC") === true, "webdav_base_url" => $webdavBaseUrl, "webdav_repositories" => $davRepos); HTMLWriter::charsetHeader("application/json"); print json_encode($prefs); break; case "get_user_template_logo": $tplId = $httpVars["template_id"]; $iconFormat = $httpVars["icon_format"]; $repo = ConfService::getRepositoryById($tplId); $logo = $repo->getOption("TPL_ICON_" . strtoupper($iconFormat)); if (isset($logo) && is_file(AJXP_DATA_PATH . "/plugins/core.conf/tpl_logos/" . $logo)) { header("Content-Type: " . AJXP_Utils::getImageMimeType($logo) . "; name=\"" . $logo . "\""); header("Content-Length: " . filesize(AJXP_DATA_PATH . "/plugins/core.conf/tpl_logos/" . $logo)); header('Pragma:'); header('Cache-Control: public'); header("Last-Modified: " . gmdate("D, d M Y H:i:s", time() - 10000) . " GMT"); header("Expires: " . gmdate("D, d M Y H:i:s", time() + 5 * 24 * 3600) . " GMT"); readfile(AJXP_DATA_PATH . "/plugins/core.conf/tpl_logos/" . $logo); } else { $logo = "default_template_logo-" . ($iconFormat == "small" ? 16 : 22) . ".png"; header("Content-Type: " . AJXP_Utils::getImageMimeType($logo) . "; name=\"" . $logo . "\""); header("Content-Length: " . filesize(AJXP_INSTALL_PATH . "/" . AJXP_PLUGINS_FOLDER . "/core.conf/" . $logo)); header('Pragma:'); header('Cache-Control: public'); header("Last-Modified: " . gmdate("D, d M Y H:i:s", time() - 10000) . " GMT"); header("Expires: " . gmdate("D, d M Y H:i:s", time() + 5 * 24 * 3600) . " GMT"); readfile(AJXP_INSTALL_PATH . "/" . AJXP_PLUGINS_FOLDER . "/core.conf/" . $logo); } break; case "get_user_templates_definition": AJXP_XMLWriter::header("repository_templates"); $count = 0; $repositories = ConfService::listRepositoriesWithCriteria(array("isTemplate" => 1), $count); $pServ = AJXP_PluginsService::getInstance(); foreach ($repositories as $repo) { if (!$repo->isTemplate) { continue; } if (!$repo->getOption("TPL_USER_CAN_CREATE")) { continue; } $repoId = $repo->getId(); $repoLabel = $repo->getDisplay(); $repoType = $repo->getAccessType(); print "<template repository_id=\"{$repoId}\" repository_label=\"{$repoLabel}\" repository_type=\"{$repoType}\">"; $driverPlug = $pServ->getPluginByTypeName("access", $repoType); $params = $driverPlug->getManifestRawContent("//param", "node"); $tplDefined = $repo->getOptionsDefined(); $defaultLabel = ''; foreach ($params as $paramNode) { $name = $paramNode->getAttribute("name"); if (strpos($name, "TPL_") === 0) { if ($name == "TPL_DEFAULT_LABEL") { $defaultLabel = str_replace("AJXP_USER", AuthService::getLoggedUser()->getId(), $repo->getOption($name)); } continue; } if (in_array($paramNode->getAttribute("name"), $tplDefined)) { continue; } if ($paramNode->getAttribute('no_templates') == 'true') { continue; } print AJXP_XMLWriter::replaceAjxpXmlKeywords($paramNode->ownerDocument->saveXML($paramNode)); } // ADD LABEL echo '<param name="DISPLAY" type="string" label="' . $mess[359] . '" description="' . $mess[429] . '" mandatory="true" default="' . $defaultLabel . '"/>'; print "</template>"; } AJXP_XMLWriter::close("repository_templates"); break; case "user_create_repository": $tplId = $httpVars["template_id"]; $tplRepo = ConfService::getRepositoryById($tplId); $options = array(); AJXP_Utils::parseStandardFormParameters($httpVars, $options); $loggedUser = AuthService::getLoggedUser(); $newRep = $tplRepo->createTemplateChild(AJXP_Utils::sanitize($httpVars["DISPLAY"]), $options, null, $loggedUser->getId()); $gPath = $loggedUser->getGroupPath(); if (!empty($gPath)) { $newRep->setGroupPath($gPath); } $res = ConfService::addRepository($newRep); AJXP_XMLWriter::header(); if ($res == -1) { AJXP_XMLWriter::sendMessage(null, $mess[426]); } else { // Make sure we do not overwrite otherwise loaded rights. $loggedUser->load(); $loggedUser->personalRole->setAcl($newRep->getUniqueId(), "rw"); $loggedUser->save("superuser"); $loggedUser->recomputeMergedRole(); AuthService::updateUser($loggedUser); AJXP_XMLWriter::sendMessage($mess[425], null); AJXP_XMLWriter::reloadDataNode("", $newRep->getUniqueId()); AJXP_XMLWriter::reloadRepositoryList(); } AJXP_XMLWriter::close(); break; case "user_delete_repository": $repoId = $httpVars["repository_id"]; $repository = ConfService::getRepositoryById($repoId); if (!$repository->getUniqueUser() || $repository->getUniqueUser() != AuthService::getLoggedUser()->getId()) { throw new Exception("You are not allowed to perform this operation!"); } $res = ConfService::deleteRepository($repoId); AJXP_XMLWriter::header(); if ($res == -1) { AJXP_XMLWriter::sendMessage(null, $mess[427]); } else { $loggedUser = AuthService::getLoggedUser(); // Make sure we do not override remotely set rights $loggedUser->load(); $loggedUser->personalRole->setAcl($repoId, ""); $loggedUser->save("superuser"); AuthService::updateUser($loggedUser); AJXP_XMLWriter::sendMessage($mess[428], null); AJXP_XMLWriter::reloadRepositoryList(); } AJXP_XMLWriter::close(); break; case "user_delete_user": $userId = $httpVars["user_id"]; $userObject = ConfService::getConfStorageImpl()->createUserObject($userId); if ($userObject == null || !$userObject->hasParent() || $userObject->getParent() != AuthService::getLoggedUser()->getId()) { throw new Exception("You are not allowed to edit this user"); } AuthService::deleteUser($userId); echo "SUCCESS"; break; case "user_list_authorized_users": $defaultFormat = "html"; HTMLWriter::charsetHeader(); if (!ConfService::getAuthDriverImpl()->usersEditable()) { break; } $loggedUser = AuthService::getLoggedUser(); $crtValue = $httpVars["value"]; $usersOnly = isset($httpVars["users_only"]) && $httpVars["users_only"] == "true"; $existingOnly = isset($httpVars["existing_only"]) && $httpVars["existing_only"] == "true"; if (!empty($crtValue)) { $regexp = '^' . $crtValue; } else { $regexp = null; } $skipDisplayWithoutRegexp = ConfService::getCoreConf("USERS_LIST_REGEXP_MANDATORY", "conf"); if ($skipDisplayWithoutRegexp && $regexp == null) { print "<ul></ul>"; break; } $limit = intval(ConfService::getCoreConf("USERS_LIST_COMPLETE_LIMIT", "conf")); $searchAll = ConfService::getCoreConf("CROSSUSERS_ALLGROUPS", "conf"); $displayAll = ConfService::getCoreConf("CROSSUSERS_ALLGROUPS_DISPLAY", "conf"); $baseGroup = "/"; if ($regexp == null && !$displayAll || $regexp != null && !$searchAll) { $baseGroup = AuthService::filterBaseGroup("/"); } AuthService::setGroupFiltering(false); $allUsers = AuthService::listUsers($baseGroup, $regexp, 0, $limit, false); if (!$usersOnly) { $allGroups = array(); $roleOrGroup = ConfService::getCoreConf("GROUP_OR_ROLE", "conf"); $rolePrefix = $excludeString = $includeString = null; if (!is_array($roleOrGroup)) { $roleOrGroup = array("group_switch_value" => $roleOrGroup); } $listRoleType = false; if (isset($roleOrGroup["PREFIX"])) { $rolePrefix = $loggedUser->mergedRole->filterParameterValue("core.conf", "PREFIX", null, $roleOrGroup["PREFIX"]); $excludeString = $loggedUser->mergedRole->filterParameterValue("core.conf", "EXCLUDED", null, $roleOrGroup["EXCLUDED"]); $includeString = $loggedUser->mergedRole->filterParameterValue("core.conf", "INCLUDED", null, $roleOrGroup["INCLUDED"]); $listUserRolesOnly = $loggedUser->mergedRole->filterParameterValue("core.conf", "LIST_ROLE_BY", null, $roleOrGroup["LIST_ROLE_BY"]); if (is_array($listUserRolesOnly) && isset($listUserRolesOnly["group_switch_value"])) { switch ($listUserRolesOnly["group_switch_value"]) { case "userroles": $listRoleType = true; break; case "allroles": $listRoleType = false; break; default: break; } } } switch (strtolower($roleOrGroup["group_switch_value"])) { case 'user': // donothing break; case 'group': $authGroups = AuthService::listChildrenGroups($baseGroup); foreach ($authGroups as $gId => $gName) { $allGroups["AJXP_GRP_" . rtrim($baseGroup, "/") . "/" . ltrim($gId, "/")] = $gName; } break; case 'role': $allGroups = $this->getUserRoleList($loggedUser, $rolePrefix, $includeString, $excludeString, $listRoleType); break; case 'rolegroup': $groups = array(); $authGroups = AuthService::listChildrenGroups($baseGroup); foreach ($authGroups as $gId => $gName) { $groups["AJXP_GRP_" . rtrim($baseGroup, "/") . "/" . ltrim($gId, "/")] = $gName; } $roles = $this->getUserRoleList($loggedUser, $rolePrefix, $includeString, $excludeString, $listRoleType); empty($groups) ? $allGroups = $roles : (empty($roles) ? $allGroups = $groups : ($allGroups = array_merge($groups, $roles))); //$allGroups = array_merge($groups, $roles); break; default: break; } } $users = ""; $index = 0; if ($regexp != null && (!count($allUsers) || !empty($crtValue) && !array_key_exists(strtolower($crtValue), $allUsers)) && ConfService::getCoreConf("USER_CREATE_USERS", "conf") && !$existingOnly) { $users .= "<li class='complete_user_entry_temp' data-temporary='true' data-label='{$crtValue}'><span class='user_entry_label'>{$crtValue} (" . $mess["448"] . ")</span></li>"; } else { if ($existingOnly && !empty($crtValue)) { $users .= "<li class='complete_user_entry_temp' data-temporary='true' data-label='{$crtValue}' data-entry_id='{$crtValue}'><span class='user_entry_label'>{$crtValue}</span></li>"; } } $mess = ConfService::getMessages(); if ($regexp == null && !$usersOnly) { $users .= "<li class='complete_group_entry' data-group='AJXP_GRP_/' data-label='" . $mess["447"] . "'><span class='user_entry_label'>" . $mess["447"] . "</span></li>"; } $indexGroup = 0; if (!$usersOnly && is_array($allGroups)) { foreach ($allGroups as $groupId => $groupLabel) { if ($regexp == null || preg_match("/{$regexp}/i", $groupLabel)) { $users .= "<li class='complete_group_entry' data-group='{$groupId}' data-label='{$groupLabel}' data-entry_id='{$groupId}'><span class='user_entry_label'>" . $groupLabel . "</span></li>"; $indexGroup++; } if ($indexGroup == $limit) { break; } } } if ($regexp == null && method_exists($this, "listUserTeams")) { $teams = $this->listUserTeams(); foreach ($teams as $tId => $tData) { $users .= "<li class='complete_group_entry' data-group='/AJXP_TEAM/{$tId}' data-label='[team] " . $tData["LABEL"] . "'><span class='user_entry_label'>[team] " . $tData["LABEL"] . "</span></li>"; } } foreach ($allUsers as $userId => $userObject) { if ($userObject->getId() == $loggedUser->getId()) { continue; } if (!$userObject->hasParent() && ConfService::getCoreConf("ALLOW_CROSSUSERS_SHARING", "conf") || $userObject->getParent() == $loggedUser->getId()) { $userLabel = $userObject->personalRole->filterParameterValue("core.conf", "USER_DISPLAY_NAME", AJXP_REPO_SCOPE_ALL, $userId); //if($regexp != null && ! (preg_match("/$regexp/i", $userId) || preg_match("/$regexp/i", $userLabel)) ) continue; if (empty($userLabel)) { $userLabel = $userId; } $userDisplay = $userLabel == $userId ? $userId : $userLabel . " ({$userId})"; if (ConfService::getCoreConf("USERS_LIST_HIDE_LOGIN", "conf") == true && $userLabel != $userId) { $userDisplay = $userLabel; } $users .= "<li class='complete_user_entry' data-label='{$userLabel}' data-entry_id='{$userId}'><span class='user_entry_label'>" . $userDisplay . "</span></li>"; $index++; } if ($index == $limit) { break; } } if (strlen($users)) { print "<ul>" . $users . "</ul>"; } AuthService::setGroupFiltering(true); break; case "load_repository_info": $data = array(); $repo = ConfService::getRepository(); if ($repo != null) { $users = AuthService::countUsersForRepository(ConfService::getRepository()->getId(), true); $data["core.users"] = $users; if (isset($httpVars["collect"]) && $httpVars["collect"] == "true") { AJXP_Controller::applyHook("repository.load_info", array(&$data)); } } HTMLWriter::charsetHeader("application/json"); echo json_encode($data); break; case "get_binary_param": if (isset($httpVars["tmp_file"])) { $file = AJXP_Utils::getAjxpTmpDir() . "/" . AJXP_Utils::securePath($httpVars["tmp_file"]); if (isset($file)) { header("Content-Type:image/png"); readfile($file); } } else { if (isset($httpVars["binary_id"])) { if (isset($httpVars["user_id"]) && AuthService::getLoggedUser() != null && AuthService::getLoggedUser()->isAdmin()) { $context = array("USER" => $httpVars["user_id"]); } else { $context = array("USER" => AuthService::getLoggedUser()->getId()); } $this->loadBinary($context, $httpVars["binary_id"]); } } break; case "get_global_binary_param": if (isset($httpVars["tmp_file"])) { $file = AJXP_Utils::getAjxpTmpDir() . "/" . AJXP_Utils::securePath($httpVars["tmp_file"]); if (isset($file)) { header("Content-Type:image/png"); readfile($file); } } else { if (isset($httpVars["binary_id"])) { $this->loadBinary(array(), $httpVars["binary_id"]); } } break; case "store_binary_temp": if (count($fileVars)) { $keys = array_keys($fileVars); $boxData = $fileVars[$keys[0]]; $err = AJXP_Utils::parseFileDataErrors($boxData); if ($err != null) { } else { $rand = substr(md5(time()), 0, 6); $tmp = $rand . "-" . $boxData["name"]; @move_uploaded_file($boxData["tmp_name"], AJXP_Utils::getAjxpTmpDir() . "/" . $tmp); } } if (isset($tmp) && file_exists(AJXP_Utils::getAjxpTmpDir() . "/" . $tmp)) { print '<script type="text/javascript">'; print 'parent.formManagerHiddenIFrameSubmission("' . $tmp . '");'; print '</script>'; } break; default: break; } if (isset($logMessage) || isset($errorMessage)) { $xmlBuffer .= AJXP_XMLWriter::sendMessage(isset($logMessage) ? $logMessage : null, isset($errorMessage) ? $errorMessage : null, false); } if (isset($requireAuth)) { $xmlBuffer .= AJXP_XMLWriter::requireAuth(false); } return $xmlBuffer; }
/** * @abstract * @param $userId * @return array() */ function getUserChildren($userId) { $result = array(); $authDriver = ConfService::getAuthDriverImpl(); $confDriver = ConfService::getConfStorageImpl(); $users = $authDriver->listUsers(); foreach (array_keys($users) as $id) { $object = $confDriver->createUserObject($id); if ($object->hasParent() && $object->getParent() == $userId) { $result[] = $object; } } return $result; }
function switchAction($action, $httpVars, $fileVars) { if (!isset($this->actions[$action])) { return; } if (preg_match('/MSIE 7/', $_SERVER['HTTP_USER_AGENT']) || preg_match('/MSIE 8/', $_SERVER['HTTP_USER_AGENT'])) { // Force legacy theme for the moment $this->pluginConf["GUI_THEME"] = "oxygen"; } if (!defined("AJXP_THEME_FOLDER")) { define("CLIENT_RESOURCES_FOLDER", AJXP_PLUGINS_FOLDER . "/gui.ajax/res"); define("AJXP_THEME_FOLDER", CLIENT_RESOURCES_FOLDER . "/themes/" . $this->pluginConf["GUI_THEME"]); } foreach ($httpVars as $getName => $getValue) { ${$getName} = AJXP_Utils::securePath($getValue); } if (isset($dir) && $action != "upload") { $dir = SystemTextEncoding::fromUTF8($dir); } $mess = ConfService::getMessages(); switch ($action) { //------------------------------------ // GET AN HTML TEMPLATE //------------------------------------ case "get_template": HTMLWriter::charsetHeader(); $folder = CLIENT_RESOURCES_FOLDER . "/html"; if (isset($httpVars["pluginName"])) { $folder = AJXP_INSTALL_PATH . "/" . AJXP_PLUGINS_FOLDER . "/" . AJXP_Utils::securePath($httpVars["pluginName"]); if (isset($httpVars["pluginPath"])) { $folder .= "/" . AJXP_Utils::securePath($httpVars["pluginPath"]); } } $crtTheme = $this->pluginConf["GUI_THEME"]; $thFolder = AJXP_THEME_FOLDER . "/html"; if (isset($template_name)) { if (is_file($thFolder . "/" . $template_name)) { include $thFolder . "/" . $template_name; } else { if (is_file($folder . "/" . $template_name)) { include $folder . "/" . $template_name; } } } break; //------------------------------------ // GET I18N MESSAGES //------------------------------------ //------------------------------------ // GET I18N MESSAGES //------------------------------------ case "get_i18n_messages": $refresh = false; if (isset($httpVars["lang"])) { ConfService::setLanguage($httpVars["lang"]); $refresh = true; } HTMLWriter::charsetHeader('text/javascript'); HTMLWriter::writeI18nMessagesClass(ConfService::getMessages($refresh)); break; //------------------------------------ // SEND XML REGISTRY //------------------------------------ //------------------------------------ // SEND XML REGISTRY //------------------------------------ case "get_xml_registry": $regDoc = AJXP_PluginsService::getXmlRegistry(); $changes = AJXP_Controller::filterActionsRegistry($regDoc); if ($changes) { AJXP_PluginsService::updateXmlRegistry($regDoc); } if (isset($_GET["xPath"])) { $regPath = new DOMXPath($regDoc); $nodes = $regPath->query($_GET["xPath"]); AJXP_XMLWriter::header("ajxp_registry_part", array("xPath" => $_GET["xPath"])); if ($nodes->length) { print AJXP_XMLWriter::replaceAjxpXmlKeywords($regDoc->saveXML($nodes->item(0))); } AJXP_XMLWriter::close("ajxp_registry_part"); } else { AJXP_Utils::safeIniSet("zlib.output_compression", "4096"); header('Content-Type: application/xml; charset=UTF-8'); print AJXP_XMLWriter::replaceAjxpXmlKeywords($regDoc->saveXML()); } break; //------------------------------------ // DISPLAY DOC //------------------------------------ //------------------------------------ // DISPLAY DOC //------------------------------------ case "display_doc": HTMLWriter::charsetHeader(); echo HTMLWriter::getDocFile(AJXP_Utils::securePath(htmlentities($_GET["doc_file"]))); break; //------------------------------------ // GET BOOT GUI //------------------------------------ //------------------------------------ // GET BOOT GUI //------------------------------------ case "get_boot_gui": header("X-UA-Compatible: chrome=1"); HTMLWriter::charsetHeader(); if (!is_file(TESTS_RESULT_FILE)) { $outputArray = array(); $testedParams = array(); $passed = AJXP_Utils::runTests($outputArray, $testedParams); if (!$passed && !isset($_GET["ignore_tests"])) { die(AJXP_Utils::testResultsToTable($outputArray, $testedParams)); } else { AJXP_Utils::testResultsToFile($outputArray, $testedParams); } } $START_PARAMETERS = array("BOOTER_URL" => "index.php?get_action=get_boot_conf", "MAIN_ELEMENT" => "ajxp_desktop"); if (AuthService::usersEnabled()) { AuthService::preLogUser(isset($httpVars["remote_session"]) ? $httpVars["remote_session"] : ""); AuthService::bootSequence($START_PARAMETERS); if (AuthService::getLoggedUser() != null || AuthService::logUser(null, null) == 1) { if (AuthService::getDefaultRootId() == -1) { AuthService::disconnect(); } else { $loggedUser = AuthService::getLoggedUser(); if (!$loggedUser->canRead(ConfService::getCurrentRootDirIndex()) && AuthService::getDefaultRootId() != ConfService::getCurrentRootDirIndex()) { ConfService::switchRootDir(AuthService::getDefaultRootId()); } } } } AJXP_Utils::parseApplicationGetParameters($_GET, $START_PARAMETERS, $_SESSION); $confErrors = ConfService::getErrors(); if (count($confErrors)) { $START_PARAMETERS["ALERT"] = implode(", ", array_values($confErrors)); } $JSON_START_PARAMETERS = json_encode($START_PARAMETERS); $crtTheme = $this->pluginConf["GUI_THEME"]; if (ConfService::getConf("JS_DEBUG")) { if (!isset($mess)) { $mess = ConfService::getMessages(); } if (is_file(AJXP_INSTALL_PATH . "/plugins/gui.ajax/res/themes/{$crtTheme}/html/gui_debug.html")) { include AJXP_INSTALL_PATH . "/plugins/gui.ajax/res/themes/{$crtTheme}/html/gui_debug.html"; } else { include AJXP_INSTALL_PATH . "/plugins/gui.ajax/res/html/gui_debug.html"; } } else { if (is_file(AJXP_INSTALL_PATH . "/plugins/gui.ajax/res/themes/{$crtTheme}/html/gui.html")) { $content = file_get_contents(AJXP_INSTALL_PATH . "/plugins/gui.ajax/res/themes/{$crtTheme}/html/gui.html"); } else { $content = file_get_contents(AJXP_INSTALL_PATH . "/plugins/gui.ajax/res/html/gui.html"); } if (preg_match('/MSIE 7/', $_SERVER['HTTP_USER_AGENT']) || preg_match('/MSIE 8/', $_SERVER['HTTP_USER_AGENT'])) { $content = str_replace("ajaxplorer_boot.js", "ajaxplorer_boot_protolegacy.js", $content); } $content = AJXP_XMLWriter::replaceAjxpXmlKeywords($content, false); if ($JSON_START_PARAMETERS) { $content = str_replace("//AJXP_JSON_START_PARAMETERS", "startParameters = " . $JSON_START_PARAMETERS . ";", $content); } print $content; } break; //------------------------------------ // GET CONFIG FOR BOOT //------------------------------------ //------------------------------------ // GET CONFIG FOR BOOT //------------------------------------ case "get_boot_conf": if (isset($_GET["server_prefix_uri"])) { $_SESSION["AJXP_SERVER_PREFIX_URI"] = $_GET["server_prefix_uri"]; } $config = array(); $config["ajxpResourcesFolder"] = "plugins/gui.ajax/res"; $config["ajxpServerAccess"] = AJXP_SERVER_ACCESS; $config["zipEnabled"] = ConfService::zipEnabled(); $config["multipleFilesDownloadEnabled"] = ConfService::getCoreConf("ZIP_CREATION"); $config["customWording"] = array("welcomeMessage" => $this->pluginConf["CUSTOM_WELCOME_MESSAGE"], "title" => ConfService::getCoreConf("APPLICATION_TITLE"), "icon" => $this->pluginConf["CUSTOM_ICON"], "iconWidth" => $this->pluginConf["CUSTOM_ICON_WIDTH"], "iconHeight" => $this->pluginConf["CUSTOM_ICON_HEIGHT"], "iconOnly" => $this->pluginConf["CUSTOM_ICON_ONLY"], "titleFontSize" => $this->pluginConf["CUSTOM_FONT_SIZE"]); $config["usersEnabled"] = AuthService::usersEnabled(); $config["loggedUser"] = AuthService::getLoggedUser() != null; $config["currentLanguage"] = ConfService::getLanguage(); $config["session_timeout"] = intval(ini_get("session.gc_maxlifetime")); if (!isset($this->pluginConf["CLIENT_TIMEOUT_TIME"]) || $this->pluginConf["CLIENT_TIMEOUT_TIME"] == "") { $to = $config["session_timeout"]; } else { $to = $this->pluginConf["CLIENT_TIMEOUT_TIME"]; } $config["client_timeout"] = $to; $config["client_timeout_warning"] = $this->pluginConf["CLIENT_TIMEOUT_WARN"]; $config["availableLanguages"] = ConfService::getConf("AVAILABLE_LANG"); $config["usersEditable"] = ConfService::getAuthDriverImpl()->usersEditable(); $config["ajxpVersion"] = AJXP_VERSION; $config["ajxpVersionDate"] = AJXP_VERSION_DATE; if (stristr($_SERVER["HTTP_USER_AGENT"], "msie 6")) { $config["cssResources"] = array("css/pngHack/pngHack.css"); } if (!empty($this->pluginConf['GOOGLE_ANALYTICS_ID'])) { $config["googleAnalyticsData"] = array("id" => $this->pluginConf['GOOGLE_ANALYTICS_ID'], "domain" => $this->pluginConf['GOOGLE_ANALYTICS_DOMAIN'], "event" => $this->pluginConf['GOOGLE_ANALYTICS_EVENT']); } $config["i18nMessages"] = ConfService::getMessages(); $config["password_min_length"] = ConfService::getCoreConf("PASSWORD_MINLENGTH", "auth"); $config["SECURE_TOKEN"] = AuthService::generateSecureToken(); $config["streaming_supported"] = "true"; $config["theme"] = $this->pluginConf["GUI_THEME"]; header("Content-type:application/json;charset=UTF-8"); print json_encode($config); break; default: break; } return false; }
/** * @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; }
public function upgradeDB() { $confDriver = ConfService::getConfStorageImpl(); $authDriver = ConfService::getAuthDriverImpl(); $logger = AJXP_Logger::getInstance(); if (is_a($confDriver, "sqlConfDriver")) { $conf = AJXP_Utils::cleanDibiDriverParameters($confDriver->getOption("SQL_DRIVER")); if (!is_array($conf) || !isset($conf["driver"])) { return "Nothing to do"; } switch ($conf["driver"]) { case "sqlite": case "sqlite3": $ext = ".sqlite"; break; case "postgre": $ext = ".pgsql"; break; case "mysql": $ext = is_file($this->workingFolder . "/" . $this->dbUpgrade . ".mysql") ? ".mysql" : ".sql"; break; default: return "ERROR!, DB driver " . $conf["driver"] . " not supported yet in __FUNCTION__"; } $file = $this->dbUpgrade . $ext; if (!is_file($this->workingFolder . "/" . $file)) { return "Nothing to do."; } $sqlInstructions = file_get_contents($this->workingFolder . "/" . $file); $parts = array_map("trim", explode("/* SEPARATOR */", $sqlInstructions)); $results = array(); $errors = array(); dibi::connect($conf); dibi::begin(); foreach ($parts as $sqlPart) { if (empty($sqlPart)) { continue; } try { dibi::nativeQuery($sqlPart); $results[] = $sqlPart; } catch (DibiException $e) { $errors[] = $sqlPart . " (" . $e->getMessage() . ")"; } } dibi::commit(); dibi::disconnect(); if (!count($errors)) { return "Database successfully upgraded"; } else { return "Database upgrade failed. <br>The following statements were executed : <br>" . implode("<br>", $results) . ",<br><br> The following statements failed : <br>" . implode("<br>", $errors) . "<br><br> You should manually upgrade your DB."; } } }
function listUsers() { $authDriver = ConfService::getAuthDriverImpl(); $confDriver = ConfService::getConfStorageImpl(); $allUsers = array(); $users = $authDriver->listUsers(); foreach (array_keys($users) as $userId) { if ($userId == "guest" && !ALLOW_GUEST_BROWSING || $userId == "ajxp.admin.users") { continue; } $allUsers[$userId] = $confDriver->createUserObject($userId); } return $allUsers; }
/** * @param string $repositoryId * @return AbstractAjxpUser[] */ public function getUsersForRepository($repositoryId) { $result = array(); $authDriver = ConfService::getAuthDriverImpl(); $confDriver = ConfService::getConfStorageImpl(); $users = $authDriver->listUsers(AuthService::filterBaseGroup("/")); foreach (array_keys($users) as $id) { $object = $confDriver->createUserObject($id); if ($object->canSwitchTo($repositoryId)) { $result[$id] = $object; } } return $result; }
/** * @param AbstractAjxpUser $parentUser * @param string $userName * @param string $password * @param bool $isHidden * @param string $display * @return AbstractAjxpUser * @throws Exception */ public function createNewUser($parentUser, $userName, $password, $isHidden, $display) { $confDriver = ConfService::getConfStorageImpl(); if (ConfService::getAuthDriverImpl()->getOptionAsBool("TRANSMIT_CLEAR_PASS")) { $pass = $password; } else { $pass = md5($password); } if (!$isHidden) { // This is an explicit user creation - check possible limits AJXP_Controller::applyHook("user.before_create", array($userName, null, false, false)); $limit = $parentUser->mergedRole->filterParameterValue("core.conf", "USER_SHARED_USERS_LIMIT", AJXP_REPO_SCOPE_ALL, ""); if (!empty($limit) && intval($limit) > 0) { $count = count($confDriver->getUserChildren($parentUser->getId())); if ($count >= $limit) { $mess = ConfService::getMessages(); throw new Exception($mess['483']); } } } AuthService::createUser($userName, $pass, false, $isHidden); $userObject = $confDriver->createUserObject($userName); $userObject->personalRole->clearAcls(); $userObject->setParent($parentUser->getId()); $userObject->setGroupPath($parentUser->getGroupPath()); $userObject->setProfile("shared"); if ($isHidden) { $userObject->setHidden(true); $userObject->personalRole->setParameterValue("core.conf", "USER_DISPLAY_NAME", $display); } AJXP_Controller::applyHook("user.after_create", array($userObject)); return $userObject; }