mirror of
https://github.com/SuiteCRM/SuiteCRM-Core.git
synced 2025-09-02 08:09:19 +08:00
Add legacy route kernel by passing
- Add legacy route checking to kernel - Bypass legacy routes, directly require index files - Add index file mapping for api
This commit is contained in:
parent
381059ef57
commit
c996cc33ce
8 changed files with 267 additions and 6 deletions
|
@ -19,6 +19,7 @@ services:
|
|||
$legacyAssetPaths: '%legacy.asset_paths%'
|
||||
$copyLegacyAssetPaths: '%legacy.copy_asset_paths%'
|
||||
$legacyApiPaths: '%legacy.api_paths%'
|
||||
$legacyApiPathFiles: '%legacy.api_path_files%'
|
||||
$exposedUserPreferences: '%legacy.exposed_user_preferences%'
|
||||
$userPreferencesKeyMap: '%legacy.user_preferences_key_map%'
|
||||
$themeImagePaths: '%themes.image_paths%'
|
||||
|
@ -223,6 +224,10 @@ services:
|
|||
arguments:
|
||||
- !tagged { tag: 'massupdate.definition.mapper' }
|
||||
|
||||
legacy.route.handler:
|
||||
alias: App\Routes\Service\LegacyRouteHandler
|
||||
public: true
|
||||
|
||||
App\Process\Service\ActionNameMapperInterface: '@App\Engine\LegacyHandler\ActionNameMapperHandler'
|
||||
App\Process\Service\BaseActionDefinitionProviderInterface: '@App\Process\Service\BaseActionDefinitionProvider'
|
||||
App\Process\Service\LegacyModuleNameResolverInterface: '@App\Process\Service\LegacyModuleNameResolver'
|
||||
|
|
|
@ -4,3 +4,33 @@ parameters:
|
|||
Api/V8: Api/index.php/V8
|
||||
Api: Api/index.php
|
||||
service/v4_1: service/v4_1
|
||||
|
||||
legacy.api_path_files:
|
||||
Api/access_token:
|
||||
file: index.php
|
||||
dir: Api
|
||||
Api/V8:
|
||||
file: index.php
|
||||
dir: Api
|
||||
Api:
|
||||
file: index.php
|
||||
dir: Api
|
||||
service/v4_1/rest.php:
|
||||
file: rest.php
|
||||
dir: service/v4_1
|
||||
service/v4_1/soap.php:
|
||||
file: soap.php
|
||||
dir: service/v4_1
|
||||
service/v4_1:
|
||||
file: rest.php
|
||||
dir: service/v4_1
|
||||
service/v4/rest.php:
|
||||
file: rest.php
|
||||
dir: service/v4
|
||||
service/v4/soap.php:
|
||||
file: soap.php
|
||||
dir: service/v4
|
||||
service/v4:
|
||||
file: rest.php
|
||||
dir: service/v4
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ use Symfony\Component\Config\Exception\LoaderLoadException;
|
|||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
use Symfony\Component\Config\Resource\FileResource;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
|
||||
use Symfony\Component\Routing\RouteCollectionBuilder;
|
||||
use function dirname;
|
||||
|
@ -112,4 +113,20 @@ class Kernel extends BaseKernel
|
|||
$routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS, '/', 'glob');
|
||||
$routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function getLegacyRoute(Request $request): array
|
||||
{
|
||||
$this->initializeBundles();
|
||||
$this->initializeContainer();
|
||||
|
||||
if ($this->container->has('legacy.route.handler')) {
|
||||
return $this->container->get('legacy.route.handler')->getLegacyRoute($request);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,15 +37,22 @@ class LegacyApiRedirectHandler extends LegacyRedirectHandler
|
|||
*/
|
||||
private $legacyApiPaths;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $legacyApiPathFiles;
|
||||
|
||||
/**
|
||||
* LegacyApiRedirectHandler constructor.
|
||||
* @param array $legacyApiPaths
|
||||
* @param String $legacyPath
|
||||
* @param array $legacyApiPathFiles
|
||||
*/
|
||||
public function __construct(array $legacyApiPaths, string $legacyPath)
|
||||
public function __construct(array $legacyApiPaths, string $legacyPath, array $legacyApiPathFiles)
|
||||
{
|
||||
parent::__construct($legacyPath);
|
||||
$this->legacyApiPaths = $legacyApiPaths;
|
||||
$this->legacyApiPathFiles = $legacyApiPathFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,4 +84,34 @@ class LegacyApiRedirectHandler extends LegacyRedirectHandler
|
|||
|
||||
return $legacyPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert given $request route
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function getIncludeFile(Request $request): array
|
||||
{
|
||||
|
||||
foreach ($this->legacyApiPathFiles as $path => $info) {
|
||||
if ($this->inPath($request, $path)) {
|
||||
|
||||
$base = $_SERVER['BASE'] ?? $_SERVER['REDIRECT_BASE'] ?? '';
|
||||
|
||||
$scriptName = $base . '/legacy/' . $info['dir'] . '/' . $info['file'];
|
||||
$requestUri = str_replace($base, $base . '/legacy', $_SERVER['REQUEST_URI']);
|
||||
|
||||
$info['script-name'] = $scriptName;
|
||||
$info['request-uri'] = $requestUri;
|
||||
|
||||
return $info;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'dir' => '',
|
||||
'file' => 'index.php'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,4 +83,21 @@ class LegacyNonViewActionRedirectHandler extends LegacyRedirectHandler
|
|||
|
||||
return !($isRegistered === true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if is legacy entry point
|
||||
*
|
||||
* @param Request $request
|
||||
* @return bool
|
||||
*/
|
||||
public function isLegacyEntryPoint(Request $request): bool
|
||||
{
|
||||
$isEntryPoint = false;
|
||||
|
||||
if (strpos($request->getUri(), 'entryPoint=') !== false) {
|
||||
$isEntryPoint = true;
|
||||
}
|
||||
|
||||
return $isEntryPoint;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,6 +76,28 @@ class LegacyRedirectHandler
|
|||
return $baseUrl . $queryString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert given $request route
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function getIncludeFile(Request $request): array
|
||||
{
|
||||
$baseUrl = $request->getPathInfo();
|
||||
|
||||
$baseUrl = substr($baseUrl, 1);
|
||||
|
||||
if (strpos($baseUrl, '.php') === false) {
|
||||
$baseUrl .= 'index.php';
|
||||
}
|
||||
|
||||
return [
|
||||
'dir' => '',
|
||||
'file' => $baseUrl
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if given request falls into one of the given $paths
|
||||
*
|
||||
|
|
112
core/backend/Routes/Service/LegacyRouteHandler.php
Normal file
112
core/backend/Routes/Service/LegacyRouteHandler.php
Normal file
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
/**
|
||||
* SuiteCRM is a customer relationship management program developed by SalesAgility Ltd.
|
||||
* Copyright (C) 2021 SalesAgility Ltd.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SALESAGILITY, SALESAGILITY DISCLAIMS THE
|
||||
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License
|
||||
* version 3, these Appropriate Legal Notices must retain the display of the
|
||||
* "Supercharged by SuiteCRM" logo. If the display of the logos is not reasonably
|
||||
* feasible for technical reasons, the Appropriate Legal Notices must display
|
||||
* the words "Supercharged by SuiteCRM".
|
||||
*/
|
||||
|
||||
namespace App\Routes\Service;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class LegacyRouteHandler
|
||||
{
|
||||
|
||||
/**
|
||||
* @var LegacyApiRedirectHandler
|
||||
*/
|
||||
private $legacyApiRedirectHandler;
|
||||
|
||||
/**
|
||||
* @var LegacyNonViewActionRedirectHandler
|
||||
*/
|
||||
private $legacyNonViewActionRedirectHandler;
|
||||
|
||||
/**
|
||||
* LegacyRedirectListener constructor.
|
||||
* @param LegacyApiRedirectHandler $legacyApiRedirectHandler
|
||||
* @param LegacyNonViewActionRedirectHandler $legacyNonViewActionRedirectHandler
|
||||
*/
|
||||
public function __construct(
|
||||
LegacyApiRedirectHandler $legacyApiRedirectHandler,
|
||||
LegacyNonViewActionRedirectHandler $legacyNonViewActionRedirectHandler
|
||||
) {
|
||||
$this->legacyApiRedirectHandler = $legacyApiRedirectHandler;
|
||||
$this->legacyNonViewActionRedirectHandler = $legacyNonViewActionRedirectHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-direct user
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function getLegacyRoute(Request $request): array
|
||||
{
|
||||
|
||||
if ($this->isLegacyEntryPoint($request)) {
|
||||
return $this->legacyNonViewActionRedirectHandler->getIncludeFile($request);
|
||||
}
|
||||
|
||||
if ($this->isLegacyApi($request)) {
|
||||
return $this->legacyApiRedirectHandler->getIncludeFile($request);
|
||||
}
|
||||
|
||||
|
||||
if ($this->isLegacyNonViewActionRoute($request)) {
|
||||
return $this->legacyNonViewActionRedirectHandler->getIncludeFile($request);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if it is legacy entry point
|
||||
* @param Request $request
|
||||
* @return bool
|
||||
*/
|
||||
protected function isLegacyEntryPoint(Request $request): bool
|
||||
{
|
||||
return $this->legacyNonViewActionRedirectHandler->isLegacyEntryPoint($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if it is legacy api request
|
||||
* @param Request $request
|
||||
* @return bool
|
||||
*/
|
||||
protected function isLegacyApi(Request $request): bool
|
||||
{
|
||||
return $this->legacyApiRedirectHandler->isApiRequest($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if it is legacy non view request
|
||||
* @param Request $request
|
||||
* @return bool
|
||||
*/
|
||||
protected function isLegacyNonViewActionRoute(Request $request): bool
|
||||
{
|
||||
return $this->legacyNonViewActionRedirectHandler->isMatch($request);
|
||||
}
|
||||
|
||||
}
|
|
@ -13,8 +13,10 @@ if ($_SERVER['APP_DEBUG']) {
|
|||
}
|
||||
|
||||
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
|
||||
Request::setTrustedProxies(explode(',', $trustedProxies),
|
||||
Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
|
||||
Request::setTrustedProxies(
|
||||
explode(',', $trustedProxies),
|
||||
Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST
|
||||
);
|
||||
}
|
||||
|
||||
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
|
||||
|
@ -26,6 +28,25 @@ require __DIR__ . '/../vendor/autoload.php';
|
|||
|
||||
$kernel = new Kernel($_SERVER['APP_ENV'], (bool)$_SERVER['APP_DEBUG']);
|
||||
$request = Request::createFromGlobals();
|
||||
$response = $kernel->handle($request);
|
||||
$response->send();
|
||||
$kernel->terminate($request, $response);
|
||||
|
||||
global $legacyRoute;
|
||||
|
||||
$legacyRoute = $kernel->getLegacyRoute($request);
|
||||
|
||||
if (!empty($legacyRoute)) {
|
||||
|
||||
$path = './legacy';
|
||||
if (!empty($legacyRoute['dir'])) {
|
||||
$path .= '/' . $legacyRoute['dir'];
|
||||
}
|
||||
|
||||
chdir($path);
|
||||
|
||||
/* @noinspection PhpIncludeInspection */
|
||||
require $legacyRoute['file'];
|
||||
|
||||
} else {
|
||||
$response = $kernel->handle($request);
|
||||
$response->send();
|
||||
$kernel->terminate($request, $response);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue