예제 #1
0
    // Cargar las variables de sesión del usuario
    SessionUtil::loadUserSession($User);
    $Log->addDescription(sprintf('%s: %s', _('Usuario'), $userLogin));
    $Log->addDescription(sprintf('%s: %s', _('Perfil'), SP\Profile::getProfileNameById($User->getUserProfileId())));
    $Log->addDescription(sprintf('%s: %s', _('Grupo'), SP\Groups::getGroupNameById($User->getUserGroupId())));
    $Log->writeLog();
} else {
    SP\Response::printJSON(_('Error interno'));
}
$UserPrefs = \SP\UserPreferences::getPreferences($User->getUserId());
if ($UserPrefs->isUse2Fa()) {
    SP\Session::set2FApassed(false);
    $url = SP\Init::$WEBURI . '/index.php?a=2fa&i=' . $User->getUserId() . '&t=' . time() . '&f=1';
    SP\Response::printJSON($url, 0);
} else {
    SP\Session::set2FApassed(true);
}
SP\Language::setLanguage(true);
SP\Themes::setTheme(true);
SP\Session::setUserPreferences($UserPrefs);
$params = array();
// Comprobar si existen parámetros adicionales en URL via POST para pasarlos por GET
foreach ($_POST as $param => $value) {
    \SP\Html::sanitize($param);
    \SP\Html::sanitize($value);
    if (!strncmp($param, 'g_', 2)) {
        $params[] = substr($param, 2) . '=' . $value;
    }
}
$urlParams = count($params) > 0 ? '?' . implode('&', $params) : '';
SP\Response::printJSON('index.php' . $urlParams, 0);
예제 #2
0
 /**
  * Obtener los datos para el interface de login
  */
 public function getLogin()
 {
     $this->view->addTemplate('login');
     $this->view->addTemplate('footer');
     $this->view->addTemplate('body-end');
     $this->view->assign('demoEnabled', Util::demoIsEnabled());
     $this->view->assign('mailEnabled', Util::mailIsEnabled());
     $this->view->assign('isLogout', Request::analyze('logout', false, true));
     $this->view->assign('updated', Init::$UPDATED === true);
     $this->view->assign('newFeatures', array(_('Nuevo estilo visual basado en Material Design Lite by Google'), _('Usuarios en múltiples grupos'), _('Previsualización de imágenes'), _('Mostrar claves como imágenes'), _('Campos personalizados'), _('API de consultas'), _('Autentificación en 2 pasos'), _('Complejidad de generador de claves'), _('Consultas especiales'), _('Exportación a XML'), _('Clave maestra temporal'), _('Importación de cuentas desde sysPass, KeePass, KeePassX y CSV'), _('Optimización del código y mayor rapidez de carga'), _('Mejoras de seguridad en XSS e inyección SQL')));
     // Comprobar y parsear los parámetros GET para pasarlos como POST en los inputs
     $this->view->assign('getParams');
     if (count($_GET) > 0) {
         foreach ($_GET as $param => $value) {
             $getParams['g_' . \SP\Html::sanitize($param)] = \SP\Html::sanitize($value);
         }
         $this->view->assign('getParams', $getParams);
     }
 }
