Bad Behavior - Version 2.2.0

Version Description

Download this release

Release Info

Developer error
Plugin Icon wp plugin Bad Behavior
Version 2.2.0
Comparing to
See all releases

Code changes from version 2.1.16 to 2.2.0

README.txt CHANGED
@@ -4,7 +4,7 @@ Contributors: error, markjaquith, skeltoac
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=error%40ioerror%2eus&item_name=Bad%20Behavior%20%28From%20WordPress%20Page%29&no_shipping=1&cn=Comments%20about%20Bad%20Behavior&tax=0&currency_code=USD&bn=PP%2dDonationsBF&charset=UTF%2d8
5
  Requires at least: 2.7
6
  Tested up to: 3.3.1
7
- Stable tag: 2.1.16
8
 
9
  Bad Behavior prevents spammers from ever delivering their junk, and in many
10
  cases, from ever reading your site in the first place.
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=error%40ioerror%2eus&item_name=Bad%20Behavior%20%28From%20WordPress%20Page%29&no_shipping=1&cn=Comments%20about%20Bad%20Behavior&tax=0&currency_code=USD&bn=PP%2dDonationsBF&charset=UTF%2d8
5
  Requires at least: 2.7
6
  Tested up to: 3.3.1
7
+ Stable tag: 2.2.0
8
 
9
  Bad Behavior prevents spammers from ever delivering their junk, and in many
10
  cases, from ever reading your site in the first place.
