hi,

i wrote a function to avoid guestbook from spam. the spam-words are hard-coded for the moment. this could be much better.
http://drupal.org/node/61054#comment-124898

is it interesting for someone else?

ciao

jochen

Comments

fholldorff’s picture

It's a nice temporary solution but isn't better to use the spam module and make the guestbook module to work with the spam module?

JumpingJack@drupalcenter.de’s picture

Here is a simple rudimentary integration of the spam-module 2.1.2 it's working fine for me with guestbook 4.7.0 on drupal 4.7.2.

There are just a few lines of code to insert in guestbook.module

In guestbook.module do:

after line 1 add the code to include spam.module:
include_once "modules/spam/spam.module";

at the end of guestbook.module before "?>" insert the following function:

function callback_spam($source, $id, $header, $body, $probability, $old, $action)
{
   if ($probability > 98 ) {
        $msgtext = t("Entry is spam: ") . $header . " " .$body  . " probability: " .$probability;
        watchdog('guestbook', $msgtext, WATCHDOG_WARNING ); 
        drupal_set_message( $msgtext,'error' );    
        return TRUE;
   }
   return FALSE;
}

after line 391 add the code to call spam-module to check the entry for spam, before inserting the entry

  //  Is this spam?
  $spamcheck = $edit['anonname'] .  " " . $edit['anonemail'] . " ".$edit['anonwebsite'] ; 
  if (spam_content_filter("guestbook", 1, $spamcheck, $message, callback_spam) == TRUE ) {
     return;
  }

the new code should look like:

  // Make sure this isn't a dupe
  $result = db_query("SELECT message FROM {guestbook} WHERE recipient = %d ORDER BY id DESC LIMIT 1", $uid);
  $entry = db_fetch_array($result);
  if ($entry["message"] == $message) {
    return;
  }
  
  //  Is this spam?
  $spamcheck = $edit['anonname'] .  " " . $edit['anonemail'] . " ".$edit['anonwebsite'] ; 
   if (spam_content_filter("guestbook", 1, $spamcheck, $message, callback_spam) == TRUE ) {
       return;
   }
	
  // Insert new message
  if (_guestbook_access('post', $uid) == 'allowed') {
    if ($user->uid == 0) {
      // anonymous user
      $entryid = db_next_id('{guestbook}_id');
      $result = db_query("INSERT INTO {guestbook} (id, anonname, anonemail, anonwebsite, author, recipient, message, created)
        VALUES('%d', '%s', '%s', '%s', '%d', '%d', '%s', '%d')", $entryid, $edit['anonname'], $edit['anonemail'], $edit['anonwebsite'], $user->uid, $uid, $message, time()); 
    }
    else if ($user->uid > 0) {
      // registered user
      $entryid = db_next_id('{guestbook}_id');
      $result = db_query("INSERT INTO {guestbook} (id,author,recipient,message,created)
        VALUES('%d', '%d', '%d', '%s', '%d')", $entryid, $user->uid, $uid, $message, time()); 
    }

ready!!!

majabee’s picture

I inserted this script into my guestbook / spam module exactly the way it was suggested but nothing happened , the spam filter still doesn´t filter the spam out of my guestbook. I created custom filters and url filters, but when i scan the filter always shows no matches even when i know that there is spam witch matches the filters. Or do I have to set something in the settings ? but there is no checkbox for filter guestbook entries? Please help i´m getting so much spam!!

JumpingJack@drupalcenter.de’s picture

Is your spam-module generally working? Is it working for example in comments?
Did you code everything correct? Try to filter everything as spam, by coding:

function callback_spam($source, $id, $header, $body, $probability, $old, $action)
{
$msgtext = t("Entry is spam: ") . $header . " " .$body . " probability: " .$probability;
watchdog('guestbook', $msgtext, WATCHDOG_WARNING );
drupal_set_message( $msgtext,'error' );
return TRUE;
}

Now every entry must be spam. If it isn't so, the integration of the spam-module is not correct.

The hack is working very well for me.
Good luck

ljjbrosens’s picture

I also have lots of problems with spam in my guestbook. I am not a pro but could my idea work?
All spam enters by linking automaticly to the name /?q=guestbook.
If users of guestbook.module were able to choose an own name for this module, different from "guestbook" than the spamrobots could not reconise the guestbook. In the menu of our sites we could use our own given name.
So, is it possible in the php code to give the link to the guestbook an other name unknown for spammers?
In that way we do not need a spamfilter at all.
Could this work?

Met vriendelijke groet,
Leo

ljjbrosens’s picture

It seems to work.
In the files " guestbook.install " and " guestbook.module " and " nl.po " I renamed all the strings " guest ", " GUEST ", " Guest " in a string by own choice. I also renamed the two files and the module directory in the same way.
After first deactivating and removing the old questbook module I copied the renamed version and all worked well.
Now I have a same guestbook functionallity but not with the easy to track guestbookname.
I hope spamrobots will not find me now.
?

Met vriendelijke groet,
Leo

hba’s picture

Version: 4.7.x-1.x-dev » 5.x-1.x-dev
Assigned: Unassigned » hba
Status: Active » Fixed

spam.module is integrated in 5.x

Anonymous’s picture

Status: Fixed » Closed (fixed)