Esempio n. 1
0
 /**
  * Establecer variables comunes del formulario para todos los interfaces
  */
 private function setCommonData()
 {
     if ($this->isGotData()) {
         //            $this->view->assign('accountParentId', $this->getAccount()->getAccountParentId());
         $this->view->assign('accountIsHistory', $this->getAccount()->getAccountIsHistory());
         $this->view->assign('accountOtherUsers', $this->getAccount()->getAccountUsersId());
         $this->view->assign('accountOtherUsersName', UserAccounts::getUsersNameForAccount($this->getId()));
         $this->view->assign('accountOtherGroups', $this->getAccount()->getAccountUserGroupsId());
         $this->view->assign('accountOtherGroupsName', \SP\Groups::getGroupsNameForAccount($this->getId()));
         $this->view->assign('changesHash', $this->getAccount()->calcChangesHash());
         $this->view->assign('chkUserEdit', $this->view->accountData->account_otherUserEdit ? 'checked' : '');
         $this->view->assign('chkGroupEdit', $this->view->accountData->account_otherGroupEdit ? 'checked' : '');
         $this->view->assign('historyData', \SP\AccountHistory::getAccountList($this->getAccount()->getAccountParentId()));
         $this->view->assign('isModified', $this->view->accountData->account_dateEdit && $this->view->accountData->account_dateEdit != '0000-00-00 00:00:00');
         $this->view->assign('maxFileSize', round(\SP\Config::getValue('files_allowed_size') / 1024, 1));
         $this->view->assign('filesAllowedExts', \SP\Config::getValue('files_allowed_exts'));
         $this->view->assign('filesDelete', $this->_action == Acl::ACTION_ACC_EDIT ? 1 : 0);
     }
     $this->view->assign('accountParentId', Session::getLastAcountId());
     $this->view->assign('categories', \SP\DB::getValuesForSelect('categories', 'category_id', 'category_name'));
     $this->view->assign('customers', \SP\DB::getValuesForSelect('customers', 'customer_id', 'customer_name'));
     $this->view->assign('otherUsers', \SP\DB::getValuesForSelect('usrData', 'user_id', 'user_name'));
     $this->view->assign('otherGroups', \SP\DB::getValuesForSelect('usrGroups', 'usergroup_id', 'usergroup_name'));
     $this->getCustomFieldsForItem();
 }
Esempio n. 2
0
 * @link      http://syspass.org
 * @copyright 2012-2015 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/>.
 *
 */
use SP\Request;
define('APP_ROOT', '..');
require APP_ROOT . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'Base.php';
require APP_ROOT . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'strings.js.php';
Request::checkReferer('GET');
$data = array('lang' => $stringsJsLang, 'app_root' => SP\Init::$WEBURI, 'pk' => '', 'max_file_size' => \SP\Config::getValue('files_allowed_size'));
try {
    $CryptPKI = new SP\CryptPKI();
    $data['pk'] = SP\Session::getPublicKey() ? SP\Session::getPublicKey() : $CryptPKI->getPublicKey();
} catch (Exception $e) {
}
SP\Response::printJSON($data, 0);
Esempio n. 3
0
 /**
  * Obtener la pestaña de Correo
  * @return bool
  */
 public function getMailTab()
 {
     $this->setAction(self::ACTION_CFG_MAIL);
     if (!$this->checkAccess(self::ACTION_CFG_GENERAL)) {
         return;
     }
     $this->view->addTemplate('mail');
     $this->view->assign('chkMail', \SP\Config::getValue('mail_enabled') ? 'checked="checked"' : '');
     $this->view->assign('chkMailRequests', \SP\Config::getValue('mail_requestsenabled') ? 'checked="checked"' : '');
     $this->view->assign('chkMailAuth', \SP\Config::getValue('mail_authenabled') ? 'checked="checked"' : '');
     $this->view->assign('mailServer', \SP\Config::getValue('mail_server', 'localhost'));
     $this->view->assign('mailPort', \SP\Config::getValue('mail_port', 25));
     $this->view->assign('mailUser', \SP\Config::getValue('mail_user'));
     $this->view->assign('mailPass', \SP\Config::getValue('mail_pass'));
     $this->view->assign('currentMailSecurity', \SP\Config::getValue('mail_security'));
     $this->view->assign('mailFrom', \SP\Config::getValue('mail_from'));
     $this->view->assign('mailSecurity', array('SSL', 'TLS'));
     $this->view->assign('actionId', $this->getAction(), 'mail');
     $this->view->append('tabs', array('title' => _('Correo')));
     $this->view->assign('tabIndex', $this->getTabIndex(), 'mail');
 }
