Пример #1
0
 /**
  * Filter the very basic keywords from the XML  : AJXP_USER, AJXP_INSTALL_PATH, AJXP_DATA_PATH
  * Calls the vars.filter hooks.
  * @static
  * @param $value
  * @param AbstractAjxpUser|String $resolveUser
  * @return mixed|string
  */
 public static function filter($value, $resolveUser = null)
 {
     if (is_string($value) && strpos($value, "AJXP_USER") !== false) {
         if (AuthService::usersEnabled()) {
             if ($resolveUser != null) {
                 if (is_string($resolveUser)) {
                     $resolveUserId = $resolveUser;
                 } else {
                     $resolveUserId = $resolveUser->getId();
                 }
                 $value = str_replace("AJXP_USER", $resolveUserId, $value);
             } else {
                 $loggedUser = AuthService::getLoggedUser();
                 if ($loggedUser != null) {
                     if ($loggedUser->hasParent() && $loggedUser->getResolveAsParent()) {
                         $loggedUserId = $loggedUser->getParent();
                     } else {
                         $loggedUserId = $loggedUser->getId();
                     }
                     $value = str_replace("AJXP_USER", $loggedUserId, $value);
                 } else {
                     return "";
                 }
             }
         } else {
             $value = str_replace("AJXP_USER", "shared", $value);
         }
     }
     if (is_string($value) && strpos($value, "AJXP_GROUP_PATH") !== false) {
         if (AuthService::usersEnabled()) {
             if ($resolveUser != null) {
                 if (is_string($resolveUser) && AuthService::userExists($resolveUser)) {
                     $loggedUser = ConfService::getConfStorageImpl()->createUserObject($resolveUser);
                 } else {
                     $loggedUser = $resolveUser;
                 }
             } else {
                 $loggedUser = AuthService::getLoggedUser();
             }
             if ($loggedUser != null) {
                 $gPath = $loggedUser->getGroupPath();
                 $value = str_replace("AJXP_GROUP_PATH_FLAT", str_replace("/", "_", trim($gPath, "/")), $value);
                 $value = str_replace("AJXP_GROUP_PATH", $gPath, $value);
             } else {
                 return "";
             }
         } else {
             $value = str_replace(array("AJXP_GROUP_PATH", "AJXP_GROUP_PATH_FLAT"), "shared", $value);
         }
     }
     if (is_string($value) && strpos($value, "AJXP_INSTALL_PATH") !== false) {
         $value = str_replace("AJXP_INSTALL_PATH", AJXP_INSTALL_PATH, $value);
     }
     if (is_string($value) && strpos($value, "AJXP_DATA_PATH") !== false) {
         $value = str_replace("AJXP_DATA_PATH", AJXP_DATA_PATH, $value);
     }
     $tab = array(&$value);
     AJXP_Controller::applyIncludeHook("vars.filter", $tab);
     return $value;
 }
Пример #2
0
 public function __construct()
 {
     $storage = \ConfService::getConfStorageImpl();
     if ($storage->getId() == "conf.sql") {
         $this->storage = $storage;
     }
 }
 function AbstractAjxpUser($id, $storage = null)
 {
     $this->id = $id;
     if ($storage == null) {
         $storage = ConfService::getConfStorageImpl();
     }
     $this->storage = $storage;
     $this->load();
 }
 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) {
         AJXP_Logger::warning(__CLASS__, "Login failed", array("user" => $userpass[0], "error" => "WebDAV user not found or disabled"));
         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])) {
         AJXP_Logger::warning(__CLASS__, "Login failed", array("user" => $userpass[0], "error" => "Invalid WebDAV user or password"));
         $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());
     if (ConfService::getCoreConf("SESSION_SET_CREDENTIALS", "auth")) {
         AJXP_Safe::storeCredentials($this->currentUser, $userpass[1]);
     }
     if (isset($this->repositoryId) && ConfService::getRepositoryById($this->repositoryId)->getOption("AJXP_WEBDAV_DISABLED") === true) {
         throw new Sabre\DAV\Exception\NotAuthenticated('You are not allowed to access this workspace');
     }
     ConfService::switchRootDir($this->repositoryId);
     // 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;
 }
Пример #5
0
 public function listUsers($baseGroup = "/")
 {
     $users = AJXP_Utils::loadSerialFile($this->usersSerFile);
     if (AuthService::ignoreUserCase()) {
         $users = array_combine(array_map("strtolower", array_keys($users)), array_values($users));
     }
     ConfService::getConfStorageImpl()->filterUsersByGroup($users, $baseGroup, false);
     ksort($users);
     return $users;
 }
 /**
  * @return AjxpWebdavProvider
  * @throws ezcBaseFileNotFoundException
  */
 protected function getAccessDriver()
 {
     if (!isset($this->accessDriver)) {
         $confDriver = ConfService::getConfStorageImpl();
         $this->accessDriver = ConfService::loadRepositoryDriver();
         if (!$this->accessDriver instanceof AjxpWebdavProvider) {
             throw new ezcBaseFileNotFoundException($this->repository->getUniqueId());
         }
         $wrapperData = $this->accessDriver->detectStreamWrapper(true);
         $this->wrapperClassName = $wrapperData["classname"];
     }
     return $this->accessDriver;
 }
Пример #7
0
 /**
  * @return AjxpWrapperProvider
  * @throws \Sabre\DAV\Exception\NotFound
  */
 public function getAccessDriver()
 {
     if (!isset($this->accessDriver)) {
         //$RID = $this->repository->getId();
         //ConfService::switchRootDir($RID);
         ConfService::getConfStorageImpl();
         $this->accessDriver = ConfService::loadDriverForRepository($this->repository);
         if (!$this->accessDriver instanceof AjxpWrapperProvider) {
             throw new Sabre\DAV\Exception\NotFound($this->repository->getId());
         }
         $this->accessDriver->detectStreamWrapper(true);
     }
     return $this->accessDriver;
 }
 function countAdminUsers()
 {
     $confDriver = ConfService::getConfStorageImpl();
     $authDriver = ConfService::getAuthDriverImpl();
     $count = 0;
     $users = $authDriver->listUsers();
     foreach (array_keys($users) as $userId) {
         $userObject = $confDriver->createUserObject($userId);
         $userObject->load();
         if ($userObject->isAdmin()) {
             $count++;
         }
     }
     return $count;
 }
