mirror of
https://github.com/nuxsmin/sysPass.git
synced 2026-03-24 17:17:15 +01:00
* [ADD] Add Public Link notifications
This commit is contained in:
@@ -26,6 +26,7 @@ namespace Plugins\Authenticator;
|
||||
|
||||
use SP\Controller\ControllerBase;
|
||||
use SP\Core\Init;
|
||||
use SP\Core\Messages\NoticeMessage;
|
||||
use SP\Core\Plugin\PluginBase;
|
||||
use SP\Core\Session as CoreSession;
|
||||
use SP\DataModel\NoticeData;
|
||||
@@ -110,10 +111,7 @@ class LoginController
|
||||
return;
|
||||
}
|
||||
|
||||
$NoticeData = new NoticeData();
|
||||
$NoticeData->setNoticeComponent($this->Plugin->getName());
|
||||
$NoticeData->setNoticeUserId($userId);
|
||||
$NoticeData->setNoticeType(_t('authenticator', 'Aviso Caducidad'));
|
||||
|
||||
|
||||
if (count(Notice::getItem($NoticeData)->getByUserCurrentDate()) > 0) {
|
||||
return;
|
||||
@@ -122,12 +120,23 @@ class LoginController
|
||||
$expireTime = $data[$userId]->getDate() + ($data[$userId]->getExpireDays() * 86400);
|
||||
$timeRemaining = $expireTime - time();
|
||||
|
||||
$NoticeData = new NoticeData();
|
||||
$NoticeData->setNoticeComponent($this->Plugin->getName());
|
||||
$NoticeData->setNoticeUserId($userId);
|
||||
$NoticeData->setNoticeType(_t('authenticator', 'Aviso Caducidad'));
|
||||
|
||||
$Message = new NoticeMessage();
|
||||
|
||||
if ($timeRemaining <= self::WARNING_TIME) {
|
||||
$NoticeData->setNoticeDescription(sprintf(_t('authenticator', 'El código 2FA se ha de restablecer en %d días'), $timeRemaining / 86400));
|
||||
$Message->addDescription(sprintf(_t('authenticator', 'El código 2FA se ha de restablecer en %d días'), $timeRemaining / 86400));
|
||||
|
||||
$NoticeData->setNoticeDescription($Message);
|
||||
|
||||
Notice::getItem($NoticeData)->add();
|
||||
} elseif (time() > $expireTime) {
|
||||
$NoticeData->setNoticeDescription(_t('authenticator', 'El código 2FA ha caducado. Es necesario restablecerlo desde las preferencias'));
|
||||
$Message->addDescription(_t('authenticator', 'El código 2FA ha caducado. Es necesario restablecerlo desde las preferencias'));
|
||||
|
||||
$NoticeData->setNoticeDescription($Message);
|
||||
|
||||
Notice::getItem($NoticeData)->add();
|
||||
}
|
||||
|
||||
@@ -473,6 +473,7 @@ class AccountController extends ControllerBase implements ActionsInterface
|
||||
*
|
||||
* @param PublicLinkData $PublicLinkData
|
||||
* @return bool
|
||||
*
|
||||
*/
|
||||
public function getAccountFromLink(PublicLinkData $PublicLinkData)
|
||||
{
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
/**
|
||||
* sysPass
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link http://syspass.org
|
||||
* @author nuxsmin
|
||||
* @link http://syspass.org
|
||||
* @copyright 2012-2017, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
@@ -33,10 +33,12 @@ use SP\Core\DiFactory;
|
||||
use SP\Core\Exceptions\SPException;
|
||||
use SP\Core\Init;
|
||||
use SP\Core\Language;
|
||||
use SP\Core\Messages\NoticeMessage;
|
||||
use SP\Core\Plugin\PluginUtil;
|
||||
use SP\Core\Session;
|
||||
use SP\Core\SessionUtil;
|
||||
use SP\Core\Template;
|
||||
use SP\DataModel\NoticeData;
|
||||
use SP\Html\DataGrid\DataGridAction;
|
||||
use SP\Html\Html;
|
||||
use SP\Http\Request;
|
||||
@@ -72,6 +74,16 @@ class MainController extends ControllerBase implements ActionsInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Establecer la variable de página de la vista
|
||||
*
|
||||
* @param $page
|
||||
*/
|
||||
protected function setPage($page)
|
||||
{
|
||||
$this->view->assign('page', $page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inicializar las variables para la vista principal de la aplicación
|
||||
*
|
||||
@@ -478,6 +490,8 @@ class MainController extends ControllerBase implements ActionsInterface
|
||||
* Obtener la vista para mostrar un enlace publicado
|
||||
*
|
||||
* @return bool
|
||||
* @throws \SP\Core\Exceptions\FileNotFoundException
|
||||
* @throws \SP\Core\Exceptions\InvalidClassException
|
||||
* @throws \SP\Core\Exceptions\SPException
|
||||
*/
|
||||
public function getPublicLink()
|
||||
@@ -499,6 +513,24 @@ class MainController extends ControllerBase implements ActionsInterface
|
||||
} else {
|
||||
PublicLink::getItem($PublicLink)->addLinkView();
|
||||
|
||||
if ($PublicLink->isNotify()) {
|
||||
$Message = new NoticeMessage();
|
||||
$Message->setTitle(_('Enlace visualizado'));
|
||||
$Message->addDescription(sprintf('%s : %s', _('Cuenta'), $PublicLink->getItemId()));
|
||||
$Message->addDescription(sprintf('%s : %s', _('Origen'), $_SERVER['REMOTE_ADDR']));
|
||||
$Message->addDescription(sprintf('%s : %s', _('Agente'), $_SERVER['HTTP_USER_AGENT']));
|
||||
$Message->addDescription(sprintf('HTTPS : %s', $_SERVER['HTTPS'] ? 'ON' : 'OFF'));
|
||||
|
||||
|
||||
$NoticeData = new NoticeData();
|
||||
$NoticeData->setNoticeComponent(_('Cuentas'));
|
||||
$NoticeData->setNoticeDescription($Message);
|
||||
$NoticeData->setNoticeType(_('Información'));
|
||||
$NoticeData->setNoticeUserId($PublicLink->getUserId());
|
||||
|
||||
Notice::getItem($NoticeData)->add();
|
||||
}
|
||||
|
||||
$controller = new AccountController($this->view, $PublicLink->getItemId());
|
||||
$controller->getAccountFromLink($PublicLink);
|
||||
}
|
||||
@@ -514,14 +546,4 @@ class MainController extends ControllerBase implements ActionsInterface
|
||||
$this->view();
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Establecer la variable de página de la vista
|
||||
*
|
||||
* @param $page
|
||||
*/
|
||||
protected function setPage($page)
|
||||
{
|
||||
$this->view->assign('page', $page);
|
||||
}
|
||||
}
|
||||
102
inc/SP/Core/Messages/MessageBase.class.php
Normal file
102
inc/SP/Core/Messages/MessageBase.class.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/**
|
||||
* sysPass
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link http://syspass.org
|
||||
* @copyright 2012-2017, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
* sysPass is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* sysPass is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace SP\Core\Messages;
|
||||
|
||||
/**
|
||||
* Class MessageBase
|
||||
*
|
||||
* @package SP\Core\Messages
|
||||
*/
|
||||
abstract class MessageBase implements MessageInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $footer;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $description = [];
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $description
|
||||
*/
|
||||
public function setDescription(array $description)
|
||||
{
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description
|
||||
*/
|
||||
public function addDescription($description)
|
||||
{
|
||||
$this->description[] = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFooter()
|
||||
{
|
||||
return $this->footer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $footer
|
||||
*/
|
||||
public function setFooter($footer)
|
||||
{
|
||||
$this->footer = $footer;
|
||||
}
|
||||
}
|
||||
47
inc/SP/Core/Messages/MessageInterface.class.php
Normal file
47
inc/SP/Core/Messages/MessageInterface.class.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* sysPass
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link http://syspass.org
|
||||
* @copyright 2012-2017, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
* sysPass is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* sysPass is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace SP\Core\Messages;
|
||||
|
||||
/**
|
||||
* Interface MessageInterface
|
||||
*
|
||||
* @package SP\Core\Messages
|
||||
*/
|
||||
interface MessageInterface
|
||||
{
|
||||
/**
|
||||
* Componer un mensaje en formato texto
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function composeText();
|
||||
|
||||
/**
|
||||
* Componer un mensaje en formato HTML
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function composeHtml();
|
||||
}
|
||||
63
inc/SP/Core/Messages/NoticeMessage.class.php
Normal file
63
inc/SP/Core/Messages/NoticeMessage.class.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* sysPass
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link http://syspass.org
|
||||
* @copyright 2012-2017, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
* sysPass is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* sysPass is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace SP\Core\Messages;
|
||||
|
||||
/**
|
||||
* Class NoticeMessage
|
||||
*
|
||||
* @package SP\Core\Messages
|
||||
*/
|
||||
class NoticeMessage extends MessageBase
|
||||
{
|
||||
/**
|
||||
* Componer un mensaje en formato HTML
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function composeHtml()
|
||||
{
|
||||
$message[] = '<div class="notice-message">';
|
||||
$message[] = '<h1>' . $this->title . '</h1>';
|
||||
$message[] = '<p>' . implode('<br>', $this->description) . '</p>';
|
||||
$message[] = '<footer>' . $this->footer . '</footer>';
|
||||
$message[] = '</div>';
|
||||
|
||||
return implode($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Componer un mensaje en formato texto
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function composeText()
|
||||
{
|
||||
$message[] = $this->title;
|
||||
$message[] = implode(PHP_EOL, $this->description);
|
||||
$message[] = $this->footer;
|
||||
|
||||
return implode(PHP_EOL, $message);
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,8 @@
|
||||
|
||||
namespace SP\DataModel;
|
||||
|
||||
use SP\Core\Messages\MessageInterface;
|
||||
|
||||
/**
|
||||
* Class NoticeData
|
||||
*
|
||||
@@ -125,11 +127,11 @@ class NoticeData
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $notice_description
|
||||
* @param MessageInterface $message
|
||||
*/
|
||||
public function setNoticeDescription($notice_description)
|
||||
public function setNoticeDescription(MessageInterface $message)
|
||||
{
|
||||
$this->notice_description = $notice_description;
|
||||
$this->notice_description = $message->composeText();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -151,7 +151,7 @@ class PublicLinkData extends PublicLinkBaseData
|
||||
*/
|
||||
public function isNotify()
|
||||
{
|
||||
return $this->notify;
|
||||
return (bool)$this->notify;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -364,7 +364,7 @@ class Util
|
||||
*/
|
||||
public static function getVersion($retBuild = false)
|
||||
{
|
||||
$build = '17011203';
|
||||
$build = '17011204';
|
||||
$version = [2, 0, 0];
|
||||
|
||||
if ($retBuild) {
|
||||
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user