* [FIX] Fixed search grid behavior

This commit is contained in:
nuxsmin
2018-03-03 11:08:21 +01:00
parent 68b7b0ab31
commit 7ec589a6fe
20 changed files with 273 additions and 512 deletions

View File

@@ -220,7 +220,6 @@ class AccountFileController extends ControllerBase implements CrudControllerInte
*
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
* @throws \SP\Core\Dic\ContainerException
*/
public function searchAction()
{
@@ -228,16 +227,27 @@ class AccountFileController extends ControllerBase implements CrudControllerInte
return;
}
$itemsGridHelper = $this->dic->get(ItemsGridHelper::class);
$grid = $itemsGridHelper->getFilesGrid($this->accountFileService->search($this->getSearchData($this->configData)))->updatePager();
$this->view->addTemplate('datagrid-table', 'grid');
$this->view->assign('index', Request::analyze('activetab', 0));
$this->view->assign('data', $grid);
$this->view->assign('data', $this->getSearchGrid());
$this->returnJsonResponseData(['html' => $this->render()]);
}
/**
* getSearchGrid
*
* @return $this
* @throws \SP\Core\Dic\ContainerException
*/
protected function getSearchGrid()
{
$itemsGridHelper = $this->dic->get(ItemsGridHelper::class);
$itemSearchData = $this->getSearchData($this->configData->getAccountCount());
return $itemsGridHelper->updatePager($itemsGridHelper->getFilesGrid($this->accountFileService->search($itemSearchData)), $itemSearchData);
}
/**
* Create action
*/

View File

