Browse Source

updated session_limite

Bachir Soussi Chiadmi 5 years ago
parent
commit
954fc9ead1

+ 1 - 1
sites/all/modules/contrib/users/session_limit/README.txt

@@ -10,7 +10,7 @@ then enabling the module.
 
 The default max sessions is 1. Change default max sessions can be changed in
 'Configuration >> People >> Session Limit'
-The path for this is /admin/config/people/session_limit
+The path for this is /admin/config/people/session-limit
 
 Triggers are available to assign any of the three system actions to either the
 collision or disconnect events. That includes displaying a message to the user,

+ 4 - 5
sites/all/modules/contrib/users/session_limit/session_limit.info

@@ -1,16 +1,15 @@
 name = Session Limit
 description = "Limit simultaneous user sessions."
 core = 7.x
-configure = admin/config/people/session_limit
+configure = admin/config/people/session-limit
 
 files[] = session_limit.install
 files[] = session_limit.module
 files[] = session_limit.tokens.inc
 files[] = tests/session_limit.test
 
-; Information added by Drupal.org packaging script on 2016-02-24
-version = "7.x-2.2"
+; Information added by Drupal.org packaging script on 2018-10-31
+version = "7.x-2.3"
 core = "7.x"
 project = "session_limit"
-datestamp = "1456312454"
-
+datestamp = "1540976892"

+ 1 - 0
sites/all/modules/contrib/users/session_limit/session_limit.install

@@ -14,5 +14,6 @@ function session_limit_uninstall() {
   variable_del('session_limit_masquerade_ignore');
   variable_del('session_limit_logged_out_message_severity');
   variable_del('session_limit_logged_out_message');
+  variable_del('session_limit_include_root_user');
   db_query("DELETE FROM {variable} WHERE name LIKE 'session_limit_rid_%'");
 }

+ 67 - 10
sites/all/modules/contrib/users/session_limit/session_limit.module

@@ -30,6 +30,11 @@ define('SESSION_LIMIT_LOGGED_OUT_MESSAGE_SEVERITY', 'error');
  */
 define('SESSION_LIMIT_LOGGED_OUT_MESSAGE', 'You have been automatically logged out. Someone else has logged in with your username and password and the maximum number of @number simultaneous sessions was exceeded. This may indicate that your account has been compromised or that account sharing is not allowed on this site. Please contact the site administrator if you suspect your account has been compromised.');
 
+/**
+ * Default message displayed for a user on a new machine when sesison limit has been reached.
+ */
+define('SESSION_LIMIT_HIT_MESSAGE', 'The maximum number of simultaneous sessions (@number) for your account has been reached. You did not log off from a previous session or someone else is logged on to your account. This may indicate that your account has been compromised or that account sharing is limited on this site. Please contact the site administrator if you suspect your account has been compromised.');
+
 /**
  * Implements hook_help().
  */
@@ -39,13 +44,13 @@ function session_limit_help($path, $args) {
       $output = '<p>' . t("The two major notice messages to users are passed through Drupal's t() function. This maintains locale support, allowing you to override strings in any language, but such text is also available to be changed through other modules like !stringoverridesurl.", array('!stringoverridesurl' => l('String Overrides', 'http://drupal.org/project/stringoverrides'))) . '</p>';
       $output .= '<p>' . t("The two major strings are as follows:") . '</p>';
       $output .= '<p><blockquote>';
-      $output .=  'The maximum number of simultaneous sessions (@number) for your account has been reached. You did not log off from a previous session or someone else is logged on to your account. This may indicate that your account has been compromised or that account sharing is limited on this site. Please contact the site administrator if you suspect your account has been compromised.';
+      $output .= variable_get('session_limit_limit_hit_message', SESSION_LIMIT_HIT_MESSAGE);
       $output .= '</blockquote></p><p><blockquote>';
       $output .= 'You have been automatically logged out. Someone else has logged in with your username and password and the maximum number of @number simultaneous sessions was exceeded. This may indicate that your account has been compromised or that account sharing is not allowed on this site. Please contact the site administrator if you suspect your account has been compromised.';
       $output .= '</blockquote></p>';
       return $output;
     case 'session/limit':
-      return t('The maximum number of simultaneous sessions (@number) for your account has been reached. You did not log off from a previous session or someone else is logged on to your account. This may indicate that your account has been compromised or that account sharing is limited on this site. Please contact the site administrator if you suspect your account has been compromised.', array('@number' => session_limit_user_max_sessions()));
+      return t(variable_get('session_limit_limit_hit_message', SESSION_LIMIT_HIT_MESSAGE), array('@number' => session_limit_user_max_sessions()));
   }
 }
 
@@ -91,7 +96,7 @@ function session_limit_menu() {
     'access arguments' => array('administer site configuration'),
     'type' => MENU_NORMAL_ITEM,
   );
