Changeset 1249476
- Timestamp:
- 09/20/2015 05:10:09 AM (11 years ago)
- Location:
- botnet-blocker/trunk
- Files:
-
- 6 added
- 2 edited
-
botnet-blocker.php (modified) (11 diffs)
-
class.bnblocker-admin.php (added)
-
class.bnblocker-config.php (added)
-
class.settings-api.php (added)
-
languages (added)
-
languages/bnblocker-en_US.mo (added)
-
languages/bnblocker-en_US.po (added)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
botnet-blocker/trunk/botnet-blocker.php
r1249472 r1249476 5 5 Description: Free botnet IP blocker according to public DNSBL bases. Based on public DNSBL class. 6 6 Author: Dennis Wallace 7 Version: 0.2.07 Version: 1.0.0 8 8 License: GPLv2 or later 9 9 */ … … 25 25 */ 26 26 27 require_once( 'DNSBL.php' ); // see http://xbsoft.org/php/ 28 29 if ( ! class_exists( 'botnet_blocker' ) ) { 27 if ( ! class_exists( "DNSBL" ) ) { 28 include_once( 'DNSBL.php' ); // see http://xbsoft.org/php/ 29 } 30 31 if ( ! class_exists( 'BNBlocker_Config' ) ) { 32 include_once( 'class.bnblocker-config.php' ); 33 } 34 35 if ( ! class_exists( 'BNBlocker_Admin' ) ) { 36 include_once( 'class.bnblocker-admin.php' ); 37 } 38 39 40 if ( ! class_exists( 'Plugin_BNBlocker' ) ) { 30 41 /** 31 42 * Checks for a spammish IP at init time, and blocks/404s/handles it. 32 43 */ 33 class botnet_blocker { 34 /** 35 * The instance of a DNSBL object to use during lookups 36 */ 37 private $dnsbl = null; 38 39 /** 40 * An array of addresses to skip checking. Server address is included 41 * automatically at object construction time. 42 */ 43 public $skiplist = array( 44 '127.0.0.1', 45 46 // Sucuri incoming addresses 47 '192.88.134.6', 48 '192.88.135.6', 49 '185.93.228.6', 50 '185.93.229.6', 51 '185.93.230.6', 52 '192.88.134.0/23', 53 '185.93.228.0/22', 54 '192.124.249.0/24', 55 '199.223.236.179', 56 '146.148.117.213', 57 '23.251.134.134', 58 '178.33.238.180', 59 '142.4.217.0/24', 60 '167.114.0.0/24', 61 '192.99.17.0/24', 62 '5.196.79.0/24', 63 '130.211.0.0/16', 64 '104.155.0.0/16', 65 ); 66 67 /** 68 * An array of addresses that will be blocked if not on the whitelist. 69 * Use with care. 70 */ 71 public $blacklist = array( 72 ); 73 74 /** 75 * An array of addresses that will be granted access no matter what. 76 * Use with care - overrides blacklist and botnet membership checks. 77 */ 78 public $whitelist = array( 79 ); 44 class Plugin_BNBlocker { 45 /** 46 * Activate the plugin 47 */ 48 public static function activate() { 49 } 50 51 /** 52 * Deactivate the plugin 53 */ 54 public static function deactivate() { 55 } 56 57 /** 58 * Uninstall the plugin 59 */ 60 public static function uninstall() { 61 } 62 63 /** 64 * Things that run during the WP init action 65 */ 66 public function handle_init() { 67 load_plugin_textdomain( 'bnblocker', false, 'botnet-blocker/languages' ); 68 } 80 69 81 70 /** … … 83 72 */ 84 73 public function __construct() { 85 $this->dnsbl = new DNSBL(); 74 $this->config = new BNBlocker_Config(); 75 if ( isset( $_GET['debug'] ) ) { 76 header('X-BotnetBlocker-Debug-Mode: Debug Mode Enabled'); 77 $this->config->debug = 'on'; 78 } 79 86 80 87 81 // Add the current server address to the skiplist … … 89 83 $this->skiplist[] = $_SERVER['SERVER_ADDR']; 90 84 } 85 86 add_action( 'init', array( &$this, 'handle_init' ) ); 91 87 } 92 88 … … 99 95 $this->timer_start(); 100 96 101 $ips = array();97 $ips = ''; 102 98 if ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { 103 $ips = explode( ' ', str_replace(',', ' ', $_SERVER['HTTP_X_FORWARDED_FOR'] ) ); 104 } 105 $ips[] = $_SERVER['REMOTE_ADDR']; 99 $ips = $_SERVER['HTTP_X_FORWARDED_FOR']; 100 } 101 $ips .= "\n".$_SERVER['REMOTE_ADDR']; 102 $ips = $this->config->preplist( $ips ); 106 103 107 104 $result = false; … … 109 106 $blacklisted = false; 110 107 111 if ( isset( $_GET['botnetwhite'] ) ) { 112 if ( empty( $_GET['botnetwhite'] ) ) { 113 $this->whitelist[] = $_SERVER['REMOTE_ADDR']; 114 } else { 115 $this->whitelist[] = $_GET['botnetwhite']; 116 } 117 } 118 119 if ( isset( $_GET['botnetblack'] ) ) { 120 if ( empty( $_GET['botnetblack'] ) ) { 121 $this->blacklist[] = $_SERVER['REMOTE_ADDR']; 122 } else { 123 $this->blacklist[] = $_GET['botnetblack']; 124 } 125 } 126 127 if ( isset( $_GET['debug'] ) ) { 108 $skiplist = $this->config->skiplist(); 109 $blacklist = $this->config->blacklist(); 110 $whitelist = $this->config->whitelist(); 111 112 if ( $this->config->debug == 'on' ) { 128 113 header('X-BotnetBlocker-Debug-IPList: '.implode(';',$ips)); 129 114 header('X-BotnetBlocker-Debug-CurrentIP: '.$_SERVER['REMOTE_ADDR']); 130 header('X-BotnetBlocker-Debug-SkipList: '.implode(';',$ this->skiplist));131 header('X-BotnetBlocker-Debug-Whitelist: '.implode(';',$ this->whitelist));132 header('X-BotnetBlocker-Debug-Blacklist: '.implode(';',$ this->blacklist));115 header('X-BotnetBlocker-Debug-SkipList: '.implode(';',$skiplist)); 116 header('X-BotnetBlocker-Debug-Whitelist: '.implode(';',$whitelist)); 117 header('X-BotnetBlocker-Debug-Blacklist: '.implode(';',$blacklist)); 133 118 } 134 119 135 120 foreach ( $ips as $ip ) { 136 if ( ! empty( $ip ) ) { 137 if ( ! $this->netmatch_array( $ip, $this->skiplist ) ) { 138 if ( $this->netmatch_array( $ip, $this->whitelist ) ) { 139 $whitelisted = true; 140 } 121 if ( empty( $ip ) ) { 122 continue; 123 } 124 125 if ( $this->netmatch_array( $ip, $skiplist ) ) { 126 continue; 127 } 128 129 if ( $this->netmatch_array( $ip, $whitelist ) ) { 130 $whitelisted = true; 131 continue; 132 } 141 133 142 if ( $this->netmatch_array( $ip, $this->blacklist ) ) { 143 $blacklisted = true; 144 } 134 if ( $this->netmatch_array( $ip, $blacklist ) ) { 135 $blacklisted = true; 136 continue; 137 } 145 138 146 if ( ( $whitelisted || $blacklisted || $result ) == false) { 147 // Only check for botnet membership if we've not already decided 148 if ( $this->dnsbl->CheckSpamIP( $ip ) ) { 149 $result = true; 150 } 151 } 139 if ( ( $whitelisted || $blacklisted || $result ) == false) { 140 // Only check for botnet membership if we've not already decided 141 if ( $this->config->dnsbl->CheckSpamIP( $ip ) ) { 142 $result = true; 152 143 } 153 144 } … … 157 148 158 149 if ( $whitelisted ) { 159 if ( isset( $_GET['debug'] )) {150 if ( $this->config->debug == 'on' ) { 160 151 header('X-BotnetBlocker-Debug-Result: Whitelist'); 161 152 } … … 164 155 165 156 if ( $blacklisted ) { 166 if ( isset( $_GET['debug'] )) {157 if ( $this->config->debug == 'on' ) { 167 158 header('X-BotnetBlocker-Debug-Result: Blacklist'); 168 159 } … … 170 161 } 171 162 172 if ( isset( $_GET['debug'] )) {163 if ( $this->config->debug == 'on' ) { 173 164 header('X-BotnetBlocker-Debug-Result: ' . ( $result ? 'Bot' : 'OK' ) ); 174 165 } … … 199 190 list ( $net, $mask, $extra ) = explode ( '/', $cidr ); 200 191 $mask = intval( $mask ); 201 return ( ip2long ($ip) & ~((1 << (32 - $mask)) - 1) ) == ip2long ($net); 192 $net = ip2long ($net) & ~((1 << (32 - $mask)) - 1); // Enforce the mask on the network too (just in case) 193 return ( ( ip2long ($ip) & ~((1 << (32 - $mask)) - 1) ) == $net ); 202 194 } 203 195 … … 239 231 } 240 232 241 $BOTNETBLOCKER_OBJ = new botnet_blocker(); 233 if ( class_exists( 'Plugin_BNBlocker' ) && class_exists( 'BNBlocker_Admin' ) && function_exists( 'register_activation_hook' ) ) { 234 // Installation and uninstallation hooks 235 register_activation_hook(__FILE__, array('Plugin_BNBlocker', 'activate')); 236 register_deactivation_hook(__FILE__, array('Plugin_BNBlocker', 'deactivate')); 237 register_uninstall_hook(__FILE__, array('Plugin_BNBlocker', 'uninstall')); 238 239 // instantiate the plugin class 240 global $wp_plugin_bnblocker; 241 $wp_plugin_bnblocker = new Plugin_BNBlocker(); 242 $wp_plugin_bnblocker_admin = new BNBlocker_Admin(); 243 } -
botnet-blocker/trunk/readme.txt
r1249472 r1249476 4 4 Requires at least: -.-.- 5 5 Tested up to: 4.3.1 6 Stable tag: 0.2.06 Stable tag: 1.0.0 7 7 8 8 Botnet IP checker using public DNSBL bases and a hardcoded whitelist/blacklist. … … 21 21 ``` 22 22 <?php 23 global $ BOTNETBLOCKER_OBJ;24 if ( method_exists( $ BOTNETBLOCKER_OBJ, 'is_botnet' ) ) {25 if ( $ BOTNETBLOCKER_OBJ->is_botnet() ) {23 global $wp_plugin_bnblocker; 24 if ( method_exists( $wp_plugin_bnblocker, 'is_botnet' ) ) { 25 if ( $wp_plugin_bnblocker->is_botnet() ) { 26 26 /* bot detected, do something */ 27 27 } … … 55 55 Added timing checks for debugging speed issues 56 56 Added Sucuri network addresses to skip list 57 58 = 1.0.0 = 59 Complete refactor of the Plugin 60 Now has an admin section for modifying white/black/skip lists within the UI 61 Allows choosing which RBL in the UI 62 Revised logic to improve speed 63 Now uses CIDR-formatted netmasks for better maintenance 64 BREAKING CHANGE: Global object has been renamed from $BOTNETBLOCKER_OBJ to $wp_plugin_bnblocker
Note: See TracChangeset
for help on using the changeset viewer.