mirror of
https://github.com/nuxsmin/sysPass.git
synced 2026-03-04 23:54:08 +01:00
refactor: Fix initialization errors.
Signed-off-by: Rubén D <nuxsmin@syspass.org>
This commit is contained in:
@@ -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.
|
||||
*
|
||||
@@ -134,17 +134,13 @@ abstract class ControllerBase
|
||||
*/
|
||||
private function sendJsonResponse(string $response): void
|
||||
{
|
||||
Json::factory($this->router->response())
|
||||
->returnRawJson($response);
|
||||
Json::factory($this->router->response())->returnRawJson($response);
|
||||
}
|
||||
|
||||
final protected function returnResponseException(Exception $e): void
|
||||
{
|
||||
$this->sendJsonResponse(
|
||||
JsonRpcResponse::getResponseException(
|
||||
$e,
|
||||
$this->apiService->getRequestId()
|
||||
)
|
||||
JsonRpcResponse::getResponseException($e, $this->apiService->getRequestId())
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*
|
||||
@@ -27,7 +27,6 @@ namespace SP\Modules\Web\Controllers;
|
||||
defined('APP_ROOT') || die();
|
||||
|
||||
use Exception;
|
||||
use Klein\Klein;
|
||||
use SP\Core\Acl\Acl;
|
||||
use SP\Core\Application;
|
||||
use SP\Core\Context\ContextInterface;
|
||||
@@ -63,7 +62,6 @@ abstract class ControllerBase
|
||||
protected ConfigFileService $config;
|
||||
protected ContextInterface $session;
|
||||
protected ThemeInterface $theme;
|
||||
protected Klein $router;
|
||||
protected Acl $acl;
|
||||
protected ConfigDataInterface $configData;
|
||||
protected RequestInterface $request;
|
||||
|
||||
@@ -56,9 +56,9 @@ final class AccountUserController extends SimpleControllerBase
|
||||
*
|
||||
* @param int|null $accountId
|
||||
*
|
||||
* @throws \JsonException
|
||||
* @throws \SP\Core\Exceptions\ConstraintException
|
||||
* @throws \SP\Core\Exceptions\QueryException
|
||||
* @throws \SP\Core\Exceptions\SPException
|
||||
*/
|
||||
public function accountsUserAction(?int $accountId = null): void
|
||||
{
|
||||
|
||||
@@ -54,9 +54,9 @@ final class NotificationsController extends SimpleControllerBase
|
||||
|
||||
|
||||
/**
|
||||
* @throws \JsonException
|
||||
* @throws \SP\Core\Exceptions\ConstraintException
|
||||
* @throws \SP\Core\Exceptions\QueryException
|
||||
* @throws \SP\Core\Exceptions\SPException
|
||||
*/
|
||||
public function notificationsAction(): void
|
||||
{
|
||||
|
||||
@@ -36,6 +36,10 @@ abstract class ResourceBase extends SimpleControllerBase
|
||||
{
|
||||
protected Minify $minify;
|
||||
|
||||
/**
|
||||
* @throws \SP\Core\Exceptions\SessionTimeout
|
||||
* @throws \SP\Core\Exceptions\SPException
|
||||
*/
|
||||
public function __construct(
|
||||
Application $application,
|
||||
SimpleControllerHelper $simpleControllerHelper,
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
namespace SP\Modules\Web\Controllers;
|
||||
|
||||
use Klein\Klein;
|
||||
use SP\Core\Acl\Acl;
|
||||
use SP\Core\Acl\UnauthorizedPageException;
|
||||
use SP\Core\Application;
|
||||
@@ -53,7 +52,6 @@ abstract class SimpleControllerBase
|
||||
protected ConfigFileService $config;
|
||||
protected ContextInterface $session;
|
||||
protected ThemeInterface $theme;
|
||||
protected Klein $router;
|
||||
protected Acl $acl;
|
||||
protected Request $request;
|
||||
protected PhpExtensionChecker $extensionChecker;
|
||||
@@ -61,7 +59,6 @@ abstract class SimpleControllerBase
|
||||
|
||||
/**
|
||||
* @throws \SP\Core\Exceptions\SessionTimeout
|
||||
* @throws \JsonException
|
||||
*/
|
||||
public function __construct(
|
||||
Application $application,
|
||||
@@ -87,8 +84,8 @@ abstract class SimpleControllerBase
|
||||
/**
|
||||
* Comprobaciones
|
||||
*
|
||||
* @throws SessionTimeout
|
||||
* @throws \JsonException
|
||||
* @throws \SP\Core\Exceptions\SPException
|
||||
* @throws \SP\Core\Exceptions\SessionTimeout
|
||||
*/
|
||||
protected function checks(): void
|
||||
{
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
@@ -34,23 +34,21 @@ use SP\Http\JsonResponse;
|
||||
* Trait JsonTrait
|
||||
*
|
||||
* @property SessionContext $session
|
||||
* @property \Klein\Klein $router
|
||||
*/
|
||||
trait JsonTrait
|
||||
{
|
||||
/**
|
||||
* Returns JSON response
|
||||
*
|
||||
* @param int $status Status code
|
||||
* @param string $description Untranslated description string
|
||||
* @param array|null $messages Untranslated massages array of strings
|
||||
* @param int $status Status code
|
||||
* @param string $description Untranslated description string
|
||||
* @param array|null $messages Untranslated massages array of strings
|
||||
*
|
||||
* @throws \JsonException
|
||||
* @return bool
|
||||
* @throws \SP\Core\Exceptions\SPException
|
||||
*/
|
||||
protected function returnJsonResponse(
|
||||
int $status,
|
||||
string $description,
|
||||
?array $messages = null
|
||||
): bool
|
||||
protected function returnJsonResponse(int $status, string $description, ?array $messages = null): bool
|
||||
{
|
||||
$jsonResponse = new JsonResponse();
|
||||
$jsonResponse->setStatus($status);
|
||||
@@ -60,19 +58,19 @@ trait JsonTrait
|
||||
$jsonResponse->setMessages($messages);
|
||||
}
|
||||
|
||||
return Json::fromDic()->returnJson($jsonResponse);
|
||||
return Json::factory($this->router->response())->returnJson($jsonResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns JSON response
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param int $status Status code
|
||||
* @param string|null $description Untranslated description string
|
||||
* @param array|null $messages
|
||||
* @param mixed $data
|
||||
* @param int $status Status code
|
||||
* @param string|null $description Untranslated description string
|
||||
* @param array|null $messages
|
||||
*
|
||||
* @return bool
|
||||
* @throws \JsonException
|
||||
* @throws \SP\Core\Exceptions\SPException
|
||||
*/
|
||||
protected function returnJsonResponseData(
|
||||
$data,
|
||||
@@ -93,29 +91,28 @@ trait JsonTrait
|
||||
$jsonResponse->setMessages($messages);
|
||||
}
|
||||
|
||||
return Json::fromDic()->returnJson($jsonResponse);
|
||||
return Json::factory($this->router->response())->returnJson($jsonResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns JSON response
|
||||
*
|
||||
* @throws \JsonException
|
||||
* @param \Exception $exception
|
||||
* @param int $status
|
||||
*
|
||||
* @return bool
|
||||
* @throws \SP\Core\Exceptions\SPException
|
||||
*/
|
||||
protected function returnJsonResponseException(
|
||||
Exception $exception,
|
||||
int $status = JsonResponse::JSON_ERROR
|
||||
): bool
|
||||
protected function returnJsonResponseException(Exception $exception, int $status = JsonResponse::JSON_ERROR): bool
|
||||
{
|
||||
$jsonResponse = new JsonResponse();
|
||||
$jsonResponse->setStatus($status);
|
||||
$jsonResponse->setDescription($exception->getMessage());
|
||||
|
||||
if ($exception instanceof SPException
|
||||
&& $exception->getHint() !== null
|
||||
) {
|
||||
if ($exception instanceof SPException && $exception->getHint() !== null) {
|
||||
$jsonResponse->setMessages([$exception->getHint()]);
|
||||
}
|
||||
|
||||
return Json::fromDic()->returnJson($jsonResponse);
|
||||
return Json::factory($this->router->response())->returnJson($jsonResponse);
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*
|
||||
@@ -66,7 +66,7 @@ trait WebControllerTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \JsonException
|
||||
* @throws \SP\Core\Exceptions\SPException
|
||||
*/
|
||||
private function handleSessionTimeout(): void
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2020, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -19,7 +19,7 @@
|
||||
* 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/>.
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use Monolog\Logger;
|
||||
@@ -30,6 +30,7 @@ use SP\Core\Acl\Actions;
|
||||
use SP\Core\Application;
|
||||
use SP\Core\Context\ContextFactory;
|
||||
use SP\Core\Context\ContextInterface;
|
||||
use SP\Core\Crypt\CryptPKI;
|
||||
use SP\Core\Crypt\CSRF;
|
||||
use SP\Core\Language;
|
||||
use SP\Core\LanguageInterface;
|
||||
@@ -75,7 +76,7 @@ use function DI\get;
|
||||
|
||||
return [
|
||||
RequestInterface::class => create(Request::class)
|
||||
->constructor(\Klein\Request::createFromGlobals()),
|
||||
->constructor(\Klein\Request::createFromGlobals(), autowire(CryptPKI::class)),
|
||||
ContextInterface::class =>
|
||||
static fn() => ContextFactory::getForModule(APP_MODULE),
|
||||
ConfigInterface::class => create(ConfigFileService::class)
|
||||
@@ -101,10 +102,7 @@ return [
|
||||
new XmlHandler(new FileHandler(MIMETYPES_FILE))
|
||||
),
|
||||
Acl::class => autowire(Acl::class)
|
||||
->constructorParameter(
|
||||
'action',
|
||||
get(Actions::class)
|
||||
),
|
||||
->constructorParameter('actions', get(Actions::class)),
|
||||
ThemeInterface::class => autowire(Theme::class)
|
||||
->constructorParameter('module', APP_MODULE)
|
||||
->constructorParameter(
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
namespace SP\Core\Bootstrap;
|
||||
|
||||
use Closure;
|
||||
use Exception;
|
||||
use Klein\Response;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
@@ -52,9 +53,6 @@ final class BootstrapApi extends BootstrapBase
|
||||
logger('------------');
|
||||
logger('Boostrap:api');
|
||||
|
||||
// TODO: remove
|
||||
self::$container = $container;
|
||||
|
||||
try {
|
||||
/** @noinspection SelfClassReferencingInspection */
|
||||
$bs = $container->get(BootstrapApi::class);
|
||||
@@ -85,11 +83,11 @@ final class BootstrapApi extends BootstrapBase
|
||||
try {
|
||||
logger('API route');
|
||||
|
||||
$apiRequest = self::$container->get(ApiRequest::class);
|
||||
$apiRequest = $this->createObjectFor(ApiRequest::class);
|
||||
|
||||
[$controllerName, $action] = explode('/', $apiRequest->getMethod());
|
||||
|
||||
$controllerClass = self::getClassFor($controllerName);
|
||||
$controllerClass = self::getClassFor($controllerName, $action);
|
||||
|
||||
$method = $action.'Action';
|
||||
|
||||
@@ -118,8 +116,8 @@ final class BootstrapApi extends BootstrapBase
|
||||
|
||||
logger('Routing call: '.$controllerClass.'::'.$method);
|
||||
|
||||
return call_user_func([new $controllerClass(self::$container, $method), $method]);
|
||||
} catch (\Exception $e) {
|
||||
return call_user_func([$this->createObjectFor($controllerClass), $method]);
|
||||
} catch (Exception $e) {
|
||||
processException($e);
|
||||
|
||||
/** @var Response $response */
|
||||
|
||||
@@ -28,7 +28,10 @@ use Closure;
|
||||
use Klein\Klein;
|
||||
use Klein\Response;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use RuntimeException;
|
||||
use SP\Core\Exceptions\InitializationException;
|
||||
use SP\Core\Exceptions\SPException;
|
||||
use SP\Core\Language;
|
||||
@@ -63,13 +66,14 @@ abstract class BootstrapBase
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
public static $LOCK;
|
||||
public static bool $checkPhpVersion = false;
|
||||
protected static ContainerInterface $container;
|
||||
protected Klein $router;
|
||||
protected RequestInterface $request;
|
||||
protected ConfigDataInterface $configData;
|
||||
private UpgradeConfigChecker $upgradeConfigChecker;
|
||||
public static $LOCK;
|
||||
public static bool $checkPhpVersion = false;
|
||||
protected Klein $router;
|
||||
protected RequestInterface $request;
|
||||
protected ConfigDataInterface $configData;
|
||||
private ContainerInterface $container;
|
||||
private UpgradeConfigChecker $upgradeConfigChecker;
|
||||
private PhpExtensionChecker $phpExtensionChecker;
|
||||
|
||||
/**
|
||||
* Bootstrap constructor.
|
||||
@@ -78,7 +82,9 @@ abstract class BootstrapBase
|
||||
ConfigDataInterface $configData,
|
||||
Klein $router,
|
||||
RequestInterface $request,
|
||||
UpgradeConfigChecker $upgradeConfigChecker
|
||||
UpgradeConfigChecker $upgradeConfigChecker,
|
||||
PhpExtensionChecker $extensionChecker,
|
||||
ContainerInterface $container
|
||||
) {
|
||||
// Set the default language
|
||||
Language::setLocales('en_US');
|
||||
@@ -87,6 +93,8 @@ abstract class BootstrapBase
|
||||
$this->router = $router;
|
||||
$this->request = $request;
|
||||
$this->upgradeConfigChecker = $upgradeConfigChecker;
|
||||
$this->phpExtensionChecker = $extensionChecker;
|
||||
$this->container = $container;
|
||||
|
||||
$this->initRouter();
|
||||
$this->configureRouter();
|
||||
@@ -122,8 +130,7 @@ abstract class BootstrapBase
|
||||
{
|
||||
$response->header(
|
||||
'Access-Control-Allow-Origin',
|
||||
$this->configData->getApplicationUrl()
|
||||
?? $this->request->getHttpHost()
|
||||
$this->configData->getApplicationUrl() ?? $this->request->getHttpHost()
|
||||
);
|
||||
$response->header(
|
||||
'Access-Control-Allow-Headers',
|
||||
@@ -136,9 +143,13 @@ abstract class BootstrapBase
|
||||
|
||||
abstract public static function run(ContainerInterface $container): BootstrapBase;
|
||||
|
||||
public static function getContainer(): ContainerInterface
|
||||
/**
|
||||
* @deprecated
|
||||
* FIXME: delete
|
||||
*/
|
||||
public static function getContainer()
|
||||
{
|
||||
return self::$container;
|
||||
return null;
|
||||
}
|
||||
|
||||
final protected static function getClassFor(string $controllerName, ?string $actionName): string
|
||||
@@ -170,8 +181,6 @@ abstract class BootstrapBase
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
* @throws \SP\Core\Exceptions\CheckException
|
||||
* @throws \SP\Core\Exceptions\ConfigException
|
||||
* @throws \SP\Core\Exceptions\InitializationException
|
||||
@@ -192,7 +201,7 @@ abstract class BootstrapBase
|
||||
// Set application paths
|
||||
$this->initPaths();
|
||||
|
||||
self::$container->get(PhpExtensionChecker::class)->checkMandatory();
|
||||
$this->phpExtensionChecker->checkMandatory();
|
||||
|
||||
if (!self::$checkPhpVersion) {
|
||||
throw new InitializationException(
|
||||
@@ -316,4 +325,20 @@ abstract class BootstrapBase
|
||||
{
|
||||
PluginManager::getPlugins();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
final protected function createObjectFor(string $class): object
|
||||
{
|
||||
try {
|
||||
return $this->container->get($class);
|
||||
} catch (NotFoundExceptionInterface|ContainerExceptionInterface $e) {
|
||||
processException($e);
|
||||
|
||||
throw new RuntimeException($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,6 @@ namespace SP\Core\Bootstrap;
|
||||
|
||||
use Closure;
|
||||
use Exception;
|
||||
use Klein\Response;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
@@ -56,13 +55,11 @@ final class BootstrapWeb extends BootstrapBase
|
||||
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;
|
||||
@@ -76,11 +73,7 @@ final class BootstrapWeb extends BootstrapBase
|
||||
protected function configureRouter(): void
|
||||
{
|
||||
// Manage requests for web module
|
||||
$this->router->respond(
|
||||
['GET', 'POST'],
|
||||
'@(?!/api\.php)',
|
||||
$this->manageWebRequest()
|
||||
);
|
||||
$this->router->respond(['GET', 'POST'], '@(?!/api\.php)', $this->manageWebRequest());
|
||||
}
|
||||
|
||||
private function manageWebRequest(): Closure
|
||||
@@ -104,19 +97,11 @@ final class BootstrapWeb extends BootstrapBase
|
||||
}
|
||||
|
||||
$controllerName = $matches['controller'][0];
|
||||
$actionName = empty($matches['action'][0]) ? 'index' : $matches['action'][0];
|
||||
$actionName = empty($matches['actions'][0]) ? 'index' : $matches['actions'][0];
|
||||
$methodName = sprintf('%sAction', $actionName);
|
||||
$methodParams = empty($matches['params'][0])
|
||||
? []
|
||||
: Filter::getArray(
|
||||
explode(
|
||||
'/',
|
||||
trim(
|
||||
$matches['params'][0],
|
||||
'/'
|
||||
)
|
||||
)
|
||||
);
|
||||
: Filter::getArray(explode('/', trim($matches['params'][0], '/')));
|
||||
|
||||
$controllerClass = self::getClassFor($controllerName, $actionName);
|
||||
|
||||
@@ -145,7 +130,7 @@ final class BootstrapWeb extends BootstrapBase
|
||||
)
|
||||
);
|
||||
|
||||
$controller = self::$container->get($controllerClass);
|
||||
$controller = $this->createObjectFor($controllerClass);
|
||||
|
||||
return call_user_func_array([$controller, $methodName], $methodParams);
|
||||
} catch (SessionTimeout $sessionTimeout) {
|
||||
@@ -153,11 +138,6 @@ final class BootstrapWeb extends BootstrapBase
|
||||
} catch (Exception $e) {
|
||||
processException($e);
|
||||
|
||||
/** @var Response $response */
|
||||
if ($response->status()->getCode() !== 404) {
|
||||
$response->code(503);
|
||||
}
|
||||
|
||||
echo __($e->getMessage());
|
||||
|
||||
if (DEBUG) {
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
@@ -26,7 +26,6 @@ namespace SP\Core\Crypt;
|
||||
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Core\Exceptions\SPException;
|
||||
use SP\Domain\Config\In\ConfigDataInterface;
|
||||
use SP\Util\Checks;
|
||||
|
||||
defined('APP_ROOT') || die();
|
||||
@@ -67,7 +66,7 @@ final class OldCrypt
|
||||
public static function makeHashSalt($salt = null, $random = true)
|
||||
{
|
||||
/** @var \SP\Domain\Config\In\ConfigDataInterface $ConfigData */
|
||||
$ConfigData = BootstrapBase::getContainer()['configData'];
|
||||
$ConfigData = BootstrapBase::getContainer()['configData']; // FIXME
|
||||
|
||||
if ($random === true) {
|
||||
$salt = bin2hex(self::getIV());
|
||||
|
||||
@@ -24,11 +24,6 @@
|
||||
|
||||
namespace SP\Domain\Common\Services;
|
||||
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\DataModel\DataModelInterface;
|
||||
|
||||
/**
|
||||
* Trait ServiceItemTrait
|
||||
*
|
||||
@@ -36,23 +31,6 @@ use SP\DataModel\DataModelInterface;
|
||||
*/
|
||||
trait ServiceItemTrait
|
||||
{
|
||||
/**
|
||||
* Returns service items for a select
|
||||
*
|
||||
* @return DataModelInterface[]
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*
|
||||
* @deprecated
|
||||
* TODO: remove!!
|
||||
*/
|
||||
public static function getItemsBasic(): array
|
||||
{
|
||||
return BootstrapBase::getContainer()
|
||||
->get(static::class)
|
||||
->getAllBasic();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all items from the service's repository
|
||||
*
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
@@ -25,8 +25,6 @@
|
||||
namespace SP\Html;
|
||||
|
||||
use Klein\Klein;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use SP\Http\Request;
|
||||
|
||||
defined('APP_ROOT') || die();
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
@@ -25,9 +25,7 @@
|
||||
namespace SP\Http;
|
||||
|
||||
use JsonException;
|
||||
use Klein\Klein;
|
||||
use Klein\Response;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Core\Exceptions\SPException;
|
||||
|
||||
|
||||
@@ -58,18 +56,6 @@ final class Json
|
||||
return new self($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Json
|
||||
*/
|
||||
public static function fromDic(): Json
|
||||
{
|
||||
return new self(
|
||||
BootstrapBase::getContainer()
|
||||
->get(Klein::class)
|
||||
->response()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Devuelve un array con las cadenas formateadas para JSON
|
||||
*/
|
||||
@@ -78,7 +64,7 @@ final class Json
|
||||
if (is_array($data) || is_object($data)) {
|
||||
array_walk_recursive(
|
||||
$data,
|
||||
static function (&$value) {
|
||||
static function ($value) {
|
||||
if (is_object($value)) {
|
||||
foreach ($value as $property => $v) {
|
||||
if (is_string($v) && $v !== '') {
|
||||
@@ -132,7 +118,10 @@ final class Json
|
||||
/**
|
||||
* Devuelve una respuesta en formato JSON con el estado y el mensaje.
|
||||
*
|
||||
* @throws \JsonException
|
||||
* @param \SP\Http\JsonResponse $jsonResponse
|
||||
*
|
||||
* @return bool
|
||||
* @throws \SP\Core\Exceptions\SPException
|
||||
*/
|
||||
public function returnJson(JsonResponse $jsonResponse): bool
|
||||
{
|
||||
@@ -144,7 +133,7 @@ final class Json
|
||||
$jsonResponse = new JsonResponse($e->getMessage());
|
||||
$jsonResponse->addMessage($e->getHint());
|
||||
|
||||
$this->response->body(json_encode($jsonResponse, JSON_THROW_ON_ERROR));
|
||||
$this->response->body(self::getJson($jsonResponse));
|
||||
}
|
||||
|
||||
return $this->response->send(true)->isSent();
|
||||
@@ -160,17 +149,10 @@ final class Json
|
||||
*/
|
||||
public static function getJson($data, int $flags = 0): string
|
||||
{
|
||||
|
||||
try {
|
||||
$json = json_encode($data, JSON_THROW_ON_ERROR | $flags);
|
||||
return json_encode($data, JSON_THROW_ON_ERROR | $flags);
|
||||
} catch (JsonException $e) {
|
||||
throw new SPException(
|
||||
__u('Encoding error'),
|
||||
SPException::CRITICAL,
|
||||
json_last_error_msg()
|
||||
);
|
||||
throw new SPException(__u('Encoding error'), SPException::ERROR, $e->getMessage());
|
||||
}
|
||||
|
||||
return $json;
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*
|
||||
@@ -27,7 +27,6 @@ namespace SP\Http;
|
||||
use Exception;
|
||||
use Klein\DataCollection\DataCollection;
|
||||
use Klein\DataCollection\HeaderDataCollection;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Core\Crypt\CryptPKI;
|
||||
use SP\Core\Crypt\Hash;
|
||||
use SP\Core\Exceptions\SPException;
|
||||
@@ -46,8 +45,9 @@ class Request implements RequestInterface
|
||||
*/
|
||||
public const SECURE_DIRS = ['css', 'js'];
|
||||
|
||||
private HeaderDataCollection $headers;
|
||||
private \Klein\Request $request;
|
||||
private CryptPKI $cryptPKI;
|
||||
private HeaderDataCollection $headers;
|
||||
private DataCollection $params;
|
||||
private ?string $method = null;
|
||||
private ?bool $https = null;
|
||||
@@ -55,9 +55,10 @@ class Request implements RequestInterface
|
||||
/**
|
||||
* Request constructor.
|
||||
*/
|
||||
public function __construct(\Klein\Request $request)
|
||||
public function __construct(\Klein\Request $request, CryptPKI $cryptPKI)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->cryptPKI = $cryptPKI;
|
||||
$this->headers = $this->request->headers();
|
||||
$this->params = $this->getParamsByMethod();
|
||||
$this->detectHttps();
|
||||
@@ -211,8 +212,7 @@ class Request implements RequestInterface
|
||||
|
||||
try {
|
||||
// Desencriptar con la clave RSA
|
||||
$clearData = BootstrapBase::getContainer()->get(CryptPKI::class)
|
||||
->decryptRSA(base64_decode($encryptedData));
|
||||
$clearData = $this->cryptPKI->decryptRSA(base64_decode($encryptedData));
|
||||
|
||||
// Desencriptar con la clave RSA
|
||||
if ($clearData === null) {
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
@@ -25,6 +25,7 @@
|
||||
namespace SP\Mvc\Controller;
|
||||
|
||||
use Closure;
|
||||
use Klein\Klein;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\Core\Exceptions\SPException;
|
||||
use SP\Domain\Config\In\ConfigDataInterface;
|
||||
@@ -42,6 +43,7 @@ use SP\Util\Util;
|
||||
*/
|
||||
trait ControllerTrait
|
||||
{
|
||||
protected Klein $router;
|
||||
protected string $controllerName;
|
||||
|
||||
protected function getControllerName(): string
|
||||
@@ -61,7 +63,11 @@ trait ControllerTrait
|
||||
/**
|
||||
* Logout from current session
|
||||
*
|
||||
* @throws \JsonException
|
||||
* @param \SP\Http\RequestInterface $request
|
||||
* @param \SP\Domain\Config\In\ConfigDataInterface $configData
|
||||
* @param \Closure $onRedirect
|
||||
*
|
||||
* @throws \SP\Core\Exceptions\SPException
|
||||
*/
|
||||
protected function sessionLogout(
|
||||
RequestInterface $request,
|
||||
@@ -72,7 +78,7 @@ trait ControllerTrait
|
||||
$jsonResponse = new JsonResponse(__u('Session not started or timed out'));
|
||||
$jsonResponse->setStatus(10);
|
||||
|
||||
Json::fromDic()->returnJson($jsonResponse);
|
||||
Json::factory($this->router->response())->returnJson($jsonResponse);
|
||||
} elseif ($request->isAjax()) {
|
||||
Util::logout();
|
||||
} else {
|
||||
@@ -105,11 +111,11 @@ trait ControllerTrait
|
||||
/**
|
||||
* Acción no disponible
|
||||
*
|
||||
* @throws \JsonException
|
||||
* @throws \SP\Core\Exceptions\SPException
|
||||
*/
|
||||
protected function invalidAction(): void
|
||||
{
|
||||
Json::fromDic()->returnJson(new JsonResponse(__u('Invalid Action')));
|
||||
Json::factory($this->router->response())->returnJson(new JsonResponse(__u('Invalid Action')));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
@@ -160,7 +160,7 @@ class PluginManager
|
||||
|
||||
/** @var PluginInterface $plugin */
|
||||
$plugin = $reflectionClass->newInstance(
|
||||
BootstrapBase::getContainer(),
|
||||
BootstrapBase::getContainer(), // FIXME
|
||||
new PluginOperation($this->pluginDataService, $pluginName)
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user