spambot.admin.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?php
  2. /**
  3. * @file
  4. * Administration part (forms and pages) for Spambot module.
  5. */
  6. /**
  7. * Form builder for settings form.
  8. */
  9. function spambot_settings_form() {
  10. $numbers = array(
  11. 1 => 1,
  12. 2 => 2,
  13. 3 => 3,
  14. 4 => 4,
  15. 5 => 5,
  16. 6 => 6,
  17. 7 => 7,
  18. 8 => 8,
  19. 9 => 9,
  20. 10 => 10,
  21. 15 => 15,
  22. 20 => 20,
  23. 30 => 30,
  24. 40 => 40,
  25. 50 => 50,
  26. 60 => 60,
  27. 70 => 70,
  28. 80 => 80,
  29. 90 => 90,
  30. 100 => 100,
  31. 150 => 150,
  32. 200 => 200,
  33. );
  34. // Fieldset for set up spam criteria.
  35. $form['criteria'] = array(
  36. '#type' => 'fieldset',
  37. '#title' => t('Spammer criteria'),
  38. '#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.'),
  39. '#collapsible' => TRUE,
  40. '#collapsed' => TRUE,
  41. );
  42. $form['criteria']['spambot_criteria_email'] = array(
  43. '#type' => 'select',
  44. '#title' => t('Number of times the email has been reported is equal to or more than'),
  45. '#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.'),
  46. '#options' => array(0 => t("Don't use email as a criteria")) + $numbers,
  47. '#default_value' => variable_get('spambot_criteria_email', SPAMBOT_DEFAULT_CRITERIA_EMAIL),
  48. );
  49. $form['criteria']['spambot_criteria_username'] = array(
  50. '#type' => 'select',
  51. '#title' => t('Number of times the username has been reported is equal to or more than'),
  52. '#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.'),
  53. '#options' => array(0 => t("Don't use username as a criteria")) + $numbers,
  54. '#default_value' => variable_get('spambot_criteria_username', SPAMBOT_DEFAULT_CRITERIA_USERNAME),
  55. );
  56. $form['criteria']['spambot_criteria_ip'] = array(
  57. '#type' => 'select',
  58. '#title' => t('Number of times the IP address has been reported is equal to or more than'),
  59. '#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.'),
  60. '#options' => array(0 => t("Don't use IP address as a criteria")) + $numbers,
  61. '#default_value' => variable_get('spambot_criteria_ip', SPAMBOT_DEFAULT_CRITERIA_IP),
  62. );
  63. // White lists.
  64. $form['spambot_whitelist'] = array(
  65. '#type' => 'fieldset',
  66. '#title' => t('Whitelists'),
  67. '#collapsible' => TRUE,
  68. '#collapsed' => TRUE,
  69. );
  70. $form['spambot_whitelist']['spambot_whitelist_email'] = array(
  71. '#type' => 'textarea',
  72. '#title' => t('Allowed email addresses'),
  73. '#description' => t('Enter email addresses, one per line.'),
  74. '#default_value' => variable_get('spambot_whitelist_email', ''),
  75. );
  76. $form['spambot_whitelist']['spambot_whitelist_username'] = array(
  77. '#type' => 'textarea',
  78. '#title' => t('Allowed usernames'),
  79. '#description' => t('Enter usernames, one per line.'),
  80. '#default_value' => variable_get('spambot_whitelist_username', ''),
  81. );
  82. $form['spambot_whitelist']['spambot_whitelist_ip'] = array(
  83. '#type' => 'textarea',
  84. '#title' => t('Allowed IP addresses'),
  85. '#description' => t('Enter IP addresses, one per line.'),
  86. '#default_value' => variable_get('spambot_whitelist_ip', ''),
  87. );
  88. // Fieldset for configure protecting at user register form.
  89. $form['register'] = array(
  90. '#type' => 'fieldset',
  91. '#title' => t('User registration'),
  92. '#collapsible' => TRUE,
  93. '#collapsed' => TRUE,
  94. );
  95. $form['register']['spambot_user_register_protect'] = array(
  96. '#type' => 'checkbox',
  97. '#title' => t('Protect the user registration form'),
  98. '#description' => t('If ticked, new user registrations will be tested if they match any known spammers and blacklisted.'),
  99. '#default_value' => variable_get('spambot_user_register_protect', TRUE),
  100. );
  101. $sleep_options = array(t("Don't delay"), t('1 second'));
  102. foreach (array(2, 3, 4, 5, 10, 20, 30) as $num) {
  103. $sleep_options[$num] = t('@num seconds', array('@num' => $num));
  104. }
  105. $form['register']['spambot_blacklisted_delay'] = array(
  106. '#type' => 'select',
  107. '#title' => t('If blacklisted, delay for'),
  108. '#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.'),
  109. '#options' => $sleep_options,
  110. '#default_value' => variable_get('spambot_blacklisted_delay', SPAMBOT_DEFAULT_DELAY),
  111. );
  112. // Fieldset for set up scanning of existing accounts.
  113. $form['existing'] = array(
  114. '#type' => 'fieldset',
  115. '#title' => t('Scan existing accounts'),
  116. '#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."),
  117. '#collapsible' => TRUE,
  118. '#collapsed' => TRUE,
  119. );
  120. $form['existing']['spambot_cron_user_limit'] = array(
  121. '#type' => 'textfield',
  122. '#title' => t('Maximum number of user accounts to scan per cron'),
  123. '#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.'),
  124. '#size' => 10,
  125. '#default_value' => variable_get('spambot_cron_user_limit', SPAMBOT_DEFAULT_CRON_USER_LIMIT),
  126. );
  127. $form['existing']['spambot_check_blocked_accounts'] = array(
  128. '#type' => 'checkbox',
  129. '#title' => t('Scan blocked accounts'),
  130. '#description' => t('Tick this to scan blocked accounts. Otherwise blocked accounts are not scanned.'),
  131. '#default_value' => variable_get('spambot_check_blocked_accounts', FALSE),
  132. );
  133. $form['existing']['spambot_spam_account_action'] = array(
  134. '#type' => 'select',
  135. '#title' => t('Action to take'),
  136. '#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.'),
  137. '#options' => array(
  138. SPAMBOT_ACTION_NONE => t('None, just log it.'),
  139. SPAMBOT_ACTION_BLOCK => t('Block user account'),
  140. SPAMBOT_ACTION_DELETE => t('Delete user account'),
  141. ),
  142. '#default_value' => variable_get('spambot_spam_account_action', SPAMBOT_ACTION_NONE),
  143. );
  144. // Get scan status.
  145. $suffix = '';
  146. if ($last_uid = variable_get('spambot_last_checked_uid', 0)) {
  147. $num_checked = db_select('users', 'u')
  148. ->fields('u', array('uid'))
  149. ->condition('u.uid', 1, '>')
  150. ->condition('u.uid', $last_uid, '<=')
  151. ->countQuery()
  152. ->execute()
  153. ->fetchField();
  154. $num_left = db_select('users', 'u')
  155. ->fields('u', array('uid'))
  156. ->condition('u.uid', 1, '>')
  157. ->condition('u.uid', $last_uid, '>')
  158. ->countQuery()
  159. ->execute()
  160. ->fetchField();
  161. $last_uid = db_select('users', 'u')
  162. ->fields('u', array('uid'))
  163. ->condition('u.uid', 1, '>=')
  164. ->condition('u.uid', $last_uid, '<=')
  165. ->orderBy('u.uid', 'DESC')
  166. ->range(0, 1)
  167. ->execute()
  168. ->fetchField();
  169. $account = user_load($last_uid);
  170. $suffix = '<br />';
  171. $suffix .= t('The last checked user account is: !account (uid %uid)', array(
  172. '!account' => l($account->name, 'user/' . $account->uid),
  173. '%uid' => $account->uid,
  174. ));
  175. }
  176. else {
  177. $num_checked = 0;
  178. $num_left = db_select('users')
  179. ->fields('users')
  180. ->condition('uid', 1, '>')
  181. ->countQuery()
  182. ->execute()
  183. ->fetchField();
  184. }
  185. $text = t('Accounts checked: %checked, Accounts remaining: %remaining', array('%checked' => $num_checked, '%remaining' => $num_left));
  186. $form['existing']['message'] = array(
  187. '#type' => 'fieldset',
  188. '#title' => t('Scan status'),
  189. '#description' => $text . $suffix,
  190. );
  191. $form['existing']['spambot_last_checked_uid'] = array(
  192. '#type' => 'textfield',
  193. '#title' => t('Continue scanning after this user id'),
  194. '#size' => 10,
  195. '#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)),
  196. '#default_value' => $last_uid,
  197. );
  198. // Fieldset for set up messages which will be displayed for blocked users.
  199. $form['messages'] = array(
  200. '#type' => 'fieldset',
  201. '#title' => t('Blocked messages'),
  202. '#collapsible' => TRUE,
  203. '#collapsed' => TRUE,
  204. );
  205. $form['messages']['spambot_blocked_message_email'] = array(
  206. '#type' => 'textarea',
  207. '#title' => t('User registration blocked message (blocked email address)'),
  208. '#rows' => 1,
  209. '#default_value' => variable_get('spambot_blocked_message_email', SPAMBOT_DEFAULT_BLOCKED_MESSAGE),
  210. '#description' => t('Message to display when user action 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: <em>@email %email @username %username @ip %ip</em>'),
  211. );
  212. $form['messages']['spambot_blocked_message_username'] = array(
  213. '#type' => 'textarea',
  214. '#title' => t('User registration blocked message (blocked username)'),
  215. '#rows' => 1,
  216. '#default_value' => variable_get('spambot_blocked_message_username', SPAMBOT_DEFAULT_BLOCKED_MESSAGE),
  217. '#description' => t('Message to display when user action is blocked due to username.<br />The following tokens are available: <em>@email %email @username %username @ip %ip</em>'),
  218. );
  219. $form['messages']['spambot_blocked_message_ip'] = array(
  220. '#type' => 'textarea',
  221. '#title' => t('User registration blocked message (blocked ip address)'),
  222. '#rows' => 1,
  223. '#default_value' => variable_get('spambot_blocked_message_ip', SPAMBOT_DEFAULT_BLOCKED_MESSAGE),
  224. '#description' => t('Message to display when user action is blocked due to ip address.<br />The following tokens are available: <em>@email %email @username %username @ip %ip</em>'),
  225. );
  226. // Fieldset for configure log rules.
  227. $form['logging'] = array(
  228. '#type' => 'fieldset',
  229. '#title' => t('Log information'),
  230. '#collapsible' => TRUE,
  231. '#collapsed' => TRUE,
  232. );
  233. $form['logging']['spambot_log_blocked_registration'] = array(
  234. '#type' => 'checkbox',
  235. '#title' => t('Log information about blocked registrations into Drupal log'),
  236. '#default_value' => variable_get('spambot_log_blocked_registration', TRUE),
  237. );
  238. // StopFormSpam API key.
  239. $form['spambot_sfs_api_key'] = array(
  240. '#type' => 'textfield',
  241. '#title' => t('www.stopforumspam.com API key'),
  242. '#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.'),
  243. '#default_value' => variable_get('spambot_sfs_api_key', FALSE),
  244. );
  245. return system_settings_form($form);
  246. }