* [FIX] Minor fixes

* [ADD] Configuration module. Work in progress.
This commit is contained in:
nuxsmin
2018-02-06 01:11:00 +01:00
parent 8ce69f38bc
commit 74741853bd
35 changed files with 1760 additions and 1236 deletions

View File

@@ -31,11 +31,11 @@ use SP\DataModel\ItemSearchData;
use SP\Http\Request;
use SP\Modules\Web\Controllers\Helpers\ItemsGridHelper;
use SP\Modules\Web\Controllers\Helpers\TabsGridHelper;
use SP\Repositories\AuthToken\AuthTokenRepository;
use SP\Repositories\PublicLink\PublicLinkRepository;
use SP\Repositories\User\UserRepository;
use SP\Repositories\UserGroup\UserGroupRepository;
use SP\Repositories\UserProfile\UserProfileRepository;
use SP\Services\AuthToken\AuthTokenService;
use SP\Services\PublicLink\PublicLinkService;
use SP\Services\User\UserService;
use SP\Services\UserGroup\UserGroupService;
use SP\Services\UserProfile\UserProfileService;
/**
* Class AccessMgmtController
@@ -110,50 +110,60 @@ class AccessManagerController extends ControllerBase
/**
* Returns users' data tab
*
* @throws \SP\Core\Dic\ContainerException
*/
protected function getUsersList()
{
$service = new UserRepository();
$service = new UserService();
return $this->itemsGridHelper->getUsersGrid($service->search($this->itemSearchData))->updatePager();
}
/**
* Returns users group data tab
*
* @throws \SP\Core\Dic\ContainerException
*/
protected function getUsersGroupList()
{
$service = new UserGroupRepository();
$service = new UserGroupService();
return $this->itemsGridHelper->getUserGroupsGrid($service->search($this->itemSearchData))->updatePager();
}
/**
* Returns users profile data tab
*
* @throws \SP\Core\Dic\ContainerException
*/
protected function getUsersProfileList()
{
$service = new UserProfileRepository();
$service = new UserProfileService();
return $this->itemsGridHelper->getUserProfilesGrid($service->search($this->itemSearchData))->updatePager();
}
/**
* Returns API tokens data tab
*
* @throws \SP\Core\Dic\ContainerException
*/
protected function getApiTokensList()
{
$service = new AuthTokenRepository();
$service = new AuthTokenService();
return $this->itemsGridHelper->getApiTokensGrid($service->search($this->itemSearchData))->updatePager();
}
/**
* Returns public links data tab
*
* @throws \SP\Core\Dic\ContainerException
*/
protected function getPublicLinksList()
{
$service = new PublicLinkRepository();
$service = new PublicLinkService();
return $this->itemsGridHelper->getPublicLinksGrid($service->search($this->itemSearchData))->updatePager();
}

View File

@@ -34,7 +34,6 @@ use SP\Core\SessionUtil;
use SP\DataModel\AccountExtData;
use SP\Forms\AccountForm;
use SP\Http\JsonResponse;
use SP\Http\Request;
use SP\Modules\Web\Controllers\Helpers\Account\AccountHelper;
use SP\Modules\Web\Controllers\Helpers\Account\AccountHistoryHelper;
use SP\Modules\Web\Controllers\Helpers\Account\AccountPasswordHelper;
@@ -43,7 +42,6 @@ use SP\Modules\Web\Controllers\Helpers\LayoutHelper;
use SP\Modules\Web\Controllers\Traits\ItemTrait;
use SP\Modules\Web\Controllers\Traits\JsonTrait;
use SP\Mvc\Controller\CrudControllerInterface;
use SP\Services\Account\AccountFileService;
use SP\Services\Account\AccountHistoryService;
use SP\Services\Account\AccountService;
use SP\Services\PublicLink\PublicLinkService;

View File

@@ -0,0 +1,231 @@
<?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\Controller\ControllerBase;
use SP\Core\Acl\Acl;
use SP\Core\Acl\ActionsInterface;
use SP\Core\Language;
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\User\UserService;
use SP\Services\UserGroup\UserGroupService;
use SP\Services\UserProfile\UserProfileService;
use SP\Util\Checks;
/**
* Class ConfigManagerController
*
* @package SP\Modules\Web\Controllers
*/
class ConfigManagerController extends ControllerBase
{
/**
* @var TabsHelper
*/
protected $tabsHelper;
/**
* @throws \SP\Core\Exceptions\InvalidArgumentException
* @throws \SP\Core\Dic\ContainerException
*/
public function indexAction()
{
$this->getTabs();
}
/**
* Returns a tabbed grid with items
*
* @throws \SP\Core\Exceptions\InvalidArgumentException
* @throws \SP\Core\Dic\ContainerException
*/
protected function getTabs()
{
$this->tabsHelper = new TabsHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
if ($this->checkAccess(ActionsInterface::CONFIG_GENERAL)) {
$this->tabsHelper->addTab($this->getConfigGeneral());
}
if ($this->checkAccess(ActionsInterface::ACCOUNT_CONFIG)) {
$this->tabsHelper->addTab($this->getAccountConfig());
}
if ($this->checkAccess(ActionsInterface::WIKI_CONFIG)) {
$this->tabsHelper->addTab($this->getWikiConfig());
}
if ($this->checkAccess(ActionsInterface::LDAP_CONFIG)) {
$this->tabsHelper->addTab($this->getLdapConfig());
}
if ($this->checkAccess(ActionsInterface::MAIL_CONFIG)) {
$this->tabsHelper->addTab($this->getMailConfig());
}
if ($this->checkAccess(ActionsInterface::ENCRYPTION_CONFIG)) {
// $this->tabsHelper->addTab($this->getEncryptionConfig());
}
if ($this->checkAccess(ActionsInterface::BACKUP_CONFIG)) {
// $this->tabsHelper->addTab($this->getBackupConfig());
}
if ($this->checkAccess(ActionsInterface::IMPORT_CONFIG)) {
// $this->tabsHelper->addTab($this->getImportConfig());
}
$this->eventDispatcher->notifyEvent('show.config', $this);
$this->tabsHelper->renderTabs(Acl::getActionRoute(ActionsInterface::CONFIG), Request::analyze('tabIndex', 0));
$this->view();
}
/**
* @return DataTab
*/
protected function getConfigGeneral()
{
$template = clone $this->view;
$template->setBase('config');
$template->addTemplate('general');
$userData = $this->session->getUserData();
$template->assign('langsAvailable', Language::getAvailableLanguages());
$template->assign('themesAvailable', $this->theme->getThemesAvailable());
$template->assign('isDemoMode', $this->configData->isDemoEnabled() && !$userData->getIsAdminApp());
$template->assign('isDisabled', $this->configData->isDemoEnabled() && !$userData->getIsAdminApp() ? 'disabled' : '');
$template->assign('configData', $this->configData);
$template->assign('users', SelectItemAdapter::factory(UserService::getItemsBasic())->getItemsFromModel());
$template->assign('userGroups', SelectItemAdapter::factory(UserGroupService::getItemsBasic())->getItemsFromModel());
$template->assign('userProfiles', SelectItemAdapter::factory(UserProfileService::getItemsBasic())->getItemsFromModel());
return new DataTab(__('General'), $template);
}
/**
* @return TabsHelper
*/
public function getTabsHelper()
{
return $this->tabsHelper;
}
/**
* @return DataTab
*/
protected function getAccountConfig()
{
$template = clone $this->view;
$template->setBase('config');
$template->addTemplate('accounts');
$template->assign('configData', $this->configData);
return new DataTab(__('Cuentas'), $template);
}
/**
* @return DataTab
*/
protected function getWikiConfig()
{
$template = clone $this->view;
$template->setBase('config');
$template->addTemplate('wiki');
$template->assign('configData', $this->configData);
return new DataTab(__('Wiki'), $template);
}
/**
* @return DataTab
*/
protected function getLdapConfig()
{
$template = clone $this->view;
$template->setBase('config');
$template->addTemplate('ldap');
$template->assign('ldapIsAvailable', Checks::ldapIsAvailable());
$template->assign('configData', $this->configData);
$template->assign('userGroups', SelectItemAdapter::factory(UserGroupService::getItemsBasic())->getItemsFromModel());
$template->assign('userProfiles', SelectItemAdapter::factory(UserProfileService::getItemsBasic())->getItemsFromModel());
return new DataTab(__('LDAP'), $template);
}
/**
* @return DataTab
*/
protected function getMailConfig()
{
$template = clone $this->view;
$template->setBase('config');
$template->addTemplate('mail');
$template->assign('mailSecurity', ['SSL', 'TLS']);
$template->assign('configData', $this->configData);
$template->assign('userGroups', SelectItemAdapter::factory(UserGroupService::getItemsBasic())->getItemsFromModel());
$template->assign('userProfiles', SelectItemAdapter::factory(UserProfileService::getItemsBasic())->getItemsFromModel());
return new DataTab(__('Correo'), $template);
}
/**
* @return DataTab
*/
protected function getEncryptionConfig()
{
$template = clone $this->view;
$template->setBase('config');
$template->addTemplate('mail');
$template->assign('mailSecurity', ['SSL', 'TLS']);
$template->assign('configData', $this->configData);
$this->view->assign('numAccounts', AccountUtil::getTotalNumAccounts());
$this->view->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());
$template->assign('userGroups', SelectItemAdapter::factory(UserGroupService::getItemsBasic())->getItemsFromModel());
$template->assign('userProfiles', SelectItemAdapter::factory(UserProfileService::getItemsBasic())->getItemsFromModel());
return new DataTab(__('Encriptación'), $template);
}
}

