diff --git a/app/modules/web/Controllers/ConfigManagerController.php b/app/modules/web/Controllers/ConfigManagerController.php index a2efa3e0..dbd33ba4 100644 --- a/app/modules/web/Controllers/ConfigManagerController.php +++ b/app/modules/web/Controllers/ConfigManagerController.php @@ -24,17 +24,27 @@ namespace SP\Modules\Web\Controllers; +use SP\Bootstrap; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; +use SP\Core\Crypt\CryptSessionHandler; +use SP\Core\CryptMasterPass; use SP\Core\Language; +use SP\Core\Plugin\PluginUtil; +use SP\Core\Task; use SP\Http\Request; use SP\Modules\Web\Controllers\Helpers\TabsHelper; use SP\Mvc\View\Components\DataTab; use SP\Mvc\View\Components\SelectItemAdapter; +use SP\Services\Account\AccountService; +use SP\Services\Config\ConfigService; use SP\Services\User\UserService; use SP\Services\UserGroup\UserGroupService; use SP\Services\UserProfile\UserProfileService; +use SP\Storage\DBUtil; +use SP\Storage\MySQLHandler; use SP\Util\Checks; +use SP\Util\Util; /** * Class ConfigManagerController @@ -52,6 +62,7 @@ class ConfigManagerController extends ControllerBase * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Exceptions\InvalidArgumentException + * @throws \SP\Services\Config\ParameterNotFoundException */ public function indexAction() { @@ -64,6 +75,7 @@ class ConfigManagerController extends ControllerBase * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Exceptions\InvalidArgumentException + * @throws \SP\Services\Config\ParameterNotFoundException */ protected function getTabs() { @@ -90,15 +102,19 @@ class ConfigManagerController extends ControllerBase } if ($this->checkAccess(ActionsInterface::ENCRYPTION_CONFIG)) { -// $this->tabsHelper->addTab($this->getEncryptionConfig()); + $this->tabsHelper->addTab($this->getEncryptionConfig()); } if ($this->checkAccess(ActionsInterface::BACKUP_CONFIG)) { -// $this->tabsHelper->addTab($this->getBackupConfig()); + $this->tabsHelper->addTab($this->getBackupConfig()); } if ($this->checkAccess(ActionsInterface::IMPORT_CONFIG)) { -// $this->tabsHelper->addTab($this->getImportConfig()); + $this->tabsHelper->addTab($this->getImportConfig()); + } + + if ($this->checkAccess(ActionsInterface::CONFIG_GENERAL)) { + $this->tabsHelper->addTab($this->getInfo()); } @@ -135,14 +151,6 @@ class ConfigManagerController extends ControllerBase return new DataTab(__('General'), $template); } - /** - * @return TabsHelper - */ - public function getTabsHelper() - { - return $this->tabsHelper; - } - /** * @return DataTab */ @@ -213,28 +221,130 @@ class ConfigManagerController extends ControllerBase * @return DataTab * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Services\Config\ParameterNotFoundException */ protected function getEncryptionConfig() { $template = clone $this->view; $template->setBase('config'); - $template->addTemplate('mail'); + $template->addTemplate('encryption'); $template->assign('mailSecurity', ['SSL', 'TLS']); $template->assign('configData', $this->configData); - $this->view->assign('numAccounts', AccountUtil::getTotalNumAccounts()); - $this->view->assign('taskId', Task::genTaskId('masterpass')); + $template->assign('numAccounts', $this->dic->get(AccountService::class)->getTotalNumAccounts()); + $template->assign('taskId', Task::genTaskId('masterpass')); - $this->view->assign('lastUpdateMPass', isset($this->configDB['lastupdatempass']) ? $this->configDB['lastupdatempass'] : 0); - $this->view->assign('tempMasterPassTime', isset($this->configDB['tempmaster_passtime']) ? $this->configDB['tempmaster_passtime'] : 0); - $this->view->assign('tempMasterMaxTime', isset($this->configDB['tempmaster_maxtime']) ? $this->configDB['tempmaster_maxtime'] : 0); - $this->view->assign('tempMasterAttempts', isset($this->configDB['tempmaster_attempts']) ? sprintf('%d/%d', $this->configDB['tempmaster_attempts'], CryptMasterPass::MAX_ATTEMPTS) : 0); - $this->view->assign('tempMasterPass', SessionFactory::getTemporaryMasterPass()); + $configService = $this->dic->get(ConfigService::class); + + $template->assign('lastUpdateMPass', $configService->getByParam('lastupdatempass', 0)); + $template->assign('tempMasterPassTime', $configService->getByParam('tempmaster_passtime', 0)); + $template->assign('tempMasterMaxTime', $configService->getByParam('tempmaster_maxtime', 0)); + + $tempMasterAttempts = sprintf('%d/%d', $configService->getByParam('tempmaster_attempts', 0), CryptMasterPass::MAX_ATTEMPTS); + + $template->assign('tempMasterAttempts', $tempMasterAttempts); + $template->assign('tempMasterPass', $this->session->getTemporaryMasterPass()); $template->assign('userGroups', SelectItemAdapter::factory(UserGroupService::getItemsBasic())->getItemsFromModel()); - $template->assign('userProfiles', SelectItemAdapter::factory(UserProfileService::getItemsBasic())->getItemsFromModel()); return new DataTab(__('Encriptación'), $template); } + + /** + * @return DataTab + */ + protected function getBackupConfig() + { + $template = clone $this->view; + $template->setBase('config'); + $template->addTemplate('backup'); + + $template->assign('siteName', Util::getAppInfo('appname')); + $template->assign('backupDir', Bootstrap::$SERVERROOT . '/backup'); + $template->assign('backupPath', Bootstrap::$WEBROOT . '/backup'); + + $backupHash = $this->configData->getBackupHash(); + $exportHash = $this->configData->getExportHash(); + + $backupFile = $template->siteName . '-' . $backupHash . '.tar.gz'; + + $template->assign('backupFile', [ + 'absolute' => $template->backupDir . DIRECTORY_SEPARATOR . $backupFile, + 'relative' => $template->backupPath . '/' . $backupFile, + 'filename' => $backupFile + ]); + + $backupDbFile = $template->siteName . '_db-' . $backupHash . '.sql'; + + $template->assign('backupDbFile', [ + 'absolute' => $template->backupDir . DIRECTORY_SEPARATOR . $backupDbFile, + 'relative' => $template->backupPath . '/' . $backupDbFile, + 'filename' => $backupDbFile + ]); + + clearstatcache(true, $template->backupFile['absolute']); + clearstatcache(true, $template->backupDbFile['absolute']); + + $template->assign('lastBackupTime', file_exists($template->backupFile['absolute']) ? __('Último backup') . ': ' . date('r', filemtime($template->backupFile['absolute'])) : __('No se encontraron backups')); + + $exportFile = $template->siteName . '-' . $exportHash . '.xml'; + + $template->assign('exportFile', [ + 'absolute' => $template->backupDir . DIRECTORY_SEPARATOR . $exportFile, + 'relative' => $template->backupPath . '/' . $exportFile, + 'filename' => $exportFile + ]); + + clearstatcache(true, $template->exportFile['absolute']); + + $template->assign('lastExportTime', file_exists($template->exportFile['absolute']) ? __('Última exportación') . ': ' . date('r', filemtime($template->exportFile['absolute'])) : __('No se encontró archivo de exportación')); + + return new DataTab(__('Copia de Seguridad'), $template); + } + + /** + * @return DataTab + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + */ + protected function getImportConfig() + { + $template = clone $this->view; + $template->setBase('config'); + $template->addTemplate('import'); + + $template->assign('userGroups', SelectItemAdapter::factory(UserGroupService::getItemsBasic())->getItemsFromModelSelected([$this->userData->getUserGroupId()])); + $template->assign('users', SelectItemAdapter::factory(UserService::getItemsBasic())->getItemsFromModelSelected([$this->userData->getId()])); + + return new DataTab(__('Importar Cuentas'), $template); + } + + /** + * @return DataTab + * @throws \SP\Core\Exceptions\SPException + */ + protected function getInfo() + { + $template = clone $this->view; + $template->setBase('config'); + $template->addTemplate('info'); + + $template->assign('dbInfo', DBUtil::getDBinfo($this->dic->get(MySQLHandler::class))); + $template->assign('dbName', $this->configData->getDbName() . '@' . $this->configData->getDbHost()); + $template->assign('configBackupDate', date('r', $this->dic->get(ConfigService::class)->getByParam('config_backupdate', 0))); + $template->assign('plugins', PluginUtil::getLoadedPlugins()); + $template->assign('locale', Language::$localeStatus ?: sprintf('%s (%s)', $this->configData->getSiteLang(), __('No instalado'))); + $template->assign('securedSession', CryptSessionHandler::$isSecured); + + return new DataTab(__('Información'), $template); + } + + /** + * @return TabsHelper + */ + public function getTabsHelper() + { + return $this->tabsHelper; + } } \ No newline at end of file diff --git a/app/modules/web/themes/material-blue/views/config/accounts.inc b/app/modules/web/themes/material-blue/views/config/accounts.inc index f2788f26..a536a8ca 100644 --- a/app/modules/web/themes/material-blue/views/config/accounts.inc +++ b/app/modules/web/themes/material-blue/views/config/accounts.inc @@ -303,9 +303,6 @@ - - -
diff --git a/app/modules/web/themes/material-blue/views/config/backup.inc b/app/modules/web/themes/material-blue/views/config/backup.inc index ac2a1608..19788c1d 100644 --- a/app/modules/web/themes/material-blue/views/config/backup.inc +++ b/app/modules/web/themes/material-blue/views/config/backup.inc @@ -1,199 +1,182 @@ - -
-
-
- -
+
+ +
- +
+ + + + + + + + + + +
+ + +
+ + +
+ + +
+ + + + + + + + + + + +
+ +
+
+ +
+
    +
  • + + +
    +

    + +

    +
    +
  • +
  • + + +
  • +
+
+ +
+ +
+ +
+ + + + + + - - - - + + + + + + + +
+ + +
+ + +
- + -
+
- + + + + + +
- - -
+ +
+ + +
+ + +
+
+ + +
+ + +
+
+
- - - - +
+
    +
  • + +
  • +
  • + - - - - - - - - - +
    +

    -
    +

    - - - -
    +

    -
    -
      -
    • - - -
      -

      - -

      -
      -
    • -
    • - - -
    • -
    -
    - -
    - -
    - -
    - - - - - - - - - - - - - - - - - - - -
    - - -
    - - -
    - - -
    - - - - - - - -
    - - -
    - - -
    -
    - - -
    - - -
    -
    - - - - -
    - -
    -
      -
    • - -
    • -
    • - - -
      -

      - -

      - -

      - -

      -
      -
    • -
    • - -
    • -
    -
    -
    -
\ No newline at end of file +

+
+ +
  • + +
  • + +
    diff --git a/app/modules/web/themes/material-blue/views/config/encryption.inc b/app/modules/web/themes/material-blue/views/config/encryption.inc index 3e9259f5..ae3b3847 100644 --- a/app/modules/web/themes/material-blue/views/config/encryption.inc +++ b/app/modules/web/themes/material-blue/views/config/encryption.inc @@ -1,316 +1,303 @@ - -
    -
    +
    -
    - -
    - - - - 0): ?> - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - -
    - - -
    - - -
    - - -
    -
    - - -
    - - -
    -
    - - -
    - - -
    -
    -
    getIconHelp()->getIcon(); ?>
    -
    -

    - -

    -
    -
    - -
    -
    getIconWarning()->getIcon(); ?>
    - -
    -
    getIconWarning()->getIcon(); ?>
    - -
    -
    getIconWarning()->getIcon(); ?>
    - -
    -
    getIconWarning()->getIcon(); ?>
    - -
    - -
    - - = 500): ?> - - - - - - - - - -
    -
    -
      -
    • - - -
      -

      - -

      - -

      https://doc.syspass.org'); ?>

      -
      -
    • - -
    • - -
    • - - - 0): ?> -
    • - -
    • - -
    -
    - -
    - -
    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - -
    - - 0) ? date('r', $tempMasterPassTime) : __('No generada'); ?> -
    - - -
    - - $tempMasterMaxTime): ?> - - 0): echo date('r', $tempMasterMaxTime); ?> - - -
    - - -
    - - -
    - - -
    - - -
    -
    - - -
    getIconHelp()->getIcon(); ?>
    -
    -

    - -

    -
    -
    - -
    - - -
    - - -
    - - -
    - - -
    - - - -
    -
    -
      -
    • - -
    • -
    • - - - -
      -

      -
      -
    • -
    • - -
    • -
    -
    +
    +
    -
    \ No newline at end of file + + + 0): ?> + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + +
    + + +
    + + +
    + + +
    +
    + + +
    + + +
    +
    + + +
    + + +
    +
    +
    getIconHelp()->getIcon(); ?>
    +
    +

    + +

    +
    +
    + +
    +
    getIconWarning()->getIcon(); ?>
    + +
    +
    getIconWarning()->getIcon(); ?>
    + +
    +
    getIconWarning()->getIcon(); ?>
    + +
    +
    getIconWarning()->getIcon(); ?>
    + +
    + +
    + + = 500): ?> + + + + + +
    +
      +
    • + + +
      +

      + +

      + +

      https://doc.syspass.org'); ?>

      +
      +
    • + +
    • + +
    • + + + 0): ?> +
    • + +
    • + +
    +
    + +
    + +
    + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + +
    + + 0) ? date('r', $tempMasterPassTime) : __('No generada'); ?> +
    + + +
    + + $tempMasterMaxTime): ?> + + 0): echo date('r', $tempMasterMaxTime); ?> + + +
    + + +
    + + +
    + + +
    + + +
    +
    + + +
    getIconHelp()->getIcon(); ?>
    +
    +

    + +

    +
    +
    + +
    + + +
    + + +
    + + +
    + + +
    + + +
    + +
    +
      +
    • + +
    • +
    • + + + +
      +

      +
      +
    • +
    • + +
    • +
    +
    diff --git a/app/modules/web/themes/material-blue/views/config/import.inc b/app/modules/web/themes/material-blue/views/config/import.inc index 914ce33d..cd554bbb 100644 --- a/app/modules/web/themes/material-blue/views/config/import.inc +++ b/app/modules/web/themes/material-blue/views/config/import.inc @@ -1,197 +1,197 @@ - + - -
    -
    -
    - -
    +
    + +
    - - - - + +
    - -
    getIconHelp()->getIcon(); ?>
    -
    -

    - -

    -
    -
    -
    + + + + - - - - + + + + - - - - + + + + - -
    + +
    getIconHelp()->getIcon(); ?>
    +
    +

    + +

    +
    +
    +
    - -
    - -
    getIconHelp()->getIcon(); ?>
    -
    -

    - -

    -
    -
    -
    + +
    + +
    getIconHelp()->getIcon(); ?>
    +
    +

    + +

    +
    +
    +
    - -
    - - -
    + +
    + + +
    -
    - cloud_upload -
    -
    - -
    -
    +
    + cloud_upload +
    +
    + +
    +
    -
    -
      -
    • - -
    • -
    • - +
      +
        +
      • + +
      • +
      • + -
        -

        +
        +

        -

        +

        -

        +

        -

        +

        -

        +

        -

        +

        -

        -
        -
      • -
      -
      +

      +
    + + +
    -
    - -
    +
    + +
    - - - - - - - - - -
    - -
    getIconHelp()->getIcon(); ?>
    -
    -

    - -

    -
    -
    -
    - - -
    -
    - -
    getIconHelp()->getIcon(); ?>
    -
    -

    - -

    -
    -
    -
    - - -
    -
    + + + + + + + + + +
    + +
    getIconHelp()->getIcon(); ?>
    +
    +

    + +

    +
    +
    +
    + + +
    +
    + +
    getIconHelp()->getIcon(); ?>
    +
    +

    + +

    +
    +
    +
    + + +
    +
    -
    - -
    +
    + +
    - - - - - -
    - -
    getIconHelp()->getIcon(); ?>
    -
    -

    - -

    -
    -
    -
    - - -
    -
    -
    -
    \ No newline at end of file + + + + + +
    + +
    getIconHelp()->getIcon(); ?>
    +
    +

    + +

    +
    +
    +
    + + +
    +
    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 7a878f7d..cd78d82e 100644 --- a/app/modules/web/themes/material-blue/views/config/info.inc +++ b/app/modules/web/themes/material-blue/views/config/info.inc @@ -1,127 +1,124 @@ - -
    -
    -
    - -
    +
    + +
    - - - - + +
    - - -
    + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - + + + - + - - - - + + + + - - - - + + + + - -
    + + +
    - -
    - - -
    + +
    + + +
    - $infoval): ?> - -
    - - -
    - - -
    + $infoval): ?> + +
    + + +
    + + +
    - -
    - -
    - -
    - - =')): ?> -
    - - $value): ?> -
    - - -
    - - -
    + +
    + +
    + +
    + + =')): ?> +
    + + $value): ?> +
    + + +
    + + +
    - -
    - - -
    + +
    + + +
    - -
    - -
    getIconHelp()->getIcon(); ?>
    -
    -

    - -

    + +
    + +
    getIconHelp()->getIcon(); ?>
    +
    +

    + +

    -

    - -

    -
    -
    -
    +

    + +

    + +
    +
    - -
    - -
    getIconHelp()->getIcon(); ?>
    -
    -

    - -

    -
    -
    -
    + +
    + +
    getIconHelp()->getIcon(); ?>
    +
    +

    + +

    +
    +
    +
    - -
    - - -
    + +
    + + +
    -
      - $plugin): ?> -
    • +
        + $plugin): ?> +
      • extension @@ -130,22 +127,21 @@
        getAuthor()); ?>
        -
      • - -
      -
    - -
    -
      -
    • - -
    • -
    -
    - \ No newline at end of file + + + +
    + +
    +
      +
    • + +
    • +
    +
    diff --git a/lib/SP/Services/Config/ConfigService.php b/lib/SP/Services/Config/ConfigService.php index b5a1cabb..05c0563c 100644 --- a/lib/SP/Services/Config/ConfigService.php +++ b/lib/SP/Services/Config/ConfigService.php @@ -59,20 +59,26 @@ class ConfigService extends Service /** * @param string $param + * @param null $default * @return mixed * @throws ParameterNotFoundException */ - public function getByParam($param) + public function getByParam($param, $default = null) { $query = $this->configRepository->getByParam($param); if (empty($query)) { + if ($default !== null) { + return $default; + } + throw new ParameterNotFoundException( sprintf(__('Parámetro no encontrado (%s)'), SPException::ERROR, $param) ); } + return $query->value; } diff --git a/lib/SP/Util/Util.php b/lib/SP/Util/Util.php index 67d97a4a..622a6bf4 100644 --- a/lib/SP/Util/Util.php +++ b/lib/SP/Util/Util.php @@ -371,7 +371,8 @@ class Util 'appupdates' => 'https://api.github.com/repos/nuxsmin/sysPass/releases/latest', 'appnotices' => 'https://api.github.com/repos/nuxsmin/sysPass/issues?milestone=none&state=open&labels=Notices', 'apphelp' => 'https://github.com/nuxsmin/sysPass/issues', - 'appchangelog' => 'https://github.com/nuxsmin/sysPass/blob/master/CHANGELOG']; + 'appchangelog' => 'https://github.com/nuxsmin/sysPass/blob/master/CHANGELOG' + ]; if (null !== $index && isset($appinfo[$index])) { return $appinfo[$index];