snapshot of https://github.com/espocrm/espocrm.git (master, 2026-09-18; blobs > 131072B omitted)
Some checks failed
Test / Test on PHP 8.3 (push) Failing after 5s
Test / Test on PHP 8.4 (push) Failing after 4s
Test / Test on PHP 8.5 (push) Failing after 3s
TypeScript static analysis / TypeScript check (push) Failing after 14s
Test Integration on MySQL / Test on PHP 8.3 (push) Failing after 2s
Test Integration on MySQL / Test on PHP 8.5 (push) Failing after 0s
Test Integration on PostgreSQL / Test on PHP 8.4 fix (push) Failing after 1s
Test Integration on PostgreSQL / Test on PHP 8.4 master (push) Failing after 1s

This commit is contained in:
upstream-mirror
2026-09-18 04:19:15 +05:00
commit 7cc7e6b4f3
10077 changed files with 900756 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program 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.
*
* 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 <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* 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 "EspoCRM" word.
************************************************************************/
namespace Espo\Core\EntryPoint;
use Espo\Core\Api\Request;
use Espo\Core\Api\Response;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\Error;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\NotFound;
/**
* An entry point to the application by `?entryPoint={entityPointName}` URI.
* Only GET requests are handled.
*/
interface EntryPoint
{
/**
* @throws Error
* @throws Forbidden
* @throws BadRequest
* @throws NotFound
*/
public function run(Request $request, Response $response): void;
}

View File

@@ -0,0 +1,134 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program 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.
*
* 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 <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* 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 "EspoCRM" word.
************************************************************************/
namespace Espo\Core\EntryPoint;
use Espo\Core\Exceptions\NotFound;
use Espo\Core\Api\Request;
use Espo\Core\Api\Response;
use Espo\Core\Exceptions\NotFoundSilent;
use Espo\Core\InjectableFactory;
use Espo\Core\Utils\ClassFinder;
use Espo\Core\Utils\Metadata;
/**
* Runs entry points.
*/
class EntryPointManager
{
public function __construct(
private InjectableFactory $injectableFactory,
private ClassFinder $classFinder,
private Metadata $metadata,
) {}
/**
* @throws NotFound
*/
public function checkAuthRequired(string $name): bool
{
$metaParams = $this->getMetaParams($name);
if ($metaParams->noAuth) {
return false;
}
$className = $this->getClassName($name);
if (!$className) {
throw new NotFoundSilent("Entry point '$name' not found.");
}
$noAuth = false;
if (isset($className::$noAuth)) {
$noAuth = $className::$noAuth;
}
if ($noAuth) {
return false;
}
// for backward compatibility
return $className::$authRequired ?? true;
}
/**
* @throws NotFound
*/
public function run(string $name, Request $request, Response $response): void
{
$className = $this->getClassName($name);
if (!$className) {
throw new NotFoundSilent("Entry point '$name' not found.");
}
$entryPoint = $this->injectableFactory->create($className);
$entryPoint->run($request, $response);
}
/**
* @return ?class-string<EntryPoint>
*/
private function getClassName(string $name): ?string
{
$metaParams = $this->getMetaParams($name);
if ($metaParams->className) {
return $metaParams->className;
}
/** @var ?class-string<EntryPoint> */
return $this->classFinder->find('EntryPoints', ucfirst($name));
}
public function getMetaParams(string $name): MetaParams
{
/**
* @var array{
* className?: ?class-string<EntryPoint>,
* notExposed?: bool,
* noAuth?: bool,
* allowedMethods?: ?string[],
* consumes?: ?string[]
* } $params
*/
$params = $this->metadata->get("app.entryPoints.$name") ?? [];
return new MetaParams(
className: $params['className'] ?? null,
notExposed: $params['notExposed'] ?? false,
noAuth: $params['noAuth'] ?? false,
allowedMethods: $params['allowedMethods'] ?? null,
consumes: $params['consumes'] ?? null,
);
}
}

View File

@@ -0,0 +1,49 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program 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.
*
* 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 <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* 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 "EspoCRM" word.
************************************************************************/
namespace Espo\Core\EntryPoint;
/**
* @since 10.1.0
*/
readonly class MetaParams
{
/**
* @param ?class-string<EntryPoint> $className
* @param ?string[] $allowedMethods
* @param ?string[] $consumes
*/
public function __construct(
public ?string $className = null,
public bool $notExposed = false,
public bool $noAuth = false,
public ?array $allowedMethods = null,
public ?array $consumes = null,
) {}
}

