diff --git a/app/modules/web/Controllers/ConfigBackupController.php b/app/modules/web/Controllers/ConfigBackupController.php index d3c730ba..4023ca07 100644 --- a/app/modules/web/Controllers/ConfigBackupController.php +++ b/app/modules/web/Controllers/ConfigBackupController.php @@ -160,7 +160,7 @@ final class ConfigBackupController extends SimpleControllerBase $this->eventDispatcher->notifyEvent('download.exportFile', new Event($this, EventMessage::factory() ->addDescription(__u('Archivo descargado')) - ->addDetail(__u('Archivo'), $file->getFile())) + ->addDetail(__u('Archivo'), str_replace(APP_ROOT, '', $file->getFile()))) ); $response = $this->router->response(); @@ -202,7 +202,7 @@ final class ConfigBackupController extends SimpleControllerBase $this->eventDispatcher->notifyEvent('download.backupAppFile', new Event($this, EventMessage::factory() ->addDescription(__u('Archivo descargado')) - ->addDetail(__u('Archivo'), $file->getFile())) + ->addDetail(__u('Archivo'), str_replace(APP_ROOT, '', $file->getFile()))) ); $response = $this->router->response(); @@ -244,7 +244,7 @@ final class ConfigBackupController extends SimpleControllerBase $this->eventDispatcher->notifyEvent('download.backupDbFile', new Event($this, EventMessage::factory() ->addDescription(__u('Archivo descargado')) - ->addDetail(__u('Archivo'), $file->getFile())) + ->addDetail(__u('Archivo'), str_replace(APP_ROOT, '', $file->getFile()))) ); $response = $this->router->response(); diff --git a/app/modules/web/Controllers/ConfigGeneralController.php b/app/modules/web/Controllers/ConfigGeneralController.php index df293f6d..b4919763 100644 --- a/app/modules/web/Controllers/ConfigGeneralController.php +++ b/app/modules/web/Controllers/ConfigGeneralController.php @@ -27,10 +27,13 @@ namespace SP\Modules\Web\Controllers; use SP\Config\ConfigUtil; use SP\Core\Acl\Acl; use SP\Core\Acl\UnauthorizedPageException; +use SP\Core\Context\SessionContext; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Http\JsonResponse; use SP\Modules\Web\Controllers\Traits\ConfigTrait; +use SP\Services\Config\ConfigBackupService; +use SP\Storage\File\FileHandler; /** * Class ConfigGeneral @@ -168,6 +171,95 @@ final class ConfigGeneralController extends SimpleControllerBase }); } + /** + * @return bool + * @throws \SP\Core\Exceptions\SPException + */ + public function downloadLogAction() + { + $this->checkSecurityToken($this->previousSk, $this->request); + + try { + SessionContext::close(); + + $file = new FileHandler(LOG_FILE); + $file->checkFileExists(); + + $this->eventDispatcher->notifyEvent('download.logFile', + new Event($this, EventMessage::factory() + ->addDescription(__u('Archivo descargado')) + ->addDetail(__u('Archivo'), str_replace(APP_ROOT, '', $file->getFile()))) + ); + + $response = $this->router->response(); + $response->header('Cache-Control', 'max-age=60, must-revalidate'); + $response->header('Content-length', $file->getFileSize()); + $response->header('Content-type', $file->getFileType()); + $response->header('Content-Description', ' sysPass file'); + $response->header('Content-transfer-encoding', 'chunked'); + $response->header('Content-Disposition', 'attachment; filename="' . basename($file->getFile()) . '"'); + $response->header('Set-Cookie', 'fileDownload=true; path=/'); + $response->send(); + + $file->readChunked(); + } catch (\Exception $e) { + processException($e); + + $this->eventDispatcher->notifyEvent('exception', new Event($e)); + } + + return ''; + } + + /** + * @param string $type + * + * @return bool + * @throws \SP\Core\Exceptions\SPException + */ + public function downloadConfigBackupAction($type) + { + $this->checkSecurityToken($this->previousSk, $this->request); + + try { + $this->eventDispatcher->notifyEvent('download.configBackupFile', + new Event($this, EventMessage::factory() + ->addDescription(__u('Archivo descargado')) + ->addDetail(__u('Archivo'), 'config.json')) + ); + + $configBackupService = $this->dic->get(ConfigBackupService::class); + + switch ($type) { + case 'json': + $data = ConfigBackupService::configToJson($configBackupService->getBackup()); + break; + default: + throw new \RuntimeException('Not implemented'); + } + + $response = $this->router->response(); + $response->header('Cache-Control', 'max-age=60, must-revalidate'); + $response->header('Content-length', strlen($data)); + $response->header('Content-type', 'application/json'); + $response->header('Content-Description', ' sysPass file'); + $response->header('Content-transfer-encoding', 'chunked'); + $response->header('Content-Disposition', 'attachment; filename="config.json"'); + $response->header('Set-Cookie', 'fileDownload=true; path=/'); + $response->header('Content-transfer-encoding', 'binary'); + $response->header('Set-Cookie', 'fileDownload=true; path=/'); + + $response->body($data); + $response->send(true); + } catch (\Exception $e) { + processException($e); + + $this->eventDispatcher->notifyEvent('exception', new Event($e)); + } + + return ''; + } + /** * @return bool */ diff --git a/app/modules/web/Controllers/ConfigManagerController.php b/app/modules/web/Controllers/ConfigManagerController.php index 3675a145..550fafdf 100644 --- a/app/modules/web/Controllers/ConfigManagerController.php +++ b/app/modules/web/Controllers/ConfigManagerController.php @@ -354,6 +354,11 @@ final class ConfigManagerController extends ControllerBase $template->assign('missingExtensions', $this->extensionChecker->getMissing()); $template->assign('downloadRate', round(Util::getMaxDownloadChunk() / 1024 / 1024)); + $isDemo = $this->configData->isDemoEnabled(); + + $template->assign('downloadConfigBackup', !$isDemo && $this->userData->getIsAdminApp()); + $template->assign('downloadLog', !$isDemo && is_readable(LOG_FILE) && $this->userData->getIsAdminApp()); + return new DataTab(__('Información'), $template); } diff --git a/app/modules/web/themes/material-blue/views/config/info.inc b/app/modules/web/themes/material-blue/views/config/info.inc index eff15099..25b9f0ca 100644 --- a/app/modules/web/themes/material-blue/views/config/info.inc +++ b/app/modules/web/themes/material-blue/views/config/info.inc @@ -88,6 +88,18 @@
+ + +