/**
  * 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 $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) {
                 $value = str_replace("AJXP_USER", $resolveUser->getId(), $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) {
                 $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;
 }
 /**
  * @param AbstractAjxpUser $userObject
  * @return array()
  */
 public function getExposedPreferences($userObject)
 {
     $stringPrefs = array("lang", "history/last_repository", "pending_folder", "plugins_preferences");
     $jsonPrefs = array("ls_history", "gui_preferences");
     $prefs = array();
     if ($userObject->getId() == "guest" && ConfService::getCoreConf("SAVE_GUEST_PREFERENCES", "conf") === false) {
         return array();
     }
     if (ConfService::getCoreConf("SKIP_USER_HISTORY", "conf") === true) {
         $stringPrefs = array("lang", "pending_folder", "plugins_preferences");
         $jsonPrefs = array("gui_preferences");
         $prefs["SKIP_USER_HISTORY"] = array("value" => "true", "type" => "string");
     }
     foreach ($stringPrefs as $pref) {
         if (strstr($pref, "/") !== false) {
             $parts = explode("/", $pref);
             $value = $userObject->getArrayPref($parts[0], $parts[1]);
             $pref = str_replace("/", "_", $pref);
         } else {
             $value = $userObject->getPref($pref);
         }
         $prefs[$pref] = array("value" => $value, "type" => "string");
     }
     foreach ($jsonPrefs as $pref) {
         $prefs[$pref] = array("value" => $userObject->getPref($pref), "type" => "json");
     }
     $paramNodes = AJXP_PluginsService::searchAllManifests("//server_settings/param[contains(@scope,'user') and @expose='true']", "node", false, false, true);
     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");
                 $value = $userObject->mergedRole->filterParameterValue($pluginId, $name, AJXP_REPO_SCOPE_ALL, "");
                 $prefs[$name] = array("value" => $value, "type" => "string", "pluginId" => $pluginId);
             }
         }
     }
     return $prefs;
 }
示例#3
0
 /**
  * @param Repository $repository
  * @param AbstractAjxpUser $user
  * @return Array
  */
 protected function buildIndexLockKey($repository, $user)
 {
     $scope = $repository->securityScope();
     $key = $repository->getId();
     if ($scope == "USER") {
         $key .= "-" . $user->getId();
     } else {
         if ($scope == "GROUP") {
             $key .= "-" . ltrim(str_replace("/", "__", $user->getGroupPath()), "__");
         }
     }
     return $key;
 }
 /**
  * @param AbstractAjxpUser $userObject
  * @return array()
  */
 public function getExposedPreferences($userObject)
 {
     $stringPrefs = array("lang", "history/last_repository", "pending_folder", "plugins_preferences");
     $jsonPrefs = array("ls_history", "gui_preferences");
     $prefs = array();
     if ($userObject->getId() == "guest" && ConfService::getCoreConf("SAVE_GUEST_PREFERENCES", "conf") === false) {
         return array();
     }
     if (ConfService::getCoreConf("SKIP_USER_HISTORY", "conf") === true) {
         $stringPrefs = array("lang", "pending_folder", "plugins_preferences");
         $jsonPrefs = array("gui_preferences");
         $prefs["SKIP_USER_HISTORY"] = array("value" => "true", "type" => "string");
     }
     foreach ($stringPrefs as $pref) {
         if (strstr($pref, "/") !== false) {
             $parts = explode("/", $pref);
             $value = $userObject->getArrayPref($parts[0], $parts[1]);
             $pref = str_replace("/", "_", $pref);
         } else {
             $value = $userObject->getPref($pref);
         }
         $prefs[$pref] = array("value" => $value, "type" => "string");
     }
     foreach ($jsonPrefs as $pref) {
         $prefs[$pref] = array("value" => $userObject->getPref($pref), "type" => "json");
     }
     $exposed = array();
     $cacheHasExposed = AJXP_PluginsService::getInstance()->loadFromPluginQueriesCache("//server_settings/param[contains(@scope,'user') and @expose='true']");
     if ($cacheHasExposed !== null && is_array($cacheHasExposed)) {
         $exposed = $cacheHasExposed;
     } else {
         $exposed_props = AJXP_PluginsService::searchAllManifests("//server_settings/param[contains(@scope,'user') and @expose='true']", "node", false, false, true);
         foreach ($exposed_props as $exposed_prop) {
             $parentNode = $exposed_prop->parentNode->parentNode;
             $pluginId = $parentNode->getAttribute("id");
             if (empty($pluginId)) {
                 $pluginId = $parentNode->nodeName . "." . $parentNode->getAttribute("name");
             }
             $paramName = $exposed_prop->getAttribute("name");
             $exposed[] = array("PLUGIN_ID" => $pluginId, "NAME" => $paramName);
         }
         AJXP_PluginsService::getInstance()->storeToPluginQueriesCache("//server_settings/param[contains(@scope,'user') and @expose='true']", $exposed);
     }
     foreach ($exposed as $exposedProp) {
         $value = $userObject->mergedRole->filterParameterValue($exposedProp["PLUGIN_ID"], $exposedProp["NAME"], AJXP_REPO_SCOPE_ALL, "");
         $prefs[$exposedProp["NAME"]] = array("value" => $value, "type" => "string", "pluginId" => $exposedProp["PLUGIN_ID"]);
     }
     return $prefs;
 }
