mirror of
https://github.com/nuxsmin/sysPass.git
synced 2026-02-28 05:34:08 +01:00
98 lines
3.1 KiB
PHP
98 lines
3.1 KiB
PHP
<?php
|
|
/**
|
|
* sysPass
|
|
*
|
|
* @author nuxsmin
|
|
* @link http://syspass.org
|
|
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
|
|
*
|
|
* This file is part of sysPass.
|
|
*
|
|
* sysPass is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* sysPass is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* 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/>.
|
|
*/
|
|
|
|
namespace SP\Modules\Web\Controllers;
|
|
|
|
use SP\Core\Acl\ActionsInterface;
|
|
use SP\Core\Acl\UnauthorizedPageException;
|
|
use SP\Core\Exceptions\SPException;
|
|
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->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Proceso de backup finalizado'));
|
|
} catch (\Exception $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 {
|
|
$exportService = $this->dic->get(XmlExportService::class);
|
|
$exportService->doExport($exportPassword);
|
|
|
|
$this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Proceso de exportación finalizado'));
|
|
} catch (\Exception $e) {
|
|
$this->returnJsonResponseException($e);
|
|
}
|
|
}
|
|
|
|
protected function initialize()
|
|
{
|
|
try {
|
|
if (!$this->checkAccess(ActionsInterface::BACKUP_CONFIG)) {
|
|
throw new UnauthorizedPageException(SPException::INFO);
|
|
}
|
|
} catch (UnauthorizedPageException $e) {
|
|
$this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage(), [$e->getHint()]);
|
|
}
|
|
}
|
|
} |