Пример #9
0
 public function receiveAction($action, $httpVars, $filesVars)
 {
     $provider = $this->getFilteredOption("AVATAR_PROVIDER");
     $type = $this->getFilteredOption("GRAVATAR_TYPE");
     if ($action == "get_avatar_url") {
         $url = "";
         $suffix = "";
         switch ($provider) {
             case "gravatar":
             default:
                 if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
                     $url = "https://secure.gravatar.com";
                 } else {
                     $url = "http://www.gravatar.com";
                 }
                 $url .= "/avatar/";
                 $suffix .= "?s=80&r=g&d=" . $type;
                 break;
             case "libravatar":
                 $url = "";
                 // Federated Servers are not supported here without libravatar.org. Should query DNS server first.
                 if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
                     $url = "https://seccdn.libravatar.org";
                 } else {
                     $url = "http://cdn.libravatar.org";
                 }
                 $url .= "/avatar/";
                 $suffix = "?s=80&d=" . $type;
                 break;
         }
         if (isset($httpVars["userid"])) {
             $userid = $httpVars["userid"];
             if (AuthService::usersEnabled() && AuthService::userExists($userid)) {
                 $confDriver = ConfService::getConfStorageImpl();
                 $user = $confDriver->createUserObject($userid);
                 $userEmail = $user->personalRole->filterParameterValue("core.conf", "email", AJXP_REPO_SCOPE_ALL, "");
                 if (!empty($userEmail)) {
                     $url .= md5(strtolower(trim($userEmail)));
                 }
             }
         }
         $url .= $suffix;
         print $url;
     }
 }
 public function getDigestHash($realm, $username)
 {
     if (!AuthService::userExists($username)) {
         return false;
     }
     $confDriver = ConfService::getConfStorageImpl();
     $user = $confDriver->createUserObject($username);
     $webdavData = $user->getPref("AJXP_WEBDAV_DATA");
     if (empty($webdavData) || !isset($webdavData["ACTIVE"]) || $webdavData["ACTIVE"] !== true || !isset($webdavData["PASS"]) && !isset($webdavData["HA1"])) {
         return false;
     }
     if (isset($webdavData["HA1"])) {
         return $webdavData["HA1"];
     } else {
         $pass = $this->_decodePassword($webdavData["PASS"], $username);
         return md5("{$username}:{$realm}:{$pass}");
     }
 }
 private function orbitExtensionActive()
 {
     $confs = ConfService::getConfStorageImpl()->loadPluginConfig("gui", "ajax");
     if (!isset($confs) || !isset($confs["GUI_THEME"])) {
         $confs["GUI_THEME"] = "orbit";
     }
     if ($confs["GUI_THEME"] == "orbit") {
         $pServ = AJXP_PluginsService::getInstance();
         $activePlugs = $pServ->getActivePlugins();
         $streamWrappers = $pServ->getStreamWrapperPlugins();
         $streamActive = false;
         foreach ($streamWrappers as $sW) {
             if (array_key_exists($sW, $activePlugs) && $activePlugs[$sW] === true) {
                 $streamActive = true;
                 break;
             }
         }
         return $streamActive;
     }
     return false;
 }
Пример #12
0
 public function logoutCallback($actionName, $httpVars, $fileVars)
 {
     $safeCredentials = AJXP_Safe::loadCredentials();
     $crtUser = $safeCredentials["user"];
     if (isset($_SESSION["AJXP_DYNAMIC_FTP_DATA"])) {
         unset($_SESSION["AJXP_DYNAMIC_FTP_DATA"]);
     }
     AJXP_Safe::clearCredentials();
     $adminUser = $this->options["AJXP_ADMIN_LOGIN"];
     if (isset($this->options["ADMIN_USER"])) {
         $adminUser = $this->options["AJXP_ADMIN_LOGIN"];
     }
     $subUsers = array();
     if ($crtUser != $adminUser && $crtUser != "") {
         ConfService::getConfStorageImpl()->deleteUser($crtUser, $subUsers);
     }
     AuthService::disconnect();
     session_destroy();
     session_write_close();
     AJXP_XMLWriter::header();
     AJXP_XMLWriter::loggingResult(2);
     AJXP_XMLWriter::close();
 }
