. */ namespace SP\Modules\Web\Controllers; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use SP\Core\Exceptions\SPException; use SP\Core\Install\Installer; use SP\Core\Language; use SP\DataModel\InstallData; use SP\Http\JsonResponse; use SP\Http\Request; use SP\Modules\Web\Controllers\Helpers\LayoutHelper; use SP\Modules\Web\Controllers\Traits\JsonTrait; use SP\Mvc\View\Components\SelectItemAdapter; use SP\Util\Checks; /** * Class InstallController * * @package SP\Modules\Web\Controllers */ class InstallController extends ControllerBase { use JsonTrait; /** * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface * @throws \SP\Core\Dic\ContainerException */ public function indexAction() { $layoutHelper = $this->dic->get(LayoutHelper::class); $layoutHelper->getPublicLayout('index', 'install'); $errors = []; if (!Checks::checkPhpVersion()) { $errors[] = [ 'type' => SPException::CRITICAL, 'description' => __('Versión de PHP requerida >= ') . ' 5.6.0 <= 7.0', 'hint' => __('Actualice la versión de PHP para que la aplicación funcione correctamente') ]; } $modules = Checks::checkModules(); if (count($modules) > 0) { foreach ($modules as $module) { $error[] = [ 'type' => SPException::WARNING, 'description' => sprintf('%s (%s)', __('Módulo no disponible'), $module), 'hint' => __('Sin este módulo la aplicación puede no funcionar correctamente.') ]; } } if (@file_exists(__FILE__ . "\0Nullbyte")) { $errors[] = [ 'type' => SPException::WARNING, 'description' => __('La version de PHP es vulnerable al ataque NULL Byte (CVE-2006-7243)'), 'hint' => __('Actualice la versión de PHP para usar sysPass de forma segura')]; } if (!Checks::secureRNGIsAvailable()) { $errors[] = [ 'type' => SPException::WARNING, 'description' => __('No se encuentra el generador de números aleatorios.'), 'hint' => __('Sin esta función un atacante puede utilizar su cuenta al resetear la clave')]; } $this->view->assign('errors', $errors); $this->view->assign('langs', SelectItemAdapter::factory(Language::getAvailableLanguages())->getItemsFromArraySelected([Language::$globalLang])); $this->view(); } /** * Performs sysPass installation * * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ public function installAction() { $installData = new InstallData(); $installData->setSiteLang(Request::analyze('sitelang', 'en_US')); $installData->setAdminLogin(Request::analyze('adminlogin', 'admin')); $installData->setAdminPass(Request::analyzeEncrypted('adminpass')); $installData->setMasterPassword(Request::analyzeEncrypted('masterpassword')); $installData->setDbAdminUser(Request::analyze('dbuser', 'root')); $installData->setDbAdminPass(Request::analyzeEncrypted('dbpass')); $installData->setDbName(Request::analyze('dbname', 'syspass')); $installData->setDbHost(Request::analyze('dbhost', 'localhost')); $installData->setHostingMode(Request::analyze('hostingmode', false)); try { Installer::run($installData); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS_STICKY, __('Instalación finalizada')); } catch (\Exception $e) { $this->returnJsonResponseException($e); } } }