? .DS_Store
? COPYING
? badbehavior-2_5.patch
? badbehavior_5.patch
Index: badbehavior.info
===================================================================
RCS file: badbehavior.info
diff -N badbehavior.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ badbehavior.info	24 Dec 2006 18:06:14 -0000
@@ -0,0 +1,3 @@
+; $Id$
+name = Bad behavior
+description = Stop comment spam before it starts by trapping and blocking spambots before they have a chance to post comments.
Index: badbehavior.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/badbehavior/badbehavior.module,v
retrieving revision 1.10
diff -u -F^f -r1.10 badbehavior.module
--- badbehavior.module	13 Apr 2006 15:49:30 -0000	1.10
+++ badbehavior.module	24 Dec 2006 18:06:14 -0000
@@ -1,35 +1,10 @@
 <?php
 
-/*
-Module Name: Bad Behavior
-Version: 1.2.2
-Plugin URI: http://www.ioerror.us/software/bad-behavior/
-Description: Stop comment spam before it starts by trapping and blocking spambots before they have a chance to post comments.
-Author: Michael Hampton (Drupal module by David Angier)
-Author URI: http://www.ioerror.us/
-License: GPL
-
-Bad Behavior - detects and blocks unwanted Web accesses
-Copyright (C) 2005 Michael Hampton
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-This is beta software so please report any problems to
-badbots AT ioerror DOT us
-*/
+define('BB2_CWD', dirname(__FILE__));
 
