Hi everyone

I have a lot of annoying spam in my guestbook. (guestbook.module)
How can I avoid this?

thanks
Casper

Comments

dersammy’s picture

Hi,
i had the same problem and just installed the BadBedhavior module http://drupal.org/node/30501 .
Since then, almost no spam was added to the guestbook. I also installed the spam module, but it seemed that the guestbook module didnt work with it.

Nevertheless since some weeks my guestbook is just a node with comments turned on.
And in the logs, i still see many requests to /guestbook, which now go to 404. So another idea would also be to edit the guestbook module in oder to have a path not as disambiguated like 'guestbook'.

greetings
dersammy

JumpingJack@drupalcenter.de’s picture

Hi,

i wrote a function which is looking for spam-words in the message text.

new function in guestbook.module (drupal 4.7)

/**
 * Search the message for spam-words
 */ 
function is_spam( $message ) {
	$retval = FALSE;
	$spamwords = array('viagra', 'cialis', 'tramadol', 'meridia', 'soma', 'ambre', 'xanax', 'rik.tag-host','instant-loans', 'levitra');
	
	foreach ($spamwords as $spam) {
	   if ( strpos(strtolower($message), strtolower($spam)) !== FALSE ) {
			$msgtext = t("Entry is spam: ") . $spam;
			drupal_set_message( $msgtext,'error' );
			watchdog('guestbook', $msgtext, WATCHDOG_WARNING);
			$retval = TRUE;
			break;
		}
	}
	return $retval;
}

the function is called before inserting the new message in the function guestbook_form_entry_submit after line 390 in guestbook.module

old-code

function guestbook_form_entry_submit($form_id, $edit) {
  global $user;
  
  $uid = $edit['uid'];
  $message = $edit['message'];

  // 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;
  }
  

insert new function call here after line 390

  //  are there spam-words in the message?
  if (is_spam( $message ) == TRUE ) {
	return;
  }

go ahead with old-code

  // 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()); 
    }
  }
  return 'guestbook/'. $uid;
}

i know it could be much user-friendly to insert/edit the spam-words. but its my first code in php and in drupal. and it protects my guestbook from spam very well.

ciao

jochen

nautis’s picture

Jochen -

This looks like a good temporary solution. Thanks.

- matthew | nautis.com

Azan’s picture

used it too, seems to work fine, thanks, nice idea.

JumpingJack@drupalcenter.de’s picture

I made an enhancement. Spam-Words can be added by taxonimie.
Create a vocabulary call it "spamwords" add the terms, that should be interpreted as spam-words.

/**
 * Search the message for spam-words
 */ 
function is_spam( $message ) {
	$retval = FALSE;
	$spamwords = array('viagra', 'cialis', 'tramadol', 'meridia', 'soma', 'ambre', 'xanax', 'instant-loans');
	
	//read spamwords from taxonomie "spamwords"
    $result = db_query('SELECT td.name FROM {term_data} td LEFT JOIN {vocabulary} v ON td.vid = v.vid  WHERE v.name = "spamwords"');
    while ($word = db_fetch_array($result)) {
      $spamwords[] = $word['name'];
    }
	$search_message  = strtolower( str_replace( ' ','', $message ) );		//replace blanks and makelower
	foreach ($spamwords as $spam) {
	   if ( strpos($search_message, strtolower($spam)) !== FALSE ) {
			$msgtext = t("Entry is spam: ") . $spam;
			drupal_set_message( $msgtext,'error' );
			watchdog('guestbook', $msgtext, WATCHDOG_WARNING);
			$retval = TRUE;
			break;
		}
	}
	return $retval;
}
profix898’s picture

You can also use the Captcha module. Simply add a captcha point for guestbooks.
In function captcha_settings (line 25+)

$captcha_points = array(
                      'comment_form' => t('Comment Form'),
                     ...
                      'node_form' => t('Create a node'),
                      'guestbook_form_entry' => t('Create Guestbook Entry'), //this adds captcha support to guestbook
                    );

JumpingJack@drupalcenter.de’s picture

I wrote 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.
See: http://drupal.org/node/66348

s20e6a14’s picture

hi,
for all users of drupal-5.1 which want to add captcha into the guestbook module:
file "captcha.module"

add in this command:

'guestbook_form_entry_form' => t('Write a guestbook entry'),

after:

'node_form' => t('Create a node'),

whole:

function captcha_admin_settings() {

  // This is where you can add more captcha points.
  $captcha_points = array(
    'comment_form' => t('Comment form'),
    'user_login' => t('User login form'),
    'user_login_block' => t('User login form block'),
    'user_edit' => t('User edit form'),
    'user_register' => t('User registration form'),
    'user_pass' => t('User forgot password form'),
    'contact_mail_user' => t('User contact form'),
    'contact_mail_page' => t('Sitewide contact form'),
    'node_form' => t('Create a node'),
    'guestbook_form_entry_form' => t('Write a guestbook entry'),
  );
Eleazar’s picture

Thanks! My guestbook has been a disaster!

gurukripa’s picture

i had problems in my guestbooks . hope this solves it..thanks for the solution

s20e6a14’s picture

hi,
does anybody know how to include captcha versoin 5.x-2.1 into the guestbook module?

my described solution only works with the previous versions!

thanks for your help!

floretan’s picture

The solution described only works if the 'captcha_points' variable hasn't been set (i.e. it is equal to NULL).

After making the changes to captcha.module, you need to reset 'captcha_points' in the database.

Vaid-XXL’s picture

Execute this SQL-Code to have the Guestbook Point in your Captcha Settings

INSERT INTO `captcha_points` ( `form_id` , `module` , `type` )
VALUES (
'guestbook_form_entry_form', NULL , NULL
);