From ef96489cdf2f6e6be12b172b3ac8d4fa51c46e37 Mon Sep 17 00:00:00 2001 From: nuxsmin Date: Fri, 16 Feb 2018 13:56:17 +0100 Subject: [PATCH] * [MOD] Improved bootstrapping. Work in progress. --- lib/Base.php | 2 ++ lib/SP/Bootstrap.php | 5 ++++- lib/SP/Core/Session/Session.php | 34 +++++++++++++++++++++++++++++---- lib/SP/Core/SessionUtil.php | 1 + 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/lib/Base.php b/lib/Base.php index 961f84e3..9892e00d 100644 --- a/lib/Base.php +++ b/lib/Base.php @@ -54,6 +54,8 @@ define('VENDOR_PATH', APP_ROOT . DIRECTORY_SEPARATOR . 'vendor'); define('SQL_PATH', APP_ROOT . DIRECTORY_SEPARATOR . 'schemas'); define('PUBLIC_PATH', APP_ROOT . DIRECTORY_SEPARATOR . 'public'); +define('APP_PARTIAL_INIT', ['resource', 'install', 'bootstrap']); + define('DEBUG', true); // Empezar a calcular la memoria utilizada diff --git a/lib/SP/Bootstrap.php b/lib/SP/Bootstrap.php index 2a66c5b6..af5ebb2e 100644 --- a/lib/SP/Bootstrap.php +++ b/lib/SP/Bootstrap.php @@ -216,8 +216,11 @@ class Bootstrap $self->initializeCommon(); - if (in_array($controller, self::PARTIAL_INIT, true)) { + if (!in_array($controller, APP_PARTIAL_INIT, true)) { $self->initializeApp(); + } else { + // Do not keep the PHP's session opened + Session::close(); } debugLog('Routing call: ' . $controllerClass . '::' . $method . '::' . print_r($params, true)); diff --git a/lib/SP/Core/Session/Session.php b/lib/SP/Core/Session/Session.php index 1d013155..25ffa99e 100644 --- a/lib/SP/Core/Session/Session.php +++ b/lib/SP/Core/Session/Session.php @@ -37,6 +37,16 @@ use SP\Services\User\UserLoginResponse; */ class Session { + private static $isLocked = false; + + /** + * @return bool + */ + public static function isLocked() + { + return self::$isLocked; + } + /** * Devuelve el tema visual utilizado en sysPass * @@ -51,7 +61,7 @@ class Session * Devolver una variable de sesión * * @param string $key - * @param mixed $default + * @param mixed $default * @return mixed */ protected function getSessionKey($key, $default = null) @@ -76,17 +86,33 @@ class Session /** * Establecer una variable de sesión * - * @param string $key El nombre de la variable - * @param mixed $value El valor de la variable + * @param string $key El nombre de la variable + * @param mixed $value El valor de la variable * @return mixed */ protected function setSessionKey($key, $value) { - $_SESSION[$key] = $value; + if (self::$isLocked ) { + debugLog('Session locked; key=' . $key); + } else { + $_SESSION[$key] = $value; + } return $value; } + /** + * Closes session + */ + public static function close() + { + debugLog('Session closed'); + + session_write_close(); + + self::$isLocked = true; + } + /** * Establecer la configuración * diff --git a/lib/SP/Core/SessionUtil.php b/lib/SP/Core/SessionUtil.php index cca7e523..61f2447b 100644 --- a/lib/SP/Core/SessionUtil.php +++ b/lib/SP/Core/SessionUtil.php @@ -84,6 +84,7 @@ class SessionUtil * @param bool $new si es necesrio regenerar el hash * @param ConfigData|null $configData * @return string con el hash de verificación + * @deprecated */ public static function getSessionKey($new = false, ConfigData $configData = null) {