Changeset 1266863
- Timestamp:
- 10/15/2015 08:12:23 PM (10 years ago)
- Location:
- botnet-blocker/trunk
- Files:
-
- 2 edited
-
botnet-blocker.php (modified) (5 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
botnet-blocker/trunk/botnet-blocker.php
r1258674 r1266863 5 5 Description: Free botnet IP blocker according to public DNSBL bases. Based on public DNSBL class. 6 6 Author: Dennis Wallace 7 Version: 1.2. 27 Version: 1.2.3 8 8 License: GPLv2 or later 9 9 */ … … 70 70 * Things that run during the WP plugins loaded action 71 71 */ 72 public function handle_p lugins_loaded() {72 public function handle_pre_get_posts( $query ) { 73 73 if ( $this->config->onload != 'on' ) { 74 74 // We only do this if the option is set 75 75 return; 76 76 } 77 78 if ( ! $query->is_main_query() ) { 79 return; 80 } 77 81 78 82 if ( $this->is_botnet() ) { 79 $this->block( );83 $this->block( 404, $query ); 80 84 } 81 85 } … … 98 102 99 103 add_action( 'init', array( &$this, 'handle_init' ) ); 100 add_action( 'p lugins_loaded', array( &$this, 'handle_plugins_loaded' ));104 add_action( 'pre_get_posts', array( &$this, 'handle_pre_get_posts' ), 0 ); 101 105 } 102 106 … … 225 229 /** 226 230 * This is called when a spammish IP is detected. 227 */ 228 public function block( $status = 404 ) { 231 * 232 * @param integer $status The status code to return. Default is 404. 233 * @param WP_Query $query The query object to set as a 404 result. Null uses the main global $wp_query object if possible. Default is null. 234 */ 235 public function block( $status = 404, $query = null ) { 229 236 // We've got a blacklisted IP. 404 it. 230 global $wp_query; 231 $wp_query->set_404(); 237 if( is_null( $query ) ) { 238 if( isset( $GLOBALS['wp_query'] ) ) { 239 $query = $GLOBALS['wp_query']; 240 } 241 } 242 if ( method_exists( $query, 'set_404' ) ) { 243 $query->set_404(); 244 } 232 245 status_header( $status ); 233 246 nocache_headers(); … … 243 256 */ 244 257 public function netmatch( $ip, $cidr ) { 245 if ( empty( $cidr ) ) {258 if ( empty( $cidr ) || empty( $ip ) ) { 246 259 return false; 247 260 } 248 261 249 262 $cidr .= '/32'; // Put the default mask in case one wasn't given. We ignore it if it's extra. 250 list ( $net, $mask, $extra ) = explode ( '/', $cidr ); 251 $mask = intval( $mask ); 252 $net = ip2long ($net) & ~((1 << (32 - $mask)) - 1); // Enforce the mask on the network too (just in case) 253 return ( ( ip2long ($ip) & ~((1 << (32 - $mask)) - 1) ) == $net ); 263 $parts = explode( '/', $cidr ); 264 $net = ip2long( $parts[0] ); 265 $mask = intval( $parts[1] ); 266 $mask = ( 1 << ( 32 - $mask ) ) - 1; 267 $net = $net & ~( $mask ); // Enforce the mask on the network too (just in case) 268 return ( ( ip2long( $ip ) & ~( $mask ) ) == $net ); 254 269 } 255 270 -
botnet-blocker/trunk/readme.txt
r1258674 r1266863 39 39 == Upgrade Notice == 40 40 41 = 1.2.3 = 42 No longer throws extra warnings; fixes error when using Block on Page Load 43 41 44 = 1.2.2 = 42 45 Added commenting in lists, now respects the Block on Page Load setting … … 56 59 57 60 == Changelog == 61 62 = 1.2.3 = 63 * Plugin_BNBlocker::netmatch no longer throws warnings when error level is high 64 * Reworked Plugin_BNBlocker::netmatch to reduce computation a bit 65 * Fixes error when using Block on Page Load 58 66 59 67 = 1.2.2 =
Note: See TracChangeset
for help on using the changeset viewer.