예제 #3
0
 /**
  * Procesar los resultados de la búsqueda y crear la variable que contiene los datos de cada cuenta
  * a mostrar.
  *
  * @param &$results array Con los resultados de la búsqueda
  */
 private function processSearchResults(&$results)
 {
     // Variables para la barra de navegación
     $this->view->assign('firstPage', ceil(($this->view->limitStart + 1) / $this->view->limitCount));
     $this->view->assign('lastPage', ceil(\SP\AccountSearch::$queryNumRows / $this->view->limitCount));
     $this->view->assign('totalRows', \SP\AccountSearch::$queryNumRows);
     $this->view->assign('filterOn', $this->_filterOn);
     $limitLast = \SP\AccountSearch::$queryNumRows % $this->view->limitCount == 0 ? \SP\AccountSearch::$queryNumRows - $this->view->limitCount : floor(\SP\AccountSearch::$queryNumRows / $this->view->limitCount) * $this->view->limitCount;
     $this->view->assign('pagerOnnClick', array('first' => 'sysPassUtil.Common.searchSort(' . $this->view->searchKey . ', 0,1)', 'last' => 'sysPassUtil.Common.searchSort(' . $this->view->searchKey . ',' . $limitLast . ',1)', 'prev' => 'sysPassUtil.Common.searchSort(' . $this->view->searchKey . ',' . ($this->view->limitStart - $this->view->limitCount) . ',1)', 'next' => 'sysPassUtil.Common.searchSort(' . $this->view->searchKey . ',' . ($this->view->limitStart + $this->view->limitCount) . ',1)'));
     $accountLink = Session::getUserPreferences()->isAccountLink();
     $topNavbar = Session::getUserPreferences()->isTopNavbar();
     $optionalActions = Session::getUserPreferences()->isOptionalActions();
     // Variables de configuración
     $this->view->assign('accountLink', is_null($accountLink) ? \SP\Config::getValue('account_link', 0) : $accountLink);
     $this->view->assign('topNavbar', $topNavbar);
     $this->view->assign('optionalActions', $optionalActions);
     $this->view->assign('requestEnabled', \SP\Util::mailrequestIsEnabled());
     $this->view->assign('isDemoMode', \SP\Util::demoIsEnabled());
     $maxTextLength = \SP\Util::resultsCardsIsEnabled() ? 40 : 60;
     $wikiEnabled = \SP\Util::wikiIsEnabled();
     if ($wikiEnabled) {
         $wikiSearchUrl = \SP\Config::getValue('wiki_searchurl', false);
         $this->view->assign('wikiFilter', explode(',', \SP\Config::getValue('wiki_filter')));
         $this->view->assign('wikiPageUrl', \SP\Config::getValue('wiki_pageurl'));
     }
     $this->setSortFields();
     $objAccount = new \SP\Account();
     foreach ($results as $account) {
         $objAccount->setAccountId($account->account_id);
         $objAccount->setAccountUserId($account->account_userId);
         $objAccount->setAccountUserGroupId($account->account_userGroupId);
         $objAccount->setAccountOtherUserEdit($account->account_otherUserEdit);
         $objAccount->setAccountOtherGroupEdit($account->account_otherGroupEdit);
         // Obtener los datos de la cuenta para aplicar las ACL
         $accountAclData = $objAccount->getAccountDataForACL();
         // Establecer los permisos de acceso
         $accView = \SP\Acl::checkAccountAccess(self::ACTION_ACC_VIEW, $accountAclData) && \SP\Acl::checkUserAccess(self::ACTION_ACC_VIEW);
         $accViewPass = \SP\Acl::checkAccountAccess(self::ACTION_ACC_VIEW_PASS, $accountAclData) && \SP\Acl::checkUserAccess(self::ACTION_ACC_VIEW_PASS);
         $accEdit = \SP\Acl::checkAccountAccess(self::ACTION_ACC_EDIT, $accountAclData) && \SP\Acl::checkUserAccess(self::ACTION_ACC_EDIT);
         $accCopy = \SP\Acl::checkAccountAccess(self::ACTION_ACC_COPY, $accountAclData) && \SP\Acl::checkUserAccess(self::ACTION_ACC_COPY);
         $accDel = \SP\Acl::checkAccountAccess(self::ACTION_ACC_DELETE, $accountAclData) && \SP\Acl::checkUserAccess(self::ACTION_ACC_DELETE);
         $show = $accView || $accViewPass || $accEdit || $accCopy || $accDel;
         // Obtenemos datos si el usuario tiene acceso a los datos de la cuenta
         if ($show) {
             $secondaryGroups = \SP\Groups::getGroupsNameForAccount($account->account_id);
             $secondaryUsers = UserAccounts::getUsersNameForAccount($account->account_id);
             $secondaryAccesses = '<em>(G) ' . $account->usergroup_name . '*</em><br>';
             if ($secondaryGroups) {
                 foreach ($secondaryGroups as $group) {
                     $secondaryAccesses .= '<em>(G) ' . $group . '</em><br>';
                 }
             }
             if ($secondaryUsers) {
                 foreach ($secondaryUsers as $user) {
                     $secondaryAccesses .= '<em>(U) ' . $user . '</em><br>';
                 }
             }
             $accountNotes = '';
             if ($account->account_notes) {
                 $accountNotes = strlen($account->account_notes) > 300 ? substr($account->account_notes, 0, 300) . "..." : $account->account_notes;
                 $accountNotes = nl2br(wordwrap(htmlspecialchars($accountNotes), 50, '<br>', true));
             }
         }
         // Variable $accounts de la plantilla utilizada para obtener los datos de las cuentas
         $this->view->append('accounts', array('id' => $account->account_id, 'name' => $account->account_name, 'login' => \SP\Html::truncate($account->account_login, $maxTextLength), 'category_name' => $account->category_name, 'customer_name' => \SP\Html::truncate($account->customer_name, $maxTextLength), 'customer_link' => $wikiEnabled ? $wikiSearchUrl . $account->customer_name : '', 'color' => $this->pickAccountColor($account->account_customerId), 'url' => $account->account_url, 'url_short' => \SP\Html::truncate($account->account_url, $maxTextLength), 'url_islink' => preg_match("#^https?://.*#i", $account->account_url) ? true : false, 'notes' => $accountNotes, 'accesses' => isset($secondaryAccesses) ? $secondaryAccesses : '', 'numFiles' => \SP\Util::fileIsEnabled() ? $account->num_files : 0, 'show' => $show, 'showView' => $accView, 'showViewPass' => $accViewPass, 'showEdit' => $accEdit, 'showCopy' => $accCopy, 'showDel' => $accDel));
     }
 }
예제 #4
0
 /**
  * Actualizar un token
  *
  * @throws SPException
  */
 public function updateToken()
 {
     $this->checkTokenExist();
     if ($this->_refreshToken) {
         $this->refreshToken();
     }
     $query = 'UPDATE authTokens ' . 'SET authtoken_userId = :userid,' . 'authtoken_actionId = :actionid,' . 'authtoken_createdBy = :createdby,' . 'authtoken_token = :token,' . 'authtoken_startDate = UNIX_TIMESTAMP() ' . 'WHERE authtoken_id = :id LIMIT 1';
     $data['id'] = $this->_tokenId;
     $data['userid'] = $this->_userId;
     $data['actionid'] = $this->_actionId;
     $data['createdby'] = Session::getUserId();
     $data['token'] = $this->getUserToken() ? $this->_token : sha1(uniqid() . time());
     try {
         DB::getQuery($query, __FUNCTION__, $data);
     } catch (SPException $e) {
         throw new SPException(SPException::SP_CRITICAL, _('Error interno'));
     }
     $Log = new Log(_('Actualizar Autorización'));
     $Log->addDescription(sprintf('%s : %s', Html::strongText(_('Usuario')), UserUtil::getUserLoginById($this->_userId)));
     $Log->writeLog();
     Email::sendEmail($Log);
 }