* [ADD] syspass.log file and configuration backup can now be downloaded from Information tab

Signed-off-by: nuxsmin <nuxsmin@syspass.org>
This commit is contained in:
nuxsmin
2018-11-01 11:35:14 +01:00
parent ec97b603b0
commit e1f2f0b0f0
9 changed files with 187 additions and 28 deletions

View File

@@ -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
*/