From faffe5495b25b39ac5681ec2a3577116c321ac0b Mon Sep 17 00:00:00 2001 From: nuxsmin Date: Mon, 19 Feb 2018 01:51:36 +0100 Subject: [PATCH] * [ADD] Config module. Work in progress --- .../Controllers/AccessManagerController.php | 3 +- .../web/Controllers/AccountController.php | 82 +-- .../web/Controllers/AccountFileController.php | 25 +- .../web/Controllers/ApiTokenController.php | 33 +- .../web/Controllers/CategoryController.php | 25 +- .../web/Controllers/ClientController.php | 25 +- .../Controllers/ConfigAccountController.php | 105 ++++ .../Controllers/ConfigBackupController.php | 98 +++ .../ConfigEncryptionController.php | 210 +++++++ .../Controllers/ConfigGeneralController.php | 162 +++++ .../web/Controllers/ConfigLdapController.php | 101 +++ .../web/Controllers/ConfigMailController.php | 106 ++++ .../Controllers/ConfigManagerController.php | 13 +- .../web/Controllers/ConfigWikiController.php | 119 ++++ .../web/Controllers/ControllerBase.php | 4 +- .../web/Controllers/CustomFieldController.php | 25 +- .../web/Controllers/Helpers/LayoutHelper.php | 2 +- .../web/Controllers/ItemManagerController.php | 3 +- .../web/Controllers/MainController.php | 2 +- .../web/Controllers/PublicLinkController.php | 39 +- .../web/Controllers/SimpleControllerBase.php | 17 + app/modules/web/Controllers/TagController.php | 25 +- .../web/Controllers/Traits/ConfigTrait.php | 68 ++ .../web/Controllers/Traits/JsonTrait.php | 20 + .../web/Controllers/UserController.php | 39 +- .../web/Controllers/UserGroupController.php | 29 +- .../web/Controllers/UserProfileController.php | 32 +- .../material-blue/views/config/accounts.inc | 2 +- .../material-blue/views/config/backup.inc | 14 +- .../material-blue/views/config/encryption.inc | 12 +- .../material-blue/views/config/general.inc | 5 +- .../material-blue/views/config/ldap.inc | 9 +- .../material-blue/views/config/wiki.inc | 9 +- lib/BaseFunctions.php | 20 +- lib/SP/Account/AccountCrypt.php | 8 +- lib/SP/Account/AccountHistoryCrypt.php | 8 +- lib/SP/Config/Config.php | 23 +- lib/SP/Controller/MainActionController.php | 6 +- lib/SP/Core/Crypt/Crypt.php | 8 +- lib/SP/Core/Events/Event.php | 72 +++ lib/SP/Core/Events/EventDispatcherBase.php | 17 +- .../Core/Events/EventDispatcherInterface.php | 11 +- lib/SP/Core/Events/EventReceiver.php | 7 +- lib/SP/Core/Messages/TaskMessage.php | 30 + lib/SP/Core/Task.php | 29 +- lib/SP/Core/TaskFactory.php | 83 ++- lib/SP/Core/Upgrade/Account.php | 4 +- lib/SP/Core/Upgrade/Category.php | 2 +- lib/SP/Core/Upgrade/Customer.php | 2 +- lib/SP/Core/Upgrade/Group.php | 4 +- lib/SP/Core/Upgrade/Profile.php | 2 +- lib/SP/Core/Upgrade/Upgrade.php | 2 +- lib/SP/Core/Upgrade/User.php | 4 +- lib/SP/Crypt/TemporaryMasterPass.php | 3 +- lib/SP/Mgmt/Groups/Group.php | 4 +- lib/SP/Mgmt/Groups/GroupAccounts.php | 10 +- lib/SP/Mgmt/Groups/GroupUsers.php | 12 +- lib/SP/Mgmt/Users/UserUtil.php | 2 +- .../Account/AccountHistoryRepository.php | 46 ++ .../Account/AccountRepository.php | 83 ++- .../Category/CategoryRepository.php | 2 +- .../Repositories/Client/ClientRepository.php | 2 +- .../CustomField/CustomFieldRepository.php | 11 +- .../Services/Account/AccountCryptService.php | 308 +++++++++ .../Account/AccountHistoryService.php | 19 + .../Account/AccountPasswordRequest.php | 50 ++ lib/SP/Services/Account/AccountService.php | 44 +- .../Services/Account/AccountToTagService.php | 60 ++ lib/SP/Services/Auth/LoginService.php | 3 +- lib/SP/Services/Backup/FileBackupService.php | 307 +++++++++ lib/SP/Services/Category/CategoryService.php | 3 +- lib/SP/Services/Client/ClientService.php | 3 +- lib/SP/Services/Crypt/MasterPassService.php | 121 ++++ .../Crypt/TemporaryMasterPassService.php | 158 +++++ .../Crypt/UpdateMasterPassRequest.php | 116 ++++ .../CustomField/CustomFieldCryptService.php | 159 +++++ .../CustomField/CustomFieldService.php | 41 +- lib/SP/Services/Export/XmlExportService.php | 566 +++++++++++++++++ lib/SP/Services/Tag/TagService.php | 3 +- lib/SP/Storage/DBUtil.php | 6 +- lib/SP/Storage/XmlHandler.php | 4 +- public/js/app-actions.js | 587 +++++++++--------- public/js/app-actions.min.js | 84 +-- schemas/dbstructure.sql | 16 +- 84 files changed, 3955 insertions(+), 683 deletions(-) create mode 100644 app/modules/web/Controllers/ConfigAccountController.php create mode 100644 app/modules/web/Controllers/ConfigBackupController.php create mode 100644 app/modules/web/Controllers/ConfigEncryptionController.php create mode 100644 app/modules/web/Controllers/ConfigGeneralController.php create mode 100644 app/modules/web/Controllers/ConfigLdapController.php create mode 100644 app/modules/web/Controllers/ConfigMailController.php create mode 100644 app/modules/web/Controllers/ConfigWikiController.php create mode 100644 app/modules/web/Controllers/Traits/ConfigTrait.php create mode 100644 lib/SP/Core/Events/Event.php create mode 100644 lib/SP/Services/Account/AccountCryptService.php create mode 100644 lib/SP/Services/Account/AccountPasswordRequest.php create mode 100644 lib/SP/Services/Account/AccountToTagService.php create mode 100644 lib/SP/Services/Backup/FileBackupService.php create mode 100644 lib/SP/Services/Crypt/MasterPassService.php create mode 100644 lib/SP/Services/Crypt/TemporaryMasterPassService.php create mode 100644 lib/SP/Services/Crypt/UpdateMasterPassRequest.php create mode 100644 lib/SP/Services/CustomField/CustomFieldCryptService.php create mode 100644 lib/SP/Services/Export/XmlExportService.php diff --git a/app/modules/web/Controllers/AccessManagerController.php b/app/modules/web/Controllers/AccessManagerController.php index 8050a04c..d7033cba 100644 --- a/app/modules/web/Controllers/AccessManagerController.php +++ b/app/modules/web/Controllers/AccessManagerController.php @@ -26,6 +26,7 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; +use SP\Core\Events\Event; use SP\DataModel\ItemSearchData; use SP\Http\Request; use SP\Modules\Web\Controllers\Helpers\ItemsGridHelper; @@ -103,7 +104,7 @@ class AccessManagerController extends ControllerBase $this->tabsGridHelper->addTab($this->getPublicLinksList()); } - $this->eventDispatcher->notifyEvent('show.itemlist.accesses', $this); + $this->eventDispatcher->notifyEvent('show.itemlist.accesses', new Event($this)); $this->tabsGridHelper->renderTabs(Acl::getActionRoute(ActionsInterface::ACCESS_MANAGE), Request::analyze('tabIndex', 0)); diff --git a/app/modules/web/Controllers/AccountController.php b/app/modules/web/Controllers/AccountController.php index 406d4bac..4c5b2edf 100644 --- a/app/modules/web/Controllers/AccountController.php +++ b/app/modules/web/Controllers/AccountController.php @@ -24,9 +24,12 @@ namespace SP\Modules\Web\Controllers; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\Crypt\Vault; +use SP\Core\Events\Event; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; use SP\Core\SessionUtil; @@ -74,9 +77,9 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $accountSearchHelper->getSearchBox(); $accountSearchHelper->getAccountSearch(); - $this->eventDispatcher->notifyEvent('show.account.search', $this); + $this->eventDispatcher->notifyEvent('show.account.search', new Event($this)); } catch (\Exception $e) { - debugLog($e->getMessage(), true); + processException($e); ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_EXCEPTION); } @@ -95,7 +98,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $AccountSearchHelper = $this->dic->get(AccountSearchHelper::class); $AccountSearchHelper->getAccountSearch(); - $this->eventDispatcher->notifyEvent('show.account.search', $this); + $this->eventDispatcher->notifyEvent('show.account.search', new Event($this)); $data = [ 'sk' => SessionUtil::getSessionKey(), @@ -104,7 +107,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->returnJsonResponseData($data); } catch (\Exception $e) { - debugLog($e->getMessage(), true); + processException($e); ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_EXCEPTION); } @@ -141,9 +144,9 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->accountService->incrementViewCounter($id); - $this->eventDispatcher->notifyEvent('show.account', $this); + $this->eventDispatcher->notifyEvent('show.account', new Event($this)); } catch (\Exception $e) { - debugLog($e->getMessage(), true); + processException($e); ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_EXCEPTION); } @@ -219,12 +222,12 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->view->assign('accountData', $accountData); - $this->eventDispatcher->notifyEvent('show.account.link', $this); + $this->eventDispatcher->notifyEvent('show.account.link', new Event($this)); } else { ErrorUtil::showErrorFull($this->view, ErrorUtil::ERR_PAGE_NO_PERMISSION, 'account-link'); } } catch (\Exception $e) { - debugLog($e->getMessage(), true); + processException($e); ErrorUtil::showErrorFull($this->view, ErrorUtil::ERR_PAGE_NO_PERMISSION, 'account-link'); } @@ -251,9 +254,9 @@ class AccountController extends ControllerBase implements CrudControllerInterfac ); $this->view->assign('formRoute', 'account/saveCreate'); - $this->eventDispatcher->notifyEvent('show.account.create', $this); + $this->eventDispatcher->notifyEvent('show.account.create', new Event($this)); } catch (\Exception $e) { - debugLog($e->getMessage(), true); + processException($e); ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_EXCEPTION); } @@ -290,9 +293,9 @@ class AccountController extends ControllerBase implements CrudControllerInterfac ); $this->view->assign('formRoute', 'account/saveCopy'); - $this->eventDispatcher->notifyEvent('show.account.copy', $this); + $this->eventDispatcher->notifyEvent('show.account.copy', new Event($this)); } catch (\Exception $e) { - debugLog($e->getMessage(), true); + processException($e); ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_EXCEPTION); } @@ -332,9 +335,9 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->accountService->incrementViewCounter($id); - $this->eventDispatcher->notifyEvent('show.account.edit', $this); + $this->eventDispatcher->notifyEvent('show.account.edit', new Event($this)); } catch (\Exception $e) { - debugLog($e->getMessage(), true); + processException($e); ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_EXCEPTION); } @@ -370,9 +373,9 @@ class AccountController extends ControllerBase implements CrudControllerInterfac ); $this->view->assign('formRoute', 'account/saveDelete'); - $this->eventDispatcher->notifyEvent('show.account.delete', $this); + $this->eventDispatcher->notifyEvent('show.account.delete', new Event($this)); } catch (\Exception $e) { - debugLog($e->getMessage(), true); + processException($e); ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_EXCEPTION); } @@ -410,9 +413,9 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->view->assign('accountPassDateChange', gmdate('Y-m-d', $accountDetailsResponse->getAccountVData()->getPassDateChange())); - $this->eventDispatcher->notifyEvent('show.account.editpass', $this); + $this->eventDispatcher->notifyEvent('show.account.editpass', new Event($this)); } catch (\Exception $e) { - debugLog($e->getMessage(), true); + processException($e); ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_EXCEPTION); } @@ -448,9 +451,9 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->view->assign('formRoute', 'account/saveRestore'); - $this->eventDispatcher->notifyEvent('show.account.history', $this); + $this->eventDispatcher->notifyEvent('show.account.history', new Event($this)); } catch (\Exception $e) { - debugLog($e->getMessage(), true); + processException($e); ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_EXCEPTION); } @@ -475,9 +478,9 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->view->addTemplate('account-request'); $this->view->assign('formRoute', 'account/saveRequest'); - $this->eventDispatcher->notifyEvent('show.account.request', $this); + $this->eventDispatcher->notifyEvent('show.account.request', new Event($this)); } catch (\Exception $e) { - debugLog($e->getMessage(), true); + processException($e); ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_EXCEPTION); } @@ -506,11 +509,11 @@ class AccountController extends ControllerBase implements CrudControllerInterfac 'html' => $this->render() ]; - $this->eventDispatcher->notifyEvent('show.account.pass', $this); + $this->eventDispatcher->notifyEvent('show.account.pass', new Event($this)); $this->returnJsonResponseData($data); } catch (\Exception $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, $e->getMessage()); } @@ -538,7 +541,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac 'accpass' => $accountPassHelper->getPassword($account, $this->acl, AccountPasswordHelper::TYPE_NORMAL), ]; - $this->eventDispatcher->notifyEvent('copy.account.pass', $this); + $this->eventDispatcher->notifyEvent('copy.account.pass', new Event($this)); $this->returnJsonResponseData($data); } @@ -555,8 +558,6 @@ class AccountController extends ControllerBase implements CrudControllerInterfac /** * Saves create action - * - * @throws \SP\Core\Dic\ContainerException */ public function saveCreateAction() { @@ -569,7 +570,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->addCustomFieldsForItem(ActionsInterface::ACCOUNT, $accountId); - $this->eventDispatcher->notifyEvent('create.account', $this); + $this->eventDispatcher->notifyEvent('create.account', new Event($this)); $this->returnJsonResponseData( [ @@ -581,8 +582,8 @@ class AccountController extends ControllerBase implements CrudControllerInterfac ); } catch (ValidationException $e) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); - } catch (SPException $e) { - debugLog($e->getMessage(), true); + } catch (\Exception $e) { + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -606,7 +607,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->updateCustomFieldsForItem(ActionsInterface::ACCOUNT, $id); - $this->eventDispatcher->notifyEvent('edit.account', $this); + $this->eventDispatcher->notifyEvent('edit.account', new Event($this)); $this->returnJsonResponseData( [ @@ -619,7 +620,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac } catch (ValidationException $e) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -641,7 +642,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->accountService->editPassword($form->getItemData()); - $this->eventDispatcher->notifyEvent('edit.account.pass', $this); + $this->eventDispatcher->notifyEvent('edit.account.pass', new Event($this)); $this->returnJsonResponseData( [ @@ -654,7 +655,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac } catch (ValidationException $e) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -673,7 +674,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac try { $this->accountService->editRestore($historyId, $id); - $this->eventDispatcher->notifyEvent('edit.account.restore', $this); + $this->eventDispatcher->notifyEvent('edit.account.restore', new Event($this)); $this->returnJsonResponseData( [ @@ -684,7 +685,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac __u('Cuenta restaurada') ); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -701,7 +702,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac if ($this->accountService->delete($id)) { $this->deleteCustomFieldsForItem(ActionsInterface::ACCOUNT, $id); - $this->eventDispatcher->notifyEvent('delete.account', $this); + $this->eventDispatcher->notifyEvent('delete.account', new Event($this)); $this->returnJsonResponseData( ['nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_SEARCH)], @@ -710,7 +711,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac ); } } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -719,8 +720,9 @@ class AccountController extends ControllerBase implements CrudControllerInterfac /** * Initialize class * - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + * @throws \SP\Services\Auth\AuthException */ protected function initialize() { diff --git a/app/modules/web/Controllers/AccountFileController.php b/app/modules/web/Controllers/AccountFileController.php index 67c6563f..a1880f07 100644 --- a/app/modules/web/Controllers/AccountFileController.php +++ b/app/modules/web/Controllers/AccountFileController.php @@ -26,6 +26,7 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; +use SP\Core\Events\Event; use SP\Core\Exceptions\SPException; use SP\DataModel\FileData; use SP\Html\Html; @@ -73,7 +74,7 @@ class AccountFileController extends ControllerBase implements CrudControllerInte $this->view->assign('fileData', $fileData); $this->view->assign('isImage', 1); - $this->eventDispatcher->notifyEvent('show.accountFile', $this); + $this->eventDispatcher->notifyEvent('show.accountFile', new Event($this)); $this->returnJsonResponseData(['html' => $this->render()]); } @@ -81,12 +82,12 @@ class AccountFileController extends ControllerBase implements CrudControllerInte if (mb_strtoupper($fileData->getExtension()) === 'TXT') { $this->view->assign('data', htmlentities($fileData->getContent())); - $this->eventDispatcher->notifyEvent('show.accountFile', $this); + $this->eventDispatcher->notifyEvent('show.accountFile', new Event($this)); $this->returnJsonResponseData(['html' => $this->render()]); } } catch (\Exception $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(1, $e->getMessage()); } @@ -115,11 +116,11 @@ class AccountFileController extends ControllerBase implements CrudControllerInte header('Content-Description: PHP Generated Data'); header('Content-transfer-encoding: binary'); - $this->eventDispatcher->notifyEvent('download.accountFile', $this); + $this->eventDispatcher->notifyEvent('download.accountFile', new Event($this)); exit($fileData->getContent()); } catch (\Exception $e) { - debugLog($e->getMessage(), true); + processException($e); } } @@ -179,15 +180,15 @@ class AccountFileController extends ControllerBase implements CrudControllerInte $this->accountFileService->create($fileData); - $this->eventDispatcher->notifyEvent('upload.accountFile', $this); + $this->eventDispatcher->notifyEvent('upload.accountFile', new Event($this)); $this->returnJsonResponse(0, __u('Archivo guardado')); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(1, $e->getMessage(), [$e->getHint()]); } catch (\Exception $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(1, $e->getMessage()); } @@ -244,11 +245,11 @@ class AccountFileController extends ControllerBase implements CrudControllerInte try { $this->accountFileService->delete($id); - $this->eventDispatcher->notifyEvent('delete.accountFile', $this); + $this->eventDispatcher->notifyEvent('delete.accountFile', new Event($this)); $this->returnJsonResponse(0, __('Archivo Eliminado')); } catch (\Exception $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(1, $e->getMessage()); } @@ -298,9 +299,9 @@ class AccountFileController extends ControllerBase implements CrudControllerInte return; } - $this->eventDispatcher->notifyEvent('list.accountFile', $this); + $this->eventDispatcher->notifyEvent('list.accountFile', new Event($this)); } catch (\Exception $e) { - debugLog($e->getMessage(), true); + processException($e); ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_EXCEPTION); } diff --git a/app/modules/web/Controllers/ApiTokenController.php b/app/modules/web/Controllers/ApiTokenController.php index d13895c1..349be057 100644 --- a/app/modules/web/Controllers/ApiTokenController.php +++ b/app/modules/web/Controllers/ApiTokenController.php @@ -28,6 +28,7 @@ use Defuse\Crypto\Exception\CryptoException; use Defuse\Crypto\Exception\EnvironmentIsBrokenException; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; +use SP\Core\Events\Event; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; use SP\DataModel\AuthTokenData; @@ -100,8 +101,10 @@ class ApiTokenController extends ControllerBase implements CrudControllerInterfa try { $this->setViewData(); - $this->eventDispatcher->notifyEvent('show.authToken.create', $this); + $this->eventDispatcher->notifyEvent('show.authToken.create', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(1, $e->getMessage()); } @@ -158,8 +161,10 @@ class ApiTokenController extends ControllerBase implements CrudControllerInterfa try { $this->setViewData($id); - $this->eventDispatcher->notifyEvent('show.authToken.edit', $this); + $this->eventDispatcher->notifyEvent('show.authToken.edit', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -182,11 +187,11 @@ class ApiTokenController extends ControllerBase implements CrudControllerInterfa $this->deleteCustomFieldsForItem(ActionsInterface::APITOKEN, $id); - $this->eventDispatcher->notifyEvent('delete.authToken', $this); + $this->eventDispatcher->notifyEvent('delete.authToken', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Autorización eliminada')); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -213,21 +218,21 @@ class ApiTokenController extends ControllerBase implements CrudControllerInterfa $this->addCustomFieldsForItem(ActionsInterface::APITOKEN, $id); - $this->eventDispatcher->notifyEvent('create.authToken', $this); + $this->eventDispatcher->notifyEvent('create.authToken', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Autorización creada')); } catch (ValidationException $e) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } catch (EnvironmentIsBrokenException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } catch (CryptoException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -252,11 +257,11 @@ class ApiTokenController extends ControllerBase implements CrudControllerInterfa if ($form->isRefresh()){ $this->authTokenService->refreshAndUpdate($form->getItemData()); - $this->eventDispatcher->notifyEvent('refresh.authToken', $this); + $this->eventDispatcher->notifyEvent('refresh.authToken', new Event($this)); } else { $this->authTokenService->update($form->getItemData()); - $this->eventDispatcher->notifyEvent('edit.authToken', $this); + $this->eventDispatcher->notifyEvent('edit.authToken', new Event($this)); } $this->updateCustomFieldsForItem(ActionsInterface::APITOKEN, $id); @@ -265,11 +270,11 @@ class ApiTokenController extends ControllerBase implements CrudControllerInterfa } catch (ValidationException $e) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } catch (CryptoException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -293,8 +298,10 @@ class ApiTokenController extends ControllerBase implements CrudControllerInterfa try { $this->setViewData($id); - $this->eventDispatcher->notifyEvent('show.authToken', $this); + $this->eventDispatcher->notifyEvent('show.authToken', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } diff --git a/app/modules/web/Controllers/CategoryController.php b/app/modules/web/Controllers/CategoryController.php index b2de80ca..7d26d0f6 100644 --- a/app/modules/web/Controllers/CategoryController.php +++ b/app/modules/web/Controllers/CategoryController.php @@ -26,6 +26,7 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; +use SP\Core\Events\Event; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; use SP\DataModel\CategoryData; @@ -95,8 +96,10 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa try { $this->setViewData(); - $this->eventDispatcher->notifyEvent('show.category.create', $this); + $this->eventDispatcher->notifyEvent('show.category.create', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(1, $e->getMessage()); } @@ -150,8 +153,10 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa try { $this->setViewData($id); - $this->eventDispatcher->notifyEvent('show.category.edit', $this); + $this->eventDispatcher->notifyEvent('show.category.edit', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -175,11 +180,11 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa $this->deleteCustomFieldsForItem(ActionsInterface::CATEGORY, $id); - $this->eventDispatcher->notifyEvent('delete.category', $this); + $this->eventDispatcher->notifyEvent('delete.category', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Categoría eliminada')); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -204,13 +209,13 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa $this->addCustomFieldsForItem(ActionsInterface::CATEGORY, $id); - $this->eventDispatcher->notifyEvent('create.category', $this); + $this->eventDispatcher->notifyEvent('create.category', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Categoría creada')); } catch (ValidationException $e) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -236,13 +241,13 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa $this->updateCustomFieldsForItem(ActionsInterface::CATEGORY, $id); - $this->eventDispatcher->notifyEvent('edit.category', $this); + $this->eventDispatcher->notifyEvent('edit.category', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Categoría actualizada')); } catch (ValidationException $e) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -266,8 +271,10 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa try { $this->setViewData($id); - $this->eventDispatcher->notifyEvent('show.category', $this); + $this->eventDispatcher->notifyEvent('show.category', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } diff --git a/app/modules/web/Controllers/ClientController.php b/app/modules/web/Controllers/ClientController.php index b861c7d8..341c3092 100644 --- a/app/modules/web/Controllers/ClientController.php +++ b/app/modules/web/Controllers/ClientController.php @@ -27,6 +27,7 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; +use SP\Core\Events\Event; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; use SP\DataModel\ClientData; @@ -96,8 +97,10 @@ class ClientController extends ControllerBase implements CrudControllerInterface try { $this->setViewData(); - $this->eventDispatcher->notifyEvent('show.client.create', $this); + $this->eventDispatcher->notifyEvent('show.client.create', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(1, $e->getMessage()); } @@ -151,8 +154,10 @@ class ClientController extends ControllerBase implements CrudControllerInterface try { $this->setViewData($id); - $this->eventDispatcher->notifyEvent('show.client.edit', $this); + $this->eventDispatcher->notifyEvent('show.client.edit', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -175,11 +180,11 @@ class ClientController extends ControllerBase implements CrudControllerInterface $this->deleteCustomFieldsForItem(ActionsInterface::CLIENT, $id); - $this->eventDispatcher->notifyEvent('delete.client', $this); + $this->eventDispatcher->notifyEvent('delete.client', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Cliente eliminado')); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -202,13 +207,13 @@ class ClientController extends ControllerBase implements CrudControllerInterface $this->clientService->create($form->getItemData()); - $this->eventDispatcher->notifyEvent('create.client', $this); + $this->eventDispatcher->notifyEvent('create.client', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Cliente creado')); } catch (ValidationException $e) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -232,13 +237,13 @@ class ClientController extends ControllerBase implements CrudControllerInterface $this->clientService->update($form->getItemData()); - $this->eventDispatcher->notifyEvent('edit.client', $this); + $this->eventDispatcher->notifyEvent('edit.client', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Cliente actualizado')); } catch (ValidationException $e) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -262,8 +267,10 @@ class ClientController extends ControllerBase implements CrudControllerInterface try { $this->setViewData($id); - $this->eventDispatcher->notifyEvent('show.client', $this); + $this->eventDispatcher->notifyEvent('show.client', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } diff --git a/app/modules/web/Controllers/ConfigAccountController.php b/app/modules/web/Controllers/ConfigAccountController.php new file mode 100644 index 00000000..cad36e40 --- /dev/null +++ b/app/modules/web/Controllers/ConfigAccountController.php @@ -0,0 +1,105 @@ +. + */ + +namespace SP\Modules\Web\Controllers; + +use SP\Core\Acl\ActionsInterface; +use SP\Core\Acl\UnauthorizedPageException; +use SP\Core\Events\Event; +use SP\Core\Exceptions\SPException; +use SP\Http\JsonResponse; +use SP\Http\Request; +use SP\Modules\Web\Controllers\Traits\ConfigTrait; + +/** + * Class ConfigAccountController + * + * @package SP\Modules\Web\Controllers + */ +class ConfigAccountController extends SimpleControllerBase +{ + use ConfigTrait; + + /** + * @throws \SP\Core\Exceptions\InvalidArgumentException + */ + public function saveAction() + { + $configData = clone $this->config->getConfigData(); + + // Accounts + $globalSearchEnabled = Request::analyze('globalsearch', false, false, true); + $accountPassToImageEnabled = Request::analyze('account_passtoimage', false, false, true); + $accountLinkEnabled = Request::analyze('account_link', false, false, true); + $accountFullGroupAccessEnabled = Request::analyze('account_fullgroup_access', false, false, true); + $accountCount = Request::analyze('account_count', 10); + $resultsAsCardsEnabled = Request::analyze('resultsascards', false, false, true); + + $configData->setGlobalSearch($globalSearchEnabled); + $configData->setAccountPassToImage($accountPassToImageEnabled); + $configData->setAccountLink($accountLinkEnabled); + $configData->setAccountFullGroupAccess($accountFullGroupAccessEnabled); + $configData->setAccountCount($accountCount); + $configData->setResultsAsCards($resultsAsCardsEnabled); + + // Files + $filesEnabled = Request::analyze('files_enabled', false, false, true); + $filesAllowedSize = Request::analyze('files_allowed_size', 1024); + $filesAllowedExts = Request::analyze('files_allowed_exts'); + + if ($filesEnabled && $filesAllowedSize >= 16384) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('El tamaño máximo por archivo es de 16MB')); + } + + $configData->setFilesAllowedExts($filesAllowedExts); + $configData->setFilesEnabled($filesEnabled); + $configData->setFilesAllowedSize($filesAllowedSize); + + // Public Links + $pubLinksEnabled = Request::analyze('publinks_enabled', false, false, true); + $pubLinksImageEnabled = Request::analyze('publinks_image_enabled', false, false, true); + $pubLinksMaxTime = Request::analyze('publinks_maxtime', 10); + $pubLinksMaxViews = Request::analyze('publinks_maxviews', 3); + + $configData->setPublinksEnabled($pubLinksEnabled); + $configData->setPublinksImageEnabled($pubLinksImageEnabled); + $configData->setPublinksMaxTime($pubLinksMaxTime * 60); + $configData->setPublinksMaxViews($pubLinksMaxViews); + + $this->eventDispatcher->notifyEvent('save.config.account', new Event($this)); + + $this->saveConfig($configData, $this->config); + } + + protected function initialize() + { + try { + if (!$this->checkAccess(ActionsInterface::ACCOUNT_CONFIG)) { + throw new UnauthorizedPageException(SPException::INFO); + } + } catch (UnauthorizedPageException $e) { + $this->returnJsonResponseException($e); + } + } +} \ No newline at end of file diff --git a/app/modules/web/Controllers/ConfigBackupController.php b/app/modules/web/Controllers/ConfigBackupController.php new file mode 100644 index 00000000..f52f3076 --- /dev/null +++ b/app/modules/web/Controllers/ConfigBackupController.php @@ -0,0 +1,98 @@ +. + */ + +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()]); + } + } +} \ No newline at end of file diff --git a/app/modules/web/Controllers/ConfigEncryptionController.php b/app/modules/web/Controllers/ConfigEncryptionController.php new file mode 100644 index 00000000..bb440f1a --- /dev/null +++ b/app/modules/web/Controllers/ConfigEncryptionController.php @@ -0,0 +1,210 @@ +. + */ + +namespace SP\Modules\Web\Controllers; + +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; +use SP\Core\Acl\ActionsInterface; +use SP\Core\Acl\UnauthorizedPageException; +use SP\Core\Crypt\Hash; +use SP\Core\Crypt\Session as CryptSession; +use SP\Core\Events\Event; +use SP\Core\Exceptions\SPException; +use SP\Core\TaskFactory; +use SP\Http\JsonResponse; +use SP\Http\Request; +use SP\Modules\Web\Controllers\Traits\JsonTrait; +use SP\Services\Config\ConfigService; +use SP\Services\Crypt\MasterPassService; +use SP\Services\Crypt\TemporaryMasterPassService; +use SP\Services\Crypt\UpdateMasterPassRequest; +use SP\Services\ServiceException; +use SP\Util\Util; + +/** + * Class ConfigEncryptionController + * + * @package SP\Modules\Web\Controllers + */ +class ConfigEncryptionController extends SimpleControllerBase +{ + use JsonTrait; + + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + * @throws \SP\Services\Config\ParameterNotFoundException + */ + public function saveAction() + { + $mastePassService = $this->dic->get(MasterPassService::class); + + $currentMasterPass = Request::analyzeEncrypted('curMasterPwd'); + $newMasterPass = Request::analyzeEncrypted('newMasterPwd'); + $newMasterPassR = Request::analyzeEncrypted('newMasterPwdR'); + $confirmPassChange = Request::analyze('confirmPassChange', 0, false, 1); + $noAccountPassChange = Request::analyze('chkNoAccountChange', 0, false, 1); + + if (!$mastePassService->checkUserUpdateMPass($this->session->getUserData()->getLastUpdateMPass())) { + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS_STICKY, __u('Clave maestra actualizada'), [__u('Reinicie la sesión para cambiarla')]); + } + + if (empty($newMasterPass) || empty($currentMasterPass)) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('Clave maestra no indicada')); + } + + if ($confirmPassChange === false) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('Se ha de confirmar el cambio de clave')); + } + + if ($newMasterPass === $currentMasterPass) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('Las claves son idénticas')); + } + + if ($newMasterPass !== $newMasterPassR) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('Las claves maestras no coinciden')); + } + + if (!$mastePassService->checkMasterPassword($currentMasterPass)) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('La clave maestra actual no coincide')); + } + + if ($this->config->getConfigData()->isDemoEnabled()) { + $this->returnJsonResponse(JsonResponse::JSON_WARNING, __u('Ey, esto es una DEMO!!')); + } + + $configService = $this->dic->get(ConfigService::class); + + if (!$noAccountPassChange) { + Util::lockApp(); + + $request = new UpdateMasterPassRequest( + $currentMasterPass, + $newMasterPass, + $configService->getByParam('masterPwd'), + TaskFactory::create(__FUNCTION__, 'masterpass') + ); + + try { + $mastePassService->changeMasterPassword($request); + $configService->save('masterPwd', $request->getHash()); + $configService->save('lastupdatempass', time()); + } catch (\Exception $e) { + processException($e); + + $this->returnJsonResponseException($e); + } finally { + Util::unlockApp(); + + TaskFactory::end($request->getTask()->getTaskId()); + } + } else { + try { + $configService->save('masterPwd', Hash::hashKey($newMasterPass)); + $configService->save('lastupdatempass', time()); + } catch (\Exception $e) { + processException($e); + + $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('Error al guardar el hash de la clave maestra')); + } + } + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS_STICKY, __u('Clave maestra actualizada'), [__u('Reinicie la sesión para cambiarla')]); + } + + /** + * Refresh master password hash + */ + public function refreshAction() + { + if ($this->config->getConfigData()->isDemoEnabled()) { + $this->returnJsonResponse(JsonResponse::JSON_WARNING, __u('Ey, esto es una DEMO!!')); + } + + try { + $configService = $this->dic->get(ConfigService::class); + $configService->save('masterPwd', Hash::hashKey(CryptSession::getSessionKey())); + + $this->eventDispatcher->notifyEvent('refresh.masterPassword', new Event($this, [__u('Hash de clave maestra actualizado')])); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Hash de clave maestra actualizado')); + } catch (\Exception $e) { + processException($e); + + $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('Error al actualizar el hash de la clave maestra')); + } + } + + /** + * Create a temporary master pass + */ + public function saveTempAction() + { + try { + $temporaryMasterPassService = $this->dic->get(TemporaryMasterPassService::class); + $temporaryMasterPassService->create(Request::analyze('tmpass_maxtime', 3600)); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Clave Temporal Generada')); + } catch (ServiceException $e) { + $this->returnJsonResponseException($e); + } + + +// $tempMasterGroup = Request::analyze('tmpass_group', 0); +// $tempMasterEmail = Request::analyze('tmpass_chkSendEmail', 0, false, 1); +// +// $this->LogMessage->addDescription(__('Clave Temporal Generada', false)); +// +// if ($tempMasterEmail) { +// $Message = new NoticeMessage(); +// $Message->setTitle(sprintf(__('Clave Maestra %s'), Util::getAppInfo('appname'))); +// $Message->addDescription(__('Se ha generado una nueva clave para el acceso a sysPass y se solicitará en el siguiente inicio.')); +// $Message->addDescription(''); +// $Message->addDescription(sprintf(__('La nueva clave es: %s'), $tempMasterPass)); +// $Message->addDescription(''); +// $Message->addDescription(__('No olvide acceder lo antes posible para guardar los cambios.')); +// +// if ($tempMasterGroup !== 0) { +// Email::sendEmailBatch($Message, UserUtil::getUserGroupEmail($tempMasterGroup)); +// } else { +// Email::sendEmailBatch($Message, UserUtil::getUsersEmail()); +// } +// } +// +// $this->JsonResponse->setStatus(0); + + } + + protected function initialize() + { + try { + if (!$this->checkAccess(ActionsInterface::ENCRYPTION_CONFIG)) { + throw new UnauthorizedPageException(SPException::INFO); + } + } catch (UnauthorizedPageException $e) { + $this->returnJsonResponseException($e); + } + } +} \ No newline at end of file diff --git a/app/modules/web/Controllers/ConfigGeneralController.php b/app/modules/web/Controllers/ConfigGeneralController.php new file mode 100644 index 00000000..234c4c7d --- /dev/null +++ b/app/modules/web/Controllers/ConfigGeneralController.php @@ -0,0 +1,162 @@ +. + */ + +namespace SP\Modules\Web\Controllers; + +use SP\Core\Acl\ActionsInterface; +use SP\Core\Acl\UnauthorizedPageException; +use SP\Core\Events\Event; +use SP\Core\Exceptions\SPException; +use SP\Http\JsonResponse; +use SP\Http\Request; +use SP\Modules\Web\Controllers\Traits\ConfigTrait; + +/** + * Class ConfigGeneral + * + * @package SP\Modules\Web\Controllers + */ +class ConfigGeneralController extends SimpleControllerBase +{ + use ConfigTrait; + + /** + * @throws \SP\Core\Exceptions\InvalidArgumentException + */ + public function saveAction() + { + $messages = []; + $configData = clone $this->config->getConfigData(); + + // General + $siteLang = Request::analyze('sitelang'); + $siteTheme = Request::analyze('sitetheme', 'material-blue'); + $sessionTimeout = Request::analyze('session_timeout', 300); + $httpsEnabled = Request::analyze('https_enabled', false, false, true); + $debugEnabled = Request::analyze('debug', false, false, true); + $maintenanceEnabled = Request::analyze('maintenance', false, false, true); + $checkUpdatesEnabled = Request::analyze('updates', false, false, true); + $checkNoticesEnabled = Request::analyze('notices', false, false, true); + $encryptSessionEnabled = Request::analyze('encryptsession', false, false, true); + + $configData->setSiteLang($siteLang); + $configData->setSiteTheme($siteTheme); + $configData->setSessionTimeout($sessionTimeout); + $configData->setHttpsEnabled($httpsEnabled); + $configData->setDebug($debugEnabled); + $configData->setMaintenance($maintenanceEnabled); + $configData->setCheckUpdates($checkUpdatesEnabled); + $configData->setChecknotices($checkNoticesEnabled); + $configData->setEncryptSession($encryptSessionEnabled); + + // Events + $logEnabled = Request::analyze('log_enabled', false, false, true); + $syslogEnabled = Request::analyze('syslog_enabled', false, false, true); + $remoteSyslogEnabled = Request::analyze('remotesyslog_enabled', false, false, true); + $syslogServer = Request::analyze('remotesyslog_server'); + $syslogPort = Request::analyze('remotesyslog_port', 0); + + $configData->setLogEnabled($logEnabled); + $configData->setSyslogEnabled($syslogEnabled); + + if ($remoteSyslogEnabled && (!$syslogServer || !$syslogPort)) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('Faltan parámetros de syslog remoto')); + } + + if ($remoteSyslogEnabled) { + $configData->setSyslogRemoteEnabled($remoteSyslogEnabled); + $configData->setSyslogServer($syslogServer); + $configData->setSyslogPort($syslogPort); + } elseif ($configData->isSyslogEnabled()) { + $configData->setSyslogRemoteEnabled(false); + + $messages[] = __u('Syslog remoto deshabilitado'); + } + + // Proxy + $proxyEnabled = Request::analyze('proxy_enabled', false, false, true); + $proxyServer = Request::analyze('proxy_server'); + $proxyPort = Request::analyze('proxy_port', 0); + $proxyUser = Request::analyze('proxy_user'); + $proxyPass = Request::analyzeEncrypted('proxy_pass'); + + + // Valores para Proxy + if ($proxyEnabled && (!$proxyServer || !$proxyPort)) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('Faltan parámetros de Proxy')); + } + + if ($proxyEnabled) { + $configData->setProxyEnabled(true); + $configData->setProxyServer($proxyServer); + $configData->setProxyPort($proxyPort); + $configData->setProxyUser($proxyUser); + $configData->setProxyPass($proxyPass); + + $messages[] = __u('Proxy habiltado'); + } elseif ($configData->isProxyEnabled()) { + $configData->setProxyEnabled(false); + + $messages[] = __u('Proxy deshabilitado'); + } + + // Autentificación + $authBasicEnabled = Request::analyze('authbasic_enabled', false, false, true); + $authBasicAutologinEnabled = Request::analyze('authbasic_enabled', false, false, true); + $authBasicDomain = Request::analyze('authbasic_domain'); + $authSsoDefaultGroup = Request::analyze('sso_defaultgroup', false, false, true); + $authSsoDefaultProfile = Request::analyze('sso_defaultprofile', false, false, true); + + // Valores para Autentificación + if ($authBasicEnabled) { + $configData->setAuthBasicEnabled(true); + $configData->setAuthBasicAutoLoginEnabled($authBasicAutologinEnabled); + $configData->setAuthBasicDomain($authBasicDomain); + $configData->setSsoDefaultGroup($authSsoDefaultGroup); + $configData->setSsoDefaultProfile($authSsoDefaultProfile); + + $messages[] = __u('Auth Basic habilitada'); + } elseif ($configData->isAuthBasicEnabled()) { + $configData->setAuthBasicEnabled(false); + $configData->setAuthBasicAutoLoginEnabled(false); + + $messages[] = __u('Auth Basic deshabiltada'); + } + + $this->eventDispatcher->notifyEvent('save.config.general', new Event($this, $messages)); + + $this->saveConfig($configData, $this->config); + } + + protected function initialize() + { + try { + if (!$this->checkAccess(ActionsInterface::CONFIG_GENERAL)) { + throw new UnauthorizedPageException(SPException::INFO); + } + } catch (UnauthorizedPageException $e) { + $this->returnJsonResponseException($e); + } + } +} \ No newline at end of file diff --git a/app/modules/web/Controllers/ConfigLdapController.php b/app/modules/web/Controllers/ConfigLdapController.php new file mode 100644 index 00000000..5c8be8e2 --- /dev/null +++ b/app/modules/web/Controllers/ConfigLdapController.php @@ -0,0 +1,101 @@ +. + */ + +namespace SP\Modules\Web\Controllers; + +use SP\Core\Acl\ActionsInterface; +use SP\Core\Acl\UnauthorizedPageException; +use SP\Core\Events\Event; +use SP\Core\Exceptions\SPException; +use SP\Http\JsonResponse; +use SP\Http\Request; +use SP\Modules\Web\Controllers\Traits\ConfigTrait; + +/** + * Class ConfigLdapController + * + * @package SP\Modules\Web\Controllers + */ +class ConfigLdapController extends SimpleControllerBase +{ + use ConfigTrait; + + /** + * @throws \SP\Core\Exceptions\InvalidArgumentException + */ + public function saveAction() + { + $messages = []; + $configData = clone $this->config->getConfigData(); + + // LDAP + $ldapEnabled = Request::analyze('ldap_enabled', false, false, true); + $ldapADSEnabled = Request::analyze('ldap_ads', false, false, true); + $ldapServer = Request::analyze('ldap_server'); + $ldapBase = Request::analyze('ldap_base'); + $ldapGroup = Request::analyze('ldap_group'); + $ldapDefaultGroup = Request::analyze('ldap_defaultgroup', 0); + $ldapDefaultProfile = Request::analyze('ldap_defaultprofile', 0); + $ldapBindUser = Request::analyze('ldap_binduser'); + $ldapBindPass = Request::analyzeEncrypted('ldap_bindpass'); + + // Valores para la configuración de LDAP + if ($ldapEnabled && (!$ldapServer || !$ldapBase || !$ldapBindUser)) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('Faltan parámetros de LDAP')); + } + + if ($ldapEnabled) { + $configData->setLdapEnabled(true); + $configData->setLdapAds($ldapADSEnabled); + $configData->setLdapServer($ldapServer); + $configData->setLdapBase($ldapBase); + $configData->setLdapGroup($ldapGroup); + $configData->setLdapDefaultGroup($ldapDefaultGroup); + $configData->setLdapDefaultProfile($ldapDefaultProfile); + $configData->setLdapBindUser($ldapBindUser); + $configData->setLdapBindPass($ldapBindPass); + + $messages[] = __u('LDAP habiltado'); + } elseif ($configData->isLdapEnabled()) { + $configData->setLdapEnabled(false); + + $messages[] = __u('LDAP deshabilitado'); + } + + $this->eventDispatcher->notifyEvent('save.config.ldap', new Event($this, $messages)); + + $this->saveConfig($configData, $this->config); + } + + protected function initialize() + { + try { + if (!$this->checkAccess(ActionsInterface::LDAP_CONFIG)) { + throw new UnauthorizedPageException(SPException::INFO); + } + } catch (UnauthorizedPageException $e) { + $this->returnJsonResponseException($e); + } + } +} \ No newline at end of file diff --git a/app/modules/web/Controllers/ConfigMailController.php b/app/modules/web/Controllers/ConfigMailController.php new file mode 100644 index 00000000..89359b47 --- /dev/null +++ b/app/modules/web/Controllers/ConfigMailController.php @@ -0,0 +1,106 @@ +. + */ + +namespace SP\Modules\Web\Controllers; + +use SP\Core\Acl\ActionsInterface; +use SP\Core\Acl\UnauthorizedPageException; +use SP\Core\Events\Event; +use SP\Core\Exceptions\SPException; +use SP\Http\JsonResponse; +use SP\Http\Request; +use SP\Modules\Web\Controllers\Traits\ConfigTrait; + +/** + * Class ConfigMailController + * + * @package SP\Modules\Web\Controllers + */ +class ConfigMailController extends SimpleControllerBase +{ + use ConfigTrait; + + /** + * @throws \SP\Core\Exceptions\InvalidArgumentException + */ + public function saveAction() + { + $messages = []; + $configData = clone $this->config->getConfigData(); + + // Mail + $mailEnabled = Request::analyze('mail_enabled', false, false, true); + $mailServer = Request::analyze('mail_server'); + $mailPort = Request::analyze('mail_port', 25); + $mailUser = Request::analyze('mail_user'); + $mailPass = Request::analyzeEncrypted('mail_pass'); + $mailSecurity = Request::analyze('mail_security'); + $mailFrom = Request::analyze('mail_from'); + $mailRequests = Request::analyze('mail_requestsenabled', false, false, true); + $mailAuth = Request::analyze('mail_authenabled', false, false, true); + + // Valores para la configuración del Correo + if ($mailEnabled && (!$mailServer || !$mailFrom)) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('Faltan parámetros de Correo')); + } + + if ($mailEnabled) { + $configData->setMailEnabled(true); + $configData->setMailRequestsEnabled($mailRequests); + $configData->setMailServer($mailServer); + $configData->setMailPort($mailPort); + $configData->setMailSecurity($mailSecurity); + $configData->setMailFrom($mailFrom); + + if ($mailAuth) { + $configData->setMailAuthenabled($mailAuth); + $configData->setMailUser($mailUser); + $configData->setMailPass($mailPass); + } + + $messages[] = __u('Correo habiltado'); + } elseif ($configData->isMailEnabled()) { + $configData->setMailEnabled(false); + $configData->setMailRequestsEnabled(false); + $configData->setMailAuthenabled(false); + + $messages[] = __u('Correo deshabilitado'); + } + + $this->eventDispatcher->notifyEvent('save.config.mail', new Event($this, $messages)); + + $this->saveConfig($configData, $this->config); + } + + protected function initialize() + { + try { + if (!$this->checkAccess(ActionsInterface::MAIL_CONFIG)) { + throw new UnauthorizedPageException(SPException::INFO); + } + } catch (UnauthorizedPageException $e) { + $this->returnJsonResponseException($e); + } + } +} \ No newline at end of file diff --git a/app/modules/web/Controllers/ConfigManagerController.php b/app/modules/web/Controllers/ConfigManagerController.php index dbd33ba4..07d0d62a 100644 --- a/app/modules/web/Controllers/ConfigManagerController.php +++ b/app/modules/web/Controllers/ConfigManagerController.php @@ -29,6 +29,7 @@ use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\Crypt\CryptSessionHandler; use SP\Core\CryptMasterPass; +use SP\Core\Events\Event; use SP\Core\Language; use SP\Core\Plugin\PluginUtil; use SP\Core\Task; @@ -63,6 +64,7 @@ class ConfigManagerController extends ControllerBase * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Exceptions\InvalidArgumentException * @throws \SP\Services\Config\ParameterNotFoundException + * @throws \SP\Core\Exceptions\SPException */ public function indexAction() { @@ -76,6 +78,7 @@ class ConfigManagerController extends ControllerBase * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Exceptions\InvalidArgumentException * @throws \SP\Services\Config\ParameterNotFoundException + * @throws \SP\Core\Exceptions\SPException */ protected function getTabs() { @@ -118,7 +121,7 @@ class ConfigManagerController extends ControllerBase } - $this->eventDispatcher->notifyEvent('show.config', $this); + $this->eventDispatcher->notifyEvent('show.config', new Event($this)); $this->tabsHelper->renderTabs(Acl::getActionRoute(ActionsInterface::CONFIG), Request::analyze('tabIndex', 0)); @@ -261,7 +264,7 @@ class ConfigManagerController extends ControllerBase $template->addTemplate('backup'); $template->assign('siteName', Util::getAppInfo('appname')); - $template->assign('backupDir', Bootstrap::$SERVERROOT . '/backup'); + $template->assign('backupDir', BACKUP_PATH); $template->assign('backupPath', Bootstrap::$WEBROOT . '/backup'); $backupHash = $this->configData->getBackupHash(); @@ -270,7 +273,7 @@ class ConfigManagerController extends ControllerBase $backupFile = $template->siteName . '-' . $backupHash . '.tar.gz'; $template->assign('backupFile', [ - 'absolute' => $template->backupDir . DIRECTORY_SEPARATOR . $backupFile, + 'absolute' => BACKUP_PATH . DIRECTORY_SEPARATOR . $backupFile, 'relative' => $template->backupPath . '/' . $backupFile, 'filename' => $backupFile ]); @@ -278,7 +281,7 @@ class ConfigManagerController extends ControllerBase $backupDbFile = $template->siteName . '_db-' . $backupHash . '.sql'; $template->assign('backupDbFile', [ - 'absolute' => $template->backupDir . DIRECTORY_SEPARATOR . $backupDbFile, + 'absolute' => BACKUP_PATH . DIRECTORY_SEPARATOR . $backupDbFile, 'relative' => $template->backupPath . '/' . $backupDbFile, 'filename' => $backupDbFile ]); @@ -291,7 +294,7 @@ class ConfigManagerController extends ControllerBase $exportFile = $template->siteName . '-' . $exportHash . '.xml'; $template->assign('exportFile', [ - 'absolute' => $template->backupDir . DIRECTORY_SEPARATOR . $exportFile, + 'absolute' => BACKUP_PATH . DIRECTORY_SEPARATOR . $exportFile, 'relative' => $template->backupPath . '/' . $exportFile, 'filename' => $exportFile ]); diff --git a/app/modules/web/Controllers/ConfigWikiController.php b/app/modules/web/Controllers/ConfigWikiController.php new file mode 100644 index 00000000..e38a1b6d --- /dev/null +++ b/app/modules/web/Controllers/ConfigWikiController.php @@ -0,0 +1,119 @@ +. + */ + +namespace SP\Modules\Web\Controllers; + +use SP\Core\Acl\ActionsInterface; +use SP\Core\Acl\UnauthorizedPageException; +use SP\Core\Events\Event; +use SP\Core\Exceptions\SPException; +use SP\Http\JsonResponse; +use SP\Http\Request; +use SP\Modules\Web\Controllers\Traits\ConfigTrait; + +/** + * Class ConfigWikiController + * + * @package SP\Modules\Web\Controllers + */ +class ConfigWikiController extends SimpleControllerBase +{ + use ConfigTrait; + + /** + * @throws \SP\Core\Exceptions\InvalidArgumentException + */ + public function saveAction() + { + $messages = []; + $configData = clone $this->config->getConfigData(); + + // Wiki + $wikiEnabled = Request::analyze('wiki_enabled', false, false, true); + $wikiSearchUrl = Request::analyze('wiki_searchurl'); + $wikiPageUrl = Request::analyze('wiki_pageurl'); + $wikiFilter = Request::analyze('wiki_filter'); + + // Valores para la conexión a la Wiki + if ($wikiEnabled && (!$wikiSearchUrl || !$wikiPageUrl || !$wikiFilter)) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('Faltan parámetros de Wiki')); + } + + if ($wikiEnabled) { + $configData->setWikiEnabled(true); + $configData->setWikiSearchurl($wikiSearchUrl); + $configData->setWikiPageurl($wikiPageUrl); + $configData->setWikiFilter(explode(',', $wikiFilter)); + + $messages[] = __u('Wiki habiltada'); + } elseif ($configData->isWikiEnabled()) { + $configData->setWikiEnabled(false); + + $messages[] = __u('Wiki deshabilitada'); + } + + // DokuWiki + $dokuWikiEnabled = Request::analyze('dokuwiki_enabled', false, false, true); + $dokuWikiUrl = Request::analyze('dokuwiki_url'); + $dokuWikiUrlBase = Request::analyze('dokuwiki_urlbase'); + $dokuWikiUser = Request::analyze('dokuwiki_user'); + $dokuWikiPass = Request::analyzeEncrypted('dokuwiki_pass'); + $dokuWikiNamespace = Request::analyze('dokuwiki_namespace'); + + // Valores para la conexión a la API de DokuWiki + if ($dokuWikiEnabled && (!$dokuWikiUrl || !$dokuWikiUrlBase)) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('Faltan parámetros de DokuWiki')); + } + + if ($dokuWikiEnabled) { + $configData->setDokuwikiEnabled(true); + $configData->setDokuwikiUrl($dokuWikiUrl); + $configData->setDokuwikiUrlBase(trim($dokuWikiUrlBase, '/')); + $configData->setDokuwikiUser($dokuWikiUser); + $configData->setDokuwikiPass($dokuWikiPass); + $configData->setDokuwikiNamespace($dokuWikiNamespace); + + $messages[] = __u('DokuWiki habilitada'); + } elseif ($configData->isDokuwikiEnabled()) { + $configData->setDokuwikiEnabled(false); + + $messages[] = __u('DokuWiki deshabilitada'); + } + + $this->eventDispatcher->notifyEvent('save.config.wiki', new Event($this, $messages)); + + $this->saveConfig($configData, $this->config); + } + + protected function initialize() + { + try { + if (!$this->checkAccess(ActionsInterface::WIKI_CONFIG)) { + throw new UnauthorizedPageException(SPException::INFO); + } + } catch (UnauthorizedPageException $e) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage(), [$e->getHint()]); + } + } +} \ No newline at end of file diff --git a/app/modules/web/Controllers/ControllerBase.php b/app/modules/web/Controllers/ControllerBase.php index 37ed1fc9..e9405e26 100644 --- a/app/modules/web/Controllers/ControllerBase.php +++ b/app/modules/web/Controllers/ControllerBase.php @@ -189,7 +189,7 @@ abstract class ControllerBase try { echo $this->view->render(); } catch (FileNotFoundException $e) { - debugLog($e->getMessage(), true); + processException($e); echo $e->getMessage(); } @@ -205,7 +205,7 @@ abstract class ControllerBase try { return $this->view->render(); } catch (FileNotFoundException $e) { - debugLog($e->getMessage(), true); + processException($e); return $e->getMessage(); } diff --git a/app/modules/web/Controllers/CustomFieldController.php b/app/modules/web/Controllers/CustomFieldController.php index 5fdcff61..ade376cd 100644 --- a/app/modules/web/Controllers/CustomFieldController.php +++ b/app/modules/web/Controllers/CustomFieldController.php @@ -27,6 +27,7 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; +use SP\Core\Events\Event; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; use SP\DataModel\CustomFieldDefinitionData; @@ -98,8 +99,10 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte try { $this->setViewData(); - $this->eventDispatcher->notifyEvent('show.customField.create', $this); + $this->eventDispatcher->notifyEvent('show.customField.create', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(1, $e->getMessage()); } @@ -156,8 +159,10 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte try { $this->setViewData($id); - $this->eventDispatcher->notifyEvent('show.customField.edit', $this); + $this->eventDispatcher->notifyEvent('show.customField.edit', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -180,11 +185,11 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte $this->deleteCustomFieldsForItem(ActionsInterface::CUSTOMFIELD, $id); - $this->eventDispatcher->notifyEvent('delete.customField', $this); + $this->eventDispatcher->notifyEvent('delete.customField', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Campo eliminado')); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -205,13 +210,13 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte $this->customFieldService->create($form->getItemData()); - $this->eventDispatcher->notifyEvent('create.customField', $this); + $this->eventDispatcher->notifyEvent('create.customField', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Campo creado')); } catch (ValidationException $e) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -235,13 +240,13 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte $this->customFieldService->update($form->getItemData()); - $this->eventDispatcher->notifyEvent('edit.customField', $this); + $this->eventDispatcher->notifyEvent('edit.customField', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Campo actualizado')); } catch (ValidationException $e) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -265,8 +270,10 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte try { $this->setViewData($id); - $this->eventDispatcher->notifyEvent('show.customField', $this); + $this->eventDispatcher->notifyEvent('show.customField', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } diff --git a/app/modules/web/Controllers/Helpers/LayoutHelper.php b/app/modules/web/Controllers/Helpers/LayoutHelper.php index 4dacbcbd..a4c54b49 100644 --- a/app/modules/web/Controllers/Helpers/LayoutHelper.php +++ b/app/modules/web/Controllers/Helpers/LayoutHelper.php @@ -124,7 +124,7 @@ class LayoutHelper extends HelperBase // Cargar la clave pública en la sesión SessionUtil::loadPublicKey(); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); } $this->getResourcesLinks(); diff --git a/app/modules/web/Controllers/ItemManagerController.php b/app/modules/web/Controllers/ItemManagerController.php index d9e8851f..1a8133de 100644 --- a/app/modules/web/Controllers/ItemManagerController.php +++ b/app/modules/web/Controllers/ItemManagerController.php @@ -26,6 +26,7 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; +use SP\Core\Events\Event; use SP\DataModel\ItemSearchData; use SP\Http\Request; use SP\Modules\Web\Controllers\Helpers\ItemsGridHelper; @@ -118,7 +119,7 @@ class ItemManagerController extends ControllerBase $this->tabsGridHelper->addTab($this->getPluginsList()); } - $this->eventDispatcher->notifyEvent('show.itemlist.items', $this); + $this->eventDispatcher->notifyEvent('show.itemlist.items', new Event($this)); $this->tabsGridHelper->renderTabs(Acl::getActionRoute(ActionsInterface::ITEMS_MANAGE), Request::analyze('tabIndex', 0)); diff --git a/app/modules/web/Controllers/MainController.php b/app/modules/web/Controllers/MainController.php index db4b1e48..4c251671 100644 --- a/app/modules/web/Controllers/MainController.php +++ b/app/modules/web/Controllers/MainController.php @@ -117,7 +117,7 @@ class MainController extends ControllerBase implements ActionsInterface // Cargar la clave pública en la sesión SessionUtil::loadPublicKey(); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); } $this->getResourcesLinks(); diff --git a/app/modules/web/Controllers/PublicLinkController.php b/app/modules/web/Controllers/PublicLinkController.php index a0e68121..426d9a8a 100644 --- a/app/modules/web/Controllers/PublicLinkController.php +++ b/app/modules/web/Controllers/PublicLinkController.php @@ -24,9 +24,9 @@ namespace SP\Modules\Web\Controllers; -use Defuse\Crypto\Exception\CryptoException; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; +use SP\Core\Events\Event; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; use SP\DataModel\PublicLinkListData; @@ -98,8 +98,10 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter try { $this->setViewData(); - $this->eventDispatcher->notifyEvent('show.publicLink.create', $this); + $this->eventDispatcher->notifyEvent('show.publicLink.create', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(1, $e->getMessage()); } @@ -150,15 +152,11 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter try { $this->publicLinkService->refresh($id); - $this->eventDispatcher->notifyEvent('edit.publicLink.refresh', $this); + $this->eventDispatcher->notifyEvent('edit.publicLink.refresh', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Enlace actualizado')); - } catch (SPException $e) { - debugLog($e->getMessage(), true); - - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); - } catch (CryptoException $e) { - debugLog($e->getMessage(), true); + } catch (\Exception $e) { + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -183,8 +181,10 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter try { $this->setViewData($id); - $this->eventDispatcher->notifyEvent('show.publicLink.edit', $this); + $this->eventDispatcher->notifyEvent('show.publicLink.edit', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -208,11 +208,11 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter $this->deleteCustomFieldsForItem(ActionsInterface::PUBLICLINK, $id); - $this->eventDispatcher->notifyEvent('delete.publicLink', $this); + $this->eventDispatcher->notifyEvent('delete.publicLink', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Enlace eliminado')); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -223,7 +223,6 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter * * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface - * @throws \SP\Core\Dic\ContainerException */ public function saveCreateAction() { @@ -238,17 +237,13 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter $this->publicLinkService->create($form->getItemData()); // $this->publicLinkService->logAction($id, ActionsInterface::PUBLICLINK_CREATE); - $this->eventDispatcher->notifyEvent('create.publicLink', $this); + $this->eventDispatcher->notifyEvent('create.publicLink', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Enlace creado')); } catch (ValidationException $e) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); - } catch (CryptoException $e) { - debugLog($e->getMessage(), true); - - $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); - } catch (SPException $e) { - debugLog($e->getMessage(), true); + } catch (\Exception $e) { + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -282,8 +277,10 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter try { $this->setViewData($id); - $this->eventDispatcher->notifyEvent('show.publicLink', $this); + $this->eventDispatcher->notifyEvent('show.publicLink', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } diff --git a/app/modules/web/Controllers/SimpleControllerBase.php b/app/modules/web/Controllers/SimpleControllerBase.php index a38da2e3..bb5f8f49 100644 --- a/app/modules/web/Controllers/SimpleControllerBase.php +++ b/app/modules/web/Controllers/SimpleControllerBase.php @@ -28,6 +28,7 @@ use DI\Container; use Interop\Container\ContainerInterface; use Klein\Klein; use SP\Config\Config; +use SP\Core\Acl\Acl; use SP\Core\Events\EventDispatcher; use SP\Core\Session\Session; use SP\Core\UI\Theme; @@ -74,6 +75,10 @@ abstract class SimpleControllerBase * @var ContainerInterface */ protected $dic; + /** + * @var Acl + */ + protected $acl; /** * SimpleControllerBase constructor. @@ -95,6 +100,7 @@ abstract class SimpleControllerBase $this->theme = $this->dic->get(Theme::class); $this->eventDispatcher = $this->dic->get(EventDispatcher::class); $this->router = $this->dic->get(Klein::class); + $this->acl = $this->dic->get(Acl::class); if (method_exists($this, 'initialize')) { $this->initialize(); @@ -109,4 +115,15 @@ abstract class SimpleControllerBase $this->checkLoggedInSession($this->session); $this->checkSecurityToken($this->session); } + + /** + * Comprobar si está permitido el acceso al módulo/página. + * + * @param null $action La acción a comprobar + * @return bool + */ + protected function checkAccess($action) + { + return $this->session->getUserData()->getIsAdminApp() || $this->acl->checkUserAccess($action); + } } \ No newline at end of file diff --git a/app/modules/web/Controllers/TagController.php b/app/modules/web/Controllers/TagController.php index 518e93cd..58622b00 100644 --- a/app/modules/web/Controllers/TagController.php +++ b/app/modules/web/Controllers/TagController.php @@ -27,6 +27,7 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; +use SP\Core\Events\Event; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; use SP\DataModel\TagData; @@ -96,8 +97,10 @@ class TagController extends ControllerBase implements CrudControllerInterface try { $this->setViewData(); - $this->eventDispatcher->notifyEvent('show.tag.create', $this); + $this->eventDispatcher->notifyEvent('show.tag.create', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(1, $e->getMessage()); } @@ -149,8 +152,10 @@ class TagController extends ControllerBase implements CrudControllerInterface try { $this->setViewData($id); - $this->eventDispatcher->notifyEvent('show.tag.edit', $this); + $this->eventDispatcher->notifyEvent('show.tag.edit', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -173,11 +178,11 @@ class TagController extends ControllerBase implements CrudControllerInterface $this->deleteCustomFieldsForItem(ActionsInterface::TAG, $id); - $this->eventDispatcher->notifyEvent('delete.tag', $this); + $this->eventDispatcher->notifyEvent('delete.tag', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Etiqueta eliminada')); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -200,13 +205,13 @@ class TagController extends ControllerBase implements CrudControllerInterface $this->tagService->create($form->getItemData()); - $this->eventDispatcher->notifyEvent('create.tag', $this); + $this->eventDispatcher->notifyEvent('create.tag', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Etiqueta creada')); } catch (ValidationException $e) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -230,13 +235,13 @@ class TagController extends ControllerBase implements CrudControllerInterface $this->tagService->update($form->getItemData()); - $this->eventDispatcher->notifyEvent('edit.tag', $this); + $this->eventDispatcher->notifyEvent('edit.tag', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Etiqueta actualizada')); } catch (ValidationException $e) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -260,8 +265,10 @@ class TagController extends ControllerBase implements CrudControllerInterface try { $this->setViewData($id); - $this->eventDispatcher->notifyEvent('show.tag', $this); + $this->eventDispatcher->notifyEvent('show.tag', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } diff --git a/app/modules/web/Controllers/Traits/ConfigTrait.php b/app/modules/web/Controllers/Traits/ConfigTrait.php new file mode 100644 index 00000000..004a0842 --- /dev/null +++ b/app/modules/web/Controllers/Traits/ConfigTrait.php @@ -0,0 +1,68 @@ +. + */ + +namespace SP\Modules\Web\Controllers\Traits; + +use SP\Bootstrap; +use SP\Config\Config; +use SP\Config\ConfigData; +use SP\Http\JsonResponse; +use SP\Util\Util; + +/** + * Trait ConfigTrait + * + * @package SP\Modules\Web\Controllers\Traits + */ +trait ConfigTrait +{ + use JsonTrait; + + /** + * Guardar la configuración + * + * @param ConfigData $configData + * @param Config $config + */ + protected function saveConfig(ConfigData $configData, Config $config) + { + try { + if ($configData->isDemoEnabled()) { + $this->returnJsonResponse(JsonResponse::JSON_WARNING, __u('Ey, esto es una DEMO!!')); + } + + $config->saveConfig($configData); + + if ($configData->isMaintenance()) { + Util::lockApp(false); + } elseif (Bootstrap::$LOCK > 0) { + Util::unlockApp(false); + } + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Configuración actualizada')); + } catch (\Exception $e) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('Error al guardar la configuración')); + } + } +} \ No newline at end of file diff --git a/app/modules/web/Controllers/Traits/JsonTrait.php b/app/modules/web/Controllers/Traits/JsonTrait.php index d3e98847..8246358a 100644 --- a/app/modules/web/Controllers/Traits/JsonTrait.php +++ b/app/modules/web/Controllers/Traits/JsonTrait.php @@ -24,6 +24,7 @@ namespace SP\Modules\Web\Controllers\Traits; +use SP\Core\Exceptions\SPException; use SP\Http\JsonResponse; use SP\Util\Json; @@ -72,6 +73,25 @@ trait JsonTrait } + Json::returnJson($jsonResponse); + } + + /** + * Returns JSON response + * + * @param \Exception $exception + * @param int $status Status code + */ + protected function returnJsonResponseException(\Exception $exception, $status = JsonResponse::JSON_ERROR) + { + $jsonResponse = new JsonResponse(); + $jsonResponse->setStatus($status); + $jsonResponse->setDescription($exception->getMessage()); + + if ($exception instanceof SPException && $exception->getHint() !== null ) { + $jsonResponse->setMessages([$exception->getHint()]); + } + Json::returnJson($jsonResponse); } } \ No newline at end of file diff --git a/app/modules/web/Controllers/UserController.php b/app/modules/web/Controllers/UserController.php index a2454417..486fbb89 100644 --- a/app/modules/web/Controllers/UserController.php +++ b/app/modules/web/Controllers/UserController.php @@ -26,6 +26,7 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; +use SP\Core\Events\Event; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; use SP\Core\SessionUtil; @@ -100,8 +101,10 @@ class UserController extends ControllerBase implements CrudControllerInterface try { $this->setViewData(); - $this->eventDispatcher->notifyEvent('show.user.create', $this); + $this->eventDispatcher->notifyEvent('show.user.create', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(1, $e->getMessage()); } @@ -159,8 +162,10 @@ class UserController extends ControllerBase implements CrudControllerInterface try { $this->setViewData($id); - $this->eventDispatcher->notifyEvent('show.user.edit', $this); + $this->eventDispatcher->notifyEvent('show.user.edit', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -193,8 +198,10 @@ class UserController extends ControllerBase implements CrudControllerInterface $this->view->assign('user', $user); - $this->eventDispatcher->notifyEvent('show.user.editPass', $this); + $this->eventDispatcher->notifyEvent('show.user.editPass', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -220,11 +227,11 @@ class UserController extends ControllerBase implements CrudControllerInterface $this->deleteCustomFieldsForItem(ActionsInterface::USER, $id); - $this->eventDispatcher->notifyEvent('delete.user', $this); + $this->eventDispatcher->notifyEvent('delete.user', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Usuario eliminado')); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -248,7 +255,7 @@ class UserController extends ControllerBase implements CrudControllerInterface $this->addCustomFieldsForItem(ActionsInterface::USER, $id); - $this->eventDispatcher->notifyEvent('create.user', $this); + $this->eventDispatcher->notifyEvent('create.user', new Event($this)); if ($form->getItemData()->isIsChangePass() && !AuthUtil::mailPassRecover($form->getItemData()) @@ -263,8 +270,8 @@ class UserController extends ControllerBase implements CrudControllerInterface $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Usuario creado')); } catch (ValidationException $e) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); - } catch (SPException $e) { - debugLog($e->getMessage(), true); + } catch (\Exception $e) { + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -291,7 +298,7 @@ class UserController extends ControllerBase implements CrudControllerInterface $this->updateCustomFieldsForItem(ActionsInterface::USER, $id); - $this->eventDispatcher->notifyEvent('edit.user', $this); + $this->eventDispatcher->notifyEvent('edit.user', new Event($this)); if ($form->getItemData()->isIsChangePass() && !AuthUtil::mailPassRecover($form->getItemData()) @@ -306,8 +313,8 @@ class UserController extends ControllerBase implements CrudControllerInterface $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Usuario actualizado')); } catch (ValidationException $e) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); - } catch (SPException $e) { - debugLog($e->getMessage(), true); + } catch (\Exception $e) { + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -331,13 +338,13 @@ class UserController extends ControllerBase implements CrudControllerInterface $this->userService->updatePass($form->getItemData()); // $this->userService->logAction($id, ActionsInterface::USER_EDIT_PASS); - $this->eventDispatcher->notifyEvent('edit.user.pass', $this); + $this->eventDispatcher->notifyEvent('edit.user.pass', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Clave actualizada')); } catch (ValidationException $e) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); - } catch (SPException $e) { - debugLog($e->getMessage(), true); + } catch (\Exception $e) { + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -362,8 +369,10 @@ class UserController extends ControllerBase implements CrudControllerInterface try { $this->setViewData($id); - $this->eventDispatcher->notifyEvent('show.user', $this); + $this->eventDispatcher->notifyEvent('show.user', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } diff --git a/app/modules/web/Controllers/UserGroupController.php b/app/modules/web/Controllers/UserGroupController.php index 0bb50563..3c5c4ef4 100644 --- a/app/modules/web/Controllers/UserGroupController.php +++ b/app/modules/web/Controllers/UserGroupController.php @@ -26,6 +26,7 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; +use SP\Core\Events\Event; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; use SP\DataModel\UserGroupData; @@ -102,8 +103,10 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf try { $this->setViewData(); - $this->eventDispatcher->notifyEvent('show.userGroup.create', $this); + $this->eventDispatcher->notifyEvent('show.userGroup.create', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(1, $e->getMessage()); } @@ -159,8 +162,10 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf try { $this->setViewData($id); - $this->eventDispatcher->notifyEvent('show.userGroup.edit', $this); + $this->eventDispatcher->notifyEvent('show.userGroup.edit', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -184,11 +189,11 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf $this->deleteCustomFieldsForItem(ActionsInterface::GROUP, $id); - $this->eventDispatcher->notifyEvent('delete.userGroup', $this); + $this->eventDispatcher->notifyEvent('delete.userGroup', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Grupo eliminado')); } catch (SPException $e) { - debugLog($e->getMessage(), true); + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -215,13 +220,13 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf $this->addCustomFieldsForItem(ActionsInterface::GROUP, $id); - $this->eventDispatcher->notifyEvent('create.userGroup', $this); + $this->eventDispatcher->notifyEvent('create.userGroup', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Grupo creado')); } catch (ValidationException $e) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); - } catch (SPException $e) { - debugLog($e->getMessage(), true); + } catch (\Exception $e) { + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -250,13 +255,13 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf $this->updateCustomFieldsForItem(ActionsInterface::GROUP, $id); - $this->eventDispatcher->notifyEvent('edit.useGroup', $this); + $this->eventDispatcher->notifyEvent('edit.useGroup', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Grupo actualizado')); } catch (ValidationException $e) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); - } catch (SPException $e) { - debugLog($e->getMessage(), true); + } catch (\Exception $e) { + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -280,8 +285,10 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf try { $this->setViewData($id); - $this->eventDispatcher->notifyEvent('show.userGroup', $this); + $this->eventDispatcher->notifyEvent('show.userGroup', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } diff --git a/app/modules/web/Controllers/UserProfileController.php b/app/modules/web/Controllers/UserProfileController.php index fb65c390..5050f75b 100644 --- a/app/modules/web/Controllers/UserProfileController.php +++ b/app/modules/web/Controllers/UserProfileController.php @@ -26,7 +26,7 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; -use SP\Core\Exceptions\SPException; +use SP\Core\Events\Event; use SP\Core\Exceptions\ValidationException; use SP\DataModel\ProfileData; use SP\Forms\UserProfileForm; @@ -95,8 +95,10 @@ class UserProfileController extends ControllerBase implements CrudControllerInte try { $this->setViewData(); - $this->eventDispatcher->notifyEvent('show.userProfile.create', $this); + $this->eventDispatcher->notifyEvent('show.userProfile.create', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(1, $e->getMessage()); } @@ -152,8 +154,10 @@ class UserProfileController extends ControllerBase implements CrudControllerInte try { $this->setViewData($id); - $this->eventDispatcher->notifyEvent('show.userProfile.edit', $this); + $this->eventDispatcher->notifyEvent('show.userProfile.edit', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -177,11 +181,11 @@ class UserProfileController extends ControllerBase implements CrudControllerInte $this->deleteCustomFieldsForItem(ActionsInterface::PROFILE, $id); - $this->eventDispatcher->notifyEvent('delete.userProfile', $this); + $this->eventDispatcher->notifyEvent('delete.userProfile', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Perfil eliminado')); - } catch (SPException $e) { - debugLog($e->getMessage(), true); + } catch (\Exception $e) { + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -207,13 +211,13 @@ class UserProfileController extends ControllerBase implements CrudControllerInte $this->addCustomFieldsForItem(ActionsInterface::PROFILE, $id); - $this->eventDispatcher->notifyEvent('create.userProfile', $this); + $this->eventDispatcher->notifyEvent('create.userProfile', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Perfil creado')); } catch (ValidationException $e) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); - } catch (SPException $e) { - debugLog($e->getMessage(), true); + } catch (\Exception $e) { + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -241,13 +245,13 @@ class UserProfileController extends ControllerBase implements CrudControllerInte $this->updateCustomFieldsForItem(ActionsInterface::PROFILE, $id); - $this->eventDispatcher->notifyEvent('edit.userProfile', $this); + $this->eventDispatcher->notifyEvent('edit.userProfile', new Event($this)); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Perfil actualizado')); } catch (ValidationException $e) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); - } catch (SPException $e) { - debugLog($e->getMessage(), true); + } catch (\Exception $e) { + processException($e); $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } @@ -271,8 +275,10 @@ class UserProfileController extends ControllerBase implements CrudControllerInte try { $this->setViewData($id); - $this->eventDispatcher->notifyEvent('show.userProfile', $this); + $this->eventDispatcher->notifyEvent('show.userProfile', new Event($this)); } catch (\Exception $e) { + processException($e); + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); } 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 a536a8ca..1281b3a8 100644 --- a/app/modules/web/themes/material-blue/views/config/accounts.inc +++ b/app/modules/web/themes/material-blue/views/config/accounts.inc @@ -2,7 +2,7 @@
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 19788c1d..66075cd5 100644 --- a/app/modules/web/themes/material-blue/views/config/backup.inc +++ b/app/modules/web/themes/material-blue/views/config/backup.inc @@ -44,10 +44,6 @@ - -
-
-
+
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 ae3b3847..7873b9c5 100644 --- a/app/modules/web/themes/material-blue/views/config/encryption.inc +++ b/app/modules/web/themes/material-blue/views/config/encryption.inc @@ -1,7 +1,8 @@ -
@@ -138,7 +139,7 @@ @@ -163,8 +164,7 @@ + data-action-route="configEncryption/saveTemp">
@@ -266,8 +266,6 @@
- -
diff --git a/app/modules/web/themes/material-blue/views/config/general.inc b/app/modules/web/themes/material-blue/views/config/general.inc index 0c017eb6..5f3a41f5 100644 --- a/app/modules/web/themes/material-blue/views/config/general.inc +++ b/app/modules/web/themes/material-blue/views/config/general.inc @@ -4,7 +4,7 @@ ?>
@@ -12,9 +12,6 @@ includeTemplate('general-events'); ?> includeTemplate('general-proxy'); ?> includeTemplate('general-auth'); ?> - - -
diff --git a/app/modules/web/themes/material-blue/views/config/ldap.inc b/app/modules/web/themes/material-blue/views/config/ldap.inc index ab7a8842..907428ed 100644 --- a/app/modules/web/themes/material-blue/views/config/ldap.inc +++ b/app/modules/web/themes/material-blue/views/config/ldap.inc @@ -6,7 +6,7 @@
@@ -312,10 +312,6 @@
- - - -
@@ -331,7 +327,7 @@ @@ -340,6 +336,7 @@
- - - -
@@ -277,6 +275,7 @@
";mdlDialog().show({text:b,negative:{title:c.config().LANG[44],onClick:function(a){a.preventDefault();c.msg.error(c.config().LANG[44])}},positive:{title:c.config().LANG[43],onClick:function(b){b=c.appRequests().getRequestOpts();b.url=f.account.save;b.data={r:"account/saveDelete/"+a.data("item-id"),sk:c.sk.get()};c.appRequests().getActionCall(b,function(a){c.msg.out(a);k.search()})}}})},viewPass:function(a){e.info("account:showpass");var b=a.data("parent-id")||0,b=0=== -b?a.data("item-id"):b,d=a.data("history")||0,g=c.appRequests().getRequestOpts();g.url=f.entrypoint;g.method="get";g.data={r:a.data("action-route")+"/"+b+"/"+d,sk:c.sk.get(),isAjax:1};c.appRequests().getActionCall(g,function(a){0!==a.status?c.msg.out(a):(a=$(a.data.html),p(a),l=setTimeout(function(){$.magnificPopup.close()},3E4),a.on("mouseleave",function(){clearTimeout(l);l=setTimeout(function(){$.magnificPopup.close()},3E4)}).on("mouseenter",function(){0!==l&&clearTimeout(l)}))})},copyPass:function(a){e.info("account:copypass"); -var b=a.data("parent-id"),b=0===b?a.data("item-id"):b,d=c.appRequests().getRequestOpts();d.url=f.entrypoint;d.method="get";d.async=!1;d.data={r:a.data("action-route")+"/"+b+"/"+a.data("history"),sk:c.sk.get(),isAjax:1};return c.appRequests().getActionCall(d)},copy:function(a){e.info("account:copy");n(c.appRequests().getRouteForQuery(a.data("action-route"),a.data("item-id")),"account")},saveFavorite:function(a,b){e.info("account:saveFavorite");var d="on"===a.data("status"),g={r:(d?a.data("action-id-off"): -a.data("action-id-on"))+"/"+a.data("item-id"),sk:c.sk.get(),isAjax:1},q=c.appRequests().getRequestOpts();q.url=f.account.saveFavorite;q.data=g;c.appRequests().getActionCall(q,function(g){c.msg.out(g);0===g.status&&(a.data("status",d?"off":"on"),"function"===typeof b&&b())})},request:function(a){e.info("account:request");var b=c.appRequests().getRequestOpts();b.url=f.account.request;b.data=a.serialize();c.appRequests().getActionCall(b,function(a){c.msg.out(a)})},menu:function(c){c.hide();c.parent().children(".actions-optional").show(250)}, -sort:function(c){e.info("account:sort");var a=$("#frmSearch");a.find('input[name="skey"]').val(c.data("key"));a.find('input[name="sorder"]').val(c.data("dir"));a.find('input[name="start"]').val(c.data("start"));k.search()},editPass:function(a){e.info("account:editpass");var b=a.data("parent-id"),b=void 0===b?a.data("item-id"):b;n(c.appRequests().getRouteForQuery(a.data("action-route"),b),"account")},saveEditRestore:function(a){e.info("account:restore");var b=c.appRequests().getRequestOpts();b.url= -f.entrypoint+"?r="+a.data("action-route")+"/"+a.data("history-id")+"/"+a.data("item-id");b.data=a.serialize();c.appRequests().getActionCall(b,function(a){c.msg.out(a);void 0!==a.data.itemId&&void 0!==a.data.nextAction&&n(c.appRequests().getRouteForQuery(a.data.nextAction,a.data.itemId),"account")})},listFiles:function(a){e.info("account:getfiles");var b=c.appRequests().getRequestOpts();b.method="get";b.type="html";b.url=f.entrypoint;b.data={r:a.data("action-route")+"/"+a.data("item-id"),del:a.data("delete"), +var $jscomp={scope:{},findInternal:function(c,e,k){c instanceof String&&(c=String(c));for(var f=c.length,m=0;m'+b+""),g=d.find("img");if(0===g.length)return n(b);g.hide();$.magnificPopup.open({items:{src:d,type:"inline"},callbacks:{open:function(){var a=this;g.on("click",function(){a.close()});setTimeout(function(){var a=c.resizeImage(g);d.css({backgroundColor:"#fff",width:a.width,height:"auto"});g.show("slow")}, +500)}}})},p={view:function(a){e.info("account:show");l(c.appRequests().getRouteForQuery(a.data("action-route"),a.data("item-id")),"account")},viewHistory:function(a){e.info("account:showHistory");l(c.appRequests().getRouteForQuery(a.data("action-route"),a.val()),"account")},edit:function(a){e.info("account:edit");l(c.appRequests().getRouteForQuery(a.data("action-route"),a.data("item-id")),"account")},"delete":function(a){e.info("account:delete");var b='

'+c.config().LANG[3]+ +"

";mdlDialog().show({text:b,negative:{title:c.config().LANG[44],onClick:function(a){a.preventDefault();c.msg.error(c.config().LANG[44])}},positive:{title:c.config().LANG[43],onClick:function(d){d=c.appRequests().getRequestOpts();d.url=f.account.save;d.data={r:"account/saveDelete/"+a.data("item-id"),sk:c.sk.get()};c.appRequests().getActionCall(d,function(a){c.msg.out(a);p.search()})}}})},viewPass:function(a){e.info("account:showpass");var b=a.data("parent-id")||0,b=0===b?a.data("item-id"): +b,d=a.data("history")||0,g=c.appRequests().getRequestOpts();g.url=f.entrypoint;g.method="get";g.data={r:a.data("action-route")+"/"+b+"/"+d,sk:c.sk.get(),isAjax:1};c.appRequests().getActionCall(g,function(a){0!==a.status?c.msg.out(a):(a=$(a.data.html),n(a),k=setTimeout(function(){$.magnificPopup.close()},3E4),a.on("mouseleave",function(){clearTimeout(k);k=setTimeout(function(){$.magnificPopup.close()},3E4)}).on("mouseenter",function(){0!==k&&clearTimeout(k)}))})},copyPass:function(a){e.info("account:copypass"); +var b=a.data("parent-id"),b=0===b?a.data("item-id"):b,d=c.appRequests().getRequestOpts();d.url=f.entrypoint;d.method="get";d.async=!1;d.data={r:a.data("action-route")+"/"+b+"/"+a.data("history"),sk:c.sk.get(),isAjax:1};return c.appRequests().getActionCall(d)},copy:function(a){e.info("account:copy");l(c.appRequests().getRouteForQuery(a.data("action-route"),a.data("item-id")),"account")},saveFavorite:function(a,b){e.info("account:saveFavorite");var d="on"===a.data("status"),g={r:(d?a.data("action-id-off"): +a.data("action-id-on"))+"/"+a.data("item-id"),sk:c.sk.get(),isAjax:1},q=c.appRequests().getRequestOpts();q.url=f.account.saveFavorite;q.data=g;c.appRequests().getActionCall(q,function(g){c.msg.out(g);0===g.status&&(a.data("status",d?"off":"on"),"function"===typeof b&&b())})},request:function(a){e.info("account:request");var b=c.appRequests().getRequestOpts();b.url=f.account.request;b.data=a.serialize();c.appRequests().getActionCall(b,function(a){c.msg.out(a)})},menu:function(a){a.hide();a.parent().children(".actions-optional").show(250)}, +sort:function(a){e.info("account:sort");var c=$("#frmSearch");c.find('input[name="skey"]').val(a.data("key"));c.find('input[name="sorder"]').val(a.data("dir"));c.find('input[name="start"]').val(a.data("start"));p.search()},editPass:function(a){e.info("account:editpass");var b=a.data("parent-id"),b=void 0===b?a.data("item-id"):b;l(c.appRequests().getRouteForQuery(a.data("action-route"),b),"account")},saveEditRestore:function(a){e.info("account:restore");var b=c.appRequests().getRequestOpts();b.url= +f.entrypoint+"?r="+a.data("action-route")+"/"+a.data("history-id")+"/"+a.data("item-id");b.data=a.serialize();c.appRequests().getActionCall(b,function(a){c.msg.out(a);void 0!==a.data.itemId&&void 0!==a.data.nextAction&&l(c.appRequests().getRouteForQuery(a.data.nextAction,a.data.itemId),"account")})},listFiles:function(a){e.info("account:getfiles");var b=c.appRequests().getRequestOpts();b.method="get";b.type="html";b.url=f.entrypoint;b.data={r:a.data("action-route")+"/"+a.data("item-id"),del:a.data("delete"), sk:c.sk.get()};c.appRequests().getActionCall(b,function(c){a.html(c)})},search:function(a){e.info("account:search");var b=$("#frmSearch");b.find("input[name='sk']").val(c.sk.get());b.find("input[name='skey']").val();b.find("input[name='sorder']").val();void 0!==a&&b.find("input[name='start']").val(0);a=c.appRequests().getRequestOpts();a.url=f.account.search;a.method="get";a.data=b.serialize();c.appRequests().getActionCall(a,function(a){10===a.status&&c.msg.out(a);c.sk.set(a.data.sk);$("#res-content").empty().html(a.data.html)})}, -save:function(a){e.info("account:save");var b=c.appRequests().getRequestOpts();b.url=f.account.save+"?r="+a.data("action-route")+"/"+a.data("item-id");b.data=a.serialize();c.appRequests().getActionCall(b,function(a){c.msg.out(a);void 0!==a.data.itemId&&void 0!==a.data.nextAction&&n(c.appRequests().getRouteForQuery(a.data.nextAction,a.data.itemId),"account")})}};"use strict";var e=c.log,l=0,f={entrypoint:"/index.php",doAction:"/index.php",updateItems:"/index.php",user:{savePreferences:"/ajax/ajax_userPrefsSave.php", -password:"/ajax/ajax_usrpass.php",passreset:"/ajax/ajax_passReset.php"},main:{login:"/index.php?r=login/login",install:"/ajax/ajax_install.php",upgrade:"/ajax/ajax_upgrade.php",getUpdates:"/index.php?r=index/checkUpdates",task:"/ajax/ajax_task.php"},checks:"/ajax/ajax_checkConnection.php",config:{save:"/ajax/ajax_configSave.php","export":"/ajax/ajax_configSave.php","import":"/ajax/ajax_configSave.php"},file:"/ajax/ajax_filesMgmt.php",link:"/index.php",plugin:"/ajax/ajax_itemSave.php",account:{save:"/index.php", -saveFavorite:"/ajax/ajax_itemSave.php",request:"/ajax/ajax_itemSave.php",getFiles:"/index.php",search:"/index.php?r=account/search"},appMgmt:{show:"/index.php",save:"/index.php",search:"/index.php"},eventlog:"/ajax/ajax_eventlog.php",wiki:{show:"/ajax/ajax_wiki.php"},notice:{show:"/ajax/ajax_noticeShow.php",search:"/ajax/ajax_noticeSearch.php"}};Object.freeze(f);var m=function(a,b){var d={r:a.r+(void 0!==a.itemId?"/"+a.itemId:""),isAjax:1},g=c.appRequests().getRequestOpts();g.url=f.doAction;g.method= -"get";g.type="html";g.addHistory=!0;g.data=d;c.appRequests().getActionCall(g,function(a){var d=$("#content");d.empty().html(a);a=c.triggers().views;a.common(d);if(void 0!==b&&"function"===typeof a[b])a[b]();d=$(".mdl-layout__content");0'+b+""),g=d.find("img");if(0===g.length)return p(b);g.hide();$.magnificPopup.open({items:{src:d,type:"inline"},callbacks:{open:function(){var a=this;g.on("click",function(){a.close()});setTimeout(function(){var a=c.resizeImage(g);d.css({backgroundColor:"#fff",width:a.width,height:"auto"});g.show("slow")},500)}}})},r={get:function(a){e.info("items:get");var b=a[0].selectize;b.clearOptions();b.load(function(d){var g=c.appRequests().getRequestOpts(); -g.url=f.updateItems;g.method="get";g.data={r:a.data("action-route")+"/"+a.data("item-id"),sk:a.data("sk")};c.appRequests().getActionCall(g,function(g){d(g.data);b.setValue(a.data("selected-id"),!0);c.appTriggers().updateFormHash()})})},update:function(a){e.info("items:update");var b=$("#"+a.data("item-dst"))[0].selectize;b.clearOptions();b.load(function(b){var d=c.appRequests().getRequestOpts();d.url=f.updateItems;d.method="get";d.data={r:a.data("item-route"),sk:c.sk.get()};c.appRequests().getActionCall(d, -function(a){b(a)})})}},t={logout:function(){c.redirect("index.php?r=login/logout")},login:function(a){e.info("main:login");var b=c.appRequests().getRequestOpts();b.url=f.entrypoint+"?r="+a.data("route");b.method="get";b.data=a.serialize();c.appRequests().getActionCall(b,function(b){var d=$(".extra-hidden");switch(b.status){case 0:c.redirect(b.data.url);break;case 2:c.msg.out(b);a.find("input[type='text'],input[type='password']").val("");a.find("input:first").focus();0";mdlDialog().show({text:b,negative:{title:c.config().LANG[44],onClick:function(a){a.preventDefault();c.msg.error(c.config().LANG[44])}},positive:{title:c.config().LANG[43],onClick:function(b){b=a.find("input[name='useTask']");var d=$("#taskStatus");d.empty().html(c.config().LANG[62]); if(0",d=a.data("selection"),g=[];if(d&&($(d).find(".is-selected").each(function(){var a=$(this);g.push(a.data("item-id"))}),0===g.length))return;mdlDialog().show({text:b,negative:{title:c.config().LANG[44], -onClick:function(a){a.preventDefault();c.msg.error(c.config().LANG[44])}},positive:{title:c.config().LANG[43],onClick:function(b){b.preventDefault();b=c.appRequests().getRequestOpts();b.url=f.appMgmt.save;b.method="get";b.data={r:a.data("action-route")+"/"+a.data("item-id"),sk:c.sk.get(),isAjax:1};c.appRequests().getActionCall(b,function(a){c.msg.out(a);n({r:h.state.tab.route,tabIndex:h.state.tab.index})})}}})},save:function(a){e.info("appMgmt:save");var b=c.appRequests().getRequestOpts();b.url=f.appMgmt.save+ -"?r="+a.data("route");b.data=a.serialize();c.appRequests().getActionCall(b,function(a){c.msg.out(a);0===a.status&&(!0===h.state.tab.refresh&&n({r:h.state.tab.route,tabIndex:h.state.tab.index}),$.magnificPopup.close())})},search:function(a){e.info("appMgmt:search");var b=$(a.data("target")),d=c.appRequests().getRequestOpts();d.url=f.appMgmt.search+"?r="+a.data("action-route");d.method="get";d.data=a.serialize();c.appRequests().getActionCall(d,function(a){0===a.status?b.html(a.data.html):b.html(c.msg.html.error(a.description)); -c.sk.set(a.csrf)})},nav:function(a){e.info("appMgmt:nav");var b=$("#"+a.data("action-form"));b.find("[name='start']").val(a.data("start"));b.find("[name='count']").val(a.data("count"));b.find("[name='sk']").val(c.sk.get());h.search(b)},ldapSync:function(a){e.info("appMgmt:ldapSync");var b='

'+c.config().LANG[57]+"

";mdlDialog().show({text:b,negative:{title:c.config().LANG[44],onClick:function(a){a.preventDefault();c.msg.error(c.config().LANG[44])}},positive:{title:c.config().LANG[43], -onClick:function(b){b=c.appRequests().getRequestOpts();b.url=f.appMgmt.save;b.data={actionId:a.data("action-id"),sk:c.sk.get(),isAjax:1,ldap_loginattribute:$("#ldap_loginattribute").val(),ldap_nameattribute:$("#ldap_nameattribute").val(),ldap_ads:$("#ldap_ads").prop("checked")};c.appRequests().getActionCall(b,function(a){c.msg.out(a)})}}})}};return{doAction:m,appMgmt:h,account:k,file:{view:function(a){e.info("file:view");var b=c.appRequests().getRequestOpts();b.url=f.entrypoint;b.method="get";b.data= -{r:a.data("action-route")+"/"+a.data("item-id"),sk:c.sk.get()};c.appRequests().getActionCall(b,function(b){if(1===b.status)return c.msg.out(b);u(a,b.data.html)})},download:function(a){e.info("file:download");a={r:a.data("action-route")+"/"+a.data("item-id"),sk:c.sk.get()};$.fileDownload(f.entrypoint,{httpMethod:"GET",data:a})},"delete":function(a){e.info("file:delete");var b='

'+c.config().LANG[15]+"

";mdlDialog().show({text:b,negative:{title:c.config().LANG[44], -onClick:function(a){a.preventDefault();c.msg.error(c.config().LANG[44])}},positive:{title:c.config().LANG[43],onClick:function(b){b=c.appRequests().getRequestOpts();b.url=f.entrypoint;b.method="get";b.data={r:a.data("action-route")+"/"+a.data("item-id"),sk:c.sk.get()};c.appRequests().getActionCall(b,function(a){c.msg.out(a);0===a.status&&k.listFiles($("#list-account-files"))})}}})}},checks:{ldap:function(a){e.info("checks:ldap");a=$(a.data("src"));a.find("[name='sk']").val(c.sk.get());var b=c.appRequests().getRequestOpts(); +0!==b.status?a.find(":input[name=h]").val(""):(void 0!==e&&e.close(),setTimeout(function(){c.redirect("index.php")},5E3))})}}})},getUpdates:function(){e.info("main:getUpdates");var a=c.appRequests().getRequestOpts();a.url=f.main.getUpdates;a.type="html";a.method="get";a.timeout=1E4;a.useLoading=!1;a.data={isAjax:1};c.appRequests().getActionCall(a,function(a){$("#updates").html(a);void 0!==componentHandler&&componentHandler.upgradeDom()},function(){$("#updates").html("!")})}},h={state:{tab:{index:0, +refresh:!0,route:""},itemId:0,update:function(a){var c=$("#content").find("[id^='tabs-'].is-active");0",d=a.data("selection"),g=[];if(d&&($(d).find(".is-selected").each(function(){var a=$(this);g.push(a.data("item-id"))}),0===g.length))return;mdlDialog().show({text:b,negative:{title:c.config().LANG[44], +onClick:function(a){a.preventDefault();c.msg.error(c.config().LANG[44])}},positive:{title:c.config().LANG[43],onClick:function(b){b.preventDefault();b=c.appRequests().getRequestOpts();b.url=f.entrypoint;b.method="get";b.data={r:a.data("action-route")+"/"+a.data("item-id"),sk:c.sk.get(),isAjax:1};c.appRequests().getActionCall(b,function(a){c.msg.out(a);l({r:h.state.tab.route,tabIndex:h.state.tab.index})})}}})},save:function(a){e.info("appMgmt:save");var b=c.appRequests().getRequestOpts();b.url=f.entrypoint+ +"?r="+a.data("route");b.data=a.serialize();c.appRequests().getActionCall(b,function(a){c.msg.out(a);0===a.status&&(!0===h.state.tab.refresh&&l({r:h.state.tab.route,tabIndex:h.state.tab.index}),$.magnificPopup.close())})},search:function(a){e.info("appMgmt:search");var b=$(a.data("target")),d=c.appRequests().getRequestOpts();d.url=f.entrypoint+"?r="+a.data("action-route");d.method="get";d.data=a.serialize();c.appRequests().getActionCall(d,function(a){0===a.status?b.html(a.data.html):b.html(c.msg.html.error(a.description)); +c.sk.set(a.csrf)})},nav:function(a){e.info("appMgmt:nav");var b=$("#"+a.data("action-form"));b.find("[name='start']").val(a.data("start"));b.find("[name='count']").val(a.data("count"));b.find("[name='sk']").val(c.sk.get());r.search(b)},ldapSync:function(a){e.info("appMgmt:ldapSync");var b='

'+c.config().LANG[57]+"

";mdlDialog().show({text:b,negative:{title:c.config().LANG[44],onClick:function(a){a.preventDefault();c.msg.error(c.config().LANG[44])}},positive:{title:c.config().LANG[43], +onClick:function(b){b=c.appRequests().getRequestOpts();b.url=f.appMgmt.save;b.data={actionId:a.data("action-id"),sk:c.sk.get(),isAjax:1,ldap_loginattribute:$("#ldap_loginattribute").val(),ldap_nameattribute:$("#ldap_nameattribute").val(),ldap_ads:$("#ldap_ads").prop("checked")};c.appRequests().getActionCall(b,function(a){c.msg.out(a)})}}})}};return{doAction:m,appMgmt:r,account:p,file:{view:function(a){e.info("file:view");var b=c.appRequests().getRequestOpts();b.url=f.entrypoint;b.method="get";b.data= +{r:a.data("action-route")+"/"+a.data("item-id"),sk:c.sk.get()};c.appRequests().getActionCall(b,function(b){if(1===b.status)return c.msg.out(b);v(a,b.data.html)})},download:function(a){e.info("file:download");a={r:a.data("action-route")+"/"+a.data("item-id"),sk:c.sk.get()};$.fileDownload(f.entrypoint,{httpMethod:"GET",data:a})},"delete":function(a){e.info("file:delete");var b='

'+c.config().LANG[15]+"

";mdlDialog().show({text:b,negative:{title:c.config().LANG[44], +onClick:function(a){a.preventDefault();c.msg.error(c.config().LANG[44])}},positive:{title:c.config().LANG[43],onClick:function(b){b=c.appRequests().getRequestOpts();b.url=f.entrypoint;b.method="get";b.data={r:a.data("action-route")+"/"+a.data("item-id"),sk:c.sk.get()};c.appRequests().getActionCall(b,function(a){c.msg.out(a);0===a.status&&p.listFiles($("#list-account-files"))})}}})}},checks:{ldap:function(a){e.info("checks:ldap");a=$(a.data("src"));a.find("[name='sk']").val(c.sk.get());var b=c.appRequests().getRequestOpts(); b.url=f.checks;b.data=a.serialize();c.appRequests().getActionCall(b,function(a){c.msg.out(a);var b=$("#ldap-results");b.find(".list-wrap").html(c.appTheme().html.getList(a.data));b.show("slow")})},wiki:function(a){e.info("checks:wiki");a=$(a.data("src"));a.find("[name='sk']").val(c.sk.get());var b=c.appRequests().getRequestOpts();b.url=f.checks;b.data=a.serialize();c.appRequests().getActionCall(b,function(a){c.msg.out(a);0===a.status&&$("#dokuWikiResCheck").html(a.data)})}},config:{save:function(a){e.info("config:save"); -var b=c.appRequests().getRequestOpts();b.url=f.config.save;b.data=a.serialize();"masterpass"===a.data("type")&&(b.useFullLoading=!0);c.appRequests().getActionCall(b,function(b){c.msg.out(b);0===b.status&&(void 0!==a.data("nextaction-id")?m({actionId:a.data("nextaction-id"),itemId:a.data("activetab")}):void 0!==a.data("reload")&&setTimeout(function(){c.redirect("index.php")},2E3))})},masterpass:function(a){var b='

'+c.config().LANG[59]+"

";mdlDialog().show({text:b, -negative:{title:c.config().LANG[44],onClick:function(b){b.preventDefault();c.msg.error(c.config().LANG[44]);a.find(":input[type=password]").val("")}},positive:{title:c.config().LANG[43],onClick:function(b){b=a.find("input[name='useTask']");var d=$("#taskStatus");d.empty().html(c.config().LANG[62]);if(0";mdlDialog().show({text:d,negative:{title:c.config().LANG[44],onClick:function(a){a.preventDefault();c.appRequests().getActionCall(b,function(a){c.msg.out(a)})}},positive:{title:c.config().LANG[43], -onClick:function(d){d.preventDefault();b.data.notify=1;c.appRequests().getActionCall(b,function(b){c.msg.out(b);m({actionId:a.data("nextaction-id"),itemId:a.data("item-id")})})}}})},refresh:function(a){e.info("link:refresh");h.state.update(a);var b=c.appRequests().getRequestOpts();b.url=f.link;b.data={r:a.data("action-route")+"/"+a.data("item-id"),sk:c.sk.get(),isAjax:1};c.appRequests().getActionCall(b,function(a){c.msg.out(a);n({r:h.state.tab.route,tabIndex:h.state.tab.index})})}},eventlog:{nav:function(a){if(void 0=== -a.data("start"))return!1;var b=c.appRequests().getRequestOpts();b.url=f.eventlog;b.method="get";b.type="html";b.data={actionId:a.data("action-id"),sk:c.sk.get(),isAjax:1,start:a.data("start"),count:a.data("count"),current:a.data("current")};c.appRequests().getActionCall(b,function(a){$("#content").html(a);c.scrollUp()})},clear:function(a){var b='

'+c.config().LANG[20]+"

";mdlDialog().show({text:b,negative:{title:c.config().LANG[44],onClick:function(a){a.preventDefault(); -c.msg.error(c.config().LANG[44])}},positive:{title:c.config().LANG[43],onClick:function(b){b.preventDefault();b=c.appRequests().getRequestOpts();b.url=f.eventlog;b.method="get";b.data={clear:1,sk:c.sk.get(),isAjax:1};c.appRequests().getActionCall(b,function(b){c.msg.out(b);0==b.status&&m({actionId:a.data("nextaction-id")})})}}})}},ajaxUrl:f,plugin:{toggle:function(a){e.info("plugin:enable");a={itemId:a.data("item-id"),actionId:a.data("action-id"),sk:c.sk.get(),activeTab:a.data("activetab")};var b= -c.appRequests().getRequestOpts();b.url=f.appMgmt.save;b.data=a;c.appRequests().getActionCall(b,function(a){c.msg.out(a);0===a.status&&setTimeout(function(){c.redirect("index.php")},2E3)})},reset:function(a){e.info("plugin:reset");var b='

'+c.config().LANG[58]+"

";mdlDialog().show({text:b,negative:{title:c.config().LANG[44],onClick:function(a){a.preventDefault();c.msg.error(c.config().LANG[44])}},positive:{title:c.config().LANG[43],onClick:function(b){b.preventDefault(); -b={itemId:a.data("item-id"),actionId:a.data("action-id"),sk:c.sk.get(),activeTab:a.data("activetab")};var d=c.appRequests().getRequestOpts();d.url=f.appMgmt.save;d.data=b;c.appRequests().getActionCall(d,function(a){c.msg.out(a)})}}})}},notice:{check:function(a){e.info("notice:check");var b={itemId:a.data("item-id"),actionId:a.data("action-id"),sk:c.sk.get()},d=c.appRequests().getRequestOpts();d.url=f.appMgmt.save;d.data=b;c.appRequests().getActionCall(d,function(b){c.msg.out(b);0===b.status&&m({actionId:a.data("nextaction-id"), -itemId:a.data("activetab")})})},search:function(a){e.info("notice:search");var b=$(a.data("target")),d=c.appRequests().getRequestOpts();d.url=f.notice.search;d.method="get";d.data=a.serialize();c.appRequests().getActionCall(d,function(a){0===a.status?b.html(a.data.html):b.html(c.msg.html.error(a.description));c.sk.set(a.csrf)})},show:function(a){e.info("notice:show");var b=c.appRequests().getRequestOpts();b.url=f.notice.show;b.method="get";b.data={itemId:a.data("item-id"),actionId:a.data("action-id"), -activeTab:a.data("activetab"),sk:c.sk.get(),isAjax:1};c.appRequests().getActionCall(b,function(a){0!==a.status?c.msg.out(a):p(a.data.html)})}},wiki:{show:function(a){e.info("wiki:show");var b=c.appRequests().getRequestOpts();b.url=f.wiki.show;b.method="get";b.data={pageName:a.data("pagename"),actionId:a.data("action-id"),sk:c.sk.get(),isAjax:1};c.appRequests().getActionCall(b,function(a){0!==a.status?c.msg.out(a):p(a.data.html)})}},items:r}}; +h.state.update(a);var b=c.appRequests().getRequestOpts();b.url=f.entrypoint+"?r="+a.data("action-route");b.data=a.serialize();c.appRequests().getActionCall(b,function(b){c.msg.out(b);0===b.status&&(!0===h.state.tab.refresh?l({r:h.state.tab.route,tabIndex:h.state.tab.index}):void 0!==a.data("reload")&&setTimeout(function(){c.redirect("index.php")},2E3))})},masterpass:function(a){var b='

'+c.config().LANG[59]+"

";mdlDialog().show({text:b,negative:{title:c.config().LANG[44], +onClick:function(b){b.preventDefault();c.msg.error(c.config().LANG[44]);a.find(":input[type=password]").val("")}},positive:{title:c.config().LANG[43],onClick:function(b){b=a.find("input[name='useTask']");var d=$("#taskStatus");d.empty().html(c.config().LANG[62]);0";mdlDialog().show({text:d,negative:{title:c.config().LANG[44],onClick:function(a){a.preventDefault();c.appRequests().getActionCall(b,function(a){c.msg.out(a)})}},positive:{title:c.config().LANG[43],onClick:function(d){d.preventDefault();b.data.notify=1;c.appRequests().getActionCall(b,function(b){c.msg.out(b);m({actionId:a.data("nextaction-id"), +itemId:a.data("item-id")})})}}})},refresh:function(a){e.info("link:refresh");r.state.update(a);var b=c.appRequests().getRequestOpts();b.url=f.link;b.data={r:a.data("action-route")+"/"+a.data("item-id"),sk:c.sk.get(),isAjax:1};c.appRequests().getActionCall(b,function(a){c.msg.out(a);l({r:h.state.tab.route,tabIndex:h.state.tab.index})})}},eventlog:{nav:function(a){if(void 0===a.data("start"))return!1;var b=c.appRequests().getRequestOpts();b.url=f.eventlog;b.method="get";b.type="html";b.data={actionId:a.data("action-id"), +sk:c.sk.get(),isAjax:1,start:a.data("start"),count:a.data("count"),current:a.data("current")};c.appRequests().getActionCall(b,function(a){$("#content").html(a);c.scrollUp()})},clear:function(a){var b='

'+c.config().LANG[20]+"

";mdlDialog().show({text:b,negative:{title:c.config().LANG[44],onClick:function(a){a.preventDefault();c.msg.error(c.config().LANG[44])}},positive:{title:c.config().LANG[43],onClick:function(b){b.preventDefault();b=c.appRequests().getRequestOpts(); +b.url=f.eventlog;b.method="get";b.data={clear:1,sk:c.sk.get(),isAjax:1};c.appRequests().getActionCall(b,function(b){c.msg.out(b);0==b.status&&m({actionId:a.data("nextaction-id")})})}}})}},ajaxUrl:f,plugin:{toggle:function(a){e.info("plugin:enable");a={itemId:a.data("item-id"),actionId:a.data("action-id"),sk:c.sk.get(),activeTab:a.data("activetab")};var b=c.appRequests().getRequestOpts();b.url=f.appMgmt.save;b.data=a;c.appRequests().getActionCall(b,function(a){c.msg.out(a);0===a.status&&setTimeout(function(){c.redirect("index.php")}, +2E3)})},reset:function(a){e.info("plugin:reset");var b='

'+c.config().LANG[58]+"

";mdlDialog().show({text:b,negative:{title:c.config().LANG[44],onClick:function(a){a.preventDefault();c.msg.error(c.config().LANG[44])}},positive:{title:c.config().LANG[43],onClick:function(b){b.preventDefault();b={itemId:a.data("item-id"),actionId:a.data("action-id"),sk:c.sk.get(),activeTab:a.data("activetab")};var d=c.appRequests().getRequestOpts();d.url=f.appMgmt.save;d.data= +b;c.appRequests().getActionCall(d,function(a){c.msg.out(a)})}}})}},notice:{check:function(a){e.info("notice:check");var b={itemId:a.data("item-id"),actionId:a.data("action-id"),sk:c.sk.get()},d=c.appRequests().getRequestOpts();d.url=f.appMgmt.save;d.data=b;c.appRequests().getActionCall(d,function(b){c.msg.out(b);0===b.status&&m({actionId:a.data("nextaction-id"),itemId:a.data("activetab")})})},search:function(a){e.info("notice:search");var b=$(a.data("target")),d=c.appRequests().getRequestOpts();d.url= +f.notice.search;d.method="get";d.data=a.serialize();c.appRequests().getActionCall(d,function(a){0===a.status?b.html(a.data.html):b.html(c.msg.html.error(a.description));c.sk.set(a.csrf)})},show:function(a){e.info("notice:show");var b=c.appRequests().getRequestOpts();b.url=f.notice.show;b.method="get";b.data={itemId:a.data("item-id"),actionId:a.data("action-id"),activeTab:a.data("activetab"),sk:c.sk.get(),isAjax:1};c.appRequests().getActionCall(b,function(a){0!==a.status?c.msg.out(a):n(a.data.html)})}}, +wiki:{show:function(a){e.info("wiki:show");var b=c.appRequests().getRequestOpts();b.url=f.wiki.show;b.method="get";b.data={pageName:a.data("pagename"),actionId:a.data("action-id"),sk:c.sk.get(),isAjax:1};c.appRequests().getActionCall(b,function(a){0!==a.status?c.msg.out(a):n(a.data.html)})}},items:t}}; diff --git a/schemas/dbstructure.sql b/schemas/dbstructure.sql index 284ce08a..4de488b1 100644 --- a/schemas/dbstructure.sql +++ b/schemas/dbstructure.sql @@ -127,16 +127,16 @@ CREATE TABLE `AccountToFavorite` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -DROP TABLE IF EXISTS `AccountToGroup`; +DROP TABLE IF EXISTS AccountToUserGroup; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `AccountToGroup` ( +CREATE TABLE `AccountToUserGroup` ( `accountId` mediumint(8) unsigned NOT NULL, `userGroupId` smallint(5) unsigned NOT NULL, KEY `IDX_accountId` (`accountId`), KEY `fk_AccountToGroup_userGroupId` (`userGroupId`), - CONSTRAINT `fk_AccountToGroup_accountId` FOREIGN KEY (`accountId`) REFERENCES `Account` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `fk_AccountToGroup_userGroupId` FOREIGN KEY (`userGroupId`) REFERENCES `UserGroup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `fk_AccountToUserGroup_accountId` FOREIGN KEY (`accountId`) REFERENCES `Account` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `fk_AccountToUserGroup_userGroupId` FOREIGN KEY (`userGroupId`) REFERENCES `UserGroup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; @@ -465,16 +465,16 @@ CREATE TABLE `UserProfile` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -DROP TABLE IF EXISTS `UserToGroup`; +DROP TABLE IF EXISTS UserToUserGroup; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `UserToGroup` ( +CREATE TABLE `UserToUserGroup` ( `userId` smallint(5) unsigned NOT NULL, `userGroupId` smallint(5) unsigned NOT NULL, KEY `IDX_usertogroup_userId` (`userId`), KEY `fk_UserToGroup_userGroupId` (`userGroupId`), - CONSTRAINT `fk_UserToGroup_userGroupId` FOREIGN KEY (`userGroupId`) REFERENCES `UserGroup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `fk_UserToGroup_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `fk_UserToUserGroup_userGroupId` FOREIGN KEY (`userGroupId`) REFERENCES `UserGroup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `fk_UserToUserGroup_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */;