Changeset 31757

Show
Ignore:
Timestamp:
02/13/08 17:09:54 (5 months ago)
Author:
GamerZ
Message:

Fixed "unknown" IPs and added Banned By User Agents. By: Jorge Garcia de Bustos

Files:

Legend:

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

    r22746 r31757  
    2929$admin_login = trim($current_user->user_login); 
    3030$mode = trim($_GET['mode']); 
    31 $ban_settings = array('banned_ips', 'banned_hosts', 'banned_stats', 'banned_message', 'banned_referers', 'banned_exclude_ips', 'banned_ips_range'); 
     31$ban_settings = array('banned_ips', 'banned_hosts', 'banned_stats', 'banned_message', 'banned_referers', 'banned_exclude_ips', 'banned_ips_range', 'banned_user_agents'); 
    3232 
    3333 
     
    4242      $banned_hosts_post = explode("\n", trim($_POST['banned_hosts']));  
    4343      $banned_referers_post = explode("\n", trim($_POST['banned_referers'])); 
     44      $banned_user_agents_post = explode("\n", trim($_POST['banned_user_agents'])); 
    4445      $banned_exclude_ips_post = explode("\n", trim($_POST['banned_exclude_ips'])); 
    4546      $banned_message = trim($_POST['banned_template_message']); 
     
    8788            } 
    8889      } 
     90      if(!empty($banned_user_agents_post)) { 
     91            $banned_user_agents = array(); 
     92            foreach($banned_user_agents_post as $banned_user_agent) { 
     93                  if(is_admin_user_agent($banned_user_agent)) { 
     94                        $text .= '<font color="blue">'.sprintf(__('This User Agent \'%s\' Is Used By The Current Admin And Will Not Be Added To Ban List', 'wp-ban'), $banned_user_agent).'</font><br />'; 
     95                  } else { 
     96                        $banned_user_agents[] = trim($banned_user_agent); 
     97                  } 
     98            } 
     99      } 
    89100      if(!empty($banned_exclude_ips_post)) { 
    90101            $banned_exclude_ips = array(); 
     
    97108      $update_ban_queries[] = update_option('banned_hosts', $banned_hosts); 
    98109      $update_ban_queries[] = update_option('banned_referers', $banned_referers); 
     110      $update_ban_queries[] = update_option('banned_user_agents', $banned_user_agents); 
    99111      $update_ban_queries[] = update_option('banned_exclude_ips', $banned_exclude_ips); 
    100112      $update_ban_queries[] = update_option('banned_message', $banned_message); 
     
    103115      $update_ban_text[] = __('Banned Host Names', 'wp-ban'); 
    104116      $update_ban_text[] = __('Banned Referers', 'wp-ban'); 
     117      $update_ban_text[] = __('Banned User Agents', 'wp-ban'); 
    105118      $update_ban_text[] = __('Banned Excluded IPs', 'wp-ban'); 
    106119      $update_ban_text[] = __('Banned Message', 'wp-ban'); 
     
    180193            $banned_hosts = get_option('banned_hosts'); 
    181194            $banned_referers = get_option('banned_referers'); 
     195            $banned_user_agents = get_option('banned_user_agents'); 
    182196            $banned_exclude_ips = get_option('banned_exclude_ips'); 
    183197            $banned_ips_display = ''; 
     
    206220                  } 
    207221            } 
     222            if(!empty($banned_user_agents)) { 
     223                  foreach($banned_user_agents as $banned_user_agent) { 
     224                        $banned_user_agents_display .= $banned_user_agent."\n"; 
     225                  } 
     226            } 
    208227            if(!empty($banned_exclude_ips)) { 
    209228                  foreach($banned_exclude_ips as $banned_exclude_ip) { 
     
    215234            $banned_hosts_display = trim($banned_hosts_display); 
    216235            $banned_referers_display = trim($banned_referers_display); 
     236            $banned_user_agents_display = trim($banned_user_agents_display); 
    217237            $banned_exclude_ips_display = trim($banned_exclude_ips_display); 
    218238            $banned_stats = get_option('banned_stats'); 
     
    318338                  <td> 
    319339                        <textarea cols="40" rows="10" name="banned_referers"><?php echo $banned_referers_display; ?></textarea> 
     340                  </td> 
     341            </tr> 
     342            <tr> 
     343                  <td valign="top"> 
     344                        <strong><?php _e('Banned User Agents', 'wp-ban'); ?>:</strong><br /> 
     345                        <?php _e('Use <strong>*</strong> for wildcards', 'wp-ban'); ?>.<br /> 
     346                        <?php _e('Start each entry on a new line.', 'wp-ban'); ?><br /><br /> 
     347                        <?php _e('Examples:', 'wp-ban'); ?><br /> 
     348                        <strong>&raquo;</strong> Mozilla<br /><br /> 
     349                  </td> 
     350                  <td> 
     351                        <textarea cols="40" rows="10" name="banned_user_agents"><?php echo $banned_user_agents_display; ?></textarea> 
    320352                  </td> 
    321353            </tr> 
  • wp-ban/trunk/readme.html

    r22746 r31757  
    259259                  </p> 
    260260                  <p> 
    261                         <strong>Updated:</strong><br /> 
    262                         <strong>&raquo;</strong> 1st January 2008 
    263                   </p> 
    264                   <p> 
    265261                        <strong>Note:</strong><br /> 
    266262                        <strong>&raquo;</strong> The <strong>Changelog</strong>, <strong>Installation</strong>, <strong>Upgrade</strong>, <strong>Usage</strong> Tab at the top of the page.<br /> 
     
    288284                                    <li>NEW: Uses wp-ban.php Instead Of ban.php</li> 
    289285                                    <li>NEW: Uses number_format_i18n()</li> 
     286                                    <li>NEW: Banned By User Agents (By: <a href="http://www.linkedin.com/in/jgbustos">Jorge Garcia de Bustos</a>)</li> 
     287                                    <li>FIXED: "unknown" IPs (By: <a href="http://www.linkedin.com/in/jgbustos">Jorge Garcia de Bustos</a>)</li> 
    290288                              </ul> 
    291289                        </li> 
  • wp-ban/trunk/wp-ban.php

    r22746 r31757  
    4848if(!function_exists('get_IP')) { 
    4949      function get_IP() { 
    50             if(empty($_SERVER["HTTP_X_FORWARDED_FOR"])) { 
    51                   $ip_address = $_SERVER["REMOTE_ADDR"]; 
     50            if(!empty($_SERVER['HTTP_CLIENT_IP'])) { 
     51                  $ip_address = $_SERVER['HTTP_CLIENT_IP']; 
     52            } else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { 
     53                  $ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; 
     54            } else if(!empty($_SERVER['REMOTE_ADDR'])) { 
     55                  $ip_address = $_SERVER['REMOTE_ADDR']; 
    5256            } else { 
    53                   $ip_address = $_SERVER["HTTP_X_FORWARDED_FOR"]
     57                  $ip_address = ''
    5458            } 
    5559            if(strpos($ip_address, ',') !== false) { 
     
    119123      $banned_hosts = get_option('banned_hosts'); 
    120124      $banned_referers = get_option('banned_referers'); 
     125      $banned_user_agents = get_option('banned_user_agents'); 
    121126      $banned_exclude_ips = get_option('banned_exclude_ips'); 
    122127      $is_excluded = false; 
     
    134139            process_ban($banned_hosts, @gethostbyaddr(get_IP())); 
    135140            process_ban($banned_referers, $_SERVER['HTTP_REFERER']); 
     141            process_ban($banned_user_agents, $_SERVER['HTTP_USER_AGENT']); 
    136142      } 
    137143} 
     
    155161      $range_end = ip2long($range_end); 
    156162      $ip = ip2long($ip); 
    157       if($ip >= $range_start && $ip <= $range_end) { 
     163      if($ip !== false && $ip >= $range_start && $ip <= $range_end) { 
    158164            return true; 
    159165      } 
     
    185191      } 
    186192      return false; 
     193} 
     194 
     195 
     196### Function: Check Whether Or Not The User Agent Is Used by Admin 
     197function is_admin_user_agent($check) { 
     198      $regexp = str_replace ('.', '\\.', $check); 
     199      $regexp = str_replace ('*', '.+', $regexp); 
     200      return ereg("^$regexp$", $_SERVER['HTTP_USER_AGENT']); 
    187201} 
    188202 
     
    215229      add_option('banned_exclude_ips', $banned_exclude_ips, 'Banned Exclude IP'); 
    216230      add_option('banned_ips_range', $banned_ips_range, 'Banned IP Range'); 
     231      // Database Upgrade For WP-Ban 1.30 
     232      add_option('banned_user_agents', $banned_user_agents, 'Banned User Agents'); 
    217233} 
    218234?> 
  • wp-ban/trunk/wp-ban.pot

    r22746 r31757  
    33"Project-Id-Version: WP-Ban 1.30\n" 
    44"POT-Creation-Date: \n" 
    5 "PO-Revision-Date: 2007-10-21 20:22+0800\n" 
     5"PO-Revision-Date: 2008-02-14 01:09+0800\n" 
    66"Last-Translator: Lester 'GaMerZ' Chan <gamerz84@hotmail.com>\n" 
    77"Language-Team: Lester Chan <gamerz84@hotmail.com>\n" 
     
    1515"X-Poedit-SearchPath-0: .\n" 
    1616 
    17 #: ban-options.php:50 
     17#: ban-options.php:51 
    1818#, php-format 
    1919msgid "This IP '%s' Belongs To The Admin And Will Not Be Added To Ban List" 
    2020msgstr "" 
    2121 
    22 #: ban-options.php:63 
     22#: ban-options.php:64 
    2323#, php-format 
    2424msgid "The Admin's IP '%s' Fall Within This Range (%s - %s) And Will Not Be Added To Ban List" 
    2525msgstr "" 
    2626 
    27 #: ban-options.php:73 
     27#: ban-options.php:74 
    2828#, php-format 
    2929msgid "This Hostname '%s' Belongs To The Admin And Will Not Be Added To Ban List" 
    3030msgstr "" 
    3131 
    32 #: ban-options.php:83 
     32#: ban-options.php:84 
    3333#, php-format 
    3434msgid "This Referer '%s' Belongs To This Site And Will Not Be Added To Ban List" 
    3535msgstr "" 
    3636 
    37 #: ban-options.php:101 
    38 #: ban-options.php:269 
     37#: ban-options.php:94 
     38#, php-format 
     39msgid "This User Agent '%s' Is Used By The Current Admin And Will Not Be Added To Ban List" 
     40msgstr "" 
     41 
     42#: ban-options.php:113 
     43#: ban-options.php:289 
    3944msgid "Banned IPs" 
    4045msgstr "" 
    4146 
    42 #: ban-options.php:102 
     47#: ban-options.php:114 
     48#: ban-options.php:303 
     49msgid "Banned IP Range" 
     50msgstr "" 
     51 
     52#: ban-options.php:115 
     53#: ban-options.php:316 
     54msgid "Banned Host Names" 
     55msgstr "" 
     56 
     57#: ban-options.php:116 
     58#: ban-options.php:330 
     59msgid "Banned Referers" 
     60msgstr "" 
     61 
     62#: ban-options.php:117 
     63#: ban-options.php:344 
     64msgid "Banned User Agents" 
     65msgstr "" 
     66 
     67#: ban-options.php:118 
     68msgid "Banned Excluded IPs" 
     69msgstr "" 
     70 
     71#: ban-options.php:119 
     72#: ban-options.php:370 
     73msgid "Banned Message" 
     74msgstr "" 
     75 
     76#: ban-options.php:123 
     77msgid "Updated" 
     78msgstr "" 
     79 
     80#: ban-options.php:128 
     81msgid "No Ban Option Updated" 
     82msgstr "" 
     83 
     84#: ban-options.php:135 
     85#: ban-options.php:430 
     86msgid "Reset Ban Stats" 
     87msgstr "" 
     88 
     89#: ban-options.php:139 
     90msgid "All IP Ban Stats And Total Ban Stat Reseted" 
     91msgstr "" 
     92 
     93#: ban-options.php:147 
     94msgid "Selected IP Ban Stats Reseted" 
     95msgstr "" 
     96 
     97#: ban-options.php:151 
     98#: ban-options.php:467 
     99msgid "UNINSTALL WP-Ban" 
     100msgstr "" 
     101 
     102#: ban-options.php:159 
     103#, php-format 
     104msgid "Setting Key '%s' has been deleted." 
     105msgstr "" 
     106 
     107#: ban-options.php:163 
     108#, php-format 
     109msgid "Error deleting Setting Key '%s'." 
     110msgstr "" 
     111 
     112#: ban-options.php:185 
     113#: ban-options.php:437 
     114msgid "Uninstall WP-Ban" 
     115msgstr "" 
     116 
     117#: ban-options.php:186 
     118#, php-format 
     119msgid "<a href=\"%s\">Click Here</a> To Finish The Uninstallation And WP-Ban Will Be Deactivated Automatically." 
     120msgstr "" 
     121 
     122#: ban-options.php:247 
     123#: wp-ban.php:224 
     124msgid "You Are Banned." 
     125msgstr "" 
     126 
     127#: ban-options.php:276 
     128msgid "Ban Options" 
     129msgstr "" 
     130 
     131#: ban-options.php:278 
     132#: ban-options.php:387 
     133msgid "Update Options &raquo;" 
     134msgstr "" 
     135 
    43136#: ban-options.php:283 
    44 msgid "Banned IP Range" 
    45 msgstr "" 
    46  
    47 #: ban-options.php:103 
    48 #: ban-options.php:296 
    49 msgid "Banned Host Names" 
    50 msgstr "" 
    51  
    52 #: ban-options.php:104 
    53 #: ban-options.php:310 
    54 msgid "Banned Referers" 
    55 msgstr "" 
    56  
    57 #: ban-options.php:105 
    58 msgid "Banned Excluded IPs" 
    59 msgstr "" 
    60  
    61 #: ban-options.php:106 
    62 #: ban-options.php:338 
    63 msgid "Banned Message" 
    64 msgstr "" 
    65  
    66 #: ban-options.php:110 
    67 msgid "Updated" 
    68 msgstr "" 
    69  
    70 #: ban-options.php:115 
    71 msgid "No Ban Option Updated" 
    72 msgstr "" 
    73  
    74 #: ban-options.php:122 
     137#, php-format 
     138msgid "Your IP is: <strong>%s</strong><br />Your Host Name is: <strong>%s</strong><br />Your Site URL is: <strong>%s</strong>" 
     139msgstr "" 
     140 
     141#: ban-options.php:284 
     142msgid "Please <strong>DO NOT</strong> ban yourself." 
     143msgstr "" 
     144 
     145#: ban-options.php:290 
     146msgid "Use <strong>*</strong> for wildcards." 
     147msgstr "" 
     148 
     149#: ban-options.php:291 
     150#: ban-options.php:304 
     151#: ban-options.php:318 
     152#: ban-options.php:332 
     153#: ban-options.php:346 
     154#: ban-options.php:357 
     155msgid "Start each entry on a new line." 
     156msgstr "" 
     157 
     158#: ban-options.php:292 
     159#: ban-options.php:305 
     160#: ban-options.php:319 
     161#: ban-options.php:333 
     162#: ban-options.php:347 
     163#: ban-options.php:358 
     164msgid "Examples:" 
     165msgstr "" 
     166 
     167#: ban-options.php:307 
     168#: ban-options.php:335 
     169#: ban-options.php:360 
     170msgid "Notes:" 
     171msgstr "" 
     172 
     173#: ban-options.php:308 
     174#: ban-options.php:361 
     175msgid "No Wildcards Allowed." 
     176msgstr "" 
     177 
     178#: ban-options.php:317 
     179#: ban-options.php:331 
     180#: ban-options.php:345 
     181msgid "Use <strong>*</strong> for wildcards" 
     182msgstr "" 
     183 
     184#: ban-options.php:336 
     185msgid "There are ways to bypass this method of banning." 
     186msgstr "" 
     187 
     188#: ban-options.php:356 
     189msgid "Banned Exclude IPs" 
     190msgstr "" 
     191 
     192#: ban-options.php:362 
     193msgid "These Users Will Not Get Banned." 
     194msgstr "" 
     195 
     196#: ban-options.php:371 
     197msgid "Allowed Variables:" 
     198msgstr "" 
     199 
     200#: ban-options.php:378 
     201msgid "Restore Default Template" 
     202msgstr "" 
     203 
     204#: ban-options.php:379 
     205msgid "Preview Banned Message" 
     206msgstr "" 
     207 
     208#: ban-options.php:394 
     209msgid "Ban Stats" 
     210msgstr "" 
     211 
     212#: ban-options.php:397 
     213msgid "IPs" 
     214msgstr "" 
     215 
    75216#: ban-options.php:398 
    76 msgid "Reset Ban Stats" 
    77 msgstr "" 
    78  
    79 #: ban-options.php:126 
    80 msgid "All IP Ban Stats And Total Ban Stat Reseted" 
    81 msgstr "" 
    82  
    83 #: ban-options.php:134 
    84 msgid "Selected IP Ban Stats Reseted" 
    85 msgstr "" 
    86  
    87 #: ban-options.php:138 
    88 #: ban-options.php:435 
    89 msgid "UNINSTALL WP-Ban" 
    90 msgstr "" 
    91  
    92 #: ban-options.php:146 
    93 #, php-format 
    94 msgid "Setting Key '%s' has been deleted." 
    95 msgstr "" 
    96  
    97 #: ban-options.php:150 
    98 #, php-format 
    99 msgid "Error deleting Setting Key '%s'." 
    100 msgstr "" 
    101  
    102 #: ban-options.php:172 
    103 #: ban-options.php:405 
    104 msgid "Uninstall WP-Ban" 
    105 msgstr "" 
    106  
    107 #: ban-options.php:173 
    108 #, php-format 
    109 msgid "<a href=\"%s\">Click Here</a> To Finish The Uninstallation And WP-Ban Will Be Deactivated Automatically." 
    110 msgstr "" 
    111  
    112 #: ban-options.php:227 
    113 #: wp-ban.php:210 
    114 msgid "You Are Banned." 
    115 msgstr "" 
    116  
    117 #: ban-options.php:256 
    118 msgid "Ban Options" 
    119 msgstr "" 
    120  
    121 #: ban-options.php:258 
    122 #: ban-options.php:355 
    123 msgid "Update Options &raquo;" 
    124 msgstr "" 
    125  
    126 #: ban-options.php:263 
    127 #, php-format 
    128 msgid "Your IP is: <strong>%s</strong><br />Your Host Name is: <strong>%s</strong><br />Your Site URL is: <strong>%s</strong>" 
    129 msgstr "" 
    130  
    131 #: ban-options.php:264 
    132 msgid "Please <strong>DO NOT</strong> ban yourself." 
    133 msgstr "" 
    134  
    135 #: ban-options.php:270 
    136 msgid "Use <strong>*</strong> for wildcards." 
    137 msgstr "" 
    138  
    139 #: ban-options.php:271 
    140 #: ban-options.php:284 
    141 #: ban-options.php:298 
    142 #: ban-options.php:312 
    143 #: ban-options.php:325 
    144 msgid "Start each entry on a new line." 
    145 msgstr "" 
    146  
    147 #: ban-options.php:272 
    148 #: ban-options.php:285 
    149 #: ban-options.php:299 
    150 #: ban-options.php:313 
    151 #: ban-options.php:326 
    152 msgid "Examples:" 
    153 msgstr "" 
    154  
    155 #: ban-options.php:287 
    156 #: ban-options.php:315 
    157 #: ban-options.php:328 
    158 msgid "Notes:" 
    159 msgstr "" 
    160  
    161 #: ban-options.php:288 
    162 #: ban-options.php:329 
    163 msgid "No Wildcards Allowed." 
    164 msgstr "" 
    165  
    166 #: ban-options.php:297 
    167 #: ban-options.php:311 
    168 msgid "Use <strong>*</strong> for wildcards" 
    169 msgstr "" 
    170  
    171 #: ban-options.php:316 
    172 msgid "There are ways to bypass this method of banning." 
    173 msgstr "" 
    174  
    175 #: ban-options.php:324 
    176 msgid "Banned Exclude IPs" 
    177 msgstr "" 
    178  
    179 #: ban-options.php:330 
    180 msgid "These Users Will Not Get Banned." 
    181 msgstr "" 
    182  
    183 #: ban-options.php:339 
    184 msgid "Allowed Variables:" 
    185 msgstr "" 
    186  
    187 #: ban-options.php:346 
    188 msgid "Restore Default Template" 
    189 msgstr "" 
    190  
    191 #: ban-options.php:347 
    192 msgid "Preview Banned Message" 
    193 msgstr "" 
    194  
    195 #: ban-options.php:362 
    196 msgid "Ban Stats" 
    197 msgstr "" 
    198  
    199 #: ban-options.php:365 
    200 msgid "IPs" 
    201 msgstr "" 
    202  
    203 #: ban-options.php:366 
    204217msgid "Attempts" 
    205218msgstr "" 
    206219 
    207 #: ban-options.php:367 
     220#: ban-options.php:399 
    208221msgid "Action" 
    209222msgstr "" 
    210223 
    211 #: ban-options.php:388 
     224#: ban-options.php:420 
    212225msgid "No Attempts" 
    213226msgstr "" 
    214227 
    215 #: ban-options.php:393 
     228#: ban-options.php:425 
    216229msgid "Total  Attempts:" 
    217230msgstr "" 
    218231 
    219 #: ban-options.php:395 
     232#: ban-options.php:427 
    220233msgid "Reset all IP ban stats and total ban stat?" 
    221234msgstr "" 
    222235 
    223 #: ban-options.php:398 
     236#: ban-options.php:430 
    224237msgid "You Are About To Reset Ban Stats." 
    225238msgstr "" 
    226239 
    227 #: ban-options.php:398 
     240#: ban-options.php:430 
    228241msgid "This Action Is Not Reversible. Are you sure?" 
    229242msgstr "" 
    230243 
    231 #: ban-options.php:407 
     244#: ban-options.php:439 
    232245msgid "Deactivating WP-Ban plugin does not remove any data that may have been created, such as the ban options. To completely remove this plugin, you can uninstall it here." 
    233246msgstr "" 
    234247 
    235 #: ban-options.php:410 
     248#: ban-options.php:442 
    236249msgid "WARNING:" 
    237250msgstr "" 
    238251 
    239 #: ban-options.php:411 
     252#: ban-options.php:443 
    240253msgid "Once uninstalled, this cannot be undone. You should use a Database Backup plugin of WordPress to back up all the data first." 
    241254msgstr "" 
    242255 
    243 #: ban-options.php:414 
     256#: ban-options.php:446 
    244257msgid "The following WordPress Options will be DELETED:" 
    245258msgstr "" 
    246259 
    247 #: ban-options.php:418 
     260#: ban-options.php:450 
    248261msgid "WordPress Options" 
    249262msgstr "" 
    250263 
    251 #: ban-options.php:434 
     264#: ban-options.php:466 
    252265msgid "Yes" 
    253266msgstr "" 
    254267 
    255 #: ban-options.php:435 
     268#: ban-options.php:467 
    256269msgid "" 
    257270"You Are About To Uninstall WP-Ban From WordPress.\\n"