Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Add a $useSession parameter to ConfService and use in rest.php
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Jul 18, 2015
1 parent 036dde4 commit b24738c
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 34 deletions.
4 changes: 2 additions & 2 deletions core/src/core/classes/class.AuthService.php
Expand Up @@ -375,8 +375,8 @@ public static function logUser($user_id, $pwd, $bypass_pwd = false, $cookieLogin
else self::$currentUser = $user;

if ($user->isAdmin()) {
$user = self::updateAdminRights($user);
self::updateUser($user);
//$user = self::updateAdminRights($user);
//self::updateUser($user);
}

if ($authDriver->autoCreateUser() && !$user->storageExists()) {
Expand Down
86 changes: 65 additions & 21 deletions core/src/core/classes/class.ConfService.php
Expand Up @@ -28,9 +28,14 @@
class ConfService
{
private static $instance;
public static $useSession = true;

private $errors = array();
private $configs = array();

private $contextRepositoryId;
private $contextCharset;

/**
* @param AJXP_PluginsService $ajxpPluginService
* @return AbstractConfDriver
Expand Down Expand Up @@ -121,6 +126,35 @@ public static function getErrors()
return self::getInstance()->errors;
}

public static function getContextCharset(){
if(self::$useSession) {
if(isSet($_SESSION["AJXP_CHARSET"])) return $_SESSION["AJXP_CHARSET"];
else return null;
}else {
return self::getInstance()->contextCharset;
}
}

public static function setContextCharset($value){
if(self::$useSession){
$_SESSION["AJXP_CHARSET"] = $value;
}else{
self::getInstance()->contextCharset = $value;
}
}

public static function clearContextCharset(){
if(self::$useSession && isSet($_SESSION["AJXP_CHARSET"])){
unset($_SESSION["AJXP_CHARSET"]);
}else{
self::getInstance()->contextCharset = null;
}
}

private function getContextRepositoryId(){
return self::$useSession ? $_SESSION["REPO_ID"] : $this->contextRepositoryId;
}

/**
* @static
* @param $globalsArray
Expand Down Expand Up @@ -289,8 +323,8 @@ public function switchRootDirInst($rootDirIndex=-1, $temporary=false)
{
if ($rootDirIndex == -1) {
$ok = false;
if (isSet($_SESSION['REPO_ID'])) {
$sessionId = $_SESSION['REPO_ID'];
if (isSet($_SESSION['REPO_ID']) || $this->contextRepositoryId != null) {
$sessionId = self::$useSession ? $_SESSION['REPO_ID'] : $this->contextRepositoryId;
$object = self::getRepositoryById($sessionId);
if($object != null && self::repositoryIsAccessible($sessionId, $object)){
$this->configs["REPOSITORY"] = $object;
Expand All @@ -301,22 +335,26 @@ public function switchRootDirInst($rootDirIndex=-1, $temporary=false)
$currentRepos = $this->getLoadedRepositories();
$keys = array_keys($currentRepos);
$this->configs["REPOSITORY"] = $currentRepos[$keys[0]];
$_SESSION['REPO_ID'] = $keys[0];
if(self::$useSession){
$_SESSION['REPO_ID'] = $keys[0];
}else{
$this->contextRepositoryId = $keys[0];
}
}
} else {
/*
if (isSet($this->configs["REPOSITORY"]) && $this->configs["REPOSITORY"] == $rootDirIndex) {
return;
}
*/
if ($temporary && isSet($_SESSION['REPO_ID'])) {
$crtId = $_SESSION['REPO_ID'];
if ($temporary && (isSet($_SESSION['REPO_ID']) || $this->contextRepositoryId != null)) {
$crtId = self::$useSession ? $_SESSION['REPO_ID'] : $this->contextRepositoryId;
if ($crtId != $rootDirIndex && !isSet($_SESSION['SWITCH_BACK_REPO_ID'])) {
$_SESSION['SWITCH_BACK_REPO_ID'] = $crtId;
//AJXP_Logger::debug("switching to $rootDirIndex, registering $crtId");
}
} else {
$crtId = $_SESSION['REPO_ID'];
$crtId = self::$useSession ? $_SESSION['REPO_ID'] : $this->contextRepositoryId;
$_SESSION['PREVIOUS_REPO_ID'] = $crtId;
//AJXP_Logger::debug("switching back to $rootDirIndex");
}
Expand All @@ -325,16 +363,18 @@ public function switchRootDirInst($rootDirIndex=-1, $temporary=false)
} else {
$this->configs["REPOSITORY"] = ConfService::getRepositoryById($rootDirIndex);
}
$_SESSION['REPO_ID'] = $rootDirIndex;
if(self::$useSession){
$_SESSION['REPO_ID'] = $rootDirIndex;
}else{
$this->contextRepositoryId = $rootDirIndex;
}
if(isSet($this->configs["ACCESS_DRIVER"])) unset($this->configs["ACCESS_DRIVER"]);
}

if (isSet($this->configs["REPOSITORY"]) && $this->configs["REPOSITORY"]->getOption("CHARSET")!="") {
$_SESSION["AJXP_CHARSET"] = $this->configs["REPOSITORY"]->getOption("CHARSET");
self::setContextCharset($this->configs["REPOSITORY"]->getOption("CHARSET"));
} else {
if (isSet($_SESSION["AJXP_CHARSET"])) {
unset($_SESSION["AJXP_CHARSET"]);
}
self::clearContextCharset();
}


Expand Down Expand Up @@ -518,10 +558,11 @@ public static function getCurrentRepositoryId()
*/
public function getCurrentRepositoryIdInst()
{
if(isSet($_SESSION['REPO_ID'])){
$object = self::getRepositoryById($_SESSION['REPO_ID']);
if($object != null && self::repositoryIsAccessible($_SESSION['REPO_ID'], $object)){
return $_SESSION['REPO_ID'];
$ctxId = $this->getContextRepositoryId();
if(!empty($ctxId)){
$object = self::getRepositoryById($ctxId);
if($object != null && self::repositoryIsAccessible($ctxId, $object)){
return $ctxId;
}
}
$currentRepos = $this->getLoadedRepositories();
Expand All @@ -542,8 +583,9 @@ public static function getCurrentRootDirDisplay()
public function getCurrentRootDirDisplayInst()
{
$currentRepos = $this->getLoadedRepositories();
if (isSet($currentRepos[$_SESSION['REPO_ID']])) {
$repo = $currentRepos[$_SESSION['REPO_ID']];
$ctxId = $this->getContextRepositoryId();
if (isSet($currentRepos[$ctxId])) {
$repo = $currentRepos[$ctxId];
return $repo->getDisplay();
}
return "";
Expand Down Expand Up @@ -1266,8 +1308,9 @@ public static function getRepository()
*/
public function getRepositoryInst()
{
if (isSet($_SESSION['REPO_ID']) && isSet($this->configs["REPOSITORIES"]) && isSet($this->configs["REPOSITORIES"][$_SESSION['REPO_ID']])) {
return $this->configs["REPOSITORIES"][$_SESSION['REPO_ID']];
$ctxId = $this->getContextRepositoryId();
if (!empty($ctxId) && isSet($this->configs["REPOSITORIES"]) && isSet($this->configs["REPOSITORIES"][$ctxId])) {
return $this->configs["REPOSITORIES"][$ctxId];
}
return $this->configs["REPOSITORY"];
}
Expand Down Expand Up @@ -1467,9 +1510,10 @@ public function loadRepositoryDriverREST(&$repository)
}

$repository->driverInstance = $plugInstance;
if (isSet($_SESSION["REPO_ID"]) && $_SESSION["REPO_ID"] == $repository->getId()) {
$ctxId = $this->getContextRepositoryId();
if (!empty($ctxId) && $ctxId == $repository->getId()) {
$this->configs["REPOSITORY"] = $repository;
$this->cacheRepository($_SESSION['REPO_ID'], $repository);
$this->cacheRepository($ctxId, $repository);
}
return $plugInstance;
}
Expand Down
10 changes: 5 additions & 5 deletions core/src/core/classes/class.SystemTextEncoding.php
Expand Up @@ -78,12 +78,12 @@ public static function parseCharset($locale)
public static function getEncoding()
{
if (self::$currentCharsetValue == null) {
global $_SESSION;
if (isset($_SESSION["AJXP_CHARSET"]) && strlen($_SESSION["AJXP_CHARSET"])) {
// Check if the session get an assigned charset encoding (it's the case for remote SSH for example)
self::$currentCharsetValue = $_SESSION["AJXP_CHARSET"];
$charset = ConfService::getContextCharset();
if (!empty($charset)) {
// Check if the session get an assigned charset encoding (it's the case for remote SSH for example)
self::$currentCharsetValue = $charset;
} else {
// Get the current locale (expecting the filesystem is in the same locale, as the standard says)
// Get the current locale (expecting the filesystem is in the same locale, as the standard says)
self::$currentCharsetValue = self::parseCharset(setlocale(LC_CTYPE, 0));
}
}
Expand Down
9 changes: 7 additions & 2 deletions core/src/plugins/access.ftp/class.ftpAccessWrapper.php
Expand Up @@ -440,8 +440,13 @@ protected function parseUrl($url, $forceLogin = false)
$cacheKey = $repository->getId()."_ftpCharset";
if (!isset($_SESSION[$cacheKey]) || !strlen($_SESSION[$cacheKey]) || $forceLogin) {
$features = $this->getServerFeatures();
if(!isSet($_SESSION["AJXP_CHARSET"]) || $_SESSION["AJXP_CHARSET"] == "") $_SESSION["AJXP_CHARSET"] = $features["charset"];
$_SESSION[$cacheKey] = $_SESSION["AJXP_CHARSET"];
$ctxCharset = ConfService::getContextCharset();
if(empty($ctxCharset)) {
ConfService::setContextCharset($features["charset"]);
$_SESSION[$cacheKey] = $features["charset"];
}else{
$_SESSION[$cacheKey] = $ctxCharset;
}
}
return $urlParts;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/gui.ajax/class.AJXP_ClientDriver.php
Expand Up @@ -233,7 +233,7 @@ public function switchAction($action, $httpVars, $fileVars)
}
if (preg_match('/MSIE 7/',$_SERVER['HTTP_USER_AGENT']) || preg_match('/MSIE 8/',$_SERVER['HTTP_USER_AGENT'])) {
// TODO: OFFICIALLY DROP IE7 SUPPORT?
//$content = str_replace("ajaxplorer_boot.js", "ajaxplorer_boot_protolegacy.js", $content);
// $content = str_replace("ajaxplorer_boot.js", "ajaxplorer_boot_protolegacy.js", $content);
}
$content = str_replace("AJXP_ADDITIONAL_JS_FRAMEWORKS", $ADDITIONAL_FRAMEWORKS, $content);
$content = AJXP_XMLWriter::replaceAjxpXmlKeywords($content, false);
Expand Down
9 changes: 6 additions & 3 deletions core/src/rest.php
Expand Up @@ -26,15 +26,18 @@
set_exception_handler(array("AJXP_XMLWriter", "catchException"));

$pServ = AJXP_PluginsService::getInstance();
ConfService::$useSession = false;
AuthService::$useSession = false;

ConfService::init();
$confPlugin = ConfService::getInstance()->confPluginSoftLoad($pServ);
$pServ->loadPluginsRegistry(AJXP_INSTALL_PATH."/plugins", $confPlugin);
ConfService::start();
$confStorageDriver = ConfService::getConfStorageImpl();
require_once($confStorageDriver->getUserClassFileName());
session_name("AjaXplorer");
session_start();
AuthService::$useSession = false;
//session_name("AjaXplorer");
//session_start();


AJXP_PluginsService::getInstance()->initActivePlugins();
AuthService::preLogUser(array_merge($_GET, $_POST));
Expand Down

0 comments on commit b24738c

Please sign in to comment.