View File

@@ -0,0 +1,44 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program 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.
*
* 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 <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* 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 "EspoCRM" word.
************************************************************************/
namespace Espo\Core\EntryPoint;
use Espo\Core\Api\ResponseWrapper;
use Slim\ResponseEmitter;
/**
* @internal
*/
class OutputEmitter
{
public function emit(ResponseWrapper $response): void
{
(new ResponseEmitter())->emit($response->toPsr7());
}
}

View File

@@ -0,0 +1,41 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program 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.
*
* 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 <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* 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 "EspoCRM" word.
************************************************************************/
namespace Espo\Core\EntryPoint;
/**
* @since 10.1.0
*/
readonly class Params
{
public function __construct(
public ?string $name = null,
public bool $final = false,
) {}
}

View File

@@ -0,0 +1,48 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program 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.
*
* 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 <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* 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 "EspoCRM" word.
************************************************************************/
namespace Espo\Core\EntryPoint;
use Espo\Core\Api\RequestWrapper;
use Espo\Core\Utils\Route;
use Slim\Factory\ServerRequestCreatorFactory;
/**
* @internal
*/
class RequestFactory
{
public function create(): RequestWrapper
{
return new RequestWrapper(
ServerRequestCreatorFactory::create()->createServerRequestFromGlobals(),
Route::detectBasePath()
);
}
}

View File

@@ -0,0 +1,44 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program 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.
*
* 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 <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* 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 "EspoCRM" word.
************************************************************************/
namespace Espo\Core\EntryPoint;
use Espo\Core\Api\ResponseWrapper;
use Slim\Psr7\Response;
/**
* @internal
*/
class ResponseFactory
{
public function create(): ResponseWrapper
{
return new ResponseWrapper(new Response());
}
}

View File

