FINAL suepr merge step : added all modules to this super repos
This commit is contained in:
339
sites/all/modules/contrib/form/honeypot/LICENSE.txt
Normal file
339
sites/all/modules/contrib/form/honeypot/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.
|
||||
43
sites/all/modules/contrib/form/honeypot/README.txt
Normal file
43
sites/all/modules/contrib/form/honeypot/README.txt
Normal file
@@ -0,0 +1,43 @@
|
||||
|
||||
Honeypot Module Readme
|
||||
----------------------
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
To install this module, place it in your sites/all/modules folder and enable it
|
||||
on the modules page.
|
||||
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
All settings for this module are on the Honeypot configuration page, under the
|
||||
Configuration section, in the Content authoring settings. You can visit the
|
||||
configuration page directly at admin/config/content/honeypot.
|
||||
|
||||
Note that, when testing Honeypot on your website, make sure you're not logged in
|
||||
as an administrative user or user 1; Honeypot allows administrative users to
|
||||
bypass Honeypot protection, so by default, Honeypot will not be added to forms
|
||||
accessed by site administrators.
|
||||
|
||||
|
||||
Use in Your Own Forms
|
||||
---------------------
|
||||
|
||||
If you want to add honeypot to your own forms, or to any form through your own
|
||||
module's hook_form_alter's, you can simply place the following function call
|
||||
inside your form builder function (or inside a hook_form_alter):
|
||||
|
||||
honeypot_add_form_protection($form, $form_state, array('honeypot', 'time_restriction'));
|
||||
|
||||
Note that you can enable or disable either the honeypot field, or the time
|
||||
restriction on the form by including or not including the option in the array.
|
||||
|
||||
|
||||
Credit
|
||||
------
|
||||
|
||||
The Honeypot module was originally developed by Jeff Geerling of Midwestern Mac,
|
||||
LLC (midwesternmac.com), and sponsored by flockNote (flocknote.com).
|
||||
181
sites/all/modules/contrib/form/honeypot/honeypot.admin.inc
Normal file
181
sites/all/modules/contrib/form/honeypot/honeypot.admin.inc
Normal file
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Honeypot administration form.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Honeypot administration page.
|
||||
*/
|
||||
function honeypot_admin_form($form, &$form_state) {
|
||||
// Honeypot Configuration.
|
||||
$form['configuration'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Honeypot Configuration'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => FALSE,
|
||||
);
|
||||
$form['configuration']['honeypot_protect_all_forms'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Protect all forms with Honeypot'),
|
||||
'#description' => t('Enable Honeypot protection for ALL forms on this site (it is best to only enable Honeypot for the forms you need below).'),
|
||||
'#default_value' => variable_get('honeypot_protect_all_forms', 0),
|
||||
);
|
||||
$form['configuration']['honeypot_protect_all_forms']['#description'] .= '<br />' . t('<strong>Page caching will be disabled on any page where a form is present if the Honeypot time limit is not set to 0.</strong>');
|
||||
$form['configuration']['honeypot_log'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Log blocked form submissions'),
|
||||
'#description' => t('Log submissions that are blocked due to Honeypot protection.'),
|
||||
'#default_value' => variable_get('honeypot_log', 0),
|
||||
);
|
||||
$form['configuration']['honeypot_element_name'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Honeypot element name'),
|
||||
'#description' => t("The name of the Honeypot form field. It's usually most effective to use a generic name like email, homepage, or name, but this should be changed if it interferes with fields that are already in your forms. Must not contain spaces or special characters."),
|
||||
'#default_value' => variable_get('honeypot_element_name', 'url'),
|
||||
'#required' => TRUE,
|
||||
'#size' => 30,
|
||||
);
|
||||
$form['configuration']['honeypot_time_limit'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Honeypot time limit'),
|
||||
'#description' => t('Minimum time required before form should be considered entered by a human instead of a bot. Set to 0 to disable.'),
|
||||
'#default_value' => variable_get('honeypot_time_limit', 5),
|
||||
'#required' => TRUE,
|
||||
'#size' => 5,
|
||||
'#field_suffix' => t('seconds'),
|
||||
);
|
||||
$form['configuration']['honeypot_time_limit']['#description'] .= '<br />' . t('<strong>Page caching will be disabled if there is a form protected by time limit on the page.</strong>');
|
||||
|
||||
// Honeypot Enabled forms.
|
||||
$form['enabled_forms'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Honeypot Enabled Forms'),
|
||||
'#description' => t("Check the boxes next to individual forms on which you'd like Honeypot protection enabled."),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => FALSE,
|
||||
'#states' => array(
|
||||
// Hide this fieldset when all forms are protected.
|
||||
'invisible' => array(
|
||||
'input[name="honeypot_protect_all_forms"]' => array('checked' => TRUE),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Generic forms.
|
||||
$form['enabled_forms']['general_forms'] = array('#markup' => '<h5>' . t('General Forms') . '</h5>');
|
||||
// User register form.
|
||||
$form['enabled_forms']['honeypot_form_user_register_form'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('User Registration form'),
|
||||
'#default_value' => variable_get('honeypot_form_user_register_form', 0),
|
||||
);
|
||||
// User password form.
|
||||
$form['enabled_forms']['honeypot_form_user_pass'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('User Password Reset form'),
|
||||
'#default_value' => variable_get('honeypot_form_user_pass', 0),
|
||||
);
|
||||
|
||||
// If webform.module enabled, add webforms.
|
||||
if (module_exists('webform')) {
|
||||
$form['enabled_forms']['honeypot_form_webforms'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Webforms (all)'),
|
||||
'#default_value' => variable_get('honeypot_form_webforms', 0),
|
||||
);
|
||||
}
|
||||
|
||||
// If contact.module enabled, add contact forms.
|
||||
if (module_exists('contact')) {
|
||||
$form['enabled_forms']['contact_forms'] = array('#markup' => '<h5>' . t('Contact Forms') . '</h5>');
|
||||
// Sitewide contact form.
|
||||
$form['enabled_forms']['honeypot_form_contact_site_form'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Sitewide Contact form'),
|
||||
'#default_value' => variable_get('honeypot_form_contact_site_form', 0),
|
||||
);
|
||||
// Sitewide personal form.
|
||||
$form['enabled_forms']['honeypot_form_contact_personal_form'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Personal Contact forms'),
|
||||
'#default_value' => variable_get('honeypot_form_contact_personal_form', 0),
|
||||
);
|
||||
}
|
||||
|
||||
// If profile.module enabled, add profile forms.
|
||||
if (module_exists('profile')) {
|
||||
$form['enabled_forms']['profile_forms'] = array('#value' => '<h5>' . t('Profile Forms') . '</h5>');
|
||||
$form['enabled_forms']['honeypot_form_user_profile_form'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Profile forms (all)'),
|
||||
'#default_value' => variable_get('honeypot_form_user_profile_form', 0),
|
||||
);
|
||||
}
|
||||
|
||||
// Get node types for node forms and node comment forms.
|
||||
$types = node_type_get_types();
|
||||
if (!empty($types)) {
|
||||
// Node forms.
|
||||
$form['enabled_forms']['node_forms'] = array('#markup' => '<h5>' . t('Node Forms') . '</h5>');
|
||||
foreach ($types as $type) {
|
||||
$id = 'honeypot_form_' . $type->type . '_node_form';
|
||||
$form['enabled_forms'][$id] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('@name node form', array('@name' => $type->name)),
|
||||
'#default_value' => variable_get($id, 0),
|
||||
);
|
||||
}
|
||||
|
||||
// Comment forms.
|
||||
if (module_exists('comment')) {
|
||||
$form['enabled_forms']['comment_forms'] = array('#markup' => '<h5>' . t('Comment Forms') . '</h5>');
|
||||
foreach ($types as $type) {
|
||||
$id = 'honeypot_form_comment_node_' . $type->type . '_form';
|
||||
$form['enabled_forms'][$id] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('@name comment form', array('@name' => $type->name)),
|
||||
'#default_value' => variable_get($id, 0),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add our own submit handler to clear honeypot's form cache on save.
|
||||
$form['#submit'][] = 'honeypot_admin_form_submit';
|
||||
|
||||
return system_settings_form($form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the admin form.
|
||||
*/
|
||||
function honeypot_admin_form_validate($form, &$form_state) {
|
||||
// Make sure the time limit is a positive integer or 0.
|
||||
$time_limit = $form_state['values']['honeypot_time_limit'];
|
||||
if ((is_numeric($time_limit) && $time_limit > 0) || $time_limit === '0') {
|
||||
if (ctype_digit($time_limit)) {
|
||||
// Good to go.
|
||||
}
|
||||
else {
|
||||
form_set_error('honeypot_time_limit', t("The time limit must be a positive integer or 0."));
|
||||
}
|
||||
}
|
||||
else {
|
||||
form_set_error('honeypot_time_limit', t("The time limit must be a positive integer or 0."));
|
||||
}
|
||||
|
||||
// Make sure Honeypot element name only contains A-Z, 0-9.
|
||||
if (!preg_match("/^[-_a-zA-Z0-9]+$/", $form_state['values']['honeypot_element_name'])) {
|
||||
form_set_error('honeypot_element_name', t("The element name cannot contain spaces or other special characters."));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the honeypot form cache on submit.
|
||||
*/
|
||||
function honeypot_admin_form_submit($form, &$form_state) {
|
||||
cache_clear_all('honeypot_protected_forms', 'cache');
|
||||
}
|
||||
101
sites/all/modules/contrib/form/honeypot/honeypot.api.php
Normal file
101
sites/all/modules/contrib/form/honeypot/honeypot.api.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* API Functionality for Honeypot module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup hooks
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Alter the honeypot protections added to a particular form.
|
||||
*
|
||||
* @param (array) $options
|
||||
* Protections that will be applied to the form. May be empty, or may include
|
||||
* 'honeypot' and/or 'time_restriction'.
|
||||
* @param (array) $form
|
||||
* The Form API form to which protections will be added.
|
||||
*/
|
||||
function hook_honeypot_form_protections_alter(&$options, $form) {
|
||||
// Add 'time_restriction' protection to 'mymodule-form' if it's not set.
|
||||
if ($form['form_id']['#value'] == 'mymodule_form' && !in_array('time_restriction', $options)) {
|
||||
$options[] = 'time_restriction';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* React to an addition of honeypot form protections for a given form_id.
|
||||
*
|
||||
* After honeypot has added its protections to a form, this hook will be called.
|
||||
* You can use this hook to track when and how many times certain protected
|
||||
* forms are displayed to certain users, or for other tracking purposes.
|
||||
*
|
||||
* @param (array) $options
|
||||
* Protections that were applied to the form. Includes 'honeypot' and/or
|
||||
* 'time_restriction'.
|
||||
* @param (array) $form
|
||||
* The Form API form to which protections were added.
|
||||
*/
|
||||
function hook_honeypot_add_form_protection($options, $form) {
|
||||
if ($form['form_id']['#value'] == 'mymodule_form') {
|
||||
// Do something...
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* React to the rejection of a form submission.
|
||||
*
|
||||
* When honeypot rejects a form submission, it calls this hook with the form ID,
|
||||
* the user ID (0 if anonymous) of the user that was disallowed from submitting
|
||||
* the form, and the reason (type) for the rejection of the form submission.
|
||||
*
|
||||
* @param (string) $form_id
|
||||
* Form ID of the form the user was disallowed from submitting.
|
||||
* @param (int) $uid
|
||||
* 0 for anonymous users, otherwise the user ID of the user.
|
||||
* @param (string) $type
|
||||
* String indicating the reason the submission was blocked. Allowed values:
|
||||
* - honeypot: If honeypot field was filled in.
|
||||
* - honeypot_time: If form was completed before the configured time limit.
|
||||
*/
|
||||
function hook_honeypot_reject($form_id, $uid, $type) {
|
||||
if ($form_id == 'mymodule_form') {
|
||||
// Do something...
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add time to the Honeypot time limit.
|
||||
*
|
||||
* In certain circumstances (for example, on forms routinely targeted by
|
||||
* spammers), you may want to add an additional time delay. You can use this
|
||||
* hook to return additional time (in seconds) to honeypot when it is calculates
|
||||
* the time limit for a particular form.
|
||||
*
|
||||
* @param (int) $honeypot_time_limit
|
||||
* The current honeypot time limit (in seconds), to which any additions you
|
||||
* return will be added.
|
||||
* @param (array) $form_values
|
||||
* Array of form values (may be empty).
|
||||
* @param (int) $number
|
||||
* Number of times the current user has already fallen into the honeypot trap.
|
||||
*
|
||||
* @return (int) $additions
|
||||
* Additional time to add to the honeypot_time_limit, in seconds (integer).
|
||||
*/
|
||||
function hook_honeypot_time_limit($honeypot_time_limit, $form_values, $number) {
|
||||
$additions = 0;
|
||||
// If 'some_interesting_value' is set in your form, add 10 seconds to limit.
|
||||
if (!empty($form_values['some_interesting_value']) && $form_values['some_interesting_value']) {
|
||||
$additions = 10;
|
||||
}
|
||||
return $additions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "addtogroup hooks".
|
||||
*/
|
||||
14
sites/all/modules/contrib/form/honeypot/honeypot.info
Normal file
14
sites/all/modules/contrib/form/honeypot/honeypot.info
Normal file
@@ -0,0 +1,14 @@
|
||||
name = Honeypot
|
||||
description = "Mitigates spam form submissions using the honeypot method."
|
||||
core = 7.x
|
||||
configure = admin/config/content/honeypot
|
||||
package = "Spam control"
|
||||
|
||||
files[] = honeypot.test
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-09-13
|
||||
version = "7.x-1.15"
|
||||
core = "7.x"
|
||||
project = "honeypot"
|
||||
datestamp = "1379087801"
|
||||
|
||||
132
sites/all/modules/contrib/form/honeypot/honeypot.install
Normal file
132
sites/all/modules/contrib/form/honeypot/honeypot.install
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Install, update and uninstall functions for the Honeypot module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements of hook_schema().
|
||||
*/
|
||||
function honeypot_schema() {
|
||||
$schema['honeypot_user'] = array(
|
||||
'description' => 'Table that stores failed attempts to submit a form.',
|
||||
'fields' => array(
|
||||
'uid' => array(
|
||||
'description' => 'Foreign key to {users}.uid; uniquely identifies a Drupal user to whom this ACL data applies.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'timestamp' => array(
|
||||
'description' => 'Date/time when the form submission failed, as Unix timestamp.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'uid' => array('uid'),
|
||||
'timestamp' => array('timestamp'),
|
||||
),
|
||||
);
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_install().
|
||||
*/
|
||||
function honeypot_install() {
|
||||
drupal_set_message(st("Honeypot installed successfully. Please !link to protect your forms from spam bots.", array(
|
||||
'!link' => l(st('configure Honeypot'), 'admin/config/content/honeypot')
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function honeypot_uninstall() {
|
||||
db_delete('variable')
|
||||
->condition('name', db_like('honeypot_') . '%', 'LIKE')
|
||||
->execute();
|
||||
$cache_tables = array('variables', 'cache_bootstrap');
|
||||
foreach ($cache_tables as $table) {
|
||||
if (db_table_exists($table)) {
|
||||
cache_clear_all($table, 'cache');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_update_N().
|
||||
*/
|
||||
function honeypot_update_7001() {
|
||||
$ret = array();
|
||||
|
||||
// Leaving this in because I had it in version 1.3. Silly me.
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update form names after upgrade from 6.x version.
|
||||
*/
|
||||
function honeypot_update_7002() {
|
||||
$map = array(
|
||||
'user_register' => 'user_register_form',
|
||||
'contact_mail_page' => 'contact_site_form',
|
||||
'contact_mail_user' => 'contact_personal_form',
|
||||
);
|
||||
foreach ($map as $d6_name => $d7_name) {
|
||||
$value = variable_get('honeypot_form_' . $d6_name, 0);
|
||||
if ($value) {
|
||||
variable_set('honeypot_form_' . $d7_name, $value);
|
||||
}
|
||||
variable_del('honeypot_form_' . $d6_name);
|
||||
}
|
||||
|
||||
$comment_form_value = variable_get('honeypot_form_comment_form', 0);
|
||||
if ($comment_form_value) {
|
||||
$types = node_type_get_types();
|
||||
if (!empty($types)) {
|
||||
foreach ($types as $type) {
|
||||
$d7_name = 'honeypot_form_comment_node_' . $type->type . '_form';
|
||||
variable_set($d7_name, $comment_form_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
variable_del('honeypot_form_comment_form');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add {honeypot_users} database table if it doesn't exist.
|
||||
*/
|
||||
function honeypot_update_7003() {
|
||||
// Make sure the {honeypot_users} table doesn't already exist.
|
||||
if (!db_table_exists('honeypot_user')) {
|
||||
$table = array(
|
||||
'description' => 'Table that stores failed attempts to submit a form.',
|
||||
'fields' => array(
|
||||
'uid' => array(
|
||||
'description' => 'Foreign key to {users}.uid; uniquely identifies a Drupal user to whom this ACL data applies.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'timestamp' => array(
|
||||
'description' => 'Date/time when the form submission failed, as Unix timestamp.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'uid' => array('uid'),
|
||||
'timestamp' => array('timestamp'),
|
||||
),
|
||||
);
|
||||
|
||||
db_create_table('honeypot_user', $table);
|
||||
}
|
||||
}
|
||||
312
sites/all/modules/contrib/form/honeypot/honeypot.module
Normal file
312
sites/all/modules/contrib/form/honeypot/honeypot.module
Normal file
@@ -0,0 +1,312 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Honeypot module, for deterring spam bots from completing Drupal forms.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function honeypot_menu() {
|
||||
$items['admin/config/content/honeypot'] = array(
|
||||
'title' => 'Honeypot configuration',
|
||||
'description' => 'Configure Honeypot spam prevention and the forms on which Honeypot will be used.',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('honeypot_admin_form'),
|
||||
'access arguments' => array('administer honeypot'),
|
||||
'file' => 'honeypot.admin.inc',
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
function honeypot_permission() {
|
||||
return array(
|
||||
'administer honeypot' => array(
|
||||
'title' => t('Administer Honeypot'),
|
||||
'description' => t('Administer Honeypot-protected forms and settings'),
|
||||
),
|
||||
'bypass honeypot protection' => array(
|
||||
'title' => t('Bypass Honeypot protection'),
|
||||
'description' => t('Bypass Honeypot form protection.'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements of hook_cron().
|
||||
*/
|
||||
function honeypot_cron() {
|
||||
// Delete {honeypot_user} entries older than the value of honeypot_expire.
|
||||
db_delete('honeypot_user')
|
||||
->condition('timestamp', time() - variable_get('honeypot_expire', 300), '<')
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*
|
||||
* Add Honeypot features to forms enabled in the Honeypot admin interface.
|
||||
*/
|
||||
function honeypot_form_alter(&$form, &$form_state, $form_id) {
|
||||
// Don't use for maintenance mode forms (install, update, etc.).
|
||||
if (defined('MAINTENANCE_MODE')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$unprotected_forms = array(
|
||||
'user_login',
|
||||
'user_login_block',
|
||||
'search_form',
|
||||
'search_block_form',
|
||||
'views_exposed_form',
|
||||
'honeypot_admin_form',
|
||||
);
|
||||
|
||||
// If configured to protect all forms, add protection to every form.
|
||||
if (variable_get('honeypot_protect_all_forms', 0) && !in_array($form_id, $unprotected_forms)) {
|
||||
// Don't protect system forms - only admins should have access, and system
|
||||
// forms may be programmatically submitted by drush and other modules.
|
||||
if (strpos($form_id, 'system_') === FALSE && strpos($form_id, 'search_') === FALSE && strpos($form_id, 'views_exposed_form_') === FALSE) {
|
||||
honeypot_add_form_protection($form, $form_state, array('honeypot', 'time_restriction'));
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise add form protection to admin-configured forms.
|
||||
elseif ($forms_to_protect = honeypot_get_protected_forms()) {
|
||||
foreach ($forms_to_protect as $protect_form_id) {
|
||||
// For most forms, do a straight check on the form ID.
|
||||
if ($form_id == $protect_form_id) {
|
||||
honeypot_add_form_protection($form, $form_state, array('honeypot', 'time_restriction'));
|
||||
}
|
||||
// For webforms use a special check for variable form ID.
|
||||
elseif ($protect_form_id == 'webforms' && (strpos($form_id, 'webform_client_form') !== FALSE)) {
|
||||
honeypot_add_form_protection($form, $form_state, array('honeypot', 'time_restriction'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an array of all the protected forms on the site, by form_id.
|
||||
*
|
||||
* @todo - Add in API call/hook to allow modules to add to this array.
|
||||
*/
|
||||
function honeypot_get_protected_forms() {
|
||||
$forms = &drupal_static(__FUNCTION__);
|
||||
|
||||
// If the data isn't already in memory, get from cache or look it up fresh.
|
||||
if (!isset($forms)) {
|
||||
if ($cache = cache_get('honeypot_protected_forms')) {
|
||||
$forms = $cache->data;
|
||||
}
|
||||
else {
|
||||
// Look up all the honeypot forms in the variables table.
|
||||
$result = db_query("SELECT name FROM {variable} WHERE name LIKE 'honeypot_form_%'")->fetchCol();
|
||||
// Add each form that's enabled to the $forms array.
|
||||
foreach ($result as $variable) {
|
||||
if (variable_get($variable, 0)) {
|
||||
$forms[] = substr($variable, 14);
|
||||
}
|
||||
}
|
||||
|
||||
// Save the cached data.
|
||||
cache_set('honeypot_protected_forms', $forms, 'cache');
|
||||
}
|
||||
}
|
||||
|
||||
return $forms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form builder function to add different types of protection to forms.
|
||||
*
|
||||
* @param $options (array)
|
||||
* Array of options to be added to form. Currently accepts 'honeypot' and
|
||||
* 'time_restriction'.
|
||||
*
|
||||
* @return $form_elements
|
||||
* Returns elements to be placed in a form's elements array to prevent spam.
|
||||
*/
|
||||
function honeypot_add_form_protection(&$form, &$form_state, $options = array()) {
|
||||
global $user;
|
||||
|
||||
// Allow other modules to alter the protections applied to this form.
|
||||
drupal_alter('honeypot_form_protections', $options, $form);
|
||||
|
||||
// Don't add any protections if the user can bypass the Honeypot.
|
||||
if (user_access('bypass honeypot protection')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Build the honeypot element.
|
||||
if (in_array('honeypot', $options)) {
|
||||
// Get the element name (default is generic 'url').
|
||||
$honeypot_element = variable_get('honeypot_element_name', 'url');
|
||||
|
||||
// Build the honeypot element.
|
||||
$honeypot_class = $honeypot_element . '-textfield';
|
||||
$form[$honeypot_element] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Leave this field blank'),
|
||||
'#size' => 20,
|
||||
'#weight' => 100,
|
||||
'#attributes' => array('autocomplete' => 'off'),
|
||||
'#element_validate' => array('_honeypot_honeypot_validate'),
|
||||
'#prefix' => '<div class="' . $honeypot_class . '">',
|
||||
'#suffix' => '</div>',
|
||||
'#attached' => array(
|
||||
'css' => array(
|
||||
'.' . $honeypot_class . ' { display: none !important; }' => array('type' => 'inline'), // Hide honeypot.
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Build the time restriction element (if it's not disabled).
|
||||
if (in_array('time_restriction', $options) && variable_get('honeypot_time_limit', 5) != 0) {
|
||||
// Set the current time in a hidden value to be checked later.
|
||||
$form['honeypot_time'] = array(
|
||||
'#type' => 'hidden',
|
||||
'#title' => t('Timestamp'),
|
||||
'#default_value' => time(),
|
||||
'#element_validate' => array('_honeypot_time_restriction_validate'),
|
||||
);
|
||||
|
||||
// Disable page caching to make sure timestamp isn't cached.
|
||||
if (user_is_anonymous()) {
|
||||
$GLOBALS['conf']['cache'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Allow other modules to react to addition of form protection.
|
||||
if (!empty($options)) {
|
||||
module_invoke_all('honeypot_add_form_protection', $options, $form);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate honeypot field.
|
||||
*/
|
||||
function _honeypot_honeypot_validate($element, &$form_state) {
|
||||
// Get the honeypot field value.
|
||||
$honeypot_value = $element['#value'];
|
||||
|
||||
// Make sure it's empty.
|
||||
if (!empty($honeypot_value)) {
|
||||
_honeypot_log($form_state['values']['form_id'], 'honeypot');
|
||||
form_set_error('', t('There was a problem with your form submission. Please refresh the page and try again.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate honeypot's time restriction field.
|
||||
*/
|
||||
function _honeypot_time_restriction_validate($form, &$form_state) {
|
||||
// Get the time value.
|
||||
$honeypot_time = $form_state['values']['honeypot_time'];
|
||||
|
||||
// Get the honeypot_time_limit.
|
||||
$time_limit = honeypot_get_time_limit($form_state['values']);
|
||||
|
||||
// Make sure current time - (time_limit + form time value) is greater than 0.
|
||||
// If not, throw an error.
|
||||
if (time() < ($honeypot_time + $time_limit)) {
|
||||
_honeypot_log($form_state['values']['form_id'], 'honeypot_time');
|
||||
$time_limit = honeypot_get_time_limit();
|
||||
$form_state['values']['honeypot_time'] = time();
|
||||
form_set_error('', t('There was a problem with your form submission. Please wait @limit seconds and try again.', array('@limit' => $time_limit)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log blocked form submissions.
|
||||
*
|
||||
* @param $form_id
|
||||
* Form ID for the form on which submission was blocked.
|
||||
* @param $type
|
||||
* String indicating the reason the submission was blocked. Allowed values:
|
||||
* - honeypot: If honeypot field was filled in.
|
||||
* - honeypot_time: If form was completed before the configured time limit.
|
||||
*/
|
||||
function _honeypot_log($form_id, $type) {
|
||||
honeypot_log_failure($form_id, $type);
|
||||
if (variable_get('honeypot_log', 0)) {
|
||||
$variables = array(
|
||||
'%form' => $form_id,
|
||||
'@cause' => ($type == 'honeypot') ? t('submission of a value in the honeypot field') : t('submission of the form in less than minimum required time'),
|
||||
);
|
||||
watchdog('honeypot', 'Blocked submission of %form due to @cause.', $variables);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up the time limit for the current user.
|
||||
*
|
||||
* @param $form_values
|
||||
* Array of form values (optional).
|
||||
*/
|
||||
function honeypot_get_time_limit($form_values = array()) {
|
||||
global $user;
|
||||
$honeypot_time_limit = variable_get('honeypot_time_limit', 5);
|
||||
|
||||
// Only calculate time limit if honeypot_time_limit has a value > 0.
|
||||
if ($honeypot_time_limit) {
|
||||
// Get value from {honeypot_user} table for authenticated users.
|
||||
if ($user->uid) {
|
||||
$number = db_query("SELECT COUNT(*) FROM {honeypot_user} WHERE uid = :uid", array(':uid' => $user->uid))->fetchField();
|
||||
}
|
||||
// Get value from {flood} table for anonymous users.
|
||||
else {
|
||||
$number = db_query("SELECT COUNT(*) FROM {flood} WHERE event = :event AND identifier = :hostname AND timestamp > :time", array(
|
||||
':event' => 'honeypot',
|
||||
':hostname' => ip_address(),
|
||||
':time' => time() - variable_get('honeypot_expire', 300),
|
||||
))->fetchField();
|
||||
}
|
||||
// Don't add more than 30 days' worth of extra time.
|
||||
$honeypot_time_limit = $honeypot_time_limit + (int) min($honeypot_time_limit + exp($number), 2592000);
|
||||
$additions = module_invoke_all('honeypot_time_limit', $honeypot_time_limit, $form_values, $number);
|
||||
if (count($additions)) {
|
||||
$honeypot_time_limit += array_sum($additions);
|
||||
}
|
||||
}
|
||||
return $honeypot_time_limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log the failed submision with timestamp.
|
||||
*
|
||||
* @param $form_id
|
||||
* Form ID for the rejected form submission.
|
||||
* @param $type
|
||||
* String indicating the reason the submission was blocked. Allowed values:
|
||||
* - honeypot: If honeypot field was filled in.
|
||||
* - honeypot_time: If form was completed before the configured time limit.
|
||||
*/
|
||||
function honeypot_log_failure($form_id, $type) {
|
||||
global $user;
|
||||
|
||||
// Log failed submissions for authenticated users.
|
||||
if ($user->uid) {
|
||||
db_insert('honeypot_user')
|
||||
->fields(array(
|
||||
'uid' => $user->uid,
|
||||
'timestamp' => time(),
|
||||
))
|
||||
->execute();
|
||||
}
|
||||
// Register flood event for anonymous users.
|
||||
else {
|
||||
flood_register_event('honeypot');
|
||||
}
|
||||
|
||||
// Allow other modules to react to honeypot rejections.
|
||||
module_invoke_all('honeypot_reject', $form_id, $user->uid, $type);
|
||||
}
|
||||
138
sites/all/modules/contrib/form/honeypot/honeypot.test
Normal file
138
sites/all/modules/contrib/form/honeypot/honeypot.test
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Testing for Honeypot module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test the functionality of the Honeypot module for an admin user.
|
||||
*/
|
||||
class HoneypotFormTestCase extends DrupalWebTestCase {
|
||||
protected $admin_user;
|
||||
protected $web_user;
|
||||
protected $node;
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Honeypot form protections',
|
||||
'description' => 'Ensure that Honeypot protects site forms properly.',
|
||||
'group' => 'Form API',
|
||||
);
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
// Enable modules required for this test.
|
||||
parent::setUp(array('honeypot', 'comment'));
|
||||
|
||||
// Set up required Honeypot variables.
|
||||
variable_set('honeypot_element_name', 'url');
|
||||
variable_set('honeypot_time_limit', 0); // Disable time_limit protection.
|
||||
variable_set('honeypot_protect_all_forms', TRUE); // Test protecting all forms.
|
||||
variable_set('honeypot_log', FALSE);
|
||||
|
||||
// Set up other required variables.
|
||||
variable_set('user_email_verification', TRUE);
|
||||
variable_set('user_register', USER_REGISTER_VISITORS);
|
||||
|
||||
// Set up admin user.
|
||||
$this->admin_user = $this->drupalCreateUser(array(
|
||||
'administer honeypot',
|
||||
'bypass honeypot protection',
|
||||
'administer content types',
|
||||
'administer users',
|
||||
'access comments',
|
||||
'post comments',
|
||||
'skip comment approval',
|
||||
'administer comments',
|
||||
));
|
||||
|
||||
// Set up web user.
|
||||
$this->web_user = $this->drupalCreateUser(array(
|
||||
'access comments',
|
||||
'post comments',
|
||||
'create article content',
|
||||
));
|
||||
|
||||
// Set up example node.
|
||||
$this->node = $this->drupalCreateNode(array(
|
||||
'type' => 'article',
|
||||
'promote' => 1,
|
||||
'uid' => $this->web_user->uid,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test user registration (anonymous users).
|
||||
*/
|
||||
public function testProtectRegisterUserNormal() {
|
||||
// Set up form and submit it.
|
||||
$edit['name'] = $this->randomName();
|
||||
$edit['mail'] = $edit['name'] . '@example.com';
|
||||
$this->drupalPost('user/register', $edit, t('Create new account'));
|
||||
|
||||
// Form should have been submitted successfully.
|
||||
$this->assertText(t('A welcome message with further instructions has been sent to your e-mail address.'), 'User registered successfully.');
|
||||
}
|
||||
|
||||
public function testProtectUserRegisterHoneypotFilled() {
|
||||
// Set up form and submit it.
|
||||
$edit['name'] = $this->randomName();
|
||||
$edit['mail'] = $edit['name'] . '@example.com';
|
||||
$edit['url'] = 'http://www.example.com/';
|
||||
$this->drupalPost('user/register', $edit, t('Create new account'));
|
||||
|
||||
// Form should have error message.
|
||||
$this->assertText(t('There was a problem with your form submission. Please refresh the page and try again.'), 'Registration form protected by honeypot.');
|
||||
}
|
||||
|
||||
public function testProtectRegisterUserTooFast() {
|
||||
// Enable time limit for honeypot.
|
||||
variable_set('honeypot_time_limit', 5);
|
||||
|
||||
// Set up form and submit it.
|
||||
$edit['name'] = $this->randomName();
|
||||
$edit['mail'] = $edit['name'] . '@example.com';
|
||||
$this->drupalPost('user/register', $edit, t('Create new account'));
|
||||
|
||||
// Form should have error message.
|
||||
$this->assertText(t('There was a problem with your form submission. Please wait'), 'Registration form protected by time limit.');
|
||||
}
|
||||
|
||||
public function testProtectCommentFormNormal() {
|
||||
$comment = 'Test comment.';
|
||||
|
||||
// Disable time limit for honeypot.
|
||||
variable_set('honeypot_time_limit', 0);
|
||||
|
||||
// Log in the web user.
|
||||
$this->drupalLogin($this->web_user);
|
||||
|
||||
// Set up form and submit it.
|
||||
$edit['comment_body[' . LANGUAGE_NONE . '][0][value]'] = $comment;
|
||||
$this->drupalPost('comment/reply/' . $this->node->nid, $edit, t('Save'));
|
||||
$this->assertText(t('Your comment has been posted.'), 'Comment posted successfully.');
|
||||
}
|
||||
|
||||
public function testProtectCommentFormHoneypotFilled() {
|
||||
$comment = 'Test comment.';
|
||||
|
||||
// Log in the web user.
|
||||
$this->drupalLogin($this->web_user);
|
||||
|
||||
// Set up form and submit it.
|
||||
$edit['comment_body[' . LANGUAGE_NONE . '][0][value]'] = $comment;
|
||||
$edit['url'] = 'http://www.example.com/';
|
||||
$this->drupalPost('comment/reply/' . $this->node->nid, $edit, t('Save'));
|
||||
$this->assertText(t('There was a problem with your form submission. Please refresh the page and try again.'), 'Comment posted successfully.');
|
||||
}
|
||||
|
||||
public function testProtectCommentFormHoneypotBypass() {
|
||||
// Log in the admin user.
|
||||
$this->drupalLogin($this->admin_user);
|
||||
|
||||
// Get the comment reply form and ensure there's no 'url' field.
|
||||
$this->drupalGet('comment/reply/' . $this->node->nid);
|
||||
$this->assertNoText('id="edit-url" name="url"', 'Honeypot home page field not shown.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user