Пример #13
0
 public function updateUserObject(&$userObject)
 {
     parent::updateUserObject($userObject);
     if (!empty($this->separateGroup)) {
         $userObject->setGroupPath("/" . $this->separateGroup);
     }
     // SHOULD BE DEPRECATED
     if (!empty($this->customParamsMapping)) {
         $checkValues = array_values($this->customParamsMapping);
         $prefs = $userObject->getPref("CUSTOM_PARAMS");
         if (!is_array($prefs)) {
             $prefs = array();
         }
         // If one value exist, we consider the mapping has already been done.
         foreach ($checkValues as $val) {
             if (array_key_exists($val, $prefs)) {
                 return;
             }
         }
         $changes = false;
         $entries = $this->getUserEntries($userObject->getId());
         if ($entries["count"]) {
             $entry = $entries[0];
             foreach ($this->customParamsMapping as $key => $value) {
                 if (isset($entry[$key])) {
                     $prefs[$value] = $entry[$key][0];
                     $changes = true;
                 }
             }
         }
         if ($changes) {
             $userObject->setPref("CUSTOM_PARAMS", $prefs);
             $userObject->save();
         }
     }
     if (!empty($this->paramsMapping)) {
         $changes = false;
         $entries = $this->getUserEntries($userObject->getId());
         if ($entries["count"]) {
             $entry = $entries[0];
             foreach ($this->paramsMapping as $params) {
                 $key = strtolower($params['MAPPING_LDAP_PARAM']);
                 if (isset($entry[$key])) {
                     $value = $entry[$key][0];
                     $memberValues = array();
                     if ($key == "memberof") {
                         // get CN from value
                         foreach ($entry[$key] as $possibleValue) {
                             $hnParts = array();
                             $parts = explode(",", ltrim($possibleValue, '/'));
                             foreach ($parts as $part) {
                                 list($att, $attVal) = explode("=", $part);
                                 //if (strtolower($att) == "cn")  $hnParts[] = $attVal;
                                 /*
                                  * In the example above, 1st CN indicates the name of group, from 2nd, CN indicate a container,
                                  * therefore, we just take the first "cn" element by breaking the for if we found.
                                  *
                                  */
                                 if (strtolower($att) == "cn") {
                                     $hnParts[] = $attVal;
                                     break;
                                 }
                             }
                             if (count($hnParts)) {
                                 $memberValues[implode(",", $hnParts)] = $possibleValue;
                             }
                         }
                     }
                     switch ($params['MAPPING_LOCAL_TYPE']) {
                         case "role_id":
                             $valueFilters = null;
                             $matchFilter = null;
                             $filter = $params["MAPPING_LOCAL_PARAM"];
                             if (strpos($filter, "preg:") !== false) {
                                 $matchFilter = "/" . str_replace("preg:", "", $filter) . "/i";
                             } else {
                                 if (!empty($filter)) {
                                     $valueFilters = array_map("trim", explode(",", $filter));
                                 }
                             }
                             if ($key == "memberof") {
                                 if (empty($valueFilters)) {
                                     $valueFilters = $this->getLdapGroupListFromDN();
                                 }
                                 if ($this->mappedRolePrefix) {
                                     $rolePrefix = $this->mappedRolePrefix;
                                 } else {
                                     $rolePrefix = "";
                                 }
                                 $userroles = $userObject->getRoles();
                                 //remove all mapped roles before
                                 if (is_array($userroles)) {
                                     foreach ($userroles as $key => $role) {
                                         if (AuthService::getRole($key) && !(strpos($key, $this->mappedRolePrefix) === false)) {
                                             $userObject->removeRole($key);
                                         }
                                     }
                                 }
                                 $userObject->recomputeMergedRole();
                                 foreach ($memberValues as $uniqValue => $fullDN) {
                                     $uniqValueWithPrefix = $rolePrefix . $uniqValue;
                                     if (isset($matchFilter) && !preg_match($matchFilter, $uniqValueWithPrefix)) {
                                         continue;
                                     }
                                     if (isset($valueFilters) && !in_array($uniqValueWithPrefix, $valueFilters)) {
                                         continue;
                                     }
                                     $roleToAdd = AuthService::getRole($uniqValueWithPrefix, true);
                                     $roleToAdd->setLabel($uniqValue);
                                     AuthService::updateRole($roleToAdd);
                                     $userObject->addRole($roleToAdd);
                                     $changes = true;
                                 }
                             } else {
                                 foreach ($entry[$key] as $uniqValue) {
                                     if (isset($matchFilter) && !preg_match($matchFilter, $uniqValue)) {
                                         continue;
                                     }
                                     if (isset($valueFilters) && !in_array($uniqValue, $valueFilters)) {
                                         continue;
                                     }
                                     if (!in_array($uniqValue, array_keys($userObject->getRoles())) && !empty($uniqValue)) {
                                         $userObject->addRole(AuthService::getRole($uniqValue, true));
                                         $changes = true;
                                     }
                                 }
                             }
                             break;
                         case "group_path":
                             if ($key == "memberof") {
                                 $filter = $params["MAPPING_LOCAL_PARAM"];
                                 if (strpos($filter, "preg:") !== false) {
                                     $matchFilter = "/" . str_replace("preg:", "", $filter) . "/i";
                                 } else {
                                     if (!empty($filter)) {
                                         $valueFilters = array_map("trim", explode(",", $filter));
                                     }
                                 }
                                 foreach ($memberValues as $uniqValue => $fullDN) {
                                     if (isset($matchFilter) && !preg_match($matchFilter, $uniqValue)) {
                                         continue;
                                     }
                                     if (isset($valueFilters) && !in_array($uniqValue, $valueFilters)) {
                                         continue;
                                     }
                                     if ($userObject->personalRole->filterParameterValue("auth.ldap", "MEMBER_OF", AJXP_REPO_SCOPE_ALL, "") == $fullDN) {
                                         //break;
                                     }
                                     $humanName = $uniqValue;
                                     $branch = array();
                                     $this->buildGroupBranch($uniqValue, $branch);
                                     $parent = "/";
                                     if (count($branch)) {
                                         $parent = "/" . implode("/", array_reverse($branch));
                                     }
                                     if (!ConfService::getConfStorageImpl()->groupExists(rtrim(AuthService::filterBaseGroup($parent), "/") . "/" . $fullDN)) {
                                         AuthService::createGroup($parent, $fullDN, $humanName);
                                     }
                                     $userObject->setGroupPath(rtrim($parent, "/") . "/" . $fullDN, true);
                                     // Update Roles from groupPath
                                     $b = array_reverse($branch);
                                     $b[] = $fullDN;
                                     for ($i = 1; $i <= count($b); $i++) {
                                         $userObject->addRole(AuthService::getRole("AJXP_GRP_/" . implode("/", array_slice($b, 0, $i)), true));
                                     }
                                     $userObject->personalRole->setParameterValue("auth.ldap", "MEMBER_OF", $fullDN);
                                     $userObject->recomputeMergedRole();
                                     $changes = true;
                                 }
                             }
                             break;
                         case "profile":
                             if ($userObject->getProfile() != $value) {
                                 $changes = true;
                                 $userObject->setProfile($value);
                                 AuthService::updateAutoApplyRole($userObject);
                             }
                             break;
                         case "plugin_param":
                         default:
                             if (strpos($params["MAPPING_LOCAL_PARAM"], "/") !== false) {
                                 list($pId, $param) = explode("/", $params["MAPPING_LOCAL_PARAM"]);
                             } else {
                                 $pId = $this->getId();
                                 $param = $params["MAPPING_LOCAL_PARAM"];
                             }
                             if ($userObject->personalRole->filterParameterValue($pId, $param, AJXP_REPO_SCOPE_ALL, "") != $value) {
                                 $userObject->personalRole->setParameterValue($pId, $param, $value);
                                 $userObject->recomputeMergedRole();
                                 $changes = true;
                             }
                             break;
                     }
                 }
             }
         }
         if ($changes) {
             $userObject->save("superuser");
         }
     }
 }
