mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-20 07:42:17 +02:00
N°2060 [WIP] Initialisation of the portal application: Remove Silex portal files
This commit is contained in:
@@ -1,281 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// Copyright (C) 2010-2018 Combodo SARL
|
|
||||||
//
|
|
||||||
// This file is part of iTop.
|
|
||||||
//
|
|
||||||
// iTop is free software; you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Affero General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// iTop is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
|
||||||
|
|
||||||
namespace Combodo\iTop\Portal\Helper;
|
|
||||||
|
|
||||||
use Silex\Application;
|
|
||||||
use UserRights;
|
|
||||||
use IssueLog;
|
|
||||||
use MetaModel;
|
|
||||||
use DBSearch;
|
|
||||||
use DBObjectSearch;
|
|
||||||
use DBObjectSet;
|
|
||||||
use FieldExpression;
|
|
||||||
use VariableExpression;
|
|
||||||
use BinaryExpression;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SecurityHelper class
|
|
||||||
*
|
|
||||||
* Handle security checks through the different layers (portal scopes, iTop silos, user rights)
|
|
||||||
*
|
|
||||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
|
||||||
*/
|
|
||||||
class SecurityHelper
|
|
||||||
{
|
|
||||||
public static $aAllowedScopeObjectsCache = array(
|
|
||||||
UR_ACTION_READ => array(),
|
|
||||||
UR_ACTION_MODIFY => array(),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the current user is allowed to do the $sAction on an $sObjectClass object (with optionnal $sObjectId id)
|
|
||||||
* Checks are:
|
|
||||||
* - Has a scope query for the $sObjectClass / $sAction
|
|
||||||
* - Optionally, if $sObjectId provided: Is object within scope for $sObjectClass / $sObjectId / $sAction
|
|
||||||
* - Is allowed by datamodel for $sObjectClass / $sAction
|
|
||||||
*
|
|
||||||
* @param \Silex\Application $oApp
|
|
||||||
* @param string $sAction Must be in UR_ACTION_READ|UR_ACTION_MODIFY|UR_ACTION_CREATE
|
|
||||||
* @param string $sObjectClass
|
|
||||||
* @param string $sObjectId
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*
|
|
||||||
* @throws \CoreException
|
|
||||||
*/
|
|
||||||
public static function IsActionAllowed(Application $oApp, $sAction, $sObjectClass, $sObjectId = null)
|
|
||||||
{
|
|
||||||
$sDebugTracePrefix = __CLASS__ . ' / ' . __METHOD__ . ' : Returned false for action ' . $sAction . ' on ' . $sObjectClass . '::' . $sObjectId;
|
|
||||||
|
|
||||||
// Checking action type
|
|
||||||
if (!in_array($sAction, array(UR_ACTION_READ, UR_ACTION_MODIFY, UR_ACTION_CREATE)))
|
|
||||||
{
|
|
||||||
if ($oApp['debug'])
|
|
||||||
{
|
|
||||||
IssueLog::Info($sDebugTracePrefix . ' as the action value could not be understood (' . UR_ACTION_READ . '/' . UR_ACTION_MODIFY . '/' . UR_ACTION_CREATE . ' expected');
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checking the scopes layer
|
|
||||||
// - Transforming scope action as there is only 2 values
|
|
||||||
$sScopeAction = ($sAction === UR_ACTION_READ) ? UR_ACTION_READ : UR_ACTION_MODIFY;
|
|
||||||
// - Retrieving the query. If user has no scope, it can't access that kind of objects
|
|
||||||
$oScopeQuery = $oApp['scope_validator']->GetScopeFilterForProfiles(UserRights::ListProfiles(), $sObjectClass, $sScopeAction);
|
|
||||||
if ($oScopeQuery === null)
|
|
||||||
{
|
|
||||||
if ($oApp['debug'])
|
|
||||||
{
|
|
||||||
IssueLog::Info($sDebugTracePrefix . ' as there was no scope defined for action ' . $sScopeAction . ' and profiles ' . implode('/', UserRights::ListProfiles()));
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// - If action != create we do some additionnal checks
|
|
||||||
if ($sAction !== UR_ACTION_CREATE)
|
|
||||||
{
|
|
||||||
// - Checking specific object if id is specified
|
|
||||||
if ($sObjectId !== null)
|
|
||||||
{
|
|
||||||
// Checking if object status is in cache (to avoid unnecessary query)
|
|
||||||
if(isset(static::$aAllowedScopeObjectsCache[$sScopeAction][$sObjectClass][$sObjectId]) )
|
|
||||||
{
|
|
||||||
if(static::$aAllowedScopeObjectsCache[$sScopeAction][$sObjectClass][$sObjectId] === false)
|
|
||||||
{
|
|
||||||
if ($oApp['debug'])
|
|
||||||
{
|
|
||||||
IssueLog::Info($sDebugTracePrefix . ' as it was denied in the scope objects cache');
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Modifying query to filter on the ID
|
|
||||||
// - Adding expression
|
|
||||||
$sObjectKeyAtt = MetaModel::DBGetKey($sObjectClass);
|
|
||||||
$oFieldExp = new FieldExpression($sObjectKeyAtt, $oScopeQuery->GetClassAlias());
|
|
||||||
$oBinExp = new BinaryExpression($oFieldExp, '=', new VariableExpression('object_id'));
|
|
||||||
$oScopeQuery->AddConditionExpression($oBinExp);
|
|
||||||
// - Setting value
|
|
||||||
$aQueryParams = $oScopeQuery->GetInternalParams();
|
|
||||||
$aQueryParams['object_id'] = $sObjectId;
|
|
||||||
$oScopeQuery->SetInternalParams($aQueryParams);
|
|
||||||
unset($aQueryParams);
|
|
||||||
|
|
||||||
// - Checking if query result is null (which means that the user has no right to view this specific object)
|
|
||||||
$oSet = new DBObjectSet($oScopeQuery);
|
|
||||||
if ($oSet->Count() === 0)
|
|
||||||
{
|
|
||||||
// Updating cache
|
|
||||||
static::$aAllowedScopeObjectsCache[$sScopeAction][$sObjectClass][$sObjectId] = false;
|
|
||||||
|
|
||||||
if ($oApp['debug'])
|
|
||||||
{
|
|
||||||
IssueLog::Info($sDebugTracePrefix . ' as there was no result for the following scope query : ' . $oScopeQuery->ToOQL(true));
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Updating cache
|
|
||||||
static::$aAllowedScopeObjectsCache[$sScopeAction][$sObjectClass][$sObjectId] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checking reading security layer. The object could be listed, check if it is actually allowed to view it
|
|
||||||
if (UserRights::IsActionAllowed($sObjectClass, $sAction) == UR_ALLOWED_NO)
|
|
||||||
{
|
|
||||||
// For security reasons, we don't want to give the user too many informations on why he cannot access the object.
|
|
||||||
//throw new SecurityException('User not allowed to view this object', array('class' => $sObjectClass, 'id' => $sObjectId));
|
|
||||||
if ($oApp['debug'])
|
|
||||||
{
|
|
||||||
IssueLog::Info($sDebugTracePrefix . ' as the user is not allowed to access this object according to the datamodel security (cf. Console settings)');
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function IsStimulusAllowed(Application $oApp, $sStimulusCode, $sObjectClass, $oInstanceSet = null)
|
|
||||||
{
|
|
||||||
// Checking DataModel layer
|
|
||||||
$aStimuliFromDatamodel = Metamodel::EnumStimuli($sObjectClass);
|
|
||||||
$iActionAllowed = (get_class($aStimuliFromDatamodel[$sStimulusCode]) == 'StimulusUserAction') ? UserRights::IsStimulusAllowed($sObjectClass, $sStimulusCode, $oInstanceSet) : UR_ALLOWED_NO;
|
|
||||||
if( ($iActionAllowed === false) || ($iActionAllowed === UR_ALLOWED_NO) )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checking portal security layer
|
|
||||||
$aStimuliFromPortal = $oApp['lifecycle_validator']->GetStimuliForProfiles(UserRights::ListProfiles(), $sObjectClass);
|
|
||||||
if(!in_array($sStimulusCode, $aStimuliFromPortal))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Preloads scope objects cache with objects from $oQuery
|
|
||||||
*
|
|
||||||
* @param \Silex\Application $oApp
|
|
||||||
* @param \DBSearch $oSearch
|
|
||||||
* @param array $aExtKeysToPreload
|
|
||||||
*
|
|
||||||
* @throws \Exception
|
|
||||||
* @throws \CoreException
|
|
||||||
*/
|
|
||||||
public static function PreloadForCache(Application $oApp, DBSearch $oSearch, $aExtKeysToPreload = null)
|
|
||||||
{
|
|
||||||
$sObjectClass = $oSearch->GetClass();
|
|
||||||
$aObjectIds = array();
|
|
||||||
$aExtKeysIds = array();
|
|
||||||
$aColumnsToLoad = array();
|
|
||||||
|
|
||||||
if($aExtKeysToPreload !== null)
|
|
||||||
{
|
|
||||||
foreach($aExtKeysToPreload as $sAttCode)
|
|
||||||
{
|
|
||||||
/** @var \AttributeDefinition $oAttDef */
|
|
||||||
$oAttDef = MetaModel::GetAttributeDef($sObjectClass, $sAttCode);
|
|
||||||
if($oAttDef->IsExternalKey())
|
|
||||||
{
|
|
||||||
$aExtKeysIds[$oAttDef->GetTargetClass()] = array();
|
|
||||||
$aColumnsToLoad[] = $sAttCode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retrieving IDs of all objects
|
|
||||||
// Note: We have to clone $oSet otherwise the source object will be modified
|
|
||||||
$oSet = new DBObjectSet($oSearch);
|
|
||||||
$oSet->OptimizeColumnLoad(array($oSearch->GetClassAlias() => $aColumnsToLoad));
|
|
||||||
while($oCurrentRow = $oSet->Fetch())
|
|
||||||
{
|
|
||||||
// Note: By presetting value to false, it is quicker to find which objects where not returned by the scope query later
|
|
||||||
$aObjectIds[$oCurrentRow->GetKey()] = false;
|
|
||||||
|
|
||||||
// Preparing ExtKeys to preload
|
|
||||||
foreach($aColumnsToLoad as $sAttCode)
|
|
||||||
{
|
|
||||||
$iExtKey = $oCurrentRow->Get($sAttCode);
|
|
||||||
if($iExtKey > 0)
|
|
||||||
{
|
|
||||||
/** @var \AttributeExternalKey $oAttDef */
|
|
||||||
$oAttDef = MetaModel::GetAttributeDef($sObjectClass, $sAttCode);
|
|
||||||
if(!in_array($iExtKey, $aExtKeysIds[$oAttDef->GetTargetClass()]))
|
|
||||||
{
|
|
||||||
$aExtKeysIds[$oAttDef->GetTargetClass()][] = $iExtKey;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach(array(UR_ACTION_READ, UR_ACTION_MODIFY) as $sScopeAction)
|
|
||||||
{
|
|
||||||
// Retrieving scope query
|
|
||||||
/** @var DBSearch $oScopeQuery */
|
|
||||||
$oScopeQuery = $oApp['scope_validator']->GetScopeFilterForProfiles(UserRights::ListProfiles(), $sObjectClass, $sScopeAction);
|
|
||||||
if($oScopeQuery !== null)
|
|
||||||
{
|
|
||||||
// Restricting scope if specified
|
|
||||||
if(!empty($aObjectIds))
|
|
||||||
{
|
|
||||||
$oScopeQuery->AddCondition('id', array_keys($aObjectIds), 'IN');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Preparing object set
|
|
||||||
$oScopeSet = new DBObjectSet($oScopeQuery);
|
|
||||||
$oScopeSet->OptimizeColumnLoad(array());
|
|
||||||
|
|
||||||
// Checking objects status
|
|
||||||
$aScopeObjectIds = $aObjectIds;
|
|
||||||
while($oCurrentRow = $oScopeSet->Fetch())
|
|
||||||
{
|
|
||||||
$aScopeObjectIds[$oCurrentRow->GetKey()] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Updating cache
|
|
||||||
if(!isset(static::$aAllowedScopeObjectsCache[$sScopeAction][$sObjectClass]))
|
|
||||||
{
|
|
||||||
static::$aAllowedScopeObjectsCache[$sScopeAction][$sObjectClass] = $aScopeObjectIds;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
static::$aAllowedScopeObjectsCache[$sScopeAction][$sObjectClass] = array_merge_recursive(static::$aAllowedScopeObjectsCache[$sScopeAction][$sObjectClass], $aScopeObjectIds);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Preloading ExtKeys
|
|
||||||
foreach($aExtKeysIds as $sTargetClass => $aTargetIds)
|
|
||||||
{
|
|
||||||
if(!empty($aTargetIds))
|
|
||||||
{
|
|
||||||
$oTargetSearch = new DBObjectSearch($sTargetClass);
|
|
||||||
$oTargetSearch->AddCondition('id', $aTargetIds, 'IN');
|
|
||||||
|
|
||||||
static::PreloadForCache($oApp, $oTargetSearch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// Copyright (C) 2010-2015 Combodo SARL
|
|
||||||
//
|
|
||||||
// This file is part of iTop.
|
|
||||||
//
|
|
||||||
// iTop is free software; you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Affero General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// iTop is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
|
||||||
|
|
||||||
namespace Combodo\iTop\Portal\Provider;
|
|
||||||
|
|
||||||
use Pimple\Container;
|
|
||||||
use Pimple\ServiceProviderInterface;
|
|
||||||
use Combodo\iTop\Portal\Helper\ContextManipulatorHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ContextManipulatorHelper service provider
|
|
||||||
*
|
|
||||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
|
||||||
*/
|
|
||||||
class ContextManipulatorServiceProvider implements ServiceProviderInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
public function register(Container $oApp)
|
|
||||||
{
|
|
||||||
$oApp['context_manipulator'] = function ($oApp)
|
|
||||||
{
|
|
||||||
$oApp->flush();
|
|
||||||
|
|
||||||
$oContextManipulatorHelper = new ContextManipulatorHelper();
|
|
||||||
$oContextManipulatorHelper->SetApp($oApp);
|
|
||||||
|
|
||||||
return $oContextManipulatorHelper;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public function boot(Container $oApp)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// Copyright (C) 2010-2017 Combodo SARL
|
|
||||||
//
|
|
||||||
// This file is part of iTop.
|
|
||||||
//
|
|
||||||
// iTop is free software; you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Affero General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// iTop is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
|
||||||
|
|
||||||
namespace Combodo\iTop\Portal\Provider;
|
|
||||||
|
|
||||||
use Pimple\Container;
|
|
||||||
use Pimple\ServiceProviderInterface;
|
|
||||||
use Combodo\iTop\Portal\Helper\LifecycleValidatorHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* LifecycleValidatorHelper service provider
|
|
||||||
*
|
|
||||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
|
||||||
*/
|
|
||||||
class LifecycleValidatorServiceProvider implements ServiceProviderInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
public function register(Container $oApp)
|
|
||||||
{
|
|
||||||
$oApp['lifecycle_validator'] = function ($oApp)
|
|
||||||
{
|
|
||||||
$oApp->flush();
|
|
||||||
|
|
||||||
$oLifecycleValidatorHelper = new LifecycleValidatorHelper($oApp['lifecycle_validator.lifecycle_filename'], $oApp['lifecycle_validator.lifecycle_path']);
|
|
||||||
if (isset($oApp['lifecycle_validator.instance_name']))
|
|
||||||
{
|
|
||||||
$oLifecycleValidatorHelper->SetInstancePrefix($oApp['lifecycle_validator.instance_name'] . '-');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $oLifecycleValidatorHelper;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public function boot(Container $oApp)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copyright (C) 2012-2018 Combodo SARL
|
|
||||||
*
|
|
||||||
* This file is part of iTop.
|
|
||||||
*
|
|
||||||
* iTop is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* iTop is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with iTop. If not, see <http://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Combodo\iTop\Portal\Provider;
|
|
||||||
|
|
||||||
use Pimple\Container;
|
|
||||||
use Pimple\ServiceProviderInterface;
|
|
||||||
use Combodo\iTop\Portal\Helper\RequestManipulatorHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RequestManipulatorHelper service provider
|
|
||||||
*
|
|
||||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
|
||||||
* @since 2.5.1
|
|
||||||
*/
|
|
||||||
class RequestManipulatorServiceProvider implements ServiceProviderInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \Pimple\Container $oApp
|
|
||||||
*/
|
|
||||||
public function register(Container $oApp)
|
|
||||||
{
|
|
||||||
$oApp['request_manipulator'] = function ($oApp)
|
|
||||||
{
|
|
||||||
$oApp->flush();
|
|
||||||
|
|
||||||
$oRequestManipulatorHelper = new RequestManipulatorHelper($oApp['request_stack']);
|
|
||||||
|
|
||||||
return $oRequestManipulatorHelper;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \Pimple\Container $oApp
|
|
||||||
*/
|
|
||||||
public function boot(Container $oApp)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// Copyright (C) 2010-2015 Combodo SARL
|
|
||||||
//
|
|
||||||
// This file is part of iTop.
|
|
||||||
//
|
|
||||||
// iTop is free software; you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Affero General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// iTop is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
|
||||||
|
|
||||||
namespace Combodo\iTop\Portal\Provider;
|
|
||||||
|
|
||||||
use Pimple\Container;
|
|
||||||
use Pimple\ServiceProviderInterface;
|
|
||||||
use Combodo\iTop\Portal\Helper\ScopeValidatorHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ScopeValidatorHelper service provider
|
|
||||||
*
|
|
||||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
|
||||||
*/
|
|
||||||
class ScopeValidatorServiceProvider implements ServiceProviderInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
public function register(Container $oApp)
|
|
||||||
{
|
|
||||||
$oApp['scope_validator'] = function ($oApp)
|
|
||||||
{
|
|
||||||
$oApp->flush();
|
|
||||||
|
|
||||||
$oScopeValidatorHelper = new ScopeValidatorHelper($oApp['scope_validator.scopes_filename'], $oApp['scope_validator.scopes_path']);
|
|
||||||
if (isset($oApp['scope_validator.instance_name']))
|
|
||||||
{
|
|
||||||
$oScopeValidatorHelper->SetInstancePrefix($oApp['scope_validator.instance_name'] . '-');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $oScopeValidatorHelper;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public function boot(Container $oApp)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,140 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// Copyright (C) 2010-2018 Combodo SARL
|
|
||||||
//
|
|
||||||
// This file is part of iTop.
|
|
||||||
//
|
|
||||||
// iTop is free software; you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Affero General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// iTop is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
|
||||||
|
|
||||||
namespace Combodo\iTop\Portal\Router;
|
|
||||||
|
|
||||||
use Silex\Application;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AbstractRouter class is where URLs are defined with their callback, parameters and constraints (assertions).
|
|
||||||
* It allows us to have URL pattern at one place only and to generate them anywhere in the code, avoiding to maintain URLs in multiple places.
|
|
||||||
*
|
|
||||||
* @package \Combodo\iTop\Portal\Router
|
|
||||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
|
||||||
* @since 2.3.0
|
|
||||||
*/
|
|
||||||
abstract class AbstractRouter
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* List of routes for that Router.
|
|
||||||
*
|
|
||||||
* Each route is defined as an associative array and can have the following parameters :
|
|
||||||
* - pattern : URL pattern with its parameters names (eg: '/{sBrickId}/browse/{sBrowseMode}')
|
|
||||||
* - hash : String to append to the URL with an '#' (eg: 'modal-popup' will append '#modal-popup' to the above URL)
|
|
||||||
* - callback : Function to be called for that route, usally in a Controller. (eg: 'Combodo\\iTop\\Portal\\Controller\\CreateBrickController::DisplayAction')
|
|
||||||
* - bind : Unique name of the route, must not contain blanks. Usually lowercase with underscore (eg: 'p_browse_brick')
|
|
||||||
* - asserts : Associative array of assertions to check for the pattern parameters (eg: array( 'sBrowseMode' => 'list|tree'))
|
|
||||||
* - values : Associative array of default values for the pattern parameters (eg: array('sBrowseMode' => 'tree'))
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
static $aRoutes = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns routes of the current AbstractRouter defined in $aRoutes.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
static function GetRoutes()
|
|
||||||
{
|
|
||||||
return static::$aRoutes;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the route named $name of the current AbstractRouter.
|
|
||||||
* Throws an exception if not found.
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
static function GetRoute($name)
|
|
||||||
{
|
|
||||||
$bFound = false;
|
|
||||||
$aFoundRoute = array();
|
|
||||||
|
|
||||||
foreach (static::$aRoutes as $aRoute)
|
|
||||||
{
|
|
||||||
if (isset($aRoute['bind']) && $aRoute['bind'] === $name)
|
|
||||||
{
|
|
||||||
$bFound = true;
|
|
||||||
$aFoundRoute = $aRoute;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$bFound)
|
|
||||||
{
|
|
||||||
throw new \Exception('Unknown route "' . $name . '" for ' . get_class() . '');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $aFoundRoute;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers all routes of the current AbstractRouter to the Application $oApp.
|
|
||||||
*
|
|
||||||
* @param Application $oApp
|
|
||||||
* @return int Number of succesfully registered routes
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
static function RegisterAllRoutes(Application $oApp)
|
|
||||||
{
|
|
||||||
$iCounter = 0;
|
|
||||||
|
|
||||||
foreach (static::$aRoutes as $aRoute)
|
|
||||||
{
|
|
||||||
// Check if we have the base parameters to register the route
|
|
||||||
if (!isset($aRoute['pattern']) || !isset($aRoute['callback']))
|
|
||||||
{
|
|
||||||
throw new \Exception('Unable to register routes from ' . get_class() . ', some parameters are missing.');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Registering base route
|
|
||||||
$controller = $oApp->match($aRoute['pattern'], $aRoute['callback']);
|
|
||||||
|
|
||||||
// Checking if route has optionnal parameters
|
|
||||||
if (isset($aRoute['bind']))
|
|
||||||
{
|
|
||||||
$controller->bind($aRoute['bind']);
|
|
||||||
}
|
|
||||||
if (isset($aRoute['asserts']))
|
|
||||||
{
|
|
||||||
foreach ($aRoute['asserts'] as $sKey => $sValue)
|
|
||||||
{
|
|
||||||
$controller->assert($sKey, $sValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset($aRoute['values']))
|
|
||||||
{
|
|
||||||
foreach ($aRoute['values'] as $sKey => $sValue)
|
|
||||||
{
|
|
||||||
$controller->value($sKey, $sValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$iCounter++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $iCounter;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// Copyright (C) 2010-2018 Combodo SARL
|
|
||||||
//
|
|
||||||
// This file is part of iTop.
|
|
||||||
//
|
|
||||||
// iTop is free software; you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Affero General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// iTop is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should havze received a copy of the GNU Affero General Public License
|
|
||||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
|
||||||
|
|
||||||
namespace Combodo\iTop\Portal\Router;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class BrowseBrickRouter
|
|
||||||
*
|
|
||||||
* @package Combodo\iTop\Portal\Router
|
|
||||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
|
||||||
* @since 2.3.0
|
|
||||||
*/
|
|
||||||
class BrowseBrickRouter extends AbstractRouter
|
|
||||||
{
|
|
||||||
static $aRoutes = array(
|
|
||||||
// We don't set asserts for sBrowseMode on that route, as it the generic one, it can be extended by another brick.
|
|
||||||
array('pattern' => '/browse/{sBrickId}',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\BrowseBrickController::DisplayAction',
|
|
||||||
'bind' => 'p_browse_brick'
|
|
||||||
),
|
|
||||||
array('pattern' => '/browse/{sBrickId}/{sBrowseMode}',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\BrowseBrickController::DisplayAction',
|
|
||||||
'bind' => 'p_browse_brick_mode'
|
|
||||||
),
|
|
||||||
array('pattern' => '/browse/{sBrickId}/list/page/{iPageNumber}/show/{iListLength}',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\BrowseBrickController::DisplayAction',
|
|
||||||
'bind' => 'p_browse_brick_mode_list',
|
|
||||||
'asserts' => array(
|
|
||||||
'sBrowseMode' => 'list',
|
|
||||||
'iPageNumber' => '\d+',
|
|
||||||
'iListLength' => '\d+'
|
|
||||||
),
|
|
||||||
'values' => array(
|
|
||||||
'sBrowseMode' => 'list',
|
|
||||||
'sDataLoading' => 'lazy',
|
|
||||||
'iPageNumber' => '1',
|
|
||||||
'iListLength' => '20'
|
|
||||||
)
|
|
||||||
),
|
|
||||||
array('pattern' => '/browse/{sBrickId}/tree/expand/{sLevelAlias}/{sNodeId}',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\BrowseBrickController::DisplayAction',
|
|
||||||
'bind' => 'p_browse_brick_mode_tree',
|
|
||||||
'asserts' => array(
|
|
||||||
'sBrowseMode' => 'tree'
|
|
||||||
),
|
|
||||||
'values' => array(
|
|
||||||
'sBrowseMode' => 'tree',
|
|
||||||
'sDataLoading' => 'lazy',
|
|
||||||
'sNodeId' => null
|
|
||||||
)
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// Copyright (C) 2010-2018 Combodo SARL
|
|
||||||
//
|
|
||||||
// This file is part of iTop.
|
|
||||||
//
|
|
||||||
// iTop is free software; you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Affero General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// iTop is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
|
||||||
|
|
||||||
namespace Combodo\iTop\Portal\Router;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class CreateBrickRouter
|
|
||||||
*
|
|
||||||
* @package Combodo\iTop\Portal\Router
|
|
||||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
|
||||||
* @since 2.3.0
|
|
||||||
*/
|
|
||||||
class CreateBrickRouter extends AbstractRouter
|
|
||||||
{
|
|
||||||
static $aRoutes = array(
|
|
||||||
array('pattern' => '/create/{sBrickId}',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\CreateBrickController::DisplayAction',
|
|
||||||
'bind' => 'p_create_brick')
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// Copyright (C) 2010-2018 Combodo SARL
|
|
||||||
//
|
|
||||||
// This file is part of iTop.
|
|
||||||
//
|
|
||||||
// iTop is free software; you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Affero General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// iTop is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
|
||||||
|
|
||||||
namespace Combodo\iTop\Portal\Router;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class ManageBrickRouter
|
|
||||||
*
|
|
||||||
* @package Combodo\iTop\Portal\Router
|
|
||||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
|
||||||
* @author Pierre Goiffon <pierre.goiffon@combodo.com>
|
|
||||||
* @author Eric Espie <eric.espie@combodo.com>
|
|
||||||
* @since 2.3.0
|
|
||||||
*/
|
|
||||||
class ManageBrickRouter extends AbstractRouter
|
|
||||||
{
|
|
||||||
static $aRoutes = array(
|
|
||||||
array(
|
|
||||||
'pattern' => '/manage/{sBrickId}/{sGroupingTab}',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\ManageBrickController::DisplayAction',
|
|
||||||
'bind' => 'p_manage_brick',
|
|
||||||
'asserts' => array(),
|
|
||||||
'values' => array(
|
|
||||||
'sGroupingTab' => null,
|
|
||||||
)
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'pattern' => '/manage/{sBrickId}/display-as/{sDisplayMode}/{sGroupingTab}',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\ManageBrickController::DisplayAction',
|
|
||||||
'bind' => 'p_manage_brick_display_as',
|
|
||||||
'asserts' => array(
|
|
||||||
'sDisplayMode' => 'list|pie-chart|bar-chart'
|
|
||||||
),
|
|
||||||
'values' => array(
|
|
||||||
'sGroupingTab' => null,
|
|
||||||
)
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'pattern' => '/manage/{sBrickId}/{sGroupingTab}/{sGroupingArea}/page/{iPageNumber}/show/{iListLength}',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\ManageBrickController::DisplayAction',
|
|
||||||
'bind' => 'p_manage_brick_lazy',
|
|
||||||
'asserts' => array(
|
|
||||||
'iPageNumber' => '\d+',
|
|
||||||
'iListLength' => '\d+',
|
|
||||||
),
|
|
||||||
'values' => array(
|
|
||||||
'sDataLoading' => 'lazy',
|
|
||||||
'iPageNumber' => '1',
|
|
||||||
'iListLength' => '20',
|
|
||||||
)
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'pattern' => '/manage/export/excel/start/{sBrickId}/{sGroupingTab}/{sGroupingArea}',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\ManageBrickController::ExcelExportStartAction',
|
|
||||||
'bind' => 'p_manage_brick_excel_export_start',
|
|
||||||
'asserts' => array(),
|
|
||||||
'values' => array(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// Copyright (C) 2010-2018 Combodo SARL
|
|
||||||
//
|
|
||||||
// This file is part of iTop.
|
|
||||||
//
|
|
||||||
// iTop is free software; you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Affero General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// iTop is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
|
||||||
|
|
||||||
namespace Combodo\iTop\Portal\Router;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class ObjectRouter
|
|
||||||
*
|
|
||||||
* @package Combodo\iTop\Portal\Router
|
|
||||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
|
||||||
* @since 2.3.0
|
|
||||||
*/
|
|
||||||
class ObjectRouter extends AbstractRouter
|
|
||||||
{
|
|
||||||
static $aRoutes = array(
|
|
||||||
array('pattern' => '/object/create/{sObjectClass}',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\ObjectController::CreateAction',
|
|
||||||
'bind' => 'p_object_create'
|
|
||||||
),
|
|
||||||
array('pattern' => '/object/create-from-factory/{sObjectClass}/{sObjectId}/{sEncodedMethodName}',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\ObjectController::CreateFromFactoryAction',
|
|
||||||
'bind' => 'p_object_create_from_factory'
|
|
||||||
),
|
|
||||||
array('pattern' => '/object/edit/{sObjectClass}/{sObjectId}',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\ObjectController::EditAction',
|
|
||||||
'bind' => 'p_object_edit'
|
|
||||||
),
|
|
||||||
array('pattern' => '/object/view/{sObjectClass}/{sObjectId}',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\ObjectController::ViewAction',
|
|
||||||
'bind' => 'p_object_view'
|
|
||||||
),
|
|
||||||
array('pattern' => '/object/apply-stimulus/{sStimulusCode}/{sObjectClass}/{sObjectId}',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\ObjectController::ApplyStimulusAction',
|
|
||||||
'bind' => 'p_object_apply_stimulus'
|
|
||||||
),
|
|
||||||
array('pattern' => '/object/search',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\ObjectController::SearchRegularAction',
|
|
||||||
'bind' => 'p_object_search_regular'
|
|
||||||
),
|
|
||||||
array('pattern' => '/object/search/from-attribute/{sTargetAttCode}/{sHostObjectClass}/{sHostObjectId}',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\ObjectController::SearchFromAttributeAction',
|
|
||||||
'bind' => 'p_object_search_from_attribute',
|
|
||||||
'values' => array(
|
|
||||||
'sHostObjectClass' => null,
|
|
||||||
'sHostObjectId' => null
|
|
||||||
)
|
|
||||||
),
|
|
||||||
array('pattern' => '/object/search/autocomplete/{sTargetAttCode}/{sHostObjectClass}/{sHostObjectId}',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\ObjectController::SearchAutocompleteAction',
|
|
||||||
'bind' => 'p_object_search_autocomplete',
|
|
||||||
'values' => array(
|
|
||||||
'sHostObjectClass' => null,
|
|
||||||
'sHostObjectId' => null
|
|
||||||
)
|
|
||||||
),
|
|
||||||
array('pattern' => '/object/search/hierarchy/{sTargetAttCode}/{sHostObjectClass}/{sHostObjectId}',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\ObjectController::SearchHierarchyAction',
|
|
||||||
'bind' => 'p_object_search_hierarchy',
|
|
||||||
'values' => array(
|
|
||||||
'sHostObjectClass' => null,
|
|
||||||
'sHostObjectId' => null
|
|
||||||
)
|
|
||||||
),
|
|
||||||
array('pattern' => '/object/search/{sMode}/{sTargetAttCode}/{sHostObjectClass}/{sHostObjectId}',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\ObjectController::SearchAction',
|
|
||||||
'bind' => 'p_object_search_generic',
|
|
||||||
'values' => array(
|
|
||||||
'sMode' => '-sMode-',
|
|
||||||
'sHostObjectClass' => null,
|
|
||||||
'sHostObjectId' => null
|
|
||||||
)
|
|
||||||
),
|
|
||||||
array('pattern' => '/object/get-informations/json',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\ObjectController::GetInformationsAsJsonAction',
|
|
||||||
'bind' => 'p_object_get_informations_json',
|
|
||||||
),
|
|
||||||
array('pattern' => '/object/document/display/{sObjectClass}/{sObjectId}/{sObjectField}',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\ObjectController::DocumentAction',
|
|
||||||
'bind' => 'p_object_document_display',
|
|
||||||
'values' => array(
|
|
||||||
'sOperation' => 'display'
|
|
||||||
)
|
|
||||||
),
|
|
||||||
array('pattern' => '/object/document/download/{sObjectClass}/{sObjectId}/{sObjectField}',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\ObjectController::DocumentAction',
|
|
||||||
'bind' => 'p_object_document_download',
|
|
||||||
'values' => array(
|
|
||||||
'sOperation' => 'download'
|
|
||||||
)
|
|
||||||
),
|
|
||||||
array('pattern' => '/object/attachment/add',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\ObjectController::AttachmentAction',
|
|
||||||
'bind' => 'p_object_attachment_add'
|
|
||||||
),
|
|
||||||
array('pattern' => '/object/attachment/download/{sAttachmentId}',
|
|
||||||
'callback' => 'Combodo\\iTop\\Portal\\Controller\\ObjectController::AttachmentAction',
|
|
||||||
'bind' => 'p_object_attachment_download',
|
|
||||||
'values' => array(
|
|
||||||
'sOperation' => 'download'
|
|
||||||
)
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,172 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// Copyright (C) 2010-2018 Combodo SARL
|
|
||||||
//
|
|
||||||
// This file is part of iTop.
|
|
||||||
//
|
|
||||||
// iTop is free software; you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Affero General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// iTop is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Required constants :
|
|
||||||
* - PORTAL_MODULE_ID : Name of the portal instance module
|
|
||||||
* - PORTAL_ID : Name of the portal instance module design (Configuration)
|
|
||||||
*/
|
|
||||||
// Silex framework and components
|
|
||||||
require_once APPROOT . '/lib/silex/vendor/autoload.php';
|
|
||||||
// iTop application requirements
|
|
||||||
//require_once __DIR__.'/../../../../approot.inc.php'; // Required by the instanciation module
|
|
||||||
//require_once APPROOT.'/application/startup.inc.php'; // Required by the instanciation module
|
|
||||||
require_once APPROOT . '/core/moduledesign.class.inc.php';
|
|
||||||
require_once APPROOT . '/application/loginwebpage.class.inc.php';
|
|
||||||
require_once APPROOT . '/sources/autoload.php';
|
|
||||||
// Portal
|
|
||||||
// Note: This could be prevented by adding namespaces to composer
|
|
||||||
require_once __DIR__ . '/../src/providers/urlgeneratorserviceprovider.class.inc.php';
|
|
||||||
require_once __DIR__ . '/../src/helpers/urlgeneratorhelper.class.inc.php';
|
|
||||||
require_once __DIR__ . '/../src/providers/contextmanipulatorserviceprovider.class.inc.php';
|
|
||||||
require_once __DIR__ . '/../src/helpers/contextmanipulatorhelper.class.inc.php';
|
|
||||||
require_once __DIR__ . '/../src/providers/requestmanipulatorserviceprovider.class.inc.php';
|
|
||||||
require_once __DIR__ . '/../src/helpers/requestmanipulatorhelper.class.inc.php';
|
|
||||||
require_once __DIR__ . '/../src/providers/scopevalidatorserviceprovider.class.inc.php';
|
|
||||||
require_once __DIR__ . '/../src/helpers/scopevalidatorhelper.class.inc.php';
|
|
||||||
require_once __DIR__ . '/../src/providers/lifecyclevalidatorserviceprovider.class.inc.php';
|
|
||||||
require_once __DIR__ . '/../src/helpers/lifecyclevalidatorhelper.class.inc.php';
|
|
||||||
require_once __DIR__ . '/../src/helpers/securityhelper.class.inc.php';
|
|
||||||
require_once __DIR__ . '/../src/helpers/applicationhelper.class.inc.php';
|
|
||||||
|
|
||||||
use Combodo\iTop\Portal\Helper\ApplicationHelper;
|
|
||||||
use Silex\Application;
|
|
||||||
|
|
||||||
// Stacking context tag so it knows we are in the portal
|
|
||||||
$oContex = new ContextTag('GUI:Portal');
|
|
||||||
$oContex2 = new ContextTag('Portal:' . PORTAL_MODULE_ID);
|
|
||||||
|
|
||||||
// Checking if debug param is on
|
|
||||||
$bDebug = (isset($_REQUEST['debug']) && ($_REQUEST['debug'] === 'true') );
|
|
||||||
if($bDebug)
|
|
||||||
{
|
|
||||||
$oContexDebug = new ContextTag('debug');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initializing Silex framework
|
|
||||||
$oKPI = new ExecutionKPI();
|
|
||||||
$oApp = new Application();
|
|
||||||
|
|
||||||
// Registring optional silex components
|
|
||||||
$oApp->register(new Combodo\iTop\Portal\Provider\UrlGeneratorServiceProvider());
|
|
||||||
$oApp->register(new Combodo\iTop\Portal\Provider\ContextManipulatorServiceProvider());
|
|
||||||
$oApp->register(new Combodo\iTop\Portal\Provider\ScopeValidatorServiceProvider(), array(
|
|
||||||
'scope_validator.scopes_path' => utils::GetCachePath(),
|
|
||||||
'scope_validator.scopes_filename' => PORTAL_ID . '.scopes.php',
|
|
||||||
'scope_validator.instance_name' => PORTAL_ID
|
|
||||||
));
|
|
||||||
$oApp->register(new Combodo\iTop\Portal\Provider\LifecycleValidatorServiceProvider(), array(
|
|
||||||
'lifecycle_validator.lifecycle_path' => utils::GetCachePath(),
|
|
||||||
'lifecycle_validator.lifecycle_filename' => PORTAL_ID . '.lifecycle.php',
|
|
||||||
'lifecycle_validator.instance_name' => PORTAL_ID
|
|
||||||
));
|
|
||||||
$oApp->register(new Silex\Provider\TwigServiceProvider(), array(
|
|
||||||
'twig.path' => MODULESROOT,
|
|
||||||
'twig.options' => array(
|
|
||||||
'cache' => ($bDebug) ? false : utils::GetCachePath() . 'twig/',
|
|
||||||
)
|
|
||||||
));
|
|
||||||
$oApp->register(new Silex\Provider\HttpFragmentServiceProvider());
|
|
||||||
$oKPI->ComputeAndReport('Initialization of the Silex application');
|
|
||||||
|
|
||||||
$oApp->before(function(Symfony\Component\HttpFoundation\Request $oRequest, Silex\Application $oApp) use ($bDebug){
|
|
||||||
// User pre-checks
|
|
||||||
// Note: At this point the Exception handler is not registered, so we can't use $oApp::abort() method, hence the die().
|
|
||||||
// - Checking user rights and prompt if needed (401 HTTP code returned if XHR request)
|
|
||||||
$iExitMethod = ($oRequest->isXmlHttpRequest()) ? LoginWebPage::EXIT_RETURN : LoginWebPage::EXIT_PROMPT;
|
|
||||||
$iLogonRes = LoginWebPage::DoLoginEx(PORTAL_ID, false, $iExitMethod);
|
|
||||||
if( ($iExitMethod === LoginWebPage::EXIT_RETURN) && ($iLogonRes != 0) )
|
|
||||||
{
|
|
||||||
$oApp->abort(401);
|
|
||||||
}
|
|
||||||
// - User must be associated with a Contact
|
|
||||||
if (UserRights::GetContactId() == 0)
|
|
||||||
{
|
|
||||||
die(Dict::S('Portal:ErrorNoContactForThisUser'));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register request manipulator now that the request has been created.
|
|
||||||
$oApp->register(new Combodo\iTop\Portal\Provider\RequestManipulatorServiceProvider());
|
|
||||||
|
|
||||||
// Enable archived data
|
|
||||||
utils::InitArchiveMode();
|
|
||||||
|
|
||||||
// Enabling datalocalizer if needed
|
|
||||||
if (!defined('DISABLE_DATA_LOCALIZER_PORTAL'))
|
|
||||||
{
|
|
||||||
ApplicationContext::SetPluginProperty('QueryLocalizerPlugin', 'language_code', UserRights::GetUserLanguage());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configuring Silex application
|
|
||||||
$oApp['debug'] = $bDebug;
|
|
||||||
$oApp['combodo.current_environment'] = utils::GetCurrentEnvironment();
|
|
||||||
$oApp['combodo.absolute_url'] = utils::GetAbsoluteUrlAppRoot();
|
|
||||||
$oApp['combodo.modules.absolute_url'] = utils::GetAbsoluteUrlAppRoot() . 'env-' . utils::GetCurrentEnvironment();
|
|
||||||
$oApp['combodo.portal.base.absolute_url'] = utils::GetAbsoluteUrlAppRoot() . 'env-' . utils::GetCurrentEnvironment() . '/itop-portal-base/portal/web/';
|
|
||||||
$oApp['combodo.portal.base.absolute_path'] = MODULESROOT . '/itop-portal-base/portal/web/';
|
|
||||||
$oApp['combodo.portal.instance.absolute_url'] = utils::GetAbsoluteUrlAppRoot() . 'env-' . utils::GetCurrentEnvironment() . '/' . PORTAL_MODULE_ID . '/';
|
|
||||||
$oApp['combodo.portal.instance.id'] = PORTAL_MODULE_ID;
|
|
||||||
$oApp['combodo.portal.instance.conf'] = array();
|
|
||||||
$oApp['combodo.portal.instance.routes'] = array();
|
|
||||||
|
|
||||||
// Registering error/exception handler in order to transform php error to exception
|
|
||||||
ApplicationHelper::RegisterExceptionHandler($oApp);
|
|
||||||
|
|
||||||
// Preparing portal foundations (Can't use Silex autoload through composer as we don't follow PSR conventions -filenames, functions-)
|
|
||||||
$oKPI = new ExecutionKPI();
|
|
||||||
ApplicationHelper::LoadControllers();
|
|
||||||
ApplicationHelper::LoadRouters();
|
|
||||||
ApplicationHelper::RegisterRoutes($oApp);
|
|
||||||
ApplicationHelper::LoadBricks();
|
|
||||||
ApplicationHelper::LoadFormManagers();
|
|
||||||
ApplicationHelper::RegisterTwigExtensions($oApp['twig']);
|
|
||||||
$oKPI->ComputeAndReport('Loading portal files (routers, controllers, ...)');
|
|
||||||
|
|
||||||
// Loading portal configuration from the module design
|
|
||||||
$oKPI = new ExecutionKPI();
|
|
||||||
ApplicationHelper::LoadPortalConfiguration($oApp);
|
|
||||||
ApplicationHelper::LoadSessionMessages($oApp);
|
|
||||||
$oKPI->ComputeAndReport('Parsing portal configuration');
|
|
||||||
// Loading current user
|
|
||||||
ApplicationHelper::LoadCurrentUser($oApp);
|
|
||||||
|
|
||||||
// Checking that user is allowed this portal
|
|
||||||
$bAllowed = false;
|
|
||||||
foreach($oApp['combodo.portal.instance.conf']['portals'] as $aAllowedPortal)
|
|
||||||
{
|
|
||||||
if($aAllowedPortal['id'] === PORTAL_ID)
|
|
||||||
{
|
|
||||||
$bAllowed = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!$bAllowed)
|
|
||||||
{
|
|
||||||
$oApp->abort(404);
|
|
||||||
}
|
|
||||||
}, Application::EARLY_EVENT);
|
|
||||||
|
|
||||||
// Running application
|
|
||||||
$oKPI = new ExecutionKPI();
|
|
||||||
$oApp->run();
|
|
||||||
$oKPI->ComputeAndReport('Page execution and rendering');
|
|
||||||
|
|
||||||
// Logging trace and stats
|
|
||||||
DBSearch::RecordQueryTrace();
|
|
||||||
ExecutionKPI::ReportStats();
|
|
||||||
Reference in New Issue
Block a user