Changeset 13124

Show
Ignore:
Timestamp:
05/23/07 09:22:13 (1 year ago)
Author:
GamerZ
Message:

Added Banned By IP Range

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • wp-ban/trunk/ban/ban.php

    r13121 r13124  
    5959 
    6060 
     61### Function: Print Out Banned Message 
     62function 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 
    6180### Function: Process Banning 
    6281function process_ban($banarray, $against)  { 
     
    6685                  $regexp = str_replace ('*', '.+', $regexp); 
    6786                  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(); 
    8288                  } 
    8389            } 
    8490      } 
    8591      return; 
     92} 
     93 
     94 
     95### Function: Process Banned IP Range 
     96function 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      } 
    86108} 
    87109 
     
    91113function banned() { 
    92114      $banned_ips = get_option('banned_ips'); 
     115      $banned_ips_range = get_option('banned_ips_range'); 
    93116      $banned_hosts = get_option('banned_hosts'); 
    94117      $banned_referers = get_option('banned_referers'); 
     
    105128      if(!$is_excluded) { 
    106129            process_ban($banned_ips, get_IP()); 
     130            process_ban_ip_range($banned_ips_range); 
    107131            process_ban($banned_hosts, @gethostbyaddr(get_IP())); 
    108132            process_ban($banned_referers, $_SERVER['HTTP_REFERER']); 
     
    141165            $update_ban_text = array();    
    142166            $banned_ips_post = explode("\n", trim($_POST['banned_ips'])); 
     167            $banned_ips_range_post = explode("\n", trim($_POST['banned_ips_range'])); 
    143168            $banned_hosts_post = explode("\n", trim($_POST['banned_hosts']));  
    144169            $banned_referers_post = explode("\n", trim($_POST['banned_referers'])); 
     
    155180                  } 
    156181            } 
     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            } 
    157195            if(!empty($banned_hosts_post)) { 
    158196                  $banned_hosts = array(); 
     
    182220            } 
    183221            $update_ban_queries[] = update_option('banned_ips', $banned_ips); 
     222            $update_ban_queries[] = update_option('banned_ips_range', $banned_ips_range); 
    184223            $update_ban_queries[] = update_option('banned_hosts', $banned_hosts); 
    185224            $update_ban_queries[] = update_option('banned_referers', $banned_referers); 
     
    187226            $update_ban_queries[] = update_option('banned_message', $banned_message); 
    188227            $update_ban_text[] = __('Banned IPs', 'wp-ban'); 
     228            $update_ban_text[] = __('Banned IP Range', 'wp-ban'); 
    189229            $update_ban_text[] = __('Banned Host Names', 'wp-ban'); 
    190230            $update_ban_text[] = __('Banned Referers', 'wp-ban'); 
     
    204244      // Get Banned IPs/Hosts 
    205245      $banned_ips = get_option('banned_ips'); 
     246      $banned_ips_range = get_option('banned_ips_range'); 
    206247      $banned_hosts = get_option('banned_hosts'); 
    207248      $banned_referers = get_option('banned_referers'); 
    208249      $banned_exclude_ips = get_option('banned_exclude_ips'); 
    209250      $banned_ips_display = ''; 
     251      $banned_ips_range_display = ''; 
    210252      $banned_hosts_display = ''; 
    211253      $banned_referers_display = ''; 
     
    216258            } 
    217259      } 
     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      } 
    218265      if(!empty($banned_hosts)) { 
    219266            foreach($banned_hosts as $banned_host) { 
     
    232279      } 
    233280      $banned_ips_display = trim($banned_ips_display); 
     281      $banned_ips_range_display = trim($banned_ips_range_display); 
    234282      $banned_hosts_display = trim($banned_hosts_display); 
    235283      $banned_referers_display = trim($banned_referers_display); 
     
    265313            } 
    266314      } 
     315      function preview_bannedmessage() { 
     316            window.open('<?php echo get_option('siteurl').'/wp-content/plugins/ban/ban-preview.php'; ?>'); 
     317      } 
    267318/* ]]> */ 
    268319</script> 
     
    291342                        <td> 
    292343                              <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>&raquo;</strong> 192.168.1.1-192.168.1.255<br /><br /> 
     352                              <?php _e('Notes:', 'wp-ban'); ?><br /> 
     353                              <strong>&raquo;</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> 
    293357                        </td> 
    294358                  </tr> 
     
    345409                                    - %USER_HOSTNAME%<br /> 
    346410                                    - %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 /> 
    348413                        </td> 
    349414                        <td> 
     
    414479 
    415480 
     481### Function: Check Whether IP Within A Given IP Range 
     482function 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 
    416493### Function: Check Whether Or Not The Hostname Belongs To Admin 
    417494function is_admin_hostname($check) { 
     
    444521      global $wpdb; 
    445522      $banned_ips = array(); 
     523      $banned_ips_range = array(); 
    446524      $banned_hosts = array(); 
    447525      $banned_referers = array(); 
     
    464542      add_option('banned_referers', $banned_referers, 'Banned Referers'); 
    465543      add_option('banned_exclude_ips', $banned_exclude_ips, 'Banned Exclude IP'); 
     544      add_option('banned_ips_range', $banned_ips_range, 'Banned IP Range'); 
    466545} 
    467546?> 
  • wp-ban/trunk/readme.html

    r13121 r13124  
    240240                  <p> 
    241241                        <strong>Features:</strong><br /> 
    242                         <strong>&raquo;</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>&raquo;</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. 
    243243                  </p> 
    244244                  <p> 
  • wp-ban/trunk/readme.txt

    r13121 r13124  
    22Contributors: GamerZ 
    33Donate link: http://www.lesterchan.net/wordpress 
    4 Tags: ban, deny, denied, permission, ip, hostname, host, spam, bots, bot, exclude, referer, url, referral 
     4Tags: banned, ban, deny, denied, permission, ip, hostname, host, spam, bots, bot, exclude, referer, url, referral, range 
    55Requires at least: 2.1.0 
    66Stable tag: 1.10 
    77 
    8 Ban users by IP, host name and referer url from visiting your WordPress's blog. 
     8Ban users by IP, IP Range, host name and referer url from visiting your WordPress's blog. 
    99 
    1010== Description == 
    1111 
    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. 
     12It 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 
    1314All 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"). 
    1415It is the exact same readme.html is included in the zip package.