Changeset 13124
- Timestamp:
- 05/23/07 09:22:13 (1 year ago)
- Files:
-
- wp-ban/trunk/ban/ban-preview.php (added)
- wp-ban/trunk/ban/ban.php (modified) (17 diffs)
- wp-ban/trunk/readme.html (modified) (1 diff)
- wp-ban/trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
wp-ban/trunk/ban/ban.php
r13121 r13124 59 59 60 60 61 ### Function: Print Out Banned Message 62 function print_banned_message() { 63 // Credits To Joe (Ttech) - http://blog.fileville.net/ 64 $banned_stats = get_option('banned_stats'); 65 $banned_stats['count'] = (intval($banned_stats['count'])+1); 66 $banned_stats['users'][get_IP()] = intval($banned_stats['users'][get_IP()]+1); 67 update_option('banned_stats', $banned_stats); 68 $banned_message = stripslashes(get_option('banned_message')); 69 $banned_message = str_replace("%SITE_NAME%", get_option('blogname'), $banned_message); 70 $banned_message = str_replace("%SITE_URL%", get_option('siteurl'), $banned_message); 71 $banned_message = str_replace("%USER_ATTEMPTS_COUNT%", $banned_stats['users'][get_IP()], $banned_message); 72 $banned_message = str_replace("%USER_IP%", get_IP(), $banned_message); 73 $banned_message = str_replace("%USER_HOSTNAME%", @gethostbyaddr(get_IP()), $banned_message); 74 $banned_message = str_replace("%TOTAL_ATTEMPTS_COUNT%", $banned_stats['count'], $banned_message); 75 echo $banned_message; 76 exit(); 77 } 78 79 61 80 ### Function: Process Banning 62 81 function process_ban($banarray, $against) { … … 66 85 $regexp = str_replace ('*', '.+', $regexp); 67 86 if(ereg("^$regexp$", $against)) { 68 // Credits To Joe (Ttech) - http://blog.fileville.net/ 69 $banned_stats = get_option('banned_stats'); 70 $banned_stats['count'] = (intval($banned_stats['count'])+1); 71 $banned_stats['users'][get_IP()] = intval($banned_stats['users'][get_IP()]+1); 72 update_option('banned_stats', $banned_stats); 73 $banned_message = stripslashes(get_option('banned_message')); 74 $banned_message = str_replace("%SITE_NAME%", get_option('blogname'), $banned_message); 75 $banned_message = str_replace("%SITE_URL%", get_option('siteurl'), $banned_message); 76 $banned_message = str_replace("%USER_ATTEMPTS_COUNT%", $banned_stats['users'][get_IP()], $banned_message); 77 $banned_message = str_replace("%USER_IP%", get_IP(), $banned_message); 78 $banned_message = str_replace("%USER_HOSTNAME%", @gethostbyaddr(get_IP()), $banned_message); 79 $banned_message = str_replace("%TOTAL_ATTEMPTS_COUNT%", $banned_stats['count'], $banned_message); 80 echo $banned_message; 81 exit(); 87 print_banned_message(); 82 88 } 83 89 } 84 90 } 85 91 return; 92 } 93 94 95 ### Function: Process Banned IP Range 96 function process_ban_ip_range($banned_ips_range) { 97 if(!empty($banned_ips_range)) { 98 foreach($banned_ips_range as $banned_ip_range) { 99 $range = explode('-', $banned_ip_range); 100 $range_start = trim($range[0]); 101 $range_end = trim($range[1]); 102 if(check_ip_within_range(get_IP(), $range_start, $range_end)) { 103 print_banned_message(); 104 break; 105 } 106 } 107 } 86 108 } 87 109 … … 91 113 function banned() { 92 114 $banned_ips = get_option('banned_ips'); 115 $banned_ips_range = get_option('banned_ips_range'); 93 116 $banned_hosts = get_option('banned_hosts'); 94 117 $banned_referers = get_option('banned_referers'); … … 105 128 if(!$is_excluded) { 106 129 process_ban($banned_ips, get_IP()); 130 process_ban_ip_range($banned_ips_range); 107 131 process_ban($banned_hosts, @gethostbyaddr(get_IP())); 108 132 process_ban($banned_referers, $_SERVER['HTTP_REFERER']); … … 141 165 $update_ban_text = array(); 142 166 $banned_ips_post = explode("\n", trim($_POST['banned_ips'])); 167 $banned_ips_range_post = explode("\n", trim($_POST['banned_ips_range'])); 143 168 $banned_hosts_post = explode("\n", trim($_POST['banned_hosts'])); 144 169 $banned_referers_post = explode("\n", trim($_POST['banned_referers'])); … … 155 180 } 156 181 } 182 if(!empty($banned_ips_range_post)) { 183 $banned_ips_range = array(); 184 foreach($banned_ips_range_post as $banned_ip_range) { 185 $range = explode('-', $banned_ip_range); 186 $range_start = trim($range[0]); 187 $range_end = trim($range[1]); 188 if($admin_login == 'admin' && (check_ip_within_range(get_IP(), $range_start, $range_end))) { 189 $text .= '<font color="blue">'.sprintf(__('The Admin\'s IP \'%s\' Fall Within This Range (%s - %s) And Will Not Be Added To Ban List', 'wp-ban'), get_IP(), $range_start, $range_end).'</font><br />'; 190 } else { 191 $banned_ips_range[] = trim($banned_ip_range); 192 } 193 } 194 } 157 195 if(!empty($banned_hosts_post)) { 158 196 $banned_hosts = array(); … … 182 220 } 183 221 $update_ban_queries[] = update_option('banned_ips', $banned_ips); 222 $update_ban_queries[] = update_option('banned_ips_range', $banned_ips_range); 184 223 $update_ban_queries[] = update_option('banned_hosts', $banned_hosts); 185 224 $update_ban_queries[] = update_option('banned_referers', $banned_referers); … … 187 226 $update_ban_queries[] = update_option('banned_message', $banned_message); 188 227 $update_ban_text[] = __('Banned IPs', 'wp-ban'); 228 $update_ban_text[] = __('Banned IP Range', 'wp-ban'); 189 229 $update_ban_text[] = __('Banned Host Names', 'wp-ban'); 190 230 $update_ban_text[] = __('Banned Referers', 'wp-ban'); … … 204 244 // Get Banned IPs/Hosts 205 245 $banned_ips = get_option('banned_ips'); 246 $banned_ips_range = get_option('banned_ips_range'); 206 247 $banned_hosts = get_option('banned_hosts'); 207 248 $banned_referers = get_option('banned_referers'); 208 249 $banned_exclude_ips = get_option('banned_exclude_ips'); 209 250 $banned_ips_display = ''; 251 $banned_ips_range_display = ''; 210 252 $banned_hosts_display = ''; 211 253 $banned_referers_display = ''; … … 216 258 } 217 259 } 260 if(!empty($banned_ips_range)) { 261 foreach($banned_ips_range as $banned_ip_range) { 262 $banned_ips_range_display .= $banned_ip_range."\n"; 263 } 264 } 218 265 if(!empty($banned_hosts)) { 219 266 foreach($banned_hosts as $banned_host) { … … 232 279 } 233 280 $banned_ips_display = trim($banned_ips_display); 281 $banned_ips_range_display = trim($banned_ips_range_display); 234 282 $banned_hosts_display = trim($banned_hosts_display); 235 283 $banned_referers_display = trim($banned_referers_display); … … 265 313 } 266 314 } 315 function preview_bannedmessage() { 316 window.open('<?php echo get_option('siteurl').'/wp-content/plugins/ban/ban-preview.php'; ?>'); 317 } 267 318 /* ]]> */ 268 319 </script> … … 291 342 <td> 292 343 <textarea cols="40" rows="10" name="banned_ips"><?php echo $banned_ips_display; ?></textarea> 344 </td> 345 </tr> 346 <tr> 347 <td valign="top"> 348 <strong><?php _e('Banned IP Range', 'wp-ban'); ?>:</strong><br /> 349 <?php _e('Start each entry on a new line.', 'wp-ban'); ?><br /><br /> 350 <?php _e('Examples:', 'wp-ban'); ?><br /> 351 <strong>»</strong> 192.168.1.1-192.168.1.255<br /><br /> 352 <?php _e('Notes:', 'wp-ban'); ?><br /> 353 <strong>»</strong> <?php _e('No Wildcards Allowed.', 'wp-ban'); ?><br /> 354 </td> 355 <td> 356 <textarea cols="40" rows="10" name="banned_ips_range"><?php echo $banned_ips_range_display; ?></textarea> 293 357 </td> 294 358 </tr> … … 345 409 - %USER_HOSTNAME%<br /> 346 410 - %TOTAL_ATTEMPTS_COUNT%<br /><br /> 347 <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template', 'wp-ban'); ?>" onclick="javascript: banned_default_templates('message');" class="button" /> 411 <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template', 'wp-ban'); ?>" onclick="javascript: banned_default_templates('message');" class="button" /><br /><br /> 412 <input type="button" name="RestoreDefault" value="<?php _e('Preview Banned Message', 'wp-ban'); ?>" onclick="javascript: preview_bannedmessage();" class="button" /><br /> 348 413 </td> 349 414 <td> … … 414 479 415 480 481 ### Function: Check Whether IP Within A Given IP Range 482 function check_ip_within_range($ip, $range_start, $range_end) { 483 $range_start = ip2long($range_start); 484 $range_end = ip2long($range_end); 485 $ip = ip2long($ip); 486 if($ip >= $range_start && $ip <= $range_end) { 487 return true; 488 } 489 return false; 490 } 491 492 416 493 ### Function: Check Whether Or Not The Hostname Belongs To Admin 417 494 function is_admin_hostname($check) { … … 444 521 global $wpdb; 445 522 $banned_ips = array(); 523 $banned_ips_range = array(); 446 524 $banned_hosts = array(); 447 525 $banned_referers = array(); … … 464 542 add_option('banned_referers', $banned_referers, 'Banned Referers'); 465 543 add_option('banned_exclude_ips', $banned_exclude_ips, 'Banned Exclude IP'); 544 add_option('banned_ips_range', $banned_ips_range, 'Banned IP Range'); 466 545 } 467 546 ?> wp-ban/trunk/readme.html
r13121 r13124 240 240 <p> 241 241 <strong>Features:</strong><br /> 242 <strong>»</strong> Ban users by IP, host name and referer url from visiting your WordPress's blog. It will display a custom ban message when the banned IP, host name or referer url trys to visit you blog. You can also exclude certain IPs from being banned. There will be statistics recordered on how many times they attemp to visit your blog. It allows wildcard matching too.242 <strong>»</strong> Ban users by IP, IP Range, host name and referer url from visiting your WordPress's blog. It will display a custom ban message when the banned IP, IP range, host name or referer url trys to visit you blog. You can also exclude certain IPs from being banned. There will be statistics recordered on how many times they attemp to visit your blog. It allows wildcard matching too. 243 243 </p> 244 244 <p> wp-ban/trunk/readme.txt
r13121 r13124 2 2 Contributors: GamerZ 3 3 Donate link: http://www.lesterchan.net/wordpress 4 Tags: ban , deny, denied, permission, ip, hostname, host, spam, bots, bot, exclude, referer, url, referral4 Tags: banned, ban, deny, denied, permission, ip, hostname, host, spam, bots, bot, exclude, referer, url, referral, range 5 5 Requires at least: 2.1.0 6 6 Stable tag: 1.10 7 7 8 Ban users by IP, host name and referer url from visiting your WordPress's blog.8 Ban users by IP, IP Range, host name and referer url from visiting your WordPress's blog. 9 9 10 10 == Description == 11 11 12 It will display a custom ban message when the banned IP, host name or referer url trys to visit you blog. You can also exclude certain IPs from being banned. There will be statistics recordered on how many times they attemp to visit your blog. It allows wildcard matching too. 12 It will display a custom ban message when the banned IP, IP range, host name or referer url trys to visit you blog. You can also exclude certain IPs from being banned. There will be statistics recordered on how many times they attemp to visit your blog. It allows wildcard matching too. 13 13 14 All the information (general, changelog, installation, upgrade, usage) you need about this plugin can be found here: [WP-Ban Readme](http://www.lesterchan.net/wordpress/readme/wp-ban.html "WP-Ban Readme"). 14 15 It is the exact same readme.html is included in the zip package.
