public function toggleDisclaimer($actionName, $httpVars, $fileVars) { $u = AuthService::getLoggedUser(); $u->personalRole->setParameterValue("action.disclaimer", "DISCLAIMER_ACCEPTED", $httpVars["validate"] == "true" ? "yes" : "no", AJXP_REPO_SCOPE_ALL); if ($httpVars["validate"] == "true") { $u->removeLock(); $u->save("superuser"); AuthService::updateUser($u); ConfService::switchUserToActiveRepository($u); $force = $u->mergedRole->filterParameterValue("core.conf", "DEFAULT_START_REPOSITORY", AJXP_REPO_SCOPE_ALL, -1); $passId = -1; if ($force != "" && $u->canSwitchTo($force) && !isset($httpVars["tmp_repository_id"]) && !isset($_SESSION["PENDING_REPOSITORY_ID"])) { $passId = $force; } $res = ConfService::switchUserToActiveRepository($u, $passId); if (!$res) { AuthService::disconnect(); AJXP_XMLWriter::header(); AJXP_XMLWriter::requireAuth(true); AJXP_XMLWriter::close(); } ConfService::getInstance()->invalidateLoadedRepositories(); } else { $u->setLock("validate_disclaimer"); $u->save("superuser"); AuthService::disconnect(); AJXP_XMLWriter::header(); AJXP_XMLWriter::requireAuth(true); AJXP_XMLWriter::close(); } }
public function updateUserRole($userId, $roleId, $addOrRemove, $updateSubUsers = false) { $confStorage = ConfService::getConfStorageImpl(); $user = $confStorage->createUserObject($userId); if (!AuthService::canAdministrate($user)) { throw new Exception("Cannot update user data for " . $userId); } if ($addOrRemove == "add") { $roleObject = AuthService::getRole($roleId); $user->addRole($roleObject); } else { $user->removeRole($roleId); } $user->save("superuser"); $loggedUser = AuthService::getLoggedUser(); if ($loggedUser->getId() == $user->getId()) { AuthService::updateUser($user); } return $user; }
$field_errors = $user_form['has_errors']; } } return $this->view->render($response, 'forms/users_register.twig', ['user' => $user, 'flash_messages' => $flash_messages, 'errors' => $field_errors, 'userLogged' => isset($_SESSION['user_id']), 'csrf' => ['name' => $request->getAttribute('csrf_name'), 'value' => $request->getAttribute('csrf_value')]]); })->setName('register'); $app->map(['GET', 'POST'], '/users/edit', function ($request, $response, $args) { $field_errors = []; $flash_messages = $this->flash->getMessages(); $userService = new AuthService(); $user = $userService->getUserById($_SESSION['user_id']); if ($request->isPost()) { $user['full_name'] = filter_var($_POST['full_name'], FILTER_SANITIZE_STRING); $user['email'] = filter_var($_POST['email'], FILTER_SANITIZE_STRING); $user_form = validateUserEditForm($user); if ($user_form['is_valid']) { $userService->updateUser($user); $this->flash->addMessage('success', 'Details has been updated'); return $response->withRedirect($this->router->pathFor('docs-home')); } else { $field_errors = $user_form['has_errors']; } } return $this->view->render($response, 'forms/users_edit.twig', ['user' => $user, 'flash_messages' => $flash_messages, 'errors' => $field_errors, 'userLogged' => isset($_SESSION['user_id']), 'csrf' => ['name' => $request->getAttribute('csrf_name'), 'value' => $request->getAttribute('csrf_value')]]); })->setName('user-edit'); $app->map(['GET', 'POST'], '/users/password/change', function ($request, $response, $args) { $fdata = []; $field_errors = []; $flash_messages = $this->flash->getMessages(); if ($request->isPost()) { $fdata['current_password'] = filter_var($_POST['current_password'], FILTER_SANITIZE_STRING); $fdata['new_password'] = filter_var($_POST['new_password'], FILTER_SANITIZE_STRING);
/** * Specific operations to perform at boot time * @static * @param array $START_PARAMETERS A HashTable of parameters to send back to the client * @return void */ public static function bootSequence(&$START_PARAMETERS) { if (AJXP_Utils::detectApplicationFirstRun()) { return; } if (file_exists(AJXP_CACHE_DIR . "/admin_counted")) { return; } $rootRole = AuthService::getRole("ROOT_ROLE", false); if ($rootRole === false) { $rootRole = new AJXP_Role("ROOT_ROLE"); $rootRole->setLabel("Root Role"); $rootRole->setAutoApplies(array("standard", "admin")); $dashId = ""; foreach (ConfService::getRepositoriesList("all") as $repositoryId => $repoObject) { if ($repoObject->isTemplate) { continue; } if ($repoObject->getAccessType() == "ajxp_user") { $dashId = $repositoryId; } $gp = $repoObject->getGroupPath(); if (empty($gp) || $gp == "/") { if ($repoObject->getDefaultRight() != "") { $rootRole->setAcl($repositoryId, $repoObject->getDefaultRight()); } } } if (!empty($dashId)) { $rootRole->setParameterValue("core.conf", "DEFAULT_START_REPOSITORY", $dashId); } $paramNodes = AJXP_PluginsService::searchAllManifests("//server_settings/param[@scope]", "node", false, false, true); if (is_array($paramNodes) && count($paramNodes)) { foreach ($paramNodes as $xmlNode) { $default = $xmlNode->getAttribute("default"); if (empty($default)) { continue; } $parentNode = $xmlNode->parentNode->parentNode; $pluginId = $parentNode->getAttribute("id"); if (empty($pluginId)) { $pluginId = $parentNode->nodeName . "." . $parentNode->getAttribute("name"); } $rootRole->setParameterValue($pluginId, $xmlNode->getAttribute("name"), $default); } } AuthService::updateRole($rootRole); } $miniRole = AuthService::getRole("MINISITE", false); if ($miniRole === false) { $rootRole = new AJXP_Role("MINISITE"); $rootRole->setLabel("Minisite Users"); $actions = array("access.fs" => array("ajxp_link", "chmod", "purge"), "meta.watch" => array("toggle_watch"), "conf.serial" => array("get_bookmarks"), "conf.sql" => array("get_bookmarks"), "index.lucene" => array("index"), "action.share" => array("share"), "gui.ajax" => array("bookmark"), "auth.serial" => array("pass_change"), "auth.sql" => array("pass_change")); foreach ($actions as $pluginId => $acts) { foreach ($acts as $act) { $rootRole->setActionState($pluginId, $act, AJXP_REPO_SCOPE_SHARED, false); } } AuthService::updateRole($rootRole); } $miniRole = AuthService::getRole("MINISITE_NODOWNLOAD", false); if ($miniRole === false) { $rootRole = new AJXP_Role("MINISITE_NODOWNLOAD"); $rootRole->setLabel("Minisite Users - No Download"); $actions = array("access.fs" => array("download", "download_chunk", "prepare_chunk_dl", "download_all")); foreach ($actions as $pluginId => $acts) { foreach ($acts as $act) { $rootRole->setActionState($pluginId, $act, AJXP_REPO_SCOPE_SHARED, false); } } AuthService::updateRole($rootRole); } $miniRole = AuthService::getRole("GUEST", false); if ($miniRole === false) { $rootRole = new AJXP_Role("GUEST"); $rootRole->setLabel("Guest user role"); $actions = array("access.fs" => array("purge"), "meta.watch" => array("toggle_watch"), "index.lucene" => array("index")); $rootRole->setAutoApplies(array("guest")); foreach ($actions as $pluginId => $acts) { foreach ($acts as $act) { $rootRole->setActionState($pluginId, $act, AJXP_REPO_SCOPE_ALL); } } AuthService::updateRole($rootRole); } $adminCount = AuthService::countAdminUsers(); if ($adminCount == 0) { $authDriver = ConfService::getAuthDriverImpl(); $adminPass = ADMIN_PASSWORD; if ($authDriver->getOption("TRANSMIT_CLEAR_PASS") !== true) { $adminPass = md5(ADMIN_PASSWORD); } AuthService::createUser("admin", $adminPass, true); if (ADMIN_PASSWORD == INITIAL_ADMIN_PASSWORD) { $userObject = ConfService::getConfStorageImpl()->createUserObject("admin"); $userObject->setAdmin(true); AuthService::updateAdminRights($userObject); if (AuthService::changePasswordEnabled()) { $userObject->setLock("pass_change"); } $userObject->save("superuser"); $START_PARAMETERS["ALERT"] .= "Warning! User 'admin' was created with the initial password '" . INITIAL_ADMIN_PASSWORD . "'. \\nPlease log in as admin and change the password now!"; } AuthService::updateUser($userObject); } else { if ($adminCount == -1) { // Here we may come from a previous version! Check the "admin" user and set its right as admin. $confStorage = ConfService::getConfStorageImpl(); $adminUser = $confStorage->createUserObject("admin"); $adminUser->setAdmin(true); $adminUser->save("superuser"); $START_PARAMETERS["ALERT"] .= "There is an admin user, but without admin right. Now any user can have the administration rights, \\n your 'admin' user was set with the admin rights. Please check that this suits your security configuration."; } } file_put_contents(AJXP_CACHE_DIR . "/admin_counted", "true"); }
function tryToLogUser(&$httpVars, $isLast = false) { if (isset($_SESSION["CURRENT_MINISITE"])) { return false; } $this->loadConfig(); if (isset($_SESSION['AUTHENTICATE_BY_CAS'])) { $flag = $_SESSION['AUTHENTICATE_BY_CAS']; } else { $flag = 0; } $pgtIou = !empty($httpVars['pgtIou']); $logged = isset($_SESSION['LOGGED_IN_BY_CAS']); $enre = !empty($httpVars['put_action_enable_redirect']); $ticket = !empty($httpVars['ticket']); $pgt = !empty($_SESSION['phpCAS']['pgt']); $clientModeTicketPendding = isset($_SESSION['AUTHENTICATE_BY_CAS_CLIENT_MOD_TICKET_PENDDING']); if ($this->cas_modify_login_page) { if ($flag == 0 && $enre && !$logged && !$pgtIou) { $_SESSION['AUTHENTICATE_BY_CAS'] = 1; } elseif ($flag == 1 && !$enre && !$logged && !$pgtIou && !$ticket && !$pgt) { $_SESSION['AUTHENTICATE_BY_CAS'] = 0; } elseif ($flag == 1 && $enre && !$logged && !$pgtIou) { $_SESSION['AUTHENTICATE_BY_CAS'] = 1; } elseif ($pgtIou || $pgt) { $_SESSION['AUTHENTICATE_BY_CAS'] = 1; } elseif ($ticket) { $_SESSION['AUTHENTICATE_BY_CAS'] = 1; $_SESSION['AUTHENTICATE_BY_CAS_CLIENT_MOD_TICKET_PENDDING'] = 1; } elseif ($logged && $pgtIou) { $_SESSION['AUTHENTICATE_BY_CAS'] = 2; } else { $_SESSION['AUTHENTICATE_BY_CAS'] = 0; } if ($_SESSION['AUTHENTICATE_BY_CAS'] < 1) { if ($clientModeTicketPendding) { unset($_SESSION['AUTHENTICATE_BY_CAS_CLIENT_MOD_TICKET_PENDDING']); } else { return false; } } } /** * Depend on phpCAS mode configuration */ switch ($this->cas_mode) { case PHPCAS_MODE_CLIENT: if ($this->checkConfigurationForClientMode()) { AJXP_Logger::info(__FUNCTION__, "Start phpCAS mode Client: ", "sucessfully"); phpCAS::client(CAS_VERSION_2_0, $this->cas_server, $this->cas_port, $this->cas_uri, false); if (!empty($this->cas_certificate_path)) { phpCAS::setCasServerCACert($this->cas_certificate_path); } else { phpCAS::setNoCasServerValidation(); } /** * Debug */ if ($this->cas_debug_mode) { // logfile name by date: $today = getdate(); $file_path = AJXP_DATA_PATH . '/logs/phpcas_' . $today['year'] . '-' . $today['month'] . '-' . $today['mday'] . '.txt'; empty($this->cas_debug_file) ? $file_path : ($file_path = $this->cas_debug_file); phpCAS::setDebug($file_path); } phpCAS::forceAuthentication(); } else { AJXP_Logger::error(__FUNCTION__, "Could not start phpCAS mode CLIENT, please verify the configuration", ""); return false; } break; case PHPCAS_MODE_PROXY: /** * If in login page, user click on login via CAS, the page will be reload with manuallyredirectocas is set. * Or force redirect to cas login page even the force redirect is set in configuration of this module * */ if ($this->checkConfigurationForProxyMode()) { AJXP_Logger::info(__FUNCTION__, "Start phpCAS mode Proxy: ", "sucessfully"); /** * init phpCAS in mode proxy */ phpCAS::proxy(CAS_VERSION_2_0, $this->cas_server, $this->cas_port, $this->cas_uri, false); if (!empty($this->cas_certificate_path)) { phpCAS::setCasServerCACert($this->cas_certificate_path); } else { phpCAS::setNoCasServerValidation(); } /** * Debug */ if ($this->cas_debug_mode) { // logfile name by date: $today = getdate(); $file_path = AJXP_DATA_PATH . '/logs/phpcas_' . $today['year'] . '-' . $today['month'] . '-' . $today['mday'] . '.txt'; empty($this->cas_debug_file) ? $file_path : ($file_path = $this->cas_debug_file); phpCAS::setDebug($file_path); } if (!empty($this->cas_setFixedCallbackURL)) { phpCAS::setFixedCallbackURL($this->cas_setFixedCallbackURL); } // /** * PTG storage */ $this->setPTGStorage(); phpCAS::forceAuthentication(); /** * Get proxy ticket (PT) for SAMBA to authentication at CAS via pam_cas * In fact, we can use any other service. Of course, it should be enabled in CAS * */ $err_code = null; $serviceURL = $this->cas_proxied_service; AJXP_Logger::debug(__FUNCTION__, "Try to get proxy ticket for service: ", $serviceURL); $res = phpCAS::serviceSMB($serviceURL, $err_code); if (!empty($res)) { $_SESSION['PROXYTICKET'] = $res; AJXP_Logger::info(__FUNCTION__, "Get Proxy ticket successfully ", ""); } else { AJXP_Logger::info(__FUNCTION__, "Could not get Proxy ticket. ", ""); } break; } else { AJXP_Logger::error(__FUNCTION__, "Could not start phpCAS mode PROXY, please verify the configuration", ""); return false; } default: return false; break; } AJXP_Logger::debug(__FUNCTION__, "Call phpCAS::getUser() after forceAuthentication ", ""); $cas_user = phpCAS::getUser(); if (!AuthService::userExists($cas_user) && $this->is_AutoCreateUser) { AuthService::createUser($cas_user, openssl_random_pseudo_bytes(20)); } if (AuthService::userExists($cas_user)) { $res = AuthService::logUser($cas_user, "", true); if ($res > 0) { AJXP_Safe::storeCredentials($cas_user, $_SESSION['PROXYTICKET']); $_SESSION['LOGGED_IN_BY_CAS'] = true; if (!empty($this->cas_additional_role)) { $userObj = ConfService::getConfStorageImpl()->createUserObject($cas_user); $roles = $userObj->getRoles(); $cas_RoleID = $this->cas_additional_role; $userObj->addRole(AuthService::getRole($cas_RoleID, true)); AuthService::updateUser($userObj); } return true; } } return false; }
public function postVerificationCode($action, $httpVars, $fileVars) { if ($action != "duo_post_verification_code") { return; } $u = AuthService::getLoggedUser(); if ($u == null) { return; } $sigResponse = $httpVars["sig_response"]; require_once $this->getBaseDir() . "/duo_php/duo_web.php"; $appUnique = $this->getFilteredOption("DUO_AUTH_AKEY"); $iKey = $this->getFilteredOption("DUO_AUTH_IKEY"); $sKey = $this->getFilteredOption("DUO_AUTH_SKEY"); $verif = Duo::verifyResponse($iKey, $sKey, $appUnique, $sigResponse); if ($verif != null && $verif == $u->getId()) { $u->removeLock(); $u->save("superuser"); $u->recomputeMergedRole(); AuthService::updateUser($u); ConfService::switchUserToActiveRepository($u); $force = $u->mergedRole->filterParameterValue("core.conf", "DEFAULT_START_REPOSITORY", AJXP_REPO_SCOPE_ALL, -1); $passId = -1; if ($force != "" && $u->canSwitchTo($force) && !isset($httpVars["tmp_repository_id"]) && !isset($_SESSION["PENDING_REPOSITORY_ID"])) { $passId = $force; } $res = ConfService::switchUserToActiveRepository($u, $passId); if (!$res) { AuthService::disconnect(); AJXP_XMLWriter::header(); AJXP_XMLWriter::requireAuth(true); AJXP_XMLWriter::close(); } } else { AuthService::disconnect(); AJXP_XMLWriter::header(); AJXP_XMLWriter::requireAuth(true); AJXP_XMLWriter::close(); } }
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; }
/** * @param AbstractAjxpUser $loggedUser * @param String|int $parameterId * @return bool */ public static function switchUserToActiveRepository($loggedUser, $parameterId = -1) { if (isset($_SESSION["PENDING_REPOSITORY_ID"]) && isset($_SESSION["PENDING_FOLDER"])) { $loggedUser->setArrayPref("history", "last_repository", $_SESSION["PENDING_REPOSITORY_ID"]); $loggedUser->setPref("pending_folder", $_SESSION["PENDING_FOLDER"]); $loggedUser->save("user"); AuthService::updateUser($loggedUser); unset($_SESSION["PENDING_REPOSITORY_ID"]); unset($_SESSION["PENDING_FOLDER"]); } $currentRepoId = ConfService::getCurrentRepositoryId(); $lastRepoId = $loggedUser->getArrayPref("history", "last_repository"); $defaultRepoId = AuthService::getDefaultRootId(); if ($defaultRepoId == -1) { return false; } else { if ($lastRepoId !== "" && $lastRepoId !== $currentRepoId && $parameterId == -1 && $loggedUser->canSwitchTo($lastRepoId)) { ConfService::switchRootDir($lastRepoId); } else { if ($parameterId != -1 && $loggedUser->canSwitchTo($parameterId)) { ConfService::switchRootDir($parameterId); } else { if (!$loggedUser->canSwitchTo($currentRepoId)) { ConfService::switchRootDir($defaultRepoId); } } } } return true; }
function updateUserRole($userId, $roleId, $addOrRemove, $updateSubUsers = false) { $confStorage = ConfService::getConfStorageImpl(); $user = $confStorage->createUserObject($userId); if ($user->hasParent()) { return $user; } if ($addOrRemove == "add") { $user->addRole($roleId); } else { $user->removeRole($roleId); } $user->save("superuser"); $loggedUser = AuthService::getLoggedUser(); if ($loggedUser->getId() == $user->getId()) { AuthService::updateUser($user); } return $user; }
public static function parseApplicationGetParameters($parameters, &$output, &$session) { $output["EXT_REP"] = "/"; if (isset($parameters["repository_id"]) && isset($parameters["folder"])) { require_once "server/classes/class.SystemTextEncoding.php"; if (AuthService::usersEnabled()) { $loggedUser = AuthService::getLoggedUser(); if ($loggedUser != null && $loggedUser->canSwitchTo($parameters["repository_id"])) { $output["EXT_REP"] = SystemTextEncoding::toUTF8(urldecode($parameters["folder"])); $loggedUser->setArrayPref("history", "last_repository", $parameters["repository_id"]); $loggedUser->setPref("pending_folder", AJXP_Utils::decodeSecureMagic($parameters["folder"])); $loggedUser->save(); AuthService::updateUser($loggedUser); } else { $session["PENDING_REPOSITORY_ID"] = $parameters["repository_id"]; $session["PENDING_FOLDER"] = AJXP_Utils::decodeSecureMagic($parameters["folder"]); } } else { ConfService::switchRootDir($parameters["repository_id"]); $output["EXT_REP"] = SystemTextEncoding::toUTF8(urldecode($parameters["folder"])); } } if (isset($parameters["skipDebug"])) { ConfService::setConf("JS_DEBUG", false); } if (ConfService::getConf("JS_DEBUG") && isset($parameters["compile"])) { require_once SERVER_RESOURCES_FOLDER . "/class.AJXP_JSPacker.php"; AJXP_JSPacker::pack(); } if (ConfService::getConf("JS_DEBUG") && isset($parameters["update_i18n"])) { AJXP_Utils::updateI18nFiles(isset($parameters["plugin_path"]) ? $parameters["plugin_path"] : ""); } if (isset($parameters["external_selector_type"])) { $output["SELECTOR_DATA"] = array("type" => $parameters["external_selector_type"], "data" => $parameters); } }
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::getCurrentRootDirIndex(); $user->setArrayPref("history", "last_repository", $activeRepId); $user->save("user"); } //$logMessage = "Successfully Switched!"; AJXP_Logger::logAction("Switch Repository", array("rep. id" => $repository_id)); 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) { exit(1); } if (isset($httpVars["bm_action"]) && isset($httpVars["bm_path"])) { if ($httpVars["bm_action"] == "add_bookmark") { $title = ""; if (isset($httpVars["bm_title"])) { $title = $httpVars["bm_title"]; } if ($title == "" && $httpVars["bm_path"] == "/") { $title = ConfService::getCurrentRootDirDisplay(); } $bmUser->addBookMark(SystemTextEncoding::magicDequote($httpVars["bm_path"]), SystemTextEncoding::magicDequote($title)); } else { if ($httpVars["bm_action"] == "delete_bookmark") { $bmUser->removeBookmark($httpVars["bm_path"]); } else { if ($httpVars["bm_action"] == "rename_bookmark" && isset($httpVars["bm_title"])) { $bmUser->renameBookmark($httpVars["bm_path"], $httpVars["bm_title"]); } } } } 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()); AJXP_XMLWriter::close(); exit(1); 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"; exit(1); break; //------------------------------------ // WEBDAV PREFERENCES //------------------------------------ //------------------------------------ // WEBDAV PREFERENCES //------------------------------------ case "webdav_preferences": $userObject = AuthService::getLoggedUser(); $webdavActive = false; $passSet = 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") . "/"; if (isset($httpVars["activate"]) || isset($httpVars["webdav_pass"])) { $davData = $userObject->getPref("AJXP_WEBDAV_DATA"); 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_SECRET_KEY") ? AJXP_SAFE_SECRET_KEY : "CDAFx¨op#"; $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND); $password = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($user . $secret), $password, MCRYPT_MODE_ECB, $iv)); } $davData["PASS"] = $password; } $userObject->setPref("AJXP_WEBDAV_DATA", $davData); $userObject->save("user"); } $davData = $userObject->getPref("AJXP_WEBDAV_DATA"); 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, "AjxpWebdavProvider") && ($loggedUser->canRead($repoIndex) || $loggedUser->canWrite($repoIndex))) { $davRepos[$repoIndex] = $webdavBaseUrl . "" . ($repoObject->getSlug() == null ? $repoObject->getId() : $repoObject->getSlug()); } } $prefs = array("webdav_active" => $webdavActive, "password_set" => $passSet, "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"); $repositories = ConfService::getRepositoriesList(); $pServ = AJXP_PluginsService::getInstance(); foreach ($repositories as $repo) { if (!$repo->isTemplate) { continue; } if (!$repo->getOption("TPL_USER_CAN_CREATE")) { continue; } $repoId = $repo->getUniqueId(); $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(); self::parseParameters($httpVars, $options); $newRep = $tplRepo->createTemplateChild(AJXP_Utils::sanitize($httpVars["DISPLAY"]), $options, null, AuthService::getLoggedUser()->getId()); $res = ConfService::addRepository($newRep); AJXP_XMLWriter::header(); if ($res == -1) { AJXP_XMLWriter::sendMessage(null, $mess[426]); } else { $loggedUser = AuthService::getLoggedUser(); // Make sure we do not overwrite otherwise loaded rights. $loggedUser->load(); $loggedUser->setRight($newRep->getUniqueId(), "rw"); $loggedUser->save("superuser"); 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->removeRights($repoId); $loggedUser->save("superuser"); AuthService::updateUser($loggedUser); AJXP_XMLWriter::sendMessage($mess[428], null); AJXP_XMLWriter::reloadRepositoryList(); } AJXP_XMLWriter::close(); 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; }
public function remoteRepositoryById($repositoryId, &$repoObject) { if (strpos($repositoryId, "ocs_remote_share_") !== 0) { return; } $store = new Model\SQLStore(); $remoteShareId = str_replace("ocs_remote_share_", "", $repositoryId); $share = $store->remoteShareById($remoteShareId); if ($share != null) { $repoObject = $share->buildVirtualRepository(); $loggedUser = \AuthService::getLoggedUser(); if ($loggedUser != null) { $loggedUser->personalRole->setAcl($repoObject->getId(), "rw"); $loggedUser->recomputeMergedRole(); \AuthService::updateUser($loggedUser); } } }
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::getRootDirsList(); 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::getCurrentRootDirIndex(); $user->setArrayPref("history", "last_repository", $activeRepId); $user->save(); } //$logMessage = "Successfully Switched!"; AJXP_Logger::logAction("Switch Repository", array("rep. id" => $repository_id)); 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) { exit(1); } if (isset($_GET["bm_action"]) && isset($_GET["bm_path"])) { if ($_GET["bm_action"] == "add_bookmark") { $title = ""; if (isset($_GET["bm_title"])) { $title = $_GET["bm_title"]; } if ($title == "" && $_GET["bm_path"] == "/") { $title = ConfService::getCurrentRootDirDisplay(); } $bmUser->addBookMark(SystemTextEncoding::magicDequote($_GET["bm_path"]), SystemTextEncoding::magicDequote($title)); } else { if ($_GET["bm_action"] == "delete_bookmark") { $bmUser->removeBookmark($_GET["bm_path"]); } else { if ($_GET["bm_action"] == "rename_bookmark" && isset($_GET["bm_title"])) { $bmUser->renameBookmark($_GET["bm_path"], $_GET["bm_title"]); } } } } if (AuthService::usersEnabled() && AuthService::getLoggedUser() != null) { $bmUser->save(); AuthService::updateUser($bmUser); } else { if (!AuthService::usersEnabled()) { $bmUser->save(); } } AJXP_XMLWriter::header(); AJXP_XMLWriter::writeBookmarks($bmUser->getBookmarks()); AJXP_XMLWriter::close(); exit(1); break; //------------------------------------ // SAVE USER PREFERENCE //------------------------------------ //------------------------------------ // SAVE USER PREFERENCE //------------------------------------ case "save_user_pref": $userObject = AuthService::getLoggedUser(); $i = 0; while (isset($_GET["pref_name_" . $i]) && isset($_GET["pref_value_" . $i])) { $prefName = AJXP_Utils::sanitize($_GET["pref_name_" . $i], AJXP_SANITIZE_ALPHANUM); $prefValue = AJXP_Utils::sanitize(SystemTextEncoding::magicDequote($_GET["pref_value_" . $i])); if ($prefName == "password") { continue; } if ($prefName != "pending_folder" && ($userObject == null || $userObject->getId() == "guest")) { $i++; continue; } $userObject->setPref($prefName, $prefValue); $userObject->save(); AuthService::updateUser($userObject); //setcookie("AJXP_$prefName", $prefValue); $i++; } header("Content-Type:text/plain"); print "SUCCESS"; exit(1); 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; }
$rememberPass = $loggedUser->getCookieString(); } if ($loggingResult == 1) { session_regenerate_id(true); } } else { AuthService::logUser(null, null); } // Check that current user can access current repository, try to switch otherwise. $loggedUser = AuthService::getLoggedUser(); if ($loggedUser != null) { if (isset($_SESSION["PENDING_REPOSITORY_ID"]) && isset($_SESSION["PENDING_FOLDER"])) { $loggedUser->setArrayPref("history", "last_repository", $_SESSION["PENDING_REPOSITORY_ID"]); $loggedUser->setPref("pending_folder", $_SESSION["PENDING_FOLDER"]); $loggedUser->save(); AuthService::updateUser($loggedUser); unset($_SESSION["PENDING_REPOSITORY_ID"]); unset($_SESSION["PENDING_FOLDER"]); } $currentRepoId = ConfService::getCurrentRootDirIndex(); $lastRepoId = $loggedUser->getArrayPref("history", "last_repository"); $defaultRepoId = AuthService::getDefaultRootId(); if ($defaultRepoId == -1) { AuthService::disconnect(); $loggingResult = -3; } else { if ($lastRepoId != "" && $lastRepoId != $currentRepoId && !isset($httpVars["tmp_repository_id"]) && $loggedUser->canSwitchTo($lastRepoId)) { ConfService::switchRootDir($lastRepoId); } else { if (!$loggedUser->canSwitchTo($currentRepoId)) { ConfService::switchRootDir($defaultRepoId);
public function authenticate(Sabre\DAV\Server $server, $realm) { $auth = new Sabre\HTTP\BasicAuth(); $auth->setHTTPRequest($server->httpRequest); $auth->setHTTPResponse($server->httpResponse); $auth->setRealm($realm); $userpass = $auth->getUserPass(); if (!$userpass) { $auth->requireLogin(); throw new Sabre\DAV\Exception\NotAuthenticated('No basic authentication headers were found'); } // Authenticates the user //AJXP_Logger::info(__CLASS__,"authenticate",$userpass[0]); $confDriver = ConfService::getConfStorageImpl(); $userObject = $confDriver->createUserObject($userpass[0]); $webdavData = $userObject->getPref("AJXP_WEBDAV_DATA"); if (empty($webdavData) || !isset($webdavData["ACTIVE"]) || $webdavData["ACTIVE"] !== true) { throw new Sabre\DAV\Exception\NotAuthenticated(); } // check if there are cached credentials. prevents excessive authentication calls to external // auth mechanism. $cachedPasswordValid = 0; $secret = defined("AJXP_SECRET_KEY") ? AJXP_SECRET_KEY : "CDAFx¨op#"; $encryptedPass = md5($userpass[1] . $secret . date('YmdHi')); if (isset($webdavData["TMP_PASS"]) && $encryptedPass == $webdavData["TMP_PASS"]) { $cachedPasswordValid = true; //AJXP_Logger::debug("Using Cached Password"); } if (!$cachedPasswordValid && !$this->validateUserPass($userpass[0], $userpass[1])) { $auth->requireLogin(); throw new Sabre\DAV\Exception\NotAuthenticated('Username or password does not match'); } $this->currentUser = $userpass[0]; $res = AuthService::logUser($this->currentUser, $userpass[1], true); if ($res < 1) { throw new Sabre\DAV\Exception\NotAuthenticated(); } $this->updateCurrentUserRights(AuthService::getLoggedUser()); // the method used here will invalidate the cached password every minute on the minute if (!$cachedPasswordValid) { $webdavData["TMP_PASS"] = $encryptedPass; $userObject->setPref("AJXP_WEBDAV_DATA", $webdavData); $userObject->save("user"); AuthService::updateUser($userObject); } return true; }
/** * Utilitary to pass some parameters directly at startup : * + repository_id / folder * + compile & skipDebug * + update_i18n, extract, create * + external_selector_type * + skipIOS * + gui * @static * @param $parameters * @param $output * @param $session * @return void */ public static function parseApplicationGetParameters($parameters, &$output, &$session) { $output["EXT_REP"] = "/"; if (isset($parameters["repository_id"]) && isset($parameters["folder"]) || isset($parameters["goto"])) { if (isset($parameters["goto"])) { $explode = explode("/", ltrim($parameters["goto"], "/")); $repoId = array_shift($explode); $parameters["folder"] = str_replace($repoId, "", ltrim($parameters["goto"], "/")); } else { $repoId = $parameters["repository_id"]; } $repository = ConfService::getRepositoryById($repoId); if ($repository == null) { $repository = ConfService::getRepositoryByAlias($repoId); if ($repository != null) { $parameters["repository_id"] = $repository->getId(); } } else { $parameters["repository_id"] = $repository->getId(); } require_once AJXP_BIN_FOLDER . "/class.SystemTextEncoding.php"; if (AuthService::usersEnabled()) { $loggedUser = AuthService::getLoggedUser(); if ($loggedUser != null && $loggedUser->canSwitchTo($parameters["repository_id"])) { $output["FORCE_REGISTRY_RELOAD"] = true; $output["EXT_REP"] = SystemTextEncoding::toUTF8(urldecode($parameters["folder"])); $loggedUser->setArrayPref("history", "last_repository", $parameters["repository_id"]); $loggedUser->setPref("pending_folder", SystemTextEncoding::toUTF8(AJXP_Utils::decodeSecureMagic($parameters["folder"]))); $loggedUser->save("user"); AuthService::updateUser($loggedUser); } else { $session["PENDING_REPOSITORY_ID"] = $parameters["repository_id"]; $session["PENDING_FOLDER"] = SystemTextEncoding::toUTF8(AJXP_Utils::decodeSecureMagic($parameters["folder"])); } } else { ConfService::switchRootDir($parameters["repository_id"]); $output["EXT_REP"] = SystemTextEncoding::toUTF8(urldecode($parameters["folder"])); } } if (isset($parameters["skipDebug"])) { ConfService::setConf("JS_DEBUG", false); } if (ConfService::getConf("JS_DEBUG") && isset($parameters["compile"])) { require_once AJXP_BIN_FOLDER . "/class.AJXP_JSPacker.php"; AJXP_JSPacker::pack(); } if (ConfService::getConf("JS_DEBUG") && isset($parameters["update_i18n"])) { if (isset($parameters["extract"])) { self::extractConfStringsFromManifests(); } self::updateAllI18nLibraries(isset($parameters["create"]) ? $parameters["create"] : ""); } if (ConfService::getConf("JS_DEBUG") && isset($parameters["clear_plugins_cache"])) { @unlink(AJXP_PLUGINS_CACHE_FILE); @unlink(AJXP_PLUGINS_REQUIRES_FILE); } if (AJXP_SERVER_DEBUG && isset($parameters["extract_application_hooks"])) { self::extractHooksToDoc(); } if (isset($parameters["external_selector_type"])) { $output["SELECTOR_DATA"] = array("type" => $parameters["external_selector_type"], "data" => $parameters); } if (isset($parameters["skipIOS"])) { setcookie("SKIP_IOS", "true"); } if (isset($parameters["skipANDROID"])) { setcookie("SKIP_ANDROID", "true"); } if (isset($parameters["gui"])) { setcookie("AJXP_GUI", $parameters["gui"]); if ($parameters["gui"] == "light") { $session["USE_EXISTING_TOKEN_IF_EXISTS"] = true; } } else { if (isset($session["USE_EXISTING_TOKEN_IF_EXISTS"])) { unset($session["USE_EXISTING_TOKEN_IF_EXISTS"]); } setcookie("AJXP_GUI", null); } if (isset($session["OVERRIDE_GUI_START_PARAMETERS"])) { $output = array_merge($output, $session["OVERRIDE_GUI_START_PARAMETERS"]); } }
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; }
/** * Override parent method to keep a reference to the child users * @param $parentId */ public function setParent($parentId) { $u = ConfService::getConfStorageImpl()->createUserObject($parentId); $p = $u->getChildrenPointer(); if ($p == null) { $p = array(); } $p[$this->getId()] = $this->getId(); $u->setChildrenPointer($p); $u->save("superuser"); if (AuthService::getLoggedUser() != null && AuthService::getLoggedUser()->getId() == $parentId) { AuthService::updateUser($u); } parent::setParent($parentId); }
private function saveUserData($data) { $logged = AuthService::getLoggedUser(); $logged->setPref("meta.quota", $data); $logged->save("user"); AuthService::updateUser($logged); }
function switchAction($action, $httpVars, $fileVars) { if (!isset($this->actions[$action])) { return; } $xmlBuffer = ""; foreach ($httpVars as $getName => $getValue) { ${$getName} = Utils::securePath($getValue); } if (isset($dir) && $action != "upload") { $dir = SystemTextEncoding::fromUTF8($dir); } $mess = ConfService::getMessages(); switch ($action) { //------------------------------------ // SWITCH THE ROOT REPOSITORY //------------------------------------ case "switch_root_dir": if (!isset($root_dir_index)) { break; } $dirList = ConfService::getRootDirsList(); if (!isset($dirList[$root_dir_index])) { $errorMessage = "Trying to switch to an unkown folder!"; break; } ConfService::switchRootDir($root_dir_index); $logMessage = "Successfully Switched!"; AJXP_Logger::logAction("Switch Repository", array("rep. id" => $root_dir_index)); break; //------------------------------------ // GET AN HTML TEMPLATE //------------------------------------ //------------------------------------ // GET AN HTML TEMPLATE //------------------------------------ case "get_template": header("Content-type:text/html; charset:UTF-8"); if (isset($template_name) && is_file(CLIENT_RESOURCES_FOLDER . "/html/" . $template_name)) { if ($template_name == "gui_tpl.html") { include CLIENT_RESOURCES_FOLDER . "/html/usertemplate_top.html"; } include CLIENT_RESOURCES_FOLDER . "/html/" . $template_name; if ($template_name == "gui_tpl.html") { include CLIENT_RESOURCES_FOLDER . "/html/usertemplate_bottom.html"; } } exit(0); break; //------------------------------------ // GET I18N MESSAGES //------------------------------------ //------------------------------------ // GET I18N MESSAGES //------------------------------------ case "get_i18n_messages": header("Content-type:text/javascript"); HTMLWriter::writeI18nMessagesClass(ConfService::getMessages()); exit(0); 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) { exit(1); } if (isset($_GET["bm_action"]) && isset($_GET["bm_path"])) { if ($_GET["bm_action"] == "add_bookmark") { $title = ""; if (isset($_GET["title"])) { $title = $_GET["title"]; } if ($title == "" && $_GET["bm_path"] == "/") { $title = ConfService::getCurrentRootDirDisplay(); } $bmUser->addBookMark($_GET["bm_path"], $title); } else { if ($_GET["bm_action"] == "delete_bookmark") { $bmUser->removeBookmark($_GET["bm_path"]); } else { if ($_GET["bm_action"] == "rename_bookmark" && isset($_GET["bm_title"])) { $bmUser->renameBookmark($_GET["bm_path"], $_GET["bm_title"]); } } } } if (AuthService::usersEnabled() && AuthService::getLoggedUser() != null) { $bmUser->save(); AuthService::updateUser($bmUser); } else { if (!AuthService::usersEnabled()) { $bmUser->save(); } } AJXP_XMLWriter::header(); AJXP_XMLWriter::writeBookmarks($bmUser->getBookmarks()); AJXP_XMLWriter::close(); exit(1); break; //------------------------------------ // SAVE USER PREFERENCE //------------------------------------ //------------------------------------ // SAVE USER PREFERENCE //------------------------------------ case "save_user_pref": $userObject = AuthService::getLoggedUser(); if ($userObject == null) { exit(1); } $i = 0; while (isset($_GET["pref_name_" . $i]) && isset($_GET["pref_value_" . $i])) { $prefName = $_GET["pref_name_" . $i]; $prefValue = $_GET["pref_value_" . $i]; if ($prefName != "password") { $userObject->setPref($prefName, $prefValue); $userObject->save(); AuthService::updateUser($userObject); setcookie("AJXP_{$prefName}", $prefValue); } else { if (isset($_GET["crt"]) && AuthService::checkPassword($userObject->getId(), $_GET["crt"], false, $_GET["pass_seed"])) { AuthService::updatePassword($userObject->getId(), $prefValue); } else { //$errorMessage = "Wrong password!"; header("Content-Type:text/plain"); print "PASS_ERROR"; exit(1); } } $i++; } header("Content-Type:text/plain"); print "SUCCESS"; exit(1); break; //------------------------------------ // DISPLAY DOC //------------------------------------ //------------------------------------ // DISPLAY DOC //------------------------------------ case "display_doc": header("Content-type:text/html; charset:UTF-8"); echo HTMLWriter::getDocFile(htmlentities($_GET["doc_file"])); exit(1); 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); } if (isset($reload_current_node) && $reload_current_node == "true") { $xmlBuffer .= AJXP_XMLWriter::reloadCurrentNode(false); } if (isset($reload_dest_node) && $reload_dest_node != "") { $xmlBuffer .= AJXP_XMLWriter::reloadNode($reload_dest_node, false); } if (isset($reload_file_list)) { $xmlBuffer .= AJXP_XMLWriter::reloadFileList($reload_file_list, false); } return $xmlBuffer; }
/** * Function for deleting a user * * @param String $userId * @param Array $deletedSubUsers */ public function deleteUser($userId, &$deletedSubUsers) { $user = $this->createUserObject($userId); $files = glob($user->getStoragePath() . "/*.ser"); if (is_array($files) && count($files)) { foreach ($files as $file) { unlink($file); } } if (is_dir($user->getStoragePath())) { rmdir($user->getStoragePath()); } // DELETE CHILDREN USING POINTER IF POSSIBLE $users = $this->getUserChildren($userId); // $authDriver->listUsers(); foreach (array_keys($users) as $id) { $object = $this->createUserObject($id); if ($object->hasParent() && $object->getParent() == $userId) { $this->deleteUser($id, $deletedSubUsers); $deletedSubUsers[] = $id; } } // CLEAR PARENT POINTER IF NECESSARY if ($user->hasParent()) { $parentObject = $this->createUserObject($user->getParent()); $pointer = $parentObject->getChildrenPointer(); if ($pointer !== null) { unset($pointer[$userId]); $parentObject->setChildrenPointer($pointer); $parentObject->save("superuser"); if (AuthService::getLoggedUser() != null && AuthService::getLoggedUser()->getId() == $parentObject->getId()) { AuthService::updateUser($parentObject); } } } $groups = AJXP_Utils::loadSerialFile(AJXP_VarsFilter::filter($user->storage->getOption("USERS_DIRPATH")) . "/groups.ser"); if (isset($groups[$userId])) { unset($groups[$userId]); AJXP_Utils::saveSerialFile(AJXP_VarsFilter::filter($user->storage->getOption("USERS_DIRPATH")) . "/groups.ser", $groups); } }
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("users" => array("LABEL" => $mess["ajxp_conf.2"], "ICON" => "yast_kuser.png"), "repositories" => array("LABEL" => $mess["ajxp_conf.3"], "ICON" => "folder_red.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 == "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(); 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 "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, $mess["ajxp_conf.61"]); 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, $mess["ajxp_conf.43"]); 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($mess["ajxp_conf.44"], 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($mess["ajxp_conf.45"] . $_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, $mess["ajxp_conf.61"]); 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($mess["ajxp_conf.46"] . $_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($mess["ajxp_conf.47"] . $_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, $mess["ajxp_conf.61"]); AJXP_XMLWriter::close(); exit(1); } $res = AuthService::updatePassword($_GET["user_id"], $_GET["user_pwd"]); AJXP_XMLWriter::header(); if ($res === true) { AJXP_XMLWriter::sendMessage($mess["ajxp_conf.48"] . $_GET["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 = $_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); } } 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 = $_GET["repository_id"]; $repo = ConfService::getRepositoryById($repId); $res = 0; if (isset($_GET["newLabel"])) { $newLabel = SystemTextEncoding::fromPostedFileName($_GET["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($_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, $mess["ajxp_conf.53"]); } else { AJXP_XMLWriter::sendMessage($mess["ajxp_conf.54"], null); AJXP_XMLWriter::reloadDataNode("", isset($_GET["newLabel"]) ? SystemTextEncoding::fromPostedFileName($_GET["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 { $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, $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; default: break; } return; }