spambot.admin.inc 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. function spambot_settings_form($form, &$form_state) {
  3. $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);
  4. $form['criteria'] = array(
  5. '#type' => 'fieldset',
  6. '#title' => t('Spammer criteria'),
  7. '#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.'),
  8. '#collapsible' => TRUE,
  9. );
  10. $form['criteria']['spambot_criteria_email'] = array(
  11. '#type' => 'select',
  12. '#title' => t('Number of times the email has been reported is equal to or more than'),
  13. '#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.'),
  14. '#options' => array(0 => t('Don\'t use email as a criteria')) + $numbers,
  15. '#default_value' => variable_get('spambot_criteria_email', 1),
  16. );
  17. $form['criteria']['spambot_criteria_username'] = array(
  18. '#type' => 'select',
  19. '#title' => t('Number of times the username has been reported is equal to or more than'),
  20. '#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.'),
  21. '#options' => array(0 => t('Don\'t use username as a criteria')) + $numbers,
  22. '#default_value' => variable_get('spambot_criteria_username', 0),
  23. );
  24. $form['criteria']['spambot_criteria_ip'] = array(
  25. '#type' => 'select',
  26. '#title' => t('Number of times the IP address has been reported is equal to or more than'),
  27. '#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.'),
  28. '#options' => array(0 => t('Don\'t use IP address as a criteria')) + $numbers,
  29. '#default_value' => variable_get('spambot_criteria_ip', 20),
  30. );
  31. $form['register'] = array(
  32. '#type' => 'fieldset',
  33. '#title' => t('User registration'),
  34. '#collapsible' => TRUE,
  35. );
  36. $form['register']['spambot_user_register_protect'] = array(
  37. '#type' => 'checkbox',
  38. '#title' => t('Protect the user registration form'),
  39. '#description' => t('If ticked, new user registrations will be tested if they match any known spammers and blacklisted.'),
  40. '#default_value' => variable_get('spambot_user_register_protect', TRUE),
  41. );
  42. $form['register']['spambot_blocked_message_email'] = array(
  43. '#type' => 'textarea',
  44. '#title' => t('User registration blocked message (blocked email address)'),
  45. '#rows' => 1,
  46. '#default_value' => variable_get('spambot_blocked_message_email', t(SPAMBOT_DEFAULT_BLOCKED_MESSAGE)),
  47. '#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'),
  48. );
  49. $form['register']['spambot_blocked_message_username'] = array(
  50. '#type' => 'textarea',
  51. '#title' => t('User registration blocked message (blocked username)'),
  52. '#rows' => 1,
  53. '#default_value' => variable_get('spambot_blocked_message_username', t(SPAMBOT_DEFAULT_BLOCKED_MESSAGE)),
  54. '#description' => t('Message to display when user registration is blocked due to username.'),
  55. );
  56. $form['register']['spambot_blocked_message_ip'] = array(
  57. '#type' => 'textarea',
  58. '#title' => t('User registration blocked message (blocked ip address)'),
  59. '#rows' => 1,
  60. '#default_value' => variable_get('spambot_blocked_message_ip', t(SPAMBOT_DEFAULT_BLOCKED_MESSAGE)),
  61. '#description' => t('Message to display when user registration is blocked due to ip address.'),
  62. );
  63. $sleep_options = array(0 => t('Don\'t delay'), 1 => t('1 second'));
  64. foreach (array(2, 3, 4, 5, 10, 20, 30) as $num) {
  65. $sleep_options[$num] = t('@num seconds', array('@num' => $num));
  66. }
  67. $form['register']['spambot_blacklisted_delay'] = array(
  68. '#type' => 'select',
  69. '#title' => t('If blacklisted, delay for'),
  70. '#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.'),
  71. '#options' => $sleep_options,
  72. '#default_value' => variable_get('spambot_blacklisted_delay', 0),
  73. );
  74. $form['existing'] = array(
  75. '#type' => 'fieldset',
  76. '#title' => t('Scan existing accounts'),
  77. '#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.'),
  78. '#collapsible' => TRUE,
  79. );
  80. $form['existing']['spambot_cron_user_limit'] = array(
  81. '#type' => 'textfield',
  82. '#title' => t('Maximum number of user accounts to scan per cron'),
  83. '#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.'),
  84. '#size' => 10,
  85. '#default_value' => variable_get('spambot_cron_user_limit', 0),
  86. );
  87. $form['existing']['spambot_check_blocked_accounts'] = array(
  88. '#type' => 'checkbox',
  89. '#title' => t('Scan blocked accounts'),
  90. '#description' => t('Tick this to scan blocked accounts. Otherwise blocked accounts are not scanned.'),
  91. '#default_value' => variable_get('spambot_check_blocked_accounts', FALSE),
  92. );
  93. $form['existing']['spambot_spam_account_action'] = array(
  94. '#type' => 'select',
  95. '#title' => t('Action to take'),
  96. '#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.'),
  97. '#options' => array(
  98. SPAMBOT_ACTION_NONE => t('None, just log it.'),
  99. SPAMBOT_ACTION_BLOCK => t('Block user account'),
  100. SPAMBOT_ACTION_DELETE => t('Delete user account'),
  101. ),
  102. '#default_value' => variable_get('spambot_spam_account_action', SPAMBOT_ACTION_NONE),
  103. );
  104. // Show scan status
  105. $last_uid = variable_get('spambot_last_checked_uid', 0);
  106. $suffix = '';
  107. if ($last_uid) {
  108. $num_checked = db_select('users')->fields('users')
  109. ->condition('uid', '1', '>')->condition('uid', $last_uid, '<=')
  110. ->countQuery()->execute()->fetchField();
  111. $num_left = db_select('users')->fields('users')
  112. ->condition('uid', '1', '>')->condition('uid', $last_uid, '>')
  113. ->countQuery()->execute()->fetchField();
  114. $last_uid = db_select('users')->fields('users', array('uid'))
  115. ->condition('uid', '1', '>')->condition('uid', $last_uid, '<=')
  116. ->orderBy('uid', 'DESC')->range(0, 1)
  117. ->execute()->fetchField();
  118. $account = user_load((int) $last_uid);
  119. $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));
  120. }
  121. else {
  122. $num_checked = 0;
  123. $num_left = db_select('users')->fields('users')->condition('uid', 1, '>')
  124. ->countQuery()->execute()->fetchField();
  125. }
  126. $text = t('Accounts checked: @checked, Accounts remaining: @remaining', array('@checked' => $num_checked, '@remaining' => $num_left));
  127. $form['existing']['message'] = array(
  128. '#type' => 'fieldset',
  129. '#title' => t('Scan status'),
  130. '#description' => $text . $suffix,
  131. );
  132. $form['existing']['spambot_last_checked_uid'] = array(
  133. '#type' => 'textfield',
  134. '#title' => t('Continue scanning after this user id'),
  135. '#size' => 10,
  136. '#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)),
  137. '#default_value' => $last_uid,
  138. );
  139. $form['spambot_sfs_api_key'] = array(
  140. '#type' => 'textfield',
  141. '#title' => t('www.stopforumspam.com API key'),
  142. '#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.'),
  143. '#default_value' => variable_get('spambot_sfs_api_key', FALSE),
  144. );
  145. return system_settings_form($form);
  146. }