Пример #14
0
 public function userExists($login)
 {
     // Check if local storage exists for the user. If it does, assume the user
     // exists. This prevents a barrage of ldap_connect/ldap_bind/ldap_search
     // calls.
     $confDriver = ConfService::getConfStorageImpl();
     $userObject = $confDriver->instantiateAbstractUserImpl($login);
     if ($userObject->storageExists()) {
         //return true;
     }
     $entries = $this->getUserEntries($login);
     if (!is_array($entries)) {
         return false;
     }
     if (AuthService::ignoreUserCase()) {
         $res = strcasecmp($login, $entries[0][$this->ldapUserAttr][0]) == 0;
     } else {
         $res = strcmp($login, $entries[0][$this->ldapUserAttr][0]) == 0;
     }
     $this->logDebug(__FUNCTION__, 'checking if user ' . $login . ' exists  : ' . $res);
     return $res;
 }
Пример #15
0
//------------------------------------------------------------
// SPECIAL HANDLING FOR FANCY UPLOADER RIGHTS FOR THIS ACTION
//------------------------------------------------------------
if (AuthService::usersEnabled()) {
    $loggedUser = AuthService::getLoggedUser();
    if ($action == "upload" && ($loggedUser == null || !$loggedUser->canWrite(ConfService::getCurrentRepositoryId() . "")) && isset($_FILES['Filedata'])) {
        header('HTTP/1.0 ' . '410 Not authorized');
        die('Error 410 Not authorized!');
    }
}
// THIS FIRST DRIVERS DO NOT NEED ID CHECK
//$ajxpDriver = AJXP_PluginsService::findPlugin("gui", "ajax");
$authDriver = ConfService::getAuthDriverImpl();
// DRIVERS BELOW NEED IDENTIFICATION CHECK
if (!AuthService::usersEnabled() || ConfService::getCoreConf("ALLOW_GUEST_BROWSING", "auth") || AuthService::getLoggedUser() != null) {
    $confDriver = ConfService::getConfStorageImpl();
    $Driver = ConfService::loadRepositoryDriver();
}
AJXP_PluginsService::getInstance()->initActivePlugins();
require_once AJXP_BIN_FOLDER . "/class.AJXP_Controller.php";
$xmlResult = AJXP_Controller::findActionAndApply($action, array_merge($_GET, $_POST), $_FILES);
if ($xmlResult !== false && $xmlResult != "") {
    AJXP_XMLWriter::header();
    print $xmlResult;
    AJXP_XMLWriter::close();
} else {
    if (isset($requireAuth) && AJXP_Controller::$lastActionNeedsAuth) {
        AJXP_XMLWriter::header();
        AJXP_XMLWriter::requireAuth();
        AJXP_XMLWriter::close();
    }
 public function __wakeup()
 {
     $this->storage = ConfService::getConfStorageImpl();
     $this->recomputeMergedRole();
 }
 public function getFilteredOption($optionName, $repoScope = AJXP_REPO_SCOPE_ALL, $userObject = null)
 {
     $repo = $this->accessDriver->repository;
     if ($repo->hasParent() && $repo->getOwner() != null && $repo->getOwner() != AuthService::getLoggedUser()->getId()) {
         // Pass parent user instead of currently logged
         $userObject = ConfService::getConfStorageImpl()->createUserObject($repo->getOwner());
     }
     return parent::getFilteredOption($optionName, $repoScope, $userObject);
 }
Пример #18
0
 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;
 }
Пример #19
0
 public function setGroupPath($groupPath, $update = false)
 {
     if ($update && isset($this->groupPath) && $groupPath != $this->groupPath) {
         // Update Shared Users groups as well
         $res = dibi::query("SELECT [u.login] FROM [ajxp_users] AS u, [ajxp_user_rights] AS p WHERE [u.login] = [p.login] AND [p.repo_uuid] = %s AND [p.rights] = %s AND [u.groupPath] != %s ", "ajxp.parent_user", $this->getId(), $groupPath);
         foreach ($res as $row) {
             $userId = $row->login;
             // UPDATE USER GROUP AND ROLES
             $u = ConfService::getConfStorageImpl()->createUserObject($userId);
             $u->setGroupPath($groupPath);
             $r = $u->getRoles();
             // REMOVE OLD GROUP ROLES
             foreach (array_keys($r) as $role) {
                 if (strpos($role, "AJXP_GRP_/") === 0) {
                     $u->removeRole($role);
                 }
             }
             $u->recomputeMergedRole();
             $u->save("superuser");
         }
     }
     parent::setGroupPath($groupPath);
     dibi::query('UPDATE [ajxp_users] SET ', array('groupPath' => $groupPath), 'WHERE [login] = %s', $this->getId());
     $this->log('UPDATE GROUP: [Login]: ' . $this->getId() . ' [Group]:' . $groupPath);
 }
