Plugin Directory

Changeset 3219647


Ignore:
Timestamp:
01/09/2025 01:02:44 PM (15 months ago)
Author:
raldea89
Message:

Security update

Location:
htaccess-file-editor
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • htaccess-file-editor/tags/1.0.20/assets/js/htaccess-file-editor.min.js

    r3140218 r3219647  
    1 jQuery(document).ready((function(e){wp.codeEditor.initialize(e("#htaccess-file-editor-textarea"),htaccess_file_editor_settings)}));
     1jQuery(document).ready(function(e){wp.codeEditor.initialize(e("#htaccess-file-editor-textarea"),htaccess_file_editor_settings)});
  • htaccess-file-editor/tags/1.0.20/includes/class-htaccess-file-editor-hooks.php

    r3210305 r3219647  
    6464    public function migrate_backup_name() {
    6565        $old_name = 'htaccess.backup';
    66         $new_name = '.htaccess-file-editor-bkup';
     66        $hash     = sanitize_file_name( substr( wp_generate_password( 10, false ), 0, 5 ) );
     67        $new_name = '.htaccess-file-editor-bkup-' . $hash;
    6768        $path     = WP_CONTENT_DIR;
    68         // If the new backup file exists, then we don't need to migrate
    69         if ( file_exists( $path . '/' . $new_name ) ) {
     69        // Retrieve the saved backup name
     70        $saved_name = get_option( 'htaccess_file_editor_backup_name' );
     71        // If the backup file is saved in the options and exists, then we don't need to migrate
     72        if ( $saved_name && file_exists( $path . '/' . $saved_name ) ) {
    7073            return;
    7174        }
     75
    7276        // If the old file doesn't exist, then we don't need to migrate
    7377        if ( ! file_exists( $path . '/' . $old_name ) ) {
     
    8084        WP_Filesystem();
    8185        $wp_filesystem->move( $path . '/' . $old_name, $path . '/' . $new_name );
     86        update_option( 'htaccess_file_editor_backup_name', $new_name );
    8287    }
    8388}
  • htaccess-file-editor/tags/1.0.20/includes/functions.php

    r3210305 r3219647  
    99    require_once ABSPATH . '/wp-admin/includes/file.php';
    1010    WP_Filesystem();
    11     $WPHE_backup_path = ABSPATH . 'wp-content/.htaccess-file-editor-bkup';
     11    $saved_name = get_option( 'htaccess_file_editor_backup_name' );
     12    // Check if the backup file is saved in the options
     13    if ( $saved_name ) {
     14        $file_name = $saved_name;
     15    } else {
     16        $hash      = sanitize_file_name( substr( wp_generate_password( 10, false ), 0, 5 ) );
     17        $file_name = '.htaccess-file-editor-bkup-' . $hash;
     18    }
     19    $WPHE_backup_path = ABSPATH . 'wp-content/' . $file_name;
    1220    $WPHE_orig_path   = ABSPATH . '.htaccess';
    1321    @clearstatcache();
    1422
    15     htaccess_file_editor_create_secure_wpcontent();
     23    htaccess_file_editor_create_secure_wpcontent( $file_name );
    1624    if ( file_exists( $WPHE_backup_path ) ) {
    17         htaccess_file_editor_delete_backup();
     25        htaccess_file_editor_delete_backup( $file_name );
    1826
    1927        if ( file_exists( ABSPATH . '.htaccess' ) ) {
     
    3543                unset( $htaccess_content_orig );
    3644                unset( $WPHE_success );
     45                update_option( 'htaccess_file_editor_backup_name', $file_name );
    3746                return true;
    3847            }
     
    6473            unset( $htaccess_content_orig );
    6574            unset( $WPHE_success );
     75            update_option( 'htaccess_file_editor_backup_name', $file_name );
    6676            return true;
    6777        }
     
    7585
    7686
    77 function htaccess_file_editor_create_secure_wpcontent() {
     87function htaccess_file_editor_create_secure_wpcontent( $file_name = false ) {
     88    if ( ! $file_name ) {
     89        return false;
     90    }
    7891    $htaccess_file_editor_secure_path = ABSPATH . 'wp-content/.htaccess';
    7992    $htaccess_file_editor_secure_text = '
    8093# Htaccess File Editor - Secure backups
    81 <files .htaccess-file-editor-bkup>
     94<files ' . $file_name . '>
    8295order allow,deny
    8396deny from all
     
    91104
    92105        if ( $htaccess_file_editor_secure_content !== false ) {
    93             if ( strpos( $htaccess_file_editor_secure_content, '<files .htaccess-file-editor-bkup>' ) === false ) {
     106            if ( strpos( $htaccess_file_editor_secure_content, '<files ' . $file_name . '>' ) === false ) {
    94107                unset( $htaccess_file_editor_secure_content );
    95108                $htaccess_file_editor_create_sec = $wp_filesystem->put_contents( ABSPATH . 'wp-content/.htaccess', $htaccess_file_editor_secure_text );
     
    125138
    126139function htaccess_file_editor_restore_backup() {
    127     $htaccess_file_editor_backup_path = ABSPATH . 'wp-content/.htaccess-file-editor-bkup';
     140    $file_name = get_option( 'htaccess_file_editor_backup_name' );
     141    if ( ! $file_name ) {
     142        return false;
     143    }
     144    $htaccess_file_editor_backup_path = ABSPATH . 'wp-content/' . $file_name;
    128145    $WPHE_orig_path                   = ABSPATH . '.htaccess';
    129146    @clearstatcache();
     
    152169            return $htaccess_file_editor_htaccess_content_backup;
    153170        } else {
    154             htaccess_file_editor_delete_backup();
     171            htaccess_file_editor_delete_backup( $file_name );
    155172            unset( $htaccess_file_editor_success );
    156173            unset( $htaccess_file_editor_htaccess_content_backup );
     
    163180
    164181
    165 function htaccess_file_editor_delete_backup() {
    166     $htaccess_file_editor_backup_path = ABSPATH . 'wp-content/.htaccess-file-editor-bkup';
     182function htaccess_file_editor_delete_backup( $file_name = false ) {
     183
     184    if ( ! $file_name ) {
     185        $file_name = get_option( 'htaccess_file_editor_backup_name' );
     186        if ( ! $file_name ) {
     187            return false;
     188        }
     189    }
     190    $htaccess_file_editor_backup_path = ABSPATH . 'wp-content/' . $file_name;
    167191    @clearstatcache();
    168192
     
    184208            return false;
    185209        } else {
    186             unset( $htaccess_file_editor_backup_path );
    187             return true;
    188         }
    189     } else {
     210            delete_option( 'htaccess_file_editor_backup_name' );
     211            unset( $htaccess_file_editor_backup_path );
     212            return true;
     213        }
     214    } else {
     215        delete_option( 'htaccess_file_editor_backup_name' );
    190216        unset( $htaccess_file_editor_backup_path );
    191217        return true;
  • htaccess-file-editor/tags/1.0.20/templates/backup-form.php

    r3210305 r3219647  
    11<?php
    2 if (file_exists(ABSPATH . 'wp-content/.htaccess-file-editor-bkup')) {
     2$file_name = get_option('htaccess_file_editor_backup_name');
     3
     4if ($file_name && file_exists(ABSPATH . 'wp-content/' . $file_name)) {
    35    echo '<div class="postbox htaccess-file-editor-box" style="background: #FFEECE;">';
    46    ?>
  • htaccess-file-editor/tags/1.0.20/templates/dashboard.php

    r3210305 r3219647  
    99require_once ABSPATH . '/wp-admin/includes/file.php';
    1010WP_Filesystem();
    11 $htaccess_file_editor_backup_path = WP_CONTENT_URL . '/.htaccess-file-editor-bkup';
     11$file_name = get_option( 'htaccess_file_editor_backup_name' );
     12$htaccess_file_editor_backup_path = WP_CONTENT_URL . '/' . $file_name;
    1213$htaccess_file_editor_origin_path = ABSPATH . '.htaccess';
    1314?>
  • htaccess-file-editor/trunk/assets/js/htaccess-file-editor.min.js

    r3140218 r3219647  
    1 jQuery(document).ready((function(e){wp.codeEditor.initialize(e("#htaccess-file-editor-textarea"),htaccess_file_editor_settings)}));
     1jQuery(document).ready(function(e){wp.codeEditor.initialize(e("#htaccess-file-editor-textarea"),htaccess_file_editor_settings)});
  • htaccess-file-editor/trunk/includes/class-htaccess-file-editor-hooks.php

    r3210305 r3219647  
    6464    public function migrate_backup_name() {
    6565        $old_name = 'htaccess.backup';
    66         $new_name = '.htaccess-file-editor-bkup';
     66        $hash     = sanitize_file_name( substr( wp_generate_password( 10, false ), 0, 5 ) );
     67        $new_name = '.htaccess-file-editor-bkup-' . $hash;
    6768        $path     = WP_CONTENT_DIR;
    68         // If the new backup file exists, then we don't need to migrate
    69         if ( file_exists( $path . '/' . $new_name ) ) {
     69        // Retrieve the saved backup name
     70        $saved_name = get_option( 'htaccess_file_editor_backup_name' );
     71        // If the backup file is saved in the options and exists, then we don't need to migrate
     72        if ( $saved_name && file_exists( $path . '/' . $saved_name ) ) {
    7073            return;
    7174        }
     75
    7276        // If the old file doesn't exist, then we don't need to migrate
    7377        if ( ! file_exists( $path . '/' . $old_name ) ) {
     
    8084        WP_Filesystem();
    8185        $wp_filesystem->move( $path . '/' . $old_name, $path . '/' . $new_name );
     86        update_option( 'htaccess_file_editor_backup_name', $new_name );
    8287    }
    8388}
  • htaccess-file-editor/trunk/includes/functions.php

    r3210305 r3219647  
    99    require_once ABSPATH . '/wp-admin/includes/file.php';
    1010    WP_Filesystem();
    11     $WPHE_backup_path = ABSPATH . 'wp-content/.htaccess-file-editor-bkup';
     11    $saved_name = get_option( 'htaccess_file_editor_backup_name' );
     12    // Check if the backup file is saved in the options
     13    if ( $saved_name ) {
     14        $file_name = $saved_name;
     15    } else {
     16        $hash      = sanitize_file_name( substr( wp_generate_password( 10, false ), 0, 5 ) );
     17        $file_name = '.htaccess-file-editor-bkup-' . $hash;
     18    }
     19    $WPHE_backup_path = ABSPATH . 'wp-content/' . $file_name;
    1220    $WPHE_orig_path   = ABSPATH . '.htaccess';
    1321    @clearstatcache();
    1422
    15     htaccess_file_editor_create_secure_wpcontent();
     23    htaccess_file_editor_create_secure_wpcontent( $file_name );
    1624    if ( file_exists( $WPHE_backup_path ) ) {
    17         htaccess_file_editor_delete_backup();
     25        htaccess_file_editor_delete_backup( $file_name );
    1826
    1927        if ( file_exists( ABSPATH . '.htaccess' ) ) {
     
    3543                unset( $htaccess_content_orig );
    3644                unset( $WPHE_success );
     45                update_option( 'htaccess_file_editor_backup_name', $file_name );
    3746                return true;
    3847            }
     
    6473            unset( $htaccess_content_orig );
    6574            unset( $WPHE_success );
     75            update_option( 'htaccess_file_editor_backup_name', $file_name );
    6676            return true;
    6777        }
     
    7585
    7686
    77 function htaccess_file_editor_create_secure_wpcontent() {
     87function htaccess_file_editor_create_secure_wpcontent( $file_name = false ) {
     88    if ( ! $file_name ) {
     89        return false;
     90    }
    7891    $htaccess_file_editor_secure_path = ABSPATH . 'wp-content/.htaccess';
    7992    $htaccess_file_editor_secure_text = '
    8093# Htaccess File Editor - Secure backups
    81 <files .htaccess-file-editor-bkup>
     94<files ' . $file_name . '>
    8295order allow,deny
    8396deny from all
     
    91104
    92105        if ( $htaccess_file_editor_secure_content !== false ) {
    93             if ( strpos( $htaccess_file_editor_secure_content, '<files .htaccess-file-editor-bkup>' ) === false ) {
     106            if ( strpos( $htaccess_file_editor_secure_content, '<files ' . $file_name . '>' ) === false ) {
    94107                unset( $htaccess_file_editor_secure_content );
    95108                $htaccess_file_editor_create_sec = $wp_filesystem->put_contents( ABSPATH . 'wp-content/.htaccess', $htaccess_file_editor_secure_text );
     
    125138
    126139function htaccess_file_editor_restore_backup() {
    127     $htaccess_file_editor_backup_path = ABSPATH . 'wp-content/.htaccess-file-editor-bkup';
     140    $file_name = get_option( 'htaccess_file_editor_backup_name' );
     141    if ( ! $file_name ) {
     142        return false;
     143    }
     144    $htaccess_file_editor_backup_path = ABSPATH . 'wp-content/' . $file_name;
    128145    $WPHE_orig_path                   = ABSPATH . '.htaccess';
    129146    @clearstatcache();
     
    152169            return $htaccess_file_editor_htaccess_content_backup;
    153170        } else {
    154             htaccess_file_editor_delete_backup();
     171            htaccess_file_editor_delete_backup( $file_name );
    155172            unset( $htaccess_file_editor_success );
    156173            unset( $htaccess_file_editor_htaccess_content_backup );
     
    163180
    164181
    165 function htaccess_file_editor_delete_backup() {
    166     $htaccess_file_editor_backup_path = ABSPATH . 'wp-content/.htaccess-file-editor-bkup';
     182function htaccess_file_editor_delete_backup( $file_name = false ) {
     183
     184    if ( ! $file_name ) {
     185        $file_name = get_option( 'htaccess_file_editor_backup_name' );
     186        if ( ! $file_name ) {
     187            return false;
     188        }
     189    }
     190    $htaccess_file_editor_backup_path = ABSPATH . 'wp-content/' . $file_name;
    167191    @clearstatcache();
    168192
     
    184208            return false;
    185209        } else {
    186             unset( $htaccess_file_editor_backup_path );
    187             return true;
    188         }
    189     } else {
     210            delete_option( 'htaccess_file_editor_backup_name' );
     211            unset( $htaccess_file_editor_backup_path );
     212            return true;
     213        }
     214    } else {
     215        delete_option( 'htaccess_file_editor_backup_name' );
    190216        unset( $htaccess_file_editor_backup_path );
    191217        return true;
  • htaccess-file-editor/trunk/templates/backup-form.php

    r3210305 r3219647  
    11<?php
    2 if (file_exists(ABSPATH . 'wp-content/.htaccess-file-editor-bkup')) {
     2$file_name = get_option('htaccess_file_editor_backup_name');
     3
     4if ($file_name && file_exists(ABSPATH . 'wp-content/' . $file_name)) {
    35    echo '<div class="postbox htaccess-file-editor-box" style="background: #FFEECE;">';
    46    ?>
  • htaccess-file-editor/trunk/templates/dashboard.php

    r3210305 r3219647  
    99require_once ABSPATH . '/wp-admin/includes/file.php';
    1010WP_Filesystem();
    11 $htaccess_file_editor_backup_path = WP_CONTENT_URL . '/.htaccess-file-editor-bkup';
     11$file_name = get_option( 'htaccess_file_editor_backup_name' );
     12$htaccess_file_editor_backup_path = WP_CONTENT_URL . '/' . $file_name;
    1213$htaccess_file_editor_origin_path = ABSPATH . '.htaccess';
    1314?>
Note: See TracChangeset for help on using the changeset viewer.