Esempio n. 4
0
 /**
  * Obtener el timeout de sesión desde la configuración.
  *
  * @return int con el tiempo en segundos
  */
 private static function getSessionLifeTime()
 {
     if (is_null(Session::getSessionTimeout())) {
         Session::setSessionTimeout(Config::getValue('session_timeout', 60 * 5));
     }
     return Session::getSessionTimeout();
 }
Esempio n. 5
0
 /**
  * Obtener la pestaña de preferencias
  */
 public function getPreferencesTab()
 {
     $this->setAction(self::ACTION_USR_PREFERENCES_GENERAL);
     $this->view->addTemplate('preferences');
     $this->view->assign('userId', $this->_userId);
     $this->view->assign('langsAvailable', Language::getAvailableLanguages());
     $this->view->assign('currentLang', $this->_userPrefs->getLang());
     $this->view->assign('themesAvailable', Themes::getThemesAvailable());
     $this->view->assign('currentTheme', $this->_userPrefs->getTheme() ? $this->_userPrefs->getTheme() : \SP\Config::getValue('sitetheme'));
     $this->view->assign('chkAccountLink', $this->_userPrefs->isAccountLink() ? 'checked="checked"' : '');
     $this->view->assign('resultsPerPage', $this->_userPrefs->getResultsPerPage() ? $this->_userPrefs->getResultsPerPage() : \SP\Config::getValue('account_count'));
     $this->view->assign('chkSortViews', $this->_userPrefs->isSortViews() ? 'checked="checked"' : '');
     $this->view->assign('chkTopNavbar', $this->_userPrefs->isTopNavbar() ? 'checked="checked"' : '');
     $this->view->assign('chkOptionalActions', $this->_userPrefs->isOptionalActions() ? 'checked="checked"' : '');
     $this->view->append('tabs', array('title' => _('Preferencias')));
     $this->view->assign('tabIndex', $this->getTabIndex(), 'preferences');
     $this->view->assign('actionId', $this->getAction(), 'preferences');
 }
 /**
  * Realizar la conexión con la BBDD.
  * Esta función utiliza PDO para conectar con la base de datos.
  *
  * @throws SPException
  * @return \PDO
  */
 public function getConnection()
 {
     if (!$this->_db) {
         $isInstalled = Config::getValue('installed');
         $dbhost = Config::getValue('dbhost');
         $dbuser = Config::getValue('dbuser');
         $dbpass = Config::getValue('dbpass');
         $dbname = Config::getValue('dbname');
         $dbport = Config::getValue('dbport', 3306);
         if (empty($dbhost) || empty($dbuser) || empty($dbpass) || empty($dbname)) {
             if ($isInstalled) {
                 Init::initError(_('No es posible conectar con la BD'), _('Compruebe los datos de conexión'));
             } else {
                 throw new SPException(SPException::SP_CRITICAL, _('No es posible conectar con la BD'), _('Compruebe los datos de conexión'));
             }
         }
         try {
             $dsn = 'mysql:host=' . $dbhost . ';port=' . $dbport . ';dbname=' . $dbname . ';charset=utf8';
             //                $this->db = new PDO($dsn, $dbuser, $dbpass, array(PDO::ATTR_PERSISTENT => true));
             $this->_db = new PDO($dsn, $dbuser, $dbpass);
         } catch (\Exception $e) {
             if ($isInstalled) {
                 if ($e->getCode() === 1049) {
                     Config::setValue('installed', '0');
                 }
                 Init::initError(_('No es posible conectar con la BD'), 'Error ' . $e->getCode() . ': ' . $e->getMessage());
             } else {
                 throw new SPException(SPException::SP_CRITICAL, $e->getMessage(), $e->getCode());
             }
         }
     }
     $this->_db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
     $this->_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     return $this->_db;
 }
Esempio n. 7
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));
     }
 }