View File

@@ -51,6 +51,7 @@ class AccountActionsHelper extends HelperBase
/**
* @return DataGridAction
* @throws \ReflectionException
*/
public function getViewAction()
{
@@ -76,6 +77,7 @@ class AccountActionsHelper extends HelperBase
* @param AccountAcl $accountAcl
* @param AccountActionsDto $accountActionsDto
* @return DataGridAction[]
* @throws \ReflectionException
*/
public function getActionsForAccount(AccountAcl $accountAcl, AccountActionsDto $accountActionsDto)
{
@@ -183,6 +185,7 @@ class AccountActionsHelper extends HelperBase
/**
* @return DataGridAction
* @throws \ReflectionException
*/
public function getDeleteAction()
{
@@ -243,6 +246,7 @@ class AccountActionsHelper extends HelperBase
/**
* @return DataGridAction
* @throws \ReflectionException
*/
public function getViewPassAction()
{
@@ -265,6 +269,7 @@ class AccountActionsHelper extends HelperBase
/**
* @return DataGridAction
* @throws \ReflectionException
*/
public function getCopyPassAction()
{
@@ -290,6 +295,7 @@ class AccountActionsHelper extends HelperBase
/**
* @return DataGridAction
* @throws \ReflectionException
*/
public function getCopyAction()
{
@@ -311,6 +317,7 @@ class AccountActionsHelper extends HelperBase
/**
* @return DataGridAction
* @throws \ReflectionException
*/
public function getEditPassAction()
{
@@ -332,6 +339,7 @@ class AccountActionsHelper extends HelperBase
/**
* @return DataGridAction
* @throws \ReflectionException
*/
public function getEditAction()
{
@@ -353,6 +361,7 @@ class AccountActionsHelper extends HelperBase
/**
* @return DataGridAction
* @throws \ReflectionException
*/
public function getRequestAction()
{

View File

@@ -25,6 +25,7 @@
namespace SP\Modules\Web\Controllers\Helpers\Account;
use SP\Account\AccountAcl;
use SP\Core\Acl\AccountPermissionException;
use SP\Core\Acl\Acl;
use SP\Core\Acl\ActionsInterface;
use SP\Core\Acl\UnauthorizedPageException;
@@ -44,7 +45,6 @@ use SP\Services\Tag\TagService;
use SP\Services\User\UpdatedMasterPassException;
use SP\Services\User\UserService;
use SP\Services\UserGroup\UserGroupService;
use SP\Util\ErrorUtil;
/**
* Class AccountHelper
@@ -111,10 +111,12 @@ class AccountHelper extends HelperBase
*
* @param AccountDetailsResponse $accountDetailsResponse
* @param int $actionId
* @throws SPException
* @throws UnauthorizedPageException
* @throws UpdatedMasterPassException
* @throws \SP\Core\Dic\ContainerException
* @throws AccountPermissionException
* @throws SPException
* @throws \ReflectionException
*/
public function setViewForAccount(AccountDetailsResponse $accountDetailsResponse, $actionId)
{
@@ -123,7 +125,7 @@ class AccountHelper extends HelperBase
$this->accountAcl = new AccountAcl($actionId);
$this->checkActionAccess();
$this->checkAccess($accountDetailsResponse);
$accountAcl = $this->checkAccess($accountDetailsResponse);
$accountData = $accountDetailsResponse->getAccountVData();
$selectUsers = SelectItemAdapter::factory(UserService::getItemsBasic());
@@ -141,7 +143,7 @@ class AccountHelper extends HelperBase
$this->view->assign('maxFileSize', round($this->configData->getFilesAllowedSize() / 1024, 1));
$this->view->assign('filesAllowedExts', implode(',', $this->configData->getFilesAllowedExts()));
if ($this->configData->isPublinksEnabled() && $this->accountAcl->isShowLink()) {
if ($this->configData->isPublinksEnabled() && $accountAcl->isShowLink()) {
$publicLinkData = $this->publicLinkService->getHashForItem($this->accountId);
$publicLinkUrl = $publicLinkData ? PublicLinkService::getLinkForHash($publicLinkData->getHash()) : null;
@@ -160,7 +162,7 @@ class AccountHelper extends HelperBase
$this->view->assign('accountData', $accountData);
$this->view->assign('gotData', true);
$this->view->assign('actions', $this->getActionsHelper()->getActionsForAccount($this->accountAcl->getStoredAcl(), new AccountActionsDto($this->accountId, null, $accountData->getParentId())));
$this->view->assign('actions', $this->getActionsHelper()->getActionsForAccount($accountAcl, new AccountActionsDto($this->accountId, null, $accountData->getParentId())));
$this->setViewCommon();
}
@@ -184,7 +186,8 @@ class AccountHelper extends HelperBase
* Comprobar si el usuario dispone de acceso al módulo
*
* @param AccountDetailsResponse $accountDetailsResponse
* @return bool
* @return AccountAcl
* @throws AccountPermissionException
*/
protected function checkAccess(AccountDetailsResponse $accountDetailsResponse)
{
@@ -198,13 +201,13 @@ class AccountHelper extends HelperBase
$acccountAclDto->setUsersId($accountDetailsResponse->getUsers());
$acccountAclDto->setUserGroupsId($accountDetailsResponse->getUserGroups());
if (!$this->accountAcl->getAcl($acccountAclDto)->checkAccountAccess()) {
ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_ACCOUNT_NO_PERMISSION);
$accountAcl = $this->accountAcl->getAcl($acccountAclDto);
return false;
if ($accountAcl === null || !$accountAcl->checkAccountAccess()) {
throw new AccountPermissionException(SPException::SP_INFO);
}
return true;
return $accountAcl;
}
/**

View File

@@ -36,12 +36,8 @@ use SP\Html\DataGrid\DataGridHeaderSort;
use SP\Html\DataGrid\DataGridPager;
use SP\Html\DataGrid\DataGridSort;
use SP\Http\Request;
use SP\Modules\Web\Controllers\Helpers\Account\AccountActionsHelper;
use SP\Modules\Web\Controllers\Helpers\HelperBase;
use SP\Mvc\View\Components\SelectItemAdapter;
use SP\Repositories\Category\CategoryRepository;
use SP\Repositories\Client\ClientRepository;
use SP\Repositories\Tag\TagRepository;
use SP\Services\Account\AccountSearchService;
use SP\Services\Category\CategoryService;
use SP\Services\Client\ClientService;

View File

@@ -950,6 +950,7 @@ class ItemsGridHelper extends HelperBase
// Grid Header
$GridHeaders = new DataGridHeader();
$GridHeaders->addHeader(__('Cuenta'));
$GridHeaders->addHeader(__('Cliente'));
$GridHeaders->addHeader(__('Fecha Creación'));
$GridHeaders->addHeader(__('Fecha Caducidad'));
$GridHeaders->addHeader(__('Usuario'));
@@ -960,6 +961,7 @@ class ItemsGridHelper extends HelperBase
$GridData = new DataGridData();
$GridData->setDataRowSourceId('id');
$GridData->addDataRowSource('accountName');
$GridData->addDataRowSource('clientName');
$GridData->addDataRowSource('getDateAddFormat', true);
$GridData->addDataRowSource('getDateExpireFormat', true);
$GridData->addDataRowSource('userLogin');

View File

@@ -0,0 +1,71 @@
<?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\Helpers;
use SP\Mvc\View\Components\DataTab;
/**
* Class TabsHelper
*
* @package SP\Modules\Web\Controllers\Helpers
*/
class TabsHelper extends HelperBase
{
/**
* Máximo numero de acciones antes de agrupar
*/
const MAX_NUM_ACTIONS = 3;
/**
* @var DataTab[]
*/
protected $tabs = [];
/**
* Inicializar las plantillas para las pestañas
*
* @param string $route
* @param int $activeTab
*/
public function renderTabs($route, $activeTab = 0)
{
$this->view->addTemplate('datatabs', 'common');
$this->view->assign('tabs', $this->tabs);
$this->view->assign('activeTab', $activeTab);
$this->view->assign('maxNumActions', self::MAX_NUM_ACTIONS);
$this->view->assign('tabsRoute', $route);
}
/**
* Add a new data tab
*
* @param DataTab $tab
*/
public function addTab(DataTab $tab)
{
$this->tabs[] = $tab;
}
}

View File

@@ -31,14 +31,14 @@ use SP\DataModel\ItemSearchData;
use SP\Http\Request;
use SP\Modules\Web\Controllers\Helpers\ItemsGridHelper;
use SP\Modules\Web\Controllers\Helpers\TabsGridHelper;
use SP\Repositories\Account\AccountFileRepository;
use SP\Repositories\Account\AccountHistoryRepository;
use SP\Repositories\Account\AccountRepository;
use SP\Repositories\Category\CategoryRepository;
use SP\Repositories\Client\ClientRepository;
use SP\Repositories\CustomField\CustomFieldDefRepository;
use SP\Repositories\Plugin\PluginRepository;
use SP\Repositories\Tag\TagRepository;
use SP\Services\Account\AccountFileService;
use SP\Services\Account\AccountHistoryService;
use SP\Services\Account\AccountService;
use SP\Services\Category\CategoryService;
use SP\Services\Client\ClientService;
use SP\Services\CustomField\CustomFieldDefService;
use SP\Services\Tag\TagService;
/**
* Class ItemManagerController
@@ -125,70 +125,84 @@ class ItemManagerController extends ControllerBase
/**
* Returns categories' data tab
*
* @throws \SP\Core\Dic\ContainerException
*/
protected function getCategoriesList()
{
$service = new CategoryRepository();
$service = new CategoryService();
return $this->itemsGridHelper->getCategoriesGrid($service->search($this->itemSearchData))->updatePager();
}
/**
* Returns tags' data tab
*
* @throws \SP\Core\Dic\ContainerException
*/
protected function getTagsList()
{
$service = new TagRepository();
$service = new TagService();
return $this->itemsGridHelper->getTagsGrid($service->search($this->itemSearchData))->updatePager();
}
/**
* Returns clients' data tab
*
* @throws \SP\Core\Dic\ContainerException
*/
protected function getClientsList()
{
$service = new ClientRepository();
$service = new ClientService();
return $this->itemsGridHelper->getClientsGrid($service->search($this->itemSearchData))->updatePager();
}
/**
* Returns custom fields' data tab
*
* @throws \SP\Core\Dic\ContainerException
*/
protected function getCustomFieldsList()
{
$service = new CustomFieldDefRepository();
$service = new CustomFieldDefService();
return $this->itemsGridHelper->getCustomFieldsGrid($service->search($this->itemSearchData))->updatePager();
}
/**
* Returns account files' data tab
*
* @throws \SP\Core\Dic\ContainerException
*/
protected function getAccountFilesList()
{
$service = new AccountFileRepository();
$service = new AccountFileService();
return $this->itemsGridHelper->getFilesGrid($service->search($this->itemSearchData))->updatePager();
}
/**
* Returns accounts' data tab
*
* @throws \SP\Core\Dic\ContainerException
*/
protected function getAccountsList()
{
$service = new AccountRepository();
$service = new AccountService();
return $this->itemsGridHelper->getAccountsGrid($service->search($this->itemSearchData))->updatePager();
}
/**
* Returns accounts' history data tab
*
* @throws \SP\Core\Dic\ContainerException
*/
protected function getAccountsHistoryList()
{
$service = new AccountHistoryRepository();
$service = new AccountHistoryService();
return $this->itemsGridHelper->getAccountsHistoryGrid($service->search($this->itemSearchData))->updatePager();
}
@@ -198,6 +212,7 @@ class ItemManagerController extends ControllerBase
*/
protected function getPluginsList()
{
// FIXME: create Plugin Service
$service = new PluginRepository();
return $this->itemsGridHelper->getPluginsGrid($service->search($this->itemSearchData))->updatePager();