5 Responses to Quickly killing manually submitted spam with Drupal

  1. Just a quick grammatical correction (and nothing Earth-shatteringly important), but “wasn’t for the feint of heart” should actually be “wasn’t for the faint of heart”. :p

  2. I think your reporting php code has some errors.
    see: “<pre>\n” . print_r($sfsdata, TRUE) . “</pre>\n”

    And could you please post the code for Drupal 6 too ?

    What this should doo :

    if (!empty($sfsdata['success'])) {
    return TRUE;

    Does nothing ( reports nothing.

    I saw that only if I have no argument option the code sends something, but then does not delete the comments, just the user. with thelast rule

    • Hi Zet, thanks for pointing out the encoding issue with the html tags. Must have been from the visual editor in WordPress or something messing with it. Should be fixed now.

      I can’t help you with a D6 implementation, as I haven’t used D6 for several years. It shouldn’t be too hard to adapt the above though.

      The code you’re asking about is checking if the unserialized result from StopForumSpam has data. If it does it exits the script, as everything worked as it was meant to (the user was reported to SFS). If it fails, a watchdog error is generated with more details.

      The solution outlined here only specifically targets and deletes nodes, not comments. If I’m not mistaken, comments are automatically deleted when a user is deleted — but it wasn’t something I specifically handled, as in my use-case, it wasn’t required. If comments aren’t being deleted, you might check your Drupal user settings for what happens when you delete a user. You could also create a VBO similar to the content_by_user one that gets all the comments of a spam user and deletes them.

  3. Sorry for not mentioning before I use drupal 6 and I try to delete all comments, not nodes, of the spam user, because I don’t allow regular user to post anything beside comments. As default I think comments are transfered to the Anonymous user if I delete just the spam user.

    But I see the code you have above contains some of the function spambot_sfs_request($query, &$data) from the spambot module, but that I think it’s incomplete, because there’s another function spambot_report_account($account, $ip, $evidence) that sends the data including the evidence (comment title & body) to the stopforumspan.com website. And your code does not send the evidence, thus does not allow to report more than once a user/ip pair, and actually I wanted to do that.

    function spambot_report_account($account, $ip, $evidence) {
    $success = FALSE;
    $key = variable_get(‘spambot_sfs_api_key’, FALSE);

    if ($key) {
    $query['api_key'] = $key;
    $query['email'] = $account->mail;
    $query['username'] = $account->name;
    $query['ip_addr'] = $ip;
    $query['evidence'] = $evidence;

    // Change to use http_build_query() once PHP 4.x can be dropped
    $params = array();
    foreach ($query as $key => $value) {
    $params[] = $key . ‘=’ . urlencode($value);
    }

    $url = ‘http://www.stopforumspam.com/add.php?’ . join(‘&’, $params);
    $result = drupal_http_request($url);
    if (!empty($result->code) && $result->code == 200 && !empty($result->data) && stripos($result->data, ‘data submitted successfully’) !== FALSE) {
    $success = TRUE;
    }
    else if (stripos($result->data, ‘duplicate’) !== FALSE) {
    // http://www.stopforumspam.com can return a 503 code with data = ‘recent duplicate entry’
    // which we will treat as successful.
    $success = TRUE;
    }
    else {
    watchdog(‘spambot’, t(“Error reporting account: @url \n@dump”, array(‘@url’ => $url, ‘@dump’ => print_r($result, TRUE))));
    }
    }

    return $success;
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>