FINAL suepr merge step : added all modules to this super repos
This commit is contained in:
339
sites/all/modules/contrib/users/session_limit/LICENSE.txt
Normal file
339
sites/all/modules/contrib/users/session_limit/LICENSE.txt
Normal file
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
47
sites/all/modules/contrib/users/session_limit/README.txt
Normal file
47
sites/all/modules/contrib/users/session_limit/README.txt
Normal file
@@ -0,0 +1,47 @@
|
||||
Overview:
|
||||
---------
|
||||
The session-limit module is designed to allow an administrator to limit
|
||||
the number of simultaneous sessions a user may have.
|
||||
|
||||
Installation and configuration:
|
||||
-------------------------------
|
||||
Installation is as simple as copying the module into your 'modules' directory,
|
||||
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
|
||||
|
||||
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,
|
||||
sending an email, or redirecting to a different URL.
|
||||
|
||||
Rules events are available for collision or disconnect events.
|
||||
|
||||
The precedence of defined session limits are:
|
||||
|
||||
1. The user's session limit if set, otherwise,
|
||||
2. The highest session limit for a user as set on their roles, if all are set to default then
|
||||
3. The system default session_limit
|
||||
|
||||
Optional:
|
||||
---------
|
||||
This module is able to use the token module for generating tokenized emails
|
||||
or showing tokenized messages on the collision and disconnect events.
|
||||
|
||||
http://drupal.org/project/token
|
||||
|
||||
If you want to customize the notices that users see, try the String Overrides
|
||||
module. Both the message for prompting to disconnect a user and the message
|
||||
that the disconnected user sees are passed through Drupal's localize t()
|
||||
function.
|
||||
|
||||
http://drupal.org/project/stringoverrides
|
||||
|
||||
Requires:
|
||||
---------
|
||||
- Drupal 7.x
|
||||
|
||||
Issue queue:
|
||||
------------
|
||||
http://drupal.org/project/issues/session_limit
|
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file contains no working PHP code; it exists to provide additional
|
||||
* documentation for doxygen as well as to document hooks in the standard
|
||||
* Drupal manner.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Prevent session limitation checks at page load.
|
||||
*
|
||||
* Session limit module checks for active sessions during hook_init. If
|
||||
* a particular path or page load or context may mean that session
|
||||
* checks should not occur.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the current page request should bypass session limitation
|
||||
* restrictions.
|
||||
*/
|
||||
function hook_session_limit_bypass() {
|
||||
if ((arg(0) == 'session' && arg(1) == 'limit') || arg(0) == 'logout') {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify other modules that a session imitation event has occured.
|
||||
*
|
||||
* When a session limit is reached, this hook is invoked. There are
|
||||
* two types of event. Collision events happen when a new session
|
||||
* causes an old session to close. Disconnect events happen when
|
||||
* a new session is prevented by an existing session.
|
||||
*
|
||||
* @param string $sid
|
||||
* The session id of the session which caused the event. In a
|
||||
* collision, this is not the session which was ended.
|
||||
* @param string $op
|
||||
* Either 'disconnect' or 'collision'.
|
||||
*/
|
||||
function hook_session_limit($sid, $op) {
|
||||
global $user;
|
||||
rules_invoke_event('session_limit_' . $op, $user, $sid);
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
name = Session Limit
|
||||
description = "Limit simultaneous user sessions."
|
||||
core = 7.x
|
||||
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 2013-07-06
|
||||
version = "7.x-2.0-rc2"
|
||||
core = "7.x"
|
||||
project = "session_limit"
|
||||
datestamp = "1373115956"
|
||||
|
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains install and update functions for Session Limit.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function session_limit_uninstall() {
|
||||
variable_del('session_limit_max');
|
||||
variable_del('session_limit_behaviour');
|
||||
variable_del('session_limit_masquerade_ignore');
|
||||
variable_del('session_limit_logged_out_message_severity');
|
||||
variable_del('session_limit_logged_out_message');
|
||||
db_query("DELETE FROM {variable} WHERE name LIKE 'session_limit_rid_%'");
|
||||
}
|
@@ -0,0 +1,667 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Limits multiple sessions per user.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Do nothing if the session limit is exceeded.
|
||||
*/
|
||||
define('SESSION_LIMIT_DO_NOTHING', 0);
|
||||
|
||||
/**
|
||||
* Automatically drop sessions that would exceed the limit.
|
||||
*/
|
||||
define('SESSION_LIMIT_DROP', 1);
|
||||
|
||||
/**
|
||||
* Disallow sessions that would exceed the limit.
|
||||
*/
|
||||
define('SESSION_LIMIT_DISALLOW_NEW', 2);
|
||||
|
||||
/**
|
||||
* Default drupal_set_message type for logout message.
|
||||
*/
|
||||
define('SESSION_LIMIT_LOGGED_OUT_MESSAGE_SEVERITY', 'error');
|
||||
|
||||
/**
|
||||
* Default message displayed when a user is logged out.
|
||||
*/
|
||||
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.');
|
||||
|
||||
/**
|
||||
* Implements hook_help().
|
||||
*/
|
||||
function session_limit_help($path, $args) {
|
||||
switch ($path) {
|
||||
case 'admin/help#session_limit':
|
||||
$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 .= '</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()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
function session_limit_permission() {
|
||||
return array(
|
||||
'administer session limits by role' => array(
|
||||
'title' => t('Administer session limits by role'),
|
||||
'description' => t(''),
|
||||
),
|
||||
'administer session limits per user' => array(
|
||||
'title' => t('Administer session limits by user'),
|
||||
'description' => t(''),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function session_limit_menu() {
|
||||
$items['session/limit'] = array(
|
||||
'title' => 'Session limit exceeded',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('session_limit_page'),
|
||||
'access callback' => 'user_is_logged_in',
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
$items['mysessions'] = array(
|
||||
'title' => 'My sessions',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('session_limit_page'),
|
||||
'access callback' => 'user_is_logged_in',
|
||||
'type' => MENU_SUGGESTED_ITEM,
|
||||
);
|
||||
$items['admin/config/people/session_limit'] = array(
|
||||
'title' => 'Session limit',
|
||||
'description' => 'Configure session limits.',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('session_limit_settings'),
|
||||
'access arguments' => array('administer site configuration'),
|
||||
'type' => MENU_NORMAL_ITEM,
|
||||
);
|
||||
$items['admin/config/people/session_limit/defaults'] = array(
|
||||
'title' => 'Defaults',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('session_limit_settings'),
|
||||
'access arguments' => array('administer site configuration'),
|
||||
'type' => MENU_DEFAULT_LOCAL_TASK,
|
||||
);
|
||||
$items['admin/config/people/session_limit/roles'] = array(
|
||||
'title' => 'Role limits',
|
||||
'description' => 'Configure session limits by role.',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('session_limit_settings_byrole'),
|
||||
'access arguments' => array('administer session limits by role'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
);
|
||||
$items['user/%user/session_limit'] = array(
|
||||
'title' => 'Session limit',
|
||||
'description' => 'Configure session limit for one user.',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('session_limit_user_settings', 1),
|
||||
'access arguments' => array('administer session limits per user'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
|
||||
function session_limit_settings() {
|
||||
$form['session_limit_max'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Default maximum number of active sessions'),
|
||||
'#default_value' => variable_get('session_limit_max', 1),
|
||||
'#size' => 2,
|
||||
'#maxlength' => 3,
|
||||
'#description' => t('The maximum number of active sessions a user can have. 0 implies unlimited sessions.'),
|
||||
);
|
||||
|
||||
$limit_behaviours = array(
|
||||
SESSION_LIMIT_DO_NOTHING => t('Do nothing.'),
|
||||
SESSION_LIMIT_DROP => t('Automatically drop the oldest sessions without prompting.'),
|
||||
SESSION_LIMIT_DISALLOW_NEW => t('Prevent new session.'),
|
||||
);
|
||||
|
||||
$form['session_limit_behaviour'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('When the session limit is exceeded'),
|
||||
'#default_value' => variable_get('session_limit_behaviour', SESSION_LIMIT_DO_NOTHING),
|
||||
'#options' => $limit_behaviours,
|
||||
);
|
||||
|
||||
if (module_exists('masquerade')) {
|
||||
$form['session_limit_masquerade_ignore'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Ignore masqueraded sessions.'),
|
||||
'#description' => t("When a user administrator uses the masquerade module to impersonate a different user, it won't count against the session limit counter"),
|
||||
'#default_value' => variable_get('session_limit_masquerade_ignore', FALSE),
|
||||
);
|
||||
}
|
||||
$form['session_limit_logged_out_message_severity'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Logged out message severity'),
|
||||
'#default_value' => variable_get('session_limit_logged_out_message_severity', SESSION_LIMIT_LOGGED_OUT_MESSAGE_SEVERITY),
|
||||
'#options' => array(
|
||||
'error' => t('Error'),
|
||||
'warning' => t('Warning'),
|
||||
'status' => t('Status'),
|
||||
'_none' => t('No Message'),
|
||||
),
|
||||
'#description' => t('The Drupal message type. Defaults to Error.'),
|
||||
);
|
||||
|
||||
$form['session_limit_logged_out_message'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('Logged out message'),
|
||||
'#default_value' => variable_get('session_limit_logged_out_message', SESSION_LIMIT_LOGGED_OUT_MESSAGE),
|
||||
'#description' => t('The message that is displayed to a user if the workstation has been logged out.<br />
|
||||
@number is replaced with the maximum number of simultaneous sessions.'),
|
||||
);
|
||||
|
||||
return system_settings_form($form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings validation form.
|
||||
*/
|
||||
function session_limit_settings_validate($form, &$form_state) {
|
||||
$maxsessions = $form_state['values']['session_limit_max'];
|
||||
if (!is_numeric($maxsessions)) {
|
||||
form_set_error('session_limit_max', t('You must enter a number for the maximum number of active sessions'));
|
||||
}
|
||||
elseif ($maxsessions < 0) {
|
||||
form_set_error('session_limit_max', t('Maximum number of active sessions must be positive'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings by role form.
|
||||
*/
|
||||
function session_limit_settings_byrole() {
|
||||
$result = db_select('variable', 'v')
|
||||
->fields('v', array('name', 'value'))
|
||||
->condition('name', 'session_limit_rid_%', 'LIKE')
|
||||
->orderBy('name')
|
||||
->execute();
|
||||
|
||||
foreach ($result as $setting) {
|
||||
$role_limits[$setting->name] = unserialize($setting->value);
|
||||
}
|
||||
|
||||
$roles = user_roles(TRUE);
|
||||
foreach ($roles as $rid => $role) {
|
||||
$form["session_limit_rid_$rid"] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => _session_limit_user_options(),
|
||||
'#title' => check_plain($role),
|
||||
'#default_value' => empty($role_limits["session_limit_rid_$rid"]) ? 0 : $role_limits["session_limit_rid_$rid"],
|
||||
);
|
||||
}
|
||||
|
||||
$form['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save permissions'),
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set session limits by role form submission.
|
||||
*/
|
||||
function session_limit_settings_byrole_submit($form, &$form_state) {
|
||||
db_delete('variable')
|
||||
->condition('name', 'session_limit_rid_%', 'LIKE')
|
||||
->execute();
|
||||
|
||||
foreach ($form_state['values'] as $setting_name => $setting_limit) {
|
||||
variable_set($setting_name, $setting_limit);
|
||||
}
|
||||
|
||||
drupal_set_message(t('Role settings updated.'), 'status');
|
||||
watchdog('session_limit', 'Role limits updated.', array(), WATCHDOG_INFO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_init().
|
||||
*
|
||||
* Determine whether session has been verified. Redirect user if over session
|
||||
* limit. Established Sessions do NOT need to verify every page load. The new
|
||||
* session must deal w/ determining which connection is cut.
|
||||
*
|
||||
* This intentionally doesn't use hook_user()'s login feature because that's
|
||||
* only really useful if the login event always boots off at least one other
|
||||
* active session. Doing it this way makes sure that the newest session can't
|
||||
* browse to a different page after their login has validated.
|
||||
*/
|
||||
function session_limit_init() {
|
||||
global $user;
|
||||
if ($user->uid > 1 && !isset($_SESSION['session_limit'])) {
|
||||
|
||||
if (_session_limit_bypass()) {
|
||||
// Bypass the session limitation on this page callback.
|
||||
return;
|
||||
}
|
||||
|
||||
$query = db_select('sessions', 's')
|
||||
// Use distict so that HTTP and HTTPS sessions
|
||||
// are considered a single session.
|
||||
->distinct()
|
||||
->fields('s', array('sid'))
|
||||
->condition('s.uid', $user->uid);
|
||||
|
||||
if (module_exists('masquerade') && variable_get('session_limit_masquerade_ignore', FALSE)) {
|
||||
$query->leftJoin('masquerade', 'm', 's.uid = m.uid_as AND s.sid = m.sid');
|
||||
$query->isNull('m.sid');
|
||||
}
|
||||
|
||||
$active_sessions = $query->countQuery()->execute()->fetchField();
|
||||
$max_sessions = session_limit_user_max_sessions();
|
||||
|
||||
if (!empty($max_sessions) && $active_sessions > $max_sessions) {
|
||||
session_limit_invoke_session_limit(session_id(), 'collision');
|
||||
}
|
||||
else {
|
||||
// force checking this twice as there's a race condition around session creation.
|
||||
// see issue #1176412
|
||||
if (!isset($_SESSION['session_limit_checkonce'])) {
|
||||
$_SESSION['session_limit_checkonce'] = TRUE;
|
||||
}
|
||||
else {
|
||||
// mark session as verified to bypass this in future.
|
||||
$_SESSION['session_limit'] = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_action_info_alter().
|
||||
*/
|
||||
function session_limit_action_info_alter(&$info) {
|
||||
if (module_exists('token_actions')) {
|
||||
foreach ($info as $type => $data) {
|
||||
if (stripos($type, "token_actions_") === 0 || stripos($type, "system_") === 0) {
|
||||
if (isset($info[$type]['hooks']['session_limit'])) {
|
||||
array_merge($info[$type]['hooks']['session_limit'], array('collision', 'disconnect'));
|
||||
}
|
||||
else {
|
||||
$info[$type]['hooks']['session_limit'] = array('collision', 'disconnect');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_user_view().
|
||||
*/
|
||||
function session_limit_user_view($account, $view_mode) {
|
||||
if (user_access('administer session limits per user')) {
|
||||
$account->content['session_limit'] = array(
|
||||
'#title' => t('Session limit'),
|
||||
'#type' => 'user_profile_category',
|
||||
'session_limit' => array('#value' => empty($account->data['session_limit']) ? t('Default') : $account->data['session_limit'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Session limit user settings form.
|
||||
*/
|
||||
function session_limit_user_settings($form, $form_state, $account) {
|
||||
$form['account'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => $account,
|
||||
);
|
||||
|
||||
$form['session_limit'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Maximum sessions'),
|
||||
'#description' => t('Total number simultaneous active sessions this user may have at one time. The default defers to the limits that apply to each of the user\'s roles.'),
|
||||
'#required' => FALSE,
|
||||
'#default_value' => empty($account->data['session_limit']) ? 0 : $account->data['session_limit'],
|
||||
'#options' => _session_limit_user_options(),
|
||||
);
|
||||
$form['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save configuration'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Session limit user settings form validation.
|
||||
*/
|
||||
function session_limit_user_settings_validate($form, &$form_state) {
|
||||
if (!is_numeric($form_state['values']['session_limit'])) {
|
||||
form_set_error('session_limit', t('Only numeric submissions are valid.'));
|
||||
watchdog('session_limit', 'Invalid session limit submission for @user.', array('@user' => $form_state['values']['account']->name), WATCHDOG_DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Session limit user settings form submission.
|
||||
*/
|
||||
function session_limit_user_settings_submit($form, &$form_state) {
|
||||
watchdog('session_limit', 'Maximum sessions for @user updated to @count.', array('@user' => $form_state['values']['account']->name, '@count' => $form_state['values']['session_limit']), WATCHDOG_INFO, l(t('view'), "user/{$form_state['values']['account']->uid}"));
|
||||
if (empty($form_state['values']['session_limit'])) {
|
||||
$form_state['values']['session_limit'] = NULL;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display or delete sessions form.
|
||||
*/
|
||||
function session_limit_page() {
|
||||
global $user;
|
||||
|
||||
if (variable_get('session_limit_behaviour', SESSION_LIMIT_DO_NOTHING) == SESSION_LIMIT_DISALLOW_NEW) {
|
||||
session_destroy();
|
||||
$user = drupal_anonymous_user();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$result = db_query('SELECT * FROM {sessions} WHERE uid = :uid', array(':uid' => $user->uid));
|
||||
foreach ($result as $obj) {
|
||||
$message = $user->sid == $obj->sid ? t('Your current session.') : '';
|
||||
|
||||
$sids[$obj->sid] = t('<strong>Host:</strong> %host (idle: %time) <b>@message</b>',
|
||||
array(
|
||||
'%host' => $obj->hostname,
|
||||
'@message' => $message,
|
||||
'%time' => format_interval(time() - $obj->timestamp))
|
||||
);
|
||||
}
|
||||
|
||||
$form['sid'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Select a session to disconnect.'),
|
||||
'#options' => $sids,
|
||||
);
|
||||
|
||||
$form['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Disconnect session'),
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for submissions from session_limit_page().
|
||||
*/
|
||||
function session_limit_page_submit($form, &$form_state) {
|
||||
if ($GLOBALS['user']->sid == $form_state['values']['sid']) {
|
||||
drupal_goto('user/logout');
|
||||
}
|
||||
else {
|
||||
session_limit_invoke_session_limit($form_state['values']['sid'], 'disconnect');
|
||||
drupal_goto();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for populating the values of the settings form select.
|
||||
*/
|
||||
function _session_limit_user_options() {
|
||||
$options = drupal_map_assoc(range(0, 250));
|
||||
$options[0] = t('Default');
|
||||
$options['999999'] = t('Disabled');
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum number of sessions for a user.
|
||||
*
|
||||
* @param user $account
|
||||
* (optional) The user account to check. If not
|
||||
* supplied the active user account is used.
|
||||
*/
|
||||
function session_limit_user_max_sessions($account = NULL) {
|
||||
$limits = &drupal_static(__FUNCTION__, array());
|
||||
|
||||
if (empty($account)) {
|
||||
$account = $GLOBALS['user'];
|
||||
}
|
||||
|
||||
if (!isset($limits[$account->uid])) {
|
||||
$limits[$account->uid] = (int) variable_get('session_limit_max', 1);
|
||||
$limit_account = session_limit_user_max_sessions_byuser($account);
|
||||
$limit_role = session_limit_user_max_sessions_byrole($account);
|
||||
|
||||
if ($limit_account > 0) {
|
||||
$limits[$account->uid] = $limit_account;
|
||||
}
|
||||
elseif ($limit_role > 0) {
|
||||
$limits[$account->uid] = $limit_role;
|
||||
}
|
||||
|
||||
$limits[$account->uid] = (int) $limits[$account->uid];
|
||||
}
|
||||
|
||||
return $limits[$account->uid];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user specified session limit.
|
||||
*
|
||||
* @param user $account
|
||||
* The user account to get the session limit for
|
||||
*
|
||||
* @return int
|
||||
* Maximum number of sessions.
|
||||
* A value of 0 means that no user limit is set for the current user
|
||||
* and so the role limit should be used (or default if no role limit either).
|
||||
*/
|
||||
function session_limit_user_max_sessions_byuser($account) {
|
||||
return (int) empty($account->data['session_limit']) ? 0 : $account->data['session_limit'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum number of sessions allowed by the roles of an account.
|
||||
*
|
||||
* @param user $account
|
||||
* The account to check the roles of.
|
||||
*
|
||||
* @return int
|
||||
* The maximum number of sessions the user is allowed by their roles.
|
||||
* A value of 0 means that no role limit exists for this user and so
|
||||
* the default should be used.
|
||||
*/
|
||||
function session_limit_user_max_sessions_byrole($account) {
|
||||
$limits = array();
|
||||
|
||||
foreach ($account->roles as $rid => $name) {
|
||||
$limits[] = variable_get("session_limit_rid_$rid", 0);
|
||||
}
|
||||
|
||||
rsort($limits);
|
||||
|
||||
return (int) $limits[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_trigger_info().
|
||||
*/
|
||||
function session_limit_trigger_info() {
|
||||
return array(
|
||||
'session_limit' => array(
|
||||
'session_limit_collision' => array(
|
||||
'label' => t('User logs in and has too many active sessions'),
|
||||
),
|
||||
'session_limit_disconnect' => array(
|
||||
'label' => t('When an active user is logged out by a newer session'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit a users access to the sites based on the current session.
|
||||
*
|
||||
* @param string $session
|
||||
* The session id string which identifies the current session.
|
||||
* @param string $op
|
||||
* The action which caused the session limitation event. This is
|
||||
* either 'collision' or 'disconnect'.
|
||||
*
|
||||
* @return array
|
||||
* The results of all hook_session_limit functions.
|
||||
* Note that in a collision event, a Drupal goto is executed so
|
||||
* this function does not return.
|
||||
*/
|
||||
function session_limit_invoke_session_limit($session, $op) {
|
||||
$return = array();
|
||||
|
||||
// Execute the hook_session_limit().
|
||||
foreach (module_implements('session_limit') as $name) {
|
||||
$function = $name . '_session_limit';
|
||||
$result = $function($session, $op);
|
||||
if (isset($result) && is_array($result)) {
|
||||
$return = array_merge($return, $result);
|
||||
}
|
||||
elseif (isset($result)) {
|
||||
$return[] = $result;
|
||||
}
|
||||
}
|
||||
|
||||
// In the event of a collision, redirect to session handler.
|
||||
if ($op == 'collision') {
|
||||
if (variable_get('session_limit_behaviour', SESSION_LIMIT_DO_NOTHING) == SESSION_LIMIT_DROP) {
|
||||
global $user;
|
||||
|
||||
// Get the number of sessions that should be removed.
|
||||
$limit = db_query("SELECT COUNT(DISTINCT(sid)) - :max_sessions FROM {sessions} WHERE uid = :uid", array(
|
||||
':max_sessions' => session_limit_user_max_sessions($user),
|
||||
':uid' => $user->uid,
|
||||
))->fetchField();
|
||||
|
||||
if ($limit > 0) {
|
||||
// Secure session ids are seperate rows in the database, but we don't want to kick
|
||||
// the user off there http session and not there https session or vice versa. This
|
||||
// is why this query is DISTINCT.
|
||||
$result = db_select('sessions', 's')
|
||||
->distinct()
|
||||
->fields('s', array('sid'))
|
||||
->condition('s.uid', $user->uid)
|
||||
->orderBy('timestamp', 'ASC')
|
||||
->range(0, $limit)
|
||||
->execute();
|
||||
|
||||
foreach ($result as $session) {
|
||||
session_limit_invoke_session_limit($session->sid, 'disconnect');
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Otherwise re-direct to the session handler page so the user can
|
||||
// choose which action they would like to take.
|
||||
drupal_goto('session/limit');
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_session_limit().
|
||||
*/
|
||||
function session_limit_session_limit($sid, $op) {
|
||||
switch ($op) {
|
||||
case 'collision':
|
||||
watchdog('session_limit', 'Exceeded maximum allowed active sessions.', array(), WATCHDOG_INFO);
|
||||
break;
|
||||
|
||||
case 'disconnect':
|
||||
$message = variable_get('session_limit_logged_out_message', SESSION_LIMIT_LOGGED_OUT_MESSAGE);
|
||||
$message_severity = variable_get('session_limit_logged_out_message_severity', SESSION_LIMIT_LOGGED_OUT_MESSAGE_SEVERITY);
|
||||
$fields['session'] = '';
|
||||
|
||||
if ($message_severity != '_none' && !empty($message)) {
|
||||
$logout_message = t($message, array('@number' => session_limit_user_max_sessions()));
|
||||
$logout_message = 'messages|' . serialize(array($message_severity => array($logout_message)));
|
||||
$fields['session'] = $logout_message;
|
||||
}
|
||||
|
||||
$fields['uid'] = 0;
|
||||
$query = db_update('sessions')
|
||||
->fields($fields)
|
||||
->condition('sid', $sid)
|
||||
->execute();
|
||||
|
||||
watchdog('session_limit', 'Disconnected for excess active sessions.', array(), WATCHDOG_NOTICE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_session_limit().
|
||||
*
|
||||
* This implements the hook on behalf of the trigger module.
|
||||
*/
|
||||
function trigger_session_limit($sid, $op) {
|
||||
// Find all the actions against this $op.
|
||||
// Note: this notation requires the $op to match the bit in the trigger info keys after session_limit!
|
||||
$aids = trigger_get_assigned_actions('session_limit_' . $op);
|
||||
$context = array(
|
||||
'hook' => 'session_limit',
|
||||
'op' => $op,
|
||||
'sid' => $sid,
|
||||
);
|
||||
actions_do(array_keys($aids), $GLOBALS['user'], $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_session_limit().
|
||||
*
|
||||
* This implements the hook on behalf of the rules module.
|
||||
*/
|
||||
function rules_session_limit($sid, $op) {
|
||||
global $user;
|
||||
rules_invoke_event('session_limit_' . $op, $user, $sid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_session_limit_bypass().
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the page request should bypass session limitation restrictions.
|
||||
*/
|
||||
function session_limit_session_limit_bypass() {
|
||||
if ((arg(0) == 'session' && arg(1) == 'limit') || (arg(0) == 'user' && arg(1) == 'logout')) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the session limit bypass hook.
|
||||
*
|
||||
* Allow other modules to prevent session limits in their own requirements.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if session limitation should be bypassed.
|
||||
*/
|
||||
function _session_limit_bypass() {
|
||||
foreach (module_invoke_all('session_limit_bypass') as $bypass) {
|
||||
if (!empty($bypass)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Rules integration with session_limit.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_rules_event_info().
|
||||
*/
|
||||
function session_limit_rules_event_info() {
|
||||
$items = array();
|
||||
|
||||
$items['session_limit_collision'] = array(
|
||||
'label' => t('User logs in and has too many active sessions'),
|
||||
'variables' => array(
|
||||
'account' => array(
|
||||
'type' => 'user',
|
||||
'label' => t('The user who logged in.'),
|
||||
),
|
||||
'session_id' => array(
|
||||
'type' => 'text',
|
||||
'label' => t('The session id.'),
|
||||
),
|
||||
),
|
||||
'group' => t('Session Limit'),
|
||||
);
|
||||
|
||||
$items['session_limit_disconnect'] = array(
|
||||
'label' => t('User is logged out by a newer session'),
|
||||
'variables' => array(
|
||||
'account' => array(
|
||||
'type' => 'user',
|
||||
'label' => t('The user who was logged out.'),
|
||||
),
|
||||
'session_id' => array(
|
||||
'type' => 'text',
|
||||
'label' => t('The session id.'),
|
||||
),
|
||||
),
|
||||
'group' => t('Session Limit'),
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Provide tokens for session limit.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_token_info().
|
||||
*
|
||||
* Create tokens for the current user.
|
||||
*/
|
||||
function session_limit_token_info() {
|
||||
$type = array(
|
||||
'name' => t('Session limit'),
|
||||
'description' => t('Tokens related to session limit module.'),
|
||||
'needs-data' => 'user',
|
||||
);
|
||||
|
||||
$session_limit['default'] = array(
|
||||
'name' => t('Default sessions'),
|
||||
'description' => t('Maximum number of active sessions configured specific to the user.'),
|
||||
);
|
||||
$session_limit['max'] = array(
|
||||
'name' => t('Maximum sessions'),
|
||||
'description' => t('Maximum number of active sessions allowed, accounting for all configuration possibilities.'),
|
||||
);
|
||||
$session_limit['role'] = array(
|
||||
'name' => t('Maximum sessions by role'),
|
||||
'description' => t('Maximum number of active sessions allowed by role.'),
|
||||
);
|
||||
$session_limit['user'] = array(
|
||||
'name' => t('Maximum sessions for user'),
|
||||
'description' => t('Maximum number of active sessions configured specific to the user.'),
|
||||
);
|
||||
|
||||
return array(
|
||||
'types' => array('session_limit' => $type),
|
||||
'tokens' => array('session_limit' => $session_limit),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_tokens().
|
||||
*/
|
||||
function session_limit_tokens($type, $tokens, array $data = array(), array $options = array()) {
|
||||
$replacements = array();
|
||||
// The session limit variable does not need the user context.
|
||||
if ($type == 'session_limit') {
|
||||
foreach ($tokens as $name => $original) {
|
||||
if ($name == 'default') {
|
||||
$replacements[$original] = variable_get('session_limit_max', 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($type == 'session_limit' && !empty($data['user'])) {
|
||||
$account = user_load($data['user']->uid);
|
||||
foreach ($tokens as $name => $original) {
|
||||
switch ($name) {
|
||||
case 'max':
|
||||
$replacements[$original] = session_limit_user_max_sessions($account);
|
||||
break;
|
||||
case 'role':
|
||||
$replacements[$original] = session_limit_user_max_sessions_byrole($account);
|
||||
break;
|
||||
case 'user':
|
||||
$replacements[$original] = empty($account->session_limit) ? 0 : check_plain($account->session_limit);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $replacements;
|
||||
}
|
@@ -0,0 +1,604 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Simpletest tests for session_limit.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base test for session limits.
|
||||
*
|
||||
* This contains a collection of helper functions and session_limit
|
||||
* assertions.
|
||||
*/
|
||||
class SessionLimitBaseTestCase extends DrupalWebTestCase {
|
||||
|
||||
/**
|
||||
* A store references to different sessions.
|
||||
*/
|
||||
protected $curlHandles = array();
|
||||
protected $loggedInUsers = array();
|
||||
|
||||
/**
|
||||
* Session limit helper function to create 3 roles.
|
||||
*
|
||||
* @param stdClass $user
|
||||
* (optional) If provided the user will be added to
|
||||
* the three roles.
|
||||
*
|
||||
* @return array
|
||||
* An array of the three roles.
|
||||
*/
|
||||
public function sessionLimitMakeRoles($user = NULL) {
|
||||
// Create roles.
|
||||
$roles = array();
|
||||
|
||||
$roles[] = (object) array('name' => 'role1');
|
||||
$roles[] = (object) array('name' => 'role2');
|
||||
$roles[] = (object) array('name' => 'role3');
|
||||
user_role_save($roles[0]);
|
||||
user_role_save($roles[1]);
|
||||
user_role_save($roles[2]);
|
||||
|
||||
if (!empty($user)) {
|
||||
$user->roles[$roles[0]->rid] = $roles[0]->name;
|
||||
$user->roles[$roles[1]->rid] = $roles[1]->name;
|
||||
$user->roles[$roles[2]->rid] = $roles[2]->name;
|
||||
user_save($user);
|
||||
}
|
||||
|
||||
return $roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that an individual user can have up to a specifed number of sessions.
|
||||
*
|
||||
* Once the maximum is reached, the oldest session is logged out.
|
||||
*
|
||||
* @param int $session_limit
|
||||
* The max number of sessions the specified user should be able to access.
|
||||
* @param stdClass $user
|
||||
* (optional) The user to test this with. Leave blank to create a user.
|
||||
*/
|
||||
public function assertSessionLogout($session_limit, stdClass $user = NULL) {
|
||||
// Set the session limit behaviour to log out of old sessions.
|
||||
variable_set('session_limit_behaviour', 1);
|
||||
variable_set('session_limit_logged_out_message', 'Reached limit @number.');
|
||||
|
||||
// Create the user to test with.
|
||||
$user = empty($user) ? $this->drupalCreateUser(array('access content')) : $user;
|
||||
|
||||
$sessions = array();
|
||||
|
||||
for ($session_number = 1; $session_number <= $session_limit; $session_number++) {
|
||||
|
||||
// Log user into each session.
|
||||
$this->drupalLogin($user);
|
||||
$this->drupalGet('user');
|
||||
$this->assertText(t('Log out'), t('User is logged in under session @no.', array('@no' => $session_number)));
|
||||
$this->assertText($user->name, t('User is logged in under session @no.', array('@no' => $session_number)));
|
||||
|
||||
// Backup session.
|
||||
$sessions[$session_number] = $this->stashSession();
|
||||
|
||||
// Wait briefly to prevent race conditions.
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// Check all allowed sessions are currently accessible.
|
||||
foreach ($sessions as $session_number => $session_id) {
|
||||
$this->restoreSession($session_id);
|
||||
$this->drupalGet('user');
|
||||
$this->assertText(t('Log out'), t('User is logged in under session @no.', array('@no' => $session_number)));
|
||||
$this->assertText($user->name, t('User is logged in under session @no.', array('@no' => $session_number)));
|
||||
}
|
||||
|
||||
// Create a further session.
|
||||
$extra_session_number = $session_limit + 1;
|
||||
$this->stashSession();
|
||||
$this->drupalLogin($user);
|
||||
$this->drupalGet('user');
|
||||
$this->assertText(t('Log out'), t('User is logged in under session @no.', array('@no' => $extra_session_number)));
|
||||
$this->assertText($user->name, t('User is logged in under session @no.', array('@no' => $extra_session_number)));
|
||||
|
||||
// Check user 1 is no longer logged in on session 1.
|
||||
$sessions[$extra_session_number] = $this->stashSession();
|
||||
$this->restoreSession($sessions[1]);
|
||||
$this->drupalGet('node');
|
||||
$this->assertNoText(t('Log out'), t('User 1 is not logged in under session 1.'));
|
||||
|
||||
$this->assertText(t('Reached limit @number.', array('@number' => $session_limit)), t('User was shown session limit message.'));
|
||||
|
||||
// Check user 1 is logged in on all other sessions.
|
||||
foreach ($sessions as $session_number => $session_id) {
|
||||
if ($session_number == 1) {
|
||||
// We know they have been logged out of session 1.
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->restoreSession($session_id);
|
||||
$this->drupalGet('user');
|
||||
$this->assertText(t('Log out'), t('User is logged in under session @no.', array('@no' => $session_number)));
|
||||
$this->assertText($user->name, t('User is logged in under session @no.', array('@no' => $session_number)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that new sessions cannot be created past a maximum.
|
||||
*
|
||||
* This tests the session_limit 'prevent new sessions' behaviour once
|
||||
* the maximum is reached.
|
||||
*
|
||||
* @param int $session_limit
|
||||
* The maximum number of allowed sessions.
|
||||
*/
|
||||
public function assertSessionPrevent($session_limit) {
|
||||
// Set the session limit behaviour to prevent new sessions.
|
||||
variable_set('session_limit_behaviour', 2);
|
||||
|
||||
// Set the default session limit to 1.
|
||||
variable_set('session_limit_max', $session_limit);
|
||||
|
||||
// Create the user to test with.
|
||||
$user = $this->drupalCreateUser(array('access content'));
|
||||
|
||||
$sessions = array();
|
||||
|
||||
for ($session_number = 1; $session_number <= $session_limit; $session_number++) {
|
||||
|
||||
// Log user into each session.
|
||||
$this->drupalLogin($user);
|
||||
$this->drupalGet('user');
|
||||
$this->assertText(t('Log out'), t('User is logged in under session @no.', array('@no' => $session_number)));
|
||||
$this->assertText($user->name, t('User is logged in under session @no.', array('@no' => $session_number)));
|
||||
|
||||
// Backup session.
|
||||
$sessions[$session_number] = $this->stashSession();
|
||||
}
|
||||
|
||||
// Check all allowed sessions are currently accessible.
|
||||
foreach ($sessions as $session_number => $session_id) {
|
||||
$this->restoreSession($session_id);
|
||||
$this->drupalGet('user');
|
||||
$this->assertText(t('Log out'), t('User is logged in under session @no.', array('@no' => $session_number)));
|
||||
$this->assertText($user->name, t('User is logged in under session @no.', array('@no' => $session_number)));
|
||||
}
|
||||
|
||||
// Try to login on a further session.
|
||||
$this->stashSession();
|
||||
$this->drupalLoginExpectFail($user);
|
||||
$this->assertText(t('The maximum number of simultaneous sessions (@session_limit) 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('@session_limit' => $session_limit)), t('User sees the session limit login prevention message.'));
|
||||
|
||||
// Switch back to session 1 and logout.
|
||||
$extra_session_number = $session_limit + 1;
|
||||
$sessions[$extra_session_number] = $this->stashSession();
|
||||
$this->restoreSession($sessions[1]);
|
||||
$this->drupalLogout($user);
|
||||
$this->drupalGet('node');
|
||||
$this->assertNoText(t('Log out'), t('User has logged out of session 1.'));
|
||||
|
||||
// Switch back to extra session and check they can now login.
|
||||
$this->restoreSession($sessions[$extra_session_number]);
|
||||
$this->drupalLogin($user);
|
||||
$this->drupalGet('node');
|
||||
$this->assertText(t('Log out'), t('User has logged into the extra session now they have logged out of session 1.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise a new unique session.
|
||||
*
|
||||
* @return string
|
||||
* Unique identifier for the session just stored.
|
||||
* It is the cookiefile name.
|
||||
*/
|
||||
public function stashSession() {
|
||||
if (empty($this->cookieFile)) {
|
||||
// No session to stash.
|
||||
return;
|
||||
}
|
||||
|
||||
// The session_id is the current cookieFile.
|
||||
$session_id = $this->cookieFile;
|
||||
|
||||
$this->curlHandles[$session_id] = $this->curlHandle;
|
||||
$this->loggedInUsers[$session_id] = $this->loggedInUser;
|
||||
|
||||
// Reset Curl.
|
||||
unset($this->curlHandle);
|
||||
$this->loggedInUser = FALSE;
|
||||
|
||||
// Set a new unique cookie filename.
|
||||
do {
|
||||
$this->cookieFile = $this->public_files_directory . '/' . $this->randomName() . '.jar';
|
||||
}
|
||||
while (isset($this->curlHandles[$this->cookieFile]));
|
||||
|
||||
return $session_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore a previously stashed session.
|
||||
*
|
||||
* @param string $session_id
|
||||
* The session to restore as returned by stashSession();
|
||||
* This is also the path to the cookie file.
|
||||
*
|
||||
* @return string
|
||||
* The old session id that was replaced.
|
||||
*/
|
||||
public function restoreSession($session_id) {
|
||||
$old_session_id = NULL;
|
||||
|
||||
if (isset($this->curlHandle)) {
|
||||
$old_session_id = $this->stashSession();
|
||||
}
|
||||
|
||||
// Restore the specified session.
|
||||
$this->curlHandle = $this->curlHandles[$session_id];
|
||||
$this->cookieFile = $session_id;
|
||||
$this->loggedInUser = $this->loggedInUsers[$session_id];
|
||||
|
||||
return $old_session_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close all stashed sessions and the current session.
|
||||
*/
|
||||
public function closeAllSessions() {
|
||||
foreach ($this->curlHandles as $cookie_file => $curl_handle) {
|
||||
if (isset($curl_handle)) {
|
||||
curl_close($curl_handle);
|
||||
}
|
||||
}
|
||||
|
||||
// Make the server forget all sessions.
|
||||
db_truncate('sessions')->execute();
|
||||
|
||||
$this->curlHandles = array();
|
||||
$this->loggedInUsers = array();
|
||||
$this->loggedInUser = FALSE;
|
||||
$this->cookieFile = $this->public_files_directory . '/' . $this->randomName() . '.jar';
|
||||
unset($this->curlHandle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log in a user with the internal browser but expect this to fail.
|
||||
*
|
||||
* This works as drupalLogin but instead of checking if the login succeeded,
|
||||
* it instead checks for not being logged in and fails if it has managed
|
||||
* to login successfully.
|
||||
*
|
||||
* @param $account
|
||||
* User object representing the user to log in.
|
||||
*
|
||||
* @see drupalCreateUser()
|
||||
*/
|
||||
protected function drupalLoginExpectFail(stdClass $account) {
|
||||
if ($this->loggedInUser) {
|
||||
$this->drupalLogout();
|
||||
}
|
||||
|
||||
$edit = array(
|
||||
'name' => $account->name,
|
||||
'pass' => $account->pass_raw
|
||||
);
|
||||
$this->drupalPost('user', $edit, t('Log in'));
|
||||
|
||||
// Check that login was unsuccessful by ensuring there is no log out link.
|
||||
$pass = $this->assertNoLink(t('Log out'), 0, t('User %name did not log in.', array('%name' => $account->name)), t('User login'));
|
||||
|
||||
if (!$pass) {
|
||||
$this->loggedInUser = $account;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the multiple session test functionality.
|
||||
*/
|
||||
class SessionLimitSessionTestCase extends SessionLimitBaseTestCase {
|
||||
|
||||
/**
|
||||
* getInfo() returns properties that are displayed in the test selection form.
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Session Limit MutiSession Tests',
|
||||
'description' => 'Ensure the multi session tests for SimpleTest work as expected',
|
||||
'group' => 'Session Limit',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* setUp() performs any pre-requisite tasks that need to happen.
|
||||
*/
|
||||
public function setUp() {
|
||||
// Enable any modules required for the test.
|
||||
parent::setUp('session_limit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test session stash and restore.
|
||||
*
|
||||
* Drupal Simpletest has no native ability to test over multiple sessions.
|
||||
* The session_limit tests add this functionality. This first test checks
|
||||
* that multiple sessions are working in SimpleTest by logging in as two
|
||||
* different users simultaneously via two cUrl sessions.
|
||||
*/
|
||||
public function testSessionStashAndRestore() {
|
||||
|
||||
// Create and log in our privileged user.
|
||||
$user1 = $this->drupalCreateUser(array('access content'));
|
||||
$user2 = $this->drupalCreateUser(array('access content'));
|
||||
|
||||
// Make sure that session_limit does not interfere with
|
||||
// this test of the tests.
|
||||
variable_set('session_limit_behaviour', 0);
|
||||
variable_set('session_limit_max', 100);
|
||||
|
||||
// Login under session 1.
|
||||
$this->drupalLogin($user1);
|
||||
$this->drupalGet('user');
|
||||
$this->assertText(t('Log out'), t('User is logged in under session 1.'));
|
||||
$this->assertText($user1->name, t('User1 is logged in under session 1.'));
|
||||
|
||||
// Backup session 1.
|
||||
$session_1 = $this->stashSession();
|
||||
|
||||
// Check session 2 is logged out.
|
||||
$this->drupalGet('node');
|
||||
$this->assertNoText(t('Log out'), t('Session 1 is shelved.'));
|
||||
|
||||
// Login under session 2.
|
||||
$this->drupalLogin($user2);
|
||||
$this->drupalGet('user');
|
||||
$this->assertText(t('Log out'), t('User is logged in under session 2.'));
|
||||
$this->assertText($user2->name, t('User2 is logged in under session 2.'));
|
||||
|
||||
// Backup session 2.
|
||||
$session_2 = $this->stashSession();
|
||||
|
||||
// Switch to session 1.
|
||||
$this->restoreSession($session_1);
|
||||
|
||||
// Check still logged in as session 1.
|
||||
$this->drupalGet('user');
|
||||
$this->assertText(t('Log out'), t('User is logged in under session 1.'));
|
||||
$this->assertText($user1->name, t('User1 is logged in under session 1.'));
|
||||
|
||||
// Switch to session 2.
|
||||
$this->restoreSession($session_2);
|
||||
|
||||
// Check still logged in as session 2.
|
||||
$this->drupalGet('user');
|
||||
$this->assertText(t('Log out'), t('User is logged in under session 2.'));
|
||||
$this->assertText($user2->name, t('User2 is logged in under session 2.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Session limit functions when expected behaviour is to logout oldest session.
|
||||
*/
|
||||
class SessionLimitLogoutTestCase extends SessionLimitBaseTestCase {
|
||||
|
||||
/**
|
||||
* getInfo() returns properties that are displayed in the test selection form.
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Session Limit Logout Tests',
|
||||
'description' => 'Ensure that the session limit module functions as expected when behaviour is set to logout oldest session',
|
||||
'group' => 'Session Limit',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* setUp() performs any pre-requisite tasks that need to happen.
|
||||
*/
|
||||
public function setUp() {
|
||||
// Enable any modules required for the test.
|
||||
parent::setUp('session_limit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test user can only have 1 session, logout oldest.
|
||||
*/
|
||||
public function testSessionLogoutOnMax1() {
|
||||
// Set the default session limit.
|
||||
variable_set('session_limit_max', 1);
|
||||
|
||||
$this->assertSessionLogout(1);
|
||||
$this->closeAllSessions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test user can only have 2 sessions, logout oldest.
|
||||
*/
|
||||
public function testSessionLogoutOnMax2() {
|
||||
// Set the default session limit.
|
||||
variable_set('session_limit_max', 2);
|
||||
|
||||
$this->assertSessionLogout(2);
|
||||
$this->closeAllSessions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the session limit is returned correctly by a role.
|
||||
*/
|
||||
public function testSessionLimitRoles() {
|
||||
// Create a test user.
|
||||
$user = $this->drupalCreateUser(array('access content'));
|
||||
$roles = $this->sessionLimitMakeRoles($user);
|
||||
|
||||
// Set the session limits for the roles.
|
||||
variable_set('session_limit_rid_' . $roles[0]->rid, 2);
|
||||
variable_set('session_limit_rid_' . $roles[1]->rid, 4);
|
||||
variable_set('session_limit_rid_' . $roles[2]->rid, 3);
|
||||
|
||||
// Set the default session limit.
|
||||
variable_set('session_limit_max', 1);
|
||||
|
||||
// Check if the user has access to 4 sessions.
|
||||
$this->assertSessionLogout(4, $user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the session limit is returned correctly by a user override.
|
||||
*/
|
||||
public function testSessionLimitUser() {
|
||||
// Create a test user.
|
||||
$user = $this->drupalCreateUser();
|
||||
$roles = $this->sessionLimitMakeRoles($user);
|
||||
|
||||
// Add a personal session limit.
|
||||
user_save($user, array('data' => array('session_limit' => 5)));
|
||||
|
||||
// Set the session limits for the roles.
|
||||
variable_set('session_limit_rid_' . $roles[0]->rid, 2);
|
||||
variable_set('session_limit_rid_' . $roles[1]->rid, 3);
|
||||
variable_set('session_limit_rid_' . $roles[2]->rid, 4);
|
||||
|
||||
// Set the default session limit.
|
||||
variable_set('session_limit_max', 1);
|
||||
|
||||
// Check if the user has access to 5 sessions.
|
||||
$this->assertSessionLogout(5, $user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that user override takes precedence over default and role regardless of max.
|
||||
*/
|
||||
public function testSessionLimitUserMaxPrecedence() {
|
||||
// Create a test user.
|
||||
$user = $this->drupalCreateUser();
|
||||
$roles = $this->sessionLimitMakeRoles($user);
|
||||
|
||||
// Add a personal session limit.
|
||||
user_save($user, array('data' => array('session_limit' => 1)));
|
||||
|
||||
// Set the session limits for the roles.
|
||||
variable_set('session_limit_rid_' . $roles[0]->rid, 3);
|
||||
variable_set('session_limit_rid_' . $roles[1]->rid, 4);
|
||||
variable_set('session_limit_rid_' . $roles[2]->rid, 5);
|
||||
|
||||
// Set the default session limit.
|
||||
variable_set('session_limit_max', 2);
|
||||
|
||||
// Check if the user has access to only 1 session.
|
||||
$this->assertSessionLogout(1, $user);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Session limit functionality when behaviour is to prevent login at limit.
|
||||
*/
|
||||
class SessionLimitPreventTestCase extends SessionLimitBaseTestCase {
|
||||
|
||||
/**
|
||||
* getInfo() returns properties that are displayed in the test selection form.
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Session Limit Prevent Tests',
|
||||
'description' => 'Ensure that the session limit module functions as expected when behaviour is set to prevent new sessions',
|
||||
'group' => 'Session Limit',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* setUp() performs any pre-requisite tasks that need to happen.
|
||||
*/
|
||||
public function setUp() {
|
||||
// Enable any modules required for the test.
|
||||
parent::setUp('session_limit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test user can only have 1 session, prevent new sessions.
|
||||
*/
|
||||
public function testSessionPreventOnMax1() {
|
||||
// Set the default session limit.
|
||||
variable_set('session_limit_max', 1);
|
||||
|
||||
$this->assertSessionPrevent(1);
|
||||
$this->closeAllSessions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test user can only have 2 sessions, prevent new sessions.
|
||||
*/
|
||||
public function testSessionPreventOnMax2() {
|
||||
// Set the default session limit.
|
||||
variable_set('session_limit_max', 1);
|
||||
|
||||
$this->assertSessionPrevent(2);
|
||||
$this->closeAllSessions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the session limit is returned correctly by a role.
|
||||
*/
|
||||
public function testSessionLimitRoles() {
|
||||
// Create a test user.
|
||||
$user = $this->drupalCreateUser(array('access content'));
|
||||
$roles = $this->sessionLimitMakeRoles($user);
|
||||
|
||||
// Set the session limits for the roles.
|
||||
variable_set('session_limit_rid_' . $roles[0]->rid, 2);
|
||||
variable_set('session_limit_rid_' . $roles[1]->rid, 4);
|
||||
variable_set('session_limit_rid_' . $roles[2]->rid, 3);
|
||||
|
||||
// Set the default session limit.
|
||||
variable_set('session_limit_max', 1);
|
||||
|
||||
// Check if the user has access to 4 sessions.
|
||||
$this->assertSessionPrevent(4, $user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the session limit is returned correctly by a user override.
|
||||
*/
|
||||
public function testSessionLimitUser() {
|
||||
// Create a test user.
|
||||
$user = $this->drupalCreateUser();
|
||||
$roles = $this->sessionLimitMakeRoles($user);
|
||||
|
||||
// Add a personal session limit.
|
||||
user_save($user, array('data' => array('session_limit' => 5)));
|
||||
|
||||
// Set the session limits for the roles.
|
||||
variable_set('session_limit_rid_' . $roles[0]->rid, 2);
|
||||
variable_set('session_limit_rid_' . $roles[1]->rid, 3);
|
||||
variable_set('session_limit_rid_' . $roles[2]->rid, 4);
|
||||
|
||||
// Set the default session limit.
|
||||
variable_set('session_limit_max', 1);
|
||||
|
||||
// Check if the user has access to 5 sessions.
|
||||
$this->assertSessionPrevent(5, $user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that a user session limit is always used in preference to all others.
|
||||
*/
|
||||
public function testSessionLimitUserMaxPrecedence() {
|
||||
// Create a test user.
|
||||
$user = $this->drupalCreateUser();
|
||||
$roles = $this->sessionLimitMakeRoles($user);
|
||||
|
||||
// Add a personal session limit.
|
||||
user_save($user, array('data' => array('session_limit' => 1)));
|
||||
|
||||
// Set the session limits for the roles.
|
||||
variable_set('session_limit_rid_' . $roles[0]->rid, 3);
|
||||
variable_set('session_limit_rid_' . $roles[1]->rid, 4);
|
||||
variable_set('session_limit_rid_' . $roles[2]->rid, 5);
|
||||
|
||||
// Set the default session limit.
|
||||
variable_set('session_limit_max', 2);
|
||||
|
||||
// Check if the user has access to 1 session, the user specified max.
|
||||
$this->assertSessionPrevent(1, $user);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user