FINAL suepr merge step : added all modules to this super repos
This commit is contained in:
339
sites/all/modules/contrib/users/spambot/LICENSE.txt
Normal file
339
sites/all/modules/contrib/users/spambot/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.
|
159
sites/all/modules/contrib/users/spambot/spambot.admin.inc
Normal file
159
sites/all/modules/contrib/users/spambot/spambot.admin.inc
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
function spambot_settings_form($form, &$form_state) {
|
||||
$numbers = array(0 => t('Never'), 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 15 => 15, 20 => 20, 30 => 30, 40 => 40, 50 => 50, 60 => 60, 70 => 70, 80 => 80, 90 => 90, 100 => 100, 150 => 150, 200 => 200);
|
||||
|
||||
$form['criteria'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Spammer criteria'),
|
||||
'#description' => t('A user account or an attempted user registration will be deemed a spammer if the email, username, or IP address has been reported to www.stopforumspam.com more times than the following thresholds.'),
|
||||
'#collapsible' => TRUE,
|
||||
);
|
||||
$form['criteria']['spambot_criteria_email'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Number of times the email has been reported is equal to or more than'),
|
||||
'#description' => t('If the email address for a user or user registration has been reported to www.stopforumspam.com this many times, then it is deemed as a spammer.'),
|
||||
'#options' => array(0 => t('Don\'t use email as a criteria')) + $numbers,
|
||||
'#default_value' => variable_get('spambot_criteria_email', 1),
|
||||
);
|
||||
$form['criteria']['spambot_criteria_username'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Number of times the username has been reported is equal to or more than'),
|
||||
'#description' => t('If the username for a user or user registration has been reported to www.stopforumspam.com this many times, then it is deemed as a spammer. Be careful about using this option as you may accidentally block genuine users who happen to choose the same username as a known spammer.'),
|
||||
'#options' => array(0 => t('Don\'t use username as a criteria')) + $numbers,
|
||||
'#default_value' => variable_get('spambot_criteria_username', 0),
|
||||
);
|
||||
$form['criteria']['spambot_criteria_ip'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Number of times the IP address has been reported is equal to or more than'),
|
||||
'#description' => t('If the IP address for a user or user registration has been reported to www.stopforumspam.com this many times, then it is deemed as a spammer. Be careful about setting this threshold too low as IP addresses can change.'),
|
||||
'#options' => array(0 => t('Don\'t use IP address as a criteria')) + $numbers,
|
||||
'#default_value' => variable_get('spambot_criteria_ip', 20),
|
||||
);
|
||||
|
||||
$form['register'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('User registration'),
|
||||
'#collapsible' => TRUE,
|
||||
);
|
||||
$form['register']['spambot_user_register_protect'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Protect the user registration form'),
|
||||
'#description' => t('If ticked, new user registrations will be tested if they match any known spammers and blacklisted.'),
|
||||
'#default_value' => variable_get('spambot_user_register_protect', TRUE),
|
||||
);
|
||||
$form['register']['spambot_blocked_message_email'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('User registration blocked message (blocked email address)'),
|
||||
'#rows' => 1,
|
||||
'#default_value' => variable_get('spambot_blocked_message_email', t(SPAMBOT_DEFAULT_BLOCKED_MESSAGE)),
|
||||
'#description' => t('Message to display when user registration is blocked due to email address. <br />Showing a specific reason why registration was blocked may make spambot easier to circumvent.<br />The following tokens are available: @email %email @username %username @ip %ip'),
|
||||
);
|
||||
$form['register']['spambot_blocked_message_username'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('User registration blocked message (blocked username)'),
|
||||
'#rows' => 1,
|
||||
'#default_value' => variable_get('spambot_blocked_message_username', t(SPAMBOT_DEFAULT_BLOCKED_MESSAGE)),
|
||||
'#description' => t('Message to display when user registration is blocked due to username.'),
|
||||
);
|
||||
$form['register']['spambot_blocked_message_ip'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('User registration blocked message (blocked ip address)'),
|
||||
'#rows' => 1,
|
||||
'#default_value' => variable_get('spambot_blocked_message_ip', t(SPAMBOT_DEFAULT_BLOCKED_MESSAGE)),
|
||||
'#description' => t('Message to display when user registration is blocked due to ip address.'),
|
||||
);
|
||||
|
||||
$sleep_options = array(0 => t('Don\'t delay'), 1 => t('1 second'));
|
||||
foreach (array(2, 3, 4, 5, 10, 20, 30) as $num) {
|
||||
$sleep_options[$num] = t('@num seconds', array('@num' => $num));
|
||||
}
|
||||
$form['register']['spambot_blacklisted_delay'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('If blacklisted, delay for'),
|
||||
'#description' => t('If an attempted user registration is blacklisted, you can choose to deliberately delay the request. This can be useful for slowing them down if they continually try to register.<br />Be careful about choosing too large a value for this as it may exceed your PHP max_execution_time.'),
|
||||
'#options' => $sleep_options,
|
||||
'#default_value' => variable_get('spambot_blacklisted_delay', 0),
|
||||
);
|
||||
|
||||
$form['existing'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Scan existing accounts'),
|
||||
'#description' => t('This module can also scan existing user accounts to see if they are known spammers. It works by checking user accounts with increasing uid\'s ie. user id 2, 3, 4 etc during cron.'),
|
||||
'#collapsible' => TRUE,
|
||||
);
|
||||
$form['existing']['spambot_cron_user_limit'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Maximum number of user accounts to scan per cron'),
|
||||
'#description' => t('Enter the number of user accounts to scan for each cron. If you do not want to scan existing user accounts, leave this as 0.<br />Be careful not to make this value too large, as it will slow your cron execution down and may cause your site to query www.stopforumspam.com more times than allowed each day.'),
|
||||
'#size' => 10,
|
||||
'#default_value' => variable_get('spambot_cron_user_limit', 0),
|
||||
);
|
||||
$form['existing']['spambot_check_blocked_accounts'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Scan blocked accounts'),
|
||||
'#description' => t('Tick this to scan blocked accounts. Otherwise blocked accounts are not scanned.'),
|
||||
'#default_value' => variable_get('spambot_check_blocked_accounts', FALSE),
|
||||
);
|
||||
$form['existing']['spambot_spam_account_action'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Action to take'),
|
||||
'#description' => t('Please select what action to take for user accounts which are found to be spammers.<br />No action will be taken against accounts with the permission <em>protected from spambot scans</em> but they will be logged.'),
|
||||
'#options' => array(
|
||||
SPAMBOT_ACTION_NONE => t('None, just log it.'),
|
||||
SPAMBOT_ACTION_BLOCK => t('Block user account'),
|
||||
SPAMBOT_ACTION_DELETE => t('Delete user account'),
|
||||
),
|
||||
'#default_value' => variable_get('spambot_spam_account_action', SPAMBOT_ACTION_NONE),
|
||||
);
|
||||
|
||||
// Show scan status
|
||||
$last_uid = variable_get('spambot_last_checked_uid', 0);
|
||||
$suffix = '';
|
||||
if ($last_uid) {
|
||||
$num_checked = db_select('users')->fields('users')
|
||||
->condition('uid', '1', '>')->condition('uid', $last_uid, '<=')
|
||||
->countQuery()->execute()->fetchField();
|
||||
|
||||
$num_left = db_select('users')->fields('users')
|
||||
->condition('uid', '1', '>')->condition('uid', $last_uid, '>')
|
||||
->countQuery()->execute()->fetchField();
|
||||
|
||||
$last_uid = db_select('users')->fields('users', array('uid'))
|
||||
->condition('uid', '1', '>')->condition('uid', $last_uid, '<=')
|
||||
->orderBy('uid', 'DESC')->range(0, 1)
|
||||
->execute()->fetchField();
|
||||
|
||||
$account = user_load((int) $last_uid);
|
||||
$suffix = '<br />' . t('The last checked user account is: !account (uid @uid)', array('!account' => l(check_plain($account->name), 'user/' . $account->uid), '@uid' => $account->uid));
|
||||
}
|
||||
else {
|
||||
$num_checked = 0;
|
||||
$num_left = db_select('users')->fields('users')->condition('uid', 1, '>')
|
||||
->countQuery()->execute()->fetchField();
|
||||
}
|
||||
|
||||
$text = t('Accounts checked: @checked, Accounts remaining: @remaining', array('@checked' => $num_checked, '@remaining' => $num_left));
|
||||
$form['existing']['message'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Scan status'),
|
||||
'#description' => $text . $suffix,
|
||||
);
|
||||
|
||||
$form['existing']['spambot_last_checked_uid'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Continue scanning after this user id'),
|
||||
'#size' => 10,
|
||||
'#description' => t('Scanning of existing user accounts has progressed to, and including, user id @uid and will continue by scanning accounts after user id @uid. If you wish to change where the scan continues scanning from, enter a different user id here. If you wish to scan all users again, enter a value of 0.', array('@uid' => $last_uid)),
|
||||
'#default_value' => $last_uid,
|
||||
);
|
||||
|
||||
$form['spambot_sfs_api_key'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('www.stopforumspam.com API key'),
|
||||
'#description' => t('If you wish to report spammers to Stop Forum Spam, you need to register for an API key at the <a href="http://www.stopforumspam.com">Stop Forum Spam</a> website.'),
|
||||
'#default_value' => variable_get('spambot_sfs_api_key', FALSE),
|
||||
);
|
||||
|
||||
return system_settings_form($form);
|
||||
}
|
12
sites/all/modules/contrib/users/spambot/spambot.info
Normal file
12
sites/all/modules/contrib/users/spambot/spambot.info
Normal file
@@ -0,0 +1,12 @@
|
||||
name = Spambot
|
||||
description = Anti-spam module that uses data from www.stopforumspam.com to protect the user registration form against known spammers and spambots.
|
||||
package = "Spam control"
|
||||
configure = admin/config/system/spambot
|
||||
core = 7.x
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-01-11
|
||||
version = "7.x-1.3"
|
||||
core = "7.x"
|
||||
project = "spambot"
|
||||
datestamp = "1357872222"
|
||||
|
100
sites/all/modules/contrib/users/spambot/spambot.install
Normal file
100
sites/all/modules/contrib/users/spambot/spambot.install
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implementation of hook_schema().
|
||||
*/
|
||||
function spambot_schema() {
|
||||
$schema = array();
|
||||
$schema['node_spambot'] = array(
|
||||
'description' => t('Node table to track author IP addresses. For use by spambot only.'),
|
||||
'fields' => array(
|
||||
'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
||||
'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
||||
'hostname' => array( 'type' => 'varchar', 'length' => 128, 'not null' => FALSE),
|
||||
),
|
||||
'primary key' => array('nid'),
|
||||
'indexes' => array(
|
||||
'uid' => array('uid'),
|
||||
),
|
||||
);
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_uninstall().
|
||||
*/
|
||||
function spambot_uninstall() {
|
||||
db_query("DELETE FROM {variable} WHERE name LIKE 'spambot_%'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate settings from previous version of spambot (6.x-2.0)
|
||||
*/
|
||||
function spambot_update_6300() {
|
||||
$ret = array();
|
||||
|
||||
// In previous versions of spambot, the default message was 'Blacklisted. Now go away!'
|
||||
// If no custom message was configured, then configure it to 'Blacklisted. Now go away!'
|
||||
$message = variable_get('spambot_blocked_message', FALSE);
|
||||
if (!$message) {
|
||||
variable_set('spambot_blocked_message', t('Blacklisted. Now go away!'));
|
||||
}
|
||||
|
||||
// Previous versions of spambot blacklisted on any of the three criteria
|
||||
variable_set('spambot_criteria_email', TRUE);
|
||||
variable_set('spambot_criteria_username', TRUE);
|
||||
variable_set('spambot_criteria_ip', TRUE);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function spambot_update_6301() {
|
||||
$ret = array();
|
||||
// Change criteria settings from booleans to numbers
|
||||
if (variable_set('spambot_criteria_email', TRUE)) {
|
||||
variable_set('spambot_criteria_email', 1);
|
||||
}
|
||||
if (variable_set('spambot_criteria_username', FALSE)) {
|
||||
variable_set('spambot_criteria_username', 1);
|
||||
}
|
||||
if (variable_set('spambot_criteria_ip', FALSE)) {
|
||||
variable_set('spambot_criteria_ip', 1);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function spambot_update_7101() {
|
||||
$messages = array();
|
||||
|
||||
variable_del('spambot_user_register_report');
|
||||
$messages[] = t('Deleted variable <em>spambot_user_register_report.</em>');
|
||||
|
||||
$message = variable_get('spambot_blocked_message', FALSE);
|
||||
if ($message !== FALSE) {
|
||||
variable_set('spambot_blocked_message_email', $message);
|
||||
variable_set('spambot_blocked_message_username', $message);
|
||||
variable_set('spambot_blocked_message_ip', $message);
|
||||
variable_del('spambot_blocked_message');
|
||||
$messages[] = t('Transferred user registration blocked message to new format.');
|
||||
}
|
||||
|
||||
// Create new table node_spambot
|
||||
if (!db_table_exists('node_spambot')) {
|
||||
$schema = array();
|
||||
$schema['node_spambot'] = array(
|
||||
'description' => t('Node table to track author IP addresses. For use by spambot only.'),
|
||||
'fields' => array(
|
||||
'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
||||
'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
||||
'hostname' => array( 'type' => 'varchar', 'length' => 128, 'not null' => FALSE),
|
||||
),
|
||||
'primary key' => array('nid'),
|
||||
'indexes' => array(
|
||||
'uid' => array('uid'),
|
||||
),
|
||||
);
|
||||
db_create_table('node_spambot', $schema['node_spambot']);
|
||||
$messages[] = t('Created new table <em>node_spambot</em>.');
|
||||
}
|
||||
|
||||
return join('<br />', $messages);
|
||||
}
|
410
sites/all/modules/contrib/users/spambot/spambot.module
Normal file
410
sites/all/modules/contrib/users/spambot/spambot.module
Normal file
@@ -0,0 +1,410 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Anti-spam module that uses data from www.stopforumspam.com to protect the user registration form against known spammers and spambots.
|
||||
*
|
||||
*/
|
||||
|
||||
define('SPAMBOT_ACTION_NONE', 0);
|
||||
define('SPAMBOT_ACTION_BLOCK', 1);
|
||||
define('SPAMBOT_ACTION_DELETE', 2);
|
||||
|
||||
define('SPAMBOT_DEFAULT_BLOCKED_MESSAGE', 'Your email address or username or IP address is blacklisted.');
|
||||
|
||||
/**
|
||||
* Implements hook_permission()
|
||||
*/
|
||||
function spambot_permission() {
|
||||
return array(
|
||||
'protected from spambot scans' => array(
|
||||
'title' => t('Protected from spambot scans')
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function spambot_menu() {
|
||||
$items = array();
|
||||
$items['admin/config/system/spambot'] = array(
|
||||
'title' => 'Spambot',
|
||||
'description' => 'Configure the spambot module',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('spambot_settings_form'),
|
||||
'access arguments' => array('administer site configuration'),
|
||||
'file' => 'spambot.admin.inc',
|
||||
);
|
||||
|
||||
$items['user/%user/spambot'] = array(
|
||||
'title' => 'Spam',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('spambot_user_spam_admin_form', 1),
|
||||
'access arguments' => array('administer users'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'file' => 'spambot.pages.inc',
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_form_FORM_ID_alter()
|
||||
*/
|
||||
function spambot_form_user_register_form_alter(&$form, &$form_state, $form_id) {
|
||||
if (variable_get('spambot_user_register_protect', TRUE) && !user_access('administer users')) {
|
||||
$form['#validate'][] = 'spambot_user_register_validate';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the user_register form
|
||||
*/
|
||||
function spambot_user_register_validate($form, &$form_state) {
|
||||
$email_threshold = variable_get('spambot_criteria_email', 1);
|
||||
$username_threshold = variable_get('spambot_criteria_username', 0);
|
||||
$ip_threshold = variable_get('spambot_criteria_ip', 20);
|
||||
|
||||
// Build request parameters according to the criteria to use
|
||||
$request = array();
|
||||
if (!empty($form_state['values']['mail']) && $email_threshold > 0) {
|
||||
$request['email'] = $form_state['values']['mail'];
|
||||
}
|
||||
|
||||
if (!empty($form_state['values']['name']) && $username_threshold > 0) {
|
||||
$request['username'] = $form_state['values']['name'];
|
||||
}
|
||||
|
||||
if ($ip_threshold > 0) {
|
||||
$ip = ip_address();
|
||||
// Don't check the loopback interface
|
||||
if ($ip != '127.0.0.1') {
|
||||
$request['ip'] = $ip;
|
||||
}
|
||||
}
|
||||
|
||||
// Only do a remote API request if there is anything to check
|
||||
if (count($request)) {
|
||||
$data = array();
|
||||
if (spambot_sfs_request($request, $data)) {
|
||||
$substitutions = array(
|
||||
'@email' => $form_state['values']['mail'], '%email' => $form_state['values']['mail'],
|
||||
'@username' => $form_state['values']['name'], '%username' => $form_state['values']['name'],
|
||||
'@ip' => ip_address(), '%ip' => ip_address(),
|
||||
);
|
||||
|
||||
$reasons = array();
|
||||
if ($email_threshold > 0 && !empty($data['email']['appears']) && $data['email']['frequency'] >= $email_threshold) {
|
||||
form_set_error('mail', t(variable_get('spambot_blocked_message_email', t(SPAMBOT_DEFAULT_BLOCKED_MESSAGE)), $substitutions));
|
||||
$reasons[] = t('email=@value', array('@value' => $request['email']));
|
||||
}
|
||||
if ($username_threshold > 0 && !empty($data['username']['appears']) && $data['username']['frequency'] >= $username_threshold) {
|
||||
form_set_error('name', t(variable_get('spambot_blocked_message_username', t(SPAMBOT_DEFAULT_BLOCKED_MESSAGE)), $substitutions));
|
||||
$reasons[] = t('username=@value', array('@value' => $request['username']));
|
||||
}
|
||||
if ($ip_threshold > 0 && !empty($data['ip']['appears']) && $data['ip']['frequency'] >= $ip_threshold) {
|
||||
form_set_error('', t(variable_get('spambot_blocked_message_ip', t(SPAMBOT_DEFAULT_BLOCKED_MESSAGE)), $substitutions));
|
||||
$reasons[] = t('ip=@value', array('@value' => $request['ip']));
|
||||
}
|
||||
|
||||
if (count($reasons)) {
|
||||
watchdog('spambot', 'Blocked registration: @reasons', array('@reasons' => join(',', $reasons)));
|
||||
|
||||
// Slow them down if configured
|
||||
$delay = variable_get('spambot_blacklisted_delay', 0);
|
||||
if ($delay) {
|
||||
sleep($delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_node_insert
|
||||
*
|
||||
* Keeps table node_spambot up to date
|
||||
*/
|
||||
function spambot_node_insert($node) {
|
||||
db_insert('node_spambot')->fields(array('nid' => $node->nid, 'uid' => $node->uid, 'hostname' => ip_address()))->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_node_delete
|
||||
*
|
||||
* Keeps table node_spambot up to date
|
||||
*/
|
||||
function spambot_node_delete($node) {
|
||||
db_delete('node_spambot')->condition('nid', $node->nid)->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_cron
|
||||
*/
|
||||
function spambot_cron() {
|
||||
$limit = variable_get('spambot_cron_user_limit', 0);
|
||||
if ($limit) {
|
||||
$last_uid = variable_get('spambot_last_checked_uid', 0);
|
||||
if ($last_uid < 1) {
|
||||
// Skip scanning the first account
|
||||
$last_uid = 1;
|
||||
}
|
||||
|
||||
$uids = db_select('users')->fields('users', array('uid'))
|
||||
->condition('uid', $last_uid, '>')->orderBy('uid')
|
||||
->range(0, $limit)->execute()->fetchCol();
|
||||
|
||||
$action = variable_get('spambot_spam_account_action', SPAMBOT_ACTION_NONE);
|
||||
foreach ($uids as $uid) {
|
||||
$account = user_load($uid);
|
||||
|
||||
if ($account->status || variable_get('spambot_check_blocked_accounts', FALSE)) {
|
||||
$result = spambot_account_is_spammer($account);
|
||||
if ($result > 0) {
|
||||
$link = l(t('spammer'), 'user/' . $account->uid);
|
||||
switch (user_access('protected from spambot scans', $account) ? SPAMBOT_ACTION_NONE : $action) {
|
||||
case SPAMBOT_ACTION_BLOCK:
|
||||
if ($account->status) {
|
||||
user_save($account, array('status' => 0));
|
||||
watchdog('spambot', 'Blocked spam account: @name <@email> (uid @uid)', array('@name' => $account->name, '@email' => $account->mail, '@uid' => $account->uid), WATCHDOG_NOTICE, $link);
|
||||
}
|
||||
else {
|
||||
// Don't block an already blocked account
|
||||
watchdog('spambot', t('Spam account already blocked: @name <@email> (uid @uid)', array('@name' => $account->name, '@email' => $account->mail, '@uid' => $account->uid)), array(), WATCHDOG_NOTICE, $link);
|
||||
}
|
||||
break;
|
||||
|
||||
case SPAMBOT_ACTION_DELETE:
|
||||
user_delete($account->uid);
|
||||
watchdog('spambot', 'Deleted spam account: @name <@email> (uid @uid)', array('@name' => $account->name, '@email' => $account->mail, '@uid' => $account->uid), WATCHDOG_NOTICE, $link);
|
||||
break;
|
||||
|
||||
default:
|
||||
watchdog('spambot', 'Found spam account: @name <@email> (uid @uid)', array('@name' => $account->name, '@email' => $account->mail, '@uid' => $account->uid), WATCHDOG_NOTICE, $link);
|
||||
break;
|
||||
}
|
||||
// Mark this uid as successfully checked
|
||||
variable_set('spambot_last_checked_uid', $uid);
|
||||
}
|
||||
else if ($result == 0) {
|
||||
// Mark this uid as successfully checked
|
||||
variable_set('spambot_last_checked_uid', $uid);
|
||||
}
|
||||
else if ($result < 0) {
|
||||
// Error contacting service, so pause processing
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke www.stopforumspam.com's api
|
||||
*
|
||||
* @param $query
|
||||
* A keyed array of url parameters ie. array('email' => 'blah@blah.com')
|
||||
* @param $data
|
||||
* An array that will be filled with the data from www.stopforumspam.com.
|
||||
*
|
||||
* @return
|
||||
* TRUE on successful request (and $data will contain the data), FALSE if error
|
||||
*
|
||||
* $data should be an array of the following form:
|
||||
* Array
|
||||
* (
|
||||
* [success] => 1
|
||||
* [email] => Array
|
||||
* (
|
||||
* [lastseen] => 2010-01-10 08:41:26
|
||||
* [frequency] => 2
|
||||
* [appears] => 1
|
||||
* )
|
||||
*
|
||||
* [username] => Array
|
||||
* (
|
||||
* [frequency] => 0
|
||||
* [appears] => 0
|
||||
* )
|
||||
* )
|
||||
*
|
||||
*/
|
||||
function spambot_sfs_request($query, &$data) {
|
||||
// An empty request results in no match
|
||||
if (empty($query)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Use php serialisation format
|
||||
$query['f'] = 'serial';
|
||||
|
||||
$url = 'http://www.stopforumspam.com/api?' . http_build_query($query, '', '&');
|
||||
$result = drupal_http_request($url);
|
||||
if (!empty($result->code) && $result->code == 200 && empty($result->error) && !empty($result->data)) {
|
||||
$data = unserialize($result->data);
|
||||
if (!empty($data['success'])) {
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
watchdog('spambot', "Request unsuccessful: @url <pre>\n@dump</pre>", array('@url' => $url, '@dump' => print_r($data, TRUE)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
watchdog('spambot', "Error contacting service: @url <pre>\n@dump</pre>", array('@url' => $url, '@dump' => print_r($result, TRUE)));
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks an account to see if it's a spammer.
|
||||
* This one uses configurable automated criteria checking of email and username only
|
||||
*
|
||||
* @return
|
||||
* positive if spammer, 0 if not spammer, negative if error
|
||||
*/
|
||||
function spambot_account_is_spammer($account) {
|
||||
$email_threshold = variable_get('spambot_criteria_email', 1);
|
||||
$username_threshold = variable_get('spambot_criteria_username', 0);
|
||||
$ip_threshold = variable_get('spambot_criteria_ip', 20);
|
||||
|
||||
// Build request parameters according to the criteria to use
|
||||
$request = array();
|
||||
if (!empty($account->mail) && $email_threshold > 0) {
|
||||
$request['email'] = $account->mail;
|
||||
}
|
||||
|
||||
if (!empty($account->name) && $username_threshold > 0) {
|
||||
$request['username'] = $account->name;
|
||||
}
|
||||
|
||||
// Only do a remote API request if there is anything to check
|
||||
if (count($request)) {
|
||||
$data = array();
|
||||
if (spambot_sfs_request($request, $data)) {
|
||||
if (($email_threshold > 0 && !empty($data['email']['appears']) && $data['email']['frequency'] >= $email_threshold) ||
|
||||
($username_threshold > 0 && !empty($data['username']['appears']) && $data['username']['frequency'] >= $username_threshold)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Return error
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Now check IP's
|
||||
// If any IP matches the threshold, then flag as a spammer
|
||||
if ($ip_threshold > 0) {
|
||||
$ips = spambot_account_ip_addresses($account);
|
||||
foreach ($ips as $ip) {
|
||||
// Skip the loopback interface
|
||||
if ($ip == '127.0.0.1') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$request = array('ip' => $ip);
|
||||
$data = array();
|
||||
if (spambot_sfs_request($request, $data)) {
|
||||
if (!empty($data['ip']['appears']) && $data['ip']['frequency'] >= $ip_threshold) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Abort on error
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return no match
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a list of IP addresses for an account
|
||||
*
|
||||
* @param $account
|
||||
* Account to retrieve IP addresses for
|
||||
*
|
||||
* @return
|
||||
* An array of IP addresses, or an empty array if none found
|
||||
*/
|
||||
function spambot_account_ip_addresses($account) {
|
||||
$hostnames = array();
|
||||
|
||||
// Retrieve IPs from node_spambot table
|
||||
$items = db_select('node_spambot')->fields('node_spambot', array('hostname'))
|
||||
->condition('uid', $account->uid, '=')->distinct()->execute()->fetchCol();
|
||||
$hostnames = array_merge($hostnames, $items);
|
||||
|
||||
// Retrieve IPs from any sessions which may still exist
|
||||
$items = db_select('sessions')->fields('sessions', array('hostname'))
|
||||
->condition('uid', $account->uid, '=')->distinct()->execute()->fetchCol();
|
||||
$hostnames = array_merge($hostnames, $items);
|
||||
|
||||
// Retrieve IPs from comments
|
||||
if (module_exists('comment')) {
|
||||
$items = db_select('comment')->fields('comment', array('hostname'))
|
||||
->condition('uid', $account->uid, '=')->distinct()->execute()->fetchCol();
|
||||
$hostnames = array_merge($hostnames, $items);
|
||||
}
|
||||
|
||||
// Retrieve IPs from statistics
|
||||
if (module_exists('statistics')) {
|
||||
$items = db_select('accesslog')->fields('accesslog', array('hostname'))
|
||||
->condition('uid', $account->uid, '=')->distinct()->execute()->fetchCol();
|
||||
$hostnames = array_merge($hostnames, $items);
|
||||
}
|
||||
|
||||
// Retrieve IPs from user stats
|
||||
if (module_exists('user_stats')) {
|
||||
$items = db_select('user_stats_ips')->fields('user_stats_ips', array('ip_address'))
|
||||
->condition('uid', $account->uid, '=')->distinct()->execute()->fetchCol();
|
||||
$hostnames = array_merge($hostnames, $items);
|
||||
}
|
||||
|
||||
$hostnames = array_unique($hostnames);
|
||||
return $hostnames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports an account as a spammer. Requires ip address and evidence of a single incident
|
||||
*
|
||||
* @param $account
|
||||
* Account to report
|
||||
* @param $ip
|
||||
* IP address to report
|
||||
* @param $evidence
|
||||
* Evidence to report
|
||||
*
|
||||
* @return
|
||||
* TRUE if successful, FALSE if error
|
||||
*/
|
||||
function spambot_report_account($account, $ip, $evidence) {
|
||||
$success = FALSE;
|
||||
$key = variable_get('spambot_sfs_api_key', FALSE);
|
||||
|
||||
if ($key) {
|
||||
$query['api_key'] = $key;
|
||||
$query['email'] = $account->mail;
|
||||
$query['username'] = $account->name;
|
||||
$query['ip_addr'] = $ip;
|
||||
$query['evidence'] = $evidence;
|
||||
|
||||
$url = 'http://www.stopforumspam.com/add.php?' . http_build_query($query, '', '&');
|
||||
$result = drupal_http_request($url);
|
||||
if (!empty($result->code) && $result->code == 200 && !empty($result->data) && stripos($result->data, 'data submitted successfully') !== FALSE) {
|
||||
$success = TRUE;
|
||||
}
|
||||
else if (stripos($result->data, 'duplicate') !== FALSE) {
|
||||
// www.stopforumspam.com can return a 503 code with data = '<p>recent duplicate entry</p>'
|
||||
// which we will treat as successful.
|
||||
$success = TRUE;
|
||||
}
|
||||
else {
|
||||
watchdog('spambot', "Error reporting account: @url <pre>\n@dump</pre>", array('@url' => $url, '@dump' => print_r($result, TRUE)));
|
||||
}
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
264
sites/all/modules/contrib/users/spambot/spambot.pages.inc
Normal file
264
sites/all/modules/contrib/users/spambot/spambot.pages.inc
Normal file
@@ -0,0 +1,264 @@
|
||||
<?php
|
||||
|
||||
function spambot_user_spam_admin_form($form, &$form_state, $account) {
|
||||
$node_count = db_select('node')->condition('uid', $account->uid, '=')
|
||||
->countQuery()->execute()->fetchField();
|
||||
|
||||
if (module_exists('comment')) {
|
||||
$comment_count = db_select('comment')->condition('uid', $account->uid, '=')
|
||||
->countQuery()->execute()->fetchField();
|
||||
$status = t('This account has @n nodes and @c comments.', array('@n' => $node_count, '@c' => $comment_count));
|
||||
}
|
||||
else {
|
||||
$status = t('This account has @n nodes.', array('@n' => $node_count));
|
||||
}
|
||||
|
||||
$form['check'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Check if this account matches a known spammer'),
|
||||
);
|
||||
|
||||
$form['action'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Take action against this account'),
|
||||
'#collapsible' => TRUE,
|
||||
'#description' => $status,
|
||||
);
|
||||
$form['action']['unpublish_content'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Unpublish nodes and comments by this account'),
|
||||
'#default_value' => TRUE,
|
||||
);
|
||||
$form['action']['delete_content'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Delete nodes and comments by this account'),
|
||||
'#default_value' => FALSE,
|
||||
);
|
||||
|
||||
$form['action']['report'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Report this account to www.stopforumspam.com'),
|
||||
'#tree' => TRUE,
|
||||
'#collapsible' => TRUE,
|
||||
'#description' => t('An API key from <a href="http://www.stopforumspam.com">www.stopforumspam.com</a> is required to report spammers.<br />Select one or more posts below to report them to www.stopforumspam.com.'),
|
||||
);
|
||||
|
||||
// Fetch a list of reportable nodes
|
||||
$form['action']['report']['nids'] = array();
|
||||
$result = db_select('node_spambot')->fields('node_spambot', array('nid', 'hostname'))->condition('uid', $account->uid)->orderBy('nid', 'DESC')->range(0, 20)->execute();
|
||||
$nid_hostnames = array();
|
||||
foreach ($result as $record) {
|
||||
$nid_hostnames[$record->nid] = $record->hostname;
|
||||
}
|
||||
|
||||
foreach ($nid_hostnames as $nid => $hostname) {
|
||||
$node = node_load($nid);
|
||||
if (!empty($node->nid)) {
|
||||
$form['action']['report']['nids'][$nid] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => l(mb_strimwidth($node->title, 0, 128, '...'), 'node/' . $nid, array('attributes' => array('title' => mb_strimwidth($node->body['und'][0]['summary'] . "\n\n" . $node->body['und'][0]['value'], 0, 256, '...')))) . ' ' . t('(node, ip=@ip)', array('@ip' => $hostname)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch a list of reportable comments
|
||||
if (module_exists('comment')) {
|
||||
$form['action']['report']['cids'] = array();
|
||||
$result = db_select('comment')->fields('comment', array('cid'))->condition('uid', $account->uid)->orderBy('cid', 'DESC')->range(0, 20)->execute();
|
||||
$cids = array();
|
||||
foreach ($result as $record) {
|
||||
$cids[$record->cid] = $record->cid;
|
||||
}
|
||||
|
||||
foreach ($cids as $cid) {
|
||||
$comment = comment_load($cid);
|
||||
if (!empty($comment->cid)) {
|
||||
$form['action']['report']['cids'][$cid] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => l(mb_strimwidth($comment->subject, 0, 128, '...'), 'node/' . $comment->nid, array('fragment' => 'comment-'. $comment->cid, 'attributes' => array('title' => mb_strimwidth($comment->comment_body['und'][0]['value'], 0, 256, '...')))) . ' ' . t('(comment, ip=@ip)', array('@ip' => $comment->hostname)),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$form['action']['block_user'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Block this account'),
|
||||
'#default_value' => TRUE,
|
||||
);
|
||||
$form['action']['delete_user'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Delete this account'),
|
||||
'#default_value' => FALSE,
|
||||
);
|
||||
$form['action']['action'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Take action'),
|
||||
);
|
||||
$form['uid'] = array('#type' => 'value', '#value' => $account->uid);
|
||||
return $form;
|
||||
}
|
||||
|
||||
function spambot_user_spam_admin_form_validate($form, &$form_state) {
|
||||
$key_required = (!empty($form_state['values']['report']['nids']) && count(array_filter($form_state['values']['report']['nids']))) ? TRUE : FALSE;
|
||||
if (module_exists('comment')) {
|
||||
$key_required = (!empty($form_state['values']['report']['cids']) && count(array_filter($form_state['values']['report']['cids']))) || $key_required;
|
||||
}
|
||||
|
||||
if ($key_required && (!variable_get('spambot_sfs_api_key', FALSE))) {
|
||||
form_set_error('', t('To report spammers to www.stopforumspam.com, you need to register for an API key at <a href="http://www.stopforumspam.com">www.stopforumspam.com</a> and enter it into the !page.', array('!page' => l('spambot settings', 'admin/config/system/spambot'))));
|
||||
}
|
||||
}
|
||||
|
||||
function spambot_user_spam_admin_form_submit($form, &$form_state) {
|
||||
$account = user_load($form_state['values']['uid']);
|
||||
if ($form_state['values']['op'] == $form_state['values']['check']) {
|
||||
// This is a more comprehensive check than the automated criteria checks.
|
||||
// This tests everything.
|
||||
$messages = array();
|
||||
$service_down = FALSE;
|
||||
|
||||
// Check email and username
|
||||
$request = array('email' => $account->mail, 'username' => $account->name);
|
||||
$data = array();
|
||||
if (spambot_sfs_request($request, $data)) {
|
||||
if (!empty($data['email']['appears'])) {
|
||||
$messages[] = t('This account\'s email address matches @num times: !link', array('!link' => l($request['email'], 'http://www.stopforumspam.com/search?q=' . $request['email']), '@num' => $data['email']['frequency']));
|
||||
}
|
||||
|
||||
if (!empty($data['username']['appears'])) {
|
||||
$messages[] = t('This account\'s username matches @num times: !link', array('!link' => l($request['username'], 'http://www.stopforumspam.com/search?q=' . $request['username']), '@num' => $data['username']['frequency']));
|
||||
}
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('Error contacting service.'), 'warning');
|
||||
$service_down = TRUE;
|
||||
}
|
||||
|
||||
// Check IP addresses
|
||||
if (!$service_down) {
|
||||
$ips = spambot_account_ip_addresses($account);
|
||||
foreach ($ips as $ip) {
|
||||
// Skip the loopback interface
|
||||
if ($ip == '127.0.0.1') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$request = array('ip' => $ip);
|
||||
$data = array();
|
||||
if (spambot_sfs_request($request, $data)) {
|
||||
if (!empty($data['ip']['appears'])) {
|
||||
$messages[] = t('An IP address !ip used by this account matches @num times.', array('!ip' => l($ip, 'http://www.stopforumspam.com/search?q=' . $ip), '@num' => $data['ip']['frequency']));
|
||||
}
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('Error contacting service.'), 'warning');
|
||||
$service_down = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($messages)) {
|
||||
foreach ($messages as $message) {
|
||||
drupal_set_message($message);
|
||||
}
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('No matches against known spammers found.'));
|
||||
}
|
||||
}
|
||||
else if ($form_state['values']['op'] == $form_state['values']['action']) {
|
||||
if ($account->uid == 1) {
|
||||
drupal_set_message(t('Sorry, taking action against uid 1 is not allowed.'));
|
||||
return;
|
||||
}
|
||||
|
||||
// Block account
|
||||
if (!empty($form_state['values']['block_user'])) {
|
||||
if ($account->status) {
|
||||
user_save($account, array('status' => 0));
|
||||
drupal_set_message(t('Account blocked.'));
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('This account is already blocked.'));
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare some data
|
||||
$nodes = db_select('node')->fields('node', array('nid'))
|
||||
->condition('uid', $account->uid, '=')->orderBy('nid')->execute()->fetchCol();
|
||||
|
||||
$node_hostnames = array();
|
||||
$result = db_select('node_spambot')->fields('node_spambot', array('nid', 'hostname'))->condition('uid', $account->uid)->orderBy('nid', 'DESC')->execute();
|
||||
foreach ($result as $record) {
|
||||
$node_hostnames[$record->nid] = $record->hostname;
|
||||
}
|
||||
|
||||
$comments = array();
|
||||
if (module_exists('comment')) {
|
||||
$comments = db_select('comment')->fields('comment', array('cid'))
|
||||
->condition('uid', $account->uid, '=')->orderBy('cid')->execute()->fetchCol();
|
||||
}
|
||||
|
||||
// Report posts to www.stopforumspam.com
|
||||
if (!empty($form_state['values']['report']['nids'])) {
|
||||
foreach (array_filter($form_state['values']['report']['nids']) as $nid => $unused) {
|
||||
$node = node_load($nid);
|
||||
if (!empty($node->nid)) {
|
||||
if (spambot_report_account($account, $node_hostnames[$nid], $node->title . "\n\n" . $node->body['und'][0]['summary'] . "\n\n" . $node->body['und'][0]['value'])) {
|
||||
drupal_set_message(t('Node %title has been reported.', array('%title' => $node->title)));
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('There was a problem reporting node %title.', array('%title' => $node->title)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (module_exists('comment') && !empty($form_state['values']['report']['cids'])) {
|
||||
foreach (array_filter($form_state['values']['report']['cids']) as $cid => $unused) {
|
||||
$comment = comment_load($cid);
|
||||
if (!empty($comment->cid)) {
|
||||
if (spambot_report_account($account, $comment->hostname, $comment->subject . "\n\n" . $comment->comment_body['und'][0]['value'])) {
|
||||
drupal_set_message(t('Comment %title has been reported.', array('%title' => $comment->subject)));
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('There was a problem reporting comment %title.', array('%title' => $comment->subject)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete nodes and content
|
||||
if (!empty($form_state['values']['delete_content'])) {
|
||||
node_delete_multiple($nodes);
|
||||
|
||||
if (count($comments)) {
|
||||
comment_delete_multiple($comments);
|
||||
}
|
||||
|
||||
drupal_set_message(t('Nodes and comments have been deleted.'));
|
||||
}
|
||||
else if (!empty($form_state['values']['unpublish_content'])) {
|
||||
// Unpublish nodes and content
|
||||
if (count($nodes)) {
|
||||
module_load_include('inc', 'node', 'node.admin');
|
||||
node_mass_update($nodes, array('status' => 0));
|
||||
}
|
||||
|
||||
if (count($comments)) {
|
||||
db_update('comment')->fields(array('status' => COMMENT_NOT_PUBLISHED))
|
||||
->condition('uid', $account->uid)->execute();
|
||||
cache_clear_all();
|
||||
}
|
||||
drupal_set_message(t('Nodes and comments have been unpublished.'));
|
||||
}
|
||||
|
||||
// Delete user
|
||||
if (!empty($form_state['values']['delete_user'])) {
|
||||
// Redirect to user delete form
|
||||
$form_state['redirect'] = 'user/' . $account->uid . '/cancel';
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user