Plugin Directory

Changeset 584844


Ignore:
Timestamp:
08/13/2012 12:36:27 PM (14 years ago)
Author:
6Scan
Message:

We have completely changed the file access paths. Now, when signature/.htaccess file is created/changed, wp_filesystem path functions are used instead of filesystem ones

Location:
6scan-protection/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • 6scan-protection/trunk/6scan.php

    r580294 r584844  
    2424define( 'SIXSCAN_PLUGIN_DIR' ,          trailingslashit( dirname(__FILE__) ) );
    2525define( 'SIXSCAN_PLUGIN_URL' ,          trailingslashit( plugins_url( basename ( dirname (__FILE__) ) ) ) );
     26define( 'SIXSCAN_PLUGIN_DIRNAME' ,      basename( dirname ( __FILE__ ) ) );
    2627
    2728/* Platform type */
  • 6scan-protection/trunk/admin/includes/common.php

    r580294 r584844  
    6464define ( 'SIXSCAN_LOGIN_LOCKED_OUT_MINUTES' ,           'login_locked_out_minutes' );
    6565define ( 'SIXSCAN_LOGIN_NOTIFY_ADMIN_EMAIL' ,           'login_notify_admin_email' );
    66 
    67 define ( 'SIXSCAN_ANTISPAM_PROTECTION_ON_OPTION' ,      'antispam_protection_on' );
    68 define ( 'SIXSCAN_ANTISPAM_DELETE_OLD_OPTION' ,         'antispam_delete_old_spam' );
    6966
    7067define ( 'SIXSCAN_UPDATE_OK_RESPONSE_CODE',             200 );
     
    114111define ( 'SIXSCAN_ANALYTICS_OK_STRING',                 'ok' );
    115112define ( 'SIXSCAN_ANALYTICS_FAIL_PREFIX_STRING',        'error_' );
    116 
    117 define( 'SIXSCAN_HTACCESS_FILE',                        ABSPATH . '/.htaccess' );
    118 define( 'SIXSCAN_HTACCESS_6SCAN_GATE_FILE_NAME',        '6scan-gate.php' );
     113define ( 'SIXSCAN_HTACCESS_FILE',                       ABSPATH . '/.htaccess' );
     114
     115define ( 'SIXSCAN_HTACCESS_6SCAN_GATE_FILE_NAME',       '6scan-gate.php' );
    119116
    120117define( 'SIXSCAN_ADMIN_ACCESS_COOKIE_NAME',             'sixscan_wpblog_admin' );
     
    126123
    127124/*  If this script is included from outside, we will not have SIXSCAN_PLUGIN_DIR defined, but we do not really need it */
    128 if ( defined( 'SIXSCAN_PLUGIN_DIR' ) ){
     125if ( defined( 'SIXSCAN_PLUGIN_DIR' ) ){
     126
    129127    define( 'SIXSCAN_HTACCESS_6SCAN',                       SIXSCAN_PLUGIN_DIR . '/data/.htaccess.dat' );
     128    function sixscan_common_get_src_htaccess( $is_direct = TRUE ){
     129        if ( $is_direct == TRUE )
     130            return SIXSCAN_HTACCESS_6SCAN;
     131
     132        global $wp_filesystem;
     133        return $wp_filesystem->find_folder( SIXSCAN_HTACCESS_6SCAN );
     134    }
     135
     136
    130137    define( 'SIXSCAN_SIGNATURE_SRC',                        SIXSCAN_PLUGIN_DIR . '/data/' . SIXSCAN_COMM_SIGNATURE_FILENAME );
     138    function sixscan_common_get_signature_src( $is_direct = TRUE ){
     139        if ( $is_direct == TRUE )
     140            return SIXSCAN_SIGNATURE_SRC;
     141       
     142        global $wp_filesystem;
     143        return $wp_filesystem->find_folder( SIXSCAN_SIGNATURE_SRC );   
     144    }
     145
    131146    define( 'SIXSCAN_HTACCESS_6SCAN_GATE_SOURCE',           SIXSCAN_PLUGIN_DIR . '/data/' . SIXSCAN_HTACCESS_6SCAN_GATE_FILE_NAME );
     147    function sixscan_common_get_gate_src( $is_direct = TRUE ){     
     148        if ( $is_direct == TRUE )
     149            return SIXSCAN_HTACCESS_6SCAN_GATE_SOURCE;
     150       
     151        global $wp_filesystem;
     152        return $wp_filesystem->find_folder( SIXSCAN_HTACCESS_6SCAN_GATE_SOURCE );       
     153    }   
    132154    define( 'SIXSCAN_ANALYZER_LOG_FILEPATH',                SIXSCAN_PLUGIN_DIR . SIXSCAN_SECURITY_LOG_FILENAME );   
    133155}
    134156
    135 define( 'SIXSCAN_HTACCESS_6SCAN_GATE_DEST',             ABSPATH . SIXSCAN_HTACCESS_6SCAN_GATE_FILE_NAME );
    136 define( 'SIXSCAN_SIGNATURE_DEST',                       ABSPATH . SIXSCAN_COMM_SIGNATURE_FILENAME );
     157
    137158define( 'SIXSCAN_COMMON_DASHBOARD_URL',                 'six-scan-dashboard' );
    138159define( 'SIXSCAN_COMMON_SETTINGS_URL',                  'six-scan-settings' );
     
    159180EOD
    160181);
     182
     183
     184function sixscan_common_get_htaccess_file_path( $is_direct ){
     185    if ( $is_direct == TRUE )
     186        return SIXSCAN_HTACCESS_FILE;
     187
     188    global $wp_filesystem;
     189    return $wp_filesystem->abspath() . '.htaccess';
     190}
     191
     192function sixscan_common_get_htaccess_dest_path( $is_direct = TRUE ){
     193    if ( $is_direct == TRUE )
     194        return ABSPATH . SIXSCAN_HTACCESS_6SCAN_GATE_FILE_NAME;
     195
     196    global $wp_filesystem;
     197    return $wp_filesystem->abspath() . SIXSCAN_HTACCESS_6SCAN_GATE_FILE_NAME;
     198}
     199
     200function sixscan_common_get_signature_dest_path( $is_direct = TRUE ){
     201    if ( $is_direct == TRUE )
     202        return ABSPATH . SIXSCAN_COMM_SIGNATURE_FILENAME;
     203
     204    global $wp_filesystem;
     205    return $wp_filesystem->abspath() . SIXSCAN_COMM_SIGNATURE_FILENAME;
     206}
    161207
    162208function sixscan_common_set_site_id( $site_id ){
     
    379425    $submission_data .= "Is access through proxy: $is_through_proxy\n";
    380426   
    381     $htaccess_contents = file_get_contents( SIXSCAN_HTACCESS_FILE );
     427    $htaccess_contents = file_get_contents( sixscan_common_get_htaccess_file_path( TRUE ) );
    382428    if ( $htaccess_contents == FALSE )
    383429        $htaccess_contents = "Empty";
     
    409455    global $wp_filesystem;
    410456
    411     $tmp_fname = tempnam( untrailingslashit( $dir_name ) , 'sixscantmp_');
     457    $tmp_fname = untrailingslashit( $dir_name ) . 'sixscantmp_';
    412458   
    413459    $ftmp_result = $wp_filesystem->put_contents( $tmp_fname , 'write_test' );   
     
    417463
    418464    /* Cleanup */
    419     unlink( $tmp_fname );
     465    $wp_filesystem->delete( $tmp_fname );
    420466    return TRUE;
    421467}
  • 6scan-protection/trunk/admin/includes/htaccess.php

    r580294 r584844  
    77    $ret_error = array();
    88
    9     $htaccess_sixscan = trim ( $wp_filesystem->get_contents( SIXSCAN_HTACCESS_6SCAN . $htaccess_sixscan_version ) ) . "\n\n";       
    10    
    11     if ( ! $wp_filesystem->copy( SIXSCAN_HTACCESS_6SCAN_GATE_SOURCE, SIXSCAN_HTACCESS_6SCAN_GATE_DEST , TRUE , 0755 ) ) {
    12         $ret_error[ 'user_message' ] = 'Failed copying ' . SIXSCAN_HTACCESS_6SCAN_GATE_FILE_NAME . ' during installation';
     9    $is_direct = ( $wp_filesystem->method == 'direct' );   
     10    $local_htaccess_path = sixscan_common_get_htaccess_file_path( $is_direct );
     11    $htaccess_sixscan = trim ( $wp_filesystem->get_contents( sixscan_common_get_src_htaccess( $is_direct ) . $htaccess_sixscan_version ) ) . "\n\n";       
     12
     13    if ( ! $wp_filesystem->copy( sixscan_common_get_gate_src( $is_direct ) , sixscan_common_get_htaccess_dest_path( $is_direct ) , TRUE , 0755 ) ) {
     14        $ret_error[ 'user_message' ] = 'Failed copying ' . sixscan_common_get_htaccess_dest_path( $is_direct ) . ' during installation';
    1315        $ret_error[ 'short_description' ] = 'Failed copying htaccess during installation';
    1416        return $ret_error;
    1517    }       
    1618
    17     if ( ! $wp_filesystem->copy( SIXSCAN_SIGNATURE_SRC, SIXSCAN_SIGNATURE_DEST , TRUE , 0755 ) ) {
    18         $ret_error[ 'user_message' ] = 'Failed copying ' . SIXSCAN_SIGNATURE_SRC . ' during installation';
     19    if ( ! $wp_filesystem->copy( sixscan_common_get_signature_src( $is_direct ), sixscan_common_get_signature_dest_path( $is_direct ) , TRUE , 0755 ) ) {
     20        $ret_error[ 'user_message' ] = 'Failed copying ' . sixscan_common_get_signature_src( $is_direct ) . ' during installation';
    1921        $ret_error[ 'short_description' ] = 'Failed copying signature during installation';
    2022        return $ret_error;
    2123    }
    2224   
    23     if ( $wp_filesystem->exists( SIXSCAN_HTACCESS_FILE ) ) {
    24         $htaccess_content = $wp_filesystem->get_contents( SIXSCAN_HTACCESS_FILE );
     25    if ( $wp_filesystem->exists( $local_htaccess_path ) ) {
     26        $htaccess_content = $wp_filesystem->get_contents( $local_htaccess_path );
    2527        $htaccess_sixscan .= preg_replace( '@# Created by 6Scan plugin(.*?)# End of 6Scan plugin@s' , '' , $htaccess_content ) ;
    26         $wp_filesystem->delete( SIXSCAN_HTACCESS_FILE );
     28        $wp_filesystem->delete( $local_htaccess_path );
    2729    }
    2830   
    29     if ( $wp_filesystem->put_contents( SIXSCAN_HTACCESS_FILE , $htaccess_sixscan ) === FALSE ){
     31    if ( $wp_filesystem->put_contents( $local_htaccess_path , $htaccess_sixscan ) === FALSE ){
    3032        $ret_error[ 'user_message' ] = 'Failed opening htaccess during installation';
    3133        $ret_error[ 'short_description' ] = 'Failed opening htaccess during installation';
     
    4244        WP_Filesystem();
    4345
     46    $is_direct = ( $wp_filesystem->method == 'direct' );
     47    $local_htaccess_path = sixscan_common_get_htaccess_file_path( $is_direct );
     48
    4449    try {
    45         if ( $wp_filesystem->exists( SIXSCAN_HTACCESS_FILE ) ) {
    46             $htaccess_content = $wp_filesystem->get_contents( SIXSCAN_HTACCESS_FILE );
     50        if ( $wp_filesystem->exists( $local_htaccess_path ) ) {
     51            $htaccess_content = $wp_filesystem->get_contents( $local_htaccess_path );
    4752            $a = preg_replace( '@# Created by 6Scan plugin(.*?)# End of 6Scan plugin@s', '', $htaccess_content) ;
     53   
     54            if ( $wp_filesystem->put_contents( $local_htaccess_path , $a ) === FALSE )
     55                throw new Exception('Failed to open htaccess during installation');     
    4856        }
    49    
    50         if ( $wp_filesystem->put_contents( SIXSCAN_HTACCESS_FILE , $a ) === FALSE )
    51             throw new Exception('Failed to open htaccess during installation');     
    52        
    53         if ( filesize( SIXSCAN_HTACCESS_FILE ) == 1 )
    54             $wp_filesystem->delete( SIXSCAN_HTACCESS_FILE );
    5557           
    56         if ( $wp_filesystem->exists( SIXSCAN_HTACCESS_6SCAN_GATE_DEST ) )
    57             $wp_filesystem->delete( SIXSCAN_HTACCESS_6SCAN_GATE_DEST );
     58        if ( $wp_filesystem->exists( sixscan_common_get_htaccess_dest_path( $is_direct ) ) )
     59            $wp_filesystem->delete( sixscan_common_get_htaccess_dest_path( $is_direct ) ); 
    5860           
    59         if ( $wp_filesystem->exists( SIXSCAN_SIGNATURE_DEST ) )
    60             $wp_filesystem->delete ( SIXSCAN_SIGNATURE_DEST ) ;
     61        if ( $wp_filesystem->exists( sixscan_common_get_signature_dest_path( $is_direct ) ) )
     62            $wp_filesystem->delete ( sixscan_common_get_signature_dest_path( $is_direct ) ) ;
    6163       
    6264    } catch( Exception $e ) {
  • 6scan-protection/trunk/admin/includes/installation.php

    r580294 r584844  
    1515    if ( sixscan_installation_wpfs_init( $tmp_key ) == FALSE)
    1616        return;
    17 
     17   
    1818    /* Run the install */
    1919    $install_result = sixscan_installation_install( $tmp_key );
     
    117117
    118118        /*  Make sure we can create signature file and update the site's .htaccess file */
    119         if ( sixscan_common_test_dir_writable( ABSPATH ) == FALSE ){               
     119        if ( sixscan_common_test_dir_writable( $wp_filesystem->abspath() ) == FALSE ){             
    120120            $err_message = "6Scan Install <b>Error</b>: Failed creating signature file at Wordpress directory " . ABSPATH . SIXSCAN_COMM_SIGNATURE_FILENAME .
    121121            "<br/><br/>Please see <a href='http://codex.wordpress.org/Changing_File_Permissions' target='_blank'>this Wordpress article</a> for more information on how to add write permissions." .
     
    339339        define( 'FS_METHOD' , 'direct' );
    340340    else if ( $wpfs_detect_try == 'ftpext' )
    341         define( 'FS_METHOD' , 'ftpext' );
    342 
     341        define( 'FS_METHOD' , 'ftpext' );   
    343342    if ( WP_Filesystem() ){
    344343        $config_key = "";
  • 6scan-protection/trunk/modules/signatures/update.php

    r566110 r584844  
    6666    global $wp_filesystem;
    6767    /*  Prepare temporary names */
    68     $temp_upgrade_dir = get_temp_dir() . trailingslashit( "6scan_update" );
    69     $temp_zip_file = get_temp_dir() . "bguard.zip";
    70    
     68    $temp_upgrade_dir_local = trailingslashit( WP_CONTENT_DIR ) . trailingslashit( "6scan_update" );
     69    $temp_upgrade_dir = $wp_filesystem->wp_content_dir() . trailingslashit( "6scan_update" );
     70    $temp_zip_file_local = trailingslashit( WP_CONTENT_DIR ) . "bguard.zip";
     71    $temp_zip_file = $wp_filesystem->wp_content_dir() . "bguard.zip";
     72
    7173    /*  Create temp directory for update */
    72     if ( ( $wp_filesystem->is_dir( $temp_upgrade_dir ) == FALSE ) && ( $wp_filesystem->mkdir( $temp_upgrade_dir ) == FALSE ) )
     74    if ( $wp_filesystem->exists( $temp_upgrade_dir ) )
     75        $wp_filesystem->delete ( $temp_upgrade_dir , TRUE );
     76   
     77    if ( ($wp_filesystem->is_dir( $temp_upgrade_dir ) == FALSE )  && ( $wp_filesystem->mkdir( $temp_upgrade_dir ) == FALSE ) )
    7378        return "Failed creating temp directory for update at " . $temp_upgrade_dir;     
    7479       
    75     /*  Write the zip file */   
     80    /*  Write the zip file */
     81    if ( $wp_filesystem->exists( $temp_zip_file ) )
     82        $wp_filesystem->delete( $temp_zip_file );
     83   
    7684    if ( $wp_filesystem->put_contents( $temp_zip_file , $zipped_program ) == FALSE )
    7785        return "Failed writing file to " . $temp_zip_file; 
    7886   
    79     /*  unzip_file returns mixed on failure. It uses global $wp_filesystem */   
    80     if ( unzip_file( $temp_zip_file , $temp_upgrade_dir ) !== TRUE )
     87    /*  unzip_file returns mixed on failure. It uses global $wp_filesystem. */ 
     88    if ( unzip_file( $temp_zip_file_local , $temp_upgrade_dir ) !== TRUE ){     
    8189        return "unzip_file() from $temp_zip_file to $temp_upgrade_dir failed";
     90    }
    8291   
    8392    /*  Remove the no longer required zip file */
    8493    $wp_filesystem->delete( $temp_zip_file );
    8594   
    86     $plugin_main_directory = plugin_dir_path( __FILE__ ) . "../../";   
    87            
    88     $temp_upgrade_dir_internal = sixscan_signatures_update_find_plugin_dir( $temp_upgrade_dir );
    89     if ( $temp_upgrade_dir_internal == "")
    90         return "Couldn't find plugin dir in the unzipped folder $temp_upgrade_dir";
    91        
     95    $plugin_main_directory = plugin_dir_path( __FILE__ ) . "../../";
     96    $plugin_main_directory = $wp_filesystem->wp_plugins_dir() . SIXSCAN_PLUGIN_DIRNAME;
     97
     98    $temp_upgrade_dir_internal = sixscan_signatures_update_find_plugin_dir( $temp_upgrade_dir_local );
     99
     100    if ( $temp_upgrade_dir_internal == "" )
     101        return "Couldn't find plugin dir in the unzipped folder $temp_upgrade_dir_local";
     102   
     103    $temp_upgrade_dir_internal = untrailingslashit( $wp_filesystem->find_folder( $temp_upgrade_dir_internal ) );
     104
    92105    /*  Now bulk copy the rest of files to their places: */
    93106    sixscan_signatures_update_move_dir_recursive( $temp_upgrade_dir_internal , $plugin_main_directory );
    94107       
    95     /*  Remove the tmp directory */
    96     $wp_filesystem->delete ( $temp_upgrade_dir_internal );
    97     $wp_filesystem->delete ( $temp_upgrade_dir );
     108    /*  Remove the tmp directory */
     109    $wp_filesystem->delete ( $temp_upgrade_dir , TRUE );
    98110   
    99111    return TRUE;
     
    141153
    142154function sixscan_signatures_update_parse( $raw_data ) {
    143        
    144     $signature_filename = ABSPATH . "/" . SIXSCAN_COMM_SIGNATURE_FILENAME;
     155    global $wp_filesystem;
     156
     157    $signature_filename = $wp_filesystem->find_folder( ABSPATH ) . SIXSCAN_COMM_SIGNATURE_FILENAME;
    145158    $signature_filename_tmp = $signature_filename . ".tmp";
    146159    $signature_offset = strpos( $raw_data , SIXSCAN_SIGNATURE_MULTIPART_DELIMITER );
    147     global $wp_filesystem;
     160   
    148161
    149162    if ($signature_offset === FALSE)
     
    189202    global $wp_filesystem;
    190203
    191     if ( file_exists( SIXSCAN_HTACCESS_FILE ) ) {
    192         $htaccess_content = $wp_filesystem->get_contents( SIXSCAN_HTACCESS_FILE );
     204    $htaccess_fpath = sixscan_common_get_htaccess_file_path( $wp_filesystem->method == 'direct' );
     205
     206    if ( $wp_filesystem->exists( $htaccess_fpath ) ) {
     207        $htaccess_content = $wp_filesystem->get_contents( $htaccess_fpath );
    193208        /*  Remove old 6Scan signature contents */
    194209        $new_content = trim( preg_replace( '@# Created by 6Scan plugin(.*?)# End of 6Scan plugin@s', '', $htaccess_content) );
     
    287302    $htaccess_links .= $vuln_urls;     
    288303   
    289     $tmp_htaccess_file = SIXSCAN_HTACCESS_FILE . ".tmp";   
     304    $tmp_htaccess_file = $htaccess_fpath . ".tmp"; 
    290305   
    291306    $new_content = "# Created by 6Scan plugin
     
    315330    $wp_filesystem->put_contents( $tmp_htaccess_file , $new_content );
    316331       
    317     if ( sixscan_signatures_update_copy_file( $tmp_htaccess_file , SIXSCAN_HTACCESS_FILE ) == FALSE )
    318         return "Failed moving htaccess from $tmp_htaccess_file to " . SIXSCAN_HTACCESS_FILE;
     332    if ( sixscan_signatures_update_copy_file( $tmp_htaccess_file , $htaccess_fpath ) == FALSE )
     333        return "Failed moving htaccess from $tmp_htaccess_file to " . $htaccess_fpath;
    319334       
    320335    return TRUE;
     
    349364            $wp_filesystem->mkdir( $dest );
    350365           
    351         $file_list = scandir( $source );
    352 
    353         foreach( $file_list as $current_file ) {
     366        //$file_list = scandir( $source );
     367        $file_list = $wp_filesystem->dirlist( $source );
     368       
     369        foreach( $file_list as $farray => $current_fname ) {
     370            $current_file = $current_fname['name'];
     371           
    354372            if( $current_file == "." || $current_file == ".." ) {
    355373                /* skip "current" and "previous" directory */
     
    357375            }
    358376           
    359             if( is_dir( $source . "/" . $current_file ) ) {
     377            if( $wp_filesystem->is_dir( $source . "/" . $current_file ) ) {
    360378            /*  If it is directory , we have to call the recursion.*/
    361379                sixscan_signatures_update_move_dir_recursive( $source . "/" . $current_file, $dest. "/" . $current_file );
     
    416434    global $wp_filesystem;
    417435   
     436    $wp_filesystem->delete( $dst_file );
    418437    return $wp_filesystem->move( $src_file , $dst_file , TRUE );
    419438}
     
    449468        return WP_Filesystem();
    450469    }
    451    
     470
    452471    $cfg_arr = unserialize( sixscan_common_decrypt_string( base64_decode ( $wp_fs_param ) , $config_key ) );
    453472   
    454     $wp_fs = WP_Filesystem( $cfg_arr );
    455     if ( $wp_fs ){
    456         $wp_filesystem->connect();
    457         return $wp_fs;
    458     }
     473    $wp_fs = WP_Filesystem( $cfg_arr );
    459474
    460475    return $wp_fs;
Note: See TracChangeset for help on using the changeset viewer.