-  $items['admin/config/people/session_limit/defaults'] = array(
+  $items['admin/config/people/session-limit/defaults'] = array(
     'title' => 'Defaults',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('session_limit_settings'),
@@ -127,6 +132,13 @@ function session_limit_settings() {
     '#description' => t('The maximum number of active sessions a user can have. 0 implies unlimited sessions.'),
   );
 
+  $form['session_limit_include_root_user'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Apply limit to root admin user.'),
+    '#description' => t('By default session limits do not apply to user #1'),
+    '#default_value' => variable_get('session_limit_include_root_user', FALSE),
+  );
+
   $limit_behaviours = array(
     SESSION_LIMIT_DO_NOTHING => t('Do nothing.'),
     SESSION_LIMIT_DROP => t('Automatically drop the oldest sessions without prompting.'),
@@ -148,6 +160,14 @@ function session_limit_settings() {
       '#default_value' => variable_get('session_limit_masquerade_ignore', FALSE),
     );
   }
+  $form['session_limit_limit_hit_message'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Session limit has been hit message'),
+    '#default_value' => variable_get('session_limit_limit_hit_message', SESSION_LIMIT_HIT_MESSAGE),
+    '#description' => t('The message that is displayed to a user on the current workstation if the session limit has been reached.<br />
+      @number is replaced with the maximum number of simultaneous sessions.'),
+  );
+
   $form['session_limit_logged_out_message_severity'] = array(
     '#type' => 'select',
     '#title' => t('Logged out message severity'),
@@ -247,7 +267,8 @@ function session_limit_settings_byrole_submit($form, &$form_state) {
  */
 function session_limit_init() {
   global $user;
-  if ($user->uid > 1 && !isset($_SESSION['session_limit'])) {
+  $user_match = variable_get('session_limit_include_root_user', FALSE) ? 0 : 1;
+  if ($user->uid > $user_match && !isset($_SESSION['session_limit'])) {
 
     if (_session_limit_bypass()) {
       // Bypass the session limitation on this page callback.
@@ -351,6 +372,21 @@ function session_limit_user_settings($form, $form_state, $account) {
     '#default_value' => empty($account->data['session_limit']) ? 0 : $account->data['session_limit'],
     '#options' => _session_limit_user_options(),
   );
+
+  if ($account->uid == 1) {
+    $form['session_limit']['#states'] = array(
+      'enabled' => array(
+        ':input[name="session_limit_include_root_user"]' => array('checked' => TRUE),
+      ),
+    );
+    $form['session_limit_include_root_user'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Apply limit to root admin user.'),
+      '#description' => t('By default session limits do not apply to user #1'),
+      '#default_value' => variable_get('session_limit_include_root_user', FALSE),
+    );
+  }
+
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Save configuration'),
@@ -376,6 +412,9 @@ function session_limit_user_settings_submit($form, &$form_state) {
   if (empty($form_state['values']['session_limit'])) {
     $form_state['values']['session_limit'] = NULL;
   }
+  if ($form_state['values']['account']->uid == 1) {
+    variable_set('session_limit_include_root_user', !empty($form_state['values']['session_limit_include_root_user']));
+  }
   user_save($form_state['values']['account'], array('data' => array('session_limit' => $form_state['values']['session_limit'])));
   drupal_set_message(t('Session limit updated for %user.', array('%user' => $form_state['values']['account']->name)), 'status', TRUE);
 }
@@ -386,6 +425,8 @@ function session_limit_user_settings_submit($form, &$form_state) {
 function session_limit_page() {
   global $user;
 
+  $form = array();
+
   if (variable_get('session_limit_behaviour', SESSION_LIMIT_DO_NOTHING) == SESSION_LIMIT_DISALLOW_NEW) {
     session_destroy();
     $user = drupal_anonymous_user();
@@ -394,10 +435,16 @@ function session_limit_page() {
   }
 
   $result = db_query('SELECT * FROM {sessions} WHERE uid = :uid', array(':uid' => $user->uid));
-  foreach ($result as $obj) {
+
+  $active_sessions = array();
+  $session_references = array();
+
+  foreach ($result as $session_reference => $obj) {
+    $active_sessions[$session_reference] = $obj->sid;
+
     $message = $user->sid == $obj->sid ? t('Your current session.') : '';
 
-    $sids[$obj->sid] = t('<strong>Host:</strong> %host (idle: %time) <b>@message</b>',
+    $session_references[$session_reference] = t('<strong>Host:</strong> %host (idle: %time) <b>@message</b>',
       array(
         '%host' => $obj->hostname,
         '@message' => $message,
@@ -405,10 +452,15 @@ function session_limit_page() {
       );
   }
 
-  $form['sid'] = array(
+  $form['active_sessions'] = array(
+    '#type' => 'value',
+    '#value' => $active_sessions,
+  );
+
+  $form['session_reference'] = array(
     '#type' => 'radios',
     '#title' => t('Select a session to disconnect.'),
-    '#options' => $sids,
+    '#options' => $session_references,
   );
 
   $form['submit'] = array(
@@ -423,11 +475,16 @@ function session_limit_page() {
  * Handler for submissions from session_limit_page().
  */
 function session_limit_page_submit($form, &$form_state) {
-  if ($GLOBALS['user']->sid == $form_state['values']['sid']) {
+  global $user;
+
+  $session_reference = $form_state['values']['session_reference'];
+  $sid = $form['active_sessions']['#value'][$session_reference];
+
+  if ($user->sid == $sid) {
     drupal_goto('user/logout');
   }
   else {
-    session_limit_invoke_session_limit($form_state['values']['sid'], 'disconnect');
+    session_limit_invoke_session_limit($sid, 'disconnect');
     drupal_goto();
   }
 }