You are here

function spam_ip_filter in Spam 5

If blacklist is enabled, check to see if this is a known spammer IP. If it is, make them wait a while then redirect them to the main page with an indication that they're currently blacklisted.

Parameters

$source Source (comment, node, ...):

$id Unique identifier (cid, nid, ...):

$filtered Whether or not the data has already been run through the: spam filter. If it has, we increase $blacklist by one as we will also be counting the current content.

3 calls to spam_ip_filter()
spam_comment in ./spam.module
Drupal _comment hook. Passes new comments to the spam filter.
spam_content_filter in ./spam.module
Determine whether or not provided text is spam.
spam_nodeapi in ./spam.module
Drupal _nodeapi hook. Passes new node content through the spam filter.

File

./spam.module, line 132

Code

function spam_ip_filter($source, $id, $filtered = FALSE) {
  $blacklist = variable_get('spam_blacklist_ip', 2);
  if ($blacklist > -1) {
    $filtered ? $blacklist++ : '';
    $ip = db_fetch_object(db_query("SELECT count(sid) AS count FROM {spam_tracker} WHERE probability >= %d AND hostname = '%s'", variable_get('spam_threshold', 80), $_SERVER['REMOTE_ADDR']));
    if ($ip->count >= $blacklist) {
      spam_log(SPAM_VERBOSE, t('spam_ip_filter: blocked @hostname from posting content due to @num earlier spam postings.', array(
        '@hostname' => $_SERVER['REMOTE_ADDR'],
        '@num' => "{$ip->count}",
      )), $source, $id);

      // This IP address has been blacklisted but is continuing to attempt to
      // post content.  Some spammer scripts can pound your site so heavily as
      // to cause a DoS, so we will attempt to slow them down by sleeping for
      // 25 seconds before notifying them that their attempt has been denied.
      // Unfortunately, this delay can also have a negative impact on us by
      // tieing up a database connection.  We test to see if the drupal throttle
      // is enabled, and if it is we don't sleep as our own resources are
      // already being overly taxed.
      if (!module_invoke('throttle', 'status')) {
        sleep(variable_get('spam_ip_filter_sleep', 25));
      }
      drupal_set_message(t('Your IP address (@ip) was recently used to post spam to this website.  For this reason, you are currently not allowed to post new content.  If you believe this is in error, please contact the site administrator.', array(
        '@ip' => $_SERVER['REMOTE_ADDR'],
      )));
      drupal_access_denied();
      exit;
    }
  }
}