bad-behavior-generic.php CHANGED
@@ -96,6 +96,7 @@ function bb2_email() {
96
  function bb2_read_settings() {
97
  global $bb2_settings_defaults;
98
  $settings = @parse_ini_file(dirname(__FILE__) . "/settings.ini");
 
99
  return @array_merge($bb2_settings_defaults, $settings);
100
  }
101
 
96
  function bb2_read_settings() {
97
  global $bb2_settings_defaults;
98
  $settings = @parse_ini_file(dirname(__FILE__) . "/settings.ini");
99
+ if (!$settings) $settings = array();
100
  return @array_merge($bb2_settings_defaults, $settings);
101
  }
102
 
bad-behavior-mediawiki.php CHANGED
@@ -26,6 +26,8 @@ http://www.bad-behavior.ioerror.us/
26
 
27
  if (!defined('MEDIAWIKI')) die();
28
 
 
 
29
  // Settings you can adjust for Bad Behavior.
30
  // DO NOT EDIT HERE; instead make changes in settings.ini.
31
  // These settings are used when settings.ini is not present.
@@ -56,24 +58,31 @@ function bb2_db_date() {
56
 
57
  // Return affected rows from most recent query.
58
  function bb2_db_affected_rows($result) {
59
- return wfAffectedRows($result);
 
60
  }
61
 
62
  // Escape a string for database usage
63
  function bb2_db_escape($string) {
64
- // FIXME SECURITY: Get a straight answer from somebody on how MW escapes stuff
65
  return addslashes($string);
66
  }
67
 
68
  // Return the number of rows in a particular query.
69
  function bb2_db_num_rows($result) {
70
- return wfNumRows($result);
71
  }
72
 
73
  // Run a query and return the results, if any.
74
  // Should return FALSE if an error occurred.
75
  function bb2_db_query($query) {
76
- $bb2_last_query = wfQuery($query, DB_WRITE);
 
 
 
 
 
 
77
  return $bb2_last_query;
78
  }
79
 
@@ -82,8 +91,12 @@ function bb2_db_query($query) {
82
  // or equivalent and appending the result of each call to an array.
83
  function bb2_db_rows($result) {
84
  $rows = array();
85
- while ($row = wfFetchRow($result)) {
86
- $rows[] = $row;
 
 
 
 
87
  }
88
  return $rows;
89
  }
@@ -99,6 +112,7 @@ function bb2_email() {
99
  function bb2_read_settings() {
100
  global $bb2_settings_defaults;
101
  $settings = @parse_ini_file(dirname(__FILE__) . "/settings.ini");
 
102
  return @array_merge($bb2_settings_defaults, $settings);
103
  }
104
 
@@ -132,8 +146,10 @@ function bb2_relative_path() {
132
 
133
  // Cute timer display
134
  function bb2_mediawiki_timer(&$parser, &$text) {
135
- global $bb2_timer_total;
136
- $text = "<!-- Bad Behavior " . BB2_VERSION . " run time: " . number_format(1000 * $bb2_timer_total, 3) . " ms -->" . $text;
 
 
137
  return true;
138
  }
139
 
@@ -146,6 +162,11 @@ function bb2_mediawiki_entry() {
146
  if (php_sapi_name() != 'cli') {
147
  bb2_install(); // FIXME: see above
148
  $settings = bb2_read_settings();
 
 
 
 
 
149
  bb2_start($settings);
150
  }
151
 
@@ -160,8 +181,8 @@ $wgExtensionCredits['other'][] = array(
160
  'version' => BB2_VERSION,
161
  'author' => 'Michael Hampton',
162
  'description' => 'Detects and blocks unwanted Web accesses',
163
- 'url' => 'http://www.bad-behavior.ioerror.us/'
164
  );
165
 
166
- #$wgHooks['ParserAfterTidy'][] = 'bb2_mediawiki_timer';
167
  $wgExtensionFunctions[] = 'bb2_mediawiki_entry';
26
 
27
  if (!defined('MEDIAWIKI')) die();
28
 
29
+ $wgBadBehaviorTimer = true;
30
+
31
  // Settings you can adjust for Bad Behavior.
32
  // DO NOT EDIT HERE; instead make changes in settings.ini.
33
  // These settings are used when settings.ini is not present.
58
 
59
  // Return affected rows from most recent query.
60
  function bb2_db_affected_rows($result) {
61
+ $db = wfGetDB(DB_MASTER);
62
+ return $db->affectedRows();
63
  }
64
 
65
  // Escape a string for database usage
66
  function bb2_db_escape($string) {
67
+ // TODO SECURITY: Convert to using safeQuery()
68
  return addslashes($string);
69
  }
70
 
71
  // Return the number of rows in a particular query.
72
  function bb2_db_num_rows($result) {
73
+ return $result->numRows();
74
  }
75
 
76
  // Run a query and return the results, if any.
77
  // Should return FALSE if an error occurred.
78
  function bb2_db_query($query) {
79
+ $db = wfGetDB(DB_MASTER);
80
+ try {
81
+ $bb2_last_query = $db->query($query);
82
+ } catch (DBQueryError $e) {
83
+ trigger_error("Bad Behavior DBQueryError " . $e->getMessage(), E_USER_WARNING);
84
+ return false;
85
+ }
86
  return $bb2_last_query;
87
  }
88
 
91
  // or equivalent and appending the result of each call to an array.
92
  function bb2_db_rows($result) {
93
  $rows = array();
94
+ try {
95
+ while ($row = $result->fetchRow()) {
96
+ $rows[] = $row;
97
+ }
98
+ } catch (DBUnexpectedError $e) {
99
+ trigger_error("Bad Behavior DBUnexpectedError " . $e->getMessage(), E_USER_WARNING);
100
  }
101
  return $rows;
102
  }
112
  function bb2_read_settings() {
113
  global $bb2_settings_defaults;
114
  $settings = @parse_ini_file(dirname(__FILE__) . "/settings.ini");
115
+ if (!$settings) $settings = array();
116
  return @array_merge($bb2_settings_defaults, $settings);
117
  }
118
 
146
 
147
  // Cute timer display
148
  function bb2_mediawiki_timer(&$parser, &$text) {
149
+ global $bb2_timer_total, $wgBadBehaviorTimer;
150
+ if ($wgBadBehaviorTimer) {
151
+ $text .= "<!-- Bad Behavior " . BB2_VERSION . " run time: " . number_format(1000 * $bb2_timer_total, 3) . " ms -->";
152
+ }
153
  return true;
154
  }
155
 
162
  if (php_sapi_name() != 'cli') {
163
  bb2_install(); // FIXME: see above
164
  $settings = bb2_read_settings();
165
+ // FIXME: Need to make this multi-DB compatible eventually
166
+ $dbr = wfGetDB(DB_SLAVE);
167
+ if (get_class($dbr) != "DatabaseMysql") {
168
+ $settings['logging'] = false;
169
+ }
170
  bb2_start($settings);
171
  }
172
 
181
  'version' => BB2_VERSION,
182
  'author' => 'Michael Hampton',
183
  'description' => 'Detects and blocks unwanted Web accesses',
184
+ 'url' => 'http://bad-behavior.ioerror.us/'
185
  );
186
 
187
+ $wgHooks['ParserAfterTidy'][] = 'bb2_mediawiki_timer';
188
  $wgExtensionFunctions[] = 'bb2_mediawiki_entry';
bad-behavior-wordpress.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /*
3
  Plugin Name: Bad Behavior
4
- Version: 2.1.16
5
  Description: Deny automated spambots access to your PHP-based Web site.
6
  Plugin URI: http://www.bad-behavior.ioerror.us/
7
  Author: Michael Hampton
1
  <?php
2
  /*
3
  Plugin Name: Bad Behavior
4
+ Version: 2.2.0
5
  Description: Deny automated spambots access to your PHP-based Web site.
6
  Plugin URI: http://www.bad-behavior.ioerror.us/
7
  Author: Michael Hampton
bad-behavior/core.inc.php CHANGED
@@ -1,5 +1,5 @@
1
  <?php if (!defined('BB2_CWD')) die("I said no cheating!");
2
- define('BB2_VERSION', "2.1.16");
3
 
4
  // Bad Behavior entry point is bb2_start()
5
  // If you're reading this, you are probably lost.
1
  <?php if (!defined('BB2_CWD')) die("I said no cheating!");
2
+ define('BB2_VERSION', "2.2.0");
3
 
4
  // Bad Behavior entry point is bb2_start()
5
  // If you're reading this, you are probably lost.