示例#5
0
 /**
  * @static
  * @param String $type
  * @param String $element
  * @param AbstractAjxpUser $loggedUser
  * @throws Exception
  */
 public static function deleteSharedElement($type, $element, $loggedUser)
 {
     $mess = ConfService::getMessages();
     AJXP_Logger::debug($type . "-" . $element);
     if ($type == "repository") {
         $repo = ConfService::getRepositoryById($element);
         if ($repo == null) {
             return;
         }
         if (!$repo->hasOwner() || $repo->getOwner() != $loggedUser->getId()) {
             throw new Exception($mess["ajxp_shared.12"]);
         } else {
             $res = ConfService::deleteRepository($element);
             if ($res == -1) {
                 throw new Exception($mess["ajxp_conf.51"]);
             }
         }
     } else {
         if ($type == "minisite") {
             $minisiteData = self::loadPublicletData($element);
             $repoId = $minisiteData["REPOSITORY"];
             $repo = ConfService::getRepositoryById($repoId);
             if ($repo == null) {
                 return false;
             }
             if (!$repo->hasOwner() || $repo->getOwner() != $loggedUser->getId()) {
                 throw new Exception($mess["ajxp_shared.12"]);
             } else {
                 $res = ConfService::deleteRepository($repoId);
                 if ($res == -1) {
                     throw new Exception($mess["ajxp_conf.51"]);
                 }
                 // Silently delete corresponding role if it exists
                 AuthService::deleteRole("AJXP_SHARED-" . $repoId);
                 // If guest user created, remove it now.
                 if (isset($minisiteData["PRELOG_USER"])) {
                     AuthService::deleteUser($minisiteData["PRELOG_USER"]);
                 }
                 unlink($minisiteData["PUBLICLET_PATH"]);
             }
         } else {
             if ($type == "user") {
                 $confDriver = ConfService::getConfStorageImpl();
                 $object = $confDriver->createUserObject($element);
                 if (!$object->hasParent() || $object->getParent() != $loggedUser->getId()) {
                     throw new Exception($mess["ajxp_shared.12"]);
                 } else {
                     AuthService::deleteUser($element);
                 }
             } else {
                 if ($type == "file") {
                     $publicletData = self::loadPublicletData($element);
                     if (isset($publicletData["OWNER_ID"]) && $publicletData["OWNER_ID"] == $loggedUser->getId()) {
                         PublicletCounter::delete($element);
                         unlink($publicletData["PUBLICLET_PATH"]);
                     } else {
                         throw new Exception($mess["ajxp_shared.12"]);
                     }
                 }
             }
         }
     }
 }
 /**
  * @param AbstractAjxpUser $userObject
  * @return array()
  */
 function getExposedPreferences($userObject)
 {
     $stringPrefs = array("display", "lang", "diapo_autofit", "sidebar_splitter_size", "vertical_splitter_size", "history/last_repository", "pending_folder", "thumb_size", "plugins_preferences", "upload_auto_send", "upload_auto_close", "upload_existing", "action_bar_style", "force_default_repository");
     $jsonPrefs = array("ls_history", "columns_size", "columns_visibility", "gui_preferences");
     $prefs = array();
     if ($userObject->getId() == "guest" && ConfService::getCoreConf("SAVE_GUEST_PREFERENCES", "conf") === false) {
         return array();
     }
     if (ConfService::getCoreConf("SKIP_USER_HISTORY", "conf") === true) {
         $stringPrefs = array_diff($stringPrefs, array("history/last_repository"));
         $jsonPrefs = array("columns_size", "columns_visibility", "gui_preferences");
     }
     foreach ($stringPrefs as $pref) {
         if (strstr($pref, "/") !== false) {
             $parts = explode("/", $pref);
             $value = $userObject->getArrayPref($parts[0], $parts[1]);
             $pref = str_replace("/", "_", $pref);
         } else {
             $value = $userObject->getPref($pref);
         }
         $prefs[$pref] = array("value" => $value, "type" => "string");
     }
     foreach ($jsonPrefs as $pref) {
         $prefs[$pref] = array("value" => $userObject->getPref($pref), "type" => "json");
     }
     return $prefs;
 }
