All Data Structures Functions Variables Pages
SessionTimeout.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
37  Yii::import('zii.widgets.jui.CJuiWidget');
38 
42  class SessionTimeout extends CJuiWidget
43  {
44  const MAX_SESSION_TIMEOUT_IN_SECONDS = 31536000; // One year
45 
52  public $timeout = 1400;
53 
58  public $countdown;
59 
64  public $title;
65 
71  public $message;
72 
78  public $question;
79 
84  public $keepAliveButtonText;
85 
90  public $signOutButtonText;
91 
97  public $keepAliveUrl;
98 
104  public $logoutUrl;
105 
114  public $logoutRedirectUrl;
115 
121  public $restartOnYes;
122 
127  public $dialogWidth;
128 
129  public $cssFile = null;
130 
131  public $countdownCookieName;
132 
133  public function init()
134  {
135  parent::init();
136  $this->getSessionTimeout();
137  $this->countdown = 60;
138  $this->title = Zurmo::t('Core', 'Your Zurmo session is about to expire?',
140  $this->message = Zurmo::t('Core', 'You will be logged out in {0} seconds.');
141  $this->question = Zurmo::t('Core', 'Do you want to stay signed in?');
142  $this->keepAliveButtonText = Zurmo::t('Core', 'Yes, Keep me signed in');
143  $this->signOutButtonText = Zurmo::t('Core', 'No, Sign me out');
144  $this->keepAliveUrl = Yii::app()->request->url;
145  $this->logoutUrl = Yii::app()->baseUrl . '/index.php/zurmo/default/logout';
146  $this->logoutRedirectUrl = Yii::app()->baseUrl . '/index.php/zurmo/default/logout';
147  $this->countdownCookieName = 'Countdown_' . Yii::app()->request->getHostInfo() . Yii::app()->baseUrl;
148  $cs = Yii::app()->getClientScript();
149  $baseScriptUrl = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('application.core.widgets.assets'));
150  $cs->registerScriptFile($baseScriptUrl . '/sessionTimeout/timeout-dialog.js', ClientScript::POS_HEAD);
151  }
152 
153  public function run()
154  {
155  $options = array(
156  'timeout' => $this->timeout,
157  'countdown' => $this->countdown,
158  'title' => $this->title,
159  'message' => $this->message,
160  'question' => $this->question,
161  'keep_alive_button_text' => $this->keepAliveButtonText,
162  'sign_out_button_text' => $this->signOutButtonText,
163  'keep_alive_url' => $this->keepAliveUrl,
164  'logout_url' => $this->logoutUrl,
165  'restart_on_yes' => $this->restartOnYes,
166  'logout_redirect_url' => $this->logoutRedirectUrl,
167  'dialog_width' => $this->dialogWidth,
168  'start_countdown_timestamp_cookie_name' => $this->countdownCookieName,
169  );
170  foreach ($options as $key => $value)
171  {
172  if ($value === null)
173  {
174  unset($options[$key]);
175  }
176  }
177  $options = CJSON::encode($options);
178  Yii::app()->getClientScript()->registerScript('TimeoutDialog', "$.timeoutDialog($options);", CClientScript::POS_READY);
179  }
180 
181  protected function getSessionTimeout()
182  {
183  $sessionCookieLifeTime = ini_get('session.cookie_lifetime');
184  $sessionGcMaxLifeTime = ini_get('session.gc_maxlifetime');
185 
186  if (isset($sessionCookieLifeTime) && $sessionCookieLifeTime > 0)
187  {
188  $this->timeout = $sessionCookieLifeTime;
189  }
190  else
191  {
192  $this->timeout = static::MAX_SESSION_TIMEOUT_IN_SECONDS;
193  }
194 
195  if (isset($sessionGcMaxLifeTime) && $sessionGcMaxLifeTime > 0 && $sessionGcMaxLifeTime < $this->timeout)
196  {
197  $this->timeout = $sessionGcMaxLifeTime;
198  }
199  }
200  }
201 ?>
static getTranslationParamsForAllModules()
Definition: LabelUtil.php:75
Generated on Tue Feb 25 2020 07:10:30