diff --git a/spambot.admin.inc b/spambot.admin.inc index cb311a9..c41a4e3 100644 --- a/spambot.admin.inc +++ b/spambot.admin.inc @@ -63,7 +63,26 @@ function spambot_settings_form($form, &$form_state) { '#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.'), ); - + + $form['contact'] = array( + '#type' => 'fieldset', + '#title' => t('Contact form'), + '#collapsible' => TRUE, + ); + $form['contact']['spambot_contact_site_protect'] = array( + '#type' => 'checkbox', + '#title' => t('Protect the contact site form'), + '#description' => t('If ticked, all feedbacks via the site contact from will be tested if they match any known spammers and blacklisted.'), + '#default_value' => variable_get('spambot_contact_site_protect', FALSE), + ); + $form['contact']['spambot_contact_site_protect_message'] = array( + '#type' => 'textarea', + '#title' => t('User registration blocked message (blocked email address)'), + '#description' => t('Message to display when feedback via the site contact from is blocked'), + '#default_value' => variable_get('spambot_contact_site_protect_message', t(SPAMBOT_CONTACT_FORM_DEFAULT_BLOCKED_MESSAGE)), + '#rows' => 1, + ); + $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)); diff --git a/spambot.module b/spambot.module index bb5054d..5b57de8 100644 --- a/spambot.module +++ b/spambot.module @@ -10,6 +10,7 @@ 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.'); +define('SPAMBOT_CONTACT_FORM_DEFAULT_BLOCKED_MESSAGE', 'You can\'t use the feedback form, because your IP address or email address is blacklisted.'); define('SPAMBOT_MAX_EVIDENCE_LENGTH', 1024); @@ -122,6 +123,45 @@ function spambot_user_register_validate($form, &$form_state) { } /** + * Implementation of hook_form_FORM_ID_alter() + */ +function spambot_form_contact_site_form_alter(&$form, &$form_state, $form_id) { + if (variable_get('spambot_contact_site_protect', FALSE)) { + $form['#validate'][] = 'spambot_contact_site_validate'; + } +} + +/** + * Validate the user_register form + */ +function spambot_contact_site_validate($form, &$form_state) { + $email_threshold = variable_get('spambot_criteria_email', 1); + $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 ($ip_threshold > 0) { + $ip = ip_address(); + // Don't check the loopback interface + if ($ip != '127.0.0.1') { + $request['ip'] = $ip; + } + } + + $data = array(); + if (spambot_sfs_request($request, $data)) { + if (($email_threshold > 0 && !empty($data['email']['appears']) && $data['email']['frequency'] >= $email_threshold) + || ($ip_threshold > 0 && !empty($data['ip']['appears']) && $data['ip']['frequency'] >= $ip_threshold)) { + + form_set_error('', t(variable_get('spambot_contact_site_protect_message', t(SPAMBOT_CONTACT_FORM_DEFAULT_BLOCKED_MESSAGE)))); + } + } +} + +/** * Implementation of hook_node_insert * * Keeps table node_spambot up to date