mirror of
https://github.com/nuxsmin/sysPass.git
synced 2026-03-06 16:36:59 +01:00
chore: Refactoring of Bootstrap class into an abstract class.
This allows to implement bootstrap classes for each module and simplifies the bootstrap code. Signed-off-by: Rubén D <nuxsmin@syspass.org>
This commit is contained in:
4
api.php
4
api.php
@@ -22,11 +22,11 @@
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use SP\Bootstrap;
|
||||
use SP\Core\Bootstrap\BootstrapApi;
|
||||
|
||||
const APP_ROOT = __DIR__;
|
||||
const APP_MODULE = 'api';
|
||||
|
||||
$dic = require APP_ROOT.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'Base.php';
|
||||
|
||||
Bootstrap::runApi($dic);
|
||||
BootstrapApi::run($dic);
|
||||
|
||||
@@ -30,9 +30,9 @@ use DI\NotFoundException;
|
||||
use Exception;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use SP\Bootstrap;
|
||||
use SP\Core\Acl\Acl;
|
||||
use SP\Core\Acl\ActionsInterface;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Core\Context\ContextBase;
|
||||
use SP\Core\Crypt\Vault;
|
||||
use SP\Core\Events\Event;
|
||||
@@ -81,7 +81,7 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
use JsonTrait, ItemTrait;
|
||||
|
||||
protected ?AccountService $accountService = null;
|
||||
protected ?ThemeIcons $icons = null;
|
||||
protected ?ThemeIcons $icons = null;
|
||||
|
||||
/**
|
||||
* Index action
|
||||
@@ -131,7 +131,7 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
);
|
||||
|
||||
return $this->returnJsonResponseData([
|
||||
'html' => $this->render()
|
||||
'html' => $this->render(),
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
processException($e);
|
||||
@@ -148,7 +148,7 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
/**
|
||||
* View action
|
||||
*
|
||||
* @param int $id Account's ID
|
||||
* @param int $id Account's ID
|
||||
*
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
@@ -171,11 +171,12 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
ActionsInterface::ACCOUNT_VIEW
|
||||
);
|
||||
|
||||
$this->view->assign('title',
|
||||
$this->view->assign(
|
||||
'title',
|
||||
[
|
||||
'class' => 'titleNormal',
|
||||
'name' => __('Account Details'),
|
||||
'icon' => $this->icons->getIconView()->getIcon()
|
||||
'name' => __('Account Details'),
|
||||
'icon' => $this->icons->getIconView()->getIcon(),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -212,7 +213,7 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
/**
|
||||
* View public link action
|
||||
*
|
||||
* @param string $hash Link's hash
|
||||
* @param string $hash Link's hash
|
||||
*
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
@@ -246,18 +247,21 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
$vault->getData($publicLinkService->getPublicLinkKey($publicLinkData->getHash())->getKey())
|
||||
);
|
||||
|
||||
$this->view->assign('title',
|
||||
$this->view->assign(
|
||||
'title',
|
||||
[
|
||||
'class' => 'titleNormal',
|
||||
'name' => __('Account Details'),
|
||||
'icon' => $this->icons->getIconView()->getIcon()
|
||||
'name' => __('Account Details'),
|
||||
'icon' => $this->icons->getIconView()->getIcon(),
|
||||
]
|
||||
);
|
||||
|
||||
$this->view->assign('isView', true);
|
||||
$this->view->assign('useImage',
|
||||
$this->view->assign(
|
||||
'useImage',
|
||||
$this->configData->isPublinksImageEnabled()
|
||||
|| $this->configData->isAccountPassToImage());
|
||||
|| $this->configData->isAccountPassToImage()
|
||||
);
|
||||
|
||||
if ($this->view->useImage) {
|
||||
$imageUtil = $this->dic->get(ImageUtil::class);
|
||||
@@ -278,14 +282,15 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
? '***'
|
||||
: $this->request->getClientAddress(true);
|
||||
|
||||
$baseUrl = ($this->configData->getApplicationUrl() ?: Bootstrap::$WEBURI) . Bootstrap::$SUBURI;
|
||||
$baseUrl = ($this->configData->getApplicationUrl() ?: BootstrapBase::$WEBURI).BootstrapBase::$SUBURI;
|
||||
|
||||
$deepLink = new Uri($baseUrl);
|
||||
$deepLink->addParam('r', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW) . '/' . $accountData->getId());
|
||||
$deepLink->addParam('r', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW).'/'.$accountData->getId());
|
||||
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'show.account.link',
|
||||
new Event($this, EventMessage::factory()
|
||||
new Event(
|
||||
$this, EventMessage::factory()
|
||||
->addDescription(__u('Link viewed'))
|
||||
->addDetail(__u('Account'), $accountData->getName())
|
||||
->addDetail(__u('Client'), $accountData->getClientName())
|
||||
@@ -294,7 +299,8 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
->addDetail(__u('IP'), $clientAddress)
|
||||
->addDetail(__u('Link'), $deepLink->getUriSigned($this->configData->getPasswordSalt()))
|
||||
->addExtra('userId', $publicLinkData->getUserId())
|
||||
->addExtra('notify', $publicLinkData->isNotify()))
|
||||
->addExtra('notify', $publicLinkData->isNotify())
|
||||
)
|
||||
);
|
||||
} else {
|
||||
ErrorUtil::showErrorInView(
|
||||
@@ -328,11 +334,12 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
$accountHelper->setViewForBlank(ActionsInterface::ACCOUNT_CREATE);
|
||||
|
||||
$this->view->addTemplate('account');
|
||||
$this->view->assign('title',
|
||||
$this->view->assign(
|
||||
'title',
|
||||
[
|
||||
'class' => 'titleGreen',
|
||||
'name' => __('New Account'),
|
||||
'icon' => $this->icons->getIconAdd()->getIcon()
|
||||
'name' => __('New Account'),
|
||||
'icon' => $this->icons->getIconAdd()->getIcon(),
|
||||
]
|
||||
);
|
||||
$this->view->assign('formRoute', 'account/saveCreate');
|
||||
@@ -363,7 +370,7 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
/**
|
||||
* Copy action
|
||||
*
|
||||
* @param int $id Account's ID
|
||||
* @param int $id Account's ID
|
||||
*
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
@@ -384,11 +391,12 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
);
|
||||
|
||||
$this->view->addTemplate('account');
|
||||
$this->view->assign('title',
|
||||
$this->view->assign(
|
||||
'title',
|
||||
[
|
||||
'class' => 'titleGreen',
|
||||
'name' => __('New Account'),
|
||||
'icon' => $this->icons->getIconAdd()->getIcon()
|
||||
'name' => __('New Account'),
|
||||
'icon' => $this->icons->getIconAdd()->getIcon(),
|
||||
]
|
||||
);
|
||||
$this->view->assign('formRoute', 'account/saveCopy');
|
||||
@@ -424,7 +432,7 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
/**
|
||||
* Edit action
|
||||
*
|
||||
* @param int $id Account's ID
|
||||
* @param int $id Account's ID
|
||||
*
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
@@ -445,11 +453,12 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
);
|
||||
|
||||
$this->view->addTemplate('account');
|
||||
$this->view->assign('title',
|
||||
$this->view->assign(
|
||||
'title',
|
||||
[
|
||||
'class' => 'titleOrange',
|
||||
'name' => __('Edit Account'),
|
||||
'icon' => $this->icons->getIconEdit()->getIcon()
|
||||
'name' => __('Edit Account'),
|
||||
'icon' => $this->icons->getIconEdit()->getIcon(),
|
||||
]
|
||||
);
|
||||
$this->view->assign('formRoute', 'account/saveEdit');
|
||||
@@ -487,7 +496,7 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
/**
|
||||
* Delete action
|
||||
*
|
||||
* @param int|null $id Account's ID
|
||||
* @param int|null $id Account's ID
|
||||
*
|
||||
*/
|
||||
public function deleteAction(?int $id = null): void
|
||||
@@ -505,11 +514,12 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
);
|
||||
|
||||
$this->view->addTemplate('account');
|
||||
$this->view->assign('title',
|
||||
$this->view->assign(
|
||||
'title',
|
||||
[
|
||||
'class' => 'titleRed',
|
||||
'name' => __('Remove Account'),
|
||||
'icon' => $this->icons->getIconDelete()->getIcon()
|
||||
'name' => __('Remove Account'),
|
||||
'icon' => $this->icons->getIconDelete()->getIcon(),
|
||||
]
|
||||
);
|
||||
$this->view->assign('formRoute', 'account/saveDelete');
|
||||
@@ -545,7 +555,7 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
/**
|
||||
* Obtener los datos para mostrar el interface para modificar la clave de cuenta
|
||||
*
|
||||
* @param int $id Account's ID
|
||||
* @param int $id Account's ID
|
||||
*
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
@@ -565,11 +575,12 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
);
|
||||
|
||||
$this->view->addTemplate('account-editpass');
|
||||
$this->view->assign('title',
|
||||
$this->view->assign(
|
||||
'title',
|
||||
[
|
||||
'class' => 'titleOrange',
|
||||
'name' => __('Edit Account Password'),
|
||||
'icon' => $this->icons->getIconEditPass()->getIcon()
|
||||
'name' => __('Edit Account Password'),
|
||||
'icon' => $this->icons->getIconEditPass()->getIcon(),
|
||||
]
|
||||
);
|
||||
$this->view->assign('formRoute', 'account/saveEditPass');
|
||||
@@ -609,7 +620,7 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
/**
|
||||
* Obtener los datos para mostrar el interface para ver cuenta en fecha concreta
|
||||
*
|
||||
* @param int $id Account's ID
|
||||
* @param int $id Account's ID
|
||||
*
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
@@ -628,11 +639,12 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
|
||||
$this->view->addTemplate('account-history');
|
||||
|
||||
$this->view->assign('title',
|
||||
$this->view->assign(
|
||||
'title',
|
||||
[
|
||||
'class' => 'titleNormal',
|
||||
'name' => __('Account Details'),
|
||||
'icon' => 'access_time'
|
||||
'name' => __('Account Details'),
|
||||
'icon' => 'access_time',
|
||||
]
|
||||
);
|
||||
|
||||
@@ -673,7 +685,7 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
/**
|
||||
* Obtener los datos para mostrar el interface de solicitud de cambios en una cuenta
|
||||
*
|
||||
* @param int $id Account's ID
|
||||
* @param int $id Account's ID
|
||||
*
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
@@ -726,8 +738,8 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
/**
|
||||
* Display account's password
|
||||
*
|
||||
* @param int $id Account's ID
|
||||
* @param int $parentId
|
||||
* @param int $id Account's ID
|
||||
* @param int $parentId
|
||||
*
|
||||
* @return bool
|
||||
* @throws \DI\DependencyException
|
||||
@@ -743,7 +755,7 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
|
||||
$passwordPreset = $this->getPasswordPreset();
|
||||
$useImage = $this->configData->isAccountPassToImage()
|
||||
|| ($passwordPreset !== null && $passwordPreset->isUseImage());
|
||||
|| ($passwordPreset !== null && $passwordPreset->isUseImage());
|
||||
|
||||
$this->view->assign('isLinked', $parentId > 0);
|
||||
|
||||
@@ -753,9 +765,11 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'show.account.pass',
|
||||
new Event($this, EventMessage::factory()
|
||||
new Event(
|
||||
$this, EventMessage::factory()
|
||||
->addDescription(__u('Password viewed'))
|
||||
->addDetail(__u('Account'), $account->getName()))
|
||||
->addDetail(__u('Account'), $account->getName())
|
||||
)
|
||||
);
|
||||
|
||||
return $this->returnJsonResponseData($data);
|
||||
@@ -794,7 +808,7 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
/**
|
||||
* Display account's password
|
||||
*
|
||||
* @param int $id Account's ID
|
||||
* @param int $id Account's ID
|
||||
*
|
||||
* @return bool
|
||||
* @throws \DI\DependencyException
|
||||
@@ -810,7 +824,7 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
|
||||
$passwordPreset = $this->getPasswordPreset();
|
||||
$useImage = $this->configData->isAccountPassToImage()
|
||||
|| ($passwordPreset !== null && $passwordPreset->isUseImage());
|
||||
|| ($passwordPreset !== null && $passwordPreset->isUseImage());
|
||||
|
||||
$this->view->assign('isLinked', 0);
|
||||
|
||||
@@ -818,9 +832,11 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'show.account.pass.history',
|
||||
new Event($this, EventMessage::factory()
|
||||
new Event(
|
||||
$this, EventMessage::factory()
|
||||
->addDescription(__u('Password viewed'))
|
||||
->addDetail(__u('Account'), $account->getName()))
|
||||
->addDetail(__u('Account'), $account->getName())
|
||||
)
|
||||
);
|
||||
|
||||
return $this->returnJsonResponseData($data);
|
||||
@@ -839,7 +855,7 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
/**
|
||||
* Copy account's password
|
||||
*
|
||||
* @param int $id Account's ID
|
||||
* @param int $id Account's ID
|
||||
*
|
||||
* @return bool
|
||||
* @throws Helpers\HelperException
|
||||
@@ -864,9 +880,11 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'copy.account.pass',
|
||||
new Event($this, EventMessage::factory()
|
||||
new Event(
|
||||
$this, EventMessage::factory()
|
||||
->addDescription(__u('Password copied'))
|
||||
->addDetail(__u('Account'), $account->getName()))
|
||||
->addDetail(__u('Account'), $account->getName())
|
||||
)
|
||||
);
|
||||
|
||||
return $this->returnJsonResponseData($data);
|
||||
@@ -875,7 +893,7 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
/**
|
||||
* Copy account's password
|
||||
*
|
||||
* @param int $id Account's ID
|
||||
* @param int $id Account's ID
|
||||
*
|
||||
* @return bool
|
||||
* @throws Helpers\HelperException
|
||||
@@ -900,9 +918,11 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'copy.account.pass.history',
|
||||
new Event($this, EventMessage::factory()
|
||||
new Event(
|
||||
$this, EventMessage::factory()
|
||||
->addDescription(__u('Password copied'))
|
||||
->addDetail(__u('Account'), $account->getName()))
|
||||
->addDetail(__u('Account'), $account->getName())
|
||||
)
|
||||
);
|
||||
|
||||
return $this->returnJsonResponseData($data);
|
||||
@@ -938,10 +958,12 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'create.account',
|
||||
new Event($this, EventMessage::factory()
|
||||
new Event(
|
||||
$this, EventMessage::factory()
|
||||
->addDescription(__u('Account created'))
|
||||
->addDetail(__u('Account'), $accountDetails->getName())
|
||||
->addDetail(__u('Client'), $accountDetails->getClientName()))
|
||||
->addDetail(__u('Client'), $accountDetails->getClientName())
|
||||
)
|
||||
);
|
||||
|
||||
$this->addCustomFieldsForItem(
|
||||
@@ -952,8 +974,8 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
|
||||
return $this->returnJsonResponseData(
|
||||
[
|
||||
'itemId' => $accountId,
|
||||
'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_EDIT)
|
||||
'itemId' => $accountId,
|
||||
'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_EDIT),
|
||||
],
|
||||
JsonResponse::JSON_SUCCESS,
|
||||
__u('Account created')
|
||||
@@ -975,7 +997,7 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
/**
|
||||
* Saves edit action
|
||||
*
|
||||
* @param int $id Account's ID
|
||||
* @param int $id Account's ID
|
||||
*
|
||||
* @return bool
|
||||
* @throws DependencyException
|
||||
@@ -998,10 +1020,12 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'edit.account',
|
||||
new Event($this, EventMessage::factory()
|
||||
new Event(
|
||||
$this, EventMessage::factory()
|
||||
->addDescription(__u('Account updated'))
|
||||
->addDetail(__u('Account'), $accountDetails->getName())
|
||||
->addDetail(__u('Client'), $accountDetails->getClientName()))
|
||||
->addDetail(__u('Client'), $accountDetails->getClientName())
|
||||
)
|
||||
);
|
||||
|
||||
$this->updateCustomFieldsForItem(
|
||||
@@ -1012,8 +1036,8 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
|
||||
return $this->returnJsonResponseData(
|
||||
[
|
||||
'itemId' => $id,
|
||||
'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW)
|
||||
'itemId' => $id,
|
||||
'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW),
|
||||
],
|
||||
JsonResponse::JSON_SUCCESS,
|
||||
__u('Account updated')
|
||||
@@ -1035,7 +1059,7 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
/**
|
||||
* Saves edit action
|
||||
*
|
||||
* @param int $id Account's ID
|
||||
* @param int $id Account's ID
|
||||
*
|
||||
* @return bool
|
||||
* @throws \DI\DependencyException
|
||||
@@ -1056,16 +1080,18 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'edit.account.pass',
|
||||
new Event($this, EventMessage::factory()
|
||||
new Event(
|
||||
$this, EventMessage::factory()
|
||||
->addDescription(__u('Password updated'))
|
||||
->addDetail(__u('Account'), $accountDetails->getName())
|
||||
->addDetail(__u('Client'), $accountDetails->getClientName()))
|
||||
->addDetail(__u('Client'), $accountDetails->getClientName())
|
||||
)
|
||||
);
|
||||
|
||||
return $this->returnJsonResponseData(
|
||||
[
|
||||
'itemId' => $id,
|
||||
'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW)
|
||||
'itemId' => $id,
|
||||
'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW),
|
||||
],
|
||||
JsonResponse::JSON_SUCCESS,
|
||||
__u('Password updated')
|
||||
@@ -1087,8 +1113,8 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
/**
|
||||
* Saves restore action
|
||||
*
|
||||
* @param int $historyId Account's history ID
|
||||
* @param int $id Account's ID
|
||||
* @param int $historyId Account's history ID
|
||||
* @param int $id Account's ID
|
||||
*
|
||||
* @return bool
|
||||
* @throws \DI\DependencyException
|
||||
@@ -1106,16 +1132,18 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'edit.account.restore',
|
||||
new Event($this, EventMessage::factory()
|
||||
new Event(
|
||||
$this, EventMessage::factory()
|
||||
->addDescription(__u('Account restored'))
|
||||
->addDetail(__u('Account'), $accountDetails->getName())
|
||||
->addDetail(__u('Client'), $accountDetails->getClientName()))
|
||||
->addDetail(__u('Client'), $accountDetails->getClientName())
|
||||
)
|
||||
);
|
||||
|
||||
return $this->returnJsonResponseData(
|
||||
[
|
||||
'itemId' => $id,
|
||||
'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW)
|
||||
'itemId' => $id,
|
||||
'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW),
|
||||
],
|
||||
JsonResponse::JSON_SUCCESS,
|
||||
__u('Account restored')
|
||||
@@ -1135,7 +1163,7 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
/**
|
||||
* Saves delete action
|
||||
*
|
||||
* @param int $id Account's ID
|
||||
* @param int $id Account's ID
|
||||
*
|
||||
* @return bool
|
||||
* @throws \DI\DependencyException
|
||||
@@ -1153,10 +1181,12 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'delete.account',
|
||||
new Event($this, EventMessage::factory()
|
||||
new Event(
|
||||
$this, EventMessage::factory()
|
||||
->addDescription(__u('Account removed'))
|
||||
->addDetail(__u('Account'), $accountDetails->getName())
|
||||
->addDetail(__u('Client'), $accountDetails->getClientName()))
|
||||
->addDetail(__u('Client'), $accountDetails->getClientName())
|
||||
)
|
||||
);
|
||||
|
||||
$this->deleteCustomFieldsForItem(ActionsInterface::ACCOUNT, $id);
|
||||
@@ -1180,7 +1210,7 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
/**
|
||||
* Saves a request action
|
||||
*
|
||||
* @param int $id Account's ID
|
||||
* @param int $id Account's ID
|
||||
*
|
||||
* @return bool
|
||||
* @throws \DI\DependencyException
|
||||
@@ -1198,19 +1228,24 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
|
||||
$accountDetails = $this->accountService->getById($id)->getAccountVData();
|
||||
|
||||
$baseUrl = ($this->configData->getApplicationUrl() ?: Bootstrap::$WEBURI) . Bootstrap::$SUBURI;
|
||||
$baseUrl = ($this->configData->getApplicationUrl() ?: BootstrapBase::$WEBURI).BootstrapBase::$SUBURI;
|
||||
|
||||
$deepLink = new Uri($baseUrl);
|
||||
$deepLink->addParam('r', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW) . '/' . $id);
|
||||
$deepLink->addParam('r', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW).'/'.$id);
|
||||
|
||||
$usersId = [$accountDetails->userId, $accountDetails->userEditId];
|
||||
|
||||
$userService = $this->dic->get(UserService::class);
|
||||
|
||||
$this->eventDispatcher->notifyEvent('request.account',
|
||||
new Event($this, EventMessage::factory()
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'request.account',
|
||||
new Event(
|
||||
$this, EventMessage::factory()
|
||||
->addDescription(__u('Request'))
|
||||
->addDetail(__u('Requester'), sprintf('%s (%s)', $this->userData->getName(), $this->userData->getLogin()))
|
||||
->addDetail(
|
||||
__u('Requester'),
|
||||
sprintf('%s (%s)', $this->userData->getName(), $this->userData->getLogin())
|
||||
)
|
||||
->addDetail(__u('Account'), $accountDetails->getName())
|
||||
->addDetail(__u('Client'), $accountDetails->getClientName())
|
||||
->addDetail(__u('Description'), $description)
|
||||
@@ -1218,18 +1253,22 @@ final class AccountController extends ControllerBase implements CrudControllerIn
|
||||
->addExtra('accountId', $id)
|
||||
->addExtra('whoId', $this->userData->getId())
|
||||
->setExtra('userId', $usersId)
|
||||
->setExtra('email', array_map(
|
||||
->setExtra(
|
||||
'email',
|
||||
array_map(
|
||||
static function ($value) {
|
||||
return $value->email;
|
||||
},
|
||||
$userService->getUserEmailById($usersId))
|
||||
))
|
||||
$userService->getUserEmailById($usersId)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return $this->returnJsonResponseData(
|
||||
[
|
||||
'itemId' => $id,
|
||||
'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT)
|
||||
'itemId' => $id,
|
||||
'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT),
|
||||
],
|
||||
JsonResponse::JSON_SUCCESS,
|
||||
__u('Request done')
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace SP\Modules\Web\Controllers;
|
||||
use DI\DependencyException;
|
||||
use DI\NotFoundException;
|
||||
use Exception;
|
||||
use SP\Bootstrap;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Core\Crypt\CryptPKI;
|
||||
use SP\Modules\Web\Controllers\Traits\JsonTrait;
|
||||
use SP\Plugin\PluginManager;
|
||||
@@ -54,29 +54,29 @@ final class BootstrapController extends SimpleControllerBase
|
||||
public function getEnvironmentAction(): bool
|
||||
{
|
||||
$checkStatus = $this->session->getAuthCompleted()
|
||||
&& ($this->session->getUserData()->getIsAdminApp()
|
||||
|| $this->configData->isDemoEnabled());
|
||||
&& ($this->session->getUserData()->getIsAdminApp()
|
||||
|| $this->configData->isDemoEnabled());
|
||||
|
||||
$data = [
|
||||
'lang' => $this->getJsLang(),
|
||||
'locale' => $this->configData->getSiteLang(),
|
||||
'app_root' => Bootstrap::$WEBURI,
|
||||
'max_file_size' => $this->configData->getFilesAllowedSize(),
|
||||
'check_updates' => $checkStatus && $this->configData->isCheckUpdates(),
|
||||
'check_notices' => $checkStatus && $this->configData->isCheckNotices(),
|
||||
'lang' => $this->getJsLang(),
|
||||
'locale' => $this->configData->getSiteLang(),
|
||||
'app_root' => BootstrapBase::$WEBURI,
|
||||
'max_file_size' => $this->configData->getFilesAllowedSize(),
|
||||
'check_updates' => $checkStatus && $this->configData->isCheckUpdates(),
|
||||
'check_notices' => $checkStatus && $this->configData->isCheckNotices(),
|
||||
'check_notifications' => $this->getNotificationsEnabled(),
|
||||
'timezone' => date_default_timezone_get(),
|
||||
'debug' => DEBUG || $this->configData->isDebug(),
|
||||
'cookies_enabled' => $this->getCookiesEnabled(),
|
||||
'plugins' => $this->getPlugins(),
|
||||
'loggedin' => $this->session->isLoggedIn(),
|
||||
'timezone' => date_default_timezone_get(),
|
||||
'debug' => DEBUG || $this->configData->isDebug(),
|
||||
'cookies_enabled' => $this->getCookiesEnabled(),
|
||||
'plugins' => $this->getPlugins(),
|
||||
'loggedin' => $this->session->isLoggedIn(),
|
||||
'authbasic_autologin' => $this->getAuthBasicAutologinEnabled(),
|
||||
'pki_key' => $this->getPublicKey(),
|
||||
'pki_max_size' => CryptPKI::getMaxDataSize(),
|
||||
'pki_key' => $this->getPublicKey(),
|
||||
'pki_max_size' => CryptPKI::getMaxDataSize(),
|
||||
'import_allowed_mime' => ImportService::ALLOWED_MIME,
|
||||
'files_allowed_mime' => $this->configData->getFilesAllowedMime(),
|
||||
'session_timeout' => $this->configData->getSessionTimeout(),
|
||||
'csrf' => $this->getCSRF()
|
||||
'files_allowed_mime' => $this->configData->getFilesAllowedMime(),
|
||||
'session_timeout' => $this->configData->getSessionTimeout(),
|
||||
'csrf' => $this->getCSRF(),
|
||||
];
|
||||
|
||||
return $this->returnJsonResponseData($data);
|
||||
@@ -87,7 +87,7 @@ final class BootstrapController extends SimpleControllerBase
|
||||
*/
|
||||
private function getJsLang(): array
|
||||
{
|
||||
return require RESOURCES_PATH . DIRECTORY_SEPARATOR . 'strings.js.inc';
|
||||
return require RESOURCES_PATH.DIRECTORY_SEPARATOR.'strings.js.inc';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,9 +111,9 @@ final class BootstrapController extends SimpleControllerBase
|
||||
private function getCookiesEnabled(): bool
|
||||
{
|
||||
return $this->router
|
||||
->request()
|
||||
->cookies()
|
||||
->get(session_name()) !== null;
|
||||
->request()
|
||||
->cookies()
|
||||
->get(session_name()) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,7 +138,7 @@ final class BootstrapController extends SimpleControllerBase
|
||||
private function getAuthBasicAutologinEnabled(): bool
|
||||
{
|
||||
return $this->dic->get(Browser::class)->getServerAuthUser() !== null
|
||||
&& $this->configData->isAuthBasicAutoLoginEnabled();
|
||||
&& $this->configData->isAuthBasicAutoLoginEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,10 +29,10 @@ defined('APP_ROOT') || die();
|
||||
use Exception;
|
||||
use Klein\Klein;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use SP\Bootstrap;
|
||||
use SP\Config\Config;
|
||||
use SP\Config\ConfigDataInterface;
|
||||
use SP\Core\Acl\Acl;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Core\Context\ContextInterface;
|
||||
use SP\Core\Crypt\Hash;
|
||||
use SP\Core\Events\EventDispatcher;
|
||||
@@ -97,7 +97,7 @@ abstract class ControllerBase
|
||||
LayoutHelper $layoutHelper
|
||||
) {
|
||||
// TODO: remove when controllers are ready
|
||||
$this->dic = Bootstrap::getContainer();
|
||||
$this->dic = BootstrapBase::getContainer();
|
||||
|
||||
$this->controllerName = $this->getControllerName();
|
||||
$this->configData = $config->getConfigData();
|
||||
|
||||
@@ -28,11 +28,11 @@ use DI\DependencyException;
|
||||
use DI\NotFoundException;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use SP\Bootstrap;
|
||||
use SP\Core\Acl\AccountPermissionException;
|
||||
use SP\Core\Acl\Acl;
|
||||
use SP\Core\Acl\ActionsInterface;
|
||||
use SP\Core\Acl\UnauthorizedPageException;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Core\Exceptions\ConstraintException;
|
||||
use SP\Core\Exceptions\QueryException;
|
||||
use SP\Core\Exceptions\SPException;
|
||||
@@ -70,21 +70,21 @@ final class AccountHelper extends HelperBase
|
||||
{
|
||||
use ItemTrait;
|
||||
|
||||
private ?Acl $acl = null;
|
||||
private ?AccountService $accountService = null;
|
||||
private ?Acl $acl = null;
|
||||
private ?AccountService $accountService = null;
|
||||
private ?AccountHistoryService $accountHistoryService = null;
|
||||
private ?PublicLinkService $publicLinkService = null;
|
||||
private ?ItemPresetService $itemPresetService = null;
|
||||
private ?int $actionId = null;
|
||||
private ?AccountAcl $accountAcl = null;
|
||||
private ?int $accountId = null;
|
||||
private bool $isView = false;
|
||||
private ?PublicLinkService $publicLinkService = null;
|
||||
private ?ItemPresetService $itemPresetService = null;
|
||||
private ?int $actionId = null;
|
||||
private ?AccountAcl $accountAcl = null;
|
||||
private ?int $accountId = null;
|
||||
private bool $isView = false;
|
||||
|
||||
/**
|
||||
* Sets account's view variables
|
||||
*
|
||||
* @param AccountDetailsResponse $accountDetailsResponse
|
||||
* @param int $actionId
|
||||
* @param AccountDetailsResponse $accountDetailsResponse
|
||||
* @param int $actionId
|
||||
*
|
||||
* @throws AccountPermissionException
|
||||
* @throws SPException
|
||||
@@ -95,9 +95,8 @@ final class AccountHelper extends HelperBase
|
||||
*/
|
||||
public function setViewForAccount(
|
||||
AccountDetailsResponse $accountDetailsResponse,
|
||||
int $actionId
|
||||
): void
|
||||
{
|
||||
int $actionId
|
||||
): void {
|
||||
$this->accountId = $accountDetailsResponse->getAccountVData()->getId();
|
||||
$this->actionId = $actionId;
|
||||
|
||||
@@ -152,38 +151,51 @@ final class AccountHelper extends HelperBase
|
||||
)
|
||||
);
|
||||
|
||||
$this->view->assign('otherUsersView',
|
||||
$this->view->assign(
|
||||
'otherUsersView',
|
||||
$selectUsers->getItemsFromModelSelected($usersView)
|
||||
);
|
||||
$this->view->assign('otherUsersEdit',
|
||||
$this->view->assign(
|
||||
'otherUsersEdit',
|
||||
$selectUsers->getItemsFromModelSelected($usersEdit)
|
||||
);
|
||||
$this->view->assign('otherUserGroupsView',
|
||||
$this->view->assign(
|
||||
'otherUserGroupsView',
|
||||
$selectUserGroups->getItemsFromModelSelected($userGroupsView)
|
||||
);
|
||||
$this->view->assign('otherUserGroupsEdit',
|
||||
$this->view->assign(
|
||||
'otherUserGroupsEdit',
|
||||
$selectUserGroups->getItemsFromModelSelected($userGroupsEdit)
|
||||
);
|
||||
$this->view->assign('users',
|
||||
$this->view->assign(
|
||||
'users',
|
||||
$selectUsers->getItemsFromModelSelected([$accountData->getUserId()])
|
||||
);
|
||||
$this->view->assign('userGroups',
|
||||
$this->view->assign(
|
||||
'userGroups',
|
||||
$selectUserGroups->getItemsFromModelSelected([$accountData->getUserGroupId()])
|
||||
);
|
||||
$this->view->assign('tags',
|
||||
$selectTags->getItemsFromModelSelected(SelectItemAdapter::getIdFromArrayOfObjects($accountDetailsResponse->getTags()))
|
||||
$this->view->assign(
|
||||
'tags',
|
||||
$selectTags->getItemsFromModelSelected(
|
||||
SelectItemAdapter::getIdFromArrayOfObjects($accountDetailsResponse->getTags())
|
||||
)
|
||||
);
|
||||
$this->view->assign('historyData',
|
||||
$this->view->assign(
|
||||
'historyData',
|
||||
SelectItemAdapter::factory($this->accountHistoryService->getHistoryForAccount($this->accountId))
|
||||
->getItemsFromArray()
|
||||
);
|
||||
$this->view->assign('isModified',
|
||||
$this->view->assign(
|
||||
'isModified',
|
||||
strtotime($accountData->getDateEdit()) !== false
|
||||
);
|
||||
$this->view->assign('maxFileSize',
|
||||
$this->view->assign(
|
||||
'maxFileSize',
|
||||
round($this->configData->getFilesAllowedSize() / 1024, 1)
|
||||
);
|
||||
$this->view->assign('filesAllowedExts',
|
||||
$this->view->assign(
|
||||
'filesAllowedExts',
|
||||
implode(',', $this->configData->getFilesAllowedExts())
|
||||
);
|
||||
|
||||
@@ -194,16 +206,19 @@ final class AccountHelper extends HelperBase
|
||||
$accountActionsDto->setPublicLinkCreatorId($publicLinkData->getUserId());
|
||||
|
||||
$baseUrl = ($this->configData->getApplicationUrl()
|
||||
?: Bootstrap::$WEBURI) . Bootstrap::$SUBURI;
|
||||
?: BootstrapBase::$WEBURI).BootstrapBase::$SUBURI;
|
||||
|
||||
$this->view->assign('publicLinkUrl',
|
||||
$this->view->assign(
|
||||
'publicLinkUrl',
|
||||
PublicLinkService::getLinkForHash(
|
||||
$baseUrl,
|
||||
$publicLinkData->getHash()
|
||||
)
|
||||
);
|
||||
$this->view->assign('publicLinkId',
|
||||
$publicLinkData->getId());
|
||||
$this->view->assign(
|
||||
'publicLinkId',
|
||||
$publicLinkData->getId()
|
||||
);
|
||||
} catch (NoSuchItemException $e) {
|
||||
$this->view->assign('publicLinkId', 0);
|
||||
$this->view->assign('publicLinkUrl', null);
|
||||
@@ -220,14 +235,14 @@ final class AccountHelper extends HelperBase
|
||||
$this->view->assign(
|
||||
'allowPrivate',
|
||||
($userProfileData->isAccPrivate()
|
||||
&& $accountData->getUserId() === $userData->getId())
|
||||
&& $accountData->getUserId() === $userData->getId())
|
||||
|| $userData->getIsAdminApp()
|
||||
);
|
||||
|
||||
$this->view->assign(
|
||||
'allowPrivateGroup',
|
||||
($userProfileData->isAccPrivateGroup()
|
||||
&& $accountData->getUserGroupId() === $userData->getUserGroupId())
|
||||
&& $accountData->getUserGroupId() === $userData->getUserGroupId())
|
||||
|| $userData->getIsAdminApp()
|
||||
);
|
||||
|
||||
@@ -294,7 +309,7 @@ final class AccountHelper extends HelperBase
|
||||
/**
|
||||
* Comprobar si el usuario dispone de acceso al módulo
|
||||
*
|
||||
* @param AccountDetailsResponse $accountDetailsResponse
|
||||
* @param AccountDetailsResponse $accountDetailsResponse
|
||||
*
|
||||
* @return AccountAcl
|
||||
* @throws AccountPermissionException
|
||||
@@ -335,7 +350,8 @@ final class AccountHelper extends HelperBase
|
||||
|
||||
$this->view->assign('accountIsHistory', false);
|
||||
|
||||
$this->view->assign('customFields',
|
||||
$this->view->assign(
|
||||
'customFields',
|
||||
$this->getCustomFieldsForItem(
|
||||
ActionsInterface::ACCOUNT,
|
||||
$this->accountId
|
||||
@@ -344,13 +360,17 @@ final class AccountHelper extends HelperBase
|
||||
|
||||
$this->view->assign(
|
||||
'categories',
|
||||
SelectItemAdapter::factory($this->dic->get(CategoryService::class)
|
||||
->getAllBasic())->getItemsFromModel()
|
||||
SelectItemAdapter::factory(
|
||||
$this->dic->get(CategoryService::class)
|
||||
->getAllBasic()
|
||||
)->getItemsFromModel()
|
||||
);
|
||||
$this->view->assign(
|
||||
'clients',
|
||||
SelectItemAdapter::factory($this->dic->get(ClientService::class)
|
||||
->getAllForUser())->getItemsFromModel()
|
||||
SelectItemAdapter::factory(
|
||||
$this->dic->get(ClientService::class)
|
||||
->getAllForUser()
|
||||
)->getItemsFromModel()
|
||||
);
|
||||
$this->view->assign(
|
||||
'mailRequestEnabled',
|
||||
@@ -428,7 +448,7 @@ final class AccountHelper extends HelperBase
|
||||
/**
|
||||
* Sets account's view for a blank form
|
||||
*
|
||||
* @param int $actionId
|
||||
* @param int $actionId
|
||||
*
|
||||
* @return void
|
||||
* @throws \DI\DependencyException
|
||||
@@ -460,13 +480,15 @@ final class AccountHelper extends HelperBase
|
||||
|
||||
$accountPrivate = new AccountPrivate();
|
||||
|
||||
if ($itemPresetPrivate = $this->itemPresetService->getForCurrentUser(ItemPresetInterface::ITEM_TYPE_ACCOUNT_PRIVATE)) {
|
||||
if ($itemPresetPrivate =
|
||||
$this->itemPresetService->getForCurrentUser(ItemPresetInterface::ITEM_TYPE_ACCOUNT_PRIVATE)) {
|
||||
$accountPrivate = $itemPresetPrivate->hydrate(AccountPrivate::class) ?: $accountPrivate;
|
||||
}
|
||||
|
||||
$accountPermission = new AccountPermission();
|
||||
|
||||
if ($itemPresetPermission = $this->itemPresetService->getForCurrentUser(ItemPresetInterface::ITEM_TYPE_ACCOUNT_PERMISSION)) {
|
||||
if ($itemPresetPermission =
|
||||
$this->itemPresetService->getForCurrentUser(ItemPresetInterface::ITEM_TYPE_ACCOUNT_PERMISSION)) {
|
||||
$accountPermission = $itemPresetPermission->hydrate(AccountPermission::class) ?: $accountPermission;
|
||||
}
|
||||
|
||||
@@ -539,8 +561,8 @@ final class AccountHelper extends HelperBase
|
||||
/**
|
||||
* Sets account's view variables
|
||||
*
|
||||
* @param AccountDetailsResponse $accountDetailsResponse
|
||||
* @param int $actionId
|
||||
* @param AccountDetailsResponse $accountDetailsResponse
|
||||
* @param int $actionId
|
||||
*
|
||||
* @return bool
|
||||
* @throws NoSuchItemException
|
||||
@@ -552,9 +574,8 @@ final class AccountHelper extends HelperBase
|
||||
*/
|
||||
public function setViewForRequest(
|
||||
AccountDetailsResponse $accountDetailsResponse,
|
||||
int $actionId
|
||||
): bool
|
||||
{
|
||||
int $actionId
|
||||
): bool {
|
||||
$this->accountId = $accountDetailsResponse->getAccountVData()->getId();
|
||||
$this->actionId = $actionId;
|
||||
$this->accountAcl = new AccountAcl($actionId);
|
||||
@@ -575,11 +596,13 @@ final class AccountHelper extends HelperBase
|
||||
$this->view->assign(
|
||||
'accountActions',
|
||||
$this->dic->get(AccountActionsHelper::class)
|
||||
->getActionsForAccount($this->accountAcl,
|
||||
->getActionsForAccount(
|
||||
$this->accountAcl,
|
||||
new AccountActionsDto(
|
||||
$this->accountId,
|
||||
null,
|
||||
$accountData->getParentId())
|
||||
$accountData->getParentId()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -587,7 +610,7 @@ final class AccountHelper extends HelperBase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $isView
|
||||
* @param bool $isView
|
||||
*/
|
||||
public function setIsView(bool $isView): void
|
||||
{
|
||||
|
||||
@@ -26,10 +26,10 @@ namespace SP\Modules\Web\Controllers\Helpers;
|
||||
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use SP\Bootstrap;
|
||||
use SP\Core\Acl\Acl;
|
||||
use SP\Core\Acl\ActionsInterface;
|
||||
use SP\Core\AppInfoInterface;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Core\Crypt\CryptPKI;
|
||||
use SP\Core\Exceptions\SPException;
|
||||
use SP\Core\Language;
|
||||
@@ -47,14 +47,14 @@ use SP\Util\VersionUtil;
|
||||
*/
|
||||
final class LayoutHelper extends HelperBase
|
||||
{
|
||||
protected ?bool $loggedIn = null;
|
||||
protected ?ThemeInterface $theme = null;
|
||||
protected ?bool $loggedIn = null;
|
||||
protected ?ThemeInterface $theme = null;
|
||||
|
||||
/**
|
||||
* Sets a full layout page
|
||||
*
|
||||
* @param string $page Page/view name
|
||||
* @param Acl|null $acl
|
||||
* @param string $page Page/view name
|
||||
* @param Acl|null $acl
|
||||
*
|
||||
* @return LayoutHelper
|
||||
*/
|
||||
@@ -90,7 +90,7 @@ final class LayoutHelper extends HelperBase
|
||||
*/
|
||||
public function initBody(): void
|
||||
{
|
||||
$baseUrl = $this->configData->getApplicationUrl() ?? Bootstrap::$WEBURI;
|
||||
$baseUrl = $this->configData->getApplicationUrl() ?? BootstrapBase::$WEBURI;
|
||||
|
||||
$this->view->assign('isInstalled', $this->configData->isInstalled());
|
||||
$this->view->assign('app_name', AppInfoInterface::APP_NAME);
|
||||
@@ -98,9 +98,9 @@ final class LayoutHelper extends HelperBase
|
||||
$this->view->assign('app_website_url', AppInfoInterface::APP_WEBSITE_URL);
|
||||
$this->view->assign('app_blog_url', AppInfoInterface::APP_BLOG_URL);
|
||||
$this->view->assign('app_version', Installer::VERSION_TEXT);
|
||||
$this->view->assign('logo_icon', $baseUrl . '/public/images/logo_icon.png');
|
||||
$this->view->assign('logo_no_bg_color', $baseUrl . '/public/images/logo_full_nobg_outline_color.png');
|
||||
$this->view->assign('logo_no_bg', $baseUrl . '/public/images/logo_full_nobg_outline.png');
|
||||
$this->view->assign('logo_icon', $baseUrl.'/public/images/logo_icon.png');
|
||||
$this->view->assign('logo_no_bg_color', $baseUrl.'/public/images/logo_full_nobg_outline_color.png');
|
||||
$this->view->assign('logo_no_bg', $baseUrl.'/public/images/logo_full_nobg_outline.png');
|
||||
$this->view->assign('httpsEnabled', $this->request->isHttps());
|
||||
$this->view->assign('homeRoute', Acl::getActionRoute(ActionsInterface::ACCOUNT));
|
||||
|
||||
@@ -128,7 +128,7 @@ final class LayoutHelper extends HelperBase
|
||||
protected function getResourcesLinks(): void
|
||||
{
|
||||
$version = VersionUtil::getVersionStringNormalized();
|
||||
$baseUrl = ($this->configData->getApplicationUrl() ?? Bootstrap::$WEBURI) . Bootstrap::$SUBURI;
|
||||
$baseUrl = ($this->configData->getApplicationUrl() ?? BootstrapBase::$WEBURI).BootstrapBase::$SUBURI;
|
||||
|
||||
$jsUri = new Uri($baseUrl);
|
||||
$jsUri->addParam('_r', 'resource/js');
|
||||
@@ -151,7 +151,7 @@ final class LayoutHelper extends HelperBase
|
||||
|
||||
if (isset($themeInfo['js'])) {
|
||||
$jsUri->resetParams()
|
||||
->addParam('b', $this->theme->getThemePath() . DIRECTORY_SEPARATOR . 'js')
|
||||
->addParam('b', $this->theme->getThemePath().DIRECTORY_SEPARATOR.'js')
|
||||
->addParam('f', implode(',', $themeInfo['js']));
|
||||
|
||||
$this->view->append(
|
||||
@@ -172,7 +172,7 @@ final class LayoutHelper extends HelperBase
|
||||
|
||||
$cssUri = (new Uri($baseUrl))
|
||||
->addParam('_r', 'resource/css')
|
||||
->addParam('_v', md5($version . $resultsAsCards));
|
||||
->addParam('_v', md5($version.$resultsAsCards));
|
||||
|
||||
$this->view->append(
|
||||
'cssLinks',
|
||||
@@ -189,7 +189,7 @@ final class LayoutHelper extends HelperBase
|
||||
}
|
||||
|
||||
$cssUri->resetParams()
|
||||
->addParam('b', $this->theme->getThemePath() . DIRECTORY_SEPARATOR . 'css')
|
||||
->addParam('b', $this->theme->getThemePath().DIRECTORY_SEPARATOR.'css')
|
||||
->addParam('f', implode(',', $themeInfo['css']));
|
||||
|
||||
$this->view->append(
|
||||
@@ -203,14 +203,14 @@ final class LayoutHelper extends HelperBase
|
||||
|
||||
foreach ($loadedPlugins as $plugin) {
|
||||
$base = str_replace(APP_ROOT, '', $plugin->getBase());
|
||||
$base .= DIRECTORY_SEPARATOR . 'public';
|
||||
$base .= DIRECTORY_SEPARATOR.'public';
|
||||
|
||||
$jsResources = $plugin->getJsResources();
|
||||
$cssResources = $plugin->getCssResources();
|
||||
|
||||
if (count($jsResources) > 0) {
|
||||
$jsUri->resetParams()
|
||||
->addParam('b', $base . DIRECTORY_SEPARATOR . 'js')
|
||||
->addParam('b', $base.DIRECTORY_SEPARATOR.'js')
|
||||
->addParam('f', implode(',', $jsResources));
|
||||
|
||||
$this->view->append(
|
||||
@@ -221,7 +221,7 @@ final class LayoutHelper extends HelperBase
|
||||
|
||||
if (count($cssResources) > 0) {
|
||||
$cssUri->resetParams()
|
||||
->addParam('b', $base . DIRECTORY_SEPARATOR . 'css')
|
||||
->addParam('b', $base.DIRECTORY_SEPARATOR.'css')
|
||||
->addParam('f', implode(',', $cssResources));
|
||||
|
||||
$this->view->append(
|
||||
@@ -283,7 +283,7 @@ final class LayoutHelper extends HelperBase
|
||||
/**
|
||||
* Obtener los datos para mostrar el menú de acciones
|
||||
*
|
||||
* @param Acl $acl
|
||||
* @param Acl $acl
|
||||
*/
|
||||
public function getMenu(Acl $acl): void
|
||||
{
|
||||
@@ -296,8 +296,8 @@ final class LayoutHelper extends HelperBase
|
||||
$actionSearch->setIcon($icons->getIconSearch());
|
||||
$actionSearch->setData([
|
||||
'historyReset' => 1,
|
||||
'view' => 'search',
|
||||
'route' => Acl::getActionRoute(ActionsInterface::ACCOUNT)
|
||||
'view' => 'search',
|
||||
'route' => Acl::getActionRoute(ActionsInterface::ACCOUNT),
|
||||
]);
|
||||
|
||||
$actions[] = $actionSearch;
|
||||
@@ -309,8 +309,8 @@ final class LayoutHelper extends HelperBase
|
||||
$actionNewAccount->setIcon($icons->getIconAdd());
|
||||
$actionNewAccount->setData([
|
||||
'historyReset' => 0,
|
||||
'view' => 'account',
|
||||
'route' => Acl::getActionRoute(ActionsInterface::ACCOUNT_CREATE)
|
||||
'view' => 'account',
|
||||
'route' => Acl::getActionRoute(ActionsInterface::ACCOUNT_CREATE),
|
||||
]);
|
||||
|
||||
$actions[] = $actionNewAccount;
|
||||
@@ -323,8 +323,8 @@ final class LayoutHelper extends HelperBase
|
||||
$actionAccessManager->setIcon($icons->getIconAccount());
|
||||
$actionAccessManager->setData([
|
||||
'historyReset' => 0,
|
||||
'view' => 'datatabs',
|
||||
'route' => Acl::getActionRoute(ActionsInterface::ACCESS_MANAGE)
|
||||
'view' => 'datatabs',
|
||||
'route' => Acl::getActionRoute(ActionsInterface::ACCESS_MANAGE),
|
||||
]);
|
||||
|
||||
$actions[] = $actionAccessManager;
|
||||
@@ -337,8 +337,8 @@ final class LayoutHelper extends HelperBase
|
||||
$actionItemManager->setIcon($icons->getIconGroup());
|
||||
$actionItemManager->setData([
|
||||
'historyReset' => 0,
|
||||
'view' => 'datatabs',
|
||||
'route' => Acl::getActionRoute(ActionsInterface::ITEMS_MANAGE)
|
||||
'view' => 'datatabs',
|
||||
'route' => Acl::getActionRoute(ActionsInterface::ITEMS_MANAGE),
|
||||
]);
|
||||
|
||||
$actions[] = $actionItemManager;
|
||||
@@ -351,8 +351,8 @@ final class LayoutHelper extends HelperBase
|
||||
$actionSecurityManager->setIcon($icons->getIconByName('security'));
|
||||
$actionSecurityManager->setData([
|
||||
'historyReset' => 0,
|
||||
'view' => 'datatabs',
|
||||
'route' => Acl::getActionRoute(ActionsInterface::SECURITY_MANAGE)
|
||||
'view' => 'datatabs',
|
||||
'route' => Acl::getActionRoute(ActionsInterface::SECURITY_MANAGE),
|
||||
]);
|
||||
|
||||
$actions[] = $actionSecurityManager;
|
||||
@@ -365,8 +365,8 @@ final class LayoutHelper extends HelperBase
|
||||
$actionPlugins->setIcon($icons->getIconByName('extension'));
|
||||
$actionPlugins->setData([
|
||||
'historyReset' => 1,
|
||||
'view' => 'plugin',
|
||||
'route' => Acl::getActionRoute(ActionsInterface::PLUGIN)
|
||||
'view' => 'plugin',
|
||||
'route' => Acl::getActionRoute(ActionsInterface::PLUGIN),
|
||||
]);
|
||||
|
||||
$actions[] = $actionPlugins;
|
||||
@@ -379,8 +379,8 @@ final class LayoutHelper extends HelperBase
|
||||
$actionConfigManager->setIcon($icons->getIconSettings());
|
||||
$actionConfigManager->setData([
|
||||
'historyReset' => 1,
|
||||
'view' => 'config',
|
||||
'route' => Acl::getActionRoute(ActionsInterface::CONFIG)
|
||||
'view' => 'config',
|
||||
'route' => Acl::getActionRoute(ActionsInterface::CONFIG),
|
||||
]);
|
||||
|
||||
$actions[] = $actionConfigManager;
|
||||
@@ -393,8 +393,8 @@ final class LayoutHelper extends HelperBase
|
||||
/**
|
||||
* Sets a full layout page
|
||||
*
|
||||
* @param string $template
|
||||
* @param string $page Page/view name
|
||||
* @param string $template
|
||||
* @param string $page Page/view name
|
||||
*
|
||||
* @return LayoutHelper
|
||||
*/
|
||||
@@ -413,16 +413,15 @@ final class LayoutHelper extends HelperBase
|
||||
/**
|
||||
* Sets a custom layout page
|
||||
*
|
||||
* @param string $template
|
||||
* @param string $page Page/view name
|
||||
* @param string $template
|
||||
* @param string $page Page/view name
|
||||
*
|
||||
* @return LayoutHelper
|
||||
*/
|
||||
public function getCustomLayout(
|
||||
string $template,
|
||||
string $page = ''
|
||||
): LayoutHelper
|
||||
{
|
||||
): LayoutHelper {
|
||||
$this->view->addTemplate('main', '_layouts');
|
||||
$this->view->addContentTemplate($template);
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ use Exception;
|
||||
use Klein\Klein;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use SP\Bootstrap;
|
||||
use SP\Config\Config;
|
||||
use SP\Core\Acl\Acl;
|
||||
use SP\Core\Context\ContextBase;
|
||||
|
||||
@@ -29,7 +29,6 @@ use DI\NotFoundException;
|
||||
use Exception;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use RuntimeException;
|
||||
use SP\Bootstrap;
|
||||
use SP\Core\Acl\Acl;
|
||||
use SP\Core\Acl\ActionsInterface;
|
||||
use SP\Core\Events\Event;
|
||||
@@ -160,7 +159,7 @@ final class PublicLinkController extends ControllerBase implements CrudControlle
|
||||
/**
|
||||
* Sets view data for displaying public link's data
|
||||
*
|
||||
* @param int|null $publicLinkId
|
||||
* @param int|null $publicLinkId
|
||||
*
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws SPException
|
||||
@@ -190,7 +189,7 @@ final class PublicLinkController extends ControllerBase implements CrudControlle
|
||||
);
|
||||
|
||||
if ($this->view->isView === true) {
|
||||
$baseUrl = ($this->configData->getApplicationUrl() ?: Bootstrap::$WEBURI) . Bootstrap::$SUBURI;
|
||||
$baseUrl = ($this->configData->getApplicationUrl() ?: Bootstrap::$WEBURI).Bootstrap::$SUBURI;
|
||||
|
||||
$this->view->assign(
|
||||
'publicLinkURL',
|
||||
@@ -207,7 +206,7 @@ final class PublicLinkController extends ControllerBase implements CrudControlle
|
||||
/**
|
||||
* Create action
|
||||
*
|
||||
* @param int $id
|
||||
* @param int $id
|
||||
*
|
||||
* @return bool
|
||||
* @throws \DI\DependencyException
|
||||
@@ -250,7 +249,7 @@ final class PublicLinkController extends ControllerBase implements CrudControlle
|
||||
/**
|
||||
* Edit action
|
||||
*
|
||||
* @param int $id
|
||||
* @param int $id
|
||||
*
|
||||
* @return bool
|
||||
* @throws DependencyException
|
||||
@@ -269,7 +268,7 @@ final class PublicLinkController extends ControllerBase implements CrudControlle
|
||||
|
||||
$this->view->assign('header', __('Edit Public Link'));
|
||||
$this->view->assign('isView', false);
|
||||
$this->view->assign('route', 'publicLink/saveEdit/' . $id);
|
||||
$this->view->assign('route', 'publicLink/saveEdit/'.$id);
|
||||
|
||||
$this->setViewData($id);
|
||||
|
||||
@@ -294,7 +293,7 @@ final class PublicLinkController extends ControllerBase implements CrudControlle
|
||||
/**
|
||||
* Delete action
|
||||
*
|
||||
* @param int|null $id
|
||||
* @param int|null $id
|
||||
*
|
||||
* @return bool
|
||||
* @throws DependencyException
|
||||
@@ -415,8 +414,8 @@ final class PublicLinkController extends ControllerBase implements CrudControlle
|
||||
/**
|
||||
* Saves create action
|
||||
*
|
||||
* @param int $accountId
|
||||
* @param int $notify
|
||||
* @param int $accountId
|
||||
* @param int $notify
|
||||
*
|
||||
* @return bool
|
||||
* @throws \DI\DependencyException
|
||||
@@ -465,7 +464,7 @@ final class PublicLinkController extends ControllerBase implements CrudControlle
|
||||
/**
|
||||
* Saves edit action
|
||||
*
|
||||
* @param int $id
|
||||
* @param int $id
|
||||
*/
|
||||
public function saveEditAction(int $id): void
|
||||
{
|
||||
@@ -475,7 +474,7 @@ final class PublicLinkController extends ControllerBase implements CrudControlle
|
||||
/**
|
||||
* View action
|
||||
*
|
||||
* @param int $id
|
||||
* @param int $id
|
||||
*
|
||||
* @return bool
|
||||
* @throws \DI\DependencyException
|
||||
|
||||
@@ -26,10 +26,10 @@ namespace SP\Modules\Web\Controllers;
|
||||
|
||||
use Klein\Klein;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use SP\Bootstrap;
|
||||
use SP\Config\Config;
|
||||
use SP\Core\Acl\Acl;
|
||||
use SP\Core\Acl\UnauthorizedPageException;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Core\Context\ContextInterface;
|
||||
use SP\Core\Events\EventDispatcher;
|
||||
use SP\Core\Exceptions\SessionTimeout;
|
||||
@@ -75,7 +75,7 @@ abstract class SimpleControllerBase
|
||||
PhpExtensionChecker $extensionChecker
|
||||
) {
|
||||
// TODO: remove when controllers are ready
|
||||
$this->dic = Bootstrap::getContainer();
|
||||
$this->dic = BootstrapBase::getContainer();
|
||||
|
||||
$this->controllerName = $this->getControllerName();
|
||||
$this->configData = $config->getConfigData();
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
namespace SP\Modules\Web\Controllers\Traits;
|
||||
|
||||
use Exception;
|
||||
use SP\Bootstrap;
|
||||
use SP\Config\Config;
|
||||
use SP\Config\ConfigDataInterface;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Http\JsonResponse;
|
||||
use SP\Util\Util;
|
||||
|
||||
@@ -49,10 +49,9 @@ trait ConfigTrait
|
||||
*/
|
||||
protected function saveConfig(
|
||||
ConfigDataInterface $configData,
|
||||
Config $config,
|
||||
callable $onSuccess = null
|
||||
): bool
|
||||
{
|
||||
Config $config,
|
||||
callable $onSuccess = null
|
||||
): bool {
|
||||
try {
|
||||
if ($configData->isDemoEnabled()) {
|
||||
return $this->returnJsonResponse(
|
||||
@@ -63,7 +62,7 @@ trait ConfigTrait
|
||||
|
||||
$config->saveConfig($configData);
|
||||
|
||||
if (Bootstrap::$LOCK !== false
|
||||
if (BootstrapBase::$LOCK !== false
|
||||
&& $configData->isMaintenance() === false) {
|
||||
Util::unlockApp();
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ namespace SP\Modules\Web;
|
||||
use Defuse\Crypto\Exception\CryptoException;
|
||||
use Exception;
|
||||
use Klein\Klein;
|
||||
use SP\Bootstrap;
|
||||
use SP\Core\Application;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Core\Context\ContextBase;
|
||||
use SP\Core\Context\SessionContext;
|
||||
use SP\Core\Crypt\CryptSessionHandler;
|
||||
@@ -271,7 +271,7 @@ final class Init extends HttpModuleBase
|
||||
private function initSession(bool $encrypt = false): void
|
||||
{
|
||||
if ($encrypt === true
|
||||
&& Bootstrap::$checkPhpVersion
|
||||
&& BootstrapBase::$checkPhpVersion
|
||||
&& ($key = $this->secureSessionService->getKey(UUIDCookie::factory($this->request))) !== false) {
|
||||
session_set_save_handler(new CryptSessionHandler($key), true);
|
||||
}
|
||||
|
||||
@@ -22,11 +22,11 @@
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use SP\Bootstrap;
|
||||
use SP\Core\Bootstrap\BootstrapWeb;
|
||||
|
||||
const APP_ROOT = __DIR__;
|
||||
const APP_MODULE = 'web';
|
||||
|
||||
$dic = require APP_ROOT.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'Base.php';
|
||||
|
||||
Bootstrap::runWeb($dic);
|
||||
BootstrapWeb::run($dic);
|
||||
|
||||
@@ -36,7 +36,6 @@ use SP\Core\UI\Theme;
|
||||
use SP\Core\UI\ThemeInterface;
|
||||
use SP\Http\Client;
|
||||
use SP\Http\Request;
|
||||
use SP\Providers\Auth\AuthProvider;
|
||||
use SP\Services\Account\AccountAclService;
|
||||
use SP\Services\Config\ConfigBackupService;
|
||||
use SP\Storage\Database\DatabaseConnectionData;
|
||||
@@ -96,5 +95,5 @@ return [
|
||||
AccountAclService::class => autowire(AccountAclService::class),
|
||||
\GuzzleHttp\Client::class => create(GuzzleHttp\Client::class)
|
||||
->constructor(factory([Client::class, 'getOptions'])),
|
||||
CSRF::class => autowire(CSRF::class)
|
||||
CSRF::class => autowire(CSRF::class),
|
||||
];
|
||||
134
lib/SP/Core/Bootstrap/BootstrapApi.php
Normal file
134
lib/SP/Core/Bootstrap/BootstrapApi.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
/*
|
||||
* sysPass
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
* sysPass is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* sysPass 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace SP\Core\Bootstrap;
|
||||
|
||||
use Closure;
|
||||
use Klein\Response;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use SP\Core\HttpModuleBase;
|
||||
use SP\Modules\Api\Init as InitApi;
|
||||
use SP\Services\Api\ApiRequest;
|
||||
use SP\Services\Api\JsonRpcResponse;
|
||||
|
||||
/**
|
||||
* Bootstrap API interface
|
||||
*/
|
||||
final class BootstrapApi extends BootstrapBase
|
||||
{
|
||||
|
||||
protected HttpModuleBase $module;
|
||||
|
||||
/**
|
||||
* @param \Psr\Container\ContainerInterface $container
|
||||
*
|
||||
* @return \SP\Core\Bootstrap\BootstrapApi
|
||||
*/
|
||||
public static function run(ContainerInterface $container): BootstrapApi
|
||||
{
|
||||
logger('------------');
|
||||
logger('Boostrap:api');
|
||||
|
||||
// TODO: remove
|
||||
self::$container = $container;
|
||||
|
||||
try {
|
||||
/** @noinspection SelfClassReferencingInspection */
|
||||
$bs = $container->get(BootstrapApi::class);
|
||||
$bs->module = $container->get(InitApi::class);
|
||||
$bs->handleRequest();
|
||||
|
||||
return $bs;
|
||||
} catch (NotFoundExceptionInterface|ContainerExceptionInterface $e) {
|
||||
processException($e);
|
||||
|
||||
die($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected function configureRouter(): void
|
||||
{
|
||||
// Manage requests for api module
|
||||
$this->router->respond(
|
||||
'POST',
|
||||
'@/api\.php',
|
||||
$this->manageApiRequest()
|
||||
);
|
||||
}
|
||||
|
||||
private function manageApiRequest(): Closure
|
||||
{
|
||||
return function ($request, $response, $service) {
|
||||
try {
|
||||
logger('API route');
|
||||
|
||||
$apiRequest = self::$container->get(ApiRequest::class);
|
||||
|
||||
[$controllerName, $action] = explode('/', $apiRequest->getMethod());
|
||||
|
||||
$controllerClass = self::getClassFor($controllerName);
|
||||
|
||||
$method = $action.'Action';
|
||||
|
||||
if (!method_exists($controllerClass, $method)) {
|
||||
logger($controllerClass.'::'.$method);
|
||||
|
||||
/** @var Response $response */
|
||||
$response->headers()
|
||||
->set(
|
||||
'Content-type',
|
||||
'application/json; charset=utf-8'
|
||||
);
|
||||
|
||||
return $response->body(
|
||||
JsonRpcResponse::getResponseError(
|
||||
self::OOPS_MESSAGE,
|
||||
JsonRpcResponse::METHOD_NOT_FOUND,
|
||||
$apiRequest->getId()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->initializeCommon();
|
||||
|
||||
$this->module->initialize($controllerName);
|
||||
|
||||
logger('Routing call: '.$controllerClass.'::'.$method);
|
||||
|
||||
return call_user_func([new $controllerClass(self::$container, $method), $method]);
|
||||
} catch (\Exception $e) {
|
||||
processException($e);
|
||||
|
||||
/** @var Response $response */
|
||||
$response->headers()->set('Content-type', 'application/json; charset=utf-8');
|
||||
|
||||
return $response->body(JsonRpcResponse::getResponseException($e, 0));
|
||||
} finally {
|
||||
$this->router->skipRemaining();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2021, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -22,31 +22,24 @@
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace SP;
|
||||
namespace SP\Core\Bootstrap;
|
||||
|
||||
use Closure;
|
||||
use Klein\Klein;
|
||||
use Klein\Response;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use RuntimeException;
|
||||
use SP\Config\ConfigDataInterface;
|
||||
use SP\Config\ConfigUtil;
|
||||
use SP\Core\Exceptions\InitializationException;
|
||||
use SP\Core\Exceptions\SessionTimeout;
|
||||
use SP\Core\Exceptions\SPException;
|
||||
use SP\Core\Language;
|
||||
use SP\Core\ModuleBase;
|
||||
use SP\Core\PhpExtensionChecker;
|
||||
use SP\Http\Request;
|
||||
use SP\Modules\Api\Init as InitApi;
|
||||
use SP\Modules\Web\Init as InitWeb;
|
||||
use SP\Plugin\PluginManager;
|
||||
use SP\Services\Api\ApiRequest;
|
||||
use SP\Services\Api\JsonRpcResponse;
|
||||
use SP\Services\Upgrade\UpgradeConfigService;
|
||||
use SP\Services\Upgrade\UpgradeUtil;
|
||||
use SP\Util\Checks;
|
||||
use SP\Util\Filter;
|
||||
use SP\Util\VersionUtil;
|
||||
use Symfony\Component\Debug\Debug;
|
||||
use Throwable;
|
||||
@@ -54,13 +47,13 @@ use Throwable;
|
||||
defined('APP_ROOT') || die();
|
||||
|
||||
/**
|
||||
* Class Bootstrap
|
||||
* Class BootstrapBase
|
||||
*
|
||||
* @package SP
|
||||
*/
|
||||
final class Bootstrap
|
||||
abstract class BootstrapBase
|
||||
{
|
||||
private const OOPS_MESSAGE = "Oops, it looks like this content does not exist...";
|
||||
protected const OOPS_MESSAGE = "Oops, it looks like this content does not exist...";
|
||||
/**
|
||||
* @var string The current request path relative to the sysPass root (e.g. files/index.php)
|
||||
*/
|
||||
@@ -73,18 +66,17 @@ final class Bootstrap
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
public static $LOCK;
|
||||
public static bool $checkPhpVersion = false;
|
||||
private static ContainerInterface $container;
|
||||
private Klein $router;
|
||||
private Request $request;
|
||||
private ConfigDataInterface $configData;
|
||||
private ModuleBase $module;
|
||||
public static $LOCK;
|
||||
public static bool $checkPhpVersion = false;
|
||||
protected static ContainerInterface $container;
|
||||
protected Klein $router;
|
||||
protected Request $request;
|
||||
protected ConfigDataInterface $configData;
|
||||
|
||||
/**
|
||||
* Bootstrap constructor.
|
||||
*/
|
||||
public function __construct(ConfigDataInterface $configData, Klein $router, Request $request)
|
||||
final public function __construct(ConfigDataInterface $configData, Klein $router, Request $request)
|
||||
{
|
||||
// Set the default language
|
||||
Language::setLocales('en_US');
|
||||
@@ -94,6 +86,7 @@ final class Bootstrap
|
||||
$this->request = $request;
|
||||
|
||||
$this->initRouter();
|
||||
$this->configureRouter();
|
||||
}
|
||||
|
||||
private function initRouter(): void
|
||||
@@ -126,7 +119,7 @@ final class Bootstrap
|
||||
};
|
||||
}
|
||||
|
||||
private function setCors(Response $response): void
|
||||
final protected function setCors(Response $response): void
|
||||
{
|
||||
$response->header(
|
||||
'Access-Control-Allow-Origin',
|
||||
@@ -140,132 +133,16 @@ final class Bootstrap
|
||||
$response->header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
||||
}
|
||||
|
||||
abstract protected function configureRouter(): void;
|
||||
|
||||
abstract public static function run(ContainerInterface $container): BootstrapBase;
|
||||
|
||||
public static function getContainer(): ContainerInterface
|
||||
{
|
||||
return self::$container;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Psr\Container\ContainerInterface $container
|
||||
*
|
||||
* @return \SP\Bootstrap
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*
|
||||
* TODO: Inject needed classes
|
||||
*/
|
||||
public static function runWeb(ContainerInterface $container): Bootstrap
|
||||
{
|
||||
logger('------------');
|
||||
logger('Boostrap:web');
|
||||
|
||||
// TODO: remove
|
||||
self::$container = $container;
|
||||
|
||||
/** @noinspection SelfClassReferencingInspection */
|
||||
$bs = $container->get(Bootstrap::class);
|
||||
$bs->module = $container->get(InitWeb::class);
|
||||
$bs->configureRouterForWeb();
|
||||
$bs->handleRequest();
|
||||
|
||||
return $bs;
|
||||
}
|
||||
|
||||
private function configureRouterForWeb(): void
|
||||
{
|
||||
// Manage requests for web module
|
||||
$this->router->respond(
|
||||
['GET', 'POST'],
|
||||
'@(?!/api\.php)',
|
||||
$this->manageWebRequest()
|
||||
);
|
||||
}
|
||||
|
||||
private function manageWebRequest(): Closure
|
||||
{
|
||||
return function ($request, $response, $service) {
|
||||
/** @var \Klein\Request $request */
|
||||
/** @var \Klein\Response $response */
|
||||
|
||||
try {
|
||||
logger('WEB route');
|
||||
|
||||
/** @var \Klein\Request $request */
|
||||
$route = Filter::getString($request->param('r', 'index/index'));
|
||||
|
||||
if (!preg_match_all(
|
||||
'#(?P<controller>[a-zA-Z]+)(?:/(?P<action>[a-zA-Z]+))?(?P<params>(/[a-zA-Z\d.]+)+)?#',
|
||||
$route,
|
||||
$matches
|
||||
)) {
|
||||
throw new RuntimeException(self::OOPS_MESSAGE);
|
||||
}
|
||||
|
||||
$controllerName = $matches['controller'][0];
|
||||
$methodName = empty($matches['action'][0])
|
||||
? 'indexAction'
|
||||
: $matches['action'][0].'Action';
|
||||
$methodParams = empty($matches['params'][0])
|
||||
? []
|
||||
: Filter::getArray(
|
||||
explode(
|
||||
'/',
|
||||
trim(
|
||||
$matches['params'][0],
|
||||
'/'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$controllerClass = self::getClassFor($controllerName);
|
||||
|
||||
$this->initializePluginClasses();
|
||||
|
||||
if (!method_exists($controllerClass, $methodName)) {
|
||||
logger($controllerClass.'::'.$methodName);
|
||||
|
||||
$response->code(404);
|
||||
|
||||
throw new RuntimeException(self::OOPS_MESSAGE);
|
||||
}
|
||||
|
||||
$this->setCors($response);
|
||||
|
||||
$this->initializeCommon();
|
||||
|
||||
// TODO: remove??
|
||||
if (APP_MODULE === 'web') {
|
||||
$this->module->initialize($controllerName);
|
||||
}
|
||||
|
||||
logger(
|
||||
sprintf(
|
||||
'Routing call: %s::%s::%s',
|
||||
$controllerClass,
|
||||
$methodName,
|
||||
print_r($methodParams, true)
|
||||
)
|
||||
);
|
||||
|
||||
$controller = self::$container->get($controllerClass);
|
||||
|
||||
return call_user_func_array([$controller, $methodName], $methodParams);
|
||||
} catch (SessionTimeout $sessionTimeout) {
|
||||
logger('Session timeout');
|
||||
} catch (\Exception $e) {
|
||||
processException($e);
|
||||
|
||||
/** @var Response $response */
|
||||
if ($response->status()->getCode() !== 404) {
|
||||
$response->code(503);
|
||||
}
|
||||
|
||||
return __($e->getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static function getClassFor(string $controllerName): string
|
||||
final protected static function getClassFor(string $controllerName): string
|
||||
{
|
||||
return sprintf(
|
||||
'SP\Modules\%s\Controllers\%sController',
|
||||
@@ -274,9 +151,14 @@ final class Bootstrap
|
||||
);
|
||||
}
|
||||
|
||||
protected function initializePluginClasses(): void
|
||||
/**
|
||||
* Handle the request through the router
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
final protected function handleRequest(): void
|
||||
{
|
||||
PluginManager::getPlugins();
|
||||
$this->router->dispatch($this->request->getRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -287,7 +169,7 @@ final class Bootstrap
|
||||
* @throws \SP\Core\Exceptions\InitializationException
|
||||
* @throws \SP\Services\Upgrade\UpgradeException
|
||||
*/
|
||||
protected function initializeCommon(): void
|
||||
final protected function initializeCommon(): void
|
||||
{
|
||||
logger(__FUNCTION__);
|
||||
|
||||
@@ -307,7 +189,7 @@ final class Bootstrap
|
||||
if (!self::$checkPhpVersion) {
|
||||
throw new InitializationException(
|
||||
sprintf(__('Required PHP version >= %s <= %s'), '7.4', '8.0'),
|
||||
Core\Exceptions\SPException::ERROR,
|
||||
SPException::ERROR,
|
||||
__u('Please update the PHP version to run sysPass')
|
||||
);
|
||||
}
|
||||
@@ -358,14 +240,14 @@ final class Bootstrap
|
||||
/**
|
||||
* Establecer el nivel de logging
|
||||
*/
|
||||
public function initPHPVars(): void
|
||||
final public function initPHPVars(): void
|
||||
{
|
||||
if (defined('DEBUG') && DEBUG) {
|
||||
/** @noinspection ForgottenDebugOutputInspection */
|
||||
Debug::enable();
|
||||
} elseif (!defined('DEBUG')
|
||||
&& ($this->router->request()->cookies()->get('XDEBUG_SESSION')
|
||||
|| $this->configData->isDebug())
|
||||
&& ($this->router->request()->cookies()->get('XDEBUG_SESSION')
|
||||
|| $this->configData->isDebug())
|
||||
) {
|
||||
define('DEBUG', true);
|
||||
|
||||
@@ -462,107 +344,8 @@ final class Bootstrap
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the request through the router
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function handleRequest(): void
|
||||
final protected function initializePluginClasses(): void
|
||||
{
|
||||
$this->router->dispatch($this->request->getRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Psr\Container\ContainerInterface $container
|
||||
*
|
||||
* @return \SP\Bootstrap
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*
|
||||
* TODO: Inject needed classes
|
||||
*/
|
||||
public static function runApi(ContainerInterface $container): Bootstrap
|
||||
{
|
||||
logger('------------');
|
||||
logger('Boostrap:api');
|
||||
|
||||
// TODO: remove
|
||||
self::$container = $container;
|
||||
|
||||
/** @noinspection SelfClassReferencingInspection */
|
||||
$bs = $container->get(Bootstrap::class);
|
||||
$bs->module = $container->get(InitApi::class);
|
||||
$bs->configureRouterForApi();
|
||||
$bs->handleRequest();
|
||||
|
||||
return $bs;
|
||||
}
|
||||
|
||||
private function configureRouterForApi(): void
|
||||
{
|
||||
// Manage requests for api module
|
||||
$this->router->respond(
|
||||
'POST',
|
||||
'@/api\.php',
|
||||
$this->manageApiRequest()
|
||||
);
|
||||
}
|
||||
|
||||
private function manageApiRequest(): Closure
|
||||
{
|
||||
return function ($request, $response, $service) {
|
||||
try {
|
||||
logger('API route');
|
||||
|
||||
$apiRequest = self::$container->get(ApiRequest::class);
|
||||
|
||||
[$controllerName, $action] = explode('/', $apiRequest->getMethod());
|
||||
|
||||
$controllerClass = self::getClassFor($controllerName);
|
||||
|
||||
$method = $action.'Action';
|
||||
|
||||
if (!method_exists($controllerClass, $method)) {
|
||||
logger($controllerClass.'::'.$method);
|
||||
|
||||
/** @var Response $response */
|
||||
$response->headers()
|
||||
->set(
|
||||
'Content-type',
|
||||
'application/json; charset=utf-8'
|
||||
);
|
||||
|
||||
return $response->body(
|
||||
JsonRpcResponse::getResponseError(
|
||||
self::OOPS_MESSAGE,
|
||||
JsonRpcResponse::METHOD_NOT_FOUND,
|
||||
$apiRequest->getId()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->initializeCommon();
|
||||
|
||||
$this->module->initialize($controllerName);
|
||||
|
||||
logger('Routing call: '.$controllerClass.'::'.$method);
|
||||
|
||||
return call_user_func([new $controllerClass(self::$container, $method), $method]);
|
||||
} catch (\Exception $e) {
|
||||
processException($e);
|
||||
|
||||
/** @var Response $response */
|
||||
$response->headers()->set('Content-type', 'application/json; charset=utf-8');
|
||||
|
||||
return $response->body(JsonRpcResponse::getResponseException($e, 0));
|
||||
} finally {
|
||||
$this->router->skipRemaining();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public function getRouter(): Klein
|
||||
{
|
||||
return $this->router;
|
||||
PluginManager::getPlugins();
|
||||
}
|
||||
}
|
||||
168
lib/SP/Core/Bootstrap/BootstrapWeb.php
Normal file
168
lib/SP/Core/Bootstrap/BootstrapWeb.php
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
/*
|
||||
* sysPass
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
* sysPass is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* sysPass 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace SP\Core\Bootstrap;
|
||||
|
||||
|
||||
use Closure;
|
||||
use Klein\Response;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use RuntimeException;
|
||||
use SP\Core\Exceptions\SessionTimeout;
|
||||
use SP\Core\HttpModuleBase;
|
||||
use SP\Modules\Web\Init as InitWeb;
|
||||
use SP\Util\Filter;
|
||||
|
||||
/**
|
||||
* Bootstrap web interface
|
||||
*/
|
||||
final class BootstrapWeb extends BootstrapBase
|
||||
{
|
||||
protected HttpModuleBase $module;
|
||||
|
||||
/**
|
||||
* @param \Psr\Container\ContainerInterface $container
|
||||
*
|
||||
* @return \SP\Core\Bootstrap\BootstrapWeb
|
||||
*
|
||||
* TODO: Inject needed classes
|
||||
*/
|
||||
public static function run(ContainerInterface $container): BootstrapWeb
|
||||
{
|
||||
logger('------------');
|
||||
logger('Boostrap:web');
|
||||
|
||||
// TODO: remove
|
||||
self::$container = $container;
|
||||
|
||||
try {
|
||||
/** @noinspection SelfClassReferencingInspection */
|
||||
$bs = $container->get(BootstrapWeb::class);
|
||||
$bs->module = $container->get(InitWeb::class);
|
||||
$bs->handleRequest();
|
||||
|
||||
return $bs;
|
||||
} catch (NotFoundExceptionInterface|ContainerExceptionInterface $e) {
|
||||
processException($e);
|
||||
|
||||
die($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected function configureRouter(): void
|
||||
{
|
||||
// Manage requests for web module
|
||||
$this->router->respond(
|
||||
['GET', 'POST'],
|
||||
'@(?!/api\.php)',
|
||||
$this->manageWebRequest()
|
||||
);
|
||||
}
|
||||
|
||||
private function manageWebRequest(): Closure
|
||||
{
|
||||
return function ($request, $response, $service) {
|
||||
/** @var \Klein\Request $request */
|
||||
/** @var \Klein\Response $response */
|
||||
|
||||
try {
|
||||
logger('WEB route');
|
||||
|
||||
/** @var \Klein\Request $request */
|
||||
$route = Filter::getString($request->param('r', 'index/index'));
|
||||
|
||||
if (!preg_match_all(
|
||||
'#(?P<controller>[a-zA-Z]+)(?:/(?P<action>[a-zA-Z]+))?(?P<params>(/[a-zA-Z\d.]+)+)?#',
|
||||
$route,
|
||||
$matches
|
||||
)) {
|
||||
throw new RuntimeException(self::OOPS_MESSAGE);
|
||||
}
|
||||
|
||||
$controllerName = $matches['controller'][0];
|
||||
$methodName = empty($matches['action'][0])
|
||||
? 'indexAction'
|
||||
: $matches['action'][0].'Action';
|
||||
$methodParams = empty($matches['params'][0])
|
||||
? []
|
||||
: Filter::getArray(
|
||||
explode(
|
||||
'/',
|
||||
trim(
|
||||
$matches['params'][0],
|
||||
'/'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$controllerClass = self::getClassFor($controllerName);
|
||||
|
||||
$this->initializePluginClasses();
|
||||
|
||||
if (!method_exists($controllerClass, $methodName)) {
|
||||
logger($controllerClass.'::'.$methodName);
|
||||
|
||||
$response->code(404);
|
||||
|
||||
throw new RuntimeException(self::OOPS_MESSAGE);
|
||||
}
|
||||
|
||||
$this->setCors($response);
|
||||
|
||||
$this->initializeCommon();
|
||||
|
||||
// TODO: remove??
|
||||
if (APP_MODULE === 'web') {
|
||||
$this->module->initialize($controllerName);
|
||||
}
|
||||
|
||||
logger(
|
||||
sprintf(
|
||||
'Routing call: %s::%s::%s',
|
||||
$controllerClass,
|
||||
$methodName,
|
||||
print_r($methodParams, true)
|
||||
)
|
||||
);
|
||||
|
||||
$controller = self::$container->get($controllerClass);
|
||||
|
||||
return call_user_func_array([$controller, $methodName], $methodParams);
|
||||
} catch (SessionTimeout $sessionTimeout) {
|
||||
logger('Session timeout');
|
||||
} catch (\Exception $e) {
|
||||
processException($e);
|
||||
|
||||
/** @var Response $response */
|
||||
if ($response->status()->getCode() !== 404) {
|
||||
$response->code(503);
|
||||
}
|
||||
|
||||
return __($e->getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace SP\Core\Crypt;
|
||||
|
||||
use SP\Bootstrap;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Http\Request;
|
||||
|
||||
/**
|
||||
@@ -106,6 +106,6 @@ abstract class Cookie
|
||||
return false;
|
||||
}
|
||||
|
||||
return setcookie($this->cookieName, $data, 0, Bootstrap::$WEBROOT);
|
||||
return setcookie($this->cookieName, $data, 0, BootstrapBase::$WEBROOT);
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,8 @@
|
||||
|
||||
namespace SP\Core\Crypt;
|
||||
|
||||
use SP\Bootstrap;
|
||||
use SP\Config\ConfigDataInterface;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Core\Exceptions\SPException;
|
||||
use SP\Util\Checks;
|
||||
|
||||
@@ -43,8 +43,8 @@ final class OldCrypt
|
||||
/**
|
||||
* Generar un hash de una clave utilizando un salt.
|
||||
*
|
||||
* @param string $pwd con la clave a 'hashear'
|
||||
* @param bool $prefixSalt Añadir el salt al hash
|
||||
* @param string $pwd con la clave a 'hashear'
|
||||
* @param bool $prefixSalt Añadir el salt al hash
|
||||
*
|
||||
* @return string con el hash de la clave
|
||||
*/
|
||||
@@ -53,21 +53,21 @@ final class OldCrypt
|
||||
$salt = self::makeHashSalt();
|
||||
$hash = crypt($pwd, $salt);
|
||||
|
||||
return ($prefixSalt === true) ? $salt . $hash : $hash;
|
||||
return ($prefixSalt === true) ? $salt.$hash : $hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Crear un salt utilizando mcrypt.
|
||||
*
|
||||
* @param string $salt
|
||||
* @param bool $random
|
||||
* @param string $salt
|
||||
* @param bool $random
|
||||
*
|
||||
* @return string con el salt creado
|
||||
*/
|
||||
public static function makeHashSalt($salt = null, $random = true)
|
||||
{
|
||||
/** @var ConfigDataInterface $ConfigData */
|
||||
$ConfigData = Bootstrap::getContainer()['configData'];
|
||||
$ConfigData = BootstrapBase::getContainer()['configData'];
|
||||
|
||||
if ($random === true) {
|
||||
$salt = bin2hex(self::getIV());
|
||||
@@ -77,7 +77,7 @@ final class OldCrypt
|
||||
$salt = $ConfigData->getPasswordSalt();
|
||||
}
|
||||
|
||||
return '$2y$07$' . substr($salt, 0, 22) . '$';
|
||||
return '$2y$07$'.substr($salt, 0, 22).'$';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,8 +118,8 @@ final class OldCrypt
|
||||
/**
|
||||
* Generar la clave maestra encriptada con una clave
|
||||
*
|
||||
* @param string $customPwd con la clave a encriptar
|
||||
* @param string $masterPwd con la clave maestra
|
||||
* @param string $customPwd con la clave a encriptar
|
||||
* @param string $masterPwd con la clave maestra
|
||||
*
|
||||
* @return array con la clave encriptada
|
||||
*/
|
||||
@@ -134,9 +134,9 @@ final class OldCrypt
|
||||
/**
|
||||
* Encriptar datos con la clave maestra.
|
||||
*
|
||||
* @param string $strValue con los datos a encriptar
|
||||
* @param string $strPassword con la clave maestra
|
||||
* @param string $cryptIV con el IV
|
||||
* @param string $strValue con los datos a encriptar
|
||||
* @param string $strPassword con la clave maestra
|
||||
* @param string $cryptIV con el IV
|
||||
*
|
||||
* @return string con los datos encriptados
|
||||
*/
|
||||
@@ -158,8 +158,8 @@ final class OldCrypt
|
||||
/**
|
||||
* Encriptar datos. Devuelve un array con los datos encriptados y el IV.
|
||||
*
|
||||
* @param mixed $data string Los datos a encriptar
|
||||
* @param string $pwd La clave de encriptación
|
||||
* @param mixed $data string Los datos a encriptar
|
||||
* @param string $pwd La clave de encriptación
|
||||
*
|
||||
* @return array
|
||||
* @throws SPException
|
||||
@@ -210,8 +210,8 @@ final class OldCrypt
|
||||
* Generar datos encriptados.
|
||||
* Esta función llama a los métodos privados para encriptar datos.
|
||||
*
|
||||
* @param string $data con los datos a encriptar
|
||||
* @param string $masterPwd con la clave maestra
|
||||
* @param string $data con los datos a encriptar
|
||||
* @param string $masterPwd con la clave maestra
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -225,9 +225,9 @@ final class OldCrypt
|
||||
/**
|
||||
* Desencriptar datos con la clave maestra.
|
||||
*
|
||||
* @param string $cryptData Los datos a desencriptar
|
||||
* @param string $cryptIV con el IV
|
||||
* @param string $password La clave maestra
|
||||
* @param string $cryptData Los datos a desencriptar
|
||||
* @param string $cryptIV con el IV
|
||||
* @param string $password La clave maestra
|
||||
*
|
||||
* @return string con los datos desencriptados
|
||||
*/
|
||||
@@ -250,8 +250,8 @@ final class OldCrypt
|
||||
/**
|
||||
* Generar una key para su uso con el algoritmo AES
|
||||
*
|
||||
* @param string $string La cadena de la que deriva la key
|
||||
* @param null $salt El salt utilizado
|
||||
* @param string $string La cadena de la que deriva la key
|
||||
* @param null $salt El salt utilizado
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace SP\Core;
|
||||
|
||||
use Klein\Klein;
|
||||
use SP\Bootstrap;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Http\Request;
|
||||
use SP\Util\Util;
|
||||
|
||||
@@ -58,13 +58,13 @@ abstract class HttpModuleBase extends ModuleBase
|
||||
protected function checkMaintenanceMode(): bool
|
||||
{
|
||||
if ($this->configData->isMaintenance()) {
|
||||
Bootstrap::$LOCK = Util::getAppLock();
|
||||
BootstrapBase::$LOCK = Util::getAppLock();
|
||||
|
||||
return !$this->request->isAjax()
|
||||
|| !(Bootstrap::$LOCK !== false
|
||||
&& Bootstrap::$LOCK->userId > 0
|
||||
|| !(BootstrapBase::$LOCK !== false
|
||||
&& BootstrapBase::$LOCK->userId > 0
|
||||
&& $this->context->isLoggedIn()
|
||||
&& Bootstrap::$LOCK->userId === $this->context->getUserData()->getId());
|
||||
&& BootstrapBase::$LOCK->userId === $this->context->getUserData()->getId());
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
|
||||
namespace SP\Core\UI;
|
||||
|
||||
use SP\Bootstrap;
|
||||
use SP\Config\Config;
|
||||
use SP\Config\ConfigDataInterface;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Core\Context\ContextBase;
|
||||
use SP\Core\Context\ContextInterface;
|
||||
use SP\Core\Exceptions\InvalidClassException;
|
||||
@@ -42,37 +42,36 @@ defined('APP_ROOT') || die();
|
||||
*/
|
||||
final class Theme implements ThemeInterface
|
||||
{
|
||||
public const ICONS_CACHE_FILE = CACHE_PATH . DIRECTORY_SEPARATOR . 'icons.cache';
|
||||
public const ICONS_CACHE_FILE = CACHE_PATH.DIRECTORY_SEPARATOR.'icons.cache';
|
||||
/**
|
||||
* Cache expire time
|
||||
*/
|
||||
public const CACHE_EXPIRE = 86400;
|
||||
private string $themeUri = '';
|
||||
private string $themePath = '';
|
||||
private string $themePathFull = '';
|
||||
private string $themeName = '';
|
||||
private string $viewsPath = '';
|
||||
private ?ThemeIcons $icons = null;
|
||||
private string $themeUri = '';
|
||||
private string $themePath = '';
|
||||
private string $themePathFull = '';
|
||||
private string $themeName = '';
|
||||
private string $viewsPath = '';
|
||||
private ?ThemeIcons $icons = null;
|
||||
private ConfigDataInterface $configData;
|
||||
private ContextInterface $context;
|
||||
private string $module;
|
||||
private FileCacheInterface $fileCache;
|
||||
private ContextInterface $context;
|
||||
private string $module;
|
||||
private FileCacheInterface $fileCache;
|
||||
|
||||
/**
|
||||
* Theme constructor.
|
||||
*
|
||||
* @param string $module
|
||||
* @param Config $config
|
||||
* @param ContextInterface $context
|
||||
* @param FileCacheInterface $fileCache
|
||||
* @param string $module
|
||||
* @param Config $config
|
||||
* @param ContextInterface $context
|
||||
* @param FileCacheInterface $fileCache
|
||||
*/
|
||||
public function __construct(
|
||||
string $module,
|
||||
Config $config,
|
||||
ContextInterface $context,
|
||||
string $module,
|
||||
Config $config,
|
||||
ContextInterface $context,
|
||||
FileCacheInterface $fileCache
|
||||
)
|
||||
{
|
||||
) {
|
||||
$this->configData = $config->getConfigData();
|
||||
$this->context = $context;
|
||||
$this->fileCache = $fileCache;
|
||||
@@ -82,7 +81,7 @@ final class Theme implements ThemeInterface
|
||||
/**
|
||||
* Inicializar el tema visual a utilizar
|
||||
*
|
||||
* @param bool $force Forzar la detección del tema para los inicios de sesión
|
||||
* @param bool $force Forzar la detección del tema para los inicios de sesión
|
||||
*
|
||||
* @throws InvalidClassException
|
||||
*/
|
||||
@@ -93,10 +92,10 @@ final class Theme implements ThemeInterface
|
||||
$this->themeName = $this->getUserTheme() ?: $this->getGlobalTheme();
|
||||
}
|
||||
|
||||
$this->themeUri = Bootstrap::$WEBURI . '/app/modules/' . $this->module . 'themes' . $this->themeName;
|
||||
$this->themePath = str_replace(APP_ROOT, '', VIEW_PATH) . DIRECTORY_SEPARATOR . $this->themeName;
|
||||
$this->themePathFull = VIEW_PATH . DIRECTORY_SEPARATOR . $this->themeName;
|
||||
$this->viewsPath = $this->themePathFull . DIRECTORY_SEPARATOR . 'views';
|
||||
$this->themeUri = BootstrapBase::$WEBURI.'/app/modules/'.$this->module.'themes'.$this->themeName;
|
||||
$this->themePath = str_replace(APP_ROOT, '', VIEW_PATH).DIRECTORY_SEPARATOR.$this->themeName;
|
||||
$this->themePathFull = VIEW_PATH.DIRECTORY_SEPARATOR.$this->themeName;
|
||||
$this->viewsPath = $this->themePathFull.DIRECTORY_SEPARATOR.'views';
|
||||
|
||||
$this->initIcons();
|
||||
}
|
||||
@@ -148,7 +147,7 @@ final class Theme implements ThemeInterface
|
||||
*/
|
||||
private function saveIcons(): void
|
||||
{
|
||||
$iconsClass = $this->themePathFull . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'Icons.php';
|
||||
$iconsClass = $this->themePathFull.DIRECTORY_SEPARATOR.'inc'.DIRECTORY_SEPARATOR.'Icons.php';
|
||||
|
||||
if (file_exists($iconsClass)) {
|
||||
if (!($this->icons = require $iconsClass) instanceof ThemeIcons) {
|
||||
@@ -176,7 +175,7 @@ final class Theme implements ThemeInterface
|
||||
|
||||
while (false !== ($themeDir = $themesDirs->read())) {
|
||||
if ($themeDir !== '.' && $themeDir !== '..') {
|
||||
$themeFile = VIEW_PATH . DIRECTORY_SEPARATOR . $themeDir . DIRECTORY_SEPARATOR . 'index.php';
|
||||
$themeFile = VIEW_PATH.DIRECTORY_SEPARATOR.$themeDir.DIRECTORY_SEPARATOR.'index.php';
|
||||
|
||||
if (file_exists($themeFile)) {
|
||||
$themeInfo = require $themeFile;
|
||||
@@ -204,7 +203,7 @@ final class Theme implements ThemeInterface
|
||||
*/
|
||||
public function getThemeInfo(): array
|
||||
{
|
||||
$themeFile = $this->themePathFull . DIRECTORY_SEPARATOR . 'index.php';
|
||||
$themeFile = $this->themePathFull.DIRECTORY_SEPARATOR.'index.php';
|
||||
|
||||
if (file_exists($themeFile)) {
|
||||
$themeInfo = include $themeFile;
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace SP\Http;
|
||||
use JsonException;
|
||||
use Klein\Klein;
|
||||
use Klein\Response;
|
||||
use SP\Bootstrap;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Core\Exceptions\SPException;
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ final class Json
|
||||
{
|
||||
public const SAFE = [
|
||||
'from' => ['\\', '"', '\''],
|
||||
'to' => ['\\', '\"', '\\\'']
|
||||
'to' => ['\\', '\"', '\\\''],
|
||||
];
|
||||
|
||||
private Response $response;
|
||||
@@ -63,9 +63,11 @@ final class Json
|
||||
*/
|
||||
public static function fromDic(): Json
|
||||
{
|
||||
return new self(Bootstrap::getContainer()
|
||||
->get(Klein::class)
|
||||
->response());
|
||||
return new self(
|
||||
BootstrapBase::getContainer()
|
||||
->get(Klein::class)
|
||||
->response()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,7 +116,7 @@ final class Json
|
||||
/**
|
||||
* Devuelve una respuesta en formato JSON
|
||||
*
|
||||
* @param string $data JSON string
|
||||
* @param string $data JSON string
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -151,8 +153,8 @@ final class Json
|
||||
/**
|
||||
* Devuelve una cadena en formato JSON
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param int $flags JSON_* flags
|
||||
* @param mixed $data
|
||||
* @param int $flags JSON_* flags
|
||||
*
|
||||
* @throws SPException
|
||||
*/
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace SP\Http;
|
||||
use Exception;
|
||||
use Klein\DataCollection\DataCollection;
|
||||
use Klein\DataCollection\HeaderDataCollection;
|
||||
use SP\Bootstrap;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Core\Crypt\CryptPKI;
|
||||
use SP\Core\Crypt\Hash;
|
||||
use SP\Core\Exceptions\SPException;
|
||||
@@ -47,10 +47,10 @@ final class Request
|
||||
public const SECURE_DIRS = ['css', 'js'];
|
||||
|
||||
private HeaderDataCollection $headers;
|
||||
private \Klein\Request $request;
|
||||
private DataCollection $params;
|
||||
private ?string $method = null;
|
||||
private ?bool $https = null;
|
||||
private \Klein\Request $request;
|
||||
private DataCollection $params;
|
||||
private ?string $method = null;
|
||||
private ?bool $https = null;
|
||||
|
||||
/**
|
||||
* Request constructor.
|
||||
@@ -82,17 +82,16 @@ final class Request
|
||||
private function detectHttps(): void
|
||||
{
|
||||
$this->https = Util::boolval($this->request->server()->get('HTTPS', 'off'))
|
||||
|| $this->request->server()->get('SERVER_PORT', 0) === 443;
|
||||
|| $this->request->server()->get('SERVER_PORT', 0) === 443;
|
||||
}
|
||||
|
||||
/**
|
||||
* Devuelve un nombre de archivo seguro
|
||||
*/
|
||||
public static function getSecureAppFile(
|
||||
string $file,
|
||||
string $file,
|
||||
?string $base = null
|
||||
): string
|
||||
{
|
||||
): string {
|
||||
return basename(self::getSecureAppPath($file, $base));
|
||||
}
|
||||
|
||||
@@ -100,17 +99,16 @@ final class Request
|
||||
* Devolver una ruta segura para
|
||||
*/
|
||||
public static function getSecureAppPath(
|
||||
string $path,
|
||||
string $path,
|
||||
?string $base = null
|
||||
): string
|
||||
{
|
||||
): string {
|
||||
if ($base === null) {
|
||||
$base = APP_ROOT;
|
||||
} elseif (!in_array(basename($base), self::SECURE_DIRS, true)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$realPath = realpath($base . DIRECTORY_SEPARATOR . $path);
|
||||
$realPath = realpath($base.DIRECTORY_SEPARATOR.$path);
|
||||
|
||||
if ($realPath === false
|
||||
|| strpos($realPath, $base) !== 0
|
||||
@@ -147,8 +145,8 @@ final class Request
|
||||
// Forwarded: for=12.34.56.78;host=example.com;proto=https, for=23.45.67.89
|
||||
$forwarded = $this->headers->get('HTTP_FORWARDED');
|
||||
|
||||
if ($forwarded !== null &&
|
||||
preg_match_all(
|
||||
if ($forwarded !== null
|
||||
&& preg_match_all(
|
||||
'/for="?\[?([\w.:]+)]?"?/',
|
||||
$forwarded,
|
||||
$matches
|
||||
@@ -190,10 +188,9 @@ final class Request
|
||||
}
|
||||
|
||||
public function analyzeEmail(
|
||||
string $param,
|
||||
string $param,
|
||||
?string $default = null
|
||||
): ?string
|
||||
{
|
||||
): ?string {
|
||||
if (!$this->params->exists($param)) {
|
||||
return $default;
|
||||
}
|
||||
@@ -214,7 +211,7 @@ final class Request
|
||||
|
||||
try {
|
||||
// Desencriptar con la clave RSA
|
||||
$clearData = Bootstrap::getContainer()->get(CryptPKI::class)
|
||||
$clearData = BootstrapBase::getContainer()->get(CryptPKI::class)
|
||||
->decryptRSA(base64_decode($encryptedData));
|
||||
|
||||
// Desencriptar con la clave RSA
|
||||
@@ -233,10 +230,9 @@ final class Request
|
||||
}
|
||||
|
||||
public function analyzeString(
|
||||
string $param,
|
||||
string $param,
|
||||
?string $default = null
|
||||
): ?string
|
||||
{
|
||||
): ?string {
|
||||
if (!$this->params->exists($param)) {
|
||||
return $default;
|
||||
}
|
||||
@@ -245,10 +241,9 @@ final class Request
|
||||
}
|
||||
|
||||
public function analyzeUnsafeString(
|
||||
string $param,
|
||||
string $param,
|
||||
?string $default = null
|
||||
): ?string
|
||||
{
|
||||
): ?string {
|
||||
if (!$this->params->exists($param)) {
|
||||
return $default;
|
||||
}
|
||||
@@ -257,17 +252,17 @@ final class Request
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $param
|
||||
* @param callable|null $mapper
|
||||
* @param null $default
|
||||
* @param string $param
|
||||
* @param callable|null $mapper
|
||||
* @param null $default
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function analyzeArray(
|
||||
string $param,
|
||||
string $param,
|
||||
callable $mapper = null,
|
||||
$default = null): ?array
|
||||
{
|
||||
$default = null
|
||||
): ?array {
|
||||
$requestValue = $this->params->get($param);
|
||||
|
||||
if (is_array($requestValue)) {
|
||||
@@ -295,7 +290,7 @@ final class Request
|
||||
public function isAjax(): bool
|
||||
{
|
||||
return $this->headers->get('X-Requested-With') === 'XMLHttpRequest'
|
||||
|| $this->analyzeInt('isAjax', 0) === 1;
|
||||
|| $this->analyzeInt('isAjax', 0) === 1;
|
||||
}
|
||||
|
||||
public function analyzeInt(string $param, ?int $default = null): ?int
|
||||
@@ -322,8 +317,8 @@ final class Request
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param string|null $param Checks the signature only for the given param
|
||||
* @param string $key
|
||||
* @param string|null $param Checks the signature only for the given param
|
||||
*
|
||||
* @throws SPException
|
||||
*/
|
||||
@@ -336,7 +331,7 @@ final class Request
|
||||
// Strips out the hash param from the URI to get the
|
||||
// route which will be checked against the computed HMAC
|
||||
if ($param === null) {
|
||||
$uri = str_replace('&h=' . $hash, '', $this->request->uri());
|
||||
$uri = str_replace('&h='.$hash, '', $this->request->uri());
|
||||
$uri = substr($uri, strpos($uri, '?') + 1);
|
||||
} else {
|
||||
$uri = $this->params->get($param, '');
|
||||
@@ -366,7 +361,7 @@ final class Request
|
||||
$forwarded = $this->getForwardedData() ?? $this->getXForwardedData();
|
||||
|
||||
if (null !== $forwarded) {
|
||||
return strtolower($forwarded['proto'] . '://' . $forwarded['host']);
|
||||
return strtolower($forwarded['proto'].'://'.$forwarded['host']);
|
||||
}
|
||||
|
||||
/** @noinspection HttpUrlsUsage */
|
||||
@@ -377,7 +372,7 @@ final class Request
|
||||
$protocol = 'https://';
|
||||
}
|
||||
|
||||
return $protocol . $this->request->server()->get('HTTP_HOST');
|
||||
return $protocol.$this->request->server()->get('HTTP_HOST');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -400,7 +395,7 @@ final class Request
|
||||
$data = [
|
||||
'host ' => $matches['host'][1] ?? null,
|
||||
'proto' => $matches['proto'][1] ?? null,
|
||||
'for' => $this->getForwardedFor()
|
||||
'for' => $this->getForwardedFor(),
|
||||
];
|
||||
|
||||
// Check if protocol and host are not empty
|
||||
@@ -430,7 +425,7 @@ final class Request
|
||||
$data = [
|
||||
'host' => trim(str_replace('"', '', $forwardedHost)),
|
||||
'proto' => trim(str_replace('"', '', $forwardedProto)),
|
||||
'for' => $this->getForwardedFor()
|
||||
'for' => $this->getForwardedFor(),
|
||||
];
|
||||
|
||||
// Check if protocol and host are not empty
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
namespace SP\Mvc\Controller;
|
||||
|
||||
use Closure;
|
||||
use SP\Bootstrap;
|
||||
use SP\Config\ConfigDataInterface;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Core\Exceptions\SPException;
|
||||
use SP\Http\Json;
|
||||
use SP\Http\JsonResponse;
|
||||
@@ -77,7 +77,7 @@ trait ControllerTrait
|
||||
$route = $request->analyzeString('r');
|
||||
$hash = $request->analyzeString('h');
|
||||
|
||||
$uri = new Uri(Bootstrap::$WEBROOT.Bootstrap::$SUBURI);
|
||||
$uri = new Uri(BootstrapBase::$WEBROOT.BootstrapBase::$SUBURI);
|
||||
$uri->addParam('_r', 'login');
|
||||
|
||||
if ($route && $hash) {
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace SP\Mvc\Controller;
|
||||
use Defuse\Crypto\Exception\CryptoException;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use SP\Bootstrap;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Core\Exceptions\SPException;
|
||||
use SP\DataModel\CustomFieldData;
|
||||
use SP\DataModel\ItemSearchData;
|
||||
@@ -53,7 +53,7 @@ trait ItemTrait
|
||||
*/
|
||||
protected function getCustomFieldsForItem(int $moduleId, ?int $itemId): array
|
||||
{
|
||||
$customFieldService = Bootstrap::getContainer()->get(CustomFieldService::class);
|
||||
$customFieldService = BootstrapBase::getContainer()->get(CustomFieldService::class);
|
||||
$customFields = [];
|
||||
|
||||
foreach ($customFieldService->getForModuleAndItemId($moduleId, $itemId) as $item) {
|
||||
@@ -93,9 +93,9 @@ trait ItemTrait
|
||||
/**
|
||||
* Añadir los campos personalizados del elemento
|
||||
*
|
||||
* @param int $moduleId
|
||||
* @param int|int[] $itemId
|
||||
* @param Request $request
|
||||
* @param int $moduleId
|
||||
* @param int|int[] $itemId
|
||||
* @param Request $request
|
||||
*
|
||||
* @throws \SP\Core\Exceptions\ConstraintException
|
||||
* @throws \SP\Core\Exceptions\QueryException
|
||||
@@ -104,10 +104,10 @@ trait ItemTrait
|
||||
* @throws \SP\Services\ServiceException
|
||||
*/
|
||||
protected function addCustomFieldsForItem(
|
||||
int $moduleId,
|
||||
$itemId,
|
||||
Request $request): void
|
||||
{
|
||||
int $moduleId,
|
||||
$itemId,
|
||||
Request $request
|
||||
): void {
|
||||
$customFields = $request->analyzeArray(
|
||||
'customfield',
|
||||
function ($values) {
|
||||
@@ -121,7 +121,7 @@ trait ItemTrait
|
||||
);
|
||||
|
||||
if (!empty($customFields)) {
|
||||
$customFieldService = Bootstrap::getContainer()->get(CustomFieldService::class);
|
||||
$customFieldService = BootstrapBase::getContainer()->get(CustomFieldService::class);
|
||||
|
||||
try {
|
||||
foreach ($customFields as $id => $value) {
|
||||
@@ -142,8 +142,8 @@ trait ItemTrait
|
||||
/**
|
||||
* Eliminar los campos personalizados del elemento
|
||||
*
|
||||
* @param int $moduleId
|
||||
* @param int|int[] $itemId
|
||||
* @param int $moduleId
|
||||
* @param int|int[] $itemId
|
||||
*
|
||||
* @throws SPException
|
||||
* @throws ContainerExceptionInterface
|
||||
@@ -151,7 +151,7 @@ trait ItemTrait
|
||||
*/
|
||||
protected function deleteCustomFieldsForItem(int $moduleId, $itemId): void
|
||||
{
|
||||
$customFieldService = Bootstrap::getContainer()->get(CustomFieldService::class);
|
||||
$customFieldService = BootstrapBase::getContainer()->get(CustomFieldService::class);
|
||||
|
||||
if (is_array($itemId)) {
|
||||
$customFieldService->deleteCustomFieldDataBatch($itemId, $moduleId);
|
||||
@@ -163,20 +163,19 @@ trait ItemTrait
|
||||
/**
|
||||
* Actualizar los campos personalizados del elemento
|
||||
*
|
||||
* @param int $moduleId
|
||||
* @param int|int[] $itemId
|
||||
* @param Request $request
|
||||
* @param int $moduleId
|
||||
* @param int|int[] $itemId
|
||||
* @param Request $request
|
||||
*
|
||||
* @throws \SP\Core\Exceptions\ConstraintException
|
||||
* @throws \SP\Core\Exceptions\QueryException
|
||||
* @throws \SP\Core\Exceptions\SPException
|
||||
*/
|
||||
protected function updateCustomFieldsForItem(
|
||||
int $moduleId,
|
||||
$itemId,
|
||||
int $moduleId,
|
||||
$itemId,
|
||||
Request $request
|
||||
): void
|
||||
{
|
||||
): void {
|
||||
$customFields = $request->analyzeArray(
|
||||
'customfield',
|
||||
function ($values) {
|
||||
@@ -190,7 +189,7 @@ trait ItemTrait
|
||||
);
|
||||
|
||||
if (!empty($customFields)) {
|
||||
$customFieldService = Bootstrap::getContainer()
|
||||
$customFieldService = BootstrapBase::getContainer()
|
||||
->get(CustomFieldService::class);
|
||||
|
||||
try {
|
||||
@@ -215,10 +214,9 @@ trait ItemTrait
|
||||
* Returns search data object for the current request
|
||||
*/
|
||||
protected function getSearchData(
|
||||
int $limitCount,
|
||||
int $limitCount,
|
||||
Request $request
|
||||
): ItemSearchData
|
||||
{
|
||||
): ItemSearchData {
|
||||
$itemSearchData = new ItemSearchData();
|
||||
$itemSearchData->setSeachString($request->analyzeString('search'));
|
||||
$itemSearchData->setLimitStart($request->analyzeInt('start', 0));
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace SP\Mvc\View;
|
||||
|
||||
defined('APP_ROOT') || die();
|
||||
|
||||
use SP\Bootstrap;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Core\Exceptions\FileNotFoundException;
|
||||
use SP\Core\UI\ThemeInterface;
|
||||
use SP\Http\Uri;
|
||||
@@ -43,24 +43,24 @@ use SP\Http\Uri;
|
||||
final class Template
|
||||
{
|
||||
public const TEMPLATE_EXTENSION = '.inc';
|
||||
public const PARTIALS_DIR = '_partials';
|
||||
public const LAYOUTS_DIR = '_layouts';
|
||||
public const PARTIALS_DIR = '_partials';
|
||||
public const LAYOUTS_DIR = '_layouts';
|
||||
|
||||
protected ThemeInterface $theme;
|
||||
/**
|
||||
* @var array List of templates to load into the view
|
||||
*/
|
||||
private array $templates = [];
|
||||
private array $templates = [];
|
||||
private TemplateVarCollection $vars;
|
||||
/**
|
||||
* @var string Base path for imcluding templates
|
||||
*/
|
||||
private string $base;
|
||||
private array $contentTemplates = [];
|
||||
private bool $upgraded = false;
|
||||
private array $contentTemplates = [];
|
||||
private bool $upgraded = false;
|
||||
|
||||
/**
|
||||
* @param ThemeInterface $theme
|
||||
* @param ThemeInterface $theme
|
||||
*/
|
||||
public function __construct(ThemeInterface $theme)
|
||||
{
|
||||
@@ -71,14 +71,13 @@ final class Template
|
||||
/**
|
||||
* Añadir una nueva plantilla al array de plantillas de la clase
|
||||
*
|
||||
* @param string $name Con el nombre del archivo de plantilla
|
||||
* @param string|null $base Directorio base para la plantilla
|
||||
* @param string $name Con el nombre del archivo de plantilla
|
||||
* @param string|null $base Directorio base para la plantilla
|
||||
*/
|
||||
public function addContentTemplate(
|
||||
string $name,
|
||||
string $name,
|
||||
?string $base = null
|
||||
): string
|
||||
{
|
||||
): string {
|
||||
try {
|
||||
$template = $this->checkTemplate($name, $base);
|
||||
$this->setContentTemplate($template, $name);
|
||||
@@ -92,28 +91,28 @@ final class Template
|
||||
/**
|
||||
* Comprobar si un archivo de plantilla existe y se puede leer
|
||||
*
|
||||
* @param string $template Con el nombre del archivo
|
||||
* @param string|null $base Directorio base para la plantilla
|
||||
* @param string $template Con el nombre del archivo
|
||||
* @param string|null $base Directorio base para la plantilla
|
||||
*
|
||||
* @return string La ruta al archivo de la plantilla
|
||||
*
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
private function checkTemplate(
|
||||
string $template,
|
||||
string $template,
|
||||
?string $base = null
|
||||
): string
|
||||
{
|
||||
): string {
|
||||
$base = $base ?? $this->base;
|
||||
|
||||
if ($base === null) {
|
||||
$templateFile = $this->theme->getViewsPath() . DIRECTORY_SEPARATOR . $template . self::TEMPLATE_EXTENSION;
|
||||
$templateFile = $this->theme->getViewsPath().DIRECTORY_SEPARATOR.$template.self::TEMPLATE_EXTENSION;
|
||||
} elseif (strpos($base, APP_ROOT) === 0
|
||||
&& is_dir($base)
|
||||
&& is_dir($base)
|
||||
) {
|
||||
$templateFile = $base . DIRECTORY_SEPARATOR . $template . self::TEMPLATE_EXTENSION;
|
||||
$templateFile = $base.DIRECTORY_SEPARATOR.$template.self::TEMPLATE_EXTENSION;
|
||||
} else {
|
||||
$templateFile = $this->theme->getViewsPath() . DIRECTORY_SEPARATOR . $base . DIRECTORY_SEPARATOR . $template . self::TEMPLATE_EXTENSION;
|
||||
$templateFile = $this->theme->getViewsPath().DIRECTORY_SEPARATOR.$base.DIRECTORY_SEPARATOR.$template
|
||||
.self::TEMPLATE_EXTENSION;
|
||||
}
|
||||
|
||||
if (!is_readable($templateFile)) {
|
||||
@@ -130,8 +129,8 @@ final class Template
|
||||
/**
|
||||
* Añadir un nuevo archivo de plantilla al array de plantillas de contenido
|
||||
*
|
||||
* @param string $file Con el nombre del archivo
|
||||
* @param string $name Nombre de la plantilla
|
||||
* @param string $file Con el nombre del archivo
|
||||
* @param string $name Nombre de la plantilla
|
||||
*/
|
||||
private function setContentTemplate(string $file, string $name): void
|
||||
{
|
||||
@@ -161,9 +160,9 @@ final class Template
|
||||
/**
|
||||
* Removes a template from the stack
|
||||
*
|
||||
* @param string $src Source template
|
||||
* @param string $dst Destination template
|
||||
* @param string $base
|
||||
* @param string $src Source template
|
||||
* @param string $dst Destination template
|
||||
* @param string $base
|
||||
*
|
||||
* @return mixed|string
|
||||
*/
|
||||
@@ -191,8 +190,8 @@ final class Template
|
||||
/**
|
||||
* Añadir una nueva plantilla al array de plantillas de la clase
|
||||
*
|
||||
* @param string $name Con el nombre del archivo de plantilla
|
||||
* @param string|null $base Directorio base para la plantilla
|
||||
* @param string $name Con el nombre del archivo de plantilla
|
||||
* @param string|null $base Directorio base para la plantilla
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -211,8 +210,8 @@ final class Template
|
||||
/**
|
||||
* Añadir un nuevo archivo de plantilla al array de plantillas
|
||||
*
|
||||
* @param string $file Con el nombre del archivo
|
||||
* @param string $name Nombre de la plantilla
|
||||
* @param string $file Con el nombre del archivo
|
||||
* @param string $name Nombre de la plantilla
|
||||
*/
|
||||
private function setTemplate(string $file, string $name): void
|
||||
{
|
||||
@@ -222,7 +221,7 @@ final class Template
|
||||
/**
|
||||
* Añadir una nueva plantilla dentro de una plantilla
|
||||
*
|
||||
* @param string $file Con el nombre del archivo de plantilla
|
||||
* @param string $file Con el nombre del archivo de plantilla
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -234,8 +233,8 @@ final class Template
|
||||
/**
|
||||
* Añadir una nueva plantilla dentro de una plantilla
|
||||
*
|
||||
* @param string $file Con el nombre del archivo de plantilla
|
||||
* @param string|null $base Directorio base para la plantilla
|
||||
* @param string $file Con el nombre del archivo de plantilla
|
||||
* @param string|null $base Directorio base para la plantilla
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -260,8 +259,8 @@ final class Template
|
||||
* Overloading para añadir nuevas variables en al array de variables dela plantilla
|
||||
* pasadas como atributos dinámicos de la clase
|
||||
*
|
||||
* @param string $name Nombre del atributo
|
||||
* @param string $value Valor del atributo
|
||||
* @param string $name Nombre del atributo
|
||||
* @param string $value Valor del atributo
|
||||
*/
|
||||
public function __set(string $name, string $value)
|
||||
{
|
||||
@@ -287,7 +286,7 @@ final class Template
|
||||
* Overloading para comprobar si el atributo solicitado está declarado como variable
|
||||
* en el array de variables de la plantilla.
|
||||
*
|
||||
* @param string $name Nombre del atributo
|
||||
* @param string $name Nombre del atributo
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -337,7 +336,7 @@ final class Template
|
||||
};
|
||||
|
||||
$_getRoute = static function ($path) use ($configData) {
|
||||
$baseUrl = ($configData->getApplicationUrl() ?: Bootstrap::$WEBURI) . Bootstrap::$SUBURI;
|
||||
$baseUrl = ($configData->getApplicationUrl() ?: BootstrapBase::$WEBURI).BootstrapBase::$SUBURI;
|
||||
|
||||
$uri = new Uri($baseUrl);
|
||||
$uri->addParam('r', $path);
|
||||
@@ -358,20 +357,19 @@ final class Template
|
||||
/**
|
||||
* Anexar el valor de la variable al array de la misma en el array de variables
|
||||
*
|
||||
* @param string $name nombre de la variable
|
||||
* @param mixed $value valor de la variable
|
||||
* @param string|null $scope string ámbito de la variable
|
||||
* @param int|null $index string índice del array
|
||||
* @param string $name nombre de la variable
|
||||
* @param mixed $value valor de la variable
|
||||
* @param string|null $scope string ámbito de la variable
|
||||
* @param int|null $index string índice del array
|
||||
*/
|
||||
public function append(
|
||||
string $name,
|
||||
$value,
|
||||
string $name,
|
||||
$value,
|
||||
?string $scope = null,
|
||||
int $index = null
|
||||
): void
|
||||
{
|
||||
int $index = null
|
||||
): void {
|
||||
if (null !== $scope) {
|
||||
$name = $scope . '_' . $name;
|
||||
$name = $scope.'_'.$name;
|
||||
}
|
||||
|
||||
$var = $this->vars->get($name, []);
|
||||
@@ -462,18 +460,17 @@ final class Template
|
||||
/**
|
||||
* Crear la variable y asignarle un valor en el array de variables
|
||||
*
|
||||
* @param string $name nombre de la variable
|
||||
* @param mixed $value valor de la variable
|
||||
* @param string|null $scope string ámbito de la variable
|
||||
* @param string $name nombre de la variable
|
||||
* @param mixed $value valor de la variable
|
||||
* @param string|null $scope string ámbito de la variable
|
||||
*/
|
||||
public function assign(
|
||||
string $name,
|
||||
$value = '',
|
||||
string $name,
|
||||
$value = '',
|
||||
?string $scope = null
|
||||
): void
|
||||
{
|
||||
): void {
|
||||
if (null !== $scope) {
|
||||
$name = $scope . '_' . $name;
|
||||
$name = $scope.'_'.$name;
|
||||
}
|
||||
|
||||
$this->vars->set($name, $value);
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace SP\Plugin;
|
||||
|
||||
use Exception;
|
||||
use ReflectionClass;
|
||||
use SP\Bootstrap;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Core\Events\Event;
|
||||
use SP\Core\Events\EventDispatcher;
|
||||
use SP\Core\Events\EventMessage;
|
||||
@@ -48,28 +48,28 @@ use SP\Util\VersionUtil;
|
||||
final class PluginManager
|
||||
{
|
||||
private static ?array $pluginsAvailable;
|
||||
private ?array $enabledPlugins = null;
|
||||
private ?array $enabledPlugins = null;
|
||||
/**
|
||||
* @var PluginInterface[] Plugins ya cargados
|
||||
*/
|
||||
private array $loadedPlugins = [];
|
||||
private array $disabledPlugins = [];
|
||||
private PluginService $pluginService;
|
||||
private EventDispatcher $eventDispatcher;
|
||||
private array $loadedPlugins = [];
|
||||
private array $disabledPlugins = [];
|
||||
private PluginService $pluginService;
|
||||
private EventDispatcher $eventDispatcher;
|
||||
private PluginDataService $pluginDataService;
|
||||
|
||||
/**
|
||||
* PluginManager constructor.
|
||||
*
|
||||
* @param PluginService $pluginService
|
||||
* @param PluginDataService $pluginDataService
|
||||
* @param EventDispatcher $eventDispatcher
|
||||
* @param PluginService $pluginService
|
||||
* @param PluginDataService $pluginDataService
|
||||
* @param EventDispatcher $eventDispatcher
|
||||
*/
|
||||
public function __construct(PluginService $pluginService,
|
||||
PluginDataService $pluginDataService,
|
||||
EventDispatcher $eventDispatcher
|
||||
)
|
||||
{
|
||||
public function __construct(
|
||||
PluginService $pluginService,
|
||||
PluginDataService $pluginDataService,
|
||||
EventDispatcher $eventDispatcher
|
||||
) {
|
||||
$this->pluginService = $pluginService;
|
||||
$this->pluginDataService = $pluginDataService;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
@@ -90,8 +90,8 @@ final class PluginManager
|
||||
&& ($dir = dir(PLUGINS_PATH))) {
|
||||
|
||||
while (false !== ($entry = $dir->read())) {
|
||||
$pluginDir = PLUGINS_PATH . DS . $entry;
|
||||
$pluginFile = $pluginDir . DS . 'src' . DS . 'lib' . DS . 'Plugin.php';
|
||||
$pluginDir = PLUGINS_PATH.DS.$entry;
|
||||
$pluginFile = $pluginDir.DS.'src'.DS.'lib'.DS.'Plugin.php';
|
||||
|
||||
if (strpos($entry, '.') === false
|
||||
&& is_dir($pluginDir)
|
||||
@@ -99,7 +99,7 @@ final class PluginManager
|
||||
) {
|
||||
logger(sprintf('Plugin found: %s', $pluginDir));
|
||||
|
||||
$plugins[$entry] = require $pluginDir . DS . 'base.php';
|
||||
$plugins[$entry] = require $pluginDir.DS.'base.php';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,8 +112,8 @@ final class PluginManager
|
||||
/**
|
||||
* Obtener la información de un plugin
|
||||
*
|
||||
* @param string $name Nombre del plugin
|
||||
* @param bool $initialize
|
||||
* @param string $name Nombre del plugin
|
||||
* @param bool $initialize
|
||||
*
|
||||
* @return PluginInterface
|
||||
*/
|
||||
@@ -139,8 +139,8 @@ final class PluginManager
|
||||
/**
|
||||
* Cargar un plugin
|
||||
*
|
||||
* @param string $name Nombre del plugin
|
||||
* @param string $namespace
|
||||
* @param string $name Nombre del plugin
|
||||
* @param string $namespace
|
||||
*
|
||||
* @return PluginInterface
|
||||
*/
|
||||
@@ -153,21 +153,26 @@ final class PluginManager
|
||||
}
|
||||
|
||||
try {
|
||||
$class = $namespace . 'Plugin';
|
||||
$class = $namespace.'Plugin';
|
||||
$reflectionClass = new ReflectionClass($class);
|
||||
|
||||
/** @var PluginInterface $plugin */
|
||||
$plugin = $reflectionClass->newInstance(
|
||||
Bootstrap::getContainer(),
|
||||
BootstrapBase::getContainer(),
|
||||
new PluginOperation($this->pluginDataService, $pluginName)
|
||||
);
|
||||
|
||||
// Do not load plugin's data if not compatible.
|
||||
// Just return the plugin instance before disabling it
|
||||
if ($this->checkCompatibility($plugin) === false) {
|
||||
$this->eventDispatcher->notifyEvent('plugin.load.error',
|
||||
new Event($this, EventMessage::factory()
|
||||
->addDescription(sprintf(__('Plugin version not compatible (%s)'), implode('.', $plugin->getVersion()))))
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'plugin.load.error',
|
||||
new Event(
|
||||
$this, EventMessage::factory()
|
||||
->addDescription(
|
||||
sprintf(__('Plugin version not compatible (%s)'), implode('.', $plugin->getVersion()))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->disabledPlugins[] = $pluginName;
|
||||
@@ -177,11 +182,14 @@ final class PluginManager
|
||||
} catch (Exception $e) {
|
||||
processException($e);
|
||||
|
||||
$this->eventDispatcher->notifyEvent('exception',
|
||||
new Event($e, EventMessage::factory()
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'exception',
|
||||
new Event(
|
||||
$e, EventMessage::factory()
|
||||
->addDescription(sprintf(__('Unable to load the "%s" plugin'), $pluginName))
|
||||
->addDescription($e->getMessage())
|
||||
->addDetail(__u('Plugin'), $pluginName))
|
||||
->addDetail(__u('Plugin'), $pluginName)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -189,7 +197,7 @@ final class PluginManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PluginInterface $plugin
|
||||
* @param PluginInterface $plugin
|
||||
*
|
||||
* @return bool
|
||||
* @throws ConstraintException
|
||||
@@ -223,7 +231,7 @@ final class PluginManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PluginInterface $plugin
|
||||
* @param PluginInterface $plugin
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -240,11 +248,14 @@ final class PluginManager
|
||||
} catch (Exception $e) {
|
||||
processException($e);
|
||||
|
||||
$this->eventDispatcher->notifyEvent('exception',
|
||||
new Event($e, EventMessage::factory()
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'exception',
|
||||
new Event(
|
||||
$e, EventMessage::factory()
|
||||
->addDescription(sprintf(__('Unable to load the "%s" plugin'), $plugin->getName()))
|
||||
->addDescription($e->getMessage())
|
||||
->addDetail(__u('Plugin'), $plugin->getName()))
|
||||
->addDetail(__u('Plugin'), $plugin->getName())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -275,20 +286,28 @@ final class PluginManager
|
||||
if ($plugin->getAvailable() === 0) {
|
||||
$this->pluginService->toggleAvailable($plugin->getId(), true);
|
||||
|
||||
$this->eventDispatcher->notifyEvent('edit.plugin.available',
|
||||
new Event($this, EventMessage::factory()
|
||||
->addDetail(__u('Plugin available'), $plugin->getName()))
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'edit.plugin.available',
|
||||
new Event(
|
||||
$this, EventMessage::factory()
|
||||
->addDetail(__u('Plugin available'), $plugin->getName())
|
||||
)
|
||||
);
|
||||
|
||||
$this->load($plugin->getName());
|
||||
}
|
||||
} else if ($plugin->getAvailable() === 1) {
|
||||
$this->pluginService->toggleAvailable($plugin->getId(), false);
|
||||
} else {
|
||||
if ($plugin->getAvailable() === 1) {
|
||||
$this->pluginService->toggleAvailable($plugin->getId(), false);
|
||||
|
||||
$this->eventDispatcher->notifyEvent('edit.plugin.unavailable',
|
||||
new Event($this, EventMessage::factory()
|
||||
->addDetail(__u('Plugin unavailable'), $plugin->getName()))
|
||||
);
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'edit.plugin.unavailable',
|
||||
new Event(
|
||||
$this, EventMessage::factory()
|
||||
->addDetail(__u('Plugin unavailable'), $plugin->getName())
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$processed[] = $plugin->getName();
|
||||
@@ -303,7 +322,7 @@ final class PluginManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $pluginName
|
||||
* @param string $pluginName
|
||||
*/
|
||||
private function load(string $pluginName): void
|
||||
{
|
||||
@@ -317,9 +336,12 @@ final class PluginManager
|
||||
) {
|
||||
logger(sprintf('Plugin loaded: %s', $pluginName));
|
||||
|
||||
$this->eventDispatcher->notifyEvent('plugin.load',
|
||||
new Event($this, EventMessage::factory()
|
||||
->addDetail(__u('Plugin loaded'), $pluginName))
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'plugin.load',
|
||||
new Event(
|
||||
$this, EventMessage::factory()
|
||||
->addDetail(__u('Plugin loaded'), $pluginName)
|
||||
)
|
||||
);
|
||||
|
||||
$this->loadedPlugins[$pluginName] = $plugin;
|
||||
@@ -329,7 +351,7 @@ final class PluginManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
*
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
@@ -342,17 +364,20 @@ final class PluginManager
|
||||
|
||||
$this->pluginService->create($pluginData);
|
||||
|
||||
$this->eventDispatcher->notifyEvent('create.plugin',
|
||||
new Event($this, EventMessage::factory()
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'create.plugin',
|
||||
new Event(
|
||||
$this, EventMessage::factory()
|
||||
->addDescription(__u('New Plugin'))
|
||||
->addDetail(__u('Name'), $name)
|
||||
));
|
||||
)
|
||||
);
|
||||
|
||||
$this->disabledPlugins[] = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $version
|
||||
* @param string $version
|
||||
*/
|
||||
public function upgradePlugins(string $version): void
|
||||
{
|
||||
@@ -365,10 +390,13 @@ final class PluginManager
|
||||
);
|
||||
|
||||
if (null === $plugin) {
|
||||
$this->eventDispatcher->notifyEvent('upgrade.plugin.process',
|
||||
new Event($this, EventMessage::factory()
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'upgrade.plugin.process',
|
||||
new Event(
|
||||
$this, EventMessage::factory()
|
||||
->addDescription(sprintf(__('Unable to upgrade the "%s" plugin'), $pluginName))
|
||||
->addDetail(__u('Plugin'), $pluginName))
|
||||
->addDetail(__u('Plugin'), $pluginName)
|
||||
)
|
||||
);
|
||||
|
||||
continue;
|
||||
@@ -380,10 +408,13 @@ final class PluginManager
|
||||
if ($pluginModel->getVersionLevel() === null
|
||||
|| VersionUtil::checkVersion($pluginModel->getVersionLevel(), $version)
|
||||
) {
|
||||
$this->eventDispatcher->notifyEvent('upgrade.plugin.process',
|
||||
new Event($this, EventMessage::factory()
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'upgrade.plugin.process',
|
||||
new Event(
|
||||
$this, EventMessage::factory()
|
||||
->addDescription(__u('Upgrading plugin'))
|
||||
->addDetail(__u('Name'), $pluginName))
|
||||
->addDetail(__u('Name'), $pluginName)
|
||||
)
|
||||
);
|
||||
|
||||
$plugin->upgrade(
|
||||
@@ -397,20 +428,26 @@ final class PluginManager
|
||||
|
||||
$this->pluginService->update($pluginModel);
|
||||
|
||||
$this->eventDispatcher->notifyEvent('upgrade.plugin.process',
|
||||
new Event($this, EventMessage::factory()
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'upgrade.plugin.process',
|
||||
new Event(
|
||||
$this, EventMessage::factory()
|
||||
->addDescription(__u('Plugin upgraded'))
|
||||
->addDetail(__u('Name'), $pluginName))
|
||||
->addDetail(__u('Name'), $pluginName)
|
||||
)
|
||||
);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
processException($e);
|
||||
|
||||
$this->eventDispatcher->notifyEvent('exception',
|
||||
new Event($e, EventMessage::factory()
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'exception',
|
||||
new Event(
|
||||
$e, EventMessage::factory()
|
||||
->addDescription(sprintf(__('Unable to upgrade the "%s" plugin'), $pluginName))
|
||||
->addDescription($e->getMessage())
|
||||
->addDetail(__u('Plugin'), $pluginName))
|
||||
->addDetail(__u('Plugin'), $pluginName)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -427,9 +464,12 @@ final class PluginManager
|
||||
if (!in_array($plugin, $this->loadedPlugins, true)) {
|
||||
$this->pluginService->toggleAvailableByName($plugin, false);
|
||||
|
||||
$this->eventDispatcher->notifyEvent('edit.plugin.unavailable',
|
||||
new Event($this, EventMessage::factory()
|
||||
->addDetail(__u('Plugin disabled'), $plugin->getName()))
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'edit.plugin.unavailable',
|
||||
new Event(
|
||||
$this, EventMessage::factory()
|
||||
->addDetail(__u('Plugin disabled'), $plugin->getName())
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ namespace SP\Services\Account;
|
||||
|
||||
defined('APP_ROOT') || die();
|
||||
|
||||
use SP\Bootstrap;
|
||||
use SP\Config\ConfigDataInterface;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\DataModel\AccountSearchVData;
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\Html\Html;
|
||||
@@ -40,21 +40,21 @@ use SP\Services\PublicLink\PublicLinkService;
|
||||
*/
|
||||
final class AccountSearchItem
|
||||
{
|
||||
public static bool $accountLink = false;
|
||||
public static bool $topNavbar = false;
|
||||
public static bool $optionalActions = false;
|
||||
public static bool $showTags = false;
|
||||
public static bool $requestEnabled = true;
|
||||
public static bool $wikiEnabled = false;
|
||||
public static bool $dokuWikiEnabled = false;
|
||||
public static bool $accountLink = false;
|
||||
public static bool $topNavbar = false;
|
||||
public static bool $optionalActions = false;
|
||||
public static bool $showTags = false;
|
||||
public static bool $requestEnabled = true;
|
||||
public static bool $wikiEnabled = false;
|
||||
public static bool $dokuWikiEnabled = false;
|
||||
public static bool $publicLinkEnabled = false;
|
||||
public static bool $isDemoMode = false;
|
||||
public static bool $isDemoMode = false;
|
||||
|
||||
protected AccountSearchVData $accountSearchVData;
|
||||
protected ?string $color = null;
|
||||
protected ?string $link = null;
|
||||
protected bool $favorite = false;
|
||||
protected int $textMaxLength = 60;
|
||||
protected ?string $color = null;
|
||||
protected ?string $link = null;
|
||||
protected bool $favorite = false;
|
||||
protected int $textMaxLength = 60;
|
||||
/**
|
||||
* @var ItemData[]|null
|
||||
*/
|
||||
@@ -66,16 +66,15 @@ final class AccountSearchItem
|
||||
/**
|
||||
* @var ItemData[]|null
|
||||
*/
|
||||
protected ?array $userGroups = null;
|
||||
protected ?array $userGroups = null;
|
||||
private ConfigDataInterface $configData;
|
||||
private AccountAcl $accountAcl;
|
||||
private AccountAcl $accountAcl;
|
||||
|
||||
public function __construct(
|
||||
AccountSearchVData $accountSearchVData,
|
||||
AccountAcl $accountAcl,
|
||||
AccountSearchVData $accountSearchVData,
|
||||
AccountAcl $accountAcl,
|
||||
ConfigDataInterface $configData
|
||||
)
|
||||
{
|
||||
) {
|
||||
$this->accountSearchVData = $accountSearchVData;
|
||||
$this->accountAcl = $accountAcl;
|
||||
$this->configData = $configData;
|
||||
@@ -96,10 +95,15 @@ final class AccountSearchItem
|
||||
return !$this->accountAcl->isShow() && self::$requestEnabled;
|
||||
}
|
||||
|
||||
public function isShow(): bool
|
||||
{
|
||||
return $this->accountAcl->isShow();
|
||||
}
|
||||
|
||||
public function isShowCopyPass(): bool
|
||||
{
|
||||
return $this->accountAcl->isShowViewPass()
|
||||
&& !$this->configData->isAccountPassToImage();
|
||||
&& !$this->configData->isAccountPassToImage();
|
||||
}
|
||||
|
||||
public function isShowViewPass(): bool
|
||||
@@ -140,7 +144,7 @@ final class AccountSearchItem
|
||||
public function getClientLink(): ?string
|
||||
{
|
||||
return self::$wikiEnabled
|
||||
? $this->configData->getWikiSearchurl() . $this->accountSearchVData->getClientName()
|
||||
? $this->configData->getWikiSearchurl().$this->accountSearchVData->getClientName()
|
||||
: null;
|
||||
}
|
||||
|
||||
@@ -149,7 +153,7 @@ final class AccountSearchItem
|
||||
if (self::$publicLinkEnabled
|
||||
&& $this->accountSearchVData->getPublicLinkHash() !== null
|
||||
) {
|
||||
$baseUrl = ($this->configData->getApplicationUrl() ?: Bootstrap::$WEBURI) . Bootstrap::$SUBURI;
|
||||
$baseUrl = ($this->configData->getApplicationUrl() ?: BootstrapBase::$WEBURI).BootstrapBase::$SUBURI;
|
||||
|
||||
return PublicLinkService::getLinkForHash($baseUrl, $this->accountSearchVData->getPublicLinkHash());
|
||||
}
|
||||
@@ -180,8 +184,8 @@ final class AccountSearchItem
|
||||
public function getAccesses(): array
|
||||
{
|
||||
$accesses = [
|
||||
'(G*) <em>' . $this->accountSearchVData->getUserGroupName() . '</em>',
|
||||
'(U*) <em>' . $this->accountSearchVData->getUserLogin() . '</em>'
|
||||
'(G*) <em>'.$this->accountSearchVData->getUserGroupName().'</em>',
|
||||
'(U*) <em>'.$this->accountSearchVData->getUserLogin().'</em>',
|
||||
];
|
||||
|
||||
$userLabel = $this->accountSearchVData->getOtherUserEdit() === 1 ? 'U+' : 'U';
|
||||
@@ -213,11 +217,6 @@ final class AccountSearchItem
|
||||
: 0;
|
||||
}
|
||||
|
||||
public function isShow(): bool
|
||||
{
|
||||
return $this->accountAcl->isShow();
|
||||
}
|
||||
|
||||
public function isShowView(): bool
|
||||
{
|
||||
return $this->accountAcl->isShowView();
|
||||
@@ -258,12 +257,12 @@ final class AccountSearchItem
|
||||
public function isPasswordExpired(): bool
|
||||
{
|
||||
return $this->configData->isAccountExpireEnabled()
|
||||
&& $this->accountSearchVData->getPassDateChange() > 0
|
||||
&& time() > $this->accountSearchVData->getPassDateChange();
|
||||
&& $this->accountSearchVData->getPassDateChange() > 0
|
||||
&& time() > $this->accountSearchVData->getPassDateChange();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ItemData[] $userGroups
|
||||
* @param ItemData[] $userGroups
|
||||
*/
|
||||
public function setUserGroups(array $userGroups): void
|
||||
{
|
||||
@@ -271,7 +270,7 @@ final class AccountSearchItem
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ItemData[] $users
|
||||
* @param ItemData[] $users
|
||||
*/
|
||||
public function setUsers(array $users): void
|
||||
{
|
||||
@@ -287,7 +286,7 @@ final class AccountSearchItem
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ItemData[] $tags
|
||||
* @param ItemData[] $tags
|
||||
*/
|
||||
public function setTags(array $tags): void
|
||||
{
|
||||
@@ -297,8 +296,8 @@ final class AccountSearchItem
|
||||
public function isWikiMatch(string $wikiFilter): bool
|
||||
{
|
||||
return preg_match(
|
||||
'/^' . $wikiFilter . '/i',
|
||||
$this->accountSearchVData->getName()
|
||||
) === 1;
|
||||
'/^'.$wikiFilter.'/i',
|
||||
$this->accountSearchVData->getName()
|
||||
) === 1;
|
||||
}
|
||||
}
|
||||
@@ -26,8 +26,8 @@ namespace SP\Services\Mail;
|
||||
|
||||
use Exception;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use SP\Bootstrap;
|
||||
use SP\Core\AppInfoInterface;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Core\Events\Event;
|
||||
use SP\Core\Events\EventMessage;
|
||||
use SP\Core\Exceptions\SPException;
|
||||
@@ -61,7 +61,9 @@ final class MailService extends Service
|
||||
|
||||
$mailMessage = new MailMessage();
|
||||
$mailMessage->setTitle(__u('Mail test'));
|
||||
$mailMessage->addDescription(__u('This is a test email in order to verify that the configuration is working right.'));
|
||||
$mailMessage->addDescription(
|
||||
__u('This is a test email in order to verify that the configuration is working right.')
|
||||
);
|
||||
$mailMessage->setFooter($this->getEmailFooter());
|
||||
|
||||
$mailer->isHTML();
|
||||
@@ -82,7 +84,8 @@ final class MailService extends Service
|
||||
SPException::ERROR,
|
||||
$e->getMessage(),
|
||||
$e->getCode(),
|
||||
$e);
|
||||
$e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +102,7 @@ final class MailService extends Service
|
||||
AppInfoInterface::APP_NAME,
|
||||
AppInfoInterface::APP_DESC
|
||||
),
|
||||
Html::anchorText(Bootstrap::$WEBURI)
|
||||
Html::anchorText(BootstrapBase::$WEBURI),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -118,9 +121,9 @@ final class MailService extends Service
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $subject
|
||||
* @param array|string $to
|
||||
* @param MailMessage $mailMessage
|
||||
* @param string $subject
|
||||
* @param array|string $to
|
||||
* @param MailMessage $mailMessage
|
||||
*
|
||||
* @throws \PHPMailer\PHPMailer\Exception
|
||||
* @throws \SP\Services\ServiceException
|
||||
@@ -152,8 +155,10 @@ final class MailService extends Service
|
||||
try {
|
||||
$this->mailer->send();
|
||||
|
||||
$this->eventDispatcher->notifyEvent('send.mail',
|
||||
new Event($this, EventMessage::factory()
|
||||
$this->eventDispatcher->notifyEvent(
|
||||
'send.mail',
|
||||
new Event(
|
||||
$this, EventMessage::factory()
|
||||
->addDescription(__u('Email sent'))
|
||||
->addDetail(
|
||||
__u('Recipient'),
|
||||
@@ -166,7 +171,8 @@ final class MailService extends Service
|
||||
$this->mailer->getToAddresses()
|
||||
)
|
||||
)
|
||||
))
|
||||
)
|
||||
)
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
processException($e);
|
||||
@@ -185,11 +191,10 @@ final class MailService extends Service
|
||||
* @throws \SP\Services\ServiceException
|
||||
*/
|
||||
public function sendBatch(
|
||||
string $subject,
|
||||
array $to,
|
||||
string $subject,
|
||||
array $to,
|
||||
MailMessage $mailMessage
|
||||
): void
|
||||
{
|
||||
): void {
|
||||
$this->mailer->isHTML();
|
||||
|
||||
foreach ($to as $address) {
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace SP\Services;
|
||||
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use SP\Bootstrap;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\DataModel\DataModelInterface;
|
||||
|
||||
/**
|
||||
@@ -45,7 +45,7 @@ trait ServiceItemTrait
|
||||
*/
|
||||
public static function getItemsBasic(): array
|
||||
{
|
||||
return Bootstrap::getContainer()
|
||||
return BootstrapBase::getContainer()
|
||||
->get(static::class)
|
||||
->getAllBasic();
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace SP\Services\UserPassRecover;
|
||||
use Defuse\Crypto\Exception\EnvironmentIsBrokenException;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use SP\Bootstrap;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Core\Exceptions\ConstraintException;
|
||||
use SP\Core\Exceptions\QueryException;
|
||||
use SP\Core\Exceptions\SPException;
|
||||
@@ -64,7 +64,9 @@ final class UserPassRecoverService extends Service
|
||||
$mailMessage->addDescriptionLine();
|
||||
$mailMessage->addDescription(__('In order to complete the process, please go to this URL:'));
|
||||
$mailMessage->addDescriptionLine();
|
||||
$mailMessage->addDescription(Html::anchorText(Bootstrap::$WEBURI . '/index.php?r=userPassReset/reset/' . $hash));
|
||||
$mailMessage->addDescription(
|
||||
Html::anchorText(BootstrapBase::$WEBURI.'/index.php?r=userPassReset/reset/'.$hash)
|
||||
);
|
||||
$mailMessage->addDescriptionLine();
|
||||
$mailMessage->addDescription(__('If you have not requested this action, please dismiss this message.'));
|
||||
|
||||
@@ -79,7 +81,8 @@ final class UserPassRecoverService extends Service
|
||||
{
|
||||
if ($this->userPassRecoverRepository->toggleUsedByHash(
|
||||
$hash,
|
||||
time() - self::MAX_PASS_RECOVER_TIME) === 0
|
||||
time() - self::MAX_PASS_RECOVER_TIME
|
||||
) === 0
|
||||
) {
|
||||
throw new ServiceException(
|
||||
__u('Wrong hash or expired'),
|
||||
|
||||
@@ -24,10 +24,9 @@
|
||||
|
||||
namespace SP\Util;
|
||||
|
||||
|
||||
use SP\Bootstrap;
|
||||
use SP\Config\ConfigDataInterface;
|
||||
use SP\Core\Acl\Acl;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Http\Uri;
|
||||
|
||||
/**
|
||||
@@ -38,18 +37,17 @@ use SP\Http\Uri;
|
||||
final class Link
|
||||
{
|
||||
public static function getDeepLink(
|
||||
int $itemId,
|
||||
int $actionId,
|
||||
int $itemId,
|
||||
int $actionId,
|
||||
ConfigDataInterface $configData,
|
||||
bool $useUI = false
|
||||
): string
|
||||
{
|
||||
$route = Acl::getActionRoute($actionId) . '/' . $itemId;
|
||||
bool $useUI = false
|
||||
): string {
|
||||
$route = Acl::getActionRoute($actionId).'/'.$itemId;
|
||||
|
||||
if ($useUI) {
|
||||
$baseUrl = ($configData->getApplicationUrl() ?? Bootstrap::$WEBURI) . '/index.php';
|
||||
$baseUrl = ($configData->getApplicationUrl() ?? BootstrapBase::$WEBURI).'/index.php';
|
||||
} else {
|
||||
$baseUrl = ($configData->getApplicationUrl() ?? Bootstrap::$WEBURI) . Bootstrap::$SUBURI;
|
||||
$baseUrl = ($configData->getApplicationUrl() ?? BootstrapBase::$WEBURI).BootstrapBase::$SUBURI;
|
||||
}
|
||||
|
||||
$uri = new Uri($baseUrl);
|
||||
|
||||
@@ -25,15 +25,16 @@
|
||||
namespace SP\Tests\Modules\Api;
|
||||
|
||||
use DI\ContainerBuilder;
|
||||
use Klein\Klein;
|
||||
use Klein\Request;
|
||||
use Klein\Response;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use RuntimeException;
|
||||
use SP\Bootstrap;
|
||||
use SP\Config\Config;
|
||||
use SP\Config\ConfigDataInterface;
|
||||
use SP\Core\Acl\ActionsInterface;
|
||||
use SP\Core\Bootstrap\BootstrapApi;
|
||||
use SP\Core\Context\ContextInterface;
|
||||
use SP\DataModel\AuthTokenData;
|
||||
use SP\Services\Api\ApiRequest;
|
||||
@@ -58,33 +59,33 @@ abstract class ApiTestCase extends TestCase
|
||||
use DatabaseTrait;
|
||||
|
||||
private const METHOD_ACTION_MAP = [
|
||||
ActionsInterface::ACCOUNT_CREATE => 'account/create',
|
||||
ActionsInterface::ACCOUNT_VIEW => 'account/view',
|
||||
ActionsInterface::ACCOUNT_CREATE => 'account/create',
|
||||
ActionsInterface::ACCOUNT_VIEW => 'account/view',
|
||||
ActionsInterface::ACCOUNT_VIEW_PASS => 'account/viewPass',
|
||||
ActionsInterface::ACCOUNT_EDIT_PASS => 'account/editPass',
|
||||
ActionsInterface::ACCOUNT_EDIT => 'account/edit',
|
||||
ActionsInterface::ACCOUNT_SEARCH => 'account/search',
|
||||
ActionsInterface::ACCOUNT_DELETE => 'account/delete',
|
||||
ActionsInterface::CATEGORY_VIEW => 'category/view',
|
||||
ActionsInterface::CATEGORY_CREATE => 'category/create',
|
||||
ActionsInterface::CATEGORY_EDIT => 'category/edit',
|
||||
ActionsInterface::CATEGORY_DELETE => 'category/delete',
|
||||
ActionsInterface::CATEGORY_SEARCH => 'category/search',
|
||||
ActionsInterface::CLIENT_VIEW => 'client/view',
|
||||
ActionsInterface::CLIENT_CREATE => 'client/create',
|
||||
ActionsInterface::CLIENT_EDIT => 'client/edit',
|
||||
ActionsInterface::CLIENT_DELETE => 'client/delete',
|
||||
ActionsInterface::CLIENT_SEARCH => 'client/search',
|
||||
ActionsInterface::TAG_VIEW => 'tag/view',
|
||||
ActionsInterface::TAG_CREATE => 'tag/create',
|
||||
ActionsInterface::TAG_EDIT => 'tag/edit',
|
||||
ActionsInterface::TAG_DELETE => 'tag/delete',
|
||||
ActionsInterface::TAG_SEARCH => 'tag/search',
|
||||
ActionsInterface::GROUP_VIEW => 'userGroup/view',
|
||||
ActionsInterface::GROUP_CREATE => 'userGroup/create',
|
||||
ActionsInterface::GROUP_EDIT => 'userGroup/edit',
|
||||
ActionsInterface::GROUP_DELETE => 'userGroup/delete',
|
||||
ActionsInterface::GROUP_SEARCH => 'userGroup/search',
|
||||
ActionsInterface::ACCOUNT_EDIT => 'account/edit',
|
||||
ActionsInterface::ACCOUNT_SEARCH => 'account/search',
|
||||
ActionsInterface::ACCOUNT_DELETE => 'account/delete',
|
||||
ActionsInterface::CATEGORY_VIEW => 'category/view',
|
||||
ActionsInterface::CATEGORY_CREATE => 'category/create',
|
||||
ActionsInterface::CATEGORY_EDIT => 'category/edit',
|
||||
ActionsInterface::CATEGORY_DELETE => 'category/delete',
|
||||
ActionsInterface::CATEGORY_SEARCH => 'category/search',
|
||||
ActionsInterface::CLIENT_VIEW => 'client/view',
|
||||
ActionsInterface::CLIENT_CREATE => 'client/create',
|
||||
ActionsInterface::CLIENT_EDIT => 'client/edit',
|
||||
ActionsInterface::CLIENT_DELETE => 'client/delete',
|
||||
ActionsInterface::CLIENT_SEARCH => 'client/search',
|
||||
ActionsInterface::TAG_VIEW => 'tag/view',
|
||||
ActionsInterface::TAG_CREATE => 'tag/create',
|
||||
ActionsInterface::TAG_EDIT => 'tag/edit',
|
||||
ActionsInterface::TAG_DELETE => 'tag/delete',
|
||||
ActionsInterface::TAG_SEARCH => 'tag/search',
|
||||
ActionsInterface::GROUP_VIEW => 'userGroup/view',
|
||||
ActionsInterface::GROUP_CREATE => 'userGroup/create',
|
||||
ActionsInterface::GROUP_EDIT => 'userGroup/edit',
|
||||
ActionsInterface::GROUP_DELETE => 'userGroup/delete',
|
||||
ActionsInterface::GROUP_SEARCH => 'userGroup/search',
|
||||
ActionsInterface::CONFIG_BACKUP_RUN => 'config/backup',
|
||||
ActionsInterface::CONFIG_EXPORT_RUN => 'config/export',
|
||||
];
|
||||
@@ -95,9 +96,8 @@ abstract class ApiTestCase extends TestCase
|
||||
*/
|
||||
protected static function processJsonResponse(
|
||||
Response $response,
|
||||
bool $exceptionOnError = true
|
||||
): stdClass
|
||||
{
|
||||
bool $exceptionOnError = true
|
||||
): stdClass {
|
||||
if ($exceptionOnError && $response->status()->getCode() !== 200) {
|
||||
throw new RuntimeException($response->status()->getMessage());
|
||||
}
|
||||
@@ -132,7 +132,7 @@ abstract class ApiTestCase extends TestCase
|
||||
->addDefinitions(
|
||||
APP_DEFINITIONS_FILE,
|
||||
[
|
||||
ApiRequest::class => function (ContainerInterface $c) use ($actionId, $params) {
|
||||
ApiRequest::class => function (ContainerInterface $c) use ($actionId, $params) {
|
||||
$token = self::createApiToken(
|
||||
$c->get(AuthTokenService::class),
|
||||
$actionId
|
||||
@@ -140,20 +140,20 @@ abstract class ApiTestCase extends TestCase
|
||||
|
||||
$data = [
|
||||
'jsonrpc' => '2.0',
|
||||
'method' => self::METHOD_ACTION_MAP[$actionId],
|
||||
'params' => array_merge(
|
||||
'method' => self::METHOD_ACTION_MAP[$actionId],
|
||||
'params' => array_merge(
|
||||
[
|
||||
'authToken' => $token->getToken(),
|
||||
'tokenPass' => self::AUTH_TOKEN_PASS,
|
||||
],
|
||||
$params
|
||||
),
|
||||
'id' => 1
|
||||
'id' => 1,
|
||||
];
|
||||
|
||||
return new ApiRequest(json_encode($data, JSON_THROW_ON_ERROR));
|
||||
},
|
||||
DBStorageInterface::class => create(MySQLHandler::class)
|
||||
DBStorageInterface::class => create(MySQLHandler::class)
|
||||
->constructor($databaseConnectionData),
|
||||
ConfigDataInterface::class => static function (Config $config) use ($databaseConnectionData) {
|
||||
$configData = $config->getConfigData()
|
||||
@@ -167,7 +167,7 @@ abstract class ApiTestCase extends TestCase
|
||||
$config->updateConfig($configData);
|
||||
|
||||
return $configData;
|
||||
}
|
||||
},
|
||||
]
|
||||
)
|
||||
->build();
|
||||
@@ -183,20 +183,23 @@ abstract class ApiTestCase extends TestCase
|
||||
[],
|
||||
[],
|
||||
[
|
||||
'HTTP_HOST' => 'localhost:8080',
|
||||
'HTTP_ACCEPT' => 'application/json, text/javascript, */*; q=0.01',
|
||||
'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0',
|
||||
'HTTP_HOST' => 'localhost:8080',
|
||||
'HTTP_ACCEPT' => 'application/json, text/javascript, */*; q=0.01',
|
||||
'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0',
|
||||
'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.5',
|
||||
'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
|
||||
'REQUEST_URI' => '/api.php',
|
||||
'REQUEST_METHOD' => 'POST',
|
||||
'HTTP_CONTENT_TYPE' => 'application/json'
|
||||
'REQUEST_URI' => '/api.php',
|
||||
'REQUEST_METHOD' => 'POST',
|
||||
'HTTP_CONTENT_TYPE' => 'application/json',
|
||||
],
|
||||
[],
|
||||
null
|
||||
);
|
||||
|
||||
$router = (new Bootstrap($dic))->getRouter();
|
||||
$router = $dic->get(Klein::class);
|
||||
$request = $dic->get(\SP\Http\Request::class);
|
||||
|
||||
$bs = new BootstrapApi(self::$configData, $router, $request);
|
||||
$router->dispatch($request, null, false);
|
||||
|
||||
return $router->response();
|
||||
@@ -211,9 +214,8 @@ abstract class ApiTestCase extends TestCase
|
||||
*/
|
||||
private static function createApiToken(
|
||||
AuthTokenService $service,
|
||||
int $actionId
|
||||
): AuthTokenData
|
||||
{
|
||||
int $actionId
|
||||
): AuthTokenData {
|
||||
$data = new AuthTokenData();
|
||||
$data->setActionId($actionId);
|
||||
$data->setCreatedBy(1);
|
||||
|
||||
Reference in New Issue
Block a user