+/**
+ * Implementation of hook_help().
+ */
 function badbehavior_help($section='') {
   $output = '';
   switch ($section) {
@@ -43,16 +18,20 @@ function badbehavior_help($section='') {
   return $output;
 }
 
-function badbehavior_db_errortrap($errno, $string) {
-}
-
+/**
+  * Implementation of hook_menu().
+  */
 function badbehavior_menu($may_cache) {
   $items = array();
 
   if ($may_cache) {
-    $items[] = array('path' => 'admin/logs/badbehavior', 'title' => t('bad behavior'),
+    $items[] = array('path' => 'admin/content/badbehavior', 'title' => t('Bad behavior'),
+      'description' => t('Configure automatic spam blocking for your site.'),
+      'callback' => 'drupal_get_form', 'callback arguments' => array('badbehavior_settings'), 'access' => user_access('administer bad behavior'));
+    $items[] = array('path' => 'admin/logs/badbehavior', 'title' => t('Bad behavior'),
+      'description' => t('Examine the spam blocking logs for your web site.'),
       'callback' => 'badbehavior_overview', 'access' => user_access('administer bad behavior'));
-    $items[] = array('path' => 'admin/logs/badbehavior/event', 'title' => t('details'),
+    $items[] = array('path' => 'admin/logs/badbehavior/event', 'title' => t('Details'),
       'callback' => 'badbehavior_event', 'access' => user_access('administer bad behavior'),
       'type' => MENU_CALLBACK);
   }
@@ -61,66 +40,72 @@ function badbehavior_menu($may_cache) {
 
 function badbehavior_overview() {
   $header = array(
+    array('data' => t('Response'), 'field' => 'w.http_response'),
     array('data' => t('Reason'), 'field' => 'w.denied_reason'),
     array('data' => t('Date'), 'field' => 'w.date', 'sort' => 'desc'),
     array('data' => t('IP'), 'field' => 'w.ip'),
-    array('data' => t('Referrer'), 'field' => 'w.http_referrer'),
-    array('data' => t('Agent'), 'field' => 'w.http_user_agent', 'colspan' => 2)
+    array('data' => t('Agent'), 'field' => 'w.user_agent', 'colspan' => 2)
   );
-  $sql = 'SELECT w.* FROM {bad_behavior_log} w ' . tablesort_sql($header);
+  if (variable_get('badbehavior_verbose_logging_enable',0)) {
+    $sql = 'SELECT w.* FROM {bad_behavior_log} w ' . tablesort_sql($header);
+  }
+  else {
+    $sql = "SELECT w.* FROM {bad_behavior_log} w WHERE w.key != '00000000' " . tablesort_sql($header);
+  }
   $result = pager_query($sql, 50);
 
+  require_once(BB2_CWD . '/bad-behavior/responses.inc.php');
+
   while ($behave = db_fetch_object($result)) {
-    $behave->localdate = bb_convertdate($behave->date);
+    $response = bb2_get_response($behave->key);
+    $behave->localdate = bb2_convertdate($behave->date);
     $rows[] = array('data' =>
       array(
         // Cells
-	$behave->denied_reason,
+	$response['response'],
+	$response['log'],
 	$behave->date,
 	$behave->ip,
-	$behave->http_referrer,
-	$behave->http_user_agent,
+	$behave->user_agent,
         l(t('details'), "admin/logs/badbehavior/event/$behave->id")
       )
     );
   }
 
   if (!$rows) {
-    $rows[] = array(array('data' => t('No log messages available.'), 'colspan' => '7'));
+    $rows[] = array(array('data' => t('No log messages available.'), 'colspan' => '6'));
   }
 
-  $pager = theme('pager', NULL, 50, 0);
-  if (!empty($pager)) {
-    $rows[] = array(array('data' => $pager, 'colspan' => '7'));
-  }
+  $output = theme('table', $header, $rows) . theme('pager', NULL, 50, 0);
 
-  $output = theme('table', $header, $rows);
-
-  print theme('page', $output);
+  return $output;
 }
 
 function badbehavior_event($id) {
   $output = '';
   $result = db_query('SELECT w.* FROM {bad_behavior_log} w WHERE w.id = %d', $id);
+
+  require_once(BB2_CWD . '/bad-behavior/responses.inc.php');
+
   if ($behave = db_fetch_object($result)) {
-    $behave->localdate = bb_convertdate($behave->date);
+    $response = bb2_get_response($behave->key);
+    $behave->localdate = bb2_convertdate($behave->date);
     $output .= '<table border="1" cellpadding="2" cellspacing="2">';
     $output .= ' <tr><th>'. t('IP Addr') .'</th><td>' . $behave->ip . '</td></tr>';
     $output .= ' <tr><th>'. t('Hostname') .'</th><td>' . gethostbyaddr($behave->ip) . ' (' . l('whois','http://www.whois.sc/'.$behave->ip) . ')</td></tr>';
     $output .= ' <tr><th>'. t('Date') .'</th><td>' . $behave->date . '</td></tr>';
     $output .= ' <tr><th>'. t('Request type') .'</th><td>' . $behave->request_method . '</td></tr>';
-    $output .= ' <tr><th>'. t('Host') .'</th><td>' . $behave->http_host . '</td></tr>';
     $output .= ' <tr><th>'. t('URI') .'</th><td>' . $behave->request_uri . '</td></tr>';
     $output .= ' <tr><th>'. t('Protocol') .'</th><td>' . $behave->server_protocol . '</td></tr>';
-    $output .= ' <tr><th>'. t('Referrer') .'</th><td>' . $behave->http_referer . '</td></tr>';
-    $output .= ' <tr><th>'. t('User Agent') .'</th><td>' . $behave->http_user_agent . '</td></tr>';
+    $output .= ' <tr><th>'. t('User Agent') .'</th><td>' . $behave->user_agent . '</td></tr>';
     $output .= ' <tr><th>'. t('Headers') .'</th><td>' . $behave->http_headers . '</td></tr>';
     $output .= ' <tr><th>'. t('Request Entity') .'</th><td>' . $behave->request_entity . '</td></tr>';
-    $output .= ' <tr><th>'. t('Denied Reason') .'</th><td>' . $behave->denied_reason . '</td></tr>';
-    $output .= ' <tr><th>'. t('Response') .'</th><td>' . $behave->http_response . '</td></tr>';
+    $output .= ' <tr><th>'. t('Denied Reason') .'</th><td>' . $response['log'] . '</td></tr>';
+    $output .= ' <tr><th>'. t('Explanation') .'</th><td>' . $response['explanation'] . '</td></tr>';
+    $output .= ' <tr><th>'. t('Response') .'</th><td>' . $response['response'] . '</td></tr>';
     $output .= '</table>';
   }
-  print theme('page', $output);
+  return $output;
 }
 
 function badbehavior_perm() {
@@ -129,100 +114,116 @@ function badbehavior_perm() {
 
 function badbehavior_settings() {
   $form['badbehavior_email'] = array(
-				     '#type' => 'textfield',
-				     '#title' => t('Administrator Email'),
-				     '#default_value' => variable_get('badbehavior_email','badbots@ioerror.us'),
-				     '#size' => 50,
-				     '#maxlength' => 50,
-				     '#description' => t('Administrator email address for blocked users to contact to gain access'),
-				     );
-  $form['log_settings'] = array(
-		  '#type' => 'fieldset',
-		  '#title' => t('Log Settings'),
-		  );
-
-  $form['log_settings']['badbehavior_logging_enable'] = array(
-					      '#type' => 'radios',
-					      '#title' => 'Enable Logging',
-					      '#default_value' => variable_get('bedbehavior_logging_enable',1),
-					      '#options' => array(t('Disabled'),t('Enabled')),
-					      '#description' => t('Enables or disables logging of spam activity'),
-					      );
-  
-  $form['log_settings']['badbehavior_verbose_logging_enable'] = array(
-						      '#type' => 'radios',
-						      '#title' => 'Enable Verbose Logging',
-						      '#default_value' => variable_get('badbehavior_verbose_logging_enable',0),
-						      '#options' => array(t('Disabled'),
-									  t('Enabled')),
-						      '#description' => t('Enables or disables verbose logging which includes all requests, not just failed ones '),
-						      );
-  
-  $form['log_settings']['badbehavior_logging_duration'] = array(
-						'#type' => 'textfield',
-						'#title' => t('Logging Duration'),
-						'#default_value' => variable_get('badbehavior_logging_duration',7),
-						'#size' => 6,
-						'#maxlength' => 6,
-						'#description' => t('Number of days to hold logs for'),
-						);
+    '#type' => 'textfield',
+    '#title' => t('Administrator Email'),
+    '#default_value' => variable_get('badbehavior_email','badbots@ioerror.us'),
+    '#size' => 50,
+    '#maxlength' => 50,
+    '#description' => t('Administrator email address for blocked users to contact to gain access'),
+  );
+  $form['badbehavior_strict_mode_enable'] = array(
+    '#type' => 'radios',
+    '#title' => 'Enable Strict Mode',
+    '#default_value' => variable_get('badbehavior_strict_mode_enable',0),
+    '#options' => array(t('Disabled'), t('Enabled')),
+    '#description' => t('Enable strict checking (blocks more spam but may block some people)'),
+  );
+  $form['badbehavior_verbose_logging_enable'] = array(
+    '#type' => 'radios',
+    '#title' => 'Enable Verbose Logging',
+    '#default_value' => variable_get('badbehavior_verbose_logging_enable',0),
+    '#options' => array(t('Disabled'), t('Enabled')),
+    '#description' => t('Enables or disables verbose logging which includes all requests, not just failed ones'),
+  );
   
-  return $form;
+  return system_settings_form($form);
 }
 
-function badbehavior_init() {
-  define('WP_BB_CWD', dirname(__FILE__));
+// Return current time in the format preferred by your database.
+function bb2_db_date() {
+  return gmdate('Y-m-d H:i:s');	// Example is MySQL format
+}
 
-  global $wp_bb_approved;
-  global $wp_bb_db_failure;
-  global $wp_bb_remote_addr;
-  global $wp_bb_request_method;
-  global $wp_bb_http_host;
-  global $wp_bb_request_uri;
-  global $wp_bb_server_protocol;
-  global $wp_bb_http_referer;
-  global $wp_bb_http_user_agent;
-  global $wp_bb_server_signature;
-  global $wp_bb_headers;
-  global $wp_bb_request_entity;
-  global $wp_bb_http_headers_mixed;
-  global $wp_bb_logging;
-  global $wp_bb_verbose_logging;
-  global $wp_bb_logging_duration;
-  global $wp_bb_email;
-  global $wp_bb_whitelist_ip_ranges;
-  global $wp_bb_whitelist_user_agents;
-
-  $wp_bb_logging          = variable_get('badbehavior_logging_enable', 1);
-  $wp_bb_verbose_logging  = variable_get('badbehavior_verbose_logging_enable', 0);
-  $wp_bb_logging_duration = variable_get('badbehavior_logging_duration', 7);
-  $wp_bb_email            = variable_get('badbehavior_email',"badbots@ioerror.us");
-
-  define('WP_BB_LOG', '{bad_behavior_log}');
-
-  if (file_exists(WP_BB_CWD . "/bad-behavior-core.php")) {
-    require_once(WP_BB_CWD . "/bad-behavior-core.php");
-  } else {
-    watchdog('badbehavior', t('The third-party bad-behavior files are not installed. Please consult badbehavior/README.txt for details.'), WATCHDOG_ERROR);
-  }
+// Return affected rows from most recent query.
+function bb2_db_affected_rows() {
+  return db_affected_rows();
 }
 
-function bb_convertdate($bbdate) {
-  $timestamp = strtotime($bbdate. ' UTC');
-  return format_date($timestamp,'small');
+// Escape a string for database usage
+function bb2_db_escape($string) {
+  return db_escape_string($string);
+}
+
+// Return the number of rows in a particular query.
+function bb2_db_num_rows($result) {
+  if ($result != FALSE)
+    return count($result);
+  return 0;
 }
 
-function wp_bb_date() {
-  return gmdate('Y-m-d H:i:s');
+function badbehavior_db_errortrap($errno, $string) {
 }
 
-function wp_bb_db_query($query) {
+// Run a query and return the results, if any.
+function bb2_db_query($query) {
   set_error_handler('badbehavior_db_errortrap');
   $result = db_query($query);
   restore_error_handler();
-  if ($result == FALSE) {
-    return $result;
-  }
+  if ($result == FALSE)
+    return FALSE;
   return db_affected_rows();
 }
-?>
\ No newline at end of file
+
+// Return all rows in a particular query.
+function bb2_db_rows($result) {
+  return $result;
+}
+
+// Return emergency contact email address.
+function bb2_email() {
+  return variable_get('badbehavior_email',"badbots@ioerror.us");
+}
+
+// write settings to database
+function bb2_write_settings($settings) {
+  return;
+}
+
+// retrieve settings from database
+function bb2_read_settings() {
+  return array(
+    'log_table' => 'bad_behavior_log',
+    'strict' => variable_get('badbehavior_strict_checking_enable', 0),
+    'verbose' => variable_get('badbehavior_verbose_logging_enable', 0));
+}
+
+// installation
+function bb2_install() {
+  if (variable_get('badbehavior_db_installed', 0) != BB2_VERSION) {
+    bb2_db_query(bb2_table_structure('bad_behavior_log'));
+    variable_set('badbehavior_db_installed', BB2_VERSION);
+  }
+}
+
+// Return the top-level relative path of wherever we are (for cookies)
+function bb2_relative_path() {
+  global $base_path;
+  return $base_path;
+}
+
+function badbehavior_init() {
+  if (file_exists(BB2_CWD . '/bad-behavior/core.inc.php') && file_exists(BB2_CWD . '/bad-behavior/version.inc.php')) {
+    require_once(BB2_CWD . '/bad-behavior/version.inc.php');
+    require_once(BB2_CWD . '/bad-behavior/core.inc.php');
+    bb2_install();
+    bb2_start(bb2_read_settings());
+  }
+  else {
+    watchdog('badbehavior', t('The third-party bad-behavior files are not installed. Please consult badbehavior/README.txt for details.'), WATCHDOG_ERROR);
+  }
+}
+
+function bb2_convertdate($bbdate) {
+  $timestamp = strtotime($bbdate. ' UTC');
+  return format_date($timestamp,'small');
+}
\ No newline at end of file