@@ -0,0 +1,270 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program 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.
*
* 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 <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* 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 "EspoCRM" word.
************************************************************************/
namespace Espo\Core\EntryPoint;
use Espo\Core\Api\Method;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Application\Runner\Params as RunnerParams;
use Espo\Core\ApplicationUser;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\NotFound;
use Espo\Core\Portal\Application as PortalApplication;
use Espo\Core\Authentication\AuthenticationFactory;
use Espo\Core\Authentication\AuthToken\Manager as AuthTokenManager;
use Espo\Core\Api\ErrorOutput;
use Espo\Core\Api\RequestWrapper;
use Espo\Core\Api\ResponseWrapper;
use Espo\Core\Api\AuthBuilderFactory;
use Espo\Core\Portal\Utils\Url;
use Espo\Core\Utils\ClientManager;
use Espo\Core\ApplicationRunners\EntryPoint as EntryPointRunner;
use Exception;
/**
* Starts an entry point.
*/
class Starter
{
public function __construct(
private AuthenticationFactory $authenticationFactory,
private EntryPointManager $entryPointManager,
private ClientManager $clientManager,
private ApplicationUser $applicationUser,
private AuthTokenManager $authTokenManager,
private AuthBuilderFactory $authBuilderFactory,
private RequestFactory $requestFactory,
private ResponseFactory $responseFactory,
private ErrorOutput $errorOutput,
private OutputEmitter $outputEmitter,
) {}
/**
* @throws Forbidden
* @throws NotFound
*/
public function start(Params $params = new Params()): void
{
$request = $this->requestFactory->create();
$response = $this->responseFactory->create();
try {
$name = $this->getName($params, $request);
$this->checkStart($name, $params, $request);
} catch (BadRequest|Forbidden $e) {
$this->errorOutput->processWithBodyPrinting($request, $response, $e);
$this->outputEmitter->emit($response);
return;
}
/**
* @todo
* Consider supporting portal detection when it's run through the `portals/` directory.
* E.g. ChangePassword is not run through the portal unless the ID is set in ENV.
*/
$portalId = Url::getPortalIdFromEnv();
if ($portalId && !$params->final) {
$this->runThroughPortal($portalId, $name);
return;
}
try {
$authRequired = $this->entryPointManager->checkAuthRequired($name);
} catch (NotFound $e) {
$this->errorOutput->processWithBodyPrinting($request, $response, $e);
$this->outputEmitter->emit($response);
return;
}
if ($authRequired && !$params->final) {
$portalId = $this->detectPortalId($request);
if ($portalId) {
$this->runThroughPortal($portalId, $name);
return;
}
}
$this->processRequest(
entryPoint: $name,
request: $request,
response: $response,
authRequired: $authRequired,
);
$this->outputEmitter->emit($response);
}
private function processRequest(
string $entryPoint,
RequestWrapper $request,
ResponseWrapper $response,
bool $authRequired,
): void {
try {
$this->processRequestInternal(
entryPoint: $entryPoint,
request: $request,
response: $response,
authRequired: $authRequired,
);
} catch (Exception $exception) {
print_r($exception->getMessage());
$this->errorOutput->processWithBodyPrinting($request, $response, $exception);
}
}
/**
* @throws NotFound
* @throws BadRequest
*/
private function processRequestInternal(
string $entryPoint,
RequestWrapper $request,
ResponseWrapper $response,
bool $authRequired,
): void {
$authentication = $this->authenticationFactory->create();
$apiAuth = $this->authBuilderFactory->create()
->setAuthentication($authentication)
->setAuthRequired($authRequired)
->forEntryPoint()
->build();
$authResult = $apiAuth->process($request, $response);
if (!$authResult->isResolved()) {
return;
}
if ($authResult->isResolvedUseNoAuth()) {
$this->applicationUser->setupSystemUser();
}
ob_start();
$this->entryPointManager->run($entryPoint, $request, $response);
$contents = ob_get_clean();
if ($contents) {
$response->writeBody($contents);
}
}
private function detectPortalId(RequestWrapper $request): ?string
{
if ($request->hasQueryParam('portalId')) {
return $request->getQueryParam('portalId');
}
$token = $request->getCookieParam('auth-token');
if (!$token) {
return null;
}
$authToken = $this->authTokenManager->get($token);
return $authToken?->getPortalId();
}
/**
* @throws Forbidden
* @throws NotFound
*/
private function runThroughPortal(string $portalId, string $entryPoint): void
{
$app = new PortalApplication($portalId);
$clientManager = $app->getContainer()->getByClass(ClientManager::class);
$clientManager->setBasePath($this->clientManager->getBasePath());
$clientManager->setApiUrl('api/v1/portal-access/' . $portalId);
$clientManager->setApplicationId($portalId);
$params = RunnerParams::fromArray([
EntryPointRunner::PARAM_ENTRY_POINT => $entryPoint,
EntryPointRunner::PARAM_FINAL => true,
]);
$app->run(EntryPointRunner::class, $params);
}
/**
* @throws BadRequest
*/
private function getName(Params $params, RequestWrapper $request): string
{
$name = $params->name ?? $request->getQueryParam('entryPoint');
if (!$name) {
throw new BadRequest("No 'entryPoint' param.");
}
return $name;
}
/**
* @throws BadRequest
* @throws Forbidden
*/
private function checkStart(string $name, Params $params, RequestWrapper $request): void
{
$method = $request->getMethod();
$metaParams = $this->entryPointManager->getMetaParams($name);
if ($metaParams->notExposed && $params->name === null) {
throw new Forbidden("The entry point is not exposed.");
}
if ($metaParams->allowedMethods !== null) {
if (!in_array(strtolower($method), $metaParams->allowedMethods)) {
throw new BadRequest("Method '$method' is not allowed.");
}
} else if ($method !== Method::GET) {
throw new BadRequest("Only GET requests allowed for the entry point.");
}
if ($metaParams->consumes !== null && !in_array($request->getContentType(), $metaParams->consumes)) {
throw new BadRequest("Not allowed Content-Type.");
}
}
}

View File

@@ -0,0 +1,42 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program 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.
*
* 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 <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* 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 "EspoCRM" word.
************************************************************************/
namespace Espo\Core\EntryPoint\Traits;
/**
* Auth is not required for entry point.
* To be used with EntryPoint interface.
*/
trait NoAuth
{
/**
* @var bool
*/
public static $noAuth = true;
}