示例#7
0
 public function abstractUserToAdress(AbstractAjxpUser $user)
 {
     // SHOULD CHECK THAT THIS USER IS "AUTHORIZED" TO AVOID SPAM
     $userEmail = $user->personalRole->filterParameterValue("core.conf", "email", AJXP_REPO_SCOPE_ALL, "");
     if (empty($userEmail)) {
         return false;
     }
     $displayName = $user->personalRole->filterParameterValue("core.conf", "USER_DISPLAY_NAME", AJXP_REPO_SCOPE_ALL, "");
     if (empty($displayName)) {
         $displayName = $user->getId();
     }
     return array("name" => $displayName, "adress" => $userEmail);
 }
 /**
  * @static
  * @param String $type
  * @param String $element
  * @param AbstractAjxpUser $loggedUser
  * @return void
  */
 public static function deleteSharedElement($type, $element, $loggedUser)
 {
     $mess = ConfService::getMessages();
     if ($type == "repository") {
         $repo = ConfService::getRepositoryById($element);
         if (!$repo->hasOwner() || $repo->getOwner() != $loggedUser->getId()) {
             throw new Exception($mess["ajxp_shared.12"]);
         } else {
             $res = ConfService::deleteRepository($element);
             if ($res == -1) {
                 throw new Exception($mess["ajxp_conf.51"]);
             }
         }
     } else {
         if ($type == "user") {
             $confDriver = ConfService::getConfStorageImpl();
             $object = $confDriver->createUserObject($element);
             if (!$object->hasParent() || $object->getParent() != $loggedUser->getId()) {
                 throw new Exception($mess["ajxp_shared.12"]);
             } else {
                 AuthService::deleteUser($element);
             }
         } else {
             if ($type == "file") {
                 $publicletData = self::loadPublicletData($element);
                 if (isset($publicletData["OWNER_ID"]) && $publicletData["OWNER_ID"] == $loggedUser->getId()) {
                     PublicletCounter::delete($element);
                     unlink($publicletData["PUBLICLET_PATH"]);
                 } else {
                     throw new Exception($mess["ajxp_shared.12"]);
                 }
             }
         }
     }
 }
 /**
  * @param AbstractAjxpUser $parentUser
  * @param string $userName
  * @param string $password
  * @param bool $isHidden
  * @param string $display
  * @return AbstractAjxpUser
  * @throws Exception
  */
 public function createNewUser($parentUser, $userName, $password, $isHidden, $display)
 {
     $confDriver = ConfService::getConfStorageImpl();
     if (ConfService::getAuthDriverImpl()->getOptionAsBool("TRANSMIT_CLEAR_PASS")) {
         $pass = $password;
     } else {
         $pass = md5($password);
     }
     if (!$isHidden) {
         // This is an explicit user creation - check possible limits
         AJXP_Controller::applyHook("user.before_create", array($userName, null, false, false));
         $limit = $parentUser->mergedRole->filterParameterValue("core.conf", "USER_SHARED_USERS_LIMIT", AJXP_REPO_SCOPE_ALL, "");
         if (!empty($limit) && intval($limit) > 0) {
             $count = count($confDriver->getUserChildren($parentUser->getId()));
             if ($count >= $limit) {
                 $mess = ConfService::getMessages();
                 throw new Exception($mess['483']);
             }
         }
     }
     AuthService::createUser($userName, $pass, false, $isHidden);
     $userObject = $confDriver->createUserObject($userName);
     $userObject->personalRole->clearAcls();
     $userObject->setParent($parentUser->getId());
     $userObject->setGroupPath($parentUser->getGroupPath());
     $userObject->setProfile("shared");
     if ($isHidden) {
         $userObject->setHidden(true);
         $userObject->personalRole->setParameterValue("core.conf", "USER_DISPLAY_NAME", $display);
     }
     AJXP_Controller::applyHook("user.after_create", array($userObject));
     return $userObject;
 }