@@ -70,16 +70,27 @@ class ApiTokenController extends ControllerBase implements CrudControllerInterfa
return;
}
$itemsGridHelper = $this->dic->get(ItemsGridHelper::class);
$grid = $itemsGridHelper->getApiTokensGrid($this->authTokenService->search($this->getSearchData($this->configData)))->updatePager();
$this->view->addTemplate('datagrid-table', 'grid');
$this->view->assign('index', Request::analyze('activetab', 0));
$this->view->assign('data', $grid);
$this->view->assign('data', $this->getSearchGrid());
$this->returnJsonResponseData(['html' => $this->render()]);
}
/**
* getSearchGrid
*
* @return $this
* @throws \SP\Core\Dic\ContainerException
*/
protected function getSearchGrid()
{
$itemsGridHelper = $this->dic->get(ItemsGridHelper::class);
$itemSearchData = $this->getSearchData($this->configData->getAccountCount());
return $itemsGridHelper->updatePager($itemsGridHelper->getApiTokensGrid($this->authTokenService->search($itemSearchData)), $itemSearchData);
}
/**
* Create action
*

View File

@@ -67,16 +67,27 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa
return;
}
$itemsGridHelper = $this->dic->get(ItemsGridHelper::class);
$grid = $itemsGridHelper->getCategoriesGrid($this->categoryService->search($this->getSearchData($this->configData)))->updatePager();
$this->view->addTemplate('datagrid-table', 'grid');
$this->view->assign('index', Request::analyze('activetab', 0));
$this->view->assign('data', $grid);
$this->view->assign('data', $this->getSearchGrid());
$this->returnJsonResponseData(['html' => $this->render()]);
}
/**
* getSearchGrid
*
* @return $this
* @throws \SP\Core\Dic\ContainerException
*/
protected function getSearchGrid()
{
$itemsGridHelper = $this->dic->get(ItemsGridHelper::class);
$itemSearchData = $this->getSearchData($this->configData->getAccountCount());
return $itemsGridHelper->updatePager($itemsGridHelper->getCategoriesGrid($this->categoryService->search($itemSearchData)), $itemSearchData);
}
/**
* Create action
*

View File

@@ -68,16 +68,27 @@ class ClientController extends ControllerBase implements CrudControllerInterface
return;
}
$itemsGridHelper = $this->dic->get(ItemsGridHelper::class);
$grid = $itemsGridHelper->getClientsGrid($this->clientService->search($this->getSearchData($this->configData)))->updatePager();
$this->view->addTemplate('datagrid-table', 'grid');
$this->view->assign('index', Request::analyze('activetab', 0));
$this->view->assign('data', $grid);
$this->view->assign('data', $this->getSearchGrid());
$this->returnJsonResponseData(['html' => $this->render()]);
}
/**
* getSearchGrid
*
* @return $this
* @throws \SP\Core\Dic\ContainerException
*/
protected function getSearchGrid()
{
$itemsGridHelper = $this->dic->get(ItemsGridHelper::class);
$itemSearchData = $this->getSearchData($this->configData->getAccountCount());
return $itemsGridHelper->updatePager($itemsGridHelper->getClientsGrid($this->clientService->search($itemSearchData)), $itemSearchData);
}
/**
* Create action
*

View File

@@ -153,6 +153,8 @@ abstract class ControllerBase
$this->view->setBase(strtolower($this->controllerName));
$this->icons = $this->theme->getIcons();
$this->userData = clone $this->session->getUserData();
$this->userProfileData = clone $this->session->getUserProfile();
$this->setViewVars();
@@ -166,9 +168,6 @@ abstract class ControllerBase
*/
private function setViewVars()
{
$this->userData = $this->session->getUserData();
$this->userProfileData = $this->session->getUserProfile();
$this->view->assign('timeStart', $this->router->request()->server()->get('REQUEST_TIME_FLOAT'));
$this->view->assign('queryTimeStart', microtime());
$this->view->assign('userId', $this->userData->getId());
@@ -240,8 +239,8 @@ abstract class ControllerBase
$browser = $this->dic->get(Browser::class);
// Comprobar si se ha identificado mediante el servidor web y el usuario coincide
if ($browser->checkServerAuthUser($this->session->getUserData()->getLogin()) === false
&& $browser->checkServerAuthUser($this->session->getUserData()->getSsoLogin()) === false
if ($browser->checkServerAuthUser($this->userData->getLogin()) === false
&& $browser->checkServerAuthUser($this->userData->getSsoLogin()) === false
) {
throw new AuthException('Invalid browser auth');
}
@@ -258,6 +257,6 @@ abstract class ControllerBase
*/
protected function checkAccess($action)
{
return $this->session->getUserData()->getIsAdminApp() || $this->acl->checkUserAccess($action);
return $this->userData->getIsAdminApp() || $this->acl->checkUserAccess($action);
}
}

View File

@@ -70,16 +70,27 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte
return;
}
$itemsGridHelper = $this->dic->get(ItemsGridHelper::class);
$grid = $itemsGridHelper->getCustomFieldsGrid($this->customFieldService->search($this->getSearchData($this->configData)))->updatePager();
$this->view->addTemplate('datagrid-table', 'grid');
$this->view->assign('index', Request::analyze('activetab', 0));
$this->view->assign('data', $grid);
$this->view->assign('data', $this->getSearchGrid());
$this->returnJsonResponseData(['html' => $this->render()]);
}
/**
* getSearchGrid
*
* @return $this
* @throws \SP\Core\Dic\ContainerException
*/
protected function getSearchGrid()
{
$itemsGridHelper = $this->dic->get(ItemsGridHelper::class);
$itemSearchData = $this->getSearchData($this->configData->getAccountCount());
return $itemsGridHelper->updatePager($itemsGridHelper->getCustomFieldsGrid($this->customFieldService->search($itemSearchData)), $itemSearchData);
}
/**
* Create action
*

View File

@@ -2,8 +2,8 @@
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
@@ -48,6 +48,8 @@ class EventlogController extends ControllerBase
protected $eventLogService;
/**
* indexAction
*
* @throws \SP\Core\Dic\ContainerException
*/
public function indexAction()
@@ -64,19 +66,21 @@ class EventlogController extends ControllerBase
}
/**
* getSearchGrid
*
* @return $this
* @throws \SP\Core\Dic\ContainerException
*/
protected function getSearchGrid()
{
$itemsGridHelper = $this->dic->get(ItemsGridHelper::class);
$itemSearchData = $this->getSearchData($this->configData);
$itemSearchData = $this->getSearchData($this->configData->getAccountCount());
return $itemsGridHelper->updatePager($itemsGridHelper->getEventLogGrid($this->eventLogService->search($itemSearchData)), $itemSearchData);
}
/**
* @throws \SP\Core\Dic\ContainerException
* searchAction
*/
public function searchAction()
{

View File

@@ -1318,7 +1318,7 @@ class ItemsGridHelper extends HelperBase
* @return DataGrid
* @throws \SP\Core\Dic\ContainerException
*/
public function getNoticesGrid(array $data)
public function getNotificationsGrid(array $data)
{
$isAdminApp = $this->session->getUserData()->getIsAdminApp();

View File

@@ -2,8 +2,8 @@
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
@@ -27,22 +27,11 @@ namespace SP\Modules\Web\Controllers;
defined('APP_ROOT') || die();
use SP\Account\AccountUtil;
use SP\Core\Acl\ActionsInterface;
use SP\Core\DiFactory;
use SP\Core\Exceptions\SPException;
use SP\Core\Init;
use SP\Core\Language;
use SP\Core\Plugin\PluginUtil;
use SP\Core\SessionFactory;
use SP\Core\SessionUtil;
use SP\Core\Task;
use SP\Core\Upgrade\Check;
use SP\Html\DataGrid\DataGridAction;
use SP\Html\Html;
use SP\Http\Request;
use SP\Mgmt\Notices\Notice;
use SP\Mvc\View\Template;
use SP\Util\Checks;
use SP\Util\Util;
/**
@@ -51,401 +40,8 @@ use SP\Util\Util;
*
* @package Controller
*/
class MainController extends ControllerBase implements ActionsInterface
class MainController
{
/**
* Constructor
*
* @param Template $template Template con instancia de plantilla
* @param string $page El nombre de página para la clase del body
* @param bool $initialize Si es una inicialización completa
* @throws \Psr\Container\ContainerExceptionInterface
*/
public function __construct(Template $template = null, $page = '', $initialize = true)
{
parent::__construct($template);
$this->setPage($page);
if ($initialize === true) {
$this->initialize();
}
}
/**
* Establecer la variable de página de la vista
*
* @param $page
*/
protected function setPage($page)
{
$this->view->assign('page', $page);
}
/**
* Inicializar las variables para la vista principal de la aplicación
*
* @throws \Psr\Container\ContainerExceptionInterface
*/
protected function initialize()
{
$this->view->assign('startTime', microtime());
$this->view->addTemplate('header');
$this->view->addTemplate('body-start');
$this->view->assign('useLayout', true);
$this->view->assign('isInstalled', $this->configData->isInstalled());
$this->view->assign('sk', SessionUtil::getSessionKey(true));
$this->view->assign('appInfo', Util::getAppInfo());
$this->view->assign('appVersion', Util::getVersionString());
$this->view->assign('isDemoMode', $this->configData->isDemoEnabled());
$this->view->assign('icons', $this->theme->getIcons());
$this->view->assign('logoIcon', Init::$WEBURI . '/public/images/logo_icon.png');
$this->view->assign('logoNoText', Init::$WEBURI . '/public/images/logo_icon.svg');
$this->view->assign('logo', Init::$WEBURI . '/public/images/logo_full_bg.png');
$this->view->assign('logonobg', Init::$WEBURI . '/public/images/logo_full_nobg.png');
$this->view->assign('httpsEnabled', Checks::httpsEnabled());
$this->setLoggedIn(Util::isLoggedIn($this->session));
$this->view->assign('lang', $this->loggedIn ? Language::$userLang : Language::$globalLang);
$this->view->assign('loadApp', $this->session->getAuthCompleted());
try {
// Cargar la clave pública en la sesión
SessionUtil::loadPublicKey();
} catch (SPException $e) {
processException($e);
}
$this->getResourcesLinks();
$this->setResponseHeaders();
}
/**
* Obtener los datos para la cabcera de la página
*/
public function getResourcesLinks()
{
$version = Util::getVersionStringNormalized();
$jsVersionHash = md5($version);
$this->view->append('jsLinks', Init::$WEBROOT . '/public/js/js.php?v=' . $jsVersionHash);
$this->view->append('jsLinks', Init::$WEBROOT . '/public/js/js.php?g=1&v=' . $jsVersionHash);
$themeInfo = $this->theme->getThemeInfo();
if (isset($themeInfo['js'])) {
$themeJsBase = urlencode($this->theme->getThemePath() . DIRECTORY_SEPARATOR . 'js');
$themeJsFiles = urlencode(implode(',', $themeInfo['js']));
$this->view->append('jsLinks', Init::$WEBROOT . '/public/js/js.php?f=' . $themeJsFiles . '&b=' . $themeJsBase . '&v=' . $jsVersionHash);
}
$userPreferences = $this->session->getUserPreferences();
if ($this->loggedIn && $userPreferences->getUserId() > 0) {
$resultsAsCards = $userPreferences->isResultsAsCards();
} else {
$resultsAsCards = $this->configData->isResultsAsCards();
}
$cssVersionHash = md5($version . $resultsAsCards);
$this->view->append('cssLinks', Init::$WEBROOT . '/public/css/css.php?v=' . $cssVersionHash);
if (isset($themeInfo['css'])) {
if ($resultsAsCards) {
$themeInfo['css'][] = 'search-card.min.css';
} else {
$themeInfo['css'][] = 'search-grid.min.css';
}
if ($this->configData->isDokuwikiEnabled()) {
$themeInfo['css'][] = 'styles-wiki.min.css';
}
$themeCssBase = urlencode($this->theme->getThemePath() . DIRECTORY_SEPARATOR . 'css');
$themeCssFiles = urlencode(implode(',', $themeInfo['css']));
$this->view->append('cssLinks', Init::$WEBROOT . '/public/css/css.php?f=' . $themeCssFiles . '&b=' . $themeCssBase . '&v=' . $jsVersionHash);
}
// Cargar los recursos de los plugins
foreach (PluginUtil::getLoadedPlugins() as $Plugin) {
$base = str_replace(BASE_PATH, '', $Plugin->getBase());
$jsResources = $Plugin->getJsResources();
$cssResources = $Plugin->getCssResources();
if (count($jsResources) > 0) {
$this->view->append('jsLinks', Init::$WEBROOT . '/public/js/js.php?f=' . urlencode(implode(',', $jsResources)) . '&b=' . urlencode($base . DIRECTORY_SEPARATOR . 'js') . '&v=' . $jsVersionHash);
}
if (count($cssResources) > 0) {
$this->view->append('cssLinks', Init::$WEBROOT . '/public/css/css.php?f=' . urlencode(implode(',', $cssResources)) . '&b=' . urlencode($base . DIRECTORY_SEPARATOR . 'css') . '&v=' . $jsVersionHash);
}
}
}
/**
* Establecer las cabeceras HTTP
*/
private function setResponseHeaders()
{
// UTF8 Headers
header('Content-Type: text/html; charset=UTF-8');
// Cache Control
header('Cache-Control: public, no-cache, max-age=0, must-revalidate');
header('Pragma: public; max-age=0');
}
/**
* @throws SPException
* @throws \Psr\Container\ContainerExceptionInterface
*/
public function indexAction()
{
$this->initialize();
$this->getMain();
}
/**
* Obtener los datos para el interface principal de sysPass
*
* @throws \SP\Core\Exceptions\SPException
*/
public function getMain()
{
$this->setPage('main');
$this->getSessionBar();
$this->getMenu();
$this->view->addTemplate('body-content');
$this->view->addTemplate('body-footer');
$this->view->addTemplate('body-end');
}
/**
* Obtener los datos para la mostrar la barra de sesión
*
* @throws \SP\Core\Exceptions\SPException
*/
private function getSessionBar()
{
$this->view->addTemplate('sessionbar');
$userType = null;
if ($this->userData->isIsAdminApp()) {
$userType = $this->icons->getIconAppAdmin();
} elseif ($this->userData->isIsAdminAcc()) {
$userType = $this->icons->getIconAccAdmin();
}
$this->view->assign('userType', $userType);
$this->view->assign('userId', $this->userData->getId());
$this->view->assign('userLogin', mb_strtoupper($this->userData->getLogin()));
$this->view->assign('userName', $this->userData->getName() ?: mb_strtoupper($this->view->userLogin));
$this->view->assign('userGroup', $this->userData->getUserGroupName());
$this->view->assign('showPassIcon', !($this->configData->isLdapEnabled() && $this->userData->isIsLdap()));
$this->view->assign('userNotices', count(Notice::getItem()->getAllActiveForUser()));
}
/**
* Obtener los datos para mostrar el menú de acciones
*/
private function getMenu()
{
$this->view->addTemplate('body-header-menu');
$ActionSearch = new DataGridAction();
$ActionSearch->setId(self::ACCOUNT_SEARCH);
$ActionSearch->setTitle(__('Buscar'));
$ActionSearch->setIcon($this->icons->getIconSearch());
$ActionSearch->setData(['historyReset' => 1, 'view' => 'search']);
$this->view->append('actions', $ActionSearch);
if ($this->acl->checkUserAccess(self::ACCOUNT_CREATE)) {
$ActionNew = new DataGridAction();
$ActionNew->setId(self::ACCOUNT_CREATE);
$ActionNew->setTitle(__('Nueva Cuenta'));
$ActionNew->setIcon($this->icons->getIconAdd());
$ActionNew->setData(['historyReset' => 0, 'view' => 'account']);
$this->view->append('actions', $ActionNew);
}
if ($this->acl->checkUserAccess(self::ACCESS_MANAGE)) {
$ActionUsr = new DataGridAction();
$ActionUsr->setId(self::ACCESS_MANAGE);
$ActionUsr->setTitle(__('Usuarios y Accesos'));
$ActionUsr->setIcon($this->icons->getIconAccount());
$ActionUsr->setData(['historyReset' => 0, 'view' => 'datatabs']);
$this->view->append('actions', $ActionUsr);
}
if ($this->acl->checkUserAccess(self::ITEMS_MANAGE)) {
$ActionMgm = new DataGridAction();
$ActionMgm->setId(self::ITEMS_MANAGE);
$ActionMgm->setTitle(__('Elementos y Personalización'));
$ActionMgm->setIcon($this->icons->getIconGroup());
$ActionMgm->setData(['historyReset' => 0, 'view' => 'datatabs']);
$this->view->append('actions', $ActionMgm);
}
if ($this->acl->checkUserAccess(self::CONFIG)) {
$ActionConfig = new DataGridAction();
$ActionConfig->setId(self::CONFIG);
$ActionConfig->setTitle(__('Configuración'));
$ActionConfig->setIcon($this->icons->getIconSettings());
$ActionConfig->setData(['historyReset' => 1, 'view' => 'config']);
$this->view->append('actions', $ActionConfig);
}
if ($this->acl->checkUserAccess(self::EVENTLOG) && $this->configData->isLogEnabled()) {
$ActionEventlog = new DataGridAction();
$ActionEventlog->setId(self::EVENTLOG);
$ActionEventlog->setTitle(__('Registro de Eventos'));
$ActionEventlog->setIcon($this->icons->getIconHeadline());
$ActionEventlog->setData(['historyReset' => 1, 'view' => 'eventlog']);
$this->view->append('actions', $ActionEventlog);
}
}
/**
* Obtener los datos para el interface de login
*/
public function getLogin()
{
$this->setPage('login');
if (SessionFactory::getLoggedOut() === true) {
SessionFactory::setLoggedOut(false);
$this->view->assign('loggedOut', 1);
} else {
$this->view->assign('loggedOut', 0);
}
$this->view->addTemplate('login');
$this->view->addTemplate('body-footer');
$this->view->addTemplate('body-end');
$this->view->assign('useLayout', false);
$this->view->assign('mailEnabled', $this->configData->isMailEnabled());
$this->view->assign('updated', SessionFactory::getAppUpdated());
SessionFactory::setAppUpdated(false);
$getParams = [];
// Comprobar y parsear los parámetros GET para pasarlos como POST en los inputs
if (count($_GET) > 0) {
foreach ($_GET as $param => $value) {
$getParams['g_' . Html::sanitizeFull($param)] = Html::sanitizeFull($value);
}
}
$this->view->assign('getParams', $getParams);
$this->view();
exit();
}
/**
* Obtener los datos para el interface de logout
*/
public function getLogout()
{
$this->setPage('logout');
$this->view->addTemplate('logout');
$this->view->addTemplate('body-footer');
$this->view->addTemplate('body-end');
$this->view();
exit();
}
/**
* Obtener los datos para el interface del instalador
*/
public function getInstaller()
{
$this->setPage('install');
$this->view->addTemplate('body-header');
$errors = [];
if (!Checks::checkPhpVersion()) {
$errors[] = [
'type' => SPException::CRITICAL,
'description' => __('Versión de PHP requerida >= ') . ' 5.6.0 <= 7.0',
'hint' => __('Actualice la versión de PHP para que la aplicación funcione correctamente')
];
}
$modules = Checks::checkModules();
if (count($modules) > 0) {
foreach ($modules as $module) {
$error[] = [
'type' => SPException::WARNING,
'description' => sprintf('%s (%s)', __('Módulo no disponible'), $module),
'hint' => __('Sin este módulo la aplicación puede no funcionar correctamente.')
];
}
}
if (@file_exists(__FILE__ . "\0Nullbyte")) {
$errors[] = [
'type' => SPException::WARNING,
'description' => __('La version de PHP es vulnerable al ataque NULL Byte (CVE-2006-7243)'),
'hint' => __('Actualice la versión de PHP para usar sysPass de forma segura')];
}
if (!Checks::secureRNGIsAvailable()) {
$errors[] = [
'type' => SPException::WARNING,
'description' => __('No se encuentra el generador de números aleatorios.'),
'hint' => __('Sin esta función un atacante puede utilizar su cuenta al resetear la clave')];
}
$this->view->assign('errors', $errors);
$this->view->assign('langsAvailable', Language::getAvailableLanguages());
$this->view->assign('langBrowser', Language::$globalLang);
$this->view->addTemplate('install');
$this->view->addTemplate('body-footer');
$this->view->addTemplate('body-end');
}
/**
* Obtener los datos para el interface de error
*/
public function getError()
{
$this->setPage('error');
if (!Checks::isAjax()) {
$this->view->addTemplate('body-header');
$this->view->addTemplate('error');
$this->view->addTemplate('body-footer');
} else {
$this->view->addTemplate('error');
}
$this->view();
exit();
}
/**
* Obtener los datos para el interface de actualización de componentes
@@ -559,35 +155,4 @@ class MainController extends ControllerBase implements ActionsInterface
$this->showError(self::ERR_EXCEPTION);
}
}
/**
* Obtener los datos para el interface de restablecimiento de clave de usuario
*/
public function getPassReset()
{
$this->setPage('passreset');
$this->view->addTemplate('body-header');
if ($this->configData->isMailEnabled() || Request::analyze('f', 0) === 1) {
$this->view->addTemplate('passreset');
$this->view->assign('login', Request::analyze('login'));
$this->view->assign('email', Request::analyze('email'));
$this->view->assign('action', Request::analyze('a'));
$this->view->assign('hash', Request::analyze('h'));
$this->view->assign('time', Request::analyze('t'));
$this->view->assign('passReset', $this->view->action === 'passreset' && !empty($this->view->hash) && !empty($this->view->time));
} else {
$this->showError(self::ERR_UNAVAILABLE, false);
}
$this->view->addTemplate('body-footer');
$this->view->addTemplate('body-end');
$this->view();
exit();
}
}

View File

@@ -72,15 +72,17 @@ class NotificationController extends ControllerBase implements CrudControllerInt
}
/**
* getSearchGrid
*
* @return $this
* @throws \SP\Core\Dic\ContainerException
*/
protected function getSearchGrid()
{
$itemsGridHelper = $this->dic->get(ItemsGridHelper::class);
$itemSearchData = $this->getSearchData($this->configData);
$itemSearchData = $this->getSearchData($this->configData->getAccountCount());
return $itemsGridHelper->updatePager($itemsGridHelper->getNoticesGrid($this->notificationService->search($itemSearchData)), $itemSearchData);
return $itemsGridHelper->updatePager($itemsGridHelper->getNotificationsGrid($this->notificationService->search($itemSearchData)), $itemSearchData);
}
/**

View File

@@ -70,16 +70,27 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter
return;
}
$itemsGridHelper = $this->dic->get(ItemsGridHelper::class);
$grid = $itemsGridHelper->getPublicLinksGrid($this->publicLinkService->search($this->getSearchData($this->configData)))->updatePager();
$this->view->addTemplate('datagrid-table', 'grid');
$this->view->assign('index', Request::analyze('activetab', 0));
$this->view->assign('data', $grid);
$this->view->assign('data', $this->getSearchGrid());
$this->returnJsonResponseData(['html' => $this->render()]);
}
/**
* getSearchGrid
*
* @return $this
* @throws \SP\Core\Dic\ContainerException
*/
protected function getSearchGrid()
{
$itemsGridHelper = $this->dic->get(ItemsGridHelper::class);
$itemSearchData = $this->getSearchData($this->configData->getAccountCount());
return $itemsGridHelper->updatePager($itemsGridHelper->getPublicLinksGrid($this->publicLinkService->search($itemSearchData)), $itemSearchData);
}
/**
* Create action
*

View File

@@ -67,16 +67,27 @@ class TagController extends ControllerBase implements CrudControllerInterface
return;
}
$itemsGridHelper = $this->dic->get(ItemsGridHelper::class);
$grid = $itemsGridHelper->getTagsGrid($this->tagService->search($this->getSearchData($this->configData)))->updatePager();
$this->view->addTemplate('datagrid-table', 'grid');
$this->view->assign('index', Request::analyze('activetab', 0));
$this->view->assign('data', $grid);
$this->view->assign('data', $this->getSearchGrid());
$this->returnJsonResponseData(['html' => $this->render()]);
}
/**
* getSearchGrid
*
* @return $this
* @throws \SP\Core\Dic\ContainerException
*/
protected function getSearchGrid()
{
$itemsGridHelper = $this->dic->get(ItemsGridHelper::class);
$itemSearchData = $this->getSearchData($this->configData->getAccountCount());
return $itemsGridHelper->updatePager($itemsGridHelper->getTagsGrid($this->tagService->search($itemSearchData)), $itemSearchData);
}
/**
* Create action
*

View File

@@ -2,8 +2,8 @@
/**
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
@@ -26,7 +26,6 @@ namespace SP\Modules\Web\Controllers\Traits;
use Defuse\Crypto\Exception\CryptoException;
use SP\Bootstrap;
use SP\Config\ConfigData;
use SP\Core\Exceptions\SPException;
use SP\DataModel\CustomFieldData;
use SP\DataModel\ItemSearchData;
@@ -102,9 +101,9 @@ trait ItemTrait
*/
protected function addCustomFieldsForItem($moduleId, $itemId)
{
$customFields = Request::analyze('customfield');
$customFields = Request::analyzeArray('customfield');
if (is_array($customFields)) {
if ($customFields !== false) {
$customFieldData = new CustomFieldData();
$customFieldData->setId($itemId);
$customFieldData->setModuleId($moduleId);
@@ -157,9 +156,9 @@ trait ItemTrait
*/
protected function updateCustomFieldsForItem($moduleId, $itemId)
{
$customFields = Request::analyze('customfield');
$customFields = Request::analyzeArray('customfield');
if (is_array($customFields)) {
if ($customFields !== false) {
$customFieldData = new CustomFieldData();
$customFieldData->setId($itemId);
$customFieldData->setModuleId($moduleId);
@@ -182,16 +181,15 @@ trait ItemTrait
/**
* Returns search data object for the current request
*
* @param ConfigData $configData
* @param int $limitCount
* @return ItemSearchData
*/
protected function getSearchData(ConfigData $configData)
protected function getSearchData($limitCount)
{
$itemSearchData = new ItemSearchData();
$itemSearchData->setLimitCount($configData->getAccountCount());
$itemSearchData->setSeachString(Request::analyze('search'));
$itemSearchData->setLimitStart(Request::analyze('start', 0));
$itemSearchData->setLimitCount(Request::analyze('count', $configData->getAccountCount()));
$itemSearchData->setSeachString(Request::analyzeString('search'));
$itemSearchData->setLimitStart(Request::analyzeInt('start'));
$itemSearchData->setLimitCount(Request::analyzeInt('count', $limitCount));
return $itemSearchData;
}
@@ -201,6 +199,6 @@ trait ItemTrait
*/
protected function getItemsIdFromRequest()
{
return Request::analyze('items', 0);
return Request::analyzeArray('items');
}
}

View File

@@ -73,16 +73,27 @@ class UserController extends ControllerBase implements CrudControllerInterface
return;
}
$itemsGridHelper = $this->dic->get(ItemsGridHelper::class);
$grid = $itemsGridHelper->getUsersGrid($this->userService->search($this->getSearchData($this->configData)))->updatePager();
$this->view->addTemplate('datagrid-table', 'grid');
$this->view->assign('index', Request::analyze('activetab', 0));
$this->view->assign('data', $grid);
$this->view->assign('data', $this->getSearchGrid());
$this->returnJsonResponseData(['html' => $this->render()]);
}
/**
* getSearchGrid
*
* @return $this
* @throws \SP\Core\Dic\ContainerException
*/
protected function getSearchGrid()
{
$itemsGridHelper = $this->dic->get(ItemsGridHelper::class);
$itemSearchData = $this->getSearchData($this->configData->getAccountCount());
return $itemsGridHelper->updatePager($itemsGridHelper->getUsersGrid($this->userService->search($itemSearchData)), $itemSearchData);
}
/**
* Create action
*

View File

@@ -74,16 +74,27 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf
return;
}
$itemsGridHelper = $this->dic->get(ItemsGridHelper::class);
$grid = $itemsGridHelper->getUserGroupsGrid($this->userGroupService->search($this->getSearchData($this->configData)))->updatePager();
$this->view->addTemplate('datagrid-table', 'grid');
$this->view->assign('index', Request::analyze('activetab', 0));
$this->view->assign('data', $grid);
$this->view->assign('data', $this->getSearchGrid());
$this->returnJsonResponseData(['html' => $this->render()]);
}
/**
* getSearchGrid
*
* @return $this
* @throws \SP\Core\Dic\ContainerException
*/
protected function getSearchGrid()
{
$itemsGridHelper = $this->dic->get(ItemsGridHelper::class);
$itemSearchData = $this->getSearchData($this->configData->getAccountCount());
return $itemsGridHelper->updatePager($itemsGridHelper->getUserGroupsGrid($this->userGroupService->search($itemSearchData)), $itemSearchData);
}
/**
* Create action
*

View File

@@ -68,16 +68,27 @@ class UserProfileController extends ControllerBase implements CrudControllerInte
return;
}
$itemsGridHelper = $this->dic->get(ItemsGridHelper::class);
$grid = $itemsGridHelper->getUserProfilesGrid($this->userProfileService->search($this->getSearchData($this->configData)))->updatePager();
$this->view->addTemplate('datagrid-table', 'grid');
$this->view->assign('index', Request::analyze('activetab', 0));
$this->view->assign('data', $grid);
$this->view->assign('data', $this->getSearchGrid());
$this->returnJsonResponseData(['html' => $this->render()]);
}
/**
* getSearchGrid
*
* @return $this
* @throws \SP\Core\Dic\ContainerException
*/
protected function getSearchGrid()
{
$itemsGridHelper = $this->dic->get(ItemsGridHelper::class);
$itemSearchData = $this->getSearchData($this->configData->getAccountCount());
return $itemsGridHelper->updatePager($itemsGridHelper->getUserProfilesGrid($this->userProfileService->search($itemSearchData)), $itemSearchData);
}
/**
* Create action
*

View File

@@ -82,7 +82,7 @@ class ItemSearchData
*/
public function setLimitStart($limitStart)
{
$this->limitStart = $limitStart;
$this->limitStart = (int)$limitStart;
}
/**
@@ -98,7 +98,7 @@ class ItemSearchData
*/
public function setLimitCount($limitCount)
{
$this->limitCount = $limitCount;
$this->limitCount = (int)$limitCount;
}
/**

View File

@@ -27,6 +27,7 @@ namespace SP\Http;
use SP\Core\CryptPKI;
use SP\Core\Init;
use SP\Html\Html;
use SP\Util\Util;
/**
* Clase Request para la gestión de peticiones HTTP
@@ -192,6 +193,82 @@ class Request
return $value;
}
/**
* @param $param
* @return mixed
*/
public static function analyzeArray($param)
{
if (is_array($_REQUEST[$param])) {
return array_map(function ($value) {
if (is_numeric($value)) {
return (int)filter_var($value, FILTER_SANITIZE_NUMBER_INT);
} else {
return (string)filter_var($value, FILTER_SANITIZE_STRING);
}
}, $_REQUEST[$param]);
}
return false;
}
/**
* @param $param
* @param $default
* @return int
*/
public static function analyzeInt($param, $default = 0)
{
if (!isset($_REQUEST[$param])) {
return (int)$default;
}
return (int)filter_var($_REQUEST[$param], FILTER_SANITIZE_NUMBER_INT);
}
/**
* @param $param
* @param $default
* @return string
*/
public static function analyzeString($param, $default = '')
{
if (!isset($_REQUEST[$param])) {
return (string)$default;
}
return filter_var($_REQUEST[$param], FILTER_SANITIZE_STRING);
}
/**
* @param $param
* @param $default
* @return bool
*/
public static function analyzeBool($param, $default = false)
{
if (!isset($_REQUEST[$param])) {
return (bool)$default;
}
return Util::boolval($_REQUEST[$param]);
}
/**
* @param $param
* @param $default
* @return string
*/
public static function analyzePassword($param, $default = '')
{
if (!isset($_REQUEST[$param])) {
return (string)$default;
}
return filter_var($_REQUEST[$param], FILTER_SANITIZE_STRING);
}
/**
* Comprobar si se realiza una recarga de la página
*

View File

@@ -48,8 +48,10 @@ class LogHandler extends Provider implements EventReceiver
'copy.account.pass',
'clear.eventlog',
'login.',
'logout'
'logout',
'track.'
];
/**
* @var EventlogService
*/
@@ -92,13 +94,18 @@ class LogHandler extends Provider implements EventReceiver
{
$eventlogData = new EventlogData();
$eventlogData->setAction($eventType);
$eventlogData->setLevel('INFO');
if (($eventMessage = $event->getEventMessage()) !== null) {
if (($e = $event->getSource()) instanceof \Exception) {
/** @var \Exception $e */
$eventlogData->setDescription($e->getMessage());
$eventlogData->setLevel('ERROR');
} elseif (($eventMessage = $event->getEventMessage()) !== null) {
$eventlogData->setDescription($eventMessage->composeText());
$eventlogData->setLevel('INFO');
}
if (($e = $event->getSource()) instanceof \Exception) {
$eventlogData->setLevel('INFO');
/** @var \Exception $e */
$eventlogData->setDescription($e->getMessage());
}

View File

@@ -73,7 +73,7 @@ class EventlogService extends Service
$userData = $this->session->getUserData();
$eventlogData->setUserId($userData->getId());
$eventlogData->setLogin($userData->getLogin());
$eventlogData->setLogin($userData->getLogin() ?: '-');
$eventlogData->setIpAddress(HttpUtil::getClientAddress());
return $this->eventLogRepository->create($eventlogData);