You are here

function _spambot_user_spam_admin_form_submit_check in Spambot 7

Do complex checking at this user account.

1 call to _spambot_user_spam_admin_form_submit_check()
spambot_user_spam_admin_form_submit in ./spambot.pages.inc
Submit handler for spambot_user_spam_admin_form() form.

File

./spambot.pages.inc, line 215
User available pages from Spambot module.

Code

function _spambot_user_spam_admin_form_submit_check(&$form, &$form_state, $account) {
  $messages = array();
  $service_down = FALSE;

  // Check email and username.
  $data = array();
  $request = array(
    'email' => $account->mail,
    'username' => $account->name,
  );
  if (spambot_sfs_request($request, $data)) {
    if (!empty($data['email']['appears'])) {
      $messages[] = array(
        'text' => 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'],
        )),
        'type' => 'warning',
      );
    }
    if (!empty($data['username']['appears'])) {
      $messages[] = array(
        'text' => 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'],
        )),
        'type' => 'warning',
      );
    }

    // Check data at whitelist.
    if (spambot_check_whitelist('email', $account->mail)) {
      $messages[] = array(
        'text' => t("This account's email address placed at your whitelist."),
        'type' => 'status',
      );
    }
    if (spambot_check_whitelist('username', $account->name)) {
      $messages[] = array(
        'text' => t("This account's username placed at your whitelist."),
        'type' => 'status',
      );
    }
  }
  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;
      }
      elseif (spambot_check_whitelist('ip', $ip)) {
        $whitelist_ips[] = $ip;
        continue;
      }
      elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6) === FALSE) {
        $messages[] = array(
          'text' => t('Invalid IP address: @ip. Spambot will not rely on it.', array(
            '@ip' => $ip,
          )),
          'type' => 'warning',
        );
        continue;
      }
      $request = array(
        'ip' => $ip,
      );
      $data = array();
      if (spambot_sfs_request($request, $data)) {
        if (!empty($data['ip']['appears'])) {
          $messages[] = array(
            'text' => 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'],
            )),
            'type' => 'warning',
          );
        }
      }
      else {
        drupal_set_message(t('Error contacting service.'), 'warning');
        break;
      }
    }
    if (!empty($whitelist_ips)) {
      $messages[] = array(
        'text' => t('These IP addresses placed at your whitelist: %ips', array(
          '%ips' => implode(', ', $whitelist_ips),
        )),
        'type' => 'status',
      );
    }
  }
  if ($messages) {
    foreach ($messages as $message) {
      drupal_set_message($message['text'], $message['type']);
    }
  }
  else {
    drupal_set_message(t('No matches against known spammers found.'));
  }
}