Plugin Directory

Changeset 432898


Ignore:
Timestamp:
09/03/2011 02:16:33 PM (15 years ago)
Author:
ljmacphee
Message:

fix redirect loop

Location:
ttc-wordpress-security-plugin/trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • ttc-wordpress-security-plugin/trunk/readme.txt

    r422619 r432898  
    44Requires at least: 2.5
    55Tested up to: 3.2.1
    6 Stable tag: 3.0
     6Stable tag: 3.2
    77
    88This plugin blocks scrapers, cross-site scripting attempts, and other ill behaved bots.  This is the second of three security plugins.
     
    1010
    1111
    12 == Screenshots ==
    13 1. Admin screen security.jpg
    1412
    1513== Description ==
  • ttc-wordpress-security-plugin/trunk/ttc_security.php

    r422619 r432898  
    22    /**
    33     * @package TimesToCome_Security_Plugin
    4      * @version 3.0
     4     * @version 3.2
    55     **/
    66    /*
    77     Plugin Name: TimesToCome Security Plugin
    8      Version: 3.0
     8     Version: 3.2
    99     Plugin URI:  http://herselfswebtools.com/2008/06/wordpress-security-plugin-block-scrapers-hackers-and-more.html
    1010     Description: Security plugin for Wordpress
     
    4545    //Aug 2011 version 3.0 improves ui and cleans up code adds install/uninstall functions
    4646// ************************************************************************************************************
     47    //Aug 2011 version 3.1 fix overwriting of log file names
     48// ************************************************************************************************************
     49    // Sept 2011 version 3.2 fix redirect loops
     50// ************************************************************************************************************
    4751
    4852   
     
    6165    $request_method = $_SERVER['REQUEST_METHOD'];
    6266
    63 
    64        
    6567   
    6668
     
    7375        $ttc_wpdb_prefix = $wpdb->prefix;   
    7476
    75         $log_table_name = $ttc_wpdb_prefix . "ttc_security_log";
     77       
     78       
     79        // table info
     80        $log_table_name = $ttc_wpdb_prefix . "ttc_security_log";
    7681        $ip_table_name = $ttc_wpdb_prefix . "ttc_ip_blacklist";
    7782        $agent_table_name = $ttc_wpdb_prefix . "ttc_agent_blacklist";
    7883        $request_table_name = $ttc_wpdb_prefix . "ttc_request_blacklist";
    79    
     84       
     85
    8086               
    8187        // server variables
     
    9096        // local variables
    9197        $blacklisted = 0;
    92        
    93 
    94 
    95        
     98         
     99             
     100     
    96101         
    97102        ////********************************************       
     
    118123                // hack so null doesn't equal a match
    119124                $hacked_http_remote_addr = "x" . $http_remote_addr;
     125                               
    120126                if ((strpos ( $hacked_http_remote_addr, $bad_ip, 1 )) == 1 ){
    121127                    $blacklisted = 1;
     
    123129            }
    124130        }
    125        
    126131       
    127132       
     
    160165        }
    161166       
    162        
    163        
    164        
     167               
    165168       
    166169               
     
    173176       
    174177       
    175 
    176 
    177 
    178178        //update our log files
    179179        // if code is one  update log files
    180180        // else update log file and ip file
     181       
     182       // $blacklisted = 3;         // use for testing
    181183       
    182184        if ( $blacklisted == 0 ){
    183            
     185       
    184186            // do nothing all is right and wonderful in the world
    185187
     188
    186189        }else if ( $blacklisted == 1 ){                     // already blacklisted ip here so just add to log
    187190           
    188191            // too many to log, log entries growing too fast
    189             //ttc_add_to_security_log(   $blacklisted );            //  add to log
     192//          ttc_add_to_security_log(   $blacklisted );          //  add to log
    190193           
    191194            $code = "Sorry but you are listed on our ip blacklist";
     
    198201            $host  = $_SERVER['HTTP_HOST'];
    199202            $uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
    200             header("Location: http://$host$uri");
     203//          header("Location: http://$host$uri");
     204           
     205            header('HTTP/1.0 404 Not Found');
    201206           
    202207            exit();
     
    224229            $host  = $_SERVER['HTTP_HOST'];
    225230            $uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
    226             header("Location: http://$host$uri");
    227            
    228            
     231//          header("Location: http://$host$uri");
     232           
     233            header('HTTP/1.0 404 Not Found');
     234
     235           
    229236            exit();
    230237           
    231238        }
     239       
     240       
    232241    }
    233242   
     
    238247    function ttc_add_to_security_log( $error )
    239248    {
    240         // wordpress db info
    241         global $wpdb;   
    242         $ttc_wpdb_prefix = $wpdb->prefix;   
    243 
    244         // server variables
     249       
     250        // server variables
    245251        global $log_table_name;
    246252        global $request_time;
     
    249255        global $http_remote_addr;
    250256        global $request_uri;
    251        
    252        
     257       
     258       
     259        // wordpress db info
     260        global $wpdb;   
     261        $ttc_wpdb_prefix = $wpdb->prefix;   
     262       
     263       
     264        $log_table_name = $ttc_wpdb_prefix . "ttc_security_log";
     265        $ip_table_name = $ttc_wpdb_prefix . "ttc_ip_blacklist";
     266        $agent_table_name = $ttc_wpdb_prefix . "ttc_agent_blacklist";
     267        $request_table_name = $ttc_wpdb_prefix . "ttc_request_blacklist";
     268
     269
    253270        // wtf? accept statements coming in at over 255 chars?  Prevent sql errors and any funny business
    254271        // by shortening anything from user to 200 chars if over 255
     
    266283        // ok now stuff the info into the log files in the db
    267284        $sql = "INSERT INTO " . $log_table_name . " ( ip, problem, accept, agent, request, day )
    268         VALUES ( '$http_remote_addr', '$error', '$http_accept', '$http_user_agent', '$request_uri', NOW() )";
     285                VALUES ( '$http_remote_addr', '$error', '$http_accept', '$http_user_agent', '$request_uri', NOW() )";
    269286        $result = $wpdb->query( $sql );
    270        
    271     }
     287       
     288       
     289    }
     290   
     291   
    272292   
    273293   
     
    280300        global $ip_table_name;
    281301       
    282        
     302        $ttc_wpdb_prefix = $wpdb->prefix;   
     303        $ip_table_name = $ttc_wpdb_prefix . "ttc_ip_blacklist";
     304
     305       
    283306        // insert ip number into blacklisted ip table
    284307        $sql = "INSERT INTO " . $ip_table_name . " ( ip ) VALUES ( '$ip' ) ";
    285308        $result = $wpdb->query( $sql );
    286        
     309               
    287310    }
    288311   
Note: See TracChangeset for help on using the changeset viewer.