Skip to content

Commit

Permalink
N°3985 - Performance checks on the back end
Browse files Browse the repository at this point in the history
  • Loading branch information
eespie committed Aug 23, 2021
1 parent ffbd94d commit 2c2155a
Show file tree
Hide file tree
Showing 35 changed files with 747 additions and 241 deletions.
13 changes: 7 additions & 6 deletions application/applicationcontext.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* @license http://opensource.org/licenses/AGPL-3.0
*/

use Combodo\iTop\Application\Helper\Session;
use Combodo\iTop\Application\UI\Base\Component\Input\InputUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
use Combodo\iTop\Application\UI\Base\UIBlock;
Expand Down Expand Up @@ -321,7 +322,7 @@ public static function SetUrlMakerClass($sClass = 'iTopStandardURLMaker')
$sPrevious = self::GetUrlMakerClass();

self::$m_sUrlMakerClass = $sClass;
$_SESSION['UrlMakerClass'] = $sClass;
Session::Set('UrlMakerClass', $sClass);

return $sPrevious;
}
Expand All @@ -334,9 +335,9 @@ public static function GetUrlMakerClass()
{
if (is_null(self::$m_sUrlMakerClass))
{
if (isset($_SESSION['UrlMakerClass']))
if (Session::IsSet('UrlMakerClass'))
{
self::$m_sUrlMakerClass = $_SESSION['UrlMakerClass'];
self::$m_sUrlMakerClass = Session::Get('UrlMakerClass');
}
else
{
Expand Down Expand Up @@ -389,9 +390,9 @@ public static function MakeObjectUrl($sObjClass, $sObjKey, $sUrlMakerClass = nul
*/
protected static function LoadPluginProperties()
{
if (isset($_SESSION['PluginProperties']))
if (Session::IsSet('PluginProperties'))
{
self::$m_aPluginProperties = $_SESSION['PluginProperties'];
self::$m_aPluginProperties = Session::Get('PluginProperties');
}
else
{
Expand All @@ -411,7 +412,7 @@ public static function SetPluginProperty($sPluginClass, $sProperty, $value)
if (is_null(self::$m_aPluginProperties)) self::LoadPluginProperties();

self::$m_aPluginProperties[$sPluginClass][$sProperty] = $value;
$_SESSION['PluginProperties'][$sPluginClass][$sProperty] = $value;
Session::Set(['PluginProperties', $sPluginClass, $sProperty], $value);
}

/**
Expand Down
11 changes: 6 additions & 5 deletions application/cmdbabstract.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @license http://opensource.org/licenses/AGPL-3.0
*/

use Combodo\iTop\Application\Helper\Session;
use Combodo\iTop\Application\Search\SearchForm;
use Combodo\iTop\Application\UI\Base\Component\Alert\AlertUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Button\Button;
Expand Down Expand Up @@ -260,15 +261,15 @@ protected function SetSessionMessageFromInstance($sMessageId, $sMessage, $sSever
public static function SetSessionMessage($sClass, $iKey, $sMessageId, $sMessage, $sSeverity, $fRank, $bMustNotExist = false)
{
$sMessageKey = $sClass.'::'.$iKey;
if (!isset($_SESSION['obj_messages'][$sMessageKey])) {
$_SESSION['obj_messages'][$sMessageKey] = array();
if (!Session::IsSet(['obj_messages', $sMessageKey])) {
Session::Set(['obj_messages', $sMessageKey], []);
}
if (!$bMustNotExist || !array_key_exists($sMessageId, $_SESSION['obj_messages'][$sMessageKey])) {
$_SESSION['obj_messages'][$sMessageKey][$sMessageId] = array(
if (!$bMustNotExist || !Session::IsSet(['obj_messages', $sMessageKey, $sMessageId])) {
Session::Set(['obj_messages', $sMessageKey, $sMessageId], [
'rank' => $fRank,
'severity' => $sSeverity,
'message' => $sMessage,
);
]);
}
}

Expand Down
31 changes: 17 additions & 14 deletions application/loginbasic.class.inc.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

use Combodo\iTop\Application\Helper\Session;

/**
* Class LoginBasic
*
Expand All @@ -20,41 +23,41 @@ public function ListSupportedLoginModes()

protected function OnModeDetection(&$iErrorCode)
{
if (!isset($_SESSION['login_mode']))
if (!Session::IsSet('login_mode'))
{
if (isset($_SERVER['HTTP_AUTHORIZATION']) && !empty($_SERVER['HTTP_AUTHORIZATION']))
{
$_SESSION['login_mode'] = 'basic';
Session::Set('login_mode', 'basic');
}
elseif (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && !empty($_SERVER['REDIRECT_HTTP_AUTHORIZATION']))
{
$_SESSION['login_mode'] = 'basic';
Session::Set('login_mode', 'basic');
}
elseif (isset($_SERVER['PHP_AUTH_USER']))
{
$_SESSION['login_mode'] = 'basic';
Session::Set('login_mode', 'basic');
}
}
return LoginWebPage::LOGIN_FSM_CONTINUE;
}

protected function OnReadCredentials(&$iErrorCode)
{
if (!isset($_SESSION['login_mode']) || $_SESSION['login_mode'] == 'basic')
if (!Session::IsSet('login_mode') || Session::Get('login_mode') == 'basic')
{
list($sAuthUser, $sAuthPwd) = $this->GetAuthUserAndPassword();
$_SESSION['login_temp_auth_user'] = $sAuthUser;
list($sAuthUser) = $this->GetAuthUserAndPassword();
Session::Set('login_temp_auth_user', $sAuthUser);
}
return LoginWebPage::LOGIN_FSM_CONTINUE;
}


protected function OnCheckCredentials(&$iErrorCode)
{
if ($_SESSION['login_mode'] == 'basic')
if (Session::Get('login_mode') == 'basic')
{
list($sAuthUser, $sAuthPwd) = $this->GetAuthUserAndPassword();
if (!UserRights::CheckCredentials($sAuthUser, $sAuthPwd, $_SESSION['login_mode'], 'internal'))
if (!UserRights::CheckCredentials($sAuthUser, $sAuthPwd, Session::Get('login_mode'), 'internal'))
{
$iErrorCode = LoginWebPage::EXIT_CODE_WRONGCREDENTIALS;
return LoginWebPage::LOGIN_FSM_ERROR;
Expand All @@ -65,17 +68,17 @@ protected function OnCheckCredentials(&$iErrorCode)

protected function OnCredentialsOK(&$iErrorCode)
{
if ($_SESSION['login_mode'] == 'basic')
if (Session::Get('login_mode') == 'basic')
{
list($sAuthUser) = $this->GetAuthUserAndPassword();
LoginWebPage::OnLoginSuccess($sAuthUser, 'internal', $_SESSION['login_mode']);
LoginWebPage::OnLoginSuccess($sAuthUser, 'internal', Session::Get('login_mode'));
}
return LoginWebPage::LOGIN_FSM_CONTINUE;
}

protected function OnError(&$iErrorCode)
{
if ($_SESSION['login_mode'] == 'basic')
if (Session::Get('login_mode') == 'basic')
{
LoginWebPage::HTTP401Error();
}
Expand All @@ -84,9 +87,9 @@ protected function OnError(&$iErrorCode)

protected function OnConnected(&$iErrorCode)
{
if ($_SESSION['login_mode'] == 'basic')
if (Session::Get('login_mode') == 'basic')
{
$_SESSION['can_logoff'] = true;
Session::Set('can_logoff', true);
return LoginWebPage::CheckLoggedUser($iErrorCode);
}
return LoginWebPage::LOGIN_FSM_CONTINUE;
Expand Down
16 changes: 9 additions & 7 deletions application/logindefault.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* @license http://opensource.org/licenses/AGPL-3.0
*/

use Combodo\iTop\Application\Helper\Session;

/**
* Class LoginDefaultBefore
*/
Expand All @@ -23,7 +25,7 @@ protected function OnStart(&$iErrorCode)
{
$iErrorCode = LoginWebPage::EXIT_CODE_OK;

unset($_SESSION['login_temp_auth_user']);
Session::Unset('login_temp_auth_user');

// Check if proposed login mode is present and allowed
$aAllowedLoginTypes = MetaModel::GetConfig()->GetAllowedLoginTypes();
Expand All @@ -32,11 +34,11 @@ protected function OnStart(&$iErrorCode)
if ($index !== false)
{
// Force login mode
$_SESSION['login_mode'] = $sProposedLoginMode;
Session::Set('login_mode', $sProposedLoginMode);
}
else
{
unset($_SESSION['login_mode']);
Session::Unset('login_mode');
}
return LoginWebPage::LOGIN_FSM_CONTINUE;
}
Expand Down Expand Up @@ -91,7 +93,7 @@ protected function OnError(&$iErrorCode)

protected function OnCredentialsOk(&$iErrorCode)
{
if (!isset($_SESSION['login_mode']))
if (!Session::IsSet('login_mode'))
{
// If no plugin validated the user, exit
self::ResetLoginSession();
Expand All @@ -110,19 +112,19 @@ public function LogoutAction()

protected function OnConnected(&$iErrorCode)
{
unset($_SESSION['login_temp_auth_user']);
Session::Unset('login_temp_auth_user');
return LoginWebPage::LOGIN_FSM_CONTINUE;
}

// Hard reset of the session
private static function ResetLoginSession()
{
LoginWebPage::ResetSession();
foreach (array_keys($_SESSION) as $sKey)
foreach (Session::ListVariables() as $sKey)
{
if (utils::StartsWith($sKey, 'login_'))
{
unset($_SESSION[$sKey]);
Session::Unset($sKey);
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions application/startup.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with iTop. If not, see <http://www.gnu.org/licenses/>
use Combodo\iTop\Application\Helper\Session;

require_once(APPROOT.'/core/cmdbobject.class.inc.php');
require_once(APPROOT.'/application/utils.inc.php');
require_once(APPROOT.'/core/contexttag.class.inc.php');
require_once(APPROOT.'/core/kpi.class.inc.php');


/**
Expand All @@ -27,6 +30,9 @@
* @license http://opensource.org/licenses/AGPL-3.0
*/

ExecutionKPI::EnableDuration(1);
ExecutionKPI::EnableMemory(1);

// This storage is freed on error (case of allowed memory exhausted)
$sReservedMemory = str_repeat('*', 1024 * 1024);
register_shutdown_function(function()
Expand Down Expand Up @@ -63,8 +69,9 @@
}
});

session_name('itop-'.md5(APPROOT));
session_start();
Session::Start();
Session::WriteClose();

$sSwitchEnv = utils::ReadParam('switch_env', null);
$bAllowCache = true;
if (($sSwitchEnv != null) && (file_exists(APPCONF.$sSwitchEnv.'/'.ITOP_CONFIG_FILE)) && isset($_SESSION['itop_env']) && ($_SESSION['itop_env'] !== $sSwitchEnv))
Expand Down
21 changes: 11 additions & 10 deletions application/transaction.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with iTop. If not, see <http://www.gnu.org/licenses/>
use Combodo\iTop\Application\Helper\Session;

/**
* This class records the pending "transactions" corresponding to forms that have not been
Expand Down Expand Up @@ -112,15 +113,15 @@ class privUITransactionSession
*/
public static function GetNewTransactionId()
{
if (!isset($_SESSION['transactions']))
if (!Session::IsSet('transactions'))
{
$_SESSION['transactions'] = array();
Session::Set('transactions', []);
}
// Strictly speaking, the two lines below should be grouped together
// by a critical section
// sem_acquire($rSemIdentified);
$id = static::GetUserPrefix() . str_replace(array('.', ' '), '', microtime()); //1 + count($_SESSION['transactions']);
$_SESSION['transactions'][$id] = true;
$id = static::GetUserPrefix() . str_replace(array('.', ' '), '', microtime());
Session::Set(['transactions', $id], true);
// sem_release($rSemIdentified);

return (string)$id;
Expand All @@ -137,17 +138,17 @@ public static function GetNewTransactionId()
public static function IsTransactionValid($id, $bRemoveTransaction = true)
{
$bResult = false;
if (isset($_SESSION['transactions']))
if (Session::IsSet('transactions'))
{
// Strictly speaking, the eight lines below should be grouped together
// inside the same critical section as above
// sem_acquire($rSemIdentified);
if (isset($_SESSION['transactions'][$id]))
if (Session::IsSet(['transactions', $id]))
{
$bResult = true;
if ($bRemoveTransaction)
{
unset($_SESSION['transactions'][$id]);
Session::Unset(['transactions', $id]);
}
}
// sem_release($rSemIdentified);
Expand All @@ -162,14 +163,14 @@ public static function IsTransactionValid($id, $bRemoveTransaction = true)
*/
public static function RemoveTransaction($id)
{
if (isset($_SESSION['transactions']))
if (Session::IsSet('transactions'))
{
// Strictly speaking, the three lines below should be grouped together
// inside the same critical section as above
// sem_acquire($rSemIdentified);
if (isset($_SESSION['transactions'][$id]))
if (Session::IsSet(['transactions', $id]))
{
unset($_SESSION['transactions'][$id]);
Session::Unset(['transactions', $id]);
}
// sem_release($rSemIdentified);
}
Expand Down
18 changes: 6 additions & 12 deletions application/utils.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* You should have received a copy of the GNU Affero General Public License
*/

use Combodo\iTop\Application\Helper\Session;
use Combodo\iTop\Application\UI\Base\iUIBlock;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
use ScssPhp\ScssPhp\Compiler;
Expand Down Expand Up @@ -239,9 +240,9 @@ public static function IsXmlHttpRequest()

public static function InitArchiveMode()
{
if (isset($_SESSION['archive_mode']))
if (Session::IsSet('archive_mode'))
{
$iDefault = $_SESSION['archive_mode'];
$iDefault = Session::Get('archive_mode');
}
else
{
Expand All @@ -251,7 +252,7 @@ public static function InitArchiveMode()
$iCurrent = self::ReadParam('with-archive', $iDefault);
if (isset($_SESSION))
{
$_SESSION['archive_mode'] = $iCurrent;
Session::Set('archive_mode', $iCurrent);
}
// Read and use the value for the current page (web services)
$iCurrent = self::ReadParam('with_archive', $iCurrent, true);
Expand Down Expand Up @@ -1210,7 +1211,7 @@ public static function IsConnectionSecure($bForceTrustProxy = false)
*/
static function CanLogOff()
{
return (isset($_SESSION['can_logoff']) ? $_SESSION['can_logoff'] : false);
return Session::Get('can_logoff', false);
}

/**
Expand Down Expand Up @@ -1312,14 +1313,7 @@ public static function ExecITopScript(string $sScriptName, array $aArguments, st
*/
public static function GetCurrentEnvironment()
{
if (isset($_SESSION['itop_env']))
{
return $_SESSION['itop_env'];
}
else
{
return ITOP_DEFAULT_ENV;
}
return Session::Get('itop_env', ITOP_DEFAULT_ENV);
}

/**
Expand Down
Loading

0 comments on commit 2c2155a

Please sign in to comment.