Пример #20
0
 /**
  * Create the users based on the installer form results.
  * @param array $data Parsed form results
  * @param bool $loginIsEmail Whether to use the login as primary email.
  * @throws Exception
  */
 public function createUsers($data, $loginIsEmail = false)
 {
     $newConfigPlugin = ConfService::getConfStorageImpl();
     require_once $newConfigPlugin->getUserClassFileName();
     $adminLogin = AJXP_Utils::sanitize($data["ADMIN_USER_LOGIN"], AJXP_SANITIZE_EMAILCHARS);
     $adminName = $data["ADMIN_USER_NAME"];
     $adminPass = $data["ADMIN_USER_PASS"];
     AuthService::createUser($adminLogin, $adminPass, true);
     $uObj = $newConfigPlugin->createUserObject($adminLogin);
     if ($loginIsEmail) {
         $uObj->personalRole->setParameterValue("core.conf", "email", $data["ADMIN_USER_LOGIN"]);
     } else {
         if (isset($data["MAILER_ADMIN"])) {
             $uObj->personalRole->setParameterValue("core.conf", "email", $data["MAILER_ADMIN"]);
         }
     }
     $uObj->personalRole->setParameterValue("core.conf", "USER_DISPLAY_NAME", $adminName);
     $repos = ConfService::getRepositoriesList("all", false);
     foreach ($repos as $repo) {
         $uObj->personalRole->setAcl($repo->getId(), "rw");
     }
     AuthService::updateRole($uObj->personalRole);
     $loginP = "USER_LOGIN";
     $i = 0;
     while (isset($data[$loginP]) && !empty($data[$loginP])) {
         $pass = $data[str_replace("_LOGIN", "_PASS", $loginP)];
         $name = $data[str_replace("_LOGIN", "_NAME", $loginP)];
         $mail = $data[str_replace("_LOGIN", "_MAIL", $loginP)];
         $saniLogin = AJXP_Utils::sanitize($data[$loginP], AJXP_SANITIZE_EMAILCHARS);
         AuthService::createUser($saniLogin, $pass);
         $uObj = $newConfigPlugin->createUserObject($saniLogin);
         $uObj->personalRole->setParameterValue("core.conf", "email", $mail);
         $uObj->personalRole->setParameterValue("core.conf", "USER_DISPLAY_NAME", $name);
         AuthService::updateRole($uObj->personalRole);
         $i++;
         $loginP = "USER_LOGIN_" . $i;
     }
 }
 /**
  * @param String $watchType
  * @param String $currentUserId
  * @param AJXP_Node $node
  * @param array|bool $watchMeta
  * @param array|bool $usersMeta
  * @return array
  */
 private function loadWatchesFromMeta($watchType, $currentUserId, $node, $watchMeta = false, $usersMeta = false)
 {
     $IDS = array();
     if ($usersMeta !== false) {
         if ($watchType == self::$META_WATCH_CHANGE && isset($usersMeta[self::$META_WATCH_USERS_CHANGE])) {
             $usersMeta = $usersMeta[self::$META_WATCH_USERS_CHANGE];
         } else {
             if ($watchType == self::$META_WATCH_READ && isset($usersMeta[self::$META_WATCH_USERS_READ])) {
                 $usersMeta = $usersMeta[self::$META_WATCH_USERS_READ];
             } else {
                 $usersMeta = null;
             }
         }
     }
     if (!empty($watchMeta) && is_array($watchMeta)) {
         foreach ($watchMeta as $id => $type) {
             if ($type == $watchType || $type == self::$META_WATCH_BOTH) {
                 $IDS[] = $id;
             }
         }
     }
     if (!empty($usersMeta) && is_array($usersMeta)) {
         foreach ($usersMeta as $id => $targetUsers) {
             if (in_array($currentUserId, $targetUsers)) {
                 $IDS[] = $id;
             }
         }
     }
     if (count($IDS)) {
         $changes = false;
         foreach ($IDS as $index => $id) {
             if ($currentUserId == $id && !AJXP_SERVER_DEBUG) {
                 // In non-debug mode, do not send notifications to watcher!
                 unset($IDS[$index]);
                 continue;
             }
             if (!AuthService::userExists($id)) {
                 unset($IDS[$index]);
                 if (is_array($watchMeta)) {
                     $changes = true;
                     $watchMeta[$id] = AJXP_VALUE_CLEAR;
                 }
             } else {
                 // Make sure the user is still authorized on this node, otherwise remove it.
                 $uObject = ConfService::getConfStorageImpl()->createUserObject($id);
                 $acl = $uObject->mergedRole->getAcl($node->getRepositoryId());
                 $isOwner = $node->getRepository()->getOwner() == $uObject->getId();
                 if (!$isOwner && (empty($acl) || strpos($acl, "r") === FALSE)) {
                     unset($IDS[$index]);
                     if (is_array($watchMeta)) {
                         $changes = true;
                         $watchMeta[$id] = AJXP_VALUE_CLEAR;
                     }
                 }
             }
         }
         if ($changes) {
             $node->setMetadata(self::$META_WATCH_NAMESPACE, $watchMeta, false, AJXP_METADATA_SCOPE_REPOSITORY);
         }
     }
     return $IDS;
 }
Пример #22
0
 protected function updateTags($tagString)
 {
     $store = ConfService::getConfStorageImpl();
     if (!is_a($store, "sqlConfDriver")) {
         return;
     }
     $tags = $this->loadTags();
     $tags = array_merge($tags, array_map("trim", explode(",", $tagString)));
     $tags = array_unique($tags);
     $store->simpleStoreSet("meta_user_tags", ConfService::getRepository()->getId(), array_values($tags), "serial");
 }
Пример #23
0
 /**
  * Extract all the user data and put it in XML
  * @static
  * @param null $userObject * @internal param bool $details
  * @return string
  */
 public static function getUserXML($userObject = null)
 {
     $buffer = "";
     $loggedUser = AuthService::getLoggedUser();
     $confDriver = ConfService::getConfStorageImpl();
     if ($userObject != null) {
         $loggedUser = $userObject;
     }
     if (!AuthService::usersEnabled()) {
         $buffer .= "<user id=\"shared\">";
         $buffer .= "<active_repo id=\"" . ConfService::getCurrentRepositoryId() . "\" write=\"1\" read=\"1\"/>";
         $buffer .= AJXP_XMLWriter::writeRepositoriesData(null);
         $buffer .= "</user>";
     } else {
         if ($loggedUser != null) {
             $lock = $loggedUser->getLock();
             $buffer .= "<user id=\"" . $loggedUser->id . "\">";
             $buffer .= "<active_repo id=\"" . ConfService::getCurrentRepositoryId() . "\" write=\"" . ($loggedUser->canWrite(ConfService::getCurrentRepositoryId()) ? "1" : "0") . "\" read=\"" . ($loggedUser->canRead(ConfService::getCurrentRepositoryId()) ? "1" : "0") . "\"/>";
             $buffer .= AJXP_XMLWriter::writeRepositoriesData($loggedUser);
             $buffer .= "<preferences>";
             $preferences = $confDriver->getExposedPreferences($loggedUser);
             foreach ($preferences as $prefName => $prefData) {
                 $atts = "";
                 if (isset($prefData["exposed"]) && $prefData["exposed"] == true) {
                     foreach ($prefData as $k => $v) {
                         if ($k == "name") {
                             continue;
                         }
                         if ($k == "value") {
                             $k = "default";
                         }
                         $atts .= "{$k}='{$v}' ";
                     }
                 }
                 if (isset($prefData["pluginId"])) {
                     $atts .= "pluginId='" . $prefData["pluginId"] . "' ";
                 }
                 if ($prefData["type"] == "string") {
                     $buffer .= "<pref name=\"{$prefName}\" value=\"" . $prefData["value"] . "\" {$atts}/>";
                 } else {
                     if ($prefData["type"] == "json") {
                         $buffer .= "<pref name=\"{$prefName}\" {$atts}><![CDATA[" . $prefData["value"] . "]]></pref>";
                     }
                 }
             }
             $buffer .= "</preferences>";
             $buffer .= "<special_rights is_admin=\"" . ($loggedUser->isAdmin() ? "1" : "0") . "\"  " . ($lock !== false ? "lock=\"{$lock}\"" : "") . "/>";
             /*
             $bMarks = $loggedUser->getBookmarks();
             if (count($bMarks)) {
                 $buffer.= "<bookmarks>".AJXP_XMLWriter::writeBookmarks($bMarks, false)."</bookmarks>";
             }
             */
             $buffer .= "</user>";
         }
     }
     return $buffer;
 }
Пример #24
0
 public function getAuthorLabel()
 {
     if (array_key_exists($this->getAuthor(), self::$usersCaches)) {
         if (self::$usersCaches[$this->getAuthor()] != 'AJXP_USER_DONT_EXISTS') {
             $uLabel = self::$usersCaches[$this->getAuthor()];
         }
     } else {
         if (AuthService::userExists($this->getAuthor())) {
             $obj = ConfService::getConfStorageImpl()->createUserObject($this->getAuthor());
             $uLabel = $obj->personalRole->filterParameterValue("core.conf", "USER_DISPLAY_NAME", AJXP_REPO_SCOPE_ALL, "");
             self::$usersCaches[$this->getAuthor()] = $uLabel;
         } else {
             self::$usersCaches[$this->getAuthor()] = 'AJXP_USER_DONT_EXISTS';
         }
     }
     if (!empty($uLabel)) {
         return $uLabel;
     } else {
         return $this->getAuthor();
     }
 }
 public function upgradeDB()
 {
     $confDriver = ConfService::getConfStorageImpl();
     $authDriver = ConfService::getAuthDriverImpl();
     $logger = AJXP_Logger::getInstance();
     if (is_a($confDriver, "sqlConfDriver")) {
         $conf = AJXP_Utils::cleanDibiDriverParameters($confDriver->getOption("SQL_DRIVER"));
         if (!is_array($conf) || !isset($conf["driver"])) {
             return "Nothing to do";
         }
         switch ($conf["driver"]) {
             case "sqlite":
             case "sqlite3":
                 $ext = ".sqlite";
                 break;
             case "postgre":
                 $ext = ".pgsql";
                 break;
             case "mysql":
                 $ext = is_file($this->workingFolder . "/" . $this->dbUpgrade . ".mysql") ? ".mysql" : ".sql";
                 break;
             default:
                 return "ERROR!, DB driver " . $conf["driver"] . " not supported yet in __FUNCTION__";
         }
         $file = $this->dbUpgrade . $ext;
         if (!is_file($this->workingFolder . "/" . $file)) {
             return "Nothing to do.";
         }
         $sqlInstructions = file_get_contents($this->workingFolder . "/" . $file);
         $parts = array_map("trim", explode("/* SEPARATOR */", $sqlInstructions));
         $results = array();
         $errors = array();
         dibi::connect($conf);
         dibi::begin();
         foreach ($parts as $sqlPart) {
             if (empty($sqlPart)) {
                 continue;
             }
             try {
                 dibi::nativeQuery($sqlPart);
                 $results[] = $sqlPart;
             } catch (DibiException $e) {
                 $errors[] = $sqlPart . " (" . $e->getMessage() . ")";
             }
         }
         dibi::commit();
         dibi::disconnect();
         if (!count($errors)) {
             return "Database successfully upgraded";
         } else {
             return "Database upgrade failed. <br>The following statements were executed : <br>" . implode("<br>", $results) . ",<br><br> The following statements failed : <br>" . implode("<br>", $errors) . "<br><br> You should manually upgrade your DB.";
         }
     }
 }
Пример #26
0
 /**
  * @param ShareCenter $shareCenter
  * @param ShareStore $shareStore
  * @param ShareRightsManager $shareRightManager
  */
 public static function migrateLegacyMeta($shareCenter, $shareStore, $shareRightManager, $dryRun = true)
 {
     $metaStoreDir = AJXP_DATA_PATH . "/plugins/metastore.serial";
     $publicFolder = ConfService::getCoreConf("PUBLIC_DOWNLOAD_FOLDER");
     $metastores = glob($metaStoreDir . "/ajxp_meta_0");
     if ($dryRun) {
         print "RUNNING A DRY RUN FOR META MIGRATION";
     }
     foreach ($metastores as $store) {
         if (strpos($store, ".bak") !== false) {
             continue;
         }
         // Backup store
         if (!$dryRun) {
             copy($store, $store . ".bak");
         }
         $data = unserialize(file_get_contents($store));
         foreach ($data as $filePath => &$metadata) {
             foreach ($metadata as $userName => &$meta) {
                 if (!AuthService::userExists($userName)) {
                     continue;
                 }
                 $userObject = ConfService::getConfStorageImpl()->createUserObject($userName);
                 if (isset($meta["ajxp_shared"]) && isset($meta["ajxp_shared"]["element"])) {
                     print "\n\nItem {$filePath} requires upgrade :";
                     $share = $meta["ajxp_shared"];
                     $element = $meta["ajxp_shared"]["element"];
                     if (is_array($element)) {
                         $element = array_shift(array_keys($element));
                     }
                     // Take the first one only
                     $legacyLinkFile = $publicFolder . "/" . $element . ".php";
                     if (file_exists($legacyLinkFile)) {
                         // Load file, move it to DB and move the meta
                         $publiclet = $shareStore->loadShare($element);
                         rename($legacyLinkFile, $legacyLinkFile . ".migrated");
                         if (isset($share["minisite"])) {
                             print "\n--Migrate legacy minisite to new minisite?";
                             try {
                                 $sharedRepoId = $publiclet["REPOSITORY"];
                                 $sharedRepo = ConfService::getRepositoryById($sharedRepoId);
                                 if ($sharedRepo == null) {
                                     print "\n--ERROR: Cannot find repository with id " . $sharedRepoId;
                                     continue;
                                 }
                                 $shareLink = new ShareLink($shareStore, $publiclet);
                                 $user = $shareLink->getUniqueUser();
                                 if (AuthService::userExists($user)) {
                                     $userObject = ConfService::getConfStorageImpl()->createUserObject($user);
                                     $userObject->setHidden(true);
                                     print "\n--Should set existing user {$user} as hidden";
                                     if (!$dryRun) {
                                         $userObject->save();
                                     }
                                 }
                                 $shareLink->parseHttpVars(["custom_handle" => $element]);
                                 $shareLink->setParentRepositoryId($sharedRepo->getParentId());
                                 print "\n--Creating the following share object";
                                 print_r($shareLink->getJsonData($shareCenter->getPublicAccessManager(), ConfService::getMessages()));
                                 if (!$dryRun) {
                                     $shareLink->save();
                                 }
                                 $meta["ajxp_shared"] = ["shares" => [$element => ["type" => "minisite"], $sharedRepoId => ["type" => "repository"]]];
                             } catch (Exception $e) {
                                 print "\n-- Error " . $e->getMessage();
                             }
                         } else {
                             print "\n--Should migrate legacy link to new minisite with ContentFilter";
                             try {
                                 $link = new ShareLink($shareStore);
                                 $link->setOwnerId($userName);
                                 $parameters = array("custom_handle" => $element, "simple_right_download" => true);
                                 if (isset($publiclet["EXPIRE_TIME"])) {
                                     $parameters["expiration"] = $publiclet["EXPIRE_TIME"];
                                 }
                                 if (isset($publiclet["DOWNLOAD_LIMIT"])) {
                                     $parameters["downloadlimit"] = $publiclet["DOWNLOAD_LIMIT"];
                                 }
                                 $link->parseHttpVars($parameters);
                                 $parentRepositoryObject = $publiclet["REPOSITORY"];
                                 $driverInstance = AJXP_PluginsService::findPlugin("access", $parentRepositoryObject->getAccessType());
                                 if (empty($driverInstance)) {
                                     print "\n-- ERROR: Cannot find driver instance!";
                                     continue;
                                 }
                                 $options = $driverInstance->makeSharedRepositoryOptions(["file" => "/"], $parentRepositoryObject);
                                 $options["SHARE_ACCESS"] = "private";
                                 $newRepo = $parentRepositoryObject->createSharedChild(basename($filePath), $options, $parentRepositoryObject->getId(), $userObject->getId(), null);
                                 $gPath = $userObject->getGroupPath();
                                 if (!empty($gPath) && !ConfService::getCoreConf("CROSSUSERS_ALLGROUPS", "conf")) {
                                     $newRepo->setGroupPath($gPath);
                                 }
                                 $newRepo->setDescription("");
                                 // Smells like dirty hack!
                                 $newRepo->options["PATH"] = SystemTextEncoding::fromStorageEncoding($newRepo->options["PATH"]);
                                 $newRepo->setContentFilter(new ContentFilter([new AJXP_Node("pydio://" . $parentRepositoryObject->getId() . $filePath)]));
                                 if (!$dryRun) {
                                     ConfService::addRepository($newRepo);
                                 }
                                 $hiddenUserEntry = $shareRightManager->prepareSharedUserEntry(["simple_right_read" => true, "simple_right_download" => true], $link, false, null);
                                 $selection = new UserSelection($parentRepositoryObject, []);
                                 $selection->addFile($filePath);
                                 if (!$dryRun) {
                                     $shareRightManager->assignSharedRepositoryPermissions($parentRepositoryObject, $newRepo, false, [$hiddenUserEntry["ID"] => $hiddenUserEntry], [], $selection);
                                 }
                                 $link->setParentRepositoryId($parentRepositoryObject->getId());
                                 $link->attachToRepository($newRepo->getId());
                                 print "\n-- Should save following LINK: ";
                                 print_r($link->getJsonData($shareCenter->getPublicAccessManager(), ConfService::getMessages()));
                                 if (!$dryRun) {
                                     $hash = $link->save();
                                 }
                                 // UPDATE METADATA
                                 $meta["ajxp_shared"] = ["shares" => [$element => array("type" => "minisite")]];
                             } catch (Exception $e) {
                                 print "\n-- ERROR: " . $e->getMessage();
                             }
                         }
                         if ($dryRun) {
                             rename($legacyLinkFile . ".migrated", $legacyLinkFile);
                         }
                         continue;
                     } else {
                         //
                         // File does not exists, remove meta
                         //
                         unset($meta["ajxp_shared"]);
                     }
                     $repo = ConfService::getRepositoryById($element);
                     if ($repo !== null) {
                         print "\n--Shared repository: just metadata";
                         // Shared repo, migrating the meta should be enough
                         $meta["ajxp_shared"] = array("shares" => [$element => array("type" => "repository")]);
                     }
                 }
             }
         }
         print "\n\n SHOULD NOW UPDATE METADATA WITH FOLLOWING :";
         print_r($data);
         if (!$dryRun) {
             file_put_contents($store, serialize($data));
         }
     }
 }
 /**
  * @param Repository $repository
  * @param null $resolveUserId
  * @return String
  */
 protected function computeIdentifier($repository, $resolveUserId = null)
 {
     $parts = array($repository->getId());
     if ($repository->securityScope() == 'USER') {
         if ($resolveUserId != null) {
             $parts[] = $resolveUserId;
         } else {
             $parts[] = AuthService::getLoggedUser()->getId();
         }
     } else {
         if ($repository->securityScope() == 'GROUP') {
             if ($resolveUserId != null) {
                 $userObject = ConfService::getConfStorageImpl()->createUserObject($resolveUserId);
                 if ($userObject != null) {
                     $parts[] = $userObject->getGroupPath();
                 }
             } else {
                 $parts[] = AuthService::getLoggedUser()->getGroupPath();
             }
         }
     }
     return implode("-", $parts);
 }
 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;
 }
Пример #29
0
 /**
  * @param string $repositoryId
  * @return AbstractAjxpUser[]
  */
 public function getUsersForRepository($repositoryId)
 {
     $result = array();
     $authDriver = ConfService::getAuthDriverImpl();
     $confDriver = ConfService::getConfStorageImpl();
     $users = $authDriver->listUsers(AuthService::filterBaseGroup("/"));
     foreach (array_keys($users) as $id) {
         $object = $confDriver->createUserObject($id);
         if ($object->canSwitchTo($repositoryId)) {
             $result[$id] = $object;
         }
     }
     return $result;
 }
 function switchAction($action, $httpVars, $fileVars)
 {
     if (!isset($this->actions[$action])) {
         return;
     }
     parent::accessPreprocess($action, $httpVars, $fileVars);
     $loggedUser = AuthService::getLoggedUser();
     if (!ENABLE_USERS) {
         return;
     }
     if ($action == "edit") {
         if (isset($httpVars["sub_action"])) {
             $action = $httpVars["sub_action"];
         }
     }
     $mess = ConfService::getMessages();
     switch ($action) {
         //------------------------------------
         //	BASIC LISTING
         //------------------------------------
         case "ls":
             $rootNodes = array("files" => array("LABEL" => $mess["ajxp_shared.3"], "ICON" => "html.png", "DESCRIPTION" => $mess["ajxp_shared.28"]), "repositories" => array("LABEL" => $mess["ajxp_shared.2"], "ICON" => "document_open_remote.png", "DESCRIPTION" => $mess["ajxp_shared.29"]), "users" => array("LABEL" => $mess["ajxp_shared.1"], "ICON" => "user_shared.png", "DESCRIPTION" => $mess["ajxp_shared.30"]));
             $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 == "files") {
                             $this->listSharedFiles();
                         }
                     }
                 }
                 AJXP_XMLWriter::close();
                 exit(1);
             } else {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendFilesListComponentConfig('<columns switchGridMode="filelist"><column messageId="ajxp_shared.8" attributeName="ajxp_label" sortType="String"/><column messageId="ajxp_shared.31" attributeName="description" sortType="String"/></columns>');
                 foreach ($rootNodes as $key => $data) {
                     print '<tree text="' . $data["LABEL"] . '" icon="' . $data["ICON"] . '" filename="/' . $key . '" parentname="/" description="' . $data["DESCRIPTION"] . '" />';
                 }
                 AJXP_XMLWriter::close();
             }
             break;
         case "stat":
             header("Content-type:application/json");
             print '{"mode":true}';
             break;
         case "delete":
             $mime = $httpVars["ajxp_mime"];
             $selection = new UserSelection();
             $selection->initFromHttpVars();
             $files = $selection->getFiles();
             AJXP_XMLWriter::header();
             foreach ($files as $index => $element) {
                 $element = basename($element);
                 if ($mime == "shared_repository") {
                     $repo = ConfService::getRepositoryById($element);
                     if (!$repo->hasOwner() || $repo->getOwner() != $loggedUser->getId()) {
                         AJXP_XMLWriter::sendMessage(null, $mess["ajxp_shared.12"]);
                         break;
                     } else {
                         $res = ConfService::deleteRepository($element);
                         if ($res == -1) {
                             AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.51"]);
                             break;
                         } else {
                             if ($index == count($files) - 1) {
                                 AJXP_XMLWriter::sendMessage($mess["ajxp_conf.59"], null);
                                 AJXP_XMLWriter::reloadDataNode();
                             }
                         }
                     }
                 } else {
                     if ($mime == "shared_user") {
                         $confDriver = ConfService::getConfStorageImpl();
                         $object = $confDriver->createUserObject($element);
                         if (!$object->hasParent() || $object->getParent() != $loggedUser->getId()) {
                             AJXP_XMLWriter::sendMessage(null, $mess["ajxp_shared.12"]);
                             break;
                         } else {
                             $res = AuthService::deleteUser($element);
                             if ($index == count($files) - 1) {
                                 AJXP_XMLWriter::sendMessage($mess["ajxp_conf.60"], null);
                                 AJXP_XMLWriter::reloadDataNode();
                             }
                         }
                     } else {
                         if ($mime == "shared_file") {
                             $publicletData = $this->loadPublicletData(PUBLIC_DOWNLOAD_FOLDER . "/" . $element . ".php");
                             if (isset($publicletData["OWNER_ID"]) && $publicletData["OWNER_ID"] == $loggedUser->getId()) {
                                 require_once INSTALL_PATH . "/server/classes/class.PublicletCounter.php";
                                 PublicletCounter::delete($element);
                                 unlink(PUBLIC_DOWNLOAD_FOLDER . "/" . $element . ".php");
                                 if ($index == count($files) - 1) {
                                     AJXP_XMLWriter::sendMessage($mess["ajxp_shared.13"], null);
                                     AJXP_XMLWriter::reloadDataNode();
                                 }
                             } else {
                                 AJXP_XMLWriter::sendMessage(null, $mess["ajxp_shared.12"]);
                                 break;
                             }
                         }
                     }
                 }
             }
             AJXP_XMLWriter::close();
             break;
         case "clear_expired":
             $deleted = $this->clearExpiredFiles();
             AJXP_XMLWriter::header();
             if (count($deleted)) {
                 AJXP_XMLWriter::sendMessage(sprintf($mess["ajxp_shared.23"], count($deleted) . ""), null);
                 AJXP_XMLWriter::reloadDataNode();
             } else {
                 AJXP_XMLWriter::sendMessage($mess["ajxp_shared.24"], null);
             }
             AJXP_XMLWriter::close();
             break;
         case "reset_download_counter":
             $selection = new UserSelection();
             $selection->initFromHttpVars();
             $elements = $selection->getFiles();
             require_once INSTALL_PATH . "/server/classes/class.PublicletCounter.php";
             foreach ($elements as $element) {
                 PublicletCounter::reset(str_replace(".php", "", basename($element)));
             }
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::reloadDataNode();
             AJXP_XMLWriter::close();
             break;
         default:
             break;
     }
     return;
 }