. */ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\ActionsInterface; use SP\Core\Acl\UnauthorizedPageException; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Http\JsonResponse; use SP\Http\Request; use SP\Modules\Web\Controllers\Traits\ConfigTrait; use SP\Services\Backup\FileBackupService; use SP\Services\Export\XmlExportService; /** * Class ConfigBackupController * * @package SP\Modules\Web\Controllers */ class ConfigBackupController extends SimpleControllerBase { use ConfigTrait; /** * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ public function fileBackupAction() { if ($this->config->getConfigData()->isDemoEnabled()) { $this->returnJsonResponse(JsonResponse::JSON_WARNING, __u('Ey, esto es una DEMO!!')); } try { $backupService = new FileBackupService(); $backupService->doBackup(); $this->eventDispatcher->notifyEvent('run.backup.end', new Event($this, EventMessage::factory() ->addDescription(__u('Copia de la aplicación y base de datos realizada correctamente'))) ); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Proceso de backup finalizado')); } catch (\Exception $e) { processException($e); $this->eventDispatcher->notifyEvent('exception', new Event($e)); $this->returnJsonResponseException($e); } } /** * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ public function xmlExportAction() { $exportPassword = Request::analyzeEncrypted('exportPwd'); $exportPasswordR = Request::analyzeEncrypted('exportPwdR'); if (!empty($exportPassword) && $exportPassword !== $exportPasswordR) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('Las claves no coinciden')); } try { $this->eventDispatcher->notifyEvent('run.export.start', new Event($this, EventMessage::factory() ->addDescription(__u('Exportación de sysPass en XML'))) ); $exportService = $this->dic->get(XmlExportService::class); $exportService->doExport($exportPassword); $this->eventDispatcher->notifyEvent('run.export.end', new Event($this, EventMessage::factory() ->addDescription(__u('Proceso de exportación finalizado'))) ); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Proceso de exportación finalizado')); } catch (\Exception $e) { processException($e); $this->eventDispatcher->notifyEvent('exception', new Event($e)); $this->returnJsonResponseException($e); } } protected function initialize() { try { $this->checkAccess(ActionsInterface::BACKUP_CONFIG); } catch (UnauthorizedPageException $e) { $this->eventDispatcher->notifyEvent('exception', new Event($e)); $this->returnJsonResponseException($e); } } }