diff --git a/app/modules/web/Controllers/AccountController.php b/app/modules/web/Controllers/AccountController.php index 6fc84193..ba191fc4 100644 --- a/app/modules/web/Controllers/AccountController.php +++ b/app/modules/web/Controllers/AccountController.php @@ -34,6 +34,7 @@ use SP\Core\Events\EventMessage; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; use SP\Core\Session\Session; +use SP\Core\UI\ThemeIconsBase; use SP\DataModel\AccountExtData; use SP\Http\JsonResponse; use SP\Http\Request; @@ -68,6 +69,10 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * @var AccountService */ protected $accountService; + /** + * @var ThemeIconsBase + */ + protected $icons; /** * Index action @@ -183,24 +188,6 @@ class AccountController extends ControllerBase implements CrudControllerInterfac ) { $publicLinkService->addLinkView($publicLinkData); -// if ($publicLinkData->isNotify()) { -// $Message = new NoticeMessage(); -// $Message->setTitle(__('Enlace visualizado')); -// $Message->addDescription(sprintf('%s : %s', __('Cuenta'), $PublicLink->getItemId())); -// $Message->addDescription(sprintf('%s : %s', __('Origen'), $this->configData->isDemoEnabled() ? '*.*.*.*' : HttpUtil::getClientAddress(true))); -// $Message->addDescription(sprintf('%s : %s', __('Agente'), Request::getRequestHeaders('HTTP_USER_AGENT'))); -// $Message->addDescription(sprintf('HTTPS : %s', Checks::httpsEnabled() ? 'ON' : 'OFF')); -// -// -// $NoticeData = new NoticeData(); -// $NoticeData->setNoticeComponent(__('Cuentas')); -// $NoticeData->setNoticeDescription($Message); -// $NoticeData->setNoticeType(__('Información')); -// $NoticeData->setNoticeUserId($PublicLink->getPublicLinkUserId()); -// -// Notice::getItem($NoticeData)->add(); -// } - $this->accountService->incrementViewCounter($publicLinkData->getItemId()); $this->accountService->incrementDecryptCounter($publicLinkData->getItemId()); @@ -229,11 +216,15 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->view->assign('accountData', $accountData); - $this->eventDispatcher->notifyEvent('show.account.link', new Event($this, - EventMessage::factory() - ->addDescription(__('Enlace visualizado')) - ->addDetail(__('Cuenta'), $accountData->getName()) - ->addDetail(__('Cliente'), $accountData->getClientName())) + $this->eventDispatcher->notifyEvent('show.account.link', + new Event($this, EventMessage::factory() + ->addDescription(__u('Enlace visualizado')) + ->addDetail(__u('Cuenta'), $accountData->getName()) + ->addDetail(__u('Cliente'), $accountData->getClientName()) + ->addDetail(__u('Agente'), $this->router->request()->headers()->get('User-Agent')) + ->addDetail(__u('HTTPS'), $this->router->request()->isSecure() ? __u('ON') : __u('OFF')) + ->addData('userId', $publicLinkData->getUserId()) + ->addData('notify', $publicLinkData->isNotify())) ); } else { ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_PAGE_NO_PERMISSION, 'account-link'); @@ -886,5 +877,6 @@ class AccountController extends ControllerBase implements CrudControllerInterfac } $this->accountService = $this->dic->get(AccountService::class); + $this->icons = $this->theme->getIcons(); } } \ No newline at end of file diff --git a/app/modules/web/Controllers/ConfigEncryptionController.php b/app/modules/web/Controllers/ConfigEncryptionController.php index 4870306d..ef0c36e3 100644 --- a/app/modules/web/Controllers/ConfigEncryptionController.php +++ b/app/modules/web/Controllers/ConfigEncryptionController.php @@ -130,6 +130,8 @@ class ConfigEncryptionController extends SimpleControllerBase } } else { try { + $this->eventDispatcher->notifyEvent('update.masterPassword.hash', new Event($this)); + $configService->save('masterPwd', Hash::hashKey($newMasterPass)); $configService->save('lastupdatempass', time()); } catch (\Exception $e) { @@ -183,7 +185,7 @@ class ConfigEncryptionController extends SimpleControllerBase $groupId = Request::analyzeInt('tmpass_group'); $sendEmail = Request::analyzeBool('tmpass_chkSendEmail'); - if ($sendEmail && $groupId) { + if ($this->configData->isMailEnabled() && $sendEmail && $groupId) { $mailMessage = new MailMessage(); $mailMessage->setTitle(sprintf(__('Clave Maestra %s'), Util::getAppInfo('appname'))); $mailMessage->addDescription(__('Se ha generado una nueva clave para el acceso a sysPass y se solicitará en el siguiente inicio.')); diff --git a/app/modules/web/Controllers/ConfigImportController.php b/app/modules/web/Controllers/ConfigImportController.php index 50c69484..01ec1454 100644 --- a/app/modules/web/Controllers/ConfigImportController.php +++ b/app/modules/web/Controllers/ConfigImportController.php @@ -64,6 +64,9 @@ class ConfigImportController extends SimpleControllerBase $importParams->setCsvDelimiter(Request::analyzeString('csvDelimiter')); try { + + $this->eventDispatcher->notifyEvent('run.import.start', new Event($this)); + $counter = $this->dic->get(ImportService::class) ->doImport($importParams, new FileImport($this->router->request()->files()->get('inFile'))); diff --git a/app/modules/web/Controllers/ControllerBase.php b/app/modules/web/Controllers/ControllerBase.php index 0cca1509..dd3c83ac 100644 --- a/app/modules/web/Controllers/ControllerBase.php +++ b/app/modules/web/Controllers/ControllerBase.php @@ -37,7 +37,6 @@ use SP\Core\Exceptions\FileNotFoundException; use SP\Core\Language; use SP\Core\Session\Session; use SP\Core\UI\Theme; -use SP\Core\UI\ThemeIconsBase; use SP\DataModel\ProfileData; use SP\Modules\Web\Controllers\Helpers\LayoutHelper; use SP\Mvc\Controller\ControllerTrait; @@ -75,10 +74,6 @@ abstract class ControllerBase * @var string Nombre de la acción */ protected $actionName; - /** - * @var ThemeIconsBase Instancia de los iconos del tema visual - */ - protected $icons; /** * @var string Nombre del controlador */ @@ -158,8 +153,6 @@ abstract class ControllerBase $this->view->setBase(strtolower($this->controllerName)); - $this->icons = $this->theme->getIcons(); - $this->isAjax = $this->router->request()->headers()->get('X_REQUESTED_WITH') === 'XMLHttpRequest'; if ($this->session->isLoggedIn()) { @@ -189,8 +182,8 @@ abstract class ControllerBase $this->view->assign('userIsAdminAcc', $this->userData->getIsAdminAcc()); $this->view->assign('themeUri', $this->view->getTheme()->getThemeUri()); $this->view->assign('isDemo', $this->configData->isDemoEnabled()); - $this->view->assign('icons', clone $this->icons); - $this->view->assign('configData', clone $this->configData); + $this->view->assign('icons', $this->theme->getIcons()); + $this->view->assign('configData', $this->configData); } /** diff --git a/app/modules/web/Controllers/Helpers/Account/AccountActionsHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountActionsHelper.php index 33919896..a3cd2fdd 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountActionsHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountActionsHelper.php @@ -236,7 +236,7 @@ class AccountActionsHelper extends HelperBase $action->setTitle(__('Crear Enlace Público')); $action->addClass('btn-action'); $action->setIcon($this->icons->getIconPublicLink()); - $action->addData('action-route', 'publicLink/saveCreate'); + $action->addData('action-route', 'publicLink/saveCreateFromAccount'); $action->addData('action-sk', $this->sk); $action->addData('onclick', 'link/save'); $action->addData('action-next', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW)); diff --git a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php index 06eed2bf..d94f4978 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php @@ -93,7 +93,7 @@ class AccountHelper extends HelperBase * Sets account's view variables * * @param AccountDetailsResponse $accountDetailsResponse - * @param int $actionId + * @param int $actionId * @throws AccountPermissionException * @throws SPException * @throws UnauthorizedPageException @@ -131,12 +131,17 @@ class AccountHelper extends HelperBase if ($this->configData->isPublinksEnabled() && $this->accountAcl->isShowLink()) { $publicLinkData = $this->publicLinkService->getHashForItem($this->accountId); - $publicLinkUrl = $publicLinkData ? PublicLinkService::getLinkForHash($publicLinkData->getHash()) : null; + $hasPublicLink = !empty($publicLinkData); + + $publicLinkUrl = $hasPublicLink ? PublicLinkService::getLinkForHash($publicLinkData->getHash()) : null; + $this->view->assign('publicLinkUrl', $publicLinkUrl); - $this->view->assign('publicLinkId', $publicLinkData ? $publicLinkData->getId() : 0); + $this->view->assign('publicLinkId', $hasPublicLink ? $publicLinkData->getId() : 0); $this->view->assign('publicLinkShow', true); - $accountActionsDto->setPublicLinkId($publicLinkData->getId()); + if ($hasPublicLink) { + $accountActionsDto->setPublicLinkId($publicLinkData->getId()); + } } else { $this->view->assign('publicLinkShow', false); } @@ -289,7 +294,7 @@ class AccountHelper extends HelperBase * Sets account's view variables * * @param AccountDetailsResponse $accountDetailsResponse - * @param int $actionId + * @param int $actionId * @return bool * @throws UnauthorizedPageException * @throws UpdatedMasterPassException diff --git a/app/modules/web/Controllers/PublicLinkController.php b/app/modules/web/Controllers/PublicLinkController.php index 8eb0c634..ae3318b5 100644 --- a/app/modules/web/Controllers/PublicLinkController.php +++ b/app/modules/web/Controllers/PublicLinkController.php @@ -2,7 +2,7 @@ /** * sysPass * - * @author nuxsmin + * @author nuxsmin * @link https://syspass.org * @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org * @@ -30,9 +30,11 @@ use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; +use SP\DataModel\PublicLinkData; use SP\DataModel\PublicLinkListData; use SP\Http\JsonResponse; use SP\Http\Request; +use SP\Mgmt\PublicLinks\PublicLink; use SP\Modules\Web\Controllers\Helpers\ItemsGridHelper; use SP\Modules\Web\Controllers\Traits\ItemTrait; use SP\Modules\Web\Controllers\Traits\JsonTrait; @@ -41,6 +43,7 @@ use SP\Mvc\Controller\CrudControllerInterface; use SP\Mvc\View\Components\SelectItemAdapter; use SP\Services\Account\AccountService; use SP\Services\PublicLink\PublicLinkService; +use SP\Util\Util; /** * Class PublicLinkController @@ -277,6 +280,39 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter } } + /** + * Saves create action + * + * @param int $accountId + * @param int $notify + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + */ + public function saveCreateFromAccountAction($accountId, $notify) + { + if (!$this->acl->checkUserAccess(ActionsInterface::PUBLICLINK_CREATE)) { + return; + } + + try { + $publicLinkData = new PublicLinkData(); + $publicLinkData->setTypeId(PublicLink::TYPE_ACCOUNT); + $publicLinkData->setItemId($accountId); + $publicLinkData->setNotify((bool)$notify); + $publicLinkData->setHash(Util::generateRandomBytes()); + + $this->publicLinkService->create($publicLinkData); + + $this->eventDispatcher->notifyEvent('create.publicLink.account', new Event($this)); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Enlace creado')); + } catch (\Exception $e) { + processException($e); + + $this->returnJsonResponseException($e); + } + } + /** * Saves edit action * @@ -284,7 +320,7 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter */ public function saveEditAction($id) { - + throw new \RuntimeException('Not implemented'); } /** diff --git a/app/modules/web/Controllers/SimpleControllerBase.php b/app/modules/web/Controllers/SimpleControllerBase.php index bbfe40ea..2a984872 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\Config\ConfigData; use SP\Core\Acl\Acl; use SP\Core\Acl\UnauthorizedPageException; use SP\Core\Events\EventDispatcher; @@ -80,6 +81,10 @@ abstract class SimpleControllerBase * @var Acl */ protected $acl; + /** + * @var ConfigData + */ + protected $configData; /** * SimpleControllerBase constructor. @@ -97,6 +102,7 @@ abstract class SimpleControllerBase $this->actionName = $actionName; $this->config = $this->dic->get(Config::class); + $this->configData = $this->config->getConfigData(); $this->session = $this->dic->get(Session::class); $this->theme = $this->dic->get(Theme::class); $this->eventDispatcher = $this->dic->get(EventDispatcher::class); 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 7873b9c5..0733c228 100644 --- a/app/modules/web/themes/material-blue/views/config/encryption.inc +++ b/app/modules/web/themes/material-blue/views/config/encryption.inc @@ -1,4 +1,8 @@ - +
@